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