65 mCurrentRow(-100), |
65 mCurrentRow(-100), |
66 mIsNonActiveDayFocused(false), |
66 mIsNonActiveDayFocused(false), |
67 mIgnoreItemActivated(false), |
67 mIgnoreItemActivated(false), |
68 mGridLineColor(HbColorScheme::color("qtc_cal_grid_line")), |
68 mGridLineColor(HbColorScheme::color("qtc_cal_grid_line")), |
69 mActiveDatesSet(false), |
69 mActiveDatesSet(false), |
70 mIsGridAdjusting(false) |
70 mIsGridAdjusting(false), |
|
71 mEventIndicatorNotSet(false) |
71 { |
72 { |
72 OstTraceFunctionEntry0( CALENMONTHGRID_CALENMONTHGRID_ENTRY ); |
73 OstTraceFunctionEntry0( CALENMONTHGRID_CALENMONTHGRID_ENTRY ); |
73 |
74 |
74 setScrollDirections(Qt::Vertical); |
75 setScrollDirections(Qt::Vertical); |
75 setRowCount(KNumOfVisibleRows); |
76 setRowCount(KNumOfVisibleRows); |
76 setColumnCount(KCalenDaysInWeek); |
77 setColumnCount(KCalenDaysInWeek); |
77 setLongPressEnabled(false); |
|
78 setItemRecycling(false); |
78 setItemRecycling(false); |
79 setSelectionMode(HbGridView::NoSelection); |
79 setSelectionMode(HbGridView::NoSelection); |
80 setUniformItemSizes(true); |
80 setUniformItemSizes(true); |
81 setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
81 setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
82 setClampingStyle(HbScrollArea::StrictClamping); |
82 setClampingStyle(HbScrollArea::StrictClamping); |
83 setEnabledAnimations(HbAbstractItemView::None); |
83 setEnabledAnimations(HbAbstractItemView::None); |
84 setFrictionEnabled(false); |
84 setFrictionEnabled(false); |
85 setFlag(QGraphicsItem::ItemHasNoContents, false); |
85 setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
86 |
|
87 // Enable the pixmap cache for better scrolling performance |
|
88 setItemPixmapCacheEnabled(true); |
86 |
89 |
87 // Disable the rows and columns swapping on orientation change |
90 // Disable the rows and columns swapping on orientation change |
88 setSwapDimensionsOnOrientationChange(false); |
91 setSwapDimensionsOnOrientationChange(false); |
89 |
92 |
90 resetTransform(); |
93 resetTransform(); |
232 CalenGridItemPrototype* gridItemPrototype = new CalenGridItemPrototype(this); |
235 CalenGridItemPrototype* gridItemPrototype = new CalenGridItemPrototype(this); |
233 |
236 |
234 connect( |
237 connect( |
235 HbTheme::instance(), SIGNAL(changed()), |
238 HbTheme::instance(), SIGNAL(changed()), |
236 gridItemPrototype, SLOT(handleThemeChange())); |
239 gridItemPrototype, SLOT(handleThemeChange())); |
237 |
|
238 // Set the mode and the prototype |
|
239 setModel(mModel,gridItemPrototype); |
|
240 |
240 |
241 // Register the widgetml and css files |
241 // Register the widgetml and css files |
242 HbStyleLoader::registerFilePath(":/"); |
242 HbStyleLoader::registerFilePath(":/"); |
243 |
243 |
244 // Set the layout name |
244 // Set the layout name |
245 setLayoutName("calendarCustomGridItem"); |
245 setLayoutName("calendarCustomGridItem"); |
|
246 |
|
247 // Set the mode and the prototypec --> set it after setting layout name and |
|
248 // other things as it will avoid unnecessary polish calls |
|
249 setModel(mModel,gridItemPrototype); |
246 } else { |
250 } else { |
247 // Since, we have finished setData, Now unblock the signals |
251 // Since, we have finished setData, Now unblock the signals |
248 mModel->blockSignals(false); |
252 mModel->blockSignals(false); |
249 |
253 |
250 // Since till now, we had blocked signals being generated frm the mode |
254 // Since till now, we had blocked signals being generated frm the mode |
307 // Now connect to the signal which gets emitted when any item on the grid |
311 // Now connect to the signal which gets emitted when any item on the grid |
308 // is tapped. |
312 // is tapped. |
309 connect(this, SIGNAL(activated(const QModelIndex &)), this, |
313 connect(this, SIGNAL(activated(const QModelIndex &)), this, |
310 SLOT(itemActivated(const QModelIndex &))); |
314 SLOT(itemActivated(const QModelIndex &))); |
311 |
315 |
|
316 // Check if we need to set the event indicators |
|
317 if(mEventIndicatorNotSet) { |
|
318 mEventIndicatorNotSet = false; |
|
319 updateMonthGridWithEventIndicators(monthDataArray); |
|
320 } |
312 OstTraceFunctionExit0( CALENMONTHGRID_UPDATEMONTHGRIDWITHINACTIVEMONTHS_EXIT ); |
321 OstTraceFunctionExit0( CALENMONTHGRID_UPDATEMONTHGRIDWITHINACTIVEMONTHS_EXIT ); |
313 } |
322 } |
314 |
323 |
315 /*! |
324 /*! |
316 Updates the view with just event indicators |
325 Updates the view with just event indicators |
319 QList<CalenMonthData> &monthDataArray) |
328 QList<CalenMonthData> &monthDataArray) |
320 { |
329 { |
321 OstTraceFunctionEntry0( CALENMONTHGRID_UPDATEMONTHGRIDWITHEVENTINDICATORS_ENTRY ); |
330 OstTraceFunctionEntry0( CALENMONTHGRID_UPDATEMONTHGRIDWITHEVENTINDICATORS_ENTRY ); |
322 |
331 |
323 int count(monthDataArray.count()); |
332 int count(monthDataArray.count()); |
324 for(int i = 0; i < count; i++) { |
333 |
325 // Check if the day has events |
334 // Check if model is updated with all the dates |
326 if (monthDataArray[i].HasEvents()) { |
335 // If not, return false for later updation |
327 QModelIndex itemIndex = mModel->index(i,0); |
336 if(count == mModel->rowCount()) { |
328 QVariant itemData = itemIndex.data(Qt::UserRole + 1); |
337 for(int i = 0; i < count; i++) { |
329 QVariantList list = itemData.toList(); |
338 // Check if the day has events |
330 list.replace(CalendarNamespace::CalendarMonthEventRole, true); |
339 if (monthDataArray[i].HasEvents()) { |
331 mModel->itemFromIndex(itemIndex)->setData(list); |
340 QModelIndex itemIndex = mModel->index(i,0); |
332 } |
341 QVariant itemData = itemIndex.data(Qt::UserRole + 1); |
|
342 QVariantList list = itemData.toList(); |
|
343 list.replace(CalendarNamespace::CalendarMonthEventRole, true); |
|
344 mModel->itemFromIndex(itemIndex)->setData(list); |
|
345 } |
|
346 } |
|
347 } else { |
|
348 mEventIndicatorNotSet = true; |
333 } |
349 } |
334 |
350 |
335 OstTraceFunctionExit0( CALENMONTHGRID_UPDATEMONTHGRIDWITHEVENTINDICATORS_EXIT ); |
351 OstTraceFunctionExit0( CALENMONTHGRID_UPDATEMONTHGRIDWITHEVENTINDICATORS_EXIT ); |
336 } |
352 } |
337 |
353 |
444 */ |
460 */ |
445 void CalenMonthGrid::gestureEvent(QGestureEvent *event) |
461 void CalenMonthGrid::gestureEvent(QGestureEvent *event) |
446 { |
462 { |
447 OstTraceFunctionEntry0( CALENMONTHGRID_GESTUREEVENT_ENTRY ); |
463 OstTraceFunctionEntry0( CALENMONTHGRID_GESTUREEVENT_ENTRY ); |
448 |
464 |
449 // Dont listem for any gesture when grid is getting adjusted as listening to those was causing |
465 // Dont listen for any gesture when grid is getting adjusted as listening to those was causing |
450 // grid to stop abruptly i between |
466 // grid to stop abruptly i between |
451 if (mIsGridAdjusting) { |
467 if (mIsGridAdjusting) { |
452 // consume the event and return |
468 // consume the event and return |
453 qDebug()<<"RETURNING BACK"; |
469 qDebug()<<"RETURNING BACK"; |
454 event->ignore(); |
470 event->ignore(); |
466 // calculate the direction explicitly |
482 // calculate the direction explicitly |
467 // Get to know the direction of the gesture |
483 // Get to know the direction of the gesture |
468 // Use our defined threshold temporarily till scrollarea |
484 // Use our defined threshold temporarily till scrollarea |
469 // frm orbit side is made clever enough not to scroll in other direction |
485 // frm orbit side is made clever enough not to scroll in other direction |
470 // apart frm the registered scroll direction |
486 // apart frm the registered scroll direction |
471 QPointF delta = gesture->delta(); |
487 QPointF delta = gesture->sceneOffset(); |
472 // Check the current orientation of the device and |
488 qreal horizontalDiff = delta.x(); |
473 // swap the vertical and horizontal distances in landscape |
489 qreal verticalDiff = delta.y(); |
474 qreal horizontalDiff = 0.0; |
|
475 qreal verticalDiff = 0.0; |
|
476 if (hbInstance->allMainWindows().at(0)->orientation() == Qt::Vertical) { |
|
477 horizontalDiff = delta.x(); |
|
478 verticalDiff = delta.y(); |
|
479 } else { |
|
480 horizontalDiff = delta.y(); |
|
481 verticalDiff = delta.x(); |
|
482 } |
|
483 if (abs(horizontalDiff) > MAX_PAN_DIRECTION_THRESHOLD) { |
490 if (abs(horizontalDiff) > MAX_PAN_DIRECTION_THRESHOLD) { |
484 // Now see if y coord diff has crossed threshold |
491 // Now see if y coord diff has crossed threshold |
485 if (verticalDiff > MAX_PAN_DIRECTION_THRESHOLD) { |
492 if (verticalDiff > MAX_PAN_DIRECTION_THRESHOLD) { |
486 mIsPanGesture = true; |
493 mIsPanGesture = true; |
487 mIgnoreItemActivated = true; |
494 mIgnoreItemActivated = true; |
536 handlePanGestureFinished(); |
543 handlePanGestureFinished(); |
537 } |
544 } |
538 } |
545 } |
539 } |
546 } |
540 |
547 |
|
548 // Check if we can scroll |
|
549 if (!checkIfWeCanScroll(mDirection)) { |
|
550 // We cannot scroll, return back |
|
551 mIsPanGesture = false; |
|
552 mIgnoreItemActivated = false; |
|
553 mDirection = invalid; |
|
554 event->accept(Qt::PanGesture); |
|
555 } |
|
556 |
541 if (mDirection!= invalid) { |
557 if (mDirection!= invalid) { |
542 // Call the parent class to perform the pan gesture |
558 // Call the parent class to perform the pan gesture |
543 // When scrolling finished, month grid will adjust to show the proper month |
559 // When scrolling finished, month grid will adjust to show the proper month |
544 HbScrollArea::gestureEvent(event); |
560 HbScrollArea::gestureEvent(event); |
545 } |
561 } |
920 */ |
936 */ |
921 void CalenMonthGrid::itemActivated(const QModelIndex &index) |
937 void CalenMonthGrid::itemActivated(const QModelIndex &index) |
922 { |
938 { |
923 OstTraceFunctionEntry0( CALENMONTHGRID_ITEMACTIVATED_ENTRY ); |
939 OstTraceFunctionEntry0( CALENMONTHGRID_ITEMACTIVATED_ENTRY ); |
924 |
940 |
925 if (mIgnoreItemActivated) { |
941 QList<CalenMonthData >& monthDataList = mView->monthDataList(); |
|
942 // Chekc if we need to ignore the event or the newly tapped date is |
|
943 // not valid date |
|
944 if (mIgnoreItemActivated || !(CalenDateUtils::isValidDay(monthDataList[index.row()].Day()))) { |
926 mIgnoreItemActivated = false; |
945 mIgnoreItemActivated = false; |
927 OstTraceFunctionExit0( CALENMONTHGRID_ITEMACTIVATED_EXIT ); |
946 OstTraceFunctionExit0( CALENMONTHGRID_ITEMACTIVATED_EXIT ); |
928 return; |
947 return; |
929 } |
948 } |
|
949 |
930 mIsNonActiveDayFocused = false; |
950 mIsNonActiveDayFocused = false; |
931 // Check if the same item has been tapped twice |
951 // Check if the same item has been tapped twice |
932 if (mCurrentRow == index.row()) { |
952 if (mCurrentRow == index.row()) { |
933 // Launch the Day view |
953 // Launch the Day view |
934 mView->launchDayView(); |
954 mView->launchDayView(); |
954 true); |
974 true); |
955 mModel->itemFromIndex(itemIndex)->setData(list); |
975 mModel->itemFromIndex(itemIndex)->setData(list); |
956 // Check if inactive date is tapped |
976 // Check if inactive date is tapped |
957 QDateTime activeMonth = mView->getActiveDay(); |
977 QDateTime activeMonth = mView->getActiveDay(); |
958 int month = activeMonth.date().month(); |
978 int month = activeMonth.date().month(); |
959 QList<CalenMonthData >& monthDataList = mView->monthDataList(); |
|
960 if(month != monthDataList[mCurrentRow].Day().date().month()){ |
979 if(month != monthDataList[mCurrentRow].Day().date().month()){ |
961 // Set the flag |
980 // Set the flag |
962 mIsNonActiveDayFocused = true; |
981 mIsNonActiveDayFocused = true; |
963 QDateTime nonActiveFocusedDay = monthDataList[mCurrentRow].Day(); |
982 QDateTime nonActiveFocusedDay = monthDataList[mCurrentRow].Day(); |
964 |
983 |
1148 */ |
1167 */ |
1149 void CalenMonthGrid::orientationChanged(Qt::Orientation newOrientation) |
1168 void CalenMonthGrid::orientationChanged(Qt::Orientation newOrientation) |
1150 { |
1169 { |
1151 OstTraceFunctionEntry0( CALENMONTHGRID_ORIENTATIONCHANGED_ENTRY ); |
1170 OstTraceFunctionEntry0( CALENMONTHGRID_ORIENTATIONCHANGED_ENTRY ); |
1152 |
1171 |
1153 Q_UNUSED(newOrientation) |
|
1154 // We are overriding this function to avoid the default behavior of |
1172 // We are overriding this function to avoid the default behavior of |
1155 // hbgridview on orientation change as it swaps the row and column counts |
1173 // hbgridview on orientation change as it swaps the row and column counts |
1156 // Calculate the proper index to be scrolled to |
1174 // Calculate the proper index to be scrolled to |
1157 int rowsInPrevMonth; |
1175 int rowsInPrevMonth; |
1158 int itemToBeScrolled; |
1176 int itemToBeScrolled; |
1269 |
1287 |
1270 OstTraceFunctionExit0( CALENMONTHGRID_PAINT_EXIT ); |
1288 OstTraceFunctionExit0( CALENMONTHGRID_PAINT_EXIT ); |
1271 } |
1289 } |
1272 |
1290 |
1273 /*! |
1291 /*! |
|
1292 Function to check if scrolling is allowed. This function will make an effect |
|
1293 only when you are going to month that is not supported by us. |
|
1294 */ |
|
1295 bool CalenMonthGrid::checkIfWeCanScroll(scrollDirection direction) |
|
1296 { |
|
1297 OstTraceFunctionEntry0( CALENMONTHGRID_CHECKIFWECANSCROLL_ENTRY ); |
|
1298 |
|
1299 bool value = true; |
|
1300 |
|
1301 // Get the current active Date |
|
1302 QDateTime activeDate = mView->getActiveDay(); |
|
1303 // if direction is up, then check if the next month is |
|
1304 // not January, 2101 |
|
1305 if (direction == up) { |
|
1306 QDateTime nextMonth = activeDate.addMonths(1); |
|
1307 value = CalenDateUtils::isValidDay(nextMonth); |
|
1308 } else if (direction == down) { // if direction is up, then check if the next month is |
|
1309 // not December, 1899 |
|
1310 QDateTime prevMonth = activeDate.addMonths(-1); |
|
1311 value = CalenDateUtils::isValidDay(prevMonth); |
|
1312 } |
|
1313 |
|
1314 OstTraceFunctionExit0( CALENMONTHGRID_CHECKIFWECANSCROLL_EXIT ); |
|
1315 |
|
1316 return value; |
|
1317 } |
|
1318 |
|
1319 /*! |
1274 Slot to handle the change in theme |
1320 Slot to handle the change in theme |
1275 */ |
1321 */ |
1276 void CalenMonthGrid::handleThemeChange() |
1322 void CalenMonthGrid::handleThemeChange() |
1277 { |
1323 { |
1278 OstTraceFunctionEntry0(CALENMONTHGRID_HANDLETHEMECHANGE_ENTRY); |
1324 OstTraceFunctionEntry0(CALENMONTHGRID_HANDLETHEMECHANGE_ENTRY); |