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