Diffstat (limited to 'core/pim/datebook/datebookweekheaderimpl.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/pim/datebook/datebookweekheaderimpl.cpp | 93 |
1 files changed, 26 insertions, 67 deletions
diff --git a/core/pim/datebook/datebookweekheaderimpl.cpp b/core/pim/datebook/datebookweekheaderimpl.cpp index 5f555d5..fd792e2 100644 --- a/core/pim/datebook/datebookweekheaderimpl.cpp +++ b/core/pim/datebook/datebookweekheaderimpl.cpp @@ -23,149 +23,108 @@ #include <qlabel.h> #include <qspinbox.h> #include <qdatetime.h> #include <qpe/resource.h> #include <qpe/datebookmonth.h> #include <qtoolbutton.h> /* * Constructs a DateBookWeekHeader which is a child of 'parent', with the * name 'name' and widget flags set to 'f' */ -DateBookWeekHeader::DateBookWeekHeader( bool startOnMonday, QWidget* parent, - const char* name, WFlags fl ) +DateBookWeekHeader::DateBookWeekHeader( bool startOnMonday, QWidget* parent, const char* name, WFlags fl ) : DateBookWeekHeaderBase( parent, name, fl ), bStartOnMonday( startOnMonday ) { setBackgroundMode( PaletteButton ); labelDate->setBackgroundMode( PaletteButton ); - backmonth->setPixmap( Resource::loadPixmap("fastback") ); backweek->setPixmap( Resource::loadPixmap("back") ); forwardweek->setPixmap( Resource::loadPixmap("forward") ); forwardmonth->setPixmap( Resource::loadPixmap("fastforward") ); - spinYear->hide(); - spinWeek->hide(); } /* * Destroys the object and frees any allocated resources */ DateBookWeekHeader::~DateBookWeekHeader() { // no need to delete child widgets, Qt does it all for us } void DateBookWeekHeader::pickDate() { static QPopupMenu *m1 = 0; static DateBookMonth *picker = 0; - QDate currDate = dateFromWeek( week, year, bStartOnMonday ); 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( m1, SIGNAL( aboutToHide() ), -// this, SLOT( gotHide() ) ); + connect( picker, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( setDate( int, int, int ) ) ); +// connect( m1, SIGNAL( aboutToHide() ), this, SLOT( gotHide() ) ); } - picker->setDate( currDate.year(), currDate.month(), currDate.day() ); + picker->setDate( date.year(), date.month(), date.day() ); m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height()))); picker->setFocus(); } -/* - * public slot - */ -void DateBookWeekHeader::yearChanged( int y ) -{ - setDate( y, week ); -} + void DateBookWeekHeader::nextMonth() { - QDate mydate = dateFromWeek( week, year, bStartOnMonday ); // Get current week - calcWeek( mydate.addDays(28), week, year, bStartOnMonday ); // Add 4 weeks. - setDate( year, week ); // update view + setDate(date.addDays(28)); } void DateBookWeekHeader::prevMonth() { - QDate mydate = dateFromWeek( week, year, bStartOnMonday ); // Get current week - calcWeek( mydate.addDays(-28), week, year, bStartOnMonday ); // Subtract 4 weeks - setDate( year, week ); // update view + setDate(date.addDays(-28)); } -/* - * public slot - */ void DateBookWeekHeader::nextWeek() { - QDate mydate = dateFromWeek( week, year, bStartOnMonday ); // Get current week - calcWeek( mydate.addDays(7), week, year, bStartOnMonday); // Add 1 week -// if ( week < 52 ) -// week++; - setDate( year, week ); + setDate(date.addDays(7)); } -/* - * public slot - */ void DateBookWeekHeader::prevWeek() { - QDate mydate = dateFromWeek( week, year, bStartOnMonday ); // Get current week - calcWeek( mydate.addDays(-7), week, year, bStartOnMonday); // Add 1 week -// if ( week > 1 ) -// week--; - setDate( year, week ); -} -/* - * public slot - */ -void DateBookWeekHeader::weekChanged( int w ) -{ - setDate( year, w ); + setDate(date.addDays(-7)); } void DateBookWeekHeader::setDate( int y, int m, int d ) { - calcWeek( QDate(y,m,d), week, year, bStartOnMonday ); - setDate( year, week ); + setDate(QDate(y,m,d)); } -void DateBookWeekHeader::setDate( int y, int w ) -{ - year = y; - week = w; - spinYear->setValue( y ); - spinWeek->setValue( w ); - - QDate d = dateFromWeek( week, year, bStartOnMonday ); +void DateBookWeekHeader::setDate(const QDate &d) { + int year,week,dayofweek; + date=d; + dayofweek=d.dayOfWeek(); + if(bStartOnMonday) dayofweek--; + date=date.addDays(-dayofweek); - QString s = QString::number( d.day() ) + ". " + d.monthName( d.month() ) - + "-"; - d = d.addDays( 6 ); - s += QString::number( d.day() ) + ". " + d.monthName( d.month() ); - s += " ("+tr("week")+":"+QString::number( w )+")"; - labelDate->setText( s ); - - emit dateChanged( y, w ); + calcWeek(date,week,year,bStartOnMonday); + QDate start=date; + QDate stop=start.addDays(6); + labelDate->setText( QString::number(start.day()) + "." + + start.monthName(start.month()) + "-" + + QString::number(stop.day()) + "." + + start.monthName(stop.month()) +" ("+ + tr("w")+":"+QString::number( week ) +")"); + emit dateChanged(year,week); } void DateBookWeekHeader::setStartOfWeek( bool onMonday ) { bStartOnMonday = onMonday; - setDate( year, week ); + setDate( date ); } // dateFromWeek // compute the date from the week in the year - QDate dateFromWeek( int week, int year, bool startOnMonday ) { QDate d; d.setYMD( year, 1, 1 ); int dayOfWeek = d.dayOfWeek(); if ( startOnMonday ) { if ( dayOfWeek <= 4 ) { d = d.addDays( ( week - 1 ) * 7 - dayOfWeek + 1 ); } else { d = d.addDays( (week) * 7 - dayOfWeek + 1 ); } } else { |