summaryrefslogtreecommitdiff
path: root/core/pim/datebook/datebookweekheaderimpl.cpp
Unidiff
Diffstat (limited to 'core/pim/datebook/datebookweekheaderimpl.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/pim/datebook/datebookweekheaderimpl.cpp93
1 files changed, 26 insertions, 67 deletions
diff --git a/core/pim/datebook/datebookweekheaderimpl.cpp b/core/pim/datebook/datebookweekheaderimpl.cpp
index 5f555d5..fd792e2 100644
--- a/core/pim/datebook/datebookweekheaderimpl.cpp
+++ b/core/pim/datebook/datebookweekheaderimpl.cpp
@@ -32,20 +32,16 @@
32 * Constructs a DateBookWeekHeader which is a child of 'parent', with the 32 * Constructs a DateBookWeekHeader which is a child of 'parent', with the
33 * name 'name' and widget flags set to 'f' 33 * name 'name' and widget flags set to 'f'
34 */ 34 */
35DateBookWeekHeader::DateBookWeekHeader( bool startOnMonday, QWidget* parent, 35DateBookWeekHeader::DateBookWeekHeader( bool startOnMonday, QWidget* parent, const char* name, WFlags fl )
36 const char* name, WFlags fl )
37 : DateBookWeekHeaderBase( parent, name, fl ), 36 : DateBookWeekHeaderBase( parent, name, fl ),
38 bStartOnMonday( startOnMonday ) 37 bStartOnMonday( startOnMonday )
39{ 38{
40 setBackgroundMode( PaletteButton ); 39 setBackgroundMode( PaletteButton );
41 labelDate->setBackgroundMode( PaletteButton ); 40 labelDate->setBackgroundMode( PaletteButton );
42
43 backmonth->setPixmap( Resource::loadPixmap("fastback") ); 41 backmonth->setPixmap( Resource::loadPixmap("fastback") );
44 backweek->setPixmap( Resource::loadPixmap("back") ); 42 backweek->setPixmap( Resource::loadPixmap("back") );
45 forwardweek->setPixmap( Resource::loadPixmap("forward") ); 43 forwardweek->setPixmap( Resource::loadPixmap("forward") );
46 forwardmonth->setPixmap( Resource::loadPixmap("fastforward") ); 44 forwardmonth->setPixmap( Resource::loadPixmap("fastforward") );
47 spinYear->hide();
48 spinWeek->hide();
49} 45}
50 46
51/* 47/*
@@ -60,103 +56,66 @@ void DateBookWeekHeader::pickDate()
60{ 56{
61 static QPopupMenu *m1 = 0; 57 static QPopupMenu *m1 = 0;
62 static DateBookMonth *picker = 0; 58 static DateBookMonth *picker = 0;
63 QDate currDate = dateFromWeek( week, year, bStartOnMonday );
64 if ( !m1 ) { 59 if ( !m1 ) {
65 m1 = new QPopupMenu( this ); 60 m1 = new QPopupMenu( this );
66 picker = new DateBookMonth( m1, 0, TRUE ); 61 picker = new DateBookMonth( m1, 0, TRUE );
67 m1->insertItem( picker ); 62 m1->insertItem( picker );
68 connect( picker, SIGNAL( dateClicked( int, int, int ) ), 63 connect( picker, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( setDate( int, int, int ) ) );
69 this, SLOT( setDate( int, int, int ) ) ); 64 // connect( m1, SIGNAL( aboutToHide() ), this, SLOT( gotHide() ) );
70 // connect( m1, SIGNAL( aboutToHide() ),
71 // this, SLOT( gotHide() ) );
72 } 65 }
73 picker->setDate( currDate.year(), currDate.month(), currDate.day() ); 66 picker->setDate( date.year(), date.month(), date.day() );
74 m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height()))); 67 m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height())));
75 picker->setFocus(); 68 picker->setFocus();
76} 69}
77/* 70
78 * public slot
79 */
80void DateBookWeekHeader::yearChanged( int y )
81{
82 setDate( y, week );
83}
84void DateBookWeekHeader::nextMonth() 71void DateBookWeekHeader::nextMonth()
85{ 72{
86 QDate mydate = dateFromWeek( week, year, bStartOnMonday ); // Get current week 73 setDate(date.addDays(28));
87 calcWeek( mydate.addDays(28), week, year, bStartOnMonday ); // Add 4 weeks.
88 setDate( year, week ); // update view
89} 74}
90void DateBookWeekHeader::prevMonth() 75void DateBookWeekHeader::prevMonth()
91{ 76{
92 QDate mydate = dateFromWeek( week, year, bStartOnMonday ); // Get current week 77 setDate(date.addDays(-28));
93 calcWeek( mydate.addDays(-28), week, year, bStartOnMonday ); // Subtract 4 weeks
94 setDate( year, week ); // update view
95} 78}
96/*
97 * public slot
98 */
99void DateBookWeekHeader::nextWeek() 79void DateBookWeekHeader::nextWeek()
100{ 80{
101 QDate mydate = dateFromWeek( week, year, bStartOnMonday ); // Get current week 81 setDate(date.addDays(7));
102 calcWeek( mydate.addDays(7), week, year, bStartOnMonday); // Add 1 week
103// if ( week < 52 )
104 //week++;
105 setDate( year, week );
106} 82}
107/*
108 * public slot
109 */
110void DateBookWeekHeader::prevWeek() 83void DateBookWeekHeader::prevWeek()
111{ 84{
112 QDate mydate = dateFromWeek( week, year, bStartOnMonday ); // Get current week 85 setDate(date.addDays(-7));
113 calcWeek( mydate.addDays(-7), week, year, bStartOnMonday); // Add 1 week
114// if ( week > 1 )
115 //week--;
116 setDate( year, week );
117}
118/*
119 * public slot
120 */
121void DateBookWeekHeader::weekChanged( int w )
122{
123 setDate( year, w );
124} 86}
125 87
126void DateBookWeekHeader::setDate( int y, int m, int d ) 88void DateBookWeekHeader::setDate( int y, int m, int d )
127{ 89{
128 calcWeek( QDate(y,m,d), week, year, bStartOnMonday ); 90 setDate(QDate(y,m,d));
129 setDate( year, week );
130} 91}
131 92
132void DateBookWeekHeader::setDate( int y, int w ) 93void DateBookWeekHeader::setDate(const QDate &d) {
133{ 94 int year,week,dayofweek;
134 year = y; 95 date=d;
135 week = w; 96 dayofweek=d.dayOfWeek();
136 spinYear->setValue( y ); 97 if(bStartOnMonday) dayofweek--;
137 spinWeek->setValue( w ); 98 date=date.addDays(-dayofweek);
138
139 QDate d = dateFromWeek( week, year, bStartOnMonday );
140 99
141 QString s = QString::number( d.day() ) + ". " + d.monthName( d.month() ) 100 calcWeek(date,week,year,bStartOnMonday);
142 + "-"; 101 QDate start=date;
143 d = d.addDays( 6 ); 102 QDate stop=start.addDays(6);
144 s += QString::number( d.day() ) + ". " + d.monthName( d.month() ); 103 labelDate->setText( QString::number(start.day()) + "." +
145 s += " ("+tr("week")+":"+QString::number( w )+")"; 104 start.monthName(start.month()) + "-" +
146 labelDate->setText( s ); 105 QString::number(stop.day()) + "." +
147 106 start.monthName(stop.month()) +" ("+
148 emit dateChanged( y, w ); 107 tr("w")+":"+QString::number( week ) +")");
108 emit dateChanged(year,week);
149} 109}
150 110
151void DateBookWeekHeader::setStartOfWeek( bool onMonday ) 111void DateBookWeekHeader::setStartOfWeek( bool onMonday )
152{ 112{
153 bStartOnMonday = onMonday; 113 bStartOnMonday = onMonday;
154 setDate( year, week ); 114 setDate( date );
155} 115}
156 116
157// dateFromWeek 117// dateFromWeek
158// compute the date from the week in the year 118// compute the date from the week in the year
159
160QDate dateFromWeek( int week, int year, bool startOnMonday ) 119QDate dateFromWeek( int week, int year, bool startOnMonday )
161{ 120{
162 QDate d; 121 QDate d;