-rw-r--r-- | korganizer/kodaymatrix.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index a776cb6..d7a4112 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp | |||
@@ -245,96 +245,97 @@ KODayMatrix::~KODayMatrix() | |||
245 | } | 245 | } |
246 | 246 | ||
247 | /* | 247 | /* |
248 | void KODayMatrix::setStartDate(QDate start) | 248 | void KODayMatrix::setStartDate(QDate start) |
249 | { | 249 | { |
250 | updateView(start); | 250 | updateView(start); |
251 | } | 251 | } |
252 | */ | 252 | */ |
253 | 253 | ||
254 | void KODayMatrix::addSelectedDaysTo(DateList& selDays) | 254 | void KODayMatrix::addSelectedDaysTo(DateList& selDays) |
255 | { | 255 | { |
256 | 256 | ||
257 | if (mSelStart == NOSELECTION) { | 257 | if (mSelStart == NOSELECTION) { |
258 | return; | 258 | return; |
259 | } | 259 | } |
260 | 260 | ||
261 | //cope with selection being out of matrix limits at top (< 0) | 261 | //cope with selection being out of matrix limits at top (< 0) |
262 | int i0 = mSelStart; | 262 | int i0 = mSelStart; |
263 | if (i0 < 0) { | 263 | if (i0 < 0) { |
264 | for (int i = i0; i < 0; i++) { | 264 | for (int i = i0; i < 0; i++) { |
265 | selDays.append(days[0].addDays(i)); | 265 | selDays.append(days[0].addDays(i)); |
266 | } | 266 | } |
267 | i0 = 0; | 267 | i0 = 0; |
268 | } | 268 | } |
269 | 269 | ||
270 | //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) | 270 | //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) |
271 | if (mSelEnd > NUMDAYS-1) { | 271 | if (mSelEnd > NUMDAYS-1) { |
272 | for (int i = i0; i <= NUMDAYS-1; i++) { | 272 | for (int i = i0; i <= NUMDAYS-1; i++) { |
273 | selDays.append(days[i]); | 273 | selDays.append(days[i]); |
274 | } | 274 | } |
275 | for (int i = NUMDAYS; i < mSelEnd; i++) { | 275 | for (int i = NUMDAYS; i < mSelEnd; i++) { |
276 | selDays.append(days[0].addDays(i)); | 276 | selDays.append(days[0].addDays(i)); |
277 | } | 277 | } |
278 | 278 | ||
279 | // apply normal routine to selection being entirely within matrix limits | 279 | // apply normal routine to selection being entirely within matrix limits |
280 | } else { | 280 | } else { |
281 | for (int i = i0; i <= mSelEnd; i++) { | 281 | for (int i = i0; i <= mSelEnd; i++) { |
282 | selDays.append(days[i]); | 282 | selDays.append(days[i]); |
283 | } | 283 | } |
284 | } | 284 | } |
285 | } | 285 | } |
286 | 286 | ||
287 | void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) | 287 | void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) |
288 | { | 288 | { |
289 | mSelStart = startdate.daysTo(start); | 289 | mSelStart = startdate.daysTo(start); |
290 | if ( mSelStart < 0 ) | 290 | if ( mSelStart < 0 ) |
291 | mSelStart = 0; | 291 | mSelStart = 0; |
292 | mSelEnd = startdate.daysTo(end); | 292 | mSelEnd = startdate.daysTo(end); |
293 | //qDebug("SELECTION %d %d ", mSelStart ,mSelEnd ); | ||
293 | if ( mSelEnd < 0 ) | 294 | if ( mSelEnd < 0 ) |
294 | clearSelection(); | 295 | clearSelection(); |
295 | } | 296 | } |
296 | void KODayMatrix::clearSelection() | 297 | void KODayMatrix::clearSelection() |
297 | { | 298 | { |
298 | mSelEnd = mSelStart = NOSELECTION; | 299 | mSelEnd = mSelStart = NOSELECTION; |
299 | } | 300 | } |
300 | 301 | ||
301 | 302 | ||
302 | void KODayMatrix::recalculateToday() | 303 | void KODayMatrix::recalculateToday() |
303 | { | 304 | { |
304 | today = -1; | 305 | today = -1; |
305 | for (int i=0; i<NUMDAYS; i++) { | 306 | for (int i=0; i<NUMDAYS; i++) { |
306 | events[i] = 0; | 307 | events[i] = 0; |
307 | days[i] = startdate.addDays(i); | 308 | days[i] = startdate.addDays(i); |
308 | daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); | 309 | daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); |
309 | 310 | ||
310 | // if today is in the currently displayed month, hilight today | 311 | // if today is in the currently displayed month, hilight today |
311 | if (days[i].year() == QDate::currentDate().year() && | 312 | if (days[i].year() == QDate::currentDate().year() && |
312 | days[i].month() == QDate::currentDate().month() && | 313 | days[i].month() == QDate::currentDate().month() && |
313 | days[i].day() == QDate::currentDate().day()) { | 314 | days[i].day() == QDate::currentDate().day()) { |
314 | today = i; | 315 | today = i; |
315 | } | 316 | } |
316 | } | 317 | } |
317 | // qDebug(QString("Today is visible at %1.").arg(today)); | 318 | // qDebug(QString("Today is visible at %1.").arg(today)); |
318 | } | 319 | } |
319 | 320 | ||
320 | void KODayMatrix::updateView() | 321 | void KODayMatrix::updateView() |
321 | { | 322 | { |
322 | updateView(startdate); | 323 | updateView(startdate); |
323 | } | 324 | } |
324 | void KODayMatrix::repaintViewTimed() | 325 | void KODayMatrix::repaintViewTimed() |
325 | { | 326 | { |
326 | mRepaintTimer->stop(); | 327 | mRepaintTimer->stop(); |
327 | repaint(false); | 328 | repaint(false); |
328 | } | 329 | } |
329 | void KODayMatrix::updateViewTimed() | 330 | void KODayMatrix::updateViewTimed() |
330 | { | 331 | { |
331 | mUpdateTimer->stop(); | 332 | mUpdateTimer->stop(); |
332 | if ( !mCalendar ) { | 333 | if ( !mCalendar ) { |
333 | qDebug("NOT CAL "); | 334 | qDebug("NOT CAL "); |
334 | return; | 335 | return; |
335 | } | 336 | } |
336 | //qDebug("KODayMatrix::updateViewTimed "); | 337 | //qDebug("KODayMatrix::updateViewTimed "); |
337 | for(int i = 0; i < NUMDAYS; i++) { | 338 | for(int i = 0; i < NUMDAYS; i++) { |
338 | // if events are set for the day then remember to draw it bold | 339 | // if events are set for the day then remember to draw it bold |
339 | QPtrList<Event> eventlist = mCalendar->events(days[i]); | 340 | QPtrList<Event> eventlist = mCalendar->events(days[i]); |
340 | Event *event; | 341 | Event *event; |
@@ -646,97 +647,103 @@ void KODayMatrix::dropEvent(QDropEvent *e) | |||
646 | } | 647 | } |
647 | 648 | ||
648 | // ---------------------------------------------------------------------------- | 649 | // ---------------------------------------------------------------------------- |
649 | // P A I N T E V E N T H A N D L I N G | 650 | // P A I N T E V E N T H A N D L I N G |
650 | // ---------------------------------------------------------------------------- | 651 | // ---------------------------------------------------------------------------- |
651 | 652 | ||
652 | void KODayMatrix::paintEvent(QPaintEvent * pevent) | 653 | void KODayMatrix::paintEvent(QPaintEvent * pevent) |
653 | { | 654 | { |
654 | QRect sz = frameRect(); | 655 | QRect sz = frameRect(); |
655 | if ( sz.width() <= 0 || sz.height() <= 0 ) | 656 | if ( sz.width() <= 0 || sz.height() <= 0 ) |
656 | return; | 657 | return; |
657 | if ( mPendingUpdateBeforeRepaint ) { | 658 | if ( mPendingUpdateBeforeRepaint ) { |
658 | updateViewTimed(); | 659 | updateViewTimed(); |
659 | mPendingUpdateBeforeRepaint = false; | 660 | mPendingUpdateBeforeRepaint = false; |
660 | } | 661 | } |
661 | if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) { | 662 | if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) { |
662 | myPix.resize(sz.size() ); | 663 | myPix.resize(sz.size() ); |
663 | } | 664 | } |
664 | QPainter p(&myPix); | 665 | QPainter p(&myPix); |
665 | p.setFont(font()); | 666 | p.setFont(font()); |
666 | 667 | ||
667 | 668 | ||
668 | int dheight = daysize.height(); | 669 | int dheight = daysize.height(); |
669 | int dwidth = daysize.width(); | 670 | int dwidth = daysize.width(); |
670 | int row,col; | 671 | int row,col; |
671 | int selw, selh; | 672 | int selw, selh; |
672 | int xyOff = frameWidth(); | 673 | int xyOff = frameWidth(); |
673 | int colModulo = sz.width() % 7; | 674 | int colModulo = sz.width() % 7; |
674 | int rowModulo = sz.height() % 6; | 675 | int rowModulo = sz.height() % 6; |
675 | //qDebug("col %d row %d ",colModulo,rowModulo ); | 676 | //qDebug("col %d row %d ",colModulo,rowModulo ); |
676 | 677 | ||
677 | bool isRTL = KOGlobals::self()->reverseLayout(); | 678 | bool isRTL = KOGlobals::self()->reverseLayout(); |
678 | 679 | ||
679 | // draw background and topleft frame | 680 | // draw background and topleft frame |
680 | p.fillRect(pevent->rect(), mDefaultBackColor); | 681 | p.fillRect(pevent->rect(), mDefaultBackColor); |
681 | p.setPen(mDefaultTextColor); | 682 | p.setPen(mDefaultTextColor); |
682 | p.drawRect(0, 0, sz.width()+1, sz.height()+1); | 683 | p.drawRect(0, 0, sz.width()+1, sz.height()+1); |
683 | int mSelStartT = mSelStart; | 684 | int mSelStartT = mSelStart; |
684 | int mSelEndT = mSelEnd; | 685 | int mSelEndT = mSelEnd; |
685 | if ( mSelEndT >= NUMDAYS ) | 686 | if ( mSelEndT >= NUMDAYS ) |
686 | mSelEndT = NUMDAYS-1; | 687 | mSelEndT = NUMDAYS-1; |
687 | // draw selected days with highlighted background color | 688 | // draw selected days with highlighted background color |
688 | if (mSelStart != NOSELECTION) { | 689 | if (mSelStart != NOSELECTION) { |
689 | bool skip = false; | 690 | bool skip = false; |
690 | if ( ! mouseDown ) { | 691 | if ( ! mouseDown ) { |
691 | int mo = days[20].month(); | 692 | int mo = days[20].month(); |
692 | //qDebug("-- %d %d ", mSelStartT, mSelEndT); | 693 | //qDebug("-- %d %d ", mSelStartT, mSelEndT); |
693 | //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); | 694 | //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); |
694 | if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) { | 695 | int startMo = days[mSelStartT].month(); |
696 | int endMo = days[mSelEndT].month(); | ||
697 | if ( startMo == 12 && mo == 1 && endMo == 1 ) | ||
698 | startMo = 1; | ||
699 | if ( endMo == 1 && mo == 12 ) | ||
700 | endMo = 12; | ||
701 | if ( (startMo > mo || endMo < mo) ) { | ||
695 | skip = true; | 702 | skip = true; |
696 | } else { | 703 | } else { |
697 | if ( days[mSelStartT].month() != mo ) { | 704 | if ( days[mSelStartT].month() != mo ) { |
698 | int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); | 705 | int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); |
699 | mSelStartT += add +1; | 706 | mSelStartT += add +1; |
700 | } | 707 | } |
701 | if ( days[mSelEndT].month() != mo ) { | 708 | if ( days[mSelEndT].month() != mo ) { |
702 | int sub = days[mSelEndT].day(); | 709 | int sub = days[mSelEndT].day(); |
703 | mSelEndT -= sub ; | 710 | mSelEndT -= sub ; |
704 | } | 711 | } |
705 | } | 712 | } |
706 | } | 713 | } |
707 | if ( ! skip ) { | 714 | if ( ! skip ) { |
708 | row = mSelStartT/7; | 715 | row = mSelStartT/7; |
709 | col = mSelStartT -row*7; | 716 | col = mSelStartT -row*7; |
710 | QColor selcol = KOPrefs::instance()->mHighlightColor; | 717 | QColor selcol = KOPrefs::instance()->mHighlightColor; |
711 | int addCol = 0; | 718 | int addCol = 0; |
712 | int addRow = 0; | 719 | int addRow = 0; |
713 | int addRow2 = 0; | 720 | int addRow2 = 0; |
714 | int addCol2 = 0; | 721 | int addCol2 = 0; |
715 | if (row == mSelEndT/7) { | 722 | if (row == mSelEndT/7) { |
716 | if ( rowModulo ) { | 723 | if ( rowModulo ) { |
717 | if ( row >= 6 - rowModulo ) | 724 | if ( row >= 6 - rowModulo ) |
718 | addRow = row - 5 + rowModulo; | 725 | addRow = row - 5 + rowModulo; |
719 | } | 726 | } |
720 | if ( colModulo ) { | 727 | if ( colModulo ) { |
721 | int colt1 = mSelEndT%7; | 728 | int colt1 = mSelEndT%7; |
722 | //qDebug("colt1 %d ", colt1 ); | 729 | //qDebug("colt1 %d ", colt1 ); |
723 | if ( colt1 >= 7 - colModulo ) | 730 | if ( colt1 >= 7 - colModulo ) |
724 | addCol = colt1 - 7 + colModulo+1; | 731 | addCol = colt1 - 7 + colModulo+1; |
725 | int colt = mSelStartT%7; | 732 | int colt = mSelStartT%7; |
726 | if ( colt >= 7 - colModulo ) | 733 | if ( colt >= 7 - colModulo ) |
727 | addCol2 = colt - 7 + colModulo; | 734 | addCol2 = colt - 7 + colModulo; |
728 | addCol -= addCol2; | 735 | addCol -= addCol2; |
729 | //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); | 736 | //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); |
730 | } | 737 | } |
731 | // Single row selection | 738 | // Single row selection |
732 | if ( row == 0) | 739 | if ( row == 0) |
733 | addRow = 1; | 740 | addRow = 1; |
734 | p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, | 741 | p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, |
735 | row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); | 742 | row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); |
736 | } else { | 743 | } else { |
737 | // draw first row to the right | 744 | // draw first row to the right |
738 | if ( colModulo ) { | 745 | if ( colModulo ) { |
739 | if ( col >= 7 - colModulo ) | 746 | if ( col >= 7 - colModulo ) |
740 | addCol2 = col - 7 + colModulo; | 747 | addCol2 = col - 7 + colModulo; |
741 | } | 748 | } |
742 | if ( rowModulo ) { | 749 | if ( rowModulo ) { |