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