summaryrefslogtreecommitdiffstats
path: root/examples/gestures/collidingmice
diff options
context:
space:
mode:
Diffstat (limited to 'examples/gestures/collidingmice')
-rw-r--r--examples/gestures/collidingmice/gesturerecognizerlinjazax.cpp114
-rw-r--r--examples/gestures/collidingmice/gesturerecognizerlinjazax.h4
-rw-r--r--examples/gestures/collidingmice/linjazaxgesture.h17
-rw-r--r--examples/gestures/collidingmice/main.cpp4
4 files changed, 63 insertions, 76 deletions
diff --git a/examples/gestures/collidingmice/gesturerecognizerlinjazax.cpp b/examples/gestures/collidingmice/gesturerecognizerlinjazax.cpp
index 3f90588..41bb113 100644
--- a/examples/gestures/collidingmice/gesturerecognizerlinjazax.cpp
+++ b/examples/gestures/collidingmice/gesturerecognizerlinjazax.cpp
@@ -60,83 +60,67 @@ void DirectionSimpleRecognizer::reset()
///////////////////////////////////////////////////////////////////////////
GestureRecognizerLinjaZax::GestureRecognizerLinjaZax()
- : QGestureRecognizer("LinjaZax"), mousePressed(false), gestureFinished(false),
+ : QGestureRecognizer(QLatin1String("LinjaZax")), mousePressed(false), gestureFinished(false),
zoomState(LinjaZaxGesture::NoZoom)
{
}
-QGestureRecognizer::Result GestureRecognizerLinjaZax::recognize(const QList<QEvent*> &inputEvents)
+QGestureRecognizer::Result GestureRecognizerLinjaZax::filterEvent(const QEvent *event)
{
- // get all mouse events
- QList<QMouseEvent*> events;
- for(int i = 0; i < inputEvents.count(); ++i) {
- QEvent *event = inputEvents.at(i);
- switch (event->type()) {
- case QEvent::MouseButtonPress:
- case QEvent::MouseButtonRelease:
- case QEvent::MouseMove:
- events.push_back(static_cast<QMouseEvent*>(event));
- default:
- break;
- }
- }
-
if (zoomState != LinjaZaxGesture::NoZoom && !lastDirections.isEmpty()) {
lastDirections = lastDirections.right(1);
zoomState = LinjaZaxGesture::NoZoom;
}
- QGestureRecognizer::Result result = QGestureRecognizer::NotGesture;
- for(int i = 0; i < events.count(); ++i) {
- QMouseEvent *event = events.at(i);
- if (event->type() == QEvent::MouseButtonPress) {
- if (!currentDirection.isEmpty()) {
- result = QGestureRecognizer::NotGesture;
- reset();
- break;
- }
- result = QGestureRecognizer::MaybeGesture;
- mousePressed = true;
- pressedPos = lastPos = currentPos = event->pos();
- } else if (event->type() == QEvent::MouseButtonRelease) {
- if (mousePressed && !currentDirection.isEmpty()) {
- result = QGestureRecognizer::GestureFinished;
- gestureFinished = true;
- currentPos = event->pos();
- internalReset();
- break;
- }
- result = QGestureRecognizer::NotGesture;
+ if (event->type() == QEvent::MouseButtonPress) {
+ if (!currentDirection.isEmpty()) {
reset();
- break;
- } else if (event->type() == QEvent::MouseMove) {
- if (!mousePressed)
- continue;
- lastPos = currentPos;
- currentPos = event->pos();
- QString direction =
- simpleRecognizer.addPosition(event->pos()).direction;
- if (currentDirection.isEmpty()) {
- if (direction.isEmpty())
- result = QGestureRecognizer::MaybeGesture;
- else
- result = QGestureRecognizer::GestureStarted;
- } else {
+ return QGestureRecognizer::NotGesture;
+ }
+ mousePressed = true;
+ const QMouseEvent *ev = static_cast<const QMouseEvent*>(event);
+ pressedPos = lastPos = currentPos = ev->pos();
+ return QGestureRecognizer::MaybeGesture;
+ } else if (event->type() == QEvent::MouseButtonRelease) {
+ const QMouseEvent *ev = static_cast<const QMouseEvent*>(event);
+ if (mousePressed && !currentDirection.isEmpty()) {
+ gestureFinished = true;
+ currentPos = ev->pos();
+ internalReset();
+ return QGestureRecognizer::GestureFinished;
+ }
+ reset();
+ return QGestureRecognizer::NotGesture;
+ } else if (event->type() == QEvent::MouseMove) {
+ if (!mousePressed)
+ return QGestureRecognizer::NotGesture;
+ lastPos = currentPos;
+ const QMouseEvent *ev = static_cast<const QMouseEvent*>(event);
+ currentPos = ev->pos();
+ QString direction =
+ simpleRecognizer.addPosition(ev->pos()).direction;
+ QGestureRecognizer::Result result = QGestureRecognizer::NotGesture;
+ if (currentDirection.isEmpty()) {
+ if (direction.isEmpty())
+ result = QGestureRecognizer::MaybeGesture;
+ else
result = QGestureRecognizer::GestureStarted;
- }
- if (!direction.isEmpty()) {
- lastDirections.append(direction);
- currentDirection = direction;
- if (lastDirections.length() > 5)
- lastDirections.remove(0, 1);
- if (lastDirections.contains("248") || lastDirections.contains("2448"))
- zoomState = LinjaZaxGesture::ZoomingIn;
- else if (lastDirections.contains("268") || lastDirections.contains("2668"))
- zoomState = LinjaZaxGesture::ZoomingOut;
- }
+ } else {
+ result = QGestureRecognizer::GestureStarted;
+ }
+ if (!direction.isEmpty()) {
+ lastDirections.append(direction);
+ currentDirection = direction;
+ if (lastDirections.length() > 5)
+ lastDirections.remove(0, 1);
+ if (lastDirections.contains("248") || lastDirections.contains("2448"))
+ zoomState = LinjaZaxGesture::ZoomingIn;
+ else if (lastDirections.contains("268") || lastDirections.contains("2668"))
+ zoomState = LinjaZaxGesture::ZoomingOut;
}
+ return result;
}
- return result;
+ return QGestureRecognizer::NotGesture;
}
static inline LinjaZaxGesture::DirectionType convertPanningDirection(const QString &direction)
@@ -154,14 +138,14 @@ static inline LinjaZaxGesture::DirectionType convertPanningDirection(const QStri
return LinjaZaxGesture::None;
}
-QGesture* GestureRecognizerLinjaZax::makeEvent() const
+QGesture* GestureRecognizerLinjaZax::getGesture()
{
LinjaZaxGesture::DirectionType dir = convertPanningDirection(currentDirection);
LinjaZaxGesture::DirectionType lastDir = convertPanningDirection(lastDirections.right(1));
if (dir == LinjaZaxGesture::None)
return 0;
LinjaZaxGesture *g =
- new LinjaZaxGesture("LinjaZax", pressedPos, lastPos, currentPos,
+ new LinjaZaxGesture(this, pressedPos, lastPos, currentPos,
QRect(), pressedPos, QDateTime(), 0,
gestureFinished ? Qt::GestureFinished : Qt::GestureStarted);
g->lastDirection_ = lastDir;
diff --git a/examples/gestures/collidingmice/gesturerecognizerlinjazax.h b/examples/gestures/collidingmice/gesturerecognizerlinjazax.h
index 6579059..07172f1 100644
--- a/examples/gestures/collidingmice/gesturerecognizerlinjazax.h
+++ b/examples/gestures/collidingmice/gesturerecognizerlinjazax.h
@@ -43,8 +43,8 @@ class GestureRecognizerLinjaZax : public QGestureRecognizer
public:
GestureRecognizerLinjaZax();
- QGestureRecognizer::Result recognize(const QList<QEvent*> &inputEvents);
- QGesture* makeEvent() const;
+ QGestureRecognizer::Result filterEvent(const QEvent *event);
+ QGesture* getGesture();
void reset();
diff --git a/examples/gestures/collidingmice/linjazaxgesture.h b/examples/gestures/collidingmice/linjazaxgesture.h
index 9601675..8a7cb23 100644
--- a/examples/gestures/collidingmice/linjazaxgesture.h
+++ b/examples/gestures/collidingmice/linjazaxgesture.h
@@ -31,13 +31,16 @@ public:
};
public:
- explicit LinjaZaxGesture(const Qt::GestureType &type, Qt::GestureState state = Qt::GestureStarted)
- : QGesture(type, state), lastDirection_(None), direction_(None), zoomState_(NoZoom) { }
- LinjaZaxGesture(const Qt::GestureType &type, const QPoint &startPos,
- const QPoint &lastPos, const QPoint &pos, const QRect &rect,
- const QPoint &hotSpot, const QDateTime &startTime,
- uint duration, Qt::GestureState state)
- : QGesture(type, startPos, lastPos, pos, rect, hotSpot, startTime, duration, state) { }
+ explicit LinjaZaxGesture(QObject *parent,
+ Qt::GestureState state = Qt::GestureStarted)
+ : QGesture(parent, QLatin1String("LinjaZax"), state), lastDirection_(None),
+ direction_(None), zoomState_(NoZoom) { }
+ LinjaZaxGesture(QObject *parent, const QPoint &startPos,
+ const QPoint &lastPos, const QPoint &pos, const QRect &rect,
+ const QPoint &hotSpot, const QDateTime &startTime,
+ uint duration, Qt::GestureState state)
+ : QGesture(parent, QLatin1String("LinjaZax"), startPos, lastPos,
+ pos, rect, hotSpot, startTime, duration, state) { }
~LinjaZaxGesture() { }
DirectionType lastDirection() const
diff --git a/examples/gestures/collidingmice/main.cpp b/examples/gestures/collidingmice/main.cpp
index d6dbdb0..e8ef13f 100644
--- a/examples/gestures/collidingmice/main.cpp
+++ b/examples/gestures/collidingmice/main.cpp
@@ -62,7 +62,7 @@ public:
PannableGraphicsView(QGraphicsScene *scene, QWidget *parent = 0)
: QGraphicsView(scene, parent)
{
- grabGesture("LinjaZax");
+ grabGesture(QLatin1String("LinjaZax"));
#ifdef ZOOMING_ANIMATION
timeline = new QTimeLine(700, this);
timeline->setFrameRange(0, AnimationSteps);
@@ -74,7 +74,7 @@ protected:
{
if (event->type() == QEvent::Gesture) {
QGestureEvent *ge = static_cast<QGestureEvent*>(event);
- const LinjaZaxGesture *g = dynamic_cast<const LinjaZaxGesture*>(ge->gesture("LinjaZax"));
+ const LinjaZaxGesture *g = static_cast<const LinjaZaxGesture*>(ge->gesture("LinjaZax"));
if (g) {
switch (g->zoomState()) {
case LinjaZaxGesture::ZoomingIn: