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