Diffstat (limited to 'korganizer/datenavigatorcontainer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | korganizer/datenavigatorcontainer.cpp | 114 |
1 files changed, 91 insertions, 23 deletions
diff --git a/korganizer/datenavigatorcontainer.cpp b/korganizer/datenavigatorcontainer.cpp index bb27bce..6de7c45 100644 --- a/korganizer/datenavigatorcontainer.cpp +++ b/korganizer/datenavigatorcontainer.cpp @@ -47,5 +47,4 @@ DateNavigatorContainer::DateNavigatorContainer( QWidget *parent, connectNavigatorView( mNavigatorView ); //setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); - mDisplayedEndDate = QDate::currentDate(); mLastDisplayedDN = 0; } @@ -76,7 +75,56 @@ void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); - connect( v, SIGNAL( monthSelected( int ) ), SIGNAL( monthSelected( int ) ) ); + connect( v, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) ); } +void DateNavigatorContainer::slotMonthSelected( int month ) +{ + //qDebug("slotMonthSelected %d ", month); + QDate baseDate = mNavigatorView->baseDate(); + if ( baseDate.month() == month ) + return; + //qDebug("month %d %d ",baseDate.month(),month); + QDate date = QDate ( baseDate.year(), baseDate.month() , 15 ); + date = date.addDays( -(baseDate.month()-month ) *30 ); + QDate newBase = QDate ( date.year(), date.month() , baseDate.day() ); + +#if 0 + mFirstSelectedDate = dateList.first() ; + mSelectedDateCount = dateList.count() ; + + 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; + } +#endif + //qDebug("NEW BASE %s", newBase.toString().latin1()); + mNavigatorView->setBaseDate( newBase ); + QDate last = lastAvailableDate(); + QDate first = firstAvailableDate(); + + QDate selFirst = mFirstSelectedDate; + QDate selLast = selFirst.addDays( mSelectedDateCount-1 ); + if ( selFirst >= first && selLast <= last ) { + setBaseDates(); + updateDayMatrixDates(); + } + else { + setBaseDates(); + updateDayMatrixDates(); + emit monthSelected( month ); + } +} void DateNavigatorContainer::setCalendar( Calendar *cal ) { @@ -88,4 +136,18 @@ void DateNavigatorContainer::setCalendar( Calendar *cal ) } } +void DateNavigatorContainer::updateDayMatrixDates() +{ + + QDate fDate = mFirstSelectedDate; + QDate lDate = fDate.addDays( mSelectedDateCount - 1 ); + 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 ); + } + } +} void DateNavigatorContainer::updateDayMatrix() @@ -127,7 +189,28 @@ void DateNavigatorContainer::updateConfig() } } - +QDate DateNavigatorContainer::lastAvailableDate() const +{ + QDate date = mNavigatorView->baseDate(); + QDate last = QDate ( date.year(), date.month(), date.daysInMonth() ); + int iii = mLastDisplayedDN; + if ( mLastDisplayedDN ) + last = last.addDays( 1); + while ( iii ) { + last = last.addDays( last.daysInMonth ()); + //qDebug("DATE %s ", last.toString().latin1() ); + --iii; + } + if ( mLastDisplayedDN ) + last = last.addDays( -1); + return last; +} +QDate DateNavigatorContainer::firstAvailableDate() const +{ + return QDate ( mNavigatorView->baseDate().year(), mNavigatorView->baseDate().month(), 1 ); +} void DateNavigatorContainer::selectDates( const DateList &dateList ) { + mFirstSelectedDate = dateList.first() ; + mSelectedDateCount = dateList.count() ; if ( !mLastDisplayedDN ) { mNavigatorView->selectDates( dateList ); @@ -150,18 +233,8 @@ void DateNavigatorContainer::selectDates( const DateList &dateList ) return; } - KDateNavigator *view = mExtraViews.at( 0 ); - QDate date = view->baseDate(); - - QDate curEnd = date.addDays( (mLastDisplayedDN)*30 +7); + //qDebug("%s %s ", lastAvailableDate().toString().latin1(), firstAvailableDate().toString().latin1() ); //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 ); - } - } + if ( lDate <= lastAvailableDate() && firstAvailableDate() <= fDate) { + updateDayMatrixDates(); return; } @@ -182,15 +255,10 @@ void DateNavigatorContainer::selectDates( const DateList &dateList ) void DateNavigatorContainer::setBaseDates() { - KCal::DateList dateList = mNavigatorView->selectedDates(); - if ( dateList.isEmpty() ) { - kdError() << "DateNavigatorContainer::selectDates() empty list." << endl; - } - QDate baseDate = dateList.first(); - bool doRepaint = false; // skip first repaint + QDate baseDate = mNavigatorView->baseDate(); + bool doRepaint = true; 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; } } |