author | umopapisdn <umopapisdn> | 2003-05-13 22:58:18 (UTC) |
---|---|---|
committer | umopapisdn <umopapisdn> | 2003-05-13 22:58:18 (UTC) |
commit | 1e0e2f57472538bd880967ebe061c8f39a7e270b (patch) (side-by-side diff) | |
tree | fcc070d53148385f93c0dc6ab5443d5100be0d26 /core | |
parent | 45c0386de12b107e54e4d020d54eb05517a9efac (diff) | |
download | opie-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.
-rw-r--r-- | core/pim/datebook/datebookweek.cpp | 47 | ||||
-rw-r--r-- | core/pim/datebook/datebookweek.h | 6 | ||||
-rw-r--r-- | core/pim/datebook/datebookweekheaderimpl.cpp | 26 | ||||
-rw-r--r-- | core/pim/datebook/datebookweekheaderimpl.h | 4 | ||||
-rw-r--r-- | core/pim/datebook/datebookweeklst.cpp | 76 | ||||
-rw-r--r-- | core/pim/datebook/datebookweeklst.h | 11 |
6 files changed, 66 insertions, 104 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 @@ -371,5 +371,5 @@ DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, 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)) ); @@ -400,9 +400,14 @@ void DateBookWeek::keyPressEvent(QKeyEvent *e) 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); } @@ -412,16 +417,14 @@ void DateBookWeek::setDate( int y, int m, int 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(); } @@ -429,15 +432,5 @@ void DateBookWeek::dateChanged( int y, int w ) 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; } @@ -579,5 +572,11 @@ void DateBookWeek::slotClockChanged( bool ap ) 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); } diff --git a/core/pim/datebook/datebookweek.h b/core/pim/datebook/datebookweek.h index 8c5e06d..c273e30 100644 --- a/core/pim/datebook/datebookweek.h +++ b/core/pim/datebook/datebookweek.h @@ -125,5 +125,5 @@ protected slots: private slots: void showDay( int day ); - void dateChanged( int y, int w ); + void dateChanged( QDate &newdate ); void slotShowEvent( const EffectiveEvent & ); void slotHideEvent(); @@ -151,4 +151,5 @@ private: int _week; int dow; + QDate bdate; DateBookWeekHeader *header; DateBookWeekView *view; @@ -162,5 +163,4 @@ private: -bool calcWeek( const QDate &d, int &week, int &year, - bool startOnMonday = false ); +bool calcWeek( const QDate &d, int &week, int &year, bool startOnMonday = false ); #endif diff --git a/core/pim/datebook/datebookweekheaderimpl.cpp b/core/pim/datebook/datebookweekheaderimpl.cpp index fd792e2..ff7626f 100644 --- a/core/pim/datebook/datebookweekheaderimpl.cpp +++ b/core/pim/datebook/datebookweekheaderimpl.cpp @@ -106,5 +106,5 @@ void DateBookWeekHeader::setDate(const QDate &d) { start.monthName(stop.month()) +" ("+ tr("w")+":"+QString::number( week ) +")"); - emit dateChanged(year,week); + emit dateChanged(date); } @@ -114,26 +114,2 @@ void DateBookWeekHeader::setStartOfWeek( bool onMonday ) setDate( date ); } - -// dateFromWeek -// compute the date from the week in the year -QDate dateFromWeek( int week, int year, bool startOnMonday ) -{ - QDate d; - d.setYMD( year, 1, 1 ); - int dayOfWeek = d.dayOfWeek(); - if ( startOnMonday ) { - if ( dayOfWeek <= 4 ) { - d = d.addDays( ( week - 1 ) * 7 - dayOfWeek + 1 ); - } else { - d = d.addDays( (week) * 7 - dayOfWeek + 1 ); - } - } else { - if ( dayOfWeek <= 4 || dayOfWeek == 7) { - d = d.addDays( ( week - 1 ) * 7 - dayOfWeek % 7 ); - } else { - d = d.addDays( ( week ) * 7 - dayOfWeek % 7 ); - } - } - return d; -} - diff --git a/core/pim/datebook/datebookweekheaderimpl.h b/core/pim/datebook/datebookweekheaderimpl.h index 1ab1d52..d8dce90 100644 --- a/core/pim/datebook/datebookweekheaderimpl.h +++ b/core/pim/datebook/datebookweekheaderimpl.h @@ -37,5 +37,5 @@ public: signals: - void dateChanged( int y, int w ); + void dateChanged( QDate &date ); public slots: @@ -55,5 +55,3 @@ private: }; -QDate dateFromWeek( int week, int year, bool startOnMonday ); - #endif // DATEBOOKDAYHEADER_H diff --git a/core/pim/datebook/datebookweeklst.cpp b/core/pim/datebook/datebookweeklst.cpp index a39ff40..7817042 100644 --- a/core/pim/datebook/datebookweeklst.cpp +++ b/core/pim/datebook/datebookweeklst.cpp @@ -73,5 +73,5 @@ void DateBookWeekLstHeader::setDate(const QDate &d) { start.monthName(stop.month()) +" ("+ tr("w")+":"+QString::number( week ) +")"); - emit dateChanged(year,week); + emit dateChanged(date); } @@ -110,5 +110,5 @@ void DateBookWeekLstHeader::prevMonth() } -DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /*onM*/, +DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /* onM */, QWidget* parent, const char* name, @@ -118,5 +118,5 @@ DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /*onM*/, date=d; - static const char *wdays={"MTWTFSS"}; + static const char *wdays={"MTWTFSSM"}; char day=wdays[d.dayOfWeek()-1]; @@ -235,23 +235,26 @@ DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev, } - for (int i=0; i<7; i++) { + // Calculate offset to first day of week. + int dayoffset=d.dayOfWeek(); + if(bStartOnMonday) dayoffset--; + + for (int i=0; i<7; i++) { // Header - DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i), bStartOnMonday,this); - connect(hdr, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); - connect(hdr, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), - this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); - layout->addWidget(hdr); - - // Events - while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) { - if(!(((*it).end().hour()==0) && ((*it).end().minute()==0) && ((*it).startDate()!=(*it).date()))) { // Skip events ending at 00:00 starting at another day. - DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,weeklistviewconfig,this); - layout->addWidget(l); - connect (l, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); + DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i-dayoffset), bStartOnMonday,this); + connect(hdr, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); + connect(hdr, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), + this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); + layout->addWidget(hdr); + + // Events + while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) { + if(!(((*it).end().hour()==0) && ((*it).end().minute()==0) && ((*it).startDate()!=(*it).date()))) { // Skip events ending at 00:00 starting at another day. + DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,weeklistviewconfig,this); + layout->addWidget(l); + connect (l, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); + } + it++; } - it++; - } - - layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); + layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); } } @@ -299,5 +302,5 @@ DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB, header=new DateBookWeekLstHeader(onM, this); layout->addWidget( header ); - connect(header, SIGNAL(dateChanged(int,int)), this, SLOT(dateChanged(int,int))); + connect(header, SIGNAL(dateChanged(QDate &)), this, SLOT(dateChanged(QDate &))); connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool))); @@ -319,10 +322,8 @@ DateBookWeekLst::~DateBookWeekLst(){ void DateBookWeekLst::setDate(const QDate &d) { - int w,y; - calcWeek(d,w,y,bStartOnMonday); - year=y; - _week=w; - header->setDate(date()); + bdate=d; + header->setDate(d); } + void DateBookWeekLst::setDbl(bool on) { dbl=on; @@ -331,18 +332,6 @@ void DateBookWeekLst::setDbl(bool on) { void DateBookWeekLst::redraw() {getEvents();} -QDate DateBookWeekLst::date() const { - QDate d; - d.setYMD(year,1,1); - - int dow= d.dayOfWeek(); - if (!bStartOnMonday) - if (dow==7) { - dow=1; - } else { - dow++; - } - - d=d.addDays( (_week-1)*7 - dow + 1 ); - return d; +QDate DateBookWeekLst::date() { + return bdate; } @@ -372,7 +361,6 @@ void DateBookWeekLst::getEvents() { } -void DateBookWeekLst::dateChanged(int y, int w) { - year=y; - _week=w; +void DateBookWeekLst::dateChanged(QDate &newdate) { + bdate=newdate; getEvents(); } @@ -396,3 +384,3 @@ void DateBookWeekLst::keyPressEvent(QKeyEvent *e) e->ignore(); } -}
\ No newline at end of file +} diff --git a/core/pim/datebook/datebookweeklst.h b/core/pim/datebook/datebookweeklst.h index f858c4f..0bfbcda 100644 --- a/core/pim/datebook/datebookweeklst.h +++ b/core/pim/datebook/datebookweeklst.h @@ -33,5 +33,5 @@ public slots: void setDate(int y, int m, int d); signals: - void dateChanged(int y, int w); + void dateChanged(QDate &newdate); void setDbl(bool on); private: @@ -120,9 +120,9 @@ public: void setDate(const QDate &d ); int week() const { return _week; }; - QDate date() const; + QDate date(); public slots: void redraw(); - void dateChanged(int y, int w); + void dateChanged(QDate &date); protected slots: @@ -142,10 +142,11 @@ private: bool bStartOnMonday; bool dbl; - int year, _week; + QDate bdate; + int year, _week,dow; DateBookWeekLstHeader *header; QWidget *view; QVBoxLayout *layout; QScrollView *scroll; - + void getEvents(); }; |