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