-rw-r--r-- | libopie2/opieui/olistview.cpp | 153 | ||||
-rw-r--r-- | libopie2/opieui/olistview.h | 65 |
2 files changed, 210 insertions, 8 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,6 +1,6 @@ | |||
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 |
@@ -174,7 +174,7 @@ void OListView::serializeFrom( QDataStream& s ) | |||
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 | ||
@@ -188,7 +188,7 @@ void OListView::serializeFrom( QDataStream& s ) | |||
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 | { |
@@ -200,6 +200,30 @@ void OListView::serializeFrom( QDataStream& s ) | |||
200 | 200 | ||
201 | } | 201 | } |
202 | 202 | ||
203 | |||
204 | void 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 | |||
216 | void 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 | |||
203 | QDataStream& operator<<( QDataStream& s, const OListView& lv ) | 227 | QDataStream& operator<<( QDataStream& s, const OListView& lv ) |
204 | { | 228 | { |
205 | lv.serializeTo( s ); | 229 | lv.serializeTo( s ); |
@@ -445,6 +469,129 @@ QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) | |||
445 | 469 | ||
446 | 470 | ||
447 | /*====================================================================================== | 471 | /*====================================================================================== |
472 | * OCheckListItem | ||
473 | *======================================================================================*/ | ||
474 | |||
475 | OCheckListItem::OCheckListItem( QCheckListItem* parent, const QString& text, Type t ) | ||
476 | :QCheckListItem( parent, text, t ) | ||
477 | { | ||
478 | init(); | ||
479 | } | ||
480 | |||
481 | |||
482 | OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, Type t) | ||
483 | :QCheckListItem( parent, text, t ) | ||
484 | { | ||
485 | init(); | ||
486 | } | ||
487 | |||
488 | |||
489 | OCheckListItem::OCheckListItem( QListView* parent, const QString& text, Type t ) | ||
490 | :QCheckListItem( parent, text, t ) | ||
491 | { | ||
492 | init(); | ||
493 | } | ||
494 | |||
495 | |||
496 | OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, const QPixmap& p ) | ||
497 | :QCheckListItem( parent, text, p ) | ||
498 | { | ||
499 | init(); | ||
500 | } | ||
501 | |||
502 | |||
503 | OCheckListItem::OCheckListItem( QListView* parent, const QString& text, const QPixmap& p ) | ||
504 | :QCheckListItem( parent, text, p ) | ||
505 | { | ||
506 | init(); | ||
507 | } | ||
508 | |||
509 | |||
510 | OCheckListItem::~OCheckListItem() | ||
511 | { | ||
512 | } | ||
513 | |||
514 | void OCheckListItem::init() | ||
515 | { | ||
516 | m_known = false; | ||
517 | } | ||
518 | |||
519 | |||
520 | const QColor &OCheckListItem::backgroundColor() | ||
521 | { | ||
522 | return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : | ||
523 | listView()->viewport()->colorGroup().base(); | ||
524 | } | ||
525 | |||
526 | |||
527 | bool 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 | |||
571 | void 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 | ||
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,7 +1,6 @@ | |||
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 |
@@ -51,7 +50,7 @@ class OListViewItem; | |||
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 | */ |
56 | class OListView: public QListView | 55 | class OListView: public QListView |
57 | { | 56 | { |
@@ -122,6 +121,16 @@ class OListView: public QListView | |||
122 | virtual void serializeFrom( QDataStream& s ); | 121 | virtual void serializeFrom( QDataStream& s ); |
123 | #endif | 122 | #endif |
124 | 123 | ||
124 | public slots: | ||
125 | /** | ||
126 | * Expand all items | ||
127 | */ | ||
128 | void expand(); | ||
129 | /** | ||
130 | * Collapse all items | ||
131 | */ | ||
132 | void collapse(); | ||
133 | |||
125 | protected slots: | 134 | protected slots: |
126 | /** | 135 | /** |
127 | * expand the current OListViewItem | 136 | * expand the current OListViewItem |
@@ -153,6 +162,7 @@ QDataStream& operator>>( QDataStream& stream, OListView& listview ); | |||
153 | 162 | ||
154 | class OListViewItem: public QListViewItem | 163 | class OListViewItem: public QListViewItem |
155 | { | 164 | { |
165 | friend class OCheckListItem; | ||
156 | public: | 166 | public: |
157 | /** | 167 | /** |
158 | * Constructors. | 168 | * Constructors. |
@@ -250,6 +260,51 @@ QDataStream& operator<<( QDataStream& stream, const OListViewItem& item ); | |||
250 | QDataStream& operator>>( QDataStream& stream, OListViewItem& item ); | 260 | QDataStream& operator>>( QDataStream& stream, OListViewItem& item ); |
251 | #endif // QT_NO_DATASTREAM | 261 | #endif // QT_NO_DATASTREAM |
252 | 262 | ||
263 | |||
264 | /*====================================================================================== | ||
265 | * OCheckListItem | ||
266 | *======================================================================================*/ | ||
267 | |||
268 | class 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 | *======================================================================================*/ |
@@ -261,7 +316,7 @@ class ONamedListViewItem; | |||
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 | */ |
266 | class ONamedListView: public OListView | 321 | class ONamedListView: public OListView |
267 | { | 322 | { |
@@ -310,7 +365,7 @@ class ONamedListView: public OListView | |||
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 | */ |
315 | class ONamedListViewItem: public OListViewItem | 370 | class ONamedListViewItem: public OListViewItem |
316 | { | 371 | { |