author | mickeyl <mickeyl> | 2003-05-01 14:00:37 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-05-01 14:00:37 (UTC) |
commit | 95e533a6ac257d3b95cd8905660008fb7dcd33f1 (patch) (side-by-side diff) | |
tree | c671954f59eaa70db2285f9abe49fd8b4512dd12 | |
parent | 1d721ddb247e9000e29fba3150e0cce5f59f543e (diff) | |
download | opie-95e533a6ac257d3b95cd8905660008fb7dcd33f1.zip opie-95e533a6ac257d3b95cd8905660008fb7dcd33f1.tar.gz opie-95e533a6ac257d3b95cd8905660008fb7dcd33f1.tar.bz2 |
- restructure opieui example directory
- start work on ONamedListViewItem providing a slightly higher level interface
-rw-r--r-- | libopie2/examples/opieui/olistviewdemo/.cvsignore | 8 | ||||
-rw-r--r-- | libopie2/examples/opieui/olistviewdemo/main.cpp | 26 | ||||
-rw-r--r-- | libopie2/examples/opieui/olistviewdemo/olistviewdemo.cpp | 54 | ||||
-rw-r--r-- | libopie2/examples/opieui/olistviewdemo/olistviewdemo.h | 51 | ||||
-rw-r--r-- | libopie2/examples/opieui/olistviewdemo/olistviewdemo.pro (copied from libopie2/examples/opieui/oversatileviewdemo/opieui.pro) | 8 | ||||
-rw-r--r-- | libopie2/examples/opieui/opieui.pro | 3 | ||||
-rw-r--r-- | libopie2/examples/opieui/oversatileviewdemo/oversatileviewdemo.pro (renamed from libopie2/examples/opieui/oversatileviewdemo/opieui.pro) | 0 | ||||
-rw-r--r-- | libopie2/opieui/olistview.cpp | 109 | ||||
-rw-r--r-- | libopie2/opieui/olistview.h | 177 |
9 files changed, 380 insertions, 56 deletions
diff --git a/libopie2/examples/opieui/olistviewdemo/.cvsignore b/libopie2/examples/opieui/olistviewdemo/.cvsignore new file mode 100644 index 0000000..1317f7e --- a/dev/null +++ b/libopie2/examples/opieui/olistviewdemo/.cvsignore @@ -0,0 +1,8 @@ +Makefile* +moc* +*moc +*.o +~* +moc +obj + diff --git a/libopie2/examples/opieui/olistviewdemo/main.cpp b/libopie2/examples/opieui/olistviewdemo/main.cpp new file mode 100644 index 0000000..a93f361 --- a/dev/null +++ b/libopie2/examples/opieui/olistviewdemo/main.cpp @@ -0,0 +1,26 @@ +/********************************************************************** +** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. +** +** This file is part of Opie Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +**********************************************************************/ + +#include "olistviewdemo.h" +#include <opie2/oapplication.h> + +int main( int argc, char **argv ) +{ + OApplication a( argc, argv, "OListViewDemo" ); + OListViewDemo e; + a.showMainWidget(&e); + return a.exec(); +} + diff --git a/libopie2/examples/opieui/olistviewdemo/olistviewdemo.cpp b/libopie2/examples/opieui/olistviewdemo/olistviewdemo.cpp new file mode 100644 index 0000000..31bda9d --- a/dev/null +++ b/libopie2/examples/opieui/olistviewdemo/olistviewdemo.cpp @@ -0,0 +1,54 @@ +/* + This file is part of the Opie Project + + Copyright (C) 2003 Michael 'Mickey' Lauer + <mickey@tm.informatik.uni-frankfurt.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 + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + +*/ + +#include "olistviewdemo.h" +#include <opie2/olistview.h> + +#include <qstring.h> +#include <qpixmap.h> +#include <qlistview.h> + +OListViewDemo::OListViewDemo( QWidget* parent, const char* name, WFlags f ) + :QVBox( parent, name, f ) +{ + lv = new ONamedListView( this ); + lv->addColumns( QStringList::split( ' ', "Column1 Column2 Column3 Column4" ) ); + + ONamedListViewItem* item = new ONamedListViewItem( lv, QStringList::split( ' ', "Text1 Text2 Text3 Text4" ) ); + item->setText( "Column2", "ModifiedText" ); + item->setText( "Column5", "ThisColumnDoesNotExits" ); +} + +OListViewDemo::~OListViewDemo() +{ +} + diff --git a/libopie2/examples/opieui/olistviewdemo/olistviewdemo.h b/libopie2/examples/opieui/olistviewdemo/olistviewdemo.h new file mode 100644 index 0000000..8a5986a --- a/dev/null +++ b/libopie2/examples/opieui/olistviewdemo/olistviewdemo.h @@ -0,0 +1,51 @@ +/* + This file is part of the Opie Project + + Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.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 + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + +*/ + +#ifndef OLISTVIEWDEMO_H +#define OLISTVIEWDEMO_H + +#include <qvbox.h> +#include <opie2/olistview.h> + +class OListViewDemo: public QVBox +{ + Q_OBJECT + + public: + OListViewDemo( QWidget* parent=0, const char* name=0, WFlags f=0 ); + virtual ~OListViewDemo(); + + private: + ONamedListView* lv; + +}; + +#endif diff --git a/libopie2/examples/opieui/oversatileviewdemo/opieui.pro b/libopie2/examples/opieui/olistviewdemo/olistviewdemo.pro index 8ad5fc9..aabe733 100644 --- a/libopie2/examples/opieui/oversatileviewdemo/opieui.pro +++ b/libopie2/examples/opieui/olistviewdemo/olistviewdemo.pro @@ -2,6 +2,4 @@ TEMPLATE = app CONFIG = qt warn_on debug -HEADERS = opieuidemo.h \ - oversatileviewdemo.h -SOURCES = opieuidemo.cpp \ - oversatileviewdemo.cpp \ +HEADERS = olistviewdemo.h +SOURCES = olistviewdemo.cpp \ main.cpp @@ -10,3 +8,3 @@ DEPENDPATH += $(OPIEDIR)/include LIBS += -lopieui2 -lopiecore2 -TARGET = opieuidemo +TARGET = olistviewdemo MOC_DIR = moc diff --git a/libopie2/examples/opieui/opieui.pro b/libopie2/examples/opieui/opieui.pro new file mode 100644 index 0000000..b52f013 --- a/dev/null +++ b/libopie2/examples/opieui/opieui.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS = olistviewdemo oversatileviewdemo + diff --git a/libopie2/examples/opieui/oversatileviewdemo/opieui.pro b/libopie2/examples/opieui/oversatileviewdemo/oversatileviewdemo.pro index 8ad5fc9..8ad5fc9 100644 --- a/libopie2/examples/opieui/oversatileviewdemo/opieui.pro +++ b/libopie2/examples/opieui/oversatileviewdemo/oversatileviewdemo.pro 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 @@ -220,2 +220,3 @@ OListViewItem::OListViewItem(QListView *parent) + OListViewItem::OListViewItem(QListViewItem *parent) @@ -226,2 +227,3 @@ OListViewItem::OListViewItem(QListViewItem *parent) + OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) @@ -232,2 +234,3 @@ OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) + OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) @@ -238,2 +241,3 @@ OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) + OListViewItem::OListViewItem(QListView *parent, @@ -246,2 +250,3 @@ OListViewItem::OListViewItem(QListView *parent, + OListViewItem::OListViewItem(QListViewItem *parent, @@ -254,2 +259,3 @@ OListViewItem::OListViewItem(QListViewItem *parent, + OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, @@ -262,2 +268,3 @@ OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, + OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, @@ -270,2 +277,3 @@ OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, + OListViewItem::~OListViewItem() @@ -274,2 +282,3 @@ OListViewItem::~OListViewItem() + void OListViewItem::init() @@ -279,2 +288,3 @@ void OListViewItem::init() + const QColor &OListViewItem::backgroundColor() @@ -285,2 +295,3 @@ const QColor &OListViewItem::backgroundColor() + bool OListViewItem::isAlternate() @@ -328,2 +339,3 @@ bool OListViewItem::isAlternate() + void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) @@ -350,2 +362,3 @@ void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, in + OListViewItem* OListViewItem::childFactory() @@ -355,2 +368,3 @@ OListViewItem* OListViewItem::childFactory() + #ifndef QT_NO_DATASTREAM @@ -387,2 +401,4 @@ void OListViewItem::serializeTo( QDataStream& s ) const } + + void OListViewItem::serializeFrom( QDataStream& s ) @@ -413,2 +429,3 @@ void OListViewItem::serializeFrom( QDataStream& s ) + QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) @@ -418,2 +435,3 @@ QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) + QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) @@ -423 +441,92 @@ 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 @@ -40,3 +40,9 @@ class OListViewItem; +/*====================================================================================== + * OListView + *======================================================================================*/ + /** + * @brief A list/tree widget. + * * A @ref QListView variant featuring visual and functional enhancements @@ -46,5 +52,4 @@ 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 { @@ -54,7 +59,6 @@ class OListViewItem; * - * 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 ); /** @@ -63,3 +67,2 @@ class OListViewItem; virtual ~OListView(); - /** @@ -68,3 +71,2 @@ class OListViewItem; void setFullWidth( bool fullWidth ); - /** @@ -73,3 +75,2 @@ class OListViewItem; bool fullWidth() const; - /** @@ -78,3 +79,2 @@ class OListViewItem; virtual int addColumn( const QString& label, int width = -1 ); - /** @@ -83,3 +83,2 @@ class OListViewItem; virtual int addColumn( const QIconSet& iconset, const QString& label, int width = -1 ); - /** @@ -88,24 +87,17 @@ class OListViewItem; 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; - /** @@ -114,19 +106,14 @@ class OListViewItem; 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 */ @@ -143,14 +130,16 @@ class OListViewItem; /** - * \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 + *======================================================================================*/ @@ -159,2 +148,5 @@ class OListViewItem: public QListViewItem public: + /** + * Constructors. + */ OListViewItem( QListView * parent ); @@ -187,16 +179,29 @@ class OListViewItem: public QListViewItem 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 @@ -222,14 +227,84 @@ class OListViewItem: public QListViewItem /** - * \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 |