summaryrefslogtreecommitdiffabout
path: root/korganizer
Unidiff
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagendaitem.cpp28
-rw-r--r--korganizer/komonthview.cpp21
2 files changed, 35 insertions, 14 deletions
diff --git a/korganizer/koagendaitem.cpp b/korganizer/koagendaitem.cpp
index 23afe7a..e545ca8 100644
--- a/korganizer/koagendaitem.cpp
+++ b/korganizer/koagendaitem.cpp
@@ -1,808 +1,816 @@
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 <qlabel.h> 20#include <qlabel.h>
21#include <qlayout.h> 21#include <qlayout.h>
22#include <qhbox.h> 22#include <qhbox.h>
23#include <qvbox.h> 23#include <qvbox.h>
24#include <qtooltip.h> 24#include <qtooltip.h>
25#include <qwhatsthis.h> 25#include <qwhatsthis.h>
26#include <qdragobject.h> 26#include <qdragobject.h>
27#include <qdrawutil.h> 27#include <qdrawutil.h>
28#include <qpainter.h> 28#include <qpainter.h>
29 29
30#include <kiconloader.h> 30#include <kiconloader.h>
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kglobal.h> 32#include <kglobal.h>
33#include <klocale.h> 33#include <klocale.h>
34#ifndef DESKTOP_VERSION 34#ifndef DESKTOP_VERSION
35#include <qpe/qpeapplication.h> 35#include <qpe/qpeapplication.h>
36#define AGENDA_ICON_SIZE 5 36#define AGENDA_ICON_SIZE 5
37#else 37#else
38#define AGENDA_ICON_SIZE 7 38#define AGENDA_ICON_SIZE 7
39#endif 39#endif
40#include <libkcal/icaldrag.h> 40#include <libkcal/icaldrag.h>
41#include <libkcal/vcaldrag.h> 41#include <libkcal/vcaldrag.h>
42#include <libkcal/kincidenceformatter.h> 42#include <libkcal/kincidenceformatter.h>
43extern int globalFlagBlockAgenda; 43extern int globalFlagBlockAgenda;
44extern int globalFlagBlockAgendaItemPaint; 44extern int globalFlagBlockAgendaItemPaint;
45extern int globalFlagBlockAgendaItemUpdate; 45extern int globalFlagBlockAgendaItemUpdate;
46 46
47#include "koprefs.h" 47#include "koprefs.h"
48 48
49#include "koagendaitem.h" 49#include "koagendaitem.h"
50//#include "koagendaitem.moc" 50//#include "koagendaitem.moc"
51 51
52 52
53//-------------------------------------------------------------------------- 53//--------------------------------------------------------------------------
54 54
55QToolTipGroup *KOAgendaItem::mToolTipGroup = 0; 55QToolTipGroup *KOAgendaItem::mToolTipGroup = 0;
56 56
57//-------------------------------------------------------------------------- 57//--------------------------------------------------------------------------
58 58
59class KOAgendaItemWhatsThis :public QWhatsThis 59class KOAgendaItemWhatsThis :public QWhatsThis
60{ 60{
61public: 61public:
62 KOAgendaItemWhatsThis( KOAgendaItem* view ) : QWhatsThis( view ),_view (view) { }; 62 KOAgendaItemWhatsThis( KOAgendaItem* view ) : QWhatsThis( view ),_view (view) { };
63 63
64protected: 64protected:
65 virtual QString text( const QPoint& ) 65 virtual QString text( const QPoint& )
66 { 66 {
67 return _view->getWhatsThisText() ; 67 return _view->getWhatsThisText() ;
68 } 68 }
69private: 69private:
70 KOAgendaItem * _view; 70 KOAgendaItem * _view;
71}; 71};
72 72
73KOAgendaItem::KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent,bool allday, 73KOAgendaItem::KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent,bool allday,
74 const char *name,WFlags) : 74 const char *name,WFlags) :
75 QWidget(parent, name), mIncidence(incidence), mDate(qd) 75 QWidget(parent, name), mIncidence(incidence), mDate(qd)
76{ 76{
77#ifndef DESKTOP_VERSION 77#ifndef DESKTOP_VERSION
78 //QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); 78 //QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
79#endif 79#endif
80 mKOAgendaItemWhatsThis = new KOAgendaItemWhatsThis(this); 80 mKOAgendaItemWhatsThis = new KOAgendaItemWhatsThis(this);
81 int wflags = getWFlags() |WRepaintNoErase;// WResizeNoErase 81 int wflags = getWFlags() |WRepaintNoErase;// WResizeNoErase
82 setWFlags ( wflags); 82 setWFlags ( wflags);
83 mAllDay = allday; 83 mAllDay = allday;
84 init ( incidence, qd ); 84 init ( incidence, qd );
85 //setMouseTracking(true); 85 //setMouseTracking(true);
86 //setAcceptDrops(true); 86 //setAcceptDrops(true);
87 xPaintCoord = -1; 87 xPaintCoord = -1;
88 yPaintCoord = -1; 88 yPaintCoord = -1;
89} 89}
90QString KOAgendaItem::getWhatsThisText() 90QString KOAgendaItem::getWhatsThisText()
91{ 91{
92 if ( mIncidence ) 92 if ( mIncidence )
93 return KIncidenceFormatter::instance()->getFormattedText( mIncidence, 93 return KIncidenceFormatter::instance()->getFormattedText( mIncidence,
94 KOPrefs::instance()->mWTshowDetails, 94 KOPrefs::instance()->mWTshowDetails,
95 KOPrefs::instance()->mWTshowCreated, 95 KOPrefs::instance()->mWTshowCreated,
96 KOPrefs::instance()->mWTshowChanged); 96 KOPrefs::instance()->mWTshowChanged);
97 return "KOAgendaItem::getWhatsThisText()::internal error"; 97 return "KOAgendaItem::getWhatsThisText()::internal error";
98} 98}
99void KOAgendaItem::init ( Incidence *incidence, QDate qd ) 99void KOAgendaItem::init ( Incidence *incidence, QDate qd )
100{ 100{
101 mIncidence = incidence; 101 mIncidence = incidence;
102 mDate = qd; 102 mDate = qd;
103 mFirstMultiItem = 0; 103 mFirstMultiItem = 0;
104 mNextMultiItem = 0; 104 mNextMultiItem = 0;
105 mLastMultiItem = 0; 105 mLastMultiItem = 0;
106 computeText(); 106 computeText();
107 107
108 if ( (incidence->type() == "Todo") && 108 if ( (incidence->type() == "Todo") &&
109 ( !((static_cast<Todo*>(incidence))->isCompleted()) && 109 ( !((static_cast<Todo*>(incidence))->isCompleted()) &&
110 ((static_cast<Todo*>(incidence))->dtDue().date() <= QDate::currentDate()) ) ) { 110 ((static_cast<Todo*>(incidence))->dtDue().date() <= QDate::currentDate()) ) ) {
111 if ( (static_cast<Todo*>(incidence))->dtDue() < QDateTime::currentDateTime().date()) 111 if ( (static_cast<Todo*>(incidence))->dtDue() < QDateTime::currentDateTime().date())
112 mBackgroundColor = KOPrefs::instance()->mTodoOverdueColor ; 112 mBackgroundColor = KOPrefs::instance()->mTodoOverdueColor ;
113 else 113 else
114 mBackgroundColor = KOPrefs::instance()->mTodoDueTodayColor; 114 mBackgroundColor = KOPrefs::instance()->mTodoDueTodayColor;
115 } 115 }
116 else { 116 else {
117 QStringList categories = mIncidence->categories(); 117 QStringList categories = mIncidence->categories();
118 QString cat = categories.first(); 118 QString cat = categories.first();
119 if (cat.isEmpty()) { 119 if (cat.isEmpty()) {
120 if ( (incidence->type() == "Todo") &&((static_cast<Todo*>(incidence))->isCompleted()) ) 120 if ( (incidence->type() == "Todo") &&((static_cast<Todo*>(incidence))->isCompleted()) )
121 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor; 121 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor;
122 else 122 else
123 mBackgroundColor =KOPrefs::instance()->mEventColor; 123 mBackgroundColor =KOPrefs::instance()->mEventColor;
124 } else { 124 } else {
125 mBackgroundColor = *KOPrefs::instance()->categoryColor(cat); 125 mBackgroundColor = *KOPrefs::instance()->categoryColor(cat);
126 if ( (incidence->type() == "Todo") &&((static_cast<Todo*>(incidence))->isCompleted()) ) { 126 if ( (incidence->type() == "Todo") &&((static_cast<Todo*>(incidence))->isCompleted()) ) {
127 if ( mBackgroundColor == KOPrefs::instance()->mEventColor ) 127 if ( mBackgroundColor == KOPrefs::instance()->mEventColor )
128 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor; 128 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor;
129 } 129 }
130 } 130 }
131 131
132 } 132 }
133 mColorGroup = QColorGroup( mBackgroundColor.light(), 133 mColorGroup = QColorGroup( mBackgroundColor.light(),
134 mBackgroundColor.dark(),mBackgroundColor.light(), 134 mBackgroundColor.dark(),mBackgroundColor.light(),
135 mBackgroundColor.dark(),mBackgroundColor, black, mBackgroundColor) ; 135 mBackgroundColor.dark(),mBackgroundColor, black, mBackgroundColor) ;
136 setBackgroundColor( mBackgroundColor ); 136 setBackgroundColor( mBackgroundColor );
137 137
138 mConflictItems.clear(); 138 mConflictItems.clear();
139 setCellXY(0,0,1); 139 setCellXY(0,0,1);
140 setCellXWidth(0); 140 setCellXWidth(0);
141 setSubCell(0); 141 setSubCell(0);
142 setSubCells(1); 142 setSubCells(1);
143 setMultiItem(0,0,0); 143 setMultiItem(0,0,0);
144 startMove(); 144 startMove();
145 mSelected = true; 145 mSelected = true;
146 select(false); 146 select(false);
147 QFontMetrics fontinf(KOPrefs::instance()->mAgendaViewFont); 147 QFontMetrics fontinf(KOPrefs::instance()->mAgendaViewFont);
148 mFontPixelSize = fontinf.height();; 148 mFontPixelSize = fontinf.height();;
149 hide(); 149 hide();
150 xPaintCoord = -1; 150 xPaintCoord = -1;
151 yPaintCoord = -1; 151 yPaintCoord = -1;
152} 152}
153 153
154 154
155KOAgendaItem::~KOAgendaItem() 155KOAgendaItem::~KOAgendaItem()
156{ 156{
157 // qDebug("deleteKOAgendaItem::~KOAgendaItem( "); 157 // qDebug("deleteKOAgendaItem::~KOAgendaItem( ");
158 // delete mKOAgendaItemWhatsThis; 158 // delete mKOAgendaItemWhatsThis;
159} 159}
160 160
161void KOAgendaItem::recreateIncidence() 161void KOAgendaItem::recreateIncidence()
162{ 162{
163#if 0 163#if 0
164 Incidence* newInc = mIncidence->clone(); 164 Incidence* newInc = mIncidence->clone();
165 newInc->recreate(); 165 newInc->recreate();
166 if ( mIncidence->doesRecur() ) { 166 if ( mIncidence->doesRecur() ) {
167 mIncidence->addExDate( mDate ); 167 mIncidence->addExDate( mDate );
168 newInc->recurrence()->unsetRecurs(); 168 newInc->recurrence()->unsetRecurs();
169 int len = mIncidence->dtStart().secsTo( ((Event*)mIncidence)->dtEnd()); 169 int len = mIncidence->dtStart().secsTo( ((Event*)mIncidence)->dtEnd());
170 QTime tim = mIncidence->dtStart().time(); 170 QTime tim = mIncidence->dtStart().time();
171 newInc->setDtStart( QDateTime(mDate, tim) ); 171 newInc->setDtStart( QDateTime(mDate, tim) );
172 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); 172 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) );
173 } 173 }
174#endif 174#endif
175 mIncidence = mIncidence->recreateCloneException( mDate ); 175 mIncidence = mIncidence->recreateCloneException( mDate );
176} 176}
177bool KOAgendaItem::updateIcons(QPainter * p, bool horLayout) 177bool KOAgendaItem::updateIcons(QPainter * p, bool horLayout)
178{ 178{
179 int size = AGENDA_ICON_SIZE; 179 int size = AGENDA_ICON_SIZE;
180 180
181 int yOff = 0; 181 int yOff = 0;
182 int xOff = 0; 182 int xOff = 0;
183 int x = pos().x() +3; 183 int x = pos().x() +3;
184 int y; 184 int y;
185 if ( mAllDay ) 185 if ( mAllDay )
186 y = pos().y()+3; 186 y = pos().y()+3;
187 else 187 else
188 y = mCellYTop * ( height() / cellHeight() ) +3; 188 y = mCellYTop * ( height() / cellHeight() ) +3;
189 if (mIncidence->cancelled()) { 189 if (mIncidence->cancelled()) {
190 int xpos = xOff*( 1 +AGENDA_ICON_SIZE )+x; 190 int xpos = xOff*( 1 +AGENDA_ICON_SIZE )+x;
191 int ypos = yOff*( 1 +AGENDA_ICON_SIZE)+y; 191 int ypos = yOff*( 1 +AGENDA_ICON_SIZE)+y;
192 p->drawLine( xpos, ypos, xpos+AGENDA_ICON_SIZE-1, ypos+AGENDA_ICON_SIZE-1 ); 192 p->drawLine( xpos, ypos, xpos+AGENDA_ICON_SIZE-1, ypos+AGENDA_ICON_SIZE-1 );
193 p->drawLine( xpos, ypos+AGENDA_ICON_SIZE-1, xpos+AGENDA_ICON_SIZE-1, ypos ); 193 p->drawLine( xpos, ypos+AGENDA_ICON_SIZE-1, xpos+AGENDA_ICON_SIZE-1, ypos );
194 if ( horLayout ) 194 if ( horLayout )
195 ++xOff; 195 ++xOff;
196 else 196 else
197 ++yOff; 197 ++yOff;
198 } 198 }
199 if (mIncidence->isAlarmEnabled()) { 199 if (mIncidence->isAlarmEnabled()) {
200 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, red ); 200 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, red );
201 if ( horLayout ) 201 if ( horLayout )
202 ++xOff; 202 ++xOff;
203 else 203 else
204 ++yOff; 204 ++yOff;
205 } 205 }
206 if (mIncidence->recurrence()->doesRecur()) { 206 if (mIncidence->recurrence()->doesRecur()) {
207 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, blue ); 207 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, blue );
208 if ( horLayout ) 208 if ( horLayout )
209 ++xOff; 209 ++xOff;
210 else 210 else
211 ++yOff; 211 ++yOff;
212 } 212 }
213 if (mIncidence->description().length() > 0) { 213 if (mIncidence->description().length() > 0) {
214 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkGreen ); 214 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkGreen );
215 if ( horLayout ) 215 if ( horLayout )
216 ++xOff; 216 ++xOff;
217 else 217 else
218 ++yOff; 218 ++yOff;
219 } 219 }
220 if (mIncidence->isReadOnly()) { 220 if (mIncidence->isReadOnly()) {
221 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, white ); 221 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, white );
222 if ( horLayout ) 222 if ( horLayout )
223 ++xOff; 223 ++xOff;
224 else 224 else
225 ++yOff; 225 ++yOff;
226 } 226 }
227 227
228 if (mIncidence->attendeeCount()>0) { 228 if (mIncidence->attendeeCount()>0) {
229 229
230 if (mIncidence->organizer() == KOPrefs::instance()->email()) { 230 if (mIncidence->organizer() == KOPrefs::instance()->email()) {
231 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, black ); 231 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, black );
232 if ( horLayout ) 232 if ( horLayout )
233 ++xOff; 233 ++xOff;
234 else 234 else
235 ++yOff; 235 ++yOff;
236 } else { 236 } else {
237 Attendee *me = mIncidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 237 Attendee *me = mIncidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
238 if (me!=0) { 238 if (me!=0) {
239 239
240 240
241 } else { 241 } else {
242 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, yellow ); 242 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, yellow );
243 if ( horLayout ) 243 if ( horLayout )
244 ++xOff; 244 ++xOff;
245 else 245 else
246 ++yOff; 246 ++yOff;
247 247
248 } 248 }
249 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkYellow ); 249 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkYellow );
250 if ( horLayout ) 250 if ( horLayout )
251 ++xOff; 251 ++xOff;
252 else 252 else
253 ++yOff; 253 ++yOff;
254 254
255 } 255 }
256 256
257 } 257 }
258 return ( yOff || xOff ); 258 return ( yOff || xOff );
259} 259}
260 260
261 261
262void KOAgendaItem::select(bool selected) 262void KOAgendaItem::select(bool selected)
263{ 263{
264 //qDebug("select %d %d",firstMultiItem(), nextMultiItem() ); 264 //qDebug("select %d %d",firstMultiItem(), nextMultiItem() );
265 if (mSelected == selected) return; 265 if (mSelected == selected) return;
266 mSelected = selected; 266 mSelected = selected;
267 if ( ! isVisible() ) 267 if ( ! isVisible() )
268 return; 268 return;
269 if ( firstMultiItem() ) 269 if ( firstMultiItem() )
270 firstMultiItem()->select( selected ); 270 firstMultiItem()->select( selected );
271 if ( !firstMultiItem() && nextMultiItem() ) { 271 if ( !firstMultiItem() && nextMultiItem() ) {
272 KOAgendaItem * placeItem = nextMultiItem(); 272 KOAgendaItem * placeItem = nextMultiItem();
273 while ( placeItem ) { 273 while ( placeItem ) {
274 placeItem->select( selected ); 274 placeItem->select( selected );
275 placeItem = placeItem->nextMultiItem(); 275 placeItem = placeItem->nextMultiItem();
276 } 276 }
277 } 277 }
278 globalFlagBlockAgendaItemUpdate = 0; 278 globalFlagBlockAgendaItemUpdate = 0;
279 paintMe( selected ); 279 paintMe( selected );
280 globalFlagBlockAgendaItemUpdate = 1; 280 globalFlagBlockAgendaItemUpdate = 1;
281 repaint( false ); 281 repaint( false );
282} 282}
283 283
284 284
285/* 285/*
286 The eventFilter has to filter the mouse events of the agenda item childs. The 286 The eventFilter has to filter the mouse events of the agenda item childs. The
287 events are fed into the event handling method of KOAgendaItem. This allows the 287 events are fed into the event handling method of KOAgendaItem. This allows the
288 KOAgenda to handle the KOAgendaItems by using an eventFilter. 288 KOAgenda to handle the KOAgendaItems by using an eventFilter.
289*/ 289*/
290bool KOAgendaItem::eventFilter ( QObject *object, QEvent *e ) 290bool KOAgendaItem::eventFilter ( QObject *object, QEvent *e )
291{ 291{
292 if (e->type() == QEvent::MouseButtonPress || 292 if (e->type() == QEvent::MouseButtonPress ||
293 e->type() == QEvent::MouseButtonDblClick || 293 e->type() == QEvent::MouseButtonDblClick ||
294 e->type() == QEvent::MouseButtonRelease || 294 e->type() == QEvent::MouseButtonRelease ||
295 e->type() == QEvent::MouseMove) { 295 e->type() == QEvent::MouseMove) {
296 QMouseEvent *me = (QMouseEvent *)e; 296 QMouseEvent *me = (QMouseEvent *)e;
297 QPoint itemPos = this->mapFromGlobal(((QWidget *)object)-> 297 QPoint itemPos = this->mapFromGlobal(((QWidget *)object)->
298 mapToGlobal(me->pos())); 298 mapToGlobal(me->pos()));
299 QMouseEvent returnEvent (e->type(),itemPos,me->button(),me->state()); 299 QMouseEvent returnEvent (e->type(),itemPos,me->button(),me->state());
300 return event(&returnEvent); 300 return event(&returnEvent);
301 } else { 301 } else {
302 return false; 302 return false;
303 } 303 }
304} 304}
305void KOAgendaItem::repaintMe( ) 305void KOAgendaItem::repaintMe( )
306{ 306{
307 paintMe ( mSelected ); 307 paintMe ( mSelected );
308} 308}
309void KOAgendaItem::paintMe( bool selected, QPainter* paint ) 309void KOAgendaItem::paintMe( bool selected, QPainter* paint )
310{ 310{
311 if ( globalFlagBlockAgendaItemUpdate && ! selected) 311 if ( globalFlagBlockAgendaItemUpdate && ! selected)
312 return; 312 return;
313 QPainter pa; 313 QPainter pa;
314 314
315 if ( mSelected ) { 315 if ( mSelected ) {
316 pa.begin( paintPixSel() ); 316 pa.begin( paintPixSel() );
317 } else { 317 } else {
318 if ( mAllDay ) 318 if ( mAllDay )
319 pa.begin( paintPixAllday() ); 319 pa.begin( paintPixAllday() );
320 else 320 else
321 pa.begin( paintPix() ); 321 pa.begin( paintPix() );
322 } 322 }
323 int x, yy, w, h; 323 int x, yy, w, h;
324 float nfh = 7.0; 324 float nfh = 7.0;
325 x = pos().x(); w = width(); h = height (); 325 x = pos().x(); w = width(); h = height ();
326 if ( mAllDay ) 326 if ( mAllDay )
327 yy = y(); 327 yy = y();
328 else 328 else
329 yy = mCellYTop * ( height() / cellHeight() ); 329 yy = mCellYTop * ( height() / cellHeight() );
330 xPaintCoord= x; 330 xPaintCoord= x;
331 yPaintCoord = yy; 331 yPaintCoord = yy;
332 wPaintCoord = width(); 332 wPaintCoord = width();
333 hPaintCoord = height(); 333 hPaintCoord = height();
334 //qDebug("paintMe %s %d %d %d %d",incidence()->summary().latin1(), x, yy, width(), height()); 334 //qDebug("paintMe %s %d %d %d %d",incidence()->summary().latin1(), x, yy, width(), height());
335 if ( paint == 0 ) 335 if ( paint == 0 )
336 paint = &pa; 336 paint = &pa;
337 bool horLayout = ( w < h ); 337 bool horLayout = ( w < h );
338 int maxhei = mFontPixelSize+4; 338 int maxhei = mFontPixelSize+4;
339 if ( horLayout ) 339 if ( horLayout )
340 maxhei += AGENDA_ICON_SIZE -4; 340 maxhei += AGENDA_ICON_SIZE -4;
341 bool small = ( h < maxhei ); 341 bool small = ( h < maxhei );
342 if ( ! small ) 342 if ( ! small )
343 paint->setFont(KOPrefs::instance()->mAgendaViewFont); 343 paint->setFont(KOPrefs::instance()->mAgendaViewFont);
344 else { 344 else {
345 QFont f = KOPrefs::instance()->mAgendaViewFont; 345 QFont f = KOPrefs::instance()->mAgendaViewFont;
346 f.setBold( false ); 346 f.setBold( false );
347 int fh = f.pointSize(); 347 int fh = f.pointSize();
348 nfh = (((float)height())/(float)(mFontPixelSize+4))*fh; 348 nfh = (((float)height())/(float)(mFontPixelSize+4))*fh;
349 if ( nfh < 6 ) 349 if ( nfh < 6 )
350 nfh = 6; 350 nfh = 6;
351 f.setPointSize( nfh ); 351 f.setPointSize( nfh );
352 paint->setFont(f); 352 paint->setFont(f);
353 } 353 }
354 paint->fillRect ( x, yy, w, h, mBackgroundColor ); 354 paint->fillRect ( x, yy, w, h, mBackgroundColor );
355 static const QPixmap completedPxmp = SmallIcon("greenhook16"); 355 static const QPixmap completedPxmp = SmallIcon("greenhook16");
356 static const QPixmap overduePxmp = SmallIcon("redcross16"); 356 static const QPixmap overduePxmp = SmallIcon("redcross16");
357 if ( mIncidence->type() == "Todo" ) { 357 if ( mIncidence->type() == "Todo" ) {
358 Todo* tempTodo = static_cast<Todo*>(mIncidence); 358 Todo* tempTodo = static_cast<Todo*>(mIncidence);
359 int xx = pos().x()+(width()-completedPxmp.width()-3 ); 359 int xx = pos().x()+(width()-completedPxmp.width()-3 );
360 int yyy = yy+3; 360 int yyy = yy+3;
361 if ( tempTodo->isCompleted() ) 361 if ( tempTodo->isCompleted() )
362 paint->drawPixmap ( xx, yyy, completedPxmp ); 362 paint->drawPixmap ( xx, yyy, completedPxmp );
363 else { 363 else {
364 paint->drawPixmap ( xx, yyy, overduePxmp ); 364 paint->drawPixmap ( xx, yyy, overduePxmp );
365 365
366 } 366 }
367 } 367 }
368 bool addIcon = false; 368 bool addIcon = false;
369 if ( ! small || w > 3 * h || h > 3* w ) 369 if ( ! small || w > 3 * h || h > 3* w )
370 addIcon = updateIcons( paint, horLayout ); 370 addIcon = updateIcons( paint, horLayout );
371 371
372 qDrawShadePanel (paint, x, yy, w, h, mColorGroup, selected , 2, 0); 372 qDrawShadePanel (paint, x, yy, w, h, mColorGroup, selected , 2, 0);
373 //qDebug("draw rect %d %d %d %d ",x, yy, w, h ); 373 //qDebug("draw rect %d %d %d %d ",x, yy, w, h );
374 if ( ! small ) { 374 if ( ! small ) {
375 x += 3; yy += 3;w -= 6; h-= 5; 375 x += 3; yy += 3;w -= 6; h-= 5;
376 } else { 376 } else {
377 x += 2; yy += 1;w -= 4; h-= 4; 377 x += 2; yy += 1;w -= 4; h-= 4;
378 if ( nfh < 6.01 ) { 378 if ( nfh < 6.01 ) {
379 yy -= 2; 379 yy -= 2;
380 h += 4; 380 h += 4;
381 } 381 }
382 else 382 else
383 if ( nfh < h -2 ) 383 if ( nfh < h -2 )
384 ++yy; 384 ++yy;
385 } 385 }
386 int align; 386 int align;
387#ifndef DESKTOP_VERSION 387#ifndef DESKTOP_VERSION
388 align = ( AlignLeft|WordBreak|AlignTop); 388 align = ( AlignLeft|WordBreak|AlignTop);
389#else 389#else
390 align = ( AlignLeft|BreakAnywhere|WordBreak|AlignTop); 390 align = ( AlignLeft|BreakAnywhere|WordBreak|AlignTop);
391#endif 391#endif
392 if ( addIcon ) { 392 if ( addIcon ) {
393 if ( ! horLayout ) { 393 if ( ! horLayout ) {
394 x += AGENDA_ICON_SIZE+3; 394 x += AGENDA_ICON_SIZE+3;
395 w -= (AGENDA_ICON_SIZE+3); 395 w -= (AGENDA_ICON_SIZE+3);
396 } 396 }
397 else { 397 else {
398 yy+= AGENDA_ICON_SIZE+2; 398 yy+= AGENDA_ICON_SIZE+2;
399 h -=(AGENDA_ICON_SIZE+3); 399 h -=(AGENDA_ICON_SIZE+3);
400 } 400 }
401 } 401 }
402 int colsum = mBackgroundColor.red() + mBackgroundColor.green() + mBackgroundColor.blue(); 402 int colsum = mBackgroundColor.red() + mBackgroundColor.green() + mBackgroundColor.blue();
403 if ( colsum < 250 ) 403 if ( colsum < 250 )
404 paint->setPen ( white); 404 paint->setPen ( white);
405 if ( x < 0 ) { 405 if ( x < 0 ) {
406 w = w+x-3; 406 w = w+x-3;
407 x = 3; 407 x = 3;
408 if ( w > parentWidget()->width() ){ 408 if ( w > parentWidget()->width() ){
409 w = parentWidget()->width() - 6; 409 w = parentWidget()->width() - 6;
410#ifndef DESKTOP_VERSION 410#ifndef DESKTOP_VERSION
411 align = ( AlignHCenter|WordBreak|AlignTop); 411 align = ( AlignHCenter|WordBreak|AlignTop);
412#else 412#else
413 align = ( AlignHCenter|BreakAnywhere|WordBreak|AlignTop); 413 align = ( AlignHCenter|BreakAnywhere|WordBreak|AlignTop);
414#endif 414#endif
415 415
416 } 416 }
417 } 417 }
418 QRect dr; 418 QRect dr;
419 if ( w + x > parentWidget()->width() ) 419 if ( w + x > parentWidget()->width() )
420 w = parentWidget()->width()-x; 420 w = parentWidget()->width()-x;
421 paint->drawText ( x, yy, w, h, align, mDisplayedText, -1, &dr ); 421 paint->drawText ( x, yy, w, h, align, mDisplayedText, -1, &dr );
422 //qDebug("%d %d %d %d ", x, yy, w, h ); 422 //qDebug("%d %d %d %d ", x, yy, w, h );
423 if ( mIncidence->cancelled() ){ 423 if ( mIncidence->cancelled() ){
424 424
425 425
426 small = ( height() < 20 ); 426 small = ( height() < 20 );
427 427
428 if ( ! small ) { 428 if ( ! small ) {
429 QFontMetrics fm ( paint->font() ); 429 QFontMetrics fm ( paint->font() );
430 paint->drawLine(dr.left(), yy+fm.height()/2, dr.right()-2, yy+fm.height()/2); 430 paint->drawLine(dr.left(), yy+fm.height()/2, dr.right()-2, yy+fm.height()/2);
431 } 431 }
432 432
433 } 433 }
434 pa.end(); 434 pa.end();
435 435
436} 436}
437void KOAgendaItem::resizePixmap( int w , int h ) 437void KOAgendaItem::resizePixmap( int w , int h )
438{ 438{
439 paintPix()->resize( w, h ); 439 paintPix()->resize( w, h );
440 paintPixSel()->resize( w, h ); 440 paintPixSel()->resize( w, h );
441 441
442} 442}
443QPixmap * KOAgendaItem::paintPix() 443QPixmap * KOAgendaItem::paintPix()
444{ 444{
445 static QPixmap* mPaintPix = 0; 445 static QPixmap* mPaintPix = 0;
446 if ( ! mPaintPix ) 446 if ( ! mPaintPix ) {
447 mPaintPix = new QPixmap(1,1); 447 int w = QApplication::desktop()->width();
448 int h = QApplication::desktop()->height();
449 mPaintPix = new QPixmap(w,h);
450 }
448 return mPaintPix ; 451 return mPaintPix ;
449} 452}
450QPixmap * KOAgendaItem::paintPixAllday() 453QPixmap * KOAgendaItem::paintPixAllday()
451{ 454{
452 static QPixmap* mPaintPixA = 0; 455 static QPixmap* mPaintPixA = 0;
453 if ( ! mPaintPixA ) 456 if ( ! mPaintPixA ) {
454 mPaintPixA = new QPixmap(1,1); 457 int w = QApplication::desktop()->width();
458 int h = QApplication::desktop()->height()/3;
459 mPaintPixA = new QPixmap(w,h);
460 }
455 return mPaintPixA ; 461 return mPaintPixA ;
456} 462}
457QPixmap * KOAgendaItem::paintPixSel() 463QPixmap * KOAgendaItem::paintPixSel()
458{ 464{
459 static QPixmap* mPaintPixSel = 0; 465 static QPixmap* mPaintPixSel = 0;
460 if ( ! mPaintPixSel ) 466 if ( ! mPaintPixSel ) {
461 mPaintPixSel = new QPixmap(1,1); 467 int w = QApplication::desktop()->width();
468 int h = QApplication::desktop()->height();
469 mPaintPixSel = new QPixmap(w,h);
470 }
462 return mPaintPixSel ; 471 return mPaintPixSel ;
463} 472}
464void KOAgendaItem::paintEvent ( QPaintEvent *e ) 473void KOAgendaItem::paintEvent ( QPaintEvent *e )
465{ 474{
466 475
467 if ( globalFlagBlockAgendaItemPaint ) 476 if ( globalFlagBlockAgendaItemPaint )
468 return; 477 return;
469 if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 ) 478 if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 )
470 return; 479 return;
471 int yy; 480 int yy;
472 if ( mAllDay ) 481 if ( mAllDay )
473 yy = y(); 482 yy = y();
474 else 483 else
475 yy = mCellYTop * ( height() / cellHeight() ); 484 yy = mCellYTop * ( height() / cellHeight() );
476 int xx = x(); 485 int xx = x();
477 486
478 if ( xPaintCoord != xx || yPaintCoord != yy || 487 if ( xPaintCoord != xx || yPaintCoord != yy ||
479 wPaintCoord != width() || hPaintCoord != height()) { 488 wPaintCoord != width() || hPaintCoord != height()) {
480 xPaintCoord= xx; 489 xPaintCoord= xx;
481 yPaintCoord = yy; 490 yPaintCoord = yy;
482 wPaintCoord = width(); 491 wPaintCoord = width();
483 hPaintCoord = height(); 492 hPaintCoord = height();
484 globalFlagBlockAgendaItemUpdate = 0; 493 globalFlagBlockAgendaItemUpdate = 0;
485 paintMe( mSelected ); 494 paintMe( mSelected );
486 //qDebug("calling paintMe "); 495 //qDebug("calling paintMe ");
487 globalFlagBlockAgendaItemUpdate = 1; 496 globalFlagBlockAgendaItemUpdate = 1;
488 } 497 }
489 int rx, ry, rw, rh; 498 int rx, ry, rw, rh;
490 rx = e->rect().x(); 499 rx = e->rect().x();
491 ry = e->rect().y(); 500 ry = e->rect().y();
492 rw = e->rect().width(); 501 rw = e->rect().width();
493 rh = e->rect().height(); 502 rh = e->rect().height();
494 //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height()); 503 //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height());
495 504
496 QPixmap* paintFrom ; 505 QPixmap* paintFrom ;
497 if ( mSelected ) { 506 if ( mSelected ) {
498 paintFrom = paintPixSel(); 507 paintFrom = paintPixSel();
499 } else { 508 } else {
500 if ( mAllDay ) 509 if ( mAllDay )
501 paintFrom = paintPixAllday(); 510 paintFrom = paintPixAllday();
502 else 511 else
503 paintFrom = paintPix(); 512 paintFrom = paintPix();
504 } 513 }
505 xx += rx; 514 xx += rx;
506 515
507 if ( xx < 0 ) { 516 if ( xx < 0 ) {
508 rw = rw + xx; 517 rw = rw + xx;
509 rx -= xx; 518 rx -= xx;
510 xx = 0; 519 xx = 0;
511 if ( rw <= 1 ) { 520 if ( rw <= 1 ) {
512 //qDebug("KOAgendaItem::Width1 <= 1 (%d). Returning. %s",rw,mDisplayedText.latin1()); 521 //qDebug("KOAgendaItem::Width1 <= 1 (%d). Returning. %s",rw,mDisplayedText.latin1());
513 return; 522 return;
514 } 523 }
515 } 524 }
516 if ( paintFrom->width() < xx+rw ) { 525 if ( paintFrom->width() < xx+rw ) {
517 rw = paintFrom->width() - xx; 526 rw = paintFrom->width() - xx;
518 if ( rw <= 1 ) { 527 if ( rw <= 1 ) {
519 //qDebug("KOAgendaItem::Width2 <= 1 (%d). Returning.%s ",rw,mDisplayedText.latin1() ); 528 //qDebug("KOAgendaItem::Width2 <= 1 (%d). Returning.%s ",rw,mDisplayedText.latin1() );
520 return; 529 return;
521 } 530 }
522 } 531 }
523 //qDebug("%d %d %d %d %d %d %d",rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh); 532 //qDebug("%d %d %d %d %d %d %d",rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh);
524 bitBlt (this, rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh ,CopyROP); 533 bitBlt (this, rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh ,CopyROP);
525} 534}
526void KOAgendaItem::computeText() 535void KOAgendaItem::computeText()
527{ 536{
528
529 mDisplayedText = mIncidence->summary(); 537 mDisplayedText = mIncidence->summary();
530 if ( (mIncidence->type() == "Todo") ) { 538 if ( (mIncidence->type() == "Todo") ) {
531 if ( static_cast<Todo*>(mIncidence)->hasDueDate() ) { 539 if ( static_cast<Todo*>(mIncidence)->hasDueDate() ) {
532 if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() ) 540 if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() )
533 mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")"; 541 mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")";
534 else if ( !(mIncidence->doesFloat())) 542 else if ( !(mIncidence->doesFloat()))
535 mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")"; 543 mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")";
536 } 544 }
537 } else { 545 } else {
538 if ( !(mIncidence->doesFloat()) && KOPrefs::instance()->mShowTimeInAgenda) 546 if ( !(mIncidence->doesFloat()) && KOPrefs::instance()->mShowTimeInAgenda)
539 mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + "-" + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ; 547 mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + " - " + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ;
540 548
541 if ( mAllDay ) { 549 if ( mAllDay ) {
542 if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) { 550 if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) {
543 mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true) ; 551 mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true) ;
544 } 552 }
545 } 553 }
546 554
547 } 555 }
548 556
549 if ( !mIncidence->location().isEmpty() ) { 557 if ( !mIncidence->location().isEmpty() ) {
550 if ( mAllDay ) 558 if ( mAllDay )
551 mDisplayedText += " ("; 559 mDisplayedText += " (";
552 else 560 else
553 mDisplayedText += "\n("; 561 mDisplayedText += "\n(";
554 mDisplayedText += mIncidence->location() +")"; 562 mDisplayedText += mIncidence->location() +")";
555 } 563 }
556 564#ifdef DESKTOP_VERSION
557 QString tipText = mIncidence->summary(); 565 QString tipText = mIncidence->summary();
558 if ( !mIncidence->doesFloat() ) { 566 if ( !mIncidence->doesFloat() ) {
559 if ( mIncidence->type() == "Event" ) { 567 if ( mIncidence->type() == "Event" ) {
560 if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) { 568 if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) {
561 tipText += "\n"+i18n("From: ")+mIncidence->dtStartStr(); 569 tipText += "\n"+i18n("From: ")+mIncidence->dtStartStr();
562 tipText += "\n"+i18n("To: ")+(static_cast<Event*>(mIncidence))->dtEndStr(); 570 tipText += "\n"+i18n("To: ")+(static_cast<Event*>(mIncidence))->dtEndStr();
563 } 571 }
564 else { 572 else {
565 tipText += "\n"+i18n("Time: ")+mIncidence->dtStartTimeStr(); 573 tipText += "\n"+i18n("Time: ")+mIncidence->dtStartTimeStr();
566 tipText += " - "+(static_cast<Event*>(mIncidence))->dtEndTimeStr(); 574 tipText += " - "+(static_cast<Event*>(mIncidence))->dtEndTimeStr();
567 } 575 }
568 } 576 }
569 else if ( mIncidence->type() == "Todo" ) { 577 else if ( mIncidence->type() == "Todo" ) {
570 if (mIncidence->hasStartDate()) 578 if (mIncidence->hasStartDate())
571 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartStr(); 579 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartStr();
572 if (((Todo*)mIncidence)->hasDueDate()) 580 if (((Todo*)mIncidence)->hasDueDate())
573 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueStr(); 581 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueStr();
574 } 582 }
575 } else if ( mIncidence->type() == "Todo" ) { 583 } else if ( mIncidence->type() == "Todo" ) {
576 if (mIncidence->hasStartDate()) 584 if (mIncidence->hasStartDate())
577 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartDateStr(); 585 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartDateStr();
578 if (((Todo*)mIncidence)->hasDueDate()) 586 if (((Todo*)mIncidence)->hasDueDate())
579 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueDateStr(); 587 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueDateStr();
580 } 588 }
581 589
582 if (!mIncidence->location().isEmpty()) { 590 if (!mIncidence->location().isEmpty()) {
583 tipText += "\n"+i18n("Location: ")+mIncidence->location(); 591 tipText += "\n"+i18n("Location: ")+mIncidence->location();
584 } 592 }
585 QToolTip::add(this,tipText,toolTipGroup(),""); 593 QToolTip::add(this,tipText,toolTipGroup(),"");
586 594#endif
587} 595}
588void KOAgendaItem::updateItem() 596void KOAgendaItem::updateItem()
589{ 597{
590 computeText(); 598 computeText();
591 599
592 //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y()); 600 //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y());
593 paintMe( mSelected ); 601 paintMe( mSelected );
594 repaint( false); 602 repaint( false);
595} 603}
596 604
597void KOAgendaItem::resizeEvent ( QResizeEvent *ev ) 605void KOAgendaItem::resizeEvent ( QResizeEvent *ev )
598{ 606{
599 //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1()); 607 //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1());
600 paintMe( mSelected ); 608 paintMe( mSelected );
601 repaint( false ); 609 repaint( false );
602} 610}
603 611
604/* 612/*
605 Return height of item in units of agenda cells 613 Return height of item in units of agenda cells
606*/ 614*/
607int KOAgendaItem::cellHeight() 615int KOAgendaItem::cellHeight()
608{ 616{
609 int ret = mCellYBottom - mCellYTop + 1; 617 int ret = mCellYBottom - mCellYTop + 1;
610 if ( ret <= 0 ) { 618 if ( ret <= 0 ) {
611 ret = 1; 619 ret = 1;
612 mCellYBottom = 0; 620 mCellYBottom = 0;
613 mCellYTop = 0; 621 mCellYTop = 0;
614 } 622 }
615 return ret; 623 return ret;
616} 624}
617 625
618/* 626/*
619 Return height of item in units of agenda cells 627 Return height of item in units of agenda cells
620*/ 628*/
621int KOAgendaItem::cellWidth() 629int KOAgendaItem::cellWidth()
622{ 630{
623 return mCellXWidth - mCellX + 1; 631 return mCellXWidth - mCellX + 1;
624} 632}
625 633
626void KOAgendaItem::setItemDate(QDate qd) 634void KOAgendaItem::setItemDate(QDate qd)
627{ 635{
628 mDate = qd; 636 mDate = qd;
629} 637}
630 638
631void KOAgendaItem::setCellXY(int X, int YTop, int YBottom) 639void KOAgendaItem::setCellXY(int X, int YTop, int YBottom)
632{ 640{
633 mCellX = X; 641 mCellX = X;
634 mCellYTop = YTop; 642 mCellYTop = YTop;
635 mCellYBottom = YBottom; 643 mCellYBottom = YBottom;
636} 644}
637 645
638void KOAgendaItem::setCellXWidth(int xwidth) 646void KOAgendaItem::setCellXWidth(int xwidth)
639{ 647{
640 mCellXWidth = xwidth; 648 mCellXWidth = xwidth;
641} 649}
642 650
643void KOAgendaItem::setCellX(int XLeft, int XRight) 651void KOAgendaItem::setCellX(int XLeft, int XRight)
644{ 652{
645 mCellX = XLeft; 653 mCellX = XLeft;
646 mCellXWidth = XRight; 654 mCellXWidth = XRight;
647} 655}
648 656
649void KOAgendaItem::setCellY(int YTop, int YBottom) 657void KOAgendaItem::setCellY(int YTop, int YBottom)
650{ 658{
651 mCellYTop = YTop; 659 mCellYTop = YTop;
652 mCellYBottom = YBottom; 660 mCellYBottom = YBottom;
653} 661}
654 662
655void KOAgendaItem::setSubCell(int subCell) 663void KOAgendaItem::setSubCell(int subCell)
656{ 664{
657 mSubCell = subCell; 665 mSubCell = subCell;
658} 666}
659 667
660void KOAgendaItem::setSubCells(int subCells) 668void KOAgendaItem::setSubCells(int subCells)
661{ 669{
662 mSubCells = subCells; 670 mSubCells = subCells;
663} 671}
664 672
665void KOAgendaItem::setMultiItem(KOAgendaItem *first,KOAgendaItem *next, 673void KOAgendaItem::setMultiItem(KOAgendaItem *first,KOAgendaItem *next,
666 KOAgendaItem *last) 674 KOAgendaItem *last)
667{ 675{
668 mFirstMultiItem = first; 676 mFirstMultiItem = first;
669 mNextMultiItem = next; 677 mNextMultiItem = next;
670 mLastMultiItem = last; 678 mLastMultiItem = last;
671} 679}
672 680
673void KOAgendaItem::startMove() 681void KOAgendaItem::startMove()
674{ 682{
675 mStartCellX = mCellX; 683 mStartCellX = mCellX;
676 mStartCellXWidth = mCellXWidth; 684 mStartCellXWidth = mCellXWidth;
677 mStartCellYTop = mCellYTop; 685 mStartCellYTop = mCellYTop;
678 mStartCellYBottom = mCellYBottom; 686 mStartCellYBottom = mCellYBottom;
679} 687}
680 688
681void KOAgendaItem::resetMove() 689void KOAgendaItem::resetMove()
682{ 690{
683 mCellX = mStartCellX; 691 mCellX = mStartCellX;
684 mCellXWidth = mStartCellXWidth; 692 mCellXWidth = mStartCellXWidth;
685 mCellYTop = mStartCellYTop; 693 mCellYTop = mStartCellYTop;
686 mCellYBottom = mStartCellYBottom; 694 mCellYBottom = mStartCellYBottom;
687} 695}
688 696
689void KOAgendaItem::moveRelative(int dx, int dy) 697void KOAgendaItem::moveRelative(int dx, int dy)
690{ 698{
691 int newX = cellX() + dx; 699 int newX = cellX() + dx;
692 int newXWidth = cellXWidth() + dx; 700 int newXWidth = cellXWidth() + dx;
693 int newYTop = cellYTop() + dy; 701 int newYTop = cellYTop() + dy;
694 int newYBottom = cellYBottom() + dy; 702 int newYBottom = cellYBottom() + dy;
695 setCellXY(newX,newYTop,newYBottom); 703 setCellXY(newX,newYTop,newYBottom);
696 setCellXWidth(newXWidth); 704 setCellXWidth(newXWidth);
697} 705}
698 706
699void KOAgendaItem::expandTop(int dy) 707void KOAgendaItem::expandTop(int dy)
700{ 708{
701 int newYTop = cellYTop() + dy; 709 int newYTop = cellYTop() + dy;
702 int newYBottom = cellYBottom(); 710 int newYBottom = cellYBottom();
703 if (newYTop > newYBottom) newYTop = newYBottom; 711 if (newYTop > newYBottom) newYTop = newYBottom;
704 setCellY(newYTop, newYBottom); 712 setCellY(newYTop, newYBottom);
705} 713}
706 714
707void KOAgendaItem::expandBottom(int dy) 715void KOAgendaItem::expandBottom(int dy)
708{ 716{
709 int newYTop = cellYTop(); 717 int newYTop = cellYTop();
710 int newYBottom = cellYBottom() + dy; 718 int newYBottom = cellYBottom() + dy;
711 if (newYBottom < newYTop) newYBottom = newYTop; 719 if (newYBottom < newYTop) newYBottom = newYTop;
712 setCellY(newYTop, newYBottom); 720 setCellY(newYTop, newYBottom);
713} 721}
714 722
715void KOAgendaItem::expandLeft(int dx) 723void KOAgendaItem::expandLeft(int dx)
716{ 724{
717 int newX = cellX() + dx; 725 int newX = cellX() + dx;
718 int newXWidth = cellXWidth(); 726 int newXWidth = cellXWidth();
719 if (newX > newXWidth) newX = newXWidth; 727 if (newX > newXWidth) newX = newXWidth;
720 setCellX(newX,newXWidth); 728 setCellX(newX,newXWidth);
721} 729}
722 730
723void KOAgendaItem::expandRight(int dx) 731void KOAgendaItem::expandRight(int dx)
724{ 732{
725 int newX = cellX(); 733 int newX = cellX();
726 int newXWidth = cellXWidth() + dx; 734 int newXWidth = cellXWidth() + dx;
727 if (newXWidth < newX) newXWidth = newX; 735 if (newXWidth < newX) newXWidth = newX;
728 setCellX(newX,newXWidth); 736 setCellX(newX,newXWidth);
729} 737}
730 738
731QToolTipGroup *KOAgendaItem::toolTipGroup() 739QToolTipGroup *KOAgendaItem::toolTipGroup()
732{ 740{
733 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); 741 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0);
734 return mToolTipGroup; 742 return mToolTipGroup;
735} 743}
736 744
737void KOAgendaItem::dragEnterEvent( QDragEnterEvent *e ) 745void KOAgendaItem::dragEnterEvent( QDragEnterEvent *e )
738{ 746{
739#ifndef KORG_NODND 747#ifndef KORG_NODND
740 if ( ICalDrag::canDecode( e ) || VCalDrag::canDecode( e ) || 748 if ( ICalDrag::canDecode( e ) || VCalDrag::canDecode( e ) ||
741 !QTextDrag::canDecode( e ) ) { 749 !QTextDrag::canDecode( e ) ) {
742 e->ignore(); 750 e->ignore();
743 return; 751 return;
744 } 752 }
745 e->accept(); 753 e->accept();
746#endif 754#endif
747} 755}
748 756
749void KOAgendaItem::dropEvent( QDropEvent *e ) 757void KOAgendaItem::dropEvent( QDropEvent *e )
750{ 758{
751#ifndef KORG_NODND 759#ifndef KORG_NODND
752 QString text; 760 QString text;
753 if(QTextDrag::decode(e,text)) 761 if(QTextDrag::decode(e,text))
754 { 762 {
755 kdDebug() << "Dropped : " << text << endl; 763 kdDebug() << "Dropped : " << text << endl;
756 QStringList emails = QStringList::split(",",text); 764 QStringList emails = QStringList::split(",",text);
757 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { 765 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
758 kdDebug() << " Email: " << (*it) << endl; 766 kdDebug() << " Email: " << (*it) << endl;
759 int pos = (*it).find("<"); 767 int pos = (*it).find("<");
760 QString name = (*it).left(pos); 768 QString name = (*it).left(pos);
761 QString email = (*it).mid(pos); 769 QString email = (*it).mid(pos);
762 if (!email.isEmpty()) { 770 if (!email.isEmpty()) {
763 mIncidence->addAttendee(new Attendee(name,email)); 771 mIncidence->addAttendee(new Attendee(name,email));
764 } 772 }
765 } 773 }
766 } 774 }
767#endif 775#endif
768} 776}
769 777
770 778
771QPtrList<KOAgendaItem> KOAgendaItem::conflictItems() 779QPtrList<KOAgendaItem> KOAgendaItem::conflictItems()
772{ 780{
773 return mConflictItems; 781 return mConflictItems;
774} 782}
775 783
776void KOAgendaItem::setConflictItems(QPtrList<KOAgendaItem> ci) 784void KOAgendaItem::setConflictItems(QPtrList<KOAgendaItem> ci)
777{ 785{
778 mConflictItems = ci; 786 mConflictItems = ci;
779 KOAgendaItem *item; 787 KOAgendaItem *item;
780 for ( item=mConflictItems.first(); item != 0; 788 for ( item=mConflictItems.first(); item != 0;
781 item=mConflictItems.next() ) { 789 item=mConflictItems.next() ) {
782 item->addConflictItem(this); 790 item->addConflictItem(this);
783 } 791 }
784} 792}
785 793
786void KOAgendaItem::addConflictItem(KOAgendaItem *ci) 794void KOAgendaItem::addConflictItem(KOAgendaItem *ci)
787{ 795{
788 if (mConflictItems.find(ci)<0) 796 if (mConflictItems.find(ci)<0)
789 mConflictItems.append(ci); 797 mConflictItems.append(ci);
790} 798}
791 799
792bool KOAgendaItem::checkLayout() 800bool KOAgendaItem::checkLayout()
793{ 801{
794 if ( !mConflictItems.count() ) 802 if ( !mConflictItems.count() )
795 return true; 803 return true;
796 int max = 0; 804 int max = 0;
797 KOAgendaItem *item; 805 KOAgendaItem *item;
798 for ( item=mConflictItems.first(); item != 0; 806 for ( item=mConflictItems.first(); item != 0;
799 item=mConflictItems.next() ) { 807 item=mConflictItems.next() ) {
800 if ( item->subCells() > max ) 808 if ( item->subCells() > max )
801 max = item->subCells(); 809 max = item->subCells();
802 } 810 }
803 if ( max > subCells() ) { 811 if ( max > subCells() ) {
804 setSubCells( max ); 812 setSubCells( max );
805 return false; 813 return false;
806 } 814 }
807 return true; 815 return true;
808} 816}
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp
index 4dfb9df..65d6acf 100644
--- a/korganizer/komonthview.cpp
+++ b/korganizer/komonthview.cpp
@@ -1,2002 +1,2015 @@
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 resetOnFocusIn = true; 86 resetOnFocusIn = true;
87 setVScrollBarMode(QScrollView::AlwaysOff); 87 setVScrollBarMode(QScrollView::AlwaysOff);
88 setHScrollBarMode(QScrollView::AlwaysOff); 88 setHScrollBarMode(QScrollView::AlwaysOff);
89} 89}
90KNoScrollListBox::~KNoScrollListBox() 90KNoScrollListBox::~KNoScrollListBox()
91{ 91{
92 92
93} 93}
94 94
95 95
96void KNoScrollListBox::focusInEvent ( QFocusEvent * e ) 96void KNoScrollListBox::focusInEvent ( QFocusEvent * e )
97{ 97{
98 QListBox::focusInEvent ( e ); 98 QListBox::focusInEvent ( e );
99 if ( count() ){ 99 if ( count() ){
100 int ci = currentItem(); 100 int ci = currentItem();
101 if ( ci < 0 ) ci = 0; 101 if ( ci < 0 ) ci = 0;
102 102
103 setCurrentItem( ci ); 103 setCurrentItem( ci );
104 setSelected ( ci, true ); 104 setSelected ( ci, true );
105 emit highlighted( item ( ci ) ); 105 emit highlighted( item ( ci ) );
106 106
107 resetOnFocusIn = true; 107 resetOnFocusIn = true;
108 108
109 if ( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) { 109 if ( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) {
110 QListBoxItem *fi = firstItem (); 110 QListBoxItem *fi = firstItem ();
111 if (fi ) { 111 if (fi ) {
112 int ihei = fi->height( this ); 112 int ihei = fi->height( this );
113 int hei = numRows () * ihei; 113 int hei = numRows () * ihei;
114 if ( hei < height() - horizontalScrollBar()->height () ) { 114 if ( hei < height() - horizontalScrollBar()->height () ) {
115 setVScrollBarMode(QScrollView::AlwaysOff); 115 setVScrollBarMode(QScrollView::AlwaysOff);
116 } 116 }
117 else 117 else
118 setVScrollBarMode(QScrollView::Auto); 118 setVScrollBarMode(QScrollView::Auto);
119 if ( ihei *3 > height() ) { 119 if ( ihei *3 > height() ) {
120 setHScrollBarMode(QScrollView::AlwaysOff); 120 setHScrollBarMode(QScrollView::AlwaysOff);
121 } 121 }
122 else { 122 else {
123 setHScrollBarMode(QScrollView::Auto); 123 setHScrollBarMode(QScrollView::Auto);
124 } 124 }
125 } else { 125 } else {
126 setVScrollBarMode(QScrollView::Auto); 126 setVScrollBarMode(QScrollView::Auto);
127 setHScrollBarMode(QScrollView::Auto); 127 setHScrollBarMode(QScrollView::Auto);
128 } 128 }
129 } 129 }
130 } 130 }
131} 131}
132void KNoScrollListBox::focusOutEvent ( QFocusEvent * e ) 132void KNoScrollListBox::focusOutEvent ( QFocusEvent * e )
133{ 133{
134 int i = currentItem (); 134 int i = currentItem ();
135 if ( i >= 0 ) { 135 if ( i >= 0 ) {
136 setSelected ( i, false ); 136 setSelected ( i, false );
137 } 137 }
138 QListBox::focusOutEvent ( e ); 138 QListBox::focusOutEvent ( e );
139 setVScrollBarMode(QScrollView::AlwaysOff); 139 setVScrollBarMode(QScrollView::AlwaysOff);
140 setHScrollBarMode(QScrollView::AlwaysOff); 140 setHScrollBarMode(QScrollView::AlwaysOff);
141} 141}
142 142
143QString KNoScrollListBox::getWhatsThisText(QPoint p) 143QString KNoScrollListBox::getWhatsThisText(QPoint p)
144{ 144{
145 QListBoxItem* item = itemAt ( p ); 145 QListBoxItem* item = itemAt ( p );
146 if ( ! item ) { 146 if ( ! item ) {
147 return i18n("Click in the cell\nto add an event!"); 147 return i18n("Click in the cell\nto add an event!");
148 } 148 }
149 return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence(), 149 return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence(),
150 KOPrefs::instance()->mWTshowDetails, 150 KOPrefs::instance()->mWTshowDetails,
151 KOPrefs::instance()->mWTshowCreated, 151 KOPrefs::instance()->mWTshowCreated,
152 KOPrefs::instance()->mWTshowChanged); 152 KOPrefs::instance()->mWTshowChanged);
153} 153}
154void KNoScrollListBox::keyPressEvent(QKeyEvent *e) 154void KNoScrollListBox::keyPressEvent(QKeyEvent *e)
155{ 155{
156 //qDebug("KNoScrollListBox::keyPressEvent "); 156 //qDebug("KNoScrollListBox::keyPressEvent ");
157 switch(e->key()) { 157 switch(e->key()) {
158 case Key_Right: 158 case Key_Right:
159 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 159 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
160 { 160 {
161 e->ignore(); 161 e->ignore();
162 return; 162 return;
163 } 163 }
164 scrollBy(10,0); 164 scrollBy(10,0);
165 break; 165 break;
166 case Key_Left: 166 case Key_Left:
167 if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 167 if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
168 { 168 {
169 e->ignore(); 169 e->ignore();
170 return; 170 return;
171 } 171 }
172 scrollBy(-10,0); 172 scrollBy(-10,0);
173 break; 173 break;
174 case Key_Up: 174 case Key_Up:
175 if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { 175 if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) {
176 e->ignore(); 176 e->ignore();
177 break; 177 break;
178 } 178 }
179 if ( count() ) { 179 if ( count() ) {
180 if ( currentItem() == 0 ) { 180 if ( currentItem() == 0 ) {
181 emit prevCell(); 181 emit prevCell();
182 } else { 182 } else {
183 setCurrentItem((currentItem()+count()-1)%count()); 183 setCurrentItem((currentItem()+count()-1)%count());
184 if(!itemVisible(currentItem())) { 184 if(!itemVisible(currentItem())) {
185 if((unsigned int) currentItem() == (count()-1)) { 185 if((unsigned int) currentItem() == (count()-1)) {
186 setTopItem(currentItem()-numItemsVisible()+1); 186 setTopItem(currentItem()-numItemsVisible()+1);
187 } else { 187 } else {
188 setTopItem(topItem()-1); 188 setTopItem(topItem()-1);
189 } 189 }
190 } 190 }
191 } 191 }
192 } 192 }
193 break; 193 break;
194 case Key_Down: 194 case Key_Down:
195 if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { 195 if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) {
196 e->ignore(); 196 e->ignore();
197 break; 197 break;
198 } 198 }
199 if ( count () ) { 199 if ( count () ) {
200 if ( currentItem()+1 == count () ) { 200 if ( currentItem()+1 == count () ) {
201 emit nextCell(); 201 emit nextCell();
202 } else { 202 } else {
203 setCurrentItem((currentItem()+1)%count()); 203 setCurrentItem((currentItem()+1)%count());
204 if(!itemVisible(currentItem())) { 204 if(!itemVisible(currentItem())) {
205 if(currentItem() == 0) { 205 if(currentItem() == 0) {
206 setTopItem(0); 206 setTopItem(0);
207 } else { 207 } else {
208 setTopItem(topItem()+1); 208 setTopItem(topItem()+1);
209 } 209 }
210 } 210 }
211 } 211 }
212 } 212 }
213 break; 213 break;
214 case Key_I: 214 case Key_I:
215 QTimer::singleShot( 1, this, SLOT ( oneDown() ) ); 215 QTimer::singleShot( 1, this, SLOT ( oneDown() ) );
216 e->ignore(); 216 e->ignore();
217 break; 217 break;
218 case Key_Return: 218 case Key_Return:
219 case Key_Enter: 219 case Key_Enter:
220 { 220 {
221 if ( currentItem() >= 0 ) { 221 if ( currentItem() >= 0 ) {
222 emit doubleClicked( item( currentItem() ) ); 222 emit doubleClicked( item( currentItem() ) );
223 e->accept(); 223 e->accept();
224 } else { 224 } else {
225 e->ignore(); 225 e->ignore();
226 } 226 }
227 } 227 }
228 break; 228 break;
229 case Key_Shift: 229 case Key_Shift:
230 emit shiftDown(); 230 emit shiftDown();
231 break; 231 break;
232 default: 232 default:
233 e->ignore(); 233 e->ignore();
234 break; 234 break;
235 } 235 }
236} 236}
237 237
238void KNoScrollListBox::oneDown() 238void KNoScrollListBox::oneDown()
239{ 239{
240 if ( count () ) { 240 if ( count () ) {
241 if ( currentItem()+1 == count () ) { 241 if ( currentItem()+1 == count () ) {
242 emit nextCell(); 242 emit nextCell();
243 } else { 243 } else {
244 resetOnFocusIn = false; 244 resetOnFocusIn = false;
245 setCurrentItem((currentItem()+1)%count()); 245 setCurrentItem((currentItem()+1)%count());
246 if(!itemVisible(currentItem())) { 246 if(!itemVisible(currentItem())) {
247 if(currentItem() == 0) { 247 if(currentItem() == 0) {
248 setTopItem(0); 248 setTopItem(0);
249 } else { 249 } else {
250 setTopItem(topItem()+1); 250 setTopItem(topItem()+1);
251 } 251 }
252 } 252 }
253 } 253 }
254 } 254 }
255} 255}
256void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) 256void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e)
257{ 257{
258 switch(e->key()) { 258 switch(e->key()) {
259 case Key_Shift: 259 case Key_Shift:
260 emit shiftUp(); 260 emit shiftUp();
261 break; 261 break;
262 default: 262 default:
263 break; 263 break;
264 } 264 }
265} 265}
266 266
267void KNoScrollListBox::mousePressEvent(QMouseEvent *e) 267void KNoScrollListBox::mousePressEvent(QMouseEvent *e)
268{ 268{
269 QListBox::mousePressEvent(e); 269 QListBox::mousePressEvent(e);
270 270
271 if(e->button() == RightButton) { 271 if(e->button() == RightButton) {
272 emit rightClick(); 272 emit rightClick();
273 } 273 }
274} 274}
275 275
276MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) 276MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s)
277 : QListBoxItem() 277 : QListBoxItem()
278{ 278{
279 mblockRepaint = true; 279 mblockRepaint = true;
280 setText( s ); 280 setText( s );
281 mMultiday = 0; 281 mMultiday = 0;
282 mIncidence = incidence; 282 mIncidence = incidence;
283 mDate = qd; 283 mDate = qd;
284 mRecur = false; 284 mRecur = false;
285 mAlarm = false; 285 mAlarm = false;
286 mReply = false; 286 mReply = false;
287 mInfo = false; 287 mInfo = false;
288 mdayPos = 0; 288 mdayPos = 0;
289 isWeekItem = KOPrefs::instance()->mMonthViewWeek; 289 isWeekItem = KOPrefs::instance()->mMonthViewWeek;
290 //qDebug("NEWWWWWWWWWWWWW "); 290 //qDebug("NEWWWWWWWWWWWWW ");
291} 291}
292void MonthViewItem::recycle( Incidence *incidence, QDate qd, const QString & s) 292void MonthViewItem::recycle( Incidence *incidence, QDate qd, const QString & s)
293{ 293{
294 setText( s ); 294 setText( s );
295 mMultiday = 0; 295 mMultiday = 0;
296 mIncidence = incidence; 296 mIncidence = incidence;
297 mDate = qd; 297 mDate = qd;
298 mRecur = false; 298 mRecur = false;
299 mAlarm = false; 299 mAlarm = false;
300 mReply = false; 300 mReply = false;
301 mInfo = false; 301 mInfo = false;
302 mdayPos = 0; 302 mdayPos = 0;
303 //qDebug("recucleeeeeeeeeeeeeeeee "); 303 //qDebug("recucleeeeeeeeeeeeeeeee ");
304} 304}
305 305
306void MonthViewItem::paint(QPainter *p) 306void MonthViewItem::paint(QPainter *p)
307{ 307{
308 if ( mblockRepaint ) { 308 if ( mblockRepaint ) {
309 //qDebug("block "); 309 //qDebug("block ");
310 return; 310 return;
311 } 311 }
312 //qDebug("NON block "); 312 //qDebug("NON block ");
313#if QT_VERSION >= 0x030000 313#if QT_VERSION >= 0x030000
314 bool sel = isSelected(); 314 bool sel = isSelected();
315#else 315#else
316 bool sel = selected(); 316 bool sel = selected();
317#endif 317#endif
318 318
319 319
320 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) 320 if (KOPrefs::instance()->mMonthViewUsesCategoryColor)
321 { 321 {
322 p->setBackgroundColor( palette().color( QPalette::Normal, \ 322 p->setBackgroundColor( palette().color( QPalette::Normal, \
323 sel ? QColorGroup::Highlight : QColorGroup::Background ) ); 323 sel ? QColorGroup::Highlight : QColorGroup::Background ) );
324 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); 324 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) );
325 } 325 }
326 int x = 1; 326 int x = 1;
327 //int y = 3;//(height() - mRecurPixmap.height()) /2; 327 //int y = 3;//(height() - mRecurPixmap.height()) /2;
328 int size = PIXMAP_SIZE; 328 int size = PIXMAP_SIZE;
329 if ( QApplication::desktop()->width() < 300 ) 329 if ( QApplication::desktop()->width() < 300 )
330 size = 3; 330 size = 3;
331 int heihei = height( listBox () ); 331 int heihei = height( listBox () );
332 int y = (heihei - size -1 ) /2; 332 int y = (heihei - size -1 ) /2;
333 333
334 if ( KOPrefs::instance()->mMonthShowIcons ) { 334 if ( KOPrefs::instance()->mMonthShowIcons ) {
335 if ( mInfo ) { 335 if ( mInfo ) {
336 p->fillRect ( x, y,size,size, Qt::darkGreen ); 336 p->fillRect ( x, y,size,size, Qt::darkGreen );
337 x += size + 1; 337 x += size + 1;
338 } 338 }
339 if ( mRecur ) { 339 if ( mRecur ) {
340 p->fillRect ( x, y,size,size, Qt::blue ); 340 p->fillRect ( x, y,size,size, Qt::blue );
341 x += size + 1; 341 x += size + 1;
342 } 342 }
343 if ( mAlarm ) { 343 if ( mAlarm ) {
344 p->fillRect ( x, y,size,size, Qt::red ); 344 p->fillRect ( x, y,size,size, Qt::red );
345 x += size + 1; 345 x += size + 1;
346 } 346 }
347 if ( mReply ) { 347 if ( mReply ) {
348 p->fillRect ( x, y,size,size, Qt::yellow ); 348 p->fillRect ( x, y,size,size, Qt::yellow );
349 x += size + 1; 349 x += size + 1;
350 } 350 }
351 } 351 }
352 if ( mMultiday ) { 352 if ( mMultiday ) {
353 int yyy = y+(size/2); 353 int yyy = y+(size/2);
354 int sizeM = size+2; 354 int sizeM = size+2;
355 p->setBrush( QBrush::SolidPattern ); 355 p->setBrush( QBrush::SolidPattern );
356 p->drawLine ( x+1, yyy, x +sizeM +sizeM/2-1, yyy ) ; 356 p->drawLine ( x+1, yyy, x +sizeM +sizeM/2-1, yyy ) ;
357 if ( mMultiday == 2 || mMultiday == 3 ) { 357 if ( mMultiday == 2 || mMultiday == 3 ) {
358 QPointArray pa ( 3 ); 358 QPointArray pa ( 3 );
359 pa.setPoint (0, x, yyy ); 359 pa.setPoint (0, x, yyy );
360 pa.setPoint (1, x+sizeM/2, yyy+sizeM/2 ); 360 pa.setPoint (1, x+sizeM/2, yyy+sizeM/2 );
361 pa.setPoint (2, x+sizeM/2, yyy-sizeM/2 ); 361 pa.setPoint (2, x+sizeM/2, yyy-sizeM/2 );
362 p->drawPolygon( pa ); 362 p->drawPolygon( pa );
363 } 363 }
364 if ( mMultiday == 2 || mMultiday == 1 ) { 364 if ( mMultiday == 2 || mMultiday == 1 ) {
365 QPointArray pa ( 3 ); 365 QPointArray pa ( 3 );
366 pa.setPoint (0, x+sizeM +sizeM/2, yyy ); 366 pa.setPoint (0, x+sizeM +sizeM/2, yyy );
367 pa.setPoint (1, x+sizeM, yyy+sizeM/2 ); 367 pa.setPoint (1, x+sizeM, yyy+sizeM/2 );
368 pa.setPoint (2, x+sizeM, yyy-sizeM/2 ); 368 pa.setPoint (2, x+sizeM, yyy-sizeM/2 );
369 p->drawPolygon( pa ); 369 p->drawPolygon( pa );
370 } 370 }
371 if ( mMultiday == 1 ) { 371 if ( mMultiday == 1 ) {
372 // p->fillRect ( x, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); 372 // p->fillRect ( x, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) );
373 373
374 p->drawLine ( x+1, yyy-sizeM/2, x+1, yyy+sizeM/2 ); 374 p->drawLine ( x+1, yyy-sizeM/2, x+1, yyy+sizeM/2 );
375 } 375 }
376 if ( mMultiday == 3 ) { 376 if ( mMultiday == 3 ) {
377 // p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); 377 // p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) );
378 p->drawLine ( x+sizeM +sizeM/2-1, yyy-sizeM/2, x+sizeM +sizeM/2-1, yyy+sizeM/2 ); 378 p->drawLine ( x+sizeM +sizeM/2-1, yyy-sizeM/2, x+sizeM +sizeM/2-1, yyy+sizeM/2 );
379 379
380 } 380 }
381 x += sizeM/2 + 1; 381 x += sizeM/2 + 1;
382 x += sizeM + 1; 382 x += sizeM + 1;
383 } 383 }
384 384
385 if ( mIncidence->type() == "Todo" ){ 385 if ( mIncidence->type() == "Todo" ){
386 Todo* td = ( Todo* ) mIncidence; 386 Todo* td = ( Todo* ) mIncidence;
387 if ( td->isCompleted() ) { 387 if ( td->isCompleted() ) {
388 int half = size/2; 388 int half = size/2;
389 p->drawLine ( x, heihei/2, x +half , heihei/2 +half ) ; 389 p->drawLine ( x, heihei/2, x +half , heihei/2 +half ) ;
390 p->drawLine ( x +half , heihei/2 +half , x +half+half +2 , heihei/2 -2 ) ; 390 p->drawLine ( x +half , heihei/2 +half , x +half+half +2 , heihei/2 -2 ) ;
391 x += half+half + 4; 391 x += half+half + 4;
392 392
393 } else { 393 } else {
394 int val = td->percentComplete()/20; 394 int val = td->percentComplete()/20;
395 p->fillRect ( x+1, y-2, val ,size+4,Qt::black ); 395 p->fillRect ( x+1, y-2, val ,size+4,Qt::black );
396 p->drawRect ( x, y-2,7,size+4); 396 p->drawRect ( x, y-2,7,size+4);
397 x += size + 3; 397 x += size + 3;
398 } 398 }
399 } 399 }
400 QFontMetrics fm = p->fontMetrics(); 400 QFontMetrics fm = p->fontMetrics();
401 int yPos; 401 int yPos;
402 int pmheight = size; 402 int pmheight = size;
403 if( pmheight < fm.height() ) 403 if( pmheight < fm.height() )
404 yPos = fm.ascent() + fm.leading()/2; 404 yPos = fm.ascent() + fm.leading()/2;
405 else 405 else
406 yPos = pmheight/2 - fm.height()/2 + fm.ascent(); 406 yPos = pmheight/2 - fm.height()/2 + fm.ascent();
407 p->setPen( palette().color( QPalette::Normal, sel ? \ 407 p->setPen( palette().color( QPalette::Normal, sel ? \
408 QColorGroup::HighlightedText : QColorGroup::Foreground ) ); 408 QColorGroup::HighlightedText : QColorGroup::Foreground ) );
409 p->drawText( x, yPos, text() ); 409 p->drawText( x, yPos, text() );
410 if ( mIncidence->cancelled() ) { 410 if ( mIncidence->cancelled() ) {
411 int wid = fm.width( text() ); 411 int wid = fm.width( text() );
412 p->drawLine( x, heihei/2 ,x+wid, heihei/2 ); 412 p->drawLine( x, heihei/2 ,x+wid, heihei/2 );
413 } 413 }
414 414
415} 415}
416 416
417int MonthViewItem::height(const QListBox *lb) const 417int MonthViewItem::height(const QListBox *lb) const
418{ 418{
419 int ret = 10; 419 int ret = 10;
420 if ( lb ) 420 if ( lb )
421 ret = lb->fontMetrics().lineSpacing()+1; 421 ret = lb->fontMetrics().lineSpacing()+1;
422 return ret; 422 return ret;
423} 423}
424 424
425int MonthViewItem::width(const QListBox *lb) const 425int MonthViewItem::width(const QListBox *lb) const
426{ 426{
427 if( KOPrefs::instance()->mEnableMonthScroll || isWeekItem ) { 427 if( KOPrefs::instance()->mEnableMonthScroll || isWeekItem ) {
428 int size = PIXMAP_SIZE; 428 int size = PIXMAP_SIZE;
429 if ( QApplication::desktop()->width() < 300 ) 429 if ( QApplication::desktop()->width() < 300 )
430 size = 3; 430 size = 3;
431 int x = 1; 431 int x = 1;
432 if ( KOPrefs::instance()->mMonthShowIcons ) { 432 if ( KOPrefs::instance()->mMonthShowIcons ) {
433 if ( mInfo ) { 433 if ( mInfo ) {
434 x += size + 1; 434 x += size + 1;
435 } 435 }
436 if( mRecur ) { 436 if( mRecur ) {
437 x += size+1; 437 x += size+1;
438 } 438 }
439 if( mAlarm ) { 439 if( mAlarm ) {
440 x += size+1; 440 x += size+1;
441 } 441 }
442 if( mReply ) { 442 if( mReply ) {
443 x += size+1; 443 x += size+1;
444 } 444 }
445 } 445 }
446 if( mMultiday ) { 446 if( mMultiday ) {
447 x += size+1+2+size/2; 447 x += size+1+2+size/2;
448 } 448 }
449 return( x + lb->fontMetrics().width( text() ) + 1 ); 449 return( x + lb->fontMetrics().width( text() ) + 1 );
450 } 450 }
451 if ( ! lb ) 451 if ( ! lb )
452 return 10; 452 return 10;
453 //qDebug("ret wid %d ", lb->width()); 453 //qDebug("ret wid %d ", lb->width());
454 return lb->width(); 454 return lb->width();
455} 455}
456 456
457 457
458MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) 458MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par )
459 : KNoScrollListBox( par ), 459 : KNoScrollListBox( par ),
460 mMonthView( parent ) 460 mMonthView( parent )
461{ 461{
462 //QVBoxLayout *topLayout = new QVBoxLayout( this ); 462 //QVBoxLayout *topLayout = new QVBoxLayout( this );
463 currentPalette = 0; 463 currentPalette = 0;
464 // mLabel = new QLabel( this );QPushButton 464 // mLabel = new QLabel( this );QPushButton
465 mLabel = new QPushButton( this ); 465 mLabel = new QPushButton( this );
466 //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); 466 //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain );
467 //mLabel->setLineWidth( 1 ); 467 //mLabel->setLineWidth( 1 );
468 //mLabel->setAlignment( AlignCenter ); 468 //mLabel->setAlignment( AlignCenter );
469 mLabel->setFlat( true ); 469 mLabel->setFlat( true );
470 mLabel->setFocusPolicy(NoFocus); 470 mLabel->setFocusPolicy(NoFocus);
471 //mItemList = new KNoScrollListBox( this ); 471 //mItemList = new KNoScrollListBox( this );
472 setMinimumSize( 10, 10 ); 472 setMinimumSize( 10, 10 );
473 setFrameStyle( QFrame::Panel | QFrame::Plain ); 473 setFrameStyle( QFrame::Panel | QFrame::Plain );
474 setLineWidth( 1 ); 474 setLineWidth( 1 );
475 //topLayout->addWidget( mItemList ); 475 //topLayout->addWidget( mItemList );
476 mLabel->raise(); 476 mLabel->raise();
477 // QColor( 0,0,255 ) QColor( 160,1600,255 ) 477 // QColor( 0,0,255 ) QColor( 160,1600,255 )
478 mStandardPalette = palette(); 478 mStandardPalette = palette();
479 mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); 479 mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) );
480 480
481 enableScrollBars( false ); 481 enableScrollBars( false );
482 updateConfig(); 482 updateConfig();
483 //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() )); 483 //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() ));
484 connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() )); 484 connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() ));
485 connect( this , SIGNAL( doubleClicked( QListBoxItem *) ), 485 connect( this , SIGNAL( doubleClicked( QListBoxItem *) ),
486 SLOT( defaultAction( QListBoxItem * ) ) ); 486 SLOT( defaultAction( QListBoxItem * ) ) );
487 connect( this, SIGNAL( rightButtonPressed( QListBoxItem *, 487 connect( this, SIGNAL( rightButtonPressed( QListBoxItem *,
488 const QPoint &) ), 488 const QPoint &) ),
489 SLOT( contextMenu( QListBoxItem * ) ) ); 489 SLOT( contextMenu( QListBoxItem * ) ) );
490 connect( this, SIGNAL( highlighted( QListBoxItem *) ), 490 connect( this, SIGNAL( highlighted( QListBoxItem *) ),
491 SLOT( selection( QListBoxItem * ) ) ); 491 SLOT( selection( QListBoxItem * ) ) );
492 492
493 /* 493 /*
494 connect( this, SIGNAL( clicked( QListBoxItem * ) ), 494 connect( this, SIGNAL( clicked( QListBoxItem * ) ),
495 SLOT( selection( QListBoxItem * ) ) ); 495 SLOT( selection( QListBoxItem * ) ) );
496 */ 496 */
497} 497}
498#ifdef DESKTOP_VERSION 498#ifdef DESKTOP_VERSION
499QToolTipGroup *MonthViewCell::toolTipGroup() 499QToolTipGroup *MonthViewCell::toolTipGroup()
500{ 500{
501 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); 501 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0);
502 return mToolTipGroup; 502 return mToolTipGroup;
503} 503}
504#endif 504#endif
505 505
506void MonthViewCell::setDate( const QDate &date ) 506void MonthViewCell::setDate( const QDate &date )
507{ 507{
508 // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl; 508 // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl;
509 mDate = date; 509 mDate = date;
510 510
511 511
512 512
513 //resizeEvent( 0 ); 513 //resizeEvent( 0 );
514} 514}
515 515
516QDate MonthViewCell::date() const 516QDate MonthViewCell::date() const
517{ 517{
518 return mDate; 518 return mDate;
519} 519}
520 520
521void MonthViewCell::setPrimary( bool primary ) 521void MonthViewCell::setPrimary( bool primary )
522{ 522{
523 mPrimary = primary; 523 mPrimary = primary;
524 //setMyPalette(); 524 //setMyPalette();
525} 525}
526void MonthViewCell::setMyPalette() 526void MonthViewCell::setMyPalette()
527{ 527{
528 528
529 if ( mHoliday) { 529 if ( mHoliday) {
530 if ( currentPalette == 1 ) return; 530 if ( currentPalette == 1 ) return;
531 mLabel->setPalette( QPalette ( mHolidayPalette.color( QPalette::Normal,QColorGroup::Base),mHolidayPalette.color(QPalette::Normal,QColorGroup::Base ) )); 531 mLabel->setPalette( QPalette ( mHolidayPalette.color( QPalette::Normal,QColorGroup::Base),mHolidayPalette.color(QPalette::Normal,QColorGroup::Base ) ));
532 setPalette( mHolidayPalette ); 532 setPalette( mHolidayPalette );
533 //mLabel->setPalette( mHolidayPalette ); 533 //mLabel->setPalette( mHolidayPalette );
534 currentPalette = 1; 534 currentPalette = 1;
535 535
536 } else { 536 } else {
537 if ( mPrimary ) { 537 if ( mPrimary ) {
538 if ( currentPalette == 2 ) return; 538 if ( currentPalette == 2 ) return;
539 mLabel->setPalette( QPalette ( mPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); 539 mLabel->setPalette( QPalette ( mPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) ));
540 //mLabel->setPalette( mPrimaryPalette ); 540 //mLabel->setPalette( mPrimaryPalette );
541 setPalette( mPrimaryPalette ); 541 setPalette( mPrimaryPalette );
542 currentPalette = 2; 542 currentPalette = 2;
543 543
544 } else { 544 } else {
545 if ( currentPalette == 3 ) return; 545 if ( currentPalette == 3 ) return;
546 setPalette( mNonPrimaryPalette ); 546 setPalette( mNonPrimaryPalette );
547 mLabel->setPalette( QPalette ( mNonPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mNonPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); 547 mLabel->setPalette( QPalette ( mNonPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mNonPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) ));
548 //mLabel->setPalette( mNonPrimaryPalette );; 548 //mLabel->setPalette( mNonPrimaryPalette );;
549 currentPalette = 3; 549 currentPalette = 3;
550 } 550 }
551 } 551 }
552 //QPalette pal = palette(); 552 //QPalette pal = palette();
553 553
554 //mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) )); 554 //mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) ));
555} 555}
556QPalette MonthViewCell::getPalette () 556QPalette MonthViewCell::getPalette ()
557{ 557{
558 if ( !KOPrefs::instance()->mMonthViewUsesDayColors ) 558 if ( !KOPrefs::instance()->mMonthViewUsesDayColors )
559 return mStandardPalette; 559 return mStandardPalette;
560 if ( mHoliday) { 560 if ( mHoliday) {
561 return mHolidayPalette ; 561 return mHolidayPalette ;
562 } else { 562 } else {
563 if ( mPrimary ) { 563 if ( mPrimary ) {
564 return mPrimaryPalette ; 564 return mPrimaryPalette ;
565 } 565 }
566 } 566 }
567 return mNonPrimaryPalette; 567 return mNonPrimaryPalette;
568} 568}
569bool MonthViewCell::isPrimary() const 569bool MonthViewCell::isPrimary() const
570{ 570{
571 return mPrimary; 571 return mPrimary;
572} 572}
573 573
574void MonthViewCell::setHoliday( bool holiday ) 574void MonthViewCell::setHoliday( bool holiday )
575{ 575{
576 mHoliday = holiday; 576 mHoliday = holiday;
577 //setMyPalette(); 577 //setMyPalette();
578} 578}
579 579
580void MonthViewCell::setHoliday( const QString &holiday ) 580void MonthViewCell::setHoliday( const QString &holiday )
581{ 581{
582 mHolidayString = holiday; 582 mHolidayString = holiday;
583 583
584 if ( !holiday.isEmpty() ) { 584 if ( !holiday.isEmpty() ) {
585 setHoliday( true ); 585 setHoliday( true );
586 } 586 }
587} 587}
588 588
589void MonthViewCell::startUpdateCell() 589void MonthViewCell::startUpdateCell()
590{ 590{
591 mdayCount = 0; 591 mdayCount = 0;
592 setFocusPolicy(NoFocus); 592 setFocusPolicy(NoFocus);
593 if ( !mMonthView->isUpdatePossible() ) 593 if ( !mMonthView->isUpdatePossible() )
594 return; 594 return;
595 MonthViewItem *mitem = (MonthViewItem*) firstItem (); 595 MonthViewItem *mitem = (MonthViewItem*) firstItem ();
596 while ( mitem ) { 596 while ( mitem ) {
597 mitem->setBlockRepaint( true ); 597 mitem->setBlockRepaint( true );
598 mitem = (MonthViewItem *)mitem->next(); 598 mitem = (MonthViewItem *)mitem->next();
599 } 599 }
600 if ( mAvailItemList.count() > 20 ) { 600 if ( mAvailItemList.count() > 20 ) {
601 mAvailItemList.setAutoDelete( true ); 601 mAvailItemList.setAutoDelete( true );
602 mAvailItemList.clear(); 602 mAvailItemList.clear();
603 mAvailItemList.setAutoDelete( false ); 603 mAvailItemList.setAutoDelete( false );
604 } 604 }
605 /* 605 /*
606 if ( !isVisible() ){ 606 if ( !isVisible() ){
607 return; 607 return;
608 } 608 }
609 */ 609 */
610 // qDebug("MonthViewCell::updateCell() "); 610 // qDebug("MonthViewCell::updateCell() ");
611 setPrimary( mDate.month()%2 ); 611 setPrimary( mDate.month()%2 );
612 setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays); 612 setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays);
613 if ( mDate == QDate::currentDate() ) { 613 if ( mDate == QDate::currentDate() ) {
614 setLineWidth( 3 ); 614 setLineWidth( 3 );
615 } else { 615 } else {
616 setLineWidth( 1 ); 616 setLineWidth( 1 );
617 } 617 }
618 MonthViewItem* CurrentAvailItem = (MonthViewItem*) firstItem (); 618 MonthViewItem* CurrentAvailItem = (MonthViewItem*) firstItem ();
619 //clear(); 619 //clear();
620 while ( CurrentAvailItem ) { 620 while ( CurrentAvailItem ) {
621 MonthViewItem *item = CurrentAvailItem; 621 MonthViewItem *item = CurrentAvailItem;
622 CurrentAvailItem = (MonthViewItem *)item->next(); 622 CurrentAvailItem = (MonthViewItem *)item->next();
623 mAvailItemList.append( item ); 623 mAvailItemList.append( item );
624 takeItem ( item ); 624 takeItem ( item );
625 } 625 }
626 626
627#ifdef DESKTOP_VERSION 627#ifdef DESKTOP_VERSION
628 QToolTip::remove(this); 628 QToolTip::remove(this);
629#endif 629#endif
630 mToolTip.clear(); 630 mToolTip.clear();
631 //qApp->processEvents(); 631 //qApp->processEvents();
632#if 0 632#if 0
633 if ( !mHolidayString.isEmpty() ) { 633 if ( !mHolidayString.isEmpty() ) {
634 MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); 634 MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString );
635 item->setPalette( mHolidayPalette ); 635 item->setPalette( mHolidayPalette );
636 insertItem( item ); 636 insertItem( item );
637 mToolTip.append ( mHolidayString ); 637 mToolTip.append ( mHolidayString );
638 } 638 }
639#endif 639#endif
640} 640}
641 641
642int MonthViewCell::insertEvent(Event *event) 642int MonthViewCell::insertEvent(Event *event)
643{ 643{
644 bool useToolTips = true;
645#ifndef DEKSTOP_VERSION
646 useToolTips = false;
647#endif
644 QString mToolTipText; 648 QString mToolTipText;
645 setFocusPolicy(WheelFocus); 649 setFocusPolicy(WheelFocus);
646 if ( !(event->doesRecur() == Recurrence::rNone) ) { 650 if ( !(event->doesRecur() == Recurrence::rNone) ) {
647 if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) 651 if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily )
648 return mdayCount; 652 return mdayCount;
649 else 653 else
650 if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) 654 if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly )
651 return mdayCount; 655 return mdayCount;
652 } 656 }
653 657
654 if ( event->isHoliday()) { 658 if ( event->isHoliday()) {
655 setHoliday( true ); 659 setHoliday( true );
656 if ( mDate.dayOfWeek() == 7 ) 660 if ( mDate.dayOfWeek() == 7 )
657 setLineWidth( 3 ); 661 setLineWidth( 3 );
658 } 662 }
659 QString text; 663 QString text;
660 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day 664 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
661 if (event->isMultiDay()) { 665 if (event->isMultiDay()) {
662 QString prefix = "<->";multiday = 2; 666 QString prefix = "<->";multiday = 2;
663 QString time; 667 QString time;
664 if ( event->doesRecur() ) { 668 if ( event->doesRecur() ) {
665 if ( event->recursOn( mDate) ) { 669 if ( event->recursOn( mDate) ) {
666 prefix ="->" ;multiday = 1; 670 prefix ="->" ;multiday = 1;
667 } 671 }
668 else { 672 else {
669 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 673 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
670 if ( event->recursOn( mDate.addDays( -days)) ) { 674 if ( event->recursOn( mDate.addDays( -days)) ) {
671 prefix ="<-" ;multiday = 3; 675 prefix ="<-" ;multiday = 3;
672 } 676 }
673 } 677 }
674 678
675 } else { 679 } else {
676 if (mDate == event->dtStart().date()) { 680 if (mDate == event->dtStart().date()) {
677 prefix ="->" ;multiday = 1; 681 prefix ="->" ;multiday = 1;
678 } else if (mDate == event->dtEnd().date()) { 682 } else if (mDate == event->dtEnd().date()) {
679 prefix ="<-" ;multiday = 3; 683 prefix ="<-" ;multiday = 3;
680 } 684 }
681 } 685 }
682 if ( !event->doesFloat() ) { 686 if ( !event->doesFloat() ) {
683 if ( mDate == event->dtStart().date () ) 687 if ( mDate == event->dtStart().date () )
684 time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; 688 time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
685 else if ( mDate == event->dtEnd().date () ) 689 else if ( mDate == event->dtEnd().date () )
686 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 690 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
687 691
688 } 692 }
689 text = time + event->summary(); 693 text = time + event->summary();
690 mToolTipText += prefix + text; 694 if ( useToolTips )
695 mToolTipText += prefix + text;
691 } else { 696 } else {
692 if (event->doesFloat()) { 697 if (event->doesFloat()) {
693 text = event->summary(); 698 text = event->summary();
694 mToolTipText += text; 699 if ( useToolTips )
700 mToolTipText += text;
695 } 701 }
696 else { 702 else {
697 text = KGlobal::locale()->formatTime(event->dtStart().time()); 703 text = KGlobal::locale()->formatTime(event->dtStart().time());
698 text += " " + event->summary(); 704 text += " " + event->summary();
699 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 705 if ( useToolTips )
706 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
700 } 707 }
701 } 708 }
709 if ( useToolTips && ! event->location().isEmpty() ) {
710 mToolTipText += " (" + event->location() +")";
711 }
702 MonthViewItem *item ; 712 MonthViewItem *item ;
703 713
704 if ( mAvailItemList.count() ) { 714 if ( mAvailItemList.count() ) {
705 item = mAvailItemList.first(); 715 item = mAvailItemList.first();
706 mAvailItemList.remove( item ); 716 mAvailItemList.remove( item );
707 item->recycle( event, mDate, text ); 717 item->recycle( event, mDate, text );
708 } else { 718 } else {
709 item = new MonthViewItem( event, mDate, text ); 719 item = new MonthViewItem( event, mDate, text );
710 } 720 }
711 721
712 QPalette pal; 722 QPalette pal;
713 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { 723 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
714 QStringList categories = event->categories(); 724 QStringList categories = event->categories();
715 QString cat = categories.first(); 725 QString cat = categories.first();
716 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { 726 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
717 pal = getPalette(); 727 pal = getPalette();
718 if (cat.isEmpty()) { 728 if (cat.isEmpty()) {
719 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); 729 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
720 } else { 730 } else {
721 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); 731 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
722 } 732 }
723 733
724 } else { 734 } else {
725 if (cat.isEmpty()) { 735 if (cat.isEmpty()) {
726 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); 736 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
727 } else { 737 } else {
728 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); 738 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
729 } 739 }
730 } 740 }
731 741
732 } else { 742 } else {
733 pal = mStandardPalette ; 743 pal = mStandardPalette ;
734 } 744 }
735 item->setPalette( pal ); 745 item->setPalette( pal );
736 item->setRecur( event->recurrence()->doesRecur() ); 746 item->setRecur( event->recurrence()->doesRecur() );
737 item->setAlarm( event->isAlarmEnabled() && multiday < 2 ); 747 item->setAlarm( event->isAlarmEnabled() && multiday < 2 );
738 item->setMoreInfo( event->description().length() > 0 ); 748 item->setMoreInfo( event->description().length() > 0 );
739#ifdef DESKTOP_VERSION 749#ifdef DESKTOP_VERSION
740 Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, 750 Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails,
741 KOPrefs::instance()->email()); 751 KOPrefs::instance()->email());
742 if ( me != 0 ) { 752 if ( me != 0 ) {
743 if ( me->status() == Attendee::NeedsAction && me->RSVP()) 753 if ( me->status() == Attendee::NeedsAction && me->RSVP())
744 item->setReply(true && multiday < 2); 754 item->setReply(true && multiday < 2);
745 else 755 else
746 item->setReply(false); 756 item->setReply(false);
747 } else 757 } else
748 item->setReply(false); 758 item->setReply(false);
749#endif 759#endif
750 item->setMultiDay( multiday ); 760 item->setMultiDay( multiday );
751 if ( multiday ) { 761 if ( multiday ) {
752 insertItem( item ,mdayCount); 762 insertItem( item ,mdayCount);
753 ++mdayCount; 763 ++mdayCount;
754 } else { 764 } else {
755 uint i; 765 uint i;
756 int pos = mdayCount; 766 int pos = mdayCount;
757 for ( i = mdayCount; i < count();++i ) { 767 for ( i = mdayCount; i < count();++i ) {
758 QListBoxItem* it = this->item ( i ); 768 QListBoxItem* it = this->item ( i );
759 if ( text < it->text() ) { 769 if ( text < it->text() ) {
760 pos = i; 770 pos = i;
761 break; 771 break;
762 } 772 }
763 ++pos; 773 ++pos;
764 } 774 }
765 insertItem( item ,pos); 775 insertItem( item ,pos);
766 } 776 }
767 mToolTip.append( mToolTipText ); 777 if ( useToolTips )
778 mToolTip.append( mToolTipText );
768 return mdayCount; 779 return mdayCount;
769} 780}
770void MonthViewCell::insertTodo(Todo *todo) 781void MonthViewCell::insertTodo(Todo *todo)
771{ 782{
772 setFocusPolicy(WheelFocus); 783 setFocusPolicy(WheelFocus);
773 QString text; 784 QString text;
774 if (todo->hasDueDate()) { 785 if (todo->hasDueDate()) {
775 if (!todo->doesFloat()) { 786 if (!todo->doesFloat()) {
776 text += KGlobal::locale()->formatTime(todo->dtDue().time()); 787 text += KGlobal::locale()->formatTime(todo->dtDue().time());
777 text += " "; 788 text += " ";
778 } 789 }
779 } 790 }
780 text += todo->summary(); 791 text += todo->summary();
781 MonthViewItem *item ; 792 MonthViewItem *item ;
782 if ( mAvailItemList.count() ) { 793 if ( mAvailItemList.count() ) {
783 item = mAvailItemList.first(); 794 item = mAvailItemList.first();
784 mAvailItemList.remove( item ); 795 mAvailItemList.remove( item );
785 item->recycle( todo, mDate, text ); 796 item->recycle( todo, mDate, text );
786 } else { 797 } else {
787 item = new MonthViewItem( todo, mDate, text ); 798 item = new MonthViewItem( todo, mDate, text );
788 } 799 }
789 //MonthViewItem *item = new MonthViewItem( todo, mDate, text ); 800 //MonthViewItem *item = new MonthViewItem( todo, mDate, text );
790 //item->setPalette( mStandardPalette ); 801 //item->setPalette( mStandardPalette );
791 QPalette pal; 802 QPalette pal;
792 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { 803 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
793 QStringList categories = todo->categories(); 804 QStringList categories = todo->categories();
794 QString cat = categories.first(); 805 QString cat = categories.first();
795 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { 806 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
796 pal = getPalette(); 807 pal = getPalette();
797 if (cat.isEmpty()) { 808 if (cat.isEmpty()) {
798 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); 809 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
799 } else { 810 } else {
800 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); 811 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
801 } 812 }
802 813
803 } else { 814 } else {
804 if (cat.isEmpty()) { 815 if (cat.isEmpty()) {
805 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); 816 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
806 } else { 817 } else {
807 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); 818 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
808 } 819 }
809 } 820 }
810 821
811 } else { 822 } else {
812 pal = mStandardPalette ; 823 pal = mStandardPalette ;
813 } 824 }
814 item->setPalette( pal ); 825 item->setPalette( pal );
815 item->setRecur( todo->recurrence()->doesRecur() ); 826 item->setRecur( todo->recurrence()->doesRecur() );
816 item->setAlarm( todo->isAlarmEnabled() ); 827 item->setAlarm( todo->isAlarmEnabled() );
817 item->setMoreInfo( todo->description().length() > 0 ); 828 item->setMoreInfo( todo->description().length() > 0 );
818 insertItem( item , count()); 829 insertItem( item , count());
830#ifdef DESKTOP_VERSION
819 mToolTip.append( text ); 831 mToolTip.append( text );
832#endif
820} 833}
821void MonthViewCell::repaintfinishUpdateCell() 834void MonthViewCell::repaintfinishUpdateCell()
822{ 835{
823 MonthViewItem *mitem = (MonthViewItem*) firstItem (); 836 MonthViewItem *mitem = (MonthViewItem*) firstItem ();
824 while ( mitem ) { 837 while ( mitem ) {
825 mitem->setBlockRepaint( false ); 838 mitem->setBlockRepaint( false );
826 updateItem ( mitem ); 839 updateItem ( mitem );
827 mitem = (MonthViewItem *)mitem->next(); 840 mitem = (MonthViewItem *)mitem->next();
828 } 841 }
829} 842}
830void MonthViewCell::finishUpdateCell() 843void MonthViewCell::finishUpdateCell()
831{ 844{
832 845
833 846
834 847
835#ifdef DESKTOP_VERSION 848#ifdef DESKTOP_VERSION
836 if (mToolTip.count() > 0 ) { 849 if (mToolTip.count() > 0 ) {
837 mToolTip.sort(); 850 mToolTip.sort();
838 QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),""); 851 QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),"");
839 } 852 }
840#endif 853#endif
841 //sort(); 854 //sort();
842 //setMyPalette(); 855 //setMyPalette();
843 setMyPalette(); 856 setMyPalette();
844 857
845 resizeEvent( 0 ); 858 resizeEvent( 0 );
846 859
847} 860}
848void MonthViewCell::updateCell() 861void MonthViewCell::updateCell()
849{ 862{
850 //qDebug("MonthViewCell::updateCell() "); 863 //qDebug("MonthViewCell::updateCell() ");
851 if ( !mMonthView->isUpdatePossible() ) 864 if ( !mMonthView->isUpdatePossible() )
852 return; 865 return;
853 startUpdateCell(); 866 startUpdateCell();
854 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 867 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
855 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); 868 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true );
856 Event *event; 869 Event *event;
857 for( event = events.first(); event; event = events.next() ) { // for event 870 for( event = events.first(); event; event = events.next() ) { // for event
858 insertEvent(event); 871 insertEvent(event);
859 } 872 }
860 // insert due todos 873 // insert due todos
861 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); 874 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate );
862 Todo *todo; 875 Todo *todo;
863 for(todo = todos.first(); todo; todo = todos.next()) { 876 for(todo = todos.first(); todo; todo = todos.next()) {
864 insertTodo( todo ); 877 insertTodo( todo );
865 } 878 }
866 finishUpdateCell(); 879 finishUpdateCell();
867 // if ( isVisible()) 880 // if ( isVisible())
868 //qApp->processEvents(); 881 //qApp->processEvents();
869} 882}
870 883
871void MonthViewCell::updateConfig( bool bigFont ) // = false 884void MonthViewCell::updateConfig( bool bigFont ) // = false
872{ 885{
873 886
874 if ( bigFont ) { 887 if ( bigFont ) {
875 QFont fo = KOPrefs::instance()->mMonthViewFont; 888 QFont fo = KOPrefs::instance()->mMonthViewFont;
876 int ps = fo.pointSize() + 2; 889 int ps = fo.pointSize() + 2;
877 if ( ps < 18 ) 890 if ( ps < 18 )
878 ps += 2; 891 ps += 2;
879 fo.setPointSize( ps ); 892 fo.setPointSize( ps );
880 setFont( fo ); 893 setFont( fo );
881 } else 894 } else
882 setFont( KOPrefs::instance()->mMonthViewFont ); 895 setFont( KOPrefs::instance()->mMonthViewFont );
883 896
884 QFontMetrics fm( font() ); 897 QFontMetrics fm( font() );
885 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); 898 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 );
886 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); 899 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 );
887 mHolidayPalette = mStandardPalette; 900 mHolidayPalette = mStandardPalette;
888 mPrimaryPalette = mStandardPalette; 901 mPrimaryPalette = mStandardPalette;
889 mNonPrimaryPalette = mStandardPalette; 902 mNonPrimaryPalette = mStandardPalette;
890 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { 903 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) {
891 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); 904 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor );
892 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); 905 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor );
893 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); 906 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark());
894 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); 907 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark());
895 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); 908 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor);
896 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); 909 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor);
897 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); 910 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark());
898 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); 911 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor);
899 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); 912 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor);
900 } 913 }
901 //updateCell(); 914 //updateCell();
902} 915}
903 916
904void MonthViewCell::enableScrollBars( bool enabled ) 917void MonthViewCell::enableScrollBars( bool enabled )
905{ 918{
906 919
907 return; 920 return;
908 if ( enabled ) { 921 if ( enabled ) {
909 QListBoxItem *fi = firstItem (); 922 QListBoxItem *fi = firstItem ();
910 if (fi ) { 923 if (fi ) {
911 int ihei = fi->height( this ); 924 int ihei = fi->height( this );
912 int hei = numRows () * ihei; 925 int hei = numRows () * ihei;
913 if ( hei < height() - horizontalScrollBar()->height () ) { 926 if ( hei < height() - horizontalScrollBar()->height () ) {
914 setVScrollBarMode(QScrollView::AlwaysOff); 927 setVScrollBarMode(QScrollView::AlwaysOff);
915 } 928 }
916 else 929 else
917 setVScrollBarMode(QScrollView::Auto); 930 setVScrollBarMode(QScrollView::Auto);
918 if ( ihei *3 > height() ) { 931 if ( ihei *3 > height() ) {
919 setHScrollBarMode(QScrollView::AlwaysOff); 932 setHScrollBarMode(QScrollView::AlwaysOff);
920 } 933 }
921 else { 934 else {
922 setHScrollBarMode(QScrollView::Auto); 935 setHScrollBarMode(QScrollView::Auto);
923 } 936 }
924 } else { 937 } else {
925 setVScrollBarMode(QScrollView::Auto); 938 setVScrollBarMode(QScrollView::Auto);
926 setHScrollBarMode(QScrollView::Auto); 939 setHScrollBarMode(QScrollView::Auto);
927 } 940 }
928 } else { 941 } else {
929 setVScrollBarMode(QScrollView::AlwaysOff); 942 setVScrollBarMode(QScrollView::AlwaysOff);
930 setHScrollBarMode(QScrollView::AlwaysOff); 943 setHScrollBarMode(QScrollView::AlwaysOff);
931 } 944 }
932} 945}
933 946
934Incidence *MonthViewCell::selectedIncidence() 947Incidence *MonthViewCell::selectedIncidence()
935{ 948{
936 int index = currentItem(); 949 int index = currentItem();
937 if ( index < 0 ) return 0; 950 if ( index < 0 ) return 0;
938 951
939 MonthViewItem *mitem = 952 MonthViewItem *mitem =
940 static_cast<MonthViewItem *>( item( index ) ); 953 static_cast<MonthViewItem *>( item( index ) );
941 954
942 if ( !mitem ) return 0; 955 if ( !mitem ) return 0;
943 956
944 return mitem->incidence(); 957 return mitem->incidence();
945} 958}
946 959
947QDate MonthViewCell::selectedIncidenceDate() 960QDate MonthViewCell::selectedIncidenceDate()
948{ 961{
949 QDate qd; 962 QDate qd;
950 int index = currentItem(); 963 int index = currentItem();
951 if ( index < 0 ) return qd; 964 if ( index < 0 ) return qd;
952 965
953 MonthViewItem *mitem = 966 MonthViewItem *mitem =
954 static_cast<MonthViewItem *>( item( index ) ); 967 static_cast<MonthViewItem *>( item( index ) );
955 968
956 if ( !mitem ) return qd; 969 if ( !mitem ) return qd;
957 970
958 return mitem->incidenceDate(); 971 return mitem->incidenceDate();
959} 972}
960 973
961void MonthViewCell::deselect() 974void MonthViewCell::deselect()
962{ 975{
963 clearSelection(); 976 clearSelection();
964 enableScrollBars( false ); 977 enableScrollBars( false );
965 // updateCell(); 978 // updateCell();
966} 979}
967void MonthViewCell::select() 980void MonthViewCell::select()
968{ 981{
969 ;// updateCell(); 982 ;// updateCell();
970} 983}
971 984
972void MonthViewCell::resizeEvent ( QResizeEvent * e ) 985void MonthViewCell::resizeEvent ( QResizeEvent * e )
973{ 986{
974 if ( !mMonthView->isUpdatePossible() ) 987 if ( !mMonthView->isUpdatePossible() )
975 return; 988 return;
976 //qDebug("++++++++++++++MonthViewCell::resizeEvent %d %d ", width(), height()); 989 //qDebug("++++++++++++++MonthViewCell::resizeEvent %d %d ", width(), height());
977 deselect(); 990 deselect();
978 mLabel->setMaximumHeight( height() - lineWidth()*2 ); 991 mLabel->setMaximumHeight( height() - lineWidth()*2 );
979 992
980 QString text; 993 QString text;
981 mLabel->setText( text ); 994 mLabel->setText( text );
982 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; 995 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog;
983 if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { 996 if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) {
984 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " "; 997 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " ";
985 mLabel->resize( mLabelBigSize ); 998 mLabel->resize( mLabelBigSize );
986 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 999 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
987 } else { 1000 } else {
988 mLabel->resize( mLabelSize ); 1001 mLabel->resize( mLabelSize );
989 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 1002 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
990 } 1003 }
991 mLabel->setText( text ); 1004 mLabel->setText( text );
992 1005
993 int size = height() - mLabel->height() - lineWidth()-1; 1006 int size = height() - mLabel->height() - lineWidth()-1;
994 //qDebug("LW %d ", lineWidth()); 1007 //qDebug("LW %d ", lineWidth());
995 if ( size > 0 ) 1008 if ( size > 0 )
996 verticalScrollBar()->setMaximumHeight( size ); 1009 verticalScrollBar()->setMaximumHeight( size );
997 size = width() - mLabel->width() -lineWidth()-1; 1010 size = width() - mLabel->width() -lineWidth()-1;
998 if ( size > 0 ) 1011 if ( size > 0 )
999 horizontalScrollBar()->setMaximumWidth( size ); 1012 horizontalScrollBar()->setMaximumWidth( size );
1000 mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() ); 1013 mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() );
1001 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 1014 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
1002 // mItemList->resize ( width(), height () ); 1015 // mItemList->resize ( width(), height () );
1003 if ( e ) 1016 if ( e )
1004 KNoScrollListBox::resizeEvent ( e ); 1017 KNoScrollListBox::resizeEvent ( e );
1005} 1018}
1006 1019
1007void MonthViewCell::defaultAction( QListBoxItem *item ) 1020void MonthViewCell::defaultAction( QListBoxItem *item )
1008{ 1021{
1009 1022
1010 if ( !item ) { 1023 if ( !item ) {
1011 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 1024 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
1012 emit newEventSignal( dt ); 1025 emit newEventSignal( dt );
1013 return; 1026 return;
1014 } 1027 }
1015 1028
1016 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 1029 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
1017 Incidence *incidence = eventItem->incidence(); 1030 Incidence *incidence = eventItem->incidence();
1018 if ( incidence ) mMonthView->defaultAction( incidence ); 1031 if ( incidence ) mMonthView->defaultAction( incidence );
1019} 1032}
1020void MonthViewCell::showDay() 1033void MonthViewCell::showDay()
1021{ 1034{
1022 emit showDaySignal( date() ); 1035 emit showDaySignal( date() );
1023} 1036}
1024void MonthViewCell::newEvent() 1037void MonthViewCell::newEvent()
1025{ 1038{
1026 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 1039 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
1027 emit newEventSignal( dt ); 1040 emit newEventSignal( dt );
1028} 1041}
1029void MonthViewCell::cellClicked( QListBoxItem *item ) 1042void MonthViewCell::cellClicked( QListBoxItem *item )
1030{ 1043{
1031 qDebug("CELL "); 1044 qDebug("CELL ");
1032 if ( item == 0 ) { 1045 if ( item == 0 ) {
1033 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 1046 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
1034 emit newEventSignal( dt ); 1047 emit newEventSignal( dt );
1035 return; 1048 return;
1036 } 1049 }
1037 1050
1038} 1051}
1039 1052
1040void MonthViewCell::contextMenu( QListBoxItem *item ) 1053void MonthViewCell::contextMenu( QListBoxItem *item )
1041{ 1054{
1042 if ( !item ) return; 1055 if ( !item ) return;
1043 1056
1044 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 1057 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
1045 Incidence *incidence = eventItem->incidence(); 1058 Incidence *incidence = eventItem->incidence();
1046 if ( incidence ) mMonthView->showContextMenu( incidence ); 1059 if ( incidence ) mMonthView->showContextMenu( incidence );
1047} 1060}
1048 1061
1049void MonthViewCell::selection( QListBoxItem *item ) 1062void MonthViewCell::selection( QListBoxItem *item )
1050{ 1063{
1051 if ( !item ) return; 1064 if ( !item ) return;
1052 1065
1053 mMonthView->setSelectedCell( this ); 1066 mMonthView->setSelectedCell( this );
1054} 1067}
1055 1068
1056 1069
1057// ******************************************************************************* 1070// *******************************************************************************
1058// ******************************************************************************* 1071// *******************************************************************************
1059// ******************************************************************************* 1072// *******************************************************************************
1060 1073
1061 1074
1062KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) 1075KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name)
1063 : KOEventView( calendar, parent, name ), 1076 : KOEventView( calendar, parent, name ),
1064 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), 1077 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
1065 mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) 1078 mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
1066{ 1079{
1067 mFlagKeyPressed = false; 1080 mFlagKeyPressed = false;
1068 mShortDayLabelsM = false; 1081 mShortDayLabelsM = false;
1069 mShortDayLabelsW = false; 1082 mShortDayLabelsW = false;
1070 skipResize = false; 1083 skipResize = false;
1071 clPending = true; 1084 clPending = true;
1072 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); 1085 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" );
1073 mWidStack = new QWidgetStack( this ); 1086 mWidStack = new QWidgetStack( this );
1074 QVBoxLayout* hb = new QVBoxLayout( this ); 1087 QVBoxLayout* hb = new QVBoxLayout( this );
1075 mMonthView = new QWidget( mWidStack ); 1088 mMonthView = new QWidget( mWidStack );
1076 mWeekView = new QWidget( mWidStack ); 1089 mWeekView = new QWidget( mWidStack );
1077#if QT_VERSION >= 0x030000 1090#if QT_VERSION >= 0x030000
1078 mWidStack->addWidget(mMonthView ); 1091 mWidStack->addWidget(mMonthView );
1079 mWidStack->addWidget(mWeekView ); 1092 mWidStack->addWidget(mWeekView );
1080#else 1093#else
1081 mWidStack->addWidget( mMonthView, 1 ); 1094 mWidStack->addWidget( mMonthView, 1 );
1082 mWidStack->addWidget( mWeekView , 1 ); 1095 mWidStack->addWidget( mWeekView , 1 );
1083#endif 1096#endif
1084 hb->addWidget( mNavigatorBar ); 1097 hb->addWidget( mNavigatorBar );
1085 hb->addWidget( mWidStack ); 1098 hb->addWidget( mWidStack );
1086 mShowWeekView = KOPrefs::instance()->mMonthViewWeek; 1099 mShowWeekView = KOPrefs::instance()->mMonthViewWeek;
1087 updatePossible = false; 1100 updatePossible = false;
1088 //updatePossible = true; 1101 //updatePossible = true;
1089 mCells.setAutoDelete( true ); 1102 mCells.setAutoDelete( true );
1090 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 1103 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
1091 mDayLabels.resize( mDaysPerWeek ); 1104 mDayLabels.resize( mDaysPerWeek );
1092 mDayLabelsW.resize( mDaysPerWeek ); 1105 mDayLabelsW.resize( mDaysPerWeek );
1093 QFont bfont = font(); 1106 QFont bfont = font();
1094 if ( QApplication::desktop()->width() < 650 ) { 1107 if ( QApplication::desktop()->width() < 650 ) {
1095 bfont.setPointSize( bfont.pointSize() - 2 ); 1108 bfont.setPointSize( bfont.pointSize() - 2 );
1096 } 1109 }
1097 bfont.setBold( true ); 1110 bfont.setBold( true );
1098 int i; 1111 int i;
1099 1112
1100 for( i = 0; i < mDaysPerWeek; i++ ) { 1113 for( i = 0; i < mDaysPerWeek; i++ ) {
1101 QLabel *label = new QLabel( mMonthView ); 1114 QLabel *label = new QLabel( mMonthView );
1102 label->setFont(bfont); 1115 label->setFont(bfont);
1103 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1116 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1104 label->setLineWidth(1); 1117 label->setLineWidth(1);
1105 label->setAlignment(AlignCenter); 1118 label->setAlignment(AlignCenter);
1106 mDayLabels.insert( i, label ); 1119 mDayLabels.insert( i, label );
1107 label = new QLabel( mWeekView ); 1120 label = new QLabel( mWeekView );
1108 label->setFont(bfont); 1121 label->setFont(bfont);
1109 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1122 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1110 label->setLineWidth(1); 1123 label->setLineWidth(1);
1111 label->setAlignment(AlignCenter); 1124 label->setAlignment(AlignCenter);
1112 mDayLabelsW.insert( i, label ); 1125 mDayLabelsW.insert( i, label );
1113 } 1126 }
1114 1127
1115 bfont.setBold( false ); 1128 bfont.setBold( false );
1116 mWeekLabels.resize( mNumWeeks+1 ); 1129 mWeekLabels.resize( mNumWeeks+1 );
1117 mWeekLabelsW.resize( 2 ); 1130 mWeekLabelsW.resize( 2 );
1118 for( i = 0; i < mNumWeeks+1; i++ ) { 1131 for( i = 0; i < mNumWeeks+1; i++ ) {
1119 KOWeekButton *label = new KOWeekButton( mMonthView ); 1132 KOWeekButton *label = new KOWeekButton( mMonthView );
1120 label->setFocusPolicy(NoFocus); 1133 label->setFocusPolicy(NoFocus);
1121 label->setFont(bfont); 1134 label->setFont(bfont);
1122 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 1135 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
1123 label->setFlat(true); 1136 label->setFlat(true);
1124 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 1137 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
1125 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1138 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1126 //label->setLineWidth(1); 1139 //label->setLineWidth(1);
1127 //label->setAlignment(AlignCenter); 1140 //label->setAlignment(AlignCenter);
1128 mWeekLabels.insert( i, label ); 1141 mWeekLabels.insert( i, label );
1129 } 1142 }
1130 mWeekLabels[mNumWeeks]->setText( i18n("W")); 1143 mWeekLabels[mNumWeeks]->setText( i18n("W"));
1131 mWeekLabels[mNumWeeks]->setFocusPolicy(WheelFocus); 1144 mWeekLabels[mNumWeeks]->setFocusPolicy(WheelFocus);
1132 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number")); 1145 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number"));
1133 1146
1134 for( i = 0; i < 1+1; i++ ) { 1147 for( i = 0; i < 1+1; i++ ) {
1135 KOWeekButton *label = new KOWeekButton( mWeekView ); 1148 KOWeekButton *label = new KOWeekButton( mWeekView );
1136 label->setFocusPolicy(NoFocus); 1149 label->setFocusPolicy(NoFocus);
1137 label->setFont(bfont); 1150 label->setFont(bfont);
1138 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 1151 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
1139 label->setFlat(true); 1152 label->setFlat(true);
1140 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 1153 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
1141 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1154 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1142 //label->setLineWidth(1); 1155 //label->setLineWidth(1);
1143 //label->setAlignment(AlignCenter); 1156 //label->setAlignment(AlignCenter);
1144 mWeekLabelsW.insert( i, label ); 1157 mWeekLabelsW.insert( i, label );
1145 } 1158 }
1146 mWeekLabelsW[1]->setText( i18n("W")); 1159 mWeekLabelsW[1]->setText( i18n("W"));
1147 mWeekLabelsW[1]->setFocusPolicy(WheelFocus); 1160 mWeekLabelsW[1]->setFocusPolicy(WheelFocus);
1148 1161
1149 1162
1150 int row, col; 1163 int row, col;
1151 mCells.resize( mNumCells ); 1164 mCells.resize( mNumCells );
1152 for( row = 0; row < mNumWeeks; ++row ) { 1165 for( row = 0; row < mNumWeeks; ++row ) {
1153 for( col = 0; col < mDaysPerWeek; ++col ) { 1166 for( col = 0; col < mDaysPerWeek; ++col ) {
1154 MonthViewCell *cell = new MonthViewCell( this, mMonthView ); 1167 MonthViewCell *cell = new MonthViewCell( this, mMonthView );
1155 mCells.insert( row * mDaysPerWeek + col, cell ); 1168 mCells.insert( row * mDaysPerWeek + col, cell );
1156 1169
1157 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 1170 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
1158 SLOT( defaultAction( Incidence * ) ) ); 1171 SLOT( defaultAction( Incidence * ) ) );
1159 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 1172 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
1160 SIGNAL( newEventSignal( QDateTime ) ) ); 1173 SIGNAL( newEventSignal( QDateTime ) ) );
1161 connect( cell, SIGNAL( showDaySignal( QDate ) ), 1174 connect( cell, SIGNAL( showDaySignal( QDate ) ),
1162 SIGNAL( showDaySignal( QDate ) ) ); 1175 SIGNAL( showDaySignal( QDate ) ) );
1163 connect( cell, SIGNAL( nextCell() ), 1176 connect( cell, SIGNAL( nextCell() ),
1164 SLOT( nextCell() ) ); 1177 SLOT( nextCell() ) );
1165 connect( cell, SIGNAL( prevCell() ), 1178 connect( cell, SIGNAL( prevCell() ),
1166 SLOT( prevCell() ) ); 1179 SLOT( prevCell() ) );
1167 } 1180 }
1168 } 1181 }
1169 mCellsW.resize( mDaysPerWeek ); 1182 mCellsW.resize( mDaysPerWeek );
1170 for( col = 0; col < mDaysPerWeek; ++col ) { 1183 for( col = 0; col < mDaysPerWeek; ++col ) {
1171 MonthViewCell *cell = new MonthViewCell( this, mWeekView ); 1184 MonthViewCell *cell = new MonthViewCell( this, mWeekView );
1172 mCellsW.insert( col, cell ); 1185 mCellsW.insert( col, cell );
1173 1186
1174 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 1187 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
1175 SLOT( defaultAction( Incidence * ) ) ); 1188 SLOT( defaultAction( Incidence * ) ) );
1176 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 1189 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
1177 SIGNAL( newEventSignal( QDateTime ) ) ); 1190 SIGNAL( newEventSignal( QDateTime ) ) );
1178 connect( cell, SIGNAL( showDaySignal( QDate ) ), 1191 connect( cell, SIGNAL( showDaySignal( QDate ) ),
1179 SIGNAL( showDaySignal( QDate ) ) ); 1192 SIGNAL( showDaySignal( QDate ) ) );
1180 connect( cell, SIGNAL( nextCell() ), 1193 connect( cell, SIGNAL( nextCell() ),
1181 SLOT( nextCell() ) ); 1194 SLOT( nextCell() ) );
1182 connect( cell, SIGNAL( prevCell() ), 1195 connect( cell, SIGNAL( prevCell() ),
1183 SLOT( prevCell() ) ); 1196 SLOT( prevCell() ) );
1184 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); 1197 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont );
1185 } 1198 }
1186 1199
1187 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); 1200 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) );
1188 mContextMenu = eventPopup(); 1201 mContextMenu = eventPopup();
1189 // updateConfig(); //useless here... 1202 // updateConfig(); //useless here...
1190 // ... but we need mWidthLongDayLabel computed 1203 // ... but we need mWidthLongDayLabel computed
1191 QFontMetrics fontmetric(mDayLabels[0]->font()); 1204 QFontMetrics fontmetric(mDayLabels[0]->font());
1192 mWidthLongDayLabel = 0; 1205 mWidthLongDayLabel = 0;
1193 for (int i = 0; i < 7; i++) { 1206 for (int i = 0; i < 7; i++) {
1194 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 1207 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
1195 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 1208 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
1196 } 1209 }
1197 1210
1198 //mWeekLabels[mNumWeeks]->setText( i18n("W")); 1211 //mWeekLabels[mNumWeeks]->setText( i18n("W"));
1199 1212
1200#if 0 1213#if 0
1201 if ( mShowWeekView ) 1214 if ( mShowWeekView )
1202 mWidStack->raiseWidget( mWeekView ); 1215 mWidStack->raiseWidget( mWeekView );
1203 else 1216 else
1204 mWidStack->raiseWidget( mMonthView ); 1217 mWidStack->raiseWidget( mMonthView );
1205#endif 1218#endif
1206 1219
1207 emit incidenceSelected( 0 ); 1220 emit incidenceSelected( 0 );
1208 1221
1209 mComputeLayoutTimer = new QTimer( this ); 1222 mComputeLayoutTimer = new QTimer( this );
1210 connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout())); 1223 connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout()));
1211 1224
1212 1225
1213#ifndef DESKTOP_VERSION 1226#ifndef DESKTOP_VERSION
1214 resize( QApplication::desktop()->size() ); 1227 resize( QApplication::desktop()->size() );
1215#else 1228#else
1216 resize(640, 480 ); 1229 resize(640, 480 );
1217 updatePossible = true; 1230 updatePossible = true;
1218#endif 1231#endif
1219 computeLayout(); 1232 computeLayout();
1220 1233
1221 if ( mShowWeekView ) 1234 if ( mShowWeekView )
1222 mWidStack->raiseWidget( mWeekView ); 1235 mWidStack->raiseWidget( mWeekView );
1223 else 1236 else
1224 mWidStack->raiseWidget( mMonthView ); 1237 mWidStack->raiseWidget( mMonthView );
1225} 1238}
1226 1239
1227KOMonthView::~KOMonthView() 1240KOMonthView::~KOMonthView()
1228{ 1241{
1229 delete mContextMenu; 1242 delete mContextMenu;
1230} 1243}
1231 1244
1232void KOMonthView::selectInternalWeekNum ( int n ) 1245void KOMonthView::selectInternalWeekNum ( int n )
1233{ 1246{
1234 switchView(); 1247 switchView();
1235 if ( !KOPrefs::instance()->mMonthViewWeek ) 1248 if ( !KOPrefs::instance()->mMonthViewWeek )
1236 emit selectMonth (); 1249 emit selectMonth ();
1237 else 1250 else
1238 emit selectWeekNum ( n ); 1251 emit selectWeekNum ( n );
1239} 1252}
1240 1253
1241int KOMonthView::currentWeek() 1254int KOMonthView::currentWeek()
1242{ 1255{
1243 if ( mShowWeekView ) 1256 if ( mShowWeekView )
1244 return mWeekLabelsW[0]->getWeekNum(); 1257 return mWeekLabelsW[0]->getWeekNum();
1245 return mWeekLabels[0]->getWeekNum(); 1258 return mWeekLabels[0]->getWeekNum();
1246} 1259}
1247void KOMonthView::switchView() 1260void KOMonthView::switchView()
1248{ 1261{
1249 if ( selectedCell( ) ) 1262 if ( selectedCell( ) )
1250 selectedCell()->deselect(); 1263 selectedCell()->deselect();
1251 mShowWeekView = !mShowWeekView; 1264 mShowWeekView = !mShowWeekView;
1252 KOPrefs::instance()->mMonthViewWeek = mShowWeekView; 1265 KOPrefs::instance()->mMonthViewWeek = mShowWeekView;
1253 if ( clPending ) { 1266 if ( clPending ) {
1254 computeLayout(); 1267 computeLayout();
1255 updateConfig(); 1268 updateConfig();
1256 } 1269 }
1257 if ( mShowWeekView ) 1270 if ( mShowWeekView )
1258 mWidStack->raiseWidget( mWeekView ); 1271 mWidStack->raiseWidget( mWeekView );
1259 else 1272 else
1260 mWidStack->raiseWidget( mMonthView ); 1273 mWidStack->raiseWidget( mMonthView );
1261 clPending = false; 1274 clPending = false;
1262} 1275}
1263 1276
1264int KOMonthView::maxDatesHint() 1277int KOMonthView::maxDatesHint()
1265{ 1278{
1266 return mNumCells; 1279 return mNumCells;
1267} 1280}
1268 1281
1269int KOMonthView::currentDateCount() 1282int KOMonthView::currentDateCount()
1270{ 1283{
1271 return mNumCells; 1284 return mNumCells;
1272} 1285}
1273 1286
1274QPtrList<Incidence> KOMonthView::selectedIncidences() 1287QPtrList<Incidence> KOMonthView::selectedIncidences()
1275{ 1288{
1276 QPtrList<Incidence> selected; 1289 QPtrList<Incidence> selected;
1277 1290
1278 if ( mSelectedCell ) { 1291 if ( mSelectedCell ) {
1279 Incidence *incidence = mSelectedCell->selectedIncidence(); 1292 Incidence *incidence = mSelectedCell->selectedIncidence();
1280 if ( incidence ) selected.append( incidence ); 1293 if ( incidence ) selected.append( incidence );
1281 } 1294 }
1282 1295
1283 return selected; 1296 return selected;
1284} 1297}
1285 1298
1286DateList KOMonthView::selectedDates() 1299DateList KOMonthView::selectedDates()
1287{ 1300{
1288 DateList selected; 1301 DateList selected;
1289 1302
1290 if ( mSelectedCell ) { 1303 if ( mSelectedCell ) {
1291 QDate qd = mSelectedCell->selectedIncidenceDate(); 1304 QDate qd = mSelectedCell->selectedIncidenceDate();
1292 if ( qd.isValid() ) selected.append( qd ); 1305 if ( qd.isValid() ) selected.append( qd );
1293 } 1306 }
1294 1307
1295 return selected; 1308 return selected;
1296} 1309}
1297 1310
1298void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1311void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1299 const QDate &td) 1312 const QDate &td)
1300{ 1313{
1301#ifndef KORG_NOPRINTER 1314#ifndef KORG_NOPRINTER
1302 calPrinter->preview(CalPrinter::Month, fd, td); 1315 calPrinter->preview(CalPrinter::Month, fd, td);
1303#endif 1316#endif
1304} 1317}
1305 1318
1306void KOMonthView::updateConfig() 1319void KOMonthView::updateConfig()
1307{ 1320{
1308 1321
1309 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 1322 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
1310 1323
1311 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { 1324 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) {
1312 mWeekStartsMonday = true; 1325 mWeekStartsMonday = true;
1313 } 1326 }
1314 QFontMetrics fontmetric(mDayLabels[0]->font()); 1327 QFontMetrics fontmetric(mDayLabels[0]->font());
1315 mWidthLongDayLabel = 0; 1328 mWidthLongDayLabel = 0;
1316 1329
1317 for (int i = 0; i < 7; i++) { 1330 for (int i = 0; i < 7; i++) {
1318 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 1331 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
1319 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 1332 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
1320 } 1333 }
1321 bool temp = mShowSatSunComp ; 1334 bool temp = mShowSatSunComp ;
1322 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 1335 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
1323 if ( ! mShowWeekView ) { 1336 if ( ! mShowWeekView ) {
1324 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) 1337 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog )
1325 computeLayout(); 1338 computeLayout();
1326 } 1339 }
1327 updateDayLabels(); 1340 updateDayLabels();
1328 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); 1341 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks);
1329 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; 1342 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks;
1330 //resizeEvent( 0 ); 1343 //resizeEvent( 0 );
1331 for (uint i = 0; i < mCells.count(); ++i) { 1344 for (uint i = 0; i < mCells.count(); ++i) {
1332 mCells[i]->updateConfig(); 1345 mCells[i]->updateConfig();
1333 } 1346 }
1334 1347
1335 for (uint i = 0; i < mCellsW.count(); ++i) { 1348 for (uint i = 0; i < mCellsW.count(); ++i) {
1336 mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont); 1349 mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont);
1337 } 1350 }
1338#ifdef DESKTOP_VERSION 1351#ifdef DESKTOP_VERSION
1339 MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); 1352 MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips);
1340#endif 1353#endif
1341 updateView(); 1354 updateView();
1342} 1355}
1343 1356
1344void KOMonthView::updateDayLabels() 1357void KOMonthView::updateDayLabels()
1345{ 1358{
1346 1359
1347 QPtrVector<QLabel> *mDayLabelsT; 1360 QPtrVector<QLabel> *mDayLabelsT;
1348 1361
1349 mDayLabelsT = &mDayLabelsW; 1362 mDayLabelsT = &mDayLabelsW;
1350 for (int i = 0; i < 7; i++) { 1363 for (int i = 0; i < 7; i++) {
1351 { 1364 {
1352 bool show = mShortDayLabelsW; 1365 bool show = mShortDayLabelsW;
1353 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) 1366 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
1354 show = true; 1367 show = true;
1355 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); 1368 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
1356 } 1369 }
1357 } 1370 }
1358 mDayLabelsT = &mDayLabels; 1371 mDayLabelsT = &mDayLabels;
1359 for (int i = 0; i < 7; i++) { 1372 for (int i = 0; i < 7; i++) {
1360 if (KGlobal::locale()->weekStartsMonday() || KOPrefs::instance()->mMonthViewSatSunTog ) { 1373 if (KGlobal::locale()->weekStartsMonday() || KOPrefs::instance()->mMonthViewSatSunTog ) {
1361 bool show = mShortDayLabelsM; 1374 bool show = mShortDayLabelsM;
1362 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) 1375 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
1363 show = true; 1376 show = true;
1364 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); 1377 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
1365 } else { 1378 } else {
1366 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM)); 1379 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM));
1367 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM)); 1380 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM));
1368 1381
1369 } 1382 }
1370 } 1383 }
1371 1384
1372} 1385}
1373 1386
1374void KOMonthView::showDates(const QDate &start, const QDate &) 1387void KOMonthView::showDates(const QDate &start, const QDate &)
1375{ 1388{
1376 // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; 1389 // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl;
1377 1390
1378 QPtrVector<MonthViewCell> *cells; 1391 QPtrVector<MonthViewCell> *cells;
1379 QPtrVector<QLabel> *dayLabels; 1392 QPtrVector<QLabel> *dayLabels;
1380 QPtrVector<KOWeekButton> *weekLabels; 1393 QPtrVector<KOWeekButton> *weekLabels;
1381 int weekNum = 6; 1394 int weekNum = 6;
1382 mStartDate = start; 1395 mStartDate = start;
1383 if ( mShowWeekView ) { 1396 if ( mShowWeekView ) {
1384 weekNum = 1; 1397 weekNum = 1;
1385 cells = &mCellsW; 1398 cells = &mCellsW;
1386 dayLabels = &mDayLabelsW; 1399 dayLabels = &mDayLabelsW;
1387 weekLabels = &mWeekLabelsW; 1400 weekLabels = &mWeekLabelsW;
1388 if ( !KGlobal::locale()->weekStartsMonday() ) { 1401 if ( !KGlobal::locale()->weekStartsMonday() ) {
1389 mStartDate = mStartDate.addDays( 1 ); 1402 mStartDate = mStartDate.addDays( 1 );
1390 } 1403 }
1391 } else { 1404 } else {
1392 cells = &mCells; 1405 cells = &mCells;
1393 dayLabels = &mDayLabels; 1406 dayLabels = &mDayLabels;
1394 weekLabels = &mWeekLabels; 1407 weekLabels = &mWeekLabels;
1395 } 1408 }
1396 1409
1397 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 1410 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
1398 1411
1399 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { 1412 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) {
1400 mWeekStartsMonday = true; 1413 mWeekStartsMonday = true;
1401 } 1414 }
1402 int startWeekDay = mWeekStartsMonday ? 1 : 7; 1415 int startWeekDay = mWeekStartsMonday ? 1 : 7;
1403 1416
1404 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { 1417 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) {
1405 mStartDate = mStartDate.addDays( -1 ); 1418 mStartDate = mStartDate.addDays( -1 );
1406 } 1419 }
1407 bool primary = false; 1420 bool primary = false;
1408 uint i; 1421 uint i;
1409 for( i = 0; i < (*cells).size(); ++i ) { 1422 for( i = 0; i < (*cells).size(); ++i ) {
1410 QDate date = mStartDate.addDays( i ); 1423 QDate date = mStartDate.addDays( i );
1411 (*cells)[i]->setDate( date ); 1424 (*cells)[i]->setDate( date );
1412 1425
1413#ifndef KORG_NOPLUGINS 1426#ifndef KORG_NOPLUGINS
1414 // add holiday, if present 1427 // add holiday, if present
1415 QString hstring(KOCore::self()->holiday(date)); 1428 QString hstring(KOCore::self()->holiday(date));
1416 (*cells)[i]->setHoliday( hstring ); 1429 (*cells)[i]->setHoliday( hstring );
1417#endif 1430#endif
1418 1431
1419 } 1432 }
1420 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); 1433 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 );
1421 for( i = 0; i < weekNum; ++i ) { 1434 for( i = 0; i < weekNum; ++i ) {
1422 int wno; 1435 int wno;
1423 // remember, according to ISO 8601, the first week of the year is the 1436 // remember, according to ISO 8601, the first week of the year is the
1424 // first week that contains a thursday. Thus we must subtract off 4, 1437 // first week that contains a thursday. Thus we must subtract off 4,
1425 // not just 1. 1438 // not just 1.
1426 int dayOfYear = date.dayOfYear(); 1439 int dayOfYear = date.dayOfYear();
1427 if (dayOfYear % 7 != 0) 1440 if (dayOfYear % 7 != 0)
1428 wno = dayOfYear / 7 + 1; 1441 wno = dayOfYear / 7 + 1;
1429 else 1442 else
1430 wno =dayOfYear / 7; 1443 wno =dayOfYear / 7;
1431 (*weekLabels)[i]->setWeekNum( wno ); 1444 (*weekLabels)[i]->setWeekNum( wno );
1432 date = date.addDays( 7 ); 1445 date = date.addDays( 7 );
1433 } 1446 }
1434 updateView(); 1447 updateView();
1435} 1448}
1436 1449
1437void KOMonthView::showEvents(QPtrList<Event>) 1450void KOMonthView::showEvents(QPtrList<Event>)
1438{ 1451{
1439 qDebug("KOMonthView::selectEvents is not implemented yet. "); 1452 qDebug("KOMonthView::selectEvents is not implemented yet. ");
1440} 1453}
1441 1454
1442void KOMonthView::changeEventDisplay(Event *, int) 1455void KOMonthView::changeEventDisplay(Event *, int)
1443{ 1456{
1444 // this should be re-written to be much more efficient, but this 1457 // this should be re-written to be much more efficient, but this
1445 // quick-and-dirty-hack gets the job done for right now. 1458 // quick-and-dirty-hack gets the job done for right now.
1446 //qDebug("KOMonthView::changeEventDisplay "); 1459 //qDebug("KOMonthView::changeEventDisplay ");
1447 updateView(); 1460 updateView();
1448} 1461}
1449 1462
1450void KOMonthView::updateView() 1463void KOMonthView::updateView()
1451{ 1464{
1452 1465
1453 if ( !updatePossible ) 1466 if ( !updatePossible )
1454 return; 1467 return;
1455 //qDebug("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU "); 1468 //qDebug("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU ");
1456 //QTime ti; 1469 //QTime ti;
1457 //ti.start(); 1470 //ti.start();
1458 clearSelection(); 1471 clearSelection();
1459 QPtrVector<MonthViewCell> *cells; 1472 QPtrVector<MonthViewCell> *cells;
1460 if ( mShowWeekView ) { 1473 if ( mShowWeekView ) {
1461 cells = &mCellsW; 1474 cells = &mCellsW;
1462 } else { 1475 } else {
1463 cells = &mCells; 1476 cells = &mCells;
1464 } 1477 }
1465#if 1 1478#if 1
1466 int i; 1479 int i;
1467 int timeSpan = (*cells).size()-1; 1480 int timeSpan = (*cells).size()-1;
1468 if ( KOPrefs::instance()->mMonthViewWeek ) 1481 if ( KOPrefs::instance()->mMonthViewWeek )
1469 timeSpan = 6; 1482 timeSpan = 6;
1470 for( i = 0; i < timeSpan + 1; ++i ) { 1483 for( i = 0; i < timeSpan + 1; ++i ) {
1471 (*cells)[i]->startUpdateCell(); 1484 (*cells)[i]->startUpdateCell();
1472 } 1485 }
1473 1486
1474 QPtrList<Event> events = calendar()->events(); 1487 QPtrList<Event> events = calendar()->events();
1475 Event *event; 1488 Event *event;
1476 QDateTime dt; 1489 QDateTime dt;
1477 bool ok; 1490 bool ok;
1478 QDate endDate = mStartDate.addDays( timeSpan ); 1491 QDate endDate = mStartDate.addDays( timeSpan );
1479 for( event = events.first(); event; event = events.next() ) { // for event 1492 for( event = events.first(); event; event = events.next() ) { // for event
1480 if ( event->doesRecur() ) { 1493 if ( event->doesRecur() ) {
1481 bool last; 1494 bool last;
1482 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); 1495 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last );
1483 QDateTime incidenceEnd; 1496 QDateTime incidenceEnd;
1484 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); 1497 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() );
1485 bool invalid = false; 1498 bool invalid = false;
1486 while( true ) { 1499 while( true ) {
1487 if ( incidenceStart.isValid() ) { 1500 if ( incidenceStart.isValid() ) {
1488 incidenceEnd = incidenceStart.addDays( eventlen ); 1501 incidenceEnd = incidenceStart.addDays( eventlen );
1489 int st = incidenceStart.date().daysTo( endDate ); 1502 int st = incidenceStart.date().daysTo( endDate );
1490 if ( st >= 0 ) { // start before timeend 1503 if ( st >= 0 ) { // start before timeend
1491 int end = mStartDate.daysTo( incidenceEnd.date() ); 1504 int end = mStartDate.daysTo( incidenceEnd.date() );
1492 if ( end >= 0 ) { // end after timestart --- got one! 1505 if ( end >= 0 ) { // end after timestart --- got one!
1493 //normalize 1506 //normalize
1494 st = timeSpan - st; 1507 st = timeSpan - st;
1495 if ( st < 0 ) st = 0; 1508 if ( st < 0 ) st = 0;
1496 if ( end > timeSpan ) end = timeSpan; 1509 if ( end > timeSpan ) end = timeSpan;
1497 int iii; 1510 int iii;
1498 //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); 1511 //qDebug("found %s %d %d ",event->summary().latin1(), st, end );
1499 for ( iii = st;iii<= end;++iii) 1512 for ( iii = st;iii<= end;++iii)
1500 (*cells)[iii]->insertEvent( event ); 1513 (*cells)[iii]->insertEvent( event );
1501 } 1514 }
1502 } 1515 }
1503 } else { 1516 } else {
1504 if ( invalid ) 1517 if ( invalid )
1505 break; 1518 break;
1506 invalid = true; 1519 invalid = true;
1507 //qDebug("invalid %s", event->summary().latin1()); 1520 //qDebug("invalid %s", event->summary().latin1());
1508 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; 1521 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );;
1509 } 1522 }
1510 if ( last ) 1523 if ( last )
1511 break; 1524 break;
1512 bool ok; 1525 bool ok;
1513 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); 1526 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok );
1514 if ( ! ok ) 1527 if ( ! ok )
1515 break; 1528 break;
1516 if ( incidenceStart.date() > endDate ) 1529 if ( incidenceStart.date() > endDate )
1517 break; 1530 break;
1518 } 1531 }
1519 } else { // no recur 1532 } else { // no recur
1520 int st = event->dtStart().date().daysTo( endDate ); 1533 int st = event->dtStart().date().daysTo( endDate );
1521 if ( st >= 0 ) { // start before timeend 1534 if ( st >= 0 ) { // start before timeend
1522 int end = mStartDate.daysTo( event->dtEnd().date() ); 1535 int end = mStartDate.daysTo( event->dtEnd().date() );
1523 if ( end >= 0 ) { // end after timestart --- got one! 1536 if ( end >= 0 ) { // end after timestart --- got one!
1524 //normalize 1537 //normalize
1525 st = timeSpan - st; 1538 st = timeSpan - st;
1526 if ( st < 0 ) st = 0; 1539 if ( st < 0 ) st = 0;
1527 if ( end > timeSpan ) end = timeSpan; 1540 if ( end > timeSpan ) end = timeSpan;
1528 int iii; 1541 int iii;
1529 for ( iii = st;iii<= end;++iii) 1542 for ( iii = st;iii<= end;++iii)
1530 (*cells)[iii]->insertEvent( event ); 1543 (*cells)[iii]->insertEvent( event );
1531 } 1544 }
1532 } 1545 }
1533 } 1546 }
1534 } 1547 }
1535 // insert due todos 1548 // insert due todos
1536 QPtrList<Todo> todos = calendar()->todos( ); 1549 QPtrList<Todo> todos = calendar()->todos( );
1537 Todo *todo; 1550 Todo *todo;
1538 for(todo = todos.first(); todo; todo = todos.next()) { 1551 for(todo = todos.first(); todo; todo = todos.next()) {
1539 //insertTodo( todo ); 1552 //insertTodo( todo );
1540 if ( todo->hasDueDate() ) { 1553 if ( todo->hasDueDate() ) {
1541 int day = mStartDate.daysTo( todo->dtDue().date() ); 1554 int day = mStartDate.daysTo( todo->dtDue().date() );
1542 if ( day >= 0 && day < timeSpan + 1) { 1555 if ( day >= 0 && day < timeSpan + 1) {
1543 (*cells)[day]->insertTodo( todo ); 1556 (*cells)[day]->insertTodo( todo );
1544 } 1557 }
1545 } 1558 }
1546 } 1559 }
1547 1560
1548 for( i = 0; i < timeSpan+1; ++i ) { 1561 for( i = 0; i < timeSpan+1; ++i ) {
1549 (*cells)[i]->finishUpdateCell(); 1562 (*cells)[i]->finishUpdateCell();
1550 } 1563 }
1551 processSelectionChange(); 1564 processSelectionChange();
1552 //qApp->processEvents(); 1565 //qApp->processEvents();
1553 for( i = 0; i < timeSpan+1; ++i ) { 1566 for( i = 0; i < timeSpan+1; ++i ) {
1554 (*cells)[i]->repaintfinishUpdateCell(); 1567 (*cells)[i]->repaintfinishUpdateCell();
1555 } 1568 }
1556 setKeyBFocus(); 1569 setKeyBFocus();
1557#else 1570#else
1558 // old code 1571 // old code
1559 //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); 1572 //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ");
1560 int i; 1573 int i;
1561 for( i = 0; i < (*cells).count(); ++i ) { 1574 for( i = 0; i < (*cells).count(); ++i ) {
1562 (*cells)[i]->updateCell(); 1575 (*cells)[i]->updateCell();
1563 } 1576 }
1564 1577
1565 //qDebug("KOMonthView::updateView() "); 1578 //qDebug("KOMonthView::updateView() ");
1566 processSelectionChange(); 1579 processSelectionChange();
1567 // qDebug("---------------------------------------------------------------------+ "); 1580 // qDebug("---------------------------------------------------------------------+ ");
1568 (*cells)[0]->setFocus(); 1581 (*cells)[0]->setFocus();
1569#endif 1582#endif
1570 1583
1571 //qDebug("update time %d ", ti.elapsed()); 1584 //qDebug("update time %d ", ti.elapsed());
1572} 1585}
1573 1586
1574void KOMonthView::setKeyBoardFocus() 1587void KOMonthView::setKeyBoardFocus()
1575{ 1588{
1576 //qDebug("KOMonthView::setKeyBoardFocus() "); 1589 //qDebug("KOMonthView::setKeyBoardFocus() ");
1577 bool shootAgain = false; 1590 bool shootAgain = false;
1578 if ( mShowWeekView ) { 1591 if ( mShowWeekView ) {
1579 shootAgain = !mWeekLabelsW[1]->hasFocus(); 1592 shootAgain = !mWeekLabelsW[1]->hasFocus();
1580 mWeekLabelsW[1]->setFocus(); 1593 mWeekLabelsW[1]->setFocus();
1581 } 1594 }
1582 else { 1595 else {
1583 shootAgain = !mWeekLabels[mNumWeeks]->hasFocus(); 1596 shootAgain = !mWeekLabels[mNumWeeks]->hasFocus();
1584 mWeekLabels[mNumWeeks]->setFocus(); 1597 mWeekLabels[mNumWeeks]->setFocus();
1585 } 1598 }
1586 if ( shootAgain ) { 1599 if ( shootAgain ) {
1587 QTimer::singleShot( 0, this, SLOT ( setKeyBFocus() ) ); 1600 QTimer::singleShot( 0, this, SLOT ( setKeyBFocus() ) );
1588 } 1601 }
1589} 1602}
1590void KOMonthView::setKeyBFocus() 1603void KOMonthView::setKeyBFocus()
1591{ 1604{
1592 //qDebug("KOMonthView::setKeyBFocus() "); 1605 //qDebug("KOMonthView::setKeyBFocus() ");
1593 QTimer::singleShot( 0, this, SLOT ( setKeyBoardFocus() ) ); 1606 QTimer::singleShot( 0, this, SLOT ( setKeyBoardFocus() ) );
1594} 1607}
1595void KOMonthView::resizeEvent(QResizeEvent * e) 1608void KOMonthView::resizeEvent(QResizeEvent * e)
1596{ 1609{
1597 //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height()); 1610 //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height());
1598 if ( isVisible() ) { 1611 if ( isVisible() ) {
1599 //qDebug("KOMonthView::isVisible "); 1612 //qDebug("KOMonthView::isVisible ");
1600 slotComputeLayout(); 1613 slotComputeLayout();
1601 } else 1614 } else
1602 mComputeLayoutTimer->start( 100 ); 1615 mComputeLayoutTimer->start( 100 );
1603} 1616}
1604 1617
1605void KOMonthView::slotComputeLayout() 1618void KOMonthView::slotComputeLayout()
1606{ 1619{
1607 mComputeLayoutTimer->stop(); 1620 mComputeLayoutTimer->stop();
1608 //qDebug("KOMonthView::Post - resizeEvent %d %d ", width(), height() ); 1621 //qDebug("KOMonthView::Post - resizeEvent %d %d ", width(), height() );
1609 computeLayout(); 1622 computeLayout();
1610 clPending = true; 1623 clPending = true;
1611 setKeyBFocus(); 1624 setKeyBFocus();
1612} 1625}
1613void KOMonthView::computeLayoutWeek() 1626void KOMonthView::computeLayoutWeek()
1614{ 1627{
1615 static int lastWid = 0; 1628 static int lastWid = 0;
1616 static int lastHei = 0; 1629 static int lastHei = 0;
1617 int daysToShow; 1630 int daysToShow;
1618 bool combinedSatSun = false; 1631 bool combinedSatSun = false;
1619 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { 1632 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
1620 daysToShow = 6; 1633 daysToShow = 6;
1621 combinedSatSun = true; 1634 combinedSatSun = true;
1622 } 1635 }
1623 int tWid = topLevelWidget()->size().width(); 1636 int tWid = topLevelWidget()->size().width();
1624 int tHei = topLevelWidget()->size().height(); 1637 int tHei = topLevelWidget()->size().height();
1625 1638
1626 int wid = width();//e 1639 int wid = width();//e
1627 int hei = height()-1-mNavigatorBar->height(); 1640 int hei = height()-1-mNavigatorBar->height();
1628 1641
1629 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) 1642 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei )
1630 return; 1643 return;
1631 1644
1632 if ( lastWid == width() && lastHei == height() ) { 1645 if ( lastWid == width() && lastHei == height() ) {
1633 //qDebug("KOListWeekView::No compute layout needed "); 1646 //qDebug("KOListWeekView::No compute layout needed ");
1634 return; 1647 return;
1635 } 1648 }
1636 lastWid = width(); 1649 lastWid = width();
1637 lastHei = height(); 1650 lastHei = height();
1638 1651
1639 1652
1640 if ( wid < hei ) 1653 if ( wid < hei )
1641 daysToShow = 2; 1654 daysToShow = 2;
1642 else 1655 else
1643 daysToShow = 3; 1656 daysToShow = 3;
1644 mShowSatSunComp = true; 1657 mShowSatSunComp = true;
1645 combinedSatSun = true; 1658 combinedSatSun = true;
1646 1659
1647 //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ "); 1660 //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ ");
1648 QFontMetrics fm ( mWeekLabels[0]->font() ); 1661 QFontMetrics fm ( mWeekLabels[0]->font() );
1649 int weeklabelwid = fm.width( "888" ); 1662 int weeklabelwid = fm.width( "888" );
1650 wid -= weeklabelwid; 1663 wid -= weeklabelwid;
1651 1664
1652 int colWid = wid / daysToShow; 1665 int colWid = wid / daysToShow;
1653 int lastCol = wid - ( colWid*6 ); 1666 int lastCol = wid - ( colWid*6 );
1654 int dayLabelHei = mDayLabelsW[0]->sizeHint().height(); 1667 int dayLabelHei = mDayLabelsW[0]->sizeHint().height();
1655 int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow ); 1668 int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow );
1656 int colModulo = wid % daysToShow; 1669 int colModulo = wid % daysToShow;
1657 int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1; 1670 int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1;
1658 //qDebug("rowmod %d ", rowModulo); 1671 //qDebug("rowmod %d ", rowModulo);
1659 int i; 1672 int i;
1660 int x,y,w,h; 1673 int x,y,w,h;
1661 x= 0; 1674 x= 0;
1662 y= 0; 1675 y= 0;
1663 w = colWid; 1676 w = colWid;
1664 h = dayLabelHei ; 1677 h = dayLabelHei ;
1665 for ( i = 0; i < 7; i++) { 1678 for ( i = 0; i < 7; i++) {
1666 if ( i && !( i % daysToShow) && i < 6) { 1679 if ( i && !( i % daysToShow) && i < 6) {
1667 y += hei/(5-daysToShow); 1680 y += hei/(5-daysToShow);
1668 x = 0; 1681 x = 0;
1669 w = colWid; 1682 w = colWid;
1670 } 1683 }
1671 if ( ((i) % daysToShow) >= daysToShow-colModulo ) { 1684 if ( ((i) % daysToShow) >= daysToShow-colModulo ) {
1672 ++w; 1685 ++w;
1673 } 1686 }
1674 if ( i >= 5 ) { 1687 if ( i >= 5 ) {
1675 int wi = width() - x - weeklabelwid; 1688 int wi = width() - x - weeklabelwid;
1676 if ( i == 5 ) { 1689 if ( i == 5 ) {
1677 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,wi/2+wi%2,h); 1690 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,wi/2+wi%2,h);
1678 } else { 1691 } else {
1679 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,wi,h); 1692 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,wi,h);
1680 } 1693 }
1681 x = x - w + wi - (wi/2 ); 1694 x = x - w + wi - (wi/2 );
1682 } 1695 }
1683 else { 1696 else {
1684 int wi = w; 1697 int wi = w;
1685 if ( !(( i+1) % daysToShow)) { 1698 if ( !(( i+1) % daysToShow)) {
1686 wi = width() - x - weeklabelwid; 1699 wi = width() - x - weeklabelwid;
1687 } 1700 }
1688 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,wi,h); 1701 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,wi,h);
1689 } 1702 }
1690 x += w; 1703 x += w;
1691 } 1704 }
1692 x= 0; 1705 x= 0;
1693 y= dayLabelHei; 1706 y= dayLabelHei;
1694 w = colWid; 1707 w = colWid;
1695 h = cellHei; 1708 h = cellHei;
1696 int max = 0; 1709 int max = 0;
1697 for ( i = 0; i < mCellsW.count(); ++i) { 1710 for ( i = 0; i < mCellsW.count(); ++i) {
1698 if ( i > 6 ) { 1711 if ( i > 6 ) {
1699 mCellsW[i]->hide(); 1712 mCellsW[i]->hide();
1700 continue; 1713 continue;
1701 } 1714 }
1702 1715
1703 w = colWid; 1716 w = colWid;
1704 if ( ((i) % daysToShow) >= daysToShow-colModulo ) { 1717 if ( ((i) % daysToShow) >= daysToShow-colModulo ) {
1705 ++w; 1718 ++w;
1706 } 1719 }
1707 if ( i == (daysToShow-1-rowModulo)*7) 1720 if ( i == (daysToShow-1-rowModulo)*7)
1708 ++h; 1721 ++h;
1709 1722
1710 if ( i >= 5 ) { 1723 if ( i >= 5 ) {
1711 if ( i ==5 ) { 1724 if ( i ==5 ) {
1712 max = h/2; 1725 max = h/2;
1713 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max ); 1726 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max );
1714 x -= w ;y += h/2; 1727 x -= w ;y += h/2;
1715 } else { 1728 } else {
1716 if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) { 1729 if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) {
1717 ++w; 1730 ++w;
1718 } 1731 }
1719 max = h-h/2; 1732 max = h-h/2;
1720 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max ); 1733 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max );
1721 y -= h/2; 1734 y -= h/2;
1722 } 1735 }
1723 } else { 1736 } else {
1724 max = h; 1737 max = h;
1725 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h ); 1738 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h );
1726 } 1739 }
1727 1740
1728 1741
1729 x += w; 1742 x += w;
1730 if ( x + w/2 > wid ) { 1743 if ( x + w/2 > wid ) {
1731 x = 0; 1744 x = 0;
1732 y += h+dayLabelHei ; 1745 y += h+dayLabelHei ;
1733 } 1746 }
1734 //mCellsW[i]->dateLabel()->setMaximumHeight( max - mCellsW[i]->lineWidth()*2 ); 1747 //mCellsW[i]->dateLabel()->setMaximumHeight( max - mCellsW[i]->lineWidth()*2 );
1735 } 1748 }
1736 y= dayLabelHei; 1749 y= dayLabelHei;
1737 h = cellHei ; 1750 h = cellHei ;
1738 mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei); 1751 mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei);
1739 mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei); 1752 mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
1740 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); 1753 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
1741 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); 1754 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
1742 mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ; 1755 mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ;
1743 updateDayLabels(); 1756 updateDayLabels();
1744 //bool forceUpdate = !updatePossible; 1757 //bool forceUpdate = !updatePossible;
1745 updatePossible = true; 1758 updatePossible = true;
1746 //mWeekLabels[mNumWeeks]->setText( i18n("M")); 1759 //mWeekLabels[mNumWeeks]->setText( i18n("M"));
1747 //if ( forceUpdate ) 1760 //if ( forceUpdate )
1748 // updateView(); 1761 // updateView();
1749} 1762}
1750void KOMonthView::computeLayout() 1763void KOMonthView::computeLayout()
1751{ 1764{
1752 1765
1753 1766
1754 static int lastWid = 0; 1767 static int lastWid = 0;
1755 static int lastHei = 0; 1768 static int lastHei = 0;
1756 1769
1757 if ( mShowWeekView ){ 1770 if ( mShowWeekView ){
1758 computeLayoutWeek(); 1771 computeLayoutWeek();
1759 return; 1772 return;
1760 } 1773 }
1761 int daysToShow = 7; 1774 int daysToShow = 7;
1762 bool combinedSatSun = false; 1775 bool combinedSatSun = false;
1763 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { 1776 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
1764 daysToShow = 6; 1777 daysToShow = 6;
1765 combinedSatSun = true; 1778 combinedSatSun = true;
1766 } 1779 }
1767 int tWid = topLevelWidget()->size().width(); 1780 int tWid = topLevelWidget()->size().width();
1768 int tHei = topLevelWidget()->size().height(); 1781 int tHei = topLevelWidget()->size().height();
1769 1782
1770 int wid = width();//e 1783 int wid = width();//e
1771 int hei = height()-1-mNavigatorBar->height(); 1784 int hei = height()-1-mNavigatorBar->height();
1772 1785
1773 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) { 1786 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) {
1774 return; 1787 return;
1775 } 1788 }
1776 if ( lastWid == width() && lastHei == height() ){ 1789 if ( lastWid == width() && lastHei == height() ){
1777 //qDebug("KOMonthview::No compute layout needed "); 1790 //qDebug("KOMonthview::No compute layout needed ");
1778 return; 1791 return;
1779 } 1792 }
1780 1793
1781 lastWid = width(); 1794 lastWid = width();
1782 lastHei = height(); 1795 lastHei = height();
1783 //qDebug("KOMonthView::computeLayout() MMM ------------------- "); 1796 //qDebug("KOMonthView::computeLayout() MMM ------------------- ");
1784 QFontMetrics fm ( mWeekLabels[0]->font() ); 1797 QFontMetrics fm ( mWeekLabels[0]->font() );
1785 int weeklabelwid = fm.width( "888" ); 1798 int weeklabelwid = fm.width( "888" );
1786 wid -= weeklabelwid; 1799 wid -= weeklabelwid;
1787 1800
1788 int colWid = wid / daysToShow; 1801 int colWid = wid / daysToShow;
1789 int lastCol = wid - ( colWid*6 ); 1802 int lastCol = wid - ( colWid*6 );
1790 int dayLabelHei = mDayLabels[0]->sizeHint().height(); 1803 int dayLabelHei = mDayLabels[0]->sizeHint().height();
1791 int cellHei = (hei - dayLabelHei) /6; 1804 int cellHei = (hei - dayLabelHei) /6;
1792 int colModulo = wid % daysToShow; 1805 int colModulo = wid % daysToShow;
1793 int rowModulo = (hei- dayLabelHei) % 6; 1806 int rowModulo = (hei- dayLabelHei) % 6;
1794 //qDebug("rowmod %d ", rowModulo); 1807 //qDebug("rowmod %d ", rowModulo);
1795 int i; 1808 int i;
1796 int x,y,w,h; 1809 int x,y,w,h;
1797 x= 0; 1810 x= 0;
1798 y= 0; 1811 y= 0;
1799 w = colWid; 1812 w = colWid;
1800 h = dayLabelHei ; 1813 h = dayLabelHei ;
1801 for ( i = 0; i < 7; i++) { 1814 for ( i = 0; i < 7; i++) {
1802 if ( i == daysToShow-colModulo ) 1815 if ( i == daysToShow-colModulo )
1803 ++w; 1816 ++w;
1804 if ( combinedSatSun ) { 1817 if ( combinedSatSun ) {
1805 if ( i >= daysToShow-1 ) { 1818 if ( i >= daysToShow-1 ) {
1806 1819
1807 if ( i == 6 ) 1820 if ( i == 6 )
1808 mDayLabels[i]->setGeometry( x+weeklabelwid,y,width()-x-weeklabelwid,h); 1821 mDayLabels[i]->setGeometry( x+weeklabelwid,y,width()-x-weeklabelwid,h);
1809 else 1822 else
1810 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h); 1823 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h);
1811 x -= w/2 ; 1824 x -= w/2 ;
1812 } 1825 }
1813 else 1826 else
1814 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 1827 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
1815 } else 1828 } else
1816 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 1829 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
1817 x += w; 1830 x += w;
1818 } 1831 }
1819 x= 0; 1832 x= 0;
1820 y= dayLabelHei; 1833 y= dayLabelHei;
1821 w = colWid; 1834 w = colWid;
1822 h = cellHei ; 1835 h = cellHei ;
1823 int max = 0; 1836 int max = 0;
1824 for ( i = 0; i < mCells.count(); ++i) { 1837 for ( i = 0; i < mCells.count(); ++i) {
1825 //qDebug("iii %d ", i); 1838 //qDebug("iii %d ", i);
1826 w = colWid; 1839 w = colWid;
1827 if ( ((i) % 7) >= 7-colModulo ) { 1840 if ( ((i) % 7) >= 7-colModulo ) {
1828 ++w; 1841 ++w;
1829 } 1842 }
1830 if ( i == (6-rowModulo)*7) 1843 if ( i == (6-rowModulo)*7)
1831 ++h; 1844 ++h;
1832 if ( combinedSatSun ) { 1845 if ( combinedSatSun ) {
1833 if ( (i)%7 >= daysToShow-1 ) { 1846 if ( (i)%7 >= daysToShow-1 ) {
1834 if ( (i)%7 == daysToShow-1 ) { 1847 if ( (i)%7 == daysToShow-1 ) {
1835 w = width()-x-weeklabelwid; 1848 w = width()-x-weeklabelwid;
1836 max = h/2; 1849 max = h/2;
1837 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); 1850 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max );
1838 x -= w ;y += h/2; 1851 x -= w ;y += h/2;
1839 } else { 1852 } else {
1840 w = width()-x-weeklabelwid; 1853 w = width()-x-weeklabelwid;
1841 max = h-h/2; 1854 max = h-h/2;
1842 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); 1855 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max );
1843 y -= h/2; 1856 y -= h/2;
1844 } 1857 }
1845 } else { 1858 } else {
1846 max = h; 1859 max = h;
1847 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); 1860 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h );
1848 } 1861 }
1849 1862
1850 } 1863 }
1851 else { 1864 else {
1852 max = h; 1865 max = h;
1853 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); 1866 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h );
1854 } 1867 }
1855 x += w; 1868 x += w;
1856 if ( x + w/2 > wid ) { 1869 if ( x + w/2 > wid ) {
1857 x = 0; 1870 x = 0;
1858 y += h; 1871 y += h;
1859 } 1872 }
1860 //mCells[i]->dateLabel()->setMaximumHeight( max- mCells[i]->lineWidth()*2 ); 1873 //mCells[i]->dateLabel()->setMaximumHeight( max- mCells[i]->lineWidth()*2 );
1861 } 1874 }
1862 y= dayLabelHei; 1875 y= dayLabelHei;
1863 h = cellHei ; 1876 h = cellHei ;
1864 for ( i = 0; i < 6; i++) { 1877 for ( i = 0; i < 6; i++) {
1865 if ( i == (6-rowModulo)) 1878 if ( i == (6-rowModulo))
1866 ++h; 1879 ++h;
1867 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h); 1880 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h);
1868 y += h; 1881 y += h;
1869 } 1882 }
1870 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); 1883 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
1871 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); 1884 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
1872 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); 1885 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
1873 mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ; 1886 mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ;
1874 updateDayLabels(); 1887 updateDayLabels();
1875 //bool forceUpdate = !updatePossible; 1888 //bool forceUpdate = !updatePossible;
1876 updatePossible = true; 1889 updatePossible = true;
1877 //mWeekLabels[mNumWeeks]->setText( i18n("W")); 1890 //mWeekLabels[mNumWeeks]->setText( i18n("W"));
1878} 1891}
1879 1892
1880void KOMonthView::showContextMenu( Incidence *incidence ) 1893void KOMonthView::showContextMenu( Incidence *incidence )
1881{ 1894{
1882 mContextMenu->showIncidencePopup(incidence); 1895 mContextMenu->showIncidencePopup(incidence);
1883 /* 1896 /*
1884 if( incidence && incidence->type() == "Event" ) { 1897 if( incidence && incidence->type() == "Event" ) {
1885 Event *event = static_cast<Event *>(incidence); 1898 Event *event = static_cast<Event *>(incidence);
1886 mContextMenu->showEventPopup(event); 1899 mContextMenu->showEventPopup(event);
1887 } else { 1900 } else {
1888 kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; 1901 kdDebug() << "MonthView::showContextMenu(): cast failed." << endl;
1889 } 1902 }
1890 */ 1903 */
1891} 1904}
1892MonthViewCell * KOMonthView::selectedCell( ) 1905MonthViewCell * KOMonthView::selectedCell( )
1893{ 1906{
1894 return mSelectedCell; 1907 return mSelectedCell;
1895} 1908}
1896void KOMonthView::setSelectedCell( MonthViewCell *cell ) 1909void KOMonthView::setSelectedCell( MonthViewCell *cell )
1897{ 1910{
1898 //qDebug("KOMonthView::setSelectedCell "); 1911 //qDebug("KOMonthView::setSelectedCell ");
1899 if ( mSelectedCell && mSelectedCell != cell ) { 1912 if ( mSelectedCell && mSelectedCell != cell ) {
1900 MonthViewCell * mvc = mSelectedCell; 1913 MonthViewCell * mvc = mSelectedCell;
1901 mSelectedCell = cell; 1914 mSelectedCell = cell;
1902 mvc->deselect(); 1915 mvc->deselect();
1903 } else 1916 } else
1904 mSelectedCell = cell; 1917 mSelectedCell = cell;
1905 // if ( mSelectedCell ) 1918 // if ( mSelectedCell )
1906 // mSelectedCell->select(); 1919 // mSelectedCell->select();
1907 if ( !mSelectedCell ) 1920 if ( !mSelectedCell )
1908 emit incidenceSelected( 0 ); 1921 emit incidenceSelected( 0 );
1909 else 1922 else
1910 emit incidenceSelected( mSelectedCell->selectedIncidence() ); 1923 emit incidenceSelected( mSelectedCell->selectedIncidence() );
1911} 1924}
1912 1925
1913void KOMonthView::processSelectionChange() 1926void KOMonthView::processSelectionChange()
1914{ 1927{
1915 QPtrList<Incidence> incidences = selectedIncidences(); 1928 QPtrList<Incidence> incidences = selectedIncidences();
1916 if (incidences.count() > 0) { 1929 if (incidences.count() > 0) {
1917 emit incidenceSelected( incidences.first() ); 1930 emit incidenceSelected( incidences.first() );
1918 } else { 1931 } else {
1919 emit incidenceSelected( 0 ); 1932 emit incidenceSelected( 0 );
1920 clearSelection(); 1933 clearSelection();
1921 } 1934 }
1922} 1935}
1923 1936
1924void KOMonthView::clearSelection() 1937void KOMonthView::clearSelection()
1925{ 1938{
1926 if ( mSelectedCell ) { 1939 if ( mSelectedCell ) {
1927 mSelectedCell->deselect(); 1940 mSelectedCell->deselect();
1928 mSelectedCell = 0; 1941 mSelectedCell = 0;
1929 } 1942 }
1930} 1943}
1931 1944
1932void KOMonthView::keyReleaseEvent ( QKeyEvent * e) 1945void KOMonthView::keyReleaseEvent ( QKeyEvent * e)
1933{ 1946{
1934 if ( !e->isAutoRepeat() ) { 1947 if ( !e->isAutoRepeat() ) {
1935 mFlagKeyPressed = false; 1948 mFlagKeyPressed = false;
1936 } 1949 }
1937} 1950}
1938 1951
1939void KOMonthView::keyPressEvent ( QKeyEvent * e ) 1952void KOMonthView::keyPressEvent ( QKeyEvent * e )
1940{ 1953{
1941 1954
1942 qApp->processEvents(); 1955 qApp->processEvents();
1943 if ( e->isAutoRepeat() && !mFlagKeyPressed ) { 1956 if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
1944 //e->ignore(); 1957 //e->ignore();
1945 e->accept(); 1958 e->accept();
1946 return; 1959 return;
1947 } 1960 }
1948 if (! e->isAutoRepeat() ) 1961 if (! e->isAutoRepeat() )
1949 mFlagKeyPressed = true; 1962 mFlagKeyPressed = true;
1950 switch(e->key()) { 1963 switch(e->key()) {
1951 case Key_Up: 1964 case Key_Up:
1952 { 1965 {
1953 if ( mShowWeekView ) { 1966 if ( mShowWeekView ) {
1954 emit selectWeekNum ( currentWeek() - 1 ); 1967 emit selectWeekNum ( currentWeek() - 1 );
1955 } 1968 }
1956 else { 1969 else {
1957 emit prevMonth(); 1970 emit prevMonth();
1958 } 1971 }
1959 } 1972 }
1960 e->accept(); 1973 e->accept();
1961 break; 1974 break;
1962 case Key_Down: 1975 case Key_Down:
1963 { 1976 {
1964 if ( mShowWeekView ) { 1977 if ( mShowWeekView ) {
1965 emit selectWeekNum ( currentWeek() +1); 1978 emit selectWeekNum ( currentWeek() +1);
1966 } 1979 }
1967 else { 1980 else {
1968 emit nextMonth(); 1981 emit nextMonth();
1969 } 1982 }
1970 1983
1971 } 1984 }
1972 e->accept(); 1985 e->accept();
1973 break; 1986 break;
1974 case Key_Return: 1987 case Key_Return:
1975 case Key_Enter: 1988 case Key_Enter:
1976 { 1989 {
1977 selectInternalWeekNum ( currentWeek() ); 1990 selectInternalWeekNum ( currentWeek() );
1978 } 1991 }
1979 e->accept(); 1992 e->accept();
1980 break; 1993 break;
1981 case Key_D: 1994 case Key_D:
1982 if ( mSelectedCell ) { 1995 if ( mSelectedCell ) {
1983 mSelectedCell->showDay(); 1996 mSelectedCell->showDay();
1984 e->accept(); 1997 e->accept();
1985 } else { 1998 } else {
1986 e->ignore(); 1999 e->ignore();
1987 } 2000 }
1988 break; 2001 break;
1989 default: 2002 default:
1990 e->ignore(); 2003 e->ignore();
1991 break; 2004 break;
1992 } 2005 }
1993} 2006}
1994 2007
1995void KOMonthView::nextCell() 2008void KOMonthView::nextCell()
1996{ 2009{
1997 bool res = focusNextPrevChild ( true ); 2010 bool res = focusNextPrevChild ( true );
1998} 2011}
1999void KOMonthView::prevCell() 2012void KOMonthView::prevCell()
2000{ 2013{
2001 focusNextPrevChild ( false ); 2014 focusNextPrevChild ( false );
2002} 2015}