24 #include <KABC/Addressee>
28 #include <QtCore/QEvent>
29 #include <QtCore/QTimer>
30 #include <QContextMenuEvent>
31 #include <QHeaderView>
36 :
QObject( parent ), mModel( model ), mWidget( 0 )
43 Akonadi::ContactsTreeModel::Columns columns;
45 foreach (
int column, settingsColumns ) {
46 columns.append( ( Akonadi::ContactsTreeModel::Column )column );
49 mModel->setColumns( columns );
54 const Akonadi::ContactsTreeModel::Columns columns = mModel->columns();
55 QList<int> settingsColumns;
57 foreach (
int column, columns ) {
58 settingsColumns.append( (
int)column );
67 mWidget->installEventFilter(
this );
72 if ( watched == mWidget ) {
73 if ( event->type() == QEvent::ContextMenu ) {
76 Akonadi::ContactsTreeModel::Columns columns = mModel->columns();
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 );
84 QAction *familyNameAction = menu.addAction( i18n(
"Family Name" ) );
85 familyNameAction->setCheckable(
true );
86 familyNameAction->setChecked(
87 columns.contains( Akonadi::ContactsTreeModel::FamilyName ) );
89 QAction *givenNameAction = menu.addAction( i18n(
"Given Name" ) );
90 givenNameAction->setCheckable(
true );
91 givenNameAction->setChecked(
92 columns.contains( Akonadi::ContactsTreeModel::GivenName ) );
94 QAction *birthdayAction = menu.addAction( KABC::Addressee::birthdayLabel() );
95 birthdayAction->setCheckable(
true );
96 birthdayAction->setChecked(
99 QAction *homeAddressAction = menu.addAction( i18n(
"Home Address" ) );
100 homeAddressAction->setCheckable(
true );
101 homeAddressAction->setChecked(
102 columns.contains( Akonadi::ContactsTreeModel::HomeAddress ) );
104 QAction *businessAddressAction = menu.addAction( i18n(
"Business Address" ) );
105 businessAddressAction->setCheckable(
true );
106 businessAddressAction->setChecked(
107 columns.contains( Akonadi::ContactsTreeModel::BusinessAddress ) );
109 QAction *phoneNumbersAction = menu.addAction( i18n(
"Phone Numbers" ) );
110 phoneNumbersAction->setCheckable(
true );
111 phoneNumbersAction->setChecked(
114 QAction *preferredEmailAction = menu.addAction( i18n(
"Preferred EMail" ) );
115 preferredEmailAction->setCheckable(
true );
116 preferredEmailAction->setChecked(
117 columns.contains( Akonadi::ContactsTreeModel::PreferredEmail ) );
119 QAction *allEmailsAction = menu.addAction( i18n(
"All EMails" ) );
120 allEmailsAction->setCheckable(
true );
121 allEmailsAction->setChecked(
122 columns.contains( Akonadi::ContactsTreeModel::AllEmails ) );
124 QAction *organizationAction = menu.addAction( KABC::Addressee::organizationLabel() );
125 organizationAction->setCheckable(
true );
126 organizationAction->setChecked(
129 QAction *roleAction = menu.addAction( KABC::Addressee::roleLabel() );
130 roleAction->setCheckable(
true );
131 roleAction->setChecked(
132 columns.contains( Akonadi::ContactsTreeModel::Role ) );
134 QAction *homepageAction = menu.addAction( KABC::Addressee::urlLabel() );
135 homepageAction->setCheckable(
true );
136 homepageAction->setChecked(
137 columns.contains( Akonadi::ContactsTreeModel::Homepage ) );
139 QAction *noteAction = menu.addAction( KABC::Addressee::noteLabel() );
140 noteAction->setCheckable(
true );
141 noteAction->setChecked(
144 if ( menu.exec( ( ( QContextMenuEvent * )event )->globalPos() ) ) {
145 Akonadi::ContactsTreeModel::Columns columns;
147 if ( fullNameAction->isChecked() ) {
148 columns << Akonadi::ContactsTreeModel::FullName;
150 if ( familyNameAction->isChecked() ) {
151 columns << Akonadi::ContactsTreeModel::FamilyName;
153 if ( givenNameAction->isChecked() ) {
154 columns << Akonadi::ContactsTreeModel::GivenName;
156 if ( birthdayAction->isChecked() ) {
159 if ( homeAddressAction->isChecked() ) {
160 columns << Akonadi::ContactsTreeModel::HomeAddress;
162 if ( businessAddressAction->isChecked() ) {
163 columns << Akonadi::ContactsTreeModel::BusinessAddress;
165 if ( phoneNumbersAction->isChecked() ) {
168 if ( preferredEmailAction->isChecked() ) {
169 columns << Akonadi::ContactsTreeModel::PreferredEmail;
171 if ( allEmailsAction->isChecked() ) {
172 columns << Akonadi::ContactsTreeModel::AllEmails;
174 if ( organizationAction->isChecked() ) {
177 if ( roleAction->isChecked() ) {
178 columns << Akonadi::ContactsTreeModel::Role;
180 if ( homepageAction->isChecked() ) {
181 columns << Akonadi::ContactsTreeModel::Homepage;
183 if ( noteAction->isChecked() ) {
187 mModel->setColumns( columns );
188 QTimer::singleShot( 0,
this, SLOT(adaptHeaderView()) );
200 void ModelColumnManager::adaptHeaderView()
202 QHeaderView *view = qobject_cast<QHeaderView*>( mWidget );
204 view->resizeSections( QHeaderView::Stretch );
206 view->setDefaultAlignment( mModel->columns().count() == 1 ? Qt::AlignCenter : Qt::AlignLeft );
210 #include "modelcolumnmanager.moc"
void store()
Stores the user configuration.
virtual bool eventFilter(QObject *watched, QEvent *event)
ModelColumnManager(Akonadi::ContactsTreeModel *model, QObject *parent=0)
Creates a new model column manager.
void load()
Loads the user configuration and applies it to the model.
void setWidget(QWidget *view)
Sets the widget that shall provide a RMB menu to configure the columns to be shown.
static void setContactModelColumns(const QList< int > &v)
Set ContactModelColumns.
static QList< int > contactModelColumns()
Get ContactModelColumns.