summaryrefslogtreecommitdiff
authorerik <erik>2007-01-29 21:39:43 (UTC)
committer erik <erik>2007-01-29 21:39:43 (UTC)
commitb2c306a99b8dc82c981390f02db859149fac8cf0 (patch) (side-by-side diff)
tree5d3b06d7534611b8a6ea56f592d95b59b18a218c
parent597643805ce89c1237035e7f38ec953cfc0d080f (diff)
downloadopie-b2c306a99b8dc82c981390f02db859149fac8cf0.zip
opie-b2c306a99b8dc82c981390f02db859149fac8cf0.tar.gz
opie-b2c306a99b8dc82c981390f02db859149fac8cf0.tar.bz2
Reformat according to current Opie coding style.
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/pim/datebook/datebookweek.cpp74
1 files changed, 48 insertions, 26 deletions
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp
index ce0b10b..8caa827 100644
--- a/core/pim/datebook/datebookweek.cpp
+++ b/core/pim/datebook/datebookweek.cpp
@@ -336,352 +336,374 @@ void DateBookWeekView::resizeEvent( QResizeEvent *e )
header->setGeometry( 0, 0, avail, header->sizeHint().height() );
setMargins( 0, header->height(), 0, 0 );
header->resizeSection( 0, hourWidth );
int sw = (avail - hourWidth) / 7;
for ( int i = 1; i < 7; i++ )
header->resizeSection( i, sw );
header->resizeSection( 7, avail - hourWidth - sw*6 );
}
void DateBookWeekView::setStartOfWeek( bool bStartOnMonday )
{
bOnMonday = bStartOnMonday;
initNames();
}
//-------------------------------------------------------------------
DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDBHoliday *newDB,
QWidget *parent, const char *name )
: QWidget( parent, name ),
db( newDB ),
startTime( 0 ),
ampm( ap ),
bStartOnMonday( startOnMonday )
{
setFocusPolicy(StrongFocus);
QVBoxLayout *vb = new QVBoxLayout( this );
header = new DateBookWeekHeader( bStartOnMonday, this );
view = new DateBookWeekView( ampm, startOnMonday, this );
vb->addWidget( header );
vb->addWidget( view );
lblDesc = new QLabel( this, "event label" );
lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box );
lblDesc->setBackgroundColor( yellow );
lblDesc->hide();
tHide = new QTimer( this );
connect( view, SIGNAL( showDay(int) ), this, SLOT( showDay(int) ) );
connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) );
connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) );
connect( header, SIGNAL( dateChanged(QDate&) ), this, SLOT( dateChanged(QDate&) ) );
connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) );
connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) );
connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool)));
setDate(QDate::currentDate());
}
void DateBookWeek::keyPressEvent(QKeyEvent *e)
{
switch(e->key()) {
case Key_Up:
view->scrollBy(0, -20);
break;
case Key_Down:
view->scrollBy(0, 20);
break;
case Key_Left:
setDate(date().addDays(-7));
break;
case Key_Right:
setDate(date().addDays(7));
break;
default:
e->ignore();
}
}
void DateBookWeek::showDay( int day )
{
QDate d=bdate;
// Calculate offset to first day of week.
int dayoffset=d.dayOfWeek() % 7;
if(bStartOnMonday) dayoffset--;
day--;
d=d.addDays(day-dayoffset);
emit showDate( d.year(), d.month(), d.day() );
}
void DateBookWeek::setDate( int y, int m, int d )
{
setDate(QDate(y, m, d));
}
void DateBookWeek::setDate(QDate newdate)
{
bdate=newdate;
dow = newdate.dayOfWeek();
header->setDate( newdate );
}
void DateBookWeek::dateChanged( QDate &newdate )
{
bdate=newdate;
getEvents();
}
QDate DateBookWeek::date() const
{
return bdate;
}
void DateBookWeek::getEvents()
{
QDate startWeek = weekDate();
QDate endWeek = startWeek.addDays( 6 );
QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek);
view->showEvents( eventList );
view->moveToHour( startTime );
}
void DateBookWeek::generateAllDayTooltext( QString& text ) {
text += "<b>" + tr("This is an all day event.") + "</b><br>";
}
void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) {
str += "<b>" + QObject::tr("Start") + "</b>: ";
str += TimeString::timeString( ev.event().start().time(), ampm, FALSE );
if( ev.startDate()!=ev.endDate() ) {
str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>";
}
str += "<br>";
str += "<b>" + QObject::tr("End") + "</b>: ";
str += TimeString::timeString( ev.event().end().time(), ampm, FALSE );
if( ev.startDate()!=ev.endDate() ) {
str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>";
}
}
void DateBookWeek::slotShowEvent( const EffectiveEvent &ev )
{
if ( tHide->isActive() )
tHide->stop();
// why would someone use "<"? Oh well, fix it up...
// I wonder what other things may be messed up...
QString strDesc = ev.description();
int where = strDesc.find( "<" );
while ( where != -1 ) {
strDesc.remove( where, 1 );
strDesc.insert( where, "&#60;" );
where = strDesc.find( "<", where );
}
QString strCat;
// ### FIX later...
// QString strCat = ev.category();
// where = strCat.find( "<" );
// while ( where != -1 ) {
// strCat.remove( where, 1 );
// strCat.insert( where, "&#60;" );
// where = strCat.find( "<", where );
// }
QString strLocation = ev.location();
while ( where != -1 ) {
strLocation.remove( where, 1 );
strLocation.insert( where, "&#60;" );
where = strLocation.find( "<", where );
}
QString strNote = ev.notes();
where = strNote.find( "<" );
while ( where != -1 ) {
strNote.remove( where, 1 );
strNote.insert( where, "&#60;" );
where = strNote.find( "<", where );
}
QString str = "<b>" + strDesc + "</b><br>"
+ strLocation + "<br>"
+ "<i>" + strCat + "</i>"
+ "<br>" + TimeString::longDateString( ev.date() )
+ "<br>";
if (ev.event().type() == Event::Normal )
generateNormalTooltext( str, ev );
else
generateAllDayTooltext( str );
str += "<br><br>" + strNote;
lblDesc->setText( str );
lblDesc->resize( lblDesc->sizeHint() );
// move the label so it is "centerd" horizontally...
lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 );
lblDesc->show();
}
void DateBookWeek::slotHideEvent()
{
tHide->start( 2000, true );
}
void DateBookWeek::setStartViewTime( int startHere )
{
startTime = startHere;
view->moveToHour( startTime );
}
int DateBookWeek::startViewTime() const
{
return startTime;
}
void DateBookWeek::redraw()
{
getEvents();
}
void DateBookWeek::slotYearChanged( int y )
{
int totWeek;
QDate d( y, 12, 31 );
int throwAway;
calcWeek( d, totWeek, throwAway, bStartOnMonday );
while ( totWeek == 1 ) {
d = d.addDays( -1 );
calcWeek( d, totWeek, throwAway, bStartOnMonday );
}
}
void DateBookWeek::slotWeekChanged( bool onMonday )
{
bStartOnMonday = onMonday;
view->setStartOfWeek( bStartOnMonday );
header->setStartOfWeek( bStartOnMonday );
redraw();
}
void DateBookWeek::slotClockChanged( bool ap )
{
ampm = ap;
}
// return the date at the beginning of the week...
QDate DateBookWeek::weekDate() const
{
QDate d=bdate;
// Calculate offset to first day of week.
int dayoffset=d.dayOfWeek();
if(bStartOnMonday) dayoffset--;
else if( dayoffset == 7 )
dayoffset = 0;
return d.addDays(-dayoffset);
}
-// this used to only be needed by datebook.cpp, but now we need it inside
-// week view since
-// we need to be able to figure out our total number of weeks on the fly...
-// this is probably the best place to put it..
+// This used to only be needed by datebook.cpp, but now we need it
+// inside week view since we need to be able to figure out our total
+// number of weeks on the fly. This is probably the best place to put
+// it.
// For Weeks that start on Monday... (EASY!)
-// At the moment we will use ISO 8601 method for computing
-// the week. Granted, other countries use other methods,
-// bet we aren't doing any Locale stuff at the moment. So,
-// this should pass. This Algorithim is public domain and
-// available at:
+// At the moment we will use the ISO 8601 method for computing the week.
+// Granted, other countries use other methods, but we aren't doing any
+// Locale stuff at the moment. Without locale info it is too hard to
+// guess what method should be used. So, this should pass. This
+// algorithim is public domain and available at:
// http://personal.ecu.edu/mccartyr/ISOwdALG.txt
-// the week number is return, and the year number is returned in year
+// the week number is returned, and the year number is returned in year
// for Instance 2001/12/31 is actually the first week in 2002.
-// There is a more mathematical definition, but I will implement it when
-// we are pass our deadline.
+// There is a more mathematical definition, it should be implemented.
// For Weeks that start on Sunday... (ahh... home rolled)
-// okay, if Jan 1 is on Friday or Saturday,
-// it will go to the pervious
-// week...
-
+// okay, if Jan 1 is on Friday or Saturday, it will go to the previous
+// week.
+
+/*!
+ * The week number and year number of a date may actually be different
+ * then the date itself as specified by the ISO 8601 standard. For
+ * example if Jan 1 year falls on a Friday, the week number will
+ * be the last week number for the previous year (52 of year - 1). Another
+ * example is that the date 2001-12-31 falls on a Monday, its week number
+ * is 1 and its year is 2002. This function provides stripped down
+ * version of the alogrithm described in
+ * http://personal.ecu.edu/mccartyr/ISOwdALG.txt to provide the correct
+ * week number and year number for a given date.
+ *
+ * \param d The date that you want to know the week number for.
+ * \param week A reference to the variable you want to store the week
+ * number in.
+ * \param year A reference to the variable you want to store the year
+ * number in.
+ * \param startOnMonday Inform the function whether weeks start on
+ * Sunday or Monday. Set to true if your weeks start on Monday.
+ * \return false if the supplied date is invalid, true otherwise.
+ */
bool calcWeek( const QDate &d, int &week, int &year,
bool startOnMonday )
{
- int weekNumber;
- int yearNumber;
+ int weekNumber = -1;
+ int yearNumber = -1;
- // remove a pesky warning, (Optimizations on g++)
- weekNumber = -1;
int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek();
int dayOfWeek = d.dayOfWeek();
if ( !d.isValid() )
return false;
if ( startOnMonday ) {
// find the Jan1Weekday;
if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) {
yearNumber = d.year() - 1;
- if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) )
+ if ( jan1WeekDay == 5
+ || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) )
weekNumber = 53;
else
weekNumber = 52;
} else
yearNumber = d.year();
+
if ( yearNumber == d.year() ) {
int totalDays = 365;
if ( QDate::leapYear(yearNumber) )
totalDays++;
if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) )
- || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) {
+ || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3)
+ {
yearNumber++;
weekNumber = 1;
}
}
if ( yearNumber == d.year() ) {
int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 );
weekNumber = j / 7;
if ( jan1WeekDay > 4 )
weekNumber--;
}
} else {
// it's better to keep these cases separate...
if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4
- && jan1WeekDay != 7 ) {
+ && jan1WeekDay != 7 )
+ {
yearNumber = d.year() - 1;
if ( jan1WeekDay == 6
- || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) {
+ || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) )
+ {
weekNumber = 53;
}else
weekNumber = 52;
} else
yearNumber = d.year();
+
if ( yearNumber == d.year() ) {
int totalDays = 365;
if ( QDate::leapYear( yearNumber ) )
totalDays++;
if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) {
yearNumber++;
weekNumber = 1;
}
}
if ( yearNumber == d.year() ) {
int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 );
weekNumber = j / 7;
- if ( jan1WeekDay > 4 ) {
+
+ if ( jan1WeekDay > 4 )
weekNumber--;
}
}
- }
year = yearNumber;
week = weekNumber;
return true;
}