summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/datebookmonth.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/library/datebookmonth.cpp b/library/datebookmonth.cpp
index 013ab66..2616b7b 100644
--- a/library/datebookmonth.cpp
+++ b/library/datebookmonth.cpp
@@ -1,127 +1,130 @@
/**********************************************************************
** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
** 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 "resource.h"
#include <qpe/qpeapplication.h>
#include <qtoolbutton.h>
#include <qspinbox.h>
#include <qcombobox.h>
#include <qvaluestack.h>
#include <qwhatsthis.h>
+static const QColor s_colorNormalLight = QColor(255, 150, 150);
+static const QColor s_colorRepeatLight = QColor(150, 150, 255);
+static const QColor s_colorHolidayLight= QColor(150, 255, 150);
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()
{
emit dateChanged( year->value(), month->currentItem() + 1 );
}
void DateBookMonthHeader::firstMonth()
{
emit dateChanged( year->value(), 1 );
month->setCurrentItem( 0 );
}
void DateBookMonthHeader::lastMonth()
{
emit dateChanged( year->value(), 12 );
month->setCurrentItem( 11 );
}
void DateBookMonthHeader::monthBack()
{
if ( month->currentItem() > 0 ) {
emit dateChanged( year->value(), month->currentItem() );
month->setCurrentItem( month->currentItem() - 1 );
} else {
emit dateChanged( year->value() - 1, 12 );
// we have a signal set to a changed value in year so we only need to change
// year to get the result...
month->setCurrentItem( 11 );
year->setValue( year->value() - 1 );
}
}
void DateBookMonthHeader::monthForward()
{
if ( month->currentItem() < 11 ) {
@@ -517,206 +520,206 @@ DayItemMonth::~DayItemMonth()
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 );
if ( selected )
p->setPen( g.highlightedText() );
else
p->setPen( g.text() );
QValueStack<int> normalLine;
QValueStack<int> repeatLine;
QValueStack<int> travelLine;
bool normalAllDay = FALSE;
bool repeatAllDay = FALSE;
bool travelAllDay = FALSE;
bool holidayAllDay = FALSE;
QValueListIterator<EffectiveEvent> itDays = d->mDayEvents.begin();
for ( ; itDays != d->mDayEvents.end(); ++itDays ) {
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;
if (!ev.isValidUid()) {
holidayAllDay = 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 (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 (!ev.hasRepeat()) {
normalLine.push(sLine);
normalLine.push(eLine);
} else {
repeatLine.push(sLine);
repeatLine.push(eLine);
}
}
}
// draw the background
if (normalAllDay || repeatAllDay || travelAllDay || holidayAllDay) {
p->save();
if (normalAllDay)
if (repeatAllDay) {
p->fillRect( 0, 0, cr.width(), cr.height() / 2,
- colorNormalLight );
+ s_colorNormalLight );
p->fillRect( 0, cr.height() / 2, cr.width(), cr.height() / 2,
colorRepeatLight );
} else {
if (!holidayAllDay) {
p->fillRect( 0, 0, cr.width(), cr.height(),
- colorNormalLight );
+ s_colorNormalLight );
} else {
p->fillRect( 0, 0, cr.width(), cr.height(),
- QColor(0,220,0) );
+ s_colorHolidayLight );
}
} else if (repeatAllDay) {
p->fillRect( 0, 0, cr.width(), cr.height(),
- colorRepeatLight );
+ s_colorRepeatLight );
}
} else {
p->fillRect( 0, 0, cr.width(),
cr.height(), selected
? g.brush( QColorGroup::Highlight )
: g.brush( QColorGroup::Base ) );
}
// 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);
}
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 )
{
longFormat = longDate;
df = DateFormat('/', DateFormat::MonthDayYear, DateFormat::MonthDayYear);
setDate( QDate::currentDate() );
connect(this,SIGNAL(pressed()),this,SLOT(pickDate()));
}
void DateButton::pickDate()
{
static QPopupMenu *m1 = 0;
static DateBookMonth *picker = 0;
if ( !m1 ) {
m1 = new QPopupMenu( this );
picker = new DateBookMonth( m1, 0, TRUE );
m1->insertItem( picker );
connect( picker, SIGNAL( dateClicked(int,int,int) ),
this, SLOT( setDate(int,int,int) ) );
connect( picker, SIGNAL( dateClicked(int,int,int) ),
this, SIGNAL( dateSelected(int,int,int) ) );
connect( m1, SIGNAL( aboutToHide() ),
this, SLOT( gotHide() ) );
}
picker->slotWeekChange( weekStartsMonday );
picker->setDate( currDate.year(), currDate.month(), currDate.day() );
m1->popup(mapToGlobal(QPoint(0,height())));
picker->setFocus();
}