20 #include <hbabstractviewitem.h> |
20 #include <hbabstractviewitem.h> |
21 #include <hbstyleloader.h> |
21 #include <hbstyleloader.h> |
22 #include <hbcolorscheme.h> |
22 #include <hbcolorscheme.h> |
23 #include <hbpangesture.h> |
23 #include <hbpangesture.h> |
24 #include <hbswipegesture.h> |
24 #include <hbswipegesture.h> |
|
25 #include <hbtapgesture.h> |
25 #include <hbdeviceprofile.h> |
26 #include <hbdeviceprofile.h> |
26 |
27 |
27 // User includes |
28 // User includes |
28 #include "calenmonthgrid.h" |
29 #include "calenmonthgrid.h" |
29 #include "calengriditemprototype.h" |
30 #include "calengriditemprototype.h" |
30 #include "calenmonthdata.h" |
31 #include "calenmonthdata.h" |
31 #include "calenmonthview.h" |
32 #include "calenmonthview.h" |
32 #include "calendateutils.h" |
33 #include "calendateutils.h" |
33 #include "calencommon.h" |
34 #include "calencommon.h" |
34 #include "calenconstants.h" |
35 #include "calenconstants.h" |
|
36 #include "OstTraceDefinitions.h" |
|
37 #ifdef OST_TRACE_COMPILER_IN_USE |
|
38 #include "calenmonthgridTraces.h" |
|
39 #endif |
|
40 |
35 |
41 |
36 // Constants |
42 // Constants |
37 #define SCROLL_SPEEED 3000 |
43 #define SCROLL_SPEEED 3000 |
38 #define GRIDLINE_WIDTH 0.075 //units |
44 #define GRIDLINE_WIDTH 0.075 //units |
39 #define MAX_PAN_DIRECTION_THRESHOLD 50 |
45 #define MAX_PAN_DIRECTION_THRESHOLD 50 |
58 mCurrentRow(-100), |
64 mCurrentRow(-100), |
59 mIsNonActiveDayFocused(false), |
65 mIsNonActiveDayFocused(false), |
60 mIgnoreItemActivated(false), |
66 mIgnoreItemActivated(false), |
61 mGridBorderColor(Qt::gray) |
67 mGridBorderColor(Qt::gray) |
62 { |
68 { |
|
69 OstTraceFunctionEntry0( CALENMONTHGRID_CALENMONTHGRID_ENTRY ); |
|
70 |
63 setScrollDirections(Qt::Vertical); |
71 setScrollDirections(Qt::Vertical); |
64 setRowCount(KNumOfVisibleRows); |
72 setRowCount(KNumOfVisibleRows); |
65 setColumnCount(KCalenDaysInWeek); |
73 setColumnCount(KCalenDaysInWeek); |
66 setLongPressEnabled(false); |
74 setLongPressEnabled(false); |
67 setItemRecycling(false); |
75 setItemRecycling(false); |
90 } |
98 } |
91 |
99 |
92 // Connect to scrolling finished signal |
100 // Connect to scrolling finished signal |
93 connect(this, SIGNAL(scrollingEnded()), this, |
101 connect(this, SIGNAL(scrollingEnded()), this, |
94 SLOT(scrollingFinished())); |
102 SLOT(scrollingFinished())); |
|
103 |
|
104 OstTraceFunctionExit0( CALENMONTHGRID_CALENMONTHGRID_EXIT ); |
95 } |
105 } |
96 |
106 |
97 /*! |
107 /*! |
98 Destructor |
108 Destructor |
99 */ |
109 */ |
100 CalenMonthGrid::~CalenMonthGrid() |
110 CalenMonthGrid::~CalenMonthGrid() |
101 { |
111 { |
|
112 OstTraceFunctionEntry0( DUP1_CALENMONTHGRID_CALENMONTHGRID_ENTRY ); |
|
113 |
102 // Nothing Yet |
114 // Nothing Yet |
|
115 |
|
116 OstTraceFunctionExit0( DUP1_CALENMONTHGRID_CALENMONTHGRID_EXIT ); |
103 } |
117 } |
104 |
118 |
105 /*! |
119 /*! |
106 Stores the view pointer |
120 Stores the view pointer |
107 */ |
121 */ |
108 void CalenMonthGrid::setView(CalenMonthView *view) |
122 void CalenMonthGrid::setView(CalenMonthView *view) |
109 { |
123 { |
|
124 OstTraceFunctionEntry0( CALENMONTHGRID_SETVIEW_ENTRY ); |
|
125 |
110 mView = view; |
126 mView = view; |
|
127 |
|
128 OstTraceFunctionExit0( CALENMONTHGRID_SETVIEW_EXIT ); |
111 } |
129 } |
112 |
130 |
113 /*! |
131 /*! |
114 Updates the model with the proper dates and sets the required user roles |
132 Updates the model with the proper dates and sets the required user roles |
115 */ |
133 */ |
116 void CalenMonthGrid::updateMonthGridModel(QList<CalenMonthData> &monthDataArray, |
134 void CalenMonthGrid::updateMonthGridModel(QList<CalenMonthData> &monthDataArray, |
117 int indexToBeScrolled, bool isFirstTime) |
135 int indexToBeScrolled, bool isFirstTime) |
118 { |
136 { |
|
137 OstTraceFunctionEntry0( CALENMONTHGRID_UPDATEMONTHGRIDMODEL_ENTRY ); |
|
138 |
119 int loopStart = 0; |
139 int loopStart = 0; |
120 int loopEnd = monthDataArray.count(); |
140 int loopEnd = monthDataArray.count(); |
121 if (isFirstTime) { |
141 if (isFirstTime) { |
122 // Create the model with only 42 items as visible to the user |
142 // Create the model with only 42 items as visible to the user |
123 mModel = new QStandardItemModel(KCalenDaysInWeek * KNumOfVisibleRows, |
143 mModel = new QStandardItemModel(KCalenDaysInWeek * KNumOfVisibleRows, |
241 // Calculate the last visible item in the grid |
261 // Calculate the last visible item in the grid |
242 QModelIndex lastVisibleIndex = mModel->index(indexToBeScrolled, 0); |
262 QModelIndex lastVisibleIndex = mModel->index(indexToBeScrolled, 0); |
243 scrollTo(lastVisibleIndex); |
263 scrollTo(lastVisibleIndex); |
244 } |
264 } |
245 mMonthDataArray = monthDataArray; |
265 mMonthDataArray = monthDataArray; |
|
266 |
|
267 OstTraceFunctionExit0( CALENMONTHGRID_UPDATEMONTHGRIDMODEL_EXIT ); |
246 } |
268 } |
247 |
269 |
248 /*! |
270 /*! |
249 Updates the view with jprevious month dates when calendar is opened for the |
271 Updates the view with jprevious month dates when calendar is opened for the |
250 first time to improve the opening time |
272 first time to improve the opening time |
251 */ |
273 */ |
252 void CalenMonthGrid::updateMonthGridWithInActiveMonths( |
274 void CalenMonthGrid::updateMonthGridWithInActiveMonths( |
253 QList<CalenMonthData> &monthDataArray) |
275 QList<CalenMonthData> &monthDataArray) |
254 { |
276 { |
|
277 OstTraceFunctionEntry0( CALENMONTHGRID_UPDATEMONTHGRIDWITHINACTIVEMONTHS_ENTRY ); |
|
278 |
255 mMonthDataArray = monthDataArray; |
279 mMonthDataArray = monthDataArray; |
256 |
280 |
257 // Prepend the required rows |
281 // Prepend the required rows |
258 handlePrependingRows(monthDataArray); |
282 handlePrependingRows(monthDataArray); |
259 |
283 |
280 |
304 |
281 // Now connect to the signal which gets emitted when any item on the grid |
305 // Now connect to the signal which gets emitted when any item on the grid |
282 // is tapped. |
306 // is tapped. |
283 connect(this, SIGNAL(activated(const QModelIndex &)), this, |
307 connect(this, SIGNAL(activated(const QModelIndex &)), this, |
284 SLOT(itemActivated(const QModelIndex &))); |
308 SLOT(itemActivated(const QModelIndex &))); |
|
309 |
|
310 OstTraceFunctionExit0( CALENMONTHGRID_UPDATEMONTHGRIDWITHINACTIVEMONTHS_EXIT ); |
285 } |
311 } |
286 |
312 |
287 /*! |
313 /*! |
288 Updates the view with just event indicators |
314 Updates the view with just event indicators |
289 */ |
315 */ |
290 void CalenMonthGrid::updateMonthGridWithEventIndicators( |
316 void CalenMonthGrid::updateMonthGridWithEventIndicators( |
291 QList<CalenMonthData> &monthDataArray) |
317 QList<CalenMonthData> &monthDataArray) |
292 { |
318 { |
|
319 OstTraceFunctionEntry0( CALENMONTHGRID_UPDATEMONTHGRIDWITHEVENTINDICATORS_ENTRY ); |
|
320 |
293 mMonthDataArray = monthDataArray; |
321 mMonthDataArray = monthDataArray; |
294 for(int i = 0; i < monthDataArray.count(); i++) { |
322 int count(monthDataArray.count()); |
|
323 for(int i = 0; i < count; i++) { |
295 // Check if the day has events |
324 // Check if the day has events |
296 if (monthDataArray[i].HasEvents()) { |
325 if (monthDataArray[i].HasEvents()) { |
297 QModelIndex itemIndex = mModel->index(i,0); |
326 QModelIndex itemIndex = mModel->index(i,0); |
298 QVariant itemData = itemIndex.data(Qt::UserRole + 1); |
327 QVariant itemData = itemIndex.data(Qt::UserRole + 1); |
299 QVariantList list = itemData.toList(); |
328 QVariantList list = itemData.toList(); |
300 list.replace(CalendarNamespace::CalendarMonthEventRole, true); |
329 list.replace(CalendarNamespace::CalendarMonthEventRole, true); |
301 mModel->itemFromIndex(itemIndex)->setData(list); |
330 mModel->itemFromIndex(itemIndex)->setData(list); |
302 } |
331 } |
303 } |
332 } |
|
333 |
|
334 OstTraceFunctionExit0( CALENMONTHGRID_UPDATEMONTHGRIDWITHEVENTINDICATORS_EXIT ); |
304 } |
335 } |
305 |
336 |
306 /*! |
337 /*! |
307 Scrolls the content dowmwards |
338 Scrolls the content dowmwards |
308 */ |
339 */ |
309 void CalenMonthGrid::downGesture() |
340 void CalenMonthGrid::downGesture() |
310 { |
341 { |
|
342 OstTraceFunctionEntry0( CALENMONTHGRID_DOWNGESTURE_ENTRY ); |
|
343 |
311 // Make sure that content widget is properly placed |
344 // Make sure that content widget is properly placed |
312 if (mIsNonActiveDayFocused) { |
345 if (mIsNonActiveDayFocused) { |
313 mIsAtomicScroll = true; |
346 mIsAtomicScroll = true; |
314 int itemToBeScrolled = mView->rowsInPrevMonth() * KCalenDaysInWeek; |
347 int itemToBeScrolled = mView->rowsInPrevMonth() * KCalenDaysInWeek; |
315 QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
348 QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
318 mDirection = down; |
351 mDirection = down; |
319 mIsAtomicScroll = false; |
352 mIsAtomicScroll = false; |
320 setAttribute(Hb::InteractionDisabled); |
353 setAttribute(Hb::InteractionDisabled); |
321 QPointF targetPos(0.0, 0.0); |
354 QPointF targetPos(0.0, 0.0); |
322 scrollContentsTo(targetPos,500); |
355 scrollContentsTo(targetPos,500); |
|
356 |
|
357 OstTraceFunctionExit0( CALENMONTHGRID_DOWNGESTURE_EXIT ); |
323 } |
358 } |
324 |
359 |
325 /*! |
360 /*! |
326 Scrolls the content upwards |
361 Scrolls the content upwards |
327 */ |
362 */ |
328 void CalenMonthGrid::upGesture() |
363 void CalenMonthGrid::upGesture() |
329 { |
364 { |
|
365 OstTraceFunctionEntry0( CALENMONTHGRID_UPGESTURE_ENTRY ); |
|
366 |
330 // Make sure that content widget is properly placed |
367 // Make sure that content widget is properly placed |
331 if (mIsNonActiveDayFocused) { |
368 if (mIsNonActiveDayFocused) { |
332 mIsAtomicScroll = true; |
369 mIsAtomicScroll = true; |
333 int itemToBeScrolled = mView->rowsInPrevMonth() * KCalenDaysInWeek; |
370 int itemToBeScrolled = mView->rowsInPrevMonth() * KCalenDaysInWeek; |
334 itemToBeScrolled += KNumOfVisibleRows * KCalenDaysInWeek; |
371 itemToBeScrolled += KNumOfVisibleRows * KCalenDaysInWeek; |
339 mIsAtomicScroll = false; |
376 mIsAtomicScroll = false; |
340 setAttribute(Hb::InteractionDisabled); |
377 setAttribute(Hb::InteractionDisabled); |
341 QPointF targetPos(0.0, mStartPos.y() - size().height()); |
378 QPointF targetPos(0.0, mStartPos.y() - size().height()); |
342 scrollContentsTo(-targetPos,500); |
379 scrollContentsTo(-targetPos,500); |
343 |
380 |
|
381 OstTraceFunctionExit0( CALENMONTHGRID_UPGESTURE_EXIT ); |
344 } |
382 } |
345 |
383 |
346 /*! |
384 /*! |
347 Function to listen mouse press events |
385 Function to listen mouse press events |
348 */ |
386 */ |
349 void CalenMonthGrid::mousePressEvent(QGraphicsSceneMouseEvent* event) |
387 void CalenMonthGrid::mousePressEvent(QGraphicsSceneMouseEvent* event) |
350 { |
388 { |
|
389 OstTraceFunctionEntry0( CALENMONTHGRID_MOUSEPRESSEVENT_ENTRY ); |
|
390 |
351 // Pass it to parent |
391 // Pass it to parent |
352 HbGridView::mousePressEvent(event); |
392 HbGridView::mousePressEvent(event); |
|
393 |
|
394 OstTraceFunctionExit0( CALENMONTHGRID_MOUSEPRESSEVENT_EXIT ); |
353 } |
395 } |
354 |
396 |
355 /*! |
397 /*! |
356 Function to listen mouse release events |
398 Function to listen mouse release events |
357 */ |
399 */ |
358 void CalenMonthGrid::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
400 void CalenMonthGrid::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
359 { |
401 { |
|
402 OstTraceFunctionEntry0( CALENMONTHGRID_MOUSERELEASEEVENT_ENTRY ); |
|
403 |
360 // Pass it grid view if pan gesture is not in progress else pass it to |
404 // Pass it grid view if pan gesture is not in progress else pass it to |
361 // scrollarea. Problem here is, if we pass to gridview when panning, then |
405 // scrollarea. Problem here is, if we pass to gridview when panning, then |
362 // its emitting item activated signal simply becasue of which focus item |
406 // its emitting item activated signal simply becasue of which focus item |
363 // is getting changed when you finish the pan / shake |
407 // is getting changed when you finish the pan / shake |
364 if (!mIsPanGesture) { |
408 if (!mIsPanGesture) { |
365 HbGridView::mouseReleaseEvent(event); |
409 HbGridView::mouseReleaseEvent(event); |
366 } else { |
410 } else { |
367 HbScrollArea::mouseReleaseEvent(event); |
411 HbScrollArea::mouseReleaseEvent(event); |
368 } |
412 } |
|
413 |
|
414 OstTraceFunctionExit0( CALENMONTHGRID_MOUSERELEASEEVENT_EXIT ); |
369 } |
415 } |
370 |
416 |
371 /*! |
417 /*! |
372 Function to list for all the gesture events |
418 Function to list for all the gesture events |
373 */ |
419 */ |
374 void CalenMonthGrid::gestureEvent(QGestureEvent *event) |
420 void CalenMonthGrid::gestureEvent(QGestureEvent *event) |
375 { |
421 { |
|
422 OstTraceFunctionEntry0( CALENMONTHGRID_GESTUREEVENT_ENTRY ); |
|
423 |
376 if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) { |
424 if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) { |
377 if (gesture->state() == Qt::GestureStarted) { |
425 if (gesture->state() == Qt::GestureStarted) { |
378 setAttribute(Hb::InteractionDisabled); |
426 setAttribute(Hb::InteractionDisabled); |
379 mIsAtomicScroll = false; |
427 mIsAtomicScroll = false; |
380 if (!mIsPanGesture) { |
428 if (!mIsPanGesture) { |
398 mIsPanGesture = true; |
446 mIsPanGesture = true; |
399 mIgnoreItemActivated = true; |
447 mIgnoreItemActivated = true; |
400 mDirection = up; |
448 mDirection = up; |
401 } else { |
449 } else { |
402 event->accept(Qt::PanGesture); |
450 event->accept(Qt::PanGesture); |
|
451 OstTraceFunctionExit0( CALENMONTHGRID_GESTUREEVENT_EXIT ); |
403 return; |
452 return; |
404 } |
453 } |
405 } else if (abs(delta.x()) < MAX_PAN_DIRECTION_THRESHOLD) { |
454 } else if (abs(delta.x()) < MAX_PAN_DIRECTION_THRESHOLD) { |
406 if (delta.y() > MIN_PAN_DIRECTION_THRESHOLD) { |
455 if (delta.y() > MIN_PAN_DIRECTION_THRESHOLD) { |
407 mIsPanGesture = true; |
456 mIsPanGesture = true; |
427 mDirection = down; |
477 mDirection = down; |
428 } else if (gesture->sceneVerticalDirection() == QSwipeGesture::Up) { |
478 } else if (gesture->sceneVerticalDirection() == QSwipeGesture::Up) { |
429 mDirection = up; |
479 mDirection = up; |
430 } else { |
480 } else { |
431 event->accept(Qt::SwipeGesture); |
481 event->accept(Qt::SwipeGesture); |
|
482 OstTraceFunctionExit0( DUP2_CALENMONTHGRID_GESTUREEVENT_EXIT ); |
432 return; |
483 return; |
|
484 } |
|
485 } |
|
486 } else if (HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) { |
|
487 if(gesture->state() == Qt::GestureFinished) { |
|
488 // Check if scrolling is in progress |
|
489 if (mDirection != invalid) { |
|
490 // Set the pan flag to true so that grid adjusts to nearest |
|
491 // month after tapping |
|
492 mIsPanGesture = true; |
|
493 handlePanGestureFinished(); |
433 } |
494 } |
434 } |
495 } |
435 } |
496 } |
436 |
497 |
437 if (mDirection!= invalid) { |
498 if (mDirection!= invalid) { |
438 // Call the parent class to perform the pan gesture |
499 // Call the parent class to perform the pan gesture |
439 // When scrolling finished, month grid will adjust to show the proper month |
500 // When scrolling finished, month grid will adjust to show the proper month |
440 HbScrollArea::gestureEvent(event); |
501 HbScrollArea::gestureEvent(event); |
441 } |
502 } |
|
503 |
|
504 OstTraceFunctionExit0( DUP3_CALENMONTHGRID_GESTUREEVENT_EXIT ); |
442 } |
505 } |
443 |
506 |
444 /*! |
507 /*! |
445 Gets called when scrolling finishes to update the model |
508 Gets called when scrolling finishes to update the model |
446 */ |
509 */ |
447 void CalenMonthGrid::scrollingFinished() |
510 void CalenMonthGrid::scrollingFinished() |
448 { |
511 { |
|
512 OstTraceFunctionEntry0( CALENMONTHGRID_SCROLLINGFINISHED_ENTRY ); |
|
513 |
449 if (mIsPanGesture) { |
514 if (mIsPanGesture) { |
450 handlePanGestureFinished(); |
515 handlePanGestureFinished(); |
451 } else if(!mIsAtomicScroll) { |
516 } else if(!mIsAtomicScroll) { |
452 QDateTime activeDate = mView->getActiveDay(); |
517 QDateTime activeDate = mView->getActiveDay(); |
453 if(mDirection == down) { // down gesture |
518 if(mDirection == down) { // down gesture |
466 mIsAtomicScroll = false; |
531 mIsAtomicScroll = false; |
467 mDirection = invalid; |
532 mDirection = invalid; |
468 } |
533 } |
469 mIgnoreItemActivated = false; |
534 mIgnoreItemActivated = false; |
470 setAttribute(Hb::InteractionDisabled, false); |
535 setAttribute(Hb::InteractionDisabled, false); |
|
536 |
|
537 OstTraceFunctionExit0( CALENMONTHGRID_SCROLLINGFINISHED_EXIT ); |
471 } |
538 } |
472 |
539 |
473 /*! |
540 /*! |
474 Function to handle completion of pan gesture |
541 Function to handle completion of pan gesture |
475 */ |
542 */ |
476 void CalenMonthGrid::handlePanGestureFinished() |
543 void CalenMonthGrid::handlePanGestureFinished() |
477 { |
544 { |
|
545 OstTraceFunctionEntry0( CALENMONTHGRID_HANDLEPANGESTUREFINISHED_ENTRY ); |
|
546 |
478 mIsPanGesture = false; |
547 mIsPanGesture = false; |
479 // Get the first item that is visible |
548 // Get the first item that is visible |
480 QList<HbAbstractViewItem *> list = visibleItems(); |
549 QList<HbAbstractViewItem *> list = visibleItems(); |
481 HbAbstractViewItem* item = list[0]; |
550 HbAbstractViewItem* item = list[0]; |
482 QModelIndex modelIndex = item->modelIndex(); |
551 QModelIndex modelIndex = item->modelIndex(); |
538 } else if (month == nextMonth.addMonths(1).date().month()) { |
607 } else if (month == nextMonth.addMonths(1).date().month()) { |
539 // first visible date belongs to next to next month |
608 // first visible date belongs to next to next month |
540 // hence, scroll up to show the next month |
609 // hence, scroll up to show the next month |
541 upGesture(); |
610 upGesture(); |
542 } |
611 } |
|
612 |
|
613 OstTraceFunctionExit0( CALENMONTHGRID_HANDLEPANGESTUREFINISHED_EXIT ); |
543 } |
614 } |
544 |
615 |
545 /*! |
616 /*! |
546 Called when down gesture is performed. Adds the new previous month details |
617 Called when down gesture is performed. Adds the new previous month details |
547 to the model |
618 to the model |
548 */ |
619 */ |
549 void CalenMonthGrid::prependRows() |
620 void CalenMonthGrid::prependRows() |
550 { |
621 { |
|
622 OstTraceFunctionEntry0( CALENMONTHGRID_PREPENDROWS_ENTRY ); |
|
623 |
551 // Before we do anything, set the focus to proper date |
624 // Before we do anything, set the focus to proper date |
552 // Set it only when non active day was focussed. When inactive day |
625 // Set it only when non active day was focussed. When inactive day |
553 // was focussed, we need to focus the same day |
626 // was focussed, we need to focus the same day |
554 if (!mIsNonActiveDayFocused) { |
627 if (!mIsNonActiveDayFocused) { |
555 setFocusToProperDay(); |
628 setFocusToProperDay(); |
605 // Update the mCurrentRow |
678 // Update the mCurrentRow |
606 mCurrentRow += countToBeAdded; |
679 mCurrentRow += countToBeAdded; |
607 |
680 |
608 // Update the sart position of the content widget |
681 // Update the sart position of the content widget |
609 mStartPos = mContentWidget->pos(); |
682 mStartPos = mContentWidget->pos(); |
|
683 |
|
684 OstTraceFunctionExit0( CALENMONTHGRID_PREPENDROWS_EXIT ); |
610 } |
685 } |
611 |
686 |
612 /*! |
687 /*! |
613 Helper function that prepends the required rows to the model |
688 Helper function that prepends the required rows to the model |
614 */ |
689 */ |
615 void CalenMonthGrid::handlePrependingRows(QList<CalenMonthData > &monthDataList) |
690 void CalenMonthGrid::handlePrependingRows(QList<CalenMonthData > &monthDataList) |
616 { |
691 { |
|
692 OstTraceFunctionEntry0( CALENMONTHGRID_HANDLEPREPENDINGROWS_ENTRY ); |
|
693 |
617 QDateTime currDate = mView->getCurrentDay(); |
694 QDateTime currDate = mView->getCurrentDay(); |
618 QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate ); |
695 QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate ); |
619 int rowsInPrevMonth = mView->rowsInPrevMonth(); |
696 int rowsInPrevMonth = mView->rowsInPrevMonth(); |
620 // Add the new days |
697 // Add the new days |
621 int countToBeAdded = rowsInPrevMonth * KCalenDaysInWeek; |
698 int countToBeAdded = rowsInPrevMonth * KCalenDaysInWeek; |
658 itemData << false; |
735 itemData << false; |
659 |
736 |
660 // Set the data to model |
737 // Set the data to model |
661 mModel->itemFromIndex(currentIndex)->setData(itemData); |
738 mModel->itemFromIndex(currentIndex)->setData(itemData); |
662 } |
739 } |
|
740 |
|
741 OstTraceFunctionExit0( CALENMONTHGRID_HANDLEPREPENDINGROWS_EXIT ); |
663 } |
742 } |
664 |
743 |
665 /*! |
744 /*! |
666 Called when Up gwsture is performed. Adds the new future month details |
745 Called when Up gwsture is performed. Adds the new future month details |
667 to the model |
746 to the model |
668 */ |
747 */ |
669 void CalenMonthGrid::appendRows() |
748 void CalenMonthGrid::appendRows() |
670 { |
749 { |
|
750 OstTraceFunctionEntry0( CALENMONTHGRID_APPENDROWS_ENTRY ); |
|
751 |
671 // Before we do anything, set the focus to proper date |
752 // Before we do anything, set the focus to proper date |
672 // Set it only when non active day was focussed. When inactive day |
753 // Set it only when non active day was focussed. When inactive day |
673 // was focussed, we need to focus the same day |
754 // was focussed, we need to focus the same day |
674 if (!mIsNonActiveDayFocused) { |
755 if (!mIsNonActiveDayFocused) { |
675 setFocusToProperDay(); |
756 setFocusToProperDay(); |
728 mIsAtomicScroll = true; |
809 mIsAtomicScroll = true; |
729 scrollTo(indexToBeScrolled); |
810 scrollTo(indexToBeScrolled); |
730 |
811 |
731 // Update the sart position of the content widget |
812 // Update the sart position of the content widget |
732 mStartPos = mContentWidget->pos(); |
813 mStartPos = mContentWidget->pos(); |
|
814 |
|
815 OstTraceFunctionExit0( CALENMONTHGRID_APPENDROWS_EXIT ); |
733 } |
816 } |
734 |
817 |
735 /*! |
818 /*! |
736 Helper function that appends the required rows to the model |
819 Helper function that appends the required rows to the model |
737 */ |
820 */ |
738 void CalenMonthGrid::handleAppendingRows(QList<CalenMonthData > &monthDataList) |
821 void CalenMonthGrid::handleAppendingRows(QList<CalenMonthData > &monthDataList) |
739 { |
822 { |
|
823 OstTraceFunctionEntry0( CALENMONTHGRID_HANDLEAPPENDINGROWS_ENTRY ); |
|
824 |
740 QDateTime currDate = mView->getCurrentDay(); |
825 QDateTime currDate = mView->getCurrentDay(); |
741 QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate ); |
826 QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate ); |
742 int rowsInFutMonth = mView->rowsInFutMonth(); |
827 int rowsInFutMonth = mView->rowsInFutMonth(); |
743 int countToBeAdded = rowsInFutMonth * KCalenDaysInWeek; |
828 int countToBeAdded = rowsInFutMonth * KCalenDaysInWeek; |
744 int lastVisibleIndex = monthDataList.count() - countToBeAdded; |
829 int lastVisibleIndex = monthDataList.count() - countToBeAdded; |
781 itemData << false; |
866 itemData << false; |
782 |
867 |
783 // Set the data to model |
868 // Set the data to model |
784 mModel->itemFromIndex(currentIndex)->setData(itemData); |
869 mModel->itemFromIndex(currentIndex)->setData(itemData); |
785 } |
870 } |
|
871 |
|
872 OstTraceFunctionExit0( CALENMONTHGRID_HANDLEAPPENDINGROWS_EXIT ); |
786 } |
873 } |
787 |
874 |
788 /*! |
875 /*! |
789 Slot to handle when a particular grid item is tapped |
876 Slot to handle when a particular grid item is tapped |
790 */ |
877 */ |
791 void CalenMonthGrid::itemActivated(const QModelIndex &index) |
878 void CalenMonthGrid::itemActivated(const QModelIndex &index) |
792 { |
879 { |
|
880 OstTraceFunctionEntry0( CALENMONTHGRID_ITEMACTIVATED_ENTRY ); |
|
881 |
793 if (mIgnoreItemActivated) { |
882 if (mIgnoreItemActivated) { |
794 mIgnoreItemActivated = false; |
883 mIgnoreItemActivated = false; |
|
884 OstTraceFunctionExit0( CALENMONTHGRID_ITEMACTIVATED_EXIT ); |
795 return; |
885 return; |
796 } |
886 } |
797 mIsNonActiveDayFocused = false; |
887 mIsNonActiveDayFocused = false; |
798 // Check if the same item has been tapped twice |
888 // Check if the same item has been tapped twice |
799 if (mCurrentRow == index.row()) { |
889 if (mCurrentRow == index.row()) { |
802 } else { |
892 } else { |
803 // Reset the focus attribute to this item |
893 // Reset the focus attribute to this item |
804 QModelIndex itemIndex = mModel->index(mCurrentRow,0); |
894 QModelIndex itemIndex = mModel->index(mCurrentRow,0); |
805 if(itemIndex.row() < 0 || itemIndex.row() >= mModel->rowCount() || |
895 if(itemIndex.row() < 0 || itemIndex.row() >= mModel->rowCount() || |
806 itemIndex.column() < 0 || itemIndex.column() > mModel->columnCount()) { |
896 itemIndex.column() < 0 || itemIndex.column() > mModel->columnCount()) { |
|
897 OstTraceFunctionExit0( DUP1_CALENMONTHGRID_ITEMACTIVATED_EXIT ); |
807 return; |
898 return; |
808 } |
899 } |
809 QVariant itemData = itemIndex.data(Qt::UserRole + 1); |
900 QVariant itemData = itemIndex.data(Qt::UserRole + 1); |
810 QVariantList list = itemData.toList(); |
901 QVariantList list = itemData.toList(); |
811 list.replace(CalendarNamespace::CalendarMonthFocusRole, false); |
902 list.replace(CalendarNamespace::CalendarMonthFocusRole, false); |
842 setActiveDates(activeMonth.addMonths(-2).date()); |
933 setActiveDates(activeMonth.addMonths(-2).date()); |
843 } |
934 } |
844 } |
935 } |
845 mView->setContextForActiveDay(index.row()); |
936 mView->setContextForActiveDay(index.row()); |
846 } |
937 } |
|
938 |
|
939 OstTraceFunctionExit0( DUP2_CALENMONTHGRID_ITEMACTIVATED_EXIT ); |
847 } |
940 } |
848 |
941 |
849 /*! |
942 /*! |
850 Sets the focus to proper day after the flick scrollng |
943 Sets the focus to proper day after the flick scrollng |
851 */ |
944 */ |
852 void CalenMonthGrid::setFocusToProperDay() |
945 void CalenMonthGrid::setFocusToProperDay() |
853 { |
946 { |
|
947 OstTraceFunctionEntry0( CALENMONTHGRID_SETFOCUSTOPROPERDAY_ENTRY ); |
|
948 |
854 // Calculate the new item to be focussed |
949 // Calculate the new item to be focussed |
855 QDateTime oldFocussedDate = mView->getActiveDay(); |
950 QDateTime oldFocussedDate = mView->getActiveDay(); |
856 QList<CalenMonthData> monthDataList = mView->monthDataList(); |
951 QList<CalenMonthData> monthDataList = mView->monthDataList(); |
857 int listCount = monthDataList.count(); |
952 int listCount = monthDataList.count(); |
858 int rowsInPrevMonth = mView->rowsInPrevMonth(); |
953 int rowsInPrevMonth = mView->rowsInPrevMonth(); |
885 mCurrentRow = i; |
980 mCurrentRow = i; |
886 mView->setContextForActiveDay(i); |
981 mView->setContextForActiveDay(i); |
887 break; |
982 break; |
888 } |
983 } |
889 } |
984 } |
|
985 |
|
986 OstTraceFunctionExit0( CALENMONTHGRID_SETFOCUSTOPROPERDAY_EXIT ); |
890 } |
987 } |
891 |
988 |
892 /*! |
989 /*! |
893 Sets the appropriate text color depending upon the active dates |
990 Sets the appropriate text color depending upon the active dates |
894 */ |
991 */ |
895 void CalenMonthGrid::setActiveDates(QDate activeDate) |
992 void CalenMonthGrid::setActiveDates(QDate activeDate) |
896 { |
993 { |
|
994 OstTraceFunctionEntry0( CALENMONTHGRID_SETACTIVEDATES_ENTRY ); |
|
995 |
897 // By default, text color will be set as inactive date color |
996 // By default, text color will be set as inactive date color |
898 // set active date color only for the dates that fall in current month |
997 // set active date color only for the dates that fall in current month |
899 // So, in the whole data array, start from where the current month starts |
998 // So, in the whole data array, start from where the current month starts |
900 // and stop the loop where it the current month ends |
999 // and stop the loop where it the current month ends |
901 |
1000 |
967 QVariant itemData = index.data(Qt::UserRole + 1); |
1067 QVariant itemData = index.data(Qt::UserRole + 1); |
968 QVariantList list = itemData.toList(); |
1068 QVariantList list = itemData.toList(); |
969 list.replace(CalendarNamespace::CalendarMonthTextColorRole, false); |
1069 list.replace(CalendarNamespace::CalendarMonthTextColorRole, false); |
970 mModel->itemFromIndex(index)->setData(list); |
1070 mModel->itemFromIndex(index)->setData(list); |
971 } |
1071 } |
|
1072 |
|
1073 OstTraceFunctionExit0( DUP1_CALENMONTHGRID_SETACTIVEDATES_EXIT ); |
972 } |
1074 } |
973 |
1075 |
974 /*! |
1076 /*! |
975 To get current foucsed index of monthGrid |
1077 To get current foucsed index of monthGrid |
976 */ |
1078 */ |
977 int CalenMonthGrid::getCurrentIndex() |
1079 int CalenMonthGrid::getCurrentIndex() |
978 { |
1080 { |
|
1081 OstTraceFunctionEntry0( CALENMONTHGRID_GETCURRENTINDEX_ENTRY ); |
|
1082 |
|
1083 OstTraceFunctionExit0( CALENMONTHGRID_GETCURRENTINDEX_EXIT ); |
979 return mCurrentRow; |
1084 return mCurrentRow; |
980 } |
1085 } |
981 |
1086 |
982 /*! |
1087 /*! |
983 To set the focus to Index |
1088 To set the focus to Index |
984 */ |
1089 */ |
985 void CalenMonthGrid::setCurrentIdex(int index) |
1090 void CalenMonthGrid::setCurrentIdex(int index) |
986 { |
1091 { |
|
1092 OstTraceFunctionEntry0( CALENMONTHGRID_SETCURRENTIDEX_ENTRY ); |
|
1093 |
987 itemActivated(mModel->index(index, 0)); |
1094 itemActivated(mModel->index(index, 0)); |
|
1095 |
|
1096 OstTraceFunctionExit0( CALENMONTHGRID_SETCURRENTIDEX_EXIT ); |
988 } |
1097 } |
989 |
1098 |
990 /*! |
1099 /*! |
991 Function to override the default behavior of hbgridview on orientation change |
1100 Function to override the default behavior of hbgridview on orientation change |
992 */ |
1101 */ |
993 void CalenMonthGrid::orientationChanged(Qt::Orientation newOrientation) |
1102 void CalenMonthGrid::orientationChanged(Qt::Orientation newOrientation) |
994 { |
1103 { |
|
1104 OstTraceFunctionEntry0( CALENMONTHGRID_ORIENTATIONCHANGED_ENTRY ); |
|
1105 |
995 Q_UNUSED(newOrientation) |
1106 Q_UNUSED(newOrientation) |
996 // We are overriding this function to avoid the default behavior of |
1107 // We are overriding this function to avoid the default behavior of |
997 // hbgridview on orientation change as it swaps the row and column counts |
1108 // hbgridview on orientation change as it swaps the row and column counts |
998 // Calculate the proper index to be scrolled to |
1109 // Calculate the proper index to be scrolled to |
999 int rowsInPrevMonth; |
1110 int rowsInPrevMonth; |
1016 KCalenDaysInWeek) - 1; |
1127 KCalenDaysInWeek) - 1; |
1017 indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
1128 indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
1018 mIsAtomicScroll = true; |
1129 mIsAtomicScroll = true; |
1019 scrollTo(indexToBeScrolled); |
1130 scrollTo(indexToBeScrolled); |
1020 } |
1131 } |
|
1132 |
|
1133 OstTraceFunctionExit0( CALENMONTHGRID_ORIENTATIONCHANGED_EXIT ); |
1021 } |
1134 } |
1022 |
1135 |
1023 /*! |
1136 /*! |
1024 Paint function to draw grid lines |
1137 Paint function to draw grid lines |
1025 */ |
1138 */ |
1026 void CalenMonthGrid::paint(QPainter* painter, |
1139 void CalenMonthGrid::paint(QPainter* painter, |
1027 const QStyleOptionGraphicsItem* option, |
1140 const QStyleOptionGraphicsItem* option, |
1028 QWidget* widget) |
1141 QWidget* widget) |
1029 { |
1142 { |
|
1143 OstTraceFunctionEntry0( CALENMONTHGRID_PAINT_ENTRY ); |
|
1144 |
1030 Q_UNUSED(option); |
1145 Q_UNUSED(option); |
1031 Q_UNUSED(widget); |
1146 Q_UNUSED(widget); |
1032 painter->setRenderHint(QPainter::NonCosmeticDefaultPen); |
1147 painter->setRenderHint(QPainter::NonCosmeticDefaultPen); |
1033 |
1148 |
1034 // Set the required attributes to the pen |
1149 // Set the required attributes to the pen |
1041 if (mGridLineColor.isValid()) { |
1156 if (mGridLineColor.isValid()) { |
1042 pen.setBrush(mGridLineColor); |
1157 pen.setBrush(mGridLineColor); |
1043 } else { |
1158 } else { |
1044 pen.setBrush(mGridBorderColor); |
1159 pen.setBrush(mGridBorderColor); |
1045 } |
1160 } |
1046 //store the old pen first |
1161 // Store the old pen |
1047 QPen oldPen = painter->pen(); |
1162 QPen oldPen = painter->pen(); |
|
1163 |
1048 // Set the new pen to the painter |
1164 // Set the new pen to the painter |
1049 painter->setPen(pen); |
1165 painter->setPen(pen); |
1050 |
1166 |
1051 // Get the sizes of content widget |
1167 // Get the sizes of content widget |
1052 qreal contentHeight = mContentWidget->size().height(); |
1168 qreal contentHeight = mContentWidget->size().height(); |