Diffstat (limited to 'korganizer/datenavigatorcontainer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | korganizer/datenavigatorcontainer.cpp | 83 |
1 files changed, 63 insertions, 20 deletions
diff --git a/korganizer/datenavigatorcontainer.cpp b/korganizer/datenavigatorcontainer.cpp index 18756f0..bb27bce 100644 --- a/korganizer/datenavigatorcontainer.cpp +++ b/korganizer/datenavigatorcontainer.cpp | |||
@@ -41,16 +41,18 @@ DateNavigatorContainer::DateNavigatorContainer( QWidget *parent, | |||
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 | mDisplayedEndDate = QDate::currentDate(); | ||
50 | mLastDisplayedDN = 0; | ||
49 | } | 51 | } |
50 | 52 | ||
51 | DateNavigatorContainer::~DateNavigatorContainer() | 53 | DateNavigatorContainer::~DateNavigatorContainer() |
52 | { | 54 | { |
53 | } | 55 | } |
54 | 56 | ||
55 | void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) | 57 | void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) |
56 | { | 58 | { |
@@ -75,28 +77,28 @@ void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) | |||
75 | 77 | ||
76 | connect( v, SIGNAL( monthSelected( int ) ), SIGNAL( monthSelected( int ) ) ); | 78 | connect( v, SIGNAL( monthSelected( int ) ), SIGNAL( monthSelected( int ) ) ); |
77 | } | 79 | } |
78 | 80 | ||
79 | void DateNavigatorContainer::setCalendar( Calendar *cal ) | 81 | void DateNavigatorContainer::setCalendar( Calendar *cal ) |
80 | { | 82 | { |
81 | mCalendar = cal; | 83 | mCalendar = cal; |
82 | mNavigatorView->setCalendar( cal ); | 84 | mNavigatorView->setCalendar( cal ); |
83 | KDateNavigator *n; | 85 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
84 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { | 86 | KDateNavigator *n = mExtraViews.at( i ); |
85 | n->setCalendar( cal ); | 87 | n->setCalendar( cal ); |
86 | } | 88 | } |
87 | } | 89 | } |
88 | 90 | ||
89 | void DateNavigatorContainer::updateDayMatrix() | 91 | void DateNavigatorContainer::updateDayMatrix() |
90 | { | 92 | { |
91 | mNavigatorView->updateDayMatrix(); | 93 | mNavigatorView->updateDayMatrix(); |
92 | KDateNavigator *n; | 94 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
93 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { | 95 | KDateNavigator *n = mExtraViews.at( i ); |
94 | n->updateDayMatrix(); | 96 | n->updateDayMatrix(); |
95 | } | 97 | } |
96 | } | 98 | } |
97 | 99 | ||
98 | void DateNavigatorContainer::updateToday() | 100 | void DateNavigatorContainer::updateToday() |
99 | { | 101 | { |
100 | qDebug("DateNavigatorContainer::updateToday() NOT IMPL "); | 102 | qDebug("DateNavigatorContainer::updateToday() NOT IMPL "); |
101 | #if 0 | 103 | #if 0 |
102 | mNavigatorView->updateToday(); | 104 | mNavigatorView->updateToday(); |
@@ -105,57 +107,93 @@ void DateNavigatorContainer::updateToday() | |||
105 | n->updateToday(); | 107 | n->updateToday(); |
106 | } | 108 | } |
107 | #endif | 109 | #endif |
108 | } | 110 | } |
109 | 111 | ||
110 | void DateNavigatorContainer::updateView() | 112 | void DateNavigatorContainer::updateView() |
111 | { | 113 | { |
112 | mNavigatorView->updateView(); | 114 | mNavigatorView->updateView(); |
113 | KDateNavigator *n; | 115 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
114 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { | 116 | KDateNavigator *n = mExtraViews.at( i ); |
115 | n->updateView(); | 117 | n->updateView(); |
116 | } | 118 | } |
117 | } | 119 | } |
118 | 120 | ||
119 | void DateNavigatorContainer::updateConfig() | 121 | void DateNavigatorContainer::updateConfig() |
120 | { | 122 | { |
121 | mNavigatorView->updateConfig(); | 123 | mNavigatorView->updateConfig(); |
122 | KDateNavigator *n; | 124 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
123 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { | 125 | KDateNavigator *n = mExtraViews.at( i ); |
124 | n->updateConfig(); | 126 | n->updateConfig(); |
125 | } | 127 | } |
126 | } | 128 | } |
127 | 129 | ||
128 | void DateNavigatorContainer::selectDates( const DateList &dateList ) | 130 | void DateNavigatorContainer::selectDates( const DateList &dateList ) |
129 | { | 131 | { |
130 | mNavigatorView->selectDates( dateList ); | 132 | if ( !mLastDisplayedDN ) { |
131 | setBaseDates(); | 133 | mNavigatorView->selectDates( dateList ); |
132 | if ( mExtraViews.count() ) { | 134 | return; |
135 | } | ||
136 | QDate fDate = dateList.first(); | ||
137 | QDate lDate = dateList.last(); | ||
138 | if ( mLastDisplayedDN <= 2 ) { | ||
139 | mNavigatorView->selectDates( dateList ); | ||
140 | KDateNavigator *view = mExtraViews.at( 0 ); | ||
141 | QDate bDate = fDate.addDays( fDate.daysInMonth () - fDate.day() +1 ); | ||
142 | view->setBaseDate( bDate, false ); | ||
143 | view->dayMatrix()->setSelectedDaysFrom(fDate , lDate); | ||
144 | if ( mLastDisplayedDN == 2 ) { | ||
145 | view = mExtraViews.at( 1 ); | ||
146 | bDate = bDate.addDays( bDate.daysInMonth () - bDate.day() +1 ); | ||
147 | view->setBaseDate( bDate, false ); | ||
148 | view->dayMatrix()->setSelectedDaysFrom(fDate , lDate); | ||
149 | } | ||
150 | return; | ||
151 | } | ||
152 | KDateNavigator *view = mExtraViews.at( 0 ); | ||
153 | QDate date = view->baseDate(); | ||
154 | |||
155 | QDate curEnd = date.addDays( (mLastDisplayedDN)*30 +7); | ||
156 | //qDebug("End %s %s ",lDate.toString().latin1(),curEnd.toString().latin1() ); | ||
157 | if ( lDate < curEnd && date.addDays( -30 ) < fDate) { | ||
158 | mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate ); | ||
159 | mNavigatorView->dayMatrix()->repaint( false ); | ||
160 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | ||
161 | KDateNavigator *n = mExtraViews.at( i ); | ||
162 | if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) { | ||
163 | n->dayMatrix()->repaint( false ); | ||
164 | } | ||
165 | } | ||
166 | return; | ||
167 | } | ||
168 | mNavigatorView->selectDates( dateList ); | ||
169 | setBaseDates(); | ||
170 | if ( mLastDisplayedDN ) { | ||
133 | KDateNavigator *view = mExtraViews.at( 0 ); | 171 | KDateNavigator *view = mExtraViews.at( 0 ); |
134 | view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); | 172 | view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); |
135 | view->dayMatrix()->repaint( false ); | 173 | view->dayMatrix()->repaint( false ); |
136 | if ( mExtraViews.count() > 1 ) { | 174 | if ( mLastDisplayedDN > 1 ) { |
137 | KDateNavigator *view = mExtraViews.at( 1 ); | 175 | KDateNavigator *view = mExtraViews.at( 1 ); |
138 | view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); | 176 | view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); |
139 | view->dayMatrix()->repaint( false ); | 177 | view->dayMatrix()->repaint( false ); |
140 | } | 178 | } |
141 | } | 179 | } |
142 | } | 180 | } |
143 | 181 | ||
144 | void DateNavigatorContainer::setBaseDates() | 182 | void DateNavigatorContainer::setBaseDates() |
145 | { | 183 | { |
146 | KCal::DateList dateList = mNavigatorView->selectedDates(); | 184 | KCal::DateList dateList = mNavigatorView->selectedDates(); |
147 | if ( dateList.isEmpty() ) { | 185 | if ( dateList.isEmpty() ) { |
148 | kdError() << "DateNavigatorContainer::selectDates() empty list." << endl; | 186 | kdError() << "DateNavigatorContainer::selectDates() empty list." << endl; |
149 | } | 187 | } |
150 | QDate baseDate = dateList.first(); | 188 | QDate baseDate = dateList.first(); |
151 | KDateNavigator *n; | ||
152 | bool doRepaint = false; // skip first repaint | 189 | bool doRepaint = false; // skip first repaint |
153 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { | 190 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
191 | KDateNavigator *n = mExtraViews.at( i ); | ||
154 | baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 ); | 192 | baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 ); |
155 | n->setBaseDate( baseDate, doRepaint ); | 193 | n->setBaseDate( baseDate, doRepaint ); |
156 | doRepaint = true; | 194 | doRepaint = true; |
157 | } | 195 | } |
158 | } | 196 | } |
159 | 197 | ||
160 | void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) | 198 | void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) |
161 | { | 199 | { |
@@ -206,55 +244,60 @@ void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) | |||
206 | if ( mNavigatorView->fontChanged() ) { | 244 | if ( mNavigatorView->fontChanged() ) { |
207 | fontchange = true; | 245 | fontchange = true; |
208 | fo = KOPrefs::instance()->mDateNavigatorFont; | 246 | fo = KOPrefs::instance()->mDateNavigatorFont; |
209 | mNavigatorView->changeFont( fo ); | 247 | mNavigatorView->changeFont( fo ); |
210 | mNavigatorView->unsetFontChanged(); | 248 | mNavigatorView->unsetFontChanged(); |
211 | } | 249 | } |
212 | } | 250 | } |
213 | 251 | ||
252 | mLastDisplayedDN = horizontalCount*verticalCount-1; | ||
253 | bool setBaseD = false; | ||
214 | while ( count > ( mExtraViews.count() + 1 ) ) { | 254 | while ( count > ( mExtraViews.count() + 1 ) ) { |
215 | KDateNavigator *n = new KDateNavigator( this ); | 255 | KDateNavigator *n = new KDateNavigator( this ); |
216 | n->setMonthSignalOffset ( mExtraViews.count()+1 ); | 256 | n->setMonthSignalOffset ( mExtraViews.count()+1 ); |
217 | mExtraViews.append( n ); | 257 | mExtraViews.append( n ); |
218 | n->setCalendar( mCalendar ); | 258 | n->setCalendar( mCalendar ); |
219 | setBaseDates(); | 259 | setBaseD = true; |
220 | connectNavigatorView( n ); | 260 | connectNavigatorView( n ); |
221 | n->show(); | 261 | n->show(); |
222 | } | 262 | } |
223 | int iii = 0; | 263 | int iii = 0; |
224 | while ( iii < ( mExtraViews.count() ) ) { | 264 | while ( iii < ( mExtraViews.count() ) ) { |
225 | if ( iii < count-1 ) | 265 | if ( iii < count-1 ) |
226 | mExtraViews.at( iii )->show(); | 266 | mExtraViews.at( iii )->show(); |
227 | else | 267 | else |
228 | mExtraViews.at( iii )->hide(); | 268 | mExtraViews.at( iii )->hide(); |
229 | ++iii; | 269 | ++iii; |
230 | } | 270 | } |
271 | if ( setBaseD ) | ||
272 | setBaseDates(); | ||
231 | if ( fontchange ) { | 273 | if ( fontchange ) { |
232 | //mNavigatorView->changeFont( fo ); | 274 | //mNavigatorView->changeFont( fo ); |
233 | uint i; | 275 | uint i; |
234 | for( i = 0; i < mExtraViews.count(); ++i ) { | 276 | for( i = 0; i < mExtraViews.count(); ++i ) { |
235 | KDateNavigator *view = mExtraViews.at( i ); | 277 | KDateNavigator *view = mExtraViews.at( i ); |
236 | view->changeFont( fo ); | 278 | view->changeFont( fo ); |
237 | } | 279 | } |
238 | } | 280 | } |
239 | mHorizontalCount = horizontalCount; | 281 | mHorizontalCount = horizontalCount; |
240 | mVerticalCount = verticalCount; | 282 | mVerticalCount = verticalCount; |
283 | |||
241 | } | 284 | } |
242 | //qDebug("COUNT %d ", mExtraViews.count()); | 285 | //qDebug("COUNT %d ", mExtraViews.count()); |
243 | int height = size().height() / verticalCount; | 286 | int height = size().height() / verticalCount; |
244 | int width = size().width() / horizontalCount; | 287 | int width = size().width() / horizontalCount; |
245 | 288 | ||
246 | NavigatorBar *bar = mNavigatorView->navigatorBar(); | 289 | NavigatorBar *bar = mNavigatorView->navigatorBar(); |
247 | if ( horizontalCount > 1 ) bar->showButtons( true, false ); | 290 | if ( horizontalCount > 1 ) bar->showButtons( true, false ); |
248 | else bar->showButtons( true, true ); | 291 | else bar->showButtons( true, true ); |
249 | 292 | ||
250 | mNavigatorView->setGeometry(0, | 293 | mNavigatorView->setGeometry(0, |
251 | 0, width, height ); | 294 | 0, width, height ); |
252 | for( uint i = 0; i < mExtraViews.count(); ++i ) { | 295 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
253 | int x = ( i + 1 ) % horizontalCount; | 296 | int x = ( i + 1 ) % horizontalCount; |
254 | int y = ( i + 1 ) / horizontalCount; | 297 | int y = ( i + 1 ) / horizontalCount; |
255 | 298 | ||
256 | KDateNavigator *view = mExtraViews.at( i ); | 299 | KDateNavigator *view = mExtraViews.at( i ); |
257 | bar = view->navigatorBar(); | 300 | bar = view->navigatorBar(); |
258 | if ( y > 0 ) bar->showButtons( false, false ); | 301 | if ( y > 0 ) bar->showButtons( false, false ); |
259 | else { | 302 | else { |
260 | if ( x + 1 == horizontalCount ) bar->showButtons( false, true ); | 303 | if ( x + 1 == horizontalCount ) bar->showButtons( false, true ); |