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