summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagendaview.cpp19
-rw-r--r--korganizer/komonthview.cpp2
2 files changed, 17 insertions, 4 deletions
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp
index 749204b..c5acafd 100644
--- a/korganizer/koagendaview.cpp
+++ b/korganizer/koagendaview.cpp
@@ -1,1443 +1,1456 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qhbox.h> 24#include <qhbox.h>
25#include <qvbox.h> 25#include <qvbox.h>
26#include <qlabel.h> 26#include <qlabel.h>
27#include <qframe.h> 27#include <qframe.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#ifndef KORG_NOSPLITTER 29#ifndef KORG_NOSPLITTER
30#include <qsplitter.h> 30#include <qsplitter.h>
31#endif 31#endif
32#include <qfont.h> 32#include <qfont.h>
33#include <qfontmetrics.h> 33#include <qfontmetrics.h>
34#include <qpopupmenu.h> 34#include <qpopupmenu.h>
35#include <qtooltip.h> 35#include <qtooltip.h>
36#include <qpainter.h> 36#include <qpainter.h>
37#include <qpushbutton.h> 37#include <qpushbutton.h>
38#include <qapplication.h> 38#include <qapplication.h>
39 39
40#include <kapplication.h> 40#include <kapplication.h>
41#include <KDGanttMinimizeSplitter.h> 41#include <KDGanttMinimizeSplitter.h>
42#include <kdebug.h> 42#include <kdebug.h>
43#include <kstandarddirs.h> 43#include <kstandarddirs.h>
44#include <kiconloader.h> 44#include <kiconloader.h>
45#include <klocale.h> 45#include <klocale.h>
46#include <kconfig.h> 46#include <kconfig.h>
47#include <kglobal.h> 47#include <kglobal.h>
48#include "calendarview.h" 48#include "calendarview.h"
49#include "koviewmanager.h" 49#include "koviewmanager.h"
50 50
51#include <libkcal/calendar.h> 51#include <libkcal/calendar.h>
52#include <libkcal/icaldrag.h> 52#include <libkcal/icaldrag.h>
53#include <libkcal/dndfactory.h> 53#include <libkcal/dndfactory.h>
54 54
55#include <kcalendarsystem.h> 55#include <kcalendarsystem.h>
56 56
57#include "koglobals.h" 57#include "koglobals.h"
58#ifndef KORG_NOPLUGINS 58#ifndef KORG_NOPLUGINS
59#include "kocore.h" 59#include "kocore.h"
60#endif 60#endif
61#include "koprefs.h" 61#include "koprefs.h"
62#include "koagenda.h" 62#include "koagenda.h"
63#include "koagendaitem.h" 63#include "koagendaitem.h"
64#ifndef KORG_NOPRINTER 64#ifndef KORG_NOPRINTER
65#include "calprinter.h" 65#include "calprinter.h"
66#endif 66#endif
67 67
68#include "koagendaview.h" 68#include "koagendaview.h"
69//#include "koagendaview.moc" 69//#include "koagendaview.moc"
70 70
71//extern bool globalFlagBlockPainting; 71//extern bool globalFlagBlockPainting;
72extern int globalFlagBlockAgenda; 72extern int globalFlagBlockAgenda;
73extern int globalFlagBlockStartup; 73extern int globalFlagBlockStartup;
74extern int globalFlagBlockAgendaItemPaint; 74extern int globalFlagBlockAgendaItemPaint;
75extern int globalFlagBlockAgendaItemUpdate; 75extern int globalFlagBlockAgendaItemUpdate;
76extern int globalFlagBlockLabel; 76extern int globalFlagBlockLabel;
77using namespace KOrg; 77using namespace KOrg;
78 78
79TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) : 79TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) :
80 QScrollView(parent,name,f) 80 QScrollView(parent,name,f)
81{ 81{
82 mRows = rows; 82 mRows = rows;
83 83
84 setMinimumHeight( 20 ); 84 setMinimumHeight( 20 );
85 mCellHeight = KOPrefs::instance()->mHourSize*4; 85 mCellHeight = KOPrefs::instance()->mHourSize*4;
86 86
87 enableClipper(true); 87 enableClipper(true);
88 88
89 setHScrollBarMode(AlwaysOff); 89 setHScrollBarMode(AlwaysOff);
90 setVScrollBarMode(AlwaysOff); 90 setVScrollBarMode(AlwaysOff);
91 91
92 resizeContents(50,mRows * mCellHeight); 92 resizeContents(50,mRows * mCellHeight);
93 93
94 viewport()->setBackgroundMode( PaletteBackground ); 94 viewport()->setBackgroundMode( PaletteBackground );
95} 95}
96 96
97void TimeLabels::setCellHeight(int height) 97void TimeLabels::setCellHeight(int height)
98{ 98{
99 mCellHeight = height; 99 mCellHeight = height;
100} 100}
101 101
102/* 102/*
103 Optimization so that only the "dirty" portion of the scroll view 103 Optimization so that only the "dirty" portion of the scroll view
104 is redrawn. Unfortunately, this is not called by default paintEvent() method. 104 is redrawn. Unfortunately, this is not called by default paintEvent() method.
105*/ 105*/
106void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) 106void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch)
107{ 107{
108 108
109 // if ( globalFlagBlockAgenda ) 109 // if ( globalFlagBlockAgenda )
110 // return; 110 // return;
111 // bug: the parameters cx, cy, cw, ch are the areas that need to be 111 // bug: the parameters cx, cy, cw, ch are the areas that need to be
112 // redrawn, not the area of the widget. unfortunately, this 112 // redrawn, not the area of the widget. unfortunately, this
113 // code assumes the latter... 113 // code assumes the latter...
114 114
115 // now, for a workaround... 115 // now, for a workaround...
116 // these two assignments fix the weird redraw bug 116 // these two assignments fix the weird redraw bug
117 cx = contentsX() + 2; 117 cx = contentsX() + 2;
118 cw = contentsWidth() - 2; 118 cw = contentsWidth() - 2;
119 // end of workaround 119 // end of workaround
120 120
121 int cell = ((int)(cy/mCellHeight)); 121 int cell = ((int)(cy/mCellHeight));
122 int y = cell * mCellHeight; 122 int y = cell * mCellHeight;
123 QFontMetrics fm = fontMetrics(); 123 QFontMetrics fm = fontMetrics();
124 QString hour; 124 QString hour;
125 QString suffix; 125 QString suffix;
126 QString fullTime; 126 QString fullTime;
127 int tW = fm.width("24:00i"); 127 int tW = fm.width("24:00i");
128 128
129 while (y < cy + ch) { 129 while (y < cy + ch) {
130 p->drawLine(cx,y,cx+tW,y); 130 p->drawLine(cx,y,cx+tW,y);
131 hour.setNum(cell); 131 hour.setNum(cell);
132 suffix = "am"; 132 suffix = "am";
133 133
134 // handle 24h and am/pm time formats 134 // handle 24h and am/pm time formats
135 if (KGlobal::locale()->use12Clock()) { 135 if (KGlobal::locale()->use12Clock()) {
136 if (cell > 11) suffix = "pm"; 136 if (cell > 11) suffix = "pm";
137 if (cell == 0) hour.setNum(12); 137 if (cell == 0) hour.setNum(12);
138 if (cell > 12) hour.setNum(cell - 12); 138 if (cell > 12) hour.setNum(cell - 12);
139 } else { 139 } else {
140 suffix = ":00"; 140 suffix = ":00";
141 } 141 }
142 142
143 // create string in format of "XX:XX" or "XXpm/am" 143 // create string in format of "XX:XX" or "XXpm/am"
144 fullTime = hour + suffix; 144 fullTime = hour + suffix;
145 145
146 // center and draw the time label 146 // center and draw the time label
147 int timeWidth = fm.width(fullTime+"i"); 147 int timeWidth = fm.width(fullTime+"i");
148 int offset = this->width() - timeWidth; 148 int offset = this->width() - timeWidth;
149 int borderWidth = 5; 149 int borderWidth = 5;
150 int timeHeight = fm.height(); 150 int timeHeight = fm.height();
151 timeHeight = timeHeight + 2 - ( timeHeight / 4 ); 151 timeHeight = timeHeight + 2 - ( timeHeight / 4 );
152 p->drawText(cx -borderWidth + offset, y+ timeHeight, fullTime); 152 p->drawText(cx -borderWidth + offset, y+ timeHeight, fullTime);
153 153
154 // increment indices 154 // increment indices
155 y += mCellHeight; 155 y += mCellHeight;
156 cell++; 156 cell++;
157 } 157 }
158} 158}
159 159
160/** 160/**
161 Calculates the minimum width. 161 Calculates the minimum width.
162*/ 162*/
163int TimeLabels::minimumWidth() const 163int TimeLabels::minimumWidth() const
164{ 164{
165 QFontMetrics fm = fontMetrics(); 165 QFontMetrics fm = fontMetrics();
166 166
167 //TODO: calculate this value 167 //TODO: calculate this value
168 int borderWidth = 4; 168 int borderWidth = 4;
169 169
170 // the maximum width possible 170 // the maximum width possible
171 int width = fm.width("88:88x") + borderWidth; 171 int width = fm.width("88:88x") + borderWidth;
172 172
173 return width; 173 return width;
174} 174}
175 175
176/** updates widget's internal state */ 176/** updates widget's internal state */
177void TimeLabels::updateConfig() 177void TimeLabels::updateConfig()
178{ 178{
179 // set the font 179 // set the font
180 // config->setGroup("Fonts"); 180 // config->setGroup("Fonts");
181 // QFont font = config->readFontEntry("TimeBar Font"); 181 // QFont font = config->readFontEntry("TimeBar Font");
182 setFont(KOPrefs::instance()->mTimeBarFont); 182 setFont(KOPrefs::instance()->mTimeBarFont);
183 183
184 // update geometry restrictions based on new settings 184 // update geometry restrictions based on new settings
185 setFixedWidth(minimumWidth()); 185 setFixedWidth(minimumWidth());
186 186
187 // update HourSize 187 // update HourSize
188 mCellHeight = KOPrefs::instance()->mHourSize*4; 188 mCellHeight = KOPrefs::instance()->mHourSize*4;
189 resizeContents(50,mRows * mCellHeight); 189 resizeContents(50,mRows * mCellHeight);
190} 190}
191 191
192/** update time label positions */ 192/** update time label positions */
193void TimeLabels::positionChanged() 193void TimeLabels::positionChanged()
194{ 194{
195 int adjustment = mAgenda->contentsY(); 195 int adjustment = mAgenda->contentsY();
196 setContentsPos(0, adjustment); 196 setContentsPos(0, adjustment);
197} 197}
198 198
199/** */ 199/** */
200void TimeLabels::setAgenda(KOAgenda* agenda) 200void TimeLabels::setAgenda(KOAgenda* agenda)
201{ 201{
202 mAgenda = agenda; 202 mAgenda = agenda;
203} 203}
204 204
205 205
206/** This is called in response to repaint() */ 206/** This is called in response to repaint() */
207void TimeLabels::paintEvent(QPaintEvent*) 207void TimeLabels::paintEvent(QPaintEvent*)
208{ 208{
209 209
210 // kdDebug() << "paintevent..." << endl; 210 // kdDebug() << "paintevent..." << endl;
211 // this is another hack! 211 // this is another hack!
212 // QPainter painter(this); 212 // QPainter painter(this);
213 //QString c 213 //QString c
214 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight()); 214 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight());
215} 215}
216 216
217//////////////////////////////////////////////////////////////////////////// 217////////////////////////////////////////////////////////////////////////////
218 218
219EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name) 219EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name)
220 : QFrame(parent,name) 220 : QFrame(parent,name)
221{ 221{
222 mColumns = 1; 222 mColumns = 1;
223 mTopBox = 0; 223 mTopBox = 0;
224 mLocation = loc; 224 mLocation = loc;
225 mTopLayout = 0; 225 mTopLayout = 0;
226 mPaintWidget = 0; 226 mPaintWidget = 0;
227 mXOffset = 0; 227 mXOffset = 0;
228 if (mLocation == Top) mPixmap = SmallIcon("1uparrow"); 228 if (mLocation == Top) mPixmap = SmallIcon("1uparrow");
229 else mPixmap = SmallIcon("1downarrow"); 229 else mPixmap = SmallIcon("1downarrow");
230 mEnabled.resize(mColumns); 230 mEnabled.resize(mColumns);
231 if (mLocation == Top) 231 if (mLocation == Top)
232 setMaximumHeight(0); 232 setMaximumHeight(0);
233 else 233 else
234 setMinimumHeight(mPixmap.height()); 234 setMinimumHeight(mPixmap.height());
235} 235}
236 236
237EventIndicator::~EventIndicator() 237EventIndicator::~EventIndicator()
238{ 238{
239} 239}
240 240
241void EventIndicator::drawContents(QPainter *p) 241void EventIndicator::drawContents(QPainter *p)
242{ 242{
243 243
244 // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl; 244 // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl;
245 KDGanttSplitterHandle* han = 0; 245 KDGanttSplitterHandle* han = 0;
246 if ( mPaintWidget ) 246 if ( mPaintWidget )
247 han = mPaintWidget->firstHandle(); 247 han = mPaintWidget->firstHandle();
248 if ( ! han ) { 248 if ( ! han ) {
249 int i; 249 int i;
250 for(i=0;i<mColumns;++i) { 250 for(i=0;i<mColumns;++i) {
251 if (mEnabled[i]) { 251 if (mEnabled[i]) {
252 int cellWidth = contentsRect().right()/mColumns; 252 int cellWidth = contentsRect().right()/mColumns;
253 int xOffset = KOGlobals::self()->reverseLayout() ? 253 int xOffset = KOGlobals::self()->reverseLayout() ?
254 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 : 254 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 :
255 i*cellWidth + cellWidth/2 -mPixmap.width()/2; 255 i*cellWidth + cellWidth/2 -mPixmap.width()/2;
256 p->drawPixmap(QPoint(xOffset,0),mPixmap); 256 p->drawPixmap(QPoint(xOffset,0),mPixmap);
257 } 257 }
258 } 258 }
259 } else { 259 } else {
260 han->repaint(); 260 han->repaint();
261 //mPaintWidget->setBackgroundColor( red ); 261 //mPaintWidget->setBackgroundColor( red );
262 262
263 QPainter pa( han ); 263 QPainter pa( han );
264 int i; 264 int i;
265 bool setColor = false; 265 bool setColor = false;
266 for(i=0;i<mColumns;++i) { 266 for(i=0;i<mColumns;++i) {
267 if (mEnabled[i]) { 267 if (mEnabled[i]) {
268 setColor = true; 268 setColor = true;
269 269
270 int cellWidth = contentsRect().right()/mColumns; 270 int cellWidth = contentsRect().right()/mColumns;
271 int xOffset = KOGlobals::self()->reverseLayout() ? 271 int xOffset = KOGlobals::self()->reverseLayout() ?
272 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 : 272 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 :
273 i*cellWidth + cellWidth/2 -mPixmap.width()/2; 273 i*cellWidth + cellWidth/2 -mPixmap.width()/2;
274 pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap); 274 pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap);
275 //qDebug("222draw pix %d ",xOffset ); 275 //qDebug("222draw pix %d ",xOffset );
276 276
277 } 277 }
278 278
279 } 279 }
280 pa.end(); 280 pa.end();
281 281
282 } 282 }
283} 283}
284 284
285void EventIndicator::setXOffset( int x ) 285void EventIndicator::setXOffset( int x )
286{ 286{
287 mXOffset = x; 287 mXOffset = x;
288} 288}
289void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w ) 289void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w )
290{ 290{
291 mPaintWidget = w; 291 mPaintWidget = w;
292} 292}
293void EventIndicator::changeColumns(int columns) 293void EventIndicator::changeColumns(int columns)
294{ 294{
295 mColumns = columns; 295 mColumns = columns;
296 mEnabled.resize(mColumns); 296 mEnabled.resize(mColumns);
297 297
298 update(); 298 update();
299} 299}
300 300
301void EventIndicator::enableColumn(int column, bool enable) 301void EventIndicator::enableColumn(int column, bool enable)
302{ 302{
303 mEnabled[column] = enable; 303 mEnabled[column] = enable;
304} 304}
305 305
306 306
307//////////////////////////////////////////////////////////////////////////// 307////////////////////////////////////////////////////////////////////////////
308//////////////////////////////////////////////////////////////////////////// 308////////////////////////////////////////////////////////////////////////////
309//////////////////////////////////////////////////////////////////////////// 309////////////////////////////////////////////////////////////////////////////
310 310
311KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) : 311KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) :
312 KOEventView (cal,parent,name) 312 KOEventView (cal,parent,name)
313{ 313{
314 mBlockUpdating = true; 314 mBlockUpdating = true;
315 mStartHour = 8; 315 mStartHour = 8;
316 mSelectedDates.append(QDate::currentDate()); 316 mSelectedDates.append(QDate::currentDate());
317 317
318 mLayoutDayLabels = 0; 318 mLayoutDayLabels = 0;
319 mDayLabelsFrame = 0; 319 mDayLabelsFrame = 0;
320 mDayLabels = 0; 320 mDayLabels = 0;
321 bool isRTL = KOGlobals::self()->reverseLayout(); 321 bool isRTL = KOGlobals::self()->reverseLayout();
322 322
323 if ( KOPrefs::instance()->mVerticalScreen ) { 323 if ( KOPrefs::instance()->mVerticalScreen ) {
324 mExpandedPixmap = SmallIcon( "1downarrow" ); 324 mExpandedPixmap = SmallIcon( "1downarrow" );
325 mNotExpandedPixmap = SmallIcon( "1uparrow" ); 325 mNotExpandedPixmap = SmallIcon( "1uparrow" );
326 } else { 326 } else {
327 mExpandedPixmap = SmallIcon( isRTL ? "1leftarrow" : "1rightarrow" ); 327 mExpandedPixmap = SmallIcon( isRTL ? "1leftarrow" : "1rightarrow" );
328 mNotExpandedPixmap = SmallIcon( isRTL ? "1rightarrow" : "1leftarrow" ); 328 mNotExpandedPixmap = SmallIcon( isRTL ? "1rightarrow" : "1leftarrow" );
329 } 329 }
330 330
331 QBoxLayout *topLayout = new QVBoxLayout(this); 331 QBoxLayout *topLayout = new QVBoxLayout(this);
332 332
333 // Create day name labels for agenda columns 333 // Create day name labels for agenda columns
334 mDayLabelsFrame = new QHBox(this); 334 mDayLabelsFrame = new QHBox(this);
335 topLayout->addWidget(mDayLabelsFrame); 335 topLayout->addWidget(mDayLabelsFrame);
336 mDayLabels = new QFrame (mDayLabelsFrame); 336 mDayLabels = new QFrame (mDayLabelsFrame);
337 mLayoutDayLabels = new QHBoxLayout(mDayLabels); 337 mLayoutDayLabels = new QHBoxLayout(mDayLabels);
338 // Create agenda splitter 338 // Create agenda splitter
339#ifndef KORG_NOSPLITTER 339#ifndef KORG_NOSPLITTER
340 mSplitterAgenda = new QSplitter(Vertical,this); 340 mSplitterAgenda = new QSplitter(Vertical,this);
341 topLayout->addWidget(mSplitterAgenda); 341 topLayout->addWidget(mSplitterAgenda);
342 mSplitterAgenda->setOpaqueResize(); 342 mSplitterAgenda->setOpaqueResize();
343 343
344 mAllDayFrame = new QHBox(mSplitterAgenda); 344 mAllDayFrame = new QHBox(mSplitterAgenda);
345 345
346 QWidget *agendaFrame = new QWidget(mSplitterAgenda); 346 QWidget *agendaFrame = new QWidget(mSplitterAgenda);
347#else 347#else
348#if 0 348#if 0
349 QWidget *mainBox = new QWidget( this ); 349 QWidget *mainBox = new QWidget( this );
350 topLayout->addWidget( mainBox ); 350 topLayout->addWidget( mainBox );
351 QBoxLayout *mainLayout = new QVBoxLayout(mainBox); 351 QBoxLayout *mainLayout = new QVBoxLayout(mainBox);
352 mAllDayFrame = new QHBox(mainBox); 352 mAllDayFrame = new QHBox(mainBox);
353 mainLayout->addWidget(mAllDayFrame); 353 mainLayout->addWidget(mAllDayFrame);
354 mainLayout->setStretchFactor( mAllDayFrame, 0 ); 354 mainLayout->setStretchFactor( mAllDayFrame, 0 );
355 mAllDayFrame->setFocusPolicy(NoFocus); 355 mAllDayFrame->setFocusPolicy(NoFocus);
356 QWidget *agendaFrame = new QWidget(mainBox); 356 QWidget *agendaFrame = new QWidget(mainBox);
357 mainLayout->addWidget(agendaFrame); 357 mainLayout->addWidget(agendaFrame);
358 mainLayout->setStretchFactor( agendaFrame, 10 ); 358 mainLayout->setStretchFactor( agendaFrame, 10 );
359 359
360 agendaFrame->setFocusPolicy(NoFocus); 360 agendaFrame->setFocusPolicy(NoFocus);
361#endif 361#endif
362 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this); 362 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this);
363 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 363 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
364 topLayout->addWidget( mSplitterAgenda ); 364 topLayout->addWidget( mSplitterAgenda );
365 mAllDayFrame = new QHBox(mSplitterAgenda); 365 mAllDayFrame = new QHBox(mSplitterAgenda);
366 mAllDayFrame->setFocusPolicy(NoFocus); 366 mAllDayFrame->setFocusPolicy(NoFocus);
367 QWidget *agendaFrame = new QWidget(mSplitterAgenda); 367 QWidget *agendaFrame = new QWidget(mSplitterAgenda);
368 agendaFrame->setFocusPolicy(NoFocus); 368 agendaFrame->setFocusPolicy(NoFocus);
369 369
370#endif 370#endif
371 371
372 // Create all-day agenda widget 372 // Create all-day agenda widget
373 mDummyAllDayLeft = new QVBox( mAllDayFrame ); 373 mDummyAllDayLeft = new QVBox( mAllDayFrame );
374 374
375 mExpandButton = new QPushButton(mDummyAllDayLeft); 375 mExpandButton = new QPushButton(mDummyAllDayLeft);
376 mExpandButton->setPixmap( mNotExpandedPixmap ); 376 mExpandButton->setPixmap( mNotExpandedPixmap );
377 int widebut = mExpandButton->sizeHint().width(); 377 int widebut = mExpandButton->sizeHint().width();
378 if ( QApplication::desktop()->width() < 480 ) 378 if ( QApplication::desktop()->width() < 480 )
379 widebut = widebut*2; 379 widebut = widebut*2;
380 else 380 else
381 widebut = (widebut*3) / 2; 381 widebut = (widebut*3) / 2;
382 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, 382 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed,
383 // QSizePolicy::Fixed ) ); 383 // QSizePolicy::Fixed ) );
384 mExpandButton->setFixedSize( widebut, widebut); 384 mExpandButton->setFixedSize( widebut, widebut);
385 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) ); 385 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) );
386 mExpandButton->setFocusPolicy(NoFocus); 386 mExpandButton->setFocusPolicy(NoFocus);
387 mAllDayAgenda = new KOAgenda(1,mAllDayFrame); 387 mAllDayAgenda = new KOAgenda(1,mAllDayFrame);
388 mAllDayAgenda->setFocusPolicy(NoFocus); 388 mAllDayAgenda->setFocusPolicy(NoFocus);
389 QWidget *dummyAllDayRight = new QWidget(mAllDayFrame); 389 QWidget *dummyAllDayRight = new QWidget(mAllDayFrame);
390 390
391 // Create event context menu for all day agenda 391 // Create event context menu for all day agenda
392 mAllDayAgendaPopup = eventPopup(); 392 mAllDayAgendaPopup = eventPopup();
393 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), 393 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
394 mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *))); 394 mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
395 395
396 // Create agenda frame 396 // Create agenda frame
397 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,3,3); 397 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,3,3);
398 // QHBox *agendaFrame = new QHBox(splitterAgenda); 398 // QHBox *agendaFrame = new QHBox(splitterAgenda);
399 399
400 // create event indicator bars 400 // create event indicator bars
401 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame); 401 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame);
402 agendaLayout->addWidget(mEventIndicatorTop,0,1); 402 agendaLayout->addWidget(mEventIndicatorTop,0,1);
403 mEventIndicatorTop->setPaintWidget( mSplitterAgenda ); 403 mEventIndicatorTop->setPaintWidget( mSplitterAgenda );
404 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom, 404 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom,
405 agendaFrame); 405 agendaFrame);
406 agendaLayout->addWidget(mEventIndicatorBottom,2,1); 406 agendaLayout->addWidget(mEventIndicatorBottom,2,1);
407 QWidget *dummyAgendaRight = new QWidget(agendaFrame); 407 QWidget *dummyAgendaRight = new QWidget(agendaFrame);
408 agendaLayout->addWidget(dummyAgendaRight,0,2); 408 agendaLayout->addWidget(dummyAgendaRight,0,2);
409 409
410 // Create time labels 410 // Create time labels
411 mTimeLabels = new TimeLabels(24,agendaFrame); 411 mTimeLabels = new TimeLabels(24,agendaFrame);
412 agendaLayout->addWidget(mTimeLabels,1,0); 412 agendaLayout->addWidget(mTimeLabels,1,0);
413 413
414 // Create agenda 414 // Create agenda
415 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame); 415 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame);
416 agendaLayout->addMultiCellWidget(mAgenda,1,1,1,2); 416 agendaLayout->addMultiCellWidget(mAgenda,1,1,1,2);
417 agendaLayout->setColStretch(1,1); 417 agendaLayout->setColStretch(1,1);
418 mAgenda->setFocusPolicy(NoFocus); 418 mAgenda->setFocusPolicy(NoFocus);
419 // Create event context menu for agenda 419 // Create event context menu for agenda
420 mAgendaPopup = eventPopup(); 420 mAgendaPopup = eventPopup();
421 421
422 mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")), 422 mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")),
423 i18n("Toggle Alarm"),mAgenda, 423 i18n("Toggle Alarm"),mAgenda,
424 SLOT(popupAlarm()),true); 424 SLOT(popupAlarm()),true);
425 425
426 426
427 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), 427 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
428 mAgendaPopup,SLOT(showIncidencePopup(Incidence *))); 428 mAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
429 429
430 // make connections between dependent widgets 430 // make connections between dependent widgets
431 mTimeLabels->setAgenda(mAgenda); 431 mTimeLabels->setAgenda(mAgenda);
432 432
433 // Update widgets to reflect user preferences 433 // Update widgets to reflect user preferences
434 // updateConfig(); 434 // updateConfig();
435 435
436 // createDayLabels(); 436 // createDayLabels();
437 437
438 // these blank widgets make the All Day Event box line up with the agenda 438 // these blank widgets make the All Day Event box line up with the agenda
439 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 439 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
440 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 440 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
441 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 441 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
442 442
443 // Scrolling 443 // Scrolling
444 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)), 444 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)),
445 mTimeLabels, SLOT(positionChanged())); 445 mTimeLabels, SLOT(positionChanged()));
446 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)), 446 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)),
447 SLOT(setContentsPos(int))); 447 SLOT(setContentsPos(int)));
448 448
449 // Create/Show/Edit/Delete Event 449 // Create/Show/Edit/Delete Event
450 connect(mAgenda,SIGNAL(newEventSignal(int,int)), 450 connect(mAgenda,SIGNAL(newEventSignal(int,int)),
451 SLOT(newEvent(int,int))); 451 SLOT(newEvent(int,int)));
452 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)), 452 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)),
453 SLOT(newEvent(int,int,int,int))); 453 SLOT(newEvent(int,int,int,int)));
454 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)), 454 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)),
455 SLOT(newEventAllDay(int,int))); 455 SLOT(newEventAllDay(int,int)));
456 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)), 456 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)),
457 SLOT(newEventAllDay(int,int))); 457 SLOT(newEventAllDay(int,int)));
458 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 458 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
459 SLOT(newTimeSpanSelected(int,int,int,int))); 459 SLOT(newTimeSpanSelected(int,int,int,int)));
460 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 460 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
461 SLOT(newTimeSpanSelectedAllDay(int,int,int,int))); 461 SLOT(newTimeSpanSelectedAllDay(int,int,int,int)));
462 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 462 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
463 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 463 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
464 464
465 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 465 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
466 SIGNAL(editIncidenceSignal(Incidence *))); 466 SIGNAL(editIncidenceSignal(Incidence *)));
467 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 467 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
468 SIGNAL(editIncidenceSignal(Incidence *))); 468 SIGNAL(editIncidenceSignal(Incidence *)));
469 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 469 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
470 SIGNAL(showIncidenceSignal(Incidence *))); 470 SIGNAL(showIncidenceSignal(Incidence *)));
471 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 471 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
472 SIGNAL(showIncidenceSignal(Incidence *))); 472 SIGNAL(showIncidenceSignal(Incidence *)));
473 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 473 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
474 SIGNAL(deleteIncidenceSignal(Incidence *))); 474 SIGNAL(deleteIncidenceSignal(Incidence *)));
475 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 475 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
476 SIGNAL(deleteIncidenceSignal(Incidence *))); 476 SIGNAL(deleteIncidenceSignal(Incidence *)));
477 477
478 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 478 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
479 SLOT(updateEventDates(KOAgendaItem *, int ))); 479 SLOT(updateEventDates(KOAgendaItem *, int )));
480 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 480 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
481 SLOT(updateEventDates(KOAgendaItem *, int))); 481 SLOT(updateEventDates(KOAgendaItem *, int)));
482 482
483 // event indicator update 483 // event indicator update
484 connect(mAgenda,SIGNAL(lowerYChanged(int)), 484 connect(mAgenda,SIGNAL(lowerYChanged(int)),
485 SLOT(updateEventIndicatorTop(int))); 485 SLOT(updateEventIndicatorTop(int)));
486 connect(mAgenda,SIGNAL(upperYChanged(int)), 486 connect(mAgenda,SIGNAL(upperYChanged(int)),
487 SLOT(updateEventIndicatorBottom(int))); 487 SLOT(updateEventIndicatorBottom(int)));
488 // drag signals 488 // drag signals
489 /* 489 /*
490 connect(mAgenda,SIGNAL(startDragSignal(Event *)), 490 connect(mAgenda,SIGNAL(startDragSignal(Event *)),
491 SLOT(startDrag(Event *))); 491 SLOT(startDrag(Event *)));
492 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)), 492 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)),
493 SLOT(startDrag(Event *))); 493 SLOT(startDrag(Event *)));
494 */ 494 */
495 // synchronize selections 495 // synchronize selections
496 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 496 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
497 mAllDayAgenda, SLOT( deselectItem() ) ); 497 mAllDayAgenda, SLOT( deselectItem() ) );
498 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 498 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
499 mAgenda, SLOT( deselectItem() ) ); 499 mAgenda, SLOT( deselectItem() ) );
500 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 500 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
501 SIGNAL( incidenceSelected( Incidence * ) ) ); 501 SIGNAL( incidenceSelected( Incidence * ) ) );
502 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 502 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
503 SIGNAL( incidenceSelected( Incidence * ) ) ); 503 SIGNAL( incidenceSelected( Incidence * ) ) );
504 connect( mAgenda, SIGNAL( resizedSignal() ), 504 connect( mAgenda, SIGNAL( resizedSignal() ),
505 SLOT( updateConfig( ) ) ); 505 SLOT( updateConfig( ) ) );
506 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ), 506 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ),
507 SLOT( addToCalSlot(Incidence *, Incidence * ) ) ); 507 SLOT( addToCalSlot(Incidence *, Incidence * ) ) );
508 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ), 508 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ),
509 SLOT( addToCalSlot(Incidence * , Incidence *) ) ); 509 SLOT( addToCalSlot(Incidence * , Incidence *) ) );
510 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 510 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
511 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 511 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
512 512
513 513
514} 514}
515 515
516void KOAgendaView::toggleAllDay() 516void KOAgendaView::toggleAllDay()
517{ 517{
518 if ( mSplitterAgenda->firstHandle() ) 518 if ( mSplitterAgenda->firstHandle() )
519 mSplitterAgenda->firstHandle()->toggle(); 519 mSplitterAgenda->firstHandle()->toggle();
520} 520}
521void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld ) 521void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld )
522{ 522{
523 calendar()->addIncidence( inc ); 523 calendar()->addIncidence( inc );
524 524
525 if ( incOld ) { 525 if ( incOld ) {
526 if ( incOld->type() == "Todo" ) 526 if ( incOld->type() == "Todo" )
527 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED ); 527 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED );
528 else 528 else
529 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED); 529 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED);
530 } 530 }
531 531
532} 532}
533 533
534KOAgendaView::~KOAgendaView() 534KOAgendaView::~KOAgendaView()
535{ 535{
536 delete mAgendaPopup; 536 delete mAgendaPopup;
537 delete mAllDayAgendaPopup; 537 delete mAllDayAgendaPopup;
538 delete KOAgendaItem::paintPix(); 538 delete KOAgendaItem::paintPix();
539 delete KOAgendaItem::paintPixSel(); 539 delete KOAgendaItem::paintPixSel();
540} 540}
541void KOAgendaView::resizeEvent( QResizeEvent* e ) 541void KOAgendaView::resizeEvent( QResizeEvent* e )
542{ 542{
543 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); 543 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width());
544 bool uc = false; 544 bool uc = false;
545 int ow = e->oldSize().width(); 545 int ow = e->oldSize().width();
546 int oh = e->oldSize().height(); 546 int oh = e->oldSize().height();
547 int w = e->size().width(); 547 int w = e->size().width();
548 int h = e->size().height(); 548 int h = e->size().height();
549 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { 549 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) {
550 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) 550 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda )
551 uc = true; 551 uc = true;
552 //qDebug("view changed %d %d %d %d ", ow, oh , w , h); 552 //qDebug("view changed %d %d %d %d ", ow, oh , w , h);
553 } 553 }
554 mUpcomingWidth = e->size().width() ; 554 mUpcomingWidth = e->size().width() ;
555 if ( mBlockUpdating || uc ) { 555 if ( mBlockUpdating || uc ) {
556 mBlockUpdating = false; 556 mBlockUpdating = false;
557 //mAgenda->setMinimumSize(800 , 600 ); 557 //mAgenda->setMinimumSize(800 , 600 );
558 //qDebug("mAgenda->resize+++++++++++++++ "); 558 //qDebug("mAgenda->resize+++++++++++++++ ");
559 updateConfig(); 559 updateConfig();
560 //qDebug("KOAgendaView::Updating now possible "); 560 //qDebug("KOAgendaView::Updating now possible ");
561 } else 561 } else
562 createDayLabels(); 562 createDayLabels();
563 //qDebug("resizeEvent end "); 563 //qDebug("resizeEvent end ");
564 564
565} 565}
566void KOAgendaView::createDayLabels() 566void KOAgendaView::createDayLabels()
567{ 567{
568 568
569 if ( mBlockUpdating || globalFlagBlockLabel == 1) { 569 if ( mBlockUpdating || globalFlagBlockLabel == 1) {
570 // qDebug(" KOAgendaView::createDayLabels() blocked "); 570 // qDebug(" KOAgendaView::createDayLabels() blocked ");
571 return; 571 return;
572 572
573 } 573 }
574 int newHight; 574 int newHight;
575 575
576 // ### Before deleting and recreating we could check if mSelectedDates changed... 576 // ### Before deleting and recreating we could check if mSelectedDates changed...
577 // It would remove some flickering and gain speed (since this is called by 577 // It would remove some flickering and gain speed (since this is called by
578 // each updateView() call) 578 // each updateView() call)
579 579
580 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - 2; 580 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - 2;
581 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); 581 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth );
582 if ( maxWid < 0 ) 582 if ( maxWid < 0 )
583 maxWid = 20; 583 maxWid = 20;
584 584
585 QFont dlf = KOPrefs::instance()->mTimeLabelsFont; 585 QFont dlf = KOPrefs::instance()->mTimeLabelsFont;
586 QFontMetrics fm ( dlf ); 586 QFontMetrics fm ( dlf );
587 int selCount = mSelectedDates.count(); 587 int selCount = mSelectedDates.count();
588 QString dayTest = "Mon 20"; 588 QString dayTest = "Mon 20";
589 int wid = fm.width( dayTest ); 589 int wid = fm.width( dayTest );
590 maxWid -= ( selCount * 3 ); 590 maxWid -= ( selCount * 3 );
591 if ( maxWid < 0 ) 591 if ( maxWid < 0 )
592 maxWid = 20; 592 maxWid = 20;
593 int needWid = wid * selCount; 593 int needWid = wid * selCount;
594 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); 594 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid );
595 //if ( needWid > maxWid ) 595 //if ( needWid > maxWid )
596 // qDebug("DAYLABELS TOOOOOOO BIG "); 596 // qDebug("DAYLABELS TOOOOOOO BIG ");
597 while ( needWid > maxWid ) { 597 while ( needWid > maxWid ) {
598 dayTest = dayTest.left( dayTest.length() - 1 ); 598 dayTest = dayTest.left( dayTest.length() - 1 );
599 wid = fm.width( dayTest ); 599 wid = fm.width( dayTest );
600 needWid = wid * selCount; 600 needWid = wid * selCount;
601 } 601 }
602 int maxLen = dayTest.length(); 602 int maxLen = dayTest.length();
603 int fontPoint = dlf.pointSize(); 603 int fontPoint = dlf.pointSize();
604 if ( maxLen < 2 ) { 604 if ( maxLen < 2 ) {
605 int fontPoint = dlf.pointSize(); 605 int fontPoint = dlf.pointSize();
606 while ( fontPoint > 4 ) { 606 while ( fontPoint > 4 ) {
607 --fontPoint; 607 --fontPoint;
608 dlf.setPointSize( fontPoint ); 608 dlf.setPointSize( fontPoint );
609 QFontMetrics f( dlf ); 609 QFontMetrics f( dlf );
610 wid = f.width( "20" ); 610 wid = f.width( "20" );
611 needWid = wid * selCount; 611 needWid = wid * selCount;
612 if ( needWid < maxWid ) 612 if ( needWid < maxWid )
613 break; 613 break;
614 } 614 }
615 maxLen = 2; 615 maxLen = 2;
616 } 616 }
617 //qDebug("Max len %d ", dayTest.length() ); 617 //qDebug("Max len %d ", dayTest.length() );
618 618
619 QFontMetrics tempF( dlf ); 619 QFontMetrics tempF( dlf );
620 newHight = tempF.height(); 620 newHight = tempF.height();
621 mDayLabels->setFont( dlf ); 621 mDayLabels->setFont( dlf );
622 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; 622 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);;
623 // mLayoutDayLabels->addSpacing(mTimeLabels->width()); 623 // mLayoutDayLabels->addSpacing(mTimeLabels->width());
624 //mLayoutDayLabels->addSpacing( 2 ); 624 //mLayoutDayLabels->addSpacing( 2 );
625 // QFont lFont = dlf; 625 // QFont lFont = dlf;
626 bool appendLabels = false; 626 bool appendLabels = false;
627 QLabel *dayLabel; 627 QLabel *dayLabel;
628 dayLabel = mDayLabelsList.first(); 628 dayLabel = mDayLabelsList.first();
629 if ( !dayLabel ) { 629 if ( !dayLabel ) {
630 appendLabels = true; 630 appendLabels = true;
631 dayLabel = new QLabel(mDayLabels); 631 dayLabel = new QLabel(mDayLabels);
632 mDayLabelsList.append( dayLabel ); 632 mDayLabelsList.append( dayLabel );
633 mLayoutDayLabels->addWidget(dayLabel); 633 mLayoutDayLabels->addWidget(dayLabel);
634 } 634 }
635 dayLabel->setFixedWidth( mTimeLabels->width()+2 ); 635 dayLabel->setFixedWidth( mTimeLabels->width()+2 );
636 dayLabel->setFont( dlf ); 636 dayLabel->setFont( dlf );
637 dayLabel->setAlignment(QLabel::AlignHCenter); 637 dayLabel->setAlignment(QLabel::AlignHCenter);
638 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); 638 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) );
639 dayLabel->show(); 639 dayLabel->show();
640 DateList::ConstIterator dit; 640 DateList::ConstIterator dit;
641 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 641 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
642 QDate date = *dit; 642 QDate date = *dit;
643 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); 643 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels);
644 if ( ! appendLabels ) { 644 if ( ! appendLabels ) {
645 dayLabel = mDayLabelsList.next(); 645 dayLabel = mDayLabelsList.next();
646 if ( !dayLabel ) 646 if ( !dayLabel )
647 appendLabels = true; 647 appendLabels = true;
648 } 648 }
649 if ( appendLabels ) { 649 if ( appendLabels ) {
650 dayLabel = new QLabel(mDayLabels); 650 dayLabel = new QLabel(mDayLabels);
651 mDayLabelsList.append( dayLabel ); 651 mDayLabelsList.append( dayLabel );
652 mLayoutDayLabels->addWidget(dayLabel); 652 mLayoutDayLabels->addWidget(dayLabel);
653 } 653 }
654 dayLabel->setMinimumWidth( 1 ); 654 dayLabel->setMinimumWidth( 1 );
655 dayLabel->setMaximumWidth( 2048 ); 655 dayLabel->setMaximumWidth( 2048 );
656 dayLabel->setFont( dlf ); 656 dayLabel->setFont( dlf );
657 dayLabel->show(); 657 dayLabel->show();
658 QString str; 658 QString str;
659 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date); 659 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date);
660 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true ); 660 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true );
661 switch ( maxLen ) { 661 switch ( maxLen ) {
662 case 2: 662 case 2:
663 str = QString::number( date.day() ); 663 str = QString::number( date.day() );
664 break; 664 break;
665 665
666 case 3: 666 case 3:
667 str = dayName.left( 1 ) +QString::number( date.day()); 667 str = dayName.left( 1 ) +QString::number( date.day());
668 668
669 break; 669 break;
670 case 4: 670 case 4:
671 str = dayName.left( 1 ) + " " +QString::number( date.day()); 671 str = dayName.left( 1 ) + " " +QString::number( date.day());
672 672
673 break; 673 break;
674 case 5: 674 case 5:
675 str = dayName.left( 2 ) + " " +QString::number( date.day()); 675 str = dayName.left( 2 ) + " " +QString::number( date.day());
676 676
677 break; 677 break;
678 case 6: 678 case 6:
679 str = dayName.left( 3 ) + " " +QString::number( date.day()); 679 str = dayName.left( 3 ) + " " +QString::number( date.day());
680 break; 680 break;
681 681
682 default: 682 default:
683 break; 683 break;
684 } 684 }
685 685
686 dayLabel->setText(str); 686 dayLabel->setText(str);
687 dayLabel->setAlignment(QLabel::AlignHCenter); 687 dayLabel->setAlignment(QLabel::AlignHCenter);
688 if (date == QDate::currentDate()) { 688 if (date == QDate::currentDate()) {
689 QFont bFont = dlf; 689 QFont bFont = dlf;
690 bFont.setBold( true ); 690 bFont.setBold( true );
691 dayLabel->setFont(bFont); 691 dayLabel->setFont(bFont);
692 } 692 }
693 //dayLayout->addWidget(dayLabel); 693 //dayLayout->addWidget(dayLabel);
694 694
695#ifndef KORG_NOPLUGINS 695#ifndef KORG_NOPLUGINS
696 CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); 696 CalendarDecoration::List cds = KOCore::self()->calendarDecorations();
697 CalendarDecoration *it; 697 CalendarDecoration *it;
698 for(it = cds.first(); it; it = cds.next()) { 698 for(it = cds.first(); it; it = cds.next()) {
699 QString text = it->shortText( date ); 699 QString text = it->shortText( date );
700 if ( !text.isEmpty() ) { 700 if ( !text.isEmpty() ) {
701 QLabel *label = new QLabel(text,mDayLabels); 701 QLabel *label = new QLabel(text,mDayLabels);
702 label->setAlignment(AlignCenter); 702 label->setAlignment(AlignCenter);
703 dayLayout->addWidget(label); 703 dayLayout->addWidget(label);
704 } 704 }
705 } 705 }
706 706
707 for(it = cds.first(); it; it = cds.next()) { 707 for(it = cds.first(); it; it = cds.next()) {
708 QWidget *wid = it->smallWidget(mDayLabels,date); 708 QWidget *wid = it->smallWidget(mDayLabels,date);
709 if ( wid ) { 709 if ( wid ) {
710 // wid->setHeight(20); 710 // wid->setHeight(20);
711 dayLayout->addWidget(wid); 711 dayLayout->addWidget(wid);
712 } 712 }
713 } 713 }
714#endif 714#endif
715 } 715 }
716 if ( ! appendLabels ) { 716 if ( ! appendLabels ) {
717 dayLabel = mDayLabelsList.next(); 717 dayLabel = mDayLabelsList.next();
718 if ( !dayLabel ) 718 if ( !dayLabel )
719 appendLabels = true; 719 appendLabels = true;
720 } 720 }
721 if ( appendLabels ) { 721 if ( appendLabels ) {
722 dayLabel = new QLabel(mDayLabels); 722 dayLabel = new QLabel(mDayLabels);
723 mDayLabelsList.append( dayLabel ); 723 mDayLabelsList.append( dayLabel );
724 mLayoutDayLabels->addWidget(dayLabel); 724 mLayoutDayLabels->addWidget(dayLabel);
725 } 725 }
726 //dayLabel->hide();//test only 726 //dayLabel->hide();//test only
727 727
728 int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()-3 ) % mSelectedDates.count() ; 728 int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()-3 ) % mSelectedDates.count() ;
729 if ( offset < 0 ) offset = 0; 729 if ( offset < 0 ) offset = 0;
730 //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 ); 730 //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 );
731 dayLabel->setText("");//QString::number ( mSelectedDates.first().month() ) ); 731 dayLabel->setText("");//QString::number ( mSelectedDates.first().month() ) );
732 dayLabel->show(); 732 dayLabel->show();
733 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset ); 733 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset );
734 //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2); 734 //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2);
735 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); 735 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2);
736 if ( !appendLabels ) { 736 if ( !appendLabels ) {
737 dayLabel = mDayLabelsList.next(); 737 dayLabel = mDayLabelsList.next();
738 while ( dayLabel ) { 738 while ( dayLabel ) {
739 //qDebug("!dayLabel %d",dayLabel ); 739 //qDebug("!dayLabel %d",dayLabel );
740 dayLabel->hide(); 740 dayLabel->hide();
741 dayLabel = mDayLabelsList.next(); 741 dayLabel = mDayLabelsList.next();
742 } 742 }
743 } 743 }
744 //mDayLabelsFrame->show(); 744 //mDayLabelsFrame->show();
745 //mDayLabels->show(); 745 //mDayLabels->show();
746 //qDebug("heigt %d %d %d ",mDayLabelsFrame->height(), mDayLabelsFrame->sizeHint().height(), newHight); 746 //qDebug("heigt %d %d %d ",mDayLabelsFrame->height(), mDayLabelsFrame->sizeHint().height(), newHight);
747 //mDayLabelsFrame->resize( mAgenda->visibleWidth(), newHight ); 747 //mDayLabelsFrame->resize( mAgenda->visibleWidth(), newHight );
748 mDayLabelsFrame->setFixedHeight( newHight ); 748 mDayLabelsFrame->setFixedHeight( newHight );
749} 749}
750 750
751int KOAgendaView::maxDatesHint() 751int KOAgendaView::maxDatesHint()
752{ 752{
753 // Not sure about the max number of events, so return 0 for now. 753 // Not sure about the max number of events, so return 0 for now.
754 return 0; 754 return 0;
755} 755}
756 756
757int KOAgendaView::currentDateCount() 757int KOAgendaView::currentDateCount()
758{ 758{
759 return mSelectedDates.count(); 759 return mSelectedDates.count();
760} 760}
761 761
762QPtrList<Incidence> KOAgendaView::selectedIncidences() 762QPtrList<Incidence> KOAgendaView::selectedIncidences()
763{ 763{
764 QPtrList<Incidence> selected; 764 QPtrList<Incidence> selected;
765 Incidence *incidence; 765 Incidence *incidence;
766 766
767 incidence = mAgenda->selectedIncidence(); 767 incidence = mAgenda->selectedIncidence();
768 if (incidence) selected.append(incidence); 768 if (incidence) selected.append(incidence);
769 769
770 incidence = mAllDayAgenda->selectedIncidence(); 770 incidence = mAllDayAgenda->selectedIncidence();
771 if (incidence) selected.append(incidence); 771 if (incidence) selected.append(incidence);
772 772
773 return selected; 773 return selected;
774} 774}
775 775
776DateList KOAgendaView::selectedDates() 776DateList KOAgendaView::selectedDates()
777{ 777{
778 DateList selected; 778 DateList selected;
779 QDate qd; 779 QDate qd;
780 780
781 qd = mAgenda->selectedIncidenceDate(); 781 qd = mAgenda->selectedIncidenceDate();
782 if (qd.isValid()) selected.append(qd); 782 if (qd.isValid()) selected.append(qd);
783 783
784 qd = mAllDayAgenda->selectedIncidenceDate(); 784 qd = mAllDayAgenda->selectedIncidenceDate();
785 if (qd.isValid()) selected.append(qd); 785 if (qd.isValid()) selected.append(qd);
786 786
787 return selected; 787 return selected;
788} 788}
789 789
790 790
791void KOAgendaView::updateView() 791void KOAgendaView::updateView()
792{ 792{
793 if ( mBlockUpdating ) 793 if ( mBlockUpdating )
794 return; 794 return;
795 // kdDebug() << "KOAgendaView::updateView()" << endl; 795 // kdDebug() << "KOAgendaView::updateView()" << endl;
796 fillAgenda(); 796 fillAgenda();
797 797
798} 798}
799 799
800 800
801/* 801/*
802 Update configuration settings for the agenda view. This method is not 802 Update configuration settings for the agenda view. This method is not
803 complete. 803 complete.
804*/ 804*/
805void KOAgendaView::updateConfig() 805void KOAgendaView::updateConfig()
806{ 806{
807 if ( mBlockUpdating ) 807 if ( mBlockUpdating )
808 return; 808 return;
809 // kdDebug() << "KOAgendaView::updateConfig()" << endl; 809 // kdDebug() << "KOAgendaView::updateConfig()" << endl;
810 810
811 // update config for children 811 // update config for children
812 mTimeLabels->updateConfig(); 812 mTimeLabels->updateConfig();
813 mAgenda->storePosition(); 813 mAgenda->storePosition();
814 mAgenda->updateConfig(); 814 mAgenda->updateConfig();
815 mAllDayAgenda->updateConfig(); 815 mAllDayAgenda->updateConfig();
816 // widget synchronization 816 // widget synchronization
817 //TODO: find a better way, maybe signal/slot 817 //TODO: find a better way, maybe signal/slot
818 mTimeLabels->positionChanged(); 818 mTimeLabels->positionChanged();
819 819
820 // for some reason, this needs to be called explicitly 820 // for some reason, this needs to be called explicitly
821 mTimeLabels->repaint(); 821 mTimeLabels->repaint();
822 822
823 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 823 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
824 824
825 // ToolTips displaying summary of events 825 // ToolTips displaying summary of events
826 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance() 826 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance()
827 ->mEnableToolTips); 827 ->mEnableToolTips);
828 828
829 //setHolidayMasks(); 829 //setHolidayMasks();
830 830
831 //createDayLabels(); called by via updateView(); 831 //createDayLabels(); called by via updateView();
832 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth()); 832 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth());
833 updateView(); 833 updateView();
834 mAgenda->restorePosition(); 834 mAgenda->restorePosition();
835} 835}
836 836
837 837
838void KOAgendaView::updateEventDates(KOAgendaItem *item, int type) 838void KOAgendaView::updateEventDates(KOAgendaItem *item, int type)
839{ 839{
840 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl; 840 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl;
841 //qDebug("KOAgendaView::updateEventDates "); 841 //qDebug("KOAgendaView::updateEventDates ");
842 QDateTime startDt,endDt; 842 QDateTime startDt,endDt;
843 QDate startDate; 843 QDate startDate;
844 int lenInSecs; 844 int lenInSecs;
845 // if ( type == KOAgenda::RESIZETOP ) 845 // if ( type == KOAgenda::RESIZETOP )
846 // qDebug("RESIZETOP "); 846 // qDebug("RESIZETOP ");
847 // if ( type == KOAgenda::RESIZEBOTTOM ) 847 // if ( type == KOAgenda::RESIZEBOTTOM )
848 // qDebug("RESIZEBOTTOM "); 848 // qDebug("RESIZEBOTTOM ");
849 // if ( type == KOAgenda::MOVE ) 849 // if ( type == KOAgenda::MOVE )
850 // qDebug("MOVE "); 850 // qDebug("MOVE ");
851 if ( item->incidence()->type() == "Event" ) { 851 if ( item->incidence()->type() == "Event" ) {
852 startDt =item->incidence()->dtStart(); 852 startDt =item->incidence()->dtStart();
853 endDt = item->incidence()->dtEnd(); 853 endDt = item->incidence()->dtEnd();
854 lenInSecs = startDt.secsTo( endDt ); 854 lenInSecs = startDt.secsTo( endDt );
855 } 855 }
856 856
857 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED ); 857 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED );
858 858
859 if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) { 859 if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) {
860 startDate = mSelectedDates[item->mLastMoveXPos]; 860 startDate = mSelectedDates[item->mLastMoveXPos];
861 } else { 861 } else {
862 if (item->cellX() < 0) { 862 if (item->cellX() < 0) {
863 startDate = (mSelectedDates.first()).addDays(item->cellX()); 863 startDate = (mSelectedDates.first()).addDays(item->cellX());
864 } else { 864 } else {
865 startDate = mSelectedDates[item->cellX()]; 865 startDate = mSelectedDates[item->cellX()];
866 } 866 }
867 } 867 }
868 startDt.setDate(startDate); 868 startDt.setDate(startDate);
869 869
870 if (item->incidence()->doesFloat()) { 870 if (item->incidence()->doesFloat()) {
871 endDt.setDate(startDate.addDays(item->cellWidth() - 1)); 871 endDt.setDate(startDate.addDays(item->cellWidth() - 1));
872 } else { 872 } else {
873 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE ) 873 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE )
874 startDt.setTime(mAgenda->gyToTime(item->cellYTop())); 874 startDt.setTime(mAgenda->gyToTime(item->cellYTop()));
875 if ( item->incidence()->type() == "Event" ) { 875 if ( item->incidence()->type() == "Event" ) {
876 if ( type == KOAgenda::MOVE ) { 876 if ( type == KOAgenda::MOVE ) {
877 endDt = startDt.addSecs(lenInSecs); 877 endDt = startDt.addSecs(lenInSecs);
878 878
879 } else if ( type == KOAgenda::RESIZEBOTTOM ) { 879 } else if ( type == KOAgenda::RESIZEBOTTOM ) {
880 if (item->lastMultiItem()) { 880 if (item->lastMultiItem()) {
881 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 881 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
882 endDt.setDate(startDate. 882 endDt.setDate(startDate.
883 addDays(item->lastMultiItem()->cellX() - item->cellX())); 883 addDays(item->lastMultiItem()->cellX() - item->cellX()));
884 } else { 884 } else {
885 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 885 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
886 endDt.setDate(startDate); 886 endDt.setDate(startDate);
887 } 887 }
888 } 888 }
889 } else { 889 } else {
890 // todo 890 // todo
891 if (item->lastMultiItem()) { 891 if (item->lastMultiItem()) {
892 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 892 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
893 endDt.setDate(startDate. 893 endDt.setDate(startDate.
894 addDays(item->lastMultiItem()->cellX() - item->cellX())); 894 addDays(item->lastMultiItem()->cellX() - item->cellX()));
895 } else { 895 } else {
896 //qDebug("tem->cellYBottom() %d",item->cellYBottom() ); 896 //qDebug("tem->cellYBottom() %d",item->cellYBottom() );
897 if ( item->cellYBottom() > 0 ) 897 if ( item->cellYBottom() > 0 )
898 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 898 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
899 else 899 else
900 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time()); 900 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time());
901 endDt.setDate(startDate); 901 endDt.setDate(startDate);
902 } 902 }
903 } 903 }
904 } 904 }
905 905
906 906
907 if ( item->incidence()->type() == "Event" ) { 907 if ( item->incidence()->type() == "Event" ) {
908 item->incidence()->setDtStart(startDt); 908 item->incidence()->setDtStart(startDt);
909 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt); 909 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt);
910 } else if ( item->incidence()->type() == "Todo" ) { 910 } else if ( item->incidence()->type() == "Todo" ) {
911 (static_cast<Todo*>(item->incidence()))->setDtDue(endDt); 911 (static_cast<Todo*>(item->incidence()))->setDtDue(endDt);
912 } 912 }
913 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() ); 913 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() );
914 item->incidence()->setRevision(item->incidence()->revision()+1); 914 item->incidence()->setRevision(item->incidence()->revision()+1);
915 item->setItemDate(startDt.date()); 915 item->setItemDate(startDt.date());
916 //item->updateItem(); 916 //item->updateItem();
917 if ( item->incidence()->type() == "Todo" ) { 917 if ( item->incidence()->type() == "Todo" ) {
918 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED ); 918 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED );
919 919
920 } 920 }
921 else 921 else
922 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED); 922 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED);
923 item->updateItem(); 923 item->updateItem();
924} 924}
925 925
926void KOAgendaView::showDates( const QDate &start, const QDate &end ) 926void KOAgendaView::showDates( const QDate &start, const QDate &end )
927{ 927{
928 // kdDebug() << "KOAgendaView::selectDates" << endl; 928 // kdDebug() << "KOAgendaView::selectDates" << endl;
929 929
930 mSelectedDates.clear(); 930 mSelectedDates.clear();
931 // qDebug("KOAgendaView::showDates "); 931 // qDebug("KOAgendaView::showDates ");
932 QDate d = start; 932 QDate d = start;
933 while (d <= end) { 933 while (d <= end) {
934 mSelectedDates.append(d); 934 mSelectedDates.append(d);
935 d = d.addDays( 1 ); 935 d = d.addDays( 1 );
936 } 936 }
937 937
938 // and update the view 938 // and update the view
939 fillAgenda(); 939 fillAgenda();
940} 940}
941 941
942 942
943void KOAgendaView::showEvents(QPtrList<Event>) 943void KOAgendaView::showEvents(QPtrList<Event>)
944{ 944{
945 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl; 945 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl;
946} 946}
947 947
948void KOAgendaView::changeEventDisplay(Event *, int) 948void KOAgendaView::changeEventDisplay(Event *, int)
949{ 949{
950 // qDebug("KOAgendaView::changeEventDisplay "); 950 // qDebug("KOAgendaView::changeEventDisplay ");
951 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl; 951 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl;
952 // this should be re-written to be MUCH smarter. Right now we 952 // this should be re-written to be MUCH smarter. Right now we
953 // are just playing dumb. 953 // are just playing dumb.
954 fillAgenda(); 954 fillAgenda();
955} 955}
956 956
957void KOAgendaView::fillAgenda(const QDate &) 957void KOAgendaView::fillAgenda(const QDate &)
958{ 958{
959 // qDebug("KOAgendaView::fillAgenda "); 959 // qDebug("KOAgendaView::fillAgenda ");
960 fillAgenda(); 960 fillAgenda();
961} 961}
962 962
963void KOAgendaView::fillAgenda() 963void KOAgendaView::fillAgenda()
964{ 964{
965 if ( globalFlagBlockStartup ) 965 if ( globalFlagBlockStartup )
966 return; 966 return;
967 if ( globalFlagBlockAgenda == 1 ) 967 if ( globalFlagBlockAgenda == 1 )
968 return; 968 return;
969 //if ( globalFlagBlockAgenda == 2 ) 969 //if ( globalFlagBlockAgenda == 2 )
970 //globalFlagBlockAgenda = 0; 970 //globalFlagBlockAgenda = 0;
971 // globalFlagBlockPainting = false; 971 // globalFlagBlockPainting = false;
972 if ( globalFlagBlockAgenda == 0 ) 972 if ( globalFlagBlockAgenda == 0 )
973 globalFlagBlockAgenda = 1; 973 globalFlagBlockAgenda = 1;
974 // clearView(); 974 // clearView();
975 //qDebug("fillAgenda()++++ "); 975 //qDebug("fillAgenda()++++ ");
976 globalFlagBlockAgendaItemPaint = 1; 976 globalFlagBlockAgendaItemPaint = 1;
977 mAllDayAgenda->changeColumns(mSelectedDates.count()); 977 mAllDayAgenda->changeColumns(mSelectedDates.count());
978 mAgenda->changeColumns(mSelectedDates.count()); 978 mAgenda->changeColumns(mSelectedDates.count());
979 qApp->processEvents(); 979 qApp->processEvents();
980 mEventIndicatorTop->changeColumns(mSelectedDates.count()); 980 mEventIndicatorTop->changeColumns(mSelectedDates.count());
981 mEventIndicatorBottom->changeColumns(mSelectedDates.count()); 981 mEventIndicatorBottom->changeColumns(mSelectedDates.count());
982 setHolidayMasks(); 982 setHolidayMasks();
983 983
984 //mAgenda->hideUnused(); 984 //mAgenda->hideUnused();
985 //mAllDayAgenda->hideUnused(); 985 //mAllDayAgenda->hideUnused();
986 986
987 // mAgenda->blockNextRepaint( false ); 987 // mAgenda->blockNextRepaint( false );
988 // mAgenda->viewport()->repaint(); 988 // mAgenda->viewport()->repaint();
989 // mAgenda->blockNextRepaint( true ); 989 // mAgenda->blockNextRepaint( true );
990 mMinY.resize(mSelectedDates.count()); 990 mMinY.resize(mSelectedDates.count());
991 mMaxY.resize(mSelectedDates.count()); 991 mMaxY.resize(mSelectedDates.count());
992 992
993 QPtrList<Event> dayEvents; 993 QPtrList<Event> dayEvents;
994 994
995 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 995 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
996 // Therefore, get all of them. 996 // Therefore, get all of them.
997 QPtrList<Todo> todos = calendar()->todos(); 997 QPtrList<Todo> todos = calendar()->todos();
998 998
999 mAgenda->setDateList(mSelectedDates); 999 mAgenda->setDateList(mSelectedDates);
1000 1000
1001 QDate today = QDate::currentDate(); 1001 QDate today = QDate::currentDate();
1002 1002
1003 DateList::ConstIterator dit; 1003 DateList::ConstIterator dit;
1004 int curCol = 0; 1004 int curCol = 0;
1005 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 1005 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
1006 QDate currentDate = *dit; 1006 QDate currentDate = *dit;
1007 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString() 1007 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString()
1008 // << endl; 1008 // << endl;
1009 1009
1010 dayEvents = calendar()->events(currentDate,true); 1010 dayEvents = calendar()->events(currentDate,true);
1011 1011
1012 // Default values, which can never be reached 1012 // Default values, which can never be reached
1013 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1; 1013 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1;
1014 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1; 1014 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1;
1015 1015
1016 unsigned int numEvent; 1016 unsigned int numEvent;
1017 for(numEvent=0;numEvent<dayEvents.count();++numEvent) { 1017 for(numEvent=0;numEvent<dayEvents.count();++numEvent) {
1018 Event *event = dayEvents.at(numEvent); 1018 Event *event = dayEvents.at(numEvent);
1019 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") ) 1019 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") )
1020 if ( event->uid().left(15) == QString("last-syncEvent-") ) 1020 if ( event->uid().left(15) == QString("last-syncEvent-") )
1021 continue; 1021 continue;
1022 // kdDebug() << " Event: " << event->summary() << endl; 1022 // kdDebug() << " Event: " << event->summary() << endl;
1023 1023
1024 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol; 1024 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol;
1025 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol; 1025 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol;
1026 1026
1027 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl; 1027 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl;
1028 1028
1029 if (event->doesFloat()) { 1029 if (event->doesFloat()) {
1030 if (event->recurrence()->doesRecur()) { 1030 if (event->recurrence()->doesRecur()) {
1031 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol); 1031 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol);
1032 } else { 1032 } else {
1033 if (beginX <= 0 && curCol == 0) { 1033 if (beginX <= 0 && curCol == 0) {
1034 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1034 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1035 } else if (beginX == curCol) { 1035 } else if (beginX == curCol) {
1036 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1036 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1037 } 1037 }
1038 } 1038 }
1039 } else if (event->isMultiDay()) { 1039 } else if (event->isMultiDay()) {
1040 if ( event->doesRecur () ) { 1040 if ( event->doesRecur () ) {
1041 QDate dateit = currentDate; 1041 QDate dateit = currentDate;
1042 int count = 0; 1042 int count = 0;
1043 int max = event->dtStart().daysTo( event->dtEnd() ) +2; 1043 int max = event->dtStart().daysTo( event->dtEnd() ) +2;
1044 while (! event->recursOn( dateit ) && count <= max ) { 1044 while (! event->recursOn( dateit ) && count <= max ) {
1045 ++count; 1045 ++count;
1046 dateit = dateit.addDays( -1 ); 1046 dateit = dateit.addDays( -1 );
1047 } 1047 }
1048 bool ok; 1048 bool ok;
1049 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok ); 1049 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok );
1050 if ( ok ) 1050 if ( ok )
1051 { 1051 {
1052 int secs = event->dtStart().secsTo( event->dtEnd() ); 1052 int secs = event->dtStart().secsTo( event->dtEnd() );
1053 QDateTime nextOcend =nextOcstart.addSecs( secs ); ; 1053 QDateTime nextOcend =nextOcstart.addSecs( secs ); ;
1054 beginX = currentDate.daysTo(nextOcstart.date()) + curCol; 1054 beginX = currentDate.daysTo(nextOcstart.date()) + curCol;
1055 endX = currentDate.daysTo(nextOcend.date()) + curCol; 1055 endX = currentDate.daysTo(nextOcend.date()) + curCol;
1056 1056
1057 } 1057 }
1058 } 1058 }
1059 int startY = mAgenda->timeToY(event->dtStart().time()); 1059 int startY = mAgenda->timeToY(event->dtStart().time());
1060 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1060 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1061 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol ); 1061 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol );
1062 if ((beginX <= 0 && curCol == 0) || beginX == curCol) { 1062 if ((beginX <= 0 && curCol == 0) || beginX == curCol) {
1063 //qDebug("insert!!! "); 1063 //qDebug("insert!!! ");
1064 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY); 1064 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY);
1065 } 1065 }
1066 if (beginX == curCol) { 1066 if (beginX == curCol) {
1067 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1067 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1068 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1068 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1069 } else if (endX == curCol) { 1069 } else if (endX == curCol) {
1070 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1070 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1071 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1071 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1072 } else { 1072 } else {
1073 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1073 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1074 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1074 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1075 } 1075 }
1076 } else { 1076 } else {
1077 int startY = mAgenda->timeToY(event->dtStart().time()); 1077 int startY = mAgenda->timeToY(event->dtStart().time());
1078 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1078 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1079 if (endY < startY) endY = startY; 1079 if (endY < startY) endY = startY;
1080 mAgenda->insertItem(event,currentDate,curCol,startY,endY); 1080 mAgenda->insertItem(event,currentDate,curCol,startY,endY);
1081 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1081 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1082 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1082 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1083 } 1083 }
1084 } 1084 }
1085 // ---------- [display Todos -------------- 1085 // ---------- [display Todos --------------
1086 unsigned int numTodo; 1086 unsigned int numTodo;
1087 for (numTodo = 0; numTodo < todos.count(); ++numTodo) { 1087 for (numTodo = 0; numTodo < todos.count(); ++numTodo) {
1088 Todo *todo = todos.at(numTodo); 1088 Todo *todo = todos.at(numTodo);
1089 1089
1090 if ( ! todo->hasDueDate() ) continue; // todo shall not be displayed if it has no date 1090 if ( ! todo->hasDueDate() ) continue; // todo shall not be displayed if it has no date
1091 1091
1092 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 1092 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
1093 // Already completed items can be displayed on their original due date 1093 // Already completed items can be displayed on their original due date
1094 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda 1094 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda
1095 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda; 1095 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda;
1096 1096
1097 if ( ((todo->dtDue().date() == currentDate) && !overdue) || 1097 if ( ((todo->dtDue().date() == currentDate) && !overdue) ||
1098 ((currentDate == today) && overdue) ) { 1098 ((currentDate == today) && overdue) ) {
1099 if ( todo->doesFloat() || overdue ) { // Todo has no due-time set or is already overdue 1099 if ( todo->doesFloat() || overdue ) { // Todo has no due-time set or is already overdue
1100 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1100 if ( KOPrefs::instance()->mShowTodoInAgenda )
1101 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol); 1101 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol);
1102 } 1102 }
1103 else { 1103 else {
1104 1104
1105 int endY = mAgenda->timeToY(todo->dtDue().time()) - 1; 1105 int endY = mAgenda->timeToY(todo->dtDue().time()) - 1;
1106 int hi = (18/KOPrefs::instance()->mHourSize); 1106 int hi = (18/KOPrefs::instance()->mHourSize);
1107 //qDebug("hei %d ",KOPrefs::instance()->mHourSize); 1107 //qDebug("hei %d ",KOPrefs::instance()->mHourSize);
1108 int startY = endY -hi; 1108 int startY = endY -hi;
1109 1109
1110 mAgenda->insertItem(todo,currentDate,curCol,startY,endY); 1110 mAgenda->insertItem(todo,currentDate,curCol,startY,endY);
1111 1111
1112 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1112 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1113 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1113 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1114 } 1114 }
1115 } 1115 }
1116 } 1116 }
1117 // ---------- display Todos] -------------- 1117 // ---------- display Todos] --------------
1118 1118
1119 ++curCol; 1119 ++curCol;
1120 } 1120 }
1121 mAgenda->hideUnused(); 1121 mAgenda->hideUnused();
1122 mAllDayAgenda->hideUnused(); 1122 mAllDayAgenda->hideUnused();
1123 mAgenda->checkScrollBoundaries(); 1123 mAgenda->checkScrollBoundaries();
1124 1124
1125 deleteSelectedDateTime(); 1125 deleteSelectedDateTime();
1126 1126
1127 createDayLabels(); 1127 createDayLabels();
1128 emit incidenceSelected( 0 ); 1128 emit incidenceSelected( 0 );
1129 1129
1130 if ( globalFlagBlockAgenda == 2 ) { 1130 if ( globalFlagBlockAgenda == 2 ) {
1131 if ( KOPrefs::instance()->mSetTimeToDayStartAt ) 1131 if ( KOPrefs::instance()->mSetTimeToDayStartAt )
1132 setStartHour( KOPrefs::instance()->mDayBegins ); 1132 setStartHour( KOPrefs::instance()->mDayBegins );
1133 else if ( KOPrefs::instance()->mCenterOnCurrentTime ) 1133 else if ( KOPrefs::instance()->mCenterOnCurrentTime )
1134 setStartHour( QTime::currentTime ().hour() ); 1134 setStartHour( QTime::currentTime ().hour() );
1135 // qApp->processEvents(); 1135 // qApp->processEvents();
1136 } 1136 }
1137 qApp->processEvents(); 1137 qApp->processEvents();
1138 //qDebug("qApp->processEvents(); END "); 1138 //qDebug("qApp->processEvents(); END ");
1139 globalFlagBlockAgenda = 0; 1139 globalFlagBlockAgenda = 0;
1140 1140
1141 // mAgenda->hideUnused(); 1141 // mAgenda->hideUnused();
1142 //mAllDayAgenda->hideUnused(); 1142 //mAllDayAgenda->hideUnused();
1143 mAllDayAgenda->drawContentsToPainter(); 1143 mAllDayAgenda->drawContentsToPainter();
1144 mAgenda->drawContentsToPainter(); 1144 mAgenda->drawContentsToPainter();
1145 repaintAgenda(); 1145 repaintAgenda();
1146 // mAgenda->finishUpdate(); 1146 // mAgenda->finishUpdate();
1147 //mAllDayAgenda->finishUpdate(); 1147 //mAllDayAgenda->finishUpdate();
1148 1148
1149 // repaintAgenda(); 1149 // repaintAgenda();
1150 //qApp->processEvents(); 1150 //qApp->processEvents();
1151 // globalFlagBlockAgenda = 0; 1151 // globalFlagBlockAgenda = 0;
1152} 1152}
1153void KOAgendaView::repaintAgenda() 1153void KOAgendaView::repaintAgenda()
1154{ 1154{
1155 // mAllDayAgenda->drawContentsToPainter(); 1155 // mAllDayAgenda->drawContentsToPainter();
1156// mAllDayAgenda->viewport()->repaint( false ); 1156// mAllDayAgenda->viewport()->repaint( false );
1157// mAgenda->drawContentsToPainter(); 1157// mAgenda->drawContentsToPainter();
1158// mAgenda->viewport()->repaint( false ); 1158// mAgenda->viewport()->repaint( false );
1159// qApp->processEvents(); 1159// qApp->processEvents();
1160 1160
1161 //qDebug("KOAgendaView::repaintAgenda() "); 1161 //qDebug("KOAgendaView::repaintAgenda() ");
1162 //qApp->processEvents(); 1162 //qApp->processEvents();
1163 mAgenda->viewport()->repaint( false ); 1163 mAgenda->viewport()->repaint( false );
1164 mAllDayAgenda->viewport()->repaint( false ); 1164 mAllDayAgenda->viewport()->repaint( false );
1165 mAgenda->finishUpdate(); 1165 mAgenda->finishUpdate();
1166 mAllDayAgenda->finishUpdate(); 1166 mAllDayAgenda->finishUpdate();
1167} 1167}
1168 1168
1169 1169
1170void KOAgendaView::clearView() 1170void KOAgendaView::clearView()
1171{ 1171{
1172 // kdDebug() << "ClearView" << endl; 1172 // kdDebug() << "ClearView" << endl;
1173 mAllDayAgenda->clear(); 1173 mAllDayAgenda->clear();
1174 mAgenda->clear(); 1174 mAgenda->clear();
1175} 1175}
1176 1176
1177void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1177void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1178 const QDate &td) 1178 const QDate &td)
1179{ 1179{
1180#ifndef KORG_NOPRINTER 1180#ifndef KORG_NOPRINTER
1181 if (fd == td) 1181 if (fd == td)
1182 calPrinter->preview(CalPrinter::Day, fd, td); 1182 calPrinter->preview(CalPrinter::Day, fd, td);
1183 else 1183 else
1184 calPrinter->preview(CalPrinter::Week, fd, td); 1184 calPrinter->preview(CalPrinter::Week, fd, td);
1185#endif 1185#endif
1186} 1186}
1187 1187
1188// void KOAgendaView::updateMovedTodo() 1188// void KOAgendaView::updateMovedTodo()
1189// { 1189// {
1190// // updateConfig(); 1190// // updateConfig();
1191// // emit updateTodoViews(); 1191// // emit updateTodoViews();
1192// } 1192// }
1193 1193
1194void KOAgendaView::newEvent(int gx, int gy) 1194void KOAgendaView::newEvent(int gx, int gy)
1195{ 1195{
1196 if (!mSelectedDates.count()) return; 1196 if (!mSelectedDates.count()) return;
1197 1197
1198 QDate day = mSelectedDates[gx]; 1198 QDate day = mSelectedDates[gx];
1199 1199
1200 QTime time = mAgenda->gyToTime(gy); 1200 QTime time = mAgenda->gyToTime(gy);
1201 QDateTime dt(day,time); 1201 QDateTime dt(day,time);
1202 // if ( dt < QDateTime::currentDateTime () ) 1202 // if ( dt < QDateTime::currentDateTime () )
1203 // dt = QDateTime::currentDateTime ().addSecs( 3600 ); 1203 // dt = QDateTime::currentDateTime ().addSecs( 3600 );
1204 emit newEventSignal(dt); 1204 emit newEventSignal(dt);
1205} 1205}
1206 1206
1207void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd) 1207void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd)
1208{ 1208{
1209 if (!mSelectedDates.count()) return; 1209 if (!mSelectedDates.count()) return;
1210 1210
1211 QDate dayStart = mSelectedDates[gxStart]; 1211 QDate dayStart = mSelectedDates[gxStart];
1212 QDate dayEnd = mSelectedDates[gxEnd]; 1212 QDate dayEnd = mSelectedDates[gxEnd];
1213 1213
1214 QTime timeStart = mAgenda->gyToTime(gyStart); 1214 QTime timeStart = mAgenda->gyToTime(gyStart);
1215 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1215 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1216 1216
1217 QDateTime dtStart(dayStart,timeStart); 1217 QDateTime dtStart(dayStart,timeStart);
1218 QDateTime dtEnd(dayEnd,timeEnd); 1218 QDateTime dtEnd(dayEnd,timeEnd);
1219 1219
1220 emit newEventSignal(dtStart,dtEnd); 1220 emit newEventSignal(dtStart,dtEnd);
1221} 1221}
1222 1222
1223void KOAgendaView::newEventAllDay(int gx, int ) 1223void KOAgendaView::newEventAllDay(int gx, int )
1224{ 1224{
1225 if (!mSelectedDates.count()) return; 1225 if (!mSelectedDates.count()) return;
1226 1226
1227 QDate day = mSelectedDates[gx]; 1227 QDate day = mSelectedDates[gx];
1228 1228
1229 emit newEventSignal(day); 1229 emit newEventSignal(day);
1230} 1230}
1231 1231
1232void KOAgendaView::updateEventIndicatorTop(int newY) 1232void KOAgendaView::updateEventIndicatorTop(int newY)
1233{ 1233{
1234 uint i; 1234 uint i;
1235 for(i=0;i<mMinY.size();++i) { 1235 for(i=0;i<mMinY.size();++i) {
1236 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true); 1236 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true);
1237 else mEventIndicatorTop->enableColumn(i,false); 1237 else mEventIndicatorTop->enableColumn(i,false);
1238 } 1238 }
1239 1239
1240 mEventIndicatorTop->update(); 1240 mEventIndicatorTop->update();
1241} 1241}
1242 1242
1243void KOAgendaView::updateEventIndicatorBottom(int newY) 1243void KOAgendaView::updateEventIndicatorBottom(int newY)
1244{ 1244{
1245 uint i; 1245 uint i;
1246 for(i=0;i<mMaxY.size();++i) { 1246 for(i=0;i<mMaxY.size();++i) {
1247 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true); 1247 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true);
1248 else mEventIndicatorBottom->enableColumn(i,false); 1248 else mEventIndicatorBottom->enableColumn(i,false);
1249 } 1249 }
1250 1250
1251 mEventIndicatorBottom->update(); 1251 mEventIndicatorBottom->update();
1252} 1252}
1253 1253
1254void KOAgendaView::startDrag(Event *event) 1254void KOAgendaView::startDrag(Event *event)
1255{ 1255{
1256#ifndef KORG_NODND 1256#ifndef KORG_NODND
1257 DndFactory factory( calendar() ); 1257 DndFactory factory( calendar() );
1258 ICalDrag *vd = factory.createDrag(event,this); 1258 ICalDrag *vd = factory.createDrag(event,this);
1259 if (vd->drag()) { 1259 if (vd->drag()) {
1260 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl; 1260 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl;
1261 } 1261 }
1262#endif 1262#endif
1263} 1263}
1264 1264
1265void KOAgendaView::readSettings() 1265void KOAgendaView::readSettings()
1266{ 1266{
1267 readSettings(KOGlobals::config()); 1267 readSettings(KOGlobals::config());
1268} 1268}
1269 1269
1270void KOAgendaView::readSettings(KConfig *config) 1270void KOAgendaView::readSettings(KConfig *config)
1271{ 1271{
1272 // kdDebug() << "KOAgendaView::readSettings()" << endl; 1272 // kdDebug() << "KOAgendaView::readSettings()" << endl;
1273 1273
1274 config->setGroup("Views"); 1274 config->setGroup("Views");
1275 1275
1276 //#ifndef KORG_NOSPLITTER 1276 //#ifndef KORG_NOSPLITTER
1277 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView"); 1277 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView");
1278 if (sizes.count() == 2) { 1278 if (sizes.count() == 2) {
1279 if ( sizes[0] < 20 ) { 1279 if ( sizes[0] < 20 ) {
1280 sizes[1] = sizes[1] +20 - sizes[0]; 1280 sizes[1] = sizes[1] +20 - sizes[0];
1281 sizes[0] = 20; 1281 sizes[0] = 20;
1282 } 1282 }
1283 mSplitterAgenda->setSizes(sizes); 1283 mSplitterAgenda->setSizes(sizes);
1284 // qDebug("read %d %d ",sizes[0],sizes[1] ); 1284 // qDebug("read %d %d ",sizes[0],sizes[1] );
1285 } 1285 }
1286 //#endif 1286 //#endif
1287 1287
1288 // updateConfig(); 1288 // updateConfig();
1289} 1289}
1290 1290
1291void KOAgendaView::writeSettings(KConfig *config) 1291void KOAgendaView::writeSettings(KConfig *config)
1292{ 1292{
1293 // kdDebug() << "KOAgendaView::writeSettings()" << endl; 1293 // kdDebug() << "KOAgendaView::writeSettings()" << endl;
1294 1294
1295 config->setGroup("Views"); 1295 config->setGroup("Views");
1296 1296
1297 //#ifndef KORG_NOSPLITTER 1297 //#ifndef KORG_NOSPLITTER
1298 QValueList<int> list = mSplitterAgenda->sizes(); 1298 QValueList<int> list = mSplitterAgenda->sizes();
1299 config->writeEntry("Separator AgendaView",list); 1299 config->writeEntry("Separator AgendaView",list);
1300 //qDebug("write %d %d ", list[0],list[1] ); 1300 //qDebug("write %d %d ", list[0],list[1] );
1301 //#endif 1301 //#endif
1302} 1302}
1303 1303
1304void KOAgendaView::setHolidayMasks() 1304void KOAgendaView::setHolidayMasks()
1305{ 1305{
1306 mHolidayMask.resize(mSelectedDates.count()); 1306 mHolidayMask.resize(mSelectedDates.count());
1307 1307
1308 uint i; 1308 uint i;
1309 for(i=0;i<mSelectedDates.count();++i) { 1309 for(i=0;i<mSelectedDates.count();++i) {
1310 QDate date = mSelectedDates[i]; 1310 QDate date = mSelectedDates[i];
1311 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6); 1311 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6);
1312 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7); 1312 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7);
1313 bool showHoliday = false;
1314 if ( KOPrefs::instance()->mExcludeHolidays ) {
1315 QPtrList<Event> events = calendar()->events( date, true );
1316 Event *event;
1317 for( event = events.first(); event; event = events.next() ) {
1318 if ( event->categories().contains("Holiday") ||
1319 event->categories().contains(i18n("Holiday"))) {
1320 showHoliday = true;
1321 break;
1322 }
1323 }
1324
1325 }
1326
1313#ifndef KORG_NOPLUGINS 1327#ifndef KORG_NOPLUGINS
1314 bool showHoliday = KOPrefs::instance()->mExcludeHolidays && 1328 bool showHoliday = KOPrefs::instance()->mExcludeHolidays &&
1315 !KOCore::self()->holiday(date).isEmpty(); 1329 !KOCore::self()->holiday(date).isEmpty();
1316 bool showDay = showSaturday || showSunday || showHoliday;
1317#else
1318 bool showDay = showSaturday || showSunday;
1319#endif 1330#endif
1331 bool showDay = showSaturday || showSunday || showHoliday;
1332
1320 if (showDay) { 1333 if (showDay) {
1321 mHolidayMask.at(i) = true; 1334 mHolidayMask.at(i) = true;
1322 } else { 1335 } else {
1323 mHolidayMask.at(i) = false; 1336 mHolidayMask.at(i) = false;
1324 } 1337 }
1325 } 1338 }
1326 1339
1327 mAgenda->setHolidayMask(&mHolidayMask); 1340 mAgenda->setHolidayMask(&mHolidayMask);
1328 mAllDayAgenda->setHolidayMask(&mHolidayMask); 1341 mAllDayAgenda->setHolidayMask(&mHolidayMask);
1329} 1342}
1330 1343
1331void KOAgendaView::setContentsPos(int y) 1344void KOAgendaView::setContentsPos(int y)
1332{ 1345{
1333 mAgenda->setContentsPos(0,y); 1346 mAgenda->setContentsPos(0,y);
1334} 1347}
1335 1348
1336void KOAgendaView::setExpandedButton( bool expanded ) 1349void KOAgendaView::setExpandedButton( bool expanded )
1337{ 1350{
1338 if ( expanded ) { 1351 if ( expanded ) {
1339 mExpandButton->setPixmap( mExpandedPixmap ); 1352 mExpandButton->setPixmap( mExpandedPixmap );
1340 } else { 1353 } else {
1341 mExpandButton->setPixmap( mNotExpandedPixmap ); 1354 mExpandButton->setPixmap( mNotExpandedPixmap );
1342 } 1355 }
1343} 1356}
1344 1357
1345void KOAgendaView::clearSelection() 1358void KOAgendaView::clearSelection()
1346{ 1359{
1347 mAgenda->deselectItem(); 1360 mAgenda->deselectItem();
1348 mAllDayAgenda->deselectItem(); 1361 mAllDayAgenda->deselectItem();
1349} 1362}
1350 1363
1351void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart, 1364void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart,
1352 int gxEnd, int gyEnd) 1365 int gxEnd, int gyEnd)
1353{ 1366{
1354 mTimeSpanInAllDay = true; 1367 mTimeSpanInAllDay = true;
1355 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd); 1368 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd);
1356} 1369}
1357 1370
1358 1371
1359 1372
1360 1373
1361void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart, 1374void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart,
1362 int gxEnd, int gyEnd) 1375 int gxEnd, int gyEnd)
1363{ 1376{
1364 if (!mSelectedDates.count()) return; 1377 if (!mSelectedDates.count()) return;
1365 1378
1366 QDate dayStart = mSelectedDates[gxStart]; 1379 QDate dayStart = mSelectedDates[gxStart];
1367 QDate dayEnd = mSelectedDates[gxEnd]; 1380 QDate dayEnd = mSelectedDates[gxEnd];
1368 1381
1369 QTime timeStart = mAgenda->gyToTime(gyStart); 1382 QTime timeStart = mAgenda->gyToTime(gyStart);
1370 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1383 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1371 1384
1372 QDateTime dtStart(dayStart,timeStart); 1385 QDateTime dtStart(dayStart,timeStart);
1373 QDateTime dtEnd(dayEnd,timeEnd); 1386 QDateTime dtEnd(dayEnd,timeEnd);
1374 1387
1375 mTimeSpanBegin = dtStart; 1388 mTimeSpanBegin = dtStart;
1376 mTimeSpanEnd = dtEnd; 1389 mTimeSpanEnd = dtEnd;
1377 1390
1378} 1391}
1379 1392
1380void KOAgendaView::deleteSelectedDateTime() 1393void KOAgendaView::deleteSelectedDateTime()
1381{ 1394{
1382 mTimeSpanBegin.setDate(QDate()); 1395 mTimeSpanBegin.setDate(QDate());
1383 mTimeSpanEnd.setDate(QDate()); 1396 mTimeSpanEnd.setDate(QDate());
1384 mTimeSpanInAllDay = false; 1397 mTimeSpanInAllDay = false;
1385} 1398}
1386 1399
1387void KOAgendaView::keyPressEvent ( QKeyEvent * e ) 1400void KOAgendaView::keyPressEvent ( QKeyEvent * e )
1388{ 1401{
1389 e->ignore(); 1402 e->ignore();
1390} 1403}
1391 1404
1392void KOAgendaView::scrollOneHourUp() 1405void KOAgendaView::scrollOneHourUp()
1393{ 1406{
1394 1407
1395 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 ); 1408 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 );
1396} 1409}
1397void KOAgendaView::scrollOneHourDown() 1410void KOAgendaView::scrollOneHourDown()
1398{ 1411{
1399 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 ); 1412 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 );
1400} 1413}
1401 1414
1402void KOAgendaView::setStartHour( int h ) 1415void KOAgendaView::setStartHour( int h )
1403{ 1416{
1404 mAgenda->setStartHour( h ); 1417 mAgenda->setStartHour( h );
1405 1418
1406} 1419}
1407 1420
1408void KOAgendaView::updateTodo( Todo * t, int ) 1421void KOAgendaView::updateTodo( Todo * t, int )
1409{ 1422{
1410 1423
1411 bool remove = false; 1424 bool remove = false;
1412 bool removeAD = false; 1425 bool removeAD = false;
1413 if ( ! t->hasDueDate() ) { 1426 if ( ! t->hasDueDate() ) {
1414 remove = true; 1427 remove = true;
1415 removeAD = true; 1428 removeAD = true;
1416 } 1429 }
1417 else { 1430 else {
1418 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ; 1431 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ;
1419 if ( overdue && 1432 if ( overdue &&
1420 QDate::currentDate() >= mSelectedDates.first() && 1433 QDate::currentDate() >= mSelectedDates.first() &&
1421 QDate::currentDate() <= mSelectedDates.last()) { 1434 QDate::currentDate() <= mSelectedDates.last()) {
1422 removeAD = false; 1435 removeAD = false;
1423 remove = true; 1436 remove = true;
1424 } 1437 }
1425 else { 1438 else {
1426 if ( t->dtDue().date() < mSelectedDates.first() || 1439 if ( t->dtDue().date() < mSelectedDates.first() ||
1427 t->dtDue().date() > mSelectedDates.last() ) { 1440 t->dtDue().date() > mSelectedDates.last() ) {
1428 remove = true; 1441 remove = true;
1429 removeAD = true; 1442 removeAD = true;
1430 } else { 1443 } else {
1431 remove = t->doesFloat(); 1444 remove = t->doesFloat();
1432 removeAD = !remove; 1445 removeAD = !remove;
1433 } 1446 }
1434 } 1447 }
1435 } 1448 }
1436 int days = mSelectedDates.first().daysTo( t->dtDue().date() ); 1449 int days = mSelectedDates.first().daysTo( t->dtDue().date() );
1437 // qDebug("daysto %d ", days ); 1450 // qDebug("daysto %d ", days );
1438 mAgenda->updateTodo( t , days, remove); 1451 mAgenda->updateTodo( t , days, remove);
1439 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1452 if ( KOPrefs::instance()->mShowTodoInAgenda )
1440 mAllDayAgenda->updateTodo( t , days, removeAD); 1453 mAllDayAgenda->updateTodo( t , days, removeAD);
1441 //qDebug("KOAgendaView::updateTodo( Todo *, int ) "); 1454 //qDebug("KOAgendaView::updateTodo( Todo *, int ) ");
1442 1455
1443} 1456}
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp
index 688d9e1..7d1e82f 100644
--- a/korganizer/komonthview.cpp
+++ b/korganizer/komonthview.cpp
@@ -1,1056 +1,1056 @@
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 <qpushbutton.h> 26#include <qpushbutton.h>
27#include <qtooltip.h> 27#include <qtooltip.h>
28#include <qpainter.h> 28#include <qpainter.h>
29#include <qwhatsthis.h> 29#include <qwhatsthis.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 35
36#include <kdebug.h> 36#include <kdebug.h>
37#include <klocale.h> 37#include <klocale.h>
38#include <kglobal.h> 38#include <kglobal.h>
39#include <kconfig.h> 39#include <kconfig.h>
40#include <kiconloader.h> 40#include <kiconloader.h>
41 41
42#include <kcalendarsystem.h> 42#include <kcalendarsystem.h>
43 43
44#ifndef KORG_NOPRINTER 44#ifndef KORG_NOPRINTER
45#include "calprinter.h" 45#include "calprinter.h"
46#endif 46#endif
47#include "koprefs.h" 47#include "koprefs.h"
48#ifndef KORG_NOPLUGINS 48#ifndef KORG_NOPLUGINS
49#include "kocore.h" 49#include "kocore.h"
50#endif 50#endif
51#include "koglobals.h" 51#include "koglobals.h"
52#include <libkcal/kincidenceformatter.h> 52#include <libkcal/kincidenceformatter.h>
53 53
54#include "komonthview.h" 54#include "komonthview.h"
55 55
56#define PIXMAP_SIZE 5 56#define PIXMAP_SIZE 5
57 57
58class KNOWhatsThis :public QWhatsThis 58class KNOWhatsThis :public QWhatsThis
59{ 59{
60public: 60public:
61 KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { }; 61 KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { };
62 62
63protected: 63protected:
64 virtual QString text( const QPoint& p) 64 virtual QString text( const QPoint& p)
65 { 65 {
66 return _wid->getWhatsThisText(p) ; 66 return _wid->getWhatsThisText(p) ;
67 }; 67 };
68private: 68private:
69 KNoScrollListBox* _wid; 69 KNoScrollListBox* _wid;
70 70
71}; 71};
72 72
73 73
74KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) 74KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name)
75 : QListBox(parent, name) 75 : QListBox(parent, name)
76{ 76{
77#ifndef DESKTOP_VERSION 77#ifndef DESKTOP_VERSION
78 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 78 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
79#endif 79#endif
80 new KNOWhatsThis(this); 80 new KNOWhatsThis(this);
81} 81}
82 82
83QString KNoScrollListBox::getWhatsThisText(QPoint p) 83QString KNoScrollListBox::getWhatsThisText(QPoint p)
84{ 84{
85 QListBoxItem* item = itemAt ( p ); 85 QListBoxItem* item = itemAt ( p );
86 if ( ! item ) { 86 if ( ! item ) {
87 return i18n("Click in the cell or\non the date label\nto add an event!"); 87 return i18n("Click in the cell or\non the date label\nto add an event!");
88 } 88 }
89 return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence()); 89 return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence());
90} 90}
91void KNoScrollListBox::keyPressEvent(QKeyEvent *e) 91void KNoScrollListBox::keyPressEvent(QKeyEvent *e)
92{ 92{
93 93
94 switch(e->key()) { 94 switch(e->key()) {
95 case Key_Right: 95 case Key_Right:
96 // if ( e->state() == Qt::ControlButton ) 96 // if ( e->state() == Qt::ControlButton )
97 { 97 {
98 e->ignore(); 98 e->ignore();
99 return; 99 return;
100 } 100 }
101 scrollBy(4,0); 101 scrollBy(4,0);
102 break; 102 break;
103 case Key_Left: 103 case Key_Left:
104 // if ( e->state() == Qt::ControlButton ) 104 // if ( e->state() == Qt::ControlButton )
105 { 105 {
106 e->ignore(); 106 e->ignore();
107 return; 107 return;
108 } 108 }
109 scrollBy(-4,0); 109 scrollBy(-4,0);
110 break; 110 break;
111 case Key_Up: 111 case Key_Up:
112 if(!count()) break; 112 if(!count()) break;
113 setCurrentItem((currentItem()+count()-1)%count()); 113 setCurrentItem((currentItem()+count()-1)%count());
114 if(!itemVisible(currentItem())) { 114 if(!itemVisible(currentItem())) {
115 if((unsigned int) currentItem() == (count()-1)) { 115 if((unsigned int) currentItem() == (count()-1)) {
116 setTopItem(currentItem()-numItemsVisible()+1); 116 setTopItem(currentItem()-numItemsVisible()+1);
117 } else { 117 } else {
118 setTopItem(topItem()-1); 118 setTopItem(topItem()-1);
119 } 119 }
120 } 120 }
121 break; 121 break;
122 case Key_Down: 122 case Key_Down:
123 if(!count()) break; 123 if(!count()) break;
124 setCurrentItem((currentItem()+1)%count()); 124 setCurrentItem((currentItem()+1)%count());
125 if(!itemVisible(currentItem())) { 125 if(!itemVisible(currentItem())) {
126 if(currentItem() == 0) { 126 if(currentItem() == 0) {
127 setTopItem(0); 127 setTopItem(0);
128 } else { 128 } else {
129 setTopItem(topItem()+1); 129 setTopItem(topItem()+1);
130 } 130 }
131 } 131 }
132 break; 132 break;
133 case Key_Shift: 133 case Key_Shift:
134 emit shiftDown(); 134 emit shiftDown();
135 break; 135 break;
136 default: 136 default:
137 e->ignore(); 137 e->ignore();
138 break; 138 break;
139 } 139 }
140} 140}
141 141
142void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) 142void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e)
143{ 143{
144 switch(e->key()) { 144 switch(e->key()) {
145 case Key_Shift: 145 case Key_Shift:
146 emit shiftUp(); 146 emit shiftUp();
147 break; 147 break;
148 default: 148 default:
149 break; 149 break;
150 } 150 }
151} 151}
152 152
153void KNoScrollListBox::mousePressEvent(QMouseEvent *e) 153void KNoScrollListBox::mousePressEvent(QMouseEvent *e)
154{ 154{
155 QListBox::mousePressEvent(e); 155 QListBox::mousePressEvent(e);
156 156
157 if(e->button() == RightButton) { 157 if(e->button() == RightButton) {
158 emit rightClick(); 158 emit rightClick();
159 } 159 }
160} 160}
161 161
162MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) 162MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s)
163 : QListBoxItem() 163 : QListBoxItem()
164{ 164{
165 setText( s ); 165 setText( s );
166 166
167 mIncidence = incidence; 167 mIncidence = incidence;
168 mDate = qd; 168 mDate = qd;
169 // QWhatsThis::add(this,KIncidenceFormatter::instance()->getFormattedText( mIncidence )); 169 // QWhatsThis::add(this,KIncidenceFormatter::instance()->getFormattedText( mIncidence ));
170 mRecur = false; 170 mRecur = false;
171 mAlarm = false; 171 mAlarm = false;
172 mReply = false; 172 mReply = false;
173 mInfo = false; 173 mInfo = false;
174} 174}
175 175
176void MonthViewItem::paint(QPainter *p) 176void MonthViewItem::paint(QPainter *p)
177{ 177{
178#if QT_VERSION >= 0x030000 178#if QT_VERSION >= 0x030000
179 bool sel = isSelected(); 179 bool sel = isSelected();
180#else 180#else
181 bool sel = selected(); 181 bool sel = selected();
182#endif 182#endif
183 183
184 184
185 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) 185 if (KOPrefs::instance()->mMonthViewUsesCategoryColor)
186 { 186 {
187 p->setBackgroundColor( palette().color( QPalette::Normal, \ 187 p->setBackgroundColor( palette().color( QPalette::Normal, \
188 sel ? QColorGroup::Highlight : QColorGroup::Background ) ); 188 sel ? QColorGroup::Highlight : QColorGroup::Background ) );
189 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); 189 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) );
190 } 190 }
191 int x = 1; 191 int x = 1;
192 int y = 3;//(height() - mRecurPixmap.height()) /2; 192 int y = 3;//(height() - mRecurPixmap.height()) /2;
193 int size = PIXMAP_SIZE; 193 int size = PIXMAP_SIZE;
194 if ( QApplication::desktop()->width() < 300 ) 194 if ( QApplication::desktop()->width() < 300 )
195 size = 3; 195 size = 3;
196 if ( KOPrefs::instance()->mMonthShowIcons ) { 196 if ( KOPrefs::instance()->mMonthShowIcons ) {
197 if ( mInfo ) { 197 if ( mInfo ) {
198 p->fillRect ( x, y,size,size, Qt::darkGreen ); 198 p->fillRect ( x, y,size,size, Qt::darkGreen );
199 x += size + 1; 199 x += size + 1;
200 } 200 }
201 if ( mRecur ) { 201 if ( mRecur ) {
202 p->fillRect ( x, y,size,size, Qt::blue ); 202 p->fillRect ( x, y,size,size, Qt::blue );
203 x += size + 1; 203 x += size + 1;
204 } 204 }
205 if ( mAlarm ) { 205 if ( mAlarm ) {
206 p->fillRect ( x, y,size,size, Qt::red ); 206 p->fillRect ( x, y,size,size, Qt::red );
207 x += size + 1; 207 x += size + 1;
208 } 208 }
209 if ( mReply ) { 209 if ( mReply ) {
210 p->fillRect ( x, y,size,size, Qt::yellow ); 210 p->fillRect ( x, y,size,size, Qt::yellow );
211 x += size + 1; 211 x += size + 1;
212 } 212 }
213 } 213 }
214 QFontMetrics fm = p->fontMetrics(); 214 QFontMetrics fm = p->fontMetrics();
215 int yPos; 215 int yPos;
216 int pmheight = size; 216 int pmheight = size;
217 if( pmheight < fm.height() ) 217 if( pmheight < fm.height() )
218 yPos = fm.ascent() + fm.leading()/2; 218 yPos = fm.ascent() + fm.leading()/2;
219 else 219 else
220 yPos = pmheight/2 - fm.height()/2 + fm.ascent(); 220 yPos = pmheight/2 - fm.height()/2 + fm.ascent();
221 p->setPen( palette().color( QPalette::Normal, sel ? \ 221 p->setPen( palette().color( QPalette::Normal, sel ? \
222 QColorGroup::HighlightedText : QColorGroup::Foreground ) ); 222 QColorGroup::HighlightedText : QColorGroup::Foreground ) );
223 p->drawText( x, yPos, text() ); 223 p->drawText( x, yPos, text() );
224 if ( mIncidence->cancelled() ) { 224 if ( mIncidence->cancelled() ) {
225 int wid = fm.width( text() ); 225 int wid = fm.width( text() );
226 p->drawLine( x, yPos- fm.height()/2+2,x+wid, yPos- fm.height()/2 +2); 226 p->drawLine( x, yPos- fm.height()/2+2,x+wid, yPos- fm.height()/2 +2);
227 } 227 }
228 228
229} 229}
230 230
231int MonthViewItem::height(const QListBox *lb) const 231int MonthViewItem::height(const QListBox *lb) const
232{ 232{
233 return lb->fontMetrics().lineSpacing()+1; 233 return lb->fontMetrics().lineSpacing()+1;
234} 234}
235 235
236int MonthViewItem::width(const QListBox *lb) const 236int MonthViewItem::width(const QListBox *lb) const
237{ 237{
238 int size = PIXMAP_SIZE; 238 int size = PIXMAP_SIZE;
239 if ( QApplication::desktop()->width() < 300 ) 239 if ( QApplication::desktop()->width() < 300 )
240 size = 3; 240 size = 3;
241 int x = 1; 241 int x = 1;
242 if ( mInfo ) { 242 if ( mInfo ) {
243 x += size + 1; 243 x += size + 1;
244 } 244 }
245 if( mRecur ) { 245 if( mRecur ) {
246 x += size+1; 246 x += size+1;
247 } 247 }
248 if( mAlarm ) { 248 if( mAlarm ) {
249 x += size+1; 249 x += size+1;
250 } 250 }
251 if( mReply ) { 251 if( mReply ) {
252 x += size+1; 252 x += size+1;
253 } 253 }
254 254
255 return( x + lb->fontMetrics().width( text() ) + 1 ); 255 return( x + lb->fontMetrics().width( text() ) + 1 );
256} 256}
257 257
258 258
259MonthViewCell::MonthViewCell( KOMonthView *parent) 259MonthViewCell::MonthViewCell( KOMonthView *parent)
260 : QWidget( parent ), 260 : QWidget( parent ),
261 mMonthView( parent ) 261 mMonthView( parent )
262{ 262{
263 263
264 QVBoxLayout *topLayout = new QVBoxLayout( this ); 264 QVBoxLayout *topLayout = new QVBoxLayout( this );
265 265
266 // mLabel = new QLabel( this );QPushButton 266 // mLabel = new QLabel( this );QPushButton
267 mLabel = new QPushButton( this ); 267 mLabel = new QPushButton( this );
268 //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); 268 //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain );
269 //mLabel->setLineWidth( 1 ); 269 //mLabel->setLineWidth( 1 );
270 //mLabel->setAlignment( AlignCenter ); 270 //mLabel->setAlignment( AlignCenter );
271 mLabel->setFlat( true ); 271 mLabel->setFlat( true );
272 mItemList = new KNoScrollListBox( this ); 272 mItemList = new KNoScrollListBox( this );
273 mItemList->setMinimumSize( 10, 10 ); 273 mItemList->setMinimumSize( 10, 10 );
274 mItemList->setFrameStyle( QFrame::Panel | QFrame::Plain ); 274 mItemList->setFrameStyle( QFrame::Panel | QFrame::Plain );
275 mItemList->setLineWidth( 1 ); 275 mItemList->setLineWidth( 1 );
276 topLayout->addWidget( mItemList ); 276 topLayout->addWidget( mItemList );
277 mLabel->raise(); 277 mLabel->raise();
278 // QColor( 0,0,255 ) QColor( 160,1600,255 ) 278 // QColor( 0,0,255 ) QColor( 160,1600,255 )
279 mStandardPalette = palette(); 279 mStandardPalette = palette();
280 mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); 280 mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) );
281 281
282 enableScrollBars( false ); 282 enableScrollBars( false );
283 updateConfig(); 283 updateConfig();
284 connect( mLabel, SIGNAL( clicked( )), 284 connect( mLabel, SIGNAL( clicked( )),
285 SLOT( newEvent() )); 285 SLOT( newEvent() ));
286 connect( mItemList, SIGNAL( doubleClicked( QListBoxItem *) ), 286 connect( mItemList, SIGNAL( doubleClicked( QListBoxItem *) ),
287 SLOT( defaultAction( QListBoxItem * ) ) ); 287 SLOT( defaultAction( QListBoxItem * ) ) );
288 connect( mItemList, SIGNAL( rightButtonPressed( QListBoxItem *, 288 connect( mItemList, SIGNAL( rightButtonPressed( QListBoxItem *,
289 const QPoint &) ), 289 const QPoint &) ),
290 SLOT( contextMenu( QListBoxItem * ) ) ); 290 SLOT( contextMenu( QListBoxItem * ) ) );
291 connect( mItemList, SIGNAL( highlighted( QListBoxItem *) ), 291 connect( mItemList, SIGNAL( highlighted( QListBoxItem *) ),
292 SLOT( selection( QListBoxItem * ) ) ); 292 SLOT( selection( QListBoxItem * ) ) );
293 connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), 293 connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ),
294 SLOT( cellClicked( QListBoxItem * ) ) ); 294 SLOT( cellClicked( QListBoxItem * ) ) );
295 connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), 295 connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ),
296 SLOT( selection( QListBoxItem * ) ) ); 296 SLOT( selection( QListBoxItem * ) ) );
297} 297}
298 298
299void MonthViewCell::setDate( const QDate &date ) 299void MonthViewCell::setDate( const QDate &date )
300{ 300{
301// kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl; 301// kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl;
302 302
303 mDate = date; 303 mDate = date;
304 304
305 QString text; 305 QString text;
306 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; 306 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog;
307 if ( KOGlobals::self()->calendarSystem()->day( date ) == 1 || (date.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { 307 if ( KOGlobals::self()->calendarSystem()->day( date ) == 1 || (date.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) {
308 text = KOGlobals::self()->calendarSystem()->monthName( date, true ) + " "; 308 text = KOGlobals::self()->calendarSystem()->monthName( date, true ) + " ";
309 mLabel->resize( mLabelBigSize ); 309 mLabel->resize( mLabelBigSize );
310 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 310 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
311 } else { 311 } else {
312 mLabel->resize( mLabelSize ); 312 mLabel->resize( mLabelSize );
313 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 313 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
314 } 314 }
315 mLabel->setText( text ); 315 mLabel->setText( text );
316 316
317 //resizeEvent( 0 ); 317 //resizeEvent( 0 );
318} 318}
319 319
320QDate MonthViewCell::date() const 320QDate MonthViewCell::date() const
321{ 321{
322 return mDate; 322 return mDate;
323} 323}
324 324
325void MonthViewCell::setPrimary( bool primary ) 325void MonthViewCell::setPrimary( bool primary )
326{ 326{
327 mPrimary = primary; 327 mPrimary = primary;
328 //setMyPalette(); 328 //setMyPalette();
329} 329}
330void MonthViewCell::setMyPalette() 330void MonthViewCell::setMyPalette()
331{ 331{
332 332
333 if ( mHoliday) { 333 if ( mHoliday) {
334 setPalette( mHolidayPalette ); 334 setPalette( mHolidayPalette );
335 } else { 335 } else {
336 if ( mPrimary ) { 336 if ( mPrimary ) {
337 setPalette( mPrimaryPalette ); 337 setPalette( mPrimaryPalette );
338 } else { 338 } else {
339 setPalette( mNonPrimaryPalette ); 339 setPalette( mNonPrimaryPalette );
340 } 340 }
341 } 341 }
342 QPalette pal = palette(); 342 QPalette pal = palette();
343 343
344 mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) )); 344 mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) ));
345} 345}
346QPalette MonthViewCell::getPalette () 346QPalette MonthViewCell::getPalette ()
347{ 347{
348 if ( !KOPrefs::instance()->mMonthViewUsesDayColors ) 348 if ( !KOPrefs::instance()->mMonthViewUsesDayColors )
349 return mStandardPalette; 349 return mStandardPalette;
350 if ( mHoliday) { 350 if ( mHoliday) {
351 return mHolidayPalette ; 351 return mHolidayPalette ;
352 } else { 352 } else {
353 if ( mPrimary ) { 353 if ( mPrimary ) {
354 return mPrimaryPalette ; 354 return mPrimaryPalette ;
355 } 355 }
356 } 356 }
357 return mNonPrimaryPalette; 357 return mNonPrimaryPalette;
358} 358}
359bool MonthViewCell::isPrimary() const 359bool MonthViewCell::isPrimary() const
360{ 360{
361 return mPrimary; 361 return mPrimary;
362} 362}
363 363
364void MonthViewCell::setHoliday( bool holiday ) 364void MonthViewCell::setHoliday( bool holiday )
365{ 365{
366 mHoliday = holiday; 366 mHoliday = holiday;
367 //setMyPalette(); 367 //setMyPalette();
368} 368}
369 369
370void MonthViewCell::setHoliday( const QString &holiday ) 370void MonthViewCell::setHoliday( const QString &holiday )
371{ 371{
372 mHolidayString = holiday; 372 mHolidayString = holiday;
373 373
374 if ( !holiday.isEmpty() ) { 374 if ( !holiday.isEmpty() ) {
375 setHoliday( true ); 375 setHoliday( true );
376 } 376 }
377} 377}
378void MonthViewCell::keyPressEvent ( QKeyEvent * e ) 378void MonthViewCell::keyPressEvent ( QKeyEvent * e )
379{ 379{
380 380
381 e->ignore(); 381 e->ignore();
382 382
383} 383}
384void MonthViewCell::updateCell() 384void MonthViewCell::updateCell()
385{ 385{
386 386
387 setPrimary( mDate.month()%2 ); 387 setPrimary( mDate.month()%2 );
388 setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() ); 388 setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays);
389 if ( mDate == QDate::currentDate() ) { 389 if ( mDate == QDate::currentDate() ) {
390 mItemList->setLineWidth( 3 ); 390 mItemList->setLineWidth( 3 );
391 } else { 391 } else {
392 mItemList->setLineWidth( 1 ); 392 mItemList->setLineWidth( 1 );
393 } 393 }
394 mItemList->clear(); 394 mItemList->clear();
395 //qApp->processEvents(); 395 //qApp->processEvents();
396 if ( !mHolidayString.isEmpty() ) { 396 if ( !mHolidayString.isEmpty() ) {
397 MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); 397 MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString );
398 item->setPalette( mHolidayPalette ); 398 item->setPalette( mHolidayPalette );
399 mItemList->insertItem( item ); 399 mItemList->insertItem( item );
400 } 400 }
401 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 401 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
402 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); 402 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true );
403 Event *event; 403 Event *event;
404 for( event = events.first(); event; event = events.next() ) { 404 for( event = events.first(); event; event = events.next() ) {
405 if ( event->categories().contains("Holiday") || 405 if ( event->categories().contains("Holiday") ||
406 event->categories().contains(i18n("Holiday"))) { 406 event->categories().contains(i18n("Holiday"))) {
407 setHoliday( true ); 407 setHoliday( true );
408 if ( mDate.dayOfWeek() == 7 ) 408 if ( mDate.dayOfWeek() == 7 )
409 mItemList->setLineWidth( 3 ); 409 mItemList->setLineWidth( 3 );
410 } 410 }
411 QString text; 411 QString text;
412 if (event->isMultiDay()) { 412 if (event->isMultiDay()) {
413 QString prefix = "<->"; 413 QString prefix = "<->";
414 if ( event->doesRecur() ) { 414 if ( event->doesRecur() ) {
415 if ( event->recursOn( mDate) ) 415 if ( event->recursOn( mDate) )
416 prefix ="->" ; 416 prefix ="->" ;
417 else { 417 else {
418 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 418 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
419 if ( event->recursOn( mDate.addDays( -days)) ) 419 if ( event->recursOn( mDate.addDays( -days)) )
420 prefix ="<-" ; 420 prefix ="<-" ;
421 } 421 }
422 422
423 } else { 423 } else {
424 if (mDate == event->dtStart().date()) { 424 if (mDate == event->dtStart().date()) {
425 prefix ="->" ; 425 prefix ="->" ;
426 } else if (mDate == event->dtEnd().date()) { 426 } else if (mDate == event->dtEnd().date()) {
427 prefix ="<-" ; 427 prefix ="<-" ;
428 } 428 }
429 } 429 }
430 text = prefix + event->summary(); 430 text = prefix + event->summary();
431 } else { 431 } else {
432 if (event->doesFloat()) 432 if (event->doesFloat())
433 text = event->summary(); 433 text = event->summary();
434 else { 434 else {
435 text = KGlobal::locale()->formatTime(event->dtStart().time()); 435 text = KGlobal::locale()->formatTime(event->dtStart().time());
436 text += " " + event->summary(); 436 text += " " + event->summary();
437 } 437 }
438 } 438 }
439 439
440 MonthViewItem *item = new MonthViewItem( event, mDate, text ); 440 MonthViewItem *item = new MonthViewItem( event, mDate, text );
441 QPalette pal; 441 QPalette pal;
442 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { 442 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
443 QStringList categories = event->categories(); 443 QStringList categories = event->categories();
444 QString cat = categories.first(); 444 QString cat = categories.first();
445 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { 445 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
446 pal = getPalette(); 446 pal = getPalette();
447 if (cat.isEmpty()) { 447 if (cat.isEmpty()) {
448 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); 448 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
449 } else { 449 } else {
450 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); 450 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
451 } 451 }
452 452
453 } else { 453 } else {
454 if (cat.isEmpty()) { 454 if (cat.isEmpty()) {
455 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); 455 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
456 } else { 456 } else {
457 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); 457 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
458 } 458 }
459 } 459 }
460 460
461 } else { 461 } else {
462 pal = mStandardPalette ; 462 pal = mStandardPalette ;
463 } 463 }
464 item->setPalette( pal ); 464 item->setPalette( pal );
465 item->setRecur( event->recurrence()->doesRecur() ); 465 item->setRecur( event->recurrence()->doesRecur() );
466 item->setAlarm( event->isAlarmEnabled() ); 466 item->setAlarm( event->isAlarmEnabled() );
467 item->setMoreInfo( event->description().length() > 0 ); 467 item->setMoreInfo( event->description().length() > 0 );
468 Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, 468 Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails,
469 KOPrefs::instance()->email()); 469 KOPrefs::instance()->email());
470 if ( me != 0 ) { 470 if ( me != 0 ) {
471 if ( me->status() == Attendee::NeedsAction && me->RSVP()) 471 if ( me->status() == Attendee::NeedsAction && me->RSVP())
472 item->setReply(true); 472 item->setReply(true);
473 else 473 else
474 item->setReply(false); 474 item->setReply(false);
475 } else 475 } else
476 item->setReply(false); 476 item->setReply(false);
477 bool insert = true; 477 bool insert = true;
478 if ( !(event->doesRecur() == Recurrence::rNone) ) { 478 if ( !(event->doesRecur() == Recurrence::rNone) ) {
479 if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) 479 if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily )
480 insert = false; 480 insert = false;
481 else 481 else
482 if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) 482 if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly )
483 insert = false; 483 insert = false;
484 484
485 } 485 }
486 if ( insert ) 486 if ( insert )
487 mItemList->insertItem( item ); 487 mItemList->insertItem( item );
488 } 488 }
489 489
490 // insert due todos 490 // insert due todos
491 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); 491 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate );
492 Todo *todo; 492 Todo *todo;
493 for(todo = todos.first(); todo; todo = todos.next()) { 493 for(todo = todos.first(); todo; todo = todos.next()) {
494 QString text; 494 QString text;
495 if (todo->hasDueDate()) { 495 if (todo->hasDueDate()) {
496 if (!todo->doesFloat()) { 496 if (!todo->doesFloat()) {
497 text += KGlobal::locale()->formatTime(todo->dtDue().time()); 497 text += KGlobal::locale()->formatTime(todo->dtDue().time());
498 text += " "; 498 text += " ";
499 } 499 }
500 } 500 }
501 text += i18n("To-Do: %1").arg(todo->summary()); 501 text += i18n("To-Do: %1").arg(todo->summary());
502 502
503 MonthViewItem *item = new MonthViewItem( todo, mDate, text ); 503 MonthViewItem *item = new MonthViewItem( todo, mDate, text );
504 //item->setPalette( mStandardPalette ); 504 //item->setPalette( mStandardPalette );
505 QPalette pal; 505 QPalette pal;
506 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { 506 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
507 QStringList categories = todo->categories(); 507 QStringList categories = todo->categories();
508 QString cat = categories.first(); 508 QString cat = categories.first();
509 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { 509 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
510 pal = getPalette(); 510 pal = getPalette();
511 if (cat.isEmpty()) { 511 if (cat.isEmpty()) {
512 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); 512 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
513 } else { 513 } else {
514 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); 514 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
515 } 515 }
516 516
517 } else { 517 } else {
518 if (cat.isEmpty()) { 518 if (cat.isEmpty()) {
519 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); 519 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
520 } else { 520 } else {
521 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); 521 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
522 } 522 }
523 } 523 }
524 524
525 } else { 525 } else {
526 pal = mStandardPalette ; 526 pal = mStandardPalette ;
527 } 527 }
528 item->setPalette( pal ); 528 item->setPalette( pal );
529 mItemList->insertItem( item ); 529 mItemList->insertItem( item );
530 } 530 }
531 //setMyPalette(); 531 //setMyPalette();
532 setMyPalette(); 532 setMyPalette();
533 resizeEvent( 0 ); 533 resizeEvent( 0 );
534 // if ( isVisible()) 534 // if ( isVisible())
535 // qApp->processEvents(); 535 // qApp->processEvents();
536} 536}
537 537
538void MonthViewCell::updateConfig() 538void MonthViewCell::updateConfig()
539{ 539{
540 540
541 setFont( KOPrefs::instance()->mMonthViewFont ); 541 setFont( KOPrefs::instance()->mMonthViewFont );
542 542
543 QFontMetrics fm( font() ); 543 QFontMetrics fm( font() );
544 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); 544 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 );
545 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); 545 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 );
546 mHolidayPalette = mStandardPalette; 546 mHolidayPalette = mStandardPalette;
547 mPrimaryPalette = mStandardPalette; 547 mPrimaryPalette = mStandardPalette;
548 mNonPrimaryPalette = mStandardPalette; 548 mNonPrimaryPalette = mStandardPalette;
549 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { 549 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) {
550 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); 550 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor );
551 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); 551 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor );
552 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); 552 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark());
553 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); 553 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark());
554 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); 554 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor);
555 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); 555 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor);
556 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); 556 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark());
557 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); 557 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor);
558 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); 558 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor);
559 } 559 }
560 updateCell(); 560 updateCell();
561} 561}
562 562
563void MonthViewCell::enableScrollBars( bool enabled ) 563void MonthViewCell::enableScrollBars( bool enabled )
564{ 564{
565 if ( enabled ) { 565 if ( enabled ) {
566 mItemList->setVScrollBarMode(QScrollView::Auto); 566 mItemList->setVScrollBarMode(QScrollView::Auto);
567 mItemList->setHScrollBarMode(QScrollView::Auto); 567 mItemList->setHScrollBarMode(QScrollView::Auto);
568 } else { 568 } else {
569 mItemList->setVScrollBarMode(QScrollView::AlwaysOff); 569 mItemList->setVScrollBarMode(QScrollView::AlwaysOff);
570 mItemList->setHScrollBarMode(QScrollView::AlwaysOff); 570 mItemList->setHScrollBarMode(QScrollView::AlwaysOff);
571 } 571 }
572} 572}
573 573
574Incidence *MonthViewCell::selectedIncidence() 574Incidence *MonthViewCell::selectedIncidence()
575{ 575{
576 int index = mItemList->currentItem(); 576 int index = mItemList->currentItem();
577 if ( index < 0 ) return 0; 577 if ( index < 0 ) return 0;
578 578
579 MonthViewItem *item = 579 MonthViewItem *item =
580 static_cast<MonthViewItem *>( mItemList->item( index ) ); 580 static_cast<MonthViewItem *>( mItemList->item( index ) );
581 581
582 if ( !item ) return 0; 582 if ( !item ) return 0;
583 583
584 return item->incidence(); 584 return item->incidence();
585} 585}
586 586
587QDate MonthViewCell::selectedIncidenceDate() 587QDate MonthViewCell::selectedIncidenceDate()
588{ 588{
589 QDate qd; 589 QDate qd;
590 int index = mItemList->currentItem(); 590 int index = mItemList->currentItem();
591 if ( index < 0 ) return qd; 591 if ( index < 0 ) return qd;
592 592
593 MonthViewItem *item = 593 MonthViewItem *item =
594 static_cast<MonthViewItem *>( mItemList->item( index ) ); 594 static_cast<MonthViewItem *>( mItemList->item( index ) );
595 595
596 if ( !item ) return qd; 596 if ( !item ) return qd;
597 597
598 return item->incidenceDate(); 598 return item->incidenceDate();
599} 599}
600 600
601void MonthViewCell::deselect() 601void MonthViewCell::deselect()
602{ 602{
603 mItemList->clearSelection(); 603 mItemList->clearSelection();
604 enableScrollBars( false ); 604 enableScrollBars( false );
605 // updateCell(); 605 // updateCell();
606} 606}
607void MonthViewCell::select() 607void MonthViewCell::select()
608{ 608{
609 ;// updateCell(); 609 ;// updateCell();
610} 610}
611 611
612void MonthViewCell::resizeEvent ( QResizeEvent * ) 612void MonthViewCell::resizeEvent ( QResizeEvent * )
613{ 613{
614 int size = height() - mLabel->height(); 614 int size = height() - mLabel->height();
615 if ( size > 0 ) 615 if ( size > 0 )
616 mItemList->verticalScrollBar()->setMaximumHeight( size ); 616 mItemList->verticalScrollBar()->setMaximumHeight( size );
617 size = width() - mLabel->width(); 617 size = width() - mLabel->width();
618 if ( size > 0 ) 618 if ( size > 0 )
619 mItemList->horizontalScrollBar()->setMaximumWidth( size ); 619 mItemList->horizontalScrollBar()->setMaximumWidth( size );
620 mLabel->move( width()-mItemList->lineWidth() - mLabel->width(), height()-mItemList->lineWidth() - mLabel->height() ); 620 mLabel->move( width()-mItemList->lineWidth() - mLabel->width(), height()-mItemList->lineWidth() - mLabel->height() );
621 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 621 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
622} 622}
623 623
624void MonthViewCell::defaultAction( QListBoxItem *item ) 624void MonthViewCell::defaultAction( QListBoxItem *item )
625{ 625{
626 if ( !item ) return; 626 if ( !item ) return;
627 627
628 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 628 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
629 Incidence *incidence = eventItem->incidence(); 629 Incidence *incidence = eventItem->incidence();
630 if ( incidence ) mMonthView->defaultAction( incidence ); 630 if ( incidence ) mMonthView->defaultAction( incidence );
631} 631}
632void MonthViewCell::newEvent() 632void MonthViewCell::newEvent()
633{ 633{
634 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 634 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
635 emit newEventSignal( dt ); 635 emit newEventSignal( dt );
636} 636}
637void MonthViewCell::cellClicked( QListBoxItem *item ) 637void MonthViewCell::cellClicked( QListBoxItem *item )
638{ 638{
639 static QListBoxItem * lastClicked = 0; 639 static QListBoxItem * lastClicked = 0;
640 if ( item == 0 ) { 640 if ( item == 0 ) {
641 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 641 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
642 emit newEventSignal( dt ); 642 emit newEventSignal( dt );
643 return; 643 return;
644 } 644 }
645 /* 645 /*
646 if ( lastClicked ) 646 if ( lastClicked )
647 if ( ! item ) { 647 if ( ! item ) {
648 if ( lastClicked->listBox() != item->listBox() ) 648 if ( lastClicked->listBox() != item->listBox() )
649 lastClicked->listBox()->clearSelection(); 649 lastClicked->listBox()->clearSelection();
650 } 650 }
651 */ 651 */
652 652
653 mMonthView->setSelectedCell( this ); 653 mMonthView->setSelectedCell( this );
654 if( KOPrefs::instance()->mEnableMonthScroll ) enableScrollBars( true ); 654 if( KOPrefs::instance()->mEnableMonthScroll ) enableScrollBars( true );
655 select(); 655 select();
656} 656}
657 657
658void MonthViewCell::contextMenu( QListBoxItem *item ) 658void MonthViewCell::contextMenu( QListBoxItem *item )
659{ 659{
660 if ( !item ) return; 660 if ( !item ) return;
661 661
662 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 662 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
663 Incidence *incidence = eventItem->incidence(); 663 Incidence *incidence = eventItem->incidence();
664 if ( incidence ) mMonthView->showContextMenu( incidence ); 664 if ( incidence ) mMonthView->showContextMenu( incidence );
665} 665}
666 666
667void MonthViewCell::selection( QListBoxItem *item ) 667void MonthViewCell::selection( QListBoxItem *item )
668{ 668{
669 if ( !item ) return; 669 if ( !item ) return;
670 670
671 mMonthView->setSelectedCell( this ); 671 mMonthView->setSelectedCell( this );
672} 672}
673 673
674 674
675// ******************************************************************************* 675// *******************************************************************************
676// ******************************************************************************* 676// *******************************************************************************
677// ******************************************************************************* 677// *******************************************************************************
678 678
679 679
680KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) 680KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name)
681 : KOEventView( calendar, parent, name ), 681 : KOEventView( calendar, parent, name ),
682 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), 682 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
683 mShortDayLabels( false ), mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) 683 mShortDayLabels( false ), mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
684{ 684{
685 mCells.setAutoDelete( true ); 685 mCells.setAutoDelete( true );
686 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 686 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
687 // mDayLayout = new QGridLayout( this ); 687 // mDayLayout = new QGridLayout( this );
688 // create the day of the week labels (Sun, Mon, etc) and add them to 688 // create the day of the week labels (Sun, Mon, etc) and add them to
689 // the layout. 689 // the layout.
690 mDayLabels.resize( mDaysPerWeek ); 690 mDayLabels.resize( mDaysPerWeek );
691 QFont bfont = font(); 691 QFont bfont = font();
692 if ( QApplication::desktop()->width() < 650 ) { 692 if ( QApplication::desktop()->width() < 650 ) {
693 bfont.setPointSize( bfont.pointSize() - 2 ); 693 bfont.setPointSize( bfont.pointSize() - 2 );
694 } 694 }
695 bfont.setBold( true ); 695 bfont.setBold( true );
696 int i; 696 int i;
697 697
698 for( i = 0; i < mDaysPerWeek; i++ ) { 698 for( i = 0; i < mDaysPerWeek; i++ ) {
699 QLabel *label = new QLabel( this ); 699 QLabel *label = new QLabel( this );
700 label->setFont(bfont); 700 label->setFont(bfont);
701 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 701 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
702 label->setLineWidth(1); 702 label->setLineWidth(1);
703 label->setAlignment(AlignCenter); 703 label->setAlignment(AlignCenter);
704 mDayLabels.insert( i, label ); 704 mDayLabels.insert( i, label );
705 } 705 }
706 706
707 bfont.setBold( false ); 707 bfont.setBold( false );
708 mWeekLabels.resize( mNumWeeks+1 ); 708 mWeekLabels.resize( mNumWeeks+1 );
709 for( i = 0; i < mNumWeeks+1; i++ ) { 709 for( i = 0; i < mNumWeeks+1; i++ ) {
710 KOWeekButton *label = new KOWeekButton( this ); 710 KOWeekButton *label = new KOWeekButton( this );
711 label->setFont(bfont); 711 label->setFont(bfont);
712 connect( label, SIGNAL( selectWeekNum ( int )),this, SIGNAL( selectWeekNum ( int )) ); 712 connect( label, SIGNAL( selectWeekNum ( int )),this, SIGNAL( selectWeekNum ( int )) );
713 label->setFlat(true); 713 label->setFlat(true);
714 QWhatsThis::add(label,i18n("Click on the week number to\nshow week in agenda view")); 714 QWhatsThis::add(label,i18n("Click on the week number to\nshow week in agenda view"));
715 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 715 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
716 //label->setLineWidth(1); 716 //label->setLineWidth(1);
717 //label->setAlignment(AlignCenter); 717 //label->setAlignment(AlignCenter);
718 mWeekLabels.insert( i, label ); 718 mWeekLabels.insert( i, label );
719 } 719 }
720 mWeekLabels[mNumWeeks]->setText( i18n("W")); 720 mWeekLabels[mNumWeeks]->setText( i18n("W"));
721 int row, col; 721 int row, col;
722 mCells.resize( mNumCells ); 722 mCells.resize( mNumCells );
723 for( row = 0; row < mNumWeeks; ++row ) { 723 for( row = 0; row < mNumWeeks; ++row ) {
724 for( col = 0; col < mDaysPerWeek; ++col ) { 724 for( col = 0; col < mDaysPerWeek; ++col ) {
725 MonthViewCell *cell = new MonthViewCell( this ); 725 MonthViewCell *cell = new MonthViewCell( this );
726 mCells.insert( row * mDaysPerWeek + col, cell ); 726 mCells.insert( row * mDaysPerWeek + col, cell );
727 727
728 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 728 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
729 SLOT( defaultAction( Incidence * ) ) ); 729 SLOT( defaultAction( Incidence * ) ) );
730 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 730 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
731 SIGNAL( newEventSignal( QDateTime ) ) ); 731 SIGNAL( newEventSignal( QDateTime ) ) );
732 } 732 }
733 } 733 }
734 734
735 mContextMenu = eventPopup(); 735 mContextMenu = eventPopup();
736 // updateConfig(); //useless here 736 // updateConfig(); //useless here
737 737
738 emit incidenceSelected( 0 ); 738 emit incidenceSelected( 0 );
739} 739}
740 740
741KOMonthView::~KOMonthView() 741KOMonthView::~KOMonthView()
742{ 742{
743 delete mContextMenu; 743 delete mContextMenu;
744} 744}
745 745
746int KOMonthView::maxDatesHint() 746int KOMonthView::maxDatesHint()
747{ 747{
748 return mNumCells; 748 return mNumCells;
749} 749}
750 750
751int KOMonthView::currentDateCount() 751int KOMonthView::currentDateCount()
752{ 752{
753 return mNumCells; 753 return mNumCells;
754} 754}
755 755
756QPtrList<Incidence> KOMonthView::selectedIncidences() 756QPtrList<Incidence> KOMonthView::selectedIncidences()
757{ 757{
758 QPtrList<Incidence> selected; 758 QPtrList<Incidence> selected;
759 759
760 if ( mSelectedCell ) { 760 if ( mSelectedCell ) {
761 Incidence *incidence = mSelectedCell->selectedIncidence(); 761 Incidence *incidence = mSelectedCell->selectedIncidence();
762 if ( incidence ) selected.append( incidence ); 762 if ( incidence ) selected.append( incidence );
763 } 763 }
764 764
765 return selected; 765 return selected;
766} 766}
767 767
768DateList KOMonthView::selectedDates() 768DateList KOMonthView::selectedDates()
769{ 769{
770 DateList selected; 770 DateList selected;
771 771
772 if ( mSelectedCell ) { 772 if ( mSelectedCell ) {
773 QDate qd = mSelectedCell->selectedIncidenceDate(); 773 QDate qd = mSelectedCell->selectedIncidenceDate();
774 if ( qd.isValid() ) selected.append( qd ); 774 if ( qd.isValid() ) selected.append( qd );
775 } 775 }
776 776
777 return selected; 777 return selected;
778} 778}
779 779
780void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, 780void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd,
781 const QDate &td) 781 const QDate &td)
782{ 782{
783#ifndef KORG_NOPRINTER 783#ifndef KORG_NOPRINTER
784 calPrinter->preview(CalPrinter::Month, fd, td); 784 calPrinter->preview(CalPrinter::Month, fd, td);
785#endif 785#endif
786} 786}
787 787
788void KOMonthView::updateConfig() 788void KOMonthView::updateConfig()
789{ 789{
790 790
791 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 791 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
792 792
793 QFontMetrics fontmetric(mDayLabels[0]->font()); 793 QFontMetrics fontmetric(mDayLabels[0]->font());
794 mWidthLongDayLabel = 0; 794 mWidthLongDayLabel = 0;
795 795
796 for (int i = 0; i < 7; i++) { 796 for (int i = 0; i < 7; i++) {
797 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 797 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
798 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 798 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
799 } 799 }
800 bool temp = mShowSatSunComp ; 800 bool temp = mShowSatSunComp ;
801 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 801 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
802 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) 802 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog )
803 computeLayout(); 803 computeLayout();
804 updateDayLabels(); 804 updateDayLabels();
805 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); 805 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks);
806 int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; 806 int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks;
807 //resizeEvent( 0 ); 807 //resizeEvent( 0 );
808 for (uint i = 0; i < mCells.count(); ++i) { 808 for (uint i = 0; i < mCells.count(); ++i) {
809 mCells[i]->updateConfig(); 809 mCells[i]->updateConfig();
810 } 810 }
811} 811}
812 812
813void KOMonthView::updateDayLabels() 813void KOMonthView::updateDayLabels()
814{ 814{
815 815
816 for (int i = 0; i < 7; i++) { 816 for (int i = 0; i < 7; i++) {
817 if (mWeekStartsMonday) { 817 if (mWeekStartsMonday) {
818 bool show = mShortDayLabels; 818 bool show = mShortDayLabels;
819 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > mDayLabels[i]->width() ) 819 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > mDayLabels[i]->width() )
820 show = true; 820 show = true;
821 mDayLabels[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); 821 mDayLabels[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
822 } else { 822 } else {
823 if (i==0) mDayLabels[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabels)); 823 if (i==0) mDayLabels[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabels));
824 else mDayLabels[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabels)); 824 else mDayLabels[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabels));
825 825
826 } 826 }
827 } 827 }
828} 828}
829 829
830void KOMonthView::showDates(const QDate &start, const QDate &) 830void KOMonthView::showDates(const QDate &start, const QDate &)
831{ 831{
832// kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; 832// kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl;
833 833
834 834
835 mStartDate = start; 835 mStartDate = start;
836 836
837 int startWeekDay = mWeekStartsMonday ? 1 : 7; 837 int startWeekDay = mWeekStartsMonday ? 1 : 7;
838 838
839 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { 839 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) {
840 mStartDate = mStartDate.addDays( -1 ); 840 mStartDate = mStartDate.addDays( -1 );
841 } 841 }
842 842
843 bool primary = false; 843 bool primary = false;
844 uint i; 844 uint i;
845 for( i = 0; i < mCells.size(); ++i ) { 845 for( i = 0; i < mCells.size(); ++i ) {
846 QDate date = mStartDate.addDays( i ); 846 QDate date = mStartDate.addDays( i );
847 mCells[i]->setDate( date ); 847 mCells[i]->setDate( date );
848 848
849#ifndef KORG_NOPLUGINS 849#ifndef KORG_NOPLUGINS
850 // add holiday, if present 850 // add holiday, if present
851 QString hstring(KOCore::self()->holiday(date)); 851 QString hstring(KOCore::self()->holiday(date));
852 mCells[i]->setHoliday( hstring ); 852 mCells[i]->setHoliday( hstring );
853#endif 853#endif
854 854
855 } 855 }
856 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); 856 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 );
857 for( i = 0; i < 6; ++i ) { 857 for( i = 0; i < 6; ++i ) {
858 int wno; 858 int wno;
859 // remember, according to ISO 8601, the first week of the year is the 859 // remember, according to ISO 8601, the first week of the year is the
860 // first week that contains a thursday. Thus we must subtract off 4, 860 // first week that contains a thursday. Thus we must subtract off 4,
861 // not just 1. 861 // not just 1.
862 int dayOfYear = date.dayOfYear(); 862 int dayOfYear = date.dayOfYear();
863 if (dayOfYear % 7 != 0) 863 if (dayOfYear % 7 != 0)
864 wno = dayOfYear / 7 + 1; 864 wno = dayOfYear / 7 + 1;
865 else 865 else
866 wno =dayOfYear / 7; 866 wno =dayOfYear / 7;
867 mWeekLabels[i]->setWeekNum( wno ); 867 mWeekLabels[i]->setWeekNum( wno );
868 date = date.addDays( 7 ); 868 date = date.addDays( 7 );
869 } 869 }
870 updateView(); 870 updateView();
871} 871}
872 872
873void KOMonthView::showEvents(QPtrList<Event>) 873void KOMonthView::showEvents(QPtrList<Event>)
874{ 874{
875 qDebug("KOMonthView::selectEvents is not implemented yet. "); 875 qDebug("KOMonthView::selectEvents is not implemented yet. ");
876} 876}
877 877
878void KOMonthView::changeEventDisplay(Event *, int) 878void KOMonthView::changeEventDisplay(Event *, int)
879{ 879{
880 // this should be re-written to be much more efficient, but this 880 // this should be re-written to be much more efficient, but this
881 // quick-and-dirty-hack gets the job done for right now. 881 // quick-and-dirty-hack gets the job done for right now.
882 updateView(); 882 updateView();
883} 883}
884 884
885void KOMonthView::updateView() 885void KOMonthView::updateView()
886{ 886{
887 887
888 uint i; 888 uint i;
889 for( i = 0; i < mCells.count(); ++i ) { 889 for( i = 0; i < mCells.count(); ++i ) {
890 mCells[i]->updateCell(); 890 mCells[i]->updateCell();
891 } 891 }
892 //qDebug("KOMonthView::updateView() "); 892 //qDebug("KOMonthView::updateView() ");
893 processSelectionChange(); 893 processSelectionChange();
894} 894}
895 895
896void KOMonthView::resizeEvent(QResizeEvent * e) 896void KOMonthView::resizeEvent(QResizeEvent * e)
897{ 897{
898 computeLayout(); 898 computeLayout();
899} 899}
900void KOMonthView::computeLayout() 900void KOMonthView::computeLayout()
901{ 901{
902 // select the appropriate heading string size. E.g. "Wednesday" or "Wed". 902 // select the appropriate heading string size. E.g. "Wednesday" or "Wed".
903 // note this only changes the text if the requested size crosses the 903 // note this only changes the text if the requested size crosses the
904 // threshold between big enough to support the full name and not big 904 // threshold between big enough to support the full name and not big
905 // enough. 905 // enough.
906 906
907 int daysToShow = 7; 907 int daysToShow = 7;
908 bool combinedSatSun = false; 908 bool combinedSatSun = false;
909 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { 909 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
910 daysToShow = 6; 910 daysToShow = 6;
911 combinedSatSun = true; 911 combinedSatSun = true;
912 } 912 }
913 int tWid = topLevelWidget()->size().width(); 913 int tWid = topLevelWidget()->size().width();
914 int tHei = topLevelWidget()->size().height(); 914 int tHei = topLevelWidget()->size().height();
915 915
916 int wid = size().width();//e 916 int wid = size().width();//e
917 int hei = size().height()-1; 917 int hei = size().height()-1;
918 918
919 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) 919 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei )
920 return; 920 return;
921 921
922 QFontMetrics fm ( mWeekLabels[0]->font() ); 922 QFontMetrics fm ( mWeekLabels[0]->font() );
923 int weeklabelwid = fm.width( "888" ); 923 int weeklabelwid = fm.width( "888" );
924 wid -= weeklabelwid; 924 wid -= weeklabelwid;
925 925
926 int colWid = wid / daysToShow; 926 int colWid = wid / daysToShow;
927 int lastCol = wid - ( colWid*6 ); 927 int lastCol = wid - ( colWid*6 );
928 int dayLabelHei = mDayLabels[0]->sizeHint().height(); 928 int dayLabelHei = mDayLabels[0]->sizeHint().height();
929 int cellHei = (hei - dayLabelHei) /6; 929 int cellHei = (hei - dayLabelHei) /6;
930 int colModulo = wid % daysToShow; 930 int colModulo = wid % daysToShow;
931 int rowModulo = (hei- dayLabelHei) % 6; 931 int rowModulo = (hei- dayLabelHei) % 6;
932 //qDebug("rowmod %d ", rowModulo); 932 //qDebug("rowmod %d ", rowModulo);
933 int i; 933 int i;
934 int x,y,w,h; 934 int x,y,w,h;
935 x= 0; 935 x= 0;
936 y= 0; 936 y= 0;
937 w = colWid; 937 w = colWid;
938 h = dayLabelHei ; 938 h = dayLabelHei ;
939 for ( i = 0; i < 7; i++) { 939 for ( i = 0; i < 7; i++) {
940 if ( i == daysToShow-colModulo ) 940 if ( i == daysToShow-colModulo )
941 ++w; 941 ++w;
942 if ( combinedSatSun ) { 942 if ( combinedSatSun ) {
943 if ( i >= daysToShow-1 ) { 943 if ( i >= daysToShow-1 ) {
944 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h); 944 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h);
945 x -= w/2 ; 945 x -= w/2 ;
946 } 946 }
947 else 947 else
948 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 948 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
949 } else 949 } else
950 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 950 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
951 x += w; 951 x += w;
952 } 952 }
953 x= 0; 953 x= 0;
954 y= dayLabelHei; 954 y= dayLabelHei;
955 w = colWid; 955 w = colWid;
956 h = cellHei ; 956 h = cellHei ;
957 for ( i = 0; i < mCells.count(); ++i) { 957 for ( i = 0; i < mCells.count(); ++i) {
958 958
959 w = colWid; 959 w = colWid;
960 if ( ((i) % 7) >= 7-colModulo ) { 960 if ( ((i) % 7) >= 7-colModulo ) {
961 ++w; 961 ++w;
962 } 962 }
963 if ( i == (6-rowModulo)*7) 963 if ( i == (6-rowModulo)*7)
964 ++h; 964 ++h;
965 if ( combinedSatSun ) { 965 if ( combinedSatSun ) {
966 if ( (i)%7 >= daysToShow-1 ) { 966 if ( (i)%7 >= daysToShow-1 ) {
967 if ( (i)%7 == daysToShow-1 ) { 967 if ( (i)%7 == daysToShow-1 ) {
968 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h/2 ); 968 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h/2 );
969 x -= w ;y += h/2; 969 x -= w ;y += h/2;
970 } else { 970 } else {
971 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h-h/2 ); 971 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h-h/2 );
972 y -= h/2; 972 y -= h/2;
973 } 973 }
974 } else 974 } else
975 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); 975 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h );
976 976
977 } 977 }
978 else 978 else
979 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); 979 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h );
980 x += w; 980 x += w;
981 if ( x + w/2 > wid ) { 981 if ( x + w/2 > wid ) {
982 x = 0; 982 x = 0;
983 y += h; 983 y += h;
984 } 984 }
985 } 985 }
986 y= dayLabelHei; 986 y= dayLabelHei;
987 h = cellHei ; 987 h = cellHei ;
988 for ( i = 0; i < 6; i++) { 988 for ( i = 0; i < 6; i++) {
989 if ( i == (6-rowModulo)) 989 if ( i == (6-rowModulo))
990 ++h; 990 ++h;
991 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h); 991 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h);
992 y += h; 992 y += h;
993 } 993 }
994 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); 994 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
995 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); 995 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
996 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); 996 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
997 mShortDayLabels = mDayLabels[0]->width() < mWidthLongDayLabel ; 997 mShortDayLabels = mDayLabels[0]->width() < mWidthLongDayLabel ;
998 updateDayLabels(); 998 updateDayLabels();
999} 999}
1000 1000
1001void KOMonthView::showContextMenu( Incidence *incidence ) 1001void KOMonthView::showContextMenu( Incidence *incidence )
1002{ 1002{
1003 mContextMenu->showIncidencePopup(incidence); 1003 mContextMenu->showIncidencePopup(incidence);
1004 /* 1004 /*
1005 if( incidence && incidence->type() == "Event" ) { 1005 if( incidence && incidence->type() == "Event" ) {
1006 Event *event = static_cast<Event *>(incidence); 1006 Event *event = static_cast<Event *>(incidence);
1007 mContextMenu->showEventPopup(event); 1007 mContextMenu->showEventPopup(event);
1008 } else { 1008 } else {
1009 kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; 1009 kdDebug() << "MonthView::showContextMenu(): cast failed." << endl;
1010 } 1010 }
1011 */ 1011 */
1012} 1012}
1013MonthViewCell * KOMonthView::selectedCell( ) 1013MonthViewCell * KOMonthView::selectedCell( )
1014{ 1014{
1015 return mSelectedCell; 1015 return mSelectedCell;
1016} 1016}
1017void KOMonthView::setSelectedCell( MonthViewCell *cell ) 1017void KOMonthView::setSelectedCell( MonthViewCell *cell )
1018{ 1018{
1019 // qDebug("KOMonthView::setSelectedCell "); 1019 // qDebug("KOMonthView::setSelectedCell ");
1020 if ( mSelectedCell && mSelectedCell != cell ) { 1020 if ( mSelectedCell && mSelectedCell != cell ) {
1021 MonthViewCell * mvc = mSelectedCell; 1021 MonthViewCell * mvc = mSelectedCell;
1022 mSelectedCell = cell; 1022 mSelectedCell = cell;
1023 mvc->deselect(); 1023 mvc->deselect();
1024 } else 1024 } else
1025 mSelectedCell = cell; 1025 mSelectedCell = cell;
1026 // if ( mSelectedCell ) 1026 // if ( mSelectedCell )
1027// mSelectedCell->select(); 1027// mSelectedCell->select();
1028 if ( !mSelectedCell ) 1028 if ( !mSelectedCell )
1029 emit incidenceSelected( 0 ); 1029 emit incidenceSelected( 0 );
1030 else 1030 else
1031 emit incidenceSelected( mSelectedCell->selectedIncidence() ); 1031 emit incidenceSelected( mSelectedCell->selectedIncidence() );
1032} 1032}
1033 1033
1034void KOMonthView::processSelectionChange() 1034void KOMonthView::processSelectionChange()
1035{ 1035{
1036 QPtrList<Incidence> incidences = selectedIncidences(); 1036 QPtrList<Incidence> incidences = selectedIncidences();
1037 if (incidences.count() > 0) { 1037 if (incidences.count() > 0) {
1038 emit incidenceSelected( incidences.first() ); 1038 emit incidenceSelected( incidences.first() );
1039 } else { 1039 } else {
1040 emit incidenceSelected( 0 ); 1040 emit incidenceSelected( 0 );
1041 } 1041 }
1042} 1042}
1043 1043
1044void KOMonthView::clearSelection() 1044void KOMonthView::clearSelection()
1045{ 1045{
1046 if ( mSelectedCell ) { 1046 if ( mSelectedCell ) {
1047 mSelectedCell->deselect(); 1047 mSelectedCell->deselect();
1048 mSelectedCell = 0; 1048 mSelectedCell = 0;
1049 } 1049 }
1050} 1050}
1051void KOMonthView::keyPressEvent ( QKeyEvent * e ) 1051void KOMonthView::keyPressEvent ( QKeyEvent * e )
1052{ 1052{
1053 1053
1054 e->ignore(); 1054 e->ignore();
1055 1055
1056} 1056}