summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kodaymatrix.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index 7076e05..52fd1e8 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -1,1223 +1,1223 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> 3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at>
4 Parts of the source code have been copied from kdpdatebutton.cpp 4 Parts of the source code have been copied from kdpdatebutton.cpp
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source ode for Qt in the source distribution. 22 without including the source ode for Qt in the source distribution.
23*/ 23*/
24 24
25#include <qevent.h> 25#include <qevent.h>
26#include <qpainter.h> 26#include <qpainter.h>
27#include <qptrlist.h> 27#include <qptrlist.h>
28#include <qtimer.h> 28#include <qtimer.h>
29#include <qwhatsthis.h> 29#include <qwhatsthis.h>
30 30
31#include <kglobal.h> 31#include <kglobal.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <klocale.h> 33#include <klocale.h>
34 34
35#include <libkcal/vcaldrag.h> 35#include <libkcal/vcaldrag.h>
36#include <libkcal/icaldrag.h> 36#include <libkcal/icaldrag.h>
37#include <libkcal/dndfactory.h> 37#include <libkcal/dndfactory.h>
38#include <libkcal/calendarresources.h> 38#include <libkcal/calendarresources.h>
39#include <libkcal/resourcecalendar.h> 39#include <libkcal/resourcecalendar.h>
40#include <kresources/resourceselectdialog.h> 40#include <kresources/resourceselectdialog.h>
41 41
42#include <kcalendarsystem.h> 42#include <kcalendarsystem.h>
43 43
44#ifndef KORG_NOPLUGINS 44#ifndef KORG_NOPLUGINS
45#include "kocore.h" 45#include "kocore.h"
46#endif 46#endif
47#include "koprefs.h" 47#include "koprefs.h"
48#include "koglobals.h" 48#include "koglobals.h"
49 49
50#include "kodaymatrix.h" 50#include "kodaymatrix.h"
51 51
52// ============================================================================ 52// ============================================================================
53// D Y N A M I C T I P 53// D Y N A M I C T I P
54// ============================================================================ 54// ============================================================================
55 55
56DynamicTip::DynamicTip( QWidget * parent ) 56DynamicTip::DynamicTip( QWidget * parent )
57 : QToolTip( parent ) 57 : QToolTip( parent )
58{ 58{
59 matrix = (KODayMatrix*)parent; 59 matrix = (KODayMatrix*)parent;
60} 60}
61 61
62class KODaymatrixWhatsThis :public QWhatsThis 62class KODaymatrixWhatsThis :public QWhatsThis
63{ 63{
64public: 64public:
65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;}; 65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;};
66 ~KODaymatrixWhatsThis() { ; }; 66 ~KODaymatrixWhatsThis() { ; };
67 67
68protected: 68protected:
69 virtual QString text( const QPoint& p ) 69 virtual QString text( const QPoint& p )
70 { 70 {
71 return _view->getWhatsThisText( p ) ; 71 return _view->getWhatsThisText( p ) ;
72 } 72 }
73private: 73private:
74 KODayMatrix * _view; 74 KODayMatrix * _view;
75}; 75};
76 76
77void DynamicTip::maybeTip( const QPoint &pos ) 77void DynamicTip::maybeTip( const QPoint &pos )
78{ 78{
79 //calculate which cell of the matrix the mouse is in 79 //calculate which cell of the matrix the mouse is in
80 QRect sz = matrix->frameRect(); 80 QRect sz = matrix->frameRect();
81 int dheight = sz.height()*7 / 42; 81 int dheight = sz.height()*7 / 42;
82 int dwidth = sz.width() / 7; 82 int dwidth = sz.width() / 7;
83 int row = pos.y()/dheight; 83 int row = pos.y()/dheight;
84 int col = pos.x()/dwidth; 84 int col = pos.x()/dwidth;
85 85
86 QRect rct(col*dwidth, row*dheight, dwidth, dheight); 86 QRect rct(col*dwidth, row*dheight, dwidth, dheight);
87 87
88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" << 88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" <<
89// col << "][" << row << "] => " <<(col+row*7) << endl; 89// col << "][" << row << "] => " <<(col+row*7) << endl;
90 90
91 //show holiday names only 91 //show holiday names only
92 QString str = matrix->getHolidayLabel(col+row*7); 92 QString str = matrix->getHolidayLabel(col+row*7);
93 if (str.isEmpty()) return; 93 if (str.isEmpty()) return;
94 tip(rct, str); 94 tip(rct, str);
95} 95}
96 96
97 97
98// ============================================================================ 98// ============================================================================
99// K O D A Y M A T R I X 99// K O D A Y M A T R I X
100// ============================================================================ 100// ============================================================================
101 101
102const int KODayMatrix::NOSELECTION = -1000; 102const int KODayMatrix::NOSELECTION = -1000;
103const int KODayMatrix::NUMDAYS = 42; 103const int KODayMatrix::NUMDAYS = 42;
104 104
105KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) 105KODayMatrix::KODayMatrix( QWidget *parent, const char *name )
106 : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 ) 106 : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 )
107 107
108 108
109{ 109{
110 mLastView = -1; 110 mLastView = -1;
111 oldW = 0; 111 oldW = 0;
112 oldH = 0; 112 oldH = 0;
113 myPix.resize( 150, 120 ); 113 myPix.resize( 150, 120 );
114 mRedrawNeeded = true; 114 mRedrawNeeded = true;
115 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); 115 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this);
116 mPendingUpdateBeforeRepaint = false; 116 mPendingUpdateBeforeRepaint = false;
117 mouseDown = false; 117 mouseDown = false;
118 // initialize dynamic arrays 118 // initialize dynamic arrays
119 bDays.resize ( NUMDAYS ); 119 bDays.resize ( NUMDAYS );
120 pDays.resize ( NUMDAYS ); 120 pDays.resize ( NUMDAYS );
121 hDays.resize ( NUMDAYS ); 121 hDays.resize ( NUMDAYS );
122 eDays.resize ( NUMDAYS ); 122 eDays.resize ( NUMDAYS );
123 days = new QDate[NUMDAYS]; 123 days = new QDate[NUMDAYS];
124 daylbls = new QString[NUMDAYS]; 124 daylbls = new QString[NUMDAYS];
125 //events = new int[NUMDAYS]; 125 //events = new int[NUMDAYS];
126 mToolTip = new DynamicTip(this); 126 mToolTip = new DynamicTip(this);
127 127
128 // set default values used for drawing the matrix 128 // set default values used for drawing the matrix
129 mDefaultBackColor = palette().active().base(); 129 mDefaultBackColor = palette().active().base();
130 mDefaultTextColor = palette().active().foreground(); 130 mDefaultTextColor = palette().active().foreground();
131 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); 131 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor);
132 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); 132 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor);
133 mSelectedDaysColor = QColor("white"); 133 mSelectedDaysColor = QColor("white");
134 mTodayMarginWidth = 2; 134 mTodayMarginWidth = 2;
135 mSelEnd = mSelStart = NOSELECTION; 135 mSelEnd = mSelStart = NOSELECTION;
136 136
137 setAcceptDrops(true); 137 setAcceptDrops(true);
138 //setFont( QFont("Arial", 10) ); 138 //setFont( QFont("Arial", 10) );
139 139
140 mUpdateTimer = new QTimer( this ); 140 mUpdateTimer = new QTimer( this );
141 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); 141 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() ));
142 mRepaintTimer = new QTimer( this ); 142 mRepaintTimer = new QTimer( this );
143 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); 143 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() ));
144 mDayChanged = false; 144 mDayChanged = false;
145 updateView(); 145 updateView();
146} 146}
147QString KODayMatrix::getWhatsThisText( QPoint p ) 147QString KODayMatrix::getWhatsThisText( QPoint p )
148{ 148{
149 149
150 int tmp = getDayIndexFrom(p.x(), p.y()); 150 int tmp = getDayIndexFrom(p.x(), p.y());
151 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) 151 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar )
152 return QString(); 152 return QString();
153 QDate mDate = days[tmp]; 153 QDate mDate = days[tmp];
154 QPtrList<Event> eventlist = mCalendar->events(mDate); 154 QPtrList<Event> eventlist = mCalendar->events(mDate);
155 Event *event; 155 Event *event;
156 QStringList mToolTip; 156 QStringList mToolTip;
157 for(event=eventlist.first();event != 0;event=eventlist.next()) { 157 for(event=eventlist.first();event != 0;event=eventlist.next()) {
158 QString mToolTipText; 158 QString mToolTipText;
159 QString text; 159 QString text;
160 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day 160 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
161 if (event->isMultiDay()) { 161 if (event->isMultiDay()) {
162 QString prefix = "<->";multiday = 2; 162 QString prefix = "<->";multiday = 2;
163 QString time; 163 QString time;
164 if ( event->doesRecur() ) { 164 if ( event->doesRecur() ) {
165 if ( event->recursOn( mDate) ) { 165 if ( event->recursOn( mDate) ) {
166 prefix ="->" ;multiday = 1; 166 prefix ="->" ;multiday = 1;
167 } 167 }
168 else { 168 else {
169 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 169 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
170 if ( event->recursOn( mDate.addDays( -days)) ) { 170 if ( event->recursOn( mDate.addDays( -days)) ) {
171 prefix ="<-" ;multiday = 3; 171 prefix ="<-" ;multiday = 3;
172 } 172 }
173 } 173 }
174 } else { 174 } else {
175 if (mDate == event->dtStart().date()) { 175 if (mDate == event->dtStart().date()) {
176 prefix ="->" ;multiday = 1; 176 prefix ="->" ;multiday = 1;
177 } else if (mDate == event->dtEnd().date()) { 177 } else if (mDate == event->dtEnd().date()) {
178 prefix ="<-" ;multiday = 3; 178 prefix ="<-" ;multiday = 3;
179 } 179 }
180 } 180 }
181 if ( !event->doesFloat() ) { 181 if ( !event->doesFloat() ) {
182 if ( mDate == event->dtStart().date () ) 182 if ( mDate == event->dtStart().date () )
183 time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; 183 time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
184 else if ( mDate == event->dtEnd().date () ) 184 else if ( mDate == event->dtEnd().date () )
185 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 185 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
186 186
187 } 187 }
188 text = time + event->summary(); 188 text = time + event->summary();
189 mToolTipText += prefix + text; 189 mToolTipText += prefix + text;
190 } else { 190 } else {
191 if (event->doesFloat()) { 191 if (event->doesFloat()) {
192 text = event->summary(); 192 text = event->summary();
193 mToolTipText += text; 193 mToolTipText += text;
194 } 194 }
195 else { 195 else {
196 text = KGlobal::locale()->formatTime(event->dtStart().time()); 196 text = KGlobal::locale()->formatTime(event->dtStart().time());
197 text += " " + event->summary(); 197 text += " " + event->summary();
198 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 198 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
199 } 199 }
200 } 200 }
201 if ( !event->location().isEmpty() ) 201 if ( !event->location().isEmpty() )
202 mToolTipText += " (" + event->location() + ")"; 202 mToolTipText += " (" + event->location() + ")";
203 //qDebug("TTT: %s ", mToolTipText.latin1()); 203 //qDebug("TTT: %s ", mToolTipText.latin1());
204 mToolTip.append( deTag( mToolTipText ) ); 204 mToolTip.append( deTag( mToolTipText ) );
205 } 205 }
206 mToolTip.sort(); 206 mToolTip.sort();
207 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { 207 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) {
208 QPtrList<Todo> todolist = mCalendar->todos(mDate); 208 QPtrList<Todo> todolist = mCalendar->todos(mDate);
209 Todo *todo; 209 Todo *todo;
210 for(todo=todolist.first();todo != 0;todo=todolist.next()) { 210 for(todo=todolist.first();todo != 0;todo=todolist.next()) {
211 QString mToolTipText; 211 QString mToolTipText;
212 if ( !todo->doesFloat() ) 212 if ( !todo->doesFloat() )
213 mToolTipText += KGlobal::locale()->formatTime(todo->dtDue().time())+" "; 213 mToolTipText += KGlobal::locale()->formatTime(todo->dtDue().time())+" ";
214 mToolTipText += todo->summary(); 214 mToolTipText += todo->summary();
215 if ( !todo->location().isEmpty() ) 215 if ( !todo->location().isEmpty() )
216 mToolTipText += " (" + todo->location() + ")"; 216 mToolTipText += " (" + todo->location() + ")";
217 mToolTipText = deTag( mToolTipText); 217 mToolTipText = deTag( mToolTipText);
218 mToolTipText = "<b>" + i18n("Todo: ") + "</b>"+ mToolTipText; 218 mToolTipText = "<b>" + i18n("Todo: ") + "</b>"+ mToolTipText;
219 mToolTip.append( mToolTipText ); 219 mToolTip.append( mToolTipText );
220 } 220 }
221 } 221 }
222 if (KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { 222 if (KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) {
223 QPtrList<Journal> j_list = mCalendar->journals4Date( mDate ); 223 QPtrList<Journal> j_list = mCalendar->journals4Date( mDate );
224 Journal *j = j_list.first(); 224 Journal *j = j_list.first();
225 while ( j ) { 225 while ( j ) {
226 QString mToolTipText; 226 QString mToolTipText;
227 if ( !j->summary().isEmpty() ) { 227 if ( !j->summary().isEmpty() ) {
228 mToolTipText = j->summary().left(30); 228 mToolTipText = j->summary().left(30);
229 if ( j->summary().length() > 30 ) 229 if ( j->summary().length() > 30 )
230 mToolTipText += " ..."; 230 mToolTipText += " ...";
231 } else { 231 } else {
232 mToolTipText = j->description().left(25); 232 mToolTipText = j->description().left(25);
233 if ( j->description().length() > 25 ) 233 if ( j->description().length() > 25 )
234 mToolTipText += " ..."; 234 mToolTipText += " ...";
235 mToolTipText = deTag( mToolTipText); 235 mToolTipText = deTag( mToolTipText);
236 } 236 }
237 mToolTipText = "<b>" + i18n("Journal: ") + "</b>"+ mToolTipText; 237 mToolTipText = "<b>" + i18n("Journal: ") + "</b>"+ mToolTipText;
238 mToolTip.append( mToolTipText ); 238 mToolTip.append( mToolTipText );
239 j = j_list.next(); 239 j = j_list.next();
240 } 240 }
241 } 241 }
242 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); 242 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>");
243} 243}
244 244
245 245
246QString KODayMatrix::deTag( QString mToolTipText ) 246QString KODayMatrix::deTag( QString mToolTipText )
247{ 247{
248 248
249#if QT_VERSION >= 0x030000 249#if QT_VERSION >= 0x030000
250 mToolTipText.replace( '<' , "&lt;" ); 250 mToolTipText.replace( '<' , "&lt;" );
251 mToolTipText.replace( '>' , "&gt;" ); 251 mToolTipText.replace( '>' , "&gt;" );
252#else 252#else
253 if ( mToolTipText.find ('<') >= 0 ) { 253 if ( mToolTipText.find ('<') >= 0 ) {
254 mToolTipText.replace( QRegExp("<") , "&lt;" ); 254 mToolTipText.replace( QRegExp("<") , "&lt;" );
255 } 255 }
256 if ( mToolTipText.find ('>') >= 0 ) { 256 if ( mToolTipText.find ('>') >= 0 ) {
257 mToolTipText.replace( QRegExp(">") , "&gt;" ); 257 mToolTipText.replace( QRegExp(">") , "&gt;" );
258 } 258 }
259#endif 259#endif
260 return mToolTipText; 260 return mToolTipText;
261} 261}
262void KODayMatrix::setCalendar( Calendar *cal ) 262void KODayMatrix::setCalendar( Calendar *cal )
263{ 263{
264 mCalendar = cal; 264 mCalendar = cal;
265 265
266 setAcceptDrops( mCalendar ); 266 setAcceptDrops( mCalendar );
267 267
268 updateEvents(); 268 updateEvents();
269} 269}
270 270
271QColor KODayMatrix::getShadedColor(QColor color) 271QColor KODayMatrix::getShadedColor(QColor color)
272{ 272{
273 QColor shaded; 273 QColor shaded;
274 int h=0; 274 int h=0;
275 int s=0; 275 int s=0;
276 int v=0; 276 int v=0;
277 color.hsv(&h,&s,&v); 277 color.hsv(&h,&s,&v);
278 s = s/4; 278 s = s/4;
279 v = 192+v/4; 279 v = 192+v/4;
280 shaded.setHsv(h,s,v); 280 shaded.setHsv(h,s,v);
281 281
282 return shaded; 282 return shaded;
283} 283}
284 284
285KODayMatrix::~KODayMatrix() 285KODayMatrix::~KODayMatrix()
286{ 286{
287#if QT_VERSION >= 0x030000 287#if QT_VERSION >= 0x030000
288 288
289#else 289#else
290 delete mKODaymatrixWhatsThis; 290 delete mKODaymatrixWhatsThis;
291#endif 291#endif
292 292
293 // delete mKODaymatrixWhatsThis; 293 // delete mKODaymatrixWhatsThis;
294 delete [] days; 294 delete [] days;
295 delete [] daylbls; 295 delete [] daylbls;
296 //delete [] events; 296 //delete [] events;
297 delete mToolTip; 297 delete mToolTip;
298} 298}
299 299
300/* 300/*
301void KODayMatrix::setStartDate(QDate start) 301void KODayMatrix::setStartDate(QDate start)
302{ 302{
303 updateView(start); 303 updateView(start);
304} 304}
305*/ 305*/
306 306
307void KODayMatrix::addSelectedDaysTo(DateList& selDays) 307void KODayMatrix::addSelectedDaysTo(DateList& selDays)
308{ 308{
309 309
310 if (mSelStart == NOSELECTION) { 310 if (mSelStart == NOSELECTION) {
311 return; 311 return;
312 } 312 }
313 313
314 //cope with selection being out of matrix limits at top (< 0) 314 //cope with selection being out of matrix limits at top (< 0)
315 int i0 = mSelStart; 315 int i0 = mSelStart;
316 if (i0 < 0) { 316 if (i0 < 0) {
317 for (int i = i0; i < 0; i++) { 317 for (int i = i0; i < 0; i++) {
318 selDays.append(days[0].addDays(i)); 318 selDays.append(days[0].addDays(i));
319 } 319 }
320 i0 = 0; 320 i0 = 0;
321 } 321 }
322 322
323 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) 323 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1)
324 if (mSelEnd > NUMDAYS-1) { 324 if (mSelEnd > NUMDAYS-1) {
325 for (int i = i0; i <= NUMDAYS-1; i++) { 325 for (int i = i0; i <= NUMDAYS-1; i++) {
326 selDays.append(days[i]); 326 selDays.append(days[i]);
327 } 327 }
328 for (int i = NUMDAYS; i < mSelEnd; i++) { 328 for (int i = NUMDAYS; i < mSelEnd; i++) {
329 selDays.append(days[0].addDays(i)); 329 selDays.append(days[0].addDays(i));
330 } 330 }
331 331
332 // apply normal routine to selection being entirely within matrix limits 332 // apply normal routine to selection being entirely within matrix limits
333 } else { 333 } else {
334 for (int i = i0; i <= mSelEnd; i++) { 334 for (int i = i0; i <= mSelEnd; i++) {
335 selDays.append(days[i]); 335 selDays.append(days[i]);
336 } 336 }
337 } 337 }
338} 338}
339 339
340bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) 340bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
341{ 341{
342 mRedrawNeeded = true; 342 mRedrawNeeded = true;
343 bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION ); 343 bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION );
344 mSelStart = startdate.daysTo(start); 344 mSelStart = startdate.daysTo(start);
345 if ( mSelStart < 0 ) 345 if ( mSelStart < 0 )
346 mSelStart = 0; 346 mSelStart = 0;
347 mSelEnd = startdate.daysTo(end); 347 mSelEnd = startdate.daysTo(end);
348 if ( mSelEnd > NUMDAYS-1 ) 348 if ( mSelEnd > NUMDAYS-1 )
349 mSelEnd = NUMDAYS-1; 349 mSelEnd = NUMDAYS-1;
350 if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) { 350 if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) {
351 clearSelection(); 351 clearSelection();
352 if ( noSel ) 352 if ( noSel )
353 return false; 353 return false;
354 } 354 }
355 355
356 return true; 356 return true;
357} 357}
358void KODayMatrix::clearSelection() 358void KODayMatrix::clearSelection()
359{ 359{
360 mSelEnd = mSelStart = NOSELECTION; 360 mSelEnd = mSelStart = NOSELECTION;
361} 361}
362 362
363 363
364void KODayMatrix::recalculateToday() 364void KODayMatrix::recalculateToday()
365{ 365{
366 today = -1; 366 today = -1;
367 for (int i=0; i<NUMDAYS; i++) { 367 for (int i=0; i<NUMDAYS; i++) {
368 //events[i] = 0; 368 //events[i] = 0;
369 days[i] = startdate.addDays(i); 369 days[i] = startdate.addDays(i);
370 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); 370 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
371 371
372 // if today is in the currently displayed month, hilight today 372 // if today is in the currently displayed month, hilight today
373 if (days[i].year() == QDate::currentDate().year() && 373 if (days[i].year() == QDate::currentDate().year() &&
374 days[i].month() == QDate::currentDate().month() && 374 days[i].month() == QDate::currentDate().month() &&
375 days[i].day() == QDate::currentDate().day()) { 375 days[i].day() == QDate::currentDate().day()) {
376 today = i; 376 today = i;
377 } 377 }
378 } 378 }
379 // qDebug(QString("Today is visible at %1.").arg(today)); 379 // qDebug(QString("Today is visible at %1.").arg(today));
380} 380}
381 381
382void KODayMatrix::updateView() 382void KODayMatrix::updateView()
383{ 383{
384 updateView(startdate); 384 updateView(startdate);
385} 385}
386void KODayMatrix::repaintViewTimed() 386void KODayMatrix::repaintViewTimed()
387{ 387{
388 mRedrawNeeded = true; 388 mRedrawNeeded = true;
389 // bDays.fill( false); 389 // bDays.fill( false);
390 //pDays.fill( false); 390 //pDays.fill( false);
391 //hDays.fill( false); 391 //hDays.fill( false);
392 //eDays.fill( false); 392 //eDays.fill( false);
393 mRepaintTimer->stop(); 393 mRepaintTimer->stop();
394 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday 394 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday
395 int i; 395 int i;
396 for(i = 0; i < NUMDAYS; i++) { 396 for(i = 0; i < NUMDAYS; i++) {
397 if ( ( (i+startDay) % 7 == 0 ) ) { 397 if ( ( (i+startDay) % 7 == 0 ) ) {
398 pDays.setBit(i); 398 pDays.setBit(i);
399 } 399 }
400 } 400 }
401 repaint(false); 401 repaint(false);
402} 402}
403void KODayMatrix::computeEvent(Event *event, int i ) 403void KODayMatrix::computeEvent(Event *event, int i )
404{ 404{
405 QString holiStr = mHolidays[i]; 405 QString holiStr = mHolidays[i];
406 if ( event->isHoliday()) { 406 if ( event->isHoliday()) {
407 pDays.setBit(i); 407 pDays.setBit(i);
408 hDays.setBit(i); 408 hDays.setBit(i);
409 if ( !holiStr.isEmpty() ) 409 if ( !holiStr.isEmpty() )
410 holiStr += "\n"; 410 holiStr += "\n";
411 holiStr += event->summary(); 411 holiStr += event->summary();
412 if ( !event->location().isEmpty() ) 412 if ( !event->location().isEmpty() )
413 holiStr += " (" + event->location() + ")"; 413 holiStr += " (" + event->location() + ")";
414 mHolidays[i] =holiStr ; 414 mHolidays[i] =holiStr ;
415 eDays.setBit(i); 415 eDays.setBit(i);
416 } 416 }
417 if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_T_VIEW && KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) { 417 if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_T_VIEW && KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) {
418 if ( event->isBirthday()) { 418 if ( event->isBirthday()) {
419 pDays.setBit(i); 419 pDays.setBit(i);
420 if ( !holiStr.isEmpty() ) 420 if ( !holiStr.isEmpty() )
421 holiStr += "\n"; 421 holiStr += "\n";
422 holiStr += i18n("Birthday") + ": "+event->summary(); 422 holiStr += i18n("Birthday") + ": "+event->summary();
423 if ( !event->location().isEmpty() ) 423 if ( !event->location().isEmpty() )
424 holiStr += " (" + event->location() + ")"; 424 holiStr += " (" + event->location() + ")";
425 bDays.setBit(i); 425 bDays.setBit(i);
426 mHolidays[i] =holiStr ; 426 mHolidays[i] =holiStr ;
427 } 427 }
428 } 428 }
429 if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) 429 if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW )
430 eDays.setBit(i); 430 eDays.setBit(i);
431} 431}
432void KODayMatrix::updateViewTimed() 432void KODayMatrix::updateViewTimed()
433{ 433{
434 mUpdateTimer->stop(); 434 mUpdateTimer->stop();
435 if ( !mCalendar ) { 435 if ( !mCalendar ) {
436 qDebug("NOT CAL "); 436 qDebug("NOT CAL ");
437 return; 437 return;
438 } 438 }
439#if 1 439#if 1
440 440
441 441
442 int i; 442 int i;
443 int timeSpan = NUMDAYS-1; 443 int timeSpan = NUMDAYS-1;
444 QPtrList<Event> events = mCalendar->events(); 444 QPtrList<Event> events = mCalendar->events();
445 Event *event; 445 Event *event;
446 QDateTime dt; 446 QDateTime dt;
447 bool ok; 447 bool ok;
448 bDays.fill( false); 448 bDays.fill( false);
449 pDays.fill( false); 449 pDays.fill( false);
450 hDays.fill( false); 450 hDays.fill( false);
451 eDays.fill( false); 451 eDays.fill( false);
452 mHolidays.clear(); 452 mHolidays.clear();
453 QDate mStartDate = days[0]; 453 QDate mStartDate = days[0];
454 QDate endDate = mStartDate.addDays( timeSpan ); 454 QDate endDate = mStartDate.addDays( timeSpan );
455 for( event = events.first(); event; event = events.next() ) { // for event 455 for( event = events.first(); event; event = events.next() ) { // for event
456 ushort recurType = event->doesRecur(); 456 ushort recurType = event->doesRecur();
457 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 457 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
458 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 458 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
459 continue; 459 continue;
460 } 460 }
461 if ( !KOPrefs::instance()->mLongAllday && event->doesFloat()&& event->isMultiDay() ) { 461 if ( !KOPrefs::instance()->mLongAllday && event->doesFloat()&& event->isMultiDay() ) {
462 continue; 462 continue;
463 } 463 }
464 if ( event->doesRecur() ) { 464 if ( event->doesRecur() ) {
465 bool last; 465 bool last;
466 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); 466 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last );
467 QDateTime incidenceEnd; 467 QDateTime incidenceEnd;
468 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); 468 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() );
469 bool invalid = false; 469 bool invalid = false;
470 while( true ) { 470 while( true ) {
471 if ( incidenceStart.isValid() ) { 471 if ( incidenceStart.isValid() ) {
472 incidenceEnd = incidenceStart.addDays( eventlen ); 472 incidenceEnd = incidenceStart.addDays( eventlen );
473 int st = incidenceStart.date().daysTo( endDate ); 473 int st = incidenceStart.date().daysTo( endDate );
474 if ( st >= 0 ) { // start before timeend 474 if ( st >= 0 ) { // start before timeend
475 int end = mStartDate.daysTo( incidenceEnd.date() ); 475 int end = mStartDate.daysTo( incidenceEnd.date() );
476 if ( end >= 0 ) { // end after timestart --- got one! 476 if ( end >= 0 ) { // end after timestart --- got one!
477 //normalize 477 //normalize
478 st = timeSpan - st; 478 st = timeSpan - st;
479 if ( st < 0 ) st = 0; 479 if ( st < 0 ) st = 0;
480 if ( end > timeSpan ) end = timeSpan; 480 if ( end > timeSpan ) end = timeSpan;
481 int iii; 481 int iii;
482 //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); 482 //qDebug("found %s %d %d ",event->summary().latin1(), st, end );
483 for ( iii = st;iii<= end;++iii) { 483 for ( iii = st;iii<= end;++iii) {
484 computeEvent( event, iii ); 484 computeEvent( event, iii );
485 } 485 }
486 } 486 }
487 } 487 }
488 } else { 488 } else {
489 if ( invalid ) 489 if ( invalid )
490 break; 490 break;
491 invalid = true; 491 invalid = true;
492 //qDebug("invalid %s", event->summary().latin1()); 492 //qDebug("invalid %s", event->summary().latin1());
493 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; 493 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );;
494 } 494 }
495 if ( last ) 495 if ( last )
496 break; 496 break;
497 bool ok; 497 bool ok;
498 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); 498 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok );
499 if ( ! ok ) 499 if ( ! ok )
500 break; 500 break;
501 if ( incidenceStart.date() > endDate ) 501 if ( incidenceStart.date() > endDate )
502 break; 502 break;
503 } 503 }
504 } else { // no recur 504 } else { // no recur
505 int st = event->dtStart().date().daysTo( endDate ); 505 int st = event->dtStart().date().daysTo( endDate );
506 if ( st >= 0 ) { // start before timeend 506 if ( st >= 0 ) { // start before timeend
507 int end = mStartDate.daysTo( event->dtEnd().date() ); 507 int end = mStartDate.daysTo( event->dtEnd().date() );
508 if ( end >= 0 ) { // end after timestart --- got one! 508 if ( end >= 0 ) { // end after timestart --- got one!
509 //normalize 509 //normalize
510 st = timeSpan - st; 510 st = timeSpan - st;
511 if ( st < 0 ) st = 0; 511 if ( st < 0 ) st = 0;
512 if ( end > timeSpan ) end = timeSpan; 512 if ( end > timeSpan ) end = timeSpan;
513 int iii; 513 int iii;
514 for ( iii = st;iii<= end;++iii) 514 for ( iii = st;iii<= end;++iii)
515 computeEvent( event, iii ); 515 computeEvent( event, iii );
516 } 516 }
517 } 517 }
518 } 518 }
519 } 519 }
520 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday 520 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday
521 for(i = 0; i < NUMDAYS; i++) { 521 for(i = 0; i < NUMDAYS; i++) {
522 if ( ( (i+startDay) % 7 == 0 ) ) { 522 if ( ( (i+startDay) % 7 == 0 ) ) {
523 pDays.setBit(i); 523 pDays.setBit(i);
524 } 524 }
525 } 525 }
526 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { 526 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) {
527 bDays.fill( false); 527 bDays.fill( false);
528 // insert due todos 528 // insert due todos
529 QPtrList<Todo> todos = mCalendar->todos( ); 529 QPtrList<Todo> todos = mCalendar->todos( );
530 Todo *todo; 530 Todo *todo;
531 for(todo = todos.first(); todo; todo = todos.next()) { 531 for(todo = todos.first(); todo; todo = todos.next()) {
532 //insertTodo( todo ); 532 //insertTodo( todo );
533 if ( todo->hasDueDate() ) { 533 if ( todo->hasDueDate() ) {
534 int day = mStartDate.daysTo( todo->dtDue().date() ); 534 int day = mStartDate.daysTo( todo->dtDue().date() );
535 if ( day >= 0 && day < timeSpan + 1) { 535 if ( day >= 0 && day < timeSpan + 1) {
536 int i = day; 536 int i = day;
537 QString holiStr = mHolidays[i]; 537 QString holiStr = mHolidays[i];
538 pDays.setBit(i); 538 pDays.setBit(i);
539 if ( !holiStr.isEmpty() ) 539 if ( !holiStr.isEmpty() )
540 holiStr += "\n"; 540 holiStr += "\n";
541 holiStr += i18n("Todo") + ": "+todo->summary(); 541 holiStr += i18n("Todo") + ": "+todo->summary();
542 if ( !todo->location().isEmpty() ) 542 if ( !todo->location().isEmpty() )
543 holiStr += " (" + todo->location() + ")"; 543 holiStr += " (" + todo->location() + ")";
544 bDays.setBit(i); 544 bDays.setBit(i);
545 mHolidays[i] =holiStr ; 545 mHolidays[i] =holiStr ;
546 eDays.setBit(i); 546 eDays.setBit(i);
547 } 547 }
548 } 548 }
549 } 549 }
550 } 550 }
551 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { 551 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) {
552 bDays.fill( false); 552 bDays.fill( false);
553 // insert due todos 553 // insert due todos
554 QPtrList<Journal> todos = mCalendar->journals( ); 554 QPtrList<Journal> todos = mCalendar->journals( );
555 Journal *todo; 555 Journal *todo;
556 for(todo = todos.first(); todo; todo = todos.next()) { 556 for(todo = todos.first(); todo; todo = todos.next()) {
557 int day = mStartDate.daysTo( todo->dtStart().date() ); 557 int day = mStartDate.daysTo( todo->dtStart().date() );
558 if ( day >= 0 && day < timeSpan + 1) { 558 if ( day >= 0 && day < timeSpan + 1) {
559 int i = day; 559 int i = day;
560 QString holiStr = mHolidays[i]; 560 QString holiStr = mHolidays[i];
561 pDays.setBit(i); 561 pDays.setBit(i);
562 if ( !holiStr.isEmpty() ) 562 if ( !holiStr.isEmpty() )
563 holiStr += "\n"; 563 holiStr += "\n";
564 holiStr += i18n("Journal: ")+todo->summary().left(25); 564 holiStr += i18n("Journal: ")+todo->summary().left(25);
565 if ( todo->summary().length() > 25 ) 565 if ( todo->summary().length() > 25 )
566 holiStr +="..."; 566 holiStr +="...";
567 bDays.setBit(i); 567 bDays.setBit(i);
568 mHolidays[i] =holiStr ; 568 mHolidays[i] =holiStr ;
569 eDays.setBit(i); 569 eDays.setBit(i);
570 570
571 } 571 }
572 } 572 }
573 } 573 }
574#else 574#else
575 //qDebug("KODayMatrix::updateViewTimed "); 575 //qDebug("KODayMatrix::updateViewTimed ");
576 for(int i = 0; i < NUMDAYS; i++) { 576 for(int i = 0; i < NUMDAYS; i++) {
577 // if events are set for the day then remember to draw it bold 577 // if events are set for the day then remember to draw it bold
578 QPtrList<Event> eventlist = mCalendar->events(days[i]); 578 QPtrList<Event> eventlist = mCalendar->events(days[i]);
579 Event *event; 579 Event *event;
580 int numEvents = eventlist.count(); 580 int numEvents = eventlist.count();
581 QString holiStr = ""; 581 QString holiStr = "";
582 bDays.clearBit(i); 582 bDays.clearBit(i);
583 hDays.clearBit(i); 583 hDays.clearBit(i);
584 eDays.clearBit(i); 584 eDays.clearBit(i);
585 for(event=eventlist.first();event != 0;event=eventlist.next()) { 585 for(event=eventlist.first();event != 0;event=eventlist.next()) {
586 ushort recurType = event->recurrence()->doesRecur(); 586 ushort recurType = event->recurrence()->doesRecur();
587 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 587 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
588 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 588 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
589 numEvents--; 589 numEvents--;
590 } 590 }
591 if ( event->isHoliday()) { 591 if ( event->isHoliday()) {
592 hDays.setBit(i); 592 hDays.setBit(i);
593 if ( !holiStr.isEmpty() ) 593 if ( !holiStr.isEmpty() )
594 holiStr += "\n"; 594 holiStr += "\n";
595 holiStr += event->summary(); 595 holiStr += event->summary();
596 if ( !event->location().isEmpty() ) 596 if ( !event->location().isEmpty() )
597 holiStr += " (" + event->location() + ")"; 597 holiStr += " (" + event->location() + ")";
598 } 598 }
599 if ( event->isBirthday()) { 599 if ( event->isBirthday()) {
600 if ( !holiStr.isEmpty() ) 600 if ( !holiStr.isEmpty() )
601 holiStr += "\n"; 601 holiStr += "\n";
602 holiStr += i18n("Birthday") + ": "+event->summary(); 602 holiStr += i18n("Birthday") + ": "+event->summary();
603 if ( !event->location().isEmpty() ) 603 if ( !event->location().isEmpty() )
604 holiStr += " (" + event->location() + ")"; 604 holiStr += " (" + event->location() + ")";
605 bDays.setBit(i); 605 bDays.setBit(i);
606 } 606 }
607 } 607 }
608 if ( numEvents ) 608 if ( numEvents )
609 eDays.setBit(i); 609 eDays.setBit(i);
610 //if it is a holy day then draw it red. Sundays are consider holidays, too 610 //if it is a holy day then draw it red. Sundays are consider holidays, too
611 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || 611 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) ||
612 !holiStr.isEmpty()) { 612 !holiStr.isEmpty()) {
613 mHolidays[i] = holiStr; 613 mHolidays[i] = holiStr;
614 } else { 614 } else {
615 mHolidays[i] = QString::null; 615 mHolidays[i] = QString::null;
616 } 616 }
617 } 617 }
618#endif 618#endif
619 mRedrawNeeded = true; 619 mRedrawNeeded = true;
620 if ( ! mPendingUpdateBeforeRepaint ) 620 if ( ! mPendingUpdateBeforeRepaint )
621 repaint(false); 621 repaint(false);
622} 622}
623void KODayMatrix::updateView(QDate actdate) 623void KODayMatrix::updateView(QDate actdate)
624{ 624{
625 if ( mLastView != KOPrefs::instance()->mCurrentDisplayedView ) 625 if ( mLastView != KOPrefs::instance()->mCurrentDisplayedView )
626 mRedrawNeeded = true; 626 mRedrawNeeded = true;
627 mLastView = KOPrefs::instance()->mCurrentDisplayedView; 627 mLastView = KOPrefs::instance()->mCurrentDisplayedView;
628 if ( ! actdate.isValid() ) { 628 if ( ! actdate.isValid() ) {
629 //qDebug("date not valid "); 629 //qDebug("date not valid ");
630 return; 630 return;
631 } 631 }
632 mDayChanged = false; 632 mDayChanged = false;
633 //flag to indicate if the starting day of the matrix has changed by this call 633 //flag to indicate if the starting day of the matrix has changed by this call
634 //mDayChanged = false; 634 //mDayChanged = false;
635 // if a new startdate is to be set then apply Cornelius's calculation 635 // if a new startdate is to be set then apply Cornelius's calculation
636 // of the first day to be shown 636 // of the first day to be shown
637 if (actdate != startdate) { 637 if (actdate != startdate) {
638 // reset index of selection according to shift of starting date from startdate to actdate 638 // reset index of selection according to shift of starting date from startdate to actdate
639 if (mSelStart != NOSELECTION) { 639 if (mSelStart != NOSELECTION) {
640 int tmp = actdate.daysTo(startdate); 640 int tmp = actdate.daysTo(startdate);
641 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; 641 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl;
642 // shift selection if new one would be visible at least partly ! 642 // shift selection if new one would be visible at least partly !
643 643
644 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { 644 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) {
645 // nested if is required for next X display pushed from a different month - correction required 645 // nested if is required for next X display pushed from a different month - correction required
646 // otherwise, for month forward and backward, it must be avoided 646 // otherwise, for month forward and backward, it must be avoided
647 if( mSelStart > NUMDAYS || mSelStart < 0 ) 647 if( mSelStart > NUMDAYS || mSelStart < 0 )
648 mSelStart = mSelStart + tmp; 648 mSelStart = mSelStart + tmp;
649 if( mSelEnd > NUMDAYS || mSelEnd < 0 ) 649 if( mSelEnd > NUMDAYS || mSelEnd < 0 )
650 mSelEnd = mSelEnd + tmp; 650 mSelEnd = mSelEnd + tmp;
651 } 651 }
652 } 652 }
653 startdate = actdate; 653 startdate = actdate;
654 mDayChanged = true; 654 mDayChanged = true;
655 recalculateToday(); 655 recalculateToday();
656 mRedrawNeeded = true; 656 mRedrawNeeded = true;
657 } 657 }
658 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); 658 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() );
659 if ( !isVisible() ) { 659 if ( !isVisible() ) {
660 mPendingUpdateBeforeRepaint = true; 660 mPendingUpdateBeforeRepaint = true;
661 } else { 661 } else {
662#ifdef DESKTOP_VERSION 662#ifdef DESKTOP_VERSION
663 //mRepaintTimer->start( 100 ); 663 //mRepaintTimer->start( 100 );
664 //updateViewTimed(); 664 //updateViewTimed();
665 mUpdateTimer->start( 50 ); 665 mUpdateTimer->start( 50 );
666#else 666#else
667 mRepaintTimer->start( 350 ); 667 mRepaintTimer->start( 250 );
668 mUpdateTimer->start( 800 ); 668 mUpdateTimer->start( 500 );
669#endif 669#endif
670 } 670 }
671} 671}
672void KODayMatrix::updateEvents() 672void KODayMatrix::updateEvents()
673{ 673{
674 if ( !mCalendar ) return; 674 if ( !mCalendar ) return;
675 675
676 for( int i = 0; i < NUMDAYS; i++ ) { 676 for( int i = 0; i < NUMDAYS; i++ ) {
677 // if events are set for the day then remember to draw it bold 677 // if events are set for the day then remember to draw it bold
678 QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); 678 QPtrList<Event> eventlist = mCalendar->events( days[ i ] );
679 int numEvents = eventlist.count(); 679 int numEvents = eventlist.count();
680 Event *event; 680 Event *event;
681 for( event = eventlist.first(); event != 0;event=eventlist.next()) { 681 for( event = eventlist.first(); event != 0;event=eventlist.next()) {
682 ushort recurType = event->doesRecur(); 682 ushort recurType = event->doesRecur();
683 683
684 if ( ( recurType == Recurrence::rDaily && 684 if ( ( recurType == Recurrence::rDaily &&
685 !KOPrefs::instance()->mDailyRecur ) || 685 !KOPrefs::instance()->mDailyRecur ) ||
686 ( recurType == Recurrence::rWeekly && 686 ( recurType == Recurrence::rWeekly &&
687 !KOPrefs::instance()->mWeeklyRecur ) ) { 687 !KOPrefs::instance()->mWeeklyRecur ) ) {
688 numEvents--; 688 numEvents--;
689 } 689 }
690 if ( !KOPrefs::instance()->mLongAllday && event->doesFloat()&& event->isMultiDay() ) { 690 if ( !KOPrefs::instance()->mLongAllday && event->doesFloat()&& event->isMultiDay() ) {
691 numEvents--; 691 numEvents--;
692 } 692 }
693 } 693 }
694 if ( numEvents ) 694 if ( numEvents )
695 eDays.setBit(i); 695 eDays.setBit(i);
696 else 696 else
697 eDays.clearBit(i); 697 eDays.clearBit(i);
698 } 698 }
699} 699}
700 700
701const QDate& KODayMatrix::getDate(int offset) 701const QDate& KODayMatrix::getDate(int offset)
702{ 702{
703 if (offset < 0 || offset > NUMDAYS-1) { 703 if (offset < 0 || offset > NUMDAYS-1) {
704 qDebug("Wrong offset2 %d", offset); 704 qDebug("Wrong offset2 %d", offset);
705 return days[0]; 705 return days[0];
706 } 706 }
707 return days[offset]; 707 return days[offset];
708} 708}
709 709
710QString KODayMatrix::getHolidayLabel(int offset) 710QString KODayMatrix::getHolidayLabel(int offset)
711{ 711{
712 if (offset < 0 || offset > NUMDAYS-1) { 712 if (offset < 0 || offset > NUMDAYS-1) {
713 qDebug("Wrong offset1 %d", offset); 713 qDebug("Wrong offset1 %d", offset);
714 return QString(); 714 return QString();
715 } 715 }
716 return mHolidays[offset]; 716 return mHolidays[offset];
717} 717}
718 718
719int KODayMatrix::getDayIndexFrom(int x, int y) 719int KODayMatrix::getDayIndexFrom(int x, int y)
720{ 720{
721 int colModulo = (width()-2) % 7; 721 int colModulo = (width()-2) % 7;
722 int rowModulo = (height()-2) % 6; 722 int rowModulo = (height()-2) % 6;
723#if 0 723#if 0
724 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? 724 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
725 6 - x/daysize.width() : x/daysize.width()); 725 6 - x/daysize.width() : x/daysize.width());
726#endif 726#endif
727 int xVal = (x-colModulo/2-2)/daysize.width(); 727 int xVal = (x-colModulo/2-2)/daysize.width();
728 int yVal = (y-rowModulo/2-2)/daysize.height(); 728 int yVal = (y-rowModulo/2-2)/daysize.height();
729 729
730 730
731 return 7*(yVal) + xVal; 731 return 7*(yVal) + xVal;
732 732
733} 733}
734 734
735// ---------------------------------------------------------------------------- 735// ----------------------------------------------------------------------------
736// M O U S E E V E N T H A N D L I N G 736// M O U S E E V E N T H A N D L I N G
737// ---------------------------------------------------------------------------- 737// ----------------------------------------------------------------------------
738 738
739void KODayMatrix::mousePressEvent (QMouseEvent* e) 739void KODayMatrix::mousePressEvent (QMouseEvent* e)
740{ 740{
741 741
742 if ( e->button() == LeftButton ) 742 if ( e->button() == LeftButton )
743 mouseDown = true; 743 mouseDown = true;
744 mSelStart = getDayIndexFrom(e->x(), e->y()); 744 mSelStart = getDayIndexFrom(e->x(), e->y());
745 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; 745 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1;
746 mSelInit = mSelStart; 746 mSelInit = mSelStart;
747 mSelEnd = mSelStart; 747 mSelEnd = mSelStart;
748 mRedrawNeeded = true; 748 mRedrawNeeded = true;
749 repaint(false); 749 repaint(false);
750} 750}
751 751
752void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) 752void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
753{ 753{
754 mRedrawNeeded = true; 754 mRedrawNeeded = true;
755 if ( e->button() == LeftButton ) 755 if ( e->button() == LeftButton )
756 if ( ! mouseDown ) { 756 if ( ! mouseDown ) {
757 return; 757 return;
758 } 758 }
759 else 759 else
760 mouseDown = false; 760 mouseDown = false;
761 int tmp = getDayIndexFrom(e->x(), e->y()); 761 int tmp = getDayIndexFrom(e->x(), e->y());
762 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 762 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
763 763
764 if (mSelInit > tmp) { 764 if (mSelInit > tmp) {
765 mSelEnd = mSelInit; 765 mSelEnd = mSelInit;
766 if (tmp != mSelStart) { 766 if (tmp != mSelStart) {
767 mSelStart = tmp; 767 mSelStart = tmp;
768 repaint(false); 768 repaint(false);
769 } 769 }
770 } else { 770 } else {
771 mSelStart = mSelInit; 771 mSelStart = mSelInit;
772 772
773 //repaint only if selection has changed 773 //repaint only if selection has changed
774 if (tmp != mSelEnd) { 774 if (tmp != mSelEnd) {
775 mSelEnd = tmp; 775 mSelEnd = tmp;
776 repaint(false); 776 repaint(false);
777 } 777 }
778 } 778 }
779 779
780 DateList daylist; 780 DateList daylist;
781 if ( mSelStart < 0 ) 781 if ( mSelStart < 0 )
782 mSelStart = 0; 782 mSelStart = 0;
783 for (int i = mSelStart; i <= mSelEnd; i++) { 783 for (int i = mSelStart; i <= mSelEnd; i++) {
784 daylist.append(days[i]); 784 daylist.append(days[i]);
785 } 785 }
786 emit selected((const DateList)daylist); 786 emit selected((const DateList)daylist);
787 787
788} 788}
789 789
790void KODayMatrix::mouseMoveEvent (QMouseEvent* e) 790void KODayMatrix::mouseMoveEvent (QMouseEvent* e)
791{ 791{
792 if ( ! mouseDown ) { 792 if ( ! mouseDown ) {
793 return; 793 return;
794 } 794 }
795 mRedrawNeeded = true; 795 mRedrawNeeded = true;
796 int tmp = getDayIndexFrom(e->x(), e->y()); 796 int tmp = getDayIndexFrom(e->x(), e->y());
797 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 797 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
798 798
799 if (mSelInit > tmp) { 799 if (mSelInit > tmp) {
800 mSelEnd = mSelInit; 800 mSelEnd = mSelInit;
801 if (tmp != mSelStart) { 801 if (tmp != mSelStart) {
802 mSelStart = tmp; 802 mSelStart = tmp;
803 repaint(false); 803 repaint(false);
804 } 804 }
805 } else { 805 } else {
806 mSelStart = mSelInit; 806 mSelStart = mSelInit;
807 807
808 //repaint only if selection has changed 808 //repaint only if selection has changed
809 if (tmp != mSelEnd) { 809 if (tmp != mSelEnd) {
810 mSelEnd = tmp; 810 mSelEnd = tmp;
811 repaint(false); 811 repaint(false);
812 } 812 }
813 } 813 }
814} 814}
815 815
816// ---------------------------------------------------------------------------- 816// ----------------------------------------------------------------------------
817// D R A G ' N D R O P H A N D L I N G 817// D R A G ' N D R O P H A N D L I N G
818// ---------------------------------------------------------------------------- 818// ----------------------------------------------------------------------------
819 819
820void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) 820void KODayMatrix::dragEnterEvent(QDragEnterEvent *e)
821{ 821{
822#ifndef KORG_NODND 822#ifndef KORG_NODND
823 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 823 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
824 e->ignore(); 824 e->ignore();
825 return; 825 return;
826 } 826 }
827 827
828 // some visual feedback 828 // some visual feedback
829// oldPalette = palette(); 829// oldPalette = palette();
830// setPalette(my_HilitePalette); 830// setPalette(my_HilitePalette);
831// update(); 831// update();
832#endif 832#endif
833} 833}
834 834
835void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) 835void KODayMatrix::dragMoveEvent(QDragMoveEvent *e)
836{ 836{
837#ifndef KORG_NODND 837#ifndef KORG_NODND
838 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 838 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
839 e->ignore(); 839 e->ignore();
840 return; 840 return;
841 } 841 }
842 842
843 e->accept(); 843 e->accept();
844#endif 844#endif
845} 845}
846 846
847void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) 847void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/)
848{ 848{
849#ifndef KORG_NODND 849#ifndef KORG_NODND
850// setPalette(oldPalette); 850// setPalette(oldPalette);
851// update(); 851// update();
852#endif 852#endif
853} 853}
854 854
855void KODayMatrix::dropEvent(QDropEvent *e) 855void KODayMatrix::dropEvent(QDropEvent *e)
856{ 856{
857#ifndef KORG_NODND 857#ifndef KORG_NODND
858// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; 858// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl;
859 859
860 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 860 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
861 e->ignore(); 861 e->ignore();
862 return; 862 return;
863 } 863 }
864 864
865 DndFactory factory( mCalendar ); 865 DndFactory factory( mCalendar );
866 Event *event = factory.createDrop(e); 866 Event *event = factory.createDrop(e);
867 867
868 if (event) { 868 if (event) {
869 e->acceptAction(); 869 e->acceptAction();
870 870
871 Event *existingEvent = mCalendar->event(event->uid()); 871 Event *existingEvent = mCalendar->event(event->uid());
872 872
873 if(existingEvent) { 873 if(existingEvent) {
874 // uniquify event 874 // uniquify event
875 event->recreate(); 875 event->recreate();
876/* 876/*
877 KMessageBox::sorry(this, 877 KMessageBox::sorry(this,
878 i18n("Event already exists in this calendar."), 878 i18n("Event already exists in this calendar."),
879 i18n("Drop Event")); 879 i18n("Drop Event"));
880 delete event; 880 delete event;
881 return; 881 return;
882*/ 882*/
883 } 883 }
884// kdDebug() << "Drop new Event" << endl; 884// kdDebug() << "Drop new Event" << endl;
885 // Adjust date 885 // Adjust date
886 QDateTime start = event->dtStart(); 886 QDateTime start = event->dtStart();
887 QDateTime end = event->dtEnd(); 887 QDateTime end = event->dtEnd();
888 int duration = start.daysTo(end); 888 int duration = start.daysTo(end);
889 int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); 889 int idx = getDayIndexFrom(e->pos().x(), e->pos().y());
890 890
891 start.setDate(days[idx]); 891 start.setDate(days[idx]);
892 end.setDate(days[idx].addDays(duration)); 892 end.setDate(days[idx].addDays(duration));
893 893
894 event->setDtStart(start); 894 event->setDtStart(start);
895 event->setDtEnd(end); 895 event->setDtEnd(end);
896 mCalendar->addEvent(event); 896 mCalendar->addEvent(event);
897 897
898 emit eventDropped(event); 898 emit eventDropped(event);
899 } else { 899 } else {
900// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; 900// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl;
901 e->ignore(); 901 e->ignore();
902 } 902 }
903#endif 903#endif
904} 904}
905 905
906// ---------------------------------------------------------------------------- 906// ----------------------------------------------------------------------------
907// P A I N T E V E N T H A N D L I N G 907// P A I N T E V E N T H A N D L I N G
908// ---------------------------------------------------------------------------- 908// ----------------------------------------------------------------------------
909 909
910void KODayMatrix::paintEvent(QPaintEvent * pevent) 910void KODayMatrix::paintEvent(QPaintEvent * pevent)
911{ 911{
912 912
913 if ( width() <= 0 || height() <= 0 ) 913 if ( width() <= 0 || height() <= 0 )
914 return; 914 return;
915 if ( mPendingUpdateBeforeRepaint ) { 915 if ( mPendingUpdateBeforeRepaint ) {
916 updateViewTimed(); 916 updateViewTimed();
917 mPendingUpdateBeforeRepaint = false; 917 mPendingUpdateBeforeRepaint = false;
918 } 918 }
919#if 0 919#if 0
920 if ( myPix.width() != width() || myPix.height()!=height() ) { 920 if ( myPix.width() != width() || myPix.height()!=height() ) {
921 myPix.resize(size() ); 921 myPix.resize(size() );
922 mRedrawNeeded = true; 922 mRedrawNeeded = true;
923 } 923 }
924#endif 924#endif
925 if ( oldW != width() || oldH !=height() ) 925 if ( oldW != width() || oldH !=height() )
926 mRedrawNeeded = true; 926 mRedrawNeeded = true;
927 927
928 oldH = height() ; 928 oldH = height() ;
929 oldW = width(); 929 oldW = width();
930 if ( myPix.width() < width() || myPix.height() < height() ) { 930 if ( myPix.width() < width() || myPix.height() < height() ) {
931 myPix.resize(size() ); 931 myPix.resize(size() );
932 mRedrawNeeded = true; 932 mRedrawNeeded = true;
933 933
934 } 934 }
935 935
936 if ( mRedrawNeeded ) { 936 if ( mRedrawNeeded ) {
937 //qDebug("REDRAW "); 937 //qDebug("REDRAW ");
938 QPainter p(&myPix); 938 QPainter p(&myPix);
939 p.setFont(font()); 939 p.setFont(font());
940 940
941 941
942 int dheight = daysize.height(); 942 int dheight = daysize.height();
943 int dwidth = daysize.width(); 943 int dwidth = daysize.width();
944 int row,col; 944 int row,col;
945 int selw, selh; 945 int selw, selh;
946 int xyOff = frameWidth(); 946 int xyOff = frameWidth();
947 int colModulo = (width()-2) % 7; 947 int colModulo = (width()-2) % 7;
948 int rowModulo = (height()-2) % 6; 948 int rowModulo = (height()-2) % 6;
949 //qDebug("col %d row %d ",colModulo,rowModulo ); 949 //qDebug("col %d row %d ",colModulo,rowModulo );
950 950
951 bool isRTL = KOGlobals::self()->reverseLayout(); 951 bool isRTL = KOGlobals::self()->reverseLayout();
952 952
953 // draw background and topleft frame 953 // draw background and topleft frame
954 p.fillRect(0,0,width(),height(), mDefaultBackColor); 954 p.fillRect(0,0,width(),height(), mDefaultBackColor);
955 //p.setPen(mDefaultTextColor); 955 //p.setPen(mDefaultTextColor);
956 //p.drawRect(0, 0, width(), height()); 956 //p.drawRect(0, 0, width(), height());
957 int mSelStartT = mSelStart; 957 int mSelStartT = mSelStart;
958 int mSelEndT = mSelEnd; 958 int mSelEndT = mSelEnd;
959 if ( mSelEndT >= NUMDAYS ) 959 if ( mSelEndT >= NUMDAYS )
960 mSelEndT = NUMDAYS-1; 960 mSelEndT = NUMDAYS-1;
961 // draw selected days with highlighted background color 961 // draw selected days with highlighted background color
962 if (mSelStart != NOSELECTION) { 962 if (mSelStart != NOSELECTION) {
963 bool skip = false; 963 bool skip = false;
964 if ( ! mouseDown ) { 964 if ( ! mouseDown ) {
965 int mo = days[20].month(); 965 int mo = days[20].month();
966 //qDebug("-- %d %d ", mSelStartT, mSelEndT); 966 //qDebug("-- %d %d ", mSelStartT, mSelEndT);
967 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); 967 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() );
968 int startMo = days[mSelStartT].month(); 968 int startMo = days[mSelStartT].month();
969 int endMo = days[mSelEndT].month(); 969 int endMo = days[mSelEndT].month();
970 if ( startMo == 12 && mo == 1 && endMo <= 2 ) 970 if ( startMo == 12 && mo == 1 && endMo <= 2 )
971 startMo = 1; 971 startMo = 1;
972 if ( endMo == 1 && mo == 12 ) 972 if ( endMo == 1 && mo == 12 )
973 endMo = 12; 973 endMo = 12;
974 if ( mo == 12 && startMo == 1 ) 974 if ( mo == 12 && startMo == 1 )
975 startMo = 13; 975 startMo = 13;
976 if ( (startMo > mo || endMo < mo) ) { 976 if ( (startMo > mo || endMo < mo) ) {
977 skip = true; 977 skip = true;
978 } else { 978 } else {
979 if ( days[mSelStartT].month() != mo ) { 979 if ( days[mSelStartT].month() != mo ) {
980 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); 980 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day();
981 mSelStartT += add +1; 981 mSelStartT += add +1;
982 } 982 }
983 if ( days[mSelEndT].month() != mo ) { 983 if ( days[mSelEndT].month() != mo ) {
984 int sub = days[mSelEndT].day(); 984 int sub = days[mSelEndT].day();
985 mSelEndT -= sub ; 985 mSelEndT -= sub ;
986 } 986 }
987 } 987 }
988 } 988 }
989 //qDebug("SKIP %d ", skip); 989 //qDebug("SKIP %d ", skip);
990 if ( ! skip ) { 990 if ( ! skip ) {
991 row = mSelStartT/7; 991 row = mSelStartT/7;
992 col = mSelStartT -row*7; 992 col = mSelStartT -row*7;
993 QColor selcol = KOPrefs::instance()->mHighlightColor; 993 QColor selcol = KOPrefs::instance()->mHighlightColor;
994 int addCol = 0; 994 int addCol = 0;
995 int addRow = 0; 995 int addRow = 0;
996 int addRow2 = 0; 996 int addRow2 = 0;
997 int addCol2 = 0; 997 int addCol2 = 0;
998 if (row == mSelEndT/7) { 998 if (row == mSelEndT/7) {
999 if ( rowModulo ) { 999 if ( rowModulo ) {
1000 if ( row >= 6 - rowModulo ) 1000 if ( row >= 6 - rowModulo )
1001 addRow = row - 5 + rowModulo; 1001 addRow = row - 5 + rowModulo;
1002 } 1002 }
1003 if ( colModulo ) { 1003 if ( colModulo ) {
1004 int colt1 = mSelEndT%7; 1004 int colt1 = mSelEndT%7;
1005 //qDebug("colt1 %d ", colt1 ); 1005 //qDebug("colt1 %d ", colt1 );
1006 if ( colt1 >= 7 - colModulo ) 1006 if ( colt1 >= 7 - colModulo )
1007 addCol = colt1 - 7 + colModulo+1; 1007 addCol = colt1 - 7 + colModulo+1;
1008 int colt = mSelStartT%7; 1008 int colt = mSelStartT%7;
1009 if ( colt >= 7 - colModulo ) 1009 if ( colt >= 7 - colModulo )
1010 addCol2 = colt - 7 + colModulo; 1010 addCol2 = colt - 7 + colModulo;
1011 addCol -= addCol2; 1011 addCol -= addCol2;
1012 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); 1012 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 );
1013 } 1013 }
1014 // Single row selection 1014 // Single row selection
1015 //if ( row == 0) 1015 //if ( row == 0)
1016 // addRow = 1; 1016 // addRow = 1;
1017 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, 1017 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2,
1018 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); 1018 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol);
1019 } else { 1019 } else {
1020 // draw first row to the right 1020 // draw first row to the right
1021 if ( colModulo ) { 1021 if ( colModulo ) {
1022 if ( col >= 7 - colModulo ) 1022 if ( col >= 7 - colModulo )
1023 addCol2 = col - 7 + colModulo; 1023 addCol2 = col - 7 + colModulo;
1024 } 1024 }
1025 if ( rowModulo ) { 1025 if ( rowModulo ) {
1026 if ( row >= 6 - rowModulo ) 1026 if ( row >= 6 - rowModulo )
1027 addRow = row - 5 + rowModulo; 1027 addRow = row - 5 + rowModulo;
1028 } 1028 }
1029 //if ( row == 0) 1029 //if ( row == 0)
1030 // addRow = 1; 1030 // addRow = 1;
1031 int drawWid = width()-(col*dwidth+1+addCol2)-1; 1031 int drawWid = width()-(col*dwidth+1+addCol2)-1;
1032 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, drawWid, 1032 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, drawWid,
1033 dheight+1, selcol); 1033 dheight+1, selcol);
1034 // draw full block till last line 1034 // draw full block till last line
1035 selh = mSelEndT/7-row; 1035 selh = mSelEndT/7-row;
1036 addRow = 0; 1036 addRow = 0;
1037 if ( rowModulo ) { 1037 if ( rowModulo ) {
1038 if ( mSelEndT/7 >= 6 - rowModulo ) 1038 if ( mSelEndT/7 >= 6 - rowModulo )
1039 addRow = mSelEndT/7 - 5 + rowModulo; 1039 addRow = mSelEndT/7 - 5 + rowModulo;
1040 } 1040 }
1041 //qDebug("%d %d %d ",selh, row, addRow ); 1041 //qDebug("%d %d %d ",selh, row, addRow );
1042 int addrow2 = addRow-selh+1; 1042 int addrow2 = addRow-selh+1;
1043 if ( addrow2 < 0 ) 1043 if ( addrow2 < 0 )
1044 addrow2 = 0; 1044 addrow2 = 0;
1045 if (selh > 1) { 1045 if (selh > 1) {
1046 p.fillRect(1, (row+1)*dheight+addrow2, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol); 1046 p.fillRect(1, (row+1)*dheight+addrow2, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol);
1047 } 1047 }
1048 // draw last block from left to mSelEndT 1048 // draw last block from left to mSelEndT
1049 selw = mSelEndT-7*(mSelEndT/7)+1; 1049 selw = mSelEndT-7*(mSelEndT/7)+1;
1050 //qDebug("esl %d ",selw ); 1050 //qDebug("esl %d ",selw );
1051 int add = 0; 1051 int add = 0;
1052 if ( colModulo ) { 1052 if ( colModulo ) {
1053 add = 7 - colModulo; 1053 add = 7 - colModulo;
1054 if ( selw > add ) 1054 if ( selw > add )
1055 add = selw - add; 1055 add = selw - add;
1056 else 1056 else
1057 add = 0; 1057 add = 0;
1058 } 1058 }
1059 //qDebug("add %d ", add); 1059 //qDebug("add %d ", add);
1060 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow, 1060 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow,
1061 selw*dwidth+add, dheight+1, selcol); 1061 selw*dwidth+add, dheight+1, selcol);
1062 } 1062 }
1063 } 1063 }
1064 } 1064 }
1065 1065
1066 // iterate over all days in the matrix and draw the day label in appropriate colors 1066 // iterate over all days in the matrix and draw the day label in appropriate colors
1067 QColor actcol = mDefaultTextColorShaded; 1067 QColor actcol = mDefaultTextColorShaded;
1068 p.setPen(actcol); 1068 p.setPen(actcol);
1069 QPen tmppen; 1069 QPen tmppen;
1070 for(int i = 0; i < NUMDAYS; i++) { 1070 for(int i = 0; i < NUMDAYS; i++) {
1071 row = i/7; 1071 row = i/7;
1072 col = isRTL ? 6-(i-row*7) : i-row*7; 1072 col = isRTL ? 6-(i-row*7) : i-row*7;
1073 1073
1074 // if it is the first day of a month switch color from normal to shaded and vice versa 1074 // if it is the first day of a month switch color from normal to shaded and vice versa
1075 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { 1075 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) {
1076 if (actcol == mDefaultTextColorShaded) { 1076 if (actcol == mDefaultTextColorShaded) {
1077 actcol = mDefaultTextColor; 1077 actcol = mDefaultTextColor;
1078 } else { 1078 } else {
1079 actcol = mDefaultTextColorShaded; 1079 actcol = mDefaultTextColorShaded;
1080 } 1080 }
1081 p.setPen(actcol); 1081 p.setPen(actcol);
1082 } 1082 }
1083 if (actcol == mDefaultTextColorShaded) { 1083 if (actcol == mDefaultTextColorShaded) {
1084 if ( ! mouseDown ) { 1084 if ( ! mouseDown ) {
1085 continue; 1085 continue;
1086 } 1086 }
1087 } 1087 }
1088 //Reset pen color after selected days block 1088 //Reset pen color after selected days block
1089 if (i == mSelEndT+1) { 1089 if (i == mSelEndT+1) {
1090 p.setPen(actcol); 1090 p.setPen(actcol);
1091 } 1091 }
1092 1092
1093 // if today then draw rectangle around day 1093 // if today then draw rectangle around day
1094 if (today == i) { 1094 if (today == i) {
1095 tmppen = p.pen(); 1095 tmppen = p.pen();
1096 QPen mTodayPen(p.pen()); 1096 QPen mTodayPen(p.pen());
1097 if ( daysize.width() < 20 ) 1097 if ( daysize.width() < 20 )
1098 mTodayPen.setWidth(1); 1098 mTodayPen.setWidth(1);
1099 else 1099 else
1100 mTodayPen.setWidth(mTodayMarginWidth); 1100 mTodayPen.setWidth(mTodayMarginWidth);
1101 //draw red rectangle for holidays 1101 //draw red rectangle for holidays
1102 if (pDays.testBit(i)) { 1102 if (pDays.testBit(i)) {
1103 if (actcol == mDefaultTextColor) { 1103 if (actcol == mDefaultTextColor) {
1104 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); 1104 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor);
1105 } else { 1105 } else {
1106 mTodayPen.setColor(mHolidayColorShaded); 1106 mTodayPen.setColor(mHolidayColorShaded);
1107 } 1107 }
1108 } 1108 }
1109 //draw gray rectangle for today if in selection 1109 //draw gray rectangle for today if in selection
1110 if (i >= mSelStartT && i <= mSelEndT) { 1110 if (i >= mSelStartT && i <= mSelEndT) {
1111 QColor grey("grey"); 1111 QColor grey("grey");
1112 mTodayPen.setColor(grey); 1112 mTodayPen.setColor(grey);
1113 } 1113 }
1114 p.setPen(mTodayPen); 1114 p.setPen(mTodayPen);
1115 1115
1116 1116
1117 int addCol = 0; 1117 int addCol = 0;
1118 int addRow = 0; 1118 int addRow = 0;
1119 if (rowModulo) { 1119 if (rowModulo) {
1120 if ( row >= 6 - rowModulo ) 1120 if ( row >= 6 - rowModulo )
1121 addRow = row - 5 + rowModulo; 1121 addRow = row - 5 + rowModulo;
1122 } 1122 }
1123 if ( colModulo ) { 1123 if ( colModulo ) {
1124 if ( col >= 7 - colModulo ) 1124 if ( col >= 7 - colModulo )
1125 addCol = col - 6 + colModulo-1; 1125 addCol = col - 6 + colModulo-1;
1126 } 1126 }
1127 1127
1128 addCol += 1; 1128 addCol += 1;
1129 if ( row == 0 ) 1129 if ( row == 0 )
1130 addRow = 1; 1130 addRow = 1;
1131 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth+1, dheight+1); 1131 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth+1, dheight+1);
1132 p.setPen(tmppen); 1132 p.setPen(tmppen);
1133 } 1133 }
1134 1134
1135 // if any events are on that day then draw it using a bold font 1135 // if any events are on that day then draw it using a bold font
1136 if ( eDays.testBit(i) ) { 1136 if ( eDays.testBit(i) ) {
1137 QFont myFont = font(); 1137 QFont myFont = font();
1138 myFont.setBold(true); 1138 myFont.setBold(true);
1139 p.setFont(myFont); 1139 p.setFont(myFont);
1140 } 1140 }
1141 1141
1142 // if it is a holiday then use the default holiday color 1142 // if it is a holiday then use the default holiday color
1143 if ( pDays.testBit(i)) { 1143 if ( pDays.testBit(i)) {
1144 if ( bDays.testBit(i) ) { 1144 if ( bDays.testBit(i) ) {
1145 if ( hDays.testBit(i) ) 1145 if ( hDays.testBit(i) )
1146 p.setPen(QColor(0,200,0)); 1146 p.setPen(QColor(0,200,0));
1147 else 1147 else
1148 p.setPen(QColor(Qt::blue)); 1148 p.setPen(QColor(Qt::blue));
1149 } else { 1149 } else {
1150 if (actcol == mDefaultTextColor ) { 1150 if (actcol == mDefaultTextColor ) {
1151 p.setPen(KOPrefs::instance()->mHolidayColor); 1151 p.setPen(KOPrefs::instance()->mHolidayColor);
1152 } else { 1152 } else {
1153 p.setPen(mHolidayColorShaded); 1153 p.setPen(mHolidayColorShaded);
1154 } 1154 }
1155 } 1155 }
1156 } 1156 }
1157 1157
1158 // draw selected days with special color 1158 // draw selected days with special color
1159 // DO NOT specially highlight holidays in selection ! 1159 // DO NOT specially highlight holidays in selection !
1160 if (i >= mSelStartT && i <= mSelEndT) { 1160 if (i >= mSelStartT && i <= mSelEndT) {
1161 ;//p.setPen(mSelectedDaysColor); 1161 ;//p.setPen(mSelectedDaysColor);
1162 } 1162 }
1163 1163
1164 int addCol = 0; 1164 int addCol = 0;
1165 int addRow = 0; 1165 int addRow = 0;
1166 if ( colModulo ) { 1166 if ( colModulo ) {
1167 if ( col >= 7 - colModulo ) 1167 if ( col >= 7 - colModulo )
1168 addCol = col - 7 + colModulo; 1168 addCol = col - 7 + colModulo;
1169 } 1169 }
1170 if ( rowModulo ) { 1170 if ( rowModulo ) {
1171 if ( row >= 6 - rowModulo ) 1171 if ( row >= 6 - rowModulo )
1172 addRow = row - 5 + rowModulo; 1172 addRow = row - 5 + rowModulo;
1173 } 1173 }
1174 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); 1174 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow);
1175 ++addCol;//++addCol; 1175 ++addCol;//++addCol;
1176 if ( row == 0) 1176 if ( row == 0)
1177 addRow = 1; 1177 addRow = 1;
1178 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, 1178 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight,
1179 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); 1179 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]);
1180 1180
1181 // reset color to actual color 1181 // reset color to actual color
1182 if (pDays.testBit(i)) { 1182 if (pDays.testBit(i)) {
1183 p.setPen(actcol); 1183 p.setPen(actcol);
1184 } 1184 }
1185 // reset bold font to plain font 1185 // reset bold font to plain font
1186 if ( eDays.testBit(i)) { 1186 if ( eDays.testBit(i)) {
1187 QFont myFont = font(); 1187 QFont myFont = font();
1188 myFont.setBold(false); 1188 myFont.setBold(false);
1189 p.setFont(myFont); 1189 p.setFont(myFont);
1190 } 1190 }
1191 } 1191 }
1192 p.setPen(mDefaultTextColor); 1192 p.setPen(mDefaultTextColor);
1193 p.drawRect(0, 0, width(), height()); 1193 p.drawRect(0, 0, width(), height());
1194 } else { 1194 } else {
1195 //qDebug("NO redraw "); 1195 //qDebug("NO redraw ");
1196 } 1196 }
1197 1197
1198 bitBlt (this, pevent->rect().topLeft(), &myPix , pevent->rect() ,CopyROP); 1198 bitBlt (this, pevent->rect().topLeft(), &myPix , pevent->rect() ,CopyROP);
1199 mRedrawNeeded = false; 1199 mRedrawNeeded = false;
1200} 1200}
1201 1201
1202// ---------------------------------------------------------------------------- 1202// ----------------------------------------------------------------------------
1203// R E SI Z E E V E N T H A N D L I N G 1203// R E SI Z E E V E N T H A N D L I N G
1204// ---------------------------------------------------------------------------- 1204// ----------------------------------------------------------------------------
1205 1205
1206void KODayMatrix::resizeEvent(QResizeEvent * e) 1206void KODayMatrix::resizeEvent(QResizeEvent * e)
1207{ 1207{
1208 QRect sz = frameRect(); 1208 QRect sz = frameRect();
1209 daysize.setHeight(sz.height()*7 / NUMDAYS); 1209 daysize.setHeight(sz.height()*7 / NUMDAYS);
1210 daysize.setWidth(sz.width() / 7); 1210 daysize.setWidth(sz.width() / 7);
1211 QFrame::resizeEvent( e ); 1211 QFrame::resizeEvent( e );
1212} 1212}
1213 1213
1214QSize KODayMatrix::sizeHint() const 1214QSize KODayMatrix::sizeHint() const
1215{ 1215{
1216 1216
1217 QFontMetrics fm ( font() ); 1217 QFontMetrics fm ( font() );
1218 int wid = fm.width( "30") *7+3; 1218 int wid = fm.width( "30") *7+3;
1219 int hei = fm.height() * 6+3; 1219 int hei = fm.height() * 6+3;
1220 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); 1220 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei);
1221 return QSize ( wid, hei ); 1221 return QSize ( wid, hei );
1222 1222
1223} 1223}