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

#include <qstandardgestures_p.h>

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

Constructors and Destructors

◆ QTapAndHoldGestureRecognizer()

QTapAndHoldGestureRecognizer::QTapAndHoldGestureRecognizer ( )

Definition at line 490 of file qstandardgestures.cpp.

491 {
492 }

Functions

◆ create()

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

495 {
496  if (target && target->isWidgetType()) {
497  static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
498  }
499  return new QTapAndHoldGesture;
500 }
The QTapAndHoldGesture class describes a tap-and-hold (aka LongTap) gesture made by the user...
Definition: qgesture.h:249
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

◆ recognize()

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

505 {
506  QTapAndHoldGesture *q = static_cast<QTapAndHoldGesture *>(state);
507  QTapAndHoldGesturePrivate *d = q->d_func();
508 
509  if (object == state && event->type() == QEvent::Timer) {
510  q->killTimer(d->timerId);
511  d->timerId = 0;
513  }
514 
515  const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
516  const QMouseEvent *me = static_cast<const QMouseEvent *>(event);
517 #ifndef QT_NO_GRAPHICSVIEW
518  const QGraphicsSceneMouseEvent *gsme = static_cast<const QGraphicsSceneMouseEvent *>(event);
519 #endif
520 
521  enum { TapRadius = 40 };
522 
523  switch (event->type()) {
524 #ifndef QT_NO_GRAPHICSVIEW
526  d->position = gsme->screenPos();
527  q->setHotSpot(d->position);
528  if (d->timerId)
529  q->killTimer(d->timerId);
531  return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout
532 #endif
534  d->position = me->globalPos();
535  q->setHotSpot(d->position);
536  if (d->timerId)
537  q->killTimer(d->timerId);
539  return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout
540  case QEvent::TouchBegin:
541  d->position = ev->touchPoints().at(0).startScreenPos();
542  q->setHotSpot(d->position);
543  if (d->timerId)
544  q->killTimer(d->timerId);
546  return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout
547 #ifndef QT_NO_GRAPHICSVIEW
549 #endif
551  case QEvent::TouchEnd:
552  return QGestureRecognizer::CancelGesture; // get out of the MayBeGesture state
553  case QEvent::TouchUpdate:
554  if (d->timerId && ev->touchPoints().size() == 1) {
556  QPoint delta = p.pos().toPoint() - p.startPos().toPoint();
557  if (delta.manhattanLength() <= TapRadius)
559  }
561  case QEvent::MouseMove: {
562  QPoint delta = me->globalPos() - d->position.toPoint();
563  if (d->timerId && delta.manhattanLength() <= TapRadius)
566  }
567 #ifndef QT_NO_GRAPHICSVIEW
569  QPoint delta = gsme->screenPos() - d->position.toPoint();
570  if (d->timerId && delta.manhattanLength() <= TapRadius)
573  }
574 #endif
575  default:
577  }
578 }
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
double d
Definition: qnumeric_p.h:62
QPoint screenPos() const
Returns the mouse cursor position in screen coordinates.
EventRef event
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
The QTapAndHoldGesture class describes a tap-and-hold (aka LongTap) gesture made by the user...
Definition: qgesture.h:249
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
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 startScreenPos() const
Returns the starting screen position of this touch point.
Definition: qevent.cpp:4547
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
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
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
const QPoint & globalPos() const
Returns the global position of the mouse cursor at the time of the event.
Definition: qevent.h:96
QPointF startPos() const
Returns the starting position of this touch point, relative to the widget or QGraphicsItem that recei...
Definition: qevent.cpp:4522
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650

◆ reset()

void QTapAndHoldGestureRecognizer::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 580 of file qstandardgestures.cpp.

581 {
582  QTapAndHoldGesture *q = static_cast<QTapAndHoldGesture *>(state);
583  QTapAndHoldGesturePrivate *d = q->d_func();
584 
585  d->position = QPointF();
586  if (d->timerId)
587  q->killTimer(d->timerId);
588  d->timerId = 0;
589 
591 }
double d
Definition: qnumeric_p.h:62
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QTapAndHoldGesture class describes a tap-and-hold (aka LongTap) gesture made by the user...
Definition: qgesture.h:249
virtual void reset(QGesture *state)
This function is called by the framework to reset a given gesture.
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650

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