summaryrefslogtreecommitdiffabout
path: root/korganizer/kdatenavigator.cpp
Unidiff
Diffstat (limited to 'korganizer/kdatenavigator.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kdatenavigator.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/korganizer/kdatenavigator.cpp b/korganizer/kdatenavigator.cpp
index 7d0c516..b420351 100644
--- a/korganizer/kdatenavigator.cpp
+++ b/korganizer/kdatenavigator.cpp
@@ -156,196 +156,199 @@ KDateNavigator::~KDateNavigator()
156 156
157 157
158void KDateNavigator::passedMidnight() 158void KDateNavigator::passedMidnight()
159{ 159{
160 QDate today = QDate::currentDate(); 160 QDate today = QDate::currentDate();
161 bool emitMonth = false; 161 bool emitMonth = false;
162 162
163 if (today.month() != lastDayChecked.month()) 163 if (today.month() != lastDayChecked.month())
164 { 164 {
165 if (updateRollover==FollowMonth && 165 if (updateRollover==FollowMonth &&
166 daymatrix->isEndOfMonth()) { 166 daymatrix->isEndOfMonth()) {
167 goNextMonth(); 167 goNextMonth();
168 emitMonth=true; 168 emitMonth=true;
169 } 169 }
170 } 170 }
171 daymatrix->recalculateToday(); 171 daymatrix->recalculateToday();
172 daymatrix->repaint(); 172 daymatrix->repaint();
173 emit dayPassed(today); 173 emit dayPassed(today);
174 if (emitMonth) { emit monthPassed(today); } 174 if (emitMonth) { emit monthPassed(today); }
175} 175}
176 176
177/* slot */ void KDateNavigator::possiblyPastMidnight() 177/* slot */ void KDateNavigator::possiblyPastMidnight()
178{ 178{
179 if (lastDayChecked!=QDate::currentDate()) 179 if (lastDayChecked!=QDate::currentDate())
180 { 180 {
181 passedMidnight(); 181 passedMidnight();
182 lastDayChecked=QDate::currentDate(); 182 lastDayChecked=QDate::currentDate();
183 } 183 }
184 // Set the timer to go off 1 second after midnight 184 // Set the timer to go off 1 second after midnight
185 // or after 8 minutes, whichever comes first. 185 // or after 8 minutes, whichever comes first.
186 if (updateTimer) 186 if (updateTimer)
187 { 187 {
188 QTime now = QTime::currentTime(); 188 QTime now = QTime::currentTime();
189 QTime midnight = QTime(23,59,59); 189 QTime midnight = QTime(23,59,59);
190 int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000); 190 int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000);
191 191
192 // qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait)) 192 // qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait))
193 //.arg(now.toString()).arg(midnight.toString())); 193 //.arg(now.toString()).arg(midnight.toString()));
194 194
195 updateTimer->stop(); 195 updateTimer->stop();
196 updateTimer->start(msecsWait,true); 196 updateTimer->start(msecsWait,true);
197 } 197 }
198} 198}
199 199
200void KDateNavigator::updateDates() 200void KDateNavigator::updateDates()
201{ 201{
202 // Find the first day of the week of the current month. 202 // Find the first day of the week of the current month.
203 //int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr ); 203 //int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr );
204 QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() ); 204 QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() );
205 int d2 = KOGlobals::self()->calendarSystem()->day( dayone ); 205 int d2 = KOGlobals::self()->calendarSystem()->day( dayone );
206 //int di = d1 - d2 + 1; 206 //int di = d1 - d2 + 1;
207 dayone = dayone.addDays( -d2 + 1 ); 207 dayone = dayone.addDays( -d2 + 1 );
208 208
209 int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone ); 209 int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone );
210 210
211 // If month begins on Monday and Monday is first day of week, 211 // If month begins on Monday and Monday is first day of week,
212 // month should begin on second line. Sunday doesn't have this problem. 212 // month should begin on second line. Sunday doesn't have this problem.
213 int nextLine = ( ( m_fstDayOfWkCalsys == 1) && 213 int nextLine = ( ( m_fstDayOfWkCalsys == 1) &&
214 ( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0; 214 ( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0;
215 215
216 // update the matrix dates 216 // update the matrix dates
217 int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine; 217 int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine;
218 218
219 219
220 daymatrix->updateView(dayone.addDays(index)); 220 daymatrix->updateView(dayone.addDays(index));
221//each updateDates is followed by an updateView -> repaint is issued there ! 221//each updateDates is followed by an updateView -> repaint is issued there !
222// daymatrix->repaint(); 222// daymatrix->repaint();
223} 223}
224 224
225void KDateNavigator::updateDayMatrix() 225void KDateNavigator::updateDayMatrix()
226{ 226{
227 daymatrix->updateView(); 227 daymatrix->updateView();
228 daymatrix->repaint(); 228 daymatrix->repaint();
229} 229}
230 230
231 231
232void KDateNavigator::updateView() 232void KDateNavigator::updateView()
233{ 233{
234 234
235 setUpdatesEnabled( false ); 235 setUpdatesEnabled( false );
236 236
237 int i; 237 int i;
238 238
239// kdDebug() << "updateView() -> daymatrix->updateView()" << endl; 239// kdDebug() << "updateView() -> daymatrix->updateView()" << endl;
240 daymatrix->updateView(); 240 daymatrix->updateView();
241 241
242 // set the week numbers. 242 // set the week numbers.
243 for(i = 0; i < 6; i++) { 243 for(i = 0; i < 6; i++) {
244 QString weeknum; 244 QString weeknum;
245 // remember, according to ISO 8601, the first week of the year is the 245 // remember, according to ISO 8601, the first week of the year is the
246 // first week that contains a thursday. Thus we must subtract off 4, 246 // first week that contains a thursday. Thus we must subtract off 4,
247 // not just 1. 247 // not just 1.
248 248
249 //ET int dayOfYear = buttons[(i + 1) * 7 - 4]->date().dayOfYear(); 249 //ET int dayOfYear = buttons[(i + 1) * 7 - 4]->date().dayOfYear();
250 int dayOfYear = KOGlobals::self()->calendarSystem()->dayOfYear((daymatrix->getDate((i+1)*7-4))); 250 int dayOfYear = KOGlobals::self()->calendarSystem()->dayOfYear((daymatrix->getDate((i+1)*7-4)));
251 251
252 int add = 0;
253 if ( ! KGlobal::locale()->weekStartsMonday() )
254 ++add;
252 if (dayOfYear % 7 != 0) 255 if (dayOfYear % 7 != 0)
253 weeknum.setNum(dayOfYear / 7 + 1); 256 weeknum.setNum(dayOfYear / 7 + 1+add);
254 else 257 else
255 weeknum.setNum(dayOfYear / 7); 258 weeknum.setNum(dayOfYear / 7 +add);
256 weeknos[i]->setText(weeknum); 259 weeknos[i]->setText(weeknum);
257 } 260 }
258 261
259 setUpdatesEnabled( true ); 262 setUpdatesEnabled( true );
260// kdDebug() << "updateView() -> repaint()" << endl; 263// kdDebug() << "updateView() -> repaint()" << endl;
261 repaint(); 264 repaint();
262 daymatrix->repaint(); 265 daymatrix->repaint();
263} 266}
264 267
265void KDateNavigator::updateConfig() 268void KDateNavigator::updateConfig()
266{ 269{
267 int day; 270 int day;
268 for(int i=0; i<7; i++) { 271 for(int i=0; i<7; i++) {
269 // take the first letter of the day name to be the abbreviation 272 // take the first letter of the day name to be the abbreviation
270 if (KGlobal::locale()->weekStartsMonday()) { 273 if (KGlobal::locale()->weekStartsMonday()) {
271 day = i+1; 274 day = i+1;
272 } else { 275 } else {
273 if (i==0) day = 7; 276 if (i==0) day = 7;
274 else day = i; 277 else day = i;
275 } 278 }
276 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( day, 279 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( day,
277 true ); 280 true );
278 if ( KOPrefs::instance()->mCompactDialogs ) dayName = dayName.left( 1 ); 281 if ( KOPrefs::instance()->mCompactDialogs ) dayName = dayName.left( 1 );
279 headings[i]->setText( dayName ); 282 headings[i]->setText( dayName );
280 } 283 }
281 updateDates(); 284 updateDates();
282 updateView(); 285 updateView();
283} 286}
284 287
285void KDateNavigator::setShowWeekNums(bool enabled) 288void KDateNavigator::setShowWeekNums(bool enabled)
286{ 289{
287 m_bShowWeekNums = enabled; 290 m_bShowWeekNums = enabled;
288 for(int i=0; i<6; i++) { 291 for(int i=0; i<6; i++) {
289 if(enabled) 292 if(enabled)
290 weeknos[i]->show(); 293 weeknos[i]->show();
291 else 294 else
292 weeknos[i]->hide(); 295 weeknos[i]->hide();
293 } 296 }
294 resize(size()); 297 resize(size());
295} 298}
296 299
297void KDateNavigator::selectDates(const DateList& dateList) 300void KDateNavigator::selectDates(const DateList& dateList)
298{ 301{
299 302
300 if (dateList.count() > 0) { 303 if (dateList.count() > 0) {
301 mNavigatorBar->selectDates( dateList ); 304 mNavigatorBar->selectDates( dateList );
302 mSelectedDates = dateList; 305 mSelectedDates = dateList;
303 306
304 // set our record of the month and year that this datetbl is 307 // set our record of the month and year that this datetbl is
305 // displaying. 308 // displaying.
306 m_MthYr = mSelectedDates.first(); 309 m_MthYr = mSelectedDates.first();
307 310
308 311
309 // set our record of the first day of the week of the current 312 // set our record of the first day of the week of the current
310 // month. This needs to be done before calling dayToIndex, since it 313 // month. This needs to be done before calling dayToIndex, since it
311 // relies on this information being up to date. 314 // relies on this information being up to date.
312 QDate dayone(m_MthYr.year(), m_MthYr.month(), 1); 315 QDate dayone(m_MthYr.year(), m_MthYr.month(), 1);
313 m_fstDayOfWk = dayone.dayOfWeek(); 316 m_fstDayOfWk = dayone.dayOfWeek();
314 317
315 updateDates(); 318 updateDates();
316 319
317 daymatrix->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); 320 daymatrix->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
318 321
319 updateView(); 322 updateView();
320 } 323 }
321} 324}
322 325
323int KDateNavigator::dayNum(int row, int col) 326int KDateNavigator::dayNum(int row, int col)
324{ 327{
325 return 7 * (row - 1) + (col + 1) - m_fstDayOfWk; 328 return 7 * (row - 1) + (col + 1) - m_fstDayOfWk;
326} 329}
327 330
328int KDateNavigator::dayToIndex(int dayNum) 331int KDateNavigator::dayToIndex(int dayNum)
329{ 332{
330 int row, col; 333 int row, col;
331 334
332 row = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) / 7; 335 row = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) / 7;
333 if (KGlobal::locale()->weekStartsMonday() && (m_fstDayOfWk == 1)) 336 if (KGlobal::locale()->weekStartsMonday() && (m_fstDayOfWk == 1))
334 row++; 337 row++;
335 col = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) % 7; 338 col = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) % 7;
336 return row * 7 + col; 339 return row * 7 + col;
337} 340}
338 341
339void KDateNavigator::wheelEvent (QWheelEvent *e) 342void KDateNavigator::wheelEvent (QWheelEvent *e)
340{ 343{
341 if(e->delta()>0) emit goPrevious(); 344 if(e->delta()>0) emit goPrevious();
342 else emit goNext(); 345 else emit goNext();
343 346
344 e->accept(); 347 e->accept();
345} 348}
346 349
347bool KDateNavigator::eventFilter (QObject *o,QEvent *e) 350bool KDateNavigator::eventFilter (QObject *o,QEvent *e)
348{ 351{
349 if (e->type() == QEvent::MouseButtonPress) { 352 if (e->type() == QEvent::MouseButtonPress) {
350 int i; 353 int i;
351 for(i=0;i<6;++i) { 354 for(i=0;i<6;++i) {