Diffstat (limited to 'core/pim/datebook/datebookweek.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/datebook/datebookweek.cpp | 47 |
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, QWidget *parent, const char *name ) : QWidget( parent, name ), db( newDB ), startTime( 0 ), ampm( ap ), bStartOnMonday( startOnMonday ) { setFocusPolicy(StrongFocus); QVBoxLayout *vb = new QVBoxLayout( this ); header = new DateBookWeekHeader( bStartOnMonday, this ); view = new DateBookWeekView( ampm, startOnMonday, this ); vb->addWidget( header ); vb->addWidget( view ); lblDesc = new QLabel( this, "event label" ); lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); lblDesc->setBackgroundColor( yellow ); lblDesc->hide(); tHide = new QTimer( this ); connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) ); connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); - connect( header, SIGNAL( dateChanged( int, int ) ), this, SLOT( dateChanged( int, int ) ) ); + connect( header, SIGNAL( dateChanged( QDate &) ), this, SLOT( dateChanged( QDate &) ) ); connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); setDate(QDate::currentDate()); } void DateBookWeek::keyPressEvent(QKeyEvent *e) { switch(e->key()) { case Key_Up: view->scrollBy(0, -20); break; case Key_Down: view->scrollBy(0, 20); break; case Key_Left: setDate(date().addDays(-7)); break; case Key_Right: setDate(date().addDays(7)); break; default: e->ignore(); } } void DateBookWeek::showDay( int day ) { - QDate d; - d = dateFromWeek( _week, year, bStartOnMonday ); + QDate d=bdate; + + // Calculate offset to first day of week. + int dayoffset=d.dayOfWeek(); + if(bStartOnMonday) dayoffset--; + day--; - d = d.addDays( day ); + d=d.addDays(day-dayoffset); emit showDate( d.year(), d.month(), d.day() ); + qDebug("%4d-%02d-%02d / Day %d\n",d.year(),d.month(),d.day(),day); } void DateBookWeek::setDate( int y, int m, int d ) { setDate(QDate(y, m, d)); } -void DateBookWeek::setDate(QDate date) +void DateBookWeek::setDate(QDate newdate) { - dow = date.dayOfWeek(); - int w, y; - calcWeek( date, w, y, bStartOnMonday ); - header->setDate( date ); + bdate=newdate; + dow = newdate.dayOfWeek(); + header->setDate( newdate ); } -void DateBookWeek::dateChanged( int y, int w ) +void DateBookWeek::dateChanged( QDate &newdate ) { - year = y; - _week = w; + bdate=newdate; getEvents(); } QDate DateBookWeek::date() const { - QDate d; - d = dateFromWeek( _week - 1, year, bStartOnMonday ); - if ( bStartOnMonday ) - d = d.addDays( 7 + dow - 1 ); - else { - if ( dow == 7 ) - d = d.addDays( dow ); - else - d = d.addDays( 7 + dow ); - } - return d; + return bdate; } void DateBookWeek::getEvents() { QDate startWeek = weekDate(); QDate endWeek = startWeek.addDays( 6 ); QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); view->showEvents( eventList ); view->moveToHour( startTime ); } void DateBookWeek::generateAllDayTooltext( QString& text ) { text += "<b>" + tr("This is an all day event.") + "</b><br>"; } void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) { str += "<b>" + QObject::tr("Start") + "</b>: "; str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); if( ev.startDate()!=ev.endDate() ) { str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; } str += "<br>"; str += "<b>" + QObject::tr("End") + "</b>: "; @@ -557,49 +550,55 @@ void DateBookWeek::slotYearChanged( int y ) int throwAway; calcWeek( d, totWeek, throwAway, bStartOnMonday ); while ( totWeek == 1 ) { d = d.addDays( -1 ); calcWeek( d, totWeek, throwAway, bStartOnMonday ); } } void DateBookWeek::slotWeekChanged( bool onMonday ) { bStartOnMonday = onMonday; view->setStartOfWeek( bStartOnMonday ); header->setStartOfWeek( bStartOnMonday ); redraw(); } void DateBookWeek::slotClockChanged( bool ap ) { ampm = ap; } // return the date at the beginning of the week... QDate DateBookWeek::weekDate() const { - return dateFromWeek( _week, year, bStartOnMonday ); + QDate d=bdate; + + // Calculate offset to first day of week. + int dayoffset=d.dayOfWeek(); + if(bStartOnMonday) dayoffset--; + + return d.addDays(-dayoffset); } // this used to only be needed by datebook.cpp, but now we need it inside // week view since // we need to be able to figure out our total number of weeks on the fly... // this is probably the best place to put it.. // For Weeks that start on Monday... (EASY!) // At the moment we will use ISO 8601 method for computing // the week. Granted, other countries use other methods, // bet we aren't doing any Locale stuff at the moment. So, // this should pass. This Algorithim is public domain and // available at: // http://personal.ecu.edu/mccartyr/ISOwdALG.txt // the week number is return, and the year number is returned in year // for Instance 2001/12/31 is actually the first week in 2002. // There is a more mathematical definition, but I will implement it when // we are pass our deadline. // For Weeks that start on Sunday... (ahh... home rolled) // okay, if Jan 1 is on Friday or Saturday, // it will go to the pervious // week... |