-rw-r--r-- | library/datebookmonth.cpp | 203 |
1 files changed, 120 insertions, 83 deletions
diff --git a/library/datebookmonth.cpp b/library/datebookmonth.cpp index f4b3e6b..272c223 100644 --- a/library/datebookmonth.cpp +++ b/library/datebookmonth.cpp | |||
@@ -1,12 +1,12 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
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. |
@@ -15,63 +15,69 @@ | |||
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 "config.h" | 20 | #include "config.h" |
21 | #include "datebookmonth.h" | 21 | #include "datebookmonth.h" |
22 | #include "datebookdb.h" | 22 | #include "datebookdb.h" |
23 | #include <qpe/event.h> | 23 | #include <qtopia/private/event.h> |
24 | #include "resource.h" | 24 | #include "resource.h" |
25 | #include "qpeapplication.h" | 25 | #include "qpeapplication.h" |
26 | #include "timestring.h" | 26 | #include "timestring.h" |
27 | 27 | ||
28 | #include <qtoolbutton.h> | 28 | #include <qtoolbutton.h> |
29 | #include <qspinbox.h> | 29 | #include <qspinbox.h> |
30 | #include <qcombobox.h> | 30 | #include <qcombobox.h> |
31 | #include <qdatetime.h> | 31 | #include <qdatetime.h> |
32 | #include <qpainter.h> | 32 | #include <qpainter.h> |
33 | #include <qpopupmenu.h> | 33 | #include <qpopupmenu.h> |
34 | #include <qvaluestack.h> | ||
35 | #include <qwhatsthis.h> | ||
34 | 36 | ||
35 | 37 | ||
36 | DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name ) | 38 | DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name ) |
37 | : QHBox( parent, name ) | 39 | : QHBox( parent, name ) |
38 | { | 40 | { |
39 | setBackgroundMode( PaletteButton ); | 41 | setBackgroundMode( PaletteButton ); |
40 | 42 | ||
41 | begin = new QToolButton( this ); | 43 | begin = new QToolButton( this ); |
42 | begin->setFocusPolicy(NoFocus); | 44 | begin->setFocusPolicy(NoFocus); |
43 | begin->setPixmap( Resource::loadPixmap( "start" ) ); | 45 | begin->setPixmap( Resource::loadPixmap( "start" ) ); |
44 | begin->setAutoRaise( TRUE ); | 46 | begin->setAutoRaise( TRUE ); |
45 | begin->setFixedSize( begin->sizeHint() ); | 47 | begin->setFixedSize( begin->sizeHint() ); |
48 | QWhatsThis::add( begin, tr("Show January in the selected year") ); | ||
46 | 49 | ||
47 | back = new QToolButton( this ); | 50 | back = new QToolButton( this ); |
48 | back->setFocusPolicy(NoFocus); | 51 | back->setFocusPolicy(NoFocus); |
49 | back->setPixmap( Resource::loadPixmap( "back" ) ); | 52 | back->setPixmap( Resource::loadPixmap( "back" ) ); |
50 | back->setAutoRaise( TRUE ); | 53 | back->setAutoRaise( TRUE ); |
51 | back->setFixedSize( back->sizeHint() ); | 54 | back->setFixedSize( back->sizeHint() ); |
55 | QWhatsThis::add( back, tr("Show the previous month") ); | ||
52 | 56 | ||
53 | month = new QComboBox( FALSE, this ); | 57 | month = new QComboBox( FALSE, this ); |
54 | for ( int i = 0; i < 12; ++i ) | 58 | for ( int i = 0; i < 12; ++i ) |
55 | month->insertItem( Calendar::nameOfMonth( i + 1 ) ); | 59 | month->insertItem( Calendar::nameOfMonth( i + 1 ) ); |
56 | 60 | ||
57 | year = new QSpinBox( 1752, 8000, 1, this ); | 61 | year = new QSpinBox( 1752, 8000, 1, this ); |
58 | 62 | ||
59 | next = new QToolButton( this ); | 63 | next = new QToolButton( this ); |
60 | next->setFocusPolicy(NoFocus); | 64 | next->setFocusPolicy(NoFocus); |
61 | next->setPixmap( Resource::loadPixmap( "forward" ) ); | 65 | next->setPixmap( Resource::loadPixmap( "forward" ) ); |
62 | next->setAutoRaise( TRUE ); | 66 | next->setAutoRaise( TRUE ); |
63 | next->setFixedSize( next->sizeHint() ); | 67 | next->setFixedSize( next->sizeHint() ); |
68 | QWhatsThis::add( next, tr("Show the next month") ); | ||
64 | 69 | ||
65 | end = new QToolButton( this ); | 70 | end = new QToolButton( this ); |
66 | end->setFocusPolicy(NoFocus); | 71 | end->setFocusPolicy(NoFocus); |
67 | end->setPixmap( Resource::loadPixmap( "finish" ) ); | 72 | end->setPixmap( Resource::loadPixmap( "finish" ) ); |
68 | end->setAutoRaise( TRUE ); | 73 | end->setAutoRaise( TRUE ); |
69 | end->setFixedSize( end->sizeHint() ); | 74 | end->setFixedSize( end->sizeHint() ); |
75 | QWhatsThis::add( end, tr("Show December in the selected year") ); | ||
70 | 76 | ||
71 | connect( month, SIGNAL( activated( int ) ), | 77 | connect( month, SIGNAL( activated( int ) ), |
72 | this, SLOT( updateDate() ) ); | 78 | this, SLOT( updateDate() ) ); |
73 | connect( year, SIGNAL( valueChanged( int ) ), | 79 | connect( year, SIGNAL( valueChanged( int ) ), |
74 | this, SLOT( updateDate() ) ); | 80 | this, SLOT( updateDate() ) ); |
75 | connect( begin, SIGNAL( clicked() ), | 81 | connect( begin, SIGNAL( clicked() ), |
76 | this, SLOT( firstMonth() ) ); | 82 | this, SLOT( firstMonth() ) ); |
77 | connect( end, SIGNAL( clicked() ), | 83 | connect( end, SIGNAL( clicked() ), |
@@ -449,17 +455,16 @@ void DateBookMonth::redraw() | |||
449 | } | 455 | } |
450 | 456 | ||
451 | QDate DateBookMonth::selectedDate() const | 457 | QDate DateBookMonth::selectedDate() const |
452 | { | 458 | { |
453 | if ( !table ) | 459 | if ( !table ) |
454 | return QDate::currentDate(); | 460 | return QDate::currentDate(); |
455 | int y, m, d; | 461 | int y, m, d; |
456 | table->getDate( y, m, d ); | 462 | table->getDate( y, m, d ); |
457 | qDebug( "got %d %d %d", y, m, d ); | ||
458 | return QDate( y, m, d ); | 463 | return QDate( y, m, d ); |
459 | } | 464 | } |
460 | 465 | ||
461 | void DateBookMonth::slotWeekChange( bool startOnMonday ) | 466 | void DateBookMonth::slotWeekChange( bool startOnMonday ) |
462 | { | 467 | { |
463 | table->setWeekStart( startOnMonday ); | 468 | table->setWeekStart( startOnMonday ); |
464 | } | 469 | } |
465 | 470 | ||
@@ -520,113 +525,139 @@ void DayItemMonth::setEvents( const QValueList<EffectiveEvent> &effEv ) | |||
520 | void DayItemMonth::clearEffEvents() | 525 | void DayItemMonth::clearEffEvents() |
521 | { | 526 | { |
522 | d->mDayEvents.clear(); | 527 | d->mDayEvents.clear(); |
523 | } | 528 | } |
524 | 529 | ||
525 | void DayItemMonth::paint( QPainter *p, const QColorGroup &cg, | 530 | void DayItemMonth::paint( QPainter *p, const QColorGroup &cg, |
526 | const QRect &cr, bool selected ) | 531 | const QRect &cr, bool selected ) |
527 | { | 532 | { |
533 | p->save(); | ||
534 | |||
528 | QColorGroup g( cg ); | 535 | QColorGroup g( cg ); |
529 | g.setBrush( QColorGroup::Base, back ); | 536 | g.setBrush( QColorGroup::Base, back ); |
530 | g.setColor( QColorGroup::Text, forg ); | 537 | g.setColor( QColorGroup::Text, forg ); |
531 | p->fillRect( 0, 0, cr.width(), cr.height(), selected ? g.brush( QColorGroup::Highlight ) : g.brush( QColorGroup::Base ) ); | ||
532 | |||
533 | if ( selected ) | 538 | if ( selected ) |
534 | p->setPen( g.highlightedText() ); | 539 | p->setPen( g.highlightedText() ); |
535 | else | 540 | else |
536 | p->setPen( g.text() ); | 541 | p->setPen( g.text() ); |
537 | 542 | ||
538 | p->save(); | 543 | QValueStack<int> normalLine; |
539 | QFont f = p->font(); | 544 | QValueStack<int> repeatLine; |
540 | f.setPointSize( ( f.pointSize() / 3 ) * 2 ); | 545 | QValueStack<int> travelLine; |
541 | p->setFont( f ); | 546 | |
542 | QFontMetrics fm( f ); | 547 | bool normalAllDay = FALSE; |
543 | p->drawText( 1, 1 + fm.ascent(), QString::number( day() ) ); | 548 | bool repeatAllDay = FALSE; |
544 | p->restore(); | 549 | bool travelAllDay = FALSE; |
545 | // Put indicators for something like this, (similar to PalmOS) | 550 | |
546 | // Before noon: item at top of the day | ||
547 | // At noon: put a small item at the middle | ||
548 | // After noon: put an indicator at the bottom of the day | ||
549 | // an all day event: mark with a circle in the middle (a la DateBook+) | ||
550 | bool beforeNoon = false; | ||
551 | bool atNoon = false; | ||
552 | bool afterNoon = false; | ||
553 | bool bAllDay = false; | ||
554 | bool bRepeatAfter = false; | ||
555 | bool bRepeatBefore = false; | ||
556 | bool bRepeatNoon = false; | ||
557 | bool straddleAfter = false; | ||
558 | bool straddleBefore = false; | ||
559 | QValueListIterator<EffectiveEvent> itDays = d->mDayEvents.begin(); | 551 | QValueListIterator<EffectiveEvent> itDays = d->mDayEvents.begin(); |
552 | |||
560 | for ( ; itDays != d->mDayEvents.end(); ++itDays ) { | 553 | for ( ; itDays != d->mDayEvents.end(); ++itDays ) { |
561 | if ( (*itDays).event().type() == Event::AllDay ) | 554 | int w = cr.width(); |
562 | bAllDay = TRUE; | 555 | Event ev = (*itDays).event(); |
563 | else if ( (*itDays).start().hour() < 12 ) { | 556 | |
564 | beforeNoon = TRUE; | 557 | int f = (*itDays).start().hour(); // assume Effective event |
565 | if ( (*itDays).end().hour() > 12 ) { | 558 | int t = (*itDays).end().hour(); // is truncated. |
566 | atNoon = TRUE; | 559 | |
567 | straddleBefore = TRUE; | 560 | if (ev.isAllDay()) { |
561 | if (!ev.hasRepeat()) | ||
562 | normalAllDay = TRUE; | ||
563 | else | ||
564 | repeatAllDay = TRUE; | ||
565 | } else { | ||
566 | int sLine, eLine; | ||
567 | if (f == 0) | ||
568 | sLine = 0; | ||
569 | else if (f < 8 ) | ||
570 | sLine = 1; | ||
571 | else if (f >= 17) | ||
572 | sLine = w - 4; | ||
573 | else { | ||
574 | sLine = (f - 8) * (w - 8); | ||
575 | if (sLine) | ||
576 | sLine /= 8; | ||
577 | sLine += 4; | ||
568 | } | 578 | } |
569 | if ( (*itDays).end().hour() > 14 || | 579 | if (t == 23) |
570 | (*itDays).end().hour() == 14 && (*itDays).end().minute() > 0 ) { | 580 | eLine = w; |
571 | afterNoon = TRUE; | 581 | else if (t < 8) |
572 | straddleAfter = TRUE; | 582 | eLine = 4; |
583 | else if (t >= 17) | ||
584 | eLine = w - 1; | ||
585 | else { | ||
586 | eLine = (t - 8) * (w - 8); | ||
587 | if (eLine) | ||
588 | eLine /= 8; | ||
589 | eLine += 4; | ||
573 | } | 590 | } |
574 | if ( (*itDays).event().hasRepeat() ) | 591 | if (!ev.hasRepeat()) { |
575 | bRepeatBefore = TRUE; | 592 | normalLine.push(sLine); |
576 | } else if ( (*itDays).start().hour() == 12 ) { | 593 | normalLine.push(eLine); |
577 | if ( !atNoon ) | 594 | } else { |
578 | atNoon = TRUE; | 595 | repeatLine.push(sLine); |
579 | if ( (*itDays).event().hasRepeat() ) | 596 | repeatLine.push(eLine); |
580 | bRepeatNoon = TRUE; | ||
581 | if ( (*itDays).end().hour() > 14 || | ||
582 | (*itDays).end().hour() == 14 && (*itDays).end().minute() > 0 ) { | ||
583 | afterNoon = TRUE; | ||
584 | straddleAfter = TRUE; | ||
585 | } | 597 | } |
586 | } else if ( (*itDays).start().hour() > 12 ) { | ||
587 | afterNoon = TRUE; | ||
588 | if ( (*itDays).event().hasRepeat() ) | ||
589 | bRepeatAfter = TRUE; | ||
590 | } | 598 | } |
591 | } | 599 | } |
592 | int x = cr.width() - 13; | 600 | |
593 | if ( beforeNoon ) { | 601 | // draw the background |
594 | p->setBrush( blue ); | 602 | if (normalAllDay || repeatAllDay || travelAllDay) { |
595 | p->drawRect( x, 2, 10, 10 ); | 603 | p->save(); |
596 | if ( bRepeatBefore ) | 604 | |
597 | p->fillRect( x + 5, 4, 3, 3, white ); | 605 | if (normalAllDay) |
598 | } | 606 | if (repeatAllDay) { |
599 | if ( atNoon ) { | 607 | p->fillRect( 0, 0, cr.width(), cr.height() / 2, |
600 | p->setBrush( blue ); | 608 | colorNormalLight ); |
601 | p->drawRect( x, 14, 10, 5 ); | 609 | p->fillRect( 0, cr.height() / 2, cr.width(), cr.height() / 2, |
602 | if ( bRepeatNoon ) | 610 | colorRepeatLight ); |
603 | p->fillRect( x + 5, 16, 3, 2, white ); | 611 | } else |
604 | } | 612 | p->fillRect( 0, 0, cr.width(), cr.height(), |
605 | if ( straddleBefore ) { | 613 | colorNormalLight ); |
606 | p->drawLine( x, 11, x, 14 ); | 614 | else if (repeatAllDay) |
607 | p->fillRect( x + 1, 11, 8, 4, blue ); | 615 | p->fillRect( 0, 0, cr.width(), cr.height(), |
608 | p->drawLine( x + 9, 11, x + 9, 14 ); | 616 | colorRepeatLight ); |
609 | } | 617 | } else { |
610 | if ( afterNoon ) { | 618 | p->fillRect( 0, 0, cr.width(), |
611 | p->setBrush( blue ); | 619 | cr.height(), selected |
612 | p->drawRect( x, 21, 10, 10 ); | 620 | ? g.brush( QColorGroup::Highlight ) |
613 | if ( bRepeatAfter ) | 621 | : g.brush( QColorGroup::Base ) ); |
614 | p->fillRect( x + 5, 23, 3, 3, white ); | ||
615 | } | 622 | } |
616 | if ( straddleAfter ) { | 623 | |
617 | p->drawLine( x, 18, x, 21 ); | 624 | // The lines |
618 | p->fillRect( x + 1, 18, 8, 4, blue ); | 625 | // now for the lines. |
619 | p->drawLine( x + 9, 18, x + 9, 21 ); | 626 | int h = 5; |
627 | int y = cr.height() / 2 - h; | ||
628 | |||
629 | while(normalLine.count() >= 2) { | ||
630 | int x2 = normalLine.pop(); | ||
631 | int x1 = normalLine.pop(); | ||
632 | if (x2 < x1 + 2) | ||
633 | x2 = x1 + 2; | ||
634 | p->fillRect(x1, y, x2 - x1, h, colorNormal); | ||
620 | } | 635 | } |
621 | if ( bAllDay ) { | 636 | |
622 | p->setBrush( green ); | 637 | y += h; |
623 | p->drawEllipse( cr.width() / 2 - 7, cr.height() / 2 - 5, 10, 10 ); | 638 | |
639 | while(repeatLine.count() >= 2) { | ||
640 | int x2 = repeatLine.pop(); | ||
641 | int x1 = repeatLine.pop(); | ||
642 | if (x2 < x1 + 2) | ||
643 | x2 = x1 + 2; | ||
644 | p->fillRect(x1, y, x2 - x1, h, colorRepeat); | ||
624 | } | 645 | } |
646 | |||
647 | |||
648 | // Finally, draw the number. | ||
649 | QFont f = p->font(); | ||
650 | f.setPointSize( ( f.pointSize() / 3 ) * 2 ); | ||
651 | p->setFont( f ); | ||
652 | QFontMetrics fm( f ); | ||
653 | p->drawText( 1, 1 + fm.ascent(), QString::number( day() ) ); | ||
654 | |||
655 | p->restore(); | ||
625 | } | 656 | } |
626 | 657 | ||
627 | 658 | ||
628 | 659 | ||
629 | void DayItemMonth::setType( Calendar::Day::Type t ) | 660 | void DayItemMonth::setType( Calendar::Day::Type t ) |
630 | { | 661 | { |
631 | switch ( t ) { | 662 | switch ( t ) { |
632 | case Calendar::Day::PrevMonth: | 663 | case Calendar::Day::PrevMonth: |
@@ -706,8 +737,14 @@ void DateButton::setDate( QDate d ) | |||
706 | 737 | ||
707 | } | 738 | } |
708 | 739 | ||
709 | void DateButton::setDateFormat( DateFormat f ) | 740 | void DateButton::setDateFormat( DateFormat f ) |
710 | { | 741 | { |
711 | df = f; | 742 | df = f; |
712 | setDate( currDate ); | 743 | setDate( currDate ); |
713 | } | 744 | } |
745 | |||
746 | bool DateButton::customWhatsThis() const | ||
747 | { | ||
748 | return TRUE; | ||
749 | } | ||
750 | |||