summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/komonthview.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp
index df5e060..31c5659 100644
--- a/korganizer/komonthview.cpp
+++ b/korganizer/komonthview.cpp
@@ -1,1278 +1,1278 @@
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 <qwhatsthis.h> 30#include <qwhatsthis.h>
31#ifndef DESKTOP_VERSION 31#ifndef DESKTOP_VERSION
32#include <qpe/qpeapplication.h> 32#include <qpe/qpeapplication.h>
33#else 33#else
34#include <qapplication.h> 34#include <qapplication.h>
35#endif 35#endif
36 36
37#include <kdebug.h> 37#include <kdebug.h>
38#include <klocale.h> 38#include <klocale.h>
39#include <kglobal.h> 39#include <kglobal.h>
40#include <kconfig.h> 40#include <kconfig.h>
41#include <kiconloader.h> 41#include <kiconloader.h>
42 42
43#include <kcalendarsystem.h> 43#include <kcalendarsystem.h>
44 44
45#ifndef KORG_NOPRINTER 45#ifndef KORG_NOPRINTER
46#include "calprinter.h" 46#include "calprinter.h"
47#endif 47#endif
48#include "koprefs.h" 48#include "koprefs.h"
49#ifndef KORG_NOPLUGINS 49#ifndef KORG_NOPLUGINS
50#include "kocore.h" 50#include "kocore.h"
51#endif 51#endif
52#include "koglobals.h" 52#include "koglobals.h"
53#include <libkcal/kincidenceformatter.h> 53#include <libkcal/kincidenceformatter.h>
54 54
55#include "komonthview.h" 55#include "komonthview.h"
56 56
57#define PIXMAP_SIZE 5 57#define PIXMAP_SIZE 5
58#ifdef DESKTOP_VERSION 58#ifdef DESKTOP_VERSION
59QToolTipGroup *MonthViewCell::mToolTipGroup = 0; 59QToolTipGroup *MonthViewCell::mToolTipGroup = 0;
60#endif 60#endif
61class KNOWhatsThis :public QWhatsThis 61class KNOWhatsThis :public QWhatsThis
62{ 62{
63public: 63public:
64 KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { }; 64 KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { };
65 //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); }; 65 //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); };
66 66
67protected: 67protected:
68 virtual QString text( const QPoint& p) 68 virtual QString text( const QPoint& p)
69 { 69 {
70 return _wid->getWhatsThisText(p) ; 70 return _wid->getWhatsThisText(p) ;
71 }; 71 };
72private: 72private:
73 KNoScrollListBox* _wid; 73 KNoScrollListBox* _wid;
74 74
75}; 75};
76 76
77 77
78KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) 78KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name)
79 : QListBox(parent, name, WRepaintNoErase) 79 : QListBox(parent, name, WRepaintNoErase)
80{ 80{
81#ifndef DESKTOP_VERSION 81#ifndef DESKTOP_VERSION
82 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 82 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
83#endif 83#endif
84 mWT = new KNOWhatsThis(this); 84 mWT = new KNOWhatsThis(this);
85} 85}
86KNoScrollListBox::~KNoScrollListBox() 86KNoScrollListBox::~KNoScrollListBox()
87{ 87{
88 88
89} 89}
90QString KNoScrollListBox::getWhatsThisText(QPoint p) 90QString KNoScrollListBox::getWhatsThisText(QPoint p)
91{ 91{
92 QListBoxItem* item = itemAt ( p ); 92 QListBoxItem* item = itemAt ( p );
93 if ( ! item ) { 93 if ( ! item ) {
94 return i18n("Click in the cell\nto add an event!"); 94 return i18n("Click in the cell\nto add an event!");
95 } 95 }
96 return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence()); 96 return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence());
97} 97}
98void KNoScrollListBox::keyPressEvent(QKeyEvent *e) 98void KNoScrollListBox::keyPressEvent(QKeyEvent *e)
99{ 99{
100 100
101 switch(e->key()) { 101 switch(e->key()) {
102 case Key_Right: 102 case Key_Right:
103 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 103 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
104 { 104 {
105 e->ignore(); 105 e->ignore();
106 return; 106 return;
107 } 107 }
108 scrollBy(10,0); 108 scrollBy(10,0);
109 break; 109 break;
110 case Key_Left: 110 case Key_Left:
111 if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 111 if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
112 { 112 {
113 e->ignore(); 113 e->ignore();
114 return; 114 return;
115 } 115 }
116 scrollBy(-10,0); 116 scrollBy(-10,0);
117 break; 117 break;
118 case Key_Up: 118 case Key_Up:
119 if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { 119 if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) {
120 e->ignore(); 120 e->ignore();
121 break; 121 break;
122 } 122 }
123 setCurrentItem((currentItem()+count()-1)%count()); 123 setCurrentItem((currentItem()+count()-1)%count());
124 if(!itemVisible(currentItem())) { 124 if(!itemVisible(currentItem())) {
125 if((unsigned int) currentItem() == (count()-1)) { 125 if((unsigned int) currentItem() == (count()-1)) {
126 setTopItem(currentItem()-numItemsVisible()+1); 126 setTopItem(currentItem()-numItemsVisible()+1);
127 } else { 127 } else {
128 setTopItem(topItem()-1); 128 setTopItem(topItem()-1);
129 } 129 }
130 } 130 }
131 break; 131 break;
132 case Key_Down: 132 case Key_Down:
133 if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { 133 if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) {
134 e->ignore(); 134 e->ignore();
135 break; 135 break;
136 } 136 }
137 setCurrentItem((currentItem()+1)%count()); 137 setCurrentItem((currentItem()+1)%count());
138 if(!itemVisible(currentItem())) { 138 if(!itemVisible(currentItem())) {
139 if(currentItem() == 0) { 139 if(currentItem() == 0) {
140 setTopItem(0); 140 setTopItem(0);
141 } else { 141 } else {
142 setTopItem(topItem()+1); 142 setTopItem(topItem()+1);
143 } 143 }
144 } 144 }
145 break; 145 break;
146 case Key_I: 146 case Key_I:
147 QTimer::singleShot( 11, this, SLOT ( oneDown() ) ); 147 QTimer::singleShot( 11, this, SLOT ( oneDown() ) );
148 e->ignore(); 148 e->ignore();
149 break; 149 break;
150 case Key_Shift: 150 case Key_Shift:
151 emit shiftDown(); 151 emit shiftDown();
152 break; 152 break;
153 default: 153 default:
154 e->ignore(); 154 e->ignore();
155 break; 155 break;
156 } 156 }
157} 157}
158 158
159void KNoScrollListBox::oneDown() 159void KNoScrollListBox::oneDown()
160{ 160{
161 setCurrentItem((currentItem()+1)%count()); 161 setCurrentItem((currentItem()+1)%count());
162 if(!itemVisible(currentItem())) { 162 if(!itemVisible(currentItem())) {
163 if(currentItem() == 0) { 163 if(currentItem() == 0) {
164 setTopItem(0); 164 setTopItem(0);
165 } else { 165 } else {
166 setTopItem(topItem()+1); 166 setTopItem(topItem()+1);
167 } 167 }
168 } 168 }
169} 169}
170void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) 170void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e)
171{ 171{
172 switch(e->key()) { 172 switch(e->key()) {
173 case Key_Shift: 173 case Key_Shift:
174 emit shiftUp(); 174 emit shiftUp();
175 break; 175 break;
176 default: 176 default:
177 break; 177 break;
178 } 178 }
179} 179}
180 180
181void KNoScrollListBox::mousePressEvent(QMouseEvent *e) 181void KNoScrollListBox::mousePressEvent(QMouseEvent *e)
182{ 182{
183 QListBox::mousePressEvent(e); 183 QListBox::mousePressEvent(e);
184 184
185 if(e->button() == RightButton) { 185 if(e->button() == RightButton) {
186 emit rightClick(); 186 emit rightClick();
187 } 187 }
188} 188}
189 189
190MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) 190MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s)
191 : QListBoxItem() 191 : QListBoxItem()
192{ 192{
193 setText( s ); 193 setText( s );
194 194
195 mIncidence = incidence; 195 mIncidence = incidence;
196 mDate = qd; 196 mDate = qd;
197 // QWhatsThis::add(this,KIncidenceFormatter::instance()->getFormattedText( mIncidence )); 197 // QWhatsThis::add(this,KIncidenceFormatter::instance()->getFormattedText( mIncidence ));
198 mRecur = false; 198 mRecur = false;
199 mAlarm = false; 199 mAlarm = false;
200 mReply = false; 200 mReply = false;
201 mInfo = false; 201 mInfo = false;
202} 202}
203 203
204void MonthViewItem::paint(QPainter *p) 204void MonthViewItem::paint(QPainter *p)
205{ 205{
206#if QT_VERSION >= 0x030000 206#if QT_VERSION >= 0x030000
207 bool sel = isSelected(); 207 bool sel = isSelected();
208#else 208#else
209 bool sel = selected(); 209 bool sel = selected();
210#endif 210#endif
211 211
212 212
213 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) 213 if (KOPrefs::instance()->mMonthViewUsesCategoryColor)
214 { 214 {
215 p->setBackgroundColor( palette().color( QPalette::Normal, \ 215 p->setBackgroundColor( palette().color( QPalette::Normal, \
216 sel ? QColorGroup::Highlight : QColorGroup::Background ) ); 216 sel ? QColorGroup::Highlight : QColorGroup::Background ) );
217 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); 217 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) );
218 } 218 }
219 int x = 1; 219 int x = 1;
220 int y = 3;//(height() - mRecurPixmap.height()) /2; 220 int y = 3;//(height() - mRecurPixmap.height()) /2;
221 int size = PIXMAP_SIZE; 221 int size = PIXMAP_SIZE;
222 if ( QApplication::desktop()->width() < 300 ) 222 if ( QApplication::desktop()->width() < 300 )
223 size = 3; 223 size = 3;
224 if ( KOPrefs::instance()->mMonthShowIcons ) { 224 if ( KOPrefs::instance()->mMonthShowIcons ) {
225 if ( mInfo ) { 225 if ( mInfo ) {
226 p->fillRect ( x, y,size,size, Qt::darkGreen ); 226 p->fillRect ( x, y,size,size, Qt::darkGreen );
227 x += size + 1; 227 x += size + 1;
228 } 228 }
229 if ( mRecur ) { 229 if ( mRecur ) {
230 p->fillRect ( x, y,size,size, Qt::blue ); 230 p->fillRect ( x, y,size,size, Qt::blue );
231 x += size + 1; 231 x += size + 1;
232 } 232 }
233 if ( mAlarm ) { 233 if ( mAlarm ) {
234 p->fillRect ( x, y,size,size, Qt::red ); 234 p->fillRect ( x, y,size,size, Qt::red );
235 x += size + 1; 235 x += size + 1;
236 } 236 }
237 if ( mReply ) { 237 if ( mReply ) {
238 p->fillRect ( x, y,size,size, Qt::yellow ); 238 p->fillRect ( x, y,size,size, Qt::yellow );
239 x += size + 1; 239 x += size + 1;
240 } 240 }
241 } 241 }
242 QFontMetrics fm = p->fontMetrics(); 242 QFontMetrics fm = p->fontMetrics();
243 int yPos; 243 int yPos;
244 int pmheight = size; 244 int pmheight = size;
245 if( pmheight < fm.height() ) 245 if( pmheight < fm.height() )
246 yPos = fm.ascent() + fm.leading()/2; 246 yPos = fm.ascent() + fm.leading()/2;
247 else 247 else
248 yPos = pmheight/2 - fm.height()/2 + fm.ascent(); 248 yPos = pmheight/2 - fm.height()/2 + fm.ascent();
249 p->setPen( palette().color( QPalette::Normal, sel ? \ 249 p->setPen( palette().color( QPalette::Normal, sel ? \
250 QColorGroup::HighlightedText : QColorGroup::Foreground ) ); 250 QColorGroup::HighlightedText : QColorGroup::Foreground ) );
251 p->drawText( x, yPos, text() ); 251 p->drawText( x, yPos, text() );
252 if ( mIncidence->cancelled() ) { 252 if ( mIncidence->cancelled() ) {
253 int wid = fm.width( text() ); 253 int wid = fm.width( text() );
254 p->drawLine( x, yPos- fm.height()/2+2,x+wid, yPos- fm.height()/2 +2); 254 p->drawLine( x, yPos- fm.height()/2+3,x+wid, yPos- fm.height()/2 +3);
255 } 255 }
256 256
257} 257}
258 258
259int MonthViewItem::height(const QListBox *lb) const 259int MonthViewItem::height(const QListBox *lb) const
260{ 260{
261 return lb->fontMetrics().lineSpacing()+1; 261 return lb->fontMetrics().lineSpacing()+1;
262} 262}
263 263
264int MonthViewItem::width(const QListBox *lb) const 264int MonthViewItem::width(const QListBox *lb) const
265{ 265{
266 int size = PIXMAP_SIZE; 266 int size = PIXMAP_SIZE;
267 if ( QApplication::desktop()->width() < 300 ) 267 if ( QApplication::desktop()->width() < 300 )
268 size = 3; 268 size = 3;
269 int x = 1; 269 int x = 1;
270 if ( mInfo ) { 270 if ( mInfo ) {
271 x += size + 1; 271 x += size + 1;
272 } 272 }
273 if( mRecur ) { 273 if( mRecur ) {
274 x += size+1; 274 x += size+1;
275 } 275 }
276 if( mAlarm ) { 276 if( mAlarm ) {
277 x += size+1; 277 x += size+1;
278 } 278 }
279 if( mReply ) { 279 if( mReply ) {
280 x += size+1; 280 x += size+1;
281 } 281 }
282 282
283 return( x + lb->fontMetrics().width( text() ) + 1 ); 283 return( x + lb->fontMetrics().width( text() ) + 1 );
284} 284}
285 285
286 286
287MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) 287MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par )
288 : QWidget( par ), 288 : QWidget( par ),
289 mMonthView( parent ) 289 mMonthView( parent )
290{ 290{
291 291
292 QVBoxLayout *topLayout = new QVBoxLayout( this ); 292 QVBoxLayout *topLayout = new QVBoxLayout( this );
293 293
294 // mLabel = new QLabel( this );QPushButton 294 // mLabel = new QLabel( this );QPushButton
295 mLabel = new QPushButton( this ); 295 mLabel = new QPushButton( this );
296 //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); 296 //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain );
297 //mLabel->setLineWidth( 1 ); 297 //mLabel->setLineWidth( 1 );
298 //mLabel->setAlignment( AlignCenter ); 298 //mLabel->setAlignment( AlignCenter );
299 mLabel->setFlat( true ); 299 mLabel->setFlat( true );
300 mLabel->setFocusPolicy(NoFocus); 300 mLabel->setFocusPolicy(NoFocus);
301 mItemList = new KNoScrollListBox( this ); 301 mItemList = new KNoScrollListBox( this );
302 mItemList->setMinimumSize( 10, 10 ); 302 mItemList->setMinimumSize( 10, 10 );
303 mItemList->setFrameStyle( QFrame::Panel | QFrame::Plain ); 303 mItemList->setFrameStyle( QFrame::Panel | QFrame::Plain );
304 mItemList->setLineWidth( 1 ); 304 mItemList->setLineWidth( 1 );
305 topLayout->addWidget( mItemList ); 305 topLayout->addWidget( mItemList );
306 mLabel->raise(); 306 mLabel->raise();
307 // QColor( 0,0,255 ) QColor( 160,1600,255 ) 307 // QColor( 0,0,255 ) QColor( 160,1600,255 )
308 mStandardPalette = palette(); 308 mStandardPalette = palette();
309 mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); 309 mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) );
310 310
311 enableScrollBars( false ); 311 enableScrollBars( false );
312 updateConfig(); 312 updateConfig();
313 //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() )); 313 //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() ));
314 connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() )); 314 connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() ));
315 connect( mItemList, SIGNAL( doubleClicked( QListBoxItem *) ), 315 connect( mItemList, SIGNAL( doubleClicked( QListBoxItem *) ),
316 SLOT( defaultAction( QListBoxItem * ) ) ); 316 SLOT( defaultAction( QListBoxItem * ) ) );
317 connect( mItemList, SIGNAL( rightButtonPressed( QListBoxItem *, 317 connect( mItemList, SIGNAL( rightButtonPressed( QListBoxItem *,
318 const QPoint &) ), 318 const QPoint &) ),
319 SLOT( contextMenu( QListBoxItem * ) ) ); 319 SLOT( contextMenu( QListBoxItem * ) ) );
320 connect( mItemList, SIGNAL( highlighted( QListBoxItem *) ), 320 connect( mItemList, SIGNAL( highlighted( QListBoxItem *) ),
321 SLOT( selection( QListBoxItem * ) ) ); 321 SLOT( selection( QListBoxItem * ) ) );
322 connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), 322 connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ),
323 SLOT( cellClicked( QListBoxItem * ) ) ); 323 SLOT( cellClicked( QListBoxItem * ) ) );
324 connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), 324 connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ),
325 SLOT( selection( QListBoxItem * ) ) ); 325 SLOT( selection( QListBoxItem * ) ) );
326} 326}
327#ifdef DESKTOP_VERSION 327#ifdef DESKTOP_VERSION
328QToolTipGroup *MonthViewCell::toolTipGroup() 328QToolTipGroup *MonthViewCell::toolTipGroup()
329{ 329{
330 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); 330 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0);
331 return mToolTipGroup; 331 return mToolTipGroup;
332} 332}
333#endif 333#endif
334 334
335void MonthViewCell::setDate( const QDate &date ) 335void MonthViewCell::setDate( const QDate &date )
336{ 336{
337 // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl; 337 // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl;
338 mDate = date; 338 mDate = date;
339 339
340 340
341 341
342 //resizeEvent( 0 ); 342 //resizeEvent( 0 );
343} 343}
344 344
345QDate MonthViewCell::date() const 345QDate MonthViewCell::date() const
346{ 346{
347 return mDate; 347 return mDate;
348} 348}
349 349
350void MonthViewCell::setPrimary( bool primary ) 350void MonthViewCell::setPrimary( bool primary )
351{ 351{
352 mPrimary = primary; 352 mPrimary = primary;
353 //setMyPalette(); 353 //setMyPalette();
354} 354}
355void MonthViewCell::setMyPalette() 355void MonthViewCell::setMyPalette()
356{ 356{
357 357
358 if ( mHoliday) { 358 if ( mHoliday) {
359 setPalette( mHolidayPalette ); 359 setPalette( mHolidayPalette );
360 } else { 360 } else {
361 if ( mPrimary ) { 361 if ( mPrimary ) {
362 setPalette( mPrimaryPalette ); 362 setPalette( mPrimaryPalette );
363 } else { 363 } else {
364 setPalette( mNonPrimaryPalette ); 364 setPalette( mNonPrimaryPalette );
365 } 365 }
366 } 366 }
367 QPalette pal = palette(); 367 QPalette pal = palette();
368 368
369 mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) )); 369 mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) ));
370} 370}
371QPalette MonthViewCell::getPalette () 371QPalette MonthViewCell::getPalette ()
372{ 372{
373 if ( !KOPrefs::instance()->mMonthViewUsesDayColors ) 373 if ( !KOPrefs::instance()->mMonthViewUsesDayColors )
374 return mStandardPalette; 374 return mStandardPalette;
375 if ( mHoliday) { 375 if ( mHoliday) {
376 return mHolidayPalette ; 376 return mHolidayPalette ;
377 } else { 377 } else {
378 if ( mPrimary ) { 378 if ( mPrimary ) {
379 return mPrimaryPalette ; 379 return mPrimaryPalette ;
380 } 380 }
381 } 381 }
382 return mNonPrimaryPalette; 382 return mNonPrimaryPalette;
383} 383}
384bool MonthViewCell::isPrimary() const 384bool MonthViewCell::isPrimary() const
385{ 385{
386 return mPrimary; 386 return mPrimary;
387} 387}
388 388
389void MonthViewCell::setHoliday( bool holiday ) 389void MonthViewCell::setHoliday( bool holiday )
390{ 390{
391 mHoliday = holiday; 391 mHoliday = holiday;
392 //setMyPalette(); 392 //setMyPalette();
393} 393}
394 394
395void MonthViewCell::setHoliday( const QString &holiday ) 395void MonthViewCell::setHoliday( const QString &holiday )
396{ 396{
397 mHolidayString = holiday; 397 mHolidayString = holiday;
398 398
399 if ( !holiday.isEmpty() ) { 399 if ( !holiday.isEmpty() ) {
400 setHoliday( true ); 400 setHoliday( true );
401 } 401 }
402} 402}
403void MonthViewCell::keyPressEvent ( QKeyEvent * e ) 403void MonthViewCell::keyPressEvent ( QKeyEvent * e )
404{ 404{
405 405
406 e->ignore(); 406 e->ignore();
407 407
408} 408}
409void MonthViewCell::clear() 409void MonthViewCell::clear()
410{ 410{
411 mItemList->clear(); 411 mItemList->clear();
412 QApplication::removePostedEvents ( mItemList ); 412 QApplication::removePostedEvents ( mItemList );
413 QApplication::removePostedEvents ( mLabel ); 413 QApplication::removePostedEvents ( mLabel );
414 QApplication::removePostedEvents ( this ); 414 QApplication::removePostedEvents ( this );
415} 415}
416 416
417void MonthViewCell::startUpdateCell() 417void MonthViewCell::startUpdateCell()
418{ 418{
419 419
420 mItemList->setFocusPolicy(NoFocus); 420 mItemList->setFocusPolicy(NoFocus);
421 if ( !mMonthView->isUpdatePossible() ) 421 if ( !mMonthView->isUpdatePossible() )
422 return; 422 return;
423 423
424 /* 424 /*
425 if ( !isVisible() ){ 425 if ( !isVisible() ){
426 return; 426 return;
427 } 427 }
428 */ 428 */
429 // qDebug("MonthViewCell::updateCell() "); 429 // qDebug("MonthViewCell::updateCell() ");
430 setPrimary( mDate.month()%2 ); 430 setPrimary( mDate.month()%2 );
431 setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays); 431 setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays);
432 if ( mDate == QDate::currentDate() ) { 432 if ( mDate == QDate::currentDate() ) {
433 mItemList->setLineWidth( 3 ); 433 mItemList->setLineWidth( 3 );
434 } else { 434 } else {
435 mItemList->setLineWidth( 1 ); 435 mItemList->setLineWidth( 1 );
436 } 436 }
437 mItemList->clear(); 437 mItemList->clear();
438 438
439#ifdef DESKTOP_VERSION 439#ifdef DESKTOP_VERSION
440 QToolTip::remove(this); 440 QToolTip::remove(this);
441#endif 441#endif
442 mToolTip = ""; 442 mToolTip = "";
443 //qApp->processEvents(); 443 //qApp->processEvents();
444 if ( !mHolidayString.isEmpty() ) { 444 if ( !mHolidayString.isEmpty() ) {
445 MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); 445 MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString );
446 item->setPalette( mHolidayPalette ); 446 item->setPalette( mHolidayPalette );
447 mItemList->insertItem( item ); 447 mItemList->insertItem( item );
448 mToolTip += mHolidayString+"\n"; 448 mToolTip += mHolidayString+"\n";
449 } 449 }
450} 450}
451 451
452void MonthViewCell::insertEvent(Event *event) 452void MonthViewCell::insertEvent(Event *event)
453{ 453{
454 454
455 mItemList->setFocusPolicy(WheelFocus); 455 mItemList->setFocusPolicy(WheelFocus);
456 if ( !(event->doesRecur() == Recurrence::rNone) ) { 456 if ( !(event->doesRecur() == Recurrence::rNone) ) {
457 if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) 457 if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily )
458 return; 458 return;
459 else 459 else
460 if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) 460 if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly )
461 return; 461 return;
462 } 462 }
463 463
464 if ( event->categories().contains("Holiday") || 464 if ( event->categories().contains("Holiday") ||
465 event->categories().contains(i18n("Holiday"))) { 465 event->categories().contains(i18n("Holiday"))) {
466 setHoliday( true ); 466 setHoliday( true );
467 if ( mDate.dayOfWeek() == 7 ) 467 if ( mDate.dayOfWeek() == 7 )
468 mItemList->setLineWidth( 3 ); 468 mItemList->setLineWidth( 3 );
469 } 469 }
470 QString text; 470 QString text;
471 if (event->isMultiDay()) { 471 if (event->isMultiDay()) {
472 QString prefix = "<->"; 472 QString prefix = "<->";
473 if ( event->doesRecur() ) { 473 if ( event->doesRecur() ) {
474 if ( event->recursOn( mDate) ) 474 if ( event->recursOn( mDate) )
475 prefix ="->" ; 475 prefix ="->" ;
476 else { 476 else {
477 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 477 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
478 if ( event->recursOn( mDate.addDays( -days)) ) 478 if ( event->recursOn( mDate.addDays( -days)) )
479 prefix ="<-" ; 479 prefix ="<-" ;
480 } 480 }
481 481
482 } else { 482 } else {
483 if (mDate == event->dtStart().date()) { 483 if (mDate == event->dtStart().date()) {
484 prefix ="->" ; 484 prefix ="->" ;
485 } else if (mDate == event->dtEnd().date()) { 485 } else if (mDate == event->dtEnd().date()) {
486 prefix ="<-" ; 486 prefix ="<-" ;
487 } 487 }
488 } 488 }
489 if ( !event->doesFloat() ) { 489 if ( !event->doesFloat() ) {
490 if ( mDate == event->dtStart().date () ) 490 if ( mDate == event->dtStart().date () )
491 prefix += KGlobal::locale()->formatTime(event->dtStart().time())+" "; 491 prefix += KGlobal::locale()->formatTime(event->dtStart().time())+" ";
492 else if ( mDate == event->dtEnd().date () ) 492 else if ( mDate == event->dtEnd().date () )
493 prefix += KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 493 prefix += KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
494 494
495 } 495 }
496 text = prefix + event->summary(); 496 text = prefix + event->summary();
497 mToolTip += text; 497 mToolTip += text;
498 } else { 498 } else {
499 if (event->doesFloat()) { 499 if (event->doesFloat()) {
500 text = event->summary(); 500 text = event->summary();
501 mToolTip += text; 501 mToolTip += text;
502 } 502 }
503 else { 503 else {
504 text = KGlobal::locale()->formatTime(event->dtStart().time()); 504 text = KGlobal::locale()->formatTime(event->dtStart().time());
505 text += " " + event->summary(); 505 text += " " + event->summary();
506 mToolTip += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 506 mToolTip += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
507 } 507 }
508 } 508 }
509 509
510 MonthViewItem *item = new MonthViewItem( event, mDate, text ); 510 MonthViewItem *item = new MonthViewItem( event, mDate, text );
511 QPalette pal; 511 QPalette pal;
512 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { 512 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
513 QStringList categories = event->categories(); 513 QStringList categories = event->categories();
514 QString cat = categories.first(); 514 QString cat = categories.first();
515 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { 515 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
516 pal = getPalette(); 516 pal = getPalette();
517 if (cat.isEmpty()) { 517 if (cat.isEmpty()) {
518 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); 518 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
519 } else { 519 } else {
520 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); 520 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
521 } 521 }
522 522
523 } else { 523 } else {
524 if (cat.isEmpty()) { 524 if (cat.isEmpty()) {
525 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); 525 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
526 } else { 526 } else {
527 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); 527 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
528 } 528 }
529 } 529 }
530 530
531 } else { 531 } else {
532 pal = mStandardPalette ; 532 pal = mStandardPalette ;
533 } 533 }
534 item->setPalette( pal ); 534 item->setPalette( pal );
535 item->setRecur( event->recurrence()->doesRecur() ); 535 item->setRecur( event->recurrence()->doesRecur() );
536 item->setAlarm( event->isAlarmEnabled() ); 536 item->setAlarm( event->isAlarmEnabled() );
537 item->setMoreInfo( event->description().length() > 0 ); 537 item->setMoreInfo( event->description().length() > 0 );
538#ifdef DESKTOP_VERSION 538#ifdef DESKTOP_VERSION
539 Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, 539 Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails,
540 KOPrefs::instance()->email()); 540 KOPrefs::instance()->email());
541 if ( me != 0 ) { 541 if ( me != 0 ) {
542 if ( me->status() == Attendee::NeedsAction && me->RSVP()) 542 if ( me->status() == Attendee::NeedsAction && me->RSVP())
543 item->setReply(true); 543 item->setReply(true);
544 else 544 else
545 item->setReply(false); 545 item->setReply(false);
546 } else 546 } else
547 item->setReply(false); 547 item->setReply(false);
548#endif 548#endif
549 mItemList->insertItem( item ); 549 mItemList->insertItem( item );
550 mToolTip += "\n"; 550 mToolTip += "\n";
551} 551}
552void MonthViewCell::insertTodo(Todo *todo) 552void MonthViewCell::insertTodo(Todo *todo)
553{ 553{
554 QString text; 554 QString text;
555 if (todo->hasDueDate()) { 555 if (todo->hasDueDate()) {
556 if (!todo->doesFloat()) { 556 if (!todo->doesFloat()) {
557 text += KGlobal::locale()->formatTime(todo->dtDue().time()); 557 text += KGlobal::locale()->formatTime(todo->dtDue().time());
558 text += " "; 558 text += " ";
559 } 559 }
560 } 560 }
561 text += i18n("Td: %1").arg(todo->summary()); 561 text += i18n("Td: %1").arg(todo->summary());
562 562
563 MonthViewItem *item = new MonthViewItem( todo, mDate, text ); 563 MonthViewItem *item = new MonthViewItem( todo, mDate, text );
564 //item->setPalette( mStandardPalette ); 564 //item->setPalette( mStandardPalette );
565 QPalette pal; 565 QPalette pal;
566 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { 566 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
567 QStringList categories = todo->categories(); 567 QStringList categories = todo->categories();
568 QString cat = categories.first(); 568 QString cat = categories.first();
569 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { 569 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
570 pal = getPalette(); 570 pal = getPalette();
571 if (cat.isEmpty()) { 571 if (cat.isEmpty()) {
572 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); 572 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
573 } else { 573 } else {
574 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); 574 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
575 } 575 }
576 576
577 } else { 577 } else {
578 if (cat.isEmpty()) { 578 if (cat.isEmpty()) {
579 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); 579 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
580 } else { 580 } else {
581 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); 581 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
582 } 582 }
583 } 583 }
584 584
585 } else { 585 } else {
586 pal = mStandardPalette ; 586 pal = mStandardPalette ;
587 } 587 }
588 item->setPalette( pal ); 588 item->setPalette( pal );
589 mItemList->insertItem( item ); 589 mItemList->insertItem( item );
590 mToolTip += text+"\n"; 590 mToolTip += text+"\n";
591} 591}
592void MonthViewCell::finishUpdateCell() 592void MonthViewCell::finishUpdateCell()
593{ 593{
594#ifdef DESKTOP_VERSION 594#ifdef DESKTOP_VERSION
595 if (mToolTip != "") 595 if (mToolTip != "")
596 QToolTip::add(this,mToolTip,toolTipGroup(),""); 596 QToolTip::add(this,mToolTip,toolTipGroup(),"");
597#endif 597#endif
598 mItemList->sort(); 598 mItemList->sort();
599 //setMyPalette(); 599 //setMyPalette();
600 setMyPalette(); 600 setMyPalette();
601 QString text; 601 QString text;
602 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; 602 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog;
603 if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { 603 if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) {
604 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " "; 604 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " ";
605 mLabel->resize( mLabelBigSize ); 605 mLabel->resize( mLabelBigSize );
606 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 606 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
607 } else { 607 } else {
608 mLabel->resize( mLabelSize ); 608 mLabel->resize( mLabelSize );
609 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 609 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
610 } 610 }
611 611
612 mLabel->setText( text ); 612 mLabel->setText( text );
613 resizeEvent( 0 ); 613 resizeEvent( 0 );
614} 614}
615void MonthViewCell::updateCell() 615void MonthViewCell::updateCell()
616{ 616{
617 if ( !mMonthView->isUpdatePossible() ) 617 if ( !mMonthView->isUpdatePossible() )
618 return; 618 return;
619 startUpdateCell(); 619 startUpdateCell();
620 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 620 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
621 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); 621 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true );
622 Event *event; 622 Event *event;
623 for( event = events.first(); event; event = events.next() ) { // for event 623 for( event = events.first(); event; event = events.next() ) { // for event
624 insertEvent(event); 624 insertEvent(event);
625 } 625 }
626 // insert due todos 626 // insert due todos
627 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); 627 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate );
628 Todo *todo; 628 Todo *todo;
629 for(todo = todos.first(); todo; todo = todos.next()) { 629 for(todo = todos.first(); todo; todo = todos.next()) {
630 insertTodo( todo ); 630 insertTodo( todo );
631 } 631 }
632 finishUpdateCell(); 632 finishUpdateCell();
633 // if ( isVisible()) 633 // if ( isVisible())
634 //qApp->processEvents(); 634 //qApp->processEvents();
635} 635}
636 636
637void MonthViewCell::updateConfig( bool bigFont ) // = false 637void MonthViewCell::updateConfig( bool bigFont ) // = false
638{ 638{
639 639
640 if ( bigFont ) { 640 if ( bigFont ) {
641 QFont fo = KOPrefs::instance()->mMonthViewFont; 641 QFont fo = KOPrefs::instance()->mMonthViewFont;
642 int ps = fo.pointSize() + 2; 642 int ps = fo.pointSize() + 2;
643 if ( ps < 18 ) 643 if ( ps < 18 )
644 ps += 2; 644 ps += 2;
645 fo.setPointSize( ps ); 645 fo.setPointSize( ps );
646 setFont( fo ); 646 setFont( fo );
647 } else 647 } else
648 setFont( KOPrefs::instance()->mMonthViewFont ); 648 setFont( KOPrefs::instance()->mMonthViewFont );
649 649
650 QFontMetrics fm( font() ); 650 QFontMetrics fm( font() );
651 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); 651 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 );
652 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); 652 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 );
653 mHolidayPalette = mStandardPalette; 653 mHolidayPalette = mStandardPalette;
654 mPrimaryPalette = mStandardPalette; 654 mPrimaryPalette = mStandardPalette;
655 mNonPrimaryPalette = mStandardPalette; 655 mNonPrimaryPalette = mStandardPalette;
656 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { 656 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) {
657 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); 657 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor );
658 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); 658 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor );
659 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); 659 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark());
660 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); 660 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark());
661 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); 661 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor);
662 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); 662 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor);
663 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); 663 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark());
664 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); 664 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor);
665 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); 665 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor);
666 } 666 }
667 //updateCell(); 667 //updateCell();
668} 668}
669 669
670void MonthViewCell::enableScrollBars( bool enabled ) 670void MonthViewCell::enableScrollBars( bool enabled )
671{ 671{
672 if ( enabled ) { 672 if ( enabled ) {
673 mItemList->setVScrollBarMode(QScrollView::Auto); 673 mItemList->setVScrollBarMode(QScrollView::Auto);
674 mItemList->setHScrollBarMode(QScrollView::Auto); 674 mItemList->setHScrollBarMode(QScrollView::Auto);
675 } else { 675 } else {
676 mItemList->setVScrollBarMode(QScrollView::AlwaysOff); 676 mItemList->setVScrollBarMode(QScrollView::AlwaysOff);
677 mItemList->setHScrollBarMode(QScrollView::AlwaysOff); 677 mItemList->setHScrollBarMode(QScrollView::AlwaysOff);
678 } 678 }
679} 679}
680 680
681Incidence *MonthViewCell::selectedIncidence() 681Incidence *MonthViewCell::selectedIncidence()
682{ 682{
683 int index = mItemList->currentItem(); 683 int index = mItemList->currentItem();
684 if ( index < 0 ) return 0; 684 if ( index < 0 ) return 0;
685 685
686 MonthViewItem *item = 686 MonthViewItem *item =
687 static_cast<MonthViewItem *>( mItemList->item( index ) ); 687 static_cast<MonthViewItem *>( mItemList->item( index ) );
688 688
689 if ( !item ) return 0; 689 if ( !item ) return 0;
690 690
691 return item->incidence(); 691 return item->incidence();
692} 692}
693 693
694QDate MonthViewCell::selectedIncidenceDate() 694QDate MonthViewCell::selectedIncidenceDate()
695{ 695{
696 QDate qd; 696 QDate qd;
697 int index = mItemList->currentItem(); 697 int index = mItemList->currentItem();
698 if ( index < 0 ) return qd; 698 if ( index < 0 ) return qd;
699 699
700 MonthViewItem *item = 700 MonthViewItem *item =
701 static_cast<MonthViewItem *>( mItemList->item( index ) ); 701 static_cast<MonthViewItem *>( mItemList->item( index ) );
702 702
703 if ( !item ) return qd; 703 if ( !item ) return qd;
704 704
705 return item->incidenceDate(); 705 return item->incidenceDate();
706} 706}
707 707
708void MonthViewCell::deselect() 708void MonthViewCell::deselect()
709{ 709{
710 mItemList->clearSelection(); 710 mItemList->clearSelection();
711 enableScrollBars( false ); 711 enableScrollBars( false );
712 // updateCell(); 712 // updateCell();
713} 713}
714void MonthViewCell::select() 714void MonthViewCell::select()
715{ 715{
716 ;// updateCell(); 716 ;// updateCell();
717} 717}
718 718
719void MonthViewCell::resizeEvent ( QResizeEvent * ) 719void MonthViewCell::resizeEvent ( QResizeEvent * )
720{ 720{
721 if ( !mMonthView->isUpdatePossible() ) 721 if ( !mMonthView->isUpdatePossible() )
722 return; 722 return;
723 723
724 int size = height() - mLabel->height() - 2; 724 int size = height() - mLabel->height() - 2;
725 if ( size > 0 ) 725 if ( size > 0 )
726 mItemList->verticalScrollBar()->setMaximumHeight( size ); 726 mItemList->verticalScrollBar()->setMaximumHeight( size );
727 size = width() - mLabel->width() -2; 727 size = width() - mLabel->width() -2;
728 if ( size > 0 ) 728 if ( size > 0 )
729 mItemList->horizontalScrollBar()->setMaximumWidth( size ); 729 mItemList->horizontalScrollBar()->setMaximumWidth( size );
730 mLabel->move( width()-mItemList->lineWidth() - mLabel->width(), height()-mItemList->lineWidth() - mLabel->height() ); 730 mLabel->move( width()-mItemList->lineWidth() - mLabel->width(), height()-mItemList->lineWidth() - mLabel->height() );
731 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 731 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
732} 732}
733 733
734void MonthViewCell::defaultAction( QListBoxItem *item ) 734void MonthViewCell::defaultAction( QListBoxItem *item )
735{ 735{
736 if ( !item ) return; 736 if ( !item ) return;
737 737
738 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 738 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
739 Incidence *incidence = eventItem->incidence(); 739 Incidence *incidence = eventItem->incidence();
740 if ( incidence ) mMonthView->defaultAction( incidence ); 740 if ( incidence ) mMonthView->defaultAction( incidence );
741} 741}
742void MonthViewCell::showDay() 742void MonthViewCell::showDay()
743{ 743{
744 emit showDaySignal( date() ); 744 emit showDaySignal( date() );
745} 745}
746void MonthViewCell::newEvent() 746void MonthViewCell::newEvent()
747{ 747{
748 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 748 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
749 emit newEventSignal( dt ); 749 emit newEventSignal( dt );
750} 750}
751void MonthViewCell::cellClicked( QListBoxItem *item ) 751void MonthViewCell::cellClicked( QListBoxItem *item )
752{ 752{
753 static QListBoxItem * lastClicked = 0; 753 static QListBoxItem * lastClicked = 0;
754 if ( item == 0 ) { 754 if ( item == 0 ) {
755 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 755 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
756 emit newEventSignal( dt ); 756 emit newEventSignal( dt );
757 return; 757 return;
758 } 758 }
759 /* 759 /*
760 if ( lastClicked ) 760 if ( lastClicked )
761 if ( ! item ) { 761 if ( ! item ) {
762 if ( lastClicked->listBox() != item->listBox() ) 762 if ( lastClicked->listBox() != item->listBox() )
763 lastClicked->listBox()->clearSelection(); 763 lastClicked->listBox()->clearSelection();
764 } 764 }
765 */ 765 */
766 766
767 mMonthView->setSelectedCell( this ); 767 mMonthView->setSelectedCell( this );
768 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true ); 768 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true );
769 select(); 769 select();
770} 770}
771 771
772void MonthViewCell::contextMenu( QListBoxItem *item ) 772void MonthViewCell::contextMenu( QListBoxItem *item )
773{ 773{
774 if ( !item ) return; 774 if ( !item ) return;
775 775
776 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 776 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
777 Incidence *incidence = eventItem->incidence(); 777 Incidence *incidence = eventItem->incidence();
778 if ( incidence ) mMonthView->showContextMenu( incidence ); 778 if ( incidence ) mMonthView->showContextMenu( incidence );
779} 779}
780 780
781void MonthViewCell::selection( QListBoxItem *item ) 781void MonthViewCell::selection( QListBoxItem *item )
782{ 782{
783 if ( !item ) return; 783 if ( !item ) return;
784 784
785 mMonthView->setSelectedCell( this ); 785 mMonthView->setSelectedCell( this );
786} 786}
787 787
788 788
789// ******************************************************************************* 789// *******************************************************************************
790// ******************************************************************************* 790// *******************************************************************************
791// ******************************************************************************* 791// *******************************************************************************
792 792
793 793
794KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) 794KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name)
795 : KOEventView( calendar, parent, name ), 795 : KOEventView( calendar, parent, name ),
796 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), 796 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
797 mShortDayLabels( false ), mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) 797 mShortDayLabels( false ), mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
798{ 798{
799 799
800 clPending = true; 800 clPending = true;
801 mWidStack = new QWidgetStack( this ); 801 mWidStack = new QWidgetStack( this );
802 QHBoxLayout* hb = new QHBoxLayout( this ); 802 QHBoxLayout* hb = new QHBoxLayout( this );
803 mMonthView = new QWidget( mWidStack ); 803 mMonthView = new QWidget( mWidStack );
804 mWeekView = new QWidget( mWidStack ); 804 mWeekView = new QWidget( mWidStack );
805#if QT_VERSION >= 0x030000 805#if QT_VERSION >= 0x030000
806 mWidStack->addWidget(mMonthView ); 806 mWidStack->addWidget(mMonthView );
807 mWidStack->addWidget(mWeekView ); 807 mWidStack->addWidget(mWeekView );
808#else 808#else
809 mWidStack->addWidget( mMonthView, 1 ); 809 mWidStack->addWidget( mMonthView, 1 );
810 mWidStack->addWidget( mWeekView , 1 ); 810 mWidStack->addWidget( mWeekView , 1 );
811#endif 811#endif
812 hb->addWidget( mWidStack ); 812 hb->addWidget( mWidStack );
813 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 813 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
814 mShowWeekView = KOPrefs::instance()->mMonthViewWeek; 814 mShowWeekView = KOPrefs::instance()->mMonthViewWeek;
815 if ( mShowWeekView ) 815 if ( mShowWeekView )
816 mWeekStartsMonday = true; 816 mWeekStartsMonday = true;
817 updatePossible = false; 817 updatePossible = false;
818 mCells.setAutoDelete( true ); 818 mCells.setAutoDelete( true );
819 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 819 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
820 mDayLabels.resize( mDaysPerWeek ); 820 mDayLabels.resize( mDaysPerWeek );
821 mDayLabelsW.resize( mDaysPerWeek ); 821 mDayLabelsW.resize( mDaysPerWeek );
822 QFont bfont = font(); 822 QFont bfont = font();
823 if ( QApplication::desktop()->width() < 650 ) { 823 if ( QApplication::desktop()->width() < 650 ) {
824 bfont.setPointSize( bfont.pointSize() - 2 ); 824 bfont.setPointSize( bfont.pointSize() - 2 );
825 } 825 }
826 bfont.setBold( true ); 826 bfont.setBold( true );
827 int i; 827 int i;
828 828
829 for( i = 0; i < mDaysPerWeek; i++ ) { 829 for( i = 0; i < mDaysPerWeek; i++ ) {
830 QLabel *label = new QLabel( mMonthView ); 830 QLabel *label = new QLabel( mMonthView );
831 label->setFont(bfont); 831 label->setFont(bfont);
832 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 832 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
833 label->setLineWidth(1); 833 label->setLineWidth(1);
834 label->setAlignment(AlignCenter); 834 label->setAlignment(AlignCenter);
835 mDayLabels.insert( i, label ); 835 mDayLabels.insert( i, label );
836 label = new QLabel( mWeekView ); 836 label = new QLabel( mWeekView );
837 label->setFont(bfont); 837 label->setFont(bfont);
838 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 838 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
839 label->setLineWidth(1); 839 label->setLineWidth(1);
840 label->setAlignment(AlignCenter); 840 label->setAlignment(AlignCenter);
841 mDayLabelsW.insert( i, label ); 841 mDayLabelsW.insert( i, label );
842 } 842 }
843 843
844 bfont.setBold( false ); 844 bfont.setBold( false );
845 mWeekLabels.resize( mNumWeeks+1 ); 845 mWeekLabels.resize( mNumWeeks+1 );
846 mWeekLabelsW.resize( 2 ); 846 mWeekLabelsW.resize( 2 );
847 for( i = 0; i < mNumWeeks+1; i++ ) { 847 for( i = 0; i < mNumWeeks+1; i++ ) {
848 KOWeekButton *label = new KOWeekButton( mMonthView ); 848 KOWeekButton *label = new KOWeekButton( mMonthView );
849 label->setFocusPolicy(NoFocus); 849 label->setFocusPolicy(NoFocus);
850 label->setFont(bfont); 850 label->setFont(bfont);
851 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 851 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
852 label->setFlat(true); 852 label->setFlat(true);
853 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 853 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
854 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 854 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
855 //label->setLineWidth(1); 855 //label->setLineWidth(1);
856 //label->setAlignment(AlignCenter); 856 //label->setAlignment(AlignCenter);
857 mWeekLabels.insert( i, label ); 857 mWeekLabels.insert( i, label );
858 } 858 }
859 mWeekLabels[mNumWeeks]->setText( i18n("W")); 859 mWeekLabels[mNumWeeks]->setText( i18n("W"));
860 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number")); 860 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number"));
861 861
862 for( i = 0; i < 1+1; i++ ) { 862 for( i = 0; i < 1+1; i++ ) {
863 KOWeekButton *label = new KOWeekButton( mWeekView ); 863 KOWeekButton *label = new KOWeekButton( mWeekView );
864 label->setFocusPolicy(NoFocus); 864 label->setFocusPolicy(NoFocus);
865 label->setFont(bfont); 865 label->setFont(bfont);
866 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 866 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
867 label->setFlat(true); 867 label->setFlat(true);
868 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 868 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
869 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 869 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
870 //label->setLineWidth(1); 870 //label->setLineWidth(1);
871 //label->setAlignment(AlignCenter); 871 //label->setAlignment(AlignCenter);
872 mWeekLabelsW.insert( i, label ); 872 mWeekLabelsW.insert( i, label );
873 } 873 }
874 mWeekLabelsW[1]->setText( i18n("W")); 874 mWeekLabelsW[1]->setText( i18n("W"));
875 875
876 876
877 int row, col; 877 int row, col;
878 mCells.resize( mNumCells ); 878 mCells.resize( mNumCells );
879 for( row = 0; row < mNumWeeks; ++row ) { 879 for( row = 0; row < mNumWeeks; ++row ) {
880 for( col = 0; col < mDaysPerWeek; ++col ) { 880 for( col = 0; col < mDaysPerWeek; ++col ) {
881 MonthViewCell *cell = new MonthViewCell( this, mMonthView ); 881 MonthViewCell *cell = new MonthViewCell( this, mMonthView );
882 mCells.insert( row * mDaysPerWeek + col, cell ); 882 mCells.insert( row * mDaysPerWeek + col, cell );
883 883
884 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 884 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
885 SLOT( defaultAction( Incidence * ) ) ); 885 SLOT( defaultAction( Incidence * ) ) );
886 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 886 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
887 SIGNAL( newEventSignal( QDateTime ) ) ); 887 SIGNAL( newEventSignal( QDateTime ) ) );
888 connect( cell, SIGNAL( showDaySignal( QDate ) ), 888 connect( cell, SIGNAL( showDaySignal( QDate ) ),
889 SIGNAL( showDaySignal( QDate ) ) ); 889 SIGNAL( showDaySignal( QDate ) ) );
890 } 890 }
891 } 891 }
892 mCellsW.resize( mDaysPerWeek ); 892 mCellsW.resize( mDaysPerWeek );
893 for( col = 0; col < mDaysPerWeek; ++col ) { 893 for( col = 0; col < mDaysPerWeek; ++col ) {
894 MonthViewCell *cell = new MonthViewCell( this, mWeekView ); 894 MonthViewCell *cell = new MonthViewCell( this, mWeekView );
895 mCellsW.insert( col, cell ); 895 mCellsW.insert( col, cell );
896 896
897 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 897 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
898 SLOT( defaultAction( Incidence * ) ) ); 898 SLOT( defaultAction( Incidence * ) ) );
899 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 899 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
900 SIGNAL( newEventSignal( QDateTime ) ) ); 900 SIGNAL( newEventSignal( QDateTime ) ) );
901 connect( cell, SIGNAL( showDaySignal( QDate ) ), 901 connect( cell, SIGNAL( showDaySignal( QDate ) ),
902 SIGNAL( showDaySignal( QDate ) ) ); 902 SIGNAL( showDaySignal( QDate ) ) );
903 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); 903 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont );
904 } 904 }
905 905
906 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); 906 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) );
907 mContextMenu = eventPopup(); 907 mContextMenu = eventPopup();
908 // updateConfig(); //useless here 908 // updateConfig(); //useless here
909 909
910 //mWeekLabels[mNumWeeks]->setText( i18n("W")); 910 //mWeekLabels[mNumWeeks]->setText( i18n("W"));
911#if 0 911#if 0
912 mWidStack = new QWidgetStack( this ); 912 mWidStack = new QWidgetStack( this );
913 mMonthView = new QWidget( mWidStack ); 913 mMonthView = new QWidget( mWidStack );
914 mWeekView = new QWidget( mWidStack ); 914 mWeekView = new QWidget( mWidStack );
915#endif 915#endif
916 if ( mShowWeekView ) 916 if ( mShowWeekView )
917 mWidStack->raiseWidget( mWeekView ); 917 mWidStack->raiseWidget( mWeekView );
918 else 918 else
919 mWidStack->raiseWidget( mMonthView ); 919 mWidStack->raiseWidget( mMonthView );
920 920
921 emit incidenceSelected( 0 ); 921 emit incidenceSelected( 0 );
922} 922}
923 923
924KOMonthView::~KOMonthView() 924KOMonthView::~KOMonthView()
925{ 925{
926 delete mContextMenu; 926 delete mContextMenu;
927} 927}
928 928
929void KOMonthView::selectInternalWeekNum ( int n ) 929void KOMonthView::selectInternalWeekNum ( int n )
930{ 930{
931 switchView(); 931 switchView();
932 emit selectWeekNum ( n ); 932 emit selectWeekNum ( n );
933} 933}
934 934
935int KOMonthView::currentWeek() 935int KOMonthView::currentWeek()
936{ 936{
937 if ( mShowWeekView ) 937 if ( mShowWeekView )
938 return mWeekLabelsW[0]->getWeekNum(); 938 return mWeekLabelsW[0]->getWeekNum();
939 return mWeekLabels[0]->getWeekNum(); 939 return mWeekLabels[0]->getWeekNum();
940} 940}
941void KOMonthView::switchView() 941void KOMonthView::switchView()
942{ 942{
943 943
944 if ( selectedCell( ) ) 944 if ( selectedCell( ) )
945 selectedCell()->deselect(); 945 selectedCell()->deselect();
946 mShowWeekView = !mShowWeekView; 946 mShowWeekView = !mShowWeekView;
947 KOPrefs::instance()->mMonthViewWeek = mShowWeekView; 947 KOPrefs::instance()->mMonthViewWeek = mShowWeekView;
948 //emit showNavigator( !mShowWeekView ); 948 //emit showNavigator( !mShowWeekView );
949 if ( clPending ) { 949 if ( clPending ) {
950 computeLayout(); 950 computeLayout();
951 updateConfig(); 951 updateConfig();
952 } 952 }
953 if ( mShowWeekView ) 953 if ( mShowWeekView )
954 mWidStack->raiseWidget( mWeekView ); 954 mWidStack->raiseWidget( mWeekView );
955 else 955 else
956 mWidStack->raiseWidget( mMonthView ); 956 mWidStack->raiseWidget( mMonthView );
957 clPending = false; 957 clPending = false;
958} 958}
959 959
960int KOMonthView::maxDatesHint() 960int KOMonthView::maxDatesHint()
961{ 961{
962 return mNumCells; 962 return mNumCells;
963} 963}
964 964
965int KOMonthView::currentDateCount() 965int KOMonthView::currentDateCount()
966{ 966{
967 return mNumCells; 967 return mNumCells;
968} 968}
969 969
970QPtrList<Incidence> KOMonthView::selectedIncidences() 970QPtrList<Incidence> KOMonthView::selectedIncidences()
971{ 971{
972 QPtrList<Incidence> selected; 972 QPtrList<Incidence> selected;
973 973
974 if ( mSelectedCell ) { 974 if ( mSelectedCell ) {
975 Incidence *incidence = mSelectedCell->selectedIncidence(); 975 Incidence *incidence = mSelectedCell->selectedIncidence();
976 if ( incidence ) selected.append( incidence ); 976 if ( incidence ) selected.append( incidence );
977 } 977 }
978 978
979 return selected; 979 return selected;
980} 980}
981 981
982DateList KOMonthView::selectedDates() 982DateList KOMonthView::selectedDates()
983{ 983{
984 DateList selected; 984 DateList selected;
985 985
986 if ( mSelectedCell ) { 986 if ( mSelectedCell ) {
987 QDate qd = mSelectedCell->selectedIncidenceDate(); 987 QDate qd = mSelectedCell->selectedIncidenceDate();
988 if ( qd.isValid() ) selected.append( qd ); 988 if ( qd.isValid() ) selected.append( qd );
989 } 989 }
990 990
991 return selected; 991 return selected;
992} 992}
993 993
994void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, 994void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd,
995 const QDate &td) 995 const QDate &td)
996{ 996{
997#ifndef KORG_NOPRINTER 997#ifndef KORG_NOPRINTER
998 calPrinter->preview(CalPrinter::Month, fd, td); 998 calPrinter->preview(CalPrinter::Month, fd, td);
999#endif 999#endif
1000} 1000}
1001 1001
1002void KOMonthView::updateConfig() 1002void KOMonthView::updateConfig()
1003{ 1003{
1004 1004
1005 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 1005 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
1006 1006
1007 if ( mShowWeekView ) { 1007 if ( mShowWeekView ) {
1008 mWeekStartsMonday = true; 1008 mWeekStartsMonday = true;
1009 } 1009 }
1010 QFontMetrics fontmetric(mDayLabels[0]->font()); 1010 QFontMetrics fontmetric(mDayLabels[0]->font());
1011 mWidthLongDayLabel = 0; 1011 mWidthLongDayLabel = 0;
1012 1012
1013 for (int i = 0; i < 7; i++) { 1013 for (int i = 0; i < 7; i++) {
1014 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 1014 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
1015 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 1015 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
1016 } 1016 }
1017 bool temp = mShowSatSunComp ; 1017 bool temp = mShowSatSunComp ;
1018 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 1018 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
1019 if ( ! mShowWeekView ) { 1019 if ( ! mShowWeekView ) {
1020 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) 1020 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog )
1021 computeLayout(); 1021 computeLayout();
1022 } 1022 }
1023 updateDayLabels(); 1023 updateDayLabels();
1024 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); 1024 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks);
1025 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; 1025 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks;
1026 //resizeEvent( 0 ); 1026 //resizeEvent( 0 );
1027 for (uint i = 0; i < mCells.count(); ++i) { 1027 for (uint i = 0; i < mCells.count(); ++i) {
1028 mCells[i]->updateConfig(); 1028 mCells[i]->updateConfig();
1029 } 1029 }
1030 1030
1031 for (uint i = 0; i < mCellsW.count(); ++i) { 1031 for (uint i = 0; i < mCellsW.count(); ++i) {
1032 mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont); 1032 mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont);
1033 } 1033 }
1034#ifdef DESKTOP_VERSION 1034#ifdef DESKTOP_VERSION
1035 MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); 1035 MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips);
1036#endif 1036#endif
1037 updateView(); 1037 updateView();
1038} 1038}
1039 1039
1040void KOMonthView::updateDayLabels() 1040void KOMonthView::updateDayLabels()
1041{ 1041{
1042 1042
1043 QPtrVector<QLabel> *mDayLabelsT; 1043 QPtrVector<QLabel> *mDayLabelsT;
1044#if 0 1044#if 0
1045 if (mShowWeekView ) 1045 if (mShowWeekView )
1046 mDayLabelsT = &mDayLabelsW; 1046 mDayLabelsT = &mDayLabelsW;
1047 else 1047 else
1048 mDayLabelsT = &mDayLabels; 1048 mDayLabelsT = &mDayLabels;
1049#endif 1049#endif
1050 1050
1051 mDayLabelsT = &mDayLabelsW; 1051 mDayLabelsT = &mDayLabelsW;
1052 for (int i = 0; i < 7; i++) { 1052 for (int i = 0; i < 7; i++) {
1053 if (mWeekStartsMonday) { 1053 if (mWeekStartsMonday) {
1054 bool show = mShortDayLabels; 1054 bool show = mShortDayLabels;
1055 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) 1055 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
1056 show = true; 1056 show = true;
1057 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); 1057 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
1058 } else { 1058 } else {
1059 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabels)); 1059 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabels));
1060 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabels)); 1060 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabels));
1061 1061
1062 } 1062 }
1063 } 1063 }
1064 mDayLabelsT = &mDayLabels; 1064 mDayLabelsT = &mDayLabels;
1065 for (int i = 0; i < 7; i++) { 1065 for (int i = 0; i < 7; i++) {
1066 if (mWeekStartsMonday) { 1066 if (mWeekStartsMonday) {
1067 bool show = mShortDayLabels; 1067 bool show = mShortDayLabels;
1068 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) 1068 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
1069 show = true; 1069 show = true;
1070 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); 1070 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
1071 } else { 1071 } else {
1072 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabels)); 1072 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabels));
1073 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabels)); 1073 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabels));
1074 1074
1075 } 1075 }
1076 } 1076 }
1077 1077
1078} 1078}
1079 1079
1080void KOMonthView::showDates(const QDate &start, const QDate &) 1080void KOMonthView::showDates(const QDate &start, const QDate &)
1081{ 1081{
1082 // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; 1082 // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl;
1083 1083
1084 QPtrVector<MonthViewCell> *cells; 1084 QPtrVector<MonthViewCell> *cells;
1085 QPtrVector<QLabel> *dayLabels; 1085 QPtrVector<QLabel> *dayLabels;
1086 QPtrVector<KOWeekButton> *weekLabels; 1086 QPtrVector<KOWeekButton> *weekLabels;
1087 int weekNum = 6; 1087 int weekNum = 6;
1088 if ( mShowWeekView ) { 1088 if ( mShowWeekView ) {
1089 weekNum = 1; 1089 weekNum = 1;
1090 cells = &mCellsW; 1090 cells = &mCellsW;
1091 dayLabels = &mDayLabelsW; 1091 dayLabels = &mDayLabelsW;
1092 weekLabels = &mWeekLabelsW; 1092 weekLabels = &mWeekLabelsW;
1093 } else { 1093 } else {
1094 cells = &mCells; 1094 cells = &mCells;
1095 dayLabels = &mDayLabels; 1095 dayLabels = &mDayLabels;
1096 weekLabels = &mWeekLabels; 1096 weekLabels = &mWeekLabels;
1097 } 1097 }
1098 1098
1099 mStartDate = start; 1099 mStartDate = start;
1100 1100
1101 int startWeekDay = mWeekStartsMonday ? 1 : 7; 1101 int startWeekDay = mWeekStartsMonday ? 1 : 7;
1102 1102
1103 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { 1103 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) {
1104 mStartDate = mStartDate.addDays( -1 ); 1104 mStartDate = mStartDate.addDays( -1 );
1105 } 1105 }
1106 1106
1107 bool primary = false; 1107 bool primary = false;
1108 uint i; 1108 uint i;
1109 for( i = 0; i < (*cells).size(); ++i ) { 1109 for( i = 0; i < (*cells).size(); ++i ) {
1110 QDate date = mStartDate.addDays( i ); 1110 QDate date = mStartDate.addDays( i );
1111 (*cells)[i]->setDate( date ); 1111 (*cells)[i]->setDate( date );
1112 1112
1113#ifndef KORG_NOPLUGINS 1113#ifndef KORG_NOPLUGINS
1114 // add holiday, if present 1114 // add holiday, if present
1115 QString hstring(KOCore::self()->holiday(date)); 1115 QString hstring(KOCore::self()->holiday(date));
1116 (*cells)[i]->setHoliday( hstring ); 1116 (*cells)[i]->setHoliday( hstring );
1117#endif 1117#endif
1118 1118
1119 } 1119 }
1120 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); 1120 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 );
1121 for( i = 0; i < weekNum; ++i ) { 1121 for( i = 0; i < weekNum; ++i ) {
1122 int wno; 1122 int wno;
1123 // remember, according to ISO 8601, the first week of the year is the 1123 // remember, according to ISO 8601, the first week of the year is the
1124 // first week that contains a thursday. Thus we must subtract off 4, 1124 // first week that contains a thursday. Thus we must subtract off 4,
1125 // not just 1. 1125 // not just 1.
1126 int dayOfYear = date.dayOfYear(); 1126 int dayOfYear = date.dayOfYear();
1127 if (dayOfYear % 7 != 0) 1127 if (dayOfYear % 7 != 0)
1128 wno = dayOfYear / 7 + 1; 1128 wno = dayOfYear / 7 + 1;
1129 else 1129 else
1130 wno =dayOfYear / 7; 1130 wno =dayOfYear / 7;
1131 (*weekLabels)[i]->setWeekNum( wno ); 1131 (*weekLabels)[i]->setWeekNum( wno );
1132 date = date.addDays( 7 ); 1132 date = date.addDays( 7 );
1133 } 1133 }
1134 updateView(); 1134 updateView();
1135} 1135}
1136 1136
1137void KOMonthView::showEvents(QPtrList<Event>) 1137void KOMonthView::showEvents(QPtrList<Event>)
1138{ 1138{
1139 qDebug("KOMonthView::selectEvents is not implemented yet. "); 1139 qDebug("KOMonthView::selectEvents is not implemented yet. ");
1140} 1140}
1141 1141
1142void KOMonthView::changeEventDisplay(Event *, int) 1142void KOMonthView::changeEventDisplay(Event *, int)
1143{ 1143{
1144 // this should be re-written to be much more efficient, but this 1144 // this should be re-written to be much more efficient, but this
1145 // quick-and-dirty-hack gets the job done for right now. 1145 // quick-and-dirty-hack gets the job done for right now.
1146 updateView(); 1146 updateView();
1147} 1147}
1148 1148
1149void KOMonthView::updateView() 1149void KOMonthView::updateView()
1150{ 1150{
1151 1151
1152 if ( !updatePossible ) 1152 if ( !updatePossible )
1153 return; 1153 return;
1154 //QTime ti; 1154 //QTime ti;
1155 //ti.start(); 1155 //ti.start();
1156 QPtrVector<MonthViewCell> *cells; 1156 QPtrVector<MonthViewCell> *cells;
1157 if ( mShowWeekView ) { 1157 if ( mShowWeekView ) {
1158 cells = &mCellsW; 1158 cells = &mCellsW;
1159 } else { 1159 } else {
1160 cells = &mCells; 1160 cells = &mCells;
1161 } 1161 }
1162#if 1 1162#if 1
1163 int i; 1163 int i;
1164 int timeSpan = (*cells).size()-1; 1164 int timeSpan = (*cells).size()-1;
1165 if ( KOPrefs::instance()->mMonthViewWeek ) 1165 if ( KOPrefs::instance()->mMonthViewWeek )
1166 timeSpan = 6; 1166 timeSpan = 6;
1167 for( i = 0; i < timeSpan + 1; ++i ) { 1167 for( i = 0; i < timeSpan + 1; ++i ) {
1168 (*cells)[i]->startUpdateCell(); 1168 (*cells)[i]->startUpdateCell();
1169 } 1169 }
1170 1170
1171 QPtrList<Event> events = calendar()->events(); 1171 QPtrList<Event> events = calendar()->events();
1172 Event *event; 1172 Event *event;
1173 QDateTime dt; 1173 QDateTime dt;
1174 bool ok; 1174 bool ok;
1175 QDate endDate = mStartDate.addDays( timeSpan ); 1175 QDate endDate = mStartDate.addDays( timeSpan );
1176 for( event = events.first(); event; event = events.next() ) { // for event 1176 for( event = events.first(); event; event = events.next() ) { // for event
1177 if ( event->doesRecur() ) { 1177 if ( event->doesRecur() ) {
1178 bool last; 1178 bool last;
1179 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); 1179 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last );
1180 QDateTime incidenceEnd; 1180 QDateTime incidenceEnd;
1181 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); 1181 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() );
1182 bool invalid = false; 1182 bool invalid = false;
1183 while( true ) { 1183 while( true ) {
1184 if ( incidenceStart.isValid() ) { 1184 if ( incidenceStart.isValid() ) {
1185 incidenceEnd = incidenceStart.addDays( eventlen ); 1185 incidenceEnd = incidenceStart.addDays( eventlen );
1186 int st = incidenceStart.date().daysTo( endDate ); 1186 int st = incidenceStart.date().daysTo( endDate );
1187 if ( st >= 0 ) { // start before timeend 1187 if ( st >= 0 ) { // start before timeend
1188 int end = mStartDate.daysTo( incidenceEnd.date() ); 1188 int end = mStartDate.daysTo( incidenceEnd.date() );
1189 if ( end >= 0 ) { // end after timestart --- got one! 1189 if ( end >= 0 ) { // end after timestart --- got one!
1190 //normalize 1190 //normalize
1191 st = timeSpan - st; 1191 st = timeSpan - st;
1192 if ( st < 0 ) st = 0; 1192 if ( st < 0 ) st = 0;
1193 if ( end > timeSpan ) end = timeSpan; 1193 if ( end > timeSpan ) end = timeSpan;
1194 int iii; 1194 int iii;
1195 //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); 1195 //qDebug("found %s %d %d ",event->summary().latin1(), st, end );
1196 for ( iii = st;iii<= end;++iii) 1196 for ( iii = st;iii<= end;++iii)
1197 (*cells)[iii]->insertEvent( event ); 1197 (*cells)[iii]->insertEvent( event );
1198 } 1198 }
1199 } 1199 }
1200 } else { 1200 } else {
1201 if ( invalid ) 1201 if ( invalid )
1202 break; 1202 break;
1203 invalid = true; 1203 invalid = true;
1204 //qDebug("invalid %s", event->summary().latin1()); 1204 //qDebug("invalid %s", event->summary().latin1());
1205 incidenceStart = QDateTime( mStartDate ); 1205 incidenceStart = QDateTime( mStartDate );
1206 } 1206 }
1207 if ( last ) 1207 if ( last )
1208 break; 1208 break;
1209 bool ok; 1209 bool ok;
1210 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); 1210 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok );
1211 if ( ! ok ) 1211 if ( ! ok )
1212 break; 1212 break;
1213 if ( incidenceStart.date() > endDate ) 1213 if ( incidenceStart.date() > endDate )
1214 break; 1214 break;
1215 } 1215 }
1216 } else { // no recur 1216 } else { // no recur
1217 int st = event->dtStart().date().daysTo( endDate ); 1217 int st = event->dtStart().date().daysTo( endDate );
1218 if ( st >= 0 ) { // start before timeend 1218 if ( st >= 0 ) { // start before timeend
1219 int end = mStartDate.daysTo( event->dtEnd().date() ); 1219 int end = mStartDate.daysTo( event->dtEnd().date() );
1220 if ( end >= 0 ) { // end after timestart --- got one! 1220 if ( end >= 0 ) { // end after timestart --- got one!
1221 //normalize 1221 //normalize
1222 st = timeSpan - st; 1222 st = timeSpan - st;
1223 if ( st < 0 ) st = 0; 1223 if ( st < 0 ) st = 0;
1224 if ( end > timeSpan ) end = timeSpan; 1224 if ( end > timeSpan ) end = timeSpan;
1225 int iii; 1225 int iii;
1226 for ( iii = st;iii<= end;++iii) 1226 for ( iii = st;iii<= end;++iii)
1227 (*cells)[iii]->insertEvent( event ); 1227 (*cells)[iii]->insertEvent( event );
1228 } 1228 }
1229 } 1229 }
1230 } 1230 }
1231 } 1231 }
1232 // insert due todos 1232 // insert due todos
1233 QPtrList<Todo> todos = calendar()->todos( ); 1233 QPtrList<Todo> todos = calendar()->todos( );
1234 Todo *todo; 1234 Todo *todo;
1235 for(todo = todos.first(); todo; todo = todos.next()) { 1235 for(todo = todos.first(); todo; todo = todos.next()) {
1236 //insertTodo( todo ); 1236 //insertTodo( todo );
1237 if ( todo->hasDueDate() ) { 1237 if ( todo->hasDueDate() ) {
1238 int day = mStartDate.daysTo( todo->dtDue().date() ); 1238 int day = mStartDate.daysTo( todo->dtDue().date() );
1239 if ( day >= 0 && day < timeSpan + 1) { 1239 if ( day >= 0 && day < timeSpan + 1) {
1240 (*cells)[day]->insertTodo( todo ); 1240 (*cells)[day]->insertTodo( todo );
1241 } 1241 }
1242 } 1242 }
1243 } 1243 }
1244 1244
1245 for( i = 0; i < timeSpan+1; ++i ) { 1245 for( i = 0; i < timeSpan+1; ++i ) {
1246 (*cells)[i]->finishUpdateCell(); 1246 (*cells)[i]->finishUpdateCell();
1247 } 1247 }
1248 processSelectionChange(); 1248 processSelectionChange();
1249 (*cells)[0]->setFocus(); 1249 (*cells)[0]->setFocus();
1250 1250
1251 1251
1252#else 1252#else
1253 // old code 1253 // old code
1254 //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); 1254 //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ");
1255 int i; 1255 int i;
1256 for( i = 0; i < (*cells).count(); ++i ) { 1256 for( i = 0; i < (*cells).count(); ++i ) {
1257 (*cells)[i]->updateCell(); 1257 (*cells)[i]->updateCell();
1258 } 1258 }
1259 1259
1260 //qDebug("KOMonthView::updateView() "); 1260 //qDebug("KOMonthView::updateView() ");
1261 processSelectionChange(); 1261 processSelectionChange();
1262 // qDebug("---------------------------------------------------------------------+ "); 1262 // qDebug("---------------------------------------------------------------------+ ");
1263 (*cells)[0]->setFocus(); 1263 (*cells)[0]->setFocus();
1264#endif 1264#endif
1265 1265
1266 //qDebug("update time %d ", ti.elapsed()); 1266 //qDebug("update time %d ", ti.elapsed());
1267} 1267}
1268 1268
1269void KOMonthView::resizeEvent(QResizeEvent * e) 1269void KOMonthView::resizeEvent(QResizeEvent * e)
1270{ 1270{
1271 computeLayout(); 1271 computeLayout();
1272 clPending = true; 1272 clPending = true;
1273 if ( mShowWeekView ) 1273 if ( mShowWeekView )
1274 mCellsW[0]->setFocus(); 1274 mCellsW[0]->setFocus();
1275 else 1275 else
1276 mCells[0]->setFocus(); 1276 mCells[0]->setFocus();
1277} 1277}
1278void KOMonthView::computeLayoutWeek() 1278void KOMonthView::computeLayoutWeek()