author | ulf69 <ulf69> | 2004-09-09 18:55:32 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-09-09 18:55:32 (UTC) |
commit | 72860f2b84ba97de9223238d9fb97edc0804cc68 (patch) (unidiff) | |
tree | 0f0ace3690f299260f08a63b4851c422d30cb7be /kaddressbook | |
parent | 578bb7c0193afcb84bb08a65f17f6abc0375676e (diff) | |
download | kdepimpi-72860f2b84ba97de9223238d9fb97edc0804cc68.zip kdepimpi-72860f2b84ba97de9223238d9fb97edc0804cc68.tar.gz kdepimpi-72860f2b84ba97de9223238d9fb97edc0804cc68.tar.bz2 |
sourceforge 1014886: select fonts and colors for tableview
-rw-r--r-- | kaddressbook/views/contactlistview.cpp | 5 | ||||
-rw-r--r-- | kaddressbook/views/contactlistview.h | 1 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbooktableview.cpp | 29 |
3 files changed, 26 insertions, 9 deletions
diff --git a/kaddressbook/views/contactlistview.cpp b/kaddressbook/views/contactlistview.cpp index 9804e28..4cc22ea 100644 --- a/kaddressbook/views/contactlistview.cpp +++ b/kaddressbook/views/contactlistview.cpp | |||
@@ -1,340 +1,345 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> | 3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qheader.h> | 24 | #include <qheader.h> |
25 | #include <qiconset.h> | 25 | #include <qiconset.h> |
26 | #include <qimage.h> | 26 | #include <qimage.h> |
27 | #include <qdragobject.h> | 27 | #include <qdragobject.h> |
28 | #include <qcombobox.h> | 28 | #include <qcombobox.h> |
29 | #include <qpainter.h> | 29 | #include <qpainter.h> |
30 | #include <qbrush.h> | 30 | #include <qbrush.h> |
31 | #include <qevent.h> | 31 | #include <qevent.h> |
32 | 32 | ||
33 | #include <klocale.h> | 33 | #include <klocale.h> |
34 | #include <kglobalsettings.h> | 34 | #include <kglobalsettings.h> |
35 | #include <kiconloader.h> | 35 | #include <kiconloader.h> |
36 | #include <kdebug.h> | 36 | #include <kdebug.h> |
37 | #include <kconfig.h> | 37 | #include <kconfig.h> |
38 | #include <kapplication.h> | 38 | #include <kapplication.h> |
39 | #include <kurl.h> | 39 | #include <kurl.h> |
40 | 40 | ||
41 | #include "kaddressbooktableview.h" | 41 | #include "kaddressbooktableview.h" |
42 | 42 | ||
43 | #include "contactlistview.h" | 43 | #include "contactlistview.h" |
44 | 44 | ||
45 | ///////////////////////////////// | 45 | ///////////////////////////////// |
46 | // DynamicTip Methods | 46 | // DynamicTip Methods |
47 | 47 | ||
48 | DynamicTip::DynamicTip( ContactListView *parent) | 48 | DynamicTip::DynamicTip( ContactListView *parent) |
49 | : QToolTip( parent ) | 49 | : QToolTip( parent ) |
50 | { | 50 | { |
51 | } | 51 | } |
52 | 52 | ||
53 | void DynamicTip::maybeTip( const QPoint &pos ) | 53 | void DynamicTip::maybeTip( const QPoint &pos ) |
54 | { | 54 | { |
55 | static bool ishidden = true; | 55 | static bool ishidden = true; |
56 | if (!parentWidget()->inherits( "ContactListView" )) | 56 | if (!parentWidget()->inherits( "ContactListView" )) |
57 | return; | 57 | return; |
58 | 58 | ||
59 | ContactListView *plv = (ContactListView*)parentWidget(); | 59 | ContactListView *plv = (ContactListView*)parentWidget(); |
60 | if (!plv->tooltips()) | 60 | if (!plv->tooltips()) |
61 | return; | 61 | return; |
62 | 62 | ||
63 | QPoint posVp = plv->viewport()->pos(); | 63 | QPoint posVp = plv->viewport()->pos(); |
64 | 64 | ||
65 | QListViewItem *lvi = plv->itemAt( pos - posVp ); | 65 | QListViewItem *lvi = plv->itemAt( pos - posVp ); |
66 | if (!lvi) | 66 | if (!lvi) |
67 | return; | 67 | return; |
68 | 68 | ||
69 | #ifndef KAB_EMBEDDED | 69 | #ifndef KAB_EMBEDDED |
70 | ContactListViewItem *plvi = dynamic_cast< ContactListViewItem* >(lvi); | 70 | ContactListViewItem *plvi = dynamic_cast< ContactListViewItem* >(lvi); |
71 | #else //KAB_EMBEDDED | 71 | #else //KAB_EMBEDDED |
72 | ContactListViewItem *plvi = (ContactListViewItem*)(lvi); | 72 | ContactListViewItem *plvi = (ContactListViewItem*)(lvi); |
73 | #endif //KAB_EMBEDDED | 73 | #endif //KAB_EMBEDDED |
74 | 74 | ||
75 | if (!plvi) | 75 | if (!plvi) |
76 | return; | 76 | return; |
77 | 77 | ||
78 | if (ishidden) { | 78 | if (ishidden) { |
79 | QString s; | 79 | QString s; |
80 | QRect r = plv->itemRect( lvi ); | 80 | QRect r = plv->itemRect( lvi ); |
81 | r.moveBy( posVp.x(), posVp.y() ); | 81 | r.moveBy( posVp.x(), posVp.y() ); |
82 | 82 | ||
83 | //kdDebug() << "Tip rec: " << r.x() << "," << r.y() << "," << r.width() | 83 | //kdDebug() << "Tip rec: " << r.x() << "," << r.y() << "," << r.width() |
84 | // << "," << r.height() << endl; | 84 | // << "," << r.height() << endl; |
85 | 85 | ||
86 | KABC::Addressee a = plvi->addressee(); | 86 | KABC::Addressee a = plvi->addressee(); |
87 | if (a.isEmpty()) | 87 | if (a.isEmpty()) |
88 | return; | 88 | return; |
89 | 89 | ||
90 | s += i18n("label: value", "%1: %2").arg(a.formattedNameLabel()) | 90 | s += i18n("label: value", "%1: %2").arg(a.formattedNameLabel()) |
91 | .arg(a.formattedName()); | 91 | .arg(a.formattedName()); |
92 | 92 | ||
93 | s += '\n'; | 93 | s += '\n'; |
94 | s += i18n("label: value", "%1: %2").arg(a.organizationLabel()) | 94 | s += i18n("label: value", "%1: %2").arg(a.organizationLabel()) |
95 | .arg(a.organization()); | 95 | .arg(a.organization()); |
96 | 96 | ||
97 | QString notes = a.note().stripWhiteSpace(); | 97 | QString notes = a.note().stripWhiteSpace(); |
98 | if ( !notes.isEmpty() ) { | 98 | if ( !notes.isEmpty() ) { |
99 | notes += '\n'; | 99 | notes += '\n'; |
100 | s += '\n' + i18n("label: value", "%1: \n").arg(a.noteLabel()); | 100 | s += '\n' + i18n("label: value", "%1: \n").arg(a.noteLabel()); |
101 | QFontMetrics fm( font() ); | 101 | QFontMetrics fm( font() ); |
102 | 102 | ||
103 | // Begin word wrap code based on QMultiLineEdit code | 103 | // Begin word wrap code based on QMultiLineEdit code |
104 | int i = 0; | 104 | int i = 0; |
105 | bool doBreak = false; | 105 | bool doBreak = false; |
106 | int linew = 0; | 106 | int linew = 0; |
107 | int lastSpace = -1; | 107 | int lastSpace = -1; |
108 | int a = 0; | 108 | int a = 0; |
109 | int lastw = 0; | 109 | int lastw = 0; |
110 | 110 | ||
111 | while ( i < int(notes.length()) ) { | 111 | while ( i < int(notes.length()) ) { |
112 | doBreak = FALSE; | 112 | doBreak = FALSE; |
113 | if ( notes[i] != '\n' ) | 113 | if ( notes[i] != '\n' ) |
114 | linew += fm.width( notes[i] ); | 114 | linew += fm.width( notes[i] ); |
115 | 115 | ||
116 | if ( lastSpace >= a && notes[i] != '\n' ) | 116 | if ( lastSpace >= a && notes[i] != '\n' ) |
117 | if (linew >= parentWidget()->width()) { | 117 | if (linew >= parentWidget()->width()) { |
118 | doBreak = TRUE; | 118 | doBreak = TRUE; |
119 | if ( lastSpace > a ) { | 119 | if ( lastSpace > a ) { |
120 | i = lastSpace; | 120 | i = lastSpace; |
121 | linew = lastw; | 121 | linew = lastw; |
122 | } | 122 | } |
123 | else | 123 | else |
124 | i = QMAX( a, i-1 ); | 124 | i = QMAX( a, i-1 ); |
125 | } | 125 | } |
126 | 126 | ||
127 | if ( notes[i] == '\n' || doBreak ) { | 127 | if ( notes[i] == '\n' || doBreak ) { |
128 | s += notes.mid( a, i - a + (doBreak?1:0) ) +"\n"; | 128 | s += notes.mid( a, i - a + (doBreak?1:0) ) +"\n"; |
129 | 129 | ||
130 | a = i + 1; | 130 | a = i + 1; |
131 | lastSpace = a; | 131 | lastSpace = a; |
132 | linew = 0; | 132 | linew = 0; |
133 | } | 133 | } |
134 | 134 | ||
135 | if ( notes[i].isSpace() ) { | 135 | if ( notes[i].isSpace() ) { |
136 | lastSpace = i; | 136 | lastSpace = i; |
137 | lastw = linew; | 137 | lastw = linew; |
138 | } | 138 | } |
139 | 139 | ||
140 | if ( lastSpace <= a ) { | 140 | if ( lastSpace <= a ) { |
141 | lastw = linew; | 141 | lastw = linew; |
142 | } | 142 | } |
143 | 143 | ||
144 | ++i; | 144 | ++i; |
145 | } | 145 | } |
146 | } | 146 | } |
147 | 147 | ||
148 | tip( r, s ); | 148 | tip( r, s ); |
149 | } | 149 | } |
150 | else | 150 | else |
151 | hide(); | 151 | hide(); |
152 | ishidden = !ishidden; | 152 | ishidden = !ishidden; |
153 | 153 | ||
154 | } | 154 | } |
155 | 155 | ||
156 | /////////////////////////// | 156 | /////////////////////////// |
157 | // ContactListViewItem Methods | 157 | // ContactListViewItem Methods |
158 | 158 | ||
159 | ContactListViewItem::ContactListViewItem(const KABC::Addressee &a, | 159 | ContactListViewItem::ContactListViewItem(const KABC::Addressee &a, |
160 | ContactListView *parent, | 160 | ContactListView *parent, |
161 | KABC::AddressBook *doc, | 161 | KABC::AddressBook *doc, |
162 | const KABC::Field::List &fields ) | 162 | const KABC::Field::List &fields ) |
163 | : KListViewItem(parent), mAddressee(a), mFields( fields ), | 163 | : KListViewItem(parent), mAddressee(a), mFields( fields ), |
164 | parentListView( parent ), mDocument(doc) | 164 | parentListView( parent ), mDocument(doc) |
165 | { | 165 | { |
166 | refresh(); | 166 | refresh(); |
167 | } | 167 | } |
168 | 168 | ||
169 | QString ContactListViewItem::key(int column, bool ascending) const | 169 | QString ContactListViewItem::key(int column, bool ascending) const |
170 | { | 170 | { |
171 | return QListViewItem::key(column, ascending).lower(); | 171 | return QListViewItem::key(column, ascending).lower(); |
172 | } | 172 | } |
173 | 173 | ||
174 | void ContactListViewItem::paintCell(QPainter * p, | 174 | void ContactListViewItem::paintCell(QPainter * p, |
175 | const QColorGroup & cg, | 175 | const QColorGroup & cg, |
176 | int column, | 176 | int column, |
177 | int width, | 177 | int width, |
178 | int align) | 178 | int align) |
179 | { | 179 | { |
180 | KListViewItem::paintCell(p, cg, column, width, align); | 180 | KListViewItem::paintCell(p, cg, column, width, align); |
181 | 181 | ||
182 | if ( !p ) | 182 | if ( !p ) |
183 | return; | 183 | return; |
184 | 184 | ||
185 | if (parentListView->singleLine()) { | 185 | if (parentListView->singleLine()) { |
186 | p->setPen( parentListView->alternateColor() ); | 186 | p->setPen( parentListView->alternateColor() ); |
187 | p->drawLine( 0, height() - 1, width, height() - 1 ); | 187 | p->drawLine( 0, height() - 1, width, height() - 1 ); |
188 | } | 188 | } |
189 | } | 189 | } |
190 | 190 | ||
191 | 191 | ||
192 | ContactListView *ContactListViewItem::parent() | 192 | ContactListView *ContactListViewItem::parent() |
193 | { | 193 | { |
194 | return parentListView; | 194 | return parentListView; |
195 | } | 195 | } |
196 | 196 | ||
197 | 197 | ||
198 | void ContactListViewItem::refresh() | 198 | void ContactListViewItem::refresh() |
199 | { | 199 | { |
200 | // Update our addressee, since it may have changed else were | 200 | // Update our addressee, since it may have changed else were |
201 | mAddressee = mDocument->findByUid(mAddressee.uid()); | 201 | mAddressee = mDocument->findByUid(mAddressee.uid()); |
202 | if (mAddressee.isEmpty()) | 202 | if (mAddressee.isEmpty()) |
203 | return; | 203 | return; |
204 | 204 | ||
205 | int i = 0; | 205 | int i = 0; |
206 | KABC::Field::List::ConstIterator it; | 206 | KABC::Field::List::ConstIterator it; |
207 | for( it = mFields.begin(); it != mFields.end(); ++it ) { | 207 | for( it = mFields.begin(); it != mFields.end(); ++it ) { |
208 | setText( i++, (*it)->value( mAddressee ) ); | 208 | setText( i++, (*it)->value( mAddressee ) ); |
209 | } | 209 | } |
210 | } | 210 | } |
211 | 211 | ||
212 | /////////////////////////////// | 212 | /////////////////////////////// |
213 | // ContactListView | 213 | // ContactListView |
214 | 214 | ||
215 | ContactListView::ContactListView(KAddressBookTableView *view, | 215 | ContactListView::ContactListView(KAddressBookTableView *view, |
216 | KABC::AddressBook* /* doc */, | 216 | KABC::AddressBook* /* doc */, |
217 | QWidget *parent, | 217 | QWidget *parent, |
218 | const char *name ) | 218 | const char *name ) |
219 | : KListView( parent, name ), | 219 | : KListView( parent, name ), |
220 | pabWidget( view ), | 220 | pabWidget( view ), |
221 | oldColumn( 0 ) | 221 | oldColumn( 0 ) |
222 | { | 222 | { |
223 | mABackground = true; | 223 | mABackground = true; |
224 | mSingleLine = false; | 224 | mSingleLine = false; |
225 | mToolTips = true; | 225 | mToolTips = true; |
226 | #ifndef KAB_EMBEDDED | 226 | #ifndef KAB_EMBEDDED |
227 | mAlternateColor = KGlobalSettings::alternateBackgroundColor(); | 227 | mAlternateColor = KGlobalSettings::alternateBackgroundColor(); |
228 | #else //KAB_EMBEDDED | 228 | #else //KAB_EMBEDDED |
229 | mAlternateColor = QColor(240, 240, 240); | 229 | mAlternateColor = QColor(240, 240, 240); |
230 | #endif //KAB_EMBEDDED | 230 | #endif //KAB_EMBEDDED |
231 | 231 | ||
232 | setAlternateBackgroundEnabled(mABackground); | 232 | setAlternateBackgroundEnabled(mABackground); |
233 | setAcceptDrops( true ); | 233 | setAcceptDrops( true ); |
234 | viewport()->setAcceptDrops( true ); | 234 | viewport()->setAcceptDrops( true ); |
235 | setAllColumnsShowFocus( true ); | 235 | setAllColumnsShowFocus( true ); |
236 | setShowSortIndicator(true); | 236 | setShowSortIndicator(true); |
237 | 237 | ||
238 | setSelectionModeExt( KListView::Extended ); | 238 | setSelectionModeExt( KListView::Extended ); |
239 | setDropVisualizer(false); | 239 | setDropVisualizer(false); |
240 | // setFrameStyle(QFrame::NoFrame); | 240 | // setFrameStyle(QFrame::NoFrame); |
241 | //setLineWidth ( 0 ); | 241 | //setLineWidth ( 0 ); |
242 | //setMidLineWidth ( 0 ); | 242 | //setMidLineWidth ( 0 ); |
243 | //setMargin ( 0 ); | 243 | //setMargin ( 0 ); |
244 | #ifndef KAB_EMBEDDED | 244 | #ifndef KAB_EMBEDDED |
245 | connect(this, SIGNAL(dropped(QDropEvent*)), | 245 | connect(this, SIGNAL(dropped(QDropEvent*)), |
246 | this, SLOT(itemDropped(QDropEvent*))); | 246 | this, SLOT(itemDropped(QDropEvent*))); |
247 | #endif //KAB_EMBEDDED | 247 | #endif //KAB_EMBEDDED |
248 | 248 | ||
249 | 249 | ||
250 | new DynamicTip( this ); | 250 | new DynamicTip( this ); |
251 | } | 251 | } |
252 | 252 | ||
253 | void ContactListView::setAlternateColor(const QColor &m_AlternateColor) | ||
254 | { | ||
255 | mAlternateColor = m_AlternateColor; | ||
256 | } | ||
257 | |||
253 | void ContactListView::paintEmptyArea( QPainter * p, const QRect & rect ) | 258 | void ContactListView::paintEmptyArea( QPainter * p, const QRect & rect ) |
254 | { | 259 | { |
255 | QBrush b = palette().brush(QPalette::Active, QColorGroup::Base); | 260 | QBrush b = palette().brush(QPalette::Active, QColorGroup::Base); |
256 | 261 | ||
257 | // Get the brush, which will have the background pixmap if there is one. | 262 | // Get the brush, which will have the background pixmap if there is one. |
258 | if (b.pixmap()) | 263 | if (b.pixmap()) |
259 | { | 264 | { |
260 | p->drawTiledPixmap( rect.left(), rect.top(), rect.width(), rect.height(), | 265 | p->drawTiledPixmap( rect.left(), rect.top(), rect.width(), rect.height(), |
261 | *(b.pixmap()), | 266 | *(b.pixmap()), |
262 | rect.left() + contentsX(), | 267 | rect.left() + contentsX(), |
263 | rect.top() + contentsY() ); | 268 | rect.top() + contentsY() ); |
264 | } | 269 | } |
265 | 270 | ||
266 | else | 271 | else |
267 | { | 272 | { |
268 | // Do a normal paint | 273 | // Do a normal paint |
269 | KListView::paintEmptyArea(p, rect); | 274 | KListView::paintEmptyArea(p, rect); |
270 | } | 275 | } |
271 | } | 276 | } |
272 | 277 | ||
273 | void ContactListView::contentsMousePressEvent(QMouseEvent* e) | 278 | void ContactListView::contentsMousePressEvent(QMouseEvent* e) |
274 | { | 279 | { |
275 | presspos = e->pos(); | 280 | presspos = e->pos(); |
276 | KListView::contentsMousePressEvent(e); | 281 | KListView::contentsMousePressEvent(e); |
277 | } | 282 | } |
278 | 283 | ||
279 | 284 | ||
280 | // To initiate a drag operation | 285 | // To initiate a drag operation |
281 | void ContactListView::contentsMouseMoveEvent( QMouseEvent *e ) | 286 | void ContactListView::contentsMouseMoveEvent( QMouseEvent *e ) |
282 | { | 287 | { |
283 | if ((e->state() & LeftButton) && (e->pos() - presspos).manhattanLength() > 4 ) { | 288 | if ((e->state() & LeftButton) && (e->pos() - presspos).manhattanLength() > 4 ) { |
284 | emit startAddresseeDrag(); | 289 | emit startAddresseeDrag(); |
285 | } | 290 | } |
286 | else | 291 | else |
287 | KListView::contentsMouseMoveEvent( e ); | 292 | KListView::contentsMouseMoveEvent( e ); |
288 | } | 293 | } |
289 | 294 | ||
290 | bool ContactListView::acceptDrag(QDropEvent *e) const | 295 | bool ContactListView::acceptDrag(QDropEvent *e) const |
291 | { | 296 | { |
292 | #ifndef KAB_EMBEDDED | 297 | #ifndef KAB_EMBEDDED |
293 | return QTextDrag::canDecode(e); | 298 | return QTextDrag::canDecode(e); |
294 | #else //KAB_EMBEDDED | 299 | #else //KAB_EMBEDDED |
295 | qDebug("ContactListView::acceptDrag has to be fixed"); | 300 | qDebug("ContactListView::acceptDrag has to be fixed"); |
296 | return false; | 301 | return false; |
297 | #endif //KAB_EMBEDDED | 302 | #endif //KAB_EMBEDDED |
298 | } | 303 | } |
299 | 304 | ||
300 | void ContactListView::itemDropped(QDropEvent *e) | 305 | void ContactListView::itemDropped(QDropEvent *e) |
301 | { | 306 | { |
302 | contentsDropEvent(e); | 307 | contentsDropEvent(e); |
303 | } | 308 | } |
304 | 309 | ||
305 | void ContactListView::contentsDropEvent( QDropEvent *e ) | 310 | void ContactListView::contentsDropEvent( QDropEvent *e ) |
306 | { | 311 | { |
307 | emit addresseeDropped(e); | 312 | emit addresseeDropped(e); |
308 | } | 313 | } |
309 | 314 | ||
310 | void ContactListView::setAlternateBackgroundEnabled(bool enabled) | 315 | void ContactListView::setAlternateBackgroundEnabled(bool enabled) |
311 | { | 316 | { |
312 | mABackground = enabled; | 317 | mABackground = enabled; |
313 | 318 | ||
314 | if (mABackground) | 319 | if (mABackground) |
315 | { | 320 | { |
316 | setAlternateBackground(mAlternateColor); | 321 | setAlternateBackground(mAlternateColor); |
317 | } | 322 | } |
318 | else | 323 | else |
319 | { | 324 | { |
320 | setAlternateBackground(QColor()); | 325 | setAlternateBackground(QColor()); |
321 | } | 326 | } |
322 | } | 327 | } |
323 | 328 | ||
324 | void ContactListView::setBackgroundPixmap(const QString &filename) | 329 | void ContactListView::setBackgroundPixmap(const QString &filename) |
325 | { | 330 | { |
326 | if (filename.isEmpty()) | 331 | if (filename.isEmpty()) |
327 | { | 332 | { |
328 | unsetPalette(); | 333 | unsetPalette(); |
329 | } | 334 | } |
330 | else | 335 | else |
331 | { | 336 | { |
332 | qDebug("ContactListView::setBackgroundPixmap has to be verified"); | 337 | qDebug("ContactListView::setBackgroundPixmap has to be verified"); |
333 | //US setPaletteBackgroundPixmap(QPixmap(filename)); | 338 | //US setPaletteBackgroundPixmap(QPixmap(filename)); |
334 | KListView::setBackgroundPixmap((const QPixmap&)QPixmap(filename)); | 339 | KListView::setBackgroundPixmap((const QPixmap&)QPixmap(filename)); |
335 | } | 340 | } |
336 | 341 | ||
337 | } | 342 | } |
338 | #ifndef KAB_EMBEDDED | 343 | #ifndef KAB_EMBEDDED |
339 | #include "contactlistview.moc" | 344 | #include "contactlistview.moc" |
340 | #endif //KAB_EMBEDDED | 345 | #endif //KAB_EMBEDDED |
diff --git a/kaddressbook/views/contactlistview.h b/kaddressbook/views/contactlistview.h index ae9c994..fad7f38 100644 --- a/kaddressbook/views/contactlistview.h +++ b/kaddressbook/views/contactlistview.h | |||
@@ -1,128 +1,129 @@ | |||
1 | #ifndef CONTACTLISTVIEW_H | 1 | #ifndef CONTACTLISTVIEW_H |
2 | #define CONTACTLISTVIEW_H | 2 | #define CONTACTLISTVIEW_H |
3 | 3 | ||
4 | #include <qcolor.h> | 4 | #include <qcolor.h> |
5 | #include <qpixmap.h> | 5 | #include <qpixmap.h> |
6 | #include <qtooltip.h> | 6 | #include <qtooltip.h> |
7 | #include <qstring.h> | 7 | #include <qstring.h> |
8 | 8 | ||
9 | #include <klistview.h> | 9 | #include <klistview.h> |
10 | 10 | ||
11 | #include <kabc/field.h> | 11 | #include <kabc/field.h> |
12 | #include <kabc/addressee.h> | 12 | #include <kabc/addressee.h> |
13 | #include <kabc/addressbook.h> | 13 | #include <kabc/addressbook.h> |
14 | 14 | ||
15 | 15 | ||
16 | class QDropEvent; | 16 | class QDropEvent; |
17 | class KAddressBookTableView; | 17 | class KAddressBookTableView; |
18 | class ContactListView; | 18 | class ContactListView; |
19 | 19 | ||
20 | /** The whole tooltip design needs a lot of work. Currently it is | 20 | /** The whole tooltip design needs a lot of work. Currently it is |
21 | * hacked together to function. | 21 | * hacked together to function. |
22 | */ | 22 | */ |
23 | class DynamicTip : public QToolTip | 23 | class DynamicTip : public QToolTip |
24 | { | 24 | { |
25 | public: | 25 | public: |
26 | DynamicTip( ContactListView * parent ); | 26 | DynamicTip( ContactListView * parent ); |
27 | 27 | ||
28 | protected: | 28 | protected: |
29 | void maybeTip( const QPoint & ); | 29 | void maybeTip( const QPoint & ); |
30 | 30 | ||
31 | private: | 31 | private: |
32 | }; | 32 | }; |
33 | 33 | ||
34 | class ContactListViewItem : public KListViewItem | 34 | class ContactListViewItem : public KListViewItem |
35 | { | 35 | { |
36 | 36 | ||
37 | public: | 37 | public: |
38 | ContactListViewItem(const KABC::Addressee &a, ContactListView* parent, | 38 | ContactListViewItem(const KABC::Addressee &a, ContactListView* parent, |
39 | KABC::AddressBook *doc, const KABC::Field::List &fields ); | 39 | KABC::AddressBook *doc, const KABC::Field::List &fields ); |
40 | const KABC::Addressee &addressee() const { return mAddressee; } | 40 | const KABC::Addressee &addressee() const { return mAddressee; } |
41 | virtual void refresh(); | 41 | virtual void refresh(); |
42 | virtual ContactListView* parent(); | 42 | virtual ContactListView* parent(); |
43 | virtual QString key ( int, bool ) const; | 43 | virtual QString key ( int, bool ) const; |
44 | 44 | ||
45 | /** Adds the border around the cell if the user wants it. | 45 | /** Adds the border around the cell if the user wants it. |
46 | * This is how the single line config option is implemented. | 46 | * This is how the single line config option is implemented. |
47 | */ | 47 | */ |
48 | virtual void paintCell(QPainter * p, const QColorGroup & cg, | 48 | virtual void paintCell(QPainter * p, const QColorGroup & cg, |
49 | int column, int width, int align ); | 49 | int column, int width, int align ); |
50 | 50 | ||
51 | private: | 51 | private: |
52 | KABC::Addressee mAddressee; | 52 | KABC::Addressee mAddressee; |
53 | KABC::Field::List mFields; | 53 | KABC::Field::List mFields; |
54 | ContactListView *parentListView; | 54 | ContactListView *parentListView; |
55 | KABC::AddressBook *mDocument; | 55 | KABC::AddressBook *mDocument; |
56 | }; | 56 | }; |
57 | 57 | ||
58 | 58 | ||
59 | ///////////////////////////////////////////// | 59 | ///////////////////////////////////////////// |
60 | // ContactListView | 60 | // ContactListView |
61 | 61 | ||
62 | class ContactListView : public KListView | 62 | class ContactListView : public KListView |
63 | { | 63 | { |
64 | Q_OBJECT | 64 | Q_OBJECT |
65 | 65 | ||
66 | public: | 66 | public: |
67 | ContactListView(KAddressBookTableView *view, | 67 | ContactListView(KAddressBookTableView *view, |
68 | KABC::AddressBook *doc, | 68 | KABC::AddressBook *doc, |
69 | QWidget *parent, | 69 | QWidget *parent, |
70 | const char *name = 0L ); | 70 | const char *name = 0L ); |
71 | virtual ~ContactListView() {} | 71 | virtual ~ContactListView() {} |
72 | //void resort(); | 72 | //void resort(); |
73 | 73 | ||
74 | /** Returns true if tooltips should be displayed, false otherwise | 74 | /** Returns true if tooltips should be displayed, false otherwise |
75 | */ | 75 | */ |
76 | bool tooltips() const { return mToolTips; } | 76 | bool tooltips() const { return mToolTips; } |
77 | void setToolTipsEnabled(bool enabled) { mToolTips = enabled; } | 77 | void setToolTipsEnabled(bool enabled) { mToolTips = enabled; } |
78 | 78 | ||
79 | bool alternateBackground() const { return mABackground; } | 79 | bool alternateBackground() const { return mABackground; } |
80 | void setAlternateBackgroundEnabled(bool enabled); | 80 | void setAlternateBackgroundEnabled(bool enabled); |
81 | 81 | ||
82 | bool singleLine() const { return mSingleLine; } | 82 | bool singleLine() const { return mSingleLine; } |
83 | void setSingleLineEnabled(bool enabled) { mSingleLine = enabled; } | 83 | void setSingleLineEnabled(bool enabled) { mSingleLine = enabled; } |
84 | 84 | ||
85 | const QColor &alternateColor() const { return mAlternateColor; } | 85 | const QColor &alternateColor() const { return mAlternateColor; } |
86 | void setAlternateColor(const QColor &mAlternateColor); | ||
86 | 87 | ||
87 | /** Sets the background pixmap to <i>filename</i>. If the | 88 | /** Sets the background pixmap to <i>filename</i>. If the |
88 | * QString is empty (QString::isEmpty()), then the background | 89 | * QString is empty (QString::isEmpty()), then the background |
89 | * pixmap will be disabled. | 90 | * pixmap will be disabled. |
90 | */ | 91 | */ |
91 | void setBackgroundPixmap(const QString &filename); | 92 | void setBackgroundPixmap(const QString &filename); |
92 | 93 | ||
93 | protected: | 94 | protected: |
94 | /** Paints the background pixmap in the empty area. This method is needed | 95 | /** Paints the background pixmap in the empty area. This method is needed |
95 | * since Qt::FixedPixmap will not scroll with the list view. | 96 | * since Qt::FixedPixmap will not scroll with the list view. |
96 | */ | 97 | */ |
97 | virtual void paintEmptyArea( QPainter * p, const QRect & rect ); | 98 | virtual void paintEmptyArea( QPainter * p, const QRect & rect ); |
98 | virtual void contentsMousePressEvent(QMouseEvent*); | 99 | virtual void contentsMousePressEvent(QMouseEvent*); |
99 | void contentsMouseMoveEvent( QMouseEvent *e ); | 100 | void contentsMouseMoveEvent( QMouseEvent *e ); |
100 | void contentsDropEvent( QDropEvent *e ); | 101 | void contentsDropEvent( QDropEvent *e ); |
101 | virtual bool acceptDrag(QDropEvent *e) const; | 102 | virtual bool acceptDrag(QDropEvent *e) const; |
102 | 103 | ||
103 | protected slots: | 104 | protected slots: |
104 | void itemDropped(QDropEvent *e); | 105 | void itemDropped(QDropEvent *e); |
105 | 106 | ||
106 | public slots: | 107 | public slots: |
107 | 108 | ||
108 | signals: | 109 | signals: |
109 | void startAddresseeDrag(); | 110 | void startAddresseeDrag(); |
110 | void addresseeDropped(QDropEvent *); | 111 | void addresseeDropped(QDropEvent *); |
111 | 112 | ||
112 | private: | 113 | private: |
113 | KAddressBookTableView *pabWidget; | 114 | KAddressBookTableView *pabWidget; |
114 | int oldColumn; | 115 | int oldColumn; |
115 | int column; | 116 | int column; |
116 | bool ascending; | 117 | bool ascending; |
117 | 118 | ||
118 | bool mABackground; | 119 | bool mABackground; |
119 | bool mSingleLine; | 120 | bool mSingleLine; |
120 | bool mToolTips; | 121 | bool mToolTips; |
121 | 122 | ||
122 | QColor mAlternateColor; | 123 | QColor mAlternateColor; |
123 | 124 | ||
124 | QPoint presspos; | 125 | QPoint presspos; |
125 | }; | 126 | }; |
126 | 127 | ||
127 | 128 | ||
128 | #endif | 129 | #endif |
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp index 0847b64..ab11e2a 100644 --- a/kaddressbook/views/kaddressbooktableview.cpp +++ b/kaddressbook/views/kaddressbooktableview.cpp | |||
@@ -1,382 +1,393 @@ | |||
1 | // $Id$ | 1 | // $Id$ |
2 | 2 | ||
3 | #include <qvbox.h> | 3 | #include <qvbox.h> |
4 | #include <qlistbox.h> | 4 | #include <qlistbox.h> |
5 | #include <qwidget.h> | 5 | #include <qwidget.h> |
6 | #include <qfile.h> | 6 | #include <qfile.h> |
7 | #include <qimage.h> | 7 | #include <qimage.h> |
8 | #include <qcombobox.h> | 8 | #include <qcombobox.h> |
9 | #include <qapplication.h> | 9 | #include <qapplication.h> |
10 | #include <qdragobject.h> | 10 | #include <qdragobject.h> |
11 | #include <qevent.h> | 11 | #include <qevent.h> |
12 | #include <qurl.h> | 12 | #include <qurl.h> |
13 | #include <qpixmap.h> | 13 | #include <qpixmap.h> |
14 | 14 | ||
15 | #include <kabc/addressbook.h> | 15 | #include <kabc/addressbook.h> |
16 | #include <kapplication.h> | 16 | #include <kapplication.h> |
17 | #include <kconfig.h> | 17 | #include <kconfig.h> |
18 | #include <kcolorbutton.h> | 18 | #include <kcolorbutton.h> |
19 | #include <kdebug.h> | 19 | #include <kdebug.h> |
20 | #include <kglobal.h> | 20 | #include <kglobal.h> |
21 | #include <kiconloader.h> | 21 | #include <kiconloader.h> |
22 | #include <klineedit.h> | 22 | #include <klineedit.h> |
23 | #include <klocale.h> | 23 | #include <klocale.h> |
24 | #include <kmessagebox.h> | 24 | #include <kmessagebox.h> |
25 | #include <kurl.h> | 25 | #include <kurl.h> |
26 | #include <kurlrequester.h> | 26 | #include <kurlrequester.h> |
27 | 27 | ||
28 | //US#include "configuretableviewdialog.h" | 28 | //US#include "configuretableviewdialog.h" |
29 | #include "contactlistview.h" | 29 | #include "contactlistview.h" |
30 | #include "kabprefs.h" | 30 | #include "kabprefs.h" |
31 | #include "undocmds.h" | 31 | #include "undocmds.h" |
32 | #include "viewmanager.h" | 32 | #include "viewmanager.h" |
33 | 33 | ||
34 | #include <qlayout.h> | 34 | #include <qlayout.h> |
35 | 35 | #include <qheader.h> | |
36 | 36 | ||
37 | #include "kaddressbooktableview.h" | 37 | #include "kaddressbooktableview.h" |
38 | 38 | ||
39 | 39 | ||
40 | KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab, | 40 | KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab, |
41 | QWidget *parent, const char *name ) | 41 | QWidget *parent, const char *name ) |
42 | : KAddressBookView( ab, parent, name ) | 42 | : KAddressBookView( ab, parent, name ) |
43 | { | 43 | { |
44 | mainLayout = new QVBoxLayout( viewWidget(), 2 ); | 44 | mainLayout = new QVBoxLayout( viewWidget(), 2 ); |
45 | 45 | ||
46 | // The list view will be created when the config is read. | 46 | // The list view will be created when the config is read. |
47 | mListView = 0; | 47 | mListView = 0; |
48 | } | 48 | } |
49 | 49 | ||
50 | KAddressBookTableView::~KAddressBookTableView() | 50 | KAddressBookTableView::~KAddressBookTableView() |
51 | { | 51 | { |
52 | } | 52 | } |
53 | 53 | ||
54 | void KAddressBookTableView::reconstructListView() | 54 | void KAddressBookTableView::reconstructListView() |
55 | { | 55 | { |
56 | if (mListView) | 56 | if (mListView) |
57 | { | 57 | { |
58 | disconnect(mListView, SIGNAL(selectionChanged()), | 58 | disconnect(mListView, SIGNAL(selectionChanged()), |
59 | this, SLOT(addresseeSelected())); | 59 | this, SLOT(addresseeSelected())); |
60 | disconnect(mListView, SIGNAL(executed(QListViewItem*)), | 60 | disconnect(mListView, SIGNAL(executed(QListViewItem*)), |
61 | this, SLOT(addresseeExecuted(QListViewItem*))); | 61 | this, SLOT(addresseeExecuted(QListViewItem*))); |
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 | // The config could have changed the fields, so we need to reconstruct | 125 | // The config could have changed the fields, so we need to reconstruct |
126 | // the listview. | 126 | // the listview. |
127 | reconstructListView(); | 127 | reconstructListView(); |
128 | 128 | ||
129 | // costum colors? | 129 | // costum colors? |
130 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) | 130 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) |
131 | { | 131 | { |
132 | QPalette p( mListView->palette() ); | 132 | QPalette p( mListView->palette() ); |
133 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); | 133 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); |
134 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); | 134 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); |
135 | c = p.color(QPalette::Normal, QColorGroup::Text ); | 135 | c = p.color(QPalette::Normal, QColorGroup::Text ); |
136 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); | 136 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); |
137 | c = p.color(QPalette::Normal, QColorGroup::Button ); | 137 | c = p.color(QPalette::Normal, QColorGroup::Button ); |
138 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); | 138 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); |
139 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); | 139 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); |
140 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); | 140 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); |
141 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); | 141 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); |
142 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); | 142 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); |
143 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); | 143 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); |
144 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); | 144 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); |
145 | c = p.color(QPalette::Normal, QColorGroup::Base ); | 145 | #ifndef KAB_EMBEDDED |
146 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "AlternatingBackgroundColor", &c ) ); | 146 | c = KGlobalSettings::alternateBackgroundColor(); |
147 | mListView->viewport()->setPalette( p ); | 147 | #else //KAB_EMBEDDED |
148 | c = QColor(240, 240, 240); | ||
149 | #endif //KAB_EMBEDDED | ||
150 | c = config->readColorEntry ("AlternatingBackgroundColor", &c); | ||
151 | mListView->setAlternateColor(c); | ||
152 | |||
153 | |||
154 | //US mListView->viewport()->setPalette( p ); | ||
155 | mListView->setPalette( p ); | ||
148 | } | 156 | } |
149 | else | 157 | else |
150 | { | 158 | { |
151 | // needed if turned off during a session. | 159 | // needed if turned off during a session. |
152 | mListView->viewport()->setPalette( mListView->palette() ); | 160 | //US mListView->viewport()->setPalette( mListView->palette() ); |
161 | mListView->setPalette( mListView->palette() ); | ||
153 | } | 162 | } |
154 | 163 | ||
155 | //custom fonts? | 164 | //custom fonts? |
156 | QFont f( font() ); | 165 | QFont f( font() ); |
157 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) | 166 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) |
158 | { | 167 | { |
159 | // mListView->setFont( config->readFontEntry( "TextFont", &f) ); | 168 | mListView->setFont( config->readFontEntry( "TextFont", &f) ); |
160 | f.setBold( true ); | 169 | f.setBold( true ); |
161 | // mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); | 170 | //US mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); |
171 | mListView->header()->setFont( config->readFontEntry( "HeaderFont", &f ) ); | ||
162 | } | 172 | } |
163 | else | 173 | else |
164 | { | 174 | { |
165 | // mListView->setFont( f ); | 175 | mListView->setFont( f ); |
166 | f.setBold( true ); | 176 | f.setBold( true ); |
167 | // mListView->setHeaderFont( f ); | 177 | //US mListView->setHeaderFont( f ); |
178 | mListView->header()->setFont( f ); | ||
168 | } | 179 | } |
169 | 180 | ||
170 | 181 | ||
171 | 182 | ||
172 | 183 | ||
173 | 184 | ||
174 | // Set the list view options | 185 | // Set the list view options |
175 | mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", | 186 | mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", |
176 | true)); | 187 | true)); |
177 | mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); | 188 | mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); |
178 | mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); | 189 | mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); |
179 | 190 | ||
180 | if (config->readBoolEntry("Background", false)) | 191 | if (config->readBoolEntry("Background", false)) |
181 | mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); | 192 | mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); |
182 | 193 | ||
183 | // Restore the layout of the listview | 194 | // Restore the layout of the listview |
184 | mListView->restoreLayout(config, config->group()); | 195 | mListView->restoreLayout(config, config->group()); |
185 | } | 196 | } |
186 | 197 | ||
187 | void KAddressBookTableView::refresh(QString uid) | 198 | void KAddressBookTableView::refresh(QString uid) |
188 | { | 199 | { |
189 | // For now just repopulate. In reality this method should | 200 | // For now just repopulate. In reality this method should |
190 | // check the value of uid, and if valid iterate through | 201 | // check the value of uid, and if valid iterate through |
191 | // the listview to find the entry, then tell it to refresh. | 202 | // the listview to find the entry, then tell it to refresh. |
192 | 203 | ||
193 | if (uid.isNull()) { | 204 | if (uid.isNull()) { |
194 | // Clear the list view | 205 | // Clear the list view |
195 | QString currentUID, nextUID; | 206 | QString currentUID, nextUID; |
196 | #ifndef KAB_EMBEDDED | 207 | #ifndef KAB_EMBEDDED |
197 | ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); | 208 | ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); |
198 | #else //KAB_EMBEDDED | 209 | #else //KAB_EMBEDDED |
199 | ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() ); | 210 | ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() ); |
200 | #endif //KAB_EMBEDDED | 211 | #endif //KAB_EMBEDDED |
201 | 212 | ||
202 | if ( currentItem ) { | 213 | if ( currentItem ) { |
203 | #ifndef KAB_EMBEDDED | 214 | #ifndef KAB_EMBEDDED |
204 | ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() ); | 215 | ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() ); |
205 | #else //KAB_EMBEDDED | 216 | #else //KAB_EMBEDDED |
206 | ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() ); | 217 | ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() ); |
207 | #endif //KAB_EMBEDDED | 218 | #endif //KAB_EMBEDDED |
208 | if ( nextItem ) | 219 | if ( nextItem ) |
209 | nextUID = nextItem->addressee().uid(); | 220 | nextUID = nextItem->addressee().uid(); |
210 | currentUID = currentItem->addressee().uid(); | 221 | currentUID = currentItem->addressee().uid(); |
211 | } | 222 | } |
212 | 223 | ||
213 | mListView->clear(); | 224 | mListView->clear(); |
214 | 225 | ||
215 | currentItem = 0; | 226 | currentItem = 0; |
216 | KABC::Addressee::List addresseeList = addressees(); | 227 | KABC::Addressee::List addresseeList = addressees(); |
217 | KABC::Addressee::List::Iterator it; | 228 | KABC::Addressee::List::Iterator it; |
218 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 229 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
219 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); | 230 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); |
220 | if ( (*it).uid() == currentUID ) | 231 | if ( (*it).uid() == currentUID ) |
221 | currentItem = item; | 232 | currentItem = item; |
222 | else if ( (*it).uid() == nextUID && !currentItem ) | 233 | else if ( (*it).uid() == nextUID && !currentItem ) |
223 | currentItem = item; | 234 | currentItem = item; |
224 | } | 235 | } |
225 | 236 | ||
226 | // Sometimes the background pixmap gets messed up when we add lots | 237 | // Sometimes the background pixmap gets messed up when we add lots |
227 | // of items. | 238 | // of items. |
228 | mListView->repaint(); | 239 | mListView->repaint(); |
229 | 240 | ||
230 | if ( currentItem ) { | 241 | if ( currentItem ) { |
231 | mListView->setCurrentItem( currentItem ); | 242 | mListView->setCurrentItem( currentItem ); |
232 | mListView->ensureItemVisible( currentItem ); | 243 | mListView->ensureItemVisible( currentItem ); |
233 | } | 244 | } |
234 | } else { | 245 | } else { |
235 | // Only need to update on entry. Iterate through and try to find it | 246 | // Only need to update on entry. Iterate through and try to find it |
236 | ContactListViewItem *ceItem; | 247 | ContactListViewItem *ceItem; |
237 | QListViewItemIterator it( mListView ); | 248 | QListViewItemIterator it( mListView ); |
238 | while ( it.current() ) { | 249 | while ( it.current() ) { |
239 | #ifndef KAB_EMBEDDED | 250 | #ifndef KAB_EMBEDDED |
240 | ceItem = dynamic_cast<ContactListViewItem*>( it.current() ); | 251 | ceItem = dynamic_cast<ContactListViewItem*>( it.current() ); |
241 | #else //KAB_EMBEDDED | 252 | #else //KAB_EMBEDDED |
242 | ceItem = (ContactListViewItem*)( it.current() ); | 253 | ceItem = (ContactListViewItem*)( it.current() ); |
243 | #endif //KAB_EMBEDDED | 254 | #endif //KAB_EMBEDDED |
244 | 255 | ||
245 | if ( ceItem && ceItem->addressee().uid() == uid ) { | 256 | if ( ceItem && ceItem->addressee().uid() == uid ) { |
246 | ceItem->refresh(); | 257 | ceItem->refresh(); |
247 | return; | 258 | return; |
248 | } | 259 | } |
249 | ++it; | 260 | ++it; |
250 | } | 261 | } |
251 | 262 | ||
252 | refresh( QString::null ); | 263 | refresh( QString::null ); |
253 | } | 264 | } |
254 | } | 265 | } |
255 | 266 | ||
256 | QStringList KAddressBookTableView::selectedUids() | 267 | QStringList KAddressBookTableView::selectedUids() |
257 | { | 268 | { |
258 | QStringList uidList; | 269 | QStringList uidList; |
259 | QListViewItem *item; | 270 | QListViewItem *item; |
260 | ContactListViewItem *ceItem; | 271 | ContactListViewItem *ceItem; |
261 | 272 | ||
262 | for(item = mListView->firstChild(); item; item = item->itemBelow()) | 273 | for(item = mListView->firstChild(); item; item = item->itemBelow()) |
263 | { | 274 | { |
264 | if (mListView->isSelected( item )) | 275 | if (mListView->isSelected( item )) |
265 | { | 276 | { |
266 | #ifndef KAB_EMBEDDED | 277 | #ifndef KAB_EMBEDDED |
267 | ceItem = dynamic_cast<ContactListViewItem*>(item); | 278 | ceItem = dynamic_cast<ContactListViewItem*>(item); |
268 | #else //KAB_EMBEDDED | 279 | #else //KAB_EMBEDDED |
269 | ceItem = (ContactListViewItem*)(item); | 280 | ceItem = (ContactListViewItem*)(item); |
270 | #endif //KAB_EMBEDDED | 281 | #endif //KAB_EMBEDDED |
271 | 282 | ||
272 | if (ceItem != 0L) | 283 | if (ceItem != 0L) |
273 | uidList << ceItem->addressee().uid(); | 284 | uidList << ceItem->addressee().uid(); |
274 | } | 285 | } |
275 | } | 286 | } |
276 | if ( uidList.count() == 0 ) | 287 | if ( uidList.count() == 0 ) |
277 | if ( mListView->currentItem() ) { | 288 | if ( mListView->currentItem() ) { |
278 | ceItem = (ContactListViewItem*)(mListView->currentItem()) ; | 289 | ceItem = (ContactListViewItem*)(mListView->currentItem()) ; |
279 | uidList << ceItem->addressee().uid(); | 290 | uidList << ceItem->addressee().uid(); |
280 | } | 291 | } |
281 | 292 | ||
282 | return uidList; | 293 | return uidList; |
283 | } | 294 | } |
284 | 295 | ||
285 | void KAddressBookTableView::setSelected(QString uid, bool selected) | 296 | void KAddressBookTableView::setSelected(QString uid, bool selected) |
286 | { | 297 | { |
287 | QListViewItem *item; | 298 | QListViewItem *item; |
288 | ContactListViewItem *ceItem; | 299 | ContactListViewItem *ceItem; |
289 | 300 | ||
290 | if (uid.isNull()) | 301 | if (uid.isNull()) |
291 | { | 302 | { |
292 | mListView->selectAll(selected); | 303 | mListView->selectAll(selected); |
293 | } | 304 | } |
294 | else | 305 | else |
295 | { | 306 | { |
296 | for(item = mListView->firstChild(); item; item = item->itemBelow()) | 307 | for(item = mListView->firstChild(); item; item = item->itemBelow()) |
297 | { | 308 | { |
298 | #ifndef KAB_EMBEDDED | 309 | #ifndef KAB_EMBEDDED |
299 | ceItem = dynamic_cast<ContactListViewItem*>(item); | 310 | ceItem = dynamic_cast<ContactListViewItem*>(item); |
300 | #else //KAB_EMBEDDED | 311 | #else //KAB_EMBEDDED |
301 | ceItem = (ContactListViewItem*)(item); | 312 | ceItem = (ContactListViewItem*)(item); |
302 | #endif //KAB_EMBEDDED | 313 | #endif //KAB_EMBEDDED |
303 | 314 | ||
304 | 315 | ||
305 | if ((ceItem != 0L) && (ceItem->addressee().uid() == uid)) | 316 | if ((ceItem != 0L) && (ceItem->addressee().uid() == uid)) |
306 | { | 317 | { |
307 | mListView->setSelected(item, selected); | 318 | mListView->setSelected(item, selected); |
308 | 319 | ||
309 | if (selected) | 320 | if (selected) |
310 | mListView->ensureItemVisible(item); | 321 | mListView->ensureItemVisible(item); |
311 | } | 322 | } |
312 | } | 323 | } |
313 | } | 324 | } |
314 | } | 325 | } |
315 | 326 | ||
316 | void KAddressBookTableView::addresseeSelected() | 327 | void KAddressBookTableView::addresseeSelected() |
317 | { | 328 | { |
318 | // We need to try to find the first selected item. This might not be the | 329 | // We need to try to find the first selected item. This might not be the |
319 | // last selected item, but when QListView is in multiselection mode, | 330 | // last selected item, but when QListView is in multiselection mode, |
320 | // there is no way to figure out which one was | 331 | // there is no way to figure out which one was |
321 | // selected last. | 332 | // selected last. |
322 | QListViewItem *item; | 333 | QListViewItem *item; |
323 | bool found =false; | 334 | bool found =false; |
324 | for (item = mListView->firstChild(); item && !found; | 335 | for (item = mListView->firstChild(); item && !found; |
325 | item = item->nextSibling()) | 336 | item = item->nextSibling()) |
326 | { | 337 | { |
327 | if (item->isSelected()) | 338 | if (item->isSelected()) |
328 | { | 339 | { |
329 | found = true; | 340 | found = true; |
330 | #ifndef KAB_EMBEDDED | 341 | #ifndef KAB_EMBEDDED |
331 | ContactListViewItem *ceItem | 342 | ContactListViewItem *ceItem |
332 | = dynamic_cast<ContactListViewItem*>(item); | 343 | = dynamic_cast<ContactListViewItem*>(item); |
333 | #else //KAB_EMBEDDED | 344 | #else //KAB_EMBEDDED |
334 | ContactListViewItem *ceItem | 345 | ContactListViewItem *ceItem |
335 | = (ContactListViewItem*)(item); | 346 | = (ContactListViewItem*)(item); |
336 | #endif //KAB_EMBEDDED | 347 | #endif //KAB_EMBEDDED |
337 | 348 | ||
338 | if ( ceItem ) emit selected(ceItem->addressee().uid()); | 349 | if ( ceItem ) emit selected(ceItem->addressee().uid()); |
339 | } | 350 | } |
340 | } | 351 | } |
341 | 352 | ||
342 | if (!found) | 353 | if (!found) |
343 | emit selected(QString::null); | 354 | emit selected(QString::null); |
344 | } | 355 | } |
345 | 356 | ||
346 | void KAddressBookTableView::addresseeExecuted(QListViewItem *item) | 357 | void KAddressBookTableView::addresseeExecuted(QListViewItem *item) |
347 | { | 358 | { |
348 | if (item) | 359 | if (item) |
349 | { | 360 | { |
350 | #ifndef KAB_EMBEDDED | 361 | #ifndef KAB_EMBEDDED |
351 | ContactListViewItem *ceItem | 362 | ContactListViewItem *ceItem |
352 | = dynamic_cast<ContactListViewItem*>(item); | 363 | = dynamic_cast<ContactListViewItem*>(item); |
353 | #else //KAB_EMBEDDED | 364 | #else //KAB_EMBEDDED |
354 | ContactListViewItem *ceItem | 365 | ContactListViewItem *ceItem |
355 | = (ContactListViewItem*)(item); | 366 | = (ContactListViewItem*)(item); |
356 | #endif //KAB_EMBEDDED | 367 | #endif //KAB_EMBEDDED |
357 | 368 | ||
358 | if (ceItem) | 369 | if (ceItem) |
359 | { | 370 | { |
360 | emit executed(ceItem->addressee().uid()); | 371 | emit executed(ceItem->addressee().uid()); |
361 | } | 372 | } |
362 | } | 373 | } |
363 | else | 374 | else |
364 | { | 375 | { |
365 | emit executed(QString::null); | 376 | emit executed(QString::null); |
366 | } | 377 | } |
367 | } | 378 | } |
368 | 379 | ||
369 | void KAddressBookTableView::addresseeDeleted() | 380 | void KAddressBookTableView::addresseeDeleted() |
370 | { | 381 | { |
371 | 382 | ||
372 | emit deleteRequest(); | 383 | emit deleteRequest(); |
373 | 384 | ||
374 | } | 385 | } |
375 | 386 | ||
376 | 387 | ||
377 | 388 | ||
378 | 389 | ||
379 | 390 | ||
380 | #ifndef KAB_EMBEDDED | 391 | #ifndef KAB_EMBEDDED |
381 | #include "kaddressbooktableview.moc" | 392 | #include "kaddressbooktableview.moc" |
382 | #endif //KAB_EMBEDDED | 393 | #endif //KAB_EMBEDDED |