• 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
modelcolumnmanager.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KAddressBook.
3 
4  Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc.,
18  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 
21 #include "modelcolumnmanager.h"
22 #include "settings.h"
23 
24 #include <KABC/Addressee>
25 
26 #include <KLocale>
27 
28 #include <QtCore/QEvent>
29 #include <QtCore/QTimer>
30 #include <QContextMenuEvent>
31 #include <QHeaderView>
32 #include <QMenu>
33 #include <QWidget>
34 
35 ModelColumnManager::ModelColumnManager( Akonadi::ContactsTreeModel *model, QObject *parent )
36  : QObject( parent ), mModel( model ), mWidget( 0 )
37 {
38 }
39 
40 void ModelColumnManager::load()
41 {
42  const QList<int> settingsColumns = Settings::contactModelColumns();
43  Akonadi::ContactsTreeModel::Columns columns;
44 
45  foreach ( int column, settingsColumns ) {
46  columns.append( ( Akonadi::ContactsTreeModel::Column )column );
47  }
48 
49  mModel->setColumns( columns );
50 }
51 
52 void ModelColumnManager::store()
53 {
54  const Akonadi::ContactsTreeModel::Columns columns = mModel->columns();
55  QList<int> settingsColumns;
56 
57  foreach ( int column, columns ) {
58  settingsColumns.append( (int)column );
59  }
60 
61  Settings::setContactModelColumns( settingsColumns );
62 }
63 
64 void ModelColumnManager::setWidget( QWidget *widget )
65 {
66  mWidget = widget;
67  mWidget->installEventFilter( this );
68 }
69 
70 bool ModelColumnManager::eventFilter( QObject *watched, QEvent *event )
71 {
72  if ( watched == mWidget ) {
73  if ( event->type() == QEvent::ContextMenu ) {
74  QMenu menu;
75 
76  Akonadi::ContactsTreeModel::Columns columns = mModel->columns();
77 
78  QAction *fullNameAction = menu.addAction( i18n( "Full Name" ) );
79  fullNameAction->setCheckable( true );
80  fullNameAction->setChecked(
81  columns.contains( Akonadi::ContactsTreeModel::FullName ) );
82  fullNameAction->setEnabled( false );
83 
84  QAction *familyNameAction = menu.addAction( i18n( "Family Name" ) );
85  familyNameAction->setCheckable( true );
86  familyNameAction->setChecked(
87  columns.contains( Akonadi::ContactsTreeModel::FamilyName ) );
88 
89  QAction *givenNameAction = menu.addAction( i18n( "Given Name" ) );
90  givenNameAction->setCheckable( true );
91  givenNameAction->setChecked(
92  columns.contains( Akonadi::ContactsTreeModel::GivenName ) );
93 
94  QAction *birthdayAction = menu.addAction( KABC::Addressee::birthdayLabel() );
95  birthdayAction->setCheckable( true );
96  birthdayAction->setChecked(
97  columns.contains( Akonadi::ContactsTreeModel::Birthday ) );
98 
99  QAction *homeAddressAction = menu.addAction( i18n( "Home Address" ) );
100  homeAddressAction->setCheckable( true );
101  homeAddressAction->setChecked(
102  columns.contains( Akonadi::ContactsTreeModel::HomeAddress ) );
103 
104  QAction *businessAddressAction = menu.addAction( i18n( "Business Address" ) );
105  businessAddressAction->setCheckable( true );
106  businessAddressAction->setChecked(
107  columns.contains( Akonadi::ContactsTreeModel::BusinessAddress ) );
108 
109  QAction *phoneNumbersAction = menu.addAction( i18n( "Phone Numbers" ) );
110  phoneNumbersAction->setCheckable( true );
111  phoneNumbersAction->setChecked(
112  columns.contains( Akonadi::ContactsTreeModel::PhoneNumbers ) );
113 
114  QAction *preferredEmailAction = menu.addAction( i18n( "Preferred EMail" ) );
115  preferredEmailAction->setCheckable( true );
116  preferredEmailAction->setChecked(
117  columns.contains( Akonadi::ContactsTreeModel::PreferredEmail ) );
118 
119  QAction *allEmailsAction = menu.addAction( i18n( "All EMails" ) );
120  allEmailsAction->setCheckable( true );
121  allEmailsAction->setChecked(
122  columns.contains( Akonadi::ContactsTreeModel::AllEmails ) );
123 
124  QAction *organizationAction = menu.addAction( KABC::Addressee::organizationLabel() );
125  organizationAction->setCheckable( true );
126  organizationAction->setChecked(
127  columns.contains( Akonadi::ContactsTreeModel::Organization ) );
128 
129  QAction *roleAction = menu.addAction( KABC::Addressee::roleLabel() );
130  roleAction->setCheckable( true );
131  roleAction->setChecked(
132  columns.contains( Akonadi::ContactsTreeModel::Role ) );
133 
134  QAction *homepageAction = menu.addAction( KABC::Addressee::urlLabel() );
135  homepageAction->setCheckable( true );
136  homepageAction->setChecked(
137  columns.contains( Akonadi::ContactsTreeModel::Homepage ) );
138 
139  QAction *noteAction = menu.addAction( KABC::Addressee::noteLabel() );
140  noteAction->setCheckable( true );
141  noteAction->setChecked(
142  columns.contains( Akonadi::ContactsTreeModel::Note ) );
143 
144  if ( menu.exec( ( ( QContextMenuEvent * )event )->globalPos() ) ) {
145  Akonadi::ContactsTreeModel::Columns columns;
146 
147  if ( fullNameAction->isChecked() ) {
148  columns << Akonadi::ContactsTreeModel::FullName;
149  }
150  if ( familyNameAction->isChecked() ) {
151  columns << Akonadi::ContactsTreeModel::FamilyName;
152  }
153  if ( givenNameAction->isChecked() ) {
154  columns << Akonadi::ContactsTreeModel::GivenName;
155  }
156  if ( birthdayAction->isChecked() ) {
157  columns << Akonadi::ContactsTreeModel::Birthday;
158  }
159  if ( homeAddressAction->isChecked() ) {
160  columns << Akonadi::ContactsTreeModel::HomeAddress;
161  }
162  if ( businessAddressAction->isChecked() ) {
163  columns << Akonadi::ContactsTreeModel::BusinessAddress;
164  }
165  if ( phoneNumbersAction->isChecked() ) {
166  columns << Akonadi::ContactsTreeModel::PhoneNumbers;
167  }
168  if ( preferredEmailAction->isChecked() ) {
169  columns << Akonadi::ContactsTreeModel::PreferredEmail;
170  }
171  if ( allEmailsAction->isChecked() ) {
172  columns << Akonadi::ContactsTreeModel::AllEmails;
173  }
174  if ( organizationAction->isChecked() ) {
175  columns << Akonadi::ContactsTreeModel::Organization;
176  }
177  if ( roleAction->isChecked() ) {
178  columns << Akonadi::ContactsTreeModel::Role;
179  }
180  if ( homepageAction->isChecked() ) {
181  columns << Akonadi::ContactsTreeModel::Homepage;
182  }
183  if ( noteAction->isChecked() ) {
184  columns << Akonadi::ContactsTreeModel::Note;
185  }
186 
187  mModel->setColumns( columns );
188  QTimer::singleShot( 0, this, SLOT(adaptHeaderView()) );
189  }
190 
191  return true;
192  } else {
193  return false;
194  }
195  }
196 
197  return false;
198 }
199 
200 void ModelColumnManager::adaptHeaderView()
201 {
202  QHeaderView *view = qobject_cast<QHeaderView*>( mWidget );
203  if ( view ) {
204  view->resizeSections( QHeaderView::Stretch );
205 
206  view->setDefaultAlignment( mModel->columns().count() == 1 ? Qt::AlignCenter : Qt::AlignLeft );
207  }
208 }
209 
210 #include "modelcolumnmanager.moc"
ModelColumnManager::store
void store()
Stores the user configuration.
Definition: modelcolumnmanager.cpp:52
Birthday
Definition: ringbinderstyle.cpp:52
ModelColumnManager::eventFilter
virtual bool eventFilter(QObject *watched, QEvent *event)
Definition: modelcolumnmanager.cpp:70
QObject
ModelColumnManager::ModelColumnManager
ModelColumnManager(Akonadi::ContactsTreeModel *model, QObject *parent=0)
Creates a new model column manager.
Definition: modelcolumnmanager.cpp:35
Organization
Definition: ringbinderstyle.cpp:51
PhoneNumbers
Definition: ringbinderstyle.cpp:48
ModelColumnManager::load
void load()
Loads the user configuration and applies it to the model.
Definition: modelcolumnmanager.cpp:40
ModelColumnManager::setWidget
void setWidget(QWidget *view)
Sets the widget that shall provide a RMB menu to configure the columns to be shown.
Definition: modelcolumnmanager.cpp:64
modelcolumnmanager.h
settings.h
Settings::setContactModelColumns
static void setContactModelColumns(const QList< int > &v)
Set ContactModelColumns.
Definition: settings.h:130
Settings::contactModelColumns
static QList< int > contactModelColumns()
Get ContactModelColumns.
Definition: settings.h:140
Note
Definition: ringbinderstyle.cpp:53
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