summaryrefslogtreecommitdiff
authorpaule <paule>2007-01-31 09:30:53 (UTC)
committer paule <paule>2007-01-31 09:30:53 (UTC)
commit6b321230cf24e50b11783b3511a457f22ae79a58 (patch) (unidiff)
tree9d04ba6204bdc7be6b9e4ee2645b00d56a9c6f77
parente9c5c237e27d908c890779215b19c22a3706b614 (diff)
downloadopie-6b321230cf24e50b11783b3511a457f22ae79a58.zip
opie-6b321230cf24e50b11783b3511a457f22ae79a58.tar.gz
opie-6b321230cf24e50b11783b3511a457f22ae79a58.tar.bz2
Show events on all visible days in the month view, not just those within the current month. Fixes bug #1351.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/modules/monthview/odatebookmonth.cpp62
-rw-r--r--core/pim/datebook/modules/monthview/odatebookmonth.h2
2 files changed, 46 insertions, 18 deletions
diff --git a/core/pim/datebook/modules/monthview/odatebookmonth.cpp b/core/pim/datebook/modules/monthview/odatebookmonth.cpp
index d52a092..e4de279 100644
--- a/core/pim/datebook/modules/monthview/odatebookmonth.cpp
+++ b/core/pim/datebook/modules/monthview/odatebookmonth.cpp
@@ -116,197 +116,223 @@ void ODateBookMonthTable::setDate(int y, int m, int d)
116 setupTable(); 116 setupTable();
117 } 117 }
118} 118}
119 119
120void ODateBookMonthTable::redraw() 120void ODateBookMonthTable::redraw()
121{ 121{
122 setupLabels(); 122 setupLabels();
123 setupTable(); 123 setupTable();
124} 124}
125 125
126void ODateBookMonthTable::setWeekStart( bool onMonday ) 126void ODateBookMonthTable::setWeekStart( bool onMonday )
127{ 127{
128 d->onMonday = onMonday; 128 d->onMonday = onMonday;
129 setupLabels(); 129 setupLabels();
130 setupTable(); 130 setupTable();
131} 131}
132 132
133void ODateBookMonthTable::setupTable() 133void ODateBookMonthTable::setupTable()
134{ 134{
135 QValueList<Calendar::Day> days = Calendar::daysOfMonth( year, month, d->onMonday ); 135 QValueList<Calendar::Day> days = Calendar::daysOfMonth( year, month, d->onMonday );
136 QValueList<Calendar::Day>::Iterator it = days.begin(); 136 QValueList<Calendar::Day>::Iterator it = days.begin();
137 int row = 0, col = 0; 137 int row = 0, col = 0;
138 int crow = 0; 138 int crow = 0;
139 int ccol = 0; 139 int ccol = 0;
140 for ( ; it != days.end(); ++it ) { 140 for ( ; it != days.end(); ++it ) {
141 DayItemMonth *i = (DayItemMonth *)item( row, col ); 141 DayItemMonth *i = (DayItemMonth *)item( row, col );
142 if ( !i ) { 142 if ( !i ) {
143 i = new DayItemMonth( this, QTableItem::Never, "" ); 143 i = new DayItemMonth( this, QTableItem::Never, "" );
144 setItem( row, col, i ); 144 setItem( row, col, i );
145 } 145 }
146 Calendar::Day calDay = *it; 146 Calendar::Day calDay = *it;
147 i->clearEffEvents(); 147 i->clearEffEvents();
148 i->setDay( calDay.date ); 148 i->setDay( calDay.date );
149 i->setType( calDay.type ); 149 i->setType( calDay.type );
150 if ( i->day() == day && calDay.type == Calendar::Day::ThisMonth ) { 150 if ( i->day() == day && calDay.type == Calendar::Day::ThisMonth ) {
151 crow = row; 151 crow = row;
152 ccol = col; 152 ccol = col;
153 } 153 }
154 154
155 updateCell( row, col ); 155 updateCell( row, col );
156 156
157 if ( col == 6 ) { 157 if ( col == 6 ) {
158 ++row; 158 ++row;
159 col = 0; 159 col = 0;
160 } else { 160 } else {
161 ++col; 161 ++col;
162 } 162 }
163 } 163 }
164 setCurrentCell( crow, ccol ); 164 setCurrentCell( crow, ccol );
165 getEvents(); 165 getEvents();
166} 166}
167 167
168void ODateBookMonthTable::findDay( int day, int &row, int &col ) 168void ODateBookMonthTable::findDay( int day, int &row, int &col )
169{ 169{
170 QDate dtBegin( year, month, 1 ); 170 QDate dtBegin( year, month, 1 );
171 int skips = dtBegin.dayOfWeek(); 171 int skips = dtBegin.dayOfWeek();
172 int effective_day = day + skips - 1; // row/columns begin at 0 172 int effective_day = day + skips - 1; // row/columns begin at 0
173 // make an extra adjustment if we start on Mondays. 173 // make an extra adjustment if we start on Mondays.
174 if ( d->onMonday ) 174 if ( d->onMonday )
175 effective_day--; 175 effective_day--;
176 row = effective_day / 7; 176 row = effective_day / 7;
177 col = effective_day % 7; 177 col = effective_day % 7;
178} 178}
179 179
180bool ODateBookMonthTable::findDate( QDate date, int &row, int &col )
181{
182 int rows = numRows();
183 int cols = numCols();
184 for(int r=0;r<rows;r++) {
185 for(int c=0;c<cols;c++) {
186 if(getDateAt(r, c) == date) {
187 row = r;
188 col = c;
189 return true;
190 }
191 }
192 }
193 return false;
194}
195
180void ODateBookMonthTable::dayClicked( int row, int col ) 196void ODateBookMonthTable::dayClicked( int row, int col )
181{ 197{
182 changeDaySelection( row, col ); 198 changeDaySelection( row, col );
183 emit dateClicked( selYear, selMonth, selDay ); 199 emit dateClicked( selYear, selMonth, selDay );
184} 200}
185 201
186void ODateBookMonthTable::dragDay( int row, int col ) 202void ODateBookMonthTable::dragDay( int row, int col )
187{ 203{
188 changeDaySelection( row, col ); 204 changeDaySelection( row, col );
189} 205}
190 206
191void ODateBookMonthTable::changeDaySelection( int row, int col ) 207void ODateBookMonthTable::changeDaySelection( int row, int col )
192{ 208{
209 QDate selDate = getDateAt( row, col );
210 selYear = selDate.year();
211 selMonth = selDate.month();
212 selDay = selDate.day();
213}
214
215QDate ODateBookMonthTable::getDateAt( int row, int col )
216{
217 int itemMonth, itemYear;
218
193 DayItemMonth *i = (DayItemMonth*)item( row, col ); 219 DayItemMonth *i = (DayItemMonth*)item( row, col );
194 if ( !i ) 220 if ( !i )
195 return; 221 return QDate(1900, 1, 1);
196 switch ( i->type() ) { 222 switch ( i->type() ) {
197 case Calendar::Day::ThisMonth: 223 case Calendar::Day::ThisMonth:
198 selMonth = month; 224 itemMonth = month;
199 break; 225 break;
200 case Calendar::Day::PrevMonth: 226 case Calendar::Day::PrevMonth:
201 selMonth = month-1; 227 itemMonth = month-1;
202 break; 228 break;
203 default: 229 default:
204 selMonth = month+1; 230 itemMonth = month+1;
205 } 231 }
206 232
207 selYear = year; 233 itemYear = year;
208 if ( selMonth <= 0 ) { 234 if ( itemMonth <= 0 ) {
209 selMonth = 12; 235 itemMonth = 12;
210 selYear--; 236 itemYear--;
211 } else if ( selMonth > 12 ) { 237 }
212 selMonth = 1; 238 else if ( itemMonth > 12 ) {
213 selYear++; 239 itemMonth = 1;
240 itemYear++;
214 } 241 }
215 selDay = i->day();
216}
217 242
243 return QDate( itemYear, itemMonth, i->day());
244}
218 245
219void ODateBookMonthTable::viewportMouseReleaseEvent( QMouseEvent * ) 246void ODateBookMonthTable::viewportMouseReleaseEvent( QMouseEvent * )
220{ 247{
221 dayClicked( currentRow(), currentColumn() ); 248 dayClicked( currentRow(), currentColumn() );
222} 249}
223 250
224void ODateBookMonthTable::getEvents() 251void ODateBookMonthTable::getEvents()
225{ 252{
226 if ( !db ) 253 if ( !db )
227 return; 254 return;
228 255
229 QDate dtStart( year, month, 1 ); 256 QDate dtStart = getDateAt(0,0);
230 d->mMonthEvents = db->getEffectiveEvents( dtStart, 257 QDate dtEnd = getDateAt(numRows()-1, numCols()-1);
231 QDate( year, month, 258 d->mMonthEvents = db->getEffectiveEvents( dtStart, dtEnd);
232 dtStart.daysInMonth() ) );
233 QValueListIterator<EffectiveEvent> it = d->mMonthEvents.begin(); 259 QValueListIterator<EffectiveEvent> it = d->mMonthEvents.begin();
234 // now that the events are sorted, basically go through the list, make 260 // now that the events are sorted, basically go through the list, make
235 // a small list for every day and set it for each item... 261 // a small list for every day and set it for each item...
236 // clear all the items... 262 // clear all the items...
237 while ( it != d->mMonthEvents.end() ) { 263 while ( it != d->mMonthEvents.end() ) {
238 QValueList<EffectiveEvent> dayEvent; 264 QValueList<EffectiveEvent> dayEvent;
239 EffectiveEvent e = *it; 265 EffectiveEvent e = *it;
240 ++it; 266 ++it;
241 dayEvent.append( e ); 267 dayEvent.append( e );
242 while ( it != d->mMonthEvents.end() 268 while ( it != d->mMonthEvents.end()
243 && e.date() == (*it).date() ) { 269 && e.date() == (*it).date() ) {
244 dayEvent.append( *it ); 270 dayEvent.append( *it );
245 ++it; 271 ++it;
246 } 272 }
247 int row, col; 273 int row, col;
248 findDay( e.date().day(), row, col ); 274 findDate( e.date(), row, col );
249 DayItemMonth* w = static_cast<DayItemMonth*>( item( row, col ) ); 275 DayItemMonth* w = static_cast<DayItemMonth*>( item( row, col ) );
250 w->setEvents( dayEvent ); 276 w->setEvents( dayEvent );
251 updateCell( row, col ); 277 updateCell( row, col );
252 dayEvent.clear(); 278 dayEvent.clear();
253 } 279 }
254} 280}
255 281
256 282
257void ODateBookMonthTable::setupLabels() 283void ODateBookMonthTable::setupLabels()
258{ 284{
259 for ( int i = 0; i < 7; ++i ) { 285 for ( int i = 0; i < 7; ++i ) {
260// horizontalHeader()->resizeSection( i, 30 ); 286// horizontalHeader()->resizeSection( i, 30 );
261// setColumnStretchable( i, TRUE ); 287// setColumnStretchable( i, TRUE );
262 if ( d->onMonday ) 288 if ( d->onMonday )
263 horizontalHeader()->setLabel( i, Calendar::nameOfDay( i + 1 ) ); 289 horizontalHeader()->setLabel( i, Calendar::nameOfDay( i + 1 ) );
264 else { 290 else {
265 if ( i == 0 ) 291 if ( i == 0 )
266 horizontalHeader()->setLabel( i, Calendar::nameOfDay( 7 ) ); 292 horizontalHeader()->setLabel( i, Calendar::nameOfDay( 7 ) );
267 else 293 else
268 horizontalHeader()->setLabel( i, Calendar::nameOfDay( i ) ); 294 horizontalHeader()->setLabel( i, Calendar::nameOfDay( i ) );
269 } 295 }
270 } 296 }
271} 297}
272 298
273 299
274//--------------------------------------------------------------------------- 300//---------------------------------------------------------------------------
275 301
276ODateBookMonth::ODateBookMonth( QWidget *parent, const char *name, bool ac, 302ODateBookMonth::ODateBookMonth( QWidget *parent, const char *name, bool ac,
277 DateBookDBHoliday *data ) 303 DateBookDBHoliday *data )
278 : QVBox( parent, name ), 304 : QVBox( parent, name ),
279 autoClose( ac ) 305 autoClose( ac )
280{ 306{
281 setFocusPolicy(StrongFocus); 307 setFocusPolicy(StrongFocus);
282 year = QDate::currentDate().year(); 308 year = QDate::currentDate().year();
283 month = QDate::currentDate().month(); 309 month = QDate::currentDate().month();
284 day = QDate::currentDate().day(); 310 day = QDate::currentDate().day();
285 header = new DateBookMonthHeader( this, "DateBookMonthHeader" ); 311 header = new DateBookMonthHeader( this, "DateBookMonthHeader" );
286 table = new ODateBookMonthTable( this, "DateBookMonthTable", data ); 312 table = new ODateBookMonthTable( this, "DateBookMonthTable", data );
287 header->setDate( year, month ); 313 header->setDate( year, month );
288 table->setDate( year, month, QDate::currentDate().day() ); 314 table->setDate( year, month, QDate::currentDate().day() );
289 header->setFocusPolicy(NoFocus); 315 header->setFocusPolicy(NoFocus);
290 table->setFocusPolicy(NoFocus); 316 table->setFocusPolicy(NoFocus);
291 connect( header, SIGNAL( dateChanged(int,int) ), 317 connect( header, SIGNAL( dateChanged(int,int) ),
292 this, SLOT( setDate(int,int) ) ); 318 this, SLOT( setDate(int,int) ) );
293 connect( table, SIGNAL( dateClicked(int,int,int) ), 319 connect( table, SIGNAL( dateClicked(int,int,int) ),
294 this, SLOT( finalDate(int,int,int) ) ); 320 this, SLOT( finalDate(int,int,int) ) );
295 connect( qApp, SIGNAL(weekChanged(bool)), this, 321 connect( qApp, SIGNAL(weekChanged(bool)), this,
296 SLOT(slotWeekChange(bool)) ); 322 SLOT(slotWeekChange(bool)) );
297 table->setFocus(); 323 table->setFocus();
298} 324}
299 325
300ODateBookMonth::~ODateBookMonth() 326ODateBookMonth::~ODateBookMonth()
301{ 327{
302 328
303} 329}
304 330
305void ODateBookMonth::setDate( int y, int m ) 331void ODateBookMonth::setDate( int y, int m )
306{ 332{
307 /* only change the date if this is a different date, 333 /* only change the date if this is a different date,
308 * other wise we may mistakenly overide the day */ 334 * other wise we may mistakenly overide the day */
309 if ( (y != year) || (m != month) ) { 335 if ( (y != year) || (m != month) ) {
310 year = y; 336 year = y;
311 month = m; 337 month = m;
312 QDate nd( y, m, 1 ); 338 QDate nd( y, m, 1 );
diff --git a/core/pim/datebook/modules/monthview/odatebookmonth.h b/core/pim/datebook/modules/monthview/odatebookmonth.h
index e967abe..a81a161 100644
--- a/core/pim/datebook/modules/monthview/odatebookmonth.h
+++ b/core/pim/datebook/modules/monthview/odatebookmonth.h
@@ -20,113 +20,115 @@
20** not clear to you. 20** not clear to you.
21** 21**
22**********************************************************************/ 22**********************************************************************/
23#ifndef ODATEBOOKMONTH 23#ifndef ODATEBOOKMONTH
24#define ODATEBOOKMONTH 24#define ODATEBOOKMONTH
25 25
26#include <qtopia/private/event.h> 26#include <qtopia/private/event.h>
27#include <qpe/datebookmonth.h> 27#include <qpe/datebookmonth.h>
28 28
29#include <qvbox.h> 29#include <qvbox.h>
30#include <qhbox.h> 30#include <qhbox.h>
31#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qvaluelist.h> 32#include <qvaluelist.h>
33#include <qtable.h> 33#include <qtable.h>
34#include <qpushbutton.h> 34#include <qpushbutton.h>
35#include <qpopupmenu.h> 35#include <qpopupmenu.h>
36 36
37#include <qpe/calendar.h> 37#include <qpe/calendar.h>
38#include <qpe/timestring.h> 38#include <qpe/timestring.h>
39 39
40class QToolButton; 40class QToolButton;
41class QComboBox; 41class QComboBox;
42class QSpinBox; 42class QSpinBox;
43class Event; 43class Event;
44class DateBookDB; 44class DateBookDB;
45class DateBookDBHoliday; 45class DateBookDBHoliday;
46 46
47class ODateBookMonthTablePrivate; 47class ODateBookMonthTablePrivate;
48class ODateBookMonthTable : public QTable 48class ODateBookMonthTable : public QTable
49{ 49{
50 Q_OBJECT 50 Q_OBJECT
51 51
52public: 52public:
53 ODateBookMonthTable( QWidget *parent = 0, const char *name = 0, 53 ODateBookMonthTable( QWidget *parent = 0, const char *name = 0,
54 DateBookDBHoliday *newDb = 0 ); 54 DateBookDBHoliday *newDb = 0 );
55 virtual ~ODateBookMonthTable(); 55 virtual ~ODateBookMonthTable();
56 void setDate( int y, int m, int d ); 56 void setDate( int y, int m, int d );
57 void redraw(); 57 void redraw();
58 58
59 QSize minimumSizeHint() const { return sizeHint(); } 59 QSize minimumSizeHint() const { return sizeHint(); }
60 QSize minimumSize() const { return sizeHint(); } 60 QSize minimumSize() const { return sizeHint(); }
61 void getDate( int& y, int &m, int &d ) const {y=selYear;m=selMonth;d=selDay;} 61 void getDate( int& y, int &m, int &d ) const {y=selYear;m=selMonth;d=selDay;}
62 void setWeekStart( bool onMonday ); 62 void setWeekStart( bool onMonday );
63signals: 63signals:
64 void dateClicked( int year, int month, int day ); 64 void dateClicked( int year, int month, int day );
65 65
66protected: 66protected:
67 virtual void viewportMouseReleaseEvent( QMouseEvent * ); 67 virtual void viewportMouseReleaseEvent( QMouseEvent * );
68 68
69protected slots: 69protected slots:
70 70
71 virtual void keyPressEvent(QKeyEvent *e ) { 71 virtual void keyPressEvent(QKeyEvent *e ) {
72 e->ignore(); 72 e->ignore();
73 } 73 }
74 74
75private slots: 75private slots:
76 void dayClicked( int row, int col ); 76 void dayClicked( int row, int col );
77 void dragDay( int row, int col ); 77 void dragDay( int row, int col );
78 78
79private: 79private:
80 void setupTable(); 80 void setupTable();
81 void setupLabels(); 81 void setupLabels();
82 82
83 void findDay( int day, int &row, int &col ); 83 void findDay( int day, int &row, int &col );
84 bool findDate( QDate date, int &row, int &col );
84 void getEvents(); 85 void getEvents();
85 void changeDaySelection( int row, int col ); 86 void changeDaySelection( int row, int col );
87 QDate getDateAt( int row, int col );
86 88
87 int year, month, day; 89 int year, month, day;
88 int selYear, selMonth, selDay; 90 int selYear, selMonth, selDay;
89 QValueList<Event> monthsEvents; // not used anymore... 91 QValueList<Event> monthsEvents; // not used anymore...
90 DateBookDBHoliday *db; 92 DateBookDBHoliday *db;
91 ODateBookMonthTablePrivate *d; 93 ODateBookMonthTablePrivate *d;
92}; 94};
93 95
94class ODateBookMonthPrivate; 96class ODateBookMonthPrivate;
95class ODateBookMonth : public QVBox 97class ODateBookMonth : public QVBox
96{ 98{
97 Q_OBJECT 99 Q_OBJECT
98 100
99public: 101public:
100 /* ac = Auto Close */ 102 /* ac = Auto Close */
101 ODateBookMonth( QWidget *parent = 0, const char *name = 0, bool ac = FALSE, 103 ODateBookMonth( QWidget *parent = 0, const char *name = 0, bool ac = FALSE,
102 DateBookDBHoliday *data = 0 ); 104 DateBookDBHoliday *data = 0 );
103 virtual ~ODateBookMonth(); 105 virtual ~ODateBookMonth();
104 QDate selectedDate() const; 106 QDate selectedDate() const;
105 107
106signals: 108signals:
107 /* ### FIXME add a signal with QDate -zecke */ 109 /* ### FIXME add a signal with QDate -zecke */
108 void dateClicked( int year, int month, int day ); 110 void dateClicked( int year, int month, int day );
109 111
110public slots: 112public slots:
111 void setDate( int y, int m ); 113 void setDate( int y, int m );
112 void setDate( int y, int m, int d ); 114 void setDate( int y, int m, int d );
113 void setDate( QDate ); 115 void setDate( QDate );
114 void redraw(); 116 void redraw();
115 void slotWeekChange( bool ); 117 void slotWeekChange( bool );
116 118
117protected slots: 119protected slots:
118 virtual void keyPressEvent(QKeyEvent *e); 120 virtual void keyPressEvent(QKeyEvent *e);
119 121
120private slots: 122private slots:
121 void forwardDateClicked( int y, int m, int d ) { emit dateClicked( y, m, d ); } 123 void forwardDateClicked( int y, int m, int d ) { emit dateClicked( y, m, d ); }
122 void finalDate(int, int, int); 124 void finalDate(int, int, int);
123 125
124private: 126private:
125 DateBookMonthHeader *header; 127 DateBookMonthHeader *header;
126 ODateBookMonthTable *table; 128 ODateBookMonthTable *table;
127 int year, month, day; 129 int year, month, day;
128 bool autoClose; 130 bool autoClose;
129 class ODateBookMonthPrivate *d; 131 class ODateBookMonthPrivate *d;
130}; 132};
131 133
132#endif 134#endif