summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/olistview.cpp6
-rw-r--r--libopie2/opieui/olistview.h11
2 files changed, 17 insertions, 0 deletions
diff --git a/libopie2/opieui/olistview.cpp b/libopie2/opieui/olistview.cpp
index 8f290d3..ec503dd 100644
--- a/libopie2/opieui/olistview.cpp
+++ b/libopie2/opieui/olistview.cpp
@@ -6,172 +6,178 @@
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31/* QT */ 31/* QT */
32 32
33#include <qcolor.h> 33#include <qcolor.h>
34#include <qheader.h> 34#include <qheader.h>
35#include <qpainter.h> 35#include <qpainter.h>
36#include <qpixmap.h> 36#include <qpixmap.h>
37 37
38/* OPIE */ 38/* OPIE */
39 39
40#include <opie2/olistview.h> 40#include <opie2/olistview.h>
41 41
42/*====================================================================================== 42/*======================================================================================
43 * OListView 43 * OListView
44 *======================================================================================*/ 44 *======================================================================================*/
45 45
46OListView::OListView( QWidget *parent, const char *name ) 46OListView::OListView( QWidget *parent, const char *name )
47 :QListView( parent, name ) 47 :QListView( parent, name )
48{ 48{
49 //FIXME: get from global settings and calculate ==> see oglobalsettings.* 49 //FIXME: get from global settings and calculate ==> see oglobalsettings.*
50 50
51 m_alternateBackground = QColor( 238, 246, 255 ); 51 m_alternateBackground = QColor( 238, 246, 255 );
52 m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine ); 52 m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine );
53 m_fullWidth = true; 53 m_fullWidth = true;
54 connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*)));
54} 55}
55 56
56OListView::~OListView() 57OListView::~OListView()
57{ 58{
58} 59}
59 60
60void OListView::setFullWidth( bool fullWidth ) 61void OListView::setFullWidth( bool fullWidth )
61{ 62{
62 m_fullWidth = m_fullWidth; 63 m_fullWidth = m_fullWidth;
63 #if QT_VERSION > 290 64 #if QT_VERSION > 290
64 header()->setStretchEnabled( fullWidth, columns()-1 ); 65 header()->setStretchEnabled( fullWidth, columns()-1 );
65 #endif 66 #endif
66} 67}
67 68
68bool OListView::fullWidth() const 69bool OListView::fullWidth() const
69{ 70{
70 return m_fullWidth; 71 return m_fullWidth;
71} 72}
72 73
73int OListView::addColumn( const QString& label, int width ) 74int OListView::addColumn( const QString& label, int width )
74{ 75{
75 int result = QListView::addColumn( label, width ); 76 int result = QListView::addColumn( label, width );
76 #if QT_VERSION > 290 77 #if QT_VERSION > 290
77 if (m_fullWidth) { 78 if (m_fullWidth) {
78 header()->setStretchEnabled( false, columns()-2 ); 79 header()->setStretchEnabled( false, columns()-2 );
79 header()->setStretchEnabled( true, columns()-1 ); 80 header()->setStretchEnabled( true, columns()-1 );
80 } 81 }
81 #endif 82 #endif
82 return result; 83 return result;
83} 84}
84 85
85int OListView::addColumn( const QIconSet& iconset, const QString& label, int width ) 86int OListView::addColumn( const QIconSet& iconset, const QString& label, int width )
86{ 87{
87 int result = QListView::addColumn( iconset, label, width ); 88 int result = QListView::addColumn( iconset, label, width );
88 #if QT_VERSION > 290 89 #if QT_VERSION > 290
89 if (m_fullWidth) { 90 if (m_fullWidth) {
90 header()->setStretchEnabled( false, columns()-2 ); 91 header()->setStretchEnabled( false, columns()-2 );
91 header()->setStretchEnabled( true, columns()-1 ); 92 header()->setStretchEnabled( true, columns()-1 );
92 } 93 }
93 #endif 94 #endif
94 return result; 95 return result;
95} 96}
96 97
97void OListView::removeColumn( int index ) 98void OListView::removeColumn( int index )
98{ 99{
99 QListView::removeColumn(index); 100 QListView::removeColumn(index);
100 #if QT_VERSION > 290 101 #if QT_VERSION > 290
101 if ( m_fullWidth && index == columns() ) 102 if ( m_fullWidth && index == columns() )
102 { 103 {
103 header()->setStretchEnabled( true, columns()-1 ); 104 header()->setStretchEnabled( true, columns()-1 );
104 } 105 }
105 #endif 106 #endif
106} 107}
107 108
108const QColor& OListView::alternateBackground() const 109const QColor& OListView::alternateBackground() const
109{ 110{
110 return m_alternateBackground; 111 return m_alternateBackground;
111} 112}
112 113
113void OListView::setAlternateBackground( const QColor &c ) 114void OListView::setAlternateBackground( const QColor &c )
114{ 115{
115 m_alternateBackground = c; 116 m_alternateBackground = c;
116 repaint(); 117 repaint();
117} 118}
118 119
119const QPen& OListView::columnSeparator() const 120const QPen& OListView::columnSeparator() const
120{ 121{
121 return m_columnSeparator; 122 return m_columnSeparator;
122} 123}
123 124
124void OListView::setColumnSeparator( const QPen& p ) 125void OListView::setColumnSeparator( const QPen& p )
125{ 126{
126 m_columnSeparator = p; 127 m_columnSeparator = p;
127 repaint(); 128 repaint();
128} 129}
129 130
131void OListView::expand(QListViewItem *item)
132{
133 ((OListViewItem*)item)->expand();
134}
135
130OListViewItem* OListView::childFactory() 136OListViewItem* OListView::childFactory()
131{ 137{
132 return new OListViewItem( this ); 138 return new OListViewItem( this );
133} 139}
134 140
135#ifndef QT_NO_DATASTREAM 141#ifndef QT_NO_DATASTREAM
136void OListView::serializeTo( QDataStream& s ) const 142void OListView::serializeTo( QDataStream& s ) const
137{ 143{
138 #warning Caution... the binary format is still under construction... 144 #warning Caution... the binary format is still under construction...
139 qDebug( "storing OListView..." ); 145 qDebug( "storing OListView..." );
140 146
141 // store number of columns and the labels 147 // store number of columns and the labels
142 s << columns(); 148 s << columns();
143 for ( int i = 0; i < columns(); ++i ) 149 for ( int i = 0; i < columns(); ++i )
144 s << columnText( i ); 150 s << columnText( i );
145 151
146 // calculate the number of top-level items to serialize 152 // calculate the number of top-level items to serialize
147 int items = 0; 153 int items = 0;
148 QListViewItem* item = firstChild(); 154 QListViewItem* item = firstChild();
149 while ( item ) 155 while ( item )
150 { 156 {
151 item = item->nextSibling(); 157 item = item->nextSibling();
152 items++; 158 items++;
153 } 159 }
154 160
155 // store number of items and the items itself 161 // store number of items and the items itself
156 s << items; 162 s << items;
157 item = firstChild(); 163 item = firstChild();
158 for ( int i = 0; i < items; ++i ) 164 for ( int i = 0; i < items; ++i )
159 { 165 {
160 s << *static_cast<OListViewItem*>( item ); 166 s << *static_cast<OListViewItem*>( item );
161 item = item->nextSibling(); 167 item = item->nextSibling();
162 } 168 }
163 169
164 qDebug( "OListview stored." ); 170 qDebug( "OListview stored." );
165} 171}
166 172
167void OListView::serializeFrom( QDataStream& s ) 173void OListView::serializeFrom( QDataStream& s )
168{ 174{
169 #warning Caution... the binary format is still under construction... 175 #warning Caution... the binary format is still under construction...
170 qDebug( "loading OListView..." ); 176 qDebug( "loading OListView..." );
171 177
172 int cols; 178 int cols;
173 s >> cols; 179 s >> cols;
174 qDebug( "read number of columns = %d", cols ); 180 qDebug( "read number of columns = %d", cols );
175 181
176 while ( columns() < cols ) addColumn( QString::null ); 182 while ( columns() < cols ) addColumn( QString::null );
177 183
diff --git a/libopie2/opieui/olistview.h b/libopie2/opieui/olistview.h
index 109e309..a00b43a 100644
--- a/libopie2/opieui/olistview.h
+++ b/libopie2/opieui/olistview.h
@@ -77,96 +77,102 @@ class OListView: public QListView
77 bool fullWidth() const; 77 bool fullWidth() const;
78 /** 78 /**
79 * Reimplemented for full width support 79 * Reimplemented for full width support
80 */ 80 */
81 virtual int addColumn( const QString& label, int width = -1 ); 81 virtual int addColumn( const QString& label, int width = -1 );
82 /** 82 /**
83 * Reimplemented for full width support 83 * Reimplemented for full width support
84 */ 84 */
85 virtual int addColumn( const QIconSet& iconset, const QString& label, int width = -1 ); 85 virtual int addColumn( const QIconSet& iconset, const QString& label, int width = -1 );
86 /** 86 /**
87 * Reimplemented for full width support 87 * Reimplemented for full width support
88 */ 88 */
89 virtual void removeColumn(int index); 89 virtual void removeColumn(int index);
90 /** 90 /**
91 * Set the alternate background background @a color. 91 * Set the alternate background background @a color.
92 * Set to an invalid color to disable alternate colors. 92 * Set to an invalid color to disable alternate colors.
93 * This only has an effect if the items are OListViewItems 93 * This only has an effect if the items are OListViewItems
94 */ 94 */
95 void setAlternateBackground( const QColor& color ); 95 void setAlternateBackground( const QColor& color );
96 /** 96 /**
97 * Sets the column separator @a pen. 97 * Sets the column separator @a pen.
98 */ 98 */
99 void setColumnSeparator( const QPen& pen ); 99 void setColumnSeparator( const QPen& pen );
100 100
101 /** 101 /**
102 * @returns the alternate background color 102 * @returns the alternate background color
103 */ 103 */
104 const QColor& alternateBackground() const; 104 const QColor& alternateBackground() const;
105 /** 105 /**
106 * @return the column separator pen 106 * @return the column separator pen
107 */ 107 */
108 const QPen& columnSeparator() const; 108 const QPen& columnSeparator() const;
109 /** 109 /**
110 * Create a list view item as child of this object 110 * Create a list view item as child of this object
111 * @returns the new object 111 * @returns the new object
112 */ 112 */
113 virtual OListViewItem* childFactory(); 113 virtual OListViewItem* childFactory();
114#ifndef QT_NO_DATASTREAM 114#ifndef QT_NO_DATASTREAM
115 /** 115 /**
116 * Serialize this object to @ref QDataStream @a stream 116 * Serialize this object to @ref QDataStream @a stream
117 */ 117 */
118 virtual void serializeTo( QDataStream& stream ) const; 118 virtual void serializeTo( QDataStream& stream ) const;
119 /** 119 /**
120 * Serialize this object from a @ref QDataStream @a stream 120 * Serialize this object from a @ref QDataStream @a stream
121 */ 121 */
122 virtual void serializeFrom( QDataStream& s ); 122 virtual void serializeFrom( QDataStream& s );
123#endif 123#endif
124 124
125protected slots:
126 /**
127 * expand the current OListViewItem
128 */
129 void expand(QListViewItem*);
130
125 private: 131 private:
126 QColor m_alternateBackground; 132 QColor m_alternateBackground;
127 bool m_fullWidth; 133 bool m_fullWidth;
128 QPen m_columnSeparator; 134 QPen m_columnSeparator;
129}; 135};
130 136
131#ifndef QT_NO_DATASTREAM 137#ifndef QT_NO_DATASTREAM
132/** 138/**
133 * @relates OListView 139 * @relates OListView
134 * Writes @a listview to the @a stream and returns a reference to the stream. 140 * Writes @a listview to the @a stream and returns a reference to the stream.
135 */ 141 */
136QDataStream& operator<<( QDataStream& stream, const OListView& listview ); 142QDataStream& operator<<( QDataStream& stream, const OListView& listview );
137/** 143/**
138 * @relates OListView 144 * @relates OListView
139 * Reads @a listview from the @a stream and returns a reference to the stream. 145 * Reads @a listview from the @a stream and returns a reference to the stream.
140 */ 146 */
141QDataStream& operator>>( QDataStream& stream, OListView& listview ); 147QDataStream& operator>>( QDataStream& stream, OListView& listview );
142#endif // QT_NO_DATASTREAM 148#endif // QT_NO_DATASTREAM
143 149
144/*====================================================================================== 150/*======================================================================================
145 * OListViewItem 151 * OListViewItem
146 *======================================================================================*/ 152 *======================================================================================*/
147 153
148class OListViewItem: public QListViewItem 154class OListViewItem: public QListViewItem
149{ 155{
150 public: 156 public:
151 /** 157 /**
152 * Constructors. 158 * Constructors.
153 */ 159 */
154 OListViewItem( QListView * parent ); 160 OListViewItem( QListView * parent );
155 OListViewItem( QListViewItem * parent ); 161 OListViewItem( QListViewItem * parent );
156 OListViewItem( QListView * parent, QListViewItem * after ); 162 OListViewItem( QListView * parent, QListViewItem * after );
157 OListViewItem( QListViewItem * parent, QListViewItem * after ); 163 OListViewItem( QListViewItem * parent, QListViewItem * after );
158 164
159 OListViewItem( QListView * parent, 165 OListViewItem( QListView * parent,
160 QString, QString = QString::null, 166 QString, QString = QString::null,
161 QString = QString::null, QString = QString::null, 167 QString = QString::null, QString = QString::null,
162 QString = QString::null, QString = QString::null, 168 QString = QString::null, QString = QString::null,
163 QString = QString::null, QString = QString::null ); 169 QString = QString::null, QString = QString::null );
164 170
165 OListViewItem( QListViewItem * parent, 171 OListViewItem( QListViewItem * parent,
166 QString, QString = QString::null, 172 QString, QString = QString::null,
167 QString = QString::null, QString = QString::null, 173 QString = QString::null, QString = QString::null,
168 QString = QString::null, QString = QString::null, 174 QString = QString::null, QString = QString::null,
169 QString = QString::null, QString = QString::null ); 175 QString = QString::null, QString = QString::null );
170 176
171 OListViewItem( QListView * parent, QListViewItem * after, 177 OListViewItem( QListView * parent, QListViewItem * after,
172 QString, QString = QString::null, 178 QString, QString = QString::null,
@@ -175,96 +181,101 @@ class OListViewItem: public QListViewItem
175 QString = QString::null, QString = QString::null ); 181 QString = QString::null, QString = QString::null );
176 182
177 OListViewItem( QListViewItem * parent, QListViewItem * after, 183 OListViewItem( QListViewItem * parent, QListViewItem * after,
178 QString, QString = QString::null, 184 QString, QString = QString::null,
179 QString = QString::null, QString = QString::null, 185 QString = QString::null, QString = QString::null,
180 QString = QString::null, QString = QString::null, 186 QString = QString::null, QString = QString::null,
181 QString = QString::null, QString = QString::null ); 187 QString = QString::null, QString = QString::null );
182 /** 188 /**
183 * Destructor. 189 * Destructor.
184 */ 190 */
185 virtual ~OListViewItem(); 191 virtual ~OListViewItem();
186 /** 192 /**
187 * @returns the background color of the list item. 193 * @returns the background color of the list item.
188 */ 194 */
189 const QColor& backgroundColor(); 195 const QColor& backgroundColor();
190 /** 196 /**
191 * @returns true, if the item is at an odd position and 197 * @returns true, if the item is at an odd position and
192 * thus have to be painted with the alternate background color. 198 * thus have to be painted with the alternate background color.
193 */ 199 */
194 bool isAlternate(); 200 bool isAlternate();
195 /** 201 /**
196 * @note: Reimplemented for internal purposes - the API is not affected 202 * @note: Reimplemented for internal purposes - the API is not affected
197 * 203 *
198 */ 204 */
199 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); 205 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment );
200 /** 206 /**
201 * Perform object initialization. 207 * Perform object initialization.
202 */ 208 */
203 void init(); 209 void init();
204 /** 210 /**
205 * create a list view item as child of this object 211 * create a list view item as child of this object
206 * @returns the new object 212 * @returns the new object
207 */ 213 */
208 virtual OListViewItem* childFactory(); 214 virtual OListViewItem* childFactory();
209 #ifndef QT_NO_DATASTREAM 215 #ifndef QT_NO_DATASTREAM
210 /** 216 /**
211 * serialize this object to or from a @ref QDataStream 217 * serialize this object to or from a @ref QDataStream
212 * @param s the stream used to serialize this object. 218 * @param s the stream used to serialize this object.
213 */ 219 */
214 virtual void serializeTo( QDataStream& s ) const; 220 virtual void serializeTo( QDataStream& s ) const;
215 221
216 /** 222 /**
217 * serialize this object to or from a @ref QDataStream 223 * serialize this object to or from a @ref QDataStream
218 * @param s the stream used to serialize this object. 224 * @param s the stream used to serialize this object.
219 */ 225 */
220 virtual void serializeFrom( QDataStream& s ); 226 virtual void serializeFrom( QDataStream& s );
221 #endif 227 #endif
222 228
229 /**
230 * expand the the item
231 */
232 virtual void expand(){};
233
223 private: 234 private:
224 bool m_known; 235 bool m_known;
225 bool m_odd; 236 bool m_odd;
226}; 237};
227 238
228#ifndef QT_NO_DATASTREAM 239#ifndef QT_NO_DATASTREAM
229/** 240/**
230 * @relates QListViewItem 241 * @relates QListViewItem
231 * Writes listview @a item and all subitems recursively to @a stream 242 * Writes listview @a item and all subitems recursively to @a stream
232 * and returns a reference to the stream. 243 * and returns a reference to the stream.
233 */ 244 */
234QDataStream& operator<<( QDataStream& stream, const OListViewItem& item ); 245QDataStream& operator<<( QDataStream& stream, const OListViewItem& item );
235/** 246/**
236 * @relates QListViewItem 247 * @relates QListViewItem
237 * Reads listview @a item from @a stream and returns a reference to the stream. 248 * Reads listview @a item from @a stream and returns a reference to the stream.
238 */ 249 */
239QDataStream& operator>>( QDataStream& stream, OListViewItem& item ); 250QDataStream& operator>>( QDataStream& stream, OListViewItem& item );
240#endif // QT_NO_DATASTREAM 251#endif // QT_NO_DATASTREAM
241 252
242/*====================================================================================== 253/*======================================================================================
243 * ONamedListView 254 * ONamedListView
244 *======================================================================================*/ 255 *======================================================================================*/
245 256
246class ONamedListViewItem; 257class ONamedListViewItem;
247 258
248/** 259/**
249 * @brief An OListView variant with named columns. 260 * @brief An OListView variant with named columns.
250 * 261 *
251 * This class provides a higher-level interface to an OListView. 262 * This class provides a higher-level interface to an OListView.
252 * 263 *
253 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 264 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
254 */ 265 */
255class ONamedListView: public OListView 266class ONamedListView: public OListView
256{ 267{
257 public: 268 public:
258 /** 269 /**
259 * Constructor. 270 * Constructor.
260 * 271 *
261 * The parameters @a parent and @a name are handled by 272 * The parameters @a parent and @a name are handled by
262 * @ref OListView, as usual. 273 * @ref OListView, as usual.
263 */ 274 */
264 ONamedListView( QWidget* parent = 0, const char* name = 0 ); 275 ONamedListView( QWidget* parent = 0, const char* name = 0 );
265 /** 276 /**
266 * Destructor. 277 * Destructor.
267 */ 278 */
268 virtual ~ONamedListView(); 279 virtual ~ONamedListView();
269 /** 280 /**
270 * Add a number of @a columns to the listview. 281 * Add a number of @a columns to the listview.