Diffstat (limited to 'libopie2/opieui/olistview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opieui/olistview.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/libopie2/opieui/olistview.cpp b/libopie2/opieui/olistview.cpp index 2b2f09a..8f97cc6 100644 --- a/libopie2/opieui/olistview.cpp +++ b/libopie2/opieui/olistview.cpp | |||
@@ -215,77 +215,88 @@ QDataStream& operator>>( QDataStream& s, OListView& lv ) | |||
215 | OListViewItem::OListViewItem(QListView *parent) | 215 | OListViewItem::OListViewItem(QListView *parent) |
216 | : QListViewItem(parent) | 216 | : QListViewItem(parent) |
217 | { | 217 | { |
218 | init(); | 218 | init(); |
219 | } | 219 | } |
220 | 220 | ||
221 | |||
221 | OListViewItem::OListViewItem(QListViewItem *parent) | 222 | OListViewItem::OListViewItem(QListViewItem *parent) |
222 | : QListViewItem(parent) | 223 | : QListViewItem(parent) |
223 | { | 224 | { |
224 | init(); | 225 | init(); |
225 | } | 226 | } |
226 | 227 | ||
228 | |||
227 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) | 229 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) |
228 | : QListViewItem(parent, after) | 230 | : QListViewItem(parent, after) |
229 | { | 231 | { |
230 | init(); | 232 | init(); |
231 | } | 233 | } |
232 | 234 | ||
235 | |||
233 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) | 236 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) |
234 | : QListViewItem(parent, after) | 237 | : QListViewItem(parent, after) |
235 | { | 238 | { |
236 | init(); | 239 | init(); |
237 | } | 240 | } |
238 | 241 | ||
242 | |||
239 | OListViewItem::OListViewItem(QListView *parent, | 243 | OListViewItem::OListViewItem(QListView *parent, |
240 | QString label1, QString label2, QString label3, QString label4, | 244 | QString label1, QString label2, QString label3, QString label4, |
241 | QString label5, QString label6, QString label7, QString label8) | 245 | QString label5, QString label6, QString label7, QString label8) |
242 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) | 246 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) |
243 | { | 247 | { |
244 | init(); | 248 | init(); |
245 | } | 249 | } |
246 | 250 | ||
251 | |||
247 | OListViewItem::OListViewItem(QListViewItem *parent, | 252 | OListViewItem::OListViewItem(QListViewItem *parent, |
248 | QString label1, QString label2, QString label3, QString label4, | 253 | QString label1, QString label2, QString label3, QString label4, |
249 | QString label5, QString label6, QString label7, QString label8) | 254 | QString label5, QString label6, QString label7, QString label8) |
250 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) | 255 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) |
251 | { | 256 | { |
252 | init(); | 257 | init(); |
253 | } | 258 | } |
254 | 259 | ||
260 | |||
255 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, | 261 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, |
256 | QString label1, QString label2, QString label3, QString label4, | 262 | QString label1, QString label2, QString label3, QString label4, |
257 | QString label5, QString label6, QString label7, QString label8) | 263 | QString label5, QString label6, QString label7, QString label8) |
258 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) | 264 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) |
259 | { | 265 | { |
260 | init(); | 266 | init(); |
261 | } | 267 | } |
262 | 268 | ||
269 | |||
263 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, | 270 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, |
264 | QString label1, QString label2, QString label3, QString label4, | 271 | QString label1, QString label2, QString label3, QString label4, |
265 | QString label5, QString label6, QString label7, QString label8) | 272 | QString label5, QString label6, QString label7, QString label8) |
266 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) | 273 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) |
267 | { | 274 | { |
268 | init(); | 275 | init(); |
269 | } | 276 | } |
270 | 277 | ||
278 | |||
271 | OListViewItem::~OListViewItem() | 279 | OListViewItem::~OListViewItem() |
272 | { | 280 | { |
273 | } | 281 | } |
274 | 282 | ||
283 | |||
275 | void OListViewItem::init() | 284 | void OListViewItem::init() |
276 | { | 285 | { |
277 | m_known = false; | 286 | m_known = false; |
278 | } | 287 | } |
279 | 288 | ||
289 | |||
280 | const QColor &OListViewItem::backgroundColor() | 290 | const QColor &OListViewItem::backgroundColor() |
281 | { | 291 | { |
282 | return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : | 292 | return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : |
283 | listView()->viewport()->colorGroup().base(); | 293 | listView()->viewport()->colorGroup().base(); |
284 | } | 294 | } |
285 | 295 | ||
296 | |||
286 | bool OListViewItem::isAlternate() | 297 | bool OListViewItem::isAlternate() |
287 | { | 298 | { |
288 | OListView *lv = static_cast<OListView*>( listView() ); | 299 | OListView *lv = static_cast<OListView*>( listView() ); |
289 | 300 | ||
290 | // check if the item above is an OListViewItem | 301 | // check if the item above is an OListViewItem |
291 | OListViewItem *above = static_cast<OListViewItem*>( itemAbove() ); | 302 | OListViewItem *above = static_cast<OListViewItem*>( itemAbove() ); |
@@ -323,12 +334,13 @@ bool OListViewItem::isAlternate() | |||
323 | /* if (!item.inherits( "OListViewItem" ) ) break; */ | 334 | /* if (!item.inherits( "OListViewItem" ) ) break; */ |
324 | } | 335 | } |
325 | } | 336 | } |
326 | return m_odd; | 337 | return m_odd; |
327 | } | 338 | } |
328 | 339 | ||
340 | |||
329 | void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) | 341 | void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) |
330 | { | 342 | { |
331 | QColorGroup _cg = cg; | 343 | QColorGroup _cg = cg; |
332 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); | 344 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); |
333 | if (pm && !pm->isNull()) | 345 | if (pm && !pm->isNull()) |
334 | { | 346 | { |
@@ -345,17 +357,19 @@ void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, in | |||
345 | 357 | ||
346 | const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); | 358 | const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); |
347 | p->setPen( pen ); | 359 | p->setPen( pen ); |
348 | p->drawLine( width-1, 0, width-1, height() ); | 360 | p->drawLine( width-1, 0, width-1, height() ); |
349 | } | 361 | } |
350 | 362 | ||
363 | |||
351 | OListViewItem* OListViewItem::childFactory() | 364 | OListViewItem* OListViewItem::childFactory() |
352 | { | 365 | { |
353 | return new OListViewItem( this ); | 366 | return new OListViewItem( this ); |
354 | } | 367 | } |
355 | 368 | ||
369 | |||
356 | #ifndef QT_NO_DATASTREAM | 370 | #ifndef QT_NO_DATASTREAM |
357 | void OListViewItem::serializeTo( QDataStream& s ) const | 371 | void OListViewItem::serializeTo( QDataStream& s ) const |
358 | { | 372 | { |
359 | #warning Caution... the binary format is still under construction... | 373 | #warning Caution... the binary format is still under construction... |
360 | qDebug( "storing OListViewItem..." ); | 374 | qDebug( "storing OListViewItem..." ); |
361 | 375 | ||
@@ -382,12 +396,14 @@ void OListViewItem::serializeTo( QDataStream& s ) const | |||
382 | s << *static_cast<OListViewItem*>( item ); | 396 | s << *static_cast<OListViewItem*>( item ); |
383 | item = item->nextSibling(); | 397 | item = item->nextSibling(); |
384 | } | 398 | } |
385 | 399 | ||
386 | qDebug( "OListviewItem stored." ); | 400 | qDebug( "OListviewItem stored." ); |
387 | } | 401 | } |
402 | |||
403 | |||
388 | void OListViewItem::serializeFrom( QDataStream& s ) | 404 | void OListViewItem::serializeFrom( QDataStream& s ) |
389 | { | 405 | { |
390 | #warning Caution... the binary format is still under construction... | 406 | #warning Caution... the binary format is still under construction... |
391 | qDebug( "loading OListViewItem..." ); | 407 | qDebug( "loading OListViewItem..." ); |
392 | 408 | ||
393 | for ( int i = 0; i < listView()->columns(); ++i ) | 409 | for ( int i = 0; i < listView()->columns(); ++i ) |
@@ -408,16 +424,109 @@ void OListViewItem::serializeFrom( QDataStream& s ) | |||
408 | s >> (*item); | 424 | s >> (*item); |
409 | } | 425 | } |
410 | 426 | ||
411 | qDebug( "OListViewItem loaded." ); | 427 | qDebug( "OListViewItem loaded." ); |
412 | } | 428 | } |
413 | 429 | ||
430 | |||
414 | QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) | 431 | QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) |
415 | { | 432 | { |
416 | lvi.serializeTo( s ); | 433 | lvi.serializeTo( s ); |
417 | } | 434 | } |
418 | 435 | ||
436 | |||
419 | QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) | 437 | QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) |
420 | { | 438 | { |
421 | lvi.serializeFrom( s ); | 439 | lvi.serializeFrom( s ); |
422 | } | 440 | } |
423 | #endif // QT_NO_DATASTREAM | 441 | #endif // QT_NO_DATASTREAM |
442 | |||
443 | |||
444 | /*====================================================================================== | ||
445 | * ONamedListView | ||
446 | *======================================================================================*/ | ||
447 | |||
448 | ONamedListView::ONamedListView( QWidget *parent, const char *name ) | ||
449 | :OListView( parent, name ) | ||
450 | { | ||
451 | } | ||
452 | |||
453 | |||
454 | ONamedListView::~ONamedListView() | ||
455 | { | ||
456 | } | ||
457 | |||
458 | |||
459 | void ONamedListView::addColumns( const QStringList& columns ) | ||
460 | { | ||
461 | for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it ) | ||
462 | { | ||
463 | qDebug( "adding column %s", (const char*) *it ); | ||
464 | addColumn( *it ); | ||
465 | } | ||
466 | } | ||
467 | |||
468 | |||
469 | /*====================================================================================== | ||
470 | * ONamedListViewItem | ||
471 | *======================================================================================*/ | ||
472 | |||
473 | ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts ) | ||
474 | :OListViewItem( parent ) | ||
475 | { | ||
476 | setText( texts ); | ||
477 | } | ||
478 | |||
479 | |||
480 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts ) | ||
481 | :OListViewItem( parent ) | ||
482 | { | ||
483 | setText( texts ); | ||
484 | } | ||
485 | |||
486 | |||
487 | ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ) | ||
488 | :OListViewItem( parent, after ) | ||
489 | { | ||
490 | setText( texts ); | ||
491 | } | ||
492 | |||
493 | |||
494 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ) | ||
495 | :OListViewItem( parent, after ) | ||
496 | { | ||
497 | setText( texts ); | ||
498 | } | ||
499 | |||
500 | |||
501 | ONamedListViewItem::~ONamedListViewItem() | ||
502 | { | ||
503 | } | ||
504 | |||
505 | |||
506 | void ONamedListViewItem::setText( const QStringList& texts ) | ||
507 | { | ||
508 | int col = 0; | ||
509 | for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it ) | ||
510 | { | ||
511 | qDebug( "setting column %d = text %s", col, (const char*) *it ); | ||
512 | OListViewItem::setText( col++, *it ); | ||
513 | } | ||
514 | |||
515 | } | ||
516 | |||
517 | |||
518 | void ONamedListViewItem::setText( const QString& column, const QString& text ) | ||
519 | { | ||
520 | //FIXME: If used excessively, this will slow down performance of updates | ||
521 | //FIXME: because of the linear search over all column texts. | ||
522 | //FIXME: I will optimize later by using a hash map. | ||
523 | for ( int i = 0; i < listView()->columns(); ++i ) | ||
524 | { | ||
525 | if ( listView()->columnText( i ) == column ) | ||
526 | { | ||
527 | OListViewItem::setText( i, text ); | ||
528 | return; | ||
529 | } | ||
530 | } | ||
531 | qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column ); | ||
532 | } | ||