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