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