-rw-r--r-- | core/pim/datebook/modules/monthview/odatebookmonth.cpp | 60 | ||||
-rw-r--r-- | core/pim/datebook/modules/monthview/odatebookmonth.h | 2 |
2 files changed, 45 insertions, 17 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 | |||
@@ -177,6 +177,22 @@ void ODateBookMonthTable::findDay( int day, int &row, int &col ) | |||
177 | col = effective_day % 7; | 177 | col = effective_day % 7; |
178 | } | 178 | } |
179 | 179 | ||
180 | bool 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 | |||
180 | void ODateBookMonthTable::dayClicked( int row, int col ) | 196 | void ODateBookMonthTable::dayClicked( int row, int col ) |
181 | { | 197 | { |
182 | changeDaySelection( row, col ); | 198 | changeDaySelection( row, col ); |
@@ -190,31 +206,42 @@ void ODateBookMonthTable::dragDay( int row, int col ) | |||
190 | 206 | ||
191 | void ODateBookMonthTable::changeDaySelection( int row, int col ) | 207 | void 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 | |||
215 | QDate 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 ) { | ||
212 | selMonth = 1; | ||
213 | selYear++; | ||
214 | } | 237 | } |
215 | selDay = i->day(); | 238 | else if ( itemMonth > 12 ) { |
239 | itemMonth = 1; | ||
240 | itemYear++; | ||
216 | } | 241 | } |
217 | 242 | ||
243 | return QDate( itemYear, itemMonth, i->day()); | ||
244 | } | ||
218 | 245 | ||
219 | void ODateBookMonthTable::viewportMouseReleaseEvent( QMouseEvent * ) | 246 | void ODateBookMonthTable::viewportMouseReleaseEvent( QMouseEvent * ) |
220 | { | 247 | { |
@@ -226,10 +253,9 @@ void ODateBookMonthTable::getEvents() | |||
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... |
@@ -245,7 +271,7 @@ void ODateBookMonthTable::getEvents() | |||
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 ); |
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 | |||
@@ -81,8 +81,10 @@ private: | |||
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; |