-rw-r--r-- | korganizer/datenavigatorcontainer.cpp | 2 | ||||
-rw-r--r-- | korganizer/kodaymatrix.cpp | 58 |
2 files changed, 45 insertions, 15 deletions
diff --git a/korganizer/datenavigatorcontainer.cpp b/korganizer/datenavigatorcontainer.cpp index d09f484..b9bd1b9 100644 --- a/korganizer/datenavigatorcontainer.cpp +++ b/korganizer/datenavigatorcontainer.cpp @@ -51,179 +51,179 @@ DateNavigatorContainer::~DateNavigatorContainer() } void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) { connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ), SIGNAL( datesSelected( const KCal::DateList & ) ) ); #if 0 connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ), SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) ); connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ), SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) ); #endif connect( v, SIGNAL( weekClicked( const QDate & ) ), SIGNAL( weekClicked( const QDate & ) ) ); connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) ); connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) ); connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); connect( v, SIGNAL( monthSelected( int ) ), SIGNAL( monthSelected( int ) ) ); } void DateNavigatorContainer::setCalendar( Calendar *cal ) { mCalendar = cal; mNavigatorView->setCalendar( cal ); KDateNavigator *n; for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { n->setCalendar( cal ); } } void DateNavigatorContainer::updateDayMatrix() { mNavigatorView->updateDayMatrix(); KDateNavigator *n; for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { n->updateDayMatrix(); } } void DateNavigatorContainer::updateToday() { qDebug("DateNavigatorContainer::updateToday() NOT IMPL "); #if 0 mNavigatorView->updateToday(); KDateNavigator *n; for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { n->updateToday(); } #endif } void DateNavigatorContainer::updateView() { mNavigatorView->updateView(); KDateNavigator *n; for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { n->updateView(); } } void DateNavigatorContainer::updateConfig() { mNavigatorView->updateConfig(); KDateNavigator *n; for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { n->updateConfig(); } } void DateNavigatorContainer::selectDates( const DateList &dateList ) { mNavigatorView->selectDates( dateList ); setBaseDates(); if ( mExtraViews.count() ) { KDateNavigator *view = mExtraViews.at( 0 ); view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); view->dayMatrix()->repaint(); } } void DateNavigatorContainer::setBaseDates() { KCal::DateList dateList = mNavigatorView->selectedDates(); if ( dateList.isEmpty() ) { kdError() << "DateNavigatorContainer::selectDates() empty list." << endl; } QDate baseDate = dateList.first(); KDateNavigator *n; bool doRepaint = false; // skip first repaint for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { - baseDate = baseDate.addDays( baseDate.daysInMonth () ); + baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 ); n->setBaseDate( baseDate, doRepaint ); doRepaint = true; } } void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) { #if 0 kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl; kdDebug(5850) << " CURRENT SIZE: " << size() << endl; kdDebug(5850) << " MINIMUM SIZEHINT: " << minimumSizeHint() << endl; kdDebug(5850) << " SIZEHINT: " << sizeHint() << endl; kdDebug(5850) << " MINIMUM SIZE: " << minimumSize() << endl; #endif QSize minSize = mNavigatorView->yourSizeHint(); // kdDebug(5850) << " NAVIGATORVIEW minimumSizeHint: " << minSize << endl; int verticalCount = size().height() / minSize.height(); int horizontalCount = size().width() / minSize.width(); //qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() ); //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount ); if ( horizontalCount != mHorizontalCount || verticalCount != mVerticalCount ) { uint count = horizontalCount * verticalCount; if ( count == 0 ) { mNavigatorView->resize( minSize ); return; } while ( count > ( mExtraViews.count() + 1 ) ) { KDateNavigator *n = new KDateNavigator( this ); n->setMonthSignalOffset ( mExtraViews.count()+1 ); mExtraViews.append( n ); n->setCalendar( mCalendar ); setBaseDates(); connectNavigatorView( n ); n->show(); } while ( count < ( mExtraViews.count() + 1 ) ) { mExtraViews.removeLast(); } mHorizontalCount = horizontalCount; mVerticalCount = verticalCount; } int height = size().height() / verticalCount; int width = size().width() / horizontalCount; NavigatorBar *bar = mNavigatorView->navigatorBar(); if ( horizontalCount > 1 ) bar->showButtons( true, false ); else bar->showButtons( true, true ); mNavigatorView->setGeometry(0, 0, width, height ); for( uint i = 0; i < mExtraViews.count(); ++i ) { int x = ( i + 1 ) % horizontalCount; int y = ( i + 1 ) / horizontalCount; KDateNavigator *view = mExtraViews.at( i ); bar = view->navigatorBar(); if ( y > 0 ) bar->showButtons( false, false ); else { if ( x + 1 == horizontalCount ) bar->showButtons( false, true ); else bar->showButtons( false, false ); } view->setGeometry( x * width, y * height, width, height ); } } QSize DateNavigatorContainer::minimumSizeHint() const { return mNavigatorView->minimumSizeHint(); } QSize DateNavigatorContainer::sizeHint() const { return mNavigatorView->sizeHint(); } diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index 1cde616..619ae39 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp @@ -178,193 +178,197 @@ QString KODayMatrix::getWhatsThisText( QPoint p ) else if ( mDate == event->dtEnd().date () ) time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; } text = time + event->summary(); mToolTipText += prefix + text; } else { if (event->doesFloat()) { text = event->summary(); mToolTipText += text; } else { text = KGlobal::locale()->formatTime(event->dtStart().time()); text += " " + event->summary(); mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); } } mToolTip.append( mToolTipText ); } mToolTip.sort(); return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); } void KODayMatrix::setCalendar( Calendar *cal ) { mCalendar = cal; setAcceptDrops( mCalendar ); updateEvents(); } QColor KODayMatrix::getShadedColor(QColor color) { QColor shaded; int h=0; int s=0; int v=0; color.hsv(&h,&s,&v); s = s/4; v = 192+v/4; shaded.setHsv(h,s,v); return shaded; } KODayMatrix::~KODayMatrix() { delete [] days; delete [] daylbls; delete [] events; delete mToolTip; } /* void KODayMatrix::setStartDate(QDate start) { updateView(start); } */ void KODayMatrix::addSelectedDaysTo(DateList& selDays) { if (mSelStart == NOSELECTION) { return; } //cope with selection being out of matrix limits at top (< 0) int i0 = mSelStart; if (i0 < 0) { for (int i = i0; i < 0; i++) { selDays.append(days[0].addDays(i)); } i0 = 0; } //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) if (mSelEnd > NUMDAYS-1) { for (int i = i0; i <= NUMDAYS-1; i++) { selDays.append(days[i]); } for (int i = NUMDAYS; i < mSelEnd; i++) { selDays.append(days[0].addDays(i)); } // apply normal routine to selection being entirely within matrix limits } else { for (int i = i0; i <= mSelEnd; i++) { selDays.append(days[i]); } } } void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) { mSelStart = startdate.daysTo(start); + if ( mSelStart < 0 ) + mSelStart = 0; mSelEnd = startdate.daysTo(end); + if ( mSelEnd < 0 ) + clearSelection(); } void KODayMatrix::clearSelection() { mSelEnd = mSelStart = NOSELECTION; } void KODayMatrix::recalculateToday() { today = -1; for (int i=0; i<NUMDAYS; i++) { events[i] = 0; days[i] = startdate.addDays(i); daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); // if today is in the currently displayed month, hilight today if (days[i].year() == QDate::currentDate().year() && days[i].month() == QDate::currentDate().month() && days[i].day() == QDate::currentDate().day()) { today = i; } } // qDebug(QString("Today is visible at %1.").arg(today)); } void KODayMatrix::updateView() { updateView(startdate); } void KODayMatrix::repaintViewTimed() { mRepaintTimer->stop(); repaint(false); } void KODayMatrix::updateViewTimed() { mUpdateTimer->stop(); if ( !mCalendar ) { qDebug("NOT CAL "); return; } //qDebug("KODayMatrix::updateViewTimed "); for(int i = 0; i < NUMDAYS; i++) { // if events are set for the day then remember to draw it bold QPtrList<Event> eventlist = mCalendar->events(days[i]); Event *event; int numEvents = eventlist.count(); QString holiStr = ""; bDays.clearBit(i); for(event=eventlist.first();event != 0;event=eventlist.next()) { ushort recurType = event->recurrence()->doesRecur(); if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { numEvents--; } if ( event->categories().contains( i18n("Holiday") ) || event->categories().contains( "Holiday" )) { if ( !holiStr.isEmpty() ) holiStr += "\n"; holiStr += event->summary(); } if ( event->categories().contains( i18n("Birthday") ) || event->categories().contains( "Birthday" )) { if ( !holiStr.isEmpty() ) holiStr += "\n"; holiStr += event->summary(); bDays.setBit(i); } } events[i] = numEvents; //if it is a holy day then draw it red. Sundays are consider holidays, too if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || !holiStr.isEmpty()) { mHolidays[i] = holiStr; } else { mHolidays[i] = QString::null; } } if ( ! mPendingUpdateBeforeRepaint ) repaint(false); } void KODayMatrix::updateView(QDate actdate) { if ( ! actdate.isValid() ) { //qDebug("date not valid "); return; } mDayChanged = false; //flag to indicate if the starting day of the matrix has changed by this call //mDayChanged = false; // if a new startdate is to be set then apply Cornelius's calculation // of the first day to be shown if (actdate != startdate) { // reset index of selection according to shift of starting date from startdate to actdate if (mSelStart != NOSELECTION) { int tmp = actdate.daysTo(startdate); //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; @@ -545,224 +549,250 @@ void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) e->ignore(); return; } e->accept(); #endif } void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) { #ifndef KORG_NODND // setPalette(oldPalette); // update(); #endif } void KODayMatrix::dropEvent(QDropEvent *e) { #ifndef KORG_NODND // kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { e->ignore(); return; } DndFactory factory( mCalendar ); Event *event = factory.createDrop(e); if (event) { e->acceptAction(); Event *existingEvent = mCalendar->event(event->uid()); if(existingEvent) { // uniquify event event->recreate(); /* KMessageBox::sorry(this, i18n("Event already exists in this calendar."), i18n("Drop Event")); delete event; return; */ } // kdDebug() << "Drop new Event" << endl; // Adjust date QDateTime start = event->dtStart(); QDateTime end = event->dtEnd(); int duration = start.daysTo(end); int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); start.setDate(days[idx]); end.setDate(days[idx].addDays(duration)); event->setDtStart(start); event->setDtEnd(end); mCalendar->addEvent(event); emit eventDropped(event); } else { // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; e->ignore(); } #endif } // ---------------------------------------------------------------------------- // P A I N T E V E N T H A N D L I N G // ---------------------------------------------------------------------------- void KODayMatrix::paintEvent(QPaintEvent * pevent) { if ( width() <= 0 || height() <= 0 ) return; if ( mPendingUpdateBeforeRepaint ) { updateViewTimed(); mPendingUpdateBeforeRepaint = false; } if ( myPix.width() != width() || myPix.height()!=height() ) { myPix.resize(size() ); } QPainter p(&myPix); p.setFont(font()); QRect sz = frameRect(); int dheight = daysize.height(); int dwidth = daysize.width(); int row,col; int selw, selh; bool isRTL = KOGlobals::self()->reverseLayout(); // draw background and topleft frame p.fillRect(pevent->rect(), mDefaultBackColor); p.setPen(mDefaultTextColor); p.drawRect(0, 0, sz.width()+1, sz.height()+1); - + int mSelStartT = mSelStart; + int mSelEndT = mSelEnd; + if ( mSelEndT >= NUMDAYS ) + mSelEndT = NUMDAYS-1; // draw selected days with highlighted background color if (mSelStart != NOSELECTION) { - - row = mSelStart/7; - col = mSelStart -row*7; + bool skip = false; + if ( ! mouseDown ) { + int mo = days[20].month(); + //qDebug("-- %d %d ", mSelStartT, mSelEndT); + //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); + if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) { + skip = true; + } else { + if ( days[mSelStartT].month() != mo ) { + int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); + mSelStartT += add +1; + } + if ( days[mSelEndT].month() != mo ) { + int sub = days[mSelEndT].day(); + mSelEndT -= sub ; + } + } + } + if ( ! skip ) { + row = mSelStartT/7; + col = mSelStartT -row*7; QColor selcol = KOPrefs::instance()->mHighlightColor; - if (row == mSelEnd/7) { + if (row == mSelEndT/7) { // Single row selection - p.fillRect(isRTL ? (7 - (mSelEnd-mSelStart+1) - col)*dwidth : col*dwidth, - row*dheight, (mSelEnd-mSelStart+1)*dwidth, dheight, selcol); + p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth, + row*dheight, (mSelEndT-mSelStartT+1)*dwidth, dheight, selcol); } else { // draw first row to the right p.fillRect(isRTL ? 0 : col*dwidth, row*dheight, (7-col)*dwidth, dheight, selcol); // draw full block till last line - selh = mSelEnd/7-row; + selh = mSelEndT/7-row; if (selh > 1) { p.fillRect(0, (row+1)*dheight, 7*dwidth, (selh-1)*dheight,selcol); } - // draw last block from left to mSelEnd - selw = mSelEnd-7*(mSelEnd/7)+1; + // draw last block from left to mSelEndT + selw = mSelEndT-7*(mSelEndT/7)+1; p.fillRect(isRTL ? (7-selw)*dwidth : 0, (row+selh)*dheight, selw*dwidth, dheight, selcol); } + } } // iterate over all days in the matrix and draw the day label in appropriate colors QColor actcol = mDefaultTextColorShaded; p.setPen(actcol); QPen tmppen; for(int i = 0; i < NUMDAYS; i++) { row = i/7; col = isRTL ? 6-(i-row*7) : i-row*7; // if it is the first day of a month switch color from normal to shaded and vice versa if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { if (actcol == mDefaultTextColorShaded) { actcol = mDefaultTextColor; } else { actcol = mDefaultTextColorShaded; } p.setPen(actcol); } - + if (actcol == mDefaultTextColorShaded) { + if ( ! mouseDown ) { + continue; + } + } //Reset pen color after selected days block - if (i == mSelEnd+1) { + if (i == mSelEndT+1) { p.setPen(actcol); } // if today then draw rectangle around day if (today == i) { tmppen = p.pen(); QPen mTodayPen(p.pen()); mTodayPen.setWidth(mTodayMarginWidth); //draw red rectangle for holidays if (!mHolidays[i].isNull()) { if (actcol == mDefaultTextColor) { mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); } else { mTodayPen.setColor(mHolidayColorShaded); } } //draw gray rectangle for today if in selection - if (i >= mSelStart && i <= mSelEnd) { + if (i >= mSelStartT && i <= mSelEndT) { QColor grey("grey"); mTodayPen.setColor(grey); } p.setPen(mTodayPen); p.drawRect(col*dwidth, row*dheight, dwidth, dheight); p.setPen(tmppen); } // if any events are on that day then draw it using a bold font if (events[i] > 0) { QFont myFont = font(); myFont.setBold(true); p.setFont(myFont); } // if it is a holiday then use the default holiday color if (!mHolidays[i].isNull()) { if ( bDays.testBit(i) ) { p.setPen(Qt::green); } else { if (actcol == mDefaultTextColor) { p.setPen(KOPrefs::instance()->mHolidayColor); } else { p.setPen(mHolidayColorShaded); } } } // draw selected days with special color // DO NOT specially highlight holidays in selection ! - if (i >= mSelStart && i <= mSelEnd) { + if (i >= mSelStartT && i <= mSelEndT) { ;//p.setPen(mSelectedDaysColor); } p.drawText(col*dwidth, row*dheight, dwidth, dheight, Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); // reset color to actual color if (!mHolidays[i].isNull()) { p.setPen(actcol); } // reset bold font to plain font if (events[i] > 0) { QFont myFont = font(); myFont.setBold(false); p.setFont(myFont); } } bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP); } // ---------------------------------------------------------------------------- // R E SI Z E E V E N T H A N D L I N G // ---------------------------------------------------------------------------- void KODayMatrix::resizeEvent(QResizeEvent *) { QRect sz = frameRect(); daysize.setHeight(sz.height()*7 / NUMDAYS); daysize.setWidth(sz.width() / 7); } |