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