summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagenda.cpp77
-rw-r--r--korganizer/koagendaitem.cpp2
-rw-r--r--korganizer/kolistview.cpp46
-rw-r--r--korganizer/kolistview.h2
-rw-r--r--korganizer/komonthview.cpp11
5 files changed, 48 insertions, 90 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp
index 2820ca2..66ad4ec 100644
--- a/korganizer/koagenda.cpp
+++ b/korganizer/koagenda.cpp
@@ -1,2066 +1,2053 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 Marcus Bains line. 5 Marcus Bains line.
6 Copyright (c) 2001 Ali Rahimi 6 Copyright (c) 2001 Ali Rahimi
7 7
8 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 (at your option) any later version.
12 12
13 This program is distributed in the hope that it will be useful, 13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 GNU General Public License for more details.
17 17
18 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software 19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 21
22 As a special exception, permission is given to link this program 22 As a special exception, permission is given to link this program
23 with any edition of Qt, and distribute the resulting executable, 23 with any edition of Qt, and distribute the resulting executable,
24 without including the source code for Qt in the source distribution. 24 without including the source code for Qt in the source distribution.
25*/ 25*/
26 26
27#ifndef _WIN32_ 27#ifndef _WIN32_
28#define protected public 28#define protected public
29#include <qwidget.h> 29#include <qwidget.h>
30#undef protected 30#undef protected
31#endif 31#endif
32#include <qintdict.h> 32#include <qintdict.h>
33#include <qdatetime.h> 33#include <qdatetime.h>
34#include <qapplication.h> 34#include <qapplication.h>
35#include <qpopupmenu.h> 35#include <qpopupmenu.h>
36#include <qcursor.h> 36#include <qcursor.h>
37#include <qpainter.h> 37#include <qpainter.h>
38 38
39#include <kdebug.h> 39#include <kdebug.h>
40#include <klocale.h> 40#include <klocale.h>
41#include <kiconloader.h> 41#include <kiconloader.h>
42#include <kglobal.h> 42#include <kglobal.h>
43 43
44#include "koagendaitem.h" 44#include "koagendaitem.h"
45#include "koprefs.h" 45#include "koprefs.h"
46#include "koglobals.h" 46#include "koglobals.h"
47 47
48#include "koagenda.h" 48#include "koagenda.h"
49 49
50#include <libkcal/event.h> 50#include <libkcal/event.h>
51#include <libkcal/todo.h> 51#include <libkcal/todo.h>
52 52
53#ifndef DESKTOP_VERSION 53#ifndef DESKTOP_VERSION
54#include <qpe/qpeapplication.h> 54#include <qpe/qpeapplication.h>
55#endif 55#endif
56 56
57//extern bool globalFlagBlockPainting; 57//extern bool globalFlagBlockPainting;
58extern int globalFlagBlockAgenda; 58extern int globalFlagBlockAgenda;
59extern int globalFlagBlockAgendaItemPaint; 59extern int globalFlagBlockAgendaItemPaint;
60extern int globalFlagBlockAgendaItemUpdate; 60extern int globalFlagBlockAgendaItemUpdate;
61extern int globalFlagBlockStartup; 61extern int globalFlagBlockStartup;
62 62
63//////////////////////////////////////////////////////////////////////////// 63////////////////////////////////////////////////////////////////////////////
64MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name) 64MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name)
65 : QFrame(_agenda->viewport(),name), agenda(_agenda) 65 : QFrame(_agenda->viewport(),name), agenda(_agenda)
66{ 66{
67 setLineWidth(0); 67 setLineWidth(0);
68 setMargin(0); 68 setMargin(0);
69 setBackgroundColor(Qt::red); 69 setBackgroundColor(Qt::red);
70 minutes = new QTimer(this); 70 minutes = new QTimer(this);
71 connect(minutes, SIGNAL(timeout()), this, SLOT(updateLoc())); 71 connect(minutes, SIGNAL(timeout()), this, SLOT(updateLoc()));
72 minutes->start(0, true); 72 minutes->start(0, true);
73 73
74 mTimeBox = new QLabel(this); 74 mTimeBox = new QLabel(this);
75 mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom); 75 mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom);
76 QPalette pal = mTimeBox->palette(); 76 QPalette pal = mTimeBox->palette();
77 pal.setColor(QColorGroup::Foreground, Qt::red); 77 pal.setColor(QColorGroup::Foreground, Qt::red);
78 mTimeBox->setPalette(pal); 78 mTimeBox->setPalette(pal);
79 //mTimeBox->setAutoMask(true); 79 //mTimeBox->setAutoMask(true);
80 80
81 agenda->addChild(mTimeBox); 81 agenda->addChild(mTimeBox);
82 82
83 oldToday = -1; 83 oldToday = -1;
84} 84}
85 85
86MarcusBains::~MarcusBains() 86MarcusBains::~MarcusBains()
87{ 87{
88 delete minutes; 88 delete minutes;
89} 89}
90 90
91int MarcusBains::todayColumn() 91int MarcusBains::todayColumn()
92{ 92{
93 QDate currentDate = QDate::currentDate(); 93 QDate currentDate = QDate::currentDate();
94 94
95 DateList dateList = agenda->dateList(); 95 DateList dateList = agenda->dateList();
96 DateList::ConstIterator it; 96 DateList::ConstIterator it;
97 int col = 0; 97 int col = 0;
98 for(it = dateList.begin(); it != dateList.end(); ++it) { 98 for(it = dateList.begin(); it != dateList.end(); ++it) {
99 if((*it) == currentDate) 99 if((*it) == currentDate)
100 return KOGlobals::self()->reverseLayout() ? 100 return KOGlobals::self()->reverseLayout() ?
101 agenda->columns() - 1 - col : col; 101 agenda->columns() - 1 - col : col;
102 ++col; 102 ++col;
103 } 103 }
104 104
105 return -1; 105 return -1;
106} 106}
107void MarcusBains::updateLoc() 107void MarcusBains::updateLoc()
108{ 108{
109 updateLocation(); 109 updateLocation();
110} 110}
111void MarcusBains::updateLocation(bool recalculate) 111void MarcusBains::updateLocation(bool recalculate)
112{ 112{
113 113
114 QTime tim = QTime::currentTime(); 114 QTime tim = QTime::currentTime();
115 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1()); 115 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1());
116 if((tim.hour() == 0) && (oldTime.hour()==23)) 116 if((tim.hour() == 0) && (oldTime.hour()==23))
117 recalculate = true; 117 recalculate = true;
118 118
119 int mins = tim.hour()*60 + tim.minute(); 119 int mins = tim.hour()*60 + tim.minute();
120 int minutesPerCell = 24 * 60 / agenda->rows(); 120 int minutesPerCell = 24 * 60 / agenda->rows();
121 int y = mins*agenda->gridSpacingY()/minutesPerCell; 121 int y = mins*agenda->gridSpacingY()/minutesPerCell;
122 int today = recalculate ? todayColumn() : oldToday; 122 int today = recalculate ? todayColumn() : oldToday;
123 int x = agenda->gridSpacingX()*today; 123 int x = agenda->gridSpacingX()*today;
124 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled); 124 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled);
125 125
126 oldTime = tim; 126 oldTime = tim;
127 oldToday = today; 127 oldToday = today;
128 128
129 if(disabled || (today<0)) { 129 if(disabled || (today<0)) {
130 hide(); mTimeBox->hide(); 130 hide(); mTimeBox->hide();
131 return; 131 return;
132 } else { 132 } else {
133 show(); mTimeBox->show(); 133 show(); mTimeBox->show();
134 } 134 }
135 135
136 if(recalculate) 136 if(recalculate)
137 setFixedSize(agenda->gridSpacingX(),1); 137 setFixedSize(agenda->gridSpacingX(),1);
138 agenda->moveChild(this, x, y); 138 agenda->moveChild(this, x, y);
139 raise(); 139 raise();
140 140
141 if(recalculate) 141 if(recalculate)
142 //mTimeBox->setFont(QFont("helvetica",10)); 142 //mTimeBox->setFont(QFont("helvetica",10));
143 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont); 143 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont);
144 144
145 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds)); 145 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds));
146 mTimeBox->adjustSize(); 146 mTimeBox->adjustSize();
147 // the -2 below is there because there is a bug in this program 147 // the -2 below is there because there is a bug in this program
148 // somewhere, where the last column of this widget is a few pixels 148 // somewhere, where the last column of this widget is a few pixels
149 // narrower than the other columns. 149 // narrower than the other columns.
150 int offs = (today==agenda->columns()-1) ? -4 : 0; 150 int offs = (today==agenda->columns()-1) ? -4 : 0;
151 agenda->moveChild(mTimeBox, 151 agenda->moveChild(mTimeBox,
152 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1, 152 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1,
153 y-mTimeBox->height()); 153 y-mTimeBox->height());
154 154
155 mTimeBox->raise(); 155 mTimeBox->raise();
156 //mTimeBox->setAutoMask(true); 156 //mTimeBox->setAutoMask(true);
157 minutes->start(5000,true); 157 minutes->start(5000,true);
158} 158}
159 159
160 160
161//////////////////////////////////////////////////////////////////////////// 161////////////////////////////////////////////////////////////////////////////
162 162
163 163
164/* 164/*
165 Create an agenda widget with rows rows and columns columns. 165 Create an agenda widget with rows rows and columns columns.
166*/ 166*/
167KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, 167KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent,
168 const char *name,WFlags f) : 168 const char *name,WFlags f) :
169 QScrollView(parent,name,f) 169 QScrollView(parent,name,f)
170{ 170{
171 171
172 172
173 mColumns = columns; 173 mColumns = columns;
174 mRows = rows; 174 mRows = rows;
175 mGridSpacingY = rowSize; 175 mGridSpacingY = rowSize;
176 mAllDayMode = false; 176 mAllDayMode = false;
177#ifndef DESKTOP_VERSION 177#ifndef DESKTOP_VERSION
178 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 178 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
179#endif 179#endif
180 mHolidayMask = 0; 180 mHolidayMask = 0;
181 init(); 181 init();
182} 182}
183 183
184/* 184/*
185 Create an agenda widget with columns columns and one row. This is used for 185 Create an agenda widget with columns columns and one row. This is used for
186 all-day events. 186 all-day events.
187*/ 187*/
188KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : 188KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) :
189 QScrollView(parent,name,f) 189 QScrollView(parent,name,f)
190{ 190{
191 blockResize = false; 191 blockResize = false;
192 mColumns = columns; 192 mColumns = columns;
193 mRows = 1; 193 mRows = 1;
194 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize); 194 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize);
195 mGridSpacingY = KOPrefs::instance()->mAllDaySize; 195 mGridSpacingY = KOPrefs::instance()->mAllDaySize;
196 mAllDayMode = true; 196 mAllDayMode = true;
197#ifndef DESKTOP_VERSION 197#ifndef DESKTOP_VERSION
198 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 198 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
199#endif 199#endif
200 mHolidayMask = 0; 200 mHolidayMask = 0;
201 init(); 201 init();
202} 202}
203 203
204 204
205KOAgenda::~KOAgenda() 205KOAgenda::~KOAgenda()
206{ 206{
207 if(mMarcusBains) delete mMarcusBains; 207 if(mMarcusBains) delete mMarcusBains;
208 208
209} 209}
210 210
211Incidence *KOAgenda::selectedIncidence() const 211Incidence *KOAgenda::selectedIncidence() const
212{ 212{
213 return (mSelectedItem ? mSelectedItem->incidence() : 0); 213 return (mSelectedItem ? mSelectedItem->incidence() : 0);
214} 214}
215 215
216 216
217QDate KOAgenda::selectedIncidenceDate() const 217QDate KOAgenda::selectedIncidenceDate() const
218{ 218{
219 return (mSelectedItem ? mSelectedItem->itemDate() : QDate()); 219 return (mSelectedItem ? mSelectedItem->itemDate() : QDate());
220} 220}
221 221
222 222
223void KOAgenda::init() 223void KOAgenda::init()
224{ 224{
225 mNewItemPopup = new QPopupMenu( this ); 225 mNewItemPopup = new QPopupMenu( this );
226 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) ); 226 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) );
227 QString pathString = ""; 227 QString pathString = "";
228 if ( !KOPrefs::instance()->mToolBarMiniIcons ) { 228 if ( !KOPrefs::instance()->mToolBarMiniIcons ) {
229 if ( QApplication::desktop()->width() < 480 ) 229 if ( QApplication::desktop()->width() < 480 )
230 pathString += "icons16/"; 230 pathString += "icons16/";
231 } else 231 } else
232 pathString += "iconsmini/"; 232 pathString += "iconsmini/";
233 233
234 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 ); 234 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 );
235 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 ); 235 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 );
236 mNewItemPopup->insertSeparator ( ); 236 mNewItemPopup->insertSeparator ( );
237 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 ); 237 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 );
238 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 ); 238 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 );
239 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 ); 239 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 );
240 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 ); 240 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 );
241 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("Next month"),6 ); 241 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("Next month"),6 );
242 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 ); 242 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 );
243#ifndef _WIN32_ 243#ifndef _WIN32_
244 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase 244 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase
245 viewport()->setWFlags ( wflags); 245 viewport()->setWFlags ( wflags);
246#endif 246#endif
247 mGridSpacingX = 80; 247 mGridSpacingX = 80;
248 mResizeBorderWidth = 8; 248 mResizeBorderWidth = 8;
249 mScrollBorderWidth = 8; 249 mScrollBorderWidth = 8;
250 mScrollDelay = 30; 250 mScrollDelay = 30;
251 mScrollOffset = 10; 251 mScrollOffset = 10;
252 mPaintPixmap.resize( 20,20); 252 mPaintPixmap.resize( 20,20);
253 //enableClipper(true); 253 //enableClipper(true);
254 254
255 // Grab key strokes for keyboard navigation of agenda. Seems to have no 255 // Grab key strokes for keyboard navigation of agenda. Seems to have no
256 // effect. Has to be fixed. 256 // effect. Has to be fixed.
257 setFocusPolicy(WheelFocus); 257 setFocusPolicy(WheelFocus);
258 258
259 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp())); 259 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp()));
260 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown())); 260 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown()));
261 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize())); 261 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize()));
262 262
263 mStartCellX = 0; 263 mStartCellX = 0;
264 mStartCellY = 0; 264 mStartCellY = 0;
265 mCurrentCellX = 0; 265 mCurrentCellX = 0;
266 mCurrentCellY = 0; 266 mCurrentCellY = 0;
267 267
268 mSelectionCellX = 0; 268 mSelectionCellX = 0;
269 mSelectionYTop = 0; 269 mSelectionYTop = 0;
270 mSelectionHeight = 0; 270 mSelectionHeight = 0;
271 271
272 mOldLowerScrollValue = -1; 272 mOldLowerScrollValue = -1;
273 mOldUpperScrollValue = -1; 273 mOldUpperScrollValue = -1;
274 274
275 mClickedItem = 0; 275 mClickedItem = 0;
276 276
277 mActionItem = 0; 277 mActionItem = 0;
278 mActionType = NOP; 278 mActionType = NOP;
279 mItemMoved = false; 279 mItemMoved = false;
280 280
281 mSelectedItem = 0; 281 mSelectedItem = 0;
282 282
283 // mItems.setAutoDelete(true); 283 // mItems.setAutoDelete(true);
284 284
285 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 285 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
286 286
287 viewport()->update(); 287 viewport()->update();
288 288
289 setMinimumSize(30, 1); 289 setMinimumSize(30, 1);
290// setMaximumHeight(mGridSpacingY * mRows + 5); 290// setMaximumHeight(mGridSpacingY * mRows + 5);
291 291
292 // Disable horizontal scrollbar. This is a hack. The geometry should be 292 // Disable horizontal scrollbar. This is a hack. The geometry should be
293 // controlled in a way that the contents horizontally always fits. Then it is 293 // controlled in a way that the contents horizontally always fits. Then it is
294 // not necessary to turn off the scrollbar. 294 // not necessary to turn off the scrollbar.
295 setHScrollBarMode(AlwaysOff); 295 setHScrollBarMode(AlwaysOff);
296 if ( ! mAllDayMode ) 296 if ( ! mAllDayMode )
297 setVScrollBarMode(AlwaysOn); 297 setVScrollBarMode(AlwaysOn);
298 else 298 else
299 setVScrollBarMode(AlwaysOff); 299 setVScrollBarMode(AlwaysOff);
300 300
301 setStartHour(KOPrefs::instance()->mDayBegins); 301 setStartHour(KOPrefs::instance()->mDayBegins);
302 302
303 calculateWorkingHours(); 303 calculateWorkingHours();
304 304
305 connect(verticalScrollBar(),SIGNAL(valueChanged(int)), 305 connect(verticalScrollBar(),SIGNAL(valueChanged(int)),
306 SLOT(checkScrollBoundaries(int))); 306 SLOT(checkScrollBoundaries(int)));
307 307
308 // Create the Marcus Bains line. 308 // Create the Marcus Bains line.
309 if(mAllDayMode) 309 if(mAllDayMode)
310 mMarcusBains = 0; 310 mMarcusBains = 0;
311 else { 311 else {
312 mMarcusBains = new MarcusBains(this); 312 mMarcusBains = new MarcusBains(this);
313 addChild(mMarcusBains); 313 addChild(mMarcusBains);
314 } 314 }
315} 315}
316 316
317void KOAgenda::clear() 317void KOAgenda::clear()
318{ 318{
319 KOAgendaItem *item; 319 KOAgendaItem *item;
320 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 320 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
321 mUnusedItems.append( item ); 321 mUnusedItems.append( item );
322 //item->hide(); 322 //item->hide();
323 } 323 }
324 mItems.clear(); 324 mItems.clear();
325 mSelectedItem = 0; 325 mSelectedItem = 0;
326 clearSelection(); 326 clearSelection();
327} 327}
328 328
329void KOAgenda::clearSelection() 329void KOAgenda::clearSelection()
330{ 330{
331 mSelectionCellX = 0; 331 mSelectionCellX = 0;
332 mSelectionYTop = 0; 332 mSelectionYTop = 0;
333 mSelectionHeight = 0; 333 mSelectionHeight = 0;
334} 334}
335 335
336void KOAgenda::marcus_bains() 336void KOAgenda::marcus_bains()
337{ 337{
338 if(mMarcusBains) mMarcusBains->updateLocation(true); 338 if(mMarcusBains) mMarcusBains->updateLocation(true);
339} 339}
340 340
341 341
342void KOAgenda::changeColumns(int columns) 342void KOAgenda::changeColumns(int columns)
343{ 343{
344 if (columns == 0) { 344 if (columns == 0) {
345 kdDebug() << "KOAgenda::changeColumns() called with argument 0" << endl; 345 kdDebug() << "KOAgenda::changeColumns() called with argument 0" << endl;
346 return; 346 return;
347 } 347 }
348 348
349 clear(); 349 clear();
350 350
351 mColumns = columns; 351 mColumns = columns;
352// setMinimumSize(mColumns * 10, mGridSpacingY + 1); 352// setMinimumSize(mColumns * 10, mGridSpacingY + 1);
353// init(); 353// init();
354// update(); 354// update();
355 //qDebug("KOAgenda::changeColumns "); 355 //qDebug("KOAgenda::changeColumns ");
356 computeSizes(); 356 computeSizes();
357 // QResizeEvent event( size(), size() ); 357 // QResizeEvent event( size(), size() );
358 358
359 //QApplication::sendEvent( this, &event ); 359 //QApplication::sendEvent( this, &event );
360} 360}
361 361
362/* 362/*
363 This is the eventFilter function, which gets all events from the KOAgendaItems 363 This is the eventFilter function, which gets all events from the KOAgendaItems
364 contained in the agenda. It has to handle moving and resizing for all items. 364 contained in the agenda. It has to handle moving and resizing for all items.
365*/ 365*/
366bool KOAgenda::eventFilter ( QObject *object, QEvent *event ) 366bool KOAgenda::eventFilter ( QObject *object, QEvent *event )
367{ 367{
368// kdDebug() << "KOAgenda::eventFilter" << endl; 368// kdDebug() << "KOAgenda::eventFilter" << endl;
369 switch(event->type()) { 369 switch(event->type()) {
370 case QEvent::MouseButtonPress: 370 case QEvent::MouseButtonPress:
371 case QEvent::MouseButtonDblClick: 371 case QEvent::MouseButtonDblClick:
372 case QEvent::MouseButtonRelease: 372 case QEvent::MouseButtonRelease:
373 case QEvent::MouseMove: 373 case QEvent::MouseMove:
374 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event)); 374 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event));
375 375
376 case (QEvent::Leave): 376 case (QEvent::Leave):
377 if (!mActionItem) 377 if (!mActionItem)
378 setCursor(arrowCursor); 378 setCursor(arrowCursor);
379 return true; 379 return true;
380 380
381 default: 381 default:
382 return QScrollView::eventFilter(object,event); 382 return QScrollView::eventFilter(object,event);
383 } 383 }
384} 384}
385 385
386 386
387bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) 387bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me)
388{ 388{
389 //qDebug("KOAgenda::eventFilter_mous "); 389 //qDebug("KOAgenda::eventFilter_mous ");
390 QPoint viewportPos; 390 QPoint viewportPos;
391 if (object != viewport()) { 391 if (object != viewport()) {
392 viewportPos = ((QWidget *)object)->mapToParent(me->pos()); 392 viewportPos = ((QWidget *)object)->mapToParent(me->pos());
393 } else { 393 } else {
394 viewportPos = me->pos(); 394 viewportPos = me->pos();
395 } 395 }
396 static int startX = 0; 396 static int startX = 0;
397 static int startY = 0; 397 static int startY = 0;
398 static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 ); 398 static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 );
399 static bool blockMoving = true; 399 static bool blockMoving = true;
400 static bool leftMouseDown = false; 400 static bool leftMouseDown = false;
401 static bool rightMouseDown = false;
402 static QTime rightClickTime;
403 bool rightButtonPressed = false; 401 bool rightButtonPressed = false;
404 switch (me->type()) { 402 switch (me->type()) {
405 case QEvent::MouseButtonPress: 403 case QEvent::MouseButtonPress:
406 rightClickTime.restart();
407 if (me->button() == LeftButton) { 404 if (me->button() == LeftButton) {
408 leftMouseDown = true; 405 leftMouseDown = true;
409 } 406 }
410 else if (me->button() == RightButton) 407 else if (me->button() == RightButton) {
411 rightMouseDown = true; 408 leftMouseDown = false;
409 }
412 blockMoving = true; 410 blockMoving = true;
413 startX = viewportPos.x(); 411 startX = viewportPos.x();
414 startY = viewportPos.y(); 412 startY = viewportPos.y();
415 if (object != viewport()) { 413 if (object != viewport()) { // item clicked **************
416 if (me->button() == RightButton) { 414 if (me->button() == RightButton) {
415 leftMouseDown = false;
417 mClickedItem = (KOAgendaItem *)object; 416 mClickedItem = (KOAgendaItem *)object;
417 if (mActionItem ) {
418 endItemAction();
419 }
418 if (mClickedItem) { 420 if (mClickedItem) {
419 selectItem(mClickedItem); 421 selectItem(mClickedItem);
420 } 422 emit showIncidencePopupSignal(mClickedItem->incidence());
423 }
424 return true;
421 } else if (me->button() == LeftButton) { 425 } else if (me->button() == LeftButton) {
422 mActionItem = (KOAgendaItem *)object; 426 mActionItem = (KOAgendaItem *)object;
423 if (mActionItem) { 427 if (mActionItem) {
424 if ( mSelectionHeight > 0 ) { 428 if ( mSelectionHeight > 0 ) {
425 int selectionCellX = mSelectionCellX * mGridSpacingX; 429 int selectionCellX = mSelectionCellX * mGridSpacingX;
426 int selectionYTop = mSelectionYTop; 430 int selectionYTop = mSelectionYTop;
427 int gridSpacingX = mGridSpacingX; 431 int gridSpacingX = mGridSpacingX;
428 int selectionHeight = mSelectionHeight; 432 int selectionHeight = mSelectionHeight;
429 clearSelection(); 433 clearSelection();
430 repaintContents( selectionCellX, selectionYTop, 434 repaintContents( selectionCellX, selectionYTop,
431 gridSpacingX, selectionHeight,false ); 435 gridSpacingX, selectionHeight,false );
432 } 436 }
433 selectItem(mActionItem); 437 selectItem(mActionItem);
434 Incidence *incidence = mActionItem->incidence(); 438 Incidence *incidence = mActionItem->incidence();
435 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { 439 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) {
436 mActionItem = 0; 440 mActionItem = 0;
437 } else { 441 } else {
438 startItemAction(viewportPos); 442 startItemAction(viewportPos);
439 } 443 }
440 } 444 }
441 } 445 }
442 } else { // ---------- viewport() 446 } else { // ---------- viewport()
443 selectItem(0); 447 selectItem(0);
444 mActionItem = 0; 448 mActionItem = 0;
445 if (me->button() == LeftButton ) { 449 if (me->button() == LeftButton ) {
446 setCursor(arrowCursor); 450 setCursor(arrowCursor);
447 startSelectAction(viewportPos); 451 startSelectAction(viewportPos);
452 } else if (me->button() == RightButton ) {
453 setCursor(arrowCursor);
454 if ( leftMouseDown ) { // we have a simulated right click - clear left mouse action
455 endSelectAction( false ); // do not emit new event signal
456 leftMouseDown = false; // no more leftMouse computation
457 }
458 int x,y;
459 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
460 int gx,gy;
461 contentsToGrid(x,y,gx,gy);
462 mCurrentCellX = gx;
463 mCurrentCellY = gy;
464 mStartCellX = gx;
465 mStartCellY = gy;
466 mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) );
448 } 467 }
449 } 468 }
450 break; 469 break;
451 470
452 case QEvent::MouseButtonRelease: 471 case QEvent::MouseButtonRelease:
453 if ( rightClickTime.elapsed() > 500 && blockMoving ) 472
454 rightButtonPressed = true;
455 if (object != viewport()) { 473 if (object != viewport()) {
456 if (me->button() == RightButton || rightButtonPressed ) { 474 if (me->button() == LeftButton && leftMouseDown) {
457 if ( blockMoving ) {
458 mClickedItem = (KOAgendaItem *)object;
459 if (mActionItem ) {
460 endItemAction();
461 }
462 leftMouseDown = false; // no more leftMouse computation
463 if (mClickedItem) {
464 selectItem(mClickedItem);
465 emit showIncidencePopupSignal(mClickedItem->incidence());
466 }
467 }
468 } else if (me->button() == LeftButton && leftMouseDown) {
469 if (mActionItem) { 475 if (mActionItem) {
470 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 476 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos));
471 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); 477 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 );
472 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { 478 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) {
473 mScrollUpTimer.stop(); 479 mScrollUpTimer.stop();
474 mScrollDownTimer.stop(); 480 mScrollDownTimer.stop();
475 mActionItem->resetMove(); 481 mActionItem->resetMove();
476 placeSubCells( mActionItem ); 482 placeSubCells( mActionItem );
477 // emit startDragSignal( mActionItem->incidence() ); 483 // emit startDragSignal( mActionItem->incidence() );
478 setCursor( arrowCursor ); 484 setCursor( arrowCursor );
479 mActionItem = 0; 485 mActionItem = 0;
480 mActionType = NOP; 486 mActionType = NOP;
481 mItemMoved = 0; 487 mItemMoved = 0;
482 leftMouseDown = false; 488 leftMouseDown = false;
483 return true; 489 return true;
484 } 490 }
485 endItemAction(); 491 endItemAction();
486 } 492 }
487 } 493 }
488 494
489 } else { // ---------- viewport() 495 } else { // ---------- viewport()
490 if (me->button() == RightButton || rightButtonPressed ) { //right click 496 if (me->button() == LeftButton && leftMouseDown ) { //left click
491 if ( blockMoving ) { // we did mot moved the mouse much - popup menu
492 if ( leftMouseDown ) { // we have a simulated right click - clear left mouse action
493 endSelectAction( false ); // do not emit new event signal
494 leftMouseDown = false; // no more leftMouse computation
495 }
496 int x,y;
497 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
498 int gx,gy;
499 contentsToGrid(x,y,gx,gy);
500 mCurrentCellX = gx;
501 mCurrentCellY = gy;
502 mStartCellX = gx;
503 mStartCellY = gy;
504 mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) );
505 }
506 }
507 else if (me->button() == LeftButton && leftMouseDown ) { //left click
508 endSelectAction( true ); // emit new event signal 497 endSelectAction( true ); // emit new event signal
509 } 498 }
510 } 499 }
511 if (me->button() == LeftButton) 500 if (me->button() == LeftButton)
512 leftMouseDown = false; 501 leftMouseDown = false;
513 else if (me->button() == RightButton) 502
514 rightMouseDown = false;
515 break; 503 break;
516 504
517 case QEvent::MouseMove: 505 case QEvent::MouseMove:
518 if ( !rightMouseDown && !leftMouseDown ) 506 if ( !leftMouseDown )
519 return true; 507 return true;
520 if ( blockMoving ) { 508 if ( blockMoving ) {
521 int dX, dY; 509 int dX, dY;
522 dX = startX - viewportPos.x(); 510 dX = startX - viewportPos.x();
523 if ( dX < 0 ) 511 if ( dX < 0 )
524 dX = -dX; 512 dX = -dX;
525 dY = viewportPos.y() - startY; 513 dY = viewportPos.y() - startY;
526 if ( dY < 0 ) 514 if ( dY < 0 )
527 dY = -dY; 515 dY = -dY;
528 //qDebug("%d %d %d ", dX, dY , blockmoveDist ); 516 //qDebug("%d %d %d ", dX, dY , blockmoveDist );
529 if ( dX > blockmoveDist || dY > blockmoveDist ) { 517 if ( dX > blockmoveDist || dY > blockmoveDist ) {
530 blockMoving = false; 518 blockMoving = false;
531 } 519 }
532 } 520 }
533 if (object != viewport()) { 521 if (object != viewport()) {
534 KOAgendaItem *moveItem = (KOAgendaItem *)object; 522 KOAgendaItem *moveItem = (KOAgendaItem *)object;
535 if (!moveItem->incidence()->isReadOnly() ) { 523 if (!moveItem->incidence()->isReadOnly() ) {
536 if (!mActionItem) 524 if (!mActionItem)
537 setNoActionCursor(moveItem,viewportPos); 525 setNoActionCursor(moveItem,viewportPos);
538 else { 526 else {
539 if ( !blockMoving ) 527 if ( !blockMoving )
540 performItemAction(viewportPos); 528 performItemAction(viewportPos);
541 } 529 }
542 } 530 }
543 } else { // ---------- viewport() 531 } else { // ---------- viewport()
544 if ( mActionType == SELECT ) { 532 if ( mActionType == SELECT ) {
545 performSelectAction( viewportPos ); 533 performSelectAction( viewportPos );
546 } 534 }
547 } 535 }
548 break; 536 break;
549 537
550 case QEvent::MouseButtonDblClick: 538 case QEvent::MouseButtonDblClick:
551 blockMoving = false; 539 blockMoving = false;
552 leftMouseDown = false; 540 leftMouseDown = false;
553 rightMouseDown = false;
554 if (object == viewport()) { 541 if (object == viewport()) {
555 selectItem(0); 542 selectItem(0);
556 int x,y; 543 int x,y;
557 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 544 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
558 int gx,gy; 545 int gx,gy;
559 contentsToGrid(x,y,gx,gy); 546 contentsToGrid(x,y,gx,gy);
560 emit newEventSignal(gx,gy); 547 emit newEventSignal(gx,gy);
561 } else { 548 } else {
562 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; 549 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object;
563 selectItem(doubleClickedItem); 550 selectItem(doubleClickedItem);
564 if ( KOPrefs::instance()->mEditOnDoubleClick ) 551 if ( KOPrefs::instance()->mEditOnDoubleClick )
565 emit editIncidenceSignal(doubleClickedItem->incidence()); 552 emit editIncidenceSignal(doubleClickedItem->incidence());
566 else 553 else
567 emit showIncidenceSignal(doubleClickedItem->incidence()); 554 emit showIncidenceSignal(doubleClickedItem->incidence());
568 } 555 }
569 break; 556 break;
570 557
571 default: 558 default:
572 break; 559 break;
573 } 560 }
574 return true; 561 return true;
575} 562}
576 563
577void KOAgenda::newItem( int item ) 564void KOAgenda::newItem( int item )
578{ 565{
579 if ( item == 1 ) { //new event 566 if ( item == 1 ) { //new event
580 newEventSignal(mStartCellX ,mStartCellY ); 567 newEventSignal(mStartCellX ,mStartCellY );
581 } else 568 } else
582 if ( item == 2 ) { //new event 569 if ( item == 2 ) { //new event
583 newTodoSignal(mStartCellX ,mStartCellY ); 570 newTodoSignal(mStartCellX ,mStartCellY );
584 } else 571 } else
585 { 572 {
586 QDate day = mSelectedDates[mStartCellX]; 573 QDate day = mSelectedDates[mStartCellX];
587 emit showDateView( item, day ); 574 emit showDateView( item, day );
588 // 3Day view 575 // 3Day view
589 // 4Week view 576 // 4Week view
590 // 5Month view 577 // 5Month view
591 // 6Journal view 578 // 6Journal view
592 } 579 }
593} 580}
594void KOAgenda::startSelectAction(QPoint viewportPos) 581void KOAgenda::startSelectAction(QPoint viewportPos)
595{ 582{
596 //emit newStartSelectSignal(); 583 //emit newStartSelectSignal();
597 584
598 mActionType = SELECT; 585 mActionType = SELECT;
599 586
600 int x,y; 587 int x,y;
601 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 588 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
602 int gx,gy; 589 int gx,gy;
603 contentsToGrid(x,y,gx,gy); 590 contentsToGrid(x,y,gx,gy);
604 591
605 mStartCellX = gx; 592 mStartCellX = gx;
606 mStartCellY = gy; 593 mStartCellY = gy;
607 mCurrentCellX = gx; 594 mCurrentCellX = gx;
608 mCurrentCellY = gy; 595 mCurrentCellY = gy;
609 596
610 // Store coordinates of old selection 597 // Store coordinates of old selection
611 int selectionX = mSelectionCellX * mGridSpacingX; 598 int selectionX = mSelectionCellX * mGridSpacingX;
612 int selectionYTop = mSelectionYTop; 599 int selectionYTop = mSelectionYTop;
613 int selectionHeight = mSelectionHeight; 600 int selectionHeight = mSelectionHeight;
614 601
615 // Store new selection 602 // Store new selection
616 mSelectionCellX = gx; 603 mSelectionCellX = gx;
617 mSelectionYTop = gy * mGridSpacingY; 604 mSelectionYTop = gy * mGridSpacingY;
618 mSelectionHeight = mGridSpacingY; 605 mSelectionHeight = mGridSpacingY;
619 606
620 // Clear old selection 607 // Clear old selection
621 repaintContents( selectionX, selectionYTop, 608 repaintContents( selectionX, selectionYTop,
622 mGridSpacingX, selectionHeight,false ); 609 mGridSpacingX, selectionHeight,false );
623 610
624 // Paint new selection 611 // Paint new selection
625 // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop, 612 // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop,
626 // mGridSpacingX, mSelectionHeight ); 613 // mGridSpacingX, mSelectionHeight );
627} 614}
628 615
629void KOAgenda::performSelectAction(QPoint viewportPos) 616void KOAgenda::performSelectAction(QPoint viewportPos)
630{ 617{
631 int x,y; 618 int x,y;
632 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 619 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
633 int gx,gy; 620 int gx,gy;
634 contentsToGrid(x,y,gx,gy); 621 contentsToGrid(x,y,gx,gy);
635 622
636 QPoint clipperPos = clipper()-> 623 QPoint clipperPos = clipper()->
637 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 624 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
638 625
639 // Scroll if cursor was moved to upper or lower end of agenda. 626 // Scroll if cursor was moved to upper or lower end of agenda.
640 if (clipperPos.y() < mScrollBorderWidth) { 627 if (clipperPos.y() < mScrollBorderWidth) {
641 mScrollUpTimer.start(mScrollDelay); 628 mScrollUpTimer.start(mScrollDelay);
642 } else if (visibleHeight() - clipperPos.y() < 629 } else if (visibleHeight() - clipperPos.y() <
643 mScrollBorderWidth) { 630 mScrollBorderWidth) {
644 mScrollDownTimer.start(mScrollDelay); 631 mScrollDownTimer.start(mScrollDelay);
645 } else { 632 } else {
646 mScrollUpTimer.stop(); 633 mScrollUpTimer.stop();
647 mScrollDownTimer.stop(); 634 mScrollDownTimer.stop();
648 } 635 }
649 636
650 if ( gy > mCurrentCellY ) { 637 if ( gy > mCurrentCellY ) {
651 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 638 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
652 639
653#if 0 640#if 0
654 // FIXME: Repaint only the newly selected region 641 // FIXME: Repaint only the newly selected region
655 repaintContents( mSelectionCellX * mGridSpacingX, 642 repaintContents( mSelectionCellX * mGridSpacingX,
656 mCurrentCellY + mGridSpacingY, 643 mCurrentCellY + mGridSpacingY,
657 mGridSpacingX, 644 mGridSpacingX,
658 mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY ); 645 mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY );
659#else 646#else
660 repaintContents( (KOGlobals::self()->reverseLayout() ? 647 repaintContents( (KOGlobals::self()->reverseLayout() ?
661 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 648 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
662 mGridSpacingX, mSelectionYTop, 649 mGridSpacingX, mSelectionYTop,
663 mGridSpacingX, mSelectionHeight , false); 650 mGridSpacingX, mSelectionHeight , false);
664#endif 651#endif
665 652
666 mCurrentCellY = gy; 653 mCurrentCellY = gy;
667 } else if ( gy < mCurrentCellY ) { 654 } else if ( gy < mCurrentCellY ) {
668 if ( gy >= mStartCellY ) { 655 if ( gy >= mStartCellY ) {
669 int selectionHeight = mSelectionHeight; 656 int selectionHeight = mSelectionHeight;
670 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 657 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
671 658
672 repaintContents( (KOGlobals::self()->reverseLayout() ? 659 repaintContents( (KOGlobals::self()->reverseLayout() ?
673 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 660 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
674 mGridSpacingX, mSelectionYTop, 661 mGridSpacingX, mSelectionYTop,
675 mGridSpacingX, selectionHeight,false ); 662 mGridSpacingX, selectionHeight,false );
676 663
677 mCurrentCellY = gy; 664 mCurrentCellY = gy;
678 } else { 665 } else {
679 } 666 }
680 } 667 }
681} 668}
682 669
683void KOAgenda::endSelectAction( bool emitNewEvent ) 670void KOAgenda::endSelectAction( bool emitNewEvent )
684{ 671{
685 mActionType = NOP; 672 mActionType = NOP;
686 mScrollUpTimer.stop(); 673 mScrollUpTimer.stop();
687 mScrollDownTimer.stop(); 674 mScrollDownTimer.stop();
688 675
689 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); 676 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
690 if ( emitNewEvent && mStartCellY < mCurrentCellY ) { 677 if ( emitNewEvent && mStartCellY < mCurrentCellY ) {
691 qDebug("ew event signal "); 678 qDebug("ew event signal ");
692 emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); 679 emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
693 } 680 }
694} 681}
695 682
696void KOAgenda::startItemAction(QPoint viewportPos) 683void KOAgenda::startItemAction(QPoint viewportPos)
697{ 684{
698 int x,y; 685 int x,y;
699 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 686 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
700 int gx,gy; 687 int gx,gy;
701 contentsToGrid(x,y,gx,gy); 688 contentsToGrid(x,y,gx,gy);
702 689
703 mStartCellX = gx; 690 mStartCellX = gx;
704 mStartCellY = gy; 691 mStartCellY = gy;
705 mCurrentCellX = gx; 692 mCurrentCellX = gx;
706 mCurrentCellY = gy; 693 mCurrentCellY = gy;
707 694
708 if (mAllDayMode) { 695 if (mAllDayMode) {
709 int gridDistanceX = (x - gx * mGridSpacingX); 696 int gridDistanceX = (x - gx * mGridSpacingX);
710 if (gridDistanceX < mResizeBorderWidth && 697 if (gridDistanceX < mResizeBorderWidth &&
711 mActionItem->cellX() == mCurrentCellX) { 698 mActionItem->cellX() == mCurrentCellX) {
712 mActionType = RESIZELEFT; 699 mActionType = RESIZELEFT;
713 setCursor(sizeHorCursor); 700 setCursor(sizeHorCursor);
714 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 701 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
715 mActionItem->cellXWidth() == mCurrentCellX) { 702 mActionItem->cellXWidth() == mCurrentCellX) {
716 mActionType = RESIZERIGHT; 703 mActionType = RESIZERIGHT;
717 setCursor(sizeHorCursor); 704 setCursor(sizeHorCursor);
718 } else { 705 } else {
719 mActionType = MOVE; 706 mActionType = MOVE;
720 mActionItem->startMove(); 707 mActionItem->startMove();
721 setCursor(sizeAllCursor); 708 setCursor(sizeAllCursor);
722 } 709 }
723 } else { 710 } else {
724 int gridDistanceY = (y - gy * mGridSpacingY); 711 int gridDistanceY = (y - gy * mGridSpacingY);
725 bool allowResize = ( mActionItem->incidence()->type() != "Todo" ); 712 bool allowResize = ( mActionItem->incidence()->type() != "Todo" );
726 if (allowResize && gridDistanceY < mResizeBorderWidth && 713 if (allowResize && gridDistanceY < mResizeBorderWidth &&
727 mActionItem->cellYTop() == mCurrentCellY && 714 mActionItem->cellYTop() == mCurrentCellY &&
728 !mActionItem->firstMultiItem()) { 715 !mActionItem->firstMultiItem()) {
729 mActionType = RESIZETOP; 716 mActionType = RESIZETOP;
730 setCursor(sizeVerCursor); 717 setCursor(sizeVerCursor);
731 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 718 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
732 mActionItem->cellYBottom() == mCurrentCellY && 719 mActionItem->cellYBottom() == mCurrentCellY &&
733 !mActionItem->lastMultiItem()) { 720 !mActionItem->lastMultiItem()) {
734 mActionType = RESIZEBOTTOM; 721 mActionType = RESIZEBOTTOM;
735 setCursor(sizeVerCursor); 722 setCursor(sizeVerCursor);
736 } else { 723 } else {
737 mActionType = MOVE; 724 mActionType = MOVE;
738 mActionItem->startMove(); 725 mActionItem->startMove();
739 setCursor(sizeAllCursor); 726 setCursor(sizeAllCursor);
740 } 727 }
741 } 728 }
742} 729}
743 730
744void KOAgenda::performItemAction(QPoint viewportPos) 731void KOAgenda::performItemAction(QPoint viewportPos)
745{ 732{
746// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 733// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
747// QPoint point = viewport()->mapToGlobal(viewportPos); 734// QPoint point = viewport()->mapToGlobal(viewportPos);
748// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 735// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
749// point = clipper()->mapFromGlobal(point); 736// point = clipper()->mapFromGlobal(point);
750// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 737// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
751// kdDebug() << "visible height: " << visibleHeight() << endl; 738// kdDebug() << "visible height: " << visibleHeight() << endl;
752 int x,y; 739 int x,y;
753 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 740 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
754// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 741// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
755 int gx,gy; 742 int gx,gy;
756 contentsToGrid(x,y,gx,gy); 743 contentsToGrid(x,y,gx,gy);
757 QPoint clipperPos = clipper()-> 744 QPoint clipperPos = clipper()->
758 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 745 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
759 746
760 // Cursor left active agenda area. 747 // Cursor left active agenda area.
761 // This starts a drag. 748 // This starts a drag.
762 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/ 749 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/
763 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) { 750 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) {
764 if ( mActionType == MOVE ) { 751 if ( mActionType == MOVE ) {
765 mScrollUpTimer.stop(); 752 mScrollUpTimer.stop();
766 mScrollDownTimer.stop(); 753 mScrollDownTimer.stop();
767 mActionItem->resetMove(); 754 mActionItem->resetMove();
768 placeSubCells( mActionItem ); 755 placeSubCells( mActionItem );
769 // emit startDragSignal( mActionItem->incidence() ); 756 // emit startDragSignal( mActionItem->incidence() );
770 setCursor( arrowCursor ); 757 setCursor( arrowCursor );
771 mActionItem = 0; 758 mActionItem = 0;
772 mActionType = NOP; 759 mActionType = NOP;
773 mItemMoved = 0; 760 mItemMoved = 0;
774 return; 761 return;
775 } 762 }
776 } else { 763 } else {
777 switch ( mActionType ) { 764 switch ( mActionType ) {
778 case MOVE: 765 case MOVE:
779 setCursor( sizeAllCursor ); 766 setCursor( sizeAllCursor );
780 break; 767 break;
781 case RESIZETOP: 768 case RESIZETOP:
782 case RESIZEBOTTOM: 769 case RESIZEBOTTOM:
783 setCursor( sizeVerCursor ); 770 setCursor( sizeVerCursor );
784 break; 771 break;
785 case RESIZELEFT: 772 case RESIZELEFT:
786 case RESIZERIGHT: 773 case RESIZERIGHT:
787 setCursor( sizeHorCursor ); 774 setCursor( sizeHorCursor );
788 break; 775 break;
789 default: 776 default:
790 setCursor( arrowCursor ); 777 setCursor( arrowCursor );
791 } 778 }
792 } 779 }
793 780
794 // Scroll if item was moved to upper or lower end of agenda. 781 // Scroll if item was moved to upper or lower end of agenda.
795 if (clipperPos.y() < mScrollBorderWidth) { 782 if (clipperPos.y() < mScrollBorderWidth) {
796 mScrollUpTimer.start(mScrollDelay); 783 mScrollUpTimer.start(mScrollDelay);
797 } else if (visibleHeight() - clipperPos.y() < 784 } else if (visibleHeight() - clipperPos.y() <
798 mScrollBorderWidth) { 785 mScrollBorderWidth) {
799 mScrollDownTimer.start(mScrollDelay); 786 mScrollDownTimer.start(mScrollDelay);
800 } else { 787 } else {
801 mScrollUpTimer.stop(); 788 mScrollUpTimer.stop();
802 mScrollDownTimer.stop(); 789 mScrollDownTimer.stop();
803 } 790 }
804 791
805 // Move or resize item if necessary 792 // Move or resize item if necessary
806 if (mCurrentCellX != gx || mCurrentCellY != gy) { 793 if (mCurrentCellX != gx || mCurrentCellY != gy) {
807 mItemMoved = true; 794 mItemMoved = true;
808 mActionItem->raise(); 795 mActionItem->raise();
809 if (mActionType == MOVE) { 796 if (mActionType == MOVE) {
810 // Move all items belonging to a multi item 797 // Move all items belonging to a multi item
811 KOAgendaItem *moveItem = mActionItem->firstMultiItem(); 798 KOAgendaItem *moveItem = mActionItem->firstMultiItem();
812 bool isMultiItem = (moveItem || mActionItem->lastMultiItem()); 799 bool isMultiItem = (moveItem || mActionItem->lastMultiItem());
813 if (!moveItem) moveItem = mActionItem; 800 if (!moveItem) moveItem = mActionItem;
814 while (moveItem) { 801 while (moveItem) {
815 int dy; 802 int dy;
816 if (isMultiItem) dy = 0; 803 if (isMultiItem) dy = 0;
817 else dy = gy - mCurrentCellY; 804 else dy = gy - mCurrentCellY;
818 moveItem->moveRelative(gx - mCurrentCellX,dy); 805 moveItem->moveRelative(gx - mCurrentCellX,dy);
819 int x,y; 806 int x,y;
820 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y); 807 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y);
821 moveItem->resize(mGridSpacingX * moveItem->cellWidth(), 808 moveItem->resize(mGridSpacingX * moveItem->cellWidth(),
822 mGridSpacingY * moveItem->cellHeight()); 809 mGridSpacingY * moveItem->cellHeight());
823 moveChild(moveItem,x,y); 810 moveChild(moveItem,x,y);
824 moveItem = moveItem->nextMultiItem(); 811 moveItem = moveItem->nextMultiItem();
825 } 812 }
826 } else if (mActionType == RESIZETOP) { 813 } else if (mActionType == RESIZETOP) {
827 if (mCurrentCellY <= mActionItem->cellYBottom()) { 814 if (mCurrentCellY <= mActionItem->cellYBottom()) {
828 mActionItem->expandTop(gy - mCurrentCellY); 815 mActionItem->expandTop(gy - mCurrentCellY);
829 mActionItem->resize(mActionItem->width(), 816 mActionItem->resize(mActionItem->width(),
830 mGridSpacingY * mActionItem->cellHeight()); 817 mGridSpacingY * mActionItem->cellHeight());
831 int x,y; 818 int x,y;
832 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y); 819 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y);
833 //moveChild(mActionItem,childX(mActionItem),y); 820 //moveChild(mActionItem,childX(mActionItem),y);
834 QScrollView::moveChild( mActionItem,childX(mActionItem),y ); 821 QScrollView::moveChild( mActionItem,childX(mActionItem),y );
835 } 822 }
836 } else if (mActionType == RESIZEBOTTOM) { 823 } else if (mActionType == RESIZEBOTTOM) {
837 if (mCurrentCellY >= mActionItem->cellYTop()) { 824 if (mCurrentCellY >= mActionItem->cellYTop()) {
838 mActionItem->expandBottom(gy - mCurrentCellY); 825 mActionItem->expandBottom(gy - mCurrentCellY);
839 mActionItem->resize(mActionItem->width(), 826 mActionItem->resize(mActionItem->width(),
840 mGridSpacingY * mActionItem->cellHeight()); 827 mGridSpacingY * mActionItem->cellHeight());
841 } 828 }
842 } else if (mActionType == RESIZELEFT) { 829 } else if (mActionType == RESIZELEFT) {
843 if (mCurrentCellX <= mActionItem->cellXWidth()) { 830 if (mCurrentCellX <= mActionItem->cellXWidth()) {
844 mActionItem->expandLeft(gx - mCurrentCellX); 831 mActionItem->expandLeft(gx - mCurrentCellX);
845 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 832 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
846 mActionItem->height()); 833 mActionItem->height());
847 int x,y; 834 int x,y;
848 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y); 835 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y);
849 moveChild(mActionItem,x,childY(mActionItem)); 836 moveChild(mActionItem,x,childY(mActionItem));
850 } 837 }
851 } else if (mActionType == RESIZERIGHT) { 838 } else if (mActionType == RESIZERIGHT) {
852 if (mCurrentCellX >= mActionItem->cellX()) { 839 if (mCurrentCellX >= mActionItem->cellX()) {
853 mActionItem->expandRight(gx - mCurrentCellX); 840 mActionItem->expandRight(gx - mCurrentCellX);
854 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 841 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
855 mActionItem->height()); 842 mActionItem->height());
856 } 843 }
857 } 844 }
858 mCurrentCellX = gx; 845 mCurrentCellX = gx;
859 mCurrentCellY = gy; 846 mCurrentCellY = gy;
860 } 847 }
861} 848}
862 849
863void KOAgenda::endItemAction() 850void KOAgenda::endItemAction()
864{ 851{
865 852
866 if ( mItemMoved ) { 853 if ( mItemMoved ) {
867 KOAgendaItem *placeItem = mActionItem->firstMultiItem(); 854 KOAgendaItem *placeItem = mActionItem->firstMultiItem();
868 if ( !placeItem ) { 855 if ( !placeItem ) {
869 placeItem = mActionItem; 856 placeItem = mActionItem;
870 } 857 }
871 if ( placeItem->incidence()->recurrence()->doesRecur() ) { 858 if ( placeItem->incidence()->recurrence()->doesRecur() ) {
872 Incidence* oldInc = placeItem->incidence(); 859 Incidence* oldInc = placeItem->incidence();
873 placeItem->recreateIncidence(); 860 placeItem->recreateIncidence();
874 emit addToCalSignal(placeItem->incidence(), oldInc ); 861 emit addToCalSignal(placeItem->incidence(), oldInc );
875 } 862 }
876 int type = mActionType; 863 int type = mActionType;
877 if ( mAllDayMode ) 864 if ( mAllDayMode )
878 type = -1; 865 type = -1;
879 KOAgendaItem *modifiedItem = placeItem; 866 KOAgendaItem *modifiedItem = placeItem;
880 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */); 867 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */);
881 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems(); 868 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems();
882 KOAgendaItem *item; 869 KOAgendaItem *item;
883 870
884 if ( placeItem->incidence()->type() == "Todo" ) { 871 if ( placeItem->incidence()->type() == "Todo" ) {
885 mSelectedItem = 0; 872 mSelectedItem = 0;
886 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth()); 873 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth());
887 modifiedItem->mLastMoveXPos = mCurrentCellX; 874 modifiedItem->mLastMoveXPos = mCurrentCellX;
888 emit itemModified( modifiedItem, mActionType ); 875 emit itemModified( modifiedItem, mActionType );
889 } 876 }
890 else { 877 else {
891#if 0 878#if 0
892 for ( item=oldconflictItems.first(); item != 0; 879 for ( item=oldconflictItems.first(); item != 0;
893 item=oldconflictItems.next() ) { 880 item=oldconflictItems.next() ) {
894 placeSubCells(item); 881 placeSubCells(item);
895 } 882 }
896 while ( placeItem ) { 883 while ( placeItem ) {
897 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 884 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
898 placeSubCells( placeItem ); 885 placeSubCells( placeItem );
899 placeItem = placeItem->nextMultiItem(); 886 placeItem = placeItem->nextMultiItem();
900 } 887 }
901#endif 888#endif
902 889
903 globalFlagBlockAgendaItemPaint = 1; 890 globalFlagBlockAgendaItemPaint = 1;
904 for ( item=oldconflictItems.first(); item != 0; 891 for ( item=oldconflictItems.first(); item != 0;
905 item=oldconflictItems.next() ) { 892 item=oldconflictItems.next() ) {
906 placeSubCells(item); 893 placeSubCells(item);
907 } 894 }
908 while ( placeItem ) { 895 while ( placeItem ) {
909 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 896 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
910 oldconflictItems = placeItem->conflictItems(); 897 oldconflictItems = placeItem->conflictItems();
911 for ( item=oldconflictItems.first(); item != 0; 898 for ( item=oldconflictItems.first(); item != 0;
912 item=oldconflictItems.next() ) { 899 item=oldconflictItems.next() ) {
913 placeSubCells(item); 900 placeSubCells(item);
914 } 901 }
915 placeSubCells( placeItem ); 902 placeSubCells( placeItem );
916 placeItem = placeItem->nextMultiItem(); 903 placeItem = placeItem->nextMultiItem();
917 } 904 }
918 globalFlagBlockAgendaItemPaint = 0; 905 globalFlagBlockAgendaItemPaint = 0;
919 for ( item=oldconflictItems.first(); item != 0; 906 for ( item=oldconflictItems.first(); item != 0;
920 item=oldconflictItems.next() ) { 907 item=oldconflictItems.next() ) {
921 globalFlagBlockAgendaItemUpdate = 0; 908 globalFlagBlockAgendaItemUpdate = 0;
922 item->repaintMe(); 909 item->repaintMe();
923 globalFlagBlockAgendaItemUpdate = 1; 910 globalFlagBlockAgendaItemUpdate = 1;
924 item->repaint( false ); 911 item->repaint( false );
925 } 912 }
926 placeItem = modifiedItem; 913 placeItem = modifiedItem;
927 914
928 while ( placeItem ) { 915 while ( placeItem ) {
929 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 916 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
930 globalFlagBlockAgendaItemUpdate = 0; 917 globalFlagBlockAgendaItemUpdate = 0;
931 placeItem->repaintMe(); 918 placeItem->repaintMe();
932 globalFlagBlockAgendaItemUpdate = 1; 919 globalFlagBlockAgendaItemUpdate = 1;
933 placeItem->repaint(false); 920 placeItem->repaint(false);
934 placeItem = placeItem->nextMultiItem(); 921 placeItem = placeItem->nextMultiItem();
935 } 922 }
936 emit itemModified( modifiedItem, mActionType ); 923 emit itemModified( modifiedItem, mActionType );
937 924
938 925
939 placeItem = modifiedItem; 926 placeItem = modifiedItem;
940 while ( placeItem ) { 927 while ( placeItem ) {
941 oldconflictItems = placeItem->conflictItems(); 928 oldconflictItems = placeItem->conflictItems();
942 for ( item=oldconflictItems.first(); item != 0; 929 for ( item=oldconflictItems.first(); item != 0;
943 item=oldconflictItems.next() ) { 930 item=oldconflictItems.next() ) {
944 placeSubCells(item); 931 placeSubCells(item);
945 } 932 }
946 placeSubCells( placeItem ); 933 placeSubCells( placeItem );
947 placeItem = placeItem->nextMultiItem(); 934 placeItem = placeItem->nextMultiItem();
948 935
949 } 936 }
950 placeItem = modifiedItem; 937 placeItem = modifiedItem;
951 while ( placeItem ) { 938 while ( placeItem ) {
952 oldconflictItems = placeItem->conflictItems(); 939 oldconflictItems = placeItem->conflictItems();
953 for ( item=oldconflictItems.first(); item != 0; 940 for ( item=oldconflictItems.first(); item != 0;
954 item=oldconflictItems.next() ) { 941 item=oldconflictItems.next() ) {
955 globalFlagBlockAgendaItemUpdate = 0; 942 globalFlagBlockAgendaItemUpdate = 0;
956 item->repaintMe(); 943 item->repaintMe();
957 globalFlagBlockAgendaItemUpdate = 1; 944 globalFlagBlockAgendaItemUpdate = 1;
958 item->repaint(false); 945 item->repaint(false);
959 } 946 }
960 placeItem = placeItem->nextMultiItem(); 947 placeItem = placeItem->nextMultiItem();
961 } 948 }
962 /* 949 /*
963 950
964 oldconflictItems = modifiedItem->conflictItems(); 951 oldconflictItems = modifiedItem->conflictItems();
965 for ( item=oldconflictItems.first(); item != 0; 952 for ( item=oldconflictItems.first(); item != 0;
966 item=oldconflictItems.next() ) { 953 item=oldconflictItems.next() ) {
967 globalFlagBlockAgendaItemUpdate = 0; 954 globalFlagBlockAgendaItemUpdate = 0;
968 item->paintMe(false); 955 item->paintMe(false);
969 globalFlagBlockAgendaItemUpdate = 1; 956 globalFlagBlockAgendaItemUpdate = 1;
970 item->repaint(false); 957 item->repaint(false);
971 } 958 }
972 */ 959 */
973 960
974 961
975 } 962 }
976 963
977 } 964 }
978 965
979 mScrollUpTimer.stop(); 966 mScrollUpTimer.stop();
980 mScrollDownTimer.stop(); 967 mScrollDownTimer.stop();
981 setCursor( arrowCursor ); 968 setCursor( arrowCursor );
982 mActionItem = 0; 969 mActionItem = 0;
983 mActionType = NOP; 970 mActionType = NOP;
984 mItemMoved = 0; 971 mItemMoved = 0;
985 972
986} 973}
987 974
988void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos) 975void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos)
989{ 976{
990// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 977// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
991// QPoint point = viewport()->mapToGlobal(viewportPos); 978// QPoint point = viewport()->mapToGlobal(viewportPos);
992// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 979// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
993// point = clipper()->mapFromGlobal(point); 980// point = clipper()->mapFromGlobal(point);
994// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 981// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
995 982
996 int x,y; 983 int x,y;
997 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 984 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
998// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 985// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
999 int gx,gy; 986 int gx,gy;
1000 contentsToGrid(x,y,gx,gy); 987 contentsToGrid(x,y,gx,gy);
1001 988
1002 // Change cursor to resize cursor if appropriate 989 // Change cursor to resize cursor if appropriate
1003 if (mAllDayMode) { 990 if (mAllDayMode) {
1004 int gridDistanceX = (x - gx * mGridSpacingX); 991 int gridDistanceX = (x - gx * mGridSpacingX);
1005 if (gridDistanceX < mResizeBorderWidth && 992 if (gridDistanceX < mResizeBorderWidth &&
1006 moveItem->cellX() == gx) { 993 moveItem->cellX() == gx) {
1007 setCursor(sizeHorCursor); 994 setCursor(sizeHorCursor);
1008 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 995 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
1009 moveItem->cellXWidth() == gx) { 996 moveItem->cellXWidth() == gx) {
1010 setCursor(sizeHorCursor); 997 setCursor(sizeHorCursor);
1011 } else { 998 } else {
1012 setCursor(arrowCursor); 999 setCursor(arrowCursor);
1013 } 1000 }
1014 } else { 1001 } else {
1015 int gridDistanceY = (y - gy * mGridSpacingY); 1002 int gridDistanceY = (y - gy * mGridSpacingY);
1016 if (gridDistanceY < mResizeBorderWidth && 1003 if (gridDistanceY < mResizeBorderWidth &&
1017 moveItem->cellYTop() == gy && 1004 moveItem->cellYTop() == gy &&
1018 !moveItem->firstMultiItem()) { 1005 !moveItem->firstMultiItem()) {
1019 setCursor(sizeVerCursor); 1006 setCursor(sizeVerCursor);
1020 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 1007 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
1021 moveItem->cellYBottom() == gy && 1008 moveItem->cellYBottom() == gy &&
1022 !moveItem->lastMultiItem()) { 1009 !moveItem->lastMultiItem()) {
1023 setCursor(sizeVerCursor); 1010 setCursor(sizeVerCursor);
1024 } else { 1011 } else {
1025 setCursor(arrowCursor); 1012 setCursor(arrowCursor);
1026 } 1013 }
1027 } 1014 }
1028} 1015}
1029 1016
1030 1017
1031/* 1018/*
1032 Place item in cell and take care that multiple items using the same cell do 1019 Place item in cell and take care that multiple items using the same cell do
1033 not overlap. This method is not yet optimal. It doesn´t use the maximum space 1020 not overlap. This method is not yet optimal. It doesn´t use the maximum space
1034 it can get in all cases. 1021 it can get in all cases.
1035 At the moment the method has a bug: When an item is placed only the sub cell 1022 At the moment the method has a bug: When an item is placed only the sub cell
1036 widths of the items are changed, which are within the Y region the item to 1023 widths of the items are changed, which are within the Y region the item to
1037 place spans. When the sub cell width change of one of this items affects a 1024 place spans. When the sub cell width change of one of this items affects a
1038 cell, where other items are, which do not overlap in Y with the item to place, 1025 cell, where other items are, which do not overlap in Y with the item to place,
1039 the display gets corrupted, although the corruption looks quite nice. 1026 the display gets corrupted, although the corruption looks quite nice.
1040*/ 1027*/
1041void KOAgenda::placeSubCells(KOAgendaItem *placeItem) 1028void KOAgenda::placeSubCells(KOAgendaItem *placeItem)
1042{ 1029{
1043 1030
1044 QPtrList<KOAgendaItem> conflictItems; 1031 QPtrList<KOAgendaItem> conflictItems;
1045 int maxSubCells = 0; 1032 int maxSubCells = 0;
1046 QIntDict<KOAgendaItem> subCellDict(5); 1033 QIntDict<KOAgendaItem> subCellDict(5);
1047 1034
1048 KOAgendaItem *item; 1035 KOAgendaItem *item;
1049 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1036 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1050 if (item != placeItem) { 1037 if (item != placeItem) {
1051 if (placeItem->cellX() <= item->cellXWidth() && 1038 if (placeItem->cellX() <= item->cellXWidth() &&
1052 placeItem->cellXWidth() >= item->cellX()) { 1039 placeItem->cellXWidth() >= item->cellX()) {
1053 if ((placeItem->cellYTop() <= item->cellYBottom()) && 1040 if ((placeItem->cellYTop() <= item->cellYBottom()) &&
1054 (placeItem->cellYBottom() >= item->cellYTop())) { 1041 (placeItem->cellYBottom() >= item->cellYTop())) {
1055 conflictItems.append(item); 1042 conflictItems.append(item);
1056 if (item->subCells() > maxSubCells) 1043 if (item->subCells() > maxSubCells)
1057 maxSubCells = item->subCells(); 1044 maxSubCells = item->subCells();
1058 subCellDict.insert(item->subCell(),item); 1045 subCellDict.insert(item->subCell(),item);
1059 } 1046 }
1060 } 1047 }
1061 } 1048 }
1062 } 1049 }
1063 1050
1064 if (conflictItems.count() > 0) { 1051 if (conflictItems.count() > 0) {
1065 // Look for unused sub cell and insert item 1052 // Look for unused sub cell and insert item
1066 int i; 1053 int i;
1067 for(i=0;i<maxSubCells;++i) { 1054 for(i=0;i<maxSubCells;++i) {
1068 if (!subCellDict.find(i)) { 1055 if (!subCellDict.find(i)) {
1069 placeItem->setSubCell(i); 1056 placeItem->setSubCell(i);
1070 break; 1057 break;
1071 } 1058 }
1072 } 1059 }
1073 if (i == maxSubCells) { 1060 if (i == maxSubCells) {
1074 placeItem->setSubCell(maxSubCells); 1061 placeItem->setSubCell(maxSubCells);
1075 maxSubCells++; // add new item to number of sub cells 1062 maxSubCells++; // add new item to number of sub cells
1076 } 1063 }
1077 1064
1078 // Prepare for sub cell geometry adjustment 1065 // Prepare for sub cell geometry adjustment
1079 int newSubCellWidth; 1066 int newSubCellWidth;
1080 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells; 1067 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells;
1081 else newSubCellWidth = mGridSpacingX / maxSubCells; 1068 else newSubCellWidth = mGridSpacingX / maxSubCells;
1082 conflictItems.append(placeItem); 1069 conflictItems.append(placeItem);
1083 1070
1084 1071
1085 // Adjust sub cell geometry of all direct conflict items 1072 // Adjust sub cell geometry of all direct conflict items
1086 for ( item=conflictItems.first(); item != 0; 1073 for ( item=conflictItems.first(); item != 0;
1087 item=conflictItems.next() ) { 1074 item=conflictItems.next() ) {
1088 item->setSubCells(maxSubCells); 1075 item->setSubCells(maxSubCells);
1089 if (mAllDayMode) { 1076 if (mAllDayMode) {
1090 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); 1077 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth);
1091 } else { 1078 } else {
1092 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); 1079 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY);
1093 } 1080 }
1094 int x,y; 1081 int x,y;
1095 gridToContents(item->cellX(),item->cellYTop(),x,y); 1082 gridToContents(item->cellX(),item->cellYTop(),x,y);
1096 if (mAllDayMode) { 1083 if (mAllDayMode) {
1097 y += item->subCell() * newSubCellWidth; 1084 y += item->subCell() * newSubCellWidth;
1098 } else { 1085 } else {
1099 x += item->subCell() * newSubCellWidth; 1086 x += item->subCell() * newSubCellWidth;
1100 } 1087 }
1101 moveChild(item,x,y); 1088 moveChild(item,x,y);
1102 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y); 1089 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y);
1103 //item->updateItem(); 1090 //item->updateItem();
1104 } 1091 }
1105 // Adjust sub cell geometry of all conflict items of all conflict items 1092 // Adjust sub cell geometry of all conflict items of all conflict items
1106 for ( item=conflictItems.first(); item != 0; 1093 for ( item=conflictItems.first(); item != 0;
1107 item=conflictItems.next() ) { 1094 item=conflictItems.next() ) {
1108 if ( placeItem != item ) { 1095 if ( placeItem != item ) {
1109 KOAgendaItem *item2; 1096 KOAgendaItem *item2;
1110 QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems(); 1097 QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems();
1111 for ( item2=conflictItems2.first(); item2 != 0; 1098 for ( item2=conflictItems2.first(); item2 != 0;
1112 item2=conflictItems2.next() ) { 1099 item2=conflictItems2.next() ) {
1113 if ( item2->subCells() != maxSubCells) { 1100 if ( item2->subCells() != maxSubCells) {
1114 item2->setSubCells(maxSubCells); 1101 item2->setSubCells(maxSubCells);
1115 if (mAllDayMode) { 1102 if (mAllDayMode) {
1116 item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth); 1103 item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth);
1117 } else { 1104 } else {
1118 item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY); 1105 item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY);
1119 } 1106 }
1120 int x,y; 1107 int x,y;
1121 gridToContents(item2->cellX(),item2->cellYTop(),x,y); 1108 gridToContents(item2->cellX(),item2->cellYTop(),x,y);
1122 if (mAllDayMode) { 1109 if (mAllDayMode) {
1123 y += item2->subCell() * newSubCellWidth; 1110 y += item2->subCell() * newSubCellWidth;
1124 } else { 1111 } else {
1125 x += item2->subCell() * newSubCellWidth; 1112 x += item2->subCell() * newSubCellWidth;
1126 } 1113 }
1127 moveChild(item2,x,y); 1114 moveChild(item2,x,y);
1128 //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() ); 1115 //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() );
1129 } 1116 }
1130 } 1117 }
1131 } 1118 }
1132 } 1119 }
1133 } else { 1120 } else {
1134 placeItem->setSubCell(0); 1121 placeItem->setSubCell(0);
1135 placeItem->setSubCells(1); 1122 placeItem->setSubCells(1);
1136 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY); 1123 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY);
1137 else placeItem->resize(mGridSpacingX,placeItem->height()); 1124 else placeItem->resize(mGridSpacingX,placeItem->height());
1138 int x,y; 1125 int x,y;
1139 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y); 1126 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y);
1140 moveChild(placeItem,x,y); 1127 moveChild(placeItem,x,y);
1141 } 1128 }
1142 placeItem->setConflictItems(conflictItems); 1129 placeItem->setConflictItems(conflictItems);
1143 // for ( item=conflictItems.first(); item != 0; 1130 // for ( item=conflictItems.first(); item != 0;
1144// item=conflictItems.next() ) { 1131// item=conflictItems.next() ) {
1145// //item->updateItem(); 1132// //item->updateItem();
1146// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() ); 1133// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() );
1147// } 1134// }
1148// placeItem->updateItem(); 1135// placeItem->updateItem();
1149} 1136}
1150 1137
1151void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch) 1138void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
1152{ 1139{
1153 if ( globalFlagBlockAgenda ) 1140 if ( globalFlagBlockAgenda )
1154 return; 1141 return;
1155 //qDebug("KOAgenda::drawContents "); 1142 //qDebug("KOAgenda::drawContents ");
1156 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) 1143 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() )
1157 ;//drawContentsToPainter(); 1144 ;//drawContentsToPainter();
1158 1145
1159 QPaintDevice* pd = p->device(); 1146 QPaintDevice* pd = p->device();
1160 p->end(); 1147 p->end();
1161 int vx, vy; 1148 int vx, vy;
1162 int selectionX = KOGlobals::self()->reverseLayout() ? 1149 int selectionX = KOGlobals::self()->reverseLayout() ?
1163 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1150 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1164 mSelectionCellX * mGridSpacingX; 1151 mSelectionCellX * mGridSpacingX;
1165 contentsToViewport ( cx, cy, vx,vy); 1152 contentsToViewport ( cx, cy, vx,vy);
1166 // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ; 1153 // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ;
1167 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) 1154 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) )
1168 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); 1155 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP);
1169 1156
1170 if ( mSelectionHeight > 0 ) { 1157 if ( mSelectionHeight > 0 ) {
1171 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); 1158 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight );
1172 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1159 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1173 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1160 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1174 contentsToViewport ( selectionX, mSelectionYTop, vx,vy); 1161 contentsToViewport ( selectionX, mSelectionYTop, vx,vy);
1175 bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); 1162 bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP);
1176 } 1163 }
1177 } 1164 }
1178 //qDebug("btbl "); 1165 //qDebug("btbl ");
1179 p->begin( pd ); 1166 p->begin( pd );
1180 //qDebug("end "); 1167 //qDebug("end ");
1181} 1168}
1182 1169
1183void KOAgenda::finishUpdate() 1170void KOAgenda::finishUpdate()
1184{ 1171{
1185 1172
1186 KOAgendaItem *item; 1173 KOAgendaItem *item;
1187 globalFlagBlockAgendaItemPaint = 1; 1174 globalFlagBlockAgendaItemPaint = 1;
1188 // 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 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
1189 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1176 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1190 if ( !item->checkLayout() ) { 1177 if ( !item->checkLayout() ) {
1191 //qDebug(" conflictitem found "); 1178 //qDebug(" conflictitem found ");
1192 int newSubCellWidth; 1179 int newSubCellWidth;
1193 if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells(); 1180 if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells();
1194 else newSubCellWidth = mGridSpacingX / item->subCells(); 1181 else newSubCellWidth = mGridSpacingX / item->subCells();
1195 1182
1196 if (mAllDayMode) { 1183 if (mAllDayMode) {
1197 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); 1184 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth);
1198 } else { 1185 } else {
1199 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); 1186 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY);
1200 } 1187 }
1201 int x,y; 1188 int x,y;
1202 gridToContents(item->cellX(),item->cellYTop(),x,y); 1189 gridToContents(item->cellX(),item->cellYTop(),x,y);
1203 if (mAllDayMode) { 1190 if (mAllDayMode) {
1204 y += item->subCell() * newSubCellWidth; 1191 y += item->subCell() * newSubCellWidth;
1205 } else { 1192 } else {
1206 x += item->subCell() * newSubCellWidth; 1193 x += item->subCell() * newSubCellWidth;
1207 } 1194 }
1208 moveChild(item,x,y); 1195 moveChild(item,x,y);
1209 } 1196 }
1210 } 1197 }
1211 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1198 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1212 if ( !item->isVisible() ) 1199 if ( !item->isVisible() )
1213 item->show(); 1200 item->show();
1214 1201
1215 } 1202 }
1216 globalFlagBlockAgendaItemUpdate = 0; 1203 globalFlagBlockAgendaItemUpdate = 0;
1217 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1204 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1218 item->repaintMe( ); 1205 item->repaintMe( );
1219 } 1206 }
1220 globalFlagBlockAgendaItemUpdate = 1; 1207 globalFlagBlockAgendaItemUpdate = 1;
1221 qApp->processEvents(); 1208 qApp->processEvents();
1222 globalFlagBlockAgendaItemPaint = 0; 1209 globalFlagBlockAgendaItemPaint = 0;
1223 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1210 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1224 item->repaint( false ); 1211 item->repaint( false );
1225 } 1212 }
1226 1213
1227} 1214}
1228 1215
1229/* 1216/*
1230 Draw grid in the background of the agenda. 1217 Draw grid in the background of the agenda.
1231*/ 1218*/
1232void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch) 1219void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch)
1233{ 1220{
1234 1221
1235 1222
1236 if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask ) 1223 if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask )
1237 return; 1224 return;
1238 if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 ) 1225 if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 )
1239 return; 1226 return;
1240 int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight(); 1227 int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight();
1241 if ( ch < 1 ) 1228 if ( ch < 1 )
1242 ch = 1; 1229 ch = 1;
1243 if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) { 1230 if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) {
1244 mPaintPixmap.resize( contentsWidth()+42, ch ); 1231 mPaintPixmap.resize( contentsWidth()+42, ch );
1245 } 1232 }
1246 mCurPixWid = contentsWidth(); 1233 mCurPixWid = contentsWidth();
1247 mCurPixHei = ch; 1234 mCurPixHei = ch;
1248 if ( mHighlightPixmap.width() < mGridSpacingX-1 || mHighlightPixmap.height() < ch ) { 1235 if ( mHighlightPixmap.width() < mGridSpacingX-1 || mHighlightPixmap.height() < ch ) {
1249 mHighlightPixmap.resize( mGridSpacingX-1, ch ); 1236 mHighlightPixmap.resize( mGridSpacingX-1, ch );
1250 mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor ); 1237 mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor );
1251 } 1238 }
1252 mPixPainter.begin( &mPaintPixmap) ; 1239 mPixPainter.begin( &mPaintPixmap) ;
1253 //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() ); 1240 //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() );
1254 QPainter * p ; 1241 QPainter * p ;
1255 if (paint == 0) { 1242 if (paint == 0) {
1256 mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor); 1243 mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor);
1257 p = &mPixPainter; 1244 p = &mPixPainter;
1258 } 1245 }
1259 else 1246 else
1260 p = paint ; 1247 p = paint ;
1261 // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch); 1248 // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch);
1262 1249
1263 //--cx;++cw; 1250 //--cx;++cw;
1264 int lGridSpacingY = mGridSpacingY*2; 1251 int lGridSpacingY = mGridSpacingY*2;
1265 int selDay; 1252 int selDay;
1266 if ( !backgroundOnly ) 1253 if ( !backgroundOnly )
1267 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) 1254 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay)
1268 { 1255 {
1269 if ( mSelectedDates[selDay] == QDateTime::currentDateTime ().date() && KOPrefs::instance()->mHighlightCurrentDay) { 1256 if ( mSelectedDates[selDay] == QDateTime::currentDateTime ().date() && KOPrefs::instance()->mHighlightCurrentDay) {
1270 int x1 = cx; 1257 int x1 = cx;
1271 int y1 = 0; 1258 int y1 = 0;
1272 if (y1 < cy) y1 = cy; 1259 if (y1 < cy) y1 = cy;
1273 int x2 = cx+cw-1; 1260 int x2 = cx+cw-1;
1274 int y2 = contentsHeight(); 1261 int y2 = contentsHeight();
1275 if (y2 > cy+ch-1) y2=cy+ch-1; 1262 if (y2 > cy+ch-1) y2=cy+ch-1;
1276 if (x2 >= x1 && y2 >= y1) { 1263 if (x2 >= x1 && y2 >= y1) {
1277 int gxStart = selDay; 1264 int gxStart = selDay;
1278 int gxEnd = gxStart ; 1265 int gxEnd = gxStart ;
1279 int xStart = KOGlobals::self()->reverseLayout() ? 1266 int xStart = KOGlobals::self()->reverseLayout() ?
1280 (mColumns - 1 - gxStart)*mGridSpacingX : 1267 (mColumns - 1 - gxStart)*mGridSpacingX :
1281 gxStart*mGridSpacingX; 1268 gxStart*mGridSpacingX;
1282 if (xStart < x1) xStart = x1; 1269 if (xStart < x1) xStart = x1;
1283 int xEnd = KOGlobals::self()->reverseLayout() ? 1270 int xEnd = KOGlobals::self()->reverseLayout() ?
1284 (mColumns - gxStart)*mGridSpacingX-1 : 1271 (mColumns - gxStart)*mGridSpacingX-1 :
1285 (gxStart+1)*mGridSpacingX-1; 1272 (gxStart+1)*mGridSpacingX-1;
1286 if (xEnd > x2) xEnd = x2; 1273 if (xEnd > x2) xEnd = x2;
1287 if ( KOPrefs::instance()->mUseHighlightLightColor ) 1274 if ( KOPrefs::instance()->mUseHighlightLightColor )
1288 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1275 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1289 KOPrefs::instance()->mAgendaBgColor.light()); 1276 KOPrefs::instance()->mAgendaBgColor.light());
1290 else 1277 else
1291 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1278 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1292 KOPrefs::instance()->mAgendaBgColor.dark()); 1279 KOPrefs::instance()->mAgendaBgColor.dark());
1293 1280
1294 } 1281 }
1295 } 1282 }
1296 } 1283 }
1297 // Highlight working hours 1284 // Highlight working hours
1298 1285
1299 if ( !backgroundOnly ) 1286 if ( !backgroundOnly )
1300 if (mWorkingHoursEnable) { 1287 if (mWorkingHoursEnable) {
1301 int x1 = cx; 1288 int x1 = cx;
1302 int y1 = mWorkingHoursYTop; 1289 int y1 = mWorkingHoursYTop;
1303 if (y1 < cy) y1 = cy; 1290 if (y1 < cy) y1 = cy;
1304 int x2 = cx+cw-1; 1291 int x2 = cx+cw-1;
1305 // int x2 = mGridSpacingX * 5 - 1; 1292 // int x2 = mGridSpacingX * 5 - 1;
1306 // if (x2 > cx+cw-1) x2 = cx + cw - 1; 1293 // if (x2 > cx+cw-1) x2 = cx + cw - 1;
1307 int y2 = mWorkingHoursYBottom; 1294 int y2 = mWorkingHoursYBottom;
1308 if (y2 > cy+ch-1) y2=cy+ch-1; 1295 if (y2 > cy+ch-1) y2=cy+ch-1;
1309 1296
1310 if (x2 >= x1 && y2 >= y1) { 1297 if (x2 >= x1 && y2 >= y1) {
1311 // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX ); 1298 // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX );
1312 int gxStart = x1/mGridSpacingX; 1299 int gxStart = x1/mGridSpacingX;
1313 int gxEnd = x2/mGridSpacingX; 1300 int gxEnd = x2/mGridSpacingX;
1314 while(gxStart <= gxEnd) { 1301 while(gxStart <= gxEnd) {
1315 if (gxStart < int(mHolidayMask->count()) && 1302 if (gxStart < int(mHolidayMask->count()) &&
1316 !mHolidayMask->at(gxStart)) { 1303 !mHolidayMask->at(gxStart)) {
1317 int xStart = KOGlobals::self()->reverseLayout() ? 1304 int xStart = KOGlobals::self()->reverseLayout() ?
1318 (mColumns - 1 - gxStart)*mGridSpacingX : 1305 (mColumns - 1 - gxStart)*mGridSpacingX :
1319 gxStart*mGridSpacingX; 1306 gxStart*mGridSpacingX;
1320 if (xStart < x1) xStart = x1; 1307 if (xStart < x1) xStart = x1;
1321 int xEnd = KOGlobals::self()->reverseLayout() ? 1308 int xEnd = KOGlobals::self()->reverseLayout() ?
1322 (mColumns - gxStart)*mGridSpacingX-1 : 1309 (mColumns - gxStart)*mGridSpacingX-1 :
1323 (gxStart+1)*mGridSpacingX-1; 1310 (gxStart+1)*mGridSpacingX-1;
1324 if (xEnd > x2) xEnd = x2; 1311 if (xEnd > x2) xEnd = x2;
1325 if ( mSelectedDates[gxStart] == QDateTime::currentDateTime ().date()&& KOPrefs::instance()->mHighlightCurrentDay ) { 1312 if ( mSelectedDates[gxStart] == QDateTime::currentDateTime ().date()&& KOPrefs::instance()->mHighlightCurrentDay ) {
1326 if ( KOPrefs::instance()->mUseHighlightLightColor ) 1313 if ( KOPrefs::instance()->mUseHighlightLightColor )
1327 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1314 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1328 KOPrefs::instance()->mWorkingHoursColor.light()); 1315 KOPrefs::instance()->mWorkingHoursColor.light());
1329 else 1316 else
1330 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1317 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1331 KOPrefs::instance()->mWorkingHoursColor.dark()); 1318 KOPrefs::instance()->mWorkingHoursColor.dark());
1332 } else { 1319 } else {
1333 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1320 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1334 KOPrefs::instance()->mWorkingHoursColor); 1321 KOPrefs::instance()->mWorkingHoursColor);
1335 } 1322 }
1336 } 1323 }
1337 ++gxStart; 1324 ++gxStart;
1338 } 1325 }
1339 } 1326 }
1340 } 1327 }
1341 /* 1328 /*
1342 int selectionX = KOGlobals::self()->reverseLayout() ? 1329 int selectionX = KOGlobals::self()->reverseLayout() ?
1343 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1330 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1344 mSelectionCellX * mGridSpacingX; 1331 mSelectionCellX * mGridSpacingX;
1345 1332
1346 // Draw selection 1333 // Draw selection
1347 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1334 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1348 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1335 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1349 // TODO: paint only part within cx,cy,cw,ch 1336 // TODO: paint only part within cx,cy,cw,ch
1350 p->fillRect( selectionX, mSelectionYTop, mGridSpacingX, 1337 p->fillRect( selectionX, mSelectionYTop, mGridSpacingX,
1351 mSelectionHeight, KOPrefs::instance()->mHighlightColor ); 1338 mSelectionHeight, KOPrefs::instance()->mHighlightColor );
1352 } 1339 }
1353 */ 1340 */
1354 // Draw vertical lines of grid 1341 // Draw vertical lines of grid
1355 1342
1356 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX; 1343 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX;
1357 if ( mGridSpacingX > 0 ) { 1344 if ( mGridSpacingX > 0 ) {
1358 while (x < cx + cw) { 1345 while (x < cx + cw) {
1359 p->drawLine(x,cy,x,cy+ch); 1346 p->drawLine(x,cy,x,cy+ch);
1360 x+=mGridSpacingX; 1347 x+=mGridSpacingX;
1361 } 1348 }
1362 } 1349 }
1363 // Draw horizontal lines of grid 1350 // Draw horizontal lines of grid
1364 int y = ((int)(cy/lGridSpacingY))*lGridSpacingY; 1351 int y = ((int)(cy/lGridSpacingY))*lGridSpacingY;
1365 if ( lGridSpacingY > 0 ) { 1352 if ( lGridSpacingY > 0 ) {
1366 while (y < cy + ch) { 1353 while (y < cy + ch) {
1367 p->setPen( SolidLine ); 1354 p->setPen( SolidLine );
1368 p->drawLine(cx,y,cx+cw,y); 1355 p->drawLine(cx,y,cx+cw,y);
1369 y+=lGridSpacingY; 1356 y+=lGridSpacingY;
1370 p->setPen( DotLine ); 1357 p->setPen( DotLine );
1371 p->drawLine(cx,y,cx+cw,y); 1358 p->drawLine(cx,y,cx+cw,y);
1372 y+=lGridSpacingY; 1359 y+=lGridSpacingY;
1373 } 1360 }
1374 p->setPen( SolidLine ); 1361 p->setPen( SolidLine );
1375 } 1362 }
1376 mPixPainter.end() ; 1363 mPixPainter.end() ;
1377} 1364}
1378 1365
1379/* 1366/*
1380 Convert srcollview contents coordinates to agenda grid coordinates. 1367 Convert srcollview contents coordinates to agenda grid coordinates.
1381*/ 1368*/
1382void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy) 1369void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy)
1383{ 1370{
1384 gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX : 1371 gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX :
1385 x/mGridSpacingX; 1372 x/mGridSpacingX;
1386 gy = y/mGridSpacingY; 1373 gy = y/mGridSpacingY;
1387} 1374}
1388 1375
1389/* 1376/*
1390 Convert agenda grid coordinates to scrollview contents coordinates. 1377 Convert agenda grid coordinates to scrollview contents coordinates.
1391*/ 1378*/
1392void KOAgenda::gridToContents (int gx, int gy, int& x, int& y) 1379void KOAgenda::gridToContents (int gx, int gy, int& x, int& y)
1393{ 1380{
1394 x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX: 1381 x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX:
1395 gx*mGridSpacingX; 1382 gx*mGridSpacingX;
1396 y = gy*mGridSpacingY; 1383 y = gy*mGridSpacingY;
1397} 1384}
1398 1385
1399 1386
1400/* 1387/*
1401 Return Y coordinate corresponding to time. Coordinates are rounded to fit into 1388 Return Y coordinate corresponding to time. Coordinates are rounded to fit into
1402 the grid. 1389 the grid.
1403*/ 1390*/
1404int KOAgenda::timeToY(const QTime &time) 1391int KOAgenda::timeToY(const QTime &time)
1405{ 1392{
1406 int minutesPerCell = 24 * 60 / mRows; 1393 int minutesPerCell = 24 * 60 / mRows;
1407 int timeMinutes = time.hour() * 60 + time.minute(); 1394 int timeMinutes = time.hour() * 60 + time.minute();
1408 int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell; 1395 int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell;
1409 return Y; 1396 return Y;
1410} 1397}
1411 1398
1412 1399
1413/* 1400/*
1414 Return time corresponding to cell y coordinate. Coordinates are rounded to 1401 Return time corresponding to cell y coordinate. Coordinates are rounded to
1415 fit into the grid. 1402 fit into the grid.
1416*/ 1403*/
1417QTime KOAgenda::gyToTime(int gy) 1404QTime KOAgenda::gyToTime(int gy)
1418{ 1405{
1419 1406
1420 int secondsPerCell = 24 * 60 * 60/ mRows; 1407 int secondsPerCell = 24 * 60 * 60/ mRows;
1421 1408
1422 int timeSeconds = secondsPerCell * gy; 1409 int timeSeconds = secondsPerCell * gy;
1423 1410
1424 QTime time( 0, 0, 0 ); 1411 QTime time( 0, 0, 0 );
1425 if ( timeSeconds < 24 * 60 * 60 ) { 1412 if ( timeSeconds < 24 * 60 * 60 ) {
1426 time = time.addSecs(timeSeconds); 1413 time = time.addSecs(timeSeconds);
1427 } else { 1414 } else {
1428 time.setHMS( 23, 59, 59 ); 1415 time.setHMS( 23, 59, 59 );
1429 } 1416 }
1430 1417
1431 return time; 1418 return time;
1432} 1419}
1433 1420
1434void KOAgenda::setStartHour(int startHour) 1421void KOAgenda::setStartHour(int startHour)
1435{ 1422{
1436 int startCell = startHour * mRows / 24; 1423 int startCell = startHour * mRows / 24;
1437 setContentsPos(0,startCell * gridSpacingY()); 1424 setContentsPos(0,startCell * gridSpacingY());
1438} 1425}
1439void KOAgenda::hideUnused() 1426void KOAgenda::hideUnused()
1440{ 1427{
1441 // experimental only 1428 // experimental only
1442 // return; 1429 // return;
1443 KOAgendaItem *item; 1430 KOAgendaItem *item;
1444 for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) { 1431 for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) {
1445 item->hide(); 1432 item->hide();
1446 } 1433 }
1447} 1434}
1448 1435
1449 1436
1450KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view) 1437KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view)
1451{ 1438{
1452 1439
1453 KOAgendaItem *fi; 1440 KOAgendaItem *fi;
1454 for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) { 1441 for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) {
1455 if ( fi->incidence() == event ) { 1442 if ( fi->incidence() == event ) {
1456 mUnusedItems.remove(); 1443 mUnusedItems.remove();
1457 fi->init( event, qd ); 1444 fi->init( event, qd );
1458 return fi; 1445 return fi;
1459 } 1446 }
1460 } 1447 }
1461 fi=mUnusedItems.first(); 1448 fi=mUnusedItems.first();
1462 if ( fi ) { 1449 if ( fi ) {
1463 mUnusedItems.remove(); 1450 mUnusedItems.remove();
1464 fi->init( event, qd ); 1451 fi->init( event, qd );
1465 return fi; 1452 return fi;
1466 } 1453 }
1467 // qDebug("new KOAgendaItem "); 1454 // qDebug("new KOAgendaItem ");
1468 1455
1469 KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode ); 1456 KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode );
1470 agendaItem->installEventFilter(this); 1457 agendaItem->installEventFilter(this);
1471 addChild(agendaItem,0,0); 1458 addChild(agendaItem,0,0);
1472 return agendaItem; 1459 return agendaItem;
1473} 1460}
1474KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo ) 1461KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo )
1475{ 1462{
1476 KOAgendaItem *item; 1463 KOAgendaItem *item;
1477 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1464 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1478 if ( item->incidence() == todo ) { 1465 if ( item->incidence() == todo ) {
1479 mItems.remove(); 1466 mItems.remove();
1480 return item; 1467 return item;
1481 } 1468 }
1482 } 1469 }
1483 return 0; 1470 return 0;
1484} 1471}
1485 1472
1486 1473
1487void KOAgenda::updateTodo( Todo * todo, int days, bool remove) 1474void KOAgenda::updateTodo( Todo * todo, int days, bool remove)
1488{ 1475{
1489 // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )|| 1476 // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )||
1490 KOAgendaItem *item; 1477 KOAgendaItem *item;
1491 item = getItemForTodo ( todo ); 1478 item = getItemForTodo ( todo );
1492 //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove); 1479 //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove);
1493 if ( item ) { 1480 if ( item ) {
1494 blockSignals( true ); 1481 blockSignals( true );
1495 //qDebug("item found "); 1482 //qDebug("item found ");
1496 item->hide(); 1483 item->hide();
1497 item->setCellX(-2, -1 ); 1484 item->setCellX(-2, -1 );
1498 item->select(false); 1485 item->select(false);
1499 mUnusedItems.append( item ); 1486 mUnusedItems.append( item );
1500 mItems.remove( item ); 1487 mItems.remove( item );
1501 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); 1488 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems();
1502 KOAgendaItem *itemit; 1489 KOAgendaItem *itemit;
1503 //globalFlagBlockAgendaItemPaint = 1; 1490 //globalFlagBlockAgendaItemPaint = 1;
1504 for ( itemit=oldconflictItems.first(); itemit != 0; 1491 for ( itemit=oldconflictItems.first(); itemit != 0;
1505 itemit=oldconflictItems.next() ) { 1492 itemit=oldconflictItems.next() ) {
1506 if ( itemit != item ) 1493 if ( itemit != item )
1507 placeSubCells(itemit); 1494 placeSubCells(itemit);
1508 } 1495 }
1509 qApp->processEvents(); 1496 qApp->processEvents();
1510 //globalFlagBlockAgendaItemPaint = 0; 1497 //globalFlagBlockAgendaItemPaint = 0;
1511 for ( itemit=oldconflictItems.first(); itemit != 0; 1498 for ( itemit=oldconflictItems.first(); itemit != 0;
1512 itemit=oldconflictItems.next() ) { 1499 itemit=oldconflictItems.next() ) {
1513 globalFlagBlockAgendaItemUpdate = 0; 1500 globalFlagBlockAgendaItemUpdate = 0;
1514 if ( itemit != item ) 1501 if ( itemit != item )
1515 itemit->repaintMe(); 1502 itemit->repaintMe();
1516 globalFlagBlockAgendaItemUpdate = 1; 1503 globalFlagBlockAgendaItemUpdate = 1;
1517 itemit->repaint(); 1504 itemit->repaint();
1518 } 1505 }
1519 blockSignals( false ); 1506 blockSignals( false );
1520 } 1507 }
1521 if ( remove ) { 1508 if ( remove ) {
1522 //qDebug("remove****************************************** "); 1509 //qDebug("remove****************************************** ");
1523 return; 1510 return;
1524 } 1511 }
1525 //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ "); 1512 //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ ");
1526 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < QDate::currentDate())&& ( KOPrefs::instance()->mShowTodoInAgenda ); 1513 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < QDate::currentDate())&& ( KOPrefs::instance()->mShowTodoInAgenda );
1527 QDate currentDate; 1514 QDate currentDate;
1528 QDateTime dt; 1515 QDateTime dt;
1529 if ( todo->hasCompletedDate() ) 1516 if ( todo->hasCompletedDate() )
1530 dt = todo->completed(); 1517 dt = todo->completed();
1531 else 1518 else
1532 dt = todo->dtDue(); 1519 dt = todo->dtDue();
1533 if ( overdue ) { 1520 if ( overdue ) {
1534 currentDate = QDate::currentDate(); 1521 currentDate = QDate::currentDate();
1535 days += todo->dtDue().date().daysTo( currentDate ); 1522 days += todo->dtDue().date().daysTo( currentDate );
1536 } 1523 }
1537 else 1524 else
1538 currentDate = dt.date(); 1525 currentDate = dt.date();
1539 1526
1540 if (( todo->doesFloat() || overdue) && !todo->hasCompletedDate() ) { 1527 if (( todo->doesFloat() || overdue) && !todo->hasCompletedDate() ) {
1541 if ( ! mAllDayMode ) return; 1528 if ( ! mAllDayMode ) return;
1542 // aldayagenda 1529 // aldayagenda
1543 globalFlagBlockAgendaItemPaint = 1; 1530 globalFlagBlockAgendaItemPaint = 1;
1544 item = insertAllDayItem(todo, currentDate,days, days); 1531 item = insertAllDayItem(todo, currentDate,days, days);
1545 item->show(); 1532 item->show();
1546 1533
1547 } 1534 }
1548 else { 1535 else {
1549 if ( mAllDayMode ) return; 1536 if ( mAllDayMode ) return;
1550 // mAgenda 1537 // mAgenda
1551 globalFlagBlockAgendaItemPaint = 1; 1538 globalFlagBlockAgendaItemPaint = 1;
1552 int endY = timeToY(dt.time()) - 1; 1539 int endY = timeToY(dt.time()) - 1;
1553 int hi = 12/KOPrefs::instance()->mHourSize; 1540 int hi = 12/KOPrefs::instance()->mHourSize;
1554 int startY = endY - 1-hi; 1541 int startY = endY - 1-hi;
1555 item = insertItem(todo,currentDate,days,startY,endY); 1542 item = insertItem(todo,currentDate,days,startY,endY);
1556 item->show(); 1543 item->show();
1557 } 1544 }
1558 qApp->processEvents(); 1545 qApp->processEvents();
1559 globalFlagBlockAgendaItemPaint = 0; 1546 globalFlagBlockAgendaItemPaint = 0;
1560 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); 1547 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems();
1561 KOAgendaItem *itemit; 1548 KOAgendaItem *itemit;
1562 for ( itemit=oldconflictItems.first(); itemit != 0; 1549 for ( itemit=oldconflictItems.first(); itemit != 0;
1563 itemit=oldconflictItems.next() ) { 1550 itemit=oldconflictItems.next() ) {
1564 globalFlagBlockAgendaItemUpdate = 0; 1551 globalFlagBlockAgendaItemUpdate = 0;
1565 itemit->repaintMe(); 1552 itemit->repaintMe();
1566 globalFlagBlockAgendaItemUpdate = 1; 1553 globalFlagBlockAgendaItemUpdate = 1;
1567 itemit->repaint(); 1554 itemit->repaint();
1568 } 1555 }
1569 globalFlagBlockAgendaItemUpdate = 0; 1556 globalFlagBlockAgendaItemUpdate = 0;
1570 item->repaintMe(); 1557 item->repaintMe();
1571 globalFlagBlockAgendaItemUpdate = 1; 1558 globalFlagBlockAgendaItemUpdate = 1;
1572 item->repaint(); 1559 item->repaint();
1573} 1560}
1574/* 1561/*
1575 Insert KOAgendaItem into agenda. 1562 Insert KOAgendaItem into agenda.
1576*/ 1563*/
1577KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom) 1564KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom)
1578{ 1565{
1579 //kdDebug() << "KOAgenda::insertItem:" << event->summary() << "-" << qd.toString() << " ;top, bottom:" << YTop << "," << YBottom << endl; 1566 //kdDebug() << "KOAgenda::insertItem:" << event->summary() << "-" << qd.toString() << " ;top, bottom:" << YTop << "," << YBottom << endl;
1580 1567
1581 if (mAllDayMode) { 1568 if (mAllDayMode) {
1582 kdDebug() << "KOAgenda: calling insertItem in all-day mode is illegal." << endl; 1569 kdDebug() << "KOAgenda: calling insertItem in all-day mode is illegal." << endl;
1583 return 0; 1570 return 0;
1584 } 1571 }
1585 1572
1586 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); 1573 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport());
1587 //agendaItem->setFrameStyle(WinPanel|Raised); 1574 //agendaItem->setFrameStyle(WinPanel|Raised);
1588 1575
1589 int YSize = YBottom - YTop + 1; 1576 int YSize = YBottom - YTop + 1;
1590 if (YSize < 0) { 1577 if (YSize < 0) {
1591 kdDebug() << "KOAgenda::insertItem(): Text: " << agendaItem->text() << " YSize<0" << endl; 1578 kdDebug() << "KOAgenda::insertItem(): Text: " << agendaItem->text() << " YSize<0" << endl;
1592 YSize = 1; 1579 YSize = 1;
1593 } 1580 }
1594 int iheight = mGridSpacingY * YSize; 1581 int iheight = mGridSpacingY * YSize;
1595 1582
1596 agendaItem->resize(mGridSpacingX,iheight ); 1583 agendaItem->resize(mGridSpacingX,iheight );
1597 agendaItem->setCellXY(X,YTop,YBottom); 1584 agendaItem->setCellXY(X,YTop,YBottom);
1598 agendaItem->setCellXWidth(X); 1585 agendaItem->setCellXWidth(X);
1599 1586
1600 //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY); 1587 //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY);
1601 mItems.append(agendaItem); 1588 mItems.append(agendaItem);
1602 1589
1603 placeSubCells(agendaItem); 1590 placeSubCells(agendaItem);
1604 1591
1605 //agendaItem->show(); 1592 //agendaItem->show();
1606 1593
1607 marcus_bains(); 1594 marcus_bains();
1608 1595
1609 return agendaItem; 1596 return agendaItem;
1610} 1597}
1611 1598
1612 1599
1613/* 1600/*
1614 Insert all-day KOAgendaItem into agenda. 1601 Insert all-day KOAgendaItem into agenda.
1615*/ 1602*/
1616KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd) 1603KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd)
1617{ 1604{
1618 if (!mAllDayMode) { 1605 if (!mAllDayMode) {
1619 return 0; 1606 return 0;
1620 } 1607 }
1621 1608
1622 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); 1609 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport());
1623 1610
1624 agendaItem->setCellXY(XBegin,0,0); 1611 agendaItem->setCellXY(XBegin,0,0);
1625 agendaItem->setCellXWidth(XEnd); 1612 agendaItem->setCellXWidth(XEnd);
1626 agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY); 1613 agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY);
1627 1614
1628 //addChild(agendaItem,XBegin*mGridSpacingX,0); 1615 //addChild(agendaItem,XBegin*mGridSpacingX,0);
1629 mItems.append(agendaItem); 1616 mItems.append(agendaItem);
1630 1617
1631 placeSubCells(agendaItem); 1618 placeSubCells(agendaItem);
1632 1619
1633 //agendaItem->show(); 1620 //agendaItem->show();
1634 1621
1635 return agendaItem; 1622 return agendaItem;
1636} 1623}
1637 1624
1638 1625
1639void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, 1626void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd,
1640 int YTop,int YBottom) 1627 int YTop,int YBottom)
1641{ 1628{
1642 if (mAllDayMode) { 1629 if (mAllDayMode) {
1643 ; 1630 ;
1644 return; 1631 return;
1645 } 1632 }
1646 1633
1647 int cellX,cellYTop,cellYBottom; 1634 int cellX,cellYTop,cellYBottom;
1648 QString newtext; 1635 QString newtext;
1649 int width = XEnd - XBegin + 1; 1636 int width = XEnd - XBegin + 1;
1650 int count = 0; 1637 int count = 0;
1651 KOAgendaItem *current = 0; 1638 KOAgendaItem *current = 0;
1652 QPtrList<KOAgendaItem> multiItems; 1639 QPtrList<KOAgendaItem> multiItems;
1653 for (cellX = XBegin;cellX <= XEnd;++cellX) { 1640 for (cellX = XBegin;cellX <= XEnd;++cellX) {
1654 if (cellX == XBegin) cellYTop = YTop; 1641 if (cellX == XBegin) cellYTop = YTop;
1655 else cellYTop = 0; 1642 else cellYTop = 0;
1656 if (cellX == XEnd) cellYBottom = YBottom; 1643 if (cellX == XEnd) cellYBottom = YBottom;
1657 else cellYBottom = rows() - 1; 1644 else cellYBottom = rows() - 1;
1658 newtext = QString("(%1/%2): ").arg(++count).arg(width); 1645 newtext = QString("(%1/%2): ").arg(++count).arg(width);
1659 newtext.append(event->summary()); 1646 newtext.append(event->summary());
1660 current = insertItem(event,qd,cellX,cellYTop,cellYBottom); 1647 current = insertItem(event,qd,cellX,cellYTop,cellYBottom);
1661 current->setText(newtext); 1648 current->setText(newtext);
1662 multiItems.append(current); 1649 multiItems.append(current);
1663 } 1650 }
1664 1651
1665 KOAgendaItem *next = 0; 1652 KOAgendaItem *next = 0;
1666 KOAgendaItem *last = multiItems.last(); 1653 KOAgendaItem *last = multiItems.last();
1667 KOAgendaItem *first = multiItems.first(); 1654 KOAgendaItem *first = multiItems.first();
1668 KOAgendaItem *setFirst,*setLast; 1655 KOAgendaItem *setFirst,*setLast;
1669 current = first; 1656 current = first;
1670 while (current) { 1657 while (current) {
1671 next = multiItems.next(); 1658 next = multiItems.next();
1672 if (current == first) setFirst = 0; 1659 if (current == first) setFirst = 0;
1673 else setFirst = first; 1660 else setFirst = first;
1674 if (current == last) setLast = 0; 1661 if (current == last) setLast = 0;
1675 else setLast = last; 1662 else setLast = last;
1676 1663
1677 current->setMultiItem(setFirst,next,setLast); 1664 current->setMultiItem(setFirst,next,setLast);
1678 current = next; 1665 current = next;
1679 } 1666 }
1680 1667
1681 marcus_bains(); 1668 marcus_bains();
1682} 1669}
1683 1670
1684 1671
1685//QSizePolicy KOAgenda::sizePolicy() const 1672//QSizePolicy KOAgenda::sizePolicy() const
1686//{ 1673//{
1687 // Thought this would make the all-day event agenda minimum size and the 1674 // Thought this would make the all-day event agenda minimum size and the
1688 // normal agenda take the remaining space. But it doesn´t work. The QSplitter 1675 // normal agenda take the remaining space. But it doesn´t work. The QSplitter
1689 // don´t seem to think that an Expanding widget needs more space than a 1676 // don´t seem to think that an Expanding widget needs more space than a
1690 // Preferred one. 1677 // Preferred one.
1691 // But it doesn´t hurt, so it stays. 1678 // But it doesn´t hurt, so it stays.
1692// if (mAllDayMode) { 1679// if (mAllDayMode) {
1693// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); 1680// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
1694// } else { 1681// } else {
1695// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); 1682// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
1696// } 1683// }
1697//} 1684//}
1698void KOAgenda::finishResize ( ) 1685void KOAgenda::finishResize ( )
1699{ 1686{
1700 //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) "); 1687 //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) ");
1701 if ( globalFlagBlockAgenda == 0 ) { 1688 if ( globalFlagBlockAgenda == 0 ) {
1702 finishUpdate(); 1689 finishUpdate();
1703 //qDebug("finishUpdate() called "); 1690 //qDebug("finishUpdate() called ");
1704 } 1691 }
1705} 1692}
1706/* 1693/*
1707 Overridden from QScrollView to provide proper resizing of KOAgendaItems. 1694 Overridden from QScrollView to provide proper resizing of KOAgendaItems.
1708*/ 1695*/
1709void KOAgenda::resizeEvent ( QResizeEvent *ev ) 1696void KOAgenda::resizeEvent ( QResizeEvent *ev )
1710{ 1697{
1711 1698
1712 mResizeTimer.start( 150 , true ); 1699 mResizeTimer.start( 150 , true );
1713 computeSizes(); 1700 computeSizes();
1714 return; 1701 return;
1715 1702
1716} 1703}
1717void KOAgenda::computeSizes() 1704void KOAgenda::computeSizes()
1718{ 1705{
1719 if ( globalFlagBlockStartup ) 1706 if ( globalFlagBlockStartup )
1720 return; 1707 return;
1721 1708
1722 if (mAllDayMode) { 1709 if (mAllDayMode) {
1723 mGridSpacingX = (width()-3) / mColumns; 1710 mGridSpacingX = (width()-3) / mColumns;
1724 mGridSpacingY = height() - 2 * frameWidth() - 1; 1711 mGridSpacingY = height() - 2 * frameWidth() - 1;
1725 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1); 1712 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1);
1726// mGridSpacingY = height(); 1713// mGridSpacingY = height();
1727// resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1714// resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1728 1715
1729 KOAgendaItem *item; 1716 KOAgendaItem *item;
1730 int subCellWidth; 1717 int subCellWidth;
1731 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1718 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1732 subCellWidth = mGridSpacingY / item->subCells(); 1719 subCellWidth = mGridSpacingY / item->subCells();
1733 item->resize(mGridSpacingX * item->cellWidth(),subCellWidth); 1720 item->resize(mGridSpacingX * item->cellWidth(),subCellWidth);
1734 moveChild(item,KOGlobals::self()->reverseLayout() ? 1721 moveChild(item,KOGlobals::self()->reverseLayout() ?
1735 (mColumns - 1 - item->cellX()) * mGridSpacingX : 1722 (mColumns - 1 - item->cellX()) * mGridSpacingX :
1736 item->cellX() * mGridSpacingX, 1723 item->cellX() * mGridSpacingX,
1737 item->subCell() * subCellWidth); 1724 item->subCell() * subCellWidth);
1738 } 1725 }
1739 KOPrefs::instance()->mAllDaySize = mGridSpacingY; 1726 KOPrefs::instance()->mAllDaySize = mGridSpacingY;
1740 } else { 1727 } else {
1741 mGridSpacingX = (width() - verticalScrollBar()->width()-3)/mColumns; 1728 mGridSpacingX = (width() - verticalScrollBar()->width()-3)/mColumns;
1742 if (height() > mGridSpacingY * mRows + 1 ) { 1729 if (height() > mGridSpacingY * mRows + 1 ) {
1743 KOPrefs::instance()->mHourSize = ((height())/mRows)+1; 1730 KOPrefs::instance()->mHourSize = ((height())/mRows)+1;
1744 mGridSpacingY = KOPrefs::instance()->mHourSize ; 1731 mGridSpacingY = KOPrefs::instance()->mHourSize ;
1745 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1732 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1746 emit resizedSignal(); 1733 emit resizedSignal();
1747 } else 1734 } else
1748 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1735 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1749 KOAgendaItem *item; 1736 KOAgendaItem *item;
1750 int subCellWidth; 1737 int subCellWidth;
1751 1738
1752 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1739 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1753 subCellWidth = mGridSpacingX / item->subCells(); 1740 subCellWidth = mGridSpacingX / item->subCells();
1754 item->resize(subCellWidth,item->height()); 1741 item->resize(subCellWidth,item->height());
1755 moveChild(item,(KOGlobals::self()->reverseLayout() ? 1742 moveChild(item,(KOGlobals::self()->reverseLayout() ?
1756 (mColumns - 1 - item->cellX()) * mGridSpacingX : 1743 (mColumns - 1 - item->cellX()) * mGridSpacingX :
1757 item->cellX() * mGridSpacingX) + 1744 item->cellX() * mGridSpacingX) +
1758 item->subCell() * subCellWidth,childY(item)); 1745 item->subCell() * subCellWidth,childY(item));
1759 } 1746 }
1760 } 1747 }
1761 int cw = contentsWidth(); 1748 int cw = contentsWidth();
1762 int ch = contentsHeight(); 1749 int ch = contentsHeight();
1763 if ( mAllDayMode ) { 1750 if ( mAllDayMode ) {
1764 QPixmap* paintPixAll = KOAgendaItem::paintPixAllday(); 1751 QPixmap* paintPixAll = KOAgendaItem::paintPixAllday();
1765 if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 ) 1752 if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 )
1766 paintPixAll->resize( cw, ch ); 1753 paintPixAll->resize( cw, ch );
1767 } else { 1754 } else {
1768 QPixmap* paintPix = KOAgendaItem::paintPix(); 1755 QPixmap* paintPix = KOAgendaItem::paintPix();
1769 if ( paintPix->width() < cw || paintPix->height() < ch ) 1756 if ( paintPix->width() < cw || paintPix->height() < ch )
1770 KOAgendaItem::resizePixmap( cw , ch ); 1757 KOAgendaItem::resizePixmap( cw , ch );
1771 } 1758 }
1772 1759
1773 checkScrollBoundaries(); 1760 checkScrollBoundaries();
1774 marcus_bains(); 1761 marcus_bains();
1775 drawContentsToPainter(); 1762 drawContentsToPainter();
1776 viewport()->repaint(false); 1763 viewport()->repaint(false);
1777} 1764}
1778 1765
1779void KOAgenda::scrollUp() 1766void KOAgenda::scrollUp()
1780{ 1767{
1781 scrollBy(0,-mScrollOffset); 1768 scrollBy(0,-mScrollOffset);
1782} 1769}
1783 1770
1784 1771
1785void KOAgenda::scrollDown() 1772void KOAgenda::scrollDown()
1786{ 1773{
1787 scrollBy(0,mScrollOffset); 1774 scrollBy(0,mScrollOffset);
1788} 1775}
1789 1776
1790void KOAgenda::popupAlarm() 1777void KOAgenda::popupAlarm()
1791{ 1778{
1792 if (!mClickedItem) { 1779 if (!mClickedItem) {
1793 qDebug("KOAgenda::popupAlarm() called without having a clicked item "); 1780 qDebug("KOAgenda::popupAlarm() called without having a clicked item ");
1794 return; 1781 return;
1795 } 1782 }
1796// TODO: deal correctly with multiple alarms 1783// TODO: deal correctly with multiple alarms
1797 Alarm* alarm; 1784 Alarm* alarm;
1798 QPtrList<Alarm> list(mClickedItem->incidence()->alarms()); 1785 QPtrList<Alarm> list(mClickedItem->incidence()->alarms());
1799 for(alarm=list.first();alarm;alarm=list.next()) { 1786 for(alarm=list.first();alarm;alarm=list.next()) {
1800 alarm->toggleAlarm(); 1787 alarm->toggleAlarm();
1801 } 1788 }
1802 emit itemModified( mClickedItem , KOGlobals::EVENTEDITED ); 1789 emit itemModified( mClickedItem , KOGlobals::EVENTEDITED );
1803 mClickedItem->paintMe( true ); 1790 mClickedItem->paintMe( true );
1804 mClickedItem->repaint( false ); 1791 mClickedItem->repaint( false );
1805} 1792}
1806 1793
1807/* 1794/*
1808 Calculates the minimum width 1795 Calculates the minimum width
1809*/ 1796*/
1810int KOAgenda::minimumWidth() const 1797int KOAgenda::minimumWidth() const
1811{ 1798{
1812 // TODO:: develop a way to dynamically determine the minimum width 1799 // TODO:: develop a way to dynamically determine the minimum width
1813 int min = 100; 1800 int min = 100;
1814 1801
1815 return min; 1802 return min;
1816} 1803}
1817 1804
1818void KOAgenda::updateConfig() 1805void KOAgenda::updateConfig()
1819{ 1806{
1820 if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor) 1807 if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor)
1821 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor); 1808 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor);
1822 if ( mAllDayMode ) { 1809 if ( mAllDayMode ) {
1823 mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize; 1810 mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize;
1824 //mGridSpacingY = KOPrefs::instance()->mAllDaySize; 1811 //mGridSpacingY = KOPrefs::instance()->mAllDaySize;
1825 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 ); 1812 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 );
1826 // setMaximumHeight( mGridSpacingY+1 ); 1813 // setMaximumHeight( mGridSpacingY+1 );
1827 viewport()->repaint( false ); 1814 viewport()->repaint( false );
1828 //setFixedHeight( mGridSpacingY+1 ); 1815 //setFixedHeight( mGridSpacingY+1 );
1829 //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize); 1816 //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize);
1830 } 1817 }
1831 else { 1818 else {
1832 mGridSpacingY = KOPrefs::instance()->mHourSize; 1819 mGridSpacingY = KOPrefs::instance()->mHourSize;
1833 calculateWorkingHours(); 1820 calculateWorkingHours();
1834 marcus_bains(); 1821 marcus_bains();
1835 } 1822 }
1836} 1823}
1837 1824
1838void KOAgenda::checkScrollBoundaries() 1825void KOAgenda::checkScrollBoundaries()
1839{ 1826{
1840 // Invalidate old values to force update 1827 // Invalidate old values to force update
1841 mOldLowerScrollValue = -1; 1828 mOldLowerScrollValue = -1;
1842 mOldUpperScrollValue = -1; 1829 mOldUpperScrollValue = -1;
1843 1830
1844 checkScrollBoundaries(verticalScrollBar()->value()); 1831 checkScrollBoundaries(verticalScrollBar()->value());
1845} 1832}
1846 1833
1847void KOAgenda::checkScrollBoundaries(int v) 1834void KOAgenda::checkScrollBoundaries(int v)
1848{ 1835{
1849 if ( mGridSpacingY == 0 ) 1836 if ( mGridSpacingY == 0 )
1850 return; 1837 return;
1851 int yMin = v/mGridSpacingY; 1838 int yMin = v/mGridSpacingY;
1852 int yMax = (v+visibleHeight())/mGridSpacingY; 1839 int yMax = (v+visibleHeight())/mGridSpacingY;
1853 1840
1854// kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl; 1841// kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl;
1855 1842
1856 if (yMin != mOldLowerScrollValue) { 1843 if (yMin != mOldLowerScrollValue) {
1857 mOldLowerScrollValue = yMin; 1844 mOldLowerScrollValue = yMin;
1858 emit lowerYChanged(yMin); 1845 emit lowerYChanged(yMin);
1859 } 1846 }
1860 if (yMax != mOldUpperScrollValue) { 1847 if (yMax != mOldUpperScrollValue) {
1861 mOldUpperScrollValue = yMax; 1848 mOldUpperScrollValue = yMax;
1862 emit upperYChanged(yMax); 1849 emit upperYChanged(yMax);
1863 } 1850 }
1864} 1851}
1865 1852
1866void KOAgenda::deselectItem() 1853void KOAgenda::deselectItem()
1867{ 1854{
1868 if (mSelectedItem.isNull()) return; 1855 if (mSelectedItem.isNull()) return;
1869 mSelectedItem->select(false); 1856 mSelectedItem->select(false);
1870 mSelectedItem = 0; 1857 mSelectedItem = 0;
1871} 1858}
1872 1859
1873void KOAgenda::selectItem(KOAgendaItem *item) 1860void KOAgenda::selectItem(KOAgendaItem *item)
1874{ 1861{
1875 if ((KOAgendaItem *)mSelectedItem == item) return; 1862 if ((KOAgendaItem *)mSelectedItem == item) return;
1876 deselectItem(); 1863 deselectItem();
1877 if (item == 0) { 1864 if (item == 0) {
1878 emit incidenceSelected( 0 ); 1865 emit incidenceSelected( 0 );
1879 return; 1866 return;
1880 } 1867 }
1881 mSelectedItem = item; 1868 mSelectedItem = item;
1882 mSelectedItem->select(); 1869 mSelectedItem->select();
1883 emit incidenceSelected( mSelectedItem->incidence() ); 1870 emit incidenceSelected( mSelectedItem->incidence() );
1884} 1871}
1885 1872
1886// This function seems never be called. 1873// This function seems never be called.
1887void KOAgenda::keyPressEvent( QKeyEvent *kev ) 1874void KOAgenda::keyPressEvent( QKeyEvent *kev )
1888{ 1875{
1889 switch(kev->key()) { 1876 switch(kev->key()) {
1890 case Key_PageDown: 1877 case Key_PageDown:
1891 verticalScrollBar()->addPage(); 1878 verticalScrollBar()->addPage();
1892 break; 1879 break;
1893 case Key_PageUp: 1880 case Key_PageUp:
1894 verticalScrollBar()->subtractPage(); 1881 verticalScrollBar()->subtractPage();
1895 break; 1882 break;
1896 case Key_Down: 1883 case Key_Down:
1897 verticalScrollBar()->addLine(); 1884 verticalScrollBar()->addLine();
1898 break; 1885 break;
1899 case Key_Up: 1886 case Key_Up:
1900 verticalScrollBar()->subtractLine(); 1887 verticalScrollBar()->subtractLine();
1901 break; 1888 break;
1902 default: 1889 default:
1903 ; 1890 ;
1904 } 1891 }
1905} 1892}
1906 1893
1907void KOAgenda::calculateWorkingHours() 1894void KOAgenda::calculateWorkingHours()
1908{ 1895{
1909// mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours; 1896// mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours;
1910 mWorkingHoursEnable = !mAllDayMode; 1897 mWorkingHoursEnable = !mAllDayMode;
1911 1898
1912 mWorkingHoursYTop = mGridSpacingY * 1899 mWorkingHoursYTop = mGridSpacingY *
1913 KOPrefs::instance()->mWorkingHoursStart * 4; 1900 KOPrefs::instance()->mWorkingHoursStart * 4;
1914 mWorkingHoursYBottom = mGridSpacingY * 1901 mWorkingHoursYBottom = mGridSpacingY *
1915 KOPrefs::instance()->mWorkingHoursEnd * 4 - 1; 1902 KOPrefs::instance()->mWorkingHoursEnd * 4 - 1;
1916} 1903}
1917 1904
1918 1905
1919DateList KOAgenda::dateList() const 1906DateList KOAgenda::dateList() const
1920{ 1907{
1921 return mSelectedDates; 1908 return mSelectedDates;
1922} 1909}
1923 1910
1924void KOAgenda::setDateList(const DateList &selectedDates) 1911void KOAgenda::setDateList(const DateList &selectedDates)
1925{ 1912{
1926 mSelectedDates = selectedDates; 1913 mSelectedDates = selectedDates;
1927 marcus_bains(); 1914 marcus_bains();
1928} 1915}
1929 1916
1930void KOAgenda::setHolidayMask(QMemArray<bool> *mask) 1917void KOAgenda::setHolidayMask(QMemArray<bool> *mask)
1931{ 1918{
1932 mHolidayMask = mask; 1919 mHolidayMask = mask;
1933 1920
1934/* 1921/*
1935 kdDebug() << "HolidayMask: "; 1922 kdDebug() << "HolidayMask: ";
1936 for(uint i=0;i<mask->count();++i) { 1923 for(uint i=0;i<mask->count();++i) {
1937 kdDebug() << (mask->at(i) ? "*" : "o"); 1924 kdDebug() << (mask->at(i) ? "*" : "o");
1938 } 1925 }
1939 kdDebug() << endl; 1926 kdDebug() << endl;
1940*/ 1927*/
1941} 1928}
1942 1929
1943void KOAgenda::contentsMousePressEvent ( QMouseEvent *event ) 1930void KOAgenda::contentsMousePressEvent ( QMouseEvent *event )
1944{ 1931{
1945 1932
1946 QScrollView::contentsMousePressEvent(event); 1933 QScrollView::contentsMousePressEvent(event);
1947} 1934}
1948 1935
1949void KOAgenda::storePosition() 1936void KOAgenda::storePosition()
1950{ 1937{
1951 //mContentPosition 1938 //mContentPosition
1952 int max = mGridSpacingY*4*24; 1939 int max = mGridSpacingY*4*24;
1953 if ( contentsY() < 5 && max > viewport()->height()*3/2 ) 1940 if ( contentsY() < 5 && max > viewport()->height()*3/2 )
1954 mContentPosition = 0; 1941 mContentPosition = 0;
1955 else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2) 1942 else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2)
1956 mContentPosition = -1.0; 1943 mContentPosition = -1.0;
1957 else 1944 else
1958 mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2))); 1945 mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2)));
1959 //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height()); 1946 //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height());
1960 1947
1961} 1948}
1962void KOAgenda::restorePosition() 1949void KOAgenda::restorePosition()
1963{ 1950{
1964 int posY; 1951 int posY;
1965 int max = mGridSpacingY*4*24; 1952 int max = mGridSpacingY*4*24;
1966 if ( mContentPosition < 0 ) 1953 if ( mContentPosition < 0 )
1967 posY = max-viewport()->height(); 1954 posY = max-viewport()->height();
1968 else 1955 else
1969 if ( mContentPosition == 0 ) 1956 if ( mContentPosition == 0 )
1970 posY = 0; 1957 posY = 0;
1971 else 1958 else
1972 posY = (max/mContentPosition)-(viewport()->height()/2); 1959 posY = (max/mContentPosition)-(viewport()->height()/2);
1973 setContentsPos (0, posY ); 1960 setContentsPos (0, posY );
1974 //qDebug("posY %d hei %d", posY, max); 1961 //qDebug("posY %d hei %d", posY, max);
1975 1962
1976} 1963}
1977void KOAgenda::moveChild( QWidget *w, int x , int y ) 1964void KOAgenda::moveChild( QWidget *w, int x , int y )
1978{ 1965{
1979 ++x; 1966 ++x;
1980 QScrollView::moveChild( w, x , y ); 1967 QScrollView::moveChild( w, x , y );
1981} 1968}
1982#include <qmessagebox.h> 1969#include <qmessagebox.h>
1983#ifdef DESKTOP_VERSION 1970#ifdef DESKTOP_VERSION
1984#include <qprinter.h> 1971#include <qprinter.h>
1985#include <qpainter.h> 1972#include <qpainter.h>
1986#include <qpaintdevicemetrics.h> 1973#include <qpaintdevicemetrics.h>
1987 1974
1988#endif 1975#endif
1989void KOAgenda::printSelection() 1976void KOAgenda::printSelection()
1990{ 1977{
1991#ifdef DESKTOP_VERSION 1978#ifdef DESKTOP_VERSION
1992 if ( mStartCellY == mCurrentCellY ) { 1979 if ( mStartCellY == mCurrentCellY ) {
1993 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 1980 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
1994 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. "), 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. "),
1995 i18n("OK"), 0, 0, 1982 i18n("OK"), 0, 0,
1996 0, 1 ); 1983 0, 1 );
1997 return; 1984 return;
1998 } 1985 }
1999 1986
2000 float dx, dy; 1987 float dx, dy;
2001 int x,y,w,h; 1988 int x,y,w,h;
2002 x= 0; 1989 x= 0;
2003 w= contentsWidth()+2; 1990 w= contentsWidth()+2;
2004 // h= contentsHeight(); 1991 // h= contentsHeight();
2005 y = mGridSpacingY*mStartCellY; 1992 y = mGridSpacingY*mStartCellY;
2006 h = mGridSpacingY*(mCurrentCellY+1)-y+2; 1993 h = mGridSpacingY*(mCurrentCellY+1)-y+2;
2007 1994
2008 //return; 1995 //return;
2009 QPrinter* printer = new QPrinter(); 1996 QPrinter* printer = new QPrinter();
2010 if ( !printer->setup()) { 1997 if ( !printer->setup()) {
2011 delete printer; 1998 delete printer;
2012 return; 1999 return;
2013 } 2000 }
2014 QPainter p( printer ); 2001 QPainter p( printer );
2015 QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer ); 2002 QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer );
2016 QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() ); 2003 QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() );
2017 //date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true ); 2004 //date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true );
2018 int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height(); 2005 int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height();
2019 // p.drawText( 0, 0, date ); 2006 // p.drawText( 0, 0, date );
2020 int offset = m.width()/8; 2007 int offset = m.width()/8;
2021 // compute the scale 2008 // compute the scale
2022 dx = ((float) m.width()-offset) / (float)w; 2009 dx = ((float) m.width()-offset) / (float)w;
2023 dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h; 2010 dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h;
2024 float scale; 2011 float scale;
2025 // scale to fit the width or height of the paper 2012 // scale to fit the width or height of the paper
2026 if ( dx < dy ) 2013 if ( dx < dy )
2027 scale = dx; 2014 scale = dx;
2028 else 2015 else
2029 scale = dy; 2016 scale = dy;
2030 // set the scale 2017 // set the scale
2031 p.drawText( offset* scale, offset* scale*3/4, date ); 2018 p.drawText( offset* scale, offset* scale*3/4, date );
2032 2019
2033 int selDay; 2020 int selDay;
2034 float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count())); 2021 float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count()));
2035 float startX = 1; 2022 float startX = 1;
2036 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) 2023 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay)
2037 { 2024 {
2038 QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true ); 2025 QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true );
2039 p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) ); 2026 p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) );
2040 p.drawText( offset* scale+startX, (offset+hei)* scale, text ); 2027 p.drawText( offset* scale+startX, (offset+hei)* scale, text );
2041 startX += widOffset; 2028 startX += widOffset;
2042 2029
2043 } 2030 }
2044 p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale)); 2031 p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale));
2045 p.scale( scale, scale ); 2032 p.scale( scale, scale );
2046 p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale ); 2033 p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale );
2047 // now printing with y offset: 2 hei 2034 // now printing with y offset: 2 hei
2048 // p.translate( 0, -y*scale); 2035 // p.translate( 0, -y*scale);
2049 2036
2050 drawContentsToPainter(&p, true ); 2037 drawContentsToPainter(&p, true );
2051 globalFlagBlockAgendaItemUpdate = false; 2038 globalFlagBlockAgendaItemUpdate = false;
2052 KOAgendaItem *item; 2039 KOAgendaItem *item;
2053 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 2040 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
2054 item->select(false); 2041 item->select(false);
2055 item->paintMe( false, &p ); 2042 item->paintMe( false, &p );
2056 } 2043 }
2057 globalFlagBlockAgendaItemUpdate = true; 2044 globalFlagBlockAgendaItemUpdate = true;
2058 p.end(); 2045 p.end();
2059 delete printer; 2046 delete printer;
2060#else 2047#else
2061 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2048 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2062 i18n("Not supported \non PDA!\n"), 2049 i18n("Not supported \non PDA!\n"),
2063 i18n("OK"), 0, 0, 2050 i18n("OK"), 0, 0,
2064 0, 1 ); 2051 0, 1 );
2065#endif 2052#endif
2066} 2053}
diff --git a/korganizer/koagendaitem.cpp b/korganizer/koagendaitem.cpp
index b30ad75..905c1bf 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/kolistview.cpp b/korganizer/kolistview.cpp
index 3519985..6b63d7f 100644
--- a/korganizer/kolistview.cpp
+++ b/korganizer/kolistview.cpp
@@ -1,1227 +1,1195 @@
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(rightButtonClicked ( 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 )
1158{ 1158{
1159#ifndef DESKTOP_VERSION 1159#ifndef DESKTOP_VERSION
1160 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold ); 1160 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold );
1161#endif 1161#endif
1162 mYMousePos = -1000;
1163 setSelectionMode( QListView::Multi ); 1162 setSelectionMode( QListView::Multi );
1164 setMultiSelection( true); 1163 setMultiSelection( true);
1165 mAllowPopupMenu = true;
1166 mMouseDown = false;
1167
1168} 1164}
1169void KOListViewListView::contentsMouseDoubleClickEvent(QMouseEvent *e) 1165void KOListViewListView::contentsMouseDoubleClickEvent(QMouseEvent *e)
1170{ 1166{
1171 if (!e) return; 1167 if (!e) return;
1172 QPoint vp = contentsToViewport(e->pos()); 1168 QPoint vp = contentsToViewport(e->pos());
1173 QListViewItem *item = itemAt(vp); 1169 QListViewItem *item = itemAt(vp);
1174 if (!item) { 1170 if (!item) {
1175 emit newEvent(); 1171 emit newEvent();
1176 return; 1172 return;
1177 } 1173 }
1178 KListView::contentsMouseDoubleClickEvent(e); 1174 KListView::contentsMouseDoubleClickEvent(e);
1179} 1175}
1180 1176
1181
1182void KOListViewListView::contentsMousePressEvent(QMouseEvent *e) 1177void KOListViewListView::contentsMousePressEvent(QMouseEvent *e)
1183{ 1178{
1184 //qDebug("contentsMousePressEvent++++ "); 1179 //qDebug("contentsMousePressEvent++++ ");
1185 if (! mMouseDown ) {
1186 mAllowPopupMenu = true;
1187 mYMousePos = mapToGlobal( (e->pos())).y();
1188 }
1189 if ( e->button() == RightButton && mMouseDown )
1190 return;
1191 if ( e->button() == LeftButton )
1192 mMouseDown = true;
1193 KListView::contentsMousePressEvent( e ); 1180 KListView::contentsMousePressEvent( e );
1181 if ( e->button() == RightButton ) {
1182 QListViewItem* ci = currentItem();
1183 clearSelection () ;
1184 if ( ci )
1185 ci->setSelected( true );
1186 }
1194} 1187}
1195void KOListViewListView::contentsMouseReleaseEvent(QMouseEvent *e) 1188void KOListViewListView::contentsMouseReleaseEvent(QMouseEvent *e)
1196{ 1189{
1197 //qDebug("contentsMouseReleaseEv---- ");
1198 if ( ! mMouseDown ) {
1199 if ( e->button() == RightButton && ! mAllowPopupMenu )
1200 return;
1201 QListViewItem* ci = currentItem();
1202 if ( ci )
1203 ci->setSelected( true );
1204 KListView::contentsMouseReleaseEvent(e);
1205 return;
1206 }
1207 if ( e->button() == LeftButton )
1208 mMouseDown = false;
1209 if ( e->button() == RightButton && ! mAllowPopupMenu )
1210 return;
1211 if ( e->button() == RightButton ) {
1212 QListViewItem* ci = currentItem();
1213 if ( ci )
1214 ci->setSelected( true );
1215 }
1216 KListView::contentsMouseReleaseEvent(e); 1190 KListView::contentsMouseReleaseEvent(e);
1217} 1191}
1218void KOListViewListView::contentsMouseMoveEvent(QMouseEvent *e) 1192void KOListViewListView::contentsMouseMoveEvent(QMouseEvent *e)
1219{ 1193{
1220 // qDebug("contentsMouseMoveEv....... ");
1221 // qDebug("start: %d current %d ",mYMousePos , mapToGlobal( (e->pos())).y() );
1222 int diff = mYMousePos - mapToGlobal( (e->pos())).y();
1223 if ( diff < 0 ) diff = -diff;
1224 if ( diff > 20 )
1225 mAllowPopupMenu = false;
1226 KListView::contentsMouseMoveEvent(e); 1194 KListView::contentsMouseMoveEvent(e);
1227} 1195}
diff --git a/korganizer/kolistview.h b/korganizer/kolistview.h
index 0d9c525..eca71e2 100644
--- a/korganizer/kolistview.h
+++ b/korganizer/kolistview.h
@@ -1,306 +1,304 @@
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 <qcombobox.h> 50#include <qcombobox.h>
51#include <qspinbox.h> 51#include <qspinbox.h>
52#include <qtooltip.h> 52#include <qtooltip.h>
53#include <qcheckbox.h> 53#include <qcheckbox.h>
54#include <qhbox.h> 54#include <qhbox.h>
55#include <qlabel.h> 55#include <qlabel.h>
56#include <kiconloader.h> 56#include <kiconloader.h>
57#include "kfiledialog.h" 57#include "kfiledialog.h"
58#include "koprefs.h" 58#include "koprefs.h"
59class KOAlarmPrefs : public QDialog 59class KOAlarmPrefs : public QDialog
60{ 60{
61 Q_OBJECT 61 Q_OBJECT
62 public: 62 public:
63 KOAlarmPrefs( QWidget *par=0, const char *name=0 ) : 63 KOAlarmPrefs( QWidget *par=0, const char *name=0 ) :
64 QDialog( par, name, true ) 64 QDialog( par, name, true )
65 { 65 {
66 setCaption( i18n("Alarm Options") ); 66 setCaption( i18n("Alarm Options") );
67 QVBoxLayout* alarmLayout = new QVBoxLayout( this ); 67 QVBoxLayout* alarmLayout = new QVBoxLayout( this );
68 alarmLayout->setSpacing( 3 ); 68 alarmLayout->setSpacing( 3 );
69 alarmLayout->setMargin( 3 ); 69 alarmLayout->setMargin( 3 );
70 QWidget *parent = this; 70 QWidget *parent = this;
71 mAlarmButton = new QCheckBox(i18n("Set reminder ON with offset to:"),parent); 71 mAlarmButton = new QCheckBox(i18n("Set reminder ON with offset to:"),parent);
72 alarmLayout->addWidget(mAlarmButton); 72 alarmLayout->addWidget(mAlarmButton);
73 mAlarmTimeEdit = new QSpinBox ( 0, 9999, 1, parent, "mAlarmTimeEdit " ) ; 73 mAlarmTimeEdit = new QSpinBox ( 0, 9999, 1, parent, "mAlarmTimeEdit " ) ;
74 mAlarmTimeEdit->setValue( 15 ); 74 mAlarmTimeEdit->setValue( 15 );
75 alarmLayout->addWidget(mAlarmTimeEdit); 75 alarmLayout->addWidget(mAlarmTimeEdit);
76 mAlarmIncrCombo = new QComboBox(false, parent); 76 mAlarmIncrCombo = new QComboBox(false, parent);
77 mAlarmIncrCombo->insertItem(i18n("minute(s)")); 77 mAlarmIncrCombo->insertItem(i18n("minute(s)"));
78 mAlarmIncrCombo->insertItem(i18n("hour(s)")); 78 mAlarmIncrCombo->insertItem(i18n("hour(s)"));
79 mAlarmIncrCombo->insertItem(i18n("day(s)")); 79 mAlarmIncrCombo->insertItem(i18n("day(s)"));
80 alarmLayout->addWidget(mAlarmIncrCombo); 80 alarmLayout->addWidget(mAlarmIncrCombo);
81 QHBox * hb = new QHBox ( parent ); 81 QHBox * hb = new QHBox ( parent );
82 alarmLayout->addWidget(hb); 82 alarmLayout->addWidget(hb);
83 mAlarmSoundButton = new QPushButton(hb); 83 mAlarmSoundButton = new QPushButton(hb);
84 mAlarmSoundButton->setPixmap(SmallIcon("playsound")); 84 mAlarmSoundButton->setPixmap(SmallIcon("playsound"));
85 mAlarmSoundButton->setToggleButton(true); 85 mAlarmSoundButton->setToggleButton(true);
86 connect(mAlarmSoundButton, SIGNAL(clicked()), SLOT(pickAlarmSound())); 86 connect(mAlarmSoundButton, SIGNAL(clicked()), SLOT(pickAlarmSound()));
87 mAlarmProgramButton = new QPushButton(hb); 87 mAlarmProgramButton = new QPushButton(hb);
88 mAlarmProgramButton->setPixmap(SmallIcon("run")); 88 mAlarmProgramButton->setPixmap(SmallIcon("run"));
89 mAlarmProgramButton->setToggleButton(true); 89 mAlarmProgramButton->setToggleButton(true);
90 connect(mAlarmProgramButton, SIGNAL(clicked()), SLOT(pickAlarmProgram())); 90 connect(mAlarmProgramButton, SIGNAL(clicked()), SLOT(pickAlarmProgram()));
91 mAlarmSoundButton->setMaximumWidth( mAlarmSoundButton->sizeHint().width() + 4 ); 91 mAlarmSoundButton->setMaximumWidth( mAlarmSoundButton->sizeHint().width() + 4 );
92 mAlarmProgramButton->setMaximumWidth(mAlarmProgramButton->sizeHint().width() + 4 ); 92 mAlarmProgramButton->setMaximumWidth(mAlarmProgramButton->sizeHint().width() + 4 );
93 mAlarmLabel = new QLabel( this ); 93 mAlarmLabel = new QLabel( this );
94 alarmLayout->addWidget( mAlarmLabel ); 94 alarmLayout->addWidget( mAlarmLabel );
95 mAlarmLabel->setText( "..."+KOPrefs::instance()->mDefaultAlarmFile.right( 30 ) ); 95 mAlarmLabel->setText( "..."+KOPrefs::instance()->mDefaultAlarmFile.right( 30 ) );
96 mAlarmSound = KOPrefs::instance()->mDefaultAlarmFile; 96 mAlarmSound = KOPrefs::instance()->mDefaultAlarmFile;
97 mAlarmSoundButton->setOn( true ); 97 mAlarmSoundButton->setOn( true );
98 QPushButton * ok = new QPushButton( i18n("Set Alarm!"), this ); 98 QPushButton * ok = new QPushButton( i18n("Set Alarm!"), this );
99 alarmLayout->addWidget( ok ); 99 alarmLayout->addWidget( ok );
100 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 100 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
101 alarmLayout->addWidget( cancel ); 101 alarmLayout->addWidget( cancel );
102 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 102 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
103 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 103 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
104 resize( 200, 200 ); 104 resize( 200, 200 );
105 105
106 } 106 }
107 107
108 108
109 109
110 QString mAlarmSound, mAlarmProgram ; 110 QString mAlarmSound, mAlarmProgram ;
111 QCheckBox* mAlarmButton; 111 QCheckBox* mAlarmButton;
112 QSpinBox* mAlarmTimeEdit; 112 QSpinBox* mAlarmTimeEdit;
113 QLabel* mAlarmLabel; 113 QLabel* mAlarmLabel;
114 QComboBox* mAlarmIncrCombo ; 114 QComboBox* mAlarmIncrCombo ;
115 QPushButton* mAlarmSoundButton ,*mAlarmProgramButton; 115 QPushButton* mAlarmSoundButton ,*mAlarmProgramButton;
116private slots: 116private slots:
117 117
118void pickAlarmSound() 118void pickAlarmSound()
119{ 119{
120 //QString prefix = mAlarmSound; 120 //QString prefix = mAlarmSound;
121 if (!mAlarmSoundButton->isOn()) { 121 if (!mAlarmSoundButton->isOn()) {
122 //mAlarmSound = ""; 122 //mAlarmSound = "";
123 QToolTip::remove(mAlarmSoundButton); 123 QToolTip::remove(mAlarmSoundButton);
124 QToolTip::add(mAlarmSoundButton, i18n("No sound set")); 124 QToolTip::add(mAlarmSoundButton, i18n("No sound set"));
125 mAlarmProgramButton->setOn(true); 125 mAlarmProgramButton->setOn(true);
126 mAlarmSoundButton->setOn(false); 126 mAlarmSoundButton->setOn(false);
127 } else { 127 } else {
128 QString fileName(KFileDialog::getOpenFileName(mAlarmSound, 128 QString fileName(KFileDialog::getOpenFileName(mAlarmSound,
129 i18n("*.wav|Wav Files"), 0)); 129 i18n("*.wav|Wav Files"), 0));
130 if (!fileName.isEmpty()) { 130 if (!fileName.isEmpty()) {
131 mAlarmSound = fileName; 131 mAlarmSound = fileName;
132 mAlarmLabel->setText( "..."+fileName.right( 30 ) ); 132 mAlarmLabel->setText( "..."+fileName.right( 30 ) );
133 QToolTip::remove(mAlarmSoundButton); 133 QToolTip::remove(mAlarmSoundButton);
134 QString dispStr = i18n("Playing '%1'").arg(fileName); 134 QString dispStr = i18n("Playing '%1'").arg(fileName);
135 QToolTip::add(mAlarmSoundButton, dispStr); 135 QToolTip::add(mAlarmSoundButton, dispStr);
136 mAlarmProgramButton->setOn(false); 136 mAlarmProgramButton->setOn(false);
137 mAlarmSoundButton->setOn(true); 137 mAlarmSoundButton->setOn(true);
138 } else { 138 } else {
139 mAlarmProgramButton->setOn(true); 139 mAlarmProgramButton->setOn(true);
140 mAlarmSoundButton->setOn(false); 140 mAlarmSoundButton->setOn(false);
141 141
142 } 142 }
143 } 143 }
144}; 144};
145 145
146void pickAlarmProgram() 146void pickAlarmProgram()
147{ 147{
148 if (!mAlarmProgramButton->isOn()) { 148 if (!mAlarmProgramButton->isOn()) {
149 //mAlarmProgram = ""; 149 //mAlarmProgram = "";
150 QToolTip::remove(mAlarmProgramButton); 150 QToolTip::remove(mAlarmProgramButton);
151 QToolTip::add(mAlarmProgramButton, i18n("No program set")); 151 QToolTip::add(mAlarmProgramButton, i18n("No program set"));
152 mAlarmProgramButton->setOn(false); 152 mAlarmProgramButton->setOn(false);
153 mAlarmSoundButton->setOn(true); 153 mAlarmSoundButton->setOn(true);
154 } else { 154 } else {
155 QString fileName(KFileDialog::getOpenFileName(mAlarmProgram,i18n("Procedure Alarm.: ") , 0)); 155 QString fileName(KFileDialog::getOpenFileName(mAlarmProgram,i18n("Procedure Alarm.: ") , 0));
156 if (!fileName.isEmpty()) { 156 if (!fileName.isEmpty()) {
157 mAlarmProgram = fileName; 157 mAlarmProgram = fileName;
158 mAlarmLabel->setText( "..."+fileName.right( 30 ) ); 158 mAlarmLabel->setText( "..."+fileName.right( 30 ) );
159 QToolTip::remove(mAlarmProgramButton); 159 QToolTip::remove(mAlarmProgramButton);
160 QString dispStr = i18n("Running '%1'").arg(fileName); 160 QString dispStr = i18n("Running '%1'").arg(fileName);
161 QToolTip::add(mAlarmProgramButton, dispStr); 161 QToolTip::add(mAlarmProgramButton, dispStr);
162 mAlarmSoundButton->setOn(false); 162 mAlarmSoundButton->setOn(false);
163 mAlarmProgramButton->setOn(true); 163 mAlarmProgramButton->setOn(true);
164 } else { 164 } else {
165 mAlarmProgramButton->setOn(false); 165 mAlarmProgramButton->setOn(false);
166 mAlarmSoundButton->setOn(true); 166 mAlarmSoundButton->setOn(true);
167 } 167 }
168 } 168 }
169}; 169};
170 170
171}; 171};
172 172
173 173
174 174
175 175
176 176
177 177
178 178
179typedef CustomListViewItem<Incidence *> KOListViewItem; 179typedef CustomListViewItem<Incidence *> KOListViewItem;
180 180
181/** 181/**
182 This class provides the initialisation of a KOListViewItem for calendar 182 This class provides the initialisation of a KOListViewItem for calendar
183 components using the Incidence::Visitor. 183 components using the Incidence::Visitor.
184*/ 184*/
185class ListItemVisitor : public Incidence::Visitor 185class ListItemVisitor : public Incidence::Visitor
186{ 186{
187 public: 187 public:
188 ListItemVisitor(KOListViewItem *, QDate d); 188 ListItemVisitor(KOListViewItem *, QDate d);
189 ~ListItemVisitor(); 189 ~ListItemVisitor();
190 190
191 bool visit(Event *); 191 bool visit(Event *);
192 bool visit(Todo *); 192 bool visit(Todo *);
193 bool visit(Journal *); 193 bool visit(Journal *);
194 194
195 private: 195 private:
196 KOListViewItem *mItem; 196 KOListViewItem *mItem;
197 QDate mDate; 197 QDate mDate;
198}; 198};
199 199
200/** 200/**
201 This class provides a multi-column list view of events. It can 201 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 202 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 203 matter. To use a view that only handles one day at a time, use
204 KODayListView. 204 KODayListView.
205 205
206 @short multi-column list view of various events. 206 @short multi-column list view of various events.
207 @author Preston Brown <pbrown@kde.org> 207 @author Preston Brown <pbrown@kde.org>
208 @see KOBaseView, KODayListView 208 @see KOBaseView, KODayListView
209*/ 209*/
210class KOListView; 210class KOListView;
211 211
212class KOListViewListView : public KListView 212class KOListViewListView : public KListView
213{ 213{
214 Q_OBJECT 214 Q_OBJECT
215 public: 215 public:
216 KOListViewListView(KOListView * lv ); 216 KOListViewListView(KOListView * lv );
217 signals: 217 signals:
218 void newEvent(); 218 void newEvent();
219 void showIncidence( Incidence* ); 219 void showIncidence( Incidence* );
220 private: 220 private:
221 void keyPressEvent ( QKeyEvent * ) ; 221 void keyPressEvent ( QKeyEvent * ) ;
222 void contentsMouseDoubleClickEvent(QMouseEvent *e); 222 void contentsMouseDoubleClickEvent(QMouseEvent *e);
223 void contentsMousePressEvent(QMouseEvent *e); 223 void contentsMousePressEvent(QMouseEvent *e);
224 void contentsMouseReleaseEvent(QMouseEvent *e); 224 void contentsMouseReleaseEvent(QMouseEvent *e);
225 void contentsMouseMoveEvent(QMouseEvent *e); 225 void contentsMouseMoveEvent(QMouseEvent *e);
226 bool mAllowPopupMenu;
227 bool mMouseDown; 226 bool mMouseDown;
228 int mYMousePos;
229}; 227};
230 228
231class KOListView : public KOEventView 229class KOListView : public KOEventView
232{ 230{
233 Q_OBJECT 231 Q_OBJECT
234 public: 232 public:
235 KOListView(Calendar *calendar, QWidget *parent = 0, 233 KOListView(Calendar *calendar, QWidget *parent = 0,
236 const char *name = 0); 234 const char *name = 0);
237 ~KOListView(); 235 ~KOListView();
238 236
239 virtual int maxDatesHint(); 237 virtual int maxDatesHint();
240 virtual int currentDateCount(); 238 virtual int currentDateCount();
241 virtual QPtrList<Incidence> selectedIncidences(); 239 virtual QPtrList<Incidence> selectedIncidences();
242 virtual DateList selectedDates(); 240 virtual DateList selectedDates();
243 241
244 void showDates(bool show); 242 void showDates(bool show);
245 Incidence* currentItem(); 243 Incidence* currentItem();
246 void addTodos(QPtrList<Todo> eventList); 244 void addTodos(QPtrList<Todo> eventList);
247 void addJournals(QPtrList<Journal> eventList); 245 void addJournals(QPtrList<Journal> eventList);
248 virtual void printPreview(CalPrinter *calPrinter, 246 virtual void printPreview(CalPrinter *calPrinter,
249 const QDate &, const QDate &); 247 const QDate &, const QDate &);
250 248
251 void readSettings(KConfig *config, QString setting = "KOListView Layout"); 249 void readSettings(KConfig *config, QString setting = "KOListView Layout");
252 void writeSettings(KConfig *config, QString setting = "KOListView Layout"); 250 void writeSettings(KConfig *config, QString setting = "KOListView Layout");
253 void updateList(); 251 void updateList();
254 void setStartDate(const QDate &start); 252 void setStartDate(const QDate &start);
255 int count(); 253 int count();
256 QString getWhatsThisText(QPoint p); 254 QString getWhatsThisText(QPoint p);
257 void resetFocus(); 255 void resetFocus();
258 signals: 256 signals:
259 void signalNewEvent(); 257 void signalNewEvent();
260 void beamIncidenceList(QPtrList<Incidence>); 258 void beamIncidenceList(QPtrList<Incidence>);
261 259
262 public slots: 260 public slots:
263 virtual void updateView(); 261 virtual void updateView();
264 virtual void showDates(const QDate &start, const QDate &end); 262 virtual void showDates(const QDate &start, const QDate &end);
265 virtual void showEvents(QPtrList<Event> eventList); 263 virtual void showEvents(QPtrList<Event> eventList);
266 void clearSelection(); 264 void clearSelection();
267 void allSelection(); 265 void allSelection();
268 266
269 void clear(); 267 void clear();
270 void beamDone( Ir *ir ); 268 void beamDone( Ir *ir );
271 void showDates(); 269 void showDates();
272 void hideDates(); 270 void hideDates();
273 void deleteAll(); 271 void deleteAll();
274 void saveToFile(); 272 void saveToFile();
275 void saveToFileVCS(); 273 void saveToFileVCS();
276 void saveDescriptionToFile(); 274 void saveDescriptionToFile();
277 void beamSelected(); 275 void beamSelected();
278 void updateConfig(); 276 void updateConfig();
279 void addCat(); 277 void addCat();
280 void setCat(); 278 void setCat();
281 void setAlarm(); 279 void setAlarm();
282 void setCategories( bool removeOld ); 280 void setCategories( bool removeOld );
283 void changeEventDisplay(Event *, int); 281 void changeEventDisplay(Event *, int);
284 282
285 void defaultItemAction(QListViewItem *item); 283 void defaultItemAction(QListViewItem *item);
286 void popupMenu(QListViewItem *item,const QPoint &,int); 284 void popupMenu(QListViewItem *item,const QPoint &,int);
287 285
288 protected slots: 286 protected slots:
289 void processSelectionChange(QListViewItem *); 287 void processSelectionChange(QListViewItem *);
290 288
291 protected: 289 protected:
292 void writeToFile( bool iCal ); 290 void writeToFile( bool iCal );
293 void addEvents(QPtrList<Event> eventList); 291 void addEvents(QPtrList<Event> eventList);
294 void addIncidence(Incidence *); 292 void addIncidence(Incidence *);
295 KOListViewItem *getItemForEvent(Event *event); 293 KOListViewItem *getItemForEvent(Event *event);
296 294
297 private: 295 private:
298 KOListViewListView *mListView; 296 KOListViewListView *mListView;
299 KOEventPopupMenu *mPopupMenu; 297 KOEventPopupMenu *mPopupMenu;
300 KOListViewItem *mActiveItem; 298 KOListViewItem *mActiveItem;
301 QDict<Incidence> mUidDict; 299 QDict<Incidence> mUidDict;
302 QDate mStartDate; 300 QDate mStartDate;
303 void keyPressEvent ( QKeyEvent * ) ; 301 void keyPressEvent ( QKeyEvent * ) ;
304}; 302};
305 303
306#endif 304#endif
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp
index 12233ee..9085775 100644
--- a/korganizer/komonthview.cpp
+++ b/korganizer/komonthview.cpp
@@ -1,1853 +1,1858 @@
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 <qpopupmenu.h> 20#include <qpopupmenu.h>
21#include <qfont.h> 21#include <qfont.h>
22#include <qfontmetrics.h> 22#include <qfontmetrics.h>
23#include <qkeycode.h> 23#include <qkeycode.h>
24#include <qhbox.h> 24#include <qhbox.h>
25#include <qvbox.h> 25#include <qvbox.h>
26#include <qwidgetstack.h> 26#include <qwidgetstack.h>
27#include <qpushbutton.h> 27#include <qpushbutton.h>
28#include <qtooltip.h> 28#include <qtooltip.h>
29#include <qpainter.h> 29#include <qpainter.h>
30#include <qtimer.h> 30#include <qtimer.h>
31#include <qwhatsthis.h> 31#include <qwhatsthis.h>
32#ifndef DESKTOP_VERSION 32#ifndef DESKTOP_VERSION
33#include <qpe/qpeapplication.h> 33#include <qpe/qpeapplication.h>
34#else 34#else
35#include <qapplication.h> 35#include <qapplication.h>
36#endif 36#endif
37 37
38#include <kdebug.h> 38#include <kdebug.h>
39#include <klocale.h> 39#include <klocale.h>
40#include <kglobal.h> 40#include <kglobal.h>
41#include <kconfig.h> 41#include <kconfig.h>
42#include <kiconloader.h> 42#include <kiconloader.h>
43 43
44#include <kcalendarsystem.h> 44#include <kcalendarsystem.h>
45 45
46#ifndef KORG_NOPRINTER 46#ifndef KORG_NOPRINTER
47#include "calprinter.h" 47#include "calprinter.h"
48#endif 48#endif
49#include "koprefs.h" 49#include "koprefs.h"
50#ifndef KORG_NOPLUGINS 50#ifndef KORG_NOPLUGINS
51#include "kocore.h" 51#include "kocore.h"
52#endif 52#endif
53#include "koglobals.h" 53#include "koglobals.h"
54#include <libkcal/kincidenceformatter.h> 54#include <libkcal/kincidenceformatter.h>
55 55
56#include "komonthview.h" 56#include "komonthview.h"
57 57
58#define PIXMAP_SIZE 5 58#define PIXMAP_SIZE 5
59#ifdef DESKTOP_VERSION 59#ifdef DESKTOP_VERSION
60QToolTipGroup *MonthViewCell::mToolTipGroup = 0; 60QToolTipGroup *MonthViewCell::mToolTipGroup = 0;
61#endif 61#endif
62class KNOWhatsThis :public QWhatsThis 62class KNOWhatsThis :public QWhatsThis
63{ 63{
64public: 64public:
65 KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { }; 65 KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { };
66 //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); }; 66 //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); };
67 67
68protected: 68protected:
69 virtual QString text( const QPoint& p) 69 virtual QString text( const QPoint& p)
70 { 70 {
71 return _wid->getWhatsThisText(p) ; 71 return _wid->getWhatsThisText(p) ;
72 }; 72 };
73private: 73private:
74 KNoScrollListBox* _wid; 74 KNoScrollListBox* _wid;
75 75
76}; 76};
77 77
78 78
79KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) 79KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name)
80 : QListBox(parent, name, WRepaintNoErase) 80 : QListBox(parent, name, WRepaintNoErase)
81{ 81{
82#ifndef DESKTOP_VERSION 82#ifndef DESKTOP_VERSION
83 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 83 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
84#endif 84#endif
85 mWT = new KNOWhatsThis(this); 85 mWT = new KNOWhatsThis(this);
86} 86}
87KNoScrollListBox::~KNoScrollListBox() 87KNoScrollListBox::~KNoScrollListBox()
88{ 88{
89 89
90} 90}
91QString KNoScrollListBox::getWhatsThisText(QPoint p) 91QString KNoScrollListBox::getWhatsThisText(QPoint p)
92{ 92{
93 QListBoxItem* item = itemAt ( p ); 93 QListBoxItem* item = itemAt ( p );
94 if ( ! item ) { 94 if ( ! item ) {
95 return i18n("Click in the cell\nto add an event!"); 95 return i18n("Click in the cell\nto add an event!");
96 } 96 }
97 return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence(), 97 return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence(),
98 KOPrefs::instance()->mWTshowDetails, 98 KOPrefs::instance()->mWTshowDetails,
99 KOPrefs::instance()->mWTshowCreated, 99 KOPrefs::instance()->mWTshowCreated,
100 KOPrefs::instance()->mWTshowChanged); 100 KOPrefs::instance()->mWTshowChanged);
101} 101}
102void KNoScrollListBox::keyPressEvent(QKeyEvent *e) 102void KNoScrollListBox::keyPressEvent(QKeyEvent *e)
103{ 103{
104 104
105 switch(e->key()) { 105 switch(e->key()) {
106 case Key_Right: 106 case Key_Right:
107 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 107 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
108 { 108 {
109 e->ignore(); 109 e->ignore();
110 return; 110 return;
111 } 111 }
112 scrollBy(10,0); 112 scrollBy(10,0);
113 break; 113 break;
114 case Key_Left: 114 case Key_Left:
115 if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 115 if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
116 { 116 {
117 e->ignore(); 117 e->ignore();
118 return; 118 return;
119 } 119 }
120 scrollBy(-10,0); 120 scrollBy(-10,0);
121 break; 121 break;
122 case Key_Up: 122 case Key_Up:
123 if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { 123 if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) {
124 e->ignore(); 124 e->ignore();
125 break; 125 break;
126 } 126 }
127 setCurrentItem((currentItem()+count()-1)%count()); 127 setCurrentItem((currentItem()+count()-1)%count());
128 if(!itemVisible(currentItem())) { 128 if(!itemVisible(currentItem())) {
129 if((unsigned int) currentItem() == (count()-1)) { 129 if((unsigned int) currentItem() == (count()-1)) {
130 setTopItem(currentItem()-numItemsVisible()+1); 130 setTopItem(currentItem()-numItemsVisible()+1);
131 } else { 131 } else {
132 setTopItem(topItem()-1); 132 setTopItem(topItem()-1);
133 } 133 }
134 } 134 }
135 break; 135 break;
136 case Key_Down: 136 case Key_Down:
137 if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { 137 if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) {
138 e->ignore(); 138 e->ignore();
139 break; 139 break;
140 } 140 }
141 setCurrentItem((currentItem()+1)%count()); 141 setCurrentItem((currentItem()+1)%count());
142 if(!itemVisible(currentItem())) { 142 if(!itemVisible(currentItem())) {
143 if(currentItem() == 0) { 143 if(currentItem() == 0) {
144 setTopItem(0); 144 setTopItem(0);
145 } else { 145 } else {
146 setTopItem(topItem()+1); 146 setTopItem(topItem()+1);
147 } 147 }
148 } 148 }
149 break; 149 break;
150 case Key_I: 150 case Key_I:
151 QTimer::singleShot( 11, this, SLOT ( oneDown() ) ); 151 QTimer::singleShot( 11, this, SLOT ( oneDown() ) );
152 e->ignore(); 152 e->ignore();
153 break; 153 break;
154 case Key_Shift: 154 case Key_Shift:
155 emit shiftDown(); 155 emit shiftDown();
156 break; 156 break;
157 default: 157 default:
158 e->ignore(); 158 e->ignore();
159 break; 159 break;
160 } 160 }
161} 161}
162 162
163void KNoScrollListBox::oneDown() 163void KNoScrollListBox::oneDown()
164{ 164{
165 setCurrentItem((currentItem()+1)%count()); 165 setCurrentItem((currentItem()+1)%count());
166 if(!itemVisible(currentItem())) { 166 if(!itemVisible(currentItem())) {
167 if(currentItem() == 0) { 167 if(currentItem() == 0) {
168 setTopItem(0); 168 setTopItem(0);
169 } else { 169 } else {
170 setTopItem(topItem()+1); 170 setTopItem(topItem()+1);
171 } 171 }
172 } 172 }
173} 173}
174void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) 174void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e)
175{ 175{
176 switch(e->key()) { 176 switch(e->key()) {
177 case Key_Shift: 177 case Key_Shift:
178 emit shiftUp(); 178 emit shiftUp();
179 break; 179 break;
180 default: 180 default:
181 break; 181 break;
182 } 182 }
183} 183}
184 184
185void KNoScrollListBox::mousePressEvent(QMouseEvent *e) 185void KNoScrollListBox::mousePressEvent(QMouseEvent *e)
186{ 186{
187 QListBox::mousePressEvent(e); 187 QListBox::mousePressEvent(e);
188 188
189 if(e->button() == RightButton) { 189 if(e->button() == RightButton) {
190 emit rightClick(); 190 emit rightClick();
191 } 191 }
192} 192}
193 193
194MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) 194MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s)
195 : QListBoxItem() 195 : QListBoxItem()
196{ 196{
197 mblockRepaint = true; 197 mblockRepaint = true;
198 setText( s ); 198 setText( s );
199 mMultiday = 0; 199 mMultiday = 0;
200 mIncidence = incidence; 200 mIncidence = incidence;
201 mDate = qd; 201 mDate = qd;
202 mRecur = false; 202 mRecur = false;
203 mAlarm = false; 203 mAlarm = false;
204 mReply = false; 204 mReply = false;
205 mInfo = false; 205 mInfo = false;
206 //qDebug("NEWWWWWWWWWWWWW "); 206 //qDebug("NEWWWWWWWWWWWWW ");
207} 207}
208void MonthViewItem::recycle( Incidence *incidence, QDate qd, const QString & s) 208void MonthViewItem::recycle( Incidence *incidence, QDate qd, const QString & s)
209{ 209{
210 setText( s ); 210 setText( s );
211 mMultiday = 0; 211 mMultiday = 0;
212 mIncidence = incidence; 212 mIncidence = incidence;
213 mDate = qd; 213 mDate = qd;
214 mRecur = false; 214 mRecur = false;
215 mAlarm = false; 215 mAlarm = false;
216 mReply = false; 216 mReply = false;
217 mInfo = false; 217 mInfo = false;
218 //qDebug("recucleeeeeeeeeeeeeeeee "); 218 //qDebug("recucleeeeeeeeeeeeeeeee ");
219} 219}
220 220
221void MonthViewItem::paint(QPainter *p) 221void MonthViewItem::paint(QPainter *p)
222{ 222{
223 if ( mblockRepaint ) { 223 if ( mblockRepaint ) {
224 //qDebug("block "); 224 //qDebug("block ");
225 return; 225 return;
226 } 226 }
227 //qDebug("NON block "); 227 //qDebug("NON block ");
228#if QT_VERSION >= 0x030000 228#if QT_VERSION >= 0x030000
229 bool sel = isSelected(); 229 bool sel = isSelected();
230#else 230#else
231 bool sel = selected(); 231 bool sel = selected();
232#endif 232#endif
233 233
234 234
235 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) 235 if (KOPrefs::instance()->mMonthViewUsesCategoryColor)
236 { 236 {
237 p->setBackgroundColor( palette().color( QPalette::Normal, \ 237 p->setBackgroundColor( palette().color( QPalette::Normal, \
238 sel ? QColorGroup::Highlight : QColorGroup::Background ) ); 238 sel ? QColorGroup::Highlight : QColorGroup::Background ) );
239 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); 239 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) );
240 } 240 }
241 int x = 1; 241 int x = 1;
242 //int y = 3;//(height() - mRecurPixmap.height()) /2; 242 //int y = 3;//(height() - mRecurPixmap.height()) /2;
243 int size = PIXMAP_SIZE; 243 int size = PIXMAP_SIZE;
244 if ( QApplication::desktop()->width() < 300 ) 244 if ( QApplication::desktop()->width() < 300 )
245 size = 3; 245 size = 3;
246 int heihei = height( listBox () ); 246 int heihei = height( listBox () );
247 int y = (heihei - size -1 ) /2; 247 int y = (heihei - size -1 ) /2;
248 248
249 if ( KOPrefs::instance()->mMonthShowIcons ) { 249 if ( KOPrefs::instance()->mMonthShowIcons ) {
250 if ( mInfo ) { 250 if ( mInfo ) {
251 p->fillRect ( x, y,size,size, Qt::darkGreen ); 251 p->fillRect ( x, y,size,size, Qt::darkGreen );
252 x += size + 1; 252 x += size + 1;
253 } 253 }
254 if ( mRecur ) { 254 if ( mRecur ) {
255 p->fillRect ( x, y,size,size, Qt::blue ); 255 p->fillRect ( x, y,size,size, Qt::blue );
256 x += size + 1; 256 x += size + 1;
257 } 257 }
258 if ( mAlarm ) { 258 if ( mAlarm ) {
259 p->fillRect ( x, y,size,size, Qt::red ); 259 p->fillRect ( x, y,size,size, Qt::red );
260 x += size + 1; 260 x += size + 1;
261 } 261 }
262 if ( mReply ) { 262 if ( mReply ) {
263 p->fillRect ( x, y,size,size, Qt::yellow ); 263 p->fillRect ( x, y,size,size, Qt::yellow );
264 x += size + 1; 264 x += size + 1;
265 } 265 }
266 } 266 }
267 if ( mMultiday ) { 267 if ( mMultiday ) {
268 int yyy = y+(size/2); 268 int yyy = y+(size/2);
269 int sizeM = size+2; 269 int sizeM = size+2;
270 p->setBrush( QBrush::SolidPattern ); 270 p->setBrush( QBrush::SolidPattern );
271 p->drawLine ( x+1, yyy, x +sizeM +sizeM/2-1, yyy ) ; 271 p->drawLine ( x+1, yyy, x +sizeM +sizeM/2-1, yyy ) ;
272 if ( mMultiday == 2 || mMultiday == 3 ) { 272 if ( mMultiday == 2 || mMultiday == 3 ) {
273 QPointArray pa ( 3 ); 273 QPointArray pa ( 3 );
274 pa.setPoint (0, x, yyy ); 274 pa.setPoint (0, x, yyy );
275 pa.setPoint (1, x+sizeM/2, yyy+sizeM/2 ); 275 pa.setPoint (1, x+sizeM/2, yyy+sizeM/2 );
276 pa.setPoint (2, x+sizeM/2, yyy-sizeM/2 ); 276 pa.setPoint (2, x+sizeM/2, yyy-sizeM/2 );
277 p->drawPolygon( pa ); 277 p->drawPolygon( pa );
278 } 278 }
279 if ( mMultiday == 2 || mMultiday == 1 ) { 279 if ( mMultiday == 2 || mMultiday == 1 ) {
280 QPointArray pa ( 3 ); 280 QPointArray pa ( 3 );
281 pa.setPoint (0, x+sizeM +sizeM/2, yyy ); 281 pa.setPoint (0, x+sizeM +sizeM/2, yyy );
282 pa.setPoint (1, x+sizeM, yyy+sizeM/2 ); 282 pa.setPoint (1, x+sizeM, yyy+sizeM/2 );
283 pa.setPoint (2, x+sizeM, yyy-sizeM/2 ); 283 pa.setPoint (2, x+sizeM, yyy-sizeM/2 );
284 p->drawPolygon( pa ); 284 p->drawPolygon( pa );
285 } 285 }
286 if ( mMultiday == 1 ) { 286 if ( mMultiday == 1 ) {
287 // p->fillRect ( x, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); 287 // p->fillRect ( x, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) );
288 288
289 p->drawLine ( x+1, yyy-sizeM/2, x+1, yyy+sizeM/2 ); 289 p->drawLine ( x+1, yyy-sizeM/2, x+1, yyy+sizeM/2 );
290 } 290 }
291 if ( mMultiday == 3 ) { 291 if ( mMultiday == 3 ) {
292 // p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); 292 // p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) );
293 p->drawLine ( x+sizeM +sizeM/2-1, yyy-sizeM/2, x+sizeM +sizeM/2-1, yyy+sizeM/2 ); 293 p->drawLine ( x+sizeM +sizeM/2-1, yyy-sizeM/2, x+sizeM +sizeM/2-1, yyy+sizeM/2 );
294 294
295 } 295 }
296 x += sizeM/2 + 1; 296 x += sizeM/2 + 1;
297 x += sizeM + 1; 297 x += sizeM + 1;
298 } 298 }
299 299
300 if ( mIncidence->type() == "Todo" ){ 300 if ( mIncidence->type() == "Todo" ){
301 Todo* td = ( Todo* ) mIncidence; 301 Todo* td = ( Todo* ) mIncidence;
302 if ( td->isCompleted() ) { 302 if ( td->isCompleted() ) {
303 int half = size/2; 303 int half = size/2;
304 p->drawLine ( x, heihei/2, x +half , heihei/2 +half ) ; 304 p->drawLine ( x, heihei/2, x +half , heihei/2 +half ) ;
305 p->drawLine ( x +half , heihei/2 +half , x +half+half +2 , heihei/2 -2 ) ; 305 p->drawLine ( x +half , heihei/2 +half , x +half+half +2 , heihei/2 -2 ) ;
306 x += half+half + 4; 306 x += half+half + 4;
307 307
308 } else { 308 } else {
309 int val = td->percentComplete()/20; 309 int val = td->percentComplete()/20;
310 p->fillRect ( x+1, y-1, val ,size+2,Qt::black ); 310 p->fillRect ( x+1, y-1, val ,size+2,Qt::black );
311 p->drawRect ( x, y-1,7,size+2); 311 p->drawRect ( x, y-1,7,size+2);
312 x += size + 3; 312 x += size + 3;
313 } 313 }
314 } 314 }
315 QFontMetrics fm = p->fontMetrics(); 315 QFontMetrics fm = p->fontMetrics();
316 int yPos; 316 int yPos;
317 int pmheight = size; 317 int pmheight = size;
318 if( pmheight < fm.height() ) 318 if( pmheight < fm.height() )
319 yPos = fm.ascent() + fm.leading()/2; 319 yPos = fm.ascent() + fm.leading()/2;
320 else 320 else
321 yPos = pmheight/2 - fm.height()/2 + fm.ascent(); 321 yPos = pmheight/2 - fm.height()/2 + fm.ascent();
322 p->setPen( palette().color( QPalette::Normal, sel ? \ 322 p->setPen( palette().color( QPalette::Normal, sel ? \
323 QColorGroup::HighlightedText : QColorGroup::Foreground ) ); 323 QColorGroup::HighlightedText : QColorGroup::Foreground ) );
324 p->drawText( x, yPos, text() ); 324 p->drawText( x, yPos, text() );
325 if ( mIncidence->cancelled() ) { 325 if ( mIncidence->cancelled() ) {
326 int wid = fm.width( text() ); 326 int wid = fm.width( text() );
327 p->drawLine( x, heihei/2-1 ,x+wid, heihei/2-1 ); 327 p->drawLine( x, heihei/2-1 ,x+wid, heihei/2-1 );
328 } 328 }
329 329
330} 330}
331 331
332int MonthViewItem::height(const QListBox *lb) const 332int MonthViewItem::height(const QListBox *lb) const
333{ 333{
334 int ret = 10; 334 int ret = 10;
335 if ( lb ) 335 if ( lb )
336 ret = lb->fontMetrics().lineSpacing()+1; 336 ret = lb->fontMetrics().lineSpacing()+1;
337 return ret; 337 return ret;
338} 338}
339 339
340int MonthViewItem::width(const QListBox *lb) const 340int MonthViewItem::width(const QListBox *lb) const
341{ 341{
342 342
343 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) { 343 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) {
344 int size = PIXMAP_SIZE; 344 int size = PIXMAP_SIZE;
345 if ( QApplication::desktop()->width() < 300 ) 345 if ( QApplication::desktop()->width() < 300 )
346 size = 3; 346 size = 3;
347 int x = 1; 347 int x = 1;
348 if ( KOPrefs::instance()->mMonthShowIcons ) { 348 if ( KOPrefs::instance()->mMonthShowIcons ) {
349 if ( mInfo ) { 349 if ( mInfo ) {
350 x += size + 1; 350 x += size + 1;
351 } 351 }
352 if( mRecur ) { 352 if( mRecur ) {
353 x += size+1; 353 x += size+1;
354 } 354 }
355 if( mAlarm ) { 355 if( mAlarm ) {
356 x += size+1; 356 x += size+1;
357 } 357 }
358 if( mReply ) { 358 if( mReply ) {
359 x += size+1; 359 x += size+1;
360 } 360 }
361 } 361 }
362 if( mMultiday ) { 362 if( mMultiday ) {
363 x += size+1+2+size/2; 363 x += size+1+2+size/2;
364 } 364 }
365 return( x + lb->fontMetrics().width( text() ) + 1 ); 365 return( x + lb->fontMetrics().width( text() ) + 1 );
366 } 366 }
367 if ( ! lb ) 367 if ( ! lb )
368 return 10; 368 return 10;
369 //qDebug("ret wid %d ", lb->width()); 369 //qDebug("ret wid %d ", lb->width());
370 return lb->width(); 370 return lb->width();
371} 371}
372 372
373 373
374MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) 374MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par )
375 : KNoScrollListBox( par ), 375 : KNoScrollListBox( par ),
376 mMonthView( parent ) 376 mMonthView( parent )
377{ 377{
378 378
379 mCurrentAvailItem = 0; 379 mCurrentAvailItem = 0;
380 //QVBoxLayout *topLayout = new QVBoxLayout( this ); 380 //QVBoxLayout *topLayout = new QVBoxLayout( this );
381 currentPalette = 0; 381 currentPalette = 0;
382 // mLabel = new QLabel( this );QPushButton 382 // mLabel = new QLabel( this );QPushButton
383 mLabel = new QPushButton( this ); 383 mLabel = new QPushButton( this );
384 //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); 384 //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain );
385 //mLabel->setLineWidth( 1 ); 385 //mLabel->setLineWidth( 1 );
386 //mLabel->setAlignment( AlignCenter ); 386 //mLabel->setAlignment( AlignCenter );
387 mLabel->setFlat( true ); 387 mLabel->setFlat( true );
388 mLabel->setFocusPolicy(NoFocus); 388 mLabel->setFocusPolicy(NoFocus);
389 //mItemList = new KNoScrollListBox( this ); 389 //mItemList = new KNoScrollListBox( this );
390 setMinimumSize( 10, 10 ); 390 setMinimumSize( 10, 10 );
391 setFrameStyle( QFrame::Panel | QFrame::Plain ); 391 setFrameStyle( QFrame::Panel | QFrame::Plain );
392 setLineWidth( 1 ); 392 setLineWidth( 1 );
393 //topLayout->addWidget( mItemList ); 393 //topLayout->addWidget( mItemList );
394 mLabel->raise(); 394 mLabel->raise();
395 // QColor( 0,0,255 ) QColor( 160,1600,255 ) 395 // QColor( 0,0,255 ) QColor( 160,1600,255 )
396 mStandardPalette = palette(); 396 mStandardPalette = palette();
397 mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); 397 mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) );
398 398
399 enableScrollBars( false ); 399 enableScrollBars( false );
400 updateConfig(); 400 updateConfig();
401 //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() )); 401 //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() ));
402 connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() )); 402 connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() ));
403 connect( this , SIGNAL( doubleClicked( QListBoxItem *) ), 403 connect( this , SIGNAL( doubleClicked( QListBoxItem *) ),
404 SLOT( defaultAction( QListBoxItem * ) ) ); 404 SLOT( defaultAction( QListBoxItem * ) ) );
405 connect( this, SIGNAL( rightButtonPressed( QListBoxItem *, 405 connect( this, SIGNAL( rightButtonPressed( QListBoxItem *,
406 const QPoint &) ), 406 const QPoint &) ),
407 SLOT( contextMenu( QListBoxItem * ) ) ); 407 SLOT( contextMenu( QListBoxItem * ) ) );
408 connect( this, SIGNAL( highlighted( QListBoxItem *) ), 408 connect( this, SIGNAL( highlighted( QListBoxItem *) ),
409 SLOT( selection( QListBoxItem * ) ) ); 409 SLOT( selection( QListBoxItem * ) ) );
410 connect( this, SIGNAL( clicked( QListBoxItem * ) ), 410 connect( this, SIGNAL( clicked( QListBoxItem * ) ),
411 SLOT( cellClicked( QListBoxItem * ) ) ); 411 SLOT( cellClicked( QListBoxItem * ) ) );
412 connect( this, SIGNAL( clicked( QListBoxItem * ) ), 412 connect( this, SIGNAL( clicked( QListBoxItem * ) ),
413 SLOT( selection( QListBoxItem * ) ) ); 413 SLOT( selection( QListBoxItem * ) ) );
414} 414}
415#ifdef DESKTOP_VERSION 415#ifdef DESKTOP_VERSION
416QToolTipGroup *MonthViewCell::toolTipGroup() 416QToolTipGroup *MonthViewCell::toolTipGroup()
417{ 417{
418 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); 418 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0);
419 return mToolTipGroup; 419 return mToolTipGroup;
420} 420}
421#endif 421#endif
422 422
423void MonthViewCell::setDate( const QDate &date ) 423void MonthViewCell::setDate( const QDate &date )
424{ 424{
425 // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl; 425 // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl;
426 mDate = date; 426 mDate = date;
427 427
428 428
429 429
430 //resizeEvent( 0 ); 430 //resizeEvent( 0 );
431} 431}
432 432
433QDate MonthViewCell::date() const 433QDate MonthViewCell::date() const
434{ 434{
435 return mDate; 435 return mDate;
436} 436}
437 437
438void MonthViewCell::setPrimary( bool primary ) 438void MonthViewCell::setPrimary( bool primary )
439{ 439{
440 mPrimary = primary; 440 mPrimary = primary;
441 //setMyPalette(); 441 //setMyPalette();
442} 442}
443void MonthViewCell::setMyPalette() 443void MonthViewCell::setMyPalette()
444{ 444{
445 445
446 if ( mHoliday) { 446 if ( mHoliday) {
447 if ( currentPalette == 1 ) return; 447 if ( currentPalette == 1 ) return;
448 mLabel->setPalette( QPalette ( mHolidayPalette.color( QPalette::Normal,QColorGroup::Base),mHolidayPalette.color(QPalette::Normal,QColorGroup::Base ) )); 448 mLabel->setPalette( QPalette ( mHolidayPalette.color( QPalette::Normal,QColorGroup::Base),mHolidayPalette.color(QPalette::Normal,QColorGroup::Base ) ));
449 setPalette( mHolidayPalette ); 449 setPalette( mHolidayPalette );
450 //mLabel->setPalette( mHolidayPalette ); 450 //mLabel->setPalette( mHolidayPalette );
451 currentPalette = 1; 451 currentPalette = 1;
452 452
453 } else { 453 } else {
454 if ( mPrimary ) { 454 if ( mPrimary ) {
455 if ( currentPalette == 2 ) return; 455 if ( currentPalette == 2 ) return;
456 mLabel->setPalette( QPalette ( mPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); 456 mLabel->setPalette( QPalette ( mPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) ));
457 //mLabel->setPalette( mPrimaryPalette ); 457 //mLabel->setPalette( mPrimaryPalette );
458 setPalette( mPrimaryPalette ); 458 setPalette( mPrimaryPalette );
459 currentPalette = 2; 459 currentPalette = 2;
460 460
461 } else { 461 } else {
462 if ( currentPalette == 3 ) return; 462 if ( currentPalette == 3 ) return;
463 setPalette( mNonPrimaryPalette ); 463 setPalette( mNonPrimaryPalette );
464 mLabel->setPalette( QPalette ( mNonPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mNonPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); 464 mLabel->setPalette( QPalette ( mNonPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mNonPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) ));
465 //mLabel->setPalette( mNonPrimaryPalette );; 465 //mLabel->setPalette( mNonPrimaryPalette );;
466 currentPalette = 3; 466 currentPalette = 3;
467 } 467 }
468 } 468 }
469 //QPalette pal = palette(); 469 //QPalette pal = palette();
470 470
471 //mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) )); 471 //mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) ));
472} 472}
473QPalette MonthViewCell::getPalette () 473QPalette MonthViewCell::getPalette ()
474{ 474{
475 if ( !KOPrefs::instance()->mMonthViewUsesDayColors ) 475 if ( !KOPrefs::instance()->mMonthViewUsesDayColors )
476 return mStandardPalette; 476 return mStandardPalette;
477 if ( mHoliday) { 477 if ( mHoliday) {
478 return mHolidayPalette ; 478 return mHolidayPalette ;
479 } else { 479 } else {
480 if ( mPrimary ) { 480 if ( mPrimary ) {
481 return mPrimaryPalette ; 481 return mPrimaryPalette ;
482 } 482 }
483 } 483 }
484 return mNonPrimaryPalette; 484 return mNonPrimaryPalette;
485} 485}
486bool MonthViewCell::isPrimary() const 486bool MonthViewCell::isPrimary() const
487{ 487{
488 return mPrimary; 488 return mPrimary;
489} 489}
490 490
491void MonthViewCell::setHoliday( bool holiday ) 491void MonthViewCell::setHoliday( bool holiday )
492{ 492{
493 mHoliday = holiday; 493 mHoliday = holiday;
494 //setMyPalette(); 494 //setMyPalette();
495} 495}
496 496
497void MonthViewCell::setHoliday( const QString &holiday ) 497void MonthViewCell::setHoliday( const QString &holiday )
498{ 498{
499 mHolidayString = holiday; 499 mHolidayString = holiday;
500 500
501 if ( !holiday.isEmpty() ) { 501 if ( !holiday.isEmpty() ) {
502 setHoliday( true ); 502 setHoliday( true );
503 } 503 }
504} 504}
505 505
506void MonthViewCell::startUpdateCell() 506void MonthViewCell::startUpdateCell()
507{ 507{
508 508
509 setFocusPolicy(NoFocus); 509 setFocusPolicy(NoFocus);
510 if ( !mMonthView->isUpdatePossible() ) 510 if ( !mMonthView->isUpdatePossible() )
511 return; 511 return;
512 MonthViewItem *mitem = (MonthViewItem*) firstItem (); 512 MonthViewItem *mitem = (MonthViewItem*) firstItem ();
513 while ( mitem ) { 513 while ( mitem ) {
514 mitem->setBlockRepaint( true ); 514 mitem->setBlockRepaint( true );
515 mitem = (MonthViewItem *)mitem->next(); 515 mitem = (MonthViewItem *)mitem->next();
516 } 516 }
517 if ( mAvailItemList.count() > 20 ) {
518 mAvailItemList.setAutoDelete( true );
519 mAvailItemList.clear();
520 mAvailItemList.setAutoDelete( false );
521 }
517 /* 522 /*
518 if ( !isVisible() ){ 523 if ( !isVisible() ){
519 return; 524 return;
520 } 525 }
521 */ 526 */
522 // qDebug("MonthViewCell::updateCell() "); 527 // qDebug("MonthViewCell::updateCell() ");
523 setPrimary( mDate.month()%2 ); 528 setPrimary( mDate.month()%2 );
524 setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays); 529 setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays);
525 if ( mDate == QDate::currentDate() ) { 530 if ( mDate == QDate::currentDate() ) {
526 setLineWidth( 3 ); 531 setLineWidth( 3 );
527 } else { 532 } else {
528 setLineWidth( 1 ); 533 setLineWidth( 1 );
529 } 534 }
530 mCurrentAvailItem = (MonthViewItem*) firstItem (); 535 mCurrentAvailItem = (MonthViewItem*) firstItem ();
531 //clear(); 536 //clear();
532 537
533#ifdef DESKTOP_VERSION 538#ifdef DESKTOP_VERSION
534 QToolTip::remove(this); 539 QToolTip::remove(this);
535#endif 540#endif
536 mToolTip.clear(); 541 mToolTip.clear();
537 //qApp->processEvents(); 542 //qApp->processEvents();
538#if 0 543#if 0
539 if ( !mHolidayString.isEmpty() ) { 544 if ( !mHolidayString.isEmpty() ) {
540 MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); 545 MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString );
541 item->setPalette( mHolidayPalette ); 546 item->setPalette( mHolidayPalette );
542 insertItem( item ); 547 insertItem( item );
543 mToolTip.append ( mHolidayString ); 548 mToolTip.append ( mHolidayString );
544 } 549 }
545#endif 550#endif
546} 551}
547 552
548void MonthViewCell::insertEvent(Event *event) 553void MonthViewCell::insertEvent(Event *event)
549{ 554{
550 QString mToolTipText; 555 QString mToolTipText;
551 bool insertNewItem = false; 556 bool insertNewItem = false;
552 setFocusPolicy(WheelFocus); 557 setFocusPolicy(WheelFocus);
553 if ( !(event->doesRecur() == Recurrence::rNone) ) { 558 if ( !(event->doesRecur() == Recurrence::rNone) ) {
554 if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) 559 if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily )
555 return; 560 return;
556 else 561 else
557 if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) 562 if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly )
558 return; 563 return;
559 } 564 }
560 565
561 if ( event->isHoliday()) { 566 if ( event->isHoliday()) {
562 setHoliday( true ); 567 setHoliday( true );
563 if ( mDate.dayOfWeek() == 7 ) 568 if ( mDate.dayOfWeek() == 7 )
564 setLineWidth( 3 ); 569 setLineWidth( 3 );
565 } 570 }
566 QString text; 571 QString text;
567 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day 572 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
568 if (event->isMultiDay()) { 573 if (event->isMultiDay()) {
569 QString prefix = "<->";multiday = 2; 574 QString prefix = "<->";multiday = 2;
570 QString time; 575 QString time;
571 if ( event->doesRecur() ) { 576 if ( event->doesRecur() ) {
572 if ( event->recursOn( mDate) ) { 577 if ( event->recursOn( mDate) ) {
573 prefix ="->" ;multiday = 1; 578 prefix ="->" ;multiday = 1;
574 } 579 }
575 else { 580 else {
576 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 581 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
577 if ( event->recursOn( mDate.addDays( -days)) ) { 582 if ( event->recursOn( mDate.addDays( -days)) ) {
578 prefix ="<-" ;multiday = 3; 583 prefix ="<-" ;multiday = 3;
579 } 584 }
580 } 585 }
581 586
582 } else { 587 } else {
583 if (mDate == event->dtStart().date()) { 588 if (mDate == event->dtStart().date()) {
584 prefix ="->" ;multiday = 1; 589 prefix ="->" ;multiday = 1;
585 } else if (mDate == event->dtEnd().date()) { 590 } else if (mDate == event->dtEnd().date()) {
586 prefix ="<-" ;multiday = 3; 591 prefix ="<-" ;multiday = 3;
587 } 592 }
588 } 593 }
589 if ( !event->doesFloat() ) { 594 if ( !event->doesFloat() ) {
590 if ( mDate == event->dtStart().date () ) 595 if ( mDate == event->dtStart().date () )
591 time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; 596 time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
592 else if ( mDate == event->dtEnd().date () ) 597 else if ( mDate == event->dtEnd().date () )
593 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 598 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
594 599
595 } 600 }
596 text = time + event->summary(); 601 text = time + event->summary();
597 mToolTipText += prefix + text; 602 mToolTipText += prefix + text;
598 } else { 603 } else {
599 if (event->doesFloat()) { 604 if (event->doesFloat()) {
600 text = event->summary(); 605 text = event->summary();
601 mToolTipText += text; 606 mToolTipText += text;
602 } 607 }
603 else { 608 else {
604 text = KGlobal::locale()->formatTime(event->dtStart().time()); 609 text = KGlobal::locale()->formatTime(event->dtStart().time());
605 text += " " + event->summary(); 610 text += " " + event->summary();
606 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 611 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
607 } 612 }
608 } 613 }
609 MonthViewItem *item ; 614 MonthViewItem *item ;
610 if ( mCurrentAvailItem ) { 615 if ( mCurrentAvailItem ) {
611 item = mCurrentAvailItem; 616 item = mCurrentAvailItem;
612 mCurrentAvailItem = (MonthViewItem*) item->next(); 617 mCurrentAvailItem = (MonthViewItem*) item->next();
613 item->recycle( event, mDate, text ); 618 item->recycle( event, mDate, text );
614 } else { 619 } else {
615 if ( mAvailItemList.count() ) { 620 if ( mAvailItemList.count() ) {
616 item = mAvailItemList.first(); 621 item = mAvailItemList.first();
617 mAvailItemList.remove( item ); 622 mAvailItemList.remove( item );
618 item->recycle( event, mDate, text ); 623 item->recycle( event, mDate, text );
619 insertNewItem = true; 624 insertNewItem = true;
620 } else { 625 } else {
621 insertNewItem = true; 626 insertNewItem = true;
622 item = new MonthViewItem( event, mDate, text ); 627 item = new MonthViewItem( event, mDate, text );
623 } 628 }
624 } 629 }
625 QPalette pal; 630 QPalette pal;
626 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { 631 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
627 QStringList categories = event->categories(); 632 QStringList categories = event->categories();
628 QString cat = categories.first(); 633 QString cat = categories.first();
629 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { 634 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
630 pal = getPalette(); 635 pal = getPalette();
631 if (cat.isEmpty()) { 636 if (cat.isEmpty()) {
632 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); 637 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
633 } else { 638 } else {
634 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); 639 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
635 } 640 }
636 641
637 } else { 642 } else {
638 if (cat.isEmpty()) { 643 if (cat.isEmpty()) {
639 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); 644 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
640 } else { 645 } else {
641 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); 646 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
642 } 647 }
643 } 648 }
644 649
645 } else { 650 } else {
646 pal = mStandardPalette ; 651 pal = mStandardPalette ;
647 } 652 }
648 item->setPalette( pal ); 653 item->setPalette( pal );
649 item->setRecur( event->recurrence()->doesRecur() ); 654 item->setRecur( event->recurrence()->doesRecur() );
650 item->setAlarm( event->isAlarmEnabled() && multiday < 2 ); 655 item->setAlarm( event->isAlarmEnabled() && multiday < 2 );
651 item->setMoreInfo( event->description().length() > 0 ); 656 item->setMoreInfo( event->description().length() > 0 );
652#ifdef DESKTOP_VERSION 657#ifdef DESKTOP_VERSION
653 Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, 658 Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails,
654 KOPrefs::instance()->email()); 659 KOPrefs::instance()->email());
655 if ( me != 0 ) { 660 if ( me != 0 ) {
656 if ( me->status() == Attendee::NeedsAction && me->RSVP()) 661 if ( me->status() == Attendee::NeedsAction && me->RSVP())
657 item->setReply(true && multiday < 2); 662 item->setReply(true && multiday < 2);
658 else 663 else
659 item->setReply(false); 664 item->setReply(false);
660 } else 665 } else
661 item->setReply(false); 666 item->setReply(false);
662#endif 667#endif
663 item->setMultiDay( multiday ); 668 item->setMultiDay( multiday );
664 if ( insertNewItem) 669 if ( insertNewItem)
665 insertItem( item ); 670 insertItem( item );
666 mToolTip.append( mToolTipText ); 671 mToolTip.append( mToolTipText );
667} 672}
668void MonthViewCell::insertTodo(Todo *todo) 673void MonthViewCell::insertTodo(Todo *todo)
669{ 674{
670 bool insertNewItem = false; 675 bool insertNewItem = false;
671 setFocusPolicy(WheelFocus); 676 setFocusPolicy(WheelFocus);
672 QString text; 677 QString text;
673 if (todo->hasDueDate()) { 678 if (todo->hasDueDate()) {
674 if (!todo->doesFloat()) { 679 if (!todo->doesFloat()) {
675 text += KGlobal::locale()->formatTime(todo->dtDue().time()); 680 text += KGlobal::locale()->formatTime(todo->dtDue().time());
676 text += " "; 681 text += " ";
677 } 682 }
678 } 683 }
679 text += todo->summary(); 684 text += todo->summary();
680 MonthViewItem *item ; 685 MonthViewItem *item ;
681 if ( mCurrentAvailItem ) { 686 if ( mCurrentAvailItem ) {
682 item = mCurrentAvailItem; 687 item = mCurrentAvailItem;
683 mCurrentAvailItem = (MonthViewItem*) item->next(); 688 mCurrentAvailItem = (MonthViewItem*) item->next();
684 item->recycle( todo, mDate, text ); 689 item->recycle( todo, mDate, text );
685 } else { 690 } else {
686 if ( mAvailItemList.count() ) { 691 if ( mAvailItemList.count() ) {
687 item = mAvailItemList.first(); 692 item = mAvailItemList.first();
688 mAvailItemList.remove( item ); 693 mAvailItemList.remove( item );
689 item->recycle( todo, mDate, text ); 694 item->recycle( todo, mDate, text );
690 insertNewItem = true; 695 insertNewItem = true;
691 } else { 696 } else {
692 insertNewItem = true; 697 insertNewItem = true;
693 item = new MonthViewItem( todo, mDate, text ); 698 item = new MonthViewItem( todo, mDate, text );
694 } 699 }
695 } 700 }
696 //MonthViewItem *item = new MonthViewItem( todo, mDate, text ); 701 //MonthViewItem *item = new MonthViewItem( todo, mDate, text );
697 //item->setPalette( mStandardPalette ); 702 //item->setPalette( mStandardPalette );
698 QPalette pal; 703 QPalette pal;
699 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { 704 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
700 QStringList categories = todo->categories(); 705 QStringList categories = todo->categories();
701 QString cat = categories.first(); 706 QString cat = categories.first();
702 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { 707 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
703 pal = getPalette(); 708 pal = getPalette();
704 if (cat.isEmpty()) { 709 if (cat.isEmpty()) {
705 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); 710 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
706 } else { 711 } else {
707 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); 712 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
708 } 713 }
709 714
710 } else { 715 } else {
711 if (cat.isEmpty()) { 716 if (cat.isEmpty()) {
712 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); 717 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
713 } else { 718 } else {
714 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); 719 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
715 } 720 }
716 } 721 }
717 722
718 } else { 723 } else {
719 pal = mStandardPalette ; 724 pal = mStandardPalette ;
720 } 725 }
721 item->setPalette( pal ); 726 item->setPalette( pal );
722 item->setRecur( todo->recurrence()->doesRecur() ); 727 item->setRecur( todo->recurrence()->doesRecur() );
723 item->setAlarm( todo->isAlarmEnabled() ); 728 item->setAlarm( todo->isAlarmEnabled() );
724 item->setMoreInfo( todo->description().length() > 0 ); 729 item->setMoreInfo( todo->description().length() > 0 );
725 if ( insertNewItem) 730 if ( insertNewItem)
726 insertItem( item ); 731 insertItem( item );
727 mToolTip.append( text ); 732 mToolTip.append( text );
728} 733}
729void MonthViewCell::repaintfinishUpdateCell() 734void MonthViewCell::repaintfinishUpdateCell()
730{ 735{
731 MonthViewItem *mitem = (MonthViewItem*) firstItem (); 736 MonthViewItem *mitem = (MonthViewItem*) firstItem ();
732 while ( mitem ) { 737 while ( mitem ) {
733 mitem->setBlockRepaint( false ); 738 mitem->setBlockRepaint( false );
734 updateItem ( mitem ); 739 updateItem ( mitem );
735 mitem = (MonthViewItem *)mitem->next(); 740 mitem = (MonthViewItem *)mitem->next();
736 } 741 }
737} 742}
738void MonthViewCell::finishUpdateCell() 743void MonthViewCell::finishUpdateCell()
739{ 744{
740 while ( mCurrentAvailItem ) { 745 while ( mCurrentAvailItem ) {
741 MonthViewItem *item = mCurrentAvailItem; 746 MonthViewItem *item = mCurrentAvailItem;
742 mCurrentAvailItem = (MonthViewItem *)item->next(); 747 mCurrentAvailItem = (MonthViewItem *)item->next();
743 mAvailItemList.append( item ); 748 mAvailItemList.append( item );
744 takeItem ( item ); 749 takeItem ( item );
745 } 750 }
746 751
747 752
748#ifdef DESKTOP_VERSION 753#ifdef DESKTOP_VERSION
749 if (mToolTip.count() > 0 ) { 754 if (mToolTip.count() > 0 ) {
750 mToolTip.sort(); 755 mToolTip.sort();
751 QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),""); 756 QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),"");
752 } 757 }
753#endif 758#endif
754 sort(); 759 sort();
755 //setMyPalette(); 760 //setMyPalette();
756 setMyPalette(); 761 setMyPalette();
757 762
758 resizeEvent( 0 ); 763 resizeEvent( 0 );
759 764
760} 765}
761void MonthViewCell::updateCell() 766void MonthViewCell::updateCell()
762{ 767{
763 //qDebug("MonthViewCell::updateCell() "); 768 //qDebug("MonthViewCell::updateCell() ");
764 if ( !mMonthView->isUpdatePossible() ) 769 if ( !mMonthView->isUpdatePossible() )
765 return; 770 return;
766 startUpdateCell(); 771 startUpdateCell();
767 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 772 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
768 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); 773 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true );
769 Event *event; 774 Event *event;
770 for( event = events.first(); event; event = events.next() ) { // for event 775 for( event = events.first(); event; event = events.next() ) { // for event
771 insertEvent(event); 776 insertEvent(event);
772 } 777 }
773 // insert due todos 778 // insert due todos
774 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); 779 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate );
775 Todo *todo; 780 Todo *todo;
776 for(todo = todos.first(); todo; todo = todos.next()) { 781 for(todo = todos.first(); todo; todo = todos.next()) {
777 insertTodo( todo ); 782 insertTodo( todo );
778 } 783 }
779 finishUpdateCell(); 784 finishUpdateCell();
780 // if ( isVisible()) 785 // if ( isVisible())
781 //qApp->processEvents(); 786 //qApp->processEvents();
782} 787}
783 788
784void MonthViewCell::updateConfig( bool bigFont ) // = false 789void MonthViewCell::updateConfig( bool bigFont ) // = false
785{ 790{
786 791
787 if ( bigFont ) { 792 if ( bigFont ) {
788 QFont fo = KOPrefs::instance()->mMonthViewFont; 793 QFont fo = KOPrefs::instance()->mMonthViewFont;
789 int ps = fo.pointSize() + 2; 794 int ps = fo.pointSize() + 2;
790 if ( ps < 18 ) 795 if ( ps < 18 )
791 ps += 2; 796 ps += 2;
792 fo.setPointSize( ps ); 797 fo.setPointSize( ps );
793 setFont( fo ); 798 setFont( fo );
794 } else 799 } else
795 setFont( KOPrefs::instance()->mMonthViewFont ); 800 setFont( KOPrefs::instance()->mMonthViewFont );
796 801
797 QFontMetrics fm( font() ); 802 QFontMetrics fm( font() );
798 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); 803 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 );
799 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); 804 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 );
800 mHolidayPalette = mStandardPalette; 805 mHolidayPalette = mStandardPalette;
801 mPrimaryPalette = mStandardPalette; 806 mPrimaryPalette = mStandardPalette;
802 mNonPrimaryPalette = mStandardPalette; 807 mNonPrimaryPalette = mStandardPalette;
803 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { 808 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) {
804 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); 809 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor );
805 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); 810 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor );
806 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); 811 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark());
807 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); 812 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark());
808 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); 813 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor);
809 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); 814 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor);
810 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); 815 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark());
811 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); 816 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor);
812 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); 817 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor);
813 } 818 }
814 //updateCell(); 819 //updateCell();
815} 820}
816 821
817void MonthViewCell::enableScrollBars( bool enabled ) 822void MonthViewCell::enableScrollBars( bool enabled )
818{ 823{
819 if ( enabled ) { 824 if ( enabled ) {
820
821 QListBoxItem *fi = firstItem (); 825 QListBoxItem *fi = firstItem ();
822 if (fi ) { 826 if (fi ) {
823 int ihei = fi->height( this ); 827 int ihei = fi->height( this );
824 int hei = numRows () * ihei; 828 int hei = numRows () * ihei;
825 if ( hei < height() - horizontalScrollBar()->height () ) 829 if ( hei < height() - horizontalScrollBar()->height () ) {
826 setVScrollBarMode(QScrollView::AlwaysOff); 830 setVScrollBarMode(QScrollView::AlwaysOff);
827 else 831 }
832 else
828 setVScrollBarMode(QScrollView::Auto); 833 setVScrollBarMode(QScrollView::Auto);
829 if ( ihei *3 > height() ) 834 if ( ihei *3 > height() )
830 setHScrollBarMode(QScrollView::AlwaysOff); 835 setHScrollBarMode(QScrollView::AlwaysOff);
831 else 836 else
832 setHScrollBarMode(QScrollView::Auto); 837 setHScrollBarMode(QScrollView::Auto);
833 } else { 838 } else {
834 setVScrollBarMode(QScrollView::Auto); 839 setVScrollBarMode(QScrollView::Auto);
835 setHScrollBarMode(QScrollView::Auto); 840 setHScrollBarMode(QScrollView::Auto);
836 } 841 }
837 } else { 842 } else {
838 setVScrollBarMode(QScrollView::AlwaysOff); 843 setVScrollBarMode(QScrollView::AlwaysOff);
839 setHScrollBarMode(QScrollView::AlwaysOff); 844 setHScrollBarMode(QScrollView::AlwaysOff);
840 } 845 }
841} 846}
842 847
843Incidence *MonthViewCell::selectedIncidence() 848Incidence *MonthViewCell::selectedIncidence()
844{ 849{
845 int index = currentItem(); 850 int index = currentItem();
846 if ( index < 0 ) return 0; 851 if ( index < 0 ) return 0;
847 852
848 MonthViewItem *mitem = 853 MonthViewItem *mitem =
849 static_cast<MonthViewItem *>( item( index ) ); 854 static_cast<MonthViewItem *>( item( index ) );
850 855
851 if ( !mitem ) return 0; 856 if ( !mitem ) return 0;
852 857
853 return mitem->incidence(); 858 return mitem->incidence();
854} 859}
855 860
856QDate MonthViewCell::selectedIncidenceDate() 861QDate MonthViewCell::selectedIncidenceDate()
857{ 862{
858 QDate qd; 863 QDate qd;
859 int index = currentItem(); 864 int index = currentItem();
860 if ( index < 0 ) return qd; 865 if ( index < 0 ) return qd;
861 866
862 MonthViewItem *mitem = 867 MonthViewItem *mitem =
863 static_cast<MonthViewItem *>( item( index ) ); 868 static_cast<MonthViewItem *>( item( index ) );
864 869
865 if ( !mitem ) return qd; 870 if ( !mitem ) return qd;
866 871
867 return mitem->incidenceDate(); 872 return mitem->incidenceDate();
868} 873}
869 874
870void MonthViewCell::deselect() 875void MonthViewCell::deselect()
871{ 876{
872 clearSelection(); 877 clearSelection();
873 enableScrollBars( false ); 878 enableScrollBars( false );
874 // updateCell(); 879 // updateCell();
875} 880}
876void MonthViewCell::select() 881void MonthViewCell::select()
877{ 882{
878 ;// updateCell(); 883 ;// updateCell();
879} 884}
880 885
881void MonthViewCell::resizeEvent ( QResizeEvent * e ) 886void MonthViewCell::resizeEvent ( QResizeEvent * e )
882{ 887{
883 if ( !mMonthView->isUpdatePossible() ) 888 if ( !mMonthView->isUpdatePossible() )
884 return; 889 return;
885 //qDebug("++++++++++++++MonthViewCell::resizeEvent %d %d ", width(), height()); 890 //qDebug("++++++++++++++MonthViewCell::resizeEvent %d %d ", width(), height());
886 deselect(); 891 deselect();
887 mLabel->setMaximumHeight( height() - lineWidth()*2 ); 892 mLabel->setMaximumHeight( height() - lineWidth()*2 );
888 893
889 QString text; 894 QString text;
890 mLabel->setText( text ); 895 mLabel->setText( text );
891 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; 896 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog;
892 if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { 897 if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) {
893 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " "; 898 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " ";
894 mLabel->resize( mLabelBigSize ); 899 mLabel->resize( mLabelBigSize );
895 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 900 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
896 } else { 901 } else {
897 mLabel->resize( mLabelSize ); 902 mLabel->resize( mLabelSize );
898 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 903 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
899 } 904 }
900 mLabel->setText( text ); 905 mLabel->setText( text );
901 906
902 int size = height() - mLabel->height() - lineWidth()-1; 907 int size = height() - mLabel->height() - lineWidth()-1;
903 //qDebug("LW %d ", lineWidth()); 908 //qDebug("LW %d ", lineWidth());
904 if ( size > 0 ) 909 if ( size > 0 )
905 verticalScrollBar()->setMaximumHeight( size ); 910 verticalScrollBar()->setMaximumHeight( size );
906 size = width() - mLabel->width() -lineWidth()-1; 911 size = width() - mLabel->width() -lineWidth()-1;
907 if ( size > 0 ) 912 if ( size > 0 )
908 horizontalScrollBar()->setMaximumWidth( size ); 913 horizontalScrollBar()->setMaximumWidth( size );
909 mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() ); 914 mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() );
910 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 915 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
911 // mItemList->resize ( width(), height () ); 916 // mItemList->resize ( width(), height () );
912 if ( e ) 917 if ( e )
913 KNoScrollListBox::resizeEvent ( e ); 918 KNoScrollListBox::resizeEvent ( e );
914} 919}
915 920
916void MonthViewCell::defaultAction( QListBoxItem *item ) 921void MonthViewCell::defaultAction( QListBoxItem *item )
917{ 922{
918 if ( !item ) return; 923 if ( !item ) return;
919 924
920 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 925 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
921 Incidence *incidence = eventItem->incidence(); 926 Incidence *incidence = eventItem->incidence();
922 if ( incidence ) mMonthView->defaultAction( incidence ); 927 if ( incidence ) mMonthView->defaultAction( incidence );
923} 928}
924void MonthViewCell::showDay() 929void MonthViewCell::showDay()
925{ 930{
926 emit showDaySignal( date() ); 931 emit showDaySignal( date() );
927} 932}
928void MonthViewCell::newEvent() 933void MonthViewCell::newEvent()
929{ 934{
930 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 935 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
931 emit newEventSignal( dt ); 936 emit newEventSignal( dt );
932} 937}
933void MonthViewCell::cellClicked( QListBoxItem *item ) 938void MonthViewCell::cellClicked( QListBoxItem *item )
934{ 939{
935 static QListBoxItem * lastClicked = 0; 940 static QListBoxItem * lastClicked = 0;
936 if ( item == 0 ) { 941 if ( item == 0 ) {
937 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 942 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
938 emit newEventSignal( dt ); 943 emit newEventSignal( dt );
939 return; 944 return;
940 } 945 }
941 /* 946 /*
942 if ( lastClicked ) 947 if ( lastClicked )
943 if ( ! item ) { 948 if ( ! item ) {
944 if ( lastClicked->listBox() != item->listBox() ) 949 if ( lastClicked->listBox() != item->listBox() )
945 lastClicked->listBox()->clearSelection(); 950 lastClicked->listBox()->clearSelection();
946 } 951 }
947 */ 952 */
948 953
949 mMonthView->setSelectedCell( this ); 954 mMonthView->setSelectedCell( this );
950 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true ); 955 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true );
951 select(); 956 select();
952} 957}
953 958
954void MonthViewCell::contextMenu( QListBoxItem *item ) 959void MonthViewCell::contextMenu( QListBoxItem *item )
955{ 960{
956 if ( !item ) return; 961 if ( !item ) return;
957 962
958 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 963 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
959 Incidence *incidence = eventItem->incidence(); 964 Incidence *incidence = eventItem->incidence();
960 if ( incidence ) mMonthView->showContextMenu( incidence ); 965 if ( incidence ) mMonthView->showContextMenu( incidence );
961} 966}
962 967
963void MonthViewCell::selection( QListBoxItem *item ) 968void MonthViewCell::selection( QListBoxItem *item )
964{ 969{
965 if ( !item ) return; 970 if ( !item ) return;
966 971
967 mMonthView->setSelectedCell( this ); 972 mMonthView->setSelectedCell( this );
968} 973}
969 974
970 975
971// ******************************************************************************* 976// *******************************************************************************
972// ******************************************************************************* 977// *******************************************************************************
973// ******************************************************************************* 978// *******************************************************************************
974 979
975 980
976KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) 981KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name)
977 : KOEventView( calendar, parent, name ), 982 : KOEventView( calendar, parent, name ),
978 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), 983 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
979 mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) 984 mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
980{ 985{
981 mShortDayLabelsM = false; 986 mShortDayLabelsM = false;
982 mShortDayLabelsW = false; 987 mShortDayLabelsW = false;
983 skipResize = false; 988 skipResize = false;
984 clPending = true; 989 clPending = true;
985 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); 990 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" );
986 mWidStack = new QWidgetStack( this ); 991 mWidStack = new QWidgetStack( this );
987 QVBoxLayout* hb = new QVBoxLayout( this ); 992 QVBoxLayout* hb = new QVBoxLayout( this );
988 mMonthView = new QWidget( mWidStack ); 993 mMonthView = new QWidget( mWidStack );
989 mWeekView = new QWidget( mWidStack ); 994 mWeekView = new QWidget( mWidStack );
990#if QT_VERSION >= 0x030000 995#if QT_VERSION >= 0x030000
991 mWidStack->addWidget(mMonthView ); 996 mWidStack->addWidget(mMonthView );
992 mWidStack->addWidget(mWeekView ); 997 mWidStack->addWidget(mWeekView );
993#else 998#else
994 mWidStack->addWidget( mMonthView, 1 ); 999 mWidStack->addWidget( mMonthView, 1 );
995 mWidStack->addWidget( mWeekView , 1 ); 1000 mWidStack->addWidget( mWeekView , 1 );
996#endif 1001#endif
997 hb->addWidget( mNavigatorBar ); 1002 hb->addWidget( mNavigatorBar );
998 hb->addWidget( mWidStack ); 1003 hb->addWidget( mWidStack );
999 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 1004 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
1000 mShowWeekView = KOPrefs::instance()->mMonthViewWeek; 1005 mShowWeekView = KOPrefs::instance()->mMonthViewWeek;
1001 if ( mShowWeekView ) 1006 if ( mShowWeekView )
1002 mWeekStartsMonday = true; 1007 mWeekStartsMonday = true;
1003 updatePossible = false; 1008 updatePossible = false;
1004 //updatePossible = true; 1009 //updatePossible = true;
1005 mCells.setAutoDelete( true ); 1010 mCells.setAutoDelete( true );
1006 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 1011 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
1007 mDayLabels.resize( mDaysPerWeek ); 1012 mDayLabels.resize( mDaysPerWeek );
1008 mDayLabelsW.resize( mDaysPerWeek ); 1013 mDayLabelsW.resize( mDaysPerWeek );
1009 QFont bfont = font(); 1014 QFont bfont = font();
1010 if ( QApplication::desktop()->width() < 650 ) { 1015 if ( QApplication::desktop()->width() < 650 ) {
1011 bfont.setPointSize( bfont.pointSize() - 2 ); 1016 bfont.setPointSize( bfont.pointSize() - 2 );
1012 } 1017 }
1013 bfont.setBold( true ); 1018 bfont.setBold( true );
1014 int i; 1019 int i;
1015 1020
1016 for( i = 0; i < mDaysPerWeek; i++ ) { 1021 for( i = 0; i < mDaysPerWeek; i++ ) {
1017 QLabel *label = new QLabel( mMonthView ); 1022 QLabel *label = new QLabel( mMonthView );
1018 label->setFont(bfont); 1023 label->setFont(bfont);
1019 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1024 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1020 label->setLineWidth(1); 1025 label->setLineWidth(1);
1021 label->setAlignment(AlignCenter); 1026 label->setAlignment(AlignCenter);
1022 mDayLabels.insert( i, label ); 1027 mDayLabels.insert( i, label );
1023 label = new QLabel( mWeekView ); 1028 label = new QLabel( mWeekView );
1024 label->setFont(bfont); 1029 label->setFont(bfont);
1025 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1030 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1026 label->setLineWidth(1); 1031 label->setLineWidth(1);
1027 label->setAlignment(AlignCenter); 1032 label->setAlignment(AlignCenter);
1028 mDayLabelsW.insert( i, label ); 1033 mDayLabelsW.insert( i, label );
1029 } 1034 }
1030 1035
1031 bfont.setBold( false ); 1036 bfont.setBold( false );
1032 mWeekLabels.resize( mNumWeeks+1 ); 1037 mWeekLabels.resize( mNumWeeks+1 );
1033 mWeekLabelsW.resize( 2 ); 1038 mWeekLabelsW.resize( 2 );
1034 for( i = 0; i < mNumWeeks+1; i++ ) { 1039 for( i = 0; i < mNumWeeks+1; i++ ) {
1035 KOWeekButton *label = new KOWeekButton( mMonthView ); 1040 KOWeekButton *label = new KOWeekButton( mMonthView );
1036 label->setFocusPolicy(NoFocus); 1041 label->setFocusPolicy(NoFocus);
1037 label->setFont(bfont); 1042 label->setFont(bfont);
1038 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 1043 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
1039 label->setFlat(true); 1044 label->setFlat(true);
1040 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 1045 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
1041 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1046 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1042 //label->setLineWidth(1); 1047 //label->setLineWidth(1);
1043 //label->setAlignment(AlignCenter); 1048 //label->setAlignment(AlignCenter);
1044 mWeekLabels.insert( i, label ); 1049 mWeekLabels.insert( i, label );
1045 } 1050 }
1046 mWeekLabels[mNumWeeks]->setText( i18n("W")); 1051 mWeekLabels[mNumWeeks]->setText( i18n("W"));
1047 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number")); 1052 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number"));
1048 1053
1049 for( i = 0; i < 1+1; i++ ) { 1054 for( i = 0; i < 1+1; i++ ) {
1050 KOWeekButton *label = new KOWeekButton( mWeekView ); 1055 KOWeekButton *label = new KOWeekButton( mWeekView );
1051 label->setFocusPolicy(NoFocus); 1056 label->setFocusPolicy(NoFocus);
1052 label->setFont(bfont); 1057 label->setFont(bfont);
1053 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 1058 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
1054 label->setFlat(true); 1059 label->setFlat(true);
1055 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 1060 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
1056 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1061 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1057 //label->setLineWidth(1); 1062 //label->setLineWidth(1);
1058 //label->setAlignment(AlignCenter); 1063 //label->setAlignment(AlignCenter);
1059 mWeekLabelsW.insert( i, label ); 1064 mWeekLabelsW.insert( i, label );
1060 } 1065 }
1061 mWeekLabelsW[1]->setText( i18n("W")); 1066 mWeekLabelsW[1]->setText( i18n("W"));
1062 1067
1063 1068
1064 int row, col; 1069 int row, col;
1065 mCells.resize( mNumCells ); 1070 mCells.resize( mNumCells );
1066 for( row = 0; row < mNumWeeks; ++row ) { 1071 for( row = 0; row < mNumWeeks; ++row ) {
1067 for( col = 0; col < mDaysPerWeek; ++col ) { 1072 for( col = 0; col < mDaysPerWeek; ++col ) {
1068 MonthViewCell *cell = new MonthViewCell( this, mMonthView ); 1073 MonthViewCell *cell = new MonthViewCell( this, mMonthView );
1069 mCells.insert( row * mDaysPerWeek + col, cell ); 1074 mCells.insert( row * mDaysPerWeek + col, cell );
1070 1075
1071 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 1076 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
1072 SLOT( defaultAction( Incidence * ) ) ); 1077 SLOT( defaultAction( Incidence * ) ) );
1073 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 1078 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
1074 SIGNAL( newEventSignal( QDateTime ) ) ); 1079 SIGNAL( newEventSignal( QDateTime ) ) );
1075 connect( cell, SIGNAL( showDaySignal( QDate ) ), 1080 connect( cell, SIGNAL( showDaySignal( QDate ) ),
1076 SIGNAL( showDaySignal( QDate ) ) ); 1081 SIGNAL( showDaySignal( QDate ) ) );
1077 } 1082 }
1078 } 1083 }
1079 mCellsW.resize( mDaysPerWeek ); 1084 mCellsW.resize( mDaysPerWeek );
1080 for( col = 0; col < mDaysPerWeek; ++col ) { 1085 for( col = 0; col < mDaysPerWeek; ++col ) {
1081 MonthViewCell *cell = new MonthViewCell( this, mWeekView ); 1086 MonthViewCell *cell = new MonthViewCell( this, mWeekView );
1082 mCellsW.insert( col, cell ); 1087 mCellsW.insert( col, cell );
1083 1088
1084 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 1089 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
1085 SLOT( defaultAction( Incidence * ) ) ); 1090 SLOT( defaultAction( Incidence * ) ) );
1086 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 1091 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
1087 SIGNAL( newEventSignal( QDateTime ) ) ); 1092 SIGNAL( newEventSignal( QDateTime ) ) );
1088 connect( cell, SIGNAL( showDaySignal( QDate ) ), 1093 connect( cell, SIGNAL( showDaySignal( QDate ) ),
1089 SIGNAL( showDaySignal( QDate ) ) ); 1094 SIGNAL( showDaySignal( QDate ) ) );
1090 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); 1095 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont );
1091 } 1096 }
1092 1097
1093 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); 1098 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) );
1094 mContextMenu = eventPopup(); 1099 mContextMenu = eventPopup();
1095 // updateConfig(); //useless here... 1100 // updateConfig(); //useless here...
1096 // ... but we need mWidthLongDayLabel computed 1101 // ... but we need mWidthLongDayLabel computed
1097 QFontMetrics fontmetric(mDayLabels[0]->font()); 1102 QFontMetrics fontmetric(mDayLabels[0]->font());
1098 mWidthLongDayLabel = 0; 1103 mWidthLongDayLabel = 0;
1099 for (int i = 0; i < 7; i++) { 1104 for (int i = 0; i < 7; i++) {
1100 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 1105 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
1101 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 1106 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
1102 } 1107 }
1103 1108
1104 //mWeekLabels[mNumWeeks]->setText( i18n("W")); 1109 //mWeekLabels[mNumWeeks]->setText( i18n("W"));
1105 1110
1106#if 0 1111#if 0
1107 if ( mShowWeekView ) 1112 if ( mShowWeekView )
1108 mWidStack->raiseWidget( mWeekView ); 1113 mWidStack->raiseWidget( mWeekView );
1109 else 1114 else
1110 mWidStack->raiseWidget( mMonthView ); 1115 mWidStack->raiseWidget( mMonthView );
1111#endif 1116#endif
1112 1117
1113 emit incidenceSelected( 0 ); 1118 emit incidenceSelected( 0 );
1114 1119
1115 mComputeLayoutTimer = new QTimer( this ); 1120 mComputeLayoutTimer = new QTimer( this );
1116 connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout())); 1121 connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout()));
1117 1122
1118 1123
1119#ifndef DESKTOP_VERSION 1124#ifndef DESKTOP_VERSION
1120 resize( QApplication::desktop()->size() ); 1125 resize( QApplication::desktop()->size() );
1121#else 1126#else
1122 resize(640, 480 ); 1127 resize(640, 480 );
1123 updatePossible = true; 1128 updatePossible = true;
1124#endif 1129#endif
1125 computeLayout(); 1130 computeLayout();
1126 1131
1127 if ( mShowWeekView ) 1132 if ( mShowWeekView )
1128 mWidStack->raiseWidget( mWeekView ); 1133 mWidStack->raiseWidget( mWeekView );
1129 else 1134 else
1130 mWidStack->raiseWidget( mMonthView ); 1135 mWidStack->raiseWidget( mMonthView );
1131} 1136}
1132 1137
1133KOMonthView::~KOMonthView() 1138KOMonthView::~KOMonthView()
1134{ 1139{
1135 delete mContextMenu; 1140 delete mContextMenu;
1136} 1141}
1137 1142
1138void KOMonthView::selectInternalWeekNum ( int n ) 1143void KOMonthView::selectInternalWeekNum ( int n )
1139{ 1144{
1140 switchView(); 1145 switchView();
1141 if ( !KOPrefs::instance()->mMonthViewWeek ) 1146 if ( !KOPrefs::instance()->mMonthViewWeek )
1142 emit selectMonth (); 1147 emit selectMonth ();
1143 else 1148 else
1144 emit selectWeekNum ( n ); 1149 emit selectWeekNum ( n );
1145} 1150}
1146 1151
1147int KOMonthView::currentWeek() 1152int KOMonthView::currentWeek()
1148{ 1153{
1149 if ( mShowWeekView ) 1154 if ( mShowWeekView )
1150 return mWeekLabelsW[0]->getWeekNum(); 1155 return mWeekLabelsW[0]->getWeekNum();
1151 return mWeekLabels[0]->getWeekNum(); 1156 return mWeekLabels[0]->getWeekNum();
1152} 1157}
1153void KOMonthView::switchView() 1158void KOMonthView::switchView()
1154{ 1159{
1155 if ( selectedCell( ) ) 1160 if ( selectedCell( ) )
1156 selectedCell()->deselect(); 1161 selectedCell()->deselect();
1157 mShowWeekView = !mShowWeekView; 1162 mShowWeekView = !mShowWeekView;
1158 KOPrefs::instance()->mMonthViewWeek = mShowWeekView; 1163 KOPrefs::instance()->mMonthViewWeek = mShowWeekView;
1159 if ( clPending ) { 1164 if ( clPending ) {
1160 computeLayout(); 1165 computeLayout();
1161 updateConfig(); 1166 updateConfig();
1162 } 1167 }
1163 if ( mShowWeekView ) 1168 if ( mShowWeekView )
1164 mWidStack->raiseWidget( mWeekView ); 1169 mWidStack->raiseWidget( mWeekView );
1165 else 1170 else
1166 mWidStack->raiseWidget( mMonthView ); 1171 mWidStack->raiseWidget( mMonthView );
1167 clPending = false; 1172 clPending = false;
1168} 1173}
1169 1174
1170int KOMonthView::maxDatesHint() 1175int KOMonthView::maxDatesHint()
1171{ 1176{
1172 return mNumCells; 1177 return mNumCells;
1173} 1178}
1174 1179
1175int KOMonthView::currentDateCount() 1180int KOMonthView::currentDateCount()
1176{ 1181{
1177 return mNumCells; 1182 return mNumCells;
1178} 1183}
1179 1184
1180QPtrList<Incidence> KOMonthView::selectedIncidences() 1185QPtrList<Incidence> KOMonthView::selectedIncidences()
1181{ 1186{
1182 QPtrList<Incidence> selected; 1187 QPtrList<Incidence> selected;
1183 1188
1184 if ( mSelectedCell ) { 1189 if ( mSelectedCell ) {
1185 Incidence *incidence = mSelectedCell->selectedIncidence(); 1190 Incidence *incidence = mSelectedCell->selectedIncidence();
1186 if ( incidence ) selected.append( incidence ); 1191 if ( incidence ) selected.append( incidence );
1187 } 1192 }
1188 1193
1189 return selected; 1194 return selected;
1190} 1195}
1191 1196
1192DateList KOMonthView::selectedDates() 1197DateList KOMonthView::selectedDates()
1193{ 1198{
1194 DateList selected; 1199 DateList selected;
1195 1200
1196 if ( mSelectedCell ) { 1201 if ( mSelectedCell ) {
1197 QDate qd = mSelectedCell->selectedIncidenceDate(); 1202 QDate qd = mSelectedCell->selectedIncidenceDate();
1198 if ( qd.isValid() ) selected.append( qd ); 1203 if ( qd.isValid() ) selected.append( qd );
1199 } 1204 }
1200 1205
1201 return selected; 1206 return selected;
1202} 1207}
1203 1208
1204void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1209void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1205 const QDate &td) 1210 const QDate &td)
1206{ 1211{
1207#ifndef KORG_NOPRINTER 1212#ifndef KORG_NOPRINTER
1208 calPrinter->preview(CalPrinter::Month, fd, td); 1213 calPrinter->preview(CalPrinter::Month, fd, td);
1209#endif 1214#endif
1210} 1215}
1211 1216
1212void KOMonthView::updateConfig() 1217void KOMonthView::updateConfig()
1213{ 1218{
1214 1219
1215 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 1220 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
1216 1221
1217 if ( mShowWeekView ) { 1222 if ( mShowWeekView ) {
1218 mWeekStartsMonday = true; 1223 mWeekStartsMonday = true;
1219 } 1224 }
1220 QFontMetrics fontmetric(mDayLabels[0]->font()); 1225 QFontMetrics fontmetric(mDayLabels[0]->font());
1221 mWidthLongDayLabel = 0; 1226 mWidthLongDayLabel = 0;
1222 1227
1223 for (int i = 0; i < 7; i++) { 1228 for (int i = 0; i < 7; i++) {
1224 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 1229 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
1225 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 1230 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
1226 } 1231 }
1227 bool temp = mShowSatSunComp ; 1232 bool temp = mShowSatSunComp ;
1228 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 1233 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
1229 if ( ! mShowWeekView ) { 1234 if ( ! mShowWeekView ) {
1230 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) 1235 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog )
1231 computeLayout(); 1236 computeLayout();
1232 } 1237 }
1233 updateDayLabels(); 1238 updateDayLabels();
1234 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); 1239 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks);
1235 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; 1240 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks;
1236 //resizeEvent( 0 ); 1241 //resizeEvent( 0 );
1237 for (uint i = 0; i < mCells.count(); ++i) { 1242 for (uint i = 0; i < mCells.count(); ++i) {
1238 mCells[i]->updateConfig(); 1243 mCells[i]->updateConfig();
1239 } 1244 }
1240 1245
1241 for (uint i = 0; i < mCellsW.count(); ++i) { 1246 for (uint i = 0; i < mCellsW.count(); ++i) {
1242 mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont); 1247 mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont);
1243 } 1248 }
1244#ifdef DESKTOP_VERSION 1249#ifdef DESKTOP_VERSION
1245 MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); 1250 MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips);
1246#endif 1251#endif
1247 updateView(); 1252 updateView();
1248} 1253}
1249 1254
1250void KOMonthView::updateDayLabels() 1255void KOMonthView::updateDayLabels()
1251{ 1256{
1252 1257
1253 QPtrVector<QLabel> *mDayLabelsT; 1258 QPtrVector<QLabel> *mDayLabelsT;
1254 1259
1255 mDayLabelsT = &mDayLabelsW; 1260 mDayLabelsT = &mDayLabelsW;
1256 for (int i = 0; i < 7; i++) { 1261 for (int i = 0; i < 7; i++) {
1257 if (mWeekStartsMonday) { 1262 if (mWeekStartsMonday) {
1258 bool show = mShortDayLabelsW; 1263 bool show = mShortDayLabelsW;
1259 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) 1264 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
1260 show = true; 1265 show = true;
1261 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); 1266 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
1262 } else { 1267 } else {
1263 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsW)); 1268 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsW));
1264 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsW)); 1269 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsW));
1265 1270
1266 } 1271 }
1267 } 1272 }
1268 mDayLabelsT = &mDayLabels; 1273 mDayLabelsT = &mDayLabels;
1269 for (int i = 0; i < 7; i++) { 1274 for (int i = 0; i < 7; i++) {
1270 if (mWeekStartsMonday) { 1275 if (mWeekStartsMonday) {
1271 bool show = mShortDayLabelsM; 1276 bool show = mShortDayLabelsM;
1272 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) 1277 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
1273 show = true; 1278 show = true;
1274 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); 1279 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
1275 } else { 1280 } else {
1276 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM)); 1281 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM));
1277 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM)); 1282 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM));
1278 1283
1279 } 1284 }
1280 } 1285 }
1281 1286
1282} 1287}
1283 1288
1284void KOMonthView::showDates(const QDate &start, const QDate &) 1289void KOMonthView::showDates(const QDate &start, const QDate &)
1285{ 1290{
1286 // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; 1291 // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl;
1287 1292
1288 QPtrVector<MonthViewCell> *cells; 1293 QPtrVector<MonthViewCell> *cells;
1289 QPtrVector<QLabel> *dayLabels; 1294 QPtrVector<QLabel> *dayLabels;
1290 QPtrVector<KOWeekButton> *weekLabels; 1295 QPtrVector<KOWeekButton> *weekLabels;
1291 int weekNum = 6; 1296 int weekNum = 6;
1292 if ( mShowWeekView ) { 1297 if ( mShowWeekView ) {
1293 weekNum = 1; 1298 weekNum = 1;
1294 cells = &mCellsW; 1299 cells = &mCellsW;
1295 dayLabels = &mDayLabelsW; 1300 dayLabels = &mDayLabelsW;
1296 weekLabels = &mWeekLabelsW; 1301 weekLabels = &mWeekLabelsW;
1297 } else { 1302 } else {
1298 cells = &mCells; 1303 cells = &mCells;
1299 dayLabels = &mDayLabels; 1304 dayLabels = &mDayLabels;
1300 weekLabels = &mWeekLabels; 1305 weekLabels = &mWeekLabels;
1301 } 1306 }
1302 1307
1303 mStartDate = start; 1308 mStartDate = start;
1304 1309
1305 int startWeekDay = mWeekStartsMonday ? 1 : 7; 1310 int startWeekDay = mWeekStartsMonday ? 1 : 7;
1306 1311
1307 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { 1312 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) {
1308 mStartDate = mStartDate.addDays( -1 ); 1313 mStartDate = mStartDate.addDays( -1 );
1309 } 1314 }
1310 1315
1311 bool primary = false; 1316 bool primary = false;
1312 uint i; 1317 uint i;
1313 for( i = 0; i < (*cells).size(); ++i ) { 1318 for( i = 0; i < (*cells).size(); ++i ) {
1314 QDate date = mStartDate.addDays( i ); 1319 QDate date = mStartDate.addDays( i );
1315 (*cells)[i]->setDate( date ); 1320 (*cells)[i]->setDate( date );
1316 1321
1317#ifndef KORG_NOPLUGINS 1322#ifndef KORG_NOPLUGINS
1318 // add holiday, if present 1323 // add holiday, if present
1319 QString hstring(KOCore::self()->holiday(date)); 1324 QString hstring(KOCore::self()->holiday(date));
1320 (*cells)[i]->setHoliday( hstring ); 1325 (*cells)[i]->setHoliday( hstring );
1321#endif 1326#endif
1322 1327
1323 } 1328 }
1324 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); 1329 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 );
1325 for( i = 0; i < weekNum; ++i ) { 1330 for( i = 0; i < weekNum; ++i ) {
1326 int wno; 1331 int wno;
1327 // remember, according to ISO 8601, the first week of the year is the 1332 // remember, according to ISO 8601, the first week of the year is the
1328 // first week that contains a thursday. Thus we must subtract off 4, 1333 // first week that contains a thursday. Thus we must subtract off 4,
1329 // not just 1. 1334 // not just 1.
1330 int dayOfYear = date.dayOfYear(); 1335 int dayOfYear = date.dayOfYear();
1331 if (dayOfYear % 7 != 0) 1336 if (dayOfYear % 7 != 0)
1332 wno = dayOfYear / 7 + 1; 1337 wno = dayOfYear / 7 + 1;
1333 else 1338 else
1334 wno =dayOfYear / 7; 1339 wno =dayOfYear / 7;
1335 (*weekLabels)[i]->setWeekNum( wno ); 1340 (*weekLabels)[i]->setWeekNum( wno );
1336 date = date.addDays( 7 ); 1341 date = date.addDays( 7 );
1337 } 1342 }
1338 updateView(); 1343 updateView();
1339} 1344}
1340 1345
1341void KOMonthView::showEvents(QPtrList<Event>) 1346void KOMonthView::showEvents(QPtrList<Event>)
1342{ 1347{
1343 qDebug("KOMonthView::selectEvents is not implemented yet. "); 1348 qDebug("KOMonthView::selectEvents is not implemented yet. ");
1344} 1349}
1345 1350
1346void KOMonthView::changeEventDisplay(Event *, int) 1351void KOMonthView::changeEventDisplay(Event *, int)
1347{ 1352{
1348 // this should be re-written to be much more efficient, but this 1353 // this should be re-written to be much more efficient, but this
1349 // quick-and-dirty-hack gets the job done for right now. 1354 // quick-and-dirty-hack gets the job done for right now.
1350 updateView(); 1355 updateView();
1351} 1356}
1352 1357
1353void KOMonthView::updateView() 1358void KOMonthView::updateView()
1354{ 1359{
1355 1360
1356 if ( !updatePossible ) 1361 if ( !updatePossible )
1357 return; 1362 return;
1358 //qDebug("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU "); 1363 //qDebug("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU ");
1359 //QTime ti; 1364 //QTime ti;
1360 //ti.start(); 1365 //ti.start();
1361 clearSelection(); 1366 clearSelection();
1362 QPtrVector<MonthViewCell> *cells; 1367 QPtrVector<MonthViewCell> *cells;
1363 if ( mShowWeekView ) { 1368 if ( mShowWeekView ) {
1364 cells = &mCellsW; 1369 cells = &mCellsW;
1365 } else { 1370 } else {
1366 cells = &mCells; 1371 cells = &mCells;
1367 } 1372 }
1368#if 1 1373#if 1
1369 int i; 1374 int i;
1370 int timeSpan = (*cells).size()-1; 1375 int timeSpan = (*cells).size()-1;
1371 if ( KOPrefs::instance()->mMonthViewWeek ) 1376 if ( KOPrefs::instance()->mMonthViewWeek )
1372 timeSpan = 6; 1377 timeSpan = 6;
1373 for( i = 0; i < timeSpan + 1; ++i ) { 1378 for( i = 0; i < timeSpan + 1; ++i ) {
1374 (*cells)[i]->startUpdateCell(); 1379 (*cells)[i]->startUpdateCell();
1375 } 1380 }
1376 1381
1377 QPtrList<Event> events = calendar()->events(); 1382 QPtrList<Event> events = calendar()->events();
1378 Event *event; 1383 Event *event;
1379 QDateTime dt; 1384 QDateTime dt;
1380 bool ok; 1385 bool ok;
1381 QDate endDate = mStartDate.addDays( timeSpan ); 1386 QDate endDate = mStartDate.addDays( timeSpan );
1382 for( event = events.first(); event; event = events.next() ) { // for event 1387 for( event = events.first(); event; event = events.next() ) { // for event
1383 if ( event->doesRecur() ) { 1388 if ( event->doesRecur() ) {
1384 bool last; 1389 bool last;
1385 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); 1390 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last );
1386 QDateTime incidenceEnd; 1391 QDateTime incidenceEnd;
1387 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); 1392 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() );
1388 bool invalid = false; 1393 bool invalid = false;
1389 while( true ) { 1394 while( true ) {
1390 if ( incidenceStart.isValid() ) { 1395 if ( incidenceStart.isValid() ) {
1391 incidenceEnd = incidenceStart.addDays( eventlen ); 1396 incidenceEnd = incidenceStart.addDays( eventlen );
1392 int st = incidenceStart.date().daysTo( endDate ); 1397 int st = incidenceStart.date().daysTo( endDate );
1393 if ( st >= 0 ) { // start before timeend 1398 if ( st >= 0 ) { // start before timeend
1394 int end = mStartDate.daysTo( incidenceEnd.date() ); 1399 int end = mStartDate.daysTo( incidenceEnd.date() );
1395 if ( end >= 0 ) { // end after timestart --- got one! 1400 if ( end >= 0 ) { // end after timestart --- got one!
1396 //normalize 1401 //normalize
1397 st = timeSpan - st; 1402 st = timeSpan - st;
1398 if ( st < 0 ) st = 0; 1403 if ( st < 0 ) st = 0;
1399 if ( end > timeSpan ) end = timeSpan; 1404 if ( end > timeSpan ) end = timeSpan;
1400 int iii; 1405 int iii;
1401 //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); 1406 //qDebug("found %s %d %d ",event->summary().latin1(), st, end );
1402 for ( iii = st;iii<= end;++iii) 1407 for ( iii = st;iii<= end;++iii)
1403 (*cells)[iii]->insertEvent( event ); 1408 (*cells)[iii]->insertEvent( event );
1404 } 1409 }
1405 } 1410 }
1406 } else { 1411 } else {
1407 if ( invalid ) 1412 if ( invalid )
1408 break; 1413 break;
1409 invalid = true; 1414 invalid = true;
1410 //qDebug("invalid %s", event->summary().latin1()); 1415 //qDebug("invalid %s", event->summary().latin1());
1411 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; 1416 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );;
1412 } 1417 }
1413 if ( last ) 1418 if ( last )
1414 break; 1419 break;
1415 bool ok; 1420 bool ok;
1416 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); 1421 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok );
1417 if ( ! ok ) 1422 if ( ! ok )
1418 break; 1423 break;
1419 if ( incidenceStart.date() > endDate ) 1424 if ( incidenceStart.date() > endDate )
1420 break; 1425 break;
1421 } 1426 }
1422 } else { // no recur 1427 } else { // no recur
1423 int st = event->dtStart().date().daysTo( endDate ); 1428 int st = event->dtStart().date().daysTo( endDate );
1424 if ( st >= 0 ) { // start before timeend 1429 if ( st >= 0 ) { // start before timeend
1425 int end = mStartDate.daysTo( event->dtEnd().date() ); 1430 int end = mStartDate.daysTo( event->dtEnd().date() );
1426 if ( end >= 0 ) { // end after timestart --- got one! 1431 if ( end >= 0 ) { // end after timestart --- got one!
1427 //normalize 1432 //normalize
1428 st = timeSpan - st; 1433 st = timeSpan - st;
1429 if ( st < 0 ) st = 0; 1434 if ( st < 0 ) st = 0;
1430 if ( end > timeSpan ) end = timeSpan; 1435 if ( end > timeSpan ) end = timeSpan;
1431 int iii; 1436 int iii;
1432 for ( iii = st;iii<= end;++iii) 1437 for ( iii = st;iii<= end;++iii)
1433 (*cells)[iii]->insertEvent( event ); 1438 (*cells)[iii]->insertEvent( event );
1434 } 1439 }
1435 } 1440 }
1436 } 1441 }
1437 } 1442 }
1438 // insert due todos 1443 // insert due todos
1439 QPtrList<Todo> todos = calendar()->todos( ); 1444 QPtrList<Todo> todos = calendar()->todos( );
1440 Todo *todo; 1445 Todo *todo;
1441 for(todo = todos.first(); todo; todo = todos.next()) { 1446 for(todo = todos.first(); todo; todo = todos.next()) {
1442 //insertTodo( todo ); 1447 //insertTodo( todo );
1443 if ( todo->hasDueDate() ) { 1448 if ( todo->hasDueDate() ) {
1444 int day = mStartDate.daysTo( todo->dtDue().date() ); 1449 int day = mStartDate.daysTo( todo->dtDue().date() );
1445 if ( day >= 0 && day < timeSpan + 1) { 1450 if ( day >= 0 && day < timeSpan + 1) {
1446 (*cells)[day]->insertTodo( todo ); 1451 (*cells)[day]->insertTodo( todo );
1447 } 1452 }
1448 } 1453 }
1449 } 1454 }
1450 1455
1451 for( i = 0; i < timeSpan+1; ++i ) { 1456 for( i = 0; i < timeSpan+1; ++i ) {
1452 (*cells)[i]->finishUpdateCell(); 1457 (*cells)[i]->finishUpdateCell();
1453 } 1458 }
1454 processSelectionChange(); 1459 processSelectionChange();
1455 //qApp->processEvents(); 1460 //qApp->processEvents();
1456 for( i = 0; i < timeSpan+1; ++i ) { 1461 for( i = 0; i < timeSpan+1; ++i ) {
1457 (*cells)[i]->repaintfinishUpdateCell(); 1462 (*cells)[i]->repaintfinishUpdateCell();
1458 } 1463 }
1459 (*cells)[0]->setFocus(); 1464 (*cells)[0]->setFocus();
1460 1465
1461 1466
1462#else 1467#else
1463 // old code 1468 // old code
1464 //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); 1469 //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ");
1465 int i; 1470 int i;
1466 for( i = 0; i < (*cells).count(); ++i ) { 1471 for( i = 0; i < (*cells).count(); ++i ) {
1467 (*cells)[i]->updateCell(); 1472 (*cells)[i]->updateCell();
1468 } 1473 }
1469 1474
1470 //qDebug("KOMonthView::updateView() "); 1475 //qDebug("KOMonthView::updateView() ");
1471 processSelectionChange(); 1476 processSelectionChange();
1472 // qDebug("---------------------------------------------------------------------+ "); 1477 // qDebug("---------------------------------------------------------------------+ ");
1473 (*cells)[0]->setFocus(); 1478 (*cells)[0]->setFocus();
1474#endif 1479#endif
1475 1480
1476 //qDebug("update time %d ", ti.elapsed()); 1481 //qDebug("update time %d ", ti.elapsed());
1477} 1482}
1478 1483
1479void KOMonthView::resizeEvent(QResizeEvent * e) 1484void KOMonthView::resizeEvent(QResizeEvent * e)
1480{ 1485{
1481 //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height()); 1486 //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height());
1482 if ( isVisible() ) { 1487 if ( isVisible() ) {
1483 //qDebug("KOMonthView::isVisible "); 1488 //qDebug("KOMonthView::isVisible ");
1484 slotComputeLayout(); 1489 slotComputeLayout();
1485 } else 1490 } else
1486 mComputeLayoutTimer->start( 100 ); 1491 mComputeLayoutTimer->start( 100 );
1487} 1492}
1488 1493
1489void KOMonthView::slotComputeLayout() 1494void KOMonthView::slotComputeLayout()
1490{ 1495{
1491 mComputeLayoutTimer->stop(); 1496 mComputeLayoutTimer->stop();
1492 //qDebug("KOMonthView::Post - resizeEvent %d %d ", width(), height() ); 1497 //qDebug("KOMonthView::Post - resizeEvent %d %d ", width(), height() );
1493 computeLayout(); 1498 computeLayout();
1494 clPending = true; 1499 clPending = true;
1495 if ( mShowWeekView ) 1500 if ( mShowWeekView )
1496 mCellsW[0]->setFocus(); 1501 mCellsW[0]->setFocus();
1497 else 1502 else
1498 mCells[0]->setFocus(); 1503 mCells[0]->setFocus();
1499 1504
1500} 1505}
1501void KOMonthView::computeLayoutWeek() 1506void KOMonthView::computeLayoutWeek()
1502{ 1507{
1503 static int lastWid = 0; 1508 static int lastWid = 0;
1504 static int lastHei = 0; 1509 static int lastHei = 0;
1505 int daysToShow; 1510 int daysToShow;
1506 bool combinedSatSun = false; 1511 bool combinedSatSun = false;
1507 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { 1512 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
1508 daysToShow = 6; 1513 daysToShow = 6;
1509 combinedSatSun = true; 1514 combinedSatSun = true;
1510 } 1515 }
1511 int tWid = topLevelWidget()->size().width(); 1516 int tWid = topLevelWidget()->size().width();
1512 int tHei = topLevelWidget()->size().height(); 1517 int tHei = topLevelWidget()->size().height();
1513 1518
1514 int wid = width();//e 1519 int wid = width();//e
1515 int hei = height()-1-mNavigatorBar->height(); 1520 int hei = height()-1-mNavigatorBar->height();
1516 1521
1517 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) 1522 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei )
1518 return; 1523 return;
1519 1524
1520 if ( lastWid == width() && lastHei == height() ) { 1525 if ( lastWid == width() && lastHei == height() ) {
1521 //qDebug("KOListWeekView::No compute layout needed "); 1526 //qDebug("KOListWeekView::No compute layout needed ");
1522 return; 1527 return;
1523 } 1528 }
1524 lastWid = width(); 1529 lastWid = width();
1525 lastHei = height(); 1530 lastHei = height();
1526 1531
1527 1532
1528 if ( wid < hei ) 1533 if ( wid < hei )
1529 daysToShow = 2; 1534 daysToShow = 2;
1530 else 1535 else
1531 daysToShow = 3; 1536 daysToShow = 3;
1532 mShowSatSunComp = true; 1537 mShowSatSunComp = true;
1533 combinedSatSun = true; 1538 combinedSatSun = true;
1534 1539
1535 //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ "); 1540 //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ ");
1536 QFontMetrics fm ( mWeekLabels[0]->font() ); 1541 QFontMetrics fm ( mWeekLabels[0]->font() );
1537 int weeklabelwid = fm.width( "888" ); 1542 int weeklabelwid = fm.width( "888" );
1538 wid -= weeklabelwid; 1543 wid -= weeklabelwid;
1539 1544
1540 int colWid = wid / daysToShow; 1545 int colWid = wid / daysToShow;
1541 int lastCol = wid - ( colWid*6 ); 1546 int lastCol = wid - ( colWid*6 );
1542 int dayLabelHei = mDayLabelsW[0]->sizeHint().height(); 1547 int dayLabelHei = mDayLabelsW[0]->sizeHint().height();
1543 int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow ); 1548 int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow );
1544 int colModulo = wid % daysToShow; 1549 int colModulo = wid % daysToShow;
1545 int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1; 1550 int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1;
1546 //qDebug("rowmod %d ", rowModulo); 1551 //qDebug("rowmod %d ", rowModulo);
1547 int i; 1552 int i;
1548 int x,y,w,h; 1553 int x,y,w,h;
1549 x= 0; 1554 x= 0;
1550 y= 0; 1555 y= 0;
1551 w = colWid; 1556 w = colWid;
1552 h = dayLabelHei ; 1557 h = dayLabelHei ;
1553 for ( i = 0; i < 7; i++) { 1558 for ( i = 0; i < 7; i++) {
1554 if ( i && !( i % daysToShow) && i < 6) { 1559 if ( i && !( i % daysToShow) && i < 6) {
1555 y += hei/(5-daysToShow); 1560 y += hei/(5-daysToShow);
1556 x = 0; 1561 x = 0;
1557 w = colWid; 1562 w = colWid;
1558 } 1563 }
1559 if ( ((i) % daysToShow) >= daysToShow-colModulo ) { 1564 if ( ((i) % daysToShow) >= daysToShow-colModulo ) {
1560 ++w; 1565 ++w;
1561 } 1566 }
1562 if ( i >= 5 ) { 1567 if ( i >= 5 ) {
1563 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w/2+w%2,h); 1568 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w/2+w%2,h);
1564 x -= (w/2 ); 1569 x -= (w/2 );
1565 } 1570 }
1566 else 1571 else
1567 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w,h); 1572 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w,h);
1568 x += w; 1573 x += w;
1569 } 1574 }
1570 x= 0; 1575 x= 0;
1571 y= dayLabelHei; 1576 y= dayLabelHei;
1572 w = colWid; 1577 w = colWid;
1573 h = cellHei; 1578 h = cellHei;
1574 int max = 0; 1579 int max = 0;
1575 for ( i = 0; i < mCellsW.count(); ++i) { 1580 for ( i = 0; i < mCellsW.count(); ++i) {
1576 if ( i > 6 ) { 1581 if ( i > 6 ) {
1577 mCellsW[i]->hide(); 1582 mCellsW[i]->hide();
1578 continue; 1583 continue;
1579 } 1584 }
1580 1585
1581 w = colWid; 1586 w = colWid;
1582 if ( ((i) % daysToShow) >= daysToShow-colModulo ) { 1587 if ( ((i) % daysToShow) >= daysToShow-colModulo ) {
1583 ++w; 1588 ++w;
1584 } 1589 }
1585 if ( i == (daysToShow-1-rowModulo)*7) 1590 if ( i == (daysToShow-1-rowModulo)*7)
1586 ++h; 1591 ++h;
1587 1592
1588 if ( i >= 5 ) { 1593 if ( i >= 5 ) {
1589 if ( i ==5 ) { 1594 if ( i ==5 ) {
1590 max = h/2; 1595 max = h/2;
1591 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max ); 1596 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max );
1592 x -= w ;y += h/2; 1597 x -= w ;y += h/2;
1593 } else { 1598 } else {
1594 if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) { 1599 if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) {
1595 ++w; 1600 ++w;
1596 } 1601 }
1597 max = h-h/2; 1602 max = h-h/2;
1598 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max ); 1603 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max );
1599 y -= h/2; 1604 y -= h/2;
1600 } 1605 }
1601 } else { 1606 } else {
1602 max = h; 1607 max = h;
1603 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h ); 1608 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h );
1604 } 1609 }
1605 1610
1606 1611
1607 x += w; 1612 x += w;
1608 if ( x + w/2 > wid ) { 1613 if ( x + w/2 > wid ) {
1609 x = 0; 1614 x = 0;
1610 y += h+dayLabelHei ; 1615 y += h+dayLabelHei ;
1611 } 1616 }
1612 //mCellsW[i]->dateLabel()->setMaximumHeight( max - mCellsW[i]->lineWidth()*2 ); 1617 //mCellsW[i]->dateLabel()->setMaximumHeight( max - mCellsW[i]->lineWidth()*2 );
1613 } 1618 }
1614 y= dayLabelHei; 1619 y= dayLabelHei;
1615 h = cellHei ; 1620 h = cellHei ;
1616 mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei); 1621 mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei);
1617 mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei); 1622 mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
1618 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); 1623 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
1619 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); 1624 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
1620 mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ; 1625 mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ;
1621 updateDayLabels(); 1626 updateDayLabels();
1622 //bool forceUpdate = !updatePossible; 1627 //bool forceUpdate = !updatePossible;
1623 updatePossible = true; 1628 updatePossible = true;
1624 //mWeekLabels[mNumWeeks]->setText( i18n("M")); 1629 //mWeekLabels[mNumWeeks]->setText( i18n("M"));
1625 //if ( forceUpdate ) 1630 //if ( forceUpdate )
1626 // updateView(); 1631 // updateView();
1627} 1632}
1628void KOMonthView::computeLayout() 1633void KOMonthView::computeLayout()
1629{ 1634{
1630 1635
1631 1636
1632 static int lastWid = 0; 1637 static int lastWid = 0;
1633 static int lastHei = 0; 1638 static int lastHei = 0;
1634 1639
1635 if ( mShowWeekView ){ 1640 if ( mShowWeekView ){
1636 computeLayoutWeek(); 1641 computeLayoutWeek();
1637 return; 1642 return;
1638 } 1643 }
1639 int daysToShow = 7; 1644 int daysToShow = 7;
1640 bool combinedSatSun = false; 1645 bool combinedSatSun = false;
1641 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { 1646 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
1642 daysToShow = 6; 1647 daysToShow = 6;
1643 combinedSatSun = true; 1648 combinedSatSun = true;
1644 } 1649 }
1645 int tWid = topLevelWidget()->size().width(); 1650 int tWid = topLevelWidget()->size().width();
1646 int tHei = topLevelWidget()->size().height(); 1651 int tHei = topLevelWidget()->size().height();
1647 1652
1648 int wid = width();//e 1653 int wid = width();//e
1649 int hei = height()-1-mNavigatorBar->height(); 1654 int hei = height()-1-mNavigatorBar->height();
1650 1655
1651 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) { 1656 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) {
1652 return; 1657 return;
1653 } 1658 }
1654 if ( lastWid == width() && lastHei == height() ){ 1659 if ( lastWid == width() && lastHei == height() ){
1655 //qDebug("KOMonthview::No compute layout needed "); 1660 //qDebug("KOMonthview::No compute layout needed ");
1656 return; 1661 return;
1657 } 1662 }
1658 1663
1659 lastWid = width(); 1664 lastWid = width();
1660 lastHei = height(); 1665 lastHei = height();
1661 //qDebug("KOMonthView::computeLayout() MMM ------------------- "); 1666 //qDebug("KOMonthView::computeLayout() MMM ------------------- ");
1662 QFontMetrics fm ( mWeekLabels[0]->font() ); 1667 QFontMetrics fm ( mWeekLabels[0]->font() );
1663 int weeklabelwid = fm.width( "888" ); 1668 int weeklabelwid = fm.width( "888" );
1664 wid -= weeklabelwid; 1669 wid -= weeklabelwid;
1665 1670
1666 int colWid = wid / daysToShow; 1671 int colWid = wid / daysToShow;
1667 int lastCol = wid - ( colWid*6 ); 1672 int lastCol = wid - ( colWid*6 );
1668 int dayLabelHei = mDayLabels[0]->sizeHint().height(); 1673 int dayLabelHei = mDayLabels[0]->sizeHint().height();
1669 int cellHei = (hei - dayLabelHei) /6; 1674 int cellHei = (hei - dayLabelHei) /6;
1670 int colModulo = wid % daysToShow; 1675 int colModulo = wid % daysToShow;
1671 int rowModulo = (hei- dayLabelHei) % 6; 1676 int rowModulo = (hei- dayLabelHei) % 6;
1672 //qDebug("rowmod %d ", rowModulo); 1677 //qDebug("rowmod %d ", rowModulo);
1673 int i; 1678 int i;
1674 int x,y,w,h; 1679 int x,y,w,h;
1675 x= 0; 1680 x= 0;
1676 y= 0; 1681 y= 0;
1677 w = colWid; 1682 w = colWid;
1678 h = dayLabelHei ; 1683 h = dayLabelHei ;
1679 for ( i = 0; i < 7; i++) { 1684 for ( i = 0; i < 7; i++) {
1680 if ( i == daysToShow-colModulo ) 1685 if ( i == daysToShow-colModulo )
1681 ++w; 1686 ++w;
1682 if ( combinedSatSun ) { 1687 if ( combinedSatSun ) {
1683 if ( i >= daysToShow-1 ) { 1688 if ( i >= daysToShow-1 ) {
1684 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h); 1689 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h);
1685 x -= w/2 ; 1690 x -= w/2 ;
1686 } 1691 }
1687 else 1692 else
1688 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 1693 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
1689 } else 1694 } else
1690 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 1695 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
1691 x += w; 1696 x += w;
1692 } 1697 }
1693 x= 0; 1698 x= 0;
1694 y= dayLabelHei; 1699 y= dayLabelHei;
1695 w = colWid; 1700 w = colWid;
1696 h = cellHei ; 1701 h = cellHei ;
1697 int max = 0; 1702 int max = 0;
1698 for ( i = 0; i < mCells.count(); ++i) { 1703 for ( i = 0; i < mCells.count(); ++i) {
1699 //qDebug("iii %d ", i); 1704 //qDebug("iii %d ", i);
1700 w = colWid; 1705 w = colWid;
1701 if ( ((i) % 7) >= 7-colModulo ) { 1706 if ( ((i) % 7) >= 7-colModulo ) {
1702 ++w; 1707 ++w;
1703 } 1708 }
1704 if ( i == (6-rowModulo)*7) 1709 if ( i == (6-rowModulo)*7)
1705 ++h; 1710 ++h;
1706 if ( combinedSatSun ) { 1711 if ( combinedSatSun ) {
1707 if ( (i)%7 >= daysToShow-1 ) { 1712 if ( (i)%7 >= daysToShow-1 ) {
1708 if ( (i)%7 == daysToShow-1 ) { 1713 if ( (i)%7 == daysToShow-1 ) {
1709 max = h/2; 1714 max = h/2;
1710 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); 1715 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max );
1711 x -= w ;y += h/2; 1716 x -= w ;y += h/2;
1712 } else { 1717 } else {
1713 max = h-h/2; 1718 max = h-h/2;
1714 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); 1719 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max );
1715 y -= h/2; 1720 y -= h/2;
1716 } 1721 }
1717 } else { 1722 } else {
1718 max = h; 1723 max = h;
1719 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); 1724 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h );
1720 } 1725 }
1721 1726
1722 } 1727 }
1723 else { 1728 else {
1724 max = h; 1729 max = h;
1725 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); 1730 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h );
1726 } 1731 }
1727 x += w; 1732 x += w;
1728 if ( x + w/2 > wid ) { 1733 if ( x + w/2 > wid ) {
1729 x = 0; 1734 x = 0;
1730 y += h; 1735 y += h;
1731 } 1736 }
1732 //mCells[i]->dateLabel()->setMaximumHeight( max- mCells[i]->lineWidth()*2 ); 1737 //mCells[i]->dateLabel()->setMaximumHeight( max- mCells[i]->lineWidth()*2 );
1733 } 1738 }
1734 y= dayLabelHei; 1739 y= dayLabelHei;
1735 h = cellHei ; 1740 h = cellHei ;
1736 for ( i = 0; i < 6; i++) { 1741 for ( i = 0; i < 6; i++) {
1737 if ( i == (6-rowModulo)) 1742 if ( i == (6-rowModulo))
1738 ++h; 1743 ++h;
1739 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h); 1744 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h);
1740 y += h; 1745 y += h;
1741 } 1746 }
1742 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); 1747 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
1743 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); 1748 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
1744 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); 1749 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
1745 mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ; 1750 mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ;
1746 updateDayLabels(); 1751 updateDayLabels();
1747 //bool forceUpdate = !updatePossible; 1752 //bool forceUpdate = !updatePossible;
1748 updatePossible = true; 1753 updatePossible = true;
1749 //mWeekLabels[mNumWeeks]->setText( i18n("W")); 1754 //mWeekLabels[mNumWeeks]->setText( i18n("W"));
1750} 1755}
1751 1756
1752void KOMonthView::showContextMenu( Incidence *incidence ) 1757void KOMonthView::showContextMenu( Incidence *incidence )
1753{ 1758{
1754 mContextMenu->showIncidencePopup(incidence); 1759 mContextMenu->showIncidencePopup(incidence);
1755 /* 1760 /*
1756 if( incidence && incidence->type() == "Event" ) { 1761 if( incidence && incidence->type() == "Event" ) {
1757 Event *event = static_cast<Event *>(incidence); 1762 Event *event = static_cast<Event *>(incidence);
1758 mContextMenu->showEventPopup(event); 1763 mContextMenu->showEventPopup(event);
1759 } else { 1764 } else {
1760 kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; 1765 kdDebug() << "MonthView::showContextMenu(): cast failed." << endl;
1761 } 1766 }
1762 */ 1767 */
1763} 1768}
1764MonthViewCell * KOMonthView::selectedCell( ) 1769MonthViewCell * KOMonthView::selectedCell( )
1765{ 1770{
1766 return mSelectedCell; 1771 return mSelectedCell;
1767} 1772}
1768void KOMonthView::setSelectedCell( MonthViewCell *cell ) 1773void KOMonthView::setSelectedCell( MonthViewCell *cell )
1769{ 1774{
1770 //qDebug("KOMonthView::setSelectedCell "); 1775 //qDebug("KOMonthView::setSelectedCell ");
1771 if ( mSelectedCell && mSelectedCell != cell ) { 1776 if ( mSelectedCell && mSelectedCell != cell ) {
1772 MonthViewCell * mvc = mSelectedCell; 1777 MonthViewCell * mvc = mSelectedCell;
1773 mSelectedCell = cell; 1778 mSelectedCell = cell;
1774 mvc->deselect(); 1779 mvc->deselect();
1775 } else 1780 } else
1776 mSelectedCell = cell; 1781 mSelectedCell = cell;
1777 // if ( mSelectedCell ) 1782 // if ( mSelectedCell )
1778 // mSelectedCell->select(); 1783 // mSelectedCell->select();
1779 if ( !mSelectedCell ) 1784 if ( !mSelectedCell )
1780 emit incidenceSelected( 0 ); 1785 emit incidenceSelected( 0 );
1781 else 1786 else
1782 emit incidenceSelected( mSelectedCell->selectedIncidence() ); 1787 emit incidenceSelected( mSelectedCell->selectedIncidence() );
1783} 1788}
1784 1789
1785void KOMonthView::processSelectionChange() 1790void KOMonthView::processSelectionChange()
1786{ 1791{
1787 QPtrList<Incidence> incidences = selectedIncidences(); 1792 QPtrList<Incidence> incidences = selectedIncidences();
1788 if (incidences.count() > 0) { 1793 if (incidences.count() > 0) {
1789 emit incidenceSelected( incidences.first() ); 1794 emit incidenceSelected( incidences.first() );
1790 } else { 1795 } else {
1791 emit incidenceSelected( 0 ); 1796 emit incidenceSelected( 0 );
1792 clearSelection(); 1797 clearSelection();
1793 } 1798 }
1794} 1799}
1795 1800
1796void KOMonthView::clearSelection() 1801void KOMonthView::clearSelection()
1797{ 1802{
1798 if ( mSelectedCell ) { 1803 if ( mSelectedCell ) {
1799 mSelectedCell->deselect(); 1804 mSelectedCell->deselect();
1800 mSelectedCell = 0; 1805 mSelectedCell = 0;
1801 } 1806 }
1802} 1807}
1803void KOMonthView::keyPressEvent ( QKeyEvent * e ) 1808void KOMonthView::keyPressEvent ( QKeyEvent * e )
1804{ 1809{
1805 //qDebug("KOMonthView::keyPressEvent "); 1810 //qDebug("KOMonthView::keyPressEvent ");
1806 switch(e->key()) { 1811 switch(e->key()) {
1807 case Key_Up: 1812 case Key_Up:
1808 { 1813 {
1809 if ( mShowWeekView ) { 1814 if ( mShowWeekView ) {
1810 mCellsW[0]->setFocus(); 1815 mCellsW[0]->setFocus();
1811 emit selectWeekNum ( currentWeek() - 1 ); 1816 emit selectWeekNum ( currentWeek() - 1 );
1812 } 1817 }
1813 else { 1818 else {
1814 mCells[0]->setFocus(); 1819 mCells[0]->setFocus();
1815 emit prevMonth(); 1820 emit prevMonth();
1816 } 1821 }
1817 } 1822 }
1818 e->accept(); 1823 e->accept();
1819 break; 1824 break;
1820 case Key_Down: 1825 case Key_Down:
1821 { 1826 {
1822 if ( mShowWeekView ) { 1827 if ( mShowWeekView ) {
1823 mCellsW[0]->setFocus(); 1828 mCellsW[0]->setFocus();
1824 emit selectWeekNum ( currentWeek() +1); 1829 emit selectWeekNum ( currentWeek() +1);
1825 } 1830 }
1826 else { 1831 else {
1827 mCells[0]->setFocus(); 1832 mCells[0]->setFocus();
1828 emit nextMonth(); 1833 emit nextMonth();
1829 } 1834 }
1830 1835
1831 } 1836 }
1832 e->accept(); 1837 e->accept();
1833 break; 1838 break;
1834 case Key_Return: 1839 case Key_Return:
1835 case Key_Enter: 1840 case Key_Enter:
1836 { 1841 {
1837 selectInternalWeekNum ( currentWeek() ); 1842 selectInternalWeekNum ( currentWeek() );
1838 } 1843 }
1839 e->accept(); 1844 e->accept();
1840 break; 1845 break;
1841 case Key_D: 1846 case Key_D:
1842 if ( mSelectedCell ) { 1847 if ( mSelectedCell ) {
1843 mSelectedCell->showDay(); 1848 mSelectedCell->showDay();
1844 e->accept(); 1849 e->accept();
1845 } else { 1850 } else {
1846 e->ignore(); 1851 e->ignore();
1847 } 1852 }
1848 break; 1853 break;
1849 default: 1854 default:
1850 e->ignore(); 1855 e->ignore();
1851 break; 1856 break;
1852 } 1857 }
1853} 1858}