Diffstat (limited to 'core/pim/datebook/datebookweek.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/datebook/datebookweek.cpp | 179 |
1 files changed, 76 insertions, 103 deletions
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp index 8241655..3ae4610 100644 --- a/core/pim/datebook/datebookweek.cpp +++ b/core/pim/datebook/datebookweek.cpp | |||
@@ -332,176 +332,162 @@ void DateBookWeekView::resizeEvent( QResizeEvent *e ) | |||
332 | setMargins( 0, header->height(), 0, 0 ); | 332 | setMargins( 0, header->height(), 0, 0 ); |
333 | header->resizeSection( 0, hourWidth ); | 333 | header->resizeSection( 0, hourWidth ); |
334 | int sw = (avail - hourWidth) / 7; | 334 | int sw = (avail - hourWidth) / 7; |
335 | for ( int i = 1; i < 7; i++ ) | 335 | for ( int i = 1; i < 7; i++ ) |
336 | header->resizeSection( i, sw ); | 336 | header->resizeSection( i, sw ); |
337 | header->resizeSection( 7, avail - hourWidth - sw*6 ); | 337 | header->resizeSection( 7, avail - hourWidth - sw*6 ); |
338 | } | 338 | } |
339 | 339 | ||
340 | void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) | 340 | void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) |
341 | { | 341 | { |
342 | bOnMonday = bStartOnMonday; | 342 | bOnMonday = bStartOnMonday; |
343 | initNames(); | 343 | initNames(); |
344 | } | 344 | } |
345 | 345 | ||
346 | //------------------------------------------------------------------- | 346 | //------------------------------------------------------------------- |
347 | 347 | ||
348 | DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, | 348 | DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, |
349 | QWidget *parent, const char *name ) | 349 | QWidget *parent, const char *name ) |
350 | : QWidget( parent, name ), | 350 | : QWidget( parent, name ), |
351 | db( newDB ), | 351 | db( newDB ), |
352 | startTime( 0 ), | 352 | startTime( 0 ), |
353 | ampm( ap ), | 353 | ampm( ap ), |
354 | bStartOnMonday( startOnMonday ) | 354 | bStartOnMonday( startOnMonday ) |
355 | { | 355 | { |
356 | setFocusPolicy(StrongFocus); | 356 | setFocusPolicy(StrongFocus); |
357 | QVBoxLayout *vb = new QVBoxLayout( this ); | 357 | QVBoxLayout *vb = new QVBoxLayout( this ); |
358 | header = new DateBookWeekHeader( bStartOnMonday, this ); | 358 | header = new DateBookWeekHeader( bStartOnMonday, this ); |
359 | view = new DateBookWeekView( ampm, startOnMonday, this ); | 359 | view = new DateBookWeekView( ampm, startOnMonday, this ); |
360 | vb->addWidget( header ); | 360 | vb->addWidget( header ); |
361 | vb->addWidget( view ); | 361 | vb->addWidget( view ); |
362 | 362 | ||
363 | lblDesc = new QLabel( this, "event label" ); | 363 | lblDesc = new QLabel( this, "event label" ); |
364 | lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); | 364 | lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); |
365 | lblDesc->setBackgroundColor( yellow ); | 365 | lblDesc->setBackgroundColor( yellow ); |
366 | lblDesc->hide(); | 366 | lblDesc->hide(); |
367 | 367 | ||
368 | tHide = new QTimer( this ); | 368 | tHide = new QTimer( this ); |
369 | 369 | ||
370 | connect( view, SIGNAL( showDay( int ) ), | 370 | connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) ); |
371 | this, SLOT( showDay( int ) ) ); | 371 | connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); |
372 | connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), | 372 | connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); |
373 | this, SLOT(slotShowEvent(const EffectiveEvent&)) ); | 373 | connect( header, SIGNAL( dateChanged( int, int ) ), this, SLOT( dateChanged( int, int ) ) ); |
374 | connect( view, SIGNAL(signalHideEvent()), | 374 | connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); |
375 | this, SLOT(slotHideEvent()) ); | 375 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); |
376 | connect( header, SIGNAL( dateChanged( int, int ) ), | 376 | connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); |
377 | this, SLOT( dateChanged( int, int ) ) ); | 377 | setDate(QDate::currentDate()); |
378 | connect( tHide, SIGNAL( timeout() ), | ||
379 | lblDesc, SLOT( hide() ) ); | ||
380 | connect( header->spinYear, SIGNAL(valueChanged(int)), | ||
381 | this, SLOT(slotYearChanged(int)) ); | ||
382 | connect( qApp, SIGNAL(weekChanged(bool)), | ||
383 | this, SLOT(slotWeekChanged(bool)) ); | ||
384 | connect( qApp, SIGNAL(clockChanged(bool)), | ||
385 | this, SLOT(slotClockChanged(bool))); | ||
386 | setDate(QDate::currentDate()); | ||
387 | |||
388 | } | 378 | } |
389 | 379 | ||
390 | void DateBookWeek::keyPressEvent(QKeyEvent *e) | 380 | void DateBookWeek::keyPressEvent(QKeyEvent *e) |
391 | { | 381 | { |
392 | switch(e->key()) { | 382 | switch(e->key()) { |
393 | case Key_Up: | 383 | case Key_Up: |
394 | view->scrollBy(0, -20); | 384 | view->scrollBy(0, -20); |
395 | break; | 385 | break; |
396 | case Key_Down: | 386 | case Key_Down: |
397 | view->scrollBy(0, 20); | 387 | view->scrollBy(0, 20); |
398 | break; | 388 | break; |
399 | case Key_Left: | 389 | case Key_Left: |
400 | setDate(date().addDays(-7)); | 390 | setDate(date().addDays(-7)); |
401 | break; | 391 | break; |
402 | case Key_Right: | 392 | case Key_Right: |
403 | setDate(date().addDays(7)); | 393 | setDate(date().addDays(7)); |
404 | break; | 394 | break; |
405 | default: | 395 | default: |
406 | e->ignore(); | 396 | e->ignore(); |
407 | } | 397 | } |
408 | } | 398 | } |
409 | 399 | ||
410 | void DateBookWeek::showDay( int day ) | 400 | void DateBookWeek::showDay( int day ) |
411 | { | 401 | { |
412 | QDate d; | 402 | QDate d; |
413 | d = dateFromWeek( _week, year, bStartOnMonday ); | 403 | d = dateFromWeek( _week, year, bStartOnMonday ); |
414 | day--; | 404 | day--; |
415 | d = d.addDays( day ); | 405 | d = d.addDays( day ); |
416 | emit showDate( d.year(), d.month(), d.day() ); | 406 | emit showDate( d.year(), d.month(), d.day() ); |
417 | } | 407 | } |
418 | 408 | ||
419 | void DateBookWeek::setDate( int y, int m, int d ) | 409 | void DateBookWeek::setDate( int y, int m, int d ) |
420 | { | 410 | { |
421 | QDate date; | 411 | setDate(QDate(y, m, d)); |
422 | date.setYMD( y, m, d ); | ||
423 | setDate(QDate(y, m, d)); | ||
424 | } | 412 | } |
425 | 413 | ||
426 | void DateBookWeek::setDate(QDate date) | 414 | void DateBookWeek::setDate(QDate date) |
427 | { | 415 | { |
428 | dow = date.dayOfWeek(); | 416 | dow = date.dayOfWeek(); |
429 | int w, y; | 417 | int w, y; |
430 | calcWeek( date, w, y, bStartOnMonday ); | 418 | calcWeek( date, w, y, bStartOnMonday ); |
431 | header->setDate( y, w ); | 419 | header->setDate( date ); |
432 | } | 420 | } |
433 | 421 | ||
434 | void DateBookWeek::dateChanged( int y, int w ) | 422 | void DateBookWeek::dateChanged( int y, int w ) |
435 | { | 423 | { |
436 | year = y; | 424 | year = y; |
437 | _week = w; | 425 | _week = w; |
438 | getEvents(); | 426 | getEvents(); |
439 | } | 427 | } |
440 | 428 | ||
441 | QDate DateBookWeek::date() const | 429 | QDate DateBookWeek::date() const |
442 | { | 430 | { |
443 | QDate d; | 431 | QDate d; |
444 | d = dateFromWeek( _week - 1, year, bStartOnMonday ); | 432 | d = dateFromWeek( _week - 1, year, bStartOnMonday ); |
445 | if ( bStartOnMonday ) | 433 | if ( bStartOnMonday ) |
446 | d = d.addDays( 7 + dow - 1 ); | 434 | d = d.addDays( 7 + dow - 1 ); |
447 | else { | 435 | else { |
448 | if ( dow == 7 ) | 436 | if ( dow == 7 ) |
449 | d = d.addDays( dow ); | 437 | d = d.addDays( dow ); |
450 | else | 438 | else |
451 | d = d.addDays( 7 + dow ); | 439 | d = d.addDays( 7 + dow ); |
452 | } | 440 | } |
453 | return d; | 441 | return d; |
454 | } | 442 | } |
455 | 443 | ||
456 | void DateBookWeek::getEvents() | 444 | void DateBookWeek::getEvents() |
457 | { | 445 | { |
458 | QDate startWeek = weekDate(); | 446 | QDate startWeek = weekDate(); |
459 | 447 | ||
460 | QDate endWeek = startWeek.addDays( 6 ); | 448 | QDate endWeek = startWeek.addDays( 6 ); |
461 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, | 449 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); |
462 | endWeek); | 450 | view->showEvents( eventList ); |
463 | view->showEvents( eventList ); | 451 | view->moveToHour( startTime ); |
464 | view->moveToHour( startTime ); | ||
465 | } | 452 | } |
466 | 453 | ||
467 | void DateBookWeek::generateAllDayTooltext( QString& text ) { | 454 | void DateBookWeek::generateAllDayTooltext( QString& text ) { |
468 | text += "<b>" + tr("This is an all day event.") + "</b><br>"; | 455 | text += "<b>" + tr("This is an all day event.") + "</b><br>"; |
469 | } | 456 | } |
470 | 457 | ||
471 | void DateBookWeek::generateNormalTooltext( QString& str, | 458 | void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) { |
472 | const EffectiveEvent &ev ) { | 459 | str += "<b>" + QObject::tr("Start") + "</b>: "; |
473 | str += "<b>" + QObject::tr("Start") + "</b>: "; | 460 | str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); |
474 | str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); | 461 | if( ev.startDate()!=ev.endDate() ) { |
475 | if( ev.startDate()!=ev.endDate() ) { | 462 | str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; |
476 | str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; | 463 | } |
477 | } | 464 | str += "<br>"; |
478 | str += "<br>"; | 465 | str += "<b>" + QObject::tr("End") + "</b>: "; |
479 | str += "<b>" + QObject::tr("End") + "</b>: "; | 466 | str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); |
480 | str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); | 467 | if( ev.startDate()!=ev.endDate() ) { |
481 | if( ev.startDate()!=ev.endDate() ) { | 468 | str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; |
482 | str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; | 469 | } |
483 | } | ||
484 | } | 470 | } |
485 | 471 | ||
486 | void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) | 472 | void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) |
487 | { | 473 | { |
488 | if ( tHide->isActive() ) | 474 | if ( tHide->isActive() ) |
489 | tHide->stop(); | 475 | tHide->stop(); |
490 | 476 | ||
491 | // why would someone use "<"? Oh well, fix it up... | 477 | // why would someone use "<"? Oh well, fix it up... |
492 | // I wonder what other things may be messed up... | 478 | // I wonder what other things may be messed up... |
493 | QString strDesc = ev.description(); | 479 | QString strDesc = ev.description(); |
494 | int where = strDesc.find( "<" ); | 480 | int where = strDesc.find( "<" ); |
495 | while ( where != -1 ) { | 481 | while ( where != -1 ) { |
496 | strDesc.remove( where, 1 ); | 482 | strDesc.remove( where, 1 ); |
497 | strDesc.insert( where, "<" ); | 483 | strDesc.insert( where, "<" ); |
498 | where = strDesc.find( "<", where ); | 484 | where = strDesc.find( "<", where ); |
499 | } | 485 | } |
500 | 486 | ||
501 | QString strCat; | 487 | QString strCat; |
502 | // ### FIX later... | 488 | // ### FIX later... |
503 | // QString strCat = ev.category(); | 489 | // QString strCat = ev.category(); |
504 | // where = strCat.find( "<" ); | 490 | // where = strCat.find( "<" ); |
505 | // while ( where != -1 ) { | 491 | // while ( where != -1 ) { |
506 | // strCat.remove( where, 1 ); | 492 | // strCat.remove( where, 1 ); |
507 | // strCat.insert( where, "<" ); | 493 | // strCat.insert( where, "<" ); |
@@ -545,82 +531,69 @@ void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) | |||
545 | 531 | ||
546 | void DateBookWeek::slotHideEvent() | 532 | void DateBookWeek::slotHideEvent() |
547 | { | 533 | { |
548 | tHide->start( 2000, true ); | 534 | tHide->start( 2000, true ); |
549 | } | 535 | } |
550 | 536 | ||
551 | void DateBookWeek::setStartViewTime( int startHere ) | 537 | void DateBookWeek::setStartViewTime( int startHere ) |
552 | { | 538 | { |
553 | startTime = startHere; | 539 | startTime = startHere; |
554 | view->moveToHour( startTime ); | 540 | view->moveToHour( startTime ); |
555 | } | 541 | } |
556 | 542 | ||
557 | int DateBookWeek::startViewTime() const | 543 | int DateBookWeek::startViewTime() const |
558 | { | 544 | { |
559 | return startTime; | 545 | return startTime; |
560 | } | 546 | } |
561 | 547 | ||
562 | void DateBookWeek::redraw() | 548 | void DateBookWeek::redraw() |
563 | { | 549 | { |
564 | getEvents(); | 550 | getEvents(); |
565 | } | 551 | } |
566 | 552 | ||
567 | void DateBookWeek::slotYearChanged( int y ) | 553 | void DateBookWeek::slotYearChanged( int y ) |
568 | { | 554 | { |
569 | int totWeek; | 555 | int totWeek; |
570 | QDate d( y, 12, 31 ); | 556 | QDate d( y, 12, 31 ); |
571 | int throwAway; | 557 | int throwAway; |
572 | calcWeek( d, totWeek, throwAway, bStartOnMonday ); | ||
573 | while ( totWeek == 1 ) { | ||
574 | d = d.addDays( -1 ); | ||
575 | calcWeek( d, totWeek, throwAway, bStartOnMonday ); | 558 | calcWeek( d, totWeek, throwAway, bStartOnMonday ); |
576 | } | 559 | while ( totWeek == 1 ) { |
577 | if ( totWeek != totalWeeks() ) | 560 | d = d.addDays( -1 ); |
578 | setTotalWeeks( totWeek ); | 561 | calcWeek( d, totWeek, throwAway, bStartOnMonday ); |
579 | } | 562 | } |
580 | |||
581 | |||
582 | void DateBookWeek::setTotalWeeks( int numWeeks ) | ||
583 | { | ||
584 | header->spinWeek->setMaxValue( numWeeks ); | ||
585 | } | ||
586 | |||
587 | int DateBookWeek::totalWeeks() const | ||
588 | { | ||
589 | return header->spinWeek->maxValue(); | ||
590 | } | 563 | } |
591 | 564 | ||
592 | void DateBookWeek::slotWeekChanged( bool onMonday ) | 565 | void DateBookWeek::slotWeekChanged( bool onMonday ) |
593 | { | 566 | { |
594 | bStartOnMonday = onMonday; | 567 | bStartOnMonday = onMonday; |
595 | view->setStartOfWeek( bStartOnMonday ); | 568 | view->setStartOfWeek( bStartOnMonday ); |
596 | header->setStartOfWeek( bStartOnMonday ); | 569 | header->setStartOfWeek( bStartOnMonday ); |
597 | redraw(); | 570 | redraw(); |
598 | } | 571 | } |
599 | 572 | ||
600 | void DateBookWeek::slotClockChanged( bool ap ) | 573 | void DateBookWeek::slotClockChanged( bool ap ) |
601 | { | 574 | { |
602 | ampm = ap; | 575 | ampm = ap; |
603 | } | 576 | } |
604 | 577 | ||
605 | // return the date at the beginning of the week... | 578 | // return the date at the beginning of the week... |
606 | QDate DateBookWeek::weekDate() const | 579 | QDate DateBookWeek::weekDate() const |
607 | { | 580 | { |
608 | return dateFromWeek( _week, year, bStartOnMonday ); | 581 | return dateFromWeek( _week, year, bStartOnMonday ); |
609 | } | 582 | } |
610 | 583 | ||
611 | // this used to only be needed by datebook.cpp, but now we need it inside | 584 | // this used to only be needed by datebook.cpp, but now we need it inside |
612 | // week view since | 585 | // week view since |
613 | // we need to be able to figure out our total number of weeks on the fly... | 586 | // we need to be able to figure out our total number of weeks on the fly... |
614 | // this is probably the best place to put it.. | 587 | // this is probably the best place to put it.. |
615 | 588 | ||
616 | // For Weeks that start on Monday... (EASY!) | 589 | // For Weeks that start on Monday... (EASY!) |
617 | // At the moment we will use ISO 8601 method for computing | 590 | // At the moment we will use ISO 8601 method for computing |
618 | // the week. Granted, other countries use other methods, | 591 | // the week. Granted, other countries use other methods, |
619 | // bet we aren't doing any Locale stuff at the moment. So, | 592 | // bet we aren't doing any Locale stuff at the moment. So, |
620 | // this should pass. This Algorithim is public domain and | 593 | // this should pass. This Algorithim is public domain and |
621 | // available at: | 594 | // available at: |
622 | // http://personal.ecu.edu/mccartyr/ISOwdALG.txt | 595 | // http://personal.ecu.edu/mccartyr/ISOwdALG.txt |
623 | // the week number is return, and the year number is returned in year | 596 | // the week number is return, and the year number is returned in year |
624 | // for Instance 2001/12/31 is actually the first week in 2002. | 597 | // for Instance 2001/12/31 is actually the first week in 2002. |
625 | // There is a more mathematical definition, but I will implement it when | 598 | // There is a more mathematical definition, but I will implement it when |
626 | // we are pass our deadline. | 599 | // we are pass our deadline. |