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