summaryrefslogtreecommitdiffabout
path: root/korganizer/kodaymatrix.cpp
Unidiff
Diffstat (limited to 'korganizer/kodaymatrix.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kodaymatrix.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index a2e0ae0..3ee1fa7 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -263,57 +263,64 @@ void KODayMatrix::addSelectedDaysTo(DateList& selDays)
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
287void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) 287bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
288{ 288{
289 bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION );
289 mSelStart = startdate.daysTo(start); 290 mSelStart = startdate.daysTo(start);
290 if ( mSelStart < 0 ) 291 if ( mSelStart < 0 )
291 mSelStart = 0; 292 mSelStart = 0;
292 mSelEnd = startdate.daysTo(end); 293 mSelEnd = startdate.daysTo(end);
293 //qDebug("SELECTION %d %d ", mSelStart ,mSelEnd ); 294 if ( mSelEnd > NUMDAYS-1 )
294 if ( mSelEnd < 0 ) 295 mSelEnd = NUMDAYS-1;
296 if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) {
295 clearSelection(); 297 clearSelection();
298 if ( noSel )
299 return false;
300 }
301
302 return true;
296} 303}
297void KODayMatrix::clearSelection() 304void KODayMatrix::clearSelection()
298{ 305{
299 mSelEnd = mSelStart = NOSELECTION; 306 mSelEnd = mSelStart = NOSELECTION;
300} 307}
301 308
302 309
303void KODayMatrix::recalculateToday() 310void KODayMatrix::recalculateToday()
304{ 311{
305 today = -1; 312 today = -1;
306 for (int i=0; i<NUMDAYS; i++) { 313 for (int i=0; i<NUMDAYS; i++) {
307 events[i] = 0; 314 events[i] = 0;
308 days[i] = startdate.addDays(i); 315 days[i] = startdate.addDays(i);
309 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); 316 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
310 317
311 // if today is in the currently displayed month, hilight today 318 // if today is in the currently displayed month, hilight today
312 if (days[i].year() == QDate::currentDate().year() && 319 if (days[i].year() == QDate::currentDate().year() &&
313 days[i].month() == QDate::currentDate().month() && 320 days[i].month() == QDate::currentDate().month() &&
314 days[i].day() == QDate::currentDate().day()) { 321 days[i].day() == QDate::currentDate().day()) {
315 today = i; 322 today = i;
316 } 323 }
317 } 324 }
318 // qDebug(QString("Today is visible at %1.").arg(today)); 325 // qDebug(QString("Today is visible at %1.").arg(today));
319} 326}
@@ -678,61 +685,64 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent)
678 685
679 bool isRTL = KOGlobals::self()->reverseLayout(); 686 bool isRTL = KOGlobals::self()->reverseLayout();
680 687
681 // draw background and topleft frame 688 // draw background and topleft frame
682 p.fillRect(pevent->rect(), mDefaultBackColor); 689 p.fillRect(pevent->rect(), mDefaultBackColor);
683 p.setPen(mDefaultTextColor); 690 p.setPen(mDefaultTextColor);
684 p.drawRect(0, 0, sz.width()+1, sz.height()+1); 691 p.drawRect(0, 0, sz.width()+1, sz.height()+1);
685 int mSelStartT = mSelStart; 692 int mSelStartT = mSelStart;
686 int mSelEndT = mSelEnd; 693 int mSelEndT = mSelEnd;
687 if ( mSelEndT >= NUMDAYS ) 694 if ( mSelEndT >= NUMDAYS )
688 mSelEndT = NUMDAYS-1; 695 mSelEndT = NUMDAYS-1;
689 // draw selected days with highlighted background color 696 // draw selected days with highlighted background color
690 if (mSelStart != NOSELECTION) { 697 if (mSelStart != NOSELECTION) {
691 bool skip = false; 698 bool skip = false;
692 if ( ! mouseDown ) { 699 if ( ! mouseDown ) {
693 int mo = days[20].month(); 700 int mo = days[20].month();
694 //qDebug("-- %d %d ", mSelStartT, mSelEndT); 701 //qDebug("-- %d %d ", mSelStartT, mSelEndT);
695 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); 702 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() );
696 int startMo = days[mSelStartT].month(); 703 int startMo = days[mSelStartT].month();
697 int endMo = days[mSelEndT].month(); 704 int endMo = days[mSelEndT].month();
698 if ( startMo == 12 && mo == 1 && endMo <= 2 ) 705 if ( startMo == 12 && mo == 1 && endMo <= 2 )
699 startMo = 1; 706 startMo = 1;
700 if ( endMo == 1 && mo == 12 ) 707 if ( endMo == 1 && mo == 12 )
701 endMo = 12; 708 endMo = 12;
709 if ( mo == 12 && startMo == 1 )
710 startMo = 13;
702 if ( (startMo > mo || endMo < mo) ) { 711 if ( (startMo > mo || endMo < mo) ) {
703 skip = true; 712 skip = true;
704 } else { 713 } else {
705 if ( days[mSelStartT].month() != mo ) { 714 if ( days[mSelStartT].month() != mo ) {
706 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); 715 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day();
707 mSelStartT += add +1; 716 mSelStartT += add +1;
708 } 717 }
709 if ( days[mSelEndT].month() != mo ) { 718 if ( days[mSelEndT].month() != mo ) {
710 int sub = days[mSelEndT].day(); 719 int sub = days[mSelEndT].day();
711 mSelEndT -= sub ; 720 mSelEndT -= sub ;
712 } 721 }
713 } 722 }
714 } 723 }
724 //qDebug("SKIP %d ", skip);
715 if ( ! skip ) { 725 if ( ! skip ) {
716 row = mSelStartT/7; 726 row = mSelStartT/7;
717 col = mSelStartT -row*7; 727 col = mSelStartT -row*7;
718 QColor selcol = KOPrefs::instance()->mHighlightColor; 728 QColor selcol = KOPrefs::instance()->mHighlightColor;
719 int addCol = 0; 729 int addCol = 0;
720 int addRow = 0; 730 int addRow = 0;
721 int addRow2 = 0; 731 int addRow2 = 0;
722 int addCol2 = 0; 732 int addCol2 = 0;
723 if (row == mSelEndT/7) { 733 if (row == mSelEndT/7) {
724 if ( rowModulo ) { 734 if ( rowModulo ) {
725 if ( row >= 6 - rowModulo ) 735 if ( row >= 6 - rowModulo )
726 addRow = row - 5 + rowModulo; 736 addRow = row - 5 + rowModulo;
727 } 737 }
728 if ( colModulo ) { 738 if ( colModulo ) {
729 int colt1 = mSelEndT%7; 739 int colt1 = mSelEndT%7;
730 //qDebug("colt1 %d ", colt1 ); 740 //qDebug("colt1 %d ", colt1 );
731 if ( colt1 >= 7 - colModulo ) 741 if ( colt1 >= 7 - colModulo )
732 addCol = colt1 - 7 + colModulo+1; 742 addCol = colt1 - 7 + colModulo+1;
733 int colt = mSelStartT%7; 743 int colt = mSelStartT%7;
734 if ( colt >= 7 - colModulo ) 744 if ( colt >= 7 - colModulo )
735 addCol2 = colt - 7 + colModulo; 745 addCol2 = colt - 7 + colModulo;
736 addCol -= addCol2; 746 addCol -= addCol2;
737 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); 747 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 );
738 } 748 }