author | mickeyl <mickeyl> | 2004-03-05 21:36:58 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-03-05 21:36:58 (UTC) |
commit | b9d58b616102970872129b5bc2f55569910f5c03 (patch) (side-by-side diff) | |
tree | 593b40cce6f3da75593c90bff337b9b9c5092f7e /libopie2 | |
parent | 4a18103940564be8585af8121203561e16f0a32c (diff) | |
download | opie-b9d58b616102970872129b5bc2f55569910f5c03.zip opie-b9d58b616102970872129b5bc2f55569910f5c03.tar.gz opie-b9d58b616102970872129b5bc2f55569910f5c03.tar.bz2 |
add OCheckListItem
change my email address
-rw-r--r-- | libopie2/opieui/olistview.cpp | 153 | ||||
-rw-r--r-- | libopie2/opieui/olistview.h | 71 |
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,15 +1,15 @@ /* 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. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of @@ -165,50 +165,74 @@ void OListView::serializeTo( QDataStream& s ) const } odebug << "OListview stored." << oendl; } void OListView::serializeFrom( QDataStream& s ) { #warning Caution... the binary format is still under construction... odebug << "loading OListView..." << oendl; int cols; s >> cols; - qDebug( "read number of columns = %d", cols ); + odebug << "read number of columns = " << cols << oendl; while ( columns() < cols ) addColumn( QString::null ); for ( int i = 0; i < cols; ++i ) { QString coltext; s >> coltext; qDebug( "read text '%s' for column %d", (const char*) coltext, i ); setColumnText( i, coltext ); } int items; s >> items; - qDebug( "read number of items = %d", items ); + odebug << "read number of items = " << items << oendl; for ( int i = 0; i < items; ++i ) { OListViewItem* item = childFactory(); s >> *item; } odebug << "OListView loaded." << oendl; } + +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 ) { lv.serializeTo( s ); } QDataStream& operator>>( QDataStream& s, OListView& lv ) { lv.serializeFrom( s ); } #endif // QT_NO_DATASTREAM /*====================================================================================== @@ -436,24 +460,147 @@ QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) lvi.serializeTo( s ); } QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) { lvi.serializeFrom( s ); } #endif // QT_NO_DATASTREAM /*====================================================================================== + * 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 *======================================================================================*/ ONamedListView::ONamedListView( QWidget *parent, const char *name ) :OListView( parent, name ) { } ONamedListView::~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 @@ -1,16 +1,15 @@ /* 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. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of @@ -42,25 +41,25 @@ class OListViewItem; /*====================================================================================== * OListView *======================================================================================*/ /** * @brief A list/tree widget. * * A @ref QListView variant featuring visual and functional enhancements * like an alternate background for odd rows, an autostretch mode * for the width of the widget ( >= Qt 3 only ) and persistence capabilities. * - * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> + * @author Michael 'Mickey' Lauer <mickey@vanille.de> */ class OListView: public QListView { public: /** * Constructor. * * The parameters @a parent and @a name are handled by * @ref QListView, as usual. */ OListView( QWidget* parent = 0, const char* name = 0 ); /** @@ -113,29 +112,39 @@ class OListView: public QListView virtual OListViewItem* childFactory(); #ifndef QT_NO_DATASTREAM /** * Serialize this object to @ref QDataStream @a stream */ virtual void serializeTo( QDataStream& stream ) const; /** * Serialize this object from a @ref QDataStream @a stream */ virtual void serializeFrom( QDataStream& s ); #endif -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*); private: QColor m_alternateBackground; bool m_fullWidth; QPen m_columnSeparator; }; #ifndef QT_NO_DATASTREAM /** * @relates OListView * Writes @a listview to the @a stream and returns a reference to the stream. */ @@ -144,24 +153,25 @@ QDataStream& operator<<( QDataStream& stream, const OListView& listview ); * @relates OListView * Reads @a listview from the @a stream and returns a reference to the stream. */ QDataStream& operator>>( QDataStream& stream, OListView& listview ); #endif // QT_NO_DATASTREAM /*====================================================================================== * OListViewItem *======================================================================================*/ class OListViewItem: public QListViewItem { + friend class OCheckListItem; public: /** * Constructors. */ OListViewItem( QListView * parent ); OListViewItem( QListViewItem * parent ); OListViewItem( QListView * parent, QListViewItem * after ); OListViewItem( QListViewItem * parent, QListViewItem * after ); OListViewItem( QListView * parent, QString, QString = QString::null, QString = QString::null, QString = QString::null, @@ -241,36 +251,81 @@ class OListViewItem: public QListViewItem * @relates QListViewItem * Writes listview @a item and all subitems recursively to @a stream * and returns a reference to the stream. */ QDataStream& operator<<( QDataStream& stream, const OListViewItem& item ); /** * @relates QListViewItem * Reads listview @a item from @a stream and returns a reference to the stream. */ QDataStream& operator>>( QDataStream& stream, OListViewItem& item ); #endif // QT_NO_DATASTREAM + +/*====================================================================================== + * 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; +}; + + /*====================================================================================== * ONamedListView *======================================================================================*/ class ONamedListViewItem; /** * @brief An OListView variant with named columns. * * This class provides a higher-level interface to an OListView. * - * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> + * @author Michael 'Mickey' Lauer <mickey@vanille.de> */ class ONamedListView: public OListView { public: /** * Constructor. * * The parameters @a parent and @a name are handled by * @ref OListView, as usual. */ ONamedListView( QWidget* parent = 0, const char* name = 0 ); /** @@ -301,25 +356,25 @@ class ONamedListView: public OListView virtual ONamedListViewItem* find( const QString& column, const QString& text, int recurse = -1 ) const; }; /*====================================================================================== * ONamedListViewItem *======================================================================================*/ /** * @brief An OListView variant with named columns. * * This class provides a higher-level interface to an OListViewItem. * - * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> + * @author Michael 'Mickey' Lauer <mickey@vanille.de> */ class ONamedListViewItem: public OListViewItem { public: /** * Constructor. Accepts the same parameters as a @ref OListViewItem, * plus a @ref QStringList which holds an arbitrary number of @a texts. */ ONamedListViewItem( QListView* parent, const QStringList& texts ); ONamedListViewItem( QListViewItem* parent, const QStringList& texts ); ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ); ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ); |