-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 | |||
@@ -136,13 +136,125 @@ void DateNavigatorContainer::setCalendar( Calendar *cal ) | |||
136 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | 136 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
137 | KDateNavigator *n = mExtraViews.at( i ); | 137 | KDateNavigator *n = mExtraViews.at( i ); |
138 | n->setCalendar( cal ); | 138 | n->setCalendar( cal ); |
139 | } | 139 | } |
140 | } | 140 | } |
141 | void DateNavigatorContainer::checkUpdateDayMatrixDates() | 141 | void DateNavigatorContainer::checkUpdateDayMatrixDates() |
142 | { | 142 | { |
143 | qDebug("wid %d hei %d ", width(), height()); | ||
144 | mUpdateTimer->stop(); | ||
145 | //return; | ||
146 | if ( width() < 3 || height() < 3 ) | ||
147 | return; | ||
148 | static int lastWid = 0; | ||
149 | static int lastHei = 0; | ||
150 | if ( lastWid == width() && height() == lastHei ) { | ||
151 | qDebug("no layout computing needed. "); | ||
152 | } else { | ||
153 | lastWid = width(); | ||
154 | lastHei = height(); | ||
155 | |||
156 | QSize minSize = mNavigatorView->yourSizeHint(); | ||
157 | |||
158 | int verticalCount = size().height() / minSize.height(); | ||
159 | int horizontalCount = size().width() / minSize.width(); | ||
160 | //qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() ); | ||
161 | //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount ); | ||
162 | bool fontchange = false; | ||
163 | if ( horizontalCount == 1) | ||
164 | horizontalCount = size().width() / mNavigatorView->yourFullSizeHint().width(); | ||
165 | QFont fo; | ||
166 | if ( horizontalCount != mHorizontalCount || | ||
167 | verticalCount != mVerticalCount ) { | ||
168 | uint count = horizontalCount * verticalCount; | ||
169 | if ( count == 0 ) { | ||
170 | bool ok; | ||
171 | fo = mNavigatorView->yourFontHint( size() , &ok ); | ||
172 | //mNavigatorView->resize( size() ); | ||
173 | //if ( ! ok ) | ||
174 | // return; | ||
175 | int butt = 2; | ||
176 | horizontalCount = size().width() / mNavigatorView->sizeHintTwoButtons( ).width(); | ||
177 | if ( horizontalCount <= 1 ) | ||
178 | minSize = mNavigatorView->sizeHintTwoButtons( 4 ); | ||
179 | else | ||
180 | minSize = mNavigatorView->sizeHintTwoButtons(); | ||
181 | verticalCount = size().height() / minSize.height(); | ||
182 | horizontalCount = size().width() / minSize.width(); | ||
183 | if ( horizontalCount == 0 ) | ||
184 | horizontalCount = 1; | ||
185 | if ( verticalCount == 0 ) | ||
186 | verticalCount = 1; | ||
187 | fontchange = true; | ||
188 | count = horizontalCount * verticalCount; | ||
189 | } else { | ||
190 | if ( mNavigatorView->fontChanged() ) { | ||
191 | fontchange = true; | ||
192 | fo = KOPrefs::instance()->mDateNavigatorFont; | ||
193 | mNavigatorView->changeFont( fo ); | ||
194 | mNavigatorView->unsetFontChanged(); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | mLastDisplayedDN = horizontalCount*verticalCount-1; | ||
199 | while ( count > ( mExtraViews.count() + 1 ) ) { | ||
200 | KDateNavigator *n = new KDateNavigator( this ); | ||
201 | n->setMonthSignalOffset ( mExtraViews.count()+1 ); | ||
202 | mExtraViews.append( n ); | ||
203 | n->setCalendar( mCalendar ); | ||
204 | connectNavigatorView( n ); | ||
205 | n->show(); | ||
206 | } | ||
207 | int iii = 0; | ||
208 | while ( iii < ( mExtraViews.count() ) ) { | ||
209 | if ( iii < count-1 ) | ||
210 | mExtraViews.at( iii )->show(); | ||
211 | else | ||
212 | mExtraViews.at( iii )->hide(); | ||
213 | ++iii; | ||
214 | } | ||
215 | |||
216 | setBaseDates(); | ||
217 | if ( fontchange ) { | ||
218 | //mNavigatorView->changeFont( fo ); | ||
219 | uint i; | ||
220 | for( i = 0; i < mExtraViews.count(); ++i ) { | ||
221 | KDateNavigator *view = mExtraViews.at( i ); | ||
222 | view->changeFont( fo ); | ||
223 | } | ||
224 | } | ||
225 | mHorizontalCount = horizontalCount; | ||
226 | mVerticalCount = verticalCount; | ||
227 | |||
228 | } | ||
229 | |||
230 | int theight = height() / mVerticalCount; | ||
231 | int twidth = width() / mHorizontalCount; | ||
232 | |||
233 | NavigatorBar *bar = mNavigatorView->navigatorBar(); | ||
234 | if ( mHorizontalCount > 1 ) bar->showButtons( true, false ); | ||
235 | else bar->showButtons( true, true ); | ||
236 | |||
237 | mNavigatorView->setGeometry(0, | ||
238 | 0, twidth, theight ); | ||
239 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | ||
240 | int x = ( i + 1 ) % mHorizontalCount; | ||
241 | int y = ( i + 1 ) / mHorizontalCount; | ||
242 | |||
243 | KDateNavigator *view = mExtraViews.at( i ); | ||
244 | bar = view->navigatorBar(); | ||
245 | if ( y > 0 ) bar->showButtons( false, false ); | ||
246 | else { | ||
247 | if ( x + 1 == mHorizontalCount ) bar->showButtons( false, true ); | ||
248 | else bar->showButtons( false, false ); | ||
249 | } | ||
250 | view->setGeometry( x * twidth, | ||
251 | y * theight, twidth, theight ); | ||
252 | } | ||
253 | } | ||
254 | |||
143 | QDate last = lastAvailableDate(); | 255 | QDate last = lastAvailableDate(); |
144 | QDate first = firstAvailableDate(); | 256 | QDate first = firstAvailableDate(); |
145 | 257 | ||
146 | QDate selFirst = mFirstSelectedDate; | 258 | QDate selFirst = mFirstSelectedDate; |
147 | QDate selLast = selFirst.addDays( mSelectedDateCount-1 ); | 259 | QDate selLast = selFirst.addDays( mSelectedDateCount-1 ); |
148 | if ( selFirst >= first && selLast <= last ) { | 260 | if ( selFirst >= first && selLast <= last ) { |
@@ -152,13 +264,12 @@ void DateNavigatorContainer::checkUpdateDayMatrixDates() | |||
152 | updateDayMatrixDates(); | 264 | updateDayMatrixDates(); |
153 | emit monthSelected( mFirstSelectedDate.month() ); | 265 | emit monthSelected( mFirstSelectedDate.month() ); |
154 | } | 266 | } |
155 | } | 267 | } |
156 | void DateNavigatorContainer::updateDayMatrixDates() | 268 | void DateNavigatorContainer::updateDayMatrixDates() |
157 | { | 269 | { |
158 | mUpdateTimer->stop(); | ||
159 | QDate fDate = mFirstSelectedDate; | 270 | QDate fDate = mFirstSelectedDate; |
160 | QDate lDate = fDate.addDays( mSelectedDateCount - 1 ); | 271 | QDate lDate = fDate.addDays( mSelectedDateCount - 1 ); |
161 | mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate ); | 272 | mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate ); |
162 | mNavigatorView->dayMatrix()->repaint( false ); | 273 | mNavigatorView->dayMatrix()->repaint( false ); |
163 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | 274 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
164 | KDateNavigator *n = mExtraViews.at( i ); | 275 | KDateNavigator *n = mExtraViews.at( i ); |
@@ -266,120 +377,17 @@ void DateNavigatorContainer::setBaseDates() | |||
266 | n->setBaseDate( baseDate, doRepaint ); | 377 | n->setBaseDate( baseDate, doRepaint ); |
267 | } | 378 | } |
268 | } | 379 | } |
269 | 380 | ||
270 | void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) | 381 | void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) |
271 | { | 382 | { |
272 | #if 0 | ||
273 | kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl; | ||
274 | kdDebug(5850) << " CURRENT SIZE: " << size() << endl; | ||
275 | kdDebug(5850) << " MINIMUM SIZEHINT: " << minimumSizeHint() << endl; | ||
276 | kdDebug(5850) << " SIZEHINT: " << sizeHint() << endl; | ||
277 | kdDebug(5850) << " MINIMUM SIZE: " << minimumSize() << endl; | ||
278 | #endif | ||
279 | //QSize minSize = mNavigatorView->sizeHintTwoButtons(); | ||
280 | QSize minSize = mNavigatorView->yourSizeHint(); | ||
281 | |||
282 | // kdDebug(5850) << " NAVIGATORVIEW minimumSizeHint: " << minSize << endl; | ||
283 | |||
284 | int verticalCount = size().height() / minSize.height(); | ||
285 | int horizontalCount = size().width() / minSize.width(); | ||
286 | //qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() ); | ||
287 | //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount ); | ||
288 | bool fontchange = false; | ||
289 | if ( horizontalCount == 1) | ||
290 | horizontalCount = size().width() / mNavigatorView->yourFullSizeHint().width(); | ||
291 | QFont fo; | ||
292 | if ( horizontalCount != mHorizontalCount || | ||
293 | verticalCount != mVerticalCount ) { | ||
294 | uint count = horizontalCount * verticalCount; | ||
295 | if ( count == 0 ) { | ||
296 | bool ok; | ||
297 | fo = mNavigatorView->yourFontHint( size() , &ok ); | ||
298 | //mNavigatorView->resize( size() ); | ||
299 | //if ( ! ok ) | ||
300 | // return; | ||
301 | int butt = 2; | ||
302 | horizontalCount = size().width() / mNavigatorView->sizeHintTwoButtons( ).width(); | ||
303 | if ( horizontalCount <= 1 ) | ||
304 | minSize = mNavigatorView->sizeHintTwoButtons( 4 ); | ||
305 | else | ||
306 | minSize = mNavigatorView->sizeHintTwoButtons(); | ||
307 | verticalCount = size().height() / minSize.height(); | ||
308 | horizontalCount = size().width() / minSize.width(); | ||
309 | if ( horizontalCount == 0 ) | ||
310 | horizontalCount = 1; | ||
311 | if ( verticalCount == 0 ) | ||
312 | verticalCount = 1; | ||
313 | fontchange = true; | ||
314 | count = horizontalCount * verticalCount; | ||
315 | } else { | ||
316 | if ( mNavigatorView->fontChanged() ) { | ||
317 | fontchange = true; | ||
318 | fo = KOPrefs::instance()->mDateNavigatorFont; | ||
319 | mNavigatorView->changeFont( fo ); | ||
320 | mNavigatorView->unsetFontChanged(); | ||
321 | } | ||
322 | } | ||
323 | 383 | ||
324 | mLastDisplayedDN = horizontalCount*verticalCount-1; | ||
325 | while ( count > ( mExtraViews.count() + 1 ) ) { | ||
326 | KDateNavigator *n = new KDateNavigator( this ); | ||
327 | n->setMonthSignalOffset ( mExtraViews.count()+1 ); | ||
328 | mExtraViews.append( n ); | ||
329 | n->setCalendar( mCalendar ); | ||
330 | connectNavigatorView( n ); | ||
331 | n->show(); | ||
332 | } | ||
333 | int iii = 0; | ||
334 | while ( iii < ( mExtraViews.count() ) ) { | ||
335 | if ( iii < count-1 ) | ||
336 | mExtraViews.at( iii )->show(); | ||
337 | else | ||
338 | mExtraViews.at( iii )->hide(); | ||
339 | ++iii; | ||
340 | } | ||
341 | |||
342 | setBaseDates(); | ||
343 | if ( fontchange ) { | ||
344 | //mNavigatorView->changeFont( fo ); | ||
345 | uint i; | ||
346 | for( i = 0; i < mExtraViews.count(); ++i ) { | ||
347 | KDateNavigator *view = mExtraViews.at( i ); | ||
348 | view->changeFont( fo ); | ||
349 | } | ||
350 | } | ||
351 | mHorizontalCount = horizontalCount; | ||
352 | mVerticalCount = verticalCount; | ||
353 | |||
354 | } | ||
355 | //qDebug("COUNT %d ", mExtraViews.count()); | ||
356 | int height = size().height() / verticalCount; | ||
357 | int width = size().width() / horizontalCount; | ||
358 | |||
359 | NavigatorBar *bar = mNavigatorView->navigatorBar(); | ||
360 | if ( horizontalCount > 1 ) bar->showButtons( true, false ); | ||
361 | else bar->showButtons( true, true ); | ||
362 | 384 | ||
363 | mNavigatorView->setGeometry(0, | 385 | //qDebug("COUNT %d ", mExtraViews.count()); |
364 | 0, width, height ); | 386 | |
365 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | 387 | mUpdateTimer->start( 250 ); |
366 | int x = ( i + 1 ) % horizontalCount; | ||
367 | int y = ( i + 1 ) / horizontalCount; | ||
368 | |||
369 | KDateNavigator *view = mExtraViews.at( i ); | ||
370 | bar = view->navigatorBar(); | ||
371 | if ( y > 0 ) bar->showButtons( false, false ); | ||
372 | else { | ||
373 | if ( x + 1 == horizontalCount ) bar->showButtons( false, true ); | ||
374 | else bar->showButtons( false, false ); | ||
375 | } | ||
376 | view->setGeometry( x * width, | ||
377 | y * height, width, height ); | ||
378 | } | ||
379 | mUpdateTimer->start( 250 ); | ||
380 | //updateDayMatrixDates(); | 388 | //updateDayMatrixDates(); |
381 | } | 389 | } |
382 | 390 | ||
383 | QSize DateNavigatorContainer::minimumSizeHint() const | 391 | QSize DateNavigatorContainer::minimumSizeHint() const |
384 | { | 392 | { |
385 | return mNavigatorView->minimumSizeHint(); | 393 | return mNavigatorView->minimumSizeHint(); |