Diffstat (limited to 'core/pim/addressbook/abtable.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/addressbook/abtable.cpp | 55 |
1 files changed, 44 insertions, 11 deletions
diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp index e333b17..00335ae 100644 --- a/core/pim/addressbook/abtable.cpp +++ b/core/pim/addressbook/abtable.cpp | |||
@@ -114,25 +114,26 @@ void AbPickItem::setContentFromEditor( QWidget *w ) | |||
114 | /*! | 114 | /*! |
115 | \class AbTable abtable.h | 115 | \class AbTable abtable.h |
116 | 116 | ||
117 | \brief QTable based class for showing a list of entries | 117 | \brief QTable based class for showing a list of entries |
118 | */ | 118 | */ |
119 | 119 | ||
120 | AbTable::AbTable( const QValueList<int> order, QWidget *parent, const char *name ) | 120 | AbTable::AbTable( const QValueList<int> order, QWidget *parent, const char *name ) |
121 | : QTable( parent, name ), | 121 | : QTable( parent, name ), |
122 | lastSortCol( -1 ), | 122 | lastSortCol( -1 ), |
123 | asc( TRUE ), | 123 | asc( TRUE ), |
124 | intFields( order ), | 124 | intFields( order ), |
125 | enablePainting( true ), | 125 | enablePainting( true ), |
126 | columnVisible( true ) | 126 | columnVisible( true ), |
127 | countNested( 0 ) | ||
127 | { | 128 | { |
128 | qWarning("C'tor start"); | 129 | qWarning("C'tor start"); |
129 | 130 | ||
130 | setSelectionMode( NoSelection ); | 131 | setSelectionMode( NoSelection ); |
131 | init(); | 132 | init(); |
132 | setSorting( TRUE ); | 133 | setSorting( TRUE ); |
133 | connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), | 134 | connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), |
134 | this, SLOT(itemClicked(int,int)) ); | 135 | this, SLOT(itemClicked(int,int)) ); |
135 | 136 | ||
136 | contactList.clear(); | 137 | contactList.clear(); |
137 | qWarning("C'tor end"); | 138 | qWarning("C'tor end"); |
138 | } | 139 | } |
@@ -153,72 +154,75 @@ void AbTable::init() | |||
153 | verticalHeader()->hide(); | 154 | verticalHeader()->hide(); |
154 | columnVisible = true; | 155 | columnVisible = true; |
155 | } | 156 | } |
156 | 157 | ||
157 | void AbTable::setContacts( const OContactAccess::List& viewList ) | 158 | void AbTable::setContacts( const OContactAccess::List& viewList ) |
158 | { | 159 | { |
159 | qWarning("AbTable::setContacts()"); | 160 | qWarning("AbTable::setContacts()"); |
160 | 161 | ||
161 | clear(); | 162 | clear(); |
162 | m_viewList = viewList; | 163 | m_viewList = viewList; |
163 | 164 | ||
164 | setSorting( false ); | 165 | setSorting( false ); |
165 | setUpdatesEnabled( FALSE ); | 166 | setPaintingEnabled( FALSE ); |
166 | 167 | ||
167 | OContactAccess::List::Iterator it; | 168 | OContactAccess::List::Iterator it; |
168 | setNumRows( m_viewList.count() ); | 169 | setNumRows( m_viewList.count() ); |
169 | int row = 0; | 170 | int row = 0; |
170 | for ( it = m_viewList.begin(); it != m_viewList.end(); ++it ) | 171 | for ( it = m_viewList.begin(); it != m_viewList.end(); ++it ) |
171 | insertIntoTable( *it, row++ ); | 172 | insertIntoTable( *it, row++ ); |
172 | 173 | ||
173 | setUpdatesEnabled( TRUE ); | ||
174 | |||
175 | setSorting( true ); | 174 | setSorting( true ); |
176 | 175 | ||
177 | resort(); | 176 | resort(); |
178 | 177 | ||
179 | updateVisible(); | 178 | updateVisible(); |
180 | 179 | ||
180 | setPaintingEnabled( TRUE ); | ||
181 | |||
181 | } | 182 | } |
182 | 183 | ||
183 | bool AbTable::selectContact( int UID ) | 184 | bool AbTable::selectContact( int UID ) |
184 | { | 185 | { |
185 | qWarning( "AbTable::selectContact( %d )", UID ); | 186 | qWarning( "AbTable::selectContact( %d )", UID ); |
186 | int rows = numRows(); | 187 | int rows = numRows(); |
187 | AbTableItem *abi; | 188 | AbTableItem *abi; |
188 | OContact* foundContact = 0l; | 189 | OContact* foundContact = 0l; |
189 | bool found = false; | 190 | bool found = false; |
190 | 191 | ||
192 | setPaintingEnabled( FALSE ); | ||
191 | for ( int r = 0; r < rows; ++r ) { | 193 | for ( int r = 0; r < rows; ++r ) { |
192 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 194 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
193 | foundContact = &contactList[abi]; | 195 | foundContact = &contactList[abi]; |
194 | if ( foundContact -> uid() == UID ){ | 196 | if ( foundContact -> uid() == UID ){ |
195 | ensureCellVisible( r, 0 ); | 197 | ensureCellVisible( r, 0 ); |
196 | setCurrentCell( r, 0 ); | 198 | setCurrentCell( r, 0 ); |
197 | found = true; | 199 | found = true; |
198 | break; | 200 | break; |
199 | } | 201 | } |
200 | } | 202 | } |
201 | 203 | ||
202 | if ( !found ){ | 204 | if ( !found ){ |
203 | ensureCellVisible( 0,0 ); | 205 | ensureCellVisible( 0,0 ); |
204 | setCurrentCell( 0, 0 ); | 206 | setCurrentCell( 0, 0 ); |
205 | } | 207 | } |
206 | 208 | ||
209 | setPaintingEnabled( TRUE ); | ||
210 | |||
207 | return true; | 211 | return true; |
208 | } | 212 | } |
209 | 213 | ||
210 | void AbTable::insertIntoTable( const OContact& cnt, int row ) | 214 | void AbTable::insertIntoTable( const OContact& cnt, int row ) |
211 | { | 215 | { |
212 | // qWarning( "void AbTable::insertIntoTable( const OContact& cnt, %d )", row ); | 216 | qWarning( "void AbTable::insertIntoTable( const OContact& cnt, %d )", row ); |
213 | QString strName, | 217 | QString strName, |
214 | strContact; | 218 | strContact; |
215 | 219 | ||
216 | strName = findContactName( cnt ); | 220 | strName = findContactName( cnt ); |
217 | strContact = findContactContact( cnt, row ); | 221 | strContact = findContactContact( cnt, row ); |
218 | 222 | ||
219 | AbTableItem *ati; | 223 | AbTableItem *ati; |
220 | ati = new AbTableItem( this, QTableItem::Never, strName, strContact); | 224 | ati = new AbTableItem( this, QTableItem::Never, strName, strContact); |
221 | contactList.insert( ati, cnt ); | 225 | contactList.insert( ati, cnt ); |
222 | setItem( row, 0, ati ); | 226 | setItem( row, 0, ati ); |
223 | ati = new AbTableItem( this, QTableItem::Never, strContact, strName); | 227 | ati = new AbTableItem( this, QTableItem::Never, strContact, strName); |
224 | setItem( row, 1, ati ); | 228 | setItem( row, 1, ati ); |
@@ -242,79 +246,86 @@ void AbTable::columnClicked( int col ) | |||
242 | asc = !asc; | 246 | asc = !asc; |
243 | } else { | 247 | } else { |
244 | lastSortCol = col; | 248 | lastSortCol = col; |
245 | asc = TRUE; | 249 | asc = TRUE; |
246 | } | 250 | } |
247 | //QMessageBox::information( this, "resort", "columnClicked" ); | 251 | //QMessageBox::information( this, "resort", "columnClicked" ); |
248 | resort(); | 252 | resort(); |
249 | } | 253 | } |
250 | 254 | ||
251 | void AbTable::resort() | 255 | void AbTable::resort() |
252 | { | 256 | { |
253 | qWarning( "void AbTable::resort()" ); | 257 | qWarning( "void AbTable::resort()" ); |
258 | setPaintingEnabled( FALSE ); | ||
254 | if ( sorting() ) { | 259 | if ( sorting() ) { |
255 | if ( lastSortCol == -1 ) | 260 | if ( lastSortCol == -1 ) |
256 | lastSortCol = 0; | 261 | lastSortCol = 0; |
257 | sortColumn( lastSortCol, asc, TRUE ); | 262 | sortColumn( lastSortCol, asc, TRUE ); |
258 | //QMessageBox::information( this, "resort", "resort" ); | 263 | //QMessageBox::information( this, "resort", "resort" ); |
259 | updateVisible(); | 264 | updateVisible(); |
260 | } | 265 | } |
266 | setPaintingEnabled( TRUE ); | ||
261 | } | 267 | } |
262 | 268 | ||
263 | OContact AbTable::currentEntry() | 269 | OContact AbTable::currentEntry() |
264 | { | 270 | { |
265 | qWarning( "OContact AbTable::currentEntry()" ); | 271 | qWarning( "OContact AbTable::currentEntry()" ); |
266 | OContact cnt; | 272 | OContact cnt; |
267 | AbTableItem *abItem; | 273 | AbTableItem *abItem; |
268 | abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); | 274 | abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); |
269 | if ( abItem ) { | 275 | if ( abItem ) { |
270 | cnt = contactList[abItem]; | 276 | cnt = contactList[abItem]; |
271 | //cnt = contactList[currentRow()]; | 277 | //cnt = contactList[currentRow()]; |
272 | } | 278 | } |
273 | return cnt; | 279 | return cnt; |
274 | } | 280 | } |
275 | 281 | ||
276 | int AbTable::currentEntry_UID() | 282 | int AbTable::currentEntry_UID() |
277 | { | 283 | { |
278 | return ( currentEntry().uid() ); | 284 | return ( currentEntry().uid() ); |
279 | } | 285 | } |
280 | 286 | ||
281 | void AbTable::clear() | 287 | void AbTable::clear() |
282 | { | 288 | { |
283 | qWarning( "void AbTable::clear()" ); | 289 | qWarning( "void AbTable::clear()" ); |
284 | contactList.clear(); | 290 | contactList.clear(); |
291 | |||
292 | setPaintingEnabled( FALSE ); | ||
285 | for ( int r = 0; r < numRows(); ++r ) { | 293 | for ( int r = 0; r < numRows(); ++r ) { |
286 | for ( int c = 0; c < numCols(); ++c ) { | 294 | for ( int c = 0; c < numCols(); ++c ) { |
287 | if ( cellWidget( r, c ) ) | 295 | if ( cellWidget( r, c ) ) |
288 | clearCellWidget( r, c ); | 296 | clearCellWidget( r, c ); |
289 | clearCell( r, c ); | 297 | clearCell( r, c ); |
290 | } | 298 | } |
291 | } | 299 | } |
292 | setNumRows( 0 ); | 300 | setNumRows( 0 ); |
301 | setPaintingEnabled( TRUE ); | ||
293 | } | 302 | } |
294 | 303 | ||
295 | // Refresh updates column 2 if the contactsettings changed | 304 | // Refresh updates column 2 if the contactsettings changed |
296 | void AbTable::refresh() | 305 | void AbTable::refresh() |
297 | { | 306 | { |
298 | qWarning( "void AbTable::refresh()" ); | 307 | qWarning( "void AbTable::refresh()" ); |
299 | int rows = numRows(); | 308 | int rows = numRows(); |
300 | QString value; | 309 | QString value; |
301 | AbTableItem *abi; | 310 | AbTableItem *abi; |
302 | 311 | ||
312 | setPaintingEnabled( FALSE ); | ||
303 | for ( int r = 0; r < rows; ++r ) { | 313 | for ( int r = 0; r < rows; ++r ) { |
304 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 314 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
305 | value = findContactContact( contactList[abi], r ); | 315 | value = findContactContact( contactList[abi], r ); |
306 | static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() ); | 316 | static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() ); |
307 | } | 317 | } |
308 | resort(); | 318 | resort(); |
319 | setPaintingEnabled( TRUE ); | ||
309 | } | 320 | } |
310 | 321 | ||
311 | void AbTable::keyPressEvent( QKeyEvent *e ) | 322 | void AbTable::keyPressEvent( QKeyEvent *e ) |
312 | { | 323 | { |
313 | char key = toupper( e->ascii() ); | 324 | char key = toupper( e->ascii() ); |
314 | 325 | ||
315 | if ( key >= 'A' && key <= 'Z' ) | 326 | if ( key >= 'A' && key <= 'Z' ) |
316 | moveTo( key ); | 327 | moveTo( key ); |
317 | 328 | ||
318 | qWarning("Received key .."); | 329 | qWarning("Received key .."); |
319 | switch( e->key() ) { | 330 | switch( e->key() ) { |
320 | case Qt::Key_Space: | 331 | case Qt::Key_Space: |
@@ -445,36 +456,40 @@ void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) | |||
445 | // { | 456 | // { |
446 | // return QMIN( pos/18, numRows()-1 ); | 457 | // return QMIN( pos/18, numRows()-1 ); |
447 | // } | 458 | // } |
448 | 459 | ||
449 | 460 | ||
450 | 461 | ||
451 | void AbTable::fitColumns() | 462 | void AbTable::fitColumns() |
452 | { | 463 | { |
453 | qWarning( "void AbTable::fitColumns()" ); | 464 | qWarning( "void AbTable::fitColumns()" ); |
454 | int contentsWidth = visibleWidth() / 2; // :SX Why too low | 465 | int contentsWidth = visibleWidth() / 2; // :SX Why too low |
455 | // Fix to better value | 466 | // Fix to better value |
456 | // contentsWidth = 130; | 467 | // contentsWidth = 130; |
468 | |||
469 | setPaintingEnabled( FALSE ); | ||
457 | 470 | ||
458 | if ( columnVisible == false ){ | 471 | if ( columnVisible == false ){ |
459 | showColumn(0); | 472 | showColumn(0); |
460 | columnVisible = true; | 473 | columnVisible = true; |
461 | } | 474 | } |
462 | 475 | ||
463 | qWarning("Width: %d", contentsWidth); | 476 | qWarning("Width: %d", contentsWidth); |
464 | 477 | ||
465 | setColumnWidth( 0, contentsWidth ); | 478 | setColumnWidth( 0, contentsWidth ); |
466 | adjustColumn(1); | 479 | adjustColumn(1); |
467 | if ( columnWidth(1) < contentsWidth ) | 480 | if ( columnWidth(1) < contentsWidth ) |
468 | setColumnWidth( 1, contentsWidth ); | 481 | setColumnWidth( 1, contentsWidth ); |
482 | |||
483 | setPaintingEnabled( TRUE ); | ||
469 | } | 484 | } |
470 | 485 | ||
471 | void AbTable::show() | 486 | void AbTable::show() |
472 | { | 487 | { |
473 | qWarning( "void AbTable::show()" ); | 488 | qWarning( "void AbTable::show()" ); |
474 | realignTable(); | 489 | realignTable(); |
475 | QTable::show(); | 490 | QTable::show(); |
476 | } | 491 | } |
477 | 492 | ||
478 | void AbTable::setChoiceNames( const QStringList& list) | 493 | void AbTable::setChoiceNames( const QStringList& list) |
479 | { | 494 | { |
480 | choicenames = list; | 495 | choicenames = list; |
@@ -524,35 +539,37 @@ QStringList AbTable::choiceSelection(int /*index*/) const | |||
524 | } | 539 | } |
525 | } | 540 | } |
526 | 541 | ||
527 | */ | 542 | */ |
528 | return r; | 543 | return r; |
529 | } | 544 | } |
530 | 545 | ||
531 | 546 | ||
532 | 547 | ||
533 | 548 | ||
534 | void AbTable::updateVisible() | 549 | void AbTable::updateVisible() |
535 | { | 550 | { |
551 | qWarning("void AbTable::updateVisible()"); | ||
552 | |||
536 | int visible, | 553 | int visible, |
537 | totalRows, | 554 | totalRows, |
538 | row, | 555 | row, |
539 | selectedRow = 0; | 556 | selectedRow = 0; |
540 | 557 | ||
541 | visible = 0; | 558 | visible = 0; |
542 | 559 | ||
543 | realignTable(); | ||
544 | |||
545 | setPaintingEnabled( FALSE ); | 560 | setPaintingEnabled( FALSE ); |
546 | 561 | ||
562 | realignTable(); | ||
563 | |||
547 | totalRows = numRows(); | 564 | totalRows = numRows(); |
548 | for ( row = 0; row < totalRows; row++ ) { | 565 | for ( row = 0; row < totalRows; row++ ) { |
549 | if ( rowHeight(row) == 0 ) { | 566 | if ( rowHeight(row) == 0 ) { |
550 | showRow( row ); | 567 | showRow( row ); |
551 | adjustRow( row ); | 568 | adjustRow( row ); |
552 | if ( isSelected( row,0 ) || isSelected( row,1 ) ) | 569 | if ( isSelected( row,0 ) || isSelected( row,1 ) ) |
553 | selectedRow = row; | 570 | selectedRow = row; |
554 | } | 571 | } |
555 | visible++; | 572 | visible++; |
556 | } | 573 | } |
557 | 574 | ||
558 | if ( selectedRow ) | 575 | if ( selectedRow ) |
@@ -560,35 +577,51 @@ void AbTable::updateVisible() | |||
560 | 577 | ||
561 | if ( !visible ) | 578 | if ( !visible ) |
562 | setCurrentCell( -1, 0 ); | 579 | setCurrentCell( -1, 0 ); |
563 | 580 | ||
564 | setPaintingEnabled( TRUE ); | 581 | setPaintingEnabled( TRUE ); |
565 | 582 | ||
566 | 583 | ||
567 | } | 584 | } |
568 | 585 | ||
569 | 586 | ||
570 | void AbTable::setPaintingEnabled( bool e ) | 587 | void AbTable::setPaintingEnabled( bool e ) |
571 | { | 588 | { |
572 | if ( e != enablePainting ) { | 589 | qWarning("IN void AbTable::setPaintingEnabled( %d )->Nested: %d", e, countNested ); |
573 | if ( !enablePainting ) { | 590 | |
591 | if ( e ) { | ||
592 | if ( countNested > 0 ) | ||
593 | --countNested; | ||
594 | if ( ! countNested ){ | ||
595 | setUpdatesEnabled( true ); | ||
574 | enablePainting = true; | 596 | enablePainting = true; |
575 | rowHeightChanged( 0 ); | 597 | rowHeightChanged( 0 ); |
576 | viewport()->update(); | 598 | viewport()->update(); |
577 | } else { | ||
578 | enablePainting = false; | ||
579 | } | 599 | } |
600 | } else { | ||
601 | ++countNested; | ||
602 | enablePainting = false; | ||
603 | setUpdatesEnabled( false ); | ||
580 | } | 604 | } |
605 | qWarning("OUT void AbTable::setPaintingEnabled( %d )->Nested: %d", e, countNested ); | ||
581 | } | 606 | } |
582 | 607 | ||
608 | void AbTable::viewportPaintEvent( QPaintEvent* e ) { | ||
609 | qWarning(" void AbTable::viewportPaintEvent( QPaintEvent* e ) -> %d", enablePainting); | ||
610 | if ( enablePainting ) | ||
611 | QTable::viewportPaintEvent( e ); | ||
612 | } | ||
613 | |||
614 | |||
615 | |||
583 | void AbTable::rowHeightChanged( int row ) | 616 | void AbTable::rowHeightChanged( int row ) |
584 | { | 617 | { |
585 | if ( enablePainting ) | 618 | if ( enablePainting ) |
586 | QTable::rowHeightChanged( row ); | 619 | QTable::rowHeightChanged( row ); |
587 | } | 620 | } |
588 | QString AbTable::findContactContact( const OContact &entry, int /* row */ ) | 621 | QString AbTable::findContactContact( const OContact &entry, int /* row */ ) |
589 | { | 622 | { |
590 | QString value; | 623 | QString value; |
591 | value = ""; | 624 | value = ""; |
592 | for ( QValueList<int>::ConstIterator it = intFields.begin(); | 625 | for ( QValueList<int>::ConstIterator it = intFields.begin(); |
593 | it != intFields.end(); ++it ) { | 626 | it != intFields.end(); ++it ) { |
594 | switch ( *it ) { | 627 | switch ( *it ) { |