summaryrefslogtreecommitdiffabout
path: root/korganizer
Unidiff
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagenda.cpp195
-rw-r--r--korganizer/koagenda.h6
-rw-r--r--korganizer/koagendaitem.cpp2
-rw-r--r--korganizer/koagendaview.cpp14
-rw-r--r--korganizer/koagendaview.h1
-rw-r--r--korganizer/kolistview.cpp55
-rw-r--r--korganizer/kolistview.h7
7 files changed, 259 insertions, 21 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp
index 66ad4ec..14f52b8 100644
--- a/korganizer/koagenda.cpp
+++ b/korganizer/koagenda.cpp
@@ -1,2053 +1,2238 @@
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
74 mTimeBox = new QLabel(this); 73 mTimeBox = new QLabel(this);
75 mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom); 74 mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom);
76 QPalette pal = mTimeBox->palette(); 75 QPalette pal = mTimeBox->palette();
77 pal.setColor(QColorGroup::Foreground, Qt::red); 76 pal.setColor(QColorGroup::Foreground, Qt::red);
78 mTimeBox->setPalette(pal); 77 mTimeBox->setPalette(pal);
79 //mTimeBox->setAutoMask(true); 78 //mTimeBox->setAutoMask(true);
80 79
81 agenda->addChild(mTimeBox); 80 agenda->addChild(mTimeBox);
82 81
83 oldToday = -1; 82 oldToday = -1;
84} 83}
85 84
86MarcusBains::~MarcusBains() 85MarcusBains::~MarcusBains()
87{ 86{
88 delete minutes; 87 delete minutes;
89} 88}
90 89
91int MarcusBains::todayColumn() 90int MarcusBains::todayColumn()
92{ 91{
93 QDate currentDate = QDate::currentDate(); 92 QDate currentDate = QDate::currentDate();
94 93
95 DateList dateList = agenda->dateList(); 94 DateList dateList = agenda->dateList();
96 DateList::ConstIterator it; 95 DateList::ConstIterator it;
97 int col = 0; 96 int col = 0;
98 for(it = dateList.begin(); it != dateList.end(); ++it) { 97 for(it = dateList.begin(); it != dateList.end(); ++it) {
99 if((*it) == currentDate) 98 if((*it) == currentDate)
100 return KOGlobals::self()->reverseLayout() ? 99 return KOGlobals::self()->reverseLayout() ?
101 agenda->columns() - 1 - col : col; 100 agenda->columns() - 1 - col : col;
102 ++col; 101 ++col;
103 } 102 }
104 103
105 return -1; 104 return -1;
106} 105}
107void MarcusBains::updateLoc() 106void MarcusBains::updateLoc()
108{ 107{
109 updateLocation(); 108 updateLocation();
110} 109}
111void MarcusBains::updateLocation(bool recalculate) 110void MarcusBains::updateLocation(bool recalculate)
112{ 111{
113 112
114 QTime tim = QTime::currentTime(); 113 QTime tim = QTime::currentTime();
115 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1()); 114 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1());
116 if((tim.hour() == 0) && (oldTime.hour()==23)) 115 if((tim.hour() == 0) && (oldTime.hour()==23))
117 recalculate = true; 116 recalculate = true;
118 117
119 int mins = tim.hour()*60 + tim.minute(); 118 int mins = tim.hour()*60 + tim.minute();
120 int minutesPerCell = 24 * 60 / agenda->rows(); 119 int minutesPerCell = 24 * 60 / agenda->rows();
121 int y = mins*agenda->gridSpacingY()/minutesPerCell; 120 int y = mins*agenda->gridSpacingY()/minutesPerCell;
122 int today = recalculate ? todayColumn() : oldToday; 121 int today = recalculate ? todayColumn() : oldToday;
123 int x = agenda->gridSpacingX()*today; 122 int x = agenda->gridSpacingX()*today;
124 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled); 123 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled);
125 124
126 oldTime = tim; 125 oldTime = tim;
127 oldToday = today; 126 oldToday = today;
128 127
129 if(disabled || (today<0)) { 128 if(disabled || (today<0)) {
130 hide(); mTimeBox->hide(); 129 hide(); mTimeBox->hide();
131 return; 130 return;
132 } else { 131 } else {
133 show(); mTimeBox->show(); 132 show(); mTimeBox->show();
134 } 133 }
135 134
136 if(recalculate) 135 if(recalculate)
137 setFixedSize(agenda->gridSpacingX(),1); 136 setFixedSize(agenda->gridSpacingX(),1);
138 agenda->moveChild(this, x, y); 137 agenda->moveChild(this, x, y);
139 raise(); 138 raise();
140 139
141 if(recalculate) 140 if(recalculate)
142 //mTimeBox->setFont(QFont("helvetica",10)); 141 //mTimeBox->setFont(QFont("helvetica",10));
143 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont); 142 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont);
144 143
145 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds)); 144 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds));
146 mTimeBox->adjustSize(); 145 mTimeBox->adjustSize();
147 // the -2 below is there because there is a bug in this program 146 // the -2 below is there because there is a bug in this program
148 // somewhere, where the last column of this widget is a few pixels 147 // somewhere, where the last column of this widget is a few pixels
149 // narrower than the other columns. 148 // narrower than the other columns.
150 int offs = (today==agenda->columns()-1) ? -4 : 0; 149 int offs = (today==agenda->columns()-1) ? -4 : 0;
151 agenda->moveChild(mTimeBox, 150 agenda->moveChild(mTimeBox,
152 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1, 151 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1,
153 y-mTimeBox->height()); 152 y-mTimeBox->height());
154 153
155 mTimeBox->raise(); 154 mTimeBox->raise();
156 //mTimeBox->setAutoMask(true); 155 //mTimeBox->setAutoMask(true);
157 minutes->start(5000,true); 156 minutes->start(5000,true);
158} 157}
159 158
160 159
161//////////////////////////////////////////////////////////////////////////// 160////////////////////////////////////////////////////////////////////////////
162 161
163 162
164/* 163/*
165 Create an agenda widget with rows rows and columns columns. 164 Create an agenda widget with rows rows and columns columns.
166*/ 165*/
167KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, 166KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent,
168 const char *name,WFlags f) : 167 const char *name,WFlags f) :
169 QScrollView(parent,name,f) 168 QScrollView(parent,name,f)
170{ 169{
171 170
172 171
173 mColumns = columns; 172 mColumns = columns;
174 mRows = rows; 173 mRows = rows;
175 mGridSpacingY = rowSize; 174 mGridSpacingY = rowSize;
176 mAllDayMode = false; 175 mAllDayMode = false;
177#ifndef DESKTOP_VERSION 176#ifndef DESKTOP_VERSION
178 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 177 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
179#endif 178#endif
180 mHolidayMask = 0; 179 mHolidayMask = 0;
181 init(); 180 init();
182} 181}
183 182
184/* 183/*
185 Create an agenda widget with columns columns and one row. This is used for 184 Create an agenda widget with columns columns and one row. This is used for
186 all-day events. 185 all-day events.
187*/ 186*/
188KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : 187KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) :
189 QScrollView(parent,name,f) 188 QScrollView(parent,name,f)
190{ 189{
191 blockResize = false; 190 blockResize = false;
192 mColumns = columns; 191 mColumns = columns;
193 mRows = 1; 192 mRows = 1;
194 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize); 193 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize);
195 mGridSpacingY = KOPrefs::instance()->mAllDaySize; 194 mGridSpacingY = KOPrefs::instance()->mAllDaySize;
196 mAllDayMode = true; 195 mAllDayMode = true;
197#ifndef DESKTOP_VERSION 196#ifndef DESKTOP_VERSION
198 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 197 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
199#endif 198#endif
200 mHolidayMask = 0; 199 mHolidayMask = 0;
201 init(); 200 init();
202} 201}
203 202
204 203
205KOAgenda::~KOAgenda() 204KOAgenda::~KOAgenda()
206{ 205{
207 if(mMarcusBains) delete mMarcusBains; 206 if(mMarcusBains) delete mMarcusBains;
208 207
209} 208}
210 209
211Incidence *KOAgenda::selectedIncidence() const 210Incidence *KOAgenda::selectedIncidence() const
212{ 211{
213 return (mSelectedItem ? mSelectedItem->incidence() : 0); 212 return (mSelectedItem ? mSelectedItem->incidence() : 0);
214} 213}
215 214
216 215
217QDate KOAgenda::selectedIncidenceDate() const 216QDate KOAgenda::selectedIncidenceDate() const
218{ 217{
219 return (mSelectedItem ? mSelectedItem->itemDate() : QDate()); 218 return (mSelectedItem ? mSelectedItem->itemDate() : QDate());
220} 219}
221 220
222 221
223void KOAgenda::init() 222void KOAgenda::init()
224{ 223{
224 mPopupTimer = new QTimer(this);
225 connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu()));
226
225 mNewItemPopup = new QPopupMenu( this ); 227 mNewItemPopup = new QPopupMenu( this );
226 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) ); 228 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) );
227 QString pathString = ""; 229 QString pathString = "";
228 if ( !KOPrefs::instance()->mToolBarMiniIcons ) { 230 if ( !KOPrefs::instance()->mToolBarMiniIcons ) {
229 if ( QApplication::desktop()->width() < 480 ) 231 if ( QApplication::desktop()->width() < 480 )
230 pathString += "icons16/"; 232 pathString += "icons16/";
231 } else 233 } else
232 pathString += "iconsmini/"; 234 pathString += "iconsmini/";
233 235
234 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 ); 236 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 );
235 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 ); 237 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 );
236 mNewItemPopup->insertSeparator ( ); 238 mNewItemPopup->insertSeparator ( );
237 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 ); 239 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 );
238 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 ); 240 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 );
239 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 ); 241 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 );
240 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 ); 242 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 );
241 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("Next month"),6 ); 243 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("Next month"),6 );
242 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 ); 244 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 );
243#ifndef _WIN32_ 245#ifndef _WIN32_
244 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase 246 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase
245 viewport()->setWFlags ( wflags); 247 viewport()->setWFlags ( wflags);
246#endif 248#endif
247 mGridSpacingX = 80; 249 mGridSpacingX = 80;
248 mResizeBorderWidth = 8; 250 mResizeBorderWidth = 8;
249 mScrollBorderWidth = 8; 251 mScrollBorderWidth = 8;
250 mScrollDelay = 30; 252 mScrollDelay = 30;
251 mScrollOffset = 10; 253 mScrollOffset = 10;
252 mPaintPixmap.resize( 20,20); 254 mPaintPixmap.resize( 20,20);
253 //enableClipper(true); 255 //enableClipper(true);
254 256
255 // Grab key strokes for keyboard navigation of agenda. Seems to have no 257 // Grab key strokes for keyboard navigation of agenda. Seems to have no
256 // effect. Has to be fixed. 258 // effect. Has to be fixed.
257 setFocusPolicy(WheelFocus); 259 setFocusPolicy(WheelFocus);
258 260
259 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp())); 261 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp()));
260 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown())); 262 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown()));
261 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize())); 263 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize()));
262 264
263 mStartCellX = 0; 265 mStartCellX = 0;
264 mStartCellY = 0; 266 mStartCellY = 0;
265 mCurrentCellX = 0; 267 mCurrentCellX = 0;
266 mCurrentCellY = 0; 268 mCurrentCellY = 0;
267 269
268 mSelectionCellX = 0; 270 mSelectionCellX = 0;
269 mSelectionYTop = 0; 271 mSelectionYTop = 0;
270 mSelectionHeight = 0; 272 mSelectionHeight = 0;
271 273
272 mOldLowerScrollValue = -1; 274 mOldLowerScrollValue = -1;
273 mOldUpperScrollValue = -1; 275 mOldUpperScrollValue = -1;
274 276
275 mClickedItem = 0; 277 mClickedItem = 0;
276 278
277 mActionItem = 0; 279 mActionItem = 0;
278 mActionType = NOP; 280 mActionType = NOP;
279 mItemMoved = false; 281 mItemMoved = false;
280 282
281 mSelectedItem = 0; 283 mSelectedItem = 0;
282 284
283 // mItems.setAutoDelete(true); 285 // mItems.setAutoDelete(true);
284 286
285 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 287 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
286 288
287 viewport()->update(); 289 viewport()->update();
288 290
289 setMinimumSize(30, 1); 291 setMinimumSize(30, 1);
290// setMaximumHeight(mGridSpacingY * mRows + 5); 292// setMaximumHeight(mGridSpacingY * mRows + 5);
291 293
292 // Disable horizontal scrollbar. This is a hack. The geometry should be 294 // 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 295 // controlled in a way that the contents horizontally always fits. Then it is
294 // not necessary to turn off the scrollbar. 296 // not necessary to turn off the scrollbar.
295 setHScrollBarMode(AlwaysOff); 297 setHScrollBarMode(AlwaysOff);
296 if ( ! mAllDayMode ) 298 if ( ! mAllDayMode )
297 setVScrollBarMode(AlwaysOn); 299 setVScrollBarMode(AlwaysOn);
298 else 300 else
299 setVScrollBarMode(AlwaysOff); 301 setVScrollBarMode(AlwaysOff);
300 302
301 setStartHour(KOPrefs::instance()->mDayBegins); 303 setStartHour(KOPrefs::instance()->mDayBegins);
302 304
303 calculateWorkingHours(); 305 calculateWorkingHours();
304 306
305 connect(verticalScrollBar(),SIGNAL(valueChanged(int)), 307 connect(verticalScrollBar(),SIGNAL(valueChanged(int)),
306 SLOT(checkScrollBoundaries(int))); 308 SLOT(checkScrollBoundaries(int)));
307 309
308 // Create the Marcus Bains line. 310 // Create the Marcus Bains line.
309 if(mAllDayMode) 311 if(mAllDayMode)
310 mMarcusBains = 0; 312 mMarcusBains = 0;
311 else { 313 else {
312 mMarcusBains = new MarcusBains(this); 314 mMarcusBains = new MarcusBains(this);
313 addChild(mMarcusBains); 315 addChild(mMarcusBains);
314 } 316 }
317 mPopupKind = 0;
318 mPopupItem = 0;
315} 319}
316 320
317void KOAgenda::clear() 321void KOAgenda::clear()
318{ 322{
319 KOAgendaItem *item; 323 KOAgendaItem *item;
320 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 324 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
321 mUnusedItems.append( item ); 325 mUnusedItems.append( item );
322 //item->hide(); 326 //item->hide();
323 } 327 }
324 mItems.clear(); 328 mItems.clear();
325 mSelectedItem = 0; 329 mSelectedItem = 0;
326 clearSelection(); 330 clearSelection();
327} 331}
328 332
329void KOAgenda::clearSelection() 333void KOAgenda::clearSelection()
330{ 334{
331 mSelectionCellX = 0; 335 mSelectionCellX = 0;
332 mSelectionYTop = 0; 336 mSelectionYTop = 0;
333 mSelectionHeight = 0; 337 mSelectionHeight = 0;
334} 338}
335 339
336void KOAgenda::marcus_bains() 340void KOAgenda::marcus_bains()
337{ 341{
338 if(mMarcusBains) mMarcusBains->updateLocation(true); 342 if(mMarcusBains) mMarcusBains->updateLocation(true);
339} 343}
340 344
341 345
342void KOAgenda::changeColumns(int columns) 346void KOAgenda::changeColumns(int columns)
343{ 347{
344 if (columns == 0) { 348 if (columns == 0) {
345 kdDebug() << "KOAgenda::changeColumns() called with argument 0" << endl; 349 kdDebug() << "KOAgenda::changeColumns() called with argument 0" << endl;
346 return; 350 return;
347 } 351 }
348 352
349 clear(); 353 clear();
350 354
351 mColumns = columns; 355 mColumns = columns;
352// setMinimumSize(mColumns * 10, mGridSpacingY + 1); 356// setMinimumSize(mColumns * 10, mGridSpacingY + 1);
353// init(); 357// init();
354// update(); 358// update();
355 //qDebug("KOAgenda::changeColumns "); 359 //qDebug("KOAgenda::changeColumns ");
356 computeSizes(); 360 computeSizes();
357 // QResizeEvent event( size(), size() ); 361 // QResizeEvent event( size(), size() );
358 362
359 //QApplication::sendEvent( this, &event ); 363 //QApplication::sendEvent( this, &event );
360} 364}
361 365
362/* 366/*
363 This is the eventFilter function, which gets all events from the KOAgendaItems 367 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. 368 contained in the agenda. It has to handle moving and resizing for all items.
365*/ 369*/
366bool KOAgenda::eventFilter ( QObject *object, QEvent *event ) 370bool KOAgenda::eventFilter ( QObject *object, QEvent *event )
367{ 371{
368// kdDebug() << "KOAgenda::eventFilter" << endl; 372// kdDebug() << "KOAgenda::eventFilter" << endl;
369 switch(event->type()) { 373 switch(event->type()) {
370 case QEvent::MouseButtonPress: 374 case QEvent::MouseButtonPress:
371 case QEvent::MouseButtonDblClick: 375 case QEvent::MouseButtonDblClick:
372 case QEvent::MouseButtonRelease: 376 case QEvent::MouseButtonRelease:
373 case QEvent::MouseMove: 377 case QEvent::MouseMove:
374 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event)); 378 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event));
375 379
376 case (QEvent::Leave): 380 case (QEvent::Leave):
377 if (!mActionItem) 381 if (!mActionItem)
378 setCursor(arrowCursor); 382 setCursor(arrowCursor);
379 return true; 383 return true;
380 384
381 default: 385 default:
382 return QScrollView::eventFilter(object,event); 386 return QScrollView::eventFilter(object,event);
383 } 387 }
384} 388}
385 389void KOAgenda::popupMenu()
390{
391 mPopupTimer->stop();
392 if ( mPopupKind == 1 ) {
393 if (mActionItem ) {
394 endItemAction();
395 }
396 mLeftMouseDown = false; // no more leftMouse computation
397 if (mPopupItem) {
398 selectItem(mPopupItem);
399 emit showIncidencePopupSignal(mPopupItem->incidence());
400
401 }
402 } else if ( mPopupKind == 2 ) {
403 if ( mLeftMouseDown ) { // we have a simulated right click - clear left mouse action
404 endSelectAction( false ); // do not emit new event signal
405 mLeftMouseDown = false; // no more leftMouse computation
406 }
407 mNewItemPopup->popup( mPopupPos);
408 }
409 mLeftMouseDown = false;
410 mPopupItem = 0;
411 mPopupKind = 0;
412}
386 413
387bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) 414bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me)
388{ 415{
416 //qDebug("KOAgenda::eventFilter_mous ");
417 QPoint viewportPos;
418 if (object != viewport()) {
419 viewportPos = ((QWidget *)object)->mapToParent(me->pos());
420 } else {
421 viewportPos = me->pos();
422 }
423 static int startX = 0;
424 static int startY = 0;
425 static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 );
426 static bool blockMoving = true;
427 switch (me->type()) {
428 case QEvent::MouseButtonPress:
429 if (me->button() == LeftButton) {
430 mPopupTimer->start( 600 );
431 mLeftMouseDown = true;
432 }
433 blockMoving = true;
434 startX = viewportPos.x();
435 startY = viewportPos.y();
436 if (object != viewport()) {
437 mPopupItem = (KOAgendaItem *)object;
438 mPopupKind = 1;
439 if (me->button() == RightButton) {
440 popupMenu();
441 } else if (me->button() == LeftButton) {
442 mActionItem = (KOAgendaItem *)object;
443 if (mActionItem) {
444 if ( mSelectionHeight > 0 ) {
445 int selectionCellX = mSelectionCellX * mGridSpacingX;
446 int selectionYTop = mSelectionYTop;
447 int gridSpacingX = mGridSpacingX;
448 int selectionHeight = mSelectionHeight;
449 clearSelection();
450 repaintContents( selectionCellX, selectionYTop,
451 gridSpacingX, selectionHeight,false );
452 }
453 selectItem(mActionItem);
454 Incidence *incidence = mActionItem->incidence();
455 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) {
456 mActionItem = 0;
457 } else {
458 startItemAction(viewportPos);
459 }
460 }
461 }
462 } else { // ---------- viewport()
463 mPopupItem = 0;
464 mPopupKind = 2;
465 selectItem(0);
466 mActionItem = 0;
467 mPopupPos = viewport()->mapToGlobal( me->pos() );
468 if (me->button() == RightButton) {
469 popupMenu();
470 } else if (me->button() == LeftButton) {
471 setCursor(arrowCursor);
472 startSelectAction(viewportPos);
473 }
474 }
475 break;
476
477 case QEvent::MouseButtonRelease:
478 if (me->button() == LeftButton ) {
479 mPopupTimer->stop();
480 }
481 if (object != viewport()) {
482 if (me->button() == LeftButton && mLeftMouseDown) {
483 if (mActionItem) {
484 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos));
485 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 );
486 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) {
487 mScrollUpTimer.stop();
488 mScrollDownTimer.stop();
489 mActionItem->resetMove();
490 placeSubCells( mActionItem );
491 // emit startDragSignal( mActionItem->incidence() );
492 setCursor( arrowCursor );
493 mActionItem = 0;
494 mActionType = NOP;
495 mItemMoved = 0;
496 mLeftMouseDown = false;
497 return true;
498 }
499 endItemAction();
500 }
501 }
502
503 } else { // ---------- viewport()
504 if (me->button() == LeftButton && mLeftMouseDown ) { //left click
505 endSelectAction( true ); // emit new event signal
506 }
507 }
508 if (me->button() == LeftButton)
509 mLeftMouseDown = false;
510
511 break;
512
513 case QEvent::MouseMove:
514 if ( !mLeftMouseDown )
515 return true;
516 if ( blockMoving ) {
517 int dX, dY;
518 dX = startX - viewportPos.x();
519 if ( dX < 0 )
520 dX = -dX;
521 dY = viewportPos.y() - startY;
522 if ( dY < 0 )
523 dY = -dY;
524 //qDebug("%d %d %d ", dX, dY , blockmoveDist );
525 if ( dX > blockmoveDist || dY > blockmoveDist ) {
526 blockMoving = false;
527 }
528 }
529 if ( ! blockMoving )
530 mPopupTimer->stop();
531 if (object != viewport()) {
532 KOAgendaItem *moveItem = (KOAgendaItem *)object;
533 if (!moveItem->incidence()->isReadOnly() ) {
534 if (!mActionItem)
535 setNoActionCursor(moveItem,viewportPos);
536 else {
537 if ( !blockMoving )
538 performItemAction(viewportPos);
539 }
540 }
541 } else { // ---------- viewport()
542 mPopupPos = viewport()->mapToGlobal( me->pos() );
543 if ( mActionType == SELECT ) {
544 performSelectAction( viewportPos );
545 }
546 }
547 break;
548
549 case QEvent::MouseButtonDblClick:
550 mPopupTimer->stop();
551 if (object == viewport()) {
552 selectItem(0);
553 int x,y;
554 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
555 int gx,gy;
556 contentsToGrid(x,y,gx,gy);
557 emit newEventSignal(gx,gy);
558 } else {
559 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object;
560 selectItem(doubleClickedItem);
561 if ( KOPrefs::instance()->mEditOnDoubleClick )
562 emit editIncidenceSignal(doubleClickedItem->incidence());
563 else
564 emit showIncidenceSignal(doubleClickedItem->incidence());
565 }
566 break;
567
568 default:
569 break;
570 }
571 return true;
572#if 0
389 //qDebug("KOAgenda::eventFilter_mous "); 573 //qDebug("KOAgenda::eventFilter_mous ");
390 QPoint viewportPos; 574 QPoint viewportPos;
391 if (object != viewport()) { 575 if (object != viewport()) {
392 viewportPos = ((QWidget *)object)->mapToParent(me->pos()); 576 viewportPos = ((QWidget *)object)->mapToParent(me->pos());
393 } else { 577 } else {
394 viewportPos = me->pos(); 578 viewportPos = me->pos();
395 } 579 }
396 static int startX = 0; 580 static int startX = 0;
397 static int startY = 0; 581 static int startY = 0;
398 static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 ); 582 static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 );
399 static bool blockMoving = true; 583 static bool blockMoving = true;
400 static bool leftMouseDown = false; 584 static bool leftMouseDown = false;
401 bool rightButtonPressed = false; 585 bool rightButtonPressed = false;
402 switch (me->type()) { 586 switch (me->type()) {
403 case QEvent::MouseButtonPress: 587 case QEvent::MouseButtonPress:
404 if (me->button() == LeftButton) { 588 if (me->button() == LeftButton) {
405 leftMouseDown = true; 589 leftMouseDown = true;
406 } 590 }
407 else if (me->button() == RightButton) { 591 else if (me->button() == RightButton) {
408 leftMouseDown = false; 592 leftMouseDown = false;
409 } 593 }
410 blockMoving = true; 594 blockMoving = true;
411 startX = viewportPos.x(); 595 startX = viewportPos.x();
412 startY = viewportPos.y(); 596 startY = viewportPos.y();
413 if (object != viewport()) { // item clicked ************** 597 if (object != viewport()) { // item clicked **************
414 if (me->button() == RightButton) { 598 if (me->button() == RightButton) {
415 leftMouseDown = false; 599 leftMouseDown = false;
416 mClickedItem = (KOAgendaItem *)object; 600 mClickedItem = (KOAgendaItem *)object;
417 if (mActionItem ) { 601 if (mActionItem ) {
418 endItemAction(); 602 endItemAction();
419 } 603 }
420 if (mClickedItem) { 604 if (mClickedItem) {
421 selectItem(mClickedItem); 605 selectItem(mClickedItem);
422 emit showIncidencePopupSignal(mClickedItem->incidence()); 606 emit showIncidencePopupSignal(mClickedItem->incidence());
423 } 607 }
424 return true; 608 return true;
425 } else if (me->button() == LeftButton) { 609 } else if (me->button() == LeftButton) {
426 mActionItem = (KOAgendaItem *)object; 610 mActionItem = (KOAgendaItem *)object;
427 if (mActionItem) { 611 if (mActionItem) {
428 if ( mSelectionHeight > 0 ) { 612 if ( mSelectionHeight > 0 ) {
429 int selectionCellX = mSelectionCellX * mGridSpacingX; 613 int selectionCellX = mSelectionCellX * mGridSpacingX;
430 int selectionYTop = mSelectionYTop; 614 int selectionYTop = mSelectionYTop;
431 int gridSpacingX = mGridSpacingX; 615 int gridSpacingX = mGridSpacingX;
432 int selectionHeight = mSelectionHeight; 616 int selectionHeight = mSelectionHeight;
433 clearSelection(); 617 clearSelection();
434 repaintContents( selectionCellX, selectionYTop, 618 repaintContents( selectionCellX, selectionYTop,
435 gridSpacingX, selectionHeight,false ); 619 gridSpacingX, selectionHeight,false );
436 } 620 }
437 selectItem(mActionItem); 621 selectItem(mActionItem);
438 Incidence *incidence = mActionItem->incidence(); 622 Incidence *incidence = mActionItem->incidence();
439 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { 623 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) {
440 mActionItem = 0; 624 mActionItem = 0;
441 } else { 625 } else {
442 startItemAction(viewportPos); 626 startItemAction(viewportPos);
443 } 627 }
444 } 628 }
445 } 629 }
446 } else { // ---------- viewport() 630 } else { // ---------- viewport()
447 selectItem(0); 631 selectItem(0);
448 mActionItem = 0; 632 mActionItem = 0;
449 if (me->button() == LeftButton ) { 633 if (me->button() == LeftButton ) {
450 setCursor(arrowCursor); 634 setCursor(arrowCursor);
451 startSelectAction(viewportPos); 635 startSelectAction(viewportPos);
452 } else if (me->button() == RightButton ) { 636 } else if (me->button() == RightButton ) {
453 setCursor(arrowCursor); 637 setCursor(arrowCursor);
454 if ( leftMouseDown ) { // we have a simulated right click - clear left mouse action 638 if ( leftMouseDown ) { // we have a simulated right click - clear left mouse action
455 endSelectAction( false ); // do not emit new event signal 639 endSelectAction( false ); // do not emit new event signal
456 leftMouseDown = false; // no more leftMouse computation 640 leftMouseDown = false; // no more leftMouse computation
457 } 641 }
458 int x,y; 642 int x,y;
459 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 643 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
460 int gx,gy; 644 int gx,gy;
461 contentsToGrid(x,y,gx,gy); 645 contentsToGrid(x,y,gx,gy);
462 mCurrentCellX = gx; 646 mCurrentCellX = gx;
463 mCurrentCellY = gy; 647 mCurrentCellY = gy;
464 mStartCellX = gx; 648 mStartCellX = gx;
465 mStartCellY = gy; 649 mStartCellY = gy;
466 mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) ); 650 mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) );
467 } 651 }
468 } 652 }
469 break; 653 break;
470 654
471 case QEvent::MouseButtonRelease: 655 case QEvent::MouseButtonRelease:
472 656
473 if (object != viewport()) { 657 if (object != viewport()) {
474 if (me->button() == LeftButton && leftMouseDown) { 658 if (me->button() == LeftButton && leftMouseDown) {
475 if (mActionItem) { 659 if (mActionItem) {
476 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 660 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos));
477 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); 661 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 );
478 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { 662 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) {
479 mScrollUpTimer.stop(); 663 mScrollUpTimer.stop();
480 mScrollDownTimer.stop(); 664 mScrollDownTimer.stop();
481 mActionItem->resetMove(); 665 mActionItem->resetMove();
482 placeSubCells( mActionItem ); 666 placeSubCells( mActionItem );
483 // emit startDragSignal( mActionItem->incidence() ); 667 // emit startDragSignal( mActionItem->incidence() );
484 setCursor( arrowCursor ); 668 setCursor( arrowCursor );
485 mActionItem = 0; 669 mActionItem = 0;
486 mActionType = NOP; 670 mActionType = NOP;
487 mItemMoved = 0; 671 mItemMoved = 0;
488 leftMouseDown = false; 672 leftMouseDown = false;
489 return true; 673 return true;
490 } 674 }
491 endItemAction(); 675 endItemAction();
492 } 676 }
493 } 677 }
494 678
495 } else { // ---------- viewport() 679 } else { // ---------- viewport()
496 if (me->button() == LeftButton && leftMouseDown ) { //left click 680 if (me->button() == LeftButton && leftMouseDown ) { //left click
497 endSelectAction( true ); // emit new event signal 681 endSelectAction( true ); // emit new event signal
498 } 682 }
499 } 683 }
500 if (me->button() == LeftButton) 684 if (me->button() == LeftButton)
501 leftMouseDown = false; 685 leftMouseDown = false;
502 686
503 break; 687 break;
504 688
505 case QEvent::MouseMove: 689 case QEvent::MouseMove:
506 if ( !leftMouseDown ) 690 if ( !leftMouseDown )
507 return true; 691 return true;
508 if ( blockMoving ) { 692 if ( blockMoving ) {
509 int dX, dY; 693 int dX, dY;
510 dX = startX - viewportPos.x(); 694 dX = startX - viewportPos.x();
511 if ( dX < 0 ) 695 if ( dX < 0 )
512 dX = -dX; 696 dX = -dX;
513 dY = viewportPos.y() - startY; 697 dY = viewportPos.y() - startY;
514 if ( dY < 0 ) 698 if ( dY < 0 )
515 dY = -dY; 699 dY = -dY;
516 //qDebug("%d %d %d ", dX, dY , blockmoveDist ); 700 //qDebug("%d %d %d ", dX, dY , blockmoveDist );
517 if ( dX > blockmoveDist || dY > blockmoveDist ) { 701 if ( dX > blockmoveDist || dY > blockmoveDist ) {
518 blockMoving = false; 702 blockMoving = false;
519 } 703 }
520 } 704 }
521 if (object != viewport()) { 705 if (object != viewport()) {
522 KOAgendaItem *moveItem = (KOAgendaItem *)object; 706 KOAgendaItem *moveItem = (KOAgendaItem *)object;
523 if (!moveItem->incidence()->isReadOnly() ) { 707 if (!moveItem->incidence()->isReadOnly() ) {
524 if (!mActionItem) 708 if (!mActionItem)
525 setNoActionCursor(moveItem,viewportPos); 709 setNoActionCursor(moveItem,viewportPos);
526 else { 710 else {
527 if ( !blockMoving ) 711 if ( !blockMoving )
528 performItemAction(viewportPos); 712 performItemAction(viewportPos);
529 } 713 }
530 } 714 }
531 } else { // ---------- viewport() 715 } else { // ---------- viewport()
532 if ( mActionType == SELECT ) { 716 if ( mActionType == SELECT ) {
533 performSelectAction( viewportPos ); 717 performSelectAction( viewportPos );
534 } 718 }
535 } 719 }
536 break; 720 break;
537 721
538 case QEvent::MouseButtonDblClick: 722 case QEvent::MouseButtonDblClick:
539 blockMoving = false; 723 blockMoving = false;
540 leftMouseDown = false; 724 leftMouseDown = false;
541 if (object == viewport()) { 725 if (object == viewport()) {
542 selectItem(0); 726 selectItem(0);
543 int x,y; 727 int x,y;
544 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 728 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
545 int gx,gy; 729 int gx,gy;
546 contentsToGrid(x,y,gx,gy); 730 contentsToGrid(x,y,gx,gy);
547 emit newEventSignal(gx,gy); 731 emit newEventSignal(gx,gy);
548 } else { 732 } else {
549 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; 733 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object;
550 selectItem(doubleClickedItem); 734 selectItem(doubleClickedItem);
551 if ( KOPrefs::instance()->mEditOnDoubleClick ) 735 if ( KOPrefs::instance()->mEditOnDoubleClick )
552 emit editIncidenceSignal(doubleClickedItem->incidence()); 736 emit editIncidenceSignal(doubleClickedItem->incidence());
553 else 737 else
554 emit showIncidenceSignal(doubleClickedItem->incidence()); 738 emit showIncidenceSignal(doubleClickedItem->incidence());
555 } 739 }
556 break; 740 break;
557 741
558 default: 742 default:
559 break; 743 break;
560 } 744 }
561 return true; 745 return true;
746#endif
562} 747}
563 748
564void KOAgenda::newItem( int item ) 749void KOAgenda::newItem( int item )
565{ 750{
566 if ( item == 1 ) { //new event 751 if ( item == 1 ) { //new event
567 newEventSignal(mStartCellX ,mStartCellY ); 752 newEventSignal(mStartCellX ,mStartCellY );
568 } else 753 } else
569 if ( item == 2 ) { //new event 754 if ( item == 2 ) { //new event
570 newTodoSignal(mStartCellX ,mStartCellY ); 755 newTodoSignal(mStartCellX ,mStartCellY );
571 } else 756 } else
572 { 757 {
573 QDate day = mSelectedDates[mStartCellX]; 758 QDate day = mSelectedDates[mStartCellX];
574 emit showDateView( item, day ); 759 emit showDateView( item, day );
575 // 3Day view 760 // 3Day view
576 // 4Week view 761 // 4Week view
577 // 5Month view 762 // 5Month view
578 // 6Journal view 763 // 6Journal view
579 } 764 }
580} 765}
581void KOAgenda::startSelectAction(QPoint viewportPos) 766void KOAgenda::startSelectAction(QPoint viewportPos)
582{ 767{
583 //emit newStartSelectSignal(); 768 //emit newStartSelectSignal();
584 769
585 mActionType = SELECT; 770 mActionType = SELECT;
586 771
587 int x,y; 772 int x,y;
588 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 773 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
589 int gx,gy; 774 int gx,gy;
590 contentsToGrid(x,y,gx,gy); 775 contentsToGrid(x,y,gx,gy);
591 776
592 mStartCellX = gx; 777 mStartCellX = gx;
593 mStartCellY = gy; 778 mStartCellY = gy;
594 mCurrentCellX = gx; 779 mCurrentCellX = gx;
595 mCurrentCellY = gy; 780 mCurrentCellY = gy;
596 781
597 // Store coordinates of old selection 782 // Store coordinates of old selection
598 int selectionX = mSelectionCellX * mGridSpacingX; 783 int selectionX = mSelectionCellX * mGridSpacingX;
599 int selectionYTop = mSelectionYTop; 784 int selectionYTop = mSelectionYTop;
600 int selectionHeight = mSelectionHeight; 785 int selectionHeight = mSelectionHeight;
601 786
602 // Store new selection 787 // Store new selection
603 mSelectionCellX = gx; 788 mSelectionCellX = gx;
604 mSelectionYTop = gy * mGridSpacingY; 789 mSelectionYTop = gy * mGridSpacingY;
605 mSelectionHeight = mGridSpacingY; 790 mSelectionHeight = mGridSpacingY;
606 791
607 // Clear old selection 792 // Clear old selection
608 repaintContents( selectionX, selectionYTop, 793 repaintContents( selectionX, selectionYTop,
609 mGridSpacingX, selectionHeight,false ); 794 mGridSpacingX, selectionHeight,false );
610 795
611 // Paint new selection 796 // Paint new selection
612 // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop, 797 // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop,
613 // mGridSpacingX, mSelectionHeight ); 798 // mGridSpacingX, mSelectionHeight );
614} 799}
615 800
616void KOAgenda::performSelectAction(QPoint viewportPos) 801void KOAgenda::performSelectAction(QPoint viewportPos)
617{ 802{
618 int x,y; 803 int x,y;
619 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 804 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
620 int gx,gy; 805 int gx,gy;
621 contentsToGrid(x,y,gx,gy); 806 contentsToGrid(x,y,gx,gy);
622 807
623 QPoint clipperPos = clipper()-> 808 QPoint clipperPos = clipper()->
624 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 809 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
625 810
626 // Scroll if cursor was moved to upper or lower end of agenda. 811 // Scroll if cursor was moved to upper or lower end of agenda.
627 if (clipperPos.y() < mScrollBorderWidth) { 812 if (clipperPos.y() < mScrollBorderWidth) {
628 mScrollUpTimer.start(mScrollDelay); 813 mScrollUpTimer.start(mScrollDelay);
629 } else if (visibleHeight() - clipperPos.y() < 814 } else if (visibleHeight() - clipperPos.y() <
630 mScrollBorderWidth) { 815 mScrollBorderWidth) {
631 mScrollDownTimer.start(mScrollDelay); 816 mScrollDownTimer.start(mScrollDelay);
632 } else { 817 } else {
633 mScrollUpTimer.stop(); 818 mScrollUpTimer.stop();
634 mScrollDownTimer.stop(); 819 mScrollDownTimer.stop();
635 } 820 }
636 821
637 if ( gy > mCurrentCellY ) { 822 if ( gy > mCurrentCellY ) {
638 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 823 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
639 824
640#if 0 825#if 0
641 // FIXME: Repaint only the newly selected region 826 // FIXME: Repaint only the newly selected region
642 repaintContents( mSelectionCellX * mGridSpacingX, 827 repaintContents( mSelectionCellX * mGridSpacingX,
643 mCurrentCellY + mGridSpacingY, 828 mCurrentCellY + mGridSpacingY,
644 mGridSpacingX, 829 mGridSpacingX,
645 mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY ); 830 mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY );
646#else 831#else
647 repaintContents( (KOGlobals::self()->reverseLayout() ? 832 repaintContents( (KOGlobals::self()->reverseLayout() ?
648 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 833 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
649 mGridSpacingX, mSelectionYTop, 834 mGridSpacingX, mSelectionYTop,
650 mGridSpacingX, mSelectionHeight , false); 835 mGridSpacingX, mSelectionHeight , false);
651#endif 836#endif
652 837
653 mCurrentCellY = gy; 838 mCurrentCellY = gy;
654 } else if ( gy < mCurrentCellY ) { 839 } else if ( gy < mCurrentCellY ) {
655 if ( gy >= mStartCellY ) { 840 if ( gy >= mStartCellY ) {
656 int selectionHeight = mSelectionHeight; 841 int selectionHeight = mSelectionHeight;
657 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 842 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
658 843
659 repaintContents( (KOGlobals::self()->reverseLayout() ? 844 repaintContents( (KOGlobals::self()->reverseLayout() ?
660 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 845 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
661 mGridSpacingX, mSelectionYTop, 846 mGridSpacingX, mSelectionYTop,
662 mGridSpacingX, selectionHeight,false ); 847 mGridSpacingX, selectionHeight,false );
663 848
664 mCurrentCellY = gy; 849 mCurrentCellY = gy;
665 } else { 850 } else {
666 } 851 }
667 } 852 }
668} 853}
669 854
670void KOAgenda::endSelectAction( bool emitNewEvent ) 855void KOAgenda::endSelectAction( bool emitNewEvent )
671{ 856{
672 mActionType = NOP; 857 mActionType = NOP;
673 mScrollUpTimer.stop(); 858 mScrollUpTimer.stop();
674 mScrollDownTimer.stop(); 859 mScrollDownTimer.stop();
675 860
676 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); 861 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
677 if ( emitNewEvent && mStartCellY < mCurrentCellY ) { 862 if ( emitNewEvent && mStartCellY < mCurrentCellY ) {
678 qDebug("ew event signal "); 863 qDebug("ew event signal ");
679 emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); 864 emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
680 } 865 }
681} 866}
682 867
683void KOAgenda::startItemAction(QPoint viewportPos) 868void KOAgenda::startItemAction(QPoint viewportPos)
684{ 869{
685 int x,y; 870 int x,y;
686 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 871 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
687 int gx,gy; 872 int gx,gy;
688 contentsToGrid(x,y,gx,gy); 873 contentsToGrid(x,y,gx,gy);
689 874
690 mStartCellX = gx; 875 mStartCellX = gx;
691 mStartCellY = gy; 876 mStartCellY = gy;
692 mCurrentCellX = gx; 877 mCurrentCellX = gx;
693 mCurrentCellY = gy; 878 mCurrentCellY = gy;
694 879
695 if (mAllDayMode) { 880 if (mAllDayMode) {
696 int gridDistanceX = (x - gx * mGridSpacingX); 881 int gridDistanceX = (x - gx * mGridSpacingX);
697 if (gridDistanceX < mResizeBorderWidth && 882 if (gridDistanceX < mResizeBorderWidth &&
698 mActionItem->cellX() == mCurrentCellX) { 883 mActionItem->cellX() == mCurrentCellX) {
699 mActionType = RESIZELEFT; 884 mActionType = RESIZELEFT;
700 setCursor(sizeHorCursor); 885 setCursor(sizeHorCursor);
701 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 886 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
702 mActionItem->cellXWidth() == mCurrentCellX) { 887 mActionItem->cellXWidth() == mCurrentCellX) {
703 mActionType = RESIZERIGHT; 888 mActionType = RESIZERIGHT;
704 setCursor(sizeHorCursor); 889 setCursor(sizeHorCursor);
705 } else { 890 } else {
706 mActionType = MOVE; 891 mActionType = MOVE;
707 mActionItem->startMove(); 892 mActionItem->startMove();
708 setCursor(sizeAllCursor); 893 setCursor(sizeAllCursor);
709 } 894 }
710 } else { 895 } else {
711 int gridDistanceY = (y - gy * mGridSpacingY); 896 int gridDistanceY = (y - gy * mGridSpacingY);
712 bool allowResize = ( mActionItem->incidence()->type() != "Todo" ); 897 bool allowResize = ( mActionItem->incidence()->type() != "Todo" );
713 if (allowResize && gridDistanceY < mResizeBorderWidth && 898 if (allowResize && gridDistanceY < mResizeBorderWidth &&
714 mActionItem->cellYTop() == mCurrentCellY && 899 mActionItem->cellYTop() == mCurrentCellY &&
715 !mActionItem->firstMultiItem()) { 900 !mActionItem->firstMultiItem()) {
716 mActionType = RESIZETOP; 901 mActionType = RESIZETOP;
717 setCursor(sizeVerCursor); 902 setCursor(sizeVerCursor);
718 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 903 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
719 mActionItem->cellYBottom() == mCurrentCellY && 904 mActionItem->cellYBottom() == mCurrentCellY &&
720 !mActionItem->lastMultiItem()) { 905 !mActionItem->lastMultiItem()) {
721 mActionType = RESIZEBOTTOM; 906 mActionType = RESIZEBOTTOM;
722 setCursor(sizeVerCursor); 907 setCursor(sizeVerCursor);
723 } else { 908 } else {
724 mActionType = MOVE; 909 mActionType = MOVE;
725 mActionItem->startMove(); 910 mActionItem->startMove();
726 setCursor(sizeAllCursor); 911 setCursor(sizeAllCursor);
727 } 912 }
728 } 913 }
729} 914}
730 915
731void KOAgenda::performItemAction(QPoint viewportPos) 916void KOAgenda::performItemAction(QPoint viewportPos)
732{ 917{
733// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 918// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
734// QPoint point = viewport()->mapToGlobal(viewportPos); 919// QPoint point = viewport()->mapToGlobal(viewportPos);
735// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 920// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
736// point = clipper()->mapFromGlobal(point); 921// point = clipper()->mapFromGlobal(point);
737// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 922// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
738// kdDebug() << "visible height: " << visibleHeight() << endl; 923// kdDebug() << "visible height: " << visibleHeight() << endl;
739 int x,y; 924 int x,y;
740 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 925 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
741// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 926// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
742 int gx,gy; 927 int gx,gy;
743 contentsToGrid(x,y,gx,gy); 928 contentsToGrid(x,y,gx,gy);
744 QPoint clipperPos = clipper()-> 929 QPoint clipperPos = clipper()->
745 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 930 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
746 931
747 // Cursor left active agenda area. 932 // Cursor left active agenda area.
748 // This starts a drag. 933 // This starts a drag.
749 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/ 934 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/
750 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) { 935 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) {
751 if ( mActionType == MOVE ) { 936 if ( mActionType == MOVE ) {
752 mScrollUpTimer.stop(); 937 mScrollUpTimer.stop();
753 mScrollDownTimer.stop(); 938 mScrollDownTimer.stop();
754 mActionItem->resetMove(); 939 mActionItem->resetMove();
755 placeSubCells( mActionItem ); 940 placeSubCells( mActionItem );
756 // emit startDragSignal( mActionItem->incidence() ); 941 // emit startDragSignal( mActionItem->incidence() );
757 setCursor( arrowCursor ); 942 setCursor( arrowCursor );
758 mActionItem = 0; 943 mActionItem = 0;
759 mActionType = NOP; 944 mActionType = NOP;
760 mItemMoved = 0; 945 mItemMoved = 0;
761 return; 946 return;
762 } 947 }
763 } else { 948 } else {
764 switch ( mActionType ) { 949 switch ( mActionType ) {
765 case MOVE: 950 case MOVE:
766 setCursor( sizeAllCursor ); 951 setCursor( sizeAllCursor );
767 break; 952 break;
768 case RESIZETOP: 953 case RESIZETOP:
769 case RESIZEBOTTOM: 954 case RESIZEBOTTOM:
770 setCursor( sizeVerCursor ); 955 setCursor( sizeVerCursor );
771 break; 956 break;
772 case RESIZELEFT: 957 case RESIZELEFT:
773 case RESIZERIGHT: 958 case RESIZERIGHT:
774 setCursor( sizeHorCursor ); 959 setCursor( sizeHorCursor );
775 break; 960 break;
776 default: 961 default:
777 setCursor( arrowCursor ); 962 setCursor( arrowCursor );
778 } 963 }
779 } 964 }
780 965
781 // Scroll if item was moved to upper or lower end of agenda. 966 // Scroll if item was moved to upper or lower end of agenda.
782 if (clipperPos.y() < mScrollBorderWidth) { 967 if (clipperPos.y() < mScrollBorderWidth) {
783 mScrollUpTimer.start(mScrollDelay); 968 mScrollUpTimer.start(mScrollDelay);
784 } else if (visibleHeight() - clipperPos.y() < 969 } else if (visibleHeight() - clipperPos.y() <
785 mScrollBorderWidth) { 970 mScrollBorderWidth) {
786 mScrollDownTimer.start(mScrollDelay); 971 mScrollDownTimer.start(mScrollDelay);
787 } else { 972 } else {
788 mScrollUpTimer.stop(); 973 mScrollUpTimer.stop();
789 mScrollDownTimer.stop(); 974 mScrollDownTimer.stop();
790 } 975 }
791 976
792 // Move or resize item if necessary 977 // Move or resize item if necessary
793 if (mCurrentCellX != gx || mCurrentCellY != gy) { 978 if (mCurrentCellX != gx || mCurrentCellY != gy) {
794 mItemMoved = true; 979 mItemMoved = true;
795 mActionItem->raise(); 980 mActionItem->raise();
796 if (mActionType == MOVE) { 981 if (mActionType == MOVE) {
797 // Move all items belonging to a multi item 982 // Move all items belonging to a multi item
798 KOAgendaItem *moveItem = mActionItem->firstMultiItem(); 983 KOAgendaItem *moveItem = mActionItem->firstMultiItem();
799 bool isMultiItem = (moveItem || mActionItem->lastMultiItem()); 984 bool isMultiItem = (moveItem || mActionItem->lastMultiItem());
800 if (!moveItem) moveItem = mActionItem; 985 if (!moveItem) moveItem = mActionItem;
801 while (moveItem) { 986 while (moveItem) {
802 int dy; 987 int dy;
803 if (isMultiItem) dy = 0; 988 if (isMultiItem) dy = 0;
804 else dy = gy - mCurrentCellY; 989 else dy = gy - mCurrentCellY;
805 moveItem->moveRelative(gx - mCurrentCellX,dy); 990 moveItem->moveRelative(gx - mCurrentCellX,dy);
806 int x,y; 991 int x,y;
807 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y); 992 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y);
808 moveItem->resize(mGridSpacingX * moveItem->cellWidth(), 993 moveItem->resize(mGridSpacingX * moveItem->cellWidth(),
809 mGridSpacingY * moveItem->cellHeight()); 994 mGridSpacingY * moveItem->cellHeight());
810 moveChild(moveItem,x,y); 995 moveChild(moveItem,x,y);
811 moveItem = moveItem->nextMultiItem(); 996 moveItem = moveItem->nextMultiItem();
812 } 997 }
813 } else if (mActionType == RESIZETOP) { 998 } else if (mActionType == RESIZETOP) {
814 if (mCurrentCellY <= mActionItem->cellYBottom()) { 999 if (mCurrentCellY <= mActionItem->cellYBottom()) {
815 mActionItem->expandTop(gy - mCurrentCellY); 1000 mActionItem->expandTop(gy - mCurrentCellY);
816 mActionItem->resize(mActionItem->width(), 1001 mActionItem->resize(mActionItem->width(),
817 mGridSpacingY * mActionItem->cellHeight()); 1002 mGridSpacingY * mActionItem->cellHeight());
818 int x,y; 1003 int x,y;
819 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y); 1004 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y);
820 //moveChild(mActionItem,childX(mActionItem),y); 1005 //moveChild(mActionItem,childX(mActionItem),y);
821 QScrollView::moveChild( mActionItem,childX(mActionItem),y ); 1006 QScrollView::moveChild( mActionItem,childX(mActionItem),y );
822 } 1007 }
823 } else if (mActionType == RESIZEBOTTOM) { 1008 } else if (mActionType == RESIZEBOTTOM) {
824 if (mCurrentCellY >= mActionItem->cellYTop()) { 1009 if (mCurrentCellY >= mActionItem->cellYTop()) {
825 mActionItem->expandBottom(gy - mCurrentCellY); 1010 mActionItem->expandBottom(gy - mCurrentCellY);
826 mActionItem->resize(mActionItem->width(), 1011 mActionItem->resize(mActionItem->width(),
827 mGridSpacingY * mActionItem->cellHeight()); 1012 mGridSpacingY * mActionItem->cellHeight());
828 } 1013 }
829 } else if (mActionType == RESIZELEFT) { 1014 } else if (mActionType == RESIZELEFT) {
830 if (mCurrentCellX <= mActionItem->cellXWidth()) { 1015 if (mCurrentCellX <= mActionItem->cellXWidth()) {
831 mActionItem->expandLeft(gx - mCurrentCellX); 1016 mActionItem->expandLeft(gx - mCurrentCellX);
832 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 1017 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
833 mActionItem->height()); 1018 mActionItem->height());
834 int x,y; 1019 int x,y;
835 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y); 1020 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y);
836 moveChild(mActionItem,x,childY(mActionItem)); 1021 moveChild(mActionItem,x,childY(mActionItem));
837 } 1022 }
838 } else if (mActionType == RESIZERIGHT) { 1023 } else if (mActionType == RESIZERIGHT) {
839 if (mCurrentCellX >= mActionItem->cellX()) { 1024 if (mCurrentCellX >= mActionItem->cellX()) {
840 mActionItem->expandRight(gx - mCurrentCellX); 1025 mActionItem->expandRight(gx - mCurrentCellX);
841 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 1026 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
842 mActionItem->height()); 1027 mActionItem->height());
843 } 1028 }
844 } 1029 }
845 mCurrentCellX = gx; 1030 mCurrentCellX = gx;
846 mCurrentCellY = gy; 1031 mCurrentCellY = gy;
847 } 1032 }
848} 1033}
849 1034
850void KOAgenda::endItemAction() 1035void KOAgenda::endItemAction()
851{ 1036{
852 1037
853 if ( mItemMoved ) { 1038 if ( mItemMoved ) {
854 KOAgendaItem *placeItem = mActionItem->firstMultiItem(); 1039 KOAgendaItem *placeItem = mActionItem->firstMultiItem();
855 if ( !placeItem ) { 1040 if ( !placeItem ) {
856 placeItem = mActionItem; 1041 placeItem = mActionItem;
857 } 1042 }
858 if ( placeItem->incidence()->recurrence()->doesRecur() ) { 1043 if ( placeItem->incidence()->recurrence()->doesRecur() ) {
859 Incidence* oldInc = placeItem->incidence(); 1044 Incidence* oldInc = placeItem->incidence();
860 placeItem->recreateIncidence(); 1045 placeItem->recreateIncidence();
861 emit addToCalSignal(placeItem->incidence(), oldInc ); 1046 emit addToCalSignal(placeItem->incidence(), oldInc );
862 } 1047 }
863 int type = mActionType; 1048 int type = mActionType;
864 if ( mAllDayMode ) 1049 if ( mAllDayMode )
865 type = -1; 1050 type = -1;
866 KOAgendaItem *modifiedItem = placeItem; 1051 KOAgendaItem *modifiedItem = placeItem;
867 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */); 1052 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */);
868 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems(); 1053 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems();
869 KOAgendaItem *item; 1054 KOAgendaItem *item;
870 1055
871 if ( placeItem->incidence()->type() == "Todo" ) { 1056 if ( placeItem->incidence()->type() == "Todo" ) {
872 mSelectedItem = 0; 1057 mSelectedItem = 0;
873 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth()); 1058 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth());
874 modifiedItem->mLastMoveXPos = mCurrentCellX; 1059 modifiedItem->mLastMoveXPos = mCurrentCellX;
875 emit itemModified( modifiedItem, mActionType ); 1060 emit itemModified( modifiedItem, mActionType );
876 } 1061 }
877 else { 1062 else {
878#if 0 1063#if 0
879 for ( item=oldconflictItems.first(); item != 0; 1064 for ( item=oldconflictItems.first(); item != 0;
880 item=oldconflictItems.next() ) { 1065 item=oldconflictItems.next() ) {
881 placeSubCells(item); 1066 placeSubCells(item);
882 } 1067 }
883 while ( placeItem ) { 1068 while ( placeItem ) {
884 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 1069 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
885 placeSubCells( placeItem ); 1070 placeSubCells( placeItem );
886 placeItem = placeItem->nextMultiItem(); 1071 placeItem = placeItem->nextMultiItem();
887 } 1072 }
888#endif 1073#endif
889 1074
890 globalFlagBlockAgendaItemPaint = 1; 1075 globalFlagBlockAgendaItemPaint = 1;
891 for ( item=oldconflictItems.first(); item != 0; 1076 for ( item=oldconflictItems.first(); item != 0;
892 item=oldconflictItems.next() ) { 1077 item=oldconflictItems.next() ) {
893 placeSubCells(item); 1078 placeSubCells(item);
894 } 1079 }
895 while ( placeItem ) { 1080 while ( placeItem ) {
896 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 1081 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
897 oldconflictItems = placeItem->conflictItems(); 1082 oldconflictItems = placeItem->conflictItems();
898 for ( item=oldconflictItems.first(); item != 0; 1083 for ( item=oldconflictItems.first(); item != 0;
899 item=oldconflictItems.next() ) { 1084 item=oldconflictItems.next() ) {
900 placeSubCells(item); 1085 placeSubCells(item);
901 } 1086 }
902 placeSubCells( placeItem ); 1087 placeSubCells( placeItem );
903 placeItem = placeItem->nextMultiItem(); 1088 placeItem = placeItem->nextMultiItem();
904 } 1089 }
905 globalFlagBlockAgendaItemPaint = 0; 1090 globalFlagBlockAgendaItemPaint = 0;
906 for ( item=oldconflictItems.first(); item != 0; 1091 for ( item=oldconflictItems.first(); item != 0;
907 item=oldconflictItems.next() ) { 1092 item=oldconflictItems.next() ) {
908 globalFlagBlockAgendaItemUpdate = 0; 1093 globalFlagBlockAgendaItemUpdate = 0;
909 item->repaintMe(); 1094 item->repaintMe();
910 globalFlagBlockAgendaItemUpdate = 1; 1095 globalFlagBlockAgendaItemUpdate = 1;
911 item->repaint( false ); 1096 item->repaint( false );
912 } 1097 }
913 placeItem = modifiedItem; 1098 placeItem = modifiedItem;
914 1099
915 while ( placeItem ) { 1100 while ( placeItem ) {
916 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 1101 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
917 globalFlagBlockAgendaItemUpdate = 0; 1102 globalFlagBlockAgendaItemUpdate = 0;
918 placeItem->repaintMe(); 1103 placeItem->repaintMe();
919 globalFlagBlockAgendaItemUpdate = 1; 1104 globalFlagBlockAgendaItemUpdate = 1;
920 placeItem->repaint(false); 1105 placeItem->repaint(false);
921 placeItem = placeItem->nextMultiItem(); 1106 placeItem = placeItem->nextMultiItem();
922 } 1107 }
923 emit itemModified( modifiedItem, mActionType ); 1108 emit itemModified( modifiedItem, mActionType );
924 1109
925 1110
926 placeItem = modifiedItem; 1111 placeItem = modifiedItem;
927 while ( placeItem ) { 1112 while ( placeItem ) {
928 oldconflictItems = placeItem->conflictItems(); 1113 oldconflictItems = placeItem->conflictItems();
929 for ( item=oldconflictItems.first(); item != 0; 1114 for ( item=oldconflictItems.first(); item != 0;
930 item=oldconflictItems.next() ) { 1115 item=oldconflictItems.next() ) {
931 placeSubCells(item); 1116 placeSubCells(item);
932 } 1117 }
933 placeSubCells( placeItem ); 1118 placeSubCells( placeItem );
934 placeItem = placeItem->nextMultiItem(); 1119 placeItem = placeItem->nextMultiItem();
935 1120
936 } 1121 }
937 placeItem = modifiedItem; 1122 placeItem = modifiedItem;
938 while ( placeItem ) { 1123 while ( placeItem ) {
939 oldconflictItems = placeItem->conflictItems(); 1124 oldconflictItems = placeItem->conflictItems();
940 for ( item=oldconflictItems.first(); item != 0; 1125 for ( item=oldconflictItems.first(); item != 0;
941 item=oldconflictItems.next() ) { 1126 item=oldconflictItems.next() ) {
942 globalFlagBlockAgendaItemUpdate = 0; 1127 globalFlagBlockAgendaItemUpdate = 0;
943 item->repaintMe(); 1128 item->repaintMe();
944 globalFlagBlockAgendaItemUpdate = 1; 1129 globalFlagBlockAgendaItemUpdate = 1;
945 item->repaint(false); 1130 item->repaint(false);
946 } 1131 }
947 placeItem = placeItem->nextMultiItem(); 1132 placeItem = placeItem->nextMultiItem();
948 } 1133 }
949 /* 1134 /*
950 1135
951 oldconflictItems = modifiedItem->conflictItems(); 1136 oldconflictItems = modifiedItem->conflictItems();
952 for ( item=oldconflictItems.first(); item != 0; 1137 for ( item=oldconflictItems.first(); item != 0;
953 item=oldconflictItems.next() ) { 1138 item=oldconflictItems.next() ) {
954 globalFlagBlockAgendaItemUpdate = 0; 1139 globalFlagBlockAgendaItemUpdate = 0;
955 item->paintMe(false); 1140 item->paintMe(false);
956 globalFlagBlockAgendaItemUpdate = 1; 1141 globalFlagBlockAgendaItemUpdate = 1;
957 item->repaint(false); 1142 item->repaint(false);
958 } 1143 }
959 */ 1144 */
960 1145
961 1146
962 } 1147 }
963 1148
964 } 1149 }
965 1150
966 mScrollUpTimer.stop(); 1151 mScrollUpTimer.stop();
967 mScrollDownTimer.stop(); 1152 mScrollDownTimer.stop();
968 setCursor( arrowCursor ); 1153 setCursor( arrowCursor );
969 mActionItem = 0; 1154 mActionItem = 0;
970 mActionType = NOP; 1155 mActionType = NOP;
971 mItemMoved = 0; 1156 mItemMoved = 0;
972 1157
973} 1158}
974 1159
975void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos) 1160void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos)
976{ 1161{
977// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 1162// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
978// QPoint point = viewport()->mapToGlobal(viewportPos); 1163// QPoint point = viewport()->mapToGlobal(viewportPos);
979// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 1164// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
980// point = clipper()->mapFromGlobal(point); 1165// point = clipper()->mapFromGlobal(point);
981// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 1166// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
982 1167
983 int x,y; 1168 int x,y;
984 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 1169 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
985// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 1170// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
986 int gx,gy; 1171 int gx,gy;
987 contentsToGrid(x,y,gx,gy); 1172 contentsToGrid(x,y,gx,gy);
988 1173
989 // Change cursor to resize cursor if appropriate 1174 // Change cursor to resize cursor if appropriate
990 if (mAllDayMode) { 1175 if (mAllDayMode) {
991 int gridDistanceX = (x - gx * mGridSpacingX); 1176 int gridDistanceX = (x - gx * mGridSpacingX);
992 if (gridDistanceX < mResizeBorderWidth && 1177 if (gridDistanceX < mResizeBorderWidth &&
993 moveItem->cellX() == gx) { 1178 moveItem->cellX() == gx) {
994 setCursor(sizeHorCursor); 1179 setCursor(sizeHorCursor);
995 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 1180 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
996 moveItem->cellXWidth() == gx) { 1181 moveItem->cellXWidth() == gx) {
997 setCursor(sizeHorCursor); 1182 setCursor(sizeHorCursor);
998 } else { 1183 } else {
999 setCursor(arrowCursor); 1184 setCursor(arrowCursor);
1000 } 1185 }
1001 } else { 1186 } else {
1002 int gridDistanceY = (y - gy * mGridSpacingY); 1187 int gridDistanceY = (y - gy * mGridSpacingY);
1003 if (gridDistanceY < mResizeBorderWidth && 1188 if (gridDistanceY < mResizeBorderWidth &&
1004 moveItem->cellYTop() == gy && 1189 moveItem->cellYTop() == gy &&
1005 !moveItem->firstMultiItem()) { 1190 !moveItem->firstMultiItem()) {
1006 setCursor(sizeVerCursor); 1191 setCursor(sizeVerCursor);
1007 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 1192 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
1008 moveItem->cellYBottom() == gy && 1193 moveItem->cellYBottom() == gy &&
1009 !moveItem->lastMultiItem()) { 1194 !moveItem->lastMultiItem()) {
1010 setCursor(sizeVerCursor); 1195 setCursor(sizeVerCursor);
1011 } else { 1196 } else {
1012 setCursor(arrowCursor); 1197 setCursor(arrowCursor);
1013 } 1198 }
1014 } 1199 }
1015} 1200}
1016 1201
1017 1202
1018/* 1203/*
1019 Place item in cell and take care that multiple items using the same cell do 1204 Place item in cell and take care that multiple items using the same cell do
1020 not overlap. This method is not yet optimal. It doesn´t use the maximum space 1205 not overlap. This method is not yet optimal. It doesn´t use the maximum space
1021 it can get in all cases. 1206 it can get in all cases.
1022 At the moment the method has a bug: When an item is placed only the sub cell 1207 At the moment the method has a bug: When an item is placed only the sub cell
1023 widths of the items are changed, which are within the Y region the item to 1208 widths of the items are changed, which are within the Y region the item to
1024 place spans. When the sub cell width change of one of this items affects a 1209 place spans. When the sub cell width change of one of this items affects a
1025 cell, where other items are, which do not overlap in Y with the item to place, 1210 cell, where other items are, which do not overlap in Y with the item to place,
1026 the display gets corrupted, although the corruption looks quite nice. 1211 the display gets corrupted, although the corruption looks quite nice.
1027*/ 1212*/
1028void KOAgenda::placeSubCells(KOAgendaItem *placeItem) 1213void KOAgenda::placeSubCells(KOAgendaItem *placeItem)
1029{ 1214{
1030 1215
1031 QPtrList<KOAgendaItem> conflictItems; 1216 QPtrList<KOAgendaItem> conflictItems;
1032 int maxSubCells = 0; 1217 int maxSubCells = 0;
1033 QIntDict<KOAgendaItem> subCellDict(5); 1218 QIntDict<KOAgendaItem> subCellDict(5);
1034 1219
1035 KOAgendaItem *item; 1220 KOAgendaItem *item;
1036 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1221 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1037 if (item != placeItem) { 1222 if (item != placeItem) {
1038 if (placeItem->cellX() <= item->cellXWidth() && 1223 if (placeItem->cellX() <= item->cellXWidth() &&
1039 placeItem->cellXWidth() >= item->cellX()) { 1224 placeItem->cellXWidth() >= item->cellX()) {
1040 if ((placeItem->cellYTop() <= item->cellYBottom()) && 1225 if ((placeItem->cellYTop() <= item->cellYBottom()) &&
1041 (placeItem->cellYBottom() >= item->cellYTop())) { 1226 (placeItem->cellYBottom() >= item->cellYTop())) {
1042 conflictItems.append(item); 1227 conflictItems.append(item);
1043 if (item->subCells() > maxSubCells) 1228 if (item->subCells() > maxSubCells)
1044 maxSubCells = item->subCells(); 1229 maxSubCells = item->subCells();
1045 subCellDict.insert(item->subCell(),item); 1230 subCellDict.insert(item->subCell(),item);
1046 } 1231 }
1047 } 1232 }
1048 } 1233 }
1049 } 1234 }
1050 1235
1051 if (conflictItems.count() > 0) { 1236 if (conflictItems.count() > 0) {
1052 // Look for unused sub cell and insert item 1237 // Look for unused sub cell and insert item
1053 int i; 1238 int i;
1054 for(i=0;i<maxSubCells;++i) { 1239 for(i=0;i<maxSubCells;++i) {
1055 if (!subCellDict.find(i)) { 1240 if (!subCellDict.find(i)) {
1056 placeItem->setSubCell(i); 1241 placeItem->setSubCell(i);
1057 break; 1242 break;
1058 } 1243 }
1059 } 1244 }
1060 if (i == maxSubCells) { 1245 if (i == maxSubCells) {
1061 placeItem->setSubCell(maxSubCells); 1246 placeItem->setSubCell(maxSubCells);
1062 maxSubCells++; // add new item to number of sub cells 1247 maxSubCells++; // add new item to number of sub cells
1063 } 1248 }
1064 1249
1065 // Prepare for sub cell geometry adjustment 1250 // Prepare for sub cell geometry adjustment
1066 int newSubCellWidth; 1251 int newSubCellWidth;
1067 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells; 1252 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells;
1068 else newSubCellWidth = mGridSpacingX / maxSubCells; 1253 else newSubCellWidth = mGridSpacingX / maxSubCells;
1069 conflictItems.append(placeItem); 1254 conflictItems.append(placeItem);
1070 1255
1071 1256
1072 // Adjust sub cell geometry of all direct conflict items 1257 // Adjust sub cell geometry of all direct conflict items
1073 for ( item=conflictItems.first(); item != 0; 1258 for ( item=conflictItems.first(); item != 0;
1074 item=conflictItems.next() ) { 1259 item=conflictItems.next() ) {
1075 item->setSubCells(maxSubCells); 1260 item->setSubCells(maxSubCells);
1076 if (mAllDayMode) { 1261 if (mAllDayMode) {
1077 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); 1262 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth);
1078 } else { 1263 } else {
1079 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); 1264 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY);
1080 } 1265 }
1081 int x,y; 1266 int x,y;
1082 gridToContents(item->cellX(),item->cellYTop(),x,y); 1267 gridToContents(item->cellX(),item->cellYTop(),x,y);
1083 if (mAllDayMode) { 1268 if (mAllDayMode) {
1084 y += item->subCell() * newSubCellWidth; 1269 y += item->subCell() * newSubCellWidth;
1085 } else { 1270 } else {
1086 x += item->subCell() * newSubCellWidth; 1271 x += item->subCell() * newSubCellWidth;
1087 } 1272 }
1088 moveChild(item,x,y); 1273 moveChild(item,x,y);
1089 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y); 1274 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y);
1090 //item->updateItem(); 1275 //item->updateItem();
1091 } 1276 }
1092 // Adjust sub cell geometry of all conflict items of all conflict items 1277 // Adjust sub cell geometry of all conflict items of all conflict items
1093 for ( item=conflictItems.first(); item != 0; 1278 for ( item=conflictItems.first(); item != 0;
1094 item=conflictItems.next() ) { 1279 item=conflictItems.next() ) {
1095 if ( placeItem != item ) { 1280 if ( placeItem != item ) {
1096 KOAgendaItem *item2; 1281 KOAgendaItem *item2;
1097 QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems(); 1282 QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems();
1098 for ( item2=conflictItems2.first(); item2 != 0; 1283 for ( item2=conflictItems2.first(); item2 != 0;
1099 item2=conflictItems2.next() ) { 1284 item2=conflictItems2.next() ) {
1100 if ( item2->subCells() != maxSubCells) { 1285 if ( item2->subCells() != maxSubCells) {
1101 item2->setSubCells(maxSubCells); 1286 item2->setSubCells(maxSubCells);
1102 if (mAllDayMode) { 1287 if (mAllDayMode) {
1103 item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth); 1288 item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth);
1104 } else { 1289 } else {
1105 item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY); 1290 item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY);
1106 } 1291 }
1107 int x,y; 1292 int x,y;
1108 gridToContents(item2->cellX(),item2->cellYTop(),x,y); 1293 gridToContents(item2->cellX(),item2->cellYTop(),x,y);
1109 if (mAllDayMode) { 1294 if (mAllDayMode) {
1110 y += item2->subCell() * newSubCellWidth; 1295 y += item2->subCell() * newSubCellWidth;
1111 } else { 1296 } else {
1112 x += item2->subCell() * newSubCellWidth; 1297 x += item2->subCell() * newSubCellWidth;
1113 } 1298 }
1114 moveChild(item2,x,y); 1299 moveChild(item2,x,y);
1115 //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() ); 1300 //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() );
1116 } 1301 }
1117 } 1302 }
1118 } 1303 }
1119 } 1304 }
1120 } else { 1305 } else {
1121 placeItem->setSubCell(0); 1306 placeItem->setSubCell(0);
1122 placeItem->setSubCells(1); 1307 placeItem->setSubCells(1);
1123 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY); 1308 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY);
1124 else placeItem->resize(mGridSpacingX,placeItem->height()); 1309 else placeItem->resize(mGridSpacingX,placeItem->height());
1125 int x,y; 1310 int x,y;
1126 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y); 1311 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y);
1127 moveChild(placeItem,x,y); 1312 moveChild(placeItem,x,y);
1128 } 1313 }
1129 placeItem->setConflictItems(conflictItems); 1314 placeItem->setConflictItems(conflictItems);
1130 // for ( item=conflictItems.first(); item != 0; 1315 // for ( item=conflictItems.first(); item != 0;
1131// item=conflictItems.next() ) { 1316// item=conflictItems.next() ) {
1132// //item->updateItem(); 1317// //item->updateItem();
1133// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() ); 1318// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() );
1134// } 1319// }
1135// placeItem->updateItem(); 1320// placeItem->updateItem();
1136} 1321}
1137 1322
1138void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch) 1323void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
1139{ 1324{
1140 if ( globalFlagBlockAgenda ) 1325 if ( globalFlagBlockAgenda )
1141 return; 1326 return;
1142 //qDebug("KOAgenda::drawContents "); 1327 //qDebug("KOAgenda::drawContents ");
1143 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) 1328 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() )
1144 ;//drawContentsToPainter(); 1329 ;//drawContentsToPainter();
1145 1330
1146 QPaintDevice* pd = p->device(); 1331 QPaintDevice* pd = p->device();
1147 p->end(); 1332 p->end();
1148 int vx, vy; 1333 int vx, vy;
1149 int selectionX = KOGlobals::self()->reverseLayout() ? 1334 int selectionX = KOGlobals::self()->reverseLayout() ?
1150 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1335 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1151 mSelectionCellX * mGridSpacingX; 1336 mSelectionCellX * mGridSpacingX;
1152 contentsToViewport ( cx, cy, vx,vy); 1337 contentsToViewport ( cx, cy, vx,vy);
1153 // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ; 1338 // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ;
1154 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) 1339 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) )
1155 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); 1340 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP);
1156 1341
1157 if ( mSelectionHeight > 0 ) { 1342 if ( mSelectionHeight > 0 ) {
1158 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); 1343 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight );
1159 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1344 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1160 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1345 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1161 contentsToViewport ( selectionX, mSelectionYTop, vx,vy); 1346 contentsToViewport ( selectionX, mSelectionYTop, vx,vy);
1162 bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); 1347 bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP);
1163 } 1348 }
1164 } 1349 }
1165 //qDebug("btbl "); 1350 //qDebug("btbl ");
1166 p->begin( pd ); 1351 p->begin( pd );
1167 //qDebug("end "); 1352 //qDebug("end ");
1168} 1353}
1169 1354
1170void KOAgenda::finishUpdate() 1355void KOAgenda::finishUpdate()
1171{ 1356{
1172 1357
1173 KOAgendaItem *item; 1358 KOAgendaItem *item;
1174 globalFlagBlockAgendaItemPaint = 1; 1359 globalFlagBlockAgendaItemPaint = 1;
1175 // Adjust sub cell geometry of all conflict items of all conflict items of all conflict items ... of the conflict item with the max number of conflictitems 1360 // Adjust sub cell geometry of all conflict items of all conflict items of all conflict items ... of the conflict item with the max number of conflictitems
1176 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1361 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1177 if ( !item->checkLayout() ) { 1362 if ( !item->checkLayout() ) {
1178 //qDebug(" conflictitem found "); 1363 //qDebug(" conflictitem found ");
1179 int newSubCellWidth; 1364 int newSubCellWidth;
1180 if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells(); 1365 if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells();
1181 else newSubCellWidth = mGridSpacingX / item->subCells(); 1366 else newSubCellWidth = mGridSpacingX / item->subCells();
1182 1367
1183 if (mAllDayMode) { 1368 if (mAllDayMode) {
1184 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); 1369 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth);
1185 } else { 1370 } else {
1186 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); 1371 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY);
1187 } 1372 }
1188 int x,y; 1373 int x,y;
1189 gridToContents(item->cellX(),item->cellYTop(),x,y); 1374 gridToContents(item->cellX(),item->cellYTop(),x,y);
1190 if (mAllDayMode) { 1375 if (mAllDayMode) {
1191 y += item->subCell() * newSubCellWidth; 1376 y += item->subCell() * newSubCellWidth;
1192 } else { 1377 } else {
1193 x += item->subCell() * newSubCellWidth; 1378 x += item->subCell() * newSubCellWidth;
1194 } 1379 }
1195 moveChild(item,x,y); 1380 moveChild(item,x,y);
1196 } 1381 }
1197 } 1382 }
1198 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1383 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1199 if ( !item->isVisible() ) 1384 if ( !item->isVisible() )
1200 item->show(); 1385 item->show();
1201 1386
1202 } 1387 }
1203 globalFlagBlockAgendaItemUpdate = 0; 1388 globalFlagBlockAgendaItemUpdate = 0;
1204 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1389 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1205 item->repaintMe( ); 1390 item->repaintMe( );
1206 } 1391 }
1207 globalFlagBlockAgendaItemUpdate = 1; 1392 globalFlagBlockAgendaItemUpdate = 1;
1208 qApp->processEvents(); 1393 qApp->processEvents();
1209 globalFlagBlockAgendaItemPaint = 0; 1394 globalFlagBlockAgendaItemPaint = 0;
1210 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1395 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1211 item->repaint( false ); 1396 item->repaint( false );
1212 } 1397 }
1213 1398
1214} 1399}
1215 1400
1216/* 1401/*
1217 Draw grid in the background of the agenda. 1402 Draw grid in the background of the agenda.
1218*/ 1403*/
1219void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch) 1404void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch)
1220{ 1405{
1221 1406
1222 1407
1223 if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask ) 1408 if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask )
1224 return; 1409 return;
1225 if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 ) 1410 if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 )
1226 return; 1411 return;
1227 int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight(); 1412 int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight();
1228 if ( ch < 1 ) 1413 if ( ch < 1 )
1229 ch = 1; 1414 ch = 1;
1230 if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) { 1415 if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) {
1231 mPaintPixmap.resize( contentsWidth()+42, ch ); 1416 mPaintPixmap.resize( contentsWidth()+42, ch );
1232 } 1417 }
1233 mCurPixWid = contentsWidth(); 1418 mCurPixWid = contentsWidth();
1234 mCurPixHei = ch; 1419 mCurPixHei = ch;
1235 if ( mHighlightPixmap.width() < mGridSpacingX-1 || mHighlightPixmap.height() < ch ) { 1420 if ( mHighlightPixmap.width() < mGridSpacingX-1 || mHighlightPixmap.height() < ch ) {
1236 mHighlightPixmap.resize( mGridSpacingX-1, ch ); 1421 mHighlightPixmap.resize( mGridSpacingX-1, ch );
1237 mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor ); 1422 mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor );
1238 } 1423 }
1239 mPixPainter.begin( &mPaintPixmap) ; 1424 mPixPainter.begin( &mPaintPixmap) ;
1240 //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() ); 1425 //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() );
1241 QPainter * p ; 1426 QPainter * p ;
1242 if (paint == 0) { 1427 if (paint == 0) {
1243 mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor); 1428 mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor);
1244 p = &mPixPainter; 1429 p = &mPixPainter;
1245 } 1430 }
1246 else 1431 else
1247 p = paint ; 1432 p = paint ;
1248 // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch); 1433 // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch);
1249 1434
1250 //--cx;++cw; 1435 //--cx;++cw;
1251 int lGridSpacingY = mGridSpacingY*2; 1436 int lGridSpacingY = mGridSpacingY*2;
1252 int selDay; 1437 int selDay;
1253 if ( !backgroundOnly ) 1438 if ( !backgroundOnly )
1254 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) 1439 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay)
1255 { 1440 {
1256 if ( mSelectedDates[selDay] == QDateTime::currentDateTime ().date() && KOPrefs::instance()->mHighlightCurrentDay) { 1441 if ( mSelectedDates[selDay] == QDateTime::currentDateTime ().date() && KOPrefs::instance()->mHighlightCurrentDay) {
1257 int x1 = cx; 1442 int x1 = cx;
1258 int y1 = 0; 1443 int y1 = 0;
1259 if (y1 < cy) y1 = cy; 1444 if (y1 < cy) y1 = cy;
1260 int x2 = cx+cw-1; 1445 int x2 = cx+cw-1;
1261 int y2 = contentsHeight(); 1446 int y2 = contentsHeight();
1262 if (y2 > cy+ch-1) y2=cy+ch-1; 1447 if (y2 > cy+ch-1) y2=cy+ch-1;
1263 if (x2 >= x1 && y2 >= y1) { 1448 if (x2 >= x1 && y2 >= y1) {
1264 int gxStart = selDay; 1449 int gxStart = selDay;
1265 int gxEnd = gxStart ; 1450 int gxEnd = gxStart ;
1266 int xStart = KOGlobals::self()->reverseLayout() ? 1451 int xStart = KOGlobals::self()->reverseLayout() ?
1267 (mColumns - 1 - gxStart)*mGridSpacingX : 1452 (mColumns - 1 - gxStart)*mGridSpacingX :
1268 gxStart*mGridSpacingX; 1453 gxStart*mGridSpacingX;
1269 if (xStart < x1) xStart = x1; 1454 if (xStart < x1) xStart = x1;
1270 int xEnd = KOGlobals::self()->reverseLayout() ? 1455 int xEnd = KOGlobals::self()->reverseLayout() ?
1271 (mColumns - gxStart)*mGridSpacingX-1 : 1456 (mColumns - gxStart)*mGridSpacingX-1 :
1272 (gxStart+1)*mGridSpacingX-1; 1457 (gxStart+1)*mGridSpacingX-1;
1273 if (xEnd > x2) xEnd = x2; 1458 if (xEnd > x2) xEnd = x2;
1274 if ( KOPrefs::instance()->mUseHighlightLightColor ) 1459 if ( KOPrefs::instance()->mUseHighlightLightColor )
1275 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1460 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1276 KOPrefs::instance()->mAgendaBgColor.light()); 1461 KOPrefs::instance()->mAgendaBgColor.light());
1277 else 1462 else
1278 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1463 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1279 KOPrefs::instance()->mAgendaBgColor.dark()); 1464 KOPrefs::instance()->mAgendaBgColor.dark());
1280 1465
1281 } 1466 }
1282 } 1467 }
1283 } 1468 }
1284 // Highlight working hours 1469 // Highlight working hours
1285 1470
1286 if ( !backgroundOnly ) 1471 if ( !backgroundOnly )
1287 if (mWorkingHoursEnable) { 1472 if (mWorkingHoursEnable) {
1288 int x1 = cx; 1473 int x1 = cx;
1289 int y1 = mWorkingHoursYTop; 1474 int y1 = mWorkingHoursYTop;
1290 if (y1 < cy) y1 = cy; 1475 if (y1 < cy) y1 = cy;
1291 int x2 = cx+cw-1; 1476 int x2 = cx+cw-1;
1292 // int x2 = mGridSpacingX * 5 - 1; 1477 // int x2 = mGridSpacingX * 5 - 1;
1293 // if (x2 > cx+cw-1) x2 = cx + cw - 1; 1478 // if (x2 > cx+cw-1) x2 = cx + cw - 1;
1294 int y2 = mWorkingHoursYBottom; 1479 int y2 = mWorkingHoursYBottom;
1295 if (y2 > cy+ch-1) y2=cy+ch-1; 1480 if (y2 > cy+ch-1) y2=cy+ch-1;
1296 1481
1297 if (x2 >= x1 && y2 >= y1) { 1482 if (x2 >= x1 && y2 >= y1) {
1298 // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX ); 1483 // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX );
1299 int gxStart = x1/mGridSpacingX; 1484 int gxStart = x1/mGridSpacingX;
1300 int gxEnd = x2/mGridSpacingX; 1485 int gxEnd = x2/mGridSpacingX;
1301 while(gxStart <= gxEnd) { 1486 while(gxStart <= gxEnd) {
1302 if (gxStart < int(mHolidayMask->count()) && 1487 if (gxStart < int(mHolidayMask->count()) &&
1303 !mHolidayMask->at(gxStart)) { 1488 !mHolidayMask->at(gxStart)) {
1304 int xStart = KOGlobals::self()->reverseLayout() ? 1489 int xStart = KOGlobals::self()->reverseLayout() ?
1305 (mColumns - 1 - gxStart)*mGridSpacingX : 1490 (mColumns - 1 - gxStart)*mGridSpacingX :
1306 gxStart*mGridSpacingX; 1491 gxStart*mGridSpacingX;
1307 if (xStart < x1) xStart = x1; 1492 if (xStart < x1) xStart = x1;
1308 int xEnd = KOGlobals::self()->reverseLayout() ? 1493 int xEnd = KOGlobals::self()->reverseLayout() ?
1309 (mColumns - gxStart)*mGridSpacingX-1 : 1494 (mColumns - gxStart)*mGridSpacingX-1 :
1310 (gxStart+1)*mGridSpacingX-1; 1495 (gxStart+1)*mGridSpacingX-1;
1311 if (xEnd > x2) xEnd = x2; 1496 if (xEnd > x2) xEnd = x2;
1312 if ( mSelectedDates[gxStart] == QDateTime::currentDateTime ().date()&& KOPrefs::instance()->mHighlightCurrentDay ) { 1497 if ( mSelectedDates[gxStart] == QDateTime::currentDateTime ().date()&& KOPrefs::instance()->mHighlightCurrentDay ) {
1313 if ( KOPrefs::instance()->mUseHighlightLightColor ) 1498 if ( KOPrefs::instance()->mUseHighlightLightColor )
1314 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1499 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1315 KOPrefs::instance()->mWorkingHoursColor.light()); 1500 KOPrefs::instance()->mWorkingHoursColor.light());
1316 else 1501 else
1317 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1502 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1318 KOPrefs::instance()->mWorkingHoursColor.dark()); 1503 KOPrefs::instance()->mWorkingHoursColor.dark());
1319 } else { 1504 } else {
1320 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1505 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1321 KOPrefs::instance()->mWorkingHoursColor); 1506 KOPrefs::instance()->mWorkingHoursColor);
1322 } 1507 }
1323 } 1508 }
1324 ++gxStart; 1509 ++gxStart;
1325 } 1510 }
1326 } 1511 }
1327 } 1512 }
1328 /* 1513 /*
1329 int selectionX = KOGlobals::self()->reverseLayout() ? 1514 int selectionX = KOGlobals::self()->reverseLayout() ?
1330 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1515 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1331 mSelectionCellX * mGridSpacingX; 1516 mSelectionCellX * mGridSpacingX;
1332 1517
1333 // Draw selection 1518 // Draw selection
1334 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1519 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1335 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1520 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1336 // TODO: paint only part within cx,cy,cw,ch 1521 // TODO: paint only part within cx,cy,cw,ch
1337 p->fillRect( selectionX, mSelectionYTop, mGridSpacingX, 1522 p->fillRect( selectionX, mSelectionYTop, mGridSpacingX,
1338 mSelectionHeight, KOPrefs::instance()->mHighlightColor ); 1523 mSelectionHeight, KOPrefs::instance()->mHighlightColor );
1339 } 1524 }
1340 */ 1525 */
1341 // Draw vertical lines of grid 1526 // Draw vertical lines of grid
1342 1527
1343 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX; 1528 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX;
1344 if ( mGridSpacingX > 0 ) { 1529 if ( mGridSpacingX > 0 ) {
1345 while (x < cx + cw) { 1530 while (x < cx + cw) {
1346 p->drawLine(x,cy,x,cy+ch); 1531 p->drawLine(x,cy,x,cy+ch);
1347 x+=mGridSpacingX; 1532 x+=mGridSpacingX;
1348 } 1533 }
1349 } 1534 }
1350 // Draw horizontal lines of grid 1535 // Draw horizontal lines of grid
1351 int y = ((int)(cy/lGridSpacingY))*lGridSpacingY; 1536 int y = ((int)(cy/lGridSpacingY))*lGridSpacingY;
1352 if ( lGridSpacingY > 0 ) { 1537 if ( lGridSpacingY > 0 ) {
1353 while (y < cy + ch) { 1538 while (y < cy + ch) {
1354 p->setPen( SolidLine ); 1539 p->setPen( SolidLine );
1355 p->drawLine(cx,y,cx+cw,y); 1540 p->drawLine(cx,y,cx+cw,y);
1356 y+=lGridSpacingY; 1541 y+=lGridSpacingY;
1357 p->setPen( DotLine ); 1542 p->setPen( DotLine );
1358 p->drawLine(cx,y,cx+cw,y); 1543 p->drawLine(cx,y,cx+cw,y);
1359 y+=lGridSpacingY; 1544 y+=lGridSpacingY;
1360 } 1545 }
1361 p->setPen( SolidLine ); 1546 p->setPen( SolidLine );
1362 } 1547 }
1363 mPixPainter.end() ; 1548 mPixPainter.end() ;
1364} 1549}
1365 1550
1366/* 1551/*
1367 Convert srcollview contents coordinates to agenda grid coordinates. 1552 Convert srcollview contents coordinates to agenda grid coordinates.
1368*/ 1553*/
1369void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy) 1554void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy)
1370{ 1555{
1371 gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX : 1556 gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX :
1372 x/mGridSpacingX; 1557 x/mGridSpacingX;
1373 gy = y/mGridSpacingY; 1558 gy = y/mGridSpacingY;
1374} 1559}
1375 1560
1376/* 1561/*
1377 Convert agenda grid coordinates to scrollview contents coordinates. 1562 Convert agenda grid coordinates to scrollview contents coordinates.
1378*/ 1563*/
1379void KOAgenda::gridToContents (int gx, int gy, int& x, int& y) 1564void KOAgenda::gridToContents (int gx, int gy, int& x, int& y)
1380{ 1565{
1381 x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX: 1566 x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX:
1382 gx*mGridSpacingX; 1567 gx*mGridSpacingX;
1383 y = gy*mGridSpacingY; 1568 y = gy*mGridSpacingY;
1384} 1569}
1385 1570
1386 1571
1387/* 1572/*
1388 Return Y coordinate corresponding to time. Coordinates are rounded to fit into 1573 Return Y coordinate corresponding to time. Coordinates are rounded to fit into
1389 the grid. 1574 the grid.
1390*/ 1575*/
1391int KOAgenda::timeToY(const QTime &time) 1576int KOAgenda::timeToY(const QTime &time)
1392{ 1577{
1393 int minutesPerCell = 24 * 60 / mRows; 1578 int minutesPerCell = 24 * 60 / mRows;
1394 int timeMinutes = time.hour() * 60 + time.minute(); 1579 int timeMinutes = time.hour() * 60 + time.minute();
1395 int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell; 1580 int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell;
1396 return Y; 1581 return Y;
1397} 1582}
1398 1583
1399 1584
1400/* 1585/*
1401 Return time corresponding to cell y coordinate. Coordinates are rounded to 1586 Return time corresponding to cell y coordinate. Coordinates are rounded to
1402 fit into the grid. 1587 fit into the grid.
1403*/ 1588*/
1404QTime KOAgenda::gyToTime(int gy) 1589QTime KOAgenda::gyToTime(int gy)
1405{ 1590{
1406 1591
1407 int secondsPerCell = 24 * 60 * 60/ mRows; 1592 int secondsPerCell = 24 * 60 * 60/ mRows;
1408 1593
1409 int timeSeconds = secondsPerCell * gy; 1594 int timeSeconds = secondsPerCell * gy;
1410 1595
1411 QTime time( 0, 0, 0 ); 1596 QTime time( 0, 0, 0 );
1412 if ( timeSeconds < 24 * 60 * 60 ) { 1597 if ( timeSeconds < 24 * 60 * 60 ) {
1413 time = time.addSecs(timeSeconds); 1598 time = time.addSecs(timeSeconds);
1414 } else { 1599 } else {
1415 time.setHMS( 23, 59, 59 ); 1600 time.setHMS( 23, 59, 59 );
1416 } 1601 }
1417 1602
1418 return time; 1603 return time;
1419} 1604}
1420 1605
1421void KOAgenda::setStartHour(int startHour) 1606void KOAgenda::setStartHour(int startHour)
1422{ 1607{
1423 int startCell = startHour * mRows / 24; 1608 int startCell = startHour * mRows / 24;
1424 setContentsPos(0,startCell * gridSpacingY()); 1609 setContentsPos(0,startCell * gridSpacingY());
1425} 1610}
1426void KOAgenda::hideUnused() 1611void KOAgenda::hideUnused()
1427{ 1612{
1428 // experimental only 1613 // experimental only
1429 // return; 1614 // return;
1430 KOAgendaItem *item; 1615 KOAgendaItem *item;
1431 for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) { 1616 for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) {
1432 item->hide(); 1617 item->hide();
1433 } 1618 }
1434} 1619}
1435 1620
1436 1621
1437KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view) 1622KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view)
1438{ 1623{
1439 1624
1440 KOAgendaItem *fi; 1625 KOAgendaItem *fi;
1441 for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) { 1626 for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) {
1442 if ( fi->incidence() == event ) { 1627 if ( fi->incidence() == event ) {
1443 mUnusedItems.remove(); 1628 mUnusedItems.remove();
1444 fi->init( event, qd ); 1629 fi->init( event, qd );
1445 return fi; 1630 return fi;
1446 } 1631 }
1447 } 1632 }
1448 fi=mUnusedItems.first(); 1633 fi=mUnusedItems.first();
1449 if ( fi ) { 1634 if ( fi ) {
1450 mUnusedItems.remove(); 1635 mUnusedItems.remove();
1451 fi->init( event, qd ); 1636 fi->init( event, qd );
1452 return fi; 1637 return fi;
1453 } 1638 }
1454 // qDebug("new KOAgendaItem "); 1639 // qDebug("new KOAgendaItem ");
1455 1640
1456 KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode ); 1641 KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode );
1457 agendaItem->installEventFilter(this); 1642 agendaItem->installEventFilter(this);
1458 addChild(agendaItem,0,0); 1643 addChild(agendaItem,0,0);
1459 return agendaItem; 1644 return agendaItem;
1460} 1645}
1461KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo ) 1646KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo )
1462{ 1647{
1463 KOAgendaItem *item; 1648 KOAgendaItem *item;
1464 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1649 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1465 if ( item->incidence() == todo ) { 1650 if ( item->incidence() == todo ) {
1466 mItems.remove(); 1651 mItems.remove();
1467 return item; 1652 return item;
1468 } 1653 }
1469 } 1654 }
1470 return 0; 1655 return 0;
1471} 1656}
1472 1657
1473 1658
1474void KOAgenda::updateTodo( Todo * todo, int days, bool remove) 1659void KOAgenda::updateTodo( Todo * todo, int days, bool remove)
1475{ 1660{
1476 // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )|| 1661 // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )||
1477 KOAgendaItem *item; 1662 KOAgendaItem *item;
1478 item = getItemForTodo ( todo ); 1663 item = getItemForTodo ( todo );
1479 //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove); 1664 //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove);
1480 if ( item ) { 1665 if ( item ) {
1481 blockSignals( true ); 1666 blockSignals( true );
1482 //qDebug("item found "); 1667 //qDebug("item found ");
1483 item->hide(); 1668 item->hide();
1484 item->setCellX(-2, -1 ); 1669 item->setCellX(-2, -1 );
1485 item->select(false); 1670 item->select(false);
1486 mUnusedItems.append( item ); 1671 mUnusedItems.append( item );
1487 mItems.remove( item ); 1672 mItems.remove( item );
1488 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); 1673 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems();
1489 KOAgendaItem *itemit; 1674 KOAgendaItem *itemit;
1490 //globalFlagBlockAgendaItemPaint = 1; 1675 //globalFlagBlockAgendaItemPaint = 1;
1491 for ( itemit=oldconflictItems.first(); itemit != 0; 1676 for ( itemit=oldconflictItems.first(); itemit != 0;
1492 itemit=oldconflictItems.next() ) { 1677 itemit=oldconflictItems.next() ) {
1493 if ( itemit != item ) 1678 if ( itemit != item )
1494 placeSubCells(itemit); 1679 placeSubCells(itemit);
1495 } 1680 }
1496 qApp->processEvents(); 1681 qApp->processEvents();
1497 //globalFlagBlockAgendaItemPaint = 0; 1682 //globalFlagBlockAgendaItemPaint = 0;
1498 for ( itemit=oldconflictItems.first(); itemit != 0; 1683 for ( itemit=oldconflictItems.first(); itemit != 0;
1499 itemit=oldconflictItems.next() ) { 1684 itemit=oldconflictItems.next() ) {
1500 globalFlagBlockAgendaItemUpdate = 0; 1685 globalFlagBlockAgendaItemUpdate = 0;
1501 if ( itemit != item ) 1686 if ( itemit != item )
1502 itemit->repaintMe(); 1687 itemit->repaintMe();
1503 globalFlagBlockAgendaItemUpdate = 1; 1688 globalFlagBlockAgendaItemUpdate = 1;
1504 itemit->repaint(); 1689 itemit->repaint();
1505 } 1690 }
1506 blockSignals( false ); 1691 blockSignals( false );
1507 } 1692 }
1508 if ( remove ) { 1693 if ( remove ) {
1509 //qDebug("remove****************************************** "); 1694 //qDebug("remove****************************************** ");
1510 return; 1695 return;
1511 } 1696 }
1512 //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ "); 1697 //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ ");
1513 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < QDate::currentDate())&& ( KOPrefs::instance()->mShowTodoInAgenda ); 1698 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < QDate::currentDate())&& ( KOPrefs::instance()->mShowTodoInAgenda );
1514 QDate currentDate; 1699 QDate currentDate;
1515 QDateTime dt; 1700 QDateTime dt;
1516 if ( todo->hasCompletedDate() ) 1701 if ( todo->hasCompletedDate() )
1517 dt = todo->completed(); 1702 dt = todo->completed();
1518 else 1703 else
1519 dt = todo->dtDue(); 1704 dt = todo->dtDue();
1520 if ( overdue ) { 1705 if ( overdue ) {
1521 currentDate = QDate::currentDate(); 1706 currentDate = QDate::currentDate();
1522 days += todo->dtDue().date().daysTo( currentDate ); 1707 days += todo->dtDue().date().daysTo( currentDate );
1523 } 1708 }
1524 else 1709 else
1525 currentDate = dt.date(); 1710 currentDate = dt.date();
1526 1711
1527 if (( todo->doesFloat() || overdue) && !todo->hasCompletedDate() ) { 1712 if (( todo->doesFloat() || overdue) && !todo->hasCompletedDate() ) {
1528 if ( ! mAllDayMode ) return; 1713 if ( ! mAllDayMode ) return;
1529 // aldayagenda 1714 // aldayagenda
1530 globalFlagBlockAgendaItemPaint = 1; 1715 globalFlagBlockAgendaItemPaint = 1;
1531 item = insertAllDayItem(todo, currentDate,days, days); 1716 item = insertAllDayItem(todo, currentDate,days, days);
1532 item->show(); 1717 item->show();
1533 1718
1534 } 1719 }
1535 else { 1720 else {
1536 if ( mAllDayMode ) return; 1721 if ( mAllDayMode ) return;
1537 // mAgenda 1722 // mAgenda
1538 globalFlagBlockAgendaItemPaint = 1; 1723 globalFlagBlockAgendaItemPaint = 1;
1539 int endY = timeToY(dt.time()) - 1; 1724 int endY = timeToY(dt.time()) - 1;
1540 int hi = 12/KOPrefs::instance()->mHourSize; 1725 int hi = 12/KOPrefs::instance()->mHourSize;
1541 int startY = endY - 1-hi; 1726 int startY = endY - 1-hi;
1542 item = insertItem(todo,currentDate,days,startY,endY); 1727 item = insertItem(todo,currentDate,days,startY,endY);
1543 item->show(); 1728 item->show();
1544 } 1729 }
1545 qApp->processEvents(); 1730 qApp->processEvents();
1546 globalFlagBlockAgendaItemPaint = 0; 1731 globalFlagBlockAgendaItemPaint = 0;
1547 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); 1732 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems();
1548 KOAgendaItem *itemit; 1733 KOAgendaItem *itemit;
1549 for ( itemit=oldconflictItems.first(); itemit != 0; 1734 for ( itemit=oldconflictItems.first(); itemit != 0;
1550 itemit=oldconflictItems.next() ) { 1735 itemit=oldconflictItems.next() ) {
1551 globalFlagBlockAgendaItemUpdate = 0; 1736 globalFlagBlockAgendaItemUpdate = 0;
1552 itemit->repaintMe(); 1737 itemit->repaintMe();
1553 globalFlagBlockAgendaItemUpdate = 1; 1738 globalFlagBlockAgendaItemUpdate = 1;
1554 itemit->repaint(); 1739 itemit->repaint();
1555 } 1740 }
1556 globalFlagBlockAgendaItemUpdate = 0; 1741 globalFlagBlockAgendaItemUpdate = 0;
1557 item->repaintMe(); 1742 item->repaintMe();
1558 globalFlagBlockAgendaItemUpdate = 1; 1743 globalFlagBlockAgendaItemUpdate = 1;
1559 item->repaint(); 1744 item->repaint();
1560} 1745}
1561/* 1746/*
1562 Insert KOAgendaItem into agenda. 1747 Insert KOAgendaItem into agenda.
1563*/ 1748*/
1564KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom) 1749KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom)
1565{ 1750{
1566 //kdDebug() << "KOAgenda::insertItem:" << event->summary() << "-" << qd.toString() << " ;top, bottom:" << YTop << "," << YBottom << endl; 1751 //kdDebug() << "KOAgenda::insertItem:" << event->summary() << "-" << qd.toString() << " ;top, bottom:" << YTop << "," << YBottom << endl;
1567 1752
1568 if (mAllDayMode) { 1753 if (mAllDayMode) {
1569 kdDebug() << "KOAgenda: calling insertItem in all-day mode is illegal." << endl; 1754 kdDebug() << "KOAgenda: calling insertItem in all-day mode is illegal." << endl;
1570 return 0; 1755 return 0;
1571 } 1756 }
1572 1757
1573 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); 1758 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport());
1574 //agendaItem->setFrameStyle(WinPanel|Raised); 1759 //agendaItem->setFrameStyle(WinPanel|Raised);
1575 1760
1576 int YSize = YBottom - YTop + 1; 1761 int YSize = YBottom - YTop + 1;
1577 if (YSize < 0) { 1762 if (YSize < 0) {
1578 kdDebug() << "KOAgenda::insertItem(): Text: " << agendaItem->text() << " YSize<0" << endl; 1763 kdDebug() << "KOAgenda::insertItem(): Text: " << agendaItem->text() << " YSize<0" << endl;
1579 YSize = 1; 1764 YSize = 1;
1580 } 1765 }
1581 int iheight = mGridSpacingY * YSize; 1766 int iheight = mGridSpacingY * YSize;
1582 1767
1583 agendaItem->resize(mGridSpacingX,iheight ); 1768 agendaItem->resize(mGridSpacingX,iheight );
1584 agendaItem->setCellXY(X,YTop,YBottom); 1769 agendaItem->setCellXY(X,YTop,YBottom);
1585 agendaItem->setCellXWidth(X); 1770 agendaItem->setCellXWidth(X);
1586 1771
1587 //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY); 1772 //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY);
1588 mItems.append(agendaItem); 1773 mItems.append(agendaItem);
1589 1774
1590 placeSubCells(agendaItem); 1775 placeSubCells(agendaItem);
1591 1776
1592 //agendaItem->show(); 1777 //agendaItem->show();
1593 1778
1594 marcus_bains(); 1779 marcus_bains();
1595 1780
1596 return agendaItem; 1781 return agendaItem;
1597} 1782}
1598 1783
1599 1784
1600/* 1785/*
1601 Insert all-day KOAgendaItem into agenda. 1786 Insert all-day KOAgendaItem into agenda.
1602*/ 1787*/
1603KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd) 1788KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd)
1604{ 1789{
1605 if (!mAllDayMode) { 1790 if (!mAllDayMode) {
1606 return 0; 1791 return 0;
1607 } 1792 }
1608 1793
1609 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); 1794 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport());
1610 1795
1611 agendaItem->setCellXY(XBegin,0,0); 1796 agendaItem->setCellXY(XBegin,0,0);
1612 agendaItem->setCellXWidth(XEnd); 1797 agendaItem->setCellXWidth(XEnd);
1613 agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY); 1798 agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY);
1614 1799
1615 //addChild(agendaItem,XBegin*mGridSpacingX,0); 1800 //addChild(agendaItem,XBegin*mGridSpacingX,0);
1616 mItems.append(agendaItem); 1801 mItems.append(agendaItem);
1617 1802
1618 placeSubCells(agendaItem); 1803 placeSubCells(agendaItem);
1619 1804
1620 //agendaItem->show(); 1805 //agendaItem->show();
1621 1806
1622 return agendaItem; 1807 return agendaItem;
1623} 1808}
1624 1809
1625 1810
1626void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, 1811void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd,
1627 int YTop,int YBottom) 1812 int YTop,int YBottom)
1628{ 1813{
1629 if (mAllDayMode) { 1814 if (mAllDayMode) {
1630 ; 1815 ;
1631 return; 1816 return;
1632 } 1817 }
1633 1818
1634 int cellX,cellYTop,cellYBottom; 1819 int cellX,cellYTop,cellYBottom;
1635 QString newtext; 1820 QString newtext;
1636 int width = XEnd - XBegin + 1; 1821 int width = XEnd - XBegin + 1;
1637 int count = 0; 1822 int count = 0;
1638 KOAgendaItem *current = 0; 1823 KOAgendaItem *current = 0;
1639 QPtrList<KOAgendaItem> multiItems; 1824 QPtrList<KOAgendaItem> multiItems;
1640 for (cellX = XBegin;cellX <= XEnd;++cellX) { 1825 for (cellX = XBegin;cellX <= XEnd;++cellX) {
1641 if (cellX == XBegin) cellYTop = YTop; 1826 if (cellX == XBegin) cellYTop = YTop;
1642 else cellYTop = 0; 1827 else cellYTop = 0;
1643 if (cellX == XEnd) cellYBottom = YBottom; 1828 if (cellX == XEnd) cellYBottom = YBottom;
1644 else cellYBottom = rows() - 1; 1829 else cellYBottom = rows() - 1;
1645 newtext = QString("(%1/%2): ").arg(++count).arg(width); 1830 newtext = QString("(%1/%2): ").arg(++count).arg(width);
1646 newtext.append(event->summary()); 1831 newtext.append(event->summary());
1647 current = insertItem(event,qd,cellX,cellYTop,cellYBottom); 1832 current = insertItem(event,qd,cellX,cellYTop,cellYBottom);
1648 current->setText(newtext); 1833 current->setText(newtext);
1649 multiItems.append(current); 1834 multiItems.append(current);
1650 } 1835 }
1651 1836
1652 KOAgendaItem *next = 0; 1837 KOAgendaItem *next = 0;
1653 KOAgendaItem *last = multiItems.last(); 1838 KOAgendaItem *last = multiItems.last();
1654 KOAgendaItem *first = multiItems.first(); 1839 KOAgendaItem *first = multiItems.first();
1655 KOAgendaItem *setFirst,*setLast; 1840 KOAgendaItem *setFirst,*setLast;
1656 current = first; 1841 current = first;
1657 while (current) { 1842 while (current) {
1658 next = multiItems.next(); 1843 next = multiItems.next();
1659 if (current == first) setFirst = 0; 1844 if (current == first) setFirst = 0;
1660 else setFirst = first; 1845 else setFirst = first;
1661 if (current == last) setLast = 0; 1846 if (current == last) setLast = 0;
1662 else setLast = last; 1847 else setLast = last;
1663 1848
1664 current->setMultiItem(setFirst,next,setLast); 1849 current->setMultiItem(setFirst,next,setLast);
1665 current = next; 1850 current = next;
1666 } 1851 }
1667 1852
1668 marcus_bains(); 1853 marcus_bains();
1669} 1854}
1670 1855
1671 1856
1672//QSizePolicy KOAgenda::sizePolicy() const 1857//QSizePolicy KOAgenda::sizePolicy() const
1673//{ 1858//{
1674 // Thought this would make the all-day event agenda minimum size and the 1859 // Thought this would make the all-day event agenda minimum size and the
1675 // normal agenda take the remaining space. But it doesn´t work. The QSplitter 1860 // normal agenda take the remaining space. But it doesn´t work. The QSplitter
1676 // don´t seem to think that an Expanding widget needs more space than a 1861 // don´t seem to think that an Expanding widget needs more space than a
1677 // Preferred one. 1862 // Preferred one.
1678 // But it doesn´t hurt, so it stays. 1863 // But it doesn´t hurt, so it stays.
1679// if (mAllDayMode) { 1864// if (mAllDayMode) {
1680// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); 1865// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
1681// } else { 1866// } else {
1682// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); 1867// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
1683// } 1868// }
1684//} 1869//}
1685void KOAgenda::finishResize ( ) 1870void KOAgenda::finishResize ( )
1686{ 1871{
1687 //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) "); 1872 //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) ");
1688 if ( globalFlagBlockAgenda == 0 ) { 1873 if ( globalFlagBlockAgenda == 0 ) {
1689 finishUpdate(); 1874 finishUpdate();
1690 //qDebug("finishUpdate() called "); 1875 //qDebug("finishUpdate() called ");
1691 } 1876 }
1692} 1877}
1693/* 1878/*
1694 Overridden from QScrollView to provide proper resizing of KOAgendaItems. 1879 Overridden from QScrollView to provide proper resizing of KOAgendaItems.
1695*/ 1880*/
1696void KOAgenda::resizeEvent ( QResizeEvent *ev ) 1881void KOAgenda::resizeEvent ( QResizeEvent *ev )
1697{ 1882{
1698 1883
1699 mResizeTimer.start( 150 , true ); 1884 mResizeTimer.start( 150 , true );
1700 computeSizes(); 1885 computeSizes();
1701 return; 1886 return;
1702 1887
1703} 1888}
1704void KOAgenda::computeSizes() 1889void KOAgenda::computeSizes()
1705{ 1890{
1706 if ( globalFlagBlockStartup ) 1891 if ( globalFlagBlockStartup )
1707 return; 1892 return;
1708 1893
1709 if (mAllDayMode) { 1894 if (mAllDayMode) {
1710 mGridSpacingX = (width()-3) / mColumns; 1895 mGridSpacingX = (width()-3) / mColumns;
1711 mGridSpacingY = height() - 2 * frameWidth() - 1; 1896 mGridSpacingY = height() - 2 * frameWidth() - 1;
1712 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1); 1897 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1);
1713// mGridSpacingY = height(); 1898// mGridSpacingY = height();
1714// resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1899// resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1715 1900
1716 KOAgendaItem *item; 1901 KOAgendaItem *item;
1717 int subCellWidth; 1902 int subCellWidth;
1718 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1903 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1719 subCellWidth = mGridSpacingY / item->subCells(); 1904 subCellWidth = mGridSpacingY / item->subCells();
1720 item->resize(mGridSpacingX * item->cellWidth(),subCellWidth); 1905 item->resize(mGridSpacingX * item->cellWidth(),subCellWidth);
1721 moveChild(item,KOGlobals::self()->reverseLayout() ? 1906 moveChild(item,KOGlobals::self()->reverseLayout() ?
1722 (mColumns - 1 - item->cellX()) * mGridSpacingX : 1907 (mColumns - 1 - item->cellX()) * mGridSpacingX :
1723 item->cellX() * mGridSpacingX, 1908 item->cellX() * mGridSpacingX,
1724 item->subCell() * subCellWidth); 1909 item->subCell() * subCellWidth);
1725 } 1910 }
1726 KOPrefs::instance()->mAllDaySize = mGridSpacingY; 1911 KOPrefs::instance()->mAllDaySize = mGridSpacingY;
1727 } else { 1912 } else {
1728 mGridSpacingX = (width() - verticalScrollBar()->width()-3)/mColumns; 1913 mGridSpacingX = (width() - verticalScrollBar()->width()-3)/mColumns;
1729 if (height() > mGridSpacingY * mRows + 1 ) { 1914 if (height() > mGridSpacingY * mRows + 1 ) {
1730 KOPrefs::instance()->mHourSize = ((height())/mRows)+1; 1915 KOPrefs::instance()->mHourSize = ((height())/mRows)+1;
1731 mGridSpacingY = KOPrefs::instance()->mHourSize ; 1916 mGridSpacingY = KOPrefs::instance()->mHourSize ;
1732 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1917 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1733 emit resizedSignal(); 1918 emit resizedSignal();
1734 } else 1919 } else
1735 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1920 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1736 KOAgendaItem *item; 1921 KOAgendaItem *item;
1737 int subCellWidth; 1922 int subCellWidth;
1738 1923
1739 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1924 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1740 subCellWidth = mGridSpacingX / item->subCells(); 1925 subCellWidth = mGridSpacingX / item->subCells();
1741 item->resize(subCellWidth,item->height()); 1926 item->resize(subCellWidth,item->height());
1742 moveChild(item,(KOGlobals::self()->reverseLayout() ? 1927 moveChild(item,(KOGlobals::self()->reverseLayout() ?
1743 (mColumns - 1 - item->cellX()) * mGridSpacingX : 1928 (mColumns - 1 - item->cellX()) * mGridSpacingX :
1744 item->cellX() * mGridSpacingX) + 1929 item->cellX() * mGridSpacingX) +
1745 item->subCell() * subCellWidth,childY(item)); 1930 item->subCell() * subCellWidth,childY(item));
1746 } 1931 }
1747 } 1932 }
1748 int cw = contentsWidth(); 1933 int cw = contentsWidth();
1749 int ch = contentsHeight(); 1934 int ch = contentsHeight();
1750 if ( mAllDayMode ) { 1935 if ( mAllDayMode ) {
1751 QPixmap* paintPixAll = KOAgendaItem::paintPixAllday(); 1936 QPixmap* paintPixAll = KOAgendaItem::paintPixAllday();
1752 if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 ) 1937 if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 )
1753 paintPixAll->resize( cw, ch ); 1938 paintPixAll->resize( cw, ch );
1754 } else { 1939 } else {
1755 QPixmap* paintPix = KOAgendaItem::paintPix(); 1940 QPixmap* paintPix = KOAgendaItem::paintPix();
1756 if ( paintPix->width() < cw || paintPix->height() < ch ) 1941 if ( paintPix->width() < cw || paintPix->height() < ch )
1757 KOAgendaItem::resizePixmap( cw , ch ); 1942 KOAgendaItem::resizePixmap( cw , ch );
1758 } 1943 }
1759 1944
1760 checkScrollBoundaries(); 1945 checkScrollBoundaries();
1761 marcus_bains(); 1946 marcus_bains();
1762 drawContentsToPainter(); 1947 drawContentsToPainter();
1763 viewport()->repaint(false); 1948 viewport()->repaint(false);
1764} 1949}
1765 1950
1766void KOAgenda::scrollUp() 1951void KOAgenda::scrollUp()
1767{ 1952{
1768 scrollBy(0,-mScrollOffset); 1953 scrollBy(0,-mScrollOffset);
1769} 1954}
1770 1955
1771 1956
1772void KOAgenda::scrollDown() 1957void KOAgenda::scrollDown()
1773{ 1958{
1774 scrollBy(0,mScrollOffset); 1959 scrollBy(0,mScrollOffset);
1775} 1960}
1776 1961
1777void KOAgenda::popupAlarm() 1962void KOAgenda::popupAlarm()
1778{ 1963{
1779 if (!mClickedItem) { 1964 if (!mClickedItem) {
1780 qDebug("KOAgenda::popupAlarm() called without having a clicked item "); 1965 qDebug("KOAgenda::popupAlarm() called without having a clicked item ");
1781 return; 1966 return;
1782 } 1967 }
1783// TODO: deal correctly with multiple alarms 1968// TODO: deal correctly with multiple alarms
1784 Alarm* alarm; 1969 Alarm* alarm;
1785 QPtrList<Alarm> list(mClickedItem->incidence()->alarms()); 1970 QPtrList<Alarm> list(mClickedItem->incidence()->alarms());
1786 for(alarm=list.first();alarm;alarm=list.next()) { 1971 for(alarm=list.first();alarm;alarm=list.next()) {
1787 alarm->toggleAlarm(); 1972 alarm->toggleAlarm();
1788 } 1973 }
1789 emit itemModified( mClickedItem , KOGlobals::EVENTEDITED ); 1974 emit itemModified( mClickedItem , KOGlobals::EVENTEDITED );
1790 mClickedItem->paintMe( true ); 1975 mClickedItem->paintMe( true );
1791 mClickedItem->repaint( false ); 1976 mClickedItem->repaint( false );
1792} 1977}
1793 1978
1794/* 1979/*
1795 Calculates the minimum width 1980 Calculates the minimum width
1796*/ 1981*/
1797int KOAgenda::minimumWidth() const 1982int KOAgenda::minimumWidth() const
1798{ 1983{
1799 // TODO:: develop a way to dynamically determine the minimum width 1984 // TODO:: develop a way to dynamically determine the minimum width
1800 int min = 100; 1985 int min = 100;
1801 1986
1802 return min; 1987 return min;
1803} 1988}
1804 1989
1805void KOAgenda::updateConfig() 1990void KOAgenda::updateConfig()
1806{ 1991{
1807 if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor) 1992 if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor)
1808 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor); 1993 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor);
1809 if ( mAllDayMode ) { 1994 if ( mAllDayMode ) {
1810 mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize; 1995 mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize;
1811 //mGridSpacingY = KOPrefs::instance()->mAllDaySize; 1996 //mGridSpacingY = KOPrefs::instance()->mAllDaySize;
1812 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 ); 1997 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 );
1813 // setMaximumHeight( mGridSpacingY+1 ); 1998 // setMaximumHeight( mGridSpacingY+1 );
1814 viewport()->repaint( false ); 1999 viewport()->repaint( false );
1815 //setFixedHeight( mGridSpacingY+1 ); 2000 //setFixedHeight( mGridSpacingY+1 );
1816 //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize); 2001 //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize);
1817 } 2002 }
1818 else { 2003 else {
1819 mGridSpacingY = KOPrefs::instance()->mHourSize; 2004 mGridSpacingY = KOPrefs::instance()->mHourSize;
1820 calculateWorkingHours(); 2005 calculateWorkingHours();
1821 marcus_bains(); 2006 marcus_bains();
1822 } 2007 }
1823} 2008}
1824 2009
1825void KOAgenda::checkScrollBoundaries() 2010void KOAgenda::checkScrollBoundaries()
1826{ 2011{
1827 // Invalidate old values to force update 2012 // Invalidate old values to force update
1828 mOldLowerScrollValue = -1; 2013 mOldLowerScrollValue = -1;
1829 mOldUpperScrollValue = -1; 2014 mOldUpperScrollValue = -1;
1830 2015
1831 checkScrollBoundaries(verticalScrollBar()->value()); 2016 checkScrollBoundaries(verticalScrollBar()->value());
1832} 2017}
1833 2018
1834void KOAgenda::checkScrollBoundaries(int v) 2019void KOAgenda::checkScrollBoundaries(int v)
1835{ 2020{
1836 if ( mGridSpacingY == 0 ) 2021 if ( mGridSpacingY == 0 )
1837 return; 2022 return;
1838 int yMin = v/mGridSpacingY; 2023 int yMin = v/mGridSpacingY;
1839 int yMax = (v+visibleHeight())/mGridSpacingY; 2024 int yMax = (v+visibleHeight())/mGridSpacingY;
1840 2025
1841// kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl; 2026// kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl;
1842 2027
1843 if (yMin != mOldLowerScrollValue) { 2028 if (yMin != mOldLowerScrollValue) {
1844 mOldLowerScrollValue = yMin; 2029 mOldLowerScrollValue = yMin;
1845 emit lowerYChanged(yMin); 2030 emit lowerYChanged(yMin);
1846 } 2031 }
1847 if (yMax != mOldUpperScrollValue) { 2032 if (yMax != mOldUpperScrollValue) {
1848 mOldUpperScrollValue = yMax; 2033 mOldUpperScrollValue = yMax;
1849 emit upperYChanged(yMax); 2034 emit upperYChanged(yMax);
1850 } 2035 }
1851} 2036}
1852 2037
1853void KOAgenda::deselectItem() 2038void KOAgenda::deselectItem()
1854{ 2039{
1855 if (mSelectedItem.isNull()) return; 2040 if (mSelectedItem.isNull()) return;
1856 mSelectedItem->select(false); 2041 mSelectedItem->select(false);
1857 mSelectedItem = 0; 2042 mSelectedItem = 0;
1858} 2043}
1859 2044
1860void KOAgenda::selectItem(KOAgendaItem *item) 2045void KOAgenda::selectItem(KOAgendaItem *item)
1861{ 2046{
1862 if ((KOAgendaItem *)mSelectedItem == item) return; 2047 if ((KOAgendaItem *)mSelectedItem == item) return;
1863 deselectItem(); 2048 deselectItem();
1864 if (item == 0) { 2049 if (item == 0) {
1865 emit incidenceSelected( 0 ); 2050 emit incidenceSelected( 0 );
1866 return; 2051 return;
1867 } 2052 }
1868 mSelectedItem = item; 2053 mSelectedItem = item;
1869 mSelectedItem->select(); 2054 mSelectedItem->select();
1870 emit incidenceSelected( mSelectedItem->incidence() ); 2055 emit incidenceSelected( mSelectedItem->incidence() );
1871} 2056}
1872 2057
1873// This function seems never be called. 2058// This function seems never be called.
1874void KOAgenda::keyPressEvent( QKeyEvent *kev ) 2059void KOAgenda::keyPressEvent( QKeyEvent *kev )
1875{ 2060{
1876 switch(kev->key()) { 2061 switch(kev->key()) {
1877 case Key_PageDown: 2062 case Key_PageDown:
1878 verticalScrollBar()->addPage(); 2063 verticalScrollBar()->addPage();
1879 break; 2064 break;
1880 case Key_PageUp: 2065 case Key_PageUp:
1881 verticalScrollBar()->subtractPage(); 2066 verticalScrollBar()->subtractPage();
1882 break; 2067 break;
1883 case Key_Down: 2068 case Key_Down:
1884 verticalScrollBar()->addLine(); 2069 verticalScrollBar()->addLine();
1885 break; 2070 break;
1886 case Key_Up: 2071 case Key_Up:
1887 verticalScrollBar()->subtractLine(); 2072 verticalScrollBar()->subtractLine();
1888 break; 2073 break;
1889 default: 2074 default:
1890 ; 2075 ;
1891 } 2076 }
1892} 2077}
1893 2078
1894void KOAgenda::calculateWorkingHours() 2079void KOAgenda::calculateWorkingHours()
1895{ 2080{
1896// mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours; 2081// mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours;
1897 mWorkingHoursEnable = !mAllDayMode; 2082 mWorkingHoursEnable = !mAllDayMode;
1898 2083
1899 mWorkingHoursYTop = mGridSpacingY * 2084 mWorkingHoursYTop = mGridSpacingY *
1900 KOPrefs::instance()->mWorkingHoursStart * 4; 2085 KOPrefs::instance()->mWorkingHoursStart * 4;
1901 mWorkingHoursYBottom = mGridSpacingY * 2086 mWorkingHoursYBottom = mGridSpacingY *
1902 KOPrefs::instance()->mWorkingHoursEnd * 4 - 1; 2087 KOPrefs::instance()->mWorkingHoursEnd * 4 - 1;
1903} 2088}
1904 2089
1905 2090
1906DateList KOAgenda::dateList() const 2091DateList KOAgenda::dateList() const
1907{ 2092{
1908 return mSelectedDates; 2093 return mSelectedDates;
1909} 2094}
1910 2095
1911void KOAgenda::setDateList(const DateList &selectedDates) 2096void KOAgenda::setDateList(const DateList &selectedDates)
1912{ 2097{
1913 mSelectedDates = selectedDates; 2098 mSelectedDates = selectedDates;
1914 marcus_bains(); 2099 marcus_bains();
1915} 2100}
1916 2101
1917void KOAgenda::setHolidayMask(QMemArray<bool> *mask) 2102void KOAgenda::setHolidayMask(QMemArray<bool> *mask)
1918{ 2103{
1919 mHolidayMask = mask; 2104 mHolidayMask = mask;
1920 2105
1921/* 2106/*
1922 kdDebug() << "HolidayMask: "; 2107 kdDebug() << "HolidayMask: ";
1923 for(uint i=0;i<mask->count();++i) { 2108 for(uint i=0;i<mask->count();++i) {
1924 kdDebug() << (mask->at(i) ? "*" : "o"); 2109 kdDebug() << (mask->at(i) ? "*" : "o");
1925 } 2110 }
1926 kdDebug() << endl; 2111 kdDebug() << endl;
1927*/ 2112*/
1928} 2113}
1929 2114
1930void KOAgenda::contentsMousePressEvent ( QMouseEvent *event ) 2115void KOAgenda::contentsMousePressEvent ( QMouseEvent *event )
1931{ 2116{
1932 2117
1933 QScrollView::contentsMousePressEvent(event); 2118 QScrollView::contentsMousePressEvent(event);
1934} 2119}
1935 2120
1936void KOAgenda::storePosition() 2121void KOAgenda::storePosition()
1937{ 2122{
1938 //mContentPosition 2123 //mContentPosition
1939 int max = mGridSpacingY*4*24; 2124 int max = mGridSpacingY*4*24;
1940 if ( contentsY() < 5 && max > viewport()->height()*3/2 ) 2125 if ( contentsY() < 5 && max > viewport()->height()*3/2 )
1941 mContentPosition = 0; 2126 mContentPosition = 0;
1942 else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2) 2127 else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2)
1943 mContentPosition = -1.0; 2128 mContentPosition = -1.0;
1944 else 2129 else
1945 mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2))); 2130 mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2)));
1946 //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height()); 2131 //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height());
1947 2132
1948} 2133}
1949void KOAgenda::restorePosition() 2134void KOAgenda::restorePosition()
1950{ 2135{
1951 int posY; 2136 int posY;
1952 int max = mGridSpacingY*4*24; 2137 int max = mGridSpacingY*4*24;
1953 if ( mContentPosition < 0 ) 2138 if ( mContentPosition < 0 )
1954 posY = max-viewport()->height(); 2139 posY = max-viewport()->height();
1955 else 2140 else
1956 if ( mContentPosition == 0 ) 2141 if ( mContentPosition == 0 )
1957 posY = 0; 2142 posY = 0;
1958 else 2143 else
1959 posY = (max/mContentPosition)-(viewport()->height()/2); 2144 posY = (max/mContentPosition)-(viewport()->height()/2);
1960 setContentsPos (0, posY ); 2145 setContentsPos (0, posY );
1961 //qDebug("posY %d hei %d", posY, max); 2146 //qDebug("posY %d hei %d", posY, max);
1962 2147
1963} 2148}
1964void KOAgenda::moveChild( QWidget *w, int x , int y ) 2149void KOAgenda::moveChild( QWidget *w, int x , int y )
1965{ 2150{
1966 ++x; 2151 ++x;
1967 QScrollView::moveChild( w, x , y ); 2152 QScrollView::moveChild( w, x , y );
1968} 2153}
1969#include <qmessagebox.h> 2154#include <qmessagebox.h>
1970#ifdef DESKTOP_VERSION 2155#ifdef DESKTOP_VERSION
1971#include <qprinter.h> 2156#include <qprinter.h>
1972#include <qpainter.h> 2157#include <qpainter.h>
1973#include <qpaintdevicemetrics.h> 2158#include <qpaintdevicemetrics.h>
1974 2159
1975#endif 2160#endif
1976void KOAgenda::printSelection() 2161void KOAgenda::printSelection()
1977{ 2162{
1978#ifdef DESKTOP_VERSION 2163#ifdef DESKTOP_VERSION
1979 if ( mStartCellY == mCurrentCellY ) { 2164 if ( mStartCellY == mCurrentCellY ) {
1980 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2165 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
1981 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. "), 2166 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. "),
1982 i18n("OK"), 0, 0, 2167 i18n("OK"), 0, 0,
1983 0, 1 ); 2168 0, 1 );
1984 return; 2169 return;
1985 } 2170 }
1986 2171
1987 float dx, dy; 2172 float dx, dy;
1988 int x,y,w,h; 2173 int x,y,w,h;
1989 x= 0; 2174 x= 0;
1990 w= contentsWidth()+2; 2175 w= contentsWidth()+2;
1991 // h= contentsHeight(); 2176 // h= contentsHeight();
1992 y = mGridSpacingY*mStartCellY; 2177 y = mGridSpacingY*mStartCellY;
1993 h = mGridSpacingY*(mCurrentCellY+1)-y+2; 2178 h = mGridSpacingY*(mCurrentCellY+1)-y+2;
1994 2179
1995 //return; 2180 //return;
1996 QPrinter* printer = new QPrinter(); 2181 QPrinter* printer = new QPrinter();
1997 if ( !printer->setup()) { 2182 if ( !printer->setup()) {
1998 delete printer; 2183 delete printer;
1999 return; 2184 return;
2000 } 2185 }
2001 QPainter p( printer ); 2186 QPainter p( printer );
2002 QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer ); 2187 QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer );
2003 QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() ); 2188 QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() );
2004 //date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true ); 2189 //date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true );
2005 int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height(); 2190 int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height();
2006 // p.drawText( 0, 0, date ); 2191 // p.drawText( 0, 0, date );
2007 int offset = m.width()/8; 2192 int offset = m.width()/8;
2008 // compute the scale 2193 // compute the scale
2009 dx = ((float) m.width()-offset) / (float)w; 2194 dx = ((float) m.width()-offset) / (float)w;
2010 dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h; 2195 dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h;
2011 float scale; 2196 float scale;
2012 // scale to fit the width or height of the paper 2197 // scale to fit the width or height of the paper
2013 if ( dx < dy ) 2198 if ( dx < dy )
2014 scale = dx; 2199 scale = dx;
2015 else 2200 else
2016 scale = dy; 2201 scale = dy;
2017 // set the scale 2202 // set the scale
2018 p.drawText( offset* scale, offset* scale*3/4, date ); 2203 p.drawText( offset* scale, offset* scale*3/4, date );
2019 2204
2020 int selDay; 2205 int selDay;
2021 float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count())); 2206 float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count()));
2022 float startX = 1; 2207 float startX = 1;
2023 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) 2208 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay)
2024 { 2209 {
2025 QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true ); 2210 QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true );
2026 p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) ); 2211 p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) );
2027 p.drawText( offset* scale+startX, (offset+hei)* scale, text ); 2212 p.drawText( offset* scale+startX, (offset+hei)* scale, text );
2028 startX += widOffset; 2213 startX += widOffset;
2029 2214
2030 } 2215 }
2031 p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale)); 2216 p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale));
2032 p.scale( scale, scale ); 2217 p.scale( scale, scale );
2033 p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale ); 2218 p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale );
2034 // now printing with y offset: 2 hei 2219 // now printing with y offset: 2 hei
2035 // p.translate( 0, -y*scale); 2220 // p.translate( 0, -y*scale);
2036 2221
2037 drawContentsToPainter(&p, true ); 2222 drawContentsToPainter(&p, true );
2038 globalFlagBlockAgendaItemUpdate = false; 2223 globalFlagBlockAgendaItemUpdate = false;
2039 KOAgendaItem *item; 2224 KOAgendaItem *item;
2040 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 2225 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
2041 item->select(false); 2226 item->select(false);
2042 item->paintMe( false, &p ); 2227 item->paintMe( false, &p );
2043 } 2228 }
2044 globalFlagBlockAgendaItemUpdate = true; 2229 globalFlagBlockAgendaItemUpdate = true;
2045 p.end(); 2230 p.end();
2046 delete printer; 2231 delete printer;
2047#else 2232#else
2048 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2233 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2049 i18n("Not supported \non PDA!\n"), 2234 i18n("Not supported \non PDA!\n"),
2050 i18n("OK"), 0, 0, 2235 i18n("OK"), 0, 0,
2051 0, 1 ); 2236 0, 1 );
2052#endif 2237#endif
2053} 2238}
diff --git a/korganizer/koagenda.h b/korganizer/koagenda.h
index f3f1772..3d33ae5 100644
--- a/korganizer/koagenda.h
+++ b/korganizer/koagenda.h
@@ -1,290 +1,296 @@
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 KOAGENDA_H 23#ifndef KOAGENDA_H
24#define KOAGENDA_H 24#define KOAGENDA_H
25 25
26#include <qscrollview.h> 26#include <qscrollview.h>
27#include <qtimer.h> 27#include <qtimer.h>
28#include <qmemarray.h> 28#include <qmemarray.h>
29#include <qpainter.h> 29#include <qpainter.h>
30#include <qpixmap.h> 30#include <qpixmap.h>
31#include <qguardedptr.h> 31#include <qguardedptr.h>
32 32
33#include "koagendaitem.h" 33#include "koagendaitem.h"
34 34
35class QPopupMenu; 35class QPopupMenu;
36class QTime; 36class QTime;
37class KConfig; 37class KConfig;
38class QFrame; 38class QFrame;
39class KOAgenda; 39class KOAgenda;
40class KCal::Event; 40class KCal::Event;
41class KCal::Todo; 41class KCal::Todo;
42 42
43using namespace KCal; 43using namespace KCal;
44 44
45class MarcusBains : public QFrame { 45class MarcusBains : public QFrame {
46 Q_OBJECT 46 Q_OBJECT
47 public: 47 public:
48 MarcusBains(KOAgenda *agenda=0,const char *name=0); 48 MarcusBains(KOAgenda *agenda=0,const char *name=0);
49 virtual ~MarcusBains(); 49 virtual ~MarcusBains();
50 50
51 public slots: 51 public slots:
52 void updateLocation(bool recalculate=false); 52 void updateLocation(bool recalculate=false);
53 void updateLoc(); 53 void updateLoc();
54 54
55 private: 55 private:
56 int todayColumn(); 56 int todayColumn();
57 QTimer *minutes; 57 QTimer *minutes;
58 QLabel *mTimeBox; 58 QLabel *mTimeBox;
59 KOAgenda *agenda; 59 KOAgenda *agenda;
60 QTime oldTime; 60 QTime oldTime;
61 int oldToday; 61 int oldToday;
62}; 62};
63 63
64 64
65class KOAgenda : public QScrollView 65class KOAgenda : public QScrollView
66{ 66{
67 Q_OBJECT 67 Q_OBJECT
68 public: 68 public:
69 enum MouseActionType { NOP, MOVE, SELECT, 69 enum MouseActionType { NOP, MOVE, SELECT,
70 RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT }; 70 RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT };
71 71
72 KOAgenda ( int columns, int rows, int columnSize, QWidget * parent=0, 72 KOAgenda ( int columns, int rows, int columnSize, QWidget * parent=0,
73 const char * name=0, WFlags f=0 ); 73 const char * name=0, WFlags f=0 );
74 KOAgenda ( int columns, QWidget * parent=0, 74 KOAgenda ( int columns, QWidget * parent=0,
75 const char * name=0, WFlags f=0 ); 75 const char * name=0, WFlags f=0 );
76 virtual ~KOAgenda(); 76 virtual ~KOAgenda();
77 77
78 Incidence *selectedIncidence() const; 78 Incidence *selectedIncidence() const;
79 QDate selectedIncidenceDate() const; 79 QDate selectedIncidenceDate() const;
80 80
81 virtual bool eventFilter ( QObject *, QEvent * ); 81 virtual bool eventFilter ( QObject *, QEvent * );
82 82
83 void contentsToGrid (int x, int y, int& gx, int& gy); 83 void contentsToGrid (int x, int y, int& gx, int& gy);
84 void gridToContents (int gx, int gy, int& x, int& y); 84 void gridToContents (int gx, int gy, int& x, int& y);
85 85
86 int timeToY (const QTime &time); 86 int timeToY (const QTime &time);
87 QTime gyToTime (int y); 87 QTime gyToTime (int y);
88 88
89 void setStartHour(int startHour); 89 void setStartHour(int startHour);
90 90
91 KOAgendaItem *insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom); 91 KOAgendaItem *insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom);
92 KOAgendaItem *insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd); 92 KOAgendaItem *insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd);
93 void insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, 93 void insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd,
94 int YTop,int YBottom); 94 int YTop,int YBottom);
95 95
96 void changeColumns(int columns); 96 void changeColumns(int columns);
97 97
98 int columns() { return mColumns; } 98 int columns() { return mColumns; }
99 int rows() { return mRows; } 99 int rows() { return mRows; }
100 100
101 int gridSpacingX() const { return mGridSpacingX; } 101 int gridSpacingX() const { return mGridSpacingX; }
102 int gridSpacingY() const { return mGridSpacingY; } 102 int gridSpacingY() const { return mGridSpacingY; }
103 103
104// virtual QSizePolicy sizePolicy() const; 104// virtual QSizePolicy sizePolicy() const;
105 105
106 void clear(); 106 void clear();
107 107
108 void clearSelection(); 108 void clearSelection();
109 void hideUnused(); 109 void hideUnused();
110 110
111 /** Calculates the minimum width */ 111 /** Calculates the minimum width */
112 virtual int minimumWidth() const; 112 virtual int minimumWidth() const;
113 /** Update configuration from preference settings */ 113 /** Update configuration from preference settings */
114 void updateConfig(); 114 void updateConfig();
115 115
116 void checkScrollBoundaries(); 116 void checkScrollBoundaries();
117 117
118 void setHolidayMask(QMemArray<bool> *); 118 void setHolidayMask(QMemArray<bool> *);
119 void setDateList(const DateList &selectedDates); 119 void setDateList(const DateList &selectedDates);
120 DateList dateList() const; 120 DateList dateList() const;
121 void drawContentsToPainter( QPainter* paint = 0, bool backgroundOnly = false); 121 void drawContentsToPainter( QPainter* paint = 0, bool backgroundOnly = false);
122 void finishUpdate(); 122 void finishUpdate();
123 void printSelection(); 123 void printSelection();
124 void storePosition(); 124 void storePosition();
125 void restorePosition(); 125 void restorePosition();
126 126
127 127
128 public slots: 128 public slots:
129 void popupMenu();
129 void newItem( int ); 130 void newItem( int );
130 void moveChild( QWidget *, int, int ); 131 void moveChild( QWidget *, int, int );
131 void scrollUp(); 132 void scrollUp();
132 void scrollDown(); 133 void scrollDown();
133 void updateTodo( Todo * t, int , bool ); 134 void updateTodo( Todo * t, int , bool );
134 void popupAlarm(); 135 void popupAlarm();
135 136
136 void checkScrollBoundaries(int); 137 void checkScrollBoundaries(int);
137 138
138 /** Deselect selected items. This function does not emit any signals. */ 139 /** Deselect selected items. This function does not emit any signals. */
139 void deselectItem(); 140 void deselectItem();
140 /** Select item. If the argument is 0, the currently selected item gets 141 /** Select item. If the argument is 0, the currently selected item gets
141 deselected. This function emits the itemSelected(bool) signal to inform 142 deselected. This function emits the itemSelected(bool) signal to inform
142 about selection/deseelction of events. */ 143 about selection/deseelction of events. */
143 void selectItem(KOAgendaItem *); 144 void selectItem(KOAgendaItem *);
144 void finishResize(); 145 void finishResize();
145 146
146 signals: 147 signals:
147 void showDateView( int, QDate ); 148 void showDateView( int, QDate );
148 void newEventSignal(); 149 void newEventSignal();
149 void newEventSignal(int gx,int gy); 150 void newEventSignal(int gx,int gy);
150 void newTodoSignal(int gx,int gy); 151 void newTodoSignal(int gx,int gy);
151 void newEventSignal(int gxStart, int gyStart, int gxEnd, int gyEnd); 152 void newEventSignal(int gxStart, int gyStart, int gxEnd, int gyEnd);
152 void newTimeSpanSignal(int gxStart, int gyStart, int gxEnd, int gyEnd); 153 void newTimeSpanSignal(int gxStart, int gyStart, int gxEnd, int gyEnd);
153 void newStartSelectSignal(); 154 void newStartSelectSignal();
154 void showIncidenceSignal(Incidence *); 155 void showIncidenceSignal(Incidence *);
155 void editIncidenceSignal(Incidence *); 156 void editIncidenceSignal(Incidence *);
156 void deleteIncidenceSignal(Incidence *); 157 void deleteIncidenceSignal(Incidence *);
157 void showIncidencePopupSignal(Incidence *); 158 void showIncidencePopupSignal(Incidence *);
158 159
159 void itemModified(KOAgendaItem *item, int ); 160 void itemModified(KOAgendaItem *item, int );
160 void incidenceSelected(Incidence *); 161 void incidenceSelected(Incidence *);
161 162
162 void lowerYChanged(int); 163 void lowerYChanged(int);
163 void upperYChanged(int); 164 void upperYChanged(int);
164 165
165 void startDragSignal(Incidence *); 166 void startDragSignal(Incidence *);
166 void addToCalSignal(Incidence *, Incidence *); 167 void addToCalSignal(Incidence *, Incidence *);
167 void resizedSignal(); 168 void resizedSignal();
168 169
169 protected: 170 protected:
170 QPainter mPixPainter; 171 QPainter mPixPainter;
171 QPixmap mPaintPixmap; 172 QPixmap mPaintPixmap;
172 QPixmap mHighlightPixmap; 173 QPixmap mHighlightPixmap;
173 void drawContents(QPainter *p,int cx, int cy, int cw, int ch); 174 void drawContents(QPainter *p,int cx, int cy, int cw, int ch);
174 virtual void resizeEvent ( QResizeEvent * ); 175 virtual void resizeEvent ( QResizeEvent * );
175 176
176 /** Handles mouse events. Called from eventFilter */ 177 /** Handles mouse events. Called from eventFilter */
177 virtual bool eventFilter_mouse ( QObject *, QMouseEvent * ); 178 virtual bool eventFilter_mouse ( QObject *, QMouseEvent * );
178 179
179 /** Start selecting time span. */ 180 /** Start selecting time span. */
180 void startSelectAction(QPoint viewportPos); 181 void startSelectAction(QPoint viewportPos);
181 182
182 /** Select time span. */ 183 /** Select time span. */
183 void performSelectAction(QPoint viewportPos); 184 void performSelectAction(QPoint viewportPos);
184 185
185 /** Emd selecting time span. */ 186 /** Emd selecting time span. */
186 void endSelectAction( bool emitNewEvent = false ); 187 void endSelectAction( bool emitNewEvent = false );
187 188
188 /** Start moving/resizing agenda item */ 189 /** Start moving/resizing agenda item */
189 void startItemAction(QPoint viewportPos); 190 void startItemAction(QPoint viewportPos);
190 191
191 /** Move/resize agenda item */ 192 /** Move/resize agenda item */
192 void performItemAction(QPoint viewportPos); 193 void performItemAction(QPoint viewportPos);
193 194
194 /** End moving/resizing agenda item */ 195 /** End moving/resizing agenda item */
195 void endItemAction(); 196 void endItemAction();
196 197
197 /** Set cursor, when no item action is in progress */ 198 /** Set cursor, when no item action is in progress */
198 void setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos); 199 void setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos);
199 200
200 /** Place agenda item in agenda and adjust other cells if necessary */ 201 /** Place agenda item in agenda and adjust other cells if necessary */
201 void placeSubCells(KOAgendaItem *placeItem); 202 void placeSubCells(KOAgendaItem *placeItem);
202 203
203 /** Process the keyevent, including the ignored keyevents of eventwidgets. 204 /** Process the keyevent, including the ignored keyevents of eventwidgets.
204 * Implements pgup/pgdn and cursor key navigation in the view. 205 * Implements pgup/pgdn and cursor key navigation in the view.
205 */ 206 */
206 void keyPressEvent( QKeyEvent * ); 207 void keyPressEvent( QKeyEvent * );
207 208
208 void calculateWorkingHours(); 209 void calculateWorkingHours();
209 210
210 virtual void contentsMousePressEvent ( QMouseEvent * ); 211 virtual void contentsMousePressEvent ( QMouseEvent * );
211 212
212 private: 213 private:
213 void init(); 214 void init();
214 void marcus_bains(); 215 void marcus_bains();
215 bool mAllDayMode; 216 bool mAllDayMode;
216 bool blockResize; 217 bool blockResize;
218 bool mLeftMouseDown;
219 KOAgendaItem *mPopupItem;
220 QTimer* mPopupTimer;
221 int mPopupKind;
222 QPoint mPopupPos;
217 QTimer mResizeTimer; 223 QTimer mResizeTimer;
218 double mContentPosition; 224 double mContentPosition;
219 225
220 // Width and height of agenda cells 226 // Width and height of agenda cells
221 int mGridSpacingX; 227 int mGridSpacingX;
222 int mGridSpacingY; 228 int mGridSpacingY;
223 229
224 // size of border, where mouse action will resize the KOAgendaItem 230 // size of border, where mouse action will resize the KOAgendaItem
225 int mResizeBorderWidth; 231 int mResizeBorderWidth;
226 232
227 // size of border, where mouse mve will cause a scroll of the agenda 233 // size of border, where mouse mve will cause a scroll of the agenda
228 int mScrollBorderWidth; 234 int mScrollBorderWidth;
229 int mScrollDelay; 235 int mScrollDelay;
230 int mScrollOffset; 236 int mScrollOffset;
231 237
232 QTimer mScrollUpTimer; 238 QTimer mScrollUpTimer;
233 QTimer mScrollDownTimer; 239 QTimer mScrollDownTimer;
234 240
235 // Number of Columns/Rows of agenda grid 241 // Number of Columns/Rows of agenda grid
236 int mColumns; 242 int mColumns;
237 int mRows; 243 int mRows;
238 244
239 // Cells to store Move and Resize coordiantes 245 // Cells to store Move and Resize coordiantes
240 int mStartCellX; 246 int mStartCellX;
241 int mStartCellY; 247 int mStartCellY;
242 int mCurrentCellX; 248 int mCurrentCellX;
243 int mCurrentCellY; 249 int mCurrentCellY;
244 250
245 // Working Hour coordiantes 251 // Working Hour coordiantes
246 bool mWorkingHoursEnable; 252 bool mWorkingHoursEnable;
247 int mWorkingHoursYTop; 253 int mWorkingHoursYTop;
248 int mWorkingHoursYBottom; 254 int mWorkingHoursYBottom;
249 255
250 // Selection 256 // Selection
251 int mSelectionCellX; 257 int mSelectionCellX;
252 int mSelectionYTop; 258 int mSelectionYTop;
253 int mSelectionHeight; 259 int mSelectionHeight;
254 260
255 // List of dates to be displayed 261 // List of dates to be displayed
256 DateList mSelectedDates; 262 DateList mSelectedDates;
257 263
258 // The KOAgendaItem, which has been right-clicked last 264 // The KOAgendaItem, which has been right-clicked last
259 KOAgendaItem *mClickedItem; 265 KOAgendaItem *mClickedItem;
260 266
261 // The KOAgendaItem, which is being moved/resized 267 // The KOAgendaItem, which is being moved/resized
262 QGuardedPtr<KOAgendaItem> mActionItem; 268 QGuardedPtr<KOAgendaItem> mActionItem;
263 269
264 // Currently selected item 270 // Currently selected item
265 QGuardedPtr<KOAgendaItem> mSelectedItem; 271 QGuardedPtr<KOAgendaItem> mSelectedItem;
266 272
267 // The Marcus Bains Line widget. 273 // The Marcus Bains Line widget.
268 MarcusBains *mMarcusBains; 274 MarcusBains *mMarcusBains;
269 void computeSizes(); 275 void computeSizes();
270 276
271 MouseActionType mActionType; 277 MouseActionType mActionType;
272 278
273 bool mItemMoved; 279 bool mItemMoved;
274 280
275 // List of all Items contained in agenda 281 // List of all Items contained in agenda
276 QPtrList<KOAgendaItem> mItems; 282 QPtrList<KOAgendaItem> mItems;
277 QPtrList<KOAgendaItem> mUnusedItems; 283 QPtrList<KOAgendaItem> mUnusedItems;
278 KOAgendaItem* getNewItem(Incidence * event,QDate qd, QWidget* viewport); 284 KOAgendaItem* getNewItem(Incidence * event,QDate qd, QWidget* viewport);
279 QPopupMenu *mItemPopup; // Right mouse button popup menu for KOAgendaItems 285 QPopupMenu *mItemPopup; // Right mouse button popup menu for KOAgendaItems
280 QPopupMenu *mNewItemPopup; 286 QPopupMenu *mNewItemPopup;
281 287
282 int mOldLowerScrollValue; 288 int mOldLowerScrollValue;
283 int mOldUpperScrollValue; 289 int mOldUpperScrollValue;
284 KOAgendaItem * getItemForTodo ( Todo * todo ); 290 KOAgendaItem * getItemForTodo ( Todo * todo );
285 QMemArray<bool> *mHolidayMask; 291 QMemArray<bool> *mHolidayMask;
286 int mCurPixWid; 292 int mCurPixWid;
287 int mCurPixHei; 293 int mCurPixHei;
288}; 294};
289 295
290#endif // KOAGENDA_H 296#endif // KOAGENDA_H
diff --git a/korganizer/koagendaitem.cpp b/korganizer/koagendaitem.cpp
index 905c1bf..b30ad75 100644
--- a/korganizer/koagendaitem.cpp
+++ b/korganizer/koagendaitem.cpp
@@ -1,804 +1,804 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,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 19
20#include <qlabel.h> 20#include <qlabel.h>
21#include <qlayout.h> 21#include <qlayout.h>
22#include <qhbox.h> 22#include <qhbox.h>
23#include <qvbox.h> 23#include <qvbox.h>
24#include <qtooltip.h> 24#include <qtooltip.h>
25#include <qwhatsthis.h> 25#include <qwhatsthis.h>
26#include <qdragobject.h> 26#include <qdragobject.h>
27#include <qdrawutil.h> 27#include <qdrawutil.h>
28#include <qpainter.h> 28#include <qpainter.h>
29 29
30#include <kiconloader.h> 30#include <kiconloader.h>
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kglobal.h> 32#include <kglobal.h>
33#include <klocale.h> 33#include <klocale.h>
34#ifndef DESKTOP_VERSION 34#ifndef DESKTOP_VERSION
35#include <qpe/qpeapplication.h> 35#include <qpe/qpeapplication.h>
36#define AGENDA_ICON_SIZE 5 36#define AGENDA_ICON_SIZE 5
37#else 37#else
38#define AGENDA_ICON_SIZE 7 38#define AGENDA_ICON_SIZE 7
39#endif 39#endif
40#include <libkcal/icaldrag.h> 40#include <libkcal/icaldrag.h>
41#include <libkcal/vcaldrag.h> 41#include <libkcal/vcaldrag.h>
42#include <libkcal/kincidenceformatter.h> 42#include <libkcal/kincidenceformatter.h>
43extern int globalFlagBlockAgenda; 43extern int globalFlagBlockAgenda;
44extern int globalFlagBlockAgendaItemPaint; 44extern int globalFlagBlockAgendaItemPaint;
45extern int globalFlagBlockAgendaItemUpdate; 45extern int globalFlagBlockAgendaItemUpdate;
46 46
47#include "koprefs.h" 47#include "koprefs.h"
48 48
49#include "koagendaitem.h" 49#include "koagendaitem.h"
50//#include "koagendaitem.moc" 50//#include "koagendaitem.moc"
51 51
52 52
53//-------------------------------------------------------------------------- 53//--------------------------------------------------------------------------
54 54
55QToolTipGroup *KOAgendaItem::mToolTipGroup = 0; 55QToolTipGroup *KOAgendaItem::mToolTipGroup = 0;
56 56
57//-------------------------------------------------------------------------- 57//--------------------------------------------------------------------------
58 58
59class KOAgendaItemWhatsThis :public QWhatsThis 59class KOAgendaItemWhatsThis :public QWhatsThis
60{ 60{
61public: 61public:
62 KOAgendaItemWhatsThis( KOAgendaItem* view ) : QWhatsThis( view ),_view (view) { }; 62 KOAgendaItemWhatsThis( KOAgendaItem* view ) : QWhatsThis( view ),_view (view) { };
63 63
64protected: 64protected:
65 virtual QString text( const QPoint& ) 65 virtual QString text( const QPoint& )
66 { 66 {
67 return _view->getWhatsThisText() ; 67 return _view->getWhatsThisText() ;
68 } 68 }
69private: 69private:
70 KOAgendaItem * _view; 70 KOAgendaItem * _view;
71}; 71};
72 72
73KOAgendaItem::KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent,bool allday, 73KOAgendaItem::KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent,bool allday,
74 const char *name,WFlags) : 74 const char *name,WFlags) :
75 QWidget(parent, name), mIncidence(incidence), mDate(qd) 75 QWidget(parent, name), mIncidence(incidence), mDate(qd)
76{ 76{
77#ifndef DESKTOP_VERSION 77#ifndef DESKTOP_VERSION
78 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); 78 //QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
79#endif 79#endif
80 mKOAgendaItemWhatsThis = new KOAgendaItemWhatsThis(this); 80 mKOAgendaItemWhatsThis = new KOAgendaItemWhatsThis(this);
81 int wflags = getWFlags() |WRepaintNoErase;// WResizeNoErase 81 int wflags = getWFlags() |WRepaintNoErase;// WResizeNoErase
82 setWFlags ( wflags); 82 setWFlags ( wflags);
83 mAllDay = allday; 83 mAllDay = allday;
84 init ( incidence, qd ); 84 init ( incidence, qd );
85 //setMouseTracking(true); 85 //setMouseTracking(true);
86 //setAcceptDrops(true); 86 //setAcceptDrops(true);
87 xPaintCoord = -1; 87 xPaintCoord = -1;
88 yPaintCoord = -1; 88 yPaintCoord = -1;
89} 89}
90QString KOAgendaItem::getWhatsThisText() 90QString KOAgendaItem::getWhatsThisText()
91{ 91{
92 if ( mIncidence ) 92 if ( mIncidence )
93 return KIncidenceFormatter::instance()->getFormattedText( mIncidence, 93 return KIncidenceFormatter::instance()->getFormattedText( mIncidence,
94 KOPrefs::instance()->mWTshowDetails, 94 KOPrefs::instance()->mWTshowDetails,
95 KOPrefs::instance()->mWTshowCreated, 95 KOPrefs::instance()->mWTshowCreated,
96 KOPrefs::instance()->mWTshowChanged); 96 KOPrefs::instance()->mWTshowChanged);
97 return "KOAgendaItem::getWhatsThisText()::internal error"; 97 return "KOAgendaItem::getWhatsThisText()::internal error";
98} 98}
99void KOAgendaItem::init ( Incidence *incidence, QDate qd ) 99void KOAgendaItem::init ( Incidence *incidence, QDate qd )
100{ 100{
101 mIncidence = incidence; 101 mIncidence = incidence;
102 mDate = qd; 102 mDate = qd;
103 mFirstMultiItem = 0; 103 mFirstMultiItem = 0;
104 mNextMultiItem = 0; 104 mNextMultiItem = 0;
105 mLastMultiItem = 0; 105 mLastMultiItem = 0;
106 computeText(); 106 computeText();
107 107
108 if ( (incidence->type() == "Todo") && 108 if ( (incidence->type() == "Todo") &&
109 ( !((static_cast<Todo*>(incidence))->isCompleted()) && 109 ( !((static_cast<Todo*>(incidence))->isCompleted()) &&
110 ((static_cast<Todo*>(incidence))->dtDue().date() <= QDate::currentDate()) ) ) { 110 ((static_cast<Todo*>(incidence))->dtDue().date() <= QDate::currentDate()) ) ) {
111 if ( (static_cast<Todo*>(incidence))->dtDue() < QDateTime::currentDateTime().date()) 111 if ( (static_cast<Todo*>(incidence))->dtDue() < QDateTime::currentDateTime().date())
112 mBackgroundColor = KOPrefs::instance()->mTodoOverdueColor ; 112 mBackgroundColor = KOPrefs::instance()->mTodoOverdueColor ;
113 else 113 else
114 mBackgroundColor = KOPrefs::instance()->mTodoDueTodayColor; 114 mBackgroundColor = KOPrefs::instance()->mTodoDueTodayColor;
115 } 115 }
116 else { 116 else {
117 QStringList categories = mIncidence->categories(); 117 QStringList categories = mIncidence->categories();
118 QString cat = categories.first(); 118 QString cat = categories.first();
119 if (cat.isEmpty()) { 119 if (cat.isEmpty()) {
120 if ( (incidence->type() == "Todo") &&((static_cast<Todo*>(incidence))->isCompleted()) ) 120 if ( (incidence->type() == "Todo") &&((static_cast<Todo*>(incidence))->isCompleted()) )
121 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor; 121 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor;
122 else 122 else
123 mBackgroundColor =KOPrefs::instance()->mEventColor; 123 mBackgroundColor =KOPrefs::instance()->mEventColor;
124 } else { 124 } else {
125 mBackgroundColor = *KOPrefs::instance()->categoryColor(cat); 125 mBackgroundColor = *KOPrefs::instance()->categoryColor(cat);
126 if ( (incidence->type() == "Todo") &&((static_cast<Todo*>(incidence))->isCompleted()) ) { 126 if ( (incidence->type() == "Todo") &&((static_cast<Todo*>(incidence))->isCompleted()) ) {
127 if ( mBackgroundColor == KOPrefs::instance()->mEventColor ) 127 if ( mBackgroundColor == KOPrefs::instance()->mEventColor )
128 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor; 128 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor;
129 } 129 }
130 } 130 }
131 131
132 } 132 }
133 mColorGroup = QColorGroup( mBackgroundColor.light(), 133 mColorGroup = QColorGroup( mBackgroundColor.light(),
134 mBackgroundColor.dark(),mBackgroundColor.light(), 134 mBackgroundColor.dark(),mBackgroundColor.light(),
135 mBackgroundColor.dark(),mBackgroundColor, black, mBackgroundColor) ; 135 mBackgroundColor.dark(),mBackgroundColor, black, mBackgroundColor) ;
136 setBackgroundColor( mBackgroundColor ); 136 setBackgroundColor( mBackgroundColor );
137 137
138 mConflictItems.clear(); 138 mConflictItems.clear();
139 setCellXY(0,0,1); 139 setCellXY(0,0,1);
140 setCellXWidth(0); 140 setCellXWidth(0);
141 setSubCell(0); 141 setSubCell(0);
142 setSubCells(1); 142 setSubCells(1);
143 setMultiItem(0,0,0); 143 setMultiItem(0,0,0);
144 startMove(); 144 startMove();
145 mSelected = true; 145 mSelected = true;
146 select(false); 146 select(false);
147 QFontMetrics fontinf(KOPrefs::instance()->mAgendaViewFont); 147 QFontMetrics fontinf(KOPrefs::instance()->mAgendaViewFont);
148 mFontPixelSize = fontinf.height();; 148 mFontPixelSize = fontinf.height();;
149 hide(); 149 hide();
150 xPaintCoord = -1; 150 xPaintCoord = -1;
151 yPaintCoord = -1; 151 yPaintCoord = -1;
152} 152}
153 153
154 154
155KOAgendaItem::~KOAgendaItem() 155KOAgendaItem::~KOAgendaItem()
156{ 156{
157 // qDebug("deleteKOAgendaItem::~KOAgendaItem( "); 157 // qDebug("deleteKOAgendaItem::~KOAgendaItem( ");
158 // delete mKOAgendaItemWhatsThis; 158 // delete mKOAgendaItemWhatsThis;
159} 159}
160 160
161void KOAgendaItem::recreateIncidence() 161void KOAgendaItem::recreateIncidence()
162{ 162{
163#if 0 163#if 0
164 Incidence* newInc = mIncidence->clone(); 164 Incidence* newInc = mIncidence->clone();
165 newInc->recreate(); 165 newInc->recreate();
166 if ( mIncidence->doesRecur() ) { 166 if ( mIncidence->doesRecur() ) {
167 mIncidence->addExDate( mDate ); 167 mIncidence->addExDate( mDate );
168 newInc->recurrence()->unsetRecurs(); 168 newInc->recurrence()->unsetRecurs();
169 int len = mIncidence->dtStart().secsTo( ((Event*)mIncidence)->dtEnd()); 169 int len = mIncidence->dtStart().secsTo( ((Event*)mIncidence)->dtEnd());
170 QTime tim = mIncidence->dtStart().time(); 170 QTime tim = mIncidence->dtStart().time();
171 newInc->setDtStart( QDateTime(mDate, tim) ); 171 newInc->setDtStart( QDateTime(mDate, tim) );
172 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); 172 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) );
173 } 173 }
174#endif 174#endif
175 mIncidence = mIncidence->recreateCloneException( mDate ); 175 mIncidence = mIncidence->recreateCloneException( mDate );
176} 176}
177bool KOAgendaItem::updateIcons(QPainter * p, bool horLayout) 177bool KOAgendaItem::updateIcons(QPainter * p, bool horLayout)
178{ 178{
179 int size = AGENDA_ICON_SIZE; 179 int size = AGENDA_ICON_SIZE;
180 180
181 int yOff = 0; 181 int yOff = 0;
182 int xOff = 0; 182 int xOff = 0;
183 int x = pos().x() +3; 183 int x = pos().x() +3;
184 int y; 184 int y;
185 if ( mAllDay ) 185 if ( mAllDay )
186 y = pos().y()+3; 186 y = pos().y()+3;
187 else 187 else
188 y = mCellYTop * ( height() / cellHeight() ) +3; 188 y = mCellYTop * ( height() / cellHeight() ) +3;
189 if (mIncidence->cancelled()) { 189 if (mIncidence->cancelled()) {
190 int xpos = xOff*( 1 +AGENDA_ICON_SIZE )+x; 190 int xpos = xOff*( 1 +AGENDA_ICON_SIZE )+x;
191 int ypos = yOff*( 1 +AGENDA_ICON_SIZE)+y; 191 int ypos = yOff*( 1 +AGENDA_ICON_SIZE)+y;
192 p->drawLine( xpos, ypos, xpos+AGENDA_ICON_SIZE-1, ypos+AGENDA_ICON_SIZE-1 ); 192 p->drawLine( xpos, ypos, xpos+AGENDA_ICON_SIZE-1, ypos+AGENDA_ICON_SIZE-1 );
193 p->drawLine( xpos, ypos+AGENDA_ICON_SIZE-1, xpos+AGENDA_ICON_SIZE-1, ypos ); 193 p->drawLine( xpos, ypos+AGENDA_ICON_SIZE-1, xpos+AGENDA_ICON_SIZE-1, ypos );
194 if ( horLayout ) 194 if ( horLayout )
195 ++xOff; 195 ++xOff;
196 else 196 else
197 ++yOff; 197 ++yOff;
198 } 198 }
199 if (mIncidence->isAlarmEnabled()) { 199 if (mIncidence->isAlarmEnabled()) {
200 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, red ); 200 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, red );
201 if ( horLayout ) 201 if ( horLayout )
202 ++xOff; 202 ++xOff;
203 else 203 else
204 ++yOff; 204 ++yOff;
205 } 205 }
206 if (mIncidence->recurrence()->doesRecur()) { 206 if (mIncidence->recurrence()->doesRecur()) {
207 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, blue ); 207 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, blue );
208 if ( horLayout ) 208 if ( horLayout )
209 ++xOff; 209 ++xOff;
210 else 210 else
211 ++yOff; 211 ++yOff;
212 } 212 }
213 if (mIncidence->description().length() > 0) { 213 if (mIncidence->description().length() > 0) {
214 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkGreen ); 214 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkGreen );
215 if ( horLayout ) 215 if ( horLayout )
216 ++xOff; 216 ++xOff;
217 else 217 else
218 ++yOff; 218 ++yOff;
219 } 219 }
220 if (mIncidence->isReadOnly()) { 220 if (mIncidence->isReadOnly()) {
221 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, white ); 221 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, white );
222 if ( horLayout ) 222 if ( horLayout )
223 ++xOff; 223 ++xOff;
224 else 224 else
225 ++yOff; 225 ++yOff;
226 } 226 }
227 227
228 if (mIncidence->attendeeCount()>0) { 228 if (mIncidence->attendeeCount()>0) {
229 229
230 if (mIncidence->organizer() == KOPrefs::instance()->email()) { 230 if (mIncidence->organizer() == KOPrefs::instance()->email()) {
231 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, black ); 231 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, black );
232 if ( horLayout ) 232 if ( horLayout )
233 ++xOff; 233 ++xOff;
234 else 234 else
235 ++yOff; 235 ++yOff;
236 } else { 236 } else {
237 Attendee *me = mIncidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 237 Attendee *me = mIncidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
238 if (me!=0) { 238 if (me!=0) {
239 239
240 240
241 } else { 241 } else {
242 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, yellow ); 242 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, yellow );
243 if ( horLayout ) 243 if ( horLayout )
244 ++xOff; 244 ++xOff;
245 else 245 else
246 ++yOff; 246 ++yOff;
247 247
248 } 248 }
249 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkYellow ); 249 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkYellow );
250 if ( horLayout ) 250 if ( horLayout )
251 ++xOff; 251 ++xOff;
252 else 252 else
253 ++yOff; 253 ++yOff;
254 254
255 } 255 }
256 256
257 } 257 }
258 return ( yOff || xOff ); 258 return ( yOff || xOff );
259} 259}
260 260
261 261
262void KOAgendaItem::select(bool selected) 262void KOAgendaItem::select(bool selected)
263{ 263{
264 //qDebug("select %d %d",firstMultiItem(), nextMultiItem() ); 264 //qDebug("select %d %d",firstMultiItem(), nextMultiItem() );
265 if (mSelected == selected) return; 265 if (mSelected == selected) return;
266 mSelected = selected; 266 mSelected = selected;
267 if ( ! isVisible() ) 267 if ( ! isVisible() )
268 return; 268 return;
269 if ( firstMultiItem() ) 269 if ( firstMultiItem() )
270 firstMultiItem()->select( selected ); 270 firstMultiItem()->select( selected );
271 if ( !firstMultiItem() && nextMultiItem() ) { 271 if ( !firstMultiItem() && nextMultiItem() ) {
272 KOAgendaItem * placeItem = nextMultiItem(); 272 KOAgendaItem * placeItem = nextMultiItem();
273 while ( placeItem ) { 273 while ( placeItem ) {
274 placeItem->select( selected ); 274 placeItem->select( selected );
275 placeItem = placeItem->nextMultiItem(); 275 placeItem = placeItem->nextMultiItem();
276 } 276 }
277 } 277 }
278 globalFlagBlockAgendaItemUpdate = 0; 278 globalFlagBlockAgendaItemUpdate = 0;
279 paintMe( selected ); 279 paintMe( selected );
280 globalFlagBlockAgendaItemUpdate = 1; 280 globalFlagBlockAgendaItemUpdate = 1;
281 repaint( false ); 281 repaint( false );
282} 282}
283 283
284 284
285/* 285/*
286 The eventFilter has to filter the mouse events of the agenda item childs. The 286 The eventFilter has to filter the mouse events of the agenda item childs. The
287 events are fed into the event handling method of KOAgendaItem. This allows the 287 events are fed into the event handling method of KOAgendaItem. This allows the
288 KOAgenda to handle the KOAgendaItems by using an eventFilter. 288 KOAgenda to handle the KOAgendaItems by using an eventFilter.
289*/ 289*/
290bool KOAgendaItem::eventFilter ( QObject *object, QEvent *e ) 290bool KOAgendaItem::eventFilter ( QObject *object, QEvent *e )
291{ 291{
292 if (e->type() == QEvent::MouseButtonPress || 292 if (e->type() == QEvent::MouseButtonPress ||
293 e->type() == QEvent::MouseButtonDblClick || 293 e->type() == QEvent::MouseButtonDblClick ||
294 e->type() == QEvent::MouseButtonRelease || 294 e->type() == QEvent::MouseButtonRelease ||
295 e->type() == QEvent::MouseMove) { 295 e->type() == QEvent::MouseMove) {
296 QMouseEvent *me = (QMouseEvent *)e; 296 QMouseEvent *me = (QMouseEvent *)e;
297 QPoint itemPos = this->mapFromGlobal(((QWidget *)object)-> 297 QPoint itemPos = this->mapFromGlobal(((QWidget *)object)->
298 mapToGlobal(me->pos())); 298 mapToGlobal(me->pos()));
299 QMouseEvent returnEvent (e->type(),itemPos,me->button(),me->state()); 299 QMouseEvent returnEvent (e->type(),itemPos,me->button(),me->state());
300 return event(&returnEvent); 300 return event(&returnEvent);
301 } else { 301 } else {
302 return false; 302 return false;
303 } 303 }
304} 304}
305void KOAgendaItem::repaintMe( ) 305void KOAgendaItem::repaintMe( )
306{ 306{
307 paintMe ( mSelected ); 307 paintMe ( mSelected );
308} 308}
309void KOAgendaItem::paintMe( bool selected, QPainter* paint ) 309void KOAgendaItem::paintMe( bool selected, QPainter* paint )
310{ 310{
311 if ( globalFlagBlockAgendaItemUpdate && ! selected) 311 if ( globalFlagBlockAgendaItemUpdate && ! selected)
312 return; 312 return;
313 QPainter pa; 313 QPainter pa;
314 314
315 if ( mSelected ) { 315 if ( mSelected ) {
316 pa.begin( paintPixSel() ); 316 pa.begin( paintPixSel() );
317 } else { 317 } else {
318 if ( mAllDay ) 318 if ( mAllDay )
319 pa.begin( paintPixAllday() ); 319 pa.begin( paintPixAllday() );
320 else 320 else
321 pa.begin( paintPix() ); 321 pa.begin( paintPix() );
322 } 322 }
323 int x, yy, w, h; 323 int x, yy, w, h;
324 float nfh = 7.0; 324 float nfh = 7.0;
325 x = pos().x(); w = width(); h = height (); 325 x = pos().x(); w = width(); h = height ();
326 if ( mAllDay ) 326 if ( mAllDay )
327 yy = y(); 327 yy = y();
328 else 328 else
329 yy = mCellYTop * ( height() / cellHeight() ); 329 yy = mCellYTop * ( height() / cellHeight() );
330 xPaintCoord= x; 330 xPaintCoord= x;
331 yPaintCoord = yy; 331 yPaintCoord = yy;
332 wPaintCoord = width(); 332 wPaintCoord = width();
333 hPaintCoord = height(); 333 hPaintCoord = height();
334 //qDebug("paintMe %s %d %d %d %d",incidence()->summary().latin1(), x, yy, width(), height()); 334 //qDebug("paintMe %s %d %d %d %d",incidence()->summary().latin1(), x, yy, width(), height());
335 if ( paint == 0 ) 335 if ( paint == 0 )
336 paint = &pa; 336 paint = &pa;
337 bool horLayout = ( w < h ); 337 bool horLayout = ( w < h );
338 int maxhei = mFontPixelSize+4; 338 int maxhei = mFontPixelSize+4;
339 if ( horLayout ) 339 if ( horLayout )
340 maxhei += AGENDA_ICON_SIZE -4; 340 maxhei += AGENDA_ICON_SIZE -4;
341 bool small = ( h < maxhei ); 341 bool small = ( h < maxhei );
342 if ( ! small ) 342 if ( ! small )
343 paint->setFont(KOPrefs::instance()->mAgendaViewFont); 343 paint->setFont(KOPrefs::instance()->mAgendaViewFont);
344 else { 344 else {
345 QFont f = KOPrefs::instance()->mAgendaViewFont; 345 QFont f = KOPrefs::instance()->mAgendaViewFont;
346 f.setBold( false ); 346 f.setBold( false );
347 int fh = f.pointSize(); 347 int fh = f.pointSize();
348 nfh = (((float)height())/(float)(mFontPixelSize+4))*fh; 348 nfh = (((float)height())/(float)(mFontPixelSize+4))*fh;
349 if ( nfh < 6 ) 349 if ( nfh < 6 )
350 nfh = 6; 350 nfh = 6;
351 f.setPointSize( nfh ); 351 f.setPointSize( nfh );
352 paint->setFont(f); 352 paint->setFont(f);
353 } 353 }
354 paint->fillRect ( x, yy, w, h, mBackgroundColor ); 354 paint->fillRect ( x, yy, w, h, mBackgroundColor );
355 static const QPixmap completedPxmp = SmallIcon("greenhook16"); 355 static const QPixmap completedPxmp = SmallIcon("greenhook16");
356 static const QPixmap overduePxmp = SmallIcon("redcross16"); 356 static const QPixmap overduePxmp = SmallIcon("redcross16");
357 if ( mIncidence->type() == "Todo" ) { 357 if ( mIncidence->type() == "Todo" ) {
358 Todo* tempTodo = static_cast<Todo*>(mIncidence); 358 Todo* tempTodo = static_cast<Todo*>(mIncidence);
359 int xx = pos().x()+(width()-completedPxmp.width()-3 ); 359 int xx = pos().x()+(width()-completedPxmp.width()-3 );
360 int yyy = yy+3; 360 int yyy = yy+3;
361 if ( tempTodo->isCompleted() ) 361 if ( tempTodo->isCompleted() )
362 paint->drawPixmap ( xx, yyy, completedPxmp ); 362 paint->drawPixmap ( xx, yyy, completedPxmp );
363 else { 363 else {
364 paint->drawPixmap ( xx, yyy, overduePxmp ); 364 paint->drawPixmap ( xx, yyy, overduePxmp );
365 365
366 } 366 }
367 } 367 }
368 bool addIcon = false; 368 bool addIcon = false;
369 if ( ! small || w > 3 * h || h > 3* w ) 369 if ( ! small || w > 3 * h || h > 3* w )
370 addIcon = updateIcons( paint, horLayout ); 370 addIcon = updateIcons( paint, horLayout );
371 371
372 qDrawShadePanel (paint, x, yy, w, h, mColorGroup, selected , 2, 0); 372 qDrawShadePanel (paint, x, yy, w, h, mColorGroup, selected , 2, 0);
373 //qDebug("draw rect %d %d %d %d ",x, yy, w, h ); 373 //qDebug("draw rect %d %d %d %d ",x, yy, w, h );
374 if ( ! small ) { 374 if ( ! small ) {
375 x += 3; yy += 3;w -= 6; h-= 5; 375 x += 3; yy += 3;w -= 6; h-= 5;
376 } else { 376 } else {
377 x += 2; yy += 1;w -= 4; h-= 4; 377 x += 2; yy += 1;w -= 4; h-= 4;
378 if ( nfh < 6.01 ) { 378 if ( nfh < 6.01 ) {
379 yy -= 2; 379 yy -= 2;
380 h += 4; 380 h += 4;
381 } 381 }
382 else 382 else
383 if ( nfh < h -2 ) 383 if ( nfh < h -2 )
384 ++yy; 384 ++yy;
385 } 385 }
386 int align; 386 int align;
387#ifndef DESKTOP_VERSION 387#ifndef DESKTOP_VERSION
388 align = ( AlignLeft|WordBreak|AlignTop); 388 align = ( AlignLeft|WordBreak|AlignTop);
389#else 389#else
390 align = ( AlignLeft|BreakAnywhere|WordBreak|AlignTop); 390 align = ( AlignLeft|BreakAnywhere|WordBreak|AlignTop);
391#endif 391#endif
392 if ( addIcon ) { 392 if ( addIcon ) {
393 if ( ! horLayout ) { 393 if ( ! horLayout ) {
394 x += AGENDA_ICON_SIZE+3; 394 x += AGENDA_ICON_SIZE+3;
395 w -= (AGENDA_ICON_SIZE+3); 395 w -= (AGENDA_ICON_SIZE+3);
396 } 396 }
397 else { 397 else {
398 yy+= AGENDA_ICON_SIZE+2; 398 yy+= AGENDA_ICON_SIZE+2;
399 h -=(AGENDA_ICON_SIZE+3); 399 h -=(AGENDA_ICON_SIZE+3);
400 } 400 }
401 } 401 }
402 int colsum = mBackgroundColor.red() + mBackgroundColor.green() + mBackgroundColor.blue(); 402 int colsum = mBackgroundColor.red() + mBackgroundColor.green() + mBackgroundColor.blue();
403 if ( colsum < 250 ) 403 if ( colsum < 250 )
404 paint->setPen ( white); 404 paint->setPen ( white);
405 if ( x < 0 ) { 405 if ( x < 0 ) {
406 w = w+x-3; 406 w = w+x-3;
407 x = 3; 407 x = 3;
408 if ( w > parentWidget()->width() ){ 408 if ( w > parentWidget()->width() ){
409 w = parentWidget()->width() - 6; 409 w = parentWidget()->width() - 6;
410#ifndef DESKTOP_VERSION 410#ifndef DESKTOP_VERSION
411 align = ( AlignHCenter|WordBreak|AlignTop); 411 align = ( AlignHCenter|WordBreak|AlignTop);
412#else 412#else
413 align = ( AlignHCenter|BreakAnywhere|WordBreak|AlignTop); 413 align = ( AlignHCenter|BreakAnywhere|WordBreak|AlignTop);
414#endif 414#endif
415 415
416 } 416 }
417 } 417 }
418 QRect dr; 418 QRect dr;
419 if ( w + x > parentWidget()->width() ) 419 if ( w + x > parentWidget()->width() )
420 w = parentWidget()->width()-x; 420 w = parentWidget()->width()-x;
421 paint->drawText ( x, yy, w, h, align, mDisplayedText, -1, &dr ); 421 paint->drawText ( x, yy, w, h, align, mDisplayedText, -1, &dr );
422 //qDebug("%d %d %d %d ", x, yy, w, h ); 422 //qDebug("%d %d %d %d ", x, yy, w, h );
423 if ( mIncidence->cancelled() ){ 423 if ( mIncidence->cancelled() ){
424 if ( ! small ) { 424 if ( ! small ) {
425 QFontMetrics fm ( paint->font() ); 425 QFontMetrics fm ( paint->font() );
426 paint->drawLine(dr.left(), yy+fm.height()/2, dr.right()-2, yy+fm.height()/2); 426 paint->drawLine(dr.left(), yy+fm.height()/2, dr.right()-2, yy+fm.height()/2);
427 } 427 }
428 428
429 } 429 }
430 pa.end(); 430 pa.end();
431 431
432} 432}
433void KOAgendaItem::resizePixmap( int w , int h ) 433void KOAgendaItem::resizePixmap( int w , int h )
434{ 434{
435 paintPix()->resize( w, h ); 435 paintPix()->resize( w, h );
436 paintPixSel()->resize( w, h ); 436 paintPixSel()->resize( w, h );
437 437
438} 438}
439QPixmap * KOAgendaItem::paintPix() 439QPixmap * KOAgendaItem::paintPix()
440{ 440{
441 static QPixmap* mPaintPix = 0; 441 static QPixmap* mPaintPix = 0;
442 if ( ! mPaintPix ) 442 if ( ! mPaintPix )
443 mPaintPix = new QPixmap(1,1); 443 mPaintPix = new QPixmap(1,1);
444 return mPaintPix ; 444 return mPaintPix ;
445} 445}
446QPixmap * KOAgendaItem::paintPixAllday() 446QPixmap * KOAgendaItem::paintPixAllday()
447{ 447{
448 static QPixmap* mPaintPixA = 0; 448 static QPixmap* mPaintPixA = 0;
449 if ( ! mPaintPixA ) 449 if ( ! mPaintPixA )
450 mPaintPixA = new QPixmap(1,1); 450 mPaintPixA = new QPixmap(1,1);
451 return mPaintPixA ; 451 return mPaintPixA ;
452} 452}
453QPixmap * KOAgendaItem::paintPixSel() 453QPixmap * KOAgendaItem::paintPixSel()
454{ 454{
455 static QPixmap* mPaintPixSel = 0; 455 static QPixmap* mPaintPixSel = 0;
456 if ( ! mPaintPixSel ) 456 if ( ! mPaintPixSel )
457 mPaintPixSel = new QPixmap(1,1); 457 mPaintPixSel = new QPixmap(1,1);
458 return mPaintPixSel ; 458 return mPaintPixSel ;
459} 459}
460void KOAgendaItem::paintEvent ( QPaintEvent *e ) 460void KOAgendaItem::paintEvent ( QPaintEvent *e )
461{ 461{
462 462
463 if ( globalFlagBlockAgendaItemPaint ) 463 if ( globalFlagBlockAgendaItemPaint )
464 return; 464 return;
465 if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 ) 465 if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 )
466 return; 466 return;
467 int yy; 467 int yy;
468 if ( mAllDay ) 468 if ( mAllDay )
469 yy = y(); 469 yy = y();
470 else 470 else
471 yy = mCellYTop * ( height() / cellHeight() ); 471 yy = mCellYTop * ( height() / cellHeight() );
472 int xx = x(); 472 int xx = x();
473 473
474 if ( xPaintCoord != xx || yPaintCoord != yy || 474 if ( xPaintCoord != xx || yPaintCoord != yy ||
475 wPaintCoord != width() || hPaintCoord != height()) { 475 wPaintCoord != width() || hPaintCoord != height()) {
476 xPaintCoord= xx; 476 xPaintCoord= xx;
477 yPaintCoord = yy; 477 yPaintCoord = yy;
478 wPaintCoord = width(); 478 wPaintCoord = width();
479 hPaintCoord = height(); 479 hPaintCoord = height();
480 globalFlagBlockAgendaItemUpdate = 0; 480 globalFlagBlockAgendaItemUpdate = 0;
481 paintMe( mSelected ); 481 paintMe( mSelected );
482 //qDebug("calling paintMe "); 482 //qDebug("calling paintMe ");
483 globalFlagBlockAgendaItemUpdate = 1; 483 globalFlagBlockAgendaItemUpdate = 1;
484 } 484 }
485 int rx, ry, rw, rh; 485 int rx, ry, rw, rh;
486 rx = e->rect().x(); 486 rx = e->rect().x();
487 ry = e->rect().y(); 487 ry = e->rect().y();
488 rw = e->rect().width(); 488 rw = e->rect().width();
489 rh = e->rect().height(); 489 rh = e->rect().height();
490 //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height()); 490 //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height());
491 491
492 QPixmap* paintFrom ; 492 QPixmap* paintFrom ;
493 if ( mSelected ) { 493 if ( mSelected ) {
494 paintFrom = paintPixSel(); 494 paintFrom = paintPixSel();
495 } else { 495 } else {
496 if ( mAllDay ) 496 if ( mAllDay )
497 paintFrom = paintPixAllday(); 497 paintFrom = paintPixAllday();
498 else 498 else
499 paintFrom = paintPix(); 499 paintFrom = paintPix();
500 } 500 }
501 xx += rx; 501 xx += rx;
502 502
503 if ( xx < 0 ) { 503 if ( xx < 0 ) {
504 rw = rw + xx; 504 rw = rw + xx;
505 rx -= xx; 505 rx -= xx;
506 xx = 0; 506 xx = 0;
507 if ( rw <= 1 ) { 507 if ( rw <= 1 ) {
508 //qDebug("KOAgendaItem::Width1 <= 1 (%d). Returning. %s",rw,mDisplayedText.latin1()); 508 //qDebug("KOAgendaItem::Width1 <= 1 (%d). Returning. %s",rw,mDisplayedText.latin1());
509 return; 509 return;
510 } 510 }
511 } 511 }
512 if ( paintFrom->width() < xx+rw ) { 512 if ( paintFrom->width() < xx+rw ) {
513 rw = paintFrom->width() - xx; 513 rw = paintFrom->width() - xx;
514 if ( rw <= 1 ) { 514 if ( rw <= 1 ) {
515 //qDebug("KOAgendaItem::Width2 <= 1 (%d). Returning.%s ",rw,mDisplayedText.latin1() ); 515 //qDebug("KOAgendaItem::Width2 <= 1 (%d). Returning.%s ",rw,mDisplayedText.latin1() );
516 return; 516 return;
517 } 517 }
518 } 518 }
519 //qDebug("%d %d %d %d %d %d %d",rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh); 519 //qDebug("%d %d %d %d %d %d %d",rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh);
520 bitBlt (this, rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh ,CopyROP); 520 bitBlt (this, rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh ,CopyROP);
521} 521}
522void KOAgendaItem::computeText() 522void KOAgendaItem::computeText()
523{ 523{
524 524
525 mDisplayedText = mIncidence->summary(); 525 mDisplayedText = mIncidence->summary();
526 if ( (mIncidence->type() == "Todo") ) { 526 if ( (mIncidence->type() == "Todo") ) {
527 if ( static_cast<Todo*>(mIncidence)->hasDueDate() ) { 527 if ( static_cast<Todo*>(mIncidence)->hasDueDate() ) {
528 if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() ) 528 if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() )
529 mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")"; 529 mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")";
530 else if ( !(mIncidence->doesFloat())) 530 else if ( !(mIncidence->doesFloat()))
531 mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")"; 531 mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")";
532 } 532 }
533 } else { 533 } else {
534 if ( !(mIncidence->doesFloat()) && KOPrefs::instance()->mShowTimeInAgenda) 534 if ( !(mIncidence->doesFloat()) && KOPrefs::instance()->mShowTimeInAgenda)
535 mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + "-" + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ; 535 mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + "-" + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ;
536 536
537 if ( mAllDay ) { 537 if ( mAllDay ) {
538 if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) { 538 if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) {
539 mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true) ; 539 mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true) ;
540 } 540 }
541 } 541 }
542 542
543 } 543 }
544 544
545 if ( !mIncidence->location().isEmpty() ) { 545 if ( !mIncidence->location().isEmpty() ) {
546 if ( mAllDay ) 546 if ( mAllDay )
547 mDisplayedText += " ("; 547 mDisplayedText += " (";
548 else 548 else
549 mDisplayedText += "\n("; 549 mDisplayedText += "\n(";
550 mDisplayedText += mIncidence->location() +")"; 550 mDisplayedText += mIncidence->location() +")";
551 } 551 }
552 552
553 QString tipText = mIncidence->summary(); 553 QString tipText = mIncidence->summary();
554 if ( !mIncidence->doesFloat() ) { 554 if ( !mIncidence->doesFloat() ) {
555 if ( mIncidence->type() == "Event" ) { 555 if ( mIncidence->type() == "Event" ) {
556 if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) { 556 if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) {
557 tipText += "\n"+i18n("From: ")+mIncidence->dtStartStr(); 557 tipText += "\n"+i18n("From: ")+mIncidence->dtStartStr();
558 tipText += "\n"+i18n("To: ")+(static_cast<Event*>(mIncidence))->dtEndStr(); 558 tipText += "\n"+i18n("To: ")+(static_cast<Event*>(mIncidence))->dtEndStr();
559 } 559 }
560 else { 560 else {
561 tipText += "\n"+i18n("Time: ")+mIncidence->dtStartTimeStr(); 561 tipText += "\n"+i18n("Time: ")+mIncidence->dtStartTimeStr();
562 tipText += " - "+(static_cast<Event*>(mIncidence))->dtEndTimeStr(); 562 tipText += " - "+(static_cast<Event*>(mIncidence))->dtEndTimeStr();
563 } 563 }
564 } 564 }
565 else if ( mIncidence->type() == "Todo" ) { 565 else if ( mIncidence->type() == "Todo" ) {
566 if (mIncidence->hasStartDate()) 566 if (mIncidence->hasStartDate())
567 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartStr(); 567 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartStr();
568 if (((Todo*)mIncidence)->hasDueDate()) 568 if (((Todo*)mIncidence)->hasDueDate())
569 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueStr(); 569 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueStr();
570 } 570 }
571 } else if ( mIncidence->type() == "Todo" ) { 571 } else if ( mIncidence->type() == "Todo" ) {
572 if (mIncidence->hasStartDate()) 572 if (mIncidence->hasStartDate())
573 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartDateStr(); 573 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartDateStr();
574 if (((Todo*)mIncidence)->hasDueDate()) 574 if (((Todo*)mIncidence)->hasDueDate())
575 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueDateStr(); 575 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueDateStr();
576 } 576 }
577 577
578 if (!mIncidence->location().isEmpty()) { 578 if (!mIncidence->location().isEmpty()) {
579 tipText += "\n"+i18n("Location: ")+mIncidence->location(); 579 tipText += "\n"+i18n("Location: ")+mIncidence->location();
580 } 580 }
581 QToolTip::add(this,tipText,toolTipGroup(),""); 581 QToolTip::add(this,tipText,toolTipGroup(),"");
582 582
583} 583}
584void KOAgendaItem::updateItem() 584void KOAgendaItem::updateItem()
585{ 585{
586 computeText(); 586 computeText();
587 587
588 //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y()); 588 //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y());
589 paintMe( mSelected ); 589 paintMe( mSelected );
590 repaint( false); 590 repaint( false);
591} 591}
592 592
593void KOAgendaItem::resizeEvent ( QResizeEvent *ev ) 593void KOAgendaItem::resizeEvent ( QResizeEvent *ev )
594{ 594{
595 //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1()); 595 //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1());
596 paintMe( mSelected ); 596 paintMe( mSelected );
597 repaint( false ); 597 repaint( false );
598} 598}
599 599
600/* 600/*
601 Return height of item in units of agenda cells 601 Return height of item in units of agenda cells
602*/ 602*/
603int KOAgendaItem::cellHeight() 603int KOAgendaItem::cellHeight()
604{ 604{
605 int ret = mCellYBottom - mCellYTop + 1; 605 int ret = mCellYBottom - mCellYTop + 1;
606 if ( ret <= 0 ) { 606 if ( ret <= 0 ) {
607 ret = 1; 607 ret = 1;
608 mCellYBottom = 0; 608 mCellYBottom = 0;
609 mCellYTop = 0; 609 mCellYTop = 0;
610 } 610 }
611 return ret; 611 return ret;
612} 612}
613 613
614/* 614/*
615 Return height of item in units of agenda cells 615 Return height of item in units of agenda cells
616*/ 616*/
617int KOAgendaItem::cellWidth() 617int KOAgendaItem::cellWidth()
618{ 618{
619 return mCellXWidth - mCellX + 1; 619 return mCellXWidth - mCellX + 1;
620} 620}
621 621
622void KOAgendaItem::setItemDate(QDate qd) 622void KOAgendaItem::setItemDate(QDate qd)
623{ 623{
624 mDate = qd; 624 mDate = qd;
625} 625}
626 626
627void KOAgendaItem::setCellXY(int X, int YTop, int YBottom) 627void KOAgendaItem::setCellXY(int X, int YTop, int YBottom)
628{ 628{
629 mCellX = X; 629 mCellX = X;
630 mCellYTop = YTop; 630 mCellYTop = YTop;
631 mCellYBottom = YBottom; 631 mCellYBottom = YBottom;
632} 632}
633 633
634void KOAgendaItem::setCellXWidth(int xwidth) 634void KOAgendaItem::setCellXWidth(int xwidth)
635{ 635{
636 mCellXWidth = xwidth; 636 mCellXWidth = xwidth;
637} 637}
638 638
639void KOAgendaItem::setCellX(int XLeft, int XRight) 639void KOAgendaItem::setCellX(int XLeft, int XRight)
640{ 640{
641 mCellX = XLeft; 641 mCellX = XLeft;
642 mCellXWidth = XRight; 642 mCellXWidth = XRight;
643} 643}
644 644
645void KOAgendaItem::setCellY(int YTop, int YBottom) 645void KOAgendaItem::setCellY(int YTop, int YBottom)
646{ 646{
647 mCellYTop = YTop; 647 mCellYTop = YTop;
648 mCellYBottom = YBottom; 648 mCellYBottom = YBottom;
649} 649}
650 650
651void KOAgendaItem::setSubCell(int subCell) 651void KOAgendaItem::setSubCell(int subCell)
652{ 652{
653 mSubCell = subCell; 653 mSubCell = subCell;
654} 654}
655 655
656void KOAgendaItem::setSubCells(int subCells) 656void KOAgendaItem::setSubCells(int subCells)
657{ 657{
658 mSubCells = subCells; 658 mSubCells = subCells;
659} 659}
660 660
661void KOAgendaItem::setMultiItem(KOAgendaItem *first,KOAgendaItem *next, 661void KOAgendaItem::setMultiItem(KOAgendaItem *first,KOAgendaItem *next,
662 KOAgendaItem *last) 662 KOAgendaItem *last)
663{ 663{
664 mFirstMultiItem = first; 664 mFirstMultiItem = first;
665 mNextMultiItem = next; 665 mNextMultiItem = next;
666 mLastMultiItem = last; 666 mLastMultiItem = last;
667} 667}
668 668
669void KOAgendaItem::startMove() 669void KOAgendaItem::startMove()
670{ 670{
671 mStartCellX = mCellX; 671 mStartCellX = mCellX;
672 mStartCellXWidth = mCellXWidth; 672 mStartCellXWidth = mCellXWidth;
673 mStartCellYTop = mCellYTop; 673 mStartCellYTop = mCellYTop;
674 mStartCellYBottom = mCellYBottom; 674 mStartCellYBottom = mCellYBottom;
675} 675}
676 676
677void KOAgendaItem::resetMove() 677void KOAgendaItem::resetMove()
678{ 678{
679 mCellX = mStartCellX; 679 mCellX = mStartCellX;
680 mCellXWidth = mStartCellXWidth; 680 mCellXWidth = mStartCellXWidth;
681 mCellYTop = mStartCellYTop; 681 mCellYTop = mStartCellYTop;
682 mCellYBottom = mStartCellYBottom; 682 mCellYBottom = mStartCellYBottom;
683} 683}
684 684
685void KOAgendaItem::moveRelative(int dx, int dy) 685void KOAgendaItem::moveRelative(int dx, int dy)
686{ 686{
687 int newX = cellX() + dx; 687 int newX = cellX() + dx;
688 int newXWidth = cellXWidth() + dx; 688 int newXWidth = cellXWidth() + dx;
689 int newYTop = cellYTop() + dy; 689 int newYTop = cellYTop() + dy;
690 int newYBottom = cellYBottom() + dy; 690 int newYBottom = cellYBottom() + dy;
691 setCellXY(newX,newYTop,newYBottom); 691 setCellXY(newX,newYTop,newYBottom);
692 setCellXWidth(newXWidth); 692 setCellXWidth(newXWidth);
693} 693}
694 694
695void KOAgendaItem::expandTop(int dy) 695void KOAgendaItem::expandTop(int dy)
696{ 696{
697 int newYTop = cellYTop() + dy; 697 int newYTop = cellYTop() + dy;
698 int newYBottom = cellYBottom(); 698 int newYBottom = cellYBottom();
699 if (newYTop > newYBottom) newYTop = newYBottom; 699 if (newYTop > newYBottom) newYTop = newYBottom;
700 setCellY(newYTop, newYBottom); 700 setCellY(newYTop, newYBottom);
701} 701}
702 702
703void KOAgendaItem::expandBottom(int dy) 703void KOAgendaItem::expandBottom(int dy)
704{ 704{
705 int newYTop = cellYTop(); 705 int newYTop = cellYTop();
706 int newYBottom = cellYBottom() + dy; 706 int newYBottom = cellYBottom() + dy;
707 if (newYBottom < newYTop) newYBottom = newYTop; 707 if (newYBottom < newYTop) newYBottom = newYTop;
708 setCellY(newYTop, newYBottom); 708 setCellY(newYTop, newYBottom);
709} 709}
710 710
711void KOAgendaItem::expandLeft(int dx) 711void KOAgendaItem::expandLeft(int dx)
712{ 712{
713 int newX = cellX() + dx; 713 int newX = cellX() + dx;
714 int newXWidth = cellXWidth(); 714 int newXWidth = cellXWidth();
715 if (newX > newXWidth) newX = newXWidth; 715 if (newX > newXWidth) newX = newXWidth;
716 setCellX(newX,newXWidth); 716 setCellX(newX,newXWidth);
717} 717}
718 718
719void KOAgendaItem::expandRight(int dx) 719void KOAgendaItem::expandRight(int dx)
720{ 720{
721 int newX = cellX(); 721 int newX = cellX();
722 int newXWidth = cellXWidth() + dx; 722 int newXWidth = cellXWidth() + dx;
723 if (newXWidth < newX) newXWidth = newX; 723 if (newXWidth < newX) newXWidth = newX;
724 setCellX(newX,newXWidth); 724 setCellX(newX,newXWidth);
725} 725}
726 726
727QToolTipGroup *KOAgendaItem::toolTipGroup() 727QToolTipGroup *KOAgendaItem::toolTipGroup()
728{ 728{
729 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); 729 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0);
730 return mToolTipGroup; 730 return mToolTipGroup;
731} 731}
732 732
733void KOAgendaItem::dragEnterEvent( QDragEnterEvent *e ) 733void KOAgendaItem::dragEnterEvent( QDragEnterEvent *e )
734{ 734{
735#ifndef KORG_NODND 735#ifndef KORG_NODND
736 if ( ICalDrag::canDecode( e ) || VCalDrag::canDecode( e ) || 736 if ( ICalDrag::canDecode( e ) || VCalDrag::canDecode( e ) ||
737 !QTextDrag::canDecode( e ) ) { 737 !QTextDrag::canDecode( e ) ) {
738 e->ignore(); 738 e->ignore();
739 return; 739 return;
740 } 740 }
741 e->accept(); 741 e->accept();
742#endif 742#endif
743} 743}
744 744
745void KOAgendaItem::dropEvent( QDropEvent *e ) 745void KOAgendaItem::dropEvent( QDropEvent *e )
746{ 746{
747#ifndef KORG_NODND 747#ifndef KORG_NODND
748 QString text; 748 QString text;
749 if(QTextDrag::decode(e,text)) 749 if(QTextDrag::decode(e,text))
750 { 750 {
751 kdDebug() << "Dropped : " << text << endl; 751 kdDebug() << "Dropped : " << text << endl;
752 QStringList emails = QStringList::split(",",text); 752 QStringList emails = QStringList::split(",",text);
753 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { 753 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
754 kdDebug() << " Email: " << (*it) << endl; 754 kdDebug() << " Email: " << (*it) << endl;
755 int pos = (*it).find("<"); 755 int pos = (*it).find("<");
756 QString name = (*it).left(pos); 756 QString name = (*it).left(pos);
757 QString email = (*it).mid(pos); 757 QString email = (*it).mid(pos);
758 if (!email.isEmpty()) { 758 if (!email.isEmpty()) {
759 mIncidence->addAttendee(new Attendee(name,email)); 759 mIncidence->addAttendee(new Attendee(name,email));
760 } 760 }
761 } 761 }
762 } 762 }
763#endif 763#endif
764} 764}
765 765
766 766
767QPtrList<KOAgendaItem> KOAgendaItem::conflictItems() 767QPtrList<KOAgendaItem> KOAgendaItem::conflictItems()
768{ 768{
769 return mConflictItems; 769 return mConflictItems;
770} 770}
771 771
772void KOAgendaItem::setConflictItems(QPtrList<KOAgendaItem> ci) 772void KOAgendaItem::setConflictItems(QPtrList<KOAgendaItem> ci)
773{ 773{
774 mConflictItems = ci; 774 mConflictItems = ci;
775 KOAgendaItem *item; 775 KOAgendaItem *item;
776 for ( item=mConflictItems.first(); item != 0; 776 for ( item=mConflictItems.first(); item != 0;
777 item=mConflictItems.next() ) { 777 item=mConflictItems.next() ) {
778 item->addConflictItem(this); 778 item->addConflictItem(this);
779 } 779 }
780} 780}
781 781
782void KOAgendaItem::addConflictItem(KOAgendaItem *ci) 782void KOAgendaItem::addConflictItem(KOAgendaItem *ci)
783{ 783{
784 if (mConflictItems.find(ci)<0) 784 if (mConflictItems.find(ci)<0)
785 mConflictItems.append(ci); 785 mConflictItems.append(ci);
786} 786}
787 787
788bool KOAgendaItem::checkLayout() 788bool KOAgendaItem::checkLayout()
789{ 789{
790 if ( !mConflictItems.count() ) 790 if ( !mConflictItems.count() )
791 return true; 791 return true;
792 int max = 0; 792 int max = 0;
793 KOAgendaItem *item; 793 KOAgendaItem *item;
794 for ( item=mConflictItems.first(); item != 0; 794 for ( item=mConflictItems.first(); item != 0;
795 item=mConflictItems.next() ) { 795 item=mConflictItems.next() ) {
796 if ( item->subCells() > max ) 796 if ( item->subCells() > max )
797 max = item->subCells(); 797 max = item->subCells();
798 } 798 }
799 if ( max > subCells() ) { 799 if ( max > subCells() ) {
800 setSubCells( max ); 800 setSubCells( max );
801 return false; 801 return false;
802 } 802 }
803 return true; 803 return true;
804} 804}
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp
index 957ac52..b9c7dec 100644
--- a/korganizer/koagendaview.cpp
+++ b/korganizer/koagendaview.cpp
@@ -1,1589 +1,1581 @@
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
79 79
80 80
81TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) : 81TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) :
82 QScrollView(parent,name,f) 82 QScrollView(parent,name,f)
83{ 83{
84 mRows = rows; 84 mRows = rows;
85 85
86 setMinimumHeight( 20 ); 86 setMinimumHeight( 20 );
87 mCellHeight = KOPrefs::instance()->mHourSize*4; 87 mCellHeight = KOPrefs::instance()->mHourSize*4;
88 88
89 enableClipper(true); 89 enableClipper(true);
90 90
91 setHScrollBarMode(AlwaysOff); 91 setHScrollBarMode(AlwaysOff);
92 setVScrollBarMode(AlwaysOff); 92 setVScrollBarMode(AlwaysOff);
93 93
94 resizeContents(50,mRows * mCellHeight); 94 resizeContents(50,mRows * mCellHeight);
95 95
96 viewport()->setBackgroundMode( PaletteBackground ); 96 viewport()->setBackgroundMode( PaletteBackground );
97} 97}
98 98
99void TimeLabels::setCellHeight(int height) 99void TimeLabels::setCellHeight(int height)
100{ 100{
101 mCellHeight = height; 101 mCellHeight = height;
102} 102}
103 103
104/* 104/*
105 Optimization so that only the "dirty" portion of the scroll view 105 Optimization so that only the "dirty" portion of the scroll view
106 is redrawn. Unfortunately, this is not called by default paintEvent() method. 106 is redrawn. Unfortunately, this is not called by default paintEvent() method.
107*/ 107*/
108void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) 108void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch)
109{ 109{
110 110
111 // if ( globalFlagBlockAgenda ) 111 // if ( globalFlagBlockAgenda )
112 // return; 112 // return;
113 // bug: the parameters cx, cy, cw, ch are the areas that need to be 113 // bug: the parameters cx, cy, cw, ch are the areas that need to be
114 // redrawn, not the area of the widget. unfortunately, this 114 // redrawn, not the area of the widget. unfortunately, this
115 // code assumes the latter... 115 // code assumes the latter...
116 116
117 // now, for a workaround... 117 // now, for a workaround...
118 // these two assignments fix the weird redraw bug 118 // these two assignments fix the weird redraw bug
119 cx = contentsX() + 2; 119 cx = contentsX() + 2;
120 cw = contentsWidth() - 2; 120 cw = contentsWidth() - 2;
121 // end of workaround 121 // end of workaround
122 122
123 int cell = ((int)(cy/mCellHeight)); 123 int cell = ((int)(cy/mCellHeight));
124 int y = cell * mCellHeight; 124 int y = cell * mCellHeight;
125 QFontMetrics fm = fontMetrics(); 125 QFontMetrics fm = fontMetrics();
126 QString hour; 126 QString hour;
127 QString suffix; 127 QString suffix;
128 QString fullTime; 128 QString fullTime;
129 int tW = fm.width("24:00i"); 129 int tW = fm.width("24:00i");
130 int timeHeight = fm.height(); 130 int timeHeight = fm.height();
131 timeHeight -= (timeHeight/4-2); 131 timeHeight -= (timeHeight/4-2);
132 int borderWidth = 5; 132 int borderWidth = 2;
133 QFont nFont = p->font(); 133 QFont nFont = p->font();
134 QFont sFont = nFont; 134 QFont sFont = nFont;
135 sFont.setPointSize( sFont.pointSize()/2+2 ); 135 sFont.setPointSize( sFont.pointSize()/2+2 );
136 if (!KGlobal::locale()->use12Clock()) 136 if (!KGlobal::locale()->use12Clock())
137 suffix = "00"; 137 suffix = "00";
138 QFontMetrics fmS( sFont ); 138 QFontMetrics fmS( sFont );
139 int sHei = fmS.height(); 139 int sHei = fmS.height();
140 if ( timeHeight > mCellHeight ) { 140 if ( timeHeight > mCellHeight ) {
141 timeHeight = mCellHeight-1; 141 timeHeight = mCellHeight-1;
142 sHei -= 2; 142 sHei -= 2;
143 } 143 }
144 144
145 while (y < cy + ch) { 145 while (y < cy + ch) {
146 p->drawLine(cx,y,cx+tW,y); 146 p->drawLine(cx,y,cx+tW,y);
147 hour.setNum(cell); 147 hour.setNum(cell);
148 148
149 // handle 24h and am/pm time formats 149 // handle 24h and am/pm time formats
150 if (KGlobal::locale()->use12Clock()) { 150 if (KGlobal::locale()->use12Clock()) {
151 if (cell > 11) suffix = "pm"; 151 if (cell > 11) suffix = "pm";
152 else 152 else
153 suffix = "am"; 153 suffix = "am";
154 if (cell == 0) hour.setNum(12); 154 if (cell == 0) hour.setNum(12);
155 if (cell > 12) hour.setNum(cell - 12); 155 if (cell > 12) hour.setNum(cell - 12);
156 } 156 }
157 157
158 // create string in format of "XX:XX" or "XXpm/am" 158 // create string in format of "XX:XX" or "XXpm/am"
159 fullTime = hour;// + suffix; 159 fullTime = hour;// + suffix;
160 160
161 // center and draw the time label 161 // center and draw the time label
162 int timeWidth = fm.width(fullTime+"i"); 162 int timeWidth = fm.width(fullTime+"i");
163 int tw2 = fm.width(suffix); 163 int tw2 = fm.width(suffix);
164 int offset = this->width() - timeWidth - tw2; 164 int offset = this->width() - timeWidth - tw2;
165 p->setFont( nFont ); 165 p->setFont( nFont );
166 p->drawText(cx - borderWidth + offset, y+ timeHeight, fullTime); 166 p->drawText(cx - borderWidth + offset, y+ timeHeight, fullTime);
167 p->setFont( sFont ); 167 p->setFont( sFont );
168 offset += timeWidth; 168 offset += timeWidth;
169 p->drawText(cx - borderWidth + offset, y+ sHei, suffix); 169 p->drawText(cx - borderWidth + offset, y+ sHei, suffix);
170 170
171 // increment indices 171 // increment indices
172 y += mCellHeight; 172 y += mCellHeight;
173 cell++; 173 cell++;
174 } 174 }
175} 175}
176 176
177/** 177/**
178 Calculates the minimum width. 178 Calculates the minimum width.
179*/ 179*/
180int TimeLabels::minimumWidth() const 180int TimeLabels::minimumWidth() const
181{ 181{
182 QFontMetrics fm = fontMetrics(); 182 return mMiniWidth;
183
184 //TODO: calculate this value
185 int borderWidth = 4;
186
187 // the maximum width possible
188 int width = fm.width("88:88x") + borderWidth;
189
190 return width;
191} 183}
192 184
193/** updates widget's internal state */ 185/** updates widget's internal state */
194void TimeLabels::updateConfig() 186void TimeLabels::updateConfig()
195{ 187{
196 // set the font 188 // set the font
197 // config->setGroup("Fonts"); 189 // config->setGroup("Fonts");
198 // QFont font = config->readFontEntry("TimeBar Font"); 190 // QFont font = config->readFontEntry("TimeBar Font");
199 setFont(KOPrefs::instance()->mTimeBarFont); 191 setFont(KOPrefs::instance()->mTimeBarFont);
200 192 mMiniWidth = fontMetrics().width("88:88") + 2 ;
201 // update geometry restrictions based on new settings 193 // update geometry restrictions based on new settings
202 setFixedWidth(minimumWidth()); 194 setFixedWidth(minimumWidth());
203 195
204 // update HourSize 196 // update HourSize
205 mCellHeight = KOPrefs::instance()->mHourSize*4; 197 mCellHeight = KOPrefs::instance()->mHourSize*4;
206 resizeContents(50,mRows * mCellHeight); 198 resizeContents(50,mRows * mCellHeight);
207} 199}
208 200
209/** update time label positions */ 201/** update time label positions */
210void TimeLabels::positionChanged() 202void TimeLabels::positionChanged()
211{ 203{
212 int adjustment = mAgenda->contentsY(); 204 int adjustment = mAgenda->contentsY();
213 setContentsPos(0, adjustment); 205 setContentsPos(0, adjustment);
214} 206}
215 207
216/** */ 208/** */
217void TimeLabels::setAgenda(KOAgenda* agenda) 209void TimeLabels::setAgenda(KOAgenda* agenda)
218{ 210{
219 mAgenda = agenda; 211 mAgenda = agenda;
220} 212}
221 213
222void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) 214void TimeLabels::contentsMousePressEvent ( QMouseEvent * e)
223{ 215{
224 mMouseDownY = e->pos().y(); 216 mMouseDownY = e->pos().y();
225 mOrgCap = topLevelWidget()->caption(); 217 mOrgCap = topLevelWidget()->caption();
226} 218}
227 219
228void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) 220void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e )
229{ 221{
230 int diff = mMouseDownY - e->pos().y(); 222 int diff = mMouseDownY - e->pos().y();
231 if ( diff < 10 && diff > -10 ) 223 if ( diff < 10 && diff > -10 )
232 return; 224 return;
233 int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; 225 int tSize = KOPrefs::instance()->mHourSize + (diff/10) ;
234 if ( tSize < 4 ) 226 if ( tSize < 4 )
235 tSize = 4; 227 tSize = 4;
236 if ( tSize > 22 ) 228 if ( tSize > 22 )
237 tSize = 22; 229 tSize = 22;
238 tSize = (tSize-2)/2; 230 tSize = (tSize-2)/2;
239 topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); 231 topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize));
240 232
241} 233}
242void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) 234void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e )
243{ 235{
244 topLevelWidget()->setCaption( mOrgCap ); 236 topLevelWidget()->setCaption( mOrgCap );
245 int diff = mMouseDownY - e->pos().y(); 237 int diff = mMouseDownY - e->pos().y();
246 if ( diff < 10 && diff > -10 ) 238 if ( diff < 10 && diff > -10 )
247 return; 239 return;
248 int tSize = KOPrefs::instance()->mHourSize + (diff/10); 240 int tSize = KOPrefs::instance()->mHourSize + (diff/10);
249 if ( tSize < 4 ) 241 if ( tSize < 4 )
250 tSize = 4; 242 tSize = 4;
251 if ( tSize > 22 ) 243 if ( tSize > 22 )
252 tSize = 22; 244 tSize = 22;
253 tSize = (tSize/2)*2; 245 tSize = (tSize/2)*2;
254 if ( tSize == KOPrefs::instance()->mHourSize ) 246 if ( tSize == KOPrefs::instance()->mHourSize )
255 return; 247 return;
256 KOPrefs::instance()->mHourSize = tSize; 248 KOPrefs::instance()->mHourSize = tSize;
257 emit scaleChanged(); 249 emit scaleChanged();
258} 250}
259 251
260/** This is called in response to repaint() */ 252/** This is called in response to repaint() */
261void TimeLabels::paintEvent(QPaintEvent*) 253void TimeLabels::paintEvent(QPaintEvent*)
262{ 254{
263 255
264 // kdDebug() << "paintevent..." << endl; 256 // kdDebug() << "paintevent..." << endl;
265 // this is another hack! 257 // this is another hack!
266 // QPainter painter(this); 258 // QPainter painter(this);
267 //QString c 259 //QString c
268 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight()); 260 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight());
269} 261}
270 262
271//////////////////////////////////////////////////////////////////////////// 263////////////////////////////////////////////////////////////////////////////
272 264
273EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name) 265EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name)
274 : QFrame(parent,name) 266 : QFrame(parent,name)
275{ 267{
276 mColumns = 1; 268 mColumns = 1;
277 mTopBox = 0; 269 mTopBox = 0;
278 mLocation = loc; 270 mLocation = loc;
279 mTopLayout = 0; 271 mTopLayout = 0;
280 mPaintWidget = 0; 272 mPaintWidget = 0;
281 mXOffset = 0; 273 mXOffset = 0;
282 if (mLocation == Top) mPixmap = SmallIcon("1uparrow"); 274 if (mLocation == Top) mPixmap = SmallIcon("1uparrow");
283 else mPixmap = SmallIcon("1downarrow"); 275 else mPixmap = SmallIcon("1downarrow");
284 mEnabled.resize(mColumns); 276 mEnabled.resize(mColumns);
285 mEnabled.fill( false ); 277 mEnabled.fill( false );
286 setMinimumHeight(mPixmap.height()); 278 setMinimumHeight(mPixmap.height());
287} 279}
288 280
289EventIndicator::~EventIndicator() 281EventIndicator::~EventIndicator()
290{ 282{
291} 283}
292 284
293void EventIndicator::drawContents(QPainter *p) 285void EventIndicator::drawContents(QPainter *p)
294{ 286{
295 287
296 // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl; 288 // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl;
297 KDGanttSplitterHandle* han = 0; 289 KDGanttSplitterHandle* han = 0;
298 if ( mPaintWidget ) 290 if ( mPaintWidget )
299 han = mPaintWidget->firstHandle(); 291 han = mPaintWidget->firstHandle();
300 if ( ! han ) { 292 if ( ! han ) {
301 int i; 293 int i;
302 for(i=0;i<mColumns;++i) { 294 for(i=0;i<mColumns;++i) {
303 if (mEnabled[i]) { 295 if (mEnabled[i]) {
304 int cellWidth = contentsRect().right()/mColumns; 296 int cellWidth = contentsRect().right()/mColumns;
305 int xOffset = KOGlobals::self()->reverseLayout() ? 297 int xOffset = KOGlobals::self()->reverseLayout() ?
306 (mColumns - 1 - i)*cellWidth + (cellWidth -mPixmap.width())/2 : 298 (mColumns - 1 - i)*cellWidth + (cellWidth -mPixmap.width())/2 :
307 i*cellWidth + (cellWidth -mPixmap.width()) /2; 299 i*cellWidth + (cellWidth -mPixmap.width()) /2;
308 p->drawPixmap(QPoint(1+xOffset,0),mPixmap); 300 p->drawPixmap(QPoint(1+xOffset,0),mPixmap);
309 } 301 }
310 } 302 }
311 } else { 303 } else {
312 han->repaint(); 304 han->repaint();
313 //mPaintWidget->setBackgroundColor( red ); 305 //mPaintWidget->setBackgroundColor( red );
314 306
315 QPainter pa( han ); 307 QPainter pa( han );
316 int i; 308 int i;
317 bool setColor = false; 309 bool setColor = false;
318 for(i=0;i<mColumns;++i) { 310 for(i=0;i<mColumns;++i) {
319 if (mEnabled[i]) { 311 if (mEnabled[i]) {
320 setColor = true; 312 setColor = true;
321 313
322 int cellWidth = contentsRect().right()/mColumns; 314 int cellWidth = contentsRect().right()/mColumns;
323 int xOffset = KOGlobals::self()->reverseLayout() ? 315 int xOffset = KOGlobals::self()->reverseLayout() ?
324 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 : 316 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 :
325 i*cellWidth + cellWidth/2 -mPixmap.width()/2; 317 i*cellWidth + cellWidth/2 -mPixmap.width()/2;
326 pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap); 318 pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap);
327 //qDebug("222draw pix %d ",xOffset ); 319 //qDebug("222draw pix %d ",xOffset );
328 320
329 } 321 }
330 322
331 } 323 }
332 pa.end(); 324 pa.end();
333 325
334 } 326 }
335} 327}
336 328
337void EventIndicator::setXOffset( int x ) 329void EventIndicator::setXOffset( int x )
338{ 330{
339 mXOffset = x; 331 mXOffset = x;
340} 332}
341void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w ) 333void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w )
342{ 334{
343 mPaintWidget = w; 335 mPaintWidget = w;
344 setMaximumHeight(0); 336 setMaximumHeight(0);
345 setMinimumHeight(0); 337 setMinimumHeight(0);
346} 338}
347void EventIndicator::changeColumns(int columns) 339void EventIndicator::changeColumns(int columns)
348{ 340{
349 mColumns = columns; 341 mColumns = columns;
350 mEnabled.resize(mColumns); 342 mEnabled.resize(mColumns);
351 343
352 update(); 344 update();
353} 345}
354 346
355void EventIndicator::enableColumn(int column, bool enable) 347void EventIndicator::enableColumn(int column, bool enable)
356{ 348{
357 mEnabled[column] = enable; 349 mEnabled[column] = enable;
358} 350}
359 351
360 352
361//////////////////////////////////////////////////////////////////////////// 353////////////////////////////////////////////////////////////////////////////
362//////////////////////////////////////////////////////////////////////////// 354////////////////////////////////////////////////////////////////////////////
363//////////////////////////////////////////////////////////////////////////// 355////////////////////////////////////////////////////////////////////////////
364 356
365KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) : 357KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) :
366 KOEventView (cal,parent,name) 358 KOEventView (cal,parent,name)
367{ 359{
368 mBlockUpdating = true; 360 mBlockUpdating = true;
369 mStartHour = 8; 361 mStartHour = 8;
370 mSelectedDates.append(QDate::currentDate()); 362 mSelectedDates.append(QDate::currentDate());
371 363
372 mLayoutDayLabels = 0; 364 mLayoutDayLabels = 0;
373 mDayLabelsFrame = 0; 365 mDayLabelsFrame = 0;
374 mDayLabels = 0; 366 mDayLabels = 0;
375 bool isRTL = KOGlobals::self()->reverseLayout(); 367 bool isRTL = KOGlobals::self()->reverseLayout();
376 368
377 if ( KOPrefs::instance()->mVerticalScreen ) { 369 if ( KOPrefs::instance()->mVerticalScreen ) {
378 mExpandedPixmap = SmallIcon( "1downarrow" ); 370 mExpandedPixmap = SmallIcon( "1downarrow" );
379 mNotExpandedPixmap = SmallIcon( "1uparrow" ); 371 mNotExpandedPixmap = SmallIcon( "1uparrow" );
380 } else { 372 } else {
381 mExpandedPixmap = SmallIcon( isRTL ? "1leftarrow" : "1rightarrow" ); 373 mExpandedPixmap = SmallIcon( isRTL ? "1leftarrow" : "1rightarrow" );
382 mNotExpandedPixmap = SmallIcon( isRTL ? "1rightarrow" : "1leftarrow" ); 374 mNotExpandedPixmap = SmallIcon( isRTL ? "1rightarrow" : "1leftarrow" );
383 } 375 }
384 376
385 QBoxLayout *topLayout = new QVBoxLayout(this); 377 QBoxLayout *topLayout = new QVBoxLayout(this);
386 378
387 // Create day name labels for agenda columns 379 // Create day name labels for agenda columns
388 // Create agenda splitter 380 // Create agenda splitter
389 381
390 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this); 382 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this);
391 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 383 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
392 topLayout->addWidget( mSplitterAgenda ); 384 topLayout->addWidget( mSplitterAgenda );
393 mAllDayFrame = new QHBox(mSplitterAgenda); 385 mAllDayFrame = new QHBox(mSplitterAgenda);
394 mAllDayFrame->setFocusPolicy(NoFocus); 386 mAllDayFrame->setFocusPolicy(NoFocus);
395 QWidget *agendaFrame = new QWidget(mSplitterAgenda); 387 QWidget *agendaFrame = new QWidget(mSplitterAgenda);
396 agendaFrame->setFocusPolicy(NoFocus); 388 agendaFrame->setFocusPolicy(NoFocus);
397 389
398 // Create all-day agenda widget 390 // Create all-day agenda widget
399 mDummyAllDayLeft = new QVBox( mAllDayFrame ); 391 mDummyAllDayLeft = new QVBox( mAllDayFrame );
400 392
401 mExpandButton = new QPushButton(mDummyAllDayLeft); 393 mExpandButton = new QPushButton(mDummyAllDayLeft);
402 mExpandButton->setPixmap( mNotExpandedPixmap ); 394 mExpandButton->setPixmap( mNotExpandedPixmap );
403 int widebut = mExpandButton->sizeHint().width(); 395 int widebut = mExpandButton->sizeHint().width();
404 if ( QApplication::desktop()->width() < 480 ) 396 if ( QApplication::desktop()->width() < 480 )
405 widebut = widebut*2; 397 widebut = widebut*2;
406 else 398 else
407 widebut = (widebut*3) / 2; 399 widebut = (widebut*3) / 2;
408 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, 400 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed,
409 // QSizePolicy::Fixed ) ); 401 // QSizePolicy::Fixed ) );
410 mExpandButton->setFixedSize( widebut, widebut); 402 mExpandButton->setFixedSize( widebut, widebut);
411 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) ); 403 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) );
412 mExpandButton->setFocusPolicy(NoFocus); 404 mExpandButton->setFocusPolicy(NoFocus);
413 mAllDayAgenda = new KOAgenda(1,mAllDayFrame); 405 mAllDayAgenda = new KOAgenda(1,mAllDayFrame);
414 mAllDayAgenda->setFocusPolicy(NoFocus); 406 mAllDayAgenda->setFocusPolicy(NoFocus);
415 QLabel *dummyAllDayRight = new QLabel (mAllDayFrame); 407 QLabel *dummyAllDayRight = new QLabel (mAllDayFrame);
416 408
417 // Create event context menu for all day agenda 409 // Create event context menu for all day agenda
418 mAllDayAgendaPopup = eventPopup(); 410 mAllDayAgendaPopup = eventPopup();
419 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), 411 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
420 mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *))); 412 mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
421 413
422 // Create agenda frame 414 // Create agenda frame
423 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,4,3); 415 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,4,3);
424 // QHBox *agendaFrame = new QHBox(splitterAgenda); 416 // QHBox *agendaFrame = new QHBox(splitterAgenda);
425 417
426 // create event indicator bars 418 // create event indicator bars
427 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame); 419 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame);
428#ifndef DESKTOP_VERSION 420#ifndef DESKTOP_VERSION
429 // FIX 421 // FIX
430 mEventIndicatorTop->setPaintWidget( mSplitterAgenda ); 422 mEventIndicatorTop->setPaintWidget( mSplitterAgenda );
431#endif 423#endif
432 mDayLabelsFrame = new QHBox(agendaFrame); 424 mDayLabelsFrame = new QHBox(agendaFrame);
433 //topLayout->addWidget(mDayLabelsFrame); 425 //topLayout->addWidget(mDayLabelsFrame);
434 mDayLabels = new QFrame (mDayLabelsFrame); 426 mDayLabels = new QFrame (mDayLabelsFrame);
435 mLayoutDayLabels = new QHBoxLayout(mDayLabels); 427 mLayoutDayLabels = new QHBoxLayout(mDayLabels);
436 agendaLayout->addMultiCellWidget(mDayLabelsFrame ,0,0,0,2); 428 agendaLayout->addMultiCellWidget(mDayLabelsFrame ,0,0,0,2);
437 agendaLayout->addWidget(mEventIndicatorTop,1,1); 429 agendaLayout->addWidget(mEventIndicatorTop,1,1);
438 430
439 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom, 431 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom,
440 agendaFrame); 432 agendaFrame);
441 agendaLayout->addWidget(mEventIndicatorBottom,3,1); 433 agendaLayout->addWidget(mEventIndicatorBottom,3,1);
442 QWidget *dummyAgendaRight = new QWidget(agendaFrame); 434 QWidget *dummyAgendaRight = new QWidget(agendaFrame);
443 agendaLayout->addWidget(dummyAgendaRight,1,2); 435 agendaLayout->addWidget(dummyAgendaRight,1,2);
444 436
445 // Create time labels 437 // Create time labels
446 mTimeLabels = new TimeLabels(24,agendaFrame); 438 mTimeLabels = new TimeLabels(24,agendaFrame);
447 agendaLayout->addWidget(mTimeLabels,2,0); 439 agendaLayout->addWidget(mTimeLabels,2,0);
448 connect(mTimeLabels,SIGNAL( scaleChanged()), 440 connect(mTimeLabels,SIGNAL( scaleChanged()),
449 this,SLOT(updateConfig())); 441 this,SLOT(updateConfig()));
450 442
451 // Create agenda 443 // Create agenda
452 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame); 444 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame);
453 agendaLayout->addMultiCellWidget(mAgenda,2,2,1,2); 445 agendaLayout->addMultiCellWidget(mAgenda,2,2,1,2);
454 agendaLayout->setColStretch(1,1); 446 agendaLayout->setColStretch(1,1);
455 mAgenda->setFocusPolicy(NoFocus); 447 mAgenda->setFocusPolicy(NoFocus);
456 // Create event context menu for agenda 448 // Create event context menu for agenda
457 mAgendaPopup = eventPopup(); 449 mAgendaPopup = eventPopup();
458 450
459 mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")), 451 mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")),
460 i18n("Toggle Alarm"),mAgenda, 452 i18n("Toggle Alarm"),mAgenda,
461 SLOT(popupAlarm()),true); 453 SLOT(popupAlarm()),true);
462 454
463 455
464 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), 456 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
465 mAgendaPopup,SLOT(showIncidencePopup(Incidence *))); 457 mAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
466 458
467 // make connections between dependent widgets 459 // make connections between dependent widgets
468 mTimeLabels->setAgenda(mAgenda); 460 mTimeLabels->setAgenda(mAgenda);
469 461
470 // Update widgets to reflect user preferences 462 // Update widgets to reflect user preferences
471 // updateConfig(); 463 // updateConfig();
472 464
473 // createDayLabels(); 465 // createDayLabels();
474 466
475 // these blank widgets make the All Day Event box line up with the agenda 467 // these blank widgets make the All Day Event box line up with the agenda
476 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 468 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
477 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 469 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
478 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 470 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
479 471
480 // Scrolling 472 // Scrolling
481 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)), 473 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)),
482 mTimeLabels, SLOT(positionChanged())); 474 mTimeLabels, SLOT(positionChanged()));
483 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)), 475 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)),
484 SLOT(setContentsPos(int))); 476 SLOT(setContentsPos(int)));
485 477
486 connect(mAgenda,SIGNAL(showDateView( int, QDate )),SIGNAL(showDateView( int, QDate ))); 478 connect(mAgenda,SIGNAL(showDateView( int, QDate )),SIGNAL(showDateView( int, QDate )));
487 connect(mAllDayAgenda,SIGNAL(showDateView( int, QDate )),SIGNAL(showDateView( int, QDate ))); 479 connect(mAllDayAgenda,SIGNAL(showDateView( int, QDate )),SIGNAL(showDateView( int, QDate )));
488 480
489 // Create/Show/Edit/Delete Event 481 // Create/Show/Edit/Delete Event
490 connect(mAgenda,SIGNAL(newEventSignal(int,int)), 482 connect(mAgenda,SIGNAL(newEventSignal(int,int)),
491 SLOT(newEvent(int,int))); 483 SLOT(newEvent(int,int)));
492 connect(mAgenda,SIGNAL(newTodoSignal(int,int)), 484 connect(mAgenda,SIGNAL(newTodoSignal(int,int)),
493 SLOT(newTodo(int,int))); 485 SLOT(newTodo(int,int)));
494 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)), 486 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)),
495 SLOT(newEvent(int,int,int,int))); 487 SLOT(newEvent(int,int,int,int)));
496 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)), 488 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)),
497 SLOT(newEventAllDay(int,int))); 489 SLOT(newEventAllDay(int,int)));
498 connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)), 490 connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)),
499 SLOT(newTodoAllDay(int,int))); 491 SLOT(newTodoAllDay(int,int)));
500 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)), 492 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)),
501 SLOT(newEventAllDay(int,int))); 493 SLOT(newEventAllDay(int,int)));
502 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 494 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
503 SLOT(newTimeSpanSelected(int,int,int,int))); 495 SLOT(newTimeSpanSelected(int,int,int,int)));
504 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 496 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
505 SLOT(newTimeSpanSelectedAllDay(int,int,int,int))); 497 SLOT(newTimeSpanSelectedAllDay(int,int,int,int)));
506 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 498 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
507 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 499 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
508 500
509 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 501 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
510 SIGNAL(editIncidenceSignal(Incidence *))); 502 SIGNAL(editIncidenceSignal(Incidence *)));
511 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 503 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
512 SIGNAL(editIncidenceSignal(Incidence *))); 504 SIGNAL(editIncidenceSignal(Incidence *)));
513 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 505 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
514 SIGNAL(showIncidenceSignal(Incidence *))); 506 SIGNAL(showIncidenceSignal(Incidence *)));
515 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 507 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
516 SIGNAL(showIncidenceSignal(Incidence *))); 508 SIGNAL(showIncidenceSignal(Incidence *)));
517 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 509 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
518 SIGNAL(deleteIncidenceSignal(Incidence *))); 510 SIGNAL(deleteIncidenceSignal(Incidence *)));
519 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 511 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
520 SIGNAL(deleteIncidenceSignal(Incidence *))); 512 SIGNAL(deleteIncidenceSignal(Incidence *)));
521 513
522 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 514 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
523 SLOT(updateEventDates(KOAgendaItem *, int ))); 515 SLOT(updateEventDates(KOAgendaItem *, int )));
524 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 516 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
525 SLOT(updateEventDates(KOAgendaItem *, int))); 517 SLOT(updateEventDates(KOAgendaItem *, int)));
526 518
527 // event indicator update 519 // event indicator update
528 connect(mAgenda,SIGNAL(lowerYChanged(int)), 520 connect(mAgenda,SIGNAL(lowerYChanged(int)),
529 SLOT(updateEventIndicatorTop(int))); 521 SLOT(updateEventIndicatorTop(int)));
530 connect(mAgenda,SIGNAL(upperYChanged(int)), 522 connect(mAgenda,SIGNAL(upperYChanged(int)),
531 SLOT(updateEventIndicatorBottom(int))); 523 SLOT(updateEventIndicatorBottom(int)));
532 // drag signals 524 // drag signals
533 /* 525 /*
534 connect(mAgenda,SIGNAL(startDragSignal(Event *)), 526 connect(mAgenda,SIGNAL(startDragSignal(Event *)),
535 SLOT(startDrag(Event *))); 527 SLOT(startDrag(Event *)));
536 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)), 528 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)),
537 SLOT(startDrag(Event *))); 529 SLOT(startDrag(Event *)));
538 */ 530 */
539 // synchronize selections 531 // synchronize selections
540 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 532 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
541 mAllDayAgenda, SLOT( deselectItem() ) ); 533 mAllDayAgenda, SLOT( deselectItem() ) );
542 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 534 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
543 mAgenda, SLOT( deselectItem() ) ); 535 mAgenda, SLOT( deselectItem() ) );
544 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 536 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
545 SIGNAL( incidenceSelected( Incidence * ) ) ); 537 SIGNAL( incidenceSelected( Incidence * ) ) );
546 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 538 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
547 SIGNAL( incidenceSelected( Incidence * ) ) ); 539 SIGNAL( incidenceSelected( Incidence * ) ) );
548 connect( mAgenda, SIGNAL( resizedSignal() ), 540 connect( mAgenda, SIGNAL( resizedSignal() ),
549 SLOT( updateConfig( ) ) ); 541 SLOT( updateConfig( ) ) );
550 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ), 542 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ),
551 SLOT( addToCalSlot(Incidence *, Incidence * ) ) ); 543 SLOT( addToCalSlot(Incidence *, Incidence * ) ) );
552 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ), 544 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ),
553 SLOT( addToCalSlot(Incidence * , Incidence *) ) ); 545 SLOT( addToCalSlot(Incidence * , Incidence *) ) );
554 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 546 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
555 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 547 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
556 548
557 549
558} 550}
559 551
560void KOAgendaView::toggleAllDay() 552void KOAgendaView::toggleAllDay()
561{ 553{
562 if ( mSplitterAgenda->firstHandle() ) 554 if ( mSplitterAgenda->firstHandle() )
563 mSplitterAgenda->firstHandle()->toggle(); 555 mSplitterAgenda->firstHandle()->toggle();
564} 556}
565void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld ) 557void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld )
566{ 558{
567 calendar()->addIncidence( inc ); 559 calendar()->addIncidence( inc );
568 560
569 if ( incOld ) { 561 if ( incOld ) {
570 if ( incOld->type() == "Todo" ) 562 if ( incOld->type() == "Todo" )
571 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED ); 563 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED );
572 else 564 else
573 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED); 565 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED);
574 } 566 }
575 567
576} 568}
577 569
578KOAgendaView::~KOAgendaView() 570KOAgendaView::~KOAgendaView()
579{ 571{
580 delete mAgendaPopup; 572 delete mAgendaPopup;
581 delete mAllDayAgendaPopup; 573 delete mAllDayAgendaPopup;
582 delete KOAgendaItem::paintPix(); 574 delete KOAgendaItem::paintPix();
583 delete KOAgendaItem::paintPixSel(); 575 delete KOAgendaItem::paintPixSel();
584} 576}
585void KOAgendaView::resizeEvent( QResizeEvent* e ) 577void KOAgendaView::resizeEvent( QResizeEvent* e )
586{ 578{
587 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); 579 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width());
588 bool uc = false; 580 bool uc = false;
589 int ow = e->oldSize().width(); 581 int ow = e->oldSize().width();
590 int oh = e->oldSize().height(); 582 int oh = e->oldSize().height();
591 int w = e->size().width(); 583 int w = e->size().width();
592 int h = e->size().height(); 584 int h = e->size().height();
593 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { 585 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) {
594 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) 586 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda )
595 uc = true; 587 uc = true;
596 //qDebug("view changed %d %d %d %d ", ow, oh , w , h); 588 //qDebug("view changed %d %d %d %d ", ow, oh , w , h);
597 } 589 }
598 mUpcomingWidth = e->size().width() ; 590 mUpcomingWidth = e->size().width() ;
599 if ( mBlockUpdating || uc ) { 591 if ( mBlockUpdating || uc ) {
600 mBlockUpdating = false; 592 mBlockUpdating = false;
601 //mAgenda->setMinimumSize(800 , 600 ); 593 //mAgenda->setMinimumSize(800 , 600 );
602 //qDebug("mAgenda->resize+++++++++++++++ "); 594 //qDebug("mAgenda->resize+++++++++++++++ ");
603 updateConfig(); 595 updateConfig();
604 //qDebug("KOAgendaView::Updating now possible "); 596 //qDebug("KOAgendaView::Updating now possible ");
605 } else 597 } else
606 createDayLabels(); 598 createDayLabels();
607 //qDebug("resizeEvent end "); 599 //qDebug("resizeEvent end ");
608 600
609} 601}
610void KOAgendaView::slotDaylabelClicked( int num ) 602void KOAgendaView::slotDaylabelClicked( int num )
611{ 603{
612 604
613 QDate firstDate = mSelectedDates.first(); 605 QDate firstDate = mSelectedDates.first();
614 if ( num == -1 ) 606 if ( num == -1 )
615 emit showDateView( 6, firstDate ); 607 emit showDateView( 6, firstDate );
616 else if (num >= 0 ) { 608 else if (num >= 0 ) {
617 if ( mSelectedDates.count() == 1) 609 if ( mSelectedDates.count() == 1)
618 emit showDateView( 9, firstDate.addDays( num ) ); 610 emit showDateView( 9, firstDate.addDays( num ) );
619 else 611 else
620 emit showDateView( 3, firstDate.addDays( num ) ); 612 emit showDateView( 3, firstDate.addDays( num ) );
621 } 613 }
622 else 614 else
623 showDateView( 10, firstDate.addDays(1) ); 615 showDateView( 10, firstDate.addDays(1) );
624} 616}
625 617
626KOAgendaButton* KOAgendaView::getNewDaylabel() 618KOAgendaButton* KOAgendaView::getNewDaylabel()
627{ 619{
628 620
629 KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels); 621 KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels);
630 connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) ); 622 connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) );
631 mDayLabelsList.append( dayLabel ); 623 mDayLabelsList.append( dayLabel );
632 mLayoutDayLabels->addWidget(dayLabel); 624 mLayoutDayLabels->addWidget(dayLabel);
633 return dayLabel ; 625 return dayLabel ;
634} 626}
635 627
636void KOAgendaView::createDayLabels() 628void KOAgendaView::createDayLabels()
637{ 629{
638 630
639 if ( mBlockUpdating || globalFlagBlockLabel == 1) { 631 if ( mBlockUpdating || globalFlagBlockLabel == 1) {
640 // qDebug(" KOAgendaView::createDayLabels() blocked "); 632 // qDebug(" KOAgendaView::createDayLabels() blocked ");
641 return; 633 return;
642 634
643 } 635 }
644 int newHight; 636 int newHight;
645 637
646 // ### Before deleting and recreating we could check if mSelectedDates changed... 638 // ### Before deleting and recreating we could check if mSelectedDates changed...
647 // It would remove some flickering and gain speed (since this is called by 639 // It would remove some flickering and gain speed (since this is called by
648 // each updateView() call) 640 // each updateView() call)
649 641
650 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - 2; 642 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - 2;
651 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); 643 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth );
652 if ( maxWid < 0 ) 644 if ( maxWid < 0 )
653 maxWid = 20; 645 maxWid = 20;
654 646
655 QFont dlf = KOPrefs::instance()->mTimeLabelsFont; 647 QFont dlf = KOPrefs::instance()->mTimeLabelsFont;
656 QFontMetrics fm ( dlf ); 648 QFontMetrics fm ( dlf );
657 int selCount = mSelectedDates.count(); 649 int selCount = mSelectedDates.count();
658 QString dayTest = "Mon 20"; 650 QString dayTest = "Mon 20";
659 //QString dayTest = "Mon 20"; 651 //QString dayTest = "Mon 20";
660 int wid = fm.width( dayTest ); 652 int wid = fm.width( dayTest );
661 //maxWid -= ( selCount * 3 ); //working for QLabels 653 //maxWid -= ( selCount * 3 ); //working for QLabels
662 maxWid -= ( selCount * 3 ); //working for QPushButton 654 maxWid -= ( selCount * 3 ); //working for QPushButton
663 if ( maxWid < 0 ) 655 if ( maxWid < 0 )
664 maxWid = 20; 656 maxWid = 20;
665 int needWid = wid * selCount; 657 int needWid = wid * selCount;
666 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); 658 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid );
667 //if ( needWid > maxWid ) 659 //if ( needWid > maxWid )
668 // qDebug("DAYLABELS TOOOOOOO BIG "); 660 // qDebug("DAYLABELS TOOOOOOO BIG ");
669 while ( needWid > maxWid ) { 661 while ( needWid > maxWid ) {
670 dayTest = dayTest.left( dayTest.length() - 1 ); 662 dayTest = dayTest.left( dayTest.length() - 1 );
671 wid = fm.width( dayTest ); 663 wid = fm.width( dayTest );
672 needWid = wid * selCount; 664 needWid = wid * selCount;
673 } 665 }
674 int maxLen = dayTest.length(); 666 int maxLen = dayTest.length();
675 int fontPoint = dlf.pointSize(); 667 int fontPoint = dlf.pointSize();
676 if ( maxLen < 2 ) { 668 if ( maxLen < 2 ) {
677 int fontPoint = dlf.pointSize(); 669 int fontPoint = dlf.pointSize();
678 while ( fontPoint > 4 ) { 670 while ( fontPoint > 4 ) {
679 --fontPoint; 671 --fontPoint;
680 dlf.setPointSize( fontPoint ); 672 dlf.setPointSize( fontPoint );
681 QFontMetrics f( dlf ); 673 QFontMetrics f( dlf );
682 wid = f.width( "30" ); 674 wid = f.width( "30" );
683 needWid = wid * selCount; 675 needWid = wid * selCount;
684 if ( needWid < maxWid ) 676 if ( needWid < maxWid )
685 break; 677 break;
686 } 678 }
687 maxLen = 2; 679 maxLen = 2;
688 } 680 }
689 //qDebug("Max len %d ", dayTest.length() ); 681 //qDebug("Max len %d ", dayTest.length() );
690 682
691 QFontMetrics tempF( dlf ); 683 QFontMetrics tempF( dlf );
692 newHight = tempF.height(); 684 newHight = tempF.height();
693 mDayLabels->setFont( dlf ); 685 mDayLabels->setFont( dlf );
694 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; 686 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);;
695 // mLayoutDayLabels->addSpacing(mTimeLabels->width()); 687 // mLayoutDayLabels->addSpacing(mTimeLabels->width());
696 //mLayoutDayLabels->addSpacing( 2 ); 688 //mLayoutDayLabels->addSpacing( 2 );
697 // QFont lFont = dlf; 689 // QFont lFont = dlf;
698 bool appendLabels = false; 690 bool appendLabels = false;
699 KOAgendaButton *dayLabel; 691 KOAgendaButton *dayLabel;
700 dayLabel = mDayLabelsList.first(); 692 dayLabel = mDayLabelsList.first();
701 if ( !dayLabel ) { 693 if ( !dayLabel ) {
702 appendLabels = true; 694 appendLabels = true;
703 dayLabel = getNewDaylabel(); 695 dayLabel = getNewDaylabel();
704 } 696 }
705 dayLabel->setFixedWidth( mTimeLabels->width()+2 ); 697 dayLabel->setFixedWidth( mTimeLabels->width()+2 );
706 dayLabel->setFont( dlf ); 698 dayLabel->setFont( dlf );
707 dayLabel->setNum( -1 ); 699 dayLabel->setNum( -1 );
708 //dayLabel->setAlignment(QLabel::AlignHCenter); 700 //dayLabel->setAlignment(QLabel::AlignHCenter);
709 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); 701 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) );
710 dayLabel->show(); 702 dayLabel->show();
711 DateList::ConstIterator dit; 703 DateList::ConstIterator dit;
712 bool oneday = (mSelectedDates.first() == mSelectedDates.last() ); 704 bool oneday = (mSelectedDates.first() == mSelectedDates.last() );
713 int counter = -1; 705 int counter = -1;
714 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 706 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
715 ++counter; 707 ++counter;
716 QDate date = *dit; 708 QDate date = *dit;
717 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); 709 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels);
718 if ( ! appendLabels ) { 710 if ( ! appendLabels ) {
719 dayLabel = mDayLabelsList.next(); 711 dayLabel = mDayLabelsList.next();
720 if ( !dayLabel ) 712 if ( !dayLabel )
721 appendLabels = true; 713 appendLabels = true;
722 } 714 }
723 if ( appendLabels ) { 715 if ( appendLabels ) {
724 dayLabel = getNewDaylabel(); 716 dayLabel = getNewDaylabel();
725 } 717 }
726 dayLabel->setMinimumWidth( 1 ); 718 dayLabel->setMinimumWidth( 1 );
727 dayLabel->setMaximumWidth( 10240 ); 719 dayLabel->setMaximumWidth( 10240 );
728 dayLabel->setFont( dlf ); 720 dayLabel->setFont( dlf );
729 dayLabel->show(); 721 dayLabel->show();
730 dayLabel->setNum( counter ); 722 dayLabel->setNum( counter );
731 QString str; 723 QString str;
732 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date); 724 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date);
733 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true ); 725 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true );
734 switch ( maxLen ) { 726 switch ( maxLen ) {
735 case 2: 727 case 2:
736 str = QString::number( date.day() ); 728 str = QString::number( date.day() );
737 break; 729 break;
738 730
739 case 3: 731 case 3:
740 str = dayName.left( 1 ) +QString::number( date.day()); 732 str = dayName.left( 1 ) +QString::number( date.day());
741 733
742 break; 734 break;
743 case 4: 735 case 4:
744 str = dayName.left( 1 ) + " " +QString::number( date.day()); 736 str = dayName.left( 1 ) + " " +QString::number( date.day());
745 737
746 break; 738 break;
747 case 5: 739 case 5:
748 str = dayName.left( 2 ) + " " +QString::number( date.day()); 740 str = dayName.left( 2 ) + " " +QString::number( date.day());
749 741
750 break; 742 break;
751 case 6: 743 case 6:
752 str = dayName.left( 3 ) + " " +QString::number( date.day()); 744 str = dayName.left( 3 ) + " " +QString::number( date.day());
753 break; 745 break;
754 746
755 default: 747 default:
756 break; 748 break;
757 } 749 }
758 if ( oneday ) { 750 if ( oneday ) {
759 QString addString; 751 QString addString;
760 if ( mSelectedDates.first() == QDateTime::currentDateTime().date() ) 752 if ( mSelectedDates.first() == QDateTime::currentDateTime().date() )
761 addString = i18n("Today"); 753 addString = i18n("Today");
762 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) 754 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) )
763 addString = i18n("Tomorrow"); 755 addString = i18n("Tomorrow");
764 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) 756 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) )
765 addString = i18n("Yesterday"); 757 addString = i18n("Yesterday");
766 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) 758 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) )
767 addString = i18n("Day before yesterday"); 759 addString = i18n("Day before yesterday");
768 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) 760 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) )
769 addString = i18n("Day after tomorrow"); 761 addString = i18n("Day after tomorrow");
770 if ( !addString.isEmpty() ) { 762 if ( !addString.isEmpty() ) {
771 str = addString+", " + str; 763 str = addString+", " + str;
772 } 764 }
773 } 765 }
774 dayLabel->setText(str); 766 dayLabel->setText(str);
775 //dayLabel->setAlignment(QLabel::AlignHCenter); 767 //dayLabel->setAlignment(QLabel::AlignHCenter);
776 if (date == QDate::currentDate()) { 768 if (date == QDate::currentDate()) {
777 QFont bFont = dlf; 769 QFont bFont = dlf;
778 bFont.setBold( true ); 770 bFont.setBold( true );
779 dayLabel->setFont(bFont); 771 dayLabel->setFont(bFont);
780 } 772 }
781 //dayLayout->addWidget(dayLabel); 773 //dayLayout->addWidget(dayLabel);
782 774
783#ifndef KORG_NOPLUGINS 775#ifndef KORG_NOPLUGINS
784 CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); 776 CalendarDecoration::List cds = KOCore::self()->calendarDecorations();
785 CalendarDecoration *it; 777 CalendarDecoration *it;
786 for(it = cds.first(); it; it = cds.next()) { 778 for(it = cds.first(); it; it = cds.next()) {
787 QString text = it->shortText( date ); 779 QString text = it->shortText( date );
788 if ( !text.isEmpty() ) { 780 if ( !text.isEmpty() ) {
789 QLabel *label = new QLabel(text,mDayLabels); 781 QLabel *label = new QLabel(text,mDayLabels);
790 label->setAlignment(AlignCenter); 782 label->setAlignment(AlignCenter);
791 dayLayout->addWidget(label); 783 dayLayout->addWidget(label);
792 } 784 }
793 } 785 }
794 786
795 for(it = cds.first(); it; it = cds.next()) { 787 for(it = cds.first(); it; it = cds.next()) {
796 QWidget *wid = it->smallWidget(mDayLabels,date); 788 QWidget *wid = it->smallWidget(mDayLabels,date);
797 if ( wid ) { 789 if ( wid ) {
798 // wid->setHeight(20); 790 // wid->setHeight(20);
799 dayLayout->addWidget(wid); 791 dayLayout->addWidget(wid);
800 } 792 }
801 } 793 }
802#endif 794#endif
803 } 795 }
804 if ( ! appendLabels ) { 796 if ( ! appendLabels ) {
805 dayLabel = mDayLabelsList.next(); 797 dayLabel = mDayLabelsList.next();
806 if ( !dayLabel ) 798 if ( !dayLabel )
807 appendLabels = true; 799 appendLabels = true;
808 } 800 }
809 if ( appendLabels ) { 801 if ( appendLabels ) {
810 dayLabel = getNewDaylabel(); 802 dayLabel = getNewDaylabel();
811 } 803 }
812 //dayLabel->hide();//test only 804 //dayLabel->hide();//test only
813 805
814 int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()-3 ) % mSelectedDates.count() ; 806 int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()-3 ) % mSelectedDates.count() ;
815 if ( offset < 0 ) offset = 0; 807 if ( offset < 0 ) offset = 0;
816 //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 ); 808 //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 );
817 dayLabel->setText(">");//QString::number ( mSelectedDates.first().month() ) ); 809 dayLabel->setText(">");//QString::number ( mSelectedDates.first().month() ) );
818 dayLabel->setFont( dlf ); 810 dayLabel->setFont( dlf );
819 dayLabel->show(); 811 dayLabel->show();
820 dayLabel->setNum( -2 ); 812 dayLabel->setNum( -2 );
821 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset ); 813 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset );
822 //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2); 814 //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2);
823 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); 815 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2);
824 if ( !appendLabels ) { 816 if ( !appendLabels ) {
825 dayLabel = mDayLabelsList.next(); 817 dayLabel = mDayLabelsList.next();
826 while ( dayLabel ) { 818 while ( dayLabel ) {
827 //qDebug("!dayLabel %d",dayLabel ); 819 //qDebug("!dayLabel %d",dayLabel );
828 dayLabel->hide(); 820 dayLabel->hide();
829 dayLabel = mDayLabelsList.next(); 821 dayLabel = mDayLabelsList.next();
830 } 822 }
831 } 823 }
832 //mDayLabelsFrame->show(); 824 //mDayLabelsFrame->show();
833 //mDayLabels->show(); 825 //mDayLabels->show();
834 //qDebug("heigt %d %d %d ",mDayLabelsFrame->height(), mDayLabelsFrame->sizeHint().height(), newHight); 826 //qDebug("heigt %d %d %d ",mDayLabelsFrame->height(), mDayLabelsFrame->sizeHint().height(), newHight);
835 //mDayLabelsFrame->resize( mAgenda->visibleWidth(), newHight ); 827 //mDayLabelsFrame->resize( mAgenda->visibleWidth(), newHight );
836 mDayLabelsFrame->setFixedHeight( newHight ); 828 mDayLabelsFrame->setFixedHeight( newHight );
837} 829}
838 830
839int KOAgendaView::maxDatesHint() 831int KOAgendaView::maxDatesHint()
840{ 832{
841 // Not sure about the max number of events, so return 0 for now. 833 // Not sure about the max number of events, so return 0 for now.
842 return 0; 834 return 0;
843} 835}
844 836
845int KOAgendaView::currentDateCount() 837int KOAgendaView::currentDateCount()
846{ 838{
847 return mSelectedDates.count(); 839 return mSelectedDates.count();
848} 840}
849 841
850QPtrList<Incidence> KOAgendaView::selectedIncidences() 842QPtrList<Incidence> KOAgendaView::selectedIncidences()
851{ 843{
852 QPtrList<Incidence> selected; 844 QPtrList<Incidence> selected;
853 Incidence *incidence; 845 Incidence *incidence;
854 846
855 incidence = mAgenda->selectedIncidence(); 847 incidence = mAgenda->selectedIncidence();
856 if (incidence) selected.append(incidence); 848 if (incidence) selected.append(incidence);
857 849
858 incidence = mAllDayAgenda->selectedIncidence(); 850 incidence = mAllDayAgenda->selectedIncidence();
859 if (incidence) selected.append(incidence); 851 if (incidence) selected.append(incidence);
860 852
861 return selected; 853 return selected;
862} 854}
863 855
864DateList KOAgendaView::selectedDates() 856DateList KOAgendaView::selectedDates()
865{ 857{
866 DateList selected; 858 DateList selected;
867 QDate qd; 859 QDate qd;
868 860
869 qd = mAgenda->selectedIncidenceDate(); 861 qd = mAgenda->selectedIncidenceDate();
870 if (qd.isValid()) selected.append(qd); 862 if (qd.isValid()) selected.append(qd);
871 863
872 qd = mAllDayAgenda->selectedIncidenceDate(); 864 qd = mAllDayAgenda->selectedIncidenceDate();
873 if (qd.isValid()) selected.append(qd); 865 if (qd.isValid()) selected.append(qd);
874 866
875 return selected; 867 return selected;
876} 868}
877 869
878 870
879void KOAgendaView::updateView() 871void KOAgendaView::updateView()
880{ 872{
881 if ( mBlockUpdating ) 873 if ( mBlockUpdating )
882 return; 874 return;
883 // kdDebug() << "KOAgendaView::updateView()" << endl; 875 // kdDebug() << "KOAgendaView::updateView()" << endl;
884 fillAgenda(); 876 fillAgenda();
885 877
886} 878}
887 879
888 880
889/* 881/*
890 Update configuration settings for the agenda view. This method is not 882 Update configuration settings for the agenda view. This method is not
891 complete. 883 complete.
892*/ 884*/
893void KOAgendaView::updateConfig() 885void KOAgendaView::updateConfig()
894{ 886{
895 if ( mBlockUpdating ) 887 if ( mBlockUpdating )
896 return; 888 return;
897 889
898 // update config for children 890 // update config for children
899 mTimeLabels->updateConfig(); 891 mTimeLabels->updateConfig();
900 mAgenda->storePosition(); 892 mAgenda->storePosition();
901 mAgenda->updateConfig(); 893 mAgenda->updateConfig();
902 mAllDayAgenda->updateConfig(); 894 mAllDayAgenda->updateConfig();
903 // widget synchronization 895 // widget synchronization
904 //TODO: find a better way, maybe signal/slot 896 //TODO: find a better way, maybe signal/slot
905 mTimeLabels->positionChanged(); 897 mTimeLabels->positionChanged();
906 898
907 // for some reason, this needs to be called explicitly 899 // for some reason, this needs to be called explicitly
908 mTimeLabels->repaint(); 900 mTimeLabels->repaint();
909 901
910 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 902 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
911 903
912 // ToolTips displaying summary of events 904 // ToolTips displaying summary of events
913 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance() 905 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance()
914 ->mEnableToolTips); 906 ->mEnableToolTips);
915 907
916 //setHolidayMasks(); 908 //setHolidayMasks();
917 909
918 //createDayLabels(); called by via updateView(); 910 //createDayLabels(); called by via updateView();
919 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth()); 911 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth());
920 updateView(); 912 updateView();
921 mAgenda->restorePosition(); 913 mAgenda->restorePosition();
922} 914}
923 915
924 916
925void KOAgendaView::updateEventDates(KOAgendaItem *item, int type) 917void KOAgendaView::updateEventDates(KOAgendaItem *item, int type)
926{ 918{
927 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl; 919 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl;
928 //qDebug("KOAgendaView::updateEventDates "); 920 //qDebug("KOAgendaView::updateEventDates ");
929 QDateTime startDt,endDt; 921 QDateTime startDt,endDt;
930 QDate startDate; 922 QDate startDate;
931 int lenInSecs; 923 int lenInSecs;
932 // if ( type == KOAgenda::RESIZETOP ) 924 // if ( type == KOAgenda::RESIZETOP )
933 // qDebug("RESIZETOP "); 925 // qDebug("RESIZETOP ");
934 // if ( type == KOAgenda::RESIZEBOTTOM ) 926 // if ( type == KOAgenda::RESIZEBOTTOM )
935 // qDebug("RESIZEBOTTOM "); 927 // qDebug("RESIZEBOTTOM ");
936 // if ( type == KOAgenda::MOVE ) 928 // if ( type == KOAgenda::MOVE )
937 // qDebug("MOVE "); 929 // qDebug("MOVE ");
938 if ( item->incidence()->type() == "Event" ) { 930 if ( item->incidence()->type() == "Event" ) {
939 startDt =item->incidence()->dtStart(); 931 startDt =item->incidence()->dtStart();
940 endDt = item->incidence()->dtEnd(); 932 endDt = item->incidence()->dtEnd();
941 lenInSecs = startDt.secsTo( endDt ); 933 lenInSecs = startDt.secsTo( endDt );
942 } 934 }
943 935
944 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED ); 936 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED );
945 937
946 if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) { 938 if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) {
947 startDate = mSelectedDates[item->mLastMoveXPos]; 939 startDate = mSelectedDates[item->mLastMoveXPos];
948 } else { 940 } else {
949 if (item->cellX() < 0) { 941 if (item->cellX() < 0) {
950 startDate = (mSelectedDates.first()).addDays(item->cellX()); 942 startDate = (mSelectedDates.first()).addDays(item->cellX());
951 } else { 943 } else {
952 startDate = mSelectedDates[item->cellX()]; 944 startDate = mSelectedDates[item->cellX()];
953 } 945 }
954 } 946 }
955 startDt.setDate(startDate); 947 startDt.setDate(startDate);
956 948
957 if (item->incidence()->doesFloat()) { 949 if (item->incidence()->doesFloat()) {
958 endDt.setDate(startDate.addDays(item->cellWidth() - 1)); 950 endDt.setDate(startDate.addDays(item->cellWidth() - 1));
959 } else { 951 } else {
960 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE ) 952 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE )
961 startDt.setTime(mAgenda->gyToTime(item->cellYTop())); 953 startDt.setTime(mAgenda->gyToTime(item->cellYTop()));
962 if ( item->incidence()->type() == "Event" ) { 954 if ( item->incidence()->type() == "Event" ) {
963 if ( type == KOAgenda::MOVE ) { 955 if ( type == KOAgenda::MOVE ) {
964 endDt = startDt.addSecs(lenInSecs); 956 endDt = startDt.addSecs(lenInSecs);
965 957
966 } else if ( type == KOAgenda::RESIZEBOTTOM ) { 958 } else if ( type == KOAgenda::RESIZEBOTTOM ) {
967 if (item->lastMultiItem()) { 959 if (item->lastMultiItem()) {
968 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 960 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
969 endDt.setDate(startDate. 961 endDt.setDate(startDate.
970 addDays(item->lastMultiItem()->cellX() - item->cellX())); 962 addDays(item->lastMultiItem()->cellX() - item->cellX()));
971 } else { 963 } else {
972 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 964 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
973 endDt.setDate(startDate); 965 endDt.setDate(startDate);
974 } 966 }
975 } 967 }
976 } else { 968 } else {
977 // todo 969 // todo
978 if (item->lastMultiItem()) { 970 if (item->lastMultiItem()) {
979 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 971 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
980 endDt.setDate(startDate. 972 endDt.setDate(startDate.
981 addDays(item->lastMultiItem()->cellX() - item->cellX())); 973 addDays(item->lastMultiItem()->cellX() - item->cellX()));
982 } else { 974 } else {
983 //qDebug("tem->cellYBottom() %d",item->cellYBottom() ); 975 //qDebug("tem->cellYBottom() %d",item->cellYBottom() );
984 if ( item->cellYBottom() > 0 ) 976 if ( item->cellYBottom() > 0 )
985 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 977 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
986 else 978 else
987 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time()); 979 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time());
988 endDt.setDate(startDate); 980 endDt.setDate(startDate);
989 } 981 }
990 } 982 }
991 } 983 }
992 if ( item->incidence()->type() == "Event" ) { 984 if ( item->incidence()->type() == "Event" ) {
993 item->incidence()->setDtStart(startDt); 985 item->incidence()->setDtStart(startDt);
994 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt); 986 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt);
995 } else if ( item->incidence()->type() == "Todo" ) { 987 } else if ( item->incidence()->type() == "Todo" ) {
996 Todo* to = static_cast<Todo*>(item->incidence()); 988 Todo* to = static_cast<Todo*>(item->incidence());
997 989
998 to->setDtDue(endDt); 990 to->setDtDue(endDt);
999 if ( to->hasStartDate() ) { 991 if ( to->hasStartDate() ) {
1000 if (to->dtStart() >= to->dtDue() ) 992 if (to->dtStart() >= to->dtDue() )
1001 to->setDtStart(to->dtDue().addDays( -2 )); 993 to->setDtStart(to->dtDue().addDays( -2 ));
1002 } 994 }
1003 995
1004 } 996 }
1005 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() ); 997 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() );
1006 item->incidence()->setRevision(item->incidence()->revision()+1); 998 item->incidence()->setRevision(item->incidence()->revision()+1);
1007 item->setItemDate(startDt.date()); 999 item->setItemDate(startDt.date());
1008 //item->updateItem(); 1000 //item->updateItem();
1009 if ( item->incidence()->type() == "Todo" ) { 1001 if ( item->incidence()->type() == "Todo" ) {
1010 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED ); 1002 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED );
1011 1003
1012 } 1004 }
1013 else 1005 else
1014 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED); 1006 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED);
1015 item->updateItem(); 1007 item->updateItem();
1016} 1008}
1017 1009
1018void KOAgendaView::showDates( const QDate &start, const QDate &end ) 1010void KOAgendaView::showDates( const QDate &start, const QDate &end )
1019{ 1011{
1020 // kdDebug() << "KOAgendaView::selectDates" << endl; 1012 // kdDebug() << "KOAgendaView::selectDates" << endl;
1021 1013
1022 mSelectedDates.clear(); 1014 mSelectedDates.clear();
1023 // qDebug("KOAgendaView::showDates "); 1015 // qDebug("KOAgendaView::showDates ");
1024 QDate d = start; 1016 QDate d = start;
1025 while (d <= end) { 1017 while (d <= end) {
1026 mSelectedDates.append(d); 1018 mSelectedDates.append(d);
1027 d = d.addDays( 1 ); 1019 d = d.addDays( 1 );
1028 } 1020 }
1029 1021
1030 // and update the view 1022 // and update the view
1031 fillAgenda(); 1023 fillAgenda();
1032} 1024}
1033 1025
1034 1026
1035void KOAgendaView::showEvents(QPtrList<Event>) 1027void KOAgendaView::showEvents(QPtrList<Event>)
1036{ 1028{
1037 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl; 1029 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl;
1038} 1030}
1039 1031
1040void KOAgendaView::changeEventDisplay(Event *, int) 1032void KOAgendaView::changeEventDisplay(Event *, int)
1041{ 1033{
1042 // qDebug("KOAgendaView::changeEventDisplay "); 1034 // qDebug("KOAgendaView::changeEventDisplay ");
1043 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl; 1035 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl;
1044 // this should be re-written to be MUCH smarter. Right now we 1036 // this should be re-written to be MUCH smarter. Right now we
1045 // are just playing dumb. 1037 // are just playing dumb.
1046 fillAgenda(); 1038 fillAgenda();
1047} 1039}
1048 1040
1049void KOAgendaView::fillAgenda(const QDate &) 1041void KOAgendaView::fillAgenda(const QDate &)
1050{ 1042{
1051 // qDebug("KOAgendaView::fillAgenda "); 1043 // qDebug("KOAgendaView::fillAgenda ");
1052 fillAgenda(); 1044 fillAgenda();
1053} 1045}
1054 1046
1055void KOAgendaView::fillAgenda() 1047void KOAgendaView::fillAgenda()
1056{ 1048{
1057 if ( globalFlagBlockStartup ) 1049 if ( globalFlagBlockStartup )
1058 return; 1050 return;
1059 if ( globalFlagBlockAgenda == 1 ) 1051 if ( globalFlagBlockAgenda == 1 )
1060 return; 1052 return;
1061 //if ( globalFlagBlockAgenda == 2 ) 1053 //if ( globalFlagBlockAgenda == 2 )
1062 //globalFlagBlockAgenda = 0; 1054 //globalFlagBlockAgenda = 0;
1063 // globalFlagBlockPainting = false; 1055 // globalFlagBlockPainting = false;
1064 if ( globalFlagBlockAgenda == 0 ) 1056 if ( globalFlagBlockAgenda == 0 )
1065 globalFlagBlockAgenda = 1; 1057 globalFlagBlockAgenda = 1;
1066 // clearView(); 1058 // clearView();
1067 //qDebug("fillAgenda()++++ "); 1059 //qDebug("fillAgenda()++++ ");
1068 globalFlagBlockAgendaItemPaint = 1; 1060 globalFlagBlockAgendaItemPaint = 1;
1069 1061
1070 mAllDayAgenda->changeColumns(mSelectedDates.count()); 1062 mAllDayAgenda->changeColumns(mSelectedDates.count());
1071 mAgenda->changeColumns(mSelectedDates.count()); 1063 mAgenda->changeColumns(mSelectedDates.count());
1072 qApp->processEvents(); 1064 qApp->processEvents();
1073 mEventIndicatorTop->changeColumns(mSelectedDates.count()); 1065 mEventIndicatorTop->changeColumns(mSelectedDates.count());
1074 mEventIndicatorBottom->changeColumns(mSelectedDates.count()); 1066 mEventIndicatorBottom->changeColumns(mSelectedDates.count());
1075 setHolidayMasks(); 1067 setHolidayMasks();
1076 1068
1077 //mAgenda->hideUnused(); 1069 //mAgenda->hideUnused();
1078 //mAllDayAgenda->hideUnused(); 1070 //mAllDayAgenda->hideUnused();
1079 1071
1080 // mAgenda->blockNextRepaint( false ); 1072 // mAgenda->blockNextRepaint( false );
1081 // mAgenda->viewport()->repaint(); 1073 // mAgenda->viewport()->repaint();
1082 // mAgenda->blockNextRepaint( true ); 1074 // mAgenda->blockNextRepaint( true );
1083 mMinY.resize(mSelectedDates.count()); 1075 mMinY.resize(mSelectedDates.count());
1084 mMaxY.resize(mSelectedDates.count()); 1076 mMaxY.resize(mSelectedDates.count());
1085 1077
1086 QPtrList<Event> dayEvents; 1078 QPtrList<Event> dayEvents;
1087 1079
1088 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 1080 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
1089 // Therefore, gtodoset all of them. 1081 // Therefore, gtodoset all of them.
1090 QPtrList<Todo> todos = calendar()->todos(); 1082 QPtrList<Todo> todos = calendar()->todos();
1091 1083
1092 mAgenda->setDateList(mSelectedDates); 1084 mAgenda->setDateList(mSelectedDates);
1093 1085
1094 QDate today = QDate::currentDate(); 1086 QDate today = QDate::currentDate();
1095 1087
1096 DateList::ConstIterator dit; 1088 DateList::ConstIterator dit;
1097 int curCol = 0; 1089 int curCol = 0;
1098 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 1090 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
1099 QDate currentDate = *dit; 1091 QDate currentDate = *dit;
1100 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString() 1092 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString()
1101 // << endl; 1093 // << endl;
1102 1094
1103 dayEvents = calendar()->events(currentDate,true); 1095 dayEvents = calendar()->events(currentDate,true);
1104 1096
1105 // Default values, which can never be reached 1097 // Default values, which can never be reached
1106 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1; 1098 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1;
1107 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1; 1099 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1;
1108 1100
1109 unsigned int numEvent; 1101 unsigned int numEvent;
1110 for(numEvent=0;numEvent<dayEvents.count();++numEvent) { 1102 for(numEvent=0;numEvent<dayEvents.count();++numEvent) {
1111 Event *event = dayEvents.at(numEvent); 1103 Event *event = dayEvents.at(numEvent);
1112 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") ) 1104 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") )
1113 if ( event->uid().left(15) == QString("last-syncEvent-") ) 1105 if ( event->uid().left(15) == QString("last-syncEvent-") )
1114 continue; 1106 continue;
1115 // kdDebug() << " Event: " << event->summary() << endl; 1107 // kdDebug() << " Event: " << event->summary() << endl;
1116 1108
1117 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol; 1109 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol;
1118 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol; 1110 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol;
1119 1111
1120 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl; 1112 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl;
1121 1113
1122 if (event->doesFloat()) { 1114 if (event->doesFloat()) {
1123 if (event->recurrence()->doesRecur()) { 1115 if (event->recurrence()->doesRecur()) {
1124 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol); 1116 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol);
1125 } else { 1117 } else {
1126 if (beginX <= 0 && curCol == 0) { 1118 if (beginX <= 0 && curCol == 0) {
1127 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1119 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1128 } else if (beginX == curCol) { 1120 } else if (beginX == curCol) {
1129 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1121 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1130 } 1122 }
1131 } 1123 }
1132 } else if (event->isMultiDay()) { 1124 } else if (event->isMultiDay()) {
1133 if ( event->doesRecur () ) { 1125 if ( event->doesRecur () ) {
1134 QDate dateit = currentDate; 1126 QDate dateit = currentDate;
1135 int count = 0; 1127 int count = 0;
1136 int max = event->dtStart().daysTo( event->dtEnd() ) +2; 1128 int max = event->dtStart().daysTo( event->dtEnd() ) +2;
1137 while (! event->recursOn( dateit ) && count <= max ) { 1129 while (! event->recursOn( dateit ) && count <= max ) {
1138 ++count; 1130 ++count;
1139 dateit = dateit.addDays( -1 ); 1131 dateit = dateit.addDays( -1 );
1140 } 1132 }
1141 bool ok; 1133 bool ok;
1142 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok ); 1134 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok );
1143 if ( ok ) 1135 if ( ok )
1144 { 1136 {
1145 int secs = event->dtStart().secsTo( event->dtEnd() ); 1137 int secs = event->dtStart().secsTo( event->dtEnd() );
1146 QDateTime nextOcend =nextOcstart.addSecs( secs ); ; 1138 QDateTime nextOcend =nextOcstart.addSecs( secs ); ;
1147 beginX = currentDate.daysTo(nextOcstart.date()) + curCol; 1139 beginX = currentDate.daysTo(nextOcstart.date()) + curCol;
1148 endX = currentDate.daysTo(nextOcend.date()) + curCol; 1140 endX = currentDate.daysTo(nextOcend.date()) + curCol;
1149 1141
1150 } 1142 }
1151 } 1143 }
1152 int startY = mAgenda->timeToY(event->dtStart().time()); 1144 int startY = mAgenda->timeToY(event->dtStart().time());
1153 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1145 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1154 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol ); 1146 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol );
1155 if ((beginX <= 0 && curCol == 0) || beginX == curCol) { 1147 if ((beginX <= 0 && curCol == 0) || beginX == curCol) {
1156 //qDebug("insert!!! "); 1148 //qDebug("insert!!! ");
1157 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY); 1149 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY);
1158 } 1150 }
1159 if (beginX == curCol) { 1151 if (beginX == curCol) {
1160 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1152 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1161 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1153 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1162 } else if (endX == curCol) { 1154 } else if (endX == curCol) {
1163 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1155 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1164 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1156 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1165 } else { 1157 } else {
1166 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1158 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1167 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1159 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1168 } 1160 }
1169 } else { 1161 } else {
1170 int startY = mAgenda->timeToY(event->dtStart().time()); 1162 int startY = mAgenda->timeToY(event->dtStart().time());
1171 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1163 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1172 if (endY < startY) endY = startY; 1164 if (endY < startY) endY = startY;
1173 mAgenda->insertItem(event,currentDate,curCol,startY,endY); 1165 mAgenda->insertItem(event,currentDate,curCol,startY,endY);
1174 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1166 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1175 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1167 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1176 } 1168 }
1177 } 1169 }
1178 // ---------- [display Todos -------------- 1170 // ---------- [display Todos --------------
1179 unsigned int numTodo; 1171 unsigned int numTodo;
1180 for (numTodo = 0; numTodo < todos.count(); ++numTodo) { 1172 for (numTodo = 0; numTodo < todos.count(); ++numTodo) {
1181 Todo *todo = todos.at(numTodo); 1173 Todo *todo = todos.at(numTodo);
1182 1174
1183 if ( ! todo->hasDueDate() && !todo->hasCompletedDate()) continue; // todo shall not be displayed if it has no date 1175 if ( ! todo->hasDueDate() && !todo->hasCompletedDate()) continue; // todo shall not be displayed if it has no date
1184 1176
1185 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 1177 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
1186 // Already completed items can be displayed on their original due date 1178 // Already completed items can be displayed on their original due date
1187 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda 1179 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda
1188 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda; 1180 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda;
1189 bool fillIn = false; 1181 bool fillIn = false;
1190 if ( todo->hasCompletedDate() && todo->completed().date() == currentDate ) 1182 if ( todo->hasCompletedDate() && todo->completed().date() == currentDate )
1191 fillIn = true; 1183 fillIn = true;
1192 if ( ! fillIn && !todo->hasCompletedDate() ) 1184 if ( ! fillIn && !todo->hasCompletedDate() )
1193 fillIn = ((todo->dtDue().date() == currentDate) && !overdue) || ((currentDate == today) && overdue); 1185 fillIn = ((todo->dtDue().date() == currentDate) && !overdue) || ((currentDate == today) && overdue);
1194 if ( fillIn ) { 1186 if ( fillIn ) {
1195 if ( (todo->doesFloat() || overdue ) && !todo->hasCompletedDate() ) { // Todo has no due-time set or is already overdue 1187 if ( (todo->doesFloat() || overdue ) && !todo->hasCompletedDate() ) { // Todo has no due-time set or is already overdue
1196 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1188 if ( KOPrefs::instance()->mShowTodoInAgenda )
1197 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol); 1189 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol);
1198 } 1190 }
1199 else { 1191 else {
1200 QDateTime dt; 1192 QDateTime dt;
1201 if ( todo->hasCompletedDate() ) 1193 if ( todo->hasCompletedDate() )
1202 dt = todo->completed(); 1194 dt = todo->completed();
1203 else 1195 else
1204 dt = todo->dtDue();; 1196 dt = todo->dtDue();;
1205 1197
1206 1198
1207 int endY = mAgenda->timeToY(dt.time()) - 1; 1199 int endY = mAgenda->timeToY(dt.time()) - 1;
1208 int hi = (18/KOPrefs::instance()->mHourSize); 1200 int hi = (18/KOPrefs::instance()->mHourSize);
1209 //qDebug("hei %d ",KOPrefs::instance()->mHourSize); 1201 //qDebug("hei %d ",KOPrefs::instance()->mHourSize);
1210 int startY = endY -hi; 1202 int startY = endY -hi;
1211 1203
1212 mAgenda->insertItem(todo,currentDate,curCol,startY,endY); 1204 mAgenda->insertItem(todo,currentDate,curCol,startY,endY);
1213 1205
1214 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1206 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1215 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1207 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1216 } 1208 }
1217 } 1209 }
1218 } 1210 }
1219 // ---------- display Todos] -------------- 1211 // ---------- display Todos] --------------
1220 1212
1221 ++curCol; 1213 ++curCol;
1222 } 1214 }
1223 mAgenda->hideUnused(); 1215 mAgenda->hideUnused();
1224 mAllDayAgenda->hideUnused(); 1216 mAllDayAgenda->hideUnused();
1225 mAgenda->checkScrollBoundaries(); 1217 mAgenda->checkScrollBoundaries();
1226 1218
1227 deleteSelectedDateTime(); 1219 deleteSelectedDateTime();
1228 1220
1229 createDayLabels(); 1221 createDayLabels();
1230 emit incidenceSelected( 0 ); 1222 emit incidenceSelected( 0 );
1231 1223
1232 if ( globalFlagBlockAgenda == 2 ) { 1224 if ( globalFlagBlockAgenda == 2 ) {
1233 if ( KOPrefs::instance()->mSetTimeToDayStartAt ) 1225 if ( KOPrefs::instance()->mSetTimeToDayStartAt )
1234 setStartHour( KOPrefs::instance()->mDayBegins ); 1226 setStartHour( KOPrefs::instance()->mDayBegins );
1235 else if ( KOPrefs::instance()->mCenterOnCurrentTime ) 1227 else if ( KOPrefs::instance()->mCenterOnCurrentTime )
1236 setStartHour( QTime::currentTime ().hour() ); 1228 setStartHour( QTime::currentTime ().hour() );
1237 // qApp->processEvents(); 1229 // qApp->processEvents();
1238 } 1230 }
1239 qApp->processEvents(); 1231 qApp->processEvents();
1240 //qDebug("qApp->processEvents(); END "); 1232 //qDebug("qApp->processEvents(); END ");
1241 globalFlagBlockAgenda = 0; 1233 globalFlagBlockAgenda = 0;
1242 1234
1243 // mAgenda->hideUnused(); 1235 // mAgenda->hideUnused();
1244 //mAllDayAgenda->hideUnused(); 1236 //mAllDayAgenda->hideUnused();
1245 mAllDayAgenda->drawContentsToPainter(); 1237 mAllDayAgenda->drawContentsToPainter();
1246 mAgenda->drawContentsToPainter(); 1238 mAgenda->drawContentsToPainter();
1247 repaintAgenda(); 1239 repaintAgenda();
1248 // mAgenda->finishUpdate(); 1240 // mAgenda->finishUpdate();
1249 //mAllDayAgenda->finishUpdate(); 1241 //mAllDayAgenda->finishUpdate();
1250 1242
1251 // repaintAgenda(); 1243 // repaintAgenda();
1252 //qApp->processEvents(); 1244 //qApp->processEvents();
1253 // globalFlagBlockAgenda = 0; 1245 // globalFlagBlockAgenda = 0;
1254} 1246}
1255void KOAgendaView::repaintAgenda() 1247void KOAgendaView::repaintAgenda()
1256{ 1248{
1257 // mAllDayAgenda->drawContentsToPainter(); 1249 // mAllDayAgenda->drawContentsToPainter();
1258// mAllDayAgenda->viewport()->repaint( false ); 1250// mAllDayAgenda->viewport()->repaint( false );
1259// mAgenda->drawContentsToPainter(); 1251// mAgenda->drawContentsToPainter();
1260// mAgenda->viewport()->repaint( false ); 1252// mAgenda->viewport()->repaint( false );
1261// qApp->processEvents(); 1253// qApp->processEvents();
1262 1254
1263 //qDebug("KOAgendaView::repaintAgenda() "); 1255 //qDebug("KOAgendaView::repaintAgenda() ");
1264 //qApp->processEvents(); 1256 //qApp->processEvents();
1265 mAgenda->viewport()->repaint( false ); 1257 mAgenda->viewport()->repaint( false );
1266 mAllDayAgenda->viewport()->repaint( false ); 1258 mAllDayAgenda->viewport()->repaint( false );
1267 mAgenda->finishUpdate(); 1259 mAgenda->finishUpdate();
1268 mAllDayAgenda->finishUpdate(); 1260 mAllDayAgenda->finishUpdate();
1269} 1261}
1270 1262
1271 1263
1272void KOAgendaView::clearView() 1264void KOAgendaView::clearView()
1273{ 1265{
1274 // kdDebug() << "ClearView" << endl; 1266 // kdDebug() << "ClearView" << endl;
1275 mAllDayAgenda->clear(); 1267 mAllDayAgenda->clear();
1276 mAgenda->clear(); 1268 mAgenda->clear();
1277} 1269}
1278 1270
1279void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1271void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1280 const QDate &td) 1272 const QDate &td)
1281{ 1273{
1282#ifndef KORG_NOPRINTER 1274#ifndef KORG_NOPRINTER
1283 if (fd == td) 1275 if (fd == td)
1284 calPrinter->preview(CalPrinter::Day, fd, td); 1276 calPrinter->preview(CalPrinter::Day, fd, td);
1285 else 1277 else
1286 calPrinter->preview(CalPrinter::Week, fd, td); 1278 calPrinter->preview(CalPrinter::Week, fd, td);
1287#endif 1279#endif
1288} 1280}
1289 1281
1290// void KOAgendaView::updateMovedTodo() 1282// void KOAgendaView::updateMovedTodo()
1291// { 1283// {
1292// // updateConfig(); 1284// // updateConfig();
1293// // emit updateTodoViews(); 1285// // emit updateTodoViews();
1294// } 1286// }
1295 1287
1296void KOAgendaView::newEvent(int gx, int gy) 1288void KOAgendaView::newEvent(int gx, int gy)
1297{ 1289{
1298 if (!mSelectedDates.count()) return; 1290 if (!mSelectedDates.count()) return;
1299 1291
1300 QDate day = mSelectedDates[gx]; 1292 QDate day = mSelectedDates[gx];
1301 1293
1302 QTime time = mAgenda->gyToTime(gy); 1294 QTime time = mAgenda->gyToTime(gy);
1303 QDateTime dt(day,time); 1295 QDateTime dt(day,time);
1304 // if ( dt < QDateTime::currentDateTime () ) 1296 // if ( dt < QDateTime::currentDateTime () )
1305 // dt = QDateTime::currentDateTime ().addSecs( 3600 ); 1297 // dt = QDateTime::currentDateTime ().addSecs( 3600 );
1306 emit newEventSignal(dt); 1298 emit newEventSignal(dt);
1307} 1299}
1308 1300
1309void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd) 1301void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd)
1310{ 1302{
1311 if (!mSelectedDates.count()) return; 1303 if (!mSelectedDates.count()) return;
1312 1304
1313 QDate dayStart = mSelectedDates[gxStart]; 1305 QDate dayStart = mSelectedDates[gxStart];
1314 QDate dayEnd = mSelectedDates[gxEnd]; 1306 QDate dayEnd = mSelectedDates[gxEnd];
1315 1307
1316 QTime timeStart = mAgenda->gyToTime(gyStart); 1308 QTime timeStart = mAgenda->gyToTime(gyStart);
1317 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1309 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1318 1310
1319 QDateTime dtStart(dayStart,timeStart); 1311 QDateTime dtStart(dayStart,timeStart);
1320 QDateTime dtEnd(dayEnd,timeEnd); 1312 QDateTime dtEnd(dayEnd,timeEnd);
1321 1313
1322 emit newEventSignal(dtStart,dtEnd); 1314 emit newEventSignal(dtStart,dtEnd);
1323} 1315}
1324 1316
1325void KOAgendaView::newEventAllDay(int gx, int ) 1317void KOAgendaView::newEventAllDay(int gx, int )
1326{ 1318{
1327 if (!mSelectedDates.count()) return; 1319 if (!mSelectedDates.count()) return;
1328 1320
1329 QDate day = mSelectedDates[gx]; 1321 QDate day = mSelectedDates[gx];
1330 1322
1331 emit newEventSignal(day); 1323 emit newEventSignal(day);
1332} 1324}
1333void KOAgendaView::newTodoAllDay(int gx, int ) 1325void KOAgendaView::newTodoAllDay(int gx, int )
1334{ 1326{
1335 if (!mSelectedDates.count()) return; 1327 if (!mSelectedDates.count()) return;
1336 1328
1337 QDateTime day (mSelectedDates[gx] ); 1329 QDateTime day (mSelectedDates[gx] );
1338 emit newTodoSignal(day, true); 1330 emit newTodoSignal(day, true);
1339} 1331}
1340void KOAgendaView::newTodo(int gx, int gy ) 1332void KOAgendaView::newTodo(int gx, int gy )
1341{ 1333{
1342 if (!mSelectedDates.count()) return; 1334 if (!mSelectedDates.count()) return;
1343 QDate dayStart = mSelectedDates[gx]; 1335 QDate dayStart = mSelectedDates[gx];
1344 QTime timeStart = mAgenda->gyToTime(gy); 1336 QTime timeStart = mAgenda->gyToTime(gy);
1345 QDateTime dt (dayStart,timeStart); 1337 QDateTime dt (dayStart,timeStart);
1346 emit newTodoSignal( dt, false ); 1338 emit newTodoSignal( dt, false );
1347} 1339}
1348 1340
1349void KOAgendaView::updateEventIndicatorTop(int newY) 1341void KOAgendaView::updateEventIndicatorTop(int newY)
1350{ 1342{
1351 uint i; 1343 uint i;
1352 for(i=0;i<mMinY.size();++i) { 1344 for(i=0;i<mMinY.size();++i) {
1353 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true); 1345 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true);
1354 else mEventIndicatorTop->enableColumn(i,false); 1346 else mEventIndicatorTop->enableColumn(i,false);
1355 } 1347 }
1356 1348
1357 mEventIndicatorTop->update(); 1349 mEventIndicatorTop->update();
1358} 1350}
1359 1351
1360void KOAgendaView::updateEventIndicatorBottom(int newY) 1352void KOAgendaView::updateEventIndicatorBottom(int newY)
1361{ 1353{
1362 uint i; 1354 uint i;
1363 for(i=0;i<mMaxY.size();++i) { 1355 for(i=0;i<mMaxY.size();++i) {
1364 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true); 1356 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true);
1365 else mEventIndicatorBottom->enableColumn(i,false); 1357 else mEventIndicatorBottom->enableColumn(i,false);
1366 } 1358 }
1367 1359
1368 mEventIndicatorBottom->update(); 1360 mEventIndicatorBottom->update();
1369} 1361}
1370 1362
1371void KOAgendaView::startDrag(Event *event) 1363void KOAgendaView::startDrag(Event *event)
1372{ 1364{
1373#ifndef KORG_NODND 1365#ifndef KORG_NODND
1374 DndFactory factory( calendar() ); 1366 DndFactory factory( calendar() );
1375 ICalDrag *vd = factory.createDrag(event,this); 1367 ICalDrag *vd = factory.createDrag(event,this);
1376 if (vd->drag()) { 1368 if (vd->drag()) {
1377 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl; 1369 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl;
1378 } 1370 }
1379#endif 1371#endif
1380} 1372}
1381 1373
1382void KOAgendaView::readSettings() 1374void KOAgendaView::readSettings()
1383{ 1375{
1384 readSettings(KOGlobals::config()); 1376 readSettings(KOGlobals::config());
1385} 1377}
1386 1378
1387void KOAgendaView::readSettings(KConfig *config) 1379void KOAgendaView::readSettings(KConfig *config)
1388{ 1380{
1389 // kdDebug() << "KOAgendaView::readSettings()" << endl; 1381 // kdDebug() << "KOAgendaView::readSettings()" << endl;
1390 1382
1391 config->setGroup("Views"); 1383 config->setGroup("Views");
1392 1384
1393 //#ifndef KORG_NOSPLITTER 1385 //#ifndef KORG_NOSPLITTER
1394 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView"); 1386 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView");
1395 if (sizes.count() == 2) { 1387 if (sizes.count() == 2) {
1396 if ( sizes[0] < 20 ) { 1388 if ( sizes[0] < 20 ) {
1397 sizes[1] = sizes[1] +20 - sizes[0]; 1389 sizes[1] = sizes[1] +20 - sizes[0];
1398 sizes[0] = 20; 1390 sizes[0] = 20;
1399 } 1391 }
1400 mSplitterAgenda->setSizes(sizes); 1392 mSplitterAgenda->setSizes(sizes);
1401 // qDebug("read %d %d ",sizes[0],sizes[1] ); 1393 // qDebug("read %d %d ",sizes[0],sizes[1] );
1402 } 1394 }
1403 //#endif 1395 //#endif
1404 1396
1405 // updateConfig(); 1397 // updateConfig();
1406} 1398}
1407 1399
1408void KOAgendaView::writeSettings(KConfig *config) 1400void KOAgendaView::writeSettings(KConfig *config)
1409{ 1401{
1410 // kdDebug() << "KOAgendaView::writeSettings()" << endl; 1402 // kdDebug() << "KOAgendaView::writeSettings()" << endl;
1411 1403
1412 config->setGroup("Views"); 1404 config->setGroup("Views");
1413 1405
1414 //#ifndef KORG_NOSPLITTER 1406 //#ifndef KORG_NOSPLITTER
1415 QValueList<int> list = mSplitterAgenda->sizes(); 1407 QValueList<int> list = mSplitterAgenda->sizes();
1416 config->writeEntry("Separator AgendaView",list); 1408 config->writeEntry("Separator AgendaView",list);
1417 //qDebug("write %d %d ", list[0],list[1] ); 1409 //qDebug("write %d %d ", list[0],list[1] );
1418 //#endif 1410 //#endif
1419} 1411}
1420 1412
1421void KOAgendaView::setHolidayMasks() 1413void KOAgendaView::setHolidayMasks()
1422{ 1414{
1423 mHolidayMask.resize(mSelectedDates.count()); 1415 mHolidayMask.resize(mSelectedDates.count());
1424 1416
1425 uint i; 1417 uint i;
1426 for(i=0;i<mSelectedDates.count();++i) { 1418 for(i=0;i<mSelectedDates.count();++i) {
1427 QDate date = mSelectedDates[i]; 1419 QDate date = mSelectedDates[i];
1428 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6); 1420 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6);
1429 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7); 1421 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7);
1430 bool showHoliday = false; 1422 bool showHoliday = false;
1431 if ( KOPrefs::instance()->mExcludeHolidays ) { 1423 if ( KOPrefs::instance()->mExcludeHolidays ) {
1432 QPtrList<Event> events = calendar()->events( date, true ); 1424 QPtrList<Event> events = calendar()->events( date, true );
1433 Event *event; 1425 Event *event;
1434 for( event = events.first(); event; event = events.next() ) { 1426 for( event = events.first(); event; event = events.next() ) {
1435 if ( event->isHoliday()) { 1427 if ( event->isHoliday()) {
1436 showHoliday = true; 1428 showHoliday = true;
1437 break; 1429 break;
1438 } 1430 }
1439 } 1431 }
1440 1432
1441 } 1433 }
1442 1434
1443#ifndef KORG_NOPLUGINS 1435#ifndef KORG_NOPLUGINS
1444 bool showHoliday = KOPrefs::instance()->mExcludeHolidays && 1436 bool showHoliday = KOPrefs::instance()->mExcludeHolidays &&
1445 !KOCore::self()->holiday(date).isEmpty(); 1437 !KOCore::self()->holiday(date).isEmpty();
1446#endif 1438#endif
1447 bool showDay = showSaturday || showSunday || showHoliday; 1439 bool showDay = showSaturday || showSunday || showHoliday;
1448 1440
1449 if (showDay) { 1441 if (showDay) {
1450 mHolidayMask.at(i) = true; 1442 mHolidayMask.at(i) = true;
1451 } else { 1443 } else {
1452 mHolidayMask.at(i) = false; 1444 mHolidayMask.at(i) = false;
1453 } 1445 }
1454 } 1446 }
1455 1447
1456 mAgenda->setHolidayMask(&mHolidayMask); 1448 mAgenda->setHolidayMask(&mHolidayMask);
1457 mAllDayAgenda->setHolidayMask(&mHolidayMask); 1449 mAllDayAgenda->setHolidayMask(&mHolidayMask);
1458} 1450}
1459 1451
1460void KOAgendaView::setContentsPos(int y) 1452void KOAgendaView::setContentsPos(int y)
1461{ 1453{
1462 mAgenda->setContentsPos(0,y); 1454 mAgenda->setContentsPos(0,y);
1463} 1455}
1464 1456
1465void KOAgendaView::setExpandedButton( bool expanded ) 1457void KOAgendaView::setExpandedButton( bool expanded )
1466{ 1458{
1467 if ( expanded ) { 1459 if ( expanded ) {
1468 mExpandButton->setPixmap( mExpandedPixmap ); 1460 mExpandButton->setPixmap( mExpandedPixmap );
1469 } else { 1461 } else {
1470 mExpandButton->setPixmap( mNotExpandedPixmap ); 1462 mExpandButton->setPixmap( mNotExpandedPixmap );
1471 } 1463 }
1472} 1464}
1473 1465
1474void KOAgendaView::clearSelection() 1466void KOAgendaView::clearSelection()
1475{ 1467{
1476 mAgenda->deselectItem(); 1468 mAgenda->deselectItem();
1477 mAllDayAgenda->deselectItem(); 1469 mAllDayAgenda->deselectItem();
1478} 1470}
1479 1471
1480void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart, 1472void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart,
1481 int gxEnd, int gyEnd) 1473 int gxEnd, int gyEnd)
1482{ 1474{
1483 mTimeSpanInAllDay = true; 1475 mTimeSpanInAllDay = true;
1484 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd); 1476 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd);
1485} 1477}
1486 1478
1487 1479
1488 1480
1489 1481
1490void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart, 1482void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart,
1491 int gxEnd, int gyEnd) 1483 int gxEnd, int gyEnd)
1492{ 1484{
1493 if (!mSelectedDates.count()) return; 1485 if (!mSelectedDates.count()) return;
1494 1486
1495 QDate dayStart = mSelectedDates[gxStart]; 1487 QDate dayStart = mSelectedDates[gxStart];
1496 QDate dayEnd = mSelectedDates[gxEnd]; 1488 QDate dayEnd = mSelectedDates[gxEnd];
1497 1489
1498 QTime timeStart = mAgenda->gyToTime(gyStart); 1490 QTime timeStart = mAgenda->gyToTime(gyStart);
1499 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1491 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1500 1492
1501 QDateTime dtStart(dayStart,timeStart); 1493 QDateTime dtStart(dayStart,timeStart);
1502 QDateTime dtEnd(dayEnd,timeEnd); 1494 QDateTime dtEnd(dayEnd,timeEnd);
1503 1495
1504 mTimeSpanBegin = dtStart; 1496 mTimeSpanBegin = dtStart;
1505 mTimeSpanEnd = dtEnd; 1497 mTimeSpanEnd = dtEnd;
1506 1498
1507} 1499}
1508 1500
1509void KOAgendaView::deleteSelectedDateTime() 1501void KOAgendaView::deleteSelectedDateTime()
1510{ 1502{
1511 mTimeSpanBegin.setDate(QDate()); 1503 mTimeSpanBegin.setDate(QDate());
1512 mTimeSpanEnd.setDate(QDate()); 1504 mTimeSpanEnd.setDate(QDate());
1513 mTimeSpanInAllDay = false; 1505 mTimeSpanInAllDay = false;
1514} 1506}
1515 1507
1516void KOAgendaView::keyPressEvent ( QKeyEvent * e ) 1508void KOAgendaView::keyPressEvent ( QKeyEvent * e )
1517{ 1509{
1518 e->ignore(); 1510 e->ignore();
1519} 1511}
1520 1512
1521void KOAgendaView::scrollOneHourUp() 1513void KOAgendaView::scrollOneHourUp()
1522{ 1514{
1523 1515
1524 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 ); 1516 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 );
1525} 1517}
1526void KOAgendaView::scrollOneHourDown() 1518void KOAgendaView::scrollOneHourDown()
1527{ 1519{
1528 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 ); 1520 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 );
1529} 1521}
1530 1522
1531void KOAgendaView::setStartHour( int h ) 1523void KOAgendaView::setStartHour( int h )
1532{ 1524{
1533 mAgenda->setStartHour( h ); 1525 mAgenda->setStartHour( h );
1534 1526
1535} 1527}
1536void KOAgendaView::setInitStartHour() 1528void KOAgendaView::setInitStartHour()
1537{ 1529{
1538 1530
1539 if ( KOPrefs::instance()->mCenterOnCurrentTime ) 1531 if ( KOPrefs::instance()->mCenterOnCurrentTime )
1540 setStartHour( QTime::currentTime ().hour() ); 1532 setStartHour( QTime::currentTime ().hour() );
1541 else 1533 else
1542 setStartHour( KOPrefs::instance()->mDayBegins ); 1534 setStartHour( KOPrefs::instance()->mDayBegins );
1543 1535
1544} 1536}
1545 1537
1546 1538
1547void KOAgendaView::updateTodo( Todo * t, int ) 1539void KOAgendaView::updateTodo( Todo * t, int )
1548{ 1540{
1549 if ( !isVisible() ) 1541 if ( !isVisible() )
1550 return; 1542 return;
1551 bool remove = false; 1543 bool remove = false;
1552 bool removeAD = false; 1544 bool removeAD = false;
1553 QDate da; 1545 QDate da;
1554 if ( t->hasCompletedDate() ) 1546 if ( t->hasCompletedDate() )
1555 da = t->completed().date(); 1547 da = t->completed().date();
1556 else 1548 else
1557 da = t->dtDue().date(); 1549 da = t->dtDue().date();
1558 if ( ! t->hasDueDate() && !t->hasCompletedDate() ) { 1550 if ( ! t->hasDueDate() && !t->hasCompletedDate() ) {
1559 remove = true; 1551 remove = true;
1560 removeAD = true; 1552 removeAD = true;
1561 } 1553 }
1562 else { 1554 else {
1563 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ; 1555 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ;
1564 if ( overdue && 1556 if ( overdue &&
1565 QDate::currentDate() >= mSelectedDates.first() && 1557 QDate::currentDate() >= mSelectedDates.first() &&
1566 QDate::currentDate() <= mSelectedDates.last()) { 1558 QDate::currentDate() <= mSelectedDates.last()) {
1567 removeAD = false; 1559 removeAD = false;
1568 remove = true; 1560 remove = true;
1569 } 1561 }
1570 else { 1562 else {
1571 1563
1572 if ( da < mSelectedDates.first() || 1564 if ( da < mSelectedDates.first() ||
1573 da > mSelectedDates.last() ) { 1565 da > mSelectedDates.last() ) {
1574 remove = true; 1566 remove = true;
1575 removeAD = true; 1567 removeAD = true;
1576 } else { 1568 } else {
1577 remove = t->doesFloat() && !t->hasCompletedDate(); 1569 remove = t->doesFloat() && !t->hasCompletedDate();
1578 removeAD = !remove; 1570 removeAD = !remove;
1579 } 1571 }
1580 } 1572 }
1581 } 1573 }
1582 int days = mSelectedDates.first().daysTo( da ); 1574 int days = mSelectedDates.first().daysTo( da );
1583 //qDebug("daysto %d %d %d", days, remove,removeAD ); 1575 //qDebug("daysto %d %d %d", days, remove,removeAD );
1584 mAgenda->updateTodo( t , days, remove); 1576 mAgenda->updateTodo( t , days, remove);
1585 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1577 if ( KOPrefs::instance()->mShowTodoInAgenda )
1586 mAllDayAgenda->updateTodo( t , days, removeAD); 1578 mAllDayAgenda->updateTodo( t , days, removeAD);
1587 //qDebug("KOAgendaView::updateTodo( Todo *, int ) "); 1579 //qDebug("KOAgendaView::updateTodo( Todo *, int ) ");
1588 1580
1589} 1581}
diff --git a/korganizer/koagendaview.h b/korganizer/koagendaview.h
index 8b8bac0..0cb9310 100644
--- a/korganizer/koagendaview.h
+++ b/korganizer/koagendaview.h
@@ -1,291 +1,292 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,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 KOAGENDAVIEW_H 23#ifndef KOAGENDAVIEW_H
24#define KOAGENDAVIEW_H 24#define KOAGENDAVIEW_H
25 25
26#include <qscrollview.h> 26#include <qscrollview.h>
27#include <qdatetime.h> 27#include <qdatetime.h>
28#include <qpushbutton.h> 28#include <qpushbutton.h>
29#include <qlayout.h> 29#include <qlayout.h>
30#ifndef DESKTOP_VERSION 30#ifndef DESKTOP_VERSION
31#include <qksplitter.h> 31#include <qksplitter.h>
32#else 32#else
33#include <qsplitter.h> 33#include <qsplitter.h>
34#endif 34#endif
35#include <qmemarray.h> 35#include <qmemarray.h>
36 36
37#include "koeventview.h" 37#include "koeventview.h"
38 38
39class QHBox; 39class QHBox;
40class QFrame; 40class QFrame;
41class QLabel; 41class QLabel;
42class QPushButton; 42class QPushButton;
43class CalendarView; 43class CalendarView;
44class KOAgenda; 44class KOAgenda;
45class KOAgendaItem; 45class KOAgendaItem;
46class KConfig; 46class KConfig;
47class KDGanttMinimizeSplitter; 47class KDGanttMinimizeSplitter;
48 48
49class KOAgendaButton : public QPushButton 49class KOAgendaButton : public QPushButton
50{ 50{
51 Q_OBJECT 51 Q_OBJECT
52 public: 52 public:
53 KOAgendaButton( QWidget *parent=0, const char *name=0 ) : 53 KOAgendaButton( QWidget *parent=0, const char *name=0 ) :
54 QPushButton( parent, name ) 54 QPushButton( parent, name )
55 { 55 {
56 mNum = -3; 56 mNum = -3;
57 setFlat( true ); 57 setFlat( true );
58 setFocusPolicy(NoFocus); 58 setFocusPolicy(NoFocus);
59 setSizePolicy(QSizePolicy( QSizePolicy::Expanding ,QSizePolicy::Expanding )); 59 setSizePolicy(QSizePolicy( QSizePolicy::Expanding ,QSizePolicy::Expanding ));
60 connect( this, SIGNAL( clicked() ), this, SLOT ( bClicked() ) ); 60 connect( this, SIGNAL( clicked() ), this, SLOT ( bClicked() ) );
61 }; 61 };
62 62
63 QSize sizeHint () const { return QSize( 5,5) ;} 63 QSize sizeHint () const { return QSize( 5,5) ;}
64 void setNum( int n) { mNum = n; } 64 void setNum( int n) { mNum = n; }
65private slots: 65private slots:
66 void bClicked() {emit numClicked( mNum);} 66 void bClicked() {emit numClicked( mNum);}
67signals: 67signals:
68 void numClicked( int ); 68 void numClicked( int );
69private: 69private:
70 int mNum; 70 int mNum;
71}; 71};
72 72
73class TimeLabels : public QScrollView { 73class TimeLabels : public QScrollView {
74 Q_OBJECT 74 Q_OBJECT
75 public: 75 public:
76 TimeLabels(int rows,QWidget *parent=0,const char *name=0,WFlags f=0); 76 TimeLabels(int rows,QWidget *parent=0,const char *name=0,WFlags f=0);
77 77
78 void setCellHeight(int height); 78 void setCellHeight(int height);
79 79
80 /** Calculates the minimum width */ 80 /** Calculates the minimum width */
81 virtual int minimumWidth() const; 81 virtual int minimumWidth() const;
82 82
83 /** updates widget's internal state */ 83 /** updates widget's internal state */
84 void updateConfig(); 84 void updateConfig();
85 85
86 /** */ 86 /** */
87 void setAgenda(KOAgenda* agenda); 87 void setAgenda(KOAgenda* agenda);
88 88
89 /** */ 89 /** */
90 virtual void paintEvent(QPaintEvent* e); 90 virtual void paintEvent(QPaintEvent* e);
91 void contentsMousePressEvent ( QMouseEvent * ) ; 91 void contentsMousePressEvent ( QMouseEvent * ) ;
92 void contentsMouseReleaseEvent ( QMouseEvent * ); 92 void contentsMouseReleaseEvent ( QMouseEvent * );
93 void contentsMouseMoveEvent ( QMouseEvent * ); 93 void contentsMouseMoveEvent ( QMouseEvent * );
94 94
95 public slots: 95 public slots:
96 /** update time label positions */ 96 /** update time label positions */
97 void positionChanged(); 97 void positionChanged();
98 signals: 98 signals:
99 void scaleChanged(); 99 void scaleChanged();
100 protected: 100 protected:
101 void drawContents(QPainter *p,int cx, int cy, int cw, int ch); 101 void drawContents(QPainter *p,int cx, int cy, int cw, int ch);
102 102
103 private: 103 private:
104 int mMiniWidth;
104 int mMouseDownY; 105 int mMouseDownY;
105 QString mOrgCap; 106 QString mOrgCap;
106 int mRows; 107 int mRows;
107 int mCellHeight; 108 int mCellHeight;
108 109
109 /** */ 110 /** */
110 KOAgenda* mAgenda; 111 KOAgenda* mAgenda;
111}; 112};
112 113
113class EventIndicator : public QFrame { 114class EventIndicator : public QFrame {
114 Q_OBJECT 115 Q_OBJECT
115 public: 116 public:
116 enum Location { Top, Bottom }; 117 enum Location { Top, Bottom };
117 EventIndicator(Location loc=Top,QWidget *parent=0,const char *name=0); 118 EventIndicator(Location loc=Top,QWidget *parent=0,const char *name=0);
118 virtual ~EventIndicator(); 119 virtual ~EventIndicator();
119 120
120 void changeColumns(int columns); 121 void changeColumns(int columns);
121 void setPaintWidget( KDGanttMinimizeSplitter* ); 122 void setPaintWidget( KDGanttMinimizeSplitter* );
122 void setXOffset( int ); 123 void setXOffset( int );
123 void enableColumn(int column, bool enable); 124 void enableColumn(int column, bool enable);
124 125
125 protected: 126 protected:
126 void drawContents(QPainter *); 127 void drawContents(QPainter *);
127 128
128 private: 129 private:
129 int mXOffset; 130 int mXOffset;
130 KDGanttMinimizeSplitter* mPaintWidget; 131 KDGanttMinimizeSplitter* mPaintWidget;
131 int mColumns; 132 int mColumns;
132 QHBox *mTopBox; 133 QHBox *mTopBox;
133 QBoxLayout *mTopLayout; 134 QBoxLayout *mTopLayout;
134 Location mLocation; 135 Location mLocation;
135 QPixmap mPixmap; 136 QPixmap mPixmap;
136 QMemArray<bool> mEnabled; 137 QMemArray<bool> mEnabled;
137}; 138};
138 139
139/** 140/**
140 KOAgendaView is the agenda-like view used to display events in an one or 141 KOAgendaView is the agenda-like view used to display events in an one or
141 multi-day view. 142 multi-day view.
142*/ 143*/
143class KOAgendaView : public KOEventView { 144class KOAgendaView : public KOEventView {
144 Q_OBJECT 145 Q_OBJECT
145 public: 146 public:
146 KOAgendaView(Calendar *cal,QWidget *parent = 0,const char *name = 0 ); 147 KOAgendaView(Calendar *cal,QWidget *parent = 0,const char *name = 0 );
147 virtual ~KOAgendaView(); 148 virtual ~KOAgendaView();
148 void setStartHour( int ); 149 void setStartHour( int );
149 void toggleAllDay(); 150 void toggleAllDay();
150 151
151 152
152 /** Returns maximum number of days supported by the koagendaview */ 153 /** Returns maximum number of days supported by the koagendaview */
153 virtual int maxDatesHint(); 154 virtual int maxDatesHint();
154 155
155 /** Returns number of currently shown dates. */ 156 /** Returns number of currently shown dates. */
156 virtual int currentDateCount(); 157 virtual int currentDateCount();
157 158
158 /** returns the currently selected events */ 159 /** returns the currently selected events */
159 virtual QPtrList<Incidence> selectedIncidences(); 160 virtual QPtrList<Incidence> selectedIncidences();
160 161
161 /** returns the currently selected events */ 162 /** returns the currently selected events */
162 virtual DateList selectedDates(); 163 virtual DateList selectedDates();
163 164
164 /** Remove all events from view */ 165 /** Remove all events from view */
165 void clearView(); 166 void clearView();
166 KOAgenda *agenda() { return mAgenda;} 167 KOAgenda *agenda() { return mAgenda;}
167 virtual void printPreview(CalPrinter *calPrinter, 168 virtual void printPreview(CalPrinter *calPrinter,
168 const QDate &, const QDate &); 169 const QDate &, const QDate &);
169 170
170 /** start-datetime of selection */ 171 /** start-datetime of selection */
171 QDateTime selectionStart() {return mTimeSpanBegin;} 172 QDateTime selectionStart() {return mTimeSpanBegin;}
172 /** end-datetime of selection */ 173 /** end-datetime of selection */
173 QDateTime selectionEnd() {return mTimeSpanEnd;} 174 QDateTime selectionEnd() {return mTimeSpanEnd;}
174 /** returns true if selection is for whole day */ 175 /** returns true if selection is for whole day */
175 bool selectedIsAllDay() {return mTimeSpanInAllDay;} 176 bool selectedIsAllDay() {return mTimeSpanInAllDay;}
176 /** make selected start/end invalid */ 177 /** make selected start/end invalid */
177 void deleteSelectedDateTime(); 178 void deleteSelectedDateTime();
178 void repaintAgenda(); 179 void repaintAgenda();
179 public slots: 180 public slots:
180 void setInitStartHour(); 181 void setInitStartHour();
181 virtual void updateView(); 182 virtual void updateView();
182 virtual void updateConfig(); 183 virtual void updateConfig();
183 virtual void showDates(const QDate &start, const QDate &end); 184 virtual void showDates(const QDate &start, const QDate &end);
184 virtual void showEvents(QPtrList<Event> eventList); 185 virtual void showEvents(QPtrList<Event> eventList);
185 186
186 void updateTodo( Todo *, int ); 187 void updateTodo( Todo *, int );
187 void changeEventDisplay(Event *, int); 188 void changeEventDisplay(Event *, int);
188 189
189 void clearSelection(); 190 void clearSelection();
190 191
191 void newTodo(int gx,int gy); 192 void newTodo(int gx,int gy);
192 void newEvent(int gx,int gy); 193 void newEvent(int gx,int gy);
193 void newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd); 194 void newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd);
194 void newEventAllDay(int gx, int gy); 195 void newEventAllDay(int gx, int gy);
195 void newTodoAllDay(int gx, int gy); 196 void newTodoAllDay(int gx, int gy);
196 197
197 void startDrag(Event *); 198 void startDrag(Event *);
198 199
199 void readSettings(); 200 void readSettings();
200 void readSettings(KConfig *); 201 void readSettings(KConfig *);
201 void writeSettings(KConfig *); 202 void writeSettings(KConfig *);
202 203
203 void setContentsPos(int y); 204 void setContentsPos(int y);
204 205
205 void setExpandedButton( bool expanded ); 206 void setExpandedButton( bool expanded );
206 void scrollOneHourUp(); 207 void scrollOneHourUp();
207 void scrollOneHourDown(); 208 void scrollOneHourDown();
208 void addToCalSlot(Incidence *, Incidence *); 209 void addToCalSlot(Incidence *, Incidence *);
209 210
210 signals: 211 signals:
211 void showDateView( int, QDate ); 212 void showDateView( int, QDate );
212 void newTodoSignal( QDateTime ,bool ); 213 void newTodoSignal( QDateTime ,bool );
213 void toggleExpand(); 214 void toggleExpand();
214 void selectWeekNum( int ); 215 void selectWeekNum( int );
215 void todoMoved( Todo *, int ); 216 void todoMoved( Todo *, int );
216 void incidenceChanged(Incidence * , int ); 217 void incidenceChanged(Incidence * , int );
217 // void cloneIncidenceSignal(Incidence *); 218 // void cloneIncidenceSignal(Incidence *);
218 219
219 protected: 220 protected:
220 KOAgendaButton* getNewDaylabel(); 221 KOAgendaButton* getNewDaylabel();
221 bool mBlockUpdating; 222 bool mBlockUpdating;
222 int mUpcomingWidth; 223 int mUpcomingWidth;
223 /** Fill agenda beginning with date startDate */ 224 /** Fill agenda beginning with date startDate */
224 void fillAgenda(const QDate &startDate); 225 void fillAgenda(const QDate &startDate);
225 void resizeEvent( QResizeEvent* e ); 226 void resizeEvent( QResizeEvent* e );
226 /** Fill agenda using the current set value for the start date */ 227 /** Fill agenda using the current set value for the start date */
227 void fillAgenda(); 228 void fillAgenda();
228 229
229 /** Create labels for the selected dates. */ 230 /** Create labels for the selected dates. */
230 void createDayLabels(); 231 void createDayLabels();
231 232
232 /** 233 /**
233 Set the masks on the agenda widgets indicating, which days are holidays. 234 Set the masks on the agenda widgets indicating, which days are holidays.
234 */ 235 */
235 void setHolidayMasks(); 236 void setHolidayMasks();
236 237
237 protected slots: 238 protected slots:
238 void slotDaylabelClicked( int ); 239 void slotDaylabelClicked( int );
239 /** Update event belonging to agenda item */ 240 /** Update event belonging to agenda item */
240 void updateEventDates(KOAgendaItem *item, int mode = -1); 241 void updateEventDates(KOAgendaItem *item, int mode = -1);
241 //void updateMovedTodo(); 242 //void updateMovedTodo();
242 243
243 void updateEventIndicatorTop(int newY); 244 void updateEventIndicatorTop(int newY);
244 void updateEventIndicatorBottom(int newY); 245 void updateEventIndicatorBottom(int newY);
245 246
246 /** Updates data for selected timespan */ 247 /** Updates data for selected timespan */
247 void newTimeSpanSelected(int gxStart, int gyStart, int gxEnd, int gyEnd); 248 void newTimeSpanSelected(int gxStart, int gyStart, int gxEnd, int gyEnd);
248 /** Updates data for selected timespan for all day event*/ 249 /** Updates data for selected timespan for all day event*/
249 void newTimeSpanSelectedAllDay(int gxStart, int gyStart, int gxEnd, int gyEnd); 250 void newTimeSpanSelectedAllDay(int gxStart, int gyStart, int gxEnd, int gyEnd);
250 251
251 private: 252 private:
252 // view widgets 253 // view widgets
253 QFrame *mDayLabels; 254 QFrame *mDayLabels;
254 QHBox *mDayLabelsFrame; 255 QHBox *mDayLabelsFrame;
255 QBoxLayout *mLayoutDayLabels; 256 QBoxLayout *mLayoutDayLabels;
256 QFrame *mAllDayFrame; 257 QFrame *mAllDayFrame;
257 KOAgenda *mAllDayAgenda; 258 KOAgenda *mAllDayAgenda;
258 KOAgenda *mAgenda; 259 KOAgenda *mAgenda;
259 TimeLabels *mTimeLabels; 260 TimeLabels *mTimeLabels;
260 QWidget *mDummyAllDayLeft; 261 QWidget *mDummyAllDayLeft;
261 262
262 KDGanttMinimizeSplitter* mSplitterAgenda; 263 KDGanttMinimizeSplitter* mSplitterAgenda;
263 QPushButton *mExpandButton; 264 QPushButton *mExpandButton;
264 265
265 DateList mSelectedDates; // List of dates to be displayed 266 DateList mSelectedDates; // List of dates to be displayed
266 int mViewType; 267 int mViewType;
267 268
268 bool mWeekStartsMonday; 269 bool mWeekStartsMonday;
269 int mStartHour; 270 int mStartHour;
270 271
271 KOEventPopupMenu *mAgendaPopup; 272 KOEventPopupMenu *mAgendaPopup;
272 KOEventPopupMenu *mAllDayAgendaPopup; 273 KOEventPopupMenu *mAllDayAgendaPopup;
273 274
274 EventIndicator *mEventIndicatorTop; 275 EventIndicator *mEventIndicatorTop;
275 EventIndicator *mEventIndicatorBottom; 276 EventIndicator *mEventIndicatorBottom;
276 277
277 QMemArray<int> mMinY; 278 QMemArray<int> mMinY;
278 QMemArray<int> mMaxY; 279 QMemArray<int> mMaxY;
279 280
280 QMemArray<bool> mHolidayMask; 281 QMemArray<bool> mHolidayMask;
281 282
282 QPixmap mExpandedPixmap; 283 QPixmap mExpandedPixmap;
283 QPixmap mNotExpandedPixmap; 284 QPixmap mNotExpandedPixmap;
284 QPtrList<KOAgendaButton> mDayLabelsList; 285 QPtrList<KOAgendaButton> mDayLabelsList;
285 QDateTime mTimeSpanBegin; 286 QDateTime mTimeSpanBegin;
286 QDateTime mTimeSpanEnd; 287 QDateTime mTimeSpanEnd;
287 bool mTimeSpanInAllDay; 288 bool mTimeSpanInAllDay;
288 void keyPressEvent ( QKeyEvent * e ); 289 void keyPressEvent ( QKeyEvent * e );
289}; 290};
290 291
291#endif // KOAGENDAVIEW_H 292#endif // KOAGENDAVIEW_H
diff --git a/korganizer/kolistview.cpp b/korganizer/kolistview.cpp
index 6b63d7f..09d70f1 100644
--- a/korganizer/kolistview.cpp
+++ b/korganizer/kolistview.cpp
@@ -1,1195 +1,1242 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 1999 Preston Brown 3 Copyright (c) 1999 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 <qlistview.h> 25#include <qlistview.h>
26#include <qlayout.h> 26#include <qlayout.h>
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qpopupmenu.h> 28#include <qpopupmenu.h>
29#include <qprogressbar.h> 29#include <qprogressbar.h>
30#include <qfileinfo.h> 30#include <qfileinfo.h>
31#include <qmessagebox.h> 31#include <qmessagebox.h>
32#include <qdialog.h> 32#include <qdialog.h>
33#include <qtextstream.h> 33#include <qtextstream.h>
34#include <qdir.h> 34#include <qdir.h>
35#include <qwhatsthis.h> 35#include <qwhatsthis.h>
36#include <qregexp.h> 36#include <qregexp.h>
37 37
38#include <klocale.h> 38#include <klocale.h>
39#include <kdebug.h> 39#include <kdebug.h>
40#include <kiconloader.h> 40#include <kiconloader.h>
41#include <kglobal.h> 41#include <kglobal.h>
42 42
43#include <libkdepim/kpimglobalprefs.h> 43#include <libkdepim/kpimglobalprefs.h>
44#include <libkcal/calendar.h> 44#include <libkcal/calendar.h>
45#include <libkcal/calendarlocal.h> 45#include <libkcal/calendarlocal.h>
46#include <libkcal/icalformat.h> 46#include <libkcal/icalformat.h>
47#include <libkcal/vcalformat.h> 47#include <libkcal/vcalformat.h>
48#include <libkcal/recurrence.h> 48#include <libkcal/recurrence.h>
49#include <libkcal/filestorage.h> 49#include <libkcal/filestorage.h>
50#include <libkdepim/categoryselectdialog.h> 50#include <libkdepim/categoryselectdialog.h>
51#include <libkcal/kincidenceformatter.h> 51#include <libkcal/kincidenceformatter.h>
52#ifndef DESKTOP_VERSION 52#ifndef DESKTOP_VERSION
53#include <qpe/qpeapplication.h> 53#include <qpe/qpeapplication.h>
54#else 54#else
55#include <qapplication.h> 55#include <qapplication.h>
56#endif 56#endif
57 57
58#ifndef KORG_NOPRINTER 58#ifndef KORG_NOPRINTER
59#include "calprinter.h" 59#include "calprinter.h"
60#endif 60#endif
61#include "koglobals.h" 61#include "koglobals.h"
62#include "koprefs.h" 62#include "koprefs.h"
63#include "kfiledialog.h" 63#include "kfiledialog.h"
64 64
65#include "kolistview.h" 65#include "kolistview.h"
66 66
67 67
68 68
69 69
70class KOListViewWhatsThis :public QWhatsThis 70class KOListViewWhatsThis :public QWhatsThis
71{ 71{
72public: 72public:
73 KOListViewWhatsThis( QWidget *wid, KOListView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { }; 73 KOListViewWhatsThis( QWidget *wid, KOListView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { };
74 74
75protected: 75protected:
76 virtual QString text( const QPoint& p) 76 virtual QString text( const QPoint& p)
77 { 77 {
78 return _view->getWhatsThisText(p) ; 78 return _view->getWhatsThisText(p) ;
79 } 79 }
80private: 80private:
81 QWidget* _wid; 81 QWidget* _wid;
82 KOListView * _view; 82 KOListView * _view;
83}; 83};
84 84
85 85
86ListItemVisitor::ListItemVisitor(KOListViewItem *item, QDate date ) 86ListItemVisitor::ListItemVisitor(KOListViewItem *item, QDate date )
87{ 87{
88 mItem = item; 88 mItem = item;
89 mDate = date; 89 mDate = date;
90} 90}
91 91
92ListItemVisitor::~ListItemVisitor() 92ListItemVisitor::~ListItemVisitor()
93{ 93{
94} 94}
95 95
96bool ListItemVisitor::visit(Event *e) 96bool ListItemVisitor::visit(Event *e)
97{ 97{
98 98
99 bool ok = false; 99 bool ok = false;
100 QString start, end; 100 QString start, end;
101 QDate ds, de; 101 QDate ds, de;
102 if ( e->doesRecur() ) { 102 if ( e->doesRecur() ) {
103 ds = e->getNextOccurence( QDateTime( mDate, QTime(0,0,0)), &ok ).date(); 103 ds = e->getNextOccurence( QDateTime( mDate, QTime(0,0,0)), &ok ).date();
104 if ( ok ) { 104 if ( ok ) {
105 int days = e->dtStart().date().daysTo(e->dtEnd().date() ); 105 int days = e->dtStart().date().daysTo(e->dtEnd().date() );
106 start = KGlobal::locale()->formatDate(ds,true); 106 start = KGlobal::locale()->formatDate(ds,true);
107 de = ds.addDays( days); 107 de = ds.addDays( days);
108 end = KGlobal::locale()->formatDate(de,true); 108 end = KGlobal::locale()->formatDate(de,true);
109 } 109 }
110 110
111 } 111 }
112 if ( ! ok ) { 112 if ( ! ok ) {
113 start =e->dtStartDateStr(); 113 start =e->dtStartDateStr();
114 end = e->dtEndDateStr(); 114 end = e->dtEndDateStr();
115 ds = e->dtStart().date(); 115 ds = e->dtStart().date();
116 de = e->dtEnd().date(); 116 de = e->dtEnd().date();
117 } 117 }
118 mItem->setText(0,e->summary()); 118 mItem->setText(0,e->summary());
119 mItem->setText(1,start); 119 mItem->setText(1,start);
120 mItem->setText(2,e->dtStartTimeStr()); 120 mItem->setText(2,e->dtStartTimeStr());
121 mItem->setText(3,end); 121 mItem->setText(3,end);
122 mItem->setText(4,e->dtEndTimeStr()); 122 mItem->setText(4,e->dtEndTimeStr());
123 mItem->setText(5,e->isAlarmEnabled() ? i18n("Yes") : i18n("No")); 123 mItem->setText(5,e->isAlarmEnabled() ? i18n("Yes") : i18n("No"));
124 mItem->setText(6, e->recurrence()->recurrenceText()); 124 mItem->setText(6, e->recurrence()->recurrenceText());
125 mItem->setText(7,"---"); 125 mItem->setText(7,"---");
126 mItem->setText(8,"---"); 126 mItem->setText(8,"---");
127 mItem->setText(9, e->cancelled() ? i18n("Yes") : i18n("No")); 127 mItem->setText(9, e->cancelled() ? i18n("Yes") : i18n("No"));
128 mItem->setText(10,e->categoriesStr()); 128 mItem->setText(10,e->categoriesStr());
129 129
130 QString key; 130 QString key;
131 QTime t = e->doesFloat() ? QTime(0,0) : e->dtStart().time(); 131 QTime t = e->doesFloat() ? QTime(0,0) : e->dtStart().time();
132 key.sprintf("%04d%02d%02d%02d%02d",ds.year(),ds.month(),ds.day(),t.hour(),t.minute()); 132 key.sprintf("%04d%02d%02d%02d%02d",ds.year(),ds.month(),ds.day(),t.hour(),t.minute());
133 mItem->setSortKey(1,key); 133 mItem->setSortKey(1,key);
134 134
135 t = e->doesFloat() ? QTime(0,0) : e->dtEnd().time(); 135 t = e->doesFloat() ? QTime(0,0) : e->dtEnd().time();
136 key.sprintf("%04d%02d%02d%02d%02d",de.year(),de.month(),de.day(),t.hour(),t.minute()); 136 key.sprintf("%04d%02d%02d%02d%02d",de.year(),de.month(),de.day(),t.hour(),t.minute());
137 mItem->setSortKey(3,key); 137 mItem->setSortKey(3,key);
138 138
139 return true; 139 return true;
140} 140}
141 141
142bool ListItemVisitor::visit(Todo *t) 142bool ListItemVisitor::visit(Todo *t)
143{ 143{
144 mItem->setText(0,i18n("Todo: %1").arg(t->summary())); 144 mItem->setText(0,i18n("Todo: %1").arg(t->summary()));
145 if (t->hasStartDate()) { 145 if (t->hasStartDate()) {
146 mItem->setText(1,t->dtStartDateStr()); 146 mItem->setText(1,t->dtStartDateStr());
147 if (t->doesFloat()) { 147 if (t->doesFloat()) {
148 mItem->setText(2,"---"); 148 mItem->setText(2,"---");
149 } else { 149 } else {
150 mItem->setText(2,t->dtStartTimeStr()); 150 mItem->setText(2,t->dtStartTimeStr());
151 } 151 }
152 } else { 152 } else {
153 mItem->setText(1,"---"); 153 mItem->setText(1,"---");
154 mItem->setText(2,"---"); 154 mItem->setText(2,"---");
155 } 155 }
156 mItem->setText(3,"---"); 156 mItem->setText(3,"---");
157 mItem->setText(4,"---"); 157 mItem->setText(4,"---");
158 mItem->setText(5,t->isAlarmEnabled() ? i18n("Yes") : i18n("No")); 158 mItem->setText(5,t->isAlarmEnabled() ? i18n("Yes") : i18n("No"));
159 mItem->setText(6, t->recurrence()->recurrenceText()); 159 mItem->setText(6, t->recurrence()->recurrenceText());
160 if (t->hasDueDate()) { 160 if (t->hasDueDate()) {
161 mItem->setText(7,t->dtDueDateStr()); 161 mItem->setText(7,t->dtDueDateStr());
162 if (t->doesFloat()) { 162 if (t->doesFloat()) {
163 mItem->setText(8,"---"); 163 mItem->setText(8,"---");
164 } else { 164 } else {
165 mItem->setText(8,t->dtDueTimeStr()); 165 mItem->setText(8,t->dtDueTimeStr());
166 } 166 }
167 } else { 167 } else {
168 mItem->setText(7,"---"); 168 mItem->setText(7,"---");
169 mItem->setText(8,"---"); 169 mItem->setText(8,"---");
170 } 170 }
171 mItem->setText(9, t->cancelled() ? i18n("Yes") : i18n("No")); 171 mItem->setText(9, t->cancelled() ? i18n("Yes") : i18n("No"));
172 mItem->setText(10,t->categoriesStr()); 172 mItem->setText(10,t->categoriesStr());
173 173
174 QString key; 174 QString key;
175 QDate d; 175 QDate d;
176 if (t->hasDueDate()) { 176 if (t->hasDueDate()) {
177 d = t->dtDue().date(); 177 d = t->dtDue().date();
178 QTime tm = t->doesFloat() ? QTime(0,0) : t->dtDue().time(); 178 QTime tm = t->doesFloat() ? QTime(0,0) : t->dtDue().time();
179 key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute()); 179 key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute());
180 mItem->setSortKey(7,key); 180 mItem->setSortKey(7,key);
181 } 181 }
182 if ( t->hasStartDate() ) { 182 if ( t->hasStartDate() ) {
183 d = t->dtStart().date(); 183 d = t->dtStart().date();
184 QTime tm = t->doesFloat() ? QTime(0,0) : t->dtStart().time(); 184 QTime tm = t->doesFloat() ? QTime(0,0) : t->dtStart().time();
185 key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute()); 185 key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute());
186 mItem->setSortKey(1,key); 186 mItem->setSortKey(1,key);
187 } 187 }
188 return true; 188 return true;
189} 189}
190 190
191bool ListItemVisitor::visit(Journal * j) 191bool ListItemVisitor::visit(Journal * j)
192{ 192{
193 QString des = j->description().left(30); 193 QString des = j->description().left(30);
194 des = des.simplifyWhiteSpace (); 194 des = des.simplifyWhiteSpace ();
195 des.replace (QRegExp ("\\n"),"" ); 195 des.replace (QRegExp ("\\n"),"" );
196 des.replace (QRegExp ("\\r"),"" ); 196 des.replace (QRegExp ("\\r"),"" );
197 mItem->setText(0,i18n("Journal: ")+des.left(25)); 197 mItem->setText(0,i18n("Journal: ")+des.left(25));
198 mItem->setText(1,j->dtStartDateStr()); 198 mItem->setText(1,j->dtStartDateStr());
199 mItem->setText(2,"---"); 199 mItem->setText(2,"---");
200 mItem->setText(3,"---"); 200 mItem->setText(3,"---");
201 mItem->setText(4,"---"); 201 mItem->setText(4,"---");
202 mItem->setText(5,"---"); 202 mItem->setText(5,"---");
203 mItem->setText(6,"---"); 203 mItem->setText(6,"---");
204 mItem->setText(7,j->dtStartDateStr()); 204 mItem->setText(7,j->dtStartDateStr());
205 mItem->setText(8,"---"); 205 mItem->setText(8,"---");
206 mItem->setText(9,"---"); 206 mItem->setText(9,"---");
207 mItem->setText(10,i18n("Last Modified: ")+ KGlobal::locale()->formatDateTime( j->lastModified() , true) ); 207 mItem->setText(10,i18n("Last Modified: ")+ KGlobal::locale()->formatDateTime( j->lastModified() , true) );
208 208
209 QString key; 209 QString key;
210 QDate d = j->dtStart().date(); 210 QDate d = j->dtStart().date();
211 key.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 211 key.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
212 mItem->setSortKey(1,key); 212 mItem->setSortKey(1,key);
213 mItem->setSortKey(7,key); 213 mItem->setSortKey(7,key);
214 214
215 return true; 215 return true;
216} 216}
217 217
218KOListView::KOListView(Calendar *calendar, QWidget *parent, 218KOListView::KOListView(Calendar *calendar, QWidget *parent,
219 const char *name) 219 const char *name)
220 : KOEventView(calendar, parent, name) 220 : KOEventView(calendar, parent, name)
221{ 221{
222 mActiveItem = 0; 222 mActiveItem = 0;
223 mListView = new KOListViewListView(this); 223 mListView = new KOListViewListView(this);
224 mListView->addColumn(i18n("Summary")); 224 mListView->addColumn(i18n("Summary"));
225 mListView->addColumn(i18n("Start Date")); 225 mListView->addColumn(i18n("Start Date"));
226 mListView->addColumn(i18n("Start Time")); 226 mListView->addColumn(i18n("Start Time"));
227 mListView->addColumn(i18n("End Date")); 227 mListView->addColumn(i18n("End Date"));
228 mListView->addColumn(i18n("End Time")); 228 mListView->addColumn(i18n("End Time"));
229 mListView->addColumn(i18n("Alarm")); // alarm set? 229 mListView->addColumn(i18n("Alarm")); // alarm set?
230 mListView->addColumn(i18n("Recurs")); // recurs? 230 mListView->addColumn(i18n("Recurs")); // recurs?
231 mListView->addColumn(i18n("Due Date")); 231 mListView->addColumn(i18n("Due Date"));
232 mListView->addColumn(i18n("Due Time")); 232 mListView->addColumn(i18n("Due Time"));
233 mListView->addColumn(i18n("Cancelled")); 233 mListView->addColumn(i18n("Cancelled"));
234 mListView->addColumn(i18n("Categories")); 234 mListView->addColumn(i18n("Categories"));
235 235
236 mListView->setColumnAlignment(0,AlignLeft); 236 mListView->setColumnAlignment(0,AlignLeft);
237 mListView->setColumnAlignment(1,AlignLeft); 237 mListView->setColumnAlignment(1,AlignLeft);
238 mListView->setColumnAlignment(2,AlignHCenter); 238 mListView->setColumnAlignment(2,AlignHCenter);
239 mListView->setColumnAlignment(3,AlignLeft); 239 mListView->setColumnAlignment(3,AlignLeft);
240 mListView->setColumnAlignment(4,AlignHCenter); 240 mListView->setColumnAlignment(4,AlignHCenter);
241 mListView->setColumnAlignment(5,AlignLeft); 241 mListView->setColumnAlignment(5,AlignLeft);
242 mListView->setColumnAlignment(6,AlignLeft); 242 mListView->setColumnAlignment(6,AlignLeft);
243 mListView->setColumnAlignment(7,AlignLeft); 243 mListView->setColumnAlignment(7,AlignLeft);
244 mListView->setColumnAlignment(8,AlignLeft); 244 mListView->setColumnAlignment(8,AlignLeft);
245 mListView->setColumnAlignment(9,AlignLeft); 245 mListView->setColumnAlignment(9,AlignLeft);
246 mListView->setColumnAlignment(10,AlignLeft); 246 mListView->setColumnAlignment(10,AlignLeft);
247 mListView->setColumnWidthMode(10, QListView::Manual); 247 mListView->setColumnWidthMode(10, QListView::Manual);
248 new KOListViewWhatsThis(mListView->viewport(),this); 248 new KOListViewWhatsThis(mListView->viewport(),this);
249 249
250 int iii = 0; 250 int iii = 0;
251 for ( iii = 0; iii< 10 ; ++iii ) 251 for ( iii = 0; iii< 10 ; ++iii )
252 mListView->setColumnWidthMode( iii, QListView::Manual ); 252 mListView->setColumnWidthMode( iii, QListView::Manual );
253 253
254 QBoxLayout *layoutTop = new QVBoxLayout(this); 254 QBoxLayout *layoutTop = new QVBoxLayout(this);
255 layoutTop->addWidget(mListView); 255 layoutTop->addWidget(mListView);
256 mListView->setFont ( KOPrefs::instance()->mListViewFont ); 256 mListView->setFont ( KOPrefs::instance()->mListViewFont );
257 mPopupMenu = eventPopup(); 257 mPopupMenu = eventPopup();
258 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 258 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
259 i18n("Select all"),this, 259 i18n("Select all"),this,
260 SLOT(allSelection()),true); 260 SLOT(allSelection()),true);
261 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 261 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
262 i18n("Deselect all"),this, 262 i18n("Deselect all"),this,
263 SLOT(clearSelection()),true); 263 SLOT(clearSelection()),true);
264 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 264 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
265 i18n("Delete all selected"),this, 265 i18n("Delete all selected"),this,
266 SLOT(deleteAll()),true); 266 SLOT(deleteAll()),true);
267 mPopupMenu->insertSeparator(); 267 mPopupMenu->insertSeparator();
268 QPopupMenu * exportPO = new QPopupMenu ( this ); 268 QPopupMenu * exportPO = new QPopupMenu ( this );
269 mPopupMenu->insertItem( i18n("Export selected"), exportPO ); 269 mPopupMenu->insertItem( i18n("Export selected"), exportPO );
270 exportPO->insertItem( i18n("As iCal (ics) file..."),this, 270 exportPO->insertItem( i18n("As iCal (ics) file..."),this,
271 SLOT(saveToFile())); 271 SLOT(saveToFile()));
272 exportPO->insertItem( i18n("As vCal (vcs) file..."),this, 272 exportPO->insertItem( i18n("As vCal (vcs) file..."),this,
273 SLOT(saveToFileVCS())); 273 SLOT(saveToFileVCS()));
274 exportPO->insertItem( i18n("Journal/Details..."),this, 274 exportPO->insertItem( i18n("Journal/Details..."),this,
275 SLOT(saveDescriptionToFile())); 275 SLOT(saveDescriptionToFile()));
276 // mPopupMenu->insertSeparator(); 276 // mPopupMenu->insertSeparator();
277 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 277 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
278 i18n("Add Categ. to selected..."),this, 278 i18n("Add Categ. to selected..."),this,
279 SLOT(addCat()),true); 279 SLOT(addCat()),true);
280 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 280 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
281 i18n("Set Categ. for selected..."),this, 281 i18n("Set Categ. for selected..."),this,
282 SLOT(setCat()),true); 282 SLOT(setCat()),true);
283 //mPopupMenu->insertSeparator(); 283 //mPopupMenu->insertSeparator();
284 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 284 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
285 i18n("Set alarm for selected..."),this, 285 i18n("Set alarm for selected..."),this,
286 SLOT(setAlarm()),true); 286 SLOT(setAlarm()),true);
287 287
288 288
289#ifndef DESKTOP_VERSION 289#ifndef DESKTOP_VERSION
290 mPopupMenu->insertSeparator(); 290 mPopupMenu->insertSeparator();
291 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 291 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
292 i18n("Beam selected via IR"),this, 292 i18n("Beam selected via IR"),this,
293 SLOT(beamSelected()),true); 293 SLOT(beamSelected()),true);
294#endif 294#endif
295 /* 295 /*
296 mPopupMenu = new QPopupMenu; 296 mPopupMenu = new QPopupMenu;
297 mPopupMenu->insertItem(i18n("Edit Event"), this, 297 mPopupMenu->insertItem(i18n("Edit Event"), this,
298 SLOT (editEvent())); 298 SLOT (editEvent()));
299 mPopupMenu->insertItem(SmallIcon("delete"), i18n("Delete Event"), this, 299 mPopupMenu->insertItem(SmallIcon("delete"), i18n("Delete Event"), this,
300 SLOT (deleteEvent())); 300 SLOT (deleteEvent()));
301 mPopupMenu->insertSeparator(); 301 mPopupMenu->insertSeparator();
302 mPopupMenu->insertItem(i18n("Show Dates"), this, 302 mPopupMenu->insertItem(i18n("Show Dates"), this,
303 SLOT(showDates())); 303 SLOT(showDates()));
304 mPopupMenu->insertItem(i18n("Hide Dates"), this, 304 mPopupMenu->insertItem(i18n("Hide Dates"), this,
305 SLOT(hideDates())); 305 SLOT(hideDates()));
306 */ 306 */
307 QObject::connect(mListView,SIGNAL( newEvent()), 307 QObject::connect(mListView,SIGNAL( newEvent()),
308 this,SIGNAL(signalNewEvent())); 308 this,SIGNAL(signalNewEvent()));
309 QObject::connect(mListView,SIGNAL(doubleClicked(QListViewItem *)), 309 QObject::connect(mListView,SIGNAL(doubleClicked(QListViewItem *)),
310 this,SLOT(defaultItemAction(QListViewItem *))); 310 this,SLOT(defaultItemAction(QListViewItem *)));
311 QObject::connect(mListView,SIGNAL(rightButtonPressed( QListViewItem *, 311 QObject::connect(mListView,SIGNAL(rightButtonPressed( QListViewItem *,
312 const QPoint &, int )), 312 const QPoint &, int )),
313 this,SLOT(popupMenu(QListViewItem *,const QPoint &,int))); 313 this,SLOT(popupMenu(QListViewItem *,const QPoint &,int)));
314 QObject::connect(mListView,SIGNAL(currentChanged(QListViewItem *)), 314 QObject::connect(mListView,SIGNAL(currentChanged(QListViewItem *)),
315 SLOT(processSelectionChange(QListViewItem *))); 315 SLOT(processSelectionChange(QListViewItem *)));
316 QObject::connect(mListView,SIGNAL(showIncidence(Incidence *)), 316 QObject::connect(mListView,SIGNAL(showIncidence(Incidence *)),
317 SIGNAL(showIncidenceSignal(Incidence *)) ); 317 SIGNAL(showIncidenceSignal(Incidence *)) );
318 318
319 readSettings(KOGlobals::config(),"KOListView Layout"); 319 readSettings(KOGlobals::config(),"KOListView Layout");
320} 320}
321 321
322KOListView::~KOListView() 322KOListView::~KOListView()
323{ 323{
324 delete mPopupMenu; 324 delete mPopupMenu;
325} 325}
326QString KOListView::getWhatsThisText(QPoint p) 326QString KOListView::getWhatsThisText(QPoint p)
327{ 327{
328 KOListViewItem* item = ( KOListViewItem* ) mListView->itemAt( p ); 328 KOListViewItem* item = ( KOListViewItem* ) mListView->itemAt( p );
329 if ( item ) 329 if ( item )
330 return KIncidenceFormatter::instance()->getFormattedText( item->data(), 330 return KIncidenceFormatter::instance()->getFormattedText( item->data(),
331 KOPrefs::instance()->mWTshowDetails, 331 KOPrefs::instance()->mWTshowDetails,
332 KOPrefs::instance()->mWTshowCreated, 332 KOPrefs::instance()->mWTshowCreated,
333 KOPrefs::instance()->mWTshowChanged); 333 KOPrefs::instance()->mWTshowChanged);
334 return i18n("That is the list view" ); 334 return i18n("That is the list view" );
335 335
336} 336}
337 337
338void KOListView::updateList() 338void KOListView::updateList()
339{ 339{
340 // qDebug(" KOListView::updateList() "); 340 // qDebug(" KOListView::updateList() ");
341 341
342} 342}
343 343
344void KOListView::addCat( ) 344void KOListView::addCat( )
345{ 345{
346 setCategories( false ); 346 setCategories( false );
347} 347}
348void KOListView::setCat() 348void KOListView::setCat()
349{ 349{
350 setCategories( true ); 350 setCategories( true );
351} 351}
352void KOListView::setAlarm() 352void KOListView::setAlarm()
353{ 353{
354 KOAlarmPrefs kap( this); 354 KOAlarmPrefs kap( this);
355 if ( !kap.exec() ) 355 if ( !kap.exec() )
356 return; 356 return;
357 357
358 358
359 QStringList itemList; 359 QStringList itemList;
360 QPtrList<KOListViewItem> sel ; 360 QPtrList<KOListViewItem> sel ;
361 QListViewItem *qitem = mListView->firstChild (); 361 QListViewItem *qitem = mListView->firstChild ();
362 while ( qitem ) { 362 while ( qitem ) {
363 if ( qitem->isSelected() ) { 363 if ( qitem->isSelected() ) {
364 Incidence* inc = ((KOListViewItem *) qitem)->data(); 364 Incidence* inc = ((KOListViewItem *) qitem)->data();
365 if ( inc->type() != "Journal" ) { 365 if ( inc->type() != "Journal" ) {
366 if ( inc->type() == "Todo" ) { 366 if ( inc->type() == "Todo" ) {
367 if ( ((Todo*)inc)->hasDueDate() ) 367 if ( ((Todo*)inc)->hasDueDate() )
368 sel.append(((KOListViewItem *)qitem)); 368 sel.append(((KOListViewItem *)qitem));
369 } else 369 } else
370 sel.append(((KOListViewItem *)qitem)); 370 sel.append(((KOListViewItem *)qitem));
371 } 371 }
372 } 372 }
373 qitem = qitem->nextSibling(); 373 qitem = qitem->nextSibling();
374 } 374 }
375 int count = 0; 375 int count = 0;
376 KOListViewItem * item, *temp; 376 KOListViewItem * item, *temp;
377 item = sel.first(); 377 item = sel.first();
378 Incidence* inc; 378 Incidence* inc;
379 while ( item ) { 379 while ( item ) {
380 inc = item->data(); 380 inc = item->data();
381 ++count; 381 ++count;
382 if (kap.mAlarmButton->isChecked()) { 382 if (kap.mAlarmButton->isChecked()) {
383 if (inc->alarms().count() == 0) 383 if (inc->alarms().count() == 0)
384 inc->newAlarm(); 384 inc->newAlarm();
385 QPtrList<Alarm> alarms = inc->alarms(); 385 QPtrList<Alarm> alarms = inc->alarms();
386 Alarm *alarm; 386 Alarm *alarm;
387 for (alarm = alarms.first(); alarm; alarm = alarms.next() ) { 387 for (alarm = alarms.first(); alarm; alarm = alarms.next() ) {
388 alarm->setEnabled(true); 388 alarm->setEnabled(true);
389 int j = kap.mAlarmTimeEdit->value()* -60; 389 int j = kap.mAlarmTimeEdit->value()* -60;
390 if (kap.mAlarmIncrCombo->currentItem() == 1) 390 if (kap.mAlarmIncrCombo->currentItem() == 1)
391 j = j * 60; 391 j = j * 60;
392 else if (kap.mAlarmIncrCombo->currentItem() == 2) 392 else if (kap.mAlarmIncrCombo->currentItem() == 2)
393 j = j * (60 * 24); 393 j = j * (60 * 24);
394 alarm->setStartOffset( j ); 394 alarm->setStartOffset( j );
395 395
396 if (!kap.mAlarmProgram.isEmpty() && kap.mAlarmProgramButton->isOn()) { 396 if (!kap.mAlarmProgram.isEmpty() && kap.mAlarmProgramButton->isOn()) {
397 alarm->setProcedureAlarm(kap.mAlarmProgram); 397 alarm->setProcedureAlarm(kap.mAlarmProgram);
398 } 398 }
399 else if (!kap.mAlarmSound.isEmpty() && kap.mAlarmSoundButton->isOn()) 399 else if (!kap.mAlarmSound.isEmpty() && kap.mAlarmSoundButton->isOn())
400 alarm->setAudioAlarm(kap.mAlarmSound); 400 alarm->setAudioAlarm(kap.mAlarmSound);
401 else 401 else
402 alarm->setType(Alarm::Invalid); 402 alarm->setType(Alarm::Invalid);
403 //alarm->setAudioAlarm("default"); 403 //alarm->setAudioAlarm("default");
404 // TODO: Deal with multiple alarms 404 // TODO: Deal with multiple alarms
405 break; // For now, stop after the first alarm 405 break; // For now, stop after the first alarm
406 } 406 }
407 } else { 407 } else {
408 Alarm* alarm = inc->alarms().first(); 408 Alarm* alarm = inc->alarms().first();
409 if ( alarm ) { 409 if ( alarm ) {
410 alarm->setEnabled(false); 410 alarm->setEnabled(false);
411 alarm->setType(Alarm::Invalid); 411 alarm->setType(Alarm::Invalid);
412 } 412 }
413 } 413 }
414 temp = item; 414 temp = item;
415 item = sel.next(); 415 item = sel.next();
416 mUidDict.remove( inc->uid() ); 416 mUidDict.remove( inc->uid() );
417 delete temp;; 417 delete temp;;
418 addIncidence( inc ); 418 addIncidence( inc );
419 } 419 }
420 topLevelWidget()->setCaption( i18n("Canged alarm for %1 items").arg( count ) ); 420 topLevelWidget()->setCaption( i18n("Canged alarm for %1 items").arg( count ) );
421 qDebug("KO: Set alarm for %d items", count); 421 qDebug("KO: Set alarm for %d items", count);
422 calendar()->reInitAlarmSettings(); 422 calendar()->reInitAlarmSettings();
423} 423}
424void KOListView::setCategories( bool removeOld ) 424void KOListView::setCategories( bool removeOld )
425{ 425{
426 426
427 KPIM::CategorySelectDialog* csd = new KPIM::CategorySelectDialog( KOPrefs::instance(), 0 ); 427 KPIM::CategorySelectDialog* csd = new KPIM::CategorySelectDialog( KOPrefs::instance(), 0 );
428 if (! csd->exec()) { 428 if (! csd->exec()) {
429 delete csd; 429 delete csd;
430 return; 430 return;
431 } 431 }
432 QStringList catList = csd->selectedCategories(); 432 QStringList catList = csd->selectedCategories();
433 delete csd; 433 delete csd;
434 // if ( catList.count() == 0 ) 434 // if ( catList.count() == 0 )
435 // return; 435 // return;
436 catList.sort(); 436 catList.sort();
437 QString categoriesStr = catList.join(","); 437 QString categoriesStr = catList.join(",");
438 int i; 438 int i;
439 QStringList itemList; 439 QStringList itemList;
440 QPtrList<KOListViewItem> sel ; 440 QPtrList<KOListViewItem> sel ;
441 QListViewItem *qitem = mListView->firstChild (); 441 QListViewItem *qitem = mListView->firstChild ();
442 while ( qitem ) { 442 while ( qitem ) {
443 if ( qitem->isSelected() ) { 443 if ( qitem->isSelected() ) {
444 sel.append(((KOListViewItem *)qitem)); 444 sel.append(((KOListViewItem *)qitem));
445 } 445 }
446 qitem = qitem->nextSibling(); 446 qitem = qitem->nextSibling();
447 } 447 }
448 KOListViewItem * item, *temp; 448 KOListViewItem * item, *temp;
449 item = sel.first(); 449 item = sel.first();
450 Incidence* inc; 450 Incidence* inc;
451 while ( item ) { 451 while ( item ) {
452 inc = item->data(); 452 inc = item->data();
453 if ( removeOld ) { 453 if ( removeOld ) {
454 inc->setCategories( categoriesStr ); 454 inc->setCategories( categoriesStr );
455 } else { 455 } else {
456 itemList = QStringList::split (",", inc->categoriesStr() ); 456 itemList = QStringList::split (",", inc->categoriesStr() );
457 for( i = 0; i< catList.count(); ++i ) { 457 for( i = 0; i< catList.count(); ++i ) {
458 if ( !itemList.contains (catList[i])) 458 if ( !itemList.contains (catList[i]))
459 itemList.append( catList[i] ); 459 itemList.append( catList[i] );
460 } 460 }
461 itemList.sort(); 461 itemList.sort();
462 inc->setCategories( itemList.join(",") ); 462 inc->setCategories( itemList.join(",") );
463 } 463 }
464 temp = item; 464 temp = item;
465 item = sel.next(); 465 item = sel.next();
466 mUidDict.remove( inc->uid() ); 466 mUidDict.remove( inc->uid() );
467 delete temp;; 467 delete temp;;
468 addIncidence( inc ); 468 addIncidence( inc );
469 } 469 }
470} 470}
471 471
472void KOListView::beamSelected() 472void KOListView::beamSelected()
473{ 473{
474 int icount = 0; 474 int icount = 0;
475 QPtrList<Incidence> delSel ; 475 QPtrList<Incidence> delSel ;
476 QListViewItem *item = mListView->firstChild (); 476 QListViewItem *item = mListView->firstChild ();
477 while ( item ) { 477 while ( item ) {
478 if ( item->isSelected() ) { 478 if ( item->isSelected() ) {
479 delSel.append(((KOListViewItem *)item)->data()); 479 delSel.append(((KOListViewItem *)item)->data());
480 ++icount; 480 ++icount;
481 } 481 }
482 482
483 item = item->nextSibling(); 483 item = item->nextSibling();
484 } 484 }
485 if ( icount ) { 485 if ( icount ) {
486 emit beamIncidenceList( delSel ); 486 emit beamIncidenceList( delSel );
487 return; 487 return;
488 QString fn ; 488 QString fn ;
489 fn = QDir::homeDirPath()+"/kopitempbeamfile.vcs"; 489 fn = QDir::homeDirPath()+"/kopitempbeamfile.vcs";
490 QString mes; 490 QString mes;
491 bool createbup = true; 491 bool createbup = true;
492 if ( createbup ) { 492 if ( createbup ) {
493 QString description = "\n"; 493 QString description = "\n";
494 CalendarLocal* cal = new CalendarLocal(); 494 CalendarLocal* cal = new CalendarLocal();
495 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 495 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
496 Incidence *incidence = delSel.first(); 496 Incidence *incidence = delSel.first();
497 while ( incidence ) { 497 while ( incidence ) {
498 Incidence *in = incidence->clone(); 498 Incidence *in = incidence->clone();
499 description += in->summary() + "\n"; 499 description += in->summary() + "\n";
500 cal->addIncidence( in ); 500 cal->addIncidence( in );
501 incidence = delSel.next(); 501 incidence = delSel.next();
502 } 502 }
503 FileStorage storage( cal, fn, new VCalFormat ); 503 FileStorage storage( cal, fn, new VCalFormat );
504 storage.save(); 504 storage.save();
505 delete cal; 505 delete cal;
506 mes = i18n("KO/Pi: Ready for beaming"); 506 mes = i18n("KO/Pi: Ready for beaming");
507 topLevelWidget()->setCaption(mes); 507 topLevelWidget()->setCaption(mes);
508 508
509#ifndef DESKTOP_VERSION 509#ifndef DESKTOP_VERSION
510 Ir *ir = new Ir( this ); 510 Ir *ir = new Ir( this );
511 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 511 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
512 ir->send( fn, description, "text/x-vCalendar" ); 512 ir->send( fn, description, "text/x-vCalendar" );
513#endif 513#endif
514 } 514 }
515 } 515 }
516} 516}
517void KOListView::beamDone( Ir *ir ) 517void KOListView::beamDone( Ir *ir )
518{ 518{
519#ifndef DESKTOP_VERSION 519#ifndef DESKTOP_VERSION
520 delete ir; 520 delete ir;
521#endif 521#endif
522 topLevelWidget()->setCaption(i18n("KO/Pi:Beaming done")); 522 topLevelWidget()->setCaption(i18n("KO/Pi:Beaming done"));
523} 523}
524 524
525void KOListView::saveDescriptionToFile() 525void KOListView::saveDescriptionToFile()
526{ 526{
527 527
528 int result = QMessageBox::warning( this, i18n("KO/Pi: Information!"), 528 int result = QMessageBox::warning( this, i18n("KO/Pi: Information!"),
529 i18n("This saves the text/details of selected\nJournals and Events/Todos\nto a text file."), 529 i18n("This saves the text/details of selected\nJournals and Events/Todos\nto a text file."),
530 i18n("Continue"), i18n("Cancel"), 0, 530 i18n("Continue"), i18n("Cancel"), 0,
531 0, 1 ); 531 0, 1 );
532 if ( result != 0 ) { 532 if ( result != 0 ) {
533 return; 533 return;
534 } 534 }
535 int icount = 0; 535 int icount = 0;
536 QPtrList<Incidence> delSel ; 536 QPtrList<Incidence> delSel ;
537 QListViewItem *item = mListView->firstChild (); 537 QListViewItem *item = mListView->firstChild ();
538 while ( item ) { 538 while ( item ) {
539 if ( item->isSelected() ) { 539 if ( item->isSelected() ) {
540 delSel.append(((KOListViewItem *)item)->data()); 540 delSel.append(((KOListViewItem *)item)->data());
541 ++icount; 541 ++icount;
542 } 542 }
543 543
544 item = item->nextSibling(); 544 item = item->nextSibling();
545 } 545 }
546 if ( icount ) { 546 if ( icount ) {
547 QString fn = KOPrefs::instance()->mLastSaveFile; 547 QString fn = KOPrefs::instance()->mLastSaveFile;
548 fn = KFileDialog::getSaveFileName( fn, i18n("Save filename"), this ); 548 fn = KFileDialog::getSaveFileName( fn, i18n("Save filename"), this );
549 549
550 if ( fn == "" ) 550 if ( fn == "" )
551 return; 551 return;
552 QFileInfo info; 552 QFileInfo info;
553 info.setFile( fn ); 553 info.setFile( fn );
554 QString mes; 554 QString mes;
555 bool createbup = true; 555 bool createbup = true;
556 if ( info. exists() ) { 556 if ( info. exists() ) {
557 mes = i18n("File already exists!\nOld file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); 557 mes = i18n("File already exists!\nOld file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) );
558 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, 558 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
559 i18n("Overwrite!"), i18n("Cancel"), 0, 559 i18n("Overwrite!"), i18n("Cancel"), 0,
560 0, 1 ); 560 0, 1 );
561 if ( result != 0 ) { 561 if ( result != 0 ) {
562 createbup = false; 562 createbup = false;
563 } 563 }
564 } 564 }
565 if ( createbup ) { 565 if ( createbup ) {
566 QString text = i18n("KO/Pi Description/Journal save file.\nSave date: ") + 566 QString text = i18n("KO/Pi Description/Journal save file.\nSave date: ") +
567 KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), false); 567 KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), false);
568 Incidence *incidence = delSel.first(); 568 Incidence *incidence = delSel.first();
569 icount = 0; 569 icount = 0;
570 while ( incidence ) { 570 while ( incidence ) {
571 if ( incidence->type() == "Journal" ) { 571 if ( incidence->type() == "Journal" ) {
572 text += "\n************************************\n"; 572 text += "\n************************************\n";
573 text += i18n("Journal from: ") +incidence->dtStartDateStr( false ); 573 text += i18n("Journal from: ") +incidence->dtStartDateStr( false );
574 text +="\n" + i18n("Last modified: ") +KGlobal::locale()->formatDateTime(incidence->lastModified(), false); 574 text +="\n" + i18n("Last modified: ") +KGlobal::locale()->formatDateTime(incidence->lastModified(), false);
575 text +="\n" + i18n("Description: ") + "\n"+ incidence->description(); 575 text +="\n" + i18n("Description: ") + "\n"+ incidence->description();
576 ++icount; 576 ++icount;
577 577
578 } else { 578 } else {
579 if ( !incidence->description().isEmpty() ) { 579 if ( !incidence->description().isEmpty() ) {
580 text += "\n************************************\n"; 580 text += "\n************************************\n";
581 if ( incidence->type() == "Todo" ) 581 if ( incidence->type() == "Todo" )
582 text += i18n("To-Do: "); 582 text += i18n("To-Do: ");
583 text += incidence->summary(); 583 text += incidence->summary();
584 if ( incidence->hasStartDate() ) 584 if ( incidence->hasStartDate() )
585 text +="\n"+ i18n("Start Date: ") + incidence->dtStartStr( false ); 585 text +="\n"+ i18n("Start Date: ") + incidence->dtStartStr( false );
586 text +="\n"+ i18n("Last modified: ") +KGlobal::locale()->formatDateTime(incidence->lastModified(), false); 586 text +="\n"+ i18n("Last modified: ") +KGlobal::locale()->formatDateTime(incidence->lastModified(), false);
587 if ( !incidence->location().isEmpty() ) 587 if ( !incidence->location().isEmpty() )
588 text += "\n" +i18n("Location: ") + incidence->location(); 588 text += "\n" +i18n("Location: ") + incidence->location();
589 text += "\n" + i18n("Description: ") + "\n" + incidence->description(); 589 text += "\n" + i18n("Description: ") + "\n" + incidence->description();
590 ++icount; 590 ++icount;
591 591
592 } 592 }
593 } 593 }
594 incidence = delSel.next(); 594 incidence = delSel.next();
595 } 595 }
596 QFile file( fn ); 596 QFile file( fn );
597 if (!file.open( IO_WriteOnly ) ) { 597 if (!file.open( IO_WriteOnly ) ) {
598 topLevelWidget()->setCaption(i18n("File open error - nothing saved!") ); 598 topLevelWidget()->setCaption(i18n("File open error - nothing saved!") );
599 return; 599 return;
600 } 600 }
601 QTextStream ts( &file ); 601 QTextStream ts( &file );
602 ts << text; 602 ts << text;
603 file.close(); 603 file.close();
604 //qDebug("%s ", text.latin1()); 604 //qDebug("%s ", text.latin1());
605 mes = i18n("KO/Pi:Saved %1 descriptions/journals").arg(icount ); 605 mes = i18n("KO/Pi:Saved %1 descriptions/journals").arg(icount );
606 KOPrefs::instance()->mLastSaveFile = fn; 606 KOPrefs::instance()->mLastSaveFile = fn;
607 topLevelWidget()->setCaption(mes); 607 topLevelWidget()->setCaption(mes);
608 } 608 }
609 } 609 }
610} 610}
611void KOListView::saveToFileVCS() 611void KOListView::saveToFileVCS()
612{ 612{
613 writeToFile( false ); 613 writeToFile( false );
614} 614}
615void KOListView::saveToFile() 615void KOListView::saveToFile()
616{ 616{
617 writeToFile( true ); 617 writeToFile( true );
618} 618}
619void KOListView::writeToFile( bool iCal ) 619void KOListView::writeToFile( bool iCal )
620{ 620{
621 621
622 int icount = 0; 622 int icount = 0;
623 QPtrList<Incidence> delSel ; 623 QPtrList<Incidence> delSel ;
624 QListViewItem *item = mListView->firstChild (); 624 QListViewItem *item = mListView->firstChild ();
625 bool journal = iCal; // warn only for vCal 625 bool journal = iCal; // warn only for vCal
626 while ( item ) { 626 while ( item ) {
627 if ( item->isSelected() ) { 627 if ( item->isSelected() ) {
628 if ( !journal ) 628 if ( !journal )
629 if ( ((KOListViewItem *)item)->data()->type() == "Journal") 629 if ( ((KOListViewItem *)item)->data()->type() == "Journal")
630 journal = true; 630 journal = true;
631 delSel.append(((KOListViewItem *)item)->data()); 631 delSel.append(((KOListViewItem *)item)->data());
632 ++icount; 632 ++icount;
633 } 633 }
634 634
635 item = item->nextSibling(); 635 item = item->nextSibling();
636 } 636 }
637 if ( !iCal && journal ) { 637 if ( !iCal && journal ) {
638 int result = KMessageBox::warningContinueCancel(this, 638 int result = KMessageBox::warningContinueCancel(this,
639 i18n("The journal entries can not be\nexported to a vCalendar file."), 639 i18n("The journal entries can not be\nexported to a vCalendar file."),
640 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 640 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
641 true); 641 true);
642 if (result != KMessageBox::Continue) return; 642 if (result != KMessageBox::Continue) return;
643 } 643 }
644 if ( icount ) { 644 if ( icount ) {
645 QString fn = KOPrefs::instance()->mLastSaveFile; 645 QString fn = KOPrefs::instance()->mLastSaveFile;
646 QString extension; 646 QString extension;
647 if ( iCal ) { 647 if ( iCal ) {
648 if ( fn.right( 4 ).lower() == ".vcs" ) { 648 if ( fn.right( 4 ).lower() == ".vcs" ) {
649 fn = fn.left( fn.length() -3) + "ics"; 649 fn = fn.left( fn.length() -3) + "ics";
650 } 650 }
651 } else { 651 } else {
652 if ( fn.right( 4 ).lower() == ".ics" ) { 652 if ( fn.right( 4 ).lower() == ".ics" ) {
653 fn = fn.left( fn.length() -3) + "vcs"; 653 fn = fn.left( fn.length() -3) + "vcs";
654 } 654 }
655 } 655 }
656 fn = KFileDialog::getSaveFileName( fn, i18n("Save filename"), this ); 656 fn = KFileDialog::getSaveFileName( fn, i18n("Save filename"), this );
657 657
658 if ( fn == "" ) 658 if ( fn == "" )
659 return; 659 return;
660 QFileInfo info; 660 QFileInfo info;
661 info.setFile( fn ); 661 info.setFile( fn );
662 QString mes; 662 QString mes;
663 bool createbup = true; 663 bool createbup = true;
664 if ( info. exists() ) { 664 if ( info. exists() ) {
665 mes = i18n("File already exists!\nOld file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); 665 mes = i18n("File already exists!\nOld file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) );
666 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, 666 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
667 i18n("Overwrite!"), i18n("Cancel"), 0, 667 i18n("Overwrite!"), i18n("Cancel"), 0,
668 0, 1 ); 668 0, 1 );
669 if ( result != 0 ) { 669 if ( result != 0 ) {
670 createbup = false; 670 createbup = false;
671 } 671 }
672 } 672 }
673 if ( createbup ) { 673 if ( createbup ) {
674 CalendarLocal cal; 674 CalendarLocal cal;
675 cal.setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 675 cal.setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
676 Incidence *incidence = delSel.first(); 676 Incidence *incidence = delSel.first();
677 while ( incidence ) { 677 while ( incidence ) {
678 cal.addIncidence( incidence->clone() ); 678 cal.addIncidence( incidence->clone() );
679 incidence = delSel.next(); 679 incidence = delSel.next();
680 } 680 }
681 if ( iCal ) { 681 if ( iCal ) {
682 ICalFormat format; 682 ICalFormat format;
683 format.save( &cal, fn ); 683 format.save( &cal, fn );
684 } else { 684 } else {
685 685
686 VCalFormat format; 686 VCalFormat format;
687 format.save( &cal, fn ); 687 format.save( &cal, fn );
688 } 688 }
689 mes = i18n("KO/Pi:Saved %1").arg(fn ); 689 mes = i18n("KO/Pi:Saved %1").arg(fn );
690 KOPrefs::instance()->mLastSaveFile = fn; 690 KOPrefs::instance()->mLastSaveFile = fn;
691 topLevelWidget()->setCaption(mes); 691 topLevelWidget()->setCaption(mes);
692 } 692 }
693 } 693 }
694} 694}
695void KOListView::deleteAll() 695void KOListView::deleteAll()
696{ 696{
697 int icount = 0; 697 int icount = 0;
698 QPtrList<Incidence> delSel ; 698 QPtrList<Incidence> delSel ;
699 QListViewItem *item = mListView->firstChild (); 699 QListViewItem *item = mListView->firstChild ();
700 while ( item ) { 700 while ( item ) {
701 if ( item->isSelected() ) { 701 if ( item->isSelected() ) {
702 delSel.append(((KOListViewItem *)item)->data()); 702 delSel.append(((KOListViewItem *)item)->data());
703 ++icount; 703 ++icount;
704 } 704 }
705 705
706 item = item->nextSibling(); 706 item = item->nextSibling();
707 } 707 }
708 if ( icount ) { 708 if ( icount ) {
709 Incidence *incidence = delSel.first(); 709 Incidence *incidence = delSel.first();
710 Incidence *toDelete; 710 Incidence *toDelete;
711 KOPrefs *p = KOPrefs::instance(); 711 KOPrefs *p = KOPrefs::instance();
712 bool confirm = p->mConfirm; 712 bool confirm = p->mConfirm;
713 QString mess; 713 QString mess;
714 mess = mess.sprintf( i18n("You have %d item(s) selected.\n"), icount ); 714 mess = mess.sprintf( i18n("You have %d item(s) selected.\n"), icount );
715 if ( KMessageBox::Continue == KMessageBox::warningContinueCancel(this, mess + i18n("All selected items will be\npermanently deleted.\n(Deleting items will take\nsome time on a PDA)\n"), i18n("KO/Pi Confirmation"),i18n("Delete")) ) { 715 if ( KMessageBox::Continue == KMessageBox::warningContinueCancel(this, mess + i18n("All selected items will be\npermanently deleted.\n(Deleting items will take\nsome time on a PDA)\n"), i18n("KO/Pi Confirmation"),i18n("Delete")) ) {
716 p->mConfirm = false; 716 p->mConfirm = false;
717 int delCounter = 0; 717 int delCounter = 0;
718 QDialog dia ( this, "p-dialog", true ); 718 QDialog dia ( this, "p-dialog", true );
719 QLabel lab (i18n("Close dialog to abort deletion!"), &dia ); 719 QLabel lab (i18n("Close dialog to abort deletion!"), &dia );
720 QVBoxLayout lay( &dia ); 720 QVBoxLayout lay( &dia );
721 lay.setMargin(7); 721 lay.setMargin(7);
722 lay.setSpacing(7); 722 lay.setSpacing(7);
723 lay.addWidget( &lab); 723 lay.addWidget( &lab);
724 QProgressBar bar( icount, &dia ); 724 QProgressBar bar( icount, &dia );
725 lay.addWidget( &bar); 725 lay.addWidget( &bar);
726 int w = 220; 726 int w = 220;
727 int h = 50; 727 int h = 50;
728 int dw = QApplication::desktop()->width(); 728 int dw = QApplication::desktop()->width();
729 int dh = QApplication::desktop()->height(); 729 int dh = QApplication::desktop()->height();
730 dia.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 730 dia.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
731 //dia.resize( 240,50 ); 731 //dia.resize( 240,50 );
732 dia.show(); 732 dia.show();
733 733
734 while ( incidence ) { 734 while ( incidence ) {
735 bar.setProgress( delCounter ); 735 bar.setProgress( delCounter );
736 mess = mess.sprintf( i18n("Deleting item %d ..."), ++delCounter ); 736 mess = mess.sprintf( i18n("Deleting item %d ..."), ++delCounter );
737 dia.setCaption( mess ); 737 dia.setCaption( mess );
738 qApp->processEvents(); 738 qApp->processEvents();
739 toDelete = (incidence); 739 toDelete = (incidence);
740 incidence = delSel.next(); 740 incidence = delSel.next();
741 emit deleteIncidenceSignal(toDelete ); 741 emit deleteIncidenceSignal(toDelete );
742 if ( dia.result() != 0 ) 742 if ( dia.result() != 0 )
743 break; 743 break;
744 744
745 } 745 }
746 mess = mess.sprintf( i18n("%d items remaining in list."), count() ); 746 mess = mess.sprintf( i18n("%d items remaining in list."), count() );
747 topLevelWidget ()->setCaption( mess ); 747 topLevelWidget ()->setCaption( mess );
748 p->mConfirm = confirm; 748 p->mConfirm = confirm;
749 } 749 }
750 } 750 }
751 751
752 752
753} 753}
754int KOListView::maxDatesHint() 754int KOListView::maxDatesHint()
755{ 755{
756 return 0; 756 return 0;
757} 757}
758 758
759int KOListView::currentDateCount() 759int KOListView::currentDateCount()
760{ 760{
761 return 0; 761 return 0;
762} 762}
763 763
764QPtrList<Incidence> KOListView::selectedIncidences() 764QPtrList<Incidence> KOListView::selectedIncidences()
765{ 765{
766 QPtrList<Incidence> eventList; 766 QPtrList<Incidence> eventList;
767 QListViewItem *item = mListView->firstChild (); 767 QListViewItem *item = mListView->firstChild ();
768 while ( item ) { 768 while ( item ) {
769 if ( item->isSelected() ) { 769 if ( item->isSelected() ) {
770 eventList.append(((KOListViewItem *)item)->data()); 770 eventList.append(((KOListViewItem *)item)->data());
771 } 771 }
772 772
773 item = item->nextSibling(); 773 item = item->nextSibling();
774 } 774 }
775 775
776 // // QListViewItem *item = mListView->selectedItem(); 776 // // QListViewItem *item = mListView->selectedItem();
777 //if (item) eventList.append(((KOListViewItem *)item)->data()); 777 //if (item) eventList.append(((KOListViewItem *)item)->data());
778 778
779 return eventList; 779 return eventList;
780} 780}
781 781
782DateList KOListView::selectedDates() 782DateList KOListView::selectedDates()
783{ 783{
784 DateList eventList; 784 DateList eventList;
785 return eventList; 785 return eventList;
786} 786}
787 787
788void KOListView::showDates(bool show) 788void KOListView::showDates(bool show)
789{ 789{
790 // Shouldn't we set it to a value greater 0? When showDates is called with 790 // Shouldn't we set it to a value greater 0? When showDates is called with
791 // show == true at first, then the columnwidths are set to zero. 791 // show == true at first, then the columnwidths are set to zero.
792 static int oldColWidth1 = 0; 792 static int oldColWidth1 = 0;
793 static int oldColWidth3 = 0; 793 static int oldColWidth3 = 0;
794 794
795 if (!show) { 795 if (!show) {
796 oldColWidth1 = mListView->columnWidth(1); 796 oldColWidth1 = mListView->columnWidth(1);
797 oldColWidth3 = mListView->columnWidth(3); 797 oldColWidth3 = mListView->columnWidth(3);
798 mListView->setColumnWidth(1, 0); 798 mListView->setColumnWidth(1, 0);
799 mListView->setColumnWidth(3, 0); 799 mListView->setColumnWidth(3, 0);
800 } else { 800 } else {
801 mListView->setColumnWidth(1, oldColWidth1); 801 mListView->setColumnWidth(1, oldColWidth1);
802 mListView->setColumnWidth(3, oldColWidth3); 802 mListView->setColumnWidth(3, oldColWidth3);
803 } 803 }
804 mListView->repaint(); 804 mListView->repaint();
805} 805}
806 806
807void KOListView::printPreview(CalPrinter *calPrinter, const QDate &fd, 807void KOListView::printPreview(CalPrinter *calPrinter, const QDate &fd,
808 const QDate &td) 808 const QDate &td)
809{ 809{
810#ifndef KORG_NOPRINTER 810#ifndef KORG_NOPRINTER
811 calPrinter->preview(CalPrinter::Day, fd, td); 811 calPrinter->preview(CalPrinter::Day, fd, td);
812#endif 812#endif
813} 813}
814 814
815void KOListView::showDates() 815void KOListView::showDates()
816{ 816{
817 showDates(true); 817 showDates(true);
818} 818}
819 819
820void KOListView::hideDates() 820void KOListView::hideDates()
821{ 821{
822 showDates(false); 822 showDates(false);
823} 823}
824void KOListView::resetFocus() 824void KOListView::resetFocus()
825{ 825{
826 mListView->setFocus(); 826 mListView->setFocus();
827} 827}
828void KOListView::updateView() 828void KOListView::updateView()
829{ 829{
830 mListView->setFocus(); 830 mListView->setFocus();
831 if ( mListView->firstChild () ) 831 if ( mListView->firstChild () )
832 mListView->setCurrentItem( mListView->firstChild () ); 832 mListView->setCurrentItem( mListView->firstChild () );
833} 833}
834void KOListView::updateConfig() 834void KOListView::updateConfig()
835{ 835{
836 836
837 mListView->setFont ( KOPrefs::instance()->mListViewFont ); 837 mListView->setFont ( KOPrefs::instance()->mListViewFont );
838 updateView(); 838 updateView();
839 839
840} 840}
841void KOListView::setStartDate(const QDate &start) 841void KOListView::setStartDate(const QDate &start)
842{ 842{
843 mStartDate = start; 843 mStartDate = start;
844} 844}
845 845
846void KOListView::showDates(const QDate &start, const QDate &end) 846void KOListView::showDates(const QDate &start, const QDate &end)
847{ 847{
848 clear(); 848 clear();
849 mStartDate = start; 849 mStartDate = start;
850 QDate date = start; 850 QDate date = start;
851 QPtrList<Journal> j_list; 851 QPtrList<Journal> j_list;
852 while( date <= end ) { 852 while( date <= end ) {
853 addEvents(calendar()->events(date)); 853 addEvents(calendar()->events(date));
854 addTodos(calendar()->todos(date)); 854 addTodos(calendar()->todos(date));
855 Journal* jo = calendar()->journal(date); 855 Journal* jo = calendar()->journal(date);
856 if ( jo ) 856 if ( jo )
857 j_list.append( jo ); 857 j_list.append( jo );
858 date = date.addDays( 1 ); 858 date = date.addDays( 1 );
859 } 859 }
860 addJournals(j_list); 860 addJournals(j_list);
861 emit incidenceSelected( 0 ); 861 emit incidenceSelected( 0 );
862 updateView(); 862 updateView();
863 863
864} 864}
865 865
866void KOListView::addEvents(QPtrList<Event> eventList) 866void KOListView::addEvents(QPtrList<Event> eventList)
867{ 867{
868 Event *ev; 868 Event *ev;
869 for(ev = eventList.first(); ev; ev = eventList.next()) { 869 for(ev = eventList.first(); ev; ev = eventList.next()) {
870 addIncidence(ev); 870 addIncidence(ev);
871 } 871 }
872 if ( !mListView->currentItem() ){ 872 if ( !mListView->currentItem() ){
873 updateView(); 873 updateView();
874 } 874 }
875} 875}
876 876
877void KOListView::addTodos(QPtrList<Todo> eventList) 877void KOListView::addTodos(QPtrList<Todo> eventList)
878{ 878{
879 Todo *ev; 879 Todo *ev;
880 for(ev = eventList.first(); ev; ev = eventList.next()) { 880 for(ev = eventList.first(); ev; ev = eventList.next()) {
881 addIncidence(ev); 881 addIncidence(ev);
882 } 882 }
883 if ( !mListView->currentItem() ){ 883 if ( !mListView->currentItem() ){
884 updateView(); 884 updateView();
885 } 885 }
886} 886}
887void KOListView::addJournals(QPtrList<Journal> eventList) 887void KOListView::addJournals(QPtrList<Journal> eventList)
888{ 888{
889 Journal *ev; 889 Journal *ev;
890 for(ev = eventList.first(); ev; ev = eventList.next()) { 890 for(ev = eventList.first(); ev; ev = eventList.next()) {
891 addIncidence(ev); 891 addIncidence(ev);
892 } 892 }
893 if ( !mListView->currentItem() ){ 893 if ( !mListView->currentItem() ){
894 updateView(); 894 updateView();
895 } 895 }
896} 896}
897 897
898void KOListView::addIncidence(Incidence *incidence) 898void KOListView::addIncidence(Incidence *incidence)
899{ 899{
900 if ( mUidDict.find( incidence->uid() ) ) return; 900 if ( mUidDict.find( incidence->uid() ) ) return;
901 901
902 // mListView->setFont ( KOPrefs::instance()->mListViewFont ); 902 // mListView->setFont ( KOPrefs::instance()->mListViewFont );
903 mUidDict.insert( incidence->uid(), incidence ); 903 mUidDict.insert( incidence->uid(), incidence );
904 904
905 KOListViewItem *item = new KOListViewItem( incidence, mListView ); 905 KOListViewItem *item = new KOListViewItem( incidence, mListView );
906 ListItemVisitor v(item, mStartDate ); 906 ListItemVisitor v(item, mStartDate );
907 if (incidence->accept(v)) return; 907 if (incidence->accept(v)) return;
908 else delete item; 908 else delete item;
909 //qDebug("delete item "); 909 //qDebug("delete item ");
910} 910}
911 911
912void KOListView::showEvents(QPtrList<Event> eventList) 912void KOListView::showEvents(QPtrList<Event> eventList)
913{ 913{
914 clear(); 914 clear();
915 915
916 addEvents(eventList); 916 addEvents(eventList);
917 917
918 // After new creation of list view no events are selected. 918 // After new creation of list view no events are selected.
919 emit incidenceSelected( 0 ); 919 emit incidenceSelected( 0 );
920} 920}
921int KOListView::count() 921int KOListView::count()
922{ 922{
923 return mListView->childCount(); 923 return mListView->childCount();
924} 924}
925 925
926void KOListView::changeEventDisplay(Event *event, int action) 926void KOListView::changeEventDisplay(Event *event, int action)
927{ 927{
928 KOListViewItem *item; 928 KOListViewItem *item;
929 929
930 switch(action) { 930 switch(action) {
931 case KOGlobals::EVENTADDED: 931 case KOGlobals::EVENTADDED:
932 addIncidence( event ); 932 addIncidence( event );
933 break; 933 break;
934 case KOGlobals::EVENTEDITED: 934 case KOGlobals::EVENTEDITED:
935 item = getItemForEvent(event); 935 item = getItemForEvent(event);
936 if (item) { 936 if (item) {
937 mUidDict.remove( event->uid() ); 937 mUidDict.remove( event->uid() );
938 delete item; 938 delete item;
939 addIncidence( event ); 939 addIncidence( event );
940 } 940 }
941 break; 941 break;
942 case KOGlobals::EVENTDELETED: 942 case KOGlobals::EVENTDELETED:
943 item = getItemForEvent(event); 943 item = getItemForEvent(event);
944 if (item) { 944 if (item) {
945 mUidDict.remove( event->uid() ); 945 mUidDict.remove( event->uid() );
946 delete item; 946 delete item;
947 } 947 }
948 break; 948 break;
949 default: 949 default:
950 ; 950 ;
951 } 951 }
952} 952}
953 953
954KOListViewItem *KOListView::getItemForEvent(Event *event) 954KOListViewItem *KOListView::getItemForEvent(Event *event)
955{ 955{
956 KOListViewItem *item = (KOListViewItem *)mListView->firstChild(); 956 KOListViewItem *item = (KOListViewItem *)mListView->firstChild();
957 while (item) { 957 while (item) {
958 if (item->data() == event) return item; 958 if (item->data() == event) return item;
959 item = (KOListViewItem *)item->nextSibling(); 959 item = (KOListViewItem *)item->nextSibling();
960 } 960 }
961 return 0; 961 return 0;
962} 962}
963 963
964void KOListView::defaultItemAction(QListViewItem *i) 964void KOListView::defaultItemAction(QListViewItem *i)
965{ 965{
966 KOListViewItem *item = static_cast<KOListViewItem *>( i ); 966 KOListViewItem *item = static_cast<KOListViewItem *>( i );
967 if ( item ) defaultAction( item->data() ); 967 if ( item ) defaultAction( item->data() );
968 968
969} 969}
970 970
971void KOListView::popupMenu(QListViewItem *item,const QPoint &,int) 971void KOListView::popupMenu(QListViewItem *item,const QPoint &,int)
972{ 972{
973 mActiveItem = (KOListViewItem *)item; 973 mActiveItem = (KOListViewItem *)item;
974 if (mActiveItem) { 974 if (mActiveItem) {
975 Incidence *incidence = mActiveItem->data(); 975 Incidence *incidence = mActiveItem->data();
976 mPopupMenu->showIncidencePopup(incidence); 976 mPopupMenu->showIncidencePopup(incidence);
977 977
978 /* 978 /*
979 if ( incidence && incidence->type() == "Event" ) { 979 if ( incidence && incidence->type() == "Event" ) {
980 Event *event = static_cast<Event *>( incidence ); 980 Event *event = static_cast<Event *>( incidence );
981 mPopupMenu->showEventPopup(event); 981 mPopupMenu->showEventPopup(event);
982 } 982 }
983 */ 983 */
984 } 984 }
985} 985}
986 986
987void KOListView::readSettings(KConfig *config, QString setting) 987void KOListView::readSettings(KConfig *config, QString setting)
988{ 988{
989 // qDebug("KOListView::readSettings "); 989 // qDebug("KOListView::readSettings ");
990 mListView->restoreLayout(config,setting); 990 mListView->restoreLayout(config,setting);
991} 991}
992 992
993void KOListView::writeSettings(KConfig *config, QString setting) 993void KOListView::writeSettings(KConfig *config, QString setting)
994{ 994{
995 // qDebug("KOListView::writeSettings "); 995 // qDebug("KOListView::writeSettings ");
996 mListView->saveLayout(config, setting); 996 mListView->saveLayout(config, setting);
997} 997}
998 998
999void KOListView::processSelectionChange(QListViewItem *) 999void KOListView::processSelectionChange(QListViewItem *)
1000{ 1000{
1001 1001
1002 KOListViewItem *item = 1002 KOListViewItem *item =
1003 static_cast<KOListViewItem *>( mListView->currentItem() ); 1003 static_cast<KOListViewItem *>( mListView->currentItem() );
1004 1004
1005 if ( !item ) { 1005 if ( !item ) {
1006 emit incidenceSelected( 0 ); 1006 emit incidenceSelected( 0 );
1007 } else { 1007 } else {
1008 emit incidenceSelected( item->data() ); 1008 emit incidenceSelected( item->data() );
1009 } 1009 }
1010} 1010}
1011 1011
1012void KOListView::clearSelection() 1012void KOListView::clearSelection()
1013{ 1013{
1014 mListView->selectAll( false ); 1014 mListView->selectAll( false );
1015} 1015}
1016void KOListView::allSelection() 1016void KOListView::allSelection()
1017{ 1017{
1018 mListView->selectAll( true ); 1018 mListView->selectAll( true );
1019} 1019}
1020 1020
1021void KOListView::clear() 1021void KOListView::clear()
1022{ 1022{
1023 mListView->clear(); 1023 mListView->clear();
1024 mUidDict.clear(); 1024 mUidDict.clear();
1025} 1025}
1026 1026
1027Incidence* KOListView::currentItem() 1027Incidence* KOListView::currentItem()
1028{ 1028{
1029 if ( mListView->currentItem() ) 1029 if ( mListView->currentItem() )
1030 return ((KOListViewItem*) mListView->currentItem())->data(); 1030 return ((KOListViewItem*) mListView->currentItem())->data();
1031 return 0; 1031 return 0;
1032} 1032}
1033void KOListView::keyPressEvent ( QKeyEvent *e) 1033void KOListView::keyPressEvent ( QKeyEvent *e)
1034{ 1034{
1035 1035
1036 if ( e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace ) { 1036 if ( e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace ) {
1037 deleteAll(); 1037 deleteAll();
1038 return; 1038 return;
1039 } 1039 }
1040 1040
1041 e->ignore(); 1041 e->ignore();
1042} 1042}
1043void KOListViewListView::keyPressEvent ( QKeyEvent *e) 1043void KOListViewListView::keyPressEvent ( QKeyEvent *e)
1044{ 1044{
1045 1045
1046 switch ( e->key() ) { 1046 switch ( e->key() ) {
1047 case Qt::Key_Down: 1047 case Qt::Key_Down:
1048 if ( e->state() == ShiftButton ) { 1048 if ( e->state() == ShiftButton ) {
1049 QListViewItem* cn = currentItem(); 1049 QListViewItem* cn = currentItem();
1050 if ( !cn ) 1050 if ( !cn )
1051 cn = firstChild(); 1051 cn = firstChild();
1052 if ( !cn ) 1052 if ( !cn )
1053 return; 1053 return;
1054 while ( cn->nextSibling() ) 1054 while ( cn->nextSibling() )
1055 cn = cn->nextSibling(); 1055 cn = cn->nextSibling();
1056 setCurrentItem ( cn ); 1056 setCurrentItem ( cn );
1057 ensureItemVisible ( cn ); 1057 ensureItemVisible ( cn );
1058 1058
1059 e->accept(); 1059 e->accept();
1060 return; 1060 return;
1061 } 1061 }
1062 if ( e->state() == ControlButton ) { 1062 if ( e->state() == ControlButton ) {
1063 int count = childCount (); 1063 int count = childCount ();
1064 int jump = count / 5; 1064 int jump = count / 5;
1065 QListViewItem* cn; 1065 QListViewItem* cn;
1066 cn = currentItem(); 1066 cn = currentItem();
1067 if ( ! cn ) 1067 if ( ! cn )
1068 return; 1068 return;
1069 if ( jump == 0 ) 1069 if ( jump == 0 )
1070 jump = 1; 1070 jump = 1;
1071 while ( jump && cn->nextSibling() ) { 1071 while ( jump && cn->nextSibling() ) {
1072 cn = cn->nextSibling(); 1072 cn = cn->nextSibling();
1073 --jump; 1073 --jump;
1074 } 1074 }
1075 setCurrentItem ( cn ); 1075 setCurrentItem ( cn );
1076 ensureItemVisible ( cn ); 1076 ensureItemVisible ( cn );
1077 1077
1078 } else 1078 } else
1079 QListView::keyPressEvent ( e ) ; 1079 QListView::keyPressEvent ( e ) ;
1080 e->accept(); 1080 e->accept();
1081 break; 1081 break;
1082 1082
1083 case Qt::Key_Up: 1083 case Qt::Key_Up:
1084 if ( e->state() == ShiftButton ) { 1084 if ( e->state() == ShiftButton ) {
1085 QListViewItem* cn = firstChild(); 1085 QListViewItem* cn = firstChild();
1086 if ( cn ) { 1086 if ( cn ) {
1087 setCurrentItem ( cn ); 1087 setCurrentItem ( cn );
1088 ensureItemVisible ( cn ); 1088 ensureItemVisible ( cn );
1089 } 1089 }
1090 e->accept(); 1090 e->accept();
1091 return; 1091 return;
1092 } 1092 }
1093 if ( e->state() == ControlButton ) { 1093 if ( e->state() == ControlButton ) {
1094 int count = childCount (); 1094 int count = childCount ();
1095 int jump = count / 5; 1095 int jump = count / 5;
1096 QListViewItem* cn; 1096 QListViewItem* cn;
1097 cn = currentItem(); 1097 cn = currentItem();
1098 if ( ! cn ) 1098 if ( ! cn )
1099 return; 1099 return;
1100 if ( jump == 0 ) 1100 if ( jump == 0 )
1101 jump = 1; 1101 jump = 1;
1102 while ( jump && cn->itemAbove ()) { 1102 while ( jump && cn->itemAbove ()) {
1103 cn = cn->itemAbove (); 1103 cn = cn->itemAbove ();
1104 --jump; 1104 --jump;
1105 } 1105 }
1106 setCurrentItem ( cn ); 1106 setCurrentItem ( cn );
1107 ensureItemVisible ( cn ); 1107 ensureItemVisible ( cn );
1108 } else 1108 } else
1109 QListView::keyPressEvent ( e ) ; 1109 QListView::keyPressEvent ( e ) ;
1110 e->accept(); 1110 e->accept();
1111 break; 1111 break;
1112 case Qt::Key_I: { 1112 case Qt::Key_I: {
1113 QListViewItem* cn; 1113 QListViewItem* cn;
1114 cn = currentItem(); 1114 cn = currentItem();
1115 if ( cn ) { 1115 if ( cn ) {
1116 KOListViewItem* ci = (KOListViewItem*)( cn ); 1116 KOListViewItem* ci = (KOListViewItem*)( cn );
1117 if ( ci ){ 1117 if ( ci ){
1118 //emit showIncidence( ci->data()); 1118 //emit showIncidence( ci->data());
1119 cn = cn->nextSibling(); 1119 cn = cn->nextSibling();
1120 if ( cn ) { 1120 if ( cn ) {
1121 setCurrentItem ( cn ); 1121 setCurrentItem ( cn );
1122 ensureItemVisible ( cn ); 1122 ensureItemVisible ( cn );
1123 } 1123 }
1124 emit showIncidence( ci->data()); 1124 emit showIncidence( ci->data());
1125 } 1125 }
1126 } 1126 }
1127 e->accept(); 1127 e->accept();
1128 } 1128 }
1129 break; 1129 break;
1130 case Qt::Key_Return: 1130 case Qt::Key_Return:
1131 case Qt::Key_Enter: 1131 case Qt::Key_Enter:
1132 { 1132 {
1133 QListViewItem* cn; 1133 QListViewItem* cn;
1134 cn = currentItem(); 1134 cn = currentItem();
1135 if ( cn ) { 1135 if ( cn ) {
1136 KOListViewItem* ci = (KOListViewItem*)( cn ); 1136 KOListViewItem* ci = (KOListViewItem*)( cn );
1137 if ( ci ){ 1137 if ( ci ){
1138 if ( e->state() == ShiftButton ) 1138 if ( e->state() == ShiftButton )
1139 ci->setSelected( false ); 1139 ci->setSelected( false );
1140 else 1140 else
1141 ci->setSelected( true ); 1141 ci->setSelected( true );
1142 cn = cn->nextSibling(); 1142 cn = cn->nextSibling();
1143 if ( cn ) { 1143 if ( cn ) {
1144 setCurrentItem ( cn ); 1144 setCurrentItem ( cn );
1145 ensureItemVisible ( cn ); 1145 ensureItemVisible ( cn );
1146 } 1146 }
1147 } 1147 }
1148 } 1148 }
1149 e->accept(); 1149 e->accept();
1150 } 1150 }
1151 break; 1151 break;
1152 default: 1152 default:
1153 e->ignore(); 1153 e->ignore();
1154 } 1154 }
1155} 1155}
1156KOListViewListView::KOListViewListView(KOListView * lv ) 1156KOListViewListView::KOListViewListView(KOListView * lv )
1157 : KListView( lv ) 1157 : KListView( lv, "kolistlistview", false )
1158{ 1158{
1159 mPopupTimer = new QTimer(this);
1160 connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu()));
1159#ifndef DESKTOP_VERSION 1161#ifndef DESKTOP_VERSION
1160 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold ); 1162 //QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold );
1161#endif 1163#endif
1162 setSelectionMode( QListView::Multi ); 1164 setSelectionMode( QListView::Multi );
1163 setMultiSelection( true); 1165 setMultiSelection( true);
1164} 1166}
1165void KOListViewListView::contentsMouseDoubleClickEvent(QMouseEvent *e) 1167void KOListViewListView::contentsMouseDoubleClickEvent(QMouseEvent *e)
1166{ 1168{
1167 if (!e) return; 1169 if (!e) return;
1168 QPoint vp = contentsToViewport(e->pos()); 1170 QPoint vp = contentsToViewport(e->pos());
1169 QListViewItem *item = itemAt(vp); 1171 QListViewItem *item = itemAt(vp);
1170 if (!item) { 1172 if (!item) {
1171 emit newEvent(); 1173 emit newEvent();
1172 return; 1174 return;
1173 } 1175 }
1174 KListView::contentsMouseDoubleClickEvent(e); 1176 KListView::contentsMouseDoubleClickEvent(e);
1175} 1177}
1176 1178#if 0
1177void KOListViewListView::contentsMousePressEvent(QMouseEvent *e) 1179void KOListViewListView::contentsMousePressEvent(QMouseEvent *e)
1178{ 1180{
1179 //qDebug("contentsMousePressEvent++++ "); 1181 //qDebug("contentsMousePressEvent++++ ");
1180 KListView::contentsMousePressEvent( e ); 1182 KListView::contentsMousePressEvent( e );
1181 if ( e->button() == RightButton ) { 1183 if ( e->button() == RightButton ) {
1182 QListViewItem* ci = currentItem(); 1184 QListViewItem* ci = currentItem();
1183 clearSelection () ; 1185 clearSelection () ;
1184 if ( ci ) 1186 if ( ci )
1185 ci->setSelected( true ); 1187 ci->setSelected( true );
1186 } 1188 }
1187} 1189}
1188void KOListViewListView::contentsMouseReleaseEvent(QMouseEvent *e) 1190void KOListViewListView::contentsMouseReleaseEvent(QMouseEvent *e)
1189{ 1191{
1190 KListView::contentsMouseReleaseEvent(e); 1192 KListView::contentsMouseReleaseEvent(e);
1191} 1193}
1192void KOListViewListView::contentsMouseMoveEvent(QMouseEvent *e) 1194void KOListViewListView::contentsMouseMoveEvent(QMouseEvent *e)
1193{ 1195{
1194 KListView::contentsMouseMoveEvent(e); 1196 KListView::contentsMouseMoveEvent(e);
1195} 1197}
1198#endif
1199void KOListViewListView::popupMenu()
1200{
1201 mPopupTimer->stop();
1202 //qDebug("HUUUUUUUUUUUUUUUUUUUU ");
1203 QMouseEvent* e = new QMouseEvent( QEvent::MouseButtonPress, mEventPos ,mEventGlobalPos, RightButton , RightButton );
1204 QApplication::postEvent( this->viewport(), e );
1205}
1206void KOListViewListView::contentsMousePressEvent(QMouseEvent *e)
1207{
1208 //qDebug("contentsMousePressEvent++++ ");
1209 mYMousePos = mapToGlobal( (e->pos())).y();
1210 if ( e->button() == LeftButton ) {
1211 mPopupTimer->start( 600 );
1212 mEventPos = e->pos();
1213 mEventGlobalPos = e->globalPos();
1214 }
1215 KListView::contentsMousePressEvent( e );
1216 if ( e->button() == RightButton ) {
1217 QListViewItem* ci = currentItem();
1218 clearSelection();
1219 if ( ci )
1220 ci->setSelected( true );
1221 }
1222}
1223void KOListViewListView::contentsMouseReleaseEvent(QMouseEvent *e)
1224{
1225 mPopupTimer->stop();
1226 KListView::contentsMouseReleaseEvent(e);
1227}
1228void KOListViewListView::contentsMouseMoveEvent(QMouseEvent *e)
1229{
1230 // qDebug("contentsMouseMoveEv....... ");
1231 // qDebug("start: %d current %d ",mYMousePos , mapToGlobal( (e->pos())).y() );
1232 int diff = mYMousePos - mapToGlobal( (e->pos())).y();
1233 if ( diff < 0 ) diff = -diff;
1234 if ( diff > 15 )
1235 mPopupTimer->stop();
1236 else {
1237 mEventPos = e->pos();
1238 mEventGlobalPos = e->globalPos();
1239 }
1240 KListView::contentsMouseMoveEvent(e);
1241}
1242
diff --git a/korganizer/kolistview.h b/korganizer/kolistview.h
index eca71e2..bb0e23e 100644
--- a/korganizer/kolistview.h
+++ b/korganizer/kolistview.h
@@ -1,304 +1,311 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 1999 Preston Brown 3 Copyright (c) 1999 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#ifndef _KOLISTVIEW_H 24#ifndef _KOLISTVIEW_H
25#define _KOLISTVIEW_H 25#define _KOLISTVIEW_H
26 26
27#include <qlistview.h> 27#include <qlistview.h>
28#include <qmap.h> 28#include <qmap.h>
29#include <qdict.h> 29#include <qdict.h>
30 30
31#include <klistview.h> 31#include <klistview.h>
32 32
33#ifndef DESKTOP_VERSION 33#ifndef DESKTOP_VERSION
34#include <qtopia/ir.h> 34#include <qtopia/ir.h>
35#else 35#else
36#define Ir char 36#define Ir char
37#endif 37#endif
38#include <libkcal/incidence.h> 38#include <libkcal/incidence.h>
39 39
40#include "koeventview.h" 40#include "koeventview.h"
41#include "customlistviewitem.h" 41#include "customlistviewitem.h"
42 42
43using namespace KCal; 43using namespace KCal;
44 44
45 45
46 46
47#include <qpushbutton.h> 47#include <qpushbutton.h>
48#include <qlayout.h> 48#include <qlayout.h>
49#include <qdialog.h> 49#include <qdialog.h>
50#include <qtimer.h>
50#include <qcombobox.h> 51#include <qcombobox.h>
51#include <qspinbox.h> 52#include <qspinbox.h>
52#include <qtooltip.h> 53#include <qtooltip.h>
53#include <qcheckbox.h> 54#include <qcheckbox.h>
54#include <qhbox.h> 55#include <qhbox.h>
55#include <qlabel.h> 56#include <qlabel.h>
56#include <kiconloader.h> 57#include <kiconloader.h>
57#include "kfiledialog.h" 58#include "kfiledialog.h"
58#include "koprefs.h" 59#include "koprefs.h"
59class KOAlarmPrefs : public QDialog 60class KOAlarmPrefs : public QDialog
60{ 61{
61 Q_OBJECT 62 Q_OBJECT
62 public: 63 public:
63 KOAlarmPrefs( QWidget *par=0, const char *name=0 ) : 64 KOAlarmPrefs( QWidget *par=0, const char *name=0 ) :
64 QDialog( par, name, true ) 65 QDialog( par, name, true )
65 { 66 {
66 setCaption( i18n("Alarm Options") ); 67 setCaption( i18n("Alarm Options") );
67 QVBoxLayout* alarmLayout = new QVBoxLayout( this ); 68 QVBoxLayout* alarmLayout = new QVBoxLayout( this );
68 alarmLayout->setSpacing( 3 ); 69 alarmLayout->setSpacing( 3 );
69 alarmLayout->setMargin( 3 ); 70 alarmLayout->setMargin( 3 );
70 QWidget *parent = this; 71 QWidget *parent = this;
71 mAlarmButton = new QCheckBox(i18n("Set reminder ON with offset to:"),parent); 72 mAlarmButton = new QCheckBox(i18n("Set reminder ON with offset to:"),parent);
72 alarmLayout->addWidget(mAlarmButton); 73 alarmLayout->addWidget(mAlarmButton);
73 mAlarmTimeEdit = new QSpinBox ( 0, 9999, 1, parent, "mAlarmTimeEdit " ) ; 74 mAlarmTimeEdit = new QSpinBox ( 0, 9999, 1, parent, "mAlarmTimeEdit " ) ;
74 mAlarmTimeEdit->setValue( 15 ); 75 mAlarmTimeEdit->setValue( 15 );
75 alarmLayout->addWidget(mAlarmTimeEdit); 76 alarmLayout->addWidget(mAlarmTimeEdit);
76 mAlarmIncrCombo = new QComboBox(false, parent); 77 mAlarmIncrCombo = new QComboBox(false, parent);
77 mAlarmIncrCombo->insertItem(i18n("minute(s)")); 78 mAlarmIncrCombo->insertItem(i18n("minute(s)"));
78 mAlarmIncrCombo->insertItem(i18n("hour(s)")); 79 mAlarmIncrCombo->insertItem(i18n("hour(s)"));
79 mAlarmIncrCombo->insertItem(i18n("day(s)")); 80 mAlarmIncrCombo->insertItem(i18n("day(s)"));
80 alarmLayout->addWidget(mAlarmIncrCombo); 81 alarmLayout->addWidget(mAlarmIncrCombo);
81 QHBox * hb = new QHBox ( parent ); 82 QHBox * hb = new QHBox ( parent );
82 alarmLayout->addWidget(hb); 83 alarmLayout->addWidget(hb);
83 mAlarmSoundButton = new QPushButton(hb); 84 mAlarmSoundButton = new QPushButton(hb);
84 mAlarmSoundButton->setPixmap(SmallIcon("playsound")); 85 mAlarmSoundButton->setPixmap(SmallIcon("playsound"));
85 mAlarmSoundButton->setToggleButton(true); 86 mAlarmSoundButton->setToggleButton(true);
86 connect(mAlarmSoundButton, SIGNAL(clicked()), SLOT(pickAlarmSound())); 87 connect(mAlarmSoundButton, SIGNAL(clicked()), SLOT(pickAlarmSound()));
87 mAlarmProgramButton = new QPushButton(hb); 88 mAlarmProgramButton = new QPushButton(hb);
88 mAlarmProgramButton->setPixmap(SmallIcon("run")); 89 mAlarmProgramButton->setPixmap(SmallIcon("run"));
89 mAlarmProgramButton->setToggleButton(true); 90 mAlarmProgramButton->setToggleButton(true);
90 connect(mAlarmProgramButton, SIGNAL(clicked()), SLOT(pickAlarmProgram())); 91 connect(mAlarmProgramButton, SIGNAL(clicked()), SLOT(pickAlarmProgram()));
91 mAlarmSoundButton->setMaximumWidth( mAlarmSoundButton->sizeHint().width() + 4 ); 92 mAlarmSoundButton->setMaximumWidth( mAlarmSoundButton->sizeHint().width() + 4 );
92 mAlarmProgramButton->setMaximumWidth(mAlarmProgramButton->sizeHint().width() + 4 ); 93 mAlarmProgramButton->setMaximumWidth(mAlarmProgramButton->sizeHint().width() + 4 );
93 mAlarmLabel = new QLabel( this ); 94 mAlarmLabel = new QLabel( this );
94 alarmLayout->addWidget( mAlarmLabel ); 95 alarmLayout->addWidget( mAlarmLabel );
95 mAlarmLabel->setText( "..."+KOPrefs::instance()->mDefaultAlarmFile.right( 30 ) ); 96 mAlarmLabel->setText( "..."+KOPrefs::instance()->mDefaultAlarmFile.right( 30 ) );
96 mAlarmSound = KOPrefs::instance()->mDefaultAlarmFile; 97 mAlarmSound = KOPrefs::instance()->mDefaultAlarmFile;
97 mAlarmSoundButton->setOn( true ); 98 mAlarmSoundButton->setOn( true );
98 QPushButton * ok = new QPushButton( i18n("Set Alarm!"), this ); 99 QPushButton * ok = new QPushButton( i18n("Set Alarm!"), this );
99 alarmLayout->addWidget( ok ); 100 alarmLayout->addWidget( ok );
100 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 101 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
101 alarmLayout->addWidget( cancel ); 102 alarmLayout->addWidget( cancel );
102 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 103 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
103 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 104 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
104 resize( 200, 200 ); 105 resize( 200, 200 );
105 106
106 } 107 }
107 108
108 109
109 110
110 QString mAlarmSound, mAlarmProgram ; 111 QString mAlarmSound, mAlarmProgram ;
111 QCheckBox* mAlarmButton; 112 QCheckBox* mAlarmButton;
112 QSpinBox* mAlarmTimeEdit; 113 QSpinBox* mAlarmTimeEdit;
113 QLabel* mAlarmLabel; 114 QLabel* mAlarmLabel;
114 QComboBox* mAlarmIncrCombo ; 115 QComboBox* mAlarmIncrCombo ;
115 QPushButton* mAlarmSoundButton ,*mAlarmProgramButton; 116 QPushButton* mAlarmSoundButton ,*mAlarmProgramButton;
116private slots: 117private slots:
117 118
118void pickAlarmSound() 119void pickAlarmSound()
119{ 120{
120 //QString prefix = mAlarmSound; 121 //QString prefix = mAlarmSound;
121 if (!mAlarmSoundButton->isOn()) { 122 if (!mAlarmSoundButton->isOn()) {
122 //mAlarmSound = ""; 123 //mAlarmSound = "";
123 QToolTip::remove(mAlarmSoundButton); 124 QToolTip::remove(mAlarmSoundButton);
124 QToolTip::add(mAlarmSoundButton, i18n("No sound set")); 125 QToolTip::add(mAlarmSoundButton, i18n("No sound set"));
125 mAlarmProgramButton->setOn(true); 126 mAlarmProgramButton->setOn(true);
126 mAlarmSoundButton->setOn(false); 127 mAlarmSoundButton->setOn(false);
127 } else { 128 } else {
128 QString fileName(KFileDialog::getOpenFileName(mAlarmSound, 129 QString fileName(KFileDialog::getOpenFileName(mAlarmSound,
129 i18n("*.wav|Wav Files"), 0)); 130 i18n("*.wav|Wav Files"), 0));
130 if (!fileName.isEmpty()) { 131 if (!fileName.isEmpty()) {
131 mAlarmSound = fileName; 132 mAlarmSound = fileName;
132 mAlarmLabel->setText( "..."+fileName.right( 30 ) ); 133 mAlarmLabel->setText( "..."+fileName.right( 30 ) );
133 QToolTip::remove(mAlarmSoundButton); 134 QToolTip::remove(mAlarmSoundButton);
134 QString dispStr = i18n("Playing '%1'").arg(fileName); 135 QString dispStr = i18n("Playing '%1'").arg(fileName);
135 QToolTip::add(mAlarmSoundButton, dispStr); 136 QToolTip::add(mAlarmSoundButton, dispStr);
136 mAlarmProgramButton->setOn(false); 137 mAlarmProgramButton->setOn(false);
137 mAlarmSoundButton->setOn(true); 138 mAlarmSoundButton->setOn(true);
138 } else { 139 } else {
139 mAlarmProgramButton->setOn(true); 140 mAlarmProgramButton->setOn(true);
140 mAlarmSoundButton->setOn(false); 141 mAlarmSoundButton->setOn(false);
141 142
142 } 143 }
143 } 144 }
144}; 145};
145 146
146void pickAlarmProgram() 147void pickAlarmProgram()
147{ 148{
148 if (!mAlarmProgramButton->isOn()) { 149 if (!mAlarmProgramButton->isOn()) {
149 //mAlarmProgram = ""; 150 //mAlarmProgram = "";
150 QToolTip::remove(mAlarmProgramButton); 151 QToolTip::remove(mAlarmProgramButton);
151 QToolTip::add(mAlarmProgramButton, i18n("No program set")); 152 QToolTip::add(mAlarmProgramButton, i18n("No program set"));
152 mAlarmProgramButton->setOn(false); 153 mAlarmProgramButton->setOn(false);
153 mAlarmSoundButton->setOn(true); 154 mAlarmSoundButton->setOn(true);
154 } else { 155 } else {
155 QString fileName(KFileDialog::getOpenFileName(mAlarmProgram,i18n("Procedure Alarm.: ") , 0)); 156 QString fileName(KFileDialog::getOpenFileName(mAlarmProgram,i18n("Procedure Alarm.: ") , 0));
156 if (!fileName.isEmpty()) { 157 if (!fileName.isEmpty()) {
157 mAlarmProgram = fileName; 158 mAlarmProgram = fileName;
158 mAlarmLabel->setText( "..."+fileName.right( 30 ) ); 159 mAlarmLabel->setText( "..."+fileName.right( 30 ) );
159 QToolTip::remove(mAlarmProgramButton); 160 QToolTip::remove(mAlarmProgramButton);
160 QString dispStr = i18n("Running '%1'").arg(fileName); 161 QString dispStr = i18n("Running '%1'").arg(fileName);
161 QToolTip::add(mAlarmProgramButton, dispStr); 162 QToolTip::add(mAlarmProgramButton, dispStr);
162 mAlarmSoundButton->setOn(false); 163 mAlarmSoundButton->setOn(false);
163 mAlarmProgramButton->setOn(true); 164 mAlarmProgramButton->setOn(true);
164 } else { 165 } else {
165 mAlarmProgramButton->setOn(false); 166 mAlarmProgramButton->setOn(false);
166 mAlarmSoundButton->setOn(true); 167 mAlarmSoundButton->setOn(true);
167 } 168 }
168 } 169 }
169}; 170};
170 171
171}; 172};
172 173
173 174
174 175
175 176
176 177
177 178
178 179
179typedef CustomListViewItem<Incidence *> KOListViewItem; 180typedef CustomListViewItem<Incidence *> KOListViewItem;
180 181
181/** 182/**
182 This class provides the initialisation of a KOListViewItem for calendar 183 This class provides the initialisation of a KOListViewItem for calendar
183 components using the Incidence::Visitor. 184 components using the Incidence::Visitor.
184*/ 185*/
185class ListItemVisitor : public Incidence::Visitor 186class ListItemVisitor : public Incidence::Visitor
186{ 187{
187 public: 188 public:
188 ListItemVisitor(KOListViewItem *, QDate d); 189 ListItemVisitor(KOListViewItem *, QDate d);
189 ~ListItemVisitor(); 190 ~ListItemVisitor();
190 191
191 bool visit(Event *); 192 bool visit(Event *);
192 bool visit(Todo *); 193 bool visit(Todo *);
193 bool visit(Journal *); 194 bool visit(Journal *);
194 195
195 private: 196 private:
196 KOListViewItem *mItem; 197 KOListViewItem *mItem;
197 QDate mDate; 198 QDate mDate;
198}; 199};
199 200
200/** 201/**
201 This class provides a multi-column list view of events. It can 202 This class provides a multi-column list view of events. It can
202 display events from one particular day or several days, it doesn't 203 display events from one particular day or several days, it doesn't
203 matter. To use a view that only handles one day at a time, use 204 matter. To use a view that only handles one day at a time, use
204 KODayListView. 205 KODayListView.
205 206
206 @short multi-column list view of various events. 207 @short multi-column list view of various events.
207 @author Preston Brown <pbrown@kde.org> 208 @author Preston Brown <pbrown@kde.org>
208 @see KOBaseView, KODayListView 209 @see KOBaseView, KODayListView
209*/ 210*/
210class KOListView; 211class KOListView;
211 212
212class KOListViewListView : public KListView 213class KOListViewListView : public KListView
213{ 214{
214 Q_OBJECT 215 Q_OBJECT
215 public: 216 public:
216 KOListViewListView(KOListView * lv ); 217 KOListViewListView(KOListView * lv );
217 signals: 218 signals:
218 void newEvent(); 219 void newEvent();
219 void showIncidence( Incidence* ); 220 void showIncidence( Incidence* );
221 public slots:
222 void popupMenu();
220 private: 223 private:
224 QPoint mEventPos;
225 QPoint mEventGlobalPos;
226 QTimer* mPopupTimer;
227 int mYMousePos;
221 void keyPressEvent ( QKeyEvent * ) ; 228 void keyPressEvent ( QKeyEvent * ) ;
222 void contentsMouseDoubleClickEvent(QMouseEvent *e); 229 void contentsMouseDoubleClickEvent(QMouseEvent *e);
223 void contentsMousePressEvent(QMouseEvent *e); 230 void contentsMousePressEvent(QMouseEvent *e);
224 void contentsMouseReleaseEvent(QMouseEvent *e); 231 void contentsMouseReleaseEvent(QMouseEvent *e);
225 void contentsMouseMoveEvent(QMouseEvent *e); 232 void contentsMouseMoveEvent(QMouseEvent *e);
226 bool mMouseDown; 233 bool mMouseDown;
227}; 234};
228 235
229class KOListView : public KOEventView 236class KOListView : public KOEventView
230{ 237{
231 Q_OBJECT 238 Q_OBJECT
232 public: 239 public:
233 KOListView(Calendar *calendar, QWidget *parent = 0, 240 KOListView(Calendar *calendar, QWidget *parent = 0,
234 const char *name = 0); 241 const char *name = 0);
235 ~KOListView(); 242 ~KOListView();
236 243
237 virtual int maxDatesHint(); 244 virtual int maxDatesHint();
238 virtual int currentDateCount(); 245 virtual int currentDateCount();
239 virtual QPtrList<Incidence> selectedIncidences(); 246 virtual QPtrList<Incidence> selectedIncidences();
240 virtual DateList selectedDates(); 247 virtual DateList selectedDates();
241 248
242 void showDates(bool show); 249 void showDates(bool show);
243 Incidence* currentItem(); 250 Incidence* currentItem();
244 void addTodos(QPtrList<Todo> eventList); 251 void addTodos(QPtrList<Todo> eventList);
245 void addJournals(QPtrList<Journal> eventList); 252 void addJournals(QPtrList<Journal> eventList);
246 virtual void printPreview(CalPrinter *calPrinter, 253 virtual void printPreview(CalPrinter *calPrinter,
247 const QDate &, const QDate &); 254 const QDate &, const QDate &);
248 255
249 void readSettings(KConfig *config, QString setting = "KOListView Layout"); 256 void readSettings(KConfig *config, QString setting = "KOListView Layout");
250 void writeSettings(KConfig *config, QString setting = "KOListView Layout"); 257 void writeSettings(KConfig *config, QString setting = "KOListView Layout");
251 void updateList(); 258 void updateList();
252 void setStartDate(const QDate &start); 259 void setStartDate(const QDate &start);
253 int count(); 260 int count();
254 QString getWhatsThisText(QPoint p); 261 QString getWhatsThisText(QPoint p);
255 void resetFocus(); 262 void resetFocus();
256 signals: 263 signals:
257 void signalNewEvent(); 264 void signalNewEvent();
258 void beamIncidenceList(QPtrList<Incidence>); 265 void beamIncidenceList(QPtrList<Incidence>);
259 266
260 public slots: 267 public slots:
261 virtual void updateView(); 268 virtual void updateView();
262 virtual void showDates(const QDate &start, const QDate &end); 269 virtual void showDates(const QDate &start, const QDate &end);
263 virtual void showEvents(QPtrList<Event> eventList); 270 virtual void showEvents(QPtrList<Event> eventList);
264 void clearSelection(); 271 void clearSelection();
265 void allSelection(); 272 void allSelection();
266 273
267 void clear(); 274 void clear();
268 void beamDone( Ir *ir ); 275 void beamDone( Ir *ir );
269 void showDates(); 276 void showDates();
270 void hideDates(); 277 void hideDates();
271 void deleteAll(); 278 void deleteAll();
272 void saveToFile(); 279 void saveToFile();
273 void saveToFileVCS(); 280 void saveToFileVCS();
274 void saveDescriptionToFile(); 281 void saveDescriptionToFile();
275 void beamSelected(); 282 void beamSelected();
276 void updateConfig(); 283 void updateConfig();
277 void addCat(); 284 void addCat();
278 void setCat(); 285 void setCat();
279 void setAlarm(); 286 void setAlarm();
280 void setCategories( bool removeOld ); 287 void setCategories( bool removeOld );
281 void changeEventDisplay(Event *, int); 288 void changeEventDisplay(Event *, int);
282 289
283 void defaultItemAction(QListViewItem *item); 290 void defaultItemAction(QListViewItem *item);
284 void popupMenu(QListViewItem *item,const QPoint &,int); 291 void popupMenu(QListViewItem *item,const QPoint &,int);
285 292
286 protected slots: 293 protected slots:
287 void processSelectionChange(QListViewItem *); 294 void processSelectionChange(QListViewItem *);
288 295
289 protected: 296 protected:
290 void writeToFile( bool iCal ); 297 void writeToFile( bool iCal );
291 void addEvents(QPtrList<Event> eventList); 298 void addEvents(QPtrList<Event> eventList);
292 void addIncidence(Incidence *); 299 void addIncidence(Incidence *);
293 KOListViewItem *getItemForEvent(Event *event); 300 KOListViewItem *getItemForEvent(Event *event);
294 301
295 private: 302 private:
296 KOListViewListView *mListView; 303 KOListViewListView *mListView;
297 KOEventPopupMenu *mPopupMenu; 304 KOEventPopupMenu *mPopupMenu;
298 KOListViewItem *mActiveItem; 305 KOListViewItem *mActiveItem;
299 QDict<Incidence> mUidDict; 306 QDict<Incidence> mUidDict;
300 QDate mStartDate; 307 QDate mStartDate;
301 void keyPressEvent ( QKeyEvent * ) ; 308 void keyPressEvent ( QKeyEvent * ) ;
302}; 309};
303 310
304#endif 311#endif