summaryrefslogtreecommitdiffabout
path: root/korganizer
Unidiff
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagendaitem.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/korganizer/koagendaitem.cpp b/korganizer/koagendaitem.cpp
index b416115..407424d 100644
--- a/korganizer/koagendaitem.cpp
+++ b/korganizer/koagendaitem.cpp
@@ -1,869 +1,873 @@
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#include <qapplication.h> 38#include <qapplication.h>
39#define AGENDA_ICON_SIZE 7 39#define AGENDA_ICON_SIZE 7
40#endif 40#endif
41#include <libkcal/icaldrag.h> 41#include <libkcal/icaldrag.h>
42#include <libkcal/vcaldrag.h> 42#include <libkcal/vcaldrag.h>
43#include <libkcal/kincidenceformatter.h> 43#include <libkcal/kincidenceformatter.h>
44extern int globalFlagBlockAgenda; 44extern int globalFlagBlockAgenda;
45extern int globalFlagBlockAgendaItemPaint; 45extern int globalFlagBlockAgendaItemPaint;
46extern int globalFlagBlockAgendaItemUpdate; 46extern int globalFlagBlockAgendaItemUpdate;
47 47
48#include "koprefs.h" 48#include "koprefs.h"
49 49
50#include "koagendaitem.h" 50#include "koagendaitem.h"
51//#include "koagendaitem.moc" 51//#include "koagendaitem.moc"
52 52
53 53
54//-------------------------------------------------------------------------- 54//--------------------------------------------------------------------------
55 55
56QToolTipGroup *KOAgendaItem::mToolTipGroup = 0; 56QToolTipGroup *KOAgendaItem::mToolTipGroup = 0;
57 57
58//-------------------------------------------------------------------------- 58//--------------------------------------------------------------------------
59 59
60class KOAgendaItemWhatsThis :public QWhatsThis 60class KOAgendaItemWhatsThis :public QWhatsThis
61{ 61{
62public: 62public:
63 KOAgendaItemWhatsThis( KOAgendaItem* view ) : QWhatsThis( view ),_view (view) { }; 63 KOAgendaItemWhatsThis( KOAgendaItem* view ) : QWhatsThis( view ),_view (view) { };
64 64
65protected: 65protected:
66 virtual QString text( const QPoint& ) 66 virtual QString text( const QPoint& )
67 { 67 {
68 return _view->getWhatsThisText() ; 68 return _view->getWhatsThisText() ;
69 } 69 }
70private: 70private:
71 KOAgendaItem * _view; 71 KOAgendaItem * _view;
72}; 72};
73 73
74KOAgendaItem::KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent,bool allday, 74KOAgendaItem::KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent,bool allday,
75 const char *name,WFlags) : 75 const char *name,WFlags) :
76 QWidget(parent, name), mIncidence(incidence), mDate(qd) 76 QWidget(parent, name), mIncidence(incidence), mDate(qd)
77{ 77{
78#ifndef DESKTOP_VERSION 78#ifndef DESKTOP_VERSION
79 //QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); 79 //QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
80#endif 80#endif
81 mKOAgendaItemWhatsThis = new KOAgendaItemWhatsThis(this); 81 mKOAgendaItemWhatsThis = new KOAgendaItemWhatsThis(this);
82 int wflags = getWFlags() |WRepaintNoErase;// WResizeNoErase 82 int wflags = getWFlags() |WRepaintNoErase;// WResizeNoErase
83 setWFlags ( wflags); 83 setWFlags ( wflags);
84 mAllDay = allday; 84 mAllDay = allday;
85 init ( incidence, qd ); 85 init ( incidence, qd );
86 //setMouseTracking(true); 86 //setMouseTracking(true);
87 //setAcceptDrops(true); 87 //setAcceptDrops(true);
88 xPaintCoord = -1; 88 xPaintCoord = -1;
89 yPaintCoord = -1; 89 yPaintCoord = -1;
90} 90}
91QString KOAgendaItem::getWhatsThisText() 91QString KOAgendaItem::getWhatsThisText()
92{ 92{
93 if ( mIncidence ) 93 if ( mIncidence )
94 return KIncidenceFormatter::instance()->getFormattedText( mIncidence, 94 return KIncidenceFormatter::instance()->getFormattedText( mIncidence,
95 KOPrefs::instance()->mWTshowDetails, 95 KOPrefs::instance()->mWTshowDetails,
96 KOPrefs::instance()->mWTshowCreated, 96 KOPrefs::instance()->mWTshowCreated,
97 KOPrefs::instance()->mWTshowChanged); 97 KOPrefs::instance()->mWTshowChanged);
98 return "KOAgendaItem::getWhatsThisText()::internal error"; 98 return "KOAgendaItem::getWhatsThisText()::internal error";
99} 99}
100 100
101void KOAgendaItem::initColor () 101void KOAgendaItem::initColor ()
102{ 102{
103 if ( (mIncidence->typeID() == todoID ) && 103 if ( (mIncidence->typeID() == todoID ) &&
104 ( !((static_cast<Todo*>(mIncidence))->isCompleted()) && 104 ( !((static_cast<Todo*>(mIncidence))->isCompleted()) &&
105 ((static_cast<Todo*>(mIncidence))->dtDue().date() <= QDate::currentDate()) ) ) { 105 ((static_cast<Todo*>(mIncidence))->dtDue().date() <= QDate::currentDate()) ) ) {
106 if ( (static_cast<Todo*>(mIncidence))->dtDue() < QDateTime::currentDateTime().date()) 106 if ( (static_cast<Todo*>(mIncidence))->dtDue() < QDateTime::currentDateTime().date())
107 mBackgroundColor = KOPrefs::instance()->mTodoOverdueColor ; 107 mBackgroundColor = KOPrefs::instance()->mTodoOverdueColor ;
108 else 108 else
109 mBackgroundColor = KOPrefs::instance()->mTodoDueTodayColor; 109 mBackgroundColor = KOPrefs::instance()->mTodoDueTodayColor;
110 } 110 }
111 else { 111 else {
112 QStringList categories = mIncidence->categories(); 112 QStringList categories = mIncidence->categories();
113 QString cat = categories.first(); 113 QString cat = categories.first();
114 if (cat.isEmpty()) { 114 if (cat.isEmpty()) {
115 if ( (mIncidence->typeID() == todoID ) &&((static_cast<Todo*>(mIncidence))->isCompleted()) ) 115 if ( (mIncidence->typeID() == todoID ) &&((static_cast<Todo*>(mIncidence))->isCompleted()) )
116 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor; 116 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor;
117 else 117 else
118 mBackgroundColor =KOPrefs::instance()->defaultColor( mIncidence->calID() ); 118 mBackgroundColor =KOPrefs::instance()->defaultColor( mIncidence->calID() );
119 } else { 119 } else {
120 mBackgroundColor = *KOPrefs::instance()->categoryColor(cat); 120 mBackgroundColor = *KOPrefs::instance()->categoryColor(cat);
121 if ( (mIncidence->typeID() == todoID ) &&((static_cast<Todo*>(mIncidence))->isCompleted()) ) { 121 if ( (mIncidence->typeID() == todoID ) &&((static_cast<Todo*>(mIncidence))->isCompleted()) ) {
122 if ( mBackgroundColor == KOPrefs::instance()->mEventColor ) 122 if ( mBackgroundColor == KOPrefs::instance()->mEventColor )
123 mBackgroundColor = KOPrefs::instance()->mTodoDoneColor; 123 mBackgroundColor = KOPrefs::instance()->mTodoDoneColor;
124 } 124 }
125 } 125 }
126 126
127 } 127 }
128 128
129 QColor BackgroundColor ( mBackgroundColor ); 129 QColor BackgroundColor ( mBackgroundColor );
130 if ( mIncidence->calID() > 1 ) { 130 if ( mIncidence->calID() > 1 ) {
131 //BackgroundColor = KOPrefs::instance()->defaultColor( mIncidence->calID() ); 131 //BackgroundColor = KOPrefs::instance()->defaultColor( mIncidence->calID() );
132 } 132 }
133 mColorGroup = QColorGroup( BackgroundColor.light(), 133 mColorGroup = QColorGroup( BackgroundColor.light(),
134 BackgroundColor.dark(),BackgroundColor.light(), 134 BackgroundColor.dark(),BackgroundColor.light(),
135 BackgroundColor.dark(),BackgroundColor, black, BackgroundColor) ; 135 BackgroundColor.dark(),BackgroundColor, black, BackgroundColor) ;
136 setBackgroundColor( mBackgroundColor ); 136 setBackgroundColor( mBackgroundColor );
137 mWhiteText = (mBackgroundColor.red() + mBackgroundColor.green() + mBackgroundColor.blue() < 250); 137 mWhiteText = (mBackgroundColor.red() + mBackgroundColor.green() + mBackgroundColor.blue() < 250);
138} 138}
139void KOAgendaItem::init ( Incidence *incidence, QDate qd ) 139void KOAgendaItem::init ( Incidence *incidence, QDate qd )
140{ 140{
141 mIncidence = incidence; 141 mIncidence = incidence;
142 mDate = qd; 142 mDate = qd;
143 mFirstMultiItem = 0; 143 mFirstMultiItem = 0;
144 mNextMultiItem = 0; 144 mNextMultiItem = 0;
145 mLastMultiItem = 0; 145 mLastMultiItem = 0;
146 computeText(); 146 computeText();
147 initColor(); 147 initColor();
148 mConflictItems.clear(); 148 mConflictItems.clear();
149 setCellXY(0,0,1); 149 setCellXY(0,0,1);
150 setCellXWidth(0); 150 setCellXWidth(0);
151 setSubCell(0); 151 setSubCell(0);
152 setSubCells(1); 152 setSubCells(1);
153 setMultiItem(0,0,0); 153 setMultiItem(0,0,0);
154 startMove(); 154 startMove();
155 mSelected = true; 155 mSelected = true;
156 select(false); 156 select(false);
157 QFontMetrics fontinf(KOPrefs::instance()->mAgendaViewFont); 157 QFontMetrics fontinf(KOPrefs::instance()->mAgendaViewFont);
158 mFontPixelSize = fontinf.height();; 158 mFontPixelSize = fontinf.height();;
159 hide(); 159 hide();
160 xPaintCoord = -1; 160 xPaintCoord = -1;
161 yPaintCoord = -1; 161 yPaintCoord = -1;
162} 162}
163 163
164 164
165KOAgendaItem::~KOAgendaItem() 165KOAgendaItem::~KOAgendaItem()
166{ 166{
167#if QT_VERSION >= 0x030000 167#if QT_VERSION >= 0x030000
168 168
169#else 169#else
170 delete mKOAgendaItemWhatsThis; 170 delete mKOAgendaItemWhatsThis;
171#endif 171#endif
172 172
173} 173}
174 174
175void KOAgendaItem::recreateIncidence() 175void KOAgendaItem::recreateIncidence()
176{ 176{
177#if 0 177#if 0
178 Incidence* newInc = mIncidence->clone(); 178 Incidence* newInc = mIncidence->clone();
179 newInc->recreate(); 179 newInc->recreate();
180 if ( mIncidence->doesRecur() ) { 180 if ( mIncidence->doesRecur() ) {
181 mIncidence->addExDate( mDate ); 181 mIncidence->addExDate( mDate );
182 newInc->recurrence()->unsetRecurs(); 182 newInc->recurrence()->unsetRecurs();
183 int len = mIncidence->dtStart().secsTo( ((Event*)mIncidence)->dtEnd()); 183 int len = mIncidence->dtStart().secsTo( ((Event*)mIncidence)->dtEnd());
184 QTime tim = mIncidence->dtStart().time(); 184 QTime tim = mIncidence->dtStart().time();
185 newInc->setDtStart( QDateTime(mDate, tim) ); 185 newInc->setDtStart( QDateTime(mDate, tim) );
186 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); 186 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) );
187 } 187 }
188#endif 188#endif
189 mIncidence = mIncidence->recreateCloneException( mDate ); 189 mIncidence = mIncidence->recreateCloneException( mDate );
190} 190}
191bool KOAgendaItem::updateIcons(QPainter * p, bool horLayout) 191bool KOAgendaItem::updateIcons(QPainter * p, bool horLayout)
192{ 192{
193 int size = AGENDA_ICON_SIZE; 193 int size = AGENDA_ICON_SIZE;
194 194
195 int yOff = 0; 195 int yOff = 0;
196 int xOff = 0; 196 int xOff = 0;
197 int x = pos().x(); 197 int x = pos().x();
198 198
199 if ( x < 0 ) x = 0; 199 if ( x < 0 ) x = 0;
200 x += 3; 200 x += 3;
201 int y; 201 int y;
202 if ( mAllDay ) 202 if ( mAllDay )
203 y = pos().y()+3; 203 y = pos().y()+3;
204 else 204 else
205 y = mCellYTop * ( height() / cellHeight() ) +3; 205 y = mCellYTop * ( height() / cellHeight() ) +3;
206 206
207 207
208 if ( mIncidence->calID() > 1 ) { 208 if ( mIncidence->calID() > 1 ) {
209 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, KOPrefs::instance()->defaultColor( mIncidence->calID() ) ); 209 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, KOPrefs::instance()->defaultColor( mIncidence->calID() ) );
210 p->drawRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x-1, yOff*( 1 +AGENDA_ICON_SIZE)+y-1, AGENDA_ICON_SIZE+2, AGENDA_ICON_SIZE+2 ); 210 p->drawRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x-1, yOff*( 1 +AGENDA_ICON_SIZE)+y-1, AGENDA_ICON_SIZE+2, AGENDA_ICON_SIZE+2 );
211 if ( horLayout ){ 211 if ( horLayout ){
212 ++xOff; 212 ++xOff;
213 ++x; 213 ++x;
214 } 214 }
215 else { 215 else {
216 ++yOff; 216 ++yOff;
217 ++y; 217 ++y;
218 } 218 }
219 } 219 }
220 if (mIncidence->cancelled() && height() < 20 ) { 220 if (mIncidence->cancelled() && height() < 20 ) {
221 int xpos = xOff*( 1 +AGENDA_ICON_SIZE )+x; 221 int xpos = xOff*( 1 +AGENDA_ICON_SIZE )+x;
222 int ypos = yOff*( 1 +AGENDA_ICON_SIZE)+y; 222 int ypos = yOff*( 1 +AGENDA_ICON_SIZE)+y;
223 p->drawLine( xpos, ypos, xpos+AGENDA_ICON_SIZE-1, ypos+AGENDA_ICON_SIZE-1 ); 223 p->drawLine( xpos, ypos, xpos+AGENDA_ICON_SIZE-1, ypos+AGENDA_ICON_SIZE-1 );
224 p->drawLine( xpos, ypos+AGENDA_ICON_SIZE-1, xpos+AGENDA_ICON_SIZE-1, ypos ); 224 p->drawLine( xpos, ypos+AGENDA_ICON_SIZE-1, xpos+AGENDA_ICON_SIZE-1, ypos );
225 if ( horLayout ) 225 if ( horLayout )
226 ++xOff; 226 ++xOff;
227 else 227 else
228 ++yOff; 228 ++yOff;
229 } 229 }
230 if (mIncidence->isAlarmEnabled() && mIncidence->alarmEnabled()) { 230 if (mIncidence->isAlarmEnabled() && mIncidence->alarmEnabled()) {
231 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, red ); 231 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, red );
232 if ( horLayout ) 232 if ( horLayout )
233 ++xOff; 233 ++xOff;
234 else 234 else
235 ++yOff; 235 ++yOff;
236 } 236 }
237 if (mIncidence->doesRecur()) { 237 if (mIncidence->doesRecur()) {
238 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, blue ); 238 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, blue );
239 if ( horLayout ) 239 if ( horLayout )
240 ++xOff; 240 ++xOff;
241 else 241 else
242 ++yOff; 242 ++yOff;
243 } 243 }
244 if (mIncidence->description().length() > 0) { 244 if (mIncidence->description().length() > 0) {
245 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkGreen ); 245 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkGreen );
246 if ( horLayout ) 246 if ( horLayout )
247 ++xOff; 247 ++xOff;
248 else 248 else
249 ++yOff; 249 ++yOff;
250 } 250 }
251 if (mIncidence->isReadOnly()) { 251 if (mIncidence->isReadOnly()) {
252 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, white ); 252 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, white );
253 if ( horLayout ) 253 if ( horLayout )
254 ++xOff; 254 ++xOff;
255 else 255 else
256 ++yOff; 256 ++yOff;
257 } 257 }
258 258
259 if (mIncidence->attendeeCount()>0) { 259 if (mIncidence->attendeeCount()>0) {
260 260
261 if (mIncidence->organizer() == KOPrefs::instance()->email()) { 261 if (mIncidence->organizer() == KOPrefs::instance()->email()) {
262 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, black ); 262 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, black );
263 if ( horLayout ) 263 if ( horLayout )
264 ++xOff; 264 ++xOff;
265 else 265 else
266 ++yOff; 266 ++yOff;
267 } else { 267 } else {
268 Attendee *me = mIncidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 268 Attendee *me = mIncidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
269 if (me!=0) { 269 if (me!=0) {
270 270
271 271
272 } else { 272 } else {
273 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, yellow ); 273 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, yellow );
274 if ( horLayout ) 274 if ( horLayout )
275 ++xOff; 275 ++xOff;
276 else 276 else
277 ++yOff; 277 ++yOff;
278 278
279 } 279 }
280 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkYellow ); 280 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkYellow );
281 if ( horLayout ) 281 if ( horLayout )
282 ++xOff; 282 ++xOff;
283 else 283 else
284 ++yOff; 284 ++yOff;
285 285
286 } 286 }
287 287
288 } 288 }
289 return ( yOff || xOff ); 289 return ( yOff || xOff );
290} 290}
291 291
292 292
293void KOAgendaItem::select(bool selected) 293void KOAgendaItem::select(bool selected)
294{ 294{
295 //qDebug("select %d %d",firstMultiItem(), nextMultiItem() ); 295 //qDebug("select %d %d",firstMultiItem(), nextMultiItem() );
296 if (mSelected == selected) return; 296 if (mSelected == selected) return;
297 mSelected = selected; 297 mSelected = selected;
298 if ( ! isVisible() ) 298 if ( ! isVisible() )
299 return; 299 return;
300 if ( firstMultiItem() ) 300 if ( firstMultiItem() )
301 firstMultiItem()->select( selected ); 301 firstMultiItem()->select( selected );
302 if ( !firstMultiItem() && nextMultiItem() ) { 302 if ( !firstMultiItem() && nextMultiItem() ) {
303 KOAgendaItem * placeItem = nextMultiItem(); 303 KOAgendaItem * placeItem = nextMultiItem();
304 while ( placeItem ) { 304 while ( placeItem ) {
305 placeItem->select( selected ); 305 placeItem->select( selected );
306 placeItem = placeItem->nextMultiItem(); 306 placeItem = placeItem->nextMultiItem();
307 } 307 }
308 } 308 }
309 globalFlagBlockAgendaItemUpdate = 0; 309 globalFlagBlockAgendaItemUpdate = 0;
310 paintMe( selected ); 310 paintMe( selected );
311 globalFlagBlockAgendaItemUpdate = 1; 311 globalFlagBlockAgendaItemUpdate = 1;
312 repaint( false ); 312 repaint( false );
313} 313}
314 314
315 315
316/* 316/*
317 The eventFilter has to filter the mouse events of the agenda item childs. The 317 The eventFilter has to filter the mouse events of the agenda item childs. The
318 events are fed into the event handling method of KOAgendaItem. This allows the 318 events are fed into the event handling method of KOAgendaItem. This allows the
319 KOAgenda to handle the KOAgendaItems by using an eventFilter. 319 KOAgenda to handle the KOAgendaItems by using an eventFilter.
320*/ 320*/
321bool KOAgendaItem::eventFilter ( QObject *object, QEvent *e ) 321bool KOAgendaItem::eventFilter ( QObject *object, QEvent *e )
322{ 322{
323 if (e->type() == QEvent::MouseButtonPress || 323 if (e->type() == QEvent::MouseButtonPress ||
324 e->type() == QEvent::MouseButtonDblClick || 324 e->type() == QEvent::MouseButtonDblClick ||
325 e->type() == QEvent::MouseButtonRelease || 325 e->type() == QEvent::MouseButtonRelease ||
326 e->type() == QEvent::MouseMove) { 326 e->type() == QEvent::MouseMove) {
327 QMouseEvent *me = (QMouseEvent *)e; 327 QMouseEvent *me = (QMouseEvent *)e;
328 QPoint itemPos = this->mapFromGlobal(((QWidget *)object)-> 328 QPoint itemPos = this->mapFromGlobal(((QWidget *)object)->
329 mapToGlobal(me->pos())); 329 mapToGlobal(me->pos()));
330 QMouseEvent returnEvent (e->type(),itemPos,me->button(),me->state()); 330 QMouseEvent returnEvent (e->type(),itemPos,me->button(),me->state());
331 return event(&returnEvent); 331 return event(&returnEvent);
332 } else { 332 } else {
333 return false; 333 return false;
334 } 334 }
335} 335}
336void KOAgendaItem::repaintMe( ) 336void KOAgendaItem::repaintMe( )
337{ 337{
338 paintMe ( mSelected ); 338 paintMe ( mSelected );
339} 339}
340void KOAgendaItem::paintMe( bool selected, QPainter* paint ) 340void KOAgendaItem::paintMe( bool selected, QPainter* paint )
341{ 341{
342 if ( globalFlagBlockAgendaItemUpdate && ! selected) 342 if ( globalFlagBlockAgendaItemUpdate && ! selected)
343 return; 343 return;
344 QPainter pa; 344 QPainter pa;
345 345
346 if ( mSelected ) { 346 if ( mSelected ) {
347 pa.begin( this ); 347 pa.begin( this );
348 } else { 348 } else {
349 if ( mAllDay ) 349 if ( mAllDay )
350 pa.begin( paintPixAllday() ); 350 pa.begin( paintPixAllday() );
351 else 351 else
352 pa.begin( paintPix() ); 352 pa.begin( paintPix() );
353 } 353 }
354 int x, yy, w, h; 354 int x, yy, w, h;
355 float nfh = 7.0; 355 float nfh = 7.0;
356 x = pos().x(); w = width(); h = height (); 356 x = pos().x(); w = width(); h = height ();
357 if ( mAllDay ) 357 if ( mAllDay )
358 yy = y(); 358 yy = y();
359 else 359 else
360 yy = mCellYTop * ( height() / cellHeight() ); 360 yy = mCellYTop * ( height() / cellHeight() );
361 if ( mSelected ) { 361 if ( mSelected ) {
362 pa.translate( -x, -yy ); 362 pa.translate( -x, -yy );
363 } 363 }
364 xPaintCoord= x; 364 xPaintCoord= x;
365 yPaintCoord = yy; 365 yPaintCoord = yy;
366 wPaintCoord = width(); 366 wPaintCoord = width();
367 hPaintCoord = height(); 367 hPaintCoord = height();
368 //qDebug("paintMe %s %d %d %d %d",incidence()->summary().latin1(), x, yy, width(), height()); 368 //qDebug("paintMe %s %d %d %d %d",incidence()->summary().latin1(), x, yy, width(), height());
369 if ( paint == 0 ) 369 if ( paint == 0 )
370 paint = &pa; 370 paint = &pa;
371 bool horLayout = ( w < h ); 371 bool horLayout = ( w < h );
372 int maxhei = mFontPixelSize+4; 372 int maxhei = mFontPixelSize+4;
373 if ( horLayout ) 373 if ( horLayout )
374 maxhei += AGENDA_ICON_SIZE -4; 374 maxhei += AGENDA_ICON_SIZE -4;
375 bool small = ( h < maxhei ); 375 bool small = ( h < maxhei );
376 if ( ! small ) 376 if ( ! small )
377 paint->setFont(KOPrefs::instance()->mAgendaViewFont); 377 paint->setFont(KOPrefs::instance()->mAgendaViewFont);
378 else { 378 else {
379 QFont f = KOPrefs::instance()->mAgendaViewFont; 379 QFont f = KOPrefs::instance()->mAgendaViewFont;
380 f.setBold( false ); 380 f.setBold( false );
381 int fh = f.pointSize(); 381 int fh = f.pointSize();
382 nfh = (((float)height())/(float)(mFontPixelSize+4))*fh; 382 nfh = (((float)height())/(float)(mFontPixelSize+4))*fh;
383 if ( nfh < 6 ) 383 if ( nfh < 6 )
384 nfh = 6; 384 nfh = 6;
385 f.setPointSize( nfh ); 385 f.setPointSize( nfh );
386 paint->setFont(f); 386 paint->setFont(f);
387 } 387 }
388 paint->fillRect ( x, yy, w, h, mBackgroundColor ); 388 paint->fillRect ( x, yy, w, h, mBackgroundColor );
389 static const QPixmap completedPxmp = SmallIcon("greenhook16"); 389 static const QPixmap completedPxmp = SmallIcon("greenhook16");
390 static const QPixmap overduePxmp = SmallIcon("redcross16"); 390 static const QPixmap overduePxmp = SmallIcon("redcross16");
391 if ( mIncidence->typeID() == todoID ) { 391 if ( mIncidence->typeID() == todoID ) {
392 Todo* tempTodo = static_cast<Todo*>(mIncidence); 392 Todo* tempTodo = static_cast<Todo*>(mIncidence);
393 int xx = pos().x()+(width()-completedPxmp.width()-3 ); 393 int xx = pos().x()+(width()-completedPxmp.width()-3 );
394 int yyy = yy+3; 394 int yyy = yy+3;
395 if ( tempTodo->isCompleted() ) 395 if ( tempTodo->isCompleted() )
396 paint->drawPixmap ( xx, yyy, completedPxmp ); 396 paint->drawPixmap ( xx, yyy, completedPxmp );
397 else { 397 else {
398 paint->drawPixmap ( xx, yyy, overduePxmp ); 398 paint->drawPixmap ( xx, yyy, overduePxmp );
399 399
400 } 400 }
401 } 401 }
402 bool addIcon = false; 402 bool addIcon = false;
403 if ( ! small || w > 3 * h || h > 3* w ) 403 if ( ! small || w > 3 * h || h > 3* w )
404 addIcon = updateIcons( paint, horLayout ); 404 addIcon = updateIcons( paint, horLayout );
405 405
406 //qDrawShadePanel (paint, x, yy, w, h, mColorGroup, selected , 2, 0); 406 //qDrawShadePanel (paint, x, yy, w, h, mColorGroup, selected , 2, 0);
407 qDrawWinPanel (paint, x, yy, w, h, mColorGroup, selected ,0); 407 qDrawWinPanel (paint, x, yy, w, h, mColorGroup, selected ,0);
408 //qDebug("draw rect %d %d %d %d ",x, yy, w, h ); 408 //qDebug("draw rect %d %d %d %d ",x, yy, w, h );
409 if ( ! small ) { 409 if ( ! small ) {
410 x += 3; yy += 3;w -= 6; h-= 5; 410 x += 3; yy += 3;w -= 6; h-= 5;
411 } else { 411 } else {
412 x += 2; yy += 1;w -= 4; h-= 4; 412 x += 2; yy += 1;w -= 4; h-= 4;
413 if ( nfh < 6.01 ) { 413 if ( nfh < 6.01 ) {
414 yy -= 2; 414 yy -= 2;
415 h += 4; 415 h += 4;
416 } 416 }
417 else 417 else
418 if ( nfh < h -2 ) 418 if ( nfh < h -2 )
419 ++yy; 419 ++yy;
420 } 420 }
421 int align; 421 int align;
422#ifndef DESKTOP_VERSION 422#ifndef DESKTOP_VERSION
423 align = ( AlignLeft|WordBreak|AlignTop); 423 align = ( AlignLeft|WordBreak|AlignTop);
424#else 424#else
425 align = ( AlignLeft|BreakAnywhere|WordBreak|AlignTop); 425 align = ( AlignLeft|BreakAnywhere|WordBreak|AlignTop);
426#endif 426#endif
427 if ( addIcon ) { 427 if ( addIcon ) {
428 if ( ! horLayout ) { 428 if ( ! horLayout ) {
429 x += AGENDA_ICON_SIZE+3; 429 x += AGENDA_ICON_SIZE+3;
430 w -= (AGENDA_ICON_SIZE+3); 430 w -= (AGENDA_ICON_SIZE+3);
431 } 431 }
432 else { 432 else {
433 yy+= AGENDA_ICON_SIZE+2; 433 yy+= AGENDA_ICON_SIZE+2;
434 h -=(AGENDA_ICON_SIZE+3); 434 h -=(AGENDA_ICON_SIZE+3);
435 } 435 }
436 } 436 }
437 if ( mWhiteText ) 437 if ( mWhiteText )
438 paint->setPen ( white); 438 paint->setPen ( white);
439 if ( x < 0 ) { 439 if ( x < 0 ) {
440 w = w+x-3; 440 w = w+x-3;
441 x = 3; 441 x = 3;
442 if ( !horLayout && addIcon ) 442 if ( !horLayout && addIcon )
443 x += AGENDA_ICON_SIZE+3; 443 x += AGENDA_ICON_SIZE+3;
444 if ( w > parentWidget()->width() ){ 444 if ( w > parentWidget()->width() ){
445 w = parentWidget()->width() - 6; 445 w = parentWidget()->width() - 6;
446#ifndef DESKTOP_VERSION 446#ifndef DESKTOP_VERSION
447 align = ( AlignHCenter|WordBreak|AlignTop); 447 align = ( AlignHCenter|WordBreak|AlignTop);
448#else 448#else
449 align = ( AlignHCenter|BreakAnywhere|WordBreak|AlignTop); 449 align = ( AlignHCenter|BreakAnywhere|WordBreak|AlignTop);
450#endif 450#endif
451 451
452 } 452 }
453 } 453 }
454 QRect dr; 454 QRect dr;
455 if ( w + x > parentWidget()->width() ) 455 if ( w + x > parentWidget()->width() )
456 w = parentWidget()->width()-x; 456 w = parentWidget()->width()-x;
457 paint->drawText ( x, yy, w, h, align, mDisplayedText, -1, &dr ); 457 paint->drawText ( x, yy, w, h, align, mDisplayedText, -1, &dr );
458 //qDebug("%d %d %d %d ", x, yy, w, h ); 458 //qDebug("%d %d %d %d ", x, yy, w, h );
459 if ( mIncidence->cancelled() ){ 459 if ( mIncidence->cancelled() ){
460 460
461 461
462 small = ( height() < 20 ); 462 small = ( height() < 20 );
463 463
464 if ( ! small ) { 464 if ( ! small ) {
465 QFontMetrics fm ( paint->font() ); 465 QFontMetrics fm ( paint->font() );
466 paint->drawLine(dr.left(), yy+fm.height()/2, dr.right()-2, yy+fm.height()/2); 466 paint->drawLine(dr.left(), yy+fm.height()/2, dr.right()-2, yy+fm.height()/2);
467 } 467 }
468 468
469 } 469 }
470 pa.end(); 470 pa.end();
471 471
472} 472}
473 473
474QPixmap * KOAgendaItem::paintPix() 474QPixmap * KOAgendaItem::paintPix()
475{ 475{
476 static QPixmap* mPaintPix = 0; 476 static QPixmap* mPaintPix = 0;
477 if ( ! mPaintPix ) { 477 if ( ! mPaintPix ) {
478 int w = QApplication::desktop()->width(); 478 int w = QApplication::desktop()->width();
479 int h = QApplication::desktop()->height(); 479 int h = QApplication::desktop()->height();
480 mPaintPix = new QPixmap(w,h); 480 mPaintPix = new QPixmap(w,h);
481 } 481 }
482 return mPaintPix ; 482 return mPaintPix ;
483} 483}
484QPixmap * KOAgendaItem::paintPixAllday() 484QPixmap * KOAgendaItem::paintPixAllday()
485{ 485{
486 static QPixmap* mPaintPixA = 0; 486 static QPixmap* mPaintPixA = 0;
487 if ( ! mPaintPixA ) { 487 if ( ! mPaintPixA ) {
488 int w = QApplication::desktop()->width(); 488 int w = QApplication::desktop()->width();
489 int h = QApplication::desktop()->height()/5; 489 int h = QApplication::desktop()->height()/5;
490 mPaintPixA = new QPixmap(w,h); 490 mPaintPixA = new QPixmap(w,h);
491 } 491 }
492 return mPaintPixA ; 492 return mPaintPixA ;
493} 493}
494 494
495void KOAgendaItem::repaintItem() 495void KOAgendaItem::repaintItem()
496{ 496{
497 globalFlagBlockAgendaItemPaint = 0; 497 globalFlagBlockAgendaItemPaint = 0;
498 globalFlagBlockAgenda = 0; 498 globalFlagBlockAgenda = 0;
499 repaint( false ); 499 repaint( false );
500} 500}
501void KOAgendaItem::paintEvent ( QPaintEvent *e ) 501void KOAgendaItem::paintEvent ( QPaintEvent *e )
502{ 502{
503 503
504 if ( globalFlagBlockAgendaItemPaint ) 504 if ( globalFlagBlockAgendaItemPaint )
505 return; 505 return;
506 if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 ) 506 if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 )
507 return; 507 return;
508 int yy; 508 int yy;
509 if ( mAllDay ) 509 if ( mAllDay )
510 yy = y(); 510 yy = y();
511 else 511 else
512 yy = mCellYTop * ( height() / cellHeight() ); 512 yy = mCellYTop * ( height() / cellHeight() );
513 int xx = x(); 513 int xx = x();
514 514
515 if ( xPaintCoord != xx || yPaintCoord != yy || 515 if ( xPaintCoord != xx || yPaintCoord != yy ||
516 wPaintCoord != width() || hPaintCoord != height()) { 516 wPaintCoord != width() || hPaintCoord != height()) {
517 xPaintCoord= xx; 517 xPaintCoord= xx;
518 yPaintCoord = yy; 518 yPaintCoord = yy;
519 wPaintCoord = width(); 519 wPaintCoord = width();
520 hPaintCoord = height(); 520 hPaintCoord = height();
521 globalFlagBlockAgendaItemUpdate = 0; 521 globalFlagBlockAgendaItemUpdate = 0;
522 paintMe( mSelected ); 522 paintMe( mSelected );
523 //qDebug("calling paintMe "); 523 //qDebug("calling paintMe ");
524 globalFlagBlockAgendaItemUpdate = 1; 524 globalFlagBlockAgendaItemUpdate = 1;
525 if ( mSelected ) 525 if ( mSelected )
526 return; 526 return;
527 } 527 }
528 int rx, ry, rw, rh; 528 int rx, ry, rw, rh;
529 rx = e->rect().x(); 529 rx = e->rect().x();
530 ry = e->rect().y(); 530 ry = e->rect().y();
531 rw = e->rect().width(); 531 rw = e->rect().width();
532 rh = e->rect().height(); 532 rh = e->rect().height();
533 //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height()); 533 //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height());
534 534
535 QPixmap* paintFrom ; 535 QPixmap* paintFrom ;
536 if ( mSelected ) { 536 if ( mSelected ) {
537 paintMe( mSelected ); 537 paintMe( mSelected );
538 return; 538 return;
539 } else { 539 } else {
540 if ( mAllDay ) 540 if ( mAllDay )
541 paintFrom = paintPixAllday(); 541 paintFrom = paintPixAllday();
542 else 542 else
543 paintFrom = paintPix(); 543 paintFrom = paintPix();
544 } 544 }
545 xx += rx; 545 xx += rx;
546 546
547 if ( xx < 0 ) { 547 if ( xx < 0 ) {
548 rw = rw + xx; 548 rw = rw + xx;
549 rx -= xx; 549 rx -= xx;
550 xx = 0; 550 xx = 0;
551 if ( rw <= 1 ) { 551 if ( rw <= 1 ) {
552 //qDebug("KOAgendaItem::Width1 <= 1 (%d). Returning. %s",rw,mDisplayedText.latin1()); 552 //qDebug("KOAgendaItem::Width1 <= 1 (%d). Returning. %s",rw,mDisplayedText.latin1());
553 return; 553 return;
554 } 554 }
555 } 555 }
556 if ( paintFrom->width() < xx+rw ) { 556 if ( paintFrom->width() < xx+rw ) {
557 rw = paintFrom->width() - xx; 557 rw = paintFrom->width() - xx;
558 if ( rw <= 1 ) { 558 if ( rw <= 1 ) {
559 //qDebug("KOAgendaItem::Width2 <= 1 (%d). Returning.%s ",rw,mDisplayedText.latin1() ); 559 //qDebug("KOAgendaItem::Width2 <= 1 (%d). Returning.%s ",rw,mDisplayedText.latin1() );
560 return; 560 return;
561 } 561 }
562 } 562 }
563 //qDebug("%d %d %d %d %d %d %d",rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh); 563 //qDebug("%d %d %d %d %d %d %d",rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh);
564 bitBlt (this, rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh ,CopyROP); 564 bitBlt (this, rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh ,CopyROP);
565} 565}
566void KOAgendaItem::computeText() 566void KOAgendaItem::computeText()
567{ 567{
568 mDisplayedText = mIncidence->summary(); 568 mDisplayedText = mIncidence->summary();
569 if ( (mIncidence->typeID() == todoID ) ) { 569 if ( (mIncidence->typeID() == todoID ) ) {
570 if ( static_cast<Todo*>(mIncidence)->hasDueDate() ) { 570 if ( static_cast<Todo*>(mIncidence)->hasDueDate() ) {
571 if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() ) 571 if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() )
572 mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")"; 572 mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")";
573 else if ( !(mIncidence->doesFloat())) 573 else if ( !(mIncidence->doesFloat()))
574 mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")"; 574 mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")";
575 } 575 }
576 } else { 576 } else {
577 if ( !(mIncidence->doesFloat()) && KOPrefs::instance()->mShowTimeInAgenda) 577 if ( !(mIncidence->doesFloat()) && KOPrefs::instance()->mShowTimeInAgenda)
578 mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + " - " + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ; 578 mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + " - " + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ;
579 579
580 if ( mAllDay ) { 580 if ( mAllDay ) {
581 if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) { 581 if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) {
582 if ( mIncidence->doesRecur() ) { 582 int dur = 1+ (static_cast<Event*>(mIncidence))->dtStart().date().daysTo( (static_cast<Event*>(mIncidence))->dtEnd().date() );
583 mDisplayedText += " (" + mIncidence->recurrence()->recurrenceText() + ")"; 583 mDisplayedText += " ("+QString::number( dur )+i18n(" days") +")" ;
584 } else { 584
585 int dur = 1+ (static_cast<Event*>(mIncidence))->dtStart().date().daysTo( (static_cast<Event*>(mIncidence))->dtEnd().date() ); 585 if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) {
586 mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true) + " ("+QString::number( dur )+i18n(" days") +")" ; 586 if ( mIncidence->doesRecur() ) {
587 } 587 mDisplayedText += " (" + mIncidence->recurrence()->recurrenceText() + ")";
588 } 588 } else {
589 mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true);
590 }
591 }
592 }
589 } 593 }
590 } 594 }
591 if ( !mIncidence->location().isEmpty() ) { 595 if ( !mIncidence->location().isEmpty() ) {
592 if ( mAllDay ) 596 if ( mAllDay )
593 mDisplayedText += " ("; 597 mDisplayedText += " (";
594 else 598 else
595 mDisplayedText += "\n("; 599 mDisplayedText += "\n(";
596 mDisplayedText += mIncidence->location() +")"; 600 mDisplayedText += mIncidence->location() +")";
597 } 601 }
598#ifdef DESKTOP_VERSION 602#ifdef DESKTOP_VERSION
599 QString tipText = mIncidence->summary(); 603 QString tipText = mIncidence->summary();
600 if ( !mIncidence->doesFloat() ) { 604 if ( !mIncidence->doesFloat() ) {
601 if ( mIncidence->typeID() == eventID ) { 605 if ( mIncidence->typeID() == eventID ) {
602 if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) { 606 if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) {
603 tipText += "\n"+i18n("From: ")+mIncidence->dtStartStr(); 607 tipText += "\n"+i18n("From: ")+mIncidence->dtStartStr();
604 tipText += "\n"+i18n("To: ")+(static_cast<Event*>(mIncidence))->dtEndStr(); 608 tipText += "\n"+i18n("To: ")+(static_cast<Event*>(mIncidence))->dtEndStr();
605 } 609 }
606 else { 610 else {
607 tipText += "\n"+i18n("Time: ")+mIncidence->dtStartTimeStr(); 611 tipText += "\n"+i18n("Time: ")+mIncidence->dtStartTimeStr();
608 tipText += " - "+(static_cast<Event*>(mIncidence))->dtEndTimeStr(); 612 tipText += " - "+(static_cast<Event*>(mIncidence))->dtEndTimeStr();
609 } 613 }
610 } 614 }
611 else if ( mIncidence->typeID() == todoID ) { 615 else if ( mIncidence->typeID() == todoID ) {
612 if (mIncidence->hasStartDate()) 616 if (mIncidence->hasStartDate())
613 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartStr(); 617 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartStr();
614 if (((Todo*)mIncidence)->hasDueDate()) 618 if (((Todo*)mIncidence)->hasDueDate())
615 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueStr(); 619 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueStr();
616 } 620 }
617 } else if ( mIncidence->typeID() == todoID ) { 621 } else if ( mIncidence->typeID() == todoID ) {
618 if (mIncidence->hasStartDate()) 622 if (mIncidence->hasStartDate())
619 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartDateStr(); 623 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartDateStr();
620 if (((Todo*)mIncidence)->hasDueDate()) 624 if (((Todo*)mIncidence)->hasDueDate())
621 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueDateStr(); 625 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueDateStr();
622 } 626 }
623 627
624 if (!mIncidence->location().isEmpty()) { 628 if (!mIncidence->location().isEmpty()) {
625 tipText += "\n"+i18n("Location: ")+mIncidence->location(); 629 tipText += "\n"+i18n("Location: ")+mIncidence->location();
626 } 630 }
627 QToolTip::add(this,tipText,toolTipGroup(),""); 631 QToolTip::add(this,tipText,toolTipGroup(),"");
628#endif 632#endif
629} 633}
630void KOAgendaItem::updateItem() 634void KOAgendaItem::updateItem()
631{ 635{
632 computeText(); 636 computeText();
633 637
634 //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y()); 638 //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y());
635 paintMe( mSelected ); 639 paintMe( mSelected );
636 repaint( false); 640 repaint( false);
637} 641}
638 642
639void KOAgendaItem::resizeEvent ( QResizeEvent *ev ) 643void KOAgendaItem::resizeEvent ( QResizeEvent *ev )
640{ 644{
641 //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1()); 645 //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1());
642 paintMe( mSelected ); 646 paintMe( mSelected );
643 repaint( false ); 647 repaint( false );
644} 648}
645 649
646/* 650/*
647 Return height of item in units of agenda cells 651 Return height of item in units of agenda cells
648*/ 652*/
649int KOAgendaItem::cellHeight() 653int KOAgendaItem::cellHeight()
650{ 654{
651 int ret = mCellYBottom - mCellYTop + 1; 655 int ret = mCellYBottom - mCellYTop + 1;
652 if ( ret <= 0 ) { 656 if ( ret <= 0 ) {
653 ret = 1; 657 ret = 1;
654 mCellYBottom = 0; 658 mCellYBottom = 0;
655 mCellYTop = 0; 659 mCellYTop = 0;
656 } 660 }
657 return ret; 661 return ret;
658} 662}
659// it may be that allday agenda items have a needed width > 32000 663// it may be that allday agenda items have a needed width > 32000
660// this code is to fix this problem 664// this code is to fix this problem
661int KOAgendaItem::resizeMe( int grid, int wid, int hei, bool invalidWidth ) 665int KOAgendaItem::resizeMe( int grid, int wid, int hei, bool invalidWidth )
662{ 666{
663 int diff = 0; 667 int diff = 0;
664 if ( mCellX < -3 && mAllDay ) { 668 if ( mCellX < -3 && mAllDay ) {
665 diff = (mCellX + 3) * -grid; 669 diff = (mCellX + 3) * -grid;
666 //qDebug("%s: cellX %d diff %d wid %d grid %d ", mDisplayedText.latin1(), mCellX, diff, wid, grid); 670 //qDebug("%s: cellX %d diff %d wid %d grid %d ", mDisplayedText.latin1(), mCellX, diff, wid, grid);
667 if ( diff >= wid ) { 671 if ( diff >= wid ) {
668 // qDebug("KOAgendaItem::resizeMe: diff >= wid: diff %d wid %d ", diff, wid); 672 // qDebug("KOAgendaItem::resizeMe: diff >= wid: diff %d wid %d ", diff, wid);
669 //diff = 0; 673 //diff = 0;
670 } 674 }
671 } 675 }
672 if ( (!invalidWidth && wid == width() ) || diff >= wid ) 676 if ( (!invalidWidth && wid == width() ) || diff >= wid )
673 resize( wid, hei ); 677 resize( wid, hei );
674 else 678 else
675 resize( wid - diff, hei ); 679 resize( wid - diff, hei );
676 //qDebug("wid %d x %d ", width(), x()); 680 //qDebug("wid %d x %d ", width(), x());
677 return diff; 681 return diff;
678} 682}
679/* 683/*
680 Return height of item in units of agenda cells 684 Return height of item in units of agenda cells
681*/ 685*/
682int KOAgendaItem::cellWidth() 686int KOAgendaItem::cellWidth()
683{ 687{
684 return mCellXWidth - mCellX + 1; 688 return mCellXWidth - mCellX + 1;
685} 689}
686 690
687void KOAgendaItem::setItemDate(QDate qd) 691void KOAgendaItem::setItemDate(QDate qd)
688{ 692{
689 mDate = qd; 693 mDate = qd;
690} 694}
691 695
692void KOAgendaItem::setCellXY(int X, int YTop, int YBottom) 696void KOAgendaItem::setCellXY(int X, int YTop, int YBottom)
693{ 697{
694 mCellX = X; 698 mCellX = X;
695 mCellYTop = YTop; 699 mCellYTop = YTop;
696 mCellYBottom = YBottom; 700 mCellYBottom = YBottom;
697} 701}
698 702
699void KOAgendaItem::setCellXWidth(int xwidth) 703void KOAgendaItem::setCellXWidth(int xwidth)
700{ 704{
701 mCellXWidth = xwidth; 705 mCellXWidth = xwidth;
702} 706}
703 707
704void KOAgendaItem::setCellX(int XLeft, int XRight) 708void KOAgendaItem::setCellX(int XLeft, int XRight)
705{ 709{
706 mCellX = XLeft; 710 mCellX = XLeft;
707 mCellXWidth = XRight; 711 mCellXWidth = XRight;
708} 712}
709 713
710void KOAgendaItem::setCellY(int YTop, int YBottom) 714void KOAgendaItem::setCellY(int YTop, int YBottom)
711{ 715{
712 mCellYTop = YTop; 716 mCellYTop = YTop;
713 mCellYBottom = YBottom; 717 mCellYBottom = YBottom;
714} 718}
715 719
716void KOAgendaItem::setSubCell(int subCell) 720void KOAgendaItem::setSubCell(int subCell)
717{ 721{
718 mSubCell = subCell; 722 mSubCell = subCell;
719} 723}
720 724
721void KOAgendaItem::setSubCells(int subCells) 725void KOAgendaItem::setSubCells(int subCells)
722{ 726{
723 mSubCells = subCells; 727 mSubCells = subCells;
724} 728}
725 729
726void KOAgendaItem::setMultiItem(KOAgendaItem *first,KOAgendaItem *next, 730void KOAgendaItem::setMultiItem(KOAgendaItem *first,KOAgendaItem *next,
727 KOAgendaItem *last) 731 KOAgendaItem *last)
728{ 732{
729 mFirstMultiItem = first; 733 mFirstMultiItem = first;
730 mNextMultiItem = next; 734 mNextMultiItem = next;
731 mLastMultiItem = last; 735 mLastMultiItem = last;
732} 736}
733 737
734void KOAgendaItem::startMove() 738void KOAgendaItem::startMove()
735{ 739{
736 mStartCellX = mCellX; 740 mStartCellX = mCellX;
737 mStartCellXWidth = mCellXWidth; 741 mStartCellXWidth = mCellXWidth;
738 mStartCellYTop = mCellYTop; 742 mStartCellYTop = mCellYTop;
739 mStartCellYBottom = mCellYBottom; 743 mStartCellYBottom = mCellYBottom;
740} 744}
741 745
742void KOAgendaItem::resetMove() 746void KOAgendaItem::resetMove()
743{ 747{
744 mCellX = mStartCellX; 748 mCellX = mStartCellX;
745 mCellXWidth = mStartCellXWidth; 749 mCellXWidth = mStartCellXWidth;
746 mCellYTop = mStartCellYTop; 750 mCellYTop = mStartCellYTop;
747 mCellYBottom = mStartCellYBottom; 751 mCellYBottom = mStartCellYBottom;
748} 752}
749 753
750void KOAgendaItem::moveRelative(int dx, int dy) 754void KOAgendaItem::moveRelative(int dx, int dy)
751{ 755{
752 int newX = cellX() + dx; 756 int newX = cellX() + dx;
753 int newXWidth = cellXWidth() + dx; 757 int newXWidth = cellXWidth() + dx;
754 int newYTop = cellYTop() + dy; 758 int newYTop = cellYTop() + dy;
755 int newYBottom = cellYBottom() + dy; 759 int newYBottom = cellYBottom() + dy;
756 setCellXY(newX,newYTop,newYBottom); 760 setCellXY(newX,newYTop,newYBottom);
757 setCellXWidth(newXWidth); 761 setCellXWidth(newXWidth);
758} 762}
759 763
760void KOAgendaItem::expandTop(int dy) 764void KOAgendaItem::expandTop(int dy)
761{ 765{
762 int newYTop = cellYTop() + dy; 766 int newYTop = cellYTop() + dy;
763 int newYBottom = cellYBottom(); 767 int newYBottom = cellYBottom();
764 if (newYTop > newYBottom) newYTop = newYBottom; 768 if (newYTop > newYBottom) newYTop = newYBottom;
765 setCellY(newYTop, newYBottom); 769 setCellY(newYTop, newYBottom);
766} 770}
767 771
768void KOAgendaItem::expandBottom(int dy) 772void KOAgendaItem::expandBottom(int dy)
769{ 773{
770 int newYTop = cellYTop(); 774 int newYTop = cellYTop();
771 int newYBottom = cellYBottom() + dy; 775 int newYBottom = cellYBottom() + dy;
772 if (newYBottom < newYTop) newYBottom = newYTop; 776 if (newYBottom < newYTop) newYBottom = newYTop;
773 setCellY(newYTop, newYBottom); 777 setCellY(newYTop, newYBottom);
774} 778}
775 779
776void KOAgendaItem::expandLeft(int dx) 780void KOAgendaItem::expandLeft(int dx)
777{ 781{
778 int newX = cellX() + dx; 782 int newX = cellX() + dx;
779 int newXWidth = cellXWidth(); 783 int newXWidth = cellXWidth();
780 if (newX > newXWidth) newX = newXWidth; 784 if (newX > newXWidth) newX = newXWidth;
781 setCellX(newX,newXWidth); 785 setCellX(newX,newXWidth);
782} 786}
783 787
784void KOAgendaItem::expandRight(int dx) 788void KOAgendaItem::expandRight(int dx)
785{ 789{
786 int newX = cellX(); 790 int newX = cellX();
787 int newXWidth = cellXWidth() + dx; 791 int newXWidth = cellXWidth() + dx;
788 if (newXWidth < newX) newXWidth = newX; 792 if (newXWidth < newX) newXWidth = newX;
789 setCellX(newX,newXWidth); 793 setCellX(newX,newXWidth);
790} 794}
791 795
792QToolTipGroup *KOAgendaItem::toolTipGroup() 796QToolTipGroup *KOAgendaItem::toolTipGroup()
793{ 797{
794 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); 798 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0);
795 return mToolTipGroup; 799 return mToolTipGroup;
796} 800}
797 801
798void KOAgendaItem::dragEnterEvent( QDragEnterEvent *e ) 802void KOAgendaItem::dragEnterEvent( QDragEnterEvent *e )
799{ 803{
800#ifndef KORG_NODND 804#ifndef KORG_NODND
801 if ( ICalDrag::canDecode( e ) || VCalDrag::canDecode( e ) || 805 if ( ICalDrag::canDecode( e ) || VCalDrag::canDecode( e ) ||
802 !QTextDrag::canDecode( e ) ) { 806 !QTextDrag::canDecode( e ) ) {
803 e->ignore(); 807 e->ignore();
804 return; 808 return;
805 } 809 }
806 e->accept(); 810 e->accept();
807#endif 811#endif
808} 812}
809 813
810void KOAgendaItem::dropEvent( QDropEvent *e ) 814void KOAgendaItem::dropEvent( QDropEvent *e )
811{ 815{
812#ifndef KORG_NODND 816#ifndef KORG_NODND
813 QString text; 817 QString text;
814 if(QTextDrag::decode(e,text)) 818 if(QTextDrag::decode(e,text))
815 { 819 {
816 kdDebug() << "Dropped : " << text << endl; 820 kdDebug() << "Dropped : " << text << endl;
817 QStringList emails = QStringList::split(",",text); 821 QStringList emails = QStringList::split(",",text);
818 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { 822 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
819 kdDebug() << " Email: " << (*it) << endl; 823 kdDebug() << " Email: " << (*it) << endl;
820 int pos = (*it).find("<"); 824 int pos = (*it).find("<");
821 QString name = (*it).left(pos); 825 QString name = (*it).left(pos);
822 QString email = (*it).mid(pos); 826 QString email = (*it).mid(pos);
823 if (!email.isEmpty()) { 827 if (!email.isEmpty()) {
824 mIncidence->addAttendee(new Attendee(name,email)); 828 mIncidence->addAttendee(new Attendee(name,email));
825 } 829 }
826 } 830 }
827 } 831 }
828#endif 832#endif
829} 833}
830 834
831 835
832QPtrList<KOAgendaItem> KOAgendaItem::conflictItems() 836QPtrList<KOAgendaItem> KOAgendaItem::conflictItems()
833{ 837{
834 return mConflictItems; 838 return mConflictItems;
835} 839}
836 840
837void KOAgendaItem::setConflictItems(QPtrList<KOAgendaItem> ci) 841void KOAgendaItem::setConflictItems(QPtrList<KOAgendaItem> ci)
838{ 842{
839 mConflictItems = ci; 843 mConflictItems = ci;
840 KOAgendaItem *item; 844 KOAgendaItem *item;
841 for ( item=mConflictItems.first(); item != 0; 845 for ( item=mConflictItems.first(); item != 0;
842 item=mConflictItems.next() ) { 846 item=mConflictItems.next() ) {
843 item->addConflictItem(this); 847 item->addConflictItem(this);
844 } 848 }
845} 849}
846 850
847void KOAgendaItem::addConflictItem(KOAgendaItem *ci) 851void KOAgendaItem::addConflictItem(KOAgendaItem *ci)
848{ 852{
849 if (mConflictItems.find(ci)<0) 853 if (mConflictItems.find(ci)<0)
850 mConflictItems.append(ci); 854 mConflictItems.append(ci);
851} 855}
852 856
853bool KOAgendaItem::checkLayout() 857bool KOAgendaItem::checkLayout()
854{ 858{
855 if ( !mConflictItems.count() ) 859 if ( !mConflictItems.count() )
856 return true; 860 return true;
857 int max = 0; 861 int max = 0;
858 KOAgendaItem *item; 862 KOAgendaItem *item;
859 for ( item=mConflictItems.first(); item != 0; 863 for ( item=mConflictItems.first(); item != 0;
860 item=mConflictItems.next() ) { 864 item=mConflictItems.next() ) {
861 if ( item->subCells() > max ) 865 if ( item->subCells() > max )
862 max = item->subCells(); 866 max = item->subCells();
863 } 867 }
864 if ( max > subCells() ) { 868 if ( max > subCells() ) {
865 setSubCells( max ); 869 setSubCells( max );
866 return false; 870 return false;
867 } 871 }
868 return true; 872 return true;
869} 873}