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