Diffstat (limited to 'core/pim/datebook/datebookweeklst.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/datebook/datebookweeklst.cpp | 212 |
1 files changed, 110 insertions, 102 deletions
diff --git a/core/pim/datebook/datebookweeklst.cpp b/core/pim/datebook/datebookweeklst.cpp index 3c8fc89..a39ff40 100644 --- a/core/pim/datebook/datebookweeklst.cpp +++ b/core/pim/datebook/datebookweeklst.cpp @@ -18,133 +18,145 @@ #include <qlabel.h> #include <qlayout.h> #include <qpainter.h> #include <qpopupmenu.h> #include <qtimer.h> #include <qstyle.h> #include <qtoolbutton.h> #include <qvbox.h> #include <qsizepolicy.h> #include <qabstractlayout.h> #include <qtl.h> -bool calcWeek(const QDate &d, int &week, int &year, - bool startOnMonday = false); +bool calcWeek(const QDate &d, int &week, int &year,bool startOnMonday = false); -DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, - const char* name, WFlags fl) +DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, const char* name, WFlags fl) : DateBookWeekLstHeaderBase(parent, name, fl) { - setBackgroundMode( PaletteButton ); - labelDate->setBackgroundMode( PaletteButton ); - labelWeek->setBackgroundMode( PaletteButton ); - forward->setBackgroundMode( PaletteButton ); - forward->setPixmap( Resource::loadPixmap("forward") ); - back->setBackgroundMode( PaletteButton ); - back->setPixmap( Resource::loadPixmap("back") ); - DateBookWeekLstHeaderBaseLayout->setSpacing(0); - DateBookWeekLstHeaderBaseLayout->setMargin(0); - //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding)); - setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); - - connect(back, SIGNAL(clicked()), this, SLOT(prevWeek())); - connect(forward, SIGNAL(clicked()), this, SLOT(nextWeek())); - connect(labelWeek, SIGNAL(clicked()), this, SLOT(pickDate())); - connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool))); - onMonday=onM; + setBackgroundMode( PaletteButton ); + labelDate->setBackgroundMode( PaletteButton ); + forwardweek->setBackgroundMode( PaletteButton ); + forwardweek->setPixmap( Resource::loadPixmap("forward") ); + forwardmonth->setBackgroundMode( PaletteButton ); + forwardmonth->setPixmap( Resource::loadPixmap("fastforward") ); + backweek->setBackgroundMode( PaletteButton ); + backweek->setPixmap( Resource::loadPixmap("back") ); + backmonth->setBackgroundMode( PaletteButton ); + backmonth->setPixmap( Resource::loadPixmap("fastback") ); + DateBookWeekLstHeaderBaseLayout->setSpacing(0); + DateBookWeekLstHeaderBaseLayout->setMargin(0); + //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding)); + setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); + + connect(backmonth, SIGNAL(clicked()), this, SLOT(prevMonth())); + connect(backweek, SIGNAL(clicked()), this, SLOT(prevWeek())); + connect(forwardweek, SIGNAL(clicked()), this, SLOT(nextWeek())); + connect(forwardmonth, SIGNAL(clicked()), this, SLOT(nextMonth())); + connect(labelDate, SIGNAL(clicked()), this, SLOT(pickDate())); + connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool))); + bStartOnMonday=onM; } DateBookWeekLstHeader::~DateBookWeekLstHeader(){} + void DateBookWeekLstHeader::setDate(const QDate &d) { - date=d; - - int year,week; - calcWeek(d,week,year,onMonday); - labelWeek->setText(tr( "W: %1" ).arg( ( QString::number(week)) ) ); - - 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()) ); - emit dateChanged(year,week); + int year,week,dayofweek; + date=d; + dayofweek=d.dayOfWeek(); + if(bStartOnMonday) dayofweek--; + date=date.addDays(-dayofweek); + + 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 DateBookWeekLstHeader::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( m1, SIGNAL( aboutToHide() ), - //this, SLOT( gotHide() ) ); - } - picker->setDate( date.year(), date.month(), date.day() ); - m1->popup(mapToGlobal(labelWeek->pos()+QPoint(0,labelWeek->height()))); - picker->setFocus(); + 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( m1, SIGNAL( aboutToHide() ), + //this, SLOT( gotHide() ) ); + } + picker->setDate( date.year(), date.month(), date.day() ); + m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height()))); + picker->setFocus(); } void DateBookWeekLstHeader::setDate(int y, int m, int d) { - QDate new_date(y,m,d); - setDate(new_date); + setDate(QDate(y,m,d)); } void DateBookWeekLstHeader::nextWeek() { - setDate(date.addDays(7)); + setDate(date.addDays(7)); } void DateBookWeekLstHeader::prevWeek() { - setDate(date.addDays(-7)); + setDate(date.addDays(-7)); +} +void DateBookWeekLstHeader::nextMonth() +{ + setDate(date.addDays(28)); +} +void DateBookWeekLstHeader::prevMonth() +{ + setDate(date.addDays(-28)); } DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /*onM*/, QWidget* parent, const char* name, WFlags fl ) : DateBookWeekLstDayHdrBase(parent, name, fl) { - date=d; - - static const char *wdays={"MTWTFSS"}; - char day=wdays[d.dayOfWeek()-1]; - - label->setText( QString(QObject::tr(QString(QChar(day)))) + " " + - QString::number(d.day()) ); - add->setText("+"); - - if (d == QDate::currentDate()) { - QPalette pal=label->palette(); - pal.setColor(QColorGroup::Foreground, QColor(0,0,255)); - label->setPalette(pal); - - /* - QFont f=label->font(); - f.setItalic(true); - label->setFont(f); - label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor())); - */ - } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday - QPalette pal=label->palette(); - pal.setColor(QColorGroup::Foreground, QColor(255,0,0)); - label->setPalette(pal); - } - + date=d; + + static const char *wdays={"MTWTFSS"}; + char day=wdays[d.dayOfWeek()-1]; + + label->setText( QString(QObject::tr(QString(QChar(day)))) + " " +QString::number(d.day()) ); + add->setText("+"); + + if (d == QDate::currentDate()) { + QPalette pal=label->palette(); + pal.setColor(QColorGroup::Foreground, QColor(0,0,255)); + label->setPalette(pal); + + /* + QFont f=label->font(); + f.setItalic(true); + label->setFont(f); + label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor())); + */ + } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday + QPalette pal=label->palette(); + pal.setColor(QColorGroup::Foreground, QColor(255,0,0)); + label->setPalette(pal); + } - connect (label, SIGNAL(clicked()), this, SLOT(showDay())); - connect (add, SIGNAL(clicked()), this, SLOT(newEvent())); + connect (label, SIGNAL(clicked()), this, SLOT(showDay())); + connect (add, SIGNAL(clicked()), this, SLOT(newEvent())); } void DateBookWeekLstDayHdr::showDay() { - emit showDate(date.year(), date.month(), date.day()); + emit showDate(date.year(), date.month(), date.day()); } + void DateBookWeekLstDayHdr::newEvent() { QDateTime start, stop; start=stop=date; start.setTime(QTime(10,0)); stop.setTime(QTime(12,0)); emit addEvent(start,stop,"",0); } DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev, int weeklistviewconfig, QWidget* parent, const char* name, @@ -195,47 +207,46 @@ void DateBookWeekLstEvent::editMe() { DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev, const QDate &d, bool onM, QWidget* parent, const char* name, WFlags fl) : QWidget( parent, name, fl ) { Config config("DateBook"); config.setGroup("Main"); int weeklistviewconfig=config.readNumEntry("weeklistviewconfig", NORMAL); qDebug("Read weeklistviewconfig: %d",weeklistviewconfig); - onMonday=onM; + bStartOnMonday=onM; setPalette(white); setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); QVBoxLayout *layout = new QVBoxLayout( this ); qBubbleSort(ev); QValueListIterator<EffectiveEvent> it; it=ev.begin(); int dayOrder[7]; - if (onMonday) { + if (bStartOnMonday) { for (int d=0; d<7; d++) dayOrder[d]=d+1; } else { for (int d=0; d<7; d++) dayOrder[d]=d; dayOrder[0]=7; } for (int i=0; i<7; i++) { // Header - DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i), onMonday,this); - connect(hdr, SIGNAL(showDate(int,int,int)), - this, SIGNAL(showDate(int,int,int))); + DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i), bStartOnMonday,this); + connect(hdr, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); connect(hdr, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); layout->addWidget(hdr); // Events while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) { if(!(((*it).end().hour()==0) && ((*it).end().minute()==0) && ((*it).startDate()!=(*it).date()))) { // Skip events ending at 00:00 starting at another day. DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,weeklistviewconfig,this); layout->addWidget(l); connect (l, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); } it++; @@ -270,95 +281,93 @@ DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); } DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB, QWidget *parent, const char *name ) : QWidget( parent, name ), db( newDB ), startTime( 0 ), ampm( ap ), - onMonday(onM) + bStartOnMonday(onM) { - setFocusPolicy(StrongFocus); - layout = new QVBoxLayout( this ); - layout->setMargin(0); + setFocusPolicy(StrongFocus); + layout = new QVBoxLayout( this ); + layout->setMargin(0); - header=new DateBookWeekLstHeader(onM, this); - layout->addWidget( header ); - connect(header, SIGNAL(dateChanged(int,int)), this, SLOT(dateChanged(int,int))); - connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool))); + header=new DateBookWeekLstHeader(onM, this); + layout->addWidget( header ); + connect(header, SIGNAL(dateChanged(int,int)), this, SLOT(dateChanged(int,int))); + connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool))); scroll=new QScrollView(this); - //scroll->setVScrollBarMode(QScrollView::AlwaysOn); - //scroll->setHScrollBarMode(QScrollView::AlwaysOff); scroll->setResizePolicy(QScrollView::AutoOneFit); layout->addWidget(scroll); view=NULL; Config config("DateBook"); config.setGroup("Main"); dbl=config.readBoolEntry("weeklst_dbl", false); header->dbl->setOn(dbl); } DateBookWeekLst::~DateBookWeekLst(){ Config config("DateBook"); config.setGroup("Main"); config.writeEntry("weeklst_dbl", dbl); } void DateBookWeekLst::setDate(const QDate &d) { int w,y; - calcWeek(d,w,y,onMonday); + calcWeek(d,w,y,bStartOnMonday); year=y; _week=w; header->setDate(date()); } void DateBookWeekLst::setDbl(bool on) { dbl=on; redraw(); } void DateBookWeekLst::redraw() {getEvents();} QDate DateBookWeekLst::date() const { QDate d; d.setYMD(year,1,1); int dow= d.dayOfWeek(); - if (!onMonday) + if (!bStartOnMonday) if (dow==7) { dow=1; } else { dow++; } d=d.addDays( (_week-1)*7 - dow + 1 ); return d; } void DateBookWeekLst::getEvents() { QDate start = date(); QDate stop = start.addDays(6); QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop); if (view) delete view; if (dbl) { QDate start2=start.addDays(7); stop=start2.addDays(6); QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop); - view=new DateBookWeekLstDblView(el,el2,start,onMonday,scroll); + view=new DateBookWeekLstDblView(el,el2,start,bStartOnMonday,scroll); } else { - view=new DateBookWeekLstView(el,start,onMonday,scroll); + view=new DateBookWeekLstView(el,start,bStartOnMonday,scroll); } connect (view, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); connect (view, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); connect (view, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); scroll->addChild(view); view->show(); scroll->updateScrollBars(); } @@ -377,14 +386,13 @@ void DateBookWeekLst::keyPressEvent(QKeyEvent *e) case Key_Down: scroll->scrollBy(0, 20); break; case Key_Left: header->prevWeek(); break; case Key_Right: header->nextWeek(); break; default: e->ignore(); } -} - +}
\ No newline at end of file |