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