summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/olistview.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/libopie2/opieui/olistview.cpp b/libopie2/opieui/olistview.cpp
index 4386e0e..a5cf6f3 100644
--- a/libopie2/opieui/olistview.cpp
+++ b/libopie2/opieui/olistview.cpp
@@ -1,768 +1,768 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 =. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de> 3 =. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l. 4 .=l.
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This program is free software; you can 6 _;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License, 10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version. 11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This program is distributed in the hope that 13    .i_,=:_.      -<s. This program is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more 18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details. 19++=   -.     .`     .: details.
20 :     =  ...= . :.=- 20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU 21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with 22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB. 23    --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation, 24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, 25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27 27
28*/ 28*/
29 29
30/* QT */ 30/* QT */
31 31
32#include <qpixmap.h> 32#include <qpixmap.h>
33 33
34/* OPIE */ 34/* OPIE */
35 35
36#include <opie2/odebug.h> 36#include <opie2/odebug.h>
37#include <opie2/olistview.h> 37#include <opie2/olistview.h>
38 38
39using namespace Opie::Core; 39using namespace Opie::Core;
40 40
41 41
42namespace Opie { 42namespace Opie {
43namespace Ui { 43namespace Ui {
44/*====================================================================================== 44/*======================================================================================
45 * OListView 45 * OListView
46 *======================================================================================*/ 46 *======================================================================================*/
47 47
48OListView::OListView( QWidget *parent, const char *name, WFlags fl ) 48OListView::OListView( QWidget *parent, const char *name, WFlags fl )
49 :QListView( parent, name, fl ) 49 :QListView( parent, name, fl )
50{ 50{
51 //FIXME: get from global settings and calculate ==> see oglobalsettings.* 51 //FIXME: get from global settings and calculate ==> see oglobalsettings.*
52 52
53 m_alternateBackground = QColor( 238, 246, 255 ); 53 m_alternateBackground = QColor( 228, 236, 245 );
54 m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine ); 54 m_columnSeparator = QPen( QColor( 50, 60, 70 ), 0, DotLine );
55 m_fullWidth = true; 55 m_fullWidth = true;
56 connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*))); 56 connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*)));
57} 57}
58 58
59OListView::~OListView() 59OListView::~OListView()
60{ 60{
61} 61}
62 62
63void OListView::setFullWidth( bool fullWidth ) 63void OListView::setFullWidth( bool fullWidth )
64{ 64{
65 m_fullWidth = fullWidth; 65 m_fullWidth = fullWidth;
66 #if QT_VERSION >= 0x030000 66 #if QT_VERSION >= 0x030000
67 header()->setStretchEnabled( fullWidth, columns()-1 ); 67 header()->setStretchEnabled( fullWidth, columns()-1 );
68 #endif 68 #endif
69} 69}
70 70
71bool OListView::fullWidth() const 71bool OListView::fullWidth() const
72{ 72{
73 return m_fullWidth; 73 return m_fullWidth;
74} 74}
75 75
76int OListView::addColumn( const QString& label, int width ) 76int OListView::addColumn( const QString& label, int width )
77{ 77{
78 int result = QListView::addColumn( label, width ); 78 int result = QListView::addColumn( label, width );
79 #if QT_VERSION >= 0x030000 79 #if QT_VERSION >= 0x030000
80 if (m_fullWidth) { 80 if (m_fullWidth) {
81 header()->setStretchEnabled( false, columns()-2 ); 81 header()->setStretchEnabled( false, columns()-2 );
82 header()->setStretchEnabled( true, columns()-1 ); 82 header()->setStretchEnabled( true, columns()-1 );
83 } 83 }
84 #endif 84 #endif
85 return result; 85 return result;
86} 86}
87 87
88int OListView::addColumn( const QIconSet& iconset, const QString& label, int width ) 88int OListView::addColumn( const QIconSet& iconset, const QString& label, int width )
89{ 89{
90 int result = QListView::addColumn( iconset, label, width ); 90 int result = QListView::addColumn( iconset, label, width );
91 #if QT_VERSION >= 0x030000 91 #if QT_VERSION >= 0x030000
92 if (m_fullWidth) { 92 if (m_fullWidth) {
93 header()->setStretchEnabled( false, columns()-2 ); 93 header()->setStretchEnabled( false, columns()-2 );
94 header()->setStretchEnabled( true, columns()-1 ); 94 header()->setStretchEnabled( true, columns()-1 );
95 } 95 }
96 #endif 96 #endif
97 return result; 97 return result;
98} 98}
99 99
100void OListView::removeColumn( int index ) 100void OListView::removeColumn( int index )
101{ 101{
102 QListView::removeColumn(index); 102 QListView::removeColumn(index);
103 #if QT_VERSION >= 0x030000 103 #if QT_VERSION >= 0x030000
104 if ( m_fullWidth && index == columns() ) 104 if ( m_fullWidth && index == columns() )
105 { 105 {
106 header()->setStretchEnabled( true, columns()-1 ); 106 header()->setStretchEnabled( true, columns()-1 );
107 } 107 }
108 #endif 108 #endif
109} 109}
110 110
111const QColor& OListView::alternateBackground() const 111const QColor& OListView::alternateBackground() const
112{ 112{
113 return m_alternateBackground; 113 return m_alternateBackground;
114} 114}
115 115
116void OListView::setAlternateBackground( const QColor &c ) 116void OListView::setAlternateBackground( const QColor &c )
117{ 117{
118 m_alternateBackground = c; 118 m_alternateBackground = c;
119 repaint(); 119 repaint();
120} 120}
121 121
122const QPen& OListView::columnSeparator() const 122const QPen& OListView::columnSeparator() const
123{ 123{
124 return m_columnSeparator; 124 return m_columnSeparator;
125} 125}
126 126
127void OListView::setColumnSeparator( const QPen& p ) 127void OListView::setColumnSeparator( const QPen& p )
128{ 128{
129 m_columnSeparator = p; 129 m_columnSeparator = p;
130 repaint(); 130 repaint();
131} 131}
132 132
133void OListView::expand(QListViewItem *item) 133void OListView::expand(QListViewItem *item)
134{ 134{
135 ((OListViewItem*)item)->expand(); 135 ((OListViewItem*)item)->expand();
136} 136}
137 137
138OListViewItem* OListView::childFactory() 138OListViewItem* OListView::childFactory()
139{ 139{
140 return new OListViewItem( this ); 140 return new OListViewItem( this );
141} 141}
142 142
143#ifndef QT_NO_DATASTREAM 143#ifndef QT_NO_DATASTREAM
144void OListView::serializeTo( QDataStream& s ) const 144void OListView::serializeTo( QDataStream& s ) const
145{ 145{
146 #warning Caution... the binary format is still under construction... 146 #warning Caution... the binary format is still under construction...
147 odebug << "storing OListView..." << oendl; 147 odebug << "storing OListView..." << oendl;
148 148
149 // store number of columns and the labels 149 // store number of columns and the labels
150 s << columns(); 150 s << columns();
151 for ( int i = 0; i < columns(); ++i ) 151 for ( int i = 0; i < columns(); ++i )
152 s << columnText( i ); 152 s << columnText( i );
153 153
154 // calculate the number of top-level items to serialize 154 // calculate the number of top-level items to serialize
155 int items = 0; 155 int items = 0;
156 QListViewItem* item = firstChild(); 156 QListViewItem* item = firstChild();
157 while ( item ) 157 while ( item )
158 { 158 {
159 item = item->nextSibling(); 159 item = item->nextSibling();
160 items++; 160 items++;
161 } 161 }
162 162
163 // store number of items and the items itself 163 // store number of items and the items itself
164 s << items; 164 s << items;
165 item = firstChild(); 165 item = firstChild();
166 for ( int i = 0; i < items; ++i ) 166 for ( int i = 0; i < items; ++i )
167 { 167 {
168 s << *static_cast<OListViewItem*>( item ); 168 s << *static_cast<OListViewItem*>( item );
169 item = item->nextSibling(); 169 item = item->nextSibling();
170 } 170 }
171 171
172 odebug << "OListview stored." << oendl; 172 odebug << "OListview stored." << oendl;
173} 173}
174 174
175void OListView::serializeFrom( QDataStream& s ) 175void OListView::serializeFrom( QDataStream& s )
176{ 176{
177 #warning Caution... the binary format is still under construction... 177 #warning Caution... the binary format is still under construction...
178 odebug << "loading OListView..." << oendl; 178 odebug << "loading OListView..." << oendl;
179 179
180 int cols; 180 int cols;
181 s >> cols; 181 s >> cols;
182 odebug << "read number of columns = " << cols << oendl; 182 odebug << "read number of columns = " << cols << oendl;
183 183
184 while ( columns() < cols ) addColumn( QString::null ); 184 while ( columns() < cols ) addColumn( QString::null );
185 185
186 for ( int i = 0; i < cols; ++i ) 186 for ( int i = 0; i < cols; ++i )
187 { 187 {
188 QString coltext; 188 QString coltext;
189 s >> coltext; 189 s >> coltext;
190 odebug << "read text '" << coltext << "' for column " << i << "" << oendl; 190 odebug << "read text '" << coltext << "' for column " << i << "" << oendl;
191 setColumnText( i, coltext ); 191 setColumnText( i, coltext );
192 } 192 }
193 193
194 int items; 194 int items;
195 s >> items; 195 s >> items;
196 odebug << "read number of items = " << items << oendl; 196 odebug << "read number of items = " << items << oendl;
197 197
198 for ( int i = 0; i < items; ++i ) 198 for ( int i = 0; i < items; ++i )
199 { 199 {
200 OListViewItem* item = childFactory(); 200 OListViewItem* item = childFactory();
201 s >> *item; 201 s >> *item;
202 } 202 }
203 203
204 odebug << "OListView loaded." << oendl; 204 odebug << "OListView loaded." << oendl;
205 205
206} 206}
207 207
208 208
209void OListView::expand() 209void OListView::expand()
210{ 210{
211 odebug << "OListView::expand" << oendl; 211 odebug << "OListView::expand" << oendl;
212 212
213 QListViewItemIterator it( this ); 213 QListViewItemIterator it( this );
214 while ( it.current() ) { 214 while ( it.current() ) {
215 it.current()->setOpen( true ); 215 it.current()->setOpen( true );
216 ++it; 216 ++it;
217 } 217 }
218} 218}
219 219
220 220
221void OListView::collapse() 221void OListView::collapse()
222{ 222{
223 odebug << "OListView::collapse" << oendl; 223 odebug << "OListView::collapse" << oendl;
224 QListViewItemIterator it( this ); 224 QListViewItemIterator it( this );
225 while ( it.current() ) { 225 while ( it.current() ) {
226 it.current()->setOpen( false ); 226 it.current()->setOpen( false );
227 ++it; 227 ++it;
228 } 228 }
229} 229}
230 230
231 231
232QDataStream& operator<<( QDataStream& s, const OListView& lv ) 232QDataStream& operator<<( QDataStream& s, const OListView& lv )
233{ 233{
234 lv.serializeTo( s ); 234 lv.serializeTo( s );
235 return s; 235 return s;
236} 236}
237 237
238QDataStream& operator>>( QDataStream& s, OListView& lv ) 238QDataStream& operator>>( QDataStream& s, OListView& lv )
239{ 239{
240 lv.serializeFrom( s ); 240 lv.serializeFrom( s );
241 return s; 241 return s;
242} 242}
243#endif // QT_NO_DATASTREAM 243#endif // QT_NO_DATASTREAM
244 244
245/*====================================================================================== 245/*======================================================================================
246 * OListViewItem 246 * OListViewItem
247 *======================================================================================*/ 247 *======================================================================================*/
248 248
249OListViewItem::OListViewItem(QListView *parent) 249OListViewItem::OListViewItem(QListView *parent)
250 : QListViewItem(parent) 250 : QListViewItem(parent)
251{ 251{
252 init(); 252 init();
253} 253}
254 254
255 255
256OListViewItem::OListViewItem(QListViewItem *parent) 256OListViewItem::OListViewItem(QListViewItem *parent)
257 : QListViewItem(parent) 257 : QListViewItem(parent)
258{ 258{
259 init(); 259 init();
260} 260}
261 261
262 262
263OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) 263OListViewItem::OListViewItem(QListView *parent, QListViewItem *after)
264 : QListViewItem(parent, after) 264 : QListViewItem(parent, after)
265{ 265{
266 init(); 266 init();
267} 267}
268 268
269 269
270OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) 270OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after)
271 : QListViewItem(parent, after) 271 : QListViewItem(parent, after)
272{ 272{
273 init(); 273 init();
274} 274}
275 275
276 276
277OListViewItem::OListViewItem(QListView *parent, 277OListViewItem::OListViewItem(QListView *parent,
278 QString label1, QString label2, QString label3, QString label4, 278 QString label1, QString label2, QString label3, QString label4,
279 QString label5, QString label6, QString label7, QString label8) 279 QString label5, QString label6, QString label7, QString label8)
280 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) 280 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
281{ 281{
282 init(); 282 init();
283} 283}
284 284
285 285
286OListViewItem::OListViewItem(QListViewItem *parent, 286OListViewItem::OListViewItem(QListViewItem *parent,
287 QString label1, QString label2, QString label3, QString label4, 287 QString label1, QString label2, QString label3, QString label4,
288 QString label5, QString label6, QString label7, QString label8) 288 QString label5, QString label6, QString label7, QString label8)
289 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) 289 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
290{ 290{
291 init(); 291 init();
292} 292}
293 293
294 294
295OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, 295OListViewItem::OListViewItem(QListView *parent, QListViewItem *after,
296 QString label1, QString label2, QString label3, QString label4, 296 QString label1, QString label2, QString label3, QString label4,
297 QString label5, QString label6, QString label7, QString label8) 297 QString label5, QString label6, QString label7, QString label8)
298 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) 298 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
299{ 299{
300 init(); 300 init();
301} 301}
302 302
303 303
304OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, 304OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after,
305 QString label1, QString label2, QString label3, QString label4, 305 QString label1, QString label2, QString label3, QString label4,
306 QString label5, QString label6, QString label7, QString label8) 306 QString label5, QString label6, QString label7, QString label8)
307 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) 307 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
308{ 308{
309 init(); 309 init();
310} 310}
311 311
312 312
313OListViewItem::~OListViewItem() 313OListViewItem::~OListViewItem()
314{ 314{
315} 315}
316 316
317 317
318void OListViewItem::init() 318void OListViewItem::init()
319{ 319{
320 m_known = false; 320 m_known = false;
321} 321}
322 322
323 323
324const QColor &OListViewItem::backgroundColor() 324const QColor &OListViewItem::backgroundColor()
325{ 325{
326 return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : 326 return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() :
327 listView()->viewport()->colorGroup().base(); 327 listView()->viewport()->colorGroup().base();
328} 328}
329 329
330 330
331bool OListViewItem::isAlternate() 331bool OListViewItem::isAlternate()
332{ 332{
333 OListView *lv = static_cast<OListView*>( listView() ); 333 OListView *lv = static_cast<OListView*>( listView() );
334 334
335 // check if the item above is an OListViewItem 335 // check if the item above is an OListViewItem
336 OListViewItem *above = static_cast<OListViewItem*>( itemAbove() ); 336 OListViewItem *above = static_cast<OListViewItem*>( itemAbove() );
337 /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/ 337 /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/
338 338
339 // check if we have a valid alternate background color 339 // check if we have a valid alternate background color
340 if (!(lv && lv->alternateBackground().isValid())) return false; 340 if (!(lv && lv->alternateBackground().isValid())) return false;
341 341
342 m_known = above ? above->m_known : true; 342 m_known = above ? above->m_known : true;
343 if (m_known) 343 if (m_known)
344 { 344 {
345 m_odd = above ? !above->m_odd : false; 345 m_odd = above ? !above->m_odd : false;
346 } 346 }
347 else 347 else
348 { 348 {
349 OListViewItem *item; 349 OListViewItem *item;
350 bool previous = true; 350 bool previous = true;
351 if (parent()) 351 if (parent())
352 { 352 {
353 item = static_cast<OListViewItem *>(parent()); 353 item = static_cast<OListViewItem *>(parent());
354 if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd; 354 if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd;
355 item = static_cast<OListViewItem *>(parent()->firstChild()); 355 item = static_cast<OListViewItem *>(parent()->firstChild());
356 /* if ( !item.inherits( "OListViewItem" ) item = 0; */ 356 /* if ( !item.inherits( "OListViewItem" ) item = 0; */
357 } 357 }
358 else 358 else
359 { 359 {
360 item = static_cast<OListViewItem *>(lv->firstChild()); 360 item = static_cast<OListViewItem *>(lv->firstChild());
361 } 361 }
362 362
363 while(item) 363 while(item)
364 { 364 {
365 item->m_odd = previous = !previous; 365 item->m_odd = previous = !previous;
366 item->m_known = true; 366 item->m_known = true;
367 item = static_cast<OListViewItem *>(item->nextSibling()); 367 item = static_cast<OListViewItem *>(item->nextSibling());
368 /* if (!item.inherits( "OListViewItem" ) ) break; */ 368 /* if (!item.inherits( "OListViewItem" ) ) break; */
369 } 369 }
370 } 370 }
371 return m_odd; 371 return m_odd;
372} 372}
373 373
374 374
375void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) 375void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
376{ 376{
377 QColorGroup _cg = cg; 377 QColorGroup _cg = cg;
378 const QPixmap *pm = listView()->viewport()->backgroundPixmap(); 378 const QPixmap *pm = listView()->viewport()->backgroundPixmap();
379 if (pm && !pm->isNull()) 379 if (pm && !pm->isNull())
380 { 380 {
381 _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); 381 _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) );
382 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); 382 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
383 } 383 }
384 else if ( isAlternate() ) 384 else if ( isAlternate() )
385 { 385 {
386 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); 386 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
387 } 387 }
388 QListViewItem::paintCell( p, _cg, column, width, alignment ); 388 QListViewItem::paintCell( p, _cg, column, width, alignment );
389 389
390 //FIXME: Use styling here! 390 //FIXME: Use styling here!
391 391
392 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); 392 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
393 p->setPen( pen ); 393 p->setPen( pen );
394 p->drawLine( width-1, 0, width-1, height() ); 394 p->drawLine( width-1, 0, width-1, height() );
395} 395}
396 396
397 397
398OListViewItem* OListViewItem::childFactory() 398OListViewItem* OListViewItem::childFactory()
399{ 399{
400 return new OListViewItem( this ); 400 return new OListViewItem( this );
401} 401}
402 402
403 403
404#ifndef QT_NO_DATASTREAM 404#ifndef QT_NO_DATASTREAM
405void OListViewItem::serializeTo( QDataStream& s ) const 405void OListViewItem::serializeTo( QDataStream& s ) const
406{ 406{
407 #warning Caution... the binary format is still under construction... 407 #warning Caution... the binary format is still under construction...
408 odebug << "storing OListViewItem..." << oendl; 408 odebug << "storing OListViewItem..." << oendl;
409 409
410 // store item text 410 // store item text
411 for ( int i = 0; i < listView()->columns(); ++i ) 411 for ( int i = 0; i < listView()->columns(); ++i )
412 { 412 {
413 s << text( i ); 413 s << text( i );
414 } 414 }
415 415
416 // calculate the number of children to serialize 416 // calculate the number of children to serialize
417 int items = 0; 417 int items = 0;
418 QListViewItem* item = firstChild(); 418 QListViewItem* item = firstChild();
419 while ( item ) 419 while ( item )
420 { 420 {
421 item = item->nextSibling(); 421 item = item->nextSibling();
422 items++; 422 items++;
423 } 423 }
424 424
425 // store number of items and the items itself 425 // store number of items and the items itself
426 s << items; 426 s << items;
427 item = firstChild(); 427 item = firstChild();
428 for ( int i = 0; i < items; ++i ) 428 for ( int i = 0; i < items; ++i )
429 { 429 {
430 s << *static_cast<OListViewItem*>( item ); 430 s << *static_cast<OListViewItem*>( item );
431 item = item->nextSibling(); 431 item = item->nextSibling();
432 } 432 }
433 433
434 odebug << "OListviewItem stored." << oendl; 434 odebug << "OListviewItem stored." << oendl;
435} 435}
436 436
437 437
438void OListViewItem::serializeFrom( QDataStream& s ) 438void OListViewItem::serializeFrom( QDataStream& s )
439{ 439{
440 #warning Caution... the binary format is still under construction... 440 #warning Caution... the binary format is still under construction...
441 odebug << "loading OListViewItem..." << oendl; 441 odebug << "loading OListViewItem..." << oendl;
442 442
443 for ( int i = 0; i < listView()->columns(); ++i ) 443 for ( int i = 0; i < listView()->columns(); ++i )
444 { 444 {
445 QString coltext; 445 QString coltext;
446 s >> coltext; 446 s >> coltext;
447 odebug << "read text '" << coltext << "' for column " << i << "" << oendl; 447 odebug << "read text '" << coltext << "' for column " << i << "" << oendl;
448 setText( i, coltext ); 448 setText( i, coltext );
449 } 449 }
450 450
451 int items; 451 int items;
452 s >> items; 452 s >> items;
453 odebug << "read number of items = " << items << "" << oendl; 453 odebug << "read number of items = " << items << "" << oendl;
454 454
455 for ( int i = 0; i < items; ++i ) 455 for ( int i = 0; i < items; ++i )
456 { 456 {
457 OListViewItem* item = childFactory(); 457 OListViewItem* item = childFactory();
458 s >> (*item); 458 s >> (*item);
459 } 459 }
460 460
461 odebug << "OListViewItem loaded." << oendl; 461 odebug << "OListViewItem loaded." << oendl;
462} 462}
463 463
464 464
465QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) 465QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi )
466{ 466{
467 lvi.serializeTo( s ); 467 lvi.serializeTo( s );
468 return s; 468 return s;
469} 469}
470 470
471 471
472QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) 472QDataStream& operator>>( QDataStream& s, OListViewItem& lvi )
473{ 473{
474 lvi.serializeFrom( s ); 474 lvi.serializeFrom( s );
475 return s; 475 return s;
476} 476}
477#endif // QT_NO_DATASTREAM 477#endif // QT_NO_DATASTREAM
478 478
479 479
480/*====================================================================================== 480/*======================================================================================
481 * OCheckListItem 481 * OCheckListItem
482 *======================================================================================*/ 482 *======================================================================================*/
483 483
484OCheckListItem::OCheckListItem( QCheckListItem* parent, const QString& text, Type t ) 484OCheckListItem::OCheckListItem( QCheckListItem* parent, const QString& text, Type t )
485 :QCheckListItem( parent, text, t ) 485 :QCheckListItem( parent, text, t )
486{ 486{
487 init(); 487 init();
488} 488}
489 489
490 490
491OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, Type t) 491OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, Type t)
492 :QCheckListItem( parent, text, t ) 492 :QCheckListItem( parent, text, t )
493{ 493{
494 init(); 494 init();
495} 495}
496 496
497 497
498OCheckListItem::OCheckListItem( QListView* parent, const QString& text, Type t ) 498OCheckListItem::OCheckListItem( QListView* parent, const QString& text, Type t )
499 :QCheckListItem( parent, text, t ) 499 :QCheckListItem( parent, text, t )
500{ 500{
501 init(); 501 init();
502} 502}
503 503
504 504
505OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, const QPixmap& p ) 505OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, const QPixmap& p )
506 :QCheckListItem( parent, text, p ) 506 :QCheckListItem( parent, text, p )
507{ 507{
508 init(); 508 init();
509} 509}
510 510
511 511
512OCheckListItem::OCheckListItem( QListView* parent, const QString& text, const QPixmap& p ) 512OCheckListItem::OCheckListItem( QListView* parent, const QString& text, const QPixmap& p )
513 :QCheckListItem( parent, text, p ) 513 :QCheckListItem( parent, text, p )
514{ 514{
515 init(); 515 init();
516} 516}
517 517
518 518
519OCheckListItem::~OCheckListItem() 519OCheckListItem::~OCheckListItem()
520{ 520{
521} 521}
522 522
523void OCheckListItem::init() 523void OCheckListItem::init()
524{ 524{
525 m_known = false; 525 m_known = false;
526} 526}
527 527
528 528
529const QColor &OCheckListItem::backgroundColor() 529const QColor &OCheckListItem::backgroundColor()
530{ 530{
531 return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : 531 return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() :
532 listView()->viewport()->colorGroup().base(); 532 listView()->viewport()->colorGroup().base();
533} 533}
534 534
535 535
536bool OCheckListItem::isAlternate() 536bool OCheckListItem::isAlternate()
537{ 537{
538 OListView *lv = static_cast<OListView*>( listView() ); 538 OListView *lv = static_cast<OListView*>( listView() );
539 539
540 // check if the item above is an OCheckListItem 540 // check if the item above is an OCheckListItem
541 OCheckListItem *above = static_cast<OCheckListItem*>( itemAbove() ); 541 OCheckListItem *above = static_cast<OCheckListItem*>( itemAbove() );
542 /*if (! itemAbove()->inherits( "OCheckListItem" )) return false;*/ 542 /*if (! itemAbove()->inherits( "OCheckListItem" )) return false;*/
543 543
544 // check if we have a valid alternate background color 544 // check if we have a valid alternate background color
545 if (!(lv && lv->alternateBackground().isValid())) return false; 545 if (!(lv && lv->alternateBackground().isValid())) return false;
546 546
547 m_known = above ? above->m_known : true; 547 m_known = above ? above->m_known : true;
548 if (m_known) 548 if (m_known)
549 { 549 {
550 m_odd = above ? !above->m_odd : false; 550 m_odd = above ? !above->m_odd : false;
551 } 551 }
552 else 552 else
553 { 553 {
554 OCheckListItem *item; 554 OCheckListItem *item;
555 bool previous = true; 555 bool previous = true;
556 if (parent()) 556 if (parent())
557 { 557 {
558 item = static_cast<OCheckListItem *>(parent()); 558 item = static_cast<OCheckListItem *>(parent());
559 if ( item /*&& item->inherits( "OCheckListItem" )*/ ) previous = item->m_odd; 559 if ( item /*&& item->inherits( "OCheckListItem" )*/ ) previous = item->m_odd;
560 item = static_cast<OCheckListItem *>(parent()->firstChild()); 560 item = static_cast<OCheckListItem *>(parent()->firstChild());
561 /* if ( !item.inherits( "OCheckListItem" ) item = 0; */ 561 /* if ( !item.inherits( "OCheckListItem" ) item = 0; */
562 } 562 }
563 else 563 else
564 { 564 {
565 item = static_cast<OCheckListItem *>(lv->firstChild()); 565 item = static_cast<OCheckListItem *>(lv->firstChild());
566 } 566 }
567 567
568 while(item) 568 while(item)
569 { 569 {
570 item->m_odd = previous = !previous; 570 item->m_odd = previous = !previous;
571 item->m_known = true; 571 item->m_known = true;
572 item = static_cast<OCheckListItem *>(item->nextSibling()); 572 item = static_cast<OCheckListItem *>(item->nextSibling());
573 /* if (!item.inherits( "OCheckListItem" ) ) break; */ 573 /* if (!item.inherits( "OCheckListItem" ) ) break; */
574 } 574 }
575 } 575 }
576 return m_odd; 576 return m_odd;
577} 577}
578 578
579 579
580void OCheckListItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) 580void OCheckListItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
581{ 581{
582 QColorGroup _cg = cg; 582 QColorGroup _cg = cg;
583 const QPixmap *pm = listView()->viewport()->backgroundPixmap(); 583 const QPixmap *pm = listView()->viewport()->backgroundPixmap();
584 if (pm && !pm->isNull()) 584 if (pm && !pm->isNull())
585 { 585 {
586 _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); 586 _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) );
587 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); 587 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
588 } 588 }
589 else if ( isAlternate() ) 589 else if ( isAlternate() )
590 { 590 {
591 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); 591 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
592 } 592 }
593 QCheckListItem::paintCell( p, _cg, column, width, alignment ); 593 QCheckListItem::paintCell( p, _cg, column, width, alignment );
594 594
595 //FIXME: Use styling here! 595 //FIXME: Use styling here!
596 596
597 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); 597 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
598 p->setPen( pen ); 598 p->setPen( pen );
599 p->drawLine( width-1, 0, width-1, height() ); 599 p->drawLine( width-1, 0, width-1, height() );
600} 600}
601 601
602 602
603/*====================================================================================== 603/*======================================================================================
604 * ONamedListView 604 * ONamedListView
605 *======================================================================================*/ 605 *======================================================================================*/
606 606
607ONamedListView::ONamedListView( QWidget *parent, const char *name ) 607ONamedListView::ONamedListView( QWidget *parent, const char *name )
608 :OListView( parent, name ) 608 :OListView( parent, name )
609{ 609{
610} 610}
611 611
612 612
613ONamedListView::~ONamedListView() 613ONamedListView::~ONamedListView()
614{ 614{
615} 615}
616 616
617 617
618void ONamedListView::addColumns( const QStringList& columns ) 618void ONamedListView::addColumns( const QStringList& columns )
619{ 619{
620 for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it ) 620 for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it )
621 { 621 {
622 odebug << "adding column " << *it << "" << oendl; 622 odebug << "adding column " << *it << "" << oendl;
623 addColumn( *it ); 623 addColumn( *it );
624 } 624 }
625} 625}
626 626
627 627
628int ONamedListView::findColumn( const QString& text ) const 628int ONamedListView::findColumn( const QString& text ) const
629{ 629{
630 //FIXME: If used excessively, this will slow down performance of updates 630 //FIXME: If used excessively, this will slow down performance of updates
631 //FIXME: because of the linear search over all column texts. 631 //FIXME: because of the linear search over all column texts.
632 //FIXME: I will optimize later by using a hash map. 632 //FIXME: I will optimize later by using a hash map.
633 for ( int i = 0; i < columns(); ++i ) 633 for ( int i = 0; i < columns(); ++i )
634 if ( columnText( i ) == text ) 634 if ( columnText( i ) == text )
635 return i; 635 return i;
636 return -1; 636 return -1;
637} 637}
638 638
639 639
640ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const 640ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const
641{ 641{
642 return find( (ONamedListViewItem*) firstChild(), column, text, recurse ); 642 return find( (ONamedListViewItem*) firstChild(), column, text, recurse );
643} 643}
644 644
645 645
646ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const 646ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const
647{ 647{
648 ONamedListViewItem* result; 648 ONamedListViewItem* result;
649 while ( item && item->text( column ) != text ) 649 while ( item && item->text( column ) != text )
650 { 650 {
651 odebug << "checked " << item->text( column ) << "" << oendl; 651 odebug << "checked " << item->text( column ) << "" << oendl;
652 652
653 if ( recurse < 0 || recurse > 0 ) 653 if ( recurse < 0 || recurse > 0 )
654 { 654 {
655 odebug << "recursion is " << recurse << " - recursing into..." << oendl; 655 odebug << "recursion is " << recurse << " - recursing into..." << oendl;
656 result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 ); 656 result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 );
657 if ( result ) return result; 657 if ( result ) return result;
658 } 658 }
659 659
660 660
661 item = (ONamedListViewItem*) item->itemBelow(); 661 item = (ONamedListViewItem*) item->itemBelow();
662 } 662 }
663 if ( item && item->text( column ) == text ) 663 if ( item && item->text( column ) == text )
664 return item; 664 return item;
665 else 665 else
666 return 0; 666 return 0;
667} 667}
668 668
669 669
670ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const 670ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const
671{ 671{
672 int col = findColumn( column ); 672 int col = findColumn( column );
673 if ( col != -1 ) 673 if ( col != -1 )
674 return find( (ONamedListViewItem*) firstChild(), col, text, recurse ); 674 return find( (ONamedListViewItem*) firstChild(), col, text, recurse );
675 else 675 else
676 return 0; 676 return 0;
677} 677}
678 678
679 679
680ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const 680ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const
681{ 681{
682 int col = findColumn( column ); 682 int col = findColumn( column );
683 if ( col != -1 ) 683 if ( col != -1 )
684 return find( item, col, text, recurse ); 684 return find( item, col, text, recurse );
685 else 685 else
686 return 0; 686 return 0;
687} 687}
688 688
689 689
690/*====================================================================================== 690/*======================================================================================
691 * ONamedListViewItem 691 * ONamedListViewItem
692 *======================================================================================*/ 692 *======================================================================================*/
693 693
694ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts ) 694ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts )
695 :OListViewItem( parent ) 695 :OListViewItem( parent )
696{ 696{
697 setText( texts ); 697 setText( texts );
698} 698}
699 699
700 700
701ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts ) 701ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts )
702 :OListViewItem( parent ) 702 :OListViewItem( parent )
703{ 703{
704 setText( texts ); 704 setText( texts );
705} 705}
706 706
707 707
708ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ) 708ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts )
709 :OListViewItem( parent, after ) 709 :OListViewItem( parent, after )
710{ 710{
711 setText( texts ); 711 setText( texts );
712} 712}
713 713
714 714
715ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ) 715ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts )
716 :OListViewItem( parent, after ) 716 :OListViewItem( parent, after )
717{ 717{
718 setText( texts ); 718 setText( texts );
719} 719}
720 720
721 721
722ONamedListViewItem::~ONamedListViewItem() 722ONamedListViewItem::~ONamedListViewItem()
723{ 723{
724} 724}
725 725
726 726
727void ONamedListViewItem::setText( const QStringList& texts ) 727void ONamedListViewItem::setText( const QStringList& texts )
728{ 728{
729 int col = 0; 729 int col = 0;
730 for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it ) 730 for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it )
731 { 731 {
732 odebug << "setting column " << col << " = text " << *it << "" << oendl; 732 odebug << "setting column " << col << " = text " << *it << "" << oendl;
733 OListViewItem::setText( col++, *it ); 733 OListViewItem::setText( col++, *it );
734 } 734 }
735 735
736} 736}
737 737
738 738
739void ONamedListViewItem::setText( const QString& column, const QString& text ) 739void ONamedListViewItem::setText( const QString& column, const QString& text )
740{ 740{
741 //FIXME: If used excessively, this will slow down performance of updates 741 //FIXME: If used excessively, this will slow down performance of updates
742 //FIXME: because of the linear search over all column texts. 742 //FIXME: because of the linear search over all column texts.
743 //FIXME: I will optimize later by using a hash map. 743 //FIXME: I will optimize later by using a hash map.
744 int col = ( (ONamedListView*) listView() )->findColumn( column ); 744 int col = ( (ONamedListView*) listView() )->findColumn( column );
745 if ( col != -1 ) 745 if ( col != -1 )
746 OListViewItem::setText( col, text ); 746 OListViewItem::setText( col, text );
747 else 747 else
748 owarn << "ONamedListViewItem::setText(): Warning! Columntext '" << column << "' not found." << oendl; 748 owarn << "ONamedListViewItem::setText(): Warning! Columntext '" << column << "' not found." << oendl;
749} 749}
750 750
751 751
752ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const 752ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const
753{ 753{
754 return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse ); 754 return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse );
755} 755}
756 756
757 757
758ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const 758ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const
759{ 759{
760 int col = ( (ONamedListView*) listView() )->findColumn( column ); 760 int col = ( (ONamedListView*) listView() )->findColumn( column );
761 if ( col != -1 ) 761 if ( col != -1 )
762 return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse ); 762 return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse );
763 else 763 else
764 return 0; 764 return 0;
765} 765}
766 766
767} 767}
768} 768}