~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to kcontactmanager/contactswitcher.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi, Alessandro Ghersi, Harald Sitter
  • Date: 2009-06-27 04:40:05 UTC
  • mfrom: (1.1.39 upstream)
  • Revision ID: james.westby@ubuntu.com-20090627044005-4y2vm9xz7rvmzi4p
Tags: 4:4.2.95svn20090701-0ubuntu1
[ Alessandro Ghersi ]
* New upstream release
  - Bump build-deps
* Remove akonadi-kde and libmaildir4 packages
  - remove akonadi-kde.install and libmaildir4.install
  - remove libmaildir4 from debian/rules
  - remove akonadi-kde and libmaildir4 from depends
  - remove akonadi-kde and libmaildir4 from installgen
* Update kdepim-dev.install
* Update kpilot.install
* Add akonadi-kde and libmaildir4 transitional packages

[ Harald Sitter ]
* KAddressbook replaces Kontact << 4.2.85 (LP: #378373)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.h>
23
 
 
24
 
#include <QtGui/QAbstractItemView>
25
 
#include <QtGui/QHBoxLayout>
26
 
#include <QtGui/QLabel>
27
 
#include <QtGui/QPushButton>
28
 
 
29
 
ContactSwitcher::ContactSwitcher( QWidget *parent )
30
 
  : QWidget( parent ),
31
 
    mView( 0 )
32
 
{
33
 
  QHBoxLayout *layout = new QHBoxLayout( this );
34
 
 
35
 
  mPreviousButton = new QPushButton( i18n( "Previous" ) );
36
 
  mNextButton = new QPushButton( i18n( "Next" ) );
37
 
  mStatusLabel = new QLabel();
38
 
 
39
 
  layout->addWidget( mPreviousButton );
40
 
  layout->addWidget( mNextButton );
41
 
  layout->addStretch( 1 );
42
 
  layout->addWidget( mStatusLabel );
43
 
 
44
 
  connect( mPreviousButton, SIGNAL( clicked() ), SLOT( previousClicked() ) );
45
 
  connect( mNextButton, SIGNAL( clicked() ), SLOT( nextClicked() ) );
46
 
}
47
 
 
48
 
void ContactSwitcher::setView( QAbstractItemView *view )
49
 
{
50
 
  mView = view;
51
 
 
52
 
  Q_ASSERT_X( mView->model(), "ContactSwitcher::setView", "The view has no model set!" );
53
 
 
54
 
  connect( mView->model(), SIGNAL( layoutChanged() ), SLOT( updateStatus() ) );
55
 
  connect( mView->model(), SIGNAL( rowsInserted(const QModelIndex&, int, int) ), SLOT( updateStatus() ) );
56
 
  connect( mView->model(), SIGNAL( rowsRemoved(const QModelIndex&, int, int) ), SLOT( updateStatus() ) );
57
 
 
58
 
  updateStatus();
59
 
}
60
 
 
61
 
void ContactSwitcher::nextClicked()
62
 
{
63
 
  if ( !mView || !mView->model() )
64
 
    return;
65
 
 
66
 
  const QModelIndex index = mView->selectionModel()->currentIndex();
67
 
 
68
 
  int row = 0;
69
 
  if ( index.isValid() )
70
 
    row = index.row() + 1;
71
 
 
72
 
  mView->selectionModel()->setCurrentIndex( mView->model()->index( row, 0 ),
73
 
                                            QItemSelectionModel::Rows |
74
 
                                            QItemSelectionModel::ClearAndSelect );
75
 
 
76
 
  updateStatus();
77
 
}
78
 
 
79
 
void ContactSwitcher::previousClicked()
80
 
{
81
 
  if ( !mView || !mView->model() )
82
 
    return;
83
 
 
84
 
  const QModelIndex index = mView->selectionModel()->currentIndex();
85
 
 
86
 
  int row = 0;
87
 
  if ( index.isValid() )
88
 
    row = index.row() - 1;
89
 
 
90
 
  mView->selectionModel()->setCurrentIndex( mView->model()->index( row, 0 ),
91
 
                                            QItemSelectionModel::Rows |
92
 
                                            QItemSelectionModel::ClearAndSelect );
93
 
 
94
 
  updateStatus();
95
 
}
96
 
 
97
 
void ContactSwitcher::updateStatus()
98
 
{
99
 
  if ( !mView || !mView->model() )
100
 
    return;
101
 
 
102
 
  const QModelIndex index = mView->selectionModel()->currentIndex();
103
 
 
104
 
  int row = 0;
105
 
  if ( index.isValid() )
106
 
    row = index.row();
107
 
 
108
 
  mPreviousButton->setEnabled( row != 0 );
109
 
  mNextButton->setEnabled( row != (mView->model()->rowCount() - 1) );
110
 
 
111
 
  mStatusLabel->setText( i18n( "%1 out of %2" ).arg( row + 1 ).arg( mView->model()->rowCount() ) );
112
 
}
113
 
 
114
 
#include "contactswitcher.moc"