src/hbcore/gestures/hbswipegesture.cpp
changeset 6 c3690ec91ef8
parent 2 06ff229162e9
child 30 80e4d18b72f5
child 34 ed14f46c0e55
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
    32 
    32 
    33 /*!
    33 /*!
    34     @hbcore
    34     @hbcore
    35     \class HbSwipeGesture
    35     \class HbSwipeGesture
    36 
    36 
    37     \brief HbSwipeGesture is an extension to Qt standard HbSwipeGesture
    37     \brief The HbSwipeGesture class provides support for receiving a swipe
       
    38     (flick) gesture.
       
    39     
       
    40     HbSwipeGesture is an extension to Qt standard QSwipeGesture. It is
       
    41     optimized for mobile touch screens, and also supports recognition of
       
    42     mouse events for development purposes. Moreover, HbSwipeGesture
       
    43     has convenience functions for handling the QSwipeGesture properties
       
    44     (horizontalDirection, verticalDirection, swipeAngle) directly in scene
       
    45     coordinates. They remove the need for any manual conversions from the
       
    46     screen (global) coordinates offered by the QSwipeGesture base class
       
    47     properties.
       
    48     
       
    49     The swipe gesture is designed to be used as a single-shot gesture which
       
    50     is activated after a flick and release. No events are sent until the
       
    51     gesture is finished. Swipe should be used when feedback during the
       
    52     gesture is not possible or desired.
       
    53 
       
    54     \section _usecases_hbswipegesture Using the HbSwipeGesture class
       
    55     
       
    56     This example shows how to make a custom widget recognize the swipe
       
    57     gesture. The custom widget in the example derives from HbWidget.
       
    58     
       
    59     <ol>
       
    60     <li>
       
    61     Register for swipe gestures by using the base class function
       
    62     QGraphicsObject::grabGesture(). QGraphicsObject::grabGesture() can be
       
    63     called several times with different arguments, if the widget is
       
    64     interested in other gesture types as well.
       
    65    
       
    66     \code
       
    67     // This widget is interested in swipe and tap gestures.
       
    68     grabGesture(Qt::SwipeGesture);
       
    69     grabGesture(Qt::TapGesture);
       
    70     \endcode
       
    71     </li>
       
    72     
       
    73     <li>
       
    74     Reimplement HbWidgetBase::gestureEvent() to handle gestures that are
       
    75     meaningful for your custom widget.
       
    76    
       
    77     \code
       
    78     void MyWidget::gestureEvent(QGestureEvent *event)
       
    79     {
       
    80         if (HbSwipeGesture *swipe = qobject_cast<HbSwipeGesture *>
       
    81             (event->gesture(Qt::SwipeGesture))) {
       
    82        
       
    83             switch (swipe->state()) {
       
    84            
       
    85             case Qt::GestureStarted: // fall-through
       
    86             case Qt::GestureUpdated: // fall-through
       
    87             case Qt::GestureCanceled:
       
    88                 break;
       
    89             case Qt::GestureFinished:             
       
    90                 // Emit a signal to show the swipe movement.           
       
    91                 break;
       
    92             default:
       
    93                 break;
       
    94             }           
       
    95         }
       
    96        
       
    97         // Handle other gesture types that have been grabbed. There may be
       
    98         // several, since all gestures that are active at the same moment
       
    99         // are sent within the same gesture event.
       
   100         if (HbTapGesture *tap = qobject_cast<HbTapGesture *>
       
   101             (event->gesture(Qt::TapGesture))) {
       
   102             // handle the tap gesture
       
   103         }
       
   104        
       
   105     }   
       
   106     \endcode
       
   107     </li>
       
   108     </ol>
       
   109         
    38     \sa QSwipeGesture
   110     \sa QSwipeGesture
    39 */
   111 */
    40 
   112 
    41 const int KHbDirectionThreshold = 45; // degrees
   113 const int KHbDirectionThreshold = 45; // degrees
    42 
   114 
    43 /*!
   115 /*!
    44     \brief HbSwipeGesture constructor
   116     Constructor.
    45     \param parent Owner for gesture
   117     \param parent Owner for gesture
    46 */
   118 */
    47 HbSwipeGesture::HbSwipeGesture(QObject *parent)
   119 HbSwipeGesture::HbSwipeGesture(QObject *parent)
    48     : QSwipeGesture(parent), d_ptr(new HbSwipeGesturePrivate)
   120     : QSwipeGesture(parent), d_ptr(new HbSwipeGesturePrivate)
    49 
   121 
    50 {   
   122 {   
    51     d_ptr->mSceneSwipeAngle = 0;
   123     d_ptr->mSceneSwipeAngle = 0;
    52 }
   124 }
    53 
   125 
    54 /*!
   126 /*!
    55     \brief HbSwipeGesture constructor
   127     Constructor required by the shared d-pointer paradigm.
    56     \param dd Private data
   128     \param dd Private data
    57     \param parent Owner for gesture
   129     \param parent Owner for gesture
    58 */
   130 */
    59 HbSwipeGesture::HbSwipeGesture(HbSwipeGesturePrivate &dd, QObject *parent)
   131 HbSwipeGesture::HbSwipeGesture(HbSwipeGesturePrivate &dd, QObject *parent)
    60     : QSwipeGesture(parent), d_ptr(&dd)
   132     : QSwipeGesture(parent), d_ptr(&dd)
    61 {
   133 {
    62 
   134 
    63 }
   135 }
    64 
   136 
    65 /*!
   137 /*!
    66     \brief HbSwipeGesture destructor
   138     Destructor.
    67 */
   139 */
    68 HbSwipeGesture::~HbSwipeGesture()
   140 HbSwipeGesture::~HbSwipeGesture()
    69 {
   141 {
    70     delete d_ptr;
   142     delete d_ptr;
    71 }
   143 }
    72 
   144 
    73 /*!
   145 /*!
    74     \property sceneHorizontalDirection
   146     Returns the horizontal direction of the swipe gesture
    75     \brief Horizontal direction of swipe in scene coordinates.
   147     relative to scene coordinates.
    76 
   148 
    77     \sa QSwipeGesture::horizontalDirection()
   149     \sa QSwipeGesture::horizontalDirection()
    78 */
   150 */
    79 QSwipeGesture::SwipeDirection HbSwipeGesture::sceneHorizontalDirection() const
   151 QSwipeGesture::SwipeDirection HbSwipeGesture::sceneHorizontalDirection() const
    80 {
   152 {
    84         return QSwipeGesture::Left;
   156         return QSwipeGesture::Left;
    85     else
   157     else
    86         return QSwipeGesture::NoDirection;
   158         return QSwipeGesture::NoDirection;
    87 }
   159 }
    88 /*!
   160 /*!
    89     \property sceneVerticalDirection
   161     Returns the vertical direction of the swipe gesture
    90     \brief Vertical direction of swipe in scene coordinates.
   162     relative to scene coordinates.
    91     \sa QSwipeGesture::verticalDirection()
   163     \sa QSwipeGesture::verticalDirection()
    92 */
   164 */
    93 QSwipeGesture::SwipeDirection HbSwipeGesture::sceneVerticalDirection() const
   165 QSwipeGesture::SwipeDirection HbSwipeGesture::sceneVerticalDirection() const
    94 {    
   166 {    
    95     if (d_ptr->mSceneSwipeAngle < 180 - KHbDirectionThreshold && d_ptr->mSceneSwipeAngle > 0 + KHbDirectionThreshold)
   167     if (d_ptr->mSceneSwipeAngle < 180 - KHbDirectionThreshold && d_ptr->mSceneSwipeAngle > 0 + KHbDirectionThreshold)
    99     else
   171     else
   100         return QSwipeGesture::NoDirection;
   172         return QSwipeGesture::NoDirection;
   101 }
   173 }
   102 
   174 
   103 /*!
   175 /*!
   104     \property sceneSwipeAngle
   176     Returns the angle for the swipe gesture in degrees,
   105     \brief Angle for swipe in scene coordinates.
   177     taking into account any scene transformations.
   106     \sa QSwipeGesture::swipeAngle()
   178     \sa setSceneSwipeAngle(), QSwipeGesture::swipeAngle()
   107 */
   179 */
   108 qreal HbSwipeGesture::sceneSwipeAngle() const
   180 qreal HbSwipeGesture::sceneSwipeAngle() const
   109 {
   181 {
   110     return d_ptr->mSceneSwipeAngle;
   182     return d_ptr->mSceneSwipeAngle;
   111 }
   183 }
   112 
   184 
       
   185 /*!
       
   186     Sets the angle for the swipe gesture.
       
   187     This function is used by the framework gesture recognition logic,
       
   188     and it should not be used by the widget receiving the gesture.
       
   189     \sa sceneSwipeAngle(), QSwipeGesture::setSwipeAngle()
       
   190 */
   113 void HbSwipeGesture::setSceneSwipeAngle(qreal value)
   191 void HbSwipeGesture::setSceneSwipeAngle(qreal value)
   114 {
   192 {
   115     d_ptr->mSceneSwipeAngle = value;
   193     d_ptr->mSceneSwipeAngle = value;
   116 }
   194 }
   117 
   195 
   118 
   196 
   119 /*!
   197 /*!
   120     \deprecated
   198     \deprecated
   121     \property speed
   199     Returns the speed.
   122 */
   200 */
   123 qreal HbSwipeGesture::speed() const
   201 qreal HbSwipeGesture::speed() const
   124 {    
   202 {    
   125     HB_DEPRECATED("HbSwipeGesture::speed is deprecated");
   203     HB_DEPRECATED("HbSwipeGesture::speed is deprecated");
   126     return 1;
   204     return 1;
   127 }
   205 }
   128 
   206 
       
   207 /*!
       
   208     \deprecated
       
   209     Sets the speed.
       
   210 */
   129 void HbSwipeGesture::setSpeed(qreal speed)
   211 void HbSwipeGesture::setSpeed(qreal speed)
   130 {
   212 {
   131     Q_UNUSED (speed);
   213     Q_UNUSED (speed);
   132     HB_DEPRECATED("HbSwipeGesture::setSpeed is deprecated");
   214     HB_DEPRECATED("HbSwipeGesture::setSpeed is deprecated");
   133 }
   215 }
   134 
   216 
   135 /*!
   217 /*!
   136     \deprecated
   218     \deprecated
   137     \property touchPointCount
   219     Returns the touchPointCount.
   138 */
   220 */
   139 int HbSwipeGesture::touchPointCount() const
   221 int HbSwipeGesture::touchPointCount() const
   140 {
   222 {
   141     HB_DEPRECATED("HbSwipeGesture::touchPointCount is deprecated");
   223     HB_DEPRECATED("HbSwipeGesture::touchPointCount is deprecated");
   142     return 0;
   224     return 0;
   143 }
   225 }
   144 
   226 
       
   227 /*!
       
   228     \deprecated
       
   229     Sets the touchPointCount.
       
   230 */
   145 void HbSwipeGesture::setTouchPointCount(int touchPointCount)
   231 void HbSwipeGesture::setTouchPointCount(int touchPointCount)
   146 {
   232 {
   147     HB_DEPRECATED("HbSwipeGesture::setTouchPointCount is deprecated");
   233     HB_DEPRECATED("HbSwipeGesture::setTouchPointCount is deprecated");
   148     Q_UNUSED(touchPointCount)
   234     Q_UNUSED(touchPointCount)
   149 }
   235 }