-rw-r--r-- | korganizer/kodaymatrix.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index d543aaf..dfc6af7 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp | |||
@@ -65,96 +65,97 @@ public: | |||
65 | KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;}; | 65 | KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;}; |
66 | ~KODaymatrixWhatsThis() { ; }; | 66 | ~KODaymatrixWhatsThis() { ; }; |
67 | 67 | ||
68 | protected: | 68 | protected: |
69 | virtual QString text( const QPoint& p ) | 69 | virtual QString text( const QPoint& p ) |
70 | { | 70 | { |
71 | return _view->getWhatsThisText( p ) ; | 71 | return _view->getWhatsThisText( p ) ; |
72 | } | 72 | } |
73 | private: | 73 | private: |
74 | KODayMatrix * _view; | 74 | KODayMatrix * _view; |
75 | }; | 75 | }; |
76 | 76 | ||
77 | void DynamicTip::maybeTip( const QPoint &pos ) | 77 | void DynamicTip::maybeTip( const QPoint &pos ) |
78 | { | 78 | { |
79 | //calculate which cell of the matrix the mouse is in | 79 | //calculate which cell of the matrix the mouse is in |
80 | QRect sz = matrix->frameRect(); | 80 | QRect sz = matrix->frameRect(); |
81 | int dheight = sz.height()*7 / 42; | 81 | int dheight = sz.height()*7 / 42; |
82 | int dwidth = sz.width() / 7; | 82 | int dwidth = sz.width() / 7; |
83 | int row = pos.y()/dheight; | 83 | int row = pos.y()/dheight; |
84 | int col = pos.x()/dwidth; | 84 | int col = pos.x()/dwidth; |
85 | 85 | ||
86 | QRect rct(col*dwidth, row*dheight, dwidth, dheight); | 86 | QRect rct(col*dwidth, row*dheight, dwidth, dheight); |
87 | 87 | ||
88 | // kdDebug() << "DynamicTip::maybeTip matrix cell index [" << | 88 | // kdDebug() << "DynamicTip::maybeTip matrix cell index [" << |
89 | // col << "][" << row << "] => " <<(col+row*7) << endl; | 89 | // col << "][" << row << "] => " <<(col+row*7) << endl; |
90 | 90 | ||
91 | //show holiday names only | 91 | //show holiday names only |
92 | QString str = matrix->getHolidayLabel(col+row*7); | 92 | QString str = matrix->getHolidayLabel(col+row*7); |
93 | if (str.isEmpty()) return; | 93 | if (str.isEmpty()) return; |
94 | tip(rct, str); | 94 | tip(rct, str); |
95 | } | 95 | } |
96 | 96 | ||
97 | 97 | ||
98 | // ============================================================================ | 98 | // ============================================================================ |
99 | // K O D A Y M A T R I X | 99 | // K O D A Y M A T R I X |
100 | // ============================================================================ | 100 | // ============================================================================ |
101 | 101 | ||
102 | const int KODayMatrix::NOSELECTION = -1000; | 102 | const int KODayMatrix::NOSELECTION = -1000; |
103 | const int KODayMatrix::NUMDAYS = 42; | 103 | const int KODayMatrix::NUMDAYS = 42; |
104 | 104 | ||
105 | KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) | 105 | KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) |
106 | : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 ) | 106 | : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 ) |
107 | 107 | ||
108 | #if 0 | 108 | #if 0 |
109 | KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : | 109 | KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : |
110 | QFrame(parent, name) | 110 | QFrame(parent, name) |
111 | #endif | 111 | #endif |
112 | { | 112 | { |
113 | mRedrawNeeded = true; | ||
113 | mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); | 114 | mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); |
114 | mPendingUpdateBeforeRepaint = false; | 115 | mPendingUpdateBeforeRepaint = false; |
115 | mouseDown = false; | 116 | mouseDown = false; |
116 | // initialize dynamic arrays | 117 | // initialize dynamic arrays |
117 | bDays.resize ( NUMDAYS ); | 118 | bDays.resize ( NUMDAYS ); |
118 | hDays.resize ( NUMDAYS );; | 119 | hDays.resize ( NUMDAYS );; |
119 | eDays.resize ( NUMDAYS );; | 120 | eDays.resize ( NUMDAYS );; |
120 | days = new QDate[NUMDAYS]; | 121 | days = new QDate[NUMDAYS]; |
121 | daylbls = new QString[NUMDAYS]; | 122 | daylbls = new QString[NUMDAYS]; |
122 | //events = new int[NUMDAYS]; | 123 | //events = new int[NUMDAYS]; |
123 | mToolTip = new DynamicTip(this); | 124 | mToolTip = new DynamicTip(this); |
124 | 125 | ||
125 | // set default values used for drawing the matrix | 126 | // set default values used for drawing the matrix |
126 | mDefaultBackColor = palette().active().base(); | 127 | mDefaultBackColor = palette().active().base(); |
127 | mDefaultTextColor = palette().active().foreground(); | 128 | mDefaultTextColor = palette().active().foreground(); |
128 | mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); | 129 | mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); |
129 | mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); | 130 | mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); |
130 | mSelectedDaysColor = QColor("white"); | 131 | mSelectedDaysColor = QColor("white"); |
131 | mTodayMarginWidth = 2; | 132 | mTodayMarginWidth = 2; |
132 | mSelEnd = mSelStart = NOSELECTION; | 133 | mSelEnd = mSelStart = NOSELECTION; |
133 | 134 | ||
134 | setAcceptDrops(true); | 135 | setAcceptDrops(true); |
135 | //setFont( QFont("Arial", 10) ); | 136 | //setFont( QFont("Arial", 10) ); |
136 | 137 | ||
137 | mUpdateTimer = new QTimer( this ); | 138 | mUpdateTimer = new QTimer( this ); |
138 | connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); | 139 | connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); |
139 | mRepaintTimer = new QTimer( this ); | 140 | mRepaintTimer = new QTimer( this ); |
140 | connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); | 141 | connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); |
141 | mDayChanged = false; | 142 | mDayChanged = false; |
142 | updateView(); | 143 | updateView(); |
143 | } | 144 | } |
144 | QString KODayMatrix::getWhatsThisText( QPoint p ) | 145 | QString KODayMatrix::getWhatsThisText( QPoint p ) |
145 | { | 146 | { |
146 | 147 | ||
147 | int tmp = getDayIndexFrom(p.x(), p.y()); | 148 | int tmp = getDayIndexFrom(p.x(), p.y()); |
148 | if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) | 149 | if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) |
149 | return QString(); | 150 | return QString(); |
150 | QDate mDate = days[tmp]; | 151 | QDate mDate = days[tmp]; |
151 | QPtrList<Event> eventlist = mCalendar->events(mDate); | 152 | QPtrList<Event> eventlist = mCalendar->events(mDate); |
152 | Event *event; | 153 | Event *event; |
153 | QStringList mToolTip; | 154 | QStringList mToolTip; |
154 | for(event=eventlist.first();event != 0;event=eventlist.next()) { | 155 | for(event=eventlist.first();event != 0;event=eventlist.next()) { |
155 | QString mToolTipText; | 156 | QString mToolTipText; |
156 | QString text; | 157 | QString text; |
157 | int multiday = 0;// 1 = start, 2 = midddle, 3 = end day | 158 | int multiday = 0;// 1 = start, 2 = midddle, 3 = end day |
158 | if (event->isMultiDay()) { | 159 | if (event->isMultiDay()) { |
159 | QString prefix = "<->";multiday = 2; | 160 | QString prefix = "<->";multiday = 2; |
160 | QString time; | 161 | QString time; |
@@ -341,139 +342,141 @@ void KODayMatrix::updateViewTimed() | |||
341 | mUpdateTimer->stop(); | 342 | mUpdateTimer->stop(); |
342 | if ( !mCalendar ) { | 343 | if ( !mCalendar ) { |
343 | qDebug("NOT CAL "); | 344 | qDebug("NOT CAL "); |
344 | return; | 345 | return; |
345 | } | 346 | } |
346 | //qDebug("KODayMatrix::updateViewTimed "); | 347 | //qDebug("KODayMatrix::updateViewTimed "); |
347 | for(int i = 0; i < NUMDAYS; i++) { | 348 | for(int i = 0; i < NUMDAYS; i++) { |
348 | // if events are set for the day then remember to draw it bold | 349 | // if events are set for the day then remember to draw it bold |
349 | QPtrList<Event> eventlist = mCalendar->events(days[i]); | 350 | QPtrList<Event> eventlist = mCalendar->events(days[i]); |
350 | Event *event; | 351 | Event *event; |
351 | int numEvents = eventlist.count(); | 352 | int numEvents = eventlist.count(); |
352 | QString holiStr = ""; | 353 | QString holiStr = ""; |
353 | bDays.clearBit(i); | 354 | bDays.clearBit(i); |
354 | hDays.clearBit(i); | 355 | hDays.clearBit(i); |
355 | eDays.clearBit(i); | 356 | eDays.clearBit(i); |
356 | for(event=eventlist.first();event != 0;event=eventlist.next()) { | 357 | for(event=eventlist.first();event != 0;event=eventlist.next()) { |
357 | ushort recurType = event->recurrence()->doesRecur(); | 358 | ushort recurType = event->recurrence()->doesRecur(); |
358 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || | 359 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || |
359 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { | 360 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { |
360 | numEvents--; | 361 | numEvents--; |
361 | } | 362 | } |
362 | if ( event->isHoliday()) { | 363 | if ( event->isHoliday()) { |
363 | hDays.setBit(i); | 364 | hDays.setBit(i); |
364 | if ( !holiStr.isEmpty() ) | 365 | if ( !holiStr.isEmpty() ) |
365 | holiStr += "\n"; | 366 | holiStr += "\n"; |
366 | holiStr += event->summary(); | 367 | holiStr += event->summary(); |
367 | if ( !event->location().isEmpty() ) | 368 | if ( !event->location().isEmpty() ) |
368 | holiStr += " (" + event->location() + ")"; | 369 | holiStr += " (" + event->location() + ")"; |
369 | } | 370 | } |
370 | if ( event->isBirthday()) { | 371 | if ( event->isBirthday()) { |
371 | if ( !holiStr.isEmpty() ) | 372 | if ( !holiStr.isEmpty() ) |
372 | holiStr += "\n"; | 373 | holiStr += "\n"; |
373 | holiStr += i18n("Birthday") + ": "+event->summary(); | 374 | holiStr += i18n("Birthday") + ": "+event->summary(); |
374 | if ( !event->location().isEmpty() ) | 375 | if ( !event->location().isEmpty() ) |
375 | holiStr += " (" + event->location() + ")"; | 376 | holiStr += " (" + event->location() + ")"; |
376 | bDays.setBit(i); | 377 | bDays.setBit(i); |
377 | } | 378 | } |
378 | } | 379 | } |
379 | if ( numEvents ) | 380 | if ( numEvents ) |
380 | eDays.setBit(i); | 381 | eDays.setBit(i); |
381 | //if it is a holy day then draw it red. Sundays are consider holidays, too | 382 | //if it is a holy day then draw it red. Sundays are consider holidays, too |
382 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || | 383 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || |
383 | !holiStr.isEmpty()) { | 384 | !holiStr.isEmpty()) { |
384 | mHolidays[i] = holiStr; | 385 | mHolidays[i] = holiStr; |
385 | } else { | 386 | } else { |
386 | mHolidays[i] = QString::null; | 387 | mHolidays[i] = QString::null; |
387 | } | 388 | } |
388 | } | 389 | } |
390 | mRedrawNeeded = true; | ||
389 | if ( ! mPendingUpdateBeforeRepaint ) | 391 | if ( ! mPendingUpdateBeforeRepaint ) |
390 | repaint(false); | 392 | repaint(false); |
391 | } | 393 | } |
392 | void KODayMatrix::updateView(QDate actdate) | 394 | void KODayMatrix::updateView(QDate actdate) |
393 | { | 395 | { |
394 | 396 | ||
395 | if ( ! actdate.isValid() ) { | 397 | if ( ! actdate.isValid() ) { |
396 | //qDebug("date not valid "); | 398 | //qDebug("date not valid "); |
397 | return; | 399 | return; |
398 | } | 400 | } |
399 | mDayChanged = false; | 401 | mDayChanged = false; |
400 | //flag to indicate if the starting day of the matrix has changed by this call | 402 | //flag to indicate if the starting day of the matrix has changed by this call |
401 | //mDayChanged = false; | 403 | //mDayChanged = false; |
402 | // if a new startdate is to be set then apply Cornelius's calculation | 404 | // if a new startdate is to be set then apply Cornelius's calculation |
403 | // of the first day to be shown | 405 | // of the first day to be shown |
404 | if (actdate != startdate) { | 406 | if (actdate != startdate) { |
405 | // reset index of selection according to shift of starting date from startdate to actdate | 407 | // reset index of selection according to shift of starting date from startdate to actdate |
406 | if (mSelStart != NOSELECTION) { | 408 | if (mSelStart != NOSELECTION) { |
407 | int tmp = actdate.daysTo(startdate); | 409 | int tmp = actdate.daysTo(startdate); |
408 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; | 410 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; |
409 | // shift selection if new one would be visible at least partly ! | 411 | // shift selection if new one would be visible at least partly ! |
410 | 412 | ||
411 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { | 413 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { |
412 | // nested if is required for next X display pushed from a different month - correction required | 414 | // nested if is required for next X display pushed from a different month - correction required |
413 | // otherwise, for month forward and backward, it must be avoided | 415 | // otherwise, for month forward and backward, it must be avoided |
414 | if( mSelStart > NUMDAYS || mSelStart < 0 ) | 416 | if( mSelStart > NUMDAYS || mSelStart < 0 ) |
415 | mSelStart = mSelStart + tmp; | 417 | mSelStart = mSelStart + tmp; |
416 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) | 418 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) |
417 | mSelEnd = mSelEnd + tmp; | 419 | mSelEnd = mSelEnd + tmp; |
418 | } | 420 | } |
419 | } | 421 | } |
420 | startdate = actdate; | 422 | startdate = actdate; |
421 | mDayChanged = true; | 423 | mDayChanged = true; |
422 | recalculateToday(); | 424 | recalculateToday(); |
425 | mRedrawNeeded = true; | ||
423 | } | 426 | } |
424 | //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); | 427 | //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); |
425 | if ( !isVisible() ) { | 428 | if ( !isVisible() ) { |
426 | mPendingUpdateBeforeRepaint = true; | 429 | mPendingUpdateBeforeRepaint = true; |
427 | } else { | 430 | } else { |
428 | #ifdef DESKTOP_VERSION | 431 | #ifdef DESKTOP_VERSION |
429 | //mRepaintTimer->start( 100 ); | 432 | //mRepaintTimer->start( 100 ); |
430 | //updateViewTimed(); | 433 | //updateViewTimed(); |
431 | mUpdateTimer->start( 20 ); | 434 | mUpdateTimer->start( 50 ); |
432 | #else | 435 | #else |
433 | mRepaintTimer->start( 350 ); | 436 | mRepaintTimer->start( 350 ); |
434 | mUpdateTimer->start( 1200 ); | 437 | mUpdateTimer->start( 1200 ); |
435 | #endif | 438 | #endif |
436 | } | 439 | } |
437 | } | 440 | } |
438 | void KODayMatrix::updateEvents() | 441 | void KODayMatrix::updateEvents() |
439 | { | 442 | { |
440 | if ( !mCalendar ) return; | 443 | if ( !mCalendar ) return; |
441 | 444 | ||
442 | for( int i = 0; i < NUMDAYS; i++ ) { | 445 | for( int i = 0; i < NUMDAYS; i++ ) { |
443 | // if events are set for the day then remember to draw it bold | 446 | // if events are set for the day then remember to draw it bold |
444 | QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); | 447 | QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); |
445 | int numEvents = eventlist.count(); | 448 | int numEvents = eventlist.count(); |
446 | Event *event; | 449 | Event *event; |
447 | for( event = eventlist.first(); event != 0;event=eventlist.next()) { | 450 | for( event = eventlist.first(); event != 0;event=eventlist.next()) { |
448 | ushort recurType = event->doesRecur(); | 451 | ushort recurType = event->doesRecur(); |
449 | 452 | ||
450 | if ( ( recurType == Recurrence::rDaily && | 453 | if ( ( recurType == Recurrence::rDaily && |
451 | !KOPrefs::instance()->mDailyRecur ) || | 454 | !KOPrefs::instance()->mDailyRecur ) || |
452 | ( recurType == Recurrence::rWeekly && | 455 | ( recurType == Recurrence::rWeekly && |
453 | !KOPrefs::instance()->mWeeklyRecur ) ) { | 456 | !KOPrefs::instance()->mWeeklyRecur ) ) { |
454 | numEvents--; | 457 | numEvents--; |
455 | } | 458 | } |
456 | } | 459 | } |
457 | if ( numEvents ) | 460 | if ( numEvents ) |
458 | eDays.setBit(i); | 461 | eDays.setBit(i); |
459 | else | 462 | else |
460 | eDays.clearBit(i); | 463 | eDays.clearBit(i); |
461 | } | 464 | } |
462 | } | 465 | } |
463 | 466 | ||
464 | const QDate& KODayMatrix::getDate(int offset) | 467 | const QDate& KODayMatrix::getDate(int offset) |
465 | { | 468 | { |
466 | if (offset < 0 || offset > NUMDAYS-1) { | 469 | if (offset < 0 || offset > NUMDAYS-1) { |
467 | qDebug("Wrong offset2 %d", offset); | 470 | qDebug("Wrong offset2 %d", offset); |
468 | return days[0]; | 471 | return days[0]; |
469 | } | 472 | } |
470 | return days[offset]; | 473 | return days[offset]; |
471 | } | 474 | } |
472 | 475 | ||
473 | QString KODayMatrix::getHolidayLabel(int offset) | 476 | QString KODayMatrix::getHolidayLabel(int offset) |
474 | { | 477 | { |
475 | if (offset < 0 || offset > NUMDAYS-1) { | 478 | if (offset < 0 || offset > NUMDAYS-1) { |
476 | qDebug("Wrong offset1 %d", offset); | 479 | qDebug("Wrong offset1 %d", offset); |
477 | return QString(); | 480 | return QString(); |
478 | } | 481 | } |
479 | return mHolidays[offset]; | 482 | return mHolidays[offset]; |
@@ -633,97 +636,101 @@ void KODayMatrix::dropEvent(QDropEvent *e) | |||
633 | if(existingEvent) { | 636 | if(existingEvent) { |
634 | // uniquify event | 637 | // uniquify event |
635 | event->recreate(); | 638 | event->recreate(); |
636 | /* | 639 | /* |
637 | KMessageBox::sorry(this, | 640 | KMessageBox::sorry(this, |
638 | i18n("Event already exists in this calendar."), | 641 | i18n("Event already exists in this calendar."), |
639 | i18n("Drop Event")); | 642 | i18n("Drop Event")); |
640 | delete event; | 643 | delete event; |
641 | return; | 644 | return; |
642 | */ | 645 | */ |
643 | } | 646 | } |
644 | // kdDebug() << "Drop new Event" << endl; | 647 | // kdDebug() << "Drop new Event" << endl; |
645 | // Adjust date | 648 | // Adjust date |
646 | QDateTime start = event->dtStart(); | 649 | QDateTime start = event->dtStart(); |
647 | QDateTime end = event->dtEnd(); | 650 | QDateTime end = event->dtEnd(); |
648 | int duration = start.daysTo(end); | 651 | int duration = start.daysTo(end); |
649 | int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); | 652 | int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); |
650 | 653 | ||
651 | start.setDate(days[idx]); | 654 | start.setDate(days[idx]); |
652 | end.setDate(days[idx].addDays(duration)); | 655 | end.setDate(days[idx].addDays(duration)); |
653 | 656 | ||
654 | event->setDtStart(start); | 657 | event->setDtStart(start); |
655 | event->setDtEnd(end); | 658 | event->setDtEnd(end); |
656 | mCalendar->addEvent(event); | 659 | mCalendar->addEvent(event); |
657 | 660 | ||
658 | emit eventDropped(event); | 661 | emit eventDropped(event); |
659 | } else { | 662 | } else { |
660 | // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; | 663 | // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; |
661 | e->ignore(); | 664 | e->ignore(); |
662 | } | 665 | } |
663 | #endif | 666 | #endif |
664 | } | 667 | } |
665 | 668 | ||
666 | // ---------------------------------------------------------------------------- | 669 | // ---------------------------------------------------------------------------- |
667 | // P A I N T E V E N T H A N D L I N G | 670 | // P A I N T E V E N T H A N D L I N G |
668 | // ---------------------------------------------------------------------------- | 671 | // ---------------------------------------------------------------------------- |
669 | 672 | ||
670 | void KODayMatrix::paintEvent(QPaintEvent * pevent) | 673 | void KODayMatrix::paintEvent(QPaintEvent * pevent) |
671 | { | 674 | { |
672 | 675 | ||
673 | if ( width() <= 0 || height() <= 0 ) | 676 | if ( width() <= 0 || height() <= 0 ) |
674 | return; | 677 | return; |
675 | if ( mPendingUpdateBeforeRepaint ) { | 678 | if ( mPendingUpdateBeforeRepaint ) { |
676 | updateViewTimed(); | 679 | updateViewTimed(); |
677 | mPendingUpdateBeforeRepaint = false; | 680 | mPendingUpdateBeforeRepaint = false; |
678 | } | 681 | } |
679 | if ( myPix.width() != width() || myPix.height()!=height() ) { | 682 | if ( myPix.width() != width() || myPix.height()!=height() ) { |
680 | myPix.resize(size() ); | 683 | myPix.resize(size() ); |
684 | mRedrawNeeded = true; | ||
681 | } | 685 | } |
686 | |||
687 | if ( mRedrawNeeded ) { | ||
688 | //qDebug("REDRAW "); | ||
682 | QPainter p(&myPix); | 689 | QPainter p(&myPix); |
683 | p.setFont(font()); | 690 | p.setFont(font()); |
684 | 691 | ||
685 | 692 | ||
686 | int dheight = daysize.height(); | 693 | int dheight = daysize.height(); |
687 | int dwidth = daysize.width(); | 694 | int dwidth = daysize.width(); |
688 | int row,col; | 695 | int row,col; |
689 | int selw, selh; | 696 | int selw, selh; |
690 | int xyOff = frameWidth(); | 697 | int xyOff = frameWidth(); |
691 | int colModulo = (width()-2) % 7; | 698 | int colModulo = (width()-2) % 7; |
692 | int rowModulo = (height()-2) % 6; | 699 | int rowModulo = (height()-2) % 6; |
693 | //qDebug("col %d row %d ",colModulo,rowModulo ); | 700 | //qDebug("col %d row %d ",colModulo,rowModulo ); |
694 | 701 | ||
695 | bool isRTL = KOGlobals::self()->reverseLayout(); | 702 | bool isRTL = KOGlobals::self()->reverseLayout(); |
696 | 703 | ||
697 | // draw background and topleft frame | 704 | // draw background and topleft frame |
698 | p.fillRect(0,0,width(),height(), mDefaultBackColor); | 705 | p.fillRect(0,0,width(),height(), mDefaultBackColor); |
699 | p.setPen(mDefaultTextColor); | 706 | p.setPen(mDefaultTextColor); |
700 | p.drawRect(0, 0, width(), height()); | 707 | p.drawRect(0, 0, width(), height()); |
701 | int mSelStartT = mSelStart; | 708 | int mSelStartT = mSelStart; |
702 | int mSelEndT = mSelEnd; | 709 | int mSelEndT = mSelEnd; |
703 | if ( mSelEndT >= NUMDAYS ) | 710 | if ( mSelEndT >= NUMDAYS ) |
704 | mSelEndT = NUMDAYS-1; | 711 | mSelEndT = NUMDAYS-1; |
705 | // draw selected days with highlighted background color | 712 | // draw selected days with highlighted background color |
706 | if (mSelStart != NOSELECTION) { | 713 | if (mSelStart != NOSELECTION) { |
707 | bool skip = false; | 714 | bool skip = false; |
708 | if ( ! mouseDown ) { | 715 | if ( ! mouseDown ) { |
709 | int mo = days[20].month(); | 716 | int mo = days[20].month(); |
710 | //qDebug("-- %d %d ", mSelStartT, mSelEndT); | 717 | //qDebug("-- %d %d ", mSelStartT, mSelEndT); |
711 | //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); | 718 | //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); |
712 | int startMo = days[mSelStartT].month(); | 719 | int startMo = days[mSelStartT].month(); |
713 | int endMo = days[mSelEndT].month(); | 720 | int endMo = days[mSelEndT].month(); |
714 | if ( startMo == 12 && mo == 1 && endMo <= 2 ) | 721 | if ( startMo == 12 && mo == 1 && endMo <= 2 ) |
715 | startMo = 1; | 722 | startMo = 1; |
716 | if ( endMo == 1 && mo == 12 ) | 723 | if ( endMo == 1 && mo == 12 ) |
717 | endMo = 12; | 724 | endMo = 12; |
718 | if ( mo == 12 && startMo == 1 ) | 725 | if ( mo == 12 && startMo == 1 ) |
719 | startMo = 13; | 726 | startMo = 13; |
720 | if ( (startMo > mo || endMo < mo) ) { | 727 | if ( (startMo > mo || endMo < mo) ) { |
721 | skip = true; | 728 | skip = true; |
722 | } else { | 729 | } else { |
723 | if ( days[mSelStartT].month() != mo ) { | 730 | if ( days[mSelStartT].month() != mo ) { |
724 | int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); | 731 | int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); |
725 | mSelStartT += add +1; | 732 | mSelStartT += add +1; |
726 | } | 733 | } |
727 | if ( days[mSelEndT].month() != mo ) { | 734 | if ( days[mSelEndT].month() != mo ) { |
728 | int sub = days[mSelEndT].day(); | 735 | int sub = days[mSelEndT].day(); |
729 | mSelEndT -= sub ; | 736 | mSelEndT -= sub ; |
@@ -882,74 +889,76 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent) | |||
882 | if ( bDays.testBit(i) ) { | 889 | if ( bDays.testBit(i) ) { |
883 | if ( hDays.testBit(i) ) | 890 | if ( hDays.testBit(i) ) |
884 | p.setPen(QColor(Qt::green)); | 891 | p.setPen(QColor(Qt::green)); |
885 | else | 892 | else |
886 | p.setPen(QColor(Qt::green).dark()); | 893 | p.setPen(QColor(Qt::green).dark()); |
887 | } else { | 894 | } else { |
888 | if (actcol == mDefaultTextColor ) { | 895 | if (actcol == mDefaultTextColor ) { |
889 | p.setPen(KOPrefs::instance()->mHolidayColor); | 896 | p.setPen(KOPrefs::instance()->mHolidayColor); |
890 | } else { | 897 | } else { |
891 | p.setPen(mHolidayColorShaded); | 898 | p.setPen(mHolidayColorShaded); |
892 | } | 899 | } |
893 | } | 900 | } |
894 | } | 901 | } |
895 | 902 | ||
896 | // draw selected days with special color | 903 | // draw selected days with special color |
897 | // DO NOT specially highlight holidays in selection ! | 904 | // DO NOT specially highlight holidays in selection ! |
898 | if (i >= mSelStartT && i <= mSelEndT) { | 905 | if (i >= mSelStartT && i <= mSelEndT) { |
899 | ;//p.setPen(mSelectedDaysColor); | 906 | ;//p.setPen(mSelectedDaysColor); |
900 | } | 907 | } |
901 | 908 | ||
902 | int addCol = 0; | 909 | int addCol = 0; |
903 | int addRow = 0; | 910 | int addRow = 0; |
904 | if ( colModulo ) { | 911 | if ( colModulo ) { |
905 | if ( col >= 7 - colModulo ) | 912 | if ( col >= 7 - colModulo ) |
906 | addCol = col - 7 + colModulo; | 913 | addCol = col - 7 + colModulo; |
907 | } | 914 | } |
908 | if ( rowModulo ) { | 915 | if ( rowModulo ) { |
909 | if ( row >= 6 - rowModulo ) | 916 | if ( row >= 6 - rowModulo ) |
910 | addRow = row - 5 + rowModulo; | 917 | addRow = row - 5 + rowModulo; |
911 | } | 918 | } |
912 | //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); | 919 | //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); |
913 | ++addCol;//++addCol; | 920 | ++addCol;//++addCol; |
914 | if ( row == 0) | 921 | if ( row == 0) |
915 | addRow = 1; | 922 | addRow = 1; |
916 | p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, | 923 | p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, |
917 | Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); | 924 | Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); |
918 | 925 | ||
919 | // reset color to actual color | 926 | // reset color to actual color |
920 | if (!mHolidays[i].isNull()) { | 927 | if (!mHolidays[i].isNull()) { |
921 | p.setPen(actcol); | 928 | p.setPen(actcol); |
922 | } | 929 | } |
923 | // reset bold font to plain font | 930 | // reset bold font to plain font |
924 | if ( eDays.testBit(i)) { | 931 | if ( eDays.testBit(i)) { |
925 | QFont myFont = font(); | 932 | QFont myFont = font(); |
926 | myFont.setBold(false); | 933 | myFont.setBold(false); |
927 | p.setFont(myFont); | 934 | p.setFont(myFont); |
928 | } | 935 | } |
929 | } | 936 | } |
930 | int off = 0;//xyOff; | 937 | } else { |
931 | bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP); | 938 | //qDebug("NO redraw "); |
932 | //qDebug("ffffffffff %d ", off); | 939 | } |
940 | bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP); | ||
941 | mRedrawNeeded = false; | ||
933 | } | 942 | } |
934 | 943 | ||
935 | // ---------------------------------------------------------------------------- | 944 | // ---------------------------------------------------------------------------- |
936 | // R E SI Z E E V E N T H A N D L I N G | 945 | // R E SI Z E E V E N T H A N D L I N G |
937 | // ---------------------------------------------------------------------------- | 946 | // ---------------------------------------------------------------------------- |
938 | 947 | ||
939 | void KODayMatrix::resizeEvent(QResizeEvent *) | 948 | void KODayMatrix::resizeEvent(QResizeEvent *) |
940 | { | 949 | { |
941 | QRect sz = frameRect(); | 950 | QRect sz = frameRect(); |
942 | daysize.setHeight(sz.height()*7 / NUMDAYS); | 951 | daysize.setHeight(sz.height()*7 / NUMDAYS); |
943 | daysize.setWidth(sz.width() / 7); | 952 | daysize.setWidth(sz.width() / 7); |
944 | } | 953 | } |
945 | 954 | ||
946 | QSize KODayMatrix::sizeHint() const | 955 | QSize KODayMatrix::sizeHint() const |
947 | { | 956 | { |
948 | 957 | ||
949 | QFontMetrics fm ( font() ); | 958 | QFontMetrics fm ( font() ); |
950 | int wid = fm.width( "30") *7+3; | 959 | int wid = fm.width( "30") *7+3; |
951 | int hei = fm.height() * 6+3; | 960 | int hei = fm.height() * 6+3; |
952 | //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); | 961 | //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); |
953 | return QSize ( wid, hei ); | 962 | return QSize ( wid, hei ); |
954 | 963 | ||
955 | } | 964 | } |