summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-04-01 19:05:18 (UTC)
committer zautrix <zautrix>2005-04-01 19:05:18 (UTC)
commit1022d8763a5185c74d1fb1fba9857d6e3afd9ff5 (patch) (unidiff)
tree116b7ac7aef10e27c20ce30f3bae548ebde84da0
parentedc032c21ae3788d02a632ea8066e4ac5a4feedb (diff)
downloadkdepimpi-1022d8763a5185c74d1fb1fba9857d6e3afd9ff5.zip
kdepimpi-1022d8763a5185c74d1fb1fba9857d6e3afd9ff5.tar.gz
kdepimpi-1022d8763a5185c74d1fb1fba9857d6e3afd9ff5.tar.bz2
fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagendaview.cpp30
-rw-r--r--korganizer/kodaymatrix.cpp4
2 files changed, 16 insertions, 18 deletions
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp
index 072d464..99f547a 100644
--- a/korganizer/koagendaview.cpp
+++ b/korganizer/koagendaview.cpp
@@ -1,1618 +1,1614 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qhbox.h> 24#include <qhbox.h>
25#include <qvbox.h> 25#include <qvbox.h>
26#include <qlabel.h> 26#include <qlabel.h>
27#include <qframe.h> 27#include <qframe.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#ifndef KORG_NOSPLITTER 29#ifndef KORG_NOSPLITTER
30#include <qsplitter.h> 30#include <qsplitter.h>
31#endif 31#endif
32#include <qfont.h> 32#include <qfont.h>
33#include <qfontmetrics.h> 33#include <qfontmetrics.h>
34#include <qpopupmenu.h> 34#include <qpopupmenu.h>
35#include <qtooltip.h> 35#include <qtooltip.h>
36#include <qpainter.h> 36#include <qpainter.h>
37#include <qpushbutton.h> 37#include <qpushbutton.h>
38#include <qapplication.h> 38#include <qapplication.h>
39 39
40#include <kapplication.h> 40#include <kapplication.h>
41#include <KDGanttMinimizeSplitter.h> 41#include <KDGanttMinimizeSplitter.h>
42#include <kdebug.h> 42#include <kdebug.h>
43#include <kstandarddirs.h> 43#include <kstandarddirs.h>
44#include <kiconloader.h> 44#include <kiconloader.h>
45#include <klocale.h> 45#include <klocale.h>
46#include <kconfig.h> 46#include <kconfig.h>
47#include <kglobal.h> 47#include <kglobal.h>
48#include "calendarview.h" 48#include "calendarview.h"
49#include "koviewmanager.h" 49#include "koviewmanager.h"
50 50
51#include <libkcal/calendar.h> 51#include <libkcal/calendar.h>
52#include <libkcal/icaldrag.h> 52#include <libkcal/icaldrag.h>
53#include <libkcal/dndfactory.h> 53#include <libkcal/dndfactory.h>
54 54
55#include <kcalendarsystem.h> 55#include <kcalendarsystem.h>
56 56
57#include "koglobals.h" 57#include "koglobals.h"
58#ifndef KORG_NOPLUGINS 58#ifndef KORG_NOPLUGINS
59#include "kocore.h" 59#include "kocore.h"
60#endif 60#endif
61#include "koprefs.h" 61#include "koprefs.h"
62#include "koagenda.h" 62#include "koagenda.h"
63#include "koagendaitem.h" 63#include "koagendaitem.h"
64#ifndef KORG_NOPRINTER 64#ifndef KORG_NOPRINTER
65#include "calprinter.h" 65#include "calprinter.h"
66#endif 66#endif
67 67
68#include "koagendaview.h" 68#include "koagendaview.h"
69//#include "koagendaview.moc" 69//#include "koagendaview.moc"
70 70
71//extern bool globalFlagBlockPainting; 71//extern bool globalFlagBlockPainting;
72extern int globalFlagBlockAgenda; 72extern int globalFlagBlockAgenda;
73extern int globalFlagBlockStartup; 73extern int globalFlagBlockStartup;
74extern int globalFlagBlockAgendaItemPaint; 74extern int globalFlagBlockAgendaItemPaint;
75extern int globalFlagBlockAgendaItemUpdate; 75extern int globalFlagBlockAgendaItemUpdate;
76extern int globalFlagBlockLabel; 76extern int globalFlagBlockLabel;
77using namespace KOrg; 77using namespace KOrg;
78 78
79 79
80 80
81TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) : 81TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) :
82 QScrollView(parent,name,f) 82 QScrollView(parent,name,f)
83{ 83{
84 myPix.resize( 1, 1 ); 84 myPix.resize( 1, 1 );
85 mRows = rows; 85 mRows = rows;
86 86
87 mRedrawNeeded = true; 87 mRedrawNeeded = true;
88 setMinimumHeight( 20 ); 88 setMinimumHeight( 20 );
89 mCellHeight = KOPrefs::instance()->mHourSize*4; 89 mCellHeight = KOPrefs::instance()->mHourSize*4;
90 90
91 enableClipper(true); 91 enableClipper(true);
92 92
93 setHScrollBarMode(AlwaysOff); 93 setHScrollBarMode(AlwaysOff);
94 setVScrollBarMode(AlwaysOff); 94 setVScrollBarMode(AlwaysOff);
95 95
96 resizeContents(50,mRows * mCellHeight); 96 resizeContents(50,mRows * mCellHeight);
97 97
98 viewport()->setBackgroundMode( PaletteBackground ); 98 viewport()->setBackgroundMode( PaletteBackground );
99} 99}
100 100
101void TimeLabels::setCellHeight(int height) 101void TimeLabels::setCellHeight(int height)
102{ 102{
103 mCellHeight = height; 103 mCellHeight = height;
104} 104}
105 105
106/* 106/*
107 Optimization so that only the "dirty" portion of the scroll view 107 Optimization so that only the "dirty" portion of the scroll view
108 is redrawn. Unfortunately, this is not called by default paintEvent() method. 108 is redrawn. Unfortunately, this is not called by default paintEvent() method.
109*/ 109*/
110void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) 110void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch)
111{ 111{
112 112
113 // if ( globalFlagBlockAgenda ) 113 // if ( globalFlagBlockAgenda )
114 // return; 114 // return;
115 // bug: the parameters cx, cy, cw, ch are the areas that need to be 115 // bug: the parameters cx, cy, cw, ch are the areas that need to be
116 // redrawn, not the area of the widget. unfortunately, this 116 // redrawn, not the area of the widget. unfortunately, this
117 // code assumes the latter... 117 // code assumes the latter...
118 118
119 // now, for a workaround... 119 // now, for a workaround...
120 // these two assignments fix the weird redraw bug 120 // these two assignments fix the weird redraw bug
121 mRedrawNeeded = true; 121 mRedrawNeeded = true;
122 if ( mRedrawNeeded ) { 122 if ( mRedrawNeeded ) {
123 cx = contentsX() + frameWidth()*2; 123 cx = contentsX() + frameWidth()*2;
124 cw = contentsWidth() ; 124 cw = contentsWidth() ;
125 // end of workaround 125 // end of workaround
126 126
127 int cell = ((int)(cy/mCellHeight)); 127 int cell = ((int)(cy/mCellHeight));
128 int y = cell * mCellHeight; 128 int y = cell * mCellHeight;
129 QFontMetrics fm = fontMetrics(); 129 QFontMetrics fm = fontMetrics();
130 QString hour; 130 QString hour;
131 QString suffix; 131 QString suffix;
132 int tW = fm.width("24:00i"); 132 int timeHeight = fm.ascent();
133 int timeHeight = fm.height();
134 //timeHeight -= (timeHeight/4-2);
135 int borderWidth = 0;
136 QFont nFont = p->font(); 133 QFont nFont = p->font();
137 134
138 if (!KGlobal::locale()->use12Clock()) 135 if (!KGlobal::locale()->use12Clock())
139 suffix = "00"; 136 suffix = "00";
140 else 137
141 borderWidth = 0;
142 if ( timeHeight > mCellHeight ) { 138 if ( timeHeight > mCellHeight ) {
143 timeHeight = mCellHeight-1; 139 timeHeight = mCellHeight-1;
144 int pointS = nFont.pointSize(); 140 int pointS = nFont.pointSize();
145 while ( pointS > 4 ) { 141 while ( pointS > 4 ) {
146 nFont.setPointSize( pointS ); 142 nFont.setPointSize( pointS );
147 fm = QFontMetrics( nFont ); 143 fm = QFontMetrics( nFont );
148 if ( fm.height() < mCellHeight ) 144 if ( fm.ascent() < mCellHeight )
149 break; 145 break;
150 -- pointS; 146 -- pointS;
151 } 147 }
152 fm = QFontMetrics( nFont ); 148 fm = QFontMetrics( nFont );
153 borderWidth = 4; 149 timeHeight = fm.ascent();
154 timeHeight = fm.height();
155 } 150 }
156 //timeHeight -= (timeHeight/4-2); 151 //timeHeight -= (timeHeight/4-2);
157 QFont sFont = nFont; 152 QFont sFont = nFont;
158 sFont.setPointSize( sFont.pointSize()/2+2 ); 153 sFont.setPointSize( sFont.pointSize()/2 );
159 QFontMetrics fmS( sFont ); 154 QFontMetrics fmS( sFont );
160 int sHei = fmS.height(); 155 int sHei = fmS.ascent() ;
161 //sHei -= (sHei/4-2); 156 //sHei -= (sHei/4-2);
162 int startW = this->width() - frameWidth()-1; 157 int startW = this->width() - 2*frameWidth()-1;
158 int tw2 = fmS.width(suffix);
163 while (y < cy + ch) { 159 while (y < cy + ch) {
164 p->drawLine(cx,y,cx+tW,y); 160 p->drawLine(cx,y,cw,y);
165 hour.setNum(cell); 161 hour.setNum(cell);
166 162
167 // handle 24h and am/pm time formats 163 // handle 24h and am/pm time formats
168 if (KGlobal::locale()->use12Clock()) { 164 if (KGlobal::locale()->use12Clock()) {
169 if (cell > 11) suffix = "pm"; 165 if (cell > 11) suffix = "pm";
170 else 166 else
171 suffix = "am"; 167 suffix = "am";
172 if (cell == 0) hour.setNum(12); 168 if (cell == 0) hour.setNum(12);
173 if (cell > 12) hour.setNum(cell - 12); 169 if (cell > 12) hour.setNum(cell - 12);
170 tw2 = fmS.width(suffix);
174 } 171 }
175 172
176 // center and draw the time label 173 // center and draw the time label
177 int timeWidth = fm.width(hour); 174 int timeWidth = fm.width(hour);
178 int tw2 = fm.width(suffix);
179 int offset = startW - timeWidth - tw2 ; 175 int offset = startW - timeWidth - tw2 ;
180 p->setFont( nFont ); 176 p->setFont( nFont );
181 p->drawText( offset, y+ timeHeight, hour); 177 p->drawText( offset, y+ timeHeight, hour);
182 p->setFont( sFont ); 178 p->setFont( sFont );
183 offset = startW - tw2+1; 179 offset = startW - tw2+1;
184 p->drawText( offset, y+ sHei, suffix); 180 p->drawText( offset, y+ sHei, suffix);
185 181
186 // increment indices 182 // increment indices
187 y += mCellHeight; 183 y += mCellHeight;
188 cell++; 184 cell++;
189 } 185 }
190 } else { 186 } else {
191 //qDebug("NO redraw "); 187 //qDebug("NO redraw ");
192 } 188 }
193 // double buffer not yet implemented 189 // double buffer not yet implemented
194 //bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP); 190 //bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP);
195 //mRedrawNeeded = false; 191 //mRedrawNeeded = false;
196} 192}
197 193
198/** 194/**
199 Calculates the minimum width. 195 Calculates the minimum width.
200*/ 196*/
201int TimeLabels::minimumWidth() const 197int TimeLabels::minimumWidth() const
202{ 198{
203 return mMiniWidth; 199 return mMiniWidth;
204} 200}
205 201
206/** updates widget's internal state */ 202/** updates widget's internal state */
207void TimeLabels::updateConfig() 203void TimeLabels::updateConfig()
208{ 204{
209 mRedrawNeeded = true; 205 mRedrawNeeded = true;
210 // set the font 206 // set the font
211 // config->setGroup("Fonts"); 207 // config->setGroup("Fonts");
212 // QFont font = config->readFontEntry("TimeBar Font"); 208 // QFont font = config->readFontEntry("TimeBar Font");
213 setFont(KOPrefs::instance()->mTimeBarFont); 209 setFont(KOPrefs::instance()->mTimeBarFont);
214 QString test = "88:88"; 210 QString test = "20oo";
215 if (KGlobal::locale()->use12Clock()) 211 if (KGlobal::locale()->use12Clock())
216 test += "i"; 212 test = "12mi";
217 mMiniWidth = fontMetrics().width(test) + frameWidth()*2 +1 ; 213 mMiniWidth = fontMetrics().width(test) + frameWidth()*2 +1 ;
218 // update geometry restrictions based on new settings 214 // update geometry restrictions based on new settings
219 setFixedWidth(minimumWidth()); 215 setFixedWidth( mMiniWidth );
220 216
221 // update HourSize 217 // update HourSize
222 mCellHeight = KOPrefs::instance()->mHourSize*4; 218 mCellHeight = KOPrefs::instance()->mHourSize*4;
223 resizeContents(50,mRows * mCellHeight); 219 resizeContents(50,mRows * mCellHeight);
224} 220}
225 221
226/** update time label positions */ 222/** update time label positions */
227void TimeLabels::positionChanged() 223void TimeLabels::positionChanged()
228{ 224{
229 int adjustment = mAgenda->contentsY(); 225 int adjustment = mAgenda->contentsY();
230 setContentsPos(0, adjustment); 226 setContentsPos(0, adjustment);
231} 227}
232 228
233/** */ 229/** */
234void TimeLabels::setAgenda(KOAgenda* agenda) 230void TimeLabels::setAgenda(KOAgenda* agenda)
235{ 231{
236 mAgenda = agenda; 232 mAgenda = agenda;
237} 233}
238 234
239void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) 235void TimeLabels::contentsMousePressEvent ( QMouseEvent * e)
240{ 236{
241 mMouseDownY = e->pos().y(); 237 mMouseDownY = e->pos().y();
242 mOrgCap = topLevelWidget()->caption(); 238 mOrgCap = topLevelWidget()->caption();
243} 239}
244 240
245void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) 241void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e )
246{ 242{
247 int diff = mMouseDownY - e->pos().y(); 243 int diff = mMouseDownY - e->pos().y();
248 if ( diff < 10 && diff > -10 ) 244 if ( diff < 10 && diff > -10 )
249 return; 245 return;
250 int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; 246 int tSize = KOPrefs::instance()->mHourSize + (diff/10) ;
251 if ( tSize < 4 ) 247 if ( tSize < 4 )
252 tSize = 4; 248 tSize = 4;
253 if ( tSize > 22 ) 249 if ( tSize > 22 )
254 tSize = 22; 250 tSize = 22;
255 tSize = (tSize-2)/2; 251 tSize = (tSize-2)/2;
256 topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); 252 topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize));
257 253
258} 254}
259void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) 255void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e )
260{ 256{
261 topLevelWidget()->setCaption( mOrgCap ); 257 topLevelWidget()->setCaption( mOrgCap );
262 int diff = mMouseDownY - e->pos().y(); 258 int diff = mMouseDownY - e->pos().y();
263 if ( diff < 10 && diff > -10 ) 259 if ( diff < 10 && diff > -10 )
264 return; 260 return;
265 int tSize = KOPrefs::instance()->mHourSize + (diff/10); 261 int tSize = KOPrefs::instance()->mHourSize + (diff/10);
266 if ( tSize < 4 ) 262 if ( tSize < 4 )
267 tSize = 4; 263 tSize = 4;
268 if ( tSize > 22 ) 264 if ( tSize > 22 )
269 tSize = 22; 265 tSize = 22;
270 tSize = (tSize/2)*2; 266 tSize = (tSize/2)*2;
271 if ( tSize == KOPrefs::instance()->mHourSize ) 267 if ( tSize == KOPrefs::instance()->mHourSize )
272 return; 268 return;
273 KOPrefs::instance()->mHourSize = tSize; 269 KOPrefs::instance()->mHourSize = tSize;
274 emit scaleChanged(); 270 emit scaleChanged();
275} 271}
276 272
277/** This is called in response to repaint() */ 273/** This is called in response to repaint() */
278void TimeLabels::paintEvent(QPaintEvent*) 274void TimeLabels::paintEvent(QPaintEvent*)
279{ 275{
280 276
281 // kdDebug() << "paintevent..." << endl; 277 // kdDebug() << "paintevent..." << endl;
282 // this is another hack! 278 // this is another hack!
283 // QPainter painter(this); 279 // QPainter painter(this);
284 //QString c 280 //QString c
285 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight()); 281 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight());
286} 282}
287 283
288//////////////////////////////////////////////////////////////////////////// 284////////////////////////////////////////////////////////////////////////////
289 285
290EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name) 286EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name)
291 : QFrame(parent,name) 287 : QFrame(parent,name)
292{ 288{
293 mColumns = 1; 289 mColumns = 1;
294 mTopBox = 0; 290 mTopBox = 0;
295 mLocation = loc; 291 mLocation = loc;
296 mTopLayout = 0; 292 mTopLayout = 0;
297 mPaintWidget = 0; 293 mPaintWidget = 0;
298 mXOffset = 0; 294 mXOffset = 0;
299 if (mLocation == Top) mPixmap = SmallIcon("1uparrow"); 295 if (mLocation == Top) mPixmap = SmallIcon("1uparrow");
300 else mPixmap = SmallIcon("1downarrow"); 296 else mPixmap = SmallIcon("1downarrow");
301 mEnabled.resize(mColumns); 297 mEnabled.resize(mColumns);
302 mEnabled.fill( false ); 298 mEnabled.fill( false );
303 setMinimumHeight(mPixmap.height()); 299 setMinimumHeight(mPixmap.height());
304} 300}
305 301
306EventIndicator::~EventIndicator() 302EventIndicator::~EventIndicator()
307{ 303{
308} 304}
309 305
310void EventIndicator::drawContents(QPainter *p) 306void EventIndicator::drawContents(QPainter *p)
311{ 307{
312 308
313 // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl; 309 // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl;
314 KDGanttSplitterHandle* han = 0; 310 KDGanttSplitterHandle* han = 0;
315 if ( mPaintWidget ) 311 if ( mPaintWidget )
316 han = mPaintWidget->firstHandle(); 312 han = mPaintWidget->firstHandle();
317 if ( ! han ) { 313 if ( ! han ) {
318 int i; 314 int i;
319 for(i=0;i<mColumns;++i) { 315 for(i=0;i<mColumns;++i) {
320 if (mEnabled[i]) { 316 if (mEnabled[i]) {
321 int cellWidth = contentsRect().right()/mColumns; 317 int cellWidth = contentsRect().right()/mColumns;
322 int xOffset = KOGlobals::self()->reverseLayout() ? 318 int xOffset = KOGlobals::self()->reverseLayout() ?
323 (mColumns - 1 - i)*cellWidth + (cellWidth -mPixmap.width())/2 : 319 (mColumns - 1 - i)*cellWidth + (cellWidth -mPixmap.width())/2 :
324 i*cellWidth + (cellWidth -mPixmap.width()) /2; 320 i*cellWidth + (cellWidth -mPixmap.width()) /2;
325 p->drawPixmap(QPoint(1+xOffset,0),mPixmap); 321 p->drawPixmap(QPoint(1+xOffset,0),mPixmap);
326 } 322 }
327 } 323 }
328 } else { 324 } else {
329 han->repaint(); 325 han->repaint();
330 //mPaintWidget->setBackgroundColor( red ); 326 //mPaintWidget->setBackgroundColor( red );
331 327
332 QPainter pa( han ); 328 QPainter pa( han );
333 int i; 329 int i;
334 bool setColor = false; 330 bool setColor = false;
335 for(i=0;i<mColumns;++i) { 331 for(i=0;i<mColumns;++i) {
336 if (mEnabled[i]) { 332 if (mEnabled[i]) {
337 setColor = true; 333 setColor = true;
338 334
339 int cellWidth = contentsRect().right()/mColumns; 335 int cellWidth = contentsRect().right()/mColumns;
340 int xOffset = KOGlobals::self()->reverseLayout() ? 336 int xOffset = KOGlobals::self()->reverseLayout() ?
341 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 : 337 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 :
342 i*cellWidth + cellWidth/2 -mPixmap.width()/2; 338 i*cellWidth + cellWidth/2 -mPixmap.width()/2;
343 pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap); 339 pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap);
344 //qDebug("222draw pix %d ",xOffset ); 340 //qDebug("222draw pix %d ",xOffset );
345 341
346 } 342 }
347 343
348 } 344 }
349 pa.end(); 345 pa.end();
350 346
351 } 347 }
352} 348}
353 349
354void EventIndicator::setXOffset( int x ) 350void EventIndicator::setXOffset( int x )
355{ 351{
356 mXOffset = x; 352 mXOffset = x;
357} 353}
358void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w ) 354void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w )
359{ 355{
360 mPaintWidget = w; 356 mPaintWidget = w;
361 setMaximumHeight(0); 357 setMaximumHeight(0);
362 setMinimumHeight(0); 358 setMinimumHeight(0);
363} 359}
364void EventIndicator::changeColumns(int columns) 360void EventIndicator::changeColumns(int columns)
365{ 361{
366 mColumns = columns; 362 mColumns = columns;
367 mEnabled.resize(mColumns); 363 mEnabled.resize(mColumns);
368 364
369 update(); 365 update();
370} 366}
371 367
372void EventIndicator::enableColumn(int column, bool enable) 368void EventIndicator::enableColumn(int column, bool enable)
373{ 369{
374 mEnabled[column] = enable; 370 mEnabled[column] = enable;
375} 371}
376 372
377 373
378//////////////////////////////////////////////////////////////////////////// 374////////////////////////////////////////////////////////////////////////////
379//////////////////////////////////////////////////////////////////////////// 375////////////////////////////////////////////////////////////////////////////
380//////////////////////////////////////////////////////////////////////////// 376////////////////////////////////////////////////////////////////////////////
381 377
382KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) : 378KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) :
383 KOEventView (cal,parent,name) 379 KOEventView (cal,parent,name)
384{ 380{
385 mBlockUpdating = true; 381 mBlockUpdating = true;
386 mStartHour = 8; 382 mStartHour = 8;
387 mSelectedDates.append(QDate::currentDate()); 383 mSelectedDates.append(QDate::currentDate());
388 384
389 mLayoutDayLabels = 0; 385 mLayoutDayLabels = 0;
390 mDayLabelsFrame = 0; 386 mDayLabelsFrame = 0;
391 mDayLabels = 0; 387 mDayLabels = 0;
392 bool isRTL = KOGlobals::self()->reverseLayout(); 388 bool isRTL = KOGlobals::self()->reverseLayout();
393 QPixmap expandPix; 389 QPixmap expandPix;
394 if ( KOPrefs::instance()->mVerticalScreen ) { 390 if ( KOPrefs::instance()->mVerticalScreen ) {
395 expandPix = SmallIcon( "1updownarrow" ); 391 expandPix = SmallIcon( "1updownarrow" );
396 } else { 392 } else {
397 expandPix = SmallIcon("1leftrightarrow" ); 393 expandPix = SmallIcon("1leftrightarrow" );
398 } 394 }
399 395
400 QBoxLayout *topLayout = new QVBoxLayout(this); 396 QBoxLayout *topLayout = new QVBoxLayout(this);
401 397
402 // Create day name labels for agenda columns 398 // Create day name labels for agenda columns
403 // Create agenda splitter 399 // Create agenda splitter
404 400
405 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this); 401 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this);
406 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 402 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
407 topLayout->addWidget( mSplitterAgenda ); 403 topLayout->addWidget( mSplitterAgenda );
408 mAllDayFrame = new QHBox(mSplitterAgenda); 404 mAllDayFrame = new QHBox(mSplitterAgenda);
409 mAllDayFrame->setFocusPolicy(NoFocus); 405 mAllDayFrame->setFocusPolicy(NoFocus);
410 QWidget *agendaFrame = new QWidget(mSplitterAgenda); 406 QWidget *agendaFrame = new QWidget(mSplitterAgenda);
411 agendaFrame->setFocusPolicy(NoFocus); 407 agendaFrame->setFocusPolicy(NoFocus);
412 408
413 // Create all-day agenda widget 409 // Create all-day agenda widget
414 mDummyAllDayLeft = new QVBox( mAllDayFrame ); 410 mDummyAllDayLeft = new QVBox( mAllDayFrame );
415 411
416 mExpandButton = new QPushButton(mDummyAllDayLeft); 412 mExpandButton = new QPushButton(mDummyAllDayLeft);
417 mExpandButton->setPixmap( expandPix ); 413 mExpandButton->setPixmap( expandPix );
418 int widebut = mExpandButton->sizeHint().width()+4; 414 int widebut = mExpandButton->sizeHint().width()+4;
419 int heibut = mExpandButton->sizeHint().height()+4; 415 int heibut = mExpandButton->sizeHint().height()+4;
420 if ( heibut > widebut ) 416 if ( heibut > widebut )
421 widebut = heibut ; 417 widebut = heibut ;
422 418
423 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, 419 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed,
424 // QSizePolicy::Fixed ) ); 420 // QSizePolicy::Fixed ) );
425 mExpandButton->setFixedSize( widebut, widebut); 421 mExpandButton->setFixedSize( widebut, widebut);
426 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) ); 422 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) );
427 mExpandButton->setFocusPolicy(NoFocus); 423 mExpandButton->setFocusPolicy(NoFocus);
428 mAllDayAgenda = new KOAgenda(1,mAllDayFrame); 424 mAllDayAgenda = new KOAgenda(1,mAllDayFrame);
429 mAllDayAgenda->setFocusPolicy(NoFocus); 425 mAllDayAgenda->setFocusPolicy(NoFocus);
430 QLabel *dummyAllDayRight = new QLabel (mAllDayFrame); 426 QLabel *dummyAllDayRight = new QLabel (mAllDayFrame);
431 427
432 // Create event context menu for all day agenda 428 // Create event context menu for all day agenda
433 mAllDayAgendaPopup = eventPopup(); 429 mAllDayAgendaPopup = eventPopup();
434 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), 430 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
435 mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *))); 431 mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
436 432
437 // Create agenda frame 433 // Create agenda frame
438 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,4,3); 434 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,4,3);
439 // QHBox *agendaFrame = new QHBox(splitterAgenda); 435 // QHBox *agendaFrame = new QHBox(splitterAgenda);
440 436
441 // create event indicator bars 437 // create event indicator bars
442 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame); 438 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame);
443#ifndef DESKTOP_VERSION 439#ifndef DESKTOP_VERSION
444 // FIX 440 // FIX
445 mEventIndicatorTop->setPaintWidget( mSplitterAgenda ); 441 mEventIndicatorTop->setPaintWidget( mSplitterAgenda );
446#endif 442#endif
447 mDayLabelsFrame = new QHBox(agendaFrame); 443 mDayLabelsFrame = new QHBox(agendaFrame);
448 //topLayout->addWidget(mDayLabelsFrame); 444 //topLayout->addWidget(mDayLabelsFrame);
449 mDayLabels = new QFrame (mDayLabelsFrame); 445 mDayLabels = new QFrame (mDayLabelsFrame);
450 mLayoutDayLabels = new QHBoxLayout(mDayLabels); 446 mLayoutDayLabels = new QHBoxLayout(mDayLabels);
451 agendaLayout->addMultiCellWidget(mDayLabelsFrame ,0,0,0,2); 447 agendaLayout->addMultiCellWidget(mDayLabelsFrame ,0,0,0,2);
452 agendaLayout->addWidget(mEventIndicatorTop,1,1); 448 agendaLayout->addWidget(mEventIndicatorTop,1,1);
453 449
454 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom, 450 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom,
455 agendaFrame); 451 agendaFrame);
456 agendaLayout->addWidget(mEventIndicatorBottom,3,1); 452 agendaLayout->addWidget(mEventIndicatorBottom,3,1);
457 QWidget *dummyAgendaRight = new QWidget(agendaFrame); 453 QWidget *dummyAgendaRight = new QWidget(agendaFrame);
458 agendaLayout->addWidget(dummyAgendaRight,1,2); 454 agendaLayout->addWidget(dummyAgendaRight,1,2);
459 455
460 // Create time labels 456 // Create time labels
461 mTimeLabels = new TimeLabels(24,agendaFrame); 457 mTimeLabels = new TimeLabels(24,agendaFrame);
462 agendaLayout->addWidget(mTimeLabels,2,0); 458 agendaLayout->addWidget(mTimeLabels,2,0);
463 connect(mTimeLabels,SIGNAL( scaleChanged()), 459 connect(mTimeLabels,SIGNAL( scaleChanged()),
464 this,SLOT(updateConfig())); 460 this,SLOT(updateConfig()));
465 461
466 // Create agenda 462 // Create agenda
467 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame); 463 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame);
468 agendaLayout->addMultiCellWidget(mAgenda,2,2,1,2); 464 agendaLayout->addMultiCellWidget(mAgenda,2,2,1,2);
469 agendaLayout->setColStretch(1,1); 465 agendaLayout->setColStretch(1,1);
470 mAgenda->setFocusPolicy(NoFocus); 466 mAgenda->setFocusPolicy(NoFocus);
471 // Create event context menu for agenda 467 // Create event context menu for agenda
472 mAgendaPopup = eventPopup(); 468 mAgendaPopup = eventPopup();
473 469
474 mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")), 470 mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")),
475 i18n("Toggle Alarm"),mAgenda, 471 i18n("Toggle Alarm"),mAgenda,
476 SLOT(popupAlarm()),true); 472 SLOT(popupAlarm()),true);
477 473
478 474
479 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), 475 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
480 mAgendaPopup,SLOT(showIncidencePopup(Incidence *))); 476 mAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
481 477
482 // make connections between dependent widgets 478 // make connections between dependent widgets
483 mTimeLabels->setAgenda(mAgenda); 479 mTimeLabels->setAgenda(mAgenda);
484 480
485 // Update widgets to reflect user preferences 481 // Update widgets to reflect user preferences
486 // updateConfig(); 482 // updateConfig();
487 483
488 // createDayLabels(); 484 // createDayLabels();
489 485
490 // these blank widgets make the All Day Event box line up with the agenda 486 // these blank widgets make the All Day Event box line up with the agenda
491 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 487 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
492 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 488 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
493 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 489 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
494 490
495 // Scrolling 491 // Scrolling
496 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)), 492 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)),
497 mTimeLabels, SLOT(positionChanged())); 493 mTimeLabels, SLOT(positionChanged()));
498 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)), 494 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)),
499 SLOT(setContentsPos(int))); 495 SLOT(setContentsPos(int)));
500 496
501 connect(mAgenda,SIGNAL(showDateView( int, int)),SLOT(slotShowDateView( int, int ))); 497 connect(mAgenda,SIGNAL(showDateView( int, int)),SLOT(slotShowDateView( int, int )));
502 connect(mAllDayAgenda,SIGNAL(showDateView( int, int )), SLOT(slotShowDateView( int, int ) )); 498 connect(mAllDayAgenda,SIGNAL(showDateView( int, int )), SLOT(slotShowDateView( int, int ) ));
503 499
504 // Create/Show/Edit/Delete Event 500 // Create/Show/Edit/Delete Event
505 connect(mAgenda,SIGNAL(newEventSignal(int,int)), 501 connect(mAgenda,SIGNAL(newEventSignal(int,int)),
506 SLOT(newEvent(int,int))); 502 SLOT(newEvent(int,int)));
507 connect(mAgenda,SIGNAL(newTodoSignal(int,int)), 503 connect(mAgenda,SIGNAL(newTodoSignal(int,int)),
508 SLOT(newTodo(int,int))); 504 SLOT(newTodo(int,int)));
509 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)), 505 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)),
510 SLOT(newEvent(int,int,int,int))); 506 SLOT(newEvent(int,int,int,int)));
511 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)), 507 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)),
512 SLOT(newEventAllDay(int,int))); 508 SLOT(newEventAllDay(int,int)));
513 connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)), 509 connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)),
514 SLOT(newTodoAllDay(int,int))); 510 SLOT(newTodoAllDay(int,int)));
515 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)), 511 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)),
516 SLOT(newEventAllDay(int,int))); 512 SLOT(newEventAllDay(int,int)));
517 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 513 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
518 SLOT(newTimeSpanSelected(int,int,int,int))); 514 SLOT(newTimeSpanSelected(int,int,int,int)));
519 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 515 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
520 SLOT(newTimeSpanSelectedAllDay(int,int,int,int))); 516 SLOT(newTimeSpanSelectedAllDay(int,int,int,int)));
521 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 517 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
522 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 518 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
523 519
524 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 520 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
525 SIGNAL(editIncidenceSignal(Incidence *))); 521 SIGNAL(editIncidenceSignal(Incidence *)));
526 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 522 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
527 SIGNAL(editIncidenceSignal(Incidence *))); 523 SIGNAL(editIncidenceSignal(Incidence *)));
528 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 524 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
529 SIGNAL(showIncidenceSignal(Incidence *))); 525 SIGNAL(showIncidenceSignal(Incidence *)));
530 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 526 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
531 SIGNAL(showIncidenceSignal(Incidence *))); 527 SIGNAL(showIncidenceSignal(Incidence *)));
532 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 528 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
533 SIGNAL(deleteIncidenceSignal(Incidence *))); 529 SIGNAL(deleteIncidenceSignal(Incidence *)));
534 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 530 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
535 SIGNAL(deleteIncidenceSignal(Incidence *))); 531 SIGNAL(deleteIncidenceSignal(Incidence *)));
536 532
537 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 533 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
538 SLOT(updateEventDates(KOAgendaItem *, int ))); 534 SLOT(updateEventDates(KOAgendaItem *, int )));
539 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 535 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
540 SLOT(updateEventDates(KOAgendaItem *, int))); 536 SLOT(updateEventDates(KOAgendaItem *, int)));
541 537
542 // event indicator update 538 // event indicator update
543 connect(mAgenda,SIGNAL(lowerYChanged(int)), 539 connect(mAgenda,SIGNAL(lowerYChanged(int)),
544 SLOT(updateEventIndicatorTop(int))); 540 SLOT(updateEventIndicatorTop(int)));
545 connect(mAgenda,SIGNAL(upperYChanged(int)), 541 connect(mAgenda,SIGNAL(upperYChanged(int)),
546 SLOT(updateEventIndicatorBottom(int))); 542 SLOT(updateEventIndicatorBottom(int)));
547 // drag signals 543 // drag signals
548 /* 544 /*
549 connect(mAgenda,SIGNAL(startDragSignal(Event *)), 545 connect(mAgenda,SIGNAL(startDragSignal(Event *)),
550 SLOT(startDrag(Event *))); 546 SLOT(startDrag(Event *)));
551 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)), 547 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)),
552 SLOT(startDrag(Event *))); 548 SLOT(startDrag(Event *)));
553 */ 549 */
554 // synchronize selections 550 // synchronize selections
555 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 551 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
556 mAllDayAgenda, SLOT( deselectItem() ) ); 552 mAllDayAgenda, SLOT( deselectItem() ) );
557 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 553 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
558 mAgenda, SLOT( deselectItem() ) ); 554 mAgenda, SLOT( deselectItem() ) );
559 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 555 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
560 SIGNAL( incidenceSelected( Incidence * ) ) ); 556 SIGNAL( incidenceSelected( Incidence * ) ) );
561 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 557 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
562 SIGNAL( incidenceSelected( Incidence * ) ) ); 558 SIGNAL( incidenceSelected( Incidence * ) ) );
563 connect( mAgenda, SIGNAL( resizedSignal() ), 559 connect( mAgenda, SIGNAL( resizedSignal() ),
564 SLOT( updateConfig( ) ) ); 560 SLOT( updateConfig( ) ) );
565 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ), 561 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ),
566 SLOT( addToCalSlot(Incidence *, Incidence * ) ) ); 562 SLOT( addToCalSlot(Incidence *, Incidence * ) ) );
567 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ), 563 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ),
568 SLOT( addToCalSlot(Incidence * , Incidence *) ) ); 564 SLOT( addToCalSlot(Incidence * , Incidence *) ) );
569 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 565 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
570 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 566 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
571 567
572 568
573} 569}
574 570
575void KOAgendaView::toggleAllDay() 571void KOAgendaView::toggleAllDay()
576{ 572{
577 if ( mSplitterAgenda->firstHandle() ) 573 if ( mSplitterAgenda->firstHandle() )
578 mSplitterAgenda->firstHandle()->toggle(); 574 mSplitterAgenda->firstHandle()->toggle();
579} 575}
580void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld ) 576void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld )
581{ 577{
582 calendar()->addIncidence( inc ); 578 calendar()->addIncidence( inc );
583 579
584 if ( incOld ) { 580 if ( incOld ) {
585 if ( incOld->type() == "Todo" ) 581 if ( incOld->type() == "Todo" )
586 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED ); 582 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED );
587 else 583 else
588 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED); 584 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED);
589 } 585 }
590 586
591} 587}
592 588
593KOAgendaView::~KOAgendaView() 589KOAgendaView::~KOAgendaView()
594{ 590{
595 delete mAgendaPopup; 591 delete mAgendaPopup;
596 delete mAllDayAgendaPopup; 592 delete mAllDayAgendaPopup;
597 delete KOAgendaItem::paintPix(); 593 delete KOAgendaItem::paintPix();
598 delete KOAgendaItem::paintPixSel(); 594 delete KOAgendaItem::paintPixSel();
599} 595}
600void KOAgendaView::resizeEvent( QResizeEvent* e ) 596void KOAgendaView::resizeEvent( QResizeEvent* e )
601{ 597{
602 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); 598 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width());
603 bool uc = false; 599 bool uc = false;
604 int ow = e->oldSize().width(); 600 int ow = e->oldSize().width();
605 int oh = e->oldSize().height(); 601 int oh = e->oldSize().height();
606 int w = e->size().width(); 602 int w = e->size().width();
607 int h = e->size().height(); 603 int h = e->size().height();
608 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { 604 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) {
609 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) 605 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda )
610 uc = true; 606 uc = true;
611 //qDebug("view changed %d %d %d %d ", ow, oh , w , h); 607 //qDebug("view changed %d %d %d %d ", ow, oh , w , h);
612 } 608 }
613 mUpcomingWidth = e->size().width() ; 609 mUpcomingWidth = e->size().width() ;
614 if ( mBlockUpdating || uc ) { 610 if ( mBlockUpdating || uc ) {
615 mBlockUpdating = false; 611 mBlockUpdating = false;
616 //mAgenda->setMinimumSize(800 , 600 ); 612 //mAgenda->setMinimumSize(800 , 600 );
617 //qDebug("mAgenda->resize+++++++++++++++ "); 613 //qDebug("mAgenda->resize+++++++++++++++ ");
618 updateConfig(); 614 updateConfig();
619 //qDebug("KOAgendaView::Updating now possible "); 615 //qDebug("KOAgendaView::Updating now possible ");
620 } else 616 } else
621 createDayLabels(); 617 createDayLabels();
622 //qDebug("resizeEvent end "); 618 //qDebug("resizeEvent end ");
623 619
624} 620}
625void KOAgendaView::slotDaylabelClicked( int num ) 621void KOAgendaView::slotDaylabelClicked( int num )
626{ 622{
627 623
628 QDate firstDate = mSelectedDates.first(); 624 QDate firstDate = mSelectedDates.first();
629 if ( num == -1 ) 625 if ( num == -1 )
630 emit showDateView( 6, firstDate ); 626 emit showDateView( 6, firstDate );
631 else if (num >= 0 ) { 627 else if (num >= 0 ) {
632 if ( mSelectedDates.count() == 1) 628 if ( mSelectedDates.count() == 1)
633 emit showDateView( 9, firstDate.addDays( num ) ); 629 emit showDateView( 9, firstDate.addDays( num ) );
634 else 630 else
635 emit showDateView( 3, firstDate.addDays( num ) ); 631 emit showDateView( 3, firstDate.addDays( num ) );
636 } 632 }
637 else 633 else
638 showDateView( 10, firstDate.addDays(1) ); 634 showDateView( 10, firstDate.addDays(1) );
639} 635}
640 636
641KOAgendaButton* KOAgendaView::getNewDaylabel() 637KOAgendaButton* KOAgendaView::getNewDaylabel()
642{ 638{
643 639
644 KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels); 640 KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels);
645 connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) ); 641 connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) );
646 mDayLabelsList.append( dayLabel ); 642 mDayLabelsList.append( dayLabel );
647 mLayoutDayLabels->addWidget(dayLabel); 643 mLayoutDayLabels->addWidget(dayLabel);
648 return dayLabel ; 644 return dayLabel ;
649} 645}
650 646
651void KOAgendaView::createDayLabels() 647void KOAgendaView::createDayLabels()
652{ 648{
653 649
654 if ( mBlockUpdating || globalFlagBlockLabel == 1) { 650 if ( mBlockUpdating || globalFlagBlockLabel == 1) {
655 // qDebug(" KOAgendaView::createDayLabels() blocked "); 651 // qDebug(" KOAgendaView::createDayLabels() blocked ");
656 return; 652 return;
657 653
658 } 654 }
659 int newHight; 655 int newHight;
660 656
661 // ### Before deleting and recreating we could check if mSelectedDates changed... 657 // ### Before deleting and recreating we could check if mSelectedDates changed...
662 // It would remove some flickering and gain speed (since this is called by 658 // It would remove some flickering and gain speed (since this is called by
663 // each updateView() call) 659 // each updateView() call)
664 660
665 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - 2; 661 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - 2;
666 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); 662 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth );
667 if ( maxWid < 0 ) 663 if ( maxWid < 0 )
668 maxWid = 20; 664 maxWid = 20;
669 665
670 QFont dlf = KOPrefs::instance()->mTimeLabelsFont; 666 QFont dlf = KOPrefs::instance()->mTimeLabelsFont;
671 QFontMetrics fm ( dlf ); 667 QFontMetrics fm ( dlf );
672 int selCount = mSelectedDates.count(); 668 int selCount = mSelectedDates.count();
673 QString dayTest = "Mon 20"; 669 QString dayTest = "Mon 20";
674 //QString dayTest = "Mon 20"; 670 //QString dayTest = "Mon 20";
675 int wid = fm.width( dayTest ); 671 int wid = fm.width( dayTest );
676 //maxWid -= ( selCount * 3 ); //working for QLabels 672 //maxWid -= ( selCount * 3 ); //working for QLabels
677 maxWid -= ( selCount * 3 ); //working for QPushButton 673 maxWid -= ( selCount * 3 ); //working for QPushButton
678 if ( maxWid < 0 ) 674 if ( maxWid < 0 )
679 maxWid = 20; 675 maxWid = 20;
680 int needWid = wid * selCount; 676 int needWid = wid * selCount;
681 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); 677 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid );
682 //if ( needWid > maxWid ) 678 //if ( needWid > maxWid )
683 // qDebug("DAYLABELS TOOOOOOO BIG "); 679 // qDebug("DAYLABELS TOOOOOOO BIG ");
684 while ( needWid > maxWid ) { 680 while ( needWid > maxWid ) {
685 dayTest = dayTest.left( dayTest.length() - 1 ); 681 dayTest = dayTest.left( dayTest.length() - 1 );
686 wid = fm.width( dayTest ); 682 wid = fm.width( dayTest );
687 needWid = wid * selCount; 683 needWid = wid * selCount;
688 } 684 }
689 int maxLen = dayTest.length(); 685 int maxLen = dayTest.length();
690 int fontPoint = dlf.pointSize(); 686 int fontPoint = dlf.pointSize();
691 if ( maxLen < 2 ) { 687 if ( maxLen < 2 ) {
692 int fontPoint = dlf.pointSize(); 688 int fontPoint = dlf.pointSize();
693 while ( fontPoint > 4 ) { 689 while ( fontPoint > 4 ) {
694 --fontPoint; 690 --fontPoint;
695 dlf.setPointSize( fontPoint ); 691 dlf.setPointSize( fontPoint );
696 QFontMetrics f( dlf ); 692 QFontMetrics f( dlf );
697 wid = f.width( "30" ); 693 wid = f.width( "30" );
698 needWid = wid * selCount; 694 needWid = wid * selCount;
699 if ( needWid < maxWid ) 695 if ( needWid < maxWid )
700 break; 696 break;
701 } 697 }
702 maxLen = 2; 698 maxLen = 2;
703 } 699 }
704 //qDebug("Max len %d ", dayTest.length() ); 700 //qDebug("Max len %d ", dayTest.length() );
705 701
706 QFontMetrics tempF( dlf ); 702 QFontMetrics tempF( dlf );
707 newHight = tempF.height(); 703 newHight = tempF.height();
708 mDayLabels->setFont( dlf ); 704 mDayLabels->setFont( dlf );
709 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; 705 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);;
710 // mLayoutDayLabels->addSpacing(mTimeLabels->width()); 706 // mLayoutDayLabels->addSpacing(mTimeLabels->width());
711 //mLayoutDayLabels->addSpacing( 2 ); 707 //mLayoutDayLabels->addSpacing( 2 );
712 // QFont lFont = dlf; 708 // QFont lFont = dlf;
713 bool appendLabels = false; 709 bool appendLabels = false;
714 KOAgendaButton *dayLabel; 710 KOAgendaButton *dayLabel;
715 dayLabel = mDayLabelsList.first(); 711 dayLabel = mDayLabelsList.first();
716 if ( !dayLabel ) { 712 if ( !dayLabel ) {
717 appendLabels = true; 713 appendLabels = true;
718 dayLabel = getNewDaylabel(); 714 dayLabel = getNewDaylabel();
719 } 715 }
720 dayLabel->setFixedWidth( mTimeLabels->width()+mAgenda->frameWidth() ); 716 dayLabel->setFixedWidth( mTimeLabels->width()+mAgenda->frameWidth() );
721 dayLabel->setFont( dlf ); 717 dayLabel->setFont( dlf );
722 dayLabel->setNum( -1 ); 718 dayLabel->setNum( -1 );
723 //dayLabel->setAlignment(QLabel::AlignHCenter); 719 //dayLabel->setAlignment(QLabel::AlignHCenter);
724 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); 720 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) );
725 dayLabel->show(); 721 dayLabel->show();
726 DateList::ConstIterator dit; 722 DateList::ConstIterator dit;
727 bool oneday = (mSelectedDates.first() == mSelectedDates.last() ); 723 bool oneday = (mSelectedDates.first() == mSelectedDates.last() );
728 int counter = -1; 724 int counter = -1;
729 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 725 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
730 ++counter; 726 ++counter;
731 QDate date = *dit; 727 QDate date = *dit;
732 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); 728 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels);
733 if ( ! appendLabels ) { 729 if ( ! appendLabels ) {
734 dayLabel = mDayLabelsList.next(); 730 dayLabel = mDayLabelsList.next();
735 if ( !dayLabel ) 731 if ( !dayLabel )
736 appendLabels = true; 732 appendLabels = true;
737 } 733 }
738 if ( appendLabels ) { 734 if ( appendLabels ) {
739 dayLabel = getNewDaylabel(); 735 dayLabel = getNewDaylabel();
740 } 736 }
741 dayLabel->setMinimumWidth( 1 ); 737 dayLabel->setMinimumWidth( 1 );
742 dayLabel->setMaximumWidth( 10240 ); 738 dayLabel->setMaximumWidth( 10240 );
743 dayLabel->setFont( dlf ); 739 dayLabel->setFont( dlf );
744 dayLabel->show(); 740 dayLabel->show();
745 dayLabel->setAutoRepeat( false ); 741 dayLabel->setAutoRepeat( false );
746 dayLabel->setNum( counter ); 742 dayLabel->setNum( counter );
747 QString str; 743 QString str;
748 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date); 744 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date);
749 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true ); 745 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true );
750 switch ( maxLen ) { 746 switch ( maxLen ) {
751 case 2: 747 case 2:
752 str = QString::number( date.day() ); 748 str = QString::number( date.day() );
753 break; 749 break;
754 750
755 case 3: 751 case 3:
756 str = dayName.left( 1 ) +QString::number( date.day()); 752 str = dayName.left( 1 ) +QString::number( date.day());
757 753
758 break; 754 break;
759 case 4: 755 case 4:
760 str = dayName.left( 1 ) + " " +QString::number( date.day()); 756 str = dayName.left( 1 ) + " " +QString::number( date.day());
761 757
762 break; 758 break;
763 case 5: 759 case 5:
764 str = dayName.left( 2 ) + " " +QString::number( date.day()); 760 str = dayName.left( 2 ) + " " +QString::number( date.day());
765 761
766 break; 762 break;
767 case 6: 763 case 6:
768 str = dayName.left( 3 ) + " " +QString::number( date.day()); 764 str = dayName.left( 3 ) + " " +QString::number( date.day());
769 break; 765 break;
770 766
771 default: 767 default:
772 break; 768 break;
773 } 769 }
774 if ( oneday ) { 770 if ( oneday ) {
775 QString addString; 771 QString addString;
776 if ( mSelectedDates.first() == QDateTime::currentDateTime().date() ) 772 if ( mSelectedDates.first() == QDateTime::currentDateTime().date() )
777 addString = i18n("Today"); 773 addString = i18n("Today");
778 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) 774 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) )
779 addString = i18n("Tomorrow"); 775 addString = i18n("Tomorrow");
780 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) 776 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) )
781 addString = i18n("Yesterday"); 777 addString = i18n("Yesterday");
782 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) 778 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) )
783 addString = i18n("Day before yesterday"); 779 addString = i18n("Day before yesterday");
784 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) 780 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) )
785 addString = i18n("Day after tomorrow"); 781 addString = i18n("Day after tomorrow");
786 if ( !addString.isEmpty() ) { 782 if ( !addString.isEmpty() ) {
787 str = addString+", " + str; 783 str = addString+", " + str;
788 } else { 784 } else {
789 str = KGlobal::locale()->formatDate( date, KOPrefs::instance()->mShortDateInViewer); 785 str = KGlobal::locale()->formatDate( date, KOPrefs::instance()->mShortDateInViewer);
790 } 786 }
791 } 787 }
792 dayLabel->setText(str); 788 dayLabel->setText(str);
793 //dayLabel->setAlignment(QLabel::AlignHCenter); 789 //dayLabel->setAlignment(QLabel::AlignHCenter);
794 if (date == QDate::currentDate()) { 790 if (date == QDate::currentDate()) {
795 QFont bFont = dlf; 791 QFont bFont = dlf;
796 bFont.setBold( true ); 792 bFont.setBold( true );
797 dayLabel->setFont(bFont); 793 dayLabel->setFont(bFont);
798 } 794 }
799 //dayLayout->addWidget(dayLabel); 795 //dayLayout->addWidget(dayLabel);
800 796
801#ifndef KORG_NOPLUGINS 797#ifndef KORG_NOPLUGINS
802 CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); 798 CalendarDecoration::List cds = KOCore::self()->calendarDecorations();
803 CalendarDecoration *it; 799 CalendarDecoration *it;
804 for(it = cds.first(); it; it = cds.next()) { 800 for(it = cds.first(); it; it = cds.next()) {
805 QString text = it->shortText( date ); 801 QString text = it->shortText( date );
806 if ( !text.isEmpty() ) { 802 if ( !text.isEmpty() ) {
807 QLabel *label = new QLabel(text,mDayLabels); 803 QLabel *label = new QLabel(text,mDayLabels);
808 label->setAlignment(AlignCenter); 804 label->setAlignment(AlignCenter);
809 dayLayout->addWidget(label); 805 dayLayout->addWidget(label);
810 } 806 }
811 } 807 }
812 808
813 for(it = cds.first(); it; it = cds.next()) { 809 for(it = cds.first(); it; it = cds.next()) {
814 QWidget *wid = it->smallWidget(mDayLabels,date); 810 QWidget *wid = it->smallWidget(mDayLabels,date);
815 if ( wid ) { 811 if ( wid ) {
816 // wid->setHeight(20); 812 // wid->setHeight(20);
817 dayLayout->addWidget(wid); 813 dayLayout->addWidget(wid);
818 } 814 }
819 } 815 }
820#endif 816#endif
821 } 817 }
822 if ( ! appendLabels ) { 818 if ( ! appendLabels ) {
823 dayLabel = mDayLabelsList.next(); 819 dayLabel = mDayLabelsList.next();
824 if ( !dayLabel ) 820 if ( !dayLabel )
825 appendLabels = true; 821 appendLabels = true;
826 } 822 }
827 if ( appendLabels ) { 823 if ( appendLabels ) {
828 dayLabel = getNewDaylabel(); 824 dayLabel = getNewDaylabel();
829 } 825 }
830 //dayLabel->hide();//test only 826 //dayLabel->hide();//test only
831 qDebug("fremwidd %d ", mAgenda->frameWidth()); 827 qDebug("fremwidd %d ", mAgenda->frameWidth());
832 int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()- (mAgenda->frameWidth()*2) ) % mSelectedDates.count() ; 828 int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()- (mAgenda->frameWidth()*2) ) % mSelectedDates.count() ;
833 if ( offset < 0 ) offset = 0; 829 if ( offset < 0 ) offset = 0;
834 //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 ); 830 //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 );
835 dayLabel->setText(">");//QString::number ( mSelectedDates.first().month() ) ); 831 dayLabel->setText(">");//QString::number ( mSelectedDates.first().month() ) );
836 dayLabel->setFont( dlf ); 832 dayLabel->setFont( dlf );
837 dayLabel->setAutoRepeat( true ); 833 dayLabel->setAutoRepeat( true );
838 dayLabel->show(); 834 dayLabel->show();
839 dayLabel->setNum( -2 ); 835 dayLabel->setNum( -2 );
840 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset ); 836 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset );
841 //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2); 837 //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2);
842 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); 838 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2);
843 if ( !appendLabels ) { 839 if ( !appendLabels ) {
844 dayLabel = mDayLabelsList.next(); 840 dayLabel = mDayLabelsList.next();
845 while ( dayLabel ) { 841 while ( dayLabel ) {
846 //qDebug("!dayLabel %d",dayLabel ); 842 //qDebug("!dayLabel %d",dayLabel );
847 dayLabel->hide(); 843 dayLabel->hide();
848 dayLabel = mDayLabelsList.next(); 844 dayLabel = mDayLabelsList.next();
849 } 845 }
850 } 846 }
851 847
852 mDayLabelsFrame->setFixedHeight( newHight + 4 ); 848 mDayLabelsFrame->setFixedHeight( newHight + 4 );
853} 849}
854 850
855int KOAgendaView::maxDatesHint() 851int KOAgendaView::maxDatesHint()
856{ 852{
857 // Not sure about the max number of events, so return 0 for now. 853 // Not sure about the max number of events, so return 0 for now.
858 return 0; 854 return 0;
859} 855}
860 856
861int KOAgendaView::currentDateCount() 857int KOAgendaView::currentDateCount()
862{ 858{
863 return mSelectedDates.count(); 859 return mSelectedDates.count();
864} 860}
865 861
866QPtrList<Incidence> KOAgendaView::selectedIncidences() 862QPtrList<Incidence> KOAgendaView::selectedIncidences()
867{ 863{
868 QPtrList<Incidence> selected; 864 QPtrList<Incidence> selected;
869 Incidence *incidence; 865 Incidence *incidence;
870 866
871 incidence = mAgenda->selectedIncidence(); 867 incidence = mAgenda->selectedIncidence();
872 if (incidence) selected.append(incidence); 868 if (incidence) selected.append(incidence);
873 869
874 incidence = mAllDayAgenda->selectedIncidence(); 870 incidence = mAllDayAgenda->selectedIncidence();
875 if (incidence) selected.append(incidence); 871 if (incidence) selected.append(incidence);
876 872
877 return selected; 873 return selected;
878} 874}
879 875
880DateList KOAgendaView::selectedDates() 876DateList KOAgendaView::selectedDates()
881{ 877{
882 DateList selected; 878 DateList selected;
883 QDate qd; 879 QDate qd;
884 880
885 qd = mAgenda->selectedIncidenceDate(); 881 qd = mAgenda->selectedIncidenceDate();
886 if (qd.isValid()) selected.append(qd); 882 if (qd.isValid()) selected.append(qd);
887 883
888 qd = mAllDayAgenda->selectedIncidenceDate(); 884 qd = mAllDayAgenda->selectedIncidenceDate();
889 if (qd.isValid()) selected.append(qd); 885 if (qd.isValid()) selected.append(qd);
890 886
891 return selected; 887 return selected;
892} 888}
893 889
894 890
895void KOAgendaView::updateView() 891void KOAgendaView::updateView()
896{ 892{
897 if ( mBlockUpdating ) 893 if ( mBlockUpdating )
898 return; 894 return;
899 // kdDebug() << "KOAgendaView::updateView()" << endl; 895 // kdDebug() << "KOAgendaView::updateView()" << endl;
900 fillAgenda(); 896 fillAgenda();
901 897
902} 898}
903 899
904 900
905/* 901/*
906 Update configuration settings for the agenda view. This method is not 902 Update configuration settings for the agenda view. This method is not
907 complete. 903 complete.
908*/ 904*/
909void KOAgendaView::updateConfig() 905void KOAgendaView::updateConfig()
910{ 906{
911 if ( mBlockUpdating ) 907 if ( mBlockUpdating )
912 return; 908 return;
913 if ( mAgenda->height() > 96 * KOPrefs::instance()->mHourSize ) { 909 if ( mAgenda->height() > 96 * KOPrefs::instance()->mHourSize ) {
914 int old = KOPrefs::instance()->mHourSize; 910 int old = KOPrefs::instance()->mHourSize;
915 KOPrefs::instance()->mHourSize = mAgenda->height()/96 +1; 911 KOPrefs::instance()->mHourSize = mAgenda->height()/96 +1;
916 qDebug("KOPrefs::instance()->mHourSize adjusted %d to %d ", old,KOPrefs::instance()->mHourSize ); 912 qDebug("KOPrefs::instance()->mHourSize adjusted %d to %d ", old,KOPrefs::instance()->mHourSize );
917 } 913 }
918 914
919 915
920 // update config for children 916 // update config for children
921 mTimeLabels->updateConfig(); 917 mTimeLabels->updateConfig();
922 mAgenda->storePosition(); 918 mAgenda->storePosition();
923 mAgenda->updateConfig(); 919 mAgenda->updateConfig();
924 mAllDayAgenda->updateConfig(); 920 mAllDayAgenda->updateConfig();
925 // widget synchronization 921 // widget synchronization
926 //TODO: find a better way, maybe signal/slot 922 //TODO: find a better way, maybe signal/slot
927 mTimeLabels->positionChanged(); 923 mTimeLabels->positionChanged();
928 924
929 // for some reason, this needs to be called explicitly 925 // for some reason, this needs to be called explicitly
930 mTimeLabels->repaint(); 926 mTimeLabels->repaint();
931 927
932 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 928 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
933 929
934 // ToolTips displaying summary of events 930 // ToolTips displaying summary of events
935 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance() 931 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance()
936 ->mEnableToolTips); 932 ->mEnableToolTips);
937 933
938 //setHolidayMasks(); 934 //setHolidayMasks();
939 935
940 //createDayLabels(); called by via updateView(); 936 //createDayLabels(); called by via updateView();
941 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth()); 937 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth());
942 updateView(); 938 updateView();
943 mAgenda->restorePosition(); 939 mAgenda->restorePosition();
944} 940}
945 941
946 942
947void KOAgendaView::updateEventDates(KOAgendaItem *item, int type) 943void KOAgendaView::updateEventDates(KOAgendaItem *item, int type)
948{ 944{
949 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl; 945 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl;
950 //qDebug("KOAgendaView::updateEventDates "); 946 //qDebug("KOAgendaView::updateEventDates ");
951 QDateTime startDt,endDt; 947 QDateTime startDt,endDt;
952 QDate startDate; 948 QDate startDate;
953 int lenInSecs; 949 int lenInSecs;
954 // if ( type == KOAgenda::RESIZETOP ) 950 // if ( type == KOAgenda::RESIZETOP )
955 // qDebug("RESIZETOP "); 951 // qDebug("RESIZETOP ");
956 // if ( type == KOAgenda::RESIZEBOTTOM ) 952 // if ( type == KOAgenda::RESIZEBOTTOM )
957 // qDebug("RESIZEBOTTOM "); 953 // qDebug("RESIZEBOTTOM ");
958 // if ( type == KOAgenda::MOVE ) 954 // if ( type == KOAgenda::MOVE )
959 // qDebug("MOVE "); 955 // qDebug("MOVE ");
960 if ( item->incidence()->type() == "Event" ) { 956 if ( item->incidence()->type() == "Event" ) {
961 startDt =item->incidence()->dtStart(); 957 startDt =item->incidence()->dtStart();
962 endDt = item->incidence()->dtEnd(); 958 endDt = item->incidence()->dtEnd();
963 lenInSecs = startDt.secsTo( endDt ); 959 lenInSecs = startDt.secsTo( endDt );
964 } 960 }
965 961
966 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED ); 962 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED );
967 963
968 if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) { 964 if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) {
969 startDate = mSelectedDates[item->mLastMoveXPos]; 965 startDate = mSelectedDates[item->mLastMoveXPos];
970 } else { 966 } else {
971 if (item->cellX() < 0) { 967 if (item->cellX() < 0) {
972 startDate = (mSelectedDates.first()).addDays(item->cellX()); 968 startDate = (mSelectedDates.first()).addDays(item->cellX());
973 } else { 969 } else {
974 startDate = mSelectedDates[item->cellX()]; 970 startDate = mSelectedDates[item->cellX()];
975 } 971 }
976 } 972 }
977 startDt.setDate(startDate); 973 startDt.setDate(startDate);
978 974
979 if (item->incidence()->doesFloat()) { 975 if (item->incidence()->doesFloat()) {
980 endDt.setDate(startDate.addDays(item->cellWidth() - 1)); 976 endDt.setDate(startDate.addDays(item->cellWidth() - 1));
981 } else { 977 } else {
982 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE ) 978 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE )
983 startDt.setTime(mAgenda->gyToTime(item->cellYTop())); 979 startDt.setTime(mAgenda->gyToTime(item->cellYTop()));
984 if ( item->incidence()->type() == "Event" ) { 980 if ( item->incidence()->type() == "Event" ) {
985 if ( type == KOAgenda::MOVE ) { 981 if ( type == KOAgenda::MOVE ) {
986 endDt = startDt.addSecs(lenInSecs); 982 endDt = startDt.addSecs(lenInSecs);
987 983
988 } else if ( type == KOAgenda::RESIZEBOTTOM ) { 984 } else if ( type == KOAgenda::RESIZEBOTTOM ) {
989 if (item->lastMultiItem()) { 985 if (item->lastMultiItem()) {
990 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 986 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
991 endDt.setDate(startDate. 987 endDt.setDate(startDate.
992 addDays(item->lastMultiItem()->cellX() - item->cellX())); 988 addDays(item->lastMultiItem()->cellX() - item->cellX()));
993 } else { 989 } else {
994 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 990 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
995 endDt.setDate(startDate); 991 endDt.setDate(startDate);
996 } 992 }
997 } 993 }
998 } else { 994 } else {
999 // todo 995 // todo
1000 if (item->lastMultiItem()) { 996 if (item->lastMultiItem()) {
1001 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 997 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
1002 endDt.setDate(startDate. 998 endDt.setDate(startDate.
1003 addDays(item->lastMultiItem()->cellX() - item->cellX())); 999 addDays(item->lastMultiItem()->cellX() - item->cellX()));
1004 } else { 1000 } else {
1005 //qDebug("tem->cellYBottom() %d",item->cellYBottom() ); 1001 //qDebug("tem->cellYBottom() %d",item->cellYBottom() );
1006 if ( item->cellYBottom() > 0 ) 1002 if ( item->cellYBottom() > 0 )
1007 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 1003 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
1008 else 1004 else
1009 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time()); 1005 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time());
1010 endDt.setDate(startDate); 1006 endDt.setDate(startDate);
1011 } 1007 }
1012 } 1008 }
1013 } 1009 }
1014 if ( item->incidence()->type() == "Event" ) { 1010 if ( item->incidence()->type() == "Event" ) {
1015 item->incidence()->setDtStart(startDt); 1011 item->incidence()->setDtStart(startDt);
1016 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt); 1012 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt);
1017 } else if ( item->incidence()->type() == "Todo" ) { 1013 } else if ( item->incidence()->type() == "Todo" ) {
1018 Todo* to = static_cast<Todo*>(item->incidence()); 1014 Todo* to = static_cast<Todo*>(item->incidence());
1019 1015
1020 to->setDtDue(endDt); 1016 to->setDtDue(endDt);
1021 if ( to->hasStartDate() ) { 1017 if ( to->hasStartDate() ) {
1022 if (to->dtStart() >= to->dtDue() ) 1018 if (to->dtStart() >= to->dtDue() )
1023 to->setDtStart(to->dtDue().addDays( -2 )); 1019 to->setDtStart(to->dtDue().addDays( -2 ));
1024 } 1020 }
1025 1021
1026 } 1022 }
1027 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() ); 1023 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() );
1028 item->incidence()->setRevision(item->incidence()->revision()+1); 1024 item->incidence()->setRevision(item->incidence()->revision()+1);
1029 item->setItemDate(startDt.date()); 1025 item->setItemDate(startDt.date());
1030 //item->updateItem(); 1026 //item->updateItem();
1031 if ( item->incidence()->type() == "Todo" ) { 1027 if ( item->incidence()->type() == "Todo" ) {
1032 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED ); 1028 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED );
1033 1029
1034 } 1030 }
1035 else 1031 else
1036 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED); 1032 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED);
1037 item->updateItem(); 1033 item->updateItem();
1038} 1034}
1039 1035
1040void KOAgendaView::showDates( const QDate &start, const QDate &end ) 1036void KOAgendaView::showDates( const QDate &start, const QDate &end )
1041{ 1037{
1042 // kdDebug() << "KOAgendaView::selectDates" << endl; 1038 // kdDebug() << "KOAgendaView::selectDates" << endl;
1043 1039
1044 mSelectedDates.clear(); 1040 mSelectedDates.clear();
1045 // qDebug("KOAgendaView::showDates "); 1041 // qDebug("KOAgendaView::showDates ");
1046 QDate d = start; 1042 QDate d = start;
1047 while (d <= end) { 1043 while (d <= end) {
1048 mSelectedDates.append(d); 1044 mSelectedDates.append(d);
1049 d = d.addDays( 1 ); 1045 d = d.addDays( 1 );
1050 } 1046 }
1051 1047
1052 // and update the view 1048 // and update the view
1053 fillAgenda(); 1049 fillAgenda();
1054} 1050}
1055 1051
1056 1052
1057void KOAgendaView::showEvents(QPtrList<Event>) 1053void KOAgendaView::showEvents(QPtrList<Event>)
1058{ 1054{
1059 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl; 1055 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl;
1060} 1056}
1061 1057
1062void KOAgendaView::changeEventDisplay(Event *, int) 1058void KOAgendaView::changeEventDisplay(Event *, int)
1063{ 1059{
1064 // qDebug("KOAgendaView::changeEventDisplay "); 1060 // qDebug("KOAgendaView::changeEventDisplay ");
1065 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl; 1061 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl;
1066 // this should be re-written to be MUCH smarter. Right now we 1062 // this should be re-written to be MUCH smarter. Right now we
1067 // are just playing dumb. 1063 // are just playing dumb.
1068 fillAgenda(); 1064 fillAgenda();
1069} 1065}
1070 1066
1071void KOAgendaView::fillAgenda(const QDate &) 1067void KOAgendaView::fillAgenda(const QDate &)
1072{ 1068{
1073 // qDebug("KOAgendaView::fillAgenda "); 1069 // qDebug("KOAgendaView::fillAgenda ");
1074 fillAgenda(); 1070 fillAgenda();
1075} 1071}
1076 1072
1077void KOAgendaView::fillAgenda() 1073void KOAgendaView::fillAgenda()
1078{ 1074{
1079 if ( globalFlagBlockStartup ) 1075 if ( globalFlagBlockStartup )
1080 return; 1076 return;
1081 if ( globalFlagBlockAgenda == 1 ) 1077 if ( globalFlagBlockAgenda == 1 )
1082 return; 1078 return;
1083 static bool onlyOne = false; 1079 static bool onlyOne = false;
1084 if ( onlyOne ) 1080 if ( onlyOne )
1085 return; 1081 return;
1086 onlyOne = true; 1082 onlyOne = true;
1087 //if ( globalFlagBlockAgenda == 2 ) 1083 //if ( globalFlagBlockAgenda == 2 )
1088 //globalFlagBlockAgenda = 0; 1084 //globalFlagBlockAgenda = 0;
1089 // globalFlagBlockPainting = false; 1085 // globalFlagBlockPainting = false;
1090 if ( globalFlagBlockAgenda == 0 ) 1086 if ( globalFlagBlockAgenda == 0 )
1091 globalFlagBlockAgenda = 1; 1087 globalFlagBlockAgenda = 1;
1092 // clearView(); 1088 // clearView();
1093 //qDebug("fillAgenda()++++ "); 1089 //qDebug("fillAgenda()++++ ");
1094 globalFlagBlockAgendaItemPaint = 1; 1090 globalFlagBlockAgendaItemPaint = 1;
1095 1091
1096 mAllDayAgenda->changeColumns(mSelectedDates.count()); 1092 mAllDayAgenda->changeColumns(mSelectedDates.count());
1097 mAgenda->changeColumns(mSelectedDates.count()); 1093 mAgenda->changeColumns(mSelectedDates.count());
1098 qApp->processEvents(); 1094 qApp->processEvents();
1099 mEventIndicatorTop->changeColumns(mSelectedDates.count()); 1095 mEventIndicatorTop->changeColumns(mSelectedDates.count());
1100 mEventIndicatorBottom->changeColumns(mSelectedDates.count()); 1096 mEventIndicatorBottom->changeColumns(mSelectedDates.count());
1101 setHolidayMasks(); 1097 setHolidayMasks();
1102 1098
1103 //mAgenda->hideUnused(); 1099 //mAgenda->hideUnused();
1104 //mAllDayAgenda->hideUnused(); 1100 //mAllDayAgenda->hideUnused();
1105 1101
1106 // mAgenda->blockNextRepaint( false ); 1102 // mAgenda->blockNextRepaint( false );
1107 // mAgenda->viewport()->repaint(); 1103 // mAgenda->viewport()->repaint();
1108 // mAgenda->blockNextRepaint( true ); 1104 // mAgenda->blockNextRepaint( true );
1109 mMinY.resize(mSelectedDates.count()); 1105 mMinY.resize(mSelectedDates.count());
1110 mMaxY.resize(mSelectedDates.count()); 1106 mMaxY.resize(mSelectedDates.count());
1111 1107
1112 QPtrList<Event> dayEvents; 1108 QPtrList<Event> dayEvents;
1113 1109
1114 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 1110 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
1115 // Therefore, gtodoset all of them. 1111 // Therefore, gtodoset all of them.
1116 QPtrList<Todo> todos = calendar()->todos(); 1112 QPtrList<Todo> todos = calendar()->todos();
1117 1113
1118 mAgenda->setDateList(mSelectedDates); 1114 mAgenda->setDateList(mSelectedDates);
1119 1115
1120 QDate today = QDate::currentDate(); 1116 QDate today = QDate::currentDate();
1121 1117
1122 DateList::ConstIterator dit; 1118 DateList::ConstIterator dit;
1123 int curCol = 0; 1119 int curCol = 0;
1124 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 1120 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
1125 QDate currentDate = *dit; 1121 QDate currentDate = *dit;
1126 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString() 1122 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString()
1127 // << endl; 1123 // << endl;
1128 1124
1129 dayEvents = calendar()->events(currentDate,true); 1125 dayEvents = calendar()->events(currentDate,true);
1130 1126
1131 // Default values, which can never be reached 1127 // Default values, which can never be reached
1132 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1; 1128 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1;
1133 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1; 1129 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1;
1134 1130
1135 unsigned int numEvent; 1131 unsigned int numEvent;
1136 for(numEvent=0;numEvent<dayEvents.count();++numEvent) { 1132 for(numEvent=0;numEvent<dayEvents.count();++numEvent) {
1137 Event *event = dayEvents.at(numEvent); 1133 Event *event = dayEvents.at(numEvent);
1138 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") ) 1134 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") )
1139 if ( event->uid().left(15) == QString("last-syncEvent-") ) 1135 if ( event->uid().left(15) == QString("last-syncEvent-") )
1140 continue; 1136 continue;
1141 // kdDebug() << " Event: " << event->summary() << endl; 1137 // kdDebug() << " Event: " << event->summary() << endl;
1142 1138
1143 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol; 1139 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol;
1144 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol; 1140 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol;
1145 1141
1146 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl; 1142 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl;
1147 1143
1148 if (event->doesFloat()) { 1144 if (event->doesFloat()) {
1149 if (event->recurrence()->doesRecur()) { 1145 if (event->recurrence()->doesRecur()) {
1150 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol); 1146 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol);
1151 } else { 1147 } else {
1152 if (beginX <= 0 && curCol == 0) { 1148 if (beginX <= 0 && curCol == 0) {
1153 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1149 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1154 } else if (beginX == curCol) { 1150 } else if (beginX == curCol) {
1155 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1151 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1156 } 1152 }
1157 } 1153 }
1158 } else if (event->isMultiDay()) { 1154 } else if (event->isMultiDay()) {
1159 if ( event->doesRecur () ) { 1155 if ( event->doesRecur () ) {
1160 QDate dateit = currentDate; 1156 QDate dateit = currentDate;
1161 int count = 0; 1157 int count = 0;
1162 int max = event->dtStart().daysTo( event->dtEnd() ) +2; 1158 int max = event->dtStart().daysTo( event->dtEnd() ) +2;
1163 while (! event->recursOn( dateit ) && count <= max ) { 1159 while (! event->recursOn( dateit ) && count <= max ) {
1164 ++count; 1160 ++count;
1165 dateit = dateit.addDays( -1 ); 1161 dateit = dateit.addDays( -1 );
1166 } 1162 }
1167 bool ok; 1163 bool ok;
1168 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok ); 1164 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok );
1169 if ( ok ) 1165 if ( ok )
1170 { 1166 {
1171 int secs = event->dtStart().secsTo( event->dtEnd() ); 1167 int secs = event->dtStart().secsTo( event->dtEnd() );
1172 QDateTime nextOcend =nextOcstart.addSecs( secs ); ; 1168 QDateTime nextOcend =nextOcstart.addSecs( secs ); ;
1173 beginX = currentDate.daysTo(nextOcstart.date()) + curCol; 1169 beginX = currentDate.daysTo(nextOcstart.date()) + curCol;
1174 endX = currentDate.daysTo(nextOcend.date()) + curCol; 1170 endX = currentDate.daysTo(nextOcend.date()) + curCol;
1175 1171
1176 } 1172 }
1177 } 1173 }
1178 int startY = mAgenda->timeToY(event->dtStart().time()); 1174 int startY = mAgenda->timeToY(event->dtStart().time());
1179 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1175 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1180 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol ); 1176 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol );
1181 if ((beginX <= 0 && curCol == 0) || beginX == curCol) { 1177 if ((beginX <= 0 && curCol == 0) || beginX == curCol) {
1182 //qDebug("insert!!! "); 1178 //qDebug("insert!!! ");
1183 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY); 1179 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY);
1184 } 1180 }
1185 if (beginX == curCol) { 1181 if (beginX == curCol) {
1186 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1182 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1187 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1183 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1188 } else if (endX == curCol) { 1184 } else if (endX == curCol) {
1189 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1185 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1190 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1186 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1191 } else { 1187 } else {
1192 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1188 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1193 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1189 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1194 } 1190 }
1195 } else { 1191 } else {
1196 int startY = mAgenda->timeToY(event->dtStart().time()); 1192 int startY = mAgenda->timeToY(event->dtStart().time());
1197 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1193 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1198 if (endY < startY) endY = startY; 1194 if (endY < startY) endY = startY;
1199 mAgenda->insertItem(event,currentDate,curCol,startY,endY); 1195 mAgenda->insertItem(event,currentDate,curCol,startY,endY);
1200 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1196 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1201 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1197 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1202 } 1198 }
1203 } 1199 }
1204 // ---------- [display Todos -------------- 1200 // ---------- [display Todos --------------
1205 unsigned int numTodo; 1201 unsigned int numTodo;
1206 for (numTodo = 0; numTodo < todos.count(); ++numTodo) { 1202 for (numTodo = 0; numTodo < todos.count(); ++numTodo) {
1207 Todo *todo = todos.at(numTodo); 1203 Todo *todo = todos.at(numTodo);
1208 1204
1209 if ( ! todo->hasDueDate() && !todo->hasCompletedDate()) continue; // todo shall not be displayed if it has no date 1205 if ( ! todo->hasDueDate() && !todo->hasCompletedDate()) continue; // todo shall not be displayed if it has no date
1210 1206
1211 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 1207 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
1212 // Already completed items can be displayed on their original due date 1208 // Already completed items can be displayed on their original due date
1213 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda 1209 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda
1214 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda; 1210 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda;
1215 bool fillIn = false; 1211 bool fillIn = false;
1216 if ( todo->hasCompletedDate() && todo->completed().date() == currentDate ) 1212 if ( todo->hasCompletedDate() && todo->completed().date() == currentDate )
1217 fillIn = true; 1213 fillIn = true;
1218 if ( ! fillIn && !todo->hasCompletedDate() ) 1214 if ( ! fillIn && !todo->hasCompletedDate() )
1219 fillIn = ((todo->dtDue().date() == currentDate) && !overdue) || ((currentDate == today) && overdue); 1215 fillIn = ((todo->dtDue().date() == currentDate) && !overdue) || ((currentDate == today) && overdue);
1220 if ( fillIn ) { 1216 if ( fillIn ) {
1221 if ( (todo->doesFloat() || overdue ) && !todo->hasCompletedDate() ) { // Todo has no due-time set or is already overdue 1217 if ( (todo->doesFloat() || overdue ) && !todo->hasCompletedDate() ) { // Todo has no due-time set or is already overdue
1222 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1218 if ( KOPrefs::instance()->mShowTodoInAgenda )
1223 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol); 1219 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol);
1224 } 1220 }
1225 else { 1221 else {
1226 QDateTime dt; 1222 QDateTime dt;
1227 if ( todo->hasCompletedDate() ) 1223 if ( todo->hasCompletedDate() )
1228 dt = todo->completed(); 1224 dt = todo->completed();
1229 else 1225 else
1230 dt = todo->dtDue();; 1226 dt = todo->dtDue();;
1231 1227
1232 1228
1233 int endY = mAgenda->timeToY(dt.time()) - 1; 1229 int endY = mAgenda->timeToY(dt.time()) - 1;
1234 int hi = (18/KOPrefs::instance()->mHourSize); 1230 int hi = (18/KOPrefs::instance()->mHourSize);
1235 //qDebug("hei %d ",KOPrefs::instance()->mHourSize); 1231 //qDebug("hei %d ",KOPrefs::instance()->mHourSize);
1236 int startY = endY -hi; 1232 int startY = endY -hi;
1237 1233
1238 mAgenda->insertItem(todo,currentDate,curCol,startY,endY); 1234 mAgenda->insertItem(todo,currentDate,curCol,startY,endY);
1239 1235
1240 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1236 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1241 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1237 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1242 } 1238 }
1243 } 1239 }
1244 } 1240 }
1245 // ---------- display Todos] -------------- 1241 // ---------- display Todos] --------------
1246 1242
1247 ++curCol; 1243 ++curCol;
1248 } 1244 }
1249 mAgenda->hideUnused(); 1245 mAgenda->hideUnused();
1250 mAllDayAgenda->hideUnused(); 1246 mAllDayAgenda->hideUnused();
1251 mAgenda->checkScrollBoundaries(); 1247 mAgenda->checkScrollBoundaries();
1252 1248
1253 deleteSelectedDateTime(); 1249 deleteSelectedDateTime();
1254 1250
1255 createDayLabels(); 1251 createDayLabels();
1256 emit incidenceSelected( 0 ); 1252 emit incidenceSelected( 0 );
1257 1253
1258 if ( globalFlagBlockAgenda == 2 ) { 1254 if ( globalFlagBlockAgenda == 2 ) {
1259 if ( KOPrefs::instance()->mSetTimeToDayStartAt ) 1255 if ( KOPrefs::instance()->mSetTimeToDayStartAt )
1260 setStartHour( KOPrefs::instance()->mDayBegins ); 1256 setStartHour( KOPrefs::instance()->mDayBegins );
1261 else if ( KOPrefs::instance()->mCenterOnCurrentTime ) 1257 else if ( KOPrefs::instance()->mCenterOnCurrentTime )
1262 setStartHour( QTime::currentTime ().hour() ); 1258 setStartHour( QTime::currentTime ().hour() );
1263 // qApp->processEvents(); 1259 // qApp->processEvents();
1264 } 1260 }
1265 qApp->processEvents(); 1261 qApp->processEvents();
1266 //qDebug("qApp->processEvents(); END "); 1262 //qDebug("qApp->processEvents(); END ");
1267 globalFlagBlockAgenda = 0; 1263 globalFlagBlockAgenda = 0;
1268 1264
1269 // mAgenda->hideUnused(); 1265 // mAgenda->hideUnused();
1270 //mAllDayAgenda->hideUnused(); 1266 //mAllDayAgenda->hideUnused();
1271 mAllDayAgenda->drawContentsToPainter(); 1267 mAllDayAgenda->drawContentsToPainter();
1272 mAgenda->drawContentsToPainter(); 1268 mAgenda->drawContentsToPainter();
1273 repaintAgenda(); 1269 repaintAgenda();
1274 onlyOne = false; 1270 onlyOne = false;
1275 // mAgenda->finishUpdate(); 1271 // mAgenda->finishUpdate();
1276 //mAllDayAgenda->finishUpdate(); 1272 //mAllDayAgenda->finishUpdate();
1277 1273
1278 // repaintAgenda(); 1274 // repaintAgenda();
1279 //qApp->processEvents(); 1275 //qApp->processEvents();
1280 // globalFlagBlockAgenda = 0; 1276 // globalFlagBlockAgenda = 0;
1281} 1277}
1282void KOAgendaView::repaintAgenda() 1278void KOAgendaView::repaintAgenda()
1283{ 1279{
1284 // mAllDayAgenda->drawContentsToPainter(); 1280 // mAllDayAgenda->drawContentsToPainter();
1285// mAllDayAgenda->viewport()->repaint( false ); 1281// mAllDayAgenda->viewport()->repaint( false );
1286// mAgenda->drawContentsToPainter(); 1282// mAgenda->drawContentsToPainter();
1287// mAgenda->viewport()->repaint( false ); 1283// mAgenda->viewport()->repaint( false );
1288// qApp->processEvents(); 1284// qApp->processEvents();
1289 1285
1290 //qDebug("KOAgendaView::repaintAgenda() "); 1286 //qDebug("KOAgendaView::repaintAgenda() ");
1291 //qApp->processEvents(); 1287 //qApp->processEvents();
1292 mAgenda->viewport()->repaint( false ); 1288 mAgenda->viewport()->repaint( false );
1293 mAllDayAgenda->viewport()->repaint( false ); 1289 mAllDayAgenda->viewport()->repaint( false );
1294 mAgenda->finishUpdate(); 1290 mAgenda->finishUpdate();
1295 mAllDayAgenda->finishUpdate(); 1291 mAllDayAgenda->finishUpdate();
1296} 1292}
1297 1293
1298 1294
1299void KOAgendaView::clearView() 1295void KOAgendaView::clearView()
1300{ 1296{
1301 // kdDebug() << "ClearView" << endl; 1297 // kdDebug() << "ClearView" << endl;
1302 mAllDayAgenda->clear(); 1298 mAllDayAgenda->clear();
1303 mAgenda->clear(); 1299 mAgenda->clear();
1304} 1300}
1305 1301
1306void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1302void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1307 const QDate &td) 1303 const QDate &td)
1308{ 1304{
1309#ifndef KORG_NOPRINTER 1305#ifndef KORG_NOPRINTER
1310 if (fd == td) 1306 if (fd == td)
1311 calPrinter->preview(CalPrinter::Day, fd, td); 1307 calPrinter->preview(CalPrinter::Day, fd, td);
1312 else 1308 else
1313 calPrinter->preview(CalPrinter::Week, fd, td); 1309 calPrinter->preview(CalPrinter::Week, fd, td);
1314#endif 1310#endif
1315} 1311}
1316 1312
1317// void KOAgendaView::updateMovedTodo() 1313// void KOAgendaView::updateMovedTodo()
1318// { 1314// {
1319// // updateConfig(); 1315// // updateConfig();
1320// // emit updateTodoViews(); 1316// // emit updateTodoViews();
1321// } 1317// }
1322 1318
1323void KOAgendaView::slotShowDateView( int mode , int d ) 1319void KOAgendaView::slotShowDateView( int mode , int d )
1324{ 1320{
1325 if ( d >= mSelectedDates.count() ) { 1321 if ( d >= mSelectedDates.count() ) {
1326 qDebug("KOAgendaView::slotShowDateView datecounterror %d d ", d, mSelectedDates.count() ); 1322 qDebug("KOAgendaView::slotShowDateView datecounterror %d d ", d, mSelectedDates.count() );
1327 1323
1328 } else { 1324 } else {
1329 QDate day = mSelectedDates[d]; 1325 QDate day = mSelectedDates[d];
1330 emit showDateView(mode , day ); 1326 emit showDateView(mode , day );
1331 } 1327 }
1332 1328
1333} 1329}
1334void KOAgendaView::newEvent(int gx, int gy) 1330void KOAgendaView::newEvent(int gx, int gy)
1335{ 1331{
1336 if (!mSelectedDates.count()) return; 1332 if (!mSelectedDates.count()) return;
1337 1333
1338 QDate day = mSelectedDates[gx]; 1334 QDate day = mSelectedDates[gx];
1339 1335
1340 QTime time = mAgenda->gyToTime(gy); 1336 QTime time = mAgenda->gyToTime(gy);
1341 QDateTime dt(day,time); 1337 QDateTime dt(day,time);
1342 // if ( dt < QDateTime::currentDateTime () ) 1338 // if ( dt < QDateTime::currentDateTime () )
1343 // dt = QDateTime::currentDateTime ().addSecs( 3600 ); 1339 // dt = QDateTime::currentDateTime ().addSecs( 3600 );
1344 emit newEventSignal(dt); 1340 emit newEventSignal(dt);
1345} 1341}
1346 1342
1347void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd) 1343void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd)
1348{ 1344{
1349 if (!mSelectedDates.count()) return; 1345 if (!mSelectedDates.count()) return;
1350 1346
1351 QDate dayStart = mSelectedDates[gxStart]; 1347 QDate dayStart = mSelectedDates[gxStart];
1352 QDate dayEnd = mSelectedDates[gxEnd]; 1348 QDate dayEnd = mSelectedDates[gxEnd];
1353 1349
1354 QTime timeStart = mAgenda->gyToTime(gyStart); 1350 QTime timeStart = mAgenda->gyToTime(gyStart);
1355 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1351 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1356 1352
1357 QDateTime dtStart(dayStart,timeStart); 1353 QDateTime dtStart(dayStart,timeStart);
1358 QDateTime dtEnd(dayEnd,timeEnd); 1354 QDateTime dtEnd(dayEnd,timeEnd);
1359 1355
1360 emit newEventSignal(dtStart,dtEnd); 1356 emit newEventSignal(dtStart,dtEnd);
1361} 1357}
1362 1358
1363void KOAgendaView::newEventAllDay(int gx, int ) 1359void KOAgendaView::newEventAllDay(int gx, int )
1364{ 1360{
1365 if (!mSelectedDates.count()) return; 1361 if (!mSelectedDates.count()) return;
1366 1362
1367 QDate day = mSelectedDates[gx]; 1363 QDate day = mSelectedDates[gx];
1368 1364
1369 emit newEventSignal(day); 1365 emit newEventSignal(day);
1370} 1366}
1371void KOAgendaView::newTodoAllDay(int gx, int ) 1367void KOAgendaView::newTodoAllDay(int gx, int )
1372{ 1368{
1373 if (!mSelectedDates.count()) return; 1369 if (!mSelectedDates.count()) return;
1374 1370
1375 QDateTime day (mSelectedDates[gx] ); 1371 QDateTime day (mSelectedDates[gx] );
1376 emit newTodoSignal(day, true); 1372 emit newTodoSignal(day, true);
1377} 1373}
1378void KOAgendaView::newTodo(int gx, int gy ) 1374void KOAgendaView::newTodo(int gx, int gy )
1379{ 1375{
1380 if (!mSelectedDates.count()) return; 1376 if (!mSelectedDates.count()) return;
1381 QDate dayStart = mSelectedDates[gx]; 1377 QDate dayStart = mSelectedDates[gx];
1382 QTime timeStart = mAgenda->gyToTime(gy); 1378 QTime timeStart = mAgenda->gyToTime(gy);
1383 QDateTime dt (dayStart,timeStart); 1379 QDateTime dt (dayStart,timeStart);
1384 emit newTodoSignal( dt, false ); 1380 emit newTodoSignal( dt, false );
1385} 1381}
1386 1382
1387void KOAgendaView::updateEventIndicatorTop(int newY) 1383void KOAgendaView::updateEventIndicatorTop(int newY)
1388{ 1384{
1389 uint i; 1385 uint i;
1390 for(i=0;i<mMinY.size();++i) { 1386 for(i=0;i<mMinY.size();++i) {
1391 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true); 1387 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true);
1392 else mEventIndicatorTop->enableColumn(i,false); 1388 else mEventIndicatorTop->enableColumn(i,false);
1393 } 1389 }
1394 1390
1395 mEventIndicatorTop->update(); 1391 mEventIndicatorTop->update();
1396} 1392}
1397 1393
1398void KOAgendaView::updateEventIndicatorBottom(int newY) 1394void KOAgendaView::updateEventIndicatorBottom(int newY)
1399{ 1395{
1400 uint i; 1396 uint i;
1401 for(i=0;i<mMaxY.size();++i) { 1397 for(i=0;i<mMaxY.size();++i) {
1402 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true); 1398 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true);
1403 else mEventIndicatorBottom->enableColumn(i,false); 1399 else mEventIndicatorBottom->enableColumn(i,false);
1404 } 1400 }
1405 1401
1406 mEventIndicatorBottom->update(); 1402 mEventIndicatorBottom->update();
1407} 1403}
1408 1404
1409void KOAgendaView::startDrag(Event *event) 1405void KOAgendaView::startDrag(Event *event)
1410{ 1406{
1411#ifndef KORG_NODND 1407#ifndef KORG_NODND
1412 DndFactory factory( calendar() ); 1408 DndFactory factory( calendar() );
1413 ICalDrag *vd = factory.createDrag(event,this); 1409 ICalDrag *vd = factory.createDrag(event,this);
1414 if (vd->drag()) { 1410 if (vd->drag()) {
1415 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl; 1411 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl;
1416 } 1412 }
1417#endif 1413#endif
1418} 1414}
1419 1415
1420void KOAgendaView::readSettings() 1416void KOAgendaView::readSettings()
1421{ 1417{
1422 readSettings(KOGlobals::config()); 1418 readSettings(KOGlobals::config());
1423} 1419}
1424 1420
1425void KOAgendaView::readSettings(KConfig *config) 1421void KOAgendaView::readSettings(KConfig *config)
1426{ 1422{
1427 // kdDebug() << "KOAgendaView::readSettings()" << endl; 1423 // kdDebug() << "KOAgendaView::readSettings()" << endl;
1428 1424
1429 config->setGroup("Views"); 1425 config->setGroup("Views");
1430 1426
1431 //#ifndef KORG_NOSPLITTER 1427 //#ifndef KORG_NOSPLITTER
1432 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView"); 1428 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView");
1433 if (sizes.count() == 2) { 1429 if (sizes.count() == 2) {
1434 if ( sizes[0] < 20 ) { 1430 if ( sizes[0] < 20 ) {
1435 sizes[1] = sizes[1] +20 - sizes[0]; 1431 sizes[1] = sizes[1] +20 - sizes[0];
1436 sizes[0] = 20; 1432 sizes[0] = 20;
1437 } 1433 }
1438 mSplitterAgenda->setSizes(sizes); 1434 mSplitterAgenda->setSizes(sizes);
1439 // qDebug("read %d %d ",sizes[0],sizes[1] ); 1435 // qDebug("read %d %d ",sizes[0],sizes[1] );
1440 } 1436 }
1441 //#endif 1437 //#endif
1442 1438
1443 // updateConfig(); 1439 // updateConfig();
1444} 1440}
1445 1441
1446void KOAgendaView::writeSettings(KConfig *config) 1442void KOAgendaView::writeSettings(KConfig *config)
1447{ 1443{
1448 // kdDebug() << "KOAgendaView::writeSettings()" << endl; 1444 // kdDebug() << "KOAgendaView::writeSettings()" << endl;
1449 1445
1450 config->setGroup("Views"); 1446 config->setGroup("Views");
1451 1447
1452 //#ifndef KORG_NOSPLITTER 1448 //#ifndef KORG_NOSPLITTER
1453 QValueList<int> list = mSplitterAgenda->sizes(); 1449 QValueList<int> list = mSplitterAgenda->sizes();
1454 config->writeEntry("Separator AgendaView",list); 1450 config->writeEntry("Separator AgendaView",list);
1455 //qDebug("write %d %d ", list[0],list[1] ); 1451 //qDebug("write %d %d ", list[0],list[1] );
1456 //#endif 1452 //#endif
1457} 1453}
1458 1454
1459void KOAgendaView::setHolidayMasks() 1455void KOAgendaView::setHolidayMasks()
1460{ 1456{
1461 mHolidayMask.resize(mSelectedDates.count()); 1457 mHolidayMask.resize(mSelectedDates.count());
1462 1458
1463 uint i; 1459 uint i;
1464 for(i=0;i<mSelectedDates.count();++i) { 1460 for(i=0;i<mSelectedDates.count();++i) {
1465 QDate date = mSelectedDates[i]; 1461 QDate date = mSelectedDates[i];
1466 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6); 1462 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6);
1467 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7); 1463 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7);
1468 bool showHoliday = false; 1464 bool showHoliday = false;
1469 if ( KOPrefs::instance()->mExcludeHolidays ) { 1465 if ( KOPrefs::instance()->mExcludeHolidays ) {
1470 QPtrList<Event> events = calendar()->events( date, true ); 1466 QPtrList<Event> events = calendar()->events( date, true );
1471 Event *event; 1467 Event *event;
1472 for( event = events.first(); event; event = events.next() ) { 1468 for( event = events.first(); event; event = events.next() ) {
1473 if ( event->isHoliday()) { 1469 if ( event->isHoliday()) {
1474 showHoliday = true; 1470 showHoliday = true;
1475 break; 1471 break;
1476 } 1472 }
1477 } 1473 }
1478 1474
1479 } 1475 }
1480 1476
1481#ifndef KORG_NOPLUGINS 1477#ifndef KORG_NOPLUGINS
1482 bool showHoliday = KOPrefs::instance()->mExcludeHolidays && 1478 bool showHoliday = KOPrefs::instance()->mExcludeHolidays &&
1483 !KOCore::self()->holiday(date).isEmpty(); 1479 !KOCore::self()->holiday(date).isEmpty();
1484#endif 1480#endif
1485 bool showDay = showSaturday || showSunday || showHoliday; 1481 bool showDay = showSaturday || showSunday || showHoliday;
1486 1482
1487 if (showDay) { 1483 if (showDay) {
1488 mHolidayMask.at(i) = true; 1484 mHolidayMask.at(i) = true;
1489 } else { 1485 } else {
1490 mHolidayMask.at(i) = false; 1486 mHolidayMask.at(i) = false;
1491 } 1487 }
1492 } 1488 }
1493 1489
1494 mAgenda->setHolidayMask(&mHolidayMask); 1490 mAgenda->setHolidayMask(&mHolidayMask);
1495 mAllDayAgenda->setHolidayMask(&mHolidayMask); 1491 mAllDayAgenda->setHolidayMask(&mHolidayMask);
1496} 1492}
1497 1493
1498void KOAgendaView::setContentsPos(int y) 1494void KOAgendaView::setContentsPos(int y)
1499{ 1495{
1500 mAgenda->setContentsPos(0,y); 1496 mAgenda->setContentsPos(0,y);
1501} 1497}
1502 1498
1503void KOAgendaView::clearSelection() 1499void KOAgendaView::clearSelection()
1504{ 1500{
1505 mAgenda->deselectItem(); 1501 mAgenda->deselectItem();
1506 mAllDayAgenda->deselectItem(); 1502 mAllDayAgenda->deselectItem();
1507} 1503}
1508 1504
1509void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart, 1505void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart,
1510 int gxEnd, int gyEnd) 1506 int gxEnd, int gyEnd)
1511{ 1507{
1512 mTimeSpanInAllDay = true; 1508 mTimeSpanInAllDay = true;
1513 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd); 1509 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd);
1514} 1510}
1515 1511
1516 1512
1517 1513
1518 1514
1519void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart, 1515void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart,
1520 int gxEnd, int gyEnd) 1516 int gxEnd, int gyEnd)
1521{ 1517{
1522 if (!mSelectedDates.count()) return; 1518 if (!mSelectedDates.count()) return;
1523 1519
1524 QDate dayStart = mSelectedDates[gxStart]; 1520 QDate dayStart = mSelectedDates[gxStart];
1525 QDate dayEnd = mSelectedDates[gxEnd]; 1521 QDate dayEnd = mSelectedDates[gxEnd];
1526 1522
1527 QTime timeStart = mAgenda->gyToTime(gyStart); 1523 QTime timeStart = mAgenda->gyToTime(gyStart);
1528 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1524 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1529 1525
1530 QDateTime dtStart(dayStart,timeStart); 1526 QDateTime dtStart(dayStart,timeStart);
1531 QDateTime dtEnd(dayEnd,timeEnd); 1527 QDateTime dtEnd(dayEnd,timeEnd);
1532 1528
1533 mTimeSpanBegin = dtStart; 1529 mTimeSpanBegin = dtStart;
1534 mTimeSpanEnd = dtEnd; 1530 mTimeSpanEnd = dtEnd;
1535 1531
1536} 1532}
1537 1533
1538void KOAgendaView::deleteSelectedDateTime() 1534void KOAgendaView::deleteSelectedDateTime()
1539{ 1535{
1540 mTimeSpanBegin.setDate(QDate()); 1536 mTimeSpanBegin.setDate(QDate());
1541 mTimeSpanEnd.setDate(QDate()); 1537 mTimeSpanEnd.setDate(QDate());
1542 mTimeSpanInAllDay = false; 1538 mTimeSpanInAllDay = false;
1543} 1539}
1544 1540
1545void KOAgendaView::keyPressEvent ( QKeyEvent * e ) 1541void KOAgendaView::keyPressEvent ( QKeyEvent * e )
1546{ 1542{
1547 e->ignore(); 1543 e->ignore();
1548} 1544}
1549 1545
1550void KOAgendaView::scrollOneHourUp() 1546void KOAgendaView::scrollOneHourUp()
1551{ 1547{
1552 1548
1553 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 ); 1549 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 );
1554} 1550}
1555void KOAgendaView::scrollOneHourDown() 1551void KOAgendaView::scrollOneHourDown()
1556{ 1552{
1557 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 ); 1553 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 );
1558} 1554}
1559 1555
1560void KOAgendaView::setStartHour( int h ) 1556void KOAgendaView::setStartHour( int h )
1561{ 1557{
1562 mAgenda->setStartHour( h ); 1558 mAgenda->setStartHour( h );
1563 1559
1564} 1560}
1565void KOAgendaView::setInitStartHour() 1561void KOAgendaView::setInitStartHour()
1566{ 1562{
1567 1563
1568 if ( KOPrefs::instance()->mCenterOnCurrentTime ) 1564 if ( KOPrefs::instance()->mCenterOnCurrentTime )
1569 setStartHour( QTime::currentTime ().hour() ); 1565 setStartHour( QTime::currentTime ().hour() );
1570 else 1566 else
1571 setStartHour( KOPrefs::instance()->mDayBegins ); 1567 setStartHour( KOPrefs::instance()->mDayBegins );
1572 1568
1573} 1569}
1574 1570
1575 1571
1576void KOAgendaView::updateTodo( Todo * t, int ) 1572void KOAgendaView::updateTodo( Todo * t, int )
1577{ 1573{
1578 if ( !isVisible() ) 1574 if ( !isVisible() )
1579 return; 1575 return;
1580 bool remove = false; 1576 bool remove = false;
1581 bool removeAD = false; 1577 bool removeAD = false;
1582 QDate da; 1578 QDate da;
1583 if ( t->hasCompletedDate() ) 1579 if ( t->hasCompletedDate() )
1584 da = t->completed().date(); 1580 da = t->completed().date();
1585 else 1581 else
1586 da = t->dtDue().date(); 1582 da = t->dtDue().date();
1587 if ( ! t->hasDueDate() && !t->hasCompletedDate() ) { 1583 if ( ! t->hasDueDate() && !t->hasCompletedDate() ) {
1588 remove = true; 1584 remove = true;
1589 removeAD = true; 1585 removeAD = true;
1590 } 1586 }
1591 else { 1587 else {
1592 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ; 1588 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ;
1593 if ( overdue && 1589 if ( overdue &&
1594 QDate::currentDate() >= mSelectedDates.first() && 1590 QDate::currentDate() >= mSelectedDates.first() &&
1595 QDate::currentDate() <= mSelectedDates.last()) { 1591 QDate::currentDate() <= mSelectedDates.last()) {
1596 removeAD = false; 1592 removeAD = false;
1597 remove = true; 1593 remove = true;
1598 } 1594 }
1599 else { 1595 else {
1600 1596
1601 if ( da < mSelectedDates.first() || 1597 if ( da < mSelectedDates.first() ||
1602 da > mSelectedDates.last() ) { 1598 da > mSelectedDates.last() ) {
1603 remove = true; 1599 remove = true;
1604 removeAD = true; 1600 removeAD = true;
1605 } else { 1601 } else {
1606 remove = t->doesFloat() && !t->hasCompletedDate(); 1602 remove = t->doesFloat() && !t->hasCompletedDate();
1607 removeAD = !remove; 1603 removeAD = !remove;
1608 } 1604 }
1609 } 1605 }
1610 } 1606 }
1611 int days = mSelectedDates.first().daysTo( da ); 1607 int days = mSelectedDates.first().daysTo( da );
1612 //qDebug("daysto %d %d %d", days, remove,removeAD ); 1608 //qDebug("daysto %d %d %d", days, remove,removeAD );
1613 mAgenda->updateTodo( t , days, remove); 1609 mAgenda->updateTodo( t , days, remove);
1614 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1610 if ( KOPrefs::instance()->mShowTodoInAgenda )
1615 mAllDayAgenda->updateTodo( t , days, removeAD); 1611 mAllDayAgenda->updateTodo( t , days, removeAD);
1616 //qDebug("KOAgendaView::updateTodo( Todo *, int ) "); 1612 //qDebug("KOAgendaView::updateTodo( Todo *, int ) ");
1617 1613
1618} 1614}
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index c55f7d7..5b5703f 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -1,968 +1,970 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> 3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at>
4 Parts of the source code have been copied from kdpdatebutton.cpp 4 Parts of the source code have been copied from kdpdatebutton.cpp
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source ode for Qt in the source distribution. 22 without including the source ode for Qt in the source distribution.
23*/ 23*/
24 24
25#include <qevent.h> 25#include <qevent.h>
26#include <qpainter.h> 26#include <qpainter.h>
27#include <qptrlist.h> 27#include <qptrlist.h>
28#include <qtimer.h> 28#include <qtimer.h>
29#include <qwhatsthis.h> 29#include <qwhatsthis.h>
30 30
31#include <kglobal.h> 31#include <kglobal.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <klocale.h> 33#include <klocale.h>
34 34
35#include <libkcal/vcaldrag.h> 35#include <libkcal/vcaldrag.h>
36#include <libkcal/icaldrag.h> 36#include <libkcal/icaldrag.h>
37#include <libkcal/dndfactory.h> 37#include <libkcal/dndfactory.h>
38#include <libkcal/calendarresources.h> 38#include <libkcal/calendarresources.h>
39#include <libkcal/resourcecalendar.h> 39#include <libkcal/resourcecalendar.h>
40#include <kresources/resourceselectdialog.h> 40#include <kresources/resourceselectdialog.h>
41 41
42#include <kcalendarsystem.h> 42#include <kcalendarsystem.h>
43 43
44#ifndef KORG_NOPLUGINS 44#ifndef KORG_NOPLUGINS
45#include "kocore.h" 45#include "kocore.h"
46#endif 46#endif
47#include "koprefs.h" 47#include "koprefs.h"
48#include "koglobals.h" 48#include "koglobals.h"
49 49
50#include "kodaymatrix.h" 50#include "kodaymatrix.h"
51 51
52// ============================================================================ 52// ============================================================================
53// D Y N A M I C T I P 53// D Y N A M I C T I P
54// ============================================================================ 54// ============================================================================
55 55
56DynamicTip::DynamicTip( QWidget * parent ) 56DynamicTip::DynamicTip( QWidget * parent )
57 : QToolTip( parent ) 57 : QToolTip( parent )
58{ 58{
59 matrix = (KODayMatrix*)parent; 59 matrix = (KODayMatrix*)parent;
60} 60}
61 61
62class KODaymatrixWhatsThis :public QWhatsThis 62class KODaymatrixWhatsThis :public QWhatsThis
63{ 63{
64public: 64public:
65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;}; 65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;};
66 ~KODaymatrixWhatsThis() { ; }; 66 ~KODaymatrixWhatsThis() { ; };
67 67
68protected: 68protected:
69 virtual QString text( const QPoint& p ) 69 virtual QString text( const QPoint& p )
70 { 70 {
71 return _view->getWhatsThisText( p ) ; 71 return _view->getWhatsThisText( p ) ;
72 } 72 }
73private: 73private:
74 KODayMatrix * _view; 74 KODayMatrix * _view;
75}; 75};
76 76
77void DynamicTip::maybeTip( const QPoint &pos ) 77void DynamicTip::maybeTip( const QPoint &pos )
78{ 78{
79 //calculate which cell of the matrix the mouse is in 79 //calculate which cell of the matrix the mouse is in
80 QRect sz = matrix->frameRect(); 80 QRect sz = matrix->frameRect();
81 int dheight = sz.height()*7 / 42; 81 int dheight = sz.height()*7 / 42;
82 int dwidth = sz.width() / 7; 82 int dwidth = sz.width() / 7;
83 int row = pos.y()/dheight; 83 int row = pos.y()/dheight;
84 int col = pos.x()/dwidth; 84 int col = pos.x()/dwidth;
85 85
86 QRect rct(col*dwidth, row*dheight, dwidth, dheight); 86 QRect rct(col*dwidth, row*dheight, dwidth, dheight);
87 87
88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" << 88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" <<
89// col << "][" << row << "] => " <<(col+row*7) << endl; 89// col << "][" << row << "] => " <<(col+row*7) << endl;
90 90
91 //show holiday names only 91 //show holiday names only
92 QString str = matrix->getHolidayLabel(col+row*7); 92 QString str = matrix->getHolidayLabel(col+row*7);
93 if (str.isEmpty()) return; 93 if (str.isEmpty()) return;
94 tip(rct, str); 94 tip(rct, str);
95} 95}
96 96
97 97
98// ============================================================================ 98// ============================================================================
99// K O D A Y M A T R I X 99// K O D A Y M A T R I X
100// ============================================================================ 100// ============================================================================
101 101
102const int KODayMatrix::NOSELECTION = -1000; 102const int KODayMatrix::NOSELECTION = -1000;
103const int KODayMatrix::NUMDAYS = 42; 103const int KODayMatrix::NUMDAYS = 42;
104 104
105KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) 105KODayMatrix::KODayMatrix( QWidget *parent, const char *name )
106 : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 ) 106 : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 )
107 107
108#if 0 108#if 0
109KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : 109KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) :
110 QFrame(parent, name) 110 QFrame(parent, name)
111#endif 111#endif
112{ 112{
113 mRedrawNeeded = true; 113 mRedrawNeeded = true;
114 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); 114 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this);
115 mPendingUpdateBeforeRepaint = false; 115 mPendingUpdateBeforeRepaint = false;
116 mouseDown = false; 116 mouseDown = false;
117 // initialize dynamic arrays 117 // initialize dynamic arrays
118 bDays.resize ( NUMDAYS ); 118 bDays.resize ( NUMDAYS );
119 hDays.resize ( NUMDAYS );; 119 hDays.resize ( NUMDAYS );;
120 eDays.resize ( NUMDAYS );; 120 eDays.resize ( NUMDAYS );;
121 days = new QDate[NUMDAYS]; 121 days = new QDate[NUMDAYS];
122 daylbls = new QString[NUMDAYS]; 122 daylbls = new QString[NUMDAYS];
123 //events = new int[NUMDAYS]; 123 //events = new int[NUMDAYS];
124 mToolTip = new DynamicTip(this); 124 mToolTip = new DynamicTip(this);
125 125
126 // set default values used for drawing the matrix 126 // set default values used for drawing the matrix
127 mDefaultBackColor = palette().active().base(); 127 mDefaultBackColor = palette().active().base();
128 mDefaultTextColor = palette().active().foreground(); 128 mDefaultTextColor = palette().active().foreground();
129 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); 129 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor);
130 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); 130 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor);
131 mSelectedDaysColor = QColor("white"); 131 mSelectedDaysColor = QColor("white");
132 mTodayMarginWidth = 2; 132 mTodayMarginWidth = 2;
133 mSelEnd = mSelStart = NOSELECTION; 133 mSelEnd = mSelStart = NOSELECTION;
134 134
135 setAcceptDrops(true); 135 setAcceptDrops(true);
136 //setFont( QFont("Arial", 10) ); 136 //setFont( QFont("Arial", 10) );
137 137
138 mUpdateTimer = new QTimer( this ); 138 mUpdateTimer = new QTimer( this );
139 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); 139 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() ));
140 mRepaintTimer = new QTimer( this ); 140 mRepaintTimer = new QTimer( this );
141 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); 141 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() ));
142 mDayChanged = false; 142 mDayChanged = false;
143 updateView(); 143 updateView();
144} 144}
145QString KODayMatrix::getWhatsThisText( QPoint p ) 145QString KODayMatrix::getWhatsThisText( QPoint p )
146{ 146{
147 147
148 int tmp = getDayIndexFrom(p.x(), p.y()); 148 int tmp = getDayIndexFrom(p.x(), p.y());
149 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) 149 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar )
150 return QString(); 150 return QString();
151 QDate mDate = days[tmp]; 151 QDate mDate = days[tmp];
152 QPtrList<Event> eventlist = mCalendar->events(mDate); 152 QPtrList<Event> eventlist = mCalendar->events(mDate);
153 Event *event; 153 Event *event;
154 QStringList mToolTip; 154 QStringList mToolTip;
155 for(event=eventlist.first();event != 0;event=eventlist.next()) { 155 for(event=eventlist.first();event != 0;event=eventlist.next()) {
156 QString mToolTipText; 156 QString mToolTipText;
157 QString text; 157 QString text;
158 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day 158 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
159 if (event->isMultiDay()) { 159 if (event->isMultiDay()) {
160 QString prefix = "<->";multiday = 2; 160 QString prefix = "<->";multiday = 2;
161 QString time; 161 QString time;
162 if ( event->doesRecur() ) { 162 if ( event->doesRecur() ) {
163 if ( event->recursOn( mDate) ) { 163 if ( event->recursOn( mDate) ) {
164 prefix ="->" ;multiday = 1; 164 prefix ="->" ;multiday = 1;
165 } 165 }
166 else { 166 else {
167 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 167 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
168 if ( event->recursOn( mDate.addDays( -days)) ) { 168 if ( event->recursOn( mDate.addDays( -days)) ) {
169 prefix ="<-" ;multiday = 3; 169 prefix ="<-" ;multiday = 3;
170 } 170 }
171 } 171 }
172 } else { 172 } else {
173 if (mDate == event->dtStart().date()) { 173 if (mDate == event->dtStart().date()) {
174 prefix ="->" ;multiday = 1; 174 prefix ="->" ;multiday = 1;
175 } else if (mDate == event->dtEnd().date()) { 175 } else if (mDate == event->dtEnd().date()) {
176 prefix ="<-" ;multiday = 3; 176 prefix ="<-" ;multiday = 3;
177 } 177 }
178 } 178 }
179 if ( !event->doesFloat() ) { 179 if ( !event->doesFloat() ) {
180 if ( mDate == event->dtStart().date () ) 180 if ( mDate == event->dtStart().date () )
181 time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; 181 time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
182 else if ( mDate == event->dtEnd().date () ) 182 else if ( mDate == event->dtEnd().date () )
183 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 183 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
184 184
185 } 185 }
186 text = time + event->summary(); 186 text = time + event->summary();
187 mToolTipText += prefix + text; 187 mToolTipText += prefix + text;
188 } else { 188 } else {
189 if (event->doesFloat()) { 189 if (event->doesFloat()) {
190 text = event->summary(); 190 text = event->summary();
191 mToolTipText += text; 191 mToolTipText += text;
192 } 192 }
193 else { 193 else {
194 text = KGlobal::locale()->formatTime(event->dtStart().time()); 194 text = KGlobal::locale()->formatTime(event->dtStart().time());
195 text += " " + event->summary(); 195 text += " " + event->summary();
196 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 196 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
197 } 197 }
198 } 198 }
199 if ( !event->location().isEmpty() ) 199 if ( !event->location().isEmpty() )
200 mToolTipText += " (" + event->location() + ")"; 200 mToolTipText += " (" + event->location() + ")";
201#if QT_VERSION >= 0x030000 201#if QT_VERSION >= 0x030000
202 mToolTipText.replace( '<' , "&lt;" ); 202 mToolTipText.replace( '<' , "&lt;" );
203 mToolTipText.replace( '>' , "&gt;" ); 203 mToolTipText.replace( '>' , "&gt;" );
204#else 204#else
205 if ( mToolTipText.find ('<') >= 0 ) { 205 if ( mToolTipText.find ('<') >= 0 ) {
206 mToolTipText.replace( QRegExp("<") , "&lt;" ); 206 mToolTipText.replace( QRegExp("<") , "&lt;" );
207 } 207 }
208 if ( mToolTipText.find ('>') >= 0 ) { 208 if ( mToolTipText.find ('>') >= 0 ) {
209 mToolTipText.replace( QRegExp(">") , "&gt;" ); 209 mToolTipText.replace( QRegExp(">") , "&gt;" );
210 } 210 }
211#endif 211#endif
212 //qDebug("TTT: %s ", mToolTipText.latin1()); 212 //qDebug("TTT: %s ", mToolTipText.latin1());
213 mToolTip.append( mToolTipText ); 213 mToolTip.append( mToolTipText );
214 } 214 }
215 mToolTip.sort(); 215 mToolTip.sort();
216 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); 216 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>");
217} 217}
218void KODayMatrix::setCalendar( Calendar *cal ) 218void KODayMatrix::setCalendar( Calendar *cal )
219{ 219{
220 mCalendar = cal; 220 mCalendar = cal;
221 221
222 setAcceptDrops( mCalendar ); 222 setAcceptDrops( mCalendar );
223 223
224 updateEvents(); 224 updateEvents();
225} 225}
226 226
227QColor KODayMatrix::getShadedColor(QColor color) 227QColor KODayMatrix::getShadedColor(QColor color)
228{ 228{
229 QColor shaded; 229 QColor shaded;
230 int h=0; 230 int h=0;
231 int s=0; 231 int s=0;
232 int v=0; 232 int v=0;
233 color.hsv(&h,&s,&v); 233 color.hsv(&h,&s,&v);
234 s = s/4; 234 s = s/4;
235 v = 192+v/4; 235 v = 192+v/4;
236 shaded.setHsv(h,s,v); 236 shaded.setHsv(h,s,v);
237 237
238 return shaded; 238 return shaded;
239} 239}
240 240
241KODayMatrix::~KODayMatrix() 241KODayMatrix::~KODayMatrix()
242{ 242{
243 // delete mKODaymatrixWhatsThis; 243 // delete mKODaymatrixWhatsThis;
244 delete [] days; 244 delete [] days;
245 delete [] daylbls; 245 delete [] daylbls;
246 //delete [] events; 246 //delete [] events;
247 delete mToolTip; 247 delete mToolTip;
248} 248}
249 249
250/* 250/*
251void KODayMatrix::setStartDate(QDate start) 251void KODayMatrix::setStartDate(QDate start)
252{ 252{
253 updateView(start); 253 updateView(start);
254} 254}
255*/ 255*/
256 256
257void KODayMatrix::addSelectedDaysTo(DateList& selDays) 257void KODayMatrix::addSelectedDaysTo(DateList& selDays)
258{ 258{
259 259
260 if (mSelStart == NOSELECTION) { 260 if (mSelStart == NOSELECTION) {
261 return; 261 return;
262 } 262 }
263 263
264 //cope with selection being out of matrix limits at top (< 0) 264 //cope with selection being out of matrix limits at top (< 0)
265 int i0 = mSelStart; 265 int i0 = mSelStart;
266 if (i0 < 0) { 266 if (i0 < 0) {
267 for (int i = i0; i < 0; i++) { 267 for (int i = i0; i < 0; i++) {
268 selDays.append(days[0].addDays(i)); 268 selDays.append(days[0].addDays(i));
269 } 269 }
270 i0 = 0; 270 i0 = 0;
271 } 271 }
272 272
273 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) 273 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1)
274 if (mSelEnd > NUMDAYS-1) { 274 if (mSelEnd > NUMDAYS-1) {
275 for (int i = i0; i <= NUMDAYS-1; i++) { 275 for (int i = i0; i <= NUMDAYS-1; i++) {
276 selDays.append(days[i]); 276 selDays.append(days[i]);
277 } 277 }
278 for (int i = NUMDAYS; i < mSelEnd; i++) { 278 for (int i = NUMDAYS; i < mSelEnd; i++) {
279 selDays.append(days[0].addDays(i)); 279 selDays.append(days[0].addDays(i));
280 } 280 }
281 281
282 // apply normal routine to selection being entirely within matrix limits 282 // apply normal routine to selection being entirely within matrix limits
283 } else { 283 } else {
284 for (int i = i0; i <= mSelEnd; i++) { 284 for (int i = i0; i <= mSelEnd; i++) {
285 selDays.append(days[i]); 285 selDays.append(days[i]);
286 } 286 }
287 } 287 }
288} 288}
289 289
290bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) 290bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
291{ 291{
292 mRedrawNeeded = true; 292 mRedrawNeeded = true;
293 bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION ); 293 bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION );
294 mSelStart = startdate.daysTo(start); 294 mSelStart = startdate.daysTo(start);
295 if ( mSelStart < 0 ) 295 if ( mSelStart < 0 )
296 mSelStart = 0; 296 mSelStart = 0;
297 mSelEnd = startdate.daysTo(end); 297 mSelEnd = startdate.daysTo(end);
298 if ( mSelEnd > NUMDAYS-1 ) 298 if ( mSelEnd > NUMDAYS-1 )
299 mSelEnd = NUMDAYS-1; 299 mSelEnd = NUMDAYS-1;
300 if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) { 300 if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) {
301 clearSelection(); 301 clearSelection();
302 if ( noSel ) 302 if ( noSel )
303 return false; 303 return false;
304 } 304 }
305 305
306 return true; 306 return true;
307} 307}
308void KODayMatrix::clearSelection() 308void KODayMatrix::clearSelection()
309{ 309{
310 mSelEnd = mSelStart = NOSELECTION; 310 mSelEnd = mSelStart = NOSELECTION;
311} 311}
312 312
313 313
314void KODayMatrix::recalculateToday() 314void KODayMatrix::recalculateToday()
315{ 315{
316 today = -1; 316 today = -1;
317 for (int i=0; i<NUMDAYS; i++) { 317 for (int i=0; i<NUMDAYS; i++) {
318 //events[i] = 0; 318 //events[i] = 0;
319 days[i] = startdate.addDays(i); 319 days[i] = startdate.addDays(i);
320 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); 320 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
321 321
322 // if today is in the currently displayed month, hilight today 322 // if today is in the currently displayed month, hilight today
323 if (days[i].year() == QDate::currentDate().year() && 323 if (days[i].year() == QDate::currentDate().year() &&
324 days[i].month() == QDate::currentDate().month() && 324 days[i].month() == QDate::currentDate().month() &&
325 days[i].day() == QDate::currentDate().day()) { 325 days[i].day() == QDate::currentDate().day()) {
326 today = i; 326 today = i;
327 } 327 }
328 } 328 }
329 // qDebug(QString("Today is visible at %1.").arg(today)); 329 // qDebug(QString("Today is visible at %1.").arg(today));
330} 330}
331 331
332void KODayMatrix::updateView() 332void KODayMatrix::updateView()
333{ 333{
334 updateView(startdate); 334 updateView(startdate);
335} 335}
336void KODayMatrix::repaintViewTimed() 336void KODayMatrix::repaintViewTimed()
337{ 337{
338 mRepaintTimer->stop(); 338 mRepaintTimer->stop();
339 repaint(false); 339 repaint(false);
340} 340}
341void KODayMatrix::updateViewTimed() 341void KODayMatrix::updateViewTimed()
342{ 342{
343 mUpdateTimer->stop(); 343 mUpdateTimer->stop();
344 if ( !mCalendar ) { 344 if ( !mCalendar ) {
345 qDebug("NOT CAL "); 345 qDebug("NOT CAL ");
346 return; 346 return;
347 } 347 }
348 //qDebug("KODayMatrix::updateViewTimed "); 348 //qDebug("KODayMatrix::updateViewTimed ");
349 for(int i = 0; i < NUMDAYS; i++) { 349 for(int i = 0; i < NUMDAYS; i++) {
350 // if events are set for the day then remember to draw it bold 350 // if events are set for the day then remember to draw it bold
351 QPtrList<Event> eventlist = mCalendar->events(days[i]); 351 QPtrList<Event> eventlist = mCalendar->events(days[i]);
352 Event *event; 352 Event *event;
353 int numEvents = eventlist.count(); 353 int numEvents = eventlist.count();
354 QString holiStr = ""; 354 QString holiStr = "";
355 bDays.clearBit(i); 355 bDays.clearBit(i);
356 hDays.clearBit(i); 356 hDays.clearBit(i);
357 eDays.clearBit(i); 357 eDays.clearBit(i);
358 for(event=eventlist.first();event != 0;event=eventlist.next()) { 358 for(event=eventlist.first();event != 0;event=eventlist.next()) {
359 ushort recurType = event->recurrence()->doesRecur(); 359 ushort recurType = event->recurrence()->doesRecur();
360 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 360 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
361 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 361 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
362 numEvents--; 362 numEvents--;
363 } 363 }
364 if ( event->isHoliday()) { 364 if ( event->isHoliday()) {
365 hDays.setBit(i); 365 hDays.setBit(i);
366 if ( !holiStr.isEmpty() ) 366 if ( !holiStr.isEmpty() )
367 holiStr += "\n"; 367 holiStr += "\n";
368 holiStr += event->summary(); 368 holiStr += event->summary();
369 if ( !event->location().isEmpty() ) 369 if ( !event->location().isEmpty() )
370 holiStr += " (" + event->location() + ")"; 370 holiStr += " (" + event->location() + ")";
371 } 371 }
372 if ( event->isBirthday()) { 372 if ( event->isBirthday()) {
373 if ( !holiStr.isEmpty() ) 373 if ( !holiStr.isEmpty() )
374 holiStr += "\n"; 374 holiStr += "\n";
375 holiStr += i18n("Birthday") + ": "+event->summary(); 375 holiStr += i18n("Birthday") + ": "+event->summary();
376 if ( !event->location().isEmpty() ) 376 if ( !event->location().isEmpty() )
377 holiStr += " (" + event->location() + ")"; 377 holiStr += " (" + event->location() + ")";
378 bDays.setBit(i); 378 bDays.setBit(i);
379 } 379 }
380 } 380 }
381 if ( numEvents ) 381 if ( numEvents )
382 eDays.setBit(i); 382 eDays.setBit(i);
383 //if it is a holy day then draw it red. Sundays are consider holidays, too 383 //if it is a holy day then draw it red. Sundays are consider holidays, too
384 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || 384 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) ||
385 !holiStr.isEmpty()) { 385 !holiStr.isEmpty()) {
386 mHolidays[i] = holiStr; 386 mHolidays[i] = holiStr;
387 } else { 387 } else {
388 mHolidays[i] = QString::null; 388 mHolidays[i] = QString::null;
389 } 389 }
390 } 390 }
391 mRedrawNeeded = true; 391 mRedrawNeeded = true;
392 if ( ! mPendingUpdateBeforeRepaint ) 392 if ( ! mPendingUpdateBeforeRepaint )
393 repaint(false); 393 repaint(false);
394} 394}
395void KODayMatrix::updateView(QDate actdate) 395void KODayMatrix::updateView(QDate actdate)
396{ 396{
397 397
398 if ( ! actdate.isValid() ) { 398 if ( ! actdate.isValid() ) {
399 //qDebug("date not valid "); 399 //qDebug("date not valid ");
400 return; 400 return;
401 } 401 }
402 mDayChanged = false; 402 mDayChanged = false;
403 //flag to indicate if the starting day of the matrix has changed by this call 403 //flag to indicate if the starting day of the matrix has changed by this call
404 //mDayChanged = false; 404 //mDayChanged = false;
405 // if a new startdate is to be set then apply Cornelius's calculation 405 // if a new startdate is to be set then apply Cornelius's calculation
406 // of the first day to be shown 406 // of the first day to be shown
407 if (actdate != startdate) { 407 if (actdate != startdate) {
408 // reset index of selection according to shift of starting date from startdate to actdate 408 // reset index of selection according to shift of starting date from startdate to actdate
409 if (mSelStart != NOSELECTION) { 409 if (mSelStart != NOSELECTION) {
410 int tmp = actdate.daysTo(startdate); 410 int tmp = actdate.daysTo(startdate);
411 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; 411 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl;
412 // shift selection if new one would be visible at least partly ! 412 // shift selection if new one would be visible at least partly !
413 413
414 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { 414 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) {
415 // nested if is required for next X display pushed from a different month - correction required 415 // nested if is required for next X display pushed from a different month - correction required
416 // otherwise, for month forward and backward, it must be avoided 416 // otherwise, for month forward and backward, it must be avoided
417 if( mSelStart > NUMDAYS || mSelStart < 0 ) 417 if( mSelStart > NUMDAYS || mSelStart < 0 )
418 mSelStart = mSelStart + tmp; 418 mSelStart = mSelStart + tmp;
419 if( mSelEnd > NUMDAYS || mSelEnd < 0 ) 419 if( mSelEnd > NUMDAYS || mSelEnd < 0 )
420 mSelEnd = mSelEnd + tmp; 420 mSelEnd = mSelEnd + tmp;
421 } 421 }
422 } 422 }
423 startdate = actdate; 423 startdate = actdate;
424 mDayChanged = true; 424 mDayChanged = true;
425 recalculateToday(); 425 recalculateToday();
426 mRedrawNeeded = true; 426 mRedrawNeeded = true;
427 } 427 }
428 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); 428 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() );
429 if ( !isVisible() ) { 429 if ( !isVisible() ) {
430 mPendingUpdateBeforeRepaint = true; 430 mPendingUpdateBeforeRepaint = true;
431 } else { 431 } else {
432#ifdef DESKTOP_VERSION 432#ifdef DESKTOP_VERSION
433 //mRepaintTimer->start( 100 ); 433 //mRepaintTimer->start( 100 );
434 //updateViewTimed(); 434 //updateViewTimed();
435 mUpdateTimer->start( 50 ); 435 mUpdateTimer->start( 50 );
436#else 436#else
437 mRepaintTimer->start( 350 ); 437 mRepaintTimer->start( 350 );
438 mUpdateTimer->start( 1200 ); 438 mUpdateTimer->start( 1200 );
439#endif 439#endif
440 } 440 }
441} 441}
442void KODayMatrix::updateEvents() 442void KODayMatrix::updateEvents()
443{ 443{
444 if ( !mCalendar ) return; 444 if ( !mCalendar ) return;
445 445
446 for( int i = 0; i < NUMDAYS; i++ ) { 446 for( int i = 0; i < NUMDAYS; i++ ) {
447 // if events are set for the day then remember to draw it bold 447 // if events are set for the day then remember to draw it bold
448 QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); 448 QPtrList<Event> eventlist = mCalendar->events( days[ i ] );
449 int numEvents = eventlist.count(); 449 int numEvents = eventlist.count();
450 Event *event; 450 Event *event;
451 for( event = eventlist.first(); event != 0;event=eventlist.next()) { 451 for( event = eventlist.first(); event != 0;event=eventlist.next()) {
452 ushort recurType = event->doesRecur(); 452 ushort recurType = event->doesRecur();
453 453
454 if ( ( recurType == Recurrence::rDaily && 454 if ( ( recurType == Recurrence::rDaily &&
455 !KOPrefs::instance()->mDailyRecur ) || 455 !KOPrefs::instance()->mDailyRecur ) ||
456 ( recurType == Recurrence::rWeekly && 456 ( recurType == Recurrence::rWeekly &&
457 !KOPrefs::instance()->mWeeklyRecur ) ) { 457 !KOPrefs::instance()->mWeeklyRecur ) ) {
458 numEvents--; 458 numEvents--;
459 } 459 }
460 } 460 }
461 if ( numEvents ) 461 if ( numEvents )
462 eDays.setBit(i); 462 eDays.setBit(i);
463 else 463 else
464 eDays.clearBit(i); 464 eDays.clearBit(i);
465 } 465 }
466} 466}
467 467
468const QDate& KODayMatrix::getDate(int offset) 468const QDate& KODayMatrix::getDate(int offset)
469{ 469{
470 if (offset < 0 || offset > NUMDAYS-1) { 470 if (offset < 0 || offset > NUMDAYS-1) {
471 qDebug("Wrong offset2 %d", offset); 471 qDebug("Wrong offset2 %d", offset);
472 return days[0]; 472 return days[0];
473 } 473 }
474 return days[offset]; 474 return days[offset];
475} 475}
476 476
477QString KODayMatrix::getHolidayLabel(int offset) 477QString KODayMatrix::getHolidayLabel(int offset)
478{ 478{
479 if (offset < 0 || offset > NUMDAYS-1) { 479 if (offset < 0 || offset > NUMDAYS-1) {
480 qDebug("Wrong offset1 %d", offset); 480 qDebug("Wrong offset1 %d", offset);
481 return QString(); 481 return QString();
482 } 482 }
483 return mHolidays[offset]; 483 return mHolidays[offset];
484} 484}
485 485
486int KODayMatrix::getDayIndexFrom(int x, int y) 486int KODayMatrix::getDayIndexFrom(int x, int y)
487{ 487{
488 int colModulo = (width()-2) % 7; 488 int colModulo = (width()-2) % 7;
489 int rowModulo = (height()-2) % 6; 489 int rowModulo = (height()-2) % 6;
490#if 0 490#if 0
491 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? 491 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
492 6 - x/daysize.width() : x/daysize.width()); 492 6 - x/daysize.width() : x/daysize.width());
493#endif 493#endif
494 int xVal = (x-colModulo/2-2)/daysize.width(); 494 int xVal = (x-colModulo/2-2)/daysize.width();
495 int yVal = (y-rowModulo/2-2)/daysize.height(); 495 int yVal = (y-rowModulo/2-2)/daysize.height();
496 496
497 497
498 return 7*(yVal) + xVal; 498 return 7*(yVal) + xVal;
499 499
500} 500}
501 501
502// ---------------------------------------------------------------------------- 502// ----------------------------------------------------------------------------
503// M O U S E E V E N T H A N D L I N G 503// M O U S E E V E N T H A N D L I N G
504// ---------------------------------------------------------------------------- 504// ----------------------------------------------------------------------------
505 505
506void KODayMatrix::mousePressEvent (QMouseEvent* e) 506void KODayMatrix::mousePressEvent (QMouseEvent* e)
507{ 507{
508 508
509 if ( e->button() == LeftButton ) 509 if ( e->button() == LeftButton )
510 mouseDown = true; 510 mouseDown = true;
511 mSelStart = getDayIndexFrom(e->x(), e->y()); 511 mSelStart = getDayIndexFrom(e->x(), e->y());
512 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; 512 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1;
513 mSelInit = mSelStart; 513 mSelInit = mSelStart;
514 mSelEnd = mSelStart; 514 mSelEnd = mSelStart;
515 mRedrawNeeded = true; 515 mRedrawNeeded = true;
516 repaint(false); 516 repaint(false);
517} 517}
518 518
519void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) 519void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
520{ 520{
521 mRedrawNeeded = true; 521 mRedrawNeeded = true;
522 if ( e->button() == LeftButton ) 522 if ( e->button() == LeftButton )
523 if ( ! mouseDown ) { 523 if ( ! mouseDown ) {
524 return; 524 return;
525 } 525 }
526 else 526 else
527 mouseDown = false; 527 mouseDown = false;
528 int tmp = getDayIndexFrom(e->x(), e->y()); 528 int tmp = getDayIndexFrom(e->x(), e->y());
529 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 529 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
530 530
531 if (mSelInit > tmp) { 531 if (mSelInit > tmp) {
532 mSelEnd = mSelInit; 532 mSelEnd = mSelInit;
533 if (tmp != mSelStart) { 533 if (tmp != mSelStart) {
534 mSelStart = tmp; 534 mSelStart = tmp;
535 repaint(false); 535 repaint(false);
536 } 536 }
537 } else { 537 } else {
538 mSelStart = mSelInit; 538 mSelStart = mSelInit;
539 539
540 //repaint only if selection has changed 540 //repaint only if selection has changed
541 if (tmp != mSelEnd) { 541 if (tmp != mSelEnd) {
542 mSelEnd = tmp; 542 mSelEnd = tmp;
543 repaint(false); 543 repaint(false);
544 } 544 }
545 } 545 }
546 546
547 DateList daylist; 547 DateList daylist;
548 if ( mSelStart < 0 ) 548 if ( mSelStart < 0 )
549 mSelStart = 0; 549 mSelStart = 0;
550 for (int i = mSelStart; i <= mSelEnd; i++) { 550 for (int i = mSelStart; i <= mSelEnd; i++) {
551 daylist.append(days[i]); 551 daylist.append(days[i]);
552 } 552 }
553 emit selected((const DateList)daylist); 553 emit selected((const DateList)daylist);
554 554
555} 555}
556 556
557void KODayMatrix::mouseMoveEvent (QMouseEvent* e) 557void KODayMatrix::mouseMoveEvent (QMouseEvent* e)
558{ 558{
559 if ( ! mouseDown ) { 559 if ( ! mouseDown ) {
560 return; 560 return;
561 } 561 }
562 mRedrawNeeded = true; 562 mRedrawNeeded = true;
563 int tmp = getDayIndexFrom(e->x(), e->y()); 563 int tmp = getDayIndexFrom(e->x(), e->y());
564 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 564 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
565 565
566 if (mSelInit > tmp) { 566 if (mSelInit > tmp) {
567 mSelEnd = mSelInit; 567 mSelEnd = mSelInit;
568 if (tmp != mSelStart) { 568 if (tmp != mSelStart) {
569 mSelStart = tmp; 569 mSelStart = tmp;
570 repaint(false); 570 repaint(false);
571 } 571 }
572 } else { 572 } else {
573 mSelStart = mSelInit; 573 mSelStart = mSelInit;
574 574
575 //repaint only if selection has changed 575 //repaint only if selection has changed
576 if (tmp != mSelEnd) { 576 if (tmp != mSelEnd) {
577 mSelEnd = tmp; 577 mSelEnd = tmp;
578 repaint(false); 578 repaint(false);
579 } 579 }
580 } 580 }
581} 581}
582 582
583// ---------------------------------------------------------------------------- 583// ----------------------------------------------------------------------------
584// D R A G ' N D R O P H A N D L I N G 584// D R A G ' N D R O P H A N D L I N G
585// ---------------------------------------------------------------------------- 585// ----------------------------------------------------------------------------
586 586
587void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) 587void KODayMatrix::dragEnterEvent(QDragEnterEvent *e)
588{ 588{
589#ifndef KORG_NODND 589#ifndef KORG_NODND
590 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 590 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
591 e->ignore(); 591 e->ignore();
592 return; 592 return;
593 } 593 }
594 594
595 // some visual feedback 595 // some visual feedback
596// oldPalette = palette(); 596// oldPalette = palette();
597// setPalette(my_HilitePalette); 597// setPalette(my_HilitePalette);
598// update(); 598// update();
599#endif 599#endif
600} 600}
601 601
602void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) 602void KODayMatrix::dragMoveEvent(QDragMoveEvent *e)
603{ 603{
604#ifndef KORG_NODND 604#ifndef KORG_NODND
605 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 605 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
606 e->ignore(); 606 e->ignore();
607 return; 607 return;
608 } 608 }
609 609
610 e->accept(); 610 e->accept();
611#endif 611#endif
612} 612}
613 613
614void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) 614void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/)
615{ 615{
616#ifndef KORG_NODND 616#ifndef KORG_NODND
617// setPalette(oldPalette); 617// setPalette(oldPalette);
618// update(); 618// update();
619#endif 619#endif
620} 620}
621 621
622void KODayMatrix::dropEvent(QDropEvent *e) 622void KODayMatrix::dropEvent(QDropEvent *e)
623{ 623{
624#ifndef KORG_NODND 624#ifndef KORG_NODND
625// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; 625// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl;
626 626
627 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 627 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
628 e->ignore(); 628 e->ignore();
629 return; 629 return;
630 } 630 }
631 631
632 DndFactory factory( mCalendar ); 632 DndFactory factory( mCalendar );
633 Event *event = factory.createDrop(e); 633 Event *event = factory.createDrop(e);
634 634
635 if (event) { 635 if (event) {
636 e->acceptAction(); 636 e->acceptAction();
637 637
638 Event *existingEvent = mCalendar->event(event->uid()); 638 Event *existingEvent = mCalendar->event(event->uid());
639 639
640 if(existingEvent) { 640 if(existingEvent) {
641 // uniquify event 641 // uniquify event
642 event->recreate(); 642 event->recreate();
643/* 643/*
644 KMessageBox::sorry(this, 644 KMessageBox::sorry(this,
645 i18n("Event already exists in this calendar."), 645 i18n("Event already exists in this calendar."),
646 i18n("Drop Event")); 646 i18n("Drop Event"));
647 delete event; 647 delete event;
648 return; 648 return;
649*/ 649*/
650 } 650 }
651// kdDebug() << "Drop new Event" << endl; 651// kdDebug() << "Drop new Event" << endl;
652 // Adjust date 652 // Adjust date
653 QDateTime start = event->dtStart(); 653 QDateTime start = event->dtStart();
654 QDateTime end = event->dtEnd(); 654 QDateTime end = event->dtEnd();
655 int duration = start.daysTo(end); 655 int duration = start.daysTo(end);
656 int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); 656 int idx = getDayIndexFrom(e->pos().x(), e->pos().y());
657 657
658 start.setDate(days[idx]); 658 start.setDate(days[idx]);
659 end.setDate(days[idx].addDays(duration)); 659 end.setDate(days[idx].addDays(duration));
660 660
661 event->setDtStart(start); 661 event->setDtStart(start);
662 event->setDtEnd(end); 662 event->setDtEnd(end);
663 mCalendar->addEvent(event); 663 mCalendar->addEvent(event);
664 664
665 emit eventDropped(event); 665 emit eventDropped(event);
666 } else { 666 } else {
667// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; 667// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl;
668 e->ignore(); 668 e->ignore();
669 } 669 }
670#endif 670#endif
671} 671}
672 672
673// ---------------------------------------------------------------------------- 673// ----------------------------------------------------------------------------
674// P A I N T E V E N T H A N D L I N G 674// P A I N T E V E N T H A N D L I N G
675// ---------------------------------------------------------------------------- 675// ----------------------------------------------------------------------------
676 676
677void KODayMatrix::paintEvent(QPaintEvent * pevent) 677void KODayMatrix::paintEvent(QPaintEvent * pevent)
678{ 678{
679 679
680 if ( width() <= 0 || height() <= 0 ) 680 if ( width() <= 0 || height() <= 0 )
681 return; 681 return;
682 if ( mPendingUpdateBeforeRepaint ) { 682 if ( mPendingUpdateBeforeRepaint ) {
683 updateViewTimed(); 683 updateViewTimed();
684 mPendingUpdateBeforeRepaint = false; 684 mPendingUpdateBeforeRepaint = false;
685 } 685 }
686 if ( myPix.width() != width() || myPix.height()!=height() ) { 686 if ( myPix.width() != width() || myPix.height()!=height() ) {
687 myPix.resize(size() ); 687 myPix.resize(size() );
688 mRedrawNeeded = true; 688 mRedrawNeeded = true;
689 } 689 }
690 690
691 if ( mRedrawNeeded ) { 691 if ( mRedrawNeeded ) {
692 //qDebug("REDRAW "); 692 //qDebug("REDRAW ");
693 QPainter p(&myPix); 693 QPainter p(&myPix);
694 p.setFont(font()); 694 p.setFont(font());
695 695
696 696
697 int dheight = daysize.height(); 697 int dheight = daysize.height();
698 int dwidth = daysize.width(); 698 int dwidth = daysize.width();
699 int row,col; 699 int row,col;
700 int selw, selh; 700 int selw, selh;
701 int xyOff = frameWidth(); 701 int xyOff = frameWidth();
702 int colModulo = (width()-2) % 7; 702 int colModulo = (width()-2) % 7;
703 int rowModulo = (height()-2) % 6; 703 int rowModulo = (height()-2) % 6;
704 //qDebug("col %d row %d ",colModulo,rowModulo ); 704 //qDebug("col %d row %d ",colModulo,rowModulo );
705 705
706 bool isRTL = KOGlobals::self()->reverseLayout(); 706 bool isRTL = KOGlobals::self()->reverseLayout();
707 707
708 // draw background and topleft frame 708 // draw background and topleft frame
709 p.fillRect(0,0,width(),height(), mDefaultBackColor); 709 p.fillRect(0,0,width(),height(), mDefaultBackColor);
710 p.setPen(mDefaultTextColor); 710 p.setPen(mDefaultTextColor);
711 p.drawRect(0, 0, width(), height()); 711 p.drawRect(0, 0, width(), height());
712 int mSelStartT = mSelStart; 712 int mSelStartT = mSelStart;
713 int mSelEndT = mSelEnd; 713 int mSelEndT = mSelEnd;
714 if ( mSelEndT >= NUMDAYS ) 714 if ( mSelEndT >= NUMDAYS )
715 mSelEndT = NUMDAYS-1; 715 mSelEndT = NUMDAYS-1;
716 // draw selected days with highlighted background color 716 // draw selected days with highlighted background color
717 if (mSelStart != NOSELECTION) { 717 if (mSelStart != NOSELECTION) {
718 bool skip = false; 718 bool skip = false;
719 if ( ! mouseDown ) { 719 if ( ! mouseDown ) {
720 int mo = days[20].month(); 720 int mo = days[20].month();
721 //qDebug("-- %d %d ", mSelStartT, mSelEndT); 721 //qDebug("-- %d %d ", mSelStartT, mSelEndT);
722 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); 722 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() );
723 int startMo = days[mSelStartT].month(); 723 int startMo = days[mSelStartT].month();
724 int endMo = days[mSelEndT].month(); 724 int endMo = days[mSelEndT].month();
725 if ( startMo == 12 && mo == 1 && endMo <= 2 ) 725 if ( startMo == 12 && mo == 1 && endMo <= 2 )
726 startMo = 1; 726 startMo = 1;
727 if ( endMo == 1 && mo == 12 ) 727 if ( endMo == 1 && mo == 12 )
728 endMo = 12; 728 endMo = 12;
729 if ( mo == 12 && startMo == 1 ) 729 if ( mo == 12 && startMo == 1 )
730 startMo = 13; 730 startMo = 13;
731 if ( (startMo > mo || endMo < mo) ) { 731 if ( (startMo > mo || endMo < mo) ) {
732 skip = true; 732 skip = true;
733 } else { 733 } else {
734 if ( days[mSelStartT].month() != mo ) { 734 if ( days[mSelStartT].month() != mo ) {
735 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); 735 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day();
736 mSelStartT += add +1; 736 mSelStartT += add +1;
737 } 737 }
738 if ( days[mSelEndT].month() != mo ) { 738 if ( days[mSelEndT].month() != mo ) {
739 int sub = days[mSelEndT].day(); 739 int sub = days[mSelEndT].day();
740 mSelEndT -= sub ; 740 mSelEndT -= sub ;
741 } 741 }
742 } 742 }
743 } 743 }
744 //qDebug("SKIP %d ", skip); 744 //qDebug("SKIP %d ", skip);
745 if ( ! skip ) { 745 if ( ! skip ) {
746 row = mSelStartT/7; 746 row = mSelStartT/7;
747 col = mSelStartT -row*7; 747 col = mSelStartT -row*7;
748 QColor selcol = KOPrefs::instance()->mHighlightColor; 748 QColor selcol = KOPrefs::instance()->mHighlightColor;
749 int addCol = 0; 749 int addCol = 0;
750 int addRow = 0; 750 int addRow = 0;
751 int addRow2 = 0; 751 int addRow2 = 0;
752 int addCol2 = 0; 752 int addCol2 = 0;
753 if (row == mSelEndT/7) { 753 if (row == mSelEndT/7) {
754 if ( rowModulo ) { 754 if ( rowModulo ) {
755 if ( row >= 6 - rowModulo ) 755 if ( row >= 6 - rowModulo )
756 addRow = row - 5 + rowModulo; 756 addRow = row - 5 + rowModulo;
757 } 757 }
758 if ( colModulo ) { 758 if ( colModulo ) {
759 int colt1 = mSelEndT%7; 759 int colt1 = mSelEndT%7;
760 //qDebug("colt1 %d ", colt1 ); 760 //qDebug("colt1 %d ", colt1 );
761 if ( colt1 >= 7 - colModulo ) 761 if ( colt1 >= 7 - colModulo )
762 addCol = colt1 - 7 + colModulo+1; 762 addCol = colt1 - 7 + colModulo+1;
763 int colt = mSelStartT%7; 763 int colt = mSelStartT%7;
764 if ( colt >= 7 - colModulo ) 764 if ( colt >= 7 - colModulo )
765 addCol2 = colt - 7 + colModulo; 765 addCol2 = colt - 7 + colModulo;
766 addCol -= addCol2; 766 addCol -= addCol2;
767 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); 767 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 );
768 } 768 }
769 // Single row selection 769 // Single row selection
770 if ( row == 0) 770 if ( row == 0)
771 addRow = 1; 771 addRow = 1;
772 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, 772 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2,
773 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); 773 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol);
774 } else { 774 } else {
775 // draw first row to the right 775 // draw first row to the right
776 if ( colModulo ) { 776 if ( colModulo ) {
777 if ( col >= 7 - colModulo ) 777 if ( col >= 7 - colModulo )
778 addCol2 = col - 7 + colModulo; 778 addCol2 = col - 7 + colModulo;
779 } 779 }
780 if ( rowModulo ) { 780 if ( rowModulo ) {
781 if ( row >= 6 - rowModulo ) 781 if ( row >= 6 - rowModulo )
782 addRow = row - 5 + rowModulo; 782 addRow = row - 5 + rowModulo;
783 } 783 }
784 if ( row == 0) 784 if ( row == 0)
785 addRow = 1; 785 addRow = 1;
786 int drawWid = width()-(col*dwidth+1+addCol2)-1; 786 int drawWid = width()-(col*dwidth+1+addCol2)-1;
787 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, drawWid, 787 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, drawWid,
788 dheight+1, selcol); 788 dheight+1, selcol);
789 // draw full block till last line 789 // draw full block till last line
790 selh = mSelEndT/7-row; 790 selh = mSelEndT/7-row;
791 addRow = 0; 791 addRow = 0;
792 if ( rowModulo ) { 792 if ( rowModulo ) {
793 if ( mSelEndT/7 >= 6 - rowModulo ) 793 if ( mSelEndT/7 >= 6 - rowModulo )
794 addRow = mSelEndT/7 - 5 + rowModulo; 794 addRow = mSelEndT/7 - 5 + rowModulo;
795 } 795 }
796 if (selh > 1) { 796 if (selh > 1) {
797 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol); 797 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol);
798 } 798 }
799 // draw last block from left to mSelEndT 799 // draw last block from left to mSelEndT
800 selw = mSelEndT-7*(mSelEndT/7)+1; 800 selw = mSelEndT-7*(mSelEndT/7)+1;
801 //qDebug("esl %d ",selw ); 801 //qDebug("esl %d ",selw );
802 int add = 0; 802 int add = 0;
803 if ( colModulo ) { 803 if ( colModulo ) {
804 add = 7 - colModulo; 804 add = 7 - colModulo;
805 if ( selw > add ) 805 if ( selw > add )
806 add = selw - add; 806 add = selw - add;
807 else 807 else
808 add = 0; 808 add = 0;
809 } 809 }
810 //qDebug("add %d ", add); 810 //qDebug("add %d ", add);
811 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow, 811 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow,
812 selw*dwidth+add, dheight+1, selcol); 812 selw*dwidth+add, dheight+1, selcol);
813 } 813 }
814 } 814 }
815 } 815 }
816 816
817 // iterate over all days in the matrix and draw the day label in appropriate colors 817 // iterate over all days in the matrix and draw the day label in appropriate colors
818 QColor actcol = mDefaultTextColorShaded; 818 QColor actcol = mDefaultTextColorShaded;
819 p.setPen(actcol); 819 p.setPen(actcol);
820 QPen tmppen; 820 QPen tmppen;
821 for(int i = 0; i < NUMDAYS; i++) { 821 for(int i = 0; i < NUMDAYS; i++) {
822 row = i/7; 822 row = i/7;
823 col = isRTL ? 6-(i-row*7) : i-row*7; 823 col = isRTL ? 6-(i-row*7) : i-row*7;
824 824
825 // if it is the first day of a month switch color from normal to shaded and vice versa 825 // if it is the first day of a month switch color from normal to shaded and vice versa
826 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { 826 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) {
827 if (actcol == mDefaultTextColorShaded) { 827 if (actcol == mDefaultTextColorShaded) {
828 actcol = mDefaultTextColor; 828 actcol = mDefaultTextColor;
829 } else { 829 } else {
830 actcol = mDefaultTextColorShaded; 830 actcol = mDefaultTextColorShaded;
831 } 831 }
832 p.setPen(actcol); 832 p.setPen(actcol);
833 } 833 }
834 if (actcol == mDefaultTextColorShaded) { 834 if (actcol == mDefaultTextColorShaded) {
835 if ( ! mouseDown ) { 835 if ( ! mouseDown ) {
836 continue; 836 continue;
837 } 837 }
838 } 838 }
839 //Reset pen color after selected days block 839 //Reset pen color after selected days block
840 if (i == mSelEndT+1) { 840 if (i == mSelEndT+1) {
841 p.setPen(actcol); 841 p.setPen(actcol);
842 } 842 }
843 843
844 // if today then draw rectangle around day 844 // if today then draw rectangle around day
845 if (today == i) { 845 if (today == i) {
846 tmppen = p.pen(); 846 tmppen = p.pen();
847 QPen mTodayPen(p.pen()); 847 QPen mTodayPen(p.pen());
848 if ( daysize.width() < 20 ) 848 if ( daysize.width() < 20 )
849 mTodayPen.setWidth(1); 849 mTodayPen.setWidth(1);
850 else 850 else
851 mTodayPen.setWidth(mTodayMarginWidth); 851 mTodayPen.setWidth(mTodayMarginWidth);
852 //draw red rectangle for holidays 852 //draw red rectangle for holidays
853 if (!mHolidays[i].isNull()) { 853 if (!mHolidays[i].isNull()) {
854 if (actcol == mDefaultTextColor) { 854 if (actcol == mDefaultTextColor) {
855 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); 855 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor);
856 } else { 856 } else {
857 mTodayPen.setColor(mHolidayColorShaded); 857 mTodayPen.setColor(mHolidayColorShaded);
858 } 858 }
859 } 859 }
860 //draw gray rectangle for today if in selection 860 //draw gray rectangle for today if in selection
861 if (i >= mSelStartT && i <= mSelEndT) { 861 if (i >= mSelStartT && i <= mSelEndT) {
862 QColor grey("grey"); 862 QColor grey("grey");
863 mTodayPen.setColor(grey); 863 mTodayPen.setColor(grey);
864 } 864 }
865 p.setPen(mTodayPen); 865 p.setPen(mTodayPen);
866 866
867 867
868 int addCol = 0; 868 int addCol = 0;
869 int addRow = 0; 869 int addRow = 0;
870 if (rowModulo) { 870 if (rowModulo) {
871 if ( row >= 6 - rowModulo ) 871 if ( row >= 6 - rowModulo )
872 addRow = row - 5 + rowModulo; 872 addRow = row - 5 + rowModulo;
873 } 873 }
874 if ( colModulo ) { 874 if ( colModulo ) {
875 if ( col >= 7 - colModulo ) 875 if ( col >= 7 - colModulo )
876 addCol = col - 6 + colModulo-1; 876 addCol = col - 6 + colModulo-1;
877 } 877 }
878 878
879 addCol += 1; 879 addCol += 1;
880 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight+1); 880 if ( row == 0 )
881 addRow = 1;
882 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth+1, dheight+1);
881 p.setPen(tmppen); 883 p.setPen(tmppen);
882 } 884 }
883 885
884 // if any events are on that day then draw it using a bold font 886 // if any events are on that day then draw it using a bold font
885 if ( eDays.testBit(i) ) { 887 if ( eDays.testBit(i) ) {
886 QFont myFont = font(); 888 QFont myFont = font();
887 myFont.setBold(true); 889 myFont.setBold(true);
888 p.setFont(myFont); 890 p.setFont(myFont);
889 } 891 }
890 892
891 // if it is a holiday then use the default holiday color 893 // if it is a holiday then use the default holiday color
892 if ( !mHolidays[i].isNull()) { 894 if ( !mHolidays[i].isNull()) {
893 if ( bDays.testBit(i) ) { 895 if ( bDays.testBit(i) ) {
894 if ( hDays.testBit(i) ) 896 if ( hDays.testBit(i) )
895 p.setPen(QColor(Qt::green)); 897 p.setPen(QColor(Qt::green));
896 else 898 else
897 p.setPen(QColor(Qt::green).dark()); 899 p.setPen(QColor(Qt::green).dark());
898 } else { 900 } else {
899 if (actcol == mDefaultTextColor ) { 901 if (actcol == mDefaultTextColor ) {
900 p.setPen(KOPrefs::instance()->mHolidayColor); 902 p.setPen(KOPrefs::instance()->mHolidayColor);
901 } else { 903 } else {
902 p.setPen(mHolidayColorShaded); 904 p.setPen(mHolidayColorShaded);
903 } 905 }
904 } 906 }
905 } 907 }
906 908
907 // draw selected days with special color 909 // draw selected days with special color
908 // DO NOT specially highlight holidays in selection ! 910 // DO NOT specially highlight holidays in selection !
909 if (i >= mSelStartT && i <= mSelEndT) { 911 if (i >= mSelStartT && i <= mSelEndT) {
910 ;//p.setPen(mSelectedDaysColor); 912 ;//p.setPen(mSelectedDaysColor);
911 } 913 }
912 914
913 int addCol = 0; 915 int addCol = 0;
914 int addRow = 0; 916 int addRow = 0;
915 if ( colModulo ) { 917 if ( colModulo ) {
916 if ( col >= 7 - colModulo ) 918 if ( col >= 7 - colModulo )
917 addCol = col - 7 + colModulo; 919 addCol = col - 7 + colModulo;
918 } 920 }
919 if ( rowModulo ) { 921 if ( rowModulo ) {
920 if ( row >= 6 - rowModulo ) 922 if ( row >= 6 - rowModulo )
921 addRow = row - 5 + rowModulo; 923 addRow = row - 5 + rowModulo;
922 } 924 }
923 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); 925 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow);
924 ++addCol;//++addCol; 926 ++addCol;//++addCol;
925 if ( row == 0) 927 if ( row == 0)
926 addRow = 1; 928 addRow = 1;
927 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, 929 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight,
928 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); 930 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]);
929 931
930 // reset color to actual color 932 // reset color to actual color
931 if (!mHolidays[i].isNull()) { 933 if (!mHolidays[i].isNull()) {
932 p.setPen(actcol); 934 p.setPen(actcol);
933 } 935 }
934 // reset bold font to plain font 936 // reset bold font to plain font
935 if ( eDays.testBit(i)) { 937 if ( eDays.testBit(i)) {
936 QFont myFont = font(); 938 QFont myFont = font();
937 myFont.setBold(false); 939 myFont.setBold(false);
938 p.setFont(myFont); 940 p.setFont(myFont);
939 } 941 }
940 } 942 }
941 } else { 943 } else {
942 //qDebug("NO redraw "); 944 //qDebug("NO redraw ");
943 } 945 }
944 bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP); 946 bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP);
945 mRedrawNeeded = false; 947 mRedrawNeeded = false;
946} 948}
947 949
948// ---------------------------------------------------------------------------- 950// ----------------------------------------------------------------------------
949// R E SI Z E E V E N T H A N D L I N G 951// R E SI Z E E V E N T H A N D L I N G
950// ---------------------------------------------------------------------------- 952// ----------------------------------------------------------------------------
951 953
952void KODayMatrix::resizeEvent(QResizeEvent *) 954void KODayMatrix::resizeEvent(QResizeEvent *)
953{ 955{
954 QRect sz = frameRect(); 956 QRect sz = frameRect();
955 daysize.setHeight(sz.height()*7 / NUMDAYS); 957 daysize.setHeight(sz.height()*7 / NUMDAYS);
956 daysize.setWidth(sz.width() / 7); 958 daysize.setWidth(sz.width() / 7);
957} 959}
958 960
959QSize KODayMatrix::sizeHint() const 961QSize KODayMatrix::sizeHint() const
960{ 962{
961 963
962 QFontMetrics fm ( font() ); 964 QFontMetrics fm ( font() );
963 int wid = fm.width( "30") *7+3; 965 int wid = fm.width( "30") *7+3;
964 int hei = fm.height() * 6+3; 966 int hei = fm.height() * 6+3;
965 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); 967 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei);
966 return QSize ( wid, hei ); 968 return QSize ( wid, hei );
967 969
968} 970}