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
@@ -1,264 +1,242 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
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 <qlabel.h> 20#include <qlabel.h>
21#include <qlayout.h> 21#include <qlayout.h>
22#include <qhbox.h> 22#include <qhbox.h>
23#include <qvbox.h> 23#include <qvbox.h>
24#include <qtooltip.h> 24#include <qtooltip.h>
25#include <qwhatsthis.h> 25#include <qwhatsthis.h>
26#include <qdragobject.h> 26#include <qdragobject.h>
27#include <qdrawutil.h> 27#include <qdrawutil.h>
28#include <qpainter.h> 28#include <qpainter.h>
29 29
30#include <kiconloader.h> 30#include <kiconloader.h>
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kglobal.h> 32#include <kglobal.h>
33#include <klocale.h> 33#include <klocale.h>
34#ifndef DESKTOP_VERSION 34#ifndef DESKTOP_VERSION
35#include <qpe/qpeapplication.h> 35#include <qpe/qpeapplication.h>
36#define AGENDA_ICON_SIZE 5 36#define AGENDA_ICON_SIZE 5
37#else 37#else
38#define AGENDA_ICON_SIZE 7 38#define AGENDA_ICON_SIZE 7
39#endif 39#endif
40#include <libkcal/icaldrag.h> 40#include <libkcal/icaldrag.h>
41#include <libkcal/vcaldrag.h> 41#include <libkcal/vcaldrag.h>
42#include <libkcal/kincidenceformatter.h> 42#include <libkcal/kincidenceformatter.h>
43extern int globalFlagBlockAgenda; 43extern int globalFlagBlockAgenda;
44extern int globalFlagBlockAgendaItemPaint; 44extern int globalFlagBlockAgendaItemPaint;
45extern int globalFlagBlockAgendaItemUpdate; 45extern int globalFlagBlockAgendaItemUpdate;
46 46
47#include "koprefs.h" 47#include "koprefs.h"
48 48
49#include "koagendaitem.h" 49#include "koagendaitem.h"
50//#include "koagendaitem.moc" 50//#include "koagendaitem.moc"
51 51
52 52
53//-------------------------------------------------------------------------- 53//--------------------------------------------------------------------------
54 54
55QToolTipGroup *KOAgendaItem::mToolTipGroup = 0; 55QToolTipGroup *KOAgendaItem::mToolTipGroup = 0;
56 56
57//-------------------------------------------------------------------------- 57//--------------------------------------------------------------------------
58 58
59KOAgendaItem::KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent,bool allday, 59KOAgendaItem::KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent,bool allday,
60 const char *name,WFlags) : 60 const char *name,WFlags) :
61 QWidget(parent, name), mIncidence(incidence), mDate(qd) 61 QWidget(parent, name), mIncidence(incidence), mDate(qd)
62{ 62{
63#ifndef DESKTOP_VERSION 63#ifndef DESKTOP_VERSION
64 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); 64 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
65#endif 65#endif
66 int wflags = getWFlags() |WRepaintNoErase;// WResizeNoErase 66 int wflags = getWFlags() |WRepaintNoErase;// WResizeNoErase
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 )
185 ++xOff; 163 ++xOff;
186 else 164 else
187 ++yOff; 165 ++yOff;
188 } 166 }
189 if (mIncidence->isAlarmEnabled()) { 167 if (mIncidence->isAlarmEnabled()) {
190 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, red ); 168 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, red );
191 if ( horLayout ) 169 if ( horLayout )
192 ++xOff; 170 ++xOff;
193 else 171 else
194 ++yOff; 172 ++yOff;
195 } 173 }
196 if (mIncidence->recurrence()->doesRecur()) { 174 if (mIncidence->recurrence()->doesRecur()) {
197 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, blue ); 175 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, blue );
198 if ( horLayout ) 176 if ( horLayout )
199 ++xOff; 177 ++xOff;
200 else 178 else
201 ++yOff; 179 ++yOff;
202 } 180 }
203 if (mIncidence->description().length() > 0) { 181 if (mIncidence->description().length() > 0) {
204 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkGreen ); 182 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkGreen );
205 if ( horLayout ) 183 if ( horLayout )
206 ++xOff; 184 ++xOff;
207 else 185 else
208 ++yOff; 186 ++yOff;
209 } 187 }
210 if (mIncidence->isReadOnly()) { 188 if (mIncidence->isReadOnly()) {
211 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, white ); 189 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, white );
212 if ( horLayout ) 190 if ( horLayout )
213 ++xOff; 191 ++xOff;
214 else 192 else
215 ++yOff; 193 ++yOff;
216 } 194 }
217 195
218 if (mIncidence->attendeeCount()>0) { 196 if (mIncidence->attendeeCount()>0) {
219 197
220 if (mIncidence->organizer() == KOPrefs::instance()->email()) { 198 if (mIncidence->organizer() == KOPrefs::instance()->email()) {
221 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, black ); 199 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, black );
222 if ( horLayout ) 200 if ( horLayout )
223 ++xOff; 201 ++xOff;
224 else 202 else
225 ++yOff; 203 ++yOff;
226 } else { 204 } else {
227 Attendee *me = mIncidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 205 Attendee *me = mIncidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
228 if (me!=0) { 206 if (me!=0) {
229 207
230 208
231 } else { 209 } else {
232 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, yellow ); 210 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, yellow );
233 if ( horLayout ) 211 if ( horLayout )
234 ++xOff; 212 ++xOff;
235 else 213 else
236 ++yOff; 214 ++yOff;
237 215
238 } 216 }
239 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkYellow ); 217 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkYellow );
240 if ( horLayout ) 218 if ( horLayout )
241 ++xOff; 219 ++xOff;
242 else 220 else
243 ++yOff; 221 ++yOff;
244 222
245 } 223 }
246 224
247 } 225 }
248 return ( yOff || xOff ); 226 return ( yOff || xOff );
249} 227}
250 228
251 229
252void KOAgendaItem::select(bool selected) 230void KOAgendaItem::select(bool selected)
253{ 231{
254 //qDebug("select %d %d",firstMultiItem(), nextMultiItem() ); 232 //qDebug("select %d %d",firstMultiItem(), nextMultiItem() );
255 if (mSelected == selected) return; 233 if (mSelected == selected) return;
256 mSelected = selected; 234 mSelected = selected;
257 if ( ! isVisible() ) 235 if ( ! isVisible() )
258 return; 236 return;
259 if ( firstMultiItem() ) 237 if ( firstMultiItem() )
260 firstMultiItem()->select( selected ); 238 firstMultiItem()->select( selected );
261 if ( !firstMultiItem() && nextMultiItem() ) { 239 if ( !firstMultiItem() && nextMultiItem() ) {
262 KOAgendaItem * placeItem = nextMultiItem(); 240 KOAgendaItem * placeItem = nextMultiItem();
263 while ( placeItem ) { 241 while ( placeItem ) {
264 placeItem->select( selected ); 242 placeItem->select( selected );
@@ -363,284 +341,315 @@ void KOAgendaItem::paintMe( bool selected, QPainter* paint )
363 //qDebug("draw rect %d %d %d %d ",x, yy, w, h ); 341 //qDebug("draw rect %d %d %d %d ",x, yy, w, h );
364 if ( ! small ) { 342 if ( ! small ) {
365 x += 3; yy += 3;w -= 6; h-= 5; 343 x += 3; yy += 3;w -= 6; h-= 5;
366 } else { 344 } else {
367 x += 2; yy += 1;w -= 4; h-= 4; 345 x += 2; yy += 1;w -= 4; h-= 4;
368 if ( nfh < 6.01 ) { 346 if ( nfh < 6.01 ) {
369 yy -= 2; 347 yy -= 2;
370 h += 4; 348 h += 4;
371 } 349 }
372 else 350 else
373 if ( nfh < h -2 ) 351 if ( nfh < h -2 )
374 ++yy; 352 ++yy;
375 } 353 }
376 int align; 354 int align;
377#ifndef DESKTOP_VERSION 355#ifndef DESKTOP_VERSION
378 align = ( AlignLeft|WordBreak|AlignTop); 356 align = ( AlignLeft|WordBreak|AlignTop);
379#else 357#else
380 align = ( AlignLeft|BreakAnywhere|WordBreak|AlignTop); 358 align = ( AlignLeft|BreakAnywhere|WordBreak|AlignTop);
381#endif 359#endif
382 if ( addIcon ) { 360 if ( addIcon ) {
383 if ( ! horLayout ) { 361 if ( ! horLayout ) {
384 x += AGENDA_ICON_SIZE+3; 362 x += AGENDA_ICON_SIZE+3;
385 w -= (AGENDA_ICON_SIZE+3); 363 w -= (AGENDA_ICON_SIZE+3);
386 } 364 }
387 else { 365 else {
388 yy+= AGENDA_ICON_SIZE+2; 366 yy+= AGENDA_ICON_SIZE+2;
389 h -=(AGENDA_ICON_SIZE+3); 367 h -=(AGENDA_ICON_SIZE+3);
390 } 368 }
391 } 369 }
392 int colsum = mBackgroundColor.red() + mBackgroundColor.green() + mBackgroundColor.blue(); 370 int colsum = mBackgroundColor.red() + mBackgroundColor.green() + mBackgroundColor.blue();
393 if ( colsum < 250 ) 371 if ( colsum < 250 )
394 paint->setPen ( white); 372 paint->setPen ( white);
395 if ( x < 0 ) { 373 if ( x < 0 ) {
396 w = w+x-3; 374 w = w+x-3;
397 x = 3; 375 x = 3;
398 if ( w > parentWidget()->width() ){ 376 if ( w > parentWidget()->width() ){
399 w = parentWidget()->width() - 6; 377 w = parentWidget()->width() - 6;
400#ifndef DESKTOP_VERSION 378#ifndef DESKTOP_VERSION
401 align = ( AlignCenter|WordBreak); 379 align = ( AlignCenter|WordBreak);
402#else 380#else
403 align = ( AlignCenter|BreakAnywhere|WordBreak); 381 align = ( AlignCenter|BreakAnywhere|WordBreak);
404#endif 382#endif
405 383
406 } 384 }
407 } 385 }
408 QRect dr; 386 QRect dr;
409 paint->drawText ( x, yy, w, h, align, mDisplayedText, -1, &dr ); 387 paint->drawText ( x, yy, w, h, align, mDisplayedText, -1, &dr );
410 if ( mIncidence->cancelled() ){ 388 if ( mIncidence->cancelled() ){
411 if ( ! small ) { 389 if ( ! small ) {
412 QFontMetrics fm ( paint->font() ); 390 QFontMetrics fm ( paint->font() );
413 paint->drawLine(dr.left(), yy+fm.height()/2, dr.right()-2, yy+fm.height()/2); 391 paint->drawLine(dr.left(), yy+fm.height()/2, dr.right()-2, yy+fm.height()/2);
414 } 392 }
415 393
416 } 394 }
417 pa.end(); 395 pa.end();
418 396
419} 397}
420void KOAgendaItem::resizePixmap( int w , int h ) 398void KOAgendaItem::resizePixmap( int w , int h )
421{ 399{
422 paintPix()->resize( w, h ); 400 paintPix()->resize( w, h );
423 paintPixSel()->resize( w, h ); 401 paintPixSel()->resize( w, h );
424 402
425} 403}
426QPixmap * KOAgendaItem::paintPix() 404QPixmap * KOAgendaItem::paintPix()
427{ 405{
428 static QPixmap* mPaintPix = 0; 406 static QPixmap* mPaintPix = 0;
429 if ( ! mPaintPix ) 407 if ( ! mPaintPix )
430 mPaintPix = new QPixmap(1,1); 408 mPaintPix = new QPixmap(1,1);
431 return mPaintPix ; 409 return mPaintPix ;
432} 410}
433QPixmap * KOAgendaItem::paintPixAllday() 411QPixmap * KOAgendaItem::paintPixAllday()
434{ 412{
435 static QPixmap* mPaintPixA = 0; 413 static QPixmap* mPaintPixA = 0;
436 if ( ! mPaintPixA ) 414 if ( ! mPaintPixA )
437 mPaintPixA = new QPixmap(1,1); 415 mPaintPixA = new QPixmap(1,1);
438 return mPaintPixA ; 416 return mPaintPixA ;
439} 417}
440QPixmap * KOAgendaItem::paintPixSel() 418QPixmap * KOAgendaItem::paintPixSel()
441{ 419{
442 static QPixmap* mPaintPixSel = 0; 420 static QPixmap* mPaintPixSel = 0;
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;
567 mCellYBottom = YBottom; 576 mCellYBottom = YBottom;
568} 577}
569 578
570void KOAgendaItem::setCellXWidth(int xwidth) 579void KOAgendaItem::setCellXWidth(int xwidth)
571{ 580{
572 mCellXWidth = xwidth; 581 mCellXWidth = xwidth;
573} 582}
574 583
575void KOAgendaItem::setCellX(int XLeft, int XRight) 584void KOAgendaItem::setCellX(int XLeft, int XRight)
576{ 585{
577 mCellX = XLeft; 586 mCellX = XLeft;
578 mCellXWidth = XRight; 587 mCellXWidth = XRight;
579} 588}
580 589
581void KOAgendaItem::setCellY(int YTop, int YBottom) 590void KOAgendaItem::setCellY(int YTop, int YBottom)
582{ 591{
583 mCellYTop = YTop; 592 mCellYTop = YTop;
584 mCellYBottom = YBottom; 593 mCellYBottom = YBottom;
585} 594}
586 595
587void KOAgendaItem::setSubCell(int subCell) 596void KOAgendaItem::setSubCell(int subCell)
588{ 597{
589 mSubCell = subCell; 598 mSubCell = subCell;
590} 599}
591 600
592void KOAgendaItem::setSubCells(int subCells) 601void KOAgendaItem::setSubCells(int subCells)
593{ 602{
594 mSubCells = subCells; 603 mSubCells = subCells;
595} 604}
596 605
597void KOAgendaItem::setMultiItem(KOAgendaItem *first,KOAgendaItem *next, 606void KOAgendaItem::setMultiItem(KOAgendaItem *first,KOAgendaItem *next,
598 KOAgendaItem *last) 607 KOAgendaItem *last)
599{ 608{
600 mFirstMultiItem = first; 609 mFirstMultiItem = first;
601 mNextMultiItem = next; 610 mNextMultiItem = next;
602 mLastMultiItem = last; 611 mLastMultiItem = last;
603} 612}
604 613
605void KOAgendaItem::startMove() 614void KOAgendaItem::startMove()
606{ 615{
607 mStartCellX = mCellX; 616 mStartCellX = mCellX;
608 mStartCellXWidth = mCellXWidth; 617 mStartCellXWidth = mCellXWidth;
609 mStartCellYTop = mCellYTop; 618 mStartCellYTop = mCellYTop;
610 mStartCellYBottom = mCellYBottom; 619 mStartCellYBottom = mCellYBottom;
611} 620}
612 621
613void KOAgendaItem::resetMove() 622void KOAgendaItem::resetMove()
614{ 623{
615 mCellX = mStartCellX; 624 mCellX = mStartCellX;
616 mCellXWidth = mStartCellXWidth; 625 mCellXWidth = mStartCellXWidth;
617 mCellYTop = mStartCellYTop; 626 mCellYTop = mStartCellYTop;
618 mCellYBottom = mStartCellYBottom; 627 mCellYBottom = mStartCellYBottom;
619} 628}
620 629
621void KOAgendaItem::moveRelative(int dx, int dy) 630void KOAgendaItem::moveRelative(int dx, int dy)
622{ 631{
623 int newX = cellX() + dx; 632 int newX = cellX() + dx;
624 int newXWidth = cellXWidth() + dx; 633 int newXWidth = cellXWidth() + dx;
625 int newYTop = cellYTop() + dy; 634 int newYTop = cellYTop() + dy;
626 int newYBottom = cellYBottom() + dy; 635 int newYBottom = cellYBottom() + dy;
627 setCellXY(newX,newYTop,newYBottom); 636 setCellXY(newX,newYTop,newYBottom);
628 setCellXWidth(newXWidth); 637 setCellXWidth(newXWidth);
629} 638}
630 639
631void KOAgendaItem::expandTop(int dy) 640void KOAgendaItem::expandTop(int dy)
632{ 641{
633 int newYTop = cellYTop() + dy; 642 int newYTop = cellYTop() + dy;
634 int newYBottom = cellYBottom(); 643 int newYBottom = cellYBottom();
635 if (newYTop > newYBottom) newYTop = newYBottom; 644 if (newYTop > newYBottom) newYTop = newYBottom;
636 setCellY(newYTop, newYBottom); 645 setCellY(newYTop, newYBottom);
637} 646}
638 647
639void KOAgendaItem::expandBottom(int dy) 648void KOAgendaItem::expandBottom(int dy)
640{ 649{
641 int newYTop = cellYTop(); 650 int newYTop = cellYTop();
642 int newYBottom = cellYBottom() + dy; 651 int newYBottom = cellYBottom() + dy;
643 if (newYBottom < newYTop) newYBottom = newYTop; 652 if (newYBottom < newYTop) newYBottom = newYTop;
644 setCellY(newYTop, newYBottom); 653 setCellY(newYTop, newYBottom);
645} 654}
646 655