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
@@ -325,165 +325,158 @@ void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch
325 325
326void DateBookWeekView::resizeEvent( QResizeEvent *e ) 326void DateBookWeekView::resizeEvent( QResizeEvent *e )
327{ 327{
328 const int hourWidth = 20; 328 const int hourWidth = 20;
329 QScrollView::resizeEvent( e ); 329 QScrollView::resizeEvent( e );
330 int avail = width()-qApp->style().scrollBarExtent().width()-1; 330 int avail = width()-qApp->style().scrollBarExtent().width()-1;
331 header->setGeometry( 0, 0, avail, header->sizeHint().height() ); 331 header->setGeometry( 0, 0, avail, header->sizeHint().height() );
332 setMargins( 0, header->height(), 0, 0 ); 332 setMargins( 0, header->height(), 0, 0 );
333 header->resizeSection( 0, hourWidth ); 333 header->resizeSection( 0, hourWidth );
334 int sw = (avail - hourWidth) / 7; 334 int sw = (avail - hourWidth) / 7;
335 for ( int i = 1; i < 7; i++ ) 335 for ( int i = 1; i < 7; i++ )
336 header->resizeSection( i, sw ); 336 header->resizeSection( i, sw );
337 header->resizeSection( 7, avail - hourWidth - sw*6 ); 337 header->resizeSection( 7, avail - hourWidth - sw*6 );
338} 338}
339 339
340void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) 340void DateBookWeekView::setStartOfWeek( bool bStartOnMonday )
341{ 341{
342 bOnMonday = bStartOnMonday; 342 bOnMonday = bStartOnMonday;
343 initNames(); 343 initNames();
344} 344}
345 345
346//------------------------------------------------------------------- 346//-------------------------------------------------------------------
347 347
348DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, 348DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB,
349 QWidget *parent, const char *name ) 349 QWidget *parent, const char *name )
350 : QWidget( parent, name ), 350 : QWidget( parent, name ),
351 db( newDB ), 351 db( newDB ),
352 startTime( 0 ), 352 startTime( 0 ),
353 ampm( ap ), 353 ampm( ap ),
354 bStartOnMonday( startOnMonday ) 354 bStartOnMonday( startOnMonday )
355{ 355{
356 setFocusPolicy(StrongFocus); 356 setFocusPolicy(StrongFocus);
357 QVBoxLayout *vb = new QVBoxLayout( this ); 357 QVBoxLayout *vb = new QVBoxLayout( this );
358 header = new DateBookWeekHeader( bStartOnMonday, this ); 358 header = new DateBookWeekHeader( bStartOnMonday, this );
359 view = new DateBookWeekView( ampm, startOnMonday, this ); 359 view = new DateBookWeekView( ampm, startOnMonday, this );
360 vb->addWidget( header ); 360 vb->addWidget( header );
361 vb->addWidget( view ); 361 vb->addWidget( view );
362 362
363 lblDesc = new QLabel( this, "event label" ); 363 lblDesc = new QLabel( this, "event label" );
364 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); 364 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box );
365 lblDesc->setBackgroundColor( yellow ); 365 lblDesc->setBackgroundColor( yellow );
366 lblDesc->hide(); 366 lblDesc->hide();
367 367
368 tHide = new QTimer( this ); 368 tHide = new QTimer( this );
369 369
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)));
377 setDate(QDate::currentDate()); 377 setDate(QDate::currentDate());
378} 378}
379 379
380void DateBookWeek::keyPressEvent(QKeyEvent *e) 380void DateBookWeek::keyPressEvent(QKeyEvent *e)
381{ 381{
382 switch(e->key()) { 382 switch(e->key()) {
383 case Key_Up: 383 case Key_Up:
384 view->scrollBy(0, -20); 384 view->scrollBy(0, -20);
385 break; 385 break;
386 case Key_Down: 386 case Key_Down:
387 view->scrollBy(0, 20); 387 view->scrollBy(0, 20);
388 break; 388 break;
389 case Key_Left: 389 case Key_Left:
390 setDate(date().addDays(-7)); 390 setDate(date().addDays(-7));
391 break; 391 break;
392 case Key_Right: 392 case Key_Right:
393 setDate(date().addDays(7)); 393 setDate(date().addDays(7));
394 break; 394 break;
395 default: 395 default:
396 e->ignore(); 396 e->ignore();
397 } 397 }
398} 398}
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 )
410{ 415{
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()
445{ 438{
446 QDate startWeek = weekDate(); 439 QDate startWeek = weekDate();
447 440
448 QDate endWeek = startWeek.addDays( 6 ); 441 QDate endWeek = startWeek.addDays( 6 );
449 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); 442 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek);
450 view->showEvents( eventList ); 443 view->showEvents( eventList );
451 view->moveToHour( startTime ); 444 view->moveToHour( startTime );
452} 445}
453 446
454void DateBookWeek::generateAllDayTooltext( QString& text ) { 447void DateBookWeek::generateAllDayTooltext( QString& text ) {
455 text += "<b>" + tr("This is an all day event.") + "</b><br>"; 448 text += "<b>" + tr("This is an all day event.") + "</b><br>";
456} 449}
457 450
458void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) { 451void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) {
459 str += "<b>" + QObject::tr("Start") + "</b>: "; 452 str += "<b>" + QObject::tr("Start") + "</b>: ";
460 str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); 453 str += TimeString::timeString( ev.event().start().time(), ampm, FALSE );
461 if( ev.startDate()!=ev.endDate() ) { 454 if( ev.startDate()!=ev.endDate() ) {
462 str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; 455 str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>";
463 } 456 }
464 str += "<br>"; 457 str += "<br>";
465 str += "<b>" + QObject::tr("End") + "</b>: "; 458 str += "<b>" + QObject::tr("End") + "</b>: ";
466 str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); 459 str += TimeString::timeString( ev.event().end().time(), ampm, FALSE );
467 if( ev.startDate()!=ev.endDate() ) { 460 if( ev.startDate()!=ev.endDate() ) {
468 str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; 461 str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>";
469 } 462 }
470} 463}
471 464
472void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) 465void DateBookWeek::slotShowEvent( const EffectiveEvent &ev )
473{ 466{
474 if ( tHide->isActive() ) 467 if ( tHide->isActive() )
475 tHide->stop(); 468 tHide->stop();
476 469
477 // why would someone use "<"? Oh well, fix it up... 470 // why would someone use "<"? Oh well, fix it up...
478 // I wonder what other things may be messed up... 471 // I wonder what other things may be messed up...
479 QString strDesc = ev.description(); 472 QString strDesc = ev.description();
480 int where = strDesc.find( "<" ); 473 int where = strDesc.find( "<" );
481 while ( where != -1 ) { 474 while ( where != -1 ) {
482 strDesc.remove( where, 1 ); 475 strDesc.remove( where, 1 );
483 strDesc.insert( where, "&#60;" ); 476 strDesc.insert( where, "&#60;" );
484 where = strDesc.find( "<", where ); 477 where = strDesc.find( "<", where );
485 } 478 }
486 479
487 QString strCat; 480 QString strCat;
488 // ### FIX later... 481 // ### FIX later...
489// QString strCat = ev.category(); 482// QString strCat = ev.category();
@@ -533,97 +526,103 @@ void DateBookWeek::slotHideEvent()
533{ 526{
534 tHide->start( 2000, true ); 527 tHide->start( 2000, true );
535} 528}
536 529
537void DateBookWeek::setStartViewTime( int startHere ) 530void DateBookWeek::setStartViewTime( int startHere )
538{ 531{
539 startTime = startHere; 532 startTime = startHere;
540 view->moveToHour( startTime ); 533 view->moveToHour( startTime );
541} 534}
542 535
543int DateBookWeek::startViewTime() const 536int DateBookWeek::startViewTime() const
544{ 537{
545 return startTime; 538 return startTime;
546} 539}
547 540
548void DateBookWeek::redraw() 541void DateBookWeek::redraw()
549{ 542{
550 getEvents(); 543 getEvents();
551} 544}
552 545
553void DateBookWeek::slotYearChanged( int y ) 546void DateBookWeek::slotYearChanged( int y )
554{ 547{
555 int totWeek; 548 int totWeek;
556 QDate d( y, 12, 31 ); 549 QDate d( y, 12, 31 );
557 int throwAway; 550 int throwAway;
558 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 551 calcWeek( d, totWeek, throwAway, bStartOnMonday );
559 while ( totWeek == 1 ) { 552 while ( totWeek == 1 ) {
560 d = d.addDays( -1 ); 553 d = d.addDays( -1 );
561 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 554 calcWeek( d, totWeek, throwAway, bStartOnMonday );
562 } 555 }
563} 556}
564 557
565void DateBookWeek::slotWeekChanged( bool onMonday ) 558void DateBookWeek::slotWeekChanged( bool onMonday )
566{ 559{
567 bStartOnMonday = onMonday; 560 bStartOnMonday = onMonday;
568 view->setStartOfWeek( bStartOnMonday ); 561 view->setStartOfWeek( bStartOnMonday );
569 header->setStartOfWeek( bStartOnMonday ); 562 header->setStartOfWeek( bStartOnMonday );
570 redraw(); 563 redraw();
571} 564}
572 565
573void DateBookWeek::slotClockChanged( bool ap ) 566void DateBookWeek::slotClockChanged( bool ap )
574{ 567{
575 ampm = ap; 568 ampm = ap;
576} 569}
577 570
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
585// week view since 584// week view since
586// we need to be able to figure out our total number of weeks on the fly... 585// we need to be able to figure out our total number of weeks on the fly...
587// this is probably the best place to put it.. 586// this is probably the best place to put it..
588 587
589// For Weeks that start on Monday... (EASY!) 588// For Weeks that start on Monday... (EASY!)
590// At the moment we will use ISO 8601 method for computing 589// At the moment we will use ISO 8601 method for computing
591// the week. Granted, other countries use other methods, 590// the week. Granted, other countries use other methods,
592// bet we aren't doing any Locale stuff at the moment. So, 591// bet we aren't doing any Locale stuff at the moment. So,
593// this should pass. This Algorithim is public domain and 592// this should pass. This Algorithim is public domain and
594// available at: 593// available at:
595// http://personal.ecu.edu/mccartyr/ISOwdALG.txt 594// http://personal.ecu.edu/mccartyr/ISOwdALG.txt
596// the week number is return, and the year number is returned in year 595// the week number is return, and the year number is returned in year
597// for Instance 2001/12/31 is actually the first week in 2002. 596// for Instance 2001/12/31 is actually the first week in 2002.
598// There is a more mathematical definition, but I will implement it when 597// There is a more mathematical definition, but I will implement it when
599// we are pass our deadline. 598// we are pass our deadline.
600 599
601// For Weeks that start on Sunday... (ahh... home rolled) 600// For Weeks that start on Sunday... (ahh... home rolled)
602// okay, if Jan 1 is on Friday or Saturday, 601// okay, if Jan 1 is on Friday or Saturday,
603// it will go to the pervious 602// it will go to the pervious
604// week... 603// week...
605 604
606bool calcWeek( const QDate &d, int &week, int &year, 605bool calcWeek( const QDate &d, int &week, int &year,
607 bool startOnMonday ) 606 bool startOnMonday )
608{ 607{
609 int weekNumber; 608 int weekNumber;
610 int yearNumber; 609 int yearNumber;
611 610
612 // remove a pesky warning, (Optimizations on g++) 611 // remove a pesky warning, (Optimizations on g++)
613 weekNumber = -1; 612 weekNumber = -1;
614 int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek(); 613 int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek();
615 int dayOfWeek = d.dayOfWeek(); 614 int dayOfWeek = d.dayOfWeek();
616 615
617 if ( !d.isValid() ) 616 if ( !d.isValid() )
618 return false; 617 return false;
619 618
620 if ( startOnMonday ) { 619 if ( startOnMonday ) {
621 // find the Jan1Weekday; 620 // find the Jan1Weekday;
622 if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) { 621 if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) {
623 yearNumber = d.year() - 1; 622 yearNumber = d.year() - 1;
624 if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) 623 if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) )
625 weekNumber = 53; 624 weekNumber = 53;
626 else 625 else
627 weekNumber = 52; 626 weekNumber = 52;
628 } else 627 } else
629 yearNumber = d.year(); 628 yearNumber = d.year();
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
@@ -79,88 +79,88 @@ private slots:
79 79
80private: 80private:
81 void positionItem( DateBookWeekItem *i ); 81 void positionItem( DateBookWeekItem *i );
82 DateBookWeekItem *intersects( const DateBookWeekItem * ); 82 DateBookWeekItem *intersects( const DateBookWeekItem * );
83 void drawContents( QPainter *p, int cx, int cy, int cw, int ch ); 83 void drawContents( QPainter *p, int cx, int cy, int cw, int ch );
84 void contentsMousePressEvent( QMouseEvent * ); 84 void contentsMousePressEvent( QMouseEvent * );
85 void contentsMouseReleaseEvent( QMouseEvent * ); 85 void contentsMouseReleaseEvent( QMouseEvent * );
86 void resizeEvent( QResizeEvent * ); 86 void resizeEvent( QResizeEvent * );
87 void initNames(); 87 void initNames();
88 88
89private: 89private:
90 bool ampm; 90 bool ampm;
91 bool bOnMonday; 91 bool bOnMonday;
92 QHeader *header; 92 QHeader *header;
93 QList<DateBookWeekItem> items; 93 QList<DateBookWeekItem> items;
94 int rowHeight; 94 int rowHeight;
95 bool showingEvent; 95 bool showingEvent;
96}; 96};
97 97
98class DateBookWeek : public QWidget 98class DateBookWeek : public QWidget
99{ 99{
100 Q_OBJECT 100 Q_OBJECT
101 101
102public: 102public:
103 DateBookWeek( bool ampm, bool weekOnMonday, DateBookDB *newDB, 103 DateBookWeek( bool ampm, bool weekOnMonday, DateBookDB *newDB,
104 QWidget *parent = 0, const char *name = 0 ); 104 QWidget *parent = 0, const char *name = 0 );
105 void setDate( int y, int m, int d ); 105 void setDate( int y, int m, int d );
106 void setDate( QDate d ); 106 void setDate( QDate d );
107 QDate date() const; 107 QDate date() const;
108 DateBookWeekView *weekView() const { return view; } 108 DateBookWeekView *weekView() const { return view; }
109 void setStartViewTime( int startHere ); 109 void setStartViewTime( int startHere );
110 int startViewTime() const; 110 int startViewTime() const;
111 int week() const { return _week; }; 111 int week() const { return _week; };
112 QDate weekDate() const; 112 QDate weekDate() const;
113 113
114public slots: 114public slots:
115 void redraw(); 115 void redraw();
116 void slotWeekChanged( bool bStartOnMonday ); 116 void slotWeekChanged( bool bStartOnMonday );
117 void slotClockChanged( bool a ); 117 void slotClockChanged( bool a );
118 118
119signals: 119signals:
120 void showDate( int y, int m, int d ); 120 void showDate( int y, int m, int d );
121 121
122protected slots: 122protected slots:
123 void keyPressEvent(QKeyEvent *); 123 void keyPressEvent(QKeyEvent *);
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 );
131 131
132private: 132private:
133 void getEvents(); 133 void getEvents();
134 134
135 /** 135 /**
136 * Wow that's a hell lot of code duplication 136 * Wow that's a hell lot of code duplication
137 * in datebook. I vote for a common base class 137 * in datebook. I vote for a common base class
138 * but never the less. This add a note 138 * but never the less. This add a note
139 * that the Event is an all day event 139 * that the Event is an all day event
140 * 140 *
141 */ 141 */
142 void generateAllDayTooltext( QString& text ); 142 void generateAllDayTooltext( QString& text );
143 143
144 /** 144 /**
145 * This will add the times to the text 145 * This will add the times to the text
146 * It will be shown in the Tooltip bubble 146 * It will be shown in the Tooltip bubble
147 */ 147 */
148 void generateNormalTooltext( QString& text, 148 void generateNormalTooltext( QString& text,
149 const EffectiveEvent &ev); 149 const EffectiveEvent &ev);
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;
156 QLabel *lblDesc; 157 QLabel *lblDesc;
157 QTimer *tHide; 158 QTimer *tHide;
158 int startTime; 159 int startTime;
159 bool ampm; 160 bool ampm;
160 bool bStartOnMonday; 161 bool bStartOnMonday;
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
@@ -60,80 +60,56 @@ void DateBookWeekHeader::pickDate()
60 m1 = new QPopupMenu( this ); 60 m1 = new QPopupMenu( this );
61 picker = new DateBookMonth( m1, 0, TRUE ); 61 picker = new DateBookMonth( m1, 0, TRUE );
62 m1->insertItem( picker ); 62 m1->insertItem( picker );
63 connect( picker, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( setDate( int, int, int ) ) ); 63 connect( picker, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( setDate( int, int, int ) ) );
64 // connect( m1, SIGNAL( aboutToHide() ), this, SLOT( gotHide() ) ); 64 // connect( m1, SIGNAL( aboutToHide() ), this, SLOT( gotHide() ) );
65 } 65 }
66 picker->setDate( date.year(), date.month(), date.day() ); 66 picker->setDate( date.year(), date.month(), date.day() );
67 m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height()))); 67 m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height())));
68 picker->setFocus(); 68 picker->setFocus();
69} 69}
70 70
71void DateBookWeekHeader::nextMonth() 71void DateBookWeekHeader::nextMonth()
72{ 72{
73 setDate(date.addDays(28)); 73 setDate(date.addDays(28));
74} 74}
75void DateBookWeekHeader::prevMonth() 75void DateBookWeekHeader::prevMonth()
76{ 76{
77 setDate(date.addDays(-28)); 77 setDate(date.addDays(-28));
78} 78}
79void DateBookWeekHeader::nextWeek() 79void DateBookWeekHeader::nextWeek()
80{ 80{
81 setDate(date.addDays(7)); 81 setDate(date.addDays(7));
82} 82}
83void DateBookWeekHeader::prevWeek() 83void DateBookWeekHeader::prevWeek()
84{ 84{
85 setDate(date.addDays(-7)); 85 setDate(date.addDays(-7));
86} 86}
87 87
88void DateBookWeekHeader::setDate( int y, int m, int d ) 88void DateBookWeekHeader::setDate( int y, int m, int d )
89{ 89{
90 setDate(QDate(y,m,d)); 90 setDate(QDate(y,m,d));
91} 91}
92 92
93void DateBookWeekHeader::setDate(const QDate &d) { 93void DateBookWeekHeader::setDate(const QDate &d) {
94 int year,week,dayofweek; 94 int year,week,dayofweek;
95 date=d; 95 date=d;
96 dayofweek=d.dayOfWeek(); 96 dayofweek=d.dayOfWeek();
97 if(bStartOnMonday) dayofweek--; 97 if(bStartOnMonday) dayofweek--;
98 date=date.addDays(-dayofweek); 98 date=date.addDays(-dayofweek);
99 99
100 calcWeek(date,week,year,bStartOnMonday); 100 calcWeek(date,week,year,bStartOnMonday);
101 QDate start=date; 101 QDate start=date;
102 QDate stop=start.addDays(6); 102 QDate stop=start.addDays(6);
103 labelDate->setText( QString::number(start.day()) + "." + 103 labelDate->setText( QString::number(start.day()) + "." +
104 start.monthName(start.month()) + "-" + 104 start.monthName(start.month()) + "-" +
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 )
112{ 112{
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
@@ -1,59 +1,57 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef DATEBOOKDAYHEADER_H 20#ifndef DATEBOOKDAYHEADER_H
21#define DATEBOOKDAYHEADER_H 21#define DATEBOOKDAYHEADER_H
22#include <qdatetime.h> 22#include <qdatetime.h>
23#include "datebookweekheader.h" 23#include "datebookweekheader.h"
24 24
25 25
26class DateBookWeekHeader : public DateBookWeekHeaderBase 26class DateBookWeekHeader : public DateBookWeekHeaderBase
27{ 27{
28 Q_OBJECT 28 Q_OBJECT
29 29
30public: 30public:
31 DateBookWeekHeader( bool startOnMonday, QWidget* parent = 0, 31 DateBookWeekHeader( bool startOnMonday, QWidget* parent = 0,
32 const char* name = 0, WFlags fl = 0 ); 32 const char* name = 0, WFlags fl = 0 );
33 ~DateBookWeekHeader(); 33 ~DateBookWeekHeader();
34 34
35 void setDate(const QDate &d); 35 void setDate(const QDate &d);
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();
43 void nextMonth(); 43 void nextMonth();
44 void prevMonth(); 44 void prevMonth();
45 void nextWeek(); 45 void nextWeek();
46 void prevWeek(); 46 void prevWeek();
47 void setDate( int y, int m, int d); 47 void setDate( int y, int m, int d);
48 48
49protected slots: 49protected slots:
50 void keyPressEvent(QKeyEvent *e) { e->ignore(); } 50 void keyPressEvent(QKeyEvent *e) { e->ignore(); }
51 51
52private: 52private:
53 QDate date; 53 QDate date;
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
@@ -27,142 +27,142 @@
27#include <qabstractlayout.h> 27#include <qabstractlayout.h>
28#include <qtl.h> 28#include <qtl.h>
29 29
30bool calcWeek(const QDate &d, int &week, int &year,bool startOnMonday = false); 30bool calcWeek(const QDate &d, int &week, int &year,bool startOnMonday = false);
31 31
32DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, const char* name, WFlags fl) 32DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, const char* name, WFlags fl)
33 : DateBookWeekLstHeaderBase(parent, name, fl) 33 : DateBookWeekLstHeaderBase(parent, name, fl)
34{ 34{
35 setBackgroundMode( PaletteButton ); 35 setBackgroundMode( PaletteButton );
36 labelDate->setBackgroundMode( PaletteButton ); 36 labelDate->setBackgroundMode( PaletteButton );
37 forwardweek->setBackgroundMode( PaletteButton ); 37 forwardweek->setBackgroundMode( PaletteButton );
38 forwardweek->setPixmap( Resource::loadPixmap("forward") ); 38 forwardweek->setPixmap( Resource::loadPixmap("forward") );
39 forwardmonth->setBackgroundMode( PaletteButton ); 39 forwardmonth->setBackgroundMode( PaletteButton );
40 forwardmonth->setPixmap( Resource::loadPixmap("fastforward") ); 40 forwardmonth->setPixmap( Resource::loadPixmap("fastforward") );
41 backweek->setBackgroundMode( PaletteButton ); 41 backweek->setBackgroundMode( PaletteButton );
42 backweek->setPixmap( Resource::loadPixmap("back") ); 42 backweek->setPixmap( Resource::loadPixmap("back") );
43 backmonth->setBackgroundMode( PaletteButton ); 43 backmonth->setBackgroundMode( PaletteButton );
44 backmonth->setPixmap( Resource::loadPixmap("fastback") ); 44 backmonth->setPixmap( Resource::loadPixmap("fastback") );
45 DateBookWeekLstHeaderBaseLayout->setSpacing(0); 45 DateBookWeekLstHeaderBaseLayout->setSpacing(0);
46 DateBookWeekLstHeaderBaseLayout->setMargin(0); 46 DateBookWeekLstHeaderBaseLayout->setMargin(0);
47 //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding)); 47 //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding));
48 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); 48 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
49 49
50 connect(backmonth, SIGNAL(clicked()), this, SLOT(prevMonth())); 50 connect(backmonth, SIGNAL(clicked()), this, SLOT(prevMonth()));
51 connect(backweek, SIGNAL(clicked()), this, SLOT(prevWeek())); 51 connect(backweek, SIGNAL(clicked()), this, SLOT(prevWeek()));
52 connect(forwardweek, SIGNAL(clicked()), this, SLOT(nextWeek())); 52 connect(forwardweek, SIGNAL(clicked()), this, SLOT(nextWeek()));
53 connect(forwardmonth, SIGNAL(clicked()), this, SLOT(nextMonth())); 53 connect(forwardmonth, SIGNAL(clicked()), this, SLOT(nextMonth()));
54 connect(labelDate, SIGNAL(clicked()), this, SLOT(pickDate())); 54 connect(labelDate, SIGNAL(clicked()), this, SLOT(pickDate()));
55 connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool))); 55 connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool)));
56 bStartOnMonday=onM; 56 bStartOnMonday=onM;
57} 57}
58DateBookWeekLstHeader::~DateBookWeekLstHeader(){} 58DateBookWeekLstHeader::~DateBookWeekLstHeader(){}
59 59
60void DateBookWeekLstHeader::setDate(const QDate &d) { 60void DateBookWeekLstHeader::setDate(const QDate &d) {
61 int year,week,dayofweek; 61 int year,week,dayofweek;
62 date=d; 62 date=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
78void DateBookWeekLstHeader::pickDate() { 78void 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() ) );
88 } 88 }
89 picker->setDate( date.year(), date.month(), date.day() ); 89 picker->setDate( date.year(), date.month(), date.day() );
90 m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height()))); 90 m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height())));
91 picker->setFocus(); 91 picker->setFocus();
92} 92}
93void DateBookWeekLstHeader::setDate(int y, int m, int d) { 93void DateBookWeekLstHeader::setDate(int y, int m, int d) {
94 setDate(QDate(y,m,d)); 94 setDate(QDate(y,m,d));
95} 95}
96 96
97void DateBookWeekLstHeader::nextWeek() { 97void DateBookWeekLstHeader::nextWeek() {
98 setDate(date.addDays(7)); 98 setDate(date.addDays(7));
99} 99}
100void DateBookWeekLstHeader::prevWeek() { 100void DateBookWeekLstHeader::prevWeek() {
101 setDate(date.addDays(-7)); 101 setDate(date.addDays(-7));
102} 102}
103void DateBookWeekLstHeader::nextMonth() 103void DateBookWeekLstHeader::nextMonth()
104{ 104{
105 setDate(date.addDays(28)); 105 setDate(date.addDays(28));
106} 106}
107void DateBookWeekLstHeader::prevMonth() 107void DateBookWeekLstHeader::prevMonth()
108{ 108{
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 )
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();
133 f.setItalic(true); 133 f.setItalic(true);
134 label->setFont(f); 134 label->setFont(f);
135 label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor())); 135 label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor()));
136 */ 136 */
137 } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday 137 } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday
138 QPalette pal=label->palette(); 138 QPalette pal=label->palette();
139 pal.setColor(QColorGroup::Foreground, QColor(255,0,0)); 139 pal.setColor(QColorGroup::Foreground, QColor(255,0,0));
140 label->setPalette(pal); 140 label->setPalette(pal);
141 } 141 }
142 142
143 connect (label, SIGNAL(clicked()), this, SLOT(showDay())); 143 connect (label, SIGNAL(clicked()), this, SLOT(showDay()));
144 connect (add, SIGNAL(clicked()), this, SLOT(newEvent())); 144 connect (add, SIGNAL(clicked()), this, SLOT(newEvent()));
145} 145}
146 146
147void DateBookWeekLstDayHdr::showDay() { 147void DateBookWeekLstDayHdr::showDay() {
148 emit showDate(date.year(), date.month(), date.day()); 148 emit showDate(date.year(), date.month(), date.day());
149} 149}
150 150
151void DateBookWeekLstDayHdr::newEvent() { 151void DateBookWeekLstDayHdr::newEvent() {
152 QDateTime start, stop; 152 QDateTime start, stop;
153 start=stop=date; 153 start=stop=date;
154 start.setTime(QTime(10,0)); 154 start.setTime(QTime(10,0));
155 stop.setTime(QTime(12,0)); 155 stop.setTime(QTime(12,0));
156 156
157 emit addEvent(start,stop,"",0); 157 emit addEvent(start,stop,"",0);
158} 158}
159DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev, 159DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev,
160 int weeklistviewconfig, 160 int weeklistviewconfig,
161 QWidget* parent, 161 QWidget* parent,
162 const char* name, 162 const char* name,
163 WFlags fl ) : OClickableLabel(parent,name,fl), event(ev) 163 WFlags fl ) : OClickableLabel(parent,name,fl), event(ev)
164{ 164{
165 // old values... lastday = "__|__", middle=" |---", Firstday="00:00", 165 // old values... lastday = "__|__", middle=" |---", Firstday="00:00",
166 QString s,start,middle,end,day; 166 QString s,start,middle,end,day;
167 167
168 qDebug("weeklistviewconfig=%d",weeklistviewconfig); 168 qDebug("weeklistviewconfig=%d",weeklistviewconfig);
@@ -189,210 +189,198 @@ DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev,
189 } else if(ev.startDate()==ev.date()) {// start event. 189 } else if(ev.startDate()==ev.date()) {// start event.
190 s=start; 190 s=start;
191 } else if(ev.endDate()==ev.date()) { // end event. 191 } else if(ev.endDate()==ev.date()) { // end event.
192 s=end; 192 s=end;
193 } else {// middle day. 193 } else {// middle day.
194 s=middle; 194 s=middle;
195 } 195 }
196 } else { 196 } else {
197 s=""; 197 s="";
198 } 198 }
199 setText(QString(s) + " " + ev.description()); 199 setText(QString(s) + " " + ev.description());
200 connect(this, SIGNAL(clicked()), this, SLOT(editMe())); 200 connect(this, SIGNAL(clicked()), this, SLOT(editMe()));
201 setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) ); 201 setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) );
202} 202}
203void DateBookWeekLstEvent::editMe() { 203void DateBookWeekLstEvent::editMe() {
204 emit editEvent(event.event()); 204 emit editEvent(event.event());
205} 205}
206 206
207 207
208DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev, 208DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev,
209 const QDate &d, bool onM, 209 const QDate &d, bool onM,
210 QWidget* parent, 210 QWidget* parent,
211 const char* name, WFlags fl) 211 const char* name, WFlags fl)
212 : QWidget( parent, name, fl ) 212 : QWidget( parent, name, fl )
213{ 213{
214 Config config("DateBook"); 214 Config config("DateBook");
215 config.setGroup("Main"); 215 config.setGroup("Main");
216 int weeklistviewconfig=config.readNumEntry("weeklistviewconfig", NORMAL); 216 int weeklistviewconfig=config.readNumEntry("weeklistviewconfig", NORMAL);
217 qDebug("Read weeklistviewconfig: %d",weeklistviewconfig); 217 qDebug("Read weeklistviewconfig: %d",weeklistviewconfig);
218 218
219 bStartOnMonday=onM; 219 bStartOnMonday=onM;
220 setPalette(white); 220 setPalette(white);
221 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); 221 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
222 222
223 QVBoxLayout *layout = new QVBoxLayout( this ); 223 QVBoxLayout *layout = new QVBoxLayout( this );
224 224
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}
258DateBookWeekLstView::~DateBookWeekLstView(){} 261DateBookWeekLstView::~DateBookWeekLstView(){}
259void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();} 262void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();}
260 263
261DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, 264DateBookWeekLstDblView::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{
268 QHBoxLayout *layout = new QHBoxLayout( this ); 271 QHBoxLayout *layout = new QHBoxLayout( this );
269 272
270 DateBookWeekLstView *w=new DateBookWeekLstView(ev1,d,onM,this); 273 DateBookWeekLstView *w=new DateBookWeekLstView(ev1,d,onM,this);
271 layout->addWidget(w); 274 layout->addWidget(w);
272 connect (w, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); 275 connect (w, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &)));
273 connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); 276 connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int)));
274 connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &,const QString &)), 277 connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &,const QString &)),
275 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); 278 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)));
276 279
277 280
278 w=new DateBookWeekLstView(ev2,d.addDays(7),onM,this); 281 w=new DateBookWeekLstView(ev2,d.addDays(7),onM,this);
279 layout->addWidget(w); 282 layout->addWidget(w);
280 connect (w, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); 283 connect (w, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &)));
281 connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); 284 connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int)));
282 connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), 285 connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)),
283 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); 286 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)));
284} 287}
285 288
286DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB, 289DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB,
287 QWidget *parent, 290 QWidget *parent,
288 const char *name ) 291 const char *name )
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}
314DateBookWeekLst::~DateBookWeekLst(){ 317DateBookWeekLst::~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
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() {
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);
359 view=new DateBookWeekLstDblView(el,el2,start,bStartOnMonday,scroll); 348 view=new DateBookWeekLstDblView(el,el2,start,bStartOnMonday,scroll);
360 } else { 349 } else {
361 view=new DateBookWeekLstView(el,start,bStartOnMonday,scroll); 350 view=new DateBookWeekLstView(el,start,bStartOnMonday,scroll);
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
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
380void DateBookWeekLst::keyPressEvent(QKeyEvent *e) 368void 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}
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
@@ -1,154 +1,155 @@
1#ifndef DATEBOOKWEEKLST 1#ifndef DATEBOOKWEEKLST
2#define DATEBOOKWEEKLST 2#define DATEBOOKWEEKLST
3 3
4#include <qwidget.h> 4#include <qwidget.h>
5#include <qdatetime.h> 5#include <qdatetime.h>
6#include <qpe/event.h> 6#include <qpe/event.h>
7#include <qlabel.h> 7#include <qlabel.h>
8#include <qscrollview.h> 8#include <qscrollview.h>
9 9
10#include "datebookweeklstheader.h" 10#include "datebookweeklstheader.h"
11#include "datebookweeklstdayhdr.h" 11#include "datebookweeklstdayhdr.h"
12 12
13#include <opie/oclickablelabel.h> 13#include <opie/oclickablelabel.h>
14 14
15class QDateTime; 15class QDateTime;
16class DateBookDB; 16class DateBookDB;
17 17
18class DateBookWeekLstHeader: public DateBookWeekLstHeaderBase 18class DateBookWeekLstHeader: public DateBookWeekLstHeaderBase
19{ 19{
20 Q_OBJECT 20 Q_OBJECT
21public: 21public:
22 DateBookWeekLstHeader(bool onM, QWidget* parent = 0, const char* name = 0, 22 DateBookWeekLstHeader(bool onM, QWidget* parent = 0, const char* name = 0,
23 WFlags fl = 0 ); 23 WFlags fl = 0 );
24 ~DateBookWeekLstHeader(); 24 ~DateBookWeekLstHeader();
25 void setDate(const QDate &d); 25 void setDate(const QDate &d);
26 26
27public slots: 27public slots:
28 void nextWeek(); 28 void nextWeek();
29 void prevWeek(); 29 void prevWeek();
30 void nextMonth(); 30 void nextMonth();
31 void prevMonth(); 31 void prevMonth();
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;
39 //bool onMonday; 39 //bool onMonday;
40 bool bStartOnMonday; 40 bool bStartOnMonday;
41}; 41};
42 42
43class DateBookWeekLstDayHdr: public DateBookWeekLstDayHdrBase 43class DateBookWeekLstDayHdr: public DateBookWeekLstDayHdrBase
44{ 44{
45 Q_OBJECT 45 Q_OBJECT
46public: 46public:
47 DateBookWeekLstDayHdr(const QDate &d, bool onM, 47 DateBookWeekLstDayHdr(const QDate &d, bool onM,
48 QWidget* parent = 0, const char* name = 0, 48 QWidget* parent = 0, const char* name = 0,
49 WFlags fl = 0 ); 49 WFlags fl = 0 );
50public slots: 50public slots:
51 void showDay(); 51 void showDay();
52 void newEvent(); 52 void newEvent();
53signals: 53signals:
54 void showDate(int y, int m, int d); 54 void showDate(int y, int m, int d);
55 void addEvent(const QDateTime &start, const QDateTime &stop, 55 void addEvent(const QDateTime &start, const QDateTime &stop,
56 const QString &str, const QString &location); 56 const QString &str, const QString &location);
57private: 57private:
58 QDate date; 58 QDate date;
59}; 59};
60 60
61class DateBookWeekLstEvent: public OClickableLabel 61class DateBookWeekLstEvent: public OClickableLabel
62{ 62{
63 Q_OBJECT 63 Q_OBJECT
64public: 64public:
65 DateBookWeekLstEvent(const EffectiveEvent &ev, int weeklistviewconfig =1, 65 DateBookWeekLstEvent(const EffectiveEvent &ev, int weeklistviewconfig =1,
66 QWidget* parent = 0, const char* name = 0, 66 QWidget* parent = 0, const char* name = 0,
67 WFlags fl = 0); 67 WFlags fl = 0);
68signals: 68signals:
69 void editEvent(const Event &e); 69 void editEvent(const Event &e);
70private slots: 70private slots:
71 void editMe(); 71 void editMe();
72private: 72private:
73 const EffectiveEvent event; 73 const EffectiveEvent event;
74}; 74};
75 75
76class DateBookWeekLstView: public QWidget 76class DateBookWeekLstView: public QWidget
77{ 77{
78 Q_OBJECT 78 Q_OBJECT
79public: 79public:
80 DateBookWeekLstView(QValueList<EffectiveEvent> &ev, const QDate &d, bool onM, 80 DateBookWeekLstView(QValueList<EffectiveEvent> &ev, const QDate &d, bool onM,
81 QWidget* parent = 0, const char* name = 0, 81 QWidget* parent = 0, const char* name = 0,
82 WFlags fl = 0 ); 82 WFlags fl = 0 );
83 ~DateBookWeekLstView(); 83 ~DateBookWeekLstView();
84signals: 84signals:
85 void editEvent(const Event &e); 85 void editEvent(const Event &e);
86 void showDate(int y, int m, int d); 86 void showDate(int y, int m, int d);
87 void addEvent(const QDateTime &start, const QDateTime &stop, 87 void addEvent(const QDateTime &start, const QDateTime &stop,
88 const QString &str, const QString &location); 88 const QString &str, const QString &location);
89private: 89private:
90 bool bStartOnMonday; 90 bool bStartOnMonday;
91protected slots: 91protected slots:
92 void keyPressEvent(QKeyEvent *); 92 void keyPressEvent(QKeyEvent *);
93}; 93};
94 94
95class DateBookWeekLstDblView: public QWidget { 95class DateBookWeekLstDblView: public QWidget {
96 Q_OBJECT 96 Q_OBJECT
97public: 97public:
98 DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, 98 DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1,
99 QValueList<EffectiveEvent> &ev2, 99 QValueList<EffectiveEvent> &ev2,
100 QDate &d, bool onM, 100 QDate &d, bool onM,
101 QWidget* parent = 0, const char* name = 0, 101 QWidget* parent = 0, const char* name = 0,
102 WFlags fl = 0 ); 102 WFlags fl = 0 );
103signals: 103signals:
104 void editEvent(const Event &e); 104 void editEvent(const Event &e);
105 void showDate(int y, int m, int d); 105 void showDate(int y, int m, int d);
106 void addEvent(const QDateTime &start, const QDateTime &stop, 106 void addEvent(const QDateTime &start, const QDateTime &stop,
107 const QString &str, const QString &location); 107 const QString &str, const QString &location);
108}; 108};
109 109
110class DateBookWeekLst : public QWidget 110class DateBookWeekLst : public QWidget
111{ 111{
112 Q_OBJECT 112 Q_OBJECT
113 113
114public: 114public:
115 DateBookWeekLst( bool ampm, bool onM, DateBookDB *newDB, 115 DateBookWeekLst( bool ampm, bool onM, DateBookDB *newDB,
116 QWidget *parent = 0, 116 QWidget *parent = 0,
117 const char *name = 0 ); 117 const char *name = 0 );
118 ~DateBookWeekLst(); 118 ~DateBookWeekLst();
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 *);
130 void setDbl(bool on); 130 void setDbl(bool on);
131 131
132signals: 132signals:
133 void showDate(int y, int m, int d); 133 void showDate(int y, int m, int d);
134 void addEvent(const QDateTime &start, const QDateTime &stop, 134 void addEvent(const QDateTime &start, const QDateTime &stop,
135 const QString &str, const QString &location); 135 const QString &str, const QString &location);
136 void editEvent(const Event &e); 136 void editEvent(const Event &e);
137 137
138private: 138private:
139 DateBookDB *db; 139 DateBookDB *db;
140 int startTime; 140 int startTime;
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
153#endif 154#endif
154 155