summaryrefslogtreecommitdiff
path: root/core/pim/datebook/datebookweeklst.cpp
Side-by-side diff
Diffstat (limited to 'core/pim/datebook/datebookweeklst.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebookweeklst.cpp76
1 files changed, 32 insertions, 44 deletions
diff --git a/core/pim/datebook/datebookweeklst.cpp b/core/pim/datebook/datebookweeklst.cpp
index a39ff40..7817042 100644
--- a/core/pim/datebook/datebookweeklst.cpp
+++ b/core/pim/datebook/datebookweeklst.cpp
@@ -69,13 +69,13 @@ void DateBookWeekLstHeader::setDate(const QDate &d) {
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);
+ emit dateChanged(date);
}
void DateBookWeekLstHeader::pickDate() {
static QPopupMenu *m1 = 0;
static DateBookMonth *picker = 0;
if ( !m1 ) {
@@ -106,21 +106,21 @@ void DateBookWeekLstHeader::nextMonth()
}
void DateBookWeekLstHeader::prevMonth()
{
setDate(date.addDays(-28));
}
-DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /*onM*/,
+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"};
+ static const char *wdays={"MTWTFSSM"};
char day=wdays[d.dayOfWeek()-1];
label->setText( QString(QObject::tr(QString(QChar(day)))) + " " +QString::number(d.day()) );
add->setText("+");
if (d == QDate::currentDate()) {
@@ -231,31 +231,34 @@ DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev,
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++) {
+ // Calculate offset to first day of week.
+ int dayoffset=d.dayOfWeek();
+ if(bStartOnMonday) dayoffset--;
+
+ for (int i=0; i<7; i++) {
// Header
- 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 &)));
+ DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i-dayoffset), 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++;
}
- it++;
- }
-
- layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding));
+ layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding));
}
}
DateBookWeekLstView::~DateBookWeekLstView(){}
void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();}
DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1,
@@ -295,13 +298,13 @@ DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB,
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(dateChanged(QDate &)), this, SLOT(dateChanged(QDate &)));
connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool)));
scroll=new QScrollView(this);
scroll->setResizePolicy(QScrollView::AutoOneFit);
layout->addWidget(scroll);
@@ -315,38 +318,24 @@ 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,bStartOnMonday);
- year=y;
- _week=w;
- header->setDate(date());
+ bdate=d;
+ header->setDate(d);
}
+
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 (!bStartOnMonday)
- if (dow==7) {
- dow=1;
- } else {
- dow++;
- }
-
- d=d.addDays( (_week-1)*7 - dow + 1 );
- return d;
+QDate DateBookWeekLst::date() {
+ return bdate;
}
void DateBookWeekLst::getEvents() {
QDate start = date();
QDate stop = start.addDays(6);
QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop);
@@ -368,15 +357,14 @@ void DateBookWeekLst::getEvents() {
scroll->addChild(view);
view->show();
scroll->updateScrollBars();
}
-void DateBookWeekLst::dateChanged(int y, int w) {
- year=y;
- _week=w;
+void DateBookWeekLst::dateChanged(QDate &newdate) {
+ bdate=newdate;
getEvents();
}
void DateBookWeekLst::keyPressEvent(QKeyEvent *e)
{
switch(e->key()) {
@@ -392,7 +380,7 @@ void DateBookWeekLst::keyPressEvent(QKeyEvent *e)
case Key_Right:
header->nextWeek();
break;
default:
e->ignore();
}
-} \ No newline at end of file
+}