24 #include <QAbstractItemView>
25 #include <QHBoxLayout>
27 #include <QPushButton>
30 : QWidget( parent ), mView( 0 )
32 QHBoxLayout *layout =
new QHBoxLayout(
this );
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." ) );
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." ) );
48 mStatusLabel =
new QLabel();
50 layout->addWidget( mPreviousButton );
51 layout->addWidget( mNextButton );
52 layout->addStretch( 1 );
53 layout->addWidget( mStatusLabel );
55 connect( mPreviousButton, SIGNAL(clicked()), SLOT(previousClicked()) );
56 connect( mNextButton, SIGNAL(clicked()), SLOT(nextClicked()) );
63 Q_ASSERT_X( mView->model(),
"ContactSwitcher::setView",
"The view has no model set!" );
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()));
73 void ContactSwitcher::nextClicked()
75 if ( !mView || !mView->model() ) {
79 const QModelIndex index = mView->selectionModel()->currentIndex();
82 if ( index.isValid() ) {
83 row = index.row() + 1;
86 mView->selectionModel()->setCurrentIndex( mView->model()->index( row, 0 ),
87 QItemSelectionModel::Rows |
88 QItemSelectionModel::ClearAndSelect );
93 void ContactSwitcher::previousClicked()
95 if ( !mView || !mView->model() ) {
99 const QModelIndex index = mView->selectionModel()->currentIndex();
102 if ( index.isValid() ) {
103 row = index.row() - 1;
106 mView->selectionModel()->setCurrentIndex( mView->model()->index( row, 0 ),
107 QItemSelectionModel::Rows |
108 QItemSelectionModel::ClearAndSelect );
113 void ContactSwitcher::updateStatus()
115 if ( !mView || !mView->model() ) {
119 const QModelIndex index = mView->selectionModel()->currentIndex();
122 if ( index.isValid() ) {
126 mPreviousButton->setEnabled( row != 0 );
127 mNextButton->setEnabled( row != ( mView->model()->rowCount() - 1 ) );
129 mStatusLabel->setText( i18nc(
"@info:status",
130 "%1 out of %2", row + 1, mView->model()->rowCount() ) );
133 #include "contactswitcher.moc"