Home · All Classes · Overviews

QGesture Class Reference
[QtGui module]

The QGesture class is the base class for implementing custom gestures. More...

 #include <QGesture>

Inherits QObject.

Inherited by QPanGesture, QPinchGesture, and QSwipeGesture.

This class was introduced in Qt 4.6.


Properties


Public Functions

QGesture ( QObject * gestureTarget = 0, QObject * parent = 0 )
~QGesture ()
virtual bool filterEvent ( QEvent * event ) = 0
QObject * gestureTarget () const
QGraphicsItem * graphicsItem () const
void setGestureTarget ( QObject * object )
void setGraphicsItem ( QGraphicsItem * graphicsItem )
Qt::GestureState state () const

Signals

void cancelled ()
void finished ()
void started ()
void triggered ()

Protected Functions

virtual void reset ()
void updateState ( Qt::GestureState state )

Additional Inherited Members


Detailed Description

The QGesture class is the base class for implementing custom gestures.

This class represents both an object that recognizes a gesture out of a set of input events (a gesture recognizer), and a gesture object itself that can be used to get extended information about the triggered gesture.

The class has a list of properties that can be queried by the user to get some gesture-specific parameters (for example, an offset of a Pan gesture).

Usually gesture recognizer implements a state machine, storing its state internally in the recognizer object. The recognizer receives input events through the filterEvent() virtual function and decides whether the event should change the state of the recognizer by emitting an appropriate signal.

Input events should be either fed to the recognizer one by one with a filterEvent() function, or the gesture recognizer should be attached to an object it filters events for by specifying it as a parent object. The QGesture object installs itself as an event filter to the parent object automatically, the unsetObject() function should be used to remove an event filter from the parent object. To make a gesture that operates on a QGraphicsItem, both the appropriate QGraphicsView should be passed as a parent object and setGraphicsItem() functions should be used to attach a gesture to a graphics item.

This is a base class, to create a custom gesture type, you should subclass it and implement its pure virtual functions.

See also QPanGesture.


Property Documentation

gestureTarget : QObject *

Gesture target is the object that the gesture will watch for events. Typically this means that the gesture installs an event filter on the target object.

Access functions:

QObject * gestureTarget () const
void setGestureTarget ( QObject * object )

state : const Qt::GestureState

This property holds the current state of the gesture.

Access functions:

Qt::GestureState state () const

Member Function Documentation

QGesture::QGesture ( QObject * gestureTarget = 0, QObject * parent = 0 )

Creates a new gesture handler object and marks it as a child of parent. gestureTarget is the object that the gesture will watch for events.

The parent object is also the default event source for the gesture, meaning that the gesture installs itself as an event filter for the parent.

See also setGraphicsItem().

QGesture::~QGesture ()

Destroys the gesture object.

void QGesture::cancelled ()   [signal]

The signal is emitted when the gesture is cancelled, for example the reset() function is called while the gesture was in the process of emitting a triggered() signal. Extended information about the gesture is contained in the sender object.

bool QGesture::filterEvent ( QEvent * event )   [pure virtual]

Parses input event and emits a signal when detects a gesture.

In your reimplementation of this function, if you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false;

This is a pure virtual function that needs to be implemented in subclasses.

void QGesture::finished ()   [signal]

The signal is emitted when the gesture is finished. Extended information about the gesture is contained in the signal sender object.

QGraphicsItem * QGesture::graphicsItem () const

Returns the graphics item the gesture is filtering events for.

See also setGraphicsItem().

void QGesture::reset ()   [virtual protected]

Resets the internal state of the gesture. This function might be called by the filterEvent() implementation in a derived class, or by the user to cancel a gesture. The base class implementation calls updateState(Qt::NoGesture) which emits the cancelled() signal if the state() of the gesture indicated it was active.

void QGesture::setGraphicsItem ( QGraphicsItem * graphicsItem )

Sets the graphicsItem the gesture is filtering events for.

The gesture will install an event filter to the graphicsItem and redirect them to the filterEvent() function.

See also graphicsItem().

void QGesture::started ()   [signal]

The signal is emitted when the gesture is started. Extended information about the gesture is contained in the signal sender object.

In addition to started(), a triggered() signal should also be emitted.

void QGesture::triggered ()   [signal]

The signal is emitted when the gesture is detected. Extended information about the gesture is contained in the signal sender object.

void QGesture::updateState ( Qt::GestureState state )   [protected]

Sets this gesture's recognition state to state and emits appropriate signals.

This functions emits the signals according to the old state and the new state, and it should be called after all the internal properties have been initialized.

See also started(), triggered(), finished(), and cancelled().


Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt 4.6.0-tp1