summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebookweek.cpp47
-rw-r--r--core/pim/datebook/datebookweek.h6
-rw-r--r--core/pim/datebook/datebookweekheaderimpl.cpp26
-rw-r--r--core/pim/datebook/datebookweekheaderimpl.h4
-rw-r--r--core/pim/datebook/datebookweeklst.cpp76
-rw-r--r--core/pim/datebook/datebookweeklst.h11
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
@@ -370,7 +370,7 @@ DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB,
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)));
@@ -399,11 +399,16 @@ void DateBookWeek::keyPressEvent(QKeyEvent *e)
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 )
@@ -411,34 +416,22 @@ void DateBookWeek::setDate( int y, int m, int d )
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()
@@ -578,7 +571,13 @@ void DateBookWeek::slotClockChanged( bool ap )
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
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
@@ -124,7 +124,7 @@ protected slots:
124 124
125private slots: 125private slots:
126 void showDay( int day ); 126 void showDay( int day );
127 void dateChanged( int y, int w ); 127 void dateChanged( QDate &newdate );
128 void slotShowEvent( const EffectiveEvent & ); 128 void slotShowEvent( const EffectiveEvent & );
129 void slotHideEvent(); 129 void slotHideEvent();
130 void slotYearChanged( int ); 130 void slotYearChanged( int );
@@ -150,6 +150,7 @@ private:
150 int year; 150 int year;
151 int _week; 151 int _week;
152 int dow; 152 int dow;
153 QDate bdate;
153 DateBookWeekHeader *header; 154 DateBookWeekHeader *header;
154 DateBookWeekView *view; 155 DateBookWeekView *view;
155 DateBookDB *db; 156 DateBookDB *db;
@@ -161,6 +162,5 @@ private:
161}; 162};
162 163
163 164
164bool calcWeek( const QDate &d, int &week, int &year, 165bool calcWeek( const QDate &d, int &week, int &year, bool startOnMonday = false );
165 bool startOnMonday = false );
166#endif 166#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
@@ -105,7 +105,7 @@ void DateBookWeekHeader::setDate(const QDate &d) {
105 QString::number(stop.day()) + "." + 105 QString::number(stop.day()) + "." +
106 start.monthName(stop.month()) +" ("+ 106 start.monthName(stop.month()) +" ("+
107 tr("w")+":"+QString::number( week ) +")"); 107 tr("w")+":"+QString::number( week ) +")");
108 emit dateChanged(year,week); 108 emit dateChanged(date);
109} 109}
110 110
111void DateBookWeekHeader::setStartOfWeek( bool onMonday ) 111void DateBookWeekHeader::setStartOfWeek( bool onMonday )
@@ -113,27 +113,3 @@ void DateBookWeekHeader::setStartOfWeek( bool onMonday )
113 bStartOnMonday = onMonday; 113 bStartOnMonday = onMonday;
114 setDate( date ); 114 setDate( date );
115} 115}
116
117// dateFromWeek
118// compute the date from the week in the year
119QDate dateFromWeek( int week, int year, bool startOnMonday )
120{
121 QDate d;
122 d.setYMD( year, 1, 1 );
123 int dayOfWeek = d.dayOfWeek();
124 if ( startOnMonday ) {
125 if ( dayOfWeek <= 4 ) {
126 d = d.addDays( ( week - 1 ) * 7 - dayOfWeek + 1 );
127 } else {
128 d = d.addDays( (week) * 7 - dayOfWeek + 1 );
129 }
130 } else {
131 if ( dayOfWeek <= 4 || dayOfWeek == 7) {
132 d = d.addDays( ( week - 1 ) * 7 - dayOfWeek % 7 );
133 } else {
134 d = d.addDays( ( week ) * 7 - dayOfWeek % 7 );
135 }
136 }
137 return d;
138}
139
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
@@ -36,7 +36,7 @@ public:
36 void setStartOfWeek( bool onMonday ); 36 void setStartOfWeek( bool onMonday );
37 37
38signals: 38signals:
39 void dateChanged( int y, int w ); 39 void dateChanged( QDate &date );
40 40
41public slots: 41public slots:
42 void pickDate(); 42 void pickDate();
@@ -54,6 +54,4 @@ private:
54 bool bStartOnMonday; 54 bool bStartOnMonday;
55}; 55};
56 56
57QDate dateFromWeek( int week, int year, bool startOnMonday );
58
59#endif // DATEBOOKDAYHEADER_H 57#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
@@ -72,7 +72,7 @@ void DateBookWeekLstHeader::setDate(const QDate &d) {
72 QString::number(stop.day()) + "." + 72 QString::number(stop.day()) + "." +
73 start.monthName(stop.month()) +" ("+ 73 start.monthName(stop.month()) +" ("+
74 tr("w")+":"+QString::number( week ) +")"); 74 tr("w")+":"+QString::number( week ) +")");
75 emit dateChanged(year,week); 75 emit dateChanged(date);
76} 76}
77 77
78void DateBookWeekLstHeader::pickDate() { 78void DateBookWeekLstHeader::pickDate() {
@@ -109,7 +109,7 @@ void DateBookWeekLstHeader::prevMonth()
109 setDate(date.addDays(-28)); 109 setDate(date.addDays(-28));
110} 110}
111 111
112DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /*onM*/, 112DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /* onM */,
113 QWidget* parent, 113 QWidget* parent,
114 const char* name, 114 const char* name,
115 WFlags fl ) 115 WFlags fl )
@@ -117,7 +117,7 @@ DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /*onM*/,
117 117
118 date=d; 118 date=d;
119 119
120 static const char *wdays={"MTWTFSS"}; 120 static const char *wdays={"MTWTFSSM"};
121 char day=wdays[d.dayOfWeek()-1]; 121 char day=wdays[d.dayOfWeek()-1];
122 122
123 label->setText( QString(QObject::tr(QString(QChar(day)))) + " " +QString::number(d.day()) ); 123 label->setText( QString(QObject::tr(QString(QChar(day)))) + " " +QString::number(d.day()) );
@@ -234,25 +234,28 @@ DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev,
234 dayOrder[0]=7; 234 dayOrder[0]=7;
235 } 235 }
236 236
237 for (int i=0; i<7; i++) { 237 // Calculate offset to first day of week.
238 int dayoffset=d.dayOfWeek();
239 if(bStartOnMonday) dayoffset--;
240
241 for (int i=0; i<7; i++) {
238 // Header 242 // Header
239 DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i), bStartOnMonday,this); 243 DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i-dayoffset), bStartOnMonday,this);
240 connect(hdr, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); 244 connect(hdr, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int)));
241 connect(hdr, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), 245 connect(hdr, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)),
242 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); 246 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)));
243 layout->addWidget(hdr); 247 layout->addWidget(hdr);
244 248
245 // Events 249 // Events
246 while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) { 250 while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) {
247 if(!(((*it).end().hour()==0) && ((*it).end().minute()==0) && ((*it).startDate()!=(*it).date()))) {// Skip events ending at 00:00 starting at another day. 251 if(!(((*it).end().hour()==0) && ((*it).end().minute()==0) && ((*it).startDate()!=(*it).date()))) {// Skip events ending at 00:00 starting at another day.
248 DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,weeklistviewconfig,this); 252 DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,weeklistviewconfig,this);
249 layout->addWidget(l); 253 layout->addWidget(l);
250 connect (l, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); 254 connect (l, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &)));
255 }
256 it++;
251 } 257 }
252 it++; 258 layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding));
253 }
254
255 layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding));
256 } 259 }
257} 260}
258DateBookWeekLstView::~DateBookWeekLstView(){} 261DateBookWeekLstView::~DateBookWeekLstView(){}
@@ -298,7 +301,7 @@ DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB,
298 301
299 header=new DateBookWeekLstHeader(onM, this); 302 header=new DateBookWeekLstHeader(onM, this);
300 layout->addWidget( header ); 303 layout->addWidget( header );
301 connect(header, SIGNAL(dateChanged(int,int)), this, SLOT(dateChanged(int,int))); 304 connect(header, SIGNAL(dateChanged(QDate &)), this, SLOT(dateChanged(QDate &)));
302 connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool))); 305 connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool)));
303 306
304 scroll=new QScrollView(this); 307 scroll=new QScrollView(this);
@@ -318,32 +321,18 @@ DateBookWeekLst::~DateBookWeekLst(){
318} 321}
319 322
320void DateBookWeekLst::setDate(const QDate &d) { 323void DateBookWeekLst::setDate(const QDate &d) {
321 int w,y; 324 bdate=d;
322 calcWeek(d,w,y,bStartOnMonday); 325 header->setDate(d);
323 year=y;
324 _week=w;
325 header->setDate(date());
326} 326}
327
327void DateBookWeekLst::setDbl(bool on) { 328void DateBookWeekLst::setDbl(bool on) {
328 dbl=on; 329 dbl=on;
329 redraw(); 330 redraw();
330} 331}
331void DateBookWeekLst::redraw() {getEvents();} 332void DateBookWeekLst::redraw() {getEvents();}
332 333
333QDate DateBookWeekLst::date() const { 334QDate DateBookWeekLst::date() {
334 QDate d; 335 return bdate;
335 d.setYMD(year,1,1);
336
337 int dow= d.dayOfWeek();
338 if (!bStartOnMonday)
339 if (dow==7) {
340 dow=1;
341 } else {
342 dow++;
343 }
344
345 d=d.addDays( (_week-1)*7 - dow + 1 );
346 return d;
347} 336}
348 337
349void DateBookWeekLst::getEvents() { 338void DateBookWeekLst::getEvents() {
@@ -371,9 +360,8 @@ void DateBookWeekLst::getEvents() {
371 scroll->updateScrollBars(); 360 scroll->updateScrollBars();
372} 361}
373 362
374void DateBookWeekLst::dateChanged(int y, int w) { 363void DateBookWeekLst::dateChanged(QDate &newdate) {
375 year=y; 364 bdate=newdate;
376 _week=w;
377 getEvents(); 365 getEvents();
378} 366}
379 367
@@ -395,4 +383,4 @@ void DateBookWeekLst::keyPressEvent(QKeyEvent *e)
395 default: 383 default:
396 e->ignore(); 384 e->ignore();
397 } 385 }
398} \ No newline at end of file 386}
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
@@ -32,7 +32,7 @@ public slots:
32 void pickDate(); 32 void pickDate();
33 void setDate(int y, int m, int d); 33 void setDate(int y, int m, int d);
34signals: 34signals:
35 void dateChanged(int y, int w); 35 void dateChanged(QDate &newdate);
36 void setDbl(bool on); 36 void setDbl(bool on);
37private: 37private:
38 QDate date; 38 QDate date;
@@ -119,11 +119,11 @@ public:
119 void setDate( int y, int w ); 119 void setDate( int y, int w );
120 void setDate(const QDate &d ); 120 void setDate(const QDate &d );
121 int week() const { return _week; }; 121 int week() const { return _week; };
122 QDate date() const; 122 QDate date();
123 123
124public slots: 124public slots:
125 void redraw(); 125 void redraw();
126 void dateChanged(int y, int w); 126 void dateChanged(QDate &date);
127 127
128protected slots: 128protected slots:
129 void keyPressEvent(QKeyEvent *); 129 void keyPressEvent(QKeyEvent *);
@@ -141,12 +141,13 @@ private:
141 bool ampm; 141 bool ampm;
142 bool bStartOnMonday; 142 bool bStartOnMonday;
143 bool dbl; 143 bool dbl;
144 int year, _week; 144 QDate bdate;
145 int year, _week,dow;
145 DateBookWeekLstHeader *header; 146 DateBookWeekLstHeader *header;
146 QWidget *view; 147 QWidget *view;
147 QVBoxLayout *layout; 148 QVBoxLayout *layout;
148 QScrollView *scroll; 149 QScrollView *scroll;
149 150
150 void getEvents(); 151 void getEvents();
151}; 152};
152 153