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