calendarui/views/dayview/src/calendaycontentscrollarea.cpp
changeset 58 ef813d54df51
parent 50 579cc610882e
child 68 a5a1242fd2e8
equal deleted inserted replaced
50:579cc610882e 58:ef813d54df51
    24 
    24 
    25 // User includes
    25 // User includes
    26 #include "calendaycontentscrollarea.h"
    26 #include "calendaycontentscrollarea.h"
    27 #include "calendayutils.h"
    27 #include "calendayutils.h"
    28 
    28 
       
    29 // Constants
       
    30 /*!
       
    31  Default timeout for scrolling between days [ms]
       
    32  */
       
    33 const int KCalenScrollDaysTimeout = 600;
       
    34 
       
    35 /*!
       
    36  Value [%] defines how long (depending on content area width) should horizontal
       
    37  pan gesture be to change day to previous/next.
       
    38  If the gesture is shorter - current view is not changed.
       
    39  */
       
    40 const int KCalenHScrollMoveParam = 30;  //!< Percentage
       
    41 
       
    42 /*!
       
    43  Value [degree] defines the max. angle of swipe gesture which should change day.
       
    44  */
       
    45 const qreal KCalenSwipeAngle = 30;
       
    46 
       
    47 
    29 /*!
    48 /*!
    30  \class CalenDayContentScrollArea
    49  \class CalenDayContentScrollArea
    31  \brief Scrollable container class for content widgets.
    50  \brief Scrollable container class for content widgets.
    32  
    51  
    33  It handles horizontal scrolling and swipe or pan gestures.
    52  It handles horizontal scrolling and swipe or pan gestures.
    42  \param parent The parent of scroll area widget
    61  \param parent The parent of scroll area widget
    43  */
    62  */
    44 CalenDayContentScrollArea::CalenDayContentScrollArea(QGraphicsItem *parent) :
    63 CalenDayContentScrollArea::CalenDayContentScrollArea(QGraphicsItem *parent) :
    45     HbScrollArea(parent), mPanDayDirection(ECalenPanNotSet), mIsMoving(false),
    64     HbScrollArea(parent), mPanDayDirection(ECalenPanNotSet), mIsMoving(false),
    46     mMoveDirection(ECalenScrollNoDayChange)
    65     mMoveDirection(ECalenScrollNoDayChange)
    47 {
    66 { 
    48     // Set scroll settings
       
    49     setScrollDirections(Qt::Horizontal);
       
    50     setClampingStyle(StrictClamping);
       
    51     setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
       
    52     
       
    53 #ifdef CALENDAYVIEW_PANNING_ENABLED
    67 #ifdef CALENDAYVIEW_PANNING_ENABLED
    54     grabGesture(Qt::PanGesture);
    68     grabGesture(Qt::PanGesture);
    55     ungrabGesture(Qt::SwipeGesture);
    69     ungrabGesture(Qt::SwipeGesture);
    56 #else
    70 #else
    57     grabGesture(Qt::SwipeGesture);
    71     grabGesture(Qt::SwipeGesture);
    59 #endif
    73 #endif
    60 
    74 
    61     // Get the width of content area and orientation of screen
    75     // Get the width of content area and orientation of screen
    62     mContentWidth = CalenDayUtils::instance()->contentWidth();
    76     mContentWidth = CalenDayUtils::instance()->contentWidth();
    63     mOrientation = CalenDayUtils::instance()->orientation();
    77     mOrientation = CalenDayUtils::instance()->orientation();
       
    78     
       
    79     // Fix the width of scroll area
       
    80     setMinimumWidth(mContentWidth);
       
    81     setMaximumWidth(mContentWidth);
    64 
    82 
    65     // Connect to main window's orientationChanged SIGNAL to handle orientation
    83     // Connect to main window's orientationChanged SIGNAL to handle orientation
    66     // switching
    84     // switching
    67     connect(CalenDayUtils::instance()->mainWindow(), 
    85     connect(CalenDayUtils::instance()->mainWindow(), 
    68         SIGNAL(orientationChanged(Qt::Orientation)), this,
    86         SIGNAL(orientationChanged(Qt::Orientation)), this,
   212         qobject_cast<HbSwipeGesture *> (event->gesture(Qt::SwipeGesture))) {
   230         qobject_cast<HbSwipeGesture *> (event->gesture(Qt::SwipeGesture))) {
   213         if (swipeGesture->state() == Qt::GestureStarted) {
   231         if (swipeGesture->state() == Qt::GestureStarted) {
   214             mStartPosition = contentWidget()->pos();
   232             mStartPosition = contentWidget()->pos();
   215             
   233             
   216             qreal swipeAngle = swipeGesture->sceneSwipeAngle();
   234             qreal swipeAngle = swipeGesture->sceneSwipeAngle();
   217             if (CalenDayUtils::instance()->isHorizontalSwipe(swipeAngle)) {
   235             if (isHorizontalSwipe(swipeAngle)) {
   218                 if (QSwipeGesture::Left == 
   236                 if (QSwipeGesture::Left == 
   219                     swipeGesture->sceneHorizontalDirection()) {
   237                     swipeGesture->sceneHorizontalDirection()) {
   220                     mMoveDirection = ECalenScrollToNext;
   238                     mMoveDirection = ECalenScrollToNext;
   221                     moveTo(QPointF((-mStartPosition.x() + mContentWidth),
   239                     moveTo(QPointF((-mStartPosition.x() + mContentWidth),
   222                             -mStartPosition.y()), KCalenScrollDaysTimeout);
   240                             -mStartPosition.y()), KCalenScrollDaysTimeout);
   371         emit scrollAreaMoveStarted(mMoveDirection);
   389         emit scrollAreaMoveStarted(mMoveDirection);
   372     }
   390     }
   373 }
   391 }
   374 
   392 
   375 /*!
   393 /*!
       
   394  \brief isHorizontalSwipe
       
   395  
       
   396  \return TRUE if horizontal swipe was recognized (angle in specific range)
       
   397  */
       
   398 bool CalenDayContentScrollArea::isHorizontalSwipe(qreal angle) const
       
   399 {
       
   400     bool isHSwipe = false;
       
   401     if ((angle < KCalenSwipeAngle) || 
       
   402         ((angle > 180 - KCalenSwipeAngle) && (angle < 180 + KCalenSwipeAngle)) ||
       
   403         (angle > 360 - KCalenSwipeAngle)) {
       
   404         isHSwipe = true;
       
   405     }
       
   406     
       
   407     return isHSwipe;
       
   408 }
       
   409 
       
   410 /*!
   376  \brief Slot which is called when moving of scroll area is finished.
   411  \brief Slot which is called when moving of scroll area is finished.
   377  
   412  
   378  Resets internal isMoving flag.
   413  Resets internal isMoving flag.
   379  */
   414  */
   380 void CalenDayContentScrollArea::moveFinished()
   415 void CalenDayContentScrollArea::moveFinished()
   400 void CalenDayContentScrollArea::orientationChanged(Qt::Orientation orientation)
   435 void CalenDayContentScrollArea::orientationChanged(Qt::Orientation orientation)
   401 {
   436 {
   402     // Update the width of content area
   437     // Update the width of content area
   403     mContentWidth = CalenDayUtils::instance()->contentWidth();
   438     mContentWidth = CalenDayUtils::instance()->contentWidth();
   404     mOrientation = orientation;
   439     mOrientation = orientation;
   405     
   440 
       
   441     // Fix the width of scroll area
       
   442     setMinimumWidth(mContentWidth);
       
   443     setMaximumWidth(mContentWidth);
       
   444 
       
   445     scrollToMiddleWidget();
       
   446 
   406     // Reset flag related to moving
   447     // Reset flag related to moving
   407     mPanDayDirection = ECalenPanNotSet;
   448     mPanDayDirection = ECalenPanNotSet;
   408     mMoveDirection = ECalenScrollNoDayChange;
   449     mMoveDirection = ECalenScrollNoDayChange;
   409     mIsMoving = false;
   450     mIsMoving = false;
   410 }
   451 }