• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kaddressbook

  • sources
  • kde-4.12
  • kdepim
  • kaddressbook
contactswitcher.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "contactswitcher.h"
21 
22 #include <KLocale>
23 
24 #include <QAbstractItemView>
25 #include <QHBoxLayout>
26 #include <QLabel>
27 #include <QPushButton>
28 
29 ContactSwitcher::ContactSwitcher( QWidget *parent )
30  : QWidget( parent ), mView( 0 )
31 {
32  QHBoxLayout *layout = new QHBoxLayout( this );
33 
34  mPreviousButton = new QPushButton( i18nc( "@action:button Previous contact", "Previous" ) );
35  mPreviousButton->setToolTip(
36  i18nc( "@info:tooltip", "Move to the previous contact in the list" ) );
37  mPreviousButton->setWhatsThis(
38  i18nc( "@info:whatsthis",
39  "Press this button to move to the previous contact in the list." ) );
40 
41  mNextButton = new QPushButton( i18nc( "@action:button Next contact", "Next" ) );
42  mNextButton->setToolTip(
43  i18nc( "@info:tooltip", "Move to the next contact in the list" ) );
44  mNextButton->setWhatsThis(
45  i18nc( "@info:whatsthis",
46  "Press this button to move to the next contact in the list." ) );
47 
48  mStatusLabel = new QLabel();
49 
50  layout->addWidget( mPreviousButton );
51  layout->addWidget( mNextButton );
52  layout->addStretch( 1 );
53  layout->addWidget( mStatusLabel );
54 
55  connect( mPreviousButton, SIGNAL(clicked()), SLOT(previousClicked()) );
56  connect( mNextButton, SIGNAL(clicked()), SLOT(nextClicked()) );
57 }
58 
59 void ContactSwitcher::setView( QAbstractItemView *view )
60 {
61  mView = view;
62 
63  Q_ASSERT_X( mView->model(), "ContactSwitcher::setView", "The view has no model set!" );
64 
65  connect( mView->model(), SIGNAL(layoutChanged()), SLOT(updateStatus()) );
66  connect( mView->model(), SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(updateStatus()) );
67  connect( mView->model(), SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(updateStatus()) );
68  connect( mView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(updateStatus()));
69 
70  updateStatus();
71 }
72 
73 void ContactSwitcher::nextClicked()
74 {
75  if ( !mView || !mView->model() ) {
76  return;
77  }
78 
79  const QModelIndex index = mView->selectionModel()->currentIndex();
80 
81  int row = 0;
82  if ( index.isValid() ) {
83  row = index.row() + 1;
84  }
85 
86  mView->selectionModel()->setCurrentIndex( mView->model()->index( row, 0 ),
87  QItemSelectionModel::Rows |
88  QItemSelectionModel::ClearAndSelect );
89 
90  updateStatus();
91 }
92 
93 void ContactSwitcher::previousClicked()
94 {
95  if ( !mView || !mView->model() ) {
96  return;
97  }
98 
99  const QModelIndex index = mView->selectionModel()->currentIndex();
100 
101  int row = 0;
102  if ( index.isValid() ) {
103  row = index.row() - 1;
104  }
105 
106  mView->selectionModel()->setCurrentIndex( mView->model()->index( row, 0 ),
107  QItemSelectionModel::Rows |
108  QItemSelectionModel::ClearAndSelect );
109 
110  updateStatus();
111 }
112 
113 void ContactSwitcher::updateStatus()
114 {
115  if ( !mView || !mView->model() ) {
116  return;
117  }
118 
119  const QModelIndex index = mView->selectionModel()->currentIndex();
120 
121  int row = 0;
122  if ( index.isValid() ) {
123  row = index.row();
124  }
125 
126  mPreviousButton->setEnabled( row != 0 );
127  mNextButton->setEnabled( row != ( mView->model()->rowCount() - 1 ) );
128 
129  mStatusLabel->setText( i18nc( "@info:status",
130  "%1 out of %2", row + 1, mView->model()->rowCount() ) );
131 }
132 
133 #include "contactswitcher.moc"
contactswitcher.h
ContactSwitcher::setView
void setView(QAbstractItemView *view)
Sets the view the contact switcher shall work on.
Definition: contactswitcher.cpp:59
ContactSwitcher::ContactSwitcher
ContactSwitcher(QWidget *parent=0)
Creates a new contact switcher.
Definition: contactswitcher.cpp:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kaddressbook

Skip menu "kaddressbook"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal