summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-03-05 21:36:58 (UTC)
committer mickeyl <mickeyl>2004-03-05 21:36:58 (UTC)
commitb9d58b616102970872129b5bc2f55569910f5c03 (patch) (unidiff)
tree593b40cce6f3da75593c90bff337b9b9c5092f7e
parent4a18103940564be8585af8121203561e16f0a32c (diff)
downloadopie-b9d58b616102970872129b5bc2f55569910f5c03.zip
opie-b9d58b616102970872129b5bc2f55569910f5c03.tar.gz
opie-b9d58b616102970872129b5bc2f55569910f5c03.tar.bz2
add OCheckListItem
change my email address
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/olistview.cpp153
-rw-r--r--libopie2/opieui/olistview.h71
2 files changed, 213 insertions, 11 deletions
diff --git a/libopie2/opieui/olistview.cpp b/libopie2/opieui/olistview.cpp
index 84617f8..0ee2fde 100644
--- a/libopie2/opieui/olistview.cpp
+++ b/libopie2/opieui/olistview.cpp
@@ -1,51 +1,51 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 =. (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> 3 =. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l. 4 .=l.
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This program is free software; you can 6 _;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License, 10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version. 11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This program is distributed in the hope that 13    .i_,=:_.      -<s. This program is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more 18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details. 19++=   -.     .`     .: details.
20 :     =  ...= . :.=- 20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU 21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with 22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB. 23    --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation, 24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, 25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27 27
28*/ 28*/
29 29
30/* QT */ 30/* QT */
31 31
32#include <qpixmap.h> 32#include <qpixmap.h>
33 33
34/* OPIE */ 34/* OPIE */
35 35
36#include <opie2/odebug.h> 36#include <opie2/odebug.h>
37#include <opie2/olistview.h> 37#include <opie2/olistview.h>
38 38
39/*====================================================================================== 39/*======================================================================================
40 * OListView 40 * OListView
41 *======================================================================================*/ 41 *======================================================================================*/
42 42
43OListView::OListView( QWidget *parent, const char *name ) 43OListView::OListView( QWidget *parent, const char *name )
44 :QListView( parent, name ) 44 :QListView( parent, name )
45{ 45{
46 //FIXME: get from global settings and calculate ==> see oglobalsettings.* 46 //FIXME: get from global settings and calculate ==> see oglobalsettings.*
47 47
48 m_alternateBackground = QColor( 238, 246, 255 ); 48 m_alternateBackground = QColor( 238, 246, 255 );
49 m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine ); 49 m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine );
50 m_fullWidth = true; 50 m_fullWidth = true;
51 connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*))); 51 connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*)));
@@ -129,122 +129,146 @@ void OListView::expand(QListViewItem *item)
129{ 129{
130 ((OListViewItem*)item)->expand(); 130 ((OListViewItem*)item)->expand();
131} 131}
132 132
133OListViewItem* OListView::childFactory() 133OListViewItem* OListView::childFactory()
134{ 134{
135 return new OListViewItem( this ); 135 return new OListViewItem( this );
136} 136}
137 137
138#ifndef QT_NO_DATASTREAM 138#ifndef QT_NO_DATASTREAM
139void OListView::serializeTo( QDataStream& s ) const 139void OListView::serializeTo( QDataStream& s ) const
140{ 140{
141 #warning Caution... the binary format is still under construction... 141 #warning Caution... the binary format is still under construction...
142 odebug << "storing OListView..." << oendl; 142 odebug << "storing OListView..." << oendl;
143 143
144 // store number of columns and the labels 144 // store number of columns and the labels
145 s << columns(); 145 s << columns();
146 for ( int i = 0; i < columns(); ++i ) 146 for ( int i = 0; i < columns(); ++i )
147 s << columnText( i ); 147 s << columnText( i );
148 148
149 // calculate the number of top-level items to serialize 149 // calculate the number of top-level items to serialize
150 int items = 0; 150 int items = 0;
151 QListViewItem* item = firstChild(); 151 QListViewItem* item = firstChild();
152 while ( item ) 152 while ( item )
153 { 153 {
154 item = item->nextSibling(); 154 item = item->nextSibling();
155 items++; 155 items++;
156 } 156 }
157 157
158 // store number of items and the items itself 158 // store number of items and the items itself
159 s << items; 159 s << items;
160 item = firstChild(); 160 item = firstChild();
161 for ( int i = 0; i < items; ++i ) 161 for ( int i = 0; i < items; ++i )
162 { 162 {
163 s << *static_cast<OListViewItem*>( item ); 163 s << *static_cast<OListViewItem*>( item );
164 item = item->nextSibling(); 164 item = item->nextSibling();
165 } 165 }
166 166
167 odebug << "OListview stored." << oendl; 167 odebug << "OListview stored." << oendl;
168} 168}
169 169
170void OListView::serializeFrom( QDataStream& s ) 170void OListView::serializeFrom( QDataStream& s )
171{ 171{
172 #warning Caution... the binary format is still under construction... 172 #warning Caution... the binary format is still under construction...
173 odebug << "loading OListView..." << oendl; 173 odebug << "loading OListView..." << oendl;
174 174
175 int cols; 175 int cols;
176 s >> cols; 176 s >> cols;
177 qDebug( "read number of columns = %d", cols ); 177 odebug << "read number of columns = " << cols << oendl;
178 178
179 while ( columns() < cols ) addColumn( QString::null ); 179 while ( columns() < cols ) addColumn( QString::null );
180 180
181 for ( int i = 0; i < cols; ++i ) 181 for ( int i = 0; i < cols; ++i )
182 { 182 {
183 QString coltext; 183 QString coltext;
184 s >> coltext; 184 s >> coltext;
185 qDebug( "read text '%s' for column %d", (const char*) coltext, i ); 185 qDebug( "read text '%s' for column %d", (const char*) coltext, i );
186 setColumnText( i, coltext ); 186 setColumnText( i, coltext );
187 } 187 }
188 188
189 int items; 189 int items;
190 s >> items; 190 s >> items;
191 qDebug( "read number of items = %d", items ); 191 odebug << "read number of items = " << items << oendl;
192 192
193 for ( int i = 0; i < items; ++i ) 193 for ( int i = 0; i < items; ++i )
194 { 194 {
195 OListViewItem* item = childFactory(); 195 OListViewItem* item = childFactory();
196 s >> *item; 196 s >> *item;
197 } 197 }
198 198
199 odebug << "OListView loaded." << oendl; 199 odebug << "OListView loaded." << oendl;
200 200
201} 201}
202 202
203
204void OListView::expand()
205{
206 odebug << "OListView::expand" << oendl;
207
208 QListViewItemIterator it( this );
209 while ( it.current() ) {
210 it.current()->setOpen( true );
211 ++it;
212 }
213}
214
215
216void OListView::collapse()
217{
218 odebug << "OListView::collapse" << oendl;
219 QListViewItemIterator it( this );
220 while ( it.current() ) {
221 it.current()->setOpen( false );
222 ++it;
223 }
224}
225
226
203QDataStream& operator<<( QDataStream& s, const OListView& lv ) 227QDataStream& operator<<( QDataStream& s, const OListView& lv )
204{ 228{
205 lv.serializeTo( s ); 229 lv.serializeTo( s );
206} 230}
207 231
208QDataStream& operator>>( QDataStream& s, OListView& lv ) 232QDataStream& operator>>( QDataStream& s, OListView& lv )
209{ 233{
210 lv.serializeFrom( s ); 234 lv.serializeFrom( s );
211} 235}
212#endif // QT_NO_DATASTREAM 236#endif // QT_NO_DATASTREAM
213 237
214/*====================================================================================== 238/*======================================================================================
215 * OListViewItem 239 * OListViewItem
216 *======================================================================================*/ 240 *======================================================================================*/
217 241
218OListViewItem::OListViewItem(QListView *parent) 242OListViewItem::OListViewItem(QListView *parent)
219 : QListViewItem(parent) 243 : QListViewItem(parent)
220{ 244{
221 init(); 245 init();
222} 246}
223 247
224 248
225OListViewItem::OListViewItem(QListViewItem *parent) 249OListViewItem::OListViewItem(QListViewItem *parent)
226 : QListViewItem(parent) 250 : QListViewItem(parent)
227{ 251{
228 init(); 252 init();
229} 253}
230 254
231 255
232OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) 256OListViewItem::OListViewItem(QListView *parent, QListViewItem *after)
233 : QListViewItem(parent, after) 257 : QListViewItem(parent, after)
234{ 258{
235 init(); 259 init();
236} 260}
237 261
238 262
239OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) 263OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after)
240 : QListViewItem(parent, after) 264 : QListViewItem(parent, after)
241{ 265{
242 init(); 266 init();
243} 267}
244 268
245 269
246OListViewItem::OListViewItem(QListView *parent, 270OListViewItem::OListViewItem(QListView *parent,
247 QString label1, QString label2, QString label3, QString label4, 271 QString label1, QString label2, QString label3, QString label4,
248 QString label5, QString label6, QString label7, QString label8) 272 QString label5, QString label6, QString label7, QString label8)
249 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) 273 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
250{ 274{
@@ -400,96 +424,219 @@ void OListViewItem::serializeTo( QDataStream& s ) const
400 item = item->nextSibling(); 424 item = item->nextSibling();
401 } 425 }
402 426
403 odebug << "OListviewItem stored." << oendl; 427 odebug << "OListviewItem stored." << oendl;
404} 428}
405 429
406 430
407void OListViewItem::serializeFrom( QDataStream& s ) 431void OListViewItem::serializeFrom( QDataStream& s )
408{ 432{
409 #warning Caution... the binary format is still under construction... 433 #warning Caution... the binary format is still under construction...
410 odebug << "loading OListViewItem..." << oendl; 434 odebug << "loading OListViewItem..." << oendl;
411 435
412 for ( int i = 0; i < listView()->columns(); ++i ) 436 for ( int i = 0; i < listView()->columns(); ++i )
413 { 437 {
414 QString coltext; 438 QString coltext;
415 s >> coltext; 439 s >> coltext;
416 qDebug( "read text '%s' for column %d", (const char*) coltext, i ); 440 qDebug( "read text '%s' for column %d", (const char*) coltext, i );
417 setText( i, coltext ); 441 setText( i, coltext );
418 } 442 }
419 443
420 int items; 444 int items;
421 s >> items; 445 s >> items;
422 qDebug( "read number of items = %d", items ); 446 qDebug( "read number of items = %d", items );
423 447
424 for ( int i = 0; i < items; ++i ) 448 for ( int i = 0; i < items; ++i )
425 { 449 {
426 OListViewItem* item = childFactory(); 450 OListViewItem* item = childFactory();
427 s >> (*item); 451 s >> (*item);
428 } 452 }
429 453
430 odebug << "OListViewItem loaded." << oendl; 454 odebug << "OListViewItem loaded." << oendl;
431} 455}
432 456
433 457
434QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) 458QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi )
435{ 459{
436 lvi.serializeTo( s ); 460 lvi.serializeTo( s );
437} 461}
438 462
439 463
440QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) 464QDataStream& operator>>( QDataStream& s, OListViewItem& lvi )
441{ 465{
442 lvi.serializeFrom( s ); 466 lvi.serializeFrom( s );
443} 467}
444#endif // QT_NO_DATASTREAM 468#endif // QT_NO_DATASTREAM
445 469
446 470
447/*====================================================================================== 471/*======================================================================================
472 * OCheckListItem
473 *======================================================================================*/
474
475OCheckListItem::OCheckListItem( QCheckListItem* parent, const QString& text, Type t )
476 :QCheckListItem( parent, text, t )
477{
478 init();
479}
480
481
482OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, Type t)
483 :QCheckListItem( parent, text, t )
484{
485 init();
486}
487
488
489OCheckListItem::OCheckListItem( QListView* parent, const QString& text, Type t )
490 :QCheckListItem( parent, text, t )
491{
492 init();
493}
494
495
496OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, const QPixmap& p )
497 :QCheckListItem( parent, text, p )
498{
499 init();
500}
501
502
503OCheckListItem::OCheckListItem( QListView* parent, const QString& text, const QPixmap& p )
504 :QCheckListItem( parent, text, p )
505{
506 init();
507}
508
509
510OCheckListItem::~OCheckListItem()
511{
512}
513
514void OCheckListItem::init()
515{
516 m_known = false;
517}
518
519
520const QColor &OCheckListItem::backgroundColor()
521{
522 return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() :
523 listView()->viewport()->colorGroup().base();
524}
525
526
527bool OCheckListItem::isAlternate()
528{
529 OListView *lv = static_cast<OListView*>( listView() );
530
531 // check if the item above is an OCheckListItem
532 OCheckListItem *above = static_cast<OCheckListItem*>( itemAbove() );
533 /*if (! itemAbove()->inherits( "OCheckListItem" )) return false;*/
534
535 // check if we have a valid alternate background color
536 if (!(lv && lv->alternateBackground().isValid())) return false;
537
538 m_known = above ? above->m_known : true;
539 if (m_known)
540 {
541 m_odd = above ? !above->m_odd : false;
542 }
543 else
544 {
545 OCheckListItem *item;
546 bool previous = true;
547 if (parent())
548 {
549 item = static_cast<OCheckListItem *>(parent());
550 if ( item /*&& item->inherits( "OCheckListItem" )*/ ) previous = item->m_odd;
551 item = static_cast<OCheckListItem *>(parent()->firstChild());
552 /* if ( !item.inherits( "OCheckListItem" ) item = 0; */
553 }
554 else
555 {
556 item = static_cast<OCheckListItem *>(lv->firstChild());
557 }
558
559 while(item)
560 {
561 item->m_odd = previous = !previous;
562 item->m_known = true;
563 item = static_cast<OCheckListItem *>(item->nextSibling());
564 /* if (!item.inherits( "OCheckListItem" ) ) break; */
565 }
566 }
567 return m_odd;
568}
569
570
571void OCheckListItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
572{
573 QColorGroup _cg = cg;
574 const QPixmap *pm = listView()->viewport()->backgroundPixmap();
575 if (pm && !pm->isNull())
576 {
577 _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) );
578 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
579 }
580 else if ( isAlternate() )
581 {
582 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
583 }
584 QCheckListItem::paintCell( p, _cg, column, width, alignment );
585
586 //FIXME: Use styling here!
587
588 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
589 p->setPen( pen );
590 p->drawLine( width-1, 0, width-1, height() );
591}
592
593
594/*======================================================================================
448 * ONamedListView 595 * ONamedListView
449 *======================================================================================*/ 596 *======================================================================================*/
450 597
451ONamedListView::ONamedListView( QWidget *parent, const char *name ) 598ONamedListView::ONamedListView( QWidget *parent, const char *name )
452 :OListView( parent, name ) 599 :OListView( parent, name )
453{ 600{
454} 601}
455 602
456 603
457ONamedListView::~ONamedListView() 604ONamedListView::~ONamedListView()
458{ 605{
459} 606}
460 607
461 608
462void ONamedListView::addColumns( const QStringList& columns ) 609void ONamedListView::addColumns( const QStringList& columns )
463{ 610{
464 for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it ) 611 for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it )
465 { 612 {
466 qDebug( "adding column %s", (const char*) *it ); 613 qDebug( "adding column %s", (const char*) *it );
467 addColumn( *it ); 614 addColumn( *it );
468 } 615 }
469} 616}
470 617
471 618
472int ONamedListView::findColumn( const QString& text ) const 619int ONamedListView::findColumn( const QString& text ) const
473{ 620{
474 //FIXME: If used excessively, this will slow down performance of updates 621 //FIXME: If used excessively, this will slow down performance of updates
475 //FIXME: because of the linear search over all column texts. 622 //FIXME: because of the linear search over all column texts.
476 //FIXME: I will optimize later by using a hash map. 623 //FIXME: I will optimize later by using a hash map.
477 for ( int i = 0; i < columns(); ++i ) 624 for ( int i = 0; i < columns(); ++i )
478 if ( columnText( i ) == text ) 625 if ( columnText( i ) == text )
479 return i; 626 return i;
480 return -1; 627 return -1;
481} 628}
482 629
483 630
484ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const 631ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const
485{ 632{
486 return find( (ONamedListViewItem*) firstChild(), column, text, recurse ); 633 return find( (ONamedListViewItem*) firstChild(), column, text, recurse );
487} 634}
488 635
489 636
490ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const 637ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const
491{ 638{
492 ONamedListViewItem* result; 639 ONamedListViewItem* result;
493 while ( item && item->text( column ) != text ) 640 while ( item && item->text( column ) != text )
494 { 641 {
495 qDebug( "checked %s", (const char*) item->text( column ) ); 642 qDebug( "checked %s", (const char*) item->text( column ) );
diff --git a/libopie2/opieui/olistview.h b/libopie2/opieui/olistview.h
index a00b43a..59b0973 100644
--- a/libopie2/opieui/olistview.h
+++ b/libopie2/opieui/olistview.h
@@ -1,203 +1,213 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3 =. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@vanille.de>
4 =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 .=l. 4 .=l.
6           .>+-= 5           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 6 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 10 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 11     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 12    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 13    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 18..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 19++=   -.     .`     .: details.
21 :     =  ...= . :.=- 20 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 21 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 22  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 23    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 24 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 25 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
28 27
29*/ 28*/
30 29
31#ifndef OLISTVIEW_H 30#ifndef OLISTVIEW_H
32#define OLISTVIEW_H 31#define OLISTVIEW_H
33 32
34#include <qcolor.h> 33#include <qcolor.h>
35#include <qlistview.h> 34#include <qlistview.h>
36#include <qpen.h> 35#include <qpen.h>
37#include <qdatastream.h> 36#include <qdatastream.h>
38#include <qstringlist.h> 37#include <qstringlist.h>
39 38
40class OListViewItem; 39class OListViewItem;
41 40
42 41
43/*====================================================================================== 42/*======================================================================================
44 * OListView 43 * OListView
45 *======================================================================================*/ 44 *======================================================================================*/
46 45
47/** 46/**
48 * @brief A list/tree widget. 47 * @brief A list/tree widget.
49 * 48 *
50 * A @ref QListView variant featuring visual and functional enhancements 49 * A @ref QListView variant featuring visual and functional enhancements
51 * like an alternate background for odd rows, an autostretch mode 50 * like an alternate background for odd rows, an autostretch mode
52 * for the width of the widget ( >= Qt 3 only ) and persistence capabilities. 51 * for the width of the widget ( >= Qt 3 only ) and persistence capabilities.
53 * 52 *
54 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 53 * @author Michael 'Mickey' Lauer <mickey@vanille.de>
55 */ 54 */
56class OListView: public QListView 55class OListView: public QListView
57{ 56{
58 public: 57 public:
59 /** 58 /**
60 * Constructor. 59 * Constructor.
61 * 60 *
62 * The parameters @a parent and @a name are handled by 61 * The parameters @a parent and @a name are handled by
63 * @ref QListView, as usual. 62 * @ref QListView, as usual.
64 */ 63 */
65 OListView( QWidget* parent = 0, const char* name = 0 ); 64 OListView( QWidget* parent = 0, const char* name = 0 );
66 /** 65 /**
67 * Destructor. 66 * Destructor.
68 */ 67 */
69 virtual ~OListView(); 68 virtual ~OListView();
70 /** 69 /**
71 * Let the last column fit exactly all the available width. 70 * Let the last column fit exactly all the available width.
72 */ 71 */
73 void setFullWidth( bool fullWidth ); 72 void setFullWidth( bool fullWidth );
74 /** 73 /**
75 * Returns whether the last column is set to fit the available width. 74 * Returns whether the last column is set to fit the available width.
76 */ 75 */
77 bool fullWidth() const; 76 bool fullWidth() const;
78 /** 77 /**
79 * Reimplemented for full width support 78 * Reimplemented for full width support
80 */ 79 */
81 virtual int addColumn( const QString& label, int width = -1 ); 80 virtual int addColumn( const QString& label, int width = -1 );
82 /** 81 /**
83 * Reimplemented for full width support 82 * Reimplemented for full width support
84 */ 83 */
85 virtual int addColumn( const QIconSet& iconset, const QString& label, int width = -1 ); 84 virtual int addColumn( const QIconSet& iconset, const QString& label, int width = -1 );
86 /** 85 /**
87 * Reimplemented for full width support 86 * Reimplemented for full width support
88 */ 87 */
89 virtual void removeColumn(int index); 88 virtual void removeColumn(int index);
90 /** 89 /**
91 * Set the alternate background background @a color. 90 * Set the alternate background background @a color.
92 * Set to an invalid color to disable alternate colors. 91 * Set to an invalid color to disable alternate colors.
93 * This only has an effect if the items are OListViewItems 92 * This only has an effect if the items are OListViewItems
94 */ 93 */
95 void setAlternateBackground( const QColor& color ); 94 void setAlternateBackground( const QColor& color );
96 /** 95 /**
97 * Sets the column separator @a pen. 96 * Sets the column separator @a pen.
98 */ 97 */
99 void setColumnSeparator( const QPen& pen ); 98 void setColumnSeparator( const QPen& pen );
100 99
101 /** 100 /**
102 * @returns the alternate background color 101 * @returns the alternate background color
103 */ 102 */
104 const QColor& alternateBackground() const; 103 const QColor& alternateBackground() const;
105 /** 104 /**
106 * @return the column separator pen 105 * @return the column separator pen
107 */ 106 */
108 const QPen& columnSeparator() const; 107 const QPen& columnSeparator() const;
109 /** 108 /**
110 * Create a list view item as child of this object 109 * Create a list view item as child of this object
111 * @returns the new object 110 * @returns the new object
112 */ 111 */
113 virtual OListViewItem* childFactory(); 112 virtual OListViewItem* childFactory();
114#ifndef QT_NO_DATASTREAM 113#ifndef QT_NO_DATASTREAM
115 /** 114 /**
116 * Serialize this object to @ref QDataStream @a stream 115 * Serialize this object to @ref QDataStream @a stream
117 */ 116 */
118 virtual void serializeTo( QDataStream& stream ) const; 117 virtual void serializeTo( QDataStream& stream ) const;
119 /** 118 /**
120 * Serialize this object from a @ref QDataStream @a stream 119 * Serialize this object from a @ref QDataStream @a stream
121 */ 120 */
122 virtual void serializeFrom( QDataStream& s ); 121 virtual void serializeFrom( QDataStream& s );
123#endif 122#endif
124 123
125protected slots: 124 public slots:
126 /** 125 /**
126 * Expand all items
127 */
128 void expand();
129 /**
130 * Collapse all items
131 */
132 void collapse();
133
134 protected slots:
135 /**
127 * expand the current OListViewItem 136 * expand the current OListViewItem
128 */ 137 */
129 void expand(QListViewItem*); 138 void expand(QListViewItem*);
130 139
131 private: 140 private:
132 QColor m_alternateBackground; 141 QColor m_alternateBackground;
133 bool m_fullWidth; 142 bool m_fullWidth;
134 QPen m_columnSeparator; 143 QPen m_columnSeparator;
135}; 144};
136 145
137#ifndef QT_NO_DATASTREAM 146#ifndef QT_NO_DATASTREAM
138/** 147/**
139 * @relates OListView 148 * @relates OListView
140 * Writes @a listview to the @a stream and returns a reference to the stream. 149 * Writes @a listview to the @a stream and returns a reference to the stream.
141 */ 150 */
142QDataStream& operator<<( QDataStream& stream, const OListView& listview ); 151QDataStream& operator<<( QDataStream& stream, const OListView& listview );
143/** 152/**
144 * @relates OListView 153 * @relates OListView
145 * Reads @a listview from the @a stream and returns a reference to the stream. 154 * Reads @a listview from the @a stream and returns a reference to the stream.
146 */ 155 */
147QDataStream& operator>>( QDataStream& stream, OListView& listview ); 156QDataStream& operator>>( QDataStream& stream, OListView& listview );
148#endif // QT_NO_DATASTREAM 157#endif // QT_NO_DATASTREAM
149 158
150/*====================================================================================== 159/*======================================================================================
151 * OListViewItem 160 * OListViewItem
152 *======================================================================================*/ 161 *======================================================================================*/
153 162
154class OListViewItem: public QListViewItem 163class OListViewItem: public QListViewItem
155{ 164{
165 friend class OCheckListItem;
156 public: 166 public:
157 /** 167 /**
158 * Constructors. 168 * Constructors.
159 */ 169 */
160 OListViewItem( QListView * parent ); 170 OListViewItem( QListView * parent );
161 OListViewItem( QListViewItem * parent ); 171 OListViewItem( QListViewItem * parent );
162 OListViewItem( QListView * parent, QListViewItem * after ); 172 OListViewItem( QListView * parent, QListViewItem * after );
163 OListViewItem( QListViewItem * parent, QListViewItem * after ); 173 OListViewItem( QListViewItem * parent, QListViewItem * after );
164 174
165 OListViewItem( QListView * parent, 175 OListViewItem( QListView * parent,
166 QString, QString = QString::null, 176 QString, QString = QString::null,
167 QString = QString::null, QString = QString::null, 177 QString = QString::null, QString = QString::null,
168 QString = QString::null, QString = QString::null, 178 QString = QString::null, QString = QString::null,
169 QString = QString::null, QString = QString::null ); 179 QString = QString::null, QString = QString::null );
170 180
171 OListViewItem( QListViewItem * parent, 181 OListViewItem( QListViewItem * parent,
172 QString, QString = QString::null, 182 QString, QString = QString::null,
173 QString = QString::null, QString = QString::null, 183 QString = QString::null, QString = QString::null,
174 QString = QString::null, QString = QString::null, 184 QString = QString::null, QString = QString::null,
175 QString = QString::null, QString = QString::null ); 185 QString = QString::null, QString = QString::null );
176 186
177 OListViewItem( QListView * parent, QListViewItem * after, 187 OListViewItem( QListView * parent, QListViewItem * after,
178 QString, QString = QString::null, 188 QString, QString = QString::null,
179 QString = QString::null, QString = QString::null, 189 QString = QString::null, QString = QString::null,
180 QString = QString::null, QString = QString::null, 190 QString = QString::null, QString = QString::null,
181 QString = QString::null, QString = QString::null ); 191 QString = QString::null, QString = QString::null );
182 192
183 OListViewItem( QListViewItem * parent, QListViewItem * after, 193 OListViewItem( QListViewItem * parent, QListViewItem * after,
184 QString, QString = QString::null, 194 QString, QString = QString::null,
185 QString = QString::null, QString = QString::null, 195 QString = QString::null, QString = QString::null,
186 QString = QString::null, QString = QString::null, 196 QString = QString::null, QString = QString::null,
187 QString = QString::null, QString = QString::null ); 197 QString = QString::null, QString = QString::null );
188 /** 198 /**
189 * Destructor. 199 * Destructor.
190 */ 200 */
191 virtual ~OListViewItem(); 201 virtual ~OListViewItem();
192 /** 202 /**
193 * @returns the background color of the list item. 203 * @returns the background color of the list item.
194 */ 204 */
195 const QColor& backgroundColor(); 205 const QColor& backgroundColor();
196 /** 206 /**
197 * @returns true, if the item is at an odd position and 207 * @returns true, if the item is at an odd position and
198 * thus have to be painted with the alternate background color. 208 * thus have to be painted with the alternate background color.
199 */ 209 */
200 bool isAlternate(); 210 bool isAlternate();
201 /** 211 /**
202 * @note: Reimplemented for internal purposes - the API is not affected 212 * @note: Reimplemented for internal purposes - the API is not affected
203 * 213 *
@@ -205,150 +215,195 @@ class OListViewItem: public QListViewItem
205 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); 215 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment );
206 /** 216 /**
207 * Perform object initialization. 217 * Perform object initialization.
208 */ 218 */
209 void init(); 219 void init();
210 /** 220 /**
211 * create a list view item as child of this object 221 * create a list view item as child of this object
212 * @returns the new object 222 * @returns the new object
213 */ 223 */
214 virtual OListViewItem* childFactory(); 224 virtual OListViewItem* childFactory();
215 #ifndef QT_NO_DATASTREAM 225 #ifndef QT_NO_DATASTREAM
216 /** 226 /**
217 * serialize this object to or from a @ref QDataStream 227 * serialize this object to or from a @ref QDataStream
218 * @param s the stream used to serialize this object. 228 * @param s the stream used to serialize this object.
219 */ 229 */
220 virtual void serializeTo( QDataStream& s ) const; 230 virtual void serializeTo( QDataStream& s ) const;
221 231
222 /** 232 /**
223 * serialize this object to or from a @ref QDataStream 233 * serialize this object to or from a @ref QDataStream
224 * @param s the stream used to serialize this object. 234 * @param s the stream used to serialize this object.
225 */ 235 */
226 virtual void serializeFrom( QDataStream& s ); 236 virtual void serializeFrom( QDataStream& s );
227 #endif 237 #endif
228 238
229 /** 239 /**
230 * expand the the item 240 * expand the the item
231 */ 241 */
232 virtual void expand(){}; 242 virtual void expand(){};
233 243
234 private: 244 private:
235 bool m_known; 245 bool m_known;
236 bool m_odd; 246 bool m_odd;
237}; 247};
238 248
239#ifndef QT_NO_DATASTREAM 249#ifndef QT_NO_DATASTREAM
240/** 250/**
241 * @relates QListViewItem 251 * @relates QListViewItem
242 * Writes listview @a item and all subitems recursively to @a stream 252 * Writes listview @a item and all subitems recursively to @a stream
243 * and returns a reference to the stream. 253 * and returns a reference to the stream.
244 */ 254 */
245QDataStream& operator<<( QDataStream& stream, const OListViewItem& item ); 255QDataStream& operator<<( QDataStream& stream, const OListViewItem& item );
246/** 256/**
247 * @relates QListViewItem 257 * @relates QListViewItem
248 * Reads listview @a item from @a stream and returns a reference to the stream. 258 * Reads listview @a item from @a stream and returns a reference to the stream.
249 */ 259 */
250QDataStream& operator>>( QDataStream& stream, OListViewItem& item ); 260QDataStream& operator>>( QDataStream& stream, OListViewItem& item );
251#endif // QT_NO_DATASTREAM 261#endif // QT_NO_DATASTREAM
252 262
263
264/*======================================================================================
265 * OCheckListItem
266 *======================================================================================*/
267
268class OCheckListItem : public QCheckListItem
269{
270 public:
271
272 OCheckListItem( QCheckListItem *parent, const QString &text,
273 Type = Controller );
274 OCheckListItem( QListViewItem *parent, const QString &text,
275 Type = Controller );
276 OCheckListItem( QListView *parent, const QString &text,
277 Type = Controller );
278 OCheckListItem( QListViewItem *parent, const QString &text,
279 const QPixmap & );
280 OCheckListItem( QListView *parent, const QString &text,
281 const QPixmap & );
282 ~OCheckListItem();
283 /**
284 * @returns the background color of the list item.
285 */
286 const QColor& backgroundColor();
287 /**
288 * @returns true, if the item is at an odd position and
289 * thus have to be painted with the alternate background color.
290 */
291 bool isAlternate();
292 /**
293 * @note: Reimplemented for internal purposes - the API is not affected
294 *
295 */
296 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment );
297 /**
298 * Perform object initialization.
299 */
300 void init();
301
302 private:
303 bool m_known;
304 bool m_odd;
305};
306
307
253/*====================================================================================== 308/*======================================================================================
254 * ONamedListView 309 * ONamedListView
255 *======================================================================================*/ 310 *======================================================================================*/
256 311
257class ONamedListViewItem; 312class ONamedListViewItem;
258 313
259/** 314/**
260 * @brief An OListView variant with named columns. 315 * @brief An OListView variant with named columns.
261 * 316 *
262 * This class provides a higher-level interface to an OListView. 317 * This class provides a higher-level interface to an OListView.
263 * 318 *
264 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 319 * @author Michael 'Mickey' Lauer <mickey@vanille.de>
265 */ 320 */
266class ONamedListView: public OListView 321class ONamedListView: public OListView
267{ 322{
268 public: 323 public:
269 /** 324 /**
270 * Constructor. 325 * Constructor.
271 * 326 *
272 * The parameters @a parent and @a name are handled by 327 * The parameters @a parent and @a name are handled by
273 * @ref OListView, as usual. 328 * @ref OListView, as usual.
274 */ 329 */
275 ONamedListView( QWidget* parent = 0, const char* name = 0 ); 330 ONamedListView( QWidget* parent = 0, const char* name = 0 );
276 /** 331 /**
277 * Destructor. 332 * Destructor.
278 */ 333 */
279 virtual ~ONamedListView(); 334 virtual ~ONamedListView();
280 /** 335 /**
281 * Add a number of @a columns to the listview. 336 * Add a number of @a columns to the listview.
282 */ 337 */
283 virtual void addColumns( const QStringList& columns ); 338 virtual void addColumns( const QStringList& columns );
284 /** 339 /**
285 * @returns the column index matching to @a text or -1 if not found. 340 * @returns the column index matching to @a text or -1 if not found.
286 */ 341 */
287 virtual int findColumn( const QString& text ) const; 342 virtual int findColumn( const QString& text ) const;
288 /** 343 /**
289 * @returns the first item which has a @a text in column @a column. 344 * @returns the first item which has a @a text in column @a column.
290 * Set @a recurse to indicate how much subchild levels to search, e.g.<ul> 345 * Set @a recurse to indicate how much subchild levels to search, e.g.<ul>
291 * <li>set it to 0 to search only among direct childs, 346 * <li>set it to 0 to search only among direct childs,
292 * <li>set it to 1 to search direct childs and all 1st order subchilds 347 * <li>set it to 1 to search direct childs and all 1st order subchilds
293 * <li>set it to -1 for maximum recursion. 348 * <li>set it to -1 for maximum recursion.
294 * </ul> 349 * </ul>
295 * @sa ONamedListViewItem::find() 350 * @sa ONamedListViewItem::find()
296 */ 351 */
297 virtual ONamedListViewItem* find( ONamedListViewItem* start, int column, const QString& text, int recurse = -1 ) const; 352 virtual ONamedListViewItem* find( ONamedListViewItem* start, int column, const QString& text, int recurse = -1 ) const;
298 virtual ONamedListViewItem* find( int column, const QString& text, int recurse = -1 ) const; 353 virtual ONamedListViewItem* find( int column, const QString& text, int recurse = -1 ) const;
299 354
300 virtual ONamedListViewItem* find( ONamedListViewItem* start, const QString& column, const QString& text, int recurse = -1 ) const; 355 virtual ONamedListViewItem* find( ONamedListViewItem* start, const QString& column, const QString& text, int recurse = -1 ) const;
301 virtual ONamedListViewItem* find( const QString& column, const QString& text, int recurse = -1 ) const; 356 virtual ONamedListViewItem* find( const QString& column, const QString& text, int recurse = -1 ) const;
302}; 357};
303 358
304/*====================================================================================== 359/*======================================================================================
305 * ONamedListViewItem 360 * ONamedListViewItem
306 *======================================================================================*/ 361 *======================================================================================*/
307 362
308/** 363/**
309 * @brief An OListView variant with named columns. 364 * @brief An OListView variant with named columns.
310 * 365 *
311 * This class provides a higher-level interface to an OListViewItem. 366 * This class provides a higher-level interface to an OListViewItem.
312 * 367 *
313 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 368 * @author Michael 'Mickey' Lauer <mickey@vanille.de>
314 */ 369 */
315class ONamedListViewItem: public OListViewItem 370class ONamedListViewItem: public OListViewItem
316{ 371{
317 public: 372 public:
318 /** 373 /**
319 * Constructor. Accepts the same parameters as a @ref OListViewItem, 374 * Constructor. Accepts the same parameters as a @ref OListViewItem,
320 * plus a @ref QStringList which holds an arbitrary number of @a texts. 375 * plus a @ref QStringList which holds an arbitrary number of @a texts.
321 */ 376 */
322 ONamedListViewItem( QListView* parent, const QStringList& texts ); 377 ONamedListViewItem( QListView* parent, const QStringList& texts );
323 ONamedListViewItem( QListViewItem* parent, const QStringList& texts ); 378 ONamedListViewItem( QListViewItem* parent, const QStringList& texts );
324 ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ); 379 ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts );
325 ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ); 380 ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts );
326 /** 381 /**
327 * Destructor. 382 * Destructor.
328 */ 383 */
329 virtual ~ONamedListViewItem(); 384 virtual ~ONamedListViewItem();
330 /** 385 /**
331 * Sets the text in column @a column to @a text. 386 * Sets the text in column @a column to @a text.
332 * This method differs from @ref QListViewItem::setText() in that it 387 * This method differs from @ref QListViewItem::setText() in that it
333 * accepts a string as column indicator instead of an int. 388 * accepts a string as column indicator instead of an int.
334 */ 389 */
335 virtual void setText( const QString& column, const QString& text ); 390 virtual void setText( const QString& column, const QString& text );
336 /** 391 /**
337 * Sets a number of @a texts for this item. 392 * Sets a number of @a texts for this item.
338 */ 393 */
339 virtual void setText( const QStringList& texts ); 394 virtual void setText( const QStringList& texts );
340 /** 395 /**
341 * @returns the first child which has a @a text in column @a column. 396 * @returns the first child which has a @a text in column @a column.
342 * Set @a recurse to indicate how much subchild levels to search, e.g.<ul> 397 * Set @a recurse to indicate how much subchild levels to search, e.g.<ul>
343 * <li>set it to 0 to search only among direct childs, 398 * <li>set it to 0 to search only among direct childs,
344 * <li>set it to 1 to search direct childs and all 1st order subchilds 399 * <li>set it to 1 to search direct childs and all 1st order subchilds
345 * <li>set it to -1 for maximum recursion. 400 * <li>set it to -1 for maximum recursion.
346 * </ul> 401 * </ul>
347 * @sa ONamedListView::find() 402 * @sa ONamedListView::find()
348 */ 403 */
349 virtual ONamedListViewItem* find( int column, const QString& text, int recurse = -1 ) const; 404 virtual ONamedListViewItem* find( int column, const QString& text, int recurse = -1 ) const;
350 virtual ONamedListViewItem* find( const QString& column, const QString& text, int recurse = -1 ) const; 405 virtual ONamedListViewItem* find( const QString& column, const QString& text, int recurse = -1 ) const;
351}; 406};
352 407
353 408
354#endif // OLISTVIEW_H 409#endif // OLISTVIEW_H