Diffstat (limited to 'core/pim/datebook/modules/weeklst/datebookweeklst.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/datebook/modules/weeklst/datebookweeklst.cpp | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/core/pim/datebook/modules/weeklst/datebookweeklst.cpp b/core/pim/datebook/modules/weeklst/datebookweeklst.cpp new file mode 100644 index 0000000..47bc597 --- a/dev/null +++ b/core/pim/datebook/modules/weeklst/datebookweeklst.cpp | |||
@@ -0,0 +1,138 @@ | |||
1 | #include "namespace_hack.h" | ||
2 | #include "datebookweeklst.h" | ||
3 | #include "datebookweeklstheader.h" | ||
4 | #include "datebookweeklstview.h" | ||
5 | #include "datebookweeklstdblview.h" | ||
6 | |||
7 | #include "datebook.h" | ||
8 | |||
9 | #include <opie2/odebug.h> | ||
10 | |||
11 | #include <qpe/datebookmonth.h> | ||
12 | #include <qpe/config.h> | ||
13 | #include <qpe/resource.h> | ||
14 | |||
15 | #include <qlayout.h> | ||
16 | #include <qtoolbutton.h> | ||
17 | |||
18 | using namespace Opie::Ui; | ||
19 | |||
20 | DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDBHoliday *newDB, | ||
21 | QWidget *parent, | ||
22 | const char *name ) | ||
23 | : QWidget( parent, name ), | ||
24 | db( newDB ), | ||
25 | startTime( 0 ), | ||
26 | ampm( ap ), | ||
27 | bStartOnMonday(onM) | ||
28 | { | ||
29 | setFocusPolicy(StrongFocus); | ||
30 | layout = new QVBoxLayout( this ); | ||
31 | layout->setMargin(0); | ||
32 | |||
33 | header=new DateBookWeekLstHeader(onM, this); | ||
34 | layout->addWidget( header ); | ||
35 | connect(header, SIGNAL(dateChanged(QDate&)), this, SLOT(dateChanged(QDate&))); | ||
36 | connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool))); | ||
37 | |||
38 | scroll=new QScrollView(this); | ||
39 | scroll->setResizePolicy(QScrollView::AutoOneFit); | ||
40 | layout->addWidget(scroll); | ||
41 | |||
42 | view=NULL; | ||
43 | Config config("DateBook"); | ||
44 | config.setGroup("Main"); | ||
45 | dbl=config.readBoolEntry("weeklst_dbl", false); | ||
46 | header->dbl->setOn(dbl); | ||
47 | } | ||
48 | DateBookWeekLst::~DateBookWeekLst(){ | ||
49 | Config config("DateBook"); | ||
50 | config.setGroup("Main"); | ||
51 | config.writeEntry("weeklst_dbl", dbl); | ||
52 | } | ||
53 | |||
54 | void DateBookWeekLst::setDate(const QDate &d) { | ||
55 | bdate=d; | ||
56 | header->setDate(d); | ||
57 | } | ||
58 | |||
59 | void DateBookWeekLst::setDbl(bool on) { | ||
60 | dbl=on; | ||
61 | redraw(); | ||
62 | } | ||
63 | void DateBookWeekLst::redraw() {getEvents();} | ||
64 | |||
65 | QDate DateBookWeekLst::date() { | ||
66 | return bdate; | ||
67 | } | ||
68 | |||
69 | // return the date at the beginning of the week... | ||
70 | // copied from DateBookWeek | ||
71 | QDate DateBookWeekLst::weekDate() const | ||
72 | { | ||
73 | QDate d=bdate; | ||
74 | |||
75 | // Calculate offset to first day of week. | ||
76 | int dayoffset=d.dayOfWeek(); | ||
77 | if(bStartOnMonday) dayoffset--; | ||
78 | else if( dayoffset == 7 ) | ||
79 | dayoffset = 0; | ||
80 | |||
81 | return d.addDays(-dayoffset); | ||
82 | } | ||
83 | |||
84 | void DateBookWeekLst::getEvents() { | ||
85 | QDate start = weekDate(); //date(); | ||
86 | QDate stop = start.addDays(6); | ||
87 | QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop); | ||
88 | |||
89 | setUpdatesEnabled(false); | ||
90 | if (view) delete view; | ||
91 | if (dbl) { | ||
92 | QDate start2=start.addDays(7); | ||
93 | stop=start2.addDays(6); | ||
94 | QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop); | ||
95 | view=new DateBookWeekLstDblView(el,el2,start,bStartOnMonday,scroll); | ||
96 | } else { | ||
97 | view=new DateBookWeekLstView(el,start,bStartOnMonday,scroll); | ||
98 | } | ||
99 | |||
100 | connect (view, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); | ||
101 | connect (view, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &))); | ||
102 | connect (view, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &))); | ||
103 | connect (view, SIGNAL(beamEvent(const Event &)), this, SIGNAL(beamEvent(const Event &))); | ||
104 | connect (view, SIGNAL(redraw()), this, SLOT(redraw())); | ||
105 | connect (view, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); | ||
106 | connect (view, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), | ||
107 | this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); | ||
108 | |||
109 | scroll->addChild(view); | ||
110 | view->show(); | ||
111 | scroll->updateScrollBars(); | ||
112 | setUpdatesEnabled(true); | ||
113 | } | ||
114 | |||
115 | void DateBookWeekLst::dateChanged(QDate &newdate) { | ||
116 | bdate=newdate; | ||
117 | getEvents(); | ||
118 | } | ||
119 | |||
120 | void DateBookWeekLst::keyPressEvent(QKeyEvent *e) | ||
121 | { | ||
122 | switch(e->key()) { | ||
123 | case Key_Up: | ||
124 | scroll->scrollBy(0, -20); | ||
125 | break; | ||
126 | case Key_Down: | ||
127 | scroll->scrollBy(0, 20); | ||
128 | break; | ||
129 | case Key_Left: | ||
130 | header->prevWeek(); | ||
131 | break; | ||
132 | case Key_Right: | ||
133 | header->nextWeek(); | ||
134 | break; | ||
135 | default: | ||
136 | e->ignore(); | ||
137 | } | ||
138 | } | ||