summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/komonthview.cpp88
1 files changed, 55 insertions, 33 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp
index 8ee5bc3..050bfb9 100644
--- a/korganizer/komonthview.cpp
+++ b/korganizer/komonthview.cpp
@@ -1,1564 +1,1586 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <qpopupmenu.h> 20#include <qpopupmenu.h>
21#include <qfont.h> 21#include <qfont.h>
22#include <qfontmetrics.h> 22#include <qfontmetrics.h>
23#include <qkeycode.h> 23#include <qkeycode.h>
24#include <qhbox.h> 24#include <qhbox.h>
25#include <qvbox.h> 25#include <qvbox.h>
26#include <qwidgetstack.h> 26#include <qwidgetstack.h>
27#include <qpushbutton.h> 27#include <qpushbutton.h>
28#include <qtooltip.h> 28#include <qtooltip.h>
29#include <qpainter.h> 29#include <qpainter.h>
30#include <qtimer.h> 30#include <qtimer.h>
31#include <qwhatsthis.h> 31#include <qwhatsthis.h>
32#ifndef DESKTOP_VERSION 32#ifndef DESKTOP_VERSION
33#include <qpe/qpeapplication.h> 33#include <qpe/qpeapplication.h>
34#else 34#else
35#include <qapplication.h> 35#include <qapplication.h>
36#endif 36#endif
37 37
38#include <kdebug.h> 38#include <kdebug.h>
39#include <klocale.h> 39#include <klocale.h>
40#include <kglobal.h> 40#include <kglobal.h>
41#include <kconfig.h> 41#include <kconfig.h>
42#include <kiconloader.h> 42#include <kiconloader.h>
43 43
44#include <kcalendarsystem.h> 44#include <kcalendarsystem.h>
45 45
46#ifndef KORG_NOPRINTER 46#ifndef KORG_NOPRINTER
47#include "calprinter.h" 47#include "calprinter.h"
48#endif 48#endif
49#include "koprefs.h" 49#include "koprefs.h"
50#ifndef KORG_NOPLUGINS 50#ifndef KORG_NOPLUGINS
51#include "kocore.h" 51#include "kocore.h"
52#endif 52#endif
53#include "koglobals.h" 53#include "koglobals.h"
54#include <libkcal/kincidenceformatter.h> 54#include <libkcal/kincidenceformatter.h>
55 55
56#include "komonthview.h" 56#include "komonthview.h"
57 57
58#define PIXMAP_SIZE 5 58#define PIXMAP_SIZE 5
59#ifdef DESKTOP_VERSION 59#ifdef DESKTOP_VERSION
60QToolTipGroup *MonthViewCell::mToolTipGroup = 0; 60QToolTipGroup *MonthViewCell::mToolTipGroup = 0;
61#endif 61#endif
62class KNOWhatsThis :public QWhatsThis 62class KNOWhatsThis :public QWhatsThis
63{ 63{
64public: 64public:
65 KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { }; 65 KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { };
66 //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); }; 66 //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); };
67 67
68protected: 68protected:
69 virtual QString text( const QPoint& p) 69 virtual QString text( const QPoint& p)
70 { 70 {
71 return _wid->getWhatsThisText(p) ; 71 return _wid->getWhatsThisText(p) ;
72 }; 72 };
73private: 73private:
74 KNoScrollListBox* _wid; 74 KNoScrollListBox* _wid;
75 75
76}; 76};
77 77
78 78
79KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) 79KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name)
80 : QListBox(parent, name, WRepaintNoErase) 80 : QListBox(parent, name, WRepaintNoErase)
81{ 81{
82#ifndef DESKTOP_VERSION 82#ifndef DESKTOP_VERSION
83 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 83 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
84#endif 84#endif
85 mWT = new KNOWhatsThis(this); 85 mWT = new KNOWhatsThis(this);
86} 86}
87KNoScrollListBox::~KNoScrollListBox() 87KNoScrollListBox::~KNoScrollListBox()
88{ 88{
89 89
90} 90}
91QString KNoScrollListBox::getWhatsThisText(QPoint p) 91QString KNoScrollListBox::getWhatsThisText(QPoint p)
92{ 92{
93 QListBoxItem* item = itemAt ( p ); 93 QListBoxItem* item = itemAt ( p );
94 if ( ! item ) { 94 if ( ! item ) {
95 return i18n("Click in the cell\nto add an event!"); 95 return i18n("Click in the cell\nto add an event!");
96 } 96 }
97 return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence(), 97 return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence(),
98 KOPrefs::instance()->mWTshowDetails, 98 KOPrefs::instance()->mWTshowDetails,
99 KOPrefs::instance()->mWTshowCreated, 99 KOPrefs::instance()->mWTshowCreated,
100 KOPrefs::instance()->mWTshowChanged); 100 KOPrefs::instance()->mWTshowChanged);
101} 101}
102void KNoScrollListBox::keyPressEvent(QKeyEvent *e) 102void KNoScrollListBox::keyPressEvent(QKeyEvent *e)
103{ 103{
104 104
105 switch(e->key()) { 105 switch(e->key()) {
106 case Key_Right: 106 case Key_Right:
107 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 107 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
108 { 108 {
109 e->ignore(); 109 e->ignore();
110 return; 110 return;
111 } 111 }
112 scrollBy(10,0); 112 scrollBy(10,0);
113 break; 113 break;
114 case Key_Left: 114 case Key_Left:
115 if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 115 if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
116 { 116 {
117 e->ignore(); 117 e->ignore();
118 return; 118 return;
119 } 119 }
120 scrollBy(-10,0); 120 scrollBy(-10,0);
121 break; 121 break;
122 case Key_Up: 122 case Key_Up:
123 if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { 123 if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) {
124 e->ignore(); 124 e->ignore();
125 break; 125 break;
126 } 126 }
127 setCurrentItem((currentItem()+count()-1)%count()); 127 setCurrentItem((currentItem()+count()-1)%count());
128 if(!itemVisible(currentItem())) { 128 if(!itemVisible(currentItem())) {
129 if((unsigned int) currentItem() == (count()-1)) { 129 if((unsigned int) currentItem() == (count()-1)) {
130 setTopItem(currentItem()-numItemsVisible()+1); 130 setTopItem(currentItem()-numItemsVisible()+1);
131 } else { 131 } else {
132 setTopItem(topItem()-1); 132 setTopItem(topItem()-1);
133 } 133 }
134 } 134 }
135 break; 135 break;
136 case Key_Down: 136 case Key_Down:
137 if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { 137 if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) {
138 e->ignore(); 138 e->ignore();
139 break; 139 break;
140 } 140 }
141 setCurrentItem((currentItem()+1)%count()); 141 setCurrentItem((currentItem()+1)%count());
142 if(!itemVisible(currentItem())) { 142 if(!itemVisible(currentItem())) {
143 if(currentItem() == 0) { 143 if(currentItem() == 0) {
144 setTopItem(0); 144 setTopItem(0);
145 } else { 145 } else {
146 setTopItem(topItem()+1); 146 setTopItem(topItem()+1);
147 } 147 }
148 } 148 }
149 break; 149 break;
150 case Key_I: 150 case Key_I:
151 QTimer::singleShot( 11, this, SLOT ( oneDown() ) ); 151 QTimer::singleShot( 11, this, SLOT ( oneDown() ) );
152 e->ignore(); 152 e->ignore();
153 break; 153 break;
154 case Key_Shift: 154 case Key_Shift:
155 emit shiftDown(); 155 emit shiftDown();
156 break; 156 break;
157 default: 157 default:
158 e->ignore(); 158 e->ignore();
159 break; 159 break;
160 } 160 }
161} 161}
162 162
163void KNoScrollListBox::oneDown() 163void KNoScrollListBox::oneDown()
164{ 164{
165 setCurrentItem((currentItem()+1)%count()); 165 setCurrentItem((currentItem()+1)%count());
166 if(!itemVisible(currentItem())) { 166 if(!itemVisible(currentItem())) {
167 if(currentItem() == 0) { 167 if(currentItem() == 0) {
168 setTopItem(0); 168 setTopItem(0);
169 } else { 169 } else {
170 setTopItem(topItem()+1); 170 setTopItem(topItem()+1);
171 } 171 }
172 } 172 }
173} 173}
174void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) 174void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e)
175{ 175{
176 switch(e->key()) { 176 switch(e->key()) {
177 case Key_Shift: 177 case Key_Shift:
178 emit shiftUp(); 178 emit shiftUp();
179 break; 179 break;
180 default: 180 default:
181 break; 181 break;
182 } 182 }
183} 183}
184 184
185void KNoScrollListBox::mousePressEvent(QMouseEvent *e) 185void KNoScrollListBox::mousePressEvent(QMouseEvent *e)
186{ 186{
187 QListBox::mousePressEvent(e); 187 QListBox::mousePressEvent(e);
188 188
189 if(e->button() == RightButton) { 189 if(e->button() == RightButton) {
190 emit rightClick(); 190 emit rightClick();
191 } 191 }
192} 192}
193 193
194MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) 194MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s)
195 : QListBoxItem() 195 : QListBoxItem()
196{ 196{
197 setText( s ); 197 setText( s );
198 mMultiday = 0; 198 mMultiday = 0;
199 mIncidence = incidence; 199 mIncidence = incidence;
200 mDate = qd; 200 mDate = qd;
201 mRecur = false; 201 mRecur = false;
202 mAlarm = false; 202 mAlarm = false;
203 mReply = false; 203 mReply = false;
204 mInfo = false; 204 mInfo = false;
205} 205}
206 206
207void MonthViewItem::paint(QPainter *p) 207void MonthViewItem::paint(QPainter *p)
208{ 208{
209#if QT_VERSION >= 0x030000 209#if QT_VERSION >= 0x030000
210 bool sel = isSelected(); 210 bool sel = isSelected();
211#else 211#else
212 bool sel = selected(); 212 bool sel = selected();
213#endif 213#endif
214 214
215 215
216 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) 216 if (KOPrefs::instance()->mMonthViewUsesCategoryColor)
217 { 217 {
218 p->setBackgroundColor( palette().color( QPalette::Normal, \ 218 p->setBackgroundColor( palette().color( QPalette::Normal, \
219 sel ? QColorGroup::Highlight : QColorGroup::Background ) ); 219 sel ? QColorGroup::Highlight : QColorGroup::Background ) );
220 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); 220 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) );
221 } 221 }
222 int x = 1; 222 int x = 1;
223 //int y = 3;//(height() - mRecurPixmap.height()) /2; 223 //int y = 3;//(height() - mRecurPixmap.height()) /2;
224 int size = PIXMAP_SIZE; 224 int size = PIXMAP_SIZE;
225 if ( QApplication::desktop()->width() < 300 ) 225 if ( QApplication::desktop()->width() < 300 )
226 size = 3; 226 size = 3;
227 int heihei = height( listBox () ); 227 int heihei = height( listBox () );
228 int y = (heihei - size -1 ) /2; 228 int y = (heihei - size -1 ) /2;
229 229
230 if ( KOPrefs::instance()->mMonthShowIcons ) { 230 if ( KOPrefs::instance()->mMonthShowIcons ) {
231 if ( mInfo ) { 231 if ( mInfo ) {
232 p->fillRect ( x, y,size,size, Qt::darkGreen ); 232 p->fillRect ( x, y,size,size, Qt::darkGreen );
233 x += size + 1; 233 x += size + 1;
234 } 234 }
235 if ( mRecur ) { 235 if ( mRecur ) {
236 p->fillRect ( x, y,size,size, Qt::blue ); 236 p->fillRect ( x, y,size,size, Qt::blue );
237 x += size + 1; 237 x += size + 1;
238 } 238 }
239 if ( mAlarm ) { 239 if ( mAlarm ) {
240 p->fillRect ( x, y,size,size, Qt::red ); 240 p->fillRect ( x, y,size,size, Qt::red );
241 x += size + 1; 241 x += size + 1;
242 } 242 }
243 if ( mReply ) { 243 if ( mReply ) {
244 p->fillRect ( x, y,size,size, Qt::yellow ); 244 p->fillRect ( x, y,size,size, Qt::yellow );
245 x += size + 1; 245 x += size + 1;
246 } 246 }
247 } 247 }
248 if ( mMultiday ) { 248 if ( mMultiday ) {
249 int yyy = y+(size/2); 249 int yyy = y+(size/2);
250 int sizeM = size+2; 250 int sizeM = size+2;
251 p->setBrush( QBrush::SolidPattern ); 251 p->setBrush( QBrush::SolidPattern );
252 p->drawLine ( x+1, yyy, x +sizeM +sizeM/2-1, yyy ) ; 252 p->drawLine ( x+1, yyy, x +sizeM +sizeM/2-1, yyy ) ;
253 if ( mMultiday == 2 || mMultiday == 3 ) { 253 if ( mMultiday == 2 || mMultiday == 3 ) {
254 QPointArray pa ( 3 ); 254 QPointArray pa ( 3 );
255 pa.setPoint (0, x, yyy ); 255 pa.setPoint (0, x, yyy );
256 pa.setPoint (1, x+sizeM/2, yyy+sizeM/2 ); 256 pa.setPoint (1, x+sizeM/2, yyy+sizeM/2 );
257 pa.setPoint (2, x+sizeM/2, yyy-sizeM/2 ); 257 pa.setPoint (2, x+sizeM/2, yyy-sizeM/2 );
258 p->drawPolygon( pa ); 258 p->drawPolygon( pa );
259 } 259 }
260 if ( mMultiday == 2 || mMultiday == 1 ) { 260 if ( mMultiday == 2 || mMultiday == 1 ) {
261 QPointArray pa ( 3 ); 261 QPointArray pa ( 3 );
262 pa.setPoint (0, x+sizeM +sizeM/2, yyy ); 262 pa.setPoint (0, x+sizeM +sizeM/2, yyy );
263 pa.setPoint (1, x+sizeM, yyy+sizeM/2 ); 263 pa.setPoint (1, x+sizeM, yyy+sizeM/2 );
264 pa.setPoint (2, x+sizeM, yyy-sizeM/2 ); 264 pa.setPoint (2, x+sizeM, yyy-sizeM/2 );
265 p->drawPolygon( pa ); 265 p->drawPolygon( pa );
266 } 266 }
267 if ( mMultiday == 1 ) { 267 if ( mMultiday == 1 ) {
268 // p->fillRect ( x, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); 268 // p->fillRect ( x, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) );
269 269
270 p->drawLine ( x+1, yyy-sizeM/2, x+1, yyy+sizeM/2 ); 270 p->drawLine ( x+1, yyy-sizeM/2, x+1, yyy+sizeM/2 );
271 } 271 }
272 if ( mMultiday == 3 ) { 272 if ( mMultiday == 3 ) {
273 // p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); 273 // p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) );
274 p->drawLine ( x+sizeM +sizeM/2-1, yyy-sizeM/2, x+sizeM +sizeM/2-1, yyy+sizeM/2 ); 274 p->drawLine ( x+sizeM +sizeM/2-1, yyy-sizeM/2, x+sizeM +sizeM/2-1, yyy+sizeM/2 );
275 275
276 } 276 }
277 x += sizeM/2 + 1; 277 x += sizeM/2 + 1;
278 x += sizeM + 1; 278 x += sizeM + 1;
279 } 279 }
280 280
281 if ( mIncidence->type() == "Todo" ){ 281 if ( mIncidence->type() == "Todo" ){
282 Todo* td = ( Todo* ) mIncidence; 282 Todo* td = ( Todo* ) mIncidence;
283 if ( td->isCompleted() ) { 283 if ( td->isCompleted() ) {
284 int half = size/2; 284 int half = size/2;
285 p->drawLine ( x, heihei/2, x +half , heihei/2 +half ) ; 285 p->drawLine ( x, heihei/2, x +half , heihei/2 +half ) ;
286 p->drawLine ( x +half , heihei/2 +half , x +half+half +2 , heihei/2 -2 ) ; 286 p->drawLine ( x +half , heihei/2 +half , x +half+half +2 , heihei/2 -2 ) ;
287 x += half+half + 4; 287 x += half+half + 4;
288 288
289 } else { 289 } else {
290 int val = td->percentComplete()/20; 290 int val = td->percentComplete()/20;
291 p->fillRect ( x+1, y-1, val ,size+2,Qt::black ); 291 p->fillRect ( x+1, y-1, val ,size+2,Qt::black );
292 p->drawRect ( x, y-1,7,size+2); 292 p->drawRect ( x, y-1,7,size+2);
293 x += size + 3; 293 x += size + 3;
294 } 294 }
295 } 295 }
296 QFontMetrics fm = p->fontMetrics(); 296 QFontMetrics fm = p->fontMetrics();
297 int yPos; 297 int yPos;
298 int pmheight = size; 298 int pmheight = size;
299 if( pmheight < fm.height() ) 299 if( pmheight < fm.height() )
300 yPos = fm.ascent() + fm.leading()/2; 300 yPos = fm.ascent() + fm.leading()/2;
301 else 301 else
302 yPos = pmheight/2 - fm.height()/2 + fm.ascent(); 302 yPos = pmheight/2 - fm.height()/2 + fm.ascent();
303 p->setPen( palette().color( QPalette::Normal, sel ? \ 303 p->setPen( palette().color( QPalette::Normal, sel ? \
304 QColorGroup::HighlightedText : QColorGroup::Foreground ) ); 304 QColorGroup::HighlightedText : QColorGroup::Foreground ) );
305 p->drawText( x, yPos, text() ); 305 p->drawText( x, yPos, text() );
306 if ( mIncidence->cancelled() ) { 306 if ( mIncidence->cancelled() ) {
307 int wid = fm.width( text() ); 307 int wid = fm.width( text() );
308 p->drawLine( x, heihei/2-1 ,x+wid, heihei/2-1 ); 308 p->drawLine( x, heihei/2-1 ,x+wid, heihei/2-1 );
309 } 309 }
310 310
311} 311}
312 312
313int MonthViewItem::height(const QListBox *lb) const 313int MonthViewItem::height(const QListBox *lb) const
314{ 314{
315 int ret = 10;
315 if ( lb ) 316 if ( lb )
316 return lb->fontMetrics().lineSpacing()+1; 317 ret = lb->fontMetrics().lineSpacing()+1;
317 return 10; 318 return ret;
318} 319}
319 320
320int MonthViewItem::width(const QListBox *lb) const 321int MonthViewItem::width(const QListBox *lb) const
321{ 322{
322 int size = PIXMAP_SIZE; 323
323 if ( QApplication::desktop()->width() < 300 ) 324 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) {
324 size = 3; 325 int size = PIXMAP_SIZE;
325 int x = 1; 326 if ( QApplication::desktop()->width() < 300 )
326 if ( KOPrefs::instance()->mMonthShowIcons ) { 327 size = 3;
327 if ( mInfo ) { 328 int x = 1;
328 x += size + 1; 329 if ( KOPrefs::instance()->mMonthShowIcons ) {
329 } 330 if ( mInfo ) {
330 if( mRecur ) { 331 x += size + 1;
331 x += size+1; 332 }
332 } 333 if( mRecur ) {
333 if( mAlarm ) { 334 x += size+1;
334 x += size+1; 335 }
336 if( mAlarm ) {
337 x += size+1;
338 }
339 if( mReply ) {
340 x += size+1;
341 }
335 } 342 }
336 if( mReply ) { 343 if( mMultiday ) {
337 x += size+1; 344 x += size+1+2+size/2;
338 } 345 }
346 return( x + lb->fontMetrics().width( text() ) + 1 );
339 } 347 }
340 if( mMultiday ) { 348 if ( ! lb )
341 x += size+1+2+size/2; 349 return 10;
342 } 350 //qDebug("ret wid %d ", lb->width());
343 351 return lb->width();
344 return( x + lb->fontMetrics().width( text() ) + 1 );
345} 352}
346 353
347 354
348MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) 355MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par )
349 : QWidget( par ), 356 : QWidget( par ),
350 mMonthView( parent ) 357 mMonthView( parent )
351{ 358{
352 359
353 QVBoxLayout *topLayout = new QVBoxLayout( this ); 360 //QVBoxLayout *topLayout = new QVBoxLayout( this );
354 361
355 // mLabel = new QLabel( this );QPushButton 362 // mLabel = new QLabel( this );QPushButton
356 mLabel = new QPushButton( this ); 363 mLabel = new QPushButton( this );
357 //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); 364 //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain );
358 //mLabel->setLineWidth( 1 ); 365 //mLabel->setLineWidth( 1 );
359 //mLabel->setAlignment( AlignCenter ); 366 //mLabel->setAlignment( AlignCenter );
360 mLabel->setFlat( true ); 367 mLabel->setFlat( true );
361 mLabel->setFocusPolicy(NoFocus); 368 mLabel->setFocusPolicy(NoFocus);
362 mItemList = new KNoScrollListBox( this ); 369 mItemList = new KNoScrollListBox( this );
363 mItemList->setMinimumSize( 10, 10 ); 370 mItemList->setMinimumSize( 10, 10 );
364 mItemList->setFrameStyle( QFrame::Panel | QFrame::Plain ); 371 mItemList->setFrameStyle( QFrame::Panel | QFrame::Plain );
365 mItemList->setLineWidth( 1 ); 372 mItemList->setLineWidth( 1 );
366 topLayout->addWidget( mItemList ); 373 //topLayout->addWidget( mItemList );
367 mLabel->raise(); 374 mLabel->raise();
368 // QColor( 0,0,255 ) QColor( 160,1600,255 ) 375 // QColor( 0,0,255 ) QColor( 160,1600,255 )
369 mStandardPalette = palette(); 376 mStandardPalette = palette();
370 mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); 377 mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) );
371 378
372 enableScrollBars( false ); 379 enableScrollBars( false );
373 updateConfig(); 380 updateConfig();
374 //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() )); 381 //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() ));
375 connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() )); 382 connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() ));
376 connect( mItemList, SIGNAL( doubleClicked( QListBoxItem *) ), 383 connect( mItemList, SIGNAL( doubleClicked( QListBoxItem *) ),
377 SLOT( defaultAction( QListBoxItem * ) ) ); 384 SLOT( defaultAction( QListBoxItem * ) ) );
378 connect( mItemList, SIGNAL( rightButtonPressed( QListBoxItem *, 385 connect( mItemList, SIGNAL( rightButtonPressed( QListBoxItem *,
379 const QPoint &) ), 386 const QPoint &) ),
380 SLOT( contextMenu( QListBoxItem * ) ) ); 387 SLOT( contextMenu( QListBoxItem * ) ) );
381 connect( mItemList, SIGNAL( highlighted( QListBoxItem *) ), 388 connect( mItemList, SIGNAL( highlighted( QListBoxItem *) ),
382 SLOT( selection( QListBoxItem * ) ) ); 389 SLOT( selection( QListBoxItem * ) ) );
383 connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), 390 connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ),
384 SLOT( cellClicked( QListBoxItem * ) ) ); 391 SLOT( cellClicked( QListBoxItem * ) ) );
385 connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), 392 connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ),
386 SLOT( selection( QListBoxItem * ) ) ); 393 SLOT( selection( QListBoxItem * ) ) );
387} 394}
388#ifdef DESKTOP_VERSION 395#ifdef DESKTOP_VERSION
389QToolTipGroup *MonthViewCell::toolTipGroup() 396QToolTipGroup *MonthViewCell::toolTipGroup()
390{ 397{
391 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); 398 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0);
392 return mToolTipGroup; 399 return mToolTipGroup;
393} 400}
394#endif 401#endif
395 402
396void MonthViewCell::setDate( const QDate &date ) 403void MonthViewCell::setDate( const QDate &date )
397{ 404{
398 // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl; 405 // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl;
399 mDate = date; 406 mDate = date;
400 407
401 408
402 409
403 //resizeEvent( 0 ); 410 //resizeEvent( 0 );
404} 411}
405 412
406QDate MonthViewCell::date() const 413QDate MonthViewCell::date() const
407{ 414{
408 return mDate; 415 return mDate;
409} 416}
410 417
411void MonthViewCell::setPrimary( bool primary ) 418void MonthViewCell::setPrimary( bool primary )
412{ 419{
413 mPrimary = primary; 420 mPrimary = primary;
414 //setMyPalette(); 421 //setMyPalette();
415} 422}
416void MonthViewCell::setMyPalette() 423void MonthViewCell::setMyPalette()
417{ 424{
418 425
419 if ( mHoliday) { 426 if ( mHoliday) {
420 setPalette( mHolidayPalette ); 427 mLabel->setPalette( QPalette ( mHolidayPalette.color( QPalette::Normal,QColorGroup::Base),mHolidayPalette.color(QPalette::Normal,QColorGroup::Base ) ));
428 mItemList->setPalette( mHolidayPalette );
421 } else { 429 } else {
422 if ( mPrimary ) { 430 if ( mPrimary ) {
423 setPalette( mPrimaryPalette ); 431 mLabel->setPalette( QPalette ( mPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) ));
432 mItemList->setPalette( mPrimaryPalette );
424 } else { 433 } else {
425 setPalette( mNonPrimaryPalette ); 434 mItemList->setPalette( mNonPrimaryPalette );
435 mLabel->setPalette( QPalette ( mNonPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mNonPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) ));
426 } 436 }
427 } 437 }
428 QPalette pal = palette(); 438 //QPalette pal = palette();
429 439
430 mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) )); 440 //mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) ));
431} 441}
432QPalette MonthViewCell::getPalette () 442QPalette MonthViewCell::getPalette ()
433{ 443{
434 if ( !KOPrefs::instance()->mMonthViewUsesDayColors ) 444 if ( !KOPrefs::instance()->mMonthViewUsesDayColors )
435 return mStandardPalette; 445 return mStandardPalette;
436 if ( mHoliday) { 446 if ( mHoliday) {
437 return mHolidayPalette ; 447 return mHolidayPalette ;
438 } else { 448 } else {
439 if ( mPrimary ) { 449 if ( mPrimary ) {
440 return mPrimaryPalette ; 450 return mPrimaryPalette ;
441 } 451 }
442 } 452 }
443 return mNonPrimaryPalette; 453 return mNonPrimaryPalette;
444} 454}
445bool MonthViewCell::isPrimary() const 455bool MonthViewCell::isPrimary() const
446{ 456{
447 return mPrimary; 457 return mPrimary;
448} 458}
449 459
450void MonthViewCell::setHoliday( bool holiday ) 460void MonthViewCell::setHoliday( bool holiday )
451{ 461{
452 mHoliday = holiday; 462 mHoliday = holiday;
453 //setMyPalette(); 463 //setMyPalette();
454} 464}
455 465
456void MonthViewCell::setHoliday( const QString &holiday ) 466void MonthViewCell::setHoliday( const QString &holiday )
457{ 467{
458 mHolidayString = holiday; 468 mHolidayString = holiday;
459 469
460 if ( !holiday.isEmpty() ) { 470 if ( !holiday.isEmpty() ) {
461 setHoliday( true ); 471 setHoliday( true );
462 } 472 }
463} 473}
464void MonthViewCell::keyPressEvent ( QKeyEvent * e ) 474void MonthViewCell::keyPressEvent ( QKeyEvent * e )
465{ 475{
466 476
467 e->ignore(); 477 e->ignore();
468 478
469} 479}
470 480
471void MonthViewCell::startUpdateCell() 481void MonthViewCell::startUpdateCell()
472{ 482{
473 483
474 mItemList->setFocusPolicy(NoFocus); 484 mItemList->setFocusPolicy(NoFocus);
475 if ( !mMonthView->isUpdatePossible() ) 485 if ( !mMonthView->isUpdatePossible() )
476 return; 486 return;
477 487
478 /* 488 /*
479 if ( !isVisible() ){ 489 if ( !isVisible() ){
480 return; 490 return;
481 } 491 }
482 */ 492 */
483 // qDebug("MonthViewCell::updateCell() "); 493 // qDebug("MonthViewCell::updateCell() ");
484 setPrimary( mDate.month()%2 ); 494 setPrimary( mDate.month()%2 );
485 setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays); 495 setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays);
486 if ( mDate == QDate::currentDate() ) { 496 if ( mDate == QDate::currentDate() ) {
487 mItemList->setLineWidth( 3 ); 497 mItemList->setLineWidth( 3 );
488 } else { 498 } else {
489 mItemList->setLineWidth( 1 ); 499 mItemList->setLineWidth( 1 );
490 } 500 }
491 mItemList->clear(); 501 mItemList->clear();
492 502
493#ifdef DESKTOP_VERSION 503#ifdef DESKTOP_VERSION
494 QToolTip::remove(this); 504 QToolTip::remove(this);
495#endif 505#endif
496 mToolTip.clear(); 506 mToolTip.clear();
497 //qApp->processEvents(); 507 //qApp->processEvents();
498 if ( !mHolidayString.isEmpty() ) { 508 if ( !mHolidayString.isEmpty() ) {
499 MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); 509 MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString );
500 item->setPalette( mHolidayPalette ); 510 item->setPalette( mHolidayPalette );
501 mItemList->insertItem( item ); 511 mItemList->insertItem( item );
502 mToolTip.append ( mHolidayString ); 512 mToolTip.append ( mHolidayString );
503 } 513 }
504} 514}
505 515
506void MonthViewCell::insertEvent(Event *event) 516void MonthViewCell::insertEvent(Event *event)
507{ 517{
508 QString mToolTipText; 518 QString mToolTipText;
509 mItemList->setFocusPolicy(WheelFocus); 519 mItemList->setFocusPolicy(WheelFocus);
510 if ( !(event->doesRecur() == Recurrence::rNone) ) { 520 if ( !(event->doesRecur() == Recurrence::rNone) ) {
511 if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) 521 if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily )
512 return; 522 return;
513 else 523 else
514 if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) 524 if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly )
515 return; 525 return;
516 } 526 }
517 527
518 if ( event->isHoliday()) { 528 if ( event->isHoliday()) {
519 setHoliday( true ); 529 setHoliday( true );
520 if ( mDate.dayOfWeek() == 7 ) 530 if ( mDate.dayOfWeek() == 7 )
521 mItemList->setLineWidth( 3 ); 531 mItemList->setLineWidth( 3 );
522 } 532 }
523 QString text; 533 QString text;
524 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day 534 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
525 if (event->isMultiDay()) { 535 if (event->isMultiDay()) {
526 QString prefix = "<->";multiday = 2; 536 QString prefix = "<->";multiday = 2;
527 QString time; 537 QString time;
528 if ( event->doesRecur() ) { 538 if ( event->doesRecur() ) {
529 if ( event->recursOn( mDate) ) { 539 if ( event->recursOn( mDate) ) {
530 prefix ="->" ;multiday = 1; 540 prefix ="->" ;multiday = 1;
531 } 541 }
532 else { 542 else {
533 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 543 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
534 if ( event->recursOn( mDate.addDays( -days)) ) { 544 if ( event->recursOn( mDate.addDays( -days)) ) {
535 prefix ="<-" ;multiday = 3; 545 prefix ="<-" ;multiday = 3;
536 } 546 }
537 } 547 }
538 548
539 } else { 549 } else {
540 if (mDate == event->dtStart().date()) { 550 if (mDate == event->dtStart().date()) {
541 prefix ="->" ;multiday = 1; 551 prefix ="->" ;multiday = 1;
542 } else if (mDate == event->dtEnd().date()) { 552 } else if (mDate == event->dtEnd().date()) {
543 prefix ="<-" ;multiday = 3; 553 prefix ="<-" ;multiday = 3;
544 } 554 }
545 } 555 }
546 if ( !event->doesFloat() ) { 556 if ( !event->doesFloat() ) {
547 if ( mDate == event->dtStart().date () ) 557 if ( mDate == event->dtStart().date () )
548 time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; 558 time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
549 else if ( mDate == event->dtEnd().date () ) 559 else if ( mDate == event->dtEnd().date () )
550 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 560 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
551 561
552 } 562 }
553 text = time + event->summary(); 563 text = time + event->summary();
554 mToolTipText += prefix + text; 564 mToolTipText += prefix + text;
555 } else { 565 } else {
556 if (event->doesFloat()) { 566 if (event->doesFloat()) {
557 text = event->summary(); 567 text = event->summary();
558 mToolTipText += text; 568 mToolTipText += text;
559 } 569 }
560 else { 570 else {
561 text = KGlobal::locale()->formatTime(event->dtStart().time()); 571 text = KGlobal::locale()->formatTime(event->dtStart().time());
562 text += " " + event->summary(); 572 text += " " + event->summary();
563 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 573 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
564 } 574 }
565 } 575 }
566 576
567 MonthViewItem *item = new MonthViewItem( event, mDate, text ); 577 MonthViewItem *item = new MonthViewItem( event, mDate, text );
568 QPalette pal; 578 QPalette pal;
569 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { 579 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
570 QStringList categories = event->categories(); 580 QStringList categories = event->categories();
571 QString cat = categories.first(); 581 QString cat = categories.first();
572 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { 582 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
573 pal = getPalette(); 583 pal = getPalette();
574 if (cat.isEmpty()) { 584 if (cat.isEmpty()) {
575 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); 585 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
576 } else { 586 } else {
577 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); 587 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
578 } 588 }
579 589
580 } else { 590 } else {
581 if (cat.isEmpty()) { 591 if (cat.isEmpty()) {
582 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); 592 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
583 } else { 593 } else {
584 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); 594 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
585 } 595 }
586 } 596 }
587 597
588 } else { 598 } else {
589 pal = mStandardPalette ; 599 pal = mStandardPalette ;
590 } 600 }
591 item->setPalette( pal ); 601 item->setPalette( pal );
592 item->setRecur( event->recurrence()->doesRecur() ); 602 item->setRecur( event->recurrence()->doesRecur() );
593 item->setAlarm( event->isAlarmEnabled() && multiday < 2 ); 603 item->setAlarm( event->isAlarmEnabled() && multiday < 2 );
594 item->setMoreInfo( event->description().length() > 0 ); 604 item->setMoreInfo( event->description().length() > 0 );
595#ifdef DESKTOP_VERSION 605#ifdef DESKTOP_VERSION
596 Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, 606 Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails,
597 KOPrefs::instance()->email()); 607 KOPrefs::instance()->email());
598 if ( me != 0 ) { 608 if ( me != 0 ) {
599 if ( me->status() == Attendee::NeedsAction && me->RSVP()) 609 if ( me->status() == Attendee::NeedsAction && me->RSVP())
600 item->setReply(true && multiday < 2); 610 item->setReply(true && multiday < 2);
601 else 611 else
602 item->setReply(false); 612 item->setReply(false);
603 } else 613 } else
604 item->setReply(false); 614 item->setReply(false);
605#endif 615#endif
606 item->setMultiDay( multiday ); 616 item->setMultiDay( multiday );
607 mItemList->insertItem( item ); 617 mItemList->insertItem( item );
608 mToolTip.append( mToolTipText ); 618 mToolTip.append( mToolTipText );
609} 619}
610void MonthViewCell::insertTodo(Todo *todo) 620void MonthViewCell::insertTodo(Todo *todo)
611{ 621{
612 mItemList->setFocusPolicy(WheelFocus); 622 mItemList->setFocusPolicy(WheelFocus);
613 QString text; 623 QString text;
614 if (todo->hasDueDate()) { 624 if (todo->hasDueDate()) {
615 if (!todo->doesFloat()) { 625 if (!todo->doesFloat()) {
616 text += KGlobal::locale()->formatTime(todo->dtDue().time()); 626 text += KGlobal::locale()->formatTime(todo->dtDue().time());
617 text += " "; 627 text += " ";
618 } 628 }
619 } 629 }
620 text += todo->summary(); 630 text += todo->summary();
621 631
622 MonthViewItem *item = new MonthViewItem( todo, mDate, text ); 632 MonthViewItem *item = new MonthViewItem( todo, mDate, text );
623 //item->setPalette( mStandardPalette ); 633 //item->setPalette( mStandardPalette );
624 QPalette pal; 634 QPalette pal;
625 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { 635 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
626 QStringList categories = todo->categories(); 636 QStringList categories = todo->categories();
627 QString cat = categories.first(); 637 QString cat = categories.first();
628 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { 638 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
629 pal = getPalette(); 639 pal = getPalette();
630 if (cat.isEmpty()) { 640 if (cat.isEmpty()) {
631 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); 641 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
632 } else { 642 } else {
633 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); 643 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
634 } 644 }
635 645
636 } else { 646 } else {
637 if (cat.isEmpty()) { 647 if (cat.isEmpty()) {
638 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); 648 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
639 } else { 649 } else {
640 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); 650 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
641 } 651 }
642 } 652 }
643 653
644 } else { 654 } else {
645 pal = mStandardPalette ; 655 pal = mStandardPalette ;
646 } 656 }
647 item->setPalette( pal ); 657 item->setPalette( pal );
648 item->setRecur( todo->recurrence()->doesRecur() ); 658 item->setRecur( todo->recurrence()->doesRecur() );
649 item->setAlarm( todo->isAlarmEnabled() ); 659 item->setAlarm( todo->isAlarmEnabled() );
650 item->setMoreInfo( todo->description().length() > 0 ); 660 item->setMoreInfo( todo->description().length() > 0 );
651 mItemList->insertItem( item ); 661 mItemList->insertItem( item );
652 mToolTip.append( text ); 662 mToolTip.append( text );
653} 663}
654void MonthViewCell::finishUpdateCell() 664void MonthViewCell::finishUpdateCell()
655{ 665{
656#ifdef DESKTOP_VERSION 666#ifdef DESKTOP_VERSION
657 if (mToolTip.count() > 0 ) { 667 if (mToolTip.count() > 0 ) {
658 mToolTip.sort(); 668 mToolTip.sort();
659 QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),""); 669 QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),"");
660 } 670 }
661#endif 671#endif
662 mItemList->sort(); 672 mItemList->sort();
663 //setMyPalette(); 673 //setMyPalette();
664 setMyPalette(); 674 setMyPalette();
665 QString text; 675 QString text;
666 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; 676 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog;
667 if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { 677 if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) {
668 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " "; 678 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " ";
669 mLabel->resize( mLabelBigSize ); 679 mLabel->resize( mLabelBigSize );
670 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 680 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
671 } else { 681 } else {
672 mLabel->resize( mLabelSize ); 682 mLabel->resize( mLabelSize );
673 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 683 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
674 } 684 }
675 685
676 mLabel->setText( text ); 686 mLabel->setText( text );
677 resizeEvent( 0 ); 687 resizeEvent( 0 );
688
678} 689}
679void MonthViewCell::updateCell() 690void MonthViewCell::updateCell()
680{ 691{
681 //qDebug("MonthViewCell::updateCell() "); 692 //qDebug("MonthViewCell::updateCell() ");
682 if ( !mMonthView->isUpdatePossible() ) 693 if ( !mMonthView->isUpdatePossible() )
683 return; 694 return;
684 startUpdateCell(); 695 startUpdateCell();
685 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 696 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
686 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); 697 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true );
687 Event *event; 698 Event *event;
688 for( event = events.first(); event; event = events.next() ) { // for event 699 for( event = events.first(); event; event = events.next() ) { // for event
689 insertEvent(event); 700 insertEvent(event);
690 } 701 }
691 // insert due todos 702 // insert due todos
692 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); 703 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate );
693 Todo *todo; 704 Todo *todo;
694 for(todo = todos.first(); todo; todo = todos.next()) { 705 for(todo = todos.first(); todo; todo = todos.next()) {
695 insertTodo( todo ); 706 insertTodo( todo );
696 } 707 }
697 finishUpdateCell(); 708 finishUpdateCell();
698 // if ( isVisible()) 709 // if ( isVisible())
699 //qApp->processEvents(); 710 //qApp->processEvents();
700} 711}
701 712
702void MonthViewCell::updateConfig( bool bigFont ) // = false 713void MonthViewCell::updateConfig( bool bigFont ) // = false
703{ 714{
704 715
705 if ( bigFont ) { 716 if ( bigFont ) {
706 QFont fo = KOPrefs::instance()->mMonthViewFont; 717 QFont fo = KOPrefs::instance()->mMonthViewFont;
707 int ps = fo.pointSize() + 2; 718 int ps = fo.pointSize() + 2;
708 if ( ps < 18 ) 719 if ( ps < 18 )
709 ps += 2; 720 ps += 2;
710 fo.setPointSize( ps ); 721 fo.setPointSize( ps );
711 setFont( fo ); 722 setFont( fo );
712 } else 723 } else
713 setFont( KOPrefs::instance()->mMonthViewFont ); 724 setFont( KOPrefs::instance()->mMonthViewFont );
714 725
715 QFontMetrics fm( font() ); 726 QFontMetrics fm( font() );
716 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); 727 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 );
717 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); 728 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 );
718 mHolidayPalette = mStandardPalette; 729 mHolidayPalette = mStandardPalette;
719 mPrimaryPalette = mStandardPalette; 730 mPrimaryPalette = mStandardPalette;
720 mNonPrimaryPalette = mStandardPalette; 731 mNonPrimaryPalette = mStandardPalette;
721 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { 732 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) {
722 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); 733 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor );
723 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); 734 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor );
724 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); 735 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark());
725 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); 736 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark());
726 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); 737 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor);
727 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); 738 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor);
728 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); 739 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark());
729 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); 740 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor);
730 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); 741 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor);
731 } 742 }
732 //updateCell(); 743 //updateCell();
733} 744}
734 745
735void MonthViewCell::enableScrollBars( bool enabled ) 746void MonthViewCell::enableScrollBars( bool enabled )
736{ 747{
737 if ( enabled ) { 748 if ( enabled ) {
738 mItemList->setVScrollBarMode(QScrollView::Auto); 749 //mItemList->setVScrollBarMode(QScrollView::Auto);
739 mItemList->setHScrollBarMode(QScrollView::Auto); 750 mItemList->setHScrollBarMode(QScrollView::Auto);
751 QListBoxItem *fi = mItemList->firstItem ();
752 if (fi ) {
753 int hei = mItemList->numRows () * fi->height(mItemList);
754 if ( hei < height() - mItemList->horizontalScrollBar()->height () )
755 mItemList->setVScrollBarMode(QScrollView::AlwaysOff);
756 else
757 mItemList->setVScrollBarMode(QScrollView::Auto);
758 }
740 } else { 759 } else {
741 mItemList->setVScrollBarMode(QScrollView::AlwaysOff); 760 mItemList->setVScrollBarMode(QScrollView::AlwaysOff);
742 mItemList->setHScrollBarMode(QScrollView::AlwaysOff); 761 mItemList->setHScrollBarMode(QScrollView::AlwaysOff);
743 } 762 }
744} 763}
745 764
746Incidence *MonthViewCell::selectedIncidence() 765Incidence *MonthViewCell::selectedIncidence()
747{ 766{
748 int index = mItemList->currentItem(); 767 int index = mItemList->currentItem();
749 if ( index < 0 ) return 0; 768 if ( index < 0 ) return 0;
750 769
751 MonthViewItem *item = 770 MonthViewItem *item =
752 static_cast<MonthViewItem *>( mItemList->item( index ) ); 771 static_cast<MonthViewItem *>( mItemList->item( index ) );
753 772
754 if ( !item ) return 0; 773 if ( !item ) return 0;
755 774
756 return item->incidence(); 775 return item->incidence();
757} 776}
758 777
759QDate MonthViewCell::selectedIncidenceDate() 778QDate MonthViewCell::selectedIncidenceDate()
760{ 779{
761 QDate qd; 780 QDate qd;
762 int index = mItemList->currentItem(); 781 int index = mItemList->currentItem();
763 if ( index < 0 ) return qd; 782 if ( index < 0 ) return qd;
764 783
765 MonthViewItem *item = 784 MonthViewItem *item =
766 static_cast<MonthViewItem *>( mItemList->item( index ) ); 785 static_cast<MonthViewItem *>( mItemList->item( index ) );
767 786
768 if ( !item ) return qd; 787 if ( !item ) return qd;
769 788
770 return item->incidenceDate(); 789 return item->incidenceDate();
771} 790}
772 791
773void MonthViewCell::deselect() 792void MonthViewCell::deselect()
774{ 793{
775 mItemList->clearSelection(); 794 mItemList->clearSelection();
776 enableScrollBars( false ); 795 enableScrollBars( false );
777 // updateCell(); 796 // updateCell();
778} 797}
779void MonthViewCell::select() 798void MonthViewCell::select()
780{ 799{
781 ;// updateCell(); 800 ;// updateCell();
782} 801}
783 802
784void MonthViewCell::resizeEvent ( QResizeEvent * ) 803void MonthViewCell::resizeEvent ( QResizeEvent * e )
785{ 804{
786 if ( !mMonthView->isUpdatePossible() ) 805 if ( !mMonthView->isUpdatePossible() )
787 return; 806 return;
788 807 //qDebug("++++++++++++++MonthViewCell::resizeEvent %d %d ", width(), height());
808 deselect();
789 int size = height() - mLabel->height() - 2; 809 int size = height() - mLabel->height() - 2;
790 if ( size > 0 ) 810 if ( size > 0 )
791 mItemList->verticalScrollBar()->setMaximumHeight( size ); 811 mItemList->verticalScrollBar()->setMaximumHeight( size );
792 size = width() - mLabel->width() -2; 812 size = width() - mLabel->width() -2;
793 if ( size > 0 ) 813 if ( size > 0 )
794 mItemList->horizontalScrollBar()->setMaximumWidth( size ); 814 mItemList->horizontalScrollBar()->setMaximumWidth( size );
795 mLabel->move( width()-mItemList->lineWidth() - mLabel->width(), height()-mItemList->lineWidth() - mLabel->height() ); 815 mLabel->move( width()-mItemList->lineWidth() - mLabel->width(), height()-mItemList->lineWidth() - mLabel->height() );
796 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 816 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
817 mItemList->resize ( width(), height () );
818
797} 819}
798 820
799void MonthViewCell::defaultAction( QListBoxItem *item ) 821void MonthViewCell::defaultAction( QListBoxItem *item )
800{ 822{
801 if ( !item ) return; 823 if ( !item ) return;
802 824
803 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 825 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
804 Incidence *incidence = eventItem->incidence(); 826 Incidence *incidence = eventItem->incidence();
805 if ( incidence ) mMonthView->defaultAction( incidence ); 827 if ( incidence ) mMonthView->defaultAction( incidence );
806} 828}
807void MonthViewCell::showDay() 829void MonthViewCell::showDay()
808{ 830{
809 emit showDaySignal( date() ); 831 emit showDaySignal( date() );
810} 832}
811void MonthViewCell::newEvent() 833void MonthViewCell::newEvent()
812{ 834{
813 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 835 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
814 emit newEventSignal( dt ); 836 emit newEventSignal( dt );
815} 837}
816void MonthViewCell::cellClicked( QListBoxItem *item ) 838void MonthViewCell::cellClicked( QListBoxItem *item )
817{ 839{
818 static QListBoxItem * lastClicked = 0; 840 static QListBoxItem * lastClicked = 0;
819 if ( item == 0 ) { 841 if ( item == 0 ) {
820 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 842 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
821 emit newEventSignal( dt ); 843 emit newEventSignal( dt );
822 return; 844 return;
823 } 845 }
824 /* 846 /*
825 if ( lastClicked ) 847 if ( lastClicked )
826 if ( ! item ) { 848 if ( ! item ) {
827 if ( lastClicked->listBox() != item->listBox() ) 849 if ( lastClicked->listBox() != item->listBox() )
828 lastClicked->listBox()->clearSelection(); 850 lastClicked->listBox()->clearSelection();
829 } 851 }
830 */ 852 */
831 853
832 mMonthView->setSelectedCell( this ); 854 mMonthView->setSelectedCell( this );
833 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true ); 855 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true );
834 select(); 856 select();
835} 857}
836 858
837void MonthViewCell::contextMenu( QListBoxItem *item ) 859void MonthViewCell::contextMenu( QListBoxItem *item )
838{ 860{
839 if ( !item ) return; 861 if ( !item ) return;
840 862
841 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 863 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
842 Incidence *incidence = eventItem->incidence(); 864 Incidence *incidence = eventItem->incidence();
843 if ( incidence ) mMonthView->showContextMenu( incidence ); 865 if ( incidence ) mMonthView->showContextMenu( incidence );
844} 866}
845 867
846void MonthViewCell::selection( QListBoxItem *item ) 868void MonthViewCell::selection( QListBoxItem *item )
847{ 869{
848 if ( !item ) return; 870 if ( !item ) return;
849 871
850 mMonthView->setSelectedCell( this ); 872 mMonthView->setSelectedCell( this );
851} 873}
852 874
853 875
854// ******************************************************************************* 876// *******************************************************************************
855// ******************************************************************************* 877// *******************************************************************************
856// ******************************************************************************* 878// *******************************************************************************
857 879
858 880
859KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) 881KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name)
860 : KOEventView( calendar, parent, name ), 882 : KOEventView( calendar, parent, name ),
861 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), 883 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
862 mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) 884 mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
863{ 885{
864 mShortDayLabelsM = false; 886 mShortDayLabelsM = false;
865 mShortDayLabelsW = false; 887 mShortDayLabelsW = false;
866 skipResize = false; 888 skipResize = false;
867 clPending = true; 889 clPending = true;
868 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); 890 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" );
869 mWidStack = new QWidgetStack( this ); 891 mWidStack = new QWidgetStack( this );
870 QVBoxLayout* hb = new QVBoxLayout( this ); 892 QVBoxLayout* hb = new QVBoxLayout( this );
871 mMonthView = new QWidget( mWidStack ); 893 mMonthView = new QWidget( mWidStack );
872 mWeekView = new QWidget( mWidStack ); 894 mWeekView = new QWidget( mWidStack );
873#if QT_VERSION >= 0x030000 895#if QT_VERSION >= 0x030000
874 mWidStack->addWidget(mMonthView ); 896 mWidStack->addWidget(mMonthView );
875 mWidStack->addWidget(mWeekView ); 897 mWidStack->addWidget(mWeekView );
876#else 898#else
877 mWidStack->addWidget( mMonthView, 1 ); 899 mWidStack->addWidget( mMonthView, 1 );
878 mWidStack->addWidget( mWeekView , 1 ); 900 mWidStack->addWidget( mWeekView , 1 );
879#endif 901#endif
880 hb->addWidget( mNavigatorBar ); 902 hb->addWidget( mNavigatorBar );
881 hb->addWidget( mWidStack ); 903 hb->addWidget( mWidStack );
882 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 904 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
883 mShowWeekView = KOPrefs::instance()->mMonthViewWeek; 905 mShowWeekView = KOPrefs::instance()->mMonthViewWeek;
884 if ( mShowWeekView ) 906 if ( mShowWeekView )
885 mWeekStartsMonday = true; 907 mWeekStartsMonday = true;
886 updatePossible = false; 908 updatePossible = false;
887 //updatePossible = true; 909 //updatePossible = true;
888 mCells.setAutoDelete( true ); 910 mCells.setAutoDelete( true );
889 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 911 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
890 mDayLabels.resize( mDaysPerWeek ); 912 mDayLabels.resize( mDaysPerWeek );
891 mDayLabelsW.resize( mDaysPerWeek ); 913 mDayLabelsW.resize( mDaysPerWeek );
892 QFont bfont = font(); 914 QFont bfont = font();
893 if ( QApplication::desktop()->width() < 650 ) { 915 if ( QApplication::desktop()->width() < 650 ) {
894 bfont.setPointSize( bfont.pointSize() - 2 ); 916 bfont.setPointSize( bfont.pointSize() - 2 );
895 } 917 }
896 bfont.setBold( true ); 918 bfont.setBold( true );
897 int i; 919 int i;
898 920
899 for( i = 0; i < mDaysPerWeek; i++ ) { 921 for( i = 0; i < mDaysPerWeek; i++ ) {
900 QLabel *label = new QLabel( mMonthView ); 922 QLabel *label = new QLabel( mMonthView );
901 label->setFont(bfont); 923 label->setFont(bfont);
902 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 924 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
903 label->setLineWidth(1); 925 label->setLineWidth(1);
904 label->setAlignment(AlignCenter); 926 label->setAlignment(AlignCenter);
905 mDayLabels.insert( i, label ); 927 mDayLabels.insert( i, label );
906 label = new QLabel( mWeekView ); 928 label = new QLabel( mWeekView );
907 label->setFont(bfont); 929 label->setFont(bfont);
908 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 930 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
909 label->setLineWidth(1); 931 label->setLineWidth(1);
910 label->setAlignment(AlignCenter); 932 label->setAlignment(AlignCenter);
911 mDayLabelsW.insert( i, label ); 933 mDayLabelsW.insert( i, label );
912 } 934 }
913 935
914 bfont.setBold( false ); 936 bfont.setBold( false );
915 mWeekLabels.resize( mNumWeeks+1 ); 937 mWeekLabels.resize( mNumWeeks+1 );
916 mWeekLabelsW.resize( 2 ); 938 mWeekLabelsW.resize( 2 );
917 for( i = 0; i < mNumWeeks+1; i++ ) { 939 for( i = 0; i < mNumWeeks+1; i++ ) {
918 KOWeekButton *label = new KOWeekButton( mMonthView ); 940 KOWeekButton *label = new KOWeekButton( mMonthView );
919 label->setFocusPolicy(NoFocus); 941 label->setFocusPolicy(NoFocus);
920 label->setFont(bfont); 942 label->setFont(bfont);
921 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 943 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
922 label->setFlat(true); 944 label->setFlat(true);
923 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 945 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
924 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 946 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
925 //label->setLineWidth(1); 947 //label->setLineWidth(1);
926 //label->setAlignment(AlignCenter); 948 //label->setAlignment(AlignCenter);
927 mWeekLabels.insert( i, label ); 949 mWeekLabels.insert( i, label );
928 } 950 }
929 mWeekLabels[mNumWeeks]->setText( i18n("W")); 951 mWeekLabels[mNumWeeks]->setText( i18n("W"));
930 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number")); 952 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number"));
931 953
932 for( i = 0; i < 1+1; i++ ) { 954 for( i = 0; i < 1+1; i++ ) {
933 KOWeekButton *label = new KOWeekButton( mWeekView ); 955 KOWeekButton *label = new KOWeekButton( mWeekView );
934 label->setFocusPolicy(NoFocus); 956 label->setFocusPolicy(NoFocus);
935 label->setFont(bfont); 957 label->setFont(bfont);
936 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 958 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
937 label->setFlat(true); 959 label->setFlat(true);
938 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 960 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
939 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 961 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
940 //label->setLineWidth(1); 962 //label->setLineWidth(1);
941 //label->setAlignment(AlignCenter); 963 //label->setAlignment(AlignCenter);
942 mWeekLabelsW.insert( i, label ); 964 mWeekLabelsW.insert( i, label );
943 } 965 }
944 mWeekLabelsW[1]->setText( i18n("W")); 966 mWeekLabelsW[1]->setText( i18n("W"));
945 967
946 968
947 int row, col; 969 int row, col;
948 mCells.resize( mNumCells ); 970 mCells.resize( mNumCells );
949 for( row = 0; row < mNumWeeks; ++row ) { 971 for( row = 0; row < mNumWeeks; ++row ) {
950 for( col = 0; col < mDaysPerWeek; ++col ) { 972 for( col = 0; col < mDaysPerWeek; ++col ) {
951 MonthViewCell *cell = new MonthViewCell( this, mMonthView ); 973 MonthViewCell *cell = new MonthViewCell( this, mMonthView );
952 mCells.insert( row * mDaysPerWeek + col, cell ); 974 mCells.insert( row * mDaysPerWeek + col, cell );
953 975
954 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 976 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
955 SLOT( defaultAction( Incidence * ) ) ); 977 SLOT( defaultAction( Incidence * ) ) );
956 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 978 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
957 SIGNAL( newEventSignal( QDateTime ) ) ); 979 SIGNAL( newEventSignal( QDateTime ) ) );
958 connect( cell, SIGNAL( showDaySignal( QDate ) ), 980 connect( cell, SIGNAL( showDaySignal( QDate ) ),
959 SIGNAL( showDaySignal( QDate ) ) ); 981 SIGNAL( showDaySignal( QDate ) ) );
960 } 982 }
961 } 983 }
962 mCellsW.resize( mDaysPerWeek ); 984 mCellsW.resize( mDaysPerWeek );
963 for( col = 0; col < mDaysPerWeek; ++col ) { 985 for( col = 0; col < mDaysPerWeek; ++col ) {
964 MonthViewCell *cell = new MonthViewCell( this, mWeekView ); 986 MonthViewCell *cell = new MonthViewCell( this, mWeekView );
965 mCellsW.insert( col, cell ); 987 mCellsW.insert( col, cell );
966 988
967 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 989 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
968 SLOT( defaultAction( Incidence * ) ) ); 990 SLOT( defaultAction( Incidence * ) ) );
969 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 991 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
970 SIGNAL( newEventSignal( QDateTime ) ) ); 992 SIGNAL( newEventSignal( QDateTime ) ) );
971 connect( cell, SIGNAL( showDaySignal( QDate ) ), 993 connect( cell, SIGNAL( showDaySignal( QDate ) ),
972 SIGNAL( showDaySignal( QDate ) ) ); 994 SIGNAL( showDaySignal( QDate ) ) );
973 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); 995 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont );
974 } 996 }
975 997
976 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); 998 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) );
977 mContextMenu = eventPopup(); 999 mContextMenu = eventPopup();
978 // updateConfig(); //useless here... 1000 // updateConfig(); //useless here...
979 // ... but we need mWidthLongDayLabel computed 1001 // ... but we need mWidthLongDayLabel computed
980 QFontMetrics fontmetric(mDayLabels[0]->font()); 1002 QFontMetrics fontmetric(mDayLabels[0]->font());
981 mWidthLongDayLabel = 0; 1003 mWidthLongDayLabel = 0;
982 for (int i = 0; i < 7; i++) { 1004 for (int i = 0; i < 7; i++) {
983 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 1005 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
984 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 1006 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
985 } 1007 }
986 1008
987 //mWeekLabels[mNumWeeks]->setText( i18n("W")); 1009 //mWeekLabels[mNumWeeks]->setText( i18n("W"));
988 1010
989#if 0 1011#if 0
990 if ( mShowWeekView ) 1012 if ( mShowWeekView )
991 mWidStack->raiseWidget( mWeekView ); 1013 mWidStack->raiseWidget( mWeekView );
992 else 1014 else
993 mWidStack->raiseWidget( mMonthView ); 1015 mWidStack->raiseWidget( mMonthView );
994#endif 1016#endif
995 1017
996 emit incidenceSelected( 0 ); 1018 emit incidenceSelected( 0 );
997 1019
998 mComputeLayoutTimer = new QTimer( this ); 1020 mComputeLayoutTimer = new QTimer( this );
999 connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout())); 1021 connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout()));
1000 1022
1001 1023
1002#ifndef DESKTOP_VERSION 1024#ifndef DESKTOP_VERSION
1003 resize( QApplication::desktop()->size() ); 1025 resize( QApplication::desktop()->size() );
1004#else 1026#else
1005 resize(640, 480 ); 1027 resize(640, 480 );
1006 updatePossible = true; 1028 updatePossible = true;
1007#endif 1029#endif
1008 computeLayout(); 1030 computeLayout();
1009 1031
1010 if ( mShowWeekView ) 1032 if ( mShowWeekView )
1011 mWidStack->raiseWidget( mWeekView ); 1033 mWidStack->raiseWidget( mWeekView );
1012 else 1034 else
1013 mWidStack->raiseWidget( mMonthView ); 1035 mWidStack->raiseWidget( mMonthView );
1014} 1036}
1015 1037
1016KOMonthView::~KOMonthView() 1038KOMonthView::~KOMonthView()
1017{ 1039{
1018 delete mContextMenu; 1040 delete mContextMenu;
1019} 1041}
1020 1042
1021void KOMonthView::selectInternalWeekNum ( int n ) 1043void KOMonthView::selectInternalWeekNum ( int n )
1022{ 1044{
1023 switchView(); 1045 switchView();
1024 if ( !KOPrefs::instance()->mMonthViewWeek ) 1046 if ( !KOPrefs::instance()->mMonthViewWeek )
1025 emit selectMonth (); 1047 emit selectMonth ();
1026 else 1048 else
1027 emit selectWeekNum ( n ); 1049 emit selectWeekNum ( n );
1028} 1050}
1029 1051
1030int KOMonthView::currentWeek() 1052int KOMonthView::currentWeek()
1031{ 1053{
1032 if ( mShowWeekView ) 1054 if ( mShowWeekView )
1033 return mWeekLabelsW[0]->getWeekNum(); 1055 return mWeekLabelsW[0]->getWeekNum();
1034 return mWeekLabels[0]->getWeekNum(); 1056 return mWeekLabels[0]->getWeekNum();
1035} 1057}
1036void KOMonthView::switchView() 1058void KOMonthView::switchView()
1037{ 1059{
1038 if ( selectedCell( ) ) 1060 if ( selectedCell( ) )
1039 selectedCell()->deselect(); 1061 selectedCell()->deselect();
1040 mShowWeekView = !mShowWeekView; 1062 mShowWeekView = !mShowWeekView;
1041 KOPrefs::instance()->mMonthViewWeek = mShowWeekView; 1063 KOPrefs::instance()->mMonthViewWeek = mShowWeekView;
1042 if ( clPending ) { 1064 if ( clPending ) {
1043 computeLayout(); 1065 computeLayout();
1044 updateConfig(); 1066 updateConfig();
1045 } 1067 }
1046 if ( mShowWeekView ) 1068 if ( mShowWeekView )
1047 mWidStack->raiseWidget( mWeekView ); 1069 mWidStack->raiseWidget( mWeekView );
1048 else 1070 else
1049 mWidStack->raiseWidget( mMonthView ); 1071 mWidStack->raiseWidget( mMonthView );
1050 clPending = false; 1072 clPending = false;
1051} 1073}
1052 1074
1053int KOMonthView::maxDatesHint() 1075int KOMonthView::maxDatesHint()
1054{ 1076{
1055 return mNumCells; 1077 return mNumCells;
1056} 1078}
1057 1079
1058int KOMonthView::currentDateCount() 1080int KOMonthView::currentDateCount()
1059{ 1081{
1060 return mNumCells; 1082 return mNumCells;
1061} 1083}
1062 1084
1063QPtrList<Incidence> KOMonthView::selectedIncidences() 1085QPtrList<Incidence> KOMonthView::selectedIncidences()
1064{ 1086{
1065 QPtrList<Incidence> selected; 1087 QPtrList<Incidence> selected;
1066 1088
1067 if ( mSelectedCell ) { 1089 if ( mSelectedCell ) {
1068 Incidence *incidence = mSelectedCell->selectedIncidence(); 1090 Incidence *incidence = mSelectedCell->selectedIncidence();
1069 if ( incidence ) selected.append( incidence ); 1091 if ( incidence ) selected.append( incidence );
1070 } 1092 }
1071 1093
1072 return selected; 1094 return selected;
1073} 1095}
1074 1096
1075DateList KOMonthView::selectedDates() 1097DateList KOMonthView::selectedDates()
1076{ 1098{
1077 DateList selected; 1099 DateList selected;
1078 1100
1079 if ( mSelectedCell ) { 1101 if ( mSelectedCell ) {
1080 QDate qd = mSelectedCell->selectedIncidenceDate(); 1102 QDate qd = mSelectedCell->selectedIncidenceDate();
1081 if ( qd.isValid() ) selected.append( qd ); 1103 if ( qd.isValid() ) selected.append( qd );
1082 } 1104 }
1083 1105
1084 return selected; 1106 return selected;
1085} 1107}
1086 1108
1087void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1109void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1088 const QDate &td) 1110 const QDate &td)
1089{ 1111{
1090#ifndef KORG_NOPRINTER 1112#ifndef KORG_NOPRINTER
1091 calPrinter->preview(CalPrinter::Month, fd, td); 1113 calPrinter->preview(CalPrinter::Month, fd, td);
1092#endif 1114#endif
1093} 1115}
1094 1116
1095void KOMonthView::updateConfig() 1117void KOMonthView::updateConfig()
1096{ 1118{
1097 1119
1098 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 1120 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
1099 1121
1100 if ( mShowWeekView ) { 1122 if ( mShowWeekView ) {
1101 mWeekStartsMonday = true; 1123 mWeekStartsMonday = true;
1102 } 1124 }
1103 QFontMetrics fontmetric(mDayLabels[0]->font()); 1125 QFontMetrics fontmetric(mDayLabels[0]->font());
1104 mWidthLongDayLabel = 0; 1126 mWidthLongDayLabel = 0;
1105 1127
1106 for (int i = 0; i < 7; i++) { 1128 for (int i = 0; i < 7; i++) {
1107 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 1129 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
1108 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 1130 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
1109 } 1131 }
1110 bool temp = mShowSatSunComp ; 1132 bool temp = mShowSatSunComp ;
1111 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 1133 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
1112 if ( ! mShowWeekView ) { 1134 if ( ! mShowWeekView ) {
1113 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) 1135 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog )
1114 computeLayout(); 1136 computeLayout();
1115 } 1137 }
1116 updateDayLabels(); 1138 updateDayLabels();
1117 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); 1139 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks);
1118 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; 1140 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks;
1119 //resizeEvent( 0 ); 1141 //resizeEvent( 0 );
1120 for (uint i = 0; i < mCells.count(); ++i) { 1142 for (uint i = 0; i < mCells.count(); ++i) {
1121 mCells[i]->updateConfig(); 1143 mCells[i]->updateConfig();
1122 } 1144 }
1123 1145
1124 for (uint i = 0; i < mCellsW.count(); ++i) { 1146 for (uint i = 0; i < mCellsW.count(); ++i) {
1125 mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont); 1147 mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont);
1126 } 1148 }
1127#ifdef DESKTOP_VERSION 1149#ifdef DESKTOP_VERSION
1128 MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); 1150 MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips);
1129#endif 1151#endif
1130 updateView(); 1152 updateView();
1131} 1153}
1132 1154
1133void KOMonthView::updateDayLabels() 1155void KOMonthView::updateDayLabels()
1134{ 1156{
1135 1157
1136 QPtrVector<QLabel> *mDayLabelsT; 1158 QPtrVector<QLabel> *mDayLabelsT;
1137 1159
1138 mDayLabelsT = &mDayLabelsW; 1160 mDayLabelsT = &mDayLabelsW;
1139 for (int i = 0; i < 7; i++) { 1161 for (int i = 0; i < 7; i++) {
1140 if (mWeekStartsMonday) { 1162 if (mWeekStartsMonday) {
1141 bool show = mShortDayLabelsW; 1163 bool show = mShortDayLabelsW;
1142 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) 1164 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
1143 show = true; 1165 show = true;
1144 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); 1166 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
1145 } else { 1167 } else {
1146 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsW)); 1168 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsW));
1147 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsW)); 1169 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsW));
1148 1170
1149 } 1171 }
1150 } 1172 }
1151 mDayLabelsT = &mDayLabels; 1173 mDayLabelsT = &mDayLabels;
1152 for (int i = 0; i < 7; i++) { 1174 for (int i = 0; i < 7; i++) {
1153 if (mWeekStartsMonday) { 1175 if (mWeekStartsMonday) {
1154 bool show = mShortDayLabelsM; 1176 bool show = mShortDayLabelsM;
1155 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) 1177 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
1156 show = true; 1178 show = true;
1157 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); 1179 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
1158 } else { 1180 } else {
1159 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM)); 1181 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM));
1160 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM)); 1182 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM));
1161 1183
1162 } 1184 }
1163 } 1185 }
1164 1186
1165} 1187}
1166 1188
1167void KOMonthView::showDates(const QDate &start, const QDate &) 1189void KOMonthView::showDates(const QDate &start, const QDate &)
1168{ 1190{
1169 // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; 1191 // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl;
1170 1192
1171 QPtrVector<MonthViewCell> *cells; 1193 QPtrVector<MonthViewCell> *cells;
1172 QPtrVector<QLabel> *dayLabels; 1194 QPtrVector<QLabel> *dayLabels;
1173 QPtrVector<KOWeekButton> *weekLabels; 1195 QPtrVector<KOWeekButton> *weekLabels;
1174 int weekNum = 6; 1196 int weekNum = 6;
1175 if ( mShowWeekView ) { 1197 if ( mShowWeekView ) {
1176 weekNum = 1; 1198 weekNum = 1;
1177 cells = &mCellsW; 1199 cells = &mCellsW;
1178 dayLabels = &mDayLabelsW; 1200 dayLabels = &mDayLabelsW;
1179 weekLabels = &mWeekLabelsW; 1201 weekLabels = &mWeekLabelsW;
1180 } else { 1202 } else {
1181 cells = &mCells; 1203 cells = &mCells;
1182 dayLabels = &mDayLabels; 1204 dayLabels = &mDayLabels;
1183 weekLabels = &mWeekLabels; 1205 weekLabels = &mWeekLabels;
1184 } 1206 }
1185 1207
1186 mStartDate = start; 1208 mStartDate = start;
1187 1209
1188 int startWeekDay = mWeekStartsMonday ? 1 : 7; 1210 int startWeekDay = mWeekStartsMonday ? 1 : 7;
1189 1211
1190 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { 1212 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) {
1191 mStartDate = mStartDate.addDays( -1 ); 1213 mStartDate = mStartDate.addDays( -1 );
1192 } 1214 }
1193 1215
1194 bool primary = false; 1216 bool primary = false;
1195 uint i; 1217 uint i;
1196 for( i = 0; i < (*cells).size(); ++i ) { 1218 for( i = 0; i < (*cells).size(); ++i ) {
1197 QDate date = mStartDate.addDays( i ); 1219 QDate date = mStartDate.addDays( i );
1198 (*cells)[i]->setDate( date ); 1220 (*cells)[i]->setDate( date );
1199 1221
1200#ifndef KORG_NOPLUGINS 1222#ifndef KORG_NOPLUGINS
1201 // add holiday, if present 1223 // add holiday, if present
1202 QString hstring(KOCore::self()->holiday(date)); 1224 QString hstring(KOCore::self()->holiday(date));
1203 (*cells)[i]->setHoliday( hstring ); 1225 (*cells)[i]->setHoliday( hstring );
1204#endif 1226#endif
1205 1227
1206 } 1228 }
1207 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); 1229 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 );
1208 for( i = 0; i < weekNum; ++i ) { 1230 for( i = 0; i < weekNum; ++i ) {
1209 int wno; 1231 int wno;
1210 // remember, according to ISO 8601, the first week of the year is the 1232 // remember, according to ISO 8601, the first week of the year is the
1211 // first week that contains a thursday. Thus we must subtract off 4, 1233 // first week that contains a thursday. Thus we must subtract off 4,
1212 // not just 1. 1234 // not just 1.
1213 int dayOfYear = date.dayOfYear(); 1235 int dayOfYear = date.dayOfYear();
1214 if (dayOfYear % 7 != 0) 1236 if (dayOfYear % 7 != 0)
1215 wno = dayOfYear / 7 + 1; 1237 wno = dayOfYear / 7 + 1;
1216 else 1238 else
1217 wno =dayOfYear / 7; 1239 wno =dayOfYear / 7;
1218 (*weekLabels)[i]->setWeekNum( wno ); 1240 (*weekLabels)[i]->setWeekNum( wno );
1219 date = date.addDays( 7 ); 1241 date = date.addDays( 7 );
1220 } 1242 }
1221 updateView(); 1243 updateView();
1222} 1244}
1223 1245
1224void KOMonthView::showEvents(QPtrList<Event>) 1246void KOMonthView::showEvents(QPtrList<Event>)
1225{ 1247{
1226 qDebug("KOMonthView::selectEvents is not implemented yet. "); 1248 qDebug("KOMonthView::selectEvents is not implemented yet. ");
1227} 1249}
1228 1250
1229void KOMonthView::changeEventDisplay(Event *, int) 1251void KOMonthView::changeEventDisplay(Event *, int)
1230{ 1252{
1231 // this should be re-written to be much more efficient, but this 1253 // this should be re-written to be much more efficient, but this
1232 // quick-and-dirty-hack gets the job done for right now. 1254 // quick-and-dirty-hack gets the job done for right now.
1233 updateView(); 1255 updateView();
1234} 1256}
1235 1257
1236void KOMonthView::updateView() 1258void KOMonthView::updateView()
1237{ 1259{
1238 1260
1239 if ( !updatePossible ) 1261 if ( !updatePossible )
1240 return; 1262 return;
1241 //QTime ti; 1263 //QTime ti;
1242 //ti.start(); 1264 //ti.start();
1243 clearSelection(); 1265 clearSelection();
1244 QPtrVector<MonthViewCell> *cells; 1266 QPtrVector<MonthViewCell> *cells;
1245 if ( mShowWeekView ) { 1267 if ( mShowWeekView ) {
1246 cells = &mCellsW; 1268 cells = &mCellsW;
1247 } else { 1269 } else {
1248 cells = &mCells; 1270 cells = &mCells;
1249 } 1271 }
1250#if 1 1272#if 1
1251 int i; 1273 int i;
1252 int timeSpan = (*cells).size()-1; 1274 int timeSpan = (*cells).size()-1;
1253 if ( KOPrefs::instance()->mMonthViewWeek ) 1275 if ( KOPrefs::instance()->mMonthViewWeek )
1254 timeSpan = 6; 1276 timeSpan = 6;
1255 for( i = 0; i < timeSpan + 1; ++i ) { 1277 for( i = 0; i < timeSpan + 1; ++i ) {
1256 (*cells)[i]->startUpdateCell(); 1278 (*cells)[i]->startUpdateCell();
1257 } 1279 }
1258 1280
1259 QPtrList<Event> events = calendar()->events(); 1281 QPtrList<Event> events = calendar()->events();
1260 Event *event; 1282 Event *event;
1261 QDateTime dt; 1283 QDateTime dt;
1262 bool ok; 1284 bool ok;
1263 QDate endDate = mStartDate.addDays( timeSpan ); 1285 QDate endDate = mStartDate.addDays( timeSpan );
1264 for( event = events.first(); event; event = events.next() ) { // for event 1286 for( event = events.first(); event; event = events.next() ) { // for event
1265 if ( event->doesRecur() ) { 1287 if ( event->doesRecur() ) {
1266 bool last; 1288 bool last;
1267 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); 1289 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last );
1268 QDateTime incidenceEnd; 1290 QDateTime incidenceEnd;
1269 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); 1291 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() );
1270 bool invalid = false; 1292 bool invalid = false;
1271 while( true ) { 1293 while( true ) {
1272 if ( incidenceStart.isValid() ) { 1294 if ( incidenceStart.isValid() ) {
1273 incidenceEnd = incidenceStart.addDays( eventlen ); 1295 incidenceEnd = incidenceStart.addDays( eventlen );
1274 int st = incidenceStart.date().daysTo( endDate ); 1296 int st = incidenceStart.date().daysTo( endDate );
1275 if ( st >= 0 ) { // start before timeend 1297 if ( st >= 0 ) { // start before timeend
1276 int end = mStartDate.daysTo( incidenceEnd.date() ); 1298 int end = mStartDate.daysTo( incidenceEnd.date() );
1277 if ( end >= 0 ) { // end after timestart --- got one! 1299 if ( end >= 0 ) { // end after timestart --- got one!
1278 //normalize 1300 //normalize
1279 st = timeSpan - st; 1301 st = timeSpan - st;
1280 if ( st < 0 ) st = 0; 1302 if ( st < 0 ) st = 0;
1281 if ( end > timeSpan ) end = timeSpan; 1303 if ( end > timeSpan ) end = timeSpan;
1282 int iii; 1304 int iii;
1283 //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); 1305 //qDebug("found %s %d %d ",event->summary().latin1(), st, end );
1284 for ( iii = st;iii<= end;++iii) 1306 for ( iii = st;iii<= end;++iii)
1285 (*cells)[iii]->insertEvent( event ); 1307 (*cells)[iii]->insertEvent( event );
1286 } 1308 }
1287 } 1309 }
1288 } else { 1310 } else {
1289 if ( invalid ) 1311 if ( invalid )
1290 break; 1312 break;
1291 invalid = true; 1313 invalid = true;
1292 //qDebug("invalid %s", event->summary().latin1()); 1314 //qDebug("invalid %s", event->summary().latin1());
1293 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; 1315 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );;
1294 } 1316 }
1295 if ( last ) 1317 if ( last )
1296 break; 1318 break;
1297 bool ok; 1319 bool ok;
1298 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); 1320 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok );
1299 if ( ! ok ) 1321 if ( ! ok )
1300 break; 1322 break;
1301 if ( incidenceStart.date() > endDate ) 1323 if ( incidenceStart.date() > endDate )
1302 break; 1324 break;
1303 } 1325 }
1304 } else { // no recur 1326 } else { // no recur
1305 int st = event->dtStart().date().daysTo( endDate ); 1327 int st = event->dtStart().date().daysTo( endDate );
1306 if ( st >= 0 ) { // start before timeend 1328 if ( st >= 0 ) { // start before timeend
1307 int end = mStartDate.daysTo( event->dtEnd().date() ); 1329 int end = mStartDate.daysTo( event->dtEnd().date() );
1308 if ( end >= 0 ) { // end after timestart --- got one! 1330 if ( end >= 0 ) { // end after timestart --- got one!
1309 //normalize 1331 //normalize
1310 st = timeSpan - st; 1332 st = timeSpan - st;
1311 if ( st < 0 ) st = 0; 1333 if ( st < 0 ) st = 0;
1312 if ( end > timeSpan ) end = timeSpan; 1334 if ( end > timeSpan ) end = timeSpan;
1313 int iii; 1335 int iii;
1314 for ( iii = st;iii<= end;++iii) 1336 for ( iii = st;iii<= end;++iii)
1315 (*cells)[iii]->insertEvent( event ); 1337 (*cells)[iii]->insertEvent( event );
1316 } 1338 }
1317 } 1339 }
1318 } 1340 }
1319 } 1341 }
1320 // insert due todos 1342 // insert due todos
1321 QPtrList<Todo> todos = calendar()->todos( ); 1343 QPtrList<Todo> todos = calendar()->todos( );
1322 Todo *todo; 1344 Todo *todo;
1323 for(todo = todos.first(); todo; todo = todos.next()) { 1345 for(todo = todos.first(); todo; todo = todos.next()) {
1324 //insertTodo( todo ); 1346 //insertTodo( todo );
1325 if ( todo->hasDueDate() ) { 1347 if ( todo->hasDueDate() ) {
1326 int day = mStartDate.daysTo( todo->dtDue().date() ); 1348 int day = mStartDate.daysTo( todo->dtDue().date() );
1327 if ( day >= 0 && day < timeSpan + 1) { 1349 if ( day >= 0 && day < timeSpan + 1) {
1328 (*cells)[day]->insertTodo( todo ); 1350 (*cells)[day]->insertTodo( todo );
1329 } 1351 }
1330 } 1352 }
1331 } 1353 }
1332 1354
1333 for( i = 0; i < timeSpan+1; ++i ) { 1355 for( i = 0; i < timeSpan+1; ++i ) {
1334 (*cells)[i]->finishUpdateCell(); 1356 (*cells)[i]->finishUpdateCell();
1335 } 1357 }
1336 processSelectionChange(); 1358 processSelectionChange();
1337 (*cells)[0]->setFocus(); 1359 (*cells)[0]->setFocus();
1338 1360
1339 1361
1340#else 1362#else
1341 // old code 1363 // old code
1342 //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); 1364 //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ");
1343 int i; 1365 int i;
1344 for( i = 0; i < (*cells).count(); ++i ) { 1366 for( i = 0; i < (*cells).count(); ++i ) {
1345 (*cells)[i]->updateCell(); 1367 (*cells)[i]->updateCell();
1346 } 1368 }
1347 1369
1348 //qDebug("KOMonthView::updateView() "); 1370 //qDebug("KOMonthView::updateView() ");
1349 processSelectionChange(); 1371 processSelectionChange();
1350 // qDebug("---------------------------------------------------------------------+ "); 1372 // qDebug("---------------------------------------------------------------------+ ");
1351 (*cells)[0]->setFocus(); 1373 (*cells)[0]->setFocus();
1352#endif 1374#endif
1353 1375
1354 //qDebug("update time %d ", ti.elapsed()); 1376 //qDebug("update time %d ", ti.elapsed());
1355} 1377}
1356 1378
1357void KOMonthView::resizeEvent(QResizeEvent * e) 1379void KOMonthView::resizeEvent(QResizeEvent * e)
1358{ 1380{
1359 qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height()); 1381 qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height());
1360 if ( isVisible() ) { 1382 if ( isVisible() ) {
1361 qDebug("KOMonthView::isVisible "); 1383 qDebug("KOMonthView::isVisible ");
1362 slotComputeLayout(); 1384 slotComputeLayout();
1363 } else 1385 } else
1364 mComputeLayoutTimer->start( 100 ); 1386 mComputeLayoutTimer->start( 100 );
1365} 1387}
1366 1388
1367void KOMonthView::slotComputeLayout() 1389void KOMonthView::slotComputeLayout()
1368{ 1390{
1369 mComputeLayoutTimer->stop(); 1391 mComputeLayoutTimer->stop();
1370 qDebug("KOMonthView::Post - resizeEvent %d %d ", width(), height() ); 1392 qDebug("KOMonthView::Post - resizeEvent %d %d ", width(), height() );
1371 computeLayout(); 1393 computeLayout();
1372 clPending = true; 1394 clPending = true;
1373 if ( mShowWeekView ) 1395 if ( mShowWeekView )
1374 mCellsW[0]->setFocus(); 1396 mCellsW[0]->setFocus();
1375 else 1397 else
1376 mCells[0]->setFocus(); 1398 mCells[0]->setFocus();
1377 1399
1378} 1400}
1379void KOMonthView::computeLayoutWeek() 1401void KOMonthView::computeLayoutWeek()
1380{ 1402{
1381 static int lastWid = 0; 1403 static int lastWid = 0;
1382 static int lastHei = 0; 1404 static int lastHei = 0;
1383 int daysToShow; 1405 int daysToShow;
1384 bool combinedSatSun = false; 1406 bool combinedSatSun = false;
1385 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { 1407 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
1386 daysToShow = 6; 1408 daysToShow = 6;
1387 combinedSatSun = true; 1409 combinedSatSun = true;
1388 } 1410 }
1389 int tWid = topLevelWidget()->size().width(); 1411 int tWid = topLevelWidget()->size().width();
1390 int tHei = topLevelWidget()->size().height(); 1412 int tHei = topLevelWidget()->size().height();
1391 1413
1392 int wid = width();//e 1414 int wid = width();//e
1393 int hei = height()-1-mNavigatorBar->height(); 1415 int hei = height()-1-mNavigatorBar->height();
1394 1416
1395 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) 1417 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei )
1396 return; 1418 return;
1397 1419
1398 if ( lastWid == width() && lastHei == height() ) { 1420 if ( lastWid == width() && lastHei == height() ) {
1399 qDebug("KOListWeekView::No compute layout needed "); 1421 qDebug("KOListWeekView::No compute layout needed ");
1400 return; 1422 return;
1401 } 1423 }
1402 lastWid = width(); 1424 lastWid = width();
1403 lastHei = height(); 1425 lastHei = height();
1404 1426
1405 1427
1406 if ( wid < hei ) 1428 if ( wid < hei )
1407 daysToShow = 2; 1429 daysToShow = 2;
1408 else 1430 else
1409 daysToShow = 3; 1431 daysToShow = 3;
1410 mShowSatSunComp = true; 1432 mShowSatSunComp = true;
1411 combinedSatSun = true; 1433 combinedSatSun = true;
1412 1434
1413 //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ "); 1435 //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ ");
1414 QFontMetrics fm ( mWeekLabels[0]->font() ); 1436 QFontMetrics fm ( mWeekLabels[0]->font() );
1415 int weeklabelwid = fm.width( "888" ); 1437 int weeklabelwid = fm.width( "888" );
1416 wid -= weeklabelwid; 1438 wid -= weeklabelwid;
1417 1439
1418 int colWid = wid / daysToShow; 1440 int colWid = wid / daysToShow;
1419 int lastCol = wid - ( colWid*6 ); 1441 int lastCol = wid - ( colWid*6 );
1420 int dayLabelHei = mDayLabelsW[0]->sizeHint().height(); 1442 int dayLabelHei = mDayLabelsW[0]->sizeHint().height();
1421 int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow ); 1443 int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow );
1422 int colModulo = wid % daysToShow; 1444 int colModulo = wid % daysToShow;
1423 int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1; 1445 int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1;
1424 //qDebug("rowmod %d ", rowModulo); 1446 //qDebug("rowmod %d ", rowModulo);
1425 int i; 1447 int i;
1426 int x,y,w,h; 1448 int x,y,w,h;
1427 x= 0; 1449 x= 0;
1428 y= 0; 1450 y= 0;
1429 w = colWid; 1451 w = colWid;
1430 h = dayLabelHei ; 1452 h = dayLabelHei ;
1431 for ( i = 0; i < 7; i++) { 1453 for ( i = 0; i < 7; i++) {
1432 if ( i && !( i % daysToShow) && i < 6) { 1454 if ( i && !( i % daysToShow) && i < 6) {
1433 y += hei/(5-daysToShow); 1455 y += hei/(5-daysToShow);
1434 x = 0; 1456 x = 0;
1435 w = colWid; 1457 w = colWid;
1436 } 1458 }
1437 if ( ((i) % daysToShow) >= daysToShow-colModulo ) { 1459 if ( ((i) % daysToShow) >= daysToShow-colModulo ) {
1438 ++w; 1460 ++w;
1439 } 1461 }
1440 if ( i >= 5 ) { 1462 if ( i >= 5 ) {
1441 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w/2+w%2,h); 1463 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w/2+w%2,h);
1442 x -= (w/2 ); 1464 x -= (w/2 );
1443 } 1465 }
1444 else 1466 else
1445 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w,h); 1467 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w,h);
1446 x += w; 1468 x += w;
1447 } 1469 }
1448 x= 0; 1470 x= 0;
1449 y= dayLabelHei; 1471 y= dayLabelHei;
1450 w = colWid; 1472 w = colWid;
1451 h = cellHei; 1473 h = cellHei;
1452 for ( i = 0; i < mCellsW.count(); ++i) { 1474 for ( i = 0; i < mCellsW.count(); ++i) {
1453 if ( i > 6 ) { 1475 if ( i > 6 ) {
1454 mCellsW[i]->hide(); 1476 mCellsW[i]->hide();
1455 continue; 1477 continue;
1456 } 1478 }
1457 1479
1458 w = colWid; 1480 w = colWid;
1459 if ( ((i) % daysToShow) >= daysToShow-colModulo ) { 1481 if ( ((i) % daysToShow) >= daysToShow-colModulo ) {
1460 ++w; 1482 ++w;
1461 } 1483 }
1462 if ( i == (daysToShow-1-rowModulo)*7) 1484 if ( i == (daysToShow-1-rowModulo)*7)
1463 ++h; 1485 ++h;
1464 1486
1465 if ( i >= 5 ) { 1487 if ( i >= 5 ) {
1466 if ( i ==5 ) { 1488 if ( i ==5 ) {
1467 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h/2 ); 1489 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h/2 );
1468 x -= w ;y += h/2; 1490 x -= w ;y += h/2;
1469 } else { 1491 } else {
1470 if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) { 1492 if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) {
1471 ++w; 1493 ++w;
1472 } 1494 }
1473 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h-h/2 ); 1495 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h-h/2 );
1474 y -= h/2; 1496 y -= h/2;
1475 } 1497 }
1476 } else 1498 } else
1477 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h ); 1499 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h );
1478 1500
1479 1501
1480 x += w; 1502 x += w;
1481 if ( x + w/2 > wid ) { 1503 if ( x + w/2 > wid ) {
1482 x = 0; 1504 x = 0;
1483 y += h+dayLabelHei ; 1505 y += h+dayLabelHei ;
1484 } 1506 }
1485 } 1507 }
1486 y= dayLabelHei; 1508 y= dayLabelHei;
1487 h = cellHei ; 1509 h = cellHei ;
1488 mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei); 1510 mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei);
1489 mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei); 1511 mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
1490 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); 1512 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
1491 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); 1513 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
1492 mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ; 1514 mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ;
1493 updateDayLabels(); 1515 updateDayLabels();
1494 //bool forceUpdate = !updatePossible; 1516 //bool forceUpdate = !updatePossible;
1495 updatePossible = true; 1517 updatePossible = true;
1496 //mWeekLabels[mNumWeeks]->setText( i18n("M")); 1518 //mWeekLabels[mNumWeeks]->setText( i18n("M"));
1497 //if ( forceUpdate ) 1519 //if ( forceUpdate )
1498 // updateView(); 1520 // updateView();
1499} 1521}
1500void KOMonthView::computeLayout() 1522void KOMonthView::computeLayout()
1501{ 1523{
1502 1524
1503 1525
1504 static int lastWid = 0; 1526 static int lastWid = 0;
1505 static int lastHei = 0; 1527 static int lastHei = 0;
1506 1528
1507 if ( mShowWeekView ){ 1529 if ( mShowWeekView ){
1508 computeLayoutWeek(); 1530 computeLayoutWeek();
1509 return; 1531 return;
1510 } 1532 }
1511 int daysToShow = 7; 1533 int daysToShow = 7;
1512 bool combinedSatSun = false; 1534 bool combinedSatSun = false;
1513 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { 1535 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
1514 daysToShow = 6; 1536 daysToShow = 6;
1515 combinedSatSun = true; 1537 combinedSatSun = true;
1516 } 1538 }
1517 int tWid = topLevelWidget()->size().width(); 1539 int tWid = topLevelWidget()->size().width();
1518 int tHei = topLevelWidget()->size().height(); 1540 int tHei = topLevelWidget()->size().height();
1519 1541
1520 int wid = width();//e 1542 int wid = width();//e
1521 int hei = height()-1-mNavigatorBar->height(); 1543 int hei = height()-1-mNavigatorBar->height();
1522 1544
1523 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) { 1545 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) {
1524 return; 1546 return;
1525 } 1547 }
1526 if ( lastWid == width() && lastHei == height() ){ 1548 if ( lastWid == width() && lastHei == height() ){
1527 qDebug("KOMonthview::No compute layout needed "); 1549 qDebug("KOMonthview::No compute layout needed ");
1528 return; 1550 return;
1529 } 1551 }
1530 1552
1531 lastWid = width(); 1553 lastWid = width();
1532 lastHei = height(); 1554 lastHei = height();
1533 qDebug("KOMonthView::computeLayout() MMM ------------------- "); 1555 qDebug("KOMonthView::computeLayout() MMM ------------------- ");
1534 QFontMetrics fm ( mWeekLabels[0]->font() ); 1556 QFontMetrics fm ( mWeekLabels[0]->font() );
1535 int weeklabelwid = fm.width( "888" ); 1557 int weeklabelwid = fm.width( "888" );
1536 wid -= weeklabelwid; 1558 wid -= weeklabelwid;
1537 1559
1538 int colWid = wid / daysToShow; 1560 int colWid = wid / daysToShow;
1539 int lastCol = wid - ( colWid*6 ); 1561 int lastCol = wid - ( colWid*6 );
1540 int dayLabelHei = mDayLabels[0]->sizeHint().height(); 1562 int dayLabelHei = mDayLabels[0]->sizeHint().height();
1541 int cellHei = (hei - dayLabelHei) /6; 1563 int cellHei = (hei - dayLabelHei) /6;
1542 int colModulo = wid % daysToShow; 1564 int colModulo = wid % daysToShow;
1543 int rowModulo = (hei- dayLabelHei) % 6; 1565 int rowModulo = (hei- dayLabelHei) % 6;
1544 //qDebug("rowmod %d ", rowModulo); 1566 //qDebug("rowmod %d ", rowModulo);
1545 int i; 1567 int i;
1546 int x,y,w,h; 1568 int x,y,w,h;
1547 x= 0; 1569 x= 0;
1548 y= 0; 1570 y= 0;
1549 w = colWid; 1571 w = colWid;
1550 h = dayLabelHei ; 1572 h = dayLabelHei ;
1551 for ( i = 0; i < 7; i++) { 1573 for ( i = 0; i < 7; i++) {
1552 if ( i == daysToShow-colModulo ) 1574 if ( i == daysToShow-colModulo )
1553 ++w; 1575 ++w;
1554 if ( combinedSatSun ) { 1576 if ( combinedSatSun ) {
1555 if ( i >= daysToShow-1 ) { 1577 if ( i >= daysToShow-1 ) {
1556 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h); 1578 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h);
1557 x -= w/2 ; 1579 x -= w/2 ;
1558 } 1580 }
1559 else 1581 else
1560 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 1582 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
1561 } else 1583 } else
1562 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 1584 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
1563 x += w; 1585 x += w;
1564 } 1586 }