calendarui/views/src/calenmonthgrid.cpp
changeset 70 a5ed90760192
parent 63 a3cb48f6c889
child 75 7ac58b2aae6f
equal deleted inserted replaced
64:1881ad52dc45 70:a5ed90760192
    64 	mView(NULL),
    64 	mView(NULL),
    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 {
    71 {
    71     OstTraceFunctionEntry0( CALENMONTHGRID_CALENMONTHGRID_ENTRY );
    72     OstTraceFunctionEntry0( CALENMONTHGRID_CALENMONTHGRID_ENTRY );
    72     
    73     
    73 	setScrollDirections(Qt::Vertical);
    74 	setScrollDirections(Qt::Vertical);
    74 	setRowCount(KNumOfVisibleRows);
    75 	setRowCount(KNumOfVisibleRows);
   338  Scrolls the content dowmwards
   339  Scrolls the content dowmwards
   339  */
   340  */
   340 void CalenMonthGrid::downGesture()
   341 void CalenMonthGrid::downGesture()
   341 {
   342 {
   342     OstTraceFunctionEntry0( CALENMONTHGRID_DOWNGESTURE_ENTRY );
   343     OstTraceFunctionEntry0( CALENMONTHGRID_DOWNGESTURE_ENTRY );
   343     
   344     mIsGridAdjusting = true;
   344     // Make sure that content widget is properly placed
   345     // Make sure that content widget is properly placed
   345     // We are doing this as tapping on inactive date of previous month is leading to
   346     // We are doing this as tapping on inactive date of previous month is leading to
   346     // position the grid at wrong place after scrolling down. Hence, set the grid
   347     // position the grid at wrong place after scrolling down. Hence, set the grid
   347     // at proper position before we start actual scrolling
   348     // at proper position before we start actual scrolling
   348     if (mIsNonActiveDayFocused) {
   349     if (mIsNonActiveDayFocused) {
   378  Scrolls the content upwards
   379  Scrolls the content upwards
   379  */
   380  */
   380 void CalenMonthGrid::upGesture()
   381 void CalenMonthGrid::upGesture()
   381 {
   382 {
   382     OstTraceFunctionEntry0( CALENMONTHGRID_UPGESTURE_ENTRY );
   383     OstTraceFunctionEntry0( CALENMONTHGRID_UPGESTURE_ENTRY );
   383     
   384 	
   384    
   385     mIsGridAdjusting = true;
       
   386 
   385     // Set the required flags
   387     // Set the required flags
   386     mDirection = up;
   388     mDirection = up;
   387     mIsAtomicScroll = false;
   389     mIsAtomicScroll = false;
   388     
   390     
   389     // Set the active and inactive dates
   391     // Set the active and inactive dates
   442  */
   444  */
   443 void CalenMonthGrid::gestureEvent(QGestureEvent *event)
   445 void CalenMonthGrid::gestureEvent(QGestureEvent *event)
   444 {
   446 {
   445     OstTraceFunctionEntry0( CALENMONTHGRID_GESTUREEVENT_ENTRY );
   447     OstTraceFunctionEntry0( CALENMONTHGRID_GESTUREEVENT_ENTRY );
   446     
   448     
       
   449     // Dont listem for any gesture when grid is getting adjusted as listening to those was causing
       
   450     // grid to stop abruptly i between
       
   451     if (mIsGridAdjusting) {
       
   452         // consume the event and return
       
   453         qDebug()<<"RETURNING BACK";
       
   454         event->ignore();
       
   455         return;
       
   456     }
       
   457 	
   447    if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) {
   458    if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) {
   448         if (gesture->state() == Qt::GestureStarted) {
   459         if (gesture->state() == Qt::GestureStarted) {
   449             mIsAtomicScroll = false;
   460             mIsAtomicScroll = false;
   450             if (!mIsPanGesture) {
   461             if (!mIsPanGesture) {
   451                 mDirection = invalid;
   462                 mDirection = invalid;
   540  Gets called when scrolling finishes to update the model
   551  Gets called when scrolling finishes to update the model
   541  */
   552  */
   542 void CalenMonthGrid::scrollingFinished()
   553 void CalenMonthGrid::scrollingFinished()
   543 {
   554 {
   544     OstTraceFunctionEntry0( CALENMONTHGRID_SCROLLINGFINISHED_ENTRY );
   555     OstTraceFunctionEntry0( CALENMONTHGRID_SCROLLINGFINISHED_ENTRY );
   545     
   556 
       
   557     mIsGridAdjusting = false;
   546 	if (mIsPanGesture) {
   558 	if (mIsPanGesture) {
   547 		handlePanGestureFinished();
   559 		handlePanGestureFinished();
   548 	} else if(!mIsAtomicScroll) {
   560 		// Check if still request has been made for scrolling
       
   561 		// if yes, then simply return
       
   562 		if (mDirection != invalid) {
       
   563             mIgnoreItemActivated = false;
       
   564             return;
       
   565 		}
       
   566 	} 
       
   567 	
       
   568 	if(!mIsAtomicScroll) {
   549 		QDateTime activeDate = mView->getActiveDay();
   569 		QDateTime activeDate = mView->getActiveDay();
   550 		if(mDirection == down) { // down gesture
   570 		if(mDirection == down) { // down gesture
   551 			if (!mActiveDatesSet) {
   571 			if (!mActiveDatesSet) {
   552 				setActiveDates(activeDate.addMonths(-1).date());
   572 				setActiveDates(activeDate.addMonths(-1).date());
   553 				setFocusToProperDay();
   573 				setFocusToProperDay();
   577 void CalenMonthGrid::handlePanGestureFinished()
   597 void CalenMonthGrid::handlePanGestureFinished()
   578 {
   598 {
   579     OstTraceFunctionEntry0( CALENMONTHGRID_HANDLEPANGESTUREFINISHED_ENTRY );
   599     OstTraceFunctionEntry0( CALENMONTHGRID_HANDLEPANGESTUREFINISHED_ENTRY );
   580     
   600     
   581 	mIsPanGesture = false;
   601 	mIsPanGesture = false;
       
   602 	// Reset the mDirection flag
       
   603 	mDirection = invalid;
   582 	// Get the first item that is visible
   604 	// Get the first item that is visible
   583 	QList<HbAbstractViewItem *> list = visibleItems();
   605 	QList<HbAbstractViewItem *> list = visibleItems();
   584 	HbAbstractViewItem* item = list[0];
   606 	HbAbstractViewItem* item = list[0];
   585 	QModelIndex modelIndex = item->modelIndex();
   607 	QModelIndex modelIndex = item->modelIndex();
   586 	
   608 	
   611 		}
   633 		}
   612 	} else if (month == prevMonth.date().month()) {
   634 	} else if (month == prevMonth.date().month()) {
   613 		// first visible item belongs to previous month
   635 		// first visible item belongs to previous month
   614 		// Check if the date is more than half of the previous month
   636 		// Check if the date is more than half of the previous month
   615 		if (date.date().day() > (prevMonth.date().daysInMonth()) / 2) {
   637 		if (date.date().day() > (prevMonth.date().daysInMonth()) / 2) {
   616 			// we should again show the current month by scrolling upwards
   638 			// we should again show the current month by scrolling downwards
   617 			mDirection = up;
   639 			mDirection = down;
   618 			mIsAtomicScroll = true;
   640 			mIsAtomicScroll = true;
   619 			scrollContentsTo(-mStartPos,500);
   641 			scrollContentsTo(-mStartPos,500);
   620 		} else {
   642 		} else {
   621 			// down gesture to show the previous month
   643 			// down gesture to show the previous month
   622 			downGesture();
   644 			downGesture();
   632 			// up gesture to bring the next month
   654 			// up gesture to bring the next month
   633 			upGesture();
   655 			upGesture();
   634 		} else {
   656 		} else {
   635 			// we should again show the current month by scrolling upwards
   657 			// we should again show the current month by scrolling upwards
   636 			mDirection = up;
   658 			mDirection = up;
       
   659 			mIsAtomicScroll = true;
   637 			scrollContentsTo(-mStartPos,500);
   660 			scrollContentsTo(-mStartPos,500);
   638 		}
   661 		}
   639 	} else if (month == nextMonth.addMonths(1).date().month()) {
   662 	} else if (month == nextMonth.addMonths(1).date().month()) {
   640 		// first visible date belongs to next to next month
   663 		// first visible date belongs to next to next month
   641 		// hence, scroll up to show the next month
   664 		// hence, scroll up to show the next month
   642 		upGesture();
   665 		upGesture();
       
   666 	} else {
       
   667         // User has panned so that exact month has been scrolled
       
   668         // no need for any adjustment here, just append/prepend the rows
       
   669         mIsAtomicScroll = false;
   643 	}
   670 	}
   644 	
   671 	
   645 	OstTraceFunctionExit0( CALENMONTHGRID_HANDLEPANGESTUREFINISHED_EXIT );
   672 	OstTraceFunctionExit0( CALENMONTHGRID_HANDLEPANGESTUREFINISHED_EXIT );
   646 }
   673 }
   647 
   674