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