src/hbcore/gestures/hbpinchgesture.cpp
changeset 6 c3690ec91ef8
parent 2 06ff229162e9
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
    29 
    29 
    30 /*!
    30 /*!
    31     @hbcore
    31     @hbcore
    32     \class HbPinchGesture
    32     \class HbPinchGesture
    33 
    33 
    34     \brief HbPinchGesture is an extension to Qt standard QPinchGesture
    34     \brief The HbPinchGesture class provides multitouch support.
       
    35     
       
    36     HbPinchGesture is an extension to Qt standard QPinchGesture. It offers
       
    37     convenience functions for handling the pinch gesture properties directly
       
    38     in scene coordinates. This removes any need for manual conversions from
       
    39     the screen (global) coordinates of the QPinchGesture base class
       
    40     properties.
       
    41     
       
    42     You can use HbPinchGesture, for example, to let the user change an
       
    43     image size in a photo application by dragging the two opposing corners
       
    44     of the image at the same time. Another example would be rotating a widget
       
    45     with two fingers.
       
    46     
       
    47     \section _usecases_hbpinchgesture Using the HbPinchGesture class
       
    48     
       
    49     This example shows how to make a custom widget recognize the pinch
       
    50     gesture. The custom widget in the example derives from HbWidget.
       
    51     
       
    52     <ol>
       
    53     <li>
       
    54     In order to receive touch events, which are required by the pinch gesture,
       
    55     at least one widget in the scene needs to accept the QEvent::TouchBegin event.
       
    56     To make sure this is done, you can do this in your widget by reimplementing
       
    57     QGraphicsWidget::event().
       
    58     
       
    59     \code
       
    60     bool MyWidget::event(QEvent *e)
       
    61     {
       
    62         if (e->type() == QEvent::TouchBegin) {
       
    63             return true;
       
    64         }
       
    65         return HbWidget::event(e);
       
    66     }    
       
    67     \endcode 
       
    68     </li>
       
    69     
       
    70     <li>
       
    71     Register for pinch gestures by using the base class function
       
    72     QGraphicsObject::grabGesture(). QGraphicsObject::grabGesture() can be
       
    73     called several times with different arguments, if the widget is
       
    74     interested in other gesture types as well.
       
    75    
       
    76     \code
       
    77     // This widget is interested in pinch and tap gestures.
       
    78     grabGesture(Qt::PinchGesture);
       
    79     grabGesture(Qt::TapGesture);
       
    80     \endcode
       
    81     </li>
       
    82     
       
    83     <li>
       
    84     Reimplement HbWidgetBase::gestureEvent() to handle gestures that are
       
    85     meaningful for your custom widget.
       
    86    
       
    87     \code
       
    88     void MyWidget::gestureEvent(QGestureEvent *event)
       
    89     {
       
    90         if (HbPinchGesture *pinch = qobject_cast<HbPinchGesture *>
       
    91             (event->gesture(Qt::PinchGesture))) {
       
    92        
       
    93             switch (pinch->state()) {
       
    94            
       
    95             case Qt::GestureStarted:
       
    96                 // Visualize the active state of the widget.
       
    97                 // Emit a signal to move the content.
       
    98                 break;
       
    99             case Qt::GestureUpdated:
       
   100                 // Emit a signal to move the content.
       
   101                 break;
       
   102             case Qt::GestureCanceled:
       
   103                 // Visualize the non-active state of the widget.
       
   104                 // Emit a signal to return the content to the starting
       
   105                 // position.
       
   106                 break;
       
   107             case Qt::GestureFinished:              
       
   108                 // Visualize the non-active state of the widget.              
       
   109                 // Emit a signal to move the content.             
       
   110                 break;
       
   111             default:
       
   112                 break;
       
   113             }           
       
   114         }
       
   115        
       
   116         // Handle other gesture types that have been grabbed. There may be several,
       
   117         // since all gestures that are active at the same moment are sent within
       
   118         // the same gesture event.
       
   119         if (HbTapGesture *tap = qobject_cast<HbTapGesture *>
       
   120             (event->gesture(Qt::TapGesture))) {
       
   121             // handle the tap gesture
       
   122         }
       
   123        
       
   124     }   
       
   125     \endcode
       
   126     </li>
       
   127     </ol>
       
   128     
    35     \sa QPinchGesture
   129     \sa QPinchGesture
    36 */
   130 */
    37 
   131 
    38 /*!
   132 /*!
    39     \brief HbPinchGesture constructor
   133     Constructor.
    40     \param parent Owner for gesture
   134     \param parent Owner for gesture
    41 */
   135 */
    42 HbPinchGesture::HbPinchGesture(QObject *parent)
   136 HbPinchGesture::HbPinchGesture(QObject *parent)
    43     : QPinchGesture(parent), d_ptr(new HbPinchGesturePrivate)
   137     : QPinchGesture(parent), d_ptr(new HbPinchGesturePrivate)
    44 
   138 
    48     setLastScaleFactor(1);
   142     setLastScaleFactor(1);
    49     setScaleFactor(1);
   143     setScaleFactor(1);
    50 }
   144 }
    51 
   145 
    52 /*!
   146 /*!
    53     \brief HbPinchGesture constructor
   147     Constructor required by the shared d-pointer paradigm.
    54     \param dd Private data
   148     \param dd Private data
    55     \param parent Owner for gesture
   149     \param parent Owner for gesture
    56 */
   150 */
    57 HbPinchGesture::HbPinchGesture(HbPinchGesturePrivate &dd, QObject *parent)
   151 HbPinchGesture::HbPinchGesture(HbPinchGesturePrivate &dd, QObject *parent)
    58     : QPinchGesture(parent), d_ptr(&dd)
   152     : QPinchGesture(parent), d_ptr(&dd)
    62     setLastScaleFactor(1);
   156     setLastScaleFactor(1);
    63     setScaleFactor(1);
   157     setScaleFactor(1);
    64 }
   158 }
    65 
   159 
    66 /*!
   160 /*!
    67     \brief HbPinchGesture destructor
   161     Destructor.
    68 */
   162 */
    69 HbPinchGesture::~HbPinchGesture()
   163 HbPinchGesture::~HbPinchGesture()
    70 {
   164 {
    71     delete d_ptr;
   165     delete d_ptr;
    72 }
   166 }
    73 
   167 
    74 /*!
   168 /*!
    75     \property sceneTotalRotationAngle
   169     Returns the total angle covered by the gesture in scene coordinates.
    76     \brief The total angle covered by the gesture in scene coordinates.
   170     \sa setSceneTotalRotationAngle(), QPinchGesture::totalRotationAngle()
    77     \sa QPinchGesture::totalRotationAngle()
       
    78 */
   171 */
    79 qreal HbPinchGesture::sceneTotalRotationAngle() const
   172 qreal HbPinchGesture::sceneTotalRotationAngle() const
    80 {
   173 {
    81     Q_D(const HbPinchGesture);
   174     Q_D(const HbPinchGesture);
    82     return d->mSceneTotalRotationAngle;
   175     return d->mSceneTotalRotationAngle;
    83 }
   176 }
    84 
   177 
       
   178 /*!
       
   179     Sets the total angle covered by the gesture in scene coordinates.
       
   180     This function is used by the framework gesture recognition logic,
       
   181     and it should not be used by the widget receiving the gesture.
       
   182     \sa sceneTotalRotationAngle(), QPinchGesture::setTotalRotationAngle()
       
   183 */
    85 void HbPinchGesture::setSceneTotalRotationAngle(qreal value)
   184 void HbPinchGesture::setSceneTotalRotationAngle(qreal value)
    86 {
   185 {
    87     Q_D(HbPinchGesture);
   186     Q_D(HbPinchGesture);
    88     d->mSceneTotalRotationAngle = value;
   187     d->mSceneTotalRotationAngle = value;
    89 }
   188 }
    90 
   189 
    91 /*!
   190 /*!
    92     \property sceneLastRotationAngle
   191     Returns the last reported angle covered by the gesture in scene
    93     \brief The last reported angle covered by the gesture motion in scene coordinates.
   192     coordinates.
    94     \sa QPinchGesture::lastRotationAngle()
   193     \sa setSceneLastRotationAngle(), QPinchGesture::lastRotationAngle()
    95 */
   194 */
    96 qreal HbPinchGesture::sceneLastRotationAngle() const
   195 qreal HbPinchGesture::sceneLastRotationAngle() const
    97 {
   196 {
    98     Q_D(const HbPinchGesture);
   197     Q_D(const HbPinchGesture);
    99     return d->mSceneLastRotationAngle;
   198     return d->mSceneLastRotationAngle;
   100 }
   199 }
   101 
   200 
       
   201 /*!
       
   202     Sets the last reported angle covered by the gesture in scene coordinates.
       
   203     This function is used by the framework gesture recognition logic,
       
   204     and it should not be used by the widget receiving the gesture.
       
   205     \sa sceneLastRotationAngle(), QPinchGesture::setLastRotationAngle()
       
   206 */
   102 void HbPinchGesture::setSceneLastRotationAngle(qreal value)
   207 void HbPinchGesture::setSceneLastRotationAngle(qreal value)
   103 {
   208 {
   104     Q_D(HbPinchGesture);
   209     Q_D(HbPinchGesture);
   105     d->mSceneLastRotationAngle = value;
   210     d->mSceneLastRotationAngle = value;
   106 }
   211 }
   107 
   212 
   108 /*!
   213 /*!
   109     \property sceneRotationAngle
   214     Returns the angle covered by the gesture since last update
   110     \brief The angle covered by the gesture motion in scene coordinates.
   215     in scene coordinates.
   111     \sa QPinchGesture::rotationAngle()
   216     \sa setSceneRotationAngle(), QPinchGesture::rotationAngle()
   112 */
   217 */
   113 qreal HbPinchGesture::sceneRotationAngle() const
   218 qreal HbPinchGesture::sceneRotationAngle() const
   114 {
   219 {
   115     Q_D(const HbPinchGesture);
   220     Q_D(const HbPinchGesture);
   116     return d->mSceneRotationAngle;
   221     return d->mSceneRotationAngle;
   117 }
   222 }
   118 
   223 
       
   224 /*!
       
   225     Sets the angle covered by the gesture since last update
       
   226     in scene coordinates.
       
   227     This function is used by the framework gesture recognition logic,
       
   228     and it should not be used by the widget receiving the gesture.
       
   229     \sa sceneRotationAngle(), QPinchGesture::setRotationAngle()
       
   230 */
   119 void HbPinchGesture::setSceneRotationAngle(qreal value)
   231 void HbPinchGesture::setSceneRotationAngle(qreal value)
   120 {
   232 {
   121     Q_D(HbPinchGesture);
   233     Q_D(HbPinchGesture);
   122     d->mSceneRotationAngle = value;
   234     d->mSceneRotationAngle = value;
   123 }
   235 }
   124 
   236 
   125 /*!
   237 /*!
   126     \property sceneStartCenterPoint
   238     Returns the starting position of the center point in scene coordinates.
   127     \brief The starting position of the center point in scene coordinates.
   239     \sa setSceneStartCenterPoint(), QPinchGesture::startCenterPoint()
   128     \sa QPinchGesture::startCenterPoint()
       
   129 */
   240 */
   130 QPointF HbPinchGesture::sceneStartCenterPoint() const
   241 QPointF HbPinchGesture::sceneStartCenterPoint() const
   131 {
   242 {
   132     Q_D(const HbPinchGesture);
   243     Q_D(const HbPinchGesture);
   133     return d->mSceneStartCenterPoint;
   244     return d->mSceneStartCenterPoint;
   134 }
   245 }
   135 
   246 
       
   247 /*!
       
   248     Sets the starting position of the center point in scene coordinates.
       
   249     This function is used by the framework gesture recognition logic,
       
   250     and it should not be used by the widget receiving the gesture.
       
   251     \sa sceneStartCenterPoint(), QPinchGesture::setStartCenterPoint()
       
   252 */
   136 void HbPinchGesture::setSceneStartCenterPoint(const QPointF &value)
   253 void HbPinchGesture::setSceneStartCenterPoint(const QPointF &value)
   137 {
   254 {
   138     Q_D(HbPinchGesture);
   255     Q_D(HbPinchGesture);
   139     d->mSceneStartCenterPoint = value;
   256     d->mSceneStartCenterPoint = value;
   140 }
   257 }
   141 
   258 
   142 /*!
   259 /*!
   143     \property sceneLastCenterPoint
   260     Returns the last position of the center point recorded for the gesture
   144     \brief The last position of the center point recorded for this gesture in scene coordinates.
   261     in scene coordinates.
   145     \sa QPinchGesture::lastCenterPoint()
   262     \sa setSceneLastCenterPoint(), QPinchGesture::lastCenterPoint()
   146 */
   263 */
   147 QPointF HbPinchGesture::sceneLastCenterPoint() const
   264 QPointF HbPinchGesture::sceneLastCenterPoint() const
   148 {
   265 {
   149     Q_D(const HbPinchGesture);
   266     Q_D(const HbPinchGesture);
   150     return d->mSceneLastCenterPoint;
   267     return d->mSceneLastCenterPoint;
   151 }
   268 }
   152 
   269 
       
   270 /*!
       
   271     Sets the last position of the center point recorded for the gesture
       
   272     in scene coordinates.
       
   273     This function is used by the framework gesture recognition logic,
       
   274     and it should not be used by the widget receiving the gesture.
       
   275     \sa sceneLastCenterPoint(), QPinchGesture::setLastCenterPoint()
       
   276 */
   153 void HbPinchGesture::setSceneLastCenterPoint(const QPointF &value)
   277 void HbPinchGesture::setSceneLastCenterPoint(const QPointF &value)
   154 {
   278 {
   155     Q_D(HbPinchGesture);
   279     Q_D(HbPinchGesture);
   156     d->mSceneLastCenterPoint = value;
   280     d->mSceneLastCenterPoint = value;
   157 }
   281 }
   158 
   282 
   159 /*!
   283 /*!
   160     \property sceneCenterPoint
   284     Returns the current center point in scene coordinates.
   161     \brief The current center point in scene coordinates.
   285     \sa setSceneCenterPoint(), QPinchGesture::centerPoint()
   162     \sa QPinchGesture::centerPoint()
       
   163 */
   286 */
   164 QPointF HbPinchGesture::sceneCenterPoint() const
   287 QPointF HbPinchGesture::sceneCenterPoint() const
   165 {
   288 {
   166     Q_D(const HbPinchGesture);
   289     Q_D(const HbPinchGesture);
   167     return d->mSceneCenterPoint;
   290     return d->mSceneCenterPoint;
   168 }
   291 }
   169 
   292 
       
   293 /*!
       
   294     Sets the current center point in scene coordinates.
       
   295     This function is used by the framework gesture recognition logic,
       
   296     and it should not be used by the widget receiving the gesture.
       
   297     \sa sceneCenterPoint(), QPinchGesture::setCenterPoint()
       
   298 */
   170 void HbPinchGesture::setSceneCenterPoint(const QPointF &value)
   299 void HbPinchGesture::setSceneCenterPoint(const QPointF &value)
   171 {
   300 {
   172     Q_D(HbPinchGesture);
   301     Q_D(HbPinchGesture);
   173     d->mSceneCenterPoint = value;
   302     d->mSceneCenterPoint = value;
   174 }
   303 }