summaryrefslogtreecommitdiffabout
path: root/korganizer/datenavigatorcontainer.cpp
Unidiff
Diffstat (limited to 'korganizer/datenavigatorcontainer.cpp') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/datenavigatorcontainer.cpp40
1 files changed, 27 insertions, 13 deletions
diff --git a/korganizer/datenavigatorcontainer.cpp b/korganizer/datenavigatorcontainer.cpp
index 2290c53..11dc592 100644
--- a/korganizer/datenavigatorcontainer.cpp
+++ b/korganizer/datenavigatorcontainer.cpp
@@ -19,52 +19,53 @@
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 20
21 As a special exception, permission is given to link this program 21 As a special exception, permission is given to link this program
22 with any edition of Qt, and distribute the resulting executable, 22 with any edition of Qt, and distribute the resulting executable,
23 without including the source code for Qt in the source distribution. 23 without including the source code for Qt in the source distribution.
24*/ 24*/
25 25
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
38DateNavigatorContainer::DateNavigatorContainer( QWidget *parent, 38DateNavigatorContainer::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 mResizeEnabled = false;
43 mExtraViews.setAutoDelete( true ); 44 mExtraViews.setAutoDelete( true );
44 45
45 mNavigatorView = new KDateNavigator( this, name ); 46 mNavigatorView = new KDateNavigator( this, name );
46 47 mNavigatorView->hide();
47 connectNavigatorView( mNavigatorView ); 48 connectNavigatorView( mNavigatorView );
48 //setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); 49 //setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) );
49 mLastDisplayedDN = 0; 50 mLastDisplayedDN = 0;
50 mUpdateTimer; 51 mUpdateTimer;
51 mUpdateTimer = new QTimer( this ); 52 mUpdateTimer = new QTimer( this );
52 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( checkUpdateDayMatrixDates() )); 53 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( checkUpdateDayMatrixDates() ));
53 mFirstSelectedDate = QDate::currentDate(); 54 mFirstSelectedDate = QDate::currentDate();
54 mSelectedDateCount = 1; 55 mSelectedDateCount = 1;
55} 56}
56 57
57DateNavigatorContainer::~DateNavigatorContainer() 58DateNavigatorContainer::~DateNavigatorContainer()
58{ 59{
59} 60}
60 61
61void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) 62void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v )
62{ 63{
63 connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ), 64 connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ),
64 SIGNAL( datesSelected( const KCal::DateList & ) ) ); 65 SIGNAL( datesSelected( const KCal::DateList & ) ) );
65#if 0 66#if 0
66 connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ), 67 connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ),
67 SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) ); 68 SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) );
68 connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ), 69 connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ),
69 SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) ); 70 SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) );
70#endif 71#endif
@@ -197,96 +198,99 @@ void DateNavigatorContainer::checkUpdateDayMatrixDates()
197 verticalCount = size().height() / minSize.height(); 198 verticalCount = size().height() / minSize.height();
198 horizontalCount = size().width() / minSize.width(); 199 horizontalCount = size().width() / minSize.width();
199 if ( horizontalCount == 0 ) 200 if ( horizontalCount == 0 )
200 horizontalCount = 1; 201 horizontalCount = 1;
201 if ( verticalCount == 0 ) 202 if ( verticalCount == 0 )
202 verticalCount = 1; 203 verticalCount = 1;
203 fontchange = true; 204 fontchange = true;
204 count = horizontalCount * verticalCount; 205 count = horizontalCount * verticalCount;
205 } else { 206 } else {
206 if ( mNavigatorView->fontChanged() ) { 207 if ( mNavigatorView->fontChanged() ) {
207 fontchange = true; 208 fontchange = true;
208 fo = KOPrefs::instance()->mDateNavigatorFont; 209 fo = KOPrefs::instance()->mDateNavigatorFont;
209 mNavigatorView->changeFont( fo ); 210 mNavigatorView->changeFont( fo );
210 mNavigatorView->unsetFontChanged(); 211 mNavigatorView->unsetFontChanged();
211 } 212 }
212 } 213 }
213 214
214 mLastDisplayedDN = horizontalCount*verticalCount-1; 215 mLastDisplayedDN = horizontalCount*verticalCount-1;
215 while ( count > ( mExtraViews.count() + 1 ) ) { 216 while ( count > ( mExtraViews.count() + 1 ) ) {
216 KDateNavigator *n = new KDateNavigator( this ); 217 KDateNavigator *n = new KDateNavigator( this );
217 n->setMonthSignalOffset ( mExtraViews.count()+1 ); 218 n->setMonthSignalOffset ( mExtraViews.count()+1 );
218 mExtraViews.append( n ); 219 mExtraViews.append( n );
219 n->setCalendar( mCalendar ); 220 n->setCalendar( mCalendar );
220 connectNavigatorView( n ); 221 connectNavigatorView( n );
221 n->show(); 222 // n->show();
222 }
223 int iii = 0;
224 while ( iii < ( mExtraViews.count() ) ) {
225 if ( iii < count-1 )
226 mExtraViews.at( iii )->show();
227 else
228 mExtraViews.at( iii )->hide();
229 ++iii;
230 } 223 }
231 224
225
232 setBaseDates(); 226 setBaseDates();
233 if ( fontchange ) { 227 if ( fontchange ) {
234 //mNavigatorView->changeFont( fo ); 228 //mNavigatorView->changeFont( fo );
235 uint i; 229 uint i;
236 for( i = 0; i < mExtraViews.count(); ++i ) { 230 for( i = 0; i < mExtraViews.count(); ++i ) {
237 KDateNavigator *view = mExtraViews.at( i ); 231 KDateNavigator *view = mExtraViews.at( i );
238 view->changeFont( fo ); 232 view->changeFont( fo );
239 } 233 }
240 } 234 }
241 mHorizontalCount = horizontalCount; 235 mHorizontalCount = horizontalCount;
242 mVerticalCount = verticalCount; 236 mVerticalCount = verticalCount;
243 237
244 } 238 }
245 239
246 int theight = height() / mVerticalCount; 240 int theight = height() / mVerticalCount;
247 int twidth = width() / mHorizontalCount; 241 int twidth = width() / mHorizontalCount;
248 242
249 NavigatorBar *bar = mNavigatorView->navigatorBar(); 243 NavigatorBar *bar = mNavigatorView->navigatorBar();
250 if ( mHorizontalCount > 1 ) bar->showButtons( true, false ); 244 if ( mHorizontalCount > 1 ) bar->showButtons( true, false );
251 else bar->showButtons( true, true ); 245 else bar->showButtons( true, true );
252 246
253 mNavigatorView->setGeometry(0, 247 mNavigatorView->setGeometry(0,
254 0, twidth, theight ); 248 0, twidth, theight );
255 for( uint i = 0; i < mLastDisplayedDN; ++i ) { 249 for( uint i = 0; i < mLastDisplayedDN; ++i ) {
256 int x = ( i + 1 ) % mHorizontalCount; 250 int x = ( i + 1 ) % mHorizontalCount;
257 int y = ( i + 1 ) / mHorizontalCount; 251 int y = ( i + 1 ) / mHorizontalCount;
258 252
259 KDateNavigator *view = mExtraViews.at( i ); 253 KDateNavigator *view = mExtraViews.at( i );
260 bar = view->navigatorBar(); 254 bar = view->navigatorBar();
261 if ( y > 0 ) bar->showButtons( false, false ); 255 if ( y > 0 ) bar->showButtons( false, false );
262 else { 256 else {
263 if ( x + 1 == mHorizontalCount ) bar->showButtons( false, true ); 257 if ( x + 1 == mHorizontalCount ) bar->showButtons( false, true );
264 else bar->showButtons( false, false ); 258 else bar->showButtons( false, false );
265 } 259 }
266 view->setGeometry( x * twidth, 260 view->setGeometry( x * twidth,
267 y * theight, twidth, theight ); 261 y * theight, twidth, theight );
268 } 262 }
263 int iii = 0;
264 int ccc = mHorizontalCount * mVerticalCount;
265 mNavigatorView->show();
266 while ( iii < ( mExtraViews.count() ) ) {
267 if ( iii < ccc-1 )
268 mExtraViews.at( iii )->show();
269 else
270 mExtraViews.at( iii )->hide();
271 ++iii;
272 }
269 } 273 }
270 274
271 QDate last = lastAvailableDate(); 275 QDate last = lastAvailableDate();
272 QDate first = firstAvailableDate(); 276 QDate first = firstAvailableDate();
273 277
274 QDate selFirst = mFirstSelectedDate; 278 QDate selFirst = mFirstSelectedDate;
275 QDate selLast = selFirst.addDays( mSelectedDateCount-1 ); 279 QDate selLast = selFirst.addDays( mSelectedDateCount-1 );
276 if ( selFirst >= first && selLast <= last ) { 280 if ( selFirst >= first && selLast <= last ) {
277 updateDayMatrixDates(); 281 updateDayMatrixDates();
278 } 282 }
279 else { 283 else {
280 updateDayMatrixDates(); 284 updateDayMatrixDates();
281 emit monthSelected( mFirstSelectedDate.month() ); 285 emit monthSelected( mFirstSelectedDate.month() );
282 } 286 }
283} 287}
284void DateNavigatorContainer::updateDayMatrixDates() 288void DateNavigatorContainer::updateDayMatrixDates()
285{ 289{
286 QDate fDate = mFirstSelectedDate; 290 QDate fDate = mFirstSelectedDate;
287 QDate lDate = fDate.addDays( mSelectedDateCount - 1 ); 291 QDate lDate = fDate.addDays( mSelectedDateCount - 1 );
288 mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate ); 292 mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate );
289 mNavigatorView->dayMatrix()->repaint( false ); 293 mNavigatorView->dayMatrix()->repaint( false );
290 for( uint i = 0; i < mLastDisplayedDN; ++i ) { 294 for( uint i = 0; i < mLastDisplayedDN; ++i ) {
291 KDateNavigator *n = mExtraViews.at( i ); 295 KDateNavigator *n = mExtraViews.at( i );
292 if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) { 296 if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) {
@@ -372,44 +376,54 @@ void DateNavigatorContainer::selectDates( const DateList &dateList )
372 mNavigatorView->selectDates( dateList ); 376 mNavigatorView->selectDates( dateList );
373 setBaseDates(); 377 setBaseDates();
374 if ( mLastDisplayedDN ) { 378 if ( mLastDisplayedDN ) {
375 KDateNavigator *view = mExtraViews.at( 0 ); 379 KDateNavigator *view = mExtraViews.at( 0 );
376 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); 380 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
377 view->dayMatrix()->repaint( false ); 381 view->dayMatrix()->repaint( false );
378 if ( mLastDisplayedDN > 1 ) { 382 if ( mLastDisplayedDN > 1 ) {
379 KDateNavigator *view = mExtraViews.at( 1 ); 383 KDateNavigator *view = mExtraViews.at( 1 );
380 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); 384 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
381 view->dayMatrix()->repaint( false ); 385 view->dayMatrix()->repaint( false );
382 } 386 }
383 } 387 }
384} 388}
385 389
386void DateNavigatorContainer::setBaseDates() 390void DateNavigatorContainer::setBaseDates()
387{ 391{
388 QDate baseDate = mNavigatorView->baseDate(); 392 QDate baseDate = mNavigatorView->baseDate();
389 bool doRepaint = true; 393 bool doRepaint = true;
390 for( uint i = 0; i < mLastDisplayedDN; ++i ) { 394 for( uint i = 0; i < mLastDisplayedDN; ++i ) {
391 KDateNavigator *n = mExtraViews.at( i ); 395 KDateNavigator *n = mExtraViews.at( i );
392 baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 ); 396 baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 );
393 n->setBaseDate( baseDate, doRepaint ); 397 n->setBaseDate( baseDate, doRepaint );
394 } 398 }
395} 399}
396 400void DateNavigatorContainer::setResizeEnabled()
401{
402 mResizeEnabled = true;
403 //qDebug("DateNavigatorContainer::setResizeEnabled ");
404 checkUpdateDayMatrixDates();
405}
397void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) 406void DateNavigatorContainer::resizeEvent( QResizeEvent * e )
398{ 407{
399 408
400 409 //qDebug("DateNavigatorContainer::resizeEvent %d %d ", width(), height());
401 //qDebug("COUNT %d ", mExtraViews.count()); 410 //qDebug("COUNT %d ", mExtraViews.count());
402 411 if ( ! mResizeEnabled ) {
412 //qDebug("NOT ResizeEnabled");
413 return;
414 }
415 else
403 mUpdateTimer->start( 250 ); 416 mUpdateTimer->start( 250 );
417
404 //updateDayMatrixDates(); 418 //updateDayMatrixDates();
405} 419}
406 420
407QSize DateNavigatorContainer::minimumSizeHint() const 421QSize DateNavigatorContainer::minimumSizeHint() const
408{ 422{
409 return mNavigatorView->minimumSizeHint(); 423 return mNavigatorView->minimumSizeHint();
410} 424}
411 425
412QSize DateNavigatorContainer::sizeHint() const 426QSize DateNavigatorContainer::sizeHint() const
413{ 427{
414 return mNavigatorView->yourSizeHint(); 428 return mNavigatorView->yourSizeHint();
415} 429}