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