-rw-r--r-- | library/datebookmonth.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/library/datebookmonth.cpp b/library/datebookmonth.cpp index 421559e..013ab66 100644 --- a/library/datebookmonth.cpp +++ b/library/datebookmonth.cpp | |||
@@ -422,323 +422,334 @@ void DateBookMonth::setDate( int y, int m ) | |||
422 | } | 422 | } |
423 | } | 423 | } |
424 | 424 | ||
425 | void DateBookMonth::setDate( int y, int m, int d ) | 425 | void DateBookMonth::setDate( int y, int m, int d ) |
426 | { | 426 | { |
427 | header->setDate( y, m); | 427 | header->setDate( y, m); |
428 | table->setDate( y, m, d); | 428 | table->setDate( y, m, d); |
429 | year = y; | 429 | year = y; |
430 | month = m; | 430 | month = m; |
431 | day = d; | 431 | day = d; |
432 | } | 432 | } |
433 | 433 | ||
434 | /* called when we wish to close or pass back the date */ | 434 | /* called when we wish to close or pass back the date */ |
435 | void DateBookMonth::finalDate(int y, int m, int d) | 435 | void DateBookMonth::finalDate(int y, int m, int d) |
436 | { | 436 | { |
437 | setDate( y, m, d ); | 437 | setDate( y, m, d ); |
438 | 438 | ||
439 | emit dateClicked(y, m, d); | 439 | emit dateClicked(y, m, d); |
440 | // emit dateClicked(QDate(y, m, d).toString()); | 440 | // emit dateClicked(QDate(y, m, d).toString()); |
441 | 441 | ||
442 | if ( autoClose && parentWidget() ) | 442 | if ( autoClose && parentWidget() ) |
443 | parentWidget()->close(); | 443 | parentWidget()->close(); |
444 | } | 444 | } |
445 | 445 | ||
446 | void DateBookMonth::setDate( QDate d) | 446 | void DateBookMonth::setDate( QDate d) |
447 | { | 447 | { |
448 | setDate(d.year(), d.month(), d.day()); | 448 | setDate(d.year(), d.month(), d.day()); |
449 | } | 449 | } |
450 | 450 | ||
451 | void DateBookMonth::redraw() | 451 | void DateBookMonth::redraw() |
452 | { | 452 | { |
453 | table->setDate( year, month, day ); | 453 | table->setDate( year, month, day ); |
454 | table->redraw(); | 454 | table->redraw(); |
455 | } | 455 | } |
456 | 456 | ||
457 | QDate DateBookMonth::selectedDate() const | 457 | QDate DateBookMonth::selectedDate() const |
458 | { | 458 | { |
459 | if ( !table ) | 459 | if ( !table ) |
460 | return QDate::currentDate(); | 460 | return QDate::currentDate(); |
461 | int y, m, d; | 461 | int y, m, d; |
462 | table->getDate( y, m, d ); | 462 | table->getDate( y, m, d ); |
463 | return QDate( y, m, d ); | 463 | return QDate( y, m, d ); |
464 | } | 464 | } |
465 | 465 | ||
466 | void DateBookMonth::slotWeekChange( bool startOnMonday ) | 466 | void DateBookMonth::slotWeekChange( bool startOnMonday ) |
467 | { | 467 | { |
468 | table->setWeekStart( startOnMonday ); | 468 | table->setWeekStart( startOnMonday ); |
469 | } | 469 | } |
470 | 470 | ||
471 | void DateBookMonth::keyPressEvent( QKeyEvent *e ) | 471 | void DateBookMonth::keyPressEvent( QKeyEvent *e ) |
472 | { | 472 | { |
473 | switch(e->key()) { | 473 | switch(e->key()) { |
474 | case Key_Up: | 474 | case Key_Up: |
475 | setDate(QDate(year, month, day).addDays(-7)); | 475 | setDate(QDate(year, month, day).addDays(-7)); |
476 | break; | 476 | break; |
477 | case Key_Down: | 477 | case Key_Down: |
478 | setDate(QDate(year, month, day).addDays(7)); | 478 | setDate(QDate(year, month, day).addDays(7)); |
479 | break; | 479 | break; |
480 | case Key_Left: | 480 | case Key_Left: |
481 | setDate(QDate(year, month, day).addDays(-1)); | 481 | setDate(QDate(year, month, day).addDays(-1)); |
482 | break; | 482 | break; |
483 | case Key_Right: | 483 | case Key_Right: |
484 | setDate(QDate(year, month, day).addDays(1)); | 484 | setDate(QDate(year, month, day).addDays(1)); |
485 | break; | 485 | break; |
486 | case Key_Space: | 486 | case Key_Space: |
487 | qWarning("space"); | 487 | qWarning("space"); |
488 | emit dateClicked(year, month, day); | 488 | emit dateClicked(year, month, day); |
489 | if ( autoClose && parentWidget() ) | 489 | if ( autoClose && parentWidget() ) |
490 | parentWidget()->close(); | 490 | parentWidget()->close(); |
491 | break; | 491 | break; |
492 | default: | 492 | default: |
493 | qWarning("ignore"); | 493 | qWarning("ignore"); |
494 | e->ignore(); | 494 | e->ignore(); |
495 | break; | 495 | break; |
496 | } | 496 | } |
497 | } | 497 | } |
498 | 498 | ||
499 | //--------------------------------------------------------------------------- | 499 | //--------------------------------------------------------------------------- |
500 | class DayItemMonthPrivate | 500 | class DayItemMonthPrivate |
501 | { | 501 | { |
502 | public: | 502 | public: |
503 | DayItemMonthPrivate() {}; | 503 | DayItemMonthPrivate() {}; |
504 | ~DayItemMonthPrivate() { mDayEvents.clear(); }; | 504 | ~DayItemMonthPrivate() { mDayEvents.clear(); }; |
505 | QValueList<EffectiveEvent> mDayEvents; | 505 | QValueList<EffectiveEvent> mDayEvents; |
506 | }; | 506 | }; |
507 | 507 | ||
508 | DayItemMonth::DayItemMonth( QTable *table, EditType et, const QString &t ) | 508 | DayItemMonth::DayItemMonth( QTable *table, EditType et, const QString &t ) |
509 | : QTableItem( table, et, t ) | 509 | : QTableItem( table, et, t ) |
510 | { | 510 | { |
511 | d = new DayItemMonthPrivate(); | 511 | d = new DayItemMonthPrivate(); |
512 | } | 512 | } |
513 | 513 | ||
514 | DayItemMonth::~DayItemMonth() | 514 | DayItemMonth::~DayItemMonth() |
515 | { | 515 | { |
516 | daysEvents.clear(); | 516 | daysEvents.clear(); |
517 | delete d; | 517 | delete d; |
518 | } | 518 | } |
519 | 519 | ||
520 | void DayItemMonth::setEvents( const QValueList<EffectiveEvent> &effEv ) | 520 | void DayItemMonth::setEvents( const QValueList<EffectiveEvent> &effEv ) |
521 | { | 521 | { |
522 | d->mDayEvents = effEv; | 522 | d->mDayEvents = effEv; |
523 | } | 523 | } |
524 | 524 | ||
525 | void DayItemMonth::clearEffEvents() | 525 | void DayItemMonth::clearEffEvents() |
526 | { | 526 | { |
527 | d->mDayEvents.clear(); | 527 | d->mDayEvents.clear(); |
528 | } | 528 | } |
529 | 529 | ||
530 | void DayItemMonth::paint( QPainter *p, const QColorGroup &cg, | 530 | void DayItemMonth::paint( QPainter *p, const QColorGroup &cg, |
531 | const QRect &cr, bool selected ) | 531 | const QRect &cr, bool selected ) |
532 | { | 532 | { |
533 | p->save(); | 533 | p->save(); |
534 | 534 | ||
535 | QColorGroup g( cg ); | 535 | QColorGroup g( cg ); |
536 | g.setBrush( QColorGroup::Base, back ); | 536 | g.setBrush( QColorGroup::Base, back ); |
537 | g.setColor( QColorGroup::Text, forg ); | 537 | g.setColor( QColorGroup::Text, forg ); |
538 | if ( selected ) | 538 | if ( selected ) |
539 | p->setPen( g.highlightedText() ); | 539 | p->setPen( g.highlightedText() ); |
540 | else | 540 | else |
541 | p->setPen( g.text() ); | 541 | p->setPen( g.text() ); |
542 | 542 | ||
543 | QValueStack<int> normalLine; | 543 | QValueStack<int> normalLine; |
544 | QValueStack<int> repeatLine; | 544 | QValueStack<int> repeatLine; |
545 | QValueStack<int> travelLine; | 545 | QValueStack<int> travelLine; |
546 | 546 | ||
547 | bool normalAllDay = FALSE; | 547 | bool normalAllDay = FALSE; |
548 | bool repeatAllDay = FALSE; | 548 | bool repeatAllDay = FALSE; |
549 | bool travelAllDay = FALSE; | 549 | bool travelAllDay = FALSE; |
550 | bool holidayAllDay = FALSE; | ||
550 | 551 | ||
551 | QValueListIterator<EffectiveEvent> itDays = d->mDayEvents.begin(); | 552 | QValueListIterator<EffectiveEvent> itDays = d->mDayEvents.begin(); |
552 | 553 | ||
553 | for ( ; itDays != d->mDayEvents.end(); ++itDays ) { | 554 | for ( ; itDays != d->mDayEvents.end(); ++itDays ) { |
554 | int w = cr.width(); | 555 | int w = cr.width(); |
555 | Event ev = (*itDays).event(); | 556 | Event ev = (*itDays).event(); |
556 | 557 | ||
557 | int f = (*itDays).start().hour(); // assume Effective event | 558 | int f = (*itDays).start().hour(); // assume Effective event |
558 | int t = (*itDays).end().hour(); // is truncated. | 559 | int t = (*itDays).end().hour(); // is truncated. |
559 | 560 | ||
560 | if (ev.isAllDay()) { | 561 | if (ev.isAllDay()) { |
561 | if (!ev.hasRepeat()) | 562 | if (!ev.hasRepeat()) { |
562 | normalAllDay = TRUE; | 563 | normalAllDay = TRUE; |
563 | else | 564 | if (!ev.isValidUid()) { |
564 | repeatAllDay = TRUE; | 565 | holidayAllDay = TRUE; |
566 | } | ||
567 | } else { | ||
568 | repeatAllDay = TRUE; | ||
569 | } | ||
565 | } else { | 570 | } else { |
566 | int sLine, eLine; | 571 | int sLine, eLine; |
567 | if (f == 0) | 572 | if (f == 0) |
568 | sLine = 0; | 573 | sLine = 0; |
569 | else if (f < 8 ) | 574 | else if (f < 8 ) |
570 | sLine = 1; | 575 | sLine = 1; |
571 | else if (f >= 17) | 576 | else if (f >= 17) |
572 | sLine = w - 4; | 577 | sLine = w - 4; |
573 | else { | 578 | else { |
574 | sLine = (f - 8) * (w - 8); | 579 | sLine = (f - 8) * (w - 8); |
575 | if (sLine) | 580 | if (sLine) |
576 | sLine /= 8; | 581 | sLine /= 8; |
577 | sLine += 4; | 582 | sLine += 4; |
578 | } | 583 | } |
579 | if (t == 23) | 584 | if (t == 23) |
580 | eLine = w; | 585 | eLine = w; |
581 | else if (t < 8) | 586 | else if (t < 8) |
582 | eLine = 4; | 587 | eLine = 4; |
583 | else if (t >= 17) | 588 | else if (t >= 17) |
584 | eLine = w - 1; | 589 | eLine = w - 1; |
585 | else { | 590 | else { |
586 | eLine = (t - 8) * (w - 8); | 591 | eLine = (t - 8) * (w - 8); |
587 | if (eLine) | 592 | if (eLine) |
588 | eLine /= 8; | 593 | eLine /= 8; |
589 | eLine += 4; | 594 | eLine += 4; |
590 | } | 595 | } |
591 | if (!ev.hasRepeat()) { | 596 | if (!ev.hasRepeat()) { |
592 | normalLine.push(sLine); | 597 | normalLine.push(sLine); |
593 | normalLine.push(eLine); | 598 | normalLine.push(eLine); |
594 | } else { | 599 | } else { |
595 | repeatLine.push(sLine); | 600 | repeatLine.push(sLine); |
596 | repeatLine.push(eLine); | 601 | repeatLine.push(eLine); |
597 | } | 602 | } |
598 | } | 603 | } |
599 | } | 604 | } |
600 | 605 | ||
601 | // draw the background | 606 | // draw the background |
602 | if (normalAllDay || repeatAllDay || travelAllDay) { | 607 | if (normalAllDay || repeatAllDay || travelAllDay || holidayAllDay) { |
603 | p->save(); | 608 | p->save(); |
604 | 609 | ||
605 | if (normalAllDay) | 610 | if (normalAllDay) |
606 | if (repeatAllDay) { | 611 | if (repeatAllDay) { |
607 | p->fillRect( 0, 0, cr.width(), cr.height() / 2, | 612 | p->fillRect( 0, 0, cr.width(), cr.height() / 2, |
608 | colorNormalLight ); | 613 | colorNormalLight ); |
609 | p->fillRect( 0, cr.height() / 2, cr.width(), cr.height() / 2, | 614 | p->fillRect( 0, cr.height() / 2, cr.width(), cr.height() / 2, |
610 | colorRepeatLight ); | 615 | colorRepeatLight ); |
611 | } else | 616 | } else { |
617 | if (!holidayAllDay) { | ||
612 | p->fillRect( 0, 0, cr.width(), cr.height(), | 618 | p->fillRect( 0, 0, cr.width(), cr.height(), |
613 | colorNormalLight ); | 619 | colorNormalLight ); |
614 | else if (repeatAllDay) | 620 | } else { |
621 | p->fillRect( 0, 0, cr.width(), cr.height(), | ||
622 | QColor(0,220,0) ); | ||
623 | } | ||
624 | } else if (repeatAllDay) { | ||
615 | p->fillRect( 0, 0, cr.width(), cr.height(), | 625 | p->fillRect( 0, 0, cr.width(), cr.height(), |
616 | colorRepeatLight ); | 626 | colorRepeatLight ); |
627 | } | ||
617 | } else { | 628 | } else { |
618 | p->fillRect( 0, 0, cr.width(), | 629 | p->fillRect( 0, 0, cr.width(), |
619 | cr.height(), selected | 630 | cr.height(), selected |
620 | ? g.brush( QColorGroup::Highlight ) | 631 | ? g.brush( QColorGroup::Highlight ) |
621 | : g.brush( QColorGroup::Base ) ); | 632 | : g.brush( QColorGroup::Base ) ); |
622 | } | 633 | } |
623 | 634 | ||
624 | // The lines | 635 | // The lines |
625 | // now for the lines. | 636 | // now for the lines. |
626 | int h = 5; | 637 | int h = 5; |
627 | int y = cr.height() / 2 - h; | 638 | int y = cr.height() / 2 - h; |
628 | 639 | ||
629 | while(normalLine.count() >= 2) { | 640 | while(normalLine.count() >= 2) { |
630 | int x2 = normalLine.pop(); | 641 | int x2 = normalLine.pop(); |
631 | int x1 = normalLine.pop(); | 642 | int x1 = normalLine.pop(); |
632 | if (x2 < x1 + 2) | 643 | if (x2 < x1 + 2) |
633 | x2 = x1 + 2; | 644 | x2 = x1 + 2; |
634 | p->fillRect(x1, y, x2 - x1, h, colorNormal); | 645 | p->fillRect(x1, y, x2 - x1, h, colorNormal); |
635 | } | 646 | } |
636 | 647 | ||
637 | y += h; | 648 | y += h; |
638 | 649 | ||
639 | while(repeatLine.count() >= 2) { | 650 | while(repeatLine.count() >= 2) { |
640 | int x2 = repeatLine.pop(); | 651 | int x2 = repeatLine.pop(); |
641 | int x1 = repeatLine.pop(); | 652 | int x1 = repeatLine.pop(); |
642 | if (x2 < x1 + 2) | 653 | if (x2 < x1 + 2) |
643 | x2 = x1 + 2; | 654 | x2 = x1 + 2; |
644 | p->fillRect(x1, y, x2 - x1, h, colorRepeat); | 655 | p->fillRect(x1, y, x2 - x1, h, colorRepeat); |
645 | } | 656 | } |
646 | 657 | ||
647 | 658 | ||
648 | // Finally, draw the number. | 659 | // Finally, draw the number. |
649 | QFont f = p->font(); | 660 | QFont f = p->font(); |
650 | f.setPointSize( ( f.pointSize() / 3 ) * 2 ); | 661 | f.setPointSize( ( f.pointSize() / 3 ) * 2 ); |
651 | p->setFont( f ); | 662 | p->setFont( f ); |
652 | QFontMetrics fm( f ); | 663 | QFontMetrics fm( f ); |
653 | p->drawText( 1, 1 + fm.ascent(), QString::number( day() ) ); | 664 | p->drawText( 1, 1 + fm.ascent(), QString::number( day() ) ); |
654 | 665 | ||
655 | p->restore(); | 666 | p->restore(); |
656 | } | 667 | } |
657 | 668 | ||
658 | 669 | ||
659 | 670 | ||
660 | void DayItemMonth::setType( Calendar::Day::Type t ) | 671 | void DayItemMonth::setType( Calendar::Day::Type t ) |
661 | { | 672 | { |
662 | switch ( t ) { | 673 | switch ( t ) { |
663 | case Calendar::Day::PrevMonth: | 674 | case Calendar::Day::PrevMonth: |
664 | case Calendar::Day::NextMonth: | 675 | case Calendar::Day::NextMonth: |
665 | back = QBrush( QColor( 224, 224, 224 ) ); | 676 | back = QBrush( QColor( 224, 224, 224 ) ); |
666 | forg = black; | 677 | forg = black; |
667 | break; | 678 | break; |
668 | case Calendar::Day::ThisMonth: | 679 | case Calendar::Day::ThisMonth: |
669 | back = QBrush( white ); | 680 | back = QBrush( white ); |
670 | forg = black; | 681 | forg = black; |
671 | break; | 682 | break; |
672 | } | 683 | } |
673 | typ = t; | 684 | typ = t; |
674 | } | 685 | } |
675 | 686 | ||
676 | 687 | ||
677 | 688 | ||
678 | DateButton::DateButton( bool longDate, QWidget *parent, const char * name ) | 689 | DateButton::DateButton( bool longDate, QWidget *parent, const char * name ) |
679 | :QPushButton( parent, name ) | 690 | :QPushButton( parent, name ) |
680 | { | 691 | { |
681 | longFormat = longDate; | 692 | longFormat = longDate; |
682 | df = DateFormat('/', DateFormat::MonthDayYear, DateFormat::MonthDayYear); | 693 | df = DateFormat('/', DateFormat::MonthDayYear, DateFormat::MonthDayYear); |
683 | setDate( QDate::currentDate() ); | 694 | setDate( QDate::currentDate() ); |
684 | 695 | ||
685 | connect(this,SIGNAL(pressed()),this,SLOT(pickDate())); | 696 | connect(this,SIGNAL(pressed()),this,SLOT(pickDate())); |
686 | 697 | ||
687 | 698 | ||
688 | } | 699 | } |
689 | 700 | ||
690 | 701 | ||
691 | void DateButton::pickDate() | 702 | void DateButton::pickDate() |
692 | { | 703 | { |
693 | static QPopupMenu *m1 = 0; | 704 | static QPopupMenu *m1 = 0; |
694 | static DateBookMonth *picker = 0; | 705 | static DateBookMonth *picker = 0; |
695 | if ( !m1 ) { | 706 | if ( !m1 ) { |
696 | m1 = new QPopupMenu( this ); | 707 | m1 = new QPopupMenu( this ); |
697 | picker = new DateBookMonth( m1, 0, TRUE ); | 708 | picker = new DateBookMonth( m1, 0, TRUE ); |
698 | m1->insertItem( picker ); | 709 | m1->insertItem( picker ); |
699 | connect( picker, SIGNAL( dateClicked(int,int,int) ), | 710 | connect( picker, SIGNAL( dateClicked(int,int,int) ), |
700 | this, SLOT( setDate(int,int,int) ) ); | 711 | this, SLOT( setDate(int,int,int) ) ); |
701 | connect( picker, SIGNAL( dateClicked(int,int,int) ), | 712 | connect( picker, SIGNAL( dateClicked(int,int,int) ), |
702 | this, SIGNAL( dateSelected(int,int,int) ) ); | 713 | this, SIGNAL( dateSelected(int,int,int) ) ); |
703 | connect( m1, SIGNAL( aboutToHide() ), | 714 | connect( m1, SIGNAL( aboutToHide() ), |
704 | this, SLOT( gotHide() ) ); | 715 | this, SLOT( gotHide() ) ); |
705 | } | 716 | } |
706 | picker->slotWeekChange( weekStartsMonday ); | 717 | picker->slotWeekChange( weekStartsMonday ); |
707 | picker->setDate( currDate.year(), currDate.month(), currDate.day() ); | 718 | picker->setDate( currDate.year(), currDate.month(), currDate.day() ); |
708 | m1->popup(mapToGlobal(QPoint(0,height()))); | 719 | m1->popup(mapToGlobal(QPoint(0,height()))); |
709 | picker->setFocus(); | 720 | picker->setFocus(); |
710 | } | 721 | } |
711 | 722 | ||
712 | 723 | ||
713 | void DateButton::gotHide() | 724 | void DateButton::gotHide() |
714 | { | 725 | { |
715 | // we have to redo the button... | 726 | // we have to redo the button... |
716 | setDown( false ); | 727 | setDown( false ); |
717 | } | 728 | } |
718 | 729 | ||
719 | 730 | ||
720 | // void dateSelected( int year, int month, int day ); | 731 | // void dateSelected( int year, int month, int day ); |
721 | 732 | ||
722 | void DateButton::setWeekStartsMonday( int b ) | 733 | void DateButton::setWeekStartsMonday( int b ) |
723 | { | 734 | { |
724 | weekStartsMonday = b; | 735 | weekStartsMonday = b; |
725 | } | 736 | } |
726 | 737 | ||
727 | void DateButton::setDate( int y, int m, int d ) | 738 | void DateButton::setDate( int y, int m, int d ) |
728 | { | 739 | { |
729 | setDate( QDate( y,m,d) ); | 740 | setDate( QDate( y,m,d) ); |
730 | } | 741 | } |
731 | 742 | ||
732 | void DateButton::setDate( QDate d ) | 743 | void DateButton::setDate( QDate d ) |
733 | { | 744 | { |
734 | currDate = d; | 745 | currDate = d; |
735 | setText( longFormat ? TimeString::longDateString( d, df ) : | 746 | setText( longFormat ? TimeString::longDateString( d, df ) : |
736 | TimeString::shortDate( d, df ) ); | 747 | TimeString::shortDate( d, df ) ); |
737 | 748 | ||
738 | } | 749 | } |
739 | 750 | ||
740 | void DateButton::setDateFormat( DateFormat f ) | 751 | void DateButton::setDateFormat( DateFormat f ) |
741 | { | 752 | { |
742 | df = f; | 753 | df = f; |
743 | setDate( currDate ); | 754 | setDate( currDate ); |
744 | } | 755 | } |