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

#include <qstandardgestures_p.h>

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

Constructors and Destructors

◆ QTapGestureRecognizer()

QTapGestureRecognizer::QTapGestureRecognizer ( )

Definition at line 419 of file qstandardgestures.cpp.

420 {
421 }

Functions

◆ create()

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

424 {
425  if (target && target->isWidgetType()) {
426  static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
427  }
428  return new QTapGesture;
429 }
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
The QTapGesture class describes a tap gesture made by the user.
Definition: qgesture.h:232

◆ recognize()

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

434 {
435  QTapGesture *q = static_cast<QTapGesture *>(state);
436  QTapGesturePrivate *d = q->d_func();
437 
438  const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
439 
440  QGestureRecognizer::Result result = QGestureRecognizer::CancelGesture;
441 
442  switch (event->type()) {
443  case QEvent::TouchBegin: {
444  d->position = ev->touchPoints().at(0).pos();
445  q->setHotSpot(ev->touchPoints().at(0).screenPos());
447  break;
448  }
449  case QEvent::TouchUpdate:
450  case QEvent::TouchEnd: {
451  if (q->state() != Qt::NoGesture && ev->touchPoints().size() == 1) {
453  QPoint delta = p.pos().toPoint() - p.startPos().toPoint();
454  enum { TapRadius = 40 };
455  if (delta.manhattanLength() <= TapRadius) {
456  if (event->type() == QEvent::TouchEnd)
458  else
460  }
461  }
462  break;
463  }
465  case QEvent::MouseMove:
468  break;
469  default:
471  break;
472  }
473  return result;
474 }
double d
Definition: qnumeric_p.h:62
EventRef event
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Qt::GestureState state() const
int manhattanLength() const
Returns the sum of the absolute values of x() and y(), traditionally known as the "Manhattan length" ...
Definition: qpoint.cpp:489
QPointF screenPos() const
Returns the screen position of this touch point.
Definition: qevent.cpp:4498
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376
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
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
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
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
The QTapGesture class describes a tap gesture made by the user.
Definition: qgesture.h:232
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 QTapGestureRecognizer::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 476 of file qstandardgestures.cpp.

477 {
478  QTapGesture *q = static_cast<QTapGesture *>(state);
479  QTapGesturePrivate *d = q->d_func();
480 
481  d->position = QPointF();
482 
484 }
double d
Definition: qnumeric_p.h:62
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 QTapGesture class describes a tap gesture made by the user.
Definition: qgesture.h:232

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