Qt 4.8
Public Functions | List of all members
QPinchGestureRecognizer Class Reference

#include <qstandardgestures_p.h>

Inheritance diagram for QPinchGestureRecognizer:
QGestureRecognizer

Public Functions

QGesturecreate (QObject *target)
 This function is called by Qt to create a new QGesture object for the given target (QWidget or QGraphicsObject). More...
 
 QPinchGestureRecognizer ()
 
QGestureRecognizer::Result recognize (QGesture *state, QObject *watched, QEvent *event)
 Handles the given event for the watched object, updating the state of the gesture object as required, and returns a suitable result for the current recognition step. More...
 
void reset (QGesture *state)
 This function is called by the framework to reset a given gesture. More...
 
- Public Functions inherited from QGestureRecognizer
 QGestureRecognizer ()
 Constructs a new gesture recognizer object. More...
 
virtual ~QGestureRecognizer ()
 Destroys the gesture recognizer. More...
 

Additional Inherited Members

- Public Types inherited from QGestureRecognizer
enum  ResultFlag {
  Ignore = 0x0001, MayBeGesture = 0x0002, TriggerGesture = 0x0004, FinishGesture = 0x0008,
  CancelGesture = 0x0010, ResultState_Mask = 0x00ff, ConsumeEventHint = 0x0100, ResultHint_Mask = 0xff00
}
 This enum describes the result of the current event filtering step in a gesture recognizer state machine. More...
 
- Static Public Functions inherited from QGestureRecognizer
static Qt::GestureType registerRecognizer (QGestureRecognizer *recognizer)
 Registers the given recognizer in the gesture framework and returns a gesture ID for it. More...
 
static void unregisterRecognizer (Qt::GestureType type)
 Unregisters all gesture recognizers of the specified type. More...
 

Detailed Description

Definition at line 73 of file qstandardgestures_p.h.

Constructors and Destructors

◆ QPinchGestureRecognizer()

QPinchGestureRecognizer::QPinchGestureRecognizer ( )

Definition at line 152 of file qstandardgestures.cpp.

153 {
154 }

Functions

◆ create()

QGesture * QPinchGestureRecognizer::create ( QObject target)
virtual

This function is called by Qt to create a new QGesture object for the given target (QWidget or QGraphicsObject).

Reimplement this function to create a custom QGesture-derived gesture object if necessary.

The application takes ownership of the created gesture object.

Reimplemented from QGestureRecognizer.

Definition at line 156 of file qstandardgestures.cpp.

157 {
158  if (target && target->isWidgetType()) {
159  static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
160  }
161  return new QPinchGesture;
162 }
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QPinchGesture class describes a pinch gesture made by the user.
Definition: qgesture.h:136
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition: qobject.h:146

◆ recognize()

QGestureRecognizer::Result QPinchGestureRecognizer::recognize ( QGesture gesture,
QObject watched,
QEvent event 
)
virtual

Handles the given event for the watched object, updating the state of the gesture object as required, and returns a suitable result for the current recognition step.

This function is called by the framework to allow the recognizer to filter input events dispatched to QWidget or QGraphicsObject instances that it is monitoring.

The result reflects how much of the gesture has been recognized. The state of the gesture object is set depending on the result.

See also
QGestureRecognizer::Result

Implements QGestureRecognizer.

Definition at line 164 of file qstandardgestures.cpp.

167 {
168  QPinchGesture *q = static_cast<QPinchGesture *>(state);
169  QPinchGesturePrivate *d = q->d_func();
170 
171  const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
172 
173  QGestureRecognizer::Result result;
174 
175  switch (event->type()) {
176  case QEvent::TouchBegin: {
178  break;
179  }
180  case QEvent::TouchEnd: {
181  if (q->state() != Qt::NoGesture) {
183  } else {
185  }
186  break;
187  }
188  case QEvent::TouchUpdate: {
189  d->changeFlags = 0;
190  if (ev->touchPoints().size() == 2) {
191  QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);
192  QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
193 
194  d->hotSpot = p1.screenPos();
195  d->isHotSpotSet = true;
196 
197  QPointF centerPoint = (p1.screenPos() + p2.screenPos()) / 2.0;
198  if (d->isNewSequence) {
199  d->startPosition[0] = p1.screenPos();
200  d->startPosition[1] = p2.screenPos();
201  d->lastCenterPoint = centerPoint;
202  } else {
204  }
205  d->centerPoint = centerPoint;
206 
208 
209  if (d->isNewSequence) {
210  d->scaleFactor = 1.0;
211  d->lastScaleFactor = 1.0;
212  } else {
214  QLineF line(p1.screenPos(), p2.screenPos());
215  QLineF lastLine(p1.lastScreenPos(), p2.lastScreenPos());
216  d->scaleFactor = line.length() / lastLine.length();
217  }
220 
221  qreal angle = QLineF(p1.screenPos(), p2.screenPos()).angle();
222  if (angle > 180)
223  angle -= 360;
224  qreal startAngle = QLineF(p1.startScreenPos(), p2.startScreenPos()).angle();
225  if (startAngle > 180)
226  startAngle -= 360;
227  const qreal rotationAngle = startAngle - angle;
228  if (d->isNewSequence)
229  d->lastRotationAngle = 0.0;
230  else
232  d->rotationAngle = rotationAngle;
235 
236  d->totalChangeFlags |= d->changeFlags;
237  d->isNewSequence = false;
239  } else {
240  d->isNewSequence = true;
241  if (q->state() == Qt::NoGesture)
243  else
245  }
246  break;
247  }
249  case QEvent::MouseMove:
252  break;
253  default:
255  break;
256  }
257  return result;
258 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
QPinchGesture::ChangeFlags changeFlags
Definition: qgesture_p.h:122
EventRef event
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPointF lastScreenPos() const
Returns the screen position of this touch point from the previous touch event.
Definition: qevent.cpp:4598
QPointF hotSpot
Definition: qgesture_p.h:79
QPointF startPosition[2]
Definition: qgesture_p.h:137
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Qt::GestureState state() const
The QPinchGesture class describes a pinch gesture made by the user.
Definition: qgesture.h:136
QPointF screenPos() const
Returns the screen position of this touch point.
Definition: qevent.cpp:4498
QPointF startScreenPos() const
Returns the starting screen position of this touch point.
Definition: qevent.cpp:4547
qreal angle(const QPointF &p1, const QPointF &p2)
const QList< QTouchEvent::TouchPoint > & touchPoints() const
Returns the list of touch points contained in the touch event.
Definition: qevent.h:820
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QPinchGesture::ChangeFlags totalChangeFlags
Definition: qgesture_p.h:121
The TouchPoint class provides information about a touch point in a QTouchEvent.
Definition: qevent.h:744
The QTouchEvent class contains parameters that describe a touch event.
Definition: qevent.h:741
Type type() const
Returns the event type.
Definition: qcoreevent.h:303

◆ reset()

void QPinchGestureRecognizer::reset ( QGesture gesture)
virtual

This function is called by the framework to reset a given gesture.

Reimplement this function to implement additional requirements for custom QGesture objects. This may be necessary if you implement a custom QGesture whose properties need special handling when the gesture is reset.

Reimplemented from QGestureRecognizer.

Definition at line 260 of file qstandardgestures.cpp.

261 {
262  QPinchGesture *pinch = static_cast<QPinchGesture *>(state);
263  QPinchGesturePrivate *d = pinch->d_func();
264 
265  d->totalChangeFlags = d->changeFlags = 0;
266 
270 
271  d->isNewSequence = true;
272  d->startPosition[0] = d->startPosition[1] = QPointF();
273 
275 }
double d
Definition: qnumeric_p.h:62
QPinchGesture::ChangeFlags changeFlags
Definition: qgesture_p.h:122
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPointF startPosition[2]
Definition: qgesture_p.h:137
virtual void reset(QGesture *state)
This function is called by the framework to reset a given gesture.
The QPinchGesture class describes a pinch gesture made by the user.
Definition: qgesture.h:136
QPointF startCenterPoint
Definition: qgesture_p.h:124
QPinchGesture::ChangeFlags totalChangeFlags
Definition: qgesture_p.h:121

The documentation for this class was generated from the following files: