summaryrefslogtreecommitdiff
Side-by-side diff
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
@@ -2,3 +2,3 @@
                This file is part of the Opie Project
- =. (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de>
+ =. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de>
.=l.
@@ -176,3 +176,3 @@ void OListView::serializeFrom( QDataStream& s )
s >> cols;
- qDebug( "read number of columns = %d", cols );
+ odebug << "read number of columns = " << cols << oendl;
@@ -190,3 +190,3 @@ void OListView::serializeFrom( QDataStream& s )
s >> items;
- qDebug( "read number of items = %d", items );
+ odebug << "read number of items = " << items << oendl;
@@ -202,2 +202,26 @@ void OListView::serializeFrom( QDataStream& s )
+
+void OListView::expand()
+{
+ odebug << "OListView::expand" << oendl;
+
+ QListViewItemIterator it( this );
+ while ( it.current() ) {
+ it.current()->setOpen( true );
+ ++it;
+ }
+}
+
+
+void OListView::collapse()
+{
+ odebug << "OListView::collapse" << oendl;
+ QListViewItemIterator it( this );
+ while ( it.current() ) {
+ it.current()->setOpen( false );
+ ++it;
+ }
+}
+
+
QDataStream& operator<<( QDataStream& s, const OListView& lv )
@@ -447,2 +471,125 @@ QDataStream& operator>>( QDataStream& s, OListViewItem& lvi )
/*======================================================================================
+ * OCheckListItem
+ *======================================================================================*/
+
+OCheckListItem::OCheckListItem( QCheckListItem* parent, const QString& text, Type t )
+ :QCheckListItem( parent, text, t )
+{
+ init();
+}
+
+
+OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, Type t)
+ :QCheckListItem( parent, text, t )
+{
+ init();
+}
+
+
+OCheckListItem::OCheckListItem( QListView* parent, const QString& text, Type t )
+ :QCheckListItem( parent, text, t )
+{
+ init();
+}
+
+
+OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, const QPixmap& p )
+ :QCheckListItem( parent, text, p )
+{
+ init();
+}
+
+
+OCheckListItem::OCheckListItem( QListView* parent, const QString& text, const QPixmap& p )
+ :QCheckListItem( parent, text, p )
+{
+ init();
+}
+
+
+OCheckListItem::~OCheckListItem()
+{
+}
+
+void OCheckListItem::init()
+{
+ m_known = false;
+}
+
+
+const QColor &OCheckListItem::backgroundColor()
+{
+ return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() :
+ listView()->viewport()->colorGroup().base();
+}
+
+
+bool OCheckListItem::isAlternate()
+{
+ OListView *lv = static_cast<OListView*>( listView() );
+
+ // check if the item above is an OCheckListItem
+ OCheckListItem *above = static_cast<OCheckListItem*>( itemAbove() );
+ /*if (! itemAbove()->inherits( "OCheckListItem" )) return false;*/
+
+ // check if we have a valid alternate background color
+ if (!(lv && lv->alternateBackground().isValid())) return false;
+
+ m_known = above ? above->m_known : true;
+ if (m_known)
+ {
+ m_odd = above ? !above->m_odd : false;
+ }
+ else
+ {
+ OCheckListItem *item;
+ bool previous = true;
+ if (parent())
+ {
+ item = static_cast<OCheckListItem *>(parent());
+ if ( item /*&& item->inherits( "OCheckListItem" )*/ ) previous = item->m_odd;
+ item = static_cast<OCheckListItem *>(parent()->firstChild());
+ /* if ( !item.inherits( "OCheckListItem" ) item = 0; */
+ }
+ else
+ {
+ item = static_cast<OCheckListItem *>(lv->firstChild());
+ }
+
+ while(item)
+ {
+ item->m_odd = previous = !previous;
+ item->m_known = true;
+ item = static_cast<OCheckListItem *>(item->nextSibling());
+ /* if (!item.inherits( "OCheckListItem" ) ) break; */
+ }
+ }
+ return m_odd;
+}
+
+
+void OCheckListItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
+{
+ QColorGroup _cg = cg;
+ const QPixmap *pm = listView()->viewport()->backgroundPixmap();
+ if (pm && !pm->isNull())
+ {
+ _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) );
+ p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
+ }
+ else if ( isAlternate() )
+ {
+ _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
+ }
+ QCheckListItem::paintCell( p, _cg, column, width, alignment );
+
+ //FIXME: Use styling here!
+
+ const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
+ p->setPen( pen );
+ p->drawLine( width-1, 0, width-1, height() );
+}
+
+
+/*======================================================================================
* ONamedListView
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
@@ -2,4 +2,3 @@
                This file is part of the Opie Project
-
- =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
+ =. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@vanille.de>
.=l.
@@ -53,3 +52,3 @@ class OListViewItem;
*
- * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
+ * @author Michael 'Mickey' Lauer <mickey@vanille.de>
*/
@@ -124,7 +123,17 @@ class OListView: public QListView
-protected slots:
- /**
+ public slots:
+ /**
+ * Expand all items
+ */
+ void expand();
+ /**
+ * Collapse all items
+ */
+ void collapse();
+
+ protected slots:
+ /**
* expand the current OListViewItem
*/
- void expand(QListViewItem*);
+ void expand(QListViewItem*);
@@ -155,2 +164,3 @@ class OListViewItem: public QListViewItem
{
+ friend class OCheckListItem;
public:
@@ -252,2 +262,47 @@ QDataStream& operator>>( QDataStream& stream, OListViewItem& item );
+
+/*======================================================================================
+ * OCheckListItem
+ *======================================================================================*/
+
+class OCheckListItem : public QCheckListItem
+{
+ public:
+
+ OCheckListItem( QCheckListItem *parent, const QString &text,
+ Type = Controller );
+ OCheckListItem( QListViewItem *parent, const QString &text,
+ Type = Controller );
+ OCheckListItem( QListView *parent, const QString &text,
+ Type = Controller );
+ OCheckListItem( QListViewItem *parent, const QString &text,
+ const QPixmap & );
+ OCheckListItem( QListView *parent, const QString &text,
+ const QPixmap & );
+ ~OCheckListItem();
+ /**
+ * @returns the background color of the list item.
+ */
+ const QColor& backgroundColor();
+ /**
+ * @returns true, if the item is at an odd position and
+ * thus have to be painted with the alternate background color.
+ */
+ bool isAlternate();
+ /**
+ * @note: Reimplemented for internal purposes - the API is not affected
+ *
+ */
+ void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment );
+ /**
+ * Perform object initialization.
+ */
+ void init();
+
+ private:
+ bool m_known;
+ bool m_odd;
+};
+
+
/*======================================================================================
@@ -263,3 +318,3 @@ class ONamedListViewItem;
*
- * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
+ * @author Michael 'Mickey' Lauer <mickey@vanille.de>
*/
@@ -312,3 +367,3 @@ class ONamedListView: public OListView
*
- * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
+ * @author Michael 'Mickey' Lauer <mickey@vanille.de>
*/