Diffstat (limited to 'korganizer/datenavigatorcontainer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | korganizer/datenavigatorcontainer.cpp | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/korganizer/datenavigatorcontainer.cpp b/korganizer/datenavigatorcontainer.cpp index 9720146..ba97fa6 100644 --- a/korganizer/datenavigatorcontainer.cpp +++ b/korganizer/datenavigatorcontainer.cpp | |||
@@ -26,48 +26,51 @@ | |||
26 | #include <kdebug.h> | 26 | #include <kdebug.h> |
27 | #include <klocale.h> | 27 | #include <klocale.h> |
28 | 28 | ||
29 | //#include "koglobals.h" | 29 | //#include "koglobals.h" |
30 | #include "navigatorbar.h" | 30 | #include "navigatorbar.h" |
31 | #include "kdatenavigator.h" | 31 | #include "kdatenavigator.h" |
32 | 32 | ||
33 | #include <kcalendarsystem.h> | 33 | #include <kcalendarsystem.h> |
34 | 34 | ||
35 | #include "datenavigatorcontainer.h" | 35 | #include "datenavigatorcontainer.h" |
36 | #include "koprefs.h" | 36 | #include "koprefs.h" |
37 | 37 | ||
38 | DateNavigatorContainer::DateNavigatorContainer( QWidget *parent, | 38 | DateNavigatorContainer::DateNavigatorContainer( QWidget *parent, |
39 | const char *name ) | 39 | const char *name ) |
40 | : QWidget( parent, name ), mCalendar( 0 ), | 40 | : QWidget( parent, name ), mCalendar( 0 ), |
41 | mHorizontalCount( 1 ), mVerticalCount( 1 ) | 41 | mHorizontalCount( 1 ), mVerticalCount( 1 ) |
42 | { | 42 | { |
43 | mExtraViews.setAutoDelete( true ); | 43 | mExtraViews.setAutoDelete( true ); |
44 | 44 | ||
45 | mNavigatorView = new KDateNavigator( this, name ); | 45 | mNavigatorView = new KDateNavigator( this, name ); |
46 | 46 | ||
47 | connectNavigatorView( mNavigatorView ); | 47 | connectNavigatorView( mNavigatorView ); |
48 | //setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); | 48 | //setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); |
49 | mLastDisplayedDN = 0; | 49 | mLastDisplayedDN = 0; |
50 | mUpdateTimer; | ||
51 | mUpdateTimer = new QTimer( this ); | ||
52 | connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( checkUpdateDayMatrixDates() )); | ||
50 | } | 53 | } |
51 | 54 | ||
52 | DateNavigatorContainer::~DateNavigatorContainer() | 55 | DateNavigatorContainer::~DateNavigatorContainer() |
53 | { | 56 | { |
54 | } | 57 | } |
55 | 58 | ||
56 | void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) | 59 | void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) |
57 | { | 60 | { |
58 | connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ), | 61 | connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ), |
59 | SIGNAL( datesSelected( const KCal::DateList & ) ) ); | 62 | SIGNAL( datesSelected( const KCal::DateList & ) ) ); |
60 | #if 0 | 63 | #if 0 |
61 | connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ), | 64 | connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ), |
62 | SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) ); | 65 | SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) ); |
63 | connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ), | 66 | connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ), |
64 | SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) ); | 67 | SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) ); |
65 | #endif | 68 | #endif |
66 | connect( v, SIGNAL( weekClicked( const QDate & ) ), | 69 | connect( v, SIGNAL( weekClicked( const QDate & ) ), |
67 | SIGNAL( weekClicked( const QDate & ) ) ); | 70 | SIGNAL( weekClicked( const QDate & ) ) ); |
68 | 71 | ||
69 | connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) ); | 72 | connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) ); |
70 | connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) ); | 73 | connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) ); |
71 | 74 | ||
72 | connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); | 75 | connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); |
73 | connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); | 76 | connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); |
@@ -114,51 +117,66 @@ void DateNavigatorContainer::slotMonthSelected( int month ) | |||
114 | QDate last = lastAvailableDate(); | 117 | QDate last = lastAvailableDate(); |
115 | QDate first = firstAvailableDate(); | 118 | QDate first = firstAvailableDate(); |
116 | 119 | ||
117 | QDate selFirst = mFirstSelectedDate; | 120 | QDate selFirst = mFirstSelectedDate; |
118 | QDate selLast = selFirst.addDays( mSelectedDateCount-1 ); | 121 | QDate selLast = selFirst.addDays( mSelectedDateCount-1 ); |
119 | if ( selFirst >= first && selLast <= last ) { | 122 | if ( selFirst >= first && selLast <= last ) { |
120 | setBaseDates(); | 123 | setBaseDates(); |
121 | updateDayMatrixDates(); | 124 | updateDayMatrixDates(); |
122 | } | 125 | } |
123 | else { | 126 | else { |
124 | setBaseDates(); | 127 | setBaseDates(); |
125 | updateDayMatrixDates(); | 128 | updateDayMatrixDates(); |
126 | emit monthSelected( month ); | 129 | emit monthSelected( month ); |
127 | } | 130 | } |
128 | } | 131 | } |
129 | void DateNavigatorContainer::setCalendar( Calendar *cal ) | 132 | void DateNavigatorContainer::setCalendar( Calendar *cal ) |
130 | { | 133 | { |
131 | mCalendar = cal; | 134 | mCalendar = cal; |
132 | mNavigatorView->setCalendar( cal ); | 135 | mNavigatorView->setCalendar( cal ); |
133 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | 136 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
134 | KDateNavigator *n = mExtraViews.at( i ); | 137 | KDateNavigator *n = mExtraViews.at( i ); |
135 | n->setCalendar( cal ); | 138 | n->setCalendar( cal ); |
136 | } | 139 | } |
137 | } | 140 | } |
141 | void DateNavigatorContainer::checkUpdateDayMatrixDates() | ||
142 | { | ||
143 | QDate last = lastAvailableDate(); | ||
144 | QDate first = firstAvailableDate(); | ||
145 | |||
146 | QDate selFirst = mFirstSelectedDate; | ||
147 | QDate selLast = selFirst.addDays( mSelectedDateCount-1 ); | ||
148 | if ( selFirst >= first && selLast <= last ) { | ||
149 | updateDayMatrixDates(); | ||
150 | } | ||
151 | else { | ||
152 | updateDayMatrixDates(); | ||
153 | emit monthSelected( mFirstSelectedDate.month() ); | ||
154 | } | ||
155 | } | ||
138 | void DateNavigatorContainer::updateDayMatrixDates() | 156 | void DateNavigatorContainer::updateDayMatrixDates() |
139 | { | 157 | { |
140 | 158 | mUpdateTimer->stop(); | |
141 | QDate fDate = mFirstSelectedDate; | 159 | QDate fDate = mFirstSelectedDate; |
142 | QDate lDate = fDate.addDays( mSelectedDateCount - 1 ); | 160 | QDate lDate = fDate.addDays( mSelectedDateCount - 1 ); |
143 | mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate ); | 161 | mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate ); |
144 | mNavigatorView->dayMatrix()->repaint( false ); | 162 | mNavigatorView->dayMatrix()->repaint( false ); |
145 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | 163 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
146 | KDateNavigator *n = mExtraViews.at( i ); | 164 | KDateNavigator *n = mExtraViews.at( i ); |
147 | if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) { | 165 | if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) { |
148 | n->dayMatrix()->repaint( false ); | 166 | n->dayMatrix()->repaint( false ); |
149 | } | 167 | } |
150 | } | 168 | } |
151 | } | 169 | } |
152 | 170 | ||
153 | void DateNavigatorContainer::updateDayMatrix() | 171 | void DateNavigatorContainer::updateDayMatrix() |
154 | { | 172 | { |
155 | mNavigatorView->updateDayMatrix(); | 173 | mNavigatorView->updateDayMatrix(); |
156 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | 174 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
157 | KDateNavigator *n = mExtraViews.at( i ); | 175 | KDateNavigator *n = mExtraViews.at( i ); |
158 | n->updateDayMatrix(); | 176 | n->updateDayMatrix(); |
159 | } | 177 | } |
160 | } | 178 | } |
161 | 179 | ||
162 | void DateNavigatorContainer::updateToday() | 180 | void DateNavigatorContainer::updateToday() |
163 | { | 181 | { |
164 | qDebug("DateNavigatorContainer::updateToday() NOT IMPL "); | 182 | qDebug("DateNavigatorContainer::updateToday() NOT IMPL "); |
@@ -197,62 +215,48 @@ QDate DateNavigatorContainer::lastAvailableDate() const | |||
197 | last = last.addDays( 1); | 215 | last = last.addDays( 1); |
198 | while ( iii ) { | 216 | while ( iii ) { |
199 | last = last.addDays( last.daysInMonth ()); | 217 | last = last.addDays( last.daysInMonth ()); |
200 | //qDebug("DATE %s ", last.toString().latin1() ); | 218 | //qDebug("DATE %s ", last.toString().latin1() ); |
201 | --iii; | 219 | --iii; |
202 | } | 220 | } |
203 | if ( mLastDisplayedDN ) | 221 | if ( mLastDisplayedDN ) |
204 | last = last.addDays( -1); | 222 | last = last.addDays( -1); |
205 | return last; | 223 | return last; |
206 | } | 224 | } |
207 | QDate DateNavigatorContainer::firstAvailableDate() const | 225 | QDate DateNavigatorContainer::firstAvailableDate() const |
208 | { | 226 | { |
209 | return QDate ( mNavigatorView->baseDate().year(), mNavigatorView->baseDate().month(), 1 ); | 227 | return QDate ( mNavigatorView->baseDate().year(), mNavigatorView->baseDate().month(), 1 ); |
210 | } | 228 | } |
211 | void DateNavigatorContainer::selectDates( const DateList &dateList ) | 229 | void DateNavigatorContainer::selectDates( const DateList &dateList ) |
212 | { | 230 | { |
213 | mFirstSelectedDate = dateList.first() ; | 231 | mFirstSelectedDate = dateList.first() ; |
214 | mSelectedDateCount = dateList.count() ; | 232 | mSelectedDateCount = dateList.count() ; |
215 | if ( !mLastDisplayedDN ) { | 233 | if ( !mLastDisplayedDN ) { |
216 | mNavigatorView->selectDates( dateList ); | 234 | mNavigatorView->selectDates( dateList ); |
217 | return; | 235 | return; |
218 | } | 236 | } |
219 | QDate fDate = dateList.first(); | 237 | QDate fDate = dateList.first(); |
220 | QDate lDate = dateList.last(); | 238 | QDate lDate = dateList.last(); |
221 | if ( mLastDisplayedDN <= 2 ) { | ||
222 | mNavigatorView->selectDates( dateList ); | ||
223 | KDateNavigator *view = mExtraViews.at( 0 ); | ||
224 | QDate bDate = fDate.addDays( fDate.daysInMonth () - fDate.day() +1 ); | ||
225 | view->setBaseDate( bDate, false ); | ||
226 | view->dayMatrix()->setSelectedDaysFrom(fDate , lDate); | ||
227 | if ( mLastDisplayedDN == 2 ) { | ||
228 | view = mExtraViews.at( 1 ); | ||
229 | bDate = bDate.addDays( bDate.daysInMonth () - bDate.day() +1 ); | ||
230 | view->setBaseDate( bDate, false ); | ||
231 | view->dayMatrix()->setSelectedDaysFrom(fDate , lDate); | ||
232 | } | ||
233 | return; | ||
234 | } | ||
235 | //qDebug("%s %s ", lastAvailableDate().toString().latin1(), firstAvailableDate().toString().latin1() ); | 239 | //qDebug("%s %s ", lastAvailableDate().toString().latin1(), firstAvailableDate().toString().latin1() ); |
236 | //qDebug("End %s %s ",lDate.toString().latin1(),curEnd.toString().latin1() ); | 240 | //qDebug("End %s %s ",lDate.toString().latin1(),curEnd.toString().latin1() ); |
237 | if ( lDate <= lastAvailableDate() && firstAvailableDate() <= fDate) { | 241 | if ( lDate <= lastAvailableDate() && firstAvailableDate() <= fDate) { |
238 | updateDayMatrixDates(); | 242 | updateDayMatrixDates(); |
239 | return; | 243 | return; |
240 | } | 244 | } |
241 | mNavigatorView->selectDates( dateList ); | 245 | mNavigatorView->selectDates( dateList ); |
242 | setBaseDates(); | 246 | setBaseDates(); |
243 | if ( mLastDisplayedDN ) { | 247 | if ( mLastDisplayedDN ) { |
244 | KDateNavigator *view = mExtraViews.at( 0 ); | 248 | KDateNavigator *view = mExtraViews.at( 0 ); |
245 | view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); | 249 | view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); |
246 | view->dayMatrix()->repaint( false ); | 250 | view->dayMatrix()->repaint( false ); |
247 | if ( mLastDisplayedDN > 1 ) { | 251 | if ( mLastDisplayedDN > 1 ) { |
248 | KDateNavigator *view = mExtraViews.at( 1 ); | 252 | KDateNavigator *view = mExtraViews.at( 1 ); |
249 | view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); | 253 | view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); |
250 | view->dayMatrix()->repaint( false ); | 254 | view->dayMatrix()->repaint( false ); |
251 | } | 255 | } |
252 | } | 256 | } |
253 | } | 257 | } |
254 | 258 | ||
255 | void DateNavigatorContainer::setBaseDates() | 259 | void DateNavigatorContainer::setBaseDates() |
256 | { | 260 | { |
257 | QDate baseDate = mNavigatorView->baseDate(); | 261 | QDate baseDate = mNavigatorView->baseDate(); |
258 | bool doRepaint = true; | 262 | bool doRepaint = true; |
@@ -351,36 +355,37 @@ void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) | |||
351 | //qDebug("COUNT %d ", mExtraViews.count()); | 355 | //qDebug("COUNT %d ", mExtraViews.count()); |
352 | int height = size().height() / verticalCount; | 356 | int height = size().height() / verticalCount; |
353 | int width = size().width() / horizontalCount; | 357 | int width = size().width() / horizontalCount; |
354 | 358 | ||
355 | NavigatorBar *bar = mNavigatorView->navigatorBar(); | 359 | NavigatorBar *bar = mNavigatorView->navigatorBar(); |
356 | if ( horizontalCount > 1 ) bar->showButtons( true, false ); | 360 | if ( horizontalCount > 1 ) bar->showButtons( true, false ); |
357 | else bar->showButtons( true, true ); | 361 | else bar->showButtons( true, true ); |
358 | 362 | ||
359 | mNavigatorView->setGeometry(0, | 363 | mNavigatorView->setGeometry(0, |
360 | 0, width, height ); | 364 | 0, width, height ); |
361 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | 365 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
362 | int x = ( i + 1 ) % horizontalCount; | 366 | int x = ( i + 1 ) % horizontalCount; |
363 | int y = ( i + 1 ) / horizontalCount; | 367 | int y = ( i + 1 ) / horizontalCount; |
364 | 368 | ||
365 | KDateNavigator *view = mExtraViews.at( i ); | 369 | KDateNavigator *view = mExtraViews.at( i ); |
366 | bar = view->navigatorBar(); | 370 | bar = view->navigatorBar(); |
367 | if ( y > 0 ) bar->showButtons( false, false ); | 371 | if ( y > 0 ) bar->showButtons( false, false ); |
368 | else { | 372 | else { |
369 | if ( x + 1 == horizontalCount ) bar->showButtons( false, true ); | 373 | if ( x + 1 == horizontalCount ) bar->showButtons( false, true ); |
370 | else bar->showButtons( false, false ); | 374 | else bar->showButtons( false, false ); |
371 | } | 375 | } |
372 | view->setGeometry( x * width, | 376 | view->setGeometry( x * width, |
373 | y * height, width, height ); | 377 | y * height, width, height ); |
374 | } | 378 | } |
379 | mUpdateTimer->start( 250 ); | ||
375 | //updateDayMatrixDates(); | 380 | //updateDayMatrixDates(); |
376 | } | 381 | } |
377 | 382 | ||
378 | QSize DateNavigatorContainer::minimumSizeHint() const | 383 | QSize DateNavigatorContainer::minimumSizeHint() const |
379 | { | 384 | { |
380 | return mNavigatorView->minimumSizeHint(); | 385 | return mNavigatorView->minimumSizeHint(); |
381 | } | 386 | } |
382 | 387 | ||
383 | QSize DateNavigatorContainer::sizeHint() const | 388 | QSize DateNavigatorContainer::sizeHint() const |
384 | { | 389 | { |
385 | return mNavigatorView->yourSizeHint(); | 390 | return mNavigatorView->yourSizeHint(); |
386 | } | 391 | } |