summaryrefslogtreecommitdiff
path: root/core/pim/datebook/datebookweek.cpp
authorumopapisdn <umopapisdn>2003-05-13 22:58:18 (UTC)
committer umopapisdn <umopapisdn>2003-05-13 22:58:18 (UTC)
commit1e0e2f57472538bd880967ebe061c8f39a7e270b (patch) (unidiff)
treefcc070d53148385f93c0dc6ab5443d5100be0d26 /core/pim/datebook/datebookweek.cpp
parent45c0386de12b107e54e4d020d54eb05517a9efac (diff)
downloadopie-1e0e2f57472538bd880967ebe061c8f39a7e270b.zip
opie-1e0e2f57472538bd880967ebe061c8f39a7e270b.tar.gz
opie-1e0e2f57472538bd880967ebe061c8f39a7e270b.tar.bz2
Bugfix: (Bug #0000902) Adding events in weekview shouldn't create them as events on the first day of the week but rather the last visited day.
Diffstat (limited to 'core/pim/datebook/datebookweek.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebookweek.cpp47
1 files changed, 23 insertions, 24 deletions
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp
index 3ae4610..12f57a0 100644
--- a/core/pim/datebook/datebookweek.cpp
+++ b/core/pim/datebook/datebookweek.cpp
@@ -349,117 +349,110 @@ DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB,
349 QWidget *parent, const char *name ) 349 QWidget *parent, const char *name )
350 : QWidget( parent, name ), 350 : QWidget( parent, name ),
351 db( newDB ), 351 db( newDB ),
352 startTime( 0 ), 352 startTime( 0 ),
353 ampm( ap ), 353 ampm( ap ),
354 bStartOnMonday( startOnMonday ) 354 bStartOnMonday( startOnMonday )
355{ 355{
356 setFocusPolicy(StrongFocus); 356 setFocusPolicy(StrongFocus);
357 QVBoxLayout *vb = new QVBoxLayout( this ); 357 QVBoxLayout *vb = new QVBoxLayout( this );
358 header = new DateBookWeekHeader( bStartOnMonday, this ); 358 header = new DateBookWeekHeader( bStartOnMonday, this );
359 view = new DateBookWeekView( ampm, startOnMonday, this ); 359 view = new DateBookWeekView( ampm, startOnMonday, this );
360 vb->addWidget( header ); 360 vb->addWidget( header );
361 vb->addWidget( view ); 361 vb->addWidget( view );
362 362
363 lblDesc = new QLabel( this, "event label" ); 363 lblDesc = new QLabel( this, "event label" );
364 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); 364 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box );
365 lblDesc->setBackgroundColor( yellow ); 365 lblDesc->setBackgroundColor( yellow );
366 lblDesc->hide(); 366 lblDesc->hide();
367 367
368 tHide = new QTimer( this ); 368 tHide = new QTimer( this );
369 369
370 connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) ); 370 connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) );
371 connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); 371 connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) );
372 connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); 372 connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) );
373 connect( header, SIGNAL( dateChanged( int, int ) ), this, SLOT( dateChanged( int, int ) ) ); 373 connect( header, SIGNAL( dateChanged( QDate &) ), this, SLOT( dateChanged( QDate &) ) );
374 connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); 374 connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) );
375 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); 375 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) );
376 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); 376 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool)));
377 setDate(QDate::currentDate()); 377 setDate(QDate::currentDate());
378} 378}
379 379
380void DateBookWeek::keyPressEvent(QKeyEvent *e) 380void DateBookWeek::keyPressEvent(QKeyEvent *e)
381{ 381{
382 switch(e->key()) { 382 switch(e->key()) {
383 case Key_Up: 383 case Key_Up:
384 view->scrollBy(0, -20); 384 view->scrollBy(0, -20);
385 break; 385 break;
386 case Key_Down: 386 case Key_Down:
387 view->scrollBy(0, 20); 387 view->scrollBy(0, 20);
388 break; 388 break;
389 case Key_Left: 389 case Key_Left:
390 setDate(date().addDays(-7)); 390 setDate(date().addDays(-7));
391 break; 391 break;
392 case Key_Right: 392 case Key_Right:
393 setDate(date().addDays(7)); 393 setDate(date().addDays(7));
394 break; 394 break;
395 default: 395 default:
396 e->ignore(); 396 e->ignore();
397 } 397 }
398} 398}
399 399
400void DateBookWeek::showDay( int day ) 400void DateBookWeek::showDay( int day )
401{ 401{
402 QDate d; 402 QDate d=bdate;
403 d = dateFromWeek( _week, year, bStartOnMonday ); 403
404 // Calculate offset to first day of week.
405 int dayoffset=d.dayOfWeek();
406 if(bStartOnMonday) dayoffset--;
407
404 day--; 408 day--;
405 d = d.addDays( day ); 409 d=d.addDays(day-dayoffset);
406 emit showDate( d.year(), d.month(), d.day() ); 410 emit showDate( d.year(), d.month(), d.day() );
411 qDebug("%4d-%02d-%02d / Day %d\n",d.year(),d.month(),d.day(),day);
407} 412}
408 413
409void DateBookWeek::setDate( int y, int m, int d ) 414void DateBookWeek::setDate( int y, int m, int d )
410{ 415{
411 setDate(QDate(y, m, d)); 416 setDate(QDate(y, m, d));
412} 417}
413 418
414void DateBookWeek::setDate(QDate date) 419void DateBookWeek::setDate(QDate newdate)
415{ 420{
416 dow = date.dayOfWeek(); 421 bdate=newdate;
417 int w, y; 422 dow = newdate.dayOfWeek();
418 calcWeek( date, w, y, bStartOnMonday ); 423 header->setDate( newdate );
419 header->setDate( date );
420} 424}
421 425
422void DateBookWeek::dateChanged( int y, int w ) 426void DateBookWeek::dateChanged( QDate &newdate )
423{ 427{
424 year = y; 428 bdate=newdate;
425 _week = w;
426 getEvents(); 429 getEvents();
427} 430}
428 431
429QDate DateBookWeek::date() const 432QDate DateBookWeek::date() const
430{ 433{
431 QDate d; 434 return bdate;
432 d = dateFromWeek( _week - 1, year, bStartOnMonday );
433 if ( bStartOnMonday )
434 d = d.addDays( 7 + dow - 1 );
435 else {
436 if ( dow == 7 )
437 d = d.addDays( dow );
438 else
439 d = d.addDays( 7 + dow );
440 }
441 return d;
442} 435}
443 436
444void DateBookWeek::getEvents() 437void DateBookWeek::getEvents()
445{ 438{
446 QDate startWeek = weekDate(); 439 QDate startWeek = weekDate();
447 440
448 QDate endWeek = startWeek.addDays( 6 ); 441 QDate endWeek = startWeek.addDays( 6 );
449 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); 442 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek);
450 view->showEvents( eventList ); 443 view->showEvents( eventList );
451 view->moveToHour( startTime ); 444 view->moveToHour( startTime );
452} 445}
453 446
454void DateBookWeek::generateAllDayTooltext( QString& text ) { 447void DateBookWeek::generateAllDayTooltext( QString& text ) {
455 text += "<b>" + tr("This is an all day event.") + "</b><br>"; 448 text += "<b>" + tr("This is an all day event.") + "</b><br>";
456} 449}
457 450
458void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) { 451void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) {
459 str += "<b>" + QObject::tr("Start") + "</b>: "; 452 str += "<b>" + QObject::tr("Start") + "</b>: ";
460 str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); 453 str += TimeString::timeString( ev.event().start().time(), ampm, FALSE );
461 if( ev.startDate()!=ev.endDate() ) { 454 if( ev.startDate()!=ev.endDate() ) {
462 str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; 455 str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>";
463 } 456 }
464 str += "<br>"; 457 str += "<br>";
465 str += "<b>" + QObject::tr("End") + "</b>: "; 458 str += "<b>" + QObject::tr("End") + "</b>: ";
@@ -557,49 +550,55 @@ void DateBookWeek::slotYearChanged( int y )
557 int throwAway; 550 int throwAway;
558 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 551 calcWeek( d, totWeek, throwAway, bStartOnMonday );
559 while ( totWeek == 1 ) { 552 while ( totWeek == 1 ) {
560 d = d.addDays( -1 ); 553 d = d.addDays( -1 );
561 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 554 calcWeek( d, totWeek, throwAway, bStartOnMonday );
562 } 555 }
563} 556}
564 557
565void DateBookWeek::slotWeekChanged( bool onMonday ) 558void DateBookWeek::slotWeekChanged( bool onMonday )
566{ 559{
567 bStartOnMonday = onMonday; 560 bStartOnMonday = onMonday;
568 view->setStartOfWeek( bStartOnMonday ); 561 view->setStartOfWeek( bStartOnMonday );
569 header->setStartOfWeek( bStartOnMonday ); 562 header->setStartOfWeek( bStartOnMonday );
570 redraw(); 563 redraw();
571} 564}
572 565
573void DateBookWeek::slotClockChanged( bool ap ) 566void DateBookWeek::slotClockChanged( bool ap )
574{ 567{
575 ampm = ap; 568 ampm = ap;
576} 569}
577 570
578// return the date at the beginning of the week... 571// return the date at the beginning of the week...
579QDate DateBookWeek::weekDate() const 572QDate DateBookWeek::weekDate() const
580{ 573{
581 return dateFromWeek( _week, year, bStartOnMonday ); 574 QDate d=bdate;
575
576 // Calculate offset to first day of week.
577 int dayoffset=d.dayOfWeek();
578 if(bStartOnMonday) dayoffset--;
579
580 return d.addDays(-dayoffset);
582} 581}
583 582
584// this used to only be needed by datebook.cpp, but now we need it inside 583// this used to only be needed by datebook.cpp, but now we need it inside
585// week view since 584// week view since
586// we need to be able to figure out our total number of weeks on the fly... 585// we need to be able to figure out our total number of weeks on the fly...
587// this is probably the best place to put it.. 586// this is probably the best place to put it..
588 587
589// For Weeks that start on Monday... (EASY!) 588// For Weeks that start on Monday... (EASY!)
590// At the moment we will use ISO 8601 method for computing 589// At the moment we will use ISO 8601 method for computing
591// the week. Granted, other countries use other methods, 590// the week. Granted, other countries use other methods,
592// bet we aren't doing any Locale stuff at the moment. So, 591// bet we aren't doing any Locale stuff at the moment. So,
593// this should pass. This Algorithim is public domain and 592// this should pass. This Algorithim is public domain and
594// available at: 593// available at:
595// http://personal.ecu.edu/mccartyr/ISOwdALG.txt 594// http://personal.ecu.edu/mccartyr/ISOwdALG.txt
596// the week number is return, and the year number is returned in year 595// the week number is return, and the year number is returned in year
597// for Instance 2001/12/31 is actually the first week in 2002. 596// for Instance 2001/12/31 is actually the first week in 2002.
598// There is a more mathematical definition, but I will implement it when 597// There is a more mathematical definition, but I will implement it when
599// we are pass our deadline. 598// we are pass our deadline.
600 599
601// For Weeks that start on Sunday... (ahh... home rolled) 600// For Weeks that start on Sunday... (ahh... home rolled)
602// okay, if Jan 1 is on Friday or Saturday, 601// okay, if Jan 1 is on Friday or Saturday,
603// it will go to the pervious 602// it will go to the pervious
604// week... 603// week...
605 604