Diffstat (limited to 'core/pim/datebook/datebookweek.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/pim/datebook/datebookweek.cpp | 63 |
1 files changed, 26 insertions, 37 deletions
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp index 2ad7aa9..ab7e963 100644 --- a/core/pim/datebook/datebookweek.cpp +++ b/core/pim/datebook/datebookweek.cpp | |||
@@ -11,39 +11,32 @@ | |||
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 | #include "datebookweek.h" | 20 | #include "datebookweek.h" |
21 | #include "datebookweekheaderimpl.h" | 21 | #include "datebookweekheaderimpl.h" |
22 | 22 | ||
23 | #include <qpe/calendar.h> | ||
24 | #include <qpe/datebookdb.h> | 23 | #include <qpe/datebookdb.h> |
25 | #include <qpe/event.h> | ||
26 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
27 | #include <qpe/timestring.h> | 25 | #include <qpe/calendar.h> |
28 | 26 | ||
29 | #include <qdatetime.h> | ||
30 | #include <qheader.h> | 27 | #include <qheader.h> |
31 | #include <qlabel.h> | 28 | #include <qlabel.h> |
32 | #include <qlayout.h> | 29 | #include <qlayout.h> |
33 | #include <qpainter.h> | ||
34 | #include <qpopupmenu.h> | ||
35 | #include <qtimer.h> | 30 | #include <qtimer.h> |
36 | #include <qspinbox.h> | ||
37 | #include <qstyle.h> | ||
38 | 31 | ||
39 | //----------------------------------------------------------------- | 32 | //----------------------------------------------------------------- |
40 | 33 | ||
41 | 34 | ||
42 | DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e ) | 35 | DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e ) |
43 | : ev( e ) | 36 | : ev( e ) |
44 | { | 37 | { |
45 | // with the current implementation change the color for all day events | 38 | // with the current implementation change the color for all day events |
46 | if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) { | 39 | if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) { |
47 | c = Qt::green; | 40 | c = Qt::green; |
48 | } else { | 41 | } else { |
49 | c = ev.event().hasAlarm() ? Qt::red : Qt::blue; | 42 | c = ev.event().hasAlarm() ? Qt::red : Qt::blue; |
@@ -80,62 +73,55 @@ DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday, | |||
80 | 73 | ||
81 | QObject::connect(qApp, SIGNAL(clockChanged(bool)), | 74 | QObject::connect(qApp, SIGNAL(clockChanged(bool)), |
82 | this, SLOT(slotChangeClock(bool))); | 75 | this, SLOT(slotChangeClock(bool))); |
83 | 76 | ||
84 | QFontMetrics fm( font() ); | 77 | QFontMetrics fm( font() ); |
85 | rowHeight = fm.height()+2; | 78 | rowHeight = fm.height()+2; |
86 | 79 | ||
87 | resizeContents( width(), 24*rowHeight ); | 80 | resizeContents( width(), 24*rowHeight ); |
88 | } | 81 | } |
89 | 82 | ||
90 | void DateBookWeekView::initNames() | 83 | void DateBookWeekView::initNames() |
91 | { | 84 | { |
85 | #warning Please review this ! (eilers) | ||
86 | |||
87 | // Ok, I am Mr. Pedantic, but shouldn't we count until 6 instead of 7, if bOnMonday is false ? (eilers) | ||
88 | |||
92 | static bool bFirst = true; | 89 | static bool bFirst = true; |
93 | if ( bFirst ) { | 90 | if ( bFirst ) { |
94 | if ( bOnMonday ) { | 91 | if ( bOnMonday ) { |
95 | header->addLabel( tr("Mo", "Monday" ) ); | 92 | for ( int i = 1; i<=7; i++ ) { |
96 | header->addLabel( tr("Tu", "Tuesday") ); | 93 | header->addLabel( Calendar::nameOfDay( i ) ); |
97 | header->addLabel( tr("We", "Wednesday" ) ); | 94 | } |
98 | header->addLabel( tr("Th", "Thursday" ) ); | 95 | |
99 | header->addLabel( tr("Fr", "Friday" ) ); | ||
100 | header->addLabel( tr("Sa", "Saturday" ) ); | ||
101 | header->addLabel( tr("Su", "Sunday" ) ); | ||
102 | } else { | 96 | } else { |
103 | header->addLabel( tr("Su", "Sunday" ) ); | 97 | header->addLabel( Calendar::nameOfDay( 7 ) ); |
104 | header->addLabel( tr("Mo", "Monday") ); | 98 | for ( int i = 1; i<7; i++ ) { |
105 | header->addLabel( tr("Tu", "Tuesday") ); | 99 | header->addLabel( Calendar::nameOfDay( i ) ); |
106 | header->addLabel( tr("We", "Wednesday" ) ); | 100 | } |
107 | header->addLabel( tr("Th", "Thursday" ) ); | ||
108 | header->addLabel( tr("Fr", "Friday" ) ); | ||
109 | header->addLabel( tr("Sa", "Saturday" ) ); | ||
110 | } | 101 | } |
111 | bFirst = false; | 102 | bFirst = false; |
112 | } else { | 103 | } else { |
113 | // we are change things... | 104 | // we are change things... |
114 | if ( bOnMonday ) { | 105 | if ( bOnMonday ) { |
115 | header->setLabel( 1, tr("Mo", "Monday") ); | 106 | for ( int i = 1; i<=7; i++ ) { |
116 | header->setLabel( 2, tr("Tu", "Tuesday") ); | 107 | header->setLabel( i, Calendar::nameOfDay( i ) ); |
117 | header->setLabel( 3, tr("We", "Wednesday" ) ); | 108 | } |
118 | header->setLabel( 4, tr("Th", "Thursday" ) ); | 109 | |
119 | header->setLabel( 5, tr("Fr", "Friday" ) ); | ||
120 | header->setLabel( 6, tr("Sa", "Saturday" ) ); | ||
121 | header->setLabel( 7, tr("Su", "Sunday" ) ); | ||
122 | } else { | 110 | } else { |
123 | header->setLabel( 1, tr("Su", "Sunday" ) ); | 111 | header->setLabel( 1, Calendar::nameOfDay( 7 ) ); |
124 | header->setLabel( 2, tr("Mo", "Monday") ); | 112 | for ( int i = 1; i<7; i++ ) { |
125 | header->setLabel( 3, tr("Tu", "Tuesday") ); | 113 | header->setLabel( i+1, Calendar::nameOfDay( i ) ); |
126 | header->setLabel( 4, tr("We", "Wednesday" ) ); | 114 | } |
127 | header->setLabel( 5, tr("Th", "Thursday" ) ); | 115 | |
128 | header->setLabel( 6, tr("Fr", "Friday" ) ); | ||
129 | header->setLabel( 7, tr("Sa", "Saturday" ) ); | ||
130 | } | 116 | } |
131 | } | 117 | } |
132 | } | 118 | } |
133 | 119 | ||
134 | 120 | ||
135 | 121 | ||
136 | void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) | 122 | void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) |
137 | { | 123 | { |
138 | items.clear(); | 124 | items.clear(); |
139 | QValueListIterator<EffectiveEvent> it; | 125 | QValueListIterator<EffectiveEvent> it; |
140 | for ( it = ev.begin(); it != ev.end(); ++it ) { | 126 | for ( it = ev.begin(); it != ev.end(); ++it ) { |
141 | DateBookWeekItem *i = new DateBookWeekItem( *it ); | 127 | DateBookWeekItem *i = new DateBookWeekItem( *it ); |
@@ -393,25 +379,26 @@ void DateBookWeek::keyPressEvent(QKeyEvent *e) | |||
393 | setDate(date().addDays(7)); | 379 | setDate(date().addDays(7)); |
394 | break; | 380 | break; |
395 | default: | 381 | default: |
396 | e->ignore(); | 382 | e->ignore(); |
397 | } | 383 | } |
398 | } | 384 | } |
399 | 385 | ||
400 | void DateBookWeek::showDay( int day ) | 386 | void DateBookWeek::showDay( int day ) |
401 | { | 387 | { |
402 | QDate d=bdate; | 388 | QDate d=bdate; |
403 | 389 | ||
404 | // Calculate offset to first day of week. | 390 | // Calculate offset to first day of week. |
405 | int dayoffset=d.dayOfWeek(); | 391 | int dayoffset=d.dayOfWeek() % 7; |
392 | |||
406 | if(bStartOnMonday) dayoffset--; | 393 | if(bStartOnMonday) dayoffset--; |
407 | 394 | ||
408 | day--; | 395 | day--; |
409 | d=d.addDays(day-dayoffset); | 396 | d=d.addDays(day-dayoffset); |
410 | emit showDate( d.year(), d.month(), d.day() ); | 397 | emit showDate( d.year(), d.month(), d.day() ); |
411 | } | 398 | } |
412 | 399 | ||
413 | void DateBookWeek::setDate( int y, int m, int d ) | 400 | void DateBookWeek::setDate( int y, int m, int d ) |
414 | { | 401 | { |
415 | setDate(QDate(y, m, d)); | 402 | setDate(QDate(y, m, d)); |
416 | } | 403 | } |
417 | 404 | ||
@@ -566,24 +553,26 @@ void DateBookWeek::slotClockChanged( bool ap ) | |||
566 | { | 553 | { |
567 | ampm = ap; | 554 | ampm = ap; |
568 | } | 555 | } |
569 | 556 | ||
570 | // return the date at the beginning of the week... | 557 | // return the date at the beginning of the week... |
571 | QDate DateBookWeek::weekDate() const | 558 | QDate DateBookWeek::weekDate() const |
572 | { | 559 | { |
573 | QDate d=bdate; | 560 | QDate d=bdate; |
574 | 561 | ||
575 | // Calculate offset to first day of week. | 562 | // Calculate offset to first day of week. |
576 | int dayoffset=d.dayOfWeek(); | 563 | int dayoffset=d.dayOfWeek(); |
577 | if(bStartOnMonday) dayoffset--; | 564 | if(bStartOnMonday) dayoffset--; |
565 | else if( dayoffset == 7 ) | ||
566 | dayoffset = 0; | ||
578 | 567 | ||
579 | return d.addDays(-dayoffset); | 568 | return d.addDays(-dayoffset); |
580 | } | 569 | } |
581 | 570 | ||
582 | // this used to only be needed by datebook.cpp, but now we need it inside | 571 | // this used to only be needed by datebook.cpp, but now we need it inside |
583 | // week view since | 572 | // week view since |
584 | // we need to be able to figure out our total number of weeks on the fly... | 573 | // we need to be able to figure out our total number of weeks on the fly... |
585 | // this is probably the best place to put it.. | 574 | // this is probably the best place to put it.. |
586 | 575 | ||
587 | // For Weeks that start on Monday... (EASY!) | 576 | // For Weeks that start on Monday... (EASY!) |
588 | // At the moment we will use ISO 8601 method for computing | 577 | // At the moment we will use ISO 8601 method for computing |
589 | // the week. Granted, other countries use other methods, | 578 | // the week. Granted, other countries use other methods, |