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.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/noncore/net/wellenreiter/cornucopia/olistview.cpp b/noncore/net/wellenreiter/cornucopia/olistview.cpp
index f2d3730..c292eb9 100644
--- a/noncore/net/wellenreiter/cornucopia/olistview.cpp
+++ b/noncore/net/wellenreiter/cornucopia/olistview.cpp
@@ -102,48 +102,53 @@ void OListView::removeColumn( int index )
102} 102}
103 103
104const QColor& OListView::alternateBackground() const 104const QColor& OListView::alternateBackground() const
105{ 105{
106 return m_alternateBackground; 106 return m_alternateBackground;
107} 107}
108 108
109void OListView::setAlternateBackground( const QColor &c ) 109void OListView::setAlternateBackground( const QColor &c )
110{ 110{
111 m_alternateBackground = c; 111 m_alternateBackground = c;
112 repaint(); 112 repaint();
113} 113}
114 114
115const QPen& OListView::columnSeparator() const 115const QPen& OListView::columnSeparator() const
116{ 116{
117 return m_columnSeparator; 117 return m_columnSeparator;
118} 118}
119 119
120void OListView::setColumnSeparator( const QPen& p ) 120void OListView::setColumnSeparator( const QPen& p )
121{ 121{
122 m_columnSeparator = p; 122 m_columnSeparator = p;
123 repaint(); 123 repaint();
124} 124}
125 125
126OListViewItem* OListView::childFactory()
127{
128 return new OListViewItem( this );
129}
130
126#ifndef QT_NO_DATASTREAM 131#ifndef QT_NO_DATASTREAM
127void OListView::serializeTo( QDataStream& s ) const 132void OListView::serializeTo( QDataStream& s ) const
128{ 133{
129 #warning Caution... the binary format is still under construction... 134 #warning Caution... the binary format is still under construction...
130 qDebug( "storing OListView..." ); 135 qDebug( "storing OListView..." );
131 136
132 // store number of columns and the labels 137 // store number of columns and the labels
133 s << columns(); 138 s << columns();
134 for ( int i = 0; i < columns(); ++i ) 139 for ( int i = 0; i < columns(); ++i )
135 s << columnText( i ); 140 s << columnText( i );
136 141
137 // calculate the number of top-level items to serialize 142 // calculate the number of top-level items to serialize
138 int items = 0; 143 int items = 0;
139 QListViewItem* item = firstChild(); 144 QListViewItem* item = firstChild();
140 while ( item ) 145 while ( item )
141 { 146 {
142 item = item->nextSibling(); 147 item = item->nextSibling();
143 items++; 148 items++;
144 } 149 }
145 150
146 // store number of items and the items itself 151 // store number of items and the items itself
147 s << items; 152 s << items;
148 item = firstChild(); 153 item = firstChild();
149 for ( int i = 0; i < items; ++i ) 154 for ( int i = 0; i < items; ++i )
@@ -159,49 +164,49 @@ void OListView::serializeFrom( QDataStream& s )
159{ 164{
160 #warning Caution... the binary format is still under construction... 165 #warning Caution... the binary format is still under construction...
161 qDebug( "loading OListView..." ); 166 qDebug( "loading OListView..." );
162 167
163 int cols; 168 int cols;
164 s >> cols; 169 s >> cols;
165 qDebug( "read number of columns = %d", cols ); 170 qDebug( "read number of columns = %d", cols );
166 171
167 while ( columns() < cols ) addColumn( QString::null ); 172 while ( columns() < cols ) addColumn( QString::null );
168 173
169 for ( int i = 0; i < cols; ++i ) 174 for ( int i = 0; i < cols; ++i )
170 { 175 {
171 QString coltext; 176 QString coltext;
172 s >> coltext; 177 s >> coltext;
173 qDebug( "read text '%s' for column %d", (const char*) coltext, i ); 178 qDebug( "read text '%s' for column %d", (const char*) coltext, i );
174 setColumnText( i, coltext ); 179 setColumnText( i, coltext );
175 } 180 }
176 181
177 int items; 182 int items;
178 s >> items; 183 s >> items;
179 qDebug( "read number of items = %d", items ); 184 qDebug( "read number of items = %d", items );
180 185
181 for ( int i = 0; i < items; ++i ) 186 for ( int i = 0; i < items; ++i )
182 { 187 {
183 OListViewItem* item = new OListViewItem( this ); 188 OListViewItem* item = childFactory();
184 s >> *item; 189 s >> *item;
185 } 190 }
186 191
187 qDebug( "OListView loaded." ); 192 qDebug( "OListView loaded." );
188 193
189} 194}
190 195
191QDataStream& operator<<( QDataStream& s, const OListView& lv ) 196QDataStream& operator<<( QDataStream& s, const OListView& lv )
192{ 197{
193 lv.serializeTo( s ); 198 lv.serializeTo( s );
194} 199}
195 200
196QDataStream& operator>>( QDataStream& s, OListView& lv ) 201QDataStream& operator>>( QDataStream& s, OListView& lv )
197{ 202{
198 lv.serializeFrom( s ); 203 lv.serializeFrom( s );
199} 204}
200#endif // QT_NO_DATASTREAM 205#endif // QT_NO_DATASTREAM
201 206
202//****************************** OListViewItem *********************************************************************** 207//****************************** OListViewItem ***********************************************************************
203 208
204OListViewItem::OListViewItem(QListView *parent) 209OListViewItem::OListViewItem(QListView *parent)
205 : QListViewItem(parent) 210 : QListViewItem(parent)
206{ 211{
207 init(); 212 init();
@@ -316,48 +321,53 @@ bool OListViewItem::isAlternate()
316} 321}
317 322
318void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) 323void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
319{ 324{
320 QColorGroup _cg = cg; 325 QColorGroup _cg = cg;
321 const QPixmap *pm = listView()->viewport()->backgroundPixmap(); 326 const QPixmap *pm = listView()->viewport()->backgroundPixmap();
322 if (pm && !pm->isNull()) 327 if (pm && !pm->isNull())
323 { 328 {
324 _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); 329 _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) );
325 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); 330 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
326 } 331 }
327 else if ( isAlternate() ) 332 else if ( isAlternate() )
328 { 333 {
329 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); 334 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
330 } 335 }
331 QListViewItem::paintCell( p, _cg, column, width, alignment ); 336 QListViewItem::paintCell( p, _cg, column, width, alignment );
332 337
333 //FIXME: Use styling here! 338 //FIXME: Use styling here!
334 339
335 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); 340 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
336 p->setPen( pen ); 341 p->setPen( pen );
337 p->drawLine( width-1, 0, width-1, height() ); 342 p->drawLine( width-1, 0, width-1, height() );
338} 343}
339 344
345OListViewItem* OListViewItem::childFactory()
346{
347 return new OListViewItem( this );
348}
349
340#ifndef QT_NO_DATASTREAM 350#ifndef QT_NO_DATASTREAM
341void OListViewItem::serializeTo( QDataStream& s ) const 351void OListViewItem::serializeTo( QDataStream& s ) const
342{ 352{
343 #warning Caution... the binary format is still under construction... 353 #warning Caution... the binary format is still under construction...
344 qDebug( "storing OListViewItem..." ); 354 qDebug( "storing OListViewItem..." );
345 355
346 // store item text 356 // store item text
347 for ( int i = 0; i < listView()->columns(); ++i ) 357 for ( int i = 0; i < listView()->columns(); ++i )
348 { 358 {
349 s << text( i ); 359 s << text( i );
350 } 360 }
351 361
352 // calculate the number of children to serialize 362 // calculate the number of children to serialize
353 int items = 0; 363 int items = 0;
354 QListViewItem* item = firstChild(); 364 QListViewItem* item = firstChild();
355 while ( item ) 365 while ( item )
356 { 366 {
357 item = item->nextSibling(); 367 item = item->nextSibling();
358 items++; 368 items++;
359 } 369 }
360 370
361 // store number of items and the items itself 371 // store number of items and the items itself
362 s << items; 372 s << items;
363 item = firstChild(); 373 item = firstChild();
@@ -367,41 +377,41 @@ void OListViewItem::serializeTo( QDataStream& s ) const
367 item = item->nextSibling(); 377 item = item->nextSibling();
368 } 378 }
369 379
370 qDebug( "OListviewItem stored." ); 380 qDebug( "OListviewItem stored." );
371} 381}
372void OListViewItem::serializeFrom( QDataStream& s ) 382void OListViewItem::serializeFrom( QDataStream& s )
373{ 383{
374 #warning Caution... the binary format is still under construction... 384 #warning Caution... the binary format is still under construction...
375 qDebug( "loading OListViewItem..." ); 385 qDebug( "loading OListViewItem..." );
376 386
377 for ( int i = 0; i < listView()->columns(); ++i ) 387 for ( int i = 0; i < listView()->columns(); ++i )
378 { 388 {
379 QString coltext; 389 QString coltext;
380 s >> coltext; 390 s >> coltext;
381 qDebug( "read text '%s' for column %d", (const char*) coltext, i ); 391 qDebug( "read text '%s' for column %d", (const char*) coltext, i );
382 setText( i, coltext ); 392 setText( i, coltext );
383 } 393 }
384 394
385 int items; 395 int items;
386 s >> items; 396 s >> items;
387 qDebug( "read number of items = %d", items ); 397 qDebug( "read number of items = %d", items );
388 398
389 for ( int i = 0; i < items; ++i ) 399 for ( int i = 0; i < items; ++i )
390 { 400 {
391 OListViewItem* item = new OListViewItem( this ); 401 OListViewItem* item = childFactory();
392 s >> (*item); 402 s >> (*item);
393 } 403 }
394 404
395 qDebug( "OListViewItem loaded." ); 405 qDebug( "OListViewItem loaded." );
396} 406}
397 407
398QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) 408QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi )
399{ 409{
400 lvi.serializeTo( s ); 410 lvi.serializeTo( s );
401} 411}
402 412
403QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) 413QDataStream& operator>>( QDataStream& s, OListViewItem& lvi )
404{ 414{
405 lvi.serializeFrom( s ); 415 lvi.serializeFrom( s );
406} 416}
407#endif // QT_NO_DATASTREAM 417#endif // QT_NO_DATASTREAM