summaryrefslogtreecommitdiffabout
path: root/kaddressbook/views
authorzautrix <zautrix>2005-01-16 22:19:12 (UTC)
committer zautrix <zautrix>2005-01-16 22:19:12 (UTC)
commit507b362d42d5eed6277ad17422b6ba61acca636e (patch) (unidiff)
treed3d29451d37649b102c3e171e2927437925f8ce8 /kaddressbook/views
parenta704468d5fd02d30cf962c8b2d6815c7e9208e5d (diff)
downloadkdepimpi-507b362d42d5eed6277ad17422b6ba61acca636e.zip
kdepimpi-507b362d42d5eed6277ad17422b6ba61acca636e.tar.gz
kdepimpi-507b362d42d5eed6277ad17422b6ba61acca636e.tar.bz2
print AB
Diffstat (limited to 'kaddressbook/views') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/views/contactlistview.cpp27
-rw-r--r--kaddressbook/views/contactlistview.h1
-rw-r--r--kaddressbook/views/kaddressbookcardview.cpp29
-rw-r--r--kaddressbook/views/kaddressbookcardview.h2
-rw-r--r--kaddressbook/views/kaddressbooktableview.cpp2
5 files changed, 61 insertions, 0 deletions
diff --git a/kaddressbook/views/contactlistview.cpp b/kaddressbook/views/contactlistview.cpp
index 23b091c..e75810e 100644
--- a/kaddressbook/views/contactlistview.cpp
+++ b/kaddressbook/views/contactlistview.cpp
@@ -1,373 +1,400 @@
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
48DynamicTip::DynamicTip( ContactListView *parent) 48DynamicTip::DynamicTip( ContactListView *parent)
49 : QToolTip( parent ) 49 : QToolTip( parent )
50{ 50{
51} 51}
52 52
53void DynamicTip::maybeTip( const QPoint &pos ) 53void 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
159ContactListViewItem::ContactListViewItem(const KABC::Addressee &a, 159ContactListViewItem::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
169QString ContactListViewItem::key(int column, bool ascending) const 169QString ContactListViewItem::key(int column, bool ascending) const
170{ 170{
171#ifndef DESKTOP_VERSION 171#ifndef DESKTOP_VERSION
172 int lan = KGlobal::locale()->language(); 172 int lan = KGlobal::locale()->language();
173 //qDebug("language %d ", lan); 173 //qDebug("language %d ", lan);
174 if ( lan == 1 ) { //GERMAN 174 if ( lan == 1 ) { //GERMAN
175 QString ret = QListViewItem::key(column, ascending).lower().utf8(); 175 QString ret = QListViewItem::key(column, ascending).lower().utf8();
176 int start = -1; 176 int start = -1;
177 while ( (start = ret.find( 'ä', start+1)) > 0 ) { 177 while ( (start = ret.find( 'ä', start+1)) > 0 ) {
178 ret.at(start-1) = 'a'; 178 ret.at(start-1) = 'a';
179 } 179 }
180 start = -1; 180 start = -1;
181 while ( (start = ret.find( 'ö', start+1)) > 0 ) { 181 while ( (start = ret.find( 'ö', start+1)) > 0 ) {
182 ret.at(start-1) = 'o'; 182 ret.at(start-1) = 'o';
183 } 183 }
184 start = -1; 184 start = -1;
185 while ( (start = ret.find( 'ü', start+1)) > 0 ) { 185 while ( (start = ret.find( 'ü', start+1)) > 0 ) {
186 ret.at(start-1) = 'o'; 186 ret.at(start-1) = 'o';
187 } 187 }
188 start = -1; 188 start = -1;
189 while ( (start = ret.find( 'ß', start+1)) > 0 ) { 189 while ( (start = ret.find( 'ß', start+1)) > 0 ) {
190 ret.at(start-1) = 's'; 190 ret.at(start-1) = 's';
191 } 191 }
192 //qDebug("conv string %s ", ret.latin1()); 192 //qDebug("conv string %s ", ret.latin1());
193 193
194 return ret; 194 return ret;
195 195
196 } 196 }
197 else 197 else
198#endif 198#endif
199 return QListViewItem::key(column, ascending).lower(); 199 return QListViewItem::key(column, ascending).lower();
200} 200}
201 201
202void ContactListViewItem::paintCell(QPainter * p, 202void ContactListViewItem::paintCell(QPainter * p,
203 const QColorGroup & cg, 203 const QColorGroup & cg,
204 int column, 204 int column,
205 int width, 205 int width,
206 int align) 206 int align)
207{ 207{
208 KListViewItem::paintCell(p, cg, column, width, align); 208 KListViewItem::paintCell(p, cg, column, width, align);
209 209
210 if ( !p ) 210 if ( !p )
211 return; 211 return;
212 212
213 if (parentListView->singleLine()) { 213 if (parentListView->singleLine()) {
214 p->setPen( parentListView->alternateColor() ); 214 p->setPen( parentListView->alternateColor() );
215 p->drawLine( 0, height() - 1, width, height() - 1 ); 215 p->drawLine( 0, height() - 1, width, height() - 1 );
216 } 216 }
217} 217}
218 218
219 219
220ContactListView *ContactListViewItem::parent() 220ContactListView *ContactListViewItem::parent()
221{ 221{
222 return parentListView; 222 return parentListView;
223} 223}
224 224
225 225
226void ContactListViewItem::refresh() 226void ContactListViewItem::refresh()
227{ 227{
228 // Update our addressee, since it may have changed else were 228 // Update our addressee, since it may have changed else were
229 mAddressee = mDocument->findByUid(mAddressee.uid()); 229 mAddressee = mDocument->findByUid(mAddressee.uid());
230 if (mAddressee.isEmpty()) 230 if (mAddressee.isEmpty())
231 return; 231 return;
232 232
233 int i = 0; 233 int i = 0;
234 KABC::Field::List::ConstIterator it; 234 KABC::Field::List::ConstIterator it;
235 for( it = mFields.begin(); it != mFields.end(); ++it ) { 235 for( it = mFields.begin(); it != mFields.end(); ++it ) {
236 setText( i++, (*it)->value( mAddressee ) ); 236 setText( i++, (*it)->value( mAddressee ) );
237 } 237 }
238} 238}
239 239
240/////////////////////////////// 240///////////////////////////////
241// ContactListView 241// ContactListView
242 242
243ContactListView::ContactListView(KAddressBookTableView *view, 243ContactListView::ContactListView(KAddressBookTableView *view,
244 KABC::AddressBook* /* doc */, 244 KABC::AddressBook* /* doc */,
245 QWidget *parent, 245 QWidget *parent,
246 const char *name ) 246 const char *name )
247 : KListView( parent, name ), 247 : KListView( parent, name ),
248 pabWidget( view ), 248 pabWidget( view ),
249 oldColumn( 0 ) 249 oldColumn( 0 )
250{ 250{
251 mABackground = true; 251 mABackground = true;
252 mSingleLine = false; 252 mSingleLine = false;
253 mToolTips = true; 253 mToolTips = true;
254#ifndef KAB_EMBEDDED 254#ifndef KAB_EMBEDDED
255 mAlternateColor = KGlobalSettings::alternateBackgroundColor(); 255 mAlternateColor = KGlobalSettings::alternateBackgroundColor();
256#else //KAB_EMBEDDED 256#else //KAB_EMBEDDED
257 mAlternateColor = QColor(240, 240, 240); 257 mAlternateColor = QColor(240, 240, 240);
258#endif //KAB_EMBEDDED 258#endif //KAB_EMBEDDED
259 259
260 setAlternateBackgroundEnabled(mABackground); 260 setAlternateBackgroundEnabled(mABackground);
261 setAcceptDrops( true ); 261 setAcceptDrops( true );
262 viewport()->setAcceptDrops( true ); 262 viewport()->setAcceptDrops( true );
263 setAllColumnsShowFocus( true ); 263 setAllColumnsShowFocus( true );
264 setShowSortIndicator(true); 264 setShowSortIndicator(true);
265 265
266 setSelectionModeExt( KListView::Extended ); 266 setSelectionModeExt( KListView::Extended );
267 setDropVisualizer(false); 267 setDropVisualizer(false);
268 // setFrameStyle(QFrame::NoFrame); 268 // setFrameStyle(QFrame::NoFrame);
269 //setLineWidth ( 0 ); 269 //setLineWidth ( 0 );
270 //setMidLineWidth ( 0 ); 270 //setMidLineWidth ( 0 );
271 //setMargin ( 0 ); 271 //setMargin ( 0 );
272#ifndef KAB_EMBEDDED 272#ifndef KAB_EMBEDDED
273 connect(this, SIGNAL(dropped(QDropEvent*)), 273 connect(this, SIGNAL(dropped(QDropEvent*)),
274 this, SLOT(itemDropped(QDropEvent*))); 274 this, SLOT(itemDropped(QDropEvent*)));
275#endif //KAB_EMBEDDED 275#endif //KAB_EMBEDDED
276 276
277 277
278 new DynamicTip( this ); 278 new DynamicTip( this );
279} 279}
280void ContactListView::printMe()
281{
282#ifdef DESKTOP_VERSION
283 QPrinter printer;
284 if (!printer.setup() )
285 return;
286 QPainter p;
287 p.begin ( &printer );
288 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer );
289 float dx, dy;
290 int wid = (m.width() * 9)/10;
291 dx = (float) wid/(float)contentsWidth ();
292 dy = (float)(m.height()) / (float)contentsHeight ();
293 float scale;
294 // scale to fit the width or height of the paper
295 if ( dx < dy )
296 scale = dx;
297 else
298 scale = dy;
299 p.translate( m.width()/10,0 );
300 p.scale( scale, scale );
301 qDebug("scale %f ", scale);
302 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () );
303 p.end();
304 qDebug("Why does it not print??? ");
305#endif
306}
280 307
281void ContactListView::setAlternateColor(const QColor &m_AlternateColor) 308void ContactListView::setAlternateColor(const QColor &m_AlternateColor)
282{ 309{
283 mAlternateColor = m_AlternateColor; 310 mAlternateColor = m_AlternateColor;
284} 311}
285 312
286void ContactListView::paintEmptyArea( QPainter * p, const QRect & rect ) 313void ContactListView::paintEmptyArea( QPainter * p, const QRect & rect )
287{ 314{
288 QBrush b = palette().brush(QPalette::Active, QColorGroup::Base); 315 QBrush b = palette().brush(QPalette::Active, QColorGroup::Base);
289 316
290 // Get the brush, which will have the background pixmap if there is one. 317 // Get the brush, which will have the background pixmap if there is one.
291 if (b.pixmap()) 318 if (b.pixmap())
292 { 319 {
293 p->drawTiledPixmap( rect.left(), rect.top(), rect.width(), rect.height(), 320 p->drawTiledPixmap( rect.left(), rect.top(), rect.width(), rect.height(),
294 *(b.pixmap()), 321 *(b.pixmap()),
295 rect.left() + contentsX(), 322 rect.left() + contentsX(),
296 rect.top() + contentsY() ); 323 rect.top() + contentsY() );
297 } 324 }
298 325
299 else 326 else
300 { 327 {
301 // Do a normal paint 328 // Do a normal paint
302 KListView::paintEmptyArea(p, rect); 329 KListView::paintEmptyArea(p, rect);
303 } 330 }
304} 331}
305 332
306void ContactListView::contentsMousePressEvent(QMouseEvent* e) 333void ContactListView::contentsMousePressEvent(QMouseEvent* e)
307{ 334{
308 presspos = e->pos(); 335 presspos = e->pos();
309 KListView::contentsMousePressEvent(e); 336 KListView::contentsMousePressEvent(e);
310} 337}
311 338
312 339
313// To initiate a drag operation 340// To initiate a drag operation
314void ContactListView::contentsMouseMoveEvent( QMouseEvent *e ) 341void ContactListView::contentsMouseMoveEvent( QMouseEvent *e )
315{ 342{
316 if ((e->state() & LeftButton) && (e->pos() - presspos).manhattanLength() > 4 ) { 343 if ((e->state() & LeftButton) && (e->pos() - presspos).manhattanLength() > 4 ) {
317 emit startAddresseeDrag(); 344 emit startAddresseeDrag();
318 } 345 }
319 else 346 else
320 KListView::contentsMouseMoveEvent( e ); 347 KListView::contentsMouseMoveEvent( e );
321} 348}
322 349
323bool ContactListView::acceptDrag(QDropEvent *e) const 350bool ContactListView::acceptDrag(QDropEvent *e) const
324{ 351{
325#ifndef KAB_EMBEDDED 352#ifndef KAB_EMBEDDED
326 return QTextDrag::canDecode(e); 353 return QTextDrag::canDecode(e);
327#else //KAB_EMBEDDED 354#else //KAB_EMBEDDED
328qDebug("ContactListView::acceptDrag has to be fixed"); 355qDebug("ContactListView::acceptDrag has to be fixed");
329 return false; 356 return false;
330#endif //KAB_EMBEDDED 357#endif //KAB_EMBEDDED
331} 358}
332 359
333void ContactListView::itemDropped(QDropEvent *e) 360void ContactListView::itemDropped(QDropEvent *e)
334{ 361{
335 contentsDropEvent(e); 362 contentsDropEvent(e);
336} 363}
337 364
338void ContactListView::contentsDropEvent( QDropEvent *e ) 365void ContactListView::contentsDropEvent( QDropEvent *e )
339{ 366{
340 emit addresseeDropped(e); 367 emit addresseeDropped(e);
341} 368}
342 369
343void ContactListView::setAlternateBackgroundEnabled(bool enabled) 370void ContactListView::setAlternateBackgroundEnabled(bool enabled)
344{ 371{
345 mABackground = enabled; 372 mABackground = enabled;
346 373
347 if (mABackground) 374 if (mABackground)
348 { 375 {
349 setAlternateBackground(mAlternateColor); 376 setAlternateBackground(mAlternateColor);
350 } 377 }
351 else 378 else
352 { 379 {
353 setAlternateBackground(QColor()); 380 setAlternateBackground(QColor());
354 } 381 }
355} 382}
356 383
357void ContactListView::setBackgroundPixmap(const QString &filename) 384void ContactListView::setBackgroundPixmap(const QString &filename)
358{ 385{
359 if (filename.isEmpty()) 386 if (filename.isEmpty())
360 { 387 {
361 unsetPalette(); 388 unsetPalette();
362 } 389 }
363 else 390 else
364 { 391 {
365 qDebug("ContactListView::setBackgroundPixmap has to be verified"); 392 qDebug("ContactListView::setBackgroundPixmap has to be verified");
366//US setPaletteBackgroundPixmap(QPixmap(filename)); 393//US setPaletteBackgroundPixmap(QPixmap(filename));
367 KListView::setBackgroundPixmap((const QPixmap&)QPixmap(filename)); 394 KListView::setBackgroundPixmap((const QPixmap&)QPixmap(filename));
368 } 395 }
369 396
370} 397}
371#ifndef KAB_EMBEDDED 398#ifndef KAB_EMBEDDED
372#include "contactlistview.moc" 399#include "contactlistview.moc"
373#endif //KAB_EMBEDDED 400#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/contactlistview.h b/kaddressbook/views/contactlistview.h
index fad7f38..9d1a672 100644
--- a/kaddressbook/views/contactlistview.h
+++ b/kaddressbook/views/contactlistview.h
@@ -1,129 +1,130 @@
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
16class QDropEvent; 16class QDropEvent;
17class KAddressBookTableView; 17class KAddressBookTableView;
18class ContactListView; 18class 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*/
23class DynamicTip : public QToolTip 23class 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
34class ContactListViewItem : public KListViewItem 34class ContactListViewItem : public KListViewItem
35{ 35{
36 36
37public: 37public:
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
51private: 51private:
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
62class ContactListView : public KListView 62class ContactListView : public KListView
63{ 63{
64 Q_OBJECT 64 Q_OBJECT
65 65
66public: 66public:
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 void setAlternateColor(const QColor &mAlternateColor);
87 87
88 /** Sets the background pixmap to <i>filename</i>. If the 88 /** Sets the background pixmap to <i>filename</i>. If the
89 * QString is empty (QString::isEmpty()), then the background 89 * QString is empty (QString::isEmpty()), then the background
90 * pixmap will be disabled. 90 * pixmap will be disabled.
91 */ 91 */
92 void setBackgroundPixmap(const QString &filename); 92 void setBackgroundPixmap(const QString &filename);
93 93
94protected: 94protected:
95 /** 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
96 * since Qt::FixedPixmap will not scroll with the list view. 96 * since Qt::FixedPixmap will not scroll with the list view.
97 */ 97 */
98 virtual void paintEmptyArea( QPainter * p, const QRect & rect ); 98 virtual void paintEmptyArea( QPainter * p, const QRect & rect );
99 virtual void contentsMousePressEvent(QMouseEvent*); 99 virtual void contentsMousePressEvent(QMouseEvent*);
100 void contentsMouseMoveEvent( QMouseEvent *e ); 100 void contentsMouseMoveEvent( QMouseEvent *e );
101 void contentsDropEvent( QDropEvent *e ); 101 void contentsDropEvent( QDropEvent *e );
102 virtual bool acceptDrag(QDropEvent *e) const; 102 virtual bool acceptDrag(QDropEvent *e) const;
103 103
104protected slots: 104protected slots:
105 void itemDropped(QDropEvent *e); 105 void itemDropped(QDropEvent *e);
106 106
107public slots: 107public slots:
108 void printMe();
108 109
109signals: 110signals:
110 void startAddresseeDrag(); 111 void startAddresseeDrag();
111 void addresseeDropped(QDropEvent *); 112 void addresseeDropped(QDropEvent *);
112 113
113private: 114private:
114 KAddressBookTableView *pabWidget; 115 KAddressBookTableView *pabWidget;
115 int oldColumn; 116 int oldColumn;
116 int column; 117 int column;
117 bool ascending; 118 bool ascending;
118 119
119 bool mABackground; 120 bool mABackground;
120 bool mSingleLine; 121 bool mSingleLine;
121 bool mToolTips; 122 bool mToolTips;
122 123
123 QColor mAlternateColor; 124 QColor mAlternateColor;
124 125
125 QPoint presspos; 126 QPoint presspos;
126}; 127};
127 128
128 129
129#endif 130#endif
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp
index 2d7ed08..107be59 100644
--- a/kaddressbook/views/kaddressbookcardview.cpp
+++ b/kaddressbook/views/kaddressbookcardview.cpp
@@ -1,478 +1,507 @@
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 <qdragobject.h> 24#include <qdragobject.h>
25#include <qevent.h> 25#include <qevent.h>
26#include <qiconview.h> 26#include <qiconview.h>
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qstringlist.h> 28#include <qstringlist.h>
29#include <qregexp.h> 29#include <qregexp.h>
30#include <qapplication.h> 30#include <qapplication.h>
31 31
32#include <kabc/addressbook.h> 32#include <kabc/addressbook.h>
33#include <kabc/addressee.h> 33#include <kabc/addressee.h>
34#include <kconfig.h> 34#include <kconfig.h>
35#include <kdebug.h> 35#include <kdebug.h>
36#include <klocale.h> 36#include <klocale.h>
37 37
38#include "kabprefs.h" 38#include "kabprefs.h"
39#include "viewmanager.h" 39#include "viewmanager.h"
40 40
41
41#include "kaddressbookcardview.h" 42#include "kaddressbookcardview.h"
42 43
43#ifndef KAB_EMBEDDED 44#ifndef KAB_EMBEDDED
44extern "C" { 45extern "C" {
45 void *init_libkaddrbk_cardview() 46 void *init_libkaddrbk_cardview()
46 { 47 {
47 return ( new CardViewFactory ); 48 return ( new CardViewFactory );
48 } 49 }
49} 50}
50#endif //KAB_EMBEDDED 51#endif //KAB_EMBEDDED
51 52
52//////////////////////////////// 53////////////////////////////////
53// AddresseeCardViewItem (internal class) 54// AddresseeCardViewItem (internal class)
54class AddresseeCardViewItem : public CardViewItem 55class AddresseeCardViewItem : public CardViewItem
55{ 56{
56 public: 57 public:
57 AddresseeCardViewItem(const KABC::Field::List &fields, 58 AddresseeCardViewItem(const KABC::Field::List &fields,
58 bool showEmptyFields, 59 bool showEmptyFields,
59 KABC::AddressBook *doc, const KABC::Addressee &a, 60 KABC::AddressBook *doc, const KABC::Addressee &a,
60 CardView *parent) 61 CardView *parent)
61 : CardViewItem(parent, a.formattedName()), 62 : CardViewItem(parent, a.formattedName()),
62 mFields( fields ), mShowEmptyFields(showEmptyFields), 63 mFields( fields ), mShowEmptyFields(showEmptyFields),
63 mDocument(doc), mAddressee(a) 64 mDocument(doc), mAddressee(a)
64 { 65 {
65 if ( mFields.isEmpty() ) { 66 if ( mFields.isEmpty() ) {
66 mFields = KABC::Field::defaultFields(); 67 mFields = KABC::Field::defaultFields();
67 } 68 }
68 refresh(); 69 refresh();
69 } 70 }
70 71
71 const KABC::Addressee &addressee() const { return mAddressee; } 72 const KABC::Addressee &addressee() const { return mAddressee; }
72 73
73 void refresh() 74 void refresh()
74 { 75 {
75 // Update our addressee, since it may have changed elsewhere 76 // Update our addressee, since it may have changed elsewhere
76 mAddressee = mDocument->findByUid(mAddressee.uid()); 77 mAddressee = mDocument->findByUid(mAddressee.uid());
77 78
78 if (!mAddressee.isEmpty()) 79 if (!mAddressee.isEmpty())
79 { 80 {
80 clearFields(); 81 clearFields();
81 82
82 // Try all the selected fields until we find one with text. 83 // Try all the selected fields until we find one with text.
83 // This will limit the number of unlabeled icons in the view 84 // This will limit the number of unlabeled icons in the view
84 KABC::Field::List::Iterator iter; 85 KABC::Field::List::Iterator iter;
85 for (iter = mFields.begin(); iter != mFields.end(); ++iter) 86 for (iter = mFields.begin(); iter != mFields.end(); ++iter)
86 { 87 {
87 // insert empty fields or not? not doing so saves a bit of memory and CPU 88 // insert empty fields or not? not doing so saves a bit of memory and CPU
88 // (during geometry calculations), but prevents having equally 89 // (during geometry calculations), but prevents having equally
89 // wide label columns in all cards, unless CardViewItem/CardView search 90 // wide label columns in all cards, unless CardViewItem/CardView search
90 // globally for the widest label. (anders) 91 // globally for the widest label. (anders)
91 //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty()) 92 //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty())
92 insertField((*iter)->label(), (*iter)->value( mAddressee )); 93 insertField((*iter)->label(), (*iter)->value( mAddressee ));
93 } 94 }
94 95
95 // We might want to make this the first field. hmm... -mpilone 96 // We might want to make this the first field. hmm... -mpilone
96 setCaption( mAddressee.realName() ); 97 setCaption( mAddressee.realName() );
97 } 98 }
98 } 99 }
99 100
100 private: 101 private:
101 KABC::Field::List mFields; 102 KABC::Field::List mFields;
102 bool mShowEmptyFields; 103 bool mShowEmptyFields;
103 KABC::AddressBook *mDocument; 104 KABC::AddressBook *mDocument;
104 KABC::Addressee mAddressee; 105 KABC::Addressee mAddressee;
105}; 106};
106 107
107/////////////////////////////// 108///////////////////////////////
108// AddresseeCardView 109// AddresseeCardView
109 110
110AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) 111AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name)
111 : CardView(parent, name) 112 : CardView(parent, name)
112{ 113{
113 setAcceptDrops(true); 114 setAcceptDrops(true);
114} 115}
115 116
116AddresseeCardView::~AddresseeCardView() 117AddresseeCardView::~AddresseeCardView()
117{ 118{
118} 119}
120void AddresseeCardView::printMe()
121{
122#ifdef DESKTOP_VERSION
123 QPrinter printer;
124 if (!printer.setup() )
125 return;
126 QPainter p;
127 p.begin ( &printer );
128 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer );
129 float dx, dy;
130 int wid = (m.width() * 9)/10;
131 dx = (float) wid/(float)contentsWidth ();
132 dy = (float)(m.height()) / (float)contentsHeight ();
133 float scale;
134 // scale to fit the width or height of the paper
135 if ( dx < dy )
136 scale = dx;
137 else
138 scale = dy;
139 p.translate( m.width()/10,0 );
140 p.scale( scale, scale );
141 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () );
142 p.end();
143 repaint();
144#endif
145}
119 146
120 147
121void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) 148void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e)
122{ 149{
123#ifndef KAB_EMBEDDED 150#ifndef KAB_EMBEDDED
124 if (QTextDrag::canDecode(e)) 151 if (QTextDrag::canDecode(e))
125 e->accept(); 152 e->accept();
126#else //KAB_EMBEDDED 153#else //KAB_EMBEDDED
127qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); 154qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented");
128#endif //KAB_EMBEDDED 155#endif //KAB_EMBEDDED
129} 156}
130 157
131void AddresseeCardView::dropEvent(QDropEvent *e) 158void AddresseeCardView::dropEvent(QDropEvent *e)
132{ 159{
133 emit addresseeDropped(e); 160 emit addresseeDropped(e);
134} 161}
135 162
136void AddresseeCardView::startDrag() 163void AddresseeCardView::startDrag()
137{ 164{
138 emit startAddresseeDrag(); 165 emit startAddresseeDrag();
139} 166}
140 167
141 168
142/////////////////////////////// 169///////////////////////////////
143// KAddressBookCardView 170// KAddressBookCardView
144 171
145KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, 172KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab,
146 QWidget *parent, const char *name ) 173 QWidget *parent, const char *name )
147 : KAddressBookView( ab, parent, name ) 174 : KAddressBookView( ab, parent, name )
148{ 175{
149 mShowEmptyFields = false; 176 mShowEmptyFields = false;
150 177
151 // Init the GUI 178 // Init the GUI
152 QVBoxLayout *layout = new QVBoxLayout(viewWidget()); 179 QVBoxLayout *layout = new QVBoxLayout(viewWidget());
153 180
154 mCardView = new AddresseeCardView(viewWidget(), "mCardView"); 181 mCardView = new AddresseeCardView(viewWidget(), "mCardView");
155 mCardView->setSelectionMode(CardView::Extended); 182 mCardView->setSelectionMode(CardView::Extended);
156 layout->addWidget(mCardView); 183 layout->addWidget(mCardView);
157 184
158 // Connect up the signals 185 // Connect up the signals
159 connect(mCardView, SIGNAL(executed(CardViewItem *)), 186 connect(mCardView, SIGNAL(executed(CardViewItem *)),
160 this, SLOT(addresseeExecuted(CardViewItem *))); 187 this, SLOT(addresseeExecuted(CardViewItem *)));
161 connect(mCardView, SIGNAL(selectionChanged()), 188 connect(mCardView, SIGNAL(selectionChanged()),
162 this, SLOT(addresseeSelected())); 189 this, SLOT(addresseeSelected()));
163 connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), 190 connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)),
164 this, SIGNAL(dropped(QDropEvent*))); 191 this, SIGNAL(dropped(QDropEvent*)));
165 connect(mCardView, SIGNAL(startAddresseeDrag()), 192 connect(mCardView, SIGNAL(startAddresseeDrag()),
166 this, SIGNAL(startDrag())); 193 this, SIGNAL(startDrag()));
194 connect(this, SIGNAL(printView()),
195 mCardView , SLOT(printMe()));
167} 196}
168 197
169KAddressBookCardView::~KAddressBookCardView() 198KAddressBookCardView::~KAddressBookCardView()
170{ 199{
171} 200}
172void KAddressBookCardView::setFocusAV() 201void KAddressBookCardView::setFocusAV()
173{ 202{
174 if ( mCardView ) 203 if ( mCardView )
175 mCardView->setFocus(); 204 mCardView->setFocus();
176 205
177} 206}
178void KAddressBookCardView::scrollUP() 207void KAddressBookCardView::scrollUP()
179{ 208{
180 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); 209 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 );
181 QApplication::postEvent( mCardView, ev ); 210 QApplication::postEvent( mCardView, ev );
182 211
183} 212}
184void KAddressBookCardView::scrollDOWN() 213void KAddressBookCardView::scrollDOWN()
185{ 214{
186 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); 215 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 );
187 QApplication::postEvent( mCardView, ev ); 216 QApplication::postEvent( mCardView, ev );
188} 217}
189void KAddressBookCardView::readConfig(KConfig *config) 218void KAddressBookCardView::readConfig(KConfig *config)
190{ 219{
191 KAddressBookView::readConfig(config); 220 KAddressBookView::readConfig(config);
192 221
193 // costum colors? 222 // costum colors?
194 if ( config->readBoolEntry( "EnableCustomColors", false ) ) 223 if ( config->readBoolEntry( "EnableCustomColors", false ) )
195 { 224 {
196 QPalette p( mCardView->palette() ); 225 QPalette p( mCardView->palette() );
197 QColor c = p.color(QPalette::Normal, QColorGroup::Base ); 226 QColor c = p.color(QPalette::Normal, QColorGroup::Base );
198 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); 227 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) );
199 c = p.color(QPalette::Normal, QColorGroup::Text ); 228 c = p.color(QPalette::Normal, QColorGroup::Text );
200 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); 229 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) );
201 c = p.color(QPalette::Normal, QColorGroup::Button ); 230 c = p.color(QPalette::Normal, QColorGroup::Button );
202 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); 231 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) );
203 c = p.color(QPalette::Normal, QColorGroup::ButtonText ); 232 c = p.color(QPalette::Normal, QColorGroup::ButtonText );
204 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); 233 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) );
205 c = p.color(QPalette::Normal, QColorGroup::Highlight ); 234 c = p.color(QPalette::Normal, QColorGroup::Highlight );
206 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); 235 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) );
207 c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); 236 c = p.color(QPalette::Normal, QColorGroup::HighlightedText );
208 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); 237 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) );
209 mCardView->viewport()->setPalette( p ); 238 mCardView->viewport()->setPalette( p );
210 } 239 }
211 else 240 else
212 { 241 {
213 // needed if turned off during a session. 242 // needed if turned off during a session.
214 mCardView->viewport()->setPalette( mCardView->palette() ); 243 mCardView->viewport()->setPalette( mCardView->palette() );
215 } 244 }
216 245
217 //custom fonts? 246 //custom fonts?
218 QFont f( font() ); 247 QFont f( font() );
219 if ( config->readBoolEntry( "EnableCustomFonts", false ) ) 248 if ( config->readBoolEntry( "EnableCustomFonts", false ) )
220 { 249 {
221 mCardView->setFont( config->readFontEntry( "TextFont", &f) ); 250 mCardView->setFont( config->readFontEntry( "TextFont", &f) );
222 f.setBold( true ); 251 f.setBold( true );
223 mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); 252 mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) );
224 } 253 }
225 else 254 else
226 { 255 {
227 mCardView->setFont( f ); 256 mCardView->setFont( f );
228 f.setBold( true ); 257 f.setBold( true );
229 mCardView->setHeaderFont( f ); 258 mCardView->setHeaderFont( f );
230 } 259 }
231 260
232 mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true)); 261 mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true));
233 mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators", 262 mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators",
234 true)); 263 true));
235 mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false)); 264 mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false));
236 mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false); 265 mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false);
237 266
238 mCardView->setShowEmptyFields( mShowEmptyFields ); 267 mCardView->setShowEmptyFields( mShowEmptyFields );
239 268
240 mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) ); 269 mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) );
241 mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) ); 270 mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) );
242 mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) ); 271 mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) );
243 mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) ); 272 mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) );
244 273
245#if 0 274#if 0
246 // LR KABPrefs::instance()->mHonorSingleClick is handled and fixed in cardviews contentsMouseDoubleClickEven 275 // LR KABPrefs::instance()->mHonorSingleClick is handled and fixed in cardviews contentsMouseDoubleClickEven
247 disconnect(mCardView, SIGNAL(executed(CardViewItem *)), 276 disconnect(mCardView, SIGNAL(executed(CardViewItem *)),
248 this, SLOT(addresseeExecuted(CardViewItem *))); 277 this, SLOT(addresseeExecuted(CardViewItem *)));
249 278
250 if (KABPrefs::instance()->mHonorSingleClick) 279 if (KABPrefs::instance()->mHonorSingleClick)
251 connect(mCardView, SIGNAL(executed(CardViewItem *)), 280 connect(mCardView, SIGNAL(executed(CardViewItem *)),
252 this, SLOT(addresseeExecuted(CardViewItem *))); 281 this, SLOT(addresseeExecuted(CardViewItem *)));
253 else 282 else
254 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), 283 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)),
255 this, SLOT(addresseeExecuted(CardViewItem *))); 284 this, SLOT(addresseeExecuted(CardViewItem *)));
256#endif 285#endif
257 286
258 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), 287 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)),
259 this, SLOT(addresseeExecuted(CardViewItem *))); 288 this, SLOT(addresseeExecuted(CardViewItem *)));
260} 289}
261 290
262void KAddressBookCardView::writeConfig( KConfig *config ) 291void KAddressBookCardView::writeConfig( KConfig *config )
263{ 292{
264 config->writeEntry( "ItemWidth", mCardView->itemWidth() ); 293 config->writeEntry( "ItemWidth", mCardView->itemWidth() );
265 KAddressBookView::writeConfig( config ); 294 KAddressBookView::writeConfig( config );
266} 295}
267void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field ) 296void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field )
268{ 297{
269 mCardView->clear(); 298 mCardView->clear();
270 if ( s.isEmpty() || s == "*" ) { 299 if ( s.isEmpty() || s == "*" ) {
271 refresh(); 300 refresh();
272 return; 301 return;
273 } 302 }
274 QString pattern = s.lower()+"*"; 303 QString pattern = s.lower()+"*";
275 QRegExp re; 304 QRegExp re;
276 re.setWildcard(true); // most people understand these better. 305 re.setWildcard(true); // most people understand these better.
277 re.setCaseSensitive(false); 306 re.setCaseSensitive(false);
278 re.setPattern( pattern ); 307 re.setPattern( pattern );
279 if (!re.isValid()) 308 if (!re.isValid())
280 return; 309 return;
281 mCardView->viewport()->setUpdatesEnabled( false ); 310 mCardView->viewport()->setUpdatesEnabled( false );
282 KABC::Addressee::List addresseeList = addressees(); 311 KABC::Addressee::List addresseeList = addressees();
283 KABC::Addressee::List::Iterator it; 312 KABC::Addressee::List::Iterator it;
284 if ( field ) { 313 if ( field ) {
285 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 314 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
286 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 315 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
287 continue; 316 continue;
288#if QT_VERSION >= 300 317#if QT_VERSION >= 300
289 if (re.search(field->value( *it ).lower()) != -1) 318 if (re.search(field->value( *it ).lower()) != -1)
290#else 319#else
291 if (re.match(field->value( *it ).lower()) != -1) 320 if (re.match(field->value( *it ).lower()) != -1)
292#endif 321#endif
293 new AddresseeCardViewItem(fields(), mShowEmptyFields, 322 new AddresseeCardViewItem(fields(), mShowEmptyFields,
294 addressBook(), *it, mCardView); 323 addressBook(), *it, mCardView);
295 324
296 } 325 }
297 } else { 326 } else {
298 KABC::Field::List fieldList = allFields(); 327 KABC::Field::List fieldList = allFields();
299 KABC::Field::List::ConstIterator fieldIt; 328 KABC::Field::List::ConstIterator fieldIt;
300 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 329 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
301 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 330 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
302 continue; 331 continue;
303 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { 332 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
304#if QT_VERSION >= 300 333#if QT_VERSION >= 300
305 if (re.search((*fieldIt)->value( *it ).lower()) != -1) 334 if (re.search((*fieldIt)->value( *it ).lower()) != -1)
306#else 335#else
307 if (re.match((*fieldIt)->value( *it ).lower()) != -1) 336 if (re.match((*fieldIt)->value( *it ).lower()) != -1)
308#endif 337#endif
309 { 338 {
310 new AddresseeCardViewItem(fields(), mShowEmptyFields, 339 new AddresseeCardViewItem(fields(), mShowEmptyFields,
311 addressBook(), *it, mCardView); 340 addressBook(), *it, mCardView);
312 continue; 341 continue;
313 } 342 }
314 } 343 }
315 } 344 }
316 } 345 }
317 mCardView->viewport()->setUpdatesEnabled( true ); 346 mCardView->viewport()->setUpdatesEnabled( true );
318 mCardView->viewport()->update(); 347 mCardView->viewport()->update();
319 if ( mCardView->firstItem() ) { 348 if ( mCardView->firstItem() ) {
320 mCardView->setCurrentItem ( mCardView->firstItem() ); 349 mCardView->setCurrentItem ( mCardView->firstItem() );
321 mCardView->setSelected ( mCardView->firstItem() , true ); 350 mCardView->setSelected ( mCardView->firstItem() , true );
322 } 351 }
323 else 352 else
324 emit selected(QString::null); 353 emit selected(QString::null);
325} 354}
326QStringList KAddressBookCardView::selectedUids() 355QStringList KAddressBookCardView::selectedUids()
327{ 356{
328 QStringList uidList; 357 QStringList uidList;
329 CardViewItem *item; 358 CardViewItem *item;
330 AddresseeCardViewItem *aItem; 359 AddresseeCardViewItem *aItem;
331 360
332 for (item = mCardView->firstItem(); item; item = item->nextItem()) 361 for (item = mCardView->firstItem(); item; item = item->nextItem())
333 { 362 {
334 if (item->isSelected()) 363 if (item->isSelected())
335 { 364 {
336#ifndef KAB_EMBEDDED 365#ifndef KAB_EMBEDDED
337 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 366 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
338#else //KAB_EMBEDDED 367#else //KAB_EMBEDDED
339 aItem = (AddresseeCardViewItem*)(item); 368 aItem = (AddresseeCardViewItem*)(item);
340#endif //KAB_EMBEDDED 369#endif //KAB_EMBEDDED
341 if (aItem) 370 if (aItem)
342 uidList << aItem->addressee().uid(); 371 uidList << aItem->addressee().uid();
343 } 372 }
344 } 373 }
345 374
346 return uidList; 375 return uidList;
347} 376}
348 377
349void KAddressBookCardView::refresh(QString uid) 378void KAddressBookCardView::refresh(QString uid)
350{ 379{
351 CardViewItem *item; 380 CardViewItem *item;
352 AddresseeCardViewItem *aItem; 381 AddresseeCardViewItem *aItem;
353 382
354 if (uid.isNull()) 383 if (uid.isNull())
355 { 384 {
356 // Rebuild the view 385 // Rebuild the view
357 mCardView->viewport()->setUpdatesEnabled( false ); 386 mCardView->viewport()->setUpdatesEnabled( false );
358 mCardView->clear(); 387 mCardView->clear();
359 388
360 KABC::Addressee::List addresseeList = addressees(); 389 KABC::Addressee::List addresseeList = addressees();
361 KABC::Addressee::List::Iterator iter; 390 KABC::Addressee::List::Iterator iter;
362 for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter) 391 for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter)
363 { 392 {
364 if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") ) 393 if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") )
365 continue; 394 continue;
366 aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields, 395 aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields,
367 addressBook(), *iter, mCardView); 396 addressBook(), *iter, mCardView);
368 } 397 }
369 mCardView->viewport()->setUpdatesEnabled( true ); 398 mCardView->viewport()->setUpdatesEnabled( true );
370 mCardView->viewport()->update(); 399 mCardView->viewport()->update();
371 400
372 // by default nothing is selected 401 // by default nothing is selected
373 emit selected(QString::null); 402 emit selected(QString::null);
374 } 403 }
375 else 404 else
376 { 405 {
377 // Try to find the one to refresh 406 // Try to find the one to refresh
378 bool found = false; 407 bool found = false;
379 for (item = mCardView->firstItem(); item && !found; 408 for (item = mCardView->firstItem(); item && !found;
380 item = item->nextItem()) 409 item = item->nextItem())
381 { 410 {
382#ifndef KAB_EMBEDDED 411#ifndef KAB_EMBEDDED
383 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 412 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
384#else //KAB_EMBEDDED 413#else //KAB_EMBEDDED
385 aItem = (AddresseeCardViewItem*)(item); 414 aItem = (AddresseeCardViewItem*)(item);
386#endif //KAB_EMBEDDED 415#endif //KAB_EMBEDDED
387 416
388 if ((aItem) && (aItem->addressee().uid() == uid)) 417 if ((aItem) && (aItem->addressee().uid() == uid))
389 { 418 {
390 aItem->refresh(); 419 aItem->refresh();
391 found = true; 420 found = true;
392 } 421 }
393 } 422 }
394 } 423 }
395} 424}
396 425
397void KAddressBookCardView::setSelected(QString uid, bool selected) 426void KAddressBookCardView::setSelected(QString uid, bool selected)
398{ 427{
399 CardViewItem *item; 428 CardViewItem *item;
400 AddresseeCardViewItem *aItem; 429 AddresseeCardViewItem *aItem;
401 430
402 if (uid.isNull()) 431 if (uid.isNull())
403 { 432 {
404 mCardView->selectAll(selected); 433 mCardView->selectAll(selected);
405 } 434 }
406 else 435 else
407 { 436 {
408 bool found = false; 437 bool found = false;
409 for (item = mCardView->firstItem(); item && !found; 438 for (item = mCardView->firstItem(); item && !found;
410 item = item->nextItem()) 439 item = item->nextItem())
411 { 440 {
412#ifndef KAB_EMBEDDED 441#ifndef KAB_EMBEDDED
413 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 442 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
414#else //KAB_EMBEDDED 443#else //KAB_EMBEDDED
415 aItem = (AddresseeCardViewItem*)(item); 444 aItem = (AddresseeCardViewItem*)(item);
416#endif //KAB_EMBEDDED 445#endif //KAB_EMBEDDED
417 446
418 if ((aItem) && (aItem->addressee().uid() == uid)) 447 if ((aItem) && (aItem->addressee().uid() == uid))
419 { 448 {
420 mCardView->setSelected(aItem, selected); 449 mCardView->setSelected(aItem, selected);
421 mCardView->ensureItemVisible(item); 450 mCardView->ensureItemVisible(item);
422 found = true; 451 found = true;
423 } 452 }
424 } 453 }
425 } 454 }
426} 455}
427 456
428//US added an additional method without parameter 457//US added an additional method without parameter
429void KAddressBookCardView::setSelected() 458void KAddressBookCardView::setSelected()
430{ 459{
431 setSelected(QString::null, true); 460 setSelected(QString::null, true);
432} 461}
433 462
434void KAddressBookCardView::addresseeExecuted(CardViewItem *item) 463void KAddressBookCardView::addresseeExecuted(CardViewItem *item)
435{ 464{
436#ifndef KAB_EMBEDDED 465#ifndef KAB_EMBEDDED
437 AddresseeCardViewItem *aItem = dynamic_cast<AddresseeCardViewItem*>(item); 466 AddresseeCardViewItem *aItem = dynamic_cast<AddresseeCardViewItem*>(item);
438#else //KAB_EMBEDDED 467#else //KAB_EMBEDDED
439 AddresseeCardViewItem *aItem = (AddresseeCardViewItem*)(item); 468 AddresseeCardViewItem *aItem = (AddresseeCardViewItem*)(item);
440#endif //KAB_EMBEDDED 469#endif //KAB_EMBEDDED
441 if (aItem) 470 if (aItem)
442 { 471 {
443 //kdDebug()<<"... even has a valid item:)"<<endl; 472 //kdDebug()<<"... even has a valid item:)"<<endl;
444 emit executed(aItem->addressee().uid()); 473 emit executed(aItem->addressee().uid());
445 } 474 }
446} 475}
447 476
448void KAddressBookCardView::addresseeSelected() 477void KAddressBookCardView::addresseeSelected()
449{ 478{
450 CardViewItem *item; 479 CardViewItem *item;
451 AddresseeCardViewItem *aItem; 480 AddresseeCardViewItem *aItem;
452 481
453 bool found = false; 482 bool found = false;
454 for (item = mCardView->firstItem(); item && !found; 483 for (item = mCardView->firstItem(); item && !found;
455 item = item->nextItem()) 484 item = item->nextItem())
456 { 485 {
457 if (item->isSelected()) 486 if (item->isSelected())
458 { 487 {
459#ifndef KAB_EMBEDDED 488#ifndef KAB_EMBEDDED
460 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 489 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
461#else //KAB_EMBEDDED 490#else //KAB_EMBEDDED
462 aItem = (AddresseeCardViewItem*)(item); 491 aItem = (AddresseeCardViewItem*)(item);
463#endif //KAB_EMBEDDED 492#endif //KAB_EMBEDDED
464 if ( aItem ) 493 if ( aItem )
465 { 494 {
466 emit selected(aItem->addressee().uid()); 495 emit selected(aItem->addressee().uid());
467 found = true; 496 found = true;
468 } 497 }
469 } 498 }
470 } 499 }
471 500
472 if (!found) 501 if (!found)
473 emit selected(QString::null); 502 emit selected(QString::null);
474 503
475} 504}
476#ifndef KAB_EMBEDDED 505#ifndef KAB_EMBEDDED
477#include "kaddressbookcardview.moc" 506#include "kaddressbookcardview.moc"
478#endif //KAB_EMBEDDED 507#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/kaddressbookcardview.h b/kaddressbook/views/kaddressbookcardview.h
index 8f22d54..2a71f7e 100644
--- a/kaddressbook/views/kaddressbookcardview.h
+++ b/kaddressbook/views/kaddressbookcardview.h
@@ -1,120 +1,122 @@
1#ifndef KADDRESSBOOKCARDVIEW_H 1#ifndef KADDRESSBOOKCARDVIEW_H
2#define KADDRESSBOOKCARDVIEW_H 2#define KADDRESSBOOKCARDVIEW_H
3 3
4/* 4/*
5 This file is part of KAddressBook. 5 This file is part of KAddressBook.
6 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 6 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
7 7
8 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 (at your option) any later version.
12 12
13 This program is distributed in the hope that it will be useful, 13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 GNU General Public License for more details.
17 17
18 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software 19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 21
22 As a special exception, permission is given to link this program 22 As a special exception, permission is given to link this program
23 with any edition of Qt, and distribute the resulting executable, 23 with any edition of Qt, and distribute the resulting executable,
24 without including the source code for Qt in the source distribution. 24 without including the source code for Qt in the source distribution.
25*/ 25*/
26 26
27#include <qstring.h> 27#include <qstring.h>
28#ifndef KAB_EMBEDDED 28#ifndef KAB_EMBEDDED
29#include <kiconview.h> 29#include <kiconview.h>
30#else //KAB_EMBEDDED 30#else //KAB_EMBEDDED
31#include <klocale.h> 31#include <klocale.h>
32#endif //KAB_EMBEDDED 32#endif //KAB_EMBEDDED
33 33
34#include "cardview.h" 34#include "cardview.h"
35#include "kaddressbookview.h" 35#include "kaddressbookview.h"
36#include "configurecardviewdialog.h" 36#include "configurecardviewdialog.h"
37 37
38class QDragEnterEvent; 38class QDragEnterEvent;
39class QDragEntryEvent; 39class QDragEntryEvent;
40class QDropEvent; 40class QDropEvent;
41class KConfig; 41class KConfig;
42class AddresseeCardView; 42class AddresseeCardView;
43 43
44/** 44/**
45 This view uses the CardView class to create a card view. At some 45 This view uses the CardView class to create a card view. At some
46 point in the future I think this will be the default view of 46 point in the future I think this will be the default view of
47 KAddressBook. 47 KAddressBook.
48 */ 48 */
49class KAddressBookCardView : public KAddressBookView 49class KAddressBookCardView : public KAddressBookView
50{ 50{
51 Q_OBJECT 51 Q_OBJECT
52 52
53 public: 53 public:
54 KAddressBookCardView( KABC::AddressBook *ab, QWidget *parent, 54 KAddressBookCardView( KABC::AddressBook *ab, QWidget *parent,
55 const char *name = 0 ); 55 const char *name = 0 );
56 virtual ~KAddressBookCardView(); 56 virtual ~KAddressBookCardView();
57 void doSearch( const QString& s,KABC::Field *field ); 57 void doSearch( const QString& s,KABC::Field *field );
58 virtual QStringList selectedUids(); 58 virtual QStringList selectedUids();
59 virtual QString type() const { return "Card"; } 59 virtual QString type() const { return "Card"; }
60 60
61 virtual void readConfig(KConfig *config); 61 virtual void readConfig(KConfig *config);
62 virtual void writeConfig(KConfig *); 62 virtual void writeConfig(KConfig *);
63 virtual void scrollUP(); 63 virtual void scrollUP();
64 virtual void scrollDOWN(); 64 virtual void scrollDOWN();
65 virtual void setFocusAV(); 65 virtual void setFocusAV();
66 66
67 public slots: 67 public slots:
68 void refresh(QString uid = QString::null); 68 void refresh(QString uid = QString::null);
69 void setSelected(QString uid/*US = QString::null*/, bool selected/*US = true*/); 69 void setSelected(QString uid/*US = QString::null*/, bool selected/*US = true*/);
70//US added an additional method without parameter 70//US added an additional method without parameter
71 void setSelected(); 71 void setSelected();
72 72
73 protected slots: 73 protected slots:
74 void addresseeExecuted(CardViewItem *item); 74 void addresseeExecuted(CardViewItem *item);
75 void addresseeSelected(); 75 void addresseeSelected();
76 76
77 private: 77 private:
78 AddresseeCardView *mCardView; 78 AddresseeCardView *mCardView;
79 bool mShowEmptyFields; 79 bool mShowEmptyFields;
80}; 80};
81 81
82class AddresseeCardView : public CardView 82class AddresseeCardView : public CardView
83{ 83{
84 Q_OBJECT 84 Q_OBJECT
85 public: 85 public:
86 AddresseeCardView(QWidget *parent, const char *name = 0); 86 AddresseeCardView(QWidget *parent, const char *name = 0);
87 ~AddresseeCardView(); 87 ~AddresseeCardView();
88public slots:
89 void printMe();
88 90
89 signals: 91 signals:
90 void startAddresseeDrag(); 92 void startAddresseeDrag();
91 void addresseeDropped(QDropEvent *); 93 void addresseeDropped(QDropEvent *);
92 94
93 protected: 95 protected:
94 virtual void dragEnterEvent(QDragEnterEvent *); 96 virtual void dragEnterEvent(QDragEnterEvent *);
95 virtual void dropEvent(QDropEvent *); 97 virtual void dropEvent(QDropEvent *);
96 virtual void startDrag(); 98 virtual void startDrag();
97}; 99};
98 100
99 101
100class CardViewFactory : public ViewFactory 102class CardViewFactory : public ViewFactory
101{ 103{
102 public: 104 public:
103 KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name ) 105 KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name )
104 { 106 {
105 return new KAddressBookCardView( ab, parent, name ); 107 return new KAddressBookCardView( ab, parent, name );
106 } 108 }
107 109
108 QString type() const { return "Card"; } 110 QString type() const { return "Card"; }
109 111
110 QString description() const { return i18n( "Rolodex style cards represent contacts." ); } 112 QString description() const { return i18n( "Rolodex style cards represent contacts." ); }
111 113
112 ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, QWidget *parent, 114 ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, QWidget *parent,
113 const char *name = 0 ) 115 const char *name = 0 )
114 { 116 {
115 return new ConfigureCardViewWidget( ab, parent, name ); 117 return new ConfigureCardViewWidget( ab, parent, name );
116 } 118 }
117}; 119};
118 120
119 121
120#endif 122#endif
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp
index 61703ee..ecd6f05 100644
--- a/kaddressbook/views/kaddressbooktableview.cpp
+++ b/kaddressbook/views/kaddressbooktableview.cpp
@@ -1,471 +1,473 @@
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#include <qheader.h> 35#include <qheader.h>
36#include <qregexp.h> 36#include <qregexp.h>
37 37
38#include "kaddressbooktableview.h" 38#include "kaddressbooktableview.h"
39 39
40 40
41KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab, 41KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab,
42 QWidget *parent, const char *name ) 42 QWidget *parent, const char *name )
43 : KAddressBookView( ab, parent, name ) 43 : KAddressBookView( ab, parent, name )
44{ 44{
45 mainLayout = new QVBoxLayout( viewWidget(), 2 ); 45 mainLayout = new QVBoxLayout( viewWidget(), 2 );
46 46
47 // The list view will be created when the config is read. 47 // The list view will be created when the config is read.
48 mListView = 0; 48 mListView = 0;
49} 49}
50 50
51KAddressBookTableView::~KAddressBookTableView() 51KAddressBookTableView::~KAddressBookTableView()
52{ 52{
53} 53}
54void KAddressBookTableView::setFocusAV() 54void KAddressBookTableView::setFocusAV()
55{ 55{
56 if ( mListView ) 56 if ( mListView )
57 mListView->setFocus(); 57 mListView->setFocus();
58 58
59} 59}
60void KAddressBookTableView::scrollUP() 60void KAddressBookTableView::scrollUP()
61{ 61{
62 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); 62 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 );
63 QApplication::postEvent( mListView, ev ); 63 QApplication::postEvent( mListView, ev );
64} 64}
65void KAddressBookTableView::scrollDOWN() 65void KAddressBookTableView::scrollDOWN()
66{ 66{
67 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); 67 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 );
68 QApplication::postEvent( mListView, ev ); 68 QApplication::postEvent( mListView, ev );
69} 69}
70void KAddressBookTableView::reconstructListView() 70void KAddressBookTableView::reconstructListView()
71{ 71{
72 if (mListView) 72 if (mListView)
73 { 73 {
74 disconnect(mListView, SIGNAL(selectionChanged()), 74 disconnect(mListView, SIGNAL(selectionChanged()),
75 this, SLOT(addresseeSelected())); 75 this, SLOT(addresseeSelected()));
76 disconnect(mListView, SIGNAL(executed(QListViewItem*)), 76 disconnect(mListView, SIGNAL(executed(QListViewItem*)),
77 this, SLOT(addresseeExecuted(QListViewItem*))); 77 this, SLOT(addresseeExecuted(QListViewItem*)));
78 disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)), 78 disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
79 this, SLOT(addresseeExecuted(QListViewItem*))); 79 this, SLOT(addresseeExecuted(QListViewItem*)));
80 disconnect(mListView, SIGNAL(startAddresseeDrag()), this, 80 disconnect(mListView, SIGNAL(startAddresseeDrag()), this,
81 SIGNAL(startDrag())); 81 SIGNAL(startDrag()));
82 disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)), 82 disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)),
83 this, SLOT(addresseeExecuted(QListViewItem*))); 83 this, SLOT(addresseeExecuted(QListViewItem*)));
84 84
85 disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, 85 disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
86 SIGNAL(dropped(QDropEvent*))); 86 SIGNAL(dropped(QDropEvent*)));
87 delete mListView; 87 delete mListView;
88 } 88 }
89 89
90 mListView = new ContactListView( this, addressBook(), viewWidget() ); 90 mListView = new ContactListView( this, addressBook(), viewWidget() );
91 91
92 connect(this, SIGNAL(printView()),
93 mListView , SLOT(printMe()));
92 //US set singleClick manually, because it is no global configparameter in embedded space 94 //US set singleClick manually, because it is no global configparameter in embedded space
93 mListView->setSingleClick(KABPrefs::instance()->mHonorSingleClick); 95 mListView->setSingleClick(KABPrefs::instance()->mHonorSingleClick);
94 96
95 // Add the columns 97 // Add the columns
96 KABC::Field::List fieldList = fields(); 98 KABC::Field::List fieldList = fields();
97 KABC::Field::List::ConstIterator it; 99 KABC::Field::List::ConstIterator it;
98 100
99 int c = 0; 101 int c = 0;
100 for( it = fieldList.begin(); it != fieldList.end(); ++it ) { 102 for( it = fieldList.begin(); it != fieldList.end(); ++it ) {
101 mListView->addColumn( (*it)->label() ); 103 mListView->addColumn( (*it)->label() );
102 mListView->setColumnWidthMode(c++, QListView::Manual); 104 mListView->setColumnWidthMode(c++, QListView::Manual);
103//US 105//US
104 // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1()); 106 // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1());
105 } 107 }
106 108
107 connect(mListView, SIGNAL(selectionChanged()), 109 connect(mListView, SIGNAL(selectionChanged()),
108 this, SLOT(addresseeSelected())); 110 this, SLOT(addresseeSelected()));
109 connect(mListView, SIGNAL(startAddresseeDrag()), this, 111 connect(mListView, SIGNAL(startAddresseeDrag()), this,
110 SIGNAL(startDrag())); 112 SIGNAL(startDrag()));
111 connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, 113 connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
112 SIGNAL(dropped(QDropEvent*))); 114 SIGNAL(dropped(QDropEvent*)));
113 115
114 if (KABPrefs::instance()->mHonorSingleClick) { 116 if (KABPrefs::instance()->mHonorSingleClick) {
115 // qDebug("KAddressBookTableView::reconstructListView single"); 117 // qDebug("KAddressBookTableView::reconstructListView single");
116 connect(mListView, SIGNAL(executed(QListViewItem*)), 118 connect(mListView, SIGNAL(executed(QListViewItem*)),
117 this, SLOT(addresseeExecuted(QListViewItem*))); 119 this, SLOT(addresseeExecuted(QListViewItem*)));
118 } else { 120 } else {
119 // qDebug("KAddressBookTableView::reconstructListView double"); 121 // qDebug("KAddressBookTableView::reconstructListView double");
120 connect(mListView, SIGNAL(doubleClicked(QListViewItem*)), 122 connect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
121 this, SLOT(addresseeExecuted(QListViewItem*))); 123 this, SLOT(addresseeExecuted(QListViewItem*)));
122 } 124 }
123 connect(mListView, SIGNAL(returnPressed(QListViewItem*)), 125 connect(mListView, SIGNAL(returnPressed(QListViewItem*)),
124 this, SLOT(addresseeExecuted(QListViewItem*))); 126 this, SLOT(addresseeExecuted(QListViewItem*)));
125 connect(mListView, SIGNAL(signalDelete()), 127 connect(mListView, SIGNAL(signalDelete()),
126 this, SLOT(addresseeDeleted())); 128 this, SLOT(addresseeDeleted()));
127 129
128//US performceimprovement. Refresh is done from the outside 130//US performceimprovement. Refresh is done from the outside
129//US refresh(); 131//US refresh();
130 132
131 mListView->setSorting( 0, true ); 133 mListView->setSorting( 0, true );
132 mainLayout->addWidget( mListView ); 134 mainLayout->addWidget( mListView );
133 mainLayout->activate(); 135 mainLayout->activate();
134 mListView->show(); 136 mListView->show();
135} 137}
136 138
137void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field ) 139void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field )
138{ 140{
139 mListView->clear(); 141 mListView->clear();
140 if ( s.isEmpty() || s == "*" ) { 142 if ( s.isEmpty() || s == "*" ) {
141 refresh(); 143 refresh();
142 return; 144 return;
143 } 145 }
144 QString pattern = s.lower()+"*"; 146 QString pattern = s.lower()+"*";
145 QRegExp re; 147 QRegExp re;
146 re.setWildcard(true); // most people understand these better. 148 re.setWildcard(true); // most people understand these better.
147 re.setCaseSensitive(false); 149 re.setCaseSensitive(false);
148 re.setPattern( pattern ); 150 re.setPattern( pattern );
149 if (!re.isValid()) 151 if (!re.isValid())
150 return; 152 return;
151 KABC::Addressee::List addresseeList = addressees(); 153 KABC::Addressee::List addresseeList = addressees();
152 KABC::Addressee::List::Iterator it; 154 KABC::Addressee::List::Iterator it;
153 if ( field ) { 155 if ( field ) {
154 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 156 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
155 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 157 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
156 continue; 158 continue;
157#if QT_VERSION >= 300 159#if QT_VERSION >= 300
158 if (re.search(field->value( *it ).lower()) != -1) 160 if (re.search(field->value( *it ).lower()) != -1)
159#else 161#else
160 if (re.match(field->value( *it ).lower()) != -1) 162 if (re.match(field->value( *it ).lower()) != -1)
161#endif 163#endif
162 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); 164 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
163 165
164 } 166 }
165 } else { 167 } else {
166 KABC::Field::List fieldList = allFields(); 168 KABC::Field::List fieldList = allFields();
167 KABC::Field::List::ConstIterator fieldIt; 169 KABC::Field::List::ConstIterator fieldIt;
168 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 170 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
169 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 171 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
170 continue; 172 continue;
171 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { 173 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
172#if QT_VERSION >= 300 174#if QT_VERSION >= 300
173 if (re.search((*fieldIt)->value( *it ).lower()) != -1) 175 if (re.search((*fieldIt)->value( *it ).lower()) != -1)
174#else 176#else
175 if (re.match((*fieldIt)->value( *it ).lower()) != -1) 177 if (re.match((*fieldIt)->value( *it ).lower()) != -1)
176#endif 178#endif
177 { 179 {
178 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); 180 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
179 break; 181 break;
180 } 182 }
181 } 183 }
182 } 184 }
183 } 185 }
184 // Sometimes the background pixmap gets messed up when we add lots 186 // Sometimes the background pixmap gets messed up when we add lots
185 // of items. 187 // of items.
186 mListView->repaint(); 188 mListView->repaint();
187 if ( mListView->firstChild() ) { 189 if ( mListView->firstChild() ) {
188 mListView->setCurrentItem ( mListView->firstChild() ); 190 mListView->setCurrentItem ( mListView->firstChild() );
189 mListView->setSelected ( mListView->firstChild(), true ); 191 mListView->setSelected ( mListView->firstChild(), true );
190 } 192 }
191 else 193 else
192 emit selected(QString::null); 194 emit selected(QString::null);
193 195
194} 196}
195void KAddressBookTableView::writeConfig(KConfig *config) 197void KAddressBookTableView::writeConfig(KConfig *config)
196{ 198{
197 KAddressBookView::writeConfig(config); 199 KAddressBookView::writeConfig(config);
198 200
199 mListView->saveLayout(config, config->group()); 201 mListView->saveLayout(config, config->group());
200} 202}
201 203
202void KAddressBookTableView::readConfig(KConfig *config) 204void KAddressBookTableView::readConfig(KConfig *config)
203{ 205{
204 KAddressBookView::readConfig( config ); 206 KAddressBookView::readConfig( config );
205 // The config could have changed the fields, so we need to reconstruct 207 // The config could have changed the fields, so we need to reconstruct
206 // the listview. 208 // the listview.
207 reconstructListView(); 209 reconstructListView();
208 210
209 // costum colors? 211 // costum colors?
210 if ( config->readBoolEntry( "EnableCustomColors", false ) ) 212 if ( config->readBoolEntry( "EnableCustomColors", false ) )
211 { 213 {
212 QPalette p( mListView->palette() ); 214 QPalette p( mListView->palette() );
213 QColor c = p.color(QPalette::Normal, QColorGroup::Base ); 215 QColor c = p.color(QPalette::Normal, QColorGroup::Base );
214 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); 216 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) );
215 c = p.color(QPalette::Normal, QColorGroup::Text ); 217 c = p.color(QPalette::Normal, QColorGroup::Text );
216 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); 218 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) );
217 c = p.color(QPalette::Normal, QColorGroup::Button ); 219 c = p.color(QPalette::Normal, QColorGroup::Button );
218 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); 220 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) );
219 c = p.color(QPalette::Normal, QColorGroup::ButtonText ); 221 c = p.color(QPalette::Normal, QColorGroup::ButtonText );
220 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); 222 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) );
221 c = p.color(QPalette::Normal, QColorGroup::Highlight ); 223 c = p.color(QPalette::Normal, QColorGroup::Highlight );
222 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); 224 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) );
223 c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); 225 c = p.color(QPalette::Normal, QColorGroup::HighlightedText );
224 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); 226 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) );
225#ifndef KAB_EMBEDDED 227#ifndef KAB_EMBEDDED
226 c = KGlobalSettings::alternateBackgroundColor(); 228 c = KGlobalSettings::alternateBackgroundColor();
227#else //KAB_EMBEDDED 229#else //KAB_EMBEDDED
228 c = QColor(240, 240, 240); 230 c = QColor(240, 240, 240);
229#endif //KAB_EMBEDDED 231#endif //KAB_EMBEDDED
230 c = config->readColorEntry ("AlternatingBackgroundColor", &c); 232 c = config->readColorEntry ("AlternatingBackgroundColor", &c);
231 mListView->setAlternateColor(c); 233 mListView->setAlternateColor(c);
232 234
233 235
234 //US mListView->viewport()->setPalette( p ); 236 //US mListView->viewport()->setPalette( p );
235 mListView->setPalette( p ); 237 mListView->setPalette( p );
236 } 238 }
237 else 239 else
238 { 240 {
239 // needed if turned off during a session. 241 // needed if turned off during a session.
240 //US mListView->viewport()->setPalette( mListView->palette() ); 242 //US mListView->viewport()->setPalette( mListView->palette() );
241 mListView->setPalette( mListView->palette() ); 243 mListView->setPalette( mListView->palette() );
242 } 244 }
243 245
244 //custom fonts? 246 //custom fonts?
245 QFont f( font() ); 247 QFont f( font() );
246 if ( config->readBoolEntry( "EnableCustomFonts", false ) ) 248 if ( config->readBoolEntry( "EnableCustomFonts", false ) )
247 { 249 {
248 mListView->setFont( config->readFontEntry( "TextFont", &f) ); 250 mListView->setFont( config->readFontEntry( "TextFont", &f) );
249 f.setBold( true ); 251 f.setBold( true );
250 //US mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); 252 //US mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) );
251 mListView->header()->setFont( config->readFontEntry( "HeaderFont", &f ) ); 253 mListView->header()->setFont( config->readFontEntry( "HeaderFont", &f ) );
252 } 254 }
253 else 255 else
254 { 256 {
255 mListView->setFont( f ); 257 mListView->setFont( f );
256 f.setBold( true ); 258 f.setBold( true );
257 //US mListView->setHeaderFont( f ); 259 //US mListView->setHeaderFont( f );
258 mListView->header()->setFont( f ); 260 mListView->header()->setFont( f );
259 } 261 }
260 262
261 // Set the list view options 263 // Set the list view options
262 mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", 264 mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground",
263 true)); 265 true));
264 mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); 266 mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false));
265 mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); 267 mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true));
266 268
267 if (config->readBoolEntry("Background", false)) 269 if (config->readBoolEntry("Background", false))
268 mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); 270 mListView->setBackgroundPixmap(config->readEntry("BackgroundName"));
269 271
270 // Restore the layout of the listview 272 // Restore the layout of the listview
271 mListView->restoreLayout(config, config->group()); 273 mListView->restoreLayout(config, config->group());
272} 274}
273 275
274void KAddressBookTableView::refresh(QString uid) 276void KAddressBookTableView::refresh(QString uid)
275{ 277{
276 // For now just repopulate. In reality this method should 278 // For now just repopulate. In reality this method should
277 // check the value of uid, and if valid iterate through 279 // check the value of uid, and if valid iterate through
278 // the listview to find the entry, then tell it to refresh. 280 // the listview to find the entry, then tell it to refresh.
279 281
280 if (uid.isNull()) { 282 if (uid.isNull()) {
281 // Clear the list view 283 // Clear the list view
282 QString currentUID, nextUID; 284 QString currentUID, nextUID;
283#ifndef KAB_EMBEDDED 285#ifndef KAB_EMBEDDED
284 ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); 286 ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() );
285#else //KAB_EMBEDDED 287#else //KAB_EMBEDDED
286 ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() ); 288 ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() );
287#endif //KAB_EMBEDDED 289#endif //KAB_EMBEDDED
288 290
289 if ( currentItem ) { 291 if ( currentItem ) {
290#ifndef KAB_EMBEDDED 292#ifndef KAB_EMBEDDED
291 ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() ); 293 ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() );
292#else //KAB_EMBEDDED 294#else //KAB_EMBEDDED
293 ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() ); 295 ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() );
294#endif //KAB_EMBEDDED 296#endif //KAB_EMBEDDED
295 if ( nextItem ) 297 if ( nextItem )
296 nextUID = nextItem->addressee().uid(); 298 nextUID = nextItem->addressee().uid();
297 currentUID = currentItem->addressee().uid(); 299 currentUID = currentItem->addressee().uid();
298 } 300 }
299 301
300 mListView->clear(); 302 mListView->clear();
301 303
302 currentItem = 0; 304 currentItem = 0;
303 KABC::Addressee::List addresseeList = addressees(); 305 KABC::Addressee::List addresseeList = addressees();
304 KABC::Addressee::List::Iterator it; 306 KABC::Addressee::List::Iterator it;
305 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 307 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
306 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 308 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
307 continue; 309 continue;
308 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); 310 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
309 if ( (*it).uid() == currentUID ) 311 if ( (*it).uid() == currentUID )
310 currentItem = item; 312 currentItem = item;
311 else if ( (*it).uid() == nextUID && !currentItem ) 313 else if ( (*it).uid() == nextUID && !currentItem )
312 currentItem = item; 314 currentItem = item;
313 } 315 }
314 316
315 // Sometimes the background pixmap gets messed up when we add lots 317 // Sometimes the background pixmap gets messed up when we add lots
316 // of items. 318 // of items.
317 mListView->repaint(); 319 mListView->repaint();
318 320
319 if ( currentItem ) { 321 if ( currentItem ) {
320 mListView->setCurrentItem( currentItem ); 322 mListView->setCurrentItem( currentItem );
321 mListView->ensureItemVisible( currentItem ); 323 mListView->ensureItemVisible( currentItem );
322 } 324 }
323 } else { 325 } else {
324 // Only need to update on entry. Iterate through and try to find it 326 // Only need to update on entry. Iterate through and try to find it
325 ContactListViewItem *ceItem; 327 ContactListViewItem *ceItem;
326 QListViewItemIterator it( mListView ); 328 QListViewItemIterator it( mListView );
327 while ( it.current() ) { 329 while ( it.current() ) {
328#ifndef KAB_EMBEDDED 330#ifndef KAB_EMBEDDED
329 ceItem = dynamic_cast<ContactListViewItem*>( it.current() ); 331 ceItem = dynamic_cast<ContactListViewItem*>( it.current() );
330#else //KAB_EMBEDDED 332#else //KAB_EMBEDDED
331 ceItem = (ContactListViewItem*)( it.current() ); 333 ceItem = (ContactListViewItem*)( it.current() );
332#endif //KAB_EMBEDDED 334#endif //KAB_EMBEDDED
333 335
334 if ( ceItem && ceItem->addressee().uid() == uid ) { 336 if ( ceItem && ceItem->addressee().uid() == uid ) {
335 ceItem->refresh(); 337 ceItem->refresh();
336 return; 338 return;
337 } 339 }
338 ++it; 340 ++it;
339 } 341 }
340 342
341 refresh( QString::null ); 343 refresh( QString::null );
342 } 344 }
343} 345}
344 346
345QStringList KAddressBookTableView::selectedUids() 347QStringList KAddressBookTableView::selectedUids()
346{ 348{
347 QStringList uidList; 349 QStringList uidList;
348 QListViewItem *item; 350 QListViewItem *item;
349 ContactListViewItem *ceItem; 351 ContactListViewItem *ceItem;
350 352
351 for(item = mListView->firstChild(); item; item = item->itemBelow()) 353 for(item = mListView->firstChild(); item; item = item->itemBelow())
352 { 354 {
353 if (mListView->isSelected( item )) 355 if (mListView->isSelected( item ))
354 { 356 {
355#ifndef KAB_EMBEDDED 357#ifndef KAB_EMBEDDED
356 ceItem = dynamic_cast<ContactListViewItem*>(item); 358 ceItem = dynamic_cast<ContactListViewItem*>(item);
357#else //KAB_EMBEDDED 359#else //KAB_EMBEDDED
358 ceItem = (ContactListViewItem*)(item); 360 ceItem = (ContactListViewItem*)(item);
359#endif //KAB_EMBEDDED 361#endif //KAB_EMBEDDED
360 362
361 if (ceItem != 0L) 363 if (ceItem != 0L)
362 uidList << ceItem->addressee().uid(); 364 uidList << ceItem->addressee().uid();
363 } 365 }
364 } 366 }
365 if ( uidList.count() == 0 ) 367 if ( uidList.count() == 0 )
366 if ( mListView->currentItem() ) { 368 if ( mListView->currentItem() ) {
367 ceItem = (ContactListViewItem*)(mListView->currentItem()) ; 369 ceItem = (ContactListViewItem*)(mListView->currentItem()) ;
368 uidList << ceItem->addressee().uid(); 370 uidList << ceItem->addressee().uid();
369 } 371 }
370 372
371 return uidList; 373 return uidList;
372} 374}
373 375
374void KAddressBookTableView::setSelected(QString uid, bool selected) 376void KAddressBookTableView::setSelected(QString uid, bool selected)
375{ 377{
376 QListViewItem *item; 378 QListViewItem *item;
377 ContactListViewItem *ceItem; 379 ContactListViewItem *ceItem;
378 380
379 if (uid.isNull()) 381 if (uid.isNull())
380 { 382 {
381 mListView->selectAll(selected); 383 mListView->selectAll(selected);
382 } 384 }
383 else 385 else
384 { 386 {
385 for(item = mListView->firstChild(); item; item = item->itemBelow()) 387 for(item = mListView->firstChild(); item; item = item->itemBelow())
386 { 388 {
387#ifndef KAB_EMBEDDED 389#ifndef KAB_EMBEDDED
388 ceItem = dynamic_cast<ContactListViewItem*>(item); 390 ceItem = dynamic_cast<ContactListViewItem*>(item);
389#else //KAB_EMBEDDED 391#else //KAB_EMBEDDED
390 ceItem = (ContactListViewItem*)(item); 392 ceItem = (ContactListViewItem*)(item);
391#endif //KAB_EMBEDDED 393#endif //KAB_EMBEDDED
392 394
393 395
394 if ((ceItem != 0L) && (ceItem->addressee().uid() == uid)) 396 if ((ceItem != 0L) && (ceItem->addressee().uid() == uid))
395 { 397 {
396 mListView->setSelected(item, selected); 398 mListView->setSelected(item, selected);
397 399
398 if (selected) 400 if (selected)
399 mListView->ensureItemVisible(item); 401 mListView->ensureItemVisible(item);
400 } 402 }
401 } 403 }
402 } 404 }
403} 405}
404 406
405void KAddressBookTableView::addresseeSelected() 407void KAddressBookTableView::addresseeSelected()
406{ 408{
407 // We need to try to find the first selected item. This might not be the 409 // We need to try to find the first selected item. This might not be the
408 // last selected item, but when QListView is in multiselection mode, 410 // last selected item, but when QListView is in multiselection mode,
409 // there is no way to figure out which one was 411 // there is no way to figure out which one was
410 // selected last. 412 // selected last.
411 QListViewItem *item; 413 QListViewItem *item;
412 bool found =false; 414 bool found =false;
413 for (item = mListView->firstChild(); item && !found; 415 for (item = mListView->firstChild(); item && !found;
414 item = item->nextSibling()) 416 item = item->nextSibling())
415 { 417 {
416 if (item->isSelected()) 418 if (item->isSelected())
417 { 419 {
418 found = true; 420 found = true;
419#ifndef KAB_EMBEDDED 421#ifndef KAB_EMBEDDED
420 ContactListViewItem *ceItem 422 ContactListViewItem *ceItem
421 = dynamic_cast<ContactListViewItem*>(item); 423 = dynamic_cast<ContactListViewItem*>(item);
422#else //KAB_EMBEDDED 424#else //KAB_EMBEDDED
423 ContactListViewItem *ceItem 425 ContactListViewItem *ceItem
424 = (ContactListViewItem*)(item); 426 = (ContactListViewItem*)(item);
425#endif //KAB_EMBEDDED 427#endif //KAB_EMBEDDED
426 428
427 if ( ceItem ) emit selected(ceItem->addressee().uid()); 429 if ( ceItem ) emit selected(ceItem->addressee().uid());
428 } 430 }
429 } 431 }
430 432
431 if (!found) 433 if (!found)
432 emit selected(QString::null); 434 emit selected(QString::null);
433} 435}
434 436
435void KAddressBookTableView::addresseeExecuted(QListViewItem *item) 437void KAddressBookTableView::addresseeExecuted(QListViewItem *item)
436{ 438{
437 if (item) 439 if (item)
438 { 440 {
439#ifndef KAB_EMBEDDED 441#ifndef KAB_EMBEDDED
440 ContactListViewItem *ceItem 442 ContactListViewItem *ceItem
441 = dynamic_cast<ContactListViewItem*>(item); 443 = dynamic_cast<ContactListViewItem*>(item);
442#else //KAB_EMBEDDED 444#else //KAB_EMBEDDED
443 ContactListViewItem *ceItem 445 ContactListViewItem *ceItem
444 = (ContactListViewItem*)(item); 446 = (ContactListViewItem*)(item);
445#endif //KAB_EMBEDDED 447#endif //KAB_EMBEDDED
446 448
447 if (ceItem) 449 if (ceItem)
448 { 450 {
449 emit executed(ceItem->addressee().uid()); 451 emit executed(ceItem->addressee().uid());
450 } 452 }
451 } 453 }
452 else 454 else
453 { 455 {
454 emit executed(QString::null); 456 emit executed(QString::null);
455 } 457 }
456} 458}
457 459
458void KAddressBookTableView::addresseeDeleted() 460void KAddressBookTableView::addresseeDeleted()
459{ 461{
460 462
461 emit deleteRequest(); 463 emit deleteRequest();
462 464
463} 465}
464 466
465 467
466 468
467 469
468 470
469#ifndef KAB_EMBEDDED 471#ifndef KAB_EMBEDDED
470#include "kaddressbooktableview.moc" 472#include "kaddressbooktableview.moc"
471#endif //KAB_EMBEDDED 473#endif //KAB_EMBEDDED