Diffstat (limited to 'core/pim/datebook/datebookweek.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/datebook/datebookweek.cpp | 65 |
1 files changed, 27 insertions, 38 deletions
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp index 2ad7aa9..ab7e963 100644 --- a/core/pim/datebook/datebookweek.cpp +++ b/core/pim/datebook/datebookweek.cpp @@ -1,61 +1,54 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of 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 "datebookweek.h" #include "datebookweekheaderimpl.h" -#include <qpe/calendar.h> #include <qpe/datebookdb.h> -#include <qpe/event.h> #include <qpe/qpeapplication.h> -#include <qpe/timestring.h> +#include <qpe/calendar.h> -#include <qdatetime.h> #include <qheader.h> #include <qlabel.h> #include <qlayout.h> -#include <qpainter.h> -#include <qpopupmenu.h> #include <qtimer.h> -#include <qspinbox.h> -#include <qstyle.h> //----------------------------------------------------------------- DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e ) : ev( e ) { // with the current implementation change the color for all day events if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) { c = Qt::green; } else { c = ev.event().hasAlarm() ? Qt::red : Qt::blue; } } void DateBookWeekItem::setGeometry( int x, int y, int w, int h ) { r.setRect( x, y, w, h ); } //------------------=--------------------------------------------- DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday, @@ -68,86 +61,79 @@ DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday, viewport()->setBackgroundMode( PaletteBase ); header = new QHeader( this ); header->addLabel( "" ); header->setMovingEnabled( false ); header->setResizeEnabled( false ); header->setClickEnabled( false, 0 ); initNames(); connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) ); QObject::connect(qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotChangeClock(bool))); QFontMetrics fm( font() ); rowHeight = fm.height()+2; resizeContents( width(), 24*rowHeight ); } void DateBookWeekView::initNames() { +#warning Please review this ! (eilers) + + // Ok, I am Mr. Pedantic, but shouldn't we count until 6 instead of 7, if bOnMonday is false ? (eilers) + static bool bFirst = true; if ( bFirst ) { if ( bOnMonday ) { - header->addLabel( tr("Mo", "Monday" ) ); - header->addLabel( tr("Tu", "Tuesday") ); - header->addLabel( tr("We", "Wednesday" ) ); - header->addLabel( tr("Th", "Thursday" ) ); - header->addLabel( tr("Fr", "Friday" ) ); - header->addLabel( tr("Sa", "Saturday" ) ); - header->addLabel( tr("Su", "Sunday" ) ); + for ( int i = 1; i<=7; i++ ) { + header->addLabel( Calendar::nameOfDay( i ) ); + } + } else { - header->addLabel( tr("Su", "Sunday" ) ); - header->addLabel( tr("Mo", "Monday") ); - header->addLabel( tr("Tu", "Tuesday") ); - header->addLabel( tr("We", "Wednesday" ) ); - header->addLabel( tr("Th", "Thursday" ) ); - header->addLabel( tr("Fr", "Friday" ) ); - header->addLabel( tr("Sa", "Saturday" ) ); - } + header->addLabel( Calendar::nameOfDay( 7 ) ); + for ( int i = 1; i<7; i++ ) { + header->addLabel( Calendar::nameOfDay( i ) ); + } + } bFirst = false; } else { // we are change things... if ( bOnMonday ) { - header->setLabel( 1, tr("Mo", "Monday") ); - header->setLabel( 2, tr("Tu", "Tuesday") ); - header->setLabel( 3, tr("We", "Wednesday" ) ); - header->setLabel( 4, tr("Th", "Thursday" ) ); - header->setLabel( 5, tr("Fr", "Friday" ) ); - header->setLabel( 6, tr("Sa", "Saturday" ) ); - header->setLabel( 7, tr("Su", "Sunday" ) ); + for ( int i = 1; i<=7; i++ ) { + header->setLabel( i, Calendar::nameOfDay( i ) ); + } + } else { - header->setLabel( 1, tr("Su", "Sunday" ) ); - header->setLabel( 2, tr("Mo", "Monday") ); - header->setLabel( 3, tr("Tu", "Tuesday") ); - header->setLabel( 4, tr("We", "Wednesday" ) ); - header->setLabel( 5, tr("Th", "Thursday" ) ); - header->setLabel( 6, tr("Fr", "Friday" ) ); - header->setLabel( 7, tr("Sa", "Saturday" ) ); + header->setLabel( 1, Calendar::nameOfDay( 7 ) ); + for ( int i = 1; i<7; i++ ) { + header->setLabel( i+1, Calendar::nameOfDay( i ) ); + } + } } } void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) { items.clear(); QValueListIterator<EffectiveEvent> it; for ( it = ev.begin(); it != ev.end(); ++it ) { DateBookWeekItem *i = new DateBookWeekItem( *it ); if(!((i->event().end().hour()==0) && (i->event().end().minute()==0) && (i->event().startDate()!=i->event().date()))) { // Skip events ending at 00:00 starting at another day. positionItem( i ); items.append( i ); } } viewport()->update(); } void DateBookWeekView::moveToHour( int h ) { int offset = h*rowHeight; setContentsPos( 0, offset ); @@ -381,49 +367,50 @@ 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(); + 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(); } @@ -554,48 +541,50 @@ void DateBookWeek::slotYearChanged( int y ) } } 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.. // 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: // http://personal.ecu.edu/mccartyr/ISOwdALG.txt // the week number is return, 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. // For Weeks that start on Sunday... (ahh... home rolled) // okay, if Jan 1 is on Friday or Saturday, // it will go to the pervious |