summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagendaitem.cpp53
1 files changed, 31 insertions, 22 deletions
diff --git a/korganizer/koagendaitem.cpp b/korganizer/koagendaitem.cpp
index 62281d4..39355b4 100644
--- a/korganizer/koagendaitem.cpp
+++ b/korganizer/koagendaitem.cpp
@@ -67,118 +67,96 @@ KOAgendaItem::KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent,bool
67 setWFlags ( wflags); 67 setWFlags ( wflags);
68 mAllDay = allday; 68 mAllDay = allday;
69 init ( incidence, qd ); 69 init ( incidence, qd );
70 setMouseTracking(true); 70 setMouseTracking(true);
71 //setAcceptDrops(true); 71 //setAcceptDrops(true);
72 xPaintCoord = -1; 72 xPaintCoord = -1;
73 yPaintCoord = -1; 73 yPaintCoord = -1;
74} 74}
75 75
76void KOAgendaItem::init ( Incidence *incidence, QDate qd ) 76void KOAgendaItem::init ( Incidence *incidence, QDate qd )
77{ 77{
78 mIncidence = incidence; 78 mIncidence = incidence;
79 mDate = qd; 79 mDate = qd;
80 mFirstMultiItem = 0; 80 mFirstMultiItem = 0;
81 mNextMultiItem = 0; 81 mNextMultiItem = 0;
82 mLastMultiItem = 0; 82 mLastMultiItem = 0;
83 computeText(); 83 computeText();
84 84
85 if ( (incidence->type() == "Todo") && 85 if ( (incidence->type() == "Todo") &&
86 ( !((static_cast<Todo*>(incidence))->isCompleted()) && 86 ( !((static_cast<Todo*>(incidence))->isCompleted()) &&
87 ((static_cast<Todo*>(incidence))->dtDue().date() <= QDate::currentDate()) ) ) { 87 ((static_cast<Todo*>(incidence))->dtDue().date() <= QDate::currentDate()) ) ) {
88 if ( (static_cast<Todo*>(incidence))->dtDue() < QDateTime::currentDateTime().date()) 88 if ( (static_cast<Todo*>(incidence))->dtDue() < QDateTime::currentDateTime().date())
89 mBackgroundColor = KOPrefs::instance()->mTodoOverdueColor ; 89 mBackgroundColor = KOPrefs::instance()->mTodoOverdueColor ;
90 else 90 else
91 mBackgroundColor = KOPrefs::instance()->mTodoDueTodayColor; 91 mBackgroundColor = KOPrefs::instance()->mTodoDueTodayColor;
92 } 92 }
93 else { 93 else {
94 QStringList categories = mIncidence->categories(); 94 QStringList categories = mIncidence->categories();
95 QString cat = categories.first(); 95 QString cat = categories.first();
96 if (cat.isEmpty()) { 96 if (cat.isEmpty()) {
97 mBackgroundColor =KOPrefs::instance()->mEventColor; 97 mBackgroundColor =KOPrefs::instance()->mEventColor;
98 } else { 98 } else {
99 mBackgroundColor = *KOPrefs::instance()->categoryColor(cat); 99 mBackgroundColor = *KOPrefs::instance()->categoryColor(cat);
100 } 100 }
101 } 101 }
102 mColorGroup = QColorGroup( mBackgroundColor.light(), 102 mColorGroup = QColorGroup( mBackgroundColor.light(),
103 mBackgroundColor.dark(),mBackgroundColor.light(), 103 mBackgroundColor.dark(),mBackgroundColor.light(),
104 mBackgroundColor.dark(),mBackgroundColor, black, mBackgroundColor) ; 104 mBackgroundColor.dark(),mBackgroundColor, black, mBackgroundColor) ;
105 setBackgroundColor( mBackgroundColor ); 105 setBackgroundColor( mBackgroundColor );
106 106
107 setCellXY(0,0,1); 107 setCellXY(0,0,1);
108 setCellXWidth(0); 108 setCellXWidth(0);
109 setSubCell(0); 109 setSubCell(0);
110 setSubCells(1); 110 setSubCells(1);
111 setMultiItem(0,0,0); 111 setMultiItem(0,0,0);
112 startMove(); 112 startMove();
113 mSelected = true; 113 mSelected = true;
114 select(false); 114 select(false);
115 QString tipText = mIncidence->summary();
116 // QToolTip::add(this,tipText);
117 QWhatsThis::add(this,KIncidenceFormatter::instance()->getFormattedText( mIncidence ));
118 if ( !mIncidence->doesFloat() )
119 if ( mIncidence->type() == "Event" ) {
120 if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) {
121 tipText += "\n"+i18n("From: ")+mIncidence->dtStartStr();
122 tipText += "\n"+i18n("To: ")+(static_cast<Event*>(mIncidence))->dtEndStr();
123 }
124 else {
125 tipText += "\n"+i18n("Time: ")+mIncidence->dtStartTimeStr();
126 tipText += " - "+(static_cast<Event*>(mIncidence))->dtEndTimeStr();
127 }
128 }
129 else if ( mIncidence->type() == "Todo" ) {
130 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueTimeStr();
131 }
132
133 if (!mIncidence->location().isEmpty()) {
134 tipText += "\n"+i18n("Location: ")+mIncidence->location();
135 }
136 QToolTip::add(this,tipText,toolTipGroup(),"");
137 QFontMetrics fontinf(KOPrefs::instance()->mAgendaViewFont); 115 QFontMetrics fontinf(KOPrefs::instance()->mAgendaViewFont);
138 mFontPixelSize = fontinf.height();; 116 mFontPixelSize = fontinf.height();;
139 hide(); 117 hide();
140 xPaintCoord = -1; 118 xPaintCoord = -1;
141 yPaintCoord = -1; 119 yPaintCoord = -1;
142} 120}
143 121
144 122
145KOAgendaItem::~KOAgendaItem() 123KOAgendaItem::~KOAgendaItem()
146{ 124{
147 // qDebug("deleteKOAgendaItem::~KOAgendaItem( "); 125 // qDebug("deleteKOAgendaItem::~KOAgendaItem( ");
148 126
149} 127}
150 128
151void KOAgendaItem::recreateIncidence() 129void KOAgendaItem::recreateIncidence()
152{ 130{
153#if 0 131#if 0
154 Incidence* newInc = mIncidence->clone(); 132 Incidence* newInc = mIncidence->clone();
155 newInc->recreate(); 133 newInc->recreate();
156 if ( mIncidence->doesRecur() ) { 134 if ( mIncidence->doesRecur() ) {
157 mIncidence->addExDate( mDate ); 135 mIncidence->addExDate( mDate );
158 newInc->recurrence()->unsetRecurs(); 136 newInc->recurrence()->unsetRecurs();
159 int len = mIncidence->dtStart().secsTo( ((Event*)mIncidence)->dtEnd()); 137 int len = mIncidence->dtStart().secsTo( ((Event*)mIncidence)->dtEnd());
160 QTime tim = mIncidence->dtStart().time(); 138 QTime tim = mIncidence->dtStart().time();
161 newInc->setDtStart( QDateTime(mDate, tim) ); 139 newInc->setDtStart( QDateTime(mDate, tim) );
162 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); 140 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) );
163 } 141 }
164#endif 142#endif
165 mIncidence = mIncidence->recreateCloneException( mDate ); 143 mIncidence = mIncidence->recreateCloneException( mDate );
166} 144}
167bool KOAgendaItem::updateIcons(QPainter * p, bool horLayout) 145bool KOAgendaItem::updateIcons(QPainter * p, bool horLayout)
168{ 146{
169 int size = AGENDA_ICON_SIZE; 147 int size = AGENDA_ICON_SIZE;
170 148
171 int yOff = 0; 149 int yOff = 0;
172 int xOff = 0; 150 int xOff = 0;
173 int x = pos().x() +3; 151 int x = pos().x() +3;
174 int y; 152 int y;
175 if ( mAllDay ) 153 if ( mAllDay )
176 y = pos().y()+3; 154 y = pos().y()+3;
177 else 155 else
178 y = mCellYTop * ( height() / cellHeight() ) +3; 156 y = mCellYTop * ( height() / cellHeight() ) +3;
179 if (mIncidence->cancelled()) { 157 if (mIncidence->cancelled()) {
180 int xpos = xOff*( 1 +AGENDA_ICON_SIZE )+x; 158 int xpos = xOff*( 1 +AGENDA_ICON_SIZE )+x;
181 int ypos = yOff*( 1 +AGENDA_ICON_SIZE)+y; 159 int ypos = yOff*( 1 +AGENDA_ICON_SIZE)+y;
182 p->drawLine( xpos, ypos, xpos+AGENDA_ICON_SIZE-1, ypos+AGENDA_ICON_SIZE-1 ); 160 p->drawLine( xpos, ypos, xpos+AGENDA_ICON_SIZE-1, ypos+AGENDA_ICON_SIZE-1 );
183 p->drawLine( xpos, ypos+AGENDA_ICON_SIZE-1, xpos+AGENDA_ICON_SIZE-1, ypos ); 161 p->drawLine( xpos, ypos+AGENDA_ICON_SIZE-1, xpos+AGENDA_ICON_SIZE-1, ypos );
184 if ( horLayout ) 162 if ( horLayout )
@@ -443,124 +421,155 @@ QPixmap * KOAgendaItem::paintPixSel()
443 if ( ! mPaintPixSel ) 421 if ( ! mPaintPixSel )
444 mPaintPixSel = new QPixmap(1,1); 422 mPaintPixSel = new QPixmap(1,1);
445 return mPaintPixSel ; 423 return mPaintPixSel ;
446} 424}
447void KOAgendaItem::paintEvent ( QPaintEvent *e ) 425void KOAgendaItem::paintEvent ( QPaintEvent *e )
448{ 426{
449 427
450 if ( globalFlagBlockAgendaItemPaint ) 428 if ( globalFlagBlockAgendaItemPaint )
451 return; 429 return;
452 if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 ) 430 if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 )
453 return; 431 return;
454 int yy; 432 int yy;
455 if ( mAllDay ) 433 if ( mAllDay )
456 yy = y(); 434 yy = y();
457 else 435 else
458 yy = mCellYTop * ( height() / cellHeight() ); 436 yy = mCellYTop * ( height() / cellHeight() );
459 int xx = x(); 437 int xx = x();
460 if ( xPaintCoord != xx || yPaintCoord != yy || 438 if ( xPaintCoord != xx || yPaintCoord != yy ||
461 wPaintCoord != width() || hPaintCoord != height()) { 439 wPaintCoord != width() || hPaintCoord != height()) {
462 xPaintCoord= xx; 440 xPaintCoord= xx;
463 yPaintCoord = yy; 441 yPaintCoord = yy;
464 wPaintCoord = width(); 442 wPaintCoord = width();
465 hPaintCoord = height(); 443 hPaintCoord = height();
466 globalFlagBlockAgendaItemUpdate = 0; 444 globalFlagBlockAgendaItemUpdate = 0;
467 paintMe( mSelected ); 445 paintMe( mSelected );
468 //qDebug("calling paintMe "); 446 //qDebug("calling paintMe ");
469 globalFlagBlockAgendaItemUpdate = 1; 447 globalFlagBlockAgendaItemUpdate = 1;
470 } 448 }
471 int rx, ry, rw, rh; 449 int rx, ry, rw, rh;
472 rx = e->rect().x(); 450 rx = e->rect().x();
473 ry = e->rect().y(); 451 ry = e->rect().y();
474 rw = e->rect().width(); 452 rw = e->rect().width();
475 rh = e->rect().height(); 453 rh = e->rect().height();
476 //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height()); 454 //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height());
477 455
478 QPixmap* paintFrom ; 456 QPixmap* paintFrom ;
479 if ( mSelected ) { 457 if ( mSelected ) {
480 paintFrom = paintPixSel(); 458 paintFrom = paintPixSel();
481 } else { 459 } else {
482 if ( mAllDay ) 460 if ( mAllDay )
483 paintFrom = paintPixAllday(); 461 paintFrom = paintPixAllday();
484 else 462 else
485 paintFrom = paintPix(); 463 paintFrom = paintPix();
486 } 464 }
487 bitBlt (this, rx, ry, paintFrom, x()+rx ,yPaintCoord+ry, rw, rh ,CopyROP); 465 bitBlt (this, rx, ry, paintFrom, x()+rx ,yPaintCoord+ry, rw, rh ,CopyROP);
488} 466}
489void KOAgendaItem::computeText() 467void KOAgendaItem::computeText()
490{ 468{
469
491 mDisplayedText = mIncidence->summary(); 470 mDisplayedText = mIncidence->summary();
492 if ( (mIncidence->type() == "Todo") ) { 471 if ( (mIncidence->type() == "Todo") ) {
493 if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() ) 472 if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() )
494 mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")"; 473 mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")";
495 else if ( !(mIncidence->doesFloat())) 474 else if ( !(mIncidence->doesFloat()))
496 mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")"; 475 mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")";
497 476
498 477
499 478
500 } else { 479 } else {
501 if ( !(mIncidence->doesFloat()) && KOPrefs::instance()->mShowTimeInAgenda) 480 if ( !(mIncidence->doesFloat()) && KOPrefs::instance()->mShowTimeInAgenda)
502 mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + "-" + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ; 481 mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + "-" + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ;
503 482
504 if ( mAllDay ) { 483 if ( mAllDay ) {
505 if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) { 484 if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) {
506 mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true) ; 485 mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true) ;
507 } 486 }
508 } 487 }
509 488
510 } 489 }
511 490
512 if ( !mIncidence->location().isEmpty() ) { 491 if ( !mIncidence->location().isEmpty() ) {
513 if ( mAllDay ) 492 if ( mAllDay )
514 mDisplayedText += " ("; 493 mDisplayedText += " (";
515 else 494 else
516 mDisplayedText += "\n("; 495 mDisplayedText += "\n(";
517 mDisplayedText += mIncidence->location() +")"; 496 mDisplayedText += mIncidence->location() +")";
518 } 497 }
498
499 QString tipText = mIncidence->summary();
500 QWhatsThis::add(this,KIncidenceFormatter::instance()->getFormattedText( mIncidence ));
501 if ( !mIncidence->doesFloat() ) {
502 if ( mIncidence->type() == "Event" ) {
503 if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) {
504 tipText += "\n"+i18n("From: ")+mIncidence->dtStartStr();
505 tipText += "\n"+i18n("To: ")+(static_cast<Event*>(mIncidence))->dtEndStr();
506 }
507 else {
508 tipText += "\n"+i18n("Time: ")+mIncidence->dtStartTimeStr();
509 tipText += " - "+(static_cast<Event*>(mIncidence))->dtEndTimeStr();
510 }
511 }
512 else if ( mIncidence->type() == "Todo" ) {
513 if (mIncidence->hasStartDate())
514 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartStr();
515 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueStr();
516 }
517 } else if ( mIncidence->type() == "Todo" ) {
518 if (mIncidence->hasStartDate())
519 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartDateStr();
520 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueDateStr();
521 }
522
523 if (!mIncidence->location().isEmpty()) {
524 tipText += "\n"+i18n("Location: ")+mIncidence->location();
525 }
526 QToolTip::add(this,tipText,toolTipGroup(),"");
527
519} 528}
520void KOAgendaItem::updateItem() 529void KOAgendaItem::updateItem()
521{ 530{
522 computeText(); 531 computeText();
523 532
524 //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y()); 533 //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y());
525 paintMe( mSelected ); 534 paintMe( mSelected );
526 repaint( false); 535 repaint( false);
527} 536}
528 537
529void KOAgendaItem::resizeEvent ( QResizeEvent *ev ) 538void KOAgendaItem::resizeEvent ( QResizeEvent *ev )
530{ 539{
531 //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1()); 540 //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1());
532 paintMe( mSelected ); 541 paintMe( mSelected );
533 repaint( false ); 542 repaint( false );
534} 543}
535 544
536/* 545/*
537 Return height of item in units of agenda cells 546 Return height of item in units of agenda cells
538*/ 547*/
539int KOAgendaItem::cellHeight() 548int KOAgendaItem::cellHeight()
540{ 549{
541 int ret = mCellYBottom - mCellYTop + 1; 550 int ret = mCellYBottom - mCellYTop + 1;
542 if ( ret <= 0 ) { 551 if ( ret <= 0 ) {
543 ret = 1; 552 ret = 1;
544 mCellYBottom = 0; 553 mCellYBottom = 0;
545 mCellYTop = 0; 554 mCellYTop = 0;
546 } 555 }
547 return ret; 556 return ret;
548} 557}
549 558
550/* 559/*
551 Return height of item in units of agenda cells 560 Return height of item in units of agenda cells
552*/ 561*/
553int KOAgendaItem::cellWidth() 562int KOAgendaItem::cellWidth()
554{ 563{
555 return mCellXWidth - mCellX + 1; 564 return mCellXWidth - mCellX + 1;
556} 565}
557 566
558void KOAgendaItem::setItemDate(QDate qd) 567void KOAgendaItem::setItemDate(QDate qd)
559{ 568{
560 mDate = qd; 569 mDate = qd;
561} 570}
562 571
563void KOAgendaItem::setCellXY(int X, int YTop, int YBottom) 572void KOAgendaItem::setCellXY(int X, int YTop, int YBottom)
564{ 573{
565 mCellX = X; 574 mCellX = X;
566 mCellYTop = YTop; 575 mCellYTop = YTop;