summaryrefslogtreecommitdiff
path: root/library/datebookmonth.cpp
Unidiff
Diffstat (limited to 'library/datebookmonth.cpp') (more/less context) (show whitespace changes)
-rw-r--r--library/datebookmonth.cpp209
1 files changed, 123 insertions, 86 deletions
diff --git a/library/datebookmonth.cpp b/library/datebookmonth.cpp
index f4b3e6b..272c223 100644
--- a/library/datebookmonth.cpp
+++ b/library/datebookmonth.cpp
@@ -1,5 +1,5 @@
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**
@@ -22,3 +22,3 @@
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"
@@ -33,2 +33,4 @@
33#include <qpopupmenu.h> 33#include <qpopupmenu.h>
34#include <qvaluestack.h>
35#include <qwhatsthis.h>
34 36
@@ -45,2 +47,3 @@ DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name )
45 begin->setFixedSize( begin->sizeHint() ); 47 begin->setFixedSize( begin->sizeHint() );
48 QWhatsThis::add( begin, tr("Show January in the selected year") );
46 49
@@ -51,2 +54,3 @@ DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name )
51 back->setFixedSize( back->sizeHint() ); 54 back->setFixedSize( back->sizeHint() );
55 QWhatsThis::add( back, tr("Show the previous month") );
52 56
@@ -63,2 +67,3 @@ DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name )
63 next->setFixedSize( next->sizeHint() ); 67 next->setFixedSize( next->sizeHint() );
68 QWhatsThis::add( next, tr("Show the next month") );
64 69
@@ -69,2 +74,3 @@ DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name )
69 end->setFixedSize( end->sizeHint() ); 74 end->setFixedSize( end->sizeHint() );
75 QWhatsThis::add( end, tr("Show December in the selected year") );
70 76
@@ -456,3 +462,2 @@ QDate DateBookMonth::selectedDate() const
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 );
@@ -527,2 +532,4 @@ void DayItemMonth::paint( QPainter *p, const QColorGroup &cg,
527{ 532{
533 p->save();
534
528 QColorGroup g( cg ); 535 QColorGroup g( cg );
@@ -530,4 +537,2 @@ void DayItemMonth::paint( QPainter *p, const QColorGroup &cg,
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 )
@@ -537,3 +542,108 @@ void DayItemMonth::paint( QPainter *p, const QColorGroup &cg,
537 542
543 QValueStack<int> normalLine;
544 QValueStack<int> repeatLine;
545 QValueStack<int> travelLine;
546
547 bool normalAllDay = FALSE;
548 bool repeatAllDay = FALSE;
549 bool travelAllDay = FALSE;
550
551 QValueListIterator<EffectiveEvent> itDays = d->mDayEvents.begin();
552
553 for ( ; itDays != d->mDayEvents.end(); ++itDays ) {
554 int w = cr.width();
555 Event ev = (*itDays).event();
556
557 int f = (*itDays).start().hour(); // assume Effective event
558 int t = (*itDays).end().hour(); // is truncated.
559
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;
578 }
579 if (t == 23)
580 eLine = w;
581 else if (t < 8)
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;
590 }
591 if (!ev.hasRepeat()) {
592 normalLine.push(sLine);
593 normalLine.push(eLine);
594 } else {
595 repeatLine.push(sLine);
596 repeatLine.push(eLine);
597 }
598 }
599 }
600
601 // draw the background
602 if (normalAllDay || repeatAllDay || travelAllDay) {
538 p->save(); 603 p->save();
604
605 if (normalAllDay)
606 if (repeatAllDay) {
607 p->fillRect( 0, 0, cr.width(), cr.height() / 2,
608 colorNormalLight );
609 p->fillRect( 0, cr.height() / 2, cr.width(), cr.height() / 2,
610 colorRepeatLight );
611 } else
612 p->fillRect( 0, 0, cr.width(), cr.height(),
613 colorNormalLight );
614 else if (repeatAllDay)
615 p->fillRect( 0, 0, cr.width(), cr.height(),
616 colorRepeatLight );
617 } else {
618 p->fillRect( 0, 0, cr.width(),
619 cr.height(), selected
620 ? g.brush( QColorGroup::Highlight )
621 : g.brush( QColorGroup::Base ) );
622 }
623
624 // The lines
625 // now for the lines.
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);
635 }
636
637 y += h;
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);
645 }
646
647
648 // Finally, draw the number.
539 QFont f = p->font(); 649 QFont f = p->font();
@@ -543,83 +653,4 @@ void DayItemMonth::paint( QPainter *p, const QColorGroup &cg,
543 p->drawText( 1, 1 + fm.ascent(), QString::number( day() ) ); 653 p->drawText( 1, 1 + fm.ascent(), QString::number( day() ) );
654
544 p->restore(); 655 p->restore();
545 // Put indicators for something like this, (similar to PalmOS)
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();
560 for ( ; itDays != d->mDayEvents.end(); ++itDays ) {
561 if ( (*itDays).event().type() == Event::AllDay )
562 bAllDay = TRUE;
563 else if ( (*itDays).start().hour() < 12 ) {
564 beforeNoon = TRUE;
565 if ( (*itDays).end().hour() > 12 ) {
566 atNoon = TRUE;
567 straddleBefore = TRUE;
568 }
569 if ( (*itDays).end().hour() > 14 ||
570 (*itDays).end().hour() == 14 && (*itDays).end().minute() > 0 ) {
571 afterNoon = TRUE;
572 straddleAfter = TRUE;
573 }
574 if ( (*itDays).event().hasRepeat() )
575 bRepeatBefore = TRUE;
576 } else if ( (*itDays).start().hour() == 12 ) {
577 if ( !atNoon )
578 atNoon = TRUE;
579 if ( (*itDays).event().hasRepeat() )
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 }
586 } else if ( (*itDays).start().hour() > 12 ) {
587 afterNoon = TRUE;
588 if ( (*itDays).event().hasRepeat() )
589 bRepeatAfter = TRUE;
590 }
591 }
592 int x = cr.width() - 13;
593 if ( beforeNoon ) {
594 p->setBrush( blue );
595 p->drawRect( x, 2, 10, 10 );
596 if ( bRepeatBefore )
597 p->fillRect( x + 5, 4, 3, 3, white );
598 }
599 if ( atNoon ) {
600 p->setBrush( blue );
601 p->drawRect( x, 14, 10, 5 );
602 if ( bRepeatNoon )
603 p->fillRect( x + 5, 16, 3, 2, white );
604 }
605 if ( straddleBefore ) {
606 p->drawLine( x, 11, x, 14 );
607 p->fillRect( x + 1, 11, 8, 4, blue );
608 p->drawLine( x + 9, 11, x + 9, 14 );
609 }
610 if ( afterNoon ) {
611 p->setBrush( blue );
612 p->drawRect( x, 21, 10, 10 );
613 if ( bRepeatAfter )
614 p->fillRect( x + 5, 23, 3, 3, white );
615 }
616 if ( straddleAfter ) {
617 p->drawLine( x, 18, x, 21 );
618 p->fillRect( x + 1, 18, 8, 4, blue );
619 p->drawLine( x + 9, 18, x + 9, 21 );
620 }
621 if ( bAllDay ) {
622 p->setBrush( green );
623 p->drawEllipse( cr.width() / 2 - 7, cr.height() / 2 - 5, 10, 10 );
624 }
625} 656}
@@ -713 +744,7 @@ void DateButton::setDateFormat( DateFormat f )
713} 744}
745
746bool DateButton::customWhatsThis() const
747{
748 return TRUE;
749}
750