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