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