author | zecke <zecke> | 2003-08-30 08:07:32 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-08-30 08:07:32 (UTC) |
commit | d9b5fcc45b1fef5ac11ef549a47561c7382ff451 (patch) (unidiff) | |
tree | 8f9e82d455e22be0285a5a8fc47e893b52c05871 | |
parent | 18cae99f1deb15213074a8fb96f79eae4b0c5a43 (diff) | |
download | opie-d9b5fcc45b1fef5ac11ef549a47561c7382ff451.zip opie-d9b5fcc45b1fef5ac11ef549a47561c7382ff451.tar.gz opie-d9b5fcc45b1fef5ac11ef549a47561c7382ff451.tar.bz2 |
do not rely on scrollbars beeing right
-rw-r--r-- | core/pim/datebook/datebookweek.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp index ab7e963..dad1c3f 100644 --- a/core/pim/datebook/datebookweek.cpp +++ b/core/pim/datebook/datebookweek.cpp | |||
@@ -1,666 +1,667 @@ | |||
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 | #include "datebookweek.h" | 20 | #include "datebookweek.h" |
21 | #include "datebookweekheaderimpl.h" | 21 | #include "datebookweekheaderimpl.h" |
22 | 22 | ||
23 | #include <qpe/datebookdb.h> | 23 | #include <qpe/datebookdb.h> |
24 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
25 | #include <qpe/calendar.h> | 25 | #include <qpe/calendar.h> |
26 | 26 | ||
27 | #include <qheader.h> | 27 | #include <qheader.h> |
28 | #include <qlabel.h> | 28 | #include <qlabel.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | #include <qtimer.h> | 30 | #include <qtimer.h> |
31 | 31 | ||
32 | //----------------------------------------------------------------- | 32 | //----------------------------------------------------------------- |
33 | 33 | ||
34 | 34 | ||
35 | DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e ) | 35 | DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e ) |
36 | : ev( e ) | 36 | : ev( e ) |
37 | { | 37 | { |
38 | // with the current implementation change the color for all day events | 38 | // with the current implementation change the color for all day events |
39 | if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) { | 39 | if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) { |
40 | c = Qt::green; | 40 | c = Qt::green; |
41 | } else { | 41 | } else { |
42 | c = ev.event().hasAlarm() ? Qt::red : Qt::blue; | 42 | c = ev.event().hasAlarm() ? Qt::red : Qt::blue; |
43 | } | 43 | } |
44 | } | 44 | } |
45 | 45 | ||
46 | void DateBookWeekItem::setGeometry( int x, int y, int w, int h ) | 46 | void DateBookWeekItem::setGeometry( int x, int y, int w, int h ) |
47 | { | 47 | { |
48 | r.setRect( x, y, w, h ); | 48 | r.setRect( x, y, w, h ); |
49 | } | 49 | } |
50 | 50 | ||
51 | 51 | ||
52 | //------------------=--------------------------------------------- | 52 | //------------------=--------------------------------------------- |
53 | 53 | ||
54 | DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday, | 54 | DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday, |
55 | QWidget *parent, const char *name ) | 55 | QWidget *parent, const char *name ) |
56 | : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ), | 56 | : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ), |
57 | showingEvent( false ) | 57 | showingEvent( false ) |
58 | { | 58 | { |
59 | items.setAutoDelete( true ); | 59 | items.setAutoDelete( true ); |
60 | 60 | ||
61 | viewport()->setBackgroundMode( PaletteBase ); | 61 | viewport()->setBackgroundMode( PaletteBase ); |
62 | 62 | ||
63 | header = new QHeader( this ); | 63 | header = new QHeader( this ); |
64 | header->addLabel( "" ); | 64 | header->addLabel( "" ); |
65 | 65 | ||
66 | header->setMovingEnabled( false ); | 66 | header->setMovingEnabled( false ); |
67 | header->setResizeEnabled( false ); | 67 | header->setResizeEnabled( false ); |
68 | header->setClickEnabled( false, 0 ); | 68 | header->setClickEnabled( false, 0 ); |
69 | initNames(); | 69 | initNames(); |
70 | 70 | ||
71 | 71 | ||
72 | connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) ); | 72 | connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) ); |
73 | 73 | ||
74 | QObject::connect(qApp, SIGNAL(clockChanged(bool)), | 74 | QObject::connect(qApp, SIGNAL(clockChanged(bool)), |
75 | this, SLOT(slotChangeClock(bool))); | 75 | this, SLOT(slotChangeClock(bool))); |
76 | 76 | ||
77 | QFontMetrics fm( font() ); | 77 | QFontMetrics fm( font() ); |
78 | rowHeight = fm.height()+2; | 78 | rowHeight = fm.height()+2; |
79 | 79 | ||
80 | resizeContents( width(), 24*rowHeight ); | 80 | resizeContents( width(), 24*rowHeight ); |
81 | } | 81 | } |
82 | 82 | ||
83 | void DateBookWeekView::initNames() | 83 | void DateBookWeekView::initNames() |
84 | { | 84 | { |
85 | #warning Please review this ! (eilers) | 85 | #warning Please review this ! (eilers) |
86 | 86 | ||
87 | // Ok, I am Mr. Pedantic, but shouldn't we count until 6 instead of 7, if bOnMonday is false ? (eilers) | 87 | // Ok, I am Mr. Pedantic, but shouldn't we count until 6 instead of 7, if bOnMonday is false ? (eilers) |
88 | 88 | ||
89 | static bool bFirst = true; | 89 | static bool bFirst = true; |
90 | if ( bFirst ) { | 90 | if ( bFirst ) { |
91 | if ( bOnMonday ) { | 91 | if ( bOnMonday ) { |
92 | for ( int i = 1; i<=7; i++ ) { | 92 | for ( int i = 1; i<=7; i++ ) { |
93 | header->addLabel( Calendar::nameOfDay( i ) ); | 93 | header->addLabel( Calendar::nameOfDay( i ) ); |
94 | } | 94 | } |
95 | 95 | ||
96 | } else { | 96 | } else { |
97 | header->addLabel( Calendar::nameOfDay( 7 ) ); | 97 | header->addLabel( Calendar::nameOfDay( 7 ) ); |
98 | for ( int i = 1; i<7; i++ ) { | 98 | for ( int i = 1; i<7; i++ ) { |
99 | header->addLabel( Calendar::nameOfDay( i ) ); | 99 | header->addLabel( Calendar::nameOfDay( i ) ); |
100 | } | 100 | } |
101 | } | 101 | } |
102 | bFirst = false; | 102 | bFirst = false; |
103 | } else { | 103 | } else { |
104 | // we are change things... | 104 | // we are change things... |
105 | if ( bOnMonday ) { | 105 | if ( bOnMonday ) { |
106 | for ( int i = 1; i<=7; i++ ) { | 106 | for ( int i = 1; i<=7; i++ ) { |
107 | header->setLabel( i, Calendar::nameOfDay( i ) ); | 107 | header->setLabel( i, Calendar::nameOfDay( i ) ); |
108 | } | 108 | } |
109 | 109 | ||
110 | } else { | 110 | } else { |
111 | header->setLabel( 1, Calendar::nameOfDay( 7 ) ); | 111 | header->setLabel( 1, Calendar::nameOfDay( 7 ) ); |
112 | for ( int i = 1; i<7; i++ ) { | 112 | for ( int i = 1; i<7; i++ ) { |
113 | header->setLabel( i+1, Calendar::nameOfDay( i ) ); | 113 | header->setLabel( i+1, Calendar::nameOfDay( i ) ); |
114 | } | 114 | } |
115 | 115 | ||
116 | } | 116 | } |
117 | } | 117 | } |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | 121 | ||
122 | void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) | 122 | void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) |
123 | { | 123 | { |
124 | items.clear(); | 124 | items.clear(); |
125 | QValueListIterator<EffectiveEvent> it; | 125 | QValueListIterator<EffectiveEvent> it; |
126 | for ( it = ev.begin(); it != ev.end(); ++it ) { | 126 | for ( it = ev.begin(); it != ev.end(); ++it ) { |
127 | DateBookWeekItem *i = new DateBookWeekItem( *it ); | 127 | DateBookWeekItem *i = new DateBookWeekItem( *it ); |
128 | if(!((i->event().end().hour()==0) && (i->event().end().minute()==0) && (i->event().startDate()!=i->event().date()))) {// Skip events ending at 00:00 starting at another day. | 128 | if(!((i->event().end().hour()==0) && (i->event().end().minute()==0) && (i->event().startDate()!=i->event().date()))) {// Skip events ending at 00:00 starting at another day. |
129 | positionItem( i ); | 129 | positionItem( i ); |
130 | items.append( i ); | 130 | items.append( i ); |
131 | } | 131 | } |
132 | } | 132 | } |
133 | viewport()->update(); | 133 | viewport()->update(); |
134 | } | 134 | } |
135 | 135 | ||
136 | void DateBookWeekView::moveToHour( int h ) | 136 | void DateBookWeekView::moveToHour( int h ) |
137 | { | 137 | { |
138 | int offset = h*rowHeight; | 138 | int offset = h*rowHeight; |
139 | setContentsPos( 0, offset ); | 139 | setContentsPos( 0, offset ); |
140 | } | 140 | } |
141 | 141 | ||
142 | void DateBookWeekView::keyPressEvent( QKeyEvent *e ) | 142 | void DateBookWeekView::keyPressEvent( QKeyEvent *e ) |
143 | { | 143 | { |
144 | e->ignore(); | 144 | e->ignore(); |
145 | } | 145 | } |
146 | 146 | ||
147 | void DateBookWeekView::slotChangeClock( bool c ) | 147 | void DateBookWeekView::slotChangeClock( bool c ) |
148 | { | 148 | { |
149 | ampm = c; | 149 | ampm = c; |
150 | viewport()->update(); | 150 | viewport()->update(); |
151 | } | 151 | } |
152 | 152 | ||
153 | static inline int db_round30min( int m ) | 153 | static inline int db_round30min( int m ) |
154 | { | 154 | { |
155 | if ( m < 15 ) | 155 | if ( m < 15 ) |
156 | m = 0; | 156 | m = 0; |
157 | else if ( m < 45 ) | 157 | else if ( m < 45 ) |
158 | m = 1; | 158 | m = 1; |
159 | else | 159 | else |
160 | m = 2; | 160 | m = 2; |
161 | 161 | ||
162 | return m; | 162 | return m; |
163 | } | 163 | } |
164 | 164 | ||
165 | void DateBookWeekView::alterDay( int day ) | 165 | void DateBookWeekView::alterDay( int day ) |
166 | { | 166 | { |
167 | if ( !bOnMonday ) { | 167 | if ( !bOnMonday ) { |
168 | day--; | 168 | day--; |
169 | } | 169 | } |
170 | emit showDay( day ); | 170 | emit showDay( day ); |
171 | } | 171 | } |
172 | 172 | ||
173 | void DateBookWeekView::positionItem( DateBookWeekItem *i ) | 173 | void DateBookWeekView::positionItem( DateBookWeekItem *i ) |
174 | { | 174 | { |
175 | const int Width = 8; | 175 | const int Width = 8; |
176 | const EffectiveEvent ev = i->event(); | 176 | const EffectiveEvent ev = i->event(); |
177 | 177 | ||
178 | // 30 minute intervals | 178 | // 30 minute intervals |
179 | int y = ev.start().hour() * 2; | 179 | int y = ev.start().hour() * 2; |
180 | y += db_round30min( ev.start().minute() ); | 180 | y += db_round30min( ev.start().minute() ); |
181 | int y2 = ev.end().hour() * 2; | 181 | int y2 = ev.end().hour() * 2; |
182 | y2 += db_round30min( ev.end().minute() ); | 182 | y2 += db_round30min( ev.end().minute() ); |
183 | if ( y > 47 ) y = 47; | 183 | if ( y > 47 ) y = 47; |
184 | if ( y2 > 48 ) y2 = 48; | 184 | if ( y2 > 48 ) y2 = 48; |
185 | y = (y * rowHeight) / 2; | 185 | y = (y * rowHeight) / 2; |
186 | y2 = (y2 * rowHeight) / 2; | 186 | y2 = (y2 * rowHeight) / 2; |
187 | 187 | ||
188 | int h; | 188 | int h; |
189 | if ( ev.event().type() == Event::AllDay ) { | 189 | if ( ev.event().type() == Event::AllDay ) { |
190 | h = (48 * rowHeight) / 2; | 190 | h = (48 * rowHeight) / 2; |
191 | y = 0; | 191 | y = 0; |
192 | } else { | 192 | } else { |
193 | h=y2-y; | 193 | h=y2-y; |
194 | if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2; | 194 | if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2; |
195 | } | 195 | } |
196 | 196 | ||
197 | int dow = ev.date().dayOfWeek(); | 197 | int dow = ev.date().dayOfWeek(); |
198 | if ( !bOnMonday ) { | 198 | if ( !bOnMonday ) { |
199 | if ( dow == 7 ) | 199 | if ( dow == 7 ) |
200 | dow = 1; | 200 | dow = 1; |
201 | else | 201 | else |
202 | dow++; | 202 | dow++; |
203 | } | 203 | } |
204 | int x = header->sectionPos( dow ) - 1; | 204 | int x = header->sectionPos( dow ) - 1; |
205 | int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); | 205 | int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); |
206 | DateBookWeekItem *isect = 0; | 206 | DateBookWeekItem *isect = 0; |
207 | do { | 207 | do { |
208 | i->setGeometry( x, y, Width, h ); | 208 | i->setGeometry( x, y, Width, h ); |
209 | isect = intersects( i ); | 209 | isect = intersects( i ); |
210 | x += Width - 1; | 210 | x += Width - 1; |
211 | } while ( isect && x < xlim ); | 211 | } while ( isect && x < xlim ); |
212 | } | 212 | } |
213 | 213 | ||
214 | DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) | 214 | DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) |
215 | { | 215 | { |
216 | QRect geom = item->geometry(); | 216 | QRect geom = item->geometry(); |
217 | 217 | ||
218 | // We allow the edges to overlap | 218 | // We allow the edges to overlap |
219 | geom.moveBy( 1, 1 ); | 219 | geom.moveBy( 1, 1 ); |
220 | geom.setSize( geom.size()-QSize(2,2) ); | 220 | geom.setSize( geom.size()-QSize(2,2) ); |
221 | 221 | ||
222 | QListIterator<DateBookWeekItem> it(items); | 222 | QListIterator<DateBookWeekItem> it(items); |
223 | for ( ; it.current(); ++it ) { | 223 | for ( ; it.current(); ++it ) { |
224 | DateBookWeekItem *i = it.current(); | 224 | DateBookWeekItem *i = it.current(); |
225 | if ( i != item ) { | 225 | if ( i != item ) { |
226 | if ( i->geometry().intersects( geom ) ) { | 226 | if ( i->geometry().intersects( geom ) ) { |
227 | return i; | 227 | return i; |
228 | } | 228 | } |
229 | } | 229 | } |
230 | } | 230 | } |
231 | 231 | ||
232 | return 0; | 232 | return 0; |
233 | } | 233 | } |
234 | 234 | ||
235 | void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) | 235 | void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) |
236 | { | 236 | { |
237 | QListIterator<DateBookWeekItem> it(items); | 237 | QListIterator<DateBookWeekItem> it(items); |
238 | for ( ; it.current(); ++it ) { | 238 | for ( ; it.current(); ++it ) { |
239 | DateBookWeekItem *i = it.current(); | 239 | DateBookWeekItem *i = it.current(); |
240 | if ( i->geometry().contains( e->pos() ) ) { | 240 | if ( i->geometry().contains( e->pos() ) ) { |
241 | showingEvent = true; | 241 | showingEvent = true; |
242 | emit signalShowEvent( i->event() ); | 242 | emit signalShowEvent( i->event() ); |
243 | break; | 243 | break; |
244 | } | 244 | } |
245 | } | 245 | } |
246 | } | 246 | } |
247 | 247 | ||
248 | void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) | 248 | void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) |
249 | { | 249 | { |
250 | if ( showingEvent ) { | 250 | if ( showingEvent ) { |
251 | showingEvent = false; | 251 | showingEvent = false; |
252 | emit signalHideEvent(); | 252 | emit signalHideEvent(); |
253 | } else { | 253 | } else { |
254 | int d = header->sectionAt( e->pos().x() ); | 254 | int d = header->sectionAt( e->pos().x() ); |
255 | if ( d > 0 ) { | 255 | if ( d > 0 ) { |
256 | // if ( !bOnMonday ) | 256 | // if ( !bOnMonday ) |
257 | // d--; | 257 | // d--; |
258 | emit showDay( d ); | 258 | emit showDay( d ); |
259 | } | 259 | } |
260 | } | 260 | } |
261 | } | 261 | } |
262 | 262 | ||
263 | void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) | 263 | void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) |
264 | { | 264 | { |
265 | QRect ur( cx, cy, cw, ch ); | 265 | QRect ur( cx, cy, cw, ch ); |
266 | p->setPen( lightGray ); | 266 | p->setPen( lightGray ); |
267 | for ( int i = 1; i <= 7; i++ ) | 267 | for ( int i = 1; i <= 7; i++ ) |
268 | p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); | 268 | p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); |
269 | 269 | ||
270 | p->setPen( black ); | 270 | p->setPen( black ); |
271 | for ( int t = 0; t < 24; t++ ) { | 271 | for ( int t = 0; t < 24; t++ ) { |
272 | int y = t*rowHeight; | 272 | int y = t*rowHeight; |
273 | if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { | 273 | if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { |
274 | QString s; | 274 | QString s; |
275 | if ( ampm ) { | 275 | if ( ampm ) { |
276 | if ( t == 0 ) | 276 | if ( t == 0 ) |
277 | s = QString::number( 12 ); | 277 | s = QString::number( 12 ); |
278 | else if ( t == 12 ) | 278 | else if ( t == 12 ) |
279 | s = QString::number(12) + tr( "p" ); | 279 | s = QString::number(12) + tr( "p" ); |
280 | else if ( t > 12 ) { | 280 | else if ( t > 12 ) { |
281 | if ( t - 12 < 10 ) | 281 | if ( t - 12 < 10 ) |
282 | s = " "; | 282 | s = " "; |
283 | else | 283 | else |
284 | s = ""; | 284 | s = ""; |
285 | s += QString::number( t - 12 ) + tr("p"); | 285 | s += QString::number( t - 12 ) + tr("p"); |
286 | } else { | 286 | } else { |
287 | if ( 12 - t < 3 ) | 287 | if ( 12 - t < 3 ) |
288 | s = ""; | 288 | s = ""; |
289 | else | 289 | else |
290 | s = " "; | 290 | s = " "; |
291 | s += QString::number( t ); | 291 | s += QString::number( t ); |
292 | } | 292 | } |
293 | } else { | 293 | } else { |
294 | s = QString::number( t ); | 294 | s = QString::number( t ); |
295 | if ( s.length() == 1 ) | 295 | if ( s.length() == 1 ) |
296 | s.prepend( "0" ); | 296 | s.prepend( "0" ); |
297 | } | 297 | } |
298 | p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); | 298 | p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); |
299 | } | 299 | } |
300 | } | 300 | } |
301 | 301 | ||
302 | QListIterator<DateBookWeekItem> it(items); | 302 | QListIterator<DateBookWeekItem> it(items); |
303 | for ( ; it.current(); ++it ) { | 303 | for ( ; it.current(); ++it ) { |
304 | DateBookWeekItem *i = it.current(); | 304 | DateBookWeekItem *i = it.current(); |
305 | if ( i->geometry().intersects( ur ) ) { | 305 | if ( i->geometry().intersects( ur ) ) { |
306 | p->setBrush( i->color() ); | 306 | p->setBrush( i->color() ); |
307 | p->drawRect( i->geometry() ); | 307 | p->drawRect( i->geometry() ); |
308 | } | 308 | } |
309 | } | 309 | } |
310 | } | 310 | } |
311 | 311 | ||
312 | void DateBookWeekView::resizeEvent( QResizeEvent *e ) | 312 | void DateBookWeekView::resizeEvent( QResizeEvent *e ) |
313 | { | 313 | { |
314 | const int hourWidth = 20; | 314 | const int hourWidth = 20; |
315 | QScrollView::resizeEvent( e ); | 315 | QScrollView::resizeEvent( e ); |
316 | int avail = width()-qApp->style().scrollBarExtent().width()-1; | 316 | int avail = visibleWidth(); |
317 | header->setGeometry( 0, 0, avail, header->sizeHint().height() ); | 317 | header->setGeometry( leftMargin()+frameWidth()+frameRect().left() , frameWidth(), |
318 | setMargins( 0, header->height(), 0, 0 ); | 318 | visibleWidth(), header->sizeHint().height() ); |
319 | setMargins( 0, header->sizeHint().height(), 0, 0 ); | ||
319 | header->resizeSection( 0, hourWidth ); | 320 | header->resizeSection( 0, hourWidth ); |
320 | int sw = (avail - hourWidth) / 7; | 321 | int sw = (avail - hourWidth) / 7; |
321 | for ( int i = 1; i < 7; i++ ) | 322 | for ( int i = 1; i < 7; i++ ) |
322 | header->resizeSection( i, sw ); | 323 | header->resizeSection( i, sw ); |
323 | header->resizeSection( 7, avail - hourWidth - sw*6 ); | 324 | header->resizeSection( 7, avail - hourWidth - sw*6 ); |
324 | } | 325 | } |
325 | 326 | ||
326 | void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) | 327 | void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) |
327 | { | 328 | { |
328 | bOnMonday = bStartOnMonday; | 329 | bOnMonday = bStartOnMonday; |
329 | initNames(); | 330 | initNames(); |
330 | } | 331 | } |
331 | 332 | ||
332 | //------------------------------------------------------------------- | 333 | //------------------------------------------------------------------- |
333 | 334 | ||
334 | DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, | 335 | DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, |
335 | QWidget *parent, const char *name ) | 336 | QWidget *parent, const char *name ) |
336 | : QWidget( parent, name ), | 337 | : QWidget( parent, name ), |
337 | db( newDB ), | 338 | db( newDB ), |
338 | startTime( 0 ), | 339 | startTime( 0 ), |
339 | ampm( ap ), | 340 | ampm( ap ), |
340 | bStartOnMonday( startOnMonday ) | 341 | bStartOnMonday( startOnMonday ) |
341 | { | 342 | { |
342 | setFocusPolicy(StrongFocus); | 343 | setFocusPolicy(StrongFocus); |
343 | QVBoxLayout *vb = new QVBoxLayout( this ); | 344 | QVBoxLayout *vb = new QVBoxLayout( this ); |
344 | header = new DateBookWeekHeader( bStartOnMonday, this ); | 345 | header = new DateBookWeekHeader( bStartOnMonday, this ); |
345 | view = new DateBookWeekView( ampm, startOnMonday, this ); | 346 | view = new DateBookWeekView( ampm, startOnMonday, this ); |
346 | vb->addWidget( header ); | 347 | vb->addWidget( header ); |
347 | vb->addWidget( view ); | 348 | vb->addWidget( view ); |
348 | 349 | ||
349 | lblDesc = new QLabel( this, "event label" ); | 350 | lblDesc = new QLabel( this, "event label" ); |
350 | lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); | 351 | lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); |
351 | lblDesc->setBackgroundColor( yellow ); | 352 | lblDesc->setBackgroundColor( yellow ); |
352 | lblDesc->hide(); | 353 | lblDesc->hide(); |
353 | 354 | ||
354 | tHide = new QTimer( this ); | 355 | tHide = new QTimer( this ); |
355 | 356 | ||
356 | connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) ); | 357 | connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) ); |
357 | connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); | 358 | connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); |
358 | connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); | 359 | connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); |
359 | connect( header, SIGNAL( dateChanged( QDate &) ), this, SLOT( dateChanged( QDate &) ) ); | 360 | connect( header, SIGNAL( dateChanged( QDate &) ), this, SLOT( dateChanged( QDate &) ) ); |
360 | connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); | 361 | connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); |
361 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); | 362 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); |
362 | connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); | 363 | connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); |
363 | setDate(QDate::currentDate()); | 364 | setDate(QDate::currentDate()); |
364 | } | 365 | } |
365 | 366 | ||
366 | void DateBookWeek::keyPressEvent(QKeyEvent *e) | 367 | void DateBookWeek::keyPressEvent(QKeyEvent *e) |
367 | { | 368 | { |
368 | switch(e->key()) { | 369 | switch(e->key()) { |
369 | case Key_Up: | 370 | case Key_Up: |
370 | view->scrollBy(0, -20); | 371 | view->scrollBy(0, -20); |
371 | break; | 372 | break; |
372 | case Key_Down: | 373 | case Key_Down: |
373 | view->scrollBy(0, 20); | 374 | view->scrollBy(0, 20); |
374 | break; | 375 | break; |
375 | case Key_Left: | 376 | case Key_Left: |
376 | setDate(date().addDays(-7)); | 377 | setDate(date().addDays(-7)); |
377 | break; | 378 | break; |
378 | case Key_Right: | 379 | case Key_Right: |
379 | setDate(date().addDays(7)); | 380 | setDate(date().addDays(7)); |
380 | break; | 381 | break; |
381 | default: | 382 | default: |
382 | e->ignore(); | 383 | e->ignore(); |
383 | } | 384 | } |
384 | } | 385 | } |
385 | 386 | ||
386 | void DateBookWeek::showDay( int day ) | 387 | void DateBookWeek::showDay( int day ) |
387 | { | 388 | { |
388 | QDate d=bdate; | 389 | QDate d=bdate; |
389 | 390 | ||
390 | // Calculate offset to first day of week. | 391 | // Calculate offset to first day of week. |
391 | int dayoffset=d.dayOfWeek() % 7; | 392 | int dayoffset=d.dayOfWeek() % 7; |
392 | 393 | ||
393 | if(bStartOnMonday) dayoffset--; | 394 | if(bStartOnMonday) dayoffset--; |
394 | 395 | ||
395 | day--; | 396 | day--; |
396 | d=d.addDays(day-dayoffset); | 397 | d=d.addDays(day-dayoffset); |
397 | emit showDate( d.year(), d.month(), d.day() ); | 398 | emit showDate( d.year(), d.month(), d.day() ); |
398 | } | 399 | } |
399 | 400 | ||
400 | void DateBookWeek::setDate( int y, int m, int d ) | 401 | void DateBookWeek::setDate( int y, int m, int d ) |
401 | { | 402 | { |
402 | setDate(QDate(y, m, d)); | 403 | setDate(QDate(y, m, d)); |
403 | } | 404 | } |
404 | 405 | ||
405 | void DateBookWeek::setDate(QDate newdate) | 406 | void DateBookWeek::setDate(QDate newdate) |
406 | { | 407 | { |
407 | bdate=newdate; | 408 | bdate=newdate; |
408 | dow = newdate.dayOfWeek(); | 409 | dow = newdate.dayOfWeek(); |
409 | header->setDate( newdate ); | 410 | header->setDate( newdate ); |
410 | } | 411 | } |
411 | 412 | ||
412 | void DateBookWeek::dateChanged( QDate &newdate ) | 413 | void DateBookWeek::dateChanged( QDate &newdate ) |
413 | { | 414 | { |
414 | bdate=newdate; | 415 | bdate=newdate; |
415 | getEvents(); | 416 | getEvents(); |
416 | } | 417 | } |
417 | 418 | ||
418 | QDate DateBookWeek::date() const | 419 | QDate DateBookWeek::date() const |
419 | { | 420 | { |
420 | return bdate; | 421 | return bdate; |
421 | } | 422 | } |
422 | 423 | ||
423 | void DateBookWeek::getEvents() | 424 | void DateBookWeek::getEvents() |
424 | { | 425 | { |
425 | QDate startWeek = weekDate(); | 426 | QDate startWeek = weekDate(); |
426 | 427 | ||
427 | QDate endWeek = startWeek.addDays( 6 ); | 428 | QDate endWeek = startWeek.addDays( 6 ); |
428 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); | 429 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); |
429 | view->showEvents( eventList ); | 430 | view->showEvents( eventList ); |
430 | view->moveToHour( startTime ); | 431 | view->moveToHour( startTime ); |
431 | } | 432 | } |
432 | 433 | ||
433 | void DateBookWeek::generateAllDayTooltext( QString& text ) { | 434 | void DateBookWeek::generateAllDayTooltext( QString& text ) { |
434 | text += "<b>" + tr("This is an all day event.") + "</b><br>"; | 435 | text += "<b>" + tr("This is an all day event.") + "</b><br>"; |
435 | } | 436 | } |
436 | 437 | ||
437 | void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) { | 438 | void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) { |
438 | str += "<b>" + QObject::tr("Start") + "</b>: "; | 439 | str += "<b>" + QObject::tr("Start") + "</b>: "; |
439 | str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); | 440 | str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); |
440 | if( ev.startDate()!=ev.endDate() ) { | 441 | if( ev.startDate()!=ev.endDate() ) { |
441 | str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; | 442 | str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; |
442 | } | 443 | } |
443 | str += "<br>"; | 444 | str += "<br>"; |
444 | str += "<b>" + QObject::tr("End") + "</b>: "; | 445 | str += "<b>" + QObject::tr("End") + "</b>: "; |
445 | str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); | 446 | str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); |
446 | if( ev.startDate()!=ev.endDate() ) { | 447 | if( ev.startDate()!=ev.endDate() ) { |
447 | str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; | 448 | str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; |
448 | } | 449 | } |
449 | } | 450 | } |
450 | 451 | ||
451 | void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) | 452 | void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) |
452 | { | 453 | { |
453 | if ( tHide->isActive() ) | 454 | if ( tHide->isActive() ) |
454 | tHide->stop(); | 455 | tHide->stop(); |
455 | 456 | ||
456 | // why would someone use "<"? Oh well, fix it up... | 457 | // why would someone use "<"? Oh well, fix it up... |
457 | // I wonder what other things may be messed up... | 458 | // I wonder what other things may be messed up... |
458 | QString strDesc = ev.description(); | 459 | QString strDesc = ev.description(); |
459 | int where = strDesc.find( "<" ); | 460 | int where = strDesc.find( "<" ); |
460 | while ( where != -1 ) { | 461 | while ( where != -1 ) { |
461 | strDesc.remove( where, 1 ); | 462 | strDesc.remove( where, 1 ); |
462 | strDesc.insert( where, "<" ); | 463 | strDesc.insert( where, "<" ); |
463 | where = strDesc.find( "<", where ); | 464 | where = strDesc.find( "<", where ); |
464 | } | 465 | } |
465 | 466 | ||
466 | QString strCat; | 467 | QString strCat; |
467 | // ### FIX later... | 468 | // ### FIX later... |
468 | // QString strCat = ev.category(); | 469 | // QString strCat = ev.category(); |
469 | // where = strCat.find( "<" ); | 470 | // where = strCat.find( "<" ); |
470 | // while ( where != -1 ) { | 471 | // while ( where != -1 ) { |
471 | // strCat.remove( where, 1 ); | 472 | // strCat.remove( where, 1 ); |
472 | // strCat.insert( where, "<" ); | 473 | // strCat.insert( where, "<" ); |
473 | // where = strCat.find( "<", where ); | 474 | // where = strCat.find( "<", where ); |
474 | // } | 475 | // } |
475 | 476 | ||
476 | QString strLocation = ev.location(); | 477 | QString strLocation = ev.location(); |
477 | while ( where != -1 ) { | 478 | while ( where != -1 ) { |
478 | strLocation.remove( where, 1 ); | 479 | strLocation.remove( where, 1 ); |
479 | strLocation.insert( where, "<" ); | 480 | strLocation.insert( where, "<" ); |
480 | where = strLocation.find( "<", where ); | 481 | where = strLocation.find( "<", where ); |
481 | } | 482 | } |
482 | 483 | ||
483 | QString strNote = ev.notes(); | 484 | QString strNote = ev.notes(); |
484 | where = strNote.find( "<" ); | 485 | where = strNote.find( "<" ); |
485 | while ( where != -1 ) { | 486 | while ( where != -1 ) { |
486 | strNote.remove( where, 1 ); | 487 | strNote.remove( where, 1 ); |
487 | strNote.insert( where, "<" ); | 488 | strNote.insert( where, "<" ); |
488 | where = strNote.find( "<", where ); | 489 | where = strNote.find( "<", where ); |
489 | } | 490 | } |
490 | 491 | ||
491 | QString str = "<b>" + strDesc + "</b><br>" | 492 | QString str = "<b>" + strDesc + "</b><br>" |
492 | + strLocation + "<br>" | 493 | + strLocation + "<br>" |
493 | + "<i>" + strCat + "</i>" | 494 | + "<i>" + strCat + "</i>" |
494 | + "<br>" + TimeString::longDateString( ev.date() ) | 495 | + "<br>" + TimeString::longDateString( ev.date() ) |
495 | + "<br>"; | 496 | + "<br>"; |
496 | 497 | ||
497 | if (ev.event().type() == Event::Normal ) | 498 | if (ev.event().type() == Event::Normal ) |
498 | generateNormalTooltext( str, ev ); | 499 | generateNormalTooltext( str, ev ); |
499 | else | 500 | else |
500 | generateAllDayTooltext( str ); | 501 | generateAllDayTooltext( str ); |
501 | 502 | ||
502 | str += "<br><br>" + strNote; | 503 | str += "<br><br>" + strNote; |
503 | 504 | ||
504 | lblDesc->setText( str ); | 505 | lblDesc->setText( str ); |
505 | lblDesc->resize( lblDesc->sizeHint() ); | 506 | lblDesc->resize( lblDesc->sizeHint() ); |
506 | // move the label so it is "centerd" horizontally... | 507 | // move the label so it is "centerd" horizontally... |
507 | lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 ); | 508 | lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 ); |
508 | lblDesc->show(); | 509 | lblDesc->show(); |
509 | } | 510 | } |
510 | 511 | ||
511 | void DateBookWeek::slotHideEvent() | 512 | void DateBookWeek::slotHideEvent() |
512 | { | 513 | { |
513 | tHide->start( 2000, true ); | 514 | tHide->start( 2000, true ); |
514 | } | 515 | } |
515 | 516 | ||
516 | void DateBookWeek::setStartViewTime( int startHere ) | 517 | void DateBookWeek::setStartViewTime( int startHere ) |
517 | { | 518 | { |
518 | startTime = startHere; | 519 | startTime = startHere; |
519 | view->moveToHour( startTime ); | 520 | view->moveToHour( startTime ); |
520 | } | 521 | } |
521 | 522 | ||
522 | int DateBookWeek::startViewTime() const | 523 | int DateBookWeek::startViewTime() const |
523 | { | 524 | { |
524 | return startTime; | 525 | return startTime; |
525 | } | 526 | } |
526 | 527 | ||
527 | void DateBookWeek::redraw() | 528 | void DateBookWeek::redraw() |
528 | { | 529 | { |
529 | getEvents(); | 530 | getEvents(); |
530 | } | 531 | } |
531 | 532 | ||
532 | void DateBookWeek::slotYearChanged( int y ) | 533 | void DateBookWeek::slotYearChanged( int y ) |
533 | { | 534 | { |
534 | int totWeek; | 535 | int totWeek; |
535 | QDate d( y, 12, 31 ); | 536 | QDate d( y, 12, 31 ); |
536 | int throwAway; | 537 | int throwAway; |
537 | calcWeek( d, totWeek, throwAway, bStartOnMonday ); | 538 | calcWeek( d, totWeek, throwAway, bStartOnMonday ); |
538 | while ( totWeek == 1 ) { | 539 | while ( totWeek == 1 ) { |
539 | d = d.addDays( -1 ); | 540 | d = d.addDays( -1 ); |
540 | calcWeek( d, totWeek, throwAway, bStartOnMonday ); | 541 | calcWeek( d, totWeek, throwAway, bStartOnMonday ); |
541 | } | 542 | } |
542 | } | 543 | } |
543 | 544 | ||
544 | void DateBookWeek::slotWeekChanged( bool onMonday ) | 545 | void DateBookWeek::slotWeekChanged( bool onMonday ) |
545 | { | 546 | { |
546 | bStartOnMonday = onMonday; | 547 | bStartOnMonday = onMonday; |
547 | view->setStartOfWeek( bStartOnMonday ); | 548 | view->setStartOfWeek( bStartOnMonday ); |
548 | header->setStartOfWeek( bStartOnMonday ); | 549 | header->setStartOfWeek( bStartOnMonday ); |
549 | redraw(); | 550 | redraw(); |
550 | } | 551 | } |
551 | 552 | ||
552 | void DateBookWeek::slotClockChanged( bool ap ) | 553 | void DateBookWeek::slotClockChanged( bool ap ) |
553 | { | 554 | { |
554 | ampm = ap; | 555 | ampm = ap; |
555 | } | 556 | } |
556 | 557 | ||
557 | // return the date at the beginning of the week... | 558 | // return the date at the beginning of the week... |
558 | QDate DateBookWeek::weekDate() const | 559 | QDate DateBookWeek::weekDate() const |
559 | { | 560 | { |
560 | QDate d=bdate; | 561 | QDate d=bdate; |
561 | 562 | ||
562 | // Calculate offset to first day of week. | 563 | // Calculate offset to first day of week. |
563 | int dayoffset=d.dayOfWeek(); | 564 | int dayoffset=d.dayOfWeek(); |
564 | if(bStartOnMonday) dayoffset--; | 565 | if(bStartOnMonday) dayoffset--; |
565 | else if( dayoffset == 7 ) | 566 | else if( dayoffset == 7 ) |
566 | dayoffset = 0; | 567 | dayoffset = 0; |
567 | 568 | ||
568 | return d.addDays(-dayoffset); | 569 | return d.addDays(-dayoffset); |
569 | } | 570 | } |
570 | 571 | ||
571 | // this used to only be needed by datebook.cpp, but now we need it inside | 572 | // this used to only be needed by datebook.cpp, but now we need it inside |
572 | // week view since | 573 | // week view since |
573 | // we need to be able to figure out our total number of weeks on the fly... | 574 | // we need to be able to figure out our total number of weeks on the fly... |
574 | // this is probably the best place to put it.. | 575 | // this is probably the best place to put it.. |
575 | 576 | ||
576 | // For Weeks that start on Monday... (EASY!) | 577 | // For Weeks that start on Monday... (EASY!) |
577 | // At the moment we will use ISO 8601 method for computing | 578 | // At the moment we will use ISO 8601 method for computing |
578 | // the week. Granted, other countries use other methods, | 579 | // the week. Granted, other countries use other methods, |
579 | // bet we aren't doing any Locale stuff at the moment. So, | 580 | // bet we aren't doing any Locale stuff at the moment. So, |
580 | // this should pass. This Algorithim is public domain and | 581 | // this should pass. This Algorithim is public domain and |
581 | // available at: | 582 | // available at: |
582 | // http://personal.ecu.edu/mccartyr/ISOwdALG.txt | 583 | // http://personal.ecu.edu/mccartyr/ISOwdALG.txt |
583 | // the week number is return, and the year number is returned in year | 584 | // the week number is return, and the year number is returned in year |
584 | // for Instance 2001/12/31 is actually the first week in 2002. | 585 | // for Instance 2001/12/31 is actually the first week in 2002. |
585 | // There is a more mathematical definition, but I will implement it when | 586 | // There is a more mathematical definition, but I will implement it when |
586 | // we are pass our deadline. | 587 | // we are pass our deadline. |
587 | 588 | ||
588 | // For Weeks that start on Sunday... (ahh... home rolled) | 589 | // For Weeks that start on Sunday... (ahh... home rolled) |
589 | // okay, if Jan 1 is on Friday or Saturday, | 590 | // okay, if Jan 1 is on Friday or Saturday, |
590 | // it will go to the pervious | 591 | // it will go to the pervious |
591 | // week... | 592 | // week... |
592 | 593 | ||
593 | bool calcWeek( const QDate &d, int &week, int &year, | 594 | bool calcWeek( const QDate &d, int &week, int &year, |
594 | bool startOnMonday ) | 595 | bool startOnMonday ) |
595 | { | 596 | { |
596 | int weekNumber; | 597 | int weekNumber; |
597 | int yearNumber; | 598 | int yearNumber; |
598 | 599 | ||
599 | // remove a pesky warning, (Optimizations on g++) | 600 | // remove a pesky warning, (Optimizations on g++) |
600 | weekNumber = -1; | 601 | weekNumber = -1; |
601 | int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek(); | 602 | int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek(); |
602 | int dayOfWeek = d.dayOfWeek(); | 603 | int dayOfWeek = d.dayOfWeek(); |
603 | 604 | ||
604 | if ( !d.isValid() ) | 605 | if ( !d.isValid() ) |
605 | return false; | 606 | return false; |
606 | 607 | ||
607 | if ( startOnMonday ) { | 608 | if ( startOnMonday ) { |
608 | // find the Jan1Weekday; | 609 | // find the Jan1Weekday; |
609 | if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) { | 610 | if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) { |
610 | yearNumber = d.year() - 1; | 611 | yearNumber = d.year() - 1; |
611 | if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) | 612 | if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) |
612 | weekNumber = 53; | 613 | weekNumber = 53; |
613 | else | 614 | else |
614 | weekNumber = 52; | 615 | weekNumber = 52; |
615 | } else | 616 | } else |
616 | yearNumber = d.year(); | 617 | yearNumber = d.year(); |
617 | if ( yearNumber == d.year() ) { | 618 | if ( yearNumber == d.year() ) { |
618 | int totalDays = 365; | 619 | int totalDays = 365; |
619 | if ( QDate::leapYear(yearNumber) ) | 620 | if ( QDate::leapYear(yearNumber) ) |
620 | totalDays++; | 621 | totalDays++; |
621 | if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) ) | 622 | if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) ) |
622 | || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) { | 623 | || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) { |
623 | yearNumber++; | 624 | yearNumber++; |
624 | weekNumber = 1; | 625 | weekNumber = 1; |
625 | } | 626 | } |
626 | } | 627 | } |
627 | if ( yearNumber == d.year() ) { | 628 | if ( yearNumber == d.year() ) { |
628 | int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 ); | 629 | int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 ); |
629 | weekNumber = j / 7; | 630 | weekNumber = j / 7; |
630 | if ( jan1WeekDay > 4 ) | 631 | if ( jan1WeekDay > 4 ) |
631 | weekNumber--; | 632 | weekNumber--; |
632 | } | 633 | } |
633 | } else { | 634 | } else { |
634 | // it's better to keep these cases separate... | 635 | // it's better to keep these cases separate... |
635 | if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4 | 636 | if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4 |
636 | && jan1WeekDay != 7 ) { | 637 | && jan1WeekDay != 7 ) { |
637 | yearNumber = d.year() - 1; | 638 | yearNumber = d.year() - 1; |
638 | if ( jan1WeekDay == 6 | 639 | if ( jan1WeekDay == 6 |
639 | || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) { | 640 | || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) { |
640 | weekNumber = 53; | 641 | weekNumber = 53; |
641 | }else | 642 | }else |
642 | weekNumber = 52; | 643 | weekNumber = 52; |
643 | } else | 644 | } else |
644 | yearNumber = d.year(); | 645 | yearNumber = d.year(); |
645 | if ( yearNumber == d.year() ) { | 646 | if ( yearNumber == d.year() ) { |
646 | int totalDays = 365; | 647 | int totalDays = 365; |
647 | if ( QDate::leapYear( yearNumber ) ) | 648 | if ( QDate::leapYear( yearNumber ) ) |
648 | totalDays++; | 649 | totalDays++; |
649 | if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) { | 650 | if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) { |
650 | yearNumber++; | 651 | yearNumber++; |
651 | weekNumber = 1; | 652 | weekNumber = 1; |
652 | } | 653 | } |
653 | } | 654 | } |
654 | if ( yearNumber == d.year() ) { | 655 | if ( yearNumber == d.year() ) { |
655 | int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 ); | 656 | int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 ); |
656 | weekNumber = j / 7; | 657 | weekNumber = j / 7; |
657 | if ( jan1WeekDay > 4 ) { | 658 | if ( jan1WeekDay > 4 ) { |
658 | weekNumber--; | 659 | weekNumber--; |
659 | } | 660 | } |
660 | } | 661 | } |
661 | } | 662 | } |
662 | year = yearNumber; | 663 | year = yearNumber; |
663 | week = weekNumber; | 664 | week = weekNumber; |
664 | return true; | 665 | return true; |
665 | } | 666 | } |
666 | 667 | ||