-rw-r--r-- | korganizer/kodaymatrix.cpp | 144 |
1 files changed, 140 insertions, 4 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index c7e1b45..322131f 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp | |||
@@ -114,16 +114,17 @@ KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const | |||
114 | oldH = 0; | 114 | oldH = 0; |
115 | myPix.resize( 150, 120 ); | 115 | myPix.resize( 150, 120 ); |
116 | mRedrawNeeded = true; | 116 | mRedrawNeeded = true; |
117 | mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); | 117 | mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); |
118 | mPendingUpdateBeforeRepaint = false; | 118 | mPendingUpdateBeforeRepaint = false; |
119 | mouseDown = false; | 119 | mouseDown = false; |
120 | // initialize dynamic arrays | 120 | // initialize dynamic arrays |
121 | bDays.resize ( NUMDAYS ); | 121 | bDays.resize ( NUMDAYS ); |
122 | pDays.resize ( NUMDAYS ); | ||
122 | hDays.resize ( NUMDAYS ); | 123 | hDays.resize ( NUMDAYS ); |
123 | eDays.resize ( NUMDAYS ); | 124 | eDays.resize ( NUMDAYS ); |
124 | days = new QDate[NUMDAYS]; | 125 | days = new QDate[NUMDAYS]; |
125 | daylbls = new QString[NUMDAYS]; | 126 | daylbls = new QString[NUMDAYS]; |
126 | //events = new int[NUMDAYS]; | 127 | //events = new int[NUMDAYS]; |
127 | mToolTip = new DynamicTip(this); | 128 | mToolTip = new DynamicTip(this); |
128 | 129 | ||
129 | // set default values used for drawing the matrix | 130 | // set default values used for drawing the matrix |
@@ -335,39 +336,173 @@ void KODayMatrix::recalculateToday() | |||
335 | void KODayMatrix::updateView() | 336 | void KODayMatrix::updateView() |
336 | { | 337 | { |
337 | updateView(startdate); | 338 | updateView(startdate); |
338 | } | 339 | } |
339 | void KODayMatrix::repaintViewTimed() | 340 | void KODayMatrix::repaintViewTimed() |
340 | { | 341 | { |
341 | mRedrawNeeded = true; | 342 | mRedrawNeeded = true; |
342 | bDays.fill( false); | 343 | bDays.fill( false); |
344 | pDays.fill( false); | ||
343 | hDays.fill( false); | 345 | hDays.fill( false); |
344 | eDays.fill( false); | 346 | eDays.fill( false); |
345 | mRepaintTimer->stop(); | 347 | mRepaintTimer->stop(); |
348 | int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday | ||
349 | int i; | ||
350 | for(i = 0; i < NUMDAYS; i++) { | ||
351 | if ( ( (i+startDay) % 7 == 0 ) ) { | ||
352 | pDays.setBit(i); | ||
353 | } | ||
354 | } | ||
346 | repaint(false); | 355 | repaint(false); |
347 | } | 356 | } |
357 | void KODayMatrix::computeEvent(Event *event, int i ) | ||
358 | { | ||
359 | QString holiStr = mHolidays[i]; | ||
360 | if ( event->isHoliday()) { | ||
361 | pDays.setBit(i); | ||
362 | hDays.setBit(i); | ||
363 | if ( !holiStr.isEmpty() ) | ||
364 | holiStr += "\n"; | ||
365 | holiStr += event->summary(); | ||
366 | if ( !event->location().isEmpty() ) | ||
367 | holiStr += " (" + event->location() + ")"; | ||
368 | mHolidays[i] =holiStr ; | ||
369 | } | ||
370 | if ( event->isBirthday()) { | ||
371 | pDays.setBit(i); | ||
372 | if ( !holiStr.isEmpty() ) | ||
373 | holiStr += "\n"; | ||
374 | holiStr += i18n("Birthday") + ": "+event->summary(); | ||
375 | if ( !event->location().isEmpty() ) | ||
376 | holiStr += " (" + event->location() + ")"; | ||
377 | bDays.setBit(i); | ||
378 | mHolidays[i] =holiStr ; | ||
379 | } | ||
380 | eDays.setBit(i); | ||
381 | } | ||
348 | void KODayMatrix::updateViewTimed() | 382 | void KODayMatrix::updateViewTimed() |
349 | { | 383 | { |
350 | mUpdateTimer->stop(); | 384 | mUpdateTimer->stop(); |
351 | if ( !mCalendar ) { | 385 | if ( !mCalendar ) { |
352 | qDebug("NOT CAL "); | 386 | qDebug("NOT CAL "); |
353 | return; | 387 | return; |
354 | } | 388 | } |
389 | #if 1 | ||
390 | |||
391 | int i; | ||
392 | int timeSpan = NUMDAYS-1; | ||
393 | QPtrList<Event> events = mCalendar->events(); | ||
394 | Event *event; | ||
395 | QDateTime dt; | ||
396 | bool ok; | ||
397 | bDays.fill( false); | ||
398 | pDays.fill( false); | ||
399 | hDays.fill( false); | ||
400 | eDays.fill( false); | ||
401 | mHolidays.clear(); | ||
402 | QDate mStartDate = days[0]; | ||
403 | QDate endDate = mStartDate.addDays( timeSpan ); | ||
404 | for( event = events.first(); event; event = events.next() ) { // for event | ||
405 | ushort recurType = event->recurrence()->doesRecur(); | ||
406 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || | ||
407 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { | ||
408 | continue; | ||
409 | } | ||
410 | if ( event->doesRecur() ) { | ||
411 | bool last; | ||
412 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); | ||
413 | QDateTime incidenceEnd; | ||
414 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); | ||
415 | bool invalid = false; | ||
416 | while( true ) { | ||
417 | if ( incidenceStart.isValid() ) { | ||
418 | incidenceEnd = incidenceStart.addDays( eventlen ); | ||
419 | int st = incidenceStart.date().daysTo( endDate ); | ||
420 | if ( st >= 0 ) { // start before timeend | ||
421 | int end = mStartDate.daysTo( incidenceEnd.date() ); | ||
422 | if ( end >= 0 ) { // end after timestart --- got one! | ||
423 | //normalize | ||
424 | st = timeSpan - st; | ||
425 | if ( st < 0 ) st = 0; | ||
426 | if ( end > timeSpan ) end = timeSpan; | ||
427 | int iii; | ||
428 | //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); | ||
429 | for ( iii = st;iii<= end;++iii) { | ||
430 | computeEvent( event, iii ); | ||
431 | } | ||
432 | } | ||
433 | } | ||
434 | } else { | ||
435 | if ( invalid ) | ||
436 | break; | ||
437 | invalid = true; | ||
438 | //qDebug("invalid %s", event->summary().latin1()); | ||
439 | incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; | ||
440 | } | ||
441 | if ( last ) | ||
442 | break; | ||
443 | bool ok; | ||
444 | incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); | ||
445 | if ( ! ok ) | ||
446 | break; | ||
447 | if ( incidenceStart.date() > endDate ) | ||
448 | break; | ||
449 | } | ||
450 | } else { // no recur | ||
451 | int st = event->dtStart().date().daysTo( endDate ); | ||
452 | if ( st >= 0 ) { // start before timeend | ||
453 | int end = mStartDate.daysTo( event->dtEnd().date() ); | ||
454 | if ( end >= 0 ) { // end after timestart --- got one! | ||
455 | //normalize | ||
456 | st = timeSpan - st; | ||
457 | if ( st < 0 ) st = 0; | ||
458 | if ( end > timeSpan ) end = timeSpan; | ||
459 | int iii; | ||
460 | for ( iii = st;iii<= end;++iii) | ||
461 | computeEvent( event, iii ); | ||
462 | } | ||
463 | } | ||
464 | } | ||
465 | } | ||
466 | int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday | ||
467 | for(i = 0; i < NUMDAYS; i++) { | ||
468 | if ( ( (i+startDay) % 7 == 0 ) ) { | ||
469 | pDays.setBit(i); | ||
470 | } | ||
471 | } | ||
472 | |||
473 | #if 0 | ||
474 | // insert due todos | ||
475 | QPtrList<Todo> todos = calendar()->todos( ); | ||
476 | Todo *todo; | ||
477 | for(todo = todos.first(); todo; todo = todos.next()) { | ||
478 | //insertTodo( todo ); | ||
479 | if ( todo->hasDueDate() ) { | ||
480 | int day = mStartDate.daysTo( todo->dtDue().date() ); | ||
481 | if ( day >= 0 && day < timeSpan + 1) { | ||
482 | (*cells)[day]->insertTodo( todo ); | ||
483 | } | ||
484 | } | ||
485 | } | ||
486 | #endif | ||
487 | |||
488 | #else | ||
355 | //qDebug("KODayMatrix::updateViewTimed "); | 489 | //qDebug("KODayMatrix::updateViewTimed "); |
356 | for(int i = 0; i < NUMDAYS; i++) { | 490 | for(int i = 0; i < NUMDAYS; i++) { |
357 | // if events are set for the day then remember to draw it bold | 491 | // if events are set for the day then remember to draw it bold |
358 | QPtrList<Event> eventlist = mCalendar->events(days[i]); | 492 | QPtrList<Event> eventlist = mCalendar->events(days[i]); |
359 | Event *event; | 493 | Event *event; |
360 | int numEvents = eventlist.count(); | 494 | int numEvents = eventlist.count(); |
361 | QString holiStr = ""; | 495 | QString holiStr = ""; |
362 | bDays.clearBit(i); | 496 | bDays.clearBit(i); |
363 | hDays.clearBit(i); | 497 | hDays.clearBit(i); |
364 | eDays.clearBit(i); | 498 | eDays.clearBit(i); |
365 | for(event=eventlist.first();event != 0;event=eventlist.next()) { | 499 | for(event=eventlist.first();event != 0;event=eventlist.next()) { |
500 | qDebug("FFFFFFFFFFFFFFFFFFFFFFFFF "); | ||
366 | ushort recurType = event->recurrence()->doesRecur(); | 501 | ushort recurType = event->recurrence()->doesRecur(); |
367 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || | 502 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || |
368 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { | 503 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { |
369 | numEvents--; | 504 | numEvents--; |
370 | } | 505 | } |
371 | if ( event->isHoliday()) { | 506 | if ( event->isHoliday()) { |
372 | hDays.setBit(i); | 507 | hDays.setBit(i); |
373 | if ( !holiStr.isEmpty() ) | 508 | if ( !holiStr.isEmpty() ) |
@@ -390,16 +525,17 @@ void KODayMatrix::updateViewTimed() | |||
390 | //if it is a holy day then draw it red. Sundays are consider holidays, too | 525 | //if it is a holy day then draw it red. Sundays are consider holidays, too |
391 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || | 526 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || |
392 | !holiStr.isEmpty()) { | 527 | !holiStr.isEmpty()) { |
393 | mHolidays[i] = holiStr; | 528 | mHolidays[i] = holiStr; |
394 | } else { | 529 | } else { |
395 | mHolidays[i] = QString::null; | 530 | mHolidays[i] = QString::null; |
396 | } | 531 | } |
397 | } | 532 | } |
533 | #endif | ||
398 | mRedrawNeeded = true; | 534 | mRedrawNeeded = true; |
399 | if ( ! mPendingUpdateBeforeRepaint ) | 535 | if ( ! mPendingUpdateBeforeRepaint ) |
400 | repaint(false); | 536 | repaint(false); |
401 | } | 537 | } |
402 | void KODayMatrix::updateView(QDate actdate) | 538 | void KODayMatrix::updateView(QDate actdate) |
403 | { | 539 | { |
404 | 540 | ||
405 | if ( ! actdate.isValid() ) { | 541 | if ( ! actdate.isValid() ) { |
@@ -437,17 +573,17 @@ void KODayMatrix::updateView(QDate actdate) | |||
437 | mPendingUpdateBeforeRepaint = true; | 573 | mPendingUpdateBeforeRepaint = true; |
438 | } else { | 574 | } else { |
439 | #ifdef DESKTOP_VERSION | 575 | #ifdef DESKTOP_VERSION |
440 | //mRepaintTimer->start( 100 ); | 576 | //mRepaintTimer->start( 100 ); |
441 | //updateViewTimed(); | 577 | //updateViewTimed(); |
442 | mUpdateTimer->start( 50 ); | 578 | mUpdateTimer->start( 50 ); |
443 | #else | 579 | #else |
444 | mRepaintTimer->start( 350 ); | 580 | mRepaintTimer->start( 350 ); |
445 | mUpdateTimer->start( 1200 ); | 581 | mUpdateTimer->start( 800 ); |
446 | #endif | 582 | #endif |
447 | } | 583 | } |
448 | } | 584 | } |
449 | void KODayMatrix::updateEvents() | 585 | void KODayMatrix::updateEvents() |
450 | { | 586 | { |
451 | if ( !mCalendar ) return; | 587 | if ( !mCalendar ) return; |
452 | 588 | ||
453 | for( int i = 0; i < NUMDAYS; i++ ) { | 589 | for( int i = 0; i < NUMDAYS; i++ ) { |
@@ -868,17 +1004,17 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent) | |||
868 | if (today == i) { | 1004 | if (today == i) { |
869 | tmppen = p.pen(); | 1005 | tmppen = p.pen(); |
870 | QPen mTodayPen(p.pen()); | 1006 | QPen mTodayPen(p.pen()); |
871 | if ( daysize.width() < 20 ) | 1007 | if ( daysize.width() < 20 ) |
872 | mTodayPen.setWidth(1); | 1008 | mTodayPen.setWidth(1); |
873 | else | 1009 | else |
874 | mTodayPen.setWidth(mTodayMarginWidth); | 1010 | mTodayPen.setWidth(mTodayMarginWidth); |
875 | //draw red rectangle for holidays | 1011 | //draw red rectangle for holidays |
876 | if (!mHolidays[i].isNull()) { | 1012 | if (pDays.testBit(i)) { |
877 | if (actcol == mDefaultTextColor) { | 1013 | if (actcol == mDefaultTextColor) { |
878 | mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); | 1014 | mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); |
879 | } else { | 1015 | } else { |
880 | mTodayPen.setColor(mHolidayColorShaded); | 1016 | mTodayPen.setColor(mHolidayColorShaded); |
881 | } | 1017 | } |
882 | } | 1018 | } |
883 | //draw gray rectangle for today if in selection | 1019 | //draw gray rectangle for today if in selection |
884 | if (i >= mSelStartT && i <= mSelEndT) { | 1020 | if (i >= mSelStartT && i <= mSelEndT) { |
@@ -909,17 +1045,17 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent) | |||
909 | // if any events are on that day then draw it using a bold font | 1045 | // if any events are on that day then draw it using a bold font |
910 | if ( eDays.testBit(i) ) { | 1046 | if ( eDays.testBit(i) ) { |
911 | QFont myFont = font(); | 1047 | QFont myFont = font(); |
912 | myFont.setBold(true); | 1048 | myFont.setBold(true); |
913 | p.setFont(myFont); | 1049 | p.setFont(myFont); |
914 | } | 1050 | } |
915 | 1051 | ||
916 | // if it is a holiday then use the default holiday color | 1052 | // if it is a holiday then use the default holiday color |
917 | if ( !mHolidays[i].isNull()) { | 1053 | if ( pDays.testBit(i)) { |
918 | if ( bDays.testBit(i) ) { | 1054 | if ( bDays.testBit(i) ) { |
919 | if ( hDays.testBit(i) ) | 1055 | if ( hDays.testBit(i) ) |
920 | p.setPen(QColor(Qt::green)); | 1056 | p.setPen(QColor(Qt::green)); |
921 | else | 1057 | else |
922 | p.setPen(QColor(Qt::green).dark()); | 1058 | p.setPen(QColor(Qt::green).dark()); |
923 | } else { | 1059 | } else { |
924 | if (actcol == mDefaultTextColor ) { | 1060 | if (actcol == mDefaultTextColor ) { |
925 | p.setPen(KOPrefs::instance()->mHolidayColor); | 1061 | p.setPen(KOPrefs::instance()->mHolidayColor); |
@@ -948,17 +1084,17 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent) | |||
948 | //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); | 1084 | //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); |
949 | ++addCol;//++addCol; | 1085 | ++addCol;//++addCol; |
950 | if ( row == 0) | 1086 | if ( row == 0) |
951 | addRow = 1; | 1087 | addRow = 1; |
952 | p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, | 1088 | p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, |
953 | Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); | 1089 | Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); |
954 | 1090 | ||
955 | // reset color to actual color | 1091 | // reset color to actual color |
956 | if (!mHolidays[i].isNull()) { | 1092 | if (pDays.testBit(i)) { |
957 | p.setPen(actcol); | 1093 | p.setPen(actcol); |
958 | } | 1094 | } |
959 | // reset bold font to plain font | 1095 | // reset bold font to plain font |
960 | if ( eDays.testBit(i)) { | 1096 | if ( eDays.testBit(i)) { |
961 | QFont myFont = font(); | 1097 | QFont myFont = font(); |
962 | myFont.setBold(false); | 1098 | myFont.setBold(false); |
963 | p.setFont(myFont); | 1099 | p.setFont(myFont); |
964 | } | 1100 | } |