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