-rw-r--r-- | libopie2/opieui/olistview.cpp | 109 | ||||
-rw-r--r-- | libopie2/opieui/olistview.h | 177 |
2 files changed, 235 insertions, 51 deletions
diff --git a/libopie2/opieui/olistview.cpp b/libopie2/opieui/olistview.cpp index 2b2f09a..8f97cc6 100644 --- a/libopie2/opieui/olistview.cpp +++ b/libopie2/opieui/olistview.cpp @@ -219,4 +219,5 @@ OListViewItem::OListViewItem(QListView *parent) } + OListViewItem::OListViewItem(QListViewItem *parent) : QListViewItem(parent) @@ -225,4 +226,5 @@ OListViewItem::OListViewItem(QListViewItem *parent) } + OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) : QListViewItem(parent, after) @@ -231,4 +233,5 @@ OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) } + OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) : QListViewItem(parent, after) @@ -237,4 +240,5 @@ OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) } + OListViewItem::OListViewItem(QListView *parent, QString label1, QString label2, QString label3, QString label4, @@ -245,4 +249,5 @@ OListViewItem::OListViewItem(QListView *parent, } + OListViewItem::OListViewItem(QListViewItem *parent, QString label1, QString label2, QString label3, QString label4, @@ -253,4 +258,5 @@ OListViewItem::OListViewItem(QListViewItem *parent, } + OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, QString label1, QString label2, QString label3, QString label4, @@ -261,4 +267,5 @@ OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, } + OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, QString label1, QString label2, QString label3, QString label4, @@ -269,8 +276,10 @@ OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, } + OListViewItem::~OListViewItem() { } + void OListViewItem::init() { @@ -278,4 +287,5 @@ void OListViewItem::init() } + const QColor &OListViewItem::backgroundColor() { @@ -284,4 +294,5 @@ const QColor &OListViewItem::backgroundColor() } + bool OListViewItem::isAlternate() { @@ -327,4 +338,5 @@ bool OListViewItem::isAlternate() } + void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) { @@ -349,4 +361,5 @@ void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, in } + OListViewItem* OListViewItem::childFactory() { @@ -354,4 +367,5 @@ OListViewItem* OListViewItem::childFactory() } + #ifndef QT_NO_DATASTREAM void OListViewItem::serializeTo( QDataStream& s ) const @@ -386,4 +400,6 @@ void OListViewItem::serializeTo( QDataStream& s ) const qDebug( "OListviewItem stored." ); } + + void OListViewItem::serializeFrom( QDataStream& s ) { @@ -412,4 +428,5 @@ void OListViewItem::serializeFrom( QDataStream& s ) } + QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) { @@ -417,4 +434,5 @@ QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) } + QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) { @@ -422,2 +440,93 @@ QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) } #endif // QT_NO_DATASTREAM + + +/*====================================================================================== + * ONamedListView + *======================================================================================*/ + +ONamedListView::ONamedListView( QWidget *parent, const char *name ) + :OListView( parent, name ) +{ +} + + +ONamedListView::~ONamedListView() +{ +} + + +void ONamedListView::addColumns( const QStringList& columns ) +{ + for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it ) + { + qDebug( "adding column %s", (const char*) *it ); + addColumn( *it ); + } +} + + +/*====================================================================================== + * ONamedListViewItem + *======================================================================================*/ + +ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts ) + :OListViewItem( parent ) +{ + setText( texts ); +} + + +ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts ) + :OListViewItem( parent ) +{ + setText( texts ); +} + + +ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ) + :OListViewItem( parent, after ) +{ + setText( texts ); +} + + +ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ) + :OListViewItem( parent, after ) +{ + setText( texts ); +} + + +ONamedListViewItem::~ONamedListViewItem() +{ +} + + +void ONamedListViewItem::setText( const QStringList& texts ) +{ + int col = 0; + for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it ) + { + qDebug( "setting column %d = text %s", col, (const char*) *it ); + OListViewItem::setText( col++, *it ); + } + +} + + +void ONamedListViewItem::setText( const QString& column, const QString& text ) +{ + //FIXME: If used excessively, this will slow down performance of updates + //FIXME: because of the linear search over all column texts. + //FIXME: I will optimize later by using a hash map. + for ( int i = 0; i < listView()->columns(); ++i ) + { + if ( listView()->columnText( i ) == column ) + { + OListViewItem::setText( i, text ); + return; + } + } + qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column ); +} diff --git a/libopie2/opieui/olistview.h b/libopie2/opieui/olistview.h index b62e278..99770bf 100644 --- a/libopie2/opieui/olistview.h +++ b/libopie2/opieui/olistview.h @@ -39,5 +39,11 @@ 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 @@ -45,7 +51,6 @@ class OListViewItem; * * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> - * @short OListView list/tree widget. */ - class OListView: public QListView +class OListView: public QListView { public: @@ -53,81 +58,63 @@ class OListViewItem; * Constructor. * - * The parameters @p parent and @p name are handled by + * The parameters @a parent and @a name are handled by * @ref QListView, as usual. */ - OListView ( QWidget *parent = 0, const char *name = 0 ); - + OListView( QWidget* parent = 0, const char* name = 0 ); /** * Destructor. */ virtual ~OListView(); - /** * Let the last column fit exactly all the available width. */ void setFullWidth( bool fullWidth ); - /** * Returns whether the last column is set to fit the available width. */ bool fullWidth() const; - /** * Reimplemented for full width support */ virtual int addColumn( const QString& label, int width = -1 ); - /** * Reimplemented for full width support */ virtual int addColumn( const QIconSet& iconset, const QString& label, int width = -1 ); - /** * Reimplemented for full width support */ virtual void removeColumn(int index); - /** - * sets the alternate background background color. + * Set the alternate background background @a color. + * Set to an invalid color to disable alternate colors. * This only has an effect if the items are OListViewItems - * - * @param c the color to use for every other item. Set to an invalid - * color to disable alternate colors. */ - void setAlternateBackground( const QColor &c ); - + void setAlternateBackground( const QColor& color ); /** - * sets the column separator pen. - * - * @param p the pen used to draw the column separator. + * Sets the column separator @a pen. */ - void setColumnSeparator( const QPen &p ); + void setColumnSeparator( const QPen& pen ); /** - * @return the alternate background color + * @returns the alternate background color */ const QColor& alternateBackground() const; - /** * @return the column separator pen */ const QPen& columnSeparator() const; - /** - * create a list view item as child of this object - * @return the new object + * Create a list view item as child of this object + * @returns the new object */ virtual OListViewItem* childFactory(); - #ifndef QT_NO_DATASTREAM /** - * serialize this object to a @ref QDataStream - * @param s the stream used to serialize this object. + * Serialize this object to @ref QDataStream @a stream */ - virtual void serializeTo( QDataStream& s ) const; - + virtual void serializeTo( QDataStream& stream ) const; /** - * serialize this object from a @ref QDataStream - * @param s the stream used to serialize this object. + * Serialize this object from a @ref QDataStream @a stream */ virtual void serializeFrom( QDataStream& s ); @@ -142,20 +129,25 @@ class OListViewItem; #ifndef QT_NO_DATASTREAM /** - * \relates QListView - * Writes a listview to the stream and returns a reference to the stream. + * @relates OListView + * Writes @a listview to the @a stream and returns a reference to the stream. */ -QDataStream& operator<<( QDataStream& s, const OListView& lv ); +QDataStream& operator<<( QDataStream& stream, const OListView& listview ); /** - * \relates QListView - * Reads a listview from the stream and returns a reference to the stream. + * @relates OListView + * Reads @a listview from the @a stream and returns a reference to the stream. */ -QDataStream& operator>>( QDataStream& s, OListView& lv ); +QDataStream& operator>>( QDataStream& stream, OListView& listview ); #endif // QT_NO_DATASTREAM -//****************************** OListViewItem ****************************************************************** +/*====================================================================================== + * OListViewItem + *======================================================================================*/ class OListViewItem: public QListViewItem { public: + /** + * Constructors. + */ OListViewItem( QListView * parent ); OListViewItem( QListViewItem * parent ); @@ -186,18 +178,31 @@ class OListViewItem: public QListViewItem QString = QString::null, QString = QString::null, QString = QString::null, QString = QString::null ); - + /** + * Destructor. + */ virtual ~OListViewItem(); - + /** + * @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(); - /** * create a list view item as child of this object - * @return the new object + * @returns the new object */ virtual OListViewItem* childFactory(); - #ifndef QT_NO_DATASTREAM /** @@ -221,15 +226,85 @@ class OListViewItem: public QListViewItem #ifndef QT_NO_DATASTREAM /** - * \relates QListViewItem - * Writes a listview item and all subitems recursively to the stream + * @relates QListViewItem + * Writes listview @a item and all subitems recursively to @a stream * and returns a reference to the stream. */ -QDataStream& operator<<( QDataStream &s, const OListViewItem& lvi ); +QDataStream& operator<<( QDataStream& stream, const OListViewItem& item ); /** - * \relates QListViewItem - * Reads a listview item from the stream and returns a reference to the stream. + * @relates QListViewItem + * Reads listview @a item from @a stream and returns a reference to the stream. */ -QDataStream& operator>>( QDataStream &s, OListViewItem& lvi ); +QDataStream& operator>>( QDataStream& stream, OListViewItem& item ); #endif // QT_NO_DATASTREAM +/*====================================================================================== + * ONamedListView + *======================================================================================*/ + +/** + * @brief An OListView variant with named columns. + * + * This class provides a higher-level interface to the columns in an OListView. + * + * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.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 ); + /** + * Destructor. + */ + virtual ~ONamedListView(); + /** + * Add a number of @a columns to the listview. + */ + virtual void addColumns( const QStringList& columns ); +}; + +/*====================================================================================== + * ONamedListViewItem + *======================================================================================*/ + +/** + * @brief An OListView variant with named columns. + * + * This class provides a higher-level interface to the columns in an OListViewItem. + * + * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.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 ); + /** + * Destructor. + */ + virtual ~ONamedListViewItem(); + /** + * Sets the text in column @a column to @a text. + * This method differs from @ref QListViewItem::setText() in that it + * accepts a string as column indicator instead of an int. + */ + virtual void setText( const QString& column, const QString& text ); + /** + * Sets a number of @a texts for this item. + */ + virtual void setText( const QStringList& texts ); +}; + + #endif // OLISTVIEW_H |