summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-03-20 20:24:06 (UTC)
committer zautrix <zautrix>2005-03-20 20:24:06 (UTC)
commitb32c8de5dcd6c4f8dce9415fb686970e2c991ebb (patch) (unidiff)
treeee5ba00bcc830d011a816981fd20dcf781b9cbf5
parent64068741e3b82a34c1b8a67da412ac88841b640c (diff)
downloadkdepimpi-b32c8de5dcd6c4f8dce9415fb686970e2c991ebb.zip
kdepimpi-b32c8de5dcd6c4f8dce9415fb686970e2c991ebb.tar.gz
kdepimpi-b32c8de5dcd6c4f8dce9415fb686970e2c991ebb.tar.bz2
nf
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kodaymatrix.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index f864022..ae0a051 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -1,890 +1,900 @@
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 66
67protected: 67protected:
68 virtual QString text( const QPoint& p ) 68 virtual QString text( const QPoint& p )
69 { 69 {
70 return _view->getWhatsThisText( p ) ; 70 return _view->getWhatsThisText( p ) ;
71 } 71 }
72private: 72private:
73 KODayMatrix * _view; 73 KODayMatrix * _view;
74}; 74};
75 75
76void DynamicTip::maybeTip( const QPoint &pos ) 76void DynamicTip::maybeTip( const QPoint &pos )
77{ 77{
78 //calculate which cell of the matrix the mouse is in 78 //calculate which cell of the matrix the mouse is in
79 QRect sz = matrix->frameRect(); 79 QRect sz = matrix->frameRect();
80 int dheight = sz.height()*7 / 42; 80 int dheight = sz.height()*7 / 42;
81 int dwidth = sz.width() / 7; 81 int dwidth = sz.width() / 7;
82 int row = pos.y()/dheight; 82 int row = pos.y()/dheight;
83 int col = pos.x()/dwidth; 83 int col = pos.x()/dwidth;
84 84
85 QRect rct(col*dwidth, row*dheight, dwidth, dheight); 85 QRect rct(col*dwidth, row*dheight, dwidth, dheight);
86 86
87// kdDebug() << "DynamicTip::maybeTip matrix cell index [" << 87// kdDebug() << "DynamicTip::maybeTip matrix cell index [" <<
88// col << "][" << row << "] => " <<(col+row*7) << endl; 88// col << "][" << row << "] => " <<(col+row*7) << endl;
89 89
90 //show holiday names only 90 //show holiday names only
91 QString str = matrix->getHolidayLabel(col+row*7); 91 QString str = matrix->getHolidayLabel(col+row*7);
92 if (str.isEmpty()) return; 92 if (str.isEmpty()) return;
93 tip(rct, str); 93 tip(rct, str);
94} 94}
95 95
96 96
97// ============================================================================ 97// ============================================================================
98// K O D A Y M A T R I X 98// K O D A Y M A T R I X
99// ============================================================================ 99// ============================================================================
100 100
101const int KODayMatrix::NOSELECTION = -1000; 101const int KODayMatrix::NOSELECTION = -1000;
102const int KODayMatrix::NUMDAYS = 42; 102const int KODayMatrix::NUMDAYS = 42;
103 103
104KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) 104KODayMatrix::KODayMatrix( QWidget *parent, const char *name )
105 : QFrame( parent, name ), mCalendar( 0 ) 105 : QFrame( parent, name ), mCalendar( 0 )
106 106
107#if 0 107#if 0
108KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : 108KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) :
109 QFrame(parent, name) 109 QFrame(parent, name)
110#endif 110#endif
111{ 111{
112 new KODaymatrixWhatsThis(this); 112 new KODaymatrixWhatsThis(this);
113 mPendingUpdateBeforeRepaint = false; 113 mPendingUpdateBeforeRepaint = false;
114 mouseDown = false; 114 mouseDown = false;
115 // initialize dynamic arrays 115 // initialize dynamic arrays
116 bDays.resize ( NUMDAYS ); 116 bDays.resize ( NUMDAYS );
117 days = new QDate[NUMDAYS]; 117 days = new QDate[NUMDAYS];
118 daylbls = new QString[NUMDAYS]; 118 daylbls = new QString[NUMDAYS];
119 events = new int[NUMDAYS]; 119 events = new int[NUMDAYS];
120 mToolTip = new DynamicTip(this); 120 mToolTip = new DynamicTip(this);
121 121
122 // set default values used for drawing the matrix 122 // set default values used for drawing the matrix
123 mDefaultBackColor = palette().active().base(); 123 mDefaultBackColor = palette().active().base();
124 mDefaultTextColor = palette().active().foreground(); 124 mDefaultTextColor = palette().active().foreground();
125 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); 125 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor);
126 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); 126 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor);
127 mSelectedDaysColor = QColor("white"); 127 mSelectedDaysColor = QColor("white");
128 mTodayMarginWidth = 2; 128 mTodayMarginWidth = 2;
129 mSelEnd = mSelStart = NOSELECTION; 129 mSelEnd = mSelStart = NOSELECTION;
130 130
131 setAcceptDrops(true); 131 setAcceptDrops(true);
132 //setFont( QFont("Arial", 10) ); 132 //setFont( QFont("Arial", 10) );
133 133
134 mUpdateTimer = new QTimer( this ); 134 mUpdateTimer = new QTimer( this );
135 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); 135 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() ));
136 mRepaintTimer = new QTimer( this ); 136 mRepaintTimer = new QTimer( this );
137 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); 137 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() ));
138 mDayChanged = false; 138 mDayChanged = false;
139 updateView(); 139 updateView();
140} 140}
141QString KODayMatrix::getWhatsThisText( QPoint p ) 141QString KODayMatrix::getWhatsThisText( QPoint p )
142{ 142{
143 143
144 int tmp = getDayIndexFrom(p.x(), p.y()); 144 int tmp = getDayIndexFrom(p.x(), p.y());
145 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) 145 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar )
146 return QString(); 146 return QString();
147 QDate mDate = days[tmp]; 147 QDate mDate = days[tmp];
148 QPtrList<Event> eventlist = mCalendar->events(mDate); 148 QPtrList<Event> eventlist = mCalendar->events(mDate);
149 Event *event; 149 Event *event;
150 QStringList mToolTip; 150 QStringList mToolTip;
151 for(event=eventlist.first();event != 0;event=eventlist.next()) { 151 for(event=eventlist.first();event != 0;event=eventlist.next()) {
152 QString mToolTipText; 152 QString mToolTipText;
153 QString text; 153 QString text;
154 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day 154 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
155 if (event->isMultiDay()) { 155 if (event->isMultiDay()) {
156 QString prefix = "<->";multiday = 2; 156 QString prefix = "<->";multiday = 2;
157 QString time; 157 QString time;
158 if ( event->doesRecur() ) { 158 if ( event->doesRecur() ) {
159 if ( event->recursOn( mDate) ) { 159 if ( event->recursOn( mDate) ) {
160 prefix ="->" ;multiday = 1; 160 prefix ="->" ;multiday = 1;
161 } 161 }
162 else { 162 else {
163 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 163 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
164 if ( event->recursOn( mDate.addDays( -days)) ) { 164 if ( event->recursOn( mDate.addDays( -days)) ) {
165 prefix ="<-" ;multiday = 3; 165 prefix ="<-" ;multiday = 3;
166 } 166 }
167 } 167 }
168 } else { 168 } else {
169 if (mDate == event->dtStart().date()) { 169 if (mDate == event->dtStart().date()) {
170 prefix ="->" ;multiday = 1; 170 prefix ="->" ;multiday = 1;
171 } else if (mDate == event->dtEnd().date()) { 171 } else if (mDate == event->dtEnd().date()) {
172 prefix ="<-" ;multiday = 3; 172 prefix ="<-" ;multiday = 3;
173 } 173 }
174 } 174 }
175 if ( !event->doesFloat() ) { 175 if ( !event->doesFloat() ) {
176 if ( mDate == event->dtStart().date () ) 176 if ( mDate == event->dtStart().date () )
177 time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; 177 time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
178 else if ( mDate == event->dtEnd().date () ) 178 else if ( mDate == event->dtEnd().date () )
179 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 179 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
180 180
181 } 181 }
182 text = time + event->summary(); 182 text = time + event->summary();
183 mToolTipText += prefix + text; 183 mToolTipText += prefix + text;
184 } else { 184 } else {
185 if (event->doesFloat()) { 185 if (event->doesFloat()) {
186 text = event->summary(); 186 text = event->summary();
187 mToolTipText += text; 187 mToolTipText += text;
188 } 188 }
189 else { 189 else {
190 text = KGlobal::locale()->formatTime(event->dtStart().time()); 190 text = KGlobal::locale()->formatTime(event->dtStart().time());
191 text += " " + event->summary(); 191 text += " " + event->summary();
192 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 192 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
193 } 193 }
194 } 194 }
195 mToolTip.append( mToolTipText ); 195 mToolTip.append( mToolTipText );
196 } 196 }
197 mToolTip.sort(); 197 mToolTip.sort();
198 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); 198 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>");
199} 199}
200void KODayMatrix::setCalendar( Calendar *cal ) 200void KODayMatrix::setCalendar( Calendar *cal )
201{ 201{
202 mCalendar = cal; 202 mCalendar = cal;
203 203
204 setAcceptDrops( mCalendar ); 204 setAcceptDrops( mCalendar );
205 205
206 updateEvents(); 206 updateEvents();
207} 207}
208 208
209QColor KODayMatrix::getShadedColor(QColor color) 209QColor KODayMatrix::getShadedColor(QColor color)
210{ 210{
211 QColor shaded; 211 QColor shaded;
212 int h=0; 212 int h=0;
213 int s=0; 213 int s=0;
214 int v=0; 214 int v=0;
215 color.hsv(&h,&s,&v); 215 color.hsv(&h,&s,&v);
216 s = s/4; 216 s = s/4;
217 v = 192+v/4; 217 v = 192+v/4;
218 shaded.setHsv(h,s,v); 218 shaded.setHsv(h,s,v);
219 219
220 return shaded; 220 return shaded;
221} 221}
222 222
223KODayMatrix::~KODayMatrix() 223KODayMatrix::~KODayMatrix()
224{ 224{
225 delete [] days; 225 delete [] days;
226 delete [] daylbls; 226 delete [] daylbls;
227 delete [] events; 227 delete [] events;
228 delete mToolTip; 228 delete mToolTip;
229} 229}
230 230
231/* 231/*
232void KODayMatrix::setStartDate(QDate start) 232void KODayMatrix::setStartDate(QDate start)
233{ 233{
234 updateView(start); 234 updateView(start);
235} 235}
236*/ 236*/
237 237
238void KODayMatrix::addSelectedDaysTo(DateList& selDays) 238void KODayMatrix::addSelectedDaysTo(DateList& selDays)
239{ 239{
240 240
241 if (mSelStart == NOSELECTION) { 241 if (mSelStart == NOSELECTION) {
242 return; 242 return;
243 } 243 }
244 244
245 //cope with selection being out of matrix limits at top (< 0) 245 //cope with selection being out of matrix limits at top (< 0)
246 int i0 = mSelStart; 246 int i0 = mSelStart;
247 if (i0 < 0) { 247 if (i0 < 0) {
248 for (int i = i0; i < 0; i++) { 248 for (int i = i0; i < 0; i++) {
249 selDays.append(days[0].addDays(i)); 249 selDays.append(days[0].addDays(i));
250 } 250 }
251 i0 = 0; 251 i0 = 0;
252 } 252 }
253 253
254 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) 254 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1)
255 if (mSelEnd > NUMDAYS-1) { 255 if (mSelEnd > NUMDAYS-1) {
256 for (int i = i0; i <= NUMDAYS-1; i++) { 256 for (int i = i0; i <= NUMDAYS-1; i++) {
257 selDays.append(days[i]); 257 selDays.append(days[i]);
258 } 258 }
259 for (int i = NUMDAYS; i < mSelEnd; i++) { 259 for (int i = NUMDAYS; i < mSelEnd; i++) {
260 selDays.append(days[0].addDays(i)); 260 selDays.append(days[0].addDays(i));
261 } 261 }
262 262
263 // apply normal routine to selection being entirely within matrix limits 263 // apply normal routine to selection being entirely within matrix limits
264 } else { 264 } else {
265 for (int i = i0; i <= mSelEnd; i++) { 265 for (int i = i0; i <= mSelEnd; i++) {
266 selDays.append(days[i]); 266 selDays.append(days[i]);
267 } 267 }
268 } 268 }
269} 269}
270 270
271void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) 271void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
272{ 272{
273 mSelStart = startdate.daysTo(start); 273 mSelStart = startdate.daysTo(start);
274 if ( mSelStart < 0 ) 274 if ( mSelStart < 0 )
275 mSelStart = 0; 275 mSelStart = 0;
276 mSelEnd = startdate.daysTo(end); 276 mSelEnd = startdate.daysTo(end);
277 if ( mSelEnd < 0 ) 277 if ( mSelEnd < 0 )
278 clearSelection(); 278 clearSelection();
279} 279}
280void KODayMatrix::clearSelection() 280void KODayMatrix::clearSelection()
281{ 281{
282 mSelEnd = mSelStart = NOSELECTION; 282 mSelEnd = mSelStart = NOSELECTION;
283} 283}
284 284
285 285
286void KODayMatrix::recalculateToday() 286void KODayMatrix::recalculateToday()
287{ 287{
288 today = -1; 288 today = -1;
289 for (int i=0; i<NUMDAYS; i++) { 289 for (int i=0; i<NUMDAYS; i++) {
290 events[i] = 0; 290 events[i] = 0;
291 days[i] = startdate.addDays(i); 291 days[i] = startdate.addDays(i);
292 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); 292 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
293 293
294 // if today is in the currently displayed month, hilight today 294 // if today is in the currently displayed month, hilight today
295 if (days[i].year() == QDate::currentDate().year() && 295 if (days[i].year() == QDate::currentDate().year() &&
296 days[i].month() == QDate::currentDate().month() && 296 days[i].month() == QDate::currentDate().month() &&
297 days[i].day() == QDate::currentDate().day()) { 297 days[i].day() == QDate::currentDate().day()) {
298 today = i; 298 today = i;
299 } 299 }
300 } 300 }
301 // qDebug(QString("Today is visible at %1.").arg(today)); 301 // qDebug(QString("Today is visible at %1.").arg(today));
302} 302}
303 303
304void KODayMatrix::updateView() 304void KODayMatrix::updateView()
305{ 305{
306 updateView(startdate); 306 updateView(startdate);
307} 307}
308void KODayMatrix::repaintViewTimed() 308void KODayMatrix::repaintViewTimed()
309{ 309{
310 mRepaintTimer->stop(); 310 mRepaintTimer->stop();
311 repaint(false); 311 repaint(false);
312} 312}
313void KODayMatrix::updateViewTimed() 313void KODayMatrix::updateViewTimed()
314{ 314{
315 mUpdateTimer->stop(); 315 mUpdateTimer->stop();
316 if ( !mCalendar ) { 316 if ( !mCalendar ) {
317 qDebug("NOT CAL "); 317 qDebug("NOT CAL ");
318 return; 318 return;
319 } 319 }
320 //qDebug("KODayMatrix::updateViewTimed "); 320 //qDebug("KODayMatrix::updateViewTimed ");
321 for(int i = 0; i < NUMDAYS; i++) { 321 for(int i = 0; i < NUMDAYS; i++) {
322 // if events are set for the day then remember to draw it bold 322 // if events are set for the day then remember to draw it bold
323 QPtrList<Event> eventlist = mCalendar->events(days[i]); 323 QPtrList<Event> eventlist = mCalendar->events(days[i]);
324 Event *event; 324 Event *event;
325 int numEvents = eventlist.count(); 325 int numEvents = eventlist.count();
326 QString holiStr = ""; 326 QString holiStr = "";
327 bDays.clearBit(i); 327 bDays.clearBit(i);
328 for(event=eventlist.first();event != 0;event=eventlist.next()) { 328 for(event=eventlist.first();event != 0;event=eventlist.next()) {
329 ushort recurType = event->recurrence()->doesRecur(); 329 ushort recurType = event->recurrence()->doesRecur();
330 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 330 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
331 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 331 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
332 numEvents--; 332 numEvents--;
333 } 333 }
334 if ( event->categories().contains( i18n("Holiday") ) || event->categories().contains( "Holiday" )) { 334 if ( event->categories().contains( i18n("Holiday") ) || event->categories().contains( "Holiday" )) {
335 if ( !holiStr.isEmpty() ) 335 if ( !holiStr.isEmpty() )
336 holiStr += "\n"; 336 holiStr += "\n";
337 holiStr += event->summary(); 337 holiStr += event->summary();
338 } 338 }
339 if ( event->categories().contains( i18n("Birthday") ) || event->categories().contains( "Birthday" )) { 339 if ( event->categories().contains( i18n("Birthday") ) || event->categories().contains( "Birthday" )) {
340 if ( !holiStr.isEmpty() ) 340 if ( !holiStr.isEmpty() )
341 holiStr += "\n"; 341 holiStr += "\n";
342 holiStr += event->summary(); 342 holiStr += event->summary();
343 bDays.setBit(i); 343 bDays.setBit(i);
344 } 344 }
345 } 345 }
346 events[i] = numEvents; 346 events[i] = numEvents;
347 //if it is a holy day then draw it red. Sundays are consider holidays, too 347 //if it is a holy day then draw it red. Sundays are consider holidays, too
348 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || 348 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) ||
349 !holiStr.isEmpty()) { 349 !holiStr.isEmpty()) {
350 mHolidays[i] = holiStr; 350 mHolidays[i] = holiStr;
351 } else { 351 } else {
352 mHolidays[i] = QString::null; 352 mHolidays[i] = QString::null;
353 } 353 }
354 } 354 }
355 if ( ! mPendingUpdateBeforeRepaint ) 355 if ( ! mPendingUpdateBeforeRepaint )
356 repaint(false); 356 repaint(false);
357} 357}
358void KODayMatrix::updateView(QDate actdate) 358void KODayMatrix::updateView(QDate actdate)
359{ 359{
360 360
361 if ( ! actdate.isValid() ) { 361 if ( ! actdate.isValid() ) {
362 //qDebug("date not valid "); 362 //qDebug("date not valid ");
363 return; 363 return;
364 } 364 }
365 mDayChanged = false; 365 mDayChanged = false;
366 //flag to indicate if the starting day of the matrix has changed by this call 366 //flag to indicate if the starting day of the matrix has changed by this call
367 //mDayChanged = false; 367 //mDayChanged = false;
368 // if a new startdate is to be set then apply Cornelius's calculation 368 // if a new startdate is to be set then apply Cornelius's calculation
369 // of the first day to be shown 369 // of the first day to be shown
370 if (actdate != startdate) { 370 if (actdate != startdate) {
371 // reset index of selection according to shift of starting date from startdate to actdate 371 // reset index of selection according to shift of starting date from startdate to actdate
372 if (mSelStart != NOSELECTION) { 372 if (mSelStart != NOSELECTION) {
373 int tmp = actdate.daysTo(startdate); 373 int tmp = actdate.daysTo(startdate);
374 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; 374 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl;
375 // shift selection if new one would be visible at least partly ! 375 // shift selection if new one would be visible at least partly !
376 376
377 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { 377 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) {
378 // nested if is required for next X display pushed from a different month - correction required 378 // nested if is required for next X display pushed from a different month - correction required
379 // otherwise, for month forward and backward, it must be avoided 379 // otherwise, for month forward and backward, it must be avoided
380 if( mSelStart > NUMDAYS || mSelStart < 0 ) 380 if( mSelStart > NUMDAYS || mSelStart < 0 )
381 mSelStart = mSelStart + tmp; 381 mSelStart = mSelStart + tmp;
382 if( mSelEnd > NUMDAYS || mSelEnd < 0 ) 382 if( mSelEnd > NUMDAYS || mSelEnd < 0 )
383 mSelEnd = mSelEnd + tmp; 383 mSelEnd = mSelEnd + tmp;
384 } 384 }
385 } 385 }
386 startdate = actdate; 386 startdate = actdate;
387 mDayChanged = true; 387 mDayChanged = true;
388 recalculateToday(); 388 recalculateToday();
389 } 389 }
390 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); 390 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() );
391 if ( !isVisible() ) { 391 if ( !isVisible() ) {
392 mPendingUpdateBeforeRepaint = true; 392 mPendingUpdateBeforeRepaint = true;
393 } else { 393 } else {
394#ifdef DESKTOP_VERSION 394#ifdef DESKTOP_VERSION
395 //mRepaintTimer->start( 150 ); 395 //mRepaintTimer->start( 150 );
396 mUpdateTimer->start( 150 ); 396 mUpdateTimer->start( 150 );
397#else 397#else
398 mRepaintTimer->start( 350 ); 398 mRepaintTimer->start( 350 );
399 mUpdateTimer->start( 1200 ); 399 mUpdateTimer->start( 1200 );
400#endif 400#endif
401 } 401 }
402} 402}
403void KODayMatrix::updateEvents() 403void KODayMatrix::updateEvents()
404{ 404{
405 if ( !mCalendar ) return; 405 if ( !mCalendar ) return;
406 406
407 for( int i = 0; i < NUMDAYS; i++ ) { 407 for( int i = 0; i < NUMDAYS; i++ ) {
408 // if events are set for the day then remember to draw it bold 408 // if events are set for the day then remember to draw it bold
409 QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); 409 QPtrList<Event> eventlist = mCalendar->events( days[ i ] );
410 int numEvents = eventlist.count(); 410 int numEvents = eventlist.count();
411 Event *event; 411 Event *event;
412 for( event = eventlist.first(); event != 0;event=eventlist.next()) { 412 for( event = eventlist.first(); event != 0;event=eventlist.next()) {
413 ushort recurType = event->doesRecur(); 413 ushort recurType = event->doesRecur();
414 414
415 if ( ( recurType == Recurrence::rDaily && 415 if ( ( recurType == Recurrence::rDaily &&
416 !KOPrefs::instance()->mDailyRecur ) || 416 !KOPrefs::instance()->mDailyRecur ) ||
417 ( recurType == Recurrence::rWeekly && 417 ( recurType == Recurrence::rWeekly &&
418 !KOPrefs::instance()->mWeeklyRecur ) ) { 418 !KOPrefs::instance()->mWeeklyRecur ) ) {
419 numEvents--; 419 numEvents--;
420 } 420 }
421 } 421 }
422 events[ i ] = numEvents; 422 events[ i ] = numEvents;
423 } 423 }
424} 424}
425 425
426const QDate& KODayMatrix::getDate(int offset) 426const QDate& KODayMatrix::getDate(int offset)
427{ 427{
428 if (offset < 0 || offset > NUMDAYS-1) { 428 if (offset < 0 || offset > NUMDAYS-1) {
429 qDebug("Wrong offset2 "); 429 qDebug("Wrong offset2 ");
430 return days[0]; 430 return days[0];
431 } 431 }
432 return days[offset]; 432 return days[offset];
433} 433}
434 434
435QString KODayMatrix::getHolidayLabel(int offset) 435QString KODayMatrix::getHolidayLabel(int offset)
436{ 436{
437 if (offset < 0 || offset > NUMDAYS-1) { 437 if (offset < 0 || offset > NUMDAYS-1) {
438 qDebug("Wrong offset1 "); 438 qDebug("Wrong offset1 ");
439 return 0; 439 return 0;
440 } 440 }
441 return mHolidays[offset]; 441 return mHolidays[offset];
442} 442}
443 443
444int KODayMatrix::getDayIndexFrom(int x, int y) 444int KODayMatrix::getDayIndexFrom(int x, int y)
445{ 445{
446 int colModulo = (width()-2) % 7;
447 int rowModulo = (height()-2) % 6;
448#if 0
446 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? 449 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
447 6 - x/daysize.width() : x/daysize.width()); 450 6 - x/daysize.width() : x/daysize.width());
451#endif
452 int xVal = (x-colModulo/2-2)/daysize.width();
453 int yVal = (y-rowModulo/2-2)/daysize.height();
454
455
456 return 7*(yVal) + xVal;
457
448} 458}
449 459
450// ---------------------------------------------------------------------------- 460// ----------------------------------------------------------------------------
451// M O U S E E V E N T H A N D L I N G 461// M O U S E E V E N T H A N D L I N G
452// ---------------------------------------------------------------------------- 462// ----------------------------------------------------------------------------
453 463
454void KODayMatrix::mousePressEvent (QMouseEvent* e) 464void KODayMatrix::mousePressEvent (QMouseEvent* e)
455{ 465{
456 466
457 if ( e->button() == LeftButton ) 467 if ( e->button() == LeftButton )
458 mouseDown = true; 468 mouseDown = true;
459 mSelStart = getDayIndexFrom(e->x(), e->y()); 469 mSelStart = getDayIndexFrom(e->x(), e->y());
460 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; 470 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1;
461 mSelInit = mSelStart; 471 mSelInit = mSelStart;
462 mSelEnd = mSelStart; 472 mSelEnd = mSelStart;
463 repaint(false); 473 repaint(false);
464} 474}
465 475
466void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) 476void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
467{ 477{
468 if ( e->button() == LeftButton ) 478 if ( e->button() == LeftButton )
469 if ( ! mouseDown ) { 479 if ( ! mouseDown ) {
470 return; 480 return;
471 } 481 }
472 else 482 else
473 mouseDown = false; 483 mouseDown = false;
474 int tmp = getDayIndexFrom(e->x(), e->y()); 484 int tmp = getDayIndexFrom(e->x(), e->y());
475 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 485 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
476 486
477 if (mSelInit > tmp) { 487 if (mSelInit > tmp) {
478 mSelEnd = mSelInit; 488 mSelEnd = mSelInit;
479 if (tmp != mSelStart) { 489 if (tmp != mSelStart) {
480 mSelStart = tmp; 490 mSelStart = tmp;
481 repaint(false); 491 repaint(false);
482 } 492 }
483 } else { 493 } else {
484 mSelStart = mSelInit; 494 mSelStart = mSelInit;
485 495
486 //repaint only if selection has changed 496 //repaint only if selection has changed
487 if (tmp != mSelEnd) { 497 if (tmp != mSelEnd) {
488 mSelEnd = tmp; 498 mSelEnd = tmp;
489 repaint(false); 499 repaint(false);
490 } 500 }
491 } 501 }
492 502
493 DateList daylist; 503 DateList daylist;
494 if ( mSelStart < 0 ) 504 if ( mSelStart < 0 )
495 mSelStart = 0; 505 mSelStart = 0;
496 for (int i = mSelStart; i <= mSelEnd; i++) { 506 for (int i = mSelStart; i <= mSelEnd; i++) {
497 daylist.append(days[i]); 507 daylist.append(days[i]);
498 } 508 }
499 emit selected((const DateList)daylist); 509 emit selected((const DateList)daylist);
500 510
501} 511}
502 512
503void KODayMatrix::mouseMoveEvent (QMouseEvent* e) 513void KODayMatrix::mouseMoveEvent (QMouseEvent* e)
504{ 514{
505 if ( ! mouseDown ) { 515 if ( ! mouseDown ) {
506 return; 516 return;
507 } 517 }
508 int tmp = getDayIndexFrom(e->x(), e->y()); 518 int tmp = getDayIndexFrom(e->x(), e->y());
509 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 519 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
510 520
511 if (mSelInit > tmp) { 521 if (mSelInit > tmp) {
512 mSelEnd = mSelInit; 522 mSelEnd = mSelInit;
513 if (tmp != mSelStart) { 523 if (tmp != mSelStart) {
514 mSelStart = tmp; 524 mSelStart = tmp;
515 repaint(false); 525 repaint(false);
516 } 526 }
517 } else { 527 } else {
518 mSelStart = mSelInit; 528 mSelStart = mSelInit;
519 529
520 //repaint only if selection has changed 530 //repaint only if selection has changed
521 if (tmp != mSelEnd) { 531 if (tmp != mSelEnd) {
522 mSelEnd = tmp; 532 mSelEnd = tmp;
523 repaint(false); 533 repaint(false);
524 } 534 }
525 } 535 }
526} 536}
527 537
528// ---------------------------------------------------------------------------- 538// ----------------------------------------------------------------------------
529// D R A G ' N D R O P H A N D L I N G 539// D R A G ' N D R O P H A N D L I N G
530// ---------------------------------------------------------------------------- 540// ----------------------------------------------------------------------------
531 541
532void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) 542void KODayMatrix::dragEnterEvent(QDragEnterEvent *e)
533{ 543{
534#ifndef KORG_NODND 544#ifndef KORG_NODND
535 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 545 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
536 e->ignore(); 546 e->ignore();
537 return; 547 return;
538 } 548 }
539 549
540 // some visual feedback 550 // some visual feedback
541// oldPalette = palette(); 551// oldPalette = palette();
542// setPalette(my_HilitePalette); 552// setPalette(my_HilitePalette);
543// update(); 553// update();
544#endif 554#endif
545} 555}
546 556
547void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) 557void KODayMatrix::dragMoveEvent(QDragMoveEvent *e)
548{ 558{
549#ifndef KORG_NODND 559#ifndef KORG_NODND
550 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 560 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
551 e->ignore(); 561 e->ignore();
552 return; 562 return;
553 } 563 }
554 564
555 e->accept(); 565 e->accept();
556#endif 566#endif
557} 567}
558 568
559void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) 569void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/)
560{ 570{
561#ifndef KORG_NODND 571#ifndef KORG_NODND
562// setPalette(oldPalette); 572// setPalette(oldPalette);
563// update(); 573// update();
564#endif 574#endif
565} 575}
566 576
567void KODayMatrix::dropEvent(QDropEvent *e) 577void KODayMatrix::dropEvent(QDropEvent *e)
568{ 578{
569#ifndef KORG_NODND 579#ifndef KORG_NODND
570// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; 580// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl;
571 581
572 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 582 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
573 e->ignore(); 583 e->ignore();
574 return; 584 return;
575 } 585 }
576 586
577 DndFactory factory( mCalendar ); 587 DndFactory factory( mCalendar );
578 Event *event = factory.createDrop(e); 588 Event *event = factory.createDrop(e);
579 589
580 if (event) { 590 if (event) {
581 e->acceptAction(); 591 e->acceptAction();
582 592
583 Event *existingEvent = mCalendar->event(event->uid()); 593 Event *existingEvent = mCalendar->event(event->uid());
584 594
585 if(existingEvent) { 595 if(existingEvent) {
586 // uniquify event 596 // uniquify event
587 event->recreate(); 597 event->recreate();
588/* 598/*
589 KMessageBox::sorry(this, 599 KMessageBox::sorry(this,
590 i18n("Event already exists in this calendar."), 600 i18n("Event already exists in this calendar."),
591 i18n("Drop Event")); 601 i18n("Drop Event"));
592 delete event; 602 delete event;
593 return; 603 return;
594*/ 604*/
595 } 605 }
596// kdDebug() << "Drop new Event" << endl; 606// kdDebug() << "Drop new Event" << endl;
597 // Adjust date 607 // Adjust date
598 QDateTime start = event->dtStart(); 608 QDateTime start = event->dtStart();
599 QDateTime end = event->dtEnd(); 609 QDateTime end = event->dtEnd();
600 int duration = start.daysTo(end); 610 int duration = start.daysTo(end);
601 int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); 611 int idx = getDayIndexFrom(e->pos().x(), e->pos().y());
602 612
603 start.setDate(days[idx]); 613 start.setDate(days[idx]);
604 end.setDate(days[idx].addDays(duration)); 614 end.setDate(days[idx].addDays(duration));
605 615
606 event->setDtStart(start); 616 event->setDtStart(start);
607 event->setDtEnd(end); 617 event->setDtEnd(end);
608 mCalendar->addEvent(event); 618 mCalendar->addEvent(event);
609 619
610 emit eventDropped(event); 620 emit eventDropped(event);
611 } else { 621 } else {
612// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; 622// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl;
613 e->ignore(); 623 e->ignore();
614 } 624 }
615#endif 625#endif
616} 626}
617 627
618// ---------------------------------------------------------------------------- 628// ----------------------------------------------------------------------------
619// P A I N T E V E N T H A N D L I N G 629// P A I N T E V E N T H A N D L I N G
620// ---------------------------------------------------------------------------- 630// ----------------------------------------------------------------------------
621 631
622void KODayMatrix::paintEvent(QPaintEvent * pevent) 632void KODayMatrix::paintEvent(QPaintEvent * pevent)
623{ 633{
624 QRect sz = frameRect(); 634 QRect sz = frameRect();
625 if ( sz.width() <= 0 || sz.height() <= 0 ) 635 if ( sz.width() <= 0 || sz.height() <= 0 )
626 return; 636 return;
627 if ( mPendingUpdateBeforeRepaint ) { 637 if ( mPendingUpdateBeforeRepaint ) {
628 updateViewTimed(); 638 updateViewTimed();
629 mPendingUpdateBeforeRepaint = false; 639 mPendingUpdateBeforeRepaint = false;
630 } 640 }
631 if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) { 641 if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) {
632 myPix.resize(sz.size() ); 642 myPix.resize(sz.size() );
633 } 643 }
634 QPainter p(&myPix); 644 QPainter p(&myPix);
635 p.setFont(font()); 645 p.setFont(font());
636 646
637 647
638 int dheight = daysize.height(); 648 int dheight = daysize.height();
639 int dwidth = daysize.width(); 649 int dwidth = daysize.width();
640 int row,col; 650 int row,col;
641 int selw, selh; 651 int selw, selh;
642 int xyOff = frameWidth(); 652 int xyOff = frameWidth();
643 int colModulo = sz.width() % 7; 653 int colModulo = sz.width() % 7;
644 int rowModulo = sz.height() % 6; 654 int rowModulo = sz.height() % 6;
645 qDebug("col %d row %d ",colModulo,rowModulo ); 655 //qDebug("col %d row %d ",colModulo,rowModulo );
646 656
647 bool isRTL = KOGlobals::self()->reverseLayout(); 657 bool isRTL = KOGlobals::self()->reverseLayout();
648 658
649 // draw background and topleft frame 659 // draw background and topleft frame
650 p.fillRect(pevent->rect(), mDefaultBackColor); 660 p.fillRect(pevent->rect(), mDefaultBackColor);
651 p.setPen(mDefaultTextColor); 661 p.setPen(mDefaultTextColor);
652 p.drawRect(0, 0, sz.width()+1, sz.height()+1); 662 p.drawRect(0, 0, sz.width()+1, sz.height()+1);
653 int mSelStartT = mSelStart; 663 int mSelStartT = mSelStart;
654 int mSelEndT = mSelEnd; 664 int mSelEndT = mSelEnd;
655 if ( mSelEndT >= NUMDAYS ) 665 if ( mSelEndT >= NUMDAYS )
656 mSelEndT = NUMDAYS-1; 666 mSelEndT = NUMDAYS-1;
657 // draw selected days with highlighted background color 667 // draw selected days with highlighted background color
658 if (mSelStart != NOSELECTION) { 668 if (mSelStart != NOSELECTION) {
659 bool skip = false; 669 bool skip = false;
660 if ( ! mouseDown ) { 670 if ( ! mouseDown ) {
661 int mo = days[20].month(); 671 int mo = days[20].month();
662 //qDebug("-- %d %d ", mSelStartT, mSelEndT); 672 //qDebug("-- %d %d ", mSelStartT, mSelEndT);
663 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); 673 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() );
664 if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) { 674 if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) {
665 skip = true; 675 skip = true;
666 } else { 676 } else {
667 if ( days[mSelStartT].month() != mo ) { 677 if ( days[mSelStartT].month() != mo ) {
668 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); 678 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day();
669 mSelStartT += add +1; 679 mSelStartT += add +1;
670 } 680 }
671 if ( days[mSelEndT].month() != mo ) { 681 if ( days[mSelEndT].month() != mo ) {
672 int sub = days[mSelEndT].day(); 682 int sub = days[mSelEndT].day();
673 mSelEndT -= sub ; 683 mSelEndT -= sub ;
674 } 684 }
675 } 685 }
676 } 686 }
677 if ( ! skip ) { 687 if ( ! skip ) {
678 row = mSelStartT/7; 688 row = mSelStartT/7;
679 col = mSelStartT -row*7; 689 col = mSelStartT -row*7;
680 QColor selcol = KOPrefs::instance()->mHighlightColor; 690 QColor selcol = KOPrefs::instance()->mHighlightColor;
681 int addCol = 0; 691 int addCol = 0;
682 int addRow = 0; 692 int addRow = 0;
683 int addRow2 = 0; 693 int addRow2 = 0;
684 int addCol2 = 0; 694 int addCol2 = 0;
685 if (row == mSelEndT/7) { 695 if (row == mSelEndT/7) {
686 if ( rowModulo ) { 696 if ( rowModulo ) {
687 if ( row >= 6 - rowModulo ) 697 if ( row >= 6 - rowModulo )
688 addRow = row - 5 + rowModulo; 698 addRow = row - 5 + rowModulo;
689 } 699 }
690 if ( colModulo ) { 700 if ( colModulo ) {
691 int colt1 = mSelEndT%7; 701 int colt1 = mSelEndT%7;
692 //qDebug("colt1 %d ", colt1 ); 702 //qDebug("colt1 %d ", colt1 );
693 if ( colt1 >= 7 - colModulo ) 703 if ( colt1 >= 7 - colModulo )
694 addCol = colt1 - 7 + colModulo+1; 704 addCol = colt1 - 7 + colModulo+1;
695 int colt = mSelStartT%7; 705 int colt = mSelStartT%7;
696 if ( colt >= 7 - colModulo ) 706 if ( colt >= 7 - colModulo )
697 addCol2 = colt - 7 + colModulo; 707 addCol2 = colt - 7 + colModulo;
698 addCol -= addCol2; 708 addCol -= addCol2;
699 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); 709 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 );
700 } 710 }
701 // Single row selection 711 // Single row selection
702 if ( row == 0) 712 if ( row == 0)
703 addRow = 1; 713 addRow = 1;
704 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, 714 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2,
705 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); 715 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol);
706 } else { 716 } else {
707 // draw first row to the right 717 // draw first row to the right
708 if ( colModulo ) { 718 if ( colModulo ) {
709 if ( col >= 7 - colModulo ) 719 if ( col >= 7 - colModulo )
710 addCol2 = col - 7 + colModulo; 720 addCol2 = col - 7 + colModulo;
711 } 721 }
712 if ( rowModulo ) { 722 if ( rowModulo ) {
713 if ( row >= 6 - rowModulo ) 723 if ( row >= 6 - rowModulo )
714 addRow = row - 5 + rowModulo; 724 addRow = row - 5 + rowModulo;
715 } 725 }
716 if ( row == 0) 726 if ( row == 0)
717 addRow = 1; 727 addRow = 1;
718 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, (7-col)*dwidth+colModulo, 728 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, (7-col)*dwidth+colModulo,
719 dheight+1, selcol); 729 dheight+1, selcol);
720 // draw full block till last line 730 // draw full block till last line
721 selh = mSelEndT/7-row; 731 selh = mSelEndT/7-row;
722 addRow = 0; 732 addRow = 0;
723 if ( rowModulo ) { 733 if ( rowModulo ) {
724 if ( mSelEndT/7 >= 6 - rowModulo ) 734 if ( mSelEndT/7 >= 6 - rowModulo )
725 addRow = mSelEndT/7 - 5 + rowModulo; 735 addRow = mSelEndT/7 - 5 + rowModulo;
726 } 736 }
727 if (selh > 1) { 737 if (selh > 1) {
728 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol); 738 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol);
729 } 739 }
730 // draw last block from left to mSelEndT 740 // draw last block from left to mSelEndT
731 selw = mSelEndT-7*(mSelEndT/7)+1; 741 selw = mSelEndT-7*(mSelEndT/7)+1;
732 //qDebug("esl %d ",selw ); 742 //qDebug("esl %d ",selw );
733 int add = 0; 743 int add = 0;
734 if ( colModulo ) { 744 if ( colModulo ) {
735 add = 7 - colModulo; 745 add = 7 - colModulo;
736 if ( selw > add ) 746 if ( selw > add )
737 add = selw - add; 747 add = selw - add;
738 else 748 else
739 add = 0; 749 add = 0;
740 } 750 }
741 //qDebug("add %d ", add); 751 //qDebug("add %d ", add);
742 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow, 752 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow,
743 selw*dwidth+add, dheight+1, selcol); 753 selw*dwidth+add, dheight+1, selcol);
744 } 754 }
745 } 755 }
746 } 756 }
747 757
748 // iterate over all days in the matrix and draw the day label in appropriate colors 758 // iterate over all days in the matrix and draw the day label in appropriate colors
749 QColor actcol = mDefaultTextColorShaded; 759 QColor actcol = mDefaultTextColorShaded;
750 p.setPen(actcol); 760 p.setPen(actcol);
751 QPen tmppen; 761 QPen tmppen;
752 for(int i = 0; i < NUMDAYS; i++) { 762 for(int i = 0; i < NUMDAYS; i++) {
753 row = i/7; 763 row = i/7;
754 col = isRTL ? 6-(i-row*7) : i-row*7; 764 col = isRTL ? 6-(i-row*7) : i-row*7;
755 765
756 // if it is the first day of a month switch color from normal to shaded and vice versa 766 // if it is the first day of a month switch color from normal to shaded and vice versa
757 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { 767 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) {
758 if (actcol == mDefaultTextColorShaded) { 768 if (actcol == mDefaultTextColorShaded) {
759 actcol = mDefaultTextColor; 769 actcol = mDefaultTextColor;
760 } else { 770 } else {
761 actcol = mDefaultTextColorShaded; 771 actcol = mDefaultTextColorShaded;
762 } 772 }
763 p.setPen(actcol); 773 p.setPen(actcol);
764 } 774 }
765 if (actcol == mDefaultTextColorShaded) { 775 if (actcol == mDefaultTextColorShaded) {
766 if ( ! mouseDown ) { 776 if ( ! mouseDown ) {
767 continue; 777 continue;
768 } 778 }
769 } 779 }
770 //Reset pen color after selected days block 780 //Reset pen color after selected days block
771 if (i == mSelEndT+1) { 781 if (i == mSelEndT+1) {
772 p.setPen(actcol); 782 p.setPen(actcol);
773 } 783 }
774 784
775 // if today then draw rectangle around day 785 // if today then draw rectangle around day
776 if (today == i) { 786 if (today == i) {
777 tmppen = p.pen(); 787 tmppen = p.pen();
778 QPen mTodayPen(p.pen()); 788 QPen mTodayPen(p.pen());
779 if ( daysize.width() < 20 ) 789 if ( daysize.width() < 20 )
780 mTodayPen.setWidth(1); 790 mTodayPen.setWidth(1);
781 else 791 else
782 mTodayPen.setWidth(mTodayMarginWidth); 792 mTodayPen.setWidth(mTodayMarginWidth);
783 //draw red rectangle for holidays 793 //draw red rectangle for holidays
784 if (!mHolidays[i].isNull()) { 794 if (!mHolidays[i].isNull()) {
785 if (actcol == mDefaultTextColor) { 795 if (actcol == mDefaultTextColor) {
786 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); 796 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor);
787 } else { 797 } else {
788 mTodayPen.setColor(mHolidayColorShaded); 798 mTodayPen.setColor(mHolidayColorShaded);
789 } 799 }
790 } 800 }
791 //draw gray rectangle for today if in selection 801 //draw gray rectangle for today if in selection
792 if (i >= mSelStartT && i <= mSelEndT) { 802 if (i >= mSelStartT && i <= mSelEndT) {
793 QColor grey("grey"); 803 QColor grey("grey");
794 mTodayPen.setColor(grey); 804 mTodayPen.setColor(grey);
795 } 805 }
796 p.setPen(mTodayPen); 806 p.setPen(mTodayPen);
797 807
798 808
799 int addCol = 0; 809 int addCol = 0;
800 int addRow = 0; 810 int addRow = 0;
801 if (rowModulo) { 811 if (rowModulo) {
802 if ( row >= 6 - rowModulo ) 812 if ( row >= 6 - rowModulo )
803 addRow = row - 5 + rowModulo; 813 addRow = row - 5 + rowModulo;
804 } 814 }
805 if ( colModulo ) { 815 if ( colModulo ) {
806 if ( col >= 7 - colModulo ) 816 if ( col >= 7 - colModulo )
807 addCol = col - 6 + colModulo-1; 817 addCol = col - 6 + colModulo-1;
808 } 818 }
809 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight+1); 819 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight+1);
810 p.setPen(tmppen); 820 p.setPen(tmppen);
811 } 821 }
812 822
813 // if any events are on that day then draw it using a bold font 823 // if any events are on that day then draw it using a bold font
814 if (events[i] > 0) { 824 if (events[i] > 0) {
815 QFont myFont = font(); 825 QFont myFont = font();
816 myFont.setBold(true); 826 myFont.setBold(true);
817 p.setFont(myFont); 827 p.setFont(myFont);
818 } 828 }
819 829
820 // if it is a holiday then use the default holiday color 830 // if it is a holiday then use the default holiday color
821 if (!mHolidays[i].isNull()) { 831 if (!mHolidays[i].isNull()) {
822 if ( bDays.testBit(i) ) { 832 if ( bDays.testBit(i) ) {
823 p.setPen(Qt::green); 833 p.setPen(Qt::green);
824 } else { 834 } else {
825 if (actcol == mDefaultTextColor) { 835 if (actcol == mDefaultTextColor) {
826 p.setPen(KOPrefs::instance()->mHolidayColor); 836 p.setPen(KOPrefs::instance()->mHolidayColor);
827 } else { 837 } else {
828 p.setPen(mHolidayColorShaded); 838 p.setPen(mHolidayColorShaded);
829 } 839 }
830 } 840 }
831 } 841 }
832 842
833 // draw selected days with special color 843 // draw selected days with special color
834 // DO NOT specially highlight holidays in selection ! 844 // DO NOT specially highlight holidays in selection !
835 if (i >= mSelStartT && i <= mSelEndT) { 845 if (i >= mSelStartT && i <= mSelEndT) {
836 ;//p.setPen(mSelectedDaysColor); 846 ;//p.setPen(mSelectedDaysColor);
837 } 847 }
838 848
839 int addCol = 0; 849 int addCol = 0;
840 int addRow = 0; 850 int addRow = 0;
841 if ( colModulo ) { 851 if ( colModulo ) {
842 if ( col >= 7 - colModulo ) 852 if ( col >= 7 - colModulo )
843 addCol = col - 7 + colModulo; 853 addCol = col - 7 + colModulo;
844 } 854 }
845 if ( rowModulo ) { 855 if ( rowModulo ) {
846 if ( row >= 6 - rowModulo ) 856 if ( row >= 6 - rowModulo )
847 addRow = row - 5 + rowModulo; 857 addRow = row - 5 + rowModulo;
848 } 858 }
849 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); 859 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow);
850 ++addCol;//++addCol; 860 ++addCol;//++addCol;
851 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, 861 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight,
852 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); 862 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]);
853 863
854 // reset color to actual color 864 // reset color to actual color
855 if (!mHolidays[i].isNull()) { 865 if (!mHolidays[i].isNull()) {
856 p.setPen(actcol); 866 p.setPen(actcol);
857 } 867 }
858 // reset bold font to plain font 868 // reset bold font to plain font
859 if (events[i] > 0) { 869 if (events[i] > 0) {
860 QFont myFont = font(); 870 QFont myFont = font();
861 myFont.setBold(false); 871 myFont.setBold(false);
862 p.setFont(myFont); 872 p.setFont(myFont);
863 } 873 }
864 } 874 }
865 int off = xyOff; 875 int off = xyOff;
866 bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP); 876 bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP);
867 //qDebug("ffffffffff %d ", off); 877 //qDebug("ffffffffff %d ", off);
868} 878}
869 879
870// ---------------------------------------------------------------------------- 880// ----------------------------------------------------------------------------
871// R E SI Z E E V E N T H A N D L I N G 881// R E SI Z E E V E N T H A N D L I N G
872// ---------------------------------------------------------------------------- 882// ----------------------------------------------------------------------------
873 883
874void KODayMatrix::resizeEvent(QResizeEvent *) 884void KODayMatrix::resizeEvent(QResizeEvent *)
875{ 885{
876 QRect sz = frameRect(); 886 QRect sz = frameRect();
877 daysize.setHeight(sz.height()*7 / NUMDAYS); 887 daysize.setHeight(sz.height()*7 / NUMDAYS);
878 daysize.setWidth(sz.width() / 7); 888 daysize.setWidth(sz.width() / 7);
879} 889}
880 890
881QSize KODayMatrix::sizeHint() const 891QSize KODayMatrix::sizeHint() const
882{ 892{
883 893
884 QFontMetrics fm ( font() ); 894 QFontMetrics fm ( font() );
885 int wid = fm.width( "30") *7+3; 895 int wid = fm.width( "30") *7+3;
886 int hei = fm.height() * 6+3; 896 int hei = fm.height() * 6+3;
887 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); 897 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei);
888 return QSize ( wid, hei ); 898 return QSize ( wid, hei );
889 899
890} 900}