author | ulf69 <ulf69> | 2004-09-03 01:34:57 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-09-03 01:34:57 (UTC) |
commit | f6b72fd55671131cd81a3357940c9337ea5d7494 (patch) (unidiff) | |
tree | 1075a46b4a7e24696eb7945e5f76bef552d75d88 /kaddressbook/views | |
parent | 7d5e6ab1868753f1f6a3b0831ba2e3c9d6ba411c (diff) | |
download | kdepimpi-f6b72fd55671131cd81a3357940c9337ea5d7494.zip kdepimpi-f6b72fd55671131cd81a3357940c9337ea5d7494.tar.gz kdepimpi-f6b72fd55671131cd81a3357940c9337ea5d7494.tar.bz2 |
sourceforge 1014886: first change to allow customized tableview
-rw-r--r-- | kaddressbook/views/kaddressbooktableview.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp index 8d2203e..66a3f0b 100644 --- a/kaddressbook/views/kaddressbooktableview.cpp +++ b/kaddressbook/views/kaddressbooktableview.cpp | |||
@@ -62,128 +62,172 @@ void KAddressBookTableView::reconstructListView() | |||
62 | disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)), | 62 | disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)), |
63 | this, SLOT(addresseeExecuted(QListViewItem*))); | 63 | this, SLOT(addresseeExecuted(QListViewItem*))); |
64 | disconnect(mListView, SIGNAL(startAddresseeDrag()), this, | 64 | disconnect(mListView, SIGNAL(startAddresseeDrag()), this, |
65 | SIGNAL(startDrag())); | 65 | SIGNAL(startDrag())); |
66 | disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)), | 66 | disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)), |
67 | this, SLOT(addresseeExecuted(QListViewItem*))); | 67 | this, SLOT(addresseeExecuted(QListViewItem*))); |
68 | 68 | ||
69 | disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, | 69 | disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, |
70 | SIGNAL(dropped(QDropEvent*))); | 70 | SIGNAL(dropped(QDropEvent*))); |
71 | delete mListView; | 71 | delete mListView; |
72 | } | 72 | } |
73 | 73 | ||
74 | mListView = new ContactListView( this, addressBook(), viewWidget() ); | 74 | mListView = new ContactListView( this, addressBook(), viewWidget() ); |
75 | 75 | ||
76 | // Add the columns | 76 | // Add the columns |
77 | KABC::Field::List fieldList = fields(); | 77 | KABC::Field::List fieldList = fields(); |
78 | KABC::Field::List::ConstIterator it; | 78 | KABC::Field::List::ConstIterator it; |
79 | 79 | ||
80 | int c = 0; | 80 | int c = 0; |
81 | for( it = fieldList.begin(); it != fieldList.end(); ++it ) { | 81 | for( it = fieldList.begin(); it != fieldList.end(); ++it ) { |
82 | mListView->addColumn( (*it)->label() ); | 82 | mListView->addColumn( (*it)->label() ); |
83 | mListView->setColumnWidthMode(c++, QListView::Manual); | 83 | mListView->setColumnWidthMode(c++, QListView::Manual); |
84 | //US | 84 | //US |
85 | // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1()); | 85 | // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1()); |
86 | } | 86 | } |
87 | 87 | ||
88 | connect(mListView, SIGNAL(selectionChanged()), | 88 | connect(mListView, SIGNAL(selectionChanged()), |
89 | this, SLOT(addresseeSelected())); | 89 | this, SLOT(addresseeSelected())); |
90 | connect(mListView, SIGNAL(startAddresseeDrag()), this, | 90 | connect(mListView, SIGNAL(startAddresseeDrag()), this, |
91 | SIGNAL(startDrag())); | 91 | SIGNAL(startDrag())); |
92 | connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, | 92 | connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, |
93 | SIGNAL(dropped(QDropEvent*))); | 93 | SIGNAL(dropped(QDropEvent*))); |
94 | 94 | ||
95 | if (KABPrefs::instance()->mHonorSingleClick) | 95 | if (KABPrefs::instance()->mHonorSingleClick) |
96 | connect(mListView, SIGNAL(executed(QListViewItem*)), | 96 | connect(mListView, SIGNAL(executed(QListViewItem*)), |
97 | this, SLOT(addresseeExecuted(QListViewItem*))); | 97 | this, SLOT(addresseeExecuted(QListViewItem*))); |
98 | else | 98 | else |
99 | connect(mListView, SIGNAL(doubleClicked(QListViewItem*)), | 99 | connect(mListView, SIGNAL(doubleClicked(QListViewItem*)), |
100 | this, SLOT(addresseeExecuted(QListViewItem*))); | 100 | this, SLOT(addresseeExecuted(QListViewItem*))); |
101 | connect(mListView, SIGNAL(returnPressed(QListViewItem*)), | 101 | connect(mListView, SIGNAL(returnPressed(QListViewItem*)), |
102 | this, SLOT(addresseeExecuted(QListViewItem*))); | 102 | this, SLOT(addresseeExecuted(QListViewItem*))); |
103 | connect(mListView, SIGNAL(signalDelete()), | 103 | connect(mListView, SIGNAL(signalDelete()), |
104 | this, SLOT(addresseeDeleted())); | 104 | this, SLOT(addresseeDeleted())); |
105 | 105 | ||
106 | //US performceimprovement. Refresh is done from the outside | 106 | //US performceimprovement. Refresh is done from the outside |
107 | //US refresh(); | 107 | //US refresh(); |
108 | 108 | ||
109 | mListView->setSorting( 0, true ); | 109 | mListView->setSorting( 0, true ); |
110 | mainLayout->addWidget( mListView ); | 110 | mainLayout->addWidget( mListView ); |
111 | mainLayout->activate(); | 111 | mainLayout->activate(); |
112 | mListView->show(); | 112 | mListView->show(); |
113 | } | 113 | } |
114 | 114 | ||
115 | void KAddressBookTableView::writeConfig(KConfig *config) | 115 | void KAddressBookTableView::writeConfig(KConfig *config) |
116 | { | 116 | { |
117 | KAddressBookView::writeConfig(config); | 117 | KAddressBookView::writeConfig(config); |
118 | 118 | ||
119 | mListView->saveLayout(config, config->group()); | 119 | mListView->saveLayout(config, config->group()); |
120 | } | 120 | } |
121 | 121 | ||
122 | void KAddressBookTableView::readConfig(KConfig *config) | 122 | void KAddressBookTableView::readConfig(KConfig *config) |
123 | { | 123 | { |
124 | KAddressBookView::readConfig( config ); | 124 | KAddressBookView::readConfig( config ); |
125 | 125 | ||
126 | // costum colors? | ||
127 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) | ||
128 | { | ||
129 | QPalette p( mListView->palette() ); | ||
130 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); | ||
131 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); | ||
132 | c = p.color(QPalette::Normal, QColorGroup::Text ); | ||
133 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); | ||
134 | c = p.color(QPalette::Normal, QColorGroup::Button ); | ||
135 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); | ||
136 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); | ||
137 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); | ||
138 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); | ||
139 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); | ||
140 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); | ||
141 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); | ||
142 | c = p.color(QPalette::Normal, QColorGroup::Base ); | ||
143 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "AlternatingBackgroundColor", &c ) ); | ||
144 | mListView->viewport()->setPalette( p ); | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | // needed if turned off during a session. | ||
149 | mListView->viewport()->setPalette( mListView->palette() ); | ||
150 | } | ||
151 | |||
152 | //custom fonts? | ||
153 | QFont f( font() ); | ||
154 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) | ||
155 | { | ||
156 | // mListView->setFont( config->readFontEntry( "TextFont", &f) ); | ||
157 | f.setBold( true ); | ||
158 | // mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | // mListView->setFont( f ); | ||
163 | f.setBold( true ); | ||
164 | // mListView->setHeaderFont( f ); | ||
165 | } | ||
166 | |||
167 | |||
168 | |||
169 | |||
126 | // The config could have changed the fields, so we need to reconstruct | 170 | // The config could have changed the fields, so we need to reconstruct |
127 | // the listview. | 171 | // the listview. |
128 | reconstructListView(); | 172 | reconstructListView(); |
129 | 173 | ||
130 | // Set the list view options | 174 | // Set the list view options |
131 | mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", | 175 | mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", |
132 | true)); | 176 | true)); |
133 | mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); | 177 | mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); |
134 | mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); | 178 | mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); |
135 | 179 | ||
136 | if (config->readBoolEntry("Background", false)) | 180 | if (config->readBoolEntry("Background", false)) |
137 | mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); | 181 | mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); |
138 | 182 | ||
139 | // Restore the layout of the listview | 183 | // Restore the layout of the listview |
140 | mListView->restoreLayout(config, config->group()); | 184 | mListView->restoreLayout(config, config->group()); |
141 | } | 185 | } |
142 | 186 | ||
143 | void KAddressBookTableView::refresh(QString uid) | 187 | void KAddressBookTableView::refresh(QString uid) |
144 | { | 188 | { |
145 | // For now just repopulate. In reality this method should | 189 | // For now just repopulate. In reality this method should |
146 | // check the value of uid, and if valid iterate through | 190 | // check the value of uid, and if valid iterate through |
147 | // the listview to find the entry, then tell it to refresh. | 191 | // the listview to find the entry, then tell it to refresh. |
148 | 192 | ||
149 | if (uid.isNull()) { | 193 | if (uid.isNull()) { |
150 | // Clear the list view | 194 | // Clear the list view |
151 | QString currentUID, nextUID; | 195 | QString currentUID, nextUID; |
152 | #ifndef KAB_EMBEDDED | 196 | #ifndef KAB_EMBEDDED |
153 | ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); | 197 | ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); |
154 | #else //KAB_EMBEDDED | 198 | #else //KAB_EMBEDDED |
155 | ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() ); | 199 | ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() ); |
156 | #endif //KAB_EMBEDDED | 200 | #endif //KAB_EMBEDDED |
157 | 201 | ||
158 | if ( currentItem ) { | 202 | if ( currentItem ) { |
159 | #ifndef KAB_EMBEDDED | 203 | #ifndef KAB_EMBEDDED |
160 | ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() ); | 204 | ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() ); |
161 | #else //KAB_EMBEDDED | 205 | #else //KAB_EMBEDDED |
162 | ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() ); | 206 | ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() ); |
163 | #endif //KAB_EMBEDDED | 207 | #endif //KAB_EMBEDDED |
164 | if ( nextItem ) | 208 | if ( nextItem ) |
165 | nextUID = nextItem->addressee().uid(); | 209 | nextUID = nextItem->addressee().uid(); |
166 | currentUID = currentItem->addressee().uid(); | 210 | currentUID = currentItem->addressee().uid(); |
167 | } | 211 | } |
168 | 212 | ||
169 | mListView->clear(); | 213 | mListView->clear(); |
170 | 214 | ||
171 | currentItem = 0; | 215 | currentItem = 0; |
172 | KABC::Addressee::List addresseeList = addressees(); | 216 | KABC::Addressee::List addresseeList = addressees(); |
173 | KABC::Addressee::List::Iterator it; | 217 | KABC::Addressee::List::Iterator it; |
174 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 218 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
175 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); | 219 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); |
176 | if ( (*it).uid() == currentUID ) | 220 | if ( (*it).uid() == currentUID ) |
177 | currentItem = item; | 221 | currentItem = item; |
178 | else if ( (*it).uid() == nextUID && !currentItem ) | 222 | else if ( (*it).uid() == nextUID && !currentItem ) |
179 | currentItem = item; | 223 | currentItem = item; |
180 | } | 224 | } |
181 | 225 | ||
182 | // Sometimes the background pixmap gets messed up when we add lots | 226 | // Sometimes the background pixmap gets messed up when we add lots |
183 | // of items. | 227 | // of items. |
184 | mListView->repaint(); | 228 | mListView->repaint(); |
185 | 229 | ||
186 | if ( currentItem ) { | 230 | if ( currentItem ) { |
187 | mListView->setCurrentItem( currentItem ); | 231 | mListView->setCurrentItem( currentItem ); |
188 | mListView->ensureItemVisible( currentItem ); | 232 | mListView->ensureItemVisible( currentItem ); |
189 | } | 233 | } |