author | mickeyl <mickeyl> | 2003-05-01 14:00:37 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-05-01 14:00:37 (UTC) |
commit | 95e533a6ac257d3b95cd8905660008fb7dcd33f1 (patch) (unidiff) | |
tree | c671954f59eaa70db2285f9abe49fd8b4512dd12 /libopie2/opieui/olistview.cpp | |
parent | 1d721ddb247e9000e29fba3150e0cce5f59f543e (diff) | |
download | opie-95e533a6ac257d3b95cd8905660008fb7dcd33f1.zip opie-95e533a6ac257d3b95cd8905660008fb7dcd33f1.tar.gz opie-95e533a6ac257d3b95cd8905660008fb7dcd33f1.tar.bz2 |
- restructure opieui example directory
- start work on ONamedListViewItem providing a slightly higher level interface
-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 | |||
@@ -218,24 +218,28 @@ OListViewItem::OListViewItem(QListView *parent) | |||
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) |
@@ -244,6 +248,7 @@ OListViewItem::OListViewItem(QListView *parent, | |||
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) |
@@ -252,6 +257,7 @@ OListViewItem::OListViewItem(QListViewItem *parent, | |||
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) |
@@ -260,6 +266,7 @@ OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, | |||
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) |
@@ -268,21 +275,25 @@ OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, | |||
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() ); |
@@ -326,6 +337,7 @@ bool OListViewItem::isAlternate() | |||
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; |
@@ -348,11 +360,13 @@ void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, in | |||
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 | { |
@@ -385,6 +399,8 @@ void OListViewItem::serializeTo( QDataStream& s ) const | |||
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... |
@@ -411,13 +427,106 @@ void OListViewItem::serializeFrom( QDataStream& s ) | |||
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 | } | ||