-rw-r--r-- | korganizer/kotodoviewitem.cpp | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/korganizer/kotodoviewitem.cpp b/korganizer/kotodoviewitem.cpp index 519bb16..c21816d 100644 --- a/korganizer/kotodoviewitem.cpp +++ b/korganizer/kotodoviewitem.cpp | |||
@@ -10,40 +10,44 @@ | |||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <klocale.h> | 20 | #include <klocale.h> |
21 | #include <kdebug.h> | 21 | #include <kdebug.h> |
22 | #include <qapp.h> | 22 | #include <qapplication.h> |
23 | #include <QDesktopWidget> | ||
24 | //Added by qt3to4: | ||
25 | #include <Q3PointArray> | ||
26 | #include <QPixmap> | ||
23 | #include <kglobal.h> | 27 | #include <kglobal.h> |
24 | 28 | ||
25 | #include <kiconloader.h> | 29 | #include <kiconloader.h> |
26 | #include "kotodoviewitem.h" | 30 | #include "kotodoviewitem.h" |
27 | #include "kotodoview.h" | 31 | #include "kotodoview.h" |
28 | #include "koprefs.h" | 32 | #include "koprefs.h" |
29 | 33 | ||
30 | KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo) | 34 | KOTodoViewItem::KOTodoViewItem( Q3ListView *parent, Todo *todo, KOTodoView *kotodo) |
31 | : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) | 35 | : Q3CheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) |
32 | { | 36 | { |
33 | construct(); | 37 | construct(); |
34 | } | 38 | } |
35 | 39 | ||
36 | KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo ) | 40 | KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo ) |
37 | : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) | 41 | : Q3CheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) |
38 | { | 42 | { |
39 | construct(); | 43 | construct(); |
40 | } | 44 | } |
41 | 45 | ||
42 | QString KOTodoViewItem::key(int column,bool) const | 46 | QString KOTodoViewItem::key(int column,bool) const |
43 | { | 47 | { |
44 | if ( column == 0 ) | 48 | if ( column == 0 ) |
45 | return text(0).lower(); | 49 | return text(0).lower(); |
46 | if ( column == 1 ) { | 50 | if ( column == 1 ) { |
47 | if ( mTodo->isCompleted() ) { | 51 | if ( mTodo->isCompleted() ) { |
48 | return "6"+QString::number(mTodo->priority())+text(0).lower(); | 52 | return "6"+QString::number(mTodo->priority())+text(0).lower(); |
49 | } | 53 | } |
@@ -71,25 +75,25 @@ void KOTodoViewItem:: setup() | |||
71 | setHeight( h ); | 75 | setHeight( h ); |
72 | 76 | ||
73 | } | 77 | } |
74 | void KOTodoViewItem::setSortKey(int column,const QString &key) | 78 | void KOTodoViewItem::setSortKey(int column,const QString &key) |
75 | { | 79 | { |
76 | mKeyMap.insert(column,key); | 80 | mKeyMap.insert(column,key); |
77 | } | 81 | } |
78 | 82 | ||
79 | #if QT_VERSION >= 0x030000 | 83 | #if QT_VERSION >= 0x030000 |
80 | void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w, | 84 | void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w, |
81 | int y,int h) | 85 | int y,int h) |
82 | { | 86 | { |
83 | QListViewItem::paintBranches(p,cg,w,y,h); | 87 | Q3ListViewItem::paintBranches(p,cg,w,y,h); |
84 | } | 88 | } |
85 | #else | 89 | #else |
86 | #endif | 90 | #endif |
87 | 91 | ||
88 | void KOTodoViewItem::construct() | 92 | void KOTodoViewItem::construct() |
89 | { | 93 | { |
90 | // qDebug("KOTodoViewItem::construct() "); | 94 | // qDebug("KOTodoViewItem::construct() "); |
91 | m_init = true; | 95 | m_init = true; |
92 | QString keyd = "=="; | 96 | QString keyd = "=="; |
93 | QString keyt = "=="; | 97 | QString keyt = "=="; |
94 | QString skeyd = "=="; | 98 | QString skeyd = "=="; |
95 | QString skeyt = "=="; | 99 | QString skeyt = "=="; |
@@ -307,34 +311,34 @@ void KOTodoViewItem::stateChange(bool state) | |||
307 | else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); | 311 | else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); |
308 | 312 | ||
309 | setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); | 313 | setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); |
310 | if (mTodo->percentComplete()<100) { | 314 | if (mTodo->percentComplete()<100) { |
311 | if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); | 315 | if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); |
312 | else setSortKey(2,QString::number(mTodo->percentComplete())); | 316 | else setSortKey(2,QString::number(mTodo->percentComplete())); |
313 | } | 317 | } |
314 | else { | 318 | else { |
315 | if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); | 319 | if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); |
316 | else setSortKey(2,QString::number(99)); | 320 | else setSortKey(2,QString::number(99)); |
317 | } | 321 | } |
318 | if ( state ) { | 322 | if ( state ) { |
319 | QListViewItem * myChild = firstChild(); | 323 | Q3ListViewItem * myChild = firstChild(); |
320 | KOTodoViewItem *item; | 324 | KOTodoViewItem *item; |
321 | while( myChild ) { | 325 | while( myChild ) { |
322 | //qDebug("stateCH "); | 326 | //qDebug("stateCH "); |
323 | item = static_cast<KOTodoViewItem*>(myChild); | 327 | item = static_cast<KOTodoViewItem*>(myChild); |
324 | item->stateChange(state); | 328 | item->stateChange(state); |
325 | myChild = myChild->nextSibling(); | 329 | myChild = myChild->nextSibling(); |
326 | } | 330 | } |
327 | } else { | 331 | } else { |
328 | QListViewItem * myChild = parent(); | 332 | Q3ListViewItem * myChild = parent(); |
329 | if ( myChild ) | 333 | if ( myChild ) |
330 | (static_cast<KOTodoViewItem*>(myChild))->stateChange(state); | 334 | (static_cast<KOTodoViewItem*>(myChild))->stateChange(state); |
331 | } | 335 | } |
332 | mTodoView->modified(true); | 336 | mTodoView->modified(true); |
333 | setMyPixmap(); | 337 | setMyPixmap(); |
334 | mTodoView->setTodoModified( mTodo ); | 338 | mTodoView->setTodoModified( mTodo ); |
335 | } | 339 | } |
336 | 340 | ||
337 | bool KOTodoViewItem::isAlternate() | 341 | bool KOTodoViewItem::isAlternate() |
338 | { | 342 | { |
339 | #if 0 | 343 | #if 0 |
340 | //if ( m_known ) return m_odd; | 344 | //if ( m_known ) return m_odd; |
@@ -374,30 +378,30 @@ bool KOTodoViewItem::isAlternate() | |||
374 | //if (lv && lv->alternateBackground().isValid()) | 378 | //if (lv && lv->alternateBackground().isValid()) |
375 | { | 379 | { |
376 | KOTodoViewItem *above = static_cast<KOTodoViewItem *>(itemAbove()); | 380 | KOTodoViewItem *above = static_cast<KOTodoViewItem *>(itemAbove()); |
377 | m_known = above ? above->m_known : true; | 381 | m_known = above ? above->m_known : true; |
378 | if (m_known) | 382 | if (m_known) |
379 | { | 383 | { |
380 | m_odd = above ? !above->m_odd : false; | 384 | m_odd = above ? !above->m_odd : false; |
381 | } | 385 | } |
382 | else | 386 | else |
383 | { | 387 | { |
384 | KOTodoViewItem *item; | 388 | KOTodoViewItem *item; |
385 | bool previous = true; | 389 | bool previous = true; |
386 | if (QListViewItem::parent()) | 390 | if (Q3ListViewItem::parent()) |
387 | { | 391 | { |
388 | item = static_cast<KOTodoViewItem *>(QListViewItem::parent()); | 392 | item = static_cast<KOTodoViewItem *>(Q3ListViewItem::parent()); |
389 | if (item) | 393 | if (item) |
390 | previous = item->m_odd; | 394 | previous = item->m_odd; |
391 | item = static_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild()); | 395 | item = static_cast<KOTodoViewItem *>(Q3ListViewItem::parent()->firstChild()); |
392 | } | 396 | } |
393 | else | 397 | else |
394 | { | 398 | { |
395 | KOTodoListView *lv = static_cast<KOTodoListView *>(listView()); | 399 | KOTodoListView *lv = static_cast<KOTodoListView *>(listView()); |
396 | item = static_cast<KOTodoViewItem *>(lv->firstChild()); | 400 | item = static_cast<KOTodoViewItem *>(lv->firstChild()); |
397 | } | 401 | } |
398 | 402 | ||
399 | while(item) | 403 | while(item) |
400 | { | 404 | { |
401 | item->m_odd = previous = !previous; | 405 | item->m_odd = previous = !previous; |
402 | item->m_known = true; | 406 | item->m_known = true; |
403 | item = static_cast<KOTodoViewItem *>(item->nextSibling()); | 407 | item = static_cast<KOTodoViewItem *>(item->nextSibling()); |
@@ -467,113 +471,113 @@ void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, i | |||
467 | } | 471 | } |
468 | //#endif | 472 | //#endif |
469 | if ( column > 0 ){ | 473 | if ( column > 0 ){ |
470 | if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) { | 474 | if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) { |
471 | p->save(); | 475 | p->save(); |
472 | int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5); | 476 | int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5); |
473 | 477 | ||
474 | p->fillRect( 0, 0, width, height(), _cg.base() ); // background | 478 | p->fillRect( 0, 0, width, height(), _cg.base() ); // background |
475 | // p->setPen(Qt::black ); //border | 479 | // p->setPen(Qt::black ); //border |
476 | // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling | 480 | // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling |
477 | QColor fc = KOPrefs::instance()->mHighlightColor; | 481 | QColor fc = KOPrefs::instance()->mHighlightColor; |
478 | if ( mTodo->percentComplete() == 100 ) | 482 | if ( mTodo->percentComplete() == 100 ) |
479 | fc = darkGreen; | 483 | fc = Qt::darkGreen; |
480 | p->drawRect( 2, 2, width-4, height()-4); | 484 | p->drawRect( 2, 2, width-4, height()-4); |
481 | p->fillRect( 3, 3, progress, height()-6, | 485 | p->fillRect( 3, 3, progress, height()-6, |
482 | fc ); | 486 | fc ); |
483 | p->restore(); | 487 | p->restore(); |
484 | } else { | 488 | } else { |
485 | QCheckListItem::paintCell(p, _cg, column, width, alignment); | 489 | Q3CheckListItem::paintCell(p, _cg, column, width, alignment); |
486 | } | 490 | } |
487 | return; | 491 | return; |
488 | } | 492 | } |
489 | 493 | ||
490 | int align = alignment; | 494 | int align = alignment; |
491 | 495 | ||
492 | if ( !p ) | 496 | if ( !p ) |
493 | return; | 497 | return; |
494 | 498 | ||
495 | p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) ); | 499 | p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) ); |
496 | 500 | ||
497 | QListView *lv = listView(); | 501 | Q3ListView *lv = listView(); |
498 | if ( !lv ) | 502 | if ( !lv ) |
499 | return; | 503 | return; |
500 | int marg = 2;//lv->itemMargin(); | 504 | int marg = 2;//lv->itemMargin(); |
501 | int r = 0; | 505 | int r = 0; |
502 | QCheckListItem::Type myType = QCheckListItem::CheckBox; | 506 | Q3CheckListItem::Type myType = Q3CheckListItem::CheckBox; |
503 | int BoxSize = 20; | 507 | int BoxSize = 20; |
504 | int boxOffset = 2; | 508 | int boxOffset = 2; |
505 | int xOffset = 2; | 509 | int xOffset = 2; |
506 | if (qApp->desktop()->width() < 300 ) { | 510 | if (qApp->desktop()->width() < 300 ) { |
507 | BoxSize = 14; | 511 | BoxSize = 14; |
508 | boxOffset = -1; | 512 | boxOffset = -1; |
509 | xOffset = 1; | 513 | xOffset = 1; |
510 | // marg = 0; | 514 | // marg = 0; |
511 | } | 515 | } |
512 | if ( height() < BoxSize ) { | 516 | if ( height() < BoxSize ) { |
513 | boxOffset = boxOffset - ((BoxSize - height())/2) ; | 517 | boxOffset = boxOffset - ((BoxSize - height())/2) ; |
514 | // qDebug("boxOffset %d height %d", boxOffset, height() ); | 518 | // qDebug("boxOffset %d height %d", boxOffset, height() ); |
515 | BoxSize = height(); | 519 | BoxSize = height(); |
516 | 520 | ||
517 | } | 521 | } |
518 | //bool winStyle = lv->style() == WindowsStyle; | 522 | //bool winStyle = lv->style() == WindowsStyle; |
519 | 523 | ||
520 | int lineStart = 5; | 524 | int lineStart = 5; |
521 | if ( myType == Controller ) { | 525 | if ( myType == Controller ) { |
522 | if ( !pixmap( 0 ) ) | 526 | if ( !pixmap( 0 ) ) |
523 | r += BoxSize + 4; | 527 | r += BoxSize + 4; |
524 | } else { | 528 | } else { |
525 | ASSERT( lv ); //### | 529 | Q_ASSERT( lv ); //### |
526 | //QFontMetrics fm( lv->font() ); | 530 | //QFontMetrics fm( lv->font() ); |
527 | //int d = fm.height(); | 531 | //int d = fm.height(); |
528 | int x = 0; | 532 | int x = 0; |
529 | int y = (height() - BoxSize) / 2; | 533 | int y = (height() - BoxSize) / 2; |
530 | //p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) ); | 534 | //p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) ); |
531 | if ( myType == CheckBox ) { | 535 | if ( myType == CheckBox ) { |
532 | if ( isEnabled() ) | 536 | if ( isEnabled() ) |
533 | p->setPen( QPen( _cg.text(), 1 ) ); | 537 | p->setPen( QPen( _cg.text(), 1 ) ); |
534 | else | 538 | else |
535 | p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) ); | 539 | p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) ); |
536 | p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 ); | 540 | p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 ); |
537 | lineStart = x+marg; | 541 | lineStart = x+marg; |
538 | ///////////////////// | 542 | ///////////////////// |
539 | x++; | 543 | x++; |
540 | y++; | 544 | y++; |
541 | if ( isOn() ) { | 545 | if ( isOn() ) { |
542 | QPointArray a( 7*2 ); | 546 | Q3PointArray a( 7*2 ); |
543 | int i, xx, yy; | 547 | int i, xx, yy; |
544 | xx = x+xOffset+marg+(boxOffset/2); | 548 | xx = x+xOffset+marg+(boxOffset/2); |
545 | yy = y+5+boxOffset; | 549 | yy = y+5+boxOffset; |
546 | for ( i=0; i<3; i++ ) { | 550 | for ( i=0; i<3; i++ ) { |
547 | a.setPoint( 2*i, xx, yy ); | 551 | a.setPoint( 2*i, xx, yy ); |
548 | a.setPoint( 2*i+1, xx, yy+2 ); | 552 | a.setPoint( 2*i+1, xx, yy+2 ); |
549 | // qDebug(" "); | 553 | // qDebug(" "); |
550 | xx++; yy++; | 554 | xx++; yy++; |
551 | } | 555 | } |
552 | yy -= 2; | 556 | yy -= 2; |
553 | for ( i=3; i<7; i++ ) { | 557 | for ( i=3; i<7; i++ ) { |
554 | a.setPoint( 2*i, xx, yy ); | 558 | a.setPoint( 2*i, xx, yy ); |
555 | a.setPoint( 2*i+1, xx, yy+2 ); | 559 | a.setPoint( 2*i+1, xx, yy+2 ); |
556 | xx++; yy--; | 560 | xx++; yy--; |
557 | } | 561 | } |
558 | p->setPen( darkGreen ); | 562 | p->setPen( Qt::darkGreen ); |
559 | p->drawLineSegments( a ); | 563 | p->drawLineSegments( a ); |
560 | } | 564 | } |
561 | //////////////////////// | 565 | //////////////////////// |
562 | } | 566 | } |
563 | r += BoxSize + 4; | 567 | r += BoxSize + 4; |
564 | } | 568 | } |
565 | 569 | ||
566 | p->translate( r, 0 ); | 570 | p->translate( r, 0 ); |
567 | p->setPen( QPen( _cg.text() ) ); | 571 | p->setPen( QPen( _cg.text() ) ); |
568 | QListViewItem::paintCell( p, _cg, column, width - r, align ); | 572 | Q3ListViewItem::paintCell( p, _cg, column, width - r, align ); |
569 | if ( mTodo->cancelled () ) { | 573 | if ( mTodo->cancelled () ) { |
570 | p->setPen( black ); | 574 | p->setPen( Qt::black ); |
571 | QRect br = p->boundingRect( 1,1,1,1,0,mTodo->summary() ); | 575 | QRect br = p->boundingRect( 1,1,1,1,0,mTodo->summary() ); |
572 | int wid = br.width() +lineStart; | 576 | int wid = br.width() +lineStart; |
573 | if ( wid > width-3 ) | 577 | if ( wid > width-3 ) |
574 | wid = width-3; | 578 | wid = width-3; |
575 | p->drawLine( lineStart, height()/2+1, wid, height()/2+1 ); | 579 | p->drawLine( lineStart, height()/2+1, wid, height()/2+1 ); |
576 | 580 | ||
577 | } | 581 | } |
578 | 582 | ||
579 | } | 583 | } |