-rw-r--r-- | korganizer/kodaymatrix.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index f864022..ae0a051 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp | |||
@@ -189,702 +189,712 @@ QString KODayMatrix::getWhatsThisText( QPoint p ) | |||
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 | int colModulo = (width()-2) % 7; | ||
447 | int rowModulo = (height()-2) % 6; | ||
448 | #if 0 | ||
446 | return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? | 449 | return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? |
447 | 6 - x/daysize.width() : x/daysize.width()); | 450 | 6 - x/daysize.width() : x/daysize.width()); |
451 | #endif | ||
452 | int xVal = (x-colModulo/2-2)/daysize.width(); | ||
453 | int yVal = (y-rowModulo/2-2)/daysize.height(); | ||
454 | |||
455 | |||
456 | return 7*(yVal) + xVal; | ||
457 | |||
448 | } | 458 | } |
449 | 459 | ||
450 | // ---------------------------------------------------------------------------- | 460 | // ---------------------------------------------------------------------------- |
451 | // M O U S E E V E N T H A N D L I N G | 461 | // M O U S E E V E N T H A N D L I N G |
452 | // ---------------------------------------------------------------------------- | 462 | // ---------------------------------------------------------------------------- |
453 | 463 | ||
454 | void KODayMatrix::mousePressEvent (QMouseEvent* e) | 464 | void KODayMatrix::mousePressEvent (QMouseEvent* e) |
455 | { | 465 | { |
456 | 466 | ||
457 | if ( e->button() == LeftButton ) | 467 | if ( e->button() == LeftButton ) |
458 | mouseDown = true; | 468 | mouseDown = true; |
459 | mSelStart = getDayIndexFrom(e->x(), e->y()); | 469 | mSelStart = getDayIndexFrom(e->x(), e->y()); |
460 | if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; | 470 | if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; |
461 | mSelInit = mSelStart; | 471 | mSelInit = mSelStart; |
462 | mSelEnd = mSelStart; | 472 | mSelEnd = mSelStart; |
463 | repaint(false); | 473 | repaint(false); |
464 | } | 474 | } |
465 | 475 | ||
466 | void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) | 476 | void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) |
467 | { | 477 | { |
468 | if ( e->button() == LeftButton ) | 478 | if ( e->button() == LeftButton ) |
469 | if ( ! mouseDown ) { | 479 | if ( ! mouseDown ) { |
470 | return; | 480 | return; |
471 | } | 481 | } |
472 | else | 482 | else |
473 | mouseDown = false; | 483 | mouseDown = false; |
474 | int tmp = getDayIndexFrom(e->x(), e->y()); | 484 | int tmp = getDayIndexFrom(e->x(), e->y()); |
475 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; | 485 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; |
476 | 486 | ||
477 | if (mSelInit > tmp) { | 487 | if (mSelInit > tmp) { |
478 | mSelEnd = mSelInit; | 488 | mSelEnd = mSelInit; |
479 | if (tmp != mSelStart) { | 489 | if (tmp != mSelStart) { |
480 | mSelStart = tmp; | 490 | mSelStart = tmp; |
481 | repaint(false); | 491 | repaint(false); |
482 | } | 492 | } |
483 | } else { | 493 | } else { |
484 | mSelStart = mSelInit; | 494 | mSelStart = mSelInit; |
485 | 495 | ||
486 | //repaint only if selection has changed | 496 | //repaint only if selection has changed |
487 | if (tmp != mSelEnd) { | 497 | if (tmp != mSelEnd) { |
488 | mSelEnd = tmp; | 498 | mSelEnd = tmp; |
489 | repaint(false); | 499 | repaint(false); |
490 | } | 500 | } |
491 | } | 501 | } |
492 | 502 | ||
493 | DateList daylist; | 503 | DateList daylist; |
494 | if ( mSelStart < 0 ) | 504 | if ( mSelStart < 0 ) |
495 | mSelStart = 0; | 505 | mSelStart = 0; |
496 | for (int i = mSelStart; i <= mSelEnd; i++) { | 506 | for (int i = mSelStart; i <= mSelEnd; i++) { |
497 | daylist.append(days[i]); | 507 | daylist.append(days[i]); |
498 | } | 508 | } |
499 | emit selected((const DateList)daylist); | 509 | emit selected((const DateList)daylist); |
500 | 510 | ||
501 | } | 511 | } |
502 | 512 | ||
503 | void KODayMatrix::mouseMoveEvent (QMouseEvent* e) | 513 | void KODayMatrix::mouseMoveEvent (QMouseEvent* e) |
504 | { | 514 | { |
505 | if ( ! mouseDown ) { | 515 | if ( ! mouseDown ) { |
506 | return; | 516 | return; |
507 | } | 517 | } |
508 | int tmp = getDayIndexFrom(e->x(), e->y()); | 518 | int tmp = getDayIndexFrom(e->x(), e->y()); |
509 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; | 519 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; |
510 | 520 | ||
511 | if (mSelInit > tmp) { | 521 | if (mSelInit > tmp) { |
512 | mSelEnd = mSelInit; | 522 | mSelEnd = mSelInit; |
513 | if (tmp != mSelStart) { | 523 | if (tmp != mSelStart) { |
514 | mSelStart = tmp; | 524 | mSelStart = tmp; |
515 | repaint(false); | 525 | repaint(false); |
516 | } | 526 | } |
517 | } else { | 527 | } else { |
518 | mSelStart = mSelInit; | 528 | mSelStart = mSelInit; |
519 | 529 | ||
520 | //repaint only if selection has changed | 530 | //repaint only if selection has changed |
521 | if (tmp != mSelEnd) { | 531 | if (tmp != mSelEnd) { |
522 | mSelEnd = tmp; | 532 | mSelEnd = tmp; |
523 | repaint(false); | 533 | repaint(false); |
524 | } | 534 | } |
525 | } | 535 | } |
526 | } | 536 | } |
527 | 537 | ||
528 | // ---------------------------------------------------------------------------- | 538 | // ---------------------------------------------------------------------------- |
529 | // D R A G ' N D R O P H A N D L I N G | 539 | // D R A G ' N D R O P H A N D L I N G |
530 | // ---------------------------------------------------------------------------- | 540 | // ---------------------------------------------------------------------------- |
531 | 541 | ||
532 | void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) | 542 | void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) |
533 | { | 543 | { |
534 | #ifndef KORG_NODND | 544 | #ifndef KORG_NODND |
535 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { | 545 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { |
536 | e->ignore(); | 546 | e->ignore(); |
537 | return; | 547 | return; |
538 | } | 548 | } |
539 | 549 | ||
540 | // some visual feedback | 550 | // some visual feedback |
541 | // oldPalette = palette(); | 551 | // oldPalette = palette(); |
542 | // setPalette(my_HilitePalette); | 552 | // setPalette(my_HilitePalette); |
543 | // update(); | 553 | // update(); |
544 | #endif | 554 | #endif |
545 | } | 555 | } |
546 | 556 | ||
547 | void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) | 557 | void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) |
548 | { | 558 | { |
549 | #ifndef KORG_NODND | 559 | #ifndef KORG_NODND |
550 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { | 560 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { |
551 | e->ignore(); | 561 | e->ignore(); |
552 | return; | 562 | return; |
553 | } | 563 | } |
554 | 564 | ||
555 | e->accept(); | 565 | e->accept(); |
556 | #endif | 566 | #endif |
557 | } | 567 | } |
558 | 568 | ||
559 | void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) | 569 | void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) |
560 | { | 570 | { |
561 | #ifndef KORG_NODND | 571 | #ifndef KORG_NODND |
562 | // setPalette(oldPalette); | 572 | // setPalette(oldPalette); |
563 | // update(); | 573 | // update(); |
564 | #endif | 574 | #endif |
565 | } | 575 | } |
566 | 576 | ||
567 | void KODayMatrix::dropEvent(QDropEvent *e) | 577 | void KODayMatrix::dropEvent(QDropEvent *e) |
568 | { | 578 | { |
569 | #ifndef KORG_NODND | 579 | #ifndef KORG_NODND |
570 | // kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; | 580 | // kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; |
571 | 581 | ||
572 | if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { | 582 | if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { |
573 | e->ignore(); | 583 | e->ignore(); |
574 | return; | 584 | return; |
575 | } | 585 | } |
576 | 586 | ||
577 | DndFactory factory( mCalendar ); | 587 | DndFactory factory( mCalendar ); |
578 | Event *event = factory.createDrop(e); | 588 | Event *event = factory.createDrop(e); |
579 | 589 | ||
580 | if (event) { | 590 | if (event) { |
581 | e->acceptAction(); | 591 | e->acceptAction(); |
582 | 592 | ||
583 | Event *existingEvent = mCalendar->event(event->uid()); | 593 | Event *existingEvent = mCalendar->event(event->uid()); |
584 | 594 | ||
585 | if(existingEvent) { | 595 | if(existingEvent) { |
586 | // uniquify event | 596 | // uniquify event |
587 | event->recreate(); | 597 | event->recreate(); |
588 | /* | 598 | /* |
589 | KMessageBox::sorry(this, | 599 | KMessageBox::sorry(this, |
590 | i18n("Event already exists in this calendar."), | 600 | i18n("Event already exists in this calendar."), |
591 | i18n("Drop Event")); | 601 | i18n("Drop Event")); |
592 | delete event; | 602 | delete event; |
593 | return; | 603 | return; |
594 | */ | 604 | */ |
595 | } | 605 | } |
596 | // kdDebug() << "Drop new Event" << endl; | 606 | // kdDebug() << "Drop new Event" << endl; |
597 | // Adjust date | 607 | // Adjust date |
598 | QDateTime start = event->dtStart(); | 608 | QDateTime start = event->dtStart(); |
599 | QDateTime end = event->dtEnd(); | 609 | QDateTime end = event->dtEnd(); |
600 | int duration = start.daysTo(end); | 610 | int duration = start.daysTo(end); |
601 | int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); | 611 | int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); |
602 | 612 | ||
603 | start.setDate(days[idx]); | 613 | start.setDate(days[idx]); |
604 | end.setDate(days[idx].addDays(duration)); | 614 | end.setDate(days[idx].addDays(duration)); |
605 | 615 | ||
606 | event->setDtStart(start); | 616 | event->setDtStart(start); |
607 | event->setDtEnd(end); | 617 | event->setDtEnd(end); |
608 | mCalendar->addEvent(event); | 618 | mCalendar->addEvent(event); |
609 | 619 | ||
610 | emit eventDropped(event); | 620 | emit eventDropped(event); |
611 | } else { | 621 | } else { |
612 | // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; | 622 | // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; |
613 | e->ignore(); | 623 | e->ignore(); |
614 | } | 624 | } |
615 | #endif | 625 | #endif |
616 | } | 626 | } |
617 | 627 | ||
618 | // ---------------------------------------------------------------------------- | 628 | // ---------------------------------------------------------------------------- |
619 | // P A I N T E V E N T H A N D L I N G | 629 | // P A I N T E V E N T H A N D L I N G |
620 | // ---------------------------------------------------------------------------- | 630 | // ---------------------------------------------------------------------------- |
621 | 631 | ||
622 | void KODayMatrix::paintEvent(QPaintEvent * pevent) | 632 | void KODayMatrix::paintEvent(QPaintEvent * pevent) |
623 | { | 633 | { |
624 | QRect sz = frameRect(); | 634 | QRect sz = frameRect(); |
625 | if ( sz.width() <= 0 || sz.height() <= 0 ) | 635 | if ( sz.width() <= 0 || sz.height() <= 0 ) |
626 | return; | 636 | return; |
627 | if ( mPendingUpdateBeforeRepaint ) { | 637 | if ( mPendingUpdateBeforeRepaint ) { |
628 | updateViewTimed(); | 638 | updateViewTimed(); |
629 | mPendingUpdateBeforeRepaint = false; | 639 | mPendingUpdateBeforeRepaint = false; |
630 | } | 640 | } |
631 | if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) { | 641 | if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) { |
632 | myPix.resize(sz.size() ); | 642 | myPix.resize(sz.size() ); |
633 | } | 643 | } |
634 | QPainter p(&myPix); | 644 | QPainter p(&myPix); |
635 | p.setFont(font()); | 645 | p.setFont(font()); |
636 | 646 | ||
637 | 647 | ||
638 | int dheight = daysize.height(); | 648 | int dheight = daysize.height(); |
639 | int dwidth = daysize.width(); | 649 | int dwidth = daysize.width(); |
640 | int row,col; | 650 | int row,col; |
641 | int selw, selh; | 651 | int selw, selh; |
642 | int xyOff = frameWidth(); | 652 | int xyOff = frameWidth(); |
643 | int colModulo = sz.width() % 7; | 653 | int colModulo = sz.width() % 7; |
644 | int rowModulo = sz.height() % 6; | 654 | int rowModulo = sz.height() % 6; |
645 | qDebug("col %d row %d ",colModulo,rowModulo ); | 655 | //qDebug("col %d row %d ",colModulo,rowModulo ); |
646 | 656 | ||
647 | bool isRTL = KOGlobals::self()->reverseLayout(); | 657 | bool isRTL = KOGlobals::self()->reverseLayout(); |
648 | 658 | ||
649 | // draw background and topleft frame | 659 | // draw background and topleft frame |
650 | p.fillRect(pevent->rect(), mDefaultBackColor); | 660 | p.fillRect(pevent->rect(), mDefaultBackColor); |
651 | p.setPen(mDefaultTextColor); | 661 | p.setPen(mDefaultTextColor); |
652 | p.drawRect(0, 0, sz.width()+1, sz.height()+1); | 662 | p.drawRect(0, 0, sz.width()+1, sz.height()+1); |
653 | int mSelStartT = mSelStart; | 663 | int mSelStartT = mSelStart; |
654 | int mSelEndT = mSelEnd; | 664 | int mSelEndT = mSelEnd; |
655 | if ( mSelEndT >= NUMDAYS ) | 665 | if ( mSelEndT >= NUMDAYS ) |
656 | mSelEndT = NUMDAYS-1; | 666 | mSelEndT = NUMDAYS-1; |
657 | // draw selected days with highlighted background color | 667 | // draw selected days with highlighted background color |
658 | if (mSelStart != NOSELECTION) { | 668 | if (mSelStart != NOSELECTION) { |
659 | bool skip = false; | 669 | bool skip = false; |
660 | if ( ! mouseDown ) { | 670 | if ( ! mouseDown ) { |
661 | int mo = days[20].month(); | 671 | int mo = days[20].month(); |
662 | //qDebug("-- %d %d ", mSelStartT, mSelEndT); | 672 | //qDebug("-- %d %d ", mSelStartT, mSelEndT); |
663 | //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); | 673 | //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); |
664 | if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) { | 674 | if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) { |
665 | skip = true; | 675 | skip = true; |
666 | } else { | 676 | } else { |
667 | if ( days[mSelStartT].month() != mo ) { | 677 | if ( days[mSelStartT].month() != mo ) { |
668 | int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); | 678 | int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); |
669 | mSelStartT += add +1; | 679 | mSelStartT += add +1; |
670 | } | 680 | } |
671 | if ( days[mSelEndT].month() != mo ) { | 681 | if ( days[mSelEndT].month() != mo ) { |
672 | int sub = days[mSelEndT].day(); | 682 | int sub = days[mSelEndT].day(); |
673 | mSelEndT -= sub ; | 683 | mSelEndT -= sub ; |
674 | } | 684 | } |
675 | } | 685 | } |
676 | } | 686 | } |
677 | if ( ! skip ) { | 687 | if ( ! skip ) { |
678 | row = mSelStartT/7; | 688 | row = mSelStartT/7; |
679 | col = mSelStartT -row*7; | 689 | col = mSelStartT -row*7; |
680 | QColor selcol = KOPrefs::instance()->mHighlightColor; | 690 | QColor selcol = KOPrefs::instance()->mHighlightColor; |
681 | int addCol = 0; | 691 | int addCol = 0; |
682 | int addRow = 0; | 692 | int addRow = 0; |
683 | int addRow2 = 0; | 693 | int addRow2 = 0; |
684 | int addCol2 = 0; | 694 | int addCol2 = 0; |
685 | if (row == mSelEndT/7) { | 695 | if (row == mSelEndT/7) { |
686 | if ( rowModulo ) { | 696 | if ( rowModulo ) { |
687 | if ( row >= 6 - rowModulo ) | 697 | if ( row >= 6 - rowModulo ) |
688 | addRow = row - 5 + rowModulo; | 698 | addRow = row - 5 + rowModulo; |
689 | } | 699 | } |
690 | if ( colModulo ) { | 700 | if ( colModulo ) { |
691 | int colt1 = mSelEndT%7; | 701 | int colt1 = mSelEndT%7; |
692 | //qDebug("colt1 %d ", colt1 ); | 702 | //qDebug("colt1 %d ", colt1 ); |
693 | if ( colt1 >= 7 - colModulo ) | 703 | if ( colt1 >= 7 - colModulo ) |
694 | addCol = colt1 - 7 + colModulo+1; | 704 | addCol = colt1 - 7 + colModulo+1; |
695 | int colt = mSelStartT%7; | 705 | int colt = mSelStartT%7; |
696 | if ( colt >= 7 - colModulo ) | 706 | if ( colt >= 7 - colModulo ) |
697 | addCol2 = colt - 7 + colModulo; | 707 | addCol2 = colt - 7 + colModulo; |
698 | addCol -= addCol2; | 708 | addCol -= addCol2; |
699 | //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); | 709 | //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); |
700 | } | 710 | } |
701 | // Single row selection | 711 | // Single row selection |
702 | if ( row == 0) | 712 | if ( row == 0) |
703 | addRow = 1; | 713 | addRow = 1; |
704 | p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, | 714 | p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, |
705 | row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); | 715 | row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); |
706 | } else { | 716 | } else { |
707 | // draw first row to the right | 717 | // draw first row to the right |
708 | if ( colModulo ) { | 718 | if ( colModulo ) { |
709 | if ( col >= 7 - colModulo ) | 719 | if ( col >= 7 - colModulo ) |
710 | addCol2 = col - 7 + colModulo; | 720 | addCol2 = col - 7 + colModulo; |
711 | } | 721 | } |
712 | if ( rowModulo ) { | 722 | if ( rowModulo ) { |
713 | if ( row >= 6 - rowModulo ) | 723 | if ( row >= 6 - rowModulo ) |
714 | addRow = row - 5 + rowModulo; | 724 | addRow = row - 5 + rowModulo; |
715 | } | 725 | } |
716 | if ( row == 0) | 726 | if ( row == 0) |
717 | addRow = 1; | 727 | addRow = 1; |
718 | p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, (7-col)*dwidth+colModulo, | 728 | p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, (7-col)*dwidth+colModulo, |
719 | dheight+1, selcol); | 729 | dheight+1, selcol); |
720 | // draw full block till last line | 730 | // draw full block till last line |
721 | selh = mSelEndT/7-row; | 731 | selh = mSelEndT/7-row; |
722 | addRow = 0; | 732 | addRow = 0; |
723 | if ( rowModulo ) { | 733 | if ( rowModulo ) { |
724 | if ( mSelEndT/7 >= 6 - rowModulo ) | 734 | if ( mSelEndT/7 >= 6 - rowModulo ) |
725 | addRow = mSelEndT/7 - 5 + rowModulo; | 735 | addRow = mSelEndT/7 - 5 + rowModulo; |
726 | } | 736 | } |
727 | if (selh > 1) { | 737 | if (selh > 1) { |
728 | p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol); | 738 | p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol); |
729 | } | 739 | } |
730 | // draw last block from left to mSelEndT | 740 | // draw last block from left to mSelEndT |
731 | selw = mSelEndT-7*(mSelEndT/7)+1; | 741 | selw = mSelEndT-7*(mSelEndT/7)+1; |
732 | //qDebug("esl %d ",selw ); | 742 | //qDebug("esl %d ",selw ); |
733 | int add = 0; | 743 | int add = 0; |
734 | if ( colModulo ) { | 744 | if ( colModulo ) { |
735 | add = 7 - colModulo; | 745 | add = 7 - colModulo; |
736 | if ( selw > add ) | 746 | if ( selw > add ) |
737 | add = selw - add; | 747 | add = selw - add; |
738 | else | 748 | else |
739 | add = 0; | 749 | add = 0; |
740 | } | 750 | } |
741 | //qDebug("add %d ", add); | 751 | //qDebug("add %d ", add); |
742 | p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow, | 752 | p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow, |
743 | selw*dwidth+add, dheight+1, selcol); | 753 | selw*dwidth+add, dheight+1, selcol); |
744 | } | 754 | } |
745 | } | 755 | } |
746 | } | 756 | } |
747 | 757 | ||
748 | // iterate over all days in the matrix and draw the day label in appropriate colors | 758 | // iterate over all days in the matrix and draw the day label in appropriate colors |
749 | QColor actcol = mDefaultTextColorShaded; | 759 | QColor actcol = mDefaultTextColorShaded; |
750 | p.setPen(actcol); | 760 | p.setPen(actcol); |
751 | QPen tmppen; | 761 | QPen tmppen; |
752 | for(int i = 0; i < NUMDAYS; i++) { | 762 | for(int i = 0; i < NUMDAYS; i++) { |
753 | row = i/7; | 763 | row = i/7; |
754 | col = isRTL ? 6-(i-row*7) : i-row*7; | 764 | col = isRTL ? 6-(i-row*7) : i-row*7; |
755 | 765 | ||
756 | // if it is the first day of a month switch color from normal to shaded and vice versa | 766 | // if it is the first day of a month switch color from normal to shaded and vice versa |
757 | if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { | 767 | if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { |
758 | if (actcol == mDefaultTextColorShaded) { | 768 | if (actcol == mDefaultTextColorShaded) { |
759 | actcol = mDefaultTextColor; | 769 | actcol = mDefaultTextColor; |
760 | } else { | 770 | } else { |
761 | actcol = mDefaultTextColorShaded; | 771 | actcol = mDefaultTextColorShaded; |
762 | } | 772 | } |
763 | p.setPen(actcol); | 773 | p.setPen(actcol); |
764 | } | 774 | } |
765 | if (actcol == mDefaultTextColorShaded) { | 775 | if (actcol == mDefaultTextColorShaded) { |
766 | if ( ! mouseDown ) { | 776 | if ( ! mouseDown ) { |
767 | continue; | 777 | continue; |
768 | } | 778 | } |
769 | } | 779 | } |
770 | //Reset pen color after selected days block | 780 | //Reset pen color after selected days block |
771 | if (i == mSelEndT+1) { | 781 | if (i == mSelEndT+1) { |
772 | p.setPen(actcol); | 782 | p.setPen(actcol); |
773 | } | 783 | } |
774 | 784 | ||
775 | // if today then draw rectangle around day | 785 | // if today then draw rectangle around day |
776 | if (today == i) { | 786 | if (today == i) { |
777 | tmppen = p.pen(); | 787 | tmppen = p.pen(); |
778 | QPen mTodayPen(p.pen()); | 788 | QPen mTodayPen(p.pen()); |
779 | if ( daysize.width() < 20 ) | 789 | if ( daysize.width() < 20 ) |
780 | mTodayPen.setWidth(1); | 790 | mTodayPen.setWidth(1); |
781 | else | 791 | else |
782 | mTodayPen.setWidth(mTodayMarginWidth); | 792 | mTodayPen.setWidth(mTodayMarginWidth); |
783 | //draw red rectangle for holidays | 793 | //draw red rectangle for holidays |
784 | if (!mHolidays[i].isNull()) { | 794 | if (!mHolidays[i].isNull()) { |
785 | if (actcol == mDefaultTextColor) { | 795 | if (actcol == mDefaultTextColor) { |
786 | mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); | 796 | mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); |
787 | } else { | 797 | } else { |
788 | mTodayPen.setColor(mHolidayColorShaded); | 798 | mTodayPen.setColor(mHolidayColorShaded); |
789 | } | 799 | } |
790 | } | 800 | } |
791 | //draw gray rectangle for today if in selection | 801 | //draw gray rectangle for today if in selection |
792 | if (i >= mSelStartT && i <= mSelEndT) { | 802 | if (i >= mSelStartT && i <= mSelEndT) { |
793 | QColor grey("grey"); | 803 | QColor grey("grey"); |
794 | mTodayPen.setColor(grey); | 804 | mTodayPen.setColor(grey); |
795 | } | 805 | } |
796 | p.setPen(mTodayPen); | 806 | p.setPen(mTodayPen); |
797 | 807 | ||
798 | 808 | ||
799 | int addCol = 0; | 809 | int addCol = 0; |
800 | int addRow = 0; | 810 | int addRow = 0; |
801 | if (rowModulo) { | 811 | if (rowModulo) { |
802 | if ( row >= 6 - rowModulo ) | 812 | if ( row >= 6 - rowModulo ) |
803 | addRow = row - 5 + rowModulo; | 813 | addRow = row - 5 + rowModulo; |
804 | } | 814 | } |
805 | if ( colModulo ) { | 815 | if ( colModulo ) { |
806 | if ( col >= 7 - colModulo ) | 816 | if ( col >= 7 - colModulo ) |
807 | addCol = col - 6 + colModulo-1; | 817 | addCol = col - 6 + colModulo-1; |
808 | } | 818 | } |
809 | p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight+1); | 819 | p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight+1); |
810 | p.setPen(tmppen); | 820 | p.setPen(tmppen); |
811 | } | 821 | } |
812 | 822 | ||
813 | // if any events are on that day then draw it using a bold font | 823 | // if any events are on that day then draw it using a bold font |
814 | if (events[i] > 0) { | 824 | if (events[i] > 0) { |
815 | QFont myFont = font(); | 825 | QFont myFont = font(); |
816 | myFont.setBold(true); | 826 | myFont.setBold(true); |
817 | p.setFont(myFont); | 827 | p.setFont(myFont); |
818 | } | 828 | } |
819 | 829 | ||
820 | // if it is a holiday then use the default holiday color | 830 | // if it is a holiday then use the default holiday color |
821 | if (!mHolidays[i].isNull()) { | 831 | if (!mHolidays[i].isNull()) { |
822 | if ( bDays.testBit(i) ) { | 832 | if ( bDays.testBit(i) ) { |
823 | p.setPen(Qt::green); | 833 | p.setPen(Qt::green); |
824 | } else { | 834 | } else { |
825 | if (actcol == mDefaultTextColor) { | 835 | if (actcol == mDefaultTextColor) { |
826 | p.setPen(KOPrefs::instance()->mHolidayColor); | 836 | p.setPen(KOPrefs::instance()->mHolidayColor); |
827 | } else { | 837 | } else { |
828 | p.setPen(mHolidayColorShaded); | 838 | p.setPen(mHolidayColorShaded); |
829 | } | 839 | } |
830 | } | 840 | } |
831 | } | 841 | } |
832 | 842 | ||
833 | // draw selected days with special color | 843 | // draw selected days with special color |
834 | // DO NOT specially highlight holidays in selection ! | 844 | // DO NOT specially highlight holidays in selection ! |
835 | if (i >= mSelStartT && i <= mSelEndT) { | 845 | if (i >= mSelStartT && i <= mSelEndT) { |
836 | ;//p.setPen(mSelectedDaysColor); | 846 | ;//p.setPen(mSelectedDaysColor); |
837 | } | 847 | } |
838 | 848 | ||
839 | int addCol = 0; | 849 | int addCol = 0; |
840 | int addRow = 0; | 850 | int addRow = 0; |
841 | if ( colModulo ) { | 851 | if ( colModulo ) { |
842 | if ( col >= 7 - colModulo ) | 852 | if ( col >= 7 - colModulo ) |
843 | addCol = col - 7 + colModulo; | 853 | addCol = col - 7 + colModulo; |
844 | } | 854 | } |
845 | if ( rowModulo ) { | 855 | if ( rowModulo ) { |
846 | if ( row >= 6 - rowModulo ) | 856 | if ( row >= 6 - rowModulo ) |
847 | addRow = row - 5 + rowModulo; | 857 | addRow = row - 5 + rowModulo; |
848 | } | 858 | } |
849 | //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); | 859 | //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); |
850 | ++addCol;//++addCol; | 860 | ++addCol;//++addCol; |
851 | p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, | 861 | p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, |
852 | Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); | 862 | Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); |
853 | 863 | ||
854 | // reset color to actual color | 864 | // reset color to actual color |
855 | if (!mHolidays[i].isNull()) { | 865 | if (!mHolidays[i].isNull()) { |
856 | p.setPen(actcol); | 866 | p.setPen(actcol); |
857 | } | 867 | } |
858 | // reset bold font to plain font | 868 | // reset bold font to plain font |
859 | if (events[i] > 0) { | 869 | if (events[i] > 0) { |
860 | QFont myFont = font(); | 870 | QFont myFont = font(); |
861 | myFont.setBold(false); | 871 | myFont.setBold(false); |
862 | p.setFont(myFont); | 872 | p.setFont(myFont); |
863 | } | 873 | } |
864 | } | 874 | } |
865 | int off = xyOff; | 875 | int off = xyOff; |
866 | bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP); | 876 | bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP); |
867 | //qDebug("ffffffffff %d ", off); | 877 | //qDebug("ffffffffff %d ", off); |
868 | } | 878 | } |
869 | 879 | ||
870 | // ---------------------------------------------------------------------------- | 880 | // ---------------------------------------------------------------------------- |
871 | // R E SI Z E E V E N T H A N D L I N G | 881 | // R E SI Z E E V E N T H A N D L I N G |
872 | // ---------------------------------------------------------------------------- | 882 | // ---------------------------------------------------------------------------- |
873 | 883 | ||
874 | void KODayMatrix::resizeEvent(QResizeEvent *) | 884 | void KODayMatrix::resizeEvent(QResizeEvent *) |
875 | { | 885 | { |
876 | QRect sz = frameRect(); | 886 | QRect sz = frameRect(); |
877 | daysize.setHeight(sz.height()*7 / NUMDAYS); | 887 | daysize.setHeight(sz.height()*7 / NUMDAYS); |
878 | daysize.setWidth(sz.width() / 7); | 888 | daysize.setWidth(sz.width() / 7); |
879 | } | 889 | } |
880 | 890 | ||
881 | QSize KODayMatrix::sizeHint() const | 891 | QSize KODayMatrix::sizeHint() const |
882 | { | 892 | { |
883 | 893 | ||
884 | QFontMetrics fm ( font() ); | 894 | QFontMetrics fm ( font() ); |
885 | int wid = fm.width( "30") *7+3; | 895 | int wid = fm.width( "30") *7+3; |
886 | int hei = fm.height() * 6+3; | 896 | int hei = fm.height() * 6+3; |
887 | //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); | 897 | //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); |
888 | return QSize ( wid, hei ); | 898 | return QSize ( wid, hei ); |
889 | 899 | ||
890 | } | 900 | } |