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