-rw-r--r-- | core/pim/datebook/datebookweek.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp index dad1c3f..8435132 100644 --- a/core/pim/datebook/datebookweek.cpp +++ b/core/pim/datebook/datebookweek.cpp | |||
@@ -220,254 +220,266 @@ DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) | |||
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 | |||
317 | #warning check the geometry i have choosen BRANCH_1_0 (waspe) | ||
318 | |||
319 | //HEAD | ||
320 | /* | ||
316 | int avail = visibleWidth(); | 321 | int avail = visibleWidth(); |
317 | header->setGeometry( leftMargin()+frameWidth()+frameRect().left() , frameWidth(), | 322 | header->setGeometry( leftMargin()+frameWidth()+frameRect().left() , frameWidth(), |
318 | visibleWidth(), header->sizeHint().height() ); | 323 | visibleWidth(), header->sizeHint().height() ); |
319 | setMargins( 0, header->sizeHint().height(), 0, 0 ); | 324 | setMargins( 0, header->sizeHint().height(), 0, 0 ); |
325 | */ | ||
326 | //BRANCH_1_0 | ||
327 | int avail = width()-qApp->style().scrollBarExtent().width()-1; | ||
328 | header->setGeometry( 0, 0, avail, header->sizeHint().height() ); | ||
329 | setMargins( 0, header->height(), 0, 0 ); | ||
330 | |||
331 | |||
320 | header->resizeSection( 0, hourWidth ); | 332 | header->resizeSection( 0, hourWidth ); |
321 | int sw = (avail - hourWidth) / 7; | 333 | int sw = (avail - hourWidth) / 7; |
322 | for ( int i = 1; i < 7; i++ ) | 334 | for ( int i = 1; i < 7; i++ ) |
323 | header->resizeSection( i, sw ); | 335 | header->resizeSection( i, sw ); |
324 | header->resizeSection( 7, avail - hourWidth - sw*6 ); | 336 | header->resizeSection( 7, avail - hourWidth - sw*6 ); |
325 | } | 337 | } |
326 | 338 | ||
327 | void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) | 339 | void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) |
328 | { | 340 | { |
329 | bOnMonday = bStartOnMonday; | 341 | bOnMonday = bStartOnMonday; |
330 | initNames(); | 342 | initNames(); |
331 | } | 343 | } |
332 | 344 | ||
333 | //------------------------------------------------------------------- | 345 | //------------------------------------------------------------------- |
334 | 346 | ||
335 | DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, | 347 | DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, |
336 | QWidget *parent, const char *name ) | 348 | QWidget *parent, const char *name ) |
337 | : QWidget( parent, name ), | 349 | : QWidget( parent, name ), |
338 | db( newDB ), | 350 | db( newDB ), |
339 | startTime( 0 ), | 351 | startTime( 0 ), |
340 | ampm( ap ), | 352 | ampm( ap ), |
341 | bStartOnMonday( startOnMonday ) | 353 | bStartOnMonday( startOnMonday ) |
342 | { | 354 | { |
343 | setFocusPolicy(StrongFocus); | 355 | setFocusPolicy(StrongFocus); |
344 | QVBoxLayout *vb = new QVBoxLayout( this ); | 356 | QVBoxLayout *vb = new QVBoxLayout( this ); |
345 | header = new DateBookWeekHeader( bStartOnMonday, this ); | 357 | header = new DateBookWeekHeader( bStartOnMonday, this ); |
346 | view = new DateBookWeekView( ampm, startOnMonday, this ); | 358 | view = new DateBookWeekView( ampm, startOnMonday, this ); |
347 | vb->addWidget( header ); | 359 | vb->addWidget( header ); |
348 | vb->addWidget( view ); | 360 | vb->addWidget( view ); |
349 | 361 | ||
350 | lblDesc = new QLabel( this, "event label" ); | 362 | lblDesc = new QLabel( this, "event label" ); |
351 | lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); | 363 | lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); |
352 | lblDesc->setBackgroundColor( yellow ); | 364 | lblDesc->setBackgroundColor( yellow ); |
353 | lblDesc->hide(); | 365 | lblDesc->hide(); |
354 | 366 | ||
355 | tHide = new QTimer( this ); | 367 | tHide = new QTimer( this ); |
356 | 368 | ||
357 | connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) ); | 369 | connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) ); |
358 | connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); | 370 | connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); |
359 | connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); | 371 | connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); |
360 | connect( header, SIGNAL( dateChanged( QDate &) ), this, SLOT( dateChanged( QDate &) ) ); | 372 | connect( header, SIGNAL( dateChanged( QDate &) ), this, SLOT( dateChanged( QDate &) ) ); |
361 | connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); | 373 | connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); |
362 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); | 374 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); |
363 | connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); | 375 | connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); |
364 | setDate(QDate::currentDate()); | 376 | setDate(QDate::currentDate()); |
365 | } | 377 | } |
366 | 378 | ||
367 | void DateBookWeek::keyPressEvent(QKeyEvent *e) | 379 | void DateBookWeek::keyPressEvent(QKeyEvent *e) |
368 | { | 380 | { |
369 | switch(e->key()) { | 381 | switch(e->key()) { |
370 | case Key_Up: | 382 | case Key_Up: |
371 | view->scrollBy(0, -20); | 383 | view->scrollBy(0, -20); |
372 | break; | 384 | break; |
373 | case Key_Down: | 385 | case Key_Down: |
374 | view->scrollBy(0, 20); | 386 | view->scrollBy(0, 20); |
375 | break; | 387 | break; |
376 | case Key_Left: | 388 | case Key_Left: |
377 | setDate(date().addDays(-7)); | 389 | setDate(date().addDays(-7)); |
378 | break; | 390 | break; |
379 | case Key_Right: | 391 | case Key_Right: |
380 | setDate(date().addDays(7)); | 392 | setDate(date().addDays(7)); |
381 | break; | 393 | break; |
382 | default: | 394 | default: |
383 | e->ignore(); | 395 | e->ignore(); |
384 | } | 396 | } |
385 | } | 397 | } |
386 | 398 | ||
387 | void DateBookWeek::showDay( int day ) | 399 | void DateBookWeek::showDay( int day ) |
388 | { | 400 | { |
389 | QDate d=bdate; | 401 | QDate d=bdate; |
390 | 402 | ||
391 | // Calculate offset to first day of week. | 403 | // Calculate offset to first day of week. |
392 | int dayoffset=d.dayOfWeek() % 7; | 404 | int dayoffset=d.dayOfWeek() % 7; |
393 | 405 | ||
394 | if(bStartOnMonday) dayoffset--; | 406 | if(bStartOnMonday) dayoffset--; |
395 | 407 | ||
396 | day--; | 408 | day--; |
397 | d=d.addDays(day-dayoffset); | 409 | d=d.addDays(day-dayoffset); |
398 | emit showDate( d.year(), d.month(), d.day() ); | 410 | emit showDate( d.year(), d.month(), d.day() ); |
399 | } | 411 | } |
400 | 412 | ||
401 | void DateBookWeek::setDate( int y, int m, int d ) | 413 | void DateBookWeek::setDate( int y, int m, int d ) |
402 | { | 414 | { |
403 | setDate(QDate(y, m, d)); | 415 | setDate(QDate(y, m, d)); |
404 | } | 416 | } |
405 | 417 | ||
406 | void DateBookWeek::setDate(QDate newdate) | 418 | void DateBookWeek::setDate(QDate newdate) |
407 | { | 419 | { |
408 | bdate=newdate; | 420 | bdate=newdate; |
409 | dow = newdate.dayOfWeek(); | 421 | dow = newdate.dayOfWeek(); |
410 | header->setDate( newdate ); | 422 | header->setDate( newdate ); |
411 | } | 423 | } |
412 | 424 | ||
413 | void DateBookWeek::dateChanged( QDate &newdate ) | 425 | void DateBookWeek::dateChanged( QDate &newdate ) |
414 | { | 426 | { |
415 | bdate=newdate; | 427 | bdate=newdate; |
416 | getEvents(); | 428 | getEvents(); |
417 | } | 429 | } |
418 | 430 | ||
419 | QDate DateBookWeek::date() const | 431 | QDate DateBookWeek::date() const |
420 | { | 432 | { |
421 | return bdate; | 433 | return bdate; |
422 | } | 434 | } |
423 | 435 | ||
424 | void DateBookWeek::getEvents() | 436 | void DateBookWeek::getEvents() |
425 | { | 437 | { |
426 | QDate startWeek = weekDate(); | 438 | QDate startWeek = weekDate(); |
427 | 439 | ||
428 | QDate endWeek = startWeek.addDays( 6 ); | 440 | QDate endWeek = startWeek.addDays( 6 ); |
429 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); | 441 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); |
430 | view->showEvents( eventList ); | 442 | view->showEvents( eventList ); |
431 | view->moveToHour( startTime ); | 443 | view->moveToHour( startTime ); |
432 | } | 444 | } |
433 | 445 | ||
434 | void DateBookWeek::generateAllDayTooltext( QString& text ) { | 446 | void DateBookWeek::generateAllDayTooltext( QString& text ) { |
435 | text += "<b>" + tr("This is an all day event.") + "</b><br>"; | 447 | text += "<b>" + tr("This is an all day event.") + "</b><br>"; |
436 | } | 448 | } |
437 | 449 | ||
438 | void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) { | 450 | void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) { |
439 | str += "<b>" + QObject::tr("Start") + "</b>: "; | 451 | str += "<b>" + QObject::tr("Start") + "</b>: "; |
440 | str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); | 452 | str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); |
441 | if( ev.startDate()!=ev.endDate() ) { | 453 | if( ev.startDate()!=ev.endDate() ) { |
442 | str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; | 454 | str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; |
443 | } | 455 | } |
444 | str += "<br>"; | 456 | str += "<br>"; |
445 | str += "<b>" + QObject::tr("End") + "</b>: "; | 457 | str += "<b>" + QObject::tr("End") + "</b>: "; |
446 | str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); | 458 | str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); |
447 | if( ev.startDate()!=ev.endDate() ) { | 459 | if( ev.startDate()!=ev.endDate() ) { |
448 | str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; | 460 | str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; |
449 | } | 461 | } |
450 | } | 462 | } |
451 | 463 | ||
452 | void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) | 464 | void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) |
453 | { | 465 | { |
454 | if ( tHide->isActive() ) | 466 | if ( tHide->isActive() ) |
455 | tHide->stop(); | 467 | tHide->stop(); |
456 | 468 | ||
457 | // why would someone use "<"? Oh well, fix it up... | 469 | // why would someone use "<"? Oh well, fix it up... |
458 | // I wonder what other things may be messed up... | 470 | // I wonder what other things may be messed up... |
459 | QString strDesc = ev.description(); | 471 | QString strDesc = ev.description(); |
460 | int where = strDesc.find( "<" ); | 472 | int where = strDesc.find( "<" ); |
461 | while ( where != -1 ) { | 473 | while ( where != -1 ) { |
462 | strDesc.remove( where, 1 ); | 474 | strDesc.remove( where, 1 ); |
463 | strDesc.insert( where, "<" ); | 475 | strDesc.insert( where, "<" ); |
464 | where = strDesc.find( "<", where ); | 476 | where = strDesc.find( "<", where ); |
465 | } | 477 | } |
466 | 478 | ||
467 | QString strCat; | 479 | QString strCat; |
468 | // ### FIX later... | 480 | // ### FIX later... |
469 | // QString strCat = ev.category(); | 481 | // QString strCat = ev.category(); |
470 | // where = strCat.find( "<" ); | 482 | // where = strCat.find( "<" ); |
471 | // while ( where != -1 ) { | 483 | // while ( where != -1 ) { |
472 | // strCat.remove( where, 1 ); | 484 | // strCat.remove( where, 1 ); |
473 | // strCat.insert( where, "<" ); | 485 | // strCat.insert( where, "<" ); |