Diffstat (limited to 'core/pim/datebook/datebookweeklst.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/datebook/datebookweeklst.cpp | 76 |
1 files changed, 32 insertions, 44 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 | |||
@@ -63,25 +63,25 @@ void DateBookWeekLstHeader::setDate(const QDate &d) { | |||
63 | dayofweek=d.dayOfWeek(); | 63 | dayofweek=d.dayOfWeek(); |
64 | if(bStartOnMonday) dayofweek--; | 64 | if(bStartOnMonday) dayofweek--; |
65 | date=date.addDays(-dayofweek); | 65 | date=date.addDays(-dayofweek); |
66 | 66 | ||
67 | calcWeek(date,week,year,bStartOnMonday); | 67 | calcWeek(date,week,year,bStartOnMonday); |
68 | QDate start=date; | 68 | QDate start=date; |
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 ) { |
82 | m1 = new QPopupMenu( this ); | 82 | m1 = new QPopupMenu( this ); |
83 | picker = new DateBookMonth( m1, 0, TRUE ); | 83 | picker = new DateBookMonth( m1, 0, TRUE ); |
84 | m1->insertItem( picker ); | 84 | m1->insertItem( picker ); |
85 | connect( picker, SIGNAL( dateClicked( int, int, int ) ),this, SLOT( setDate( int, int, int ) ) ); | 85 | connect( picker, SIGNAL( dateClicked( int, int, int ) ),this, SLOT( setDate( int, int, int ) ) ); |
86 | //connect( m1, SIGNAL( aboutToHide() ), | 86 | //connect( m1, SIGNAL( aboutToHide() ), |
87 | //this, SLOT( gotHide() ) ); | 87 | //this, SLOT( gotHide() ) ); |
@@ -100,33 +100,33 @@ void DateBookWeekLstHeader::nextWeek() { | |||
100 | void DateBookWeekLstHeader::prevWeek() { | 100 | void DateBookWeekLstHeader::prevWeek() { |
101 | setDate(date.addDays(-7)); | 101 | setDate(date.addDays(-7)); |
102 | } | 102 | } |
103 | void DateBookWeekLstHeader::nextMonth() | 103 | void DateBookWeekLstHeader::nextMonth() |
104 | { | 104 | { |
105 | setDate(date.addDays(28)); | 105 | setDate(date.addDays(28)); |
106 | } | 106 | } |
107 | void DateBookWeekLstHeader::prevMonth() | 107 | void DateBookWeekLstHeader::prevMonth() |
108 | { | 108 | { |
109 | setDate(date.addDays(-28)); | 109 | setDate(date.addDays(-28)); |
110 | } | 110 | } |
111 | 111 | ||
112 | DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /*onM*/, | 112 | DateBookWeekLstDayHdr::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 ) |
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()) { |
127 | QPalette pal=label->palette(); | 127 | QPalette pal=label->palette(); |
128 | pal.setColor(QColorGroup::Foreground, QColor(0,0,255)); | 128 | pal.setColor(QColorGroup::Foreground, QColor(0,0,255)); |
129 | label->setPalette(pal); | 129 | label->setPalette(pal); |
130 | 130 | ||
131 | /* | 131 | /* |
132 | QFont f=label->font(); | 132 | QFont f=label->font(); |
@@ -225,43 +225,46 @@ DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev, | |||
225 | qBubbleSort(ev); | 225 | qBubbleSort(ev); |
226 | QValueListIterator<EffectiveEvent> it; | 226 | QValueListIterator<EffectiveEvent> it; |
227 | it=ev.begin(); | 227 | it=ev.begin(); |
228 | 228 | ||
229 | int dayOrder[7]; | 229 | int dayOrder[7]; |
230 | if (bStartOnMonday) { | 230 | if (bStartOnMonday) { |
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 | 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 | } |
258 | DateBookWeekLstView::~DateBookWeekLstView(){} | 261 | DateBookWeekLstView::~DateBookWeekLstView(){} |
259 | void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();} | 262 | void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();} |
260 | 263 | ||
261 | DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, | 264 | DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, |
262 | QValueList<EffectiveEvent> &ev2, | 265 | QValueList<EffectiveEvent> &ev2, |
263 | QDate &d, bool onM, | 266 | QDate &d, bool onM, |
264 | QWidget* parent, | 267 | QWidget* parent, |
265 | const char* name, WFlags fl) | 268 | const char* name, WFlags fl) |
266 | : QWidget( parent, name, fl ) | 269 | : QWidget( parent, name, fl ) |
267 | { | 270 | { |
@@ -289,70 +292,56 @@ DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB, | |||
289 | : QWidget( parent, name ), | 292 | : QWidget( parent, name ), |
290 | db( newDB ), | 293 | db( newDB ), |
291 | startTime( 0 ), | 294 | startTime( 0 ), |
292 | ampm( ap ), | 295 | ampm( ap ), |
293 | bStartOnMonday(onM) | 296 | bStartOnMonday(onM) |
294 | { | 297 | { |
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 | ||
308 | view=NULL; | 311 | view=NULL; |
309 | Config config("DateBook"); | 312 | Config config("DateBook"); |
310 | config.setGroup("Main"); | 313 | config.setGroup("Main"); |
311 | dbl=config.readBoolEntry("weeklst_dbl", false); | 314 | dbl=config.readBoolEntry("weeklst_dbl", false); |
312 | header->dbl->setOn(dbl); | 315 | header->dbl->setOn(dbl); |
313 | } | 316 | } |
314 | DateBookWeekLst::~DateBookWeekLst(){ | 317 | 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); |
353 | 342 | ||
354 | if (view) delete view; | 343 | if (view) delete view; |
355 | if (dbl) { | 344 | if (dbl) { |
356 | QDate start2=start.addDays(7); | 345 | QDate start2=start.addDays(7); |
357 | stop=start2.addDays(6); | 346 | stop=start2.addDays(6); |
358 | QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop); | 347 | QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop); |
@@ -362,37 +351,36 @@ void DateBookWeekLst::getEvents() { | |||
362 | } | 351 | } |
363 | 352 | ||
364 | connect (view, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); | 353 | connect (view, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); |
365 | connect (view, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); | 354 | connect (view, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); |
366 | connect (view, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), | 355 | connect (view, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), |
367 | this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); | 356 | this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); |
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()) { |
383 | case Key_Up: | 371 | case Key_Up: |
384 | scroll->scrollBy(0, -20); | 372 | scroll->scrollBy(0, -20); |
385 | break; | 373 | break; |
386 | case Key_Down: | 374 | case Key_Down: |
387 | scroll->scrollBy(0, 20); | 375 | scroll->scrollBy(0, 20); |
388 | break; | 376 | break; |
389 | case Key_Left: | 377 | case Key_Left: |
390 | header->prevWeek(); | 378 | header->prevWeek(); |
391 | break; | 379 | break; |
392 | case Key_Right: | 380 | case Key_Right: |
393 | header->nextWeek(); | 381 | header->nextWeek(); |
394 | break; | 382 | break; |
395 | default: | 383 | default: |
396 | e->ignore(); | 384 | e->ignore(); |
397 | } | 385 | } |
398 | } \ No newline at end of file | 386 | } |