Diffstat (limited to 'korganizer/datenavigatorcontainer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | korganizer/datenavigatorcontainer.cpp | 224 |
1 files changed, 116 insertions, 108 deletions
diff --git a/korganizer/datenavigatorcontainer.cpp b/korganizer/datenavigatorcontainer.cpp index ba97fa6..548c364 100644 --- a/korganizer/datenavigatorcontainer.cpp +++ b/korganizer/datenavigatorcontainer.cpp @@ -94,113 +94,224 @@ void DateNavigatorContainer::slotMonthSelected( int month ) #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 ) { mCalendar = cal; mNavigatorView->setCalendar( cal ); for( uint i = 0; i < mLastDisplayedDN; ++i ) { KDateNavigator *n = mExtraViews.at( i ); n->setCalendar( cal ); } } void DateNavigatorContainer::checkUpdateDayMatrixDates() -{ +{ + qDebug("wid %d hei %d ", width(), height()); + mUpdateTimer->stop(); + //return; + if ( width() < 3 || height() < 3 ) + return; + static int lastWid = 0; + static int lastHei = 0; + if ( lastWid == width() && height() == lastHei ) { + qDebug("no layout computing needed. "); + } else { + lastWid = width(); + lastHei = height(); + + QSize minSize = mNavigatorView->yourSizeHint(); + + 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 ); + bool fontchange = false; + if ( horizontalCount == 1) + horizontalCount = size().width() / mNavigatorView->yourFullSizeHint().width(); + QFont fo; + if ( horizontalCount != mHorizontalCount || + verticalCount != mVerticalCount ) { + uint count = horizontalCount * verticalCount; + if ( count == 0 ) { + bool ok; + fo = mNavigatorView->yourFontHint( size() , &ok ); + //mNavigatorView->resize( size() ); + //if ( ! ok ) + // return; + int butt = 2; + horizontalCount = size().width() / mNavigatorView->sizeHintTwoButtons( ).width(); + if ( horizontalCount <= 1 ) + minSize = mNavigatorView->sizeHintTwoButtons( 4 ); + else + minSize = mNavigatorView->sizeHintTwoButtons(); + verticalCount = size().height() / minSize.height(); + horizontalCount = size().width() / minSize.width(); + if ( horizontalCount == 0 ) + horizontalCount = 1; + if ( verticalCount == 0 ) + verticalCount = 1; + fontchange = true; + count = horizontalCount * verticalCount; + } else { + if ( mNavigatorView->fontChanged() ) { + fontchange = true; + fo = KOPrefs::instance()->mDateNavigatorFont; + mNavigatorView->changeFont( fo ); + mNavigatorView->unsetFontChanged(); + } + } + + mLastDisplayedDN = horizontalCount*verticalCount-1; + while ( count > ( mExtraViews.count() + 1 ) ) { + KDateNavigator *n = new KDateNavigator( this ); + n->setMonthSignalOffset ( mExtraViews.count()+1 ); + mExtraViews.append( n ); + n->setCalendar( mCalendar ); + connectNavigatorView( n ); + n->show(); + } + int iii = 0; + while ( iii < ( mExtraViews.count() ) ) { + if ( iii < count-1 ) + mExtraViews.at( iii )->show(); + else + mExtraViews.at( iii )->hide(); + ++iii; + } + + setBaseDates(); + if ( fontchange ) { + //mNavigatorView->changeFont( fo ); + uint i; + for( i = 0; i < mExtraViews.count(); ++i ) { + KDateNavigator *view = mExtraViews.at( i ); + view->changeFont( fo ); + } + } + mHorizontalCount = horizontalCount; + mVerticalCount = verticalCount; + + } + + int theight = height() / mVerticalCount; + int twidth = width() / mHorizontalCount; + + NavigatorBar *bar = mNavigatorView->navigatorBar(); + if ( mHorizontalCount > 1 ) bar->showButtons( true, false ); + else bar->showButtons( true, true ); + + mNavigatorView->setGeometry(0, + 0, twidth, theight ); + for( uint i = 0; i < mLastDisplayedDN; ++i ) { + int x = ( i + 1 ) % mHorizontalCount; + int y = ( i + 1 ) / mHorizontalCount; + + KDateNavigator *view = mExtraViews.at( i ); + bar = view->navigatorBar(); + if ( y > 0 ) bar->showButtons( false, false ); + else { + if ( x + 1 == mHorizontalCount ) bar->showButtons( false, true ); + else bar->showButtons( false, false ); + } + view->setGeometry( x * twidth, + y * theight, twidth, theight ); + } + } + QDate last = lastAvailableDate(); QDate first = firstAvailableDate(); QDate selFirst = mFirstSelectedDate; QDate selLast = selFirst.addDays( mSelectedDateCount-1 ); if ( selFirst >= first && selLast <= last ) { updateDayMatrixDates(); } else { updateDayMatrixDates(); emit monthSelected( mFirstSelectedDate.month() ); } } void DateNavigatorContainer::updateDayMatrixDates() { - mUpdateTimer->stop(); 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() { mNavigatorView->updateDayMatrix(); for( uint i = 0; i < mLastDisplayedDN; ++i ) { KDateNavigator *n = mExtraViews.at( i ); 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(); for( uint i = 0; i < mLastDisplayedDN; ++i ) { KDateNavigator *n = mExtraViews.at( i ); n->updateView(); } } void DateNavigatorContainer::updateConfig() { mNavigatorView->updateConfig(); for( uint i = 0; i < mLastDisplayedDN; ++i ) { KDateNavigator *n = mExtraViews.at( i ); n->updateConfig(); @@ -224,168 +335,65 @@ QDate DateNavigatorContainer::lastAvailableDate() const } 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 ); return; } QDate fDate = dateList.first(); QDate lDate = dateList.last(); //qDebug("%s %s ", lastAvailableDate().toString().latin1(), firstAvailableDate().toString().latin1() ); //qDebug("End %s %s ",lDate.toString().latin1(),curEnd.toString().latin1() ); if ( lDate <= lastAvailableDate() && firstAvailableDate() <= fDate) { updateDayMatrixDates(); return; } mNavigatorView->selectDates( dateList ); setBaseDates(); if ( mLastDisplayedDN ) { KDateNavigator *view = mExtraViews.at( 0 ); view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); view->dayMatrix()->repaint( false ); if ( mLastDisplayedDN > 1 ) { KDateNavigator *view = mExtraViews.at( 1 ); view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); view->dayMatrix()->repaint( false ); } } } void DateNavigatorContainer::setBaseDates() { 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 ); } } 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->sizeHintTwoButtons(); - 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 ); - bool fontchange = false; - if ( horizontalCount == 1) - horizontalCount = size().width() / mNavigatorView->yourFullSizeHint().width(); - QFont fo; - if ( horizontalCount != mHorizontalCount || - verticalCount != mVerticalCount ) { - uint count = horizontalCount * verticalCount; - if ( count == 0 ) { - bool ok; - fo = mNavigatorView->yourFontHint( size() , &ok ); - //mNavigatorView->resize( size() ); - //if ( ! ok ) - // return; - int butt = 2; - horizontalCount = size().width() / mNavigatorView->sizeHintTwoButtons( ).width(); - if ( horizontalCount <= 1 ) - minSize = mNavigatorView->sizeHintTwoButtons( 4 ); - else - minSize = mNavigatorView->sizeHintTwoButtons(); - verticalCount = size().height() / minSize.height(); - horizontalCount = size().width() / minSize.width(); - if ( horizontalCount == 0 ) - horizontalCount = 1; - if ( verticalCount == 0 ) - verticalCount = 1; - fontchange = true; - count = horizontalCount * verticalCount; - } else { - if ( mNavigatorView->fontChanged() ) { - fontchange = true; - fo = KOPrefs::instance()->mDateNavigatorFont; - mNavigatorView->changeFont( fo ); - mNavigatorView->unsetFontChanged(); - } - } - mLastDisplayedDN = horizontalCount*verticalCount-1; - while ( count > ( mExtraViews.count() + 1 ) ) { - KDateNavigator *n = new KDateNavigator( this ); - n->setMonthSignalOffset ( mExtraViews.count()+1 ); - mExtraViews.append( n ); - n->setCalendar( mCalendar ); - connectNavigatorView( n ); - n->show(); - } - int iii = 0; - while ( iii < ( mExtraViews.count() ) ) { - if ( iii < count-1 ) - mExtraViews.at( iii )->show(); - else - mExtraViews.at( iii )->hide(); - ++iii; - } - - setBaseDates(); - if ( fontchange ) { - //mNavigatorView->changeFont( fo ); - uint i; - for( i = 0; i < mExtraViews.count(); ++i ) { - KDateNavigator *view = mExtraViews.at( i ); - view->changeFont( fo ); - } - } - mHorizontalCount = horizontalCount; - mVerticalCount = verticalCount; - - } - //qDebug("COUNT %d ", mExtraViews.count()); - 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 < mLastDisplayedDN; ++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 ); - } - mUpdateTimer->start( 250 ); + //qDebug("COUNT %d ", mExtraViews.count()); + + mUpdateTimer->start( 250 ); //updateDayMatrixDates(); } QSize DateNavigatorContainer::minimumSizeHint() const { return mNavigatorView->minimumSizeHint(); } QSize DateNavigatorContainer::sizeHint() const { return mNavigatorView->yourSizeHint(); } |