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