summaryrefslogtreecommitdiff
path: root/libopie2/opieui/olistview.cpp
authormickeyl <mickeyl>2003-03-28 15:11:52 (UTC)
committer mickeyl <mickeyl>2003-03-28 15:11:52 (UTC)
commit11304d02942e9fa493e4e80943a828f9c65f6772 (patch) (unidiff)
treea0223c10c067e1afc70d15c2b82be3f3c15e41ae /libopie2/opieui/olistview.cpp
parentb271d575fa05cf570a1a829136517761bd47e69b (diff)
downloadopie-11304d02942e9fa493e4e80943a828f9c65f6772.zip
opie-11304d02942e9fa493e4e80943a828f9c65f6772.tar.gz
opie-11304d02942e9fa493e4e80943a828f9c65f6772.tar.bz2
skeleton and the start of libopie2, please read README, ROADMAP and STATUS and comment...
Diffstat (limited to 'libopie2/opieui/olistview.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opieui/olistview.cpp423
1 files changed, 423 insertions, 0 deletions
diff --git a/libopie2/opieui/olistview.cpp b/libopie2/opieui/olistview.cpp
new file mode 100644
index 0000000..2b2f09a
--- a/dev/null
+++ b/libopie2/opieui/olistview.cpp
@@ -0,0 +1,423 @@
1/*
2                 This file is part of the Opie Project
3
4 =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 .=l.
6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details.
21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28
29*/
30
31/* QT */
32
33#include <qcolor.h>
34#include <qheader.h>
35#include <qpainter.h>
36#include <qpixmap.h>
37
38/* OPIE */
39
40#include <opie2/olistview.h>
41
42/*======================================================================================
43 * OListView
44 *======================================================================================*/
45
46OListView::OListView( QWidget *parent, const char *name )
47 :QListView( parent, name )
48{
49 //FIXME: get from global settings and calculate ==> see oglobalsettings.*
50
51 m_alternateBackground = QColor( 238, 246, 255 );
52 m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine );
53 m_fullWidth = true;
54}
55
56OListView::~OListView()
57{
58}
59
60void OListView::setFullWidth( bool fullWidth )
61{
62 m_fullWidth = m_fullWidth;
63 #if QT_VERSION > 290
64 header()->setStretchEnabled( fullWidth, columns()-1 );
65 #endif
66}
67
68bool OListView::fullWidth() const
69{
70 return m_fullWidth;
71}
72
73int OListView::addColumn( const QString& label, int width )
74{
75 int result = QListView::addColumn( label, width );
76 #if QT_VERSION > 290
77 if (m_fullWidth) {
78 header()->setStretchEnabled( false, columns()-2 );
79 header()->setStretchEnabled( true, columns()-1 );
80 }
81 #endif
82 return result;
83}
84
85int OListView::addColumn( const QIconSet& iconset, const QString& label, int width )
86{
87 int result = QListView::addColumn( iconset, label, width );
88 #if QT_VERSION > 290
89 if (m_fullWidth) {
90 header()->setStretchEnabled( false, columns()-2 );
91 header()->setStretchEnabled( true, columns()-1 );
92 }
93 #endif
94 return result;
95}
96
97void OListView::removeColumn( int index )
98{
99 QListView::removeColumn(index);
100 #if QT_VERSION > 290
101 if ( m_fullWidth && index == columns() )
102 {
103 header()->setStretchEnabled( true, columns()-1 );
104 }
105 #endif
106}
107
108const QColor& OListView::alternateBackground() const
109{
110 return m_alternateBackground;
111}
112
113void OListView::setAlternateBackground( const QColor &c )
114{
115 m_alternateBackground = c;
116 repaint();
117}
118
119const QPen& OListView::columnSeparator() const
120{
121 return m_columnSeparator;
122}
123
124void OListView::setColumnSeparator( const QPen& p )
125{
126 m_columnSeparator = p;
127 repaint();
128}
129
130OListViewItem* OListView::childFactory()
131{
132 return new OListViewItem( this );
133}
134
135#ifndef QT_NO_DATASTREAM
136void OListView::serializeTo( QDataStream& s ) const
137{
138 #warning Caution... the binary format is still under construction...
139 qDebug( "storing OListView..." );
140
141 // store number of columns and the labels
142 s << columns();
143 for ( int i = 0; i < columns(); ++i )
144 s << columnText( i );
145
146 // calculate the number of top-level items to serialize
147 int items = 0;
148 QListViewItem* item = firstChild();
149 while ( item )
150 {
151 item = item->nextSibling();
152 items++;
153 }
154
155 // store number of items and the items itself
156 s << items;
157 item = firstChild();
158 for ( int i = 0; i < items; ++i )
159 {
160 s << *static_cast<OListViewItem*>( item );
161 item = item->nextSibling();
162 }
163
164 qDebug( "OListview stored." );
165}
166
167void OListView::serializeFrom( QDataStream& s )
168{
169 #warning Caution... the binary format is still under construction...
170 qDebug( "loading OListView..." );
171
172 int cols;
173 s >> cols;
174 qDebug( "read number of columns = %d", cols );
175
176 while ( columns() < cols ) addColumn( QString::null );
177
178 for ( int i = 0; i < cols; ++i )
179 {
180 QString coltext;
181 s >> coltext;
182 qDebug( "read text '%s' for column %d", (const char*) coltext, i );
183 setColumnText( i, coltext );
184 }
185
186 int items;
187 s >> items;
188 qDebug( "read number of items = %d", items );
189
190 for ( int i = 0; i < items; ++i )
191 {
192 OListViewItem* item = childFactory();
193 s >> *item;
194 }
195
196 qDebug( "OListView loaded." );
197
198}
199
200QDataStream& operator<<( QDataStream& s, const OListView& lv )
201{
202 lv.serializeTo( s );
203}
204
205QDataStream& operator>>( QDataStream& s, OListView& lv )
206{
207 lv.serializeFrom( s );
208}
209#endif // QT_NO_DATASTREAM
210
211/*======================================================================================
212 * OListViewItem
213 *======================================================================================*/
214
215OListViewItem::OListViewItem(QListView *parent)
216 : QListViewItem(parent)
217{
218 init();
219}
220
221OListViewItem::OListViewItem(QListViewItem *parent)
222 : QListViewItem(parent)
223{
224 init();
225}
226
227OListViewItem::OListViewItem(QListView *parent, QListViewItem *after)
228 : QListViewItem(parent, after)
229{
230 init();
231}
232
233OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after)
234 : QListViewItem(parent, after)
235{
236 init();
237}
238
239OListViewItem::OListViewItem(QListView *parent,
240 QString label1, QString label2, QString label3, QString label4,
241 QString label5, QString label6, QString label7, QString label8)
242 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
243{
244 init();
245}
246
247OListViewItem::OListViewItem(QListViewItem *parent,
248 QString label1, QString label2, QString label3, QString label4,
249 QString label5, QString label6, QString label7, QString label8)
250 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
251{
252 init();
253}
254
255OListViewItem::OListViewItem(QListView *parent, QListViewItem *after,
256 QString label1, QString label2, QString label3, QString label4,
257 QString label5, QString label6, QString label7, QString label8)
258 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
259{
260 init();
261}
262
263OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after,
264 QString label1, QString label2, QString label3, QString label4,
265 QString label5, QString label6, QString label7, QString label8)
266 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
267{
268 init();
269}
270
271OListViewItem::~OListViewItem()
272{
273}
274
275void OListViewItem::init()
276{
277 m_known = false;
278}
279
280const QColor &OListViewItem::backgroundColor()
281{
282 return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() :
283 listView()->viewport()->colorGroup().base();
284}
285
286bool OListViewItem::isAlternate()
287{
288 OListView *lv = static_cast<OListView*>( listView() );
289
290 // check if the item above is an OListViewItem
291 OListViewItem *above = static_cast<OListViewItem*>( itemAbove() );
292 /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/
293
294 // check if we have a valid alternate background color
295 if (!(lv && lv->alternateBackground().isValid())) return false;
296
297 m_known = above ? above->m_known : true;
298 if (m_known)
299 {
300 m_odd = above ? !above->m_odd : false;
301 }
302 else
303 {
304 OListViewItem *item;
305 bool previous = true;
306 if (parent())
307 {
308 item = static_cast<OListViewItem *>(parent());
309 if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd;
310 item = static_cast<OListViewItem *>(parent()->firstChild());
311 /* if ( !item.inherits( "OListViewItem" ) item = 0; */
312 }
313 else
314 {
315 item = static_cast<OListViewItem *>(lv->firstChild());
316 }
317
318 while(item)
319 {
320 item->m_odd = previous = !previous;
321 item->m_known = true;
322 item = static_cast<OListViewItem *>(item->nextSibling());
323 /* if (!item.inherits( "OListViewItem" ) ) break; */
324 }
325 }
326 return m_odd;
327}
328
329void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
330{
331 QColorGroup _cg = cg;
332 const QPixmap *pm = listView()->viewport()->backgroundPixmap();
333 if (pm && !pm->isNull())
334 {
335 _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) );
336 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
337 }
338 else if ( isAlternate() )
339 {
340 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
341 }
342 QListViewItem::paintCell( p, _cg, column, width, alignment );
343
344 //FIXME: Use styling here!
345
346 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
347 p->setPen( pen );
348 p->drawLine( width-1, 0, width-1, height() );
349}
350
351OListViewItem* OListViewItem::childFactory()
352{
353 return new OListViewItem( this );
354}
355
356#ifndef QT_NO_DATASTREAM
357void OListViewItem::serializeTo( QDataStream& s ) const
358{
359 #warning Caution... the binary format is still under construction...
360 qDebug( "storing OListViewItem..." );
361
362 // store item text
363 for ( int i = 0; i < listView()->columns(); ++i )
364 {
365 s << text( i );
366 }
367
368 // calculate the number of children to serialize
369 int items = 0;
370 QListViewItem* item = firstChild();
371 while ( item )
372 {
373 item = item->nextSibling();
374 items++;
375 }
376
377 // store number of items and the items itself
378 s << items;
379 item = firstChild();
380 for ( int i = 0; i < items; ++i )
381 {
382 s << *static_cast<OListViewItem*>( item );
383 item = item->nextSibling();
384 }
385
386 qDebug( "OListviewItem stored." );
387}
388void OListViewItem::serializeFrom( QDataStream& s )
389{
390 #warning Caution... the binary format is still under construction...
391 qDebug( "loading OListViewItem..." );
392
393 for ( int i = 0; i < listView()->columns(); ++i )
394 {
395 QString coltext;
396 s >> coltext;
397 qDebug( "read text '%s' for column %d", (const char*) coltext, i );
398 setText( i, coltext );
399 }
400
401 int items;
402 s >> items;
403 qDebug( "read number of items = %d", items );
404
405 for ( int i = 0; i < items; ++i )
406 {
407 OListViewItem* item = childFactory();
408 s >> (*item);
409 }
410
411 qDebug( "OListViewItem loaded." );
412}
413
414QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi )
415{
416 lvi.serializeTo( s );
417}
418
419QDataStream& operator>>( QDataStream& s, OListViewItem& lvi )
420{
421 lvi.serializeFrom( s );
422}
423#endif // QT_NO_DATASTREAM