summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-03-23 00:25:21 (UTC)
committer zautrix <zautrix>2005-03-23 00:25:21 (UTC)
commitf9ea17deecf671a897ff594a8050e6f4728698b6 (patch) (unidiff)
tree11dc1facc1140f5a58351418d98ca135f9683d12
parentaa6d19015bc91ae3af021d766d37a473e125278f (diff)
downloadkdepimpi-f9ea17deecf671a897ff594a8050e6f4728698b6.zip
kdepimpi-f9ea17deecf671a897ff594a8050e6f4728698b6.tar.gz
kdepimpi-f9ea17deecf671a897ff594a8050e6f4728698b6.tar.bz2
lf
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/datenavigatorcontainer.cpp224
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
@@ -1,391 +1,399 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 GNU General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
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 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; 50 mUpdateTimer;
51 mUpdateTimer = new QTimer( this ); 51 mUpdateTimer = new QTimer( this );
52 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( checkUpdateDayMatrixDates() )); 52 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( checkUpdateDayMatrixDates() ));
53} 53}
54 54
55DateNavigatorContainer::~DateNavigatorContainer() 55DateNavigatorContainer::~DateNavigatorContainer()
56{ 56{
57} 57}
58 58
59void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) 59void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v )
60{ 60{
61 connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ), 61 connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ),
62 SIGNAL( datesSelected( const KCal::DateList & ) ) ); 62 SIGNAL( datesSelected( const KCal::DateList & ) ) );
63#if 0 63#if 0
64 connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ), 64 connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ),
65 SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) ); 65 SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) );
66 connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ), 66 connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ),
67 SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) ); 67 SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) );
68#endif 68#endif
69 connect( v, SIGNAL( weekClicked( const QDate & ) ), 69 connect( v, SIGNAL( weekClicked( const QDate & ) ),
70 SIGNAL( weekClicked( const QDate & ) ) ); 70 SIGNAL( weekClicked( const QDate & ) ) );
71 71
72 connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) ); 72 connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) );
73 connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) ); 73 connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) );
74 74
75 connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); 75 connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) );
76 connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); 76 connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) );
77 connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); 77 connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) );
78 connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); 78 connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) );
79 79
80 connect( v, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) ); 80 connect( v, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) );
81} 81}
82 82
83void DateNavigatorContainer::slotMonthSelected( int month ) 83void DateNavigatorContainer::slotMonthSelected( int month )
84{ 84{
85 //qDebug("slotMonthSelected %d ", month); 85 //qDebug("slotMonthSelected %d ", month);
86 QDate baseDate = mNavigatorView->baseDate(); 86 QDate baseDate = mNavigatorView->baseDate();
87 if ( baseDate.month() == month ) 87 if ( baseDate.month() == month )
88 return; 88 return;
89 //qDebug("month %d %d ",baseDate.month(),month); 89 //qDebug("month %d %d ",baseDate.month(),month);
90 QDate date = QDate ( baseDate.year(), baseDate.month() , 15 ); 90 QDate date = QDate ( baseDate.year(), baseDate.month() , 15 );
91 date = date.addDays( -(baseDate.month()-month ) *30 ); 91 date = date.addDays( -(baseDate.month()-month ) *30 );
92 QDate newBase = QDate ( date.year(), date.month() , baseDate.day() ); 92 QDate newBase = QDate ( date.year(), date.month() , baseDate.day() );
93 93
94#if 0 94#if 0
95 mFirstSelectedDate = dateList.first() ; 95 mFirstSelectedDate = dateList.first() ;
96 mSelectedDateCount = dateList.count() ; 96 mSelectedDateCount = dateList.count() ;
97 97
98 KDateNavigator *view = mExtraViews.at( 0 ); 98 KDateNavigator *view = mExtraViews.at( 0 );
99 QDate date = view->baseDate(); 99 QDate date = view->baseDate();
100 100
101 QDate curEnd = date.addDays( (mLastDisplayedDN)*30 +7); 101 QDate curEnd = date.addDays( (mLastDisplayedDN)*30 +7);
102 //qDebug("End %s %s ",lDate.toString().latin1(),curEnd.toString().latin1() ); 102 //qDebug("End %s %s ",lDate.toString().latin1(),curEnd.toString().latin1() );
103 if ( lDate < curEnd && date.addDays( -30 ) < fDate) { 103 if ( lDate < curEnd && date.addDays( -30 ) < fDate) {
104 mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate ); 104 mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate );
105 mNavigatorView->dayMatrix()->repaint( false ); 105 mNavigatorView->dayMatrix()->repaint( false );
106 for( uint i = 0; i < mLastDisplayedDN; ++i ) { 106 for( uint i = 0; i < mLastDisplayedDN; ++i ) {
107 KDateNavigator *n = mExtraViews.at( i ); 107 KDateNavigator *n = mExtraViews.at( i );
108 if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) { 108 if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) {
109 n->dayMatrix()->repaint( false ); 109 n->dayMatrix()->repaint( false );
110 } 110 }
111 } 111 }
112 return; 112 return;
113 } 113 }
114#endif 114#endif
115 //qDebug("NEW BASE %s", newBase.toString().latin1()); 115 //qDebug("NEW BASE %s", newBase.toString().latin1());
116 mNavigatorView->setBaseDate( newBase ); 116 mNavigatorView->setBaseDate( newBase );
117 QDate last = lastAvailableDate(); 117 QDate last = lastAvailableDate();
118 QDate first = firstAvailableDate(); 118 QDate first = firstAvailableDate();
119 119
120 QDate selFirst = mFirstSelectedDate; 120 QDate selFirst = mFirstSelectedDate;
121 QDate selLast = selFirst.addDays( mSelectedDateCount-1 ); 121 QDate selLast = selFirst.addDays( mSelectedDateCount-1 );
122 if ( selFirst >= first && selLast <= last ) { 122 if ( selFirst >= first && selLast <= last ) {
123 setBaseDates(); 123 setBaseDates();
124 updateDayMatrixDates(); 124 updateDayMatrixDates();
125 } 125 }
126 else { 126 else {
127 setBaseDates(); 127 setBaseDates();
128 updateDayMatrixDates(); 128 updateDayMatrixDates();
129 emit monthSelected( month ); 129 emit monthSelected( month );
130 } 130 }
131} 131}
132void DateNavigatorContainer::setCalendar( Calendar *cal ) 132void DateNavigatorContainer::setCalendar( Calendar *cal )
133{ 133{
134 mCalendar = cal; 134 mCalendar = cal;
135 mNavigatorView->setCalendar( cal ); 135 mNavigatorView->setCalendar( 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}
141void DateNavigatorContainer::checkUpdateDayMatrixDates() 141void 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 ) {
149 updateDayMatrixDates(); 261 updateDayMatrixDates();
150 } 262 }
151 else { 263 else {
152 updateDayMatrixDates(); 264 updateDayMatrixDates();
153 emit monthSelected( mFirstSelectedDate.month() ); 265 emit monthSelected( mFirstSelectedDate.month() );
154 } 266 }
155} 267}
156void DateNavigatorContainer::updateDayMatrixDates() 268void 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 );
165 if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) { 276 if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) {
166 n->dayMatrix()->repaint( false ); 277 n->dayMatrix()->repaint( false );
167 } 278 }
168 } 279 }
169} 280}
170 281
171void DateNavigatorContainer::updateDayMatrix() 282void DateNavigatorContainer::updateDayMatrix()
172{ 283{
173 mNavigatorView->updateDayMatrix(); 284 mNavigatorView->updateDayMatrix();
174 for( uint i = 0; i < mLastDisplayedDN; ++i ) { 285 for( uint i = 0; i < mLastDisplayedDN; ++i ) {
175 KDateNavigator *n = mExtraViews.at( i ); 286 KDateNavigator *n = mExtraViews.at( i );
176 n->updateDayMatrix(); 287 n->updateDayMatrix();
177 } 288 }
178} 289}
179 290
180void DateNavigatorContainer::updateToday() 291void DateNavigatorContainer::updateToday()
181{ 292{
182 qDebug("DateNavigatorContainer::updateToday() NOT IMPL "); 293 qDebug("DateNavigatorContainer::updateToday() NOT IMPL ");
183#if 0 294#if 0
184 mNavigatorView->updateToday(); 295 mNavigatorView->updateToday();
185 KDateNavigator *n; 296 KDateNavigator *n;
186 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 297 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
187 n->updateToday(); 298 n->updateToday();
188 } 299 }
189#endif 300#endif
190} 301}
191 302
192void DateNavigatorContainer::updateView() 303void DateNavigatorContainer::updateView()
193{ 304{
194 mNavigatorView->updateView(); 305 mNavigatorView->updateView();
195 for( uint i = 0; i < mLastDisplayedDN; ++i ) { 306 for( uint i = 0; i < mLastDisplayedDN; ++i ) {
196 KDateNavigator *n = mExtraViews.at( i ); 307 KDateNavigator *n = mExtraViews.at( i );
197 n->updateView(); 308 n->updateView();
198 } 309 }
199} 310}
200 311
201void DateNavigatorContainer::updateConfig() 312void DateNavigatorContainer::updateConfig()
202{ 313{
203 mNavigatorView->updateConfig(); 314 mNavigatorView->updateConfig();
204 for( uint i = 0; i < mLastDisplayedDN; ++i ) { 315 for( uint i = 0; i < mLastDisplayedDN; ++i ) {
205 KDateNavigator *n = mExtraViews.at( i ); 316 KDateNavigator *n = mExtraViews.at( i );
206 n->updateConfig(); 317 n->updateConfig();
207 } 318 }
208} 319}
209QDate DateNavigatorContainer::lastAvailableDate() const 320QDate DateNavigatorContainer::lastAvailableDate() const
210{ 321{
211 QDate date = mNavigatorView->baseDate(); 322 QDate date = mNavigatorView->baseDate();
212 QDate last = QDate ( date.year(), date.month(), date.daysInMonth() ); 323 QDate last = QDate ( date.year(), date.month(), date.daysInMonth() );
213 int iii = mLastDisplayedDN; 324 int iii = mLastDisplayedDN;
214 if ( mLastDisplayedDN ) 325 if ( mLastDisplayedDN )
215 last = last.addDays( 1); 326 last = last.addDays( 1);
216 while ( iii ) { 327 while ( iii ) {
217 last = last.addDays( last.daysInMonth ()); 328 last = last.addDays( last.daysInMonth ());
218 //qDebug("DATE %s ", last.toString().latin1() ); 329 //qDebug("DATE %s ", last.toString().latin1() );
219 --iii; 330 --iii;
220 } 331 }
221 if ( mLastDisplayedDN ) 332 if ( mLastDisplayedDN )
222 last = last.addDays( -1); 333 last = last.addDays( -1);
223 return last; 334 return last;
224} 335}
225QDate DateNavigatorContainer::firstAvailableDate() const 336QDate DateNavigatorContainer::firstAvailableDate() const
226{ 337{
227 return QDate ( mNavigatorView->baseDate().year(), mNavigatorView->baseDate().month(), 1 ); 338 return QDate ( mNavigatorView->baseDate().year(), mNavigatorView->baseDate().month(), 1 );
228} 339}
229void DateNavigatorContainer::selectDates( const DateList &dateList ) 340void DateNavigatorContainer::selectDates( const DateList &dateList )
230{ 341{
231 mFirstSelectedDate = dateList.first() ; 342 mFirstSelectedDate = dateList.first() ;
232 mSelectedDateCount = dateList.count() ; 343 mSelectedDateCount = dateList.count() ;
233 if ( !mLastDisplayedDN ) { 344 if ( !mLastDisplayedDN ) {
234 mNavigatorView->selectDates( dateList ); 345 mNavigatorView->selectDates( dateList );
235 return; 346 return;
236 } 347 }
237 QDate fDate = dateList.first(); 348 QDate fDate = dateList.first();
238 QDate lDate = dateList.last(); 349 QDate lDate = dateList.last();
239 //qDebug("%s %s ", lastAvailableDate().toString().latin1(), firstAvailableDate().toString().latin1() ); 350 //qDebug("%s %s ", lastAvailableDate().toString().latin1(), firstAvailableDate().toString().latin1() );
240 //qDebug("End %s %s ",lDate.toString().latin1(),curEnd.toString().latin1() ); 351 //qDebug("End %s %s ",lDate.toString().latin1(),curEnd.toString().latin1() );
241 if ( lDate <= lastAvailableDate() && firstAvailableDate() <= fDate) { 352 if ( lDate <= lastAvailableDate() && firstAvailableDate() <= fDate) {
242 updateDayMatrixDates(); 353 updateDayMatrixDates();
243 return; 354 return;
244 } 355 }
245 mNavigatorView->selectDates( dateList ); 356 mNavigatorView->selectDates( dateList );
246 setBaseDates(); 357 setBaseDates();
247 if ( mLastDisplayedDN ) { 358 if ( mLastDisplayedDN ) {
248 KDateNavigator *view = mExtraViews.at( 0 ); 359 KDateNavigator *view = mExtraViews.at( 0 );
249 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); 360 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
250 view->dayMatrix()->repaint( false ); 361 view->dayMatrix()->repaint( false );
251 if ( mLastDisplayedDN > 1 ) { 362 if ( mLastDisplayedDN > 1 ) {
252 KDateNavigator *view = mExtraViews.at( 1 ); 363 KDateNavigator *view = mExtraViews.at( 1 );
253 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); 364 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
254 view->dayMatrix()->repaint( false ); 365 view->dayMatrix()->repaint( false );
255 } 366 }
256 } 367 }
257} 368}
258 369
259void DateNavigatorContainer::setBaseDates() 370void DateNavigatorContainer::setBaseDates()
260{ 371{
261 QDate baseDate = mNavigatorView->baseDate(); 372 QDate baseDate = mNavigatorView->baseDate();
262 bool doRepaint = true; 373 bool doRepaint = true;
263 for( uint i = 0; i < mLastDisplayedDN; ++i ) { 374 for( uint i = 0; i < mLastDisplayedDN; ++i ) {
264 KDateNavigator *n = mExtraViews.at( i ); 375 KDateNavigator *n = mExtraViews.at( i );
265 baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 ); 376 baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 );
266 n->setBaseDate( baseDate, doRepaint ); 377 n->setBaseDate( baseDate, doRepaint );
267 } 378 }
268} 379}
269 380
270void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) 381void 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
383QSize DateNavigatorContainer::minimumSizeHint() const 391QSize DateNavigatorContainer::minimumSizeHint() const
384{ 392{
385 return mNavigatorView->minimumSizeHint(); 393 return mNavigatorView->minimumSizeHint();
386} 394}
387 395
388QSize DateNavigatorContainer::sizeHint() const 396QSize DateNavigatorContainer::sizeHint() const
389{ 397{
390 return mNavigatorView->yourSizeHint(); 398 return mNavigatorView->yourSizeHint();
391} 399}