00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <qpixmap.h>
00033
00034
00035
00036 #include <opie2/odebug.h>
00037 #include <opie2/olistview.h>
00038
00039 using namespace Opie::Core;
00040
00041
00042 namespace Opie {
00043 namespace Ui {
00044
00045
00046
00047
00048 OListView::OListView( QWidget *parent, const char *name, WFlags fl )
00049 :QListView( parent, name, fl )
00050 {
00051
00052
00053 m_alternateBackground = QColor( 228, 236, 245 );
00054 m_columnSeparator = QPen( QColor( 50, 60, 70 ), 0, DotLine );
00055 m_fullWidth = true;
00056 connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*)));
00057 }
00058
00059 OListView::~OListView()
00060 {
00061 }
00062
00063 void OListView::setFullWidth( bool fullWidth )
00064 {
00065 m_fullWidth = fullWidth;
00066 #if QT_VERSION >= 0x030000
00067 header()->setStretchEnabled( fullWidth, columns()-1 );
00068 #endif
00069 }
00070
00071 bool OListView::fullWidth() const
00072 {
00073 return m_fullWidth;
00074 }
00075
00076 int OListView::addColumn( const QString& label, int width )
00077 {
00078 int result = QListView::addColumn( label, width );
00079 #if QT_VERSION >= 0x030000
00080 if (m_fullWidth) {
00081 header()->setStretchEnabled( false, columns()-2 );
00082 header()->setStretchEnabled( true, columns()-1 );
00083 }
00084 #endif
00085 return result;
00086 }
00087
00088 int OListView::addColumn( const QIconSet& iconset, const QString& label, int width )
00089 {
00090 int result = QListView::addColumn( iconset, label, width );
00091 #if QT_VERSION >= 0x030000
00092 if (m_fullWidth) {
00093 header()->setStretchEnabled( false, columns()-2 );
00094 header()->setStretchEnabled( true, columns()-1 );
00095 }
00096 #endif
00097 return result;
00098 }
00099
00100 void OListView::removeColumn( int index )
00101 {
00102 QListView::removeColumn(index);
00103 #if QT_VERSION >= 0x030000
00104 if ( m_fullWidth && index == columns() )
00105 {
00106 header()->setStretchEnabled( true, columns()-1 );
00107 }
00108 #endif
00109 }
00110
00111 const QColor& OListView::alternateBackground() const
00112 {
00113 return m_alternateBackground;
00114 }
00115
00116 void OListView::setAlternateBackground( const QColor &c )
00117 {
00118 m_alternateBackground = c;
00119 repaint();
00120 }
00121
00122 const QPen& OListView::columnSeparator() const
00123 {
00124 return m_columnSeparator;
00125 }
00126
00127 void OListView::setColumnSeparator( const QPen& p )
00128 {
00129 m_columnSeparator = p;
00130 repaint();
00131 }
00132
00133 void OListView::expand(QListViewItem *item)
00134 {
00135 ((OListViewItem*)item)->expand();
00136 }
00137
00138 OListViewItem* OListView::childFactory()
00139 {
00140 return new OListViewItem( this );
00141 }
00142
00143 #ifndef QT_NO_DATASTREAM
00144 void OListView::serializeTo( QDataStream& s ) const
00145 {
00146 #warning Caution... the binary format is still under construction...
00147 odebug << "storing OListView..." << oendl;
00148
00149
00150 s << columns();
00151 for ( int i = 0; i < columns(); ++i )
00152 s << columnText( i );
00153
00154
00155 int items = 0;
00156 QListViewItem* item = firstChild();
00157 while ( item )
00158 {
00159 item = item->nextSibling();
00160 items++;
00161 }
00162
00163
00164 s << items;
00165 item = firstChild();
00166 for ( int i = 0; i < items; ++i )
00167 {
00168 s << *static_cast<OListViewItem*>( item );
00169 item = item->nextSibling();
00170 }
00171
00172 odebug << "OListview stored." << oendl;
00173 }
00174
00175 void OListView::serializeFrom( QDataStream& s )
00176 {
00177 #warning Caution... the binary format is still under construction...
00178 odebug << "loading OListView..." << oendl;
00179
00180 int cols;
00181 s >> cols;
00182 odebug << "read number of columns = " << cols << oendl;
00183
00184 while ( columns() < cols ) addColumn( QString::null );
00185
00186 for ( int i = 0; i < cols; ++i )
00187 {
00188 QString coltext;
00189 s >> coltext;
00190 odebug << "read text '" << coltext << "' for column " << i << "" << oendl;
00191 setColumnText( i, coltext );
00192 }
00193
00194 int items;
00195 s >> items;
00196 odebug << "read number of items = " << items << oendl;
00197
00198 for ( int i = 0; i < items; ++i )
00199 {
00200 OListViewItem* item = childFactory();
00201 s >> *item;
00202 }
00203
00204 odebug << "OListView loaded." << oendl;
00205
00206 }
00207
00208
00209 void OListView::expand()
00210 {
00211 odebug << "OListView::expand" << oendl;
00212
00213 QListViewItemIterator it( this );
00214 while ( it.current() ) {
00215 it.current()->setOpen( true );
00216 ++it;
00217 }
00218 }
00219
00220
00221 void OListView::collapse()
00222 {
00223 odebug << "OListView::collapse" << oendl;
00224 QListViewItemIterator it( this );
00225 while ( it.current() ) {
00226 it.current()->setOpen( false );
00227 ++it;
00228 }
00229 }
00230
00231
00232 QDataStream& operator<<( QDataStream& s, const OListView& lv )
00233 {
00234 lv.serializeTo( s );
00235 return s;
00236 }
00237
00238 QDataStream& operator>>( QDataStream& s, OListView& lv )
00239 {
00240 lv.serializeFrom( s );
00241 return s;
00242 }
00243 #endif // QT_NO_DATASTREAM
00244
00245
00246
00247
00248
00249 OListViewItem::OListViewItem(QListView *parent)
00250 : QListViewItem(parent)
00251 {
00252 init();
00253 }
00254
00255
00256 OListViewItem::OListViewItem(QListViewItem *parent)
00257 : QListViewItem(parent)
00258 {
00259 init();
00260 }
00261
00262
00263 OListViewItem::OListViewItem(QListView *parent, QListViewItem *after)
00264 : QListViewItem(parent, after)
00265 {
00266 init();
00267 }
00268
00269
00270 OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after)
00271 : QListViewItem(parent, after)
00272 {
00273 init();
00274 }
00275
00276
00277 OListViewItem::OListViewItem(QListView *parent,
00278 QString label1, QString label2, QString label3, QString label4,
00279 QString label5, QString label6, QString label7, QString label8)
00280 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
00281 {
00282 init();
00283 }
00284
00285
00286 OListViewItem::OListViewItem(QListViewItem *parent,
00287 QString label1, QString label2, QString label3, QString label4,
00288 QString label5, QString label6, QString label7, QString label8)
00289 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
00290 {
00291 init();
00292 }
00293
00294
00295 OListViewItem::OListViewItem(QListView *parent, QListViewItem *after,
00296 QString label1, QString label2, QString label3, QString label4,
00297 QString label5, QString label6, QString label7, QString label8)
00298 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
00299 {
00300 init();
00301 }
00302
00303
00304 OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after,
00305 QString label1, QString label2, QString label3, QString label4,
00306 QString label5, QString label6, QString label7, QString label8)
00307 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
00308 {
00309 init();
00310 }
00311
00312
00313 OListViewItem::~OListViewItem()
00314 {
00315 }
00316
00317
00318 void OListViewItem::init()
00319 {
00320 m_known = false;
00321 }
00322
00323
00324 const QColor &OListViewItem::backgroundColor()
00325 {
00326 return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() :
00327 listView()->viewport()->colorGroup().base();
00328 }
00329
00330
00331 bool OListViewItem::isAlternate()
00332 {
00333 OListView *lv = static_cast<OListView*>( listView() );
00334
00335
00336 OListViewItem *above = static_cast<OListViewItem*>( itemAbove() );
00337
00338
00339
00340 if (!(lv && lv->alternateBackground().isValid())) return false;
00341
00342 m_known = above ? above->m_known : true;
00343 if (m_known)
00344 {
00345 m_odd = above ? !above->m_odd : false;
00346 }
00347 else
00348 {
00349 OListViewItem *item;
00350 bool previous = true;
00351 if (parent())
00352 {
00353 item = static_cast<OListViewItem *>(parent());
00354 if ( item ) previous = item->m_odd;
00355 item = static_cast<OListViewItem *>(parent()->firstChild());
00356
00357 }
00358 else
00359 {
00360 item = static_cast<OListViewItem *>(lv->firstChild());
00361 }
00362
00363 while(item)
00364 {
00365 item->m_odd = previous = !previous;
00366 item->m_known = true;
00367 item = static_cast<OListViewItem *>(item->nextSibling());
00368
00369 }
00370 }
00371 return m_odd;
00372 }
00373
00374
00375 void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
00376 {
00377 QColorGroup _cg = cg;
00378 const QPixmap *pm = listView()->viewport()->backgroundPixmap();
00379 if (pm && !pm->isNull())
00380 {
00381 _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) );
00382 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
00383 }
00384 else if ( isAlternate() )
00385 {
00386 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
00387 }
00388 QListViewItem::paintCell( p, _cg, column, width, alignment );
00389
00390
00391
00392 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
00393 p->setPen( pen );
00394 p->drawLine( width-1, 0, width-1, height() );
00395 }
00396
00397
00398 OListViewItem* OListViewItem::childFactory()
00399 {
00400 return new OListViewItem( this );
00401 }
00402
00403
00404 #ifndef QT_NO_DATASTREAM
00405 void OListViewItem::serializeTo( QDataStream& s ) const
00406 {
00407 #warning Caution... the binary format is still under construction...
00408 odebug << "storing OListViewItem..." << oendl;
00409
00410
00411 for ( int i = 0; i < listView()->columns(); ++i )
00412 {
00413 s << text( i );
00414 }
00415
00416
00417 int items = 0;
00418 QListViewItem* item = firstChild();
00419 while ( item )
00420 {
00421 item = item->nextSibling();
00422 items++;
00423 }
00424
00425
00426 s << items;
00427 item = firstChild();
00428 for ( int i = 0; i < items; ++i )
00429 {
00430 s << *static_cast<OListViewItem*>( item );
00431 item = item->nextSibling();
00432 }
00433
00434 odebug << "OListviewItem stored." << oendl;
00435 }
00436
00437
00438 void OListViewItem::serializeFrom( QDataStream& s )
00439 {
00440 #warning Caution... the binary format is still under construction...
00441 odebug << "loading OListViewItem..." << oendl;
00442
00443 for ( int i = 0; i < listView()->columns(); ++i )
00444 {
00445 QString coltext;
00446 s >> coltext;
00447 odebug << "read text '" << coltext << "' for column " << i << "" << oendl;
00448 setText( i, coltext );
00449 }
00450
00451 int items;
00452 s >> items;
00453 odebug << "read number of items = " << items << "" << oendl;
00454
00455 for ( int i = 0; i < items; ++i )
00456 {
00457 OListViewItem* item = childFactory();
00458 s >> (*item);
00459 }
00460
00461 odebug << "OListViewItem loaded." << oendl;
00462 }
00463
00464
00465 QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi )
00466 {
00467 lvi.serializeTo( s );
00468 return s;
00469 }
00470
00471
00472 QDataStream& operator>>( QDataStream& s, OListViewItem& lvi )
00473 {
00474 lvi.serializeFrom( s );
00475 return s;
00476 }
00477 #endif // QT_NO_DATASTREAM
00478
00479
00480
00481
00482
00483
00484 OCheckListItem::OCheckListItem( QCheckListItem* parent, const QString& text, Type t )
00485 :QCheckListItem( parent, text, t )
00486 {
00487 init();
00488 }
00489
00490
00491 OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, Type t)
00492 :QCheckListItem( parent, text, t )
00493 {
00494 init();
00495 }
00496
00497
00498 OCheckListItem::OCheckListItem( QListView* parent, const QString& text, Type t )
00499 :QCheckListItem( parent, text, t )
00500 {
00501 init();
00502 }
00503
00504
00505 OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, const QPixmap& p )
00506 :QCheckListItem( parent, text, p )
00507 {
00508 init();
00509 }
00510
00511
00512 OCheckListItem::OCheckListItem( QListView* parent, const QString& text, const QPixmap& p )
00513 :QCheckListItem( parent, text, p )
00514 {
00515 init();
00516 }
00517
00518
00519 OCheckListItem::~OCheckListItem()
00520 {
00521 }
00522
00523 void OCheckListItem::init()
00524 {
00525 m_known = false;
00526 }
00527
00528
00529 const QColor &OCheckListItem::backgroundColor()
00530 {
00531 return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() :
00532 listView()->viewport()->colorGroup().base();
00533 }
00534
00535
00536 bool OCheckListItem::isAlternate()
00537 {
00538 OListView *lv = static_cast<OListView*>( listView() );
00539
00540
00541 OCheckListItem *above = static_cast<OCheckListItem*>( itemAbove() );
00542
00543
00544
00545 if (!(lv && lv->alternateBackground().isValid())) return false;
00546
00547 m_known = above ? above->m_known : true;
00548 if (m_known)
00549 {
00550 m_odd = above ? !above->m_odd : false;
00551 }
00552 else
00553 {
00554 OCheckListItem *item;
00555 bool previous = true;
00556 if (parent())
00557 {
00558 item = static_cast<OCheckListItem *>(parent());
00559 if ( item ) previous = item->m_odd;
00560 item = static_cast<OCheckListItem *>(parent()->firstChild());
00561
00562 }
00563 else
00564 {
00565 item = static_cast<OCheckListItem *>(lv->firstChild());
00566 }
00567
00568 while(item)
00569 {
00570 item->m_odd = previous = !previous;
00571 item->m_known = true;
00572 item = static_cast<OCheckListItem *>(item->nextSibling());
00573
00574 }
00575 }
00576 return m_odd;
00577 }
00578
00579
00580 void OCheckListItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
00581 {
00582 QColorGroup _cg = cg;
00583 const QPixmap *pm = listView()->viewport()->backgroundPixmap();
00584 if (pm && !pm->isNull())
00585 {
00586 _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) );
00587 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
00588 }
00589 else if ( isAlternate() )
00590 {
00591 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
00592 }
00593 QCheckListItem::paintCell( p, _cg, column, width, alignment );
00594
00595
00596
00597 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
00598 p->setPen( pen );
00599 p->drawLine( width-1, 0, width-1, height() );
00600 }
00601
00602
00603
00604
00605
00606
00607 ONamedListView::ONamedListView( QWidget *parent, const char *name )
00608 :OListView( parent, name )
00609 {
00610 }
00611
00612
00613 ONamedListView::~ONamedListView()
00614 {
00615 }
00616
00617
00618 void ONamedListView::addColumns( const QStringList& columns )
00619 {
00620 for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it )
00621 {
00622 odebug << "adding column " << *it << "" << oendl;
00623 addColumn( *it );
00624 }
00625 }
00626
00627
00628 int ONamedListView::findColumn( const QString& text ) const
00629 {
00630
00631
00632
00633 for ( int i = 0; i < columns(); ++i )
00634 if ( columnText( i ) == text )
00635 return i;
00636 return -1;
00637 }
00638
00639
00640 ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const
00641 {
00642 return find( (ONamedListViewItem*) firstChild(), column, text, recurse );
00643 }
00644
00645
00646 ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const
00647 {
00648 ONamedListViewItem* result;
00649 while ( item && item->text( column ) != text )
00650 {
00651 odebug << "checked " << item->text( column ) << "" << oendl;
00652
00653 if ( recurse < 0 || recurse > 0 )
00654 {
00655 odebug << "recursion is " << recurse << " - recursing into..." << oendl;
00656 result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 );
00657 if ( result ) return result;
00658 }
00659
00660
00661 item = (ONamedListViewItem*) item->itemBelow();
00662 }
00663 if ( item && item->text( column ) == text )
00664 return item;
00665 else
00666 return 0;
00667 }
00668
00669
00670 ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const
00671 {
00672 int col = findColumn( column );
00673 if ( col != -1 )
00674 return find( (ONamedListViewItem*) firstChild(), col, text, recurse );
00675 else
00676 return 0;
00677 }
00678
00679
00680 ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const
00681 {
00682 int col = findColumn( column );
00683 if ( col != -1 )
00684 return find( item, col, text, recurse );
00685 else
00686 return 0;
00687 }
00688
00689
00690
00691
00692
00693
00694 ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts )
00695 :OListViewItem( parent )
00696 {
00697 setText( texts );
00698 }
00699
00700
00701 ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts )
00702 :OListViewItem( parent )
00703 {
00704 setText( texts );
00705 }
00706
00707
00708 ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts )
00709 :OListViewItem( parent, after )
00710 {
00711 setText( texts );
00712 }
00713
00714
00715 ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts )
00716 :OListViewItem( parent, after )
00717 {
00718 setText( texts );
00719 }
00720
00721
00722 ONamedListViewItem::~ONamedListViewItem()
00723 {
00724 }
00725
00726
00727 void ONamedListViewItem::setText( const QStringList& texts )
00728 {
00729 int col = 0;
00730 for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it )
00731 {
00732 odebug << "setting column " << col << " = text " << *it << "" << oendl;
00733 OListViewItem::setText( col++, *it );
00734 }
00735
00736 }
00737
00738
00739 void ONamedListViewItem::setText( const QString& column, const QString& text )
00740 {
00741
00742
00743
00744 int col = ( (ONamedListView*) listView() )->findColumn( column );
00745 if ( col != -1 )
00746 OListViewItem::setText( col, text );
00747 else
00748 owarn << "ONamedListViewItem::setText(): Warning! Columntext '" << column << "' not found." << oendl;
00749 }
00750
00751
00752 ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const
00753 {
00754 return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse );
00755 }
00756
00757
00758 ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const
00759 {
00760 int col = ( (ONamedListView*) listView() )->findColumn( column );
00761 if ( col != -1 )
00762 return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse );
00763 else
00764 return 0;
00765 }
00766
00767 }
00768 }