174 mModel->insertRows(rowCount,countDiff); |
174 mModel->insertRows(rowCount,countDiff); |
175 } |
175 } |
176 loopEnd = dataCount; |
176 loopEnd = dataCount; |
177 } |
177 } |
178 |
178 |
179 QDateTime currDate = mView->getCurrentDay(); |
|
180 QDateTime currDateTime = CalenDateUtils::beginningOfDay(currDate); |
|
181 QDateTime activeDay = mView->getActiveDay(); |
179 QDateTime activeDay = mView->getActiveDay(); |
182 QDateTime activeDateTime = CalenDateUtils::beginningOfDay(activeDay); |
180 QDateTime activeDateTime = CalenDateUtils::beginningOfDay(activeDay); |
183 |
181 |
184 QModelIndex currentIndex; |
182 QModelIndex currentIndex; |
185 int modelIndex = 0; |
183 int modelIndex = 0; |
260 |
258 |
261 // NOTE: To make sure that we always display proper month, |
259 // NOTE: To make sure that we always display proper month, |
262 // two calls have been made to scrollTo(), one with top |
260 // two calls have been made to scrollTo(), one with top |
263 // visible item and other with bottom visible item |
261 // visible item and other with bottom visible item |
264 // Calculate the first visible item in the grid |
262 // Calculate the first visible item in the grid |
265 QModelIndex firstVisibleIndex = mModel->index(indexToBeScrolled - |
|
266 (KNumOfVisibleRows * KCalenDaysInWeek - 1), 0); |
|
267 scrollTo(firstVisibleIndex); |
|
268 |
|
269 |
263 |
270 // Calculate the last visible item in the grid |
264 // Calculate the last visible item in the grid |
271 QModelIndex lastVisibleIndex = mModel->index(indexToBeScrolled, 0); |
265 QModelIndex lastVisibleIndex = mModel->index(indexToBeScrolled, 0); |
272 scrollTo(lastVisibleIndex); |
266 scrollTo(lastVisibleIndex, HbAbstractItemView::PositionAtBottom); |
273 } |
267 } |
274 |
268 |
275 OstTraceFunctionExit0( CALENMONTHGRID_UPDATEMONTHGRIDMODEL_EXIT ); |
269 OstTraceFunctionExit0( CALENMONTHGRID_UPDATEMONTHGRIDMODEL_EXIT ); |
276 } |
270 } |
277 |
271 |
291 handleAppendingRows(monthDataArray); |
285 handleAppendingRows(monthDataArray); |
292 |
286 |
293 int rowsInPrevMonth = mView->rowsInPrevMonth(); |
287 int rowsInPrevMonth = mView->rowsInPrevMonth(); |
294 |
288 |
295 // Calculate the proper index to be scrolled to |
289 // Calculate the proper index to be scrolled to |
296 int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek; |
290 |
|
291 int itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * |
|
292 KCalenDaysInWeek) - 1; |
297 QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
293 QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
298 mIsAtomicScroll = true; |
294 mIsAtomicScroll = true; |
299 scrollTo(indexToBeScrolled); |
295 scrollTo(indexToBeScrolled, HbAbstractItemView::PositionAtBottom); |
300 |
|
301 // Scroll to proper index |
|
302 itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * |
|
303 KCalenDaysInWeek) - 1; |
|
304 indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
|
305 mIsAtomicScroll = true; |
|
306 scrollTo(indexToBeScrolled); |
|
307 |
296 |
308 // Update the sart position of the content widget |
297 // Update the sart position of the content widget |
309 mStartPos = mContentWidget->pos(); |
298 mStartPos = mContentWidget->pos(); |
310 |
299 |
311 // Now connect to the signal which gets emitted when any item on the grid |
300 // Now connect to the signal which gets emitted when any item on the grid |
338 // Check if the day has events |
327 // Check if the day has events |
339 if (monthDataArray[i].HasEvents()) { |
328 if (monthDataArray[i].HasEvents()) { |
340 QModelIndex itemIndex = mModel->index(i,0); |
329 QModelIndex itemIndex = mModel->index(i,0); |
341 QVariant itemData = itemIndex.data(Qt::UserRole + 1); |
330 QVariant itemData = itemIndex.data(Qt::UserRole + 1); |
342 QVariantList list = itemData.toList(); |
331 QVariantList list = itemData.toList(); |
343 list.replace(CalendarNamespace::CalendarMonthEventRole, true); |
332 if (list.count() > CalendarNamespace::CalendarMonthEventRole ) { |
344 mModel->itemFromIndex(itemIndex)->setData(list); |
333 list.replace(CalendarNamespace::CalendarMonthEventRole, true); |
|
334 mModel->itemFromIndex(itemIndex)->setData(list); |
|
335 } |
345 } |
336 } |
346 } |
337 } |
347 } else { |
338 } else { |
348 mEventIndicatorNotSet = true; |
339 mEventIndicatorNotSet = true; |
349 } |
340 } |
756 */ |
747 */ |
757 void CalenMonthGrid::handlePrependingRows(QList<CalenMonthData > &monthDataList) |
748 void CalenMonthGrid::handlePrependingRows(QList<CalenMonthData > &monthDataList) |
758 { |
749 { |
759 OstTraceFunctionEntry0( CALENMONTHGRID_HANDLEPREPENDINGROWS_ENTRY ); |
750 OstTraceFunctionEntry0( CALENMONTHGRID_HANDLEPREPENDINGROWS_ENTRY ); |
760 |
751 |
761 QDateTime currDate = mView->getCurrentDay(); |
|
762 QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate ); |
|
763 int rowsInPrevMonth = mView->rowsInPrevMonth(); |
752 int rowsInPrevMonth = mView->rowsInPrevMonth(); |
764 // Add the new days |
753 // Add the new days |
765 int countToBeAdded = rowsInPrevMonth * KCalenDaysInWeek; |
754 int countToBeAdded = rowsInPrevMonth * KCalenDaysInWeek; |
766 |
755 |
767 mModel->insertRows(0, countToBeAdded); |
756 mModel->insertRows(0, countToBeAdded); |
879 */ |
868 */ |
880 void CalenMonthGrid::handleAppendingRows(QList<CalenMonthData > &monthDataList) |
869 void CalenMonthGrid::handleAppendingRows(QList<CalenMonthData > &monthDataList) |
881 { |
870 { |
882 OstTraceFunctionEntry0( CALENMONTHGRID_HANDLEAPPENDINGROWS_ENTRY ); |
871 OstTraceFunctionEntry0( CALENMONTHGRID_HANDLEAPPENDINGROWS_ENTRY ); |
883 |
872 |
884 QDateTime currDate = mView->getCurrentDay(); |
|
885 QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate ); |
|
886 int rowsInFutMonth = mView->rowsInFutMonth(); |
873 int rowsInFutMonth = mView->rowsInFutMonth(); |
887 int countToBeAdded = rowsInFutMonth * KCalenDaysInWeek; |
874 int countToBeAdded = rowsInFutMonth * KCalenDaysInWeek; |
888 int lastVisibleIndex = monthDataList.count() - countToBeAdded; |
875 int lastVisibleIndex = monthDataList.count() - countToBeAdded; |
889 |
876 |
890 int rowCount = mModel->rowCount(); |
877 int rowCount = mModel->rowCount(); |
1161 |
1148 |
1162 OstTraceFunctionExit0( CALENMONTHGRID_SETCURRENTIDEX_EXIT ); |
1149 OstTraceFunctionExit0( CALENMONTHGRID_SETCURRENTIDEX_EXIT ); |
1163 } |
1150 } |
1164 |
1151 |
1165 /*! |
1152 /*! |
1166 Function to override the default behavior of hbgridview on orientation change |
|
1167 */ |
|
1168 void CalenMonthGrid::orientationChanged(Qt::Orientation newOrientation) |
|
1169 { |
|
1170 OstTraceFunctionEntry0( CALENMONTHGRID_ORIENTATIONCHANGED_ENTRY ); |
|
1171 |
|
1172 // We are overriding this function to avoid the default behavior of |
|
1173 // hbgridview on orientation change as it swaps the row and column counts |
|
1174 // Calculate the proper index to be scrolled to |
|
1175 int rowsInPrevMonth; |
|
1176 int itemToBeScrolled; |
|
1177 QModelIndex indexToBeScrolled; |
|
1178 if (newOrientation == Qt::Horizontal) { |
|
1179 rowsInPrevMonth = mView->rowsInPrevMonth(); |
|
1180 itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek; |
|
1181 indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
|
1182 mIsAtomicScroll = true; |
|
1183 scrollTo(indexToBeScrolled); |
|
1184 } else { |
|
1185 rowsInPrevMonth = mView->rowsInPrevMonth(); |
|
1186 itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek; |
|
1187 indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
|
1188 mIsAtomicScroll = true; |
|
1189 scrollTo(indexToBeScrolled); |
|
1190 |
|
1191 itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * |
|
1192 KCalenDaysInWeek) - 1; |
|
1193 indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
|
1194 mIsAtomicScroll = true; |
|
1195 scrollTo(indexToBeScrolled); |
|
1196 } |
|
1197 |
|
1198 OstTraceFunctionExit0( CALENMONTHGRID_ORIENTATIONCHANGED_EXIT ); |
|
1199 } |
|
1200 |
|
1201 /*! |
|
1202 Paint function to draw grid lines |
1153 Paint function to draw grid lines |
1203 */ |
1154 */ |
1204 void CalenMonthGrid::paint(QPainter* painter, |
1155 void CalenMonthGrid::paint(QPainter* painter, |
1205 const QStyleOptionGraphicsItem* option, |
1156 const QStyleOptionGraphicsItem* option, |
1206 QWidget* widget) |
1157 QWidget* widget) |