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