Diffstat (limited to 'core/pim/datebook/datebookweeklst.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/pim/datebook/datebookweeklst.cpp | 42 |
1 files changed, 15 insertions, 27 deletions
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 | |||
@@ -69,13 +69,13 @@ void DateBookWeekLstHeader::setDate(const QDate &d) { | |||
69 | QDate stop=start.addDays(6); | 69 | QDate stop=start.addDays(6); |
70 | labelDate->setText( QString::number(start.day()) + "." + | 70 | labelDate->setText( QString::number(start.day()) + "." + |
71 | start.monthName(start.month()) + "-" + | 71 | start.monthName(start.month()) + "-" + |
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 | ||
78 | void DateBookWeekLstHeader::pickDate() { | 78 | void DateBookWeekLstHeader::pickDate() { |
79 | static QPopupMenu *m1 = 0; | 79 | static QPopupMenu *m1 = 0; |
80 | static DateBookMonth *picker = 0; | 80 | static DateBookMonth *picker = 0; |
81 | if ( !m1 ) { | 81 | if ( !m1 ) { |
@@ -114,13 +114,13 @@ DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /*onM*/, | |||
114 | const char* name, | 114 | const char* name, |
115 | WFlags fl ) | 115 | WFlags fl ) |
116 | : DateBookWeekLstDayHdrBase(parent, name, fl) { | 116 | : DateBookWeekLstDayHdrBase(parent, name, fl) { |
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()) ); |
124 | add->setText("+"); | 124 | add->setText("+"); |
125 | 125 | ||
126 | if (d == QDate::currentDate()) { | 126 | if (d == QDate::currentDate()) { |
@@ -231,15 +231,19 @@ DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev, | |||
231 | for (int d=0; d<7; d++) dayOrder[d]=d+1; | 231 | for (int d=0; d<7; d++) dayOrder[d]=d+1; |
232 | } else { | 232 | } else { |
233 | for (int d=0; d<7; d++) dayOrder[d]=d; | 233 | for (int d=0; d<7; d++) dayOrder[d]=d; |
234 | dayOrder[0]=7; | 234 | dayOrder[0]=7; |
235 | } | 235 | } |
236 | 236 | ||
237 | // Calculate offset to first day of week. | ||
238 | int dayoffset=d.dayOfWeek(); | ||
239 | if(bStartOnMonday) dayoffset--; | ||
240 | |||
237 | for (int i=0; i<7; i++) { | 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 |
@@ -248,13 +252,12 @@ DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev, | |||
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 &))); |
251 | } | 255 | } |
252 | it++; | 256 | it++; |
253 | } | 257 | } |
254 | |||
255 | layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); | 258 | layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); |
256 | } | 259 | } |
257 | } | 260 | } |
258 | DateBookWeekLstView::~DateBookWeekLstView(){} | 261 | DateBookWeekLstView::~DateBookWeekLstView(){} |
259 | void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();} | 262 | void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();} |
260 | 263 | ||
@@ -295,13 +298,13 @@ DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB, | |||
295 | setFocusPolicy(StrongFocus); | 298 | setFocusPolicy(StrongFocus); |
296 | layout = new QVBoxLayout( this ); | 299 | layout = new QVBoxLayout( this ); |
297 | layout->setMargin(0); | 300 | layout->setMargin(0); |
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); |
305 | scroll->setResizePolicy(QScrollView::AutoOneFit); | 308 | scroll->setResizePolicy(QScrollView::AutoOneFit); |
306 | layout->addWidget(scroll); | 309 | layout->addWidget(scroll); |
307 | 310 | ||
@@ -315,38 +318,24 @@ DateBookWeekLst::~DateBookWeekLst(){ | |||
315 | Config config("DateBook"); | 318 | Config config("DateBook"); |
316 | config.setGroup("Main"); | 319 | config.setGroup("Main"); |
317 | config.writeEntry("weeklst_dbl", dbl); | 320 | config.writeEntry("weeklst_dbl", dbl); |
318 | } | 321 | } |
319 | 322 | ||
320 | void DateBookWeekLst::setDate(const QDate &d) { | 323 | void 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 | |||
327 | void DateBookWeekLst::setDbl(bool on) { | 328 | void DateBookWeekLst::setDbl(bool on) { |
328 | dbl=on; | 329 | dbl=on; |
329 | redraw(); | 330 | redraw(); |
330 | } | 331 | } |
331 | void DateBookWeekLst::redraw() {getEvents();} | 332 | void DateBookWeekLst::redraw() {getEvents();} |
332 | 333 | ||
333 | QDate DateBookWeekLst::date() const { | 334 | QDate 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 | ||
349 | void DateBookWeekLst::getEvents() { | 338 | void DateBookWeekLst::getEvents() { |
350 | QDate start = date(); | 339 | QDate start = date(); |
351 | QDate stop = start.addDays(6); | 340 | QDate stop = start.addDays(6); |
352 | QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop); | 341 | QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop); |
@@ -368,15 +357,14 @@ void DateBookWeekLst::getEvents() { | |||
368 | 357 | ||
369 | scroll->addChild(view); | 358 | scroll->addChild(view); |
370 | view->show(); | 359 | view->show(); |
371 | scroll->updateScrollBars(); | 360 | scroll->updateScrollBars(); |
372 | } | 361 | } |
373 | 362 | ||
374 | void DateBookWeekLst::dateChanged(int y, int w) { | 363 | void DateBookWeekLst::dateChanged(QDate &newdate) { |
375 | year=y; | 364 | bdate=newdate; |
376 | _week=w; | ||
377 | getEvents(); | 365 | getEvents(); |
378 | } | 366 | } |
379 | 367 | ||
380 | void DateBookWeekLst::keyPressEvent(QKeyEvent *e) | 368 | void DateBookWeekLst::keyPressEvent(QKeyEvent *e) |
381 | { | 369 | { |
382 | switch(e->key()) { | 370 | switch(e->key()) { |