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