summaryrefslogtreecommitdiffabout
path: root/korganizer
authorzautrix <zautrix>2005-01-30 16:38:38 (UTC)
committer zautrix <zautrix>2005-01-30 16:38:38 (UTC)
commit23d345c877ae9de6a077af3705026d15bb04d1e3 (patch) (unidiff)
tree1c90eaf14b5fe5daf97645bebed2eabbe66b8a89 /korganizer
parenta34c528fdd8d2cdec14bae9ccb0eee54c8e4e374 (diff)
downloadkdepimpi-23d345c877ae9de6a077af3705026d15bb04d1e3.zip
kdepimpi-23d345c877ae9de6a077af3705026d15bb04d1e3.tar.gz
kdepimpi-23d345c877ae9de6a077af3705026d15bb04d1e3.tar.bz2
fix
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagenda.cpp2
-rw-r--r--korganizer/koagendaview.cpp3
-rw-r--r--korganizer/koeditorgeneraltodo.h1
-rw-r--r--korganizer/kotodoeditor.cpp12
4 files changed, 13 insertions, 5 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp
index 7c41cab..0aef929 100644
--- a/korganizer/koagenda.cpp
+++ b/korganizer/koagenda.cpp
@@ -1,1998 +1,1998 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 Marcus Bains line. 5 Marcus Bains line.
6 Copyright (c) 2001 Ali Rahimi 6 Copyright (c) 2001 Ali Rahimi
7 7
8 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 (at your option) any later version.
12 12
13 This program is distributed in the hope that it will be useful, 13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 GNU General Public License for more details.
17 17
18 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software 19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 21
22 As a special exception, permission is given to link this program 22 As a special exception, permission is given to link this program
23 with any edition of Qt, and distribute the resulting executable, 23 with any edition of Qt, and distribute the resulting executable,
24 without including the source code for Qt in the source distribution. 24 without including the source code for Qt in the source distribution.
25*/ 25*/
26 26
27#ifndef _WIN32_ 27#ifndef _WIN32_
28#define protected public 28#define protected public
29#include <qwidget.h> 29#include <qwidget.h>
30#undef protected 30#undef protected
31#endif 31#endif
32#include <qintdict.h> 32#include <qintdict.h>
33#include <qdatetime.h> 33#include <qdatetime.h>
34#include <qapplication.h> 34#include <qapplication.h>
35#include <qpopupmenu.h> 35#include <qpopupmenu.h>
36#include <qcursor.h> 36#include <qcursor.h>
37#include <qpainter.h> 37#include <qpainter.h>
38 38
39#include <kdebug.h> 39#include <kdebug.h>
40#include <klocale.h> 40#include <klocale.h>
41#include <kiconloader.h> 41#include <kiconloader.h>
42#include <kglobal.h> 42#include <kglobal.h>
43 43
44#include "koagendaitem.h" 44#include "koagendaitem.h"
45#include "koprefs.h" 45#include "koprefs.h"
46#include "koglobals.h" 46#include "koglobals.h"
47 47
48#include "koagenda.h" 48#include "koagenda.h"
49 49
50#include <libkcal/event.h> 50#include <libkcal/event.h>
51#include <libkcal/todo.h> 51#include <libkcal/todo.h>
52 52
53#ifndef DESKTOP_VERSION 53#ifndef DESKTOP_VERSION
54#include <qpe/qpeapplication.h> 54#include <qpe/qpeapplication.h>
55#endif 55#endif
56 56
57//extern bool globalFlagBlockPainting; 57//extern bool globalFlagBlockPainting;
58extern int globalFlagBlockAgenda; 58extern int globalFlagBlockAgenda;
59extern int globalFlagBlockAgendaItemPaint; 59extern int globalFlagBlockAgendaItemPaint;
60extern int globalFlagBlockAgendaItemUpdate; 60extern int globalFlagBlockAgendaItemUpdate;
61extern int globalFlagBlockStartup; 61extern int globalFlagBlockStartup;
62 62
63//////////////////////////////////////////////////////////////////////////// 63////////////////////////////////////////////////////////////////////////////
64MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name) 64MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name)
65 : QFrame(_agenda->viewport(),name), agenda(_agenda) 65 : QFrame(_agenda->viewport(),name), agenda(_agenda)
66{ 66{
67 setLineWidth(0); 67 setLineWidth(0);
68 setMargin(0); 68 setMargin(0);
69 setBackgroundColor(Qt::red); 69 setBackgroundColor(Qt::red);
70 minutes = new QTimer(this); 70 minutes = new QTimer(this);
71 connect(minutes, SIGNAL(timeout()), this, SLOT(updateLoc())); 71 connect(minutes, SIGNAL(timeout()), this, SLOT(updateLoc()));
72 minutes->start(0, true); 72 minutes->start(0, true);
73 73
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}
90 90
91int MarcusBains::todayColumn() 91int MarcusBains::todayColumn()
92{ 92{
93 QDate currentDate = QDate::currentDate(); 93 QDate currentDate = QDate::currentDate();
94 94
95 DateList dateList = agenda->dateList(); 95 DateList dateList = agenda->dateList();
96 DateList::ConstIterator it; 96 DateList::ConstIterator it;
97 int col = 0; 97 int col = 0;
98 for(it = dateList.begin(); it != dateList.end(); ++it) { 98 for(it = dateList.begin(); it != dateList.end(); ++it) {
99 if((*it) == currentDate) 99 if((*it) == currentDate)
100 return KOGlobals::self()->reverseLayout() ? 100 return KOGlobals::self()->reverseLayout() ?
101 agenda->columns() - 1 - col : col; 101 agenda->columns() - 1 - col : col;
102 ++col; 102 ++col;
103 } 103 }
104 104
105 return -1; 105 return -1;
106} 106}
107void MarcusBains::updateLoc() 107void MarcusBains::updateLoc()
108{ 108{
109 updateLocation(); 109 updateLocation();
110} 110}
111void MarcusBains::updateLocation(bool recalculate) 111void MarcusBains::updateLocation(bool recalculate)
112{ 112{
113 113
114 QTime tim = QTime::currentTime(); 114 QTime tim = QTime::currentTime();
115 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1()); 115 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1());
116 if((tim.hour() == 0) && (oldTime.hour()==23)) 116 if((tim.hour() == 0) && (oldTime.hour()==23))
117 recalculate = true; 117 recalculate = true;
118 118
119 int mins = tim.hour()*60 + tim.minute(); 119 int mins = tim.hour()*60 + tim.minute();
120 int minutesPerCell = 24 * 60 / agenda->rows(); 120 int minutesPerCell = 24 * 60 / agenda->rows();
121 int y = mins*agenda->gridSpacingY()/minutesPerCell; 121 int y = mins*agenda->gridSpacingY()/minutesPerCell;
122 int today = recalculate ? todayColumn() : oldToday; 122 int today = recalculate ? todayColumn() : oldToday;
123 int x = agenda->gridSpacingX()*today; 123 int x = agenda->gridSpacingX()*today;
124 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled); 124 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled);
125 125
126 oldTime = tim; 126 oldTime = tim;
127 oldToday = today; 127 oldToday = today;
128 128
129 if(disabled || (today<0)) { 129 if(disabled || (today<0)) {
130 hide(); mTimeBox->hide(); 130 hide(); mTimeBox->hide();
131 return; 131 return;
132 } else { 132 } else {
133 show(); mTimeBox->show(); 133 show(); mTimeBox->show();
134 } 134 }
135 135
136 if(recalculate) 136 if(recalculate)
137 setFixedSize(agenda->gridSpacingX(),1); 137 setFixedSize(agenda->gridSpacingX(),1);
138 agenda->moveChild(this, x, y); 138 agenda->moveChild(this, x, y);
139 raise(); 139 raise();
140 140
141 if(recalculate) 141 if(recalculate)
142 //mTimeBox->setFont(QFont("helvetica",10)); 142 //mTimeBox->setFont(QFont("helvetica",10));
143 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont); 143 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont);
144 144
145 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds)); 145 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds));
146 mTimeBox->adjustSize(); 146 mTimeBox->adjustSize();
147 // the -2 below is there because there is a bug in this program 147 // the -2 below is there because there is a bug in this program
148 // somewhere, where the last column of this widget is a few pixels 148 // somewhere, where the last column of this widget is a few pixels
149 // narrower than the other columns. 149 // narrower than the other columns.
150 int offs = (today==agenda->columns()-1) ? -4 : 0; 150 int offs = (today==agenda->columns()-1) ? -4 : 0;
151 agenda->moveChild(mTimeBox, 151 agenda->moveChild(mTimeBox,
152 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1, 152 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1,
153 y-mTimeBox->height()); 153 y-mTimeBox->height());
154 154
155 mTimeBox->raise(); 155 mTimeBox->raise();
156 //mTimeBox->setAutoMask(true); 156 //mTimeBox->setAutoMask(true);
157 minutes->start(5000,true); 157 minutes->start(5000,true);
158} 158}
159 159
160 160
161//////////////////////////////////////////////////////////////////////////// 161////////////////////////////////////////////////////////////////////////////
162 162
163 163
164/* 164/*
165 Create an agenda widget with rows rows and columns columns. 165 Create an agenda widget with rows rows and columns columns.
166*/ 166*/
167KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, 167KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent,
168 const char *name,WFlags f) : 168 const char *name,WFlags f) :
169 QScrollView(parent,name,f) 169 QScrollView(parent,name,f)
170{ 170{
171 171
172 172
173 mColumns = columns; 173 mColumns = columns;
174 mRows = rows; 174 mRows = rows;
175 mGridSpacingY = rowSize; 175 mGridSpacingY = rowSize;
176 mAllDayMode = false; 176 mAllDayMode = false;
177#ifndef DESKTOP_VERSION 177#ifndef DESKTOP_VERSION
178 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 178 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
179#endif 179#endif
180 mHolidayMask = 0; 180 mHolidayMask = 0;
181 init(); 181 init();
182} 182}
183 183
184/* 184/*
185 Create an agenda widget with columns columns and one row. This is used for 185 Create an agenda widget with columns columns and one row. This is used for
186 all-day events. 186 all-day events.
187*/ 187*/
188KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : 188KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) :
189 QScrollView(parent,name,f) 189 QScrollView(parent,name,f)
190{ 190{
191 blockResize = false; 191 blockResize = false;
192 mColumns = columns; 192 mColumns = columns;
193 mRows = 1; 193 mRows = 1;
194 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize); 194 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize);
195 mGridSpacingY = KOPrefs::instance()->mAllDaySize; 195 mGridSpacingY = KOPrefs::instance()->mAllDaySize;
196 mAllDayMode = true; 196 mAllDayMode = true;
197#ifndef DESKTOP_VERSION 197#ifndef DESKTOP_VERSION
198 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 198 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
199#endif 199#endif
200 mHolidayMask = 0; 200 mHolidayMask = 0;
201 init(); 201 init();
202} 202}
203 203
204 204
205KOAgenda::~KOAgenda() 205KOAgenda::~KOAgenda()
206{ 206{
207 if(mMarcusBains) delete mMarcusBains; 207 if(mMarcusBains) delete mMarcusBains;
208 208
209} 209}
210 210
211Incidence *KOAgenda::selectedIncidence() const 211Incidence *KOAgenda::selectedIncidence() const
212{ 212{
213 return (mSelectedItem ? mSelectedItem->incidence() : 0); 213 return (mSelectedItem ? mSelectedItem->incidence() : 0);
214} 214}
215 215
216 216
217QDate KOAgenda::selectedIncidenceDate() const 217QDate KOAgenda::selectedIncidenceDate() const
218{ 218{
219 return (mSelectedItem ? mSelectedItem->itemDate() : QDate()); 219 return (mSelectedItem ? mSelectedItem->itemDate() : QDate());
220} 220}
221 221
222 222
223void KOAgenda::init() 223void KOAgenda::init()
224{ 224{
225 mNewItemPopup = new QPopupMenu( this ); 225 mNewItemPopup = new QPopupMenu( this );
226 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) ); 226 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) );
227 QString pathString = ""; 227 QString pathString = "";
228 if ( !KOPrefs::instance()->mToolBarMiniIcons ) { 228 if ( !KOPrefs::instance()->mToolBarMiniIcons ) {
229 if ( QApplication::desktop()->width() < 480 ) 229 if ( QApplication::desktop()->width() < 480 )
230 pathString += "icons16/"; 230 pathString += "icons16/";
231 } else 231 } else
232 pathString += "iconsmini/"; 232 pathString += "iconsmini/";
233 233
234 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 ); 234 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 );
235 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 ); 235 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 );
236 mNewItemPopup->insertSeparator ( ); 236 mNewItemPopup->insertSeparator ( );
237 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 ); 237 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 );
238 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 ); 238 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 );
239 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 ); 239 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 );
240 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 ); 240 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 );
241 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("Next month"),6 ); 241 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("Next month"),6 );
242 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 ); 242 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 );
243#ifndef _WIN32_ 243#ifndef _WIN32_
244 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase 244 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase
245 viewport()->setWFlags ( wflags); 245 viewport()->setWFlags ( wflags);
246#endif 246#endif
247 mGridSpacingX = 80; 247 mGridSpacingX = 80;
248 mResizeBorderWidth = 8; 248 mResizeBorderWidth = 8;
249 mScrollBorderWidth = 8; 249 mScrollBorderWidth = 8;
250 mScrollDelay = 30; 250 mScrollDelay = 30;
251 mScrollOffset = 10; 251 mScrollOffset = 10;
252 mPaintPixmap.resize( 20,20); 252 mPaintPixmap.resize( 20,20);
253 //enableClipper(true); 253 //enableClipper(true);
254 254
255 // Grab key strokes for keyboard navigation of agenda. Seems to have no 255 // Grab key strokes for keyboard navigation of agenda. Seems to have no
256 // effect. Has to be fixed. 256 // effect. Has to be fixed.
257 setFocusPolicy(WheelFocus); 257 setFocusPolicy(WheelFocus);
258 258
259 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp())); 259 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp()));
260 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown())); 260 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown()));
261 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize())); 261 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize()));
262 262
263 mStartCellX = 0; 263 mStartCellX = 0;
264 mStartCellY = 0; 264 mStartCellY = 0;
265 mCurrentCellX = 0; 265 mCurrentCellX = 0;
266 mCurrentCellY = 0; 266 mCurrentCellY = 0;
267 267
268 mSelectionCellX = 0; 268 mSelectionCellX = 0;
269 mSelectionYTop = 0; 269 mSelectionYTop = 0;
270 mSelectionHeight = 0; 270 mSelectionHeight = 0;
271 271
272 mOldLowerScrollValue = -1; 272 mOldLowerScrollValue = -1;
273 mOldUpperScrollValue = -1; 273 mOldUpperScrollValue = -1;
274 274
275 mClickedItem = 0; 275 mClickedItem = 0;
276 276
277 mActionItem = 0; 277 mActionItem = 0;
278 mActionType = NOP; 278 mActionType = NOP;
279 mItemMoved = false; 279 mItemMoved = false;
280 280
281 mSelectedItem = 0; 281 mSelectedItem = 0;
282 282
283 // mItems.setAutoDelete(true); 283 // mItems.setAutoDelete(true);
284 284
285 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 285 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
286 286
287 viewport()->update(); 287 viewport()->update();
288 288
289 setMinimumSize(30, 1); 289 setMinimumSize(30, 1);
290// setMaximumHeight(mGridSpacingY * mRows + 5); 290// setMaximumHeight(mGridSpacingY * mRows + 5);
291 291
292 // Disable horizontal scrollbar. This is a hack. The geometry should be 292 // Disable horizontal scrollbar. This is a hack. The geometry should be
293 // controlled in a way that the contents horizontally always fits. Then it is 293 // controlled in a way that the contents horizontally always fits. Then it is
294 // not necessary to turn off the scrollbar. 294 // not necessary to turn off the scrollbar.
295 setHScrollBarMode(AlwaysOff); 295 setHScrollBarMode(AlwaysOff);
296 if ( ! mAllDayMode ) 296 if ( ! mAllDayMode )
297 setVScrollBarMode(AlwaysOn); 297 setVScrollBarMode(AlwaysOn);
298 else 298 else
299 setVScrollBarMode(AlwaysOff); 299 setVScrollBarMode(AlwaysOff);
300 300
301 setStartHour(KOPrefs::instance()->mDayBegins); 301 setStartHour(KOPrefs::instance()->mDayBegins);
302 302
303 calculateWorkingHours(); 303 calculateWorkingHours();
304 304
305 connect(verticalScrollBar(),SIGNAL(valueChanged(int)), 305 connect(verticalScrollBar(),SIGNAL(valueChanged(int)),
306 SLOT(checkScrollBoundaries(int))); 306 SLOT(checkScrollBoundaries(int)));
307 307
308 // Create the Marcus Bains line. 308 // Create the Marcus Bains line.
309 if(mAllDayMode) 309 if(mAllDayMode)
310 mMarcusBains = 0; 310 mMarcusBains = 0;
311 else { 311 else {
312 mMarcusBains = new MarcusBains(this); 312 mMarcusBains = new MarcusBains(this);
313 addChild(mMarcusBains); 313 addChild(mMarcusBains);
314 } 314 }
315} 315}
316 316
317void KOAgenda::clear() 317void KOAgenda::clear()
318{ 318{
319 KOAgendaItem *item; 319 KOAgendaItem *item;
320 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 320 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
321 mUnusedItems.append( item ); 321 mUnusedItems.append( item );
322 //item->hide(); 322 //item->hide();
323 } 323 }
324 mItems.clear(); 324 mItems.clear();
325 mSelectedItem = 0; 325 mSelectedItem = 0;
326 clearSelection(); 326 clearSelection();
327} 327}
328 328
329void KOAgenda::clearSelection() 329void KOAgenda::clearSelection()
330{ 330{
331 mSelectionCellX = 0; 331 mSelectionCellX = 0;
332 mSelectionYTop = 0; 332 mSelectionYTop = 0;
333 mSelectionHeight = 0; 333 mSelectionHeight = 0;
334} 334}
335 335
336void KOAgenda::marcus_bains() 336void KOAgenda::marcus_bains()
337{ 337{
338 if(mMarcusBains) mMarcusBains->updateLocation(true); 338 if(mMarcusBains) mMarcusBains->updateLocation(true);
339} 339}
340 340
341 341
342void KOAgenda::changeColumns(int columns) 342void KOAgenda::changeColumns(int columns)
343{ 343{
344 if (columns == 0) { 344 if (columns == 0) {
345 kdDebug() << "KOAgenda::changeColumns() called with argument 0" << endl; 345 kdDebug() << "KOAgenda::changeColumns() called with argument 0" << endl;
346 return; 346 return;
347 } 347 }
348 348
349 clear(); 349 clear();
350 350
351 mColumns = columns; 351 mColumns = columns;
352// setMinimumSize(mColumns * 10, mGridSpacingY + 1); 352// setMinimumSize(mColumns * 10, mGridSpacingY + 1);
353// init(); 353// init();
354// update(); 354// update();
355 //qDebug("KOAgenda::changeColumns "); 355 //qDebug("KOAgenda::changeColumns ");
356 computeSizes(); 356 computeSizes();
357 // QResizeEvent event( size(), size() ); 357 // QResizeEvent event( size(), size() );
358 358
359 //QApplication::sendEvent( this, &event ); 359 //QApplication::sendEvent( this, &event );
360} 360}
361 361
362/* 362/*
363 This is the eventFilter function, which gets all events from the KOAgendaItems 363 This is the eventFilter function, which gets all events from the KOAgendaItems
364 contained in the agenda. It has to handle moving and resizing for all items. 364 contained in the agenda. It has to handle moving and resizing for all items.
365*/ 365*/
366bool KOAgenda::eventFilter ( QObject *object, QEvent *event ) 366bool KOAgenda::eventFilter ( QObject *object, QEvent *event )
367{ 367{
368// kdDebug() << "KOAgenda::eventFilter" << endl; 368// kdDebug() << "KOAgenda::eventFilter" << endl;
369 switch(event->type()) { 369 switch(event->type()) {
370 case QEvent::MouseButtonPress: 370 case QEvent::MouseButtonPress:
371 case QEvent::MouseButtonDblClick: 371 case QEvent::MouseButtonDblClick:
372 case QEvent::MouseButtonRelease: 372 case QEvent::MouseButtonRelease:
373 case QEvent::MouseMove: 373 case QEvent::MouseMove:
374 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event)); 374 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event));
375 375
376 case (QEvent::Leave): 376 case (QEvent::Leave):
377 if (!mActionItem) 377 if (!mActionItem)
378 setCursor(arrowCursor); 378 setCursor(arrowCursor);
379 return true; 379 return true;
380 380
381 default: 381 default:
382 return QScrollView::eventFilter(object,event); 382 return QScrollView::eventFilter(object,event);
383 } 383 }
384} 384}
385 385
386 386
387bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) 387bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me)
388{ 388{
389 //qDebug("KOAgenda::eventFilter_mous "); 389 //qDebug("KOAgenda::eventFilter_mous ");
390 QPoint viewportPos; 390 QPoint viewportPos;
391 if (object != viewport()) { 391 if (object != viewport()) {
392 viewportPos = ((QWidget *)object)->mapToParent(me->pos()); 392 viewportPos = ((QWidget *)object)->mapToParent(me->pos());
393 } else { 393 } else {
394 viewportPos = me->pos(); 394 viewportPos = me->pos();
395 } 395 }
396 static int startX = 0; 396 static int startX = 0;
397 static int startY = 0; 397 static int startY = 0;
398 static bool block = true; 398 static bool block = true;
399 switch (me->type()) { 399 switch (me->type()) {
400 case QEvent::MouseButtonPress: 400 case QEvent::MouseButtonPress:
401 //qDebug("QEvent::MouseButtonPress: "); 401 //qDebug("QEvent::MouseButtonPress: ");
402 // kdDebug() << "koagenda: filtered button press" << endl; 402 // kdDebug() << "koagenda: filtered button press" << endl;
403 if (object != viewport()) { 403 if (object != viewport()) {
404 if (me->button() == RightButton) { 404 if (me->button() == RightButton) {
405 405
406 mClickedItem = (KOAgendaItem *)object; 406 mClickedItem = (KOAgendaItem *)object;
407 if (mClickedItem) { 407 if (mClickedItem) {
408 selectItem(mClickedItem); 408 selectItem(mClickedItem);
409 // emit showIncidencePopupSignal(mClickedItem->incidence()); 409 // emit showIncidencePopupSignal(mClickedItem->incidence());
410 } 410 }
411 //mItemPopup->popup(QCursor::pos()); 411 //mItemPopup->popup(QCursor::pos());
412 } else { 412 } else {
413 mActionItem = (KOAgendaItem *)object; 413 mActionItem = (KOAgendaItem *)object;
414 if (mActionItem) { 414 if (mActionItem) {
415 if ( mSelectionHeight > 0 ) { 415 if ( mSelectionHeight > 0 ) {
416 int selectionCellX = mSelectionCellX * mGridSpacingX; 416 int selectionCellX = mSelectionCellX * mGridSpacingX;
417 int selectionYTop = mSelectionYTop; 417 int selectionYTop = mSelectionYTop;
418 int gridSpacingX = mGridSpacingX; 418 int gridSpacingX = mGridSpacingX;
419 int selectionHeight = mSelectionHeight; 419 int selectionHeight = mSelectionHeight;
420 clearSelection(); 420 clearSelection();
421 repaintContents( selectionCellX, selectionYTop, 421 repaintContents( selectionCellX, selectionYTop,
422 gridSpacingX, selectionHeight,false ); 422 gridSpacingX, selectionHeight,false );
423 } 423 }
424 selectItem(mActionItem); 424 selectItem(mActionItem);
425 Incidence *incidence = mActionItem->incidence(); 425 Incidence *incidence = mActionItem->incidence();
426 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { 426 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) {
427 mActionItem = 0; 427 mActionItem = 0;
428 } else { 428 } else {
429 startItemAction(viewportPos); 429 startItemAction(viewportPos);
430 startX = viewportPos.x(); 430 startX = viewportPos.x();
431 startY = viewportPos.y(); 431 startY = viewportPos.y();
432 block = true; 432 block = true;
433 } 433 }
434 } 434 }
435 } 435 }
436 } else { 436 } else {
437 selectItem(0); 437 selectItem(0);
438 mActionItem = 0; 438 mActionItem = 0;
439 if (me->button() == RightButton ) { 439 if (me->button() == RightButton ) {
440 blockNewEvent = true; 440 blockNewEvent = true;
441 //qDebug("right "); 441 //qDebug("right ");
442 int x,y; 442 int x,y;
443 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 443 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
444 int gx,gy; 444 int gx,gy;
445 contentsToGrid(x,y,gx,gy); 445 contentsToGrid(x,y,gx,gy);
446 mStartCellX = gx; 446 mStartCellX = gx;
447 mStartCellY = gy; 447 mStartCellY = gy;
448 mCurrentCellX = gx; 448 mCurrentCellX = gx;
449 mCurrentCellY = gy; 449 mCurrentCellY = gy;
450 mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) ); 450 mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) );
451 451
452 } else { 452 } else {
453 blockNewEvent = false; 453 blockNewEvent = false;
454 setCursor(arrowCursor); 454 setCursor(arrowCursor);
455 startSelectAction(viewportPos); 455 startSelectAction(viewportPos);
456 } 456 }
457 } 457 }
458 break; 458 break;
459 459
460 case QEvent::MouseButtonRelease: 460 case QEvent::MouseButtonRelease:
461 //qDebug("QEvent::MouseButtonRelease: "); 461 //qDebug("QEvent::MouseButtonRelease: ");
462 if (me->button() == RightButton && block ) { 462 if (me->button() == RightButton && block ) {
463 if (object != viewport()) { 463 if (object != viewport()) {
464 mClickedItem = (KOAgendaItem *)object; 464 mClickedItem = (KOAgendaItem *)object;
465 if (mActionItem ) { 465 if (mActionItem ) {
466 endItemAction(); 466 endItemAction();
467 } 467 }
468 if (mClickedItem) { 468 if (mClickedItem) {
469 selectItem(mClickedItem); 469 selectItem(mClickedItem);
470 emit showIncidencePopupSignal(mClickedItem->incidence()); 470 emit showIncidencePopupSignal(mClickedItem->incidence());
471 } 471 }
472 } 472 }
473 break; 473 break;
474 } 474 }
475 block = true; 475 block = true;
476 if (mActionItem) { 476 if (mActionItem) {
477 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 477 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos));
478 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); 478 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 );
479 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { 479 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) {
480 mScrollUpTimer.stop(); 480 mScrollUpTimer.stop();
481 mScrollDownTimer.stop(); 481 mScrollDownTimer.stop();
482 mActionItem->resetMove(); 482 mActionItem->resetMove();
483 placeSubCells( mActionItem ); 483 placeSubCells( mActionItem );
484 // emit startDragSignal( mActionItem->incidence() ); 484 // emit startDragSignal( mActionItem->incidence() );
485 setCursor( arrowCursor ); 485 setCursor( arrowCursor );
486 mActionItem = 0; 486 mActionItem = 0;
487 mActionType = NOP; 487 mActionType = NOP;
488 mItemMoved = 0; 488 mItemMoved = 0;
489 return true; 489 return true;
490 } 490 }
491 endItemAction(); 491 endItemAction();
492 } else if ( mActionType == SELECT ) { 492 } else if ( mActionType == SELECT ) {
493 if (me->button() == RightButton ) { 493 if (me->button() == RightButton ) {
494 494
495 } else { 495 } else {
496 endSelectAction( !blockNewEvent ); 496 endSelectAction( !blockNewEvent );
497 } 497 }
498 } 498 }
499 break; 499 break;
500 500
501 case QEvent::MouseMove: 501 case QEvent::MouseMove:
502 if (object != viewport()) { 502 if (object != viewport()) {
503 KOAgendaItem *moveItem = (KOAgendaItem *)object; 503 KOAgendaItem *moveItem = (KOAgendaItem *)object;
504 //qDebug("moveItem %d ",moveItem ); 504 //qDebug("moveItem %d ",moveItem );
505 if (!moveItem->incidence()->isReadOnly() /*&& 505 if (!moveItem->incidence()->isReadOnly() /*&&
506 !moveItem->incidence()->recurrence()->doesRecur()*/ ) 506 !moveItem->incidence()->recurrence()->doesRecur()*/ )
507 if (!mActionItem) 507 if (!mActionItem)
508 setNoActionCursor(moveItem,viewportPos); 508 setNoActionCursor(moveItem,viewportPos);
509 else { 509 else {
510 if ( block ) { 510 if ( block ) {
511 int dX, dY; 511 int dX, dY;
512 dX = startX - viewportPos.x(); 512 dX = startX - viewportPos.x();
513 if ( dX < 0 ) 513 if ( dX < 0 )
514 dX = -dX; 514 dX = -dX;
515 dY = viewportPos.y() - startY; 515 dY = viewportPos.y() - startY;
516 if ( dY < 0 ) 516 if ( dY < 0 )
517 dY = -dY; 517 dY = -dY;
518 int diff = 30; 518 int diff = 30;
519 if ( QApplication::desktop()->width() < 480 ) 519 if ( QApplication::desktop()->width() < 480 )
520 diff = 15; 520 diff = 15;
521 // qDebug(" %d %d ",dX, dY ); 521 // qDebug(" %d %d ",dX, dY );
522 if ( dX > diff || dY > diff ) { 522 if ( dX > diff || dY > diff ) {
523 block = false; 523 block = false;
524 } 524 }
525 } 525 }
526 if ( !block ) 526 if ( !block )
527 performItemAction(viewportPos); 527 performItemAction(viewportPos);
528 } 528 }
529 } else { 529 } else {
530 if ( mActionType == SELECT ) { 530 if ( mActionType == SELECT ) {
531 performSelectAction( viewportPos ); 531 performSelectAction( viewportPos );
532 } 532 }
533 } 533 }
534 break; 534 break;
535 535
536 case QEvent::MouseButtonDblClick: 536 case QEvent::MouseButtonDblClick:
537 if (object == viewport()) { 537 if (object == viewport()) {
538 selectItem(0); 538 selectItem(0);
539 int x,y; 539 int x,y;
540 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 540 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
541 int gx,gy; 541 int gx,gy;
542 contentsToGrid(x,y,gx,gy); 542 contentsToGrid(x,y,gx,gy);
543 emit newEventSignal(gx,gy); 543 emit newEventSignal(gx,gy);
544 } else { 544 } else {
545 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; 545 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object;
546 selectItem(doubleClickedItem); 546 selectItem(doubleClickedItem);
547 if ( KOPrefs::instance()->mEditOnDoubleClick ) 547 if ( KOPrefs::instance()->mEditOnDoubleClick )
548 emit editIncidenceSignal(doubleClickedItem->incidence()); 548 emit editIncidenceSignal(doubleClickedItem->incidence());
549 else 549 else
550 emit showIncidenceSignal(doubleClickedItem->incidence()); 550 emit showIncidenceSignal(doubleClickedItem->incidence());
551 } 551 }
552 break; 552 break;
553 553
554 default: 554 default:
555 break; 555 break;
556 } 556 }
557 557
558 return true; 558 return true;
559} 559}
560 560
561void KOAgenda::newItem( int item ) 561void KOAgenda::newItem( int item )
562{ 562{
563 if ( item == 1 ) { //new event 563 if ( item == 1 ) { //new event
564 newEventSignal(mStartCellX ,mStartCellY ); 564 newEventSignal(mStartCellX ,mStartCellY );
565 } else 565 } else
566 if ( item == 2 ) { //new event 566 if ( item == 2 ) { //new event
567 newTodoSignal(mStartCellX ,mStartCellY ); 567 newTodoSignal(mStartCellX ,mStartCellY );
568 } else 568 } else
569 { 569 {
570 QDate day = mSelectedDates[mStartCellX]; 570 QDate day = mSelectedDates[mStartCellX];
571 emit showDateView( item, day ); 571 emit showDateView( item, day );
572 // 3Day view 572 // 3Day view
573 // 4Week view 573 // 4Week view
574 // 5Month view 574 // 5Month view
575 // 6Journal view 575 // 6Journal view
576 } 576 }
577} 577}
578void KOAgenda::startSelectAction(QPoint viewportPos) 578void KOAgenda::startSelectAction(QPoint viewportPos)
579{ 579{
580 //emit newStartSelectSignal(); 580 //emit newStartSelectSignal();
581 581
582 mActionType = SELECT; 582 mActionType = SELECT;
583 583
584 int x,y; 584 int x,y;
585 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 585 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
586 int gx,gy; 586 int gx,gy;
587 contentsToGrid(x,y,gx,gy); 587 contentsToGrid(x,y,gx,gy);
588 588
589 mStartCellX = gx; 589 mStartCellX = gx;
590 mStartCellY = gy; 590 mStartCellY = gy;
591 mCurrentCellX = gx; 591 mCurrentCellX = gx;
592 mCurrentCellY = gy; 592 mCurrentCellY = gy;
593 593
594 // Store coordinates of old selection 594 // Store coordinates of old selection
595 int selectionX = mSelectionCellX * mGridSpacingX; 595 int selectionX = mSelectionCellX * mGridSpacingX;
596 int selectionYTop = mSelectionYTop; 596 int selectionYTop = mSelectionYTop;
597 int selectionHeight = mSelectionHeight; 597 int selectionHeight = mSelectionHeight;
598 598
599 // Store new selection 599 // Store new selection
600 mSelectionCellX = gx; 600 mSelectionCellX = gx;
601 mSelectionYTop = gy * mGridSpacingY; 601 mSelectionYTop = gy * mGridSpacingY;
602 mSelectionHeight = mGridSpacingY; 602 mSelectionHeight = mGridSpacingY;
603 603
604 // Clear old selection 604 // Clear old selection
605 repaintContents( selectionX, selectionYTop, 605 repaintContents( selectionX, selectionYTop,
606 mGridSpacingX, selectionHeight,false ); 606 mGridSpacingX, selectionHeight,false );
607 607
608 // Paint new selection 608 // Paint new selection
609 // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop, 609 // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop,
610 // mGridSpacingX, mSelectionHeight ); 610 // mGridSpacingX, mSelectionHeight );
611} 611}
612 612
613void KOAgenda::performSelectAction(QPoint viewportPos) 613void KOAgenda::performSelectAction(QPoint viewportPos)
614{ 614{
615 int x,y; 615 int x,y;
616 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 616 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
617 int gx,gy; 617 int gx,gy;
618 contentsToGrid(x,y,gx,gy); 618 contentsToGrid(x,y,gx,gy);
619 619
620 QPoint clipperPos = clipper()-> 620 QPoint clipperPos = clipper()->
621 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 621 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
622 622
623 // Scroll if cursor was moved to upper or lower end of agenda. 623 // Scroll if cursor was moved to upper or lower end of agenda.
624 if (clipperPos.y() < mScrollBorderWidth) { 624 if (clipperPos.y() < mScrollBorderWidth) {
625 mScrollUpTimer.start(mScrollDelay); 625 mScrollUpTimer.start(mScrollDelay);
626 } else if (visibleHeight() - clipperPos.y() < 626 } else if (visibleHeight() - clipperPos.y() <
627 mScrollBorderWidth) { 627 mScrollBorderWidth) {
628 mScrollDownTimer.start(mScrollDelay); 628 mScrollDownTimer.start(mScrollDelay);
629 } else { 629 } else {
630 mScrollUpTimer.stop(); 630 mScrollUpTimer.stop();
631 mScrollDownTimer.stop(); 631 mScrollDownTimer.stop();
632 } 632 }
633 633
634 if ( gy > mCurrentCellY ) { 634 if ( gy > mCurrentCellY ) {
635 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 635 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
636 636
637#if 0 637#if 0
638 // FIXME: Repaint only the newly selected region 638 // FIXME: Repaint only the newly selected region
639 repaintContents( mSelectionCellX * mGridSpacingX, 639 repaintContents( mSelectionCellX * mGridSpacingX,
640 mCurrentCellY + mGridSpacingY, 640 mCurrentCellY + mGridSpacingY,
641 mGridSpacingX, 641 mGridSpacingX,
642 mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY ); 642 mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY );
643#else 643#else
644 repaintContents( (KOGlobals::self()->reverseLayout() ? 644 repaintContents( (KOGlobals::self()->reverseLayout() ?
645 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 645 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
646 mGridSpacingX, mSelectionYTop, 646 mGridSpacingX, mSelectionYTop,
647 mGridSpacingX, mSelectionHeight , false); 647 mGridSpacingX, mSelectionHeight , false);
648#endif 648#endif
649 649
650 mCurrentCellY = gy; 650 mCurrentCellY = gy;
651 } else if ( gy < mCurrentCellY ) { 651 } else if ( gy < mCurrentCellY ) {
652 if ( gy >= mStartCellY ) { 652 if ( gy >= mStartCellY ) {
653 int selectionHeight = mSelectionHeight; 653 int selectionHeight = mSelectionHeight;
654 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 654 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
655 655
656 repaintContents( (KOGlobals::self()->reverseLayout() ? 656 repaintContents( (KOGlobals::self()->reverseLayout() ?
657 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 657 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
658 mGridSpacingX, mSelectionYTop, 658 mGridSpacingX, mSelectionYTop,
659 mGridSpacingX, selectionHeight,false ); 659 mGridSpacingX, selectionHeight,false );
660 660
661 mCurrentCellY = gy; 661 mCurrentCellY = gy;
662 } else { 662 } else {
663 } 663 }
664 } 664 }
665} 665}
666 666
667void KOAgenda::endSelectAction( bool emitNewEvent ) 667void KOAgenda::endSelectAction( bool emitNewEvent )
668{ 668{
669 mActionType = NOP; 669 mActionType = NOP;
670 mScrollUpTimer.stop(); 670 mScrollUpTimer.stop();
671 mScrollDownTimer.stop(); 671 mScrollDownTimer.stop();
672 672
673 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); 673 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
674 if ( emitNewEvent && mStartCellY < mCurrentCellY ) 674 if ( emitNewEvent && mStartCellY < mCurrentCellY )
675 emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); 675 emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
676} 676}
677 677
678void KOAgenda::startItemAction(QPoint viewportPos) 678void KOAgenda::startItemAction(QPoint viewportPos)
679{ 679{
680 int x,y; 680 int x,y;
681 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 681 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
682 int gx,gy; 682 int gx,gy;
683 contentsToGrid(x,y,gx,gy); 683 contentsToGrid(x,y,gx,gy);
684 684
685 mStartCellX = gx; 685 mStartCellX = gx;
686 mStartCellY = gy; 686 mStartCellY = gy;
687 mCurrentCellX = gx; 687 mCurrentCellX = gx;
688 mCurrentCellY = gy; 688 mCurrentCellY = gy;
689 689
690 if (mAllDayMode) { 690 if (mAllDayMode) {
691 int gridDistanceX = (x - gx * mGridSpacingX); 691 int gridDistanceX = (x - gx * mGridSpacingX);
692 if (gridDistanceX < mResizeBorderWidth && 692 if (gridDistanceX < mResizeBorderWidth &&
693 mActionItem->cellX() == mCurrentCellX) { 693 mActionItem->cellX() == mCurrentCellX) {
694 mActionType = RESIZELEFT; 694 mActionType = RESIZELEFT;
695 setCursor(sizeHorCursor); 695 setCursor(sizeHorCursor);
696 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 696 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
697 mActionItem->cellXWidth() == mCurrentCellX) { 697 mActionItem->cellXWidth() == mCurrentCellX) {
698 mActionType = RESIZERIGHT; 698 mActionType = RESIZERIGHT;
699 setCursor(sizeHorCursor); 699 setCursor(sizeHorCursor);
700 } else { 700 } else {
701 mActionType = MOVE; 701 mActionType = MOVE;
702 mActionItem->startMove(); 702 mActionItem->startMove();
703 setCursor(sizeAllCursor); 703 setCursor(sizeAllCursor);
704 } 704 }
705 } else { 705 } else {
706 int gridDistanceY = (y - gy * mGridSpacingY); 706 int gridDistanceY = (y - gy * mGridSpacingY);
707 bool allowResize = ( mActionItem->incidence()->type() != "Todo" ); 707 bool allowResize = ( mActionItem->incidence()->type() != "Todo" );
708 if (allowResize && gridDistanceY < mResizeBorderWidth && 708 if (allowResize && gridDistanceY < mResizeBorderWidth &&
709 mActionItem->cellYTop() == mCurrentCellY && 709 mActionItem->cellYTop() == mCurrentCellY &&
710 !mActionItem->firstMultiItem()) { 710 !mActionItem->firstMultiItem()) {
711 mActionType = RESIZETOP; 711 mActionType = RESIZETOP;
712 setCursor(sizeVerCursor); 712 setCursor(sizeVerCursor);
713 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 713 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
714 mActionItem->cellYBottom() == mCurrentCellY && 714 mActionItem->cellYBottom() == mCurrentCellY &&
715 !mActionItem->lastMultiItem()) { 715 !mActionItem->lastMultiItem()) {
716 mActionType = RESIZEBOTTOM; 716 mActionType = RESIZEBOTTOM;
717 setCursor(sizeVerCursor); 717 setCursor(sizeVerCursor);
718 } else { 718 } else {
719 mActionType = MOVE; 719 mActionType = MOVE;
720 mActionItem->startMove(); 720 mActionItem->startMove();
721 setCursor(sizeAllCursor); 721 setCursor(sizeAllCursor);
722 } 722 }
723 } 723 }
724} 724}
725 725
726void KOAgenda::performItemAction(QPoint viewportPos) 726void KOAgenda::performItemAction(QPoint viewportPos)
727{ 727{
728// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 728// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
729// QPoint point = viewport()->mapToGlobal(viewportPos); 729// QPoint point = viewport()->mapToGlobal(viewportPos);
730// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 730// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
731// point = clipper()->mapFromGlobal(point); 731// point = clipper()->mapFromGlobal(point);
732// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 732// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
733// kdDebug() << "visible height: " << visibleHeight() << endl; 733// kdDebug() << "visible height: " << visibleHeight() << endl;
734 int x,y; 734 int x,y;
735 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 735 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
736// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 736// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
737 int gx,gy; 737 int gx,gy;
738 contentsToGrid(x,y,gx,gy); 738 contentsToGrid(x,y,gx,gy);
739 QPoint clipperPos = clipper()-> 739 QPoint clipperPos = clipper()->
740 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 740 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
741 741
742 // Cursor left active agenda area. 742 // Cursor left active agenda area.
743 // This starts a drag. 743 // This starts a drag.
744 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/ 744 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/
745 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) { 745 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) {
746 if ( mActionType == MOVE ) { 746 if ( mActionType == MOVE ) {
747 mScrollUpTimer.stop(); 747 mScrollUpTimer.stop();
748 mScrollDownTimer.stop(); 748 mScrollDownTimer.stop();
749 mActionItem->resetMove(); 749 mActionItem->resetMove();
750 placeSubCells( mActionItem ); 750 placeSubCells( mActionItem );
751 // emit startDragSignal( mActionItem->incidence() ); 751 // emit startDragSignal( mActionItem->incidence() );
752 setCursor( arrowCursor ); 752 setCursor( arrowCursor );
753 mActionItem = 0; 753 mActionItem = 0;
754 mActionType = NOP; 754 mActionType = NOP;
755 mItemMoved = 0; 755 mItemMoved = 0;
756 return; 756 return;
757 } 757 }
758 } else { 758 } else {
759 switch ( mActionType ) { 759 switch ( mActionType ) {
760 case MOVE: 760 case MOVE:
761 setCursor( sizeAllCursor ); 761 setCursor( sizeAllCursor );
762 break; 762 break;
763 case RESIZETOP: 763 case RESIZETOP:
764 case RESIZEBOTTOM: 764 case RESIZEBOTTOM:
765 setCursor( sizeVerCursor ); 765 setCursor( sizeVerCursor );
766 break; 766 break;
767 case RESIZELEFT: 767 case RESIZELEFT:
768 case RESIZERIGHT: 768 case RESIZERIGHT:
769 setCursor( sizeHorCursor ); 769 setCursor( sizeHorCursor );
770 break; 770 break;
771 default: 771 default:
772 setCursor( arrowCursor ); 772 setCursor( arrowCursor );
773 } 773 }
774 } 774 }
775 775
776 // Scroll if item was moved to upper or lower end of agenda. 776 // Scroll if item was moved to upper or lower end of agenda.
777 if (clipperPos.y() < mScrollBorderWidth) { 777 if (clipperPos.y() < mScrollBorderWidth) {
778 mScrollUpTimer.start(mScrollDelay); 778 mScrollUpTimer.start(mScrollDelay);
779 } else if (visibleHeight() - clipperPos.y() < 779 } else if (visibleHeight() - clipperPos.y() <
780 mScrollBorderWidth) { 780 mScrollBorderWidth) {
781 mScrollDownTimer.start(mScrollDelay); 781 mScrollDownTimer.start(mScrollDelay);
782 } else { 782 } else {
783 mScrollUpTimer.stop(); 783 mScrollUpTimer.stop();
784 mScrollDownTimer.stop(); 784 mScrollDownTimer.stop();
785 } 785 }
786 786
787 // Move or resize item if necessary 787 // Move or resize item if necessary
788 if (mCurrentCellX != gx || mCurrentCellY != gy) { 788 if (mCurrentCellX != gx || mCurrentCellY != gy) {
789 mItemMoved = true; 789 mItemMoved = true;
790 mActionItem->raise(); 790 mActionItem->raise();
791 if (mActionType == MOVE) { 791 if (mActionType == MOVE) {
792 // Move all items belonging to a multi item 792 // Move all items belonging to a multi item
793 KOAgendaItem *moveItem = mActionItem->firstMultiItem(); 793 KOAgendaItem *moveItem = mActionItem->firstMultiItem();
794 bool isMultiItem = (moveItem || mActionItem->lastMultiItem()); 794 bool isMultiItem = (moveItem || mActionItem->lastMultiItem());
795 if (!moveItem) moveItem = mActionItem; 795 if (!moveItem) moveItem = mActionItem;
796 while (moveItem) { 796 while (moveItem) {
797 int dy; 797 int dy;
798 if (isMultiItem) dy = 0; 798 if (isMultiItem) dy = 0;
799 else dy = gy - mCurrentCellY; 799 else dy = gy - mCurrentCellY;
800 moveItem->moveRelative(gx - mCurrentCellX,dy); 800 moveItem->moveRelative(gx - mCurrentCellX,dy);
801 int x,y; 801 int x,y;
802 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y); 802 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y);
803 moveItem->resize(mGridSpacingX * moveItem->cellWidth(), 803 moveItem->resize(mGridSpacingX * moveItem->cellWidth(),
804 mGridSpacingY * moveItem->cellHeight()); 804 mGridSpacingY * moveItem->cellHeight());
805 moveChild(moveItem,x,y); 805 moveChild(moveItem,x,y);
806 moveItem = moveItem->nextMultiItem(); 806 moveItem = moveItem->nextMultiItem();
807 } 807 }
808 } else if (mActionType == RESIZETOP) { 808 } else if (mActionType == RESIZETOP) {
809 if (mCurrentCellY <= mActionItem->cellYBottom()) { 809 if (mCurrentCellY <= mActionItem->cellYBottom()) {
810 mActionItem->expandTop(gy - mCurrentCellY); 810 mActionItem->expandTop(gy - mCurrentCellY);
811 mActionItem->resize(mActionItem->width(), 811 mActionItem->resize(mActionItem->width(),
812 mGridSpacingY * mActionItem->cellHeight()); 812 mGridSpacingY * mActionItem->cellHeight());
813 int x,y; 813 int x,y;
814 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y); 814 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y);
815 //moveChild(mActionItem,childX(mActionItem),y); 815 //moveChild(mActionItem,childX(mActionItem),y);
816 QScrollView::moveChild( mActionItem,childX(mActionItem),y ); 816 QScrollView::moveChild( mActionItem,childX(mActionItem),y );
817 } 817 }
818 } else if (mActionType == RESIZEBOTTOM) { 818 } else if (mActionType == RESIZEBOTTOM) {
819 if (mCurrentCellY >= mActionItem->cellYTop()) { 819 if (mCurrentCellY >= mActionItem->cellYTop()) {
820 mActionItem->expandBottom(gy - mCurrentCellY); 820 mActionItem->expandBottom(gy - mCurrentCellY);
821 mActionItem->resize(mActionItem->width(), 821 mActionItem->resize(mActionItem->width(),
822 mGridSpacingY * mActionItem->cellHeight()); 822 mGridSpacingY * mActionItem->cellHeight());
823 } 823 }
824 } else if (mActionType == RESIZELEFT) { 824 } else if (mActionType == RESIZELEFT) {
825 if (mCurrentCellX <= mActionItem->cellXWidth()) { 825 if (mCurrentCellX <= mActionItem->cellXWidth()) {
826 mActionItem->expandLeft(gx - mCurrentCellX); 826 mActionItem->expandLeft(gx - mCurrentCellX);
827 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 827 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
828 mActionItem->height()); 828 mActionItem->height());
829 int x,y; 829 int x,y;
830 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y); 830 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y);
831 moveChild(mActionItem,x,childY(mActionItem)); 831 moveChild(mActionItem,x,childY(mActionItem));
832 } 832 }
833 } else if (mActionType == RESIZERIGHT) { 833 } else if (mActionType == RESIZERIGHT) {
834 if (mCurrentCellX >= mActionItem->cellX()) { 834 if (mCurrentCellX >= mActionItem->cellX()) {
835 mActionItem->expandRight(gx - mCurrentCellX); 835 mActionItem->expandRight(gx - mCurrentCellX);
836 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 836 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
837 mActionItem->height()); 837 mActionItem->height());
838 } 838 }
839 } 839 }
840 mCurrentCellX = gx; 840 mCurrentCellX = gx;
841 mCurrentCellY = gy; 841 mCurrentCellY = gy;
842 } 842 }
843} 843}
844 844
845void KOAgenda::endItemAction() 845void KOAgenda::endItemAction()
846{ 846{
847 847
848 if ( mItemMoved ) { 848 if ( mItemMoved ) {
849 KOAgendaItem *placeItem = mActionItem->firstMultiItem(); 849 KOAgendaItem *placeItem = mActionItem->firstMultiItem();
850 if ( !placeItem ) { 850 if ( !placeItem ) {
851 placeItem = mActionItem; 851 placeItem = mActionItem;
852 } 852 }
853 if ( placeItem->incidence()->recurrence()->doesRecur() ) { 853 if ( placeItem->incidence()->recurrence()->doesRecur() ) {
854 Incidence* oldInc = placeItem->incidence(); 854 Incidence* oldInc = placeItem->incidence();
855 placeItem->recreateIncidence(); 855 placeItem->recreateIncidence();
856 emit addToCalSignal(placeItem->incidence(), oldInc ); 856 emit addToCalSignal(placeItem->incidence(), oldInc );
857 } 857 }
858 int type = mActionType; 858 int type = mActionType;
859 if ( mAllDayMode ) 859 if ( mAllDayMode )
860 type = -1; 860 type = -1;
861 KOAgendaItem *modifiedItem = placeItem; 861 KOAgendaItem *modifiedItem = placeItem;
862 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */); 862 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */);
863 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems(); 863 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems();
864 KOAgendaItem *item; 864 KOAgendaItem *item;
865 865
866 if ( placeItem->incidence()->type() == "Todo" ) { 866 if ( placeItem->incidence()->type() == "Todo" ) {
867 mSelectedItem = 0; 867 mSelectedItem = 0;
868 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth()); 868 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth());
869 modifiedItem->mLastMoveXPos = mCurrentCellX; 869 modifiedItem->mLastMoveXPos = mCurrentCellX;
870 emit itemModified( modifiedItem, mActionType ); 870 emit itemModified( modifiedItem, mActionType );
871 } 871 }
872 else { 872 else {
873#if 0 873#if 0
874 for ( item=oldconflictItems.first(); item != 0; 874 for ( item=oldconflictItems.first(); item != 0;
875 item=oldconflictItems.next() ) { 875 item=oldconflictItems.next() ) {
876 placeSubCells(item); 876 placeSubCells(item);
877 } 877 }
878 while ( placeItem ) { 878 while ( placeItem ) {
879 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 879 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
880 placeSubCells( placeItem ); 880 placeSubCells( placeItem );
881 placeItem = placeItem->nextMultiItem(); 881 placeItem = placeItem->nextMultiItem();
882 } 882 }
883#endif 883#endif
884 884
885 globalFlagBlockAgendaItemPaint = 1; 885 globalFlagBlockAgendaItemPaint = 1;
886 for ( item=oldconflictItems.first(); item != 0; 886 for ( item=oldconflictItems.first(); item != 0;
887 item=oldconflictItems.next() ) { 887 item=oldconflictItems.next() ) {
888 placeSubCells(item); 888 placeSubCells(item);
889 } 889 }
890 while ( placeItem ) { 890 while ( placeItem ) {
891 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 891 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
892 oldconflictItems = placeItem->conflictItems(); 892 oldconflictItems = placeItem->conflictItems();
893 for ( item=oldconflictItems.first(); item != 0; 893 for ( item=oldconflictItems.first(); item != 0;
894 item=oldconflictItems.next() ) { 894 item=oldconflictItems.next() ) {
895 placeSubCells(item); 895 placeSubCells(item);
896 } 896 }
897 placeSubCells( placeItem ); 897 placeSubCells( placeItem );
898 placeItem = placeItem->nextMultiItem(); 898 placeItem = placeItem->nextMultiItem();
899 } 899 }
900 globalFlagBlockAgendaItemPaint = 0; 900 globalFlagBlockAgendaItemPaint = 0;
901 for ( item=oldconflictItems.first(); item != 0; 901 for ( item=oldconflictItems.first(); item != 0;
902 item=oldconflictItems.next() ) { 902 item=oldconflictItems.next() ) {
903 globalFlagBlockAgendaItemUpdate = 0; 903 globalFlagBlockAgendaItemUpdate = 0;
904 item->repaintMe(); 904 item->repaintMe();
905 globalFlagBlockAgendaItemUpdate = 1; 905 globalFlagBlockAgendaItemUpdate = 1;
906 item->repaint( false ); 906 item->repaint( false );
907 } 907 }
908 placeItem = modifiedItem; 908 placeItem = modifiedItem;
909 909
910 while ( placeItem ) { 910 while ( placeItem ) {
911 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 911 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
912 globalFlagBlockAgendaItemUpdate = 0; 912 globalFlagBlockAgendaItemUpdate = 0;
913 placeItem->repaintMe(); 913 placeItem->repaintMe();
914 globalFlagBlockAgendaItemUpdate = 1; 914 globalFlagBlockAgendaItemUpdate = 1;
915 placeItem->repaint(false); 915 placeItem->repaint(false);
916 placeItem = placeItem->nextMultiItem(); 916 placeItem = placeItem->nextMultiItem();
917 } 917 }
918 emit itemModified( modifiedItem, mActionType ); 918 emit itemModified( modifiedItem, mActionType );
919 919
920 920
921 placeItem = modifiedItem; 921 placeItem = modifiedItem;
922 while ( placeItem ) { 922 while ( placeItem ) {
923 oldconflictItems = placeItem->conflictItems(); 923 oldconflictItems = placeItem->conflictItems();
924 for ( item=oldconflictItems.first(); item != 0; 924 for ( item=oldconflictItems.first(); item != 0;
925 item=oldconflictItems.next() ) { 925 item=oldconflictItems.next() ) {
926 placeSubCells(item); 926 placeSubCells(item);
927 } 927 }
928 placeSubCells( placeItem ); 928 placeSubCells( placeItem );
929 placeItem = placeItem->nextMultiItem(); 929 placeItem = placeItem->nextMultiItem();
930 930
931 } 931 }
932 placeItem = modifiedItem; 932 placeItem = modifiedItem;
933 while ( placeItem ) { 933 while ( placeItem ) {
934 oldconflictItems = placeItem->conflictItems(); 934 oldconflictItems = placeItem->conflictItems();
935 for ( item=oldconflictItems.first(); item != 0; 935 for ( item=oldconflictItems.first(); item != 0;
936 item=oldconflictItems.next() ) { 936 item=oldconflictItems.next() ) {
937 globalFlagBlockAgendaItemUpdate = 0; 937 globalFlagBlockAgendaItemUpdate = 0;
938 item->repaintMe(); 938 item->repaintMe();
939 globalFlagBlockAgendaItemUpdate = 1; 939 globalFlagBlockAgendaItemUpdate = 1;
940 item->repaint(false); 940 item->repaint(false);
941 } 941 }
942 placeItem = placeItem->nextMultiItem(); 942 placeItem = placeItem->nextMultiItem();
943 } 943 }
944 /* 944 /*
945 945
946 oldconflictItems = modifiedItem->conflictItems(); 946 oldconflictItems = modifiedItem->conflictItems();
947 for ( item=oldconflictItems.first(); item != 0; 947 for ( item=oldconflictItems.first(); item != 0;
948 item=oldconflictItems.next() ) { 948 item=oldconflictItems.next() ) {
949 globalFlagBlockAgendaItemUpdate = 0; 949 globalFlagBlockAgendaItemUpdate = 0;
950 item->paintMe(false); 950 item->paintMe(false);
951 globalFlagBlockAgendaItemUpdate = 1; 951 globalFlagBlockAgendaItemUpdate = 1;
952 item->repaint(false); 952 item->repaint(false);
953 } 953 }
954 */ 954 */
955 955
956 956
957 } 957 }
958 958
959 } 959 }
960 960
961 mScrollUpTimer.stop(); 961 mScrollUpTimer.stop();
962 mScrollDownTimer.stop(); 962 mScrollDownTimer.stop();
963 setCursor( arrowCursor ); 963 setCursor( arrowCursor );
964 mActionItem = 0; 964 mActionItem = 0;
965 mActionType = NOP; 965 mActionType = NOP;
966 mItemMoved = 0; 966 mItemMoved = 0;
967 967
968} 968}
969 969
970void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos) 970void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos)
971{ 971{
972// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 972// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
973// QPoint point = viewport()->mapToGlobal(viewportPos); 973// QPoint point = viewport()->mapToGlobal(viewportPos);
974// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 974// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
975// point = clipper()->mapFromGlobal(point); 975// point = clipper()->mapFromGlobal(point);
976// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 976// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
977 977
978 int x,y; 978 int x,y;
979 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 979 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
980// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 980// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
981 int gx,gy; 981 int gx,gy;
982 contentsToGrid(x,y,gx,gy); 982 contentsToGrid(x,y,gx,gy);
983 983
984 // Change cursor to resize cursor if appropriate 984 // Change cursor to resize cursor if appropriate
985 if (mAllDayMode) { 985 if (mAllDayMode) {
986 int gridDistanceX = (x - gx * mGridSpacingX); 986 int gridDistanceX = (x - gx * mGridSpacingX);
987 if (gridDistanceX < mResizeBorderWidth && 987 if (gridDistanceX < mResizeBorderWidth &&
988 moveItem->cellX() == gx) { 988 moveItem->cellX() == gx) {
989 setCursor(sizeHorCursor); 989 setCursor(sizeHorCursor);
990 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 990 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
991 moveItem->cellXWidth() == gx) { 991 moveItem->cellXWidth() == gx) {
992 setCursor(sizeHorCursor); 992 setCursor(sizeHorCursor);
993 } else { 993 } else {
994 setCursor(arrowCursor); 994 setCursor(arrowCursor);
995 } 995 }
996 } else { 996 } else {
997 int gridDistanceY = (y - gy * mGridSpacingY); 997 int gridDistanceY = (y - gy * mGridSpacingY);
998 if (gridDistanceY < mResizeBorderWidth && 998 if (gridDistanceY < mResizeBorderWidth &&
999 moveItem->cellYTop() == gy && 999 moveItem->cellYTop() == gy &&
1000 !moveItem->firstMultiItem()) { 1000 !moveItem->firstMultiItem()) {
1001 setCursor(sizeVerCursor); 1001 setCursor(sizeVerCursor);
1002 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 1002 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
1003 moveItem->cellYBottom() == gy && 1003 moveItem->cellYBottom() == gy &&
1004 !moveItem->lastMultiItem()) { 1004 !moveItem->lastMultiItem()) {
1005 setCursor(sizeVerCursor); 1005 setCursor(sizeVerCursor);
1006 } else { 1006 } else {
1007 setCursor(arrowCursor); 1007 setCursor(arrowCursor);
1008 } 1008 }
1009 } 1009 }
1010} 1010}
1011 1011
1012 1012
1013/* 1013/*
1014 Place item in cell and take care that multiple items using the same cell do 1014 Place item in cell and take care that multiple items using the same cell do
1015 not overlap. This method is not yet optimal. It doesn´t use the maximum space 1015 not overlap. This method is not yet optimal. It doesn´t use the maximum space
1016 it can get in all cases. 1016 it can get in all cases.
1017 At the moment the method has a bug: When an item is placed only the sub cell 1017 At the moment the method has a bug: When an item is placed only the sub cell
1018 widths of the items are changed, which are within the Y region the item to 1018 widths of the items are changed, which are within the Y region the item to
1019 place spans. When the sub cell width change of one of this items affects a 1019 place spans. When the sub cell width change of one of this items affects a
1020 cell, where other items are, which do not overlap in Y with the item to place, 1020 cell, where other items are, which do not overlap in Y with the item to place,
1021 the display gets corrupted, although the corruption looks quite nice. 1021 the display gets corrupted, although the corruption looks quite nice.
1022*/ 1022*/
1023void KOAgenda::placeSubCells(KOAgendaItem *placeItem) 1023void KOAgenda::placeSubCells(KOAgendaItem *placeItem)
1024{ 1024{
1025 1025
1026 QPtrList<KOAgendaItem> conflictItems; 1026 QPtrList<KOAgendaItem> conflictItems;
1027 int maxSubCells = 0; 1027 int maxSubCells = 0;
1028 QIntDict<KOAgendaItem> subCellDict(5); 1028 QIntDict<KOAgendaItem> subCellDict(5);
1029 1029
1030 KOAgendaItem *item; 1030 KOAgendaItem *item;
1031 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1031 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1032 if (item != placeItem) { 1032 if (item != placeItem) {
1033 if (placeItem->cellX() <= item->cellXWidth() && 1033 if (placeItem->cellX() <= item->cellXWidth() &&
1034 placeItem->cellXWidth() >= item->cellX()) { 1034 placeItem->cellXWidth() >= item->cellX()) {
1035 if ((placeItem->cellYTop() <= item->cellYBottom()) && 1035 if ((placeItem->cellYTop() <= item->cellYBottom()) &&
1036 (placeItem->cellYBottom() >= item->cellYTop())) { 1036 (placeItem->cellYBottom() >= item->cellYTop())) {
1037 conflictItems.append(item); 1037 conflictItems.append(item);
1038 if (item->subCells() > maxSubCells) 1038 if (item->subCells() > maxSubCells)
1039 maxSubCells = item->subCells(); 1039 maxSubCells = item->subCells();
1040 subCellDict.insert(item->subCell(),item); 1040 subCellDict.insert(item->subCell(),item);
1041 } 1041 }
1042 } 1042 }
1043 } 1043 }
1044 } 1044 }
1045 1045
1046 if (conflictItems.count() > 0) { 1046 if (conflictItems.count() > 0) {
1047 // Look for unused sub cell and insert item 1047 // Look for unused sub cell and insert item
1048 int i; 1048 int i;
1049 for(i=0;i<maxSubCells;++i) { 1049 for(i=0;i<maxSubCells;++i) {
1050 if (!subCellDict.find(i)) { 1050 if (!subCellDict.find(i)) {
1051 placeItem->setSubCell(i); 1051 placeItem->setSubCell(i);
1052 break; 1052 break;
1053 } 1053 }
1054 } 1054 }
1055 if (i == maxSubCells) { 1055 if (i == maxSubCells) {
1056 placeItem->setSubCell(maxSubCells); 1056 placeItem->setSubCell(maxSubCells);
1057 maxSubCells++; // add new item to number of sub cells 1057 maxSubCells++; // add new item to number of sub cells
1058 } 1058 }
1059 1059
1060 // Prepare for sub cell geometry adjustment 1060 // Prepare for sub cell geometry adjustment
1061 int newSubCellWidth; 1061 int newSubCellWidth;
1062 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells; 1062 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells;
1063 else newSubCellWidth = mGridSpacingX / maxSubCells; 1063 else newSubCellWidth = mGridSpacingX / maxSubCells;
1064 conflictItems.append(placeItem); 1064 conflictItems.append(placeItem);
1065 1065
1066 1066
1067 // Adjust sub cell geometry of all items 1067 // Adjust sub cell geometry of all items
1068 for ( item=conflictItems.first(); item != 0; 1068 for ( item=conflictItems.first(); item != 0;
1069 item=conflictItems.next() ) { 1069 item=conflictItems.next() ) {
1070 item->setSubCells(maxSubCells); 1070 item->setSubCells(maxSubCells);
1071 if (mAllDayMode) { 1071 if (mAllDayMode) {
1072 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); 1072 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth);
1073 } else { 1073 } else {
1074 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); 1074 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY);
1075 } 1075 }
1076 int x,y; 1076 int x,y;
1077 gridToContents(item->cellX(),item->cellYTop(),x,y); 1077 gridToContents(item->cellX(),item->cellYTop(),x,y);
1078 if (mAllDayMode) { 1078 if (mAllDayMode) {
1079 y += item->subCell() * newSubCellWidth; 1079 y += item->subCell() * newSubCellWidth;
1080 } else { 1080 } else {
1081 x += item->subCell() * newSubCellWidth; 1081 x += item->subCell() * newSubCellWidth;
1082 } 1082 }
1083 moveChild(item,x,y); 1083 moveChild(item,x,y);
1084 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y); 1084 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y);
1085 //item->updateItem(); 1085 //item->updateItem();
1086 } 1086 }
1087 1087
1088 } else { 1088 } else {
1089 placeItem->setSubCell(0); 1089 placeItem->setSubCell(0);
1090 placeItem->setSubCells(1); 1090 placeItem->setSubCells(1);
1091 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY); 1091 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY);
1092 else placeItem->resize(mGridSpacingX,placeItem->height()); 1092 else placeItem->resize(mGridSpacingX,placeItem->height());
1093 int x,y; 1093 int x,y;
1094 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y); 1094 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y);
1095 moveChild(placeItem,x,y); 1095 moveChild(placeItem,x,y);
1096 } 1096 }
1097 placeItem->setConflictItems(conflictItems); 1097 placeItem->setConflictItems(conflictItems);
1098 // for ( item=conflictItems.first(); item != 0; 1098 // for ( item=conflictItems.first(); item != 0;
1099// item=conflictItems.next() ) { 1099// item=conflictItems.next() ) {
1100// //item->updateItem(); 1100// //item->updateItem();
1101// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() ); 1101// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() );
1102// } 1102// }
1103// placeItem->updateItem(); 1103// placeItem->updateItem();
1104} 1104}
1105 1105
1106void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch) 1106void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
1107{ 1107{
1108 if ( globalFlagBlockAgenda ) 1108 if ( globalFlagBlockAgenda )
1109 return; 1109 return;
1110 //qDebug("KOAgenda::drawContents "); 1110 //qDebug("KOAgenda::drawContents ");
1111 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) 1111 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() )
1112 ;//drawContentsToPainter(); 1112 ;//drawContentsToPainter();
1113 1113
1114 QPaintDevice* pd = p->device(); 1114 QPaintDevice* pd = p->device();
1115 p->end(); 1115 p->end();
1116 int vx, vy; 1116 int vx, vy;
1117 int selectionX = KOGlobals::self()->reverseLayout() ? 1117 int selectionX = KOGlobals::self()->reverseLayout() ?
1118 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1118 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1119 mSelectionCellX * mGridSpacingX; 1119 mSelectionCellX * mGridSpacingX;
1120 contentsToViewport ( cx, cy, vx,vy); 1120 contentsToViewport ( cx, cy, vx,vy);
1121 // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ; 1121 // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ;
1122 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) 1122 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) )
1123 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); 1123 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP);
1124 1124
1125 if ( mSelectionHeight > 0 ) { 1125 if ( mSelectionHeight > 0 ) {
1126 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); 1126 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight );
1127 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1127 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1128 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1128 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1129 contentsToViewport ( selectionX, mSelectionYTop, vx,vy); 1129 contentsToViewport ( selectionX, mSelectionYTop, vx,vy);
1130 bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); 1130 bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP);
1131 } 1131 }
1132 } 1132 }
1133 //qDebug("btbl "); 1133 //qDebug("btbl ");
1134 p->begin( pd ); 1134 p->begin( pd );
1135 //qDebug("end "); 1135 //qDebug("end ");
1136} 1136}
1137 1137
1138void KOAgenda::finishUpdate() 1138void KOAgenda::finishUpdate()
1139{ 1139{
1140 1140
1141 KOAgendaItem *item; 1141 KOAgendaItem *item;
1142 globalFlagBlockAgendaItemPaint = 1; 1142 globalFlagBlockAgendaItemPaint = 1;
1143 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1143 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1144 if ( !item->isVisible() ) 1144 if ( !item->isVisible() )
1145 item->show(); 1145 item->show();
1146 1146
1147 } 1147 }
1148 globalFlagBlockAgendaItemUpdate = 0; 1148 globalFlagBlockAgendaItemUpdate = 0;
1149 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1149 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1150 item->repaintMe( ); 1150 item->repaintMe( );
1151 } 1151 }
1152 globalFlagBlockAgendaItemUpdate = 1; 1152 globalFlagBlockAgendaItemUpdate = 1;
1153 qApp->processEvents(); 1153 qApp->processEvents();
1154 globalFlagBlockAgendaItemPaint = 0; 1154 globalFlagBlockAgendaItemPaint = 0;
1155 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1155 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1156 item->repaint( false ); 1156 item->repaint( false );
1157 } 1157 }
1158 1158
1159} 1159}
1160 1160
1161/* 1161/*
1162 Draw grid in the background of the agenda. 1162 Draw grid in the background of the agenda.
1163*/ 1163*/
1164void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch) 1164void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch)
1165{ 1165{
1166 1166
1167 1167
1168 if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask ) 1168 if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask )
1169 return; 1169 return;
1170 if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 ) 1170 if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 )
1171 return; 1171 return;
1172 int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight(); 1172 int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight();
1173 if ( ch < 1 ) 1173 if ( ch < 1 )
1174 ch = 1; 1174 ch = 1;
1175 if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) { 1175 if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) {
1176 mPaintPixmap.resize( contentsWidth()+42, ch ); 1176 mPaintPixmap.resize( contentsWidth()+42, ch );
1177 } 1177 }
1178 mCurPixWid = contentsWidth(); 1178 mCurPixWid = contentsWidth();
1179 mCurPixHei = ch; 1179 mCurPixHei = ch;
1180 if ( mHighlightPixmap.width() < mGridSpacingX-1 || mHighlightPixmap.height() < ch ) { 1180 if ( mHighlightPixmap.width() < mGridSpacingX-1 || mHighlightPixmap.height() < ch ) {
1181 mHighlightPixmap.resize( mGridSpacingX-1, ch ); 1181 mHighlightPixmap.resize( mGridSpacingX-1, ch );
1182 mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor ); 1182 mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor );
1183 } 1183 }
1184 mPixPainter.begin( &mPaintPixmap) ; 1184 mPixPainter.begin( &mPaintPixmap) ;
1185 //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() ); 1185 //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() );
1186 QPainter * p ; 1186 QPainter * p ;
1187 if (paint == 0) { 1187 if (paint == 0) {
1188 mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor); 1188 mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor);
1189 p = &mPixPainter; 1189 p = &mPixPainter;
1190 } 1190 }
1191 else 1191 else
1192 p = paint ; 1192 p = paint ;
1193 // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch); 1193 // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch);
1194 1194
1195 //--cx;++cw; 1195 //--cx;++cw;
1196 int lGridSpacingY = mGridSpacingY*2; 1196 int lGridSpacingY = mGridSpacingY*2;
1197 int selDay; 1197 int selDay;
1198 if ( !backgroundOnly ) 1198 if ( !backgroundOnly )
1199 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) 1199 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay)
1200 { 1200 {
1201 if ( mSelectedDates[selDay] == QDateTime::currentDateTime ().date() && KOPrefs::instance()->mHighlightCurrentDay) { 1201 if ( mSelectedDates[selDay] == QDateTime::currentDateTime ().date() && KOPrefs::instance()->mHighlightCurrentDay) {
1202 int x1 = cx; 1202 int x1 = cx;
1203 int y1 = 0; 1203 int y1 = 0;
1204 if (y1 < cy) y1 = cy; 1204 if (y1 < cy) y1 = cy;
1205 int x2 = cx+cw-1; 1205 int x2 = cx+cw-1;
1206 int y2 = contentsHeight(); 1206 int y2 = contentsHeight();
1207 if (y2 > cy+ch-1) y2=cy+ch-1; 1207 if (y2 > cy+ch-1) y2=cy+ch-1;
1208 if (x2 >= x1 && y2 >= y1) { 1208 if (x2 >= x1 && y2 >= y1) {
1209 int gxStart = selDay; 1209 int gxStart = selDay;
1210 int gxEnd = gxStart ; 1210 int gxEnd = gxStart ;
1211 int xStart = KOGlobals::self()->reverseLayout() ? 1211 int xStart = KOGlobals::self()->reverseLayout() ?
1212 (mColumns - 1 - gxStart)*mGridSpacingX : 1212 (mColumns - 1 - gxStart)*mGridSpacingX :
1213 gxStart*mGridSpacingX; 1213 gxStart*mGridSpacingX;
1214 if (xStart < x1) xStart = x1; 1214 if (xStart < x1) xStart = x1;
1215 int xEnd = KOGlobals::self()->reverseLayout() ? 1215 int xEnd = KOGlobals::self()->reverseLayout() ?
1216 (mColumns - gxStart)*mGridSpacingX-1 : 1216 (mColumns - gxStart)*mGridSpacingX-1 :
1217 (gxStart+1)*mGridSpacingX-1; 1217 (gxStart+1)*mGridSpacingX-1;
1218 if (xEnd > x2) xEnd = x2; 1218 if (xEnd > x2) xEnd = x2;
1219 if ( KOPrefs::instance()->mUseHighlightLightColor ) 1219 if ( KOPrefs::instance()->mUseHighlightLightColor )
1220 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1220 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1221 KOPrefs::instance()->mAgendaBgColor.light()); 1221 KOPrefs::instance()->mAgendaBgColor.light());
1222 else 1222 else
1223 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1223 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1224 KOPrefs::instance()->mAgendaBgColor.dark()); 1224 KOPrefs::instance()->mAgendaBgColor.dark());
1225 1225
1226 } 1226 }
1227 } 1227 }
1228 } 1228 }
1229 // Highlight working hours 1229 // Highlight working hours
1230 1230
1231 if ( !backgroundOnly ) 1231 if ( !backgroundOnly )
1232 if (mWorkingHoursEnable) { 1232 if (mWorkingHoursEnable) {
1233 int x1 = cx; 1233 int x1 = cx;
1234 int y1 = mWorkingHoursYTop; 1234 int y1 = mWorkingHoursYTop;
1235 if (y1 < cy) y1 = cy; 1235 if (y1 < cy) y1 = cy;
1236 int x2 = cx+cw-1; 1236 int x2 = cx+cw-1;
1237 // int x2 = mGridSpacingX * 5 - 1; 1237 // int x2 = mGridSpacingX * 5 - 1;
1238 // if (x2 > cx+cw-1) x2 = cx + cw - 1; 1238 // if (x2 > cx+cw-1) x2 = cx + cw - 1;
1239 int y2 = mWorkingHoursYBottom; 1239 int y2 = mWorkingHoursYBottom;
1240 if (y2 > cy+ch-1) y2=cy+ch-1; 1240 if (y2 > cy+ch-1) y2=cy+ch-1;
1241 1241
1242 if (x2 >= x1 && y2 >= y1) { 1242 if (x2 >= x1 && y2 >= y1) {
1243 // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX ); 1243 // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX );
1244 int gxStart = x1/mGridSpacingX; 1244 int gxStart = x1/mGridSpacingX;
1245 int gxEnd = x2/mGridSpacingX; 1245 int gxEnd = x2/mGridSpacingX;
1246 while(gxStart <= gxEnd) { 1246 while(gxStart <= gxEnd) {
1247 if (gxStart < int(mHolidayMask->count()) && 1247 if (gxStart < int(mHolidayMask->count()) &&
1248 !mHolidayMask->at(gxStart)) { 1248 !mHolidayMask->at(gxStart)) {
1249 int xStart = KOGlobals::self()->reverseLayout() ? 1249 int xStart = KOGlobals::self()->reverseLayout() ?
1250 (mColumns - 1 - gxStart)*mGridSpacingX : 1250 (mColumns - 1 - gxStart)*mGridSpacingX :
1251 gxStart*mGridSpacingX; 1251 gxStart*mGridSpacingX;
1252 if (xStart < x1) xStart = x1; 1252 if (xStart < x1) xStart = x1;
1253 int xEnd = KOGlobals::self()->reverseLayout() ? 1253 int xEnd = KOGlobals::self()->reverseLayout() ?
1254 (mColumns - gxStart)*mGridSpacingX-1 : 1254 (mColumns - gxStart)*mGridSpacingX-1 :
1255 (gxStart+1)*mGridSpacingX-1; 1255 (gxStart+1)*mGridSpacingX-1;
1256 if (xEnd > x2) xEnd = x2; 1256 if (xEnd > x2) xEnd = x2;
1257 if ( mSelectedDates[gxStart] == QDateTime::currentDateTime ().date()&& KOPrefs::instance()->mHighlightCurrentDay ) { 1257 if ( mSelectedDates[gxStart] == QDateTime::currentDateTime ().date()&& KOPrefs::instance()->mHighlightCurrentDay ) {
1258 if ( KOPrefs::instance()->mUseHighlightLightColor ) 1258 if ( KOPrefs::instance()->mUseHighlightLightColor )
1259 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1259 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1260 KOPrefs::instance()->mWorkingHoursColor.light()); 1260 KOPrefs::instance()->mWorkingHoursColor.light());
1261 else 1261 else
1262 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1262 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1263 KOPrefs::instance()->mWorkingHoursColor.dark()); 1263 KOPrefs::instance()->mWorkingHoursColor.dark());
1264 } else { 1264 } else {
1265 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1265 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1266 KOPrefs::instance()->mWorkingHoursColor); 1266 KOPrefs::instance()->mWorkingHoursColor);
1267 } 1267 }
1268 } 1268 }
1269 ++gxStart; 1269 ++gxStart;
1270 } 1270 }
1271 } 1271 }
1272 } 1272 }
1273 /* 1273 /*
1274 int selectionX = KOGlobals::self()->reverseLayout() ? 1274 int selectionX = KOGlobals::self()->reverseLayout() ?
1275 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1275 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1276 mSelectionCellX * mGridSpacingX; 1276 mSelectionCellX * mGridSpacingX;
1277 1277
1278 // Draw selection 1278 // Draw selection
1279 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1279 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1280 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1280 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1281 // TODO: paint only part within cx,cy,cw,ch 1281 // TODO: paint only part within cx,cy,cw,ch
1282 p->fillRect( selectionX, mSelectionYTop, mGridSpacingX, 1282 p->fillRect( selectionX, mSelectionYTop, mGridSpacingX,
1283 mSelectionHeight, KOPrefs::instance()->mHighlightColor ); 1283 mSelectionHeight, KOPrefs::instance()->mHighlightColor );
1284 } 1284 }
1285 */ 1285 */
1286 // Draw vertical lines of grid 1286 // Draw vertical lines of grid
1287 1287
1288 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX; 1288 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX;
1289 if ( mGridSpacingX > 0 ) { 1289 if ( mGridSpacingX > 0 ) {
1290 while (x < cx + cw) { 1290 while (x < cx + cw) {
1291 p->drawLine(x,cy,x,cy+ch); 1291 p->drawLine(x,cy,x,cy+ch);
1292 x+=mGridSpacingX; 1292 x+=mGridSpacingX;
1293 } 1293 }
1294 } 1294 }
1295 // Draw horizontal lines of grid 1295 // Draw horizontal lines of grid
1296 int y = ((int)(cy/lGridSpacingY))*lGridSpacingY; 1296 int y = ((int)(cy/lGridSpacingY))*lGridSpacingY;
1297 if ( lGridSpacingY > 0 ) { 1297 if ( lGridSpacingY > 0 ) {
1298 while (y < cy + ch) { 1298 while (y < cy + ch) {
1299 p->setPen( SolidLine ); 1299 p->setPen( SolidLine );
1300 p->drawLine(cx,y,cx+cw,y); 1300 p->drawLine(cx,y,cx+cw,y);
1301 y+=lGridSpacingY; 1301 y+=lGridSpacingY;
1302 p->setPen( DotLine ); 1302 p->setPen( DotLine );
1303 p->drawLine(cx,y,cx+cw,y); 1303 p->drawLine(cx,y,cx+cw,y);
1304 y+=lGridSpacingY; 1304 y+=lGridSpacingY;
1305 } 1305 }
1306 p->setPen( SolidLine ); 1306 p->setPen( SolidLine );
1307 } 1307 }
1308 mPixPainter.end() ; 1308 mPixPainter.end() ;
1309} 1309}
1310 1310
1311/* 1311/*
1312 Convert srcollview contents coordinates to agenda grid coordinates. 1312 Convert srcollview contents coordinates to agenda grid coordinates.
1313*/ 1313*/
1314void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy) 1314void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy)
1315{ 1315{
1316 gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX : 1316 gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX :
1317 x/mGridSpacingX; 1317 x/mGridSpacingX;
1318 gy = y/mGridSpacingY; 1318 gy = y/mGridSpacingY;
1319} 1319}
1320 1320
1321/* 1321/*
1322 Convert agenda grid coordinates to scrollview contents coordinates. 1322 Convert agenda grid coordinates to scrollview contents coordinates.
1323*/ 1323*/
1324void KOAgenda::gridToContents (int gx, int gy, int& x, int& y) 1324void KOAgenda::gridToContents (int gx, int gy, int& x, int& y)
1325{ 1325{
1326 x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX: 1326 x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX:
1327 gx*mGridSpacingX; 1327 gx*mGridSpacingX;
1328 y = gy*mGridSpacingY; 1328 y = gy*mGridSpacingY;
1329} 1329}
1330 1330
1331 1331
1332/* 1332/*
1333 Return Y coordinate corresponding to time. Coordinates are rounded to fit into 1333 Return Y coordinate corresponding to time. Coordinates are rounded to fit into
1334 the grid. 1334 the grid.
1335*/ 1335*/
1336int KOAgenda::timeToY(const QTime &time) 1336int KOAgenda::timeToY(const QTime &time)
1337{ 1337{
1338 int minutesPerCell = 24 * 60 / mRows; 1338 int minutesPerCell = 24 * 60 / mRows;
1339 int timeMinutes = time.hour() * 60 + time.minute(); 1339 int timeMinutes = time.hour() * 60 + time.minute();
1340 int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell; 1340 int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell;
1341 return Y; 1341 return Y;
1342} 1342}
1343 1343
1344 1344
1345/* 1345/*
1346 Return time corresponding to cell y coordinate. Coordinates are rounded to 1346 Return time corresponding to cell y coordinate. Coordinates are rounded to
1347 fit into the grid. 1347 fit into the grid.
1348*/ 1348*/
1349QTime KOAgenda::gyToTime(int gy) 1349QTime KOAgenda::gyToTime(int gy)
1350{ 1350{
1351 1351
1352 int secondsPerCell = 24 * 60 * 60/ mRows; 1352 int secondsPerCell = 24 * 60 * 60/ mRows;
1353 1353
1354 int timeSeconds = secondsPerCell * gy; 1354 int timeSeconds = secondsPerCell * gy;
1355 1355
1356 QTime time( 0, 0, 0 ); 1356 QTime time( 0, 0, 0 );
1357 if ( timeSeconds < 24 * 60 * 60 ) { 1357 if ( timeSeconds < 24 * 60 * 60 ) {
1358 time = time.addSecs(timeSeconds); 1358 time = time.addSecs(timeSeconds);
1359 } else { 1359 } else {
1360 time.setHMS( 23, 59, 59 ); 1360 time.setHMS( 23, 59, 59 );
1361 } 1361 }
1362 1362
1363 return time; 1363 return time;
1364} 1364}
1365 1365
1366void KOAgenda::setStartHour(int startHour) 1366void KOAgenda::setStartHour(int startHour)
1367{ 1367{
1368 int startCell = startHour * mRows / 24; 1368 int startCell = startHour * mRows / 24;
1369 setContentsPos(0,startCell * gridSpacingY()); 1369 setContentsPos(0,startCell * gridSpacingY());
1370} 1370}
1371void KOAgenda::hideUnused() 1371void KOAgenda::hideUnused()
1372{ 1372{
1373 // experimental only 1373 // experimental only
1374 // return; 1374 // return;
1375 KOAgendaItem *item; 1375 KOAgendaItem *item;
1376 for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) { 1376 for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) {
1377 item->hide(); 1377 item->hide();
1378 } 1378 }
1379} 1379}
1380 1380
1381 1381
1382KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view) 1382KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view)
1383{ 1383{
1384 1384
1385 KOAgendaItem *fi; 1385 KOAgendaItem *fi;
1386 for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) { 1386 for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) {
1387 if ( fi->incidence() == event ) { 1387 if ( fi->incidence() == event ) {
1388 mUnusedItems.remove(); 1388 mUnusedItems.remove();
1389 fi->init( event, qd ); 1389 fi->init( event, qd );
1390 return fi; 1390 return fi;
1391 } 1391 }
1392 } 1392 }
1393 fi=mUnusedItems.first(); 1393 fi=mUnusedItems.first();
1394 if ( fi ) { 1394 if ( fi ) {
1395 mUnusedItems.remove(); 1395 mUnusedItems.remove();
1396 fi->init( event, qd ); 1396 fi->init( event, qd );
1397 return fi; 1397 return fi;
1398 } 1398 }
1399 // qDebug("new KOAgendaItem "); 1399 // qDebug("new KOAgendaItem ");
1400 1400
1401 KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode ); 1401 KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode );
1402 agendaItem->installEventFilter(this); 1402 agendaItem->installEventFilter(this);
1403 addChild(agendaItem,0,0); 1403 addChild(agendaItem,0,0);
1404 return agendaItem; 1404 return agendaItem;
1405} 1405}
1406KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo ) 1406KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo )
1407{ 1407{
1408 KOAgendaItem *item; 1408 KOAgendaItem *item;
1409 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1409 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1410 if ( item->incidence() == todo ) { 1410 if ( item->incidence() == todo ) {
1411 mItems.remove(); 1411 mItems.remove();
1412 return item; 1412 return item;
1413 } 1413 }
1414 } 1414 }
1415 return 0; 1415 return 0;
1416} 1416}
1417 1417
1418 1418
1419void KOAgenda::updateTodo( Todo * todo, int days, bool remove) 1419void KOAgenda::updateTodo( Todo * todo, int days, bool remove)
1420{ 1420{
1421 // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )|| 1421 // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )||
1422 KOAgendaItem *item; 1422 KOAgendaItem *item;
1423 item = getItemForTodo ( todo ); 1423 item = getItemForTodo ( todo );
1424 //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove); 1424 //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove);
1425 if ( item ) { 1425 if ( item ) {
1426 blockSignals( true ); 1426 blockSignals( true );
1427 //qDebug("item found "); 1427 //qDebug("item found ");
1428 item->hide(); 1428 item->hide();
1429 item->setCellX(-2, -1 ); 1429 item->setCellX(-2, -1 );
1430 item->select(false); 1430 item->select(false);
1431 mUnusedItems.append( item ); 1431 mUnusedItems.append( item );
1432 mItems.remove( item ); 1432 mItems.remove( item );
1433 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); 1433 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems();
1434 KOAgendaItem *itemit; 1434 KOAgendaItem *itemit;
1435 //globalFlagBlockAgendaItemPaint = 1; 1435 //globalFlagBlockAgendaItemPaint = 1;
1436 for ( itemit=oldconflictItems.first(); itemit != 0; 1436 for ( itemit=oldconflictItems.first(); itemit != 0;
1437 itemit=oldconflictItems.next() ) { 1437 itemit=oldconflictItems.next() ) {
1438 if ( itemit != item ) 1438 if ( itemit != item )
1439 placeSubCells(itemit); 1439 placeSubCells(itemit);
1440 } 1440 }
1441 qApp->processEvents(); 1441 qApp->processEvents();
1442 //globalFlagBlockAgendaItemPaint = 0; 1442 //globalFlagBlockAgendaItemPaint = 0;
1443 for ( itemit=oldconflictItems.first(); itemit != 0; 1443 for ( itemit=oldconflictItems.first(); itemit != 0;
1444 itemit=oldconflictItems.next() ) { 1444 itemit=oldconflictItems.next() ) {
1445 globalFlagBlockAgendaItemUpdate = 0; 1445 globalFlagBlockAgendaItemUpdate = 0;
1446 if ( itemit != item ) 1446 if ( itemit != item )
1447 itemit->repaintMe(); 1447 itemit->repaintMe();
1448 globalFlagBlockAgendaItemUpdate = 1; 1448 globalFlagBlockAgendaItemUpdate = 1;
1449 itemit->repaint(); 1449 itemit->repaint();
1450 } 1450 }
1451 blockSignals( false ); 1451 blockSignals( false );
1452 } 1452 }
1453 if ( remove ) { 1453 if ( remove ) {
1454 //qDebug("remove****************************************** "); 1454 //qDebug("remove****************************************** ");
1455 return; 1455 return;
1456 } 1456 }
1457 //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ "); 1457 //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ ");
1458 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < QDate::currentDate())&& ( KOPrefs::instance()->mShowTodoInAgenda ); 1458 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < QDate::currentDate())&& ( KOPrefs::instance()->mShowTodoInAgenda );
1459 QDate currentDate; 1459 QDate currentDate;
1460 QDateTime dt; 1460 QDateTime dt;
1461 if ( todo->hasCompletedDate() ) 1461 if ( todo->hasCompletedDate() )
1462 dt = todo->completed(); 1462 dt = todo->completed();
1463 else 1463 else
1464 dt = todo->dtDue(); 1464 dt = todo->dtDue();
1465 if ( overdue ) { 1465 if ( overdue ) {
1466 currentDate = QDate::currentDate(); 1466 currentDate = QDate::currentDate();
1467 days += todo->dtDue().date().daysTo( currentDate ); 1467 days += todo->dtDue().date().daysTo( currentDate );
1468 } 1468 }
1469 else 1469 else
1470 currentDate = dt.date(); 1470 currentDate = dt.date();
1471 1471
1472 if ( todo->doesFloat() || overdue ) { 1472 if (( todo->doesFloat() || overdue) && !todo->hasCompletedDate() ) {
1473 if ( ! mAllDayMode ) return; 1473 if ( ! mAllDayMode ) return;
1474 // aldayagenda 1474 // aldayagenda
1475 globalFlagBlockAgendaItemPaint = 1; 1475 globalFlagBlockAgendaItemPaint = 1;
1476 item = insertAllDayItem(todo, currentDate,days, days); 1476 item = insertAllDayItem(todo, currentDate,days, days);
1477 item->show(); 1477 item->show();
1478 1478
1479 } 1479 }
1480 else { 1480 else {
1481 if ( mAllDayMode ) return; 1481 if ( mAllDayMode ) return;
1482 // mAgenda 1482 // mAgenda
1483 globalFlagBlockAgendaItemPaint = 1; 1483 globalFlagBlockAgendaItemPaint = 1;
1484 int endY = timeToY(dt.time()) - 1; 1484 int endY = timeToY(dt.time()) - 1;
1485 int hi = 12/KOPrefs::instance()->mHourSize; 1485 int hi = 12/KOPrefs::instance()->mHourSize;
1486 int startY = endY - 1-hi; 1486 int startY = endY - 1-hi;
1487 item = insertItem(todo,currentDate,days,startY,endY); 1487 item = insertItem(todo,currentDate,days,startY,endY);
1488 item->show(); 1488 item->show();
1489 } 1489 }
1490 qApp->processEvents(); 1490 qApp->processEvents();
1491 globalFlagBlockAgendaItemPaint = 0; 1491 globalFlagBlockAgendaItemPaint = 0;
1492 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); 1492 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems();
1493 KOAgendaItem *itemit; 1493 KOAgendaItem *itemit;
1494 for ( itemit=oldconflictItems.first(); itemit != 0; 1494 for ( itemit=oldconflictItems.first(); itemit != 0;
1495 itemit=oldconflictItems.next() ) { 1495 itemit=oldconflictItems.next() ) {
1496 globalFlagBlockAgendaItemUpdate = 0; 1496 globalFlagBlockAgendaItemUpdate = 0;
1497 itemit->repaintMe(); 1497 itemit->repaintMe();
1498 globalFlagBlockAgendaItemUpdate = 1; 1498 globalFlagBlockAgendaItemUpdate = 1;
1499 itemit->repaint(); 1499 itemit->repaint();
1500 } 1500 }
1501 globalFlagBlockAgendaItemUpdate = 0; 1501 globalFlagBlockAgendaItemUpdate = 0;
1502 item->repaintMe(); 1502 item->repaintMe();
1503 globalFlagBlockAgendaItemUpdate = 1; 1503 globalFlagBlockAgendaItemUpdate = 1;
1504 item->repaint(); 1504 item->repaint();
1505} 1505}
1506/* 1506/*
1507 Insert KOAgendaItem into agenda. 1507 Insert KOAgendaItem into agenda.
1508*/ 1508*/
1509KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom) 1509KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom)
1510{ 1510{
1511 //kdDebug() << "KOAgenda::insertItem:" << event->summary() << "-" << qd.toString() << " ;top, bottom:" << YTop << "," << YBottom << endl; 1511 //kdDebug() << "KOAgenda::insertItem:" << event->summary() << "-" << qd.toString() << " ;top, bottom:" << YTop << "," << YBottom << endl;
1512 1512
1513 if (mAllDayMode) { 1513 if (mAllDayMode) {
1514 kdDebug() << "KOAgenda: calling insertItem in all-day mode is illegal." << endl; 1514 kdDebug() << "KOAgenda: calling insertItem in all-day mode is illegal." << endl;
1515 return 0; 1515 return 0;
1516 } 1516 }
1517 1517
1518 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); 1518 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport());
1519 //agendaItem->setFrameStyle(WinPanel|Raised); 1519 //agendaItem->setFrameStyle(WinPanel|Raised);
1520 1520
1521 int YSize = YBottom - YTop + 1; 1521 int YSize = YBottom - YTop + 1;
1522 if (YSize < 0) { 1522 if (YSize < 0) {
1523 kdDebug() << "KOAgenda::insertItem(): Text: " << agendaItem->text() << " YSize<0" << endl; 1523 kdDebug() << "KOAgenda::insertItem(): Text: " << agendaItem->text() << " YSize<0" << endl;
1524 YSize = 1; 1524 YSize = 1;
1525 } 1525 }
1526 int iheight = mGridSpacingY * YSize; 1526 int iheight = mGridSpacingY * YSize;
1527 1527
1528 agendaItem->resize(mGridSpacingX,iheight ); 1528 agendaItem->resize(mGridSpacingX,iheight );
1529 agendaItem->setCellXY(X,YTop,YBottom); 1529 agendaItem->setCellXY(X,YTop,YBottom);
1530 agendaItem->setCellXWidth(X); 1530 agendaItem->setCellXWidth(X);
1531 1531
1532 //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY); 1532 //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY);
1533 mItems.append(agendaItem); 1533 mItems.append(agendaItem);
1534 1534
1535 placeSubCells(agendaItem); 1535 placeSubCells(agendaItem);
1536 1536
1537 //agendaItem->show(); 1537 //agendaItem->show();
1538 1538
1539 marcus_bains(); 1539 marcus_bains();
1540 1540
1541 return agendaItem; 1541 return agendaItem;
1542} 1542}
1543 1543
1544 1544
1545/* 1545/*
1546 Insert all-day KOAgendaItem into agenda. 1546 Insert all-day KOAgendaItem into agenda.
1547*/ 1547*/
1548KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd) 1548KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd)
1549{ 1549{
1550 if (!mAllDayMode) { 1550 if (!mAllDayMode) {
1551 return 0; 1551 return 0;
1552 } 1552 }
1553 1553
1554 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); 1554 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport());
1555 1555
1556 agendaItem->setCellXY(XBegin,0,0); 1556 agendaItem->setCellXY(XBegin,0,0);
1557 agendaItem->setCellXWidth(XEnd); 1557 agendaItem->setCellXWidth(XEnd);
1558 agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY); 1558 agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY);
1559 1559
1560 //addChild(agendaItem,XBegin*mGridSpacingX,0); 1560 //addChild(agendaItem,XBegin*mGridSpacingX,0);
1561 mItems.append(agendaItem); 1561 mItems.append(agendaItem);
1562 1562
1563 placeSubCells(agendaItem); 1563 placeSubCells(agendaItem);
1564 1564
1565 //agendaItem->show(); 1565 //agendaItem->show();
1566 1566
1567 return agendaItem; 1567 return agendaItem;
1568} 1568}
1569 1569
1570 1570
1571void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, 1571void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd,
1572 int YTop,int YBottom) 1572 int YTop,int YBottom)
1573{ 1573{
1574 if (mAllDayMode) { 1574 if (mAllDayMode) {
1575 ; 1575 ;
1576 return; 1576 return;
1577 } 1577 }
1578 1578
1579 int cellX,cellYTop,cellYBottom; 1579 int cellX,cellYTop,cellYBottom;
1580 QString newtext; 1580 QString newtext;
1581 int width = XEnd - XBegin + 1; 1581 int width = XEnd - XBegin + 1;
1582 int count = 0; 1582 int count = 0;
1583 KOAgendaItem *current = 0; 1583 KOAgendaItem *current = 0;
1584 QPtrList<KOAgendaItem> multiItems; 1584 QPtrList<KOAgendaItem> multiItems;
1585 for (cellX = XBegin;cellX <= XEnd;++cellX) { 1585 for (cellX = XBegin;cellX <= XEnd;++cellX) {
1586 if (cellX == XBegin) cellYTop = YTop; 1586 if (cellX == XBegin) cellYTop = YTop;
1587 else cellYTop = 0; 1587 else cellYTop = 0;
1588 if (cellX == XEnd) cellYBottom = YBottom; 1588 if (cellX == XEnd) cellYBottom = YBottom;
1589 else cellYBottom = rows() - 1; 1589 else cellYBottom = rows() - 1;
1590 newtext = QString("(%1/%2): ").arg(++count).arg(width); 1590 newtext = QString("(%1/%2): ").arg(++count).arg(width);
1591 newtext.append(event->summary()); 1591 newtext.append(event->summary());
1592 current = insertItem(event,qd,cellX,cellYTop,cellYBottom); 1592 current = insertItem(event,qd,cellX,cellYTop,cellYBottom);
1593 current->setText(newtext); 1593 current->setText(newtext);
1594 multiItems.append(current); 1594 multiItems.append(current);
1595 } 1595 }
1596 1596
1597 KOAgendaItem *next = 0; 1597 KOAgendaItem *next = 0;
1598 KOAgendaItem *last = multiItems.last(); 1598 KOAgendaItem *last = multiItems.last();
1599 KOAgendaItem *first = multiItems.first(); 1599 KOAgendaItem *first = multiItems.first();
1600 KOAgendaItem *setFirst,*setLast; 1600 KOAgendaItem *setFirst,*setLast;
1601 current = first; 1601 current = first;
1602 while (current) { 1602 while (current) {
1603 next = multiItems.next(); 1603 next = multiItems.next();
1604 if (current == first) setFirst = 0; 1604 if (current == first) setFirst = 0;
1605 else setFirst = first; 1605 else setFirst = first;
1606 if (current == last) setLast = 0; 1606 if (current == last) setLast = 0;
1607 else setLast = last; 1607 else setLast = last;
1608 1608
1609 current->setMultiItem(setFirst,next,setLast); 1609 current->setMultiItem(setFirst,next,setLast);
1610 current = next; 1610 current = next;
1611 } 1611 }
1612 1612
1613 marcus_bains(); 1613 marcus_bains();
1614} 1614}
1615 1615
1616 1616
1617//QSizePolicy KOAgenda::sizePolicy() const 1617//QSizePolicy KOAgenda::sizePolicy() const
1618//{ 1618//{
1619 // Thought this would make the all-day event agenda minimum size and the 1619 // Thought this would make the all-day event agenda minimum size and the
1620 // normal agenda take the remaining space. But it doesn´t work. The QSplitter 1620 // normal agenda take the remaining space. But it doesn´t work. The QSplitter
1621 // don´t seem to think that an Expanding widget needs more space than a 1621 // don´t seem to think that an Expanding widget needs more space than a
1622 // Preferred one. 1622 // Preferred one.
1623 // But it doesn´t hurt, so it stays. 1623 // But it doesn´t hurt, so it stays.
1624// if (mAllDayMode) { 1624// if (mAllDayMode) {
1625// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); 1625// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
1626// } else { 1626// } else {
1627// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); 1627// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
1628// } 1628// }
1629//} 1629//}
1630void KOAgenda::finishResize ( ) 1630void KOAgenda::finishResize ( )
1631{ 1631{
1632 //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) "); 1632 //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) ");
1633 if ( globalFlagBlockAgenda == 0 ) { 1633 if ( globalFlagBlockAgenda == 0 ) {
1634 finishUpdate(); 1634 finishUpdate();
1635 //qDebug("finishUpdate() called "); 1635 //qDebug("finishUpdate() called ");
1636 } 1636 }
1637} 1637}
1638/* 1638/*
1639 Overridden from QScrollView to provide proper resizing of KOAgendaItems. 1639 Overridden from QScrollView to provide proper resizing of KOAgendaItems.
1640*/ 1640*/
1641void KOAgenda::resizeEvent ( QResizeEvent *ev ) 1641void KOAgenda::resizeEvent ( QResizeEvent *ev )
1642{ 1642{
1643 1643
1644 mResizeTimer.start( 150 , true ); 1644 mResizeTimer.start( 150 , true );
1645 computeSizes(); 1645 computeSizes();
1646 return; 1646 return;
1647 1647
1648} 1648}
1649void KOAgenda::computeSizes() 1649void KOAgenda::computeSizes()
1650{ 1650{
1651 if ( globalFlagBlockStartup ) 1651 if ( globalFlagBlockStartup )
1652 return; 1652 return;
1653 1653
1654 if (mAllDayMode) { 1654 if (mAllDayMode) {
1655 mGridSpacingX = (width()-3) / mColumns; 1655 mGridSpacingX = (width()-3) / mColumns;
1656 mGridSpacingY = height() - 2 * frameWidth() - 1; 1656 mGridSpacingY = height() - 2 * frameWidth() - 1;
1657 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1); 1657 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1);
1658// mGridSpacingY = height(); 1658// mGridSpacingY = height();
1659// resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1659// resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1660 1660
1661 KOAgendaItem *item; 1661 KOAgendaItem *item;
1662 int subCellWidth; 1662 int subCellWidth;
1663 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1663 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1664 subCellWidth = mGridSpacingY / item->subCells(); 1664 subCellWidth = mGridSpacingY / item->subCells();
1665 item->resize(mGridSpacingX * item->cellWidth(),subCellWidth); 1665 item->resize(mGridSpacingX * item->cellWidth(),subCellWidth);
1666 moveChild(item,KOGlobals::self()->reverseLayout() ? 1666 moveChild(item,KOGlobals::self()->reverseLayout() ?
1667 (mColumns - 1 - item->cellX()) * mGridSpacingX : 1667 (mColumns - 1 - item->cellX()) * mGridSpacingX :
1668 item->cellX() * mGridSpacingX, 1668 item->cellX() * mGridSpacingX,
1669 item->subCell() * subCellWidth); 1669 item->subCell() * subCellWidth);
1670 } 1670 }
1671 KOPrefs::instance()->mAllDaySize = mGridSpacingY; 1671 KOPrefs::instance()->mAllDaySize = mGridSpacingY;
1672 } else { 1672 } else {
1673 mGridSpacingX = (width() - verticalScrollBar()->width()-3)/mColumns; 1673 mGridSpacingX = (width() - verticalScrollBar()->width()-3)/mColumns;
1674 if (height() > mGridSpacingY * mRows + 1 ) { 1674 if (height() > mGridSpacingY * mRows + 1 ) {
1675 KOPrefs::instance()->mHourSize = ((height())/mRows)+1; 1675 KOPrefs::instance()->mHourSize = ((height())/mRows)+1;
1676 mGridSpacingY = KOPrefs::instance()->mHourSize ; 1676 mGridSpacingY = KOPrefs::instance()->mHourSize ;
1677 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1677 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1678 emit resizedSignal(); 1678 emit resizedSignal();
1679 } else 1679 } else
1680 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1680 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1681 KOAgendaItem *item; 1681 KOAgendaItem *item;
1682 int subCellWidth; 1682 int subCellWidth;
1683 1683
1684 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1684 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1685 subCellWidth = mGridSpacingX / item->subCells(); 1685 subCellWidth = mGridSpacingX / item->subCells();
1686 item->resize(subCellWidth,item->height()); 1686 item->resize(subCellWidth,item->height());
1687 moveChild(item,(KOGlobals::self()->reverseLayout() ? 1687 moveChild(item,(KOGlobals::self()->reverseLayout() ?
1688 (mColumns - 1 - item->cellX()) * mGridSpacingX : 1688 (mColumns - 1 - item->cellX()) * mGridSpacingX :
1689 item->cellX() * mGridSpacingX) + 1689 item->cellX() * mGridSpacingX) +
1690 item->subCell() * subCellWidth,childY(item)); 1690 item->subCell() * subCellWidth,childY(item));
1691 } 1691 }
1692 } 1692 }
1693 int cw = contentsWidth(); 1693 int cw = contentsWidth();
1694 int ch = contentsHeight(); 1694 int ch = contentsHeight();
1695 if ( mAllDayMode ) { 1695 if ( mAllDayMode ) {
1696 QPixmap* paintPixAll = KOAgendaItem::paintPixAllday(); 1696 QPixmap* paintPixAll = KOAgendaItem::paintPixAllday();
1697 if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 ) 1697 if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 )
1698 paintPixAll->resize( cw, ch ); 1698 paintPixAll->resize( cw, ch );
1699 } else { 1699 } else {
1700 QPixmap* paintPix = KOAgendaItem::paintPix(); 1700 QPixmap* paintPix = KOAgendaItem::paintPix();
1701 if ( paintPix->width() < cw || paintPix->height() < ch ) 1701 if ( paintPix->width() < cw || paintPix->height() < ch )
1702 KOAgendaItem::resizePixmap( cw , ch ); 1702 KOAgendaItem::resizePixmap( cw , ch );
1703 } 1703 }
1704 1704
1705 checkScrollBoundaries(); 1705 checkScrollBoundaries();
1706 marcus_bains(); 1706 marcus_bains();
1707 drawContentsToPainter(); 1707 drawContentsToPainter();
1708 viewport()->repaint(false); 1708 viewport()->repaint(false);
1709} 1709}
1710 1710
1711void KOAgenda::scrollUp() 1711void KOAgenda::scrollUp()
1712{ 1712{
1713 scrollBy(0,-mScrollOffset); 1713 scrollBy(0,-mScrollOffset);
1714} 1714}
1715 1715
1716 1716
1717void KOAgenda::scrollDown() 1717void KOAgenda::scrollDown()
1718{ 1718{
1719 scrollBy(0,mScrollOffset); 1719 scrollBy(0,mScrollOffset);
1720} 1720}
1721 1721
1722void KOAgenda::popupAlarm() 1722void KOAgenda::popupAlarm()
1723{ 1723{
1724 if (!mClickedItem) { 1724 if (!mClickedItem) {
1725 qDebug("KOAgenda::popupAlarm() called without having a clicked item "); 1725 qDebug("KOAgenda::popupAlarm() called without having a clicked item ");
1726 return; 1726 return;
1727 } 1727 }
1728// TODO: deal correctly with multiple alarms 1728// TODO: deal correctly with multiple alarms
1729 Alarm* alarm; 1729 Alarm* alarm;
1730 QPtrList<Alarm> list(mClickedItem->incidence()->alarms()); 1730 QPtrList<Alarm> list(mClickedItem->incidence()->alarms());
1731 for(alarm=list.first();alarm;alarm=list.next()) { 1731 for(alarm=list.first();alarm;alarm=list.next()) {
1732 alarm->toggleAlarm(); 1732 alarm->toggleAlarm();
1733 } 1733 }
1734 emit itemModified( mClickedItem , KOGlobals::EVENTEDITED ); 1734 emit itemModified( mClickedItem , KOGlobals::EVENTEDITED );
1735 mClickedItem->paintMe( true ); 1735 mClickedItem->paintMe( true );
1736 mClickedItem->repaint( false ); 1736 mClickedItem->repaint( false );
1737} 1737}
1738 1738
1739/* 1739/*
1740 Calculates the minimum width 1740 Calculates the minimum width
1741*/ 1741*/
1742int KOAgenda::minimumWidth() const 1742int KOAgenda::minimumWidth() const
1743{ 1743{
1744 // TODO:: develop a way to dynamically determine the minimum width 1744 // TODO:: develop a way to dynamically determine the minimum width
1745 int min = 100; 1745 int min = 100;
1746 1746
1747 return min; 1747 return min;
1748} 1748}
1749 1749
1750void KOAgenda::updateConfig() 1750void KOAgenda::updateConfig()
1751{ 1751{
1752 if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor) 1752 if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor)
1753 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor); 1753 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor);
1754 if ( mAllDayMode ) { 1754 if ( mAllDayMode ) {
1755 mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize; 1755 mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize;
1756 //mGridSpacingY = KOPrefs::instance()->mAllDaySize; 1756 //mGridSpacingY = KOPrefs::instance()->mAllDaySize;
1757 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 ); 1757 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 );
1758 // setMaximumHeight( mGridSpacingY+1 ); 1758 // setMaximumHeight( mGridSpacingY+1 );
1759 viewport()->repaint( false ); 1759 viewport()->repaint( false );
1760 //setFixedHeight( mGridSpacingY+1 ); 1760 //setFixedHeight( mGridSpacingY+1 );
1761 //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize); 1761 //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize);
1762 } 1762 }
1763 else { 1763 else {
1764 mGridSpacingY = KOPrefs::instance()->mHourSize; 1764 mGridSpacingY = KOPrefs::instance()->mHourSize;
1765 calculateWorkingHours(); 1765 calculateWorkingHours();
1766 marcus_bains(); 1766 marcus_bains();
1767 } 1767 }
1768} 1768}
1769 1769
1770void KOAgenda::checkScrollBoundaries() 1770void KOAgenda::checkScrollBoundaries()
1771{ 1771{
1772 // Invalidate old values to force update 1772 // Invalidate old values to force update
1773 mOldLowerScrollValue = -1; 1773 mOldLowerScrollValue = -1;
1774 mOldUpperScrollValue = -1; 1774 mOldUpperScrollValue = -1;
1775 1775
1776 checkScrollBoundaries(verticalScrollBar()->value()); 1776 checkScrollBoundaries(verticalScrollBar()->value());
1777} 1777}
1778 1778
1779void KOAgenda::checkScrollBoundaries(int v) 1779void KOAgenda::checkScrollBoundaries(int v)
1780{ 1780{
1781 if ( mGridSpacingY == 0 ) 1781 if ( mGridSpacingY == 0 )
1782 return; 1782 return;
1783 int yMin = v/mGridSpacingY; 1783 int yMin = v/mGridSpacingY;
1784 int yMax = (v+visibleHeight())/mGridSpacingY; 1784 int yMax = (v+visibleHeight())/mGridSpacingY;
1785 1785
1786// kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl; 1786// kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl;
1787 1787
1788 if (yMin != mOldLowerScrollValue) { 1788 if (yMin != mOldLowerScrollValue) {
1789 mOldLowerScrollValue = yMin; 1789 mOldLowerScrollValue = yMin;
1790 emit lowerYChanged(yMin); 1790 emit lowerYChanged(yMin);
1791 } 1791 }
1792 if (yMax != mOldUpperScrollValue) { 1792 if (yMax != mOldUpperScrollValue) {
1793 mOldUpperScrollValue = yMax; 1793 mOldUpperScrollValue = yMax;
1794 emit upperYChanged(yMax); 1794 emit upperYChanged(yMax);
1795 } 1795 }
1796} 1796}
1797 1797
1798void KOAgenda::deselectItem() 1798void KOAgenda::deselectItem()
1799{ 1799{
1800 if (mSelectedItem.isNull()) return; 1800 if (mSelectedItem.isNull()) return;
1801 mSelectedItem->select(false); 1801 mSelectedItem->select(false);
1802 mSelectedItem = 0; 1802 mSelectedItem = 0;
1803} 1803}
1804 1804
1805void KOAgenda::selectItem(KOAgendaItem *item) 1805void KOAgenda::selectItem(KOAgendaItem *item)
1806{ 1806{
1807 if ((KOAgendaItem *)mSelectedItem == item) return; 1807 if ((KOAgendaItem *)mSelectedItem == item) return;
1808 deselectItem(); 1808 deselectItem();
1809 if (item == 0) { 1809 if (item == 0) {
1810 emit incidenceSelected( 0 ); 1810 emit incidenceSelected( 0 );
1811 return; 1811 return;
1812 } 1812 }
1813 mSelectedItem = item; 1813 mSelectedItem = item;
1814 mSelectedItem->select(); 1814 mSelectedItem->select();
1815 emit incidenceSelected( mSelectedItem->incidence() ); 1815 emit incidenceSelected( mSelectedItem->incidence() );
1816} 1816}
1817 1817
1818// This function seems never be called. 1818// This function seems never be called.
1819void KOAgenda::keyPressEvent( QKeyEvent *kev ) 1819void KOAgenda::keyPressEvent( QKeyEvent *kev )
1820{ 1820{
1821 switch(kev->key()) { 1821 switch(kev->key()) {
1822 case Key_PageDown: 1822 case Key_PageDown:
1823 verticalScrollBar()->addPage(); 1823 verticalScrollBar()->addPage();
1824 break; 1824 break;
1825 case Key_PageUp: 1825 case Key_PageUp:
1826 verticalScrollBar()->subtractPage(); 1826 verticalScrollBar()->subtractPage();
1827 break; 1827 break;
1828 case Key_Down: 1828 case Key_Down:
1829 verticalScrollBar()->addLine(); 1829 verticalScrollBar()->addLine();
1830 break; 1830 break;
1831 case Key_Up: 1831 case Key_Up:
1832 verticalScrollBar()->subtractLine(); 1832 verticalScrollBar()->subtractLine();
1833 break; 1833 break;
1834 default: 1834 default:
1835 ; 1835 ;
1836 } 1836 }
1837} 1837}
1838 1838
1839void KOAgenda::calculateWorkingHours() 1839void KOAgenda::calculateWorkingHours()
1840{ 1840{
1841// mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours; 1841// mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours;
1842 mWorkingHoursEnable = !mAllDayMode; 1842 mWorkingHoursEnable = !mAllDayMode;
1843 1843
1844 mWorkingHoursYTop = mGridSpacingY * 1844 mWorkingHoursYTop = mGridSpacingY *
1845 KOPrefs::instance()->mWorkingHoursStart * 4; 1845 KOPrefs::instance()->mWorkingHoursStart * 4;
1846 mWorkingHoursYBottom = mGridSpacingY * 1846 mWorkingHoursYBottom = mGridSpacingY *
1847 KOPrefs::instance()->mWorkingHoursEnd * 4 - 1; 1847 KOPrefs::instance()->mWorkingHoursEnd * 4 - 1;
1848} 1848}
1849 1849
1850 1850
1851DateList KOAgenda::dateList() const 1851DateList KOAgenda::dateList() const
1852{ 1852{
1853 return mSelectedDates; 1853 return mSelectedDates;
1854} 1854}
1855 1855
1856void KOAgenda::setDateList(const DateList &selectedDates) 1856void KOAgenda::setDateList(const DateList &selectedDates)
1857{ 1857{
1858 mSelectedDates = selectedDates; 1858 mSelectedDates = selectedDates;
1859 marcus_bains(); 1859 marcus_bains();
1860} 1860}
1861 1861
1862void KOAgenda::setHolidayMask(QMemArray<bool> *mask) 1862void KOAgenda::setHolidayMask(QMemArray<bool> *mask)
1863{ 1863{
1864 mHolidayMask = mask; 1864 mHolidayMask = mask;
1865 1865
1866/* 1866/*
1867 kdDebug() << "HolidayMask: "; 1867 kdDebug() << "HolidayMask: ";
1868 for(uint i=0;i<mask->count();++i) { 1868 for(uint i=0;i<mask->count();++i) {
1869 kdDebug() << (mask->at(i) ? "*" : "o"); 1869 kdDebug() << (mask->at(i) ? "*" : "o");
1870 } 1870 }
1871 kdDebug() << endl; 1871 kdDebug() << endl;
1872*/ 1872*/
1873} 1873}
1874 1874
1875void KOAgenda::contentsMousePressEvent ( QMouseEvent *event ) 1875void KOAgenda::contentsMousePressEvent ( QMouseEvent *event )
1876{ 1876{
1877 1877
1878 QScrollView::contentsMousePressEvent(event); 1878 QScrollView::contentsMousePressEvent(event);
1879} 1879}
1880 1880
1881void KOAgenda::storePosition() 1881void KOAgenda::storePosition()
1882{ 1882{
1883 //mContentPosition 1883 //mContentPosition
1884 int max = mGridSpacingY*4*24; 1884 int max = mGridSpacingY*4*24;
1885 if ( contentsY() < 5 && max > viewport()->height()*3/2 ) 1885 if ( contentsY() < 5 && max > viewport()->height()*3/2 )
1886 mContentPosition = 0; 1886 mContentPosition = 0;
1887 else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2) 1887 else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2)
1888 mContentPosition = -1.0; 1888 mContentPosition = -1.0;
1889 else 1889 else
1890 mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2))); 1890 mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2)));
1891 //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height()); 1891 //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height());
1892 1892
1893} 1893}
1894void KOAgenda::restorePosition() 1894void KOAgenda::restorePosition()
1895{ 1895{
1896 int posY; 1896 int posY;
1897 int max = mGridSpacingY*4*24; 1897 int max = mGridSpacingY*4*24;
1898 if ( mContentPosition < 0 ) 1898 if ( mContentPosition < 0 )
1899 posY = max-viewport()->height(); 1899 posY = max-viewport()->height();
1900 else 1900 else
1901 if ( mContentPosition == 0 ) 1901 if ( mContentPosition == 0 )
1902 posY = 0; 1902 posY = 0;
1903 else 1903 else
1904 posY = (max/mContentPosition)-(viewport()->height()/2); 1904 posY = (max/mContentPosition)-(viewport()->height()/2);
1905 setContentsPos (0, posY ); 1905 setContentsPos (0, posY );
1906 //qDebug("posY %d hei %d", posY, max); 1906 //qDebug("posY %d hei %d", posY, max);
1907 1907
1908} 1908}
1909void KOAgenda::moveChild( QWidget *w, int x , int y ) 1909void KOAgenda::moveChild( QWidget *w, int x , int y )
1910{ 1910{
1911 ++x; 1911 ++x;
1912 QScrollView::moveChild( w, x , y ); 1912 QScrollView::moveChild( w, x , y );
1913} 1913}
1914#include <qmessagebox.h> 1914#include <qmessagebox.h>
1915#ifdef DESKTOP_VERSION 1915#ifdef DESKTOP_VERSION
1916#include <qprinter.h> 1916#include <qprinter.h>
1917#include <qpainter.h> 1917#include <qpainter.h>
1918#include <qpaintdevicemetrics.h> 1918#include <qpaintdevicemetrics.h>
1919 1919
1920#endif 1920#endif
1921void KOAgenda::printSelection() 1921void KOAgenda::printSelection()
1922{ 1922{
1923#ifdef DESKTOP_VERSION 1923#ifdef DESKTOP_VERSION
1924 if ( mStartCellY == mCurrentCellY ) { 1924 if ( mStartCellY == mCurrentCellY ) {
1925 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 1925 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
1926 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. "), 1926 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. "),
1927 i18n("OK"), 0, 0, 1927 i18n("OK"), 0, 0,
1928 0, 1 ); 1928 0, 1 );
1929 return; 1929 return;
1930 } 1930 }
1931 1931
1932 float dx, dy; 1932 float dx, dy;
1933 int x,y,w,h; 1933 int x,y,w,h;
1934 x= 0; 1934 x= 0;
1935 w= contentsWidth()+2; 1935 w= contentsWidth()+2;
1936 // h= contentsHeight(); 1936 // h= contentsHeight();
1937 y = mGridSpacingY*mStartCellY; 1937 y = mGridSpacingY*mStartCellY;
1938 h = mGridSpacingY*(mCurrentCellY+1)-y+2; 1938 h = mGridSpacingY*(mCurrentCellY+1)-y+2;
1939 1939
1940 //return; 1940 //return;
1941 QPrinter* printer = new QPrinter(); 1941 QPrinter* printer = new QPrinter();
1942 if ( !printer->setup()) { 1942 if ( !printer->setup()) {
1943 delete printer; 1943 delete printer;
1944 return; 1944 return;
1945 } 1945 }
1946 QPainter p( printer ); 1946 QPainter p( printer );
1947 QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer ); 1947 QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer );
1948 QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() ); 1948 QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() );
1949 date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true ); 1949 date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true );
1950 int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height(); 1950 int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height();
1951 // p.drawText( 0, 0, date ); 1951 // p.drawText( 0, 0, date );
1952 int offset = m.width()/8; 1952 int offset = m.width()/8;
1953 // compute the scale 1953 // compute the scale
1954 dx = ((float) m.width()-offset) / (float)w; 1954 dx = ((float) m.width()-offset) / (float)w;
1955 dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h; 1955 dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h;
1956 float scale; 1956 float scale;
1957 // scale to fit the width or height of the paper 1957 // scale to fit the width or height of the paper
1958 if ( dx < dy ) 1958 if ( dx < dy )
1959 scale = dx; 1959 scale = dx;
1960 else 1960 else
1961 scale = dy; 1961 scale = dy;
1962 // set the scale 1962 // set the scale
1963 p.drawText( offset* scale, offset* scale*3/4, date ); 1963 p.drawText( offset* scale, offset* scale*3/4, date );
1964 1964
1965 int selDay; 1965 int selDay;
1966 float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count())); 1966 float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count()));
1967 float startX = 1; 1967 float startX = 1;
1968 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) 1968 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay)
1969 { 1969 {
1970 QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true ); 1970 QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true );
1971 p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) ); 1971 p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) );
1972 p.drawText( offset* scale+startX, (offset+hei)* scale, text ); 1972 p.drawText( offset* scale+startX, (offset+hei)* scale, text );
1973 startX += widOffset; 1973 startX += widOffset;
1974 1974
1975 } 1975 }
1976 p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale)); 1976 p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale));
1977 p.scale( scale, scale ); 1977 p.scale( scale, scale );
1978 p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale ); 1978 p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale );
1979 // now printing with y offset: 2 hei 1979 // now printing with y offset: 2 hei
1980 // p.translate( 0, -y*scale); 1980 // p.translate( 0, -y*scale);
1981 1981
1982 drawContentsToPainter(&p, true ); 1982 drawContentsToPainter(&p, true );
1983 globalFlagBlockAgendaItemUpdate = false; 1983 globalFlagBlockAgendaItemUpdate = false;
1984 KOAgendaItem *item; 1984 KOAgendaItem *item;
1985 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1985 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1986 item->select(false); 1986 item->select(false);
1987 item->paintMe( false, &p ); 1987 item->paintMe( false, &p );
1988 } 1988 }
1989 globalFlagBlockAgendaItemUpdate = true; 1989 globalFlagBlockAgendaItemUpdate = true;
1990 p.end(); 1990 p.end();
1991 delete printer; 1991 delete printer;
1992#else 1992#else
1993 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 1993 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
1994 i18n("Not supported \non PDA!\n"), 1994 i18n("Not supported \non PDA!\n"),
1995 i18n("OK"), 0, 0, 1995 i18n("OK"), 0, 0,
1996 0, 1 ); 1996 0, 1 );
1997#endif 1997#endif
1998} 1998}
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp
index 42a6f7c..8b79788 100644
--- a/korganizer/koagendaview.cpp
+++ b/korganizer/koagendaview.cpp
@@ -1,1549 +1,1548 @@
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 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qhbox.h> 24#include <qhbox.h>
25#include <qvbox.h> 25#include <qvbox.h>
26#include <qlabel.h> 26#include <qlabel.h>
27#include <qframe.h> 27#include <qframe.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#ifndef KORG_NOSPLITTER 29#ifndef KORG_NOSPLITTER
30#include <qsplitter.h> 30#include <qsplitter.h>
31#endif 31#endif
32#include <qfont.h> 32#include <qfont.h>
33#include <qfontmetrics.h> 33#include <qfontmetrics.h>
34#include <qpopupmenu.h> 34#include <qpopupmenu.h>
35#include <qtooltip.h> 35#include <qtooltip.h>
36#include <qpainter.h> 36#include <qpainter.h>
37#include <qpushbutton.h> 37#include <qpushbutton.h>
38#include <qapplication.h> 38#include <qapplication.h>
39 39
40#include <kapplication.h> 40#include <kapplication.h>
41#include <KDGanttMinimizeSplitter.h> 41#include <KDGanttMinimizeSplitter.h>
42#include <kdebug.h> 42#include <kdebug.h>
43#include <kstandarddirs.h> 43#include <kstandarddirs.h>
44#include <kiconloader.h> 44#include <kiconloader.h>
45#include <klocale.h> 45#include <klocale.h>
46#include <kconfig.h> 46#include <kconfig.h>
47#include <kglobal.h> 47#include <kglobal.h>
48#include "calendarview.h" 48#include "calendarview.h"
49#include "koviewmanager.h" 49#include "koviewmanager.h"
50 50
51#include <libkcal/calendar.h> 51#include <libkcal/calendar.h>
52#include <libkcal/icaldrag.h> 52#include <libkcal/icaldrag.h>
53#include <libkcal/dndfactory.h> 53#include <libkcal/dndfactory.h>
54 54
55#include <kcalendarsystem.h> 55#include <kcalendarsystem.h>
56 56
57#include "koglobals.h" 57#include "koglobals.h"
58#ifndef KORG_NOPLUGINS 58#ifndef KORG_NOPLUGINS
59#include "kocore.h" 59#include "kocore.h"
60#endif 60#endif
61#include "koprefs.h" 61#include "koprefs.h"
62#include "koagenda.h" 62#include "koagenda.h"
63#include "koagendaitem.h" 63#include "koagendaitem.h"
64#ifndef KORG_NOPRINTER 64#ifndef KORG_NOPRINTER
65#include "calprinter.h" 65#include "calprinter.h"
66#endif 66#endif
67 67
68#include "koagendaview.h" 68#include "koagendaview.h"
69//#include "koagendaview.moc" 69//#include "koagendaview.moc"
70 70
71//extern bool globalFlagBlockPainting; 71//extern bool globalFlagBlockPainting;
72extern int globalFlagBlockAgenda; 72extern int globalFlagBlockAgenda;
73extern int globalFlagBlockStartup; 73extern int globalFlagBlockStartup;
74extern int globalFlagBlockAgendaItemPaint; 74extern int globalFlagBlockAgendaItemPaint;
75extern int globalFlagBlockAgendaItemUpdate; 75extern int globalFlagBlockAgendaItemUpdate;
76extern int globalFlagBlockLabel; 76extern int globalFlagBlockLabel;
77using namespace KOrg; 77using namespace KOrg;
78 78
79TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) : 79TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) :
80 QScrollView(parent,name,f) 80 QScrollView(parent,name,f)
81{ 81{
82 mRows = rows; 82 mRows = rows;
83 83
84 setMinimumHeight( 20 ); 84 setMinimumHeight( 20 );
85 mCellHeight = KOPrefs::instance()->mHourSize*4; 85 mCellHeight = KOPrefs::instance()->mHourSize*4;
86 86
87 enableClipper(true); 87 enableClipper(true);
88 88
89 setHScrollBarMode(AlwaysOff); 89 setHScrollBarMode(AlwaysOff);
90 setVScrollBarMode(AlwaysOff); 90 setVScrollBarMode(AlwaysOff);
91 91
92 resizeContents(50,mRows * mCellHeight); 92 resizeContents(50,mRows * mCellHeight);
93 93
94 viewport()->setBackgroundMode( PaletteBackground ); 94 viewport()->setBackgroundMode( PaletteBackground );
95} 95}
96 96
97void TimeLabels::setCellHeight(int height) 97void TimeLabels::setCellHeight(int height)
98{ 98{
99 mCellHeight = height; 99 mCellHeight = height;
100} 100}
101 101
102/* 102/*
103 Optimization so that only the "dirty" portion of the scroll view 103 Optimization so that only the "dirty" portion of the scroll view
104 is redrawn. Unfortunately, this is not called by default paintEvent() method. 104 is redrawn. Unfortunately, this is not called by default paintEvent() method.
105*/ 105*/
106void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) 106void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch)
107{ 107{
108 108
109 // if ( globalFlagBlockAgenda ) 109 // if ( globalFlagBlockAgenda )
110 // return; 110 // return;
111 // bug: the parameters cx, cy, cw, ch are the areas that need to be 111 // bug: the parameters cx, cy, cw, ch are the areas that need to be
112 // redrawn, not the area of the widget. unfortunately, this 112 // redrawn, not the area of the widget. unfortunately, this
113 // code assumes the latter... 113 // code assumes the latter...
114 114
115 // now, for a workaround... 115 // now, for a workaround...
116 // these two assignments fix the weird redraw bug 116 // these two assignments fix the weird redraw bug
117 cx = contentsX() + 2; 117 cx = contentsX() + 2;
118 cw = contentsWidth() - 2; 118 cw = contentsWidth() - 2;
119 // end of workaround 119 // end of workaround
120 120
121 int cell = ((int)(cy/mCellHeight)); 121 int cell = ((int)(cy/mCellHeight));
122 int y = cell * mCellHeight; 122 int y = cell * mCellHeight;
123 QFontMetrics fm = fontMetrics(); 123 QFontMetrics fm = fontMetrics();
124 QString hour; 124 QString hour;
125 QString suffix; 125 QString suffix;
126 QString fullTime; 126 QString fullTime;
127 int tW = fm.width("24:00i"); 127 int tW = fm.width("24:00i");
128 128
129 while (y < cy + ch) { 129 while (y < cy + ch) {
130 p->drawLine(cx,y,cx+tW,y); 130 p->drawLine(cx,y,cx+tW,y);
131 hour.setNum(cell); 131 hour.setNum(cell);
132 suffix = "am"; 132 suffix = "am";
133 133
134 // handle 24h and am/pm time formats 134 // handle 24h and am/pm time formats
135 if (KGlobal::locale()->use12Clock()) { 135 if (KGlobal::locale()->use12Clock()) {
136 if (cell > 11) suffix = "pm"; 136 if (cell > 11) suffix = "pm";
137 if (cell == 0) hour.setNum(12); 137 if (cell == 0) hour.setNum(12);
138 if (cell > 12) hour.setNum(cell - 12); 138 if (cell > 12) hour.setNum(cell - 12);
139 } else { 139 } else {
140 suffix = ":00"; 140 suffix = ":00";
141 } 141 }
142 142
143 // create string in format of "XX:XX" or "XXpm/am" 143 // create string in format of "XX:XX" or "XXpm/am"
144 fullTime = hour + suffix; 144 fullTime = hour + suffix;
145 145
146 // center and draw the time label 146 // center and draw the time label
147 int timeWidth = fm.width(fullTime+"i"); 147 int timeWidth = fm.width(fullTime+"i");
148 int offset = this->width() - timeWidth; 148 int offset = this->width() - timeWidth;
149 int borderWidth = 5; 149 int borderWidth = 5;
150 int timeHeight = fm.height(); 150 int timeHeight = fm.height();
151 timeHeight = timeHeight + 2 - ( timeHeight / 4 ); 151 timeHeight = timeHeight + 2 - ( timeHeight / 4 );
152 p->drawText(cx -borderWidth + offset, y+ timeHeight, fullTime); 152 p->drawText(cx -borderWidth + offset, y+ timeHeight, fullTime);
153 153
154 // increment indices 154 // increment indices
155 y += mCellHeight; 155 y += mCellHeight;
156 cell++; 156 cell++;
157 } 157 }
158} 158}
159 159
160/** 160/**
161 Calculates the minimum width. 161 Calculates the minimum width.
162*/ 162*/
163int TimeLabels::minimumWidth() const 163int TimeLabels::minimumWidth() const
164{ 164{
165 QFontMetrics fm = fontMetrics(); 165 QFontMetrics fm = fontMetrics();
166 166
167 //TODO: calculate this value 167 //TODO: calculate this value
168 int borderWidth = 4; 168 int borderWidth = 4;
169 169
170 // the maximum width possible 170 // the maximum width possible
171 int width = fm.width("88:88x") + borderWidth; 171 int width = fm.width("88:88x") + borderWidth;
172 172
173 return width; 173 return width;
174} 174}
175 175
176/** updates widget's internal state */ 176/** updates widget's internal state */
177void TimeLabels::updateConfig() 177void TimeLabels::updateConfig()
178{ 178{
179 // set the font 179 // set the font
180 // config->setGroup("Fonts"); 180 // config->setGroup("Fonts");
181 // QFont font = config->readFontEntry("TimeBar Font"); 181 // QFont font = config->readFontEntry("TimeBar Font");
182 setFont(KOPrefs::instance()->mTimeBarFont); 182 setFont(KOPrefs::instance()->mTimeBarFont);
183 183
184 // update geometry restrictions based on new settings 184 // update geometry restrictions based on new settings
185 setFixedWidth(minimumWidth()); 185 setFixedWidth(minimumWidth());
186 186
187 // update HourSize 187 // update HourSize
188 mCellHeight = KOPrefs::instance()->mHourSize*4; 188 mCellHeight = KOPrefs::instance()->mHourSize*4;
189 resizeContents(50,mRows * mCellHeight); 189 resizeContents(50,mRows * mCellHeight);
190} 190}
191 191
192/** update time label positions */ 192/** update time label positions */
193void TimeLabels::positionChanged() 193void TimeLabels::positionChanged()
194{ 194{
195 int adjustment = mAgenda->contentsY(); 195 int adjustment = mAgenda->contentsY();
196 setContentsPos(0, adjustment); 196 setContentsPos(0, adjustment);
197} 197}
198 198
199/** */ 199/** */
200void TimeLabels::setAgenda(KOAgenda* agenda) 200void TimeLabels::setAgenda(KOAgenda* agenda)
201{ 201{
202 mAgenda = agenda; 202 mAgenda = agenda;
203} 203}
204 204
205void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) 205void TimeLabels::contentsMousePressEvent ( QMouseEvent * e)
206{ 206{
207 mMouseDownY = e->pos().y(); 207 mMouseDownY = e->pos().y();
208 mOrgCap = topLevelWidget()->caption(); 208 mOrgCap = topLevelWidget()->caption();
209} 209}
210 210
211void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) 211void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e )
212{ 212{
213 int diff = mMouseDownY - e->pos().y(); 213 int diff = mMouseDownY - e->pos().y();
214 if ( diff < 10 && diff > -10 ) 214 if ( diff < 10 && diff > -10 )
215 return; 215 return;
216 int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; 216 int tSize = KOPrefs::instance()->mHourSize + (diff/10) ;
217 if ( tSize < 4 ) 217 if ( tSize < 4 )
218 tSize = 4; 218 tSize = 4;
219 if ( tSize > 22 ) 219 if ( tSize > 22 )
220 tSize = 22; 220 tSize = 22;
221 tSize = (tSize-2)/2; 221 tSize = (tSize-2)/2;
222 topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); 222 topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize));
223 223
224} 224}
225void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) 225void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e )
226{ 226{
227 topLevelWidget()->setCaption( mOrgCap ); 227 topLevelWidget()->setCaption( mOrgCap );
228 int diff = mMouseDownY - e->pos().y(); 228 int diff = mMouseDownY - e->pos().y();
229 if ( diff < 10 && diff > -10 ) 229 if ( diff < 10 && diff > -10 )
230 return; 230 return;
231 int tSize = KOPrefs::instance()->mHourSize + (diff/10); 231 int tSize = KOPrefs::instance()->mHourSize + (diff/10);
232 if ( tSize < 4 ) 232 if ( tSize < 4 )
233 tSize = 4; 233 tSize = 4;
234 if ( tSize > 22 ) 234 if ( tSize > 22 )
235 tSize = 22; 235 tSize = 22;
236 tSize = (tSize/2)*2; 236 tSize = (tSize/2)*2;
237 if ( tSize == KOPrefs::instance()->mHourSize ) 237 if ( tSize == KOPrefs::instance()->mHourSize )
238 return; 238 return;
239 KOPrefs::instance()->mHourSize = tSize; 239 KOPrefs::instance()->mHourSize = tSize;
240 emit scaleChanged(); 240 emit scaleChanged();
241} 241}
242 242
243/** This is called in response to repaint() */ 243/** This is called in response to repaint() */
244void TimeLabels::paintEvent(QPaintEvent*) 244void TimeLabels::paintEvent(QPaintEvent*)
245{ 245{
246 246
247 // kdDebug() << "paintevent..." << endl; 247 // kdDebug() << "paintevent..." << endl;
248 // this is another hack! 248 // this is another hack!
249 // QPainter painter(this); 249 // QPainter painter(this);
250 //QString c 250 //QString c
251 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight()); 251 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight());
252} 252}
253 253
254//////////////////////////////////////////////////////////////////////////// 254////////////////////////////////////////////////////////////////////////////
255 255
256EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name) 256EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name)
257 : QFrame(parent,name) 257 : QFrame(parent,name)
258{ 258{
259 mColumns = 1; 259 mColumns = 1;
260 mTopBox = 0; 260 mTopBox = 0;
261 mLocation = loc; 261 mLocation = loc;
262 mTopLayout = 0; 262 mTopLayout = 0;
263 mPaintWidget = 0; 263 mPaintWidget = 0;
264 mXOffset = 0; 264 mXOffset = 0;
265 if (mLocation == Top) mPixmap = SmallIcon("1uparrow"); 265 if (mLocation == Top) mPixmap = SmallIcon("1uparrow");
266 else mPixmap = SmallIcon("1downarrow"); 266 else mPixmap = SmallIcon("1downarrow");
267 mEnabled.resize(mColumns); 267 mEnabled.resize(mColumns);
268 if (mLocation == Top) 268 if (mLocation == Top)
269 setMaximumHeight(0); 269 setMaximumHeight(0);
270 else 270 else
271 setMinimumHeight(mPixmap.height()); 271 setMinimumHeight(mPixmap.height());
272} 272}
273 273
274EventIndicator::~EventIndicator() 274EventIndicator::~EventIndicator()
275{ 275{
276} 276}
277 277
278void EventIndicator::drawContents(QPainter *p) 278void EventIndicator::drawContents(QPainter *p)
279{ 279{
280 280
281 // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl; 281 // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl;
282 KDGanttSplitterHandle* han = 0; 282 KDGanttSplitterHandle* han = 0;
283 if ( mPaintWidget ) 283 if ( mPaintWidget )
284 han = mPaintWidget->firstHandle(); 284 han = mPaintWidget->firstHandle();
285 if ( ! han ) { 285 if ( ! han ) {
286 int i; 286 int i;
287 for(i=0;i<mColumns;++i) { 287 for(i=0;i<mColumns;++i) {
288 if (mEnabled[i]) { 288 if (mEnabled[i]) {
289 int cellWidth = contentsRect().right()/mColumns; 289 int cellWidth = contentsRect().right()/mColumns;
290 int xOffset = KOGlobals::self()->reverseLayout() ? 290 int xOffset = KOGlobals::self()->reverseLayout() ?
291 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 : 291 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 :
292 i*cellWidth + cellWidth/2 -mPixmap.width()/2; 292 i*cellWidth + cellWidth/2 -mPixmap.width()/2;
293 p->drawPixmap(QPoint(xOffset,0),mPixmap); 293 p->drawPixmap(QPoint(xOffset,0),mPixmap);
294 } 294 }
295 } 295 }
296 } else { 296 } else {
297 han->repaint(); 297 han->repaint();
298 //mPaintWidget->setBackgroundColor( red ); 298 //mPaintWidget->setBackgroundColor( red );
299 299
300 QPainter pa( han ); 300 QPainter pa( han );
301 int i; 301 int i;
302 bool setColor = false; 302 bool setColor = false;
303 for(i=0;i<mColumns;++i) { 303 for(i=0;i<mColumns;++i) {
304 if (mEnabled[i]) { 304 if (mEnabled[i]) {
305 setColor = true; 305 setColor = true;
306 306
307 int cellWidth = contentsRect().right()/mColumns; 307 int cellWidth = contentsRect().right()/mColumns;
308 int xOffset = KOGlobals::self()->reverseLayout() ? 308 int xOffset = KOGlobals::self()->reverseLayout() ?
309 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 : 309 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 :
310 i*cellWidth + cellWidth/2 -mPixmap.width()/2; 310 i*cellWidth + cellWidth/2 -mPixmap.width()/2;
311 pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap); 311 pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap);
312 //qDebug("222draw pix %d ",xOffset ); 312 //qDebug("222draw pix %d ",xOffset );
313 313
314 } 314 }
315 315
316 } 316 }
317 pa.end(); 317 pa.end();
318 318
319 } 319 }
320} 320}
321 321
322void EventIndicator::setXOffset( int x ) 322void EventIndicator::setXOffset( int x )
323{ 323{
324 mXOffset = x; 324 mXOffset = x;
325} 325}
326void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w ) 326void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w )
327{ 327{
328 mPaintWidget = w; 328 mPaintWidget = w;
329} 329}
330void EventIndicator::changeColumns(int columns) 330void EventIndicator::changeColumns(int columns)
331{ 331{
332 mColumns = columns; 332 mColumns = columns;
333 mEnabled.resize(mColumns); 333 mEnabled.resize(mColumns);
334 334
335 update(); 335 update();
336} 336}
337 337
338void EventIndicator::enableColumn(int column, bool enable) 338void EventIndicator::enableColumn(int column, bool enable)
339{ 339{
340 mEnabled[column] = enable; 340 mEnabled[column] = enable;
341} 341}
342 342
343 343
344//////////////////////////////////////////////////////////////////////////// 344////////////////////////////////////////////////////////////////////////////
345//////////////////////////////////////////////////////////////////////////// 345////////////////////////////////////////////////////////////////////////////
346//////////////////////////////////////////////////////////////////////////// 346////////////////////////////////////////////////////////////////////////////
347 347
348KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) : 348KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) :
349 KOEventView (cal,parent,name) 349 KOEventView (cal,parent,name)
350{ 350{
351 mBlockUpdating = true; 351 mBlockUpdating = true;
352 mStartHour = 8; 352 mStartHour = 8;
353 mSelectedDates.append(QDate::currentDate()); 353 mSelectedDates.append(QDate::currentDate());
354 354
355 mLayoutDayLabels = 0; 355 mLayoutDayLabels = 0;
356 mDayLabelsFrame = 0; 356 mDayLabelsFrame = 0;
357 mDayLabels = 0; 357 mDayLabels = 0;
358 bool isRTL = KOGlobals::self()->reverseLayout(); 358 bool isRTL = KOGlobals::self()->reverseLayout();
359 359
360 if ( KOPrefs::instance()->mVerticalScreen ) { 360 if ( KOPrefs::instance()->mVerticalScreen ) {
361 mExpandedPixmap = SmallIcon( "1downarrow" ); 361 mExpandedPixmap = SmallIcon( "1downarrow" );
362 mNotExpandedPixmap = SmallIcon( "1uparrow" ); 362 mNotExpandedPixmap = SmallIcon( "1uparrow" );
363 } else { 363 } else {
364 mExpandedPixmap = SmallIcon( isRTL ? "1leftarrow" : "1rightarrow" ); 364 mExpandedPixmap = SmallIcon( isRTL ? "1leftarrow" : "1rightarrow" );
365 mNotExpandedPixmap = SmallIcon( isRTL ? "1rightarrow" : "1leftarrow" ); 365 mNotExpandedPixmap = SmallIcon( isRTL ? "1rightarrow" : "1leftarrow" );
366 } 366 }
367 367
368 QBoxLayout *topLayout = new QVBoxLayout(this); 368 QBoxLayout *topLayout = new QVBoxLayout(this);
369 369
370 // Create day name labels for agenda columns 370 // Create day name labels for agenda columns
371 mDayLabelsFrame = new QHBox(this); 371 mDayLabelsFrame = new QHBox(this);
372 topLayout->addWidget(mDayLabelsFrame); 372 topLayout->addWidget(mDayLabelsFrame);
373 mDayLabels = new QFrame (mDayLabelsFrame); 373 mDayLabels = new QFrame (mDayLabelsFrame);
374 mLayoutDayLabels = new QHBoxLayout(mDayLabels); 374 mLayoutDayLabels = new QHBoxLayout(mDayLabels);
375 // Create agenda splitter 375 // Create agenda splitter
376#ifndef KORG_NOSPLITTER 376#ifndef KORG_NOSPLITTER
377 mSplitterAgenda = new QSplitter(Vertical,this); 377 mSplitterAgenda = new QSplitter(Vertical,this);
378 topLayout->addWidget(mSplitterAgenda); 378 topLayout->addWidget(mSplitterAgenda);
379 mSplitterAgenda->setOpaqueResize(); 379 mSplitterAgenda->setOpaqueResize();
380 380
381 mAllDayFrame = new QHBox(mSplitterAgenda); 381 mAllDayFrame = new QHBox(mSplitterAgenda);
382 382
383 QWidget *agendaFrame = new QWidget(mSplitterAgenda); 383 QWidget *agendaFrame = new QWidget(mSplitterAgenda);
384#else 384#else
385#if 0 385#if 0
386 QWidget *mainBox = new QWidget( this ); 386 QWidget *mainBox = new QWidget( this );
387 topLayout->addWidget( mainBox ); 387 topLayout->addWidget( mainBox );
388 QBoxLayout *mainLayout = new QVBoxLayout(mainBox); 388 QBoxLayout *mainLayout = new QVBoxLayout(mainBox);
389 mAllDayFrame = new QHBox(mainBox); 389 mAllDayFrame = new QHBox(mainBox);
390 mainLayout->addWidget(mAllDayFrame); 390 mainLayout->addWidget(mAllDayFrame);
391 mainLayout->setStretchFactor( mAllDayFrame, 0 ); 391 mainLayout->setStretchFactor( mAllDayFrame, 0 );
392 mAllDayFrame->setFocusPolicy(NoFocus); 392 mAllDayFrame->setFocusPolicy(NoFocus);
393 QWidget *agendaFrame = new QWidget(mainBox); 393 QWidget *agendaFrame = new QWidget(mainBox);
394 mainLayout->addWidget(agendaFrame); 394 mainLayout->addWidget(agendaFrame);
395 mainLayout->setStretchFactor( agendaFrame, 10 ); 395 mainLayout->setStretchFactor( agendaFrame, 10 );
396 396
397 agendaFrame->setFocusPolicy(NoFocus); 397 agendaFrame->setFocusPolicy(NoFocus);
398#endif 398#endif
399 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this); 399 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this);
400 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 400 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
401 topLayout->addWidget( mSplitterAgenda ); 401 topLayout->addWidget( mSplitterAgenda );
402 mAllDayFrame = new QHBox(mSplitterAgenda); 402 mAllDayFrame = new QHBox(mSplitterAgenda);
403 mAllDayFrame->setFocusPolicy(NoFocus); 403 mAllDayFrame->setFocusPolicy(NoFocus);
404 QWidget *agendaFrame = new QWidget(mSplitterAgenda); 404 QWidget *agendaFrame = new QWidget(mSplitterAgenda);
405 agendaFrame->setFocusPolicy(NoFocus); 405 agendaFrame->setFocusPolicy(NoFocus);
406 406
407#endif 407#endif
408 408
409 // Create all-day agenda widget 409 // Create all-day agenda widget
410 mDummyAllDayLeft = new QVBox( mAllDayFrame ); 410 mDummyAllDayLeft = new QVBox( mAllDayFrame );
411 411
412 mExpandButton = new QPushButton(mDummyAllDayLeft); 412 mExpandButton = new QPushButton(mDummyAllDayLeft);
413 mExpandButton->setPixmap( mNotExpandedPixmap ); 413 mExpandButton->setPixmap( mNotExpandedPixmap );
414 int widebut = mExpandButton->sizeHint().width(); 414 int widebut = mExpandButton->sizeHint().width();
415 if ( QApplication::desktop()->width() < 480 ) 415 if ( QApplication::desktop()->width() < 480 )
416 widebut = widebut*2; 416 widebut = widebut*2;
417 else 417 else
418 widebut = (widebut*3) / 2; 418 widebut = (widebut*3) / 2;
419 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, 419 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed,
420 // QSizePolicy::Fixed ) ); 420 // QSizePolicy::Fixed ) );
421 mExpandButton->setFixedSize( widebut, widebut); 421 mExpandButton->setFixedSize( widebut, widebut);
422 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) ); 422 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) );
423 mExpandButton->setFocusPolicy(NoFocus); 423 mExpandButton->setFocusPolicy(NoFocus);
424 mAllDayAgenda = new KOAgenda(1,mAllDayFrame); 424 mAllDayAgenda = new KOAgenda(1,mAllDayFrame);
425 mAllDayAgenda->setFocusPolicy(NoFocus); 425 mAllDayAgenda->setFocusPolicy(NoFocus);
426 QWidget *dummyAllDayRight = new QWidget(mAllDayFrame); 426 QWidget *dummyAllDayRight = new QWidget(mAllDayFrame);
427 427
428 // Create event context menu for all day agenda 428 // Create event context menu for all day agenda
429 mAllDayAgendaPopup = eventPopup(); 429 mAllDayAgendaPopup = eventPopup();
430 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), 430 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
431 mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *))); 431 mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
432 432
433 // Create agenda frame 433 // Create agenda frame
434 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,3,3); 434 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,3,3);
435 // QHBox *agendaFrame = new QHBox(splitterAgenda); 435 // QHBox *agendaFrame = new QHBox(splitterAgenda);
436 436
437 // create event indicator bars 437 // create event indicator bars
438 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame); 438 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame);
439 agendaLayout->addWidget(mEventIndicatorTop,0,1); 439 agendaLayout->addWidget(mEventIndicatorTop,0,1);
440 mEventIndicatorTop->setPaintWidget( mSplitterAgenda ); 440 mEventIndicatorTop->setPaintWidget( mSplitterAgenda );
441 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom, 441 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom,
442 agendaFrame); 442 agendaFrame);
443 agendaLayout->addWidget(mEventIndicatorBottom,2,1); 443 agendaLayout->addWidget(mEventIndicatorBottom,2,1);
444 QWidget *dummyAgendaRight = new QWidget(agendaFrame); 444 QWidget *dummyAgendaRight = new QWidget(agendaFrame);
445 agendaLayout->addWidget(dummyAgendaRight,0,2); 445 agendaLayout->addWidget(dummyAgendaRight,0,2);
446 446
447 // Create time labels 447 // Create time labels
448 mTimeLabels = new TimeLabels(24,agendaFrame); 448 mTimeLabels = new TimeLabels(24,agendaFrame);
449 agendaLayout->addWidget(mTimeLabels,1,0); 449 agendaLayout->addWidget(mTimeLabels,1,0);
450 connect(mTimeLabels,SIGNAL( scaleChanged()), 450 connect(mTimeLabels,SIGNAL( scaleChanged()),
451 this,SLOT(updateConfig())); 451 this,SLOT(updateConfig()));
452 452
453 // Create agenda 453 // Create agenda
454 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame); 454 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame);
455 agendaLayout->addMultiCellWidget(mAgenda,1,1,1,2); 455 agendaLayout->addMultiCellWidget(mAgenda,1,1,1,2);
456 agendaLayout->setColStretch(1,1); 456 agendaLayout->setColStretch(1,1);
457 mAgenda->setFocusPolicy(NoFocus); 457 mAgenda->setFocusPolicy(NoFocus);
458 // Create event context menu for agenda 458 // Create event context menu for agenda
459 mAgendaPopup = eventPopup(); 459 mAgendaPopup = eventPopup();
460 460
461 mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")), 461 mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")),
462 i18n("Toggle Alarm"),mAgenda, 462 i18n("Toggle Alarm"),mAgenda,
463 SLOT(popupAlarm()),true); 463 SLOT(popupAlarm()),true);
464 464
465 465
466 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), 466 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
467 mAgendaPopup,SLOT(showIncidencePopup(Incidence *))); 467 mAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
468 468
469 // make connections between dependent widgets 469 // make connections between dependent widgets
470 mTimeLabels->setAgenda(mAgenda); 470 mTimeLabels->setAgenda(mAgenda);
471 471
472 // Update widgets to reflect user preferences 472 // Update widgets to reflect user preferences
473 // updateConfig(); 473 // updateConfig();
474 474
475 // createDayLabels(); 475 // createDayLabels();
476 476
477 // these blank widgets make the All Day Event box line up with the agenda 477 // these blank widgets make the All Day Event box line up with the agenda
478 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 478 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
479 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 479 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
480 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 480 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
481 481
482 // Scrolling 482 // Scrolling
483 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)), 483 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)),
484 mTimeLabels, SLOT(positionChanged())); 484 mTimeLabels, SLOT(positionChanged()));
485 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)), 485 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)),
486 SLOT(setContentsPos(int))); 486 SLOT(setContentsPos(int)));
487 487
488 connect(mAgenda,SIGNAL(showDateView( int, QDate )),SIGNAL(showDateView( int, QDate ))); 488 connect(mAgenda,SIGNAL(showDateView( int, QDate )),SIGNAL(showDateView( int, QDate )));
489 connect(mAllDayAgenda,SIGNAL(showDateView( int, QDate )),SIGNAL(showDateView( int, QDate ))); 489 connect(mAllDayAgenda,SIGNAL(showDateView( int, QDate )),SIGNAL(showDateView( int, QDate )));
490 490
491 // Create/Show/Edit/Delete Event 491 // Create/Show/Edit/Delete Event
492 connect(mAgenda,SIGNAL(newEventSignal(int,int)), 492 connect(mAgenda,SIGNAL(newEventSignal(int,int)),
493 SLOT(newEvent(int,int))); 493 SLOT(newEvent(int,int)));
494 connect(mAgenda,SIGNAL(newTodoSignal(int,int)), 494 connect(mAgenda,SIGNAL(newTodoSignal(int,int)),
495 SLOT(newTodo(int,int))); 495 SLOT(newTodo(int,int)));
496 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)), 496 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)),
497 SLOT(newEvent(int,int,int,int))); 497 SLOT(newEvent(int,int,int,int)));
498 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)), 498 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)),
499 SLOT(newEventAllDay(int,int))); 499 SLOT(newEventAllDay(int,int)));
500 connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)), 500 connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)),
501 SLOT(newTodoAllDay(int,int))); 501 SLOT(newTodoAllDay(int,int)));
502 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)), 502 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)),
503 SLOT(newEventAllDay(int,int))); 503 SLOT(newEventAllDay(int,int)));
504 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 504 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
505 SLOT(newTimeSpanSelected(int,int,int,int))); 505 SLOT(newTimeSpanSelected(int,int,int,int)));
506 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 506 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
507 SLOT(newTimeSpanSelectedAllDay(int,int,int,int))); 507 SLOT(newTimeSpanSelectedAllDay(int,int,int,int)));
508 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 508 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
509 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 509 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
510 510
511 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 511 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
512 SIGNAL(editIncidenceSignal(Incidence *))); 512 SIGNAL(editIncidenceSignal(Incidence *)));
513 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 513 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
514 SIGNAL(editIncidenceSignal(Incidence *))); 514 SIGNAL(editIncidenceSignal(Incidence *)));
515 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 515 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
516 SIGNAL(showIncidenceSignal(Incidence *))); 516 SIGNAL(showIncidenceSignal(Incidence *)));
517 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 517 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
518 SIGNAL(showIncidenceSignal(Incidence *))); 518 SIGNAL(showIncidenceSignal(Incidence *)));
519 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 519 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
520 SIGNAL(deleteIncidenceSignal(Incidence *))); 520 SIGNAL(deleteIncidenceSignal(Incidence *)));
521 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 521 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
522 SIGNAL(deleteIncidenceSignal(Incidence *))); 522 SIGNAL(deleteIncidenceSignal(Incidence *)));
523 523
524 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 524 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
525 SLOT(updateEventDates(KOAgendaItem *, int ))); 525 SLOT(updateEventDates(KOAgendaItem *, int )));
526 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 526 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
527 SLOT(updateEventDates(KOAgendaItem *, int))); 527 SLOT(updateEventDates(KOAgendaItem *, int)));
528 528
529 // event indicator update 529 // event indicator update
530 connect(mAgenda,SIGNAL(lowerYChanged(int)), 530 connect(mAgenda,SIGNAL(lowerYChanged(int)),
531 SLOT(updateEventIndicatorTop(int))); 531 SLOT(updateEventIndicatorTop(int)));
532 connect(mAgenda,SIGNAL(upperYChanged(int)), 532 connect(mAgenda,SIGNAL(upperYChanged(int)),
533 SLOT(updateEventIndicatorBottom(int))); 533 SLOT(updateEventIndicatorBottom(int)));
534 // drag signals 534 // drag signals
535 /* 535 /*
536 connect(mAgenda,SIGNAL(startDragSignal(Event *)), 536 connect(mAgenda,SIGNAL(startDragSignal(Event *)),
537 SLOT(startDrag(Event *))); 537 SLOT(startDrag(Event *)));
538 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)), 538 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)),
539 SLOT(startDrag(Event *))); 539 SLOT(startDrag(Event *)));
540 */ 540 */
541 // synchronize selections 541 // synchronize selections
542 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 542 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
543 mAllDayAgenda, SLOT( deselectItem() ) ); 543 mAllDayAgenda, SLOT( deselectItem() ) );
544 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 544 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
545 mAgenda, SLOT( deselectItem() ) ); 545 mAgenda, SLOT( deselectItem() ) );
546 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 546 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
547 SIGNAL( incidenceSelected( Incidence * ) ) ); 547 SIGNAL( incidenceSelected( Incidence * ) ) );
548 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 548 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
549 SIGNAL( incidenceSelected( Incidence * ) ) ); 549 SIGNAL( incidenceSelected( Incidence * ) ) );
550 connect( mAgenda, SIGNAL( resizedSignal() ), 550 connect( mAgenda, SIGNAL( resizedSignal() ),
551 SLOT( updateConfig( ) ) ); 551 SLOT( updateConfig( ) ) );
552 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ), 552 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ),
553 SLOT( addToCalSlot(Incidence *, Incidence * ) ) ); 553 SLOT( addToCalSlot(Incidence *, Incidence * ) ) );
554 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ), 554 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ),
555 SLOT( addToCalSlot(Incidence * , Incidence *) ) ); 555 SLOT( addToCalSlot(Incidence * , Incidence *) ) );
556 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 556 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
557 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 557 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
558 558
559 559
560} 560}
561 561
562void KOAgendaView::toggleAllDay() 562void KOAgendaView::toggleAllDay()
563{ 563{
564 if ( mSplitterAgenda->firstHandle() ) 564 if ( mSplitterAgenda->firstHandle() )
565 mSplitterAgenda->firstHandle()->toggle(); 565 mSplitterAgenda->firstHandle()->toggle();
566} 566}
567void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld ) 567void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld )
568{ 568{
569 calendar()->addIncidence( inc ); 569 calendar()->addIncidence( inc );
570 570
571 if ( incOld ) { 571 if ( incOld ) {
572 if ( incOld->type() == "Todo" ) 572 if ( incOld->type() == "Todo" )
573 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED ); 573 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED );
574 else 574 else
575 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED); 575 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED);
576 } 576 }
577 577
578} 578}
579 579
580KOAgendaView::~KOAgendaView() 580KOAgendaView::~KOAgendaView()
581{ 581{
582 delete mAgendaPopup; 582 delete mAgendaPopup;
583 delete mAllDayAgendaPopup; 583 delete mAllDayAgendaPopup;
584 delete KOAgendaItem::paintPix(); 584 delete KOAgendaItem::paintPix();
585 delete KOAgendaItem::paintPixSel(); 585 delete KOAgendaItem::paintPixSel();
586} 586}
587void KOAgendaView::resizeEvent( QResizeEvent* e ) 587void KOAgendaView::resizeEvent( QResizeEvent* e )
588{ 588{
589 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); 589 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width());
590 bool uc = false; 590 bool uc = false;
591 int ow = e->oldSize().width(); 591 int ow = e->oldSize().width();
592 int oh = e->oldSize().height(); 592 int oh = e->oldSize().height();
593 int w = e->size().width(); 593 int w = e->size().width();
594 int h = e->size().height(); 594 int h = e->size().height();
595 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { 595 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) {
596 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) 596 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda )
597 uc = true; 597 uc = true;
598 //qDebug("view changed %d %d %d %d ", ow, oh , w , h); 598 //qDebug("view changed %d %d %d %d ", ow, oh , w , h);
599 } 599 }
600 mUpcomingWidth = e->size().width() ; 600 mUpcomingWidth = e->size().width() ;
601 if ( mBlockUpdating || uc ) { 601 if ( mBlockUpdating || uc ) {
602 mBlockUpdating = false; 602 mBlockUpdating = false;
603 //mAgenda->setMinimumSize(800 , 600 ); 603 //mAgenda->setMinimumSize(800 , 600 );
604 //qDebug("mAgenda->resize+++++++++++++++ "); 604 //qDebug("mAgenda->resize+++++++++++++++ ");
605 updateConfig(); 605 updateConfig();
606 //qDebug("KOAgendaView::Updating now possible "); 606 //qDebug("KOAgendaView::Updating now possible ");
607 } else 607 } else
608 createDayLabels(); 608 createDayLabels();
609 //qDebug("resizeEvent end "); 609 //qDebug("resizeEvent end ");
610 610
611} 611}
612void KOAgendaView::createDayLabels() 612void KOAgendaView::createDayLabels()
613{ 613{
614 614
615 if ( mBlockUpdating || globalFlagBlockLabel == 1) { 615 if ( mBlockUpdating || globalFlagBlockLabel == 1) {
616 // qDebug(" KOAgendaView::createDayLabels() blocked "); 616 // qDebug(" KOAgendaView::createDayLabels() blocked ");
617 return; 617 return;
618 618
619 } 619 }
620 int newHight; 620 int newHight;
621 621
622 // ### Before deleting and recreating we could check if mSelectedDates changed... 622 // ### Before deleting and recreating we could check if mSelectedDates changed...
623 // It would remove some flickering and gain speed (since this is called by 623 // It would remove some flickering and gain speed (since this is called by
624 // each updateView() call) 624 // each updateView() call)
625 625
626 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - 2; 626 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - 2;
627 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); 627 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth );
628 if ( maxWid < 0 ) 628 if ( maxWid < 0 )
629 maxWid = 20; 629 maxWid = 20;
630 630
631 QFont dlf = KOPrefs::instance()->mTimeLabelsFont; 631 QFont dlf = KOPrefs::instance()->mTimeLabelsFont;
632 QFontMetrics fm ( dlf ); 632 QFontMetrics fm ( dlf );
633 int selCount = mSelectedDates.count(); 633 int selCount = mSelectedDates.count();
634 QString dayTest = "Mon 20"; 634 QString dayTest = "Mon 20";
635 int wid = fm.width( dayTest ); 635 int wid = fm.width( dayTest );
636 maxWid -= ( selCount * 3 ); 636 maxWid -= ( selCount * 3 );
637 if ( maxWid < 0 ) 637 if ( maxWid < 0 )
638 maxWid = 20; 638 maxWid = 20;
639 int needWid = wid * selCount; 639 int needWid = wid * selCount;
640 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); 640 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid );
641 //if ( needWid > maxWid ) 641 //if ( needWid > maxWid )
642 // qDebug("DAYLABELS TOOOOOOO BIG "); 642 // qDebug("DAYLABELS TOOOOOOO BIG ");
643 while ( needWid > maxWid ) { 643 while ( needWid > maxWid ) {
644 dayTest = dayTest.left( dayTest.length() - 1 ); 644 dayTest = dayTest.left( dayTest.length() - 1 );
645 wid = fm.width( dayTest ); 645 wid = fm.width( dayTest );
646 needWid = wid * selCount; 646 needWid = wid * selCount;
647 } 647 }
648 int maxLen = dayTest.length(); 648 int maxLen = dayTest.length();
649 int fontPoint = dlf.pointSize(); 649 int fontPoint = dlf.pointSize();
650 if ( maxLen < 2 ) { 650 if ( maxLen < 2 ) {
651 int fontPoint = dlf.pointSize(); 651 int fontPoint = dlf.pointSize();
652 while ( fontPoint > 4 ) { 652 while ( fontPoint > 4 ) {
653 --fontPoint; 653 --fontPoint;
654 dlf.setPointSize( fontPoint ); 654 dlf.setPointSize( fontPoint );
655 QFontMetrics f( dlf ); 655 QFontMetrics f( dlf );
656 wid = f.width( "20" ); 656 wid = f.width( "20" );
657 needWid = wid * selCount; 657 needWid = wid * selCount;
658 if ( needWid < maxWid ) 658 if ( needWid < maxWid )
659 break; 659 break;
660 } 660 }
661 maxLen = 2; 661 maxLen = 2;
662 } 662 }
663 //qDebug("Max len %d ", dayTest.length() ); 663 //qDebug("Max len %d ", dayTest.length() );
664 664
665 QFontMetrics tempF( dlf ); 665 QFontMetrics tempF( dlf );
666 newHight = tempF.height(); 666 newHight = tempF.height();
667 mDayLabels->setFont( dlf ); 667 mDayLabels->setFont( dlf );
668 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; 668 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);;
669 // mLayoutDayLabels->addSpacing(mTimeLabels->width()); 669 // mLayoutDayLabels->addSpacing(mTimeLabels->width());
670 //mLayoutDayLabels->addSpacing( 2 ); 670 //mLayoutDayLabels->addSpacing( 2 );
671 // QFont lFont = dlf; 671 // QFont lFont = dlf;
672 bool appendLabels = false; 672 bool appendLabels = false;
673 QLabel *dayLabel; 673 QLabel *dayLabel;
674 dayLabel = mDayLabelsList.first(); 674 dayLabel = mDayLabelsList.first();
675 if ( !dayLabel ) { 675 if ( !dayLabel ) {
676 appendLabels = true; 676 appendLabels = true;
677 dayLabel = new QLabel(mDayLabels); 677 dayLabel = new QLabel(mDayLabels);
678 mDayLabelsList.append( dayLabel ); 678 mDayLabelsList.append( dayLabel );
679 mLayoutDayLabels->addWidget(dayLabel); 679 mLayoutDayLabels->addWidget(dayLabel);
680 } 680 }
681 dayLabel->setFixedWidth( mTimeLabels->width()+2 ); 681 dayLabel->setFixedWidth( mTimeLabels->width()+2 );
682 dayLabel->setFont( dlf ); 682 dayLabel->setFont( dlf );
683 dayLabel->setAlignment(QLabel::AlignHCenter); 683 dayLabel->setAlignment(QLabel::AlignHCenter);
684 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); 684 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) );
685 dayLabel->show(); 685 dayLabel->show();
686 DateList::ConstIterator dit; 686 DateList::ConstIterator dit;
687 bool oneday = (mSelectedDates.first() == mSelectedDates.last() ); 687 bool oneday = (mSelectedDates.first() == mSelectedDates.last() );
688 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 688 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
689 QDate date = *dit; 689 QDate date = *dit;
690 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); 690 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels);
691 if ( ! appendLabels ) { 691 if ( ! appendLabels ) {
692 dayLabel = mDayLabelsList.next(); 692 dayLabel = mDayLabelsList.next();
693 if ( !dayLabel ) 693 if ( !dayLabel )
694 appendLabels = true; 694 appendLabels = true;
695 } 695 }
696 if ( appendLabels ) { 696 if ( appendLabels ) {
697 dayLabel = new QLabel(mDayLabels); 697 dayLabel = new QLabel(mDayLabels);
698 mDayLabelsList.append( dayLabel ); 698 mDayLabelsList.append( dayLabel );
699 mLayoutDayLabels->addWidget(dayLabel); 699 mLayoutDayLabels->addWidget(dayLabel);
700 } 700 }
701 dayLabel->setMinimumWidth( 1 ); 701 dayLabel->setMinimumWidth( 1 );
702 dayLabel->setMaximumWidth( 2048 ); 702 dayLabel->setMaximumWidth( 2048 );
703 dayLabel->setFont( dlf ); 703 dayLabel->setFont( dlf );
704 dayLabel->show(); 704 dayLabel->show();
705 QString str; 705 QString str;
706 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date); 706 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date);
707 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true ); 707 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true );
708 switch ( maxLen ) { 708 switch ( maxLen ) {
709 case 2: 709 case 2:
710 str = QString::number( date.day() ); 710 str = QString::number( date.day() );
711 break; 711 break;
712 712
713 case 3: 713 case 3:
714 str = dayName.left( 1 ) +QString::number( date.day()); 714 str = dayName.left( 1 ) +QString::number( date.day());
715 715
716 break; 716 break;
717 case 4: 717 case 4:
718 str = dayName.left( 1 ) + " " +QString::number( date.day()); 718 str = dayName.left( 1 ) + " " +QString::number( date.day());
719 719
720 break; 720 break;
721 case 5: 721 case 5:
722 str = dayName.left( 2 ) + " " +QString::number( date.day()); 722 str = dayName.left( 2 ) + " " +QString::number( date.day());
723 723
724 break; 724 break;
725 case 6: 725 case 6:
726 str = dayName.left( 3 ) + " " +QString::number( date.day()); 726 str = dayName.left( 3 ) + " " +QString::number( date.day());
727 break; 727 break;
728 728
729 default: 729 default:
730 break; 730 break;
731 } 731 }
732 if ( oneday ) { 732 if ( oneday ) {
733 QString addString; 733 QString addString;
734 if ( mSelectedDates.first() == QDateTime::currentDateTime().date() ) 734 if ( mSelectedDates.first() == QDateTime::currentDateTime().date() )
735 addString = i18n("Today"); 735 addString = i18n("Today");
736 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) 736 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) )
737 addString = i18n("Tomorrow"); 737 addString = i18n("Tomorrow");
738 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) 738 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) )
739 addString = i18n("Yesterday"); 739 addString = i18n("Yesterday");
740 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) 740 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) )
741 addString = i18n("Day before yesterday"); 741 addString = i18n("Day before yesterday");
742 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) 742 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) )
743 addString = i18n("Day after tomorrow"); 743 addString = i18n("Day after tomorrow");
744 if ( !addString.isEmpty() ) { 744 if ( !addString.isEmpty() ) {
745 str = addString+", " + str; 745 str = addString+", " + str;
746 } 746 }
747 } 747 }
748 dayLabel->setText(str); 748 dayLabel->setText(str);
749 dayLabel->setAlignment(QLabel::AlignHCenter); 749 dayLabel->setAlignment(QLabel::AlignHCenter);
750 if (date == QDate::currentDate()) { 750 if (date == QDate::currentDate()) {
751 QFont bFont = dlf; 751 QFont bFont = dlf;
752 bFont.setBold( true ); 752 bFont.setBold( true );
753 dayLabel->setFont(bFont); 753 dayLabel->setFont(bFont);
754 } 754 }
755 //dayLayout->addWidget(dayLabel); 755 //dayLayout->addWidget(dayLabel);
756 756
757#ifndef KORG_NOPLUGINS 757#ifndef KORG_NOPLUGINS
758 CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); 758 CalendarDecoration::List cds = KOCore::self()->calendarDecorations();
759 CalendarDecoration *it; 759 CalendarDecoration *it;
760 for(it = cds.first(); it; it = cds.next()) { 760 for(it = cds.first(); it; it = cds.next()) {
761 QString text = it->shortText( date ); 761 QString text = it->shortText( date );
762 if ( !text.isEmpty() ) { 762 if ( !text.isEmpty() ) {
763 QLabel *label = new QLabel(text,mDayLabels); 763 QLabel *label = new QLabel(text,mDayLabels);
764 label->setAlignment(AlignCenter); 764 label->setAlignment(AlignCenter);
765 dayLayout->addWidget(label); 765 dayLayout->addWidget(label);
766 } 766 }
767 } 767 }
768 768
769 for(it = cds.first(); it; it = cds.next()) { 769 for(it = cds.first(); it; it = cds.next()) {
770 QWidget *wid = it->smallWidget(mDayLabels,date); 770 QWidget *wid = it->smallWidget(mDayLabels,date);
771 if ( wid ) { 771 if ( wid ) {
772 // wid->setHeight(20); 772 // wid->setHeight(20);
773 dayLayout->addWidget(wid); 773 dayLayout->addWidget(wid);
774 } 774 }
775 } 775 }
776#endif 776#endif
777 } 777 }
778 if ( ! appendLabels ) { 778 if ( ! appendLabels ) {
779 dayLabel = mDayLabelsList.next(); 779 dayLabel = mDayLabelsList.next();
780 if ( !dayLabel ) 780 if ( !dayLabel )
781 appendLabels = true; 781 appendLabels = true;
782 } 782 }
783 if ( appendLabels ) { 783 if ( appendLabels ) {
784 dayLabel = new QLabel(mDayLabels); 784 dayLabel = new QLabel(mDayLabels);
785 mDayLabelsList.append( dayLabel ); 785 mDayLabelsList.append( dayLabel );
786 mLayoutDayLabels->addWidget(dayLabel); 786 mLayoutDayLabels->addWidget(dayLabel);
787 } 787 }
788 //dayLabel->hide();//test only 788 //dayLabel->hide();//test only
789 789
790 int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()-3 ) % mSelectedDates.count() ; 790 int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()-3 ) % mSelectedDates.count() ;
791 if ( offset < 0 ) offset = 0; 791 if ( offset < 0 ) offset = 0;
792 //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 ); 792 //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 );
793 dayLabel->setText("");//QString::number ( mSelectedDates.first().month() ) ); 793 dayLabel->setText("");//QString::number ( mSelectedDates.first().month() ) );
794 dayLabel->show(); 794 dayLabel->show();
795 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset ); 795 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset );
796 //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2); 796 //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2);
797 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); 797 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2);
798 if ( !appendLabels ) { 798 if ( !appendLabels ) {
799 dayLabel = mDayLabelsList.next(); 799 dayLabel = mDayLabelsList.next();
800 while ( dayLabel ) { 800 while ( dayLabel ) {
801 //qDebug("!dayLabel %d",dayLabel ); 801 //qDebug("!dayLabel %d",dayLabel );
802 dayLabel->hide(); 802 dayLabel->hide();
803 dayLabel = mDayLabelsList.next(); 803 dayLabel = mDayLabelsList.next();
804 } 804 }
805 } 805 }
806 //mDayLabelsFrame->show(); 806 //mDayLabelsFrame->show();
807 //mDayLabels->show(); 807 //mDayLabels->show();
808 //qDebug("heigt %d %d %d ",mDayLabelsFrame->height(), mDayLabelsFrame->sizeHint().height(), newHight); 808 //qDebug("heigt %d %d %d ",mDayLabelsFrame->height(), mDayLabelsFrame->sizeHint().height(), newHight);
809 //mDayLabelsFrame->resize( mAgenda->visibleWidth(), newHight ); 809 //mDayLabelsFrame->resize( mAgenda->visibleWidth(), newHight );
810 mDayLabelsFrame->setFixedHeight( newHight ); 810 mDayLabelsFrame->setFixedHeight( newHight );
811} 811}
812 812
813int KOAgendaView::maxDatesHint() 813int KOAgendaView::maxDatesHint()
814{ 814{
815 // Not sure about the max number of events, so return 0 for now. 815 // Not sure about the max number of events, so return 0 for now.
816 return 0; 816 return 0;
817} 817}
818 818
819int KOAgendaView::currentDateCount() 819int KOAgendaView::currentDateCount()
820{ 820{
821 return mSelectedDates.count(); 821 return mSelectedDates.count();
822} 822}
823 823
824QPtrList<Incidence> KOAgendaView::selectedIncidences() 824QPtrList<Incidence> KOAgendaView::selectedIncidences()
825{ 825{
826 QPtrList<Incidence> selected; 826 QPtrList<Incidence> selected;
827 Incidence *incidence; 827 Incidence *incidence;
828 828
829 incidence = mAgenda->selectedIncidence(); 829 incidence = mAgenda->selectedIncidence();
830 if (incidence) selected.append(incidence); 830 if (incidence) selected.append(incidence);
831 831
832 incidence = mAllDayAgenda->selectedIncidence(); 832 incidence = mAllDayAgenda->selectedIncidence();
833 if (incidence) selected.append(incidence); 833 if (incidence) selected.append(incidence);
834 834
835 return selected; 835 return selected;
836} 836}
837 837
838DateList KOAgendaView::selectedDates() 838DateList KOAgendaView::selectedDates()
839{ 839{
840 DateList selected; 840 DateList selected;
841 QDate qd; 841 QDate qd;
842 842
843 qd = mAgenda->selectedIncidenceDate(); 843 qd = mAgenda->selectedIncidenceDate();
844 if (qd.isValid()) selected.append(qd); 844 if (qd.isValid()) selected.append(qd);
845 845
846 qd = mAllDayAgenda->selectedIncidenceDate(); 846 qd = mAllDayAgenda->selectedIncidenceDate();
847 if (qd.isValid()) selected.append(qd); 847 if (qd.isValid()) selected.append(qd);
848 848
849 return selected; 849 return selected;
850} 850}
851 851
852 852
853void KOAgendaView::updateView() 853void KOAgendaView::updateView()
854{ 854{
855 if ( mBlockUpdating ) 855 if ( mBlockUpdating )
856 return; 856 return;
857 // kdDebug() << "KOAgendaView::updateView()" << endl; 857 // kdDebug() << "KOAgendaView::updateView()" << endl;
858 fillAgenda(); 858 fillAgenda();
859 859
860} 860}
861 861
862 862
863/* 863/*
864 Update configuration settings for the agenda view. This method is not 864 Update configuration settings for the agenda view. This method is not
865 complete. 865 complete.
866*/ 866*/
867void KOAgendaView::updateConfig() 867void KOAgendaView::updateConfig()
868{ 868{
869 if ( mBlockUpdating ) 869 if ( mBlockUpdating )
870 return; 870 return;
871 // kdDebug() << "KOAgendaView::updateConfig()" << endl; 871 // kdDebug() << "KOAgendaView::updateConfig()" << endl;
872 872
873 // update config for children 873 // update config for children
874 mTimeLabels->updateConfig(); 874 mTimeLabels->updateConfig();
875 mAgenda->storePosition(); 875 mAgenda->storePosition();
876 mAgenda->updateConfig(); 876 mAgenda->updateConfig();
877 mAllDayAgenda->updateConfig(); 877 mAllDayAgenda->updateConfig();
878 // widget synchronization 878 // widget synchronization
879 //TODO: find a better way, maybe signal/slot 879 //TODO: find a better way, maybe signal/slot
880 mTimeLabels->positionChanged(); 880 mTimeLabels->positionChanged();
881 881
882 // for some reason, this needs to be called explicitly 882 // for some reason, this needs to be called explicitly
883 mTimeLabels->repaint(); 883 mTimeLabels->repaint();
884 884
885 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 885 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
886 886
887 // ToolTips displaying summary of events 887 // ToolTips displaying summary of events
888 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance() 888 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance()
889 ->mEnableToolTips); 889 ->mEnableToolTips);
890 890
891 //setHolidayMasks(); 891 //setHolidayMasks();
892 892
893 //createDayLabels(); called by via updateView(); 893 //createDayLabels(); called by via updateView();
894 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth()); 894 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth());
895 updateView(); 895 updateView();
896 mAgenda->restorePosition(); 896 mAgenda->restorePosition();
897} 897}
898 898
899 899
900void KOAgendaView::updateEventDates(KOAgendaItem *item, int type) 900void KOAgendaView::updateEventDates(KOAgendaItem *item, int type)
901{ 901{
902 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl; 902 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl;
903 //qDebug("KOAgendaView::updateEventDates "); 903 //qDebug("KOAgendaView::updateEventDates ");
904 QDateTime startDt,endDt; 904 QDateTime startDt,endDt;
905 QDate startDate; 905 QDate startDate;
906 int lenInSecs; 906 int lenInSecs;
907 // if ( type == KOAgenda::RESIZETOP ) 907 // if ( type == KOAgenda::RESIZETOP )
908 // qDebug("RESIZETOP "); 908 // qDebug("RESIZETOP ");
909 // if ( type == KOAgenda::RESIZEBOTTOM ) 909 // if ( type == KOAgenda::RESIZEBOTTOM )
910 // qDebug("RESIZEBOTTOM "); 910 // qDebug("RESIZEBOTTOM ");
911 // if ( type == KOAgenda::MOVE ) 911 // if ( type == KOAgenda::MOVE )
912 // qDebug("MOVE "); 912 // qDebug("MOVE ");
913 if ( item->incidence()->type() == "Event" ) { 913 if ( item->incidence()->type() == "Event" ) {
914 startDt =item->incidence()->dtStart(); 914 startDt =item->incidence()->dtStart();
915 endDt = item->incidence()->dtEnd(); 915 endDt = item->incidence()->dtEnd();
916 lenInSecs = startDt.secsTo( endDt ); 916 lenInSecs = startDt.secsTo( endDt );
917 } 917 }
918 918
919 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED ); 919 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED );
920 920
921 if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) { 921 if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) {
922 startDate = mSelectedDates[item->mLastMoveXPos]; 922 startDate = mSelectedDates[item->mLastMoveXPos];
923 } else { 923 } else {
924 if (item->cellX() < 0) { 924 if (item->cellX() < 0) {
925 startDate = (mSelectedDates.first()).addDays(item->cellX()); 925 startDate = (mSelectedDates.first()).addDays(item->cellX());
926 } else { 926 } else {
927 startDate = mSelectedDates[item->cellX()]; 927 startDate = mSelectedDates[item->cellX()];
928 } 928 }
929 } 929 }
930 startDt.setDate(startDate); 930 startDt.setDate(startDate);
931 931
932 if (item->incidence()->doesFloat()) { 932 if (item->incidence()->doesFloat()) {
933 endDt.setDate(startDate.addDays(item->cellWidth() - 1)); 933 endDt.setDate(startDate.addDays(item->cellWidth() - 1));
934 } else { 934 } else {
935 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE ) 935 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE )
936 startDt.setTime(mAgenda->gyToTime(item->cellYTop())); 936 startDt.setTime(mAgenda->gyToTime(item->cellYTop()));
937 if ( item->incidence()->type() == "Event" ) { 937 if ( item->incidence()->type() == "Event" ) {
938 if ( type == KOAgenda::MOVE ) { 938 if ( type == KOAgenda::MOVE ) {
939 endDt = startDt.addSecs(lenInSecs); 939 endDt = startDt.addSecs(lenInSecs);
940 940
941 } else if ( type == KOAgenda::RESIZEBOTTOM ) { 941 } else if ( type == KOAgenda::RESIZEBOTTOM ) {
942 if (item->lastMultiItem()) { 942 if (item->lastMultiItem()) {
943 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 943 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
944 endDt.setDate(startDate. 944 endDt.setDate(startDate.
945 addDays(item->lastMultiItem()->cellX() - item->cellX())); 945 addDays(item->lastMultiItem()->cellX() - item->cellX()));
946 } else { 946 } else {
947 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 947 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
948 endDt.setDate(startDate); 948 endDt.setDate(startDate);
949 } 949 }
950 } 950 }
951 } else { 951 } else {
952 // todo 952 // todo
953 qDebug("tooooodoooooo "); 953 qDebug("tooooodoooooo ");
954 if (item->lastMultiItem()) { 954 if (item->lastMultiItem()) {
955 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 955 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
956 endDt.setDate(startDate. 956 endDt.setDate(startDate.
957 addDays(item->lastMultiItem()->cellX() - item->cellX())); 957 addDays(item->lastMultiItem()->cellX() - item->cellX()));
958 } else { 958 } else {
959 //qDebug("tem->cellYBottom() %d",item->cellYBottom() ); 959 //qDebug("tem->cellYBottom() %d",item->cellYBottom() );
960 if ( item->cellYBottom() > 0 ) 960 if ( item->cellYBottom() > 0 )
961 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 961 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
962 else 962 else
963 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time()); 963 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time());
964 endDt.setDate(startDate); 964 endDt.setDate(startDate);
965 } 965 }
966 } 966 }
967 } 967 }
968 968
969 qDebug("to888"); 969 qDebug("to888");
970 if ( item->incidence()->type() == "Event" ) { 970 if ( item->incidence()->type() == "Event" ) {
971 item->incidence()->setDtStart(startDt); 971 item->incidence()->setDtStart(startDt);
972 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt); 972 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt);
973 } else if ( item->incidence()->type() == "Todo" ) { 973 } else if ( item->incidence()->type() == "Todo" ) {
974 (static_cast<Todo*>(item->incidence()))->setDtDue(endDt); 974 (static_cast<Todo*>(item->incidence()))->setDtDue(endDt);
975 } 975 }
976 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() ); 976 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() );
977 item->incidence()->setRevision(item->incidence()->revision()+1); 977 item->incidence()->setRevision(item->incidence()->revision()+1);
978 item->setItemDate(startDt.date()); 978 item->setItemDate(startDt.date());
979 //item->updateItem(); 979 //item->updateItem();
980 if ( item->incidence()->type() == "Todo" ) { 980 if ( item->incidence()->type() == "Todo" ) {
981 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED ); 981 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED );
982 982
983 } 983 }
984 else 984 else
985 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED); 985 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED);
986 item->updateItem(); 986 item->updateItem();
987} 987}
988 988
989void KOAgendaView::showDates( const QDate &start, const QDate &end ) 989void KOAgendaView::showDates( const QDate &start, const QDate &end )
990{ 990{
991 // kdDebug() << "KOAgendaView::selectDates" << endl; 991 // kdDebug() << "KOAgendaView::selectDates" << endl;
992 992
993 mSelectedDates.clear(); 993 mSelectedDates.clear();
994 // qDebug("KOAgendaView::showDates "); 994 // qDebug("KOAgendaView::showDates ");
995 QDate d = start; 995 QDate d = start;
996 while (d <= end) { 996 while (d <= end) {
997 mSelectedDates.append(d); 997 mSelectedDates.append(d);
998 d = d.addDays( 1 ); 998 d = d.addDays( 1 );
999 } 999 }
1000 1000
1001 // and update the view 1001 // and update the view
1002 fillAgenda(); 1002 fillAgenda();
1003} 1003}
1004 1004
1005 1005
1006void KOAgendaView::showEvents(QPtrList<Event>) 1006void KOAgendaView::showEvents(QPtrList<Event>)
1007{ 1007{
1008 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl; 1008 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl;
1009} 1009}
1010 1010
1011void KOAgendaView::changeEventDisplay(Event *, int) 1011void KOAgendaView::changeEventDisplay(Event *, int)
1012{ 1012{
1013 // qDebug("KOAgendaView::changeEventDisplay "); 1013 // qDebug("KOAgendaView::changeEventDisplay ");
1014 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl; 1014 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl;
1015 // this should be re-written to be MUCH smarter. Right now we 1015 // this should be re-written to be MUCH smarter. Right now we
1016 // are just playing dumb. 1016 // are just playing dumb.
1017 fillAgenda(); 1017 fillAgenda();
1018} 1018}
1019 1019
1020void KOAgendaView::fillAgenda(const QDate &) 1020void KOAgendaView::fillAgenda(const QDate &)
1021{ 1021{
1022 // qDebug("KOAgendaView::fillAgenda "); 1022 // qDebug("KOAgendaView::fillAgenda ");
1023 fillAgenda(); 1023 fillAgenda();
1024} 1024}
1025 1025
1026void KOAgendaView::fillAgenda() 1026void KOAgendaView::fillAgenda()
1027{ 1027{
1028 if ( globalFlagBlockStartup ) 1028 if ( globalFlagBlockStartup )
1029 return; 1029 return;
1030 if ( globalFlagBlockAgenda == 1 ) 1030 if ( globalFlagBlockAgenda == 1 )
1031 return; 1031 return;
1032 //if ( globalFlagBlockAgenda == 2 ) 1032 //if ( globalFlagBlockAgenda == 2 )
1033 //globalFlagBlockAgenda = 0; 1033 //globalFlagBlockAgenda = 0;
1034 // globalFlagBlockPainting = false; 1034 // globalFlagBlockPainting = false;
1035 if ( globalFlagBlockAgenda == 0 ) 1035 if ( globalFlagBlockAgenda == 0 )
1036 globalFlagBlockAgenda = 1; 1036 globalFlagBlockAgenda = 1;
1037 // clearView(); 1037 // clearView();
1038 //qDebug("fillAgenda()++++ "); 1038 //qDebug("fillAgenda()++++ ");
1039 globalFlagBlockAgendaItemPaint = 1; 1039 globalFlagBlockAgendaItemPaint = 1;
1040 mAllDayAgenda->changeColumns(mSelectedDates.count()); 1040 mAllDayAgenda->changeColumns(mSelectedDates.count());
1041 mAgenda->changeColumns(mSelectedDates.count()); 1041 mAgenda->changeColumns(mSelectedDates.count());
1042 qApp->processEvents(); 1042 qApp->processEvents();
1043 mEventIndicatorTop->changeColumns(mSelectedDates.count()); 1043 mEventIndicatorTop->changeColumns(mSelectedDates.count());
1044 mEventIndicatorBottom->changeColumns(mSelectedDates.count()); 1044 mEventIndicatorBottom->changeColumns(mSelectedDates.count());
1045 setHolidayMasks(); 1045 setHolidayMasks();
1046 1046
1047 //mAgenda->hideUnused(); 1047 //mAgenda->hideUnused();
1048 //mAllDayAgenda->hideUnused(); 1048 //mAllDayAgenda->hideUnused();
1049 1049
1050 // mAgenda->blockNextRepaint( false ); 1050 // mAgenda->blockNextRepaint( false );
1051 // mAgenda->viewport()->repaint(); 1051 // mAgenda->viewport()->repaint();
1052 // mAgenda->blockNextRepaint( true ); 1052 // mAgenda->blockNextRepaint( true );
1053 mMinY.resize(mSelectedDates.count()); 1053 mMinY.resize(mSelectedDates.count());
1054 mMaxY.resize(mSelectedDates.count()); 1054 mMaxY.resize(mSelectedDates.count());
1055 1055
1056 QPtrList<Event> dayEvents; 1056 QPtrList<Event> dayEvents;
1057 1057
1058 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 1058 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
1059 // Therefore, gtodoset all of them. 1059 // Therefore, gtodoset all of them.
1060 QPtrList<Todo> todos = calendar()->todos(); 1060 QPtrList<Todo> todos = calendar()->todos();
1061 1061
1062 mAgenda->setDateList(mSelectedDates); 1062 mAgenda->setDateList(mSelectedDates);
1063 1063
1064 QDate today = QDate::currentDate(); 1064 QDate today = QDate::currentDate();
1065 1065
1066 DateList::ConstIterator dit; 1066 DateList::ConstIterator dit;
1067 int curCol = 0; 1067 int curCol = 0;
1068 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 1068 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
1069 QDate currentDate = *dit; 1069 QDate currentDate = *dit;
1070 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString() 1070 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString()
1071 // << endl; 1071 // << endl;
1072 1072
1073 dayEvents = calendar()->events(currentDate,true); 1073 dayEvents = calendar()->events(currentDate,true);
1074 1074
1075 // Default values, which can never be reached 1075 // Default values, which can never be reached
1076 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1; 1076 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1;
1077 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1; 1077 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1;
1078 1078
1079 unsigned int numEvent; 1079 unsigned int numEvent;
1080 for(numEvent=0;numEvent<dayEvents.count();++numEvent) { 1080 for(numEvent=0;numEvent<dayEvents.count();++numEvent) {
1081 Event *event = dayEvents.at(numEvent); 1081 Event *event = dayEvents.at(numEvent);
1082 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") ) 1082 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") )
1083 if ( event->uid().left(15) == QString("last-syncEvent-") ) 1083 if ( event->uid().left(15) == QString("last-syncEvent-") )
1084 continue; 1084 continue;
1085 // kdDebug() << " Event: " << event->summary() << endl; 1085 // kdDebug() << " Event: " << event->summary() << endl;
1086 1086
1087 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol; 1087 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol;
1088 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol; 1088 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol;
1089 1089
1090 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl; 1090 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl;
1091 1091
1092 if (event->doesFloat()) { 1092 if (event->doesFloat()) {
1093 if (event->recurrence()->doesRecur()) { 1093 if (event->recurrence()->doesRecur()) {
1094 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol); 1094 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol);
1095 } else { 1095 } else {
1096 if (beginX <= 0 && curCol == 0) { 1096 if (beginX <= 0 && curCol == 0) {
1097 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1097 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1098 } else if (beginX == curCol) { 1098 } else if (beginX == curCol) {
1099 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1099 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1100 } 1100 }
1101 } 1101 }
1102 } else if (event->isMultiDay()) { 1102 } else if (event->isMultiDay()) {
1103 if ( event->doesRecur () ) { 1103 if ( event->doesRecur () ) {
1104 QDate dateit = currentDate; 1104 QDate dateit = currentDate;
1105 int count = 0; 1105 int count = 0;
1106 int max = event->dtStart().daysTo( event->dtEnd() ) +2; 1106 int max = event->dtStart().daysTo( event->dtEnd() ) +2;
1107 while (! event->recursOn( dateit ) && count <= max ) { 1107 while (! event->recursOn( dateit ) && count <= max ) {
1108 ++count; 1108 ++count;
1109 dateit = dateit.addDays( -1 ); 1109 dateit = dateit.addDays( -1 );
1110 } 1110 }
1111 bool ok; 1111 bool ok;
1112 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok ); 1112 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok );
1113 if ( ok ) 1113 if ( ok )
1114 { 1114 {
1115 int secs = event->dtStart().secsTo( event->dtEnd() ); 1115 int secs = event->dtStart().secsTo( event->dtEnd() );
1116 QDateTime nextOcend =nextOcstart.addSecs( secs ); ; 1116 QDateTime nextOcend =nextOcstart.addSecs( secs ); ;
1117 beginX = currentDate.daysTo(nextOcstart.date()) + curCol; 1117 beginX = currentDate.daysTo(nextOcstart.date()) + curCol;
1118 endX = currentDate.daysTo(nextOcend.date()) + curCol; 1118 endX = currentDate.daysTo(nextOcend.date()) + curCol;
1119 1119
1120 } 1120 }
1121 } 1121 }
1122 int startY = mAgenda->timeToY(event->dtStart().time()); 1122 int startY = mAgenda->timeToY(event->dtStart().time());
1123 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1123 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1124 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol ); 1124 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol );
1125 if ((beginX <= 0 && curCol == 0) || beginX == curCol) { 1125 if ((beginX <= 0 && curCol == 0) || beginX == curCol) {
1126 //qDebug("insert!!! "); 1126 //qDebug("insert!!! ");
1127 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY); 1127 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY);
1128 } 1128 }
1129 if (beginX == curCol) { 1129 if (beginX == curCol) {
1130 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1130 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1131 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1131 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1132 } else if (endX == curCol) { 1132 } else if (endX == curCol) {
1133 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1133 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1134 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1134 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1135 } else { 1135 } else {
1136 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1136 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1137 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1137 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1138 } 1138 }
1139 } else { 1139 } else {
1140 int startY = mAgenda->timeToY(event->dtStart().time()); 1140 int startY = mAgenda->timeToY(event->dtStart().time());
1141 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1141 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1142 if (endY < startY) endY = startY; 1142 if (endY < startY) endY = startY;
1143 mAgenda->insertItem(event,currentDate,curCol,startY,endY); 1143 mAgenda->insertItem(event,currentDate,curCol,startY,endY);
1144 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1144 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1145 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1145 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1146 } 1146 }
1147 } 1147 }
1148 // ---------- [display Todos -------------- 1148 // ---------- [display Todos --------------
1149 unsigned int numTodo; 1149 unsigned int numTodo;
1150 for (numTodo = 0; numTodo < todos.count(); ++numTodo) { 1150 for (numTodo = 0; numTodo < todos.count(); ++numTodo) {
1151 Todo *todo = todos.at(numTodo); 1151 Todo *todo = todos.at(numTodo);
1152 1152
1153 if ( ! todo->hasDueDate() && !todo->hasCompletedDate()) continue; // todo shall not be displayed if it has no date 1153 if ( ! todo->hasDueDate() && !todo->hasCompletedDate()) continue; // todo shall not be displayed if it has no date
1154 1154
1155 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 1155 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
1156 // Already completed items can be displayed on their original due date 1156 // Already completed items can be displayed on their original due date
1157 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda 1157 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda
1158 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda; 1158 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda;
1159 bool fillIn = false; 1159 bool fillIn = false;
1160 if ( todo->hasCompletedDate() && todo->completed().date() == currentDate ) 1160 if ( todo->hasCompletedDate() && todo->completed().date() == currentDate )
1161 fillIn = true; 1161 fillIn = true;
1162 if ( ! fillIn && !todo->hasCompletedDate() ) 1162 if ( ! fillIn && !todo->hasCompletedDate() )
1163 fillIn = ((todo->dtDue().date() == currentDate) && !overdue) || ((currentDate == today) && overdue); 1163 fillIn = ((todo->dtDue().date() == currentDate) && !overdue) || ((currentDate == today) && overdue);
1164 if ( fillIn ) { 1164 if ( fillIn ) {
1165 if ( (todo->doesFloat() || overdue ) && !todo->hasCompletedDate() ) { // Todo has no due-time set or is already overdue 1165 if ( (todo->doesFloat() || overdue ) && !todo->hasCompletedDate() ) { // Todo has no due-time set or is already overdue
1166 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1166 if ( KOPrefs::instance()->mShowTodoInAgenda )
1167 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol); 1167 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol);
1168 } 1168 }
1169 else { 1169 else {
1170 QDateTime dt; 1170 QDateTime dt;
1171 if ( todo->hasCompletedDate() ) 1171 if ( todo->hasCompletedDate() )
1172 dt = todo->completed(); 1172 dt = todo->completed();
1173 else 1173 else
1174 dt = todo->dtDue();; 1174 dt = todo->dtDue();;
1175 1175
1176 1176
1177 int endY = mAgenda->timeToY(dt.time()) - 1; 1177 int endY = mAgenda->timeToY(dt.time()) - 1;
1178 int hi = (18/KOPrefs::instance()->mHourSize); 1178 int hi = (18/KOPrefs::instance()->mHourSize);
1179 //qDebug("hei %d ",KOPrefs::instance()->mHourSize); 1179 //qDebug("hei %d ",KOPrefs::instance()->mHourSize);
1180 int startY = endY -hi; 1180 int startY = endY -hi;
1181 1181
1182 mAgenda->insertItem(todo,currentDate,curCol,startY,endY); 1182 mAgenda->insertItem(todo,currentDate,curCol,startY,endY);
1183 1183
1184 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1184 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1185 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1185 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1186 } 1186 }
1187 } 1187 }
1188 } 1188 }
1189 // ---------- display Todos] -------------- 1189 // ---------- display Todos] --------------
1190 1190
1191 ++curCol; 1191 ++curCol;
1192 } 1192 }
1193 mAgenda->hideUnused(); 1193 mAgenda->hideUnused();
1194 mAllDayAgenda->hideUnused(); 1194 mAllDayAgenda->hideUnused();
1195 mAgenda->checkScrollBoundaries(); 1195 mAgenda->checkScrollBoundaries();
1196 1196
1197 deleteSelectedDateTime(); 1197 deleteSelectedDateTime();
1198 1198
1199 createDayLabels(); 1199 createDayLabels();
1200 emit incidenceSelected( 0 ); 1200 emit incidenceSelected( 0 );
1201 1201
1202 if ( globalFlagBlockAgenda == 2 ) { 1202 if ( globalFlagBlockAgenda == 2 ) {
1203 if ( KOPrefs::instance()->mSetTimeToDayStartAt ) 1203 if ( KOPrefs::instance()->mSetTimeToDayStartAt )
1204 setStartHour( KOPrefs::instance()->mDayBegins ); 1204 setStartHour( KOPrefs::instance()->mDayBegins );
1205 else if ( KOPrefs::instance()->mCenterOnCurrentTime ) 1205 else if ( KOPrefs::instance()->mCenterOnCurrentTime )
1206 setStartHour( QTime::currentTime ().hour() ); 1206 setStartHour( QTime::currentTime ().hour() );
1207 // qApp->processEvents(); 1207 // qApp->processEvents();
1208 } 1208 }
1209 qApp->processEvents(); 1209 qApp->processEvents();
1210 //qDebug("qApp->processEvents(); END "); 1210 //qDebug("qApp->processEvents(); END ");
1211 globalFlagBlockAgenda = 0; 1211 globalFlagBlockAgenda = 0;
1212 1212
1213 // mAgenda->hideUnused(); 1213 // mAgenda->hideUnused();
1214 //mAllDayAgenda->hideUnused(); 1214 //mAllDayAgenda->hideUnused();
1215 mAllDayAgenda->drawContentsToPainter(); 1215 mAllDayAgenda->drawContentsToPainter();
1216 mAgenda->drawContentsToPainter(); 1216 mAgenda->drawContentsToPainter();
1217 repaintAgenda(); 1217 repaintAgenda();
1218 // mAgenda->finishUpdate(); 1218 // mAgenda->finishUpdate();
1219 //mAllDayAgenda->finishUpdate(); 1219 //mAllDayAgenda->finishUpdate();
1220 1220
1221 // repaintAgenda(); 1221 // repaintAgenda();
1222 //qApp->processEvents(); 1222 //qApp->processEvents();
1223 // globalFlagBlockAgenda = 0; 1223 // globalFlagBlockAgenda = 0;
1224} 1224}
1225void KOAgendaView::repaintAgenda() 1225void KOAgendaView::repaintAgenda()
1226{ 1226{
1227 // mAllDayAgenda->drawContentsToPainter(); 1227 // mAllDayAgenda->drawContentsToPainter();
1228// mAllDayAgenda->viewport()->repaint( false ); 1228// mAllDayAgenda->viewport()->repaint( false );
1229// mAgenda->drawContentsToPainter(); 1229// mAgenda->drawContentsToPainter();
1230// mAgenda->viewport()->repaint( false ); 1230// mAgenda->viewport()->repaint( false );
1231// qApp->processEvents(); 1231// qApp->processEvents();
1232 1232
1233 //qDebug("KOAgendaView::repaintAgenda() "); 1233 //qDebug("KOAgendaView::repaintAgenda() ");
1234 //qApp->processEvents(); 1234 //qApp->processEvents();
1235 mAgenda->viewport()->repaint( false ); 1235 mAgenda->viewport()->repaint( false );
1236 mAllDayAgenda->viewport()->repaint( false ); 1236 mAllDayAgenda->viewport()->repaint( false );
1237 mAgenda->finishUpdate(); 1237 mAgenda->finishUpdate();
1238 mAllDayAgenda->finishUpdate(); 1238 mAllDayAgenda->finishUpdate();
1239} 1239}
1240 1240
1241 1241
1242void KOAgendaView::clearView() 1242void KOAgendaView::clearView()
1243{ 1243{
1244 // kdDebug() << "ClearView" << endl; 1244 // kdDebug() << "ClearView" << endl;
1245 mAllDayAgenda->clear(); 1245 mAllDayAgenda->clear();
1246 mAgenda->clear(); 1246 mAgenda->clear();
1247} 1247}
1248 1248
1249void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1249void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1250 const QDate &td) 1250 const QDate &td)
1251{ 1251{
1252#ifndef KORG_NOPRINTER 1252#ifndef KORG_NOPRINTER
1253 if (fd == td) 1253 if (fd == td)
1254 calPrinter->preview(CalPrinter::Day, fd, td); 1254 calPrinter->preview(CalPrinter::Day, fd, td);
1255 else 1255 else
1256 calPrinter->preview(CalPrinter::Week, fd, td); 1256 calPrinter->preview(CalPrinter::Week, fd, td);
1257#endif 1257#endif
1258} 1258}
1259 1259
1260// void KOAgendaView::updateMovedTodo() 1260// void KOAgendaView::updateMovedTodo()
1261// { 1261// {
1262// // updateConfig(); 1262// // updateConfig();
1263// // emit updateTodoViews(); 1263// // emit updateTodoViews();
1264// } 1264// }
1265 1265
1266void KOAgendaView::newEvent(int gx, int gy) 1266void KOAgendaView::newEvent(int gx, int gy)
1267{ 1267{
1268 if (!mSelectedDates.count()) return; 1268 if (!mSelectedDates.count()) return;
1269 1269
1270 QDate day = mSelectedDates[gx]; 1270 QDate day = mSelectedDates[gx];
1271 1271
1272 QTime time = mAgenda->gyToTime(gy); 1272 QTime time = mAgenda->gyToTime(gy);
1273 QDateTime dt(day,time); 1273 QDateTime dt(day,time);
1274 // if ( dt < QDateTime::currentDateTime () ) 1274 // if ( dt < QDateTime::currentDateTime () )
1275 // dt = QDateTime::currentDateTime ().addSecs( 3600 ); 1275 // dt = QDateTime::currentDateTime ().addSecs( 3600 );
1276 emit newEventSignal(dt); 1276 emit newEventSignal(dt);
1277} 1277}
1278 1278
1279void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd) 1279void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd)
1280{ 1280{
1281 if (!mSelectedDates.count()) return; 1281 if (!mSelectedDates.count()) return;
1282 1282
1283 QDate dayStart = mSelectedDates[gxStart]; 1283 QDate dayStart = mSelectedDates[gxStart];
1284 QDate dayEnd = mSelectedDates[gxEnd]; 1284 QDate dayEnd = mSelectedDates[gxEnd];
1285 1285
1286 QTime timeStart = mAgenda->gyToTime(gyStart); 1286 QTime timeStart = mAgenda->gyToTime(gyStart);
1287 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1287 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1288 1288
1289 QDateTime dtStart(dayStart,timeStart); 1289 QDateTime dtStart(dayStart,timeStart);
1290 QDateTime dtEnd(dayEnd,timeEnd); 1290 QDateTime dtEnd(dayEnd,timeEnd);
1291 1291
1292 emit newEventSignal(dtStart,dtEnd); 1292 emit newEventSignal(dtStart,dtEnd);
1293} 1293}
1294 1294
1295void KOAgendaView::newEventAllDay(int gx, int ) 1295void KOAgendaView::newEventAllDay(int gx, int )
1296{ 1296{
1297 if (!mSelectedDates.count()) return; 1297 if (!mSelectedDates.count()) return;
1298 1298
1299 QDate day = mSelectedDates[gx]; 1299 QDate day = mSelectedDates[gx];
1300 1300
1301 emit newEventSignal(day); 1301 emit newEventSignal(day);
1302} 1302}
1303void KOAgendaView::newTodoAllDay(int gx, int ) 1303void KOAgendaView::newTodoAllDay(int gx, int )
1304{ 1304{
1305 if (!mSelectedDates.count()) return; 1305 if (!mSelectedDates.count()) return;
1306 1306
1307 QDateTime day (mSelectedDates[gx] ); 1307 QDateTime day (mSelectedDates[gx] );
1308 emit newTodoSignal(day, true); 1308 emit newTodoSignal(day, true);
1309} 1309}
1310void KOAgendaView::newTodo(int gx, int gy ) 1310void KOAgendaView::newTodo(int gx, int gy )
1311{ 1311{
1312 if (!mSelectedDates.count()) return; 1312 if (!mSelectedDates.count()) return;
1313 QDate dayStart = mSelectedDates[gx]; 1313 QDate dayStart = mSelectedDates[gx];
1314 QTime timeStart = mAgenda->gyToTime(gy); 1314 QTime timeStart = mAgenda->gyToTime(gy);
1315 QDateTime dt (dayStart,timeStart); 1315 QDateTime dt (dayStart,timeStart);
1316 emit newTodoSignal( dt, false ); 1316 emit newTodoSignal( dt, false );
1317} 1317}
1318 1318
1319void KOAgendaView::updateEventIndicatorTop(int newY) 1319void KOAgendaView::updateEventIndicatorTop(int newY)
1320{ 1320{
1321 uint i; 1321 uint i;
1322 for(i=0;i<mMinY.size();++i) { 1322 for(i=0;i<mMinY.size();++i) {
1323 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true); 1323 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true);
1324 else mEventIndicatorTop->enableColumn(i,false); 1324 else mEventIndicatorTop->enableColumn(i,false);
1325 } 1325 }
1326 1326
1327 mEventIndicatorTop->update(); 1327 mEventIndicatorTop->update();
1328} 1328}
1329 1329
1330void KOAgendaView::updateEventIndicatorBottom(int newY) 1330void KOAgendaView::updateEventIndicatorBottom(int newY)
1331{ 1331{
1332 uint i; 1332 uint i;
1333 for(i=0;i<mMaxY.size();++i) { 1333 for(i=0;i<mMaxY.size();++i) {
1334 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true); 1334 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true);
1335 else mEventIndicatorBottom->enableColumn(i,false); 1335 else mEventIndicatorBottom->enableColumn(i,false);
1336 } 1336 }
1337 1337
1338 mEventIndicatorBottom->update(); 1338 mEventIndicatorBottom->update();
1339} 1339}
1340 1340
1341void KOAgendaView::startDrag(Event *event) 1341void KOAgendaView::startDrag(Event *event)
1342{ 1342{
1343#ifndef KORG_NODND 1343#ifndef KORG_NODND
1344 DndFactory factory( calendar() ); 1344 DndFactory factory( calendar() );
1345 ICalDrag *vd = factory.createDrag(event,this); 1345 ICalDrag *vd = factory.createDrag(event,this);
1346 if (vd->drag()) { 1346 if (vd->drag()) {
1347 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl; 1347 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl;
1348 } 1348 }
1349#endif 1349#endif
1350} 1350}
1351 1351
1352void KOAgendaView::readSettings() 1352void KOAgendaView::readSettings()
1353{ 1353{
1354 readSettings(KOGlobals::config()); 1354 readSettings(KOGlobals::config());
1355} 1355}
1356 1356
1357void KOAgendaView::readSettings(KConfig *config) 1357void KOAgendaView::readSettings(KConfig *config)
1358{ 1358{
1359 // kdDebug() << "KOAgendaView::readSettings()" << endl; 1359 // kdDebug() << "KOAgendaView::readSettings()" << endl;
1360 1360
1361 config->setGroup("Views"); 1361 config->setGroup("Views");
1362 1362
1363 //#ifndef KORG_NOSPLITTER 1363 //#ifndef KORG_NOSPLITTER
1364 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView"); 1364 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView");
1365 if (sizes.count() == 2) { 1365 if (sizes.count() == 2) {
1366 if ( sizes[0] < 20 ) { 1366 if ( sizes[0] < 20 ) {
1367 sizes[1] = sizes[1] +20 - sizes[0]; 1367 sizes[1] = sizes[1] +20 - sizes[0];
1368 sizes[0] = 20; 1368 sizes[0] = 20;
1369 } 1369 }
1370 mSplitterAgenda->setSizes(sizes); 1370 mSplitterAgenda->setSizes(sizes);
1371 // qDebug("read %d %d ",sizes[0],sizes[1] ); 1371 // qDebug("read %d %d ",sizes[0],sizes[1] );
1372 } 1372 }
1373 //#endif 1373 //#endif
1374 1374
1375 // updateConfig(); 1375 // updateConfig();
1376} 1376}
1377 1377
1378void KOAgendaView::writeSettings(KConfig *config) 1378void KOAgendaView::writeSettings(KConfig *config)
1379{ 1379{
1380 // kdDebug() << "KOAgendaView::writeSettings()" << endl; 1380 // kdDebug() << "KOAgendaView::writeSettings()" << endl;
1381 1381
1382 config->setGroup("Views"); 1382 config->setGroup("Views");
1383 1383
1384 //#ifndef KORG_NOSPLITTER 1384 //#ifndef KORG_NOSPLITTER
1385 QValueList<int> list = mSplitterAgenda->sizes(); 1385 QValueList<int> list = mSplitterAgenda->sizes();
1386 config->writeEntry("Separator AgendaView",list); 1386 config->writeEntry("Separator AgendaView",list);
1387 //qDebug("write %d %d ", list[0],list[1] ); 1387 //qDebug("write %d %d ", list[0],list[1] );
1388 //#endif 1388 //#endif
1389} 1389}
1390 1390
1391void KOAgendaView::setHolidayMasks() 1391void KOAgendaView::setHolidayMasks()
1392{ 1392{
1393 mHolidayMask.resize(mSelectedDates.count()); 1393 mHolidayMask.resize(mSelectedDates.count());
1394 1394
1395 uint i; 1395 uint i;
1396 for(i=0;i<mSelectedDates.count();++i) { 1396 for(i=0;i<mSelectedDates.count();++i) {
1397 QDate date = mSelectedDates[i]; 1397 QDate date = mSelectedDates[i];
1398 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6); 1398 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6);
1399 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7); 1399 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7);
1400 bool showHoliday = false; 1400 bool showHoliday = false;
1401 if ( KOPrefs::instance()->mExcludeHolidays ) { 1401 if ( KOPrefs::instance()->mExcludeHolidays ) {
1402 QPtrList<Event> events = calendar()->events( date, true ); 1402 QPtrList<Event> events = calendar()->events( date, true );
1403 Event *event; 1403 Event *event;
1404 for( event = events.first(); event; event = events.next() ) { 1404 for( event = events.first(); event; event = events.next() ) {
1405 if ( event->categories().contains("Holiday") || 1405 if ( event->categories().contains("Holiday") ||
1406 event->categories().contains(i18n("Holiday"))) { 1406 event->categories().contains(i18n("Holiday"))) {
1407 showHoliday = true; 1407 showHoliday = true;
1408 break; 1408 break;
1409 } 1409 }
1410 } 1410 }
1411 1411
1412 } 1412 }
1413 1413
1414#ifndef KORG_NOPLUGINS 1414#ifndef KORG_NOPLUGINS
1415 bool showHoliday = KOPrefs::instance()->mExcludeHolidays && 1415 bool showHoliday = KOPrefs::instance()->mExcludeHolidays &&
1416 !KOCore::self()->holiday(date).isEmpty(); 1416 !KOCore::self()->holiday(date).isEmpty();
1417#endif 1417#endif
1418 bool showDay = showSaturday || showSunday || showHoliday; 1418 bool showDay = showSaturday || showSunday || showHoliday;
1419 1419
1420 if (showDay) { 1420 if (showDay) {
1421 mHolidayMask.at(i) = true; 1421 mHolidayMask.at(i) = true;
1422 } else { 1422 } else {
1423 mHolidayMask.at(i) = false; 1423 mHolidayMask.at(i) = false;
1424 } 1424 }
1425 } 1425 }
1426 1426
1427 mAgenda->setHolidayMask(&mHolidayMask); 1427 mAgenda->setHolidayMask(&mHolidayMask);
1428 mAllDayAgenda->setHolidayMask(&mHolidayMask); 1428 mAllDayAgenda->setHolidayMask(&mHolidayMask);
1429} 1429}
1430 1430
1431void KOAgendaView::setContentsPos(int y) 1431void KOAgendaView::setContentsPos(int y)
1432{ 1432{
1433 mAgenda->setContentsPos(0,y); 1433 mAgenda->setContentsPos(0,y);
1434} 1434}
1435 1435
1436void KOAgendaView::setExpandedButton( bool expanded ) 1436void KOAgendaView::setExpandedButton( bool expanded )
1437{ 1437{
1438 if ( expanded ) { 1438 if ( expanded ) {
1439 mExpandButton->setPixmap( mExpandedPixmap ); 1439 mExpandButton->setPixmap( mExpandedPixmap );
1440 } else { 1440 } else {
1441 mExpandButton->setPixmap( mNotExpandedPixmap ); 1441 mExpandButton->setPixmap( mNotExpandedPixmap );
1442 } 1442 }
1443} 1443}
1444 1444
1445void KOAgendaView::clearSelection() 1445void KOAgendaView::clearSelection()
1446{ 1446{
1447 mAgenda->deselectItem(); 1447 mAgenda->deselectItem();
1448 mAllDayAgenda->deselectItem(); 1448 mAllDayAgenda->deselectItem();
1449} 1449}
1450 1450
1451void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart, 1451void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart,
1452 int gxEnd, int gyEnd) 1452 int gxEnd, int gyEnd)
1453{ 1453{
1454 mTimeSpanInAllDay = true; 1454 mTimeSpanInAllDay = true;
1455 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd); 1455 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd);
1456} 1456}
1457 1457
1458 1458
1459 1459
1460 1460
1461void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart, 1461void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart,
1462 int gxEnd, int gyEnd) 1462 int gxEnd, int gyEnd)
1463{ 1463{
1464 if (!mSelectedDates.count()) return; 1464 if (!mSelectedDates.count()) return;
1465 1465
1466 QDate dayStart = mSelectedDates[gxStart]; 1466 QDate dayStart = mSelectedDates[gxStart];
1467 QDate dayEnd = mSelectedDates[gxEnd]; 1467 QDate dayEnd = mSelectedDates[gxEnd];
1468 1468
1469 QTime timeStart = mAgenda->gyToTime(gyStart); 1469 QTime timeStart = mAgenda->gyToTime(gyStart);
1470 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1470 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1471 1471
1472 QDateTime dtStart(dayStart,timeStart); 1472 QDateTime dtStart(dayStart,timeStart);
1473 QDateTime dtEnd(dayEnd,timeEnd); 1473 QDateTime dtEnd(dayEnd,timeEnd);
1474 1474
1475 mTimeSpanBegin = dtStart; 1475 mTimeSpanBegin = dtStart;
1476 mTimeSpanEnd = dtEnd; 1476 mTimeSpanEnd = dtEnd;
1477 1477
1478} 1478}
1479 1479
1480void KOAgendaView::deleteSelectedDateTime() 1480void KOAgendaView::deleteSelectedDateTime()
1481{ 1481{
1482 mTimeSpanBegin.setDate(QDate()); 1482 mTimeSpanBegin.setDate(QDate());
1483 mTimeSpanEnd.setDate(QDate()); 1483 mTimeSpanEnd.setDate(QDate());
1484 mTimeSpanInAllDay = false; 1484 mTimeSpanInAllDay = false;
1485} 1485}
1486 1486
1487void KOAgendaView::keyPressEvent ( QKeyEvent * e ) 1487void KOAgendaView::keyPressEvent ( QKeyEvent * e )
1488{ 1488{
1489 e->ignore(); 1489 e->ignore();
1490} 1490}
1491 1491
1492void KOAgendaView::scrollOneHourUp() 1492void KOAgendaView::scrollOneHourUp()
1493{ 1493{
1494 1494
1495 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 ); 1495 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 );
1496} 1496}
1497void KOAgendaView::scrollOneHourDown() 1497void KOAgendaView::scrollOneHourDown()
1498{ 1498{
1499 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 ); 1499 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 );
1500} 1500}
1501 1501
1502void KOAgendaView::setStartHour( int h ) 1502void KOAgendaView::setStartHour( int h )
1503{ 1503{
1504 mAgenda->setStartHour( h ); 1504 mAgenda->setStartHour( h );
1505 1505
1506} 1506}
1507 1507
1508void KOAgendaView::updateTodo( Todo * t, int ) 1508void KOAgendaView::updateTodo( Todo * t, int )
1509{ 1509{
1510
1511 bool remove = false; 1510 bool remove = false;
1512 bool removeAD = false; 1511 bool removeAD = false;
1513 QDate da; 1512 QDate da;
1514 if ( t->hasCompletedDate() ) 1513 if ( t->hasCompletedDate() )
1515 da = t->completed().date(); 1514 da = t->completed().date();
1516 else 1515 else
1517 da = t->dtDue().date(); 1516 da = t->dtDue().date();
1518 if ( ! t->hasDueDate() && !t->hasCompletedDate() ) { 1517 if ( ! t->hasDueDate() && !t->hasCompletedDate() ) {
1519 remove = true; 1518 remove = true;
1520 removeAD = true; 1519 removeAD = true;
1521 } 1520 }
1522 else { 1521 else {
1523 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ; 1522 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ;
1524 if ( overdue && 1523 if ( overdue &&
1525 QDate::currentDate() >= mSelectedDates.first() && 1524 QDate::currentDate() >= mSelectedDates.first() &&
1526 QDate::currentDate() <= mSelectedDates.last()) { 1525 QDate::currentDate() <= mSelectedDates.last()) {
1527 removeAD = false; 1526 removeAD = false;
1528 remove = true; 1527 remove = true;
1529 } 1528 }
1530 else { 1529 else {
1531 1530
1532 if ( da < mSelectedDates.first() || 1531 if ( da < mSelectedDates.first() ||
1533 da > mSelectedDates.last() ) { 1532 da > mSelectedDates.last() ) {
1534 remove = true; 1533 remove = true;
1535 removeAD = true; 1534 removeAD = true;
1536 } else { 1535 } else {
1537 remove = t->doesFloat() && !t->hasCompletedDate(); 1536 remove = t->doesFloat() && !t->hasCompletedDate();
1538 removeAD = !remove; 1537 removeAD = !remove;
1539 } 1538 }
1540 } 1539 }
1541 } 1540 }
1542 int days = mSelectedDates.first().daysTo( da ); 1541 int days = mSelectedDates.first().daysTo( da );
1543 // qDebug("daysto %d ", days ); 1542 //qDebug("daysto %d %d %d", days, remove,removeAD );
1544 mAgenda->updateTodo( t , days, remove); 1543 mAgenda->updateTodo( t , days, remove);
1545 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1544 if ( KOPrefs::instance()->mShowTodoInAgenda )
1546 mAllDayAgenda->updateTodo( t , days, removeAD); 1545 mAllDayAgenda->updateTodo( t , days, removeAD);
1547 //qDebug("KOAgendaView::updateTodo( Todo *, int ) "); 1546 //qDebug("KOAgendaView::updateTodo( Todo *, int ) ");
1548 1547
1549} 1548}
diff --git a/korganizer/koeditorgeneraltodo.h b/korganizer/koeditorgeneraltodo.h
index f6c30f8..5f1c3cc 100644
--- a/korganizer/koeditorgeneraltodo.h
+++ b/korganizer/koeditorgeneraltodo.h
@@ -1,105 +1,106 @@
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 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23#ifndef _KOEDITORGENERALTODO_H 23#ifndef _KOEDITORGENERALTODO_H
24#define _KOEDITORGENERALTODO_H 24#define _KOEDITORGENERALTODO_H
25 25
26#include <qframe.h> 26#include <qframe.h>
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qcheckbox.h> 28#include <qcheckbox.h>
29#include <qpushbutton.h> 29#include <qpushbutton.h>
30#include <qgroupbox.h> 30#include <qgroupbox.h>
31#include <qlineedit.h> 31#include <qlineedit.h>
32#include <qcombobox.h> 32#include <qcombobox.h>
33#include <qmultilineedit.h> 33#include <qmultilineedit.h>
34#include <qlistview.h> 34#include <qlistview.h>
35#include <qradiobutton.h> 35#include <qradiobutton.h>
36 36
37#include "koeditorgeneral.h" 37#include "koeditorgeneral.h"
38#include "koglobals.h" 38#include "koglobals.h"
39 39
40class KRestrictedLine; 40class KRestrictedLine;
41 41
42class KDateEdit; 42class KDateEdit;
43 43
44using namespace KCal; 44using namespace KCal;
45 45
46class KOEditorGeneralTodo : public KOEditorGeneral 46class KOEditorGeneralTodo : public KOEditorGeneral
47{ 47{
48 Q_OBJECT 48 Q_OBJECT
49 public: 49 public:
50 KOEditorGeneralTodo (QObject* parent=0,const char* name=0); 50 KOEditorGeneralTodo (QObject* parent=0,const char* name=0);
51 virtual ~KOEditorGeneralTodo(); 51 virtual ~KOEditorGeneralTodo();
52 52
53 void initTime(QWidget *, QBoxLayout *); 53 void initTime(QWidget *, QBoxLayout *);
54 void initStatus(QWidget *, QBoxLayout *); 54 void initStatus(QWidget *, QBoxLayout *);
55 void initCompletion(QWidget *, QBoxLayout *); 55 void initCompletion(QWidget *, QBoxLayout *);
56 void initPriority(QWidget *, QBoxLayout *); 56 void initPriority(QWidget *, QBoxLayout *);
57 57
58 void finishSetup(); 58 void finishSetup();
59 59
60 /** Set widgets to default values */ 60 /** Set widgets to default values */
61 void setDefaults(QDateTime due,bool allDay); 61 void setDefaults(QDateTime due,bool allDay);
62 /** Read todo object and setup widgets accordingly */ 62 /** Read todo object and setup widgets accordingly */
63 void readTodo(Todo *); 63 void readTodo(Todo *);
64 /** Write todo settings to event object */ 64 /** Write todo settings to event object */
65 void writeTodo(Todo *); 65 void writeTodo(Todo *);
66 66
67 /** Check if the input is valid. */ 67 /** Check if the input is valid. */
68 bool validateInput(); 68 bool validateInput();
69 69
70 /** The todo has been modified externally */ 70 /** The todo has been modified externally */
71 void modified (Todo*, int); 71 void modified (Todo*, int);
72 72
73 signals: 73 signals:
74 void openCategoryDialog(); 74 void openCategoryDialog();
75 75
76 protected slots: 76 protected slots:
77 void completedChanged(int); 77 void completedChanged(int);
78 78
79 void enableDueEdit( bool enable ); 79 void enableDueEdit( bool enable );
80 void enableStartEdit( bool enable ); 80 void enableStartEdit( bool enable );
81 void enableTimeEdits( bool enable ); 81 void enableTimeEdits( bool enable );
82 void showAlarm(); 82 void showAlarm();
83 83
84 protected: 84 protected:
85 void setCompletedDate(); 85 void setCompletedDate();
86 86
87 private: 87 private:
88 friend class KOTodoEditor;
88 KDateEdit *mStartDateEdit; 89 KDateEdit *mStartDateEdit;
89 KOTimeEdit *mStartTimeEdit; 90 KOTimeEdit *mStartTimeEdit;
90 QCheckBox *mTimeButton; 91 QCheckBox *mTimeButton;
91 QCheckBox *mDueCheck; 92 QCheckBox *mDueCheck;
92 KDateEdit *mDueDateEdit; 93 KDateEdit *mDueDateEdit;
93 KOTimeEdit *mDueTimeEdit; 94 KOTimeEdit *mDueTimeEdit;
94 QComboBox *mCompletedCombo; 95 QComboBox *mCompletedCombo;
95 QLabel *mCompletedLabel; 96 QLabel *mCompletedLabel;
96 QLabel *mPriorityLabel; 97 QLabel *mPriorityLabel;
97 QComboBox *mPriorityCombo; 98 QComboBox *mPriorityCombo;
98 99
99 QCheckBox *mStartCheck; 100 QCheckBox *mStartCheck;
100 101
101 QDateTime mCompleted; 102 QDateTime mCompleted;
102}; 103};
103 104
104 105
105#endif 106#endif
diff --git a/korganizer/kotodoeditor.cpp b/korganizer/kotodoeditor.cpp
index 16c19a4..ec5c2d1 100644
--- a/korganizer/kotodoeditor.cpp
+++ b/korganizer/kotodoeditor.cpp
@@ -1,375 +1,383 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 1997, 1998 Preston Brown 3 Copyright (c) 1997, 1998 Preston Brown
4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution. 22 without including the source code for Qt in the source distribution.
23*/ 23*/
24 24
25#include <qtooltip.h> 25#include <qtooltip.h>
26#include <qframe.h> 26#include <qframe.h>
27#include <qpixmap.h> 27#include <qpixmap.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#include <qhbox.h> 29#include <qhbox.h>
30#include <qdir.h> 30#include <qdir.h>
31#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qapplication.h> 32#include <qapplication.h>
33 33
34#include <kiconloader.h> 34#include <kiconloader.h>
35#include <klocale.h> 35#include <klocale.h>
36#include <kfiledialog.h> 36#include <kfiledialog.h>
37#include <kstandarddirs.h> 37#include <kstandarddirs.h>
38#include <kmessagebox.h> 38#include <kmessagebox.h>
39 39
40#include <libkdepim/categoryselectdialog.h> 40#include <libkdepim/categoryselectdialog.h>
41#include <libkcal/calendarlocal.h> 41#include <libkcal/calendarlocal.h>
42#include <libkcal/calendarresources.h> 42#include <libkcal/calendarresources.h>
43#include <libkcal/resourcecalendar.h> 43#include <libkcal/resourcecalendar.h>
44#include <libkcal/icalformat.h> 44#include <libkcal/icalformat.h>
45#include <kresources/resourceselectdialog.h> 45#include <kresources/resourceselectdialog.h>
46 46
47#include "koprefs.h" 47#include "koprefs.h"
48#include "kolocationbox.h"
48 49
49#include "kotodoeditor.h" 50#include "kotodoeditor.h"
50extern int globalFlagBlockAgenda; 51extern int globalFlagBlockAgenda;
51 52
52KOTodoEditor::KOTodoEditor( Calendar *calendar, QWidget *parent ) : 53KOTodoEditor::KOTodoEditor( Calendar *calendar, QWidget *parent ) :
53 KOIncidenceEditor( i18n("Edit To-Do"), calendar, parent ) 54 KOIncidenceEditor( i18n("Edit To-Do"), calendar, parent )
54{ 55{
55 mTodo = 0; 56 mTodo = 0;
56 mRelatedTodo = 0; 57 mRelatedTodo = 0;
57 findButton(User1)->hide(); 58 findButton(User1)->hide();
58 init(); 59 init();
59} 60}
60 61
61KOTodoEditor::~KOTodoEditor() 62KOTodoEditor::~KOTodoEditor()
62{ 63{
63 emit dialogClose( mTodo ); 64 emit dialogClose( mTodo );
64} 65}
65 66
66void KOTodoEditor::init() 67void KOTodoEditor::init()
67{ 68{
68 setupGeneral(); 69 setupGeneral();
69 setupAttendeesTab(); 70 setupAttendeesTab();
70} 71}
71void KOTodoEditor::setCategories( QString s ) 72void KOTodoEditor::setCategories( QString s )
72{ 73{
73 mGeneral->setCategories(s); 74 mGeneral->setCategories(s);
74} 75}
75void KOTodoEditor::setSecrecy( int sec ) 76void KOTodoEditor::setSecrecy( int sec )
76{ 77{
77 mGeneral->setSecrecy( sec ); 78 mGeneral->setSecrecy( sec );
78} 79}
79void KOTodoEditor::reload() 80void KOTodoEditor::reload()
80{ 81{
81 if ( mTodo ) readTodo( mTodo ); 82 if ( mTodo ) readTodo( mTodo );
82} 83}
83 84
84void KOTodoEditor::setupGeneral() 85void KOTodoEditor::setupGeneral()
85{ 86{
86 mGeneral = new KOEditorGeneralTodo(this); 87 mGeneral = new KOEditorGeneralTodo(this);
87 connect ( mGeneral, SIGNAL ( allAccepted() ), this, SLOT ( slotOk () ) ); 88 connect ( mGeneral, SIGNAL ( allAccepted() ), this, SLOT ( slotOk () ) );
88 89
89 // connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show())); 90 // connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show()));
90 //connect(mCategoryDialog, SIGNAL(categoriesSelected(const QString &)), 91 //connect(mCategoryDialog, SIGNAL(categoriesSelected(const QString &)),
91 // mGeneral,SLOT(setCategories(const QString &))); 92 // mGeneral,SLOT(setCategories(const QString &)));
92 93
93 if (KOPrefs::instance()->mCompactDialogs) { 94 if (KOPrefs::instance()->mCompactDialogs) {
94 QFrame *topFrame = addPage(i18n("General")); 95 QFrame *topFrame = addPage(i18n("General"));
95 96
96 QBoxLayout *topLayout = new QVBoxLayout(topFrame); 97 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
97 if ( QApplication::desktop()->width() < 480 ) { 98 if ( QApplication::desktop()->width() < 480 ) {
98 topLayout->setMargin(1); 99 topLayout->setMargin(1);
99 topLayout->setSpacing(1); 100 topLayout->setSpacing(1);
100 } else { 101 } else {
101 topLayout->setMargin(marginHint()-1); 102 topLayout->setMargin(marginHint()-1);
102 topLayout->setSpacing(spacingHint()-1); 103 topLayout->setSpacing(spacingHint()-1);
103 } 104 }
104 mGeneral->initHeader(topFrame,topLayout); 105 mGeneral->initHeader(topFrame,topLayout);
105 mGeneral->initTime(topFrame,topLayout); 106 mGeneral->initTime(topFrame,topLayout);
106 mGeneral->initAlarm(topFrame,topLayout); 107 mGeneral->initAlarm(topFrame,topLayout);
107 mGeneral->enableAlarm( false ); 108 mGeneral->enableAlarm( false );
108 109
109 110
110 QBoxLayout *priorityLayout; 111 QBoxLayout *priorityLayout;
111 if ( QApplication::desktop()->width() < 500 ) 112 if ( QApplication::desktop()->width() < 500 )
112 priorityLayout = new QVBoxLayout( topLayout ); 113 priorityLayout = new QVBoxLayout( topLayout );
113 else 114 else
114 priorityLayout = new QHBoxLayout( topLayout ); 115 priorityLayout = new QHBoxLayout( topLayout );
115 QWidget* prioWidget = new QWidget (topFrame); 116 QWidget* prioWidget = new QWidget (topFrame);
116 priorityLayout->addWidget( prioWidget ); 117 priorityLayout->addWidget( prioWidget );
117 QHBoxLayout* priorityLayout2 = new QHBoxLayout( prioWidget); 118 QHBoxLayout* priorityLayout2 = new QHBoxLayout( prioWidget);
118 119
119 120
120 QIconSet icon; 121 QIconSet icon;
121 if ( QApplication::desktop()->width() < 321 ) 122 if ( QApplication::desktop()->width() < 321 )
122 icon = SmallIcon("fileexport16"); 123 icon = SmallIcon("fileexport16");
123 else 124 else
124 icon = SmallIcon("fileexport"); 125 icon = SmallIcon("fileexport");
125 QPushButton * saveTemplate = new QPushButton( prioWidget); 126 QPushButton * saveTemplate = new QPushButton( prioWidget);
126 saveTemplate->setIconSet (icon ) ; 127 saveTemplate->setIconSet (icon ) ;
127 int size = saveTemplate->sizeHint().height(); 128 int size = saveTemplate->sizeHint().height();
128 saveTemplate->setFixedSize( size, size ); 129 saveTemplate->setFixedSize( size, size );
129 if ( QApplication::desktop()->width() < 321 ) 130 if ( QApplication::desktop()->width() < 321 )
130 icon = SmallIcon("fileimport16"); 131 icon = SmallIcon("fileimport16");
131 else 132 else
132 icon = SmallIcon("fileimport"); 133 icon = SmallIcon("fileimport");
133 QPushButton * loadTemplate = new QPushButton( prioWidget); 134 QPushButton * loadTemplate = new QPushButton( prioWidget);
134 loadTemplate->setIconSet (icon ) ; 135 loadTemplate->setIconSet (icon ) ;
135 loadTemplate->setFixedSize( size, size ); 136 loadTemplate->setFixedSize( size, size );
136 137
137 priorityLayout2->addWidget(loadTemplate); 138 priorityLayout2->addWidget(loadTemplate);
138 priorityLayout2->addWidget(saveTemplate); 139 priorityLayout2->addWidget(saveTemplate);
139 mGeneral->initPriority(prioWidget,priorityLayout2); 140 mGeneral->initPriority(prioWidget,priorityLayout2);
140 mGeneral->initCategories( topFrame, priorityLayout ); 141 mGeneral->initCategories( topFrame, priorityLayout );
141 topLayout->addStretch(1); 142 topLayout->addStretch(1);
142 143
143 QFrame *topFrame2 = addPage(i18n("Details")); 144 QFrame *topFrame2 = addPage(i18n("Details"));
144 145
145 QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2); 146 QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2);
146 topLayout2->setMargin(marginHint()); 147 topLayout2->setMargin(marginHint());
147 topLayout2->setSpacing(spacingHint()); 148 topLayout2->setSpacing(spacingHint());
148 149
149 QHBoxLayout *completionLayout = new QHBoxLayout( topLayout2 ); 150 QHBoxLayout *completionLayout = new QHBoxLayout( topLayout2 );
150 mGeneral->initCompletion(topFrame2,completionLayout); 151 mGeneral->initCompletion(topFrame2,completionLayout);
151 152
152 153
153 mGeneral->initSecrecy( topFrame2, topLayout2 ); 154 mGeneral->initSecrecy( topFrame2, topLayout2 );
154 mGeneral->initDescription(topFrame2,topLayout2); 155 mGeneral->initDescription(topFrame2,topLayout2);
155 156
156 // QHBox * hb = new QHBox ( topFrame2 ); 157 // QHBox * hb = new QHBox ( topFrame2 );
157 // topLayout2->addWidget(hb); 158 // topLayout2->addWidget(hb);
158 // hb->setSpacing( 3 ); 159 // hb->setSpacing( 3 );
159 160
160 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); 161 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) );
161 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); 162 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) );
162 163
163 } else { 164 } else {
164 QFrame *topFrame = addPage(i18n("General")); 165 QFrame *topFrame = addPage(i18n("General"));
165 166
166 QBoxLayout *topLayout = new QVBoxLayout(topFrame); 167 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
167 topLayout->setSpacing(spacingHint()); 168 topLayout->setSpacing(spacingHint());
168 169
169 mGeneral->initHeader(topFrame,topLayout); 170 mGeneral->initHeader(topFrame,topLayout);
170 mGeneral->initTime(topFrame,topLayout); 171 mGeneral->initTime(topFrame,topLayout);
171 mGeneral->initStatus(topFrame,topLayout); 172 mGeneral->initStatus(topFrame,topLayout);
172 QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout); 173 QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout);
173 mGeneral->initAlarm(topFrame,alarmLineLayout); 174 mGeneral->initAlarm(topFrame,alarmLineLayout);
174 mGeneral->initDescription(topFrame,topLayout); 175 mGeneral->initDescription(topFrame,topLayout);
175 QBoxLayout *detailsLayout = new QHBoxLayout(topLayout); 176 QBoxLayout *detailsLayout = new QHBoxLayout(topLayout);
176 mGeneral->initCategories( topFrame, detailsLayout ); 177 mGeneral->initCategories( topFrame, detailsLayout );
177 mGeneral->initSecrecy( topFrame, detailsLayout ); 178 mGeneral->initSecrecy( topFrame, detailsLayout );
178 } 179 }
179 mGeneral->finishSetup(); 180 mGeneral->finishSetup();
180 181
181} 182}
182 183
183void KOTodoEditor::editTodo(Todo *todo, bool editDescription) 184void KOTodoEditor::editTodo(Todo *todo, bool editDescription)
184{ 185{
185 //init(); 186 //init();
186 187
187 mTodo = todo; 188 mTodo = todo;
188 readTodo(mTodo); 189 readTodo(mTodo);
189 if ( editDescription ) { 190 if ( editDescription ) {
190 showPage( 1 ); 191 showPage( 1 );
191 mGeneral->setFocusOn( 1 ); 192 mGeneral->setFocusOn( 1 );
192 } else { 193 } else {
193 showPage( 0 ); 194 showPage( 0 );
194 mGeneral->setFocusOn( 2 ); 195 mGeneral->setFocusOn( 2 );
195 } 196 }
196} 197}
197 198
198void KOTodoEditor::newTodo(QDateTime due,Todo *relatedTodo,bool allDay) 199void KOTodoEditor::newTodo(QDateTime due,Todo *relatedTodo,bool allDay)
199{ 200{
200 //init(); 201 //init();
201 202
202 mTodo = 0; 203 mTodo = 0;
203 setDefaults(due,relatedTodo,allDay); 204 setDefaults(due,relatedTodo,allDay);
204} 205}
205 206
206void KOTodoEditor::loadDefaults() 207void KOTodoEditor::loadDefaults()
207{ 208{
208 setDefaults(QDateTime::currentDateTime().addDays(7),0,false); 209 setDefaults(QDateTime::currentDateTime().addDays(7),0,false);
209} 210}
210 211
211bool KOTodoEditor::processInput( bool emitTime ) 212bool KOTodoEditor::processInput( bool emitTime )
212{ 213{
213 if (!validateInput()) return false; 214 if (!validateInput()) return false;
214 215
215 Todo *todo = 0; 216 Todo *todo = 0;
216 217
217 if (mTodo) todo = mTodo; 218 if (mTodo) todo = mTodo;
218 else { 219 else {
219 todo = new Todo; 220 todo = new Todo;
220 todo->setOrganizer(KOPrefs::instance()->email()); 221 todo->setOrganizer(KOPrefs::instance()->email());
221 } 222 }
222 223
223 writeTodo(todo); 224 writeTodo(todo);
224 if ( emitTime ) { 225 if ( emitTime ) {
225 globalFlagBlockAgenda = 1; 226 globalFlagBlockAgenda = 1;
226 emit showAgendaView( false ); 227 emit showAgendaView( false );
227 if ( todo->hasDueDate() ) 228 if ( todo->hasDueDate() )
228 emit jumpToTime( todo->dtDue().date() ); 229 emit jumpToTime( todo->dtDue().date() );
229 globalFlagBlockAgenda = 2; 230 globalFlagBlockAgenda = 2;
230 } 231 }
231 if (mTodo) { 232 if (mTodo) {
232 todo->setRevision(todo->revision()+1); 233 todo->setRevision(todo->revision()+1);
233 emit todoChanged(todo); 234 emit todoChanged(todo);
234 } else { 235 } else {
235 mCalendar->addTodo(todo); 236 mCalendar->addTodo(todo);
236 mTodo = todo; 237 mTodo = todo;
237 emit todoAdded(todo); 238 emit todoAdded(todo);
238 } 239 }
239 240
240 return true; 241 return true;
241} 242}
242 243
243void KOTodoEditor::deleteTodo() 244void KOTodoEditor::deleteTodo()
244{ 245{
245 if (mTodo) { 246 if (mTodo) {
246 if (KOPrefs::instance()->mConfirm) { 247 if (KOPrefs::instance()->mConfirm) {
247 switch (msgItemDelete()) { 248 switch (msgItemDelete()) {
248 case KMessageBox::Continue: // OK 249 case KMessageBox::Continue: // OK
249 emit todoToBeDeleted(mTodo); 250 emit todoToBeDeleted(mTodo);
250 emit dialogClose(mTodo); 251 emit dialogClose(mTodo);
251 mCalendar->deleteTodo(mTodo); 252 mCalendar->deleteTodo(mTodo);
252 emit todoDeleted(); 253 emit todoDeleted();
253 reject(); 254 reject();
254 break; 255 break;
255 } 256 }
256 } 257 }
257 else { 258 else {
258 emit todoToBeDeleted(mTodo); 259 emit todoToBeDeleted(mTodo);
259 emit dialogClose(mTodo); 260 emit dialogClose(mTodo);
260 mCalendar->deleteTodo(mTodo); 261 mCalendar->deleteTodo(mTodo);
261 emit todoDeleted(); 262 emit todoDeleted();
262 reject(); 263 reject();
263 } 264 }
264 } else { 265 } else {
265 reject(); 266 reject();
266 } 267 }
267} 268}
268 269
269void KOTodoEditor::setDefaults(QDateTime due,Todo *relatedEvent,bool allDay) 270void KOTodoEditor::setDefaults(QDateTime due,Todo *relatedEvent,bool allDay)
270{ 271{
271 mRelatedTodo = relatedEvent; 272 mRelatedTodo = relatedEvent;
272 273
273 mGeneral->setDefaults(due,allDay); 274 mGeneral->setDefaults(due,allDay);
274 mDetails->setDefaults(); 275 mDetails->setDefaults();
275 showPage( 0 ); 276 showPage( 0 );
276 if ( mRelatedTodo ) { 277 if ( mRelatedTodo ) {
277 mGeneral->setCategories (mRelatedTodo->categoriesStr ()); 278 mGeneral->setCategories (mRelatedTodo->categoriesStr ());
278 mGeneral->setSecrecy (mRelatedTodo->secrecy ()); 279 mGeneral->setSecrecy (mRelatedTodo->secrecy ());
280 if ( mRelatedTodo->priority() < 3 )
281 mGeneral->mPriorityCombo->setCurrentItem(mRelatedTodo->priority()-1);
282 mGeneral->mSummaryEdit->lineEdit()->setText(mRelatedTodo->summary()+": ");
283 int len = mRelatedTodo->summary().length();
284 mGeneral->mSummaryEdit->lineEdit()->setSelection ( 0, len+2 );
285 mGeneral->mSummaryEdit->lineEdit()->setCursorPosition ( len+2 );
286 mGeneral->mSummaryEdit->lineEdit()->setFocus();
279 287
280 } 288 } else
281 mGeneral->setFocusOn( 2 ); 289 mGeneral->setFocusOn( 2 );
282} 290}
283 291
284void KOTodoEditor::readTodo(Todo *todo) 292void KOTodoEditor::readTodo(Todo *todo)
285{ 293{
286 mGeneral->readTodo(todo); 294 mGeneral->readTodo(todo);
287 mDetails->readEvent(todo); 295 mDetails->readEvent(todo);
288 mRelatedTodo = 0;//todo->relatedTo(); 296 mRelatedTodo = 0;//todo->relatedTo();
289 // categories 297 // categories
290 // mCategoryDialog->setSelected(todo->categories()); 298 // mCategoryDialog->setSelected(todo->categories());
291 299
292 // We should handle read-only events here. 300 // We should handle read-only events here.
293} 301}
294 302
295void KOTodoEditor::writeTodo(Todo *event) 303void KOTodoEditor::writeTodo(Todo *event)
296{ 304{
297 mGeneral->writeTodo(event); 305 mGeneral->writeTodo(event);
298 mDetails->writeEvent(event); 306 mDetails->writeEvent(event);
299 307
300 // set related event, i.e. parent to-do in this case. 308 // set related event, i.e. parent to-do in this case.
301 if (mRelatedTodo) { 309 if (mRelatedTodo) {
302 event->setRelatedTo(mRelatedTodo); 310 event->setRelatedTo(mRelatedTodo);
303 } 311 }
304} 312}
305 313
306bool KOTodoEditor::validateInput() 314bool KOTodoEditor::validateInput()
307{ 315{
308 if (!mGeneral->validateInput()) return false; 316 if (!mGeneral->validateInput()) return false;
309 if (!mDetails->validateInput()) return false; 317 if (!mDetails->validateInput()) return false;
310 return true; 318 return true;
311} 319}
312 320
313int KOTodoEditor::msgItemDelete() 321int KOTodoEditor::msgItemDelete()
314{ 322{
315 return KMessageBox::warningContinueCancel(this, 323 return KMessageBox::warningContinueCancel(this,
316 i18n("This item will be permanently deleted."), 324 i18n("This item will be permanently deleted."),
317 i18n("KOrganizer Confirmation"),i18n("Delete")); 325 i18n("KOrganizer Confirmation"),i18n("Delete"));
318} 326}
319 327
320void KOTodoEditor::modified (int modification) 328void KOTodoEditor::modified (int modification)
321{ 329{
322 if (modification == KOGlobals::CATEGORY_MODIFIED || 330 if (modification == KOGlobals::CATEGORY_MODIFIED ||
323 KOGlobals::UNKNOWN_MODIFIED == modification ) 331 KOGlobals::UNKNOWN_MODIFIED == modification )
324 // mCategoryDialog->setSelected (mTodo->categories ()); 332 // mCategoryDialog->setSelected (mTodo->categories ());
325 mGeneral->modified (mTodo, modification); 333 mGeneral->modified (mTodo, modification);
326 334
327} 335}
328 336
329void KOTodoEditor::slotLoadTemplate() 337void KOTodoEditor::slotLoadTemplate()
330{ 338{
331 339
332 QString fileName =locateLocal( "templates", "todos" ); 340 QString fileName =locateLocal( "templates", "todos" );
333 QDir t_dir; 341 QDir t_dir;
334 if ( !t_dir.exists(fileName) ) 342 if ( !t_dir.exists(fileName) )
335 t_dir.mkdir ( fileName ); 343 t_dir.mkdir ( fileName );
336 fileName += "/todo"; 344 fileName += "/todo";
337 fileName = KFileDialog::getSaveFileName( fileName , "Load Todo template", this ); 345 fileName = KFileDialog::getSaveFileName( fileName , "Load Todo template", this );
338 if ( fileName.length() == 0 ) 346 if ( fileName.length() == 0 )
339 return; 347 return;
340 CalendarLocal cal; 348 CalendarLocal cal;
341 ICalFormat format; 349 ICalFormat format;
342 if ( !format.load( &cal, fileName ) ) { 350 if ( !format.load( &cal, fileName ) ) {
343 KMessageBox::error( this, i18n("Error loading template file\n '%1'.") 351 KMessageBox::error( this, i18n("Error loading template file\n '%1'.")
344 .arg( fileName ) ); 352 .arg( fileName ) );
345 return ; 353 return ;
346 } 354 }
347 QPtrList<Todo> todos = cal.todos(); 355 QPtrList<Todo> todos = cal.todos();
348 Todo * todo = todos.first(); 356 Todo * todo = todos.first();
349 if ( !todo ) { 357 if ( !todo ) {
350 KMessageBox::error( this, 358 KMessageBox::error( this,
351 i18n("Template does not\ncontain a valid Todo.")); 359 i18n("Template does not\ncontain a valid Todo."));
352 } else { 360 } else {
353 readTodo( todo ); 361 readTodo( todo );
354 } 362 }
355 363
356} 364}
357 365
358void KOTodoEditor::slotSaveTemplate() 366void KOTodoEditor::slotSaveTemplate()
359{ 367{
360 QString fileName =locateLocal( "templates", "todos" ); 368 QString fileName =locateLocal( "templates", "todos" );
361 QDir t_dir; 369 QDir t_dir;
362 if ( !t_dir.exists(fileName) ) 370 if ( !t_dir.exists(fileName) )
363 t_dir.mkdir ( fileName ); 371 t_dir.mkdir ( fileName );
364 fileName += "/todo"; 372 fileName += "/todo";
365 fileName = KFileDialog::getSaveFileName( fileName , "Save as Todo template", this ); 373 fileName = KFileDialog::getSaveFileName( fileName , "Save as Todo template", this );
366 if ( fileName.length() > 0 ) 374 if ( fileName.length() > 0 )
367 saveTemplate( fileName ); 375 saveTemplate( fileName );
368} 376}
369 377
370void KOTodoEditor::saveTemplate( const QString &templateName ) 378void KOTodoEditor::saveTemplate( const QString &templateName )
371{ 379{
372 Todo *todo = new Todo; 380 Todo *todo = new Todo;
373 writeTodo( todo ); 381 writeTodo( todo );
374 saveAsTemplate( todo, templateName ); 382 saveAsTemplate( todo, templateName );
375} 383}