summaryrefslogtreecommitdiffabout
path: root/korganizer
authorzautrix <zautrix>2005-04-02 12:16:34 (UTC)
committer zautrix <zautrix>2005-04-02 12:16:34 (UTC)
commit997e7660a81baa2b8aeb1b66a3cc3ebe54e00ebe (patch) (unidiff)
treef788b37459574b5cea0d2ab874882c6a396c240d /korganizer
parente0d51120d2f0c178115746e0c1357af40f95bc77 (diff)
downloadkdepimpi-997e7660a81baa2b8aeb1b66a3cc3ebe54e00ebe.zip
kdepimpi-997e7660a81baa2b8aeb1b66a3cc3ebe54e00ebe.tar.gz
kdepimpi-997e7660a81baa2b8aeb1b66a3cc3ebe54e00ebe.tar.bz2
more fixes
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagenda.cpp57
-rw-r--r--korganizer/koagenda.h4
-rw-r--r--korganizer/koagendaview.cpp18
-rw-r--r--korganizer/koagendaview.h4
-rw-r--r--korganizer/kotodoview.cpp49
5 files changed, 97 insertions, 35 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp
index deadfc9..de964da 100644
--- a/korganizer/koagenda.cpp
+++ b/korganizer/koagenda.cpp
@@ -1,2234 +1,2273 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 Marcus Bains line. 5 Marcus Bains line.
6 Copyright (c) 2001 Ali Rahimi 6 Copyright (c) 2001 Ali Rahimi
7 7
8 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 (at your option) any later version.
12 12
13 This program is distributed in the hope that it will be useful, 13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 GNU General Public License for more details.
17 17
18 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software 19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 21
22 As a special exception, permission is given to link this program 22 As a special exception, permission is given to link this program
23 with any edition of Qt, and distribute the resulting executable, 23 with any edition of Qt, and distribute the resulting executable,
24 without including the source code for Qt in the source distribution. 24 without including the source code for Qt in the source distribution.
25*/ 25*/
26 26
27#ifndef _WIN32_ 27#ifndef _WIN32_
28#define protected public 28#define protected public
29#include <qwidget.h> 29#include <qwidget.h>
30#undef protected 30#undef protected
31#endif 31#endif
32#include <qintdict.h> 32#include <qintdict.h>
33#include <qdatetime.h> 33#include <qdatetime.h>
34#include <qapplication.h> 34#include <qapplication.h>
35#include <qpopupmenu.h> 35#include <qpopupmenu.h>
36#include <qcursor.h> 36#include <qcursor.h>
37#include <qpainter.h> 37#include <qpainter.h>
38 38
39#include <kdebug.h> 39#include <kdebug.h>
40#include <klocale.h> 40#include <klocale.h>
41#include <kiconloader.h> 41#include <kiconloader.h>
42#include <kglobal.h> 42#include <kglobal.h>
43 43
44#include "koagendaitem.h" 44#include "koagendaitem.h"
45#include "koprefs.h" 45#include "koprefs.h"
46#include "koglobals.h" 46#include "koglobals.h"
47 47
48#include "koagenda.h" 48#include "koagenda.h"
49 49
50#include <libkcal/event.h> 50#include <libkcal/event.h>
51#include <libkcal/todo.h> 51#include <libkcal/todo.h>
52 52
53#ifndef DESKTOP_VERSION 53#ifndef DESKTOP_VERSION
54#include <qpe/qpeapplication.h> 54#include <qpe/qpeapplication.h>
55#endif 55#endif
56 56
57//extern bool globalFlagBlockPainting; 57//extern bool globalFlagBlockPainting;
58extern int globalFlagBlockAgenda; 58extern int globalFlagBlockAgenda;
59extern int globalFlagBlockAgendaItemPaint; 59extern int globalFlagBlockAgendaItemPaint;
60extern int globalFlagBlockAgendaItemUpdate; 60extern int globalFlagBlockAgendaItemUpdate;
61extern int globalFlagBlockStartup; 61extern int globalFlagBlockStartup;
62 62
63//////////////////////////////////////////////////////////////////////////// 63////////////////////////////////////////////////////////////////////////////
64MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name) 64MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name)
65 : QFrame(_agenda->viewport(),name), agenda(_agenda) 65 : QFrame(_agenda->viewport(),name), agenda(_agenda)
66{ 66{
67 setLineWidth(0); 67 setLineWidth(0);
68 setMargin(0); 68 setMargin(0);
69 setBackgroundColor(Qt::red); 69 setBackgroundColor(Qt::red);
70 minutes = new QTimer(this); 70 minutes = new QTimer(this);
71 connect(minutes, SIGNAL(timeout()), this, SLOT(updateLoc())); 71 connect(minutes, SIGNAL(timeout()), this, SLOT(updateLoc()));
72 minutes->start(0, true); 72 minutes->start(0, true);
73 mTimeBox = new QLabel(this); 73 mTimeBox = new QLabel(this);
74 mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom); 74 mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom);
75 QPalette pal = mTimeBox->palette(); 75 QPalette pal = mTimeBox->palette();
76 pal.setColor(QColorGroup::Foreground, Qt::red); 76 pal.setColor(QColorGroup::Foreground, Qt::red);
77 mTimeBox->setPalette(pal); 77 mTimeBox->setPalette(pal);
78 //mTimeBox->setAutoMask(true); 78 //mTimeBox->setAutoMask(true);
79 79
80 agenda->addChild(mTimeBox); 80 agenda->addChild(mTimeBox);
81 81
82 oldToday = -1; 82 oldToday = -1;
83} 83}
84 84
85MarcusBains::~MarcusBains() 85MarcusBains::~MarcusBains()
86{ 86{
87 delete minutes; 87 delete minutes;
88} 88}
89 89
90int MarcusBains::todayColumn() 90int MarcusBains::todayColumn()
91{ 91{
92 QDate currentDate = QDate::currentDate(); 92 QDate currentDate = QDate::currentDate();
93 93
94 DateList dateList = agenda->dateList(); 94 DateList dateList = agenda->dateList();
95 DateList::ConstIterator it; 95 DateList::ConstIterator it;
96 int col = 0; 96 int col = 0;
97 for(it = dateList.begin(); it != dateList.end(); ++it) { 97 for(it = dateList.begin(); it != dateList.end(); ++it) {
98 if((*it) == currentDate) 98 if((*it) == currentDate)
99 return KOGlobals::self()->reverseLayout() ? 99 return KOGlobals::self()->reverseLayout() ?
100 agenda->columns() - 1 - col : col; 100 agenda->columns() - 1 - col : col;
101 ++col; 101 ++col;
102 } 102 }
103 103
104 return -1; 104 return -1;
105} 105}
106void MarcusBains::updateLoc() 106void MarcusBains::updateLoc()
107{ 107{
108 updateLocation(); 108 updateLocation();
109} 109}
110void MarcusBains::updateLocation(bool recalculate) 110void MarcusBains::updateLocation(bool recalculate)
111{ 111{
112 112
113 QTime tim = QTime::currentTime(); 113 QTime tim = QTime::currentTime();
114 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1()); 114 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1());
115 if((tim.hour() == 0) && (oldTime.hour()==23)) 115 if((tim.hour() == 0) && (oldTime.hour()==23))
116 recalculate = true; 116 recalculate = true;
117 117
118 int mins = tim.hour()*60 + tim.minute(); 118 int mins = tim.hour()*60 + tim.minute();
119 int minutesPerCell = 24 * 60 / agenda->rows(); 119 int minutesPerCell = 24 * 60 / agenda->rows();
120 int y = mins*agenda->gridSpacingY()/minutesPerCell; 120 int y = mins*agenda->gridSpacingY()/minutesPerCell;
121 int today = recalculate ? todayColumn() : oldToday; 121 int today = recalculate ? todayColumn() : oldToday;
122 int x = agenda->gridSpacingX()*today; 122 int x = agenda->gridSpacingX()*today;
123 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled); 123 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled);
124 124
125 oldTime = tim; 125 oldTime = tim;
126 oldToday = today; 126 oldToday = today;
127 127
128 if(disabled || (today<0)) { 128 if(disabled || (today<0)) {
129 hide(); mTimeBox->hide(); 129 hide(); mTimeBox->hide();
130 return; 130 return;
131 } else { 131 } else {
132 show(); mTimeBox->show(); 132 show(); mTimeBox->show();
133 } 133 }
134 134
135 if(recalculate) 135 if(recalculate)
136 setFixedSize(agenda->gridSpacingX(),1); 136 setFixedSize(agenda->gridSpacingX(),1);
137 agenda->moveChild(this, x, y); 137 agenda->moveChild(this, x, y);
138 raise(); 138 raise();
139 139
140 if(recalculate) 140 if(recalculate)
141 //mTimeBox->setFont(QFont("helvetica",10)); 141 //mTimeBox->setFont(QFont("helvetica",10));
142 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont); 142 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont);
143 143
144 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds)); 144 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds));
145 mTimeBox->adjustSize(); 145 mTimeBox->adjustSize();
146 // the -2 below is there because there is a bug in this program 146 // the -2 below is there because there is a bug in this program
147 // somewhere, where the last column of this widget is a few pixels 147 // somewhere, where the last column of this widget is a few pixels
148 // narrower than the other columns. 148 // narrower than the other columns.
149 int offs = (today==agenda->columns()-1) ? -4 : 0; 149 int offs = (today==agenda->columns()-1) ? -4 : 0;
150 agenda->moveChild(mTimeBox, 150 agenda->moveChild(mTimeBox,
151 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1, 151 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1,
152 y-mTimeBox->height()); 152 y-mTimeBox->height());
153 153
154 mTimeBox->raise(); 154 mTimeBox->raise();
155 //mTimeBox->setAutoMask(true); 155 //mTimeBox->setAutoMask(true);
156 minutes->start(5000,true); 156 minutes->start(5000,true);
157} 157}
158 158
159 159
160//////////////////////////////////////////////////////////////////////////// 160////////////////////////////////////////////////////////////////////////////
161 161
162 162
163/* 163/*
164 Create an agenda widget with rows rows and columns columns. 164 Create an agenda widget with rows rows and columns columns.
165*/ 165*/
166KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, 166KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent,
167 const char *name,WFlags f) : 167 const char *name,WFlags f) :
168 QScrollView(parent,name,f) 168 QScrollView(parent,name,f)
169{ 169{
170 170
171 171 mAllAgendaPopup = 0;
172 mColumns = columns; 172 mColumns = columns;
173 mRows = rows; 173 mRows = rows;
174 mGridSpacingY = rowSize; 174 mGridSpacingY = rowSize;
175 mAllDayMode = false; 175 mAllDayMode = false;
176#ifndef DESKTOP_VERSION 176#ifndef DESKTOP_VERSION
177 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 177 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
178#endif 178#endif
179 mHolidayMask = 0; 179 mHolidayMask = 0;
180 init(); 180 init();
181} 181}
182 182
183/* 183/*
184 Create an agenda widget with columns columns and one row. This is used for 184 Create an agenda widget with columns columns and one row. This is used for
185 all-day events. 185 all-day events.
186*/ 186*/
187KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : 187KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) :
188 QScrollView(parent,name,f) 188 QScrollView(parent,name,f)
189{ 189{
190 mAllAgendaPopup = 0;
190 blockResize = false; 191 blockResize = false;
191 mColumns = columns; 192 mColumns = columns;
192 mRows = 1; 193 mRows = 1;
193 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize); 194 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize);
194 mGridSpacingY = KOPrefs::instance()->mAllDaySize; 195 mGridSpacingY = KOPrefs::instance()->mAllDaySize;
195 mAllDayMode = true; 196 mAllDayMode = true;
196#ifndef DESKTOP_VERSION 197#ifndef DESKTOP_VERSION
197 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 198 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
198#endif 199#endif
199 mHolidayMask = 0; 200 mHolidayMask = 0;
200 init(); 201 init();
201} 202}
202 203
203 204
204KOAgenda::~KOAgenda() 205KOAgenda::~KOAgenda()
205{ 206{
206 if(mMarcusBains) delete mMarcusBains; 207 if(mMarcusBains) delete mMarcusBains;
207 208
208} 209}
209 210
210Incidence *KOAgenda::selectedIncidence() const 211Incidence *KOAgenda::selectedIncidence() const
211{ 212{
212 return (mSelectedItem ? mSelectedItem->incidence() : 0); 213 return (mSelectedItem ? mSelectedItem->incidence() : 0);
213} 214}
214 215
215 216
216QDate KOAgenda::selectedIncidenceDate() const 217QDate KOAgenda::selectedIncidenceDate() const
217{ 218{
218 return (mSelectedItem ? mSelectedItem->itemDate() : QDate()); 219 return (mSelectedItem ? mSelectedItem->itemDate() : QDate());
219} 220}
220 221
221 222
222void KOAgenda::init() 223void KOAgenda::init()
223{ 224{
224 mPopupTimer = new QTimer(this); 225 mPopupTimer = new QTimer(this);
225 connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu())); 226 connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu()));
226 227
227 mNewItemPopup = new QPopupMenu( this ); 228 mNewItemPopup = new QPopupMenu( this );
228 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) ); 229 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) );
229 QString pathString = ""; 230 QString pathString = "";
230 if ( !KOPrefs::instance()->mToolBarMiniIcons ) { 231 if ( !KOPrefs::instance()->mToolBarMiniIcons ) {
231 if ( QApplication::desktop()->width() < 480 ) 232 if ( QApplication::desktop()->width() < 480 )
232 pathString += "icons16/"; 233 pathString += "icons16/";
233 } else 234 } else
234 pathString += "iconsmini/"; 235 pathString += "iconsmini/";
235 236
236 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 ); 237 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 );
237 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 ); 238 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 );
238 mNewItemPopup->insertSeparator ( ); 239 mNewItemPopup->insertSeparator ( );
239 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 ); 240 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 );
240 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 ); 241 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 );
241 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 ); 242 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 );
242 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 ); 243 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 );
243 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("This month"),6 ); 244 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("This month"),6 );
244 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 ); 245 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 );
245#ifndef _WIN32_ 246#ifndef _WIN32_
246 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase 247 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase
247 viewport()->setWFlags ( wflags); 248 viewport()->setWFlags ( wflags);
248#endif 249#endif
249 mGridSpacingX = 80; 250 mGridSpacingX = 80;
250 mResizeBorderWidth = 8; 251 mResizeBorderWidth = 8;
251 mScrollBorderWidth = 8; 252 mScrollBorderWidth = 8;
252 mScrollDelay = 30; 253 mScrollDelay = 30;
253 mScrollOffset = 10; 254 mScrollOffset = 10;
254 mPaintPixmap.resize( 20,20); 255 mPaintPixmap.resize( 20,20);
255 //enableClipper(true); 256 //enableClipper(true);
256 257
257 // Grab key strokes for keyboard navigation of agenda. Seems to have no 258 // Grab key strokes for keyboard navigation of agenda. Seems to have no
258 // effect. Has to be fixed. 259 // effect. Has to be fixed.
259 setFocusPolicy(WheelFocus); 260 setFocusPolicy(WheelFocus);
260 261
261 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp())); 262 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp()));
262 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown())); 263 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown()));
263 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize())); 264 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize()));
264 265
265 mStartCellX = 0; 266 mStartCellX = 0;
266 mStartCellY = 0; 267 mStartCellY = 0;
267 mCurrentCellX = 0; 268 mCurrentCellX = 0;
268 mCurrentCellY = 0; 269 mCurrentCellY = 0;
269 270
270 mSelectionCellX = 0; 271 mSelectionCellX = 0;
271 mSelectionYTop = 0; 272 mSelectionYTop = 0;
272 mSelectionHeight = 0; 273 mSelectionHeight = 0;
273 274
274 mOldLowerScrollValue = -1; 275 mOldLowerScrollValue = -1;
275 mOldUpperScrollValue = -1; 276 mOldUpperScrollValue = -1;
276 277
277 mClickedItem = 0; 278 mClickedItem = 0;
278 279
279 mActionItem = 0; 280 mActionItem = 0;
280 mActionType = NOP; 281 mActionType = NOP;
281 mItemMoved = false; 282 mItemMoved = false;
282 283
283 mSelectedItem = 0; 284 mSelectedItem = 0;
284 285
285 // mItems.setAutoDelete(true); 286 // mItems.setAutoDelete(true);
286 287
287 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 288 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
288 289
289 viewport()->update(); 290 viewport()->update();
290 291
291 setMinimumSize(30, 1); 292 setMinimumSize(30, 1);
292// setMaximumHeight(mGridSpacingY * mRows + 5); 293// setMaximumHeight(mGridSpacingY * mRows + 5);
293 294
294 // Disable horizontal scrollbar. This is a hack. The geometry should be 295 // Disable horizontal scrollbar. This is a hack. The geometry should be
295 // controlled in a way that the contents horizontally always fits. Then it is 296 // controlled in a way that the contents horizontally always fits. Then it is
296 // not necessary to turn off the scrollbar. 297 // not necessary to turn off the scrollbar.
297 setHScrollBarMode(AlwaysOff); 298 setHScrollBarMode(AlwaysOff);
298 if ( ! mAllDayMode ) 299 if ( ! mAllDayMode )
299 setVScrollBarMode(AlwaysOn); 300 setVScrollBarMode(AlwaysOn);
300 else 301 else
301 setVScrollBarMode(AlwaysOff); 302 setVScrollBarMode(AlwaysOff);
302 303
303 setStartHour(KOPrefs::instance()->mDayBegins); 304 setStartHour(KOPrefs::instance()->mDayBegins);
304 305
305 calculateWorkingHours(); 306 calculateWorkingHours();
306 307
307 connect(verticalScrollBar(),SIGNAL(valueChanged(int)), 308 connect(verticalScrollBar(),SIGNAL(valueChanged(int)),
308 SLOT(checkScrollBoundaries(int))); 309 SLOT(checkScrollBoundaries(int)));
309 310
310 // Create the Marcus Bains line. 311 // Create the Marcus Bains line.
311 if(mAllDayMode) 312 if(mAllDayMode)
312 mMarcusBains = 0; 313 mMarcusBains = 0;
313 else { 314 else {
314 mMarcusBains = new MarcusBains(this); 315 mMarcusBains = new MarcusBains(this);
315 addChild(mMarcusBains); 316 addChild(mMarcusBains);
316 } 317 }
317 mPopupKind = 0; 318 mPopupKind = 0;
318 mPopupItem = 0; 319 mPopupItem = 0;
319} 320}
320 321
321void KOAgenda::clear() 322void KOAgenda::clear()
322{ 323{
323 KOAgendaItem *item; 324 KOAgendaItem *item;
324 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 325 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
325 mUnusedItems.append( item ); 326 mUnusedItems.append( item );
326 //item->hide(); 327 //item->hide();
327 } 328 }
328 mItems.clear(); 329 mItems.clear();
329 mSelectedItem = 0; 330 mSelectedItem = 0;
330 clearSelection(); 331 clearSelection();
331} 332}
332 333
333void KOAgenda::clearSelection() 334void KOAgenda::clearSelection()
334{ 335{
335 mSelectionCellX = 0; 336 mSelectionCellX = 0;
336 mSelectionYTop = 0; 337 mSelectionYTop = 0;
337 mSelectionHeight = 0; 338 mSelectionHeight = 0;
338} 339}
339 340
340void KOAgenda::marcus_bains() 341void KOAgenda::marcus_bains()
341{ 342{
342 if(mMarcusBains) mMarcusBains->updateLocation(true); 343 if(mMarcusBains) mMarcusBains->updateLocation(true);
343} 344}
344 345
345 346
346void KOAgenda::changeColumns(int columns) 347void KOAgenda::changeColumns(int columns)
347{ 348{
348 if (columns == 0) { 349 if (columns == 0) {
349 qDebug("KOAgenda::changeColumns() called with argument 0 "); 350 qDebug("KOAgenda::changeColumns() called with argument 0 ");
350 return; 351 return;
351 } 352 }
352 clear(); 353 clear();
353 mColumns = columns; 354 mColumns = columns;
354 computeSizes(); 355 computeSizes();
355} 356}
356 357
357/* 358/*
358 This is the eventFilter function, which gets all events from the KOAgendaItems 359 This is the eventFilter function, which gets all events from the KOAgendaItems
359 contained in the agenda. It has to handle moving and resizing for all items. 360 contained in the agenda. It has to handle moving and resizing for all items.
360*/ 361*/
361bool KOAgenda::eventFilter ( QObject *object, QEvent *event ) 362bool KOAgenda::eventFilter ( QObject *object, QEvent *event )
362{ 363{
363 // kdDebug() << "KOAgenda::eventFilter" << endl; 364 // kdDebug() << "KOAgenda::eventFilter" << endl;
364 switch(event->type()) { 365 switch(event->type()) {
365 case QEvent::MouseButtonPress: 366 case QEvent::MouseButtonPress:
366 case QEvent::MouseButtonDblClick: 367 case QEvent::MouseButtonDblClick:
367 case QEvent::MouseButtonRelease: 368 case QEvent::MouseButtonRelease:
368 case QEvent::MouseMove: 369 case QEvent::MouseMove:
369 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event)); 370 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event));
370 371
371 case (QEvent::Leave): 372 case (QEvent::Leave):
372 if (!mActionItem) 373 if (!mActionItem)
373 setCursor(arrowCursor); 374 setCursor(arrowCursor);
374 return true; 375 return true;
375 376
376 default: 377 default:
377 return QScrollView::eventFilter(object,event); 378 return QScrollView::eventFilter(object,event);
378 } 379 }
379} 380}
380void KOAgenda::popupMenu() 381void KOAgenda::popupMenu()
381{ 382{
382 mPopupTimer->stop(); 383 mPopupTimer->stop();
383 if ( mPopupKind == 1 ) { 384 if ( mPopupKind == 1 ) {
384 if (mActionItem ) { 385 if (mActionItem ) {
385 endItemAction(); 386 endItemAction();
386 } 387 }
387 mLeftMouseDown = false; // no more leftMouse computation 388 mLeftMouseDown = false; // no more leftMouse computation
388 if (mPopupItem) { 389 if (mPopupItem) {
389 selectItem(mPopupItem); 390 selectItem(mPopupItem);
391 if ( mAllAgendaPopup )
392 mAllAgendaPopup->installEventFilter( this );
390 emit showIncidencePopupSignal(mPopupItem->incidence()); 393 emit showIncidencePopupSignal(mPopupItem->incidence());
391 394
392 } 395 }
393 } else if ( mPopupKind == 2 ) { 396 } else if ( mPopupKind == 2 ) {
394 if ( mLeftMouseDown ) { // we have a simulated right click - clear left mouse action 397 if ( mLeftMouseDown ) { // we have a simulated right click - clear left mouse action
395 endSelectAction( false ); // do not emit new event signal 398 endSelectAction( false ); // do not emit new event signal
396 mLeftMouseDown = false; // no more leftMouse computation 399 mLeftMouseDown = false; // no more leftMouse computation
397 } 400 }
401 mNewItemPopup->installEventFilter( this );
398 mNewItemPopup->popup( mPopupPos); 402 mNewItemPopup->popup( mPopupPos);
403
399 } 404 }
400 mLeftMouseDown = false; 405 mLeftMouseDown = false;
401 mPopupItem = 0; 406 mPopupItem = 0;
402 mPopupKind = 0; 407 mPopupKind = 0;
403} 408}
404 409
405bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) 410bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me)
406{ 411{
407 //qDebug("KOAgenda::eventFilter_mous "); 412 static int startX = 0;
413 static int startY = 0;
414 static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 );
415 static bool blockMoving = true;
416
417 //qDebug("KOAgenda::eventFilter_mous ");
418 if ( object == mNewItemPopup ) {
419 //qDebug("mNewItemPopup ");
420 if ( me->type() == QEvent::MouseButtonRelease ) {
421 mNewItemPopup->removeEventFilter( this );
422 int dX = me->globalPos().x() - mPopupPos.x();;
423 if ( dX < 0 )
424 dX = -dX;
425 int dY = me->globalPos().y() - mPopupPos.y();
426 if ( dY < 0 )
427 dY = -dY;
428 if ( dX > blockmoveDist || dY > blockmoveDist ) {
429 mNewItemPopup->hide();
430 }
431 }
432 return true;
433 }
434 if ( object == mAllAgendaPopup ) {
435 //qDebug(" mAllAgendaPopup ");
436 if ( me->type() == QEvent::MouseButtonRelease ) {
437 mAllAgendaPopup->removeEventFilter( this );
438 int dX = me->globalPos().x() - mPopupPos.x();;
439 if ( dX < 0 )
440 dX = -dX;
441 int dY = me->globalPos().y() - mPopupPos.y();
442 if ( dY < 0 )
443 dY = -dY;
444 if ( dX > blockmoveDist || dY > blockmoveDist ) {
445 mAllAgendaPopup->hide();
446 }
447 }
448 return true;
449 }
408 QPoint viewportPos; 450 QPoint viewportPos;
409 if (object != viewport()) { 451 if (object != viewport()) {
410 viewportPos = ((QWidget *)object)->mapToParent(me->pos()); 452 viewportPos = ((QWidget *)object)->mapToParent(me->pos());
411 } else { 453 } else {
412 viewportPos = me->pos(); 454 viewportPos = me->pos();
413 } 455 }
414 static int startX = 0; 456
415 static int startY = 0;
416 static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 );
417 static bool blockMoving = true;
418 switch (me->type()) { 457 switch (me->type()) {
419 case QEvent::MouseButtonPress: 458 case QEvent::MouseButtonPress:
420 if (me->button() == LeftButton) { 459 if (me->button() == LeftButton) {
421 mPopupTimer->start( 600 ); 460 mPopupTimer->start( 600 );
422 mLeftMouseDown = true; 461 mLeftMouseDown = true;
423 } 462 }
424 blockMoving = true; 463 blockMoving = true;
425 startX = viewportPos.x(); 464 startX = viewportPos.x();
426 startY = viewportPos.y(); 465 startY = viewportPos.y();
466 mPopupPos = me->globalPos();
427 if (object != viewport()) { 467 if (object != viewport()) {
428 mPopupItem = (KOAgendaItem *)object; 468 mPopupItem = (KOAgendaItem *)object;
429 mPopupKind = 1; 469 mPopupKind = 1;
430 if (me->button() == RightButton) { 470 if (me->button() == RightButton) {
431 popupMenu(); 471 popupMenu();
432 } else if (me->button() == LeftButton) { 472 } else if (me->button() == LeftButton) {
433 mActionItem = (KOAgendaItem *)object; 473 mActionItem = (KOAgendaItem *)object;
434 if (mActionItem) { 474 if (mActionItem) {
435 if ( mSelectionHeight > 0 ) { 475 if ( mSelectionHeight > 0 ) {
436 int selectionCellX = mSelectionCellX * mGridSpacingX; 476 int selectionCellX = mSelectionCellX * mGridSpacingX;
437 int selectionYTop = mSelectionYTop; 477 int selectionYTop = mSelectionYTop;
438 int gridSpacingX = mGridSpacingX; 478 int gridSpacingX = mGridSpacingX;
439 int selectionHeight = mSelectionHeight; 479 int selectionHeight = mSelectionHeight;
440 clearSelection(); 480 clearSelection();
441 repaintContents( selectionCellX, selectionYTop, 481 repaintContents( selectionCellX, selectionYTop,
442 gridSpacingX, selectionHeight,false ); 482 gridSpacingX, selectionHeight,false );
443 } 483 }
444 selectItem(mActionItem); 484 selectItem(mActionItem);
445 Incidence *incidence = mActionItem->incidence(); 485 Incidence *incidence = mActionItem->incidence();
446 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { 486 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) {
447 mActionItem = 0; 487 mActionItem = 0;
448 } else { 488 } else {
449 startItemAction(viewportPos); 489 startItemAction(viewportPos);
450 } 490 }
451 } 491 }
452 } 492 }
453 } else { // ---------- viewport() 493 } else { // ---------- viewport()
454 mPopupItem = 0; 494 mPopupItem = 0;
455 mPopupKind = 2; 495 mPopupKind = 2;
456 selectItem(0); 496 selectItem(0);
457 mActionItem = 0; 497 mActionItem = 0;
458 mPopupPos = viewport()->mapToGlobal( me->pos() );
459 if (me->button() == RightButton) { 498 if (me->button() == RightButton) {
460 int x,y; 499 int x,y;
461 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 500 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
462 int gx,gy; 501 int gx,gy;
463 contentsToGrid(x,y,gx,gy); 502 contentsToGrid(x,y,gx,gy);
464 mCurrentCellX = gx; 503 mCurrentCellX = gx;
465 mCurrentCellY = gy; 504 mCurrentCellY = gy;
466 mStartCellX = gx; 505 mStartCellX = gx;
467 mStartCellY = gy; 506 mStartCellY = gy;
468 popupMenu(); 507 popupMenu();
469 } else if (me->button() == LeftButton) { 508 } else if (me->button() == LeftButton) {
470 setCursor(arrowCursor); 509 setCursor(arrowCursor);
471 startSelectAction(viewportPos); 510 startSelectAction(viewportPos);
472 } 511 }
473 } 512 }
474 break; 513 break;
475 514
476 case QEvent::MouseButtonRelease: 515 case QEvent::MouseButtonRelease:
477 if (me->button() == LeftButton ) { 516 if (me->button() == LeftButton ) {
478 mPopupTimer->stop(); 517 mPopupTimer->stop();
479 } 518 }
480 if (object != viewport()) { 519 if (object != viewport()) {
481 if (me->button() == LeftButton && mLeftMouseDown) { 520 if (me->button() == LeftButton && mLeftMouseDown) {
482 if (mActionItem) { 521 if (mActionItem) {
483 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 522 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos));
484 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); 523 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 );
485 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { 524 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) {
486 mScrollUpTimer.stop(); 525 mScrollUpTimer.stop();
487 mScrollDownTimer.stop(); 526 mScrollDownTimer.stop();
488 mActionItem->resetMove(); 527 mActionItem->resetMove();
489 placeSubCells( mActionItem ); 528 placeSubCells( mActionItem );
490 // emit startDragSignal( mActionItem->incidence() ); 529 // emit startDragSignal( mActionItem->incidence() );
491 setCursor( arrowCursor ); 530 setCursor( arrowCursor );
492 mActionItem = 0; 531 mActionItem = 0;
493 mActionType = NOP; 532 mActionType = NOP;
494 mItemMoved = 0; 533 mItemMoved = 0;
495 mLeftMouseDown = false; 534 mLeftMouseDown = false;
496 return true; 535 return true;
497 } 536 }
498 endItemAction(); 537 endItemAction();
499 } 538 }
500 } 539 }
501 540
502 } else { // ---------- viewport() 541 } else { // ---------- viewport()
503 if (me->button() == LeftButton && mLeftMouseDown ) { //left click 542 if (me->button() == LeftButton && mLeftMouseDown ) { //left click
504 endSelectAction( true ); // emit new event signal 543 endSelectAction( true ); // emit new event signal
505 } 544 }
506 } 545 }
507 if (me->button() == LeftButton) 546 if (me->button() == LeftButton)
508 mLeftMouseDown = false; 547 mLeftMouseDown = false;
509 548
510 break; 549 break;
511 550
512 case QEvent::MouseMove: 551 case QEvent::MouseMove:
513 //qDebug("mm "); 552 //qDebug("mm ");
514 if ( !mLeftMouseDown ) 553 if ( !mLeftMouseDown )
515 return false; 554 return false;
516 if ( blockMoving ) { 555 if ( blockMoving ) {
517 int dX, dY; 556 int dX, dY;
518 dX = startX - viewportPos.x(); 557 dX = startX - viewportPos.x();
519 if ( dX < 0 ) 558 if ( dX < 0 )
520 dX = -dX; 559 dX = -dX;
521 dY = viewportPos.y() - startY; 560 dY = viewportPos.y() - startY;
522 if ( dY < 0 ) 561 if ( dY < 0 )
523 dY = -dY; 562 dY = -dY;
524 //qDebug("%d %d %d ", dX, dY , blockmoveDist ); 563 //qDebug("%d %d %d ", dX, dY , blockmoveDist );
525 if ( dX > blockmoveDist || dY > blockmoveDist ) { 564 if ( dX > blockmoveDist || dY > blockmoveDist ) {
526 blockMoving = false; 565 blockMoving = false;
527 } 566 }
528 } 567 }
529 if ( ! blockMoving ) 568 if ( ! blockMoving )
530 mPopupTimer->stop(); 569 mPopupTimer->stop();
531 if (object != viewport()) { 570 if (object != viewport()) {
532 KOAgendaItem *moveItem = (KOAgendaItem *)object; 571 KOAgendaItem *moveItem = (KOAgendaItem *)object;
533 if (!moveItem->incidence()->isReadOnly() ) { 572 if (!moveItem->incidence()->isReadOnly() ) {
534 if (!mActionItem) 573 if (!mActionItem)
535 setNoActionCursor(moveItem,viewportPos); 574 setNoActionCursor(moveItem,viewportPos);
536 else { 575 else {
537 if ( !blockMoving ) 576 if ( !blockMoving )
538 performItemAction(viewportPos); 577 performItemAction(viewportPos);
539 } 578 }
540 } 579 }
541 } else { // ---------- viewport() 580 } else { // ---------- viewport()
542 mPopupPos = viewport()->mapToGlobal( me->pos() ); 581 mPopupPos = viewport()->mapToGlobal( me->pos() );
543 if ( mActionType == SELECT ) { 582 if ( mActionType == SELECT ) {
544 performSelectAction( viewportPos ); 583 performSelectAction( viewportPos );
545 } 584 }
546 } 585 }
547 break; 586 break;
548 587
549 case QEvent::MouseButtonDblClick: 588 case QEvent::MouseButtonDblClick:
550 mPopupTimer->stop(); 589 mPopupTimer->stop();
551 if (object == viewport()) { 590 if (object == viewport()) {
552 selectItem(0); 591 selectItem(0);
553 int x,y; 592 int x,y;
554 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 593 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
555 int gx,gy; 594 int gx,gy;
556 contentsToGrid(x,y,gx,gy); 595 contentsToGrid(x,y,gx,gy);
557 emit newEventSignal(gx,gy); 596 emit newEventSignal(gx,gy);
558 } else { 597 } else {
559 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; 598 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object;
560 selectItem(doubleClickedItem); 599 selectItem(doubleClickedItem);
561 if ( KOPrefs::instance()->mEditOnDoubleClick ) 600 if ( KOPrefs::instance()->mEditOnDoubleClick )
562 emit editIncidenceSignal(doubleClickedItem->incidence()); 601 emit editIncidenceSignal(doubleClickedItem->incidence());
563 else 602 else
564 emit showIncidenceSignal(doubleClickedItem->incidence()); 603 emit showIncidenceSignal(doubleClickedItem->incidence());
565 } 604 }
566 break; 605 break;
567 606
568 default: 607 default:
569 break; 608 break;
570 } 609 }
571 return true; 610 return true;
572#if 0 611#if 0
573 //qDebug("KOAgenda::eventFilter_mous "); 612 //qDebug("KOAgenda::eventFilter_mous ");
574 QPoint viewportPos; 613 QPoint viewportPos;
575 if (object != viewport()) { 614 if (object != viewport()) {
576 viewportPos = ((QWidget *)object)->mapToParent(me->pos()); 615 viewportPos = ((QWidget *)object)->mapToParent(me->pos());
577 } else { 616 } else {
578 viewportPos = me->pos(); 617 viewportPos = me->pos();
579 } 618 }
580 static int startX = 0; 619 static int startX = 0;
581 static int startY = 0; 620 static int startY = 0;
582 static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 ); 621 static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 );
583 static bool blockMoving = true; 622 static bool blockMoving = true;
584 static bool leftMouseDown = false; 623 static bool leftMouseDown = false;
585 bool rightButtonPressed = false; 624 bool rightButtonPressed = false;
586 switch (me->type()) { 625 switch (me->type()) {
587 case QEvent::MouseButtonPress: 626 case QEvent::MouseButtonPress:
588 if (me->button() == LeftButton) { 627 if (me->button() == LeftButton) {
589 leftMouseDown = true; 628 leftMouseDown = true;
590 } 629 }
591 else if (me->button() == RightButton) { 630 else if (me->button() == RightButton) {
592 leftMouseDown = false; 631 leftMouseDown = false;
593 } 632 }
594 blockMoving = true; 633 blockMoving = true;
595 startX = viewportPos.x(); 634 startX = viewportPos.x();
596 startY = viewportPos.y(); 635 startY = viewportPos.y();
597 if (object != viewport()) { // item clicked ************** 636 if (object != viewport()) { // item clicked **************
598 if (me->button() == RightButton) { 637 if (me->button() == RightButton) {
599 leftMouseDown = false; 638 leftMouseDown = false;
600 mClickedItem = (KOAgendaItem *)object; 639 mClickedItem = (KOAgendaItem *)object;
601 if (mActionItem ) { 640 if (mActionItem ) {
602 endItemAction(); 641 endItemAction();
603 } 642 }
604 if (mClickedItem) { 643 if (mClickedItem) {
605 selectItem(mClickedItem); 644 selectItem(mClickedItem);
606 emit showIncidencePopupSignal(mClickedItem->incidence()); 645 emit showIncidencePopupSignal(mClickedItem->incidence());
607 } 646 }
608 return true; 647 return true;
609 } else if (me->button() == LeftButton) { 648 } else if (me->button() == LeftButton) {
610 mActionItem = (KOAgendaItem *)object; 649 mActionItem = (KOAgendaItem *)object;
611 if (mActionItem) { 650 if (mActionItem) {
612 if ( mSelectionHeight > 0 ) { 651 if ( mSelectionHeight > 0 ) {
613 int selectionCellX = mSelectionCellX * mGridSpacingX; 652 int selectionCellX = mSelectionCellX * mGridSpacingX;
614 int selectionYTop = mSelectionYTop; 653 int selectionYTop = mSelectionYTop;
615 int gridSpacingX = mGridSpacingX; 654 int gridSpacingX = mGridSpacingX;
616 int selectionHeight = mSelectionHeight; 655 int selectionHeight = mSelectionHeight;
617 clearSelection(); 656 clearSelection();
618 repaintContents( selectionCellX, selectionYTop, 657 repaintContents( selectionCellX, selectionYTop,
619 gridSpacingX, selectionHeight,false ); 658 gridSpacingX, selectionHeight,false );
620 } 659 }
621 selectItem(mActionItem); 660 selectItem(mActionItem);
622 Incidence *incidence = mActionItem->incidence(); 661 Incidence *incidence = mActionItem->incidence();
623 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { 662 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) {
624 mActionItem = 0; 663 mActionItem = 0;
625 } else { 664 } else {
626 startItemAction(viewportPos); 665 startItemAction(viewportPos);
627 } 666 }
628 } 667 }
629 } 668 }
630 } else { // ---------- viewport() 669 } else { // ---------- viewport()
631 selectItem(0); 670 selectItem(0);
632 mActionItem = 0; 671 mActionItem = 0;
633 if (me->button() == LeftButton ) { 672 if (me->button() == LeftButton ) {
634 setCursor(arrowCursor); 673 setCursor(arrowCursor);
635 startSelectAction(viewportPos); 674 startSelectAction(viewportPos);
636 } else if (me->button() == RightButton ) { 675 } else if (me->button() == RightButton ) {
637 setCursor(arrowCursor); 676 setCursor(arrowCursor);
638 if ( leftMouseDown ) { // we have a simulated right click - clear left mouse action 677 if ( leftMouseDown ) { // we have a simulated right click - clear left mouse action
639 endSelectAction( false ); // do not emit new event signal 678 endSelectAction( false ); // do not emit new event signal
640 leftMouseDown = false; // no more leftMouse computation 679 leftMouseDown = false; // no more leftMouse computation
641 } 680 }
642 int x,y; 681 int x,y;
643 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 682 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
644 int gx,gy; 683 int gx,gy;
645 contentsToGrid(x,y,gx,gy); 684 contentsToGrid(x,y,gx,gy);
646 mCurrentCellX = gx; 685 mCurrentCellX = gx;
647 mCurrentCellY = gy; 686 mCurrentCellY = gy;
648 mStartCellX = gx; 687 mStartCellX = gx;
649 mStartCellY = gy; 688 mStartCellY = gy;
650 mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) ); 689 mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) );
651 } 690 }
652 } 691 }
653 break; 692 break;
654 693
655 case QEvent::MouseButtonRelease: 694 case QEvent::MouseButtonRelease:
656 695
657 if (object != viewport()) { 696 if (object != viewport()) {
658 if (me->button() == LeftButton && leftMouseDown) { 697 if (me->button() == LeftButton && leftMouseDown) {
659 if (mActionItem) { 698 if (mActionItem) {
660 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 699 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos));
661 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); 700 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 );
662 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { 701 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) {
663 mScrollUpTimer.stop(); 702 mScrollUpTimer.stop();
664 mScrollDownTimer.stop(); 703 mScrollDownTimer.stop();
665 mActionItem->resetMove(); 704 mActionItem->resetMove();
666 placeSubCells( mActionItem ); 705 placeSubCells( mActionItem );
667 // emit startDragSignal( mActionItem->incidence() ); 706 // emit startDragSignal( mActionItem->incidence() );
668 setCursor( arrowCursor ); 707 setCursor( arrowCursor );
669 mActionItem = 0; 708 mActionItem = 0;
670 mActionType = NOP; 709 mActionType = NOP;
671 mItemMoved = 0; 710 mItemMoved = 0;
672 leftMouseDown = false; 711 leftMouseDown = false;
673 return true; 712 return true;
674 } 713 }
675 endItemAction(); 714 endItemAction();
676 } 715 }
677 } 716 }
678 717
679 } else { // ---------- viewport() 718 } else { // ---------- viewport()
680 if (me->button() == LeftButton && leftMouseDown ) { //left click 719 if (me->button() == LeftButton && leftMouseDown ) { //left click
681 endSelectAction( true ); // emit new event signal 720 endSelectAction( true ); // emit new event signal
682 } 721 }
683 } 722 }
684 if (me->button() == LeftButton) 723 if (me->button() == LeftButton)
685 leftMouseDown = false; 724 leftMouseDown = false;
686 725
687 break; 726 break;
688 727
689 case QEvent::MouseMove: 728 case QEvent::MouseMove:
690 if ( !leftMouseDown ) 729 if ( !leftMouseDown )
691 return true; 730 return true;
692 if ( blockMoving ) { 731 if ( blockMoving ) {
693 int dX, dY; 732 int dX, dY;
694 dX = startX - viewportPos.x(); 733 dX = startX - viewportPos.x();
695 if ( dX < 0 ) 734 if ( dX < 0 )
696 dX = -dX; 735 dX = -dX;
697 dY = viewportPos.y() - startY; 736 dY = viewportPos.y() - startY;
698 if ( dY < 0 ) 737 if ( dY < 0 )
699 dY = -dY; 738 dY = -dY;
700 //qDebug("%d %d %d ", dX, dY , blockmoveDist ); 739 //qDebug("%d %d %d ", dX, dY , blockmoveDist );
701 if ( dX > blockmoveDist || dY > blockmoveDist ) { 740 if ( dX > blockmoveDist || dY > blockmoveDist ) {
702 blockMoving = false; 741 blockMoving = false;
703 } 742 }
704 } 743 }
705 if (object != viewport()) { 744 if (object != viewport()) {
706 KOAgendaItem *moveItem = (KOAgendaItem *)object; 745 KOAgendaItem *moveItem = (KOAgendaItem *)object;
707 if (!moveItem->incidence()->isReadOnly() ) { 746 if (!moveItem->incidence()->isReadOnly() ) {
708 if (!mActionItem) 747 if (!mActionItem)
709 setNoActionCursor(moveItem,viewportPos); 748 setNoActionCursor(moveItem,viewportPos);
710 else { 749 else {
711 if ( !blockMoving ) 750 if ( !blockMoving )
712 performItemAction(viewportPos); 751 performItemAction(viewportPos);
713 } 752 }
714 } 753 }
715 } else { // ---------- viewport() 754 } else { // ---------- viewport()
716 if ( mActionType == SELECT ) { 755 if ( mActionType == SELECT ) {
717 performSelectAction( viewportPos ); 756 performSelectAction( viewportPos );
718 } 757 }
719 } 758 }
720 break; 759 break;
721 760
722 case QEvent::MouseButtonDblClick: 761 case QEvent::MouseButtonDblClick:
723 blockMoving = false; 762 blockMoving = false;
724 leftMouseDown = false; 763 leftMouseDown = false;
725 if (object == viewport()) { 764 if (object == viewport()) {
726 selectItem(0); 765 selectItem(0);
727 int x,y; 766 int x,y;
728 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 767 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
729 int gx,gy; 768 int gx,gy;
730 contentsToGrid(x,y,gx,gy); 769 contentsToGrid(x,y,gx,gy);
731 emit newEventSignal(gx,gy); 770 emit newEventSignal(gx,gy);
732 } else { 771 } else {
733 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; 772 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object;
734 selectItem(doubleClickedItem); 773 selectItem(doubleClickedItem);
735 if ( KOPrefs::instance()->mEditOnDoubleClick ) 774 if ( KOPrefs::instance()->mEditOnDoubleClick )
736 emit editIncidenceSignal(doubleClickedItem->incidence()); 775 emit editIncidenceSignal(doubleClickedItem->incidence());
737 else 776 else
738 emit showIncidenceSignal(doubleClickedItem->incidence()); 777 emit showIncidenceSignal(doubleClickedItem->incidence());
739 } 778 }
740 break; 779 break;
741 780
742 default: 781 default:
743 break; 782 break;
744 } 783 }
745 return true; 784 return true;
746#endif 785#endif
747} 786}
748 787
749void KOAgenda::newItem( int item ) 788void KOAgenda::newItem( int item )
750{ 789{
751 if ( item == 1 ) { //new event 790 if ( item == 1 ) { //new event
752 newEventSignal(mStartCellX ,mStartCellY ); 791 newEventSignal(mStartCellX ,mStartCellY );
753 } else 792 } else
754 if ( item == 2 ) { //new event 793 if ( item == 2 ) { //new event
755 newTodoSignal(mStartCellX ,mStartCellY ); 794 newTodoSignal(mStartCellX ,mStartCellY );
756 } else 795 } else
757 { 796 {
758 emit showDateView( item, mStartCellX ); 797 emit showDateView( item, mStartCellX );
759 // 3Day view 798 // 3Day view
760 // 4Week view 799 // 4Week view
761 // 5Month view 800 // 5Month view
762 // 6Journal view 801 // 6Journal view
763 } 802 }
764} 803}
765void KOAgenda::startSelectAction(QPoint viewportPos) 804void KOAgenda::startSelectAction(QPoint viewportPos)
766{ 805{
767 //emit newStartSelectSignal(); 806 //emit newStartSelectSignal();
768 807
769 mActionType = SELECT; 808 mActionType = SELECT;
770 809
771 int x,y; 810 int x,y;
772 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 811 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
773 int gx,gy; 812 int gx,gy;
774 contentsToGrid(x,y,gx,gy); 813 contentsToGrid(x,y,gx,gy);
775 814
776 mStartCellX = gx; 815 mStartCellX = gx;
777 mStartCellY = gy; 816 mStartCellY = gy;
778 mCurrentCellX = gx; 817 mCurrentCellX = gx;
779 mCurrentCellY = gy; 818 mCurrentCellY = gy;
780 819
781 // Store coordinates of old selection 820 // Store coordinates of old selection
782 int selectionX = mSelectionCellX * mGridSpacingX; 821 int selectionX = mSelectionCellX * mGridSpacingX;
783 int selectionYTop = mSelectionYTop; 822 int selectionYTop = mSelectionYTop;
784 int selectionHeight = mSelectionHeight; 823 int selectionHeight = mSelectionHeight;
785 824
786 // Store new selection 825 // Store new selection
787 mSelectionCellX = gx; 826 mSelectionCellX = gx;
788 mSelectionYTop = gy * mGridSpacingY; 827 mSelectionYTop = gy * mGridSpacingY;
789 mSelectionHeight = mGridSpacingY; 828 mSelectionHeight = mGridSpacingY;
790 829
791 // Clear old selection 830 // Clear old selection
792 repaintContents( selectionX, selectionYTop, 831 repaintContents( selectionX, selectionYTop,
793 mGridSpacingX, selectionHeight,false ); 832 mGridSpacingX, selectionHeight,false );
794 833
795 // Paint new selection 834 // Paint new selection
796 // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop, 835 // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop,
797 // mGridSpacingX, mSelectionHeight ); 836 // mGridSpacingX, mSelectionHeight );
798} 837}
799 838
800void KOAgenda::performSelectAction(QPoint viewportPos) 839void KOAgenda::performSelectAction(QPoint viewportPos)
801{ 840{
802 int x,y; 841 int x,y;
803 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 842 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
804 int gx,gy; 843 int gx,gy;
805 contentsToGrid(x,y,gx,gy); 844 contentsToGrid(x,y,gx,gy);
806 845
807 QPoint clipperPos = clipper()-> 846 QPoint clipperPos = clipper()->
808 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 847 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
809 848
810 // Scroll if cursor was moved to upper or lower end of agenda. 849 // Scroll if cursor was moved to upper or lower end of agenda.
811 if (clipperPos.y() < mScrollBorderWidth) { 850 if (clipperPos.y() < mScrollBorderWidth) {
812 mScrollUpTimer.start(mScrollDelay); 851 mScrollUpTimer.start(mScrollDelay);
813 } else if (visibleHeight() - clipperPos.y() < 852 } else if (visibleHeight() - clipperPos.y() <
814 mScrollBorderWidth) { 853 mScrollBorderWidth) {
815 mScrollDownTimer.start(mScrollDelay); 854 mScrollDownTimer.start(mScrollDelay);
816 } else { 855 } else {
817 mScrollUpTimer.stop(); 856 mScrollUpTimer.stop();
818 mScrollDownTimer.stop(); 857 mScrollDownTimer.stop();
819 } 858 }
820 859
821 if ( gy > mCurrentCellY ) { 860 if ( gy > mCurrentCellY ) {
822 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 861 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
823 862
824#if 0 863#if 0
825 // FIXME: Repaint only the newly selected region 864 // FIXME: Repaint only the newly selected region
826 repaintContents( mSelectionCellX * mGridSpacingX, 865 repaintContents( mSelectionCellX * mGridSpacingX,
827 mCurrentCellY + mGridSpacingY, 866 mCurrentCellY + mGridSpacingY,
828 mGridSpacingX, 867 mGridSpacingX,
829 mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY ); 868 mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY );
830#else 869#else
831 repaintContents( (KOGlobals::self()->reverseLayout() ? 870 repaintContents( (KOGlobals::self()->reverseLayout() ?
832 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 871 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
833 mGridSpacingX, mSelectionYTop, 872 mGridSpacingX, mSelectionYTop,
834 mGridSpacingX, mSelectionHeight , false); 873 mGridSpacingX, mSelectionHeight , false);
835#endif 874#endif
836 875
837 mCurrentCellY = gy; 876 mCurrentCellY = gy;
838 } else if ( gy < mCurrentCellY ) { 877 } else if ( gy < mCurrentCellY ) {
839 if ( gy >= mStartCellY ) { 878 if ( gy >= mStartCellY ) {
840 int selectionHeight = mSelectionHeight; 879 int selectionHeight = mSelectionHeight;
841 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 880 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
842 881
843 repaintContents( (KOGlobals::self()->reverseLayout() ? 882 repaintContents( (KOGlobals::self()->reverseLayout() ?
844 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 883 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
845 mGridSpacingX, mSelectionYTop, 884 mGridSpacingX, mSelectionYTop,
846 mGridSpacingX, selectionHeight,false ); 885 mGridSpacingX, selectionHeight,false );
847 886
848 mCurrentCellY = gy; 887 mCurrentCellY = gy;
849 } else { 888 } else {
850 } 889 }
851 } 890 }
852} 891}
853 892
854void KOAgenda::endSelectAction( bool emitNewEvent ) 893void KOAgenda::endSelectAction( bool emitNewEvent )
855{ 894{
856 mActionType = NOP; 895 mActionType = NOP;
857 mScrollUpTimer.stop(); 896 mScrollUpTimer.stop();
858 mScrollDownTimer.stop(); 897 mScrollDownTimer.stop();
859 898
860 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); 899 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
861 if ( emitNewEvent && mStartCellY < mCurrentCellY ) { 900 if ( emitNewEvent && mStartCellY < mCurrentCellY ) {
862 qDebug("ew event signal "); 901 qDebug("ew event signal ");
863 emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); 902 emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
864 } 903 }
865} 904}
866 905
867void KOAgenda::startItemAction(QPoint viewportPos) 906void KOAgenda::startItemAction(QPoint viewportPos)
868{ 907{
869 int x,y; 908 int x,y;
870 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 909 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
871 int gx,gy; 910 int gx,gy;
872 contentsToGrid(x,y,gx,gy); 911 contentsToGrid(x,y,gx,gy);
873 912
874 mStartCellX = gx; 913 mStartCellX = gx;
875 mStartCellY = gy; 914 mStartCellY = gy;
876 mCurrentCellX = gx; 915 mCurrentCellX = gx;
877 mCurrentCellY = gy; 916 mCurrentCellY = gy;
878 917
879 if (mAllDayMode) { 918 if (mAllDayMode) {
880 int gridDistanceX = (x - gx * mGridSpacingX); 919 int gridDistanceX = (x - gx * mGridSpacingX);
881 if (gridDistanceX < mResizeBorderWidth && 920 if (gridDistanceX < mResizeBorderWidth &&
882 mActionItem->cellX() == mCurrentCellX) { 921 mActionItem->cellX() == mCurrentCellX) {
883 mActionType = RESIZELEFT; 922 mActionType = RESIZELEFT;
884 setCursor(sizeHorCursor); 923 setCursor(sizeHorCursor);
885 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 924 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
886 mActionItem->cellXWidth() == mCurrentCellX) { 925 mActionItem->cellXWidth() == mCurrentCellX) {
887 mActionType = RESIZERIGHT; 926 mActionType = RESIZERIGHT;
888 setCursor(sizeHorCursor); 927 setCursor(sizeHorCursor);
889 } else { 928 } else {
890 mActionType = MOVE; 929 mActionType = MOVE;
891 mActionItem->startMove(); 930 mActionItem->startMove();
892 setCursor(sizeAllCursor); 931 setCursor(sizeAllCursor);
893 } 932 }
894 } else { 933 } else {
895 int gridDistanceY = (y - gy * mGridSpacingY); 934 int gridDistanceY = (y - gy * mGridSpacingY);
896 bool allowResize = ( mActionItem->incidence()->type() != "Todo" ); 935 bool allowResize = ( mActionItem->incidence()->type() != "Todo" );
897 if (allowResize && gridDistanceY < mResizeBorderWidth && 936 if (allowResize && gridDistanceY < mResizeBorderWidth &&
898 mActionItem->cellYTop() == mCurrentCellY && 937 mActionItem->cellYTop() == mCurrentCellY &&
899 !mActionItem->firstMultiItem()) { 938 !mActionItem->firstMultiItem()) {
900 mActionType = RESIZETOP; 939 mActionType = RESIZETOP;
901 setCursor(sizeVerCursor); 940 setCursor(sizeVerCursor);
902 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 941 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
903 mActionItem->cellYBottom() == mCurrentCellY && 942 mActionItem->cellYBottom() == mCurrentCellY &&
904 !mActionItem->lastMultiItem()) { 943 !mActionItem->lastMultiItem()) {
905 mActionType = RESIZEBOTTOM; 944 mActionType = RESIZEBOTTOM;
906 setCursor(sizeVerCursor); 945 setCursor(sizeVerCursor);
907 } else { 946 } else {
908 mActionType = MOVE; 947 mActionType = MOVE;
909 mActionItem->startMove(); 948 mActionItem->startMove();
910 setCursor(sizeAllCursor); 949 setCursor(sizeAllCursor);
911 } 950 }
912 } 951 }
913} 952}
914 953
915void KOAgenda::performItemAction(QPoint viewportPos) 954void KOAgenda::performItemAction(QPoint viewportPos)
916{ 955{
917// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 956// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
918// QPoint point = viewport()->mapToGlobal(viewportPos); 957// QPoint point = viewport()->mapToGlobal(viewportPos);
919// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 958// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
920// point = clipper()->mapFromGlobal(point); 959// point = clipper()->mapFromGlobal(point);
921// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 960// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
922// kdDebug() << "visible height: " << visibleHeight() << endl; 961// kdDebug() << "visible height: " << visibleHeight() << endl;
923 int x,y; 962 int x,y;
924 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 963 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
925// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 964// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
926 int gx,gy; 965 int gx,gy;
927 contentsToGrid(x,y,gx,gy); 966 contentsToGrid(x,y,gx,gy);
928 QPoint clipperPos = clipper()-> 967 QPoint clipperPos = clipper()->
929 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 968 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
930 969
931 // Cursor left active agenda area. 970 // Cursor left active agenda area.
932 // This starts a drag. 971 // This starts a drag.
933 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/ 972 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/
934 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) { 973 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) {
935 if ( mActionType == MOVE ) { 974 if ( mActionType == MOVE ) {
936 mScrollUpTimer.stop(); 975 mScrollUpTimer.stop();
937 mScrollDownTimer.stop(); 976 mScrollDownTimer.stop();
938 mActionItem->resetMove(); 977 mActionItem->resetMove();
939 placeSubCells( mActionItem ); 978 placeSubCells( mActionItem );
940 // emit startDragSignal( mActionItem->incidence() ); 979 // emit startDragSignal( mActionItem->incidence() );
941 setCursor( arrowCursor ); 980 setCursor( arrowCursor );
942 mActionItem = 0; 981 mActionItem = 0;
943 mActionType = NOP; 982 mActionType = NOP;
944 mItemMoved = 0; 983 mItemMoved = 0;
945 return; 984 return;
946 } 985 }
947 } else { 986 } else {
948 switch ( mActionType ) { 987 switch ( mActionType ) {
949 case MOVE: 988 case MOVE:
950 setCursor( sizeAllCursor ); 989 setCursor( sizeAllCursor );
951 break; 990 break;
952 case RESIZETOP: 991 case RESIZETOP:
953 case RESIZEBOTTOM: 992 case RESIZEBOTTOM:
954 setCursor( sizeVerCursor ); 993 setCursor( sizeVerCursor );
955 break; 994 break;
956 case RESIZELEFT: 995 case RESIZELEFT:
957 case RESIZERIGHT: 996 case RESIZERIGHT:
958 setCursor( sizeHorCursor ); 997 setCursor( sizeHorCursor );
959 break; 998 break;
960 default: 999 default:
961 setCursor( arrowCursor ); 1000 setCursor( arrowCursor );
962 } 1001 }
963 } 1002 }
964 1003
965 // Scroll if item was moved to upper or lower end of agenda. 1004 // Scroll if item was moved to upper or lower end of agenda.
966 if (clipperPos.y() < mScrollBorderWidth) { 1005 if (clipperPos.y() < mScrollBorderWidth) {
967 mScrollUpTimer.start(mScrollDelay); 1006 mScrollUpTimer.start(mScrollDelay);
968 } else if (visibleHeight() - clipperPos.y() < 1007 } else if (visibleHeight() - clipperPos.y() <
969 mScrollBorderWidth) { 1008 mScrollBorderWidth) {
970 mScrollDownTimer.start(mScrollDelay); 1009 mScrollDownTimer.start(mScrollDelay);
971 } else { 1010 } else {
972 mScrollUpTimer.stop(); 1011 mScrollUpTimer.stop();
973 mScrollDownTimer.stop(); 1012 mScrollDownTimer.stop();
974 } 1013 }
975 1014
976 // Move or resize item if necessary 1015 // Move or resize item if necessary
977 if (mCurrentCellX != gx || mCurrentCellY != gy) { 1016 if (mCurrentCellX != gx || mCurrentCellY != gy) {
978 mItemMoved = true; 1017 mItemMoved = true;
979 mActionItem->raise(); 1018 mActionItem->raise();
980 if (mActionType == MOVE) { 1019 if (mActionType == MOVE) {
981 // Move all items belonging to a multi item 1020 // Move all items belonging to a multi item
982 KOAgendaItem *moveItem = mActionItem->firstMultiItem(); 1021 KOAgendaItem *moveItem = mActionItem->firstMultiItem();
983 bool isMultiItem = (moveItem || mActionItem->lastMultiItem()); 1022 bool isMultiItem = (moveItem || mActionItem->lastMultiItem());
984 if (!moveItem) moveItem = mActionItem; 1023 if (!moveItem) moveItem = mActionItem;
985 while (moveItem) { 1024 while (moveItem) {
986 int dy; 1025 int dy;
987 if (isMultiItem) dy = 0; 1026 if (isMultiItem) dy = 0;
988 else dy = gy - mCurrentCellY; 1027 else dy = gy - mCurrentCellY;
989 moveItem->moveRelative(gx - mCurrentCellX,dy); 1028 moveItem->moveRelative(gx - mCurrentCellX,dy);
990 int x,y; 1029 int x,y;
991 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y); 1030 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y);
992 moveItem->resize(mGridSpacingX * moveItem->cellWidth(), 1031 moveItem->resize(mGridSpacingX * moveItem->cellWidth(),
993 mGridSpacingY * moveItem->cellHeight()); 1032 mGridSpacingY * moveItem->cellHeight());
994 moveChild(moveItem,x,y); 1033 moveChild(moveItem,x,y);
995 moveItem = moveItem->nextMultiItem(); 1034 moveItem = moveItem->nextMultiItem();
996 } 1035 }
997 } else if (mActionType == RESIZETOP) { 1036 } else if (mActionType == RESIZETOP) {
998 if (mCurrentCellY <= mActionItem->cellYBottom()) { 1037 if (mCurrentCellY <= mActionItem->cellYBottom()) {
999 mActionItem->expandTop(gy - mCurrentCellY); 1038 mActionItem->expandTop(gy - mCurrentCellY);
1000 mActionItem->resize(mActionItem->width(), 1039 mActionItem->resize(mActionItem->width(),
1001 mGridSpacingY * mActionItem->cellHeight()); 1040 mGridSpacingY * mActionItem->cellHeight());
1002 int x,y; 1041 int x,y;
1003 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y); 1042 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y);
1004 //moveChild(mActionItem,childX(mActionItem),y); 1043 //moveChild(mActionItem,childX(mActionItem),y);
1005 QScrollView::moveChild( mActionItem,childX(mActionItem),y ); 1044 QScrollView::moveChild( mActionItem,childX(mActionItem),y );
1006 } 1045 }
1007 } else if (mActionType == RESIZEBOTTOM) { 1046 } else if (mActionType == RESIZEBOTTOM) {
1008 if (mCurrentCellY >= mActionItem->cellYTop()) { 1047 if (mCurrentCellY >= mActionItem->cellYTop()) {
1009 mActionItem->expandBottom(gy - mCurrentCellY); 1048 mActionItem->expandBottom(gy - mCurrentCellY);
1010 mActionItem->resize(mActionItem->width(), 1049 mActionItem->resize(mActionItem->width(),
1011 mGridSpacingY * mActionItem->cellHeight()); 1050 mGridSpacingY * mActionItem->cellHeight());
1012 } 1051 }
1013 } else if (mActionType == RESIZELEFT) { 1052 } else if (mActionType == RESIZELEFT) {
1014 if (mCurrentCellX <= mActionItem->cellXWidth()) { 1053 if (mCurrentCellX <= mActionItem->cellXWidth()) {
1015 mActionItem->expandLeft(gx - mCurrentCellX); 1054 mActionItem->expandLeft(gx - mCurrentCellX);
1016 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 1055 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
1017 mActionItem->height()); 1056 mActionItem->height());
1018 int x,y; 1057 int x,y;
1019 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y); 1058 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y);
1020 moveChild(mActionItem,x,childY(mActionItem)); 1059 moveChild(mActionItem,x,childY(mActionItem));
1021 } 1060 }
1022 } else if (mActionType == RESIZERIGHT) { 1061 } else if (mActionType == RESIZERIGHT) {
1023 if (mCurrentCellX >= mActionItem->cellX()) { 1062 if (mCurrentCellX >= mActionItem->cellX()) {
1024 mActionItem->expandRight(gx - mCurrentCellX); 1063 mActionItem->expandRight(gx - mCurrentCellX);
1025 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 1064 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
1026 mActionItem->height()); 1065 mActionItem->height());
1027 } 1066 }
1028 } 1067 }
1029 mCurrentCellX = gx; 1068 mCurrentCellX = gx;
1030 mCurrentCellY = gy; 1069 mCurrentCellY = gy;
1031 } 1070 }
1032} 1071}
1033 1072
1034void KOAgenda::endItemAction() 1073void KOAgenda::endItemAction()
1035{ 1074{
1036 1075
1037 if ( mItemMoved ) { 1076 if ( mItemMoved ) {
1038 KOAgendaItem *placeItem = mActionItem->firstMultiItem(); 1077 KOAgendaItem *placeItem = mActionItem->firstMultiItem();
1039 if ( !placeItem ) { 1078 if ( !placeItem ) {
1040 placeItem = mActionItem; 1079 placeItem = mActionItem;
1041 } 1080 }
1042 if ( placeItem->incidence()->recurrence()->doesRecur() ) { 1081 if ( placeItem->incidence()->recurrence()->doesRecur() ) {
1043 Incidence* oldInc = placeItem->incidence(); 1082 Incidence* oldInc = placeItem->incidence();
1044 placeItem->recreateIncidence(); 1083 placeItem->recreateIncidence();
1045 emit addToCalSignal(placeItem->incidence(), oldInc ); 1084 emit addToCalSignal(placeItem->incidence(), oldInc );
1046 } 1085 }
1047 int type = mActionType; 1086 int type = mActionType;
1048 if ( mAllDayMode ) 1087 if ( mAllDayMode )
1049 type = -1; 1088 type = -1;
1050 KOAgendaItem *modifiedItem = placeItem; 1089 KOAgendaItem *modifiedItem = placeItem;
1051 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */); 1090 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */);
1052 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems(); 1091 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems();
1053 KOAgendaItem *item; 1092 KOAgendaItem *item;
1054 1093
1055 if ( placeItem->incidence()->type() == "Todo" ) { 1094 if ( placeItem->incidence()->type() == "Todo" ) {
1056 mSelectedItem = 0; 1095 mSelectedItem = 0;
1057 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth()); 1096 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth());
1058 modifiedItem->mLastMoveXPos = mCurrentCellX; 1097 modifiedItem->mLastMoveXPos = mCurrentCellX;
1059 emit itemModified( modifiedItem, mActionType ); 1098 emit itemModified( modifiedItem, mActionType );
1060 } 1099 }
1061 else { 1100 else {
1062#if 0 1101#if 0
1063 for ( item=oldconflictItems.first(); item != 0; 1102 for ( item=oldconflictItems.first(); item != 0;
1064 item=oldconflictItems.next() ) { 1103 item=oldconflictItems.next() ) {
1065 placeSubCells(item); 1104 placeSubCells(item);
1066 } 1105 }
1067 while ( placeItem ) { 1106 while ( placeItem ) {
1068 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 1107 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
1069 placeSubCells( placeItem ); 1108 placeSubCells( placeItem );
1070 placeItem = placeItem->nextMultiItem(); 1109 placeItem = placeItem->nextMultiItem();
1071 } 1110 }
1072#endif 1111#endif
1073 1112
1074 globalFlagBlockAgendaItemPaint = 1; 1113 globalFlagBlockAgendaItemPaint = 1;
1075 for ( item=oldconflictItems.first(); item != 0; 1114 for ( item=oldconflictItems.first(); item != 0;
1076 item=oldconflictItems.next() ) { 1115 item=oldconflictItems.next() ) {
1077 placeSubCells(item); 1116 placeSubCells(item);
1078 } 1117 }
1079 while ( placeItem ) { 1118 while ( placeItem ) {
1080 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 1119 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
1081 oldconflictItems = placeItem->conflictItems(); 1120 oldconflictItems = placeItem->conflictItems();
1082 for ( item=oldconflictItems.first(); item != 0; 1121 for ( item=oldconflictItems.first(); item != 0;
1083 item=oldconflictItems.next() ) { 1122 item=oldconflictItems.next() ) {
1084 placeSubCells(item); 1123 placeSubCells(item);
1085 } 1124 }
1086 placeSubCells( placeItem ); 1125 placeSubCells( placeItem );
1087 placeItem = placeItem->nextMultiItem(); 1126 placeItem = placeItem->nextMultiItem();
1088 } 1127 }
1089 globalFlagBlockAgendaItemPaint = 0; 1128 globalFlagBlockAgendaItemPaint = 0;
1090 for ( item=oldconflictItems.first(); item != 0; 1129 for ( item=oldconflictItems.first(); item != 0;
1091 item=oldconflictItems.next() ) { 1130 item=oldconflictItems.next() ) {
1092 globalFlagBlockAgendaItemUpdate = 0; 1131 globalFlagBlockAgendaItemUpdate = 0;
1093 item->repaintMe(); 1132 item->repaintMe();
1094 globalFlagBlockAgendaItemUpdate = 1; 1133 globalFlagBlockAgendaItemUpdate = 1;
1095 item->repaint( false ); 1134 item->repaint( false );
1096 } 1135 }
1097 placeItem = modifiedItem; 1136 placeItem = modifiedItem;
1098 1137
1099 while ( placeItem ) { 1138 while ( placeItem ) {
1100 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 1139 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
1101 globalFlagBlockAgendaItemUpdate = 0; 1140 globalFlagBlockAgendaItemUpdate = 0;
1102 placeItem->repaintMe(); 1141 placeItem->repaintMe();
1103 globalFlagBlockAgendaItemUpdate = 1; 1142 globalFlagBlockAgendaItemUpdate = 1;
1104 placeItem->repaint(false); 1143 placeItem->repaint(false);
1105 placeItem = placeItem->nextMultiItem(); 1144 placeItem = placeItem->nextMultiItem();
1106 } 1145 }
1107 emit itemModified( modifiedItem, mActionType ); 1146 emit itemModified( modifiedItem, mActionType );
1108 1147
1109 1148
1110 placeItem = modifiedItem; 1149 placeItem = modifiedItem;
1111 while ( placeItem ) { 1150 while ( placeItem ) {
1112 oldconflictItems = placeItem->conflictItems(); 1151 oldconflictItems = placeItem->conflictItems();
1113 for ( item=oldconflictItems.first(); item != 0; 1152 for ( item=oldconflictItems.first(); item != 0;
1114 item=oldconflictItems.next() ) { 1153 item=oldconflictItems.next() ) {
1115 placeSubCells(item); 1154 placeSubCells(item);
1116 } 1155 }
1117 placeSubCells( placeItem ); 1156 placeSubCells( placeItem );
1118 placeItem = placeItem->nextMultiItem(); 1157 placeItem = placeItem->nextMultiItem();
1119 1158
1120 } 1159 }
1121 placeItem = modifiedItem; 1160 placeItem = modifiedItem;
1122 while ( placeItem ) { 1161 while ( placeItem ) {
1123 oldconflictItems = placeItem->conflictItems(); 1162 oldconflictItems = placeItem->conflictItems();
1124 for ( item=oldconflictItems.first(); item != 0; 1163 for ( item=oldconflictItems.first(); item != 0;
1125 item=oldconflictItems.next() ) { 1164 item=oldconflictItems.next() ) {
1126 globalFlagBlockAgendaItemUpdate = 0; 1165 globalFlagBlockAgendaItemUpdate = 0;
1127 item->repaintMe(); 1166 item->repaintMe();
1128 globalFlagBlockAgendaItemUpdate = 1; 1167 globalFlagBlockAgendaItemUpdate = 1;
1129 item->repaint(false); 1168 item->repaint(false);
1130 } 1169 }
1131 placeItem = placeItem->nextMultiItem(); 1170 placeItem = placeItem->nextMultiItem();
1132 } 1171 }
1133 /* 1172 /*
1134 1173
1135 oldconflictItems = modifiedItem->conflictItems(); 1174 oldconflictItems = modifiedItem->conflictItems();
1136 for ( item=oldconflictItems.first(); item != 0; 1175 for ( item=oldconflictItems.first(); item != 0;
1137 item=oldconflictItems.next() ) { 1176 item=oldconflictItems.next() ) {
1138 globalFlagBlockAgendaItemUpdate = 0; 1177 globalFlagBlockAgendaItemUpdate = 0;
1139 item->paintMe(false); 1178 item->paintMe(false);
1140 globalFlagBlockAgendaItemUpdate = 1; 1179 globalFlagBlockAgendaItemUpdate = 1;
1141 item->repaint(false); 1180 item->repaint(false);
1142 } 1181 }
1143 */ 1182 */
1144 1183
1145 1184
1146 } 1185 }
1147 1186
1148 } 1187 }
1149 1188
1150 mScrollUpTimer.stop(); 1189 mScrollUpTimer.stop();
1151 mScrollDownTimer.stop(); 1190 mScrollDownTimer.stop();
1152 setCursor( arrowCursor ); 1191 setCursor( arrowCursor );
1153 mActionItem = 0; 1192 mActionItem = 0;
1154 mActionType = NOP; 1193 mActionType = NOP;
1155 mItemMoved = 0; 1194 mItemMoved = 0;
1156 1195
1157} 1196}
1158 1197
1159void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos) 1198void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos)
1160{ 1199{
1161// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 1200// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
1162// QPoint point = viewport()->mapToGlobal(viewportPos); 1201// QPoint point = viewport()->mapToGlobal(viewportPos);
1163// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 1202// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
1164// point = clipper()->mapFromGlobal(point); 1203// point = clipper()->mapFromGlobal(point);
1165// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 1204// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
1166 1205
1167 int x,y; 1206 int x,y;
1168 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 1207 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
1169// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 1208// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
1170 int gx,gy; 1209 int gx,gy;
1171 contentsToGrid(x,y,gx,gy); 1210 contentsToGrid(x,y,gx,gy);
1172 1211
1173 // Change cursor to resize cursor if appropriate 1212 // Change cursor to resize cursor if appropriate
1174 if (mAllDayMode) { 1213 if (mAllDayMode) {
1175 int gridDistanceX = (x - gx * mGridSpacingX); 1214 int gridDistanceX = (x - gx * mGridSpacingX);
1176 if (gridDistanceX < mResizeBorderWidth && 1215 if (gridDistanceX < mResizeBorderWidth &&
1177 moveItem->cellX() == gx) { 1216 moveItem->cellX() == gx) {
1178 setCursor(sizeHorCursor); 1217 setCursor(sizeHorCursor);
1179 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 1218 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
1180 moveItem->cellXWidth() == gx) { 1219 moveItem->cellXWidth() == gx) {
1181 setCursor(sizeHorCursor); 1220 setCursor(sizeHorCursor);
1182 } else { 1221 } else {
1183 setCursor(arrowCursor); 1222 setCursor(arrowCursor);
1184 } 1223 }
1185 } else { 1224 } else {
1186 int gridDistanceY = (y - gy * mGridSpacingY); 1225 int gridDistanceY = (y - gy * mGridSpacingY);
1187 if (gridDistanceY < mResizeBorderWidth && 1226 if (gridDistanceY < mResizeBorderWidth &&
1188 moveItem->cellYTop() == gy && 1227 moveItem->cellYTop() == gy &&
1189 !moveItem->firstMultiItem()) { 1228 !moveItem->firstMultiItem()) {
1190 setCursor(sizeVerCursor); 1229 setCursor(sizeVerCursor);
1191 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 1230 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
1192 moveItem->cellYBottom() == gy && 1231 moveItem->cellYBottom() == gy &&
1193 !moveItem->lastMultiItem()) { 1232 !moveItem->lastMultiItem()) {
1194 setCursor(sizeVerCursor); 1233 setCursor(sizeVerCursor);
1195 } else { 1234 } else {
1196 setCursor(arrowCursor); 1235 setCursor(arrowCursor);
1197 } 1236 }
1198 } 1237 }
1199} 1238}
1200 1239
1201 1240
1202/* 1241/*
1203 Place item in cell and take care that multiple items using the same cell do 1242 Place item in cell and take care that multiple items using the same cell do
1204 not overlap. This method is not yet optimal. It doesn´t use the maximum space 1243 not overlap. This method is not yet optimal. It doesn´t use the maximum space
1205 it can get in all cases. 1244 it can get in all cases.
1206 At the moment the method has a bug: When an item is placed only the sub cell 1245 At the moment the method has a bug: When an item is placed only the sub cell
1207 widths of the items are changed, which are within the Y region the item to 1246 widths of the items are changed, which are within the Y region the item to
1208 place spans. When the sub cell width change of one of this items affects a 1247 place spans. When the sub cell width change of one of this items affects a
1209 cell, where other items are, which do not overlap in Y with the item to place, 1248 cell, where other items are, which do not overlap in Y with the item to place,
1210 the display gets corrupted, although the corruption looks quite nice. 1249 the display gets corrupted, although the corruption looks quite nice.
1211*/ 1250*/
1212void KOAgenda::placeSubCells(KOAgendaItem *placeItem) 1251void KOAgenda::placeSubCells(KOAgendaItem *placeItem)
1213{ 1252{
1214 1253
1215 QPtrList<KOAgendaItem> conflictItems; 1254 QPtrList<KOAgendaItem> conflictItems;
1216 int maxSubCells = 0; 1255 int maxSubCells = 0;
1217 QIntDict<KOAgendaItem> subCellDict(5); 1256 QIntDict<KOAgendaItem> subCellDict(5);
1218 1257
1219 KOAgendaItem *item; 1258 KOAgendaItem *item;
1220 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1259 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1221 if (item != placeItem) { 1260 if (item != placeItem) {
1222 if (placeItem->cellX() <= item->cellXWidth() && 1261 if (placeItem->cellX() <= item->cellXWidth() &&
1223 placeItem->cellXWidth() >= item->cellX()) { 1262 placeItem->cellXWidth() >= item->cellX()) {
1224 if ((placeItem->cellYTop() <= item->cellYBottom()) && 1263 if ((placeItem->cellYTop() <= item->cellYBottom()) &&
1225 (placeItem->cellYBottom() >= item->cellYTop())) { 1264 (placeItem->cellYBottom() >= item->cellYTop())) {
1226 conflictItems.append(item); 1265 conflictItems.append(item);
1227 if (item->subCells() > maxSubCells) 1266 if (item->subCells() > maxSubCells)
1228 maxSubCells = item->subCells(); 1267 maxSubCells = item->subCells();
1229 subCellDict.insert(item->subCell(),item); 1268 subCellDict.insert(item->subCell(),item);
1230 } 1269 }
1231 } 1270 }
1232 } 1271 }
1233 } 1272 }
1234 1273
1235 if (conflictItems.count() > 0) { 1274 if (conflictItems.count() > 0) {
1236 // Look for unused sub cell and insert item 1275 // Look for unused sub cell and insert item
1237 int i; 1276 int i;
1238 for(i=0;i<maxSubCells;++i) { 1277 for(i=0;i<maxSubCells;++i) {
1239 if (!subCellDict.find(i)) { 1278 if (!subCellDict.find(i)) {
1240 placeItem->setSubCell(i); 1279 placeItem->setSubCell(i);
1241 break; 1280 break;
1242 } 1281 }
1243 } 1282 }
1244 if (i == maxSubCells) { 1283 if (i == maxSubCells) {
1245 placeItem->setSubCell(maxSubCells); 1284 placeItem->setSubCell(maxSubCells);
1246 maxSubCells++; // add new item to number of sub cells 1285 maxSubCells++; // add new item to number of sub cells
1247 } 1286 }
1248 1287
1249 // Prepare for sub cell geometry adjustment 1288 // Prepare for sub cell geometry adjustment
1250 int newSubCellWidth; 1289 int newSubCellWidth;
1251 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells; 1290 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells;
1252 else newSubCellWidth = mGridSpacingX / maxSubCells; 1291 else newSubCellWidth = mGridSpacingX / maxSubCells;
1253 conflictItems.append(placeItem); 1292 conflictItems.append(placeItem);
1254 1293
1255 1294
1256 // Adjust sub cell geometry of all direct conflict items 1295 // Adjust sub cell geometry of all direct conflict items
1257 for ( item=conflictItems.first(); item != 0; 1296 for ( item=conflictItems.first(); item != 0;
1258 item=conflictItems.next() ) { 1297 item=conflictItems.next() ) {
1259 item->setSubCells(maxSubCells); 1298 item->setSubCells(maxSubCells);
1260 if (mAllDayMode) { 1299 if (mAllDayMode) {
1261 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); 1300 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth);
1262 } else { 1301 } else {
1263 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); 1302 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY);
1264 } 1303 }
1265 int x,y; 1304 int x,y;
1266 gridToContents(item->cellX(),item->cellYTop(),x,y); 1305 gridToContents(item->cellX(),item->cellYTop(),x,y);
1267 if (mAllDayMode) { 1306 if (mAllDayMode) {
1268 y += item->subCell() * newSubCellWidth; 1307 y += item->subCell() * newSubCellWidth;
1269 } else { 1308 } else {
1270 x += item->subCell() * newSubCellWidth; 1309 x += item->subCell() * newSubCellWidth;
1271 } 1310 }
1272 moveChild(item,x,y); 1311 moveChild(item,x,y);
1273 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y); 1312 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y);
1274 //item->updateItem(); 1313 //item->updateItem();
1275 } 1314 }
1276 // Adjust sub cell geometry of all conflict items of all conflict items 1315 // Adjust sub cell geometry of all conflict items of all conflict items
1277 for ( item=conflictItems.first(); item != 0; 1316 for ( item=conflictItems.first(); item != 0;
1278 item=conflictItems.next() ) { 1317 item=conflictItems.next() ) {
1279 if ( placeItem != item ) { 1318 if ( placeItem != item ) {
1280 KOAgendaItem *item2; 1319 KOAgendaItem *item2;
1281 QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems(); 1320 QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems();
1282 for ( item2=conflictItems2.first(); item2 != 0; 1321 for ( item2=conflictItems2.first(); item2 != 0;
1283 item2=conflictItems2.next() ) { 1322 item2=conflictItems2.next() ) {
1284 if ( item2->subCells() != maxSubCells) { 1323 if ( item2->subCells() != maxSubCells) {
1285 item2->setSubCells(maxSubCells); 1324 item2->setSubCells(maxSubCells);
1286 if (mAllDayMode) { 1325 if (mAllDayMode) {
1287 item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth); 1326 item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth);
1288 } else { 1327 } else {
1289 item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY); 1328 item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY);
1290 } 1329 }
1291 int x,y; 1330 int x,y;
1292 gridToContents(item2->cellX(),item2->cellYTop(),x,y); 1331 gridToContents(item2->cellX(),item2->cellYTop(),x,y);
1293 if (mAllDayMode) { 1332 if (mAllDayMode) {
1294 y += item2->subCell() * newSubCellWidth; 1333 y += item2->subCell() * newSubCellWidth;
1295 } else { 1334 } else {
1296 x += item2->subCell() * newSubCellWidth; 1335 x += item2->subCell() * newSubCellWidth;
1297 } 1336 }
1298 moveChild(item2,x,y); 1337 moveChild(item2,x,y);
1299 //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() ); 1338 //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() );
1300 } 1339 }
1301 } 1340 }
1302 } 1341 }
1303 } 1342 }
1304 } else { 1343 } else {
1305 placeItem->setSubCell(0); 1344 placeItem->setSubCell(0);
1306 placeItem->setSubCells(1); 1345 placeItem->setSubCells(1);
1307 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY); 1346 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY);
1308 else placeItem->resize(mGridSpacingX,placeItem->height()); 1347 else placeItem->resize(mGridSpacingX,placeItem->height());
1309 int x,y; 1348 int x,y;
1310 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y); 1349 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y);
1311 moveChild(placeItem,x,y); 1350 moveChild(placeItem,x,y);
1312 } 1351 }
1313 placeItem->setConflictItems(conflictItems); 1352 placeItem->setConflictItems(conflictItems);
1314 // for ( item=conflictItems.first(); item != 0; 1353 // for ( item=conflictItems.first(); item != 0;
1315// item=conflictItems.next() ) { 1354// item=conflictItems.next() ) {
1316// //item->updateItem(); 1355// //item->updateItem();
1317// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() ); 1356// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() );
1318// } 1357// }
1319// placeItem->updateItem(); 1358// placeItem->updateItem();
1320} 1359}
1321 1360
1322void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch) 1361void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
1323{ 1362{
1324 if ( globalFlagBlockAgenda ) 1363 if ( globalFlagBlockAgenda )
1325 return; 1364 return;
1326 //qDebug("KOAgenda::drawContents "); 1365 //qDebug("KOAgenda::drawContents ");
1327 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) 1366 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() )
1328 ;//drawContentsToPainter(); 1367 ;//drawContentsToPainter();
1329 1368
1330 QPaintDevice* pd = p->device(); 1369 QPaintDevice* pd = p->device();
1331 p->end(); 1370 p->end();
1332 int vx, vy; 1371 int vx, vy;
1333 int selectionX = KOGlobals::self()->reverseLayout() ? 1372 int selectionX = KOGlobals::self()->reverseLayout() ?
1334 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1373 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1335 mSelectionCellX * mGridSpacingX; 1374 mSelectionCellX * mGridSpacingX;
1336 contentsToViewport ( cx, cy, vx,vy); 1375 contentsToViewport ( cx, cy, vx,vy);
1337 // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ; 1376 // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ;
1338 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) 1377 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) )
1339 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); 1378 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP);
1340 1379
1341 if ( mSelectionHeight > 0 ) { 1380 if ( mSelectionHeight > 0 ) {
1342 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); 1381 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight );
1343 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1382 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1344 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1383 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1345 contentsToViewport ( selectionX, mSelectionYTop, vx,vy); 1384 contentsToViewport ( selectionX, mSelectionYTop, vx,vy);
1346 bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); 1385 bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP);
1347 } 1386 }
1348 } 1387 }
1349 //qDebug("btbl "); 1388 //qDebug("btbl ");
1350 p->begin( pd ); 1389 p->begin( pd );
1351 //qDebug("end "); 1390 //qDebug("end ");
1352} 1391}
1353 1392
1354void KOAgenda::finishUpdate() 1393void KOAgenda::finishUpdate()
1355{ 1394{
1356 1395
1357 KOAgendaItem *item; 1396 KOAgendaItem *item;
1358 globalFlagBlockAgendaItemPaint = 1; 1397 globalFlagBlockAgendaItemPaint = 1;
1359 // Adjust sub cell geometry of all conflict items of all conflict items of all conflict items ... of the conflict item with the max number of conflictitems 1398 // Adjust sub cell geometry of all conflict items of all conflict items of all conflict items ... of the conflict item with the max number of conflictitems
1360 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1399 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1361 if ( !item->checkLayout() ) { 1400 if ( !item->checkLayout() ) {
1362 //qDebug(" conflictitem found "); 1401 //qDebug(" conflictitem found ");
1363 int newSubCellWidth; 1402 int newSubCellWidth;
1364 if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells(); 1403 if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells();
1365 else newSubCellWidth = mGridSpacingX / item->subCells(); 1404 else newSubCellWidth = mGridSpacingX / item->subCells();
1366 1405
1367 if (mAllDayMode) { 1406 if (mAllDayMode) {
1368 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); 1407 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth);
1369 } else { 1408 } else {
1370 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); 1409 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY);
1371 } 1410 }
1372 int x,y; 1411 int x,y;
1373 gridToContents(item->cellX(),item->cellYTop(),x,y); 1412 gridToContents(item->cellX(),item->cellYTop(),x,y);
1374 if (mAllDayMode) { 1413 if (mAllDayMode) {
1375 y += item->subCell() * newSubCellWidth; 1414 y += item->subCell() * newSubCellWidth;
1376 } else { 1415 } else {
1377 x += item->subCell() * newSubCellWidth; 1416 x += item->subCell() * newSubCellWidth;
1378 } 1417 }
1379 moveChild(item,x,y); 1418 moveChild(item,x,y);
1380 } 1419 }
1381 } 1420 }
1382 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1421 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1383 if ( !item->isVisible() ) 1422 if ( !item->isVisible() )
1384 item->show(); 1423 item->show();
1385 1424
1386 } 1425 }
1387 globalFlagBlockAgendaItemUpdate = 0; 1426 globalFlagBlockAgendaItemUpdate = 0;
1388 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1427 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1389 item->repaintMe( ); 1428 item->repaintMe( );
1390 } 1429 }
1391 globalFlagBlockAgendaItemUpdate = 1; 1430 globalFlagBlockAgendaItemUpdate = 1;
1392 qApp->processEvents(); 1431 qApp->processEvents();
1393 globalFlagBlockAgendaItemPaint = 0; 1432 globalFlagBlockAgendaItemPaint = 0;
1394 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1433 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1395 item->repaint( false ); 1434 item->repaint( false );
1396 } 1435 }
1397 1436
1398} 1437}
1399 1438
1400/* 1439/*
1401 Draw grid in the background of the agenda. 1440 Draw grid in the background of the agenda.
1402*/ 1441*/
1403void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch) 1442void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch)
1404{ 1443{
1405 1444
1406 1445
1407 if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask ) 1446 if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask )
1408 return; 1447 return;
1409 if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 ) 1448 if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 )
1410 return; 1449 return;
1411 int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight(); 1450 int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight();
1412 if ( ch < 1 ) 1451 if ( ch < 1 )
1413 ch = 1; 1452 ch = 1;
1414 if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) { 1453 if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) {
1415 mPaintPixmap.resize( contentsWidth()+42, ch ); 1454 mPaintPixmap.resize( contentsWidth()+42, ch );
1416 } 1455 }
1417 mCurPixWid = contentsWidth(); 1456 mCurPixWid = contentsWidth();
1418 mCurPixHei = ch; 1457 mCurPixHei = ch;
1419 if ( mHighlightPixmap.width() < mGridSpacingX-1 || mHighlightPixmap.height() < ch ) { 1458 if ( mHighlightPixmap.width() < mGridSpacingX-1 || mHighlightPixmap.height() < ch ) {
1420 mHighlightPixmap.resize( mGridSpacingX-1, ch ); 1459 mHighlightPixmap.resize( mGridSpacingX-1, ch );
1421 mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor ); 1460 mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor );
1422 } 1461 }
1423 mPixPainter.begin( &mPaintPixmap) ; 1462 mPixPainter.begin( &mPaintPixmap) ;
1424 //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() ); 1463 //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() );
1425 QPainter * p ; 1464 QPainter * p ;
1426 if (paint == 0) { 1465 if (paint == 0) {
1427 mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor); 1466 mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor);
1428 p = &mPixPainter; 1467 p = &mPixPainter;
1429 } 1468 }
1430 else 1469 else
1431 p = paint ; 1470 p = paint ;
1432 // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch); 1471 // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch);
1433 1472
1434 //--cx;++cw; 1473 //--cx;++cw;
1435 int lGridSpacingY = mGridSpacingY*2; 1474 int lGridSpacingY = mGridSpacingY*2;
1436 int selDay; 1475 int selDay;
1437 if ( !backgroundOnly ) 1476 if ( !backgroundOnly )
1438 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) 1477 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay)
1439 { 1478 {
1440 if ( mSelectedDates[selDay] == QDateTime::currentDateTime ().date() && KOPrefs::instance()->mHighlightCurrentDay) { 1479 if ( mSelectedDates[selDay] == QDateTime::currentDateTime ().date() && KOPrefs::instance()->mHighlightCurrentDay) {
1441 int x1 = cx; 1480 int x1 = cx;
1442 int y1 = 0; 1481 int y1 = 0;
1443 if (y1 < cy) y1 = cy; 1482 if (y1 < cy) y1 = cy;
1444 int x2 = cx+cw-1; 1483 int x2 = cx+cw-1;
1445 int y2 = contentsHeight(); 1484 int y2 = contentsHeight();
1446 if (y2 > cy+ch-1) y2=cy+ch-1; 1485 if (y2 > cy+ch-1) y2=cy+ch-1;
1447 if (x2 >= x1 && y2 >= y1) { 1486 if (x2 >= x1 && y2 >= y1) {
1448 int gxStart = selDay; 1487 int gxStart = selDay;
1449 int gxEnd = gxStart ; 1488 int gxEnd = gxStart ;
1450 int xStart = KOGlobals::self()->reverseLayout() ? 1489 int xStart = KOGlobals::self()->reverseLayout() ?
1451 (mColumns - 1 - gxStart)*mGridSpacingX : 1490 (mColumns - 1 - gxStart)*mGridSpacingX :
1452 gxStart*mGridSpacingX; 1491 gxStart*mGridSpacingX;
1453 if (xStart < x1) xStart = x1; 1492 if (xStart < x1) xStart = x1;
1454 int xEnd = KOGlobals::self()->reverseLayout() ? 1493 int xEnd = KOGlobals::self()->reverseLayout() ?
1455 (mColumns - gxStart)*mGridSpacingX-1 : 1494 (mColumns - gxStart)*mGridSpacingX-1 :
1456 (gxStart+1)*mGridSpacingX-1; 1495 (gxStart+1)*mGridSpacingX-1;
1457 if (xEnd > x2) xEnd = x2; 1496 if (xEnd > x2) xEnd = x2;
1458 if ( KOPrefs::instance()->mUseHighlightLightColor ) 1497 if ( KOPrefs::instance()->mUseHighlightLightColor )
1459 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1498 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1460 KOPrefs::instance()->mAgendaBgColor.light()); 1499 KOPrefs::instance()->mAgendaBgColor.light());
1461 else 1500 else
1462 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1501 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1463 KOPrefs::instance()->mAgendaBgColor.dark()); 1502 KOPrefs::instance()->mAgendaBgColor.dark());
1464 1503
1465 } 1504 }
1466 } 1505 }
1467 } 1506 }
1468 // Highlight working hours 1507 // Highlight working hours
1469 1508
1470 if ( !backgroundOnly ) 1509 if ( !backgroundOnly )
1471 if (mWorkingHoursEnable) { 1510 if (mWorkingHoursEnable) {
1472 int x1 = cx; 1511 int x1 = cx;
1473 int y1 = mWorkingHoursYTop; 1512 int y1 = mWorkingHoursYTop;
1474 if (y1 < cy) y1 = cy; 1513 if (y1 < cy) y1 = cy;
1475 int x2 = cx+cw-1; 1514 int x2 = cx+cw-1;
1476 // int x2 = mGridSpacingX * 5 - 1; 1515 // int x2 = mGridSpacingX * 5 - 1;
1477 // if (x2 > cx+cw-1) x2 = cx + cw - 1; 1516 // if (x2 > cx+cw-1) x2 = cx + cw - 1;
1478 int y2 = mWorkingHoursYBottom; 1517 int y2 = mWorkingHoursYBottom;
1479 if (y2 > cy+ch-1) y2=cy+ch-1; 1518 if (y2 > cy+ch-1) y2=cy+ch-1;
1480 1519
1481 if (x2 >= x1 && y2 >= y1) { 1520 if (x2 >= x1 && y2 >= y1) {
1482 // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX ); 1521 // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX );
1483 int gxStart = x1/mGridSpacingX; 1522 int gxStart = x1/mGridSpacingX;
1484 int gxEnd = x2/mGridSpacingX; 1523 int gxEnd = x2/mGridSpacingX;
1485 while(gxStart <= gxEnd) { 1524 while(gxStart <= gxEnd) {
1486 if (gxStart < int(mHolidayMask->count()) && 1525 if (gxStart < int(mHolidayMask->count()) &&
1487 !mHolidayMask->at(gxStart)) { 1526 !mHolidayMask->at(gxStart)) {
1488 int xStart = KOGlobals::self()->reverseLayout() ? 1527 int xStart = KOGlobals::self()->reverseLayout() ?
1489 (mColumns - 1 - gxStart)*mGridSpacingX : 1528 (mColumns - 1 - gxStart)*mGridSpacingX :
1490 gxStart*mGridSpacingX; 1529 gxStart*mGridSpacingX;
1491 if (xStart < x1) xStart = x1; 1530 if (xStart < x1) xStart = x1;
1492 int xEnd = KOGlobals::self()->reverseLayout() ? 1531 int xEnd = KOGlobals::self()->reverseLayout() ?
1493 (mColumns - gxStart)*mGridSpacingX-1 : 1532 (mColumns - gxStart)*mGridSpacingX-1 :
1494 (gxStart+1)*mGridSpacingX-1; 1533 (gxStart+1)*mGridSpacingX-1;
1495 if (xEnd > x2) xEnd = x2; 1534 if (xEnd > x2) xEnd = x2;
1496 if ( mSelectedDates[gxStart] == QDateTime::currentDateTime ().date()&& KOPrefs::instance()->mHighlightCurrentDay ) { 1535 if ( mSelectedDates[gxStart] == QDateTime::currentDateTime ().date()&& KOPrefs::instance()->mHighlightCurrentDay ) {
1497 if ( KOPrefs::instance()->mUseHighlightLightColor ) 1536 if ( KOPrefs::instance()->mUseHighlightLightColor )
1498 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1537 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1499 KOPrefs::instance()->mWorkingHoursColor.light()); 1538 KOPrefs::instance()->mWorkingHoursColor.light());
1500 else 1539 else
1501 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1540 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1502 KOPrefs::instance()->mWorkingHoursColor.dark()); 1541 KOPrefs::instance()->mWorkingHoursColor.dark());
1503 } else { 1542 } else {
1504 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1543 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1505 KOPrefs::instance()->mWorkingHoursColor); 1544 KOPrefs::instance()->mWorkingHoursColor);
1506 } 1545 }
1507 } 1546 }
1508 ++gxStart; 1547 ++gxStart;
1509 } 1548 }
1510 } 1549 }
1511 } 1550 }
1512 /* 1551 /*
1513 int selectionX = KOGlobals::self()->reverseLayout() ? 1552 int selectionX = KOGlobals::self()->reverseLayout() ?
1514 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1553 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1515 mSelectionCellX * mGridSpacingX; 1554 mSelectionCellX * mGridSpacingX;
1516 1555
1517 // Draw selection 1556 // Draw selection
1518 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1557 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1519 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1558 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1520 // TODO: paint only part within cx,cy,cw,ch 1559 // TODO: paint only part within cx,cy,cw,ch
1521 p->fillRect( selectionX, mSelectionYTop, mGridSpacingX, 1560 p->fillRect( selectionX, mSelectionYTop, mGridSpacingX,
1522 mSelectionHeight, KOPrefs::instance()->mHighlightColor ); 1561 mSelectionHeight, KOPrefs::instance()->mHighlightColor );
1523 } 1562 }
1524 */ 1563 */
1525 // Draw vertical lines of grid 1564 // Draw vertical lines of grid
1526 1565
1527 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX; 1566 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX;
1528 if ( mGridSpacingX > 0 ) { 1567 if ( mGridSpacingX > 0 ) {
1529 while (x < cx + cw) { 1568 while (x < cx + cw) {
1530 p->drawLine(x,cy,x,cy+ch); 1569 p->drawLine(x,cy,x,cy+ch);
1531 x+=mGridSpacingX; 1570 x+=mGridSpacingX;
1532 } 1571 }
1533 } 1572 }
1534 // Draw horizontal lines of grid 1573 // Draw horizontal lines of grid
1535 int y = ((int)(cy/lGridSpacingY))*lGridSpacingY; 1574 int y = ((int)(cy/lGridSpacingY))*lGridSpacingY;
1536 if ( lGridSpacingY > 0 ) { 1575 if ( lGridSpacingY > 0 ) {
1537 while (y < cy + ch) { 1576 while (y < cy + ch) {
1538 p->setPen( SolidLine ); 1577 p->setPen( SolidLine );
1539 p->drawLine(cx,y,cx+cw,y); 1578 p->drawLine(cx,y,cx+cw,y);
1540 y+=lGridSpacingY; 1579 y+=lGridSpacingY;
1541 p->setPen( DotLine ); 1580 p->setPen( DotLine );
1542 p->drawLine(cx,y,cx+cw,y); 1581 p->drawLine(cx,y,cx+cw,y);
1543 y+=lGridSpacingY; 1582 y+=lGridSpacingY;
1544 } 1583 }
1545 p->setPen( SolidLine ); 1584 p->setPen( SolidLine );
1546 } 1585 }
1547 mPixPainter.end() ; 1586 mPixPainter.end() ;
1548} 1587}
1549 1588
1550/* 1589/*
1551 Convert srcollview contents coordinates to agenda grid coordinates. 1590 Convert srcollview contents coordinates to agenda grid coordinates.
1552*/ 1591*/
1553void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy) 1592void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy)
1554{ 1593{
1555 gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX : 1594 gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX :
1556 x/mGridSpacingX; 1595 x/mGridSpacingX;
1557 gy = y/mGridSpacingY; 1596 gy = y/mGridSpacingY;
1558} 1597}
1559 1598
1560/* 1599/*
1561 Convert agenda grid coordinates to scrollview contents coordinates. 1600 Convert agenda grid coordinates to scrollview contents coordinates.
1562*/ 1601*/
1563void KOAgenda::gridToContents (int gx, int gy, int& x, int& y) 1602void KOAgenda::gridToContents (int gx, int gy, int& x, int& y)
1564{ 1603{
1565 x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX: 1604 x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX:
1566 gx*mGridSpacingX; 1605 gx*mGridSpacingX;
1567 y = gy*mGridSpacingY; 1606 y = gy*mGridSpacingY;
1568} 1607}
1569 1608
1570 1609
1571/* 1610/*
1572 Return Y coordinate corresponding to time. Coordinates are rounded to fit into 1611 Return Y coordinate corresponding to time. Coordinates are rounded to fit into
1573 the grid. 1612 the grid.
1574*/ 1613*/
1575int KOAgenda::timeToY(const QTime &time) 1614int KOAgenda::timeToY(const QTime &time)
1576{ 1615{
1577 int minutesPerCell = 24 * 60 / mRows; 1616 int minutesPerCell = 24 * 60 / mRows;
1578 int timeMinutes = time.hour() * 60 + time.minute(); 1617 int timeMinutes = time.hour() * 60 + time.minute();
1579 int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell; 1618 int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell;
1580 return Y; 1619 return Y;
1581} 1620}
1582 1621
1583 1622
1584/* 1623/*
1585 Return time corresponding to cell y coordinate. Coordinates are rounded to 1624 Return time corresponding to cell y coordinate. Coordinates are rounded to
1586 fit into the grid. 1625 fit into the grid.
1587*/ 1626*/
1588QTime KOAgenda::gyToTime(int gy) 1627QTime KOAgenda::gyToTime(int gy)
1589{ 1628{
1590 1629
1591 int secondsPerCell = 24 * 60 * 60/ mRows; 1630 int secondsPerCell = 24 * 60 * 60/ mRows;
1592 1631
1593 int timeSeconds = secondsPerCell * gy; 1632 int timeSeconds = secondsPerCell * gy;
1594 1633
1595 QTime time( 0, 0, 0 ); 1634 QTime time( 0, 0, 0 );
1596 if ( timeSeconds < 24 * 60 * 60 ) { 1635 if ( timeSeconds < 24 * 60 * 60 ) {
1597 time = time.addSecs(timeSeconds); 1636 time = time.addSecs(timeSeconds);
1598 } else { 1637 } else {
1599 time.setHMS( 23, 59, 59 ); 1638 time.setHMS( 23, 59, 59 );
1600 } 1639 }
1601 1640
1602 return time; 1641 return time;
1603} 1642}
1604 1643
1605void KOAgenda::setStartHour(int startHour) 1644void KOAgenda::setStartHour(int startHour)
1606{ 1645{
1607 int startCell = startHour * mRows / 24; 1646 int startCell = startHour * mRows / 24;
1608 setContentsPos(0,startCell * gridSpacingY()); 1647 setContentsPos(0,startCell * gridSpacingY());
1609} 1648}
1610void KOAgenda::hideUnused() 1649void KOAgenda::hideUnused()
1611{ 1650{
1612 // experimental only 1651 // experimental only
1613 // return; 1652 // return;
1614 KOAgendaItem *item; 1653 KOAgendaItem *item;
1615 for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) { 1654 for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) {
1616 item->hide(); 1655 item->hide();
1617 } 1656 }
1618} 1657}
1619 1658
1620 1659
1621KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view) 1660KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view)
1622{ 1661{
1623 1662
1624 KOAgendaItem *fi; 1663 KOAgendaItem *fi;
1625 for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) { 1664 for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) {
1626 if ( fi->incidence() == event ) { 1665 if ( fi->incidence() == event ) {
1627 mUnusedItems.remove(); 1666 mUnusedItems.remove();
1628 fi->init( event, qd ); 1667 fi->init( event, qd );
1629 return fi; 1668 return fi;
1630 } 1669 }
1631 } 1670 }
1632 fi=mUnusedItems.first(); 1671 fi=mUnusedItems.first();
1633 if ( fi ) { 1672 if ( fi ) {
1634 mUnusedItems.remove(); 1673 mUnusedItems.remove();
1635 fi->init( event, qd ); 1674 fi->init( event, qd );
1636 return fi; 1675 return fi;
1637 } 1676 }
1638 // qDebug("new KOAgendaItem "); 1677 // qDebug("new KOAgendaItem ");
1639 1678
1640 KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode ); 1679 KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode );
1641 agendaItem->installEventFilter(this); 1680 agendaItem->installEventFilter(this);
1642 addChild(agendaItem,0,0); 1681 addChild(agendaItem,0,0);
1643 return agendaItem; 1682 return agendaItem;
1644} 1683}
1645KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo ) 1684KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo )
1646{ 1685{
1647 KOAgendaItem *item; 1686 KOAgendaItem *item;
1648 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1687 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1649 if ( item->incidence() == todo ) { 1688 if ( item->incidence() == todo ) {
1650 mItems.remove(); 1689 mItems.remove();
1651 return item; 1690 return item;
1652 } 1691 }
1653 } 1692 }
1654 return 0; 1693 return 0;
1655} 1694}
1656 1695
1657 1696
1658void KOAgenda::updateTodo( Todo * todo, int days, bool remove) 1697void KOAgenda::updateTodo( Todo * todo, int days, bool remove)
1659{ 1698{
1660 // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )|| 1699 // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )||
1661 KOAgendaItem *item; 1700 KOAgendaItem *item;
1662 item = getItemForTodo ( todo ); 1701 item = getItemForTodo ( todo );
1663 //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove); 1702 //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove);
1664 if ( item ) { 1703 if ( item ) {
1665 blockSignals( true ); 1704 blockSignals( true );
1666 //qDebug("item found "); 1705 //qDebug("item found ");
1667 item->hide(); 1706 item->hide();
1668 item->setCellX(-2, -1 ); 1707 item->setCellX(-2, -1 );
1669 item->select(false); 1708 item->select(false);
1670 mUnusedItems.append( item ); 1709 mUnusedItems.append( item );
1671 mItems.remove( item ); 1710 mItems.remove( item );
1672 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); 1711 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems();
1673 KOAgendaItem *itemit; 1712 KOAgendaItem *itemit;
1674 //globalFlagBlockAgendaItemPaint = 1; 1713 //globalFlagBlockAgendaItemPaint = 1;
1675 for ( itemit=oldconflictItems.first(); itemit != 0; 1714 for ( itemit=oldconflictItems.first(); itemit != 0;
1676 itemit=oldconflictItems.next() ) { 1715 itemit=oldconflictItems.next() ) {
1677 if ( itemit != item ) 1716 if ( itemit != item )
1678 placeSubCells(itemit); 1717 placeSubCells(itemit);
1679 } 1718 }
1680 qApp->processEvents(); 1719 qApp->processEvents();
1681 //globalFlagBlockAgendaItemPaint = 0; 1720 //globalFlagBlockAgendaItemPaint = 0;
1682 for ( itemit=oldconflictItems.first(); itemit != 0; 1721 for ( itemit=oldconflictItems.first(); itemit != 0;
1683 itemit=oldconflictItems.next() ) { 1722 itemit=oldconflictItems.next() ) {
1684 globalFlagBlockAgendaItemUpdate = 0; 1723 globalFlagBlockAgendaItemUpdate = 0;
1685 if ( itemit != item ) 1724 if ( itemit != item )
1686 itemit->repaintMe(); 1725 itemit->repaintMe();
1687 globalFlagBlockAgendaItemUpdate = 1; 1726 globalFlagBlockAgendaItemUpdate = 1;
1688 itemit->repaint(); 1727 itemit->repaint();
1689 } 1728 }
1690 blockSignals( false ); 1729 blockSignals( false );
1691 } 1730 }
1692 if ( remove ) { 1731 if ( remove ) {
1693 //qDebug("remove****************************************** "); 1732 //qDebug("remove****************************************** ");
1694 return; 1733 return;
1695 } 1734 }
1696 //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ "); 1735 //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ ");
1697 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < QDate::currentDate())&& ( KOPrefs::instance()->mShowTodoInAgenda ); 1736 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < QDate::currentDate())&& ( KOPrefs::instance()->mShowTodoInAgenda );
1698 QDate currentDate; 1737 QDate currentDate;
1699 QDateTime dt; 1738 QDateTime dt;
1700 if ( todo->hasCompletedDate() ) 1739 if ( todo->hasCompletedDate() )
1701 dt = todo->completed(); 1740 dt = todo->completed();
1702 else 1741 else
1703 dt = todo->dtDue(); 1742 dt = todo->dtDue();
1704 if ( overdue ) { 1743 if ( overdue ) {
1705 currentDate = QDate::currentDate(); 1744 currentDate = QDate::currentDate();
1706 days += todo->dtDue().date().daysTo( currentDate ); 1745 days += todo->dtDue().date().daysTo( currentDate );
1707 } 1746 }
1708 else 1747 else
1709 currentDate = dt.date(); 1748 currentDate = dt.date();
1710 1749
1711 if (( todo->doesFloat() || overdue) && !todo->hasCompletedDate() ) { 1750 if (( todo->doesFloat() || overdue) && !todo->hasCompletedDate() ) {
1712 if ( ! mAllDayMode ) return; 1751 if ( ! mAllDayMode ) return;
1713 // aldayagenda 1752 // aldayagenda
1714 globalFlagBlockAgendaItemPaint = 1; 1753 globalFlagBlockAgendaItemPaint = 1;
1715 item = insertAllDayItem(todo, currentDate,days, days); 1754 item = insertAllDayItem(todo, currentDate,days, days);
1716 item->show(); 1755 item->show();
1717 1756
1718 } 1757 }
1719 else { 1758 else {
1720 if ( mAllDayMode ) return; 1759 if ( mAllDayMode ) return;
1721 // mAgenda 1760 // mAgenda
1722 globalFlagBlockAgendaItemPaint = 1; 1761 globalFlagBlockAgendaItemPaint = 1;
1723 int endY = timeToY(dt.time()) - 1; 1762 int endY = timeToY(dt.time()) - 1;
1724 int hi = 12/KOPrefs::instance()->mHourSize; 1763 int hi = 12/KOPrefs::instance()->mHourSize;
1725 int startY = endY - 1-hi; 1764 int startY = endY - 1-hi;
1726 item = insertItem(todo,currentDate,days,startY,endY); 1765 item = insertItem(todo,currentDate,days,startY,endY);
1727 item->show(); 1766 item->show();
1728 } 1767 }
1729 qApp->processEvents(); 1768 qApp->processEvents();
1730 globalFlagBlockAgendaItemPaint = 0; 1769 globalFlagBlockAgendaItemPaint = 0;
1731 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); 1770 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems();
1732 KOAgendaItem *itemit; 1771 KOAgendaItem *itemit;
1733 for ( itemit=oldconflictItems.first(); itemit != 0; 1772 for ( itemit=oldconflictItems.first(); itemit != 0;
1734 itemit=oldconflictItems.next() ) { 1773 itemit=oldconflictItems.next() ) {
1735 globalFlagBlockAgendaItemUpdate = 0; 1774 globalFlagBlockAgendaItemUpdate = 0;
1736 itemit->repaintMe(); 1775 itemit->repaintMe();
1737 globalFlagBlockAgendaItemUpdate = 1; 1776 globalFlagBlockAgendaItemUpdate = 1;
1738 itemit->repaint(); 1777 itemit->repaint();
1739 } 1778 }
1740 globalFlagBlockAgendaItemUpdate = 0; 1779 globalFlagBlockAgendaItemUpdate = 0;
1741 item->repaintMe(); 1780 item->repaintMe();
1742 globalFlagBlockAgendaItemUpdate = 1; 1781 globalFlagBlockAgendaItemUpdate = 1;
1743 item->repaint(); 1782 item->repaint();
1744} 1783}
1745/* 1784/*
1746 Insert KOAgendaItem into agenda. 1785 Insert KOAgendaItem into agenda.
1747*/ 1786*/
1748KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom) 1787KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom)
1749{ 1788{
1750 if (mAllDayMode) { 1789 if (mAllDayMode) {
1751 qDebug("KOAgenda: calling insertItem in all-day mode is illegal. "); 1790 qDebug("KOAgenda: calling insertItem in all-day mode is illegal. ");
1752 return 0; 1791 return 0;
1753 } 1792 }
1754 1793
1755 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); 1794 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport());
1756 //agendaItem->setFrameStyle(WinPanel|Raised); 1795 //agendaItem->setFrameStyle(WinPanel|Raised);
1757 1796
1758 int YSize = YBottom - YTop + 1; 1797 int YSize = YBottom - YTop + 1;
1759 if (YSize < 0) { 1798 if (YSize < 0) {
1760 YSize = 1; 1799 YSize = 1;
1761 } 1800 }
1762 int iheight = mGridSpacingY * YSize; 1801 int iheight = mGridSpacingY * YSize;
1763 1802
1764 agendaItem->resize(mGridSpacingX,iheight ); 1803 agendaItem->resize(mGridSpacingX,iheight );
1765 agendaItem->setCellXY(X,YTop,YBottom); 1804 agendaItem->setCellXY(X,YTop,YBottom);
1766 agendaItem->setCellXWidth(X); 1805 agendaItem->setCellXWidth(X);
1767 1806
1768 //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY); 1807 //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY);
1769 mItems.append(agendaItem); 1808 mItems.append(agendaItem);
1770 1809
1771 placeSubCells(agendaItem); 1810 placeSubCells(agendaItem);
1772 1811
1773 //agendaItem->show(); 1812 //agendaItem->show();
1774 1813
1775 marcus_bains(); 1814 marcus_bains();
1776 1815
1777 return agendaItem; 1816 return agendaItem;
1778} 1817}
1779 1818
1780 1819
1781/* 1820/*
1782 Insert all-day KOAgendaItem into agenda. 1821 Insert all-day KOAgendaItem into agenda.
1783*/ 1822*/
1784KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd) 1823KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd)
1785{ 1824{
1786 if (!mAllDayMode) { 1825 if (!mAllDayMode) {
1787 return 0; 1826 return 0;
1788 } 1827 }
1789 1828
1790 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); 1829 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport());
1791 1830
1792 agendaItem->setCellXY(XBegin,0,0); 1831 agendaItem->setCellXY(XBegin,0,0);
1793 agendaItem->setCellXWidth(XEnd); 1832 agendaItem->setCellXWidth(XEnd);
1794 agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY); 1833 agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY);
1795 1834
1796 //addChild(agendaItem,XBegin*mGridSpacingX,0); 1835 //addChild(agendaItem,XBegin*mGridSpacingX,0);
1797 mItems.append(agendaItem); 1836 mItems.append(agendaItem);
1798 1837
1799 placeSubCells(agendaItem); 1838 placeSubCells(agendaItem);
1800 1839
1801 //agendaItem->show(); 1840 //agendaItem->show();
1802 1841
1803 return agendaItem; 1842 return agendaItem;
1804} 1843}
1805 1844
1806 1845
1807void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, 1846void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd,
1808 int YTop,int YBottom) 1847 int YTop,int YBottom)
1809{ 1848{
1810 if (mAllDayMode) { 1849 if (mAllDayMode) {
1811 ; 1850 ;
1812 return; 1851 return;
1813 } 1852 }
1814 1853
1815 int cellX,cellYTop,cellYBottom; 1854 int cellX,cellYTop,cellYBottom;
1816 QString newtext; 1855 QString newtext;
1817 int width = XEnd - XBegin + 1; 1856 int width = XEnd - XBegin + 1;
1818 int count = 0; 1857 int count = 0;
1819 KOAgendaItem *current = 0; 1858 KOAgendaItem *current = 0;
1820 QPtrList<KOAgendaItem> multiItems; 1859 QPtrList<KOAgendaItem> multiItems;
1821 for (cellX = XBegin;cellX <= XEnd;++cellX) { 1860 for (cellX = XBegin;cellX <= XEnd;++cellX) {
1822 if (cellX == XBegin) cellYTop = YTop; 1861 if (cellX == XBegin) cellYTop = YTop;
1823 else cellYTop = 0; 1862 else cellYTop = 0;
1824 if (cellX == XEnd) cellYBottom = YBottom; 1863 if (cellX == XEnd) cellYBottom = YBottom;
1825 else cellYBottom = rows() - 1; 1864 else cellYBottom = rows() - 1;
1826 newtext = QString("(%1/%2): ").arg(++count).arg(width); 1865 newtext = QString("(%1/%2): ").arg(++count).arg(width);
1827 newtext.append(event->summary()); 1866 newtext.append(event->summary());
1828 current = insertItem(event,qd,cellX,cellYTop,cellYBottom); 1867 current = insertItem(event,qd,cellX,cellYTop,cellYBottom);
1829 current->setText(newtext); 1868 current->setText(newtext);
1830 multiItems.append(current); 1869 multiItems.append(current);
1831 } 1870 }
1832 1871
1833 KOAgendaItem *next = 0; 1872 KOAgendaItem *next = 0;
1834 KOAgendaItem *last = multiItems.last(); 1873 KOAgendaItem *last = multiItems.last();
1835 KOAgendaItem *first = multiItems.first(); 1874 KOAgendaItem *first = multiItems.first();
1836 KOAgendaItem *setFirst,*setLast; 1875 KOAgendaItem *setFirst,*setLast;
1837 current = first; 1876 current = first;
1838 while (current) { 1877 while (current) {
1839 next = multiItems.next(); 1878 next = multiItems.next();
1840 if (current == first) setFirst = 0; 1879 if (current == first) setFirst = 0;
1841 else setFirst = first; 1880 else setFirst = first;
1842 if (current == last) setLast = 0; 1881 if (current == last) setLast = 0;
1843 else setLast = last; 1882 else setLast = last;
1844 1883
1845 current->setMultiItem(setFirst,next,setLast); 1884 current->setMultiItem(setFirst,next,setLast);
1846 current = next; 1885 current = next;
1847 } 1886 }
1848 1887
1849 marcus_bains(); 1888 marcus_bains();
1850} 1889}
1851 1890
1852 1891
1853//QSizePolicy KOAgenda::sizePolicy() const 1892//QSizePolicy KOAgenda::sizePolicy() const
1854//{ 1893//{
1855 // Thought this would make the all-day event agenda minimum size and the 1894 // Thought this would make the all-day event agenda minimum size and the
1856 // normal agenda take the remaining space. But it doesn´t work. The QSplitter 1895 // normal agenda take the remaining space. But it doesn´t work. The QSplitter
1857 // don´t seem to think that an Expanding widget needs more space than a 1896 // don´t seem to think that an Expanding widget needs more space than a
1858 // Preferred one. 1897 // Preferred one.
1859 // But it doesn´t hurt, so it stays. 1898 // But it doesn´t hurt, so it stays.
1860// if (mAllDayMode) { 1899// if (mAllDayMode) {
1861// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); 1900// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
1862// } else { 1901// } else {
1863// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); 1902// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
1864// } 1903// }
1865//} 1904//}
1866void KOAgenda::finishResize ( ) 1905void KOAgenda::finishResize ( )
1867{ 1906{
1868 //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) "); 1907 //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) ");
1869 if ( globalFlagBlockAgenda == 0 ) { 1908 if ( globalFlagBlockAgenda == 0 ) {
1870 finishUpdate(); 1909 finishUpdate();
1871 //qDebug("finishUpdate() called "); 1910 //qDebug("finishUpdate() called ");
1872 } 1911 }
1873} 1912}
1874/* 1913/*
1875 Overridden from QScrollView to provide proper resizing of KOAgendaItems. 1914 Overridden from QScrollView to provide proper resizing of KOAgendaItems.
1876*/ 1915*/
1877void KOAgenda::resizeEvent ( QResizeEvent *ev ) 1916void KOAgenda::resizeEvent ( QResizeEvent *ev )
1878{ 1917{
1879 1918
1880 mResizeTimer.start( 150 , true ); 1919 mResizeTimer.start( 150 , true );
1881 computeSizes(); 1920 computeSizes();
1882 return; 1921 return;
1883 1922
1884} 1923}
1885void KOAgenda::computeSizes() 1924void KOAgenda::computeSizes()
1886{ 1925{
1887 if ( globalFlagBlockStartup ) 1926 if ( globalFlagBlockStartup )
1888 return; 1927 return;
1889 int frameOffset = frameWidth() * 2 +1; 1928 int frameOffset = frameWidth() * 2 +1;
1890 if (mAllDayMode) { 1929 if (mAllDayMode) {
1891 mGridSpacingX = (width()-frameOffset) / mColumns; 1930 mGridSpacingX = (width()-frameOffset) / mColumns;
1892 mGridSpacingY = height() - 2 * frameWidth() - 1; 1931 mGridSpacingY = height() - 2 * frameWidth() - 1;
1893 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1); 1932 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1);
1894 // mGridSpacingY = height(); 1933 // mGridSpacingY = height();
1895 // resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1934 // resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1896 1935
1897 KOAgendaItem *item; 1936 KOAgendaItem *item;
1898 int subCellWidth; 1937 int subCellWidth;
1899 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1938 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1900 subCellWidth = mGridSpacingY / item->subCells(); 1939 subCellWidth = mGridSpacingY / item->subCells();
1901 item->resize(mGridSpacingX * item->cellWidth(),subCellWidth); 1940 item->resize(mGridSpacingX * item->cellWidth(),subCellWidth);
1902 moveChild(item,KOGlobals::self()->reverseLayout() ? 1941 moveChild(item,KOGlobals::self()->reverseLayout() ?
1903 (mColumns - 1 - item->cellX()) * mGridSpacingX : 1942 (mColumns - 1 - item->cellX()) * mGridSpacingX :
1904 item->cellX() * mGridSpacingX, 1943 item->cellX() * mGridSpacingX,
1905 item->subCell() * subCellWidth); 1944 item->subCell() * subCellWidth);
1906 } 1945 }
1907 KOPrefs::instance()->mAllDaySize = mGridSpacingY; 1946 KOPrefs::instance()->mAllDaySize = mGridSpacingY;
1908 } else { 1947 } else {
1909 mGridSpacingX = (width() - verticalScrollBar()->width()-frameOffset)/mColumns; 1948 mGridSpacingX = (width() - verticalScrollBar()->width()-frameOffset)/mColumns;
1910 if (height() > mGridSpacingY * mRows + 1 ) { 1949 if (height() > mGridSpacingY * mRows + 1 ) {
1911 KOPrefs::instance()->mHourSize = ((height())/mRows)+1; 1950 KOPrefs::instance()->mHourSize = ((height())/mRows)+1;
1912 mGridSpacingY = KOPrefs::instance()->mHourSize ; 1951 mGridSpacingY = KOPrefs::instance()->mHourSize ;
1913 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1952 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1914 emit resizedSignal(); 1953 emit resizedSignal();
1915 } else 1954 } else
1916 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1955 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1917 KOAgendaItem *item; 1956 KOAgendaItem *item;
1918 int subCellWidth; 1957 int subCellWidth;
1919 1958
1920 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1959 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1921 subCellWidth = mGridSpacingX / item->subCells(); 1960 subCellWidth = mGridSpacingX / item->subCells();
1922 item->resize(subCellWidth,item->height()); 1961 item->resize(subCellWidth,item->height());
1923 moveChild(item,(KOGlobals::self()->reverseLayout() ? 1962 moveChild(item,(KOGlobals::self()->reverseLayout() ?
1924 (mColumns - 1 - item->cellX()) * mGridSpacingX : 1963 (mColumns - 1 - item->cellX()) * mGridSpacingX :
1925 item->cellX() * mGridSpacingX) + 1964 item->cellX() * mGridSpacingX) +
1926 item->subCell() * subCellWidth,childY(item)); 1965 item->subCell() * subCellWidth,childY(item));
1927 } 1966 }
1928 } 1967 }
1929 int cw = contentsWidth(); 1968 int cw = contentsWidth();
1930 int ch = contentsHeight(); 1969 int ch = contentsHeight();
1931 if ( mAllDayMode ) { 1970 if ( mAllDayMode ) {
1932 QPixmap* paintPixAll = KOAgendaItem::paintPixAllday(); 1971 QPixmap* paintPixAll = KOAgendaItem::paintPixAllday();
1933 if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 ) 1972 if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 )
1934 paintPixAll->resize( cw, ch ); 1973 paintPixAll->resize( cw, ch );
1935 } else { 1974 } else {
1936 QPixmap* paintPix = KOAgendaItem::paintPix(); 1975 QPixmap* paintPix = KOAgendaItem::paintPix();
1937 if ( paintPix->width() < cw || paintPix->height() < ch ) 1976 if ( paintPix->width() < cw || paintPix->height() < ch )
1938 KOAgendaItem::resizePixmap( cw , ch ); 1977 KOAgendaItem::resizePixmap( cw , ch );
1939 } 1978 }
1940 1979
1941 checkScrollBoundaries(); 1980 checkScrollBoundaries();
1942 marcus_bains(); 1981 marcus_bains();
1943 drawContentsToPainter(); 1982 drawContentsToPainter();
1944 viewport()->repaint(false); 1983 viewport()->repaint(false);
1945} 1984}
1946 1985
1947void KOAgenda::scrollUp() 1986void KOAgenda::scrollUp()
1948{ 1987{
1949 scrollBy(0,-mScrollOffset); 1988 scrollBy(0,-mScrollOffset);
1950} 1989}
1951 1990
1952 1991
1953void KOAgenda::scrollDown() 1992void KOAgenda::scrollDown()
1954{ 1993{
1955 scrollBy(0,mScrollOffset); 1994 scrollBy(0,mScrollOffset);
1956} 1995}
1957 1996
1958void KOAgenda::popupAlarm() 1997void KOAgenda::popupAlarm()
1959{ 1998{
1960 if (!mClickedItem) { 1999 if (!mClickedItem) {
1961 qDebug("KOAgenda::popupAlarm() called without having a clicked item "); 2000 qDebug("KOAgenda::popupAlarm() called without having a clicked item ");
1962 return; 2001 return;
1963 } 2002 }
1964 // TODO: deal correctly with multiple alarms 2003 // TODO: deal correctly with multiple alarms
1965 Alarm* alarm; 2004 Alarm* alarm;
1966 QPtrList<Alarm> list(mClickedItem->incidence()->alarms()); 2005 QPtrList<Alarm> list(mClickedItem->incidence()->alarms());
1967 for(alarm=list.first();alarm;alarm=list.next()) { 2006 for(alarm=list.first();alarm;alarm=list.next()) {
1968 alarm->toggleAlarm(); 2007 alarm->toggleAlarm();
1969 } 2008 }
1970 emit itemModified( mClickedItem , KOGlobals::EVENTEDITED ); 2009 emit itemModified( mClickedItem , KOGlobals::EVENTEDITED );
1971 mClickedItem->paintMe( true ); 2010 mClickedItem->paintMe( true );
1972 mClickedItem->repaint( false ); 2011 mClickedItem->repaint( false );
1973} 2012}
1974 2013
1975/* 2014/*
1976 Calculates the minimum width 2015 Calculates the minimum width
1977*/ 2016*/
1978int KOAgenda::minimumWidth() const 2017int KOAgenda::minimumWidth() const
1979{ 2018{
1980 // TODO:: develop a way to dynamically determine the minimum width 2019 // TODO:: develop a way to dynamically determine the minimum width
1981 int min = 100; 2020 int min = 100;
1982 2021
1983 return min; 2022 return min;
1984} 2023}
1985 2024
1986void KOAgenda::updateConfig() 2025void KOAgenda::updateConfig()
1987{ 2026{
1988 if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor) 2027 if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor)
1989 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor); 2028 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor);
1990 if ( mAllDayMode ) { 2029 if ( mAllDayMode ) {
1991 mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize; 2030 mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize;
1992 //mGridSpacingY = KOPrefs::instance()->mAllDaySize; 2031 //mGridSpacingY = KOPrefs::instance()->mAllDaySize;
1993 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 ); 2032 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 );
1994 // setMaximumHeight( mGridSpacingY+1 ); 2033 // setMaximumHeight( mGridSpacingY+1 );
1995 viewport()->repaint( false ); 2034 viewport()->repaint( false );
1996 //setFixedHeight( mGridSpacingY+1 ); 2035 //setFixedHeight( mGridSpacingY+1 );
1997 //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize); 2036 //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize);
1998 } 2037 }
1999 else { 2038 else {
2000 mGridSpacingY = KOPrefs::instance()->mHourSize; 2039 mGridSpacingY = KOPrefs::instance()->mHourSize;
2001 calculateWorkingHours(); 2040 calculateWorkingHours();
2002 marcus_bains(); 2041 marcus_bains();
2003 } 2042 }
2004} 2043}
2005 2044
2006void KOAgenda::checkScrollBoundaries() 2045void KOAgenda::checkScrollBoundaries()
2007{ 2046{
2008 // Invalidate old values to force update 2047 // Invalidate old values to force update
2009 mOldLowerScrollValue = -1; 2048 mOldLowerScrollValue = -1;
2010 mOldUpperScrollValue = -1; 2049 mOldUpperScrollValue = -1;
2011 2050
2012 checkScrollBoundaries(verticalScrollBar()->value()); 2051 checkScrollBoundaries(verticalScrollBar()->value());
2013} 2052}
2014 2053
2015void KOAgenda::checkScrollBoundaries(int v) 2054void KOAgenda::checkScrollBoundaries(int v)
2016{ 2055{
2017 if ( mGridSpacingY == 0 ) 2056 if ( mGridSpacingY == 0 )
2018 return; 2057 return;
2019 int yMin = v/mGridSpacingY; 2058 int yMin = v/mGridSpacingY;
2020 int yMax = (v+visibleHeight())/mGridSpacingY; 2059 int yMax = (v+visibleHeight())/mGridSpacingY;
2021 2060
2022// kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl; 2061// kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl;
2023 2062
2024 if (yMin != mOldLowerScrollValue) { 2063 if (yMin != mOldLowerScrollValue) {
2025 mOldLowerScrollValue = yMin; 2064 mOldLowerScrollValue = yMin;
2026 emit lowerYChanged(yMin); 2065 emit lowerYChanged(yMin);
2027 } 2066 }
2028 if (yMax != mOldUpperScrollValue) { 2067 if (yMax != mOldUpperScrollValue) {
2029 mOldUpperScrollValue = yMax; 2068 mOldUpperScrollValue = yMax;
2030 emit upperYChanged(yMax); 2069 emit upperYChanged(yMax);
2031 } 2070 }
2032} 2071}
2033 2072
2034void KOAgenda::deselectItem() 2073void KOAgenda::deselectItem()
2035{ 2074{
2036 if (mSelectedItem.isNull()) return; 2075 if (mSelectedItem.isNull()) return;
2037 mSelectedItem->select(false); 2076 mSelectedItem->select(false);
2038 mSelectedItem = 0; 2077 mSelectedItem = 0;
2039} 2078}
2040 2079
2041void KOAgenda::selectItem(KOAgendaItem *item) 2080void KOAgenda::selectItem(KOAgendaItem *item)
2042{ 2081{
2043 if ((KOAgendaItem *)mSelectedItem == item) return; 2082 if ((KOAgendaItem *)mSelectedItem == item) return;
2044 deselectItem(); 2083 deselectItem();
2045 if (item == 0) { 2084 if (item == 0) {
2046 emit incidenceSelected( 0 ); 2085 emit incidenceSelected( 0 );
2047 return; 2086 return;
2048 } 2087 }
2049 mSelectedItem = item; 2088 mSelectedItem = item;
2050 mSelectedItem->select(); 2089 mSelectedItem->select();
2051 emit incidenceSelected( mSelectedItem->incidence() ); 2090 emit incidenceSelected( mSelectedItem->incidence() );
2052} 2091}
2053 2092
2054// This function seems never be called. 2093// This function seems never be called.
2055void KOAgenda::keyPressEvent( QKeyEvent *kev ) 2094void KOAgenda::keyPressEvent( QKeyEvent *kev )
2056{ 2095{
2057 switch(kev->key()) { 2096 switch(kev->key()) {
2058 case Key_PageDown: 2097 case Key_PageDown:
2059 verticalScrollBar()->addPage(); 2098 verticalScrollBar()->addPage();
2060 break; 2099 break;
2061 case Key_PageUp: 2100 case Key_PageUp:
2062 verticalScrollBar()->subtractPage(); 2101 verticalScrollBar()->subtractPage();
2063 break; 2102 break;
2064 case Key_Down: 2103 case Key_Down:
2065 verticalScrollBar()->addLine(); 2104 verticalScrollBar()->addLine();
2066 break; 2105 break;
2067 case Key_Up: 2106 case Key_Up:
2068 verticalScrollBar()->subtractLine(); 2107 verticalScrollBar()->subtractLine();
2069 break; 2108 break;
2070 default: 2109 default:
2071 ; 2110 ;
2072 } 2111 }
2073} 2112}
2074 2113
2075void KOAgenda::calculateWorkingHours() 2114void KOAgenda::calculateWorkingHours()
2076{ 2115{
2077// mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours; 2116// mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours;
2078 mWorkingHoursEnable = !mAllDayMode; 2117 mWorkingHoursEnable = !mAllDayMode;
2079 2118
2080 mWorkingHoursYTop = mGridSpacingY * 2119 mWorkingHoursYTop = mGridSpacingY *
2081 KOPrefs::instance()->mWorkingHoursStart * 4; 2120 KOPrefs::instance()->mWorkingHoursStart * 4;
2082 mWorkingHoursYBottom = mGridSpacingY * 2121 mWorkingHoursYBottom = mGridSpacingY *
2083 KOPrefs::instance()->mWorkingHoursEnd * 4 - 1; 2122 KOPrefs::instance()->mWorkingHoursEnd * 4 - 1;
2084} 2123}
2085 2124
2086 2125
2087DateList KOAgenda::dateList() const 2126DateList KOAgenda::dateList() const
2088{ 2127{
2089 return mSelectedDates; 2128 return mSelectedDates;
2090} 2129}
2091 2130
2092void KOAgenda::setDateList(const DateList &selectedDates) 2131void KOAgenda::setDateList(const DateList &selectedDates)
2093{ 2132{
2094 mSelectedDates = selectedDates; 2133 mSelectedDates = selectedDates;
2095 marcus_bains(); 2134 marcus_bains();
2096} 2135}
2097 2136
2098void KOAgenda::setHolidayMask(QMemArray<bool> *mask) 2137void KOAgenda::setHolidayMask(QMemArray<bool> *mask)
2099{ 2138{
2100 mHolidayMask = mask; 2139 mHolidayMask = mask;
2101 2140
2102/* 2141/*
2103 kdDebug() << "HolidayMask: "; 2142 kdDebug() << "HolidayMask: ";
2104 for(uint i=0;i<mask->count();++i) { 2143 for(uint i=0;i<mask->count();++i) {
2105 kdDebug() << (mask->at(i) ? "*" : "o"); 2144 kdDebug() << (mask->at(i) ? "*" : "o");
2106 } 2145 }
2107 kdDebug() << endl; 2146 kdDebug() << endl;
2108*/ 2147*/
2109} 2148}
2110 2149
2111void KOAgenda::contentsMousePressEvent ( QMouseEvent *event ) 2150void KOAgenda::contentsMousePressEvent ( QMouseEvent *event )
2112{ 2151{
2113 2152
2114 QScrollView::contentsMousePressEvent(event); 2153 QScrollView::contentsMousePressEvent(event);
2115} 2154}
2116 2155
2117void KOAgenda::storePosition() 2156void KOAgenda::storePosition()
2118{ 2157{
2119 //mContentPosition 2158 //mContentPosition
2120 int max = mGridSpacingY*4*24; 2159 int max = mGridSpacingY*4*24;
2121 if ( contentsY() < 5 && max > viewport()->height()*3/2 ) 2160 if ( contentsY() < 5 && max > viewport()->height()*3/2 )
2122 mContentPosition = 0; 2161 mContentPosition = 0;
2123 else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2) 2162 else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2)
2124 mContentPosition = -1.0; 2163 mContentPosition = -1.0;
2125 else 2164 else
2126 mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2))); 2165 mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2)));
2127 //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height()); 2166 //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height());
2128 2167
2129} 2168}
2130void KOAgenda::restorePosition() 2169void KOAgenda::restorePosition()
2131{ 2170{
2132 int posY; 2171 int posY;
2133 int max = mGridSpacingY*4*24; 2172 int max = mGridSpacingY*4*24;
2134 if ( mContentPosition < 0 ) 2173 if ( mContentPosition < 0 )
2135 posY = max-viewport()->height(); 2174 posY = max-viewport()->height();
2136 else 2175 else
2137 if ( mContentPosition == 0 ) 2176 if ( mContentPosition == 0 )
2138 posY = 0; 2177 posY = 0;
2139 else 2178 else
2140 posY = (max/mContentPosition)-(viewport()->height()/2); 2179 posY = (max/mContentPosition)-(viewport()->height()/2);
2141 setContentsPos (0, posY ); 2180 setContentsPos (0, posY );
2142 //qDebug("posY %d hei %d", posY, max); 2181 //qDebug("posY %d hei %d", posY, max);
2143 2182
2144} 2183}
2145void KOAgenda::moveChild( QWidget *w, int x , int y ) 2184void KOAgenda::moveChild( QWidget *w, int x , int y )
2146{ 2185{
2147 ++x; 2186 ++x;
2148 QScrollView::moveChild( w, x , y ); 2187 QScrollView::moveChild( w, x , y );
2149} 2188}
2150#include <qmessagebox.h> 2189#include <qmessagebox.h>
2151#ifdef DESKTOP_VERSION 2190#ifdef DESKTOP_VERSION
2152#include <qprinter.h> 2191#include <qprinter.h>
2153#include <qpainter.h> 2192#include <qpainter.h>
2154#include <qpaintdevicemetrics.h> 2193#include <qpaintdevicemetrics.h>
2155 2194
2156#endif 2195#endif
2157void KOAgenda::printSelection() 2196void KOAgenda::printSelection()
2158{ 2197{
2159#ifdef DESKTOP_VERSION 2198#ifdef DESKTOP_VERSION
2160 if ( mStartCellY == mCurrentCellY ) { 2199 if ( mStartCellY == mCurrentCellY ) {
2161 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2200 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2162 i18n("Nothing selected!\n\nThis prints the full width of the Agenda view as you see it!\n\nTo determine the vertical range of the printing, please select\na vertical range (with the left mouse button down) in one column. "), 2201 i18n("Nothing selected!\n\nThis prints the full width of the Agenda view as you see it!\n\nTo determine the vertical range of the printing, please select\na vertical range (with the left mouse button down) in one column. "),
2163 i18n("OK"), 0, 0, 2202 i18n("OK"), 0, 0,
2164 0, 1 ); 2203 0, 1 );
2165 return; 2204 return;
2166 } 2205 }
2167 2206
2168 float dx, dy; 2207 float dx, dy;
2169 int x,y,w,h; 2208 int x,y,w,h;
2170 x= 0; 2209 x= 0;
2171 w= contentsWidth()+2; 2210 w= contentsWidth()+2;
2172 // h= contentsHeight(); 2211 // h= contentsHeight();
2173 y = mGridSpacingY*mStartCellY; 2212 y = mGridSpacingY*mStartCellY;
2174 h = mGridSpacingY*(mCurrentCellY+1)-y+2; 2213 h = mGridSpacingY*(mCurrentCellY+1)-y+2;
2175 2214
2176 //return; 2215 //return;
2177 QPrinter* printer = new QPrinter(); 2216 QPrinter* printer = new QPrinter();
2178 if ( !printer->setup()) { 2217 if ( !printer->setup()) {
2179 delete printer; 2218 delete printer;
2180 return; 2219 return;
2181 } 2220 }
2182 QPainter p( printer ); 2221 QPainter p( printer );
2183 QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer ); 2222 QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer );
2184 QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() ); 2223 QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() );
2185 //date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true ); 2224 //date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true );
2186 int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height(); 2225 int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height();
2187 // p.drawText( 0, 0, date ); 2226 // p.drawText( 0, 0, date );
2188 int offset = m.width()/8; 2227 int offset = m.width()/8;
2189 // compute the scale 2228 // compute the scale
2190 dx = ((float) m.width()-offset) / (float)w; 2229 dx = ((float) m.width()-offset) / (float)w;
2191 dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h; 2230 dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h;
2192 float scale; 2231 float scale;
2193 // scale to fit the width or height of the paper 2232 // scale to fit the width or height of the paper
2194 if ( dx < dy ) 2233 if ( dx < dy )
2195 scale = dx; 2234 scale = dx;
2196 else 2235 else
2197 scale = dy; 2236 scale = dy;
2198 // set the scale 2237 // set the scale
2199 p.drawText( offset* scale, offset* scale*3/4, date ); 2238 p.drawText( offset* scale, offset* scale*3/4, date );
2200 2239
2201 int selDay; 2240 int selDay;
2202 float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count())); 2241 float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count()));
2203 float startX = 1; 2242 float startX = 1;
2204 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) 2243 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay)
2205 { 2244 {
2206 QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true ); 2245 QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true );
2207 p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) ); 2246 p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) );
2208 p.drawText( offset* scale+startX, (offset+hei)* scale, text ); 2247 p.drawText( offset* scale+startX, (offset+hei)* scale, text );
2209 startX += widOffset; 2248 startX += widOffset;
2210 2249
2211 } 2250 }
2212 p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale)); 2251 p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale));
2213 p.scale( scale, scale ); 2252 p.scale( scale, scale );
2214 p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale ); 2253 p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale );
2215 // now printing with y offset: 2 hei 2254 // now printing with y offset: 2 hei
2216 // p.translate( 0, -y*scale); 2255 // p.translate( 0, -y*scale);
2217 2256
2218 drawContentsToPainter(&p, true ); 2257 drawContentsToPainter(&p, true );
2219 globalFlagBlockAgendaItemUpdate = false; 2258 globalFlagBlockAgendaItemUpdate = false;
2220 KOAgendaItem *item; 2259 KOAgendaItem *item;
2221 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 2260 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
2222 item->select(false); 2261 item->select(false);
2223 item->paintMe( false, &p ); 2262 item->paintMe( false, &p );
2224 } 2263 }
2225 globalFlagBlockAgendaItemUpdate = true; 2264 globalFlagBlockAgendaItemUpdate = true;
2226 p.end(); 2265 p.end();
2227 delete printer; 2266 delete printer;
2228#else 2267#else
2229 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2268 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2230 i18n("Not supported \non PDA!\n"), 2269 i18n("Not supported \non PDA!\n"),
2231 i18n("OK"), 0, 0, 2270 i18n("OK"), 0, 0,
2232 0, 1 ); 2271 0, 1 );
2233#endif 2272#endif
2234} 2273}
diff --git a/korganizer/koagenda.h b/korganizer/koagenda.h
index 35c08b6..4f1fdb9 100644
--- a/korganizer/koagenda.h
+++ b/korganizer/koagenda.h
@@ -1,296 +1,298 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 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#ifndef KOAGENDA_H 23#ifndef KOAGENDA_H
24#define KOAGENDA_H 24#define KOAGENDA_H
25 25
26#include <qscrollview.h> 26#include <qscrollview.h>
27#include <qtimer.h> 27#include <qtimer.h>
28#include <qmemarray.h> 28#include <qmemarray.h>
29#include <qpainter.h> 29#include <qpainter.h>
30#include <qpixmap.h> 30#include <qpixmap.h>
31#include <qguardedptr.h> 31#include <qguardedptr.h>
32 32
33#include "koagendaitem.h" 33#include "koagendaitem.h"
34#include "koeventview.h"
34 35
35class QPopupMenu; 36class QPopupMenu;
36class QTime; 37class QTime;
37class KConfig; 38class KConfig;
38class QFrame; 39class QFrame;
39class KOAgenda; 40class KOAgenda;
40class KCal::Event; 41class KCal::Event;
41class KCal::Todo; 42class KCal::Todo;
42 43
43using namespace KCal; 44using namespace KCal;
44 45
45class MarcusBains : public QFrame { 46class MarcusBains : public QFrame {
46 Q_OBJECT 47 Q_OBJECT
47 public: 48 public:
48 MarcusBains(KOAgenda *agenda=0,const char *name=0); 49 MarcusBains(KOAgenda *agenda=0,const char *name=0);
49 virtual ~MarcusBains(); 50 virtual ~MarcusBains();
50 51
51 public slots: 52 public slots:
52 void updateLocation(bool recalculate=false); 53 void updateLocation(bool recalculate=false);
53 void updateLoc(); 54 void updateLoc();
54 55
55 private: 56 private:
56 int todayColumn(); 57 int todayColumn();
57 QTimer *minutes; 58 QTimer *minutes;
58 QLabel *mTimeBox; 59 QLabel *mTimeBox;
59 KOAgenda *agenda; 60 KOAgenda *agenda;
60 QTime oldTime; 61 QTime oldTime;
61 int oldToday; 62 int oldToday;
62}; 63};
63 64
64 65
65class KOAgenda : public QScrollView 66class KOAgenda : public QScrollView
66{ 67{
67 Q_OBJECT 68 Q_OBJECT
68 public: 69 public:
69 enum MouseActionType { NOP, MOVE, SELECT, 70 enum MouseActionType { NOP, MOVE, SELECT,
70 RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT }; 71 RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT };
71 72
72 KOAgenda ( int columns, int rows, int columnSize, QWidget * parent=0, 73 KOAgenda ( int columns, int rows, int columnSize, QWidget * parent=0,
73 const char * name=0, WFlags f=0 ); 74 const char * name=0, WFlags f=0 );
74 KOAgenda ( int columns, QWidget * parent=0, 75 KOAgenda ( int columns, QWidget * parent=0,
75 const char * name=0, WFlags f=0 ); 76 const char * name=0, WFlags f=0 );
76 virtual ~KOAgenda(); 77 virtual ~KOAgenda();
77 78
78 Incidence *selectedIncidence() const; 79 Incidence *selectedIncidence() const;
79 QDate selectedIncidenceDate() const; 80 QDate selectedIncidenceDate() const;
80 81
81 virtual bool eventFilter ( QObject *, QEvent * ); 82 virtual bool eventFilter ( QObject *, QEvent * );
82 83
83 void contentsToGrid (int x, int y, int& gx, int& gy); 84 void contentsToGrid (int x, int y, int& gx, int& gy);
84 void gridToContents (int gx, int gy, int& x, int& y); 85 void gridToContents (int gx, int gy, int& x, int& y);
85 86
86 int timeToY (const QTime &time); 87 int timeToY (const QTime &time);
87 QTime gyToTime (int y); 88 QTime gyToTime (int y);
88 89
89 void setStartHour(int startHour); 90 void setStartHour(int startHour);
90 91
91 KOAgendaItem *insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom); 92 KOAgendaItem *insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom);
92 KOAgendaItem *insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd); 93 KOAgendaItem *insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd);
93 void insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, 94 void insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd,
94 int YTop,int YBottom); 95 int YTop,int YBottom);
95 96
96 void changeColumns(int columns); 97 void changeColumns(int columns);
97 98
98 int columns() { return mColumns; } 99 int columns() { return mColumns; }
99 int rows() { return mRows; } 100 int rows() { return mRows; }
100 101
101 int gridSpacingX() const { return mGridSpacingX; } 102 int gridSpacingX() const { return mGridSpacingX; }
102 int gridSpacingY() const { return mGridSpacingY; } 103 int gridSpacingY() const { return mGridSpacingY; }
103 104
104// virtual QSizePolicy sizePolicy() const; 105// virtual QSizePolicy sizePolicy() const;
105 106
106 void clear(); 107 void clear();
107 108
108 void clearSelection(); 109 void clearSelection();
109 void hideUnused(); 110 void hideUnused();
110 111
111 /** Calculates the minimum width */ 112 /** Calculates the minimum width */
112 virtual int minimumWidth() const; 113 virtual int minimumWidth() const;
113 /** Update configuration from preference settings */ 114 /** Update configuration from preference settings */
114 void updateConfig(); 115 void updateConfig();
115 116
116 void checkScrollBoundaries(); 117 void checkScrollBoundaries();
117 118
118 void setHolidayMask(QMemArray<bool> *); 119 void setHolidayMask(QMemArray<bool> *);
119 void setDateList(const DateList &selectedDates); 120 void setDateList(const DateList &selectedDates);
120 DateList dateList() const; 121 DateList dateList() const;
121 void drawContentsToPainter( QPainter* paint = 0, bool backgroundOnly = false); 122 void drawContentsToPainter( QPainter* paint = 0, bool backgroundOnly = false);
122 void finishUpdate(); 123 void finishUpdate();
123 void printSelection(); 124 void printSelection();
124 void storePosition(); 125 void storePosition();
125 void restorePosition(); 126 void restorePosition();
126 127 void setPopup( KOEventPopupMenu * p ) { mAllAgendaPopup = p; }
127 128
128 public slots: 129 public slots:
129 void popupMenu(); 130 void popupMenu();
130 void newItem( int ); 131 void newItem( int );
131 void moveChild( QWidget *, int, int ); 132 void moveChild( QWidget *, int, int );
132 void scrollUp(); 133 void scrollUp();
133 void scrollDown(); 134 void scrollDown();
134 void updateTodo( Todo * t, int , bool ); 135 void updateTodo( Todo * t, int , bool );
135 void popupAlarm(); 136 void popupAlarm();
136 137
137 void checkScrollBoundaries(int); 138 void checkScrollBoundaries(int);
138 139
139 /** Deselect selected items. This function does not emit any signals. */ 140 /** Deselect selected items. This function does not emit any signals. */
140 void deselectItem(); 141 void deselectItem();
141 /** Select item. If the argument is 0, the currently selected item gets 142 /** Select item. If the argument is 0, the currently selected item gets
142 deselected. This function emits the itemSelected(bool) signal to inform 143 deselected. This function emits the itemSelected(bool) signal to inform
143 about selection/deseelction of events. */ 144 about selection/deseelction of events. */
144 void selectItem(KOAgendaItem *); 145 void selectItem(KOAgendaItem *);
145 void finishResize(); 146 void finishResize();
146 147
147 signals: 148 signals:
148 void showDateView( int, int); 149 void showDateView( int, int);
149 void newEventSignal(); 150 void newEventSignal();
150 void newEventSignal(int gx,int gy); 151 void newEventSignal(int gx,int gy);
151 void newTodoSignal(int gx,int gy); 152 void newTodoSignal(int gx,int gy);
152 void newEventSignal(int gxStart, int gyStart, int gxEnd, int gyEnd); 153 void newEventSignal(int gxStart, int gyStart, int gxEnd, int gyEnd);
153 void newTimeSpanSignal(int gxStart, int gyStart, int gxEnd, int gyEnd); 154 void newTimeSpanSignal(int gxStart, int gyStart, int gxEnd, int gyEnd);
154 void newStartSelectSignal(); 155 void newStartSelectSignal();
155 void showIncidenceSignal(Incidence *); 156 void showIncidenceSignal(Incidence *);
156 void editIncidenceSignal(Incidence *); 157 void editIncidenceSignal(Incidence *);
157 void deleteIncidenceSignal(Incidence *); 158 void deleteIncidenceSignal(Incidence *);
158 void showIncidencePopupSignal(Incidence *); 159 void showIncidencePopupSignal(Incidence *);
159 160
160 void itemModified(KOAgendaItem *item, int ); 161 void itemModified(KOAgendaItem *item, int );
161 void incidenceSelected(Incidence *); 162 void incidenceSelected(Incidence *);
162 163
163 void lowerYChanged(int); 164 void lowerYChanged(int);
164 void upperYChanged(int); 165 void upperYChanged(int);
165 166
166 void startDragSignal(Incidence *); 167 void startDragSignal(Incidence *);
167 void addToCalSignal(Incidence *, Incidence *); 168 void addToCalSignal(Incidence *, Incidence *);
168 void resizedSignal(); 169 void resizedSignal();
169 170
170 protected: 171 protected:
172 KOEventPopupMenu * mAllAgendaPopup;
171 QPainter mPixPainter; 173 QPainter mPixPainter;
172 QPixmap mPaintPixmap; 174 QPixmap mPaintPixmap;
173 QPixmap mHighlightPixmap; 175 QPixmap mHighlightPixmap;
174 void drawContents(QPainter *p,int cx, int cy, int cw, int ch); 176 void drawContents(QPainter *p,int cx, int cy, int cw, int ch);
175 virtual void resizeEvent ( QResizeEvent * ); 177 virtual void resizeEvent ( QResizeEvent * );
176 178
177 /** Handles mouse events. Called from eventFilter */ 179 /** Handles mouse events. Called from eventFilter */
178 virtual bool eventFilter_mouse ( QObject *, QMouseEvent * ); 180 virtual bool eventFilter_mouse ( QObject *, QMouseEvent * );
179 181
180 /** Start selecting time span. */ 182 /** Start selecting time span. */
181 void startSelectAction(QPoint viewportPos); 183 void startSelectAction(QPoint viewportPos);
182 184
183 /** Select time span. */ 185 /** Select time span. */
184 void performSelectAction(QPoint viewportPos); 186 void performSelectAction(QPoint viewportPos);
185 187
186 /** Emd selecting time span. */ 188 /** Emd selecting time span. */
187 void endSelectAction( bool emitNewEvent = false ); 189 void endSelectAction( bool emitNewEvent = false );
188 190
189 /** Start moving/resizing agenda item */ 191 /** Start moving/resizing agenda item */
190 void startItemAction(QPoint viewportPos); 192 void startItemAction(QPoint viewportPos);
191 193
192 /** Move/resize agenda item */ 194 /** Move/resize agenda item */
193 void performItemAction(QPoint viewportPos); 195 void performItemAction(QPoint viewportPos);
194 196
195 /** End moving/resizing agenda item */ 197 /** End moving/resizing agenda item */
196 void endItemAction(); 198 void endItemAction();
197 199
198 /** Set cursor, when no item action is in progress */ 200 /** Set cursor, when no item action is in progress */
199 void setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos); 201 void setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos);
200 202
201 /** Place agenda item in agenda and adjust other cells if necessary */ 203 /** Place agenda item in agenda and adjust other cells if necessary */
202 void placeSubCells(KOAgendaItem *placeItem); 204 void placeSubCells(KOAgendaItem *placeItem);
203 205
204 /** Process the keyevent, including the ignored keyevents of eventwidgets. 206 /** Process the keyevent, including the ignored keyevents of eventwidgets.
205 * Implements pgup/pgdn and cursor key navigation in the view. 207 * Implements pgup/pgdn and cursor key navigation in the view.
206 */ 208 */
207 void keyPressEvent( QKeyEvent * ); 209 void keyPressEvent( QKeyEvent * );
208 210
209 void calculateWorkingHours(); 211 void calculateWorkingHours();
210 212
211 virtual void contentsMousePressEvent ( QMouseEvent * ); 213 virtual void contentsMousePressEvent ( QMouseEvent * );
212 214
213 private: 215 private:
214 void init(); 216 void init();
215 void marcus_bains(); 217 void marcus_bains();
216 bool mAllDayMode; 218 bool mAllDayMode;
217 bool blockResize; 219 bool blockResize;
218 bool mLeftMouseDown; 220 bool mLeftMouseDown;
219 KOAgendaItem *mPopupItem; 221 KOAgendaItem *mPopupItem;
220 QTimer* mPopupTimer; 222 QTimer* mPopupTimer;
221 int mPopupKind; 223 int mPopupKind;
222 QPoint mPopupPos; 224 QPoint mPopupPos;
223 QTimer mResizeTimer; 225 QTimer mResizeTimer;
224 double mContentPosition; 226 double mContentPosition;
225 227
226 // Width and height of agenda cells 228 // Width and height of agenda cells
227 int mGridSpacingX; 229 int mGridSpacingX;
228 int mGridSpacingY; 230 int mGridSpacingY;
229 231
230 // size of border, where mouse action will resize the KOAgendaItem 232 // size of border, where mouse action will resize the KOAgendaItem
231 int mResizeBorderWidth; 233 int mResizeBorderWidth;
232 234
233 // size of border, where mouse mve will cause a scroll of the agenda 235 // size of border, where mouse mve will cause a scroll of the agenda
234 int mScrollBorderWidth; 236 int mScrollBorderWidth;
235 int mScrollDelay; 237 int mScrollDelay;
236 int mScrollOffset; 238 int mScrollOffset;
237 239
238 QTimer mScrollUpTimer; 240 QTimer mScrollUpTimer;
239 QTimer mScrollDownTimer; 241 QTimer mScrollDownTimer;
240 242
241 // Number of Columns/Rows of agenda grid 243 // Number of Columns/Rows of agenda grid
242 int mColumns; 244 int mColumns;
243 int mRows; 245 int mRows;
244 246
245 // Cells to store Move and Resize coordiantes 247 // Cells to store Move and Resize coordiantes
246 int mStartCellX; 248 int mStartCellX;
247 int mStartCellY; 249 int mStartCellY;
248 int mCurrentCellX; 250 int mCurrentCellX;
249 int mCurrentCellY; 251 int mCurrentCellY;
250 252
251 // Working Hour coordiantes 253 // Working Hour coordiantes
252 bool mWorkingHoursEnable; 254 bool mWorkingHoursEnable;
253 int mWorkingHoursYTop; 255 int mWorkingHoursYTop;
254 int mWorkingHoursYBottom; 256 int mWorkingHoursYBottom;
255 257
256 // Selection 258 // Selection
257 int mSelectionCellX; 259 int mSelectionCellX;
258 int mSelectionYTop; 260 int mSelectionYTop;
259 int mSelectionHeight; 261 int mSelectionHeight;
260 262
261 // List of dates to be displayed 263 // List of dates to be displayed
262 DateList mSelectedDates; 264 DateList mSelectedDates;
263 265
264 // The KOAgendaItem, which has been right-clicked last 266 // The KOAgendaItem, which has been right-clicked last
265 KOAgendaItem *mClickedItem; 267 KOAgendaItem *mClickedItem;
266 268
267 // The KOAgendaItem, which is being moved/resized 269 // The KOAgendaItem, which is being moved/resized
268 QGuardedPtr<KOAgendaItem> mActionItem; 270 QGuardedPtr<KOAgendaItem> mActionItem;
269 271
270 // Currently selected item 272 // Currently selected item
271 QGuardedPtr<KOAgendaItem> mSelectedItem; 273 QGuardedPtr<KOAgendaItem> mSelectedItem;
272 274
273 // The Marcus Bains Line widget. 275 // The Marcus Bains Line widget.
274 MarcusBains *mMarcusBains; 276 MarcusBains *mMarcusBains;
275 void computeSizes(); 277 void computeSizes();
276 278
277 MouseActionType mActionType; 279 MouseActionType mActionType;
278 280
279 bool mItemMoved; 281 bool mItemMoved;
280 282
281 // List of all Items contained in agenda 283 // List of all Items contained in agenda
282 QPtrList<KOAgendaItem> mItems; 284 QPtrList<KOAgendaItem> mItems;
283 QPtrList<KOAgendaItem> mUnusedItems; 285 QPtrList<KOAgendaItem> mUnusedItems;
284 KOAgendaItem* getNewItem(Incidence * event,QDate qd, QWidget* viewport); 286 KOAgendaItem* getNewItem(Incidence * event,QDate qd, QWidget* viewport);
285 QPopupMenu *mItemPopup; // Right mouse button popup menu for KOAgendaItems 287 QPopupMenu *mItemPopup; // Right mouse button popup menu for KOAgendaItems
286 QPopupMenu *mNewItemPopup; 288 QPopupMenu *mNewItemPopup;
287 289
288 int mOldLowerScrollValue; 290 int mOldLowerScrollValue;
289 int mOldUpperScrollValue; 291 int mOldUpperScrollValue;
290 KOAgendaItem * getItemForTodo ( Todo * todo ); 292 KOAgendaItem * getItemForTodo ( Todo * todo );
291 QMemArray<bool> *mHolidayMask; 293 QMemArray<bool> *mHolidayMask;
292 int mCurPixWid; 294 int mCurPixWid;
293 int mCurPixHei; 295 int mCurPixHei;
294}; 296};
295 297
296#endif // KOAGENDA_H 298#endif // KOAGENDA_H
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp
index 8d32152..95388ef 100644
--- a/korganizer/koagendaview.cpp
+++ b/korganizer/koagendaview.cpp
@@ -1,1700 +1,1702 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 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 <qhbox.h> 24#include <qhbox.h>
25#include <qvbox.h> 25#include <qvbox.h>
26#include <qlabel.h> 26#include <qlabel.h>
27#include <qframe.h> 27#include <qframe.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#ifndef KORG_NOSPLITTER 29#ifndef KORG_NOSPLITTER
30#include <qsplitter.h> 30#include <qsplitter.h>
31#endif 31#endif
32#include <qfont.h> 32#include <qfont.h>
33#include <qfontmetrics.h> 33#include <qfontmetrics.h>
34#include <qpopupmenu.h> 34#include <qpopupmenu.h>
35#include <qtooltip.h> 35#include <qtooltip.h>
36#include <qpainter.h> 36#include <qpainter.h>
37#include <qpushbutton.h> 37#include <qpushbutton.h>
38#include <qapplication.h> 38#include <qapplication.h>
39 39
40#include <kapplication.h> 40#include <kapplication.h>
41#include <KDGanttMinimizeSplitter.h> 41#include <KDGanttMinimizeSplitter.h>
42#include <kdebug.h> 42#include <kdebug.h>
43#include <kstandarddirs.h> 43#include <kstandarddirs.h>
44#include <kiconloader.h> 44#include <kiconloader.h>
45#include <klocale.h> 45#include <klocale.h>
46#include <kconfig.h> 46#include <kconfig.h>
47#include <kglobal.h> 47#include <kglobal.h>
48#include "calendarview.h" 48#include "calendarview.h"
49#include "koviewmanager.h" 49#include "koviewmanager.h"
50 50
51#include <libkcal/calendar.h> 51#include <libkcal/calendar.h>
52#include <libkcal/icaldrag.h> 52#include <libkcal/icaldrag.h>
53#include <libkcal/dndfactory.h> 53#include <libkcal/dndfactory.h>
54 54
55#include <kcalendarsystem.h> 55#include <kcalendarsystem.h>
56 56
57#include "koglobals.h" 57#include "koglobals.h"
58#ifndef KORG_NOPLUGINS 58#ifndef KORG_NOPLUGINS
59#include "kocore.h" 59#include "kocore.h"
60#endif 60#endif
61#include "koprefs.h" 61#include "koprefs.h"
62#include "koagenda.h" 62#include "koagenda.h"
63#include "koagendaitem.h" 63#include "koagendaitem.h"
64#ifndef KORG_NOPRINTER 64#ifndef KORG_NOPRINTER
65#include "calprinter.h" 65#include "calprinter.h"
66#endif 66#endif
67 67
68#include "koagendaview.h" 68#include "koagendaview.h"
69//#include "koagendaview.moc" 69//#include "koagendaview.moc"
70 70
71//extern bool globalFlagBlockPainting; 71//extern bool globalFlagBlockPainting;
72extern int globalFlagBlockAgenda; 72extern int globalFlagBlockAgenda;
73extern int globalFlagBlockStartup; 73extern int globalFlagBlockStartup;
74extern int globalFlagBlockAgendaItemPaint; 74extern int globalFlagBlockAgendaItemPaint;
75extern int globalFlagBlockAgendaItemUpdate; 75extern int globalFlagBlockAgendaItemUpdate;
76extern int globalFlagBlockLabel; 76extern int globalFlagBlockLabel;
77using namespace KOrg; 77using namespace KOrg;
78 78
79 79
80 80
81TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) : 81TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) :
82 QScrollView(parent,name,f) 82 QScrollView(parent,name,f)
83{ 83{
84 myPix.resize( 1, 1 ); 84 myPix.resize( 1, 1 );
85 mRows = rows; 85 mRows = rows;
86 86
87 mRedrawNeeded = true; 87 mRedrawNeeded = true;
88 setMinimumHeight( 20 ); 88 setMinimumHeight( 20 );
89 mCellHeight = KOPrefs::instance()->mHourSize*4; 89 mCellHeight = KOPrefs::instance()->mHourSize*4;
90 90
91 enableClipper(true); 91 enableClipper(true);
92 92
93 setHScrollBarMode(AlwaysOff); 93 setHScrollBarMode(AlwaysOff);
94 setVScrollBarMode(AlwaysOff); 94 setVScrollBarMode(AlwaysOff);
95 95
96 resizeContents(50,mRows * mCellHeight); 96 resizeContents(50,mRows * mCellHeight);
97 97
98 viewport()->setBackgroundMode( PaletteBackground ); 98 viewport()->setBackgroundMode( PaletteBackground );
99} 99}
100 100
101void TimeLabels::setCellHeight(int height) 101void TimeLabels::setCellHeight(int height)
102{ 102{
103 mCellHeight = height; 103 mCellHeight = height;
104} 104}
105 105
106/* 106/*
107 Optimization so that only the "dirty" portion of the scroll view 107 Optimization so that only the "dirty" portion of the scroll view
108 is redrawn. Unfortunately, this is not called by default paintEvent() method. 108 is redrawn. Unfortunately, this is not called by default paintEvent() method.
109*/ 109*/
110void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) 110void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch)
111{ 111{
112 112
113 cx = contentsX() + frameWidth()*2; 113 cx = contentsX() + frameWidth()*2;
114 cw = contentsWidth() ; 114 cw = contentsWidth() ;
115 // end of workaround 115 // end of workaround
116 116
117 int cell = ((int)(cy/mCellHeight)); 117 int cell = ((int)(cy/mCellHeight));
118 int y = cell * mCellHeight; 118 int y = cell * mCellHeight;
119 QFontMetrics fm = fontMetrics(); 119 QFontMetrics fm = fontMetrics();
120 QString hour; 120 QString hour;
121 QString suffix = "am"; 121 QString suffix = "am";
122 int timeHeight = fm.ascent(); 122 int timeHeight = fm.ascent();
123 QFont nFont = p->font(); 123 QFont nFont = p->font();
124 124
125 if (!KGlobal::locale()->use12Clock()) { 125 if (!KGlobal::locale()->use12Clock()) {
126 if ( QApplication::desktop()->width() <= 320 ) 126 if ( QApplication::desktop()->width() <= 320 )
127 suffix = "00"; 127 suffix = "00";
128 else 128 else
129 suffix = "00"; 129 suffix = "00";
130 } 130 }
131 131
132 if ( timeHeight > mCellHeight ) { 132 if ( timeHeight > mCellHeight ) {
133 timeHeight = mCellHeight-1; 133 timeHeight = mCellHeight-1;
134 int pointS = nFont.pointSize(); 134 int pointS = nFont.pointSize();
135 while ( pointS > 4 ) { 135 while ( pointS > 4 ) {
136 nFont.setPointSize( pointS ); 136 nFont.setPointSize( pointS );
137 fm = QFontMetrics( nFont ); 137 fm = QFontMetrics( nFont );
138 if ( fm.ascent() < mCellHeight ) 138 if ( fm.ascent() < mCellHeight )
139 break; 139 break;
140 -- pointS; 140 -- pointS;
141 } 141 }
142 fm = QFontMetrics( nFont ); 142 fm = QFontMetrics( nFont );
143 timeHeight = fm.ascent(); 143 timeHeight = fm.ascent();
144 } 144 }
145 //timeHeight -= (timeHeight/4-2); 145 //timeHeight -= (timeHeight/4-2);
146 QFont sFont = nFont; 146 QFont sFont = nFont;
147 sFont.setPointSize( sFont.pointSize()/2 ); 147 sFont.setPointSize( sFont.pointSize()/2 );
148 QFontMetrics fmS( sFont ); 148 QFontMetrics fmS( sFont );
149 int sHei = fmS.ascent() ; 149 int sHei = fmS.ascent() ;
150 //sHei -= (sHei/4-2); 150 //sHei -= (sHei/4-2);
151 int startW = this->width() - frameWidth()-2; 151 int startW = this->width() - frameWidth()-2;
152 int tw2 = fmS.width(suffix); 152 int tw2 = fmS.width(suffix);
153 timeHeight = (timeHeight-1) /2 -1; 153 timeHeight = (timeHeight-1) /2 -1;
154 while (y < cy + ch+mCellHeight) { 154 while (y < cy + ch+mCellHeight) {
155 p->drawLine(startW-tw2+1 ,y,cw,y); 155 p->drawLine(startW-tw2+1 ,y,cw,y);
156 hour.setNum(cell); 156 hour.setNum(cell);
157 // handle 24h and am/pm time formats 157 // handle 24h and am/pm time formats
158 if (KGlobal::locale()->use12Clock()) { 158 if (KGlobal::locale()->use12Clock()) {
159 if (cell > 11) suffix = "pm"; 159 if (cell > 11) suffix = "pm";
160 else 160 else
161 suffix = "am"; 161 suffix = "am";
162 if (cell == 0) hour.setNum(12); 162 if (cell == 0) hour.setNum(12);
163 if (cell > 12) hour.setNum(cell - 12); 163 if (cell > 12) hour.setNum(cell - 12);
164 } 164 }
165 165
166 // center and draw the time label 166 // center and draw the time label
167 int timeWidth = fm.width(hour); 167 int timeWidth = fm.width(hour);
168 int offset = startW - timeWidth - tw2 ; 168 int offset = startW - timeWidth - tw2 ;
169 p->setFont( nFont ); 169 p->setFont( nFont );
170 p->drawText( offset, y+ timeHeight, hour); 170 p->drawText( offset, y+ timeHeight, hour);
171 p->setFont( sFont ); 171 p->setFont( sFont );
172 offset = startW - tw2+1; 172 offset = startW - tw2+1;
173 p->drawText( offset, y -1, suffix); 173 p->drawText( offset, y -1, suffix);
174 174
175 // increment indices 175 // increment indices
176 y += mCellHeight; 176 y += mCellHeight;
177 cell++; 177 cell++;
178 } 178 }
179 179
180 180
181 181
182 182
183#if 0 183#if 0
184 mRedrawNeeded = true; 184 mRedrawNeeded = true;
185 if ( mRedrawNeeded ) { 185 if ( mRedrawNeeded ) {
186 cx = contentsX() + frameWidth()*2; 186 cx = contentsX() + frameWidth()*2;
187 cw = contentsWidth() ; 187 cw = contentsWidth() ;
188 // end of workaround 188 // end of workaround
189 189
190 int cell = ((int)(cy/mCellHeight)); 190 int cell = ((int)(cy/mCellHeight));
191 int y = cell * mCellHeight; 191 int y = cell * mCellHeight;
192 QFontMetrics fm = fontMetrics(); 192 QFontMetrics fm = fontMetrics();
193 QString hour; 193 QString hour;
194 QString suffix; 194 QString suffix;
195 int timeHeight = fm.ascent(); 195 int timeHeight = fm.ascent();
196 QFont nFont = p->font(); 196 QFont nFont = p->font();
197 197
198 if (!KGlobal::locale()->use12Clock()) { 198 if (!KGlobal::locale()->use12Clock()) {
199 if ( QApplication::desktop()->width() <= 320 ) 199 if ( QApplication::desktop()->width() <= 320 )
200 suffix = ""; 200 suffix = "";
201 else 201 else
202 suffix = "00"; 202 suffix = "00";
203 } 203 }
204 204
205 if ( timeHeight > mCellHeight ) { 205 if ( timeHeight > mCellHeight ) {
206 timeHeight = mCellHeight-1; 206 timeHeight = mCellHeight-1;
207 int pointS = nFont.pointSize(); 207 int pointS = nFont.pointSize();
208 while ( pointS > 4 ) { 208 while ( pointS > 4 ) {
209 nFont.setPointSize( pointS ); 209 nFont.setPointSize( pointS );
210 fm = QFontMetrics( nFont ); 210 fm = QFontMetrics( nFont );
211 if ( fm.ascent() < mCellHeight ) 211 if ( fm.ascent() < mCellHeight )
212 break; 212 break;
213 -- pointS; 213 -- pointS;
214 } 214 }
215 fm = QFontMetrics( nFont ); 215 fm = QFontMetrics( nFont );
216 timeHeight = fm.ascent(); 216 timeHeight = fm.ascent();
217 } 217 }
218 //timeHeight -= (timeHeight/4-2); 218 //timeHeight -= (timeHeight/4-2);
219 QFont sFont = nFont; 219 QFont sFont = nFont;
220 sFont.setPointSize( sFont.pointSize()/2 ); 220 sFont.setPointSize( sFont.pointSize()/2 );
221 QFontMetrics fmS( sFont ); 221 QFontMetrics fmS( sFont );
222 int sHei = fmS.ascent() ; 222 int sHei = fmS.ascent() ;
223 //sHei -= (sHei/4-2); 223 //sHei -= (sHei/4-2);
224 int startW = this->width() - frameWidth()-2; 224 int startW = this->width() - frameWidth()-2;
225 int tw2 = fmS.width(suffix); 225 int tw2 = fmS.width(suffix);
226 while (y < cy + ch) { 226 while (y < cy + ch) {
227 p->drawLine(cx,y,cw,y); 227 p->drawLine(cx,y,cw,y);
228 hour.setNum(cell); 228 hour.setNum(cell);
229 // handle 24h and am/pm time formats 229 // handle 24h and am/pm time formats
230 if (KGlobal::locale()->use12Clock()) { 230 if (KGlobal::locale()->use12Clock()) {
231 if (cell > 11) suffix = "pm"; 231 if (cell > 11) suffix = "pm";
232 else 232 else
233 suffix = "am"; 233 suffix = "am";
234 if (cell == 0) hour.setNum(12); 234 if (cell == 0) hour.setNum(12);
235 if (cell > 12) hour.setNum(cell - 12); 235 if (cell > 12) hour.setNum(cell - 12);
236 tw2 = fmS.width(suffix); 236 tw2 = fmS.width(suffix);
237 } 237 }
238 238
239 // center and draw the time label 239 // center and draw the time label
240 int timeWidth = fm.width(hour); 240 int timeWidth = fm.width(hour);
241 int offset = startW - timeWidth - tw2 ; 241 int offset = startW - timeWidth - tw2 ;
242 p->setFont( nFont ); 242 p->setFont( nFont );
243 p->drawText( offset, y+ timeHeight, hour); 243 p->drawText( offset, y+ timeHeight, hour);
244 p->setFont( sFont ); 244 p->setFont( sFont );
245 offset = startW - tw2+1; 245 offset = startW - tw2+1;
246 p->drawText( offset, y+ sHei, suffix); 246 p->drawText( offset, y+ sHei, suffix);
247 247
248 // increment indices 248 // increment indices
249 y += mCellHeight; 249 y += mCellHeight;
250 cell++; 250 cell++;
251 } 251 }
252 } else { 252 } else {
253 //qDebug("NO redraw "); 253 //qDebug("NO redraw ");
254 } 254 }
255 // double buffer not yet implemented 255 // double buffer not yet implemented
256 //bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP); 256 //bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP);
257 //mRedrawNeeded = false; 257 //mRedrawNeeded = false;
258#endif 258#endif
259} 259}
260 260
261/** 261/**
262 Calculates the minimum width. 262 Calculates the minimum width.
263*/ 263*/
264int TimeLabels::minimumWidth() const 264int TimeLabels::minimumWidth() const
265{ 265{
266 return mMiniWidth; 266 return mMiniWidth;
267} 267}
268 268
269/** updates widget's internal state */ 269/** updates widget's internal state */
270void TimeLabels::updateConfig() 270void TimeLabels::updateConfig()
271{ 271{
272 mRedrawNeeded = true; 272 mRedrawNeeded = true;
273 // set the font 273 // set the font
274 // config->setGroup("Fonts"); 274 // config->setGroup("Fonts");
275 // QFont font = config->readFontEntry("TimeBar Font"); 275 // QFont font = config->readFontEntry("TimeBar Font");
276 setFont(KOPrefs::instance()->mTimeBarFont); 276 setFont(KOPrefs::instance()->mTimeBarFont);
277 QString test = "20"; 277 QString test = "20";
278 if (KGlobal::locale()->use12Clock()) 278 if (KGlobal::locale()->use12Clock())
279 test = "12"; 279 test = "12";
280 mMiniWidth = fontMetrics().width(test); 280 mMiniWidth = fontMetrics().width(test);
281 if (KGlobal::locale()->use12Clock()) 281 if (KGlobal::locale()->use12Clock())
282 test = "pm"; 282 test = "pm";
283 else { 283 else {
284 if ( QApplication::desktop()->width() <= 320 ) 284 if ( QApplication::desktop()->width() <= 320 )
285 test = "00"; 285 test = "00";
286 else 286 else
287 test = "00"; 287 test = "00";
288 } 288 }
289 QFont sFont = font(); 289 QFont sFont = font();
290 sFont.setPointSize( sFont.pointSize()/2 ); 290 sFont.setPointSize( sFont.pointSize()/2 );
291 QFontMetrics fmS( sFont ); 291 QFontMetrics fmS( sFont );
292 mMiniWidth += fmS.width( test ) + frameWidth()*2 +4 ; 292 mMiniWidth += fmS.width( test ) + frameWidth()*2 +4 ;
293 // update geometry restrictions based on new settings 293 // update geometry restrictions based on new settings
294 setFixedWidth( mMiniWidth ); 294 setFixedWidth( mMiniWidth );
295 295
296 // update HourSize 296 // update HourSize
297 mCellHeight = KOPrefs::instance()->mHourSize*4; 297 mCellHeight = KOPrefs::instance()->mHourSize*4;
298 resizeContents(50,mRows * mCellHeight); 298 resizeContents(50,mRows * mCellHeight);
299} 299}
300 300
301/** update time label positions */ 301/** update time label positions */
302void TimeLabels::positionChanged() 302void TimeLabels::positionChanged()
303{ 303{
304 int adjustment = mAgenda->contentsY(); 304 int adjustment = mAgenda->contentsY();
305 setContentsPos(0, adjustment); 305 setContentsPos(0, adjustment);
306} 306}
307 307
308/** */ 308/** */
309void TimeLabels::setAgenda(KOAgenda* agenda) 309void TimeLabels::setAgenda(KOAgenda* agenda)
310{ 310{
311 mAgenda = agenda; 311 mAgenda = agenda;
312} 312}
313 313
314void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) 314void TimeLabels::contentsMousePressEvent ( QMouseEvent * e)
315{ 315{
316 mMouseDownY = e->pos().y(); 316 mMouseDownY = e->pos().y();
317 mOrgCap = topLevelWidget()->caption(); 317 mOrgCap = topLevelWidget()->caption();
318} 318}
319 319
320void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) 320void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e )
321{ 321{
322 int diff = mMouseDownY - e->pos().y(); 322 int diff = mMouseDownY - e->pos().y();
323 if ( diff < 10 && diff > -10 ) 323 if ( diff < 10 && diff > -10 )
324 return; 324 return;
325 int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; 325 int tSize = KOPrefs::instance()->mHourSize + (diff/10) ;
326 if ( tSize < 4 ) 326 if ( tSize < 4 )
327 tSize = 4; 327 tSize = 4;
328 if ( tSize > 22 ) 328 if ( tSize > 22 )
329 tSize = 22; 329 tSize = 22;
330 tSize = (tSize-2)/2; 330 tSize = (tSize-2)/2;
331 topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); 331 topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize));
332 332
333} 333}
334void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) 334void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e )
335{ 335{
336 topLevelWidget()->setCaption( mOrgCap ); 336 topLevelWidget()->setCaption( mOrgCap );
337 int diff = mMouseDownY - e->pos().y(); 337 int diff = mMouseDownY - e->pos().y();
338 if ( diff < 10 && diff > -10 ) 338 if ( diff < 10 && diff > -10 )
339 return; 339 return;
340 int tSize = KOPrefs::instance()->mHourSize + (diff/10); 340 int tSize = KOPrefs::instance()->mHourSize + (diff/10);
341 if ( tSize < 4 ) 341 if ( tSize < 4 )
342 tSize = 4; 342 tSize = 4;
343 if ( tSize > 22 ) 343 if ( tSize > 22 )
344 tSize = 22; 344 tSize = 22;
345 tSize = (tSize/2)*2; 345 tSize = (tSize/2)*2;
346 if ( tSize == KOPrefs::instance()->mHourSize ) 346 if ( tSize == KOPrefs::instance()->mHourSize )
347 return; 347 return;
348 KOPrefs::instance()->mHourSize = tSize; 348 KOPrefs::instance()->mHourSize = tSize;
349 emit scaleChanged(); 349 emit scaleChanged();
350} 350}
351 351
352/** This is called in response to repaint() */ 352/** This is called in response to repaint() */
353void TimeLabels::paintEvent(QPaintEvent*) 353void TimeLabels::paintEvent(QPaintEvent*)
354{ 354{
355 355
356 // kdDebug() << "paintevent..." << endl; 356 // kdDebug() << "paintevent..." << endl;
357 // this is another hack! 357 // this is another hack!
358 // QPainter painter(this); 358 // QPainter painter(this);
359 //QString c 359 //QString c
360 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight()); 360 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight());
361} 361}
362 362
363//////////////////////////////////////////////////////////////////////////// 363////////////////////////////////////////////////////////////////////////////
364 364
365EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name) 365EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name)
366 : QFrame(parent,name) 366 : QFrame(parent,name)
367{ 367{
368 mColumns = 1; 368 mColumns = 1;
369 mTopBox = 0; 369 mTopBox = 0;
370 mLocation = loc; 370 mLocation = loc;
371 mTopLayout = 0; 371 mTopLayout = 0;
372 mPaintWidget = 0; 372 mPaintWidget = 0;
373 mXOffset = 0; 373 mXOffset = 0;
374 if (mLocation == Top) mPixmap = SmallIcon("1uparrow"); 374 if (mLocation == Top) mPixmap = SmallIcon("1uparrow");
375 else mPixmap = SmallIcon("1downarrow"); 375 else mPixmap = SmallIcon("1downarrow");
376 mEnabled.resize(mColumns); 376 mEnabled.resize(mColumns);
377 mEnabled.fill( false ); 377 mEnabled.fill( false );
378 setMinimumHeight(mPixmap.height()); 378 setMinimumHeight(mPixmap.height());
379} 379}
380 380
381EventIndicator::~EventIndicator() 381EventIndicator::~EventIndicator()
382{ 382{
383} 383}
384 384
385void EventIndicator::drawContents(QPainter *p) 385void EventIndicator::drawContents(QPainter *p)
386{ 386{
387 387
388 // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl; 388 // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl;
389 KDGanttSplitterHandle* han = 0; 389 KDGanttSplitterHandle* han = 0;
390 if ( mPaintWidget ) 390 if ( mPaintWidget )
391 han = mPaintWidget->firstHandle(); 391 han = mPaintWidget->firstHandle();
392 if ( ! han ) { 392 if ( ! han ) {
393 int i; 393 int i;
394 for(i=0;i<mColumns;++i) { 394 for(i=0;i<mColumns;++i) {
395 if (mEnabled[i]) { 395 if (mEnabled[i]) {
396 int cellWidth = contentsRect().right()/mColumns; 396 int cellWidth = contentsRect().right()/mColumns;
397 int xOffset = KOGlobals::self()->reverseLayout() ? 397 int xOffset = KOGlobals::self()->reverseLayout() ?
398 (mColumns - 1 - i)*cellWidth + (cellWidth -mPixmap.width())/2 : 398 (mColumns - 1 - i)*cellWidth + (cellWidth -mPixmap.width())/2 :
399 i*cellWidth + (cellWidth -mPixmap.width()) /2; 399 i*cellWidth + (cellWidth -mPixmap.width()) /2;
400 p->drawPixmap(QPoint(1+xOffset,0),mPixmap); 400 p->drawPixmap(QPoint(1+xOffset,0),mPixmap);
401 } 401 }
402 } 402 }
403 } else { 403 } else {
404 han->repaint(); 404 han->repaint();
405 //mPaintWidget->setBackgroundColor( red ); 405 //mPaintWidget->setBackgroundColor( red );
406 406
407 QPainter pa( han ); 407 QPainter pa( han );
408 int i; 408 int i;
409 bool setColor = false; 409 bool setColor = false;
410 for(i=0;i<mColumns;++i) { 410 for(i=0;i<mColumns;++i) {
411 if (mEnabled[i]) { 411 if (mEnabled[i]) {
412 setColor = true; 412 setColor = true;
413 413
414 int cellWidth = contentsRect().right()/mColumns; 414 int cellWidth = contentsRect().right()/mColumns;
415 int xOffset = KOGlobals::self()->reverseLayout() ? 415 int xOffset = KOGlobals::self()->reverseLayout() ?
416 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 : 416 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 :
417 i*cellWidth + cellWidth/2 -mPixmap.width()/2; 417 i*cellWidth + cellWidth/2 -mPixmap.width()/2;
418 pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap); 418 pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap);
419 //qDebug("222draw pix %d ",xOffset ); 419 //qDebug("222draw pix %d ",xOffset );
420 420
421 } 421 }
422 422
423 } 423 }
424 pa.end(); 424 pa.end();
425 425
426 } 426 }
427} 427}
428 428
429void EventIndicator::setXOffset( int x ) 429void EventIndicator::setXOffset( int x )
430{ 430{
431 mXOffset = x; 431 mXOffset = x;
432} 432}
433void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w ) 433void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w )
434{ 434{
435 mPaintWidget = w; 435 mPaintWidget = w;
436 setMaximumHeight(0); 436 setMaximumHeight(0);
437 setMinimumHeight(0); 437 setMinimumHeight(0);
438} 438}
439void EventIndicator::changeColumns(int columns) 439void EventIndicator::changeColumns(int columns)
440{ 440{
441 mColumns = columns; 441 mColumns = columns;
442 mEnabled.resize(mColumns); 442 mEnabled.resize(mColumns);
443 443
444 update(); 444 update();
445} 445}
446 446
447void EventIndicator::enableColumn(int column, bool enable) 447void EventIndicator::enableColumn(int column, bool enable)
448{ 448{
449 mEnabled[column] = enable; 449 mEnabled[column] = enable;
450} 450}
451 451
452 452
453//////////////////////////////////////////////////////////////////////////// 453////////////////////////////////////////////////////////////////////////////
454//////////////////////////////////////////////////////////////////////////// 454////////////////////////////////////////////////////////////////////////////
455//////////////////////////////////////////////////////////////////////////// 455////////////////////////////////////////////////////////////////////////////
456 456
457KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) : 457KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) :
458 KOEventView (cal,parent,name) 458 KOEventView (cal,parent,name)
459{ 459{
460 mBlockUpdating = true; 460 mBlockUpdating = true;
461 mStartHour = 8; 461 mStartHour = 8;
462 mSelectedDates.append(QDate::currentDate()); 462 mSelectedDates.append(QDate::currentDate());
463 463
464 mLayoutDayLabels = 0; 464 mLayoutDayLabels = 0;
465 mDayLabelsFrame = 0; 465 mDayLabelsFrame = 0;
466 mDayLabels = 0; 466 mDayLabels = 0;
467 bool isRTL = KOGlobals::self()->reverseLayout(); 467 bool isRTL = KOGlobals::self()->reverseLayout();
468 QPixmap expandPix; 468 QPixmap expandPix;
469 if ( KOPrefs::instance()->mVerticalScreen ) { 469 if ( KOPrefs::instance()->mVerticalScreen ) {
470 expandPix = SmallIcon( "1updownarrow" ); 470 expandPix = SmallIcon( "1updownarrow" );
471 } else { 471 } else {
472 expandPix = SmallIcon("1leftrightarrow" ); 472 expandPix = SmallIcon("1leftrightarrow" );
473 } 473 }
474 474
475 QBoxLayout *topLayout = new QVBoxLayout(this); 475 QBoxLayout *topLayout = new QVBoxLayout(this);
476 476
477 // Create day name labels for agenda columns 477 // Create day name labels for agenda columns
478 // Create agenda splitter 478 // Create agenda splitter
479 479
480 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this); 480 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this);
481 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 481 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
482 topLayout->addWidget( mSplitterAgenda ); 482 topLayout->addWidget( mSplitterAgenda );
483 mAllDayFrame = new QHBox(mSplitterAgenda); 483 mAllDayFrame = new QHBox(mSplitterAgenda);
484 mAllDayFrame->setFocusPolicy(NoFocus); 484 mAllDayFrame->setFocusPolicy(NoFocus);
485 QWidget *agendaFrame = new QWidget(mSplitterAgenda); 485 QWidget *agendaFrame = new QWidget(mSplitterAgenda);
486 agendaFrame->setFocusPolicy(NoFocus); 486 agendaFrame->setFocusPolicy(NoFocus);
487 487
488 // Create all-day agenda widget 488 // Create all-day agenda widget
489 mDummyAllDayLeft = new QVBox( mAllDayFrame ); 489 mDummyAllDayLeft = new QVBox( mAllDayFrame );
490 490
491 mExpandButton = new QPushButton(mDummyAllDayLeft); 491 mExpandButton = new QPushButton(mDummyAllDayLeft);
492 mExpandButton->setPixmap( expandPix ); 492 mExpandButton->setPixmap( expandPix );
493 int widebut = mExpandButton->sizeHint().width()+4; 493 int widebut = mExpandButton->sizeHint().width()+4;
494 int heibut = mExpandButton->sizeHint().height()+4; 494 int heibut = mExpandButton->sizeHint().height()+4;
495 if ( heibut > widebut ) 495 if ( heibut > widebut )
496 widebut = heibut ; 496 widebut = heibut ;
497 497
498 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, 498 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed,
499 // QSizePolicy::Fixed ) ); 499 // QSizePolicy::Fixed ) );
500 mExpandButton->setFixedSize( widebut, widebut); 500 mExpandButton->setFixedSize( widebut, widebut);
501 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) ); 501 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) );
502 mExpandButton->setFocusPolicy(NoFocus); 502 mExpandButton->setFocusPolicy(NoFocus);
503 mAllDayAgenda = new KOAgenda(1,mAllDayFrame); 503 mAllDayAgenda = new KOAgenda(1,mAllDayFrame);
504 mAllDayAgenda->setFocusPolicy(NoFocus); 504 mAllDayAgenda->setFocusPolicy(NoFocus);
505 QLabel *dummyAllDayRight = new QLabel (mAllDayFrame); 505 QLabel *dummyAllDayRight = new QLabel (mAllDayFrame);
506 506
507 // Create event context menu for all day agenda 507 // Create event context menu for all day agenda
508 mAllDayAgendaPopup = eventPopup(); 508 //mAllDayAgendaPopup = eventPopup();
509 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
510 mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
511 509
512 // Create agenda frame 510 // Create agenda frame
513 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,4,3); 511 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,4,3);
514 // QHBox *agendaFrame = new QHBox(splitterAgenda); 512 // QHBox *agendaFrame = new QHBox(splitterAgenda);
515 513
516 // create event indicator bars 514 // create event indicator bars
517 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame); 515 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame);
518#ifndef DESKTOP_VERSION 516#ifndef DESKTOP_VERSION
519 // FIX 517 // FIX
520 mEventIndicatorTop->setPaintWidget( mSplitterAgenda ); 518 mEventIndicatorTop->setPaintWidget( mSplitterAgenda );
521#endif 519#endif
522 mDayLabelsFrame = new QHBox(agendaFrame); 520 mDayLabelsFrame = new QHBox(agendaFrame);
523 //topLayout->addWidget(mDayLabelsFrame); 521 //topLayout->addWidget(mDayLabelsFrame);
524 mDayLabels = new QFrame (mDayLabelsFrame); 522 mDayLabels = new QFrame (mDayLabelsFrame);
525 mLayoutDayLabels = new QHBoxLayout(mDayLabels); 523 mLayoutDayLabels = new QHBoxLayout(mDayLabels);
526 agendaLayout->addMultiCellWidget(mDayLabelsFrame ,0,0,0,2); 524 agendaLayout->addMultiCellWidget(mDayLabelsFrame ,0,0,0,2);
527 agendaLayout->addWidget(mEventIndicatorTop,1,1); 525 agendaLayout->addWidget(mEventIndicatorTop,1,1);
528 526
529 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom, 527 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom,
530 agendaFrame); 528 agendaFrame);
531 agendaLayout->addWidget(mEventIndicatorBottom,3,1); 529 agendaLayout->addWidget(mEventIndicatorBottom,3,1);
532 QWidget *dummyAgendaRight = new QWidget(agendaFrame); 530 QWidget *dummyAgendaRight = new QWidget(agendaFrame);
533 agendaLayout->addWidget(dummyAgendaRight,1,2); 531 agendaLayout->addWidget(dummyAgendaRight,1,2);
534 532
535 // Create time labels 533 // Create time labels
536 mTimeLabels = new TimeLabels(24,agendaFrame); 534 mTimeLabels = new TimeLabels(24,agendaFrame);
537 agendaLayout->addWidget(mTimeLabels,2,0); 535 agendaLayout->addWidget(mTimeLabels,2,0);
538 connect(mTimeLabels,SIGNAL( scaleChanged()), 536 connect(mTimeLabels,SIGNAL( scaleChanged()),
539 this,SLOT(updateConfig())); 537 this,SLOT(updateConfig()));
540 538
541 // Create agenda 539 // Create agenda
542 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame); 540 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame);
543 agendaLayout->addMultiCellWidget(mAgenda,2,2,1,2); 541 agendaLayout->addMultiCellWidget(mAgenda,2,2,1,2);
544 agendaLayout->setColStretch(1,1); 542 agendaLayout->setColStretch(1,1);
545 mAgenda->setFocusPolicy(NoFocus); 543 mAgenda->setFocusPolicy(NoFocus);
546 // Create event context menu for agenda 544 // Create event context menu for agenda
547 mAgendaPopup = eventPopup(); 545 mAllAgendaPopup = eventPopup();
548 546
549 mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")), 547 mAllAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")),
550 i18n("Toggle Alarm"),mAgenda, 548 i18n("Toggle Alarm"),mAgenda,
551 SLOT(popupAlarm()),true); 549 SLOT(popupAlarm()),true);
552 550
553 551
554 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), 552 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
555 mAgendaPopup,SLOT(showIncidencePopup(Incidence *))); 553 mAllAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
556 554
555 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
556 mAllAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
557 mAgenda->setPopup( mAllAgendaPopup );
558 mAllDayAgenda->setPopup( mAllAgendaPopup );
557 // make connections between dependent widgets 559 // make connections between dependent widgets
558 mTimeLabels->setAgenda(mAgenda); 560 mTimeLabels->setAgenda(mAgenda);
559 561
560 // Update widgets to reflect user preferences 562 // Update widgets to reflect user preferences
561 // updateConfig(); 563 // updateConfig();
562 564
563 // createDayLabels(); 565 // createDayLabels();
564 566
565 // these blank widgets make the All Day Event box line up with the agenda 567 // these blank widgets make the All Day Event box line up with the agenda
566 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 568 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
567 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 569 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
568 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 570 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
569 571
570 // Scrolling 572 // Scrolling
571 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)), 573 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)),
572 mTimeLabels, SLOT(positionChanged())); 574 mTimeLabels, SLOT(positionChanged()));
573 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)), 575 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)),
574 SLOT(setContentsPos(int))); 576 SLOT(setContentsPos(int)));
575 577
576 connect(mAgenda,SIGNAL(showDateView( int, int)),SLOT(slotShowDateView( int, int ))); 578 connect(mAgenda,SIGNAL(showDateView( int, int)),SLOT(slotShowDateView( int, int )));
577 connect(mAllDayAgenda,SIGNAL(showDateView( int, int )), SLOT(slotShowDateView( int, int ) )); 579 connect(mAllDayAgenda,SIGNAL(showDateView( int, int )), SLOT(slotShowDateView( int, int ) ));
578 580
579 // Create/Show/Edit/Delete Event 581 // Create/Show/Edit/Delete Event
580 connect(mAgenda,SIGNAL(newEventSignal(int,int)), 582 connect(mAgenda,SIGNAL(newEventSignal(int,int)),
581 SLOT(newEvent(int,int))); 583 SLOT(newEvent(int,int)));
582 connect(mAgenda,SIGNAL(newTodoSignal(int,int)), 584 connect(mAgenda,SIGNAL(newTodoSignal(int,int)),
583 SLOT(newTodo(int,int))); 585 SLOT(newTodo(int,int)));
584 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)), 586 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)),
585 SLOT(newEvent(int,int,int,int))); 587 SLOT(newEvent(int,int,int,int)));
586 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)), 588 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)),
587 SLOT(newEventAllDay(int,int))); 589 SLOT(newEventAllDay(int,int)));
588 connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)), 590 connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)),
589 SLOT(newTodoAllDay(int,int))); 591 SLOT(newTodoAllDay(int,int)));
590 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)), 592 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)),
591 SLOT(newEventAllDay(int,int))); 593 SLOT(newEventAllDay(int,int)));
592 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 594 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
593 SLOT(newTimeSpanSelected(int,int,int,int))); 595 SLOT(newTimeSpanSelected(int,int,int,int)));
594 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 596 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
595 SLOT(newTimeSpanSelectedAllDay(int,int,int,int))); 597 SLOT(newTimeSpanSelectedAllDay(int,int,int,int)));
596 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 598 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
597 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 599 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
598 600
599 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 601 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
600 SIGNAL(editIncidenceSignal(Incidence *))); 602 SIGNAL(editIncidenceSignal(Incidence *)));
601 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 603 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
602 SIGNAL(editIncidenceSignal(Incidence *))); 604 SIGNAL(editIncidenceSignal(Incidence *)));
603 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 605 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
604 SIGNAL(showIncidenceSignal(Incidence *))); 606 SIGNAL(showIncidenceSignal(Incidence *)));
605 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 607 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
606 SIGNAL(showIncidenceSignal(Incidence *))); 608 SIGNAL(showIncidenceSignal(Incidence *)));
607 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 609 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
608 SIGNAL(deleteIncidenceSignal(Incidence *))); 610 SIGNAL(deleteIncidenceSignal(Incidence *)));
609 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 611 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
610 SIGNAL(deleteIncidenceSignal(Incidence *))); 612 SIGNAL(deleteIncidenceSignal(Incidence *)));
611 613
612 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 614 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
613 SLOT(updateEventDates(KOAgendaItem *, int ))); 615 SLOT(updateEventDates(KOAgendaItem *, int )));
614 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 616 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
615 SLOT(updateEventDates(KOAgendaItem *, int))); 617 SLOT(updateEventDates(KOAgendaItem *, int)));
616 618
617 // event indicator update 619 // event indicator update
618 connect(mAgenda,SIGNAL(lowerYChanged(int)), 620 connect(mAgenda,SIGNAL(lowerYChanged(int)),
619 SLOT(updateEventIndicatorTop(int))); 621 SLOT(updateEventIndicatorTop(int)));
620 connect(mAgenda,SIGNAL(upperYChanged(int)), 622 connect(mAgenda,SIGNAL(upperYChanged(int)),
621 SLOT(updateEventIndicatorBottom(int))); 623 SLOT(updateEventIndicatorBottom(int)));
622 // drag signals 624 // drag signals
623 /* 625 /*
624 connect(mAgenda,SIGNAL(startDragSignal(Event *)), 626 connect(mAgenda,SIGNAL(startDragSignal(Event *)),
625 SLOT(startDrag(Event *))); 627 SLOT(startDrag(Event *)));
626 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)), 628 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)),
627 SLOT(startDrag(Event *))); 629 SLOT(startDrag(Event *)));
628 */ 630 */
629 // synchronize selections 631 // synchronize selections
630 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 632 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
631 mAllDayAgenda, SLOT( deselectItem() ) ); 633 mAllDayAgenda, SLOT( deselectItem() ) );
632 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 634 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
633 mAgenda, SLOT( deselectItem() ) ); 635 mAgenda, SLOT( deselectItem() ) );
634 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 636 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
635 SIGNAL( incidenceSelected( Incidence * ) ) ); 637 SIGNAL( incidenceSelected( Incidence * ) ) );
636 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 638 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
637 SIGNAL( incidenceSelected( Incidence * ) ) ); 639 SIGNAL( incidenceSelected( Incidence * ) ) );
638 connect( mAgenda, SIGNAL( resizedSignal() ), 640 connect( mAgenda, SIGNAL( resizedSignal() ),
639 SLOT( updateConfig( ) ) ); 641 SLOT( updateConfig( ) ) );
640 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ), 642 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ),
641 SLOT( addToCalSlot(Incidence *, Incidence * ) ) ); 643 SLOT( addToCalSlot(Incidence *, Incidence * ) ) );
642 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ), 644 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ),
643 SLOT( addToCalSlot(Incidence * , Incidence *) ) ); 645 SLOT( addToCalSlot(Incidence * , Incidence *) ) );
644 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 646 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
645 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 647 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
646 648
647 649
648} 650}
649 651
650void KOAgendaView::toggleAllDay() 652void KOAgendaView::toggleAllDay()
651{ 653{
652 if ( mSplitterAgenda->firstHandle() ) 654 if ( mSplitterAgenda->firstHandle() )
653 mSplitterAgenda->firstHandle()->toggle(); 655 mSplitterAgenda->firstHandle()->toggle();
654} 656}
655void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld ) 657void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld )
656{ 658{
657 calendar()->addIncidence( inc ); 659 calendar()->addIncidence( inc );
658 660
659 if ( incOld ) { 661 if ( incOld ) {
660 if ( incOld->type() == "Todo" ) 662 if ( incOld->type() == "Todo" )
661 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED ); 663 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED );
662 else 664 else
663 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED); 665 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED);
664 } 666 }
665 667
666} 668}
667 669
668KOAgendaView::~KOAgendaView() 670KOAgendaView::~KOAgendaView()
669{ 671{
670 delete mAgendaPopup; 672 delete mAllAgendaPopup;
671 delete mAllDayAgendaPopup; 673 //delete mAllDayAgendaPopup;
672 delete KOAgendaItem::paintPix(); 674 delete KOAgendaItem::paintPix();
673 delete KOAgendaItem::paintPixSel(); 675 delete KOAgendaItem::paintPixSel();
674} 676}
675void KOAgendaView::resizeEvent( QResizeEvent* e ) 677void KOAgendaView::resizeEvent( QResizeEvent* e )
676{ 678{
677 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); 679 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width());
678 bool uc = false; 680 bool uc = false;
679 int ow = e->oldSize().width(); 681 int ow = e->oldSize().width();
680 int oh = e->oldSize().height(); 682 int oh = e->oldSize().height();
681 int w = e->size().width(); 683 int w = e->size().width();
682 int h = e->size().height(); 684 int h = e->size().height();
683 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { 685 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) {
684 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) 686 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda )
685 uc = true; 687 uc = true;
686 //qDebug("view changed %d %d %d %d ", ow, oh , w , h); 688 //qDebug("view changed %d %d %d %d ", ow, oh , w , h);
687 } 689 }
688 mUpcomingWidth = e->size().width() ; 690 mUpcomingWidth = e->size().width() ;
689 if ( mBlockUpdating || uc ) { 691 if ( mBlockUpdating || uc ) {
690 mBlockUpdating = false; 692 mBlockUpdating = false;
691 //mAgenda->setMinimumSize(800 , 600 ); 693 //mAgenda->setMinimumSize(800 , 600 );
692 //qDebug("mAgenda->resize+++++++++++++++ "); 694 //qDebug("mAgenda->resize+++++++++++++++ ");
693 updateConfig(); 695 updateConfig();
694 //qDebug("KOAgendaView::Updating now possible "); 696 //qDebug("KOAgendaView::Updating now possible ");
695 } else 697 } else
696 createDayLabels(); 698 createDayLabels();
697 //qDebug("resizeEvent end "); 699 //qDebug("resizeEvent end ");
698 700
699} 701}
700void KOAgendaView::slotDaylabelClicked( int num ) 702void KOAgendaView::slotDaylabelClicked( int num )
701{ 703{
702 704
703 QDate firstDate = mSelectedDates.first(); 705 QDate firstDate = mSelectedDates.first();
704 if ( num == -1 ) 706 if ( num == -1 )
705 emit showDateView( 6, firstDate ); 707 emit showDateView( 6, firstDate );
706 else if (num >= 0 ) { 708 else if (num >= 0 ) {
707 if ( mSelectedDates.count() == 1) 709 if ( mSelectedDates.count() == 1)
708 emit showDateView( 9, firstDate.addDays( num ) ); 710 emit showDateView( 9, firstDate.addDays( num ) );
709 else 711 else
710 emit showDateView( 3, firstDate.addDays( num ) ); 712 emit showDateView( 3, firstDate.addDays( num ) );
711 } 713 }
712 else 714 else
713 showDateView( 10, firstDate.addDays(1) ); 715 showDateView( 10, firstDate.addDays(1) );
714} 716}
715 717
716KOAgendaButton* KOAgendaView::getNewDaylabel() 718KOAgendaButton* KOAgendaView::getNewDaylabel()
717{ 719{
718 720
719 KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels); 721 KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels);
720 connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) ); 722 connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) );
721 mDayLabelsList.append( dayLabel ); 723 mDayLabelsList.append( dayLabel );
722 mLayoutDayLabels->addWidget(dayLabel); 724 mLayoutDayLabels->addWidget(dayLabel);
723 return dayLabel ; 725 return dayLabel ;
724} 726}
725 727
726void KOAgendaView::createDayLabels() 728void KOAgendaView::createDayLabels()
727{ 729{
728 730
729 if ( mBlockUpdating || globalFlagBlockLabel == 1) { 731 if ( mBlockUpdating || globalFlagBlockLabel == 1) {
730 // qDebug(" KOAgendaView::createDayLabels() blocked "); 732 // qDebug(" KOAgendaView::createDayLabels() blocked ");
731 return; 733 return;
732 734
733 } 735 }
734 int newHight; 736 int newHight;
735 737
736 // ### Before deleting and recreating we could check if mSelectedDates changed... 738 // ### Before deleting and recreating we could check if mSelectedDates changed...
737 // It would remove some flickering and gain speed (since this is called by 739 // It would remove some flickering and gain speed (since this is called by
738 // each updateView() call) 740 // each updateView() call)
739 741
740 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - mAgenda->frameWidth()*2; 742 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - mAgenda->frameWidth()*2;
741 if ( QApplication::desktop()->width() <= 320 ) 743 if ( QApplication::desktop()->width() <= 320 )
742 maxWid -= 10; 744 maxWid -= 10;
743 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); 745 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth );
744 if ( maxWid < 0 ) 746 if ( maxWid < 0 )
745 maxWid = 20; 747 maxWid = 20;
746 748
747 QFont dlf = KOPrefs::instance()->mTimeLabelsFont; 749 QFont dlf = KOPrefs::instance()->mTimeLabelsFont;
748 QFontMetrics fm ( dlf ); 750 QFontMetrics fm ( dlf );
749 int selCount = mSelectedDates.count(); 751 int selCount = mSelectedDates.count();
750 QString dayTest = "Mon 20"; 752 QString dayTest = "Mon 20";
751 //QString dayTest = "Mon 20"; 753 //QString dayTest = "Mon 20";
752 int wid = fm.width( dayTest ); 754 int wid = fm.width( dayTest );
753 //maxWid -= ( selCount * 3 ); //working for QLabels 755 //maxWid -= ( selCount * 3 ); //working for QLabels
754 maxWid -= ( selCount * 3 ); //working for QPushButton 756 maxWid -= ( selCount * 3 ); //working for QPushButton
755 if ( maxWid < 0 ) 757 if ( maxWid < 0 )
756 maxWid = 20; 758 maxWid = 20;
757 int needWid = wid * selCount; 759 int needWid = wid * selCount;
758 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); 760 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid );
759 //if ( needWid > maxWid ) 761 //if ( needWid > maxWid )
760 // qDebug("DAYLABELS TOOOOOOO BIG "); 762 // qDebug("DAYLABELS TOOOOOOO BIG ");
761 while ( needWid > maxWid ) { 763 while ( needWid > maxWid ) {
762 dayTest = dayTest.left( dayTest.length() - 1 ); 764 dayTest = dayTest.left( dayTest.length() - 1 );
763 wid = fm.width( dayTest ); 765 wid = fm.width( dayTest );
764 needWid = wid * selCount; 766 needWid = wid * selCount;
765 } 767 }
766 int maxLen = dayTest.length(); 768 int maxLen = dayTest.length();
767 int fontPoint = dlf.pointSize(); 769 int fontPoint = dlf.pointSize();
768 if ( maxLen < 2 ) { 770 if ( maxLen < 2 ) {
769 int fontPoint = dlf.pointSize(); 771 int fontPoint = dlf.pointSize();
770 while ( fontPoint > 4 ) { 772 while ( fontPoint > 4 ) {
771 --fontPoint; 773 --fontPoint;
772 dlf.setPointSize( fontPoint ); 774 dlf.setPointSize( fontPoint );
773 QFontMetrics f( dlf ); 775 QFontMetrics f( dlf );
774 wid = f.width( "30" ); 776 wid = f.width( "30" );
775 needWid = wid * selCount; 777 needWid = wid * selCount;
776 if ( needWid < maxWid ) 778 if ( needWid < maxWid )
777 break; 779 break;
778 } 780 }
779 maxLen = 2; 781 maxLen = 2;
780 } 782 }
781 //qDebug("Max len %d ", dayTest.length() ); 783 //qDebug("Max len %d ", dayTest.length() );
782 784
783 QFontMetrics tempF( dlf ); 785 QFontMetrics tempF( dlf );
784 newHight = tempF.height(); 786 newHight = tempF.height();
785 mDayLabels->setFont( dlf ); 787 mDayLabels->setFont( dlf );
786 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; 788 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);;
787 // mLayoutDayLabels->addSpacing(mTimeLabels->width()); 789 // mLayoutDayLabels->addSpacing(mTimeLabels->width());
788 //mLayoutDayLabels->addSpacing( 2 ); 790 //mLayoutDayLabels->addSpacing( 2 );
789 // QFont lFont = dlf; 791 // QFont lFont = dlf;
790 bool appendLabels = false; 792 bool appendLabels = false;
791 KOAgendaButton *dayLabel; 793 KOAgendaButton *dayLabel;
792 dayLabel = mDayLabelsList.first(); 794 dayLabel = mDayLabelsList.first();
793 if ( !dayLabel ) { 795 if ( !dayLabel ) {
794 appendLabels = true; 796 appendLabels = true;
795 dayLabel = getNewDaylabel(); 797 dayLabel = getNewDaylabel();
796 } 798 }
797 dayLabel->setFixedWidth( mTimeLabels->width()+mAgenda->frameWidth() ); 799 dayLabel->setFixedWidth( mTimeLabels->width()+mAgenda->frameWidth() );
798 dayLabel->setFont( dlf ); 800 dayLabel->setFont( dlf );
799 dayLabel->setNum( -1 ); 801 dayLabel->setNum( -1 );
800 //dayLabel->setAlignment(QLabel::AlignHCenter); 802 //dayLabel->setAlignment(QLabel::AlignHCenter);
801#if 0 803#if 0
802 if ( QApplication::desktop()->width() <= 320 ) 804 if ( QApplication::desktop()->width() <= 320 )
803 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ).left(2) ); 805 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ).left(2) );
804 else 806 else
805#endif 807#endif
806 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); 808 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) );
807 dayLabel->show(); 809 dayLabel->show();
808 DateList::ConstIterator dit; 810 DateList::ConstIterator dit;
809 bool oneday = (mSelectedDates.first() == mSelectedDates.last() ); 811 bool oneday = (mSelectedDates.first() == mSelectedDates.last() );
810 int counter = -1; 812 int counter = -1;
811 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 813 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
812 ++counter; 814 ++counter;
813 QDate date = *dit; 815 QDate date = *dit;
814 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); 816 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels);
815 if ( ! appendLabels ) { 817 if ( ! appendLabels ) {
816 dayLabel = mDayLabelsList.next(); 818 dayLabel = mDayLabelsList.next();
817 if ( !dayLabel ) 819 if ( !dayLabel )
818 appendLabels = true; 820 appendLabels = true;
819 } 821 }
820 if ( appendLabels ) { 822 if ( appendLabels ) {
821 dayLabel = getNewDaylabel(); 823 dayLabel = getNewDaylabel();
822 } 824 }
823 dayLabel->setMinimumWidth( 1 ); 825 dayLabel->setMinimumWidth( 1 );
824 dayLabel->setMaximumWidth( 10240 ); 826 dayLabel->setMaximumWidth( 10240 );
825 dayLabel->setFont( dlf ); 827 dayLabel->setFont( dlf );
826 dayLabel->show(); 828 dayLabel->show();
827 dayLabel->setAutoRepeat( false ); 829 dayLabel->setAutoRepeat( false );
828 dayLabel->setNum( counter ); 830 dayLabel->setNum( counter );
829 QString str; 831 QString str;
830 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date); 832 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date);
831 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true ); 833 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true );
832 switch ( maxLen ) { 834 switch ( maxLen ) {
833 case 2: 835 case 2:
834 str = QString::number( date.day() ); 836 str = QString::number( date.day() );
835 break; 837 break;
836 838
837 case 3: 839 case 3:
838 str = dayName.left( 1 ) +QString::number( date.day()); 840 str = dayName.left( 1 ) +QString::number( date.day());
839 841
840 break; 842 break;
841 case 4: 843 case 4:
842 str = dayName.left( 1 ) + " " +QString::number( date.day()); 844 str = dayName.left( 1 ) + " " +QString::number( date.day());
843 845
844 break; 846 break;
845 case 5: 847 case 5:
846 str = dayName.left( 2 ) + " " +QString::number( date.day()); 848 str = dayName.left( 2 ) + " " +QString::number( date.day());
847 849
848 break; 850 break;
849 case 6: 851 case 6:
850 str = dayName.left( 3 ) + " " +QString::number( date.day()); 852 str = dayName.left( 3 ) + " " +QString::number( date.day());
851 break; 853 break;
852 854
853 default: 855 default:
854 break; 856 break;
855 } 857 }
856 if ( oneday ) { 858 if ( oneday ) {
857 QString addString; 859 QString addString;
858 if ( mSelectedDates.first() == QDateTime::currentDateTime().date() ) 860 if ( mSelectedDates.first() == QDateTime::currentDateTime().date() )
859 addString = i18n("Today"); 861 addString = i18n("Today");
860 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) 862 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) )
861 addString = i18n("Tomorrow"); 863 addString = i18n("Tomorrow");
862 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) 864 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) )
863 addString = i18n("Yesterday"); 865 addString = i18n("Yesterday");
864 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) 866 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) )
865 addString = i18n("Day before yesterday"); 867 addString = i18n("Day before yesterday");
866 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) 868 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) )
867 addString = i18n("Day after tomorrow"); 869 addString = i18n("Day after tomorrow");
868 if ( !addString.isEmpty() ) { 870 if ( !addString.isEmpty() ) {
869 str = addString+", " + str; 871 str = addString+", " + str;
870 } else { 872 } else {
871 str = KGlobal::locale()->formatDate( date, KOPrefs::instance()->mShortDateInViewer); 873 str = KGlobal::locale()->formatDate( date, KOPrefs::instance()->mShortDateInViewer);
872 } 874 }
873 } 875 }
874 dayLabel->setText(str); 876 dayLabel->setText(str);
875 //dayLabel->setAlignment(QLabel::AlignHCenter); 877 //dayLabel->setAlignment(QLabel::AlignHCenter);
876 if (date == QDate::currentDate()) { 878 if (date == QDate::currentDate()) {
877 QFont bFont = dlf; 879 QFont bFont = dlf;
878 bFont.setBold( true ); 880 bFont.setBold( true );
879 dayLabel->setFont(bFont); 881 dayLabel->setFont(bFont);
880 } 882 }
881 //dayLayout->addWidget(dayLabel); 883 //dayLayout->addWidget(dayLabel);
882 884
883#ifndef KORG_NOPLUGINS 885#ifndef KORG_NOPLUGINS
884 CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); 886 CalendarDecoration::List cds = KOCore::self()->calendarDecorations();
885 CalendarDecoration *it; 887 CalendarDecoration *it;
886 for(it = cds.first(); it; it = cds.next()) { 888 for(it = cds.first(); it; it = cds.next()) {
887 QString text = it->shortText( date ); 889 QString text = it->shortText( date );
888 if ( !text.isEmpty() ) { 890 if ( !text.isEmpty() ) {
889 QLabel *label = new QLabel(text,mDayLabels); 891 QLabel *label = new QLabel(text,mDayLabels);
890 label->setAlignment(AlignCenter); 892 label->setAlignment(AlignCenter);
891 dayLayout->addWidget(label); 893 dayLayout->addWidget(label);
892 } 894 }
893 } 895 }
894 896
895 for(it = cds.first(); it; it = cds.next()) { 897 for(it = cds.first(); it; it = cds.next()) {
896 QWidget *wid = it->smallWidget(mDayLabels,date); 898 QWidget *wid = it->smallWidget(mDayLabels,date);
897 if ( wid ) { 899 if ( wid ) {
898 // wid->setHeight(20); 900 // wid->setHeight(20);
899 dayLayout->addWidget(wid); 901 dayLayout->addWidget(wid);
900 } 902 }
901 } 903 }
902#endif 904#endif
903 } 905 }
904 if ( ! appendLabels ) { 906 if ( ! appendLabels ) {
905 dayLabel = mDayLabelsList.next(); 907 dayLabel = mDayLabelsList.next();
906 if ( !dayLabel ) 908 if ( !dayLabel )
907 appendLabels = true; 909 appendLabels = true;
908 } 910 }
909 if ( appendLabels ) { 911 if ( appendLabels ) {
910 dayLabel = getNewDaylabel(); 912 dayLabel = getNewDaylabel();
911 } 913 }
912 //dayLabel->hide();//test only 914 //dayLabel->hide();//test only
913 int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()- (mAgenda->frameWidth()*2) ) % mSelectedDates.count() ; 915 int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()- (mAgenda->frameWidth()*2) ) % mSelectedDates.count() ;
914 if ( offset < 0 ) offset = 0; 916 if ( offset < 0 ) offset = 0;
915 //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 ); 917 //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 );
916 dayLabel->setText(">");//QString::number ( mSelectedDates.first().month() ) ); 918 dayLabel->setText(">");//QString::number ( mSelectedDates.first().month() ) );
917 dayLabel->setFont( dlf ); 919 dayLabel->setFont( dlf );
918 dayLabel->setAutoRepeat( true ); 920 dayLabel->setAutoRepeat( true );
919 dayLabel->show(); 921 dayLabel->show();
920 dayLabel->setNum( -2 ); 922 dayLabel->setNum( -2 );
921 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset ); 923 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset );
922 924
923 //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2); 925 //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2);
924 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); 926 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2);
925 if ( !appendLabels ) { 927 if ( !appendLabels ) {
926 dayLabel = mDayLabelsList.next(); 928 dayLabel = mDayLabelsList.next();
927 while ( dayLabel ) { 929 while ( dayLabel ) {
928 //qDebug("!dayLabel %d",dayLabel ); 930 //qDebug("!dayLabel %d",dayLabel );
929 dayLabel->hide(); 931 dayLabel->hide();
930 dayLabel = mDayLabelsList.next(); 932 dayLabel = mDayLabelsList.next();
931 } 933 }
932 } 934 }
933 935
934 mDayLabelsFrame->setFixedHeight( newHight + 4 ); 936 mDayLabelsFrame->setFixedHeight( newHight + 4 );
935} 937}
936 938
937int KOAgendaView::maxDatesHint() 939int KOAgendaView::maxDatesHint()
938{ 940{
939 // Not sure about the max number of events, so return 0 for now. 941 // Not sure about the max number of events, so return 0 for now.
940 return 0; 942 return 0;
941} 943}
942 944
943int KOAgendaView::currentDateCount() 945int KOAgendaView::currentDateCount()
944{ 946{
945 return mSelectedDates.count(); 947 return mSelectedDates.count();
946} 948}
947 949
948QPtrList<Incidence> KOAgendaView::selectedIncidences() 950QPtrList<Incidence> KOAgendaView::selectedIncidences()
949{ 951{
950 QPtrList<Incidence> selected; 952 QPtrList<Incidence> selected;
951 Incidence *incidence; 953 Incidence *incidence;
952 954
953 incidence = mAgenda->selectedIncidence(); 955 incidence = mAgenda->selectedIncidence();
954 if (incidence) selected.append(incidence); 956 if (incidence) selected.append(incidence);
955 957
956 incidence = mAllDayAgenda->selectedIncidence(); 958 incidence = mAllDayAgenda->selectedIncidence();
957 if (incidence) selected.append(incidence); 959 if (incidence) selected.append(incidence);
958 960
959 return selected; 961 return selected;
960} 962}
961 963
962DateList KOAgendaView::selectedDates() 964DateList KOAgendaView::selectedDates()
963{ 965{
964 DateList selected; 966 DateList selected;
965 QDate qd; 967 QDate qd;
966 968
967 qd = mAgenda->selectedIncidenceDate(); 969 qd = mAgenda->selectedIncidenceDate();
968 if (qd.isValid()) selected.append(qd); 970 if (qd.isValid()) selected.append(qd);
969 971
970 qd = mAllDayAgenda->selectedIncidenceDate(); 972 qd = mAllDayAgenda->selectedIncidenceDate();
971 if (qd.isValid()) selected.append(qd); 973 if (qd.isValid()) selected.append(qd);
972 974
973 return selected; 975 return selected;
974} 976}
975 977
976 978
977void KOAgendaView::updateView() 979void KOAgendaView::updateView()
978{ 980{
979 if ( mBlockUpdating ) 981 if ( mBlockUpdating )
980 return; 982 return;
981 // kdDebug() << "KOAgendaView::updateView()" << endl; 983 // kdDebug() << "KOAgendaView::updateView()" << endl;
982 fillAgenda(); 984 fillAgenda();
983 985
984} 986}
985 987
986 988
987/* 989/*
988 Update configuration settings for the agenda view. This method is not 990 Update configuration settings for the agenda view. This method is not
989 complete. 991 complete.
990*/ 992*/
991void KOAgendaView::updateConfig() 993void KOAgendaView::updateConfig()
992{ 994{
993 if ( mBlockUpdating ) 995 if ( mBlockUpdating )
994 return; 996 return;
995 if ( mAgenda->height() > 96 * KOPrefs::instance()->mHourSize ) { 997 if ( mAgenda->height() > 96 * KOPrefs::instance()->mHourSize ) {
996 int old = KOPrefs::instance()->mHourSize; 998 int old = KOPrefs::instance()->mHourSize;
997 KOPrefs::instance()->mHourSize = mAgenda->height()/96 +1; 999 KOPrefs::instance()->mHourSize = mAgenda->height()/96 +1;
998 qDebug("KOPrefs::instance()->mHourSize adjusted %d to %d ", old,KOPrefs::instance()->mHourSize ); 1000 qDebug("KOPrefs::instance()->mHourSize adjusted %d to %d ", old,KOPrefs::instance()->mHourSize );
999 } 1001 }
1000 1002
1001 1003
1002 // update config for children 1004 // update config for children
1003 mTimeLabels->updateConfig(); 1005 mTimeLabels->updateConfig();
1004 mAgenda->storePosition(); 1006 mAgenda->storePosition();
1005 mAgenda->updateConfig(); 1007 mAgenda->updateConfig();
1006 mAllDayAgenda->updateConfig(); 1008 mAllDayAgenda->updateConfig();
1007 // widget synchronization 1009 // widget synchronization
1008 //TODO: find a better way, maybe signal/slot 1010 //TODO: find a better way, maybe signal/slot
1009 mTimeLabels->positionChanged(); 1011 mTimeLabels->positionChanged();
1010 1012
1011 // for some reason, this needs to be called explicitly 1013 // for some reason, this needs to be called explicitly
1012 mTimeLabels->repaint(); 1014 mTimeLabels->repaint();
1013 1015
1014 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 1016 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
1015 1017
1016 // ToolTips displaying summary of events 1018 // ToolTips displaying summary of events
1017 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance() 1019 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance()
1018 ->mEnableToolTips); 1020 ->mEnableToolTips);
1019 1021
1020 //setHolidayMasks(); 1022 //setHolidayMasks();
1021 1023
1022 //createDayLabels(); called by via updateView(); 1024 //createDayLabels(); called by via updateView();
1023 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth()); 1025 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth());
1024 updateView(); 1026 updateView();
1025 mAgenda->restorePosition(); 1027 mAgenda->restorePosition();
1026} 1028}
1027 1029
1028 1030
1029void KOAgendaView::updateEventDates(KOAgendaItem *item, int type) 1031void KOAgendaView::updateEventDates(KOAgendaItem *item, int type)
1030{ 1032{
1031 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl; 1033 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl;
1032 //qDebug("KOAgendaView::updateEventDates "); 1034 //qDebug("KOAgendaView::updateEventDates ");
1033 QDateTime startDt,endDt; 1035 QDateTime startDt,endDt;
1034 QDate startDate; 1036 QDate startDate;
1035 int lenInSecs; 1037 int lenInSecs;
1036 // if ( type == KOAgenda::RESIZETOP ) 1038 // if ( type == KOAgenda::RESIZETOP )
1037 // qDebug("RESIZETOP "); 1039 // qDebug("RESIZETOP ");
1038 // if ( type == KOAgenda::RESIZEBOTTOM ) 1040 // if ( type == KOAgenda::RESIZEBOTTOM )
1039 // qDebug("RESIZEBOTTOM "); 1041 // qDebug("RESIZEBOTTOM ");
1040 // if ( type == KOAgenda::MOVE ) 1042 // if ( type == KOAgenda::MOVE )
1041 // qDebug("MOVE "); 1043 // qDebug("MOVE ");
1042 if ( item->incidence()->type() == "Event" ) { 1044 if ( item->incidence()->type() == "Event" ) {
1043 startDt =item->incidence()->dtStart(); 1045 startDt =item->incidence()->dtStart();
1044 endDt = item->incidence()->dtEnd(); 1046 endDt = item->incidence()->dtEnd();
1045 lenInSecs = startDt.secsTo( endDt ); 1047 lenInSecs = startDt.secsTo( endDt );
1046 } 1048 }
1047 1049
1048 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED ); 1050 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED );
1049 1051
1050 if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) { 1052 if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) {
1051 startDate = mSelectedDates[item->mLastMoveXPos]; 1053 startDate = mSelectedDates[item->mLastMoveXPos];
1052 } else { 1054 } else {
1053 if (item->cellX() < 0) { 1055 if (item->cellX() < 0) {
1054 startDate = (mSelectedDates.first()).addDays(item->cellX()); 1056 startDate = (mSelectedDates.first()).addDays(item->cellX());
1055 } else { 1057 } else {
1056 startDate = mSelectedDates[item->cellX()]; 1058 startDate = mSelectedDates[item->cellX()];
1057 } 1059 }
1058 } 1060 }
1059 startDt.setDate(startDate); 1061 startDt.setDate(startDate);
1060 1062
1061 if (item->incidence()->doesFloat()) { 1063 if (item->incidence()->doesFloat()) {
1062 endDt.setDate(startDate.addDays(item->cellWidth() - 1)); 1064 endDt.setDate(startDate.addDays(item->cellWidth() - 1));
1063 } else { 1065 } else {
1064 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE ) 1066 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE )
1065 startDt.setTime(mAgenda->gyToTime(item->cellYTop())); 1067 startDt.setTime(mAgenda->gyToTime(item->cellYTop()));
1066 if ( item->incidence()->type() == "Event" ) { 1068 if ( item->incidence()->type() == "Event" ) {
1067 if ( type == KOAgenda::MOVE ) { 1069 if ( type == KOAgenda::MOVE ) {
1068 endDt = startDt.addSecs(lenInSecs); 1070 endDt = startDt.addSecs(lenInSecs);
1069 1071
1070 } else if ( type == KOAgenda::RESIZEBOTTOM ) { 1072 } else if ( type == KOAgenda::RESIZEBOTTOM ) {
1071 if (item->lastMultiItem()) { 1073 if (item->lastMultiItem()) {
1072 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 1074 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
1073 endDt.setDate(startDate. 1075 endDt.setDate(startDate.
1074 addDays(item->lastMultiItem()->cellX() - item->cellX())); 1076 addDays(item->lastMultiItem()->cellX() - item->cellX()));
1075 } else { 1077 } else {
1076 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 1078 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
1077 endDt.setDate(startDate); 1079 endDt.setDate(startDate);
1078 } 1080 }
1079 } 1081 }
1080 } else { 1082 } else {
1081 // todo 1083 // todo
1082 if (item->lastMultiItem()) { 1084 if (item->lastMultiItem()) {
1083 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 1085 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
1084 endDt.setDate(startDate. 1086 endDt.setDate(startDate.
1085 addDays(item->lastMultiItem()->cellX() - item->cellX())); 1087 addDays(item->lastMultiItem()->cellX() - item->cellX()));
1086 } else { 1088 } else {
1087 //qDebug("tem->cellYBottom() %d",item->cellYBottom() ); 1089 //qDebug("tem->cellYBottom() %d",item->cellYBottom() );
1088 if ( item->cellYBottom() > 0 ) 1090 if ( item->cellYBottom() > 0 )
1089 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 1091 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
1090 else 1092 else
1091 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time()); 1093 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time());
1092 endDt.setDate(startDate); 1094 endDt.setDate(startDate);
1093 } 1095 }
1094 } 1096 }
1095 } 1097 }
1096 if ( item->incidence()->type() == "Event" ) { 1098 if ( item->incidence()->type() == "Event" ) {
1097 item->incidence()->setDtStart(startDt); 1099 item->incidence()->setDtStart(startDt);
1098 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt); 1100 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt);
1099 } else if ( item->incidence()->type() == "Todo" ) { 1101 } else if ( item->incidence()->type() == "Todo" ) {
1100 Todo* to = static_cast<Todo*>(item->incidence()); 1102 Todo* to = static_cast<Todo*>(item->incidence());
1101 1103
1102 to->setDtDue(endDt); 1104 to->setDtDue(endDt);
1103 if ( to->hasStartDate() ) { 1105 if ( to->hasStartDate() ) {
1104 if (to->dtStart() >= to->dtDue() ) 1106 if (to->dtStart() >= to->dtDue() )
1105 to->setDtStart(to->dtDue().addDays( -2 )); 1107 to->setDtStart(to->dtDue().addDays( -2 ));
1106 } 1108 }
1107 1109
1108 } 1110 }
1109 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() ); 1111 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() );
1110 item->incidence()->setRevision(item->incidence()->revision()+1); 1112 item->incidence()->setRevision(item->incidence()->revision()+1);
1111 item->setItemDate(startDt.date()); 1113 item->setItemDate(startDt.date());
1112 //item->updateItem(); 1114 //item->updateItem();
1113 if ( item->incidence()->type() == "Todo" ) { 1115 if ( item->incidence()->type() == "Todo" ) {
1114 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED ); 1116 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED );
1115 1117
1116 } 1118 }
1117 else 1119 else
1118 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED); 1120 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED);
1119 item->updateItem(); 1121 item->updateItem();
1120} 1122}
1121 1123
1122void KOAgendaView::showDates( const QDate &start, const QDate &end ) 1124void KOAgendaView::showDates( const QDate &start, const QDate &end )
1123{ 1125{
1124 // kdDebug() << "KOAgendaView::selectDates" << endl; 1126 // kdDebug() << "KOAgendaView::selectDates" << endl;
1125 1127
1126 mSelectedDates.clear(); 1128 mSelectedDates.clear();
1127 // qDebug("KOAgendaView::showDates "); 1129 // qDebug("KOAgendaView::showDates ");
1128 QDate d = start; 1130 QDate d = start;
1129 while (d <= end) { 1131 while (d <= end) {
1130 mSelectedDates.append(d); 1132 mSelectedDates.append(d);
1131 d = d.addDays( 1 ); 1133 d = d.addDays( 1 );
1132 } 1134 }
1133 1135
1134 // and update the view 1136 // and update the view
1135 fillAgenda(); 1137 fillAgenda();
1136} 1138}
1137 1139
1138 1140
1139void KOAgendaView::showEvents(QPtrList<Event>) 1141void KOAgendaView::showEvents(QPtrList<Event>)
1140{ 1142{
1141 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl; 1143 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl;
1142} 1144}
1143 1145
1144void KOAgendaView::changeEventDisplay(Event *, int) 1146void KOAgendaView::changeEventDisplay(Event *, int)
1145{ 1147{
1146 // qDebug("KOAgendaView::changeEventDisplay "); 1148 // qDebug("KOAgendaView::changeEventDisplay ");
1147 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl; 1149 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl;
1148 // this should be re-written to be MUCH smarter. Right now we 1150 // this should be re-written to be MUCH smarter. Right now we
1149 // are just playing dumb. 1151 // are just playing dumb.
1150 fillAgenda(); 1152 fillAgenda();
1151} 1153}
1152 1154
1153void KOAgendaView::fillAgenda(const QDate &) 1155void KOAgendaView::fillAgenda(const QDate &)
1154{ 1156{
1155 // qDebug("KOAgendaView::fillAgenda "); 1157 // qDebug("KOAgendaView::fillAgenda ");
1156 fillAgenda(); 1158 fillAgenda();
1157} 1159}
1158 1160
1159void KOAgendaView::fillAgenda() 1161void KOAgendaView::fillAgenda()
1160{ 1162{
1161 if ( globalFlagBlockStartup ) 1163 if ( globalFlagBlockStartup )
1162 return; 1164 return;
1163 if ( globalFlagBlockAgenda == 1 ) 1165 if ( globalFlagBlockAgenda == 1 )
1164 return; 1166 return;
1165 static bool onlyOne = false; 1167 static bool onlyOne = false;
1166 if ( onlyOne ) 1168 if ( onlyOne )
1167 return; 1169 return;
1168 onlyOne = true; 1170 onlyOne = true;
1169 //if ( globalFlagBlockAgenda == 2 ) 1171 //if ( globalFlagBlockAgenda == 2 )
1170 //globalFlagBlockAgenda = 0; 1172 //globalFlagBlockAgenda = 0;
1171 // globalFlagBlockPainting = false; 1173 // globalFlagBlockPainting = false;
1172 if ( globalFlagBlockAgenda == 0 ) 1174 if ( globalFlagBlockAgenda == 0 )
1173 globalFlagBlockAgenda = 1; 1175 globalFlagBlockAgenda = 1;
1174 // clearView(); 1176 // clearView();
1175 //qDebug("fillAgenda()++++ "); 1177 //qDebug("fillAgenda()++++ ");
1176 globalFlagBlockAgendaItemPaint = 1; 1178 globalFlagBlockAgendaItemPaint = 1;
1177 1179
1178 mAllDayAgenda->changeColumns(mSelectedDates.count()); 1180 mAllDayAgenda->changeColumns(mSelectedDates.count());
1179 mAgenda->changeColumns(mSelectedDates.count()); 1181 mAgenda->changeColumns(mSelectedDates.count());
1180 qApp->processEvents(); 1182 qApp->processEvents();
1181 mEventIndicatorTop->changeColumns(mSelectedDates.count()); 1183 mEventIndicatorTop->changeColumns(mSelectedDates.count());
1182 mEventIndicatorBottom->changeColumns(mSelectedDates.count()); 1184 mEventIndicatorBottom->changeColumns(mSelectedDates.count());
1183 setHolidayMasks(); 1185 setHolidayMasks();
1184 1186
1185 //mAgenda->hideUnused(); 1187 //mAgenda->hideUnused();
1186 //mAllDayAgenda->hideUnused(); 1188 //mAllDayAgenda->hideUnused();
1187 1189
1188 // mAgenda->blockNextRepaint( false ); 1190 // mAgenda->blockNextRepaint( false );
1189 // mAgenda->viewport()->repaint(); 1191 // mAgenda->viewport()->repaint();
1190 // mAgenda->blockNextRepaint( true ); 1192 // mAgenda->blockNextRepaint( true );
1191 mMinY.resize(mSelectedDates.count()); 1193 mMinY.resize(mSelectedDates.count());
1192 mMaxY.resize(mSelectedDates.count()); 1194 mMaxY.resize(mSelectedDates.count());
1193 1195
1194 QPtrList<Event> dayEvents; 1196 QPtrList<Event> dayEvents;
1195 1197
1196 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 1198 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
1197 // Therefore, gtodoset all of them. 1199 // Therefore, gtodoset all of them.
1198 QPtrList<Todo> todos = calendar()->todos(); 1200 QPtrList<Todo> todos = calendar()->todos();
1199 1201
1200 mAgenda->setDateList(mSelectedDates); 1202 mAgenda->setDateList(mSelectedDates);
1201 1203
1202 QDate today = QDate::currentDate(); 1204 QDate today = QDate::currentDate();
1203 1205
1204 DateList::ConstIterator dit; 1206 DateList::ConstIterator dit;
1205 int curCol = 0; 1207 int curCol = 0;
1206 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 1208 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
1207 QDate currentDate = *dit; 1209 QDate currentDate = *dit;
1208 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString() 1210 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString()
1209 // << endl; 1211 // << endl;
1210 1212
1211 dayEvents = calendar()->events(currentDate,true); 1213 dayEvents = calendar()->events(currentDate,true);
1212 1214
1213 // Default values, which can never be reached 1215 // Default values, which can never be reached
1214 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1; 1216 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1;
1215 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1; 1217 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1;
1216 1218
1217 unsigned int numEvent; 1219 unsigned int numEvent;
1218 for(numEvent=0;numEvent<dayEvents.count();++numEvent) { 1220 for(numEvent=0;numEvent<dayEvents.count();++numEvent) {
1219 Event *event = dayEvents.at(numEvent); 1221 Event *event = dayEvents.at(numEvent);
1220 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") ) 1222 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") )
1221 if ( event->uid().left(15) == QString("last-syncEvent-") ) 1223 if ( event->uid().left(15) == QString("last-syncEvent-") )
1222 continue; 1224 continue;
1223 // kdDebug() << " Event: " << event->summary() << endl; 1225 // kdDebug() << " Event: " << event->summary() << endl;
1224 1226
1225 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol; 1227 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol;
1226 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol; 1228 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol;
1227 1229
1228 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl; 1230 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl;
1229 1231
1230 if (event->doesFloat()) { 1232 if (event->doesFloat()) {
1231 if (event->recurrence()->doesRecur()) { 1233 if (event->recurrence()->doesRecur()) {
1232 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol); 1234 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol);
1233 } else { 1235 } else {
1234 if (beginX <= 0 && curCol == 0) { 1236 if (beginX <= 0 && curCol == 0) {
1235 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1237 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1236 } else if (beginX == curCol) { 1238 } else if (beginX == curCol) {
1237 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1239 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1238 } 1240 }
1239 } 1241 }
1240 } else if (event->isMultiDay()) { 1242 } else if (event->isMultiDay()) {
1241 if ( event->doesRecur () ) { 1243 if ( event->doesRecur () ) {
1242 QDate dateit = currentDate; 1244 QDate dateit = currentDate;
1243 int count = 0; 1245 int count = 0;
1244 int max = event->dtStart().daysTo( event->dtEnd() ) +2; 1246 int max = event->dtStart().daysTo( event->dtEnd() ) +2;
1245 while (! event->recursOn( dateit ) && count <= max ) { 1247 while (! event->recursOn( dateit ) && count <= max ) {
1246 ++count; 1248 ++count;
1247 dateit = dateit.addDays( -1 ); 1249 dateit = dateit.addDays( -1 );
1248 } 1250 }
1249 bool ok; 1251 bool ok;
1250 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok ); 1252 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok );
1251 if ( ok ) 1253 if ( ok )
1252 { 1254 {
1253 int secs = event->dtStart().secsTo( event->dtEnd() ); 1255 int secs = event->dtStart().secsTo( event->dtEnd() );
1254 QDateTime nextOcend =nextOcstart.addSecs( secs ); ; 1256 QDateTime nextOcend =nextOcstart.addSecs( secs ); ;
1255 beginX = currentDate.daysTo(nextOcstart.date()) + curCol; 1257 beginX = currentDate.daysTo(nextOcstart.date()) + curCol;
1256 endX = currentDate.daysTo(nextOcend.date()) + curCol; 1258 endX = currentDate.daysTo(nextOcend.date()) + curCol;
1257 1259
1258 } 1260 }
1259 } 1261 }
1260 int startY = mAgenda->timeToY(event->dtStart().time()); 1262 int startY = mAgenda->timeToY(event->dtStart().time());
1261 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1263 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1262 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol ); 1264 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol );
1263 if ((beginX <= 0 && curCol == 0) || beginX == curCol) { 1265 if ((beginX <= 0 && curCol == 0) || beginX == curCol) {
1264 //qDebug("insert!!! "); 1266 //qDebug("insert!!! ");
1265 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY); 1267 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY);
1266 } 1268 }
1267 if (beginX == curCol) { 1269 if (beginX == curCol) {
1268 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1270 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1269 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1271 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1270 } else if (endX == curCol) { 1272 } else if (endX == curCol) {
1271 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1273 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1272 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1274 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1273 } else { 1275 } else {
1274 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1276 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1275 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1277 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1276 } 1278 }
1277 } else { 1279 } else {
1278 int startY = mAgenda->timeToY(event->dtStart().time()); 1280 int startY = mAgenda->timeToY(event->dtStart().time());
1279 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1281 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1280 if (endY < startY) endY = startY; 1282 if (endY < startY) endY = startY;
1281 mAgenda->insertItem(event,currentDate,curCol,startY,endY); 1283 mAgenda->insertItem(event,currentDate,curCol,startY,endY);
1282 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1284 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1283 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1285 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1284 } 1286 }
1285 } 1287 }
1286 // ---------- [display Todos -------------- 1288 // ---------- [display Todos --------------
1287 unsigned int numTodo; 1289 unsigned int numTodo;
1288 for (numTodo = 0; numTodo < todos.count(); ++numTodo) { 1290 for (numTodo = 0; numTodo < todos.count(); ++numTodo) {
1289 Todo *todo = todos.at(numTodo); 1291 Todo *todo = todos.at(numTodo);
1290 1292
1291 if ( ! todo->hasDueDate() && !todo->hasCompletedDate()) continue; // todo shall not be displayed if it has no date 1293 if ( ! todo->hasDueDate() && !todo->hasCompletedDate()) continue; // todo shall not be displayed if it has no date
1292 1294
1293 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 1295 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
1294 // Already completed items can be displayed on their original due date 1296 // Already completed items can be displayed on their original due date
1295 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda 1297 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda
1296 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda; 1298 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda;
1297 bool fillIn = false; 1299 bool fillIn = false;
1298 if ( todo->hasCompletedDate() && todo->completed().date() == currentDate ) 1300 if ( todo->hasCompletedDate() && todo->completed().date() == currentDate )
1299 fillIn = true; 1301 fillIn = true;
1300 if ( ! fillIn && !todo->hasCompletedDate() ) 1302 if ( ! fillIn && !todo->hasCompletedDate() )
1301 fillIn = ((todo->dtDue().date() == currentDate) && !overdue) || ((currentDate == today) && overdue); 1303 fillIn = ((todo->dtDue().date() == currentDate) && !overdue) || ((currentDate == today) && overdue);
1302 if ( fillIn ) { 1304 if ( fillIn ) {
1303 if ( (todo->doesFloat() || overdue ) && !todo->hasCompletedDate() ) { // Todo has no due-time set or is already overdue 1305 if ( (todo->doesFloat() || overdue ) && !todo->hasCompletedDate() ) { // Todo has no due-time set or is already overdue
1304 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1306 if ( KOPrefs::instance()->mShowTodoInAgenda )
1305 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol); 1307 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol);
1306 } 1308 }
1307 else { 1309 else {
1308 QDateTime dt; 1310 QDateTime dt;
1309 if ( todo->hasCompletedDate() ) 1311 if ( todo->hasCompletedDate() )
1310 dt = todo->completed(); 1312 dt = todo->completed();
1311 else 1313 else
1312 dt = todo->dtDue();; 1314 dt = todo->dtDue();;
1313 1315
1314 1316
1315 int endY = mAgenda->timeToY(dt.time()) - 1; 1317 int endY = mAgenda->timeToY(dt.time()) - 1;
1316 int hi = (18/KOPrefs::instance()->mHourSize); 1318 int hi = (18/KOPrefs::instance()->mHourSize);
1317 //qDebug("hei %d ",KOPrefs::instance()->mHourSize); 1319 //qDebug("hei %d ",KOPrefs::instance()->mHourSize);
1318 int startY = endY -hi; 1320 int startY = endY -hi;
1319 1321
1320 mAgenda->insertItem(todo,currentDate,curCol,startY,endY); 1322 mAgenda->insertItem(todo,currentDate,curCol,startY,endY);
1321 1323
1322 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1324 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1323 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1325 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1324 } 1326 }
1325 } 1327 }
1326 } 1328 }
1327 // ---------- display Todos] -------------- 1329 // ---------- display Todos] --------------
1328 1330
1329 ++curCol; 1331 ++curCol;
1330 } 1332 }
1331 mAgenda->hideUnused(); 1333 mAgenda->hideUnused();
1332 mAllDayAgenda->hideUnused(); 1334 mAllDayAgenda->hideUnused();
1333 mAgenda->checkScrollBoundaries(); 1335 mAgenda->checkScrollBoundaries();
1334 1336
1335 deleteSelectedDateTime(); 1337 deleteSelectedDateTime();
1336 1338
1337 createDayLabels(); 1339 createDayLabels();
1338 emit incidenceSelected( 0 ); 1340 emit incidenceSelected( 0 );
1339 1341
1340 if ( globalFlagBlockAgenda == 2 ) { 1342 if ( globalFlagBlockAgenda == 2 ) {
1341 if ( KOPrefs::instance()->mSetTimeToDayStartAt ) 1343 if ( KOPrefs::instance()->mSetTimeToDayStartAt )
1342 setStartHour( KOPrefs::instance()->mDayBegins ); 1344 setStartHour( KOPrefs::instance()->mDayBegins );
1343 else if ( KOPrefs::instance()->mCenterOnCurrentTime ) 1345 else if ( KOPrefs::instance()->mCenterOnCurrentTime )
1344 setStartHour( QTime::currentTime ().hour() ); 1346 setStartHour( QTime::currentTime ().hour() );
1345 // qApp->processEvents(); 1347 // qApp->processEvents();
1346 } 1348 }
1347 qApp->processEvents(); 1349 qApp->processEvents();
1348 //qDebug("qApp->processEvents(); END "); 1350 //qDebug("qApp->processEvents(); END ");
1349 globalFlagBlockAgenda = 0; 1351 globalFlagBlockAgenda = 0;
1350 1352
1351 // mAgenda->hideUnused(); 1353 // mAgenda->hideUnused();
1352 //mAllDayAgenda->hideUnused(); 1354 //mAllDayAgenda->hideUnused();
1353 mAllDayAgenda->drawContentsToPainter(); 1355 mAllDayAgenda->drawContentsToPainter();
1354 mAgenda->drawContentsToPainter(); 1356 mAgenda->drawContentsToPainter();
1355 repaintAgenda(); 1357 repaintAgenda();
1356 onlyOne = false; 1358 onlyOne = false;
1357 // mAgenda->finishUpdate(); 1359 // mAgenda->finishUpdate();
1358 //mAllDayAgenda->finishUpdate(); 1360 //mAllDayAgenda->finishUpdate();
1359 1361
1360 // repaintAgenda(); 1362 // repaintAgenda();
1361 //qApp->processEvents(); 1363 //qApp->processEvents();
1362 // globalFlagBlockAgenda = 0; 1364 // globalFlagBlockAgenda = 0;
1363} 1365}
1364void KOAgendaView::repaintAgenda() 1366void KOAgendaView::repaintAgenda()
1365{ 1367{
1366 // mAllDayAgenda->drawContentsToPainter(); 1368 // mAllDayAgenda->drawContentsToPainter();
1367// mAllDayAgenda->viewport()->repaint( false ); 1369// mAllDayAgenda->viewport()->repaint( false );
1368// mAgenda->drawContentsToPainter(); 1370// mAgenda->drawContentsToPainter();
1369// mAgenda->viewport()->repaint( false ); 1371// mAgenda->viewport()->repaint( false );
1370// qApp->processEvents(); 1372// qApp->processEvents();
1371 1373
1372 //qDebug("KOAgendaView::repaintAgenda() "); 1374 //qDebug("KOAgendaView::repaintAgenda() ");
1373 //qApp->processEvents(); 1375 //qApp->processEvents();
1374 mAgenda->viewport()->repaint( false ); 1376 mAgenda->viewport()->repaint( false );
1375 mAllDayAgenda->viewport()->repaint( false ); 1377 mAllDayAgenda->viewport()->repaint( false );
1376 mAgenda->finishUpdate(); 1378 mAgenda->finishUpdate();
1377 mAllDayAgenda->finishUpdate(); 1379 mAllDayAgenda->finishUpdate();
1378} 1380}
1379 1381
1380 1382
1381void KOAgendaView::clearView() 1383void KOAgendaView::clearView()
1382{ 1384{
1383 // kdDebug() << "ClearView" << endl; 1385 // kdDebug() << "ClearView" << endl;
1384 mAllDayAgenda->clear(); 1386 mAllDayAgenda->clear();
1385 mAgenda->clear(); 1387 mAgenda->clear();
1386} 1388}
1387 1389
1388void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1390void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1389 const QDate &td) 1391 const QDate &td)
1390{ 1392{
1391#ifndef KORG_NOPRINTER 1393#ifndef KORG_NOPRINTER
1392 if (fd == td) 1394 if (fd == td)
1393 calPrinter->preview(CalPrinter::Day, fd, td); 1395 calPrinter->preview(CalPrinter::Day, fd, td);
1394 else 1396 else
1395 calPrinter->preview(CalPrinter::Week, fd, td); 1397 calPrinter->preview(CalPrinter::Week, fd, td);
1396#endif 1398#endif
1397} 1399}
1398 1400
1399// void KOAgendaView::updateMovedTodo() 1401// void KOAgendaView::updateMovedTodo()
1400// { 1402// {
1401// // updateConfig(); 1403// // updateConfig();
1402// // emit updateTodoViews(); 1404// // emit updateTodoViews();
1403// } 1405// }
1404 1406
1405void KOAgendaView::slotShowDateView( int mode , int d ) 1407void KOAgendaView::slotShowDateView( int mode , int d )
1406{ 1408{
1407 if ( d >= mSelectedDates.count() ) { 1409 if ( d >= mSelectedDates.count() ) {
1408 qDebug("KOAgendaView::slotShowDateView datecounterror %d d ", d, mSelectedDates.count() ); 1410 qDebug("KOAgendaView::slotShowDateView datecounterror %d d ", d, mSelectedDates.count() );
1409 1411
1410 } else { 1412 } else {
1411 QDate day = mSelectedDates[d]; 1413 QDate day = mSelectedDates[d];
1412 emit showDateView(mode , day ); 1414 emit showDateView(mode , day );
1413 } 1415 }
1414 1416
1415} 1417}
1416void KOAgendaView::newEvent(int gx, int gy) 1418void KOAgendaView::newEvent(int gx, int gy)
1417{ 1419{
1418 if (!mSelectedDates.count()) return; 1420 if (!mSelectedDates.count()) return;
1419 1421
1420 QDate day = mSelectedDates[gx]; 1422 QDate day = mSelectedDates[gx];
1421 1423
1422 QTime time = mAgenda->gyToTime(gy); 1424 QTime time = mAgenda->gyToTime(gy);
1423 QDateTime dt(day,time); 1425 QDateTime dt(day,time);
1424 // if ( dt < QDateTime::currentDateTime () ) 1426 // if ( dt < QDateTime::currentDateTime () )
1425 // dt = QDateTime::currentDateTime ().addSecs( 3600 ); 1427 // dt = QDateTime::currentDateTime ().addSecs( 3600 );
1426 emit newEventSignal(dt); 1428 emit newEventSignal(dt);
1427} 1429}
1428 1430
1429void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd) 1431void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd)
1430{ 1432{
1431 if (!mSelectedDates.count()) return; 1433 if (!mSelectedDates.count()) return;
1432 1434
1433 QDate dayStart = mSelectedDates[gxStart]; 1435 QDate dayStart = mSelectedDates[gxStart];
1434 QDate dayEnd = mSelectedDates[gxEnd]; 1436 QDate dayEnd = mSelectedDates[gxEnd];
1435 1437
1436 QTime timeStart = mAgenda->gyToTime(gyStart); 1438 QTime timeStart = mAgenda->gyToTime(gyStart);
1437 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1439 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1438 1440
1439 QDateTime dtStart(dayStart,timeStart); 1441 QDateTime dtStart(dayStart,timeStart);
1440 QDateTime dtEnd(dayEnd,timeEnd); 1442 QDateTime dtEnd(dayEnd,timeEnd);
1441 1443
1442 emit newEventSignal(dtStart,dtEnd); 1444 emit newEventSignal(dtStart,dtEnd);
1443} 1445}
1444 1446
1445void KOAgendaView::newEventAllDay(int gx, int ) 1447void KOAgendaView::newEventAllDay(int gx, int )
1446{ 1448{
1447 if (!mSelectedDates.count()) return; 1449 if (!mSelectedDates.count()) return;
1448 1450
1449 QDate day = mSelectedDates[gx]; 1451 QDate day = mSelectedDates[gx];
1450 1452
1451 emit newEventSignal(day); 1453 emit newEventSignal(day);
1452} 1454}
1453void KOAgendaView::newTodoAllDay(int gx, int ) 1455void KOAgendaView::newTodoAllDay(int gx, int )
1454{ 1456{
1455 if (!mSelectedDates.count()) return; 1457 if (!mSelectedDates.count()) return;
1456 1458
1457 QDateTime day (mSelectedDates[gx] ); 1459 QDateTime day (mSelectedDates[gx] );
1458 emit newTodoSignal(day, true); 1460 emit newTodoSignal(day, true);
1459} 1461}
1460void KOAgendaView::newTodo(int gx, int gy ) 1462void KOAgendaView::newTodo(int gx, int gy )
1461{ 1463{
1462 if (!mSelectedDates.count()) return; 1464 if (!mSelectedDates.count()) return;
1463 QDate dayStart = mSelectedDates[gx]; 1465 QDate dayStart = mSelectedDates[gx];
1464 QTime timeStart = mAgenda->gyToTime(gy); 1466 QTime timeStart = mAgenda->gyToTime(gy);
1465 QDateTime dt (dayStart,timeStart); 1467 QDateTime dt (dayStart,timeStart);
1466 emit newTodoSignal( dt, false ); 1468 emit newTodoSignal( dt, false );
1467} 1469}
1468 1470
1469void KOAgendaView::updateEventIndicatorTop(int newY) 1471void KOAgendaView::updateEventIndicatorTop(int newY)
1470{ 1472{
1471 uint i; 1473 uint i;
1472 for(i=0;i<mMinY.size();++i) { 1474 for(i=0;i<mMinY.size();++i) {
1473 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true); 1475 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true);
1474 else mEventIndicatorTop->enableColumn(i,false); 1476 else mEventIndicatorTop->enableColumn(i,false);
1475 } 1477 }
1476 1478
1477 mEventIndicatorTop->update(); 1479 mEventIndicatorTop->update();
1478} 1480}
1479 1481
1480void KOAgendaView::updateEventIndicatorBottom(int newY) 1482void KOAgendaView::updateEventIndicatorBottom(int newY)
1481{ 1483{
1482 uint i; 1484 uint i;
1483 for(i=0;i<mMaxY.size();++i) { 1485 for(i=0;i<mMaxY.size();++i) {
1484 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true); 1486 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true);
1485 else mEventIndicatorBottom->enableColumn(i,false); 1487 else mEventIndicatorBottom->enableColumn(i,false);
1486 } 1488 }
1487 1489
1488 mEventIndicatorBottom->update(); 1490 mEventIndicatorBottom->update();
1489} 1491}
1490 1492
1491void KOAgendaView::startDrag(Event *event) 1493void KOAgendaView::startDrag(Event *event)
1492{ 1494{
1493#ifndef KORG_NODND 1495#ifndef KORG_NODND
1494 DndFactory factory( calendar() ); 1496 DndFactory factory( calendar() );
1495 ICalDrag *vd = factory.createDrag(event,this); 1497 ICalDrag *vd = factory.createDrag(event,this);
1496 if (vd->drag()) { 1498 if (vd->drag()) {
1497 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl; 1499 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl;
1498 } 1500 }
1499#endif 1501#endif
1500} 1502}
1501 1503
1502void KOAgendaView::readSettings() 1504void KOAgendaView::readSettings()
1503{ 1505{
1504 readSettings(KOGlobals::config()); 1506 readSettings(KOGlobals::config());
1505} 1507}
1506 1508
1507void KOAgendaView::readSettings(KConfig *config) 1509void KOAgendaView::readSettings(KConfig *config)
1508{ 1510{
1509 // kdDebug() << "KOAgendaView::readSettings()" << endl; 1511 // kdDebug() << "KOAgendaView::readSettings()" << endl;
1510 1512
1511 config->setGroup("Views"); 1513 config->setGroup("Views");
1512 1514
1513 //#ifndef KORG_NOSPLITTER 1515 //#ifndef KORG_NOSPLITTER
1514 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView"); 1516 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView");
1515 if (sizes.count() == 2) { 1517 if (sizes.count() == 2) {
1516 if ( sizes[0] < 20 ) { 1518 if ( sizes[0] < 20 ) {
1517 sizes[1] = sizes[1] +20 - sizes[0]; 1519 sizes[1] = sizes[1] +20 - sizes[0];
1518 sizes[0] = 20; 1520 sizes[0] = 20;
1519 } 1521 }
1520 mSplitterAgenda->setSizes(sizes); 1522 mSplitterAgenda->setSizes(sizes);
1521 // qDebug("read %d %d ",sizes[0],sizes[1] ); 1523 // qDebug("read %d %d ",sizes[0],sizes[1] );
1522 } 1524 }
1523 //#endif 1525 //#endif
1524 1526
1525 // updateConfig(); 1527 // updateConfig();
1526} 1528}
1527 1529
1528void KOAgendaView::writeSettings(KConfig *config) 1530void KOAgendaView::writeSettings(KConfig *config)
1529{ 1531{
1530 // kdDebug() << "KOAgendaView::writeSettings()" << endl; 1532 // kdDebug() << "KOAgendaView::writeSettings()" << endl;
1531 1533
1532 config->setGroup("Views"); 1534 config->setGroup("Views");
1533 1535
1534 //#ifndef KORG_NOSPLITTER 1536 //#ifndef KORG_NOSPLITTER
1535 QValueList<int> list = mSplitterAgenda->sizes(); 1537 QValueList<int> list = mSplitterAgenda->sizes();
1536 config->writeEntry("Separator AgendaView",list); 1538 config->writeEntry("Separator AgendaView",list);
1537 //qDebug("write %d %d ", list[0],list[1] ); 1539 //qDebug("write %d %d ", list[0],list[1] );
1538 //#endif 1540 //#endif
1539} 1541}
1540 1542
1541void KOAgendaView::setHolidayMasks() 1543void KOAgendaView::setHolidayMasks()
1542{ 1544{
1543 mHolidayMask.resize(mSelectedDates.count()); 1545 mHolidayMask.resize(mSelectedDates.count());
1544 1546
1545 uint i; 1547 uint i;
1546 for(i=0;i<mSelectedDates.count();++i) { 1548 for(i=0;i<mSelectedDates.count();++i) {
1547 QDate date = mSelectedDates[i]; 1549 QDate date = mSelectedDates[i];
1548 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6); 1550 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6);
1549 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7); 1551 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7);
1550 bool showHoliday = false; 1552 bool showHoliday = false;
1551 if ( KOPrefs::instance()->mExcludeHolidays ) { 1553 if ( KOPrefs::instance()->mExcludeHolidays ) {
1552 QPtrList<Event> events = calendar()->events( date, true ); 1554 QPtrList<Event> events = calendar()->events( date, true );
1553 Event *event; 1555 Event *event;
1554 for( event = events.first(); event; event = events.next() ) { 1556 for( event = events.first(); event; event = events.next() ) {
1555 if ( event->isHoliday()) { 1557 if ( event->isHoliday()) {
1556 showHoliday = true; 1558 showHoliday = true;
1557 break; 1559 break;
1558 } 1560 }
1559 } 1561 }
1560 1562
1561 } 1563 }
1562 1564
1563#ifndef KORG_NOPLUGINS 1565#ifndef KORG_NOPLUGINS
1564 bool showHoliday = KOPrefs::instance()->mExcludeHolidays && 1566 bool showHoliday = KOPrefs::instance()->mExcludeHolidays &&
1565 !KOCore::self()->holiday(date).isEmpty(); 1567 !KOCore::self()->holiday(date).isEmpty();
1566#endif 1568#endif
1567 bool showDay = showSaturday || showSunday || showHoliday; 1569 bool showDay = showSaturday || showSunday || showHoliday;
1568 1570
1569 if (showDay) { 1571 if (showDay) {
1570 mHolidayMask.at(i) = true; 1572 mHolidayMask.at(i) = true;
1571 } else { 1573 } else {
1572 mHolidayMask.at(i) = false; 1574 mHolidayMask.at(i) = false;
1573 } 1575 }
1574 } 1576 }
1575 1577
1576 mAgenda->setHolidayMask(&mHolidayMask); 1578 mAgenda->setHolidayMask(&mHolidayMask);
1577 mAllDayAgenda->setHolidayMask(&mHolidayMask); 1579 mAllDayAgenda->setHolidayMask(&mHolidayMask);
1578} 1580}
1579 1581
1580void KOAgendaView::setContentsPos(int y) 1582void KOAgendaView::setContentsPos(int y)
1581{ 1583{
1582 mAgenda->setContentsPos(0,y); 1584 mAgenda->setContentsPos(0,y);
1583} 1585}
1584 1586
1585void KOAgendaView::clearSelection() 1587void KOAgendaView::clearSelection()
1586{ 1588{
1587 mAgenda->deselectItem(); 1589 mAgenda->deselectItem();
1588 mAllDayAgenda->deselectItem(); 1590 mAllDayAgenda->deselectItem();
1589} 1591}
1590 1592
1591void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart, 1593void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart,
1592 int gxEnd, int gyEnd) 1594 int gxEnd, int gyEnd)
1593{ 1595{
1594 mTimeSpanInAllDay = true; 1596 mTimeSpanInAllDay = true;
1595 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd); 1597 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd);
1596} 1598}
1597 1599
1598 1600
1599 1601
1600 1602
1601void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart, 1603void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart,
1602 int gxEnd, int gyEnd) 1604 int gxEnd, int gyEnd)
1603{ 1605{
1604 if (!mSelectedDates.count()) return; 1606 if (!mSelectedDates.count()) return;
1605 1607
1606 QDate dayStart = mSelectedDates[gxStart]; 1608 QDate dayStart = mSelectedDates[gxStart];
1607 QDate dayEnd = mSelectedDates[gxEnd]; 1609 QDate dayEnd = mSelectedDates[gxEnd];
1608 1610
1609 QTime timeStart = mAgenda->gyToTime(gyStart); 1611 QTime timeStart = mAgenda->gyToTime(gyStart);
1610 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1612 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1611 1613
1612 QDateTime dtStart(dayStart,timeStart); 1614 QDateTime dtStart(dayStart,timeStart);
1613 QDateTime dtEnd(dayEnd,timeEnd); 1615 QDateTime dtEnd(dayEnd,timeEnd);
1614 1616
1615 mTimeSpanBegin = dtStart; 1617 mTimeSpanBegin = dtStart;
1616 mTimeSpanEnd = dtEnd; 1618 mTimeSpanEnd = dtEnd;
1617 1619
1618} 1620}
1619 1621
1620void KOAgendaView::deleteSelectedDateTime() 1622void KOAgendaView::deleteSelectedDateTime()
1621{ 1623{
1622 mTimeSpanBegin.setDate(QDate()); 1624 mTimeSpanBegin.setDate(QDate());
1623 mTimeSpanEnd.setDate(QDate()); 1625 mTimeSpanEnd.setDate(QDate());
1624 mTimeSpanInAllDay = false; 1626 mTimeSpanInAllDay = false;
1625} 1627}
1626 1628
1627void KOAgendaView::keyPressEvent ( QKeyEvent * e ) 1629void KOAgendaView::keyPressEvent ( QKeyEvent * e )
1628{ 1630{
1629 e->ignore(); 1631 e->ignore();
1630} 1632}
1631 1633
1632void KOAgendaView::scrollOneHourUp() 1634void KOAgendaView::scrollOneHourUp()
1633{ 1635{
1634 1636
1635 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 ); 1637 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 );
1636} 1638}
1637void KOAgendaView::scrollOneHourDown() 1639void KOAgendaView::scrollOneHourDown()
1638{ 1640{
1639 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 ); 1641 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 );
1640} 1642}
1641 1643
1642void KOAgendaView::setStartHour( int h ) 1644void KOAgendaView::setStartHour( int h )
1643{ 1645{
1644 mAgenda->setStartHour( h ); 1646 mAgenda->setStartHour( h );
1645 1647
1646} 1648}
1647void KOAgendaView::setInitStartHour() 1649void KOAgendaView::setInitStartHour()
1648{ 1650{
1649 1651
1650 if ( KOPrefs::instance()->mCenterOnCurrentTime ) 1652 if ( KOPrefs::instance()->mCenterOnCurrentTime )
1651 setStartHour( QTime::currentTime ().hour() ); 1653 setStartHour( QTime::currentTime ().hour() );
1652 else 1654 else
1653 setStartHour( KOPrefs::instance()->mDayBegins ); 1655 setStartHour( KOPrefs::instance()->mDayBegins );
1654 1656
1655} 1657}
1656 1658
1657 1659
1658void KOAgendaView::updateTodo( Todo * t, int ) 1660void KOAgendaView::updateTodo( Todo * t, int )
1659{ 1661{
1660 if ( !isVisible() ) 1662 if ( !isVisible() )
1661 return; 1663 return;
1662 bool remove = false; 1664 bool remove = false;
1663 bool removeAD = false; 1665 bool removeAD = false;
1664 QDate da; 1666 QDate da;
1665 if ( t->hasCompletedDate() ) 1667 if ( t->hasCompletedDate() )
1666 da = t->completed().date(); 1668 da = t->completed().date();
1667 else 1669 else
1668 da = t->dtDue().date(); 1670 da = t->dtDue().date();
1669 if ( ! t->hasDueDate() && !t->hasCompletedDate() ) { 1671 if ( ! t->hasDueDate() && !t->hasCompletedDate() ) {
1670 remove = true; 1672 remove = true;
1671 removeAD = true; 1673 removeAD = true;
1672 } 1674 }
1673 else { 1675 else {
1674 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ; 1676 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ;
1675 if ( overdue && 1677 if ( overdue &&
1676 QDate::currentDate() >= mSelectedDates.first() && 1678 QDate::currentDate() >= mSelectedDates.first() &&
1677 QDate::currentDate() <= mSelectedDates.last()) { 1679 QDate::currentDate() <= mSelectedDates.last()) {
1678 removeAD = false; 1680 removeAD = false;
1679 remove = true; 1681 remove = true;
1680 } 1682 }
1681 else { 1683 else {
1682 1684
1683 if ( da < mSelectedDates.first() || 1685 if ( da < mSelectedDates.first() ||
1684 da > mSelectedDates.last() ) { 1686 da > mSelectedDates.last() ) {
1685 remove = true; 1687 remove = true;
1686 removeAD = true; 1688 removeAD = true;
1687 } else { 1689 } else {
1688 remove = t->doesFloat() && !t->hasCompletedDate(); 1690 remove = t->doesFloat() && !t->hasCompletedDate();
1689 removeAD = !remove; 1691 removeAD = !remove;
1690 } 1692 }
1691 } 1693 }
1692 } 1694 }
1693 int days = mSelectedDates.first().daysTo( da ); 1695 int days = mSelectedDates.first().daysTo( da );
1694 //qDebug("daysto %d %d %d", days, remove,removeAD ); 1696 //qDebug("daysto %d %d %d", days, remove,removeAD );
1695 mAgenda->updateTodo( t , days, remove); 1697 mAgenda->updateTodo( t , days, remove);
1696 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1698 if ( KOPrefs::instance()->mShowTodoInAgenda )
1697 mAllDayAgenda->updateTodo( t , days, removeAD); 1699 mAllDayAgenda->updateTodo( t , days, removeAD);
1698 //qDebug("KOAgendaView::updateTodo( Todo *, int ) "); 1700 //qDebug("KOAgendaView::updateTodo( Todo *, int ) ");
1699 1701
1700} 1702}
diff --git a/korganizer/koagendaview.h b/korganizer/koagendaview.h
index 30c9b05..c6e6602 100644
--- a/korganizer/koagendaview.h
+++ b/korganizer/koagendaview.h
@@ -1,292 +1,292 @@
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#ifndef KOAGENDAVIEW_H 23#ifndef KOAGENDAVIEW_H
24#define KOAGENDAVIEW_H 24#define KOAGENDAVIEW_H
25 25
26#include <qscrollview.h> 26#include <qscrollview.h>
27#include <qdatetime.h> 27#include <qdatetime.h>
28#include <qpushbutton.h> 28#include <qpushbutton.h>
29#include <qlayout.h> 29#include <qlayout.h>
30#ifndef DESKTOP_VERSION 30#ifndef DESKTOP_VERSION
31#include <qksplitter.h> 31#include <qksplitter.h>
32#else 32#else
33#include <qsplitter.h> 33#include <qsplitter.h>
34#endif 34#endif
35#include <qmemarray.h> 35#include <qmemarray.h>
36 36
37#include "koeventview.h" 37#include "koeventview.h"
38 38
39class QHBox; 39class QHBox;
40class QFrame; 40class QFrame;
41class QLabel; 41class QLabel;
42class QPushButton; 42class QPushButton;
43class CalendarView; 43class CalendarView;
44class KOAgenda; 44class KOAgenda;
45class KOAgendaItem; 45class KOAgendaItem;
46class KConfig; 46class KConfig;
47class KDGanttMinimizeSplitter; 47class KDGanttMinimizeSplitter;
48 48
49class KOAgendaButton : public QPushButton 49class KOAgendaButton : public QPushButton
50{ 50{
51 Q_OBJECT 51 Q_OBJECT
52 public: 52 public:
53 KOAgendaButton( QWidget *parent=0, const char *name=0 ) : 53 KOAgendaButton( QWidget *parent=0, const char *name=0 ) :
54 QPushButton( parent, name ) 54 QPushButton( parent, name )
55 { 55 {
56 mNum = -3; 56 mNum = -3;
57 setFlat( true ); 57 setFlat( true );
58 setFocusPolicy(NoFocus); 58 setFocusPolicy(NoFocus);
59 setSizePolicy(QSizePolicy( QSizePolicy::Expanding ,QSizePolicy::Expanding )); 59 setSizePolicy(QSizePolicy( QSizePolicy::Expanding ,QSizePolicy::Expanding ));
60 connect( this, SIGNAL( clicked() ), this, SLOT ( bClicked() ) ); 60 connect( this, SIGNAL( clicked() ), this, SLOT ( bClicked() ) );
61 }; 61 };
62 62
63 QSize sizeHint () const { return QSize( 5,5) ;} 63 QSize sizeHint () const { return QSize( 5,5) ;}
64 void setNum( int n) { mNum = n; } 64 void setNum( int n) { mNum = n; }
65private slots: 65private slots:
66 void bClicked() {emit numClicked( mNum);} 66 void bClicked() {emit numClicked( mNum);}
67signals: 67signals:
68 void numClicked( int ); 68 void numClicked( int );
69private: 69private:
70 int mNum; 70 int mNum;
71}; 71};
72 72
73class TimeLabels : public QScrollView { 73class TimeLabels : public QScrollView {
74 Q_OBJECT 74 Q_OBJECT
75 public: 75 public:
76 TimeLabels(int rows,QWidget *parent=0,const char *name=0,WFlags f=0); 76 TimeLabels(int rows,QWidget *parent=0,const char *name=0,WFlags f=0);
77 77
78 void setCellHeight(int height); 78 void setCellHeight(int height);
79 79
80 /** Calculates the minimum width */ 80 /** Calculates the minimum width */
81 virtual int minimumWidth() const; 81 virtual int minimumWidth() const;
82 82
83 /** updates widget's internal state */ 83 /** updates widget's internal state */
84 void updateConfig(); 84 void updateConfig();
85 85
86 /** */ 86 /** */
87 void setAgenda(KOAgenda* agenda); 87 void setAgenda(KOAgenda* agenda);
88 88
89 /** */ 89 /** */
90 virtual void paintEvent(QPaintEvent* e); 90 virtual void paintEvent(QPaintEvent* e);
91 void contentsMousePressEvent ( QMouseEvent * ) ; 91 void contentsMousePressEvent ( QMouseEvent * ) ;
92 void contentsMouseReleaseEvent ( QMouseEvent * ); 92 void contentsMouseReleaseEvent ( QMouseEvent * );
93 void contentsMouseMoveEvent ( QMouseEvent * ); 93 void contentsMouseMoveEvent ( QMouseEvent * );
94 94
95 public slots: 95 public slots:
96 /** update time label positions */ 96 /** update time label positions */
97 void positionChanged(); 97 void positionChanged();
98 signals: 98 signals:
99 void scaleChanged(); 99 void scaleChanged();
100 protected: 100 protected:
101 void drawContents(QPainter *p,int cx, int cy, int cw, int ch); 101 void drawContents(QPainter *p,int cx, int cy, int cw, int ch);
102 102
103 private: 103 private:
104 QPixmap myPix; 104 QPixmap myPix;
105 bool mRedrawNeeded; 105 bool mRedrawNeeded;
106 int mMiniWidth; 106 int mMiniWidth;
107 int mMouseDownY; 107 int mMouseDownY;
108 QString mOrgCap; 108 QString mOrgCap;
109 int mRows; 109 int mRows;
110 int mCellHeight; 110 int mCellHeight;
111 111
112 /** */ 112 /** */
113 KOAgenda* mAgenda; 113 KOAgenda* mAgenda;
114}; 114};
115 115
116class EventIndicator : public QFrame { 116class EventIndicator : public QFrame {
117 Q_OBJECT 117 Q_OBJECT
118 public: 118 public:
119 enum Location { Top, Bottom }; 119 enum Location { Top, Bottom };
120 EventIndicator(Location loc=Top,QWidget *parent=0,const char *name=0); 120 EventIndicator(Location loc=Top,QWidget *parent=0,const char *name=0);
121 virtual ~EventIndicator(); 121 virtual ~EventIndicator();
122 122
123 void changeColumns(int columns); 123 void changeColumns(int columns);
124 void setPaintWidget( KDGanttMinimizeSplitter* ); 124 void setPaintWidget( KDGanttMinimizeSplitter* );
125 void setXOffset( int ); 125 void setXOffset( int );
126 void enableColumn(int column, bool enable); 126 void enableColumn(int column, bool enable);
127 127
128 protected: 128 protected:
129 void drawContents(QPainter *); 129 void drawContents(QPainter *);
130 130
131 private: 131 private:
132 int mXOffset; 132 int mXOffset;
133 KDGanttMinimizeSplitter* mPaintWidget; 133 KDGanttMinimizeSplitter* mPaintWidget;
134 int mColumns; 134 int mColumns;
135 QHBox *mTopBox; 135 QHBox *mTopBox;
136 QBoxLayout *mTopLayout; 136 QBoxLayout *mTopLayout;
137 Location mLocation; 137 Location mLocation;
138 QPixmap mPixmap; 138 QPixmap mPixmap;
139 QMemArray<bool> mEnabled; 139 QMemArray<bool> mEnabled;
140}; 140};
141 141
142/** 142/**
143 KOAgendaView is the agenda-like view used to display events in an one or 143 KOAgendaView is the agenda-like view used to display events in an one or
144 multi-day view. 144 multi-day view.
145*/ 145*/
146class KOAgendaView : public KOEventView { 146class KOAgendaView : public KOEventView {
147 Q_OBJECT 147 Q_OBJECT
148 public: 148 public:
149 KOAgendaView(Calendar *cal,QWidget *parent = 0,const char *name = 0 ); 149 KOAgendaView(Calendar *cal,QWidget *parent = 0,const char *name = 0 );
150 virtual ~KOAgendaView(); 150 virtual ~KOAgendaView();
151 void setStartHour( int ); 151 void setStartHour( int );
152 void toggleAllDay(); 152 void toggleAllDay();
153 153
154 154
155 /** Returns maximum number of days supported by the koagendaview */ 155 /** Returns maximum number of days supported by the koagendaview */
156 virtual int maxDatesHint(); 156 virtual int maxDatesHint();
157 157
158 /** Returns number of currently shown dates. */ 158 /** Returns number of currently shown dates. */
159 virtual int currentDateCount(); 159 virtual int currentDateCount();
160 160
161 /** returns the currently selected events */ 161 /** returns the currently selected events */
162 virtual QPtrList<Incidence> selectedIncidences(); 162 virtual QPtrList<Incidence> selectedIncidences();
163 163
164 /** returns the currently selected events */ 164 /** returns the currently selected events */
165 virtual DateList selectedDates(); 165 virtual DateList selectedDates();
166 166
167 /** Remove all events from view */ 167 /** Remove all events from view */
168 void clearView(); 168 void clearView();
169 KOAgenda *agenda() { return mAgenda;} 169 KOAgenda *agenda() { return mAgenda;}
170 virtual void printPreview(CalPrinter *calPrinter, 170 virtual void printPreview(CalPrinter *calPrinter,
171 const QDate &, const QDate &); 171 const QDate &, const QDate &);
172 172
173 /** start-datetime of selection */ 173 /** start-datetime of selection */
174 QDateTime selectionStart() {return mTimeSpanBegin;} 174 QDateTime selectionStart() {return mTimeSpanBegin;}
175 /** end-datetime of selection */ 175 /** end-datetime of selection */
176 QDateTime selectionEnd() {return mTimeSpanEnd;} 176 QDateTime selectionEnd() {return mTimeSpanEnd;}
177 /** returns true if selection is for whole day */ 177 /** returns true if selection is for whole day */
178 bool selectedIsAllDay() {return mTimeSpanInAllDay;} 178 bool selectedIsAllDay() {return mTimeSpanInAllDay;}
179 /** make selected start/end invalid */ 179 /** make selected start/end invalid */
180 void deleteSelectedDateTime(); 180 void deleteSelectedDateTime();
181 void repaintAgenda(); 181 void repaintAgenda();
182 public slots: 182 public slots:
183 void setInitStartHour(); 183 void setInitStartHour();
184 virtual void updateView(); 184 virtual void updateView();
185 virtual void updateConfig(); 185 virtual void updateConfig();
186 virtual void showDates(const QDate &start, const QDate &end); 186 virtual void showDates(const QDate &start, const QDate &end);
187 virtual void showEvents(QPtrList<Event> eventList); 187 virtual void showEvents(QPtrList<Event> eventList);
188 188
189 void updateTodo( Todo *, int ); 189 void updateTodo( Todo *, int );
190 void changeEventDisplay(Event *, int); 190 void changeEventDisplay(Event *, int);
191 191
192 void clearSelection(); 192 void clearSelection();
193 193
194 void newTodo(int gx,int gy); 194 void newTodo(int gx,int gy);
195 void newEvent(int gx,int gy); 195 void newEvent(int gx,int gy);
196 void newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd); 196 void newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd);
197 void newEventAllDay(int gx, int gy); 197 void newEventAllDay(int gx, int gy);
198 void newTodoAllDay(int gx, int gy); 198 void newTodoAllDay(int gx, int gy);
199 199
200 void startDrag(Event *); 200 void startDrag(Event *);
201 201
202 void readSettings(); 202 void readSettings();
203 void readSettings(KConfig *); 203 void readSettings(KConfig *);
204 void writeSettings(KConfig *); 204 void writeSettings(KConfig *);
205 205
206 void setContentsPos(int y); 206 void setContentsPos(int y);
207 207
208 void scrollOneHourUp(); 208 void scrollOneHourUp();
209 void scrollOneHourDown(); 209 void scrollOneHourDown();
210 void addToCalSlot(Incidence *, Incidence *); 210 void addToCalSlot(Incidence *, Incidence *);
211 void slotShowDateView( int, int ); 211 void slotShowDateView( int, int );
212 212
213 signals: 213 signals:
214 void showDateView( int, QDate ); 214 void showDateView( int, QDate );
215 void newTodoSignal( QDateTime ,bool ); 215 void newTodoSignal( QDateTime ,bool );
216 void toggleExpand(); 216 void toggleExpand();
217 void selectWeekNum( int ); 217 void selectWeekNum( int );
218 void todoMoved( Todo *, int ); 218 void todoMoved( Todo *, int );
219 void incidenceChanged(Incidence * , int ); 219 void incidenceChanged(Incidence * , int );
220 // void cloneIncidenceSignal(Incidence *); 220 // void cloneIncidenceSignal(Incidence *);
221 221
222 protected: 222 protected:
223 KOAgendaButton* getNewDaylabel(); 223 KOAgendaButton* getNewDaylabel();
224 bool mBlockUpdating; 224 bool mBlockUpdating;
225 int mUpcomingWidth; 225 int mUpcomingWidth;
226 /** Fill agenda beginning with date startDate */ 226 /** Fill agenda beginning with date startDate */
227 void fillAgenda(const QDate &startDate); 227 void fillAgenda(const QDate &startDate);
228 void resizeEvent( QResizeEvent* e ); 228 void resizeEvent( QResizeEvent* e );
229 /** Fill agenda using the current set value for the start date */ 229 /** Fill agenda using the current set value for the start date */
230 void fillAgenda(); 230 void fillAgenda();
231 231
232 /** Create labels for the selected dates. */ 232 /** Create labels for the selected dates. */
233 void createDayLabels(); 233 void createDayLabels();
234 234
235 /** 235 /**
236 Set the masks on the agenda widgets indicating, which days are holidays. 236 Set the masks on the agenda widgets indicating, which days are holidays.
237 */ 237 */
238 void setHolidayMasks(); 238 void setHolidayMasks();
239 239
240 protected slots: 240 protected slots:
241 void slotDaylabelClicked( int ); 241 void slotDaylabelClicked( int );
242 /** Update event belonging to agenda item */ 242 /** Update event belonging to agenda item */
243 void updateEventDates(KOAgendaItem *item, int mode = -1); 243 void updateEventDates(KOAgendaItem *item, int mode = -1);
244 //void updateMovedTodo(); 244 //void updateMovedTodo();
245 245
246 void updateEventIndicatorTop(int newY); 246 void updateEventIndicatorTop(int newY);
247 void updateEventIndicatorBottom(int newY); 247 void updateEventIndicatorBottom(int newY);
248 248
249 /** Updates data for selected timespan */ 249 /** Updates data for selected timespan */
250 void newTimeSpanSelected(int gxStart, int gyStart, int gxEnd, int gyEnd); 250 void newTimeSpanSelected(int gxStart, int gyStart, int gxEnd, int gyEnd);
251 /** Updates data for selected timespan for all day event*/ 251 /** Updates data for selected timespan for all day event*/
252 void newTimeSpanSelectedAllDay(int gxStart, int gyStart, int gxEnd, int gyEnd); 252 void newTimeSpanSelectedAllDay(int gxStart, int gyStart, int gxEnd, int gyEnd);
253 253
254 private: 254 private:
255 // view widgets 255 // view widgets
256 QFrame *mDayLabels; 256 QFrame *mDayLabels;
257 QHBox *mDayLabelsFrame; 257 QHBox *mDayLabelsFrame;
258 QBoxLayout *mLayoutDayLabels; 258 QBoxLayout *mLayoutDayLabels;
259 QFrame *mAllDayFrame; 259 QFrame *mAllDayFrame;
260 KOAgenda *mAllDayAgenda; 260 KOAgenda *mAllDayAgenda;
261 KOAgenda *mAgenda; 261 KOAgenda *mAgenda;
262 TimeLabels *mTimeLabels; 262 TimeLabels *mTimeLabels;
263 QWidget *mDummyAllDayLeft; 263 QWidget *mDummyAllDayLeft;
264 264
265 KDGanttMinimizeSplitter* mSplitterAgenda; 265 KDGanttMinimizeSplitter* mSplitterAgenda;
266 QPushButton *mExpandButton; 266 QPushButton *mExpandButton;
267 267
268 DateList mSelectedDates; // List of dates to be displayed 268 DateList mSelectedDates; // List of dates to be displayed
269 int mViewType; 269 int mViewType;
270 270
271 bool mWeekStartsMonday; 271 bool mWeekStartsMonday;
272 int mStartHour; 272 int mStartHour;
273 273
274 KOEventPopupMenu *mAgendaPopup; 274 KOEventPopupMenu *mAllAgendaPopup;
275 KOEventPopupMenu *mAllDayAgendaPopup; 275 //KOEventPopupMenu *mAllDayAgendaPopup;
276 276
277 EventIndicator *mEventIndicatorTop; 277 EventIndicator *mEventIndicatorTop;
278 EventIndicator *mEventIndicatorBottom; 278 EventIndicator *mEventIndicatorBottom;
279 279
280 QMemArray<int> mMinY; 280 QMemArray<int> mMinY;
281 QMemArray<int> mMaxY; 281 QMemArray<int> mMaxY;
282 282
283 QMemArray<bool> mHolidayMask; 283 QMemArray<bool> mHolidayMask;
284 284
285 QPtrList<KOAgendaButton> mDayLabelsList; 285 QPtrList<KOAgendaButton> mDayLabelsList;
286 QDateTime mTimeSpanBegin; 286 QDateTime mTimeSpanBegin;
287 QDateTime mTimeSpanEnd; 287 QDateTime mTimeSpanEnd;
288 bool mTimeSpanInAllDay; 288 bool mTimeSpanInAllDay;
289 void keyPressEvent ( QKeyEvent * e ); 289 void keyPressEvent ( QKeyEvent * e );
290}; 290};
291 291
292#endif // KOAGENDAVIEW_H 292#endif // KOAGENDAVIEW_H
diff --git a/korganizer/kotodoview.cpp b/korganizer/kotodoview.cpp
index ccc4b01..0a315cb 100644
--- a/korganizer/kotodoview.cpp
+++ b/korganizer/kotodoview.cpp
@@ -1,1394 +1,1413 @@
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
211 QPoint p(contentsToViewport(e->pos()));
212 QListViewItem *i = itemAt(p);
213 bool rootClicked = true;
214 if (i) {
215 // if the user clicked into the root decoration of the item, don't
216 // try to start a drag!
217 int X = p.x();
218 //qDebug("%d %d %d", X, header()->sectionPos(0), treeStepSize() );
219 if (X > header()->sectionPos(0) +
220 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) +
221 itemMargin() ||
222 X < header()->sectionPos(0)) {
223 rootClicked = false;
224 }
225 }
210#ifndef KORG_NODND 226#ifndef KORG_NODND
211 QPoint p(contentsToViewport(e->pos())); 227 mMousePressed = false;
212 QListViewItem *i = itemAt(p); 228 if (! rootClicked ) {
213 mMousePressed = false;
214 if (i) {
215 // if the user clicked into the root decoration of the item, don't
216 // try to start a drag!
217 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) +
218 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) +
219 itemMargin() ||
220 p.x() < header()->sectionPos(header()->mapToIndex(0))) {
221 if (e->button()==Qt::LeftButton) {
222 mPressPos = e->pos(); 229 mPressPos = e->pos();
223 mMousePressed = true; 230 mMousePressed = true;
224 }
225 } 231 }
226 }
227#endif 232#endif
228 QListView::contentsMousePressEvent(e); 233 //qDebug("KOTodoListView::contentsMousePressEvent %d", rootClicked);
234#ifndef DESKTOP_VERSION
235 if (!( e->button() == RightButton && rootClicked) )
236 QListView::contentsMousePressEvent(e);
237#else
238 QListView::contentsMousePressEvent(e);
239#endif
229} 240}
230void KOTodoListView::paintEvent(QPaintEvent* e) 241void KOTodoListView::paintEvent(QPaintEvent* e)
231{ 242{
232 emit paintNeeded(); 243 emit paintNeeded();
233 QListView::paintEvent( e); 244 QListView::paintEvent( e);
234} 245}
235void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e) 246void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e)
236{ 247{
237 248
238#ifndef KORG_NODND 249#ifndef KORG_NODND
239 //QListView::contentsMouseMoveEvent(e); 250 //QListView::contentsMouseMoveEvent(e);
240 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() > 251 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() >
241 QApplication::startDragDistance()*3) { 252 QApplication::startDragDistance()*3) {
242 mMousePressed = false; 253 mMousePressed = false;
243 QListViewItem *item = itemAt(contentsToViewport(mPressPos)); 254 QListViewItem *item = itemAt(contentsToViewport(mPressPos));
244 if (item) { 255 if (item) {
245 DndFactory factory( mCalendar ); 256 DndFactory factory( mCalendar );
246 ICalDrag *vd = factory.createDrag( 257 ICalDrag *vd = factory.createDrag(
247 ((KOTodoViewItem *)item)->todo(),viewport()); 258 ((KOTodoViewItem *)item)->todo(),viewport());
248 internalDrop = false; 259 internalDrop = false;
249 // we cannot do any senseful here, because the DnD is still broken in Qt 260 // we cannot do any senseful here, because the DnD is still broken in Qt
250 if (vd->drag()) { 261 if (vd->drag()) {
251 if ( !internalDrop ) { 262 if ( !internalDrop ) {
252 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() ); 263 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() );
253 qDebug("Dnd: External move: Delete drag source "); 264 qDebug("Dnd: External move: Delete drag source ");
254 } else 265 } else
255 qDebug("Dnd: Internal move "); 266 qDebug("Dnd: Internal move ");
256 267
257 } else { 268 } else {
258 if ( !internalDrop ) { 269 if ( !internalDrop ) {
259 qDebug("Dnd: External Copy"); 270 qDebug("Dnd: External Copy");
260 } else 271 } else
261 qDebug("DnD: Internal copy: Copy pending"); 272 qDebug("DnD: Internal copy: Copy pending");
262 } 273 }
263 } 274 }
264 } 275 }
265#endif 276#endif
266} 277}
267void KOTodoListView::keyReleaseEvent ( QKeyEvent *e ) 278void KOTodoListView::keyReleaseEvent ( QKeyEvent *e )
268{ 279{
269 if ( !e->isAutoRepeat() ) { 280 if ( !e->isAutoRepeat() ) {
270 mFlagKeyPressed = false; 281 mFlagKeyPressed = false;
271 } 282 }
272} 283}
273 284
274 285
275void KOTodoListView::keyPressEvent ( QKeyEvent * e ) 286void KOTodoListView::keyPressEvent ( QKeyEvent * e )
276{ 287{
277 qApp->processEvents(); 288 qApp->processEvents();
278 if ( e->isAutoRepeat() && !mFlagKeyPressed ) { 289 if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
279 e->ignore(); 290 e->ignore();
280 // qDebug(" ignore %d",e->isAutoRepeat() ); 291 // qDebug(" ignore %d",e->isAutoRepeat() );
281 return; 292 return;
282 } 293 }
283 if (! e->isAutoRepeat() ) 294 if (! e->isAutoRepeat() )
284 mFlagKeyPressed = true; 295 mFlagKeyPressed = true;
285 QListViewItem* cn; 296 QListViewItem* cn;
286 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) { 297 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) {
287 cn = currentItem(); 298 cn = currentItem();
288 if ( cn ) { 299 if ( cn ) {
289 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 300 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
290 if ( ci ){ 301 if ( ci ){
291 if ( e->state() == ShiftButton ) 302 if ( e->state() == ShiftButton )
292 ci->setOn( false ); 303 ci->setOn( false );
293 else 304 else
294 ci->setOn( true ); 305 ci->setOn( true );
295 cn = cn->itemBelow(); 306 cn = cn->itemBelow();
296 if ( cn ) { 307 if ( cn ) {
297 setCurrentItem ( cn ); 308 setCurrentItem ( cn );
298 ensureItemVisible ( cn ); 309 ensureItemVisible ( cn );
299 } 310 }
300 311
301 } 312 }
302 } 313 }
303 314
304 return; 315 return;
305 } 316 }
306 317
307 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) { 318 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) {
308 switch ( e->key() ) { 319 switch ( e->key() ) {
309 case Qt::Key_Down: 320 case Qt::Key_Down:
310 case Qt::Key_Up: 321 case Qt::Key_Up:
311 QListView::keyPressEvent ( e ); 322 QListView::keyPressEvent ( e );
312 break; 323 break;
313 case Qt::Key_Left: 324 case Qt::Key_Left:
314 case Qt::Key_Right: 325 case Qt::Key_Right:
315 QListView::keyPressEvent ( e ); 326 QListView::keyPressEvent ( e );
316 e->accept(); 327 e->accept();
317 return; 328 return;
318 break; 329 break;
319 default: 330 default:
320 e->ignore(); 331 e->ignore();
321 break; 332 break;
322 } 333 }
323 return; 334 return;
324 } 335 }
325 e->ignore(); 336 e->ignore();
326} 337}
327void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e) 338void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e)
328{ 339{
329 QListView::contentsMouseReleaseEvent(e); 340 QListView::contentsMouseReleaseEvent(e);
330 mMousePressed = false; 341 mMousePressed = false;
331} 342}
332 343
333void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e) 344void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e)
334{ 345{
335 if (!e) return; 346 if (!e) return;
336 347
337 QPoint vp = contentsToViewport(e->pos()); 348 QPoint vp = contentsToViewport(e->pos());
338 349
339 QListViewItem *item = itemAt(vp); 350 QListViewItem *item = itemAt(vp);
340 351
341 emit double_Clicked(item); 352 emit double_Clicked(item);
342 if (!item) return; 353 if (!item) return;
343 354
344 emit doubleClicked(item,vp,0); 355 emit doubleClicked(item,vp,0);
345} 356}
346 357
347///////////////////////////////////////////////////////////////////////////// 358/////////////////////////////////////////////////////////////////////////////
348 359
349KOQuickTodo::KOQuickTodo(QWidget *parent) : 360KOQuickTodo::KOQuickTodo(QWidget *parent) :
350 QLineEdit(parent) 361 QLineEdit(parent)
351{ 362{
352 setText(i18n("Click to add a new Todo")); 363 setText(i18n("Click to add a new Todo"));
353} 364}
354 365
355void KOQuickTodo::focusInEvent(QFocusEvent *ev) 366void KOQuickTodo::focusInEvent(QFocusEvent *ev)
356{ 367{
357 if ( text()==i18n("Click to add a new Todo") ) 368 if ( text()==i18n("Click to add a new Todo") )
358 setText(""); 369 setText("");
359 QLineEdit::focusInEvent(ev); 370 QLineEdit::focusInEvent(ev);
360} 371}
361 372
362void KOQuickTodo::focusOutEvent(QFocusEvent *ev) 373void KOQuickTodo::focusOutEvent(QFocusEvent *ev)
363{ 374{
364 setText(i18n("Click to add a new Todo")); 375 setText(i18n("Click to add a new Todo"));
365 QLineEdit::focusOutEvent(ev); 376 QLineEdit::focusOutEvent(ev);
366} 377}
367 378
368///////////////////////////////////////////////////////////////////////////// 379/////////////////////////////////////////////////////////////////////////////
369 380
370KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) : 381KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) :
371 KOrg::BaseView(calendar,parent,name) 382 KOrg::BaseView(calendar,parent,name)
372{ 383{
373 mPendingUpdateBeforeRepaint = false; 384 mPendingUpdateBeforeRepaint = false;
374 isFlatDisplay = false; 385 isFlatDisplay = false;
375 mNavigator = 0; 386 mNavigator = 0;
376 QBoxLayout *topLayout = new QVBoxLayout(this); 387 QBoxLayout *topLayout = new QVBoxLayout(this);
377 mName = QString ( name ); 388 mName = QString ( name );
378 mBlockUpdate = false; 389 mBlockUpdate = false;
379 mQuickAdd = new KOQuickTodo(this); 390 mQuickAdd = new KOQuickTodo(this);
380 topLayout->addWidget(mQuickAdd); 391 topLayout->addWidget(mQuickAdd);
381 392
382 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide(); 393 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide();
383 394
384 mTodoListView = new KOTodoListView(calendar,this, name ); 395 mTodoListView = new KOTodoListView(calendar,this, name );
385 topLayout->addWidget(mTodoListView); 396 topLayout->addWidget(mTodoListView);
386 //mTodoListView->header()->setMaximumHeight(30); 397 //mTodoListView->header()->setMaximumHeight(30);
387 mTodoListView->setRootIsDecorated(true); 398 mTodoListView->setRootIsDecorated(true);
388 mTodoListView->setAllColumnsShowFocus(true); 399 mTodoListView->setAllColumnsShowFocus(true);
389 400
390 mTodoListView->setShowSortIndicator(true); 401 mTodoListView->setShowSortIndicator(true);
391 402
392 mTodoListView->addColumn(i18n("Todo")); 403 mTodoListView->addColumn(i18n("Todo"));
393 mTodoListView->addColumn(i18n("Prio")); 404 mTodoListView->addColumn(i18n("Prio"));
394 mTodoListView->setColumnAlignment(1,AlignHCenter); 405 mTodoListView->setColumnAlignment(1,AlignHCenter);
395 mTodoListView->addColumn(i18n("Complete")); 406 mTodoListView->addColumn(i18n("Complete"));
396 mTodoListView->setColumnAlignment(2,AlignCenter); 407 mTodoListView->setColumnAlignment(2,AlignCenter);
397 408
398 mTodoListView->addColumn(i18n("Due Date")); 409 mTodoListView->addColumn(i18n("Due Date"));
399 mTodoListView->setColumnAlignment(3,AlignLeft); 410 mTodoListView->setColumnAlignment(3,AlignLeft);
400 mTodoListView->addColumn(i18n("Due Time")); 411 mTodoListView->addColumn(i18n("Due Time"));
401 mTodoListView->setColumnAlignment(4,AlignHCenter); 412 mTodoListView->setColumnAlignment(4,AlignHCenter);
402 413
403 mTodoListView->addColumn(i18n("Start Date")); 414 mTodoListView->addColumn(i18n("Start Date"));
404 mTodoListView->setColumnAlignment(5,AlignLeft); 415 mTodoListView->setColumnAlignment(5,AlignLeft);
405 mTodoListView->addColumn(i18n("Start Time")); 416 mTodoListView->addColumn(i18n("Start Time"));
406 mTodoListView->setColumnAlignment(6,AlignHCenter); 417 mTodoListView->setColumnAlignment(6,AlignHCenter);
407 418
408 mTodoListView->addColumn(i18n("Cancelled")); 419 mTodoListView->addColumn(i18n("Cancelled"));
409 mTodoListView->addColumn(i18n("Categories")); 420 mTodoListView->addColumn(i18n("Categories"));
410#if 0 421#if 0
411 mTodoListView->addColumn(i18n("Sort Id")); 422 mTodoListView->addColumn(i18n("Sort Id"));
412 mTodoListView->setColumnAlignment(4,AlignHCenter); 423 mTodoListView->setColumnAlignment(4,AlignHCenter);
413#endif 424#endif
414 425
415 mTodoListView->setMinimumHeight( 60 ); 426 mTodoListView->setMinimumHeight( 60 );
416 mTodoListView->setItemsRenameable( true ); 427 mTodoListView->setItemsRenameable( true );
417 mTodoListView->setRenameable( 0 ); 428 mTodoListView->setRenameable( 0 );
418 mTodoListView->setColumnWidth( 0, 120 ); 429 mTodoListView->setColumnWidth( 0, 120 );
419 mTodoListView->setColumnWidthMode(0, QListView::Manual); 430 mTodoListView->setColumnWidthMode(0, QListView::Manual);
420 mTodoListView->setColumnWidthMode(1, QListView::Manual); 431 mTodoListView->setColumnWidthMode(1, QListView::Manual);
421 mTodoListView->setColumnWidthMode(2, QListView::Manual); 432 mTodoListView->setColumnWidthMode(2, QListView::Manual);
422 mTodoListView->setColumnWidthMode(3, QListView::Manual); 433 mTodoListView->setColumnWidthMode(3, QListView::Manual);
423 mTodoListView->setColumnWidthMode(4, QListView::Manual); 434 mTodoListView->setColumnWidthMode(4, QListView::Manual);
424 mTodoListView->setColumnWidthMode(5, QListView::Manual); 435 mTodoListView->setColumnWidthMode(5, QListView::Manual);
425 mTodoListView->setColumnWidthMode(6, QListView::Manual); 436 mTodoListView->setColumnWidthMode(6, QListView::Manual);
426 mTodoListView->setColumnWidthMode(7, QListView::Manual); 437 mTodoListView->setColumnWidthMode(7, QListView::Manual);
427 mTodoListView->setColumnWidthMode(8, QListView::Manual); 438 mTodoListView->setColumnWidthMode(8, QListView::Manual);
428 439
429 440
430 mKOTodoViewWhatsThis = new KOTodoViewWhatsThis(mTodoListView->viewport(),this); 441 mKOTodoViewWhatsThis = new KOTodoViewWhatsThis(mTodoListView->viewport(),this);
431 442
432 mPriorityPopupMenu = new QPopupMenu(this); 443 mPriorityPopupMenu = new QPopupMenu(this);
433 for (int i = 1; i <= 5; i++) { 444 for (int i = 1; i <= 5; i++) {
434 QString label = QString ("%1").arg (i); 445 QString label = QString ("%1").arg (i);
435 mPriority[mPriorityPopupMenu->insertItem (label)] = i; 446 mPriority[mPriorityPopupMenu->insertItem (label)] = i;
436 } 447 }
437 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int))); 448 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int)));
438 449
439 mPercentageCompletedPopupMenu = new QPopupMenu(this); 450 mPercentageCompletedPopupMenu = new QPopupMenu(this);
440 for (int i = 0; i <= 100; i+=20) { 451 for (int i = 0; i <= 100; i+=20) {
441 QString label = QString ("%1 %").arg (i); 452 QString label = QString ("%1 %").arg (i);
442 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i; 453 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i;
443 } 454 }
444 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int))); 455 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int)));
445 456
446 457
447 458
448 mItemPopupMenu = new QPopupMenu(this); 459 mItemPopupMenu = new QPopupMenu(this);
449 mItemPopupMenu->insertItem(i18n("Show..."), this, 460 mItemPopupMenu->insertItem(i18n("Show..."), this,
450 SLOT (showTodo())); 461 SLOT (showTodo()));
451 mItemPopupMenu->insertItem(i18n("Edit..."), this, 462 mItemPopupMenu->insertItem(i18n("Edit..."), this,
452 SLOT (editTodo())); 463 SLOT (editTodo()));
453 mItemPopupMenu->insertItem( i18n("Delete"), this, 464 mItemPopupMenu->insertItem( i18n("Delete"), this,
454 SLOT (deleteTodo())); 465 SLOT (deleteTodo()));
455 mItemPopupMenu->insertItem( i18n("Clone..."), this, 466 mItemPopupMenu->insertItem( i18n("Clone..."), this,
456 SLOT (cloneTodo())); 467 SLOT (cloneTodo()));
457 mItemPopupMenu->insertItem( i18n("Move..."), this, 468 mItemPopupMenu->insertItem( i18n("Move..."), this,
458 SLOT (moveTodo())); 469 SLOT (moveTodo()));
459 mItemPopupMenu->insertItem( i18n("Beam..."), this, 470 mItemPopupMenu->insertItem( i18n("Beam..."), this,
460 SLOT (beamTodo())); 471 SLOT (beamTodo()));
461 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this, 472 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this,
462 SLOT (cancelTodo())); 473 SLOT (cancelTodo()));
463 mItemPopupMenu->insertSeparator(); 474 mItemPopupMenu->insertSeparator();
464 475
465 mItemPopupMenu->insertItem( i18n("New Todo..."), this, 476 mItemPopupMenu->insertItem( i18n("New Todo..."), this,
466 SLOT (newTodo())); 477 SLOT (newTodo()));
467 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this, 478 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this,
468 SLOT (newSubTodo())); 479 SLOT (newSubTodo()));
469 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this, 480 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this,
470 SLOT (unparentTodo()),0,21); 481 SLOT (unparentTodo()),0,21);
471 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this, 482 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this,
472 SLOT (reparentTodo()),0,22); 483 SLOT (reparentTodo()),0,22);
473 mItemPopupMenu->insertSeparator(); 484 mItemPopupMenu->insertSeparator();
474#if 0 485#if 0
475 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"), 486 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"),
476 this, SLOT( purgeCompleted() ) ); 487 this, SLOT( purgeCompleted() ) );
477 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"), 488 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"),
478 this, SLOT( toggleCompleted() ),0, 33 ); 489 this, SLOT( toggleCompleted() ),0, 33 );
479 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 490 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
480 this, SLOT( toggleQuickTodo() ),0, 34 ); 491 this, SLOT( toggleQuickTodo() ),0, 34 );
481 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 492 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
482 this, SLOT( toggleRunning() ),0, 35 ); 493 this, SLOT( toggleRunning() ),0, 35 );
483 494
484#endif 495#endif
485 mPopupMenu = new QPopupMenu(this); 496 mPopupMenu = new QPopupMenu(this);
486 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this, 497 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this,
487 SLOT (newTodo()),0,1); 498 SLOT (newTodo()),0,1);
488 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"), 499 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"),
489 this, SLOT(purgeCompleted()),0,2); 500 this, SLOT(purgeCompleted()),0,2);
490 mPopupMenu->insertItem(i18n("Show Completed"), 501 mPopupMenu->insertItem(i18n("Show Completed"),
491 this, SLOT( toggleCompleted() ),0,3 ); 502 this, SLOT( toggleCompleted() ),0,3 );
492 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 503 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
493 this, SLOT( toggleQuickTodo() ),0,4 ); 504 this, SLOT( toggleQuickTodo() ),0,4 );
494 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 505 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
495 this, SLOT( toggleRunning() ),0,5 ); 506 this, SLOT( toggleRunning() ),0,5 );
496 mPopupMenu->insertItem(i18n(" set all open","Display all opened"), 507 mPopupMenu->insertItem(i18n(" set all open","Display all opened"),
497 this, SLOT( setAllOpen() ),0,6 ); 508 this, SLOT( setAllOpen() ),0,6 );
498 mPopupMenu->insertItem(i18n(" set all close","Display all closed"), 509 mPopupMenu->insertItem(i18n(" set all close","Display all closed"),
499 this, SLOT( setAllClose() ),0,7 ); 510 this, SLOT( setAllClose() ),0,7 );
500 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"), 511 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"),
501 this, SLOT( setAllFlat() ),0,8 ); 512 this, SLOT( setAllFlat() ),0,8 );
502 mDocPrefs = new DocPrefs( name ); 513 mDocPrefs = new DocPrefs( name );
503 514
504 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu ); 515 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu );
505 mPopupMenu->setCheckable( true ); 516 mPopupMenu->setCheckable( true );
506 mItemPopupMenu->setCheckable( true ); 517 mItemPopupMenu->setCheckable( true );
507 518
508 519
509 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 520 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
510 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 521 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
511 522
512 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 523 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
513 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 524 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
514 525
515 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 526 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
516 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 527 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
517 528
518 529
519 // Double clicking conflicts with opening/closing the subtree 530 // Double clicking conflicts with opening/closing the subtree
520 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ), 531 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ),
521 SLOT( editItem( QListViewItem *) ) ); 532 SLOT( editItem( QListViewItem *) ) );
522 /* 533 /*
523 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *, 534 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *,
524 const QPoint &,int ) ), 535 const QPoint &,int ) ),
525 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 536 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
526 */ 537 */
527 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *, 538 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *,
528 const QPoint &,int ) ), 539 const QPoint &,int ) ),
529 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 540 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
530 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ), 541 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ),
531 SLOT( itemClicked( QListViewItem * ) ) ); 542 SLOT( itemClicked( QListViewItem * ) ) );
532 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ), 543 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ),
533 SLOT( itemDoubleClicked( QListViewItem * ) ) ); 544 SLOT( itemDoubleClicked( QListViewItem * ) ) );
534 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 545 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
535 SLOT( updateView() ) ); 546 SLOT( updateView() ) );
536 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 547 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
537 SLOT( todoModified(Todo *, int) ) ); 548 SLOT( todoModified(Todo *, int) ) );
538 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ), 549 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ),
539 SLOT( itemStateChanged( QListViewItem * ) ) ); 550 SLOT( itemStateChanged( QListViewItem * ) ) );
540 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ), 551 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ),
541 SLOT( itemStateChanged( QListViewItem * ) ) ); 552 SLOT( itemStateChanged( QListViewItem * ) ) );
542 connect( mTodoListView, SIGNAL( paintNeeded() ), 553 connect( mTodoListView, SIGNAL( paintNeeded() ),
543 SLOT( paintNeeded()) ); 554 SLOT( paintNeeded()) );
544 555
545#if 0 556#if 0
546 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)), 557 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)),
547 SLOT(selectionChanged(QListViewItem *))); 558 SLOT(selectionChanged(QListViewItem *)));
548 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)), 559 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)),
549 SLOT(selectionChanged(QListViewItem *))); 560 SLOT(selectionChanged(QListViewItem *)));
550 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)), 561 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)),
551 SLOT(selectionChanged(QListViewItem *))); 562 SLOT(selectionChanged(QListViewItem *)));
552#endif 563#endif
553 564
554 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) )); 565 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) ));
555 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) )); 566 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) ));
556 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) )); 567 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) ));
557 568
558 connect( mTodoListView, SIGNAL(selectionChanged() ), 569 connect( mTodoListView, SIGNAL(selectionChanged() ),
559 SLOT( processSelectionChange() ) ); 570 SLOT( processSelectionChange() ) );
560 connect( mQuickAdd, SIGNAL( returnPressed () ), 571 connect( mQuickAdd, SIGNAL( returnPressed () ),
561 SLOT( addQuickTodo() ) ); 572 SLOT( addQuickTodo() ) );
562 573
563} 574}
564 575
565KOTodoView::~KOTodoView() 576KOTodoView::~KOTodoView()
566{ 577{
567 // delete mKOTodoViewWhatsThis; 578 // delete mKOTodoViewWhatsThis;
568 delete mDocPrefs; 579 delete mDocPrefs;
569} 580}
570QString KOTodoView::getWhatsThisText(QPoint p) 581QString KOTodoView::getWhatsThisText(QPoint p)
571{ 582{
572 KOTodoViewItem* item = ( KOTodoViewItem* ) mTodoListView->itemAt( p ); 583 KOTodoViewItem* item = ( KOTodoViewItem* ) mTodoListView->itemAt( p );
573 if ( item ) 584 if ( item )
574 return KIncidenceFormatter::instance()->getFormattedText( item->todo(), 585 return KIncidenceFormatter::instance()->getFormattedText( item->todo(),
575 KOPrefs::instance()->mWTshowDetails, 586 KOPrefs::instance()->mWTshowDetails,
576 KOPrefs::instance()->mWTshowCreated, 587 KOPrefs::instance()->mWTshowCreated,
577 KOPrefs::instance()->mWTshowChanged); 588 KOPrefs::instance()->mWTshowChanged);
578 return i18n("That is the todo view" ); 589 return i18n("That is the todo view" );
579 590
580} 591}
581 592
582void KOTodoView::jumpToDate () 593void KOTodoView::jumpToDate ()
583{ 594{
584 // if (mActiveItem) { 595 // if (mActiveItem) {
585// mActiveItem->todo()); 596// mActiveItem->todo());
586// if ( mActiveItem->todo()->hasDueDate() ) 597// if ( mActiveItem->todo()->hasDueDate() )
587// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() ); 598// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() );
588} 599}
589void KOTodoView::paintNeeded() 600void KOTodoView::paintNeeded()
590{ 601{
591 if ( mPendingUpdateBeforeRepaint ) { 602 if ( mPendingUpdateBeforeRepaint ) {
592 updateView(); 603 updateView();
593 mPendingUpdateBeforeRepaint = false; 604 mPendingUpdateBeforeRepaint = false;
594 } 605 }
595} 606}
596void KOTodoView::paintEvent(QPaintEvent * pevent) 607void KOTodoView::paintEvent(QPaintEvent * pevent)
597{ 608{
598 if ( mPendingUpdateBeforeRepaint ) { 609 if ( mPendingUpdateBeforeRepaint ) {
599 updateView(); 610 updateView();
600 mPendingUpdateBeforeRepaint = false; 611 mPendingUpdateBeforeRepaint = false;
601 } 612 }
602 KOrg::BaseView::paintEvent( pevent); 613 KOrg::BaseView::paintEvent( pevent);
603} 614}
604 615
605void KOTodoView::updateView() 616void KOTodoView::updateView()
606{ 617{
607 pendingSubtodo = 0; 618 pendingSubtodo = 0;
608 if ( mBlockUpdate ) { 619 if ( mBlockUpdate ) {
609 return; 620 return;
610 } 621 }
611 if ( !isVisible() ) { 622 if ( !isVisible() ) {
612 mPendingUpdateBeforeRepaint = true; 623 mPendingUpdateBeforeRepaint = true;
613 return; 624 return;
614 } 625 }
615 storeCurrentItem(); 626 storeCurrentItem();
616 //qDebug("KOTodoView::updateView() %x", this); 627 //qDebug("KOTodoView::updateView() %x", this);
617 if ( isFlatDisplay ) { 628 if ( isFlatDisplay ) {
618 displayAllFlat(); 629 displayAllFlat();
619 resetCurrentItem(); 630 resetCurrentItem();
620 return; 631 return;
621 } 632 }
622 //qDebug("update "); 633 //qDebug("update ");
623// kdDebug() << "KOTodoView::updateView()" << endl; 634// kdDebug() << "KOTodoView::updateView()" << endl;
624 QFont fo = KOPrefs::instance()->mTodoViewFont; 635 QFont fo = KOPrefs::instance()->mTodoViewFont;
625 636
626 637
627 mTodoListView->clear(); 638 mTodoListView->clear();
628 if ( mName == "todolistsmall" ) { 639 if ( mName == "todolistsmall" ) {
629 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) { 640 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) {
630 int ps = fo.pointSize() -2; 641 int ps = fo.pointSize() -2;
631 if ( ps > 12 ) 642 if ( ps > 12 )
632 ps -= 2; 643 ps -= 2;
633 fo.setPointSize( ps ); 644 fo.setPointSize( ps );
634 } 645 }
635 } 646 }
636 647
637 mTodoListView->setFont( fo ); 648 mTodoListView->setFont( fo );
638 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont ); 649 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont );
639 //mTodoListView->header()->setMaximumHeight(fm.height()); 650 //mTodoListView->header()->setMaximumHeight(fm.height());
640 QPtrList<Todo> todoList = calendar()->todos(); 651 QPtrList<Todo> todoList = calendar()->todos();
641 652
642/* 653/*
643 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl; 654 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl;
644 Event *t; 655 Event *t;
645 for(t = todoList.first(); t; t = todoList.next()) { 656 for(t = todoList.first(); t; t = todoList.next()) {
646 kdDebug() << " " << t->getSummary() << endl; 657 kdDebug() << " " << t->getSummary() << endl;
647 658
648 if (t->getRelatedTo()) { 659 if (t->getRelatedTo()) {
649 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl; 660 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl;
650 } 661 }
651 662
652 QPtrList<Event> l = t->getRelations(); 663 QPtrList<Event> l = t->getRelations();
653 Event *c; 664 Event *c;
654 for(c=l.first();c;c=l.next()) { 665 for(c=l.first();c;c=l.next()) {
655 kdDebug() << " - relation: " << c->getSummary() << endl; 666 kdDebug() << " - relation: " << c->getSummary() << endl;
656 } 667 }
657 } 668 }
658*/ 669*/
659 670
660 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a 671 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a
661 // specific order of events. That means that we have to generate parent items 672 // specific order of events. That means that we have to generate parent items
662 // recursively for proper hierarchical display of Todos. 673 // recursively for proper hierarchical display of Todos.
663 mTodoMap.clear(); 674 mTodoMap.clear();
664 Todo *todo; 675 Todo *todo;
665 todo = todoList.first();// todo; todo = todoList.next()) { 676 todo = todoList.first();// todo; todo = todoList.next()) {
666 while ( todo ) { 677 while ( todo ) {
667 bool next = true; 678 bool next = true;
668 // qDebug("todo %s ", todo->summary().latin1()); 679 // qDebug("todo %s ", todo->summary().latin1());
669 Incidence *incidence = todo->relatedTo(); 680 Incidence *incidence = todo->relatedTo();
670 while ( incidence ) { 681 while ( incidence ) {
671 if ( incidence->type() == "Todo") { 682 if ( incidence->type() == "Todo") {
672 //qDebug("related %s ",incidence->summary().latin1() ); 683 //qDebug("related %s ",incidence->summary().latin1() );
673 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) { 684 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) {
674 //qDebug("related not found "); 685 //qDebug("related not found ");
675 todoList.remove( ); 686 todoList.remove( );
676 todo = todoList.current(); 687 todo = todoList.current();
677 next = false; 688 next = false;
678 incidence = 0; 689 incidence = 0;
679 690
680 } else { 691 } else {
681 //qDebug("related found "); 692 //qDebug("related found ");
682 incidence = incidence->relatedTo(); 693 incidence = incidence->relatedTo();
683 } 694 }
684 } else 695 } else
685 incidence = 0; 696 incidence = 0;
686 } 697 }
687 if ( next ) 698 if ( next )
688 todo = todoList.next(); 699 todo = todoList.next();
689 } 700 }
690// qDebug("again .... "); 701// qDebug("again .... ");
691// for(todo = todoList.first(); todo; todo = todoList.next()) { 702// for(todo = todoList.first(); todo; todo = todoList.next()) {
692 703
693// qDebug("yytodo %s ", todo->summary().latin1()); 704// qDebug("yytodo %s ", todo->summary().latin1());
694// } 705// }
695 //qDebug("for "); 706 //qDebug("for ");
696 for(todo = todoList.first(); todo; todo = todoList.next()) { 707 for(todo = todoList.first(); todo; todo = todoList.next()) {
697 if (!mTodoMap.contains(todo) && checkTodo( todo ) ) 708 if (!mTodoMap.contains(todo) && checkTodo( todo ) )
698 { 709 {
699 insertTodoItem(todo); 710 insertTodoItem(todo);
700 } 711 }
701 } 712 }
702 //qDebug("for end "); 713 //qDebug("for end ");
703 // Restore opened/closed state 714 // Restore opened/closed state
704 mTodoListView->blockSignals( true ); 715 mTodoListView->blockSignals( true );
705 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() ); 716 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() );
706 mTodoListView->blockSignals( false ); 717 mTodoListView->blockSignals( false );
707 resetCurrentItem(); 718 resetCurrentItem();
708 processSelectionChange(); 719 processSelectionChange();
709} 720}
710 721
711void KOTodoView::storeCurrentItem() 722void KOTodoView::storeCurrentItem()
712{ 723{
713 mCurItem = 0; 724 mCurItem = 0;
714 mCurItemRootParent = 0; 725 mCurItemRootParent = 0;
715 mCurItemAbove = 0; 726 mCurItemAbove = 0;
716 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 727 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
717 if (mActiveItem) { 728 if (mActiveItem) {
718 mCurItem = mActiveItem->todo(); 729 mCurItem = mActiveItem->todo();
719 KOTodoViewItem* activeItemAbove = (KOTodoViewItem*)mActiveItem->itemAbove (); 730 KOTodoViewItem* activeItemAbove = (KOTodoViewItem*)mActiveItem->itemAbove ();
720 if ( activeItemAbove ) 731 if ( activeItemAbove )
721 mCurItemAbove = activeItemAbove->todo(); 732 mCurItemAbove = activeItemAbove->todo();
722 while ( mActiveItem->parent() != 0 ) 733 while ( mActiveItem->parent() != 0 )
723 mActiveItem = (KOTodoViewItem*)mActiveItem->parent(); 734 mActiveItem = (KOTodoViewItem*)mActiveItem->parent();
724 mCurItemRootParent = mActiveItem->todo(); 735 mCurItemRootParent = mActiveItem->todo();
725 } 736 }
726 mActiveItem = 0; 737 mActiveItem = 0;
727} 738}
728 739
729void KOTodoView::resetCurrentItem() 740void KOTodoView::resetCurrentItem()
730{ 741{
731 mTodoListView->setFocus(); 742 mTodoListView->setFocus();
732 KOTodoViewItem* foundItem = 0; 743 KOTodoViewItem* foundItem = 0;
733 KOTodoViewItem* foundItemRoot = 0; 744 KOTodoViewItem* foundItemRoot = 0;
734 KOTodoViewItem* foundItemAbove = 0; 745 KOTodoViewItem* foundItemAbove = 0;
735 if ( mTodoListView->firstChild () ) { 746 if ( mTodoListView->firstChild () ) {
736 if ( mCurItem ) { 747 if ( mCurItem ) {
737 KOTodoViewItem* item = (KOTodoViewItem*)mTodoListView->firstChild (); 748 KOTodoViewItem* item = (KOTodoViewItem*)mTodoListView->firstChild ();
738 while ( item ) { 749 while ( item ) {
739 if ( item->todo() == mCurItem ) { 750 if ( item->todo() == mCurItem ) {
740 foundItem = item; 751 foundItem = item;
741 break; 752 break;
742 } else if ( item->todo() == mCurItemAbove ) { 753 } else if ( item->todo() == mCurItemAbove ) {
743 foundItemAbove = item; 754 foundItemAbove = item;
744 755
745 } else if ( item->todo() == mCurItemRootParent ) { 756 } else if ( item->todo() == mCurItemRootParent ) {
746 foundItemRoot = item; 757 foundItemRoot = item;
747 } 758 }
748 item = (KOTodoViewItem*)item->itemBelow(); 759 item = (KOTodoViewItem*)item->itemBelow();
749 } 760 }
750 if ( ! foundItem ) { 761 if ( ! foundItem ) {
751 if ( foundItemAbove ) 762 if ( foundItemAbove )
752 foundItem = foundItemAbove; 763 foundItem = foundItemAbove;
753 else 764 else
754 foundItem = foundItemRoot; 765 foundItem = foundItemRoot;
755 } 766 }
756 } 767 }
757 if ( foundItem ) { 768 if ( foundItem ) {
758 mTodoListView->setCurrentItem( foundItem ); 769 mTodoListView->setCurrentItem( foundItem );
759 mTodoListView->ensureItemVisible( foundItem ); 770 mTodoListView->ensureItemVisible( foundItem );
760 } else { 771 } else {
761 mTodoListView->setCurrentItem( mTodoListView->firstChild () ); 772 mTodoListView->setCurrentItem( mTodoListView->firstChild () );
762 } 773 }
763 } 774 }
764 mTodoListView->setFocus(); 775 mTodoListView->setFocus();
765} 776}
766//Incidence * mCurItem, *mCurItemRootParent,*mCurItemAbove; 777//Incidence * mCurItem, *mCurItemRootParent,*mCurItemAbove;
767bool KOTodoView::checkTodo( Todo * todo ) 778bool KOTodoView::checkTodo( Todo * todo )
768{ 779{
769 780
770 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() ) 781 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() )
771 return false; 782 return false;
772 if ( !todo->isCompleted() ) { 783 if ( !todo->isCompleted() ) {
773 if ( todo->hasDueDate() && todo->dtDue().date() <= QDate::currentDate() ) 784 if ( todo->hasDueDate() && todo->dtDue().date() <= QDate::currentDate() )
774 return true; 785 return true;
775 } 786 }
776 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) { 787 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) {
777 if ( todo->hasStartDate() ) 788 if ( todo->hasStartDate() )
778 if ( mNavigator->selectedDates().last() < todo->dtStart().date() ) 789 if ( mNavigator->selectedDates().last() < todo->dtStart().date() )
779 return false; 790 return false;
780 if ( todo->hasDueDate() ) 791 if ( todo->hasDueDate() )
781 if ( mNavigator->selectedDates().first() > todo->dtDue().date() ) 792 if ( mNavigator->selectedDates().first() > todo->dtDue().date() )
782 return false; 793 return false;
783 } 794 }
784 return true; 795 return true;
785} 796}
786 797
787void KOTodoView::restoreItemState( QListViewItem *item ) 798void KOTodoView::restoreItemState( QListViewItem *item )
788{ 799{
789 pendingSubtodo = 0; 800 pendingSubtodo = 0;
790 while( item ) { 801 while( item ) {
791 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 802 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
792 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) ); 803 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) );
793 if( item->childCount() > 0 ) restoreItemState( item->firstChild() ); 804 if( item->childCount() > 0 ) restoreItemState( item->firstChild() );
794 item = item->nextSibling(); 805 item = item->nextSibling();
795 } 806 }
796} 807}
797 808
798 809
799QMap<Todo *,KOTodoViewItem *>::ConstIterator 810QMap<Todo *,KOTodoViewItem *>::ConstIterator
800 KOTodoView::insertTodoItem(Todo *todo) 811 KOTodoView::insertTodoItem(Todo *todo)
801{ 812{
802 813
803// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl; 814// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl;
804 // TODO: Check, if dynmaic cast is necessary 815 // TODO: Check, if dynmaic cast is necessary
805 816
806 pendingSubtodo = 0; 817 pendingSubtodo = 0;
807 Incidence *incidence = todo->relatedTo(); 818 Incidence *incidence = todo->relatedTo();
808 if (incidence && incidence->type() == "Todo") { 819 if (incidence && incidence->type() == "Todo") {
809 Todo *relatedTodo = static_cast<Todo *>(incidence); 820 Todo *relatedTodo = static_cast<Todo *>(incidence);
810 821
811// kdDebug() << " has Related" << endl; 822// kdDebug() << " has Related" << endl;
812 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 823 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
813 itemIterator = mTodoMap.find(relatedTodo); 824 itemIterator = mTodoMap.find(relatedTodo);
814 if (itemIterator == mTodoMap.end()) { 825 if (itemIterator == mTodoMap.end()) {
815// kdDebug() << " related not yet in list" << endl; 826// kdDebug() << " related not yet in list" << endl;
816 itemIterator = insertTodoItem (relatedTodo); 827 itemIterator = insertTodoItem (relatedTodo);
817 } 828 }
818 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem 829 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem
819 // and one into the map. Sure finding is more easy but why? -zecke 830 // and one into the map. Sure finding is more easy but why? -zecke
820 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this); 831 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this);
821 return mTodoMap.insert(todo,todoItem); 832 return mTodoMap.insert(todo,todoItem);
822 } else { 833 } else {
823// kdDebug() << " no Related" << endl; 834// kdDebug() << " no Related" << endl;
824 // see above -zecke 835 // see above -zecke
825 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 836 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
826 return mTodoMap.insert(todo,todoItem); 837 return mTodoMap.insert(todo,todoItem);
827 } 838 }
828} 839}
829 840
830 841
831void KOTodoView::updateConfig() 842void KOTodoView::updateConfig()
832{ 843{
833 updateView(); 844 updateView();
834 mTodoListView->repaintContents(); 845 mTodoListView->repaintContents();
835} 846}
836 847
837QPtrList<Incidence> KOTodoView::selectedIncidences() 848QPtrList<Incidence> KOTodoView::selectedIncidences()
838{ 849{
839 QPtrList<Incidence> selected; 850 QPtrList<Incidence> selected;
840 851
841 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 852 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
842// if (!item) item = mActiveItem; 853// if (!item) item = mActiveItem;
843 if (item) selected.append(item->todo()); 854 if (item) selected.append(item->todo());
844 855
845 return selected; 856 return selected;
846} 857}
847 858
848QPtrList<Todo> KOTodoView::selectedTodos() 859QPtrList<Todo> KOTodoView::selectedTodos()
849{ 860{
850 QPtrList<Todo> selected; 861 QPtrList<Todo> selected;
851 862
852 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 863 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
853// if (!item) item = mActiveItem; 864// if (!item) item = mActiveItem;
854 if (item) selected.append(item->todo()); 865 if (item) selected.append(item->todo());
855 866
856 return selected; 867 return selected;
857} 868}
858 869
859void KOTodoView::changeEventDisplay(Event *, int) 870void KOTodoView::changeEventDisplay(Event *, int)
860{ 871{
861 updateView(); 872 updateView();
862} 873}
863 874
864void KOTodoView::showDates(const QDate &, const QDate &) 875void KOTodoView::showDates(const QDate &, const QDate &)
865{ 876{
866} 877}
867 878
868void KOTodoView::showEvents(QPtrList<Event>) 879void KOTodoView::showEvents(QPtrList<Event>)
869{ 880{
870 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl; 881 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl;
871} 882}
872 883
873void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd, 884void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd,
874 const QDate &td) 885 const QDate &td)
875{ 886{
876#ifndef KORG_NOPRINTER 887#ifndef KORG_NOPRINTER
877 calPrinter->preview(CalPrinter::Todolist, fd, td); 888 calPrinter->preview(CalPrinter::Todolist, fd, td);
878#endif 889#endif
879} 890}
880 891
881void KOTodoView::editItem(QListViewItem *item ) 892void KOTodoView::editItem(QListViewItem *item )
882{ 893{
883 // qDebug("editItem(QListViewItem *item ) "); 894 // qDebug("editItem(QListViewItem *item ) ");
884 emit editTodoSignal(((KOTodoViewItem *)item)->todo()); 895 emit editTodoSignal(((KOTodoViewItem *)item)->todo());
885} 896}
886 897
887void KOTodoView::showItem(QListViewItem *item,const QPoint &,int) 898void KOTodoView::showItem(QListViewItem *item,const QPoint &,int)
888{ 899{
889 emit showTodoSignal(((KOTodoViewItem *)item)->todo()); 900 emit showTodoSignal(((KOTodoViewItem *)item)->todo());
890} 901}
891 902
892void KOTodoView::popupMenu(QListViewItem *item,const QPoint &p,int column) 903void KOTodoView::popupMenu(QListViewItem *item,const QPoint &p,int column)
893{ 904{
894 pendingSubtodo = 0; 905 pendingSubtodo = 0;
895 mActiveItem = (KOTodoViewItem *)item; 906 mActiveItem = (KOTodoViewItem *)item;
896 if (item) { 907 if (item) {
897 switch (column){ 908 switch (column){
898 case 1: 909 case 1:
899 mPriorityPopupMenu->popup(QCursor::pos ()); break; 910 mPriorityPopupMenu->popup(QCursor::pos ()); break;
900 case 2: 911 case 2:
901 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break; 912 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break;
902 case 3: 913 case 3:
903 moveTodo(); 914 moveTodo();
904 break; 915 break;
905 case 8: 916 case 8:
906 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break; 917 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break;
907 default: 918 default:
908 mItemPopupMenu->popup(QCursor::pos()); 919 mItemPopupMenu->popup(QCursor::pos());
909 } 920 }
910 } else mPopupMenu->popup(QCursor::pos()); 921 } else mPopupMenu->popup(QCursor::pos());
911} 922}
912void KOTodoView::newTodo() 923void KOTodoView::newTodo()
913{ 924{
914 emit newTodoSignal(); 925 emit newTodoSignal();
915} 926}
916 927
917void KOTodoView::newSubTodo() 928void KOTodoView::newSubTodo()
918{ 929{
919 if (mActiveItem) { 930 if (mActiveItem) {
920 emit newSubTodoSignal(mActiveItem->todo()); 931 emit newSubTodoSignal(mActiveItem->todo());
921 } 932 }
922} 933}
923void KOTodoView::unparentTodo() 934void KOTodoView::unparentTodo()
924{ 935{
925 if (mActiveItem) { 936 if (mActiveItem) {
926 emit unparentTodoSignal(mActiveItem->todo()); 937 emit unparentTodoSignal(mActiveItem->todo());
927 } 938 }
928} 939}
929 940
930void KOTodoView::reparentTodo() 941void KOTodoView::reparentTodo()
931{ 942{
932 if (mActiveItem) { 943 if (mActiveItem) {
933 qDebug("KOTodoView::reparentTodo() "); 944 qDebug("KOTodoView::reparentTodo() ");
934 topLevelWidget()->setCaption(i18n("Click on new parent item")); 945 topLevelWidget()->setCaption(i18n("Click on new parent item"));
935 pendingSubtodo = mActiveItem; 946 pendingSubtodo = mActiveItem;
936 } 947 }
937} 948}
938void KOTodoView::editTodo() 949void KOTodoView::editTodo()
939{ 950{
940 if (mActiveItem) { 951 if (mActiveItem) {
941 emit editTodoSignal(mActiveItem->todo()); 952 emit editTodoSignal(mActiveItem->todo());
942 } 953 }
943} 954}
944void KOTodoView::cloneTodo() 955void KOTodoView::cloneTodo()
945{ 956{
946 if (mActiveItem) { 957 if (mActiveItem) {
947 emit cloneTodoSignal((Incidence*)mActiveItem->todo()); 958 emit cloneTodoSignal((Incidence*)mActiveItem->todo());
948 } 959 }
949} 960}
950void KOTodoView::cancelTodo() 961void KOTodoView::cancelTodo()
951{ 962{
952 if (mActiveItem) { 963 if (mActiveItem) {
953 emit cancelTodoSignal((Incidence*)mActiveItem->todo()); 964 emit cancelTodoSignal((Incidence*)mActiveItem->todo());
954 } 965 }
955} 966}
956void KOTodoView::moveTodo() 967void KOTodoView::moveTodo()
957{ 968{
958 if (mActiveItem) { 969 if (mActiveItem) {
959 emit moveTodoSignal((Incidence*)mActiveItem->todo()); 970 emit moveTodoSignal((Incidence*)mActiveItem->todo());
960 } 971 }
961} 972}
962void KOTodoView::beamTodo() 973void KOTodoView::beamTodo()
963{ 974{
964 if (mActiveItem) { 975 if (mActiveItem) {
965 emit beamTodoSignal((Incidence*)mActiveItem->todo()); 976 emit beamTodoSignal((Incidence*)mActiveItem->todo());
966 } 977 }
967} 978}
968 979
969 980
970void KOTodoView::showTodo() 981void KOTodoView::showTodo()
971{ 982{
972 if (mActiveItem) { 983 if (mActiveItem) {
973 emit showTodoSignal(mActiveItem->todo()); 984 emit showTodoSignal(mActiveItem->todo());
974 } 985 }
975} 986}
976 987
977void KOTodoView::deleteTodo() 988void KOTodoView::deleteTodo()
978{ 989{
979 if (mActiveItem) { 990 if (mActiveItem) {
980 emit deleteTodoSignal(mActiveItem->todo()); 991 emit deleteTodoSignal(mActiveItem->todo());
981 } 992 }
982} 993}
983 994
984void KOTodoView::setNewPriority(int index) 995void KOTodoView::setNewPriority(int index)
985{ 996{
986 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 997 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
987 mActiveItem->todo()->setPriority(mPriority[index]); 998 mActiveItem->todo()->setPriority(mPriority[index]);
988 mActiveItem->construct(); 999 mActiveItem->construct();
989 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED); 1000 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED);
990 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 1001 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
991 } 1002 }
992} 1003}
993 1004
994void KOTodoView::setNewPercentage(int index) 1005void KOTodoView::setNewPercentage(int index)
995{ 1006{
996 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 1007 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
997 1008
998 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) { 1009 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) {
999 mActiveItem->setOn( true ); 1010 mActiveItem->setOn( true );
1000 return; 1011 return;
1001 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) { 1012 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) {
1002 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent())); 1013 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent()));
1003 if ( par && par->isOn() ) 1014 if ( par && par->isOn() )
1004 par->setOn( false ); 1015 par->setOn( false );
1005 } 1016 }
1006 if (mPercentage[index] == 100) { 1017 if (mPercentage[index] == 100) {
1007 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime()); 1018 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime());
1008 } else { 1019 } else {
1009 mActiveItem->todo()->setCompleted(false); 1020 mActiveItem->todo()->setCompleted(false);
1010 } 1021 }
1011 mActiveItem->todo()->setPercentComplete(mPercentage[index]); 1022 mActiveItem->todo()->setPercentComplete(mPercentage[index]);
1012 mActiveItem->construct(); 1023 mActiveItem->construct();
1013 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED); 1024 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED);
1014 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 1025 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
1015 } 1026 }
1016} 1027}
1017 1028
1018 1029
1019QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem) 1030QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem)
1020{ 1031{
1021 QPopupMenu* tempMenu = new QPopupMenu (this); 1032 QPopupMenu* tempMenu = new QPopupMenu (this);
1022 QStringList checkedCategories = todoItem->todo()->categories (); 1033 QStringList checkedCategories = todoItem->todo()->categories ();
1023 1034
1024 tempMenu->setCheckable (true); 1035 tempMenu->setCheckable (true);
1025 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin (); 1036 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin ();
1026 it != KOPrefs::instance()->mCustomCategories.end (); 1037 it != KOPrefs::instance()->mCustomCategories.end ();
1027 ++it) { 1038 ++it) {
1028 int index = tempMenu->insertItem (*it); 1039 int index = tempMenu->insertItem (*it);
1029 mCategory[index] = *it; 1040 mCategory[index] = *it;
1030 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true); 1041 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true);
1031 } 1042 }
1032 1043
1033 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int))); 1044 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int)));
1034 return tempMenu; 1045 return tempMenu;
1035 1046
1036 1047
1037} 1048}
1038void KOTodoView::changedCategories(int index) 1049void KOTodoView::changedCategories(int index)
1039{ 1050{
1040 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 1051 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
1041 QStringList categories = mActiveItem->todo()->categories (); 1052 QStringList categories = mActiveItem->todo()->categories ();
1042 QString colcat = categories.first(); 1053 QString colcat = categories.first();
1043 if (categories.find (mCategory[index]) != categories.end ()) 1054 if (categories.find (mCategory[index]) != categories.end ())
1044 categories.remove (mCategory[index]); 1055 categories.remove (mCategory[index]);
1045 else 1056 else
1046 categories.insert (categories.end(), mCategory[index]); 1057 categories.insert (categories.end(), mCategory[index]);
1047 categories.sort (); 1058 categories.sort ();
1048 if ( !colcat.isEmpty() ) { 1059 if ( !colcat.isEmpty() ) {
1049 if ( categories.find ( colcat ) != categories.end () ) { 1060 if ( categories.find ( colcat ) != categories.end () ) {
1050 categories.remove( colcat ); 1061 categories.remove( colcat );
1051 categories.prepend( colcat ); 1062 categories.prepend( colcat );
1052 } 1063 }
1053 } 1064 }
1054 mActiveItem->todo()->setCategories (categories); 1065 mActiveItem->todo()->setCategories (categories);
1055 mActiveItem->construct(); 1066 mActiveItem->construct();
1056 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 1067 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
1057 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED); 1068 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED);
1058 } 1069 }
1059} 1070}
1060void KOTodoView::itemDoubleClicked(QListViewItem *item) 1071void KOTodoView::itemDoubleClicked(QListViewItem *item)
1061{ 1072{
1062 if ( pendingSubtodo != 0 ) { 1073 if ( pendingSubtodo != 0 ) {
1063 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 1074 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
1064 } 1075 }
1065 pendingSubtodo = 0; 1076 pendingSubtodo = 0;
1077 int row = mTodoListView->header()->sectionAt ( mTodoListView->header()->mapFromGlobal( QCursor::pos()).x() );
1078 //qDebug("ROW %d ", row);
1066 if (!item) { 1079 if (!item) {
1067 newTodo(); 1080 newTodo();
1068 return; 1081 return;
1082 } else {
1083 if ( row == 1 ) {
1084 mActiveItem = (KOTodoViewItem *) item;
1085 newSubTodo();
1086 return;
1087 }
1069 } 1088 }
1070 if ( KOPrefs::instance()->mEditOnDoubleClick ) 1089 if ( KOPrefs::instance()->mEditOnDoubleClick )
1071 editItem( item ); 1090 editItem( item );
1072 else 1091 else
1073 showItem( item , QPoint(), 0 ); 1092 showItem( item , QPoint(), 0 );
1074} 1093}
1075void KOTodoView::itemClicked(QListViewItem *item) 1094void KOTodoView::itemClicked(QListViewItem *item)
1076{ 1095{
1077 1096 //qDebug("KOTodoView::itemClicked %d", item);
1078 if (!item) { 1097 if (!item) {
1079 if ( pendingSubtodo != 0 ) { 1098 if ( pendingSubtodo != 0 ) {
1080 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 1099 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
1081 } 1100 }
1082 pendingSubtodo = 0; 1101 pendingSubtodo = 0;
1083 return; 1102 return;
1084 } 1103 }
1085 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 1104 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
1086 if ( pendingSubtodo != 0 ) { 1105 if ( pendingSubtodo != 0 ) {
1087 bool allowReparent = true; 1106 bool allowReparent = true;
1088 QListViewItem *par = item; 1107 QListViewItem *par = item;
1089 while ( par ) { 1108 while ( par ) {
1090 if ( par == pendingSubtodo ) { 1109 if ( par == pendingSubtodo ) {
1091 allowReparent = false; 1110 allowReparent = false;
1092 break; 1111 break;
1093 } 1112 }
1094 par = par->parent(); 1113 par = par->parent();
1095 } 1114 }
1096 if ( !allowReparent ) { 1115 if ( !allowReparent ) {
1097 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!")); 1116 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!"));
1098 qDebug("Recursive reparenting not possible "); 1117 qDebug("Recursive reparenting not possible ");
1099 pendingSubtodo = 0; 1118 pendingSubtodo = 0;
1100 } else { 1119 } else {
1101 Todo* newParent = todoItem->todo(); 1120 Todo* newParent = todoItem->todo();
1102 Todo* newSub = pendingSubtodo->todo(); 1121 Todo* newSub = pendingSubtodo->todo();
1103 pendingSubtodo = 0; 1122 pendingSubtodo = 0;
1104 emit reparentTodoSignal( newParent,newSub ); 1123 emit reparentTodoSignal( newParent,newSub );
1105 return; 1124 return;
1106 } 1125 }
1107 } 1126 }
1108#if 0 1127#if 0
1109 // handled by the item itself 1128 // handled by the item itself
1110 bool completed = todoItem->todo()->isCompleted(); // Completed or not? 1129 bool completed = todoItem->todo()->isCompleted(); // Completed or not?
1111 qDebug("com %d ",completed ); 1130 qDebug("com %d ",completed );
1112 qDebug("itemclicked "); 1131 qDebug("itemclicked ");
1113 if (todoItem->isOn()) { 1132 if (todoItem->isOn()) {
1114 qDebug("on "); 1133 qDebug("on ");
1115 if (!completed) { 1134 if (!completed) {
1116 qDebug("set true "); 1135 qDebug("set true ");
1117 todoItem->todo()->setCompleted(QDateTime::currentDateTime()); 1136 todoItem->todo()->setCompleted(QDateTime::currentDateTime());
1118 } 1137 }
1119 } else { 1138 } else {
1120 qDebug("not on "); 1139 qDebug("not on ");
1121 if (completed) { 1140 if (completed) {
1122 qDebug("set false "); 1141 qDebug("set false ");
1123 todoItem->todo()->setCompleted(false); 1142 todoItem->todo()->setCompleted(false);
1124 } 1143 }
1125 } 1144 }
1126#endif 1145#endif
1127} 1146}
1128 1147
1129void KOTodoView::setDocumentId( const QString &id ) 1148void KOTodoView::setDocumentId( const QString &id )
1130{ 1149{
1131 kdDebug() << "KOTodoView::setDocumentId()" << endl; 1150 kdDebug() << "KOTodoView::setDocumentId()" << endl;
1132 1151
1133 mDocPrefs->setDoc( id ); 1152 mDocPrefs->setDoc( id );
1134} 1153}
1135 1154
1136void KOTodoView::itemStateChanged( QListViewItem *item ) 1155void KOTodoView::itemStateChanged( QListViewItem *item )
1137{ 1156{
1138 if (!item) return; 1157 if (!item) return;
1139 1158
1140 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 1159 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
1141 1160
1142// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl; 1161// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl;
1143 1162
1144 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() ); 1163 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() );
1145} 1164}
1146 1165
1147void KOTodoView::saveLayout(KConfig *config, const QString &group) const 1166void KOTodoView::saveLayout(KConfig *config, const QString &group) const
1148{ 1167{
1149 mTodoListView->saveLayout(config,group); 1168 mTodoListView->saveLayout(config,group);
1150} 1169}
1151 1170
1152void KOTodoView::restoreLayout(KConfig *config, const QString &group) 1171void KOTodoView::restoreLayout(KConfig *config, const QString &group)
1153{ 1172{
1154 mTodoListView->restoreLayout(config,group); 1173 mTodoListView->restoreLayout(config,group);
1155} 1174}
1156 1175
1157void KOTodoView::processSelectionChange() 1176void KOTodoView::processSelectionChange()
1158{ 1177{
1159// kdDebug() << "KOTodoView::processSelectionChange()" << endl; 1178// kdDebug() << "KOTodoView::processSelectionChange()" << endl;
1160 1179
1161 KOTodoViewItem *item = 1180 KOTodoViewItem *item =
1162 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() ); 1181 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() );
1163 1182
1164 if ( !item ) { 1183 if ( !item ) {
1165 emit incidenceSelected( 0 ); 1184 emit incidenceSelected( 0 );
1166 } else { 1185 } else {
1167 emit incidenceSelected( item->todo() ); 1186 emit incidenceSelected( item->todo() );
1168 } 1187 }
1169} 1188}
1170 1189
1171void KOTodoView::modified(bool b) 1190void KOTodoView::modified(bool b)
1172{ 1191{
1173 emit isModified(b); 1192 emit isModified(b);
1174} 1193}
1175void KOTodoView::setTodoModified( Todo* todo ) 1194void KOTodoView::setTodoModified( Todo* todo )
1176{ 1195{
1177 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED ); 1196 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED );
1178} 1197}
1179void KOTodoView::clearSelection() 1198void KOTodoView::clearSelection()
1180{ 1199{
1181 mTodoListView->selectAll( false ); 1200 mTodoListView->selectAll( false );
1182} 1201}
1183void KOTodoView::setAllOpen() 1202void KOTodoView::setAllOpen()
1184{ 1203{
1185 if ( isFlatDisplay ) { 1204 if ( isFlatDisplay ) {
1186 isFlatDisplay = false; 1205 isFlatDisplay = false;
1187 mPopupMenu->setItemChecked( 8,false ); 1206 mPopupMenu->setItemChecked( 8,false );
1188 updateView(); 1207 updateView();
1189 } 1208 }
1190 setOpen(mTodoListView->firstChild(), true); 1209 setOpen(mTodoListView->firstChild(), true);
1191} 1210}
1192void KOTodoView::setAllClose() 1211void KOTodoView::setAllClose()
1193{ 1212{
1194 if ( isFlatDisplay ) { 1213 if ( isFlatDisplay ) {
1195 isFlatDisplay = false; 1214 isFlatDisplay = false;
1196 mPopupMenu->setItemChecked( 8,false ); 1215 mPopupMenu->setItemChecked( 8,false );
1197 updateView(); 1216 updateView();
1198 } 1217 }
1199 setOpen(mTodoListView->firstChild(), false); 1218 setOpen(mTodoListView->firstChild(), false);
1200} 1219}
1201void KOTodoView::setOpen( QListViewItem* item, bool setOpenI) 1220void KOTodoView::setOpen( QListViewItem* item, bool setOpenI)
1202{ 1221{
1203 1222
1204 while ( item ) { 1223 while ( item ) {
1205 setOpen( item->firstChild(), setOpenI ); 1224 setOpen( item->firstChild(), setOpenI );
1206 item->setOpen( setOpenI ); 1225 item->setOpen( setOpenI );
1207 item = item->nextSibling(); 1226 item = item->nextSibling();
1208 } 1227 }
1209} 1228}
1210 1229
1211void KOTodoView::displayAllFlat() 1230void KOTodoView::displayAllFlat()
1212{ 1231{
1213 pendingSubtodo = 0; 1232 pendingSubtodo = 0;
1214 if ( mBlockUpdate ) { 1233 if ( mBlockUpdate ) {
1215 return; 1234 return;
1216 } 1235 }
1217 mPopupMenu->setItemChecked( 8,true ); 1236 mPopupMenu->setItemChecked( 8,true );
1218 isFlatDisplay = true; 1237 isFlatDisplay = true;
1219 QPtrList<Todo> todoList = calendar()->todos(); 1238 QPtrList<Todo> todoList = calendar()->todos();
1220 mTodoMap.clear(); 1239 mTodoMap.clear();
1221 mTodoListView->clear(); 1240 mTodoListView->clear();
1222 Todo *todo; 1241 Todo *todo;
1223 for(todo = todoList.first(); todo; todo = todoList.next()) { 1242 for(todo = todoList.first(); todo; todo = todoList.next()) {
1224 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 1243 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
1225 mTodoMap.insert(todo,todoItem); 1244 mTodoMap.insert(todo,todoItem);
1226 } 1245 }
1227 mTodoListView->setFocus(); 1246 mTodoListView->setFocus();
1228 processSelectionChange(); 1247 processSelectionChange();
1229} 1248}
1230 1249
1231void KOTodoView::setAllFlat() 1250void KOTodoView::setAllFlat()
1232{ 1251{
1233 if ( isFlatDisplay ) { 1252 if ( isFlatDisplay ) {
1234 isFlatDisplay = false; 1253 isFlatDisplay = false;
1235 mPopupMenu->setItemChecked( 8,false ); 1254 mPopupMenu->setItemChecked( 8,false );
1236 updateView(); 1255 updateView();
1237 return; 1256 return;
1238 } 1257 }
1239 displayAllFlat(); 1258 displayAllFlat();
1240} 1259}
1241 1260
1242void KOTodoView::purgeCompleted() 1261void KOTodoView::purgeCompleted()
1243{ 1262{
1244 emit purgeCompletedSignal(); 1263 emit purgeCompletedSignal();
1245} 1264}
1246void KOTodoView::toggleQuickTodo() 1265void KOTodoView::toggleQuickTodo()
1247{ 1266{
1248 if ( mQuickAdd->isVisible() ) { 1267 if ( mQuickAdd->isVisible() ) {
1249 mQuickAdd->hide(); 1268 mQuickAdd->hide();
1250 KOPrefs::instance()->mEnableQuickTodo = false; 1269 KOPrefs::instance()->mEnableQuickTodo = false;
1251 } 1270 }
1252 else { 1271 else {
1253 mQuickAdd->show(); 1272 mQuickAdd->show();
1254 KOPrefs::instance()->mEnableQuickTodo = true; 1273 KOPrefs::instance()->mEnableQuickTodo = true;
1255 } 1274 }
1256 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 1275 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
1257 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 1276 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
1258} 1277}
1259 1278
1260void KOTodoView::toggleRunning() 1279void KOTodoView::toggleRunning()
1261{ 1280{
1262 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos; 1281 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos;
1263 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 1282 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
1264 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 1283 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
1265 updateView(); 1284 updateView();
1266} 1285}
1267 1286
1268void KOTodoView::toggleCompleted() 1287void KOTodoView::toggleCompleted()
1269{ 1288{
1270 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo; 1289 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo;
1271 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 1290 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
1272 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 1291 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
1273 updateView(); 1292 updateView();
1274} 1293}
1275 1294
1276void KOTodoView::addQuickTodo() 1295void KOTodoView::addQuickTodo()
1277{ 1296{
1278 Todo *todo = new Todo(); 1297 Todo *todo = new Todo();
1279 todo->setSummary(mQuickAdd->text()); 1298 todo->setSummary(mQuickAdd->text());
1280 todo->setOrganizer(KOPrefs::instance()->email()); 1299 todo->setOrganizer(KOPrefs::instance()->email());
1281 CalFilter * cf = mCalendar->filter(); 1300 CalFilter * cf = mCalendar->filter();
1282 if ( cf ) { 1301 if ( cf ) {
1283 if ( cf->isEnabled()&& cf->showCategories()) { 1302 if ( cf->isEnabled()&& cf->showCategories()) {
1284 todo->setCategories(cf->categoryList()); 1303 todo->setCategories(cf->categoryList());
1285 } 1304 }
1286 if ( cf->isEnabled() ) 1305 if ( cf->isEnabled() )
1287 todo->setSecrecy( cf->getSecrecy()); 1306 todo->setSecrecy( cf->getSecrecy());
1288 } 1307 }
1289 mCalendar->addTodo(todo); 1308 mCalendar->addTodo(todo);
1290 mQuickAdd->setText(""); 1309 mQuickAdd->setText("");
1291 todoModified (todo, KOGlobals::EVENTADDED ); 1310 todoModified (todo, KOGlobals::EVENTADDED );
1292 updateView(); 1311 updateView();
1293} 1312}
1294 1313
1295void KOTodoView::keyPressEvent ( QKeyEvent * e ) 1314void KOTodoView::keyPressEvent ( QKeyEvent * e )
1296{ 1315{
1297 // e->ignore(); 1316 // e->ignore();
1298 //return; 1317 //return;
1299 //qDebug("KOTodoView::keyPressEvent "); 1318 //qDebug("KOTodoView::keyPressEvent ");
1300 switch ( e->key() ) { 1319 switch ( e->key() ) {
1301 case Qt::Key_Down: 1320 case Qt::Key_Down:
1302 case Qt::Key_Up: 1321 case Qt::Key_Up:
1303 QWidget::keyPressEvent ( e ); 1322 QWidget::keyPressEvent ( e );
1304 break; 1323 break;
1305 1324
1306 case Qt::Key_Q: 1325 case Qt::Key_Q:
1307 toggleQuickTodo(); 1326 toggleQuickTodo();
1308 break; 1327 break;
1309 case Qt::Key_U: 1328 case Qt::Key_U:
1310 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1329 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1311 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1330 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1312 unparentTodo(); 1331 unparentTodo();
1313 e->accept(); 1332 e->accept();
1314 } else 1333 } else
1315 e->ignore(); 1334 e->ignore();
1316 break; 1335 break;
1317 case Qt::Key_S: 1336 case Qt::Key_S:
1318 if ( e->state() == Qt::ControlButton ) { 1337 if ( e->state() == Qt::ControlButton ) {
1319 e->ignore(); 1338 e->ignore();
1320 break; 1339 break;
1321 } 1340 }
1322 if ( e->state() == Qt::ShiftButton ) { 1341 if ( e->state() == Qt::ShiftButton ) {
1323 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1342 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1324 reparentTodo(); 1343 reparentTodo();
1325 e->accept(); 1344 e->accept();
1326 } else 1345 } else
1327 e->ignore(); 1346 e->ignore();
1328 break; 1347 break;
1329 case Qt::Key_P: 1348 case Qt::Key_P:
1330 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1349 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1331 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1350 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1332 if ( pendingSubtodo ) 1351 if ( pendingSubtodo )
1333 itemClicked(mActiveItem); 1352 itemClicked(mActiveItem);
1334 e->accept(); 1353 e->accept();
1335 } else 1354 } else
1336 e->ignore(); 1355 e->ignore();
1337 break; 1356 break;
1338 case Qt::Key_Escape: 1357 case Qt::Key_Escape:
1339 if ( pendingSubtodo ) { 1358 if ( pendingSubtodo ) {
1340 itemClicked(0); 1359 itemClicked(0);
1341 e->accept(); 1360 e->accept();
1342 } else 1361 } else
1343 e->ignore(); 1362 e->ignore();
1344 break; 1363 break;
1345 default: 1364 default:
1346 e->ignore(); 1365 e->ignore();
1347 } 1366 }
1348 1367
1349 if ( true ) { 1368 if ( true ) {
1350 if ( e->key() == Qt::Key_I ) { 1369 if ( e->key() == Qt::Key_I ) {
1351 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem(); 1370 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem();
1352 if ( cn ) { 1371 if ( cn ) {
1353 mActiveItem = cn; 1372 mActiveItem = cn;
1354 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 1373 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
1355 if ( ci ){ 1374 if ( ci ){
1356 showTodo(); 1375 showTodo();
1357 cn = (KOTodoViewItem*)cn->itemBelow(); 1376 cn = (KOTodoViewItem*)cn->itemBelow();
1358 if ( cn ) { 1377 if ( cn ) {
1359 mTodoListView->setCurrentItem ( cn ); 1378 mTodoListView->setCurrentItem ( cn );
1360 mTodoListView->ensureItemVisible ( cn ); 1379 mTodoListView->ensureItemVisible ( cn );
1361 } 1380 }
1362 1381
1363 } 1382 }
1364 } 1383 }
1365 e->accept(); 1384 e->accept();
1366 1385
1367 } 1386 }
1368 1387
1369 } 1388 }
1370 1389
1371} 1390}
1372void KOTodoView::updateTodo( Todo * t, int type ) 1391void KOTodoView::updateTodo( Todo * t, int type )
1373{ 1392{
1374 if ( mBlockUpdate) 1393 if ( mBlockUpdate)
1375 return; 1394 return;
1376 1395
1377 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 1396 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
1378 itemIterator = mTodoMap.find(t); 1397 itemIterator = mTodoMap.find(t);
1379 if (itemIterator != mTodoMap.end()) { 1398 if (itemIterator != mTodoMap.end()) {
1380 (*itemIterator)->construct(); 1399 (*itemIterator)->construct();
1381 } else { 1400 } else {
1382 if ( type == KOGlobals::EVENTADDED ) { 1401 if ( type == KOGlobals::EVENTADDED ) {
1383 insertTodoItem( t ); 1402 insertTodoItem( t );
1384 } 1403 }
1385 } 1404 }
1386 1405
1387} 1406}
1388 1407
1389void KOTodoView::todoModified(Todo * t , int p ) 1408void KOTodoView::todoModified(Todo * t , int p )
1390{ 1409{
1391 mBlockUpdate = true; 1410 mBlockUpdate = true;
1392 emit todoModifiedSignal ( t, p ); 1411 emit todoModifiedSignal ( t, p );
1393 mBlockUpdate = false; 1412 mBlockUpdate = false;
1394} 1413}