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

#include <qstandardgestures_p.h>

Inheritance diagram for QPanGestureRecognizer:
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...
 
 QPanGestureRecognizer ()
 
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 63 of file qstandardgestures_p.h.

Constructors and Destructors

◆ QPanGestureRecognizer()

QPanGestureRecognizer::QPanGestureRecognizer ( )

Definition at line 55 of file qstandardgestures.cpp.

56 {
57 }

Functions

◆ create()

QGesture * QPanGestureRecognizer::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 59 of file qstandardgestures.cpp.

60 {
61  if (target && target->isWidgetType()) {
62 #if defined(Q_OS_WIN) && !defined(QT_NO_NATIVE_GESTURES)
63  // for scroll areas on Windows we want to use native gestures instead
64  if (!qobject_cast<QAbstractScrollArea *>(target->parent()))
65  static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
66 #else
67  static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
68 #endif
69  }
70  return new QPanGesture;
71 }
The QPanGesture class describes a panning gesture made by the user.
Definition: qgesture.h:107
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition: qobject.h:146
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273

◆ recognize()

QGestureRecognizer::Result QPanGestureRecognizer::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 73 of file qstandardgestures.cpp.

76 {
77  QPanGesture *q = static_cast<QPanGesture *>(state);
78  QPanGesturePrivate *d = q->d_func();
79 
80  const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
81 
82  QGestureRecognizer::Result result;
83  switch (event->type()) {
84  case QEvent::TouchBegin: {
87  d->lastOffset = d->offset = QPointF();
88  break;
89  }
90  case QEvent::TouchEnd: {
91  if (q->state() != Qt::NoGesture) {
92  if (ev->touchPoints().size() == 2) {
95  d->lastOffset = d->offset;
96  d->offset =
97  QPointF(p1.pos().x() - p1.startPos().x() + p2.pos().x() - p2.startPos().x(),
98  p1.pos().y() - p1.startPos().y() + p2.pos().y() - p2.startPos().y()) / 2;
99  }
101  } else {
103  }
104  break;
105  }
106  case QEvent::TouchUpdate: {
107  if (ev->touchPoints().size() >= 2) {
108  QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);
109  QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
110  d->lastOffset = d->offset;
111  d->offset =
112  QPointF(p1.pos().x() - p1.startPos().x() + p2.pos().x() - p2.startPos().x(),
113  p1.pos().y() - p1.startPos().y() + p2.pos().y() - p2.startPos().y()) / 2;
114  if (d->offset.x() > 10 || d->offset.y() > 10 ||
115  d->offset.x() < -10 || d->offset.y() < -10) {
116  q->setHotSpot(p1.startScreenPos());
118  } else {
120  }
121  }
122  break;
123  }
125  case QEvent::MouseMove:
128  break;
129  default:
131  break;
132  }
133  return result;
134 }
double d
Definition: qnumeric_p.h:62
The QPanGesture class describes a panning gesture made by the user.
Definition: qgesture.h:107
EventRef event
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Qt::GestureState state() const
QPointF startScreenPos() const
Returns the starting screen position of this touch point.
Definition: qevent.cpp:4547
void setHotSpot(const QPointF &value)
Definition: qgesture.cpp:180
QPointF pos() const
Returns the position of this touch point, relative to the widget or QGraphicsItem that received the e...
Definition: qevent.cpp:4473
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
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
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
QPointF startPos() const
Returns the starting position of this touch point, relative to the widget or QGraphicsItem that recei...
Definition: qevent.cpp:4522

◆ reset()

void QPanGestureRecognizer::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 136 of file qstandardgestures.cpp.

137 {
138  QPanGesture *pan = static_cast<QPanGesture*>(state);
139  QPanGesturePrivate *d = pan->d_func();
140 
141  d->lastOffset = d->offset = QPointF();
142  d->acceleration = 0;
143 
145 }
double d
Definition: qnumeric_p.h:62
The QPanGesture class describes a panning gesture made by the user.
Definition: qgesture.h:107
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
virtual void reset(QGesture *state)
This function is called by the framework to reset a given gesture.

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