summaryrefslogtreecommitdiff
authoreilers <eilers>2003-03-06 08:15:23 (UTC)
committer eilers <eilers>2003-03-06 08:15:23 (UTC)
commitde5ee3b655897d8d6b8b78fee3cb2b63f9a9bf8a (patch) (unidiff)
treea1be481f2d4281f7221f538f95bfe996ff5e2dfc
parentcaecd32d28df2c0de6982bf84c599c5b25880661 (diff)
downloadopie-de5ee3b655897d8d6b8b78fee3cb2b63f9a9bf8a.zip
opie-de5ee3b655897d8d6b8b78fee3cb2b63f9a9bf8a.tar.gz
opie-de5ee3b655897d8d6b8b78fee3cb2b63f9a9bf8a.tar.bz2
New table appearance by Dan Williams ! It looks like todolist, now ! Thanks
a lot !
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/addressbook/abtable.cpp36
-rw-r--r--core/pim/addressbook/abtable.h1
2 files changed, 35 insertions, 2 deletions
diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp
index 55b1ba1..a829dc2 100644
--- a/core/pim/addressbook/abtable.cpp
+++ b/core/pim/addressbook/abtable.cpp
@@ -1,780 +1,812 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) 3** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de)
4** 4**
5** This file is part of Qt Palmtop Environment. 5** This file is part of Qt Palmtop Environment.
6** 6**
7** This file may be distributed and/or modified under the terms of the 7** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software 8** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file. 10** packaging of this file.
11** 11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14** 14**
15** See http://www.trolltech.com/gpl/ for GPL licensing information. 15** See http://www.trolltech.com/gpl/ for GPL licensing information.
16** 16**
17** Contact info@trolltech.com if any conditions of this licensing are 17** Contact info@trolltech.com if any conditions of this licensing are
18** not clear to you. 18** not clear to you.
19** 19**
20**********************************************************************/ 20**********************************************************************/
21 21
22 22
23#include <qpe/categoryselect.h> 23#include <qpe/categoryselect.h>
24#include <qpe/config.h> 24#include <qpe/config.h>
25#include <qpe/stringutil.h> 25#include <qpe/stringutil.h>
26#include <qpe/qcopenvelope_qws.h> 26#include <qpe/qcopenvelope_qws.h>
27#include <qpe/timestring.h> 27#include <qpe/timestring.h>
28#include <qpe/resource.h> 28#include <qpe/resource.h>
29 29
30#include <opie/orecordlist.h> 30#include <opie/orecordlist.h>
31 31
32#include <qasciidict.h> 32#include <qasciidict.h>
33#include <qdatetime.h> 33#include <qdatetime.h>
34#include <qfile.h> 34#include <qfile.h>
35#include <qregexp.h> 35#include <qregexp.h>
36#include <qmessagebox.h> 36#include <qmessagebox.h>
37 37
38#include "abtable.h" 38#include "abtable.h"
39 39
40#include <errno.h> 40#include <errno.h>
41#include <fcntl.h> 41#include <fcntl.h>
42#include <unistd.h> 42#include <unistd.h>
43#include <stdlib.h> 43#include <stdlib.h>
44 44
45#include <ctype.h> //toupper() for key hack 45#include <ctype.h> //toupper() for key hack
46 46
47/*! 47/*!
48 \class AbTableItem abtable.h 48 \class AbTableItem abtable.h
49 49
50 \brief QTableItem based class for showing a field of an entry 50 \brief QTableItem based class for showing a field of an entry
51*/ 51*/
52 52
53AbTableItem::AbTableItem( QTable *t, EditType et, const QString &s, 53AbTableItem::AbTableItem( QTable *t, EditType et, const QString &s,
54 const QString &secondSortKey) 54 const QString &secondSortKey)
55 : QTableItem( t, et, s ) 55 : QTableItem( t, et, s )
56{ 56{
57 // sortKey = s.lower() + QChar( '\0' ) + secondSortKey.lower(); 57 // sortKey = s.lower() + QChar( '\0' ) + secondSortKey.lower();
58 sortKey = Qtopia::buildSortKey( s, secondSortKey ); 58 sortKey = Qtopia::buildSortKey( s, secondSortKey );
59} 59}
60 60
61int AbTableItem::alignment() const 61int AbTableItem::alignment() const
62{ 62{
63 return AlignLeft|AlignVCenter; 63 return AlignLeft|AlignVCenter;
64} 64}
65 65
66QString AbTableItem::key() const 66QString AbTableItem::key() const
67{ 67{
68 return sortKey; 68 return sortKey;
69} 69}
70 70
71// A way to reset the item, without out doing a delete or a new... 71// A way to reset the item, without out doing a delete or a new...
72void AbTableItem::setItem( const QString &txt, const QString &secondKey ) 72void AbTableItem::setItem( const QString &txt, const QString &secondKey )
73{ 73{
74 setText( txt ); 74 setText( txt );
75 sortKey = Qtopia::buildSortKey( txt, secondKey ); 75 sortKey = Qtopia::buildSortKey( txt, secondKey );
76 76
77 // sortKey = txt.lower() + QChar( '\0' ) + secondKey.lower(); 77 // sortKey = txt.lower() + QChar( '\0' ) + secondKey.lower();
78} 78}
79 79
80/*! 80/*!
81 \class AbPickItem abtable.h 81 \class AbPickItem abtable.h
82 82
83 \brief QTableItem based class for showing slection of an entry 83 \brief QTableItem based class for showing slection of an entry
84*/ 84*/
85 85
86AbPickItem::AbPickItem( QTable *t ) : 86AbPickItem::AbPickItem( QTable *t ) :
87 QTableItem(t, WhenCurrent, "?") 87 QTableItem(t, WhenCurrent, "?")
88{ 88{
89} 89}
90 90
91QWidget *AbPickItem::createEditor() const 91QWidget *AbPickItem::createEditor() const
92{ 92{
93 QComboBox* combo = new QComboBox( table()->viewport() ); 93 QComboBox* combo = new QComboBox( table()->viewport() );
94 ( (AbPickItem*)this )->cb = combo; 94 ( (AbPickItem*)this )->cb = combo;
95 AbTable* t = static_cast<AbTable*>(table()); 95 AbTable* t = static_cast<AbTable*>(table());
96 QStringList c = t->choiceNames(); 96 QStringList c = t->choiceNames();
97 int cur = 0; 97 int cur = 0;
98 for (QStringList::ConstIterator it = c.begin(); it!=c.end(); ++it) { 98 for (QStringList::ConstIterator it = c.begin(); it!=c.end(); ++it) {
99 if ( *it == text() ) 99 if ( *it == text() )
100 cur = combo->count(); 100 cur = combo->count();
101 combo->insertItem(*it); 101 combo->insertItem(*it);
102 } 102 }
103 combo->setCurrentItem(cur); 103 combo->setCurrentItem(cur);
104 return combo; 104 return combo;
105} 105}
106 106
107void AbPickItem::setContentFromEditor( QWidget *w ) 107void AbPickItem::setContentFromEditor( QWidget *w )
108{ 108{
109 if ( w->inherits("QComboBox") ) 109 if ( w->inherits("QComboBox") )
110 setText( ( (QComboBox*)w )->currentText() ); 110 setText( ( (QComboBox*)w )->currentText() );
111 else 111 else
112 QTableItem::setContentFromEditor( w ); 112 QTableItem::setContentFromEditor( w );
113} 113}
114 114
115/*! 115/*!
116 \class AbTable abtable.h 116 \class AbTable abtable.h
117 117
118 \brief QTable based class for showing a list of entries 118 \brief QTable based class for showing a list of entries
119*/ 119*/
120 120
121AbTable::AbTable( const QValueList<int> order, QWidget *parent, const char *name ) 121AbTable::AbTable( const QValueList<int> order, QWidget *parent, const char *name )
122 : QTable( parent, name ), 122 : QTable( parent, name ),
123 lastSortCol( -1 ), 123 lastSortCol( -1 ),
124 asc( TRUE ), 124 asc( TRUE ),
125 intFields( order ), 125 intFields( order ),
126 enablePainting( true ), 126 enablePainting( true ),
127 columnVisible( true ), 127 columnVisible( true ),
128 countNested( 0 ) 128 countNested( 0 )
129{ 129{
130 //qWarning("C'tor start"); 130 //qWarning("C'tor start");
131 131
132 setSelectionMode( NoSelection ); 132 setSelectionMode( NoSelection );
133 init(); 133 init();
134 setSorting( TRUE ); 134 setSorting( TRUE );
135 connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), 135 connect( this, SIGNAL(clicked(int,int,int,const QPoint &)),
136 this, SLOT(itemClicked(int,int)) ); 136 this, SLOT(itemClicked(int,int)) );
137 137
138 contactList.clear(); 138 contactList.clear();
139 //qWarning("C'tor end"); 139 //qWarning("C'tor end");
140} 140}
141 141
142AbTable::~AbTable() 142AbTable::~AbTable()
143{ 143{
144} 144}
145 145
146void AbTable::init() 146void AbTable::init()
147{ 147{
148 // :SX showChar = '\0'; 148 // :SX showChar = '\0';
149 setNumRows( 0 ); 149 setNumRows( 0 );
150 setNumCols( 2 ); 150 setNumCols( 2 );
151 151
152 horizontalHeader()->setLabel( 0, tr( "Full Name" )); 152 horizontalHeader()->setLabel( 0, tr( "Full Name" ));
153 horizontalHeader()->setLabel( 1, tr( "Contact" )); 153 horizontalHeader()->setLabel( 1, tr( "Contact" ));
154 setLeftMargin( 0 ); 154 setLeftMargin( 0 );
155 verticalHeader()->hide(); 155 verticalHeader()->hide();
156 columnVisible = true; 156 columnVisible = true;
157} 157}
158 158
159void AbTable::setContacts( const OContactAccess::List& viewList ) 159void AbTable::setContacts( const OContactAccess::List& viewList )
160{ 160{
161 //qWarning("AbTable::setContacts()"); 161 //qWarning("AbTable::setContacts()");
162 162
163 clear(); 163 clear();
164 m_viewList = viewList; 164 m_viewList = viewList;
165 165
166 setSorting( false ); 166 setSorting( false );
167 setPaintingEnabled( FALSE ); 167 setPaintingEnabled( FALSE );
168 168
169 OContactAccess::List::Iterator it; 169 OContactAccess::List::Iterator it;
170 setNumRows( m_viewList.count() ); 170 setNumRows( m_viewList.count() );
171 int row = 0; 171 int row = 0;
172 for ( it = m_viewList.begin(); it != m_viewList.end(); ++it ) 172 for ( it = m_viewList.begin(); it != m_viewList.end(); ++it )
173 insertIntoTable( *it, row++ ); 173 insertIntoTable( *it, row++ );
174 174
175 setSorting( true ); 175 setSorting( true );
176 176
177 resort(); 177 resort();
178 178
179 updateVisible(); 179 updateVisible();
180 180
181 setPaintingEnabled( TRUE ); 181 setPaintingEnabled( TRUE );
182 182
183} 183}
184 184
185bool AbTable::selectContact( int UID ) 185bool AbTable::selectContact( int UID )
186{ 186{
187 //qWarning( "AbTable::selectContact( %d )", UID ); 187 //qWarning( "AbTable::selectContact( %d )", UID );
188 int rows = numRows(); 188 int rows = numRows();
189 AbTableItem *abi; 189 AbTableItem *abi;
190 OContact* foundContact = 0l; 190 OContact* foundContact = 0l;
191 bool found = false; 191 bool found = false;
192 192
193 setPaintingEnabled( FALSE ); 193 setPaintingEnabled( FALSE );
194 for ( int r = 0; r < rows; ++r ) { 194 for ( int r = 0; r < rows; ++r ) {
195 abi = static_cast<AbTableItem*>( item(r, 0) ); 195 abi = static_cast<AbTableItem*>( item(r, 0) );
196 foundContact = &contactList[abi]; 196 foundContact = &contactList[abi];
197 if ( foundContact -> uid() == UID ){ 197 if ( foundContact -> uid() == UID ){
198 ensureCellVisible( r, 0 ); 198 ensureCellVisible( r, 0 );
199 setCurrentCell( r, 0 ); 199 setCurrentCell( r, 0 );
200 found = true; 200 found = true;
201 break; 201 break;
202 } 202 }
203 } 203 }
204 204
205 if ( !found ){ 205 if ( !found ){
206 ensureCellVisible( 0,0 ); 206 ensureCellVisible( 0,0 );
207 setCurrentCell( 0, 0 ); 207 setCurrentCell( 0, 0 );
208 } 208 }
209 209
210 setPaintingEnabled( TRUE ); 210 setPaintingEnabled( TRUE );
211 211
212 return true; 212 return true;
213} 213}
214 214
215void AbTable::insertIntoTable( const OContact& cnt, int row ) 215void AbTable::insertIntoTable( const OContact& cnt, int row )
216{ 216{
217 //qWarning( "void AbTable::insertIntoTable( const OContact& cnt, %d )", row ); 217 //qWarning( "void AbTable::insertIntoTable( const OContact& cnt, %d )", row );
218 QString strName; 218 QString strName;
219 ContactItem contactItem; 219 ContactItem contactItem;
220 220
221 strName = findContactName( cnt ); 221 strName = findContactName( cnt );
222 contactItem = findContactContact( cnt, row ); 222 contactItem = findContactContact( cnt, row );
223 223
224 AbTableItem *ati; 224 AbTableItem *ati;
225 ati = new AbTableItem( this, QTableItem::Never, strName, contactItem.value ); 225 ati = new AbTableItem( this, QTableItem::Never, strName, contactItem.value );
226 contactList.insert( ati, cnt ); 226 contactList.insert( ati, cnt );
227 setItem( row, 0, ati ); 227 setItem( row, 0, ati );
228 ati = new AbTableItem( this, QTableItem::Never, contactItem.value, strName); 228 ati = new AbTableItem( this, QTableItem::Never, contactItem.value, strName);
229 if ( !contactItem.icon.isNull() ) 229 if ( !contactItem.icon.isNull() )
230 ati->setPixmap( contactItem.icon ); 230 ati->setPixmap( contactItem.icon );
231 setItem( row, 1, ati ); 231 setItem( row, 1, ati );
232 232
233 //### cannot do this; table only has two columns at this point 233 //### cannot do this; table only has two columns at this point
234 // setItem( row, 2, new AbPickItem( this ) ); 234 // setItem( row, 2, new AbPickItem( this ) );
235 235
236} 236}
237 237
238 238
239 239
240void AbTable::columnClicked( int col ) 240void AbTable::columnClicked( int col )
241{ 241{
242 if ( !sorting() ) 242 if ( !sorting() )
243 return; 243 return;
244 244
245 if ( lastSortCol == -1 ) 245 if ( lastSortCol == -1 )
246 lastSortCol = col; 246 lastSortCol = col;
247 247
248 if ( col == lastSortCol ) { 248 if ( col == lastSortCol ) {
249 asc = !asc; 249 asc = !asc;
250 } else { 250 } else {
251 lastSortCol = col; 251 lastSortCol = col;
252 asc = TRUE; 252 asc = TRUE;
253 } 253 }
254 //QMessageBox::information( this, "resort", "columnClicked" ); 254 //QMessageBox::information( this, "resort", "columnClicked" );
255 resort(); 255 resort();
256} 256}
257 257
258void AbTable::resort() 258void AbTable::resort()
259{ 259{
260 //qWarning( "void AbTable::resort()" ); 260 //qWarning( "void AbTable::resort()" );
261 setPaintingEnabled( FALSE ); 261 setPaintingEnabled( FALSE );
262 if ( sorting() ) { 262 if ( sorting() ) {
263 if ( lastSortCol == -1 ) 263 if ( lastSortCol == -1 )
264 lastSortCol = 0; 264 lastSortCol = 0;
265 sortColumn( lastSortCol, asc, TRUE ); 265 sortColumn( lastSortCol, asc, TRUE );
266 //QMessageBox::information( this, "resort", "resort" ); 266 //QMessageBox::information( this, "resort", "resort" );
267 updateVisible(); 267 updateVisible();
268 } 268 }
269 setPaintingEnabled( TRUE ); 269 setPaintingEnabled( TRUE );
270} 270}
271 271
272OContact AbTable::currentEntry() 272OContact AbTable::currentEntry()
273{ 273{
274 //qWarning( "OContact AbTable::currentEntry()" ); 274 //qWarning( "OContact AbTable::currentEntry()" );
275 OContact cnt; 275 OContact cnt;
276 AbTableItem *abItem; 276 AbTableItem *abItem;
277 abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); 277 abItem = static_cast<AbTableItem*>(item( currentRow(), 0 ));
278 if ( abItem ) { 278 if ( abItem ) {
279 cnt = contactList[abItem]; 279 cnt = contactList[abItem];
280 //cnt = contactList[currentRow()]; 280 //cnt = contactList[currentRow()];
281 } 281 }
282 return cnt; 282 return cnt;
283} 283}
284 284
285int AbTable::currentEntry_UID() 285int AbTable::currentEntry_UID()
286{ 286{
287 return ( currentEntry().uid() ); 287 return ( currentEntry().uid() );
288} 288}
289 289
290void AbTable::clear() 290void AbTable::clear()
291{ 291{
292 //qWarning( "void AbTable::clear()" ); 292 //qWarning( "void AbTable::clear()" );
293 contactList.clear(); 293 contactList.clear();
294 294
295 setPaintingEnabled( FALSE ); 295 setPaintingEnabled( FALSE );
296 for ( int r = 0; r < numRows(); ++r ) { 296 for ( int r = 0; r < numRows(); ++r ) {
297 for ( int c = 0; c < numCols(); ++c ) { 297 for ( int c = 0; c < numCols(); ++c ) {
298 if ( cellWidget( r, c ) ) 298 if ( cellWidget( r, c ) )
299 clearCellWidget( r, c ); 299 clearCellWidget( r, c );
300 clearCell( r, c ); 300 clearCell( r, c );
301 } 301 }
302 } 302 }
303 setNumRows( 0 ); 303 setNumRows( 0 );
304 setPaintingEnabled( TRUE ); 304 setPaintingEnabled( TRUE );
305} 305}
306 306
307// Refresh updates column 2 if the contactsettings changed 307// Refresh updates column 2 if the contactsettings changed
308void AbTable::refresh() 308void AbTable::refresh()
309{ 309{
310 //qWarning( "void AbTable::refresh()" ); 310 //qWarning( "void AbTable::refresh()" );
311 int rows = numRows(); 311 int rows = numRows();
312 AbTableItem *abi; 312 AbTableItem *abi;
313 ContactItem contactItem; 313 ContactItem contactItem;
314 314
315 setPaintingEnabled( FALSE ); 315 setPaintingEnabled( FALSE );
316 for ( int r = 0; r < rows; ++r ) { 316 for ( int r = 0; r < rows; ++r ) {
317 abi = static_cast<AbTableItem*>( item(r, 0) ); 317 abi = static_cast<AbTableItem*>( item(r, 0) );
318 contactItem = findContactContact( contactList[abi], r ); 318 contactItem = findContactContact( contactList[abi], r );
319 static_cast<AbTableItem*>( item(r, 1) )->setItem( contactItem.value, abi->text() ); 319 static_cast<AbTableItem*>( item(r, 1) )->setItem( contactItem.value, abi->text() );
320 if ( !contactItem.icon.isNull() ) 320 if ( !contactItem.icon.isNull() )
321 static_cast<AbTableItem*>( item(r, 1) )-> 321 static_cast<AbTableItem*>( item(r, 1) )->
322 setPixmap( contactItem.icon ); 322 setPixmap( contactItem.icon );
323 323
324 } 324 }
325 resort(); 325 resort();
326 setPaintingEnabled( TRUE ); 326 setPaintingEnabled( TRUE );
327} 327}
328 328
329void AbTable::keyPressEvent( QKeyEvent *e ) 329void AbTable::keyPressEvent( QKeyEvent *e )
330{ 330{
331 char key = toupper( e->ascii() ); 331 char key = toupper( e->ascii() );
332 332
333 if ( key >= 'A' && key <= 'Z' ) 333 if ( key >= 'A' && key <= 'Z' )
334 moveTo( key ); 334 moveTo( key );
335 335
336 //qWarning("Received key .."); 336 //qWarning("Received key ..");
337 switch( e->key() ) { 337 switch( e->key() ) {
338 case Qt::Key_Space: 338 case Qt::Key_Space:
339 case Qt::Key_Return: 339 case Qt::Key_Return:
340 case Qt::Key_Enter: 340 case Qt::Key_Enter:
341 emit signalSwitch(); 341 emit signalSwitch();
342 break; 342 break;
343 // case Qt::Key_Up: 343 // case Qt::Key_Up:
344 // qWarning("a"); 344 // qWarning("a");
345 // emit signalKeyUp(); 345 // emit signalKeyUp();
346 // break; 346 // break;
347 // case Qt::Key_Down: 347 // case Qt::Key_Down:
348 // qWarning("b"); 348 // qWarning("b");
349 // emit signalKeyDown(); 349 // emit signalKeyDown();
350 // break; 350 // break;
351 default: 351 default:
352 QTable::keyPressEvent( e ); 352 QTable::keyPressEvent( e );
353 } 353 }
354 354
355} 355}
356 356
357void AbTable::moveTo( char c ) 357void AbTable::moveTo( char c )
358{ 358{
359 qWarning( "void AbTable::moveTo( char c )" ); 359 qWarning( "void AbTable::moveTo( char c )" );
360 360
361 int rows = numRows(); 361 int rows = numRows();
362 QString value; 362 QString value;
363 AbTableItem *abi; 363 AbTableItem *abi;
364 int r; 364 int r;
365 if ( asc ) { 365 if ( asc ) {
366 r = 0; 366 r = 0;
367 while ( r < rows-1) { 367 while ( r < rows-1) {
368 abi = static_cast<AbTableItem*>( item(r, 0) ); 368 abi = static_cast<AbTableItem*>( item(r, 0) );
369 QChar first = abi->key()[0]; 369 QChar first = abi->key()[0];
370 //### is there a bug in QChar to char comparison??? 370 //### is there a bug in QChar to char comparison???
371 if ( first.row() || first.cell() >= c ) 371 if ( first.row() || first.cell() >= c )
372 break; 372 break;
373 r++; 373 r++;
374 } 374 }
375 } else { 375 } else {
376 //### should probably disable reverse sorting instead 376 //### should probably disable reverse sorting instead
377 r = rows - 1; 377 r = rows - 1;
378 while ( r > 0 ) { 378 while ( r > 0 ) {
379 abi = static_cast<AbTableItem*>( item(r, 0) ); 379 abi = static_cast<AbTableItem*>( item(r, 0) );
380 QChar first = abi->key()[0]; 380 QChar first = abi->key()[0];
381 //### is there a bug in QChar to char comparison??? 381 //### is there a bug in QChar to char comparison???
382 if ( first.row() || first.cell() >= c ) 382 if ( first.row() || first.cell() >= c )
383 break; 383 break;
384 r--; 384 r--;
385 } 385 }
386 } 386 }
387 setCurrentCell( r, currentColumn() ); 387 setCurrentCell( r, currentColumn() );
388} 388}
389 389
390 390
391QString AbTable::findContactName( const OContact &entry ) 391QString AbTable::findContactName( const OContact &entry )
392{ 392{
393 // We use the fileAs, then company, defaultEmail 393 // We use the fileAs, then company, defaultEmail
394 QString str; 394 QString str;
395 str = entry.fileAs(); 395 str = entry.fileAs();
396 if ( str.isEmpty() ) { 396 if ( str.isEmpty() ) {
397 str = entry.company(); 397 str = entry.company();
398 if ( str.isEmpty() ) { 398 if ( str.isEmpty() ) {
399 str = entry.defaultEmail(); 399 str = entry.defaultEmail();
400 } 400 }
401 } 401 }
402 return str; 402 return str;
403} 403}
404 404
405 405
406 406
407void AbTable::resizeRows() { 407void AbTable::resizeRows() {
408 /* 408 /*
409 if (numRows()) { 409 if (numRows()) {
410 for (int i = 0; i < numRows(); i++) { 410 for (int i = 0; i < numRows(); i++) {
411 setRowHeight( i, size ); 411 setRowHeight( i, size );
412 } 412 }
413 } 413 }
414 updateVisible(); 414 updateVisible();
415 */ 415 */
416} 416}
417 417
418 418
419void AbTable::realignTable() 419void AbTable::realignTable()
420{ 420{
421 //qWarning( "void AbTable::realignTable()" ); 421 //qWarning( "void AbTable::realignTable()" );
422 422
423 setPaintingEnabled( FALSE ); 423 setPaintingEnabled( FALSE );
424 424
425 resizeRows(); 425 resizeRows();
426 fitColumns(); 426 fitColumns();
427 427
428 setPaintingEnabled( TRUE ); 428 setPaintingEnabled( TRUE );
429 429
430} 430}
431 431
432 432
433 433
434 434
435#if QT_VERSION <= 230 435#if QT_VERSION <= 230
436#ifndef SINGLE_APP 436#ifndef SINGLE_APP
437void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) 437void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch )
438{ 438{
439 // Region of the rect we should draw 439 // Region of the rect we should draw
440 QRegion reg( QRect( cx, cy, cw, ch ) ); 440 QRegion reg( QRect( cx, cy, cw, ch ) );
441 // Subtract the table from it 441 // Subtract the table from it
442 reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) ); 442 reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) );
443 // And draw the rectangles (transformed as needed) 443 // And draw the rectangles (transformed as needed)
444 QArray<QRect> r = reg.rects(); 444 QArray<QRect> r = reg.rects();
445 for (unsigned int i=0; i<r.count(); i++) 445 for (unsigned int i=0; i<r.count(); i++)
446 p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) ); 446 p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) );
447} 447}
448#endif 448#endif
449#endif 449#endif
450 450
451 451
452// int AbTable::rowHeight( int ) const 452// int AbTable::rowHeight( int ) const
453// { 453// {
454// return 18; 454// return 18;
455// } 455// }
456 456
457// int AbTable::rowPos( int row ) const 457// int AbTable::rowPos( int row ) const
458// { 458// {
459// return 18*row; 459// return 18*row;
460// } 460// }
461 461
462// int AbTable::rowAt( int pos ) const 462// int AbTable::rowAt( int pos ) const
463// { 463// {
464// return QMIN( pos/18, numRows()-1 ); 464// return QMIN( pos/18, numRows()-1 );
465// } 465// }
466 466
467 467
468 468
469void AbTable::fitColumns() 469void AbTable::fitColumns()
470{ 470{
471 //qWarning( "void AbTable::fitColumns()" ); 471 //qWarning( "void AbTable::fitColumns()" );
472 int contentsWidth = visibleWidth() / 2; // :SX Why too low 472 int contentsWidth = visibleWidth() / 2; // :SX Why too low
473 // Fix to better value 473 // Fix to better value
474 // contentsWidth = 130; 474 // contentsWidth = 130;
475 475
476 setPaintingEnabled( FALSE ); 476 setPaintingEnabled( FALSE );
477 477
478 if ( columnVisible == false ){ 478 if ( columnVisible == false ){
479 showColumn(0); 479 showColumn(0);
480 columnVisible = true; 480 columnVisible = true;
481 } 481 }
482 482
483 //qWarning("Width: %d", contentsWidth); 483 //qWarning("Width: %d", contentsWidth);
484 484
485 setColumnWidth( 0, contentsWidth ); 485 setColumnWidth( 0, contentsWidth );
486 adjustColumn(1); 486 adjustColumn(1);
487 if ( columnWidth(1) < contentsWidth ) 487 if ( columnWidth(1) < contentsWidth )
488 setColumnWidth( 1, contentsWidth ); 488 setColumnWidth( 1, contentsWidth );
489 489
490 setPaintingEnabled( TRUE ); 490 setPaintingEnabled( TRUE );
491} 491}
492 492
493void AbTable::show() 493void AbTable::show()
494{ 494{
495 //qWarning( "void AbTable::show()" ); 495 //qWarning( "void AbTable::show()" );
496 realignTable(); 496 realignTable();
497 QTable::show(); 497 QTable::show();
498} 498}
499 499
500void AbTable::setChoiceNames( const QStringList& list) 500void AbTable::setChoiceNames( const QStringList& list)
501{ 501{
502 choicenames = list; 502 choicenames = list;
503 if ( choicenames.isEmpty() ) { 503 if ( choicenames.isEmpty() ) {
504 // hide pick column 504 // hide pick column
505 setNumCols( 2 ); 505 setNumCols( 2 );
506 } else { 506 } else {
507 // show pick column 507 // show pick column
508 setNumCols( 3 ); 508 setNumCols( 3 );
509 setColumnWidth( 2, fontMetrics().width(tr( "Pick" ))+8 ); 509 setColumnWidth( 2, fontMetrics().width(tr( "Pick" ))+8 );
510 horizontalHeader()->setLabel( 2, tr( "Pick" )); 510 horizontalHeader()->setLabel( 2, tr( "Pick" ));
511 } 511 }
512 fitColumns(); 512 fitColumns();
513} 513}
514 514
515void AbTable::itemClicked(int,int col) 515void AbTable::itemClicked(int,int col)
516{ 516{
517 //qWarning( "AbTable::itemClicked(int, col:%d)", col); 517 //qWarning( "AbTable::itemClicked(int, col:%d)", col);
518 if ( col == 2 ) { 518 if ( col == 2 ) {
519 return; 519 return;
520 } else { 520 } else {
521 // qWarning ("Emitting signalSwitch()"); 521 // qWarning ("Emitting signalSwitch()");
522 emit signalSwitch(); 522 emit signalSwitch();
523 } 523 }
524} 524}
525 525
526QStringList AbTable::choiceNames() const 526QStringList AbTable::choiceNames() const
527{ 527{
528 return choicenames; 528 return choicenames;
529} 529}
530 530
531void AbTable::setChoiceSelection( const QValueList<int>& list ) 531void AbTable::setChoiceSelection( const QValueList<int>& list )
532{ 532{
533 intFields = list; 533 intFields = list;
534} 534}
535 535
536QStringList AbTable::choiceSelection(int /*index*/) const 536QStringList AbTable::choiceSelection(int /*index*/) const
537{ 537{
538 QStringList r; 538 QStringList r;
539 /* ###### 539 /* ######
540 540
541 QString selname = choicenames.at(index); 541 QString selname = choicenames.at(index);
542 for (each row) { 542 for (each row) {
543 OContact *c = contactForRow(row); 543 OContact *c = contactForRow(row);
544 if ( text(row,2) == selname ) { 544 if ( text(row,2) == selname ) {
545 r.append(c->email); 545 r.append(c->email);
546 } 546 }
547 } 547 }
548 548
549 */ 549 */
550 return r; 550 return r;
551} 551}
552 552
553 553
554 554
555 555
556void AbTable::updateVisible() 556void AbTable::updateVisible()
557{ 557{
558 //qWarning("void AbTable::updateVisible()"); 558 //qWarning("void AbTable::updateVisible()");
559 559
560 int visible, 560 int visible,
561 totalRows, 561 totalRows,
562 row, 562 row,
563 selectedRow = 0; 563 selectedRow = 0;
564 564
565 visible = 0; 565 visible = 0;
566 566
567 setPaintingEnabled( FALSE ); 567 setPaintingEnabled( FALSE );
568 568
569 realignTable(); 569 realignTable();
570 570
571 totalRows = numRows(); 571 totalRows = numRows();
572 for ( row = 0; row < totalRows; row++ ) { 572 for ( row = 0; row < totalRows; row++ ) {
573 if ( rowHeight(row) == 0 ) { 573 if ( rowHeight(row) == 0 ) {
574 showRow( row ); 574 showRow( row );
575 adjustRow( row ); 575 adjustRow( row );
576 if ( isSelected( row,0 ) || isSelected( row,1 ) ) 576 if ( isSelected( row,0 ) || isSelected( row,1 ) )
577 selectedRow = row; 577 selectedRow = row;
578 } 578 }
579 visible++; 579 visible++;
580 } 580 }
581 581
582 if ( selectedRow ) 582 if ( selectedRow )
583 setCurrentCell( selectedRow, 0 ); 583 setCurrentCell( selectedRow, 0 );
584 584
585 if ( !visible ) 585 if ( !visible )
586 setCurrentCell( -1, 0 ); 586 setCurrentCell( -1, 0 );
587 587
588 setPaintingEnabled( TRUE ); 588 setPaintingEnabled( TRUE );
589
590
591} 589}
592 590
593 591
594void AbTable::setPaintingEnabled( bool e ) 592void AbTable::setPaintingEnabled( bool e )
595{ 593{
596 //qWarning("IN void AbTable::setPaintingEnabled( %d )->Nested: %d", e, countNested ); 594 //qWarning("IN void AbTable::setPaintingEnabled( %d )->Nested: %d", e, countNested );
597 595
598 if ( e ) { 596 if ( e ) {
599 if ( countNested > 0 ) 597 if ( countNested > 0 )
600 --countNested; 598 --countNested;
601 if ( ! countNested ){ 599 if ( ! countNested ){
602 setUpdatesEnabled( true ); 600 setUpdatesEnabled( true );
603 enablePainting = true; 601 enablePainting = true;
604 rowHeightChanged( 0 ); 602 rowHeightChanged( 0 );
605 viewport()->update(); 603 viewport()->update();
606 } 604 }
607 } else { 605 } else {
608 ++countNested; 606 ++countNested;
609 enablePainting = false; 607 enablePainting = false;
610 setUpdatesEnabled( false ); 608 setUpdatesEnabled( false );
611 } 609 }
612 //qWarning("OUT void AbTable::setPaintingEnabled( %d )->Nested: %d", e, countNested ); 610 //qWarning("OUT void AbTable::setPaintingEnabled( %d )->Nested: %d", e, countNested );
613} 611}
614 612
615void AbTable::viewportPaintEvent( QPaintEvent* e ) { 613void AbTable::viewportPaintEvent( QPaintEvent* e ) {
616 //qWarning(" void AbTable::viewportPaintEvent( QPaintEvent* e ) -> %d", enablePainting); 614 //qWarning(" void AbTable::viewportPaintEvent( QPaintEvent* e ) -> %d", enablePainting);
617 if ( enablePainting ) 615 if ( enablePainting )
618 QTable::viewportPaintEvent( e ); 616 QTable::viewportPaintEvent( e );
619} 617}
620 618
619void AbTable::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) {
620 const QColorGroup &cg = colorGroup();
621
622 p->save();
623
624 // Paint alternating background bars
625 if ( (row % 2 ) == 0 ) {
626 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
627 p->setPen( QPen( cg.text() ) );
628 }
629 else {
630 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Background ) );
631 p->setPen( QPen( cg.buttonText() ) );
632 }
621 633
634 QFont f = p->font();
635 QFontMetrics fm(f);
636
637 int marg = 2;
638 int x = 0;
639 int y = ( cr.height() - 14 ) / 2;
640
641 QPixmap pic = pixmap( row, col );
642 if ( !pic.isNull() )
643 {
644 p->drawPixmap( x + marg, y, pixmap( row, col ) );
645 p->drawText( x + marg + pixmap( row, col ).width() + 4,2 + fm.ascent(), text( row, col ) );
646 }
647 else
648 {
649 p->drawText( x + marg,2 + fm.ascent(), text( row, col ) );
650 }
651
652 p->restore();
653}
622 654
623void AbTable::rowHeightChanged( int row ) 655void AbTable::rowHeightChanged( int row )
624{ 656{
625 if ( enablePainting ) 657 if ( enablePainting )
626 QTable::rowHeightChanged( row ); 658 QTable::rowHeightChanged( row );
627} 659}
628ContactItem AbTable::findContactContact( const OContact &entry, int /* row */ ) 660ContactItem AbTable::findContactContact( const OContact &entry, int /* row */ )
629{ 661{
630 662
631 ContactItem item; 663 ContactItem item;
632 664
633 item.value = ""; 665 item.value = "";
634 666
635 for ( QValueList<int>::ConstIterator it = intFields.begin(); 667 for ( QValueList<int>::ConstIterator it = intFields.begin();
636 it != intFields.end(); ++it ) { 668 it != intFields.end(); ++it ) {
637 switch ( *it ) { 669 switch ( *it ) {
638 default: 670 default:
639 break; 671 break;
640 case Qtopia::Title: 672 case Qtopia::Title:
641 item.value = entry.title(); 673 item.value = entry.title();
642 break; 674 break;
643 case Qtopia::Suffix: 675 case Qtopia::Suffix:
644 item.value = entry.suffix(); 676 item.value = entry.suffix();
645 break; 677 break;
646 case Qtopia::FileAs: 678 case Qtopia::FileAs:
647 item.value = entry.fileAs(); 679 item.value = entry.fileAs();
648 break; 680 break;
649 case Qtopia::DefaultEmail: 681 case Qtopia::DefaultEmail:
650 item.value = entry.defaultEmail(); 682 item.value = entry.defaultEmail();
651 if ( !item.value.isEmpty() ) 683 if ( !item.value.isEmpty() )
652 item.icon = Resource::loadPixmap( "addressbook/email" ); 684 item.icon = Resource::loadPixmap( "addressbook/email" );
653 break; 685 break;
654 case Qtopia::Emails: 686 case Qtopia::Emails:
655 item.value = entry.emails(); 687 item.value = entry.emails();
656 if ( !item.value.isEmpty() ) 688 if ( !item.value.isEmpty() )
657 item.icon = Resource::loadPixmap( "addressbook/email" ); 689 item.icon = Resource::loadPixmap( "addressbook/email" );
658 break; 690 break;
659 case Qtopia::HomeStreet: 691 case Qtopia::HomeStreet:
660 item.value = entry.homeStreet(); 692 item.value = entry.homeStreet();
661 break; 693 break;
662 case Qtopia::HomeCity: 694 case Qtopia::HomeCity:
663 item.value = entry.homeCity(); 695 item.value = entry.homeCity();
664 break; 696 break;
665 case Qtopia::HomeState: 697 case Qtopia::HomeState:
666 item.value = entry.homeState(); 698 item.value = entry.homeState();
667 break; 699 break;
668 case Qtopia::HomeZip: 700 case Qtopia::HomeZip:
669 item.value = entry.homeZip(); 701 item.value = entry.homeZip();
670 break; 702 break;
671 case Qtopia::HomeCountry: 703 case Qtopia::HomeCountry:
672 item.value = entry.homeCountry(); 704 item.value = entry.homeCountry();
673 break; 705 break;
674 case Qtopia::HomePhone: 706 case Qtopia::HomePhone:
675 item.value = entry.homePhone(); 707 item.value = entry.homePhone();
676 if ( !item.value.isEmpty() ) 708 if ( !item.value.isEmpty() )
677 item.icon = Resource::loadPixmap( "addressbook/phonehome" ); 709 item.icon = Resource::loadPixmap( "addressbook/phonehome" );
678 break; 710 break;
679 case Qtopia::HomeFax: 711 case Qtopia::HomeFax:
680 item.value = entry.homeFax(); 712 item.value = entry.homeFax();
681 if ( !item.value.isEmpty() ) 713 if ( !item.value.isEmpty() )
682 item.icon = Resource::loadPixmap( "addressbook/faxhome" ); 714 item.icon = Resource::loadPixmap( "addressbook/faxhome" );
683 break; 715 break;
684 case Qtopia::HomeMobile: 716 case Qtopia::HomeMobile:
685 item.value = entry.homeMobile(); 717 item.value = entry.homeMobile();
686 if ( !item.value.isEmpty() ) 718 if ( !item.value.isEmpty() )
687 item.icon = Resource::loadPixmap( "addressbook/mobilehome" ); 719 item.icon = Resource::loadPixmap( "addressbook/mobilehome" );
688 break; 720 break;
689 case Qtopia::HomeWebPage: 721 case Qtopia::HomeWebPage:
690 item.value = entry.homeWebpage(); 722 item.value = entry.homeWebpage();
691 if ( !item.value.isEmpty() ) 723 if ( !item.value.isEmpty() )
692 item.icon = Resource::loadPixmap( "addressbook/webpagehome" ); 724 item.icon = Resource::loadPixmap( "addressbook/webpagehome" );
693 break; 725 break;
694 case Qtopia::Company: 726 case Qtopia::Company:
695 item.value = entry.company(); 727 item.value = entry.company();
696 break; 728 break;
697 case Qtopia::BusinessCity: 729 case Qtopia::BusinessCity:
698 item.value = entry.businessCity(); 730 item.value = entry.businessCity();
699 break; 731 break;
700 case Qtopia::BusinessStreet: 732 case Qtopia::BusinessStreet:
701 item.value = entry.businessStreet(); 733 item.value = entry.businessStreet();
702 break; 734 break;
703 case Qtopia::BusinessZip: 735 case Qtopia::BusinessZip:
704 item.value = entry.businessZip(); 736 item.value = entry.businessZip();
705 break; 737 break;
706 case Qtopia::BusinessCountry: 738 case Qtopia::BusinessCountry:
707 item.value = entry.businessCountry(); 739 item.value = entry.businessCountry();
708 break; 740 break;
709 case Qtopia::BusinessWebPage: 741 case Qtopia::BusinessWebPage:
710 item.value = entry.businessWebpage(); 742 item.value = entry.businessWebpage();
711 if ( !item.value.isEmpty() ) 743 if ( !item.value.isEmpty() )
712 item.icon = Resource::loadPixmap( "addressbook/webpagework" ); 744 item.icon = Resource::loadPixmap( "addressbook/webpagework" );
713 break; 745 break;
714 case Qtopia::JobTitle: 746 case Qtopia::JobTitle:
715 item.value = entry.jobTitle(); 747 item.value = entry.jobTitle();
716 break; 748 break;
717 case Qtopia::Department: 749 case Qtopia::Department:
718 item.value = entry.department(); 750 item.value = entry.department();
719 break; 751 break;
720 case Qtopia::Office: 752 case Qtopia::Office:
721 item.value = entry.office(); 753 item.value = entry.office();
722 break; 754 break;
723 case Qtopia::BusinessPhone: 755 case Qtopia::BusinessPhone:
724 item.value = entry.businessPhone(); 756 item.value = entry.businessPhone();
725 if ( !item.value.isEmpty() ) 757 if ( !item.value.isEmpty() )
726 item.icon = Resource::loadPixmap( "addressbook/phonework" ); 758 item.icon = Resource::loadPixmap( "addressbook/phonework" );
727 break; 759 break;
728 case Qtopia::BusinessFax: 760 case Qtopia::BusinessFax:
729 item.value = entry.businessFax(); 761 item.value = entry.businessFax();
730 if ( !item.value.isEmpty() ) 762 if ( !item.value.isEmpty() )
731 item.icon = Resource::loadPixmap( "addressbook/faxwork" ); 763 item.icon = Resource::loadPixmap( "addressbook/faxwork" );
732 break; 764 break;
733 case Qtopia::BusinessMobile: 765 case Qtopia::BusinessMobile:
734 item.value = entry.businessMobile(); 766 item.value = entry.businessMobile();
735 if ( !item.value.isEmpty() ) 767 if ( !item.value.isEmpty() )
736 item.icon = Resource::loadPixmap( "addressbook/mobilework" ); 768 item.icon = Resource::loadPixmap( "addressbook/mobilework" );
737 break; 769 break;
738 case Qtopia::BusinessPager: 770 case Qtopia::BusinessPager:
739 item.value = entry.businessPager(); 771 item.value = entry.businessPager();
740 break; 772 break;
741 case Qtopia::Profession: 773 case Qtopia::Profession:
742 item.value = entry.profession(); 774 item.value = entry.profession();
743 break; 775 break;
744 case Qtopia::Assistant: 776 case Qtopia::Assistant:
745 item.value = entry.assistant(); 777 item.value = entry.assistant();
746 break; 778 break;
747 case Qtopia::Manager: 779 case Qtopia::Manager:
748 item.value = entry.manager(); 780 item.value = entry.manager();
749 break; 781 break;
750 case Qtopia::Spouse: 782 case Qtopia::Spouse:
751 item.value = entry.spouse(); 783 item.value = entry.spouse();
752 break; 784 break;
753 case Qtopia::Gender: 785 case Qtopia::Gender:
754 item.value = entry.gender(); 786 item.value = entry.gender();
755 break; 787 break;
756 case Qtopia::Birthday: 788 case Qtopia::Birthday:
757 if ( ! entry.birthday().isNull() ){ 789 if ( ! entry.birthday().isNull() ){
758 item.value = TimeString::numberDateString( entry.birthday() ); 790 item.value = TimeString::numberDateString( entry.birthday() );
759 } 791 }
760 break; 792 break;
761 case Qtopia::Anniversary: 793 case Qtopia::Anniversary:
762 if ( ! entry.anniversary().isNull() ){ 794 if ( ! entry.anniversary().isNull() ){
763 item.value = TimeString::numberDateString( entry.anniversary() ); 795 item.value = TimeString::numberDateString( entry.anniversary() );
764 } 796 }
765 break; 797 break;
766 case Qtopia::Nickname: 798 case Qtopia::Nickname:
767 item.value = entry.nickname(); 799 item.value = entry.nickname();
768 break; 800 break;
769 case Qtopia::Children: 801 case Qtopia::Children:
770 item.value = entry.children(); 802 item.value = entry.children();
771 break; 803 break;
772 case Qtopia::Notes: 804 case Qtopia::Notes:
773 item.value = entry.notes(); 805 item.value = entry.notes();
774 break; 806 break;
775 } 807 }
776 if ( !item.value.isEmpty() ) 808 if ( !item.value.isEmpty() )
777 break; 809 break;
778 } 810 }
779 return item; 811 return item;
780} 812}
diff --git a/core/pim/addressbook/abtable.h b/core/pim/addressbook/abtable.h
index 092e86f..4e6b294 100644
--- a/core/pim/addressbook/abtable.h
+++ b/core/pim/addressbook/abtable.h
@@ -1,147 +1,148 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) 3** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de)
4** 4**
5** This file is part of Qt Palmtop Environment. 5** This file is part of Qt Palmtop Environment.
6** 6**
7** This file may be distributed and/or modified under the terms of the 7** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software 8** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file. 10** packaging of this file.
11** 11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14** 14**
15** See http://www.trolltech.com/gpl/ for GPL licensing information. 15** See http://www.trolltech.com/gpl/ for GPL licensing information.
16** 16**
17** Contact info@trolltech.com if any conditions of this licensing are 17** Contact info@trolltech.com if any conditions of this licensing are
18** not clear to you. 18** not clear to you.
19** 19**
20**********************************************************************/ 20**********************************************************************/
21 21
22#ifndef ABTABLE_H 22#ifndef ABTABLE_H
23#define ABTABLE_H 23#define ABTABLE_H
24 24
25#include <qpe/categories.h> 25#include <qpe/categories.h>
26#include <opie/ocontact.h> 26#include <opie/ocontact.h>
27#include <opie/ocontactaccess.h> 27#include <opie/ocontactaccess.h>
28 28
29#include <qmap.h> 29#include <qmap.h>
30#include <qtable.h> 30#include <qtable.h>
31#include <qstringlist.h> 31#include <qstringlist.h>
32#include <qcombobox.h> 32#include <qcombobox.h>
33#include <qpixmap.h> 33#include <qpixmap.h>
34 34
35class AbTableItem : public QTableItem 35class AbTableItem : public QTableItem
36{ 36{
37public: 37public:
38 AbTableItem( QTable *t, EditType et, const QString &s, 38 AbTableItem( QTable *t, EditType et, const QString &s,
39 const QString &secondSortKey); 39 const QString &secondSortKey);
40 QString entryKey() const; 40 QString entryKey() const;
41 void setEntryKey( const QString & k ); 41 void setEntryKey( const QString & k );
42 virtual int alignment() const; 42 virtual int alignment() const;
43 virtual QString key() const; 43 virtual QString key() const;
44 void setItem( const QString &txt, const QString &secondKey ); 44 void setItem( const QString &txt, const QString &secondKey );
45 45
46private: 46private:
47 QString sortKey; 47 QString sortKey;
48}; 48};
49 49
50// This is a simple container, storing all contact 50// This is a simple container, storing all contact
51// information 51// information
52class ContactItem 52class ContactItem
53{ 53{
54 public: 54 public:
55 QPixmap icon; 55 QPixmap icon;
56 QString value; 56 QString value;
57}; 57};
58 58
59class AbPickItem : public QTableItem 59class AbPickItem : public QTableItem
60{ 60{
61public: 61public:
62 AbPickItem( QTable *t ); 62 AbPickItem( QTable *t );
63 63
64 QWidget *createEditor() const; 64 QWidget *createEditor() const;
65 void setContentFromEditor( QWidget *w ); 65 void setContentFromEditor( QWidget *w );
66 66
67private: 67private:
68 QGuardedPtr<QComboBox> cb; 68 QGuardedPtr<QComboBox> cb;
69}; 69};
70 70
71class AbTable : public QTable 71class AbTable : public QTable
72{ 72{
73 Q_OBJECT 73 Q_OBJECT
74 74
75public: 75public:
76 AbTable( const QValueList<int> ordered, QWidget *parent, const char *name=0 ); 76 AbTable( const QValueList<int> ordered, QWidget *parent, const char *name=0 );
77 ~AbTable(); 77 ~AbTable();
78 78
79 // Set the contacts shown in the table 79 // Set the contacts shown in the table
80 void setContacts( const OContactAccess::List& viewList ); 80 void setContacts( const OContactAccess::List& viewList );
81 // Selects a contact of a specific UID 81 // Selects a contact of a specific UID
82 bool selectContact( int UID ); 82 bool selectContact( int UID );
83 83
84 // Get the current selected entry 84 // Get the current selected entry
85 OContact currentEntry(); 85 OContact currentEntry();
86 86
87 // Get the UID of the current selected Entry 87 // Get the UID of the current selected Entry
88 int currentEntry_UID(); 88 int currentEntry_UID();
89 89
90 QString findContactName( const OContact &entry ); 90 QString findContactName( const OContact &entry );
91 91
92 void init(); 92 void init();
93 void clear(); 93 void clear();
94 void refresh(); 94 void refresh();
95 95
96 void show(); 96 void show();
97 void setPaintingEnabled( bool e ); 97 void setPaintingEnabled( bool e );
98 void viewportPaintEvent( QPaintEvent* e); 98 void viewportPaintEvent( QPaintEvent* e);
99 void paintCell(QPainter* p, int row, int col, const QRect&, bool );
99 100
100 // addresspicker mode (What's that ? se) 101 // addresspicker mode (What's that ? se)
101 void setChoiceNames( const QStringList& list); 102 void setChoiceNames( const QStringList& list);
102 QStringList choiceNames() const; 103 QStringList choiceNames() const;
103 void setChoiceSelection( const QValueList<int>& list ); 104 void setChoiceSelection( const QValueList<int>& list );
104 QStringList choiceSelection(int index) const; 105 QStringList choiceSelection(int index) const;
105 106
106signals: 107signals:
107 void signalSwitch(); 108 void signalSwitch();
108 void signalEditor(); 109 void signalEditor();
109 void signalKeyDown(); 110 void signalKeyDown();
110 void signalKeyUp(); 111 void signalKeyUp();
111 112
112protected: 113protected:
113 virtual void keyPressEvent( QKeyEvent *e ); 114 virtual void keyPressEvent( QKeyEvent *e );
114 115
115// int rowHeight( int ) const; 116// int rowHeight( int ) const;
116// int rowPos( int row ) const; 117// int rowPos( int row ) const;
117// virtual int rowAt( int pos ) const; 118// virtual int rowAt( int pos ) const;
118 119
119 120
120protected slots: 121protected slots:
121 void moveTo( char ); 122 void moveTo( char );
122 virtual void columnClicked( int col ); 123 virtual void columnClicked( int col );
123 void itemClicked(int,int col); 124 void itemClicked(int,int col);
124 void rowHeightChanged( int row ); 125 void rowHeightChanged( int row );
125 126
126private: 127private:
127 void insertIntoTable( const OContact &cnt, int row ); 128 void insertIntoTable( const OContact &cnt, int row );
128 ContactItem findContactContact( const OContact &entry, int row ); 129 ContactItem findContactContact( const OContact &entry, int row );
129 void fitColumns(); 130 void fitColumns();
130 void resizeRows(); 131 void resizeRows();
131 void realignTable(); 132 void realignTable();
132 void resort(); 133 void resort();
133 void updateVisible(); 134 void updateVisible();
134 135
135 int lastSortCol; 136 int lastSortCol;
136 bool asc; 137 bool asc;
137 QMap<AbTableItem*, OContact> contactList; 138 QMap<AbTableItem*, OContact> contactList;
138 QValueList<int> intFields; 139 QValueList<int> intFields;
139 QStringList choicenames; 140 QStringList choicenames;
140 bool enablePainting; 141 bool enablePainting;
141 bool columnVisible; 142 bool columnVisible;
142 int countNested; 143 int countNested;
143 144
144 OContactAccess::List m_viewList; 145 OContactAccess::List m_viewList;
145 146
146}; 147};
147#endif // ABTABLE_H 148#endif // ABTABLE_H