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