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
@@ -78,96 +78,172 @@ int OListView::addColumn( const QString& label, int width )
78 return result; 78 return result;
79} 79}
80 80
81int OListView::addColumn( const QIconSet& iconset, const QString& label, int width ) 81int OListView::addColumn( const QIconSet& iconset, const QString& label, int width )
82{ 82{
83 int result = QListView::addColumn( iconset, label, width ); 83 int result = QListView::addColumn( iconset, label, width );
84 #if QT_VERSION > 290 84 #if QT_VERSION > 290
85 if (m_fullWidth) { 85 if (m_fullWidth) {
86 header()->setStretchEnabled( false, columns()-2 ); 86 header()->setStretchEnabled( false, columns()-2 );
87 header()->setStretchEnabled( true, columns()-1 ); 87 header()->setStretchEnabled( true, columns()-1 );
88 } 88 }
89 #endif 89 #endif
90 return result; 90 return result;
91} 91}
92 92
93void OListView::removeColumn( int index ) 93void OListView::removeColumn( int index )
94{ 94{
95 QListView::removeColumn(index); 95 QListView::removeColumn(index);
96 #if QT_VERSION > 290 96 #if QT_VERSION > 290
97 if ( m_fullWidth && index == columns() ) 97 if ( m_fullWidth && index == columns() )
98 { 98 {
99 header()->setStretchEnabled( true, columns()-1 ); 99 header()->setStretchEnabled( true, columns()-1 );
100 } 100 }
101 #endif 101 #endif
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
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();
132} 208}
133 209
134OListViewItem::OListViewItem(QListViewItem *parent) 210OListViewItem::OListViewItem(QListViewItem *parent)
135 : QListViewItem(parent) 211 : QListViewItem(parent)
136{ 212{
137 init(); 213 init();
138} 214}
139 215
140OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) 216OListViewItem::OListViewItem(QListView *parent, QListViewItem *after)
141 : QListViewItem(parent, after) 217 : QListViewItem(parent, after)
142{ 218{
143 init(); 219 init();
144} 220}
145 221
146OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) 222OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after)
147 : QListViewItem(parent, after) 223 : QListViewItem(parent, after)
148{ 224{
149 init(); 225 init();
150} 226}
151 227
152OListViewItem::OListViewItem(QListView *parent, 228OListViewItem::OListViewItem(QListView *parent,
153 QString label1, QString label2, QString label3, QString label4, 229 QString label1, QString label2, QString label3, QString label4,
154 QString label5, QString label6, QString label7, QString label8) 230 QString label5, QString label6, QString label7, QString label8)
155 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) 231 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
156{ 232{
157 init(); 233 init();
158} 234}
159 235
160OListViewItem::OListViewItem(QListViewItem *parent, 236OListViewItem::OListViewItem(QListViewItem *parent,
161 QString label1, QString label2, QString label3, QString label4, 237 QString label1, QString label2, QString label3, QString label4,
162 QString label5, QString label6, QString label7, QString label8) 238 QString label5, QString label6, QString label7, QString label8)
163 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) 239 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
164{ 240{
165 init(); 241 init();
166} 242}
167 243
168OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, 244OListViewItem::OListViewItem(QListView *parent, QListViewItem *after,
169 QString label1, QString label2, QString label3, QString label4, 245 QString label1, QString label2, QString label3, QString label4,
170 QString label5, QString label6, QString label7, QString label8) 246 QString label5, QString label6, QString label7, QString label8)
171 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) 247 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
172{ 248{
173 init(); 249 init();
@@ -200,63 +276,132 @@ bool OListViewItem::isAlternate()
200{ 276{
201 OListView *lv = static_cast<OListView*>( listView() ); 277 OListView *lv = static_cast<OListView*>( listView() );
202 278
203 // check if the item above is an OListViewItem 279 // check if the item above is an OListViewItem
204 OListViewItem *above = static_cast<OListViewItem*>( itemAbove() ); 280 OListViewItem *above = static_cast<OListViewItem*>( itemAbove() );
205 /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/ 281 /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/
206 282
207 // check if we have a valid alternate background color 283 // check if we have a valid alternate background color
208 if (!(lv && lv->alternateBackground().isValid())) return false; 284 if (!(lv && lv->alternateBackground().isValid())) return false;
209 285
210 m_known = above ? above->m_known : true; 286 m_known = above ? above->m_known : true;
211 if (m_known) 287 if (m_known)
212 { 288 {
213 m_odd = above ? !above->m_odd : false; 289 m_odd = above ? !above->m_odd : false;
214 } 290 }
215 else 291 else
216 { 292 {
217 OListViewItem *item; 293 OListViewItem *item;
218 bool previous = true; 294 bool previous = true;
219 if (parent()) 295 if (parent())
220 { 296 {
221 item = static_cast<OListViewItem *>(parent()); 297 item = static_cast<OListViewItem *>(parent());
222 if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd; 298 if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd;
223 item = static_cast<OListViewItem *>(parent()->firstChild()); 299 item = static_cast<OListViewItem *>(parent()->firstChild());
224 /* if ( !item.inherits( "OListViewItem" ) item = 0; */ 300 /* if ( !item.inherits( "OListViewItem" ) item = 0; */
225 } 301 }
226 else 302 else
227 { 303 {
228 item = static_cast<OListViewItem *>(lv->firstChild()); 304 item = static_cast<OListViewItem *>(lv->firstChild());
229 } 305 }
230 306
231 while(item) 307 while(item)
232 { 308 {
233 item->m_odd = previous = !previous; 309 item->m_odd = previous = !previous;
234 item->m_known = true; 310 item->m_known = true;
235 item = static_cast<OListViewItem *>(item->nextSibling()); 311 item = static_cast<OListViewItem *>(item->nextSibling());
236 /* if (!item.inherits( "OListViewItem" ) ) break; */ 312 /* if (!item.inherits( "OListViewItem" ) ) break; */
237 } 313 }
238 } 314 }
239 return m_odd; 315 return m_odd;
240} 316}
241 317
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