summaryrefslogtreecommitdiff
path: root/library/datebookmonth.cpp
Side-by-side diff
Diffstat (limited to 'library/datebookmonth.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/datebookmonth.cpp203
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,93 +1,99 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "config.h"
#include "datebookmonth.h"
#include "datebookdb.h"
-#include <qpe/event.h>
+#include <qtopia/private/event.h>
#include "resource.h"
#include "qpeapplication.h"
#include "timestring.h"
#include <qtoolbutton.h>
#include <qspinbox.h>
#include <qcombobox.h>
#include <qdatetime.h>
#include <qpainter.h>
#include <qpopupmenu.h>
+#include <qvaluestack.h>
+#include <qwhatsthis.h>
DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name )
: QHBox( parent, name )
{
setBackgroundMode( PaletteButton );
begin = new QToolButton( this );
begin->setFocusPolicy(NoFocus);
begin->setPixmap( Resource::loadPixmap( "start" ) );
begin->setAutoRaise( TRUE );
begin->setFixedSize( begin->sizeHint() );
+ QWhatsThis::add( begin, tr("Show January in the selected year") );
back = new QToolButton( this );
back->setFocusPolicy(NoFocus);
back->setPixmap( Resource::loadPixmap( "back" ) );
back->setAutoRaise( TRUE );
back->setFixedSize( back->sizeHint() );
+ QWhatsThis::add( back, tr("Show the previous month") );
month = new QComboBox( FALSE, this );
for ( int i = 0; i < 12; ++i )
month->insertItem( Calendar::nameOfMonth( i + 1 ) );
year = new QSpinBox( 1752, 8000, 1, this );
next = new QToolButton( this );
next->setFocusPolicy(NoFocus);
next->setPixmap( Resource::loadPixmap( "forward" ) );
next->setAutoRaise( TRUE );
next->setFixedSize( next->sizeHint() );
+ QWhatsThis::add( next, tr("Show the next month") );
end = new QToolButton( this );
end->setFocusPolicy(NoFocus);
end->setPixmap( Resource::loadPixmap( "finish" ) );
end->setAutoRaise( TRUE );
end->setFixedSize( end->sizeHint() );
+ QWhatsThis::add( end, tr("Show December in the selected year") );
connect( month, SIGNAL( activated( int ) ),
this, SLOT( updateDate() ) );
connect( year, SIGNAL( valueChanged( int ) ),
this, SLOT( updateDate() ) );
connect( begin, SIGNAL( clicked() ),
this, SLOT( firstMonth() ) );
connect( end, SIGNAL( clicked() ),
this, SLOT( lastMonth() ) );
connect( back, SIGNAL( clicked() ),
this, SLOT( monthBack() ) );
connect( next, SIGNAL( clicked() ),
this, SLOT( monthForward() ) );
back->setAutoRepeat( TRUE );
next->setAutoRepeat( TRUE );
}
DateBookMonthHeader::~DateBookMonthHeader()
{
}
void DateBookMonthHeader::updateDate()
@@ -433,49 +439,48 @@ void DateBookMonth::finalDate(int y, int m, int d)
emit dateClicked(y, m, d);
// emit dateClicked(QDate(y, m, d).toString());
if ( autoClose && parentWidget() )
parentWidget()->close();
}
void DateBookMonth::setDate( QDate d)
{
setDate(d.year(), d.month(), d.day());
}
void DateBookMonth::redraw()
{
table->setDate( year, month, day );
table->redraw();
}
QDate DateBookMonth::selectedDate() const
{
if ( !table )
return QDate::currentDate();
int y, m, d;
table->getDate( y, m, d );
- qDebug( "got %d %d %d", y, m, d );
return QDate( y, m, d );
}
void DateBookMonth::slotWeekChange( bool startOnMonday )
{
table->setWeekStart( startOnMonday );
}
void DateBookMonth::keyPressEvent( QKeyEvent *e )
{
switch(e->key()) {
case Key_Up:
setDate(QDate(year, month, day).addDays(-7));
break;
case Key_Down:
setDate(QDate(year, month, day).addDays(7));
break;
case Key_Left:
setDate(QDate(year, month, day).addDays(-1));
break;
case Key_Right:
setDate(QDate(year, month, day).addDays(1));
break;
case Key_Space:
@@ -504,145 +509,171 @@ DayItemMonth::DayItemMonth( QTable *table, EditType et, const QString &t )
: QTableItem( table, et, t )
{
d = new DayItemMonthPrivate();
}
DayItemMonth::~DayItemMonth()
{
daysEvents.clear();
delete d;
}
void DayItemMonth::setEvents( const QValueList<EffectiveEvent> &effEv )
{
d->mDayEvents = effEv;
}
void DayItemMonth::clearEffEvents()
{
d->mDayEvents.clear();
}
void DayItemMonth::paint( QPainter *p, const QColorGroup &cg,
const QRect &cr, bool selected )
{
+ p->save();
+
QColorGroup g( cg );
g.setBrush( QColorGroup::Base, back );
g.setColor( QColorGroup::Text, forg );
- p->fillRect( 0, 0, cr.width(), cr.height(), selected ? g.brush( QColorGroup::Highlight ) : g.brush( QColorGroup::Base ) );
-
if ( selected )
p->setPen( g.highlightedText() );
else
p->setPen( g.text() );
- p->save();
- QFont f = p->font();
- f.setPointSize( ( f.pointSize() / 3 ) * 2 );
- p->setFont( f );
- QFontMetrics fm( f );
- p->drawText( 1, 1 + fm.ascent(), QString::number( day() ) );
- p->restore();
- // Put indicators for something like this, (similar to PalmOS)
- // Before noon: item at top of the day
- // At noon: put a small item at the middle
- // After noon: put an indicator at the bottom of the day
- // an all day event: mark with a circle in the middle (a la DateBook+)
- bool beforeNoon = false;
- bool atNoon = false;
- bool afterNoon = false;
- bool bAllDay = false;
- bool bRepeatAfter = false;
- bool bRepeatBefore = false;
- bool bRepeatNoon = false;
- bool straddleAfter = false;
- bool straddleBefore = false;
+ QValueStack<int> normalLine;
+ QValueStack<int> repeatLine;
+ QValueStack<int> travelLine;
+
+ bool normalAllDay = FALSE;
+ bool repeatAllDay = FALSE;
+ bool travelAllDay = FALSE;
+
QValueListIterator<EffectiveEvent> itDays = d->mDayEvents.begin();
+
for ( ; itDays != d->mDayEvents.end(); ++itDays ) {
- if ( (*itDays).event().type() == Event::AllDay )
- bAllDay = TRUE;
- else if ( (*itDays).start().hour() < 12 ) {
- beforeNoon = TRUE;
- if ( (*itDays).end().hour() > 12 ) {
- atNoon = TRUE;
- straddleBefore = TRUE;
+ int w = cr.width();
+ Event ev = (*itDays).event();
+
+ int f = (*itDays).start().hour(); // assume Effective event
+ int t = (*itDays).end().hour(); // is truncated.
+
+ if (ev.isAllDay()) {
+ if (!ev.hasRepeat())
+ normalAllDay = TRUE;
+ else
+ repeatAllDay = TRUE;
+ } else {
+ int sLine, eLine;
+ if (f == 0)
+ sLine = 0;
+ else if (f < 8 )
+ sLine = 1;
+ else if (f >= 17)
+ sLine = w - 4;
+ else {
+ sLine = (f - 8) * (w - 8);
+ if (sLine)
+ sLine /= 8;
+ sLine += 4;
}
- if ( (*itDays).end().hour() > 14 ||
- (*itDays).end().hour() == 14 && (*itDays).end().minute() > 0 ) {
- afterNoon = TRUE;
- straddleAfter = TRUE;
+ if (t == 23)
+ eLine = w;
+ else if (t < 8)
+ eLine = 4;
+ else if (t >= 17)
+ eLine = w - 1;
+ else {
+ eLine = (t - 8) * (w - 8);
+ if (eLine)
+ eLine /= 8;
+ eLine += 4;
}
- if ( (*itDays).event().hasRepeat() )
- bRepeatBefore = TRUE;
- } else if ( (*itDays).start().hour() == 12 ) {
- if ( !atNoon )
- atNoon = TRUE;
- if ( (*itDays).event().hasRepeat() )
- bRepeatNoon = TRUE;
- if ( (*itDays).end().hour() > 14 ||
- (*itDays).end().hour() == 14 && (*itDays).end().minute() > 0 ) {
- afterNoon = TRUE;
- straddleAfter = TRUE;
+ if (!ev.hasRepeat()) {
+ normalLine.push(sLine);
+ normalLine.push(eLine);
+ } else {
+ repeatLine.push(sLine);
+ repeatLine.push(eLine);
}
- } else if ( (*itDays).start().hour() > 12 ) {
- afterNoon = TRUE;
- if ( (*itDays).event().hasRepeat() )
- bRepeatAfter = TRUE;
}
}
- int x = cr.width() - 13;
- if ( beforeNoon ) {
- p->setBrush( blue );
- p->drawRect( x, 2, 10, 10 );
- if ( bRepeatBefore )
- p->fillRect( x + 5, 4, 3, 3, white );
- }
- if ( atNoon ) {
- p->setBrush( blue );
- p->drawRect( x, 14, 10, 5 );
- if ( bRepeatNoon )
- p->fillRect( x + 5, 16, 3, 2, white );
- }
- if ( straddleBefore ) {
- p->drawLine( x, 11, x, 14 );
- p->fillRect( x + 1, 11, 8, 4, blue );
- p->drawLine( x + 9, 11, x + 9, 14 );
- }
- if ( afterNoon ) {
- p->setBrush( blue );
- p->drawRect( x, 21, 10, 10 );
- if ( bRepeatAfter )
- p->fillRect( x + 5, 23, 3, 3, white );
+
+ // draw the background
+ if (normalAllDay || repeatAllDay || travelAllDay) {
+ p->save();
+
+ if (normalAllDay)
+ if (repeatAllDay) {
+ p->fillRect( 0, 0, cr.width(), cr.height() / 2,
+ colorNormalLight );
+ p->fillRect( 0, cr.height() / 2, cr.width(), cr.height() / 2,
+ colorRepeatLight );
+ } else
+ p->fillRect( 0, 0, cr.width(), cr.height(),
+ colorNormalLight );
+ else if (repeatAllDay)
+ p->fillRect( 0, 0, cr.width(), cr.height(),
+ colorRepeatLight );
+ } else {
+ p->fillRect( 0, 0, cr.width(),
+ cr.height(), selected
+ ? g.brush( QColorGroup::Highlight )
+ : g.brush( QColorGroup::Base ) );
}
- if ( straddleAfter ) {
- p->drawLine( x, 18, x, 21 );
- p->fillRect( x + 1, 18, 8, 4, blue );
- p->drawLine( x + 9, 18, x + 9, 21 );
+
+ // The lines
+ // now for the lines.
+ int h = 5;
+ int y = cr.height() / 2 - h;
+
+ while(normalLine.count() >= 2) {
+ int x2 = normalLine.pop();
+ int x1 = normalLine.pop();
+ if (x2 < x1 + 2)
+ x2 = x1 + 2;
+ p->fillRect(x1, y, x2 - x1, h, colorNormal);
}
- if ( bAllDay ) {
- p->setBrush( green );
- p->drawEllipse( cr.width() / 2 - 7, cr.height() / 2 - 5, 10, 10 );
+
+ y += h;
+
+ while(repeatLine.count() >= 2) {
+ int x2 = repeatLine.pop();
+ int x1 = repeatLine.pop();
+ if (x2 < x1 + 2)
+ x2 = x1 + 2;
+ p->fillRect(x1, y, x2 - x1, h, colorRepeat);
}
+
+
+ // Finally, draw the number.
+ QFont f = p->font();
+ f.setPointSize( ( f.pointSize() / 3 ) * 2 );
+ p->setFont( f );
+ QFontMetrics fm( f );
+ p->drawText( 1, 1 + fm.ascent(), QString::number( day() ) );
+
+ p->restore();
}
void DayItemMonth::setType( Calendar::Day::Type t )
{
switch ( t ) {
case Calendar::Day::PrevMonth:
case Calendar::Day::NextMonth:
back = QBrush( QColor( 224, 224, 224 ) );
forg = black;
break;
case Calendar::Day::ThisMonth:
back = QBrush( white );
forg = black;
break;
}
typ = t;
}
DateButton::DateButton( bool longDate, QWidget *parent, const char * name )
:QPushButton( parent, name )
@@ -690,24 +721,30 @@ void DateButton::gotHide()
void DateButton::setWeekStartsMonday( int b )
{
weekStartsMonday = b;
}
void DateButton::setDate( int y, int m, int d )
{
setDate( QDate( y,m,d) );
}
void DateButton::setDate( QDate d )
{
currDate = d;
setText( longFormat ? TimeString::longDateString( d, df ) :
TimeString::shortDate( d, df ) );
}
void DateButton::setDateFormat( DateFormat f )
{
df = f;
setDate( currDate );
}
+
+bool DateButton::customWhatsThis() const
+{
+ return TRUE;
+}
+