summaryrefslogtreecommitdiff
path: root/core/pim/datebook/modules/weeklst/datebookweeklst.cpp
Unidiff
Diffstat (limited to 'core/pim/datebook/modules/weeklst/datebookweeklst.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/pim/datebook/modules/weeklst/datebookweeklst.cpp61
1 files changed, 41 insertions, 20 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
@@ -18,111 +18,132 @@
18using namespace Opie::Ui; 18using namespace Opie::Ui;
19 19
20DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDBHoliday *newDB, 20DateBookWeekLst::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
48DateBookWeekLst::~DateBookWeekLst(){ 50DateBookWeekLst::~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
54void DateBookWeekLst::setDate(const QDate &d) { 56void DateBookWeekLst::setDate(const QDate &d) {
55 bdate=d; 57 bdate=d;
56 header->setDate(d); 58 header->setDate(d);
57} 59}
58 60
59void DateBookWeekLst::setDbl(bool on) { 61void 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
63void DateBookWeekLst::redraw() {getEvents();} 72void DateBookWeekLst::redraw() {getEvents();}
64 73
65QDate DateBookWeekLst::date() { 74QDate 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
71QDate DateBookWeekLst::weekDate() const 80QDate 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
84void DateBookWeekLst::getEvents() { 93void 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);
96 } else { 111 } else {
97 view=new DateBookWeekLstView(el,start,bStartOnMonday,scroll); 112 m_CurrentView=new DateBookWeekLstDblView(el,start,bStartOnMonday,scroll);
98 } 113 }
99 114 m_CurrentView->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
100 connect (view, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); 115 connect (m_CurrentView, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&)));
101 connect (view, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &))); 116 connect (m_CurrentView, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &)));
102 connect (view, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &))); 117 connect (m_CurrentView, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &)));
103 connect (view, SIGNAL(beamEvent(const Event &)), this, SIGNAL(beamEvent(const Event &))); 118 connect (m_CurrentView, SIGNAL(beamEvent(const Event &)), this, SIGNAL(beamEvent(const Event &)));
104 connect (view, SIGNAL(redraw()), this, SLOT(redraw())); 119 connect (m_CurrentView, SIGNAL(redraw()), this, SLOT(redraw()));
105 connect (view, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); 120 connect (m_CurrentView, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int)));
106 connect (view, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), 121 connect (m_CurrentView, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)),
107 this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); 122 this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)));
108 123 scroll->addChild(m_CurrentView);
109 scroll->addChild(view); 124 } else {
110 view->show(); 125 if (dbl) {
126 m_CurrentView->setEvents(el,el2,start,bStartOnMonday);
127 } else {
128 m_CurrentView->setEvents(el,start,bStartOnMonday);
129 }
130 }
111 scroll->updateScrollBars(); 131 scroll->updateScrollBars();
112 setUpdatesEnabled(true);
113} 132}
114 133
115void DateBookWeekLst::dateChanged(QDate &newdate) { 134void 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
120void DateBookWeekLst::keyPressEvent(QKeyEvent *e) 141void 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;