-rw-r--r-- | korganizer/koagendaitem.cpp | 720 |
1 files changed, 720 insertions, 0 deletions
diff --git a/korganizer/koagendaitem.cpp b/korganizer/koagendaitem.cpp new file mode 100644 index 0000000..02fd33b --- a/dev/null +++ b/korganizer/koagendaitem.cpp | |||
@@ -0,0 +1,720 @@ | |||
1 | /* | ||
2 | This file is part of KOrganizer. | ||
3 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> | ||
4 | |||
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 | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | |||
20 | #include <qlabel.h> | ||
21 | #include <qlayout.h> | ||
22 | #include <qhbox.h> | ||
23 | #include <qvbox.h> | ||
24 | #include <qtooltip.h> | ||
25 | #include <qwhatsthis.h> | ||
26 | #include <qdragobject.h> | ||
27 | #include <qdrawutil.h> | ||
28 | #include <qpainter.h> | ||
29 | |||
30 | #include <kiconloader.h> | ||
31 | #include <kdebug.h> | ||
32 | #include <kglobal.h> | ||
33 | #include <klocale.h> | ||
34 | #ifndef DESKTOP_VERSION | ||
35 | #include <qpe/qpeapplication.h> | ||
36 | #define AGENDA_ICON_SIZE 5 | ||
37 | #else | ||
38 | #define AGENDA_ICON_SIZE 7 | ||
39 | #endif | ||
40 | #include <libkcal/icaldrag.h> | ||
41 | #include <libkcal/vcaldrag.h> | ||
42 | #include <libkdepim/kincidenceformatter.h> | ||
43 | extern int globalFlagBlockAgenda; | ||
44 | extern int globalFlagBlockAgendaItemPaint; | ||
45 | extern int globalFlagBlockAgendaItemUpdate; | ||
46 | |||
47 | #include "koprefs.h" | ||
48 | |||
49 | #include "koagendaitem.h" | ||
50 | #include "koagendaitem.moc" | ||
51 | |||
52 | |||
53 | //-------------------------------------------------------------------------- | ||
54 | |||
55 | QToolTipGroup *KOAgendaItem::mToolTipGroup = 0; | ||
56 | |||
57 | //-------------------------------------------------------------------------- | ||
58 | |||
59 | KOAgendaItem::KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent,bool allday, | ||
60 | const char *name,WFlags) : | ||
61 | QWidget(parent, name), mIncidence(incidence), mDate(qd) | ||
62 | { | ||
63 | #ifndef DESKTOP_VERSION | ||
64 | QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); | ||
65 | #endif | ||
66 | int wflags = getWFlags() |WRepaintNoErase;// WResizeNoErase | ||
67 | setWFlags ( wflags); | ||
68 | mAllDay = allday; | ||
69 | init ( incidence, qd ); | ||
70 | setMouseTracking(true); | ||
71 | //setAcceptDrops(true); | ||
72 | xPaintCoord = -1; | ||
73 | yPaintCoord = -1; | ||
74 | } | ||
75 | |||
76 | void KOAgendaItem::init ( Incidence *incidence, QDate qd ) | ||
77 | { | ||
78 | mIncidence = incidence; | ||
79 | mDate = qd; | ||
80 | mFirstMultiItem = 0; | ||
81 | mNextMultiItem = 0; | ||
82 | mLastMultiItem = 0; | ||
83 | computeText(); | ||
84 | |||
85 | if ( (incidence->type() == "Todo") && | ||
86 | ( !((static_cast<Todo*>(incidence))->isCompleted()) && | ||
87 | ((static_cast<Todo*>(incidence))->dtDue().date() <= QDate::currentDate()) ) ) { | ||
88 | if ( (static_cast<Todo*>(incidence))->dtDue() < QDateTime::currentDateTime().date()) | ||
89 | mBackgroundColor = KOPrefs::instance()->mTodoOverdueColor ; | ||
90 | else | ||
91 | mBackgroundColor = KOPrefs::instance()->mTodoDueTodayColor; | ||
92 | } | ||
93 | else { | ||
94 | QStringList categories = mIncidence->categories(); | ||
95 | QString cat = categories.first(); | ||
96 | if (cat.isEmpty()) { | ||
97 | mBackgroundColor =KOPrefs::instance()->mEventColor; | ||
98 | } else { | ||
99 | mBackgroundColor = *KOPrefs::instance()->categoryColor(cat); | ||
100 | } | ||
101 | } | ||
102 | mColorGroup = QColorGroup( mBackgroundColor.light(), | ||
103 | mBackgroundColor.dark(),mBackgroundColor.light(), | ||
104 | mBackgroundColor.dark(),mBackgroundColor, black, mBackgroundColor) ; | ||
105 | setBackgroundColor( mBackgroundColor ); | ||
106 | |||
107 | setCellXY(0,0,1); | ||
108 | setCellXWidth(0); | ||
109 | setSubCell(0); | ||
110 | setSubCells(1); | ||
111 | setMultiItem(0,0,0); | ||
112 | startMove(); | ||
113 | mSelected = true; | ||
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); | ||
138 | mFontPixelSize = fontinf.height();; | ||
139 | hide(); | ||
140 | xPaintCoord = -1; | ||
141 | yPaintCoord = -1; | ||
142 | } | ||
143 | |||
144 | |||
145 | KOAgendaItem::~KOAgendaItem() | ||
146 | { | ||
147 | // qDebug("deleteKOAgendaItem::~KOAgendaItem( "); | ||
148 | |||
149 | } | ||
150 | |||
151 | void KOAgendaItem::recreateIncidence() | ||
152 | { | ||
153 | Incidence* newInc = mIncidence->clone(); | ||
154 | newInc->recreate(); | ||
155 | if ( mIncidence->doesRecur() ) { | ||
156 | mIncidence->addExDate( mDate ); | ||
157 | newInc->recurrence()->unsetRecurs(); | ||
158 | int len = mIncidence->dtStart().secsTo( ((Event*)mIncidence)->dtEnd()); | ||
159 | QTime tim = mIncidence->dtStart().time(); | ||
160 | newInc->setDtStart( QDateTime(mDate, tim) ); | ||
161 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); | ||
162 | } | ||
163 | mIncidence = newInc; | ||
164 | } | ||
165 | bool KOAgendaItem::updateIcons(QPainter * p, bool horLayout) | ||
166 | { | ||
167 | int size = AGENDA_ICON_SIZE; | ||
168 | |||
169 | int yOff = 0; | ||
170 | int xOff = 0; | ||
171 | int x = pos().x() +3; | ||
172 | int y; | ||
173 | if ( mAllDay ) | ||
174 | y = pos().y()+3; | ||
175 | else | ||
176 | y = mCellYTop * ( height() / cellHeight() ) +3; | ||
177 | if (mIncidence->cancelled()) { | ||
178 | int xpos = xOff*( 1 +AGENDA_ICON_SIZE )+x; | ||
179 | int ypos = yOff*( 1 +AGENDA_ICON_SIZE)+y; | ||
180 | p->drawLine( xpos, ypos, xpos+AGENDA_ICON_SIZE-1, ypos+AGENDA_ICON_SIZE-1 ); | ||
181 | p->drawLine( xpos, ypos+AGENDA_ICON_SIZE-1, xpos+AGENDA_ICON_SIZE-1, ypos ); | ||
182 | if ( horLayout ) | ||
183 | ++xOff; | ||
184 | else | ||
185 | ++yOff; | ||
186 | } | ||
187 | if (mIncidence->isAlarmEnabled()) { | ||
188 | p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, red ); | ||
189 | if ( horLayout ) | ||
190 | ++xOff; | ||
191 | else | ||
192 | ++yOff; | ||
193 | } | ||
194 | if (mIncidence->recurrence()->doesRecur()) { | ||
195 | p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, blue ); | ||
196 | if ( horLayout ) | ||
197 | ++xOff; | ||
198 | else | ||
199 | ++yOff; | ||
200 | } | ||
201 | if (mIncidence->description().length() > 0) { | ||
202 | p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkGreen ); | ||
203 | if ( horLayout ) | ||
204 | ++xOff; | ||
205 | else | ||
206 | ++yOff; | ||
207 | } | ||
208 | if (mIncidence->isReadOnly()) { | ||
209 | p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, white ); | ||
210 | if ( horLayout ) | ||
211 | ++xOff; | ||
212 | else | ||
213 | ++yOff; | ||
214 | } | ||
215 | |||
216 | if (mIncidence->attendeeCount()>0) { | ||
217 | |||
218 | if (mIncidence->organizer() == KOPrefs::instance()->email()) { | ||
219 | p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, black ); | ||
220 | if ( horLayout ) | ||
221 | ++xOff; | ||
222 | else | ||
223 | ++yOff; | ||
224 | } else { | ||
225 | Attendee *me = mIncidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); | ||
226 | if (me!=0) { | ||
227 | |||
228 | |||
229 | } else { | ||
230 | p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, yellow ); | ||
231 | if ( horLayout ) | ||
232 | ++xOff; | ||
233 | else | ||
234 | ++yOff; | ||
235 | |||
236 | } | ||
237 | p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkYellow ); | ||
238 | if ( horLayout ) | ||
239 | ++xOff; | ||
240 | else | ||
241 | ++yOff; | ||
242 | |||
243 | } | ||
244 | |||
245 | } | ||
246 | return ( yOff || xOff ); | ||
247 | } | ||
248 | |||
249 | |||
250 | void KOAgendaItem::select(bool selected) | ||
251 | { | ||
252 | //qDebug("select %d %d",firstMultiItem(), nextMultiItem() ); | ||
253 | if (mSelected == selected) return; | ||
254 | mSelected = selected; | ||
255 | if ( ! isVisible() ) | ||
256 | return; | ||
257 | if ( firstMultiItem() ) | ||
258 | firstMultiItem()->select( selected ); | ||
259 | if ( !firstMultiItem() && nextMultiItem() ) { | ||
260 | KOAgendaItem * placeItem = nextMultiItem(); | ||
261 | while ( placeItem ) { | ||
262 | placeItem->select( selected ); | ||
263 | placeItem = placeItem->nextMultiItem(); | ||
264 | } | ||
265 | } | ||
266 | globalFlagBlockAgendaItemUpdate = 0; | ||
267 | paintMe( selected ); | ||
268 | globalFlagBlockAgendaItemUpdate = 1; | ||
269 | repaint( false ); | ||
270 | } | ||
271 | |||
272 | |||
273 | /* | ||
274 | The eventFilter has to filter the mouse events of the agenda item childs. The | ||
275 | events are fed into the event handling method of KOAgendaItem. This allows the | ||
276 | KOAgenda to handle the KOAgendaItems by using an eventFilter. | ||
277 | */ | ||
278 | bool KOAgendaItem::eventFilter ( QObject *object, QEvent *e ) | ||
279 | { | ||
280 | if (e->type() == QEvent::MouseButtonPress || | ||
281 | e->type() == QEvent::MouseButtonDblClick || | ||
282 | e->type() == QEvent::MouseButtonRelease || | ||
283 | e->type() == QEvent::MouseMove) { | ||
284 | QMouseEvent *me = (QMouseEvent *)e; | ||
285 | QPoint itemPos = this->mapFromGlobal(((QWidget *)object)-> | ||
286 | mapToGlobal(me->pos())); | ||
287 | QMouseEvent returnEvent (e->type(),itemPos,me->button(),me->state()); | ||
288 | return event(&returnEvent); | ||
289 | } else { | ||
290 | return false; | ||
291 | } | ||
292 | } | ||
293 | void KOAgendaItem::repaintMe( ) | ||
294 | { | ||
295 | paintMe ( mSelected ); | ||
296 | } | ||
297 | void KOAgendaItem::paintMe( bool selected, QPainter* paint ) | ||
298 | { | ||
299 | if ( globalFlagBlockAgendaItemUpdate && ! selected) | ||
300 | return; | ||
301 | QPainter pa; | ||
302 | |||
303 | if ( mSelected ) { | ||
304 | pa.begin( paintPixSel() ); | ||
305 | } else { | ||
306 | if ( mAllDay ) | ||
307 | pa.begin( paintPixAllday() ); | ||
308 | else | ||
309 | pa.begin( paintPix() ); | ||
310 | } | ||
311 | int x, yy, w, h; | ||
312 | float nfh; | ||
313 | x = pos().x(); w = width(); h = height (); | ||
314 | if ( mAllDay ) | ||
315 | yy = y(); | ||
316 | else | ||
317 | yy = mCellYTop * ( height() / cellHeight() ); | ||
318 | xPaintCoord= x; | ||
319 | yPaintCoord = yy; | ||
320 | wPaintCoord = width(); | ||
321 | hPaintCoord = height(); | ||
322 | //qDebug("paintMe %s %d %d %d %d",incidence()->summary().latin1(), x, yy, width(), height()); | ||
323 | if ( paint == 0 ) | ||
324 | paint = &pa; | ||
325 | bool horLayout = ( w < h ); | ||
326 | int maxhei = mFontPixelSize+4; | ||
327 | if ( horLayout ) | ||
328 | maxhei += AGENDA_ICON_SIZE -4; | ||
329 | bool small = ( h < maxhei ); | ||
330 | if ( ! small ) | ||
331 | paint->setFont(KOPrefs::instance()->mAgendaViewFont); | ||
332 | else { | ||
333 | QFont f = KOPrefs::instance()->mAgendaViewFont; | ||
334 | f.setBold( false ); | ||
335 | int fh = f.pointSize(); | ||
336 | nfh = (((float)height())/(float)(mFontPixelSize+4))*fh; | ||
337 | if ( nfh < 6 ) | ||
338 | nfh = 6; | ||
339 | f.setPointSize( nfh ); | ||
340 | paint->setFont(f); | ||
341 | } | ||
342 | paint->fillRect ( x, yy, w, h, mBackgroundColor ); | ||
343 | static const QPixmap completedPxmp = SmallIcon("greenhook16"); | ||
344 | static const QPixmap overduePxmp = SmallIcon("redcross16"); | ||
345 | if ( mIncidence->type() == "Todo" ) { | ||
346 | Todo* tempTodo = static_cast<Todo*>(mIncidence); | ||
347 | int xx = pos().x()+(width()-completedPxmp.width()-3 ); | ||
348 | int yyy = yy+3; | ||
349 | if ( tempTodo->isCompleted() ) | ||
350 | paint->drawPixmap ( xx, yyy, completedPxmp ); | ||
351 | else { | ||
352 | paint->drawPixmap ( xx, yyy, overduePxmp ); | ||
353 | |||
354 | } | ||
355 | } | ||
356 | bool addIcon = false; | ||
357 | if ( ! small || w > 3 * h || h > 3* w ) | ||
358 | addIcon = updateIcons( paint, horLayout ); | ||
359 | |||
360 | qDrawShadePanel (paint, x, yy, w, h, mColorGroup, selected , 2, 0); | ||
361 | //qDebug("draw rect %d %d %d %d ",x, yy, w, h ); | ||
362 | if ( ! small ) { | ||
363 | x += 3; yy += 3;w -= 6; h-= 5; | ||
364 | } else { | ||
365 | x += 2; yy += 1;w -= 4; h-= 4; | ||
366 | if ( nfh < 6.01 ) { | ||
367 | yy -= 2; | ||
368 | h += 4; | ||
369 | } | ||
370 | else | ||
371 | if ( nfh < h -2 ) | ||
372 | ++yy; | ||
373 | } | ||
374 | int align; | ||
375 | #ifndef DESKTOP_VERSION | ||
376 | align = ( AlignLeft|WordBreak|AlignTop); | ||
377 | #else | ||
378 | align = ( AlignLeft|BreakAnywhere|WordBreak|AlignTop); | ||
379 | #endif | ||
380 | if ( addIcon ) { | ||
381 | if ( ! horLayout ) { | ||
382 | x += AGENDA_ICON_SIZE+3; | ||
383 | w -= (AGENDA_ICON_SIZE+3); | ||
384 | } | ||
385 | else { | ||
386 | yy+= AGENDA_ICON_SIZE+2; | ||
387 | h -=(AGENDA_ICON_SIZE+3); | ||
388 | } | ||
389 | } | ||
390 | int colsum = mBackgroundColor.red() + mBackgroundColor.green() + mBackgroundColor.blue(); | ||
391 | if ( colsum < 250 ) | ||
392 | paint->setPen ( white); | ||
393 | if ( x < 0 ) { | ||
394 | w = w+x-3; | ||
395 | x = 3; | ||
396 | if ( w > parentWidget()->width() ){ | ||
397 | w = parentWidget()->width() - 6; | ||
398 | #ifndef DESKTOP_VERSION | ||
399 | align = ( AlignCenter|WordBreak); | ||
400 | #else | ||
401 | align = ( AlignCenter|BreakAnywhere|WordBreak); | ||
402 | #endif | ||
403 | |||
404 | } | ||
405 | } | ||
406 | QRect dr; | ||
407 | paint->drawText ( x, yy, w, h, align, mDisplayedText, -1, &dr ); | ||
408 | if ( mIncidence->cancelled() ){ | ||
409 | if ( ! small ) { | ||
410 | QFontMetrics fm ( paint->font() ); | ||
411 | paint->drawLine(dr.left(), yy+fm.height()/2, dr.right()-2, yy+fm.height()/2); | ||
412 | } | ||
413 | |||
414 | } | ||
415 | pa.end(); | ||
416 | |||
417 | } | ||
418 | void KOAgendaItem::resizePixmap( int w , int h ) | ||
419 | { | ||
420 | paintPix()->resize( w, h ); | ||
421 | paintPixSel()->resize( w, h ); | ||
422 | |||
423 | } | ||
424 | QPixmap * KOAgendaItem::paintPix() | ||
425 | { | ||
426 | static QPixmap* mPaintPix = 0; | ||
427 | if ( ! mPaintPix ) | ||
428 | mPaintPix = new QPixmap(); | ||
429 | return mPaintPix ; | ||
430 | } | ||
431 | QPixmap * KOAgendaItem::paintPixAllday() | ||
432 | { | ||
433 | static QPixmap* mPaintPixA = 0; | ||
434 | if ( ! mPaintPixA ) | ||
435 | mPaintPixA = new QPixmap(); | ||
436 | return mPaintPixA ; | ||
437 | } | ||
438 | QPixmap * KOAgendaItem::paintPixSel() | ||
439 | { | ||
440 | static QPixmap* mPaintPixSel = 0; | ||
441 | if ( ! mPaintPixSel ) | ||
442 | mPaintPixSel = new QPixmap(); | ||
443 | return mPaintPixSel ; | ||
444 | } | ||
445 | void KOAgendaItem::paintEvent ( QPaintEvent *e ) | ||
446 | { | ||
447 | |||
448 | if ( globalFlagBlockAgendaItemPaint ) | ||
449 | return; | ||
450 | if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 ) | ||
451 | return; | ||
452 | int yy; | ||
453 | if ( mAllDay ) | ||
454 | yy = y(); | ||
455 | else | ||
456 | yy = mCellYTop * ( height() / cellHeight() ); | ||
457 | int xx = x(); | ||
458 | if ( xPaintCoord != xx || yPaintCoord != yy || | ||
459 | wPaintCoord != width() || hPaintCoord != height()) { | ||
460 | xPaintCoord= xx; | ||
461 | yPaintCoord = yy; | ||
462 | wPaintCoord = width(); | ||
463 | hPaintCoord = height(); | ||
464 | globalFlagBlockAgendaItemUpdate = 0; | ||
465 | paintMe( mSelected ); | ||
466 | //qDebug("calling paintMe "); | ||
467 | globalFlagBlockAgendaItemUpdate = 1; | ||
468 | } | ||
469 | int rx, ry, rw, rh; | ||
470 | rx = e->rect().x(); | ||
471 | ry = e->rect().y(); | ||
472 | rw = e->rect().width(); | ||
473 | rh = e->rect().height(); | ||
474 | //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height()); | ||
475 | |||
476 | QPixmap* paintFrom ; | ||
477 | if ( mSelected ) { | ||
478 | paintFrom = paintPixSel(); | ||
479 | } else { | ||
480 | if ( mAllDay ) | ||
481 | paintFrom = paintPixAllday(); | ||
482 | else | ||
483 | paintFrom = paintPix(); | ||
484 | } | ||
485 | bitBlt (this, rx, ry, paintFrom, x()+rx ,yPaintCoord+ry, rw, rh ,CopyROP); | ||
486 | } | ||
487 | void KOAgendaItem::computeText() | ||
488 | { | ||
489 | mDisplayedText = mIncidence->summary(); | ||
490 | if ( (mIncidence->type() == "Todo") ) { | ||
491 | if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() ) | ||
492 | mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")"; | ||
493 | else if ( !(mIncidence->doesFloat())) | ||
494 | mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")"; | ||
495 | |||
496 | |||
497 | |||
498 | } else { | ||
499 | if ( !(mIncidence->doesFloat())) | ||
500 | mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + "-" + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ; | ||
501 | |||
502 | if ( mAllDay ) { | ||
503 | if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) { | ||
504 | mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true) ; | ||
505 | } | ||
506 | } | ||
507 | |||
508 | } | ||
509 | |||
510 | if ( !mIncidence->location().isEmpty() ) { | ||
511 | if ( mAllDay ) | ||
512 | mDisplayedText += " ("; | ||
513 | else | ||
514 | mDisplayedText += "\n("; | ||
515 | mDisplayedText += mIncidence->location() +")"; | ||
516 | } | ||
517 | } | ||
518 | void KOAgendaItem::updateItem() | ||
519 | { | ||
520 | computeText(); | ||
521 | |||
522 | //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y()); | ||
523 | paintMe( mSelected ); | ||
524 | repaint( false); | ||
525 | } | ||
526 | |||
527 | void KOAgendaItem::resizeEvent ( QResizeEvent *ev ) | ||
528 | { | ||
529 | //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1()); | ||
530 | paintMe( mSelected ); | ||
531 | repaint( false ); | ||
532 | } | ||
533 | |||
534 | /* | ||
535 | Return height of item in units of agenda cells | ||
536 | */ | ||
537 | int KOAgendaItem::cellHeight() | ||
538 | { | ||
539 | int ret = mCellYBottom - mCellYTop + 1; | ||
540 | if ( ret <= 0 ) { | ||
541 | ret = 1; | ||
542 | mCellYBottom = 0; | ||
543 | mCellYTop = 0; | ||
544 | } | ||
545 | return ret; | ||
546 | } | ||
547 | |||
548 | /* | ||
549 | Return height of item in units of agenda cells | ||
550 | */ | ||
551 | int KOAgendaItem::cellWidth() | ||
552 | { | ||
553 | return mCellXWidth - mCellX + 1; | ||
554 | } | ||
555 | |||
556 | void KOAgendaItem::setItemDate(QDate qd) | ||
557 | { | ||
558 | mDate = qd; | ||
559 | } | ||
560 | |||
561 | void KOAgendaItem::setCellXY(int X, int YTop, int YBottom) | ||
562 | { | ||
563 | mCellX = X; | ||
564 | mCellYTop = YTop; | ||
565 | mCellYBottom = YBottom; | ||
566 | } | ||
567 | |||
568 | void KOAgendaItem::setCellXWidth(int xwidth) | ||
569 | { | ||
570 | mCellXWidth = xwidth; | ||
571 | } | ||
572 | |||
573 | void KOAgendaItem::setCellX(int XLeft, int XRight) | ||
574 | { | ||
575 | mCellX = XLeft; | ||
576 | mCellXWidth = XRight; | ||
577 | } | ||
578 | |||
579 | void KOAgendaItem::setCellY(int YTop, int YBottom) | ||
580 | { | ||
581 | mCellYTop = YTop; | ||
582 | mCellYBottom = YBottom; | ||
583 | } | ||
584 | |||
585 | void KOAgendaItem::setSubCell(int subCell) | ||
586 | { | ||
587 | mSubCell = subCell; | ||
588 | } | ||
589 | |||
590 | void KOAgendaItem::setSubCells(int subCells) | ||
591 | { | ||
592 | mSubCells = subCells; | ||
593 | } | ||
594 | |||
595 | void KOAgendaItem::setMultiItem(KOAgendaItem *first,KOAgendaItem *next, | ||
596 | KOAgendaItem *last) | ||
597 | { | ||
598 | mFirstMultiItem = first; | ||
599 | mNextMultiItem = next; | ||
600 | mLastMultiItem = last; | ||
601 | } | ||
602 | |||
603 | void KOAgendaItem::startMove() | ||
604 | { | ||
605 | mStartCellX = mCellX; | ||
606 | mStartCellXWidth = mCellXWidth; | ||
607 | mStartCellYTop = mCellYTop; | ||
608 | mStartCellYBottom = mCellYBottom; | ||
609 | } | ||
610 | |||
611 | void KOAgendaItem::resetMove() | ||
612 | { | ||
613 | mCellX = mStartCellX; | ||
614 | mCellXWidth = mStartCellXWidth; | ||
615 | mCellYTop = mStartCellYTop; | ||
616 | mCellYBottom = mStartCellYBottom; | ||
617 | } | ||
618 | |||
619 | void KOAgendaItem::moveRelative(int dx, int dy) | ||
620 | { | ||
621 | int newX = cellX() + dx; | ||
622 | int newXWidth = cellXWidth() + dx; | ||
623 | int newYTop = cellYTop() + dy; | ||
624 | int newYBottom = cellYBottom() + dy; | ||
625 | setCellXY(newX,newYTop,newYBottom); | ||
626 | setCellXWidth(newXWidth); | ||
627 | } | ||
628 | |||
629 | void KOAgendaItem::expandTop(int dy) | ||
630 | { | ||
631 | int newYTop = cellYTop() + dy; | ||
632 | int newYBottom = cellYBottom(); | ||
633 | if (newYTop > newYBottom) newYTop = newYBottom; | ||
634 | setCellY(newYTop, newYBottom); | ||
635 | } | ||
636 | |||
637 | void KOAgendaItem::expandBottom(int dy) | ||
638 | { | ||
639 | int newYTop = cellYTop(); | ||
640 | int newYBottom = cellYBottom() + dy; | ||
641 | if (newYBottom < newYTop) newYBottom = newYTop; | ||
642 | setCellY(newYTop, newYBottom); | ||
643 | } | ||
644 | |||
645 | void KOAgendaItem::expandLeft(int dx) | ||
646 | { | ||
647 | int newX = cellX() + dx; | ||
648 | int newXWidth = cellXWidth(); | ||
649 | if (newX > newXWidth) newX = newXWidth; | ||
650 | setCellX(newX,newXWidth); | ||
651 | } | ||
652 | |||
653 | void KOAgendaItem::expandRight(int dx) | ||
654 | { | ||
655 | int newX = cellX(); | ||
656 | int newXWidth = cellXWidth() + dx; | ||
657 | if (newXWidth < newX) newXWidth = newX; | ||
658 | setCellX(newX,newXWidth); | ||
659 | } | ||
660 | |||
661 | QToolTipGroup *KOAgendaItem::toolTipGroup() | ||
662 | { | ||
663 | if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); | ||
664 | return mToolTipGroup; | ||
665 | } | ||
666 | |||
667 | void KOAgendaItem::dragEnterEvent( QDragEnterEvent *e ) | ||
668 | { | ||
669 | #ifndef KORG_NODND | ||
670 | if ( ICalDrag::canDecode( e ) || VCalDrag::canDecode( e ) || | ||
671 | !QTextDrag::canDecode( e ) ) { | ||
672 | e->ignore(); | ||
673 | return; | ||
674 | } | ||
675 | e->accept(); | ||
676 | #endif | ||
677 | } | ||
678 | |||
679 | void KOAgendaItem::dropEvent( QDropEvent *e ) | ||
680 | { | ||
681 | #ifndef KORG_NODND | ||
682 | QString text; | ||
683 | if(QTextDrag::decode(e,text)) | ||
684 | { | ||
685 | kdDebug() << "Dropped : " << text << endl; | ||
686 | QStringList emails = QStringList::split(",",text); | ||
687 | for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { | ||
688 | kdDebug() << " Email: " << (*it) << endl; | ||
689 | int pos = (*it).find("<"); | ||
690 | QString name = (*it).left(pos); | ||
691 | QString email = (*it).mid(pos); | ||
692 | if (!email.isEmpty()) { | ||
693 | mIncidence->addAttendee(new Attendee(name,email)); | ||
694 | } | ||
695 | } | ||
696 | } | ||
697 | #endif | ||
698 | } | ||
699 | |||
700 | |||
701 | QPtrList<KOAgendaItem> KOAgendaItem::conflictItems() | ||
702 | { | ||
703 | return mConflictItems; | ||
704 | } | ||
705 | |||
706 | void KOAgendaItem::setConflictItems(QPtrList<KOAgendaItem> ci) | ||
707 | { | ||
708 | mConflictItems = ci; | ||
709 | KOAgendaItem *item; | ||
710 | for ( item=mConflictItems.first(); item != 0; | ||
711 | item=mConflictItems.next() ) { | ||
712 | item->addConflictItem(this); | ||
713 | } | ||
714 | } | ||
715 | |||
716 | void KOAgendaItem::addConflictItem(KOAgendaItem *ci) | ||
717 | { | ||
718 | if (mConflictItems.find(ci)<0) | ||
719 | mConflictItems.append(ci); | ||
720 | } | ||