-rw-r--r-- | korganizer/kodaymatrix.cpp | 87 |
1 files changed, 62 insertions, 25 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index 17a1d13..df606d0 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp | |||
@@ -345,70 +345,75 @@ void KODayMatrix::repaintViewTimed() | |||
345 | //hDays.fill( false); | 345 | //hDays.fill( false); |
346 | //eDays.fill( false); | 346 | //eDays.fill( false); |
347 | mRepaintTimer->stop(); | 347 | mRepaintTimer->stop(); |
348 | int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday | 348 | int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday |
349 | int i; | 349 | int i; |
350 | for(i = 0; i < NUMDAYS; i++) { | 350 | for(i = 0; i < NUMDAYS; i++) { |
351 | if ( ( (i+startDay) % 7 == 0 ) ) { | 351 | if ( ( (i+startDay) % 7 == 0 ) ) { |
352 | pDays.setBit(i); | 352 | pDays.setBit(i); |
353 | } | 353 | } |
354 | } | 354 | } |
355 | repaint(false); | 355 | repaint(false); |
356 | } | 356 | } |
357 | void KODayMatrix::computeEvent(Event *event, int i ) | 357 | void KODayMatrix::computeEvent(Event *event, int i ) |
358 | { | 358 | { |
359 | QString holiStr = mHolidays[i]; | 359 | QString holiStr = mHolidays[i]; |
360 | if ( event->isHoliday()) { | 360 | if ( event->isHoliday()) { |
361 | pDays.setBit(i); | 361 | pDays.setBit(i); |
362 | hDays.setBit(i); | 362 | hDays.setBit(i); |
363 | if ( !holiStr.isEmpty() ) | 363 | if ( !holiStr.isEmpty() ) |
364 | holiStr += "\n"; | 364 | holiStr += "\n"; |
365 | holiStr += event->summary(); | 365 | holiStr += event->summary(); |
366 | if ( !event->location().isEmpty() ) | 366 | if ( !event->location().isEmpty() ) |
367 | holiStr += " (" + event->location() + ")"; | 367 | holiStr += " (" + event->location() + ")"; |
368 | mHolidays[i] =holiStr ; | 368 | mHolidays[i] =holiStr ; |
369 | eDays.setBit(i); | ||
369 | } | 370 | } |
370 | if ( event->isBirthday()) { | 371 | if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_T_VIEW && KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) { |
371 | pDays.setBit(i); | 372 | if ( event->isBirthday()) { |
372 | if ( !holiStr.isEmpty() ) | 373 | pDays.setBit(i); |
373 | holiStr += "\n"; | 374 | if ( !holiStr.isEmpty() ) |
374 | holiStr += i18n("Birthday") + ": "+event->summary(); | 375 | holiStr += "\n"; |
375 | if ( !event->location().isEmpty() ) | 376 | holiStr += i18n("Birthday") + ": "+event->summary(); |
376 | holiStr += " (" + event->location() + ")"; | 377 | if ( !event->location().isEmpty() ) |
377 | bDays.setBit(i); | 378 | holiStr += " (" + event->location() + ")"; |
378 | mHolidays[i] =holiStr ; | 379 | bDays.setBit(i); |
380 | mHolidays[i] =holiStr ; | ||
381 | } | ||
379 | } | 382 | } |
380 | eDays.setBit(i); | 383 | if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) |
384 | eDays.setBit(i); | ||
381 | } | 385 | } |
382 | void KODayMatrix::updateViewTimed() | 386 | void KODayMatrix::updateViewTimed() |
383 | { | 387 | { |
384 | mUpdateTimer->stop(); | 388 | mUpdateTimer->stop(); |
385 | if ( !mCalendar ) { | 389 | if ( !mCalendar ) { |
386 | qDebug("NOT CAL "); | 390 | qDebug("NOT CAL "); |
387 | return; | 391 | return; |
388 | } | 392 | } |
389 | #if 1 | 393 | #if 1 |
390 | 394 | ||
395 | |||
391 | int i; | 396 | int i; |
392 | int timeSpan = NUMDAYS-1; | 397 | int timeSpan = NUMDAYS-1; |
393 | QPtrList<Event> events = mCalendar->events(); | 398 | QPtrList<Event> events = mCalendar->events(); |
394 | Event *event; | 399 | Event *event; |
395 | QDateTime dt; | 400 | QDateTime dt; |
396 | bool ok; | 401 | bool ok; |
397 | bDays.fill( false); | 402 | bDays.fill( false); |
398 | pDays.fill( false); | 403 | pDays.fill( false); |
399 | hDays.fill( false); | 404 | hDays.fill( false); |
400 | eDays.fill( false); | 405 | eDays.fill( false); |
401 | mHolidays.clear(); | 406 | mHolidays.clear(); |
402 | QDate mStartDate = days[0]; | 407 | QDate mStartDate = days[0]; |
403 | QDate endDate = mStartDate.addDays( timeSpan ); | 408 | QDate endDate = mStartDate.addDays( timeSpan ); |
404 | for( event = events.first(); event; event = events.next() ) { // for event | 409 | for( event = events.first(); event; event = events.next() ) { // for event |
405 | ushort recurType = event->recurrence()->doesRecur(); | 410 | ushort recurType = event->recurrence()->doesRecur(); |
406 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || | 411 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || |
407 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { | 412 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { |
408 | continue; | 413 | continue; |
409 | } | 414 | } |
410 | if ( event->doesRecur() ) { | 415 | if ( event->doesRecur() ) { |
411 | bool last; | 416 | bool last; |
412 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); | 417 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); |
413 | QDateTime incidenceEnd; | 418 | QDateTime incidenceEnd; |
414 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); | 419 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); |
@@ -448,64 +453,94 @@ void KODayMatrix::updateViewTimed() | |||
448 | break; | 453 | break; |
449 | } | 454 | } |
450 | } else { // no recur | 455 | } else { // no recur |
451 | int st = event->dtStart().date().daysTo( endDate ); | 456 | int st = event->dtStart().date().daysTo( endDate ); |
452 | if ( st >= 0 ) { // start before timeend | 457 | if ( st >= 0 ) { // start before timeend |
453 | int end = mStartDate.daysTo( event->dtEnd().date() ); | 458 | int end = mStartDate.daysTo( event->dtEnd().date() ); |
454 | if ( end >= 0 ) { // end after timestart --- got one! | 459 | if ( end >= 0 ) { // end after timestart --- got one! |
455 | //normalize | 460 | //normalize |
456 | st = timeSpan - st; | 461 | st = timeSpan - st; |
457 | if ( st < 0 ) st = 0; | 462 | if ( st < 0 ) st = 0; |
458 | if ( end > timeSpan ) end = timeSpan; | 463 | if ( end > timeSpan ) end = timeSpan; |
459 | int iii; | 464 | int iii; |
460 | for ( iii = st;iii<= end;++iii) | 465 | for ( iii = st;iii<= end;++iii) |
461 | computeEvent( event, iii ); | 466 | computeEvent( event, iii ); |
462 | } | 467 | } |
463 | } | 468 | } |
464 | } | 469 | } |
465 | } | 470 | } |
466 | int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday | 471 | int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday |
467 | for(i = 0; i < NUMDAYS; i++) { | 472 | for(i = 0; i < NUMDAYS; i++) { |
468 | if ( ( (i+startDay) % 7 == 0 ) ) { | 473 | if ( ( (i+startDay) % 7 == 0 ) ) { |
469 | pDays.setBit(i); | 474 | pDays.setBit(i); |
470 | } | 475 | } |
471 | } | 476 | } |
472 | 477 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { | |
473 | #if 0 | 478 | bDays.fill( false); |
474 | // insert due todos | 479 | // insert due todos |
475 | QPtrList<Todo> todos = calendar()->todos( ); | 480 | QPtrList<Todo> todos = mCalendar->todos( ); |
476 | Todo *todo; | 481 | Todo *todo; |
477 | for(todo = todos.first(); todo; todo = todos.next()) { | 482 | for(todo = todos.first(); todo; todo = todos.next()) { |
478 | //insertTodo( todo ); | 483 | //insertTodo( todo ); |
479 | if ( todo->hasDueDate() ) { | 484 | if ( todo->hasDueDate() ) { |
480 | int day = mStartDate.daysTo( todo->dtDue().date() ); | 485 | int day = mStartDate.daysTo( todo->dtDue().date() ); |
486 | if ( day >= 0 && day < timeSpan + 1) { | ||
487 | int i = day; | ||
488 | QString holiStr = mHolidays[i]; | ||
489 | pDays.setBit(i); | ||
490 | if ( !holiStr.isEmpty() ) | ||
491 | holiStr += "\n"; | ||
492 | holiStr += i18n("Todo") + ": "+todo->summary(); | ||
493 | if ( !todo->location().isEmpty() ) | ||
494 | holiStr += " (" + todo->location() + ")"; | ||
495 | bDays.setBit(i); | ||
496 | mHolidays[i] =holiStr ; | ||
497 | eDays.setBit(i); | ||
498 | } | ||
499 | } | ||
500 | } | ||
501 | } | ||
502 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { | ||
503 | bDays.fill( false); | ||
504 | // insert due todos | ||
505 | QPtrList<Journal> todos = mCalendar->journals( ); | ||
506 | Journal *todo; | ||
507 | for(todo = todos.first(); todo; todo = todos.next()) { | ||
508 | int day = mStartDate.daysTo( todo->dtStart().date() ); | ||
481 | if ( day >= 0 && day < timeSpan + 1) { | 509 | if ( day >= 0 && day < timeSpan + 1) { |
482 | (*cells)[day]->insertTodo( todo ); | 510 | int i = day; |
511 | QString holiStr = mHolidays[i]; | ||
512 | pDays.setBit(i); | ||
513 | if ( !holiStr.isEmpty() ) | ||
514 | holiStr += "\n"; | ||
515 | holiStr += i18n("Journal"); | ||
516 | bDays.setBit(i); | ||
517 | mHolidays[i] =holiStr ; | ||
518 | eDays.setBit(i); | ||
519 | |||
483 | } | 520 | } |
484 | } | 521 | } |
485 | } | 522 | } |
486 | #endif | ||
487 | |||
488 | #else | 523 | #else |
489 | //qDebug("KODayMatrix::updateViewTimed "); | 524 | //qDebug("KODayMatrix::updateViewTimed "); |
490 | for(int i = 0; i < NUMDAYS; i++) { | 525 | for(int i = 0; i < NUMDAYS; i++) { |
491 | // if events are set for the day then remember to draw it bold | 526 | // if events are set for the day then remember to draw it bold |
492 | QPtrList<Event> eventlist = mCalendar->events(days[i]); | 527 | QPtrList<Event> eventlist = mCalendar->events(days[i]); |
493 | Event *event; | 528 | Event *event; |
494 | int numEvents = eventlist.count(); | 529 | int numEvents = eventlist.count(); |
495 | QString holiStr = ""; | 530 | QString holiStr = ""; |
496 | bDays.clearBit(i); | 531 | bDays.clearBit(i); |
497 | hDays.clearBit(i); | 532 | hDays.clearBit(i); |
498 | eDays.clearBit(i); | 533 | eDays.clearBit(i); |
499 | for(event=eventlist.first();event != 0;event=eventlist.next()) { | 534 | for(event=eventlist.first();event != 0;event=eventlist.next()) { |
500 | ushort recurType = event->recurrence()->doesRecur(); | 535 | ushort recurType = event->recurrence()->doesRecur(); |
501 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || | 536 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || |
502 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { | 537 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { |
503 | numEvents--; | 538 | numEvents--; |
504 | } | 539 | } |
505 | if ( event->isHoliday()) { | 540 | if ( event->isHoliday()) { |
506 | hDays.setBit(i); | 541 | hDays.setBit(i); |
507 | if ( !holiStr.isEmpty() ) | 542 | if ( !holiStr.isEmpty() ) |
508 | holiStr += "\n"; | 543 | holiStr += "\n"; |
509 | holiStr += event->summary(); | 544 | holiStr += event->summary(); |
510 | if ( !event->location().isEmpty() ) | 545 | if ( !event->location().isEmpty() ) |
511 | holiStr += " (" + event->location() + ")"; | 546 | holiStr += " (" + event->location() + ")"; |
@@ -515,49 +550,51 @@ void KODayMatrix::updateViewTimed() | |||
515 | holiStr += "\n"; | 550 | holiStr += "\n"; |
516 | holiStr += i18n("Birthday") + ": "+event->summary(); | 551 | holiStr += i18n("Birthday") + ": "+event->summary(); |
517 | if ( !event->location().isEmpty() ) | 552 | if ( !event->location().isEmpty() ) |
518 | holiStr += " (" + event->location() + ")"; | 553 | holiStr += " (" + event->location() + ")"; |
519 | bDays.setBit(i); | 554 | bDays.setBit(i); |
520 | } | 555 | } |
521 | } | 556 | } |
522 | if ( numEvents ) | 557 | if ( numEvents ) |
523 | eDays.setBit(i); | 558 | eDays.setBit(i); |
524 | //if it is a holy day then draw it red. Sundays are consider holidays, too | 559 | //if it is a holy day then draw it red. Sundays are consider holidays, too |
525 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || | 560 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || |
526 | !holiStr.isEmpty()) { | 561 | !holiStr.isEmpty()) { |
527 | mHolidays[i] = holiStr; | 562 | mHolidays[i] = holiStr; |
528 | } else { | 563 | } else { |
529 | mHolidays[i] = QString::null; | 564 | mHolidays[i] = QString::null; |
530 | } | 565 | } |
531 | } | 566 | } |
532 | #endif | 567 | #endif |
533 | mRedrawNeeded = true; | 568 | mRedrawNeeded = true; |
534 | if ( ! mPendingUpdateBeforeRepaint ) | 569 | if ( ! mPendingUpdateBeforeRepaint ) |
535 | repaint(false); | 570 | repaint(false); |
536 | } | 571 | } |
537 | void KODayMatrix::updateView(QDate actdate) | 572 | void KODayMatrix::updateView(QDate actdate) |
538 | { | 573 | { |
539 | 574 | if ( mLastView != KOPrefs::instance()->mCurrentDisplayedView ) | |
575 | mRedrawNeeded = true; | ||
576 | mLastView = KOPrefs::instance()->mCurrentDisplayedView; | ||
540 | if ( ! actdate.isValid() ) { | 577 | if ( ! actdate.isValid() ) { |
541 | //qDebug("date not valid "); | 578 | //qDebug("date not valid "); |
542 | return; | 579 | return; |
543 | } | 580 | } |
544 | mDayChanged = false; | 581 | mDayChanged = false; |
545 | //flag to indicate if the starting day of the matrix has changed by this call | 582 | //flag to indicate if the starting day of the matrix has changed by this call |
546 | //mDayChanged = false; | 583 | //mDayChanged = false; |
547 | // if a new startdate is to be set then apply Cornelius's calculation | 584 | // if a new startdate is to be set then apply Cornelius's calculation |
548 | // of the first day to be shown | 585 | // of the first day to be shown |
549 | if (actdate != startdate) { | 586 | if (actdate != startdate) { |
550 | // reset index of selection according to shift of starting date from startdate to actdate | 587 | // reset index of selection according to shift of starting date from startdate to actdate |
551 | if (mSelStart != NOSELECTION) { | 588 | if (mSelStart != NOSELECTION) { |
552 | int tmp = actdate.daysTo(startdate); | 589 | int tmp = actdate.daysTo(startdate); |
553 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; | 590 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; |
554 | // shift selection if new one would be visible at least partly ! | 591 | // shift selection if new one would be visible at least partly ! |
555 | 592 | ||
556 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { | 593 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { |
557 | // nested if is required for next X display pushed from a different month - correction required | 594 | // nested if is required for next X display pushed from a different month - correction required |
558 | // otherwise, for month forward and backward, it must be avoided | 595 | // otherwise, for month forward and backward, it must be avoided |
559 | if( mSelStart > NUMDAYS || mSelStart < 0 ) | 596 | if( mSelStart > NUMDAYS || mSelStart < 0 ) |
560 | mSelStart = mSelStart + tmp; | 597 | mSelStart = mSelStart + tmp; |
561 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) | 598 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) |
562 | mSelEnd = mSelEnd + tmp; | 599 | mSelEnd = mSelEnd + tmp; |
563 | } | 600 | } |
@@ -1031,51 +1068,51 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent) | |||
1031 | } | 1068 | } |
1032 | if ( colModulo ) { | 1069 | if ( colModulo ) { |
1033 | if ( col >= 7 - colModulo ) | 1070 | if ( col >= 7 - colModulo ) |
1034 | addCol = col - 6 + colModulo-1; | 1071 | addCol = col - 6 + colModulo-1; |
1035 | } | 1072 | } |
1036 | 1073 | ||
1037 | addCol += 1; | 1074 | addCol += 1; |
1038 | if ( row == 0 ) | 1075 | if ( row == 0 ) |
1039 | addRow = 1; | 1076 | addRow = 1; |
1040 | p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth+1, dheight+1); | 1077 | p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth+1, dheight+1); |
1041 | p.setPen(tmppen); | 1078 | p.setPen(tmppen); |
1042 | } | 1079 | } |
1043 | 1080 | ||
1044 | // if any events are on that day then draw it using a bold font | 1081 | // if any events are on that day then draw it using a bold font |
1045 | if ( eDays.testBit(i) ) { | 1082 | if ( eDays.testBit(i) ) { |
1046 | QFont myFont = font(); | 1083 | QFont myFont = font(); |
1047 | myFont.setBold(true); | 1084 | myFont.setBold(true); |
1048 | p.setFont(myFont); | 1085 | p.setFont(myFont); |
1049 | } | 1086 | } |
1050 | 1087 | ||
1051 | // if it is a holiday then use the default holiday color | 1088 | // if it is a holiday then use the default holiday color |
1052 | if ( pDays.testBit(i)) { | 1089 | if ( pDays.testBit(i)) { |
1053 | if ( bDays.testBit(i) ) { | 1090 | if ( bDays.testBit(i) ) { |
1054 | if ( hDays.testBit(i) ) | 1091 | if ( hDays.testBit(i) ) |
1055 | p.setPen(QColor(Qt::green)); | 1092 | p.setPen(QColor(0,200,0)); |
1056 | else | 1093 | else |
1057 | p.setPen(QColor(Qt::green).dark()); | 1094 | p.setPen(QColor(Qt::blue)); |
1058 | } else { | 1095 | } else { |
1059 | if (actcol == mDefaultTextColor ) { | 1096 | if (actcol == mDefaultTextColor ) { |
1060 | p.setPen(KOPrefs::instance()->mHolidayColor); | 1097 | p.setPen(KOPrefs::instance()->mHolidayColor); |
1061 | } else { | 1098 | } else { |
1062 | p.setPen(mHolidayColorShaded); | 1099 | p.setPen(mHolidayColorShaded); |
1063 | } | 1100 | } |
1064 | } | 1101 | } |
1065 | } | 1102 | } |
1066 | 1103 | ||
1067 | // draw selected days with special color | 1104 | // draw selected days with special color |
1068 | // DO NOT specially highlight holidays in selection ! | 1105 | // DO NOT specially highlight holidays in selection ! |
1069 | if (i >= mSelStartT && i <= mSelEndT) { | 1106 | if (i >= mSelStartT && i <= mSelEndT) { |
1070 | ;//p.setPen(mSelectedDaysColor); | 1107 | ;//p.setPen(mSelectedDaysColor); |
1071 | } | 1108 | } |
1072 | 1109 | ||
1073 | int addCol = 0; | 1110 | int addCol = 0; |
1074 | int addRow = 0; | 1111 | int addRow = 0; |
1075 | if ( colModulo ) { | 1112 | if ( colModulo ) { |
1076 | if ( col >= 7 - colModulo ) | 1113 | if ( col >= 7 - colModulo ) |
1077 | addCol = col - 7 + colModulo; | 1114 | addCol = col - 7 + colModulo; |
1078 | } | 1115 | } |
1079 | if ( rowModulo ) { | 1116 | if ( rowModulo ) { |
1080 | if ( row >= 6 - rowModulo ) | 1117 | if ( row >= 6 - rowModulo ) |
1081 | addRow = row - 5 + rowModulo; | 1118 | addRow = row - 5 + rowModulo; |