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.cpp151
1 files changed, 148 insertions, 3 deletions
diff --git a/noncore/net/wellenreiter/cornucopia/olistview.cpp b/noncore/net/wellenreiter/cornucopia/olistview.cpp
index 8bc59de..f2d3730 100644
--- a/noncore/net/wellenreiter/cornucopia/olistview.cpp
+++ b/noncore/net/wellenreiter/cornucopia/olistview.cpp
@@ -120,12 +120,88 @@ const QPen& OListView::columnSeparator() const
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
126#ifndef QT_NO_DATASTREAM
127void OListView::serializeTo( QDataStream& s ) const
128{
129 #warning Caution... the binary format is still under construction...
130 qDebug( "storing OListView..." );
131
132 // store number of columns and the labels
133 s << columns();
134 for ( int i = 0; i < columns(); ++i )
135 s << columnText( i );
136
137 // calculate the number of top-level items to serialize
138 int items = 0;
139 QListViewItem* item = firstChild();
140 while ( item )
141 {
142 item = item->nextSibling();
143 items++;
144 }
145
146 // store number of items and the items itself
147 s << items;
148 item = firstChild();
149 for ( int i = 0; i < items; ++i )
150 {
151 s << *static_cast<OListViewItem*>( item );
152 item = item->nextSibling();
153 }
154
155 qDebug( "OListview stored." );
156}
157
158void OListView::serializeFrom( QDataStream& s )
159{
160 #warning Caution... the binary format is still under construction...
161 qDebug( "loading OListView..." );
162
163 int cols;
164 s >> cols;
165 qDebug( "read number of columns = %d", cols );
166
167 while ( columns() < cols ) addColumn( QString::null );
168
169 for ( int i = 0; i < cols; ++i )
170 {
171 QString coltext;
172 s >> coltext;
173 qDebug( "read text '%s' for column %d", (const char*) coltext, i );
174 setColumnText( i, coltext );
175 }
176
177 int items;
178 s >> items;
179 qDebug( "read number of items = %d", items );
180
181 for ( int i = 0; i < items; ++i )
182 {
183 OListViewItem* item = new OListViewItem( this );
184 s >> *item;
185 }
186
187 qDebug( "OListView loaded." );
188
189}
190
191QDataStream& operator<<( QDataStream& s, const OListView& lv )
192{
193 lv.serializeTo( s );
194}
195
196QDataStream& operator>>( QDataStream& s, OListView& lv )
197{
198 lv.serializeFrom( s );
199}
200#endif // QT_NO_DATASTREAM
201
126//****************************** OListViewItem *********************************************************************** 202//****************************** OListViewItem ***********************************************************************
127 203
128OListViewItem::OListViewItem(QListView *parent) 204OListViewItem::OListViewItem(QListView *parent)
129 : QListViewItem(parent) 205 : QListViewItem(parent)
130{ 206{
131 init(); 207 init();
@@ -242,21 +318,90 @@ bool OListViewItem::isAlternate()
242void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) 318void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
243{ 319{
244 QColorGroup _cg = cg; 320 QColorGroup _cg = cg;
245 const QPixmap *pm = listView()->viewport()->backgroundPixmap(); 321 const QPixmap *pm = listView()->viewport()->backgroundPixmap();
246 if (pm && !pm->isNull()) 322 if (pm && !pm->isNull())
247 { 323 {
248 _cg.setBrush(QColorGroup::Base, QBrush(backgroundColor(), *pm)); 324 _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) );
249 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); 325 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
250 } 326 }
251 else if ( isAlternate() ) 327 else if ( isAlternate() )
252 { 328 {
253 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); 329 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
254 } 330 }
255 QListViewItem::paintCell(p, _cg, column, width, alignment); 331 QListViewItem::paintCell( p, _cg, column, width, alignment );
256 332
257 //FIXME: Use styling here? 333 //FIXME: Use styling here!
258 334
259 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); 335 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
260 p->setPen( pen ); 336 p->setPen( pen );
261 p->drawLine( width-1, 0, width-1, height() ); 337 p->drawLine( width-1, 0, width-1, height() );
262} 338}
339
340#ifndef QT_NO_DATASTREAM
341void OListViewItem::serializeTo( QDataStream& s ) const
342{
343 #warning Caution... the binary format is still under construction...
344 qDebug( "storing OListViewItem..." );
345
346 // store item text
347 for ( int i = 0; i < listView()->columns(); ++i )
348 {
349 s << text( i );
350 }
351
352 // calculate the number of children to serialize
353 int items = 0;
354 QListViewItem* item = firstChild();
355 while ( item )
356 {
357 item = item->nextSibling();
358 items++;
359 }
360
361 // store number of items and the items itself
362 s << items;
363 item = firstChild();
364 for ( int i = 0; i < items; ++i )
365 {
366 s << *static_cast<OListViewItem*>( item );
367 item = item->nextSibling();
368 }
369
370 qDebug( "OListviewItem stored." );
371}
372void OListViewItem::serializeFrom( QDataStream& s )
373{
374 #warning Caution... the binary format is still under construction...
375 qDebug( "loading OListViewItem..." );
376
377 for ( int i = 0; i < listView()->columns(); ++i )
378 {
379 QString coltext;
380 s >> coltext;
381 qDebug( "read text '%s' for column %d", (const char*) coltext, i );
382 setText( i, coltext );
383 }
384
385 int items;
386 s >> items;
387 qDebug( "read number of items = %d", items );
388
389 for ( int i = 0; i < items; ++i )
390 {
391 OListViewItem* item = new OListViewItem( this );
392 s >> (*item);
393 }
394
395 qDebug( "OListViewItem loaded." );
396}
397
398QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi )
399{
400 lvi.serializeTo( s );
401}
402
403QDataStream& operator>>( QDataStream& s, OListViewItem& lvi )
404{
405 lvi.serializeFrom( s );
406}
407#endif // QT_NO_DATASTREAM