src/hbcore/gestures/hbtapandholdgesture.cpp
changeset 6 c3690ec91ef8
parent 2 06ff229162e9
child 30 80e4d18b72f5
child 34 ed14f46c0e55
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
    31 
    31 
    32 /*!
    32 /*!
    33     @hbcore
    33     @hbcore
    34     \class HbTapAndHoldGesture
    34     \class HbTapAndHoldGesture
    35 
    35 
    36     \brief HbTapAndHoldGesture is an extension to Qt standard QTapAndHoldGesture
    36     \brief The HbTapAndHoldGesture class provides support for receiving
    37     \sa QTapAndHoldGesture
    37     tap-and-hold gestures.
       
    38     
       
    39     HbTapAndHoldGesture is an extension to Qt standard QTapAndHoldGesture.
       
    40     It is optimized for mobile touch screens, and also supports recognition
       
    41     of mouse events for development purposes. It also gives information about
       
    42     the tap-and-hold gesture position directly in scene coordinates, removing
       
    43     any need for manual conversions from the screen (global) coordinates
       
    44     offered by QTapAndHoldGesture.
       
    45     
       
    46     Use HbTapAndHoldGesture for a custom widget that is only interested in
       
    47     the tap-and-hold (long tap) gesture. If you want your custom widget to
       
    48     receive both short and long taps, use HbTapGesture instead, since it
       
    49     supports both.
       
    50     
       
    51     \section _usecases_hbtapandholdgesture Using the HbTapAndHoldGesture class
       
    52     
       
    53     This example shows how to make a custom widget recognize the tap-and-hold
       
    54     gesture. The custom widget in the example derives from HbWidget.
       
    55     
       
    56     <ol>
       
    57     <li>
       
    58     Register for tap-and-hold gestures by using the base class function
       
    59     QGraphicsObject::grabGesture(). QGraphicsObject::grabGesture() can be
       
    60     called several times with different arguments, if the widget is
       
    61     interested in other gesture types as well.
       
    62    
       
    63     \code
       
    64     // This widget is interested in tap-and-hold and pan gestures.
       
    65     grabGesture(Qt::TapAndHoldGesture);
       
    66     grabGesture(Qt::PanGesture);
       
    67     \endcode
       
    68     </li>
       
    69     
       
    70     <li>
       
    71     Reimplement HbWidgetBase::gestureEvent() to handle gestures that are
       
    72     meaningful for your custom widget.
       
    73    
       
    74     \code
       
    75     void MyWidget::gestureEvent(QGestureEvent *event)
       
    76     {
       
    77         if (HbTapAndHoldGesture *tapAndHold =
       
    78             qobject_cast<HbTapAndHoldGesture *>
       
    79                 (event->gesture(Qt::TapAndHoldGesture))) {
       
    80        
       
    81             switch (tapAndHold->state()) {
       
    82            
       
    83             case Qt::GestureStarted:
       
    84                 // Visualize the active state of the widget.
       
    85                 break;
       
    86                 
       
    87             // No GestureUpdated events are sent for this gesture type,
       
    88             // so no handling is needed for those
       
    89              
       
    90             case Qt::GestureCanceled:
       
    91                 // Visualize the non-active state of the widget.
       
    92                 break;
       
    93             case Qt::GestureFinished:              
       
    94                 // Visualize the non-active state of the widget.
       
    95                 // Emit a long tap signal.              
       
    96                 break;
       
    97             default:
       
    98                 break;
       
    99             }           
       
   100         }
       
   101        
       
   102         // Handle other gesture types that have been grabbed. There may be
       
   103         // several, since all gestures that are active at the same moment
       
   104         // are sent within the same gesture event.
       
   105         if (HbPanGesture *pan = qobject_cast<HbPanGesture *>
       
   106             (event->gesture(Qt::PanGesture))) {
       
   107             // handle the pan gesture
       
   108         }
       
   109        
       
   110     }   
       
   111     \endcode
       
   112     </li>
       
   113     </ol>
       
   114    
       
   115     \sa HbTapGesture, QTapAndHoldGesture
    38 */
   116 */
    39 
   117 
    40 /*!
   118 /*!
    41     \brief HbTapAndHoldGesture constructor
   119     Constructor.
    42     \param parent Parent for the gesture
   120     \param parent Parent for the gesture
    43 */
   121 */
    44 HbTapAndHoldGesture::HbTapAndHoldGesture(QObject* parent)
   122 HbTapAndHoldGesture::HbTapAndHoldGesture(QObject* parent)
    45     :
   123     :
    46     QTapAndHoldGesture(parent)
   124     QTapAndHoldGesture(parent)
    47 {
   125 {
    48     priv = new HbTapAndHoldGesturePrivate(this);
   126     priv = new HbTapAndHoldGesturePrivate(this);
    49 }
   127 }
    50 
   128 
    51 /*!
   129 /*!
    52     \brief HbTapAndHoldGesture constructor
   130     Constructor required by the shared d-pointer paradigm.
    53     \param dd Custom private data
   131     \param dd Custom private data
    54     \param parent Parent for the gesture
   132     \param parent Parent for the gesture
    55 */
   133 */
    56 HbTapAndHoldGesture::HbTapAndHoldGesture(HbTapAndHoldGesturePrivate* dd, QObject* parent)
   134 HbTapAndHoldGesture::HbTapAndHoldGesture(HbTapAndHoldGesturePrivate* dd, QObject* parent)
    57     :
   135     :
    60 {
   138 {
    61     priv->q_ptr = this;
   139     priv->q_ptr = this;
    62 }
   140 }
    63 
   141 
    64 /*!
   142 /*!
    65     \brief HbTapAndHoldGesture destructor
   143     Destructor.
    66 */
   144 */
    67 HbTapAndHoldGesture::~HbTapAndHoldGesture()
   145 HbTapAndHoldGesture::~HbTapAndHoldGesture()
    68 {
   146 {
    69     delete priv; priv = NULL;
   147     delete priv; priv = NULL;
    70 }
   148 }
    71 
   149 
    72 /*!
   150 /*!
    73     \property scenePosition
   151     Returns the current position of the gesture in scene coordinates.
    74 
   152     \sa setScenePosition(), QTapAndHoldGesture::position()
    75     Current position of the gesture.
       
    76     \sa QTapAndHoldGesture::position()
       
    77 */
   153 */
    78 QPointF HbTapAndHoldGesture::scenePosition() const
   154 QPointF HbTapAndHoldGesture::scenePosition() const
    79 {
   155 {
    80     return priv->mScenePos;
   156     return priv->mScenePos;
    81 }
   157 }
    82 
   158 
       
   159 /*!
       
   160     Sets the current position of the gesture in scene coordinates.
       
   161     This function is used by the framework gesture recognition logic,
       
   162     and it should not be used by the widget receiving the gesture.
       
   163     \sa scenePosition(), QTapAndHoldGesture::setPosition()
       
   164 */
    83 void HbTapAndHoldGesture::setScenePosition(const QPointF& pos)
   165 void HbTapAndHoldGesture::setScenePosition(const QPointF& pos)
    84 {
   166 {
    85     priv->mScenePos = pos;
   167     priv->mScenePos = pos;
    86 }
   168 }