summaryrefslogtreecommitdiffabout
path: root/korganizer
authorzautrix <zautrix>2005-03-31 23:55:51 (UTC)
committer zautrix <zautrix>2005-03-31 23:55:51 (UTC)
commitb76ad1e7e329051a47e28c9d132ce3fcd0b25c5c (patch) (unidiff)
treeb0b3d0eb7a3d29981c183275aadeed0cbbef0007 /korganizer
parentc0fa26aa3b33c293853bdd7d028ddb0545e33c85 (diff)
downloadkdepimpi-b76ad1e7e329051a47e28c9d132ce3fcd0b25c5c.zip
kdepimpi-b76ad1e7e329051a47e28c9d132ce3fcd0b25c5c.tar.gz
kdepimpi-b76ad1e7e329051a47e28c9d132ce3fcd0b25c5c.tar.bz2
fixes
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagenda.cpp5
-rw-r--r--korganizer/koagenda.h2
-rw-r--r--korganizer/koagendaview.cpp15
-rw-r--r--korganizer/koagendaview.h1
-rw-r--r--korganizer/komonthview.cpp7
-rw-r--r--korganizer/kotodoview.cpp103
-rw-r--r--korganizer/kotodoview.h5
-rw-r--r--korganizer/koviewmanager.cpp4
8 files changed, 109 insertions, 33 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp
index 1a24887..9720f43 100644
--- a/korganizer/koagenda.cpp
+++ b/korganizer/koagenda.cpp
@@ -1,2234 +1,2233 @@
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 mTimeBox = new QLabel(this); 73 mTimeBox = new QLabel(this);
74 mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom); 74 mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom);
75 QPalette pal = mTimeBox->palette(); 75 QPalette pal = mTimeBox->palette();
76 pal.setColor(QColorGroup::Foreground, Qt::red); 76 pal.setColor(QColorGroup::Foreground, Qt::red);
77 mTimeBox->setPalette(pal); 77 mTimeBox->setPalette(pal);
78 //mTimeBox->setAutoMask(true); 78 //mTimeBox->setAutoMask(true);
79 79
80 agenda->addChild(mTimeBox); 80 agenda->addChild(mTimeBox);
81 81
82 oldToday = -1; 82 oldToday = -1;
83} 83}
84 84
85MarcusBains::~MarcusBains() 85MarcusBains::~MarcusBains()
86{ 86{
87 delete minutes; 87 delete minutes;
88} 88}
89 89
90int MarcusBains::todayColumn() 90int MarcusBains::todayColumn()
91{ 91{
92 QDate currentDate = QDate::currentDate(); 92 QDate currentDate = QDate::currentDate();
93 93
94 DateList dateList = agenda->dateList(); 94 DateList dateList = agenda->dateList();
95 DateList::ConstIterator it; 95 DateList::ConstIterator it;
96 int col = 0; 96 int col = 0;
97 for(it = dateList.begin(); it != dateList.end(); ++it) { 97 for(it = dateList.begin(); it != dateList.end(); ++it) {
98 if((*it) == currentDate) 98 if((*it) == currentDate)
99 return KOGlobals::self()->reverseLayout() ? 99 return KOGlobals::self()->reverseLayout() ?
100 agenda->columns() - 1 - col : col; 100 agenda->columns() - 1 - col : col;
101 ++col; 101 ++col;
102 } 102 }
103 103
104 return -1; 104 return -1;
105} 105}
106void MarcusBains::updateLoc() 106void MarcusBains::updateLoc()
107{ 107{
108 updateLocation(); 108 updateLocation();
109} 109}
110void MarcusBains::updateLocation(bool recalculate) 110void MarcusBains::updateLocation(bool recalculate)
111{ 111{
112 112
113 QTime tim = QTime::currentTime(); 113 QTime tim = QTime::currentTime();
114 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1()); 114 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1());
115 if((tim.hour() == 0) && (oldTime.hour()==23)) 115 if((tim.hour() == 0) && (oldTime.hour()==23))
116 recalculate = true; 116 recalculate = true;
117 117
118 int mins = tim.hour()*60 + tim.minute(); 118 int mins = tim.hour()*60 + tim.minute();
119 int minutesPerCell = 24 * 60 / agenda->rows(); 119 int minutesPerCell = 24 * 60 / agenda->rows();
120 int y = mins*agenda->gridSpacingY()/minutesPerCell; 120 int y = mins*agenda->gridSpacingY()/minutesPerCell;
121 int today = recalculate ? todayColumn() : oldToday; 121 int today = recalculate ? todayColumn() : oldToday;
122 int x = agenda->gridSpacingX()*today; 122 int x = agenda->gridSpacingX()*today;
123 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled); 123 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled);
124 124
125 oldTime = tim; 125 oldTime = tim;
126 oldToday = today; 126 oldToday = today;
127 127
128 if(disabled || (today<0)) { 128 if(disabled || (today<0)) {
129 hide(); mTimeBox->hide(); 129 hide(); mTimeBox->hide();
130 return; 130 return;
131 } else { 131 } else {
132 show(); mTimeBox->show(); 132 show(); mTimeBox->show();
133 } 133 }
134 134
135 if(recalculate) 135 if(recalculate)
136 setFixedSize(agenda->gridSpacingX(),1); 136 setFixedSize(agenda->gridSpacingX(),1);
137 agenda->moveChild(this, x, y); 137 agenda->moveChild(this, x, y);
138 raise(); 138 raise();
139 139
140 if(recalculate) 140 if(recalculate)
141 //mTimeBox->setFont(QFont("helvetica",10)); 141 //mTimeBox->setFont(QFont("helvetica",10));
142 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont); 142 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont);
143 143
144 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds)); 144 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds));
145 mTimeBox->adjustSize(); 145 mTimeBox->adjustSize();
146 // the -2 below is there because there is a bug in this program 146 // the -2 below is there because there is a bug in this program
147 // somewhere, where the last column of this widget is a few pixels 147 // somewhere, where the last column of this widget is a few pixels
148 // narrower than the other columns. 148 // narrower than the other columns.
149 int offs = (today==agenda->columns()-1) ? -4 : 0; 149 int offs = (today==agenda->columns()-1) ? -4 : 0;
150 agenda->moveChild(mTimeBox, 150 agenda->moveChild(mTimeBox,
151 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1, 151 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1,
152 y-mTimeBox->height()); 152 y-mTimeBox->height());
153 153
154 mTimeBox->raise(); 154 mTimeBox->raise();
155 //mTimeBox->setAutoMask(true); 155 //mTimeBox->setAutoMask(true);
156 minutes->start(5000,true); 156 minutes->start(5000,true);
157} 157}
158 158
159 159
160//////////////////////////////////////////////////////////////////////////// 160////////////////////////////////////////////////////////////////////////////
161 161
162 162
163/* 163/*
164 Create an agenda widget with rows rows and columns columns. 164 Create an agenda widget with rows rows and columns columns.
165*/ 165*/
166KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, 166KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent,
167 const char *name,WFlags f) : 167 const char *name,WFlags f) :
168 QScrollView(parent,name,f) 168 QScrollView(parent,name,f)
169{ 169{
170 170
171 171
172 mColumns = columns; 172 mColumns = columns;
173 mRows = rows; 173 mRows = rows;
174 mGridSpacingY = rowSize; 174 mGridSpacingY = rowSize;
175 mAllDayMode = false; 175 mAllDayMode = false;
176#ifndef DESKTOP_VERSION 176#ifndef DESKTOP_VERSION
177 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 177 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
178#endif 178#endif
179 mHolidayMask = 0; 179 mHolidayMask = 0;
180 init(); 180 init();
181} 181}
182 182
183/* 183/*
184 Create an agenda widget with columns columns and one row. This is used for 184 Create an agenda widget with columns columns and one row. This is used for
185 all-day events. 185 all-day events.
186*/ 186*/
187KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : 187KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) :
188 QScrollView(parent,name,f) 188 QScrollView(parent,name,f)
189{ 189{
190 blockResize = false; 190 blockResize = false;
191 mColumns = columns; 191 mColumns = columns;
192 mRows = 1; 192 mRows = 1;
193 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize); 193 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize);
194 mGridSpacingY = KOPrefs::instance()->mAllDaySize; 194 mGridSpacingY = KOPrefs::instance()->mAllDaySize;
195 mAllDayMode = true; 195 mAllDayMode = true;
196#ifndef DESKTOP_VERSION 196#ifndef DESKTOP_VERSION
197 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 197 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
198#endif 198#endif
199 mHolidayMask = 0; 199 mHolidayMask = 0;
200 init(); 200 init();
201} 201}
202 202
203 203
204KOAgenda::~KOAgenda() 204KOAgenda::~KOAgenda()
205{ 205{
206 if(mMarcusBains) delete mMarcusBains; 206 if(mMarcusBains) delete mMarcusBains;
207 207
208} 208}
209 209
210Incidence *KOAgenda::selectedIncidence() const 210Incidence *KOAgenda::selectedIncidence() const
211{ 211{
212 return (mSelectedItem ? mSelectedItem->incidence() : 0); 212 return (mSelectedItem ? mSelectedItem->incidence() : 0);
213} 213}
214 214
215 215
216QDate KOAgenda::selectedIncidenceDate() const 216QDate KOAgenda::selectedIncidenceDate() const
217{ 217{
218 return (mSelectedItem ? mSelectedItem->itemDate() : QDate()); 218 return (mSelectedItem ? mSelectedItem->itemDate() : QDate());
219} 219}
220 220
221 221
222void KOAgenda::init() 222void KOAgenda::init()
223{ 223{
224 mPopupTimer = new QTimer(this); 224 mPopupTimer = new QTimer(this);
225 connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu())); 225 connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu()));
226 226
227 mNewItemPopup = new QPopupMenu( this ); 227 mNewItemPopup = new QPopupMenu( this );
228 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) ); 228 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) );
229 QString pathString = ""; 229 QString pathString = "";
230 if ( !KOPrefs::instance()->mToolBarMiniIcons ) { 230 if ( !KOPrefs::instance()->mToolBarMiniIcons ) {
231 if ( QApplication::desktop()->width() < 480 ) 231 if ( QApplication::desktop()->width() < 480 )
232 pathString += "icons16/"; 232 pathString += "icons16/";
233 } else 233 } else
234 pathString += "iconsmini/"; 234 pathString += "iconsmini/";
235 235
236 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 ); 236 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 );
237 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 ); 237 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 );
238 mNewItemPopup->insertSeparator ( ); 238 mNewItemPopup->insertSeparator ( );
239 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 ); 239 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 );
240 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 ); 240 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 );
241 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 ); 241 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 );
242 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 ); 242 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 );
243 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("Next month"),6 ); 243 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("This month"),6 );
244 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 ); 244 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 );
245#ifndef _WIN32_ 245#ifndef _WIN32_
246 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase 246 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase
247 viewport()->setWFlags ( wflags); 247 viewport()->setWFlags ( wflags);
248#endif 248#endif
249 mGridSpacingX = 80; 249 mGridSpacingX = 80;
250 mResizeBorderWidth = 8; 250 mResizeBorderWidth = 8;
251 mScrollBorderWidth = 8; 251 mScrollBorderWidth = 8;
252 mScrollDelay = 30; 252 mScrollDelay = 30;
253 mScrollOffset = 10; 253 mScrollOffset = 10;
254 mPaintPixmap.resize( 20,20); 254 mPaintPixmap.resize( 20,20);
255 //enableClipper(true); 255 //enableClipper(true);
256 256
257 // Grab key strokes for keyboard navigation of agenda. Seems to have no 257 // Grab key strokes for keyboard navigation of agenda. Seems to have no
258 // effect. Has to be fixed. 258 // effect. Has to be fixed.
259 setFocusPolicy(WheelFocus); 259 setFocusPolicy(WheelFocus);
260 260
261 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp())); 261 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp()));
262 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown())); 262 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown()));
263 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize())); 263 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize()));
264 264
265 mStartCellX = 0; 265 mStartCellX = 0;
266 mStartCellY = 0; 266 mStartCellY = 0;
267 mCurrentCellX = 0; 267 mCurrentCellX = 0;
268 mCurrentCellY = 0; 268 mCurrentCellY = 0;
269 269
270 mSelectionCellX = 0; 270 mSelectionCellX = 0;
271 mSelectionYTop = 0; 271 mSelectionYTop = 0;
272 mSelectionHeight = 0; 272 mSelectionHeight = 0;
273 273
274 mOldLowerScrollValue = -1; 274 mOldLowerScrollValue = -1;
275 mOldUpperScrollValue = -1; 275 mOldUpperScrollValue = -1;
276 276
277 mClickedItem = 0; 277 mClickedItem = 0;
278 278
279 mActionItem = 0; 279 mActionItem = 0;
280 mActionType = NOP; 280 mActionType = NOP;
281 mItemMoved = false; 281 mItemMoved = false;
282 282
283 mSelectedItem = 0; 283 mSelectedItem = 0;
284 284
285 // mItems.setAutoDelete(true); 285 // mItems.setAutoDelete(true);
286 286
287 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 287 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
288 288
289 viewport()->update(); 289 viewport()->update();
290 290
291 setMinimumSize(30, 1); 291 setMinimumSize(30, 1);
292// setMaximumHeight(mGridSpacingY * mRows + 5); 292// setMaximumHeight(mGridSpacingY * mRows + 5);
293 293
294 // Disable horizontal scrollbar. This is a hack. The geometry should be 294 // Disable horizontal scrollbar. This is a hack. The geometry should be
295 // controlled in a way that the contents horizontally always fits. Then it is 295 // controlled in a way that the contents horizontally always fits. Then it is
296 // not necessary to turn off the scrollbar. 296 // not necessary to turn off the scrollbar.
297 setHScrollBarMode(AlwaysOff); 297 setHScrollBarMode(AlwaysOff);
298 if ( ! mAllDayMode ) 298 if ( ! mAllDayMode )
299 setVScrollBarMode(AlwaysOn); 299 setVScrollBarMode(AlwaysOn);
300 else 300 else
301 setVScrollBarMode(AlwaysOff); 301 setVScrollBarMode(AlwaysOff);
302 302
303 setStartHour(KOPrefs::instance()->mDayBegins); 303 setStartHour(KOPrefs::instance()->mDayBegins);
304 304
305 calculateWorkingHours(); 305 calculateWorkingHours();
306 306
307 connect(verticalScrollBar(),SIGNAL(valueChanged(int)), 307 connect(verticalScrollBar(),SIGNAL(valueChanged(int)),
308 SLOT(checkScrollBoundaries(int))); 308 SLOT(checkScrollBoundaries(int)));
309 309
310 // Create the Marcus Bains line. 310 // Create the Marcus Bains line.
311 if(mAllDayMode) 311 if(mAllDayMode)
312 mMarcusBains = 0; 312 mMarcusBains = 0;
313 else { 313 else {
314 mMarcusBains = new MarcusBains(this); 314 mMarcusBains = new MarcusBains(this);
315 addChild(mMarcusBains); 315 addChild(mMarcusBains);
316 } 316 }
317 mPopupKind = 0; 317 mPopupKind = 0;
318 mPopupItem = 0; 318 mPopupItem = 0;
319} 319}
320 320
321void KOAgenda::clear() 321void KOAgenda::clear()
322{ 322{
323 KOAgendaItem *item; 323 KOAgendaItem *item;
324 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 324 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
325 mUnusedItems.append( item ); 325 mUnusedItems.append( item );
326 //item->hide(); 326 //item->hide();
327 } 327 }
328 mItems.clear(); 328 mItems.clear();
329 mSelectedItem = 0; 329 mSelectedItem = 0;
330 clearSelection(); 330 clearSelection();
331} 331}
332 332
333void KOAgenda::clearSelection() 333void KOAgenda::clearSelection()
334{ 334{
335 mSelectionCellX = 0; 335 mSelectionCellX = 0;
336 mSelectionYTop = 0; 336 mSelectionYTop = 0;
337 mSelectionHeight = 0; 337 mSelectionHeight = 0;
338} 338}
339 339
340void KOAgenda::marcus_bains() 340void KOAgenda::marcus_bains()
341{ 341{
342 if(mMarcusBains) mMarcusBains->updateLocation(true); 342 if(mMarcusBains) mMarcusBains->updateLocation(true);
343} 343}
344 344
345 345
346void KOAgenda::changeColumns(int columns) 346void KOAgenda::changeColumns(int columns)
347{ 347{
348 if (columns == 0) { 348 if (columns == 0) {
349 qDebug("KOAgenda::changeColumns() called with argument 0 "); 349 qDebug("KOAgenda::changeColumns() called with argument 0 ");
350 return; 350 return;
351 } 351 }
352 clear(); 352 clear();
353 mColumns = columns; 353 mColumns = columns;
354 computeSizes(); 354 computeSizes();
355} 355}
356 356
357/* 357/*
358 This is the eventFilter function, which gets all events from the KOAgendaItems 358 This is the eventFilter function, which gets all events from the KOAgendaItems
359 contained in the agenda. It has to handle moving and resizing for all items. 359 contained in the agenda. It has to handle moving and resizing for all items.
360*/ 360*/
361bool KOAgenda::eventFilter ( QObject *object, QEvent *event ) 361bool KOAgenda::eventFilter ( QObject *object, QEvent *event )
362{ 362{
363 // kdDebug() << "KOAgenda::eventFilter" << endl; 363 // kdDebug() << "KOAgenda::eventFilter" << endl;
364 switch(event->type()) { 364 switch(event->type()) {
365 case QEvent::MouseButtonPress: 365 case QEvent::MouseButtonPress:
366 case QEvent::MouseButtonDblClick: 366 case QEvent::MouseButtonDblClick:
367 case QEvent::MouseButtonRelease: 367 case QEvent::MouseButtonRelease:
368 case QEvent::MouseMove: 368 case QEvent::MouseMove:
369 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event)); 369 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event));
370 370
371 case (QEvent::Leave): 371 case (QEvent::Leave):
372 if (!mActionItem) 372 if (!mActionItem)
373 setCursor(arrowCursor); 373 setCursor(arrowCursor);
374 return true; 374 return true;
375 375
376 default: 376 default:
377 return QScrollView::eventFilter(object,event); 377 return QScrollView::eventFilter(object,event);
378 } 378 }
379} 379}
380void KOAgenda::popupMenu() 380void KOAgenda::popupMenu()
381{ 381{
382 mPopupTimer->stop(); 382 mPopupTimer->stop();
383 if ( mPopupKind == 1 ) { 383 if ( mPopupKind == 1 ) {
384 if (mActionItem ) { 384 if (mActionItem ) {
385 endItemAction(); 385 endItemAction();
386 } 386 }
387 mLeftMouseDown = false; // no more leftMouse computation 387 mLeftMouseDown = false; // no more leftMouse computation
388 if (mPopupItem) { 388 if (mPopupItem) {
389 selectItem(mPopupItem); 389 selectItem(mPopupItem);
390 emit showIncidencePopupSignal(mPopupItem->incidence()); 390 emit showIncidencePopupSignal(mPopupItem->incidence());
391 391
392 } 392 }
393 } else if ( mPopupKind == 2 ) { 393 } else if ( mPopupKind == 2 ) {
394 if ( mLeftMouseDown ) { // we have a simulated right click - clear left mouse action 394 if ( mLeftMouseDown ) { // we have a simulated right click - clear left mouse action
395 endSelectAction( false ); // do not emit new event signal 395 endSelectAction( false ); // do not emit new event signal
396 mLeftMouseDown = false; // no more leftMouse computation 396 mLeftMouseDown = false; // no more leftMouse computation
397 } 397 }
398 mNewItemPopup->popup( mPopupPos); 398 mNewItemPopup->popup( mPopupPos);
399 } 399 }
400 mLeftMouseDown = false; 400 mLeftMouseDown = false;
401 mPopupItem = 0; 401 mPopupItem = 0;
402 mPopupKind = 0; 402 mPopupKind = 0;
403} 403}
404 404
405bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) 405bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me)
406{ 406{
407 //qDebug("KOAgenda::eventFilter_mous "); 407 //qDebug("KOAgenda::eventFilter_mous ");
408 QPoint viewportPos; 408 QPoint viewportPos;
409 if (object != viewport()) { 409 if (object != viewport()) {
410 viewportPos = ((QWidget *)object)->mapToParent(me->pos()); 410 viewportPos = ((QWidget *)object)->mapToParent(me->pos());
411 } else { 411 } else {
412 viewportPos = me->pos(); 412 viewportPos = me->pos();
413 } 413 }
414 static int startX = 0; 414 static int startX = 0;
415 static int startY = 0; 415 static int startY = 0;
416 static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 ); 416 static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 );
417 static bool blockMoving = true; 417 static bool blockMoving = true;
418 switch (me->type()) { 418 switch (me->type()) {
419 case QEvent::MouseButtonPress: 419 case QEvent::MouseButtonPress:
420 if (me->button() == LeftButton) { 420 if (me->button() == LeftButton) {
421 mPopupTimer->start( 600 ); 421 mPopupTimer->start( 600 );
422 mLeftMouseDown = true; 422 mLeftMouseDown = true;
423 } 423 }
424 blockMoving = true; 424 blockMoving = true;
425 startX = viewportPos.x(); 425 startX = viewportPos.x();
426 startY = viewportPos.y(); 426 startY = viewportPos.y();
427 if (object != viewport()) { 427 if (object != viewport()) {
428 mPopupItem = (KOAgendaItem *)object; 428 mPopupItem = (KOAgendaItem *)object;
429 mPopupKind = 1; 429 mPopupKind = 1;
430 if (me->button() == RightButton) { 430 if (me->button() == RightButton) {
431 popupMenu(); 431 popupMenu();
432 } else if (me->button() == LeftButton) { 432 } else if (me->button() == LeftButton) {
433 mActionItem = (KOAgendaItem *)object; 433 mActionItem = (KOAgendaItem *)object;
434 if (mActionItem) { 434 if (mActionItem) {
435 if ( mSelectionHeight > 0 ) { 435 if ( mSelectionHeight > 0 ) {
436 int selectionCellX = mSelectionCellX * mGridSpacingX; 436 int selectionCellX = mSelectionCellX * mGridSpacingX;
437 int selectionYTop = mSelectionYTop; 437 int selectionYTop = mSelectionYTop;
438 int gridSpacingX = mGridSpacingX; 438 int gridSpacingX = mGridSpacingX;
439 int selectionHeight = mSelectionHeight; 439 int selectionHeight = mSelectionHeight;
440 clearSelection(); 440 clearSelection();
441 repaintContents( selectionCellX, selectionYTop, 441 repaintContents( selectionCellX, selectionYTop,
442 gridSpacingX, selectionHeight,false ); 442 gridSpacingX, selectionHeight,false );
443 } 443 }
444 selectItem(mActionItem); 444 selectItem(mActionItem);
445 Incidence *incidence = mActionItem->incidence(); 445 Incidence *incidence = mActionItem->incidence();
446 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { 446 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) {
447 mActionItem = 0; 447 mActionItem = 0;
448 } else { 448 } else {
449 startItemAction(viewportPos); 449 startItemAction(viewportPos);
450 } 450 }
451 } 451 }
452 } 452 }
453 } else { // ---------- viewport() 453 } else { // ---------- viewport()
454 mPopupItem = 0; 454 mPopupItem = 0;
455 mPopupKind = 2; 455 mPopupKind = 2;
456 selectItem(0); 456 selectItem(0);
457 mActionItem = 0; 457 mActionItem = 0;
458 mPopupPos = viewport()->mapToGlobal( me->pos() ); 458 mPopupPos = viewport()->mapToGlobal( me->pos() );
459 if (me->button() == RightButton) { 459 if (me->button() == RightButton) {
460 int x,y; 460 int x,y;
461 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 461 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
462 int gx,gy; 462 int gx,gy;
463 contentsToGrid(x,y,gx,gy); 463 contentsToGrid(x,y,gx,gy);
464 mCurrentCellX = gx; 464 mCurrentCellX = gx;
465 mCurrentCellY = gy; 465 mCurrentCellY = gy;
466 mStartCellX = gx; 466 mStartCellX = gx;
467 mStartCellY = gy; 467 mStartCellY = gy;
468 popupMenu(); 468 popupMenu();
469 } else if (me->button() == LeftButton) { 469 } else if (me->button() == LeftButton) {
470 setCursor(arrowCursor); 470 setCursor(arrowCursor);
471 startSelectAction(viewportPos); 471 startSelectAction(viewportPos);
472 } 472 }
473 } 473 }
474 break; 474 break;
475 475
476 case QEvent::MouseButtonRelease: 476 case QEvent::MouseButtonRelease:
477 if (me->button() == LeftButton ) { 477 if (me->button() == LeftButton ) {
478 mPopupTimer->stop(); 478 mPopupTimer->stop();
479 } 479 }
480 if (object != viewport()) { 480 if (object != viewport()) {
481 if (me->button() == LeftButton && mLeftMouseDown) { 481 if (me->button() == LeftButton && mLeftMouseDown) {
482 if (mActionItem) { 482 if (mActionItem) {
483 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 483 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos));
484 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); 484 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 );
485 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { 485 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) {
486 mScrollUpTimer.stop(); 486 mScrollUpTimer.stop();
487 mScrollDownTimer.stop(); 487 mScrollDownTimer.stop();
488 mActionItem->resetMove(); 488 mActionItem->resetMove();
489 placeSubCells( mActionItem ); 489 placeSubCells( mActionItem );
490 // emit startDragSignal( mActionItem->incidence() ); 490 // emit startDragSignal( mActionItem->incidence() );
491 setCursor( arrowCursor ); 491 setCursor( arrowCursor );
492 mActionItem = 0; 492 mActionItem = 0;
493 mActionType = NOP; 493 mActionType = NOP;
494 mItemMoved = 0; 494 mItemMoved = 0;
495 mLeftMouseDown = false; 495 mLeftMouseDown = false;
496 return true; 496 return true;
497 } 497 }
498 endItemAction(); 498 endItemAction();
499 } 499 }
500 } 500 }
501 501
502 } else { // ---------- viewport() 502 } else { // ---------- viewport()
503 if (me->button() == LeftButton && mLeftMouseDown ) { //left click 503 if (me->button() == LeftButton && mLeftMouseDown ) { //left click
504 endSelectAction( true ); // emit new event signal 504 endSelectAction( true ); // emit new event signal
505 } 505 }
506 } 506 }
507 if (me->button() == LeftButton) 507 if (me->button() == LeftButton)
508 mLeftMouseDown = false; 508 mLeftMouseDown = false;
509 509
510 break; 510 break;
511 511
512 case QEvent::MouseMove: 512 case QEvent::MouseMove:
513 if ( !mLeftMouseDown ) 513 if ( !mLeftMouseDown )
514 return true; 514 return true;
515 if ( blockMoving ) { 515 if ( blockMoving ) {
516 int dX, dY; 516 int dX, dY;
517 dX = startX - viewportPos.x(); 517 dX = startX - viewportPos.x();
518 if ( dX < 0 ) 518 if ( dX < 0 )
519 dX = -dX; 519 dX = -dX;
520 dY = viewportPos.y() - startY; 520 dY = viewportPos.y() - startY;
521 if ( dY < 0 ) 521 if ( dY < 0 )
522 dY = -dY; 522 dY = -dY;
523 //qDebug("%d %d %d ", dX, dY , blockmoveDist ); 523 //qDebug("%d %d %d ", dX, dY , blockmoveDist );
524 if ( dX > blockmoveDist || dY > blockmoveDist ) { 524 if ( dX > blockmoveDist || dY > blockmoveDist ) {
525 blockMoving = false; 525 blockMoving = false;
526 } 526 }
527 } 527 }
528 if ( ! blockMoving ) 528 if ( ! blockMoving )
529 mPopupTimer->stop(); 529 mPopupTimer->stop();
530 if (object != viewport()) { 530 if (object != viewport()) {
531 KOAgendaItem *moveItem = (KOAgendaItem *)object; 531 KOAgendaItem *moveItem = (KOAgendaItem *)object;
532 if (!moveItem->incidence()->isReadOnly() ) { 532 if (!moveItem->incidence()->isReadOnly() ) {
533 if (!mActionItem) 533 if (!mActionItem)
534 setNoActionCursor(moveItem,viewportPos); 534 setNoActionCursor(moveItem,viewportPos);
535 else { 535 else {
536 if ( !blockMoving ) 536 if ( !blockMoving )
537 performItemAction(viewportPos); 537 performItemAction(viewportPos);
538 } 538 }
539 } 539 }
540 } else { // ---------- viewport() 540 } else { // ---------- viewport()
541 mPopupPos = viewport()->mapToGlobal( me->pos() ); 541 mPopupPos = viewport()->mapToGlobal( me->pos() );
542 if ( mActionType == SELECT ) { 542 if ( mActionType == SELECT ) {
543 performSelectAction( viewportPos ); 543 performSelectAction( viewportPos );
544 } 544 }
545 } 545 }
546 break; 546 break;
547 547
548 case QEvent::MouseButtonDblClick: 548 case QEvent::MouseButtonDblClick:
549 mPopupTimer->stop(); 549 mPopupTimer->stop();
550 if (object == viewport()) { 550 if (object == viewport()) {
551 selectItem(0); 551 selectItem(0);
552 int x,y; 552 int x,y;
553 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 553 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
554 int gx,gy; 554 int gx,gy;
555 contentsToGrid(x,y,gx,gy); 555 contentsToGrid(x,y,gx,gy);
556 emit newEventSignal(gx,gy); 556 emit newEventSignal(gx,gy);
557 } else { 557 } else {
558 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; 558 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object;
559 selectItem(doubleClickedItem); 559 selectItem(doubleClickedItem);
560 if ( KOPrefs::instance()->mEditOnDoubleClick ) 560 if ( KOPrefs::instance()->mEditOnDoubleClick )
561 emit editIncidenceSignal(doubleClickedItem->incidence()); 561 emit editIncidenceSignal(doubleClickedItem->incidence());
562 else 562 else
563 emit showIncidenceSignal(doubleClickedItem->incidence()); 563 emit showIncidenceSignal(doubleClickedItem->incidence());
564 } 564 }
565 break; 565 break;
566 566
567 default: 567 default:
568 break; 568 break;
569 } 569 }
570 return true; 570 return true;
571#if 0 571#if 0
572 //qDebug("KOAgenda::eventFilter_mous "); 572 //qDebug("KOAgenda::eventFilter_mous ");
573 QPoint viewportPos; 573 QPoint viewportPos;
574 if (object != viewport()) { 574 if (object != viewport()) {
575 viewportPos = ((QWidget *)object)->mapToParent(me->pos()); 575 viewportPos = ((QWidget *)object)->mapToParent(me->pos());
576 } else { 576 } else {
577 viewportPos = me->pos(); 577 viewportPos = me->pos();
578 } 578 }
579 static int startX = 0; 579 static int startX = 0;
580 static int startY = 0; 580 static int startY = 0;
581 static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 ); 581 static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 );
582 static bool blockMoving = true; 582 static bool blockMoving = true;
583 static bool leftMouseDown = false; 583 static bool leftMouseDown = false;
584 bool rightButtonPressed = false; 584 bool rightButtonPressed = false;
585 switch (me->type()) { 585 switch (me->type()) {
586 case QEvent::MouseButtonPress: 586 case QEvent::MouseButtonPress:
587 if (me->button() == LeftButton) { 587 if (me->button() == LeftButton) {
588 leftMouseDown = true; 588 leftMouseDown = true;
589 } 589 }
590 else if (me->button() == RightButton) { 590 else if (me->button() == RightButton) {
591 leftMouseDown = false; 591 leftMouseDown = false;
592 } 592 }
593 blockMoving = true; 593 blockMoving = true;
594 startX = viewportPos.x(); 594 startX = viewportPos.x();
595 startY = viewportPos.y(); 595 startY = viewportPos.y();
596 if (object != viewport()) { // item clicked ************** 596 if (object != viewport()) { // item clicked **************
597 if (me->button() == RightButton) { 597 if (me->button() == RightButton) {
598 leftMouseDown = false; 598 leftMouseDown = false;
599 mClickedItem = (KOAgendaItem *)object; 599 mClickedItem = (KOAgendaItem *)object;
600 if (mActionItem ) { 600 if (mActionItem ) {
601 endItemAction(); 601 endItemAction();
602 } 602 }
603 if (mClickedItem) { 603 if (mClickedItem) {
604 selectItem(mClickedItem); 604 selectItem(mClickedItem);
605 emit showIncidencePopupSignal(mClickedItem->incidence()); 605 emit showIncidencePopupSignal(mClickedItem->incidence());
606 } 606 }
607 return true; 607 return true;
608 } else if (me->button() == LeftButton) { 608 } else if (me->button() == LeftButton) {
609 mActionItem = (KOAgendaItem *)object; 609 mActionItem = (KOAgendaItem *)object;
610 if (mActionItem) { 610 if (mActionItem) {
611 if ( mSelectionHeight > 0 ) { 611 if ( mSelectionHeight > 0 ) {
612 int selectionCellX = mSelectionCellX * mGridSpacingX; 612 int selectionCellX = mSelectionCellX * mGridSpacingX;
613 int selectionYTop = mSelectionYTop; 613 int selectionYTop = mSelectionYTop;
614 int gridSpacingX = mGridSpacingX; 614 int gridSpacingX = mGridSpacingX;
615 int selectionHeight = mSelectionHeight; 615 int selectionHeight = mSelectionHeight;
616 clearSelection(); 616 clearSelection();
617 repaintContents( selectionCellX, selectionYTop, 617 repaintContents( selectionCellX, selectionYTop,
618 gridSpacingX, selectionHeight,false ); 618 gridSpacingX, selectionHeight,false );
619 } 619 }
620 selectItem(mActionItem); 620 selectItem(mActionItem);
621 Incidence *incidence = mActionItem->incidence(); 621 Incidence *incidence = mActionItem->incidence();
622 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { 622 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) {
623 mActionItem = 0; 623 mActionItem = 0;
624 } else { 624 } else {
625 startItemAction(viewportPos); 625 startItemAction(viewportPos);
626 } 626 }
627 } 627 }
628 } 628 }
629 } else { // ---------- viewport() 629 } else { // ---------- viewport()
630 selectItem(0); 630 selectItem(0);
631 mActionItem = 0; 631 mActionItem = 0;
632 if (me->button() == LeftButton ) { 632 if (me->button() == LeftButton ) {
633 setCursor(arrowCursor); 633 setCursor(arrowCursor);
634 startSelectAction(viewportPos); 634 startSelectAction(viewportPos);
635 } else if (me->button() == RightButton ) { 635 } else if (me->button() == RightButton ) {
636 setCursor(arrowCursor); 636 setCursor(arrowCursor);
637 if ( leftMouseDown ) { // we have a simulated right click - clear left mouse action 637 if ( leftMouseDown ) { // we have a simulated right click - clear left mouse action
638 endSelectAction( false ); // do not emit new event signal 638 endSelectAction( false ); // do not emit new event signal
639 leftMouseDown = false; // no more leftMouse computation 639 leftMouseDown = false; // no more leftMouse computation
640 } 640 }
641 int x,y; 641 int x,y;
642 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 642 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
643 int gx,gy; 643 int gx,gy;
644 contentsToGrid(x,y,gx,gy); 644 contentsToGrid(x,y,gx,gy);
645 mCurrentCellX = gx; 645 mCurrentCellX = gx;
646 mCurrentCellY = gy; 646 mCurrentCellY = gy;
647 mStartCellX = gx; 647 mStartCellX = gx;
648 mStartCellY = gy; 648 mStartCellY = gy;
649 mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) ); 649 mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) );
650 } 650 }
651 } 651 }
652 break; 652 break;
653 653
654 case QEvent::MouseButtonRelease: 654 case QEvent::MouseButtonRelease:
655 655
656 if (object != viewport()) { 656 if (object != viewport()) {
657 if (me->button() == LeftButton && leftMouseDown) { 657 if (me->button() == LeftButton && leftMouseDown) {
658 if (mActionItem) { 658 if (mActionItem) {
659 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 659 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos));
660 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); 660 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 );
661 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { 661 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) {
662 mScrollUpTimer.stop(); 662 mScrollUpTimer.stop();
663 mScrollDownTimer.stop(); 663 mScrollDownTimer.stop();
664 mActionItem->resetMove(); 664 mActionItem->resetMove();
665 placeSubCells( mActionItem ); 665 placeSubCells( mActionItem );
666 // emit startDragSignal( mActionItem->incidence() ); 666 // emit startDragSignal( mActionItem->incidence() );
667 setCursor( arrowCursor ); 667 setCursor( arrowCursor );
668 mActionItem = 0; 668 mActionItem = 0;
669 mActionType = NOP; 669 mActionType = NOP;
670 mItemMoved = 0; 670 mItemMoved = 0;
671 leftMouseDown = false; 671 leftMouseDown = false;
672 return true; 672 return true;
673 } 673 }
674 endItemAction(); 674 endItemAction();
675 } 675 }
676 } 676 }
677 677
678 } else { // ---------- viewport() 678 } else { // ---------- viewport()
679 if (me->button() == LeftButton && leftMouseDown ) { //left click 679 if (me->button() == LeftButton && leftMouseDown ) { //left click
680 endSelectAction( true ); // emit new event signal 680 endSelectAction( true ); // emit new event signal
681 } 681 }
682 } 682 }
683 if (me->button() == LeftButton) 683 if (me->button() == LeftButton)
684 leftMouseDown = false; 684 leftMouseDown = false;
685 685
686 break; 686 break;
687 687
688 case QEvent::MouseMove: 688 case QEvent::MouseMove:
689 if ( !leftMouseDown ) 689 if ( !leftMouseDown )
690 return true; 690 return true;
691 if ( blockMoving ) { 691 if ( blockMoving ) {
692 int dX, dY; 692 int dX, dY;
693 dX = startX - viewportPos.x(); 693 dX = startX - viewportPos.x();
694 if ( dX < 0 ) 694 if ( dX < 0 )
695 dX = -dX; 695 dX = -dX;
696 dY = viewportPos.y() - startY; 696 dY = viewportPos.y() - startY;
697 if ( dY < 0 ) 697 if ( dY < 0 )
698 dY = -dY; 698 dY = -dY;
699 //qDebug("%d %d %d ", dX, dY , blockmoveDist ); 699 //qDebug("%d %d %d ", dX, dY , blockmoveDist );
700 if ( dX > blockmoveDist || dY > blockmoveDist ) { 700 if ( dX > blockmoveDist || dY > blockmoveDist ) {
701 blockMoving = false; 701 blockMoving = false;
702 } 702 }
703 } 703 }
704 if (object != viewport()) { 704 if (object != viewport()) {
705 KOAgendaItem *moveItem = (KOAgendaItem *)object; 705 KOAgendaItem *moveItem = (KOAgendaItem *)object;
706 if (!moveItem->incidence()->isReadOnly() ) { 706 if (!moveItem->incidence()->isReadOnly() ) {
707 if (!mActionItem) 707 if (!mActionItem)
708 setNoActionCursor(moveItem,viewportPos); 708 setNoActionCursor(moveItem,viewportPos);
709 else { 709 else {
710 if ( !blockMoving ) 710 if ( !blockMoving )
711 performItemAction(viewportPos); 711 performItemAction(viewportPos);
712 } 712 }
713 } 713 }
714 } else { // ---------- viewport() 714 } else { // ---------- viewport()
715 if ( mActionType == SELECT ) { 715 if ( mActionType == SELECT ) {
716 performSelectAction( viewportPos ); 716 performSelectAction( viewportPos );
717 } 717 }
718 } 718 }
719 break; 719 break;
720 720
721 case QEvent::MouseButtonDblClick: 721 case QEvent::MouseButtonDblClick:
722 blockMoving = false; 722 blockMoving = false;
723 leftMouseDown = false; 723 leftMouseDown = false;
724 if (object == viewport()) { 724 if (object == viewport()) {
725 selectItem(0); 725 selectItem(0);
726 int x,y; 726 int x,y;
727 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 727 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
728 int gx,gy; 728 int gx,gy;
729 contentsToGrid(x,y,gx,gy); 729 contentsToGrid(x,y,gx,gy);
730 emit newEventSignal(gx,gy); 730 emit newEventSignal(gx,gy);
731 } else { 731 } else {
732 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; 732 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object;
733 selectItem(doubleClickedItem); 733 selectItem(doubleClickedItem);
734 if ( KOPrefs::instance()->mEditOnDoubleClick ) 734 if ( KOPrefs::instance()->mEditOnDoubleClick )
735 emit editIncidenceSignal(doubleClickedItem->incidence()); 735 emit editIncidenceSignal(doubleClickedItem->incidence());
736 else 736 else
737 emit showIncidenceSignal(doubleClickedItem->incidence()); 737 emit showIncidenceSignal(doubleClickedItem->incidence());
738 } 738 }
739 break; 739 break;
740 740
741 default: 741 default:
742 break; 742 break;
743 } 743 }
744 return true; 744 return true;
745#endif 745#endif
746} 746}
747 747
748void KOAgenda::newItem( int item ) 748void KOAgenda::newItem( int item )
749{ 749{
750 if ( item == 1 ) { //new event 750 if ( item == 1 ) { //new event
751 newEventSignal(mStartCellX ,mStartCellY ); 751 newEventSignal(mStartCellX ,mStartCellY );
752 } else 752 } else
753 if ( item == 2 ) { //new event 753 if ( item == 2 ) { //new event
754 newTodoSignal(mStartCellX ,mStartCellY ); 754 newTodoSignal(mStartCellX ,mStartCellY );
755 } else 755 } else
756 { 756 {
757 QDate day = mSelectedDates[mStartCellX]; 757 emit showDateView( item, mStartCellX );
758 emit showDateView( item, day );
759 // 3Day view 758 // 3Day view
760 // 4Week view 759 // 4Week view
761 // 5Month view 760 // 5Month view
762 // 6Journal view 761 // 6Journal view
763 } 762 }
764} 763}
765void KOAgenda::startSelectAction(QPoint viewportPos) 764void KOAgenda::startSelectAction(QPoint viewportPos)
766{ 765{
767 //emit newStartSelectSignal(); 766 //emit newStartSelectSignal();
768 767
769 mActionType = SELECT; 768 mActionType = SELECT;
770 769
771 int x,y; 770 int x,y;
772 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 771 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
773 int gx,gy; 772 int gx,gy;
774 contentsToGrid(x,y,gx,gy); 773 contentsToGrid(x,y,gx,gy);
775 774
776 mStartCellX = gx; 775 mStartCellX = gx;
777 mStartCellY = gy; 776 mStartCellY = gy;
778 mCurrentCellX = gx; 777 mCurrentCellX = gx;
779 mCurrentCellY = gy; 778 mCurrentCellY = gy;
780 779
781 // Store coordinates of old selection 780 // Store coordinates of old selection
782 int selectionX = mSelectionCellX * mGridSpacingX; 781 int selectionX = mSelectionCellX * mGridSpacingX;
783 int selectionYTop = mSelectionYTop; 782 int selectionYTop = mSelectionYTop;
784 int selectionHeight = mSelectionHeight; 783 int selectionHeight = mSelectionHeight;
785 784
786 // Store new selection 785 // Store new selection
787 mSelectionCellX = gx; 786 mSelectionCellX = gx;
788 mSelectionYTop = gy * mGridSpacingY; 787 mSelectionYTop = gy * mGridSpacingY;
789 mSelectionHeight = mGridSpacingY; 788 mSelectionHeight = mGridSpacingY;
790 789
791 // Clear old selection 790 // Clear old selection
792 repaintContents( selectionX, selectionYTop, 791 repaintContents( selectionX, selectionYTop,
793 mGridSpacingX, selectionHeight,false ); 792 mGridSpacingX, selectionHeight,false );
794 793
795 // Paint new selection 794 // Paint new selection
796 // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop, 795 // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop,
797 // mGridSpacingX, mSelectionHeight ); 796 // mGridSpacingX, mSelectionHeight );
798} 797}
799 798
800void KOAgenda::performSelectAction(QPoint viewportPos) 799void KOAgenda::performSelectAction(QPoint viewportPos)
801{ 800{
802 int x,y; 801 int x,y;
803 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 802 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
804 int gx,gy; 803 int gx,gy;
805 contentsToGrid(x,y,gx,gy); 804 contentsToGrid(x,y,gx,gy);
806 805
807 QPoint clipperPos = clipper()-> 806 QPoint clipperPos = clipper()->
808 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 807 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
809 808
810 // Scroll if cursor was moved to upper or lower end of agenda. 809 // Scroll if cursor was moved to upper or lower end of agenda.
811 if (clipperPos.y() < mScrollBorderWidth) { 810 if (clipperPos.y() < mScrollBorderWidth) {
812 mScrollUpTimer.start(mScrollDelay); 811 mScrollUpTimer.start(mScrollDelay);
813 } else if (visibleHeight() - clipperPos.y() < 812 } else if (visibleHeight() - clipperPos.y() <
814 mScrollBorderWidth) { 813 mScrollBorderWidth) {
815 mScrollDownTimer.start(mScrollDelay); 814 mScrollDownTimer.start(mScrollDelay);
816 } else { 815 } else {
817 mScrollUpTimer.stop(); 816 mScrollUpTimer.stop();
818 mScrollDownTimer.stop(); 817 mScrollDownTimer.stop();
819 } 818 }
820 819
821 if ( gy > mCurrentCellY ) { 820 if ( gy > mCurrentCellY ) {
822 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 821 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
823 822
824#if 0 823#if 0
825 // FIXME: Repaint only the newly selected region 824 // FIXME: Repaint only the newly selected region
826 repaintContents( mSelectionCellX * mGridSpacingX, 825 repaintContents( mSelectionCellX * mGridSpacingX,
827 mCurrentCellY + mGridSpacingY, 826 mCurrentCellY + mGridSpacingY,
828 mGridSpacingX, 827 mGridSpacingX,
829 mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY ); 828 mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY );
830#else 829#else
831 repaintContents( (KOGlobals::self()->reverseLayout() ? 830 repaintContents( (KOGlobals::self()->reverseLayout() ?
832 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 831 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
833 mGridSpacingX, mSelectionYTop, 832 mGridSpacingX, mSelectionYTop,
834 mGridSpacingX, mSelectionHeight , false); 833 mGridSpacingX, mSelectionHeight , false);
835#endif 834#endif
836 835
837 mCurrentCellY = gy; 836 mCurrentCellY = gy;
838 } else if ( gy < mCurrentCellY ) { 837 } else if ( gy < mCurrentCellY ) {
839 if ( gy >= mStartCellY ) { 838 if ( gy >= mStartCellY ) {
840 int selectionHeight = mSelectionHeight; 839 int selectionHeight = mSelectionHeight;
841 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 840 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
842 841
843 repaintContents( (KOGlobals::self()->reverseLayout() ? 842 repaintContents( (KOGlobals::self()->reverseLayout() ?
844 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 843 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
845 mGridSpacingX, mSelectionYTop, 844 mGridSpacingX, mSelectionYTop,
846 mGridSpacingX, selectionHeight,false ); 845 mGridSpacingX, selectionHeight,false );
847 846
848 mCurrentCellY = gy; 847 mCurrentCellY = gy;
849 } else { 848 } else {
850 } 849 }
851 } 850 }
852} 851}
853 852
854void KOAgenda::endSelectAction( bool emitNewEvent ) 853void KOAgenda::endSelectAction( bool emitNewEvent )
855{ 854{
856 mActionType = NOP; 855 mActionType = NOP;
857 mScrollUpTimer.stop(); 856 mScrollUpTimer.stop();
858 mScrollDownTimer.stop(); 857 mScrollDownTimer.stop();
859 858
860 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); 859 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
861 if ( emitNewEvent && mStartCellY < mCurrentCellY ) { 860 if ( emitNewEvent && mStartCellY < mCurrentCellY ) {
862 qDebug("ew event signal "); 861 qDebug("ew event signal ");
863 emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); 862 emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
864 } 863 }
865} 864}
866 865
867void KOAgenda::startItemAction(QPoint viewportPos) 866void KOAgenda::startItemAction(QPoint viewportPos)
868{ 867{
869 int x,y; 868 int x,y;
870 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 869 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
871 int gx,gy; 870 int gx,gy;
872 contentsToGrid(x,y,gx,gy); 871 contentsToGrid(x,y,gx,gy);
873 872
874 mStartCellX = gx; 873 mStartCellX = gx;
875 mStartCellY = gy; 874 mStartCellY = gy;
876 mCurrentCellX = gx; 875 mCurrentCellX = gx;
877 mCurrentCellY = gy; 876 mCurrentCellY = gy;
878 877
879 if (mAllDayMode) { 878 if (mAllDayMode) {
880 int gridDistanceX = (x - gx * mGridSpacingX); 879 int gridDistanceX = (x - gx * mGridSpacingX);
881 if (gridDistanceX < mResizeBorderWidth && 880 if (gridDistanceX < mResizeBorderWidth &&
882 mActionItem->cellX() == mCurrentCellX) { 881 mActionItem->cellX() == mCurrentCellX) {
883 mActionType = RESIZELEFT; 882 mActionType = RESIZELEFT;
884 setCursor(sizeHorCursor); 883 setCursor(sizeHorCursor);
885 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 884 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
886 mActionItem->cellXWidth() == mCurrentCellX) { 885 mActionItem->cellXWidth() == mCurrentCellX) {
887 mActionType = RESIZERIGHT; 886 mActionType = RESIZERIGHT;
888 setCursor(sizeHorCursor); 887 setCursor(sizeHorCursor);
889 } else { 888 } else {
890 mActionType = MOVE; 889 mActionType = MOVE;
891 mActionItem->startMove(); 890 mActionItem->startMove();
892 setCursor(sizeAllCursor); 891 setCursor(sizeAllCursor);
893 } 892 }
894 } else { 893 } else {
895 int gridDistanceY = (y - gy * mGridSpacingY); 894 int gridDistanceY = (y - gy * mGridSpacingY);
896 bool allowResize = ( mActionItem->incidence()->type() != "Todo" ); 895 bool allowResize = ( mActionItem->incidence()->type() != "Todo" );
897 if (allowResize && gridDistanceY < mResizeBorderWidth && 896 if (allowResize && gridDistanceY < mResizeBorderWidth &&
898 mActionItem->cellYTop() == mCurrentCellY && 897 mActionItem->cellYTop() == mCurrentCellY &&
899 !mActionItem->firstMultiItem()) { 898 !mActionItem->firstMultiItem()) {
900 mActionType = RESIZETOP; 899 mActionType = RESIZETOP;
901 setCursor(sizeVerCursor); 900 setCursor(sizeVerCursor);
902 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 901 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
903 mActionItem->cellYBottom() == mCurrentCellY && 902 mActionItem->cellYBottom() == mCurrentCellY &&
904 !mActionItem->lastMultiItem()) { 903 !mActionItem->lastMultiItem()) {
905 mActionType = RESIZEBOTTOM; 904 mActionType = RESIZEBOTTOM;
906 setCursor(sizeVerCursor); 905 setCursor(sizeVerCursor);
907 } else { 906 } else {
908 mActionType = MOVE; 907 mActionType = MOVE;
909 mActionItem->startMove(); 908 mActionItem->startMove();
910 setCursor(sizeAllCursor); 909 setCursor(sizeAllCursor);
911 } 910 }
912 } 911 }
913} 912}
914 913
915void KOAgenda::performItemAction(QPoint viewportPos) 914void KOAgenda::performItemAction(QPoint viewportPos)
916{ 915{
917// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 916// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
918// QPoint point = viewport()->mapToGlobal(viewportPos); 917// QPoint point = viewport()->mapToGlobal(viewportPos);
919// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 918// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
920// point = clipper()->mapFromGlobal(point); 919// point = clipper()->mapFromGlobal(point);
921// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 920// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
922// kdDebug() << "visible height: " << visibleHeight() << endl; 921// kdDebug() << "visible height: " << visibleHeight() << endl;
923 int x,y; 922 int x,y;
924 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 923 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
925// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 924// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
926 int gx,gy; 925 int gx,gy;
927 contentsToGrid(x,y,gx,gy); 926 contentsToGrid(x,y,gx,gy);
928 QPoint clipperPos = clipper()-> 927 QPoint clipperPos = clipper()->
929 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 928 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
930 929
931 // Cursor left active agenda area. 930 // Cursor left active agenda area.
932 // This starts a drag. 931 // This starts a drag.
933 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/ 932 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/
934 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) { 933 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) {
935 if ( mActionType == MOVE ) { 934 if ( mActionType == MOVE ) {
936 mScrollUpTimer.stop(); 935 mScrollUpTimer.stop();
937 mScrollDownTimer.stop(); 936 mScrollDownTimer.stop();
938 mActionItem->resetMove(); 937 mActionItem->resetMove();
939 placeSubCells( mActionItem ); 938 placeSubCells( mActionItem );
940 // emit startDragSignal( mActionItem->incidence() ); 939 // emit startDragSignal( mActionItem->incidence() );
941 setCursor( arrowCursor ); 940 setCursor( arrowCursor );
942 mActionItem = 0; 941 mActionItem = 0;
943 mActionType = NOP; 942 mActionType = NOP;
944 mItemMoved = 0; 943 mItemMoved = 0;
945 return; 944 return;
946 } 945 }
947 } else { 946 } else {
948 switch ( mActionType ) { 947 switch ( mActionType ) {
949 case MOVE: 948 case MOVE:
950 setCursor( sizeAllCursor ); 949 setCursor( sizeAllCursor );
951 break; 950 break;
952 case RESIZETOP: 951 case RESIZETOP:
953 case RESIZEBOTTOM: 952 case RESIZEBOTTOM:
954 setCursor( sizeVerCursor ); 953 setCursor( sizeVerCursor );
955 break; 954 break;
956 case RESIZELEFT: 955 case RESIZELEFT:
957 case RESIZERIGHT: 956 case RESIZERIGHT:
958 setCursor( sizeHorCursor ); 957 setCursor( sizeHorCursor );
959 break; 958 break;
960 default: 959 default:
961 setCursor( arrowCursor ); 960 setCursor( arrowCursor );
962 } 961 }
963 } 962 }
964 963
965 // Scroll if item was moved to upper or lower end of agenda. 964 // Scroll if item was moved to upper or lower end of agenda.
966 if (clipperPos.y() < mScrollBorderWidth) { 965 if (clipperPos.y() < mScrollBorderWidth) {
967 mScrollUpTimer.start(mScrollDelay); 966 mScrollUpTimer.start(mScrollDelay);
968 } else if (visibleHeight() - clipperPos.y() < 967 } else if (visibleHeight() - clipperPos.y() <
969 mScrollBorderWidth) { 968 mScrollBorderWidth) {
970 mScrollDownTimer.start(mScrollDelay); 969 mScrollDownTimer.start(mScrollDelay);
971 } else { 970 } else {
972 mScrollUpTimer.stop(); 971 mScrollUpTimer.stop();
973 mScrollDownTimer.stop(); 972 mScrollDownTimer.stop();
974 } 973 }
975 974
976 // Move or resize item if necessary 975 // Move or resize item if necessary
977 if (mCurrentCellX != gx || mCurrentCellY != gy) { 976 if (mCurrentCellX != gx || mCurrentCellY != gy) {
978 mItemMoved = true; 977 mItemMoved = true;
979 mActionItem->raise(); 978 mActionItem->raise();
980 if (mActionType == MOVE) { 979 if (mActionType == MOVE) {
981 // Move all items belonging to a multi item 980 // Move all items belonging to a multi item
982 KOAgendaItem *moveItem = mActionItem->firstMultiItem(); 981 KOAgendaItem *moveItem = mActionItem->firstMultiItem();
983 bool isMultiItem = (moveItem || mActionItem->lastMultiItem()); 982 bool isMultiItem = (moveItem || mActionItem->lastMultiItem());
984 if (!moveItem) moveItem = mActionItem; 983 if (!moveItem) moveItem = mActionItem;
985 while (moveItem) { 984 while (moveItem) {
986 int dy; 985 int dy;
987 if (isMultiItem) dy = 0; 986 if (isMultiItem) dy = 0;
988 else dy = gy - mCurrentCellY; 987 else dy = gy - mCurrentCellY;
989 moveItem->moveRelative(gx - mCurrentCellX,dy); 988 moveItem->moveRelative(gx - mCurrentCellX,dy);
990 int x,y; 989 int x,y;
991 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y); 990 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y);
992 moveItem->resize(mGridSpacingX * moveItem->cellWidth(), 991 moveItem->resize(mGridSpacingX * moveItem->cellWidth(),
993 mGridSpacingY * moveItem->cellHeight()); 992 mGridSpacingY * moveItem->cellHeight());
994 moveChild(moveItem,x,y); 993 moveChild(moveItem,x,y);
995 moveItem = moveItem->nextMultiItem(); 994 moveItem = moveItem->nextMultiItem();
996 } 995 }
997 } else if (mActionType == RESIZETOP) { 996 } else if (mActionType == RESIZETOP) {
998 if (mCurrentCellY <= mActionItem->cellYBottom()) { 997 if (mCurrentCellY <= mActionItem->cellYBottom()) {
999 mActionItem->expandTop(gy - mCurrentCellY); 998 mActionItem->expandTop(gy - mCurrentCellY);
1000 mActionItem->resize(mActionItem->width(), 999 mActionItem->resize(mActionItem->width(),
1001 mGridSpacingY * mActionItem->cellHeight()); 1000 mGridSpacingY * mActionItem->cellHeight());
1002 int x,y; 1001 int x,y;
1003 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y); 1002 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y);
1004 //moveChild(mActionItem,childX(mActionItem),y); 1003 //moveChild(mActionItem,childX(mActionItem),y);
1005 QScrollView::moveChild( mActionItem,childX(mActionItem),y ); 1004 QScrollView::moveChild( mActionItem,childX(mActionItem),y );
1006 } 1005 }
1007 } else if (mActionType == RESIZEBOTTOM) { 1006 } else if (mActionType == RESIZEBOTTOM) {
1008 if (mCurrentCellY >= mActionItem->cellYTop()) { 1007 if (mCurrentCellY >= mActionItem->cellYTop()) {
1009 mActionItem->expandBottom(gy - mCurrentCellY); 1008 mActionItem->expandBottom(gy - mCurrentCellY);
1010 mActionItem->resize(mActionItem->width(), 1009 mActionItem->resize(mActionItem->width(),
1011 mGridSpacingY * mActionItem->cellHeight()); 1010 mGridSpacingY * mActionItem->cellHeight());
1012 } 1011 }
1013 } else if (mActionType == RESIZELEFT) { 1012 } else if (mActionType == RESIZELEFT) {
1014 if (mCurrentCellX <= mActionItem->cellXWidth()) { 1013 if (mCurrentCellX <= mActionItem->cellXWidth()) {
1015 mActionItem->expandLeft(gx - mCurrentCellX); 1014 mActionItem->expandLeft(gx - mCurrentCellX);
1016 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 1015 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
1017 mActionItem->height()); 1016 mActionItem->height());
1018 int x,y; 1017 int x,y;
1019 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y); 1018 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y);
1020 moveChild(mActionItem,x,childY(mActionItem)); 1019 moveChild(mActionItem,x,childY(mActionItem));
1021 } 1020 }
1022 } else if (mActionType == RESIZERIGHT) { 1021 } else if (mActionType == RESIZERIGHT) {
1023 if (mCurrentCellX >= mActionItem->cellX()) { 1022 if (mCurrentCellX >= mActionItem->cellX()) {
1024 mActionItem->expandRight(gx - mCurrentCellX); 1023 mActionItem->expandRight(gx - mCurrentCellX);
1025 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 1024 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
1026 mActionItem->height()); 1025 mActionItem->height());
1027 } 1026 }
1028 } 1027 }
1029 mCurrentCellX = gx; 1028 mCurrentCellX = gx;
1030 mCurrentCellY = gy; 1029 mCurrentCellY = gy;
1031 } 1030 }
1032} 1031}
1033 1032
1034void KOAgenda::endItemAction() 1033void KOAgenda::endItemAction()
1035{ 1034{
1036 1035
1037 if ( mItemMoved ) { 1036 if ( mItemMoved ) {
1038 KOAgendaItem *placeItem = mActionItem->firstMultiItem(); 1037 KOAgendaItem *placeItem = mActionItem->firstMultiItem();
1039 if ( !placeItem ) { 1038 if ( !placeItem ) {
1040 placeItem = mActionItem; 1039 placeItem = mActionItem;
1041 } 1040 }
1042 if ( placeItem->incidence()->recurrence()->doesRecur() ) { 1041 if ( placeItem->incidence()->recurrence()->doesRecur() ) {
1043 Incidence* oldInc = placeItem->incidence(); 1042 Incidence* oldInc = placeItem->incidence();
1044 placeItem->recreateIncidence(); 1043 placeItem->recreateIncidence();
1045 emit addToCalSignal(placeItem->incidence(), oldInc ); 1044 emit addToCalSignal(placeItem->incidence(), oldInc );
1046 } 1045 }
1047 int type = mActionType; 1046 int type = mActionType;
1048 if ( mAllDayMode ) 1047 if ( mAllDayMode )
1049 type = -1; 1048 type = -1;
1050 KOAgendaItem *modifiedItem = placeItem; 1049 KOAgendaItem *modifiedItem = placeItem;
1051 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */); 1050 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */);
1052 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems(); 1051 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems();
1053 KOAgendaItem *item; 1052 KOAgendaItem *item;
1054 1053
1055 if ( placeItem->incidence()->type() == "Todo" ) { 1054 if ( placeItem->incidence()->type() == "Todo" ) {
1056 mSelectedItem = 0; 1055 mSelectedItem = 0;
1057 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth()); 1056 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth());
1058 modifiedItem->mLastMoveXPos = mCurrentCellX; 1057 modifiedItem->mLastMoveXPos = mCurrentCellX;
1059 emit itemModified( modifiedItem, mActionType ); 1058 emit itemModified( modifiedItem, mActionType );
1060 } 1059 }
1061 else { 1060 else {
1062#if 0 1061#if 0
1063 for ( item=oldconflictItems.first(); item != 0; 1062 for ( item=oldconflictItems.first(); item != 0;
1064 item=oldconflictItems.next() ) { 1063 item=oldconflictItems.next() ) {
1065 placeSubCells(item); 1064 placeSubCells(item);
1066 } 1065 }
1067 while ( placeItem ) { 1066 while ( placeItem ) {
1068 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 1067 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
1069 placeSubCells( placeItem ); 1068 placeSubCells( placeItem );
1070 placeItem = placeItem->nextMultiItem(); 1069 placeItem = placeItem->nextMultiItem();
1071 } 1070 }
1072#endif 1071#endif
1073 1072
1074 globalFlagBlockAgendaItemPaint = 1; 1073 globalFlagBlockAgendaItemPaint = 1;
1075 for ( item=oldconflictItems.first(); item != 0; 1074 for ( item=oldconflictItems.first(); item != 0;
1076 item=oldconflictItems.next() ) { 1075 item=oldconflictItems.next() ) {
1077 placeSubCells(item); 1076 placeSubCells(item);
1078 } 1077 }
1079 while ( placeItem ) { 1078 while ( placeItem ) {
1080 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 1079 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
1081 oldconflictItems = placeItem->conflictItems(); 1080 oldconflictItems = placeItem->conflictItems();
1082 for ( item=oldconflictItems.first(); item != 0; 1081 for ( item=oldconflictItems.first(); item != 0;
1083 item=oldconflictItems.next() ) { 1082 item=oldconflictItems.next() ) {
1084 placeSubCells(item); 1083 placeSubCells(item);
1085 } 1084 }
1086 placeSubCells( placeItem ); 1085 placeSubCells( placeItem );
1087 placeItem = placeItem->nextMultiItem(); 1086 placeItem = placeItem->nextMultiItem();
1088 } 1087 }
1089 globalFlagBlockAgendaItemPaint = 0; 1088 globalFlagBlockAgendaItemPaint = 0;
1090 for ( item=oldconflictItems.first(); item != 0; 1089 for ( item=oldconflictItems.first(); item != 0;
1091 item=oldconflictItems.next() ) { 1090 item=oldconflictItems.next() ) {
1092 globalFlagBlockAgendaItemUpdate = 0; 1091 globalFlagBlockAgendaItemUpdate = 0;
1093 item->repaintMe(); 1092 item->repaintMe();
1094 globalFlagBlockAgendaItemUpdate = 1; 1093 globalFlagBlockAgendaItemUpdate = 1;
1095 item->repaint( false ); 1094 item->repaint( false );
1096 } 1095 }
1097 placeItem = modifiedItem; 1096 placeItem = modifiedItem;
1098 1097
1099 while ( placeItem ) { 1098 while ( placeItem ) {
1100 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 1099 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
1101 globalFlagBlockAgendaItemUpdate = 0; 1100 globalFlagBlockAgendaItemUpdate = 0;
1102 placeItem->repaintMe(); 1101 placeItem->repaintMe();
1103 globalFlagBlockAgendaItemUpdate = 1; 1102 globalFlagBlockAgendaItemUpdate = 1;
1104 placeItem->repaint(false); 1103 placeItem->repaint(false);
1105 placeItem = placeItem->nextMultiItem(); 1104 placeItem = placeItem->nextMultiItem();
1106 } 1105 }
1107 emit itemModified( modifiedItem, mActionType ); 1106 emit itemModified( modifiedItem, mActionType );
1108 1107
1109 1108
1110 placeItem = modifiedItem; 1109 placeItem = modifiedItem;
1111 while ( placeItem ) { 1110 while ( placeItem ) {
1112 oldconflictItems = placeItem->conflictItems(); 1111 oldconflictItems = placeItem->conflictItems();
1113 for ( item=oldconflictItems.first(); item != 0; 1112 for ( item=oldconflictItems.first(); item != 0;
1114 item=oldconflictItems.next() ) { 1113 item=oldconflictItems.next() ) {
1115 placeSubCells(item); 1114 placeSubCells(item);
1116 } 1115 }
1117 placeSubCells( placeItem ); 1116 placeSubCells( placeItem );
1118 placeItem = placeItem->nextMultiItem(); 1117 placeItem = placeItem->nextMultiItem();
1119 1118
1120 } 1119 }
1121 placeItem = modifiedItem; 1120 placeItem = modifiedItem;
1122 while ( placeItem ) { 1121 while ( placeItem ) {
1123 oldconflictItems = placeItem->conflictItems(); 1122 oldconflictItems = placeItem->conflictItems();
1124 for ( item=oldconflictItems.first(); item != 0; 1123 for ( item=oldconflictItems.first(); item != 0;
1125 item=oldconflictItems.next() ) { 1124 item=oldconflictItems.next() ) {
1126 globalFlagBlockAgendaItemUpdate = 0; 1125 globalFlagBlockAgendaItemUpdate = 0;
1127 item->repaintMe(); 1126 item->repaintMe();
1128 globalFlagBlockAgendaItemUpdate = 1; 1127 globalFlagBlockAgendaItemUpdate = 1;
1129 item->repaint(false); 1128 item->repaint(false);
1130 } 1129 }
1131 placeItem = placeItem->nextMultiItem(); 1130 placeItem = placeItem->nextMultiItem();
1132 } 1131 }
1133 /* 1132 /*
1134 1133
1135 oldconflictItems = modifiedItem->conflictItems(); 1134 oldconflictItems = modifiedItem->conflictItems();
1136 for ( item=oldconflictItems.first(); item != 0; 1135 for ( item=oldconflictItems.first(); item != 0;
1137 item=oldconflictItems.next() ) { 1136 item=oldconflictItems.next() ) {
1138 globalFlagBlockAgendaItemUpdate = 0; 1137 globalFlagBlockAgendaItemUpdate = 0;
1139 item->paintMe(false); 1138 item->paintMe(false);
1140 globalFlagBlockAgendaItemUpdate = 1; 1139 globalFlagBlockAgendaItemUpdate = 1;
1141 item->repaint(false); 1140 item->repaint(false);
1142 } 1141 }
1143 */ 1142 */
1144 1143
1145 1144
1146 } 1145 }
1147 1146
1148 } 1147 }
1149 1148
1150 mScrollUpTimer.stop(); 1149 mScrollUpTimer.stop();
1151 mScrollDownTimer.stop(); 1150 mScrollDownTimer.stop();
1152 setCursor( arrowCursor ); 1151 setCursor( arrowCursor );
1153 mActionItem = 0; 1152 mActionItem = 0;
1154 mActionType = NOP; 1153 mActionType = NOP;
1155 mItemMoved = 0; 1154 mItemMoved = 0;
1156 1155
1157} 1156}
1158 1157
1159void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos) 1158void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos)
1160{ 1159{
1161// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 1160// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
1162// QPoint point = viewport()->mapToGlobal(viewportPos); 1161// QPoint point = viewport()->mapToGlobal(viewportPos);
1163// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 1162// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
1164// point = clipper()->mapFromGlobal(point); 1163// point = clipper()->mapFromGlobal(point);
1165// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 1164// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
1166 1165
1167 int x,y; 1166 int x,y;
1168 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 1167 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
1169// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 1168// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
1170 int gx,gy; 1169 int gx,gy;
1171 contentsToGrid(x,y,gx,gy); 1170 contentsToGrid(x,y,gx,gy);
1172 1171
1173 // Change cursor to resize cursor if appropriate 1172 // Change cursor to resize cursor if appropriate
1174 if (mAllDayMode) { 1173 if (mAllDayMode) {
1175 int gridDistanceX = (x - gx * mGridSpacingX); 1174 int gridDistanceX = (x - gx * mGridSpacingX);
1176 if (gridDistanceX < mResizeBorderWidth && 1175 if (gridDistanceX < mResizeBorderWidth &&
1177 moveItem->cellX() == gx) { 1176 moveItem->cellX() == gx) {
1178 setCursor(sizeHorCursor); 1177 setCursor(sizeHorCursor);
1179 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 1178 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
1180 moveItem->cellXWidth() == gx) { 1179 moveItem->cellXWidth() == gx) {
1181 setCursor(sizeHorCursor); 1180 setCursor(sizeHorCursor);
1182 } else { 1181 } else {
1183 setCursor(arrowCursor); 1182 setCursor(arrowCursor);
1184 } 1183 }
1185 } else { 1184 } else {
1186 int gridDistanceY = (y - gy * mGridSpacingY); 1185 int gridDistanceY = (y - gy * mGridSpacingY);
1187 if (gridDistanceY < mResizeBorderWidth && 1186 if (gridDistanceY < mResizeBorderWidth &&
1188 moveItem->cellYTop() == gy && 1187 moveItem->cellYTop() == gy &&
1189 !moveItem->firstMultiItem()) { 1188 !moveItem->firstMultiItem()) {
1190 setCursor(sizeVerCursor); 1189 setCursor(sizeVerCursor);
1191 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 1190 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
1192 moveItem->cellYBottom() == gy && 1191 moveItem->cellYBottom() == gy &&
1193 !moveItem->lastMultiItem()) { 1192 !moveItem->lastMultiItem()) {
1194 setCursor(sizeVerCursor); 1193 setCursor(sizeVerCursor);
1195 } else { 1194 } else {
1196 setCursor(arrowCursor); 1195 setCursor(arrowCursor);
1197 } 1196 }
1198 } 1197 }
1199} 1198}
1200 1199
1201 1200
1202/* 1201/*
1203 Place item in cell and take care that multiple items using the same cell do 1202 Place item in cell and take care that multiple items using the same cell do
1204 not overlap. This method is not yet optimal. It doesn´t use the maximum space 1203 not overlap. This method is not yet optimal. It doesn´t use the maximum space
1205 it can get in all cases. 1204 it can get in all cases.
1206 At the moment the method has a bug: When an item is placed only the sub cell 1205 At the moment the method has a bug: When an item is placed only the sub cell
1207 widths of the items are changed, which are within the Y region the item to 1206 widths of the items are changed, which are within the Y region the item to
1208 place spans. When the sub cell width change of one of this items affects a 1207 place spans. When the sub cell width change of one of this items affects a
1209 cell, where other items are, which do not overlap in Y with the item to place, 1208 cell, where other items are, which do not overlap in Y with the item to place,
1210 the display gets corrupted, although the corruption looks quite nice. 1209 the display gets corrupted, although the corruption looks quite nice.
1211*/ 1210*/
1212void KOAgenda::placeSubCells(KOAgendaItem *placeItem) 1211void KOAgenda::placeSubCells(KOAgendaItem *placeItem)
1213{ 1212{
1214 1213
1215 QPtrList<KOAgendaItem> conflictItems; 1214 QPtrList<KOAgendaItem> conflictItems;
1216 int maxSubCells = 0; 1215 int maxSubCells = 0;
1217 QIntDict<KOAgendaItem> subCellDict(5); 1216 QIntDict<KOAgendaItem> subCellDict(5);
1218 1217
1219 KOAgendaItem *item; 1218 KOAgendaItem *item;
1220 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1219 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1221 if (item != placeItem) { 1220 if (item != placeItem) {
1222 if (placeItem->cellX() <= item->cellXWidth() && 1221 if (placeItem->cellX() <= item->cellXWidth() &&
1223 placeItem->cellXWidth() >= item->cellX()) { 1222 placeItem->cellXWidth() >= item->cellX()) {
1224 if ((placeItem->cellYTop() <= item->cellYBottom()) && 1223 if ((placeItem->cellYTop() <= item->cellYBottom()) &&
1225 (placeItem->cellYBottom() >= item->cellYTop())) { 1224 (placeItem->cellYBottom() >= item->cellYTop())) {
1226 conflictItems.append(item); 1225 conflictItems.append(item);
1227 if (item->subCells() > maxSubCells) 1226 if (item->subCells() > maxSubCells)
1228 maxSubCells = item->subCells(); 1227 maxSubCells = item->subCells();
1229 subCellDict.insert(item->subCell(),item); 1228 subCellDict.insert(item->subCell(),item);
1230 } 1229 }
1231 } 1230 }
1232 } 1231 }
1233 } 1232 }
1234 1233
1235 if (conflictItems.count() > 0) { 1234 if (conflictItems.count() > 0) {
1236 // Look for unused sub cell and insert item 1235 // Look for unused sub cell and insert item
1237 int i; 1236 int i;
1238 for(i=0;i<maxSubCells;++i) { 1237 for(i=0;i<maxSubCells;++i) {
1239 if (!subCellDict.find(i)) { 1238 if (!subCellDict.find(i)) {
1240 placeItem->setSubCell(i); 1239 placeItem->setSubCell(i);
1241 break; 1240 break;
1242 } 1241 }
1243 } 1242 }
1244 if (i == maxSubCells) { 1243 if (i == maxSubCells) {
1245 placeItem->setSubCell(maxSubCells); 1244 placeItem->setSubCell(maxSubCells);
1246 maxSubCells++; // add new item to number of sub cells 1245 maxSubCells++; // add new item to number of sub cells
1247 } 1246 }
1248 1247
1249 // Prepare for sub cell geometry adjustment 1248 // Prepare for sub cell geometry adjustment
1250 int newSubCellWidth; 1249 int newSubCellWidth;
1251 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells; 1250 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells;
1252 else newSubCellWidth = mGridSpacingX / maxSubCells; 1251 else newSubCellWidth = mGridSpacingX / maxSubCells;
1253 conflictItems.append(placeItem); 1252 conflictItems.append(placeItem);
1254 1253
1255 1254
1256 // Adjust sub cell geometry of all direct conflict items 1255 // Adjust sub cell geometry of all direct conflict items
1257 for ( item=conflictItems.first(); item != 0; 1256 for ( item=conflictItems.first(); item != 0;
1258 item=conflictItems.next() ) { 1257 item=conflictItems.next() ) {
1259 item->setSubCells(maxSubCells); 1258 item->setSubCells(maxSubCells);
1260 if (mAllDayMode) { 1259 if (mAllDayMode) {
1261 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); 1260 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth);
1262 } else { 1261 } else {
1263 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); 1262 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY);
1264 } 1263 }
1265 int x,y; 1264 int x,y;
1266 gridToContents(item->cellX(),item->cellYTop(),x,y); 1265 gridToContents(item->cellX(),item->cellYTop(),x,y);
1267 if (mAllDayMode) { 1266 if (mAllDayMode) {
1268 y += item->subCell() * newSubCellWidth; 1267 y += item->subCell() * newSubCellWidth;
1269 } else { 1268 } else {
1270 x += item->subCell() * newSubCellWidth; 1269 x += item->subCell() * newSubCellWidth;
1271 } 1270 }
1272 moveChild(item,x,y); 1271 moveChild(item,x,y);
1273 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y); 1272 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y);
1274 //item->updateItem(); 1273 //item->updateItem();
1275 } 1274 }
1276 // Adjust sub cell geometry of all conflict items of all conflict items 1275 // Adjust sub cell geometry of all conflict items of all conflict items
1277 for ( item=conflictItems.first(); item != 0; 1276 for ( item=conflictItems.first(); item != 0;
1278 item=conflictItems.next() ) { 1277 item=conflictItems.next() ) {
1279 if ( placeItem != item ) { 1278 if ( placeItem != item ) {
1280 KOAgendaItem *item2; 1279 KOAgendaItem *item2;
1281 QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems(); 1280 QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems();
1282 for ( item2=conflictItems2.first(); item2 != 0; 1281 for ( item2=conflictItems2.first(); item2 != 0;
1283 item2=conflictItems2.next() ) { 1282 item2=conflictItems2.next() ) {
1284 if ( item2->subCells() != maxSubCells) { 1283 if ( item2->subCells() != maxSubCells) {
1285 item2->setSubCells(maxSubCells); 1284 item2->setSubCells(maxSubCells);
1286 if (mAllDayMode) { 1285 if (mAllDayMode) {
1287 item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth); 1286 item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth);
1288 } else { 1287 } else {
1289 item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY); 1288 item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY);
1290 } 1289 }
1291 int x,y; 1290 int x,y;
1292 gridToContents(item2->cellX(),item2->cellYTop(),x,y); 1291 gridToContents(item2->cellX(),item2->cellYTop(),x,y);
1293 if (mAllDayMode) { 1292 if (mAllDayMode) {
1294 y += item2->subCell() * newSubCellWidth; 1293 y += item2->subCell() * newSubCellWidth;
1295 } else { 1294 } else {
1296 x += item2->subCell() * newSubCellWidth; 1295 x += item2->subCell() * newSubCellWidth;
1297 } 1296 }
1298 moveChild(item2,x,y); 1297 moveChild(item2,x,y);
1299 //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() ); 1298 //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() );
1300 } 1299 }
1301 } 1300 }
1302 } 1301 }
1303 } 1302 }
1304 } else { 1303 } else {
1305 placeItem->setSubCell(0); 1304 placeItem->setSubCell(0);
1306 placeItem->setSubCells(1); 1305 placeItem->setSubCells(1);
1307 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY); 1306 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY);
1308 else placeItem->resize(mGridSpacingX,placeItem->height()); 1307 else placeItem->resize(mGridSpacingX,placeItem->height());
1309 int x,y; 1308 int x,y;
1310 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y); 1309 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y);
1311 moveChild(placeItem,x,y); 1310 moveChild(placeItem,x,y);
1312 } 1311 }
1313 placeItem->setConflictItems(conflictItems); 1312 placeItem->setConflictItems(conflictItems);
1314 // for ( item=conflictItems.first(); item != 0; 1313 // for ( item=conflictItems.first(); item != 0;
1315// item=conflictItems.next() ) { 1314// item=conflictItems.next() ) {
1316// //item->updateItem(); 1315// //item->updateItem();
1317// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() ); 1316// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() );
1318// } 1317// }
1319// placeItem->updateItem(); 1318// placeItem->updateItem();
1320} 1319}
1321 1320
1322void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch) 1321void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
1323{ 1322{
1324 if ( globalFlagBlockAgenda ) 1323 if ( globalFlagBlockAgenda )
1325 return; 1324 return;
1326 //qDebug("KOAgenda::drawContents "); 1325 //qDebug("KOAgenda::drawContents ");
1327 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) 1326 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() )
1328 ;//drawContentsToPainter(); 1327 ;//drawContentsToPainter();
1329 1328
1330 QPaintDevice* pd = p->device(); 1329 QPaintDevice* pd = p->device();
1331 p->end(); 1330 p->end();
1332 int vx, vy; 1331 int vx, vy;
1333 int selectionX = KOGlobals::self()->reverseLayout() ? 1332 int selectionX = KOGlobals::self()->reverseLayout() ?
1334 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1333 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1335 mSelectionCellX * mGridSpacingX; 1334 mSelectionCellX * mGridSpacingX;
1336 contentsToViewport ( cx, cy, vx,vy); 1335 contentsToViewport ( cx, cy, vx,vy);
1337 // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ; 1336 // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ;
1338 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) 1337 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) )
1339 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); 1338 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP);
1340 1339
1341 if ( mSelectionHeight > 0 ) { 1340 if ( mSelectionHeight > 0 ) {
1342 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); 1341 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight );
1343 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1342 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1344 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1343 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1345 contentsToViewport ( selectionX, mSelectionYTop, vx,vy); 1344 contentsToViewport ( selectionX, mSelectionYTop, vx,vy);
1346 bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); 1345 bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP);
1347 } 1346 }
1348 } 1347 }
1349 //qDebug("btbl "); 1348 //qDebug("btbl ");
1350 p->begin( pd ); 1349 p->begin( pd );
1351 //qDebug("end "); 1350 //qDebug("end ");
1352} 1351}
1353 1352
1354void KOAgenda::finishUpdate() 1353void KOAgenda::finishUpdate()
1355{ 1354{
1356 1355
1357 KOAgendaItem *item; 1356 KOAgendaItem *item;
1358 globalFlagBlockAgendaItemPaint = 1; 1357 globalFlagBlockAgendaItemPaint = 1;
1359 // 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 1358 // Adjust sub cell geometry of all conflict items of all conflict items of all conflict items ... of the conflict item with the max number of conflictitems
1360 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1359 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1361 if ( !item->checkLayout() ) { 1360 if ( !item->checkLayout() ) {
1362 //qDebug(" conflictitem found "); 1361 //qDebug(" conflictitem found ");
1363 int newSubCellWidth; 1362 int newSubCellWidth;
1364 if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells(); 1363 if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells();
1365 else newSubCellWidth = mGridSpacingX / item->subCells(); 1364 else newSubCellWidth = mGridSpacingX / item->subCells();
1366 1365
1367 if (mAllDayMode) { 1366 if (mAllDayMode) {
1368 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); 1367 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth);
1369 } else { 1368 } else {
1370 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); 1369 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY);
1371 } 1370 }
1372 int x,y; 1371 int x,y;
1373 gridToContents(item->cellX(),item->cellYTop(),x,y); 1372 gridToContents(item->cellX(),item->cellYTop(),x,y);
1374 if (mAllDayMode) { 1373 if (mAllDayMode) {
1375 y += item->subCell() * newSubCellWidth; 1374 y += item->subCell() * newSubCellWidth;
1376 } else { 1375 } else {
1377 x += item->subCell() * newSubCellWidth; 1376 x += item->subCell() * newSubCellWidth;
1378 } 1377 }
1379 moveChild(item,x,y); 1378 moveChild(item,x,y);
1380 } 1379 }
1381 } 1380 }
1382 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1381 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1383 if ( !item->isVisible() ) 1382 if ( !item->isVisible() )
1384 item->show(); 1383 item->show();
1385 1384
1386 } 1385 }
1387 globalFlagBlockAgendaItemUpdate = 0; 1386 globalFlagBlockAgendaItemUpdate = 0;
1388 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1387 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1389 item->repaintMe( ); 1388 item->repaintMe( );
1390 } 1389 }
1391 globalFlagBlockAgendaItemUpdate = 1; 1390 globalFlagBlockAgendaItemUpdate = 1;
1392 qApp->processEvents(); 1391 qApp->processEvents();
1393 globalFlagBlockAgendaItemPaint = 0; 1392 globalFlagBlockAgendaItemPaint = 0;
1394 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1393 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1395 item->repaint( false ); 1394 item->repaint( false );
1396 } 1395 }
1397 1396
1398} 1397}
1399 1398
1400/* 1399/*
1401 Draw grid in the background of the agenda. 1400 Draw grid in the background of the agenda.
1402*/ 1401*/
1403void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch) 1402void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch)
1404{ 1403{
1405 1404
1406 1405
1407 if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask ) 1406 if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask )
1408 return; 1407 return;
1409 if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 ) 1408 if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 )
1410 return; 1409 return;
1411 int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight(); 1410 int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight();
1412 if ( ch < 1 ) 1411 if ( ch < 1 )
1413 ch = 1; 1412 ch = 1;
1414 if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) { 1413 if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) {
1415 mPaintPixmap.resize( contentsWidth()+42, ch ); 1414 mPaintPixmap.resize( contentsWidth()+42, ch );
1416 } 1415 }
1417 mCurPixWid = contentsWidth(); 1416 mCurPixWid = contentsWidth();
1418 mCurPixHei = ch; 1417 mCurPixHei = ch;
1419 if ( mHighlightPixmap.width() < mGridSpacingX-1 || mHighlightPixmap.height() < ch ) { 1418 if ( mHighlightPixmap.width() < mGridSpacingX-1 || mHighlightPixmap.height() < ch ) {
1420 mHighlightPixmap.resize( mGridSpacingX-1, ch ); 1419 mHighlightPixmap.resize( mGridSpacingX-1, ch );
1421 mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor ); 1420 mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor );
1422 } 1421 }
1423 mPixPainter.begin( &mPaintPixmap) ; 1422 mPixPainter.begin( &mPaintPixmap) ;
1424 //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() ); 1423 //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() );
1425 QPainter * p ; 1424 QPainter * p ;
1426 if (paint == 0) { 1425 if (paint == 0) {
1427 mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor); 1426 mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor);
1428 p = &mPixPainter; 1427 p = &mPixPainter;
1429 } 1428 }
1430 else 1429 else
1431 p = paint ; 1430 p = paint ;
1432 // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch); 1431 // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch);
1433 1432
1434 //--cx;++cw; 1433 //--cx;++cw;
1435 int lGridSpacingY = mGridSpacingY*2; 1434 int lGridSpacingY = mGridSpacingY*2;
1436 int selDay; 1435 int selDay;
1437 if ( !backgroundOnly ) 1436 if ( !backgroundOnly )
1438 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) 1437 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay)
1439 { 1438 {
1440 if ( mSelectedDates[selDay] == QDateTime::currentDateTime ().date() && KOPrefs::instance()->mHighlightCurrentDay) { 1439 if ( mSelectedDates[selDay] == QDateTime::currentDateTime ().date() && KOPrefs::instance()->mHighlightCurrentDay) {
1441 int x1 = cx; 1440 int x1 = cx;
1442 int y1 = 0; 1441 int y1 = 0;
1443 if (y1 < cy) y1 = cy; 1442 if (y1 < cy) y1 = cy;
1444 int x2 = cx+cw-1; 1443 int x2 = cx+cw-1;
1445 int y2 = contentsHeight(); 1444 int y2 = contentsHeight();
1446 if (y2 > cy+ch-1) y2=cy+ch-1; 1445 if (y2 > cy+ch-1) y2=cy+ch-1;
1447 if (x2 >= x1 && y2 >= y1) { 1446 if (x2 >= x1 && y2 >= y1) {
1448 int gxStart = selDay; 1447 int gxStart = selDay;
1449 int gxEnd = gxStart ; 1448 int gxEnd = gxStart ;
1450 int xStart = KOGlobals::self()->reverseLayout() ? 1449 int xStart = KOGlobals::self()->reverseLayout() ?
1451 (mColumns - 1 - gxStart)*mGridSpacingX : 1450 (mColumns - 1 - gxStart)*mGridSpacingX :
1452 gxStart*mGridSpacingX; 1451 gxStart*mGridSpacingX;
1453 if (xStart < x1) xStart = x1; 1452 if (xStart < x1) xStart = x1;
1454 int xEnd = KOGlobals::self()->reverseLayout() ? 1453 int xEnd = KOGlobals::self()->reverseLayout() ?
1455 (mColumns - gxStart)*mGridSpacingX-1 : 1454 (mColumns - gxStart)*mGridSpacingX-1 :
1456 (gxStart+1)*mGridSpacingX-1; 1455 (gxStart+1)*mGridSpacingX-1;
1457 if (xEnd > x2) xEnd = x2; 1456 if (xEnd > x2) xEnd = x2;
1458 if ( KOPrefs::instance()->mUseHighlightLightColor ) 1457 if ( KOPrefs::instance()->mUseHighlightLightColor )
1459 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1458 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1460 KOPrefs::instance()->mAgendaBgColor.light()); 1459 KOPrefs::instance()->mAgendaBgColor.light());
1461 else 1460 else
1462 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1461 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1463 KOPrefs::instance()->mAgendaBgColor.dark()); 1462 KOPrefs::instance()->mAgendaBgColor.dark());
1464 1463
1465 } 1464 }
1466 } 1465 }
1467 } 1466 }
1468 // Highlight working hours 1467 // Highlight working hours
1469 1468
1470 if ( !backgroundOnly ) 1469 if ( !backgroundOnly )
1471 if (mWorkingHoursEnable) { 1470 if (mWorkingHoursEnable) {
1472 int x1 = cx; 1471 int x1 = cx;
1473 int y1 = mWorkingHoursYTop; 1472 int y1 = mWorkingHoursYTop;
1474 if (y1 < cy) y1 = cy; 1473 if (y1 < cy) y1 = cy;
1475 int x2 = cx+cw-1; 1474 int x2 = cx+cw-1;
1476 // int x2 = mGridSpacingX * 5 - 1; 1475 // int x2 = mGridSpacingX * 5 - 1;
1477 // if (x2 > cx+cw-1) x2 = cx + cw - 1; 1476 // if (x2 > cx+cw-1) x2 = cx + cw - 1;
1478 int y2 = mWorkingHoursYBottom; 1477 int y2 = mWorkingHoursYBottom;
1479 if (y2 > cy+ch-1) y2=cy+ch-1; 1478 if (y2 > cy+ch-1) y2=cy+ch-1;
1480 1479
1481 if (x2 >= x1 && y2 >= y1) { 1480 if (x2 >= x1 && y2 >= y1) {
1482 // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX ); 1481 // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX );
1483 int gxStart = x1/mGridSpacingX; 1482 int gxStart = x1/mGridSpacingX;
1484 int gxEnd = x2/mGridSpacingX; 1483 int gxEnd = x2/mGridSpacingX;
1485 while(gxStart <= gxEnd) { 1484 while(gxStart <= gxEnd) {
1486 if (gxStart < int(mHolidayMask->count()) && 1485 if (gxStart < int(mHolidayMask->count()) &&
1487 !mHolidayMask->at(gxStart)) { 1486 !mHolidayMask->at(gxStart)) {
1488 int xStart = KOGlobals::self()->reverseLayout() ? 1487 int xStart = KOGlobals::self()->reverseLayout() ?
1489 (mColumns - 1 - gxStart)*mGridSpacingX : 1488 (mColumns - 1 - gxStart)*mGridSpacingX :
1490 gxStart*mGridSpacingX; 1489 gxStart*mGridSpacingX;
1491 if (xStart < x1) xStart = x1; 1490 if (xStart < x1) xStart = x1;
1492 int xEnd = KOGlobals::self()->reverseLayout() ? 1491 int xEnd = KOGlobals::self()->reverseLayout() ?
1493 (mColumns - gxStart)*mGridSpacingX-1 : 1492 (mColumns - gxStart)*mGridSpacingX-1 :
1494 (gxStart+1)*mGridSpacingX-1; 1493 (gxStart+1)*mGridSpacingX-1;
1495 if (xEnd > x2) xEnd = x2; 1494 if (xEnd > x2) xEnd = x2;
1496 if ( mSelectedDates[gxStart] == QDateTime::currentDateTime ().date()&& KOPrefs::instance()->mHighlightCurrentDay ) { 1495 if ( mSelectedDates[gxStart] == QDateTime::currentDateTime ().date()&& KOPrefs::instance()->mHighlightCurrentDay ) {
1497 if ( KOPrefs::instance()->mUseHighlightLightColor ) 1496 if ( KOPrefs::instance()->mUseHighlightLightColor )
1498 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1497 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1499 KOPrefs::instance()->mWorkingHoursColor.light()); 1498 KOPrefs::instance()->mWorkingHoursColor.light());
1500 else 1499 else
1501 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1500 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1502 KOPrefs::instance()->mWorkingHoursColor.dark()); 1501 KOPrefs::instance()->mWorkingHoursColor.dark());
1503 } else { 1502 } else {
1504 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1503 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1505 KOPrefs::instance()->mWorkingHoursColor); 1504 KOPrefs::instance()->mWorkingHoursColor);
1506 } 1505 }
1507 } 1506 }
1508 ++gxStart; 1507 ++gxStart;
1509 } 1508 }
1510 } 1509 }
1511 } 1510 }
1512 /* 1511 /*
1513 int selectionX = KOGlobals::self()->reverseLayout() ? 1512 int selectionX = KOGlobals::self()->reverseLayout() ?
1514 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1513 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1515 mSelectionCellX * mGridSpacingX; 1514 mSelectionCellX * mGridSpacingX;
1516 1515
1517 // Draw selection 1516 // Draw selection
1518 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1517 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1519 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1518 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1520 // TODO: paint only part within cx,cy,cw,ch 1519 // TODO: paint only part within cx,cy,cw,ch
1521 p->fillRect( selectionX, mSelectionYTop, mGridSpacingX, 1520 p->fillRect( selectionX, mSelectionYTop, mGridSpacingX,
1522 mSelectionHeight, KOPrefs::instance()->mHighlightColor ); 1521 mSelectionHeight, KOPrefs::instance()->mHighlightColor );
1523 } 1522 }
1524 */ 1523 */
1525 // Draw vertical lines of grid 1524 // Draw vertical lines of grid
1526 1525
1527 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX; 1526 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX;
1528 if ( mGridSpacingX > 0 ) { 1527 if ( mGridSpacingX > 0 ) {
1529 while (x < cx + cw) { 1528 while (x < cx + cw) {
1530 p->drawLine(x,cy,x,cy+ch); 1529 p->drawLine(x,cy,x,cy+ch);
1531 x+=mGridSpacingX; 1530 x+=mGridSpacingX;
1532 } 1531 }
1533 } 1532 }
1534 // Draw horizontal lines of grid 1533 // Draw horizontal lines of grid
1535 int y = ((int)(cy/lGridSpacingY))*lGridSpacingY; 1534 int y = ((int)(cy/lGridSpacingY))*lGridSpacingY;
1536 if ( lGridSpacingY > 0 ) { 1535 if ( lGridSpacingY > 0 ) {
1537 while (y < cy + ch) { 1536 while (y < cy + ch) {
1538 p->setPen( SolidLine ); 1537 p->setPen( SolidLine );
1539 p->drawLine(cx,y,cx+cw,y); 1538 p->drawLine(cx,y,cx+cw,y);
1540 y+=lGridSpacingY; 1539 y+=lGridSpacingY;
1541 p->setPen( DotLine ); 1540 p->setPen( DotLine );
1542 p->drawLine(cx,y,cx+cw,y); 1541 p->drawLine(cx,y,cx+cw,y);
1543 y+=lGridSpacingY; 1542 y+=lGridSpacingY;
1544 } 1543 }
1545 p->setPen( SolidLine ); 1544 p->setPen( SolidLine );
1546 } 1545 }
1547 mPixPainter.end() ; 1546 mPixPainter.end() ;
1548} 1547}
1549 1548
1550/* 1549/*
1551 Convert srcollview contents coordinates to agenda grid coordinates. 1550 Convert srcollview contents coordinates to agenda grid coordinates.
1552*/ 1551*/
1553void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy) 1552void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy)
1554{ 1553{
1555 gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX : 1554 gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX :
1556 x/mGridSpacingX; 1555 x/mGridSpacingX;
1557 gy = y/mGridSpacingY; 1556 gy = y/mGridSpacingY;
1558} 1557}
1559 1558
1560/* 1559/*
1561 Convert agenda grid coordinates to scrollview contents coordinates. 1560 Convert agenda grid coordinates to scrollview contents coordinates.
1562*/ 1561*/
1563void KOAgenda::gridToContents (int gx, int gy, int& x, int& y) 1562void KOAgenda::gridToContents (int gx, int gy, int& x, int& y)
1564{ 1563{
1565 x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX: 1564 x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX:
1566 gx*mGridSpacingX; 1565 gx*mGridSpacingX;
1567 y = gy*mGridSpacingY; 1566 y = gy*mGridSpacingY;
1568} 1567}
1569 1568
1570 1569
1571/* 1570/*
1572 Return Y coordinate corresponding to time. Coordinates are rounded to fit into 1571 Return Y coordinate corresponding to time. Coordinates are rounded to fit into
1573 the grid. 1572 the grid.
1574*/ 1573*/
1575int KOAgenda::timeToY(const QTime &time) 1574int KOAgenda::timeToY(const QTime &time)
1576{ 1575{
1577 int minutesPerCell = 24 * 60 / mRows; 1576 int minutesPerCell = 24 * 60 / mRows;
1578 int timeMinutes = time.hour() * 60 + time.minute(); 1577 int timeMinutes = time.hour() * 60 + time.minute();
1579 int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell; 1578 int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell;
1580 return Y; 1579 return Y;
1581} 1580}
1582 1581
1583 1582
1584/* 1583/*
1585 Return time corresponding to cell y coordinate. Coordinates are rounded to 1584 Return time corresponding to cell y coordinate. Coordinates are rounded to
1586 fit into the grid. 1585 fit into the grid.
1587*/ 1586*/
1588QTime KOAgenda::gyToTime(int gy) 1587QTime KOAgenda::gyToTime(int gy)
1589{ 1588{
1590 1589
1591 int secondsPerCell = 24 * 60 * 60/ mRows; 1590 int secondsPerCell = 24 * 60 * 60/ mRows;
1592 1591
1593 int timeSeconds = secondsPerCell * gy; 1592 int timeSeconds = secondsPerCell * gy;
1594 1593
1595 QTime time( 0, 0, 0 ); 1594 QTime time( 0, 0, 0 );
1596 if ( timeSeconds < 24 * 60 * 60 ) { 1595 if ( timeSeconds < 24 * 60 * 60 ) {
1597 time = time.addSecs(timeSeconds); 1596 time = time.addSecs(timeSeconds);
1598 } else { 1597 } else {
1599 time.setHMS( 23, 59, 59 ); 1598 time.setHMS( 23, 59, 59 );
1600 } 1599 }
1601 1600
1602 return time; 1601 return time;
1603} 1602}
1604 1603
1605void KOAgenda::setStartHour(int startHour) 1604void KOAgenda::setStartHour(int startHour)
1606{ 1605{
1607 int startCell = startHour * mRows / 24; 1606 int startCell = startHour * mRows / 24;
1608 setContentsPos(0,startCell * gridSpacingY()); 1607 setContentsPos(0,startCell * gridSpacingY());
1609} 1608}
1610void KOAgenda::hideUnused() 1609void KOAgenda::hideUnused()
1611{ 1610{
1612 // experimental only 1611 // experimental only
1613 // return; 1612 // return;
1614 KOAgendaItem *item; 1613 KOAgendaItem *item;
1615 for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) { 1614 for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) {
1616 item->hide(); 1615 item->hide();
1617 } 1616 }
1618} 1617}
1619 1618
1620 1619
1621KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view) 1620KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view)
1622{ 1621{
1623 1622
1624 KOAgendaItem *fi; 1623 KOAgendaItem *fi;
1625 for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) { 1624 for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) {
1626 if ( fi->incidence() == event ) { 1625 if ( fi->incidence() == event ) {
1627 mUnusedItems.remove(); 1626 mUnusedItems.remove();
1628 fi->init( event, qd ); 1627 fi->init( event, qd );
1629 return fi; 1628 return fi;
1630 } 1629 }
1631 } 1630 }
1632 fi=mUnusedItems.first(); 1631 fi=mUnusedItems.first();
1633 if ( fi ) { 1632 if ( fi ) {
1634 mUnusedItems.remove(); 1633 mUnusedItems.remove();
1635 fi->init( event, qd ); 1634 fi->init( event, qd );
1636 return fi; 1635 return fi;
1637 } 1636 }
1638 // qDebug("new KOAgendaItem "); 1637 // qDebug("new KOAgendaItem ");
1639 1638
1640 KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode ); 1639 KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode );
1641 agendaItem->installEventFilter(this); 1640 agendaItem->installEventFilter(this);
1642 addChild(agendaItem,0,0); 1641 addChild(agendaItem,0,0);
1643 return agendaItem; 1642 return agendaItem;
1644} 1643}
1645KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo ) 1644KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo )
1646{ 1645{
1647 KOAgendaItem *item; 1646 KOAgendaItem *item;
1648 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1647 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1649 if ( item->incidence() == todo ) { 1648 if ( item->incidence() == todo ) {
1650 mItems.remove(); 1649 mItems.remove();
1651 return item; 1650 return item;
1652 } 1651 }
1653 } 1652 }
1654 return 0; 1653 return 0;
1655} 1654}
1656 1655
1657 1656
1658void KOAgenda::updateTodo( Todo * todo, int days, bool remove) 1657void KOAgenda::updateTodo( Todo * todo, int days, bool remove)
1659{ 1658{
1660 // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )|| 1659 // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )||
1661 KOAgendaItem *item; 1660 KOAgendaItem *item;
1662 item = getItemForTodo ( todo ); 1661 item = getItemForTodo ( todo );
1663 //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove); 1662 //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove);
1664 if ( item ) { 1663 if ( item ) {
1665 blockSignals( true ); 1664 blockSignals( true );
1666 //qDebug("item found "); 1665 //qDebug("item found ");
1667 item->hide(); 1666 item->hide();
1668 item->setCellX(-2, -1 ); 1667 item->setCellX(-2, -1 );
1669 item->select(false); 1668 item->select(false);
1670 mUnusedItems.append( item ); 1669 mUnusedItems.append( item );
1671 mItems.remove( item ); 1670 mItems.remove( item );
1672 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); 1671 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems();
1673 KOAgendaItem *itemit; 1672 KOAgendaItem *itemit;
1674 //globalFlagBlockAgendaItemPaint = 1; 1673 //globalFlagBlockAgendaItemPaint = 1;
1675 for ( itemit=oldconflictItems.first(); itemit != 0; 1674 for ( itemit=oldconflictItems.first(); itemit != 0;
1676 itemit=oldconflictItems.next() ) { 1675 itemit=oldconflictItems.next() ) {
1677 if ( itemit != item ) 1676 if ( itemit != item )
1678 placeSubCells(itemit); 1677 placeSubCells(itemit);
1679 } 1678 }
1680 qApp->processEvents(); 1679 qApp->processEvents();
1681 //globalFlagBlockAgendaItemPaint = 0; 1680 //globalFlagBlockAgendaItemPaint = 0;
1682 for ( itemit=oldconflictItems.first(); itemit != 0; 1681 for ( itemit=oldconflictItems.first(); itemit != 0;
1683 itemit=oldconflictItems.next() ) { 1682 itemit=oldconflictItems.next() ) {
1684 globalFlagBlockAgendaItemUpdate = 0; 1683 globalFlagBlockAgendaItemUpdate = 0;
1685 if ( itemit != item ) 1684 if ( itemit != item )
1686 itemit->repaintMe(); 1685 itemit->repaintMe();
1687 globalFlagBlockAgendaItemUpdate = 1; 1686 globalFlagBlockAgendaItemUpdate = 1;
1688 itemit->repaint(); 1687 itemit->repaint();
1689 } 1688 }
1690 blockSignals( false ); 1689 blockSignals( false );
1691 } 1690 }
1692 if ( remove ) { 1691 if ( remove ) {
1693 //qDebug("remove****************************************** "); 1692 //qDebug("remove****************************************** ");
1694 return; 1693 return;
1695 } 1694 }
1696 //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ "); 1695 //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ ");
1697 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < QDate::currentDate())&& ( KOPrefs::instance()->mShowTodoInAgenda ); 1696 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < QDate::currentDate())&& ( KOPrefs::instance()->mShowTodoInAgenda );
1698 QDate currentDate; 1697 QDate currentDate;
1699 QDateTime dt; 1698 QDateTime dt;
1700 if ( todo->hasCompletedDate() ) 1699 if ( todo->hasCompletedDate() )
1701 dt = todo->completed(); 1700 dt = todo->completed();
1702 else 1701 else
1703 dt = todo->dtDue(); 1702 dt = todo->dtDue();
1704 if ( overdue ) { 1703 if ( overdue ) {
1705 currentDate = QDate::currentDate(); 1704 currentDate = QDate::currentDate();
1706 days += todo->dtDue().date().daysTo( currentDate ); 1705 days += todo->dtDue().date().daysTo( currentDate );
1707 } 1706 }
1708 else 1707 else
1709 currentDate = dt.date(); 1708 currentDate = dt.date();
1710 1709
1711 if (( todo->doesFloat() || overdue) && !todo->hasCompletedDate() ) { 1710 if (( todo->doesFloat() || overdue) && !todo->hasCompletedDate() ) {
1712 if ( ! mAllDayMode ) return; 1711 if ( ! mAllDayMode ) return;
1713 // aldayagenda 1712 // aldayagenda
1714 globalFlagBlockAgendaItemPaint = 1; 1713 globalFlagBlockAgendaItemPaint = 1;
1715 item = insertAllDayItem(todo, currentDate,days, days); 1714 item = insertAllDayItem(todo, currentDate,days, days);
1716 item->show(); 1715 item->show();
1717 1716
1718 } 1717 }
1719 else { 1718 else {
1720 if ( mAllDayMode ) return; 1719 if ( mAllDayMode ) return;
1721 // mAgenda 1720 // mAgenda
1722 globalFlagBlockAgendaItemPaint = 1; 1721 globalFlagBlockAgendaItemPaint = 1;
1723 int endY = timeToY(dt.time()) - 1; 1722 int endY = timeToY(dt.time()) - 1;
1724 int hi = 12/KOPrefs::instance()->mHourSize; 1723 int hi = 12/KOPrefs::instance()->mHourSize;
1725 int startY = endY - 1-hi; 1724 int startY = endY - 1-hi;
1726 item = insertItem(todo,currentDate,days,startY,endY); 1725 item = insertItem(todo,currentDate,days,startY,endY);
1727 item->show(); 1726 item->show();
1728 } 1727 }
1729 qApp->processEvents(); 1728 qApp->processEvents();
1730 globalFlagBlockAgendaItemPaint = 0; 1729 globalFlagBlockAgendaItemPaint = 0;
1731 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); 1730 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems();
1732 KOAgendaItem *itemit; 1731 KOAgendaItem *itemit;
1733 for ( itemit=oldconflictItems.first(); itemit != 0; 1732 for ( itemit=oldconflictItems.first(); itemit != 0;
1734 itemit=oldconflictItems.next() ) { 1733 itemit=oldconflictItems.next() ) {
1735 globalFlagBlockAgendaItemUpdate = 0; 1734 globalFlagBlockAgendaItemUpdate = 0;
1736 itemit->repaintMe(); 1735 itemit->repaintMe();
1737 globalFlagBlockAgendaItemUpdate = 1; 1736 globalFlagBlockAgendaItemUpdate = 1;
1738 itemit->repaint(); 1737 itemit->repaint();
1739 } 1738 }
1740 globalFlagBlockAgendaItemUpdate = 0; 1739 globalFlagBlockAgendaItemUpdate = 0;
1741 item->repaintMe(); 1740 item->repaintMe();
1742 globalFlagBlockAgendaItemUpdate = 1; 1741 globalFlagBlockAgendaItemUpdate = 1;
1743 item->repaint(); 1742 item->repaint();
1744} 1743}
1745/* 1744/*
1746 Insert KOAgendaItem into agenda. 1745 Insert KOAgendaItem into agenda.
1747*/ 1746*/
1748KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom) 1747KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom)
1749{ 1748{
1750 if (mAllDayMode) { 1749 if (mAllDayMode) {
1751 qDebug("KOAgenda: calling insertItem in all-day mode is illegal. "); 1750 qDebug("KOAgenda: calling insertItem in all-day mode is illegal. ");
1752 return 0; 1751 return 0;
1753 } 1752 }
1754 1753
1755 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); 1754 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport());
1756 //agendaItem->setFrameStyle(WinPanel|Raised); 1755 //agendaItem->setFrameStyle(WinPanel|Raised);
1757 1756
1758 int YSize = YBottom - YTop + 1; 1757 int YSize = YBottom - YTop + 1;
1759 if (YSize < 0) { 1758 if (YSize < 0) {
1760 YSize = 1; 1759 YSize = 1;
1761 } 1760 }
1762 int iheight = mGridSpacingY * YSize; 1761 int iheight = mGridSpacingY * YSize;
1763 1762
1764 agendaItem->resize(mGridSpacingX,iheight ); 1763 agendaItem->resize(mGridSpacingX,iheight );
1765 agendaItem->setCellXY(X,YTop,YBottom); 1764 agendaItem->setCellXY(X,YTop,YBottom);
1766 agendaItem->setCellXWidth(X); 1765 agendaItem->setCellXWidth(X);
1767 1766
1768 //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY); 1767 //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY);
1769 mItems.append(agendaItem); 1768 mItems.append(agendaItem);
1770 1769
1771 placeSubCells(agendaItem); 1770 placeSubCells(agendaItem);
1772 1771
1773 //agendaItem->show(); 1772 //agendaItem->show();
1774 1773
1775 marcus_bains(); 1774 marcus_bains();
1776 1775
1777 return agendaItem; 1776 return agendaItem;
1778} 1777}
1779 1778
1780 1779
1781/* 1780/*
1782 Insert all-day KOAgendaItem into agenda. 1781 Insert all-day KOAgendaItem into agenda.
1783*/ 1782*/
1784KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd) 1783KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd)
1785{ 1784{
1786 if (!mAllDayMode) { 1785 if (!mAllDayMode) {
1787 return 0; 1786 return 0;
1788 } 1787 }
1789 1788
1790 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); 1789 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport());
1791 1790
1792 agendaItem->setCellXY(XBegin,0,0); 1791 agendaItem->setCellXY(XBegin,0,0);
1793 agendaItem->setCellXWidth(XEnd); 1792 agendaItem->setCellXWidth(XEnd);
1794 agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY); 1793 agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY);
1795 1794
1796 //addChild(agendaItem,XBegin*mGridSpacingX,0); 1795 //addChild(agendaItem,XBegin*mGridSpacingX,0);
1797 mItems.append(agendaItem); 1796 mItems.append(agendaItem);
1798 1797
1799 placeSubCells(agendaItem); 1798 placeSubCells(agendaItem);
1800 1799
1801 //agendaItem->show(); 1800 //agendaItem->show();
1802 1801
1803 return agendaItem; 1802 return agendaItem;
1804} 1803}
1805 1804
1806 1805
1807void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, 1806void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd,
1808 int YTop,int YBottom) 1807 int YTop,int YBottom)
1809{ 1808{
1810 if (mAllDayMode) { 1809 if (mAllDayMode) {
1811 ; 1810 ;
1812 return; 1811 return;
1813 } 1812 }
1814 1813
1815 int cellX,cellYTop,cellYBottom; 1814 int cellX,cellYTop,cellYBottom;
1816 QString newtext; 1815 QString newtext;
1817 int width = XEnd - XBegin + 1; 1816 int width = XEnd - XBegin + 1;
1818 int count = 0; 1817 int count = 0;
1819 KOAgendaItem *current = 0; 1818 KOAgendaItem *current = 0;
1820 QPtrList<KOAgendaItem> multiItems; 1819 QPtrList<KOAgendaItem> multiItems;
1821 for (cellX = XBegin;cellX <= XEnd;++cellX) { 1820 for (cellX = XBegin;cellX <= XEnd;++cellX) {
1822 if (cellX == XBegin) cellYTop = YTop; 1821 if (cellX == XBegin) cellYTop = YTop;
1823 else cellYTop = 0; 1822 else cellYTop = 0;
1824 if (cellX == XEnd) cellYBottom = YBottom; 1823 if (cellX == XEnd) cellYBottom = YBottom;
1825 else cellYBottom = rows() - 1; 1824 else cellYBottom = rows() - 1;
1826 newtext = QString("(%1/%2): ").arg(++count).arg(width); 1825 newtext = QString("(%1/%2): ").arg(++count).arg(width);
1827 newtext.append(event->summary()); 1826 newtext.append(event->summary());
1828 current = insertItem(event,qd,cellX,cellYTop,cellYBottom); 1827 current = insertItem(event,qd,cellX,cellYTop,cellYBottom);
1829 current->setText(newtext); 1828 current->setText(newtext);
1830 multiItems.append(current); 1829 multiItems.append(current);
1831 } 1830 }
1832 1831
1833 KOAgendaItem *next = 0; 1832 KOAgendaItem *next = 0;
1834 KOAgendaItem *last = multiItems.last(); 1833 KOAgendaItem *last = multiItems.last();
1835 KOAgendaItem *first = multiItems.first(); 1834 KOAgendaItem *first = multiItems.first();
1836 KOAgendaItem *setFirst,*setLast; 1835 KOAgendaItem *setFirst,*setLast;
1837 current = first; 1836 current = first;
1838 while (current) { 1837 while (current) {
1839 next = multiItems.next(); 1838 next = multiItems.next();
1840 if (current == first) setFirst = 0; 1839 if (current == first) setFirst = 0;
1841 else setFirst = first; 1840 else setFirst = first;
1842 if (current == last) setLast = 0; 1841 if (current == last) setLast = 0;
1843 else setLast = last; 1842 else setLast = last;
1844 1843
1845 current->setMultiItem(setFirst,next,setLast); 1844 current->setMultiItem(setFirst,next,setLast);
1846 current = next; 1845 current = next;
1847 } 1846 }
1848 1847
1849 marcus_bains(); 1848 marcus_bains();
1850} 1849}
1851 1850
1852 1851
1853//QSizePolicy KOAgenda::sizePolicy() const 1852//QSizePolicy KOAgenda::sizePolicy() const
1854//{ 1853//{
1855 // Thought this would make the all-day event agenda minimum size and the 1854 // Thought this would make the all-day event agenda minimum size and the
1856 // normal agenda take the remaining space. But it doesn´t work. The QSplitter 1855 // normal agenda take the remaining space. But it doesn´t work. The QSplitter
1857 // don´t seem to think that an Expanding widget needs more space than a 1856 // don´t seem to think that an Expanding widget needs more space than a
1858 // Preferred one. 1857 // Preferred one.
1859 // But it doesn´t hurt, so it stays. 1858 // But it doesn´t hurt, so it stays.
1860// if (mAllDayMode) { 1859// if (mAllDayMode) {
1861// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); 1860// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
1862// } else { 1861// } else {
1863// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); 1862// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
1864// } 1863// }
1865//} 1864//}
1866void KOAgenda::finishResize ( ) 1865void KOAgenda::finishResize ( )
1867{ 1866{
1868 //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) "); 1867 //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) ");
1869 if ( globalFlagBlockAgenda == 0 ) { 1868 if ( globalFlagBlockAgenda == 0 ) {
1870 finishUpdate(); 1869 finishUpdate();
1871 //qDebug("finishUpdate() called "); 1870 //qDebug("finishUpdate() called ");
1872 } 1871 }
1873} 1872}
1874/* 1873/*
1875 Overridden from QScrollView to provide proper resizing of KOAgendaItems. 1874 Overridden from QScrollView to provide proper resizing of KOAgendaItems.
1876*/ 1875*/
1877void KOAgenda::resizeEvent ( QResizeEvent *ev ) 1876void KOAgenda::resizeEvent ( QResizeEvent *ev )
1878{ 1877{
1879 1878
1880 mResizeTimer.start( 150 , true ); 1879 mResizeTimer.start( 150 , true );
1881 computeSizes(); 1880 computeSizes();
1882 return; 1881 return;
1883 1882
1884} 1883}
1885void KOAgenda::computeSizes() 1884void KOAgenda::computeSizes()
1886{ 1885{
1887 if ( globalFlagBlockStartup ) 1886 if ( globalFlagBlockStartup )
1888 return; 1887 return;
1889 int frameOffset = frameWidth() * 2 +1; 1888 int frameOffset = frameWidth() * 2 +1;
1890 if (mAllDayMode) { 1889 if (mAllDayMode) {
1891 mGridSpacingX = (width()-frameOffset) / mColumns; 1890 mGridSpacingX = (width()-frameOffset) / mColumns;
1892 mGridSpacingY = height() - 2 * frameWidth() - 1; 1891 mGridSpacingY = height() - 2 * frameWidth() - 1;
1893 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1); 1892 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1);
1894 // mGridSpacingY = height(); 1893 // mGridSpacingY = height();
1895 // resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1894 // resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1896 1895
1897 KOAgendaItem *item; 1896 KOAgendaItem *item;
1898 int subCellWidth; 1897 int subCellWidth;
1899 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1898 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1900 subCellWidth = mGridSpacingY / item->subCells(); 1899 subCellWidth = mGridSpacingY / item->subCells();
1901 item->resize(mGridSpacingX * item->cellWidth(),subCellWidth); 1900 item->resize(mGridSpacingX * item->cellWidth(),subCellWidth);
1902 moveChild(item,KOGlobals::self()->reverseLayout() ? 1901 moveChild(item,KOGlobals::self()->reverseLayout() ?
1903 (mColumns - 1 - item->cellX()) * mGridSpacingX : 1902 (mColumns - 1 - item->cellX()) * mGridSpacingX :
1904 item->cellX() * mGridSpacingX, 1903 item->cellX() * mGridSpacingX,
1905 item->subCell() * subCellWidth); 1904 item->subCell() * subCellWidth);
1906 } 1905 }
1907 KOPrefs::instance()->mAllDaySize = mGridSpacingY; 1906 KOPrefs::instance()->mAllDaySize = mGridSpacingY;
1908 } else { 1907 } else {
1909 mGridSpacingX = (width() - verticalScrollBar()->width()-frameOffset)/mColumns; 1908 mGridSpacingX = (width() - verticalScrollBar()->width()-frameOffset)/mColumns;
1910 if (height() > mGridSpacingY * mRows + 1 ) { 1909 if (height() > mGridSpacingY * mRows + 1 ) {
1911 KOPrefs::instance()->mHourSize = ((height())/mRows)+1; 1910 KOPrefs::instance()->mHourSize = ((height())/mRows)+1;
1912 mGridSpacingY = KOPrefs::instance()->mHourSize ; 1911 mGridSpacingY = KOPrefs::instance()->mHourSize ;
1913 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1912 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1914 emit resizedSignal(); 1913 emit resizedSignal();
1915 } else 1914 } else
1916 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1915 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1917 KOAgendaItem *item; 1916 KOAgendaItem *item;
1918 int subCellWidth; 1917 int subCellWidth;
1919 1918
1920 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1919 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1921 subCellWidth = mGridSpacingX / item->subCells(); 1920 subCellWidth = mGridSpacingX / item->subCells();
1922 item->resize(subCellWidth,item->height()); 1921 item->resize(subCellWidth,item->height());
1923 moveChild(item,(KOGlobals::self()->reverseLayout() ? 1922 moveChild(item,(KOGlobals::self()->reverseLayout() ?
1924 (mColumns - 1 - item->cellX()) * mGridSpacingX : 1923 (mColumns - 1 - item->cellX()) * mGridSpacingX :
1925 item->cellX() * mGridSpacingX) + 1924 item->cellX() * mGridSpacingX) +
1926 item->subCell() * subCellWidth,childY(item)); 1925 item->subCell() * subCellWidth,childY(item));
1927 } 1926 }
1928 } 1927 }
1929 int cw = contentsWidth(); 1928 int cw = contentsWidth();
1930 int ch = contentsHeight(); 1929 int ch = contentsHeight();
1931 if ( mAllDayMode ) { 1930 if ( mAllDayMode ) {
1932 QPixmap* paintPixAll = KOAgendaItem::paintPixAllday(); 1931 QPixmap* paintPixAll = KOAgendaItem::paintPixAllday();
1933 if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 ) 1932 if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 )
1934 paintPixAll->resize( cw, ch ); 1933 paintPixAll->resize( cw, ch );
1935 } else { 1934 } else {
1936 QPixmap* paintPix = KOAgendaItem::paintPix(); 1935 QPixmap* paintPix = KOAgendaItem::paintPix();
1937 if ( paintPix->width() < cw || paintPix->height() < ch ) 1936 if ( paintPix->width() < cw || paintPix->height() < ch )
1938 KOAgendaItem::resizePixmap( cw , ch ); 1937 KOAgendaItem::resizePixmap( cw , ch );
1939 } 1938 }
1940 1939
1941 checkScrollBoundaries(); 1940 checkScrollBoundaries();
1942 marcus_bains(); 1941 marcus_bains();
1943 drawContentsToPainter(); 1942 drawContentsToPainter();
1944 viewport()->repaint(false); 1943 viewport()->repaint(false);
1945} 1944}
1946 1945
1947void KOAgenda::scrollUp() 1946void KOAgenda::scrollUp()
1948{ 1947{
1949 scrollBy(0,-mScrollOffset); 1948 scrollBy(0,-mScrollOffset);
1950} 1949}
1951 1950
1952 1951
1953void KOAgenda::scrollDown() 1952void KOAgenda::scrollDown()
1954{ 1953{
1955 scrollBy(0,mScrollOffset); 1954 scrollBy(0,mScrollOffset);
1956} 1955}
1957 1956
1958void KOAgenda::popupAlarm() 1957void KOAgenda::popupAlarm()
1959{ 1958{
1960 if (!mClickedItem) { 1959 if (!mClickedItem) {
1961 qDebug("KOAgenda::popupAlarm() called without having a clicked item "); 1960 qDebug("KOAgenda::popupAlarm() called without having a clicked item ");
1962 return; 1961 return;
1963 } 1962 }
1964 // TODO: deal correctly with multiple alarms 1963 // TODO: deal correctly with multiple alarms
1965 Alarm* alarm; 1964 Alarm* alarm;
1966 QPtrList<Alarm> list(mClickedItem->incidence()->alarms()); 1965 QPtrList<Alarm> list(mClickedItem->incidence()->alarms());
1967 for(alarm=list.first();alarm;alarm=list.next()) { 1966 for(alarm=list.first();alarm;alarm=list.next()) {
1968 alarm->toggleAlarm(); 1967 alarm->toggleAlarm();
1969 } 1968 }
1970 emit itemModified( mClickedItem , KOGlobals::EVENTEDITED ); 1969 emit itemModified( mClickedItem , KOGlobals::EVENTEDITED );
1971 mClickedItem->paintMe( true ); 1970 mClickedItem->paintMe( true );
1972 mClickedItem->repaint( false ); 1971 mClickedItem->repaint( false );
1973} 1972}
1974 1973
1975/* 1974/*
1976 Calculates the minimum width 1975 Calculates the minimum width
1977*/ 1976*/
1978int KOAgenda::minimumWidth() const 1977int KOAgenda::minimumWidth() const
1979{ 1978{
1980 // TODO:: develop a way to dynamically determine the minimum width 1979 // TODO:: develop a way to dynamically determine the minimum width
1981 int min = 100; 1980 int min = 100;
1982 1981
1983 return min; 1982 return min;
1984} 1983}
1985 1984
1986void KOAgenda::updateConfig() 1985void KOAgenda::updateConfig()
1987{ 1986{
1988 if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor) 1987 if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor)
1989 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor); 1988 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor);
1990 if ( mAllDayMode ) { 1989 if ( mAllDayMode ) {
1991 mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize; 1990 mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize;
1992 //mGridSpacingY = KOPrefs::instance()->mAllDaySize; 1991 //mGridSpacingY = KOPrefs::instance()->mAllDaySize;
1993 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 ); 1992 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 );
1994 // setMaximumHeight( mGridSpacingY+1 ); 1993 // setMaximumHeight( mGridSpacingY+1 );
1995 viewport()->repaint( false ); 1994 viewport()->repaint( false );
1996 //setFixedHeight( mGridSpacingY+1 ); 1995 //setFixedHeight( mGridSpacingY+1 );
1997 //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize); 1996 //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize);
1998 } 1997 }
1999 else { 1998 else {
2000 mGridSpacingY = KOPrefs::instance()->mHourSize; 1999 mGridSpacingY = KOPrefs::instance()->mHourSize;
2001 calculateWorkingHours(); 2000 calculateWorkingHours();
2002 marcus_bains(); 2001 marcus_bains();
2003 } 2002 }
2004} 2003}
2005 2004
2006void KOAgenda::checkScrollBoundaries() 2005void KOAgenda::checkScrollBoundaries()
2007{ 2006{
2008 // Invalidate old values to force update 2007 // Invalidate old values to force update
2009 mOldLowerScrollValue = -1; 2008 mOldLowerScrollValue = -1;
2010 mOldUpperScrollValue = -1; 2009 mOldUpperScrollValue = -1;
2011 2010
2012 checkScrollBoundaries(verticalScrollBar()->value()); 2011 checkScrollBoundaries(verticalScrollBar()->value());
2013} 2012}
2014 2013
2015void KOAgenda::checkScrollBoundaries(int v) 2014void KOAgenda::checkScrollBoundaries(int v)
2016{ 2015{
2017 if ( mGridSpacingY == 0 ) 2016 if ( mGridSpacingY == 0 )
2018 return; 2017 return;
2019 int yMin = v/mGridSpacingY; 2018 int yMin = v/mGridSpacingY;
2020 int yMax = (v+visibleHeight())/mGridSpacingY; 2019 int yMax = (v+visibleHeight())/mGridSpacingY;
2021 2020
2022// kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl; 2021// kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl;
2023 2022
2024 if (yMin != mOldLowerScrollValue) { 2023 if (yMin != mOldLowerScrollValue) {
2025 mOldLowerScrollValue = yMin; 2024 mOldLowerScrollValue = yMin;
2026 emit lowerYChanged(yMin); 2025 emit lowerYChanged(yMin);
2027 } 2026 }
2028 if (yMax != mOldUpperScrollValue) { 2027 if (yMax != mOldUpperScrollValue) {
2029 mOldUpperScrollValue = yMax; 2028 mOldUpperScrollValue = yMax;
2030 emit upperYChanged(yMax); 2029 emit upperYChanged(yMax);
2031 } 2030 }
2032} 2031}
2033 2032
2034void KOAgenda::deselectItem() 2033void KOAgenda::deselectItem()
2035{ 2034{
2036 if (mSelectedItem.isNull()) return; 2035 if (mSelectedItem.isNull()) return;
2037 mSelectedItem->select(false); 2036 mSelectedItem->select(false);
2038 mSelectedItem = 0; 2037 mSelectedItem = 0;
2039} 2038}
2040 2039
2041void KOAgenda::selectItem(KOAgendaItem *item) 2040void KOAgenda::selectItem(KOAgendaItem *item)
2042{ 2041{
2043 if ((KOAgendaItem *)mSelectedItem == item) return; 2042 if ((KOAgendaItem *)mSelectedItem == item) return;
2044 deselectItem(); 2043 deselectItem();
2045 if (item == 0) { 2044 if (item == 0) {
2046 emit incidenceSelected( 0 ); 2045 emit incidenceSelected( 0 );
2047 return; 2046 return;
2048 } 2047 }
2049 mSelectedItem = item; 2048 mSelectedItem = item;
2050 mSelectedItem->select(); 2049 mSelectedItem->select();
2051 emit incidenceSelected( mSelectedItem->incidence() ); 2050 emit incidenceSelected( mSelectedItem->incidence() );
2052} 2051}
2053 2052
2054// This function seems never be called. 2053// This function seems never be called.
2055void KOAgenda::keyPressEvent( QKeyEvent *kev ) 2054void KOAgenda::keyPressEvent( QKeyEvent *kev )
2056{ 2055{
2057 switch(kev->key()) { 2056 switch(kev->key()) {
2058 case Key_PageDown: 2057 case Key_PageDown:
2059 verticalScrollBar()->addPage(); 2058 verticalScrollBar()->addPage();
2060 break; 2059 break;
2061 case Key_PageUp: 2060 case Key_PageUp:
2062 verticalScrollBar()->subtractPage(); 2061 verticalScrollBar()->subtractPage();
2063 break; 2062 break;
2064 case Key_Down: 2063 case Key_Down:
2065 verticalScrollBar()->addLine(); 2064 verticalScrollBar()->addLine();
2066 break; 2065 break;
2067 case Key_Up: 2066 case Key_Up:
2068 verticalScrollBar()->subtractLine(); 2067 verticalScrollBar()->subtractLine();
2069 break; 2068 break;
2070 default: 2069 default:
2071 ; 2070 ;
2072 } 2071 }
2073} 2072}
2074 2073
2075void KOAgenda::calculateWorkingHours() 2074void KOAgenda::calculateWorkingHours()
2076{ 2075{
2077// mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours; 2076// mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours;
2078 mWorkingHoursEnable = !mAllDayMode; 2077 mWorkingHoursEnable = !mAllDayMode;
2079 2078
2080 mWorkingHoursYTop = mGridSpacingY * 2079 mWorkingHoursYTop = mGridSpacingY *
2081 KOPrefs::instance()->mWorkingHoursStart * 4; 2080 KOPrefs::instance()->mWorkingHoursStart * 4;
2082 mWorkingHoursYBottom = mGridSpacingY * 2081 mWorkingHoursYBottom = mGridSpacingY *
2083 KOPrefs::instance()->mWorkingHoursEnd * 4 - 1; 2082 KOPrefs::instance()->mWorkingHoursEnd * 4 - 1;
2084} 2083}
2085 2084
2086 2085
2087DateList KOAgenda::dateList() const 2086DateList KOAgenda::dateList() const
2088{ 2087{
2089 return mSelectedDates; 2088 return mSelectedDates;
2090} 2089}
2091 2090
2092void KOAgenda::setDateList(const DateList &selectedDates) 2091void KOAgenda::setDateList(const DateList &selectedDates)
2093{ 2092{
2094 mSelectedDates = selectedDates; 2093 mSelectedDates = selectedDates;
2095 marcus_bains(); 2094 marcus_bains();
2096} 2095}
2097 2096
2098void KOAgenda::setHolidayMask(QMemArray<bool> *mask) 2097void KOAgenda::setHolidayMask(QMemArray<bool> *mask)
2099{ 2098{
2100 mHolidayMask = mask; 2099 mHolidayMask = mask;
2101 2100
2102/* 2101/*
2103 kdDebug() << "HolidayMask: "; 2102 kdDebug() << "HolidayMask: ";
2104 for(uint i=0;i<mask->count();++i) { 2103 for(uint i=0;i<mask->count();++i) {
2105 kdDebug() << (mask->at(i) ? "*" : "o"); 2104 kdDebug() << (mask->at(i) ? "*" : "o");
2106 } 2105 }
2107 kdDebug() << endl; 2106 kdDebug() << endl;
2108*/ 2107*/
2109} 2108}
2110 2109
2111void KOAgenda::contentsMousePressEvent ( QMouseEvent *event ) 2110void KOAgenda::contentsMousePressEvent ( QMouseEvent *event )
2112{ 2111{
2113 2112
2114 QScrollView::contentsMousePressEvent(event); 2113 QScrollView::contentsMousePressEvent(event);
2115} 2114}
2116 2115
2117void KOAgenda::storePosition() 2116void KOAgenda::storePosition()
2118{ 2117{
2119 //mContentPosition 2118 //mContentPosition
2120 int max = mGridSpacingY*4*24; 2119 int max = mGridSpacingY*4*24;
2121 if ( contentsY() < 5 && max > viewport()->height()*3/2 ) 2120 if ( contentsY() < 5 && max > viewport()->height()*3/2 )
2122 mContentPosition = 0; 2121 mContentPosition = 0;
2123 else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2) 2122 else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2)
2124 mContentPosition = -1.0; 2123 mContentPosition = -1.0;
2125 else 2124 else
2126 mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2))); 2125 mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2)));
2127 //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height()); 2126 //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height());
2128 2127
2129} 2128}
2130void KOAgenda::restorePosition() 2129void KOAgenda::restorePosition()
2131{ 2130{
2132 int posY; 2131 int posY;
2133 int max = mGridSpacingY*4*24; 2132 int max = mGridSpacingY*4*24;
2134 if ( mContentPosition < 0 ) 2133 if ( mContentPosition < 0 )
2135 posY = max-viewport()->height(); 2134 posY = max-viewport()->height();
2136 else 2135 else
2137 if ( mContentPosition == 0 ) 2136 if ( mContentPosition == 0 )
2138 posY = 0; 2137 posY = 0;
2139 else 2138 else
2140 posY = (max/mContentPosition)-(viewport()->height()/2); 2139 posY = (max/mContentPosition)-(viewport()->height()/2);
2141 setContentsPos (0, posY ); 2140 setContentsPos (0, posY );
2142 //qDebug("posY %d hei %d", posY, max); 2141 //qDebug("posY %d hei %d", posY, max);
2143 2142
2144} 2143}
2145void KOAgenda::moveChild( QWidget *w, int x , int y ) 2144void KOAgenda::moveChild( QWidget *w, int x , int y )
2146{ 2145{
2147 ++x; 2146 ++x;
2148 QScrollView::moveChild( w, x , y ); 2147 QScrollView::moveChild( w, x , y );
2149} 2148}
2150#include <qmessagebox.h> 2149#include <qmessagebox.h>
2151#ifdef DESKTOP_VERSION 2150#ifdef DESKTOP_VERSION
2152#include <qprinter.h> 2151#include <qprinter.h>
2153#include <qpainter.h> 2152#include <qpainter.h>
2154#include <qpaintdevicemetrics.h> 2153#include <qpaintdevicemetrics.h>
2155 2154
2156#endif 2155#endif
2157void KOAgenda::printSelection() 2156void KOAgenda::printSelection()
2158{ 2157{
2159#ifdef DESKTOP_VERSION 2158#ifdef DESKTOP_VERSION
2160 if ( mStartCellY == mCurrentCellY ) { 2159 if ( mStartCellY == mCurrentCellY ) {
2161 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2160 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2162 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. "), 2161 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. "),
2163 i18n("OK"), 0, 0, 2162 i18n("OK"), 0, 0,
2164 0, 1 ); 2163 0, 1 );
2165 return; 2164 return;
2166 } 2165 }
2167 2166
2168 float dx, dy; 2167 float dx, dy;
2169 int x,y,w,h; 2168 int x,y,w,h;
2170 x= 0; 2169 x= 0;
2171 w= contentsWidth()+2; 2170 w= contentsWidth()+2;
2172 // h= contentsHeight(); 2171 // h= contentsHeight();
2173 y = mGridSpacingY*mStartCellY; 2172 y = mGridSpacingY*mStartCellY;
2174 h = mGridSpacingY*(mCurrentCellY+1)-y+2; 2173 h = mGridSpacingY*(mCurrentCellY+1)-y+2;
2175 2174
2176 //return; 2175 //return;
2177 QPrinter* printer = new QPrinter(); 2176 QPrinter* printer = new QPrinter();
2178 if ( !printer->setup()) { 2177 if ( !printer->setup()) {
2179 delete printer; 2178 delete printer;
2180 return; 2179 return;
2181 } 2180 }
2182 QPainter p( printer ); 2181 QPainter p( printer );
2183 QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer ); 2182 QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer );
2184 QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() ); 2183 QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() );
2185 //date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true ); 2184 //date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true );
2186 int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height(); 2185 int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height();
2187 // p.drawText( 0, 0, date ); 2186 // p.drawText( 0, 0, date );
2188 int offset = m.width()/8; 2187 int offset = m.width()/8;
2189 // compute the scale 2188 // compute the scale
2190 dx = ((float) m.width()-offset) / (float)w; 2189 dx = ((float) m.width()-offset) / (float)w;
2191 dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h; 2190 dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h;
2192 float scale; 2191 float scale;
2193 // scale to fit the width or height of the paper 2192 // scale to fit the width or height of the paper
2194 if ( dx < dy ) 2193 if ( dx < dy )
2195 scale = dx; 2194 scale = dx;
2196 else 2195 else
2197 scale = dy; 2196 scale = dy;
2198 // set the scale 2197 // set the scale
2199 p.drawText( offset* scale, offset* scale*3/4, date ); 2198 p.drawText( offset* scale, offset* scale*3/4, date );
2200 2199
2201 int selDay; 2200 int selDay;
2202 float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count())); 2201 float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count()));
2203 float startX = 1; 2202 float startX = 1;
2204 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) 2203 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay)
2205 { 2204 {
2206 QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true ); 2205 QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true );
2207 p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) ); 2206 p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) );
2208 p.drawText( offset* scale+startX, (offset+hei)* scale, text ); 2207 p.drawText( offset* scale+startX, (offset+hei)* scale, text );
2209 startX += widOffset; 2208 startX += widOffset;
2210 2209
2211 } 2210 }
2212 p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale)); 2211 p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale));
2213 p.scale( scale, scale ); 2212 p.scale( scale, scale );
2214 p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale ); 2213 p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale );
2215 // now printing with y offset: 2 hei 2214 // now printing with y offset: 2 hei
2216 // p.translate( 0, -y*scale); 2215 // p.translate( 0, -y*scale);
2217 2216
2218 drawContentsToPainter(&p, true ); 2217 drawContentsToPainter(&p, true );
2219 globalFlagBlockAgendaItemUpdate = false; 2218 globalFlagBlockAgendaItemUpdate = false;
2220 KOAgendaItem *item; 2219 KOAgendaItem *item;
2221 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 2220 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
2222 item->select(false); 2221 item->select(false);
2223 item->paintMe( false, &p ); 2222 item->paintMe( false, &p );
2224 } 2223 }
2225 globalFlagBlockAgendaItemUpdate = true; 2224 globalFlagBlockAgendaItemUpdate = true;
2226 p.end(); 2225 p.end();
2227 delete printer; 2226 delete printer;
2228#else 2227#else
2229 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2228 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2230 i18n("Not supported \non PDA!\n"), 2229 i18n("Not supported \non PDA!\n"),
2231 i18n("OK"), 0, 0, 2230 i18n("OK"), 0, 0,
2232 0, 1 ); 2231 0, 1 );
2233#endif 2232#endif
2234} 2233}
diff --git a/korganizer/koagenda.h b/korganizer/koagenda.h
index 3d33ae5..35c08b6 100644
--- a/korganizer/koagenda.h
+++ b/korganizer/koagenda.h
@@ -1,296 +1,296 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23#ifndef KOAGENDA_H 23#ifndef KOAGENDA_H
24#define KOAGENDA_H 24#define KOAGENDA_H
25 25
26#include <qscrollview.h> 26#include <qscrollview.h>
27#include <qtimer.h> 27#include <qtimer.h>
28#include <qmemarray.h> 28#include <qmemarray.h>
29#include <qpainter.h> 29#include <qpainter.h>
30#include <qpixmap.h> 30#include <qpixmap.h>
31#include <qguardedptr.h> 31#include <qguardedptr.h>
32 32
33#include "koagendaitem.h" 33#include "koagendaitem.h"
34 34
35class QPopupMenu; 35class QPopupMenu;
36class QTime; 36class QTime;
37class KConfig; 37class KConfig;
38class QFrame; 38class QFrame;
39class KOAgenda; 39class KOAgenda;
40class KCal::Event; 40class KCal::Event;
41class KCal::Todo; 41class KCal::Todo;
42 42
43using namespace KCal; 43using namespace KCal;
44 44
45class MarcusBains : public QFrame { 45class MarcusBains : public QFrame {
46 Q_OBJECT 46 Q_OBJECT
47 public: 47 public:
48 MarcusBains(KOAgenda *agenda=0,const char *name=0); 48 MarcusBains(KOAgenda *agenda=0,const char *name=0);
49 virtual ~MarcusBains(); 49 virtual ~MarcusBains();
50 50
51 public slots: 51 public slots:
52 void updateLocation(bool recalculate=false); 52 void updateLocation(bool recalculate=false);
53 void updateLoc(); 53 void updateLoc();
54 54
55 private: 55 private:
56 int todayColumn(); 56 int todayColumn();
57 QTimer *minutes; 57 QTimer *minutes;
58 QLabel *mTimeBox; 58 QLabel *mTimeBox;
59 KOAgenda *agenda; 59 KOAgenda *agenda;
60 QTime oldTime; 60 QTime oldTime;
61 int oldToday; 61 int oldToday;
62}; 62};
63 63
64 64
65class KOAgenda : public QScrollView 65class KOAgenda : public QScrollView
66{ 66{
67 Q_OBJECT 67 Q_OBJECT
68 public: 68 public:
69 enum MouseActionType { NOP, MOVE, SELECT, 69 enum MouseActionType { NOP, MOVE, SELECT,
70 RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT }; 70 RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT };
71 71
72 KOAgenda ( int columns, int rows, int columnSize, QWidget * parent=0, 72 KOAgenda ( int columns, int rows, int columnSize, QWidget * parent=0,
73 const char * name=0, WFlags f=0 ); 73 const char * name=0, WFlags f=0 );
74 KOAgenda ( int columns, QWidget * parent=0, 74 KOAgenda ( int columns, QWidget * parent=0,
75 const char * name=0, WFlags f=0 ); 75 const char * name=0, WFlags f=0 );
76 virtual ~KOAgenda(); 76 virtual ~KOAgenda();
77 77
78 Incidence *selectedIncidence() const; 78 Incidence *selectedIncidence() const;
79 QDate selectedIncidenceDate() const; 79 QDate selectedIncidenceDate() const;
80 80
81 virtual bool eventFilter ( QObject *, QEvent * ); 81 virtual bool eventFilter ( QObject *, QEvent * );
82 82
83 void contentsToGrid (int x, int y, int& gx, int& gy); 83 void contentsToGrid (int x, int y, int& gx, int& gy);
84 void gridToContents (int gx, int gy, int& x, int& y); 84 void gridToContents (int gx, int gy, int& x, int& y);
85 85
86 int timeToY (const QTime &time); 86 int timeToY (const QTime &time);
87 QTime gyToTime (int y); 87 QTime gyToTime (int y);
88 88
89 void setStartHour(int startHour); 89 void setStartHour(int startHour);
90 90
91 KOAgendaItem *insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom); 91 KOAgendaItem *insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom);
92 KOAgendaItem *insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd); 92 KOAgendaItem *insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd);
93 void insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, 93 void insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd,
94 int YTop,int YBottom); 94 int YTop,int YBottom);
95 95
96 void changeColumns(int columns); 96 void changeColumns(int columns);
97 97
98 int columns() { return mColumns; } 98 int columns() { return mColumns; }
99 int rows() { return mRows; } 99 int rows() { return mRows; }
100 100
101 int gridSpacingX() const { return mGridSpacingX; } 101 int gridSpacingX() const { return mGridSpacingX; }
102 int gridSpacingY() const { return mGridSpacingY; } 102 int gridSpacingY() const { return mGridSpacingY; }
103 103
104// virtual QSizePolicy sizePolicy() const; 104// virtual QSizePolicy sizePolicy() const;
105 105
106 void clear(); 106 void clear();
107 107
108 void clearSelection(); 108 void clearSelection();
109 void hideUnused(); 109 void hideUnused();
110 110
111 /** Calculates the minimum width */ 111 /** Calculates the minimum width */
112 virtual int minimumWidth() const; 112 virtual int minimumWidth() const;
113 /** Update configuration from preference settings */ 113 /** Update configuration from preference settings */
114 void updateConfig(); 114 void updateConfig();
115 115
116 void checkScrollBoundaries(); 116 void checkScrollBoundaries();
117 117
118 void setHolidayMask(QMemArray<bool> *); 118 void setHolidayMask(QMemArray<bool> *);
119 void setDateList(const DateList &selectedDates); 119 void setDateList(const DateList &selectedDates);
120 DateList dateList() const; 120 DateList dateList() const;
121 void drawContentsToPainter( QPainter* paint = 0, bool backgroundOnly = false); 121 void drawContentsToPainter( QPainter* paint = 0, bool backgroundOnly = false);
122 void finishUpdate(); 122 void finishUpdate();
123 void printSelection(); 123 void printSelection();
124 void storePosition(); 124 void storePosition();
125 void restorePosition(); 125 void restorePosition();
126 126
127 127
128 public slots: 128 public slots:
129 void popupMenu(); 129 void popupMenu();
130 void newItem( int ); 130 void newItem( int );
131 void moveChild( QWidget *, int, int ); 131 void moveChild( QWidget *, int, int );
132 void scrollUp(); 132 void scrollUp();
133 void scrollDown(); 133 void scrollDown();
134 void updateTodo( Todo * t, int , bool ); 134 void updateTodo( Todo * t, int , bool );
135 void popupAlarm(); 135 void popupAlarm();
136 136
137 void checkScrollBoundaries(int); 137 void checkScrollBoundaries(int);
138 138
139 /** Deselect selected items. This function does not emit any signals. */ 139 /** Deselect selected items. This function does not emit any signals. */
140 void deselectItem(); 140 void deselectItem();
141 /** Select item. If the argument is 0, the currently selected item gets 141 /** Select item. If the argument is 0, the currently selected item gets
142 deselected. This function emits the itemSelected(bool) signal to inform 142 deselected. This function emits the itemSelected(bool) signal to inform
143 about selection/deseelction of events. */ 143 about selection/deseelction of events. */
144 void selectItem(KOAgendaItem *); 144 void selectItem(KOAgendaItem *);
145 void finishResize(); 145 void finishResize();
146 146
147 signals: 147 signals:
148 void showDateView( int, QDate ); 148 void showDateView( int, int);
149 void newEventSignal(); 149 void newEventSignal();
150 void newEventSignal(int gx,int gy); 150 void newEventSignal(int gx,int gy);
151 void newTodoSignal(int gx,int gy); 151 void newTodoSignal(int gx,int gy);
152 void newEventSignal(int gxStart, int gyStart, int gxEnd, int gyEnd); 152 void newEventSignal(int gxStart, int gyStart, int gxEnd, int gyEnd);
153 void newTimeSpanSignal(int gxStart, int gyStart, int gxEnd, int gyEnd); 153 void newTimeSpanSignal(int gxStart, int gyStart, int gxEnd, int gyEnd);
154 void newStartSelectSignal(); 154 void newStartSelectSignal();
155 void showIncidenceSignal(Incidence *); 155 void showIncidenceSignal(Incidence *);
156 void editIncidenceSignal(Incidence *); 156 void editIncidenceSignal(Incidence *);
157 void deleteIncidenceSignal(Incidence *); 157 void deleteIncidenceSignal(Incidence *);
158 void showIncidencePopupSignal(Incidence *); 158 void showIncidencePopupSignal(Incidence *);
159 159
160 void itemModified(KOAgendaItem *item, int ); 160 void itemModified(KOAgendaItem *item, int );
161 void incidenceSelected(Incidence *); 161 void incidenceSelected(Incidence *);
162 162
163 void lowerYChanged(int); 163 void lowerYChanged(int);
164 void upperYChanged(int); 164 void upperYChanged(int);
165 165
166 void startDragSignal(Incidence *); 166 void startDragSignal(Incidence *);
167 void addToCalSignal(Incidence *, Incidence *); 167 void addToCalSignal(Incidence *, Incidence *);
168 void resizedSignal(); 168 void resizedSignal();
169 169
170 protected: 170 protected:
171 QPainter mPixPainter; 171 QPainter mPixPainter;
172 QPixmap mPaintPixmap; 172 QPixmap mPaintPixmap;
173 QPixmap mHighlightPixmap; 173 QPixmap mHighlightPixmap;
174 void drawContents(QPainter *p,int cx, int cy, int cw, int ch); 174 void drawContents(QPainter *p,int cx, int cy, int cw, int ch);
175 virtual void resizeEvent ( QResizeEvent * ); 175 virtual void resizeEvent ( QResizeEvent * );
176 176
177 /** Handles mouse events. Called from eventFilter */ 177 /** Handles mouse events. Called from eventFilter */
178 virtual bool eventFilter_mouse ( QObject *, QMouseEvent * ); 178 virtual bool eventFilter_mouse ( QObject *, QMouseEvent * );
179 179
180 /** Start selecting time span. */ 180 /** Start selecting time span. */
181 void startSelectAction(QPoint viewportPos); 181 void startSelectAction(QPoint viewportPos);
182 182
183 /** Select time span. */ 183 /** Select time span. */
184 void performSelectAction(QPoint viewportPos); 184 void performSelectAction(QPoint viewportPos);
185 185
186 /** Emd selecting time span. */ 186 /** Emd selecting time span. */
187 void endSelectAction( bool emitNewEvent = false ); 187 void endSelectAction( bool emitNewEvent = false );
188 188
189 /** Start moving/resizing agenda item */ 189 /** Start moving/resizing agenda item */
190 void startItemAction(QPoint viewportPos); 190 void startItemAction(QPoint viewportPos);
191 191
192 /** Move/resize agenda item */ 192 /** Move/resize agenda item */
193 void performItemAction(QPoint viewportPos); 193 void performItemAction(QPoint viewportPos);
194 194
195 /** End moving/resizing agenda item */ 195 /** End moving/resizing agenda item */
196 void endItemAction(); 196 void endItemAction();
197 197
198 /** Set cursor, when no item action is in progress */ 198 /** Set cursor, when no item action is in progress */
199 void setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos); 199 void setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos);
200 200
201 /** Place agenda item in agenda and adjust other cells if necessary */ 201 /** Place agenda item in agenda and adjust other cells if necessary */
202 void placeSubCells(KOAgendaItem *placeItem); 202 void placeSubCells(KOAgendaItem *placeItem);
203 203
204 /** Process the keyevent, including the ignored keyevents of eventwidgets. 204 /** Process the keyevent, including the ignored keyevents of eventwidgets.
205 * Implements pgup/pgdn and cursor key navigation in the view. 205 * Implements pgup/pgdn and cursor key navigation in the view.
206 */ 206 */
207 void keyPressEvent( QKeyEvent * ); 207 void keyPressEvent( QKeyEvent * );
208 208
209 void calculateWorkingHours(); 209 void calculateWorkingHours();
210 210
211 virtual void contentsMousePressEvent ( QMouseEvent * ); 211 virtual void contentsMousePressEvent ( QMouseEvent * );
212 212
213 private: 213 private:
214 void init(); 214 void init();
215 void marcus_bains(); 215 void marcus_bains();
216 bool mAllDayMode; 216 bool mAllDayMode;
217 bool blockResize; 217 bool blockResize;
218 bool mLeftMouseDown; 218 bool mLeftMouseDown;
219 KOAgendaItem *mPopupItem; 219 KOAgendaItem *mPopupItem;
220 QTimer* mPopupTimer; 220 QTimer* mPopupTimer;
221 int mPopupKind; 221 int mPopupKind;
222 QPoint mPopupPos; 222 QPoint mPopupPos;
223 QTimer mResizeTimer; 223 QTimer mResizeTimer;
224 double mContentPosition; 224 double mContentPosition;
225 225
226 // Width and height of agenda cells 226 // Width and height of agenda cells
227 int mGridSpacingX; 227 int mGridSpacingX;
228 int mGridSpacingY; 228 int mGridSpacingY;
229 229
230 // size of border, where mouse action will resize the KOAgendaItem 230 // size of border, where mouse action will resize the KOAgendaItem
231 int mResizeBorderWidth; 231 int mResizeBorderWidth;
232 232
233 // size of border, where mouse mve will cause a scroll of the agenda 233 // size of border, where mouse mve will cause a scroll of the agenda
234 int mScrollBorderWidth; 234 int mScrollBorderWidth;
235 int mScrollDelay; 235 int mScrollDelay;
236 int mScrollOffset; 236 int mScrollOffset;
237 237
238 QTimer mScrollUpTimer; 238 QTimer mScrollUpTimer;
239 QTimer mScrollDownTimer; 239 QTimer mScrollDownTimer;
240 240
241 // Number of Columns/Rows of agenda grid 241 // Number of Columns/Rows of agenda grid
242 int mColumns; 242 int mColumns;
243 int mRows; 243 int mRows;
244 244
245 // Cells to store Move and Resize coordiantes 245 // Cells to store Move and Resize coordiantes
246 int mStartCellX; 246 int mStartCellX;
247 int mStartCellY; 247 int mStartCellY;
248 int mCurrentCellX; 248 int mCurrentCellX;
249 int mCurrentCellY; 249 int mCurrentCellY;
250 250
251 // Working Hour coordiantes 251 // Working Hour coordiantes
252 bool mWorkingHoursEnable; 252 bool mWorkingHoursEnable;
253 int mWorkingHoursYTop; 253 int mWorkingHoursYTop;
254 int mWorkingHoursYBottom; 254 int mWorkingHoursYBottom;
255 255
256 // Selection 256 // Selection
257 int mSelectionCellX; 257 int mSelectionCellX;
258 int mSelectionYTop; 258 int mSelectionYTop;
259 int mSelectionHeight; 259 int mSelectionHeight;
260 260
261 // List of dates to be displayed 261 // List of dates to be displayed
262 DateList mSelectedDates; 262 DateList mSelectedDates;
263 263
264 // The KOAgendaItem, which has been right-clicked last 264 // The KOAgendaItem, which has been right-clicked last
265 KOAgendaItem *mClickedItem; 265 KOAgendaItem *mClickedItem;
266 266
267 // The KOAgendaItem, which is being moved/resized 267 // The KOAgendaItem, which is being moved/resized
268 QGuardedPtr<KOAgendaItem> mActionItem; 268 QGuardedPtr<KOAgendaItem> mActionItem;
269 269
270 // Currently selected item 270 // Currently selected item
271 QGuardedPtr<KOAgendaItem> mSelectedItem; 271 QGuardedPtr<KOAgendaItem> mSelectedItem;
272 272
273 // The Marcus Bains Line widget. 273 // The Marcus Bains Line widget.
274 MarcusBains *mMarcusBains; 274 MarcusBains *mMarcusBains;
275 void computeSizes(); 275 void computeSizes();
276 276
277 MouseActionType mActionType; 277 MouseActionType mActionType;
278 278
279 bool mItemMoved; 279 bool mItemMoved;
280 280
281 // List of all Items contained in agenda 281 // List of all Items contained in agenda
282 QPtrList<KOAgendaItem> mItems; 282 QPtrList<KOAgendaItem> mItems;
283 QPtrList<KOAgendaItem> mUnusedItems; 283 QPtrList<KOAgendaItem> mUnusedItems;
284 KOAgendaItem* getNewItem(Incidence * event,QDate qd, QWidget* viewport); 284 KOAgendaItem* getNewItem(Incidence * event,QDate qd, QWidget* viewport);
285 QPopupMenu *mItemPopup; // Right mouse button popup menu for KOAgendaItems 285 QPopupMenu *mItemPopup; // Right mouse button popup menu for KOAgendaItems
286 QPopupMenu *mNewItemPopup; 286 QPopupMenu *mNewItemPopup;
287 287
288 int mOldLowerScrollValue; 288 int mOldLowerScrollValue;
289 int mOldUpperScrollValue; 289 int mOldUpperScrollValue;
290 KOAgendaItem * getItemForTodo ( Todo * todo ); 290 KOAgendaItem * getItemForTodo ( Todo * todo );
291 QMemArray<bool> *mHolidayMask; 291 QMemArray<bool> *mHolidayMask;
292 int mCurPixWid; 292 int mCurPixWid;
293 int mCurPixHei; 293 int mCurPixHei;
294}; 294};
295 295
296#endif // KOAGENDA_H 296#endif // KOAGENDA_H
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp
index b9909d6..2996acb 100644
--- a/korganizer/koagendaview.cpp
+++ b/korganizer/koagendaview.cpp
@@ -1,1597 +1,1608 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qhbox.h> 24#include <qhbox.h>
25#include <qvbox.h> 25#include <qvbox.h>
26#include <qlabel.h> 26#include <qlabel.h>
27#include <qframe.h> 27#include <qframe.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#ifndef KORG_NOSPLITTER 29#ifndef KORG_NOSPLITTER
30#include <qsplitter.h> 30#include <qsplitter.h>
31#endif 31#endif
32#include <qfont.h> 32#include <qfont.h>
33#include <qfontmetrics.h> 33#include <qfontmetrics.h>
34#include <qpopupmenu.h> 34#include <qpopupmenu.h>
35#include <qtooltip.h> 35#include <qtooltip.h>
36#include <qpainter.h> 36#include <qpainter.h>
37#include <qpushbutton.h> 37#include <qpushbutton.h>
38#include <qapplication.h> 38#include <qapplication.h>
39 39
40#include <kapplication.h> 40#include <kapplication.h>
41#include <KDGanttMinimizeSplitter.h> 41#include <KDGanttMinimizeSplitter.h>
42#include <kdebug.h> 42#include <kdebug.h>
43#include <kstandarddirs.h> 43#include <kstandarddirs.h>
44#include <kiconloader.h> 44#include <kiconloader.h>
45#include <klocale.h> 45#include <klocale.h>
46#include <kconfig.h> 46#include <kconfig.h>
47#include <kglobal.h> 47#include <kglobal.h>
48#include "calendarview.h" 48#include "calendarview.h"
49#include "koviewmanager.h" 49#include "koviewmanager.h"
50 50
51#include <libkcal/calendar.h> 51#include <libkcal/calendar.h>
52#include <libkcal/icaldrag.h> 52#include <libkcal/icaldrag.h>
53#include <libkcal/dndfactory.h> 53#include <libkcal/dndfactory.h>
54 54
55#include <kcalendarsystem.h> 55#include <kcalendarsystem.h>
56 56
57#include "koglobals.h" 57#include "koglobals.h"
58#ifndef KORG_NOPLUGINS 58#ifndef KORG_NOPLUGINS
59#include "kocore.h" 59#include "kocore.h"
60#endif 60#endif
61#include "koprefs.h" 61#include "koprefs.h"
62#include "koagenda.h" 62#include "koagenda.h"
63#include "koagendaitem.h" 63#include "koagendaitem.h"
64#ifndef KORG_NOPRINTER 64#ifndef KORG_NOPRINTER
65#include "calprinter.h" 65#include "calprinter.h"
66#endif 66#endif
67 67
68#include "koagendaview.h" 68#include "koagendaview.h"
69//#include "koagendaview.moc" 69//#include "koagendaview.moc"
70 70
71//extern bool globalFlagBlockPainting; 71//extern bool globalFlagBlockPainting;
72extern int globalFlagBlockAgenda; 72extern int globalFlagBlockAgenda;
73extern int globalFlagBlockStartup; 73extern int globalFlagBlockStartup;
74extern int globalFlagBlockAgendaItemPaint; 74extern int globalFlagBlockAgendaItemPaint;
75extern int globalFlagBlockAgendaItemUpdate; 75extern int globalFlagBlockAgendaItemUpdate;
76extern int globalFlagBlockLabel; 76extern int globalFlagBlockLabel;
77using namespace KOrg; 77using namespace KOrg;
78 78
79 79
80 80
81TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) : 81TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) :
82 QScrollView(parent,name,f) 82 QScrollView(parent,name,f)
83{ 83{
84 mRows = rows; 84 mRows = rows;
85 85
86 setMinimumHeight( 20 ); 86 setMinimumHeight( 20 );
87 mCellHeight = KOPrefs::instance()->mHourSize*4; 87 mCellHeight = KOPrefs::instance()->mHourSize*4;
88 88
89 enableClipper(true); 89 enableClipper(true);
90 90
91 setHScrollBarMode(AlwaysOff); 91 setHScrollBarMode(AlwaysOff);
92 setVScrollBarMode(AlwaysOff); 92 setVScrollBarMode(AlwaysOff);
93 93
94 resizeContents(50,mRows * mCellHeight); 94 resizeContents(50,mRows * mCellHeight);
95 95
96 viewport()->setBackgroundMode( PaletteBackground ); 96 viewport()->setBackgroundMode( PaletteBackground );
97} 97}
98 98
99void TimeLabels::setCellHeight(int height) 99void TimeLabels::setCellHeight(int height)
100{ 100{
101 mCellHeight = height; 101 mCellHeight = height;
102} 102}
103 103
104/* 104/*
105 Optimization so that only the "dirty" portion of the scroll view 105 Optimization so that only the "dirty" portion of the scroll view
106 is redrawn. Unfortunately, this is not called by default paintEvent() method. 106 is redrawn. Unfortunately, this is not called by default paintEvent() method.
107*/ 107*/
108void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) 108void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch)
109{ 109{
110 110
111 // if ( globalFlagBlockAgenda ) 111 // if ( globalFlagBlockAgenda )
112 // return; 112 // return;
113 // bug: the parameters cx, cy, cw, ch are the areas that need to be 113 // bug: the parameters cx, cy, cw, ch are the areas that need to be
114 // redrawn, not the area of the widget. unfortunately, this 114 // redrawn, not the area of the widget. unfortunately, this
115 // code assumes the latter... 115 // code assumes the latter...
116 116
117 // now, for a workaround... 117 // now, for a workaround...
118 // these two assignments fix the weird redraw bug 118 // these two assignments fix the weird redraw bug
119 cx = contentsX() + 2; 119 cx = contentsX() + 2;
120 cw = contentsWidth() - 2; 120 cw = contentsWidth() - 2;
121 // end of workaround 121 // end of workaround
122 122
123 int cell = ((int)(cy/mCellHeight)); 123 int cell = ((int)(cy/mCellHeight));
124 int y = cell * mCellHeight; 124 int y = cell * mCellHeight;
125 QFontMetrics fm = fontMetrics(); 125 QFontMetrics fm = fontMetrics();
126 QString hour; 126 QString hour;
127 QString suffix; 127 QString suffix;
128 int tW = fm.width("24:00i"); 128 int tW = fm.width("24:00i");
129 int timeHeight = fm.height(); 129 int timeHeight = fm.height();
130 //timeHeight -= (timeHeight/4-2); 130 //timeHeight -= (timeHeight/4-2);
131 int borderWidth = 0; 131 int borderWidth = 0;
132 QFont nFont = p->font(); 132 QFont nFont = p->font();
133 133
134 if (!KGlobal::locale()->use12Clock()) 134 if (!KGlobal::locale()->use12Clock())
135 suffix = "00"; 135 suffix = "00";
136 else 136 else
137 borderWidth = 0; 137 borderWidth = 0;
138 if ( timeHeight > mCellHeight ) { 138 if ( timeHeight > mCellHeight ) {
139 timeHeight = mCellHeight-1; 139 timeHeight = mCellHeight-1;
140 int pointS = nFont.pointSize(); 140 int pointS = nFont.pointSize();
141 while ( pointS > 4 ) { 141 while ( pointS > 4 ) {
142 nFont.setPointSize( pointS ); 142 nFont.setPointSize( pointS );
143 fm = QFontMetrics( nFont ); 143 fm = QFontMetrics( nFont );
144 if ( fm.height() < mCellHeight ) 144 if ( fm.height() < mCellHeight )
145 break; 145 break;
146 -- pointS; 146 -- pointS;
147 } 147 }
148 fm = QFontMetrics( nFont ); 148 fm = QFontMetrics( nFont );
149 borderWidth = 4; 149 borderWidth = 4;
150 timeHeight = fm.height(); 150 timeHeight = fm.height();
151 } 151 }
152 timeHeight -= (timeHeight/4-2); 152 timeHeight -= (timeHeight/4-2);
153 QFont sFont = nFont; 153 QFont sFont = nFont;
154 sFont.setPointSize( sFont.pointSize()/2+2 ); 154 sFont.setPointSize( sFont.pointSize()/2+2 );
155 QFontMetrics fmS( sFont ); 155 QFontMetrics fmS( sFont );
156 int sHei = fmS.height(); 156 int sHei = fmS.height();
157 sHei -= (sHei/4-2); 157 sHei -= (sHei/4-2);
158 int startW = this->width() - frameWidth(); 158 int startW = this->width() - frameWidth();
159 while (y < cy + ch) { 159 while (y < cy + ch) {
160 p->drawLine(cx,y,cx+tW,y); 160 p->drawLine(cx,y,cx+tW,y);
161 hour.setNum(cell); 161 hour.setNum(cell);
162 162
163 // handle 24h and am/pm time formats 163 // handle 24h and am/pm time formats
164 if (KGlobal::locale()->use12Clock()) { 164 if (KGlobal::locale()->use12Clock()) {
165 if (cell > 11) suffix = "pm"; 165 if (cell > 11) suffix = "pm";
166 else 166 else
167 suffix = "am"; 167 suffix = "am";
168 if (cell == 0) hour.setNum(12); 168 if (cell == 0) hour.setNum(12);
169 if (cell > 12) hour.setNum(cell - 12); 169 if (cell > 12) hour.setNum(cell - 12);
170 } 170 }
171 171
172 // center and draw the time label 172 // center and draw the time label
173 int timeWidth = fm.width(hour+"i"); 173 int timeWidth = fm.width(hour+"i");
174 int tw2 = fm.width(suffix); 174 int tw2 = fm.width(suffix);
175 int offset = startW - timeWidth - tw2 ; 175 int offset = startW - timeWidth - tw2 ;
176 p->setFont( nFont ); 176 p->setFont( nFont );
177 p->drawText(cx - borderWidth + offset, y+ timeHeight, hour); 177 p->drawText(cx - borderWidth + offset, y+ timeHeight, hour);
178 p->setFont( sFont ); 178 p->setFont( sFont );
179 offset = startW - tw2-1; 179 offset = startW - tw2-1;
180 p->drawText(cx - borderWidth + offset, y+ sHei, suffix); 180 p->drawText(cx - borderWidth + offset, y+ sHei, suffix);
181 181
182 // increment indices 182 // increment indices
183 y += mCellHeight; 183 y += mCellHeight;
184 cell++; 184 cell++;
185 } 185 }
186} 186}
187 187
188/** 188/**
189 Calculates the minimum width. 189 Calculates the minimum width.
190*/ 190*/
191int TimeLabels::minimumWidth() const 191int TimeLabels::minimumWidth() const
192{ 192{
193 return mMiniWidth; 193 return mMiniWidth;
194} 194}
195 195
196/** updates widget's internal state */ 196/** updates widget's internal state */
197void TimeLabels::updateConfig() 197void TimeLabels::updateConfig()
198{ 198{
199 // set the font 199 // set the font
200 // config->setGroup("Fonts"); 200 // config->setGroup("Fonts");
201 // QFont font = config->readFontEntry("TimeBar Font"); 201 // QFont font = config->readFontEntry("TimeBar Font");
202 setFont(KOPrefs::instance()->mTimeBarFont); 202 setFont(KOPrefs::instance()->mTimeBarFont);
203 QString test = "88:88"; 203 QString test = "88:88";
204 if (KGlobal::locale()->use12Clock()) 204 if (KGlobal::locale()->use12Clock())
205 test += "i"; 205 test += "i";
206 mMiniWidth = fontMetrics().width(test) + frameWidth()*2 +1 ; 206 mMiniWidth = fontMetrics().width(test) + frameWidth()*2 +1 ;
207 // update geometry restrictions based on new settings 207 // update geometry restrictions based on new settings
208 setFixedWidth(minimumWidth()); 208 setFixedWidth(minimumWidth());
209 209
210 // update HourSize 210 // update HourSize
211 mCellHeight = KOPrefs::instance()->mHourSize*4; 211 mCellHeight = KOPrefs::instance()->mHourSize*4;
212 resizeContents(50,mRows * mCellHeight); 212 resizeContents(50,mRows * mCellHeight);
213} 213}
214 214
215/** update time label positions */ 215/** update time label positions */
216void TimeLabels::positionChanged() 216void TimeLabels::positionChanged()
217{ 217{
218 int adjustment = mAgenda->contentsY(); 218 int adjustment = mAgenda->contentsY();
219 setContentsPos(0, adjustment); 219 setContentsPos(0, adjustment);
220} 220}
221 221
222/** */ 222/** */
223void TimeLabels::setAgenda(KOAgenda* agenda) 223void TimeLabels::setAgenda(KOAgenda* agenda)
224{ 224{
225 mAgenda = agenda; 225 mAgenda = agenda;
226} 226}
227 227
228void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) 228void TimeLabels::contentsMousePressEvent ( QMouseEvent * e)
229{ 229{
230 mMouseDownY = e->pos().y(); 230 mMouseDownY = e->pos().y();
231 mOrgCap = topLevelWidget()->caption(); 231 mOrgCap = topLevelWidget()->caption();
232} 232}
233 233
234void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) 234void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e )
235{ 235{
236 int diff = mMouseDownY - e->pos().y(); 236 int diff = mMouseDownY - e->pos().y();
237 if ( diff < 10 && diff > -10 ) 237 if ( diff < 10 && diff > -10 )
238 return; 238 return;
239 int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; 239 int tSize = KOPrefs::instance()->mHourSize + (diff/10) ;
240 if ( tSize < 4 ) 240 if ( tSize < 4 )
241 tSize = 4; 241 tSize = 4;
242 if ( tSize > 22 ) 242 if ( tSize > 22 )
243 tSize = 22; 243 tSize = 22;
244 tSize = (tSize-2)/2; 244 tSize = (tSize-2)/2;
245 topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); 245 topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize));
246 246
247} 247}
248void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) 248void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e )
249{ 249{
250 topLevelWidget()->setCaption( mOrgCap ); 250 topLevelWidget()->setCaption( mOrgCap );
251 int diff = mMouseDownY - e->pos().y(); 251 int diff = mMouseDownY - e->pos().y();
252 if ( diff < 10 && diff > -10 ) 252 if ( diff < 10 && diff > -10 )
253 return; 253 return;
254 int tSize = KOPrefs::instance()->mHourSize + (diff/10); 254 int tSize = KOPrefs::instance()->mHourSize + (diff/10);
255 if ( tSize < 4 ) 255 if ( tSize < 4 )
256 tSize = 4; 256 tSize = 4;
257 if ( tSize > 22 ) 257 if ( tSize > 22 )
258 tSize = 22; 258 tSize = 22;
259 tSize = (tSize/2)*2; 259 tSize = (tSize/2)*2;
260 if ( tSize == KOPrefs::instance()->mHourSize ) 260 if ( tSize == KOPrefs::instance()->mHourSize )
261 return; 261 return;
262 KOPrefs::instance()->mHourSize = tSize; 262 KOPrefs::instance()->mHourSize = tSize;
263 emit scaleChanged(); 263 emit scaleChanged();
264} 264}
265 265
266/** This is called in response to repaint() */ 266/** This is called in response to repaint() */
267void TimeLabels::paintEvent(QPaintEvent*) 267void TimeLabels::paintEvent(QPaintEvent*)
268{ 268{
269 269
270 // kdDebug() << "paintevent..." << endl; 270 // kdDebug() << "paintevent..." << endl;
271 // this is another hack! 271 // this is another hack!
272 // QPainter painter(this); 272 // QPainter painter(this);
273 //QString c 273 //QString c
274 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight()); 274 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight());
275} 275}
276 276
277//////////////////////////////////////////////////////////////////////////// 277////////////////////////////////////////////////////////////////////////////
278 278
279EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name) 279EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name)
280 : QFrame(parent,name) 280 : QFrame(parent,name)
281{ 281{
282 mColumns = 1; 282 mColumns = 1;
283 mTopBox = 0; 283 mTopBox = 0;
284 mLocation = loc; 284 mLocation = loc;
285 mTopLayout = 0; 285 mTopLayout = 0;
286 mPaintWidget = 0; 286 mPaintWidget = 0;
287 mXOffset = 0; 287 mXOffset = 0;
288 if (mLocation == Top) mPixmap = SmallIcon("1uparrow"); 288 if (mLocation == Top) mPixmap = SmallIcon("1uparrow");
289 else mPixmap = SmallIcon("1downarrow"); 289 else mPixmap = SmallIcon("1downarrow");
290 mEnabled.resize(mColumns); 290 mEnabled.resize(mColumns);
291 mEnabled.fill( false ); 291 mEnabled.fill( false );
292 setMinimumHeight(mPixmap.height()); 292 setMinimumHeight(mPixmap.height());
293} 293}
294 294
295EventIndicator::~EventIndicator() 295EventIndicator::~EventIndicator()
296{ 296{
297} 297}
298 298
299void EventIndicator::drawContents(QPainter *p) 299void EventIndicator::drawContents(QPainter *p)
300{ 300{
301 301
302 // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl; 302 // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl;
303 KDGanttSplitterHandle* han = 0; 303 KDGanttSplitterHandle* han = 0;
304 if ( mPaintWidget ) 304 if ( mPaintWidget )
305 han = mPaintWidget->firstHandle(); 305 han = mPaintWidget->firstHandle();
306 if ( ! han ) { 306 if ( ! han ) {
307 int i; 307 int i;
308 for(i=0;i<mColumns;++i) { 308 for(i=0;i<mColumns;++i) {
309 if (mEnabled[i]) { 309 if (mEnabled[i]) {
310 int cellWidth = contentsRect().right()/mColumns; 310 int cellWidth = contentsRect().right()/mColumns;
311 int xOffset = KOGlobals::self()->reverseLayout() ? 311 int xOffset = KOGlobals::self()->reverseLayout() ?
312 (mColumns - 1 - i)*cellWidth + (cellWidth -mPixmap.width())/2 : 312 (mColumns - 1 - i)*cellWidth + (cellWidth -mPixmap.width())/2 :
313 i*cellWidth + (cellWidth -mPixmap.width()) /2; 313 i*cellWidth + (cellWidth -mPixmap.width()) /2;
314 p->drawPixmap(QPoint(1+xOffset,0),mPixmap); 314 p->drawPixmap(QPoint(1+xOffset,0),mPixmap);
315 } 315 }
316 } 316 }
317 } else { 317 } else {
318 han->repaint(); 318 han->repaint();
319 //mPaintWidget->setBackgroundColor( red ); 319 //mPaintWidget->setBackgroundColor( red );
320 320
321 QPainter pa( han ); 321 QPainter pa( han );
322 int i; 322 int i;
323 bool setColor = false; 323 bool setColor = false;
324 for(i=0;i<mColumns;++i) { 324 for(i=0;i<mColumns;++i) {
325 if (mEnabled[i]) { 325 if (mEnabled[i]) {
326 setColor = true; 326 setColor = true;
327 327
328 int cellWidth = contentsRect().right()/mColumns; 328 int cellWidth = contentsRect().right()/mColumns;
329 int xOffset = KOGlobals::self()->reverseLayout() ? 329 int xOffset = KOGlobals::self()->reverseLayout() ?
330 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 : 330 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 :
331 i*cellWidth + cellWidth/2 -mPixmap.width()/2; 331 i*cellWidth + cellWidth/2 -mPixmap.width()/2;
332 pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap); 332 pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap);
333 //qDebug("222draw pix %d ",xOffset ); 333 //qDebug("222draw pix %d ",xOffset );
334 334
335 } 335 }
336 336
337 } 337 }
338 pa.end(); 338 pa.end();
339 339
340 } 340 }
341} 341}
342 342
343void EventIndicator::setXOffset( int x ) 343void EventIndicator::setXOffset( int x )
344{ 344{
345 mXOffset = x; 345 mXOffset = x;
346} 346}
347void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w ) 347void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w )
348{ 348{
349 mPaintWidget = w; 349 mPaintWidget = w;
350 setMaximumHeight(0); 350 setMaximumHeight(0);
351 setMinimumHeight(0); 351 setMinimumHeight(0);
352} 352}
353void EventIndicator::changeColumns(int columns) 353void EventIndicator::changeColumns(int columns)
354{ 354{
355 mColumns = columns; 355 mColumns = columns;
356 mEnabled.resize(mColumns); 356 mEnabled.resize(mColumns);
357 357
358 update(); 358 update();
359} 359}
360 360
361void EventIndicator::enableColumn(int column, bool enable) 361void EventIndicator::enableColumn(int column, bool enable)
362{ 362{
363 mEnabled[column] = enable; 363 mEnabled[column] = enable;
364} 364}
365 365
366 366
367//////////////////////////////////////////////////////////////////////////// 367////////////////////////////////////////////////////////////////////////////
368//////////////////////////////////////////////////////////////////////////// 368////////////////////////////////////////////////////////////////////////////
369//////////////////////////////////////////////////////////////////////////// 369////////////////////////////////////////////////////////////////////////////
370 370
371KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) : 371KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) :
372 KOEventView (cal,parent,name) 372 KOEventView (cal,parent,name)
373{ 373{
374 mBlockUpdating = true; 374 mBlockUpdating = true;
375 mStartHour = 8; 375 mStartHour = 8;
376 mSelectedDates.append(QDate::currentDate()); 376 mSelectedDates.append(QDate::currentDate());
377 377
378 mLayoutDayLabels = 0; 378 mLayoutDayLabels = 0;
379 mDayLabelsFrame = 0; 379 mDayLabelsFrame = 0;
380 mDayLabels = 0; 380 mDayLabels = 0;
381 bool isRTL = KOGlobals::self()->reverseLayout(); 381 bool isRTL = KOGlobals::self()->reverseLayout();
382 QPixmap expandPix; 382 QPixmap expandPix;
383 if ( KOPrefs::instance()->mVerticalScreen ) { 383 if ( KOPrefs::instance()->mVerticalScreen ) {
384 expandPix = SmallIcon( "1updownarrow" ); 384 expandPix = SmallIcon( "1updownarrow" );
385 } else { 385 } else {
386 expandPix = SmallIcon("1leftrightarrow" ); 386 expandPix = SmallIcon("1leftrightarrow" );
387 } 387 }
388 388
389 QBoxLayout *topLayout = new QVBoxLayout(this); 389 QBoxLayout *topLayout = new QVBoxLayout(this);
390 390
391 // Create day name labels for agenda columns 391 // Create day name labels for agenda columns
392 // Create agenda splitter 392 // Create agenda splitter
393 393
394 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this); 394 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this);
395 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 395 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
396 topLayout->addWidget( mSplitterAgenda ); 396 topLayout->addWidget( mSplitterAgenda );
397 mAllDayFrame = new QHBox(mSplitterAgenda); 397 mAllDayFrame = new QHBox(mSplitterAgenda);
398 mAllDayFrame->setFocusPolicy(NoFocus); 398 mAllDayFrame->setFocusPolicy(NoFocus);
399 QWidget *agendaFrame = new QWidget(mSplitterAgenda); 399 QWidget *agendaFrame = new QWidget(mSplitterAgenda);
400 agendaFrame->setFocusPolicy(NoFocus); 400 agendaFrame->setFocusPolicy(NoFocus);
401 401
402 // Create all-day agenda widget 402 // Create all-day agenda widget
403 mDummyAllDayLeft = new QVBox( mAllDayFrame ); 403 mDummyAllDayLeft = new QVBox( mAllDayFrame );
404 404
405 mExpandButton = new QPushButton(mDummyAllDayLeft); 405 mExpandButton = new QPushButton(mDummyAllDayLeft);
406 mExpandButton->setPixmap( expandPix ); 406 mExpandButton->setPixmap( expandPix );
407 int widebut = mExpandButton->sizeHint().width()+4; 407 int widebut = mExpandButton->sizeHint().width()+4;
408 int heibut = mExpandButton->sizeHint().height()+4; 408 int heibut = mExpandButton->sizeHint().height()+4;
409 if ( heibut > widebut ) 409 if ( heibut > widebut )
410 widebut = heibut ; 410 widebut = heibut ;
411 if ( QApplication::desktop()->width() < 480 ) 411 if ( QApplication::desktop()->width() < 480 )
412 widebut = widebut*3/2; 412 widebut = widebut*3/2;
413 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, 413 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed,
414 // QSizePolicy::Fixed ) ); 414 // QSizePolicy::Fixed ) );
415 mExpandButton->setFixedSize( widebut, widebut); 415 mExpandButton->setFixedSize( widebut, widebut);
416 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) ); 416 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) );
417 mExpandButton->setFocusPolicy(NoFocus); 417 mExpandButton->setFocusPolicy(NoFocus);
418 mAllDayAgenda = new KOAgenda(1,mAllDayFrame); 418 mAllDayAgenda = new KOAgenda(1,mAllDayFrame);
419 mAllDayAgenda->setFocusPolicy(NoFocus); 419 mAllDayAgenda->setFocusPolicy(NoFocus);
420 QLabel *dummyAllDayRight = new QLabel (mAllDayFrame); 420 QLabel *dummyAllDayRight = new QLabel (mAllDayFrame);
421 421
422 // Create event context menu for all day agenda 422 // Create event context menu for all day agenda
423 mAllDayAgendaPopup = eventPopup(); 423 mAllDayAgendaPopup = eventPopup();
424 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), 424 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
425 mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *))); 425 mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
426 426
427 // Create agenda frame 427 // Create agenda frame
428 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,4,3); 428 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,4,3);
429 // QHBox *agendaFrame = new QHBox(splitterAgenda); 429 // QHBox *agendaFrame = new QHBox(splitterAgenda);
430 430
431 // create event indicator bars 431 // create event indicator bars
432 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame); 432 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame);
433#ifndef DESKTOP_VERSION 433#ifndef DESKTOP_VERSION
434 // FIX 434 // FIX
435 mEventIndicatorTop->setPaintWidget( mSplitterAgenda ); 435 mEventIndicatorTop->setPaintWidget( mSplitterAgenda );
436#endif 436#endif
437 mDayLabelsFrame = new QHBox(agendaFrame); 437 mDayLabelsFrame = new QHBox(agendaFrame);
438 //topLayout->addWidget(mDayLabelsFrame); 438 //topLayout->addWidget(mDayLabelsFrame);
439 mDayLabels = new QFrame (mDayLabelsFrame); 439 mDayLabels = new QFrame (mDayLabelsFrame);
440 mLayoutDayLabels = new QHBoxLayout(mDayLabels); 440 mLayoutDayLabels = new QHBoxLayout(mDayLabels);
441 agendaLayout->addMultiCellWidget(mDayLabelsFrame ,0,0,0,2); 441 agendaLayout->addMultiCellWidget(mDayLabelsFrame ,0,0,0,2);
442 agendaLayout->addWidget(mEventIndicatorTop,1,1); 442 agendaLayout->addWidget(mEventIndicatorTop,1,1);
443 443
444 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom, 444 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom,
445 agendaFrame); 445 agendaFrame);
446 agendaLayout->addWidget(mEventIndicatorBottom,3,1); 446 agendaLayout->addWidget(mEventIndicatorBottom,3,1);
447 QWidget *dummyAgendaRight = new QWidget(agendaFrame); 447 QWidget *dummyAgendaRight = new QWidget(agendaFrame);
448 agendaLayout->addWidget(dummyAgendaRight,1,2); 448 agendaLayout->addWidget(dummyAgendaRight,1,2);
449 449
450 // Create time labels 450 // Create time labels
451 mTimeLabels = new TimeLabels(24,agendaFrame); 451 mTimeLabels = new TimeLabels(24,agendaFrame);
452 agendaLayout->addWidget(mTimeLabels,2,0); 452 agendaLayout->addWidget(mTimeLabels,2,0);
453 connect(mTimeLabels,SIGNAL( scaleChanged()), 453 connect(mTimeLabels,SIGNAL( scaleChanged()),
454 this,SLOT(updateConfig())); 454 this,SLOT(updateConfig()));
455 455
456 // Create agenda 456 // Create agenda
457 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame); 457 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame);
458 agendaLayout->addMultiCellWidget(mAgenda,2,2,1,2); 458 agendaLayout->addMultiCellWidget(mAgenda,2,2,1,2);
459 agendaLayout->setColStretch(1,1); 459 agendaLayout->setColStretch(1,1);
460 mAgenda->setFocusPolicy(NoFocus); 460 mAgenda->setFocusPolicy(NoFocus);
461 // Create event context menu for agenda 461 // Create event context menu for agenda
462 mAgendaPopup = eventPopup(); 462 mAgendaPopup = eventPopup();
463 463
464 mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")), 464 mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")),
465 i18n("Toggle Alarm"),mAgenda, 465 i18n("Toggle Alarm"),mAgenda,
466 SLOT(popupAlarm()),true); 466 SLOT(popupAlarm()),true);
467 467
468 468
469 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), 469 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
470 mAgendaPopup,SLOT(showIncidencePopup(Incidence *))); 470 mAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
471 471
472 // make connections between dependent widgets 472 // make connections between dependent widgets
473 mTimeLabels->setAgenda(mAgenda); 473 mTimeLabels->setAgenda(mAgenda);
474 474
475 // Update widgets to reflect user preferences 475 // Update widgets to reflect user preferences
476 // updateConfig(); 476 // updateConfig();
477 477
478 // createDayLabels(); 478 // createDayLabels();
479 479
480 // these blank widgets make the All Day Event box line up with the agenda 480 // these blank widgets make the All Day Event box line up with the agenda
481 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 481 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
482 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 482 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
483 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 483 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
484 484
485 // Scrolling 485 // Scrolling
486 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)), 486 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)),
487 mTimeLabels, SLOT(positionChanged())); 487 mTimeLabels, SLOT(positionChanged()));
488 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)), 488 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)),
489 SLOT(setContentsPos(int))); 489 SLOT(setContentsPos(int)));
490 490
491 connect(mAgenda,SIGNAL(showDateView( int, QDate )),SIGNAL(showDateView( int, QDate ))); 491 connect(mAgenda,SIGNAL(showDateView( int, int)),SLOT(slotShowDateView( int, int )));
492 connect(mAllDayAgenda,SIGNAL(showDateView( int, QDate )),SIGNAL(showDateView( int, QDate ))); 492 connect(mAllDayAgenda,SIGNAL(showDateView( int, int )), SLOT(slotShowDateView( int, int ) ));
493 493
494 // Create/Show/Edit/Delete Event 494 // Create/Show/Edit/Delete Event
495 connect(mAgenda,SIGNAL(newEventSignal(int,int)), 495 connect(mAgenda,SIGNAL(newEventSignal(int,int)),
496 SLOT(newEvent(int,int))); 496 SLOT(newEvent(int,int)));
497 connect(mAgenda,SIGNAL(newTodoSignal(int,int)), 497 connect(mAgenda,SIGNAL(newTodoSignal(int,int)),
498 SLOT(newTodo(int,int))); 498 SLOT(newTodo(int,int)));
499 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)), 499 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)),
500 SLOT(newEvent(int,int,int,int))); 500 SLOT(newEvent(int,int,int,int)));
501 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)), 501 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)),
502 SLOT(newEventAllDay(int,int))); 502 SLOT(newEventAllDay(int,int)));
503 connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)), 503 connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)),
504 SLOT(newTodoAllDay(int,int))); 504 SLOT(newTodoAllDay(int,int)));
505 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)), 505 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)),
506 SLOT(newEventAllDay(int,int))); 506 SLOT(newEventAllDay(int,int)));
507 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 507 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
508 SLOT(newTimeSpanSelected(int,int,int,int))); 508 SLOT(newTimeSpanSelected(int,int,int,int)));
509 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 509 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
510 SLOT(newTimeSpanSelectedAllDay(int,int,int,int))); 510 SLOT(newTimeSpanSelectedAllDay(int,int,int,int)));
511 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 511 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
512 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 512 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
513 513
514 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 514 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
515 SIGNAL(editIncidenceSignal(Incidence *))); 515 SIGNAL(editIncidenceSignal(Incidence *)));
516 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 516 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
517 SIGNAL(editIncidenceSignal(Incidence *))); 517 SIGNAL(editIncidenceSignal(Incidence *)));
518 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 518 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
519 SIGNAL(showIncidenceSignal(Incidence *))); 519 SIGNAL(showIncidenceSignal(Incidence *)));
520 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 520 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
521 SIGNAL(showIncidenceSignal(Incidence *))); 521 SIGNAL(showIncidenceSignal(Incidence *)));
522 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 522 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
523 SIGNAL(deleteIncidenceSignal(Incidence *))); 523 SIGNAL(deleteIncidenceSignal(Incidence *)));
524 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 524 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
525 SIGNAL(deleteIncidenceSignal(Incidence *))); 525 SIGNAL(deleteIncidenceSignal(Incidence *)));
526 526
527 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 527 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
528 SLOT(updateEventDates(KOAgendaItem *, int ))); 528 SLOT(updateEventDates(KOAgendaItem *, int )));
529 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 529 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
530 SLOT(updateEventDates(KOAgendaItem *, int))); 530 SLOT(updateEventDates(KOAgendaItem *, int)));
531 531
532 // event indicator update 532 // event indicator update
533 connect(mAgenda,SIGNAL(lowerYChanged(int)), 533 connect(mAgenda,SIGNAL(lowerYChanged(int)),
534 SLOT(updateEventIndicatorTop(int))); 534 SLOT(updateEventIndicatorTop(int)));
535 connect(mAgenda,SIGNAL(upperYChanged(int)), 535 connect(mAgenda,SIGNAL(upperYChanged(int)),
536 SLOT(updateEventIndicatorBottom(int))); 536 SLOT(updateEventIndicatorBottom(int)));
537 // drag signals 537 // drag signals
538 /* 538 /*
539 connect(mAgenda,SIGNAL(startDragSignal(Event *)), 539 connect(mAgenda,SIGNAL(startDragSignal(Event *)),
540 SLOT(startDrag(Event *))); 540 SLOT(startDrag(Event *)));
541 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)), 541 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)),
542 SLOT(startDrag(Event *))); 542 SLOT(startDrag(Event *)));
543 */ 543 */
544 // synchronize selections 544 // synchronize selections
545 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 545 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
546 mAllDayAgenda, SLOT( deselectItem() ) ); 546 mAllDayAgenda, SLOT( deselectItem() ) );
547 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 547 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
548 mAgenda, SLOT( deselectItem() ) ); 548 mAgenda, SLOT( deselectItem() ) );
549 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 549 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
550 SIGNAL( incidenceSelected( Incidence * ) ) ); 550 SIGNAL( incidenceSelected( Incidence * ) ) );
551 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 551 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
552 SIGNAL( incidenceSelected( Incidence * ) ) ); 552 SIGNAL( incidenceSelected( Incidence * ) ) );
553 connect( mAgenda, SIGNAL( resizedSignal() ), 553 connect( mAgenda, SIGNAL( resizedSignal() ),
554 SLOT( updateConfig( ) ) ); 554 SLOT( updateConfig( ) ) );
555 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ), 555 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ),
556 SLOT( addToCalSlot(Incidence *, Incidence * ) ) ); 556 SLOT( addToCalSlot(Incidence *, Incidence * ) ) );
557 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ), 557 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ),
558 SLOT( addToCalSlot(Incidence * , Incidence *) ) ); 558 SLOT( addToCalSlot(Incidence * , Incidence *) ) );
559 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 559 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
560 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 560 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
561 561
562 562
563} 563}
564 564
565void KOAgendaView::toggleAllDay() 565void KOAgendaView::toggleAllDay()
566{ 566{
567 if ( mSplitterAgenda->firstHandle() ) 567 if ( mSplitterAgenda->firstHandle() )
568 mSplitterAgenda->firstHandle()->toggle(); 568 mSplitterAgenda->firstHandle()->toggle();
569} 569}
570void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld ) 570void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld )
571{ 571{
572 calendar()->addIncidence( inc ); 572 calendar()->addIncidence( inc );
573 573
574 if ( incOld ) { 574 if ( incOld ) {
575 if ( incOld->type() == "Todo" ) 575 if ( incOld->type() == "Todo" )
576 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED ); 576 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED );
577 else 577 else
578 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED); 578 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED);
579 } 579 }
580 580
581} 581}
582 582
583KOAgendaView::~KOAgendaView() 583KOAgendaView::~KOAgendaView()
584{ 584{
585 delete mAgendaPopup; 585 delete mAgendaPopup;
586 delete mAllDayAgendaPopup; 586 delete mAllDayAgendaPopup;
587 delete KOAgendaItem::paintPix(); 587 delete KOAgendaItem::paintPix();
588 delete KOAgendaItem::paintPixSel(); 588 delete KOAgendaItem::paintPixSel();
589} 589}
590void KOAgendaView::resizeEvent( QResizeEvent* e ) 590void KOAgendaView::resizeEvent( QResizeEvent* e )
591{ 591{
592 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); 592 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width());
593 bool uc = false; 593 bool uc = false;
594 int ow = e->oldSize().width(); 594 int ow = e->oldSize().width();
595 int oh = e->oldSize().height(); 595 int oh = e->oldSize().height();
596 int w = e->size().width(); 596 int w = e->size().width();
597 int h = e->size().height(); 597 int h = e->size().height();
598 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { 598 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) {
599 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) 599 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda )
600 uc = true; 600 uc = true;
601 //qDebug("view changed %d %d %d %d ", ow, oh , w , h); 601 //qDebug("view changed %d %d %d %d ", ow, oh , w , h);
602 } 602 }
603 mUpcomingWidth = e->size().width() ; 603 mUpcomingWidth = e->size().width() ;
604 if ( mBlockUpdating || uc ) { 604 if ( mBlockUpdating || uc ) {
605 mBlockUpdating = false; 605 mBlockUpdating = false;
606 //mAgenda->setMinimumSize(800 , 600 ); 606 //mAgenda->setMinimumSize(800 , 600 );
607 //qDebug("mAgenda->resize+++++++++++++++ "); 607 //qDebug("mAgenda->resize+++++++++++++++ ");
608 updateConfig(); 608 updateConfig();
609 //qDebug("KOAgendaView::Updating now possible "); 609 //qDebug("KOAgendaView::Updating now possible ");
610 } else 610 } else
611 createDayLabels(); 611 createDayLabels();
612 //qDebug("resizeEvent end "); 612 //qDebug("resizeEvent end ");
613 613
614} 614}
615void KOAgendaView::slotDaylabelClicked( int num ) 615void KOAgendaView::slotDaylabelClicked( int num )
616{ 616{
617 617
618 QDate firstDate = mSelectedDates.first(); 618 QDate firstDate = mSelectedDates.first();
619 if ( num == -1 ) 619 if ( num == -1 )
620 emit showDateView( 6, firstDate ); 620 emit showDateView( 6, firstDate );
621 else if (num >= 0 ) { 621 else if (num >= 0 ) {
622 if ( mSelectedDates.count() == 1) 622 if ( mSelectedDates.count() == 1)
623 emit showDateView( 9, firstDate.addDays( num ) ); 623 emit showDateView( 9, firstDate.addDays( num ) );
624 else 624 else
625 emit showDateView( 3, firstDate.addDays( num ) ); 625 emit showDateView( 3, firstDate.addDays( num ) );
626 } 626 }
627 else 627 else
628 showDateView( 10, firstDate.addDays(1) ); 628 showDateView( 10, firstDate.addDays(1) );
629} 629}
630 630
631KOAgendaButton* KOAgendaView::getNewDaylabel() 631KOAgendaButton* KOAgendaView::getNewDaylabel()
632{ 632{
633 633
634 KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels); 634 KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels);
635 connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) ); 635 connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) );
636 mDayLabelsList.append( dayLabel ); 636 mDayLabelsList.append( dayLabel );
637 mLayoutDayLabels->addWidget(dayLabel); 637 mLayoutDayLabels->addWidget(dayLabel);
638 return dayLabel ; 638 return dayLabel ;
639} 639}
640 640
641void KOAgendaView::createDayLabels() 641void KOAgendaView::createDayLabels()
642{ 642{
643 643
644 if ( mBlockUpdating || globalFlagBlockLabel == 1) { 644 if ( mBlockUpdating || globalFlagBlockLabel == 1) {
645 // qDebug(" KOAgendaView::createDayLabels() blocked "); 645 // qDebug(" KOAgendaView::createDayLabels() blocked ");
646 return; 646 return;
647 647
648 } 648 }
649 int newHight; 649 int newHight;
650 650
651 // ### Before deleting and recreating we could check if mSelectedDates changed... 651 // ### Before deleting and recreating we could check if mSelectedDates changed...
652 // It would remove some flickering and gain speed (since this is called by 652 // It would remove some flickering and gain speed (since this is called by
653 // each updateView() call) 653 // each updateView() call)
654 654
655 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - 2; 655 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - 2;
656 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); 656 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth );
657 if ( maxWid < 0 ) 657 if ( maxWid < 0 )
658 maxWid = 20; 658 maxWid = 20;
659 659
660 QFont dlf = KOPrefs::instance()->mTimeLabelsFont; 660 QFont dlf = KOPrefs::instance()->mTimeLabelsFont;
661 QFontMetrics fm ( dlf ); 661 QFontMetrics fm ( dlf );
662 int selCount = mSelectedDates.count(); 662 int selCount = mSelectedDates.count();
663 QString dayTest = "Mon 20"; 663 QString dayTest = "Mon 20";
664 //QString dayTest = "Mon 20"; 664 //QString dayTest = "Mon 20";
665 int wid = fm.width( dayTest ); 665 int wid = fm.width( dayTest );
666 //maxWid -= ( selCount * 3 ); //working for QLabels 666 //maxWid -= ( selCount * 3 ); //working for QLabels
667 maxWid -= ( selCount * 3 ); //working for QPushButton 667 maxWid -= ( selCount * 3 ); //working for QPushButton
668 if ( maxWid < 0 ) 668 if ( maxWid < 0 )
669 maxWid = 20; 669 maxWid = 20;
670 int needWid = wid * selCount; 670 int needWid = wid * selCount;
671 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); 671 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid );
672 //if ( needWid > maxWid ) 672 //if ( needWid > maxWid )
673 // qDebug("DAYLABELS TOOOOOOO BIG "); 673 // qDebug("DAYLABELS TOOOOOOO BIG ");
674 while ( needWid > maxWid ) { 674 while ( needWid > maxWid ) {
675 dayTest = dayTest.left( dayTest.length() - 1 ); 675 dayTest = dayTest.left( dayTest.length() - 1 );
676 wid = fm.width( dayTest ); 676 wid = fm.width( dayTest );
677 needWid = wid * selCount; 677 needWid = wid * selCount;
678 } 678 }
679 int maxLen = dayTest.length(); 679 int maxLen = dayTest.length();
680 int fontPoint = dlf.pointSize(); 680 int fontPoint = dlf.pointSize();
681 if ( maxLen < 2 ) { 681 if ( maxLen < 2 ) {
682 int fontPoint = dlf.pointSize(); 682 int fontPoint = dlf.pointSize();
683 while ( fontPoint > 4 ) { 683 while ( fontPoint > 4 ) {
684 --fontPoint; 684 --fontPoint;
685 dlf.setPointSize( fontPoint ); 685 dlf.setPointSize( fontPoint );
686 QFontMetrics f( dlf ); 686 QFontMetrics f( dlf );
687 wid = f.width( "30" ); 687 wid = f.width( "30" );
688 needWid = wid * selCount; 688 needWid = wid * selCount;
689 if ( needWid < maxWid ) 689 if ( needWid < maxWid )
690 break; 690 break;
691 } 691 }
692 maxLen = 2; 692 maxLen = 2;
693 } 693 }
694 //qDebug("Max len %d ", dayTest.length() ); 694 //qDebug("Max len %d ", dayTest.length() );
695 695
696 QFontMetrics tempF( dlf ); 696 QFontMetrics tempF( dlf );
697 newHight = tempF.height(); 697 newHight = tempF.height();
698 mDayLabels->setFont( dlf ); 698 mDayLabels->setFont( dlf );
699 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; 699 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);;
700 // mLayoutDayLabels->addSpacing(mTimeLabels->width()); 700 // mLayoutDayLabels->addSpacing(mTimeLabels->width());
701 //mLayoutDayLabels->addSpacing( 2 ); 701 //mLayoutDayLabels->addSpacing( 2 );
702 // QFont lFont = dlf; 702 // QFont lFont = dlf;
703 bool appendLabels = false; 703 bool appendLabels = false;
704 KOAgendaButton *dayLabel; 704 KOAgendaButton *dayLabel;
705 dayLabel = mDayLabelsList.first(); 705 dayLabel = mDayLabelsList.first();
706 if ( !dayLabel ) { 706 if ( !dayLabel ) {
707 appendLabels = true; 707 appendLabels = true;
708 dayLabel = getNewDaylabel(); 708 dayLabel = getNewDaylabel();
709 } 709 }
710 dayLabel->setFixedWidth( mTimeLabels->width()+2 ); 710 dayLabel->setFixedWidth( mTimeLabels->width()+2 );
711 dayLabel->setFont( dlf ); 711 dayLabel->setFont( dlf );
712 dayLabel->setNum( -1 ); 712 dayLabel->setNum( -1 );
713 //dayLabel->setAlignment(QLabel::AlignHCenter); 713 //dayLabel->setAlignment(QLabel::AlignHCenter);
714 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); 714 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) );
715 dayLabel->show(); 715 dayLabel->show();
716 DateList::ConstIterator dit; 716 DateList::ConstIterator dit;
717 bool oneday = (mSelectedDates.first() == mSelectedDates.last() ); 717 bool oneday = (mSelectedDates.first() == mSelectedDates.last() );
718 int counter = -1; 718 int counter = -1;
719 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 719 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
720 ++counter; 720 ++counter;
721 QDate date = *dit; 721 QDate date = *dit;
722 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); 722 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels);
723 if ( ! appendLabels ) { 723 if ( ! appendLabels ) {
724 dayLabel = mDayLabelsList.next(); 724 dayLabel = mDayLabelsList.next();
725 if ( !dayLabel ) 725 if ( !dayLabel )
726 appendLabels = true; 726 appendLabels = true;
727 } 727 }
728 if ( appendLabels ) { 728 if ( appendLabels ) {
729 dayLabel = getNewDaylabel(); 729 dayLabel = getNewDaylabel();
730 } 730 }
731 dayLabel->setMinimumWidth( 1 ); 731 dayLabel->setMinimumWidth( 1 );
732 dayLabel->setMaximumWidth( 10240 ); 732 dayLabel->setMaximumWidth( 10240 );
733 dayLabel->setFont( dlf ); 733 dayLabel->setFont( dlf );
734 dayLabel->show(); 734 dayLabel->show();
735 dayLabel->setAutoRepeat( false ); 735 dayLabel->setAutoRepeat( false );
736 dayLabel->setNum( counter ); 736 dayLabel->setNum( counter );
737 QString str; 737 QString str;
738 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date); 738 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date);
739 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true ); 739 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true );
740 switch ( maxLen ) { 740 switch ( maxLen ) {
741 case 2: 741 case 2:
742 str = QString::number( date.day() ); 742 str = QString::number( date.day() );
743 break; 743 break;
744 744
745 case 3: 745 case 3:
746 str = dayName.left( 1 ) +QString::number( date.day()); 746 str = dayName.left( 1 ) +QString::number( date.day());
747 747
748 break; 748 break;
749 case 4: 749 case 4:
750 str = dayName.left( 1 ) + " " +QString::number( date.day()); 750 str = dayName.left( 1 ) + " " +QString::number( date.day());
751 751
752 break; 752 break;
753 case 5: 753 case 5:
754 str = dayName.left( 2 ) + " " +QString::number( date.day()); 754 str = dayName.left( 2 ) + " " +QString::number( date.day());
755 755
756 break; 756 break;
757 case 6: 757 case 6:
758 str = dayName.left( 3 ) + " " +QString::number( date.day()); 758 str = dayName.left( 3 ) + " " +QString::number( date.day());
759 break; 759 break;
760 760
761 default: 761 default:
762 break; 762 break;
763 } 763 }
764 if ( oneday ) { 764 if ( oneday ) {
765 QString addString; 765 QString addString;
766 if ( mSelectedDates.first() == QDateTime::currentDateTime().date() ) 766 if ( mSelectedDates.first() == QDateTime::currentDateTime().date() )
767 addString = i18n("Today"); 767 addString = i18n("Today");
768 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) 768 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) )
769 addString = i18n("Tomorrow"); 769 addString = i18n("Tomorrow");
770 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) 770 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) )
771 addString = i18n("Yesterday"); 771 addString = i18n("Yesterday");
772 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) 772 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) )
773 addString = i18n("Day before yesterday"); 773 addString = i18n("Day before yesterday");
774 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) 774 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) )
775 addString = i18n("Day after tomorrow"); 775 addString = i18n("Day after tomorrow");
776 if ( !addString.isEmpty() ) { 776 if ( !addString.isEmpty() ) {
777 str = addString+", " + str; 777 str = addString+", " + str;
778 } else { 778 } else {
779 str = KGlobal::locale()->formatDate( date, KOPrefs::instance()->mShortDateInViewer); 779 str = KGlobal::locale()->formatDate( date, KOPrefs::instance()->mShortDateInViewer);
780 } 780 }
781 } 781 }
782 dayLabel->setText(str); 782 dayLabel->setText(str);
783 //dayLabel->setAlignment(QLabel::AlignHCenter); 783 //dayLabel->setAlignment(QLabel::AlignHCenter);
784 if (date == QDate::currentDate()) { 784 if (date == QDate::currentDate()) {
785 QFont bFont = dlf; 785 QFont bFont = dlf;
786 bFont.setBold( true ); 786 bFont.setBold( true );
787 dayLabel->setFont(bFont); 787 dayLabel->setFont(bFont);
788 } 788 }
789 //dayLayout->addWidget(dayLabel); 789 //dayLayout->addWidget(dayLabel);
790 790
791#ifndef KORG_NOPLUGINS 791#ifndef KORG_NOPLUGINS
792 CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); 792 CalendarDecoration::List cds = KOCore::self()->calendarDecorations();
793 CalendarDecoration *it; 793 CalendarDecoration *it;
794 for(it = cds.first(); it; it = cds.next()) { 794 for(it = cds.first(); it; it = cds.next()) {
795 QString text = it->shortText( date ); 795 QString text = it->shortText( date );
796 if ( !text.isEmpty() ) { 796 if ( !text.isEmpty() ) {
797 QLabel *label = new QLabel(text,mDayLabels); 797 QLabel *label = new QLabel(text,mDayLabels);
798 label->setAlignment(AlignCenter); 798 label->setAlignment(AlignCenter);
799 dayLayout->addWidget(label); 799 dayLayout->addWidget(label);
800 } 800 }
801 } 801 }
802 802
803 for(it = cds.first(); it; it = cds.next()) { 803 for(it = cds.first(); it; it = cds.next()) {
804 QWidget *wid = it->smallWidget(mDayLabels,date); 804 QWidget *wid = it->smallWidget(mDayLabels,date);
805 if ( wid ) { 805 if ( wid ) {
806 // wid->setHeight(20); 806 // wid->setHeight(20);
807 dayLayout->addWidget(wid); 807 dayLayout->addWidget(wid);
808 } 808 }
809 } 809 }
810#endif 810#endif
811 } 811 }
812 if ( ! appendLabels ) { 812 if ( ! appendLabels ) {
813 dayLabel = mDayLabelsList.next(); 813 dayLabel = mDayLabelsList.next();
814 if ( !dayLabel ) 814 if ( !dayLabel )
815 appendLabels = true; 815 appendLabels = true;
816 } 816 }
817 if ( appendLabels ) { 817 if ( appendLabels ) {
818 dayLabel = getNewDaylabel(); 818 dayLabel = getNewDaylabel();
819 } 819 }
820 //dayLabel->hide();//test only 820 //dayLabel->hide();//test only
821 821
822 int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()-3 ) % mSelectedDates.count() ; 822 int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()-3 ) % mSelectedDates.count() ;
823 if ( offset < 0 ) offset = 0; 823 if ( offset < 0 ) offset = 0;
824 //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 ); 824 //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 );
825 dayLabel->setText(">");//QString::number ( mSelectedDates.first().month() ) ); 825 dayLabel->setText(">");//QString::number ( mSelectedDates.first().month() ) );
826 dayLabel->setFont( dlf ); 826 dayLabel->setFont( dlf );
827 dayLabel->setAutoRepeat( true ); 827 dayLabel->setAutoRepeat( true );
828 dayLabel->show(); 828 dayLabel->show();
829 dayLabel->setNum( -2 ); 829 dayLabel->setNum( -2 );
830 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset ); 830 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset );
831 //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2); 831 //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2);
832 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); 832 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2);
833 if ( !appendLabels ) { 833 if ( !appendLabels ) {
834 dayLabel = mDayLabelsList.next(); 834 dayLabel = mDayLabelsList.next();
835 while ( dayLabel ) { 835 while ( dayLabel ) {
836 //qDebug("!dayLabel %d",dayLabel ); 836 //qDebug("!dayLabel %d",dayLabel );
837 dayLabel->hide(); 837 dayLabel->hide();
838 dayLabel = mDayLabelsList.next(); 838 dayLabel = mDayLabelsList.next();
839 } 839 }
840 } 840 }
841 841
842 mDayLabelsFrame->setFixedHeight( newHight + 4 ); 842 mDayLabelsFrame->setFixedHeight( newHight + 4 );
843} 843}
844 844
845int KOAgendaView::maxDatesHint() 845int KOAgendaView::maxDatesHint()
846{ 846{
847 // Not sure about the max number of events, so return 0 for now. 847 // Not sure about the max number of events, so return 0 for now.
848 return 0; 848 return 0;
849} 849}
850 850
851int KOAgendaView::currentDateCount() 851int KOAgendaView::currentDateCount()
852{ 852{
853 return mSelectedDates.count(); 853 return mSelectedDates.count();
854} 854}
855 855
856QPtrList<Incidence> KOAgendaView::selectedIncidences() 856QPtrList<Incidence> KOAgendaView::selectedIncidences()
857{ 857{
858 QPtrList<Incidence> selected; 858 QPtrList<Incidence> selected;
859 Incidence *incidence; 859 Incidence *incidence;
860 860
861 incidence = mAgenda->selectedIncidence(); 861 incidence = mAgenda->selectedIncidence();
862 if (incidence) selected.append(incidence); 862 if (incidence) selected.append(incidence);
863 863
864 incidence = mAllDayAgenda->selectedIncidence(); 864 incidence = mAllDayAgenda->selectedIncidence();
865 if (incidence) selected.append(incidence); 865 if (incidence) selected.append(incidence);
866 866
867 return selected; 867 return selected;
868} 868}
869 869
870DateList KOAgendaView::selectedDates() 870DateList KOAgendaView::selectedDates()
871{ 871{
872 DateList selected; 872 DateList selected;
873 QDate qd; 873 QDate qd;
874 874
875 qd = mAgenda->selectedIncidenceDate(); 875 qd = mAgenda->selectedIncidenceDate();
876 if (qd.isValid()) selected.append(qd); 876 if (qd.isValid()) selected.append(qd);
877 877
878 qd = mAllDayAgenda->selectedIncidenceDate(); 878 qd = mAllDayAgenda->selectedIncidenceDate();
879 if (qd.isValid()) selected.append(qd); 879 if (qd.isValid()) selected.append(qd);
880 880
881 return selected; 881 return selected;
882} 882}
883 883
884 884
885void KOAgendaView::updateView() 885void KOAgendaView::updateView()
886{ 886{
887 if ( mBlockUpdating ) 887 if ( mBlockUpdating )
888 return; 888 return;
889 // kdDebug() << "KOAgendaView::updateView()" << endl; 889 // kdDebug() << "KOAgendaView::updateView()" << endl;
890 fillAgenda(); 890 fillAgenda();
891 891
892} 892}
893 893
894 894
895/* 895/*
896 Update configuration settings for the agenda view. This method is not 896 Update configuration settings for the agenda view. This method is not
897 complete. 897 complete.
898*/ 898*/
899void KOAgendaView::updateConfig() 899void KOAgendaView::updateConfig()
900{ 900{
901 if ( mBlockUpdating ) 901 if ( mBlockUpdating )
902 return; 902 return;
903 if ( mAgenda->height() > 96 * KOPrefs::instance()->mHourSize ) { 903 if ( mAgenda->height() > 96 * KOPrefs::instance()->mHourSize ) {
904 int old = KOPrefs::instance()->mHourSize; 904 int old = KOPrefs::instance()->mHourSize;
905 KOPrefs::instance()->mHourSize = mAgenda->height()/96 +1; 905 KOPrefs::instance()->mHourSize = mAgenda->height()/96 +1;
906 qDebug("KOPrefs::instance()->mHourSize adjusted %d to %d ", old,KOPrefs::instance()->mHourSize ); 906 qDebug("KOPrefs::instance()->mHourSize adjusted %d to %d ", old,KOPrefs::instance()->mHourSize );
907 } 907 }
908 908
909 909
910 // update config for children 910 // update config for children
911 mTimeLabels->updateConfig(); 911 mTimeLabels->updateConfig();
912 mAgenda->storePosition(); 912 mAgenda->storePosition();
913 mAgenda->updateConfig(); 913 mAgenda->updateConfig();
914 mAllDayAgenda->updateConfig(); 914 mAllDayAgenda->updateConfig();
915 // widget synchronization 915 // widget synchronization
916 //TODO: find a better way, maybe signal/slot 916 //TODO: find a better way, maybe signal/slot
917 mTimeLabels->positionChanged(); 917 mTimeLabels->positionChanged();
918 918
919 // for some reason, this needs to be called explicitly 919 // for some reason, this needs to be called explicitly
920 mTimeLabels->repaint(); 920 mTimeLabels->repaint();
921 921
922 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 922 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
923 923
924 // ToolTips displaying summary of events 924 // ToolTips displaying summary of events
925 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance() 925 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance()
926 ->mEnableToolTips); 926 ->mEnableToolTips);
927 927
928 //setHolidayMasks(); 928 //setHolidayMasks();
929 929
930 //createDayLabels(); called by via updateView(); 930 //createDayLabels(); called by via updateView();
931 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth()); 931 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth());
932 updateView(); 932 updateView();
933 mAgenda->restorePosition(); 933 mAgenda->restorePosition();
934} 934}
935 935
936 936
937void KOAgendaView::updateEventDates(KOAgendaItem *item, int type) 937void KOAgendaView::updateEventDates(KOAgendaItem *item, int type)
938{ 938{
939 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl; 939 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl;
940 //qDebug("KOAgendaView::updateEventDates "); 940 //qDebug("KOAgendaView::updateEventDates ");
941 QDateTime startDt,endDt; 941 QDateTime startDt,endDt;
942 QDate startDate; 942 QDate startDate;
943 int lenInSecs; 943 int lenInSecs;
944 // if ( type == KOAgenda::RESIZETOP ) 944 // if ( type == KOAgenda::RESIZETOP )
945 // qDebug("RESIZETOP "); 945 // qDebug("RESIZETOP ");
946 // if ( type == KOAgenda::RESIZEBOTTOM ) 946 // if ( type == KOAgenda::RESIZEBOTTOM )
947 // qDebug("RESIZEBOTTOM "); 947 // qDebug("RESIZEBOTTOM ");
948 // if ( type == KOAgenda::MOVE ) 948 // if ( type == KOAgenda::MOVE )
949 // qDebug("MOVE "); 949 // qDebug("MOVE ");
950 if ( item->incidence()->type() == "Event" ) { 950 if ( item->incidence()->type() == "Event" ) {
951 startDt =item->incidence()->dtStart(); 951 startDt =item->incidence()->dtStart();
952 endDt = item->incidence()->dtEnd(); 952 endDt = item->incidence()->dtEnd();
953 lenInSecs = startDt.secsTo( endDt ); 953 lenInSecs = startDt.secsTo( endDt );
954 } 954 }
955 955
956 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED ); 956 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED );
957 957
958 if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) { 958 if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) {
959 startDate = mSelectedDates[item->mLastMoveXPos]; 959 startDate = mSelectedDates[item->mLastMoveXPos];
960 } else { 960 } else {
961 if (item->cellX() < 0) { 961 if (item->cellX() < 0) {
962 startDate = (mSelectedDates.first()).addDays(item->cellX()); 962 startDate = (mSelectedDates.first()).addDays(item->cellX());
963 } else { 963 } else {
964 startDate = mSelectedDates[item->cellX()]; 964 startDate = mSelectedDates[item->cellX()];
965 } 965 }
966 } 966 }
967 startDt.setDate(startDate); 967 startDt.setDate(startDate);
968 968
969 if (item->incidence()->doesFloat()) { 969 if (item->incidence()->doesFloat()) {
970 endDt.setDate(startDate.addDays(item->cellWidth() - 1)); 970 endDt.setDate(startDate.addDays(item->cellWidth() - 1));
971 } else { 971 } else {
972 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE ) 972 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE )
973 startDt.setTime(mAgenda->gyToTime(item->cellYTop())); 973 startDt.setTime(mAgenda->gyToTime(item->cellYTop()));
974 if ( item->incidence()->type() == "Event" ) { 974 if ( item->incidence()->type() == "Event" ) {
975 if ( type == KOAgenda::MOVE ) { 975 if ( type == KOAgenda::MOVE ) {
976 endDt = startDt.addSecs(lenInSecs); 976 endDt = startDt.addSecs(lenInSecs);
977 977
978 } else if ( type == KOAgenda::RESIZEBOTTOM ) { 978 } else if ( type == KOAgenda::RESIZEBOTTOM ) {
979 if (item->lastMultiItem()) { 979 if (item->lastMultiItem()) {
980 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 980 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
981 endDt.setDate(startDate. 981 endDt.setDate(startDate.
982 addDays(item->lastMultiItem()->cellX() - item->cellX())); 982 addDays(item->lastMultiItem()->cellX() - item->cellX()));
983 } else { 983 } else {
984 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 984 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
985 endDt.setDate(startDate); 985 endDt.setDate(startDate);
986 } 986 }
987 } 987 }
988 } else { 988 } else {
989 // todo 989 // todo
990 if (item->lastMultiItem()) { 990 if (item->lastMultiItem()) {
991 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 991 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
992 endDt.setDate(startDate. 992 endDt.setDate(startDate.
993 addDays(item->lastMultiItem()->cellX() - item->cellX())); 993 addDays(item->lastMultiItem()->cellX() - item->cellX()));
994 } else { 994 } else {
995 //qDebug("tem->cellYBottom() %d",item->cellYBottom() ); 995 //qDebug("tem->cellYBottom() %d",item->cellYBottom() );
996 if ( item->cellYBottom() > 0 ) 996 if ( item->cellYBottom() > 0 )
997 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 997 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
998 else 998 else
999 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time()); 999 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time());
1000 endDt.setDate(startDate); 1000 endDt.setDate(startDate);
1001 } 1001 }
1002 } 1002 }
1003 } 1003 }
1004 if ( item->incidence()->type() == "Event" ) { 1004 if ( item->incidence()->type() == "Event" ) {
1005 item->incidence()->setDtStart(startDt); 1005 item->incidence()->setDtStart(startDt);
1006 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt); 1006 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt);
1007 } else if ( item->incidence()->type() == "Todo" ) { 1007 } else if ( item->incidence()->type() == "Todo" ) {
1008 Todo* to = static_cast<Todo*>(item->incidence()); 1008 Todo* to = static_cast<Todo*>(item->incidence());
1009 1009
1010 to->setDtDue(endDt); 1010 to->setDtDue(endDt);
1011 if ( to->hasStartDate() ) { 1011 if ( to->hasStartDate() ) {
1012 if (to->dtStart() >= to->dtDue() ) 1012 if (to->dtStart() >= to->dtDue() )
1013 to->setDtStart(to->dtDue().addDays( -2 )); 1013 to->setDtStart(to->dtDue().addDays( -2 ));
1014 } 1014 }
1015 1015
1016 } 1016 }
1017 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() ); 1017 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() );
1018 item->incidence()->setRevision(item->incidence()->revision()+1); 1018 item->incidence()->setRevision(item->incidence()->revision()+1);
1019 item->setItemDate(startDt.date()); 1019 item->setItemDate(startDt.date());
1020 //item->updateItem(); 1020 //item->updateItem();
1021 if ( item->incidence()->type() == "Todo" ) { 1021 if ( item->incidence()->type() == "Todo" ) {
1022 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED ); 1022 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED );
1023 1023
1024 } 1024 }
1025 else 1025 else
1026 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED); 1026 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED);
1027 item->updateItem(); 1027 item->updateItem();
1028} 1028}
1029 1029
1030void KOAgendaView::showDates( const QDate &start, const QDate &end ) 1030void KOAgendaView::showDates( const QDate &start, const QDate &end )
1031{ 1031{
1032 // kdDebug() << "KOAgendaView::selectDates" << endl; 1032 // kdDebug() << "KOAgendaView::selectDates" << endl;
1033 1033
1034 mSelectedDates.clear(); 1034 mSelectedDates.clear();
1035 // qDebug("KOAgendaView::showDates "); 1035 // qDebug("KOAgendaView::showDates ");
1036 QDate d = start; 1036 QDate d = start;
1037 while (d <= end) { 1037 while (d <= end) {
1038 mSelectedDates.append(d); 1038 mSelectedDates.append(d);
1039 d = d.addDays( 1 ); 1039 d = d.addDays( 1 );
1040 } 1040 }
1041 1041
1042 // and update the view 1042 // and update the view
1043 fillAgenda(); 1043 fillAgenda();
1044} 1044}
1045 1045
1046 1046
1047void KOAgendaView::showEvents(QPtrList<Event>) 1047void KOAgendaView::showEvents(QPtrList<Event>)
1048{ 1048{
1049 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl; 1049 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl;
1050} 1050}
1051 1051
1052void KOAgendaView::changeEventDisplay(Event *, int) 1052void KOAgendaView::changeEventDisplay(Event *, int)
1053{ 1053{
1054 // qDebug("KOAgendaView::changeEventDisplay "); 1054 // qDebug("KOAgendaView::changeEventDisplay ");
1055 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl; 1055 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl;
1056 // this should be re-written to be MUCH smarter. Right now we 1056 // this should be re-written to be MUCH smarter. Right now we
1057 // are just playing dumb. 1057 // are just playing dumb.
1058 fillAgenda(); 1058 fillAgenda();
1059} 1059}
1060 1060
1061void KOAgendaView::fillAgenda(const QDate &) 1061void KOAgendaView::fillAgenda(const QDate &)
1062{ 1062{
1063 // qDebug("KOAgendaView::fillAgenda "); 1063 // qDebug("KOAgendaView::fillAgenda ");
1064 fillAgenda(); 1064 fillAgenda();
1065} 1065}
1066 1066
1067void KOAgendaView::fillAgenda() 1067void KOAgendaView::fillAgenda()
1068{ 1068{
1069 if ( globalFlagBlockStartup ) 1069 if ( globalFlagBlockStartup )
1070 return; 1070 return;
1071 if ( globalFlagBlockAgenda == 1 ) 1071 if ( globalFlagBlockAgenda == 1 )
1072 return; 1072 return;
1073 static bool onlyOne = false; 1073 static bool onlyOne = false;
1074 if ( onlyOne ) 1074 if ( onlyOne )
1075 return; 1075 return;
1076 onlyOne = true; 1076 onlyOne = true;
1077 //if ( globalFlagBlockAgenda == 2 ) 1077 //if ( globalFlagBlockAgenda == 2 )
1078 //globalFlagBlockAgenda = 0; 1078 //globalFlagBlockAgenda = 0;
1079 // globalFlagBlockPainting = false; 1079 // globalFlagBlockPainting = false;
1080 if ( globalFlagBlockAgenda == 0 ) 1080 if ( globalFlagBlockAgenda == 0 )
1081 globalFlagBlockAgenda = 1; 1081 globalFlagBlockAgenda = 1;
1082 // clearView(); 1082 // clearView();
1083 //qDebug("fillAgenda()++++ "); 1083 //qDebug("fillAgenda()++++ ");
1084 globalFlagBlockAgendaItemPaint = 1; 1084 globalFlagBlockAgendaItemPaint = 1;
1085 1085
1086 mAllDayAgenda->changeColumns(mSelectedDates.count()); 1086 mAllDayAgenda->changeColumns(mSelectedDates.count());
1087 mAgenda->changeColumns(mSelectedDates.count()); 1087 mAgenda->changeColumns(mSelectedDates.count());
1088 qApp->processEvents(); 1088 qApp->processEvents();
1089 mEventIndicatorTop->changeColumns(mSelectedDates.count()); 1089 mEventIndicatorTop->changeColumns(mSelectedDates.count());
1090 mEventIndicatorBottom->changeColumns(mSelectedDates.count()); 1090 mEventIndicatorBottom->changeColumns(mSelectedDates.count());
1091 setHolidayMasks(); 1091 setHolidayMasks();
1092 1092
1093 //mAgenda->hideUnused(); 1093 //mAgenda->hideUnused();
1094 //mAllDayAgenda->hideUnused(); 1094 //mAllDayAgenda->hideUnused();
1095 1095
1096 // mAgenda->blockNextRepaint( false ); 1096 // mAgenda->blockNextRepaint( false );
1097 // mAgenda->viewport()->repaint(); 1097 // mAgenda->viewport()->repaint();
1098 // mAgenda->blockNextRepaint( true ); 1098 // mAgenda->blockNextRepaint( true );
1099 mMinY.resize(mSelectedDates.count()); 1099 mMinY.resize(mSelectedDates.count());
1100 mMaxY.resize(mSelectedDates.count()); 1100 mMaxY.resize(mSelectedDates.count());
1101 1101
1102 QPtrList<Event> dayEvents; 1102 QPtrList<Event> dayEvents;
1103 1103
1104 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 1104 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
1105 // Therefore, gtodoset all of them. 1105 // Therefore, gtodoset all of them.
1106 QPtrList<Todo> todos = calendar()->todos(); 1106 QPtrList<Todo> todos = calendar()->todos();
1107 1107
1108 mAgenda->setDateList(mSelectedDates); 1108 mAgenda->setDateList(mSelectedDates);
1109 1109
1110 QDate today = QDate::currentDate(); 1110 QDate today = QDate::currentDate();
1111 1111
1112 DateList::ConstIterator dit; 1112 DateList::ConstIterator dit;
1113 int curCol = 0; 1113 int curCol = 0;
1114 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 1114 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
1115 QDate currentDate = *dit; 1115 QDate currentDate = *dit;
1116 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString() 1116 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString()
1117 // << endl; 1117 // << endl;
1118 1118
1119 dayEvents = calendar()->events(currentDate,true); 1119 dayEvents = calendar()->events(currentDate,true);
1120 1120
1121 // Default values, which can never be reached 1121 // Default values, which can never be reached
1122 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1; 1122 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1;
1123 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1; 1123 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1;
1124 1124
1125 unsigned int numEvent; 1125 unsigned int numEvent;
1126 for(numEvent=0;numEvent<dayEvents.count();++numEvent) { 1126 for(numEvent=0;numEvent<dayEvents.count();++numEvent) {
1127 Event *event = dayEvents.at(numEvent); 1127 Event *event = dayEvents.at(numEvent);
1128 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") ) 1128 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") )
1129 if ( event->uid().left(15) == QString("last-syncEvent-") ) 1129 if ( event->uid().left(15) == QString("last-syncEvent-") )
1130 continue; 1130 continue;
1131 // kdDebug() << " Event: " << event->summary() << endl; 1131 // kdDebug() << " Event: " << event->summary() << endl;
1132 1132
1133 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol; 1133 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol;
1134 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol; 1134 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol;
1135 1135
1136 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl; 1136 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl;
1137 1137
1138 if (event->doesFloat()) { 1138 if (event->doesFloat()) {
1139 if (event->recurrence()->doesRecur()) { 1139 if (event->recurrence()->doesRecur()) {
1140 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol); 1140 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol);
1141 } else { 1141 } else {
1142 if (beginX <= 0 && curCol == 0) { 1142 if (beginX <= 0 && curCol == 0) {
1143 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1143 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1144 } else if (beginX == curCol) { 1144 } else if (beginX == curCol) {
1145 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1145 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1146 } 1146 }
1147 } 1147 }
1148 } else if (event->isMultiDay()) { 1148 } else if (event->isMultiDay()) {
1149 if ( event->doesRecur () ) { 1149 if ( event->doesRecur () ) {
1150 QDate dateit = currentDate; 1150 QDate dateit = currentDate;
1151 int count = 0; 1151 int count = 0;
1152 int max = event->dtStart().daysTo( event->dtEnd() ) +2; 1152 int max = event->dtStart().daysTo( event->dtEnd() ) +2;
1153 while (! event->recursOn( dateit ) && count <= max ) { 1153 while (! event->recursOn( dateit ) && count <= max ) {
1154 ++count; 1154 ++count;
1155 dateit = dateit.addDays( -1 ); 1155 dateit = dateit.addDays( -1 );
1156 } 1156 }
1157 bool ok; 1157 bool ok;
1158 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok ); 1158 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok );
1159 if ( ok ) 1159 if ( ok )
1160 { 1160 {
1161 int secs = event->dtStart().secsTo( event->dtEnd() ); 1161 int secs = event->dtStart().secsTo( event->dtEnd() );
1162 QDateTime nextOcend =nextOcstart.addSecs( secs ); ; 1162 QDateTime nextOcend =nextOcstart.addSecs( secs ); ;
1163 beginX = currentDate.daysTo(nextOcstart.date()) + curCol; 1163 beginX = currentDate.daysTo(nextOcstart.date()) + curCol;
1164 endX = currentDate.daysTo(nextOcend.date()) + curCol; 1164 endX = currentDate.daysTo(nextOcend.date()) + curCol;
1165 1165
1166 } 1166 }
1167 } 1167 }
1168 int startY = mAgenda->timeToY(event->dtStart().time()); 1168 int startY = mAgenda->timeToY(event->dtStart().time());
1169 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1169 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1170 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol ); 1170 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol );
1171 if ((beginX <= 0 && curCol == 0) || beginX == curCol) { 1171 if ((beginX <= 0 && curCol == 0) || beginX == curCol) {
1172 //qDebug("insert!!! "); 1172 //qDebug("insert!!! ");
1173 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY); 1173 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY);
1174 } 1174 }
1175 if (beginX == curCol) { 1175 if (beginX == curCol) {
1176 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1176 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1177 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1177 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1178 } else if (endX == curCol) { 1178 } else if (endX == curCol) {
1179 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1179 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1180 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1180 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1181 } else { 1181 } else {
1182 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1182 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1183 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1183 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1184 } 1184 }
1185 } else { 1185 } else {
1186 int startY = mAgenda->timeToY(event->dtStart().time()); 1186 int startY = mAgenda->timeToY(event->dtStart().time());
1187 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1187 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1188 if (endY < startY) endY = startY; 1188 if (endY < startY) endY = startY;
1189 mAgenda->insertItem(event,currentDate,curCol,startY,endY); 1189 mAgenda->insertItem(event,currentDate,curCol,startY,endY);
1190 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1190 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1191 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1191 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1192 } 1192 }
1193 } 1193 }
1194 // ---------- [display Todos -------------- 1194 // ---------- [display Todos --------------
1195 unsigned int numTodo; 1195 unsigned int numTodo;
1196 for (numTodo = 0; numTodo < todos.count(); ++numTodo) { 1196 for (numTodo = 0; numTodo < todos.count(); ++numTodo) {
1197 Todo *todo = todos.at(numTodo); 1197 Todo *todo = todos.at(numTodo);
1198 1198
1199 if ( ! todo->hasDueDate() && !todo->hasCompletedDate()) continue; // todo shall not be displayed if it has no date 1199 if ( ! todo->hasDueDate() && !todo->hasCompletedDate()) continue; // todo shall not be displayed if it has no date
1200 1200
1201 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 1201 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
1202 // Already completed items can be displayed on their original due date 1202 // Already completed items can be displayed on their original due date
1203 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda 1203 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda
1204 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda; 1204 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda;
1205 bool fillIn = false; 1205 bool fillIn = false;
1206 if ( todo->hasCompletedDate() && todo->completed().date() == currentDate ) 1206 if ( todo->hasCompletedDate() && todo->completed().date() == currentDate )
1207 fillIn = true; 1207 fillIn = true;
1208 if ( ! fillIn && !todo->hasCompletedDate() ) 1208 if ( ! fillIn && !todo->hasCompletedDate() )
1209 fillIn = ((todo->dtDue().date() == currentDate) && !overdue) || ((currentDate == today) && overdue); 1209 fillIn = ((todo->dtDue().date() == currentDate) && !overdue) || ((currentDate == today) && overdue);
1210 if ( fillIn ) { 1210 if ( fillIn ) {
1211 if ( (todo->doesFloat() || overdue ) && !todo->hasCompletedDate() ) { // Todo has no due-time set or is already overdue 1211 if ( (todo->doesFloat() || overdue ) && !todo->hasCompletedDate() ) { // Todo has no due-time set or is already overdue
1212 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1212 if ( KOPrefs::instance()->mShowTodoInAgenda )
1213 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol); 1213 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol);
1214 } 1214 }
1215 else { 1215 else {
1216 QDateTime dt; 1216 QDateTime dt;
1217 if ( todo->hasCompletedDate() ) 1217 if ( todo->hasCompletedDate() )
1218 dt = todo->completed(); 1218 dt = todo->completed();
1219 else 1219 else
1220 dt = todo->dtDue();; 1220 dt = todo->dtDue();;
1221 1221
1222 1222
1223 int endY = mAgenda->timeToY(dt.time()) - 1; 1223 int endY = mAgenda->timeToY(dt.time()) - 1;
1224 int hi = (18/KOPrefs::instance()->mHourSize); 1224 int hi = (18/KOPrefs::instance()->mHourSize);
1225 //qDebug("hei %d ",KOPrefs::instance()->mHourSize); 1225 //qDebug("hei %d ",KOPrefs::instance()->mHourSize);
1226 int startY = endY -hi; 1226 int startY = endY -hi;
1227 1227
1228 mAgenda->insertItem(todo,currentDate,curCol,startY,endY); 1228 mAgenda->insertItem(todo,currentDate,curCol,startY,endY);
1229 1229
1230 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1230 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1231 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1231 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1232 } 1232 }
1233 } 1233 }
1234 } 1234 }
1235 // ---------- display Todos] -------------- 1235 // ---------- display Todos] --------------
1236 1236
1237 ++curCol; 1237 ++curCol;
1238 } 1238 }
1239 mAgenda->hideUnused(); 1239 mAgenda->hideUnused();
1240 mAllDayAgenda->hideUnused(); 1240 mAllDayAgenda->hideUnused();
1241 mAgenda->checkScrollBoundaries(); 1241 mAgenda->checkScrollBoundaries();
1242 1242
1243 deleteSelectedDateTime(); 1243 deleteSelectedDateTime();
1244 1244
1245 createDayLabels(); 1245 createDayLabels();
1246 emit incidenceSelected( 0 ); 1246 emit incidenceSelected( 0 );
1247 1247
1248 if ( globalFlagBlockAgenda == 2 ) { 1248 if ( globalFlagBlockAgenda == 2 ) {
1249 if ( KOPrefs::instance()->mSetTimeToDayStartAt ) 1249 if ( KOPrefs::instance()->mSetTimeToDayStartAt )
1250 setStartHour( KOPrefs::instance()->mDayBegins ); 1250 setStartHour( KOPrefs::instance()->mDayBegins );
1251 else if ( KOPrefs::instance()->mCenterOnCurrentTime ) 1251 else if ( KOPrefs::instance()->mCenterOnCurrentTime )
1252 setStartHour( QTime::currentTime ().hour() ); 1252 setStartHour( QTime::currentTime ().hour() );
1253 // qApp->processEvents(); 1253 // qApp->processEvents();
1254 } 1254 }
1255 qApp->processEvents(); 1255 qApp->processEvents();
1256 //qDebug("qApp->processEvents(); END "); 1256 //qDebug("qApp->processEvents(); END ");
1257 globalFlagBlockAgenda = 0; 1257 globalFlagBlockAgenda = 0;
1258 1258
1259 // mAgenda->hideUnused(); 1259 // mAgenda->hideUnused();
1260 //mAllDayAgenda->hideUnused(); 1260 //mAllDayAgenda->hideUnused();
1261 mAllDayAgenda->drawContentsToPainter(); 1261 mAllDayAgenda->drawContentsToPainter();
1262 mAgenda->drawContentsToPainter(); 1262 mAgenda->drawContentsToPainter();
1263 repaintAgenda(); 1263 repaintAgenda();
1264 onlyOne = false; 1264 onlyOne = false;
1265 // mAgenda->finishUpdate(); 1265 // mAgenda->finishUpdate();
1266 //mAllDayAgenda->finishUpdate(); 1266 //mAllDayAgenda->finishUpdate();
1267 1267
1268 // repaintAgenda(); 1268 // repaintAgenda();
1269 //qApp->processEvents(); 1269 //qApp->processEvents();
1270 // globalFlagBlockAgenda = 0; 1270 // globalFlagBlockAgenda = 0;
1271} 1271}
1272void KOAgendaView::repaintAgenda() 1272void KOAgendaView::repaintAgenda()
1273{ 1273{
1274 // mAllDayAgenda->drawContentsToPainter(); 1274 // mAllDayAgenda->drawContentsToPainter();
1275// mAllDayAgenda->viewport()->repaint( false ); 1275// mAllDayAgenda->viewport()->repaint( false );
1276// mAgenda->drawContentsToPainter(); 1276// mAgenda->drawContentsToPainter();
1277// mAgenda->viewport()->repaint( false ); 1277// mAgenda->viewport()->repaint( false );
1278// qApp->processEvents(); 1278// qApp->processEvents();
1279 1279
1280 //qDebug("KOAgendaView::repaintAgenda() "); 1280 //qDebug("KOAgendaView::repaintAgenda() ");
1281 //qApp->processEvents(); 1281 //qApp->processEvents();
1282 mAgenda->viewport()->repaint( false ); 1282 mAgenda->viewport()->repaint( false );
1283 mAllDayAgenda->viewport()->repaint( false ); 1283 mAllDayAgenda->viewport()->repaint( false );
1284 mAgenda->finishUpdate(); 1284 mAgenda->finishUpdate();
1285 mAllDayAgenda->finishUpdate(); 1285 mAllDayAgenda->finishUpdate();
1286} 1286}
1287 1287
1288 1288
1289void KOAgendaView::clearView() 1289void KOAgendaView::clearView()
1290{ 1290{
1291 // kdDebug() << "ClearView" << endl; 1291 // kdDebug() << "ClearView" << endl;
1292 mAllDayAgenda->clear(); 1292 mAllDayAgenda->clear();
1293 mAgenda->clear(); 1293 mAgenda->clear();
1294} 1294}
1295 1295
1296void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1296void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1297 const QDate &td) 1297 const QDate &td)
1298{ 1298{
1299#ifndef KORG_NOPRINTER 1299#ifndef KORG_NOPRINTER
1300 if (fd == td) 1300 if (fd == td)
1301 calPrinter->preview(CalPrinter::Day, fd, td); 1301 calPrinter->preview(CalPrinter::Day, fd, td);
1302 else 1302 else
1303 calPrinter->preview(CalPrinter::Week, fd, td); 1303 calPrinter->preview(CalPrinter::Week, fd, td);
1304#endif 1304#endif
1305} 1305}
1306 1306
1307// void KOAgendaView::updateMovedTodo() 1307// void KOAgendaView::updateMovedTodo()
1308// { 1308// {
1309// // updateConfig(); 1309// // updateConfig();
1310// // emit updateTodoViews(); 1310// // emit updateTodoViews();
1311// } 1311// }
1312 1312
1313void KOAgendaView::slotShowDateView( int mode , int d )
1314{
1315 if ( d >= mSelectedDates.count() ) {
1316 qDebug("KOAgendaView::slotShowDateView datecounterror %d d ", d, mSelectedDates.count() );
1317
1318 } else {
1319 QDate day = mSelectedDates[d];
1320 emit showDateView(mode , day );
1321 }
1322
1323}
1313void KOAgendaView::newEvent(int gx, int gy) 1324void KOAgendaView::newEvent(int gx, int gy)
1314{ 1325{
1315 if (!mSelectedDates.count()) return; 1326 if (!mSelectedDates.count()) return;
1316 1327
1317 QDate day = mSelectedDates[gx]; 1328 QDate day = mSelectedDates[gx];
1318 1329
1319 QTime time = mAgenda->gyToTime(gy); 1330 QTime time = mAgenda->gyToTime(gy);
1320 QDateTime dt(day,time); 1331 QDateTime dt(day,time);
1321 // if ( dt < QDateTime::currentDateTime () ) 1332 // if ( dt < QDateTime::currentDateTime () )
1322 // dt = QDateTime::currentDateTime ().addSecs( 3600 ); 1333 // dt = QDateTime::currentDateTime ().addSecs( 3600 );
1323 emit newEventSignal(dt); 1334 emit newEventSignal(dt);
1324} 1335}
1325 1336
1326void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd) 1337void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd)
1327{ 1338{
1328 if (!mSelectedDates.count()) return; 1339 if (!mSelectedDates.count()) return;
1329 1340
1330 QDate dayStart = mSelectedDates[gxStart]; 1341 QDate dayStart = mSelectedDates[gxStart];
1331 QDate dayEnd = mSelectedDates[gxEnd]; 1342 QDate dayEnd = mSelectedDates[gxEnd];
1332 1343
1333 QTime timeStart = mAgenda->gyToTime(gyStart); 1344 QTime timeStart = mAgenda->gyToTime(gyStart);
1334 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1345 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1335 1346
1336 QDateTime dtStart(dayStart,timeStart); 1347 QDateTime dtStart(dayStart,timeStart);
1337 QDateTime dtEnd(dayEnd,timeEnd); 1348 QDateTime dtEnd(dayEnd,timeEnd);
1338 1349
1339 emit newEventSignal(dtStart,dtEnd); 1350 emit newEventSignal(dtStart,dtEnd);
1340} 1351}
1341 1352
1342void KOAgendaView::newEventAllDay(int gx, int ) 1353void KOAgendaView::newEventAllDay(int gx, int )
1343{ 1354{
1344 if (!mSelectedDates.count()) return; 1355 if (!mSelectedDates.count()) return;
1345 1356
1346 QDate day = mSelectedDates[gx]; 1357 QDate day = mSelectedDates[gx];
1347 1358
1348 emit newEventSignal(day); 1359 emit newEventSignal(day);
1349} 1360}
1350void KOAgendaView::newTodoAllDay(int gx, int ) 1361void KOAgendaView::newTodoAllDay(int gx, int )
1351{ 1362{
1352 if (!mSelectedDates.count()) return; 1363 if (!mSelectedDates.count()) return;
1353 1364
1354 QDateTime day (mSelectedDates[gx] ); 1365 QDateTime day (mSelectedDates[gx] );
1355 emit newTodoSignal(day, true); 1366 emit newTodoSignal(day, true);
1356} 1367}
1357void KOAgendaView::newTodo(int gx, int gy ) 1368void KOAgendaView::newTodo(int gx, int gy )
1358{ 1369{
1359 if (!mSelectedDates.count()) return; 1370 if (!mSelectedDates.count()) return;
1360 QDate dayStart = mSelectedDates[gx]; 1371 QDate dayStart = mSelectedDates[gx];
1361 QTime timeStart = mAgenda->gyToTime(gy); 1372 QTime timeStart = mAgenda->gyToTime(gy);
1362 QDateTime dt (dayStart,timeStart); 1373 QDateTime dt (dayStart,timeStart);
1363 emit newTodoSignal( dt, false ); 1374 emit newTodoSignal( dt, false );
1364} 1375}
1365 1376
1366void KOAgendaView::updateEventIndicatorTop(int newY) 1377void KOAgendaView::updateEventIndicatorTop(int newY)
1367{ 1378{
1368 uint i; 1379 uint i;
1369 for(i=0;i<mMinY.size();++i) { 1380 for(i=0;i<mMinY.size();++i) {
1370 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true); 1381 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true);
1371 else mEventIndicatorTop->enableColumn(i,false); 1382 else mEventIndicatorTop->enableColumn(i,false);
1372 } 1383 }
1373 1384
1374 mEventIndicatorTop->update(); 1385 mEventIndicatorTop->update();
1375} 1386}
1376 1387
1377void KOAgendaView::updateEventIndicatorBottom(int newY) 1388void KOAgendaView::updateEventIndicatorBottom(int newY)
1378{ 1389{
1379 uint i; 1390 uint i;
1380 for(i=0;i<mMaxY.size();++i) { 1391 for(i=0;i<mMaxY.size();++i) {
1381 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true); 1392 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true);
1382 else mEventIndicatorBottom->enableColumn(i,false); 1393 else mEventIndicatorBottom->enableColumn(i,false);
1383 } 1394 }
1384 1395
1385 mEventIndicatorBottom->update(); 1396 mEventIndicatorBottom->update();
1386} 1397}
1387 1398
1388void KOAgendaView::startDrag(Event *event) 1399void KOAgendaView::startDrag(Event *event)
1389{ 1400{
1390#ifndef KORG_NODND 1401#ifndef KORG_NODND
1391 DndFactory factory( calendar() ); 1402 DndFactory factory( calendar() );
1392 ICalDrag *vd = factory.createDrag(event,this); 1403 ICalDrag *vd = factory.createDrag(event,this);
1393 if (vd->drag()) { 1404 if (vd->drag()) {
1394 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl; 1405 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl;
1395 } 1406 }
1396#endif 1407#endif
1397} 1408}
1398 1409
1399void KOAgendaView::readSettings() 1410void KOAgendaView::readSettings()
1400{ 1411{
1401 readSettings(KOGlobals::config()); 1412 readSettings(KOGlobals::config());
1402} 1413}
1403 1414
1404void KOAgendaView::readSettings(KConfig *config) 1415void KOAgendaView::readSettings(KConfig *config)
1405{ 1416{
1406 // kdDebug() << "KOAgendaView::readSettings()" << endl; 1417 // kdDebug() << "KOAgendaView::readSettings()" << endl;
1407 1418
1408 config->setGroup("Views"); 1419 config->setGroup("Views");
1409 1420
1410 //#ifndef KORG_NOSPLITTER 1421 //#ifndef KORG_NOSPLITTER
1411 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView"); 1422 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView");
1412 if (sizes.count() == 2) { 1423 if (sizes.count() == 2) {
1413 if ( sizes[0] < 20 ) { 1424 if ( sizes[0] < 20 ) {
1414 sizes[1] = sizes[1] +20 - sizes[0]; 1425 sizes[1] = sizes[1] +20 - sizes[0];
1415 sizes[0] = 20; 1426 sizes[0] = 20;
1416 } 1427 }
1417 mSplitterAgenda->setSizes(sizes); 1428 mSplitterAgenda->setSizes(sizes);
1418 // qDebug("read %d %d ",sizes[0],sizes[1] ); 1429 // qDebug("read %d %d ",sizes[0],sizes[1] );
1419 } 1430 }
1420 //#endif 1431 //#endif
1421 1432
1422 // updateConfig(); 1433 // updateConfig();
1423} 1434}
1424 1435
1425void KOAgendaView::writeSettings(KConfig *config) 1436void KOAgendaView::writeSettings(KConfig *config)
1426{ 1437{
1427 // kdDebug() << "KOAgendaView::writeSettings()" << endl; 1438 // kdDebug() << "KOAgendaView::writeSettings()" << endl;
1428 1439
1429 config->setGroup("Views"); 1440 config->setGroup("Views");
1430 1441
1431 //#ifndef KORG_NOSPLITTER 1442 //#ifndef KORG_NOSPLITTER
1432 QValueList<int> list = mSplitterAgenda->sizes(); 1443 QValueList<int> list = mSplitterAgenda->sizes();
1433 config->writeEntry("Separator AgendaView",list); 1444 config->writeEntry("Separator AgendaView",list);
1434 //qDebug("write %d %d ", list[0],list[1] ); 1445 //qDebug("write %d %d ", list[0],list[1] );
1435 //#endif 1446 //#endif
1436} 1447}
1437 1448
1438void KOAgendaView::setHolidayMasks() 1449void KOAgendaView::setHolidayMasks()
1439{ 1450{
1440 mHolidayMask.resize(mSelectedDates.count()); 1451 mHolidayMask.resize(mSelectedDates.count());
1441 1452
1442 uint i; 1453 uint i;
1443 for(i=0;i<mSelectedDates.count();++i) { 1454 for(i=0;i<mSelectedDates.count();++i) {
1444 QDate date = mSelectedDates[i]; 1455 QDate date = mSelectedDates[i];
1445 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6); 1456 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6);
1446 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7); 1457 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7);
1447 bool showHoliday = false; 1458 bool showHoliday = false;
1448 if ( KOPrefs::instance()->mExcludeHolidays ) { 1459 if ( KOPrefs::instance()->mExcludeHolidays ) {
1449 QPtrList<Event> events = calendar()->events( date, true ); 1460 QPtrList<Event> events = calendar()->events( date, true );
1450 Event *event; 1461 Event *event;
1451 for( event = events.first(); event; event = events.next() ) { 1462 for( event = events.first(); event; event = events.next() ) {
1452 if ( event->isHoliday()) { 1463 if ( event->isHoliday()) {
1453 showHoliday = true; 1464 showHoliday = true;
1454 break; 1465 break;
1455 } 1466 }
1456 } 1467 }
1457 1468
1458 } 1469 }
1459 1470
1460#ifndef KORG_NOPLUGINS 1471#ifndef KORG_NOPLUGINS
1461 bool showHoliday = KOPrefs::instance()->mExcludeHolidays && 1472 bool showHoliday = KOPrefs::instance()->mExcludeHolidays &&
1462 !KOCore::self()->holiday(date).isEmpty(); 1473 !KOCore::self()->holiday(date).isEmpty();
1463#endif 1474#endif
1464 bool showDay = showSaturday || showSunday || showHoliday; 1475 bool showDay = showSaturday || showSunday || showHoliday;
1465 1476
1466 if (showDay) { 1477 if (showDay) {
1467 mHolidayMask.at(i) = true; 1478 mHolidayMask.at(i) = true;
1468 } else { 1479 } else {
1469 mHolidayMask.at(i) = false; 1480 mHolidayMask.at(i) = false;
1470 } 1481 }
1471 } 1482 }
1472 1483
1473 mAgenda->setHolidayMask(&mHolidayMask); 1484 mAgenda->setHolidayMask(&mHolidayMask);
1474 mAllDayAgenda->setHolidayMask(&mHolidayMask); 1485 mAllDayAgenda->setHolidayMask(&mHolidayMask);
1475} 1486}
1476 1487
1477void KOAgendaView::setContentsPos(int y) 1488void KOAgendaView::setContentsPos(int y)
1478{ 1489{
1479 mAgenda->setContentsPos(0,y); 1490 mAgenda->setContentsPos(0,y);
1480} 1491}
1481 1492
1482void KOAgendaView::clearSelection() 1493void KOAgendaView::clearSelection()
1483{ 1494{
1484 mAgenda->deselectItem(); 1495 mAgenda->deselectItem();
1485 mAllDayAgenda->deselectItem(); 1496 mAllDayAgenda->deselectItem();
1486} 1497}
1487 1498
1488void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart, 1499void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart,
1489 int gxEnd, int gyEnd) 1500 int gxEnd, int gyEnd)
1490{ 1501{
1491 mTimeSpanInAllDay = true; 1502 mTimeSpanInAllDay = true;
1492 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd); 1503 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd);
1493} 1504}
1494 1505
1495 1506
1496 1507
1497 1508
1498void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart, 1509void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart,
1499 int gxEnd, int gyEnd) 1510 int gxEnd, int gyEnd)
1500{ 1511{
1501 if (!mSelectedDates.count()) return; 1512 if (!mSelectedDates.count()) return;
1502 1513
1503 QDate dayStart = mSelectedDates[gxStart]; 1514 QDate dayStart = mSelectedDates[gxStart];
1504 QDate dayEnd = mSelectedDates[gxEnd]; 1515 QDate dayEnd = mSelectedDates[gxEnd];
1505 1516
1506 QTime timeStart = mAgenda->gyToTime(gyStart); 1517 QTime timeStart = mAgenda->gyToTime(gyStart);
1507 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1518 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1508 1519
1509 QDateTime dtStart(dayStart,timeStart); 1520 QDateTime dtStart(dayStart,timeStart);
1510 QDateTime dtEnd(dayEnd,timeEnd); 1521 QDateTime dtEnd(dayEnd,timeEnd);
1511 1522
1512 mTimeSpanBegin = dtStart; 1523 mTimeSpanBegin = dtStart;
1513 mTimeSpanEnd = dtEnd; 1524 mTimeSpanEnd = dtEnd;
1514 1525
1515} 1526}
1516 1527
1517void KOAgendaView::deleteSelectedDateTime() 1528void KOAgendaView::deleteSelectedDateTime()
1518{ 1529{
1519 mTimeSpanBegin.setDate(QDate()); 1530 mTimeSpanBegin.setDate(QDate());
1520 mTimeSpanEnd.setDate(QDate()); 1531 mTimeSpanEnd.setDate(QDate());
1521 mTimeSpanInAllDay = false; 1532 mTimeSpanInAllDay = false;
1522} 1533}
1523 1534
1524void KOAgendaView::keyPressEvent ( QKeyEvent * e ) 1535void KOAgendaView::keyPressEvent ( QKeyEvent * e )
1525{ 1536{
1526 e->ignore(); 1537 e->ignore();
1527} 1538}
1528 1539
1529void KOAgendaView::scrollOneHourUp() 1540void KOAgendaView::scrollOneHourUp()
1530{ 1541{
1531 1542
1532 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 ); 1543 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 );
1533} 1544}
1534void KOAgendaView::scrollOneHourDown() 1545void KOAgendaView::scrollOneHourDown()
1535{ 1546{
1536 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 ); 1547 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 );
1537} 1548}
1538 1549
1539void KOAgendaView::setStartHour( int h ) 1550void KOAgendaView::setStartHour( int h )
1540{ 1551{
1541 mAgenda->setStartHour( h ); 1552 mAgenda->setStartHour( h );
1542 1553
1543} 1554}
1544void KOAgendaView::setInitStartHour() 1555void KOAgendaView::setInitStartHour()
1545{ 1556{
1546 1557
1547 if ( KOPrefs::instance()->mCenterOnCurrentTime ) 1558 if ( KOPrefs::instance()->mCenterOnCurrentTime )
1548 setStartHour( QTime::currentTime ().hour() ); 1559 setStartHour( QTime::currentTime ().hour() );
1549 else 1560 else
1550 setStartHour( KOPrefs::instance()->mDayBegins ); 1561 setStartHour( KOPrefs::instance()->mDayBegins );
1551 1562
1552} 1563}
1553 1564
1554 1565
1555void KOAgendaView::updateTodo( Todo * t, int ) 1566void KOAgendaView::updateTodo( Todo * t, int )
1556{ 1567{
1557 if ( !isVisible() ) 1568 if ( !isVisible() )
1558 return; 1569 return;
1559 bool remove = false; 1570 bool remove = false;
1560 bool removeAD = false; 1571 bool removeAD = false;
1561 QDate da; 1572 QDate da;
1562 if ( t->hasCompletedDate() ) 1573 if ( t->hasCompletedDate() )
1563 da = t->completed().date(); 1574 da = t->completed().date();
1564 else 1575 else
1565 da = t->dtDue().date(); 1576 da = t->dtDue().date();
1566 if ( ! t->hasDueDate() && !t->hasCompletedDate() ) { 1577 if ( ! t->hasDueDate() && !t->hasCompletedDate() ) {
1567 remove = true; 1578 remove = true;
1568 removeAD = true; 1579 removeAD = true;
1569 } 1580 }
1570 else { 1581 else {
1571 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ; 1582 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ;
1572 if ( overdue && 1583 if ( overdue &&
1573 QDate::currentDate() >= mSelectedDates.first() && 1584 QDate::currentDate() >= mSelectedDates.first() &&
1574 QDate::currentDate() <= mSelectedDates.last()) { 1585 QDate::currentDate() <= mSelectedDates.last()) {
1575 removeAD = false; 1586 removeAD = false;
1576 remove = true; 1587 remove = true;
1577 } 1588 }
1578 else { 1589 else {
1579 1590
1580 if ( da < mSelectedDates.first() || 1591 if ( da < mSelectedDates.first() ||
1581 da > mSelectedDates.last() ) { 1592 da > mSelectedDates.last() ) {
1582 remove = true; 1593 remove = true;
1583 removeAD = true; 1594 removeAD = true;
1584 } else { 1595 } else {
1585 remove = t->doesFloat() && !t->hasCompletedDate(); 1596 remove = t->doesFloat() && !t->hasCompletedDate();
1586 removeAD = !remove; 1597 removeAD = !remove;
1587 } 1598 }
1588 } 1599 }
1589 } 1600 }
1590 int days = mSelectedDates.first().daysTo( da ); 1601 int days = mSelectedDates.first().daysTo( da );
1591 //qDebug("daysto %d %d %d", days, remove,removeAD ); 1602 //qDebug("daysto %d %d %d", days, remove,removeAD );
1592 mAgenda->updateTodo( t , days, remove); 1603 mAgenda->updateTodo( t , days, remove);
1593 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1604 if ( KOPrefs::instance()->mShowTodoInAgenda )
1594 mAllDayAgenda->updateTodo( t , days, removeAD); 1605 mAllDayAgenda->updateTodo( t , days, removeAD);
1595 //qDebug("KOAgendaView::updateTodo( Todo *, int ) "); 1606 //qDebug("KOAgendaView::updateTodo( Todo *, int ) ");
1596 1607
1597} 1608}
diff --git a/korganizer/koagendaview.h b/korganizer/koagendaview.h
index 57b4e46..6dc81c6 100644
--- a/korganizer/koagendaview.h
+++ b/korganizer/koagendaview.h
@@ -1,289 +1,290 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23#ifndef KOAGENDAVIEW_H 23#ifndef KOAGENDAVIEW_H
24#define KOAGENDAVIEW_H 24#define KOAGENDAVIEW_H
25 25
26#include <qscrollview.h> 26#include <qscrollview.h>
27#include <qdatetime.h> 27#include <qdatetime.h>
28#include <qpushbutton.h> 28#include <qpushbutton.h>
29#include <qlayout.h> 29#include <qlayout.h>
30#ifndef DESKTOP_VERSION 30#ifndef DESKTOP_VERSION
31#include <qksplitter.h> 31#include <qksplitter.h>
32#else 32#else
33#include <qsplitter.h> 33#include <qsplitter.h>
34#endif 34#endif
35#include <qmemarray.h> 35#include <qmemarray.h>
36 36
37#include "koeventview.h" 37#include "koeventview.h"
38 38
39class QHBox; 39class QHBox;
40class QFrame; 40class QFrame;
41class QLabel; 41class QLabel;
42class QPushButton; 42class QPushButton;
43class CalendarView; 43class CalendarView;
44class KOAgenda; 44class KOAgenda;
45class KOAgendaItem; 45class KOAgendaItem;
46class KConfig; 46class KConfig;
47class KDGanttMinimizeSplitter; 47class KDGanttMinimizeSplitter;
48 48
49class KOAgendaButton : public QPushButton 49class KOAgendaButton : public QPushButton
50{ 50{
51 Q_OBJECT 51 Q_OBJECT
52 public: 52 public:
53 KOAgendaButton( QWidget *parent=0, const char *name=0 ) : 53 KOAgendaButton( QWidget *parent=0, const char *name=0 ) :
54 QPushButton( parent, name ) 54 QPushButton( parent, name )
55 { 55 {
56 mNum = -3; 56 mNum = -3;
57 setFlat( true ); 57 setFlat( true );
58 setFocusPolicy(NoFocus); 58 setFocusPolicy(NoFocus);
59 setSizePolicy(QSizePolicy( QSizePolicy::Expanding ,QSizePolicy::Expanding )); 59 setSizePolicy(QSizePolicy( QSizePolicy::Expanding ,QSizePolicy::Expanding ));
60 connect( this, SIGNAL( clicked() ), this, SLOT ( bClicked() ) ); 60 connect( this, SIGNAL( clicked() ), this, SLOT ( bClicked() ) );
61 }; 61 };
62 62
63 QSize sizeHint () const { return QSize( 5,5) ;} 63 QSize sizeHint () const { return QSize( 5,5) ;}
64 void setNum( int n) { mNum = n; } 64 void setNum( int n) { mNum = n; }
65private slots: 65private slots:
66 void bClicked() {emit numClicked( mNum);} 66 void bClicked() {emit numClicked( mNum);}
67signals: 67signals:
68 void numClicked( int ); 68 void numClicked( int );
69private: 69private:
70 int mNum; 70 int mNum;
71}; 71};
72 72
73class TimeLabels : public QScrollView { 73class TimeLabels : public QScrollView {
74 Q_OBJECT 74 Q_OBJECT
75 public: 75 public:
76 TimeLabels(int rows,QWidget *parent=0,const char *name=0,WFlags f=0); 76 TimeLabels(int rows,QWidget *parent=0,const char *name=0,WFlags f=0);
77 77
78 void setCellHeight(int height); 78 void setCellHeight(int height);
79 79
80 /** Calculates the minimum width */ 80 /** Calculates the minimum width */
81 virtual int minimumWidth() const; 81 virtual int minimumWidth() const;
82 82
83 /** updates widget's internal state */ 83 /** updates widget's internal state */
84 void updateConfig(); 84 void updateConfig();
85 85
86 /** */ 86 /** */
87 void setAgenda(KOAgenda* agenda); 87 void setAgenda(KOAgenda* agenda);
88 88
89 /** */ 89 /** */
90 virtual void paintEvent(QPaintEvent* e); 90 virtual void paintEvent(QPaintEvent* e);
91 void contentsMousePressEvent ( QMouseEvent * ) ; 91 void contentsMousePressEvent ( QMouseEvent * ) ;
92 void contentsMouseReleaseEvent ( QMouseEvent * ); 92 void contentsMouseReleaseEvent ( QMouseEvent * );
93 void contentsMouseMoveEvent ( QMouseEvent * ); 93 void contentsMouseMoveEvent ( QMouseEvent * );
94 94
95 public slots: 95 public slots:
96 /** update time label positions */ 96 /** update time label positions */
97 void positionChanged(); 97 void positionChanged();
98 signals: 98 signals:
99 void scaleChanged(); 99 void scaleChanged();
100 protected: 100 protected:
101 void drawContents(QPainter *p,int cx, int cy, int cw, int ch); 101 void drawContents(QPainter *p,int cx, int cy, int cw, int ch);
102 102
103 private: 103 private:
104 int mMiniWidth; 104 int mMiniWidth;
105 int mMouseDownY; 105 int mMouseDownY;
106 QString mOrgCap; 106 QString mOrgCap;
107 int mRows; 107 int mRows;
108 int mCellHeight; 108 int mCellHeight;
109 109
110 /** */ 110 /** */
111 KOAgenda* mAgenda; 111 KOAgenda* mAgenda;
112}; 112};
113 113
114class EventIndicator : public QFrame { 114class EventIndicator : public QFrame {
115 Q_OBJECT 115 Q_OBJECT
116 public: 116 public:
117 enum Location { Top, Bottom }; 117 enum Location { Top, Bottom };
118 EventIndicator(Location loc=Top,QWidget *parent=0,const char *name=0); 118 EventIndicator(Location loc=Top,QWidget *parent=0,const char *name=0);
119 virtual ~EventIndicator(); 119 virtual ~EventIndicator();
120 120
121 void changeColumns(int columns); 121 void changeColumns(int columns);
122 void setPaintWidget( KDGanttMinimizeSplitter* ); 122 void setPaintWidget( KDGanttMinimizeSplitter* );
123 void setXOffset( int ); 123 void setXOffset( int );
124 void enableColumn(int column, bool enable); 124 void enableColumn(int column, bool enable);
125 125
126 protected: 126 protected:
127 void drawContents(QPainter *); 127 void drawContents(QPainter *);
128 128
129 private: 129 private:
130 int mXOffset; 130 int mXOffset;
131 KDGanttMinimizeSplitter* mPaintWidget; 131 KDGanttMinimizeSplitter* mPaintWidget;
132 int mColumns; 132 int mColumns;
133 QHBox *mTopBox; 133 QHBox *mTopBox;
134 QBoxLayout *mTopLayout; 134 QBoxLayout *mTopLayout;
135 Location mLocation; 135 Location mLocation;
136 QPixmap mPixmap; 136 QPixmap mPixmap;
137 QMemArray<bool> mEnabled; 137 QMemArray<bool> mEnabled;
138}; 138};
139 139
140/** 140/**
141 KOAgendaView is the agenda-like view used to display events in an one or 141 KOAgendaView is the agenda-like view used to display events in an one or
142 multi-day view. 142 multi-day view.
143*/ 143*/
144class KOAgendaView : public KOEventView { 144class KOAgendaView : public KOEventView {
145 Q_OBJECT 145 Q_OBJECT
146 public: 146 public:
147 KOAgendaView(Calendar *cal,QWidget *parent = 0,const char *name = 0 ); 147 KOAgendaView(Calendar *cal,QWidget *parent = 0,const char *name = 0 );
148 virtual ~KOAgendaView(); 148 virtual ~KOAgendaView();
149 void setStartHour( int ); 149 void setStartHour( int );
150 void toggleAllDay(); 150 void toggleAllDay();
151 151
152 152
153 /** Returns maximum number of days supported by the koagendaview */ 153 /** Returns maximum number of days supported by the koagendaview */
154 virtual int maxDatesHint(); 154 virtual int maxDatesHint();
155 155
156 /** Returns number of currently shown dates. */ 156 /** Returns number of currently shown dates. */
157 virtual int currentDateCount(); 157 virtual int currentDateCount();
158 158
159 /** returns the currently selected events */ 159 /** returns the currently selected events */
160 virtual QPtrList<Incidence> selectedIncidences(); 160 virtual QPtrList<Incidence> selectedIncidences();
161 161
162 /** returns the currently selected events */ 162 /** returns the currently selected events */
163 virtual DateList selectedDates(); 163 virtual DateList selectedDates();
164 164
165 /** Remove all events from view */ 165 /** Remove all events from view */
166 void clearView(); 166 void clearView();
167 KOAgenda *agenda() { return mAgenda;} 167 KOAgenda *agenda() { return mAgenda;}
168 virtual void printPreview(CalPrinter *calPrinter, 168 virtual void printPreview(CalPrinter *calPrinter,
169 const QDate &, const QDate &); 169 const QDate &, const QDate &);
170 170
171 /** start-datetime of selection */ 171 /** start-datetime of selection */
172 QDateTime selectionStart() {return mTimeSpanBegin;} 172 QDateTime selectionStart() {return mTimeSpanBegin;}
173 /** end-datetime of selection */ 173 /** end-datetime of selection */
174 QDateTime selectionEnd() {return mTimeSpanEnd;} 174 QDateTime selectionEnd() {return mTimeSpanEnd;}
175 /** returns true if selection is for whole day */ 175 /** returns true if selection is for whole day */
176 bool selectedIsAllDay() {return mTimeSpanInAllDay;} 176 bool selectedIsAllDay() {return mTimeSpanInAllDay;}
177 /** make selected start/end invalid */ 177 /** make selected start/end invalid */
178 void deleteSelectedDateTime(); 178 void deleteSelectedDateTime();
179 void repaintAgenda(); 179 void repaintAgenda();
180 public slots: 180 public slots:
181 void setInitStartHour(); 181 void setInitStartHour();
182 virtual void updateView(); 182 virtual void updateView();
183 virtual void updateConfig(); 183 virtual void updateConfig();
184 virtual void showDates(const QDate &start, const QDate &end); 184 virtual void showDates(const QDate &start, const QDate &end);
185 virtual void showEvents(QPtrList<Event> eventList); 185 virtual void showEvents(QPtrList<Event> eventList);
186 186
187 void updateTodo( Todo *, int ); 187 void updateTodo( Todo *, int );
188 void changeEventDisplay(Event *, int); 188 void changeEventDisplay(Event *, int);
189 189
190 void clearSelection(); 190 void clearSelection();
191 191
192 void newTodo(int gx,int gy); 192 void newTodo(int gx,int gy);
193 void newEvent(int gx,int gy); 193 void newEvent(int gx,int gy);
194 void newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd); 194 void newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd);
195 void newEventAllDay(int gx, int gy); 195 void newEventAllDay(int gx, int gy);
196 void newTodoAllDay(int gx, int gy); 196 void newTodoAllDay(int gx, int gy);
197 197
198 void startDrag(Event *); 198 void startDrag(Event *);
199 199
200 void readSettings(); 200 void readSettings();
201 void readSettings(KConfig *); 201 void readSettings(KConfig *);
202 void writeSettings(KConfig *); 202 void writeSettings(KConfig *);
203 203
204 void setContentsPos(int y); 204 void setContentsPos(int y);
205 205
206 void scrollOneHourUp(); 206 void scrollOneHourUp();
207 void scrollOneHourDown(); 207 void scrollOneHourDown();
208 void addToCalSlot(Incidence *, Incidence *); 208 void addToCalSlot(Incidence *, Incidence *);
209 void slotShowDateView( int, int );
209 210
210 signals: 211 signals:
211 void showDateView( int, QDate ); 212 void showDateView( int, QDate );
212 void newTodoSignal( QDateTime ,bool ); 213 void newTodoSignal( QDateTime ,bool );
213 void toggleExpand(); 214 void toggleExpand();
214 void selectWeekNum( int ); 215 void selectWeekNum( int );
215 void todoMoved( Todo *, int ); 216 void todoMoved( Todo *, int );
216 void incidenceChanged(Incidence * , int ); 217 void incidenceChanged(Incidence * , int );
217 // void cloneIncidenceSignal(Incidence *); 218 // void cloneIncidenceSignal(Incidence *);
218 219
219 protected: 220 protected:
220 KOAgendaButton* getNewDaylabel(); 221 KOAgendaButton* getNewDaylabel();
221 bool mBlockUpdating; 222 bool mBlockUpdating;
222 int mUpcomingWidth; 223 int mUpcomingWidth;
223 /** Fill agenda beginning with date startDate */ 224 /** Fill agenda beginning with date startDate */
224 void fillAgenda(const QDate &startDate); 225 void fillAgenda(const QDate &startDate);
225 void resizeEvent( QResizeEvent* e ); 226 void resizeEvent( QResizeEvent* e );
226 /** Fill agenda using the current set value for the start date */ 227 /** Fill agenda using the current set value for the start date */
227 void fillAgenda(); 228 void fillAgenda();
228 229
229 /** Create labels for the selected dates. */ 230 /** Create labels for the selected dates. */
230 void createDayLabels(); 231 void createDayLabels();
231 232
232 /** 233 /**
233 Set the masks on the agenda widgets indicating, which days are holidays. 234 Set the masks on the agenda widgets indicating, which days are holidays.
234 */ 235 */
235 void setHolidayMasks(); 236 void setHolidayMasks();
236 237
237 protected slots: 238 protected slots:
238 void slotDaylabelClicked( int ); 239 void slotDaylabelClicked( int );
239 /** Update event belonging to agenda item */ 240 /** Update event belonging to agenda item */
240 void updateEventDates(KOAgendaItem *item, int mode = -1); 241 void updateEventDates(KOAgendaItem *item, int mode = -1);
241 //void updateMovedTodo(); 242 //void updateMovedTodo();
242 243
243 void updateEventIndicatorTop(int newY); 244 void updateEventIndicatorTop(int newY);
244 void updateEventIndicatorBottom(int newY); 245 void updateEventIndicatorBottom(int newY);
245 246
246 /** Updates data for selected timespan */ 247 /** Updates data for selected timespan */
247 void newTimeSpanSelected(int gxStart, int gyStart, int gxEnd, int gyEnd); 248 void newTimeSpanSelected(int gxStart, int gyStart, int gxEnd, int gyEnd);
248 /** Updates data for selected timespan for all day event*/ 249 /** Updates data for selected timespan for all day event*/
249 void newTimeSpanSelectedAllDay(int gxStart, int gyStart, int gxEnd, int gyEnd); 250 void newTimeSpanSelectedAllDay(int gxStart, int gyStart, int gxEnd, int gyEnd);
250 251
251 private: 252 private:
252 // view widgets 253 // view widgets
253 QFrame *mDayLabels; 254 QFrame *mDayLabels;
254 QHBox *mDayLabelsFrame; 255 QHBox *mDayLabelsFrame;
255 QBoxLayout *mLayoutDayLabels; 256 QBoxLayout *mLayoutDayLabels;
256 QFrame *mAllDayFrame; 257 QFrame *mAllDayFrame;
257 KOAgenda *mAllDayAgenda; 258 KOAgenda *mAllDayAgenda;
258 KOAgenda *mAgenda; 259 KOAgenda *mAgenda;
259 TimeLabels *mTimeLabels; 260 TimeLabels *mTimeLabels;
260 QWidget *mDummyAllDayLeft; 261 QWidget *mDummyAllDayLeft;
261 262
262 KDGanttMinimizeSplitter* mSplitterAgenda; 263 KDGanttMinimizeSplitter* mSplitterAgenda;
263 QPushButton *mExpandButton; 264 QPushButton *mExpandButton;
264 265
265 DateList mSelectedDates; // List of dates to be displayed 266 DateList mSelectedDates; // List of dates to be displayed
266 int mViewType; 267 int mViewType;
267 268
268 bool mWeekStartsMonday; 269 bool mWeekStartsMonday;
269 int mStartHour; 270 int mStartHour;
270 271
271 KOEventPopupMenu *mAgendaPopup; 272 KOEventPopupMenu *mAgendaPopup;
272 KOEventPopupMenu *mAllDayAgendaPopup; 273 KOEventPopupMenu *mAllDayAgendaPopup;
273 274
274 EventIndicator *mEventIndicatorTop; 275 EventIndicator *mEventIndicatorTop;
275 EventIndicator *mEventIndicatorBottom; 276 EventIndicator *mEventIndicatorBottom;
276 277
277 QMemArray<int> mMinY; 278 QMemArray<int> mMinY;
278 QMemArray<int> mMaxY; 279 QMemArray<int> mMaxY;
279 280
280 QMemArray<bool> mHolidayMask; 281 QMemArray<bool> mHolidayMask;
281 282
282 QPtrList<KOAgendaButton> mDayLabelsList; 283 QPtrList<KOAgendaButton> mDayLabelsList;
283 QDateTime mTimeSpanBegin; 284 QDateTime mTimeSpanBegin;
284 QDateTime mTimeSpanEnd; 285 QDateTime mTimeSpanEnd;
285 bool mTimeSpanInAllDay; 286 bool mTimeSpanInAllDay;
286 void keyPressEvent ( QKeyEvent * e ); 287 void keyPressEvent ( QKeyEvent * e );
287}; 288};
288 289
289#endif // KOAGENDAVIEW_H 290#endif // KOAGENDAVIEW_H
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp
index b9ce4f4..ab9a4b6 100644
--- a/korganizer/komonthview.cpp
+++ b/korganizer/komonthview.cpp
@@ -1,1903 +1,1908 @@
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 //qDebug("KNoScrollListBox::keyPressEvent "); 104 //qDebug("KNoScrollListBox::keyPressEvent ");
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 if ( count() ) { 127 if ( count() ) {
128 setCurrentItem((currentItem()+count()-1)%count()); 128 setCurrentItem((currentItem()+count()-1)%count());
129 if(!itemVisible(currentItem())) { 129 if(!itemVisible(currentItem())) {
130 if((unsigned int) currentItem() == (count()-1)) { 130 if((unsigned int) currentItem() == (count()-1)) {
131 setTopItem(currentItem()-numItemsVisible()+1); 131 setTopItem(currentItem()-numItemsVisible()+1);
132 } else { 132 } else {
133 setTopItem(topItem()-1); 133 setTopItem(topItem()-1);
134 } 134 }
135 } 135 }
136 } 136 }
137 break; 137 break;
138 case Key_Down: 138 case Key_Down:
139 if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { 139 if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) {
140 e->ignore(); 140 e->ignore();
141 break; 141 break;
142 } 142 }
143 if ( count () ) { 143 if ( count () ) {
144 setCurrentItem((currentItem()+1)%count()); 144 setCurrentItem((currentItem()+1)%count());
145 if(!itemVisible(currentItem())) { 145 if(!itemVisible(currentItem())) {
146 if(currentItem() == 0) { 146 if(currentItem() == 0) {
147 setTopItem(0); 147 setTopItem(0);
148 } else { 148 } else {
149 setTopItem(topItem()+1); 149 setTopItem(topItem()+1);
150 } 150 }
151 } 151 }
152 } 152 }
153 break; 153 break;
154 case Key_I: 154 case Key_I:
155 QTimer::singleShot( 11, this, SLOT ( oneDown() ) ); 155 QTimer::singleShot( 11, this, SLOT ( oneDown() ) );
156 e->ignore(); 156 e->ignore();
157 break; 157 break;
158 case Key_Return: 158 case Key_Return:
159 case Key_Enter: 159 case Key_Enter:
160 { 160 {
161 if ( currentItem() >= 0 ) { 161 if ( currentItem() >= 0 ) {
162 emit doubleClicked( item( currentItem() ) ); 162 emit doubleClicked( item( currentItem() ) );
163 e->accept(); 163 e->accept();
164 } else { 164 } else {
165 e->ignore(); 165 e->ignore();
166 } 166 }
167 } 167 }
168 break; 168 break;
169 case Key_Shift: 169 case Key_Shift:
170 emit shiftDown(); 170 emit shiftDown();
171 break; 171 break;
172 default: 172 default:
173 e->ignore(); 173 e->ignore();
174 break; 174 break;
175 } 175 }
176} 176}
177 177
178void KNoScrollListBox::oneDown() 178void KNoScrollListBox::oneDown()
179{ 179{
180 if ( count () ) { 180 if ( count () ) {
181 setCurrentItem((currentItem()+1)%count()); 181 setCurrentItem((currentItem()+1)%count());
182 if(!itemVisible(currentItem())) { 182 if(!itemVisible(currentItem())) {
183 if(currentItem() == 0) { 183 if(currentItem() == 0) {
184 setTopItem(0); 184 setTopItem(0);
185 } else { 185 } else {
186 setTopItem(topItem()+1); 186 setTopItem(topItem()+1);
187 } 187 }
188 } 188 }
189 } 189 }
190} 190}
191void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) 191void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e)
192{ 192{
193 switch(e->key()) { 193 switch(e->key()) {
194 case Key_Shift: 194 case Key_Shift:
195 emit shiftUp(); 195 emit shiftUp();
196 break; 196 break;
197 default: 197 default:
198 break; 198 break;
199 } 199 }
200} 200}
201 201
202void KNoScrollListBox::mousePressEvent(QMouseEvent *e) 202void KNoScrollListBox::mousePressEvent(QMouseEvent *e)
203{ 203{
204 QListBox::mousePressEvent(e); 204 QListBox::mousePressEvent(e);
205 205
206 if(e->button() == RightButton) { 206 if(e->button() == RightButton) {
207 emit rightClick(); 207 emit rightClick();
208 } 208 }
209} 209}
210 210
211MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) 211MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s)
212 : QListBoxItem() 212 : QListBoxItem()
213{ 213{
214 mblockRepaint = true; 214 mblockRepaint = true;
215 setText( s ); 215 setText( s );
216 mMultiday = 0; 216 mMultiday = 0;
217 mIncidence = incidence; 217 mIncidence = incidence;
218 mDate = qd; 218 mDate = qd;
219 mRecur = false; 219 mRecur = false;
220 mAlarm = false; 220 mAlarm = false;
221 mReply = false; 221 mReply = false;
222 mInfo = false; 222 mInfo = false;
223 //qDebug("NEWWWWWWWWWWWWW "); 223 //qDebug("NEWWWWWWWWWWWWW ");
224} 224}
225void MonthViewItem::recycle( Incidence *incidence, QDate qd, const QString & s) 225void MonthViewItem::recycle( Incidence *incidence, QDate qd, const QString & s)
226{ 226{
227 setText( s ); 227 setText( s );
228 mMultiday = 0; 228 mMultiday = 0;
229 mIncidence = incidence; 229 mIncidence = incidence;
230 mDate = qd; 230 mDate = qd;
231 mRecur = false; 231 mRecur = false;
232 mAlarm = false; 232 mAlarm = false;
233 mReply = false; 233 mReply = false;
234 mInfo = false; 234 mInfo = false;
235 //qDebug("recucleeeeeeeeeeeeeeeee "); 235 //qDebug("recucleeeeeeeeeeeeeeeee ");
236} 236}
237 237
238void MonthViewItem::paint(QPainter *p) 238void MonthViewItem::paint(QPainter *p)
239{ 239{
240 if ( mblockRepaint ) { 240 if ( mblockRepaint ) {
241 //qDebug("block "); 241 //qDebug("block ");
242 return; 242 return;
243 } 243 }
244 //qDebug("NON block "); 244 //qDebug("NON block ");
245#if QT_VERSION >= 0x030000 245#if QT_VERSION >= 0x030000
246 bool sel = isSelected(); 246 bool sel = isSelected();
247#else 247#else
248 bool sel = selected(); 248 bool sel = selected();
249#endif 249#endif
250 250
251 251
252 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) 252 if (KOPrefs::instance()->mMonthViewUsesCategoryColor)
253 { 253 {
254 p->setBackgroundColor( palette().color( QPalette::Normal, \ 254 p->setBackgroundColor( palette().color( QPalette::Normal, \
255 sel ? QColorGroup::Highlight : QColorGroup::Background ) ); 255 sel ? QColorGroup::Highlight : QColorGroup::Background ) );
256 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); 256 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) );
257 } 257 }
258 int x = 1; 258 int x = 1;
259 //int y = 3;//(height() - mRecurPixmap.height()) /2; 259 //int y = 3;//(height() - mRecurPixmap.height()) /2;
260 int size = PIXMAP_SIZE; 260 int size = PIXMAP_SIZE;
261 if ( QApplication::desktop()->width() < 300 ) 261 if ( QApplication::desktop()->width() < 300 )
262 size = 3; 262 size = 3;
263 int heihei = height( listBox () ); 263 int heihei = height( listBox () );
264 int y = (heihei - size -1 ) /2; 264 int y = (heihei - size -1 ) /2;
265 265
266 if ( KOPrefs::instance()->mMonthShowIcons ) { 266 if ( KOPrefs::instance()->mMonthShowIcons ) {
267 if ( mInfo ) { 267 if ( mInfo ) {
268 p->fillRect ( x, y,size,size, Qt::darkGreen ); 268 p->fillRect ( x, y,size,size, Qt::darkGreen );
269 x += size + 1; 269 x += size + 1;
270 } 270 }
271 if ( mRecur ) { 271 if ( mRecur ) {
272 p->fillRect ( x, y,size,size, Qt::blue ); 272 p->fillRect ( x, y,size,size, Qt::blue );
273 x += size + 1; 273 x += size + 1;
274 } 274 }
275 if ( mAlarm ) { 275 if ( mAlarm ) {
276 p->fillRect ( x, y,size,size, Qt::red ); 276 p->fillRect ( x, y,size,size, Qt::red );
277 x += size + 1; 277 x += size + 1;
278 } 278 }
279 if ( mReply ) { 279 if ( mReply ) {
280 p->fillRect ( x, y,size,size, Qt::yellow ); 280 p->fillRect ( x, y,size,size, Qt::yellow );
281 x += size + 1; 281 x += size + 1;
282 } 282 }
283 } 283 }
284 if ( mMultiday ) { 284 if ( mMultiday ) {
285 int yyy = y+(size/2); 285 int yyy = y+(size/2);
286 int sizeM = size+2; 286 int sizeM = size+2;
287 p->setBrush( QBrush::SolidPattern ); 287 p->setBrush( QBrush::SolidPattern );
288 p->drawLine ( x+1, yyy, x +sizeM +sizeM/2-1, yyy ) ; 288 p->drawLine ( x+1, yyy, x +sizeM +sizeM/2-1, yyy ) ;
289 if ( mMultiday == 2 || mMultiday == 3 ) { 289 if ( mMultiday == 2 || mMultiday == 3 ) {
290 QPointArray pa ( 3 ); 290 QPointArray pa ( 3 );
291 pa.setPoint (0, x, yyy ); 291 pa.setPoint (0, x, yyy );
292 pa.setPoint (1, x+sizeM/2, yyy+sizeM/2 ); 292 pa.setPoint (1, x+sizeM/2, yyy+sizeM/2 );
293 pa.setPoint (2, x+sizeM/2, yyy-sizeM/2 ); 293 pa.setPoint (2, x+sizeM/2, yyy-sizeM/2 );
294 p->drawPolygon( pa ); 294 p->drawPolygon( pa );
295 } 295 }
296 if ( mMultiday == 2 || mMultiday == 1 ) { 296 if ( mMultiday == 2 || mMultiday == 1 ) {
297 QPointArray pa ( 3 ); 297 QPointArray pa ( 3 );
298 pa.setPoint (0, x+sizeM +sizeM/2, yyy ); 298 pa.setPoint (0, x+sizeM +sizeM/2, yyy );
299 pa.setPoint (1, x+sizeM, yyy+sizeM/2 ); 299 pa.setPoint (1, x+sizeM, yyy+sizeM/2 );
300 pa.setPoint (2, x+sizeM, yyy-sizeM/2 ); 300 pa.setPoint (2, x+sizeM, yyy-sizeM/2 );
301 p->drawPolygon( pa ); 301 p->drawPolygon( pa );
302 } 302 }
303 if ( mMultiday == 1 ) { 303 if ( mMultiday == 1 ) {
304 // p->fillRect ( x, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); 304 // p->fillRect ( x, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) );
305 305
306 p->drawLine ( x+1, yyy-sizeM/2, x+1, yyy+sizeM/2 ); 306 p->drawLine ( x+1, yyy-sizeM/2, x+1, yyy+sizeM/2 );
307 } 307 }
308 if ( mMultiday == 3 ) { 308 if ( mMultiday == 3 ) {
309 // p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); 309 // p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) );
310 p->drawLine ( x+sizeM +sizeM/2-1, yyy-sizeM/2, x+sizeM +sizeM/2-1, yyy+sizeM/2 ); 310 p->drawLine ( x+sizeM +sizeM/2-1, yyy-sizeM/2, x+sizeM +sizeM/2-1, yyy+sizeM/2 );
311 311
312 } 312 }
313 x += sizeM/2 + 1; 313 x += sizeM/2 + 1;
314 x += sizeM + 1; 314 x += sizeM + 1;
315 } 315 }
316 316
317 if ( mIncidence->type() == "Todo" ){ 317 if ( mIncidence->type() == "Todo" ){
318 Todo* td = ( Todo* ) mIncidence; 318 Todo* td = ( Todo* ) mIncidence;
319 if ( td->isCompleted() ) { 319 if ( td->isCompleted() ) {
320 int half = size/2; 320 int half = size/2;
321 p->drawLine ( x, heihei/2, x +half , heihei/2 +half ) ; 321 p->drawLine ( x, heihei/2, x +half , heihei/2 +half ) ;
322 p->drawLine ( x +half , heihei/2 +half , x +half+half +2 , heihei/2 -2 ) ; 322 p->drawLine ( x +half , heihei/2 +half , x +half+half +2 , heihei/2 -2 ) ;
323 x += half+half + 4; 323 x += half+half + 4;
324 324
325 } else { 325 } else {
326 int val = td->percentComplete()/20; 326 int val = td->percentComplete()/20;
327 p->fillRect ( x+1, y-2, val ,size+4,Qt::black ); 327 p->fillRect ( x+1, y-2, val ,size+4,Qt::black );
328 p->drawRect ( x, y-2,7,size+4); 328 p->drawRect ( x, y-2,7,size+4);
329 x += size + 3; 329 x += size + 3;
330 } 330 }
331 } 331 }
332 QFontMetrics fm = p->fontMetrics(); 332 QFontMetrics fm = p->fontMetrics();
333 int yPos; 333 int yPos;
334 int pmheight = size; 334 int pmheight = size;
335 if( pmheight < fm.height() ) 335 if( pmheight < fm.height() )
336 yPos = fm.ascent() + fm.leading()/2; 336 yPos = fm.ascent() + fm.leading()/2;
337 else 337 else
338 yPos = pmheight/2 - fm.height()/2 + fm.ascent(); 338 yPos = pmheight/2 - fm.height()/2 + fm.ascent();
339 p->setPen( palette().color( QPalette::Normal, sel ? \ 339 p->setPen( palette().color( QPalette::Normal, sel ? \
340 QColorGroup::HighlightedText : QColorGroup::Foreground ) ); 340 QColorGroup::HighlightedText : QColorGroup::Foreground ) );
341 p->drawText( x, yPos, text() ); 341 p->drawText( x, yPos, text() );
342 if ( mIncidence->cancelled() ) { 342 if ( mIncidence->cancelled() ) {
343 int wid = fm.width( text() ); 343 int wid = fm.width( text() );
344 p->drawLine( x, heihei/2-1 ,x+wid, heihei/2-1 ); 344 p->drawLine( x, heihei/2-1 ,x+wid, heihei/2-1 );
345 } 345 }
346 346
347} 347}
348 348
349int MonthViewItem::height(const QListBox *lb) const 349int MonthViewItem::height(const QListBox *lb) const
350{ 350{
351 int ret = 10; 351 int ret = 10;
352 if ( lb ) 352 if ( lb )
353 ret = lb->fontMetrics().lineSpacing()+1; 353 ret = lb->fontMetrics().lineSpacing()+1;
354 return ret; 354 return ret;
355} 355}
356 356
357int MonthViewItem::width(const QListBox *lb) const 357int MonthViewItem::width(const QListBox *lb) const
358{ 358{
359 359
360 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) { 360 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) {
361 int size = PIXMAP_SIZE; 361 int size = PIXMAP_SIZE;
362 if ( QApplication::desktop()->width() < 300 ) 362 if ( QApplication::desktop()->width() < 300 )
363 size = 3; 363 size = 3;
364 int x = 1; 364 int x = 1;
365 if ( KOPrefs::instance()->mMonthShowIcons ) { 365 if ( KOPrefs::instance()->mMonthShowIcons ) {
366 if ( mInfo ) { 366 if ( mInfo ) {
367 x += size + 1; 367 x += size + 1;
368 } 368 }
369 if( mRecur ) { 369 if( mRecur ) {
370 x += size+1; 370 x += size+1;
371 } 371 }
372 if( mAlarm ) { 372 if( mAlarm ) {
373 x += size+1; 373 x += size+1;
374 } 374 }
375 if( mReply ) { 375 if( mReply ) {
376 x += size+1; 376 x += size+1;
377 } 377 }
378 } 378 }
379 if( mMultiday ) { 379 if( mMultiday ) {
380 x += size+1+2+size/2; 380 x += size+1+2+size/2;
381 } 381 }
382 return( x + lb->fontMetrics().width( text() ) + 1 ); 382 return( x + lb->fontMetrics().width( text() ) + 1 );
383 } 383 }
384 if ( ! lb ) 384 if ( ! lb )
385 return 10; 385 return 10;
386 //qDebug("ret wid %d ", lb->width()); 386 //qDebug("ret wid %d ", lb->width());
387 return lb->width(); 387 return lb->width();
388} 388}
389 389
390 390
391MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) 391MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par )
392 : KNoScrollListBox( par ), 392 : KNoScrollListBox( par ),
393 mMonthView( parent ) 393 mMonthView( parent )
394{ 394{
395 395
396 mCurrentAvailItem = 0; 396 mCurrentAvailItem = 0;
397 //QVBoxLayout *topLayout = new QVBoxLayout( this ); 397 //QVBoxLayout *topLayout = new QVBoxLayout( this );
398 currentPalette = 0; 398 currentPalette = 0;
399 // mLabel = new QLabel( this );QPushButton 399 // mLabel = new QLabel( this );QPushButton
400 mLabel = new QPushButton( this ); 400 mLabel = new QPushButton( this );
401 //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); 401 //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain );
402 //mLabel->setLineWidth( 1 ); 402 //mLabel->setLineWidth( 1 );
403 //mLabel->setAlignment( AlignCenter ); 403 //mLabel->setAlignment( AlignCenter );
404 mLabel->setFlat( true ); 404 mLabel->setFlat( true );
405 mLabel->setFocusPolicy(NoFocus); 405 mLabel->setFocusPolicy(NoFocus);
406 //mItemList = new KNoScrollListBox( this ); 406 //mItemList = new KNoScrollListBox( this );
407 setMinimumSize( 10, 10 ); 407 setMinimumSize( 10, 10 );
408 setFrameStyle( QFrame::Panel | QFrame::Plain ); 408 setFrameStyle( QFrame::Panel | QFrame::Plain );
409 setLineWidth( 1 ); 409 setLineWidth( 1 );
410 //topLayout->addWidget( mItemList ); 410 //topLayout->addWidget( mItemList );
411 mLabel->raise(); 411 mLabel->raise();
412 // QColor( 0,0,255 ) QColor( 160,1600,255 ) 412 // QColor( 0,0,255 ) QColor( 160,1600,255 )
413 mStandardPalette = palette(); 413 mStandardPalette = palette();
414 mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); 414 mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) );
415 415
416 enableScrollBars( false ); 416 enableScrollBars( false );
417 updateConfig(); 417 updateConfig();
418 //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() )); 418 //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() ));
419 connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() )); 419 connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() ));
420 connect( this , SIGNAL( doubleClicked( QListBoxItem *) ), 420 connect( this , SIGNAL( doubleClicked( QListBoxItem *) ),
421 SLOT( defaultAction( QListBoxItem * ) ) ); 421 SLOT( defaultAction( QListBoxItem * ) ) );
422 connect( this, SIGNAL( rightButtonPressed( QListBoxItem *, 422 connect( this, SIGNAL( rightButtonPressed( QListBoxItem *,
423 const QPoint &) ), 423 const QPoint &) ),
424 SLOT( contextMenu( QListBoxItem * ) ) ); 424 SLOT( contextMenu( QListBoxItem * ) ) );
425 connect( this, SIGNAL( highlighted( QListBoxItem *) ), 425 connect( this, SIGNAL( highlighted( QListBoxItem *) ),
426 SLOT( selection( QListBoxItem * ) ) ); 426 SLOT( selection( QListBoxItem * ) ) );
427 connect( this, SIGNAL( clicked( QListBoxItem * ) ), 427 connect( this, SIGNAL( clicked( QListBoxItem * ) ),
428 SLOT( cellClicked( QListBoxItem * ) ) ); 428 SLOT( cellClicked( QListBoxItem * ) ) );
429 connect( this, SIGNAL( clicked( QListBoxItem * ) ), 429 connect( this, SIGNAL( clicked( QListBoxItem * ) ),
430 SLOT( selection( QListBoxItem * ) ) ); 430 SLOT( selection( QListBoxItem * ) ) );
431} 431}
432#ifdef DESKTOP_VERSION 432#ifdef DESKTOP_VERSION
433QToolTipGroup *MonthViewCell::toolTipGroup() 433QToolTipGroup *MonthViewCell::toolTipGroup()
434{ 434{
435 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); 435 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0);
436 return mToolTipGroup; 436 return mToolTipGroup;
437} 437}
438#endif 438#endif
439 439
440void MonthViewCell::setDate( const QDate &date ) 440void MonthViewCell::setDate( const QDate &date )
441{ 441{
442 // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl; 442 // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl;
443 mDate = date; 443 mDate = date;
444 444
445 445
446 446
447 //resizeEvent( 0 ); 447 //resizeEvent( 0 );
448} 448}
449 449
450QDate MonthViewCell::date() const 450QDate MonthViewCell::date() const
451{ 451{
452 return mDate; 452 return mDate;
453} 453}
454 454
455void MonthViewCell::setPrimary( bool primary ) 455void MonthViewCell::setPrimary( bool primary )
456{ 456{
457 mPrimary = primary; 457 mPrimary = primary;
458 //setMyPalette(); 458 //setMyPalette();
459} 459}
460void MonthViewCell::setMyPalette() 460void MonthViewCell::setMyPalette()
461{ 461{
462 462
463 if ( mHoliday) { 463 if ( mHoliday) {
464 if ( currentPalette == 1 ) return; 464 if ( currentPalette == 1 ) return;
465 mLabel->setPalette( QPalette ( mHolidayPalette.color( QPalette::Normal,QColorGroup::Base),mHolidayPalette.color(QPalette::Normal,QColorGroup::Base ) )); 465 mLabel->setPalette( QPalette ( mHolidayPalette.color( QPalette::Normal,QColorGroup::Base),mHolidayPalette.color(QPalette::Normal,QColorGroup::Base ) ));
466 setPalette( mHolidayPalette ); 466 setPalette( mHolidayPalette );
467 //mLabel->setPalette( mHolidayPalette ); 467 //mLabel->setPalette( mHolidayPalette );
468 currentPalette = 1; 468 currentPalette = 1;
469 469
470 } else { 470 } else {
471 if ( mPrimary ) { 471 if ( mPrimary ) {
472 if ( currentPalette == 2 ) return; 472 if ( currentPalette == 2 ) return;
473 mLabel->setPalette( QPalette ( mPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); 473 mLabel->setPalette( QPalette ( mPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) ));
474 //mLabel->setPalette( mPrimaryPalette ); 474 //mLabel->setPalette( mPrimaryPalette );
475 setPalette( mPrimaryPalette ); 475 setPalette( mPrimaryPalette );
476 currentPalette = 2; 476 currentPalette = 2;
477 477
478 } else { 478 } else {
479 if ( currentPalette == 3 ) return; 479 if ( currentPalette == 3 ) return;
480 setPalette( mNonPrimaryPalette ); 480 setPalette( mNonPrimaryPalette );
481 mLabel->setPalette( QPalette ( mNonPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mNonPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); 481 mLabel->setPalette( QPalette ( mNonPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mNonPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) ));
482 //mLabel->setPalette( mNonPrimaryPalette );; 482 //mLabel->setPalette( mNonPrimaryPalette );;
483 currentPalette = 3; 483 currentPalette = 3;
484 } 484 }
485 } 485 }
486 //QPalette pal = palette(); 486 //QPalette pal = palette();
487 487
488 //mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) )); 488 //mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) ));
489} 489}
490QPalette MonthViewCell::getPalette () 490QPalette MonthViewCell::getPalette ()
491{ 491{
492 if ( !KOPrefs::instance()->mMonthViewUsesDayColors ) 492 if ( !KOPrefs::instance()->mMonthViewUsesDayColors )
493 return mStandardPalette; 493 return mStandardPalette;
494 if ( mHoliday) { 494 if ( mHoliday) {
495 return mHolidayPalette ; 495 return mHolidayPalette ;
496 } else { 496 } else {
497 if ( mPrimary ) { 497 if ( mPrimary ) {
498 return mPrimaryPalette ; 498 return mPrimaryPalette ;
499 } 499 }
500 } 500 }
501 return mNonPrimaryPalette; 501 return mNonPrimaryPalette;
502} 502}
503bool MonthViewCell::isPrimary() const 503bool MonthViewCell::isPrimary() const
504{ 504{
505 return mPrimary; 505 return mPrimary;
506} 506}
507 507
508void MonthViewCell::setHoliday( bool holiday ) 508void MonthViewCell::setHoliday( bool holiday )
509{ 509{
510 mHoliday = holiday; 510 mHoliday = holiday;
511 //setMyPalette(); 511 //setMyPalette();
512} 512}
513 513
514void MonthViewCell::setHoliday( const QString &holiday ) 514void MonthViewCell::setHoliday( const QString &holiday )
515{ 515{
516 mHolidayString = holiday; 516 mHolidayString = holiday;
517 517
518 if ( !holiday.isEmpty() ) { 518 if ( !holiday.isEmpty() ) {
519 setHoliday( true ); 519 setHoliday( true );
520 } 520 }
521} 521}
522 522
523void MonthViewCell::startUpdateCell() 523void MonthViewCell::startUpdateCell()
524{ 524{
525 525
526 setFocusPolicy(NoFocus); 526 setFocusPolicy(NoFocus);
527 if ( !mMonthView->isUpdatePossible() ) 527 if ( !mMonthView->isUpdatePossible() )
528 return; 528 return;
529 MonthViewItem *mitem = (MonthViewItem*) firstItem (); 529 MonthViewItem *mitem = (MonthViewItem*) firstItem ();
530 while ( mitem ) { 530 while ( mitem ) {
531 mitem->setBlockRepaint( true ); 531 mitem->setBlockRepaint( true );
532 mitem = (MonthViewItem *)mitem->next(); 532 mitem = (MonthViewItem *)mitem->next();
533 } 533 }
534 if ( mAvailItemList.count() > 20 ) { 534 if ( mAvailItemList.count() > 20 ) {
535 mAvailItemList.setAutoDelete( true ); 535 mAvailItemList.setAutoDelete( true );
536 mAvailItemList.clear(); 536 mAvailItemList.clear();
537 mAvailItemList.setAutoDelete( false ); 537 mAvailItemList.setAutoDelete( false );
538 } 538 }
539 /* 539 /*
540 if ( !isVisible() ){ 540 if ( !isVisible() ){
541 return; 541 return;
542 } 542 }
543 */ 543 */
544 // qDebug("MonthViewCell::updateCell() "); 544 // qDebug("MonthViewCell::updateCell() ");
545 setPrimary( mDate.month()%2 ); 545 setPrimary( mDate.month()%2 );
546 setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays); 546 setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays);
547 if ( mDate == QDate::currentDate() ) { 547 if ( mDate == QDate::currentDate() ) {
548 setLineWidth( 3 ); 548 setLineWidth( 3 );
549 } else { 549 } else {
550 setLineWidth( 1 ); 550 setLineWidth( 1 );
551 } 551 }
552 mCurrentAvailItem = (MonthViewItem*) firstItem (); 552 mCurrentAvailItem = (MonthViewItem*) firstItem ();
553 //clear(); 553 //clear();
554 554
555#ifdef DESKTOP_VERSION 555#ifdef DESKTOP_VERSION
556 QToolTip::remove(this); 556 QToolTip::remove(this);
557#endif 557#endif
558 mToolTip.clear(); 558 mToolTip.clear();
559 //qApp->processEvents(); 559 //qApp->processEvents();
560#if 0 560#if 0
561 if ( !mHolidayString.isEmpty() ) { 561 if ( !mHolidayString.isEmpty() ) {
562 MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); 562 MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString );
563 item->setPalette( mHolidayPalette ); 563 item->setPalette( mHolidayPalette );
564 insertItem( item ); 564 insertItem( item );
565 mToolTip.append ( mHolidayString ); 565 mToolTip.append ( mHolidayString );
566 } 566 }
567#endif 567#endif
568} 568}
569 569
570void MonthViewCell::insertEvent(Event *event) 570void MonthViewCell::insertEvent(Event *event)
571{ 571{
572 QString mToolTipText; 572 QString mToolTipText;
573 bool insertNewItem = false; 573 bool insertNewItem = false;
574 setFocusPolicy(WheelFocus); 574 setFocusPolicy(WheelFocus);
575 if ( !(event->doesRecur() == Recurrence::rNone) ) { 575 if ( !(event->doesRecur() == Recurrence::rNone) ) {
576 if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) 576 if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily )
577 return; 577 return;
578 else 578 else
579 if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) 579 if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly )
580 return; 580 return;
581 } 581 }
582 582
583 if ( event->isHoliday()) { 583 if ( event->isHoliday()) {
584 setHoliday( true ); 584 setHoliday( true );
585 if ( mDate.dayOfWeek() == 7 ) 585 if ( mDate.dayOfWeek() == 7 )
586 setLineWidth( 3 ); 586 setLineWidth( 3 );
587 } 587 }
588 QString text; 588 QString text;
589 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day 589 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
590 if (event->isMultiDay()) { 590 if (event->isMultiDay()) {
591 QString prefix = "<->";multiday = 2; 591 QString prefix = "<->";multiday = 2;
592 QString time; 592 QString time;
593 if ( event->doesRecur() ) { 593 if ( event->doesRecur() ) {
594 if ( event->recursOn( mDate) ) { 594 if ( event->recursOn( mDate) ) {
595 prefix ="->" ;multiday = 1; 595 prefix ="->" ;multiday = 1;
596 } 596 }
597 else { 597 else {
598 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 598 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
599 if ( event->recursOn( mDate.addDays( -days)) ) { 599 if ( event->recursOn( mDate.addDays( -days)) ) {
600 prefix ="<-" ;multiday = 3; 600 prefix ="<-" ;multiday = 3;
601 } 601 }
602 } 602 }
603 603
604 } else { 604 } else {
605 if (mDate == event->dtStart().date()) { 605 if (mDate == event->dtStart().date()) {
606 prefix ="->" ;multiday = 1; 606 prefix ="->" ;multiday = 1;
607 } else if (mDate == event->dtEnd().date()) { 607 } else if (mDate == event->dtEnd().date()) {
608 prefix ="<-" ;multiday = 3; 608 prefix ="<-" ;multiday = 3;
609 } 609 }
610 } 610 }
611 if ( !event->doesFloat() ) { 611 if ( !event->doesFloat() ) {
612 if ( mDate == event->dtStart().date () ) 612 if ( mDate == event->dtStart().date () )
613 time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; 613 time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
614 else if ( mDate == event->dtEnd().date () ) 614 else if ( mDate == event->dtEnd().date () )
615 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 615 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
616 616
617 } 617 }
618 text = time + event->summary(); 618 text = time + event->summary();
619 mToolTipText += prefix + text; 619 mToolTipText += prefix + text;
620 } else { 620 } else {
621 if (event->doesFloat()) { 621 if (event->doesFloat()) {
622 text = event->summary(); 622 text = event->summary();
623 mToolTipText += text; 623 mToolTipText += text;
624 } 624 }
625 else { 625 else {
626 text = KGlobal::locale()->formatTime(event->dtStart().time()); 626 text = KGlobal::locale()->formatTime(event->dtStart().time());
627 text += " " + event->summary(); 627 text += " " + event->summary();
628 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 628 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
629 } 629 }
630 } 630 }
631 MonthViewItem *item ; 631 MonthViewItem *item ;
632 if ( mCurrentAvailItem ) { 632 if ( mCurrentAvailItem ) {
633 item = mCurrentAvailItem; 633 item = mCurrentAvailItem;
634 mCurrentAvailItem = (MonthViewItem*) item->next(); 634 mCurrentAvailItem = (MonthViewItem*) item->next();
635 item->recycle( event, mDate, text ); 635 item->recycle( event, mDate, text );
636 } else { 636 } else {
637 if ( mAvailItemList.count() ) { 637 if ( mAvailItemList.count() ) {
638 item = mAvailItemList.first(); 638 item = mAvailItemList.first();
639 mAvailItemList.remove( item ); 639 mAvailItemList.remove( item );
640 item->recycle( event, mDate, text ); 640 item->recycle( event, mDate, text );
641 insertNewItem = true; 641 insertNewItem = true;
642 } else { 642 } else {
643 insertNewItem = true; 643 insertNewItem = true;
644 item = new MonthViewItem( event, mDate, text ); 644 item = new MonthViewItem( event, mDate, text );
645 } 645 }
646 } 646 }
647 QPalette pal; 647 QPalette pal;
648 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { 648 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
649 QStringList categories = event->categories(); 649 QStringList categories = event->categories();
650 QString cat = categories.first(); 650 QString cat = categories.first();
651 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { 651 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
652 pal = getPalette(); 652 pal = getPalette();
653 if (cat.isEmpty()) { 653 if (cat.isEmpty()) {
654 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); 654 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
655 } else { 655 } else {
656 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); 656 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
657 } 657 }
658 658
659 } else { 659 } else {
660 if (cat.isEmpty()) { 660 if (cat.isEmpty()) {
661 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); 661 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
662 } else { 662 } else {
663 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); 663 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
664 } 664 }
665 } 665 }
666 666
667 } else { 667 } else {
668 pal = mStandardPalette ; 668 pal = mStandardPalette ;
669 } 669 }
670 item->setPalette( pal ); 670 item->setPalette( pal );
671 item->setRecur( event->recurrence()->doesRecur() ); 671 item->setRecur( event->recurrence()->doesRecur() );
672 item->setAlarm( event->isAlarmEnabled() && multiday < 2 ); 672 item->setAlarm( event->isAlarmEnabled() && multiday < 2 );
673 item->setMoreInfo( event->description().length() > 0 ); 673 item->setMoreInfo( event->description().length() > 0 );
674#ifdef DESKTOP_VERSION 674#ifdef DESKTOP_VERSION
675 Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, 675 Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails,
676 KOPrefs::instance()->email()); 676 KOPrefs::instance()->email());
677 if ( me != 0 ) { 677 if ( me != 0 ) {
678 if ( me->status() == Attendee::NeedsAction && me->RSVP()) 678 if ( me->status() == Attendee::NeedsAction && me->RSVP())
679 item->setReply(true && multiday < 2); 679 item->setReply(true && multiday < 2);
680 else 680 else
681 item->setReply(false); 681 item->setReply(false);
682 } else 682 } else
683 item->setReply(false); 683 item->setReply(false);
684#endif 684#endif
685 item->setMultiDay( multiday ); 685 item->setMultiDay( multiday );
686 if ( insertNewItem) 686 if ( insertNewItem)
687 insertItem( item ); 687 insertItem( item );
688 mToolTip.append( mToolTipText ); 688 mToolTip.append( mToolTipText );
689} 689}
690void MonthViewCell::insertTodo(Todo *todo) 690void MonthViewCell::insertTodo(Todo *todo)
691{ 691{
692 bool insertNewItem = false; 692 bool insertNewItem = false;
693 setFocusPolicy(WheelFocus); 693 setFocusPolicy(WheelFocus);
694 QString text; 694 QString text;
695 if (todo->hasDueDate()) { 695 if (todo->hasDueDate()) {
696 if (!todo->doesFloat()) { 696 if (!todo->doesFloat()) {
697 text += KGlobal::locale()->formatTime(todo->dtDue().time()); 697 text += KGlobal::locale()->formatTime(todo->dtDue().time());
698 text += " "; 698 text += " ";
699 } 699 }
700 } 700 }
701 text += todo->summary(); 701 text += todo->summary();
702 MonthViewItem *item ; 702 MonthViewItem *item ;
703 if ( mCurrentAvailItem ) { 703 if ( mCurrentAvailItem ) {
704 item = mCurrentAvailItem; 704 item = mCurrentAvailItem;
705 mCurrentAvailItem = (MonthViewItem*) item->next(); 705 mCurrentAvailItem = (MonthViewItem*) item->next();
706 item->recycle( todo, mDate, text ); 706 item->recycle( todo, mDate, text );
707 } else { 707 } else {
708 if ( mAvailItemList.count() ) { 708 if ( mAvailItemList.count() ) {
709 item = mAvailItemList.first(); 709 item = mAvailItemList.first();
710 mAvailItemList.remove( item ); 710 mAvailItemList.remove( item );
711 item->recycle( todo, mDate, text ); 711 item->recycle( todo, mDate, text );
712 insertNewItem = true; 712 insertNewItem = true;
713 } else { 713 } else {
714 insertNewItem = true; 714 insertNewItem = true;
715 item = new MonthViewItem( todo, mDate, text ); 715 item = new MonthViewItem( todo, mDate, text );
716 } 716 }
717 } 717 }
718 //MonthViewItem *item = new MonthViewItem( todo, mDate, text ); 718 //MonthViewItem *item = new MonthViewItem( todo, mDate, text );
719 //item->setPalette( mStandardPalette ); 719 //item->setPalette( mStandardPalette );
720 QPalette pal; 720 QPalette pal;
721 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { 721 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
722 QStringList categories = todo->categories(); 722 QStringList categories = todo->categories();
723 QString cat = categories.first(); 723 QString cat = categories.first();
724 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { 724 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
725 pal = getPalette(); 725 pal = getPalette();
726 if (cat.isEmpty()) { 726 if (cat.isEmpty()) {
727 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); 727 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
728 } else { 728 } else {
729 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); 729 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
730 } 730 }
731 731
732 } else { 732 } else {
733 if (cat.isEmpty()) { 733 if (cat.isEmpty()) {
734 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); 734 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
735 } else { 735 } else {
736 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); 736 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
737 } 737 }
738 } 738 }
739 739
740 } else { 740 } else {
741 pal = mStandardPalette ; 741 pal = mStandardPalette ;
742 } 742 }
743 item->setPalette( pal ); 743 item->setPalette( pal );
744 item->setRecur( todo->recurrence()->doesRecur() ); 744 item->setRecur( todo->recurrence()->doesRecur() );
745 item->setAlarm( todo->isAlarmEnabled() ); 745 item->setAlarm( todo->isAlarmEnabled() );
746 item->setMoreInfo( todo->description().length() > 0 ); 746 item->setMoreInfo( todo->description().length() > 0 );
747 if ( insertNewItem) 747 if ( insertNewItem)
748 insertItem( item ); 748 insertItem( item );
749 mToolTip.append( text ); 749 mToolTip.append( text );
750} 750}
751void MonthViewCell::repaintfinishUpdateCell() 751void MonthViewCell::repaintfinishUpdateCell()
752{ 752{
753 MonthViewItem *mitem = (MonthViewItem*) firstItem (); 753 MonthViewItem *mitem = (MonthViewItem*) firstItem ();
754 while ( mitem ) { 754 while ( mitem ) {
755 mitem->setBlockRepaint( false ); 755 mitem->setBlockRepaint( false );
756 updateItem ( mitem ); 756 updateItem ( mitem );
757 mitem = (MonthViewItem *)mitem->next(); 757 mitem = (MonthViewItem *)mitem->next();
758 } 758 }
759} 759}
760void MonthViewCell::finishUpdateCell() 760void MonthViewCell::finishUpdateCell()
761{ 761{
762 while ( mCurrentAvailItem ) { 762 while ( mCurrentAvailItem ) {
763 MonthViewItem *item = mCurrentAvailItem; 763 MonthViewItem *item = mCurrentAvailItem;
764 mCurrentAvailItem = (MonthViewItem *)item->next(); 764 mCurrentAvailItem = (MonthViewItem *)item->next();
765 mAvailItemList.append( item ); 765 mAvailItemList.append( item );
766 takeItem ( item ); 766 takeItem ( item );
767 } 767 }
768 768
769 769
770#ifdef DESKTOP_VERSION 770#ifdef DESKTOP_VERSION
771 if (mToolTip.count() > 0 ) { 771 if (mToolTip.count() > 0 ) {
772 mToolTip.sort(); 772 mToolTip.sort();
773 QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),""); 773 QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),"");
774 } 774 }
775#endif 775#endif
776 sort(); 776 sort();
777 //setMyPalette(); 777 //setMyPalette();
778 setMyPalette(); 778 setMyPalette();
779 779
780 resizeEvent( 0 ); 780 resizeEvent( 0 );
781 781
782} 782}
783void MonthViewCell::updateCell() 783void MonthViewCell::updateCell()
784{ 784{
785 //qDebug("MonthViewCell::updateCell() "); 785 //qDebug("MonthViewCell::updateCell() ");
786 if ( !mMonthView->isUpdatePossible() ) 786 if ( !mMonthView->isUpdatePossible() )
787 return; 787 return;
788 startUpdateCell(); 788 startUpdateCell();
789 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 789 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
790 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); 790 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true );
791 Event *event; 791 Event *event;
792 for( event = events.first(); event; event = events.next() ) { // for event 792 for( event = events.first(); event; event = events.next() ) { // for event
793 insertEvent(event); 793 insertEvent(event);
794 } 794 }
795 // insert due todos 795 // insert due todos
796 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); 796 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate );
797 Todo *todo; 797 Todo *todo;
798 for(todo = todos.first(); todo; todo = todos.next()) { 798 for(todo = todos.first(); todo; todo = todos.next()) {
799 insertTodo( todo ); 799 insertTodo( todo );
800 } 800 }
801 finishUpdateCell(); 801 finishUpdateCell();
802 // if ( isVisible()) 802 // if ( isVisible())
803 //qApp->processEvents(); 803 //qApp->processEvents();
804} 804}
805 805
806void MonthViewCell::updateConfig( bool bigFont ) // = false 806void MonthViewCell::updateConfig( bool bigFont ) // = false
807{ 807{
808 808
809 if ( bigFont ) { 809 if ( bigFont ) {
810 QFont fo = KOPrefs::instance()->mMonthViewFont; 810 QFont fo = KOPrefs::instance()->mMonthViewFont;
811 int ps = fo.pointSize() + 2; 811 int ps = fo.pointSize() + 2;
812 if ( ps < 18 ) 812 if ( ps < 18 )
813 ps += 2; 813 ps += 2;
814 fo.setPointSize( ps ); 814 fo.setPointSize( ps );
815 setFont( fo ); 815 setFont( fo );
816 } else 816 } else
817 setFont( KOPrefs::instance()->mMonthViewFont ); 817 setFont( KOPrefs::instance()->mMonthViewFont );
818 818
819 QFontMetrics fm( font() ); 819 QFontMetrics fm( font() );
820 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); 820 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 );
821 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); 821 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 );
822 mHolidayPalette = mStandardPalette; 822 mHolidayPalette = mStandardPalette;
823 mPrimaryPalette = mStandardPalette; 823 mPrimaryPalette = mStandardPalette;
824 mNonPrimaryPalette = mStandardPalette; 824 mNonPrimaryPalette = mStandardPalette;
825 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { 825 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) {
826 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); 826 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor );
827 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); 827 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor );
828 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); 828 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark());
829 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); 829 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark());
830 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); 830 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor);
831 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); 831 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor);
832 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); 832 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark());
833 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); 833 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor);
834 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); 834 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor);
835 } 835 }
836 //updateCell(); 836 //updateCell();
837} 837}
838 838
839void MonthViewCell::enableScrollBars( bool enabled ) 839void MonthViewCell::enableScrollBars( bool enabled )
840{ 840{
841 if ( enabled ) { 841 if ( enabled ) {
842 QListBoxItem *fi = firstItem (); 842 QListBoxItem *fi = firstItem ();
843 if (fi ) { 843 if (fi ) {
844 int ihei = fi->height( this ); 844 int ihei = fi->height( this );
845 int hei = numRows () * ihei; 845 int hei = numRows () * ihei;
846 if ( hei < height() - horizontalScrollBar()->height () ) { 846 if ( hei < height() - horizontalScrollBar()->height () ) {
847 setVScrollBarMode(QScrollView::AlwaysOff); 847 setVScrollBarMode(QScrollView::AlwaysOff);
848 } 848 }
849 else 849 else
850 setVScrollBarMode(QScrollView::Auto); 850 setVScrollBarMode(QScrollView::Auto);
851 if ( ihei *3 > height() ) 851 if ( ihei *3 > height() )
852 setHScrollBarMode(QScrollView::AlwaysOff); 852 setHScrollBarMode(QScrollView::AlwaysOff);
853 else 853 else
854 setHScrollBarMode(QScrollView::Auto); 854 setHScrollBarMode(QScrollView::Auto);
855 } else { 855 } else {
856 setVScrollBarMode(QScrollView::Auto); 856 setVScrollBarMode(QScrollView::Auto);
857 setHScrollBarMode(QScrollView::Auto); 857 setHScrollBarMode(QScrollView::Auto);
858 } 858 }
859 } else { 859 } else {
860 setVScrollBarMode(QScrollView::AlwaysOff); 860 setVScrollBarMode(QScrollView::AlwaysOff);
861 setHScrollBarMode(QScrollView::AlwaysOff); 861 setHScrollBarMode(QScrollView::AlwaysOff);
862 } 862 }
863} 863}
864 864
865Incidence *MonthViewCell::selectedIncidence() 865Incidence *MonthViewCell::selectedIncidence()
866{ 866{
867 int index = currentItem(); 867 int index = currentItem();
868 if ( index < 0 ) return 0; 868 if ( index < 0 ) return 0;
869 869
870 MonthViewItem *mitem = 870 MonthViewItem *mitem =
871 static_cast<MonthViewItem *>( item( index ) ); 871 static_cast<MonthViewItem *>( item( index ) );
872 872
873 if ( !mitem ) return 0; 873 if ( !mitem ) return 0;
874 874
875 return mitem->incidence(); 875 return mitem->incidence();
876} 876}
877 877
878QDate MonthViewCell::selectedIncidenceDate() 878QDate MonthViewCell::selectedIncidenceDate()
879{ 879{
880 QDate qd; 880 QDate qd;
881 int index = currentItem(); 881 int index = currentItem();
882 if ( index < 0 ) return qd; 882 if ( index < 0 ) return qd;
883 883
884 MonthViewItem *mitem = 884 MonthViewItem *mitem =
885 static_cast<MonthViewItem *>( item( index ) ); 885 static_cast<MonthViewItem *>( item( index ) );
886 886
887 if ( !mitem ) return qd; 887 if ( !mitem ) return qd;
888 888
889 return mitem->incidenceDate(); 889 return mitem->incidenceDate();
890} 890}
891 891
892void MonthViewCell::deselect() 892void MonthViewCell::deselect()
893{ 893{
894 clearSelection(); 894 clearSelection();
895 enableScrollBars( false ); 895 enableScrollBars( false );
896 // updateCell(); 896 // updateCell();
897} 897}
898void MonthViewCell::select() 898void MonthViewCell::select()
899{ 899{
900 ;// updateCell(); 900 ;// updateCell();
901} 901}
902 902
903void MonthViewCell::resizeEvent ( QResizeEvent * e ) 903void MonthViewCell::resizeEvent ( QResizeEvent * e )
904{ 904{
905 if ( !mMonthView->isUpdatePossible() ) 905 if ( !mMonthView->isUpdatePossible() )
906 return; 906 return;
907 //qDebug("++++++++++++++MonthViewCell::resizeEvent %d %d ", width(), height()); 907 //qDebug("++++++++++++++MonthViewCell::resizeEvent %d %d ", width(), height());
908 deselect(); 908 deselect();
909 mLabel->setMaximumHeight( height() - lineWidth()*2 ); 909 mLabel->setMaximumHeight( height() - lineWidth()*2 );
910 910
911 QString text; 911 QString text;
912 mLabel->setText( text ); 912 mLabel->setText( text );
913 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; 913 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog;
914 if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { 914 if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) {
915 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " "; 915 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " ";
916 mLabel->resize( mLabelBigSize ); 916 mLabel->resize( mLabelBigSize );
917 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 917 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
918 } else { 918 } else {
919 mLabel->resize( mLabelSize ); 919 mLabel->resize( mLabelSize );
920 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 920 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
921 } 921 }
922 mLabel->setText( text ); 922 mLabel->setText( text );
923 923
924 int size = height() - mLabel->height() - lineWidth()-1; 924 int size = height() - mLabel->height() - lineWidth()-1;
925 //qDebug("LW %d ", lineWidth()); 925 //qDebug("LW %d ", lineWidth());
926 if ( size > 0 ) 926 if ( size > 0 )
927 verticalScrollBar()->setMaximumHeight( size ); 927 verticalScrollBar()->setMaximumHeight( size );
928 size = width() - mLabel->width() -lineWidth()-1; 928 size = width() - mLabel->width() -lineWidth()-1;
929 if ( size > 0 ) 929 if ( size > 0 )
930 horizontalScrollBar()->setMaximumWidth( size ); 930 horizontalScrollBar()->setMaximumWidth( size );
931 mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() ); 931 mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() );
932 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 932 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
933 // mItemList->resize ( width(), height () ); 933 // mItemList->resize ( width(), height () );
934 if ( e ) 934 if ( e )
935 KNoScrollListBox::resizeEvent ( e ); 935 KNoScrollListBox::resizeEvent ( e );
936} 936}
937 937
938void MonthViewCell::defaultAction( QListBoxItem *item ) 938void MonthViewCell::defaultAction( QListBoxItem *item )
939{ 939{
940 if ( !item ) return; 940 if ( !item ) {
941 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
942 emit newEventSignal( dt );
943 return;
944 }
941 945
942 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 946 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
943 Incidence *incidence = eventItem->incidence(); 947 Incidence *incidence = eventItem->incidence();
944 if ( incidence ) mMonthView->defaultAction( incidence ); 948 if ( incidence ) mMonthView->defaultAction( incidence );
945} 949}
946void MonthViewCell::showDay() 950void MonthViewCell::showDay()
947{ 951{
948 emit showDaySignal( date() ); 952 emit showDaySignal( date() );
949} 953}
950void MonthViewCell::newEvent() 954void MonthViewCell::newEvent()
951{ 955{
952 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 956 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
953 emit newEventSignal( dt ); 957 emit newEventSignal( dt );
954} 958}
955void MonthViewCell::cellClicked( QListBoxItem *item ) 959void MonthViewCell::cellClicked( QListBoxItem *item )
956{ 960{
957 static QListBoxItem * lastClicked = 0; 961 static QListBoxItem * lastClicked = 0;
958 if ( item == 0 ) { 962 if ( item == 0 ) {
959 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 963 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
960 emit newEventSignal( dt ); 964 emit newEventSignal( dt );
961 return; 965 return;
962 } 966 }
963 /* 967 /*
964 if ( lastClicked ) 968 if ( lastClicked )
965 if ( ! item ) { 969 if ( ! item ) {
966 if ( lastClicked->listBox() != item->listBox() ) 970 if ( lastClicked->listBox() != item->listBox() )
967 lastClicked->listBox()->clearSelection(); 971 lastClicked->listBox()->clearSelection();
968 } 972 }
969 */ 973 */
970 974
971 mMonthView->setSelectedCell( this ); 975 mMonthView->setSelectedCell( this );
972 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true ); 976 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true );
973 select(); 977 select();
974} 978}
975 979
976void MonthViewCell::contextMenu( QListBoxItem *item ) 980void MonthViewCell::contextMenu( QListBoxItem *item )
977{ 981{
978 if ( !item ) return; 982 if ( !item ) return;
979 983
980 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 984 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
981 Incidence *incidence = eventItem->incidence(); 985 Incidence *incidence = eventItem->incidence();
982 if ( incidence ) mMonthView->showContextMenu( incidence ); 986 if ( incidence ) mMonthView->showContextMenu( incidence );
983} 987}
984 988
985void MonthViewCell::selection( QListBoxItem *item ) 989void MonthViewCell::selection( QListBoxItem *item )
986{ 990{
987 if ( !item ) return; 991 if ( !item ) return;
988 992
989 mMonthView->setSelectedCell( this ); 993 mMonthView->setSelectedCell( this );
990} 994}
991 995
992 996
993// ******************************************************************************* 997// *******************************************************************************
994// ******************************************************************************* 998// *******************************************************************************
995// ******************************************************************************* 999// *******************************************************************************
996 1000
997 1001
998KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) 1002KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name)
999 : KOEventView( calendar, parent, name ), 1003 : KOEventView( calendar, parent, name ),
1000 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), 1004 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
1001 mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) 1005 mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
1002{ 1006{
1003 mFlagKeyPressed = false; 1007 mFlagKeyPressed = false;
1004 mShortDayLabelsM = false; 1008 mShortDayLabelsM = false;
1005 mShortDayLabelsW = false; 1009 mShortDayLabelsW = false;
1006 skipResize = false; 1010 skipResize = false;
1007 clPending = true; 1011 clPending = true;
1008 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); 1012 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" );
1009 mWidStack = new QWidgetStack( this ); 1013 mWidStack = new QWidgetStack( this );
1010 QVBoxLayout* hb = new QVBoxLayout( this ); 1014 QVBoxLayout* hb = new QVBoxLayout( this );
1011 mMonthView = new QWidget( mWidStack ); 1015 mMonthView = new QWidget( mWidStack );
1012 mWeekView = new QWidget( mWidStack ); 1016 mWeekView = new QWidget( mWidStack );
1013#if QT_VERSION >= 0x030000 1017#if QT_VERSION >= 0x030000
1014 mWidStack->addWidget(mMonthView ); 1018 mWidStack->addWidget(mMonthView );
1015 mWidStack->addWidget(mWeekView ); 1019 mWidStack->addWidget(mWeekView );
1016#else 1020#else
1017 mWidStack->addWidget( mMonthView, 1 ); 1021 mWidStack->addWidget( mMonthView, 1 );
1018 mWidStack->addWidget( mWeekView , 1 ); 1022 mWidStack->addWidget( mWeekView , 1 );
1019#endif 1023#endif
1020 hb->addWidget( mNavigatorBar ); 1024 hb->addWidget( mNavigatorBar );
1021 hb->addWidget( mWidStack ); 1025 hb->addWidget( mWidStack );
1022 mShowWeekView = KOPrefs::instance()->mMonthViewWeek; 1026 mShowWeekView = KOPrefs::instance()->mMonthViewWeek;
1023 updatePossible = false; 1027 updatePossible = false;
1024 //updatePossible = true; 1028 //updatePossible = true;
1025 mCells.setAutoDelete( true ); 1029 mCells.setAutoDelete( true );
1026 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 1030 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
1027 mDayLabels.resize( mDaysPerWeek ); 1031 mDayLabels.resize( mDaysPerWeek );
1028 mDayLabelsW.resize( mDaysPerWeek ); 1032 mDayLabelsW.resize( mDaysPerWeek );
1029 QFont bfont = font(); 1033 QFont bfont = font();
1030 if ( QApplication::desktop()->width() < 650 ) { 1034 if ( QApplication::desktop()->width() < 650 ) {
1031 bfont.setPointSize( bfont.pointSize() - 2 ); 1035 bfont.setPointSize( bfont.pointSize() - 2 );
1032 } 1036 }
1033 bfont.setBold( true ); 1037 bfont.setBold( true );
1034 int i; 1038 int i;
1035 1039
1036 for( i = 0; i < mDaysPerWeek; i++ ) { 1040 for( i = 0; i < mDaysPerWeek; i++ ) {
1037 QLabel *label = new QLabel( mMonthView ); 1041 QLabel *label = new QLabel( mMonthView );
1038 label->setFont(bfont); 1042 label->setFont(bfont);
1039 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1043 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1040 label->setLineWidth(1); 1044 label->setLineWidth(1);
1041 label->setAlignment(AlignCenter); 1045 label->setAlignment(AlignCenter);
1042 mDayLabels.insert( i, label ); 1046 mDayLabels.insert( i, label );
1043 label = new QLabel( mWeekView ); 1047 label = new QLabel( mWeekView );
1044 label->setFont(bfont); 1048 label->setFont(bfont);
1045 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1049 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1046 label->setLineWidth(1); 1050 label->setLineWidth(1);
1047 label->setAlignment(AlignCenter); 1051 label->setAlignment(AlignCenter);
1048 mDayLabelsW.insert( i, label ); 1052 mDayLabelsW.insert( i, label );
1049 } 1053 }
1050 1054
1051 bfont.setBold( false ); 1055 bfont.setBold( false );
1052 mWeekLabels.resize( mNumWeeks+1 ); 1056 mWeekLabels.resize( mNumWeeks+1 );
1053 mWeekLabelsW.resize( 2 ); 1057 mWeekLabelsW.resize( 2 );
1054 for( i = 0; i < mNumWeeks+1; i++ ) { 1058 for( i = 0; i < mNumWeeks+1; i++ ) {
1055 KOWeekButton *label = new KOWeekButton( mMonthView ); 1059 KOWeekButton *label = new KOWeekButton( mMonthView );
1056 label->setFocusPolicy(NoFocus); 1060 label->setFocusPolicy(NoFocus);
1057 label->setFont(bfont); 1061 label->setFont(bfont);
1058 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 1062 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
1059 label->setFlat(true); 1063 label->setFlat(true);
1060 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 1064 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
1061 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1065 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1062 //label->setLineWidth(1); 1066 //label->setLineWidth(1);
1063 //label->setAlignment(AlignCenter); 1067 //label->setAlignment(AlignCenter);
1064 mWeekLabels.insert( i, label ); 1068 mWeekLabels.insert( i, label );
1065 } 1069 }
1066 mWeekLabels[mNumWeeks]->setText( i18n("W")); 1070 mWeekLabels[mNumWeeks]->setText( i18n("W"));
1067 mWeekLabels[0]->setFocusPolicy(WheelFocus); 1071 mWeekLabels[0]->setFocusPolicy(WheelFocus);
1068 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number")); 1072 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number"));
1069 1073
1070 for( i = 0; i < 1+1; i++ ) { 1074 for( i = 0; i < 1+1; i++ ) {
1071 KOWeekButton *label = new KOWeekButton( mWeekView ); 1075 KOWeekButton *label = new KOWeekButton( mWeekView );
1072 label->setFocusPolicy(NoFocus); 1076 label->setFocusPolicy(NoFocus);
1073 label->setFont(bfont); 1077 label->setFont(bfont);
1074 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 1078 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
1075 label->setFlat(true); 1079 label->setFlat(true);
1076 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 1080 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
1077 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1081 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1078 //label->setLineWidth(1); 1082 //label->setLineWidth(1);
1079 //label->setAlignment(AlignCenter); 1083 //label->setAlignment(AlignCenter);
1080 mWeekLabelsW.insert( i, label ); 1084 mWeekLabelsW.insert( i, label );
1081 } 1085 }
1082 mWeekLabelsW[1]->setText( i18n("W")); 1086 mWeekLabelsW[1]->setText( i18n("W"));
1083 mWeekLabelsW[0]->setFocusPolicy(WheelFocus); 1087 mWeekLabelsW[0]->setFocusPolicy(WheelFocus);
1084 1088
1085 1089
1086 int row, col; 1090 int row, col;
1087 mCells.resize( mNumCells ); 1091 mCells.resize( mNumCells );
1088 for( row = 0; row < mNumWeeks; ++row ) { 1092 for( row = 0; row < mNumWeeks; ++row ) {
1089 for( col = 0; col < mDaysPerWeek; ++col ) { 1093 for( col = 0; col < mDaysPerWeek; ++col ) {
1090 MonthViewCell *cell = new MonthViewCell( this, mMonthView ); 1094 MonthViewCell *cell = new MonthViewCell( this, mMonthView );
1091 mCells.insert( row * mDaysPerWeek + col, cell ); 1095 mCells.insert( row * mDaysPerWeek + col, cell );
1092 1096
1093 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 1097 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
1094 SLOT( defaultAction( Incidence * ) ) ); 1098 SLOT( defaultAction( Incidence * ) ) );
1095 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 1099 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
1096 SIGNAL( newEventSignal( QDateTime ) ) ); 1100 SIGNAL( newEventSignal( QDateTime ) ) );
1097 connect( cell, SIGNAL( showDaySignal( QDate ) ), 1101 connect( cell, SIGNAL( showDaySignal( QDate ) ),
1098 SIGNAL( showDaySignal( QDate ) ) ); 1102 SIGNAL( showDaySignal( QDate ) ) );
1099 } 1103 }
1100 } 1104 }
1101 mCellsW.resize( mDaysPerWeek ); 1105 mCellsW.resize( mDaysPerWeek );
1102 for( col = 0; col < mDaysPerWeek; ++col ) { 1106 for( col = 0; col < mDaysPerWeek; ++col ) {
1103 MonthViewCell *cell = new MonthViewCell( this, mWeekView ); 1107 MonthViewCell *cell = new MonthViewCell( this, mWeekView );
1104 mCellsW.insert( col, cell ); 1108 mCellsW.insert( col, cell );
1105 1109
1106 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 1110 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
1107 SLOT( defaultAction( Incidence * ) ) ); 1111 SLOT( defaultAction( Incidence * ) ) );
1108 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 1112 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
1109 SIGNAL( newEventSignal( QDateTime ) ) ); 1113 SIGNAL( newEventSignal( QDateTime ) ) );
1110 connect( cell, SIGNAL( showDaySignal( QDate ) ), 1114 connect( cell, SIGNAL( showDaySignal( QDate ) ),
1111 SIGNAL( showDaySignal( QDate ) ) ); 1115 SIGNAL( showDaySignal( QDate ) ) );
1112 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); 1116 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont );
1113 } 1117 }
1114 1118
1115 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); 1119 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) );
1116 mContextMenu = eventPopup(); 1120 mContextMenu = eventPopup();
1117 // updateConfig(); //useless here... 1121 // updateConfig(); //useless here...
1118 // ... but we need mWidthLongDayLabel computed 1122 // ... but we need mWidthLongDayLabel computed
1119 QFontMetrics fontmetric(mDayLabels[0]->font()); 1123 QFontMetrics fontmetric(mDayLabels[0]->font());
1120 mWidthLongDayLabel = 0; 1124 mWidthLongDayLabel = 0;
1121 for (int i = 0; i < 7; i++) { 1125 for (int i = 0; i < 7; i++) {
1122 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 1126 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
1123 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 1127 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
1124 } 1128 }
1125 1129
1126 //mWeekLabels[mNumWeeks]->setText( i18n("W")); 1130 //mWeekLabels[mNumWeeks]->setText( i18n("W"));
1127 1131
1128#if 0 1132#if 0
1129 if ( mShowWeekView ) 1133 if ( mShowWeekView )
1130 mWidStack->raiseWidget( mWeekView ); 1134 mWidStack->raiseWidget( mWeekView );
1131 else 1135 else
1132 mWidStack->raiseWidget( mMonthView ); 1136 mWidStack->raiseWidget( mMonthView );
1133#endif 1137#endif
1134 1138
1135 emit incidenceSelected( 0 ); 1139 emit incidenceSelected( 0 );
1136 1140
1137 mComputeLayoutTimer = new QTimer( this ); 1141 mComputeLayoutTimer = new QTimer( this );
1138 connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout())); 1142 connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout()));
1139 1143
1140 1144
1141#ifndef DESKTOP_VERSION 1145#ifndef DESKTOP_VERSION
1142 resize( QApplication::desktop()->size() ); 1146 resize( QApplication::desktop()->size() );
1143#else 1147#else
1144 resize(640, 480 ); 1148 resize(640, 480 );
1145 updatePossible = true; 1149 updatePossible = true;
1146#endif 1150#endif
1147 computeLayout(); 1151 computeLayout();
1148 1152
1149 if ( mShowWeekView ) 1153 if ( mShowWeekView )
1150 mWidStack->raiseWidget( mWeekView ); 1154 mWidStack->raiseWidget( mWeekView );
1151 else 1155 else
1152 mWidStack->raiseWidget( mMonthView ); 1156 mWidStack->raiseWidget( mMonthView );
1153} 1157}
1154 1158
1155KOMonthView::~KOMonthView() 1159KOMonthView::~KOMonthView()
1156{ 1160{
1157 delete mContextMenu; 1161 delete mContextMenu;
1158} 1162}
1159 1163
1160void KOMonthView::selectInternalWeekNum ( int n ) 1164void KOMonthView::selectInternalWeekNum ( int n )
1161{ 1165{
1162 switchView(); 1166 switchView();
1163 if ( !KOPrefs::instance()->mMonthViewWeek ) 1167 if ( !KOPrefs::instance()->mMonthViewWeek )
1164 emit selectMonth (); 1168 emit selectMonth ();
1165 else 1169 else
1166 emit selectWeekNum ( n ); 1170 emit selectWeekNum ( n );
1167} 1171}
1168 1172
1169int KOMonthView::currentWeek() 1173int KOMonthView::currentWeek()
1170{ 1174{
1171 if ( mShowWeekView ) 1175 if ( mShowWeekView )
1172 return mWeekLabelsW[0]->getWeekNum(); 1176 return mWeekLabelsW[0]->getWeekNum();
1173 return mWeekLabels[0]->getWeekNum(); 1177 return mWeekLabels[0]->getWeekNum();
1174} 1178}
1175void KOMonthView::switchView() 1179void KOMonthView::switchView()
1176{ 1180{
1177 if ( selectedCell( ) ) 1181 if ( selectedCell( ) )
1178 selectedCell()->deselect(); 1182 selectedCell()->deselect();
1179 mShowWeekView = !mShowWeekView; 1183 mShowWeekView = !mShowWeekView;
1180 KOPrefs::instance()->mMonthViewWeek = mShowWeekView; 1184 KOPrefs::instance()->mMonthViewWeek = mShowWeekView;
1181 if ( clPending ) { 1185 if ( clPending ) {
1182 computeLayout(); 1186 computeLayout();
1183 updateConfig(); 1187 updateConfig();
1184 } 1188 }
1185 if ( mShowWeekView ) 1189 if ( mShowWeekView )
1186 mWidStack->raiseWidget( mWeekView ); 1190 mWidStack->raiseWidget( mWeekView );
1187 else 1191 else
1188 mWidStack->raiseWidget( mMonthView ); 1192 mWidStack->raiseWidget( mMonthView );
1189 clPending = false; 1193 clPending = false;
1190} 1194}
1191 1195
1192int KOMonthView::maxDatesHint() 1196int KOMonthView::maxDatesHint()
1193{ 1197{
1194 return mNumCells; 1198 return mNumCells;
1195} 1199}
1196 1200
1197int KOMonthView::currentDateCount() 1201int KOMonthView::currentDateCount()
1198{ 1202{
1199 return mNumCells; 1203 return mNumCells;
1200} 1204}
1201 1205
1202QPtrList<Incidence> KOMonthView::selectedIncidences() 1206QPtrList<Incidence> KOMonthView::selectedIncidences()
1203{ 1207{
1204 QPtrList<Incidence> selected; 1208 QPtrList<Incidence> selected;
1205 1209
1206 if ( mSelectedCell ) { 1210 if ( mSelectedCell ) {
1207 Incidence *incidence = mSelectedCell->selectedIncidence(); 1211 Incidence *incidence = mSelectedCell->selectedIncidence();
1208 if ( incidence ) selected.append( incidence ); 1212 if ( incidence ) selected.append( incidence );
1209 } 1213 }
1210 1214
1211 return selected; 1215 return selected;
1212} 1216}
1213 1217
1214DateList KOMonthView::selectedDates() 1218DateList KOMonthView::selectedDates()
1215{ 1219{
1216 DateList selected; 1220 DateList selected;
1217 1221
1218 if ( mSelectedCell ) { 1222 if ( mSelectedCell ) {
1219 QDate qd = mSelectedCell->selectedIncidenceDate(); 1223 QDate qd = mSelectedCell->selectedIncidenceDate();
1220 if ( qd.isValid() ) selected.append( qd ); 1224 if ( qd.isValid() ) selected.append( qd );
1221 } 1225 }
1222 1226
1223 return selected; 1227 return selected;
1224} 1228}
1225 1229
1226void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1230void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1227 const QDate &td) 1231 const QDate &td)
1228{ 1232{
1229#ifndef KORG_NOPRINTER 1233#ifndef KORG_NOPRINTER
1230 calPrinter->preview(CalPrinter::Month, fd, td); 1234 calPrinter->preview(CalPrinter::Month, fd, td);
1231#endif 1235#endif
1232} 1236}
1233 1237
1234void KOMonthView::updateConfig() 1238void KOMonthView::updateConfig()
1235{ 1239{
1236 1240
1237 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 1241 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
1238 1242
1239 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { 1243 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) {
1240 mWeekStartsMonday = true; 1244 mWeekStartsMonday = true;
1241 } 1245 }
1242 QFontMetrics fontmetric(mDayLabels[0]->font()); 1246 QFontMetrics fontmetric(mDayLabels[0]->font());
1243 mWidthLongDayLabel = 0; 1247 mWidthLongDayLabel = 0;
1244 1248
1245 for (int i = 0; i < 7; i++) { 1249 for (int i = 0; i < 7; i++) {
1246 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 1250 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
1247 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 1251 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
1248 } 1252 }
1249 bool temp = mShowSatSunComp ; 1253 bool temp = mShowSatSunComp ;
1250 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 1254 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
1251 if ( ! mShowWeekView ) { 1255 if ( ! mShowWeekView ) {
1252 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) 1256 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog )
1253 computeLayout(); 1257 computeLayout();
1254 } 1258 }
1255 updateDayLabels(); 1259 updateDayLabels();
1256 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); 1260 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks);
1257 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; 1261 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks;
1258 //resizeEvent( 0 ); 1262 //resizeEvent( 0 );
1259 for (uint i = 0; i < mCells.count(); ++i) { 1263 for (uint i = 0; i < mCells.count(); ++i) {
1260 mCells[i]->updateConfig(); 1264 mCells[i]->updateConfig();
1261 } 1265 }
1262 1266
1263 for (uint i = 0; i < mCellsW.count(); ++i) { 1267 for (uint i = 0; i < mCellsW.count(); ++i) {
1264 mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont); 1268 mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont);
1265 } 1269 }
1266#ifdef DESKTOP_VERSION 1270#ifdef DESKTOP_VERSION
1267 MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); 1271 MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips);
1268#endif 1272#endif
1269 updateView(); 1273 updateView();
1270} 1274}
1271 1275
1272void KOMonthView::updateDayLabels() 1276void KOMonthView::updateDayLabels()
1273{ 1277{
1274 1278
1275 QPtrVector<QLabel> *mDayLabelsT; 1279 QPtrVector<QLabel> *mDayLabelsT;
1276 1280
1277 mDayLabelsT = &mDayLabelsW; 1281 mDayLabelsT = &mDayLabelsW;
1278 for (int i = 0; i < 7; i++) { 1282 for (int i = 0; i < 7; i++) {
1279 { 1283 {
1280 bool show = mShortDayLabelsW; 1284 bool show = mShortDayLabelsW;
1281 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) 1285 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
1282 show = true; 1286 show = true;
1283 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); 1287 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
1284 } 1288 }
1285 } 1289 }
1286 mDayLabelsT = &mDayLabels; 1290 mDayLabelsT = &mDayLabels;
1287 for (int i = 0; i < 7; i++) { 1291 for (int i = 0; i < 7; i++) {
1288 if (KGlobal::locale()->weekStartsMonday() || KOPrefs::instance()->mMonthViewSatSunTog ) { 1292 if (KGlobal::locale()->weekStartsMonday() || KOPrefs::instance()->mMonthViewSatSunTog ) {
1289 bool show = mShortDayLabelsM; 1293 bool show = mShortDayLabelsM;
1290 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) 1294 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
1291 show = true; 1295 show = true;
1292 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); 1296 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
1293 } else { 1297 } else {
1294 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM)); 1298 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM));
1295 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM)); 1299 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM));
1296 1300
1297 } 1301 }
1298 } 1302 }
1299 1303
1300} 1304}
1301 1305
1302void KOMonthView::showDates(const QDate &start, const QDate &) 1306void KOMonthView::showDates(const QDate &start, const QDate &)
1303{ 1307{
1304 // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; 1308 // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl;
1305 1309
1306 QPtrVector<MonthViewCell> *cells; 1310 QPtrVector<MonthViewCell> *cells;
1307 QPtrVector<QLabel> *dayLabels; 1311 QPtrVector<QLabel> *dayLabels;
1308 QPtrVector<KOWeekButton> *weekLabels; 1312 QPtrVector<KOWeekButton> *weekLabels;
1309 int weekNum = 6; 1313 int weekNum = 6;
1310 mStartDate = start; 1314 mStartDate = start;
1311 if ( mShowWeekView ) { 1315 if ( mShowWeekView ) {
1312 weekNum = 1; 1316 weekNum = 1;
1313 cells = &mCellsW; 1317 cells = &mCellsW;
1314 dayLabels = &mDayLabelsW; 1318 dayLabels = &mDayLabelsW;
1315 weekLabels = &mWeekLabelsW; 1319 weekLabels = &mWeekLabelsW;
1316 if ( !KGlobal::locale()->weekStartsMonday() ) { 1320 if ( !KGlobal::locale()->weekStartsMonday() ) {
1317 mStartDate = mStartDate.addDays( 1 ); 1321 mStartDate = mStartDate.addDays( 1 );
1318 } 1322 }
1319 } else { 1323 } else {
1320 cells = &mCells; 1324 cells = &mCells;
1321 dayLabels = &mDayLabels; 1325 dayLabels = &mDayLabels;
1322 weekLabels = &mWeekLabels; 1326 weekLabels = &mWeekLabels;
1323 } 1327 }
1324 1328
1325 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 1329 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
1326 1330
1327 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { 1331 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) {
1328 mWeekStartsMonday = true; 1332 mWeekStartsMonday = true;
1329 } 1333 }
1330 int startWeekDay = mWeekStartsMonday ? 1 : 7; 1334 int startWeekDay = mWeekStartsMonday ? 1 : 7;
1331 1335
1332 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { 1336 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) {
1333 mStartDate = mStartDate.addDays( -1 ); 1337 mStartDate = mStartDate.addDays( -1 );
1334 } 1338 }
1335 bool primary = false; 1339 bool primary = false;
1336 uint i; 1340 uint i;
1337 for( i = 0; i < (*cells).size(); ++i ) { 1341 for( i = 0; i < (*cells).size(); ++i ) {
1338 QDate date = mStartDate.addDays( i ); 1342 QDate date = mStartDate.addDays( i );
1339 (*cells)[i]->setDate( date ); 1343 (*cells)[i]->setDate( date );
1340 1344
1341#ifndef KORG_NOPLUGINS 1345#ifndef KORG_NOPLUGINS
1342 // add holiday, if present 1346 // add holiday, if present
1343 QString hstring(KOCore::self()->holiday(date)); 1347 QString hstring(KOCore::self()->holiday(date));
1344 (*cells)[i]->setHoliday( hstring ); 1348 (*cells)[i]->setHoliday( hstring );
1345#endif 1349#endif
1346 1350
1347 } 1351 }
1348 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); 1352 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 );
1349 for( i = 0; i < weekNum; ++i ) { 1353 for( i = 0; i < weekNum; ++i ) {
1350 int wno; 1354 int wno;
1351 // remember, according to ISO 8601, the first week of the year is the 1355 // remember, according to ISO 8601, the first week of the year is the
1352 // first week that contains a thursday. Thus we must subtract off 4, 1356 // first week that contains a thursday. Thus we must subtract off 4,
1353 // not just 1. 1357 // not just 1.
1354 int dayOfYear = date.dayOfYear(); 1358 int dayOfYear = date.dayOfYear();
1355 if (dayOfYear % 7 != 0) 1359 if (dayOfYear % 7 != 0)
1356 wno = dayOfYear / 7 + 1; 1360 wno = dayOfYear / 7 + 1;
1357 else 1361 else
1358 wno =dayOfYear / 7; 1362 wno =dayOfYear / 7;
1359 (*weekLabels)[i]->setWeekNum( wno ); 1363 (*weekLabels)[i]->setWeekNum( wno );
1360 date = date.addDays( 7 ); 1364 date = date.addDays( 7 );
1361 } 1365 }
1362 updateView(); 1366 updateView();
1363} 1367}
1364 1368
1365void KOMonthView::showEvents(QPtrList<Event>) 1369void KOMonthView::showEvents(QPtrList<Event>)
1366{ 1370{
1367 qDebug("KOMonthView::selectEvents is not implemented yet. "); 1371 qDebug("KOMonthView::selectEvents is not implemented yet. ");
1368} 1372}
1369 1373
1370void KOMonthView::changeEventDisplay(Event *, int) 1374void KOMonthView::changeEventDisplay(Event *, int)
1371{ 1375{
1372 // this should be re-written to be much more efficient, but this 1376 // this should be re-written to be much more efficient, but this
1373 // quick-and-dirty-hack gets the job done for right now. 1377 // quick-and-dirty-hack gets the job done for right now.
1378 qDebug("KOMonthView::changeEventDisplay ");
1374 updateView(); 1379 updateView();
1375} 1380}
1376 1381
1377void KOMonthView::updateView() 1382void KOMonthView::updateView()
1378{ 1383{
1379 1384
1380 if ( !updatePossible ) 1385 if ( !updatePossible )
1381 return; 1386 return;
1382 //qDebug("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU "); 1387 //qDebug("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU ");
1383 //QTime ti; 1388 //QTime ti;
1384 //ti.start(); 1389 //ti.start();
1385 clearSelection(); 1390 clearSelection();
1386 QPtrVector<MonthViewCell> *cells; 1391 QPtrVector<MonthViewCell> *cells;
1387 if ( mShowWeekView ) { 1392 if ( mShowWeekView ) {
1388 cells = &mCellsW; 1393 cells = &mCellsW;
1389 } else { 1394 } else {
1390 cells = &mCells; 1395 cells = &mCells;
1391 } 1396 }
1392#if 1 1397#if 1
1393 int i; 1398 int i;
1394 int timeSpan = (*cells).size()-1; 1399 int timeSpan = (*cells).size()-1;
1395 if ( KOPrefs::instance()->mMonthViewWeek ) 1400 if ( KOPrefs::instance()->mMonthViewWeek )
1396 timeSpan = 6; 1401 timeSpan = 6;
1397 for( i = 0; i < timeSpan + 1; ++i ) { 1402 for( i = 0; i < timeSpan + 1; ++i ) {
1398 (*cells)[i]->startUpdateCell(); 1403 (*cells)[i]->startUpdateCell();
1399 } 1404 }
1400 1405
1401 QPtrList<Event> events = calendar()->events(); 1406 QPtrList<Event> events = calendar()->events();
1402 Event *event; 1407 Event *event;
1403 QDateTime dt; 1408 QDateTime dt;
1404 bool ok; 1409 bool ok;
1405 QDate endDate = mStartDate.addDays( timeSpan ); 1410 QDate endDate = mStartDate.addDays( timeSpan );
1406 for( event = events.first(); event; event = events.next() ) { // for event 1411 for( event = events.first(); event; event = events.next() ) { // for event
1407 if ( event->doesRecur() ) { 1412 if ( event->doesRecur() ) {
1408 bool last; 1413 bool last;
1409 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); 1414 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last );
1410 QDateTime incidenceEnd; 1415 QDateTime incidenceEnd;
1411 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); 1416 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() );
1412 bool invalid = false; 1417 bool invalid = false;
1413 while( true ) { 1418 while( true ) {
1414 if ( incidenceStart.isValid() ) { 1419 if ( incidenceStart.isValid() ) {
1415 incidenceEnd = incidenceStart.addDays( eventlen ); 1420 incidenceEnd = incidenceStart.addDays( eventlen );
1416 int st = incidenceStart.date().daysTo( endDate ); 1421 int st = incidenceStart.date().daysTo( endDate );
1417 if ( st >= 0 ) { // start before timeend 1422 if ( st >= 0 ) { // start before timeend
1418 int end = mStartDate.daysTo( incidenceEnd.date() ); 1423 int end = mStartDate.daysTo( incidenceEnd.date() );
1419 if ( end >= 0 ) { // end after timestart --- got one! 1424 if ( end >= 0 ) { // end after timestart --- got one!
1420 //normalize 1425 //normalize
1421 st = timeSpan - st; 1426 st = timeSpan - st;
1422 if ( st < 0 ) st = 0; 1427 if ( st < 0 ) st = 0;
1423 if ( end > timeSpan ) end = timeSpan; 1428 if ( end > timeSpan ) end = timeSpan;
1424 int iii; 1429 int iii;
1425 //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); 1430 //qDebug("found %s %d %d ",event->summary().latin1(), st, end );
1426 for ( iii = st;iii<= end;++iii) 1431 for ( iii = st;iii<= end;++iii)
1427 (*cells)[iii]->insertEvent( event ); 1432 (*cells)[iii]->insertEvent( event );
1428 } 1433 }
1429 } 1434 }
1430 } else { 1435 } else {
1431 if ( invalid ) 1436 if ( invalid )
1432 break; 1437 break;
1433 invalid = true; 1438 invalid = true;
1434 //qDebug("invalid %s", event->summary().latin1()); 1439 //qDebug("invalid %s", event->summary().latin1());
1435 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; 1440 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );;
1436 } 1441 }
1437 if ( last ) 1442 if ( last )
1438 break; 1443 break;
1439 bool ok; 1444 bool ok;
1440 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); 1445 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok );
1441 if ( ! ok ) 1446 if ( ! ok )
1442 break; 1447 break;
1443 if ( incidenceStart.date() > endDate ) 1448 if ( incidenceStart.date() > endDate )
1444 break; 1449 break;
1445 } 1450 }
1446 } else { // no recur 1451 } else { // no recur
1447 int st = event->dtStart().date().daysTo( endDate ); 1452 int st = event->dtStart().date().daysTo( endDate );
1448 if ( st >= 0 ) { // start before timeend 1453 if ( st >= 0 ) { // start before timeend
1449 int end = mStartDate.daysTo( event->dtEnd().date() ); 1454 int end = mStartDate.daysTo( event->dtEnd().date() );
1450 if ( end >= 0 ) { // end after timestart --- got one! 1455 if ( end >= 0 ) { // end after timestart --- got one!
1451 //normalize 1456 //normalize
1452 st = timeSpan - st; 1457 st = timeSpan - st;
1453 if ( st < 0 ) st = 0; 1458 if ( st < 0 ) st = 0;
1454 if ( end > timeSpan ) end = timeSpan; 1459 if ( end > timeSpan ) end = timeSpan;
1455 int iii; 1460 int iii;
1456 for ( iii = st;iii<= end;++iii) 1461 for ( iii = st;iii<= end;++iii)
1457 (*cells)[iii]->insertEvent( event ); 1462 (*cells)[iii]->insertEvent( event );
1458 } 1463 }
1459 } 1464 }
1460 } 1465 }
1461 } 1466 }
1462 // insert due todos 1467 // insert due todos
1463 QPtrList<Todo> todos = calendar()->todos( ); 1468 QPtrList<Todo> todos = calendar()->todos( );
1464 Todo *todo; 1469 Todo *todo;
1465 for(todo = todos.first(); todo; todo = todos.next()) { 1470 for(todo = todos.first(); todo; todo = todos.next()) {
1466 //insertTodo( todo ); 1471 //insertTodo( todo );
1467 if ( todo->hasDueDate() ) { 1472 if ( todo->hasDueDate() ) {
1468 int day = mStartDate.daysTo( todo->dtDue().date() ); 1473 int day = mStartDate.daysTo( todo->dtDue().date() );
1469 if ( day >= 0 && day < timeSpan + 1) { 1474 if ( day >= 0 && day < timeSpan + 1) {
1470 (*cells)[day]->insertTodo( todo ); 1475 (*cells)[day]->insertTodo( todo );
1471 } 1476 }
1472 } 1477 }
1473 } 1478 }
1474 1479
1475 for( i = 0; i < timeSpan+1; ++i ) { 1480 for( i = 0; i < timeSpan+1; ++i ) {
1476 (*cells)[i]->finishUpdateCell(); 1481 (*cells)[i]->finishUpdateCell();
1477 } 1482 }
1478 processSelectionChange(); 1483 processSelectionChange();
1479 //qApp->processEvents(); 1484 //qApp->processEvents();
1480 for( i = 0; i < timeSpan+1; ++i ) { 1485 for( i = 0; i < timeSpan+1; ++i ) {
1481 (*cells)[i]->repaintfinishUpdateCell(); 1486 (*cells)[i]->repaintfinishUpdateCell();
1482 } 1487 }
1483 setKeyBFocus(); 1488 setKeyBFocus();
1484#else 1489#else
1485 // old code 1490 // old code
1486 //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); 1491 //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ");
1487 int i; 1492 int i;
1488 for( i = 0; i < (*cells).count(); ++i ) { 1493 for( i = 0; i < (*cells).count(); ++i ) {
1489 (*cells)[i]->updateCell(); 1494 (*cells)[i]->updateCell();
1490 } 1495 }
1491 1496
1492 //qDebug("KOMonthView::updateView() "); 1497 //qDebug("KOMonthView::updateView() ");
1493 processSelectionChange(); 1498 processSelectionChange();
1494 // qDebug("---------------------------------------------------------------------+ "); 1499 // qDebug("---------------------------------------------------------------------+ ");
1495 (*cells)[0]->setFocus(); 1500 (*cells)[0]->setFocus();
1496#endif 1501#endif
1497 1502
1498 //qDebug("update time %d ", ti.elapsed()); 1503 //qDebug("update time %d ", ti.elapsed());
1499} 1504}
1500 1505
1501void KOMonthView::setKeyBoardFocus() 1506void KOMonthView::setKeyBoardFocus()
1502{ 1507{
1503 bool shootAgain = false; 1508 bool shootAgain = false;
1504 if ( mShowWeekView ) { 1509 if ( mShowWeekView ) {
1505 shootAgain = !mWeekLabelsW[0]->hasFocus(); 1510 shootAgain = !mWeekLabelsW[0]->hasFocus();
1506 mWeekLabelsW[0]->setFocus(); 1511 mWeekLabelsW[0]->setFocus();
1507 } 1512 }
1508 else { 1513 else {
1509 shootAgain = !mWeekLabels[0]->hasFocus(); 1514 shootAgain = !mWeekLabels[0]->hasFocus();
1510 mWeekLabels[0]->setFocus(); 1515 mWeekLabels[0]->setFocus();
1511 } 1516 }
1512 if ( shootAgain ) { 1517 if ( shootAgain ) {
1513 QTimer::singleShot( 0, this, SLOT ( setKeyBFocus() ) ); 1518 QTimer::singleShot( 0, this, SLOT ( setKeyBFocus() ) );
1514 } 1519 }
1515} 1520}
1516void KOMonthView::setKeyBFocus() 1521void KOMonthView::setKeyBFocus()
1517{ 1522{
1518 //qDebug("KOMonthView::setKeyBFocus() "); 1523 //qDebug("KOMonthView::setKeyBFocus() ");
1519 QTimer::singleShot( 0, this, SLOT ( setKeyBoardFocus() ) ); 1524 QTimer::singleShot( 0, this, SLOT ( setKeyBoardFocus() ) );
1520} 1525}
1521void KOMonthView::resizeEvent(QResizeEvent * e) 1526void KOMonthView::resizeEvent(QResizeEvent * e)
1522{ 1527{
1523 //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height()); 1528 //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height());
1524 if ( isVisible() ) { 1529 if ( isVisible() ) {
1525 //qDebug("KOMonthView::isVisible "); 1530 //qDebug("KOMonthView::isVisible ");
1526 slotComputeLayout(); 1531 slotComputeLayout();
1527 } else 1532 } else
1528 mComputeLayoutTimer->start( 100 ); 1533 mComputeLayoutTimer->start( 100 );
1529} 1534}
1530 1535
1531void KOMonthView::slotComputeLayout() 1536void KOMonthView::slotComputeLayout()
1532{ 1537{
1533 mComputeLayoutTimer->stop(); 1538 mComputeLayoutTimer->stop();
1534 //qDebug("KOMonthView::Post - resizeEvent %d %d ", width(), height() ); 1539 //qDebug("KOMonthView::Post - resizeEvent %d %d ", width(), height() );
1535 computeLayout(); 1540 computeLayout();
1536 clPending = true; 1541 clPending = true;
1537 setKeyBFocus(); 1542 setKeyBFocus();
1538} 1543}
1539void KOMonthView::computeLayoutWeek() 1544void KOMonthView::computeLayoutWeek()
1540{ 1545{
1541 static int lastWid = 0; 1546 static int lastWid = 0;
1542 static int lastHei = 0; 1547 static int lastHei = 0;
1543 int daysToShow; 1548 int daysToShow;
1544 bool combinedSatSun = false; 1549 bool combinedSatSun = false;
1545 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { 1550 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
1546 daysToShow = 6; 1551 daysToShow = 6;
1547 combinedSatSun = true; 1552 combinedSatSun = true;
1548 } 1553 }
1549 int tWid = topLevelWidget()->size().width(); 1554 int tWid = topLevelWidget()->size().width();
1550 int tHei = topLevelWidget()->size().height(); 1555 int tHei = topLevelWidget()->size().height();
1551 1556
1552 int wid = width();//e 1557 int wid = width();//e
1553 int hei = height()-1-mNavigatorBar->height(); 1558 int hei = height()-1-mNavigatorBar->height();
1554 1559
1555 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) 1560 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei )
1556 return; 1561 return;
1557 1562
1558 if ( lastWid == width() && lastHei == height() ) { 1563 if ( lastWid == width() && lastHei == height() ) {
1559 //qDebug("KOListWeekView::No compute layout needed "); 1564 //qDebug("KOListWeekView::No compute layout needed ");
1560 return; 1565 return;
1561 } 1566 }
1562 lastWid = width(); 1567 lastWid = width();
1563 lastHei = height(); 1568 lastHei = height();
1564 1569
1565 1570
1566 if ( wid < hei ) 1571 if ( wid < hei )
1567 daysToShow = 2; 1572 daysToShow = 2;
1568 else 1573 else
1569 daysToShow = 3; 1574 daysToShow = 3;
1570 mShowSatSunComp = true; 1575 mShowSatSunComp = true;
1571 combinedSatSun = true; 1576 combinedSatSun = true;
1572 1577
1573 //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ "); 1578 //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ ");
1574 QFontMetrics fm ( mWeekLabels[0]->font() ); 1579 QFontMetrics fm ( mWeekLabels[0]->font() );
1575 int weeklabelwid = fm.width( "888" ); 1580 int weeklabelwid = fm.width( "888" );
1576 wid -= weeklabelwid; 1581 wid -= weeklabelwid;
1577 1582
1578 int colWid = wid / daysToShow; 1583 int colWid = wid / daysToShow;
1579 int lastCol = wid - ( colWid*6 ); 1584 int lastCol = wid - ( colWid*6 );
1580 int dayLabelHei = mDayLabelsW[0]->sizeHint().height(); 1585 int dayLabelHei = mDayLabelsW[0]->sizeHint().height();
1581 int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow ); 1586 int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow );
1582 int colModulo = wid % daysToShow; 1587 int colModulo = wid % daysToShow;
1583 int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1; 1588 int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1;
1584 //qDebug("rowmod %d ", rowModulo); 1589 //qDebug("rowmod %d ", rowModulo);
1585 int i; 1590 int i;
1586 int x,y,w,h; 1591 int x,y,w,h;
1587 x= 0; 1592 x= 0;
1588 y= 0; 1593 y= 0;
1589 w = colWid; 1594 w = colWid;
1590 h = dayLabelHei ; 1595 h = dayLabelHei ;
1591 for ( i = 0; i < 7; i++) { 1596 for ( i = 0; i < 7; i++) {
1592 if ( i && !( i % daysToShow) && i < 6) { 1597 if ( i && !( i % daysToShow) && i < 6) {
1593 y += hei/(5-daysToShow); 1598 y += hei/(5-daysToShow);
1594 x = 0; 1599 x = 0;
1595 w = colWid; 1600 w = colWid;
1596 } 1601 }
1597 if ( ((i) % daysToShow) >= daysToShow-colModulo ) { 1602 if ( ((i) % daysToShow) >= daysToShow-colModulo ) {
1598 ++w; 1603 ++w;
1599 } 1604 }
1600 if ( i >= 5 ) { 1605 if ( i >= 5 ) {
1601 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w/2+w%2,h); 1606 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w/2+w%2,h);
1602 x -= (w/2 ); 1607 x -= (w/2 );
1603 } 1608 }
1604 else 1609 else
1605 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w,h); 1610 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w,h);
1606 x += w; 1611 x += w;
1607 } 1612 }
1608 x= 0; 1613 x= 0;
1609 y= dayLabelHei; 1614 y= dayLabelHei;
1610 w = colWid; 1615 w = colWid;
1611 h = cellHei; 1616 h = cellHei;
1612 int max = 0; 1617 int max = 0;
1613 for ( i = 0; i < mCellsW.count(); ++i) { 1618 for ( i = 0; i < mCellsW.count(); ++i) {
1614 if ( i > 6 ) { 1619 if ( i > 6 ) {
1615 mCellsW[i]->hide(); 1620 mCellsW[i]->hide();
1616 continue; 1621 continue;
1617 } 1622 }
1618 1623
1619 w = colWid; 1624 w = colWid;
1620 if ( ((i) % daysToShow) >= daysToShow-colModulo ) { 1625 if ( ((i) % daysToShow) >= daysToShow-colModulo ) {
1621 ++w; 1626 ++w;
1622 } 1627 }
1623 if ( i == (daysToShow-1-rowModulo)*7) 1628 if ( i == (daysToShow-1-rowModulo)*7)
1624 ++h; 1629 ++h;
1625 1630
1626 if ( i >= 5 ) { 1631 if ( i >= 5 ) {
1627 if ( i ==5 ) { 1632 if ( i ==5 ) {
1628 max = h/2; 1633 max = h/2;
1629 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max ); 1634 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max );
1630 x -= w ;y += h/2; 1635 x -= w ;y += h/2;
1631 } else { 1636 } else {
1632 if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) { 1637 if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) {
1633 ++w; 1638 ++w;
1634 } 1639 }
1635 max = h-h/2; 1640 max = h-h/2;
1636 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max ); 1641 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max );
1637 y -= h/2; 1642 y -= h/2;
1638 } 1643 }
1639 } else { 1644 } else {
1640 max = h; 1645 max = h;
1641 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h ); 1646 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h );
1642 } 1647 }
1643 1648
1644 1649
1645 x += w; 1650 x += w;
1646 if ( x + w/2 > wid ) { 1651 if ( x + w/2 > wid ) {
1647 x = 0; 1652 x = 0;
1648 y += h+dayLabelHei ; 1653 y += h+dayLabelHei ;
1649 } 1654 }
1650 //mCellsW[i]->dateLabel()->setMaximumHeight( max - mCellsW[i]->lineWidth()*2 ); 1655 //mCellsW[i]->dateLabel()->setMaximumHeight( max - mCellsW[i]->lineWidth()*2 );
1651 } 1656 }
1652 y= dayLabelHei; 1657 y= dayLabelHei;
1653 h = cellHei ; 1658 h = cellHei ;
1654 mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei); 1659 mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei);
1655 mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei); 1660 mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
1656 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); 1661 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
1657 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); 1662 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
1658 mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ; 1663 mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ;
1659 updateDayLabels(); 1664 updateDayLabels();
1660 //bool forceUpdate = !updatePossible; 1665 //bool forceUpdate = !updatePossible;
1661 updatePossible = true; 1666 updatePossible = true;
1662 //mWeekLabels[mNumWeeks]->setText( i18n("M")); 1667 //mWeekLabels[mNumWeeks]->setText( i18n("M"));
1663 //if ( forceUpdate ) 1668 //if ( forceUpdate )
1664 // updateView(); 1669 // updateView();
1665} 1670}
1666void KOMonthView::computeLayout() 1671void KOMonthView::computeLayout()
1667{ 1672{
1668 1673
1669 1674
1670 static int lastWid = 0; 1675 static int lastWid = 0;
1671 static int lastHei = 0; 1676 static int lastHei = 0;
1672 1677
1673 if ( mShowWeekView ){ 1678 if ( mShowWeekView ){
1674 computeLayoutWeek(); 1679 computeLayoutWeek();
1675 return; 1680 return;
1676 } 1681 }
1677 int daysToShow = 7; 1682 int daysToShow = 7;
1678 bool combinedSatSun = false; 1683 bool combinedSatSun = false;
1679 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { 1684 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
1680 daysToShow = 6; 1685 daysToShow = 6;
1681 combinedSatSun = true; 1686 combinedSatSun = true;
1682 } 1687 }
1683 int tWid = topLevelWidget()->size().width(); 1688 int tWid = topLevelWidget()->size().width();
1684 int tHei = topLevelWidget()->size().height(); 1689 int tHei = topLevelWidget()->size().height();
1685 1690
1686 int wid = width();//e 1691 int wid = width();//e
1687 int hei = height()-1-mNavigatorBar->height(); 1692 int hei = height()-1-mNavigatorBar->height();
1688 1693
1689 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) { 1694 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) {
1690 return; 1695 return;
1691 } 1696 }
1692 if ( lastWid == width() && lastHei == height() ){ 1697 if ( lastWid == width() && lastHei == height() ){
1693 //qDebug("KOMonthview::No compute layout needed "); 1698 //qDebug("KOMonthview::No compute layout needed ");
1694 return; 1699 return;
1695 } 1700 }
1696 1701
1697 lastWid = width(); 1702 lastWid = width();
1698 lastHei = height(); 1703 lastHei = height();
1699 //qDebug("KOMonthView::computeLayout() MMM ------------------- "); 1704 //qDebug("KOMonthView::computeLayout() MMM ------------------- ");
1700 QFontMetrics fm ( mWeekLabels[0]->font() ); 1705 QFontMetrics fm ( mWeekLabels[0]->font() );
1701 int weeklabelwid = fm.width( "888" ); 1706 int weeklabelwid = fm.width( "888" );
1702 wid -= weeklabelwid; 1707 wid -= weeklabelwid;
1703 1708
1704 int colWid = wid / daysToShow; 1709 int colWid = wid / daysToShow;
1705 int lastCol = wid - ( colWid*6 ); 1710 int lastCol = wid - ( colWid*6 );
1706 int dayLabelHei = mDayLabels[0]->sizeHint().height(); 1711 int dayLabelHei = mDayLabels[0]->sizeHint().height();
1707 int cellHei = (hei - dayLabelHei) /6; 1712 int cellHei = (hei - dayLabelHei) /6;
1708 int colModulo = wid % daysToShow; 1713 int colModulo = wid % daysToShow;
1709 int rowModulo = (hei- dayLabelHei) % 6; 1714 int rowModulo = (hei- dayLabelHei) % 6;
1710 //qDebug("rowmod %d ", rowModulo); 1715 //qDebug("rowmod %d ", rowModulo);
1711 int i; 1716 int i;
1712 int x,y,w,h; 1717 int x,y,w,h;
1713 x= 0; 1718 x= 0;
1714 y= 0; 1719 y= 0;
1715 w = colWid; 1720 w = colWid;
1716 h = dayLabelHei ; 1721 h = dayLabelHei ;
1717 for ( i = 0; i < 7; i++) { 1722 for ( i = 0; i < 7; i++) {
1718 if ( i == daysToShow-colModulo ) 1723 if ( i == daysToShow-colModulo )
1719 ++w; 1724 ++w;
1720 if ( combinedSatSun ) { 1725 if ( combinedSatSun ) {
1721 if ( i >= daysToShow-1 ) { 1726 if ( i >= daysToShow-1 ) {
1722 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h); 1727 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h);
1723 x -= w/2 ; 1728 x -= w/2 ;
1724 } 1729 }
1725 else 1730 else
1726 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 1731 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
1727 } else 1732 } else
1728 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 1733 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
1729 x += w; 1734 x += w;
1730 } 1735 }
1731 x= 0; 1736 x= 0;
1732 y= dayLabelHei; 1737 y= dayLabelHei;
1733 w = colWid; 1738 w = colWid;
1734 h = cellHei ; 1739 h = cellHei ;
1735 int max = 0; 1740 int max = 0;
1736 for ( i = 0; i < mCells.count(); ++i) { 1741 for ( i = 0; i < mCells.count(); ++i) {
1737 //qDebug("iii %d ", i); 1742 //qDebug("iii %d ", i);
1738 w = colWid; 1743 w = colWid;
1739 if ( ((i) % 7) >= 7-colModulo ) { 1744 if ( ((i) % 7) >= 7-colModulo ) {
1740 ++w; 1745 ++w;
1741 } 1746 }
1742 if ( i == (6-rowModulo)*7) 1747 if ( i == (6-rowModulo)*7)
1743 ++h; 1748 ++h;
1744 if ( combinedSatSun ) { 1749 if ( combinedSatSun ) {
1745 if ( (i)%7 >= daysToShow-1 ) { 1750 if ( (i)%7 >= daysToShow-1 ) {
1746 if ( (i)%7 == daysToShow-1 ) { 1751 if ( (i)%7 == daysToShow-1 ) {
1747 max = h/2; 1752 max = h/2;
1748 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); 1753 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max );
1749 x -= w ;y += h/2; 1754 x -= w ;y += h/2;
1750 } else { 1755 } else {
1751 max = h-h/2; 1756 max = h-h/2;
1752 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); 1757 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max );
1753 y -= h/2; 1758 y -= h/2;
1754 } 1759 }
1755 } else { 1760 } else {
1756 max = h; 1761 max = h;
1757 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); 1762 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h );
1758 } 1763 }
1759 1764
1760 } 1765 }
1761 else { 1766 else {
1762 max = h; 1767 max = h;
1763 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); 1768 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h );
1764 } 1769 }
1765 x += w; 1770 x += w;
1766 if ( x + w/2 > wid ) { 1771 if ( x + w/2 > wid ) {
1767 x = 0; 1772 x = 0;
1768 y += h; 1773 y += h;
1769 } 1774 }
1770 //mCells[i]->dateLabel()->setMaximumHeight( max- mCells[i]->lineWidth()*2 ); 1775 //mCells[i]->dateLabel()->setMaximumHeight( max- mCells[i]->lineWidth()*2 );
1771 } 1776 }
1772 y= dayLabelHei; 1777 y= dayLabelHei;
1773 h = cellHei ; 1778 h = cellHei ;
1774 for ( i = 0; i < 6; i++) { 1779 for ( i = 0; i < 6; i++) {
1775 if ( i == (6-rowModulo)) 1780 if ( i == (6-rowModulo))
1776 ++h; 1781 ++h;
1777 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h); 1782 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h);
1778 y += h; 1783 y += h;
1779 } 1784 }
1780 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); 1785 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
1781 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); 1786 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
1782 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); 1787 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
1783 mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ; 1788 mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ;
1784 updateDayLabels(); 1789 updateDayLabels();
1785 //bool forceUpdate = !updatePossible; 1790 //bool forceUpdate = !updatePossible;
1786 updatePossible = true; 1791 updatePossible = true;
1787 //mWeekLabels[mNumWeeks]->setText( i18n("W")); 1792 //mWeekLabels[mNumWeeks]->setText( i18n("W"));
1788} 1793}
1789 1794
1790void KOMonthView::showContextMenu( Incidence *incidence ) 1795void KOMonthView::showContextMenu( Incidence *incidence )
1791{ 1796{
1792 mContextMenu->showIncidencePopup(incidence); 1797 mContextMenu->showIncidencePopup(incidence);
1793 /* 1798 /*
1794 if( incidence && incidence->type() == "Event" ) { 1799 if( incidence && incidence->type() == "Event" ) {
1795 Event *event = static_cast<Event *>(incidence); 1800 Event *event = static_cast<Event *>(incidence);
1796 mContextMenu->showEventPopup(event); 1801 mContextMenu->showEventPopup(event);
1797 } else { 1802 } else {
1798 kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; 1803 kdDebug() << "MonthView::showContextMenu(): cast failed." << endl;
1799 } 1804 }
1800 */ 1805 */
1801} 1806}
1802MonthViewCell * KOMonthView::selectedCell( ) 1807MonthViewCell * KOMonthView::selectedCell( )
1803{ 1808{
1804 return mSelectedCell; 1809 return mSelectedCell;
1805} 1810}
1806void KOMonthView::setSelectedCell( MonthViewCell *cell ) 1811void KOMonthView::setSelectedCell( MonthViewCell *cell )
1807{ 1812{
1808 //qDebug("KOMonthView::setSelectedCell "); 1813 //qDebug("KOMonthView::setSelectedCell ");
1809 if ( mSelectedCell && mSelectedCell != cell ) { 1814 if ( mSelectedCell && mSelectedCell != cell ) {
1810 MonthViewCell * mvc = mSelectedCell; 1815 MonthViewCell * mvc = mSelectedCell;
1811 mSelectedCell = cell; 1816 mSelectedCell = cell;
1812 mvc->deselect(); 1817 mvc->deselect();
1813 } else 1818 } else
1814 mSelectedCell = cell; 1819 mSelectedCell = cell;
1815 // if ( mSelectedCell ) 1820 // if ( mSelectedCell )
1816 // mSelectedCell->select(); 1821 // mSelectedCell->select();
1817 if ( !mSelectedCell ) 1822 if ( !mSelectedCell )
1818 emit incidenceSelected( 0 ); 1823 emit incidenceSelected( 0 );
1819 else 1824 else
1820 emit incidenceSelected( mSelectedCell->selectedIncidence() ); 1825 emit incidenceSelected( mSelectedCell->selectedIncidence() );
1821} 1826}
1822 1827
1823void KOMonthView::processSelectionChange() 1828void KOMonthView::processSelectionChange()
1824{ 1829{
1825 QPtrList<Incidence> incidences = selectedIncidences(); 1830 QPtrList<Incidence> incidences = selectedIncidences();
1826 if (incidences.count() > 0) { 1831 if (incidences.count() > 0) {
1827 emit incidenceSelected( incidences.first() ); 1832 emit incidenceSelected( incidences.first() );
1828 } else { 1833 } else {
1829 emit incidenceSelected( 0 ); 1834 emit incidenceSelected( 0 );
1830 clearSelection(); 1835 clearSelection();
1831 } 1836 }
1832} 1837}
1833 1838
1834void KOMonthView::clearSelection() 1839void KOMonthView::clearSelection()
1835{ 1840{
1836 if ( mSelectedCell ) { 1841 if ( mSelectedCell ) {
1837 mSelectedCell->deselect(); 1842 mSelectedCell->deselect();
1838 mSelectedCell = 0; 1843 mSelectedCell = 0;
1839 } 1844 }
1840} 1845}
1841 1846
1842void KOMonthView::keyReleaseEvent ( QKeyEvent * e) 1847void KOMonthView::keyReleaseEvent ( QKeyEvent * e)
1843{ 1848{
1844 if ( !e->isAutoRepeat() ) { 1849 if ( !e->isAutoRepeat() ) {
1845 mFlagKeyPressed = false; 1850 mFlagKeyPressed = false;
1846 } 1851 }
1847} 1852}
1848 1853
1849void KOMonthView::keyPressEvent ( QKeyEvent * e ) 1854void KOMonthView::keyPressEvent ( QKeyEvent * e )
1850{ 1855{
1851 1856
1852 qApp->processEvents(); 1857 qApp->processEvents();
1853 if ( e->isAutoRepeat() && !mFlagKeyPressed ) { 1858 if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
1854 //e->ignore(); 1859 //e->ignore();
1855 e->accept(); 1860 e->accept();
1856 return; 1861 return;
1857 } 1862 }
1858 if (! e->isAutoRepeat() ) 1863 if (! e->isAutoRepeat() )
1859 mFlagKeyPressed = true; 1864 mFlagKeyPressed = true;
1860 switch(e->key()) { 1865 switch(e->key()) {
1861 case Key_Up: 1866 case Key_Up:
1862 { 1867 {
1863 if ( mShowWeekView ) { 1868 if ( mShowWeekView ) {
1864 emit selectWeekNum ( currentWeek() - 1 ); 1869 emit selectWeekNum ( currentWeek() - 1 );
1865 } 1870 }
1866 else { 1871 else {
1867 emit prevMonth(); 1872 emit prevMonth();
1868 } 1873 }
1869 } 1874 }
1870 e->accept(); 1875 e->accept();
1871 break; 1876 break;
1872 case Key_Down: 1877 case Key_Down:
1873 { 1878 {
1874 if ( mShowWeekView ) { 1879 if ( mShowWeekView ) {
1875 emit selectWeekNum ( currentWeek() +1); 1880 emit selectWeekNum ( currentWeek() +1);
1876 } 1881 }
1877 else { 1882 else {
1878 emit nextMonth(); 1883 emit nextMonth();
1879 } 1884 }
1880 1885
1881 } 1886 }
1882 e->accept(); 1887 e->accept();
1883 break; 1888 break;
1884 case Key_Return: 1889 case Key_Return:
1885 case Key_Enter: 1890 case Key_Enter:
1886 { 1891 {
1887 selectInternalWeekNum ( currentWeek() ); 1892 selectInternalWeekNum ( currentWeek() );
1888 } 1893 }
1889 e->accept(); 1894 e->accept();
1890 break; 1895 break;
1891 case Key_D: 1896 case Key_D:
1892 if ( mSelectedCell ) { 1897 if ( mSelectedCell ) {
1893 mSelectedCell->showDay(); 1898 mSelectedCell->showDay();
1894 e->accept(); 1899 e->accept();
1895 } else { 1900 } else {
1896 e->ignore(); 1901 e->ignore();
1897 } 1902 }
1898 break; 1903 break;
1899 default: 1904 default:
1900 e->ignore(); 1905 e->ignore();
1901 break; 1906 break;
1902 } 1907 }
1903} 1908}
diff --git a/korganizer/kotodoview.cpp b/korganizer/kotodoview.cpp
index e008625..ccc4b01 100644
--- a/korganizer/kotodoview.cpp
+++ b/korganizer/kotodoview.cpp
@@ -1,1341 +1,1394 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qlayout.h> 24#include <qlayout.h>
25#include <qheader.h> 25#include <qheader.h>
26#include <qcursor.h> 26#include <qcursor.h>
27#include <qwhatsthis.h> 27#include <qwhatsthis.h>
28 28
29#include <qvbox.h> 29#include <qvbox.h>
30#include <kdebug.h> 30#include <kdebug.h>
31#include "koprefs.h" 31#include "koprefs.h"
32#include <klocale.h> 32#include <klocale.h>
33#include <kglobal.h> 33#include <kglobal.h>
34#include <kiconloader.h> 34#include <kiconloader.h>
35#include <kmessagebox.h> 35#include <kmessagebox.h>
36 36
37#include <libkcal/icaldrag.h> 37#include <libkcal/icaldrag.h>
38#include <libkcal/vcaldrag.h> 38#include <libkcal/vcaldrag.h>
39#include <libkcal/calfilter.h> 39#include <libkcal/calfilter.h>
40#include <libkcal/dndfactory.h> 40#include <libkcal/dndfactory.h>
41#include <libkcal/calendarresources.h> 41#include <libkcal/calendarresources.h>
42#include <libkcal/resourcecalendar.h> 42#include <libkcal/resourcecalendar.h>
43#include <kresources/resourceselectdialog.h> 43#include <kresources/resourceselectdialog.h>
44#include <libkcal/kincidenceformatter.h> 44#include <libkcal/kincidenceformatter.h>
45#ifndef DESKTOP_VERSION 45#ifndef DESKTOP_VERSION
46#include <qpe/qpeapplication.h> 46#include <qpe/qpeapplication.h>
47#else 47#else
48#include <qapplication.h> 48#include <qapplication.h>
49#endif 49#endif
50#ifndef KORG_NOPRINTER 50#ifndef KORG_NOPRINTER
51#include "calprinter.h" 51#include "calprinter.h"
52#endif 52#endif
53#include "docprefs.h" 53#include "docprefs.h"
54 54
55#include "kotodoview.h" 55#include "kotodoview.h"
56using namespace KOrg; 56using namespace KOrg;
57 57
58 58
59class KOTodoViewWhatsThis :public QWhatsThis 59class KOTodoViewWhatsThis :public QWhatsThis
60{ 60{
61public: 61public:
62 KOTodoViewWhatsThis( QWidget *wid, KOTodoView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { }; 62 KOTodoViewWhatsThis( QWidget *wid, KOTodoView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { };
63 63
64protected: 64protected:
65 virtual QString text( const QPoint& p) 65 virtual QString text( const QPoint& p)
66 { 66 {
67 return _view->getWhatsThisText(p) ; 67 return _view->getWhatsThisText(p) ;
68 } 68 }
69private: 69private:
70 QWidget* _wid; 70 QWidget* _wid;
71 KOTodoView * _view; 71 KOTodoView * _view;
72}; 72};
73 73
74KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent, 74KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent,
75 const char *name) : 75 const char *name) :
76 KListView(parent,name) 76 KListView(parent,name)
77{ 77{
78 mName = QString ( name ); 78 mName = QString ( name );
79 mCalendar = calendar; 79 mCalendar = calendar;
80#ifndef DESKTOP_VERSION 80#ifndef DESKTOP_VERSION
81 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold ); 81 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold );
82#endif 82#endif
83 mOldCurrent = 0; 83 mOldCurrent = 0;
84 mMousePressed = false; 84 mMousePressed = false;
85 85
86 setAcceptDrops(true); 86 setAcceptDrops(true);
87 viewport()->setAcceptDrops(true); 87 viewport()->setAcceptDrops(true);
88 int size = 16; 88 int size = 16;
89 if (qApp->desktop()->width() < 300 ) 89 if (qApp->desktop()->width() < 300 )
90 size = 12; 90 size = 12;
91 setTreeStepSize( size + 6 ); 91 setTreeStepSize( size + 6 );
92 92
93} 93}
94 94
95void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e) 95void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e)
96{ 96{
97#ifndef KORG_NODND 97#ifndef KORG_NODND
98// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl; 98// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl;
99 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 99 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
100 !QTextDrag::canDecode( e ) ) { 100 !QTextDrag::canDecode( e ) ) {
101 e->ignore(); 101 e->ignore();
102 return; 102 return;
103 } 103 }
104 104
105 mOldCurrent = currentItem(); 105 mOldCurrent = currentItem();
106#endif 106#endif
107} 107}
108 108
109 109
110void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e) 110void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e)
111{ 111{
112#ifndef KORG_NODND 112#ifndef KORG_NODND
113// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl; 113// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl;
114 114
115 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 115 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
116 !QTextDrag::canDecode( e ) ) { 116 !QTextDrag::canDecode( e ) ) {
117 e->ignore(); 117 e->ignore();
118 return; 118 return;
119 } 119 }
120 120
121 e->accept(); 121 e->accept();
122#endif 122#endif
123} 123}
124 124
125void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *) 125void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *)
126{ 126{
127#ifndef KORG_NODND 127#ifndef KORG_NODND
128// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl; 128// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl;
129 129
130 setCurrentItem(mOldCurrent); 130 setCurrentItem(mOldCurrent);
131 setSelected(mOldCurrent,true); 131 setSelected(mOldCurrent,true);
132#endif 132#endif
133} 133}
134 134
135void KOTodoListView::contentsDropEvent(QDropEvent *e) 135void KOTodoListView::contentsDropEvent(QDropEvent *e)
136{ 136{
137#ifndef KORG_NODND 137#ifndef KORG_NODND
138// kdDebug() << "KOTodoListView::contentsDropEvent" << endl; 138// kdDebug() << "KOTodoListView::contentsDropEvent" << endl;
139 139
140 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 140 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
141 !QTextDrag::canDecode( e ) ) { 141 !QTextDrag::canDecode( e ) ) {
142 e->ignore(); 142 e->ignore();
143 return; 143 return;
144 } 144 }
145 145
146 DndFactory factory( mCalendar ); 146 DndFactory factory( mCalendar );
147 Todo *todo = factory.createDropTodo(e); 147 Todo *todo = factory.createDropTodo(e);
148 148
149 if (todo) { 149 if (todo) {
150 e->acceptAction(); 150 e->acceptAction();
151 151
152 KOTodoViewItem *destination = 152 KOTodoViewItem *destination =
153 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos())); 153 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos()));
154 Todo *destinationEvent = 0; 154 Todo *destinationEvent = 0;
155 if (destination) destinationEvent = destination->todo(); 155 if (destination) destinationEvent = destination->todo();
156 156
157 Todo *existingTodo = mCalendar->todo(todo->uid()); 157 Todo *existingTodo = mCalendar->todo(todo->uid());
158 158
159 if(existingTodo) { 159 if(existingTodo) {
160 Incidence *to = destinationEvent; 160 Incidence *to = destinationEvent;
161 while(to) { 161 while(to) {
162 if (to->uid() == todo->uid()) { 162 if (to->uid() == todo->uid()) {
163 KMessageBox::sorry(this, 163 KMessageBox::sorry(this,
164 i18n("Cannot move To-Do to itself\nor a child of itself"), 164 i18n("Cannot move To-Do to itself\nor a child of itself"),
165 i18n("Drop To-Do")); 165 i18n("Drop To-Do"));
166 delete todo; 166 delete todo;
167 return; 167 return;
168 } 168 }
169 to = to->relatedTo(); 169 to = to->relatedTo();
170 } 170 }
171 internalDrop = true; 171 internalDrop = true;
172 if ( destinationEvent ) 172 if ( destinationEvent )
173 reparentTodoSignal( destinationEvent, existingTodo ); 173 reparentTodoSignal( destinationEvent, existingTodo );
174 else 174 else
175 unparentTodoSignal(existingTodo); 175 unparentTodoSignal(existingTodo);
176 delete todo; 176 delete todo;
177 } else { 177 } else {
178 mCalendar->addTodo(todo); 178 mCalendar->addTodo(todo);
179 emit todoDropped(todo, KOGlobals::EVENTADDED); 179 emit todoDropped(todo, KOGlobals::EVENTADDED);
180 if ( destinationEvent ) 180 if ( destinationEvent )
181 reparentTodoSignal( destinationEvent, todo ); 181 reparentTodoSignal( destinationEvent, todo );
182 } 182 }
183 } 183 }
184 else { 184 else {
185 QString text; 185 QString text;
186 if (QTextDrag::decode(e,text)) { 186 if (QTextDrag::decode(e,text)) {
187 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) ); 187 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) );
188 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) )); 188 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) ));
189 qDebug("Dropped : " + text); 189 qDebug("Dropped : " + text);
190 QStringList emails = QStringList::split(",",text); 190 QStringList emails = QStringList::split(",",text);
191 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { 191 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
192 int pos = (*it).find("<"); 192 int pos = (*it).find("<");
193 QString name = (*it).left(pos); 193 QString name = (*it).left(pos);
194 QString email = (*it).mid(pos); 194 QString email = (*it).mid(pos);
195 if (!email.isEmpty() && todoi) { 195 if (!email.isEmpty() && todoi) {
196 todoi->todo()->addAttendee(new Attendee(name,email)); 196 todoi->todo()->addAttendee(new Attendee(name,email));
197 } 197 }
198 } 198 }
199 } 199 }
200 else { 200 else {
201 qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable "); 201 qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable ");
202 e->ignore(); 202 e->ignore();
203 } 203 }
204 } 204 }
205#endif 205#endif
206} 206}
207 207
208void KOTodoListView::contentsMousePressEvent(QMouseEvent* e) 208void KOTodoListView::contentsMousePressEvent(QMouseEvent* e)
209{ 209{
210#ifndef KORG_NODND 210#ifndef KORG_NODND
211 QPoint p(contentsToViewport(e->pos())); 211 QPoint p(contentsToViewport(e->pos()));
212 QListViewItem *i = itemAt(p); 212 QListViewItem *i = itemAt(p);
213 mMousePressed = false; 213 mMousePressed = false;
214 if (i) { 214 if (i) {
215 // if the user clicked into the root decoration of the item, don't 215 // if the user clicked into the root decoration of the item, don't
216 // try to start a drag! 216 // try to start a drag!
217 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) + 217 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) +
218 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) + 218 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) +
219 itemMargin() || 219 itemMargin() ||
220 p.x() < header()->sectionPos(header()->mapToIndex(0))) { 220 p.x() < header()->sectionPos(header()->mapToIndex(0))) {
221 if (e->button()==Qt::LeftButton) { 221 if (e->button()==Qt::LeftButton) {
222 mPressPos = e->pos(); 222 mPressPos = e->pos();
223 mMousePressed = true; 223 mMousePressed = true;
224 } 224 }
225 } 225 }
226 } 226 }
227#endif 227#endif
228 QListView::contentsMousePressEvent(e); 228 QListView::contentsMousePressEvent(e);
229} 229}
230void KOTodoListView::paintEvent(QPaintEvent* e) 230void KOTodoListView::paintEvent(QPaintEvent* e)
231{ 231{
232 emit paintNeeded(); 232 emit paintNeeded();
233 QListView::paintEvent( e); 233 QListView::paintEvent( e);
234} 234}
235void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e) 235void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e)
236{ 236{
237 237
238#ifndef KORG_NODND 238#ifndef KORG_NODND
239 //QListView::contentsMouseMoveEvent(e); 239 //QListView::contentsMouseMoveEvent(e);
240 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() > 240 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() >
241 QApplication::startDragDistance()*3) { 241 QApplication::startDragDistance()*3) {
242 mMousePressed = false; 242 mMousePressed = false;
243 QListViewItem *item = itemAt(contentsToViewport(mPressPos)); 243 QListViewItem *item = itemAt(contentsToViewport(mPressPos));
244 if (item) { 244 if (item) {
245 DndFactory factory( mCalendar ); 245 DndFactory factory( mCalendar );
246 ICalDrag *vd = factory.createDrag( 246 ICalDrag *vd = factory.createDrag(
247 ((KOTodoViewItem *)item)->todo(),viewport()); 247 ((KOTodoViewItem *)item)->todo(),viewport());
248 internalDrop = false; 248 internalDrop = false;
249 // we cannot do any senseful here, because the DnD is still broken in Qt 249 // we cannot do any senseful here, because the DnD is still broken in Qt
250 if (vd->drag()) { 250 if (vd->drag()) {
251 if ( !internalDrop ) { 251 if ( !internalDrop ) {
252 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() ); 252 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() );
253 qDebug("Dnd: External move: Delete drag source "); 253 qDebug("Dnd: External move: Delete drag source ");
254 } else 254 } else
255 qDebug("Dnd: Internal move "); 255 qDebug("Dnd: Internal move ");
256 256
257 } else { 257 } else {
258 if ( !internalDrop ) { 258 if ( !internalDrop ) {
259 qDebug("Dnd: External Copy"); 259 qDebug("Dnd: External Copy");
260 } else 260 } else
261 qDebug("DnD: Internal copy: Copy pending"); 261 qDebug("DnD: Internal copy: Copy pending");
262 } 262 }
263 } 263 }
264 } 264 }
265#endif 265#endif
266} 266}
267void KOTodoListView::keyReleaseEvent ( QKeyEvent *e )
268{
269 if ( !e->isAutoRepeat() ) {
270 mFlagKeyPressed = false;
271 }
272}
273
274
267void KOTodoListView::keyPressEvent ( QKeyEvent * e ) 275void KOTodoListView::keyPressEvent ( QKeyEvent * e )
268{ 276{
269 277 qApp->processEvents();
278 if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
279 e->ignore();
280 // qDebug(" ignore %d",e->isAutoRepeat() );
281 return;
282 }
283 if (! e->isAutoRepeat() )
284 mFlagKeyPressed = true;
270 QListViewItem* cn; 285 QListViewItem* cn;
271 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) { 286 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) {
272 cn = currentItem(); 287 cn = currentItem();
273 if ( cn ) { 288 if ( cn ) {
274 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 289 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
275 if ( ci ){ 290 if ( ci ){
276 if ( e->state() == ShiftButton ) 291 if ( e->state() == ShiftButton )
277 ci->setOn( false ); 292 ci->setOn( false );
278 else 293 else
279 ci->setOn( true ); 294 ci->setOn( true );
280 cn = cn->itemBelow(); 295 cn = cn->itemBelow();
281 if ( cn ) { 296 if ( cn ) {
282 setCurrentItem ( cn ); 297 setCurrentItem ( cn );
283 ensureItemVisible ( cn ); 298 ensureItemVisible ( cn );
284 } 299 }
285 300
286 } 301 }
287 } 302 }
288 303
289 return; 304 return;
290 } 305 }
291 306
292 // qDebug("KOTodoListView::keyPressEvent ");
293 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) { 307 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) {
294 switch ( e->key() ) { 308 switch ( e->key() ) {
295 case Qt::Key_Down: 309 case Qt::Key_Down:
296 case Qt::Key_Up: 310 case Qt::Key_Up:
297 QListView::keyPressEvent ( e ); 311 QListView::keyPressEvent ( e );
298 break; 312 break;
299 case Qt::Key_Left: 313 case Qt::Key_Left:
300 case Qt::Key_Right: 314 case Qt::Key_Right:
301 QListView::keyPressEvent ( e ); 315 QListView::keyPressEvent ( e );
302 e->accept(); 316 e->accept();
303 return; 317 return;
304 break; 318 break;
305 default: 319 default:
306 e->ignore(); 320 e->ignore();
307 break; 321 break;
308 } 322 }
309 return; 323 return;
310 } 324 }
311 e->ignore(); 325 e->ignore();
312} 326}
313void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e) 327void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e)
314{ 328{
315 QListView::contentsMouseReleaseEvent(e); 329 QListView::contentsMouseReleaseEvent(e);
316 mMousePressed = false; 330 mMousePressed = false;
317} 331}
318 332
319void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e) 333void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e)
320{ 334{
321 if (!e) return; 335 if (!e) return;
322 336
323 QPoint vp = contentsToViewport(e->pos()); 337 QPoint vp = contentsToViewport(e->pos());
324 338
325 QListViewItem *item = itemAt(vp); 339 QListViewItem *item = itemAt(vp);
326 340
327 emit double_Clicked(item); 341 emit double_Clicked(item);
328 if (!item) return; 342 if (!item) return;
329 343
330 emit doubleClicked(item,vp,0); 344 emit doubleClicked(item,vp,0);
331} 345}
332 346
333///////////////////////////////////////////////////////////////////////////// 347/////////////////////////////////////////////////////////////////////////////
334 348
335KOQuickTodo::KOQuickTodo(QWidget *parent) : 349KOQuickTodo::KOQuickTodo(QWidget *parent) :
336 QLineEdit(parent) 350 QLineEdit(parent)
337{ 351{
338 setText(i18n("Click to add a new Todo")); 352 setText(i18n("Click to add a new Todo"));
339} 353}
340 354
341void KOQuickTodo::focusInEvent(QFocusEvent *ev) 355void KOQuickTodo::focusInEvent(QFocusEvent *ev)
342{ 356{
343 if ( text()==i18n("Click to add a new Todo") ) 357 if ( text()==i18n("Click to add a new Todo") )
344 setText(""); 358 setText("");
345 QLineEdit::focusInEvent(ev); 359 QLineEdit::focusInEvent(ev);
346} 360}
347 361
348void KOQuickTodo::focusOutEvent(QFocusEvent *ev) 362void KOQuickTodo::focusOutEvent(QFocusEvent *ev)
349{ 363{
350 setText(i18n("Click to add a new Todo")); 364 setText(i18n("Click to add a new Todo"));
351 QLineEdit::focusOutEvent(ev); 365 QLineEdit::focusOutEvent(ev);
352} 366}
353 367
354///////////////////////////////////////////////////////////////////////////// 368/////////////////////////////////////////////////////////////////////////////
355 369
356KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) : 370KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) :
357 KOrg::BaseView(calendar,parent,name) 371 KOrg::BaseView(calendar,parent,name)
358{ 372{
359 mPendingUpdateBeforeRepaint = false; 373 mPendingUpdateBeforeRepaint = false;
360 isFlatDisplay = false; 374 isFlatDisplay = false;
361 mNavigator = 0; 375 mNavigator = 0;
362 QBoxLayout *topLayout = new QVBoxLayout(this); 376 QBoxLayout *topLayout = new QVBoxLayout(this);
363 mName = QString ( name ); 377 mName = QString ( name );
364 mBlockUpdate = false; 378 mBlockUpdate = false;
365 mQuickAdd = new KOQuickTodo(this); 379 mQuickAdd = new KOQuickTodo(this);
366 topLayout->addWidget(mQuickAdd); 380 topLayout->addWidget(mQuickAdd);
367 381
368 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide(); 382 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide();
369 383
370 mTodoListView = new KOTodoListView(calendar,this, name ); 384 mTodoListView = new KOTodoListView(calendar,this, name );
371 topLayout->addWidget(mTodoListView); 385 topLayout->addWidget(mTodoListView);
372 //mTodoListView->header()->setMaximumHeight(30); 386 //mTodoListView->header()->setMaximumHeight(30);
373 mTodoListView->setRootIsDecorated(true); 387 mTodoListView->setRootIsDecorated(true);
374 mTodoListView->setAllColumnsShowFocus(true); 388 mTodoListView->setAllColumnsShowFocus(true);
375 389
376 mTodoListView->setShowSortIndicator(true); 390 mTodoListView->setShowSortIndicator(true);
377 391
378 mTodoListView->addColumn(i18n("Todo")); 392 mTodoListView->addColumn(i18n("Todo"));
379 mTodoListView->addColumn(i18n("Prio")); 393 mTodoListView->addColumn(i18n("Prio"));
380 mTodoListView->setColumnAlignment(1,AlignHCenter); 394 mTodoListView->setColumnAlignment(1,AlignHCenter);
381 mTodoListView->addColumn(i18n("Complete")); 395 mTodoListView->addColumn(i18n("Complete"));
382 mTodoListView->setColumnAlignment(2,AlignCenter); 396 mTodoListView->setColumnAlignment(2,AlignCenter);
383 397
384 mTodoListView->addColumn(i18n("Due Date")); 398 mTodoListView->addColumn(i18n("Due Date"));
385 mTodoListView->setColumnAlignment(3,AlignLeft); 399 mTodoListView->setColumnAlignment(3,AlignLeft);
386 mTodoListView->addColumn(i18n("Due Time")); 400 mTodoListView->addColumn(i18n("Due Time"));
387 mTodoListView->setColumnAlignment(4,AlignHCenter); 401 mTodoListView->setColumnAlignment(4,AlignHCenter);
388 402
389 mTodoListView->addColumn(i18n("Start Date")); 403 mTodoListView->addColumn(i18n("Start Date"));
390 mTodoListView->setColumnAlignment(5,AlignLeft); 404 mTodoListView->setColumnAlignment(5,AlignLeft);
391 mTodoListView->addColumn(i18n("Start Time")); 405 mTodoListView->addColumn(i18n("Start Time"));
392 mTodoListView->setColumnAlignment(6,AlignHCenter); 406 mTodoListView->setColumnAlignment(6,AlignHCenter);
393 407
394 mTodoListView->addColumn(i18n("Cancelled")); 408 mTodoListView->addColumn(i18n("Cancelled"));
395 mTodoListView->addColumn(i18n("Categories")); 409 mTodoListView->addColumn(i18n("Categories"));
396#if 0 410#if 0
397 mTodoListView->addColumn(i18n("Sort Id")); 411 mTodoListView->addColumn(i18n("Sort Id"));
398 mTodoListView->setColumnAlignment(4,AlignHCenter); 412 mTodoListView->setColumnAlignment(4,AlignHCenter);
399#endif 413#endif
400 414
401 mTodoListView->setMinimumHeight( 60 ); 415 mTodoListView->setMinimumHeight( 60 );
402 mTodoListView->setItemsRenameable( true ); 416 mTodoListView->setItemsRenameable( true );
403 mTodoListView->setRenameable( 0 ); 417 mTodoListView->setRenameable( 0 );
404 mTodoListView->setColumnWidth( 0, 120 ); 418 mTodoListView->setColumnWidth( 0, 120 );
405 mTodoListView->setColumnWidthMode(0, QListView::Manual); 419 mTodoListView->setColumnWidthMode(0, QListView::Manual);
406 mTodoListView->setColumnWidthMode(1, QListView::Manual); 420 mTodoListView->setColumnWidthMode(1, QListView::Manual);
407 mTodoListView->setColumnWidthMode(2, QListView::Manual); 421 mTodoListView->setColumnWidthMode(2, QListView::Manual);
408 mTodoListView->setColumnWidthMode(3, QListView::Manual); 422 mTodoListView->setColumnWidthMode(3, QListView::Manual);
409 mTodoListView->setColumnWidthMode(4, QListView::Manual); 423 mTodoListView->setColumnWidthMode(4, QListView::Manual);
410 mTodoListView->setColumnWidthMode(5, QListView::Manual); 424 mTodoListView->setColumnWidthMode(5, QListView::Manual);
411 mTodoListView->setColumnWidthMode(6, QListView::Manual); 425 mTodoListView->setColumnWidthMode(6, QListView::Manual);
412 mTodoListView->setColumnWidthMode(7, QListView::Manual); 426 mTodoListView->setColumnWidthMode(7, QListView::Manual);
413 mTodoListView->setColumnWidthMode(8, QListView::Manual); 427 mTodoListView->setColumnWidthMode(8, QListView::Manual);
414 428
415 429
416 mKOTodoViewWhatsThis = new KOTodoViewWhatsThis(mTodoListView->viewport(),this); 430 mKOTodoViewWhatsThis = new KOTodoViewWhatsThis(mTodoListView->viewport(),this);
417 431
418 mPriorityPopupMenu = new QPopupMenu(this); 432 mPriorityPopupMenu = new QPopupMenu(this);
419 for (int i = 1; i <= 5; i++) { 433 for (int i = 1; i <= 5; i++) {
420 QString label = QString ("%1").arg (i); 434 QString label = QString ("%1").arg (i);
421 mPriority[mPriorityPopupMenu->insertItem (label)] = i; 435 mPriority[mPriorityPopupMenu->insertItem (label)] = i;
422 } 436 }
423 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int))); 437 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int)));
424 438
425 mPercentageCompletedPopupMenu = new QPopupMenu(this); 439 mPercentageCompletedPopupMenu = new QPopupMenu(this);
426 for (int i = 0; i <= 100; i+=20) { 440 for (int i = 0; i <= 100; i+=20) {
427 QString label = QString ("%1 %").arg (i); 441 QString label = QString ("%1 %").arg (i);
428 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i; 442 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i;
429 } 443 }
430 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int))); 444 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int)));
431 445
432 446
433 447
434 mItemPopupMenu = new QPopupMenu(this); 448 mItemPopupMenu = new QPopupMenu(this);
435 mItemPopupMenu->insertItem(i18n("Show..."), this, 449 mItemPopupMenu->insertItem(i18n("Show..."), this,
436 SLOT (showTodo())); 450 SLOT (showTodo()));
437 mItemPopupMenu->insertItem(i18n("Edit..."), this, 451 mItemPopupMenu->insertItem(i18n("Edit..."), this,
438 SLOT (editTodo())); 452 SLOT (editTodo()));
439 mItemPopupMenu->insertItem( i18n("Delete"), this, 453 mItemPopupMenu->insertItem( i18n("Delete"), this,
440 SLOT (deleteTodo())); 454 SLOT (deleteTodo()));
441 mItemPopupMenu->insertItem( i18n("Clone..."), this, 455 mItemPopupMenu->insertItem( i18n("Clone..."), this,
442 SLOT (cloneTodo())); 456 SLOT (cloneTodo()));
443 mItemPopupMenu->insertItem( i18n("Move..."), this, 457 mItemPopupMenu->insertItem( i18n("Move..."), this,
444 SLOT (moveTodo())); 458 SLOT (moveTodo()));
445 mItemPopupMenu->insertItem( i18n("Beam..."), this, 459 mItemPopupMenu->insertItem( i18n("Beam..."), this,
446 SLOT (beamTodo())); 460 SLOT (beamTodo()));
447 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this, 461 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this,
448 SLOT (cancelTodo())); 462 SLOT (cancelTodo()));
449 mItemPopupMenu->insertSeparator(); 463 mItemPopupMenu->insertSeparator();
450 464
451 mItemPopupMenu->insertItem( i18n("New Todo..."), this, 465 mItemPopupMenu->insertItem( i18n("New Todo..."), this,
452 SLOT (newTodo())); 466 SLOT (newTodo()));
453 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this, 467 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this,
454 SLOT (newSubTodo())); 468 SLOT (newSubTodo()));
455 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this, 469 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this,
456 SLOT (unparentTodo()),0,21); 470 SLOT (unparentTodo()),0,21);
457 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this, 471 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this,
458 SLOT (reparentTodo()),0,22); 472 SLOT (reparentTodo()),0,22);
459 mItemPopupMenu->insertSeparator(); 473 mItemPopupMenu->insertSeparator();
460#if 0 474#if 0
461 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"), 475 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"),
462 this, SLOT( purgeCompleted() ) ); 476 this, SLOT( purgeCompleted() ) );
463 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"), 477 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"),
464 this, SLOT( toggleCompleted() ),0, 33 ); 478 this, SLOT( toggleCompleted() ),0, 33 );
465 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 479 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
466 this, SLOT( toggleQuickTodo() ),0, 34 ); 480 this, SLOT( toggleQuickTodo() ),0, 34 );
467 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 481 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
468 this, SLOT( toggleRunning() ),0, 35 ); 482 this, SLOT( toggleRunning() ),0, 35 );
469 483
470#endif 484#endif
471 mPopupMenu = new QPopupMenu(this); 485 mPopupMenu = new QPopupMenu(this);
472 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this, 486 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this,
473 SLOT (newTodo()),0,1); 487 SLOT (newTodo()),0,1);
474 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"), 488 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"),
475 this, SLOT(purgeCompleted()),0,2); 489 this, SLOT(purgeCompleted()),0,2);
476 mPopupMenu->insertItem(i18n("Show Completed"), 490 mPopupMenu->insertItem(i18n("Show Completed"),
477 this, SLOT( toggleCompleted() ),0,3 ); 491 this, SLOT( toggleCompleted() ),0,3 );
478 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 492 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
479 this, SLOT( toggleQuickTodo() ),0,4 ); 493 this, SLOT( toggleQuickTodo() ),0,4 );
480 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 494 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
481 this, SLOT( toggleRunning() ),0,5 ); 495 this, SLOT( toggleRunning() ),0,5 );
482 mPopupMenu->insertItem(i18n(" set all open","Display all opened"), 496 mPopupMenu->insertItem(i18n(" set all open","Display all opened"),
483 this, SLOT( setAllOpen() ),0,6 ); 497 this, SLOT( setAllOpen() ),0,6 );
484 mPopupMenu->insertItem(i18n(" set all close","Display all closed"), 498 mPopupMenu->insertItem(i18n(" set all close","Display all closed"),
485 this, SLOT( setAllClose() ),0,7 ); 499 this, SLOT( setAllClose() ),0,7 );
486 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"), 500 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"),
487 this, SLOT( setAllFlat() ),0,8 ); 501 this, SLOT( setAllFlat() ),0,8 );
488 mDocPrefs = new DocPrefs( name ); 502 mDocPrefs = new DocPrefs( name );
489 503
490 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu ); 504 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu );
491 mPopupMenu->setCheckable( true ); 505 mPopupMenu->setCheckable( true );
492 mItemPopupMenu->setCheckable( true ); 506 mItemPopupMenu->setCheckable( true );
493 507
494 508
495 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 509 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
496 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 510 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
497 511
498 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 512 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
499 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 513 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
500 514
501 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 515 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
502 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 516 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
503 517
504 518
505 // Double clicking conflicts with opening/closing the subtree 519 // Double clicking conflicts with opening/closing the subtree
506 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ), 520 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ),
507 SLOT( editItem( QListViewItem *) ) ); 521 SLOT( editItem( QListViewItem *) ) );
508 /* 522 /*
509 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *, 523 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *,
510 const QPoint &,int ) ), 524 const QPoint &,int ) ),
511 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 525 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
512 */ 526 */
513 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *, 527 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *,
514 const QPoint &,int ) ), 528 const QPoint &,int ) ),
515 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 529 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
516 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ), 530 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ),
517 SLOT( itemClicked( QListViewItem * ) ) ); 531 SLOT( itemClicked( QListViewItem * ) ) );
518 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ), 532 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ),
519 SLOT( itemDoubleClicked( QListViewItem * ) ) ); 533 SLOT( itemDoubleClicked( QListViewItem * ) ) );
520 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 534 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
521 SLOT( updateView() ) ); 535 SLOT( updateView() ) );
522 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 536 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
523 SLOT( todoModified(Todo *, int) ) ); 537 SLOT( todoModified(Todo *, int) ) );
524 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ), 538 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ),
525 SLOT( itemStateChanged( QListViewItem * ) ) ); 539 SLOT( itemStateChanged( QListViewItem * ) ) );
526 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ), 540 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ),
527 SLOT( itemStateChanged( QListViewItem * ) ) ); 541 SLOT( itemStateChanged( QListViewItem * ) ) );
528 connect( mTodoListView, SIGNAL( paintNeeded() ), 542 connect( mTodoListView, SIGNAL( paintNeeded() ),
529 SLOT( paintNeeded()) ); 543 SLOT( paintNeeded()) );
530 544
531#if 0 545#if 0
532 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)), 546 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)),
533 SLOT(selectionChanged(QListViewItem *))); 547 SLOT(selectionChanged(QListViewItem *)));
534 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)), 548 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)),
535 SLOT(selectionChanged(QListViewItem *))); 549 SLOT(selectionChanged(QListViewItem *)));
536 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)), 550 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)),
537 SLOT(selectionChanged(QListViewItem *))); 551 SLOT(selectionChanged(QListViewItem *)));
538#endif 552#endif
539 553
540 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) )); 554 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) ));
541 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) )); 555 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) ));
542 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) )); 556 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) ));
543 557
544 connect( mTodoListView, SIGNAL(selectionChanged() ), 558 connect( mTodoListView, SIGNAL(selectionChanged() ),
545 SLOT( processSelectionChange() ) ); 559 SLOT( processSelectionChange() ) );
546 connect( mQuickAdd, SIGNAL( returnPressed () ), 560 connect( mQuickAdd, SIGNAL( returnPressed () ),
547 SLOT( addQuickTodo() ) ); 561 SLOT( addQuickTodo() ) );
548 562
549} 563}
550 564
551KOTodoView::~KOTodoView() 565KOTodoView::~KOTodoView()
552{ 566{
553 // delete mKOTodoViewWhatsThis; 567 // delete mKOTodoViewWhatsThis;
554 delete mDocPrefs; 568 delete mDocPrefs;
555} 569}
556QString KOTodoView::getWhatsThisText(QPoint p) 570QString KOTodoView::getWhatsThisText(QPoint p)
557{ 571{
558 KOTodoViewItem* item = ( KOTodoViewItem* ) mTodoListView->itemAt( p ); 572 KOTodoViewItem* item = ( KOTodoViewItem* ) mTodoListView->itemAt( p );
559 if ( item ) 573 if ( item )
560 return KIncidenceFormatter::instance()->getFormattedText( item->todo(), 574 return KIncidenceFormatter::instance()->getFormattedText( item->todo(),
561 KOPrefs::instance()->mWTshowDetails, 575 KOPrefs::instance()->mWTshowDetails,
562 KOPrefs::instance()->mWTshowCreated, 576 KOPrefs::instance()->mWTshowCreated,
563 KOPrefs::instance()->mWTshowChanged); 577 KOPrefs::instance()->mWTshowChanged);
564 return i18n("That is the todo view" ); 578 return i18n("That is the todo view" );
565 579
566} 580}
567 581
568void KOTodoView::jumpToDate () 582void KOTodoView::jumpToDate ()
569{ 583{
570 // if (mActiveItem) { 584 // if (mActiveItem) {
571// mActiveItem->todo()); 585// mActiveItem->todo());
572// if ( mActiveItem->todo()->hasDueDate() ) 586// if ( mActiveItem->todo()->hasDueDate() )
573// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() ); 587// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() );
574} 588}
575void KOTodoView::paintNeeded() 589void KOTodoView::paintNeeded()
576{ 590{
577 if ( mPendingUpdateBeforeRepaint ) { 591 if ( mPendingUpdateBeforeRepaint ) {
578 updateView(); 592 updateView();
579 mPendingUpdateBeforeRepaint = false; 593 mPendingUpdateBeforeRepaint = false;
580 } 594 }
581} 595}
582void KOTodoView::paintEvent(QPaintEvent * pevent) 596void KOTodoView::paintEvent(QPaintEvent * pevent)
583{ 597{
584 if ( mPendingUpdateBeforeRepaint ) { 598 if ( mPendingUpdateBeforeRepaint ) {
585 updateView(); 599 updateView();
586 mPendingUpdateBeforeRepaint = false; 600 mPendingUpdateBeforeRepaint = false;
587 } 601 }
588 KOrg::BaseView::paintEvent( pevent); 602 KOrg::BaseView::paintEvent( pevent);
589} 603}
590 604
591void KOTodoView::updateView() 605void KOTodoView::updateView()
592{ 606{
593 pendingSubtodo = 0; 607 pendingSubtodo = 0;
594 if ( mBlockUpdate ) { 608 if ( mBlockUpdate ) {
595 return; 609 return;
596 } 610 }
597 if ( !isVisible() ) { 611 if ( !isVisible() ) {
598 mPendingUpdateBeforeRepaint = true; 612 mPendingUpdateBeforeRepaint = true;
599 return; 613 return;
600 } 614 }
615 storeCurrentItem();
601 //qDebug("KOTodoView::updateView() %x", this); 616 //qDebug("KOTodoView::updateView() %x", this);
602 if ( isFlatDisplay ) { 617 if ( isFlatDisplay ) {
603 displayAllFlat(); 618 displayAllFlat();
619 resetCurrentItem();
604 return; 620 return;
605 } 621 }
606 //qDebug("update "); 622 //qDebug("update ");
607// kdDebug() << "KOTodoView::updateView()" << endl; 623// kdDebug() << "KOTodoView::updateView()" << endl;
608 QFont fo = KOPrefs::instance()->mTodoViewFont; 624 QFont fo = KOPrefs::instance()->mTodoViewFont;
609 Incidence* oldInc = 0; 625
610 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
611 if (mActiveItem)
612 oldInc = mActiveItem->todo();
613 626
614 mTodoListView->clear(); 627 mTodoListView->clear();
615 if ( mName == "todolistsmall" ) { 628 if ( mName == "todolistsmall" ) {
616 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) { 629 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) {
617 int ps = fo.pointSize() -2; 630 int ps = fo.pointSize() -2;
618 if ( ps > 12 ) 631 if ( ps > 12 )
619 ps -= 2; 632 ps -= 2;
620 fo.setPointSize( ps ); 633 fo.setPointSize( ps );
621 } 634 }
622 } 635 }
623 636
624 mTodoListView->setFont( fo ); 637 mTodoListView->setFont( fo );
625 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont ); 638 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont );
626 //mTodoListView->header()->setMaximumHeight(fm.height()); 639 //mTodoListView->header()->setMaximumHeight(fm.height());
627 QPtrList<Todo> todoList = calendar()->todos(); 640 QPtrList<Todo> todoList = calendar()->todos();
628 641
629/* 642/*
630 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl; 643 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl;
631 Event *t; 644 Event *t;
632 for(t = todoList.first(); t; t = todoList.next()) { 645 for(t = todoList.first(); t; t = todoList.next()) {
633 kdDebug() << " " << t->getSummary() << endl; 646 kdDebug() << " " << t->getSummary() << endl;
634 647
635 if (t->getRelatedTo()) { 648 if (t->getRelatedTo()) {
636 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl; 649 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl;
637 } 650 }
638 651
639 QPtrList<Event> l = t->getRelations(); 652 QPtrList<Event> l = t->getRelations();
640 Event *c; 653 Event *c;
641 for(c=l.first();c;c=l.next()) { 654 for(c=l.first();c;c=l.next()) {
642 kdDebug() << " - relation: " << c->getSummary() << endl; 655 kdDebug() << " - relation: " << c->getSummary() << endl;
643 } 656 }
644 } 657 }
645*/ 658*/
646 659
647 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a 660 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a
648 // specific order of events. That means that we have to generate parent items 661 // specific order of events. That means that we have to generate parent items
649 // recursively for proper hierarchical display of Todos. 662 // recursively for proper hierarchical display of Todos.
650 mTodoMap.clear(); 663 mTodoMap.clear();
651 Todo *todo; 664 Todo *todo;
652 todo = todoList.first();// todo; todo = todoList.next()) { 665 todo = todoList.first();// todo; todo = todoList.next()) {
653 while ( todo ) { 666 while ( todo ) {
654 bool next = true; 667 bool next = true;
655 // qDebug("todo %s ", todo->summary().latin1()); 668 // qDebug("todo %s ", todo->summary().latin1());
656 Incidence *incidence = todo->relatedTo(); 669 Incidence *incidence = todo->relatedTo();
657 while ( incidence ) { 670 while ( incidence ) {
658 if ( incidence->type() == "Todo") { 671 if ( incidence->type() == "Todo") {
659 //qDebug("related %s ",incidence->summary().latin1() ); 672 //qDebug("related %s ",incidence->summary().latin1() );
660 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) { 673 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) {
661 //qDebug("related not found "); 674 //qDebug("related not found ");
662 todoList.remove( ); 675 todoList.remove( );
663 todo = todoList.current(); 676 todo = todoList.current();
664 next = false; 677 next = false;
665 incidence = 0; 678 incidence = 0;
666 679
667 } else { 680 } else {
668 //qDebug("related found "); 681 //qDebug("related found ");
669 incidence = incidence->relatedTo(); 682 incidence = incidence->relatedTo();
670 } 683 }
671 } else 684 } else
672 incidence = 0; 685 incidence = 0;
673 } 686 }
674 if ( next ) 687 if ( next )
675 todo = todoList.next(); 688 todo = todoList.next();
676 } 689 }
677// qDebug("again .... "); 690// qDebug("again .... ");
678// for(todo = todoList.first(); todo; todo = todoList.next()) { 691// for(todo = todoList.first(); todo; todo = todoList.next()) {
679 692
680// qDebug("yytodo %s ", todo->summary().latin1()); 693// qDebug("yytodo %s ", todo->summary().latin1());
681// } 694// }
682 //qDebug("for "); 695 //qDebug("for ");
683 for(todo = todoList.first(); todo; todo = todoList.next()) { 696 for(todo = todoList.first(); todo; todo = todoList.next()) {
684 if (!mTodoMap.contains(todo) && checkTodo( todo ) ) 697 if (!mTodoMap.contains(todo) && checkTodo( todo ) )
685 { 698 {
686 insertTodoItem(todo); 699 insertTodoItem(todo);
687 } 700 }
688 } 701 }
689 //qDebug("for end "); 702 //qDebug("for end ");
690 // Restore opened/closed state 703 // Restore opened/closed state
691 mTodoListView->blockSignals( true ); 704 mTodoListView->blockSignals( true );
692 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() ); 705 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() );
693 mTodoListView->blockSignals( false ); 706 mTodoListView->blockSignals( false );
694 mTodoListView->setFocus(); 707 resetCurrentItem();
695 if ( mTodoListView->firstChild () ) {
696 if ( oldInc ) {
697 KOTodoViewItem* item = (KOTodoViewItem*)mTodoListView->firstChild ();
698 while ( item ) {
699 if ( item->todo() == oldInc ) {
700 mTodoListView->setCurrentItem( item );
701 mTodoListView->ensureItemVisible( item );
702 break;
703 }
704 item = (KOTodoViewItem*)item->itemBelow();
705 }
706 if ( ! item )
707 mTodoListView->setCurrentItem( mTodoListView->firstChild () );
708 } else {
709 mTodoListView->setCurrentItem( mTodoListView->firstChild () );
710 }
711 }
712 processSelectionChange(); 708 processSelectionChange();
713} 709}
714 710
711void KOTodoView::storeCurrentItem()
712{
713 mCurItem = 0;
714 mCurItemRootParent = 0;
715 mCurItemAbove = 0;
716 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
717 if (mActiveItem) {
718 mCurItem = mActiveItem->todo();
719 KOTodoViewItem* activeItemAbove = (KOTodoViewItem*)mActiveItem->itemAbove ();
720 if ( activeItemAbove )
721 mCurItemAbove = activeItemAbove->todo();
722 while ( mActiveItem->parent() != 0 )
723 mActiveItem = (KOTodoViewItem*)mActiveItem->parent();
724 mCurItemRootParent = mActiveItem->todo();
725 }
726 mActiveItem = 0;
727}
728
729void KOTodoView::resetCurrentItem()
730{
731 mTodoListView->setFocus();
732 KOTodoViewItem* foundItem = 0;
733 KOTodoViewItem* foundItemRoot = 0;
734 KOTodoViewItem* foundItemAbove = 0;
735 if ( mTodoListView->firstChild () ) {
736 if ( mCurItem ) {
737 KOTodoViewItem* item = (KOTodoViewItem*)mTodoListView->firstChild ();
738 while ( item ) {
739 if ( item->todo() == mCurItem ) {
740 foundItem = item;
741 break;
742 } else if ( item->todo() == mCurItemAbove ) {
743 foundItemAbove = item;
744
745 } else if ( item->todo() == mCurItemRootParent ) {
746 foundItemRoot = item;
747 }
748 item = (KOTodoViewItem*)item->itemBelow();
749 }
750 if ( ! foundItem ) {
751 if ( foundItemAbove )
752 foundItem = foundItemAbove;
753 else
754 foundItem = foundItemRoot;
755 }
756 }
757 if ( foundItem ) {
758 mTodoListView->setCurrentItem( foundItem );
759 mTodoListView->ensureItemVisible( foundItem );
760 } else {
761 mTodoListView->setCurrentItem( mTodoListView->firstChild () );
762 }
763 }
764 mTodoListView->setFocus();
765}
766//Incidence * mCurItem, *mCurItemRootParent,*mCurItemAbove;
715bool KOTodoView::checkTodo( Todo * todo ) 767bool KOTodoView::checkTodo( Todo * todo )
716{ 768{
717 769
718 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() ) 770 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() )
719 return false; 771 return false;
720 if ( !todo->isCompleted() ) { 772 if ( !todo->isCompleted() ) {
721 if ( todo->hasDueDate() && todo->dtDue().date() <= QDate::currentDate() ) 773 if ( todo->hasDueDate() && todo->dtDue().date() <= QDate::currentDate() )
722 return true; 774 return true;
723 } 775 }
724 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) { 776 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) {
725 if ( todo->hasStartDate() ) 777 if ( todo->hasStartDate() )
726 if ( mNavigator->selectedDates().last() < todo->dtStart().date() ) 778 if ( mNavigator->selectedDates().last() < todo->dtStart().date() )
727 return false; 779 return false;
728 if ( todo->hasDueDate() ) 780 if ( todo->hasDueDate() )
729 if ( mNavigator->selectedDates().first() > todo->dtDue().date() ) 781 if ( mNavigator->selectedDates().first() > todo->dtDue().date() )
730 return false; 782 return false;
731 } 783 }
732 return true; 784 return true;
733} 785}
734 786
735void KOTodoView::restoreItemState( QListViewItem *item ) 787void KOTodoView::restoreItemState( QListViewItem *item )
736{ 788{
737 pendingSubtodo = 0; 789 pendingSubtodo = 0;
738 while( item ) { 790 while( item ) {
739 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 791 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
740 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) ); 792 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) );
741 if( item->childCount() > 0 ) restoreItemState( item->firstChild() ); 793 if( item->childCount() > 0 ) restoreItemState( item->firstChild() );
742 item = item->nextSibling(); 794 item = item->nextSibling();
743 } 795 }
744} 796}
745 797
746 798
747QMap<Todo *,KOTodoViewItem *>::ConstIterator 799QMap<Todo *,KOTodoViewItem *>::ConstIterator
748 KOTodoView::insertTodoItem(Todo *todo) 800 KOTodoView::insertTodoItem(Todo *todo)
749{ 801{
750 802
751// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl; 803// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl;
752 // TODO: Check, if dynmaic cast is necessary 804 // TODO: Check, if dynmaic cast is necessary
753 805
754 pendingSubtodo = 0; 806 pendingSubtodo = 0;
755 Incidence *incidence = todo->relatedTo(); 807 Incidence *incidence = todo->relatedTo();
756 if (incidence && incidence->type() == "Todo") { 808 if (incidence && incidence->type() == "Todo") {
757 Todo *relatedTodo = static_cast<Todo *>(incidence); 809 Todo *relatedTodo = static_cast<Todo *>(incidence);
758 810
759// kdDebug() << " has Related" << endl; 811// kdDebug() << " has Related" << endl;
760 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 812 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
761 itemIterator = mTodoMap.find(relatedTodo); 813 itemIterator = mTodoMap.find(relatedTodo);
762 if (itemIterator == mTodoMap.end()) { 814 if (itemIterator == mTodoMap.end()) {
763// kdDebug() << " related not yet in list" << endl; 815// kdDebug() << " related not yet in list" << endl;
764 itemIterator = insertTodoItem (relatedTodo); 816 itemIterator = insertTodoItem (relatedTodo);
765 } 817 }
766 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem 818 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem
767 // and one into the map. Sure finding is more easy but why? -zecke 819 // and one into the map. Sure finding is more easy but why? -zecke
768 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this); 820 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this);
769 return mTodoMap.insert(todo,todoItem); 821 return mTodoMap.insert(todo,todoItem);
770 } else { 822 } else {
771// kdDebug() << " no Related" << endl; 823// kdDebug() << " no Related" << endl;
772 // see above -zecke 824 // see above -zecke
773 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 825 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
774 return mTodoMap.insert(todo,todoItem); 826 return mTodoMap.insert(todo,todoItem);
775 } 827 }
776} 828}
777 829
778 830
779void KOTodoView::updateConfig() 831void KOTodoView::updateConfig()
780{ 832{
781 updateView(); 833 updateView();
782 mTodoListView->repaintContents(); 834 mTodoListView->repaintContents();
783} 835}
784 836
785QPtrList<Incidence> KOTodoView::selectedIncidences() 837QPtrList<Incidence> KOTodoView::selectedIncidences()
786{ 838{
787 QPtrList<Incidence> selected; 839 QPtrList<Incidence> selected;
788 840
789 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 841 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
790// if (!item) item = mActiveItem; 842// if (!item) item = mActiveItem;
791 if (item) selected.append(item->todo()); 843 if (item) selected.append(item->todo());
792 844
793 return selected; 845 return selected;
794} 846}
795 847
796QPtrList<Todo> KOTodoView::selectedTodos() 848QPtrList<Todo> KOTodoView::selectedTodos()
797{ 849{
798 QPtrList<Todo> selected; 850 QPtrList<Todo> selected;
799 851
800 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 852 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
801// if (!item) item = mActiveItem; 853// if (!item) item = mActiveItem;
802 if (item) selected.append(item->todo()); 854 if (item) selected.append(item->todo());
803 855
804 return selected; 856 return selected;
805} 857}
806 858
807void KOTodoView::changeEventDisplay(Event *, int) 859void KOTodoView::changeEventDisplay(Event *, int)
808{ 860{
809 updateView(); 861 updateView();
810} 862}
811 863
812void KOTodoView::showDates(const QDate &, const QDate &) 864void KOTodoView::showDates(const QDate &, const QDate &)
813{ 865{
814} 866}
815 867
816void KOTodoView::showEvents(QPtrList<Event>) 868void KOTodoView::showEvents(QPtrList<Event>)
817{ 869{
818 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl; 870 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl;
819} 871}
820 872
821void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd, 873void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd,
822 const QDate &td) 874 const QDate &td)
823{ 875{
824#ifndef KORG_NOPRINTER 876#ifndef KORG_NOPRINTER
825 calPrinter->preview(CalPrinter::Todolist, fd, td); 877 calPrinter->preview(CalPrinter::Todolist, fd, td);
826#endif 878#endif
827} 879}
828 880
829void KOTodoView::editItem(QListViewItem *item ) 881void KOTodoView::editItem(QListViewItem *item )
830{ 882{
831 // qDebug("editItem(QListViewItem *item ) "); 883 // qDebug("editItem(QListViewItem *item ) ");
832 emit editTodoSignal(((KOTodoViewItem *)item)->todo()); 884 emit editTodoSignal(((KOTodoViewItem *)item)->todo());
833} 885}
834 886
835void KOTodoView::showItem(QListViewItem *item,const QPoint &,int) 887void KOTodoView::showItem(QListViewItem *item,const QPoint &,int)
836{ 888{
837 emit showTodoSignal(((KOTodoViewItem *)item)->todo()); 889 emit showTodoSignal(((KOTodoViewItem *)item)->todo());
838} 890}
839 891
840void KOTodoView::popupMenu(QListViewItem *item,const QPoint &p,int column) 892void KOTodoView::popupMenu(QListViewItem *item,const QPoint &p,int column)
841{ 893{
842 pendingSubtodo = 0; 894 pendingSubtodo = 0;
843 mActiveItem = (KOTodoViewItem *)item; 895 mActiveItem = (KOTodoViewItem *)item;
844 if (item) { 896 if (item) {
845 switch (column){ 897 switch (column){
846 case 1: 898 case 1:
847 mPriorityPopupMenu->popup(QCursor::pos ()); break; 899 mPriorityPopupMenu->popup(QCursor::pos ()); break;
848 case 2: 900 case 2:
849 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break; 901 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break;
850 case 3: 902 case 3:
851 moveTodo(); 903 moveTodo();
852 break; 904 break;
853 case 8: 905 case 8:
854 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break; 906 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break;
855 default: 907 default:
856 mItemPopupMenu->popup(QCursor::pos()); 908 mItemPopupMenu->popup(QCursor::pos());
857 } 909 }
858 } else mPopupMenu->popup(QCursor::pos()); 910 } else mPopupMenu->popup(QCursor::pos());
859} 911}
860void KOTodoView::newTodo() 912void KOTodoView::newTodo()
861{ 913{
862 emit newTodoSignal(); 914 emit newTodoSignal();
863} 915}
864 916
865void KOTodoView::newSubTodo() 917void KOTodoView::newSubTodo()
866{ 918{
867 if (mActiveItem) { 919 if (mActiveItem) {
868 emit newSubTodoSignal(mActiveItem->todo()); 920 emit newSubTodoSignal(mActiveItem->todo());
869 } 921 }
870} 922}
871void KOTodoView::unparentTodo() 923void KOTodoView::unparentTodo()
872{ 924{
873 if (mActiveItem) { 925 if (mActiveItem) {
874 emit unparentTodoSignal(mActiveItem->todo()); 926 emit unparentTodoSignal(mActiveItem->todo());
875 } 927 }
876} 928}
877 929
878void KOTodoView::reparentTodo() 930void KOTodoView::reparentTodo()
879{ 931{
880 if (mActiveItem) { 932 if (mActiveItem) {
881 qDebug("KOTodoView::reparentTodo() "); 933 qDebug("KOTodoView::reparentTodo() ");
882 topLevelWidget()->setCaption(i18n("Click on new parent item")); 934 topLevelWidget()->setCaption(i18n("Click on new parent item"));
883 pendingSubtodo = mActiveItem; 935 pendingSubtodo = mActiveItem;
884 } 936 }
885} 937}
886void KOTodoView::editTodo() 938void KOTodoView::editTodo()
887{ 939{
888 if (mActiveItem) { 940 if (mActiveItem) {
889 emit editTodoSignal(mActiveItem->todo()); 941 emit editTodoSignal(mActiveItem->todo());
890 } 942 }
891} 943}
892void KOTodoView::cloneTodo() 944void KOTodoView::cloneTodo()
893{ 945{
894 if (mActiveItem) { 946 if (mActiveItem) {
895 emit cloneTodoSignal((Incidence*)mActiveItem->todo()); 947 emit cloneTodoSignal((Incidence*)mActiveItem->todo());
896 } 948 }
897} 949}
898void KOTodoView::cancelTodo() 950void KOTodoView::cancelTodo()
899{ 951{
900 if (mActiveItem) { 952 if (mActiveItem) {
901 emit cancelTodoSignal((Incidence*)mActiveItem->todo()); 953 emit cancelTodoSignal((Incidence*)mActiveItem->todo());
902 } 954 }
903} 955}
904void KOTodoView::moveTodo() 956void KOTodoView::moveTodo()
905{ 957{
906 if (mActiveItem) { 958 if (mActiveItem) {
907 emit moveTodoSignal((Incidence*)mActiveItem->todo()); 959 emit moveTodoSignal((Incidence*)mActiveItem->todo());
908 } 960 }
909} 961}
910void KOTodoView::beamTodo() 962void KOTodoView::beamTodo()
911{ 963{
912 if (mActiveItem) { 964 if (mActiveItem) {
913 emit beamTodoSignal((Incidence*)mActiveItem->todo()); 965 emit beamTodoSignal((Incidence*)mActiveItem->todo());
914 } 966 }
915} 967}
916 968
917 969
918void KOTodoView::showTodo() 970void KOTodoView::showTodo()
919{ 971{
920 if (mActiveItem) { 972 if (mActiveItem) {
921 emit showTodoSignal(mActiveItem->todo()); 973 emit showTodoSignal(mActiveItem->todo());
922 } 974 }
923} 975}
924 976
925void KOTodoView::deleteTodo() 977void KOTodoView::deleteTodo()
926{ 978{
927 if (mActiveItem) { 979 if (mActiveItem) {
928 emit deleteTodoSignal(mActiveItem->todo()); 980 emit deleteTodoSignal(mActiveItem->todo());
929 } 981 }
930} 982}
931 983
932void KOTodoView::setNewPriority(int index) 984void KOTodoView::setNewPriority(int index)
933{ 985{
934 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 986 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
935 mActiveItem->todo()->setPriority(mPriority[index]); 987 mActiveItem->todo()->setPriority(mPriority[index]);
936 mActiveItem->construct(); 988 mActiveItem->construct();
937 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED); 989 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED);
938 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 990 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
939 } 991 }
940} 992}
941 993
942void KOTodoView::setNewPercentage(int index) 994void KOTodoView::setNewPercentage(int index)
943{ 995{
944 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 996 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
945 997
946 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) { 998 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) {
947 mActiveItem->setOn( true ); 999 mActiveItem->setOn( true );
948 return; 1000 return;
949 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) { 1001 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) {
950 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent())); 1002 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent()));
951 if ( par && par->isOn() ) 1003 if ( par && par->isOn() )
952 par->setOn( false ); 1004 par->setOn( false );
953 } 1005 }
954 if (mPercentage[index] == 100) { 1006 if (mPercentage[index] == 100) {
955 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime()); 1007 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime());
956 } else { 1008 } else {
957 mActiveItem->todo()->setCompleted(false); 1009 mActiveItem->todo()->setCompleted(false);
958 } 1010 }
959 mActiveItem->todo()->setPercentComplete(mPercentage[index]); 1011 mActiveItem->todo()->setPercentComplete(mPercentage[index]);
960 mActiveItem->construct(); 1012 mActiveItem->construct();
961 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED); 1013 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED);
962 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 1014 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
963 } 1015 }
964} 1016}
965 1017
966 1018
967QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem) 1019QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem)
968{ 1020{
969 QPopupMenu* tempMenu = new QPopupMenu (this); 1021 QPopupMenu* tempMenu = new QPopupMenu (this);
970 QStringList checkedCategories = todoItem->todo()->categories (); 1022 QStringList checkedCategories = todoItem->todo()->categories ();
971 1023
972 tempMenu->setCheckable (true); 1024 tempMenu->setCheckable (true);
973 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin (); 1025 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin ();
974 it != KOPrefs::instance()->mCustomCategories.end (); 1026 it != KOPrefs::instance()->mCustomCategories.end ();
975 ++it) { 1027 ++it) {
976 int index = tempMenu->insertItem (*it); 1028 int index = tempMenu->insertItem (*it);
977 mCategory[index] = *it; 1029 mCategory[index] = *it;
978 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true); 1030 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true);
979 } 1031 }
980 1032
981 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int))); 1033 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int)));
982 return tempMenu; 1034 return tempMenu;
983 1035
984 1036
985} 1037}
986void KOTodoView::changedCategories(int index) 1038void KOTodoView::changedCategories(int index)
987{ 1039{
988 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 1040 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
989 QStringList categories = mActiveItem->todo()->categories (); 1041 QStringList categories = mActiveItem->todo()->categories ();
990 QString colcat = categories.first(); 1042 QString colcat = categories.first();
991 if (categories.find (mCategory[index]) != categories.end ()) 1043 if (categories.find (mCategory[index]) != categories.end ())
992 categories.remove (mCategory[index]); 1044 categories.remove (mCategory[index]);
993 else 1045 else
994 categories.insert (categories.end(), mCategory[index]); 1046 categories.insert (categories.end(), mCategory[index]);
995 categories.sort (); 1047 categories.sort ();
996 if ( !colcat.isEmpty() ) { 1048 if ( !colcat.isEmpty() ) {
997 if ( categories.find ( colcat ) != categories.end () ) { 1049 if ( categories.find ( colcat ) != categories.end () ) {
998 categories.remove( colcat ); 1050 categories.remove( colcat );
999 categories.prepend( colcat ); 1051 categories.prepend( colcat );
1000 } 1052 }
1001 } 1053 }
1002 mActiveItem->todo()->setCategories (categories); 1054 mActiveItem->todo()->setCategories (categories);
1003 mActiveItem->construct(); 1055 mActiveItem->construct();
1004 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 1056 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
1005 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED); 1057 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED);
1006 } 1058 }
1007} 1059}
1008void KOTodoView::itemDoubleClicked(QListViewItem *item) 1060void KOTodoView::itemDoubleClicked(QListViewItem *item)
1009{ 1061{
1010 if ( pendingSubtodo != 0 ) { 1062 if ( pendingSubtodo != 0 ) {
1011 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 1063 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
1012 } 1064 }
1013 pendingSubtodo = 0; 1065 pendingSubtodo = 0;
1014 if (!item) { 1066 if (!item) {
1015 newTodo(); 1067 newTodo();
1016 return; 1068 return;
1017 } 1069 }
1018 if ( KOPrefs::instance()->mEditOnDoubleClick ) 1070 if ( KOPrefs::instance()->mEditOnDoubleClick )
1019 editItem( item ); 1071 editItem( item );
1020 else 1072 else
1021 showItem( item , QPoint(), 0 ); 1073 showItem( item , QPoint(), 0 );
1022} 1074}
1023void KOTodoView::itemClicked(QListViewItem *item) 1075void KOTodoView::itemClicked(QListViewItem *item)
1024{ 1076{
1025 1077
1026 if (!item) { 1078 if (!item) {
1027 if ( pendingSubtodo != 0 ) { 1079 if ( pendingSubtodo != 0 ) {
1028 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 1080 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
1029 } 1081 }
1030 pendingSubtodo = 0; 1082 pendingSubtodo = 0;
1031 return; 1083 return;
1032 } 1084 }
1033 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 1085 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
1034 if ( pendingSubtodo != 0 ) { 1086 if ( pendingSubtodo != 0 ) {
1035 bool allowReparent = true; 1087 bool allowReparent = true;
1036 QListViewItem *par = item; 1088 QListViewItem *par = item;
1037 while ( par ) { 1089 while ( par ) {
1038 if ( par == pendingSubtodo ) { 1090 if ( par == pendingSubtodo ) {
1039 allowReparent = false; 1091 allowReparent = false;
1040 break; 1092 break;
1041 } 1093 }
1042 par = par->parent(); 1094 par = par->parent();
1043 } 1095 }
1044 if ( !allowReparent ) { 1096 if ( !allowReparent ) {
1045 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!")); 1097 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!"));
1046 qDebug("Recursive reparenting not possible "); 1098 qDebug("Recursive reparenting not possible ");
1047 pendingSubtodo = 0; 1099 pendingSubtodo = 0;
1048 } else { 1100 } else {
1049 Todo* newParent = todoItem->todo(); 1101 Todo* newParent = todoItem->todo();
1050 Todo* newSub = pendingSubtodo->todo(); 1102 Todo* newSub = pendingSubtodo->todo();
1051 pendingSubtodo = 0; 1103 pendingSubtodo = 0;
1052 emit reparentTodoSignal( newParent,newSub ); 1104 emit reparentTodoSignal( newParent,newSub );
1053 return; 1105 return;
1054 } 1106 }
1055 } 1107 }
1056#if 0 1108#if 0
1057 // handled by the item itself 1109 // handled by the item itself
1058 bool completed = todoItem->todo()->isCompleted(); // Completed or not? 1110 bool completed = todoItem->todo()->isCompleted(); // Completed or not?
1059 qDebug("com %d ",completed ); 1111 qDebug("com %d ",completed );
1060 qDebug("itemclicked "); 1112 qDebug("itemclicked ");
1061 if (todoItem->isOn()) { 1113 if (todoItem->isOn()) {
1062 qDebug("on "); 1114 qDebug("on ");
1063 if (!completed) { 1115 if (!completed) {
1064 qDebug("set true "); 1116 qDebug("set true ");
1065 todoItem->todo()->setCompleted(QDateTime::currentDateTime()); 1117 todoItem->todo()->setCompleted(QDateTime::currentDateTime());
1066 } 1118 }
1067 } else { 1119 } else {
1068 qDebug("not on "); 1120 qDebug("not on ");
1069 if (completed) { 1121 if (completed) {
1070 qDebug("set false "); 1122 qDebug("set false ");
1071 todoItem->todo()->setCompleted(false); 1123 todoItem->todo()->setCompleted(false);
1072 } 1124 }
1073 } 1125 }
1074#endif 1126#endif
1075} 1127}
1076 1128
1077void KOTodoView::setDocumentId( const QString &id ) 1129void KOTodoView::setDocumentId( const QString &id )
1078{ 1130{
1079 kdDebug() << "KOTodoView::setDocumentId()" << endl; 1131 kdDebug() << "KOTodoView::setDocumentId()" << endl;
1080 1132
1081 mDocPrefs->setDoc( id ); 1133 mDocPrefs->setDoc( id );
1082} 1134}
1083 1135
1084void KOTodoView::itemStateChanged( QListViewItem *item ) 1136void KOTodoView::itemStateChanged( QListViewItem *item )
1085{ 1137{
1086 if (!item) return; 1138 if (!item) return;
1087 1139
1088 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 1140 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
1089 1141
1090// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl; 1142// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl;
1091 1143
1092 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() ); 1144 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() );
1093} 1145}
1094 1146
1095void KOTodoView::saveLayout(KConfig *config, const QString &group) const 1147void KOTodoView::saveLayout(KConfig *config, const QString &group) const
1096{ 1148{
1097 mTodoListView->saveLayout(config,group); 1149 mTodoListView->saveLayout(config,group);
1098} 1150}
1099 1151
1100void KOTodoView::restoreLayout(KConfig *config, const QString &group) 1152void KOTodoView::restoreLayout(KConfig *config, const QString &group)
1101{ 1153{
1102 mTodoListView->restoreLayout(config,group); 1154 mTodoListView->restoreLayout(config,group);
1103} 1155}
1104 1156
1105void KOTodoView::processSelectionChange() 1157void KOTodoView::processSelectionChange()
1106{ 1158{
1107// kdDebug() << "KOTodoView::processSelectionChange()" << endl; 1159// kdDebug() << "KOTodoView::processSelectionChange()" << endl;
1108 1160
1109 KOTodoViewItem *item = 1161 KOTodoViewItem *item =
1110 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() ); 1162 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() );
1111 1163
1112 if ( !item ) { 1164 if ( !item ) {
1113 emit incidenceSelected( 0 ); 1165 emit incidenceSelected( 0 );
1114 } else { 1166 } else {
1115 emit incidenceSelected( item->todo() ); 1167 emit incidenceSelected( item->todo() );
1116 } 1168 }
1117} 1169}
1118 1170
1119void KOTodoView::modified(bool b) 1171void KOTodoView::modified(bool b)
1120{ 1172{
1121 emit isModified(b); 1173 emit isModified(b);
1122} 1174}
1123void KOTodoView::setTodoModified( Todo* todo ) 1175void KOTodoView::setTodoModified( Todo* todo )
1124{ 1176{
1125 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED ); 1177 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED );
1126} 1178}
1127void KOTodoView::clearSelection() 1179void KOTodoView::clearSelection()
1128{ 1180{
1129 mTodoListView->selectAll( false ); 1181 mTodoListView->selectAll( false );
1130} 1182}
1131void KOTodoView::setAllOpen() 1183void KOTodoView::setAllOpen()
1132{ 1184{
1133 if ( isFlatDisplay ) { 1185 if ( isFlatDisplay ) {
1134 isFlatDisplay = false; 1186 isFlatDisplay = false;
1135 mPopupMenu->setItemChecked( 8,false ); 1187 mPopupMenu->setItemChecked( 8,false );
1136 updateView(); 1188 updateView();
1137 } 1189 }
1138 setOpen(mTodoListView->firstChild(), true); 1190 setOpen(mTodoListView->firstChild(), true);
1139} 1191}
1140void KOTodoView::setAllClose() 1192void KOTodoView::setAllClose()
1141{ 1193{
1142 if ( isFlatDisplay ) { 1194 if ( isFlatDisplay ) {
1143 isFlatDisplay = false; 1195 isFlatDisplay = false;
1144 mPopupMenu->setItemChecked( 8,false ); 1196 mPopupMenu->setItemChecked( 8,false );
1145 updateView(); 1197 updateView();
1146 } 1198 }
1147 setOpen(mTodoListView->firstChild(), false); 1199 setOpen(mTodoListView->firstChild(), false);
1148} 1200}
1149void KOTodoView::setOpen( QListViewItem* item, bool setOpenI) 1201void KOTodoView::setOpen( QListViewItem* item, bool setOpenI)
1150{ 1202{
1151 1203
1152 while ( item ) { 1204 while ( item ) {
1153 setOpen( item->firstChild(), setOpenI ); 1205 setOpen( item->firstChild(), setOpenI );
1154 item->setOpen( setOpenI ); 1206 item->setOpen( setOpenI );
1155 item = item->nextSibling(); 1207 item = item->nextSibling();
1156 } 1208 }
1157} 1209}
1158 1210
1159void KOTodoView::displayAllFlat() 1211void KOTodoView::displayAllFlat()
1160{ 1212{
1161 pendingSubtodo = 0; 1213 pendingSubtodo = 0;
1162 if ( mBlockUpdate ) { 1214 if ( mBlockUpdate ) {
1163 return; 1215 return;
1164 } 1216 }
1165 mPopupMenu->setItemChecked( 8,true ); 1217 mPopupMenu->setItemChecked( 8,true );
1166 isFlatDisplay = true; 1218 isFlatDisplay = true;
1167 QPtrList<Todo> todoList = calendar()->todos(); 1219 QPtrList<Todo> todoList = calendar()->todos();
1168 mTodoMap.clear(); 1220 mTodoMap.clear();
1169 mTodoListView->clear(); 1221 mTodoListView->clear();
1170 Todo *todo; 1222 Todo *todo;
1171 for(todo = todoList.first(); todo; todo = todoList.next()) { 1223 for(todo = todoList.first(); todo; todo = todoList.next()) {
1172 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 1224 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
1173 mTodoMap.insert(todo,todoItem); 1225 mTodoMap.insert(todo,todoItem);
1174 } 1226 }
1175 mTodoListView->setFocus(); 1227 mTodoListView->setFocus();
1176 processSelectionChange(); 1228 processSelectionChange();
1177} 1229}
1178 1230
1179void KOTodoView::setAllFlat() 1231void KOTodoView::setAllFlat()
1180{ 1232{
1181 if ( isFlatDisplay ) { 1233 if ( isFlatDisplay ) {
1182 isFlatDisplay = false; 1234 isFlatDisplay = false;
1183 mPopupMenu->setItemChecked( 8,false ); 1235 mPopupMenu->setItemChecked( 8,false );
1184 updateView(); 1236 updateView();
1185 return; 1237 return;
1186 } 1238 }
1187 displayAllFlat(); 1239 displayAllFlat();
1188} 1240}
1189 1241
1190void KOTodoView::purgeCompleted() 1242void KOTodoView::purgeCompleted()
1191{ 1243{
1192 emit purgeCompletedSignal(); 1244 emit purgeCompletedSignal();
1193} 1245}
1194void KOTodoView::toggleQuickTodo() 1246void KOTodoView::toggleQuickTodo()
1195{ 1247{
1196 if ( mQuickAdd->isVisible() ) { 1248 if ( mQuickAdd->isVisible() ) {
1197 mQuickAdd->hide(); 1249 mQuickAdd->hide();
1198 KOPrefs::instance()->mEnableQuickTodo = false; 1250 KOPrefs::instance()->mEnableQuickTodo = false;
1199 } 1251 }
1200 else { 1252 else {
1201 mQuickAdd->show(); 1253 mQuickAdd->show();
1202 KOPrefs::instance()->mEnableQuickTodo = true; 1254 KOPrefs::instance()->mEnableQuickTodo = true;
1203 } 1255 }
1204 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 1256 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
1205 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 1257 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
1206} 1258}
1207 1259
1208void KOTodoView::toggleRunning() 1260void KOTodoView::toggleRunning()
1209{ 1261{
1210 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos; 1262 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos;
1211 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 1263 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
1212 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 1264 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
1213 updateView(); 1265 updateView();
1214} 1266}
1215 1267
1216void KOTodoView::toggleCompleted() 1268void KOTodoView::toggleCompleted()
1217{ 1269{
1218 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo; 1270 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo;
1219 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 1271 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
1220 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 1272 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
1221 updateView(); 1273 updateView();
1222} 1274}
1223 1275
1224void KOTodoView::addQuickTodo() 1276void KOTodoView::addQuickTodo()
1225{ 1277{
1226 Todo *todo = new Todo(); 1278 Todo *todo = new Todo();
1227 todo->setSummary(mQuickAdd->text()); 1279 todo->setSummary(mQuickAdd->text());
1228 todo->setOrganizer(KOPrefs::instance()->email()); 1280 todo->setOrganizer(KOPrefs::instance()->email());
1229 CalFilter * cf = mCalendar->filter(); 1281 CalFilter * cf = mCalendar->filter();
1230 if ( cf ) { 1282 if ( cf ) {
1231 if ( cf->isEnabled()&& cf->showCategories()) { 1283 if ( cf->isEnabled()&& cf->showCategories()) {
1232 todo->setCategories(cf->categoryList()); 1284 todo->setCategories(cf->categoryList());
1233 } 1285 }
1234 if ( cf->isEnabled() ) 1286 if ( cf->isEnabled() )
1235 todo->setSecrecy( cf->getSecrecy()); 1287 todo->setSecrecy( cf->getSecrecy());
1236 } 1288 }
1237 mCalendar->addTodo(todo); 1289 mCalendar->addTodo(todo);
1238 mQuickAdd->setText(""); 1290 mQuickAdd->setText("");
1239 todoModified (todo, KOGlobals::EVENTADDED ); 1291 todoModified (todo, KOGlobals::EVENTADDED );
1240 updateView(); 1292 updateView();
1241} 1293}
1294
1242void KOTodoView::keyPressEvent ( QKeyEvent * e ) 1295void KOTodoView::keyPressEvent ( QKeyEvent * e )
1243{ 1296{
1244 // e->ignore(); 1297 // e->ignore();
1245 //return; 1298 //return;
1246 //qDebug("KOTodoView::keyPressEvent "); 1299 //qDebug("KOTodoView::keyPressEvent ");
1247 switch ( e->key() ) { 1300 switch ( e->key() ) {
1248 case Qt::Key_Down: 1301 case Qt::Key_Down:
1249 case Qt::Key_Up: 1302 case Qt::Key_Up:
1250 QWidget::keyPressEvent ( e ); 1303 QWidget::keyPressEvent ( e );
1251 break; 1304 break;
1252 1305
1253 case Qt::Key_Q: 1306 case Qt::Key_Q:
1254 toggleQuickTodo(); 1307 toggleQuickTodo();
1255 break; 1308 break;
1256 case Qt::Key_U: 1309 case Qt::Key_U:
1257 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1310 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1258 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1311 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1259 unparentTodo(); 1312 unparentTodo();
1260 e->accept(); 1313 e->accept();
1261 } else 1314 } else
1262 e->ignore(); 1315 e->ignore();
1263 break; 1316 break;
1264 case Qt::Key_S: 1317 case Qt::Key_S:
1265 if ( e->state() == Qt::ControlButton ) { 1318 if ( e->state() == Qt::ControlButton ) {
1266 e->ignore(); 1319 e->ignore();
1267 break; 1320 break;
1268 } 1321 }
1269 if ( e->state() == Qt::ShiftButton ) { 1322 if ( e->state() == Qt::ShiftButton ) {
1270 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1323 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1271 reparentTodo(); 1324 reparentTodo();
1272 e->accept(); 1325 e->accept();
1273 } else 1326 } else
1274 e->ignore(); 1327 e->ignore();
1275 break; 1328 break;
1276 case Qt::Key_P: 1329 case Qt::Key_P:
1277 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1330 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1278 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1331 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1279 if ( pendingSubtodo ) 1332 if ( pendingSubtodo )
1280 itemClicked(mActiveItem); 1333 itemClicked(mActiveItem);
1281 e->accept(); 1334 e->accept();
1282 } else 1335 } else
1283 e->ignore(); 1336 e->ignore();
1284 break; 1337 break;
1285 case Qt::Key_Escape: 1338 case Qt::Key_Escape:
1286 if ( pendingSubtodo ) { 1339 if ( pendingSubtodo ) {
1287 itemClicked(0); 1340 itemClicked(0);
1288 e->accept(); 1341 e->accept();
1289 } else 1342 } else
1290 e->ignore(); 1343 e->ignore();
1291 break; 1344 break;
1292 default: 1345 default:
1293 e->ignore(); 1346 e->ignore();
1294 } 1347 }
1295 1348
1296 if ( true ) { 1349 if ( true ) {
1297 if ( e->key() == Qt::Key_I ) { 1350 if ( e->key() == Qt::Key_I ) {
1298 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem(); 1351 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem();
1299 if ( cn ) { 1352 if ( cn ) {
1300 mActiveItem = cn; 1353 mActiveItem = cn;
1301 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 1354 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
1302 if ( ci ){ 1355 if ( ci ){
1303 showTodo(); 1356 showTodo();
1304 cn = (KOTodoViewItem*)cn->itemBelow(); 1357 cn = (KOTodoViewItem*)cn->itemBelow();
1305 if ( cn ) { 1358 if ( cn ) {
1306 mTodoListView->setCurrentItem ( cn ); 1359 mTodoListView->setCurrentItem ( cn );
1307 mTodoListView->ensureItemVisible ( cn ); 1360 mTodoListView->ensureItemVisible ( cn );
1308 } 1361 }
1309 1362
1310 } 1363 }
1311 } 1364 }
1312 e->accept(); 1365 e->accept();
1313 1366
1314 } 1367 }
1315 1368
1316 } 1369 }
1317 1370
1318} 1371}
1319void KOTodoView::updateTodo( Todo * t, int type ) 1372void KOTodoView::updateTodo( Todo * t, int type )
1320{ 1373{
1321 if ( mBlockUpdate) 1374 if ( mBlockUpdate)
1322 return; 1375 return;
1323 1376
1324 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 1377 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
1325 itemIterator = mTodoMap.find(t); 1378 itemIterator = mTodoMap.find(t);
1326 if (itemIterator != mTodoMap.end()) { 1379 if (itemIterator != mTodoMap.end()) {
1327 (*itemIterator)->construct(); 1380 (*itemIterator)->construct();
1328 } else { 1381 } else {
1329 if ( type == KOGlobals::EVENTADDED ) { 1382 if ( type == KOGlobals::EVENTADDED ) {
1330 insertTodoItem( t ); 1383 insertTodoItem( t );
1331 } 1384 }
1332 } 1385 }
1333 1386
1334} 1387}
1335 1388
1336void KOTodoView::todoModified(Todo * t , int p ) 1389void KOTodoView::todoModified(Todo * t , int p )
1337{ 1390{
1338 mBlockUpdate = true; 1391 mBlockUpdate = true;
1339 emit todoModifiedSignal ( t, p ); 1392 emit todoModifiedSignal ( t, p );
1340 mBlockUpdate = false; 1393 mBlockUpdate = false;
1341} 1394}
diff --git a/korganizer/kotodoview.h b/korganizer/kotodoview.h
index eab0754..e553d0e 100644
--- a/korganizer/kotodoview.h
+++ b/korganizer/kotodoview.h
@@ -1,257 +1,262 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000, 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000, 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23#ifndef KOTODOVIEW_H 23#ifndef KOTODOVIEW_H
24#define KOTODOVIEW_H 24#define KOTODOVIEW_H
25 25
26#include <qfont.h> 26#include <qfont.h>
27#include <qfontmetrics.h> 27#include <qfontmetrics.h>
28#include <qlineedit.h> 28#include <qlineedit.h>
29#include <qptrlist.h> 29#include <qptrlist.h>
30#include <qstrlist.h> 30#include <qstrlist.h>
31#include <qlistbox.h> 31#include <qlistbox.h>
32#include <qpopupmenu.h> 32#include <qpopupmenu.h>
33#include <qlabel.h> 33#include <qlabel.h>
34#include <qmap.h> 34#include <qmap.h>
35#include <qlistview.h> 35#include <qlistview.h>
36#include <klistview.h> 36#include <klistview.h>
37 37
38#include <libkcal/calendar.h> 38#include <libkcal/calendar.h>
39#include <libkcal/todo.h> 39#include <libkcal/todo.h>
40 40
41#include <korganizer/baseview.h> 41#include <korganizer/baseview.h>
42 42
43#include "kotodoviewitem.h" 43#include "kotodoviewitem.h"
44#include "koprefs.h" 44#include "koprefs.h"
45#include "koglobals.h" 45#include "koglobals.h"
46#include "datenavigator.h" 46#include "datenavigator.h"
47 47
48class QDragEnterEvent; 48class QDragEnterEvent;
49class QDragMoveEvent; 49class QDragMoveEvent;
50class QDragLeaveEvent; 50class QDragLeaveEvent;
51class QDropEvent; 51class QDropEvent;
52class KOTodoViewWhatsThis; 52class KOTodoViewWhatsThis;
53 53
54class DocPrefs; 54class DocPrefs;
55 55
56class KOTodoListView : public KListView 56class KOTodoListView : public KListView
57{ 57{
58 Q_OBJECT 58 Q_OBJECT
59 public: 59 public:
60 KOTodoListView(Calendar *,QWidget *parent=0,const char *name=0); 60 KOTodoListView(Calendar *,QWidget *parent=0,const char *name=0);
61 virtual ~KOTodoListView() {} 61 virtual ~KOTodoListView() {}
62 62
63 signals: 63 signals:
64 void paintNeeded(); 64 void paintNeeded();
65 void todoDropped(Todo *, int); 65 void todoDropped(Todo *, int);
66 void double_Clicked(QListViewItem *item); 66 void double_Clicked(QListViewItem *item);
67 void reparentTodoSignal( Todo *,Todo * ); 67 void reparentTodoSignal( Todo *,Todo * );
68 void unparentTodoSignal(Todo *); 68 void unparentTodoSignal(Todo *);
69 void deleteTodo( Todo * ); 69 void deleteTodo( Todo * );
70 protected: 70 protected:
71 void contentsDragEnterEvent(QDragEnterEvent *); 71 void contentsDragEnterEvent(QDragEnterEvent *);
72 void contentsDragMoveEvent(QDragMoveEvent *); 72 void contentsDragMoveEvent(QDragMoveEvent *);
73 void contentsDragLeaveEvent(QDragLeaveEvent *); 73 void contentsDragLeaveEvent(QDragLeaveEvent *);
74 void contentsDropEvent(QDropEvent *); 74 void contentsDropEvent(QDropEvent *);
75 75
76 void contentsMousePressEvent(QMouseEvent *); 76 void contentsMousePressEvent(QMouseEvent *);
77 void contentsMouseMoveEvent(QMouseEvent *); 77 void contentsMouseMoveEvent(QMouseEvent *);
78 void contentsMouseReleaseEvent(QMouseEvent *); 78 void contentsMouseReleaseEvent(QMouseEvent *);
79 void contentsMouseDoubleClickEvent(QMouseEvent *); 79 void contentsMouseDoubleClickEvent(QMouseEvent *);
80 80
81 private: 81 private:
82 void paintEvent(QPaintEvent * pevent); 82 void paintEvent(QPaintEvent * pevent);
83 bool internalDrop; 83 bool internalDrop;
84 QString mName; 84 QString mName;
85 Calendar *mCalendar; 85 Calendar *mCalendar;
86 QPoint mPressPos; 86 QPoint mPressPos;
87 bool mMousePressed; 87 bool mMousePressed;
88 QListViewItem *mOldCurrent; 88 QListViewItem *mOldCurrent;
89 bool mFlagKeyPressed;
89 void keyPressEvent ( QKeyEvent * ) ; 90 void keyPressEvent ( QKeyEvent * ) ;
91 void keyReleaseEvent ( QKeyEvent * ) ;
90}; 92};
91 93
92 94
93/** 95/**
94 This is the line-edit on top of the todoview for fast addition of new todos 96 This is the line-edit on top of the todoview for fast addition of new todos
95*/ 97*/
96class KOQuickTodo : public QLineEdit 98class KOQuickTodo : public QLineEdit
97{ 99{
98 public: 100 public:
99 KOQuickTodo(QWidget *parent=0); 101 KOQuickTodo(QWidget *parent=0);
100 protected: 102 protected:
101 void focusInEvent(QFocusEvent *ev); 103 void focusInEvent(QFocusEvent *ev);
102 void focusOutEvent(QFocusEvent *ev); 104 void focusOutEvent(QFocusEvent *ev);
103}; 105};
104 106
105 107
106/** 108/**
107 This class provides a multi-column list view of todo events. 109 This class provides a multi-column list view of todo events.
108 110
109 @short multi-column list view of todo events. 111 @short multi-column list view of todo events.
110 @author Cornelius Schumacher <schumacher@kde.org> 112 @author Cornelius Schumacher <schumacher@kde.org>
111*/ 113*/
112class KOTodoView : public KOrg::BaseView 114class KOTodoView : public KOrg::BaseView
113{ 115{
114 Q_OBJECT 116 Q_OBJECT
115 public: 117 public:
116 KOTodoView(Calendar *, QWidget* parent=0, const char* name=0 ); 118 KOTodoView(Calendar *, QWidget* parent=0, const char* name=0 );
117 ~KOTodoView(); 119 ~KOTodoView();
118 120
119 QPtrList<Incidence> selectedIncidences(); 121 QPtrList<Incidence> selectedIncidences();
120 QPtrList<Todo> selectedTodos(); 122 QPtrList<Todo> selectedTodos();
121 123
122 DateList selectedDates() 124 DateList selectedDates()
123 {DateList q; 125 {DateList q;
124 return q;} 126 return q;}
125 127
126 /** Return number of shown dates. TodoView does not show dates, */ 128 /** Return number of shown dates. TodoView does not show dates, */
127 int currentDateCount() { return 0; } 129 int currentDateCount() { return 0; }
128 130
129 void printPreview(CalPrinter *calPrinter, const QDate &fd, const QDate &td); 131 void printPreview(CalPrinter *calPrinter, const QDate &fd, const QDate &td);
130 132
131 void setDocumentId( const QString & ); 133 void setDocumentId( const QString & );
132 134
133 void saveLayout(KConfig *config, const QString &group) const; 135 void saveLayout(KConfig *config, const QString &group) const;
134 void restoreLayout(KConfig *config, const QString &group); 136 void restoreLayout(KConfig *config, const QString &group);
135 /** Create a popup menu to set categories */ 137 /** Create a popup menu to set categories */
136 QPopupMenu *getCategoryPopupMenu (KOTodoViewItem *todoItem); 138 QPopupMenu *getCategoryPopupMenu (KOTodoViewItem *todoItem);
137 void setNavigator( DateNavigator* nav ) {mNavigator = nav;} 139 void setNavigator( DateNavigator* nav ) {mNavigator = nav;}
138 QString getWhatsThisText(QPoint p); 140 QString getWhatsThisText(QPoint p);
139 141
140 public slots: 142 public slots:
141 void updateView(); 143 void updateView();
142 void updateConfig(); 144 void updateConfig();
143 145
144 void changeEventDisplay(Event *, int); 146 void changeEventDisplay(Event *, int);
145 147
146 void showDates(const QDate &start, const QDate &end); 148 void showDates(const QDate &start, const QDate &end);
147 void showEvents(QPtrList<Event> eventList); 149 void showEvents(QPtrList<Event> eventList);
148 150
149 void clearSelection(); 151 void clearSelection();
150 void jumpToDate (); 152 void jumpToDate ();
151 153
152 void editItem(QListViewItem *item); 154 void editItem(QListViewItem *item);
153 void showItem(QListViewItem *item,const QPoint &,int); 155 void showItem(QListViewItem *item,const QPoint &,int);
154 void popupMenu(QListViewItem *item,const QPoint &,int); 156 void popupMenu(QListViewItem *item,const QPoint &,int);
155 void newTodo(); 157 void newTodo();
156 void newSubTodo(); 158 void newSubTodo();
157 void unparentTodo(); 159 void unparentTodo();
158 void reparentTodo(); 160 void reparentTodo();
159 void showTodo(); 161 void showTodo();
160 void editTodo(); 162 void editTodo();
161 void cloneTodo(); 163 void cloneTodo();
162 void cancelTodo(); 164 void cancelTodo();
163 void moveTodo(); 165 void moveTodo();
164 void beamTodo(); 166 void beamTodo();
165 void deleteTodo(); 167 void deleteTodo();
166 168
167 void setNewPriority(int); 169 void setNewPriority(int);
168 void setNewPercentage(int); 170 void setNewPercentage(int);
169 void changedCategories(int); 171 void changedCategories(int);
170 172
171 void setAllOpen(); 173 void setAllOpen();
172 void setAllClose(); 174 void setAllClose();
173 void setAllFlat(); 175 void setAllFlat();
174 void displayAllFlat(); 176 void displayAllFlat();
175 177
176 void purgeCompleted(); 178 void purgeCompleted();
177 void toggleCompleted(); 179 void toggleCompleted();
178 void toggleRunning(); 180 void toggleRunning();
179 void toggleQuickTodo(); 181 void toggleQuickTodo();
180 void updateTodo( Todo *, int ); 182 void updateTodo( Todo *, int );
181 183
182 void itemClicked(QListViewItem *); 184 void itemClicked(QListViewItem *);
183 void itemStateChanged(QListViewItem *); 185 void itemStateChanged(QListViewItem *);
184 void modified(bool); 186 void modified(bool);
185 void itemDoubleClicked(QListViewItem *item); 187 void itemDoubleClicked(QListViewItem *item);
186 188
187 signals: 189 signals:
188 void newTodoSignal(); 190 void newTodoSignal();
189 void newSubTodoSignal(Todo *); 191 void newSubTodoSignal(Todo *);
190 void unparentTodoSignal(Todo *); 192 void unparentTodoSignal(Todo *);
191 void reparentTodoSignal( Todo *,Todo * ); 193 void reparentTodoSignal( Todo *,Todo * );
192 void showTodoSignal(Todo *); 194 void showTodoSignal(Todo *);
193 195
194 void editTodoSignal(Todo *); 196 void editTodoSignal(Todo *);
195 void deleteTodoSignal(Todo *); 197 void deleteTodoSignal(Todo *);
196 void todoModifiedSignal (Todo *, int); 198 void todoModifiedSignal (Todo *, int);
197 199
198 void isModified(bool); 200 void isModified(bool);
199 void cloneTodoSignal( Incidence * ); 201 void cloneTodoSignal( Incidence * );
200 void cancelTodoSignal( Incidence * ); 202 void cancelTodoSignal( Incidence * );
201 void moveTodoSignal( Incidence * ); 203 void moveTodoSignal( Incidence * );
202 void beamTodoSignal( Incidence * ); 204 void beamTodoSignal( Incidence * );
203 void purgeCompletedSignal(); 205 void purgeCompletedSignal();
204 206
205 protected slots: 207 protected slots:
206 void paintNeeded(); 208 void paintNeeded();
207 void processSelectionChange(); 209 void processSelectionChange();
208 void addQuickTodo(); 210 void addQuickTodo();
209 void setTodoModified( Todo* ); 211 void setTodoModified( Todo* );
210 void todoModified(Todo *, int ); 212 void todoModified(Todo *, int );
211 213
212 private: 214 private:
213 /* 215 /*
214 * the TodoEditor approach is rather unscaling in the long 216 * the TodoEditor approach is rather unscaling in the long
215 * run. 217 * run.
216 * Korganizer keeps it in memory and we need to update 218 * Korganizer keeps it in memory and we need to update
217 * 1. make KOTodoViewItem a QObject again? 219 * 1. make KOTodoViewItem a QObject again?
218 * 2. add a public method for setting one todo modified? 220 * 2. add a public method for setting one todo modified?
219 * 3. add a private method for setting a todo modified + friend here? 221 * 3. add a private method for setting a todo modified + friend here?
220 * -- zecke 2002-07-08 222 * -- zecke 2002-07-08
221 */ 223 */
222 KOTodoViewWhatsThis* mKOTodoViewWhatsThis; 224 KOTodoViewWhatsThis* mKOTodoViewWhatsThis;
223 friend class KOTodoListView; 225 friend class KOTodoListView;
224 void paintEvent(QPaintEvent * pevent); 226 void paintEvent(QPaintEvent * pevent);
225 bool mPendingUpdateBeforeRepaint; 227 bool mPendingUpdateBeforeRepaint;
226 friend class KOTodoViewItem; 228 friend class KOTodoViewItem;
227 QMap<Todo *,KOTodoViewItem *>::ConstIterator insertTodoItem(Todo *todo); 229 QMap<Todo *,KOTodoViewItem *>::ConstIterator insertTodoItem(Todo *todo);
228 void restoreItemState( QListViewItem * ); 230 void restoreItemState( QListViewItem * );
229 231
230 bool checkTodo( Todo * ); 232 bool checkTodo( Todo * );
231 bool isFlatDisplay; 233 bool isFlatDisplay;
232 void setOpen( QListViewItem*, bool setOpen); 234 void setOpen( QListViewItem*, bool setOpen);
233 KOTodoListView *mTodoListView; 235 KOTodoListView *mTodoListView;
234 QPopupMenu *mItemPopupMenu; 236 QPopupMenu *mItemPopupMenu;
235 QPopupMenu *mPopupMenu; 237 QPopupMenu *mPopupMenu;
236 QPopupMenu *mPriorityPopupMenu; 238 QPopupMenu *mPriorityPopupMenu;
237 QPopupMenu *mPercentageCompletedPopupMenu; 239 QPopupMenu *mPercentageCompletedPopupMenu;
238 QPopupMenu *mCategoryPopupMenu; 240 QPopupMenu *mCategoryPopupMenu;
239 241
240 QMap<int, int> mPercentage; 242 QMap<int, int> mPercentage;
241 QMap<int, int> mPriority; 243 QMap<int, int> mPriority;
242 QMap<int, QString> mCategory; 244 QMap<int, QString> mCategory;
243 KOTodoViewItem *mActiveItem; 245 KOTodoViewItem *mActiveItem;
244 246
245 QMap<Todo *,KOTodoViewItem *> mTodoMap; 247 QMap<Todo *,KOTodoViewItem *> mTodoMap;
246 QString mName; 248 QString mName;
247 249
248 DocPrefs *mDocPrefs; 250 DocPrefs *mDocPrefs;
249 QString mCurrentDoc; 251 QString mCurrentDoc;
250 KOQuickTodo *mQuickAdd; 252 KOQuickTodo *mQuickAdd;
251 bool mBlockUpdate; 253 bool mBlockUpdate;
252 void keyPressEvent ( QKeyEvent * ) ; 254 void keyPressEvent ( QKeyEvent * ) ;
253 KOTodoViewItem * pendingSubtodo; 255 KOTodoViewItem * pendingSubtodo;
254 DateNavigator* mNavigator; 256 DateNavigator* mNavigator;
257 void storeCurrentItem();
258 void resetCurrentItem();
259 Incidence * mCurItem, *mCurItemRootParent,*mCurItemAbove;
255}; 260};
256 261
257#endif 262#endif
diff --git a/korganizer/koviewmanager.cpp b/korganizer/koviewmanager.cpp
index f97aa98..c442d0b 100644
--- a/korganizer/koviewmanager.cpp
+++ b/korganizer/koviewmanager.cpp
@@ -1,827 +1,829 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Copyright (c) 2001 4 Copyright (c) 2001
5 Cornelius Schumacher <schumacher@kde.org> 5 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
15 GNU General Public License for more details. 15 GNU General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 20
21 As a special exception, permission is given to link this program 21 As a special exception, permission is given to link this program
22 with any edition of Qt, and distribute the resulting executable, 22 with any edition of Qt, and distribute the resulting executable,
23 without including the source code for Qt in the source distribution. 23 without including the source code for Qt in the source distribution.
24*/ 24*/
25 25
26#include <qwidgetstack.h> 26#include <qwidgetstack.h>
27 27
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#ifndef DESKTOP_VERSION 30#ifndef DESKTOP_VERSION
31#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
32#else 32#else
33#include <qapplication.h> 33#include <qapplication.h>
34#endif 34#endif
35#include <qdatetime.h> 35#include <qdatetime.h>
36#include "calendarview.h" 36#include "calendarview.h"
37#include "datenavigator.h" 37#include "datenavigator.h"
38#include "kotodoview.h" 38#include "kotodoview.h"
39#include "koagendaview.h" 39#include "koagendaview.h"
40#include "kodialogmanager.h" 40#include "kodialogmanager.h"
41#include "komonthview.h" 41#include "komonthview.h"
42#include "kolistview.h" 42#include "kolistview.h"
43#include "kowhatsnextview.h" 43#include "kowhatsnextview.h"
44#include "kojournalview.h" 44#include "kojournalview.h"
45#include "kotimespanview.h" 45#include "kotimespanview.h"
46#include "koprefs.h" 46#include "koprefs.h"
47#include "navigatorbar.h" 47#include "navigatorbar.h"
48#include "kdatenavigator.h" 48#include "kdatenavigator.h"
49 49
50#include "koviewmanager.h" 50#include "koviewmanager.h"
51//extern bool externFlagMonthviewBlockPainting; 51//extern bool externFlagMonthviewBlockPainting;
52 52
53//bool globalFlagBlockPainting = false; 53//bool globalFlagBlockPainting = false;
54int globalFlagBlockAgenda = 0; 54int globalFlagBlockAgenda = 0;
55int globalFlagBlockLabel = 0; 55int globalFlagBlockLabel = 0;
56int globalFlagBlockAgendaItemPaint = 1; 56int globalFlagBlockAgendaItemPaint = 1;
57int globalFlagBlockAgendaItemUpdate = 1; 57int globalFlagBlockAgendaItemUpdate = 1;
58 58
59 59
60KOViewManager::KOViewManager( CalendarView *mainView ) : 60KOViewManager::KOViewManager( CalendarView *mainView ) :
61 QObject(), mMainView( mainView ) 61 QObject(), mMainView( mainView )
62{ 62{
63 mCurrentView = 0; 63 mCurrentView = 0;
64 flagResetViewChangeDate = 0; 64 flagResetViewChangeDate = 0;
65 mWhatsNextView = 0; 65 mWhatsNextView = 0;
66 mTodoView = 0; 66 mTodoView = 0;
67 mAgendaView = 0; 67 mAgendaView = 0;
68 mMonthView = 0; 68 mMonthView = 0;
69 mListView = 0; 69 mListView = 0;
70 mJournalView = 0; 70 mJournalView = 0;
71 mTimeSpanView = 0; 71 mTimeSpanView = 0;
72 mCurrentAgendaView = 0 ; 72 mCurrentAgendaView = 0 ;
73 mFlagShowNextxDays = false; 73 mFlagShowNextxDays = false;
74} 74}
75 75
76KOViewManager::~KOViewManager() 76KOViewManager::~KOViewManager()
77{ 77{
78} 78}
79 79
80 80
81KOrg::BaseView *KOViewManager::currentView() 81KOrg::BaseView *KOViewManager::currentView()
82{ 82{
83 return mCurrentView; 83 return mCurrentView;
84} 84}
85 85
86void KOViewManager::readSettings(KConfig *config) 86void KOViewManager::readSettings(KConfig *config)
87{ 87{
88 config->setGroup("General"); 88 config->setGroup("General");
89 QString view = config->readEntry("Current View"); 89 QString view = config->readEntry("Current View");
90 if (view == "WhatsNext") showWhatsNextView(); 90 if (view == "WhatsNext") showWhatsNextView();
91 else if (view == "Month") { 91 else if (view == "Month") {
92 if ( !KOPrefs::instance()->mMonthViewWeek ) 92 if ( !KOPrefs::instance()->mMonthViewWeek )
93 showMonthView(); 93 showMonthView();
94 else 94 else
95 showMonthViewWeek(); 95 showMonthViewWeek();
96 } 96 }
97 else if (view == "List") showListView(); 97 else if (view == "List") showListView();
98 else if (view == "Journal") showJournalView(); 98 else if (view == "Journal") showJournalView();
99 else if (view == "TimeSpan") showTimeSpanView(); 99 else if (view == "TimeSpan") showTimeSpanView();
100 else if (view == "Todo") showTodoView(); 100 else if (view == "Todo") showTodoView();
101 else { 101 else {
102 config->setGroup( "Views" ); 102 config->setGroup( "Views" );
103 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 103 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
104 mCurrentAgendaView = dateCount; 104 mCurrentAgendaView = dateCount;
105 showAgendaView(); 105 showAgendaView();
106 mCurrentAgendaView = dateCount; 106 mCurrentAgendaView = dateCount;
107#ifdef DESKTOP_VERSION 107#ifdef DESKTOP_VERSION
108 QTimer::singleShot( 1000, mAgendaView, SLOT ( setInitStartHour() ) ); 108 QTimer::singleShot( 1000, mAgendaView, SLOT ( setInitStartHour() ) );
109#endif 109#endif
110 } 110 }
111} 111}
112 112
113void KOViewManager::showDateView( int view, QDate date) 113void KOViewManager::showDateView( int view, QDate date)
114{ 114{
115 static int lastMode = 0; 115 static int lastMode = 0;
116 static int lastCount = 0; 116 static int lastCount = 0;
117 static bool lastNDMode = false; 117 static bool lastNDMode = false;
118 static QDate lastDate; 118 static QDate lastDate;
119 //qDebug("date %d %s", view, date.toString().latin1()); 119 //qDebug("date %d %s", view, date.toString().latin1());
120 120
121 if (view != 9) 121 if (view != 9)
122 lastMode = 0; 122 lastMode = 0;
123 //qDebug("%d %d ", lastNDMode, mFlagShowNextxDays ); 123 //qDebug("%d %d ", lastNDMode, mFlagShowNextxDays );
124 bool savemFlagShowNextxDays = mFlagShowNextxDays; 124 bool savemFlagShowNextxDays = mFlagShowNextxDays;
125 mFlagShowNextxDays = false; 125 mFlagShowNextxDays = false;
126 if ( view == 3 ) { 126 if ( view == 3 ) {
127 //mCurrentAgendaView = 1 ; 127 //mCurrentAgendaView = 1 ;
128 lastDate = mMainView->dateNavigator()->selectedDates().first(); 128 lastDate = mMainView->dateNavigator()->selectedDates().first();
129 lastCount = mMainView->dateNavigator()->selectedDates().count(); 129 lastCount = mMainView->dateNavigator()->selectedDates().count();
130 lastNDMode = savemFlagShowNextxDays; 130 lastNDMode = savemFlagShowNextxDays;
131 mMainView->dateNavigator()->selectDate( date ); 131 mMainView->dateNavigator()->selectDate( date );
132 lastMode = 1; 132 lastMode = 1;
133 mCurrentAgendaView = 1 ; 133 mCurrentAgendaView = 1 ;
134 } else if (view == 4 ) { 134 } else if (view == 4 ) {
135 mCurrentAgendaView = 7 ; 135 mCurrentAgendaView = 7 ;
136 mMainView->dateNavigator()->selectDates( date, 7 ); 136 mMainView->dateNavigator()->selectDates( date, 7 );
137 } else if (view == 5 ) { 137 } else if (view == 5 ) {
138 mCurrentAgendaView = 14 ; 138 mCurrentAgendaView = 14 ;
139 mMainView->dateNavigator()->selectDates( date, 14); 139 mMainView->dateNavigator()->selectDates( date, 14);
140 } else if (view == 6 ) { 140 } else if (view == 6 ) {
141 //mMainView->dateNavigator()->selectDates( date, 7 ); 141 resetDateSilent( date,1);
142 showMonthView(); 142 showMonthView();
143 } else if (view == 7 ) { 143 } else if (view == 7 ) {
144 mMainView->dateNavigator()->selectDate( date ); 144 mMainView->dateNavigator()->selectDate( date );
145 showJournalView(); 145 showJournalView();
146 } else if (view == 8 ) { 146 } else if (view == 8 ) {
147 globalFlagBlockAgenda = 1; 147 globalFlagBlockAgenda = 1;
148 if ( mCurrentAgendaView != 3 ) 148 if ( mCurrentAgendaView != 3 )
149 mCurrentAgendaView = -1; 149 mCurrentAgendaView = -1;
150 showAgendaView(KOPrefs::instance()->mFullViewMonth); 150 showAgendaView(KOPrefs::instance()->mFullViewMonth);
151 globalFlagBlockAgenda = 2; 151 globalFlagBlockAgenda = 2;
152 mMainView->dateNavigator()->selectDates( date , 152 mMainView->dateNavigator()->selectDates( date ,
153 KOPrefs::instance()->mNextXDays ); 153 KOPrefs::instance()->mNextXDays );
154 mFlagShowNextxDays = true; 154 mFlagShowNextxDays = true;
155 mCurrentAgendaView = 3 ; 155 mCurrentAgendaView = 3 ;
156 } if (view == 9) { // return behaviour, for getting back from mode == 3 (single day mode ) 156 } if (view == 9) { // return behaviour, for getting back from mode == 3 (single day mode )
157 if ( lastMode ) { 157 if ( lastMode ) {
158 mCurrentAgendaView = lastCount ; 158 mCurrentAgendaView = lastCount ;
159 mMainView->dateNavigator()->selectDates( lastDate, lastCount); 159 mMainView->dateNavigator()->selectDates( lastDate, lastCount);
160 mFlagShowNextxDays = lastNDMode; 160 mFlagShowNextxDays = lastNDMode;
161 if ( mFlagShowNextxDays ) { 161 if ( mFlagShowNextxDays ) {
162 mCurrentAgendaView = 3 ; 162 mCurrentAgendaView = 3 ;
163 } 163 }
164 } else 164 } else
165 showWeekView(); 165 showWeekView();
166 } else if (view == 10) { 166 } else if (view == 10) {
167 mMainView->dateNavigator()->selectDates( date,mMainView->dateNavigator()->selectedDates().count() ); 167 mMainView->dateNavigator()->selectDates( date,mMainView->dateNavigator()->selectedDates().count() );
168 } 168 }
169} 169}
170 170
171 171
172 172
173void KOViewManager::writeSettings(KConfig *config) 173void KOViewManager::writeSettings(KConfig *config)
174{ 174{
175 config->setGroup("General"); 175 config->setGroup("General");
176 176
177 QString view; 177 QString view;
178 if (mCurrentView == mWhatsNextView) view = "WhatsNext"; 178 if (mCurrentView == mWhatsNextView) view = "WhatsNext";
179 else if (mCurrentView == mMonthView) view = "Month"; 179 else if (mCurrentView == mMonthView) view = "Month";
180 else if (mCurrentView == mListView) view = "List"; 180 else if (mCurrentView == mListView) view = "List";
181 else if (mCurrentView == mJournalView) view = "Journal"; 181 else if (mCurrentView == mJournalView) view = "Journal";
182 else if (mCurrentView == mTimeSpanView) view = "TimeSpan"; 182 else if (mCurrentView == mTimeSpanView) view = "TimeSpan";
183 else if (mCurrentView == mTodoView) view = "Todo"; 183 else if (mCurrentView == mTodoView) view = "Todo";
184 else view = "Agenda"; 184 else view = "Agenda";
185 185
186 config->writeEntry("Current View",view); 186 config->writeEntry("Current View",view);
187 187
188 if (mAgendaView) { 188 if (mAgendaView) {
189 mAgendaView->writeSettings(config); 189 mAgendaView->writeSettings(config);
190 } 190 }
191 if (mTimeSpanView) { 191 if (mTimeSpanView) {
192 mTimeSpanView->writeSettings(config); 192 mTimeSpanView->writeSettings(config);
193 } 193 }
194 if (mListView) { 194 if (mListView) {
195 mListView->writeSettings(config); 195 mListView->writeSettings(config);
196 } 196 }
197 if (mTodoView) { 197 if (mTodoView) {
198 mTodoView->saveLayout(config,"Todo View"); 198 mTodoView->saveLayout(config,"Todo View");
199 } 199 }
200} 200}
201void KOViewManager::showNextView() 201void KOViewManager::showNextView()
202{ 202{
203 static int selecteddatescount = 0; 203 static int selecteddatescount = 0;
204 static QDate selecteddate = QDate ( 2000, 1, 1 ); 204 static QDate selecteddate = QDate ( 2000, 1, 1 );
205 static QDate baseCycleDate = QDate ( 2000, 1, 1 ); 205 static QDate baseCycleDate = QDate ( 2000, 1, 1 );
206 int newCount = mMainView->dateNavigator()->selectedDates().count(); 206 int newCount = mMainView->dateNavigator()->selectedDates().count();
207 if ( selecteddatescount != newCount && flagResetViewChangeDate == 0 ) { 207 if ( selecteddatescount != newCount && flagResetViewChangeDate == 0 ) {
208 flagResetViewChangeDate = 1; 208 flagResetViewChangeDate = 1;
209 } 209 }
210 if ( selecteddate != mMainView->dateNavigator()->selectedDates().first() ) 210 if ( selecteddate != mMainView->dateNavigator()->selectedDates().first() )
211 flagResetViewChangeDate = 1; 211 flagResetViewChangeDate = 1;
212 if ( flagResetViewChangeDate > 0 ) { 212 if ( flagResetViewChangeDate > 0 ) {
213 baseCycleDate = mMainView->dateNavigator()->selectedDates().first(); 213 baseCycleDate = mMainView->dateNavigator()->selectedDates().first();
214 //qDebug("newCycle "); 214 //qDebug("newCycle ");
215 } 215 }
216 if (mCurrentView == mWhatsNextView) goto NEXT_X; 216 if (mCurrentView == mWhatsNextView) goto NEXT_X;
217 if (mCurrentView == mAgendaView && mFlagShowNextxDays) goto JOURNAL; 217 if (mCurrentView == mAgendaView && mFlagShowNextxDays) goto JOURNAL;
218 if (mCurrentView == mJournalView ) goto DAY_1; 218 if (mCurrentView == mJournalView ) goto DAY_1;
219 if (mCurrentView == mAgendaView && mCurrentAgendaView == 1 ) goto DAY_5; 219 if (mCurrentView == mAgendaView && mCurrentAgendaView == 1 ) goto DAY_5;
220 if (mCurrentView == mAgendaView && mCurrentAgendaView == 5 ) goto DAY_7; 220 if (mCurrentView == mAgendaView && mCurrentAgendaView == 5 ) goto DAY_7;
221 if (mCurrentView == mAgendaView ) goto DAY_6; 221 if (mCurrentView == mAgendaView ) goto DAY_6;
222 if (mCurrentView == mMonthView && KOPrefs::instance()->mMonthViewWeek) goto MONTH; 222 if (mCurrentView == mMonthView && KOPrefs::instance()->mMonthViewWeek) goto MONTH;
223 if (mCurrentView == mMonthView ) goto LIST; 223 if (mCurrentView == mMonthView ) goto LIST;
224 if (mCurrentView == mListView ) goto TODO; 224 if (mCurrentView == mListView ) goto TODO;
225 // if (mCurrentView == mTodoView ) goto NEXT; 225 // if (mCurrentView == mTodoView ) goto NEXT;
226 NEXT: 226 NEXT:
227 if ( KOPrefs::instance()->mShowIconNext ) { showWhatsNextView();goto ENTE ;} 227 if ( KOPrefs::instance()->mShowIconNext ) { showWhatsNextView();goto ENTE ;}
228 NEXT_X: 228 NEXT_X:
229 if ( KOPrefs::instance()->mShowIconNextDays ) { 229 if ( KOPrefs::instance()->mShowIconNextDays ) {
230 globalFlagBlockAgenda = 1; 230 globalFlagBlockAgenda = 1;
231 if ( mCurrentAgendaView != 3 ) 231 if ( mCurrentAgendaView != 3 )
232 mCurrentAgendaView = -1; 232 mCurrentAgendaView = -1;
233 showAgendaView(KOPrefs::instance()->mFullViewMonth); 233 showAgendaView(KOPrefs::instance()->mFullViewMonth);
234 globalFlagBlockAgenda = 2; 234 globalFlagBlockAgenda = 2;
235 mMainView->dateNavigator()->selectDates( baseCycleDate , 235 mMainView->dateNavigator()->selectDates( baseCycleDate ,
236 KOPrefs::instance()->mNextXDays ); 236 KOPrefs::instance()->mNextXDays );
237 mFlagShowNextxDays = true; 237 mFlagShowNextxDays = true;
238 mCurrentAgendaView = 3 ; 238 mCurrentAgendaView = 3 ;
239 goto ENTE ; 239 goto ENTE ;
240 } 240 }
241 JOURNAL: 241 JOURNAL:
242 if ( KOPrefs::instance()->mShowIconJournal ) { 242 if ( KOPrefs::instance()->mShowIconJournal ) {
243 resetDateSilent( baseCycleDate , 1 ); 243 resetDateSilent( baseCycleDate , 1 );
244 showJournalView() ;goto ENTE ;} 244 showJournalView() ;goto ENTE ;}
245 DAY_1: 245 DAY_1:
246 if ( KOPrefs::instance()->mShowIconDay1 ) { 246 if ( KOPrefs::instance()->mShowIconDay1 ) {
247 resetDateSilent( baseCycleDate , 2 ); 247 resetDateSilent( baseCycleDate , 2 );
248 showDayView() ;goto ENTE ;} 248 showDayView() ;goto ENTE ;}
249 DAY_5: 249 DAY_5:
250 if ( KOPrefs::instance()->mShowIconDay5 ) { 250 if ( KOPrefs::instance()->mShowIconDay5 ) {
251 resetDateSilent( baseCycleDate , 2 ); 251 resetDateSilent( baseCycleDate , 2 );
252 showWorkWeekView() ;goto ENTE ;} 252 showWorkWeekView() ;goto ENTE ;}
253 DAY_7: 253 DAY_7:
254 if ( KOPrefs::instance()->mShowIconDay7 ) { 254 if ( KOPrefs::instance()->mShowIconDay7 ) {
255 resetDateSilent( baseCycleDate , 2 ); 255 resetDateSilent( baseCycleDate , 2 );
256 showWeekView();goto ENTE ;} 256 showWeekView();goto ENTE ;}
257 DAY_6: 257 DAY_6:
258 if ( KOPrefs::instance()->mShowIconDay6 ) { 258 if ( KOPrefs::instance()->mShowIconDay6 ) {
259 resetDateSilent( baseCycleDate , 2 ); 259 resetDateSilent( baseCycleDate , 2 );
260 showMonthViewWeek();goto ENTE ;} 260 showMonthViewWeek();goto ENTE ;}
261 MONTH: 261 MONTH:
262 if ( KOPrefs::instance()->mShowIconMonth ) { 262 if ( KOPrefs::instance()->mShowIconMonth ) {
263 resetDateSilent( baseCycleDate , 2 ); 263 resetDateSilent( baseCycleDate , 2 );
264 showMonthView();goto ENTE ;} 264 showMonthView();goto ENTE ;}
265 LIST: 265 LIST:
266 if ( KOPrefs::instance()->mShowIconList ) { 266 if ( KOPrefs::instance()->mShowIconList ) {
267 resetDateSilent( baseCycleDate , 2 ); 267 resetDateSilent( baseCycleDate , 2 );
268 showListView() ;goto ENTE ;} 268 showListView() ;goto ENTE ;}
269 TODO: 269 TODO:
270 if ( KOPrefs::instance()->mShowIconTodoview ) { showTodoView() ;goto ENTE ;} 270 if ( KOPrefs::instance()->mShowIconTodoview ) { showTodoView() ;goto ENTE ;}
271 if ( KOPrefs::instance()->mShowIconNext ) { goto NEXT ;} 271 if ( KOPrefs::instance()->mShowIconNext ) { goto NEXT ;}
272 if ( KOPrefs::instance()->mShowIconNextDays ) { goto NEXT_X ;} 272 if ( KOPrefs::instance()->mShowIconNextDays ) { goto NEXT_X ;}
273 if ( KOPrefs::instance()->mShowIconJournal ) { goto JOURNAL;} 273 if ( KOPrefs::instance()->mShowIconJournal ) { goto JOURNAL;}
274 if ( KOPrefs::instance()->mShowIconDay1 ) { goto DAY_1 ;} 274 if ( KOPrefs::instance()->mShowIconDay1 ) { goto DAY_1 ;}
275 if ( KOPrefs::instance()->mShowIconDay5 ) { goto DAY_5 ;} 275 if ( KOPrefs::instance()->mShowIconDay5 ) { goto DAY_5 ;}
276 if ( KOPrefs::instance()->mShowIconDay7 ) { goto DAY_7 ;} 276 if ( KOPrefs::instance()->mShowIconDay7 ) { goto DAY_7 ;}
277 if ( KOPrefs::instance()->mShowIconDay6 ) { goto DAY_6 ;} 277 if ( KOPrefs::instance()->mShowIconDay6 ) { goto DAY_6 ;}
278 if ( KOPrefs::instance()->mShowIconMonth ) {goto MONTH ;} 278 if ( KOPrefs::instance()->mShowIconMonth ) {goto MONTH ;}
279 if ( KOPrefs::instance()->mShowIconList ) { goto LIST ;} 279 if ( KOPrefs::instance()->mShowIconList ) { goto LIST ;}
280 //if ( KOPrefs::instance()->mShowIconTodoview ) { showTodoView() ;goto ENTE ;} 280 //if ( KOPrefs::instance()->mShowIconTodoview ) { showTodoView() ;goto ENTE ;}
281 ENTE: 281 ENTE:
282 flagResetViewChangeDate = 0; 282 flagResetViewChangeDate = 0;
283 selecteddatescount = mMainView->dateNavigator()->selectedDates().count(); 283 selecteddatescount = mMainView->dateNavigator()->selectedDates().count();
284 selecteddate = mMainView->dateNavigator()->selectedDates().first(); 284 selecteddate = mMainView->dateNavigator()->selectedDates().first();
285 285
286} 286}
287void KOViewManager::resetDateSilent( QDate date , int days ) 287void KOViewManager::resetDateSilent( QDate date , int days )
288{ 288{
289 mMainView->dateNavigator()->blockSignals( true ); 289 mMainView->dateNavigator()->blockSignals( true );
290 mMainView->dateNavigator()->selectDates( date , days ); 290 mMainView->dateNavigator()->selectDates( date , days );
291 mMainView->dateNavigator()->blockSignals( false ); 291 mMainView->dateNavigator()->blockSignals( false );
292} 292}
293void KOViewManager::showView(KOrg::BaseView *view, bool fullScreen ) 293void KOViewManager::showView(KOrg::BaseView *view, bool fullScreen )
294{ 294{
295 if ( flagResetViewChangeDate < 10 ) 295 if ( flagResetViewChangeDate < 10 )
296 ++flagResetViewChangeDate; 296 ++flagResetViewChangeDate;
297 //mFlagShowNextxDays = false; 297 //mFlagShowNextxDays = false;
298 //if(view == mCurrentView) return; 298 //if(view == mCurrentView) return;
299 if ( view == 0 ) { 299 if ( view == 0 ) {
300 view = mCurrentView; 300 view = mCurrentView;
301 if ( view == 0 ) 301 if ( view == 0 )
302 return; 302 return;
303 } 303 }
304 bool callupdate = !(view == mCurrentView); 304 bool callupdate = !(view == mCurrentView);
305 bool full = fullScreen; 305 bool full = fullScreen;
306 if(view == mCurrentView && view != mWhatsNextView ) { 306 if(view == mCurrentView && view != mWhatsNextView ) {
307 if ( mCurrentAgendaView < 0 ) 307 if ( mCurrentAgendaView < 0 )
308 return; 308 return;
309 if ( view != mMonthView ) 309 if ( view != mMonthView )
310 full = mMainView->leftFrame()->isVisible(); 310 full = mMainView->leftFrame()->isVisible();
311 } else { 311 } else {
312 if ( view == mMonthView && mMonthView) 312 if ( view == mMonthView && mMonthView)
313 ;//mMonthView->skipResize = true ; 313 ;//mMonthView->skipResize = true ;
314 mCurrentView = view; 314 mCurrentView = view;
315 // bool full = fullScreen; 315 // bool full = fullScreen;
316 bool isFull = !mMainView->leftFrame()->isVisible(); 316 bool isFull = !mMainView->leftFrame()->isVisible();
317 if ( isFull && KOPrefs::instance()->mViewChangeHoldFullscreen ) 317 if ( isFull && KOPrefs::instance()->mViewChangeHoldFullscreen )
318 full = true; 318 full = true;
319 if ( !isFull && KOPrefs::instance()->mViewChangeHoldNonFullscreen ) 319 if ( !isFull && KOPrefs::instance()->mViewChangeHoldNonFullscreen )
320 full = false; 320 full = false;
321 } 321 }
322 if ( mAgendaView ) mAgendaView->deleteSelectedDateTime(); 322 if ( mAgendaView ) mAgendaView->deleteSelectedDateTime();
323 //raiseCurrentView( full ); 323 //raiseCurrentView( full );
324 mMainView->processIncidenceSelection( 0 ); 324 mMainView->processIncidenceSelection( 0 );
325 //mMainView->updateView(); 325 //mMainView->updateView();
326 raiseCurrentView( full, callupdate ); 326 raiseCurrentView( full, callupdate );
327 mMainView->adaptNavigationUnits(); 327 mMainView->adaptNavigationUnits();
328} 328}
329 329
330void KOViewManager::raiseCurrentView( bool fullScreen, bool callUpdateView ) 330void KOViewManager::raiseCurrentView( bool fullScreen, bool callUpdateView )
331{ 331{
332 mCurrentAgendaView = 0; 332 mCurrentAgendaView = 0;
333 if ( fullScreen ) { 333 if ( fullScreen ) {
334 mMainView->leftFrame()->hide(); 334 mMainView->leftFrame()->hide();
335 } else { 335 } else {
336 mMainView->leftFrame()->show(); 336 mMainView->leftFrame()->show();
337 } 337 }
338 //if ( mCurrentView == mMonthView ) qApp->processEvents(); 338 //if ( mCurrentView == mMonthView ) qApp->processEvents();
339 emit signalFullScreen( !fullScreen ); 339 emit signalFullScreen( !fullScreen );
340 if ( callUpdateView ) 340 if ( callUpdateView )
341 mMainView->updateView(); 341 mMainView->updateView();
342 342
343 if ( globalFlagBlockAgenda == 5 ) { 343 if ( globalFlagBlockAgenda == 5 ) {
344 globalFlagBlockAgenda = 4; 344 globalFlagBlockAgenda = 4;
345 globalFlagBlockAgendaItemPaint = 1; 345 globalFlagBlockAgendaItemPaint = 1;
346 } 346 }
347 mMainView->viewStack()->raiseWidget(mCurrentView); 347 mMainView->viewStack()->raiseWidget(mCurrentView);
348 if ( globalFlagBlockAgenda == 4 ) { 348 if ( globalFlagBlockAgenda == 4 ) {
349 if ( mCurrentView == mAgendaView ) { 349 if ( mCurrentView == mAgendaView ) {
350 //globalFlagBlockAgenda =1 ; 350 //globalFlagBlockAgenda =1 ;
351 if ( KOPrefs::instance()->mSetTimeToDayStartAt ) 351 if ( KOPrefs::instance()->mSetTimeToDayStartAt )
352 mAgendaView->setStartHour( KOPrefs::instance()->mDayBegins ); 352 mAgendaView->setStartHour( KOPrefs::instance()->mDayBegins );
353 else if ( KOPrefs::instance()->mCenterOnCurrentTime ) 353 else if ( KOPrefs::instance()->mCenterOnCurrentTime )
354 mAgendaView->setStartHour( QTime::currentTime ().hour() ); 354 mAgendaView->setStartHour( QTime::currentTime ().hour() );
355 qApp->processEvents(); 355 qApp->processEvents();
356 //qDebug("qApp->processEvents() "); 356 //qDebug("qApp->processEvents() ");
357 globalFlagBlockAgenda = 0; 357 globalFlagBlockAgenda = 0;
358 mAgendaView->repaintAgenda(); 358 mAgendaView->repaintAgenda();
359 359
360 } 360 }
361 globalFlagBlockAgenda = 0; 361 globalFlagBlockAgenda = 0;
362 } 362 }
363 emit signalAgendaView( mCurrentView == mAgendaView ); 363 emit signalAgendaView( mCurrentView == mAgendaView );
364 //qDebug("raiseCurrentView ende "); 364 //qDebug("raiseCurrentView ende ");
365 365
366} 366}
367 367
368void KOViewManager::updateView() 368void KOViewManager::updateView()
369{ 369{
370 // qDebug("KOViewManager::updateView() "); 370 // qDebug("KOViewManager::updateView() ");
371 // if we are updating mTodoView, we get endless recursion 371 // if we are updating mTodoView, we get endless recursion
372 if ( mTodoView == mCurrentView ) 372 if ( mTodoView == mCurrentView )
373 return; 373 return;
374 if ( mCurrentView ) mCurrentView->updateView(); 374 if ( mCurrentView ) mCurrentView->updateView();
375 375
376} 376}
377 377
378void KOViewManager::updateView(const QDate &start, const QDate &end) 378void KOViewManager::updateView(const QDate &start, const QDate &end)
379{ 379{
380 // kdDebug() << "KOViewManager::updateView()" << endl; 380 // kdDebug() << "KOViewManager::updateView()" << endl;
381 381
382 if (mCurrentView) mCurrentView->showDates(start, end); 382 if (mCurrentView) mCurrentView->showDates(start, end);
383 383
384 if (mTodoView && mTodoView == mCurrentView ) mTodoView->updateView(); 384 if (mTodoView && mTodoView == mCurrentView ) mTodoView->updateView();
385} 385}
386 386
387 387
388void KOViewManager::updateWNview() 388void KOViewManager::updateWNview()
389{ 389{
390 if ( mCurrentView == mWhatsNextView && mWhatsNextView ) 390 if ( mCurrentView == mWhatsNextView && mWhatsNextView )
391 mWhatsNextView->updateView(); 391 mWhatsNextView->updateView();
392 if ( mCurrentView == mMonthView && mMonthView )
393 mMonthView->updateView();
392 394
393} 395}
394void KOViewManager::showWhatsNextView() 396void KOViewManager::showWhatsNextView()
395{ 397{
396 if (!mWhatsNextView) { 398 if (!mWhatsNextView) {
397 mWhatsNextView = new KOWhatsNextView(mMainView->calendar(),mMainView->viewStack(), 399 mWhatsNextView = new KOWhatsNextView(mMainView->calendar(),mMainView->viewStack(),
398 "KOViewManager::WhatsNextView"); 400 "KOViewManager::WhatsNextView");
399 mWhatsNextView->setEventViewer( mMainView->getEventViewerDialog()); 401 mWhatsNextView->setEventViewer( mMainView->getEventViewerDialog());
400 connect(mMainView, SIGNAL(configChanged()), mWhatsNextView, SLOT(updateConfig())); 402 connect(mMainView, SIGNAL(configChanged()), mWhatsNextView, SLOT(updateConfig()));
401 addView(mWhatsNextView); 403 addView(mWhatsNextView);
402 connect(this, SIGNAL( printWNV() ), 404 connect(this, SIGNAL( printWNV() ),
403 mWhatsNextView, SLOT( printMe() ) ); 405 mWhatsNextView, SLOT( printMe() ) );
404 } 406 }
405 globalFlagBlockAgenda = 1; 407 globalFlagBlockAgenda = 1;
406 showView(mWhatsNextView, true ); 408 showView(mWhatsNextView, true );
407 //mWhatsNextView->updateView(); 409 //mWhatsNextView->updateView();
408 410
409} 411}
410 412
411void KOViewManager::slotprintWNV() 413void KOViewManager::slotprintWNV()
412{ 414{
413 if (!mWhatsNextView) 415 if (!mWhatsNextView)
414 showWhatsNextView(); 416 showWhatsNextView();
415 emit printWNV(); 417 emit printWNV();
416 418
417} 419}
418void KOViewManager::showListView() 420void KOViewManager::showListView()
419{ 421{
420 if (!mListView) { 422 if (!mListView) {
421 mListView = new KOListView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::ListView"); 423 mListView = new KOListView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::ListView");
422 addView(mListView); 424 addView(mListView);
423 425
424 connect(mListView, SIGNAL(showIncidenceSignal(Incidence *)), 426 connect(mListView, SIGNAL(showIncidenceSignal(Incidence *)),
425 mMainView, SLOT(showIncidence(Incidence *))); 427 mMainView, SLOT(showIncidence(Incidence *)));
426 connect(mListView, SIGNAL(editIncidenceSignal(Incidence *)), 428 connect(mListView, SIGNAL(editIncidenceSignal(Incidence *)),
427 mMainView, SLOT(editIncidence(Incidence *))); 429 mMainView, SLOT(editIncidence(Incidence *)));
428 connect(mListView, SIGNAL(deleteIncidenceSignal(Incidence *)), 430 connect(mListView, SIGNAL(deleteIncidenceSignal(Incidence *)),
429 mMainView, SLOT(deleteIncidence(Incidence *))); 431 mMainView, SLOT(deleteIncidence(Incidence *)));
430 connect( mListView, SIGNAL( incidenceSelected( Incidence * ) ), 432 connect( mListView, SIGNAL( incidenceSelected( Incidence * ) ),
431 mMainView, SLOT( processMainViewSelection( Incidence * ) ) ); 433 mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
432 connect( mListView, SIGNAL( signalNewEvent() ), 434 connect( mListView, SIGNAL( signalNewEvent() ),
433 mMainView, SLOT( newEvent() ) ); 435 mMainView, SLOT( newEvent() ) );
434 connect(mMainView, SIGNAL(configChanged()), mListView, SLOT(updateConfig())); 436 connect(mMainView, SIGNAL(configChanged()), mListView, SLOT(updateConfig()));
435 connect( mListView, SIGNAL( cloneIncidenceSignal( Incidence * ) ), 437 connect( mListView, SIGNAL( cloneIncidenceSignal( Incidence * ) ),
436 mMainView, SLOT ( cloneIncidence( Incidence * ) ) ); 438 mMainView, SLOT ( cloneIncidence( Incidence * ) ) );
437 connect( mListView, SIGNAL( cancelIncidenceSignal( Incidence * ) ), 439 connect( mListView, SIGNAL( cancelIncidenceSignal( Incidence * ) ),
438 mMainView, SLOT ( cancelIncidence( Incidence * ) ) ); 440 mMainView, SLOT ( cancelIncidence( Incidence * ) ) );
439 connect( mListView, SIGNAL( moveIncidenceSignal( Incidence * ) ), 441 connect( mListView, SIGNAL( moveIncidenceSignal( Incidence * ) ),
440 mMainView, SLOT ( moveIncidence( Incidence * ) ) ); 442 mMainView, SLOT ( moveIncidence( Incidence * ) ) );
441 connect( mListView, SIGNAL( beamIncidenceSignal( Incidence * ) ), 443 connect( mListView, SIGNAL( beamIncidenceSignal( Incidence * ) ),
442 mMainView, SLOT ( beamIncidence( Incidence * ) ) ); 444 mMainView, SLOT ( beamIncidence( Incidence * ) ) );
443 } 445 }
444 // bool temp = mFlagShowNextxDays; 446 // bool temp = mFlagShowNextxDays;
445 //globalFlagBlockPainting = true; 447 //globalFlagBlockPainting = true;
446 globalFlagBlockAgenda = 1; 448 globalFlagBlockAgenda = 1;
447 if ( KOPrefs::instance()->mListViewMonthTimespan ) { 449 if ( KOPrefs::instance()->mListViewMonthTimespan ) {
448 mMainView->setBlockShowDates( true ); 450 mMainView->setBlockShowDates( true );
449 mMainView->dateNavigator()->selectMonth(); 451 mMainView->dateNavigator()->selectMonth();
450 mMainView->setBlockShowDates( false ); 452 mMainView->setBlockShowDates( false );
451 } 453 }
452 showView(mListView, KOPrefs::instance()->mFullViewTodo); 454 showView(mListView, KOPrefs::instance()->mFullViewTodo);
453 //mFlagShowNextxDays = temp; 455 //mFlagShowNextxDays = temp;
454} 456}
455 457
456void KOViewManager::showAgendaView( bool fullScreen ) 458void KOViewManager::showAgendaView( bool fullScreen )
457{ 459{
458 460
459 mMainView->dialogManager()->hideSearchDialog(); 461 mMainView->dialogManager()->hideSearchDialog();
460 // qDebug("KOViewManager::showAgendaView "); 462 // qDebug("KOViewManager::showAgendaView ");
461 bool full; 463 bool full;
462 full = fullScreen; 464 full = fullScreen;
463 if (!mAgendaView) { 465 if (!mAgendaView) {
464 full = false; 466 full = false;
465 mAgendaView = new KOAgendaView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::AgendaView"); 467 mAgendaView = new KOAgendaView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::AgendaView");
466 addView(mAgendaView); 468 addView(mAgendaView);
467#ifndef DESKTOP_VERSION 469#ifndef DESKTOP_VERSION
468 QPEApplication::setStylusOperation( mAgendaView, QPEApplication::RightOnHold ); 470 QPEApplication::setStylusOperation( mAgendaView, QPEApplication::RightOnHold );
469#endif 471#endif
470 connect( mAgendaView, SIGNAL( incidenceChanged(Incidence *, int )), 472 connect( mAgendaView, SIGNAL( incidenceChanged(Incidence *, int )),
471 mMainView, SLOT( changeIncidenceDisplay( Incidence *, int ) )); 473 mMainView, SLOT( changeIncidenceDisplay( Incidence *, int ) ));
472 474
473 // SIGNALS/SLOTS FOR DAY/WEEK VIEW 475 // SIGNALS/SLOTS FOR DAY/WEEK VIEW
474 476
475 connect(mAgendaView,SIGNAL(showDateView( int, QDate )),SLOT(showDateView( int, QDate ))); 477 connect(mAgendaView,SIGNAL(showDateView( int, QDate )),SLOT(showDateView( int, QDate )));
476 478
477 connect(mAgendaView,SIGNAL(newTodoSignal(QDateTime,bool)), 479 connect(mAgendaView,SIGNAL(newTodoSignal(QDateTime,bool)),
478 mMainView, SLOT(newTodoDateTime(QDateTime,bool))); 480 mMainView, SLOT(newTodoDateTime(QDateTime,bool)));
479 connect(mAgendaView,SIGNAL(newEventSignal(QDateTime)), 481 connect(mAgendaView,SIGNAL(newEventSignal(QDateTime)),
480 mMainView, SLOT(newEvent(QDateTime))); 482 mMainView, SLOT(newEvent(QDateTime)));
481 connect(mAgendaView,SIGNAL(newEventSignal(QDateTime,QDateTime)), 483 connect(mAgendaView,SIGNAL(newEventSignal(QDateTime,QDateTime)),
482 mMainView, SLOT(newEvent(QDateTime,QDateTime))); 484 mMainView, SLOT(newEvent(QDateTime,QDateTime)));
483 connect(mAgendaView,SIGNAL(newEventSignal(QDate)), 485 connect(mAgendaView,SIGNAL(newEventSignal(QDate)),
484 mMainView, SLOT(newEvent(QDate))); 486 mMainView, SLOT(newEvent(QDate)));
485 487
486 connect(mAgendaView, SIGNAL(editIncidenceSignal(Incidence *)), 488 connect(mAgendaView, SIGNAL(editIncidenceSignal(Incidence *)),
487 mMainView, SLOT(editIncidence(Incidence *))); 489 mMainView, SLOT(editIncidence(Incidence *)));
488 connect(mAgendaView, SIGNAL(showIncidenceSignal(Incidence *)), 490 connect(mAgendaView, SIGNAL(showIncidenceSignal(Incidence *)),
489 mMainView, SLOT(showIncidence(Incidence *))); 491 mMainView, SLOT(showIncidence(Incidence *)));
490 connect(mAgendaView, SIGNAL(deleteIncidenceSignal(Incidence *)), 492 connect(mAgendaView, SIGNAL(deleteIncidenceSignal(Incidence *)),
491 mMainView, SLOT(deleteIncidence(Incidence *))); 493 mMainView, SLOT(deleteIncidence(Incidence *)));
492 494
493 connect( mAgendaView, SIGNAL( incidenceSelected( Incidence * ) ), 495 connect( mAgendaView, SIGNAL( incidenceSelected( Incidence * ) ),
494 mMainView, SLOT( processMainViewSelection( Incidence * ) ) ); 496 mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
495 497
496 connect(mAgendaView, SIGNAL( toggleExpand() ), 498 connect(mAgendaView, SIGNAL( toggleExpand() ),
497 mMainView, SLOT( toggleExpand() ) ); 499 mMainView, SLOT( toggleExpand() ) );
498 500
499 connect( mAgendaView, SIGNAL( cloneIncidenceSignal(Incidence *) ), 501 connect( mAgendaView, SIGNAL( cloneIncidenceSignal(Incidence *) ),
500 mMainView, SLOT(cloneIncidence(Incidence *) ) ) ; 502 mMainView, SLOT(cloneIncidence(Incidence *) ) ) ;
501 connect( mAgendaView, SIGNAL( cancelIncidenceSignal(Incidence *) ), 503 connect( mAgendaView, SIGNAL( cancelIncidenceSignal(Incidence *) ),
502 mMainView, SLOT(cancelIncidence(Incidence *) ) ) ; 504 mMainView, SLOT(cancelIncidence(Incidence *) ) ) ;
503 connect(mMainView, SIGNAL(configChanged()), mAgendaView, SLOT(updateConfig())); 505 connect(mMainView, SIGNAL(configChanged()), mAgendaView, SLOT(updateConfig()));
504 connect( mMainView, SIGNAL( todoModified( Todo *, int )), mAgendaView, 506 connect( mMainView, SIGNAL( todoModified( Todo *, int )), mAgendaView,
505 SLOT( updateTodo( Todo *, int ) ) ); 507 SLOT( updateTodo( Todo *, int ) ) );
506 connect( mAgendaView,SIGNAL( todoMoved( Todo *, int )), 508 connect( mAgendaView,SIGNAL( todoMoved( Todo *, int )),
507 mMainView, SIGNAL( todoModified( Todo *, int ))); 509 mMainView, SIGNAL( todoModified( Todo *, int )));
508 connect( mAgendaView, SIGNAL( moveIncidenceSignal( Incidence * ) ), 510 connect( mAgendaView, SIGNAL( moveIncidenceSignal( Incidence * ) ),
509 mMainView, SLOT ( moveIncidence( Incidence * ) ) ); 511 mMainView, SLOT ( moveIncidence( Incidence * ) ) );
510 connect( mAgendaView, SIGNAL( beamIncidenceSignal( Incidence * ) ), 512 connect( mAgendaView, SIGNAL( beamIncidenceSignal( Incidence * ) ),
511 mMainView, SLOT ( beamIncidence( Incidence * ) ) ); 513 mMainView, SLOT ( beamIncidence( Incidence * ) ) );
512 connect( mAgendaView, SIGNAL( selectWeekNum( int ) ), 514 connect( mAgendaView, SIGNAL( selectWeekNum( int ) ),
513 mMainView->dateNavigator(), SLOT ( selectWeek( int ) ) ); 515 mMainView->dateNavigator(), SLOT ( selectWeek( int ) ) );
514 mAgendaView->readSettings(); 516 mAgendaView->readSettings();
515 mAgendaView->updateConfig(); 517 mAgendaView->updateConfig();
516 } 518 }
517 519
518 showView( mAgendaView, full); 520 showView( mAgendaView, full);
519 521
520} 522}
521 523
522void KOViewManager::showDayView() 524void KOViewManager::showDayView()
523{ 525{
524 mCurrentAgendaView = mMainView->dateNavigator()->selectedDates().count(); 526 mCurrentAgendaView = mMainView->dateNavigator()->selectedDates().count();
525 mFlagShowNextxDays = false; 527 mFlagShowNextxDays = false;
526 globalFlagBlockLabel = 1; 528 globalFlagBlockLabel = 1;
527 globalFlagBlockAgenda = 1; 529 globalFlagBlockAgenda = 1;
528 if ( mCurrentAgendaView != 1 ) 530 if ( mCurrentAgendaView != 1 )
529 mCurrentAgendaView = -1; 531 mCurrentAgendaView = -1;
530 showAgendaView(); 532 showAgendaView();
531 qApp->processEvents(); 533 qApp->processEvents();
532 globalFlagBlockAgenda = 2; 534 globalFlagBlockAgenda = 2;
533 globalFlagBlockLabel = 0; 535 globalFlagBlockLabel = 0;
534 mMainView->dateNavigator()->selectDates( 1 ); 536 mMainView->dateNavigator()->selectDates( 1 );
535 mCurrentAgendaView = 1 ; 537 mCurrentAgendaView = 1 ;
536 538
537} 539}
538 540
539void KOViewManager::showWorkWeekView() 541void KOViewManager::showWorkWeekView()
540{ 542{
541 mCurrentAgendaView = mMainView->dateNavigator()->selectedDates().count(); 543 mCurrentAgendaView = mMainView->dateNavigator()->selectedDates().count();
542 mFlagShowNextxDays = false; 544 mFlagShowNextxDays = false;
543 globalFlagBlockAgenda = 1; 545 globalFlagBlockAgenda = 1;
544 globalFlagBlockLabel = 1; 546 globalFlagBlockLabel = 1;
545 if ( mCurrentAgendaView != 5 ) 547 if ( mCurrentAgendaView != 5 )
546 mCurrentAgendaView = -1; 548 mCurrentAgendaView = -1;
547 showAgendaView(); 549 showAgendaView();
548 qApp->processEvents(); 550 qApp->processEvents();
549 globalFlagBlockAgenda = 2; 551 globalFlagBlockAgenda = 2;
550 globalFlagBlockLabel = 0; 552 globalFlagBlockLabel = 0;
551 mMainView->dateNavigator()->selectWorkWeek(); 553 mMainView->dateNavigator()->selectWorkWeek();
552 mCurrentAgendaView = 5 ; 554 mCurrentAgendaView = 5 ;
553 555
554} 556}
555 557
556void KOViewManager::showWeekView() 558void KOViewManager::showWeekView()
557{ 559{
558 /* 560 /*
559 globalFlagBlockAgenda = 2; 561 globalFlagBlockAgenda = 2;
560 qDebug("4globalFlagBlockAgenda = 2; "); 562 qDebug("4globalFlagBlockAgenda = 2; ");
561 //globalFlagBlockPainting = true; 563 //globalFlagBlockPainting = true;
562 mMainView->dateNavigator()->selectWeek(); 564 mMainView->dateNavigator()->selectWeek();
563 showAgendaView(); 565 showAgendaView();
564 */ 566 */
565 567
566 568
567 mCurrentAgendaView = mMainView->dateNavigator()->selectedDates().count(); 569 mCurrentAgendaView = mMainView->dateNavigator()->selectedDates().count();
568 mFlagShowNextxDays = false; 570 mFlagShowNextxDays = false;
569 globalFlagBlockAgenda = 1; 571 globalFlagBlockAgenda = 1;
570 globalFlagBlockLabel = 1; 572 globalFlagBlockLabel = 1;
571 if ( mCurrentAgendaView != 7 ) 573 if ( mCurrentAgendaView != 7 )
572 mCurrentAgendaView = -1; 574 mCurrentAgendaView = -1;
573 showAgendaView(); 575 showAgendaView();
574 qApp->processEvents(); 576 qApp->processEvents();
575 globalFlagBlockAgenda = 2; 577 globalFlagBlockAgenda = 2;
576 globalFlagBlockLabel = 0; 578 globalFlagBlockLabel = 0;
577 mMainView->dateNavigator()->selectWeek(); 579 mMainView->dateNavigator()->selectWeek();
578 mCurrentAgendaView = 7 ; 580 mCurrentAgendaView = 7 ;
579} 581}
580 582
581void KOViewManager::showNextXView() 583void KOViewManager::showNextXView()
582{ 584{
583 585
584 globalFlagBlockAgenda = 1; 586 globalFlagBlockAgenda = 1;
585 if ( mCurrentAgendaView != 3 ) 587 if ( mCurrentAgendaView != 3 )
586 mCurrentAgendaView = -1; 588 mCurrentAgendaView = -1;
587 showAgendaView(KOPrefs::instance()->mFullViewMonth); 589 showAgendaView(KOPrefs::instance()->mFullViewMonth);
588 globalFlagBlockAgenda = 2; 590 globalFlagBlockAgenda = 2;
589 mMainView->dateNavigator()->selectDates( QDate::currentDate(), 591 mMainView->dateNavigator()->selectDates( QDate::currentDate(),
590 KOPrefs::instance()->mNextXDays ); 592 KOPrefs::instance()->mNextXDays );
591 mFlagShowNextxDays = true; 593 mFlagShowNextxDays = true;
592 mCurrentAgendaView = 3 ; 594 mCurrentAgendaView = 3 ;
593} 595}
594bool KOViewManager::showsNextDays() 596bool KOViewManager::showsNextDays()
595{ 597{
596 return mFlagShowNextxDays; 598 return mFlagShowNextxDays;
597} 599}
598void KOViewManager::createMonthView() 600void KOViewManager::createMonthView()
599{ 601{
600if (!mMonthView) { 602if (!mMonthView) {
601 mMonthView = new KOMonthView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::MonthView"); 603 mMonthView = new KOMonthView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::MonthView");
602 604
603 addView(mMonthView); 605 addView(mMonthView);
604 // mMonthView->show(); 606 // mMonthView->show();
605 // SIGNALS/SLOTS FOR MONTH VIEW 607 // SIGNALS/SLOTS FOR MONTH VIEW
606 connect(mMonthView, SIGNAL(newEventSignal(QDateTime)), 608 connect(mMonthView, SIGNAL(newEventSignal(QDateTime)),
607 mMainView, SLOT(newEvent(QDateTime))); 609 mMainView, SLOT(newEvent(QDateTime)));
608 610
609 connect(mMonthView, SIGNAL(showIncidenceSignal(Incidence *)), 611 connect(mMonthView, SIGNAL(showIncidenceSignal(Incidence *)),
610 mMainView, SLOT(showIncidence(Incidence *))); 612 mMainView, SLOT(showIncidence(Incidence *)));
611 connect(mMonthView, SIGNAL(editIncidenceSignal(Incidence *)), 613 connect(mMonthView, SIGNAL(editIncidenceSignal(Incidence *)),
612 mMainView, SLOT(editIncidence(Incidence *))); 614 mMainView, SLOT(editIncidence(Incidence *)));
613 connect(mMonthView, SIGNAL(deleteIncidenceSignal(Incidence *)), 615 connect(mMonthView, SIGNAL(deleteIncidenceSignal(Incidence *)),
614 mMainView, SLOT(deleteIncidence(Incidence *))); 616 mMainView, SLOT(deleteIncidence(Incidence *)));
615 617
616 connect( mMonthView, SIGNAL( incidenceSelected( Incidence * ) ), 618 connect( mMonthView, SIGNAL( incidenceSelected( Incidence * ) ),
617 mMainView, SLOT( processMainViewSelection( Incidence * ) ) ); 619 mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
618 connect( mMonthView, SIGNAL( cloneIncidenceSignal( Incidence * ) ), 620 connect( mMonthView, SIGNAL( cloneIncidenceSignal( Incidence * ) ),
619 mMainView, SLOT ( cloneIncidence( Incidence * ) ) ); 621 mMainView, SLOT ( cloneIncidence( Incidence * ) ) );
620 connect( mMonthView, SIGNAL( cancelIncidenceSignal( Incidence * ) ), 622 connect( mMonthView, SIGNAL( cancelIncidenceSignal( Incidence * ) ),
621 mMainView, SLOT ( cancelIncidence( Incidence * ) ) ); 623 mMainView, SLOT ( cancelIncidence( Incidence * ) ) );
622 624
623 connect( mMonthView, SIGNAL( moveIncidenceSignal( Incidence * ) ), 625 connect( mMonthView, SIGNAL( moveIncidenceSignal( Incidence * ) ),
624 mMainView, SLOT ( moveIncidence( Incidence * ) ) ); 626 mMainView, SLOT ( moveIncidence( Incidence * ) ) );
625 connect( mMonthView, SIGNAL( beamIncidenceSignal( Incidence * ) ), 627 connect( mMonthView, SIGNAL( beamIncidenceSignal( Incidence * ) ),
626 mMainView, SLOT ( beamIncidence( Incidence * ) ) ); 628 mMainView, SLOT ( beamIncidence( Incidence * ) ) );
627 connect( mMonthView, SIGNAL( selectWeekNum( int ) ), 629 connect( mMonthView, SIGNAL( selectWeekNum( int ) ),
628 mMainView->dateNavigator(), SLOT ( selectWeekFromMonthView( int ) ) ); 630 mMainView->dateNavigator(), SLOT ( selectWeekFromMonthView( int ) ) );
629 connect( mMonthView, SIGNAL( selectMonth() ), 631 connect( mMonthView, SIGNAL( selectMonth() ),
630 mMainView->dateNavigator(), SLOT ( selectMonthFromMonthview() ) ); 632 mMainView->dateNavigator(), SLOT ( selectMonthFromMonthview() ) );
631 connect( mMonthView, SIGNAL( showDaySignal( QDate ) ), 633 connect( mMonthView, SIGNAL( showDaySignal( QDate ) ),
632 mMainView, SLOT ( showDay( QDate ) ) ); 634 mMainView, SLOT ( showDay( QDate ) ) );
633 connect(mMainView, SIGNAL(configChanged()), mMonthView, SLOT(updateConfig())); 635 connect(mMainView, SIGNAL(configChanged()), mMonthView, SLOT(updateConfig()));
634 connect( mMonthView, SIGNAL(nextMonth() ), 636 connect( mMonthView, SIGNAL(nextMonth() ),
635 mMonthView->navigatorBar(), SIGNAL(goNextMonth() ) ); 637 mMonthView->navigatorBar(), SIGNAL(goNextMonth() ) );
636 connect( mMonthView, SIGNAL(prevMonth() ), 638 connect( mMonthView, SIGNAL(prevMonth() ),
637 mMonthView->navigatorBar(), SIGNAL(goPrevMonth() ) ); 639 mMonthView->navigatorBar(), SIGNAL(goPrevMonth() ) );
638 connect( mMonthView->navigatorBar(), SIGNAL( goPrevYear() ), 640 connect( mMonthView->navigatorBar(), SIGNAL( goPrevYear() ),
639 mMainView->dateNavigator(), SLOT( selectPreviousYear() ) ); 641 mMainView->dateNavigator(), SLOT( selectPreviousYear() ) );
640 connect( mMonthView->navigatorBar(), SIGNAL( goNextYear() ), 642 connect( mMonthView->navigatorBar(), SIGNAL( goNextYear() ),
641 mMainView->dateNavigator(), SLOT( selectNextYear() ) ); 643 mMainView->dateNavigator(), SLOT( selectNextYear() ) );
642 connect( mMonthView->navigatorBar(), SIGNAL( goPrevMonth() ), 644 connect( mMonthView->navigatorBar(), SIGNAL( goPrevMonth() ),
643 mMainView->dateNavigator(), SLOT( selectPreviousMonth() ) ); 645 mMainView->dateNavigator(), SLOT( selectPreviousMonth() ) );
644 connect( mMonthView->navigatorBar(), SIGNAL( goNextMonth() ), 646 connect( mMonthView->navigatorBar(), SIGNAL( goNextMonth() ),
645 mMainView->dateNavigator(), SLOT( selectNextMonth() ) ); 647 mMainView->dateNavigator(), SLOT( selectNextMonth() ) );
646 connect( mMonthView->navigatorBar(), SIGNAL( goPrevWeek() ), 648 connect( mMonthView->navigatorBar(), SIGNAL( goPrevWeek() ),
647 mMainView->dateNavigator(), SLOT( selectPreviousWeek() ) ); 649 mMainView->dateNavigator(), SLOT( selectPreviousWeek() ) );
648 connect( mMonthView->navigatorBar(), SIGNAL( goNextWeek() ), 650 connect( mMonthView->navigatorBar(), SIGNAL( goNextWeek() ),
649 mMainView->dateNavigator(), SLOT( selectNextWeek() ) ); 651 mMainView->dateNavigator(), SLOT( selectNextWeek() ) );
650 652
651 connect( mMainView->dateNavigator(), SIGNAL( datesSelected( const KCal::DateList & ) ), 653 connect( mMainView->dateNavigator(), SIGNAL( datesSelected( const KCal::DateList & ) ),
652 mMonthView->navigatorBar(), SLOT( selectDates( const KCal::DateList & ) ) ); 654 mMonthView->navigatorBar(), SLOT( selectDates( const KCal::DateList & ) ) );
653 655
654 656
655 connect( mMonthView->navigatorBar(), SIGNAL( monthSelected ( int ) ), 657 connect( mMonthView->navigatorBar(), SIGNAL( monthSelected ( int ) ),
656 mMainView->dateNavigator(), SLOT( slotMonthSelect( int ) ) ); 658 mMainView->dateNavigator(), SLOT( slotMonthSelect( int ) ) );
657 659
658 } 660 }
659} 661}
660void KOViewManager::showMonthViewWeek() 662void KOViewManager::showMonthViewWeek()
661{ 663{
662 createMonthView(); 664 createMonthView();
663 globalFlagBlockAgenda = 1; 665 globalFlagBlockAgenda = 1;
664 bool full = true; 666 bool full = true;
665 if ( mCurrentView == mMonthView) 667 if ( mCurrentView == mMonthView)
666 full = mMainView->leftFrame()->isVisible(); 668 full = mMainView->leftFrame()->isVisible();
667 if ( !KOPrefs::instance()->mMonthViewWeek ) { 669 if ( !KOPrefs::instance()->mMonthViewWeek ) {
668 mMonthView->switchView(); 670 mMonthView->switchView();
669 if ( KOPrefs::instance()->mViewChangeHoldNonFullscreen && mMainView->leftFrame()->isVisible() ) 671 if ( KOPrefs::instance()->mViewChangeHoldNonFullscreen && mMainView->leftFrame()->isVisible() )
670 full = false; 672 full = false;
671 else 673 else
672 full = true; 674 full = true;
673 } 675 }
674 mMainView->dateNavigator()->selectWeek(); 676 mMainView->dateNavigator()->selectWeek();
675 showView(mMonthView, full ); 677 showView(mMonthView, full );
676 mMonthView->setKeyBFocus(); 678 mMonthView->setKeyBFocus();
677} 679}
678 680
679void KOViewManager::showMonth( const QDate & date ) 681void KOViewManager::showMonth( const QDate & date )
680{ 682{
681 mMainView->dateNavigator()->blockSignals( true ); 683 mMainView->dateNavigator()->blockSignals( true );
682 mMainView->dateNavigator()->selectDate( date ); 684 mMainView->dateNavigator()->selectDate( date );
683 mMainView->dateNavigator()->blockSignals( false ); 685 mMainView->dateNavigator()->blockSignals( false );
684 showMonthView(); 686 showMonthView();
685} 687}
686void KOViewManager::showMonthView() 688void KOViewManager::showMonthView()
687 { 689 {
688 690
689 createMonthView(); 691 createMonthView();
690 globalFlagBlockAgenda = 1; 692 globalFlagBlockAgenda = 1;
691 //mFlagShowNextxDays = false; 693 //mFlagShowNextxDays = false;
692 bool full = true; 694 bool full = true;
693 if ( mCurrentView == mMonthView) 695 if ( mCurrentView == mMonthView)
694 full = mMainView->leftFrame()->isVisible(); 696 full = mMainView->leftFrame()->isVisible();
695 // if(mMonthView == mCurrentView) return; 697 // if(mMonthView == mCurrentView) return;
696 if ( KOPrefs::instance()->mMonthViewWeek ) { 698 if ( KOPrefs::instance()->mMonthViewWeek ) {
697 mMonthView->switchView(); 699 mMonthView->switchView();
698 if ( KOPrefs::instance()->mViewChangeHoldNonFullscreen && mMainView->leftFrame()->isVisible() ) 700 if ( KOPrefs::instance()->mViewChangeHoldNonFullscreen && mMainView->leftFrame()->isVisible() )
699 full = false; 701 full = false;
700 else 702 else
701 full = true; 703 full = true;
702 } 704 }
703 mMainView->dateNavigator()->selectMonth(); 705 mMainView->dateNavigator()->selectMonth();
704 706
705 showView(mMonthView, full ); 707 showView(mMonthView, full );
706 mMonthView->setKeyBFocus(); 708 mMonthView->setKeyBFocus();
707 709
708} 710}
709 711
710void KOViewManager::showTodoView() 712void KOViewManager::showTodoView()
711{ 713{
712 //mFlagShowNextxDays = false; 714 //mFlagShowNextxDays = false;
713 if ( !mTodoView ) { 715 if ( !mTodoView ) {
714 mTodoView = new KOTodoView( mMainView->calendar(), mMainView->viewStack(), 716 mTodoView = new KOTodoView( mMainView->calendar(), mMainView->viewStack(),
715 "KOViewManager::TodoView" ); 717 "KOViewManager::TodoView" );
716 718
717 addView( mTodoView ); 719 addView( mTodoView );
718 // QPEApplication::setStylusOperation( mTodoView, QPEApplication::RightOnHold ); 720 // QPEApplication::setStylusOperation( mTodoView, QPEApplication::RightOnHold );
719 721
720 // SIGNALS/SLOTS FOR TODO VIEW 722 // SIGNALS/SLOTS FOR TODO VIEW
721 connect( mTodoView, SIGNAL( newTodoSignal() ), 723 connect( mTodoView, SIGNAL( newTodoSignal() ),
722 mMainView, SLOT( newTodo() ) ); 724 mMainView, SLOT( newTodo() ) );
723 connect( mTodoView, SIGNAL( newSubTodoSignal( Todo * ) ), 725 connect( mTodoView, SIGNAL( newSubTodoSignal( Todo * ) ),
724 mMainView, SLOT( newSubTodo( Todo *) ) ); 726 mMainView, SLOT( newSubTodo( Todo *) ) );
725 connect( mTodoView, SIGNAL( showTodoSignal( Todo *) ), 727 connect( mTodoView, SIGNAL( showTodoSignal( Todo *) ),
726 mMainView, SLOT( showTodo( Todo * ) ) ); 728 mMainView, SLOT( showTodo( Todo * ) ) );
727 connect( mTodoView, SIGNAL( editTodoSignal( Todo * ) ), 729 connect( mTodoView, SIGNAL( editTodoSignal( Todo * ) ),
728 mMainView, SLOT( editTodo( Todo * ) ) ); 730 mMainView, SLOT( editTodo( Todo * ) ) );
729 connect( mTodoView, SIGNAL( deleteTodoSignal( Todo * ) ), 731 connect( mTodoView, SIGNAL( deleteTodoSignal( Todo * ) ),
730 mMainView, SLOT( deleteTodo( Todo * ) ) ); 732 mMainView, SLOT( deleteTodo( Todo * ) ) );
731 connect( mTodoView, SIGNAL( purgeCompletedSignal() ), 733 connect( mTodoView, SIGNAL( purgeCompletedSignal() ),
732 mMainView, SLOT( purgeCompleted() ) ); 734 mMainView, SLOT( purgeCompleted() ) );
733 735
734 connect( mTodoView, SIGNAL( incidenceSelected( Incidence * ) ), 736 connect( mTodoView, SIGNAL( incidenceSelected( Incidence * ) ),
735 mMainView, SLOT( processMainViewSelection( Incidence * ) ) ); 737 mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
736 738
737 connect( mMainView, SIGNAL( configChanged() ), mTodoView, 739 connect( mMainView, SIGNAL( configChanged() ), mTodoView,
738 SLOT( updateConfig() ) ); 740 SLOT( updateConfig() ) );
739 connect( mMainView, SIGNAL( todoModified( Todo *, int )), mTodoView, 741 connect( mMainView, SIGNAL( todoModified( Todo *, int )), mTodoView,
740 SLOT( updateTodo( Todo *, int ) ) ); 742 SLOT( updateTodo( Todo *, int ) ) );
741 connect( mTodoView, SIGNAL( todoModifiedSignal( Todo *, int ) ), 743 connect( mTodoView, SIGNAL( todoModifiedSignal( Todo *, int ) ),
742 mMainView, SIGNAL ( todoModified( Todo *, int ) ) ); 744 mMainView, SIGNAL ( todoModified( Todo *, int ) ) );
743 connect( mTodoView, SIGNAL( cloneTodoSignal( Incidence * ) ), 745 connect( mTodoView, SIGNAL( cloneTodoSignal( Incidence * ) ),
744 mMainView, SLOT ( cloneIncidence( Incidence * ) ) ); 746 mMainView, SLOT ( cloneIncidence( Incidence * ) ) );
745 connect( mTodoView, SIGNAL( cancelTodoSignal( Incidence * ) ), 747 connect( mTodoView, SIGNAL( cancelTodoSignal( Incidence * ) ),
746 mMainView, SLOT ( cancelIncidence( Incidence * ) ) ); 748 mMainView, SLOT ( cancelIncidence( Incidence * ) ) );
747 connect( mTodoView, SIGNAL( unparentTodoSignal( Todo * ) ), 749 connect( mTodoView, SIGNAL( unparentTodoSignal( Todo * ) ),
748 mMainView, SLOT ( todo_unsub( Todo * ) ) ); 750 mMainView, SLOT ( todo_unsub( Todo * ) ) );
749 connect( mTodoView, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 751 connect( mTodoView, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
750 mMainView, SLOT ( todo_resub( Todo *, Todo *) ) ); 752 mMainView, SLOT ( todo_resub( Todo *, Todo *) ) );
751 connect( mTodoView, SIGNAL( moveTodoSignal( Incidence * ) ), 753 connect( mTodoView, SIGNAL( moveTodoSignal( Incidence * ) ),
752 mMainView, SLOT ( moveIncidence( Incidence * ) ) ); 754 mMainView, SLOT ( moveIncidence( Incidence * ) ) );
753 connect( mTodoView, SIGNAL( beamTodoSignal( Incidence * ) ), 755 connect( mTodoView, SIGNAL( beamTodoSignal( Incidence * ) ),
754 mMainView, SLOT ( beamIncidence( Incidence * ) ) ); 756 mMainView, SLOT ( beamIncidence( Incidence * ) ) );
755 KConfig *config = KOGlobals::config(); 757 KConfig *config = KOGlobals::config();
756 mTodoView->restoreLayout(config,"Todo View"); 758 mTodoView->restoreLayout(config,"Todo View");
757 mTodoView->setNavigator( mMainView->dateNavigator() ); 759 mTodoView->setNavigator( mMainView->dateNavigator() );
758 } 760 }
759 761
760 globalFlagBlockAgenda = 1; 762 globalFlagBlockAgenda = 1;
761 showView( mTodoView, true ); 763 showView( mTodoView, true );
762 764
763} 765}
764 766
765void KOViewManager::showJournalView() 767void KOViewManager::showJournalView()
766{ 768{
767 //mFlagShowNextxDays = false; 769 //mFlagShowNextxDays = false;
768 if (!mJournalView) { 770 if (!mJournalView) {
769 mJournalView = new KOJournalView(mMainView->calendar(),mMainView->viewStack(), 771 mJournalView = new KOJournalView(mMainView->calendar(),mMainView->viewStack(),
770 "KOViewManager::JournalView"); 772 "KOViewManager::JournalView");
771 connect( mMainView, SIGNAL( configChanged() ), mJournalView, 773 connect( mMainView, SIGNAL( configChanged() ), mJournalView,
772 SLOT( updateConfig() ) ); 774 SLOT( updateConfig() ) );
773 connect(mJournalView, SIGNAL(deleteJournal(Journal *) ), mMainView,SLOT(deleteJournal(Journal *)) ); 775 connect(mJournalView, SIGNAL(deleteJournal(Journal *) ), mMainView,SLOT(deleteJournal(Journal *)) );
774 addView(mJournalView); 776 addView(mJournalView);
775 } 777 }
776 778
777 showView(mJournalView); 779 showView(mJournalView);
778 mMainView->dateNavigator()->selectDates( 1 ); 780 mMainView->dateNavigator()->selectDates( 1 );
779} 781}
780 782
781void KOViewManager::showTimeSpanView() 783void KOViewManager::showTimeSpanView()
782{ 784{
783 //mFlagShowNextxDays = false; 785 //mFlagShowNextxDays = false;
784 if (!mTimeSpanView) { 786 if (!mTimeSpanView) {
785 mTimeSpanView = new KOTimeSpanView(mMainView->calendar(),mMainView->viewStack(), 787 mTimeSpanView = new KOTimeSpanView(mMainView->calendar(),mMainView->viewStack(),
786 "KOViewManager::TimeSpanView"); 788 "KOViewManager::TimeSpanView");
787 addView(mTimeSpanView); 789 addView(mTimeSpanView);
788 790
789 mTimeSpanView->readSettings(); 791 mTimeSpanView->readSettings();
790 } 792 }
791 793
792 showView(mTimeSpanView); 794 showView(mTimeSpanView);
793} 795}
794 796
795Incidence *KOViewManager::currentSelection() 797Incidence *KOViewManager::currentSelection()
796{ 798{
797 if (!mCurrentView) return 0; 799 if (!mCurrentView) return 0;
798 if ( mCurrentView == mListView ) { 800 if ( mCurrentView == mListView ) {
799 if ( mListView->currentItem() ) 801 if ( mListView->currentItem() )
800 return mListView->currentItem(); 802 return mListView->currentItem();
801 } 803 }
802 return mCurrentView->selectedIncidences().first(); 804 return mCurrentView->selectedIncidences().first();
803} 805}
804 806
805QDate KOViewManager::currentSelectionDate() 807QDate KOViewManager::currentSelectionDate()
806{ 808{
807 QDate qd; 809 QDate qd;
808 if (mCurrentView) { 810 if (mCurrentView) {
809 DateList qvl = mCurrentView->selectedDates(); 811 DateList qvl = mCurrentView->selectedDates();
810 if (!qvl.isEmpty()) qd = qvl.first(); 812 if (!qvl.isEmpty()) qd = qvl.first();
811 } 813 }
812 return qd; 814 return qd;
813} 815}
814 816
815void KOViewManager::addView(KOrg::BaseView *view) 817void KOViewManager::addView(KOrg::BaseView *view)
816{ 818{
817#if QT_VERSION >= 0x030000 819#if QT_VERSION >= 0x030000
818 mMainView->viewStack()->addWidget( view ); 820 mMainView->viewStack()->addWidget( view );
819#else 821#else
820 mMainView->viewStack()->addWidget( view, 1 ); 822 mMainView->viewStack()->addWidget( view, 1 );
821#endif 823#endif
822} 824}
823 825
824void KOViewManager::setDocumentId( const QString &id ) 826void KOViewManager::setDocumentId( const QString &id )
825{ 827{
826 if (mTodoView) mTodoView->setDocumentId( id ); 828 if (mTodoView) mTodoView->setDocumentId( id );
827} 829}