112 |
108 |
113 /*! |
109 /*! |
114 Updates the model with the proper dates and sets the required user roles |
110 Updates the model with the proper dates and sets the required user roles |
115 */ |
111 */ |
116 void CalenMonthGrid::updateMonthGridModel(QList<CalenMonthData> &monthDataArray, |
112 void CalenMonthGrid::updateMonthGridModel(QList<CalenMonthData> &monthDataArray, |
117 int indexToBeScrolled) |
113 int indexToBeScrolled, bool isFirstTime) |
118 { |
114 { |
119 // Check the counts |
115 int loopStart = 0; |
120 int dataCount = monthDataArray.count(); |
116 int loopEnd = monthDataArray.count(); |
121 int rowCount = mModel->rowCount(); |
117 if (isFirstTime) { |
122 int countDiff = dataCount - rowCount; |
118 // Create the model with only 42 items as visible to the user |
123 if (countDiff < 0) { |
119 mModel = new QStandardItemModel(KCalenDaysInWeek * KNumOfVisibleRows, |
124 // Delete extra rows in the model |
120 1, this); |
125 mModel->removeRows(dataCount,abs(countDiff)); |
121 loopStart = (mView->rowsInPrevMonth()) * KCalenDaysInWeek; |
126 } else if (countDiff > 0) { |
122 loopEnd = loopStart + (KCalenDaysInWeek * KNumOfVisibleRows); |
127 // Add the necessary number of rows |
123 } else { |
128 mModel->insertRows(rowCount,countDiff); |
124 // Block the signals generated by model, this is being done as |
129 } |
125 // we want to avoid the overload of view listening to signals |
|
126 mModel->blockSignals(true); |
|
127 |
|
128 // Check the counts |
|
129 int dataCount = monthDataArray.count(); |
|
130 int rowCount = mModel->rowCount(); |
|
131 int countDiff = dataCount - rowCount; |
|
132 if (countDiff < 0) { |
|
133 // Delete extra rows in the model |
|
134 mModel->removeRows(dataCount,abs(countDiff)); |
|
135 } else if (countDiff > 0) { |
|
136 // Add the necessary number of rows |
|
137 mModel->insertRows(rowCount,countDiff); |
|
138 } |
|
139 loopEnd = dataCount; |
|
140 } |
|
141 |
130 QDateTime currDate = mView->getCurrentDay(); |
142 QDateTime currDate = mView->getCurrentDay(); |
131 QDateTime currDateTime = CalenDateUtils::beginningOfDay(currDate); |
143 QDateTime currDateTime = CalenDateUtils::beginningOfDay(currDate); |
132 QDateTime activeDay = mView->getActiveDay(); |
144 QDateTime activeDay = mView->getActiveDay(); |
133 QDateTime activeDateTime = CalenDateUtils::beginningOfDay(activeDay); |
145 QDateTime activeDateTime = CalenDateUtils::beginningOfDay(activeDay); |
134 |
146 |
135 QModelIndex currentIndex; |
147 QModelIndex currentIndex; |
136 |
148 int modelIndex = 0; |
137 // Get the default text color to be set |
149 for (int i = loopStart; i < loopEnd; i++) { |
138 QColor textColor = HbColorScheme::color("qtc_cal_month_notactive_dates"); |
|
139 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
140 for (int i = 0; i < dataCount; i++) { |
|
141 QDateTime dateTime = monthDataArray[i].Day(); |
150 QDateTime dateTime = monthDataArray[i].Day(); |
142 currentIndex = mModel->index(i, 0); |
151 currentIndex = mModel->index(modelIndex++, 0); |
143 // Get the localised string for the day |
|
144 QString date = locale.toString(dateTime.date().day()); |
|
145 |
152 |
146 // Create the variant list to contain the date to depict a grid item |
153 // Create the variant list to contain the date to depict a grid item |
147 QVariantList itemData; |
154 QVariantList itemData; |
148 |
155 |
149 // NOTE: Add the data in the order mentioned in the |
156 // !!!NOTE!!!: Add the data in the order mentioned in the |
150 // CalendarNamespace::DataRole enum. Dont change the order. |
157 // CalendarNamespace::DataRole enum. Dont change the order. |
151 itemData << date; |
158 itemData << mLocalisedDates.at(dateTime.date().day()-1); |
152 |
159 |
153 // Check for active day |
160 // Check for active day |
154 if (activeDateTime == CalenDateUtils::beginningOfDay(dateTime)) { |
161 if (activeDateTime == CalenDateUtils::beginningOfDay(dateTime)) { |
155 mCurrentRow = currentIndex.row(); |
162 mCurrentRow = i; |
156 // Set the focus icon |
163 // Set the focus attribute to true |
157 itemData << QString("qtg_fr_cal_focused_day_ind"); |
164 itemData << true; |
158 } else { |
165 } else { |
159 // reset the highlight |
166 // reset the highlight |
160 itemData << QString(""); |
167 itemData << false; |
161 } |
168 } |
162 |
169 |
163 // Check for current day |
170 // Check for current day |
164 if (currDateTime == CalenDateUtils::beginningOfDay(dateTime)) { |
171 if (currDateTime == CalenDateUtils::beginningOfDay(dateTime)) { |
165 // Set the underline icon |
172 // Set the underline attribute to true |
166 itemData << true; |
173 itemData << true; |
167 } else { |
174 } else { |
168 itemData << false; |
175 itemData << false; |
169 } |
176 } |
170 |
177 |
171 // Check for events |
178 // Check for events |
172 if (monthDataArray[i].HasEvents()) { |
179 if (monthDataArray[i].HasEvents()) { |
173 // Set the underline icon |
180 // Set the event indicator attribute |
174 itemData << QString("qtg_graf_cal_event_ind"); |
181 itemData << true; |
175 } else { |
182 } else { |
176 itemData << QString(""); |
183 itemData << false; |
177 } |
184 } |
178 |
185 |
179 // Add default text color |
186 // Add default text color |
180 itemData << textColor; |
187 if (monthDataArray[i].isActive()) { |
|
188 itemData << true; |
|
189 } else { |
|
190 itemData << false; |
|
191 } |
181 mModel->itemFromIndex(currentIndex)->setData(itemData); |
192 mModel->itemFromIndex(currentIndex)->setData(itemData); |
182 } |
193 } |
|
194 |
|
195 if (isFirstTime) { |
|
196 // Color of the today indicator |
|
197 QColor todayIndColor = HbColorScheme::color("qtc_cal_month_current_day"); |
|
198 // Color of the active dates |
|
199 QColor mActiveTextColor = |
|
200 HbColorScheme::color("qtc_cal_month_active_dates"); |
|
201 // Color of the inactive dates |
|
202 QColor mInActiveTextColor = |
|
203 HbColorScheme::color("qtc_cal_month_notactive_dates"); |
|
204 |
|
205 // Create the prototype |
|
206 CalenGridItemPrototype* gridItemPrototype = new CalenGridItemPrototype( |
|
207 todayIndColor, mActiveTextColor, mInActiveTextColor, this); |
|
208 |
|
209 // Set the mode and the prototype |
|
210 setModel(mModel,gridItemPrototype); |
|
211 |
|
212 // Register the widgetml and css files |
|
213 HbStyleLoader::registerFilePath(":/"); |
|
214 |
|
215 // Set the layout name |
|
216 setLayoutName("calendarCustomGridItem"); |
|
217 } else { |
|
218 // Since, we have finished setData, Now unblock the signals |
|
219 mModel->blockSignals(false); |
|
220 |
|
221 // Since till now, we had blocked signals being generated frm the mode |
|
222 // view will be unaware of the items that we added. Hence, inform the view |
|
223 // explicitly in one shot |
|
224 QModelIndex leftIndex = mModel->index(0, 0); |
|
225 QModelIndex rightIndex = mModel->index(loopEnd-1, 0); |
|
226 dataChanged(leftIndex, rightIndex); |
|
227 |
|
228 // NOTE: To make sure that we always display proper month, |
|
229 // two calls have been made to scrollTo(), one with top |
|
230 // visible item and other with bottom visible item |
|
231 // Calculate the first visible item in the grid |
|
232 QModelIndex firstVisibleIndex = mModel->index(indexToBeScrolled - |
|
233 (KNumOfVisibleRows * KCalenDaysInWeek - 1), 0); |
|
234 scrollTo(firstVisibleIndex); |
|
235 |
|
236 |
|
237 // Calculate the last visible item in the grid |
|
238 QModelIndex lastVisibleIndex = mModel->index(indexToBeScrolled, 0); |
|
239 scrollTo(lastVisibleIndex); |
|
240 } |
183 mMonthDataArray = monthDataArray; |
241 mMonthDataArray = monthDataArray; |
184 |
242 } |
185 // Get the active month |
243 |
186 QDateTime activeDate = mView->getActiveDay(); |
244 /*! |
187 // Set the text color properly |
245 Updates the view with jprevious month dates when calendar is opened for the |
188 setActiveDates(activeDate.date()); |
246 first time to improve the opening time |
189 |
247 */ |
190 // NOTE: To make sure that we always display proper month, |
248 void CalenMonthGrid::updateMonthGridWithInActiveMonths( |
191 // two calls have been made to scrollTo(), one with top |
249 QList<CalenMonthData> &monthDataArray) |
192 // visible item and other with bottom visible item |
250 { |
193 // Calculate the first visible item in the grid |
251 mMonthDataArray = monthDataArray; |
194 QModelIndex firstVisibleIndex = mModel->index(indexToBeScrolled - |
252 |
195 (KNumOfVisibleRows * KCalenDaysInWeek - 1), 0); |
253 // Prepend the required rows |
196 scrollTo(firstVisibleIndex); |
254 handlePrependingRows(monthDataArray); |
197 |
255 |
198 |
256 // Append the required rows |
199 // Calculate the last visible item in the grid |
257 handleAppendingRows(monthDataArray); |
200 QModelIndex lastVisibleIndex = mModel->index(indexToBeScrolled, 0); |
258 |
201 scrollTo(lastVisibleIndex); |
259 int rowsInPrevMonth = mView->rowsInPrevMonth(); |
|
260 |
|
261 // Calculate the proper index to be scrolled to |
|
262 int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek; |
|
263 QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
|
264 mIsAtomicScroll = true; |
|
265 scrollTo(indexToBeScrolled); |
|
266 |
|
267 // Scroll to proper index |
|
268 itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * |
|
269 KCalenDaysInWeek) - 1; |
|
270 indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
|
271 mIsAtomicScroll = true; |
|
272 scrollTo(indexToBeScrolled); |
|
273 } |
|
274 |
|
275 /*! |
|
276 Updates the view with just event indicators |
|
277 */ |
|
278 void CalenMonthGrid::updateMonthGridWithEventIndicators( |
|
279 QList<CalenMonthData> &monthDataArray) |
|
280 { |
|
281 mMonthDataArray = monthDataArray; |
|
282 for(int i = 0; i < monthDataArray.count(); i++) { |
|
283 // Check if the day has events |
|
284 if (monthDataArray[i].HasEvents()) { |
|
285 QModelIndex itemIndex = mModel->index(i,0); |
|
286 QVariant itemData = itemIndex.data(Qt::UserRole + 1); |
|
287 QVariantList list = itemData.toList(); |
|
288 list.replace(CalendarNamespace::CalendarMonthEventRole, true); |
|
289 mModel->itemFromIndex(itemIndex)->setData(list); |
|
290 } |
|
291 } |
202 } |
292 } |
203 |
293 |
204 /*! |
294 /*! |
205 Listens for down gesture |
295 Listens for down gesture |
206 */ |
296 */ |
207 void CalenMonthGrid::downGesture (int value) |
297 void CalenMonthGrid::downGesture (int value) |
208 { |
298 { |
209 Q_UNUSED(value) |
299 Q_UNUSED(value) |
210 mDirection = down; |
300 mDirection = down; |
211 // Before we start scrolling, setthe active text color to previous month |
301 mIsAtomicScroll = false; |
212 QDateTime activeDate = mView->getActiveDay(); |
302 setAttribute(Hb::InteractionDisabled); |
213 setActiveDates(activeDate.addMonths(-1).date()); |
303 |
214 HbScrollArea::downGesture(SCROLL_SPEEED); |
304 // pass it to parent |
|
305 HbScrollArea::downGesture(value); |
215 } |
306 } |
216 |
307 |
217 /*! |
308 /*! |
218 Listens for Up gesture |
309 Listens for Up gesture |
219 */ |
310 */ |
220 void CalenMonthGrid::upGesture (int value) |
311 void CalenMonthGrid::upGesture (int value) |
221 { |
312 { |
222 Q_UNUSED(value) |
313 Q_UNUSED(value) |
223 mDirection = up; |
314 mDirection = up; |
224 // Before we start scrolling, setthe active text color to future month |
315 mIsAtomicScroll = false; |
225 QDateTime activeDate = mView->getActiveDay(); |
316 setAttribute(Hb::InteractionDisabled); |
226 setActiveDates(activeDate.addMonths(1).date()); |
317 |
227 HbScrollArea::upGesture(SCROLL_SPEEED); |
318 // pass it to parent |
|
319 HbScrollArea::upGesture(value); |
|
320 |
228 } |
321 } |
229 |
322 |
230 /*! |
323 /*! |
231 Function to listen mouse press events |
324 Function to listen mouse press events |
232 */ |
325 */ |
286 */ |
374 */ |
287 void CalenMonthGrid::scrollingFinished() |
375 void CalenMonthGrid::scrollingFinished() |
288 { |
376 { |
289 |
377 |
290 if (mIsPanGesture) { |
378 if (mIsPanGesture) { |
291 mIsPanGesture = false; |
379 handlePanGestureFinished(); |
292 if (mDirection == up) { |
|
293 // Make a request for upgesture |
|
294 upGesture(SCROLL_SPEEED); |
|
295 return; // return immediately |
|
296 } else if (mDirection == down) { |
|
297 // Make a request for upgesture |
|
298 downGesture(SCROLL_SPEEED); |
|
299 return; // return immediately |
|
300 } |
|
301 } else if(!mIsAtomicScroll) { |
380 } else if(!mIsAtomicScroll) { |
302 // Before we do anything, set the focus to proper date |
381 QDateTime activeDate = mView->getActiveDay(); |
303 // Set it only when non active day was focussed. When inactive day |
382 if(mDirection == down) { // down gesture |
304 // was focussed, we need to focus the same day |
383 if (!mIsNonActiveDayFocused) { |
305 if (!mIsNonActiveDayFocused) { |
384 setActiveDates(activeDate.addMonths(-1).date()); |
306 setFocusToProperDay(); |
385 } |
307 } |
386 prependRows(); |
308 // To improve the performance, lets start the timer for 10 ms, |
387 } else if (mDirection == up) { //up gesture |
309 // return immediately and do the other things after that |
388 if (!mIsNonActiveDayFocused) { |
310 QTimer::singleShot(10, this, SLOT(timerExpired())); |
389 setActiveDates(activeDate.addMonths(1).date()); |
|
390 } |
|
391 appendRows(); |
|
392 } |
|
393 mDirection = invalid; |
311 } else { |
394 } else { |
312 mIsAtomicScroll = false; |
395 mIsAtomicScroll = false; |
313 } |
396 } |
314 mIgnoreItemActivated = false; |
397 mIgnoreItemActivated = false; |
315 } |
398 setAttribute(Hb::InteractionDisabled, false); |
316 |
399 } |
317 void CalenMonthGrid::timerExpired() |
400 |
318 { |
401 /*! |
319 if(mDirection == down) { // down gesture |
402 Function to handle completion of pan gesture |
320 prependRows(); |
403 */ |
321 } else if (mDirection == up) { //up gesture |
404 void CalenMonthGrid::handlePanGestureFinished() |
322 appendRows(); |
405 { |
323 } |
406 mIsPanGesture = false; |
324 mDirection = invalid; |
407 // Get the first item that is visible |
|
408 QList<HbAbstractViewItem *> list = visibleItems(); |
|
409 HbAbstractViewItem* item = list[0]; |
|
410 QModelIndex modelIndex = item->modelIndex(); |
|
411 |
|
412 // Get the date which is visible at the above row |
|
413 QDateTime date = mMonthDataArray[modelIndex.row()].Day(); |
|
414 |
|
415 // Check if this date belong to current active month or |
|
416 // previous month else future month |
|
417 QDateTime activeMonth = mView->getActiveDay(); |
|
418 QDateTime prevMonth = activeMonth.addMonths(-1); |
|
419 QDateTime nextMonth = activeMonth.addMonths(1); |
|
420 int month = date.date().month(); |
|
421 if (month == activeMonth.date().month()) { |
|
422 // Then pan is completed on current month |
|
423 // Check if the date is more than half of the current month or it is |
|
424 // more than or equal to half of the future month |
|
425 if (date.date().day() > (activeMonth.date().daysInMonth()) / 2 || |
|
426 date.addDays(KNumOfVisibleRows*KCalenDaysInWeek).date().day() >= |
|
427 (prevMonth.date().daysInMonth()) / 2) { |
|
428 // up gesture to bring the next month |
|
429 upGesture(SCROLL_SPEEED); |
|
430 } else { |
|
431 // we should again show the current month by scrolling downwards |
|
432 mDirection = down; |
|
433 mIsAtomicScroll = true; |
|
434 scrollContentsTo(-mStartPos,500); |
|
435 } |
|
436 } else if (month == prevMonth.date().month()) { |
|
437 // first visible item belongs to previous month |
|
438 // Check if the date is more than half of the previous month |
|
439 if (date.date().day() > (prevMonth.date().daysInMonth()) / 2) { |
|
440 // we should again show the current month by scrolling upwards |
|
441 mDirection = up; |
|
442 mIsAtomicScroll = true; |
|
443 scrollContentsTo(-mStartPos,500); |
|
444 } else { |
|
445 // down gesture to show the previous month |
|
446 downGesture(SCROLL_SPEEED); |
|
447 } |
|
448 } else if (month == nextMonth.date().month()) { |
|
449 // first visible item belongs to next month |
|
450 // Check if the date is more than half of the next month |
|
451 if (date.date().day() > (nextMonth.date().daysInMonth()) / 2) { |
|
452 // up gesture to bring the next month |
|
453 upGesture(SCROLL_SPEEED); |
|
454 } else { |
|
455 // we should again show the current month by scrolling upwards |
|
456 mDirection = invalid; |
|
457 scrollContentsTo(-mStartPos,500); |
|
458 } |
|
459 } |
325 } |
460 } |
326 |
461 |
327 /*! |
462 /*! |
328 Called when down gesture is performed. Adds the new previous month details |
463 Called when down gesture is performed. Adds the new previous month details |
329 to the model |
464 to the model |
330 */ |
465 */ |
331 void CalenMonthGrid::prependRows() |
466 void CalenMonthGrid::prependRows() |
332 { |
467 { |
|
468 // Before we do anything, set the focus to proper date |
|
469 // Set it only when non active day was focussed. When inactive day |
|
470 // was focussed, we need to focus the same day |
|
471 if (!mIsNonActiveDayFocused) { |
|
472 setFocusToProperDay(); |
|
473 } |
|
474 |
|
475 // Block the signals generated by model, this is being done as |
|
476 // we want to avoid the overload of view listening to signals |
|
477 mModel->blockSignals(true); |
|
478 |
333 mIsNonActiveDayFocused = false; |
479 mIsNonActiveDayFocused = false; |
334 QDateTime currDate = mView->getCurrentDay(); |
480 |
335 QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate ); |
|
336 int rowsInFutMonthEarlier = mView->rowsInFutMonth(); |
481 int rowsInFutMonthEarlier = mView->rowsInFutMonth(); |
337 int rowsInPrevMonthEarlier = mView->rowsInPrevMonth(); |
482 int rowsInPrevMonthEarlier = mView->rowsInPrevMonth(); |
|
483 |
|
484 // remove the cells in the future month |
|
485 int deleteFromIndex = (rowsInPrevMonthEarlier + KNumOfVisibleRows) * KCalenDaysInWeek; |
|
486 int numOfIndices = rowsInFutMonthEarlier * KCalenDaysInWeek; |
338 |
487 |
339 // Get the updated dates from the view |
488 // Get the updated dates from the view |
340 mView->updateModelWithPrevMonth(); |
489 mView->updateModelWithPrevMonth(); |
341 QList<CalenMonthData > monthDataList = mView->monthDataList(); |
490 QList<CalenMonthData > monthDataList = mView->monthDataList(); |
342 mMonthDataArray = monthDataList; |
491 mMonthDataArray = monthDataList; |
343 int listCount = monthDataList.count(); |
492 |
344 // Get the updated rows to be inserted |
493 // Prepend the required rows |
|
494 handlePrependingRows(monthDataList); |
|
495 |
|
496 // Since, we have finished setData, Now unblock the signals |
|
497 mModel->blockSignals(false); |
|
498 |
345 int rowsInPrevMonth = mView->rowsInPrevMonth(); |
499 int rowsInPrevMonth = mView->rowsInPrevMonth(); |
346 int rowsInFutMonth = mView->rowsInFutMonth(); |
|
347 |
|
348 // remove the cells in the future month |
|
349 int deleteFromIndex = (rowsInPrevMonthEarlier + KNumOfVisibleRows) * KCalenDaysInWeek; |
|
350 int numOfIndices = rowsInFutMonthEarlier * KCalenDaysInWeek; |
|
351 int count = mModel->rowCount(); |
|
352 |
|
353 count = mModel->rowCount(); |
|
354 |
|
355 // Add the new days |
|
356 int countToBeAdded = rowsInPrevMonth * KCalenDaysInWeek; |
500 int countToBeAdded = rowsInPrevMonth * KCalenDaysInWeek; |
357 |
501 |
358 mModel->insertRows(0, countToBeAdded); |
502 // Since till now, we had blocked signals being generated frm the model |
359 count = mModel->rowCount(); |
503 // view will be unaware of the items that we added. Hence, inform the view |
360 |
504 // explicitly in one shot |
361 // Get the default text color to be set |
505 QModelIndex leftIndex = mModel->index(0, 0); |
362 QColor textColor = HbColorScheme::color("qtc_cal_month_notactive_dates"); |
506 QModelIndex rightIndex = mModel->index(countToBeAdded-1, 0); |
363 HbExtendedLocale locale = HbExtendedLocale::system(); |
507 dataChanged(leftIndex, rightIndex); |
364 |
508 |
365 for (int i = 0; i < countToBeAdded; i++) { |
|
366 QDateTime dateTime = monthDataList[i].Day(); |
|
367 |
|
368 // Get the localised string for the day |
|
369 QString date = locale.toString(dateTime.date().day()); |
|
370 QModelIndex currentIndex = mModel->index(i, 0); |
|
371 |
|
372 // Create the variant list to contain the date to depict a grid item |
|
373 QVariantList itemData; |
|
374 |
|
375 // NOTE: Add the data in the order mentioned in the |
|
376 // CalendarNamespace::DataRole enum. Dont change the order. |
|
377 itemData << date; |
|
378 |
|
379 // Diable the focus role |
|
380 itemData << QString(""); |
|
381 |
|
382 // Check for current day |
|
383 if (currDateTime == CalenDateUtils::beginningOfDay( dateTime )) { |
|
384 // Set the underline icon |
|
385 itemData << true; |
|
386 } else { |
|
387 itemData << false; |
|
388 } |
|
389 |
|
390 // Update the event indicators |
|
391 if (monthDataList[i].HasEvents()) { |
|
392 // Set the event indicator icon |
|
393 itemData << QString("qtg_graf_cal_event_ind"); |
|
394 } else { |
|
395 itemData << QString(""); |
|
396 } |
|
397 |
|
398 // Add default text color |
|
399 |
|
400 itemData << textColor; |
|
401 |
|
402 // Set the data to model |
|
403 mModel->itemFromIndex(currentIndex)->setData(itemData); |
|
404 } |
|
405 |
|
406 // Update the mCurrentRow |
|
407 mCurrentRow += countToBeAdded; |
|
408 // Scroll to proper index |
|
409 int itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * |
|
410 KCalenDaysInWeek) - 1; |
|
411 QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
|
412 QMap<int, QVariant> data; |
|
413 data = mModel->itemData(indexToBeScrolled); |
|
414 QVariant value = data.value(Qt::DisplayRole); |
|
415 int date = value.toInt(); |
|
416 mIsAtomicScroll = true; |
|
417 scrollTo(indexToBeScrolled); |
|
418 |
|
419 // Now remove the necessary items frm the model |
509 // Now remove the necessary items frm the model |
420 mModel->removeRows(deleteFromIndex+countToBeAdded, numOfIndices); |
510 mModel->removeRows(deleteFromIndex+countToBeAdded, numOfIndices); |
421 mIsAtomicScroll = true; |
511 mIsAtomicScroll = true; |
422 itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek; |
512 int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek; |
|
513 QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
|
514 scrollTo(indexToBeScrolled); |
|
515 |
|
516 // Scroll to proper index |
|
517 itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * |
|
518 KCalenDaysInWeek) - 1; |
423 indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
519 indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
|
520 mIsAtomicScroll = true; |
424 scrollTo(indexToBeScrolled); |
521 scrollTo(indexToBeScrolled); |
|
522 // Update the mCurrentRow |
|
523 mCurrentRow += countToBeAdded; |
|
524 } |
|
525 |
|
526 /*! |
|
527 Helper function that prepends the required rows to the model |
|
528 */ |
|
529 void CalenMonthGrid::handlePrependingRows(QList<CalenMonthData > &monthDataList) |
|
530 { |
|
531 QDateTime currDate = mView->getCurrentDay(); |
|
532 QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate ); |
|
533 int rowsInPrevMonth = mView->rowsInPrevMonth(); |
|
534 // Add the new days |
|
535 int countToBeAdded = rowsInPrevMonth * KCalenDaysInWeek; |
|
536 |
|
537 mModel->insertRows(0, countToBeAdded); |
|
538 |
|
539 for (int i = 0; i < countToBeAdded; i++) { |
|
540 QDateTime dateTime = monthDataList[i].Day(); |
|
541 |
|
542 // Get the localised string for the day |
|
543 QModelIndex currentIndex = mModel->index(i, 0); |
|
544 |
|
545 // Create the variant list to contain the date to depict a grid item |
|
546 QVariantList itemData; |
|
547 |
|
548 // NOTE: Add the data in the order mentioned in the |
|
549 // CalendarNamespace::DataRole enum. Dont change the order. |
|
550 itemData << mLocalisedDates.at(dateTime.date().day()-1);; |
|
551 |
|
552 // Disable the focus role |
|
553 itemData << false; |
|
554 |
|
555 // Check for current day |
|
556 if (currDateTime == CalenDateUtils::beginningOfDay( dateTime )) { |
|
557 // Set the underline icon attribute |
|
558 itemData << true; |
|
559 } else { |
|
560 itemData << false; |
|
561 } |
|
562 |
|
563 // Update the event indicators |
|
564 if (monthDataList[i].HasEvents()) { |
|
565 // Set the event indicator attribute |
|
566 itemData << true; |
|
567 } else { |
|
568 itemData << false; |
|
569 } |
|
570 |
|
571 // Add default text color |
|
572 itemData << false; |
|
573 |
|
574 // Set the data to model |
|
575 mModel->itemFromIndex(currentIndex)->setData(itemData); |
|
576 } |
425 } |
577 } |
426 |
578 |
427 /*! |
579 /*! |
428 Called when Up gwsture is performed. Adds the new future month details |
580 Called when Up gwsture is performed. Adds the new future month details |
429 to the model |
581 to the model |
430 */ |
582 */ |
431 void CalenMonthGrid::appendRows() |
583 void CalenMonthGrid::appendRows() |
432 { |
584 { |
|
585 // Before we do anything, set the focus to proper date |
|
586 // Set it only when non active day was focussed. When inactive day |
|
587 // was focussed, we need to focus the same day |
|
588 if (!mIsNonActiveDayFocused) { |
|
589 setFocusToProperDay(); |
|
590 } |
|
591 |
|
592 // Block the signals generated by model, this is being done as |
|
593 // we want to avoid the overload of view listening to signals |
|
594 mModel->blockSignals(true); |
|
595 |
433 mIsNonActiveDayFocused = false; |
596 mIsNonActiveDayFocused = false; |
434 QDateTime currDate = mView->getCurrentDay(); |
597 |
435 QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate ); |
|
436 int rowsInFutMonth = mView->rowsInFutMonth(); |
598 int rowsInFutMonth = mView->rowsInFutMonth(); |
437 int rowsInPrevMonth = mView->rowsInPrevMonth(); |
599 int rowsInPrevMonth = mView->rowsInPrevMonth(); |
438 // remove the cells in the previous month |
600 // remove the cells in the previous month |
439 int countToBeDeleted = rowsInPrevMonth * KCalenDaysInWeek; |
601 int countToBeDeleted = rowsInPrevMonth * KCalenDaysInWeek; |
440 |
602 |
441 // Get the updated dates from the view |
603 // Get the updated dates from the view |
442 mView->updateModelWithFutureMonth(); |
604 mView->updateModelWithFutureMonth(); |
443 QList<CalenMonthData > monthDataList = mView->monthDataList(); |
605 QList<CalenMonthData > monthDataList = mView->monthDataList(); |
444 mMonthDataArray = monthDataList; |
606 mMonthDataArray = monthDataList; |
445 // Get the updated rows to be inserted |
607 |
446 rowsInPrevMonth = mView->rowsInPrevMonth(); |
608 // Get the model count before we add any rows into the mode |
447 rowsInFutMonth = mView->rowsInFutMonth(); |
|
448 int countToBeAdded = rowsInFutMonth * KCalenDaysInWeek; |
|
449 int lastVisibleIndex = monthDataList.count() - countToBeAdded; |
|
450 |
|
451 int rowCount = mModel->rowCount(); |
609 int rowCount = mModel->rowCount(); |
452 mModel->insertRows(rowCount, countToBeAdded); |
610 // Append the required rows |
453 |
611 handleAppendingRows(monthDataList); |
454 // Get the default text color to be set |
612 |
455 QColor textColor = HbColorScheme::color("qtc_cal_month_notactive_dates"); |
613 // Since, we have finished setData, Now unblock the signals |
456 for (int i = 0; i < countToBeAdded; i++) { |
614 mModel->blockSignals(false); |
457 QMap<int, QVariant> data; |
615 |
458 QModelIndex currentIndex = mModel->index(rowCount + i, 0); |
616 // Since till now, we had blocked signals being generated frm the mode |
459 |
617 // view will be unaware of the items that we added. Hence, inform the view |
460 QDateTime dateTime = monthDataList[lastVisibleIndex + i].Day(); |
618 // explicitly in one shot |
461 HbExtendedLocale locale = HbExtendedLocale::system(); |
619 QModelIndex leftIndex = mModel->index(rowCount-1, 0); |
462 // Get the localised string for the day |
620 QModelIndex rightIndex = mModel->index(mModel->rowCount()-1, 0); |
463 QString date = locale.toString(dateTime.date().day()); |
621 dataChanged(leftIndex, rightIndex); |
464 data.insert(CalendarNamespace::CalendarMonthDayRole, date); |
622 |
465 |
|
466 // Create the variant list to contain the date to depict a grid item |
|
467 QVariantList itemData; |
|
468 |
|
469 // NOTE: Add the data in the order mentioned in the |
|
470 // CalendarNamespace::DataRole enum. Dont change the order. |
|
471 itemData << date; |
|
472 |
|
473 // Disable the focus role |
|
474 itemData << QString(""); |
|
475 |
|
476 // Check for current day |
|
477 if (currDateTime == CalenDateUtils::beginningOfDay( dateTime )) { |
|
478 // Set the underline icon |
|
479 itemData << true; |
|
480 } else { |
|
481 itemData << false; |
|
482 } |
|
483 |
|
484 // Update the event indicators |
|
485 if (monthDataList[lastVisibleIndex + i].HasEvents()) { |
|
486 // Set the underline icon |
|
487 itemData << QString("qtg_graf_cal_event_ind"); |
|
488 } else { |
|
489 itemData << QString(""); |
|
490 } |
|
491 |
|
492 // Add default text color |
|
493 itemData << textColor; |
|
494 |
|
495 // Set the data to model |
|
496 mModel->itemFromIndex(currentIndex)->setData(itemData); |
|
497 } |
|
498 |
|
499 // Update the mCurrentRow |
623 // Update the mCurrentRow |
500 mCurrentRow -= (countToBeDeleted); |
624 mCurrentRow -= (countToBeDeleted); |
501 for (int i = 0; i < countToBeDeleted; i++) { |
625 for (int i = 0; i < countToBeDeleted; i++) { |
502 mModel->removeRow(0); |
626 mModel->removeRow(0); |
503 } |
627 } |
|
628 |
504 mIsAtomicScroll = true; |
629 mIsAtomicScroll = true; |
|
630 |
|
631 rowsInFutMonth = mView->rowsInFutMonth(); |
|
632 rowsInPrevMonth = mView->rowsInPrevMonth(); |
505 |
633 |
506 // Calculate the proper index to be scrolled to |
634 // Calculate the proper index to be scrolled to |
507 int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek; |
635 int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek; |
508 QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
636 QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
509 scrollTo(indexToBeScrolled); |
637 scrollTo(indexToBeScrolled); |
|
638 |
|
639 itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * |
|
640 KCalenDaysInWeek) - 1; |
|
641 indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
|
642 mIsAtomicScroll = true; |
|
643 scrollTo(indexToBeScrolled); |
|
644 } |
|
645 |
|
646 /*! |
|
647 Helper function that appends the required rows to the model |
|
648 */ |
|
649 void CalenMonthGrid::handleAppendingRows(QList<CalenMonthData > &monthDataList) |
|
650 { |
|
651 QDateTime currDate = mView->getCurrentDay(); |
|
652 QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate ); |
|
653 int rowsInFutMonth = mView->rowsInFutMonth(); |
|
654 int countToBeAdded = rowsInFutMonth * KCalenDaysInWeek; |
|
655 int lastVisibleIndex = monthDataList.count() - countToBeAdded; |
|
656 |
|
657 int rowCount = mModel->rowCount(); |
|
658 mModel->insertRows(rowCount, countToBeAdded); |
|
659 |
|
660 for (int i = 0; i < countToBeAdded; i++) { |
|
661 QModelIndex currentIndex = mModel->index(rowCount + i, 0); |
|
662 |
|
663 QDateTime dateTime = monthDataList[lastVisibleIndex + i].Day(); |
|
664 |
|
665 // Create the variant list to contain the date to depict a grid item |
|
666 QVariantList itemData; |
|
667 |
|
668 // NOTE: Add the data in the order mentioned in the |
|
669 // CalendarNamespace::DataRole enum. Dont change the order. |
|
670 itemData << mLocalisedDates.at(dateTime.date().day()-1);; |
|
671 |
|
672 // Disable the focus role |
|
673 itemData << false; |
|
674 |
|
675 // Check for current day |
|
676 if (currDateTime == CalenDateUtils::beginningOfDay( dateTime )) { |
|
677 // Set the underline icon attribute |
|
678 itemData << true; |
|
679 } else { |
|
680 itemData << false; |
|
681 } |
|
682 |
|
683 // Update the event indicators |
|
684 if (monthDataList[lastVisibleIndex + i].HasEvents()) { |
|
685 // Set the event indicator attribute |
|
686 itemData << true; |
|
687 } else { |
|
688 itemData << false; |
|
689 } |
|
690 |
|
691 // Add default text color |
|
692 itemData << false; |
|
693 |
|
694 // Set the data to model |
|
695 mModel->itemFromIndex(currentIndex)->setData(itemData); |
|
696 } |
510 } |
697 } |
511 |
698 |
512 /*! |
699 /*! |
513 Slot to handle when a particular grid item is tapped |
700 Slot to handle when a particular grid item is tapped |
514 */ |
701 */ |