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