summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-03-21 12:34:49 (UTC)
committer zautrix <zautrix>2005-03-21 12:34:49 (UTC)
commitad4ecbb0cbf79f37140041eb9a14e71e6fd393f1 (patch) (unidiff)
treeb92ef416aa5542e06f1fc472d19619804ff897c8
parent3b7ba9f46c78816bae8c4b30a455e261d7da9f4a (diff)
downloadkdepimpi-ad4ecbb0cbf79f37140041eb9a14e71e6fd393f1.zip
kdepimpi-ad4ecbb0cbf79f37140041eb9a14e71e6fd393f1.tar.gz
kdepimpi-ad4ecbb0cbf79f37140041eb9a14e71e6fd393f1.tar.bz2
fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagendaitem.cpp2
-rw-r--r--korganizer/kodaymatrix.cpp2
-rw-r--r--korganizer/kotodoview.cpp2
3 files changed, 2 insertions, 4 deletions
diff --git a/korganizer/koagendaitem.cpp b/korganizer/koagendaitem.cpp
index 19cc0e3..5ee433a 100644
--- a/korganizer/koagendaitem.cpp
+++ b/korganizer/koagendaitem.cpp
@@ -1,784 +1,784 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <qlabel.h> 20#include <qlabel.h>
21#include <qlayout.h> 21#include <qlayout.h>
22#include <qhbox.h> 22#include <qhbox.h>
23#include <qvbox.h> 23#include <qvbox.h>
24#include <qtooltip.h> 24#include <qtooltip.h>
25#include <qwhatsthis.h> 25#include <qwhatsthis.h>
26#include <qdragobject.h> 26#include <qdragobject.h>
27#include <qdrawutil.h> 27#include <qdrawutil.h>
28#include <qpainter.h> 28#include <qpainter.h>
29 29
30#include <kiconloader.h> 30#include <kiconloader.h>
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kglobal.h> 32#include <kglobal.h>
33#include <klocale.h> 33#include <klocale.h>
34#ifndef DESKTOP_VERSION 34#ifndef DESKTOP_VERSION
35#include <qpe/qpeapplication.h> 35#include <qpe/qpeapplication.h>
36#define AGENDA_ICON_SIZE 5 36#define AGENDA_ICON_SIZE 5
37#else 37#else
38#define AGENDA_ICON_SIZE 7 38#define AGENDA_ICON_SIZE 7
39#endif 39#endif
40#include <libkcal/icaldrag.h> 40#include <libkcal/icaldrag.h>
41#include <libkcal/vcaldrag.h> 41#include <libkcal/vcaldrag.h>
42#include <libkcal/kincidenceformatter.h> 42#include <libkcal/kincidenceformatter.h>
43extern int globalFlagBlockAgenda; 43extern int globalFlagBlockAgenda;
44extern int globalFlagBlockAgendaItemPaint; 44extern int globalFlagBlockAgendaItemPaint;
45extern int globalFlagBlockAgendaItemUpdate; 45extern int globalFlagBlockAgendaItemUpdate;
46 46
47#include "koprefs.h" 47#include "koprefs.h"
48 48
49#include "koagendaitem.h" 49#include "koagendaitem.h"
50//#include "koagendaitem.moc" 50//#include "koagendaitem.moc"
51 51
52 52
53//-------------------------------------------------------------------------- 53//--------------------------------------------------------------------------
54 54
55QToolTipGroup *KOAgendaItem::mToolTipGroup = 0; 55QToolTipGroup *KOAgendaItem::mToolTipGroup = 0;
56 56
57//-------------------------------------------------------------------------- 57//--------------------------------------------------------------------------
58 58
59class KOAgendaItemWhatsThis :public QWhatsThis 59class KOAgendaItemWhatsThis :public QWhatsThis
60{ 60{
61public: 61public:
62 KOAgendaItemWhatsThis( KOAgendaItem* view ) : QWhatsThis( view ),_view (view) { }; 62 KOAgendaItemWhatsThis( KOAgendaItem* view ) : QWhatsThis( view ),_view (view) { };
63 63
64protected: 64protected:
65 virtual QString text( const QPoint& ) 65 virtual QString text( const QPoint& )
66 { 66 {
67 return _view->getWhatsThisText() ; 67 return _view->getWhatsThisText() ;
68 } 68 }
69private: 69private:
70 KOAgendaItem * _view; 70 KOAgendaItem * _view;
71}; 71};
72 72
73KOAgendaItem::KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent,bool allday, 73KOAgendaItem::KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent,bool allday,
74 const char *name,WFlags) : 74 const char *name,WFlags) :
75 QWidget(parent, name), mIncidence(incidence), mDate(qd) 75 QWidget(parent, name), mIncidence(incidence), mDate(qd)
76{ 76{
77#ifndef DESKTOP_VERSION 77#ifndef DESKTOP_VERSION
78 //QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); 78 //QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
79#endif 79#endif
80 mKOAgendaItemWhatsThis = new KOAgendaItemWhatsThis(this); 80 mKOAgendaItemWhatsThis = new KOAgendaItemWhatsThis(this);
81 int wflags = getWFlags() |WRepaintNoErase;// WResizeNoErase 81 int wflags = getWFlags() |WRepaintNoErase;// WResizeNoErase
82 setWFlags ( wflags); 82 setWFlags ( wflags);
83 mAllDay = allday; 83 mAllDay = allday;
84 init ( incidence, qd ); 84 init ( incidence, qd );
85 //setMouseTracking(true); 85 //setMouseTracking(true);
86 //setAcceptDrops(true); 86 //setAcceptDrops(true);
87 xPaintCoord = -1; 87 xPaintCoord = -1;
88 yPaintCoord = -1; 88 yPaintCoord = -1;
89} 89}
90QString KOAgendaItem::getWhatsThisText() 90QString KOAgendaItem::getWhatsThisText()
91{ 91{
92 if ( mIncidence ) 92 if ( mIncidence )
93 return KIncidenceFormatter::instance()->getFormattedText( mIncidence, 93 return KIncidenceFormatter::instance()->getFormattedText( mIncidence,
94 KOPrefs::instance()->mWTshowDetails, 94 KOPrefs::instance()->mWTshowDetails,
95 KOPrefs::instance()->mWTshowCreated, 95 KOPrefs::instance()->mWTshowCreated,
96 KOPrefs::instance()->mWTshowChanged); 96 KOPrefs::instance()->mWTshowChanged);
97 return "KOAgendaItem::getWhatsThisText()::internal error"; 97 return "KOAgendaItem::getWhatsThisText()::internal error";
98} 98}
99void KOAgendaItem::init ( Incidence *incidence, QDate qd ) 99void KOAgendaItem::init ( Incidence *incidence, QDate qd )
100{ 100{
101 mIncidence = incidence; 101 mIncidence = incidence;
102 mDate = qd; 102 mDate = qd;
103 mFirstMultiItem = 0; 103 mFirstMultiItem = 0;
104 mNextMultiItem = 0; 104 mNextMultiItem = 0;
105 mLastMultiItem = 0; 105 mLastMultiItem = 0;
106 computeText(); 106 computeText();
107 107
108 if ( (incidence->type() == "Todo") && 108 if ( (incidence->type() == "Todo") &&
109 ( !((static_cast<Todo*>(incidence))->isCompleted()) && 109 ( !((static_cast<Todo*>(incidence))->isCompleted()) &&
110 ((static_cast<Todo*>(incidence))->dtDue().date() <= QDate::currentDate()) ) ) { 110 ((static_cast<Todo*>(incidence))->dtDue().date() <= QDate::currentDate()) ) ) {
111 if ( (static_cast<Todo*>(incidence))->dtDue() < QDateTime::currentDateTime().date()) 111 if ( (static_cast<Todo*>(incidence))->dtDue() < QDateTime::currentDateTime().date())
112 mBackgroundColor = KOPrefs::instance()->mTodoOverdueColor ; 112 mBackgroundColor = KOPrefs::instance()->mTodoOverdueColor ;
113 else 113 else
114 mBackgroundColor = KOPrefs::instance()->mTodoDueTodayColor; 114 mBackgroundColor = KOPrefs::instance()->mTodoDueTodayColor;
115 } 115 }
116 else { 116 else {
117 QStringList categories = mIncidence->categories(); 117 QStringList categories = mIncidence->categories();
118 QString cat = categories.first(); 118 QString cat = categories.first();
119 if (cat.isEmpty()) { 119 if (cat.isEmpty()) {
120 if ( (incidence->type() == "Todo") &&((static_cast<Todo*>(incidence))->isCompleted()) ) 120 if ( (incidence->type() == "Todo") &&((static_cast<Todo*>(incidence))->isCompleted()) )
121 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor; 121 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor;
122 else 122 else
123 mBackgroundColor =KOPrefs::instance()->mEventColor; 123 mBackgroundColor =KOPrefs::instance()->mEventColor;
124 } else { 124 } else {
125 mBackgroundColor = *KOPrefs::instance()->categoryColor(cat); 125 mBackgroundColor = *KOPrefs::instance()->categoryColor(cat);
126 if ( (incidence->type() == "Todo") &&((static_cast<Todo*>(incidence))->isCompleted()) ) { 126 if ( (incidence->type() == "Todo") &&((static_cast<Todo*>(incidence))->isCompleted()) ) {
127 if ( mBackgroundColor == KOPrefs::instance()->mEventColor ) 127 if ( mBackgroundColor == KOPrefs::instance()->mEventColor )
128 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor; 128 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor;
129 } 129 }
130 } 130 }
131 131
132 } 132 }
133 mColorGroup = QColorGroup( mBackgroundColor.light(), 133 mColorGroup = QColorGroup( mBackgroundColor.light(),
134 mBackgroundColor.dark(),mBackgroundColor.light(), 134 mBackgroundColor.dark(),mBackgroundColor.light(),
135 mBackgroundColor.dark(),mBackgroundColor, black, mBackgroundColor) ; 135 mBackgroundColor.dark(),mBackgroundColor, black, mBackgroundColor) ;
136 setBackgroundColor( mBackgroundColor ); 136 setBackgroundColor( mBackgroundColor );
137 137
138 mConflictItems.clear(); 138 mConflictItems.clear();
139 setCellXY(0,0,1); 139 setCellXY(0,0,1);
140 setCellXWidth(0); 140 setCellXWidth(0);
141 setSubCell(0); 141 setSubCell(0);
142 setSubCells(1); 142 setSubCells(1);
143 setMultiItem(0,0,0); 143 setMultiItem(0,0,0);
144 startMove(); 144 startMove();
145 mSelected = true; 145 mSelected = true;
146 select(false); 146 select(false);
147 QFontMetrics fontinf(KOPrefs::instance()->mAgendaViewFont); 147 QFontMetrics fontinf(KOPrefs::instance()->mAgendaViewFont);
148 mFontPixelSize = fontinf.height();; 148 mFontPixelSize = fontinf.height();;
149 hide(); 149 hide();
150 xPaintCoord = -1; 150 xPaintCoord = -1;
151 yPaintCoord = -1; 151 yPaintCoord = -1;
152} 152}
153 153
154 154
155KOAgendaItem::~KOAgendaItem() 155KOAgendaItem::~KOAgendaItem()
156{ 156{
157 // qDebug("deleteKOAgendaItem::~KOAgendaItem( "); 157 // qDebug("deleteKOAgendaItem::~KOAgendaItem( ");
158 delete mKOAgendaItemWhatsThis; 158 // delete mKOAgendaItemWhatsThis;
159} 159}
160 160
161void KOAgendaItem::recreateIncidence() 161void KOAgendaItem::recreateIncidence()
162{ 162{
163#if 0 163#if 0
164 Incidence* newInc = mIncidence->clone(); 164 Incidence* newInc = mIncidence->clone();
165 newInc->recreate(); 165 newInc->recreate();
166 if ( mIncidence->doesRecur() ) { 166 if ( mIncidence->doesRecur() ) {
167 mIncidence->addExDate( mDate ); 167 mIncidence->addExDate( mDate );
168 newInc->recurrence()->unsetRecurs(); 168 newInc->recurrence()->unsetRecurs();
169 int len = mIncidence->dtStart().secsTo( ((Event*)mIncidence)->dtEnd()); 169 int len = mIncidence->dtStart().secsTo( ((Event*)mIncidence)->dtEnd());
170 QTime tim = mIncidence->dtStart().time(); 170 QTime tim = mIncidence->dtStart().time();
171 newInc->setDtStart( QDateTime(mDate, tim) ); 171 newInc->setDtStart( QDateTime(mDate, tim) );
172 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); 172 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) );
173 } 173 }
174#endif 174#endif
175 mIncidence = mIncidence->recreateCloneException( mDate ); 175 mIncidence = mIncidence->recreateCloneException( mDate );
176} 176}
177bool KOAgendaItem::updateIcons(QPainter * p, bool horLayout) 177bool KOAgendaItem::updateIcons(QPainter * p, bool horLayout)
178{ 178{
179 int size = AGENDA_ICON_SIZE; 179 int size = AGENDA_ICON_SIZE;
180 180
181 int yOff = 0; 181 int yOff = 0;
182 int xOff = 0; 182 int xOff = 0;
183 int x = pos().x() +3; 183 int x = pos().x() +3;
184 int y; 184 int y;
185 if ( mAllDay ) 185 if ( mAllDay )
186 y = pos().y()+3; 186 y = pos().y()+3;
187 else 187 else
188 y = mCellYTop * ( height() / cellHeight() ) +3; 188 y = mCellYTop * ( height() / cellHeight() ) +3;
189 if (mIncidence->cancelled()) { 189 if (mIncidence->cancelled()) {
190 int xpos = xOff*( 1 +AGENDA_ICON_SIZE )+x; 190 int xpos = xOff*( 1 +AGENDA_ICON_SIZE )+x;
191 int ypos = yOff*( 1 +AGENDA_ICON_SIZE)+y; 191 int ypos = yOff*( 1 +AGENDA_ICON_SIZE)+y;
192 p->drawLine( xpos, ypos, xpos+AGENDA_ICON_SIZE-1, ypos+AGENDA_ICON_SIZE-1 ); 192 p->drawLine( xpos, ypos, xpos+AGENDA_ICON_SIZE-1, ypos+AGENDA_ICON_SIZE-1 );
193 p->drawLine( xpos, ypos+AGENDA_ICON_SIZE-1, xpos+AGENDA_ICON_SIZE-1, ypos ); 193 p->drawLine( xpos, ypos+AGENDA_ICON_SIZE-1, xpos+AGENDA_ICON_SIZE-1, ypos );
194 if ( horLayout ) 194 if ( horLayout )
195 ++xOff; 195 ++xOff;
196 else 196 else
197 ++yOff; 197 ++yOff;
198 } 198 }
199 if (mIncidence->isAlarmEnabled()) { 199 if (mIncidence->isAlarmEnabled()) {
200 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, red ); 200 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, red );
201 if ( horLayout ) 201 if ( horLayout )
202 ++xOff; 202 ++xOff;
203 else 203 else
204 ++yOff; 204 ++yOff;
205 } 205 }
206 if (mIncidence->recurrence()->doesRecur()) { 206 if (mIncidence->recurrence()->doesRecur()) {
207 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, blue ); 207 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, blue );
208 if ( horLayout ) 208 if ( horLayout )
209 ++xOff; 209 ++xOff;
210 else 210 else
211 ++yOff; 211 ++yOff;
212 } 212 }
213 if (mIncidence->description().length() > 0) { 213 if (mIncidence->description().length() > 0) {
214 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkGreen ); 214 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkGreen );
215 if ( horLayout ) 215 if ( horLayout )
216 ++xOff; 216 ++xOff;
217 else 217 else
218 ++yOff; 218 ++yOff;
219 } 219 }
220 if (mIncidence->isReadOnly()) { 220 if (mIncidence->isReadOnly()) {
221 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, white ); 221 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, white );
222 if ( horLayout ) 222 if ( horLayout )
223 ++xOff; 223 ++xOff;
224 else 224 else
225 ++yOff; 225 ++yOff;
226 } 226 }
227 227
228 if (mIncidence->attendeeCount()>0) { 228 if (mIncidence->attendeeCount()>0) {
229 229
230 if (mIncidence->organizer() == KOPrefs::instance()->email()) { 230 if (mIncidence->organizer() == KOPrefs::instance()->email()) {
231 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, black ); 231 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, black );
232 if ( horLayout ) 232 if ( horLayout )
233 ++xOff; 233 ++xOff;
234 else 234 else
235 ++yOff; 235 ++yOff;
236 } else { 236 } else {
237 Attendee *me = mIncidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 237 Attendee *me = mIncidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
238 if (me!=0) { 238 if (me!=0) {
239 239
240 240
241 } else { 241 } else {
242 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, yellow ); 242 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, yellow );
243 if ( horLayout ) 243 if ( horLayout )
244 ++xOff; 244 ++xOff;
245 else 245 else
246 ++yOff; 246 ++yOff;
247 247
248 } 248 }
249 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkYellow ); 249 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkYellow );
250 if ( horLayout ) 250 if ( horLayout )
251 ++xOff; 251 ++xOff;
252 else 252 else
253 ++yOff; 253 ++yOff;
254 254
255 } 255 }
256 256
257 } 257 }
258 return ( yOff || xOff ); 258 return ( yOff || xOff );
259} 259}
260 260
261 261
262void KOAgendaItem::select(bool selected) 262void KOAgendaItem::select(bool selected)
263{ 263{
264 //qDebug("select %d %d",firstMultiItem(), nextMultiItem() ); 264 //qDebug("select %d %d",firstMultiItem(), nextMultiItem() );
265 if (mSelected == selected) return; 265 if (mSelected == selected) return;
266 mSelected = selected; 266 mSelected = selected;
267 if ( ! isVisible() ) 267 if ( ! isVisible() )
268 return; 268 return;
269 if ( firstMultiItem() ) 269 if ( firstMultiItem() )
270 firstMultiItem()->select( selected ); 270 firstMultiItem()->select( selected );
271 if ( !firstMultiItem() && nextMultiItem() ) { 271 if ( !firstMultiItem() && nextMultiItem() ) {
272 KOAgendaItem * placeItem = nextMultiItem(); 272 KOAgendaItem * placeItem = nextMultiItem();
273 while ( placeItem ) { 273 while ( placeItem ) {
274 placeItem->select( selected ); 274 placeItem->select( selected );
275 placeItem = placeItem->nextMultiItem(); 275 placeItem = placeItem->nextMultiItem();
276 } 276 }
277 } 277 }
278 globalFlagBlockAgendaItemUpdate = 0; 278 globalFlagBlockAgendaItemUpdate = 0;
279 paintMe( selected ); 279 paintMe( selected );
280 globalFlagBlockAgendaItemUpdate = 1; 280 globalFlagBlockAgendaItemUpdate = 1;
281 repaint( false ); 281 repaint( false );
282} 282}
283 283
284 284
285/* 285/*
286 The eventFilter has to filter the mouse events of the agenda item childs. The 286 The eventFilter has to filter the mouse events of the agenda item childs. The
287 events are fed into the event handling method of KOAgendaItem. This allows the 287 events are fed into the event handling method of KOAgendaItem. This allows the
288 KOAgenda to handle the KOAgendaItems by using an eventFilter. 288 KOAgenda to handle the KOAgendaItems by using an eventFilter.
289*/ 289*/
290bool KOAgendaItem::eventFilter ( QObject *object, QEvent *e ) 290bool KOAgendaItem::eventFilter ( QObject *object, QEvent *e )
291{ 291{
292 if (e->type() == QEvent::MouseButtonPress || 292 if (e->type() == QEvent::MouseButtonPress ||
293 e->type() == QEvent::MouseButtonDblClick || 293 e->type() == QEvent::MouseButtonDblClick ||
294 e->type() == QEvent::MouseButtonRelease || 294 e->type() == QEvent::MouseButtonRelease ||
295 e->type() == QEvent::MouseMove) { 295 e->type() == QEvent::MouseMove) {
296 QMouseEvent *me = (QMouseEvent *)e; 296 QMouseEvent *me = (QMouseEvent *)e;
297 QPoint itemPos = this->mapFromGlobal(((QWidget *)object)-> 297 QPoint itemPos = this->mapFromGlobal(((QWidget *)object)->
298 mapToGlobal(me->pos())); 298 mapToGlobal(me->pos()));
299 QMouseEvent returnEvent (e->type(),itemPos,me->button(),me->state()); 299 QMouseEvent returnEvent (e->type(),itemPos,me->button(),me->state());
300 return event(&returnEvent); 300 return event(&returnEvent);
301 } else { 301 } else {
302 return false; 302 return false;
303 } 303 }
304} 304}
305void KOAgendaItem::repaintMe( ) 305void KOAgendaItem::repaintMe( )
306{ 306{
307 paintMe ( mSelected ); 307 paintMe ( mSelected );
308} 308}
309void KOAgendaItem::paintMe( bool selected, QPainter* paint ) 309void KOAgendaItem::paintMe( bool selected, QPainter* paint )
310{ 310{
311 if ( globalFlagBlockAgendaItemUpdate && ! selected) 311 if ( globalFlagBlockAgendaItemUpdate && ! selected)
312 return; 312 return;
313 QPainter pa; 313 QPainter pa;
314 314
315 if ( mSelected ) { 315 if ( mSelected ) {
316 pa.begin( paintPixSel() ); 316 pa.begin( paintPixSel() );
317 } else { 317 } else {
318 if ( mAllDay ) 318 if ( mAllDay )
319 pa.begin( paintPixAllday() ); 319 pa.begin( paintPixAllday() );
320 else 320 else
321 pa.begin( paintPix() ); 321 pa.begin( paintPix() );
322 } 322 }
323 int x, yy, w, h; 323 int x, yy, w, h;
324 float nfh = 7.0; 324 float nfh = 7.0;
325 x = pos().x(); w = width(); h = height (); 325 x = pos().x(); w = width(); h = height ();
326 if ( mAllDay ) 326 if ( mAllDay )
327 yy = y(); 327 yy = y();
328 else 328 else
329 yy = mCellYTop * ( height() / cellHeight() ); 329 yy = mCellYTop * ( height() / cellHeight() );
330 xPaintCoord= x; 330 xPaintCoord= x;
331 yPaintCoord = yy; 331 yPaintCoord = yy;
332 wPaintCoord = width(); 332 wPaintCoord = width();
333 hPaintCoord = height(); 333 hPaintCoord = height();
334 //qDebug("paintMe %s %d %d %d %d",incidence()->summary().latin1(), x, yy, width(), height()); 334 //qDebug("paintMe %s %d %d %d %d",incidence()->summary().latin1(), x, yy, width(), height());
335 if ( paint == 0 ) 335 if ( paint == 0 )
336 paint = &pa; 336 paint = &pa;
337 bool horLayout = ( w < h ); 337 bool horLayout = ( w < h );
338 int maxhei = mFontPixelSize+4; 338 int maxhei = mFontPixelSize+4;
339 if ( horLayout ) 339 if ( horLayout )
340 maxhei += AGENDA_ICON_SIZE -4; 340 maxhei += AGENDA_ICON_SIZE -4;
341 bool small = ( h < maxhei ); 341 bool small = ( h < maxhei );
342 if ( ! small ) 342 if ( ! small )
343 paint->setFont(KOPrefs::instance()->mAgendaViewFont); 343 paint->setFont(KOPrefs::instance()->mAgendaViewFont);
344 else { 344 else {
345 QFont f = KOPrefs::instance()->mAgendaViewFont; 345 QFont f = KOPrefs::instance()->mAgendaViewFont;
346 f.setBold( false ); 346 f.setBold( false );
347 int fh = f.pointSize(); 347 int fh = f.pointSize();
348 nfh = (((float)height())/(float)(mFontPixelSize+4))*fh; 348 nfh = (((float)height())/(float)(mFontPixelSize+4))*fh;
349 if ( nfh < 6 ) 349 if ( nfh < 6 )
350 nfh = 6; 350 nfh = 6;
351 f.setPointSize( nfh ); 351 f.setPointSize( nfh );
352 paint->setFont(f); 352 paint->setFont(f);
353 } 353 }
354 paint->fillRect ( x, yy, w, h, mBackgroundColor ); 354 paint->fillRect ( x, yy, w, h, mBackgroundColor );
355 static const QPixmap completedPxmp = SmallIcon("greenhook16"); 355 static const QPixmap completedPxmp = SmallIcon("greenhook16");
356 static const QPixmap overduePxmp = SmallIcon("redcross16"); 356 static const QPixmap overduePxmp = SmallIcon("redcross16");
357 if ( mIncidence->type() == "Todo" ) { 357 if ( mIncidence->type() == "Todo" ) {
358 Todo* tempTodo = static_cast<Todo*>(mIncidence); 358 Todo* tempTodo = static_cast<Todo*>(mIncidence);
359 int xx = pos().x()+(width()-completedPxmp.width()-3 ); 359 int xx = pos().x()+(width()-completedPxmp.width()-3 );
360 int yyy = yy+3; 360 int yyy = yy+3;
361 if ( tempTodo->isCompleted() ) 361 if ( tempTodo->isCompleted() )
362 paint->drawPixmap ( xx, yyy, completedPxmp ); 362 paint->drawPixmap ( xx, yyy, completedPxmp );
363 else { 363 else {
364 paint->drawPixmap ( xx, yyy, overduePxmp ); 364 paint->drawPixmap ( xx, yyy, overduePxmp );
365 365
366 } 366 }
367 } 367 }
368 bool addIcon = false; 368 bool addIcon = false;
369 if ( ! small || w > 3 * h || h > 3* w ) 369 if ( ! small || w > 3 * h || h > 3* w )
370 addIcon = updateIcons( paint, horLayout ); 370 addIcon = updateIcons( paint, horLayout );
371 371
372 qDrawShadePanel (paint, x, yy, w, h, mColorGroup, selected , 2, 0); 372 qDrawShadePanel (paint, x, yy, w, h, mColorGroup, selected , 2, 0);
373 //qDebug("draw rect %d %d %d %d ",x, yy, w, h ); 373 //qDebug("draw rect %d %d %d %d ",x, yy, w, h );
374 if ( ! small ) { 374 if ( ! small ) {
375 x += 3; yy += 3;w -= 6; h-= 5; 375 x += 3; yy += 3;w -= 6; h-= 5;
376 } else { 376 } else {
377 x += 2; yy += 1;w -= 4; h-= 4; 377 x += 2; yy += 1;w -= 4; h-= 4;
378 if ( nfh < 6.01 ) { 378 if ( nfh < 6.01 ) {
379 yy -= 2; 379 yy -= 2;
380 h += 4; 380 h += 4;
381 } 381 }
382 else 382 else
383 if ( nfh < h -2 ) 383 if ( nfh < h -2 )
384 ++yy; 384 ++yy;
385 } 385 }
386 int align; 386 int align;
387#ifndef DESKTOP_VERSION 387#ifndef DESKTOP_VERSION
388 align = ( AlignLeft|WordBreak|AlignTop); 388 align = ( AlignLeft|WordBreak|AlignTop);
389#else 389#else
390 align = ( AlignLeft|BreakAnywhere|WordBreak|AlignTop); 390 align = ( AlignLeft|BreakAnywhere|WordBreak|AlignTop);
391#endif 391#endif
392 if ( addIcon ) { 392 if ( addIcon ) {
393 if ( ! horLayout ) { 393 if ( ! horLayout ) {
394 x += AGENDA_ICON_SIZE+3; 394 x += AGENDA_ICON_SIZE+3;
395 w -= (AGENDA_ICON_SIZE+3); 395 w -= (AGENDA_ICON_SIZE+3);
396 } 396 }
397 else { 397 else {
398 yy+= AGENDA_ICON_SIZE+2; 398 yy+= AGENDA_ICON_SIZE+2;
399 h -=(AGENDA_ICON_SIZE+3); 399 h -=(AGENDA_ICON_SIZE+3);
400 } 400 }
401 } 401 }
402 int colsum = mBackgroundColor.red() + mBackgroundColor.green() + mBackgroundColor.blue(); 402 int colsum = mBackgroundColor.red() + mBackgroundColor.green() + mBackgroundColor.blue();
403 if ( colsum < 250 ) 403 if ( colsum < 250 )
404 paint->setPen ( white); 404 paint->setPen ( white);
405 if ( x < 0 ) { 405 if ( x < 0 ) {
406 w = w+x-3; 406 w = w+x-3;
407 x = 3; 407 x = 3;
408 if ( w > parentWidget()->width() ){ 408 if ( w > parentWidget()->width() ){
409 w = parentWidget()->width() - 6; 409 w = parentWidget()->width() - 6;
410#ifndef DESKTOP_VERSION 410#ifndef DESKTOP_VERSION
411 align = ( AlignHCenter|WordBreak|AlignTop); 411 align = ( AlignHCenter|WordBreak|AlignTop);
412#else 412#else
413 align = ( AlignHCenter|BreakAnywhere|WordBreak|AlignTop); 413 align = ( AlignHCenter|BreakAnywhere|WordBreak|AlignTop);
414#endif 414#endif
415 415
416 } 416 }
417 } 417 }
418 QRect dr; 418 QRect dr;
419 if ( w + x > parentWidget()->width() ) 419 if ( w + x > parentWidget()->width() )
420 w = parentWidget()->width()-x; 420 w = parentWidget()->width()-x;
421 paint->drawText ( x, yy, w, h, align, mDisplayedText, -1, &dr ); 421 paint->drawText ( x, yy, w, h, align, mDisplayedText, -1, &dr );
422 //qDebug("%d %d %d %d ", x, yy, w, h ); 422 //qDebug("%d %d %d %d ", x, yy, w, h );
423 if ( mIncidence->cancelled() ){ 423 if ( mIncidence->cancelled() ){
424 if ( ! small ) { 424 if ( ! small ) {
425 QFontMetrics fm ( paint->font() ); 425 QFontMetrics fm ( paint->font() );
426 paint->drawLine(dr.left(), yy+fm.height()/2, dr.right()-2, yy+fm.height()/2); 426 paint->drawLine(dr.left(), yy+fm.height()/2, dr.right()-2, yy+fm.height()/2);
427 } 427 }
428 428
429 } 429 }
430 pa.end(); 430 pa.end();
431 431
432} 432}
433void KOAgendaItem::resizePixmap( int w , int h ) 433void KOAgendaItem::resizePixmap( int w , int h )
434{ 434{
435 paintPix()->resize( w, h ); 435 paintPix()->resize( w, h );
436 paintPixSel()->resize( w, h ); 436 paintPixSel()->resize( w, h );
437 437
438} 438}
439QPixmap * KOAgendaItem::paintPix() 439QPixmap * KOAgendaItem::paintPix()
440{ 440{
441 static QPixmap* mPaintPix = 0; 441 static QPixmap* mPaintPix = 0;
442 if ( ! mPaintPix ) 442 if ( ! mPaintPix )
443 mPaintPix = new QPixmap(1,1); 443 mPaintPix = new QPixmap(1,1);
444 return mPaintPix ; 444 return mPaintPix ;
445} 445}
446QPixmap * KOAgendaItem::paintPixAllday() 446QPixmap * KOAgendaItem::paintPixAllday()
447{ 447{
448 static QPixmap* mPaintPixA = 0; 448 static QPixmap* mPaintPixA = 0;
449 if ( ! mPaintPixA ) 449 if ( ! mPaintPixA )
450 mPaintPixA = new QPixmap(1,1); 450 mPaintPixA = new QPixmap(1,1);
451 return mPaintPixA ; 451 return mPaintPixA ;
452} 452}
453QPixmap * KOAgendaItem::paintPixSel() 453QPixmap * KOAgendaItem::paintPixSel()
454{ 454{
455 static QPixmap* mPaintPixSel = 0; 455 static QPixmap* mPaintPixSel = 0;
456 if ( ! mPaintPixSel ) 456 if ( ! mPaintPixSel )
457 mPaintPixSel = new QPixmap(1,1); 457 mPaintPixSel = new QPixmap(1,1);
458 return mPaintPixSel ; 458 return mPaintPixSel ;
459} 459}
460void KOAgendaItem::paintEvent ( QPaintEvent *e ) 460void KOAgendaItem::paintEvent ( QPaintEvent *e )
461{ 461{
462 462
463 if ( globalFlagBlockAgendaItemPaint ) 463 if ( globalFlagBlockAgendaItemPaint )
464 return; 464 return;
465 if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 ) 465 if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 )
466 return; 466 return;
467 int yy; 467 int yy;
468 if ( mAllDay ) 468 if ( mAllDay )
469 yy = y(); 469 yy = y();
470 else 470 else
471 yy = mCellYTop * ( height() / cellHeight() ); 471 yy = mCellYTop * ( height() / cellHeight() );
472 int xx = x(); 472 int xx = x();
473 if ( xPaintCoord != xx || yPaintCoord != yy || 473 if ( xPaintCoord != xx || yPaintCoord != yy ||
474 wPaintCoord != width() || hPaintCoord != height()) { 474 wPaintCoord != width() || hPaintCoord != height()) {
475 xPaintCoord= xx; 475 xPaintCoord= xx;
476 yPaintCoord = yy; 476 yPaintCoord = yy;
477 wPaintCoord = width(); 477 wPaintCoord = width();
478 hPaintCoord = height(); 478 hPaintCoord = height();
479 globalFlagBlockAgendaItemUpdate = 0; 479 globalFlagBlockAgendaItemUpdate = 0;
480 paintMe( mSelected ); 480 paintMe( mSelected );
481 //qDebug("calling paintMe "); 481 //qDebug("calling paintMe ");
482 globalFlagBlockAgendaItemUpdate = 1; 482 globalFlagBlockAgendaItemUpdate = 1;
483 } 483 }
484 int rx, ry, rw, rh; 484 int rx, ry, rw, rh;
485 rx = e->rect().x(); 485 rx = e->rect().x();
486 ry = e->rect().y(); 486 ry = e->rect().y();
487 rw = e->rect().width(); 487 rw = e->rect().width();
488 rh = e->rect().height(); 488 rh = e->rect().height();
489 //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height()); 489 //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height());
490 490
491 QPixmap* paintFrom ; 491 QPixmap* paintFrom ;
492 if ( mSelected ) { 492 if ( mSelected ) {
493 paintFrom = paintPixSel(); 493 paintFrom = paintPixSel();
494 } else { 494 } else {
495 if ( mAllDay ) 495 if ( mAllDay )
496 paintFrom = paintPixAllday(); 496 paintFrom = paintPixAllday();
497 else 497 else
498 paintFrom = paintPix(); 498 paintFrom = paintPix();
499 } 499 }
500 bitBlt (this, rx, ry, paintFrom, x()+rx ,yPaintCoord+ry, rw, rh ,CopyROP); 500 bitBlt (this, rx, ry, paintFrom, x()+rx ,yPaintCoord+ry, rw, rh ,CopyROP);
501} 501}
502void KOAgendaItem::computeText() 502void KOAgendaItem::computeText()
503{ 503{
504 504
505 mDisplayedText = mIncidence->summary(); 505 mDisplayedText = mIncidence->summary();
506 if ( (mIncidence->type() == "Todo") ) { 506 if ( (mIncidence->type() == "Todo") ) {
507 if ( static_cast<Todo*>(mIncidence)->hasDueDate() ) { 507 if ( static_cast<Todo*>(mIncidence)->hasDueDate() ) {
508 if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() ) 508 if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() )
509 mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")"; 509 mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")";
510 else if ( !(mIncidence->doesFloat())) 510 else if ( !(mIncidence->doesFloat()))
511 mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")"; 511 mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")";
512 } 512 }
513 } else { 513 } else {
514 if ( !(mIncidence->doesFloat()) && KOPrefs::instance()->mShowTimeInAgenda) 514 if ( !(mIncidence->doesFloat()) && KOPrefs::instance()->mShowTimeInAgenda)
515 mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + "-" + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ; 515 mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + "-" + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ;
516 516
517 if ( mAllDay ) { 517 if ( mAllDay ) {
518 if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) { 518 if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) {
519 mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true) ; 519 mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true) ;
520 } 520 }
521 } 521 }
522 522
523 } 523 }
524 524
525 if ( !mIncidence->location().isEmpty() ) { 525 if ( !mIncidence->location().isEmpty() ) {
526 if ( mAllDay ) 526 if ( mAllDay )
527 mDisplayedText += " ("; 527 mDisplayedText += " (";
528 else 528 else
529 mDisplayedText += "\n("; 529 mDisplayedText += "\n(";
530 mDisplayedText += mIncidence->location() +")"; 530 mDisplayedText += mIncidence->location() +")";
531 } 531 }
532 532
533 QString tipText = mIncidence->summary(); 533 QString tipText = mIncidence->summary();
534 if ( !mIncidence->doesFloat() ) { 534 if ( !mIncidence->doesFloat() ) {
535 if ( mIncidence->type() == "Event" ) { 535 if ( mIncidence->type() == "Event" ) {
536 if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) { 536 if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) {
537 tipText += "\n"+i18n("From: ")+mIncidence->dtStartStr(); 537 tipText += "\n"+i18n("From: ")+mIncidence->dtStartStr();
538 tipText += "\n"+i18n("To: ")+(static_cast<Event*>(mIncidence))->dtEndStr(); 538 tipText += "\n"+i18n("To: ")+(static_cast<Event*>(mIncidence))->dtEndStr();
539 } 539 }
540 else { 540 else {
541 tipText += "\n"+i18n("Time: ")+mIncidence->dtStartTimeStr(); 541 tipText += "\n"+i18n("Time: ")+mIncidence->dtStartTimeStr();
542 tipText += " - "+(static_cast<Event*>(mIncidence))->dtEndTimeStr(); 542 tipText += " - "+(static_cast<Event*>(mIncidence))->dtEndTimeStr();
543 } 543 }
544 } 544 }
545 else if ( mIncidence->type() == "Todo" ) { 545 else if ( mIncidence->type() == "Todo" ) {
546 if (mIncidence->hasStartDate()) 546 if (mIncidence->hasStartDate())
547 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartStr(); 547 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartStr();
548 if (((Todo*)mIncidence)->hasDueDate()) 548 if (((Todo*)mIncidence)->hasDueDate())
549 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueStr(); 549 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueStr();
550 } 550 }
551 } else if ( mIncidence->type() == "Todo" ) { 551 } else if ( mIncidence->type() == "Todo" ) {
552 if (mIncidence->hasStartDate()) 552 if (mIncidence->hasStartDate())
553 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartDateStr(); 553 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartDateStr();
554 if (((Todo*)mIncidence)->hasDueDate()) 554 if (((Todo*)mIncidence)->hasDueDate())
555 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueDateStr(); 555 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueDateStr();
556 } 556 }
557 557
558 if (!mIncidence->location().isEmpty()) { 558 if (!mIncidence->location().isEmpty()) {
559 tipText += "\n"+i18n("Location: ")+mIncidence->location(); 559 tipText += "\n"+i18n("Location: ")+mIncidence->location();
560 } 560 }
561 QToolTip::add(this,tipText,toolTipGroup(),""); 561 QToolTip::add(this,tipText,toolTipGroup(),"");
562 562
563} 563}
564void KOAgendaItem::updateItem() 564void KOAgendaItem::updateItem()
565{ 565{
566 computeText(); 566 computeText();
567 567
568 //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y()); 568 //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y());
569 paintMe( mSelected ); 569 paintMe( mSelected );
570 repaint( false); 570 repaint( false);
571} 571}
572 572
573void KOAgendaItem::resizeEvent ( QResizeEvent *ev ) 573void KOAgendaItem::resizeEvent ( QResizeEvent *ev )
574{ 574{
575 //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1()); 575 //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1());
576 paintMe( mSelected ); 576 paintMe( mSelected );
577 repaint( false ); 577 repaint( false );
578} 578}
579 579
580/* 580/*
581 Return height of item in units of agenda cells 581 Return height of item in units of agenda cells
582*/ 582*/
583int KOAgendaItem::cellHeight() 583int KOAgendaItem::cellHeight()
584{ 584{
585 int ret = mCellYBottom - mCellYTop + 1; 585 int ret = mCellYBottom - mCellYTop + 1;
586 if ( ret <= 0 ) { 586 if ( ret <= 0 ) {
587 ret = 1; 587 ret = 1;
588 mCellYBottom = 0; 588 mCellYBottom = 0;
589 mCellYTop = 0; 589 mCellYTop = 0;
590 } 590 }
591 return ret; 591 return ret;
592} 592}
593 593
594/* 594/*
595 Return height of item in units of agenda cells 595 Return height of item in units of agenda cells
596*/ 596*/
597int KOAgendaItem::cellWidth() 597int KOAgendaItem::cellWidth()
598{ 598{
599 return mCellXWidth - mCellX + 1; 599 return mCellXWidth - mCellX + 1;
600} 600}
601 601
602void KOAgendaItem::setItemDate(QDate qd) 602void KOAgendaItem::setItemDate(QDate qd)
603{ 603{
604 mDate = qd; 604 mDate = qd;
605} 605}
606 606
607void KOAgendaItem::setCellXY(int X, int YTop, int YBottom) 607void KOAgendaItem::setCellXY(int X, int YTop, int YBottom)
608{ 608{
609 mCellX = X; 609 mCellX = X;
610 mCellYTop = YTop; 610 mCellYTop = YTop;
611 mCellYBottom = YBottom; 611 mCellYBottom = YBottom;
612} 612}
613 613
614void KOAgendaItem::setCellXWidth(int xwidth) 614void KOAgendaItem::setCellXWidth(int xwidth)
615{ 615{
616 mCellXWidth = xwidth; 616 mCellXWidth = xwidth;
617} 617}
618 618
619void KOAgendaItem::setCellX(int XLeft, int XRight) 619void KOAgendaItem::setCellX(int XLeft, int XRight)
620{ 620{
621 mCellX = XLeft; 621 mCellX = XLeft;
622 mCellXWidth = XRight; 622 mCellXWidth = XRight;
623} 623}
624 624
625void KOAgendaItem::setCellY(int YTop, int YBottom) 625void KOAgendaItem::setCellY(int YTop, int YBottom)
626{ 626{
627 mCellYTop = YTop; 627 mCellYTop = YTop;
628 mCellYBottom = YBottom; 628 mCellYBottom = YBottom;
629} 629}
630 630
631void KOAgendaItem::setSubCell(int subCell) 631void KOAgendaItem::setSubCell(int subCell)
632{ 632{
633 mSubCell = subCell; 633 mSubCell = subCell;
634} 634}
635 635
636void KOAgendaItem::setSubCells(int subCells) 636void KOAgendaItem::setSubCells(int subCells)
637{ 637{
638 mSubCells = subCells; 638 mSubCells = subCells;
639} 639}
640 640
641void KOAgendaItem::setMultiItem(KOAgendaItem *first,KOAgendaItem *next, 641void KOAgendaItem::setMultiItem(KOAgendaItem *first,KOAgendaItem *next,
642 KOAgendaItem *last) 642 KOAgendaItem *last)
643{ 643{
644 mFirstMultiItem = first; 644 mFirstMultiItem = first;
645 mNextMultiItem = next; 645 mNextMultiItem = next;
646 mLastMultiItem = last; 646 mLastMultiItem = last;
647} 647}
648 648
649void KOAgendaItem::startMove() 649void KOAgendaItem::startMove()
650{ 650{
651 mStartCellX = mCellX; 651 mStartCellX = mCellX;
652 mStartCellXWidth = mCellXWidth; 652 mStartCellXWidth = mCellXWidth;
653 mStartCellYTop = mCellYTop; 653 mStartCellYTop = mCellYTop;
654 mStartCellYBottom = mCellYBottom; 654 mStartCellYBottom = mCellYBottom;
655} 655}
656 656
657void KOAgendaItem::resetMove() 657void KOAgendaItem::resetMove()
658{ 658{
659 mCellX = mStartCellX; 659 mCellX = mStartCellX;
660 mCellXWidth = mStartCellXWidth; 660 mCellXWidth = mStartCellXWidth;
661 mCellYTop = mStartCellYTop; 661 mCellYTop = mStartCellYTop;
662 mCellYBottom = mStartCellYBottom; 662 mCellYBottom = mStartCellYBottom;
663} 663}
664 664
665void KOAgendaItem::moveRelative(int dx, int dy) 665void KOAgendaItem::moveRelative(int dx, int dy)
666{ 666{
667 int newX = cellX() + dx; 667 int newX = cellX() + dx;
668 int newXWidth = cellXWidth() + dx; 668 int newXWidth = cellXWidth() + dx;
669 int newYTop = cellYTop() + dy; 669 int newYTop = cellYTop() + dy;
670 int newYBottom = cellYBottom() + dy; 670 int newYBottom = cellYBottom() + dy;
671 setCellXY(newX,newYTop,newYBottom); 671 setCellXY(newX,newYTop,newYBottom);
672 setCellXWidth(newXWidth); 672 setCellXWidth(newXWidth);
673} 673}
674 674
675void KOAgendaItem::expandTop(int dy) 675void KOAgendaItem::expandTop(int dy)
676{ 676{
677 int newYTop = cellYTop() + dy; 677 int newYTop = cellYTop() + dy;
678 int newYBottom = cellYBottom(); 678 int newYBottom = cellYBottom();
679 if (newYTop > newYBottom) newYTop = newYBottom; 679 if (newYTop > newYBottom) newYTop = newYBottom;
680 setCellY(newYTop, newYBottom); 680 setCellY(newYTop, newYBottom);
681} 681}
682 682
683void KOAgendaItem::expandBottom(int dy) 683void KOAgendaItem::expandBottom(int dy)
684{ 684{
685 int newYTop = cellYTop(); 685 int newYTop = cellYTop();
686 int newYBottom = cellYBottom() + dy; 686 int newYBottom = cellYBottom() + dy;
687 if (newYBottom < newYTop) newYBottom = newYTop; 687 if (newYBottom < newYTop) newYBottom = newYTop;
688 setCellY(newYTop, newYBottom); 688 setCellY(newYTop, newYBottom);
689} 689}
690 690
691void KOAgendaItem::expandLeft(int dx) 691void KOAgendaItem::expandLeft(int dx)
692{ 692{
693 int newX = cellX() + dx; 693 int newX = cellX() + dx;
694 int newXWidth = cellXWidth(); 694 int newXWidth = cellXWidth();
695 if (newX > newXWidth) newX = newXWidth; 695 if (newX > newXWidth) newX = newXWidth;
696 setCellX(newX,newXWidth); 696 setCellX(newX,newXWidth);
697} 697}
698 698
699void KOAgendaItem::expandRight(int dx) 699void KOAgendaItem::expandRight(int dx)
700{ 700{
701 int newX = cellX(); 701 int newX = cellX();
702 int newXWidth = cellXWidth() + dx; 702 int newXWidth = cellXWidth() + dx;
703 if (newXWidth < newX) newXWidth = newX; 703 if (newXWidth < newX) newXWidth = newX;
704 setCellX(newX,newXWidth); 704 setCellX(newX,newXWidth);
705} 705}
706 706
707QToolTipGroup *KOAgendaItem::toolTipGroup() 707QToolTipGroup *KOAgendaItem::toolTipGroup()
708{ 708{
709 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); 709 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0);
710 return mToolTipGroup; 710 return mToolTipGroup;
711} 711}
712 712
713void KOAgendaItem::dragEnterEvent( QDragEnterEvent *e ) 713void KOAgendaItem::dragEnterEvent( QDragEnterEvent *e )
714{ 714{
715#ifndef KORG_NODND 715#ifndef KORG_NODND
716 if ( ICalDrag::canDecode( e ) || VCalDrag::canDecode( e ) || 716 if ( ICalDrag::canDecode( e ) || VCalDrag::canDecode( e ) ||
717 !QTextDrag::canDecode( e ) ) { 717 !QTextDrag::canDecode( e ) ) {
718 e->ignore(); 718 e->ignore();
719 return; 719 return;
720 } 720 }
721 e->accept(); 721 e->accept();
722#endif 722#endif
723} 723}
724 724
725void KOAgendaItem::dropEvent( QDropEvent *e ) 725void KOAgendaItem::dropEvent( QDropEvent *e )
726{ 726{
727#ifndef KORG_NODND 727#ifndef KORG_NODND
728 QString text; 728 QString text;
729 if(QTextDrag::decode(e,text)) 729 if(QTextDrag::decode(e,text))
730 { 730 {
731 kdDebug() << "Dropped : " << text << endl; 731 kdDebug() << "Dropped : " << text << endl;
732 QStringList emails = QStringList::split(",",text); 732 QStringList emails = QStringList::split(",",text);
733 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { 733 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
734 kdDebug() << " Email: " << (*it) << endl; 734 kdDebug() << " Email: " << (*it) << endl;
735 int pos = (*it).find("<"); 735 int pos = (*it).find("<");
736 QString name = (*it).left(pos); 736 QString name = (*it).left(pos);
737 QString email = (*it).mid(pos); 737 QString email = (*it).mid(pos);
738 if (!email.isEmpty()) { 738 if (!email.isEmpty()) {
739 mIncidence->addAttendee(new Attendee(name,email)); 739 mIncidence->addAttendee(new Attendee(name,email));
740 } 740 }
741 } 741 }
742 } 742 }
743#endif 743#endif
744} 744}
745 745
746 746
747QPtrList<KOAgendaItem> KOAgendaItem::conflictItems() 747QPtrList<KOAgendaItem> KOAgendaItem::conflictItems()
748{ 748{
749 return mConflictItems; 749 return mConflictItems;
750} 750}
751 751
752void KOAgendaItem::setConflictItems(QPtrList<KOAgendaItem> ci) 752void KOAgendaItem::setConflictItems(QPtrList<KOAgendaItem> ci)
753{ 753{
754 mConflictItems = ci; 754 mConflictItems = ci;
755 KOAgendaItem *item; 755 KOAgendaItem *item;
756 for ( item=mConflictItems.first(); item != 0; 756 for ( item=mConflictItems.first(); item != 0;
757 item=mConflictItems.next() ) { 757 item=mConflictItems.next() ) {
758 item->addConflictItem(this); 758 item->addConflictItem(this);
759 } 759 }
760} 760}
761 761
762void KOAgendaItem::addConflictItem(KOAgendaItem *ci) 762void KOAgendaItem::addConflictItem(KOAgendaItem *ci)
763{ 763{
764 if (mConflictItems.find(ci)<0) 764 if (mConflictItems.find(ci)<0)
765 mConflictItems.append(ci); 765 mConflictItems.append(ci);
766} 766}
767 767
768bool KOAgendaItem::checkLayout() 768bool KOAgendaItem::checkLayout()
769{ 769{
770 if ( !mConflictItems.count() ) 770 if ( !mConflictItems.count() )
771 return true; 771 return true;
772 int max = 0; 772 int max = 0;
773 KOAgendaItem *item; 773 KOAgendaItem *item;
774 for ( item=mConflictItems.first(); item != 0; 774 for ( item=mConflictItems.first(); item != 0;
775 item=mConflictItems.next() ) { 775 item=mConflictItems.next() ) {
776 if ( item->subCells() > max ) 776 if ( item->subCells() > max )
777 max = item->subCells(); 777 max = item->subCells();
778 } 778 }
779 if ( max > subCells() ) { 779 if ( max > subCells() ) {
780 setSubCells( max ); 780 setSubCells( max );
781 return false; 781 return false;
782 } 782 }
783 return true; 783 return true;
784} 784}
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index 9c1f5f3..582b2ef 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -1,921 +1,919 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> 3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at>
4 Parts of the source code have been copied from kdpdatebutton.cpp 4 Parts of the source code have been copied from kdpdatebutton.cpp
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source ode for Qt in the source distribution. 22 without including the source ode for Qt in the source distribution.
23*/ 23*/
24 24
25#include <qevent.h> 25#include <qevent.h>
26#include <qpainter.h> 26#include <qpainter.h>
27#include <qptrlist.h> 27#include <qptrlist.h>
28#include <qtimer.h> 28#include <qtimer.h>
29#include <qwhatsthis.h> 29#include <qwhatsthis.h>
30 30
31#include <kglobal.h> 31#include <kglobal.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <klocale.h> 33#include <klocale.h>
34 34
35#include <libkcal/vcaldrag.h> 35#include <libkcal/vcaldrag.h>
36#include <libkcal/icaldrag.h> 36#include <libkcal/icaldrag.h>
37#include <libkcal/dndfactory.h> 37#include <libkcal/dndfactory.h>
38#include <libkcal/calendarresources.h> 38#include <libkcal/calendarresources.h>
39#include <libkcal/resourcecalendar.h> 39#include <libkcal/resourcecalendar.h>
40#include <kresources/resourceselectdialog.h> 40#include <kresources/resourceselectdialog.h>
41 41
42#include <kcalendarsystem.h> 42#include <kcalendarsystem.h>
43 43
44#ifndef KORG_NOPLUGINS 44#ifndef KORG_NOPLUGINS
45#include "kocore.h" 45#include "kocore.h"
46#endif 46#endif
47#include "koprefs.h" 47#include "koprefs.h"
48#include "koglobals.h" 48#include "koglobals.h"
49 49
50#include "kodaymatrix.h" 50#include "kodaymatrix.h"
51 51
52// ============================================================================ 52// ============================================================================
53// D Y N A M I C T I P 53// D Y N A M I C T I P
54// ============================================================================ 54// ============================================================================
55 55
56DynamicTip::DynamicTip( QWidget * parent ) 56DynamicTip::DynamicTip( QWidget * parent )
57 : QToolTip( parent ) 57 : QToolTip( parent )
58{ 58{
59 matrix = (KODayMatrix*)parent; 59 matrix = (KODayMatrix*)parent;
60} 60}
61 61
62class KODaymatrixWhatsThis :public QWhatsThis 62class KODaymatrixWhatsThis :public QWhatsThis
63{ 63{
64public: 64public:
65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;}; 65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;};
66 ~KODaymatrixWhatsThis() { ; }; 66 ~KODaymatrixWhatsThis() { ; };
67 67
68protected: 68protected:
69 virtual QString text( const QPoint& p ) 69 virtual QString text( const QPoint& p )
70 { 70 {
71 return _view->getWhatsThisText( p ) ; 71 return _view->getWhatsThisText( p ) ;
72 } 72 }
73private: 73private:
74 KODayMatrix * _view; 74 KODayMatrix * _view;
75}; 75};
76 76
77void DynamicTip::maybeTip( const QPoint &pos ) 77void DynamicTip::maybeTip( const QPoint &pos )
78{ 78{
79 //calculate which cell of the matrix the mouse is in 79 //calculate which cell of the matrix the mouse is in
80 QRect sz = matrix->frameRect(); 80 QRect sz = matrix->frameRect();
81 int dheight = sz.height()*7 / 42; 81 int dheight = sz.height()*7 / 42;
82 int dwidth = sz.width() / 7; 82 int dwidth = sz.width() / 7;
83 int row = pos.y()/dheight; 83 int row = pos.y()/dheight;
84 int col = pos.x()/dwidth; 84 int col = pos.x()/dwidth;
85 85
86 QRect rct(col*dwidth, row*dheight, dwidth, dheight); 86 QRect rct(col*dwidth, row*dheight, dwidth, dheight);
87 87
88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" << 88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" <<
89// col << "][" << row << "] => " <<(col+row*7) << endl; 89// col << "][" << row << "] => " <<(col+row*7) << endl;
90 90
91 //show holiday names only 91 //show holiday names only
92 QString str = matrix->getHolidayLabel(col+row*7); 92 QString str = matrix->getHolidayLabel(col+row*7);
93 if (str.isEmpty()) return; 93 if (str.isEmpty()) return;
94 tip(rct, str); 94 tip(rct, str);
95} 95}
96 96
97 97
98// ============================================================================ 98// ============================================================================
99// K O D A Y M A T R I X 99// K O D A Y M A T R I X
100// ============================================================================ 100// ============================================================================
101 101
102const int KODayMatrix::NOSELECTION = -1000; 102const int KODayMatrix::NOSELECTION = -1000;
103const int KODayMatrix::NUMDAYS = 42; 103const int KODayMatrix::NUMDAYS = 42;
104 104
105KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) 105KODayMatrix::KODayMatrix( QWidget *parent, const char *name )
106 : QFrame( parent, name ), mCalendar( 0 ) 106 : QFrame( parent, name ), mCalendar( 0 )
107 107
108#if 0 108#if 0
109KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : 109KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) :
110 QFrame(parent, name) 110 QFrame(parent, name)
111#endif 111#endif
112{ 112{
113 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); 113 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this);
114 mPendingUpdateBeforeRepaint = false; 114 mPendingUpdateBeforeRepaint = false;
115 mouseDown = false; 115 mouseDown = false;
116 // initialize dynamic arrays 116 // initialize dynamic arrays
117 bDays.resize ( NUMDAYS ); 117 bDays.resize ( NUMDAYS );
118 days = new QDate[NUMDAYS]; 118 days = new QDate[NUMDAYS];
119 daylbls = new QString[NUMDAYS]; 119 daylbls = new QString[NUMDAYS];
120 events = new int[NUMDAYS]; 120 events = new int[NUMDAYS];
121 mToolTip = new DynamicTip(this); 121 mToolTip = new DynamicTip(this);
122 122
123 // set default values used for drawing the matrix 123 // set default values used for drawing the matrix
124 mDefaultBackColor = palette().active().base(); 124 mDefaultBackColor = palette().active().base();
125 mDefaultTextColor = palette().active().foreground(); 125 mDefaultTextColor = palette().active().foreground();
126 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); 126 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor);
127 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); 127 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor);
128 mSelectedDaysColor = QColor("white"); 128 mSelectedDaysColor = QColor("white");
129 mTodayMarginWidth = 2; 129 mTodayMarginWidth = 2;
130 mSelEnd = mSelStart = NOSELECTION; 130 mSelEnd = mSelStart = NOSELECTION;
131 131
132 setAcceptDrops(true); 132 setAcceptDrops(true);
133 //setFont( QFont("Arial", 10) ); 133 //setFont( QFont("Arial", 10) );
134 134
135 mUpdateTimer = new QTimer( this ); 135 mUpdateTimer = new QTimer( this );
136 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); 136 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() ));
137 mRepaintTimer = new QTimer( this ); 137 mRepaintTimer = new QTimer( this );
138 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); 138 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() ));
139 mDayChanged = false; 139 mDayChanged = false;
140 updateView(); 140 updateView();
141} 141}
142QString KODayMatrix::getWhatsThisText( QPoint p ) 142QString KODayMatrix::getWhatsThisText( QPoint p )
143{ 143{
144 144
145 int tmp = getDayIndexFrom(p.x(), p.y()); 145 int tmp = getDayIndexFrom(p.x(), p.y());
146 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) 146 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar )
147 return QString(); 147 return QString();
148 QDate mDate = days[tmp]; 148 QDate mDate = days[tmp];
149 QPtrList<Event> eventlist = mCalendar->events(mDate); 149 QPtrList<Event> eventlist = mCalendar->events(mDate);
150 Event *event; 150 Event *event;
151 QStringList mToolTip; 151 QStringList mToolTip;
152 for(event=eventlist.first();event != 0;event=eventlist.next()) { 152 for(event=eventlist.first();event != 0;event=eventlist.next()) {
153 QString mToolTipText; 153 QString mToolTipText;
154 QString text; 154 QString text;
155 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day 155 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
156 if (event->isMultiDay()) { 156 if (event->isMultiDay()) {
157 QString prefix = "<->";multiday = 2; 157 QString prefix = "<->";multiday = 2;
158 QString time; 158 QString time;
159 if ( event->doesRecur() ) { 159 if ( event->doesRecur() ) {
160 if ( event->recursOn( mDate) ) { 160 if ( event->recursOn( mDate) ) {
161 prefix ="->" ;multiday = 1; 161 prefix ="->" ;multiday = 1;
162 } 162 }
163 else { 163 else {
164 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 164 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
165 if ( event->recursOn( mDate.addDays( -days)) ) { 165 if ( event->recursOn( mDate.addDays( -days)) ) {
166 prefix ="<-" ;multiday = 3; 166 prefix ="<-" ;multiday = 3;
167 } 167 }
168 } 168 }
169 } else { 169 } else {
170 if (mDate == event->dtStart().date()) { 170 if (mDate == event->dtStart().date()) {
171 prefix ="->" ;multiday = 1; 171 prefix ="->" ;multiday = 1;
172 } else if (mDate == event->dtEnd().date()) { 172 } else if (mDate == event->dtEnd().date()) {
173 prefix ="<-" ;multiday = 3; 173 prefix ="<-" ;multiday = 3;
174 } 174 }
175 } 175 }
176 if ( !event->doesFloat() ) { 176 if ( !event->doesFloat() ) {
177 if ( mDate == event->dtStart().date () ) 177 if ( mDate == event->dtStart().date () )
178 time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; 178 time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
179 else if ( mDate == event->dtEnd().date () ) 179 else if ( mDate == event->dtEnd().date () )
180 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 180 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
181 181
182 } 182 }
183 qDebug("event->isMultiDay() %s", event->summary().latin1() );
184 text = time + event->summary(); 183 text = time + event->summary();
185 mToolTipText += prefix + text; 184 mToolTipText += prefix + text;
186 } else { 185 } else {
187 if (event->doesFloat()) { 186 if (event->doesFloat()) {
188 text = event->summary(); 187 text = event->summary();
189 mToolTipText += text; 188 mToolTipText += text;
190 } 189 }
191 else { 190 else {
192 text = KGlobal::locale()->formatTime(event->dtStart().time()); 191 text = KGlobal::locale()->formatTime(event->dtStart().time());
193 text += " " + event->summary(); 192 text += " " + event->summary();
194 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 193 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
195 } 194 }
196 } 195 }
197 if ( !event->location().isEmpty() ) 196 if ( !event->location().isEmpty() )
198 mToolTipText += " (" + event->location() + ")"; 197 mToolTipText += " (" + event->location() + ")";
199#if QT_VERSION >= 0x030000 198#if QT_VERSION >= 0x030000
200 mToolTipText.replace( '<' , "&lt;" ); 199 mToolTipText.replace( '<' , "&lt;" );
201 mToolTipText.replace( '>' , "&gt;" ); 200 mToolTipText.replace( '>' , "&gt;" );
202#else 201#else
203 if ( mToolTipText.find ('<') > 0 ) { 202 if ( mToolTipText.find ('<') > 0 ) {
204 mToolTipText.replace( QRegExp("<") , "&lt;" ); 203 mToolTipText.replace( QRegExp("<") , "&lt;" );
205 } 204 }
206 if ( mToolTipText.find ('>') > 0 ) { 205 if ( mToolTipText.find ('>') > 0 ) {
207 mToolTipText.replace( QRegExp(">") , "&gt;" ); 206 mToolTipText.replace( QRegExp(">") , "&gt;" );
208 } 207 }
209#endif 208#endif
210 mToolTip.append( mToolTipText ); 209 mToolTip.append( mToolTipText );
211 } 210 }
212 mToolTip.sort(); 211 mToolTip.sort();
213 qDebug("%s ", mToolTip.join("<br>").latin1());
214 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); 212 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>");
215} 213}
216void KODayMatrix::setCalendar( Calendar *cal ) 214void KODayMatrix::setCalendar( Calendar *cal )
217{ 215{
218 mCalendar = cal; 216 mCalendar = cal;
219 217
220 setAcceptDrops( mCalendar ); 218 setAcceptDrops( mCalendar );
221 219
222 updateEvents(); 220 updateEvents();
223} 221}
224 222
225QColor KODayMatrix::getShadedColor(QColor color) 223QColor KODayMatrix::getShadedColor(QColor color)
226{ 224{
227 QColor shaded; 225 QColor shaded;
228 int h=0; 226 int h=0;
229 int s=0; 227 int s=0;
230 int v=0; 228 int v=0;
231 color.hsv(&h,&s,&v); 229 color.hsv(&h,&s,&v);
232 s = s/4; 230 s = s/4;
233 v = 192+v/4; 231 v = 192+v/4;
234 shaded.setHsv(h,s,v); 232 shaded.setHsv(h,s,v);
235 233
236 return shaded; 234 return shaded;
237} 235}
238 236
239KODayMatrix::~KODayMatrix() 237KODayMatrix::~KODayMatrix()
240{ 238{
241 // delete mKODaymatrixWhatsThis; 239 // delete mKODaymatrixWhatsThis;
242 delete [] days; 240 delete [] days;
243 delete [] daylbls; 241 delete [] daylbls;
244 delete [] events; 242 delete [] events;
245 delete mToolTip; 243 delete mToolTip;
246} 244}
247 245
248/* 246/*
249void KODayMatrix::setStartDate(QDate start) 247void KODayMatrix::setStartDate(QDate start)
250{ 248{
251 updateView(start); 249 updateView(start);
252} 250}
253*/ 251*/
254 252
255void KODayMatrix::addSelectedDaysTo(DateList& selDays) 253void KODayMatrix::addSelectedDaysTo(DateList& selDays)
256{ 254{
257 255
258 if (mSelStart == NOSELECTION) { 256 if (mSelStart == NOSELECTION) {
259 return; 257 return;
260 } 258 }
261 259
262 //cope with selection being out of matrix limits at top (< 0) 260 //cope with selection being out of matrix limits at top (< 0)
263 int i0 = mSelStart; 261 int i0 = mSelStart;
264 if (i0 < 0) { 262 if (i0 < 0) {
265 for (int i = i0; i < 0; i++) { 263 for (int i = i0; i < 0; i++) {
266 selDays.append(days[0].addDays(i)); 264 selDays.append(days[0].addDays(i));
267 } 265 }
268 i0 = 0; 266 i0 = 0;
269 } 267 }
270 268
271 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) 269 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1)
272 if (mSelEnd > NUMDAYS-1) { 270 if (mSelEnd > NUMDAYS-1) {
273 for (int i = i0; i <= NUMDAYS-1; i++) { 271 for (int i = i0; i <= NUMDAYS-1; i++) {
274 selDays.append(days[i]); 272 selDays.append(days[i]);
275 } 273 }
276 for (int i = NUMDAYS; i < mSelEnd; i++) { 274 for (int i = NUMDAYS; i < mSelEnd; i++) {
277 selDays.append(days[0].addDays(i)); 275 selDays.append(days[0].addDays(i));
278 } 276 }
279 277
280 // apply normal routine to selection being entirely within matrix limits 278 // apply normal routine to selection being entirely within matrix limits
281 } else { 279 } else {
282 for (int i = i0; i <= mSelEnd; i++) { 280 for (int i = i0; i <= mSelEnd; i++) {
283 selDays.append(days[i]); 281 selDays.append(days[i]);
284 } 282 }
285 } 283 }
286} 284}
287 285
288void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) 286void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
289{ 287{
290 mSelStart = startdate.daysTo(start); 288 mSelStart = startdate.daysTo(start);
291 if ( mSelStart < 0 ) 289 if ( mSelStart < 0 )
292 mSelStart = 0; 290 mSelStart = 0;
293 mSelEnd = startdate.daysTo(end); 291 mSelEnd = startdate.daysTo(end);
294 if ( mSelEnd < 0 ) 292 if ( mSelEnd < 0 )
295 clearSelection(); 293 clearSelection();
296} 294}
297void KODayMatrix::clearSelection() 295void KODayMatrix::clearSelection()
298{ 296{
299 mSelEnd = mSelStart = NOSELECTION; 297 mSelEnd = mSelStart = NOSELECTION;
300} 298}
301 299
302 300
303void KODayMatrix::recalculateToday() 301void KODayMatrix::recalculateToday()
304{ 302{
305 today = -1; 303 today = -1;
306 for (int i=0; i<NUMDAYS; i++) { 304 for (int i=0; i<NUMDAYS; i++) {
307 events[i] = 0; 305 events[i] = 0;
308 days[i] = startdate.addDays(i); 306 days[i] = startdate.addDays(i);
309 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); 307 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
310 308
311 // if today is in the currently displayed month, hilight today 309 // if today is in the currently displayed month, hilight today
312 if (days[i].year() == QDate::currentDate().year() && 310 if (days[i].year() == QDate::currentDate().year() &&
313 days[i].month() == QDate::currentDate().month() && 311 days[i].month() == QDate::currentDate().month() &&
314 days[i].day() == QDate::currentDate().day()) { 312 days[i].day() == QDate::currentDate().day()) {
315 today = i; 313 today = i;
316 } 314 }
317 } 315 }
318 // qDebug(QString("Today is visible at %1.").arg(today)); 316 // qDebug(QString("Today is visible at %1.").arg(today));
319} 317}
320 318
321void KODayMatrix::updateView() 319void KODayMatrix::updateView()
322{ 320{
323 updateView(startdate); 321 updateView(startdate);
324} 322}
325void KODayMatrix::repaintViewTimed() 323void KODayMatrix::repaintViewTimed()
326{ 324{
327 mRepaintTimer->stop(); 325 mRepaintTimer->stop();
328 repaint(false); 326 repaint(false);
329} 327}
330void KODayMatrix::updateViewTimed() 328void KODayMatrix::updateViewTimed()
331{ 329{
332 mUpdateTimer->stop(); 330 mUpdateTimer->stop();
333 if ( !mCalendar ) { 331 if ( !mCalendar ) {
334 qDebug("NOT CAL "); 332 qDebug("NOT CAL ");
335 return; 333 return;
336 } 334 }
337 //qDebug("KODayMatrix::updateViewTimed "); 335 //qDebug("KODayMatrix::updateViewTimed ");
338 for(int i = 0; i < NUMDAYS; i++) { 336 for(int i = 0; i < NUMDAYS; i++) {
339 // if events are set for the day then remember to draw it bold 337 // if events are set for the day then remember to draw it bold
340 QPtrList<Event> eventlist = mCalendar->events(days[i]); 338 QPtrList<Event> eventlist = mCalendar->events(days[i]);
341 Event *event; 339 Event *event;
342 int numEvents = eventlist.count(); 340 int numEvents = eventlist.count();
343 QString holiStr = ""; 341 QString holiStr = "";
344 bDays.clearBit(i); 342 bDays.clearBit(i);
345 for(event=eventlist.first();event != 0;event=eventlist.next()) { 343 for(event=eventlist.first();event != 0;event=eventlist.next()) {
346 ushort recurType = event->recurrence()->doesRecur(); 344 ushort recurType = event->recurrence()->doesRecur();
347 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 345 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
348 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 346 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
349 numEvents--; 347 numEvents--;
350 } 348 }
351 if ( event->categories().contains( i18n("Holiday") ) || event->categories().contains( "Holiday" )) { 349 if ( event->categories().contains( i18n("Holiday") ) || event->categories().contains( "Holiday" )) {
352 if ( !holiStr.isEmpty() ) 350 if ( !holiStr.isEmpty() )
353 holiStr += "\n"; 351 holiStr += "\n";
354 holiStr += event->summary(); 352 holiStr += event->summary();
355 if ( !event->location().isEmpty() ) 353 if ( !event->location().isEmpty() )
356 holiStr += " (" + event->location() + ")"; 354 holiStr += " (" + event->location() + ")";
357 } 355 }
358 if ( event->categories().contains( i18n("Birthday") ) || event->categories().contains( "Birthday" )) { 356 if ( event->categories().contains( i18n("Birthday") ) || event->categories().contains( "Birthday" )) {
359 if ( !holiStr.isEmpty() ) 357 if ( !holiStr.isEmpty() )
360 holiStr += "\n"; 358 holiStr += "\n";
361 holiStr += i18n("Birthday") + ": "+event->summary(); 359 holiStr += i18n("Birthday") + ": "+event->summary();
362 if ( !event->location().isEmpty() ) 360 if ( !event->location().isEmpty() )
363 holiStr += " (" + event->location() + ")"; 361 holiStr += " (" + event->location() + ")";
364 bDays.setBit(i); 362 bDays.setBit(i);
365 } 363 }
366 } 364 }
367 events[i] = numEvents; 365 events[i] = numEvents;
368 //if it is a holy day then draw it red. Sundays are consider holidays, too 366 //if it is a holy day then draw it red. Sundays are consider holidays, too
369 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || 367 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) ||
370 !holiStr.isEmpty()) { 368 !holiStr.isEmpty()) {
371 mHolidays[i] = holiStr; 369 mHolidays[i] = holiStr;
372 } else { 370 } else {
373 mHolidays[i] = QString::null; 371 mHolidays[i] = QString::null;
374 } 372 }
375 } 373 }
376 if ( ! mPendingUpdateBeforeRepaint ) 374 if ( ! mPendingUpdateBeforeRepaint )
377 repaint(false); 375 repaint(false);
378} 376}
379void KODayMatrix::updateView(QDate actdate) 377void KODayMatrix::updateView(QDate actdate)
380{ 378{
381 379
382 if ( ! actdate.isValid() ) { 380 if ( ! actdate.isValid() ) {
383 //qDebug("date not valid "); 381 //qDebug("date not valid ");
384 return; 382 return;
385 } 383 }
386 mDayChanged = false; 384 mDayChanged = false;
387 //flag to indicate if the starting day of the matrix has changed by this call 385 //flag to indicate if the starting day of the matrix has changed by this call
388 //mDayChanged = false; 386 //mDayChanged = false;
389 // if a new startdate is to be set then apply Cornelius's calculation 387 // if a new startdate is to be set then apply Cornelius's calculation
390 // of the first day to be shown 388 // of the first day to be shown
391 if (actdate != startdate) { 389 if (actdate != startdate) {
392 // reset index of selection according to shift of starting date from startdate to actdate 390 // reset index of selection according to shift of starting date from startdate to actdate
393 if (mSelStart != NOSELECTION) { 391 if (mSelStart != NOSELECTION) {
394 int tmp = actdate.daysTo(startdate); 392 int tmp = actdate.daysTo(startdate);
395 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; 393 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl;
396 // shift selection if new one would be visible at least partly ! 394 // shift selection if new one would be visible at least partly !
397 395
398 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { 396 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) {
399 // nested if is required for next X display pushed from a different month - correction required 397 // nested if is required for next X display pushed from a different month - correction required
400 // otherwise, for month forward and backward, it must be avoided 398 // otherwise, for month forward and backward, it must be avoided
401 if( mSelStart > NUMDAYS || mSelStart < 0 ) 399 if( mSelStart > NUMDAYS || mSelStart < 0 )
402 mSelStart = mSelStart + tmp; 400 mSelStart = mSelStart + tmp;
403 if( mSelEnd > NUMDAYS || mSelEnd < 0 ) 401 if( mSelEnd > NUMDAYS || mSelEnd < 0 )
404 mSelEnd = mSelEnd + tmp; 402 mSelEnd = mSelEnd + tmp;
405 } 403 }
406 } 404 }
407 startdate = actdate; 405 startdate = actdate;
408 mDayChanged = true; 406 mDayChanged = true;
409 recalculateToday(); 407 recalculateToday();
410 } 408 }
411 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); 409 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() );
412 if ( !isVisible() ) { 410 if ( !isVisible() ) {
413 mPendingUpdateBeforeRepaint = true; 411 mPendingUpdateBeforeRepaint = true;
414 } else { 412 } else {
415#ifdef DESKTOP_VERSION 413#ifdef DESKTOP_VERSION
416 //mRepaintTimer->start( 150 ); 414 //mRepaintTimer->start( 150 );
417 mUpdateTimer->start( 150 ); 415 mUpdateTimer->start( 150 );
418#else 416#else
419 mRepaintTimer->start( 350 ); 417 mRepaintTimer->start( 350 );
420 mUpdateTimer->start( 1200 ); 418 mUpdateTimer->start( 1200 );
421#endif 419#endif
422 } 420 }
423} 421}
424void KODayMatrix::updateEvents() 422void KODayMatrix::updateEvents()
425{ 423{
426 if ( !mCalendar ) return; 424 if ( !mCalendar ) return;
427 425
428 for( int i = 0; i < NUMDAYS; i++ ) { 426 for( int i = 0; i < NUMDAYS; i++ ) {
429 // if events are set for the day then remember to draw it bold 427 // if events are set for the day then remember to draw it bold
430 QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); 428 QPtrList<Event> eventlist = mCalendar->events( days[ i ] );
431 int numEvents = eventlist.count(); 429 int numEvents = eventlist.count();
432 Event *event; 430 Event *event;
433 for( event = eventlist.first(); event != 0;event=eventlist.next()) { 431 for( event = eventlist.first(); event != 0;event=eventlist.next()) {
434 ushort recurType = event->doesRecur(); 432 ushort recurType = event->doesRecur();
435 433
436 if ( ( recurType == Recurrence::rDaily && 434 if ( ( recurType == Recurrence::rDaily &&
437 !KOPrefs::instance()->mDailyRecur ) || 435 !KOPrefs::instance()->mDailyRecur ) ||
438 ( recurType == Recurrence::rWeekly && 436 ( recurType == Recurrence::rWeekly &&
439 !KOPrefs::instance()->mWeeklyRecur ) ) { 437 !KOPrefs::instance()->mWeeklyRecur ) ) {
440 numEvents--; 438 numEvents--;
441 } 439 }
442 } 440 }
443 events[ i ] = numEvents; 441 events[ i ] = numEvents;
444 } 442 }
445} 443}
446 444
447const QDate& KODayMatrix::getDate(int offset) 445const QDate& KODayMatrix::getDate(int offset)
448{ 446{
449 if (offset < 0 || offset > NUMDAYS-1) { 447 if (offset < 0 || offset > NUMDAYS-1) {
450 qDebug("Wrong offset2 "); 448 qDebug("Wrong offset2 ");
451 return days[0]; 449 return days[0];
452 } 450 }
453 return days[offset]; 451 return days[offset];
454} 452}
455 453
456QString KODayMatrix::getHolidayLabel(int offset) 454QString KODayMatrix::getHolidayLabel(int offset)
457{ 455{
458 if (offset < 0 || offset > NUMDAYS-1) { 456 if (offset < 0 || offset > NUMDAYS-1) {
459 qDebug("Wrong offset1 "); 457 qDebug("Wrong offset1 ");
460 return 0; 458 return 0;
461 } 459 }
462 return mHolidays[offset]; 460 return mHolidays[offset];
463} 461}
464 462
465int KODayMatrix::getDayIndexFrom(int x, int y) 463int KODayMatrix::getDayIndexFrom(int x, int y)
466{ 464{
467 int colModulo = (width()-2) % 7; 465 int colModulo = (width()-2) % 7;
468 int rowModulo = (height()-2) % 6; 466 int rowModulo = (height()-2) % 6;
469#if 0 467#if 0
470 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? 468 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
471 6 - x/daysize.width() : x/daysize.width()); 469 6 - x/daysize.width() : x/daysize.width());
472#endif 470#endif
473 int xVal = (x-colModulo/2-2)/daysize.width(); 471 int xVal = (x-colModulo/2-2)/daysize.width();
474 int yVal = (y-rowModulo/2-2)/daysize.height(); 472 int yVal = (y-rowModulo/2-2)/daysize.height();
475 473
476 474
477 return 7*(yVal) + xVal; 475 return 7*(yVal) + xVal;
478 476
479} 477}
480 478
481// ---------------------------------------------------------------------------- 479// ----------------------------------------------------------------------------
482// M O U S E E V E N T H A N D L I N G 480// M O U S E E V E N T H A N D L I N G
483// ---------------------------------------------------------------------------- 481// ----------------------------------------------------------------------------
484 482
485void KODayMatrix::mousePressEvent (QMouseEvent* e) 483void KODayMatrix::mousePressEvent (QMouseEvent* e)
486{ 484{
487 485
488 if ( e->button() == LeftButton ) 486 if ( e->button() == LeftButton )
489 mouseDown = true; 487 mouseDown = true;
490 mSelStart = getDayIndexFrom(e->x(), e->y()); 488 mSelStart = getDayIndexFrom(e->x(), e->y());
491 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; 489 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1;
492 mSelInit = mSelStart; 490 mSelInit = mSelStart;
493 mSelEnd = mSelStart; 491 mSelEnd = mSelStart;
494 repaint(false); 492 repaint(false);
495} 493}
496 494
497void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) 495void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
498{ 496{
499 if ( e->button() == LeftButton ) 497 if ( e->button() == LeftButton )
500 if ( ! mouseDown ) { 498 if ( ! mouseDown ) {
501 return; 499 return;
502 } 500 }
503 else 501 else
504 mouseDown = false; 502 mouseDown = false;
505 int tmp = getDayIndexFrom(e->x(), e->y()); 503 int tmp = getDayIndexFrom(e->x(), e->y());
506 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 504 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
507 505
508 if (mSelInit > tmp) { 506 if (mSelInit > tmp) {
509 mSelEnd = mSelInit; 507 mSelEnd = mSelInit;
510 if (tmp != mSelStart) { 508 if (tmp != mSelStart) {
511 mSelStart = tmp; 509 mSelStart = tmp;
512 repaint(false); 510 repaint(false);
513 } 511 }
514 } else { 512 } else {
515 mSelStart = mSelInit; 513 mSelStart = mSelInit;
516 514
517 //repaint only if selection has changed 515 //repaint only if selection has changed
518 if (tmp != mSelEnd) { 516 if (tmp != mSelEnd) {
519 mSelEnd = tmp; 517 mSelEnd = tmp;
520 repaint(false); 518 repaint(false);
521 } 519 }
522 } 520 }
523 521
524 DateList daylist; 522 DateList daylist;
525 if ( mSelStart < 0 ) 523 if ( mSelStart < 0 )
526 mSelStart = 0; 524 mSelStart = 0;
527 for (int i = mSelStart; i <= mSelEnd; i++) { 525 for (int i = mSelStart; i <= mSelEnd; i++) {
528 daylist.append(days[i]); 526 daylist.append(days[i]);
529 } 527 }
530 emit selected((const DateList)daylist); 528 emit selected((const DateList)daylist);
531 529
532} 530}
533 531
534void KODayMatrix::mouseMoveEvent (QMouseEvent* e) 532void KODayMatrix::mouseMoveEvent (QMouseEvent* e)
535{ 533{
536 if ( ! mouseDown ) { 534 if ( ! mouseDown ) {
537 return; 535 return;
538 } 536 }
539 int tmp = getDayIndexFrom(e->x(), e->y()); 537 int tmp = getDayIndexFrom(e->x(), e->y());
540 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 538 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
541 539
542 if (mSelInit > tmp) { 540 if (mSelInit > tmp) {
543 mSelEnd = mSelInit; 541 mSelEnd = mSelInit;
544 if (tmp != mSelStart) { 542 if (tmp != mSelStart) {
545 mSelStart = tmp; 543 mSelStart = tmp;
546 repaint(false); 544 repaint(false);
547 } 545 }
548 } else { 546 } else {
549 mSelStart = mSelInit; 547 mSelStart = mSelInit;
550 548
551 //repaint only if selection has changed 549 //repaint only if selection has changed
552 if (tmp != mSelEnd) { 550 if (tmp != mSelEnd) {
553 mSelEnd = tmp; 551 mSelEnd = tmp;
554 repaint(false); 552 repaint(false);
555 } 553 }
556 } 554 }
557} 555}
558 556
559// ---------------------------------------------------------------------------- 557// ----------------------------------------------------------------------------
560// D R A G ' N D R O P H A N D L I N G 558// D R A G ' N D R O P H A N D L I N G
561// ---------------------------------------------------------------------------- 559// ----------------------------------------------------------------------------
562 560
563void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) 561void KODayMatrix::dragEnterEvent(QDragEnterEvent *e)
564{ 562{
565#ifndef KORG_NODND 563#ifndef KORG_NODND
566 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 564 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
567 e->ignore(); 565 e->ignore();
568 return; 566 return;
569 } 567 }
570 568
571 // some visual feedback 569 // some visual feedback
572// oldPalette = palette(); 570// oldPalette = palette();
573// setPalette(my_HilitePalette); 571// setPalette(my_HilitePalette);
574// update(); 572// update();
575#endif 573#endif
576} 574}
577 575
578void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) 576void KODayMatrix::dragMoveEvent(QDragMoveEvent *e)
579{ 577{
580#ifndef KORG_NODND 578#ifndef KORG_NODND
581 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 579 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
582 e->ignore(); 580 e->ignore();
583 return; 581 return;
584 } 582 }
585 583
586 e->accept(); 584 e->accept();
587#endif 585#endif
588} 586}
589 587
590void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) 588void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/)
591{ 589{
592#ifndef KORG_NODND 590#ifndef KORG_NODND
593// setPalette(oldPalette); 591// setPalette(oldPalette);
594// update(); 592// update();
595#endif 593#endif
596} 594}
597 595
598void KODayMatrix::dropEvent(QDropEvent *e) 596void KODayMatrix::dropEvent(QDropEvent *e)
599{ 597{
600#ifndef KORG_NODND 598#ifndef KORG_NODND
601// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; 599// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl;
602 600
603 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 601 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
604 e->ignore(); 602 e->ignore();
605 return; 603 return;
606 } 604 }
607 605
608 DndFactory factory( mCalendar ); 606 DndFactory factory( mCalendar );
609 Event *event = factory.createDrop(e); 607 Event *event = factory.createDrop(e);
610 608
611 if (event) { 609 if (event) {
612 e->acceptAction(); 610 e->acceptAction();
613 611
614 Event *existingEvent = mCalendar->event(event->uid()); 612 Event *existingEvent = mCalendar->event(event->uid());
615 613
616 if(existingEvent) { 614 if(existingEvent) {
617 // uniquify event 615 // uniquify event
618 event->recreate(); 616 event->recreate();
619/* 617/*
620 KMessageBox::sorry(this, 618 KMessageBox::sorry(this,
621 i18n("Event already exists in this calendar."), 619 i18n("Event already exists in this calendar."),
622 i18n("Drop Event")); 620 i18n("Drop Event"));
623 delete event; 621 delete event;
624 return; 622 return;
625*/ 623*/
626 } 624 }
627// kdDebug() << "Drop new Event" << endl; 625// kdDebug() << "Drop new Event" << endl;
628 // Adjust date 626 // Adjust date
629 QDateTime start = event->dtStart(); 627 QDateTime start = event->dtStart();
630 QDateTime end = event->dtEnd(); 628 QDateTime end = event->dtEnd();
631 int duration = start.daysTo(end); 629 int duration = start.daysTo(end);
632 int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); 630 int idx = getDayIndexFrom(e->pos().x(), e->pos().y());
633 631
634 start.setDate(days[idx]); 632 start.setDate(days[idx]);
635 end.setDate(days[idx].addDays(duration)); 633 end.setDate(days[idx].addDays(duration));
636 634
637 event->setDtStart(start); 635 event->setDtStart(start);
638 event->setDtEnd(end); 636 event->setDtEnd(end);
639 mCalendar->addEvent(event); 637 mCalendar->addEvent(event);
640 638
641 emit eventDropped(event); 639 emit eventDropped(event);
642 } else { 640 } else {
643// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; 641// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl;
644 e->ignore(); 642 e->ignore();
645 } 643 }
646#endif 644#endif
647} 645}
648 646
649// ---------------------------------------------------------------------------- 647// ----------------------------------------------------------------------------
650// P A I N T E V E N T H A N D L I N G 648// P A I N T E V E N T H A N D L I N G
651// ---------------------------------------------------------------------------- 649// ----------------------------------------------------------------------------
652 650
653void KODayMatrix::paintEvent(QPaintEvent * pevent) 651void KODayMatrix::paintEvent(QPaintEvent * pevent)
654{ 652{
655 QRect sz = frameRect(); 653 QRect sz = frameRect();
656 if ( sz.width() <= 0 || sz.height() <= 0 ) 654 if ( sz.width() <= 0 || sz.height() <= 0 )
657 return; 655 return;
658 if ( mPendingUpdateBeforeRepaint ) { 656 if ( mPendingUpdateBeforeRepaint ) {
659 updateViewTimed(); 657 updateViewTimed();
660 mPendingUpdateBeforeRepaint = false; 658 mPendingUpdateBeforeRepaint = false;
661 } 659 }
662 if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) { 660 if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) {
663 myPix.resize(sz.size() ); 661 myPix.resize(sz.size() );
664 } 662 }
665 QPainter p(&myPix); 663 QPainter p(&myPix);
666 p.setFont(font()); 664 p.setFont(font());
667 665
668 666
669 int dheight = daysize.height(); 667 int dheight = daysize.height();
670 int dwidth = daysize.width(); 668 int dwidth = daysize.width();
671 int row,col; 669 int row,col;
672 int selw, selh; 670 int selw, selh;
673 int xyOff = frameWidth(); 671 int xyOff = frameWidth();
674 int colModulo = sz.width() % 7; 672 int colModulo = sz.width() % 7;
675 int rowModulo = sz.height() % 6; 673 int rowModulo = sz.height() % 6;
676 //qDebug("col %d row %d ",colModulo,rowModulo ); 674 //qDebug("col %d row %d ",colModulo,rowModulo );
677 675
678 bool isRTL = KOGlobals::self()->reverseLayout(); 676 bool isRTL = KOGlobals::self()->reverseLayout();
679 677
680 // draw background and topleft frame 678 // draw background and topleft frame
681 p.fillRect(pevent->rect(), mDefaultBackColor); 679 p.fillRect(pevent->rect(), mDefaultBackColor);
682 p.setPen(mDefaultTextColor); 680 p.setPen(mDefaultTextColor);
683 p.drawRect(0, 0, sz.width()+1, sz.height()+1); 681 p.drawRect(0, 0, sz.width()+1, sz.height()+1);
684 int mSelStartT = mSelStart; 682 int mSelStartT = mSelStart;
685 int mSelEndT = mSelEnd; 683 int mSelEndT = mSelEnd;
686 if ( mSelEndT >= NUMDAYS ) 684 if ( mSelEndT >= NUMDAYS )
687 mSelEndT = NUMDAYS-1; 685 mSelEndT = NUMDAYS-1;
688 // draw selected days with highlighted background color 686 // draw selected days with highlighted background color
689 if (mSelStart != NOSELECTION) { 687 if (mSelStart != NOSELECTION) {
690 bool skip = false; 688 bool skip = false;
691 if ( ! mouseDown ) { 689 if ( ! mouseDown ) {
692 int mo = days[20].month(); 690 int mo = days[20].month();
693 //qDebug("-- %d %d ", mSelStartT, mSelEndT); 691 //qDebug("-- %d %d ", mSelStartT, mSelEndT);
694 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); 692 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() );
695 if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) { 693 if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) {
696 skip = true; 694 skip = true;
697 } else { 695 } else {
698 if ( days[mSelStartT].month() != mo ) { 696 if ( days[mSelStartT].month() != mo ) {
699 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); 697 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day();
700 mSelStartT += add +1; 698 mSelStartT += add +1;
701 } 699 }
702 if ( days[mSelEndT].month() != mo ) { 700 if ( days[mSelEndT].month() != mo ) {
703 int sub = days[mSelEndT].day(); 701 int sub = days[mSelEndT].day();
704 mSelEndT -= sub ; 702 mSelEndT -= sub ;
705 } 703 }
706 } 704 }
707 } 705 }
708 if ( ! skip ) { 706 if ( ! skip ) {
709 row = mSelStartT/7; 707 row = mSelStartT/7;
710 col = mSelStartT -row*7; 708 col = mSelStartT -row*7;
711 QColor selcol = KOPrefs::instance()->mHighlightColor; 709 QColor selcol = KOPrefs::instance()->mHighlightColor;
712 int addCol = 0; 710 int addCol = 0;
713 int addRow = 0; 711 int addRow = 0;
714 int addRow2 = 0; 712 int addRow2 = 0;
715 int addCol2 = 0; 713 int addCol2 = 0;
716 if (row == mSelEndT/7) { 714 if (row == mSelEndT/7) {
717 if ( rowModulo ) { 715 if ( rowModulo ) {
718 if ( row >= 6 - rowModulo ) 716 if ( row >= 6 - rowModulo )
719 addRow = row - 5 + rowModulo; 717 addRow = row - 5 + rowModulo;
720 } 718 }
721 if ( colModulo ) { 719 if ( colModulo ) {
722 int colt1 = mSelEndT%7; 720 int colt1 = mSelEndT%7;
723 //qDebug("colt1 %d ", colt1 ); 721 //qDebug("colt1 %d ", colt1 );
724 if ( colt1 >= 7 - colModulo ) 722 if ( colt1 >= 7 - colModulo )
725 addCol = colt1 - 7 + colModulo+1; 723 addCol = colt1 - 7 + colModulo+1;
726 int colt = mSelStartT%7; 724 int colt = mSelStartT%7;
727 if ( colt >= 7 - colModulo ) 725 if ( colt >= 7 - colModulo )
728 addCol2 = colt - 7 + colModulo; 726 addCol2 = colt - 7 + colModulo;
729 addCol -= addCol2; 727 addCol -= addCol2;
730 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); 728 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 );
731 } 729 }
732 // Single row selection 730 // Single row selection
733 if ( row == 0) 731 if ( row == 0)
734 addRow = 1; 732 addRow = 1;
735 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, 733 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2,
736 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); 734 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol);
737 } else { 735 } else {
738 // draw first row to the right 736 // draw first row to the right
739 if ( colModulo ) { 737 if ( colModulo ) {
740 if ( col >= 7 - colModulo ) 738 if ( col >= 7 - colModulo )
741 addCol2 = col - 7 + colModulo; 739 addCol2 = col - 7 + colModulo;
742 } 740 }
743 if ( rowModulo ) { 741 if ( rowModulo ) {
744 if ( row >= 6 - rowModulo ) 742 if ( row >= 6 - rowModulo )
745 addRow = row - 5 + rowModulo; 743 addRow = row - 5 + rowModulo;
746 } 744 }
747 if ( row == 0) 745 if ( row == 0)
748 addRow = 1; 746 addRow = 1;
749 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, (7-col)*dwidth+colModulo, 747 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, (7-col)*dwidth+colModulo,
750 dheight+1, selcol); 748 dheight+1, selcol);
751 // draw full block till last line 749 // draw full block till last line
752 selh = mSelEndT/7-row; 750 selh = mSelEndT/7-row;
753 addRow = 0; 751 addRow = 0;
754 if ( rowModulo ) { 752 if ( rowModulo ) {
755 if ( mSelEndT/7 >= 6 - rowModulo ) 753 if ( mSelEndT/7 >= 6 - rowModulo )
756 addRow = mSelEndT/7 - 5 + rowModulo; 754 addRow = mSelEndT/7 - 5 + rowModulo;
757 } 755 }
758 if (selh > 1) { 756 if (selh > 1) {
759 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol); 757 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol);
760 } 758 }
761 // draw last block from left to mSelEndT 759 // draw last block from left to mSelEndT
762 selw = mSelEndT-7*(mSelEndT/7)+1; 760 selw = mSelEndT-7*(mSelEndT/7)+1;
763 //qDebug("esl %d ",selw ); 761 //qDebug("esl %d ",selw );
764 int add = 0; 762 int add = 0;
765 if ( colModulo ) { 763 if ( colModulo ) {
766 add = 7 - colModulo; 764 add = 7 - colModulo;
767 if ( selw > add ) 765 if ( selw > add )
768 add = selw - add; 766 add = selw - add;
769 else 767 else
770 add = 0; 768 add = 0;
771 } 769 }
772 //qDebug("add %d ", add); 770 //qDebug("add %d ", add);
773 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow, 771 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow,
774 selw*dwidth+add, dheight+1, selcol); 772 selw*dwidth+add, dheight+1, selcol);
775 } 773 }
776 } 774 }
777 } 775 }
778 776
779 // iterate over all days in the matrix and draw the day label in appropriate colors 777 // iterate over all days in the matrix and draw the day label in appropriate colors
780 QColor actcol = mDefaultTextColorShaded; 778 QColor actcol = mDefaultTextColorShaded;
781 p.setPen(actcol); 779 p.setPen(actcol);
782 QPen tmppen; 780 QPen tmppen;
783 for(int i = 0; i < NUMDAYS; i++) { 781 for(int i = 0; i < NUMDAYS; i++) {
784 row = i/7; 782 row = i/7;
785 col = isRTL ? 6-(i-row*7) : i-row*7; 783 col = isRTL ? 6-(i-row*7) : i-row*7;
786 784
787 // if it is the first day of a month switch color from normal to shaded and vice versa 785 // if it is the first day of a month switch color from normal to shaded and vice versa
788 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { 786 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) {
789 if (actcol == mDefaultTextColorShaded) { 787 if (actcol == mDefaultTextColorShaded) {
790 actcol = mDefaultTextColor; 788 actcol = mDefaultTextColor;
791 } else { 789 } else {
792 actcol = mDefaultTextColorShaded; 790 actcol = mDefaultTextColorShaded;
793 } 791 }
794 p.setPen(actcol); 792 p.setPen(actcol);
795 } 793 }
796 if (actcol == mDefaultTextColorShaded) { 794 if (actcol == mDefaultTextColorShaded) {
797 if ( ! mouseDown ) { 795 if ( ! mouseDown ) {
798 continue; 796 continue;
799 } 797 }
800 } 798 }
801 //Reset pen color after selected days block 799 //Reset pen color after selected days block
802 if (i == mSelEndT+1) { 800 if (i == mSelEndT+1) {
803 p.setPen(actcol); 801 p.setPen(actcol);
804 } 802 }
805 803
806 // if today then draw rectangle around day 804 // if today then draw rectangle around day
807 if (today == i) { 805 if (today == i) {
808 tmppen = p.pen(); 806 tmppen = p.pen();
809 QPen mTodayPen(p.pen()); 807 QPen mTodayPen(p.pen());
810 if ( daysize.width() < 20 ) 808 if ( daysize.width() < 20 )
811 mTodayPen.setWidth(1); 809 mTodayPen.setWidth(1);
812 else 810 else
813 mTodayPen.setWidth(mTodayMarginWidth); 811 mTodayPen.setWidth(mTodayMarginWidth);
814 //draw red rectangle for holidays 812 //draw red rectangle for holidays
815 if (!mHolidays[i].isNull()) { 813 if (!mHolidays[i].isNull()) {
816 if (actcol == mDefaultTextColor) { 814 if (actcol == mDefaultTextColor) {
817 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); 815 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor);
818 } else { 816 } else {
819 mTodayPen.setColor(mHolidayColorShaded); 817 mTodayPen.setColor(mHolidayColorShaded);
820 } 818 }
821 } 819 }
822 //draw gray rectangle for today if in selection 820 //draw gray rectangle for today if in selection
823 if (i >= mSelStartT && i <= mSelEndT) { 821 if (i >= mSelStartT && i <= mSelEndT) {
824 QColor grey("grey"); 822 QColor grey("grey");
825 mTodayPen.setColor(grey); 823 mTodayPen.setColor(grey);
826 } 824 }
827 p.setPen(mTodayPen); 825 p.setPen(mTodayPen);
828 826
829 827
830 int addCol = 0; 828 int addCol = 0;
831 int addRow = 0; 829 int addRow = 0;
832 if (rowModulo) { 830 if (rowModulo) {
833 if ( row >= 6 - rowModulo ) 831 if ( row >= 6 - rowModulo )
834 addRow = row - 5 + rowModulo; 832 addRow = row - 5 + rowModulo;
835 } 833 }
836 if ( colModulo ) { 834 if ( colModulo ) {
837 if ( col >= 7 - colModulo ) 835 if ( col >= 7 - colModulo )
838 addCol = col - 6 + colModulo-1; 836 addCol = col - 6 + colModulo-1;
839 } 837 }
840 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight+1); 838 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight+1);
841 p.setPen(tmppen); 839 p.setPen(tmppen);
842 } 840 }
843 841
844 // if any events are on that day then draw it using a bold font 842 // if any events are on that day then draw it using a bold font
845 if (events[i] > 0) { 843 if (events[i] > 0) {
846 QFont myFont = font(); 844 QFont myFont = font();
847 myFont.setBold(true); 845 myFont.setBold(true);
848 p.setFont(myFont); 846 p.setFont(myFont);
849 } 847 }
850 848
851 // if it is a holiday then use the default holiday color 849 // if it is a holiday then use the default holiday color
852 if (!mHolidays[i].isNull()) { 850 if (!mHolidays[i].isNull()) {
853 if ( bDays.testBit(i) ) { 851 if ( bDays.testBit(i) ) {
854 p.setPen(Qt::green); 852 p.setPen(Qt::green);
855 } else { 853 } else {
856 if (actcol == mDefaultTextColor) { 854 if (actcol == mDefaultTextColor) {
857 p.setPen(KOPrefs::instance()->mHolidayColor); 855 p.setPen(KOPrefs::instance()->mHolidayColor);
858 } else { 856 } else {
859 p.setPen(mHolidayColorShaded); 857 p.setPen(mHolidayColorShaded);
860 } 858 }
861 } 859 }
862 } 860 }
863 861
864 // draw selected days with special color 862 // draw selected days with special color
865 // DO NOT specially highlight holidays in selection ! 863 // DO NOT specially highlight holidays in selection !
866 if (i >= mSelStartT && i <= mSelEndT) { 864 if (i >= mSelStartT && i <= mSelEndT) {
867 ;//p.setPen(mSelectedDaysColor); 865 ;//p.setPen(mSelectedDaysColor);
868 } 866 }
869 867
870 int addCol = 0; 868 int addCol = 0;
871 int addRow = 0; 869 int addRow = 0;
872 if ( colModulo ) { 870 if ( colModulo ) {
873 if ( col >= 7 - colModulo ) 871 if ( col >= 7 - colModulo )
874 addCol = col - 7 + colModulo; 872 addCol = col - 7 + colModulo;
875 } 873 }
876 if ( rowModulo ) { 874 if ( rowModulo ) {
877 if ( row >= 6 - rowModulo ) 875 if ( row >= 6 - rowModulo )
878 addRow = row - 5 + rowModulo; 876 addRow = row - 5 + rowModulo;
879 } 877 }
880 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); 878 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow);
881 ++addCol;//++addCol; 879 ++addCol;//++addCol;
882 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, 880 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight,
883 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); 881 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]);
884 882
885 // reset color to actual color 883 // reset color to actual color
886 if (!mHolidays[i].isNull()) { 884 if (!mHolidays[i].isNull()) {
887 p.setPen(actcol); 885 p.setPen(actcol);
888 } 886 }
889 // reset bold font to plain font 887 // reset bold font to plain font
890 if (events[i] > 0) { 888 if (events[i] > 0) {
891 QFont myFont = font(); 889 QFont myFont = font();
892 myFont.setBold(false); 890 myFont.setBold(false);
893 p.setFont(myFont); 891 p.setFont(myFont);
894 } 892 }
895 } 893 }
896 int off = xyOff; 894 int off = xyOff;
897 bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP); 895 bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP);
898 //qDebug("ffffffffff %d ", off); 896 //qDebug("ffffffffff %d ", off);
899} 897}
900 898
901// ---------------------------------------------------------------------------- 899// ----------------------------------------------------------------------------
902// R E SI Z E E V E N T H A N D L I N G 900// R E SI Z E E V E N T H A N D L I N G
903// ---------------------------------------------------------------------------- 901// ----------------------------------------------------------------------------
904 902
905void KODayMatrix::resizeEvent(QResizeEvent *) 903void KODayMatrix::resizeEvent(QResizeEvent *)
906{ 904{
907 QRect sz = frameRect(); 905 QRect sz = frameRect();
908 daysize.setHeight(sz.height()*7 / NUMDAYS); 906 daysize.setHeight(sz.height()*7 / NUMDAYS);
909 daysize.setWidth(sz.width() / 7); 907 daysize.setWidth(sz.width() / 7);
910} 908}
911 909
912QSize KODayMatrix::sizeHint() const 910QSize KODayMatrix::sizeHint() const
913{ 911{
914 912
915 QFontMetrics fm ( font() ); 913 QFontMetrics fm ( font() );
916 int wid = fm.width( "30") *7+3; 914 int wid = fm.width( "30") *7+3;
917 int hei = fm.height() * 6+3; 915 int hei = fm.height() * 6+3;
918 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); 916 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei);
919 return QSize ( wid, hei ); 917 return QSize ( wid, hei );
920 918
921} 919}
diff --git a/korganizer/kotodoview.cpp b/korganizer/kotodoview.cpp
index 2b01c23..e008625 100644
--- a/korganizer/kotodoview.cpp
+++ b/korganizer/kotodoview.cpp
@@ -1,1341 +1,1341 @@
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 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qlayout.h> 24#include <qlayout.h>
25#include <qheader.h> 25#include <qheader.h>
26#include <qcursor.h> 26#include <qcursor.h>
27#include <qwhatsthis.h> 27#include <qwhatsthis.h>
28 28
29#include <qvbox.h> 29#include <qvbox.h>
30#include <kdebug.h> 30#include <kdebug.h>
31#include "koprefs.h" 31#include "koprefs.h"
32#include <klocale.h> 32#include <klocale.h>
33#include <kglobal.h> 33#include <kglobal.h>
34#include <kiconloader.h> 34#include <kiconloader.h>
35#include <kmessagebox.h> 35#include <kmessagebox.h>
36 36
37#include <libkcal/icaldrag.h> 37#include <libkcal/icaldrag.h>
38#include <libkcal/vcaldrag.h> 38#include <libkcal/vcaldrag.h>
39#include <libkcal/calfilter.h> 39#include <libkcal/calfilter.h>
40#include <libkcal/dndfactory.h> 40#include <libkcal/dndfactory.h>
41#include <libkcal/calendarresources.h> 41#include <libkcal/calendarresources.h>
42#include <libkcal/resourcecalendar.h> 42#include <libkcal/resourcecalendar.h>
43#include <kresources/resourceselectdialog.h> 43#include <kresources/resourceselectdialog.h>
44#include <libkcal/kincidenceformatter.h> 44#include <libkcal/kincidenceformatter.h>
45#ifndef DESKTOP_VERSION 45#ifndef DESKTOP_VERSION
46#include <qpe/qpeapplication.h> 46#include <qpe/qpeapplication.h>
47#else 47#else
48#include <qapplication.h> 48#include <qapplication.h>
49#endif 49#endif
50#ifndef KORG_NOPRINTER 50#ifndef KORG_NOPRINTER
51#include "calprinter.h" 51#include "calprinter.h"
52#endif 52#endif
53#include "docprefs.h" 53#include "docprefs.h"
54 54
55#include "kotodoview.h" 55#include "kotodoview.h"
56using namespace KOrg; 56using namespace KOrg;
57 57
58 58
59class KOTodoViewWhatsThis :public QWhatsThis 59class KOTodoViewWhatsThis :public QWhatsThis
60{ 60{
61public: 61public:
62 KOTodoViewWhatsThis( QWidget *wid, KOTodoView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { }; 62 KOTodoViewWhatsThis( QWidget *wid, KOTodoView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { };
63 63
64protected: 64protected:
65 virtual QString text( const QPoint& p) 65 virtual QString text( const QPoint& p)
66 { 66 {
67 return _view->getWhatsThisText(p) ; 67 return _view->getWhatsThisText(p) ;
68 } 68 }
69private: 69private:
70 QWidget* _wid; 70 QWidget* _wid;
71 KOTodoView * _view; 71 KOTodoView * _view;
72}; 72};
73 73
74KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent, 74KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent,
75 const char *name) : 75 const char *name) :
76 KListView(parent,name) 76 KListView(parent,name)
77{ 77{
78 mName = QString ( name ); 78 mName = QString ( name );
79 mCalendar = calendar; 79 mCalendar = calendar;
80#ifndef DESKTOP_VERSION 80#ifndef DESKTOP_VERSION
81 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold ); 81 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold );
82#endif 82#endif
83 mOldCurrent = 0; 83 mOldCurrent = 0;
84 mMousePressed = false; 84 mMousePressed = false;
85 85
86 setAcceptDrops(true); 86 setAcceptDrops(true);
87 viewport()->setAcceptDrops(true); 87 viewport()->setAcceptDrops(true);
88 int size = 16; 88 int size = 16;
89 if (qApp->desktop()->width() < 300 ) 89 if (qApp->desktop()->width() < 300 )
90 size = 12; 90 size = 12;
91 setTreeStepSize( size + 6 ); 91 setTreeStepSize( size + 6 );
92 92
93} 93}
94 94
95void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e) 95void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e)
96{ 96{
97#ifndef KORG_NODND 97#ifndef KORG_NODND
98// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl; 98// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl;
99 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 99 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
100 !QTextDrag::canDecode( e ) ) { 100 !QTextDrag::canDecode( e ) ) {
101 e->ignore(); 101 e->ignore();
102 return; 102 return;
103 } 103 }
104 104
105 mOldCurrent = currentItem(); 105 mOldCurrent = currentItem();
106#endif 106#endif
107} 107}
108 108
109 109
110void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e) 110void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e)
111{ 111{
112#ifndef KORG_NODND 112#ifndef KORG_NODND
113// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl; 113// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl;
114 114
115 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 115 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
116 !QTextDrag::canDecode( e ) ) { 116 !QTextDrag::canDecode( e ) ) {
117 e->ignore(); 117 e->ignore();
118 return; 118 return;
119 } 119 }
120 120
121 e->accept(); 121 e->accept();
122#endif 122#endif
123} 123}
124 124
125void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *) 125void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *)
126{ 126{
127#ifndef KORG_NODND 127#ifndef KORG_NODND
128// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl; 128// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl;
129 129
130 setCurrentItem(mOldCurrent); 130 setCurrentItem(mOldCurrent);
131 setSelected(mOldCurrent,true); 131 setSelected(mOldCurrent,true);
132#endif 132#endif
133} 133}
134 134
135void KOTodoListView::contentsDropEvent(QDropEvent *e) 135void KOTodoListView::contentsDropEvent(QDropEvent *e)
136{ 136{
137#ifndef KORG_NODND 137#ifndef KORG_NODND
138// kdDebug() << "KOTodoListView::contentsDropEvent" << endl; 138// kdDebug() << "KOTodoListView::contentsDropEvent" << endl;
139 139
140 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 140 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
141 !QTextDrag::canDecode( e ) ) { 141 !QTextDrag::canDecode( e ) ) {
142 e->ignore(); 142 e->ignore();
143 return; 143 return;
144 } 144 }
145 145
146 DndFactory factory( mCalendar ); 146 DndFactory factory( mCalendar );
147 Todo *todo = factory.createDropTodo(e); 147 Todo *todo = factory.createDropTodo(e);
148 148
149 if (todo) { 149 if (todo) {
150 e->acceptAction(); 150 e->acceptAction();
151 151
152 KOTodoViewItem *destination = 152 KOTodoViewItem *destination =
153 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos())); 153 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos()));
154 Todo *destinationEvent = 0; 154 Todo *destinationEvent = 0;
155 if (destination) destinationEvent = destination->todo(); 155 if (destination) destinationEvent = destination->todo();
156 156
157 Todo *existingTodo = mCalendar->todo(todo->uid()); 157 Todo *existingTodo = mCalendar->todo(todo->uid());
158 158
159 if(existingTodo) { 159 if(existingTodo) {
160 Incidence *to = destinationEvent; 160 Incidence *to = destinationEvent;
161 while(to) { 161 while(to) {
162 if (to->uid() == todo->uid()) { 162 if (to->uid() == todo->uid()) {
163 KMessageBox::sorry(this, 163 KMessageBox::sorry(this,
164 i18n("Cannot move To-Do to itself\nor a child of itself"), 164 i18n("Cannot move To-Do to itself\nor a child of itself"),
165 i18n("Drop To-Do")); 165 i18n("Drop To-Do"));
166 delete todo; 166 delete todo;
167 return; 167 return;
168 } 168 }
169 to = to->relatedTo(); 169 to = to->relatedTo();
170 } 170 }
171 internalDrop = true; 171 internalDrop = true;
172 if ( destinationEvent ) 172 if ( destinationEvent )
173 reparentTodoSignal( destinationEvent, existingTodo ); 173 reparentTodoSignal( destinationEvent, existingTodo );
174 else 174 else
175 unparentTodoSignal(existingTodo); 175 unparentTodoSignal(existingTodo);
176 delete todo; 176 delete todo;
177 } else { 177 } else {
178 mCalendar->addTodo(todo); 178 mCalendar->addTodo(todo);
179 emit todoDropped(todo, KOGlobals::EVENTADDED); 179 emit todoDropped(todo, KOGlobals::EVENTADDED);
180 if ( destinationEvent ) 180 if ( destinationEvent )
181 reparentTodoSignal( destinationEvent, todo ); 181 reparentTodoSignal( destinationEvent, todo );
182 } 182 }
183 } 183 }
184 else { 184 else {
185 QString text; 185 QString text;
186 if (QTextDrag::decode(e,text)) { 186 if (QTextDrag::decode(e,text)) {
187 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) ); 187 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) );
188 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) )); 188 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) ));
189 qDebug("Dropped : " + text); 189 qDebug("Dropped : " + text);
190 QStringList emails = QStringList::split(",",text); 190 QStringList emails = QStringList::split(",",text);
191 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { 191 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
192 int pos = (*it).find("<"); 192 int pos = (*it).find("<");
193 QString name = (*it).left(pos); 193 QString name = (*it).left(pos);
194 QString email = (*it).mid(pos); 194 QString email = (*it).mid(pos);
195 if (!email.isEmpty() && todoi) { 195 if (!email.isEmpty() && todoi) {
196 todoi->todo()->addAttendee(new Attendee(name,email)); 196 todoi->todo()->addAttendee(new Attendee(name,email));
197 } 197 }
198 } 198 }
199 } 199 }
200 else { 200 else {
201 qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable "); 201 qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable ");
202 e->ignore(); 202 e->ignore();
203 } 203 }
204 } 204 }
205#endif 205#endif
206} 206}
207 207
208void KOTodoListView::contentsMousePressEvent(QMouseEvent* e) 208void KOTodoListView::contentsMousePressEvent(QMouseEvent* e)
209{ 209{
210#ifndef KORG_NODND 210#ifndef KORG_NODND
211 QPoint p(contentsToViewport(e->pos())); 211 QPoint p(contentsToViewport(e->pos()));
212 QListViewItem *i = itemAt(p); 212 QListViewItem *i = itemAt(p);
213 mMousePressed = false; 213 mMousePressed = false;
214 if (i) { 214 if (i) {
215 // if the user clicked into the root decoration of the item, don't 215 // if the user clicked into the root decoration of the item, don't
216 // try to start a drag! 216 // try to start a drag!
217 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) + 217 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) +
218 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) + 218 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) +
219 itemMargin() || 219 itemMargin() ||
220 p.x() < header()->sectionPos(header()->mapToIndex(0))) { 220 p.x() < header()->sectionPos(header()->mapToIndex(0))) {
221 if (e->button()==Qt::LeftButton) { 221 if (e->button()==Qt::LeftButton) {
222 mPressPos = e->pos(); 222 mPressPos = e->pos();
223 mMousePressed = true; 223 mMousePressed = true;
224 } 224 }
225 } 225 }
226 } 226 }
227#endif 227#endif
228 QListView::contentsMousePressEvent(e); 228 QListView::contentsMousePressEvent(e);
229} 229}
230void KOTodoListView::paintEvent(QPaintEvent* e) 230void KOTodoListView::paintEvent(QPaintEvent* e)
231{ 231{
232 emit paintNeeded(); 232 emit paintNeeded();
233 QListView::paintEvent( e); 233 QListView::paintEvent( e);
234} 234}
235void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e) 235void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e)
236{ 236{
237 237
238#ifndef KORG_NODND 238#ifndef KORG_NODND
239 //QListView::contentsMouseMoveEvent(e); 239 //QListView::contentsMouseMoveEvent(e);
240 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() > 240 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() >
241 QApplication::startDragDistance()*3) { 241 QApplication::startDragDistance()*3) {
242 mMousePressed = false; 242 mMousePressed = false;
243 QListViewItem *item = itemAt(contentsToViewport(mPressPos)); 243 QListViewItem *item = itemAt(contentsToViewport(mPressPos));
244 if (item) { 244 if (item) {
245 DndFactory factory( mCalendar ); 245 DndFactory factory( mCalendar );
246 ICalDrag *vd = factory.createDrag( 246 ICalDrag *vd = factory.createDrag(
247 ((KOTodoViewItem *)item)->todo(),viewport()); 247 ((KOTodoViewItem *)item)->todo(),viewport());
248 internalDrop = false; 248 internalDrop = false;
249 // we cannot do any senseful here, because the DnD is still broken in Qt 249 // we cannot do any senseful here, because the DnD is still broken in Qt
250 if (vd->drag()) { 250 if (vd->drag()) {
251 if ( !internalDrop ) { 251 if ( !internalDrop ) {
252 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() ); 252 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() );
253 qDebug("Dnd: External move: Delete drag source "); 253 qDebug("Dnd: External move: Delete drag source ");
254 } else 254 } else
255 qDebug("Dnd: Internal move "); 255 qDebug("Dnd: Internal move ");
256 256
257 } else { 257 } else {
258 if ( !internalDrop ) { 258 if ( !internalDrop ) {
259 qDebug("Dnd: External Copy"); 259 qDebug("Dnd: External Copy");
260 } else 260 } else
261 qDebug("DnD: Internal copy: Copy pending"); 261 qDebug("DnD: Internal copy: Copy pending");
262 } 262 }
263 } 263 }
264 } 264 }
265#endif 265#endif
266} 266}
267void KOTodoListView::keyPressEvent ( QKeyEvent * e ) 267void KOTodoListView::keyPressEvent ( QKeyEvent * e )
268{ 268{
269 269
270 QListViewItem* cn; 270 QListViewItem* cn;
271 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) { 271 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) {
272 cn = currentItem(); 272 cn = currentItem();
273 if ( cn ) { 273 if ( cn ) {
274 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 274 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
275 if ( ci ){ 275 if ( ci ){
276 if ( e->state() == ShiftButton ) 276 if ( e->state() == ShiftButton )
277 ci->setOn( false ); 277 ci->setOn( false );
278 else 278 else
279 ci->setOn( true ); 279 ci->setOn( true );
280 cn = cn->itemBelow(); 280 cn = cn->itemBelow();
281 if ( cn ) { 281 if ( cn ) {
282 setCurrentItem ( cn ); 282 setCurrentItem ( cn );
283 ensureItemVisible ( cn ); 283 ensureItemVisible ( cn );
284 } 284 }
285 285
286 } 286 }
287 } 287 }
288 288
289 return; 289 return;
290 } 290 }
291 291
292 // qDebug("KOTodoListView::keyPressEvent "); 292 // qDebug("KOTodoListView::keyPressEvent ");
293 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) { 293 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) {
294 switch ( e->key() ) { 294 switch ( e->key() ) {
295 case Qt::Key_Down: 295 case Qt::Key_Down:
296 case Qt::Key_Up: 296 case Qt::Key_Up:
297 QListView::keyPressEvent ( e ); 297 QListView::keyPressEvent ( e );
298 break; 298 break;
299 case Qt::Key_Left: 299 case Qt::Key_Left:
300 case Qt::Key_Right: 300 case Qt::Key_Right:
301 QListView::keyPressEvent ( e ); 301 QListView::keyPressEvent ( e );
302 e->accept(); 302 e->accept();
303 return; 303 return;
304 break; 304 break;
305 default: 305 default:
306 e->ignore(); 306 e->ignore();
307 break; 307 break;
308 } 308 }
309 return; 309 return;
310 } 310 }
311 e->ignore(); 311 e->ignore();
312} 312}
313void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e) 313void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e)
314{ 314{
315 QListView::contentsMouseReleaseEvent(e); 315 QListView::contentsMouseReleaseEvent(e);
316 mMousePressed = false; 316 mMousePressed = false;
317} 317}
318 318
319void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e) 319void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e)
320{ 320{
321 if (!e) return; 321 if (!e) return;
322 322
323 QPoint vp = contentsToViewport(e->pos()); 323 QPoint vp = contentsToViewport(e->pos());
324 324
325 QListViewItem *item = itemAt(vp); 325 QListViewItem *item = itemAt(vp);
326 326
327 emit double_Clicked(item); 327 emit double_Clicked(item);
328 if (!item) return; 328 if (!item) return;
329 329
330 emit doubleClicked(item,vp,0); 330 emit doubleClicked(item,vp,0);
331} 331}
332 332
333///////////////////////////////////////////////////////////////////////////// 333/////////////////////////////////////////////////////////////////////////////
334 334
335KOQuickTodo::KOQuickTodo(QWidget *parent) : 335KOQuickTodo::KOQuickTodo(QWidget *parent) :
336 QLineEdit(parent) 336 QLineEdit(parent)
337{ 337{
338 setText(i18n("Click to add a new Todo")); 338 setText(i18n("Click to add a new Todo"));
339} 339}
340 340
341void KOQuickTodo::focusInEvent(QFocusEvent *ev) 341void KOQuickTodo::focusInEvent(QFocusEvent *ev)
342{ 342{
343 if ( text()==i18n("Click to add a new Todo") ) 343 if ( text()==i18n("Click to add a new Todo") )
344 setText(""); 344 setText("");
345 QLineEdit::focusInEvent(ev); 345 QLineEdit::focusInEvent(ev);
346} 346}
347 347
348void KOQuickTodo::focusOutEvent(QFocusEvent *ev) 348void KOQuickTodo::focusOutEvent(QFocusEvent *ev)
349{ 349{
350 setText(i18n("Click to add a new Todo")); 350 setText(i18n("Click to add a new Todo"));
351 QLineEdit::focusOutEvent(ev); 351 QLineEdit::focusOutEvent(ev);
352} 352}
353 353
354///////////////////////////////////////////////////////////////////////////// 354/////////////////////////////////////////////////////////////////////////////
355 355
356KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) : 356KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) :
357 KOrg::BaseView(calendar,parent,name) 357 KOrg::BaseView(calendar,parent,name)
358{ 358{
359 mPendingUpdateBeforeRepaint = false; 359 mPendingUpdateBeforeRepaint = false;
360 isFlatDisplay = false; 360 isFlatDisplay = false;
361 mNavigator = 0; 361 mNavigator = 0;
362 QBoxLayout *topLayout = new QVBoxLayout(this); 362 QBoxLayout *topLayout = new QVBoxLayout(this);
363 mName = QString ( name ); 363 mName = QString ( name );
364 mBlockUpdate = false; 364 mBlockUpdate = false;
365 mQuickAdd = new KOQuickTodo(this); 365 mQuickAdd = new KOQuickTodo(this);
366 topLayout->addWidget(mQuickAdd); 366 topLayout->addWidget(mQuickAdd);
367 367
368 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide(); 368 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide();
369 369
370 mTodoListView = new KOTodoListView(calendar,this, name ); 370 mTodoListView = new KOTodoListView(calendar,this, name );
371 topLayout->addWidget(mTodoListView); 371 topLayout->addWidget(mTodoListView);
372 //mTodoListView->header()->setMaximumHeight(30); 372 //mTodoListView->header()->setMaximumHeight(30);
373 mTodoListView->setRootIsDecorated(true); 373 mTodoListView->setRootIsDecorated(true);
374 mTodoListView->setAllColumnsShowFocus(true); 374 mTodoListView->setAllColumnsShowFocus(true);
375 375
376 mTodoListView->setShowSortIndicator(true); 376 mTodoListView->setShowSortIndicator(true);
377 377
378 mTodoListView->addColumn(i18n("Todo")); 378 mTodoListView->addColumn(i18n("Todo"));
379 mTodoListView->addColumn(i18n("Prio")); 379 mTodoListView->addColumn(i18n("Prio"));
380 mTodoListView->setColumnAlignment(1,AlignHCenter); 380 mTodoListView->setColumnAlignment(1,AlignHCenter);
381 mTodoListView->addColumn(i18n("Complete")); 381 mTodoListView->addColumn(i18n("Complete"));
382 mTodoListView->setColumnAlignment(2,AlignCenter); 382 mTodoListView->setColumnAlignment(2,AlignCenter);
383 383
384 mTodoListView->addColumn(i18n("Due Date")); 384 mTodoListView->addColumn(i18n("Due Date"));
385 mTodoListView->setColumnAlignment(3,AlignLeft); 385 mTodoListView->setColumnAlignment(3,AlignLeft);
386 mTodoListView->addColumn(i18n("Due Time")); 386 mTodoListView->addColumn(i18n("Due Time"));
387 mTodoListView->setColumnAlignment(4,AlignHCenter); 387 mTodoListView->setColumnAlignment(4,AlignHCenter);
388 388
389 mTodoListView->addColumn(i18n("Start Date")); 389 mTodoListView->addColumn(i18n("Start Date"));
390 mTodoListView->setColumnAlignment(5,AlignLeft); 390 mTodoListView->setColumnAlignment(5,AlignLeft);
391 mTodoListView->addColumn(i18n("Start Time")); 391 mTodoListView->addColumn(i18n("Start Time"));
392 mTodoListView->setColumnAlignment(6,AlignHCenter); 392 mTodoListView->setColumnAlignment(6,AlignHCenter);
393 393
394 mTodoListView->addColumn(i18n("Cancelled")); 394 mTodoListView->addColumn(i18n("Cancelled"));
395 mTodoListView->addColumn(i18n("Categories")); 395 mTodoListView->addColumn(i18n("Categories"));
396#if 0 396#if 0
397 mTodoListView->addColumn(i18n("Sort Id")); 397 mTodoListView->addColumn(i18n("Sort Id"));
398 mTodoListView->setColumnAlignment(4,AlignHCenter); 398 mTodoListView->setColumnAlignment(4,AlignHCenter);
399#endif 399#endif
400 400
401 mTodoListView->setMinimumHeight( 60 ); 401 mTodoListView->setMinimumHeight( 60 );
402 mTodoListView->setItemsRenameable( true ); 402 mTodoListView->setItemsRenameable( true );
403 mTodoListView->setRenameable( 0 ); 403 mTodoListView->setRenameable( 0 );
404 mTodoListView->setColumnWidth( 0, 120 ); 404 mTodoListView->setColumnWidth( 0, 120 );
405 mTodoListView->setColumnWidthMode(0, QListView::Manual); 405 mTodoListView->setColumnWidthMode(0, QListView::Manual);
406 mTodoListView->setColumnWidthMode(1, QListView::Manual); 406 mTodoListView->setColumnWidthMode(1, QListView::Manual);
407 mTodoListView->setColumnWidthMode(2, QListView::Manual); 407 mTodoListView->setColumnWidthMode(2, QListView::Manual);
408 mTodoListView->setColumnWidthMode(3, QListView::Manual); 408 mTodoListView->setColumnWidthMode(3, QListView::Manual);
409 mTodoListView->setColumnWidthMode(4, QListView::Manual); 409 mTodoListView->setColumnWidthMode(4, QListView::Manual);
410 mTodoListView->setColumnWidthMode(5, QListView::Manual); 410 mTodoListView->setColumnWidthMode(5, QListView::Manual);
411 mTodoListView->setColumnWidthMode(6, QListView::Manual); 411 mTodoListView->setColumnWidthMode(6, QListView::Manual);
412 mTodoListView->setColumnWidthMode(7, QListView::Manual); 412 mTodoListView->setColumnWidthMode(7, QListView::Manual);
413 mTodoListView->setColumnWidthMode(8, QListView::Manual); 413 mTodoListView->setColumnWidthMode(8, QListView::Manual);
414 414
415 415
416 mKOTodoViewWhatsThis = new KOTodoViewWhatsThis(mTodoListView->viewport(),this); 416 mKOTodoViewWhatsThis = new KOTodoViewWhatsThis(mTodoListView->viewport(),this);
417 417
418 mPriorityPopupMenu = new QPopupMenu(this); 418 mPriorityPopupMenu = new QPopupMenu(this);
419 for (int i = 1; i <= 5; i++) { 419 for (int i = 1; i <= 5; i++) {
420 QString label = QString ("%1").arg (i); 420 QString label = QString ("%1").arg (i);
421 mPriority[mPriorityPopupMenu->insertItem (label)] = i; 421 mPriority[mPriorityPopupMenu->insertItem (label)] = i;
422 } 422 }
423 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int))); 423 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int)));
424 424
425 mPercentageCompletedPopupMenu = new QPopupMenu(this); 425 mPercentageCompletedPopupMenu = new QPopupMenu(this);
426 for (int i = 0; i <= 100; i+=20) { 426 for (int i = 0; i <= 100; i+=20) {
427 QString label = QString ("%1 %").arg (i); 427 QString label = QString ("%1 %").arg (i);
428 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i; 428 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i;
429 } 429 }
430 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int))); 430 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int)));
431 431
432 432
433 433
434 mItemPopupMenu = new QPopupMenu(this); 434 mItemPopupMenu = new QPopupMenu(this);
435 mItemPopupMenu->insertItem(i18n("Show..."), this, 435 mItemPopupMenu->insertItem(i18n("Show..."), this,
436 SLOT (showTodo())); 436 SLOT (showTodo()));
437 mItemPopupMenu->insertItem(i18n("Edit..."), this, 437 mItemPopupMenu->insertItem(i18n("Edit..."), this,
438 SLOT (editTodo())); 438 SLOT (editTodo()));
439 mItemPopupMenu->insertItem( i18n("Delete"), this, 439 mItemPopupMenu->insertItem( i18n("Delete"), this,
440 SLOT (deleteTodo())); 440 SLOT (deleteTodo()));
441 mItemPopupMenu->insertItem( i18n("Clone..."), this, 441 mItemPopupMenu->insertItem( i18n("Clone..."), this,
442 SLOT (cloneTodo())); 442 SLOT (cloneTodo()));
443 mItemPopupMenu->insertItem( i18n("Move..."), this, 443 mItemPopupMenu->insertItem( i18n("Move..."), this,
444 SLOT (moveTodo())); 444 SLOT (moveTodo()));
445 mItemPopupMenu->insertItem( i18n("Beam..."), this, 445 mItemPopupMenu->insertItem( i18n("Beam..."), this,
446 SLOT (beamTodo())); 446 SLOT (beamTodo()));
447 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this, 447 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this,
448 SLOT (cancelTodo())); 448 SLOT (cancelTodo()));
449 mItemPopupMenu->insertSeparator(); 449 mItemPopupMenu->insertSeparator();
450 450
451 mItemPopupMenu->insertItem( i18n("New Todo..."), this, 451 mItemPopupMenu->insertItem( i18n("New Todo..."), this,
452 SLOT (newTodo())); 452 SLOT (newTodo()));
453 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this, 453 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this,
454 SLOT (newSubTodo())); 454 SLOT (newSubTodo()));
455 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this, 455 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this,
456 SLOT (unparentTodo()),0,21); 456 SLOT (unparentTodo()),0,21);
457 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this, 457 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this,
458 SLOT (reparentTodo()),0,22); 458 SLOT (reparentTodo()),0,22);
459 mItemPopupMenu->insertSeparator(); 459 mItemPopupMenu->insertSeparator();
460#if 0 460#if 0
461 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"), 461 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"),
462 this, SLOT( purgeCompleted() ) ); 462 this, SLOT( purgeCompleted() ) );
463 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"), 463 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"),
464 this, SLOT( toggleCompleted() ),0, 33 ); 464 this, SLOT( toggleCompleted() ),0, 33 );
465 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 465 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
466 this, SLOT( toggleQuickTodo() ),0, 34 ); 466 this, SLOT( toggleQuickTodo() ),0, 34 );
467 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 467 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
468 this, SLOT( toggleRunning() ),0, 35 ); 468 this, SLOT( toggleRunning() ),0, 35 );
469 469
470#endif 470#endif
471 mPopupMenu = new QPopupMenu(this); 471 mPopupMenu = new QPopupMenu(this);
472 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this, 472 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this,
473 SLOT (newTodo()),0,1); 473 SLOT (newTodo()),0,1);
474 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"), 474 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"),
475 this, SLOT(purgeCompleted()),0,2); 475 this, SLOT(purgeCompleted()),0,2);
476 mPopupMenu->insertItem(i18n("Show Completed"), 476 mPopupMenu->insertItem(i18n("Show Completed"),
477 this, SLOT( toggleCompleted() ),0,3 ); 477 this, SLOT( toggleCompleted() ),0,3 );
478 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 478 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
479 this, SLOT( toggleQuickTodo() ),0,4 ); 479 this, SLOT( toggleQuickTodo() ),0,4 );
480 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 480 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
481 this, SLOT( toggleRunning() ),0,5 ); 481 this, SLOT( toggleRunning() ),0,5 );
482 mPopupMenu->insertItem(i18n(" set all open","Display all opened"), 482 mPopupMenu->insertItem(i18n(" set all open","Display all opened"),
483 this, SLOT( setAllOpen() ),0,6 ); 483 this, SLOT( setAllOpen() ),0,6 );
484 mPopupMenu->insertItem(i18n(" set all close","Display all closed"), 484 mPopupMenu->insertItem(i18n(" set all close","Display all closed"),
485 this, SLOT( setAllClose() ),0,7 ); 485 this, SLOT( setAllClose() ),0,7 );
486 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"), 486 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"),
487 this, SLOT( setAllFlat() ),0,8 ); 487 this, SLOT( setAllFlat() ),0,8 );
488 mDocPrefs = new DocPrefs( name ); 488 mDocPrefs = new DocPrefs( name );
489 489
490 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu ); 490 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu );
491 mPopupMenu->setCheckable( true ); 491 mPopupMenu->setCheckable( true );
492 mItemPopupMenu->setCheckable( true ); 492 mItemPopupMenu->setCheckable( true );
493 493
494 494
495 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 495 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
496 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 496 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
497 497
498 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 498 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
499 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 499 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
500 500
501 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 501 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
502 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 502 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
503 503
504 504
505 // Double clicking conflicts with opening/closing the subtree 505 // Double clicking conflicts with opening/closing the subtree
506 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ), 506 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ),
507 SLOT( editItem( QListViewItem *) ) ); 507 SLOT( editItem( QListViewItem *) ) );
508 /* 508 /*
509 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *, 509 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *,
510 const QPoint &,int ) ), 510 const QPoint &,int ) ),
511 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 511 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
512 */ 512 */
513 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *, 513 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *,
514 const QPoint &,int ) ), 514 const QPoint &,int ) ),
515 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 515 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
516 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ), 516 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ),
517 SLOT( itemClicked( QListViewItem * ) ) ); 517 SLOT( itemClicked( QListViewItem * ) ) );
518 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ), 518 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ),
519 SLOT( itemDoubleClicked( QListViewItem * ) ) ); 519 SLOT( itemDoubleClicked( QListViewItem * ) ) );
520 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 520 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
521 SLOT( updateView() ) ); 521 SLOT( updateView() ) );
522 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 522 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
523 SLOT( todoModified(Todo *, int) ) ); 523 SLOT( todoModified(Todo *, int) ) );
524 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ), 524 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ),
525 SLOT( itemStateChanged( QListViewItem * ) ) ); 525 SLOT( itemStateChanged( QListViewItem * ) ) );
526 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ), 526 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ),
527 SLOT( itemStateChanged( QListViewItem * ) ) ); 527 SLOT( itemStateChanged( QListViewItem * ) ) );
528 connect( mTodoListView, SIGNAL( paintNeeded() ), 528 connect( mTodoListView, SIGNAL( paintNeeded() ),
529 SLOT( paintNeeded()) ); 529 SLOT( paintNeeded()) );
530 530
531#if 0 531#if 0
532 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)), 532 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)),
533 SLOT(selectionChanged(QListViewItem *))); 533 SLOT(selectionChanged(QListViewItem *)));
534 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)), 534 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)),
535 SLOT(selectionChanged(QListViewItem *))); 535 SLOT(selectionChanged(QListViewItem *)));
536 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)), 536 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)),
537 SLOT(selectionChanged(QListViewItem *))); 537 SLOT(selectionChanged(QListViewItem *)));
538#endif 538#endif
539 539
540 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) )); 540 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) ));
541 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) )); 541 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) ));
542 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) )); 542 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) ));
543 543
544 connect( mTodoListView, SIGNAL(selectionChanged() ), 544 connect( mTodoListView, SIGNAL(selectionChanged() ),
545 SLOT( processSelectionChange() ) ); 545 SLOT( processSelectionChange() ) );
546 connect( mQuickAdd, SIGNAL( returnPressed () ), 546 connect( mQuickAdd, SIGNAL( returnPressed () ),
547 SLOT( addQuickTodo() ) ); 547 SLOT( addQuickTodo() ) );
548 548
549} 549}
550 550
551KOTodoView::~KOTodoView() 551KOTodoView::~KOTodoView()
552{ 552{
553 delete mKOTodoViewWhatsThis; 553 // delete mKOTodoViewWhatsThis;
554 delete mDocPrefs; 554 delete mDocPrefs;
555} 555}
556QString KOTodoView::getWhatsThisText(QPoint p) 556QString KOTodoView::getWhatsThisText(QPoint p)
557{ 557{
558 KOTodoViewItem* item = ( KOTodoViewItem* ) mTodoListView->itemAt( p ); 558 KOTodoViewItem* item = ( KOTodoViewItem* ) mTodoListView->itemAt( p );
559 if ( item ) 559 if ( item )
560 return KIncidenceFormatter::instance()->getFormattedText( item->todo(), 560 return KIncidenceFormatter::instance()->getFormattedText( item->todo(),
561 KOPrefs::instance()->mWTshowDetails, 561 KOPrefs::instance()->mWTshowDetails,
562 KOPrefs::instance()->mWTshowCreated, 562 KOPrefs::instance()->mWTshowCreated,
563 KOPrefs::instance()->mWTshowChanged); 563 KOPrefs::instance()->mWTshowChanged);
564 return i18n("That is the todo view" ); 564 return i18n("That is the todo view" );
565 565
566} 566}
567 567
568void KOTodoView::jumpToDate () 568void KOTodoView::jumpToDate ()
569{ 569{
570 // if (mActiveItem) { 570 // if (mActiveItem) {
571// mActiveItem->todo()); 571// mActiveItem->todo());
572// if ( mActiveItem->todo()->hasDueDate() ) 572// if ( mActiveItem->todo()->hasDueDate() )
573// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() ); 573// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() );
574} 574}
575void KOTodoView::paintNeeded() 575void KOTodoView::paintNeeded()
576{ 576{
577 if ( mPendingUpdateBeforeRepaint ) { 577 if ( mPendingUpdateBeforeRepaint ) {
578 updateView(); 578 updateView();
579 mPendingUpdateBeforeRepaint = false; 579 mPendingUpdateBeforeRepaint = false;
580 } 580 }
581} 581}
582void KOTodoView::paintEvent(QPaintEvent * pevent) 582void KOTodoView::paintEvent(QPaintEvent * pevent)
583{ 583{
584 if ( mPendingUpdateBeforeRepaint ) { 584 if ( mPendingUpdateBeforeRepaint ) {
585 updateView(); 585 updateView();
586 mPendingUpdateBeforeRepaint = false; 586 mPendingUpdateBeforeRepaint = false;
587 } 587 }
588 KOrg::BaseView::paintEvent( pevent); 588 KOrg::BaseView::paintEvent( pevent);
589} 589}
590 590
591void KOTodoView::updateView() 591void KOTodoView::updateView()
592{ 592{
593 pendingSubtodo = 0; 593 pendingSubtodo = 0;
594 if ( mBlockUpdate ) { 594 if ( mBlockUpdate ) {
595 return; 595 return;
596 } 596 }
597 if ( !isVisible() ) { 597 if ( !isVisible() ) {
598 mPendingUpdateBeforeRepaint = true; 598 mPendingUpdateBeforeRepaint = true;
599 return; 599 return;
600 } 600 }
601 //qDebug("KOTodoView::updateView() %x", this); 601 //qDebug("KOTodoView::updateView() %x", this);
602 if ( isFlatDisplay ) { 602 if ( isFlatDisplay ) {
603 displayAllFlat(); 603 displayAllFlat();
604 return; 604 return;
605 } 605 }
606 //qDebug("update "); 606 //qDebug("update ");
607// kdDebug() << "KOTodoView::updateView()" << endl; 607// kdDebug() << "KOTodoView::updateView()" << endl;
608 QFont fo = KOPrefs::instance()->mTodoViewFont; 608 QFont fo = KOPrefs::instance()->mTodoViewFont;
609 Incidence* oldInc = 0; 609 Incidence* oldInc = 0;
610 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 610 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
611 if (mActiveItem) 611 if (mActiveItem)
612 oldInc = mActiveItem->todo(); 612 oldInc = mActiveItem->todo();
613 613
614 mTodoListView->clear(); 614 mTodoListView->clear();
615 if ( mName == "todolistsmall" ) { 615 if ( mName == "todolistsmall" ) {
616 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) { 616 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) {
617 int ps = fo.pointSize() -2; 617 int ps = fo.pointSize() -2;
618 if ( ps > 12 ) 618 if ( ps > 12 )
619 ps -= 2; 619 ps -= 2;
620 fo.setPointSize( ps ); 620 fo.setPointSize( ps );
621 } 621 }
622 } 622 }
623 623
624 mTodoListView->setFont( fo ); 624 mTodoListView->setFont( fo );
625 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont ); 625 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont );
626 //mTodoListView->header()->setMaximumHeight(fm.height()); 626 //mTodoListView->header()->setMaximumHeight(fm.height());
627 QPtrList<Todo> todoList = calendar()->todos(); 627 QPtrList<Todo> todoList = calendar()->todos();
628 628
629/* 629/*
630 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl; 630 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl;
631 Event *t; 631 Event *t;
632 for(t = todoList.first(); t; t = todoList.next()) { 632 for(t = todoList.first(); t; t = todoList.next()) {
633 kdDebug() << " " << t->getSummary() << endl; 633 kdDebug() << " " << t->getSummary() << endl;
634 634
635 if (t->getRelatedTo()) { 635 if (t->getRelatedTo()) {
636 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl; 636 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl;
637 } 637 }
638 638
639 QPtrList<Event> l = t->getRelations(); 639 QPtrList<Event> l = t->getRelations();
640 Event *c; 640 Event *c;
641 for(c=l.first();c;c=l.next()) { 641 for(c=l.first();c;c=l.next()) {
642 kdDebug() << " - relation: " << c->getSummary() << endl; 642 kdDebug() << " - relation: " << c->getSummary() << endl;
643 } 643 }
644 } 644 }
645*/ 645*/
646 646
647 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a 647 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a
648 // specific order of events. That means that we have to generate parent items 648 // specific order of events. That means that we have to generate parent items
649 // recursively for proper hierarchical display of Todos. 649 // recursively for proper hierarchical display of Todos.
650 mTodoMap.clear(); 650 mTodoMap.clear();
651 Todo *todo; 651 Todo *todo;
652 todo = todoList.first();// todo; todo = todoList.next()) { 652 todo = todoList.first();// todo; todo = todoList.next()) {
653 while ( todo ) { 653 while ( todo ) {
654 bool next = true; 654 bool next = true;
655 // qDebug("todo %s ", todo->summary().latin1()); 655 // qDebug("todo %s ", todo->summary().latin1());
656 Incidence *incidence = todo->relatedTo(); 656 Incidence *incidence = todo->relatedTo();
657 while ( incidence ) { 657 while ( incidence ) {
658 if ( incidence->type() == "Todo") { 658 if ( incidence->type() == "Todo") {
659 //qDebug("related %s ",incidence->summary().latin1() ); 659 //qDebug("related %s ",incidence->summary().latin1() );
660 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) { 660 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) {
661 //qDebug("related not found "); 661 //qDebug("related not found ");
662 todoList.remove( ); 662 todoList.remove( );
663 todo = todoList.current(); 663 todo = todoList.current();
664 next = false; 664 next = false;
665 incidence = 0; 665 incidence = 0;
666 666
667 } else { 667 } else {
668 //qDebug("related found "); 668 //qDebug("related found ");
669 incidence = incidence->relatedTo(); 669 incidence = incidence->relatedTo();
670 } 670 }
671 } else 671 } else
672 incidence = 0; 672 incidence = 0;
673 } 673 }
674 if ( next ) 674 if ( next )
675 todo = todoList.next(); 675 todo = todoList.next();
676 } 676 }
677// qDebug("again .... "); 677// qDebug("again .... ");
678// for(todo = todoList.first(); todo; todo = todoList.next()) { 678// for(todo = todoList.first(); todo; todo = todoList.next()) {
679 679
680// qDebug("yytodo %s ", todo->summary().latin1()); 680// qDebug("yytodo %s ", todo->summary().latin1());
681// } 681// }
682 //qDebug("for "); 682 //qDebug("for ");
683 for(todo = todoList.first(); todo; todo = todoList.next()) { 683 for(todo = todoList.first(); todo; todo = todoList.next()) {
684 if (!mTodoMap.contains(todo) && checkTodo( todo ) ) 684 if (!mTodoMap.contains(todo) && checkTodo( todo ) )
685 { 685 {
686 insertTodoItem(todo); 686 insertTodoItem(todo);
687 } 687 }
688 } 688 }
689 //qDebug("for end "); 689 //qDebug("for end ");
690 // Restore opened/closed state 690 // Restore opened/closed state
691 mTodoListView->blockSignals( true ); 691 mTodoListView->blockSignals( true );
692 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() ); 692 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() );
693 mTodoListView->blockSignals( false ); 693 mTodoListView->blockSignals( false );
694 mTodoListView->setFocus(); 694 mTodoListView->setFocus();
695 if ( mTodoListView->firstChild () ) { 695 if ( mTodoListView->firstChild () ) {
696 if ( oldInc ) { 696 if ( oldInc ) {
697 KOTodoViewItem* item = (KOTodoViewItem*)mTodoListView->firstChild (); 697 KOTodoViewItem* item = (KOTodoViewItem*)mTodoListView->firstChild ();
698 while ( item ) { 698 while ( item ) {
699 if ( item->todo() == oldInc ) { 699 if ( item->todo() == oldInc ) {
700 mTodoListView->setCurrentItem( item ); 700 mTodoListView->setCurrentItem( item );
701 mTodoListView->ensureItemVisible( item ); 701 mTodoListView->ensureItemVisible( item );
702 break; 702 break;
703 } 703 }
704 item = (KOTodoViewItem*)item->itemBelow(); 704 item = (KOTodoViewItem*)item->itemBelow();
705 } 705 }
706 if ( ! item ) 706 if ( ! item )
707 mTodoListView->setCurrentItem( mTodoListView->firstChild () ); 707 mTodoListView->setCurrentItem( mTodoListView->firstChild () );
708 } else { 708 } else {
709 mTodoListView->setCurrentItem( mTodoListView->firstChild () ); 709 mTodoListView->setCurrentItem( mTodoListView->firstChild () );
710 } 710 }
711 } 711 }
712 processSelectionChange(); 712 processSelectionChange();
713} 713}
714 714
715bool KOTodoView::checkTodo( Todo * todo ) 715bool KOTodoView::checkTodo( Todo * todo )
716{ 716{
717 717
718 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() ) 718 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() )
719 return false; 719 return false;
720 if ( !todo->isCompleted() ) { 720 if ( !todo->isCompleted() ) {
721 if ( todo->hasDueDate() && todo->dtDue().date() <= QDate::currentDate() ) 721 if ( todo->hasDueDate() && todo->dtDue().date() <= QDate::currentDate() )
722 return true; 722 return true;
723 } 723 }
724 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) { 724 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) {
725 if ( todo->hasStartDate() ) 725 if ( todo->hasStartDate() )
726 if ( mNavigator->selectedDates().last() < todo->dtStart().date() ) 726 if ( mNavigator->selectedDates().last() < todo->dtStart().date() )
727 return false; 727 return false;
728 if ( todo->hasDueDate() ) 728 if ( todo->hasDueDate() )
729 if ( mNavigator->selectedDates().first() > todo->dtDue().date() ) 729 if ( mNavigator->selectedDates().first() > todo->dtDue().date() )
730 return false; 730 return false;
731 } 731 }
732 return true; 732 return true;
733} 733}
734 734
735void KOTodoView::restoreItemState( QListViewItem *item ) 735void KOTodoView::restoreItemState( QListViewItem *item )
736{ 736{
737 pendingSubtodo = 0; 737 pendingSubtodo = 0;
738 while( item ) { 738 while( item ) {
739 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 739 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
740 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) ); 740 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) );
741 if( item->childCount() > 0 ) restoreItemState( item->firstChild() ); 741 if( item->childCount() > 0 ) restoreItemState( item->firstChild() );
742 item = item->nextSibling(); 742 item = item->nextSibling();
743 } 743 }
744} 744}
745 745
746 746
747QMap<Todo *,KOTodoViewItem *>::ConstIterator 747QMap<Todo *,KOTodoViewItem *>::ConstIterator
748 KOTodoView::insertTodoItem(Todo *todo) 748 KOTodoView::insertTodoItem(Todo *todo)
749{ 749{
750 750
751// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl; 751// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl;
752 // TODO: Check, if dynmaic cast is necessary 752 // TODO: Check, if dynmaic cast is necessary
753 753
754 pendingSubtodo = 0; 754 pendingSubtodo = 0;
755 Incidence *incidence = todo->relatedTo(); 755 Incidence *incidence = todo->relatedTo();
756 if (incidence && incidence->type() == "Todo") { 756 if (incidence && incidence->type() == "Todo") {
757 Todo *relatedTodo = static_cast<Todo *>(incidence); 757 Todo *relatedTodo = static_cast<Todo *>(incidence);
758 758
759// kdDebug() << " has Related" << endl; 759// kdDebug() << " has Related" << endl;
760 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 760 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
761 itemIterator = mTodoMap.find(relatedTodo); 761 itemIterator = mTodoMap.find(relatedTodo);
762 if (itemIterator == mTodoMap.end()) { 762 if (itemIterator == mTodoMap.end()) {
763// kdDebug() << " related not yet in list" << endl; 763// kdDebug() << " related not yet in list" << endl;
764 itemIterator = insertTodoItem (relatedTodo); 764 itemIterator = insertTodoItem (relatedTodo);
765 } 765 }
766 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem 766 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem
767 // and one into the map. Sure finding is more easy but why? -zecke 767 // and one into the map. Sure finding is more easy but why? -zecke
768 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this); 768 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this);
769 return mTodoMap.insert(todo,todoItem); 769 return mTodoMap.insert(todo,todoItem);
770 } else { 770 } else {
771// kdDebug() << " no Related" << endl; 771// kdDebug() << " no Related" << endl;
772 // see above -zecke 772 // see above -zecke
773 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 773 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
774 return mTodoMap.insert(todo,todoItem); 774 return mTodoMap.insert(todo,todoItem);
775 } 775 }
776} 776}
777 777
778 778
779void KOTodoView::updateConfig() 779void KOTodoView::updateConfig()
780{ 780{
781 updateView(); 781 updateView();
782 mTodoListView->repaintContents(); 782 mTodoListView->repaintContents();
783} 783}
784 784
785QPtrList<Incidence> KOTodoView::selectedIncidences() 785QPtrList<Incidence> KOTodoView::selectedIncidences()
786{ 786{
787 QPtrList<Incidence> selected; 787 QPtrList<Incidence> selected;
788 788
789 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 789 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
790// if (!item) item = mActiveItem; 790// if (!item) item = mActiveItem;
791 if (item) selected.append(item->todo()); 791 if (item) selected.append(item->todo());
792 792
793 return selected; 793 return selected;
794} 794}
795 795
796QPtrList<Todo> KOTodoView::selectedTodos() 796QPtrList<Todo> KOTodoView::selectedTodos()
797{ 797{
798 QPtrList<Todo> selected; 798 QPtrList<Todo> selected;
799 799
800 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 800 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
801// if (!item) item = mActiveItem; 801// if (!item) item = mActiveItem;
802 if (item) selected.append(item->todo()); 802 if (item) selected.append(item->todo());
803 803
804 return selected; 804 return selected;
805} 805}
806 806
807void KOTodoView::changeEventDisplay(Event *, int) 807void KOTodoView::changeEventDisplay(Event *, int)
808{ 808{
809 updateView(); 809 updateView();
810} 810}
811 811
812void KOTodoView::showDates(const QDate &, const QDate &) 812void KOTodoView::showDates(const QDate &, const QDate &)
813{ 813{
814} 814}
815 815
816void KOTodoView::showEvents(QPtrList<Event>) 816void KOTodoView::showEvents(QPtrList<Event>)
817{ 817{
818 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl; 818 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl;
819} 819}
820 820
821void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd, 821void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd,
822 const QDate &td) 822 const QDate &td)
823{ 823{
824#ifndef KORG_NOPRINTER 824#ifndef KORG_NOPRINTER
825 calPrinter->preview(CalPrinter::Todolist, fd, td); 825 calPrinter->preview(CalPrinter::Todolist, fd, td);
826#endif 826#endif
827} 827}
828 828
829void KOTodoView::editItem(QListViewItem *item ) 829void KOTodoView::editItem(QListViewItem *item )
830{ 830{
831 // qDebug("editItem(QListViewItem *item ) "); 831 // qDebug("editItem(QListViewItem *item ) ");
832 emit editTodoSignal(((KOTodoViewItem *)item)->todo()); 832 emit editTodoSignal(((KOTodoViewItem *)item)->todo());
833} 833}
834 834
835void KOTodoView::showItem(QListViewItem *item,const QPoint &,int) 835void KOTodoView::showItem(QListViewItem *item,const QPoint &,int)
836{ 836{
837 emit showTodoSignal(((KOTodoViewItem *)item)->todo()); 837 emit showTodoSignal(((KOTodoViewItem *)item)->todo());
838} 838}
839 839
840void KOTodoView::popupMenu(QListViewItem *item,const QPoint &p,int column) 840void KOTodoView::popupMenu(QListViewItem *item,const QPoint &p,int column)
841{ 841{
842 pendingSubtodo = 0; 842 pendingSubtodo = 0;
843 mActiveItem = (KOTodoViewItem *)item; 843 mActiveItem = (KOTodoViewItem *)item;
844 if (item) { 844 if (item) {
845 switch (column){ 845 switch (column){
846 case 1: 846 case 1:
847 mPriorityPopupMenu->popup(QCursor::pos ()); break; 847 mPriorityPopupMenu->popup(QCursor::pos ()); break;
848 case 2: 848 case 2:
849 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break; 849 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break;
850 case 3: 850 case 3:
851 moveTodo(); 851 moveTodo();
852 break; 852 break;
853 case 8: 853 case 8:
854 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break; 854 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break;
855 default: 855 default:
856 mItemPopupMenu->popup(QCursor::pos()); 856 mItemPopupMenu->popup(QCursor::pos());
857 } 857 }
858 } else mPopupMenu->popup(QCursor::pos()); 858 } else mPopupMenu->popup(QCursor::pos());
859} 859}
860void KOTodoView::newTodo() 860void KOTodoView::newTodo()
861{ 861{
862 emit newTodoSignal(); 862 emit newTodoSignal();
863} 863}
864 864
865void KOTodoView::newSubTodo() 865void KOTodoView::newSubTodo()
866{ 866{
867 if (mActiveItem) { 867 if (mActiveItem) {
868 emit newSubTodoSignal(mActiveItem->todo()); 868 emit newSubTodoSignal(mActiveItem->todo());
869 } 869 }
870} 870}
871void KOTodoView::unparentTodo() 871void KOTodoView::unparentTodo()
872{ 872{
873 if (mActiveItem) { 873 if (mActiveItem) {
874 emit unparentTodoSignal(mActiveItem->todo()); 874 emit unparentTodoSignal(mActiveItem->todo());
875 } 875 }
876} 876}
877 877
878void KOTodoView::reparentTodo() 878void KOTodoView::reparentTodo()
879{ 879{
880 if (mActiveItem) { 880 if (mActiveItem) {
881 qDebug("KOTodoView::reparentTodo() "); 881 qDebug("KOTodoView::reparentTodo() ");
882 topLevelWidget()->setCaption(i18n("Click on new parent item")); 882 topLevelWidget()->setCaption(i18n("Click on new parent item"));
883 pendingSubtodo = mActiveItem; 883 pendingSubtodo = mActiveItem;
884 } 884 }
885} 885}
886void KOTodoView::editTodo() 886void KOTodoView::editTodo()
887{ 887{
888 if (mActiveItem) { 888 if (mActiveItem) {
889 emit editTodoSignal(mActiveItem->todo()); 889 emit editTodoSignal(mActiveItem->todo());
890 } 890 }
891} 891}
892void KOTodoView::cloneTodo() 892void KOTodoView::cloneTodo()
893{ 893{
894 if (mActiveItem) { 894 if (mActiveItem) {
895 emit cloneTodoSignal((Incidence*)mActiveItem->todo()); 895 emit cloneTodoSignal((Incidence*)mActiveItem->todo());
896 } 896 }
897} 897}
898void KOTodoView::cancelTodo() 898void KOTodoView::cancelTodo()
899{ 899{
900 if (mActiveItem) { 900 if (mActiveItem) {
901 emit cancelTodoSignal((Incidence*)mActiveItem->todo()); 901 emit cancelTodoSignal((Incidence*)mActiveItem->todo());
902 } 902 }
903} 903}
904void KOTodoView::moveTodo() 904void KOTodoView::moveTodo()
905{ 905{
906 if (mActiveItem) { 906 if (mActiveItem) {
907 emit moveTodoSignal((Incidence*)mActiveItem->todo()); 907 emit moveTodoSignal((Incidence*)mActiveItem->todo());
908 } 908 }
909} 909}
910void KOTodoView::beamTodo() 910void KOTodoView::beamTodo()
911{ 911{
912 if (mActiveItem) { 912 if (mActiveItem) {
913 emit beamTodoSignal((Incidence*)mActiveItem->todo()); 913 emit beamTodoSignal((Incidence*)mActiveItem->todo());
914 } 914 }
915} 915}
916 916
917 917
918void KOTodoView::showTodo() 918void KOTodoView::showTodo()
919{ 919{
920 if (mActiveItem) { 920 if (mActiveItem) {
921 emit showTodoSignal(mActiveItem->todo()); 921 emit showTodoSignal(mActiveItem->todo());
922 } 922 }
923} 923}
924 924
925void KOTodoView::deleteTodo() 925void KOTodoView::deleteTodo()
926{ 926{
927 if (mActiveItem) { 927 if (mActiveItem) {
928 emit deleteTodoSignal(mActiveItem->todo()); 928 emit deleteTodoSignal(mActiveItem->todo());
929 } 929 }
930} 930}
931 931
932void KOTodoView::setNewPriority(int index) 932void KOTodoView::setNewPriority(int index)
933{ 933{
934 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 934 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
935 mActiveItem->todo()->setPriority(mPriority[index]); 935 mActiveItem->todo()->setPriority(mPriority[index]);
936 mActiveItem->construct(); 936 mActiveItem->construct();
937 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED); 937 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED);
938 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 938 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
939 } 939 }
940} 940}
941 941
942void KOTodoView::setNewPercentage(int index) 942void KOTodoView::setNewPercentage(int index)
943{ 943{
944 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 944 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
945 945
946 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) { 946 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) {
947 mActiveItem->setOn( true ); 947 mActiveItem->setOn( true );
948 return; 948 return;
949 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) { 949 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) {
950 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent())); 950 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent()));
951 if ( par && par->isOn() ) 951 if ( par && par->isOn() )
952 par->setOn( false ); 952 par->setOn( false );
953 } 953 }
954 if (mPercentage[index] == 100) { 954 if (mPercentage[index] == 100) {
955 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime()); 955 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime());
956 } else { 956 } else {
957 mActiveItem->todo()->setCompleted(false); 957 mActiveItem->todo()->setCompleted(false);
958 } 958 }
959 mActiveItem->todo()->setPercentComplete(mPercentage[index]); 959 mActiveItem->todo()->setPercentComplete(mPercentage[index]);
960 mActiveItem->construct(); 960 mActiveItem->construct();
961 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED); 961 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED);
962 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 962 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
963 } 963 }
964} 964}
965 965
966 966
967QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem) 967QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem)
968{ 968{
969 QPopupMenu* tempMenu = new QPopupMenu (this); 969 QPopupMenu* tempMenu = new QPopupMenu (this);
970 QStringList checkedCategories = todoItem->todo()->categories (); 970 QStringList checkedCategories = todoItem->todo()->categories ();
971 971
972 tempMenu->setCheckable (true); 972 tempMenu->setCheckable (true);
973 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin (); 973 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin ();
974 it != KOPrefs::instance()->mCustomCategories.end (); 974 it != KOPrefs::instance()->mCustomCategories.end ();
975 ++it) { 975 ++it) {
976 int index = tempMenu->insertItem (*it); 976 int index = tempMenu->insertItem (*it);
977 mCategory[index] = *it; 977 mCategory[index] = *it;
978 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true); 978 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true);
979 } 979 }
980 980
981 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int))); 981 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int)));
982 return tempMenu; 982 return tempMenu;
983 983
984 984
985} 985}
986void KOTodoView::changedCategories(int index) 986void KOTodoView::changedCategories(int index)
987{ 987{
988 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 988 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
989 QStringList categories = mActiveItem->todo()->categories (); 989 QStringList categories = mActiveItem->todo()->categories ();
990 QString colcat = categories.first(); 990 QString colcat = categories.first();
991 if (categories.find (mCategory[index]) != categories.end ()) 991 if (categories.find (mCategory[index]) != categories.end ())
992 categories.remove (mCategory[index]); 992 categories.remove (mCategory[index]);
993 else 993 else
994 categories.insert (categories.end(), mCategory[index]); 994 categories.insert (categories.end(), mCategory[index]);
995 categories.sort (); 995 categories.sort ();
996 if ( !colcat.isEmpty() ) { 996 if ( !colcat.isEmpty() ) {
997 if ( categories.find ( colcat ) != categories.end () ) { 997 if ( categories.find ( colcat ) != categories.end () ) {
998 categories.remove( colcat ); 998 categories.remove( colcat );
999 categories.prepend( colcat ); 999 categories.prepend( colcat );
1000 } 1000 }
1001 } 1001 }
1002 mActiveItem->todo()->setCategories (categories); 1002 mActiveItem->todo()->setCategories (categories);
1003 mActiveItem->construct(); 1003 mActiveItem->construct();
1004 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 1004 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
1005 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED); 1005 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED);
1006 } 1006 }
1007} 1007}
1008void KOTodoView::itemDoubleClicked(QListViewItem *item) 1008void KOTodoView::itemDoubleClicked(QListViewItem *item)
1009{ 1009{
1010 if ( pendingSubtodo != 0 ) { 1010 if ( pendingSubtodo != 0 ) {
1011 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 1011 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
1012 } 1012 }
1013 pendingSubtodo = 0; 1013 pendingSubtodo = 0;
1014 if (!item) { 1014 if (!item) {
1015 newTodo(); 1015 newTodo();
1016 return; 1016 return;
1017 } 1017 }
1018 if ( KOPrefs::instance()->mEditOnDoubleClick ) 1018 if ( KOPrefs::instance()->mEditOnDoubleClick )
1019 editItem( item ); 1019 editItem( item );
1020 else 1020 else
1021 showItem( item , QPoint(), 0 ); 1021 showItem( item , QPoint(), 0 );
1022} 1022}
1023void KOTodoView::itemClicked(QListViewItem *item) 1023void KOTodoView::itemClicked(QListViewItem *item)
1024{ 1024{
1025 1025
1026 if (!item) { 1026 if (!item) {
1027 if ( pendingSubtodo != 0 ) { 1027 if ( pendingSubtodo != 0 ) {
1028 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 1028 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
1029 } 1029 }
1030 pendingSubtodo = 0; 1030 pendingSubtodo = 0;
1031 return; 1031 return;
1032 } 1032 }
1033 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 1033 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
1034 if ( pendingSubtodo != 0 ) { 1034 if ( pendingSubtodo != 0 ) {
1035 bool allowReparent = true; 1035 bool allowReparent = true;
1036 QListViewItem *par = item; 1036 QListViewItem *par = item;
1037 while ( par ) { 1037 while ( par ) {
1038 if ( par == pendingSubtodo ) { 1038 if ( par == pendingSubtodo ) {
1039 allowReparent = false; 1039 allowReparent = false;
1040 break; 1040 break;
1041 } 1041 }
1042 par = par->parent(); 1042 par = par->parent();
1043 } 1043 }
1044 if ( !allowReparent ) { 1044 if ( !allowReparent ) {
1045 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!")); 1045 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!"));
1046 qDebug("Recursive reparenting not possible "); 1046 qDebug("Recursive reparenting not possible ");
1047 pendingSubtodo = 0; 1047 pendingSubtodo = 0;
1048 } else { 1048 } else {
1049 Todo* newParent = todoItem->todo(); 1049 Todo* newParent = todoItem->todo();
1050 Todo* newSub = pendingSubtodo->todo(); 1050 Todo* newSub = pendingSubtodo->todo();
1051 pendingSubtodo = 0; 1051 pendingSubtodo = 0;
1052 emit reparentTodoSignal( newParent,newSub ); 1052 emit reparentTodoSignal( newParent,newSub );
1053 return; 1053 return;
1054 } 1054 }
1055 } 1055 }
1056#if 0 1056#if 0
1057 // handled by the item itself 1057 // handled by the item itself
1058 bool completed = todoItem->todo()->isCompleted(); // Completed or not? 1058 bool completed = todoItem->todo()->isCompleted(); // Completed or not?
1059 qDebug("com %d ",completed ); 1059 qDebug("com %d ",completed );
1060 qDebug("itemclicked "); 1060 qDebug("itemclicked ");
1061 if (todoItem->isOn()) { 1061 if (todoItem->isOn()) {
1062 qDebug("on "); 1062 qDebug("on ");
1063 if (!completed) { 1063 if (!completed) {
1064 qDebug("set true "); 1064 qDebug("set true ");
1065 todoItem->todo()->setCompleted(QDateTime::currentDateTime()); 1065 todoItem->todo()->setCompleted(QDateTime::currentDateTime());
1066 } 1066 }
1067 } else { 1067 } else {
1068 qDebug("not on "); 1068 qDebug("not on ");
1069 if (completed) { 1069 if (completed) {
1070 qDebug("set false "); 1070 qDebug("set false ");
1071 todoItem->todo()->setCompleted(false); 1071 todoItem->todo()->setCompleted(false);
1072 } 1072 }
1073 } 1073 }
1074#endif 1074#endif
1075} 1075}
1076 1076
1077void KOTodoView::setDocumentId( const QString &id ) 1077void KOTodoView::setDocumentId( const QString &id )
1078{ 1078{
1079 kdDebug() << "KOTodoView::setDocumentId()" << endl; 1079 kdDebug() << "KOTodoView::setDocumentId()" << endl;
1080 1080
1081 mDocPrefs->setDoc( id ); 1081 mDocPrefs->setDoc( id );
1082} 1082}
1083 1083
1084void KOTodoView::itemStateChanged( QListViewItem *item ) 1084void KOTodoView::itemStateChanged( QListViewItem *item )
1085{ 1085{
1086 if (!item) return; 1086 if (!item) return;
1087 1087
1088 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 1088 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
1089 1089
1090// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl; 1090// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl;
1091 1091
1092 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() ); 1092 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() );
1093} 1093}
1094 1094
1095void KOTodoView::saveLayout(KConfig *config, const QString &group) const 1095void KOTodoView::saveLayout(KConfig *config, const QString &group) const
1096{ 1096{
1097 mTodoListView->saveLayout(config,group); 1097 mTodoListView->saveLayout(config,group);
1098} 1098}
1099 1099
1100void KOTodoView::restoreLayout(KConfig *config, const QString &group) 1100void KOTodoView::restoreLayout(KConfig *config, const QString &group)
1101{ 1101{
1102 mTodoListView->restoreLayout(config,group); 1102 mTodoListView->restoreLayout(config,group);
1103} 1103}
1104 1104
1105void KOTodoView::processSelectionChange() 1105void KOTodoView::processSelectionChange()
1106{ 1106{
1107// kdDebug() << "KOTodoView::processSelectionChange()" << endl; 1107// kdDebug() << "KOTodoView::processSelectionChange()" << endl;
1108 1108
1109 KOTodoViewItem *item = 1109 KOTodoViewItem *item =
1110 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() ); 1110 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() );
1111 1111
1112 if ( !item ) { 1112 if ( !item ) {
1113 emit incidenceSelected( 0 ); 1113 emit incidenceSelected( 0 );
1114 } else { 1114 } else {
1115 emit incidenceSelected( item->todo() ); 1115 emit incidenceSelected( item->todo() );
1116 } 1116 }
1117} 1117}
1118 1118
1119void KOTodoView::modified(bool b) 1119void KOTodoView::modified(bool b)
1120{ 1120{
1121 emit isModified(b); 1121 emit isModified(b);
1122} 1122}
1123void KOTodoView::setTodoModified( Todo* todo ) 1123void KOTodoView::setTodoModified( Todo* todo )
1124{ 1124{
1125 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED ); 1125 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED );
1126} 1126}
1127void KOTodoView::clearSelection() 1127void KOTodoView::clearSelection()
1128{ 1128{
1129 mTodoListView->selectAll( false ); 1129 mTodoListView->selectAll( false );
1130} 1130}
1131void KOTodoView::setAllOpen() 1131void KOTodoView::setAllOpen()
1132{ 1132{
1133 if ( isFlatDisplay ) { 1133 if ( isFlatDisplay ) {
1134 isFlatDisplay = false; 1134 isFlatDisplay = false;
1135 mPopupMenu->setItemChecked( 8,false ); 1135 mPopupMenu->setItemChecked( 8,false );
1136 updateView(); 1136 updateView();
1137 } 1137 }
1138 setOpen(mTodoListView->firstChild(), true); 1138 setOpen(mTodoListView->firstChild(), true);
1139} 1139}
1140void KOTodoView::setAllClose() 1140void KOTodoView::setAllClose()
1141{ 1141{
1142 if ( isFlatDisplay ) { 1142 if ( isFlatDisplay ) {
1143 isFlatDisplay = false; 1143 isFlatDisplay = false;
1144 mPopupMenu->setItemChecked( 8,false ); 1144 mPopupMenu->setItemChecked( 8,false );
1145 updateView(); 1145 updateView();
1146 } 1146 }
1147 setOpen(mTodoListView->firstChild(), false); 1147 setOpen(mTodoListView->firstChild(), false);
1148} 1148}
1149void KOTodoView::setOpen( QListViewItem* item, bool setOpenI) 1149void KOTodoView::setOpen( QListViewItem* item, bool setOpenI)
1150{ 1150{
1151 1151
1152 while ( item ) { 1152 while ( item ) {
1153 setOpen( item->firstChild(), setOpenI ); 1153 setOpen( item->firstChild(), setOpenI );
1154 item->setOpen( setOpenI ); 1154 item->setOpen( setOpenI );
1155 item = item->nextSibling(); 1155 item = item->nextSibling();
1156 } 1156 }
1157} 1157}
1158 1158
1159void KOTodoView::displayAllFlat() 1159void KOTodoView::displayAllFlat()
1160{ 1160{
1161 pendingSubtodo = 0; 1161 pendingSubtodo = 0;
1162 if ( mBlockUpdate ) { 1162 if ( mBlockUpdate ) {
1163 return; 1163 return;
1164 } 1164 }
1165 mPopupMenu->setItemChecked( 8,true ); 1165 mPopupMenu->setItemChecked( 8,true );
1166 isFlatDisplay = true; 1166 isFlatDisplay = true;
1167 QPtrList<Todo> todoList = calendar()->todos(); 1167 QPtrList<Todo> todoList = calendar()->todos();
1168 mTodoMap.clear(); 1168 mTodoMap.clear();
1169 mTodoListView->clear(); 1169 mTodoListView->clear();
1170 Todo *todo; 1170 Todo *todo;
1171 for(todo = todoList.first(); todo; todo = todoList.next()) { 1171 for(todo = todoList.first(); todo; todo = todoList.next()) {
1172 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 1172 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
1173 mTodoMap.insert(todo,todoItem); 1173 mTodoMap.insert(todo,todoItem);
1174 } 1174 }
1175 mTodoListView->setFocus(); 1175 mTodoListView->setFocus();
1176 processSelectionChange(); 1176 processSelectionChange();
1177} 1177}
1178 1178
1179void KOTodoView::setAllFlat() 1179void KOTodoView::setAllFlat()
1180{ 1180{
1181 if ( isFlatDisplay ) { 1181 if ( isFlatDisplay ) {
1182 isFlatDisplay = false; 1182 isFlatDisplay = false;
1183 mPopupMenu->setItemChecked( 8,false ); 1183 mPopupMenu->setItemChecked( 8,false );
1184 updateView(); 1184 updateView();
1185 return; 1185 return;
1186 } 1186 }
1187 displayAllFlat(); 1187 displayAllFlat();
1188} 1188}
1189 1189
1190void KOTodoView::purgeCompleted() 1190void KOTodoView::purgeCompleted()
1191{ 1191{
1192 emit purgeCompletedSignal(); 1192 emit purgeCompletedSignal();
1193} 1193}
1194void KOTodoView::toggleQuickTodo() 1194void KOTodoView::toggleQuickTodo()
1195{ 1195{
1196 if ( mQuickAdd->isVisible() ) { 1196 if ( mQuickAdd->isVisible() ) {
1197 mQuickAdd->hide(); 1197 mQuickAdd->hide();
1198 KOPrefs::instance()->mEnableQuickTodo = false; 1198 KOPrefs::instance()->mEnableQuickTodo = false;
1199 } 1199 }
1200 else { 1200 else {
1201 mQuickAdd->show(); 1201 mQuickAdd->show();
1202 KOPrefs::instance()->mEnableQuickTodo = true; 1202 KOPrefs::instance()->mEnableQuickTodo = true;
1203 } 1203 }
1204 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 1204 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
1205 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 1205 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
1206} 1206}
1207 1207
1208void KOTodoView::toggleRunning() 1208void KOTodoView::toggleRunning()
1209{ 1209{
1210 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos; 1210 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos;
1211 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 1211 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
1212 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 1212 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
1213 updateView(); 1213 updateView();
1214} 1214}
1215 1215
1216void KOTodoView::toggleCompleted() 1216void KOTodoView::toggleCompleted()
1217{ 1217{
1218 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo; 1218 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo;
1219 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 1219 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
1220 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 1220 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
1221 updateView(); 1221 updateView();
1222} 1222}
1223 1223
1224void KOTodoView::addQuickTodo() 1224void KOTodoView::addQuickTodo()
1225{ 1225{
1226 Todo *todo = new Todo(); 1226 Todo *todo = new Todo();
1227 todo->setSummary(mQuickAdd->text()); 1227 todo->setSummary(mQuickAdd->text());
1228 todo->setOrganizer(KOPrefs::instance()->email()); 1228 todo->setOrganizer(KOPrefs::instance()->email());
1229 CalFilter * cf = mCalendar->filter(); 1229 CalFilter * cf = mCalendar->filter();
1230 if ( cf ) { 1230 if ( cf ) {
1231 if ( cf->isEnabled()&& cf->showCategories()) { 1231 if ( cf->isEnabled()&& cf->showCategories()) {
1232 todo->setCategories(cf->categoryList()); 1232 todo->setCategories(cf->categoryList());
1233 } 1233 }
1234 if ( cf->isEnabled() ) 1234 if ( cf->isEnabled() )
1235 todo->setSecrecy( cf->getSecrecy()); 1235 todo->setSecrecy( cf->getSecrecy());
1236 } 1236 }
1237 mCalendar->addTodo(todo); 1237 mCalendar->addTodo(todo);
1238 mQuickAdd->setText(""); 1238 mQuickAdd->setText("");
1239 todoModified (todo, KOGlobals::EVENTADDED ); 1239 todoModified (todo, KOGlobals::EVENTADDED );
1240 updateView(); 1240 updateView();
1241} 1241}
1242void KOTodoView::keyPressEvent ( QKeyEvent * e ) 1242void KOTodoView::keyPressEvent ( QKeyEvent * e )
1243{ 1243{
1244 // e->ignore(); 1244 // e->ignore();
1245 //return; 1245 //return;
1246 //qDebug("KOTodoView::keyPressEvent "); 1246 //qDebug("KOTodoView::keyPressEvent ");
1247 switch ( e->key() ) { 1247 switch ( e->key() ) {
1248 case Qt::Key_Down: 1248 case Qt::Key_Down:
1249 case Qt::Key_Up: 1249 case Qt::Key_Up:
1250 QWidget::keyPressEvent ( e ); 1250 QWidget::keyPressEvent ( e );
1251 break; 1251 break;
1252 1252
1253 case Qt::Key_Q: 1253 case Qt::Key_Q:
1254 toggleQuickTodo(); 1254 toggleQuickTodo();
1255 break; 1255 break;
1256 case Qt::Key_U: 1256 case Qt::Key_U:
1257 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1257 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1258 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1258 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1259 unparentTodo(); 1259 unparentTodo();
1260 e->accept(); 1260 e->accept();
1261 } else 1261 } else
1262 e->ignore(); 1262 e->ignore();
1263 break; 1263 break;
1264 case Qt::Key_S: 1264 case Qt::Key_S:
1265 if ( e->state() == Qt::ControlButton ) { 1265 if ( e->state() == Qt::ControlButton ) {
1266 e->ignore(); 1266 e->ignore();
1267 break; 1267 break;
1268 } 1268 }
1269 if ( e->state() == Qt::ShiftButton ) { 1269 if ( e->state() == Qt::ShiftButton ) {
1270 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1270 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1271 reparentTodo(); 1271 reparentTodo();
1272 e->accept(); 1272 e->accept();
1273 } else 1273 } else
1274 e->ignore(); 1274 e->ignore();
1275 break; 1275 break;
1276 case Qt::Key_P: 1276 case Qt::Key_P:
1277 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1277 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1278 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1278 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1279 if ( pendingSubtodo ) 1279 if ( pendingSubtodo )
1280 itemClicked(mActiveItem); 1280 itemClicked(mActiveItem);
1281 e->accept(); 1281 e->accept();
1282 } else 1282 } else
1283 e->ignore(); 1283 e->ignore();
1284 break; 1284 break;
1285 case Qt::Key_Escape: 1285 case Qt::Key_Escape:
1286 if ( pendingSubtodo ) { 1286 if ( pendingSubtodo ) {
1287 itemClicked(0); 1287 itemClicked(0);
1288 e->accept(); 1288 e->accept();
1289 } else 1289 } else
1290 e->ignore(); 1290 e->ignore();
1291 break; 1291 break;
1292 default: 1292 default:
1293 e->ignore(); 1293 e->ignore();
1294 } 1294 }
1295 1295
1296 if ( true ) { 1296 if ( true ) {
1297 if ( e->key() == Qt::Key_I ) { 1297 if ( e->key() == Qt::Key_I ) {
1298 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem(); 1298 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem();
1299 if ( cn ) { 1299 if ( cn ) {
1300 mActiveItem = cn; 1300 mActiveItem = cn;
1301 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 1301 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
1302 if ( ci ){ 1302 if ( ci ){
1303 showTodo(); 1303 showTodo();
1304 cn = (KOTodoViewItem*)cn->itemBelow(); 1304 cn = (KOTodoViewItem*)cn->itemBelow();
1305 if ( cn ) { 1305 if ( cn ) {
1306 mTodoListView->setCurrentItem ( cn ); 1306 mTodoListView->setCurrentItem ( cn );
1307 mTodoListView->ensureItemVisible ( cn ); 1307 mTodoListView->ensureItemVisible ( cn );
1308 } 1308 }
1309 1309
1310 } 1310 }
1311 } 1311 }
1312 e->accept(); 1312 e->accept();
1313 1313
1314 } 1314 }
1315 1315
1316 } 1316 }
1317 1317
1318} 1318}
1319void KOTodoView::updateTodo( Todo * t, int type ) 1319void KOTodoView::updateTodo( Todo * t, int type )
1320{ 1320{
1321 if ( mBlockUpdate) 1321 if ( mBlockUpdate)
1322 return; 1322 return;
1323 1323
1324 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 1324 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
1325 itemIterator = mTodoMap.find(t); 1325 itemIterator = mTodoMap.find(t);
1326 if (itemIterator != mTodoMap.end()) { 1326 if (itemIterator != mTodoMap.end()) {
1327 (*itemIterator)->construct(); 1327 (*itemIterator)->construct();
1328 } else { 1328 } else {
1329 if ( type == KOGlobals::EVENTADDED ) { 1329 if ( type == KOGlobals::EVENTADDED ) {
1330 insertTodoItem( t ); 1330 insertTodoItem( t );
1331 } 1331 }
1332 } 1332 }
1333 1333
1334} 1334}
1335 1335
1336void KOTodoView::todoModified(Todo * t , int p ) 1336void KOTodoView::todoModified(Todo * t , int p )
1337{ 1337{
1338 mBlockUpdate = true; 1338 mBlockUpdate = true;
1339 emit todoModifiedSignal ( t, p ); 1339 emit todoModifiedSignal ( t, p );
1340 mBlockUpdate = false; 1340 mBlockUpdate = false;
1341} 1341}