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