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