-rw-r--r-- | korganizer/datenavigatorcontainer.cpp | 83 | ||||
-rw-r--r-- | korganizer/datenavigatorcontainer.h | 2 | ||||
-rw-r--r-- | korganizer/kdatenavigator.h | 3 | ||||
-rw-r--r-- | korganizer/kodaymatrix.cpp | 16 | ||||
-rw-r--r-- | korganizer/kodaymatrix.h | 2 |
5 files changed, 82 insertions, 24 deletions
diff --git a/korganizer/datenavigatorcontainer.cpp b/korganizer/datenavigatorcontainer.cpp index 18756f0..bb27bce 100644 --- a/korganizer/datenavigatorcontainer.cpp +++ b/korganizer/datenavigatorcontainer.cpp @@ -46,6 +46,8 @@ DateNavigatorContainer::DateNavigatorContainer( QWidget *parent, connectNavigatorView( mNavigatorView ); //setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); + mDisplayedEndDate = QDate::currentDate(); + mLastDisplayedDN = 0; } DateNavigatorContainer::~DateNavigatorContainer() @@ -80,18 +82,18 @@ void DateNavigatorContainer::setCalendar( Calendar *cal ) { mCalendar = cal; mNavigatorView->setCalendar( cal ); - KDateNavigator *n; - for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { - n->setCalendar( cal ); + for( uint i = 0; i < mLastDisplayedDN; ++i ) { + KDateNavigator *n = mExtraViews.at( i ); + n->setCalendar( cal ); } } void DateNavigatorContainer::updateDayMatrix() { mNavigatorView->updateDayMatrix(); - KDateNavigator *n; - for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { - n->updateDayMatrix(); + for( uint i = 0; i < mLastDisplayedDN; ++i ) { + KDateNavigator *n = mExtraViews.at( i ); + n->updateDayMatrix(); } } @@ -110,30 +112,66 @@ void DateNavigatorContainer::updateToday() void DateNavigatorContainer::updateView() { mNavigatorView->updateView(); - KDateNavigator *n; - for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { - n->updateView(); + for( uint i = 0; i < mLastDisplayedDN; ++i ) { + KDateNavigator *n = mExtraViews.at( i ); + n->updateView(); } } void DateNavigatorContainer::updateConfig() { mNavigatorView->updateConfig(); - KDateNavigator *n; - for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { - n->updateConfig(); + for( uint i = 0; i < mLastDisplayedDN; ++i ) { + KDateNavigator *n = mExtraViews.at( i ); + n->updateConfig(); } } void DateNavigatorContainer::selectDates( const DateList &dateList ) { - mNavigatorView->selectDates( dateList ); - setBaseDates(); - if ( mExtraViews.count() ) { + if ( !mLastDisplayedDN ) { + mNavigatorView->selectDates( dateList ); + return; + } + QDate fDate = dateList.first(); + QDate lDate = dateList.last(); + if ( mLastDisplayedDN <= 2 ) { + mNavigatorView->selectDates( dateList ); + KDateNavigator *view = mExtraViews.at( 0 ); + QDate bDate = fDate.addDays( fDate.daysInMonth () - fDate.day() +1 ); + view->setBaseDate( bDate, false ); + view->dayMatrix()->setSelectedDaysFrom(fDate , lDate); + if ( mLastDisplayedDN == 2 ) { + view = mExtraViews.at( 1 ); + bDate = bDate.addDays( bDate.daysInMonth () - bDate.day() +1 ); + view->setBaseDate( bDate, false ); + view->dayMatrix()->setSelectedDaysFrom(fDate , lDate); + } + return; + } + KDateNavigator *view = mExtraViews.at( 0 ); + QDate date = view->baseDate(); + + QDate curEnd = date.addDays( (mLastDisplayedDN)*30 +7); + //qDebug("End %s %s ",lDate.toString().latin1(),curEnd.toString().latin1() ); + if ( lDate < curEnd && date.addDays( -30 ) < fDate) { + mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate ); + mNavigatorView->dayMatrix()->repaint( false ); + for( uint i = 0; i < mLastDisplayedDN; ++i ) { + KDateNavigator *n = mExtraViews.at( i ); + if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) { + n->dayMatrix()->repaint( false ); + } + } + return; + } + mNavigatorView->selectDates( dateList ); + setBaseDates(); + if ( mLastDisplayedDN ) { KDateNavigator *view = mExtraViews.at( 0 ); view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); view->dayMatrix()->repaint( false ); - if ( mExtraViews.count() > 1 ) { + if ( mLastDisplayedDN > 1 ) { KDateNavigator *view = mExtraViews.at( 1 ); view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); view->dayMatrix()->repaint( false ); @@ -148,9 +186,9 @@ void DateNavigatorContainer::setBaseDates() 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() ) { + for( uint i = 0; i < mLastDisplayedDN; ++i ) { + KDateNavigator *n = mExtraViews.at( i ); baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 ); n->setBaseDate( baseDate, doRepaint ); doRepaint = true; @@ -211,12 +249,14 @@ void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) } } + mLastDisplayedDN = horizontalCount*verticalCount-1; + bool setBaseD = false; while ( count > ( mExtraViews.count() + 1 ) ) { KDateNavigator *n = new KDateNavigator( this ); n->setMonthSignalOffset ( mExtraViews.count()+1 ); mExtraViews.append( n ); n->setCalendar( mCalendar ); - setBaseDates(); + setBaseD = true; connectNavigatorView( n ); n->show(); } @@ -228,6 +268,8 @@ void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) mExtraViews.at( iii )->hide(); ++iii; } + if ( setBaseD ) + setBaseDates(); if ( fontchange ) { //mNavigatorView->changeFont( fo ); uint i; @@ -238,6 +280,7 @@ void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) } mHorizontalCount = horizontalCount; mVerticalCount = verticalCount; + } //qDebug("COUNT %d ", mExtraViews.count()); int height = size().height() / verticalCount; @@ -249,7 +292,7 @@ void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) mNavigatorView->setGeometry(0, 0, width, height ); - for( uint i = 0; i < mExtraViews.count(); ++i ) { + for( uint i = 0; i < mLastDisplayedDN; ++i ) { int x = ( i + 1 ) % horizontalCount; int y = ( i + 1 ) / horizontalCount; diff --git a/korganizer/datenavigatorcontainer.h b/korganizer/datenavigatorcontainer.h index affa8e1..f45af20 100644 --- a/korganizer/datenavigatorcontainer.h +++ b/korganizer/datenavigatorcontainer.h @@ -77,6 +77,8 @@ class DateNavigatorContainer: public QWidget void connectNavigatorView( KDateNavigator *v ); private: + int mLastDisplayedDN; + QDate mDisplayedEndDate; KDateNavigator *mNavigatorView; KCal::Calendar *mCalendar; diff --git a/korganizer/kdatenavigator.h b/korganizer/kdatenavigator.h index 10bc1be..93bbceb 100644 --- a/korganizer/kdatenavigator.h +++ b/korganizer/kdatenavigator.h @@ -61,6 +61,9 @@ class KDateNavigator: public QFrame void setShowWeekNums( bool enabled ); void setCalendar( Calendar * ); void setBaseDate( const QDate & , bool doRepaint = true ); + + QDate baseDate() const { return m_MthYr;} + KCal::DateList selectedDates() const { return mSelectedDates; } NavigatorBar *navigatorBar() const { return mNavigatorBar; } void setMonthSignalOffset ( int off ) { mMonthSignalOffset = off%12;} diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index a2e0ae0..3ee1fa7 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp @@ -284,15 +284,22 @@ void KODayMatrix::addSelectedDaysTo(DateList& selDays) } } -void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) +bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) { + bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION ); mSelStart = startdate.daysTo(start); if ( mSelStart < 0 ) mSelStart = 0; mSelEnd = startdate.daysTo(end); - //qDebug("SELECTION %d %d ", mSelStart ,mSelEnd ); - if ( mSelEnd < 0 ) + if ( mSelEnd > NUMDAYS-1 ) + mSelEnd = NUMDAYS-1; + if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) { clearSelection(); + if ( noSel ) + return false; + } + + return true; } void KODayMatrix::clearSelection() { @@ -699,6 +706,8 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent) startMo = 1; if ( endMo == 1 && mo == 12 ) endMo = 12; + if ( mo == 12 && startMo == 1 ) + startMo = 13; if ( (startMo > mo || endMo < mo) ) { skip = true; } else { @@ -712,6 +721,7 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent) } } } + //qDebug("SKIP %d ", skip); if ( ! skip ) { row = mSelStartT/7; col = mSelStartT -row*7; diff --git a/korganizer/kodaymatrix.h b/korganizer/kodaymatrix.h index 10f4b05..2a1959c 100644 --- a/korganizer/kodaymatrix.h +++ b/korganizer/kodaymatrix.h @@ -154,7 +154,7 @@ public: * start and ending with end. Theview must be manually updated by calling * repaint. (?) */ - void setSelectedDaysFrom(const QDate& start, const QDate& end); + bool setSelectedDaysFrom(const QDate& start, const QDate& end); void clearSelection(); /** Is today visible in the view? Keep this in sync with |