diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-03-13 18:29:05 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-05-11 14:51:32 (GMT) |
commit | 04bb61d39f56fb7a980bda26241b86a8c41724de (patch) | |
tree | 44dc1bb7354d9707081084ee234fab6aa74ad2cc | |
parent | 32164d09d8647995e6177efec967ace799b7c528 (diff) | |
download | Qt-04bb61d39f56fb7a980bda26241b86a8c41724de.zip Qt-04bb61d39f56fb7a980bda26241b86a8c41724de.tar.gz Qt-04bb61d39f56fb7a980bda26241b86a8c41724de.tar.bz2 |
Gesture examples compile now.
-rw-r--r-- | examples/gestures/collidingmice/gesturerecognizerlinjazax.cpp | 114 | ||||
-rw-r--r-- | examples/gestures/collidingmice/gesturerecognizerlinjazax.h | 4 | ||||
-rw-r--r-- | examples/gestures/collidingmice/linjazaxgesture.h | 17 | ||||
-rw-r--r-- | examples/gestures/collidingmice/main.cpp | 4 | ||||
-rw-r--r-- | examples/gestures/graphicsview/main.cpp | 10 | ||||
-rw-r--r-- | examples/gestures/imageviewer/imagewidget.cpp | 20 |
6 files changed, 77 insertions, 92 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: diff --git a/examples/gestures/graphicsview/main.cpp b/examples/gestures/graphicsview/main.cpp index 1b325ee..1a40805 100644 --- a/examples/gestures/graphicsview/main.cpp +++ b/examples/gestures/graphicsview/main.cpp @@ -46,14 +46,14 @@ class PannableGraphicsView : public QGraphicsView public: PannableGraphicsView() { - grabGesture(Qt::Pan); + grabGesture(Qt::PanGesture); } protected: bool event(QEvent *event) { if (event->type() == QEvent::Gesture) { - QGestureEvent *ge = static_cast<QGestureEvent*>(event); - if (const QPannableGesture *g = dynamic_cast<const QPannableGesture*>(ge->gesture(Qt::Pan))) { + QGestureEvent *gestureEvent = static_cast<QGestureEvent*>(event); + if (const QGesture *g = gestureEvent->gesture(Qt::PanGesture)) { QPoint pt = g->pos() - g->lastPos(); horizontalScrollBar()->setValue(horizontalScrollBar()->value() - pt.x()); verticalScrollBar()->setValue(verticalScrollBar()->value() - pt.y()); @@ -71,7 +71,7 @@ public: ImageItem() : colored(false) { - grabGesture(Qt::DoubleTap); + grabGesture(Qt::DoubleTapGesture); } QRectF boundingRect() const @@ -96,7 +96,7 @@ public: { if (event->type() == QEvent::GraphicsSceneGesture) { QGraphicsSceneGestureEvent *gestureEvent = static_cast<QGraphicsSceneGestureEvent*>(event); - if (gestureEvent->gesture(Qt::DoubleTap)) { + if (gestureEvent->gesture(Qt::DoubleTapGesture)) { event->accept(); colored = !colored; update(); diff --git a/examples/gestures/imageviewer/imagewidget.cpp b/examples/gestures/imageviewer/imagewidget.cpp index 0db62bb..1a341a5 100644 --- a/examples/gestures/imageviewer/imagewidget.cpp +++ b/examples/gestures/imageviewer/imagewidget.cpp @@ -61,9 +61,9 @@ ImageWidget::ImageWidget(QWidget *parent) horizontalOffset = 0; verticalOffset = 0; - grabGesture(Qt::DoubleTap); - grabGesture(Qt::Pan); - grabGesture(Qt::LongTap); + grabGesture(Qt::DoubleTapGesture); + grabGesture(Qt::PanGesture); + grabGesture(Qt::TapAndHoldGesture); } void ImageWidget::paintEvent(QPaintEvent*) @@ -136,16 +136,16 @@ void ImageWidget::gestureEvent(QGestureEvent *event) touchFeedback.doubleTapped = false; Q_ASSERT(event); - if (event->contains(Qt::Tap)) { + if (event->contains(Qt::TapGesture)) { // - } else if (const QGesture *g = event->gesture(Qt::DoubleTap)) { + } else if (const QGesture *g = event->gesture(Qt::DoubleTapGesture)) { touchFeedback.doubleTapped = true; horizontalOffset = g->hotSpot().x() - currentImage.width()*1.0*g->hotSpot().x()/width(); verticalOffset = g->hotSpot().y() - currentImage.height()*1.0*g->hotSpot().y()/height(); setZoomedIn(!zoomedIn); zoomed = rotated = false; updateImage(); - } else if (const QGesture *g = event->gesture(Qt::Pan)) { + } else if (const QGesture *g = event->gesture(Qt::PanGesture)) { if (zoomedIn) { // usual panning #ifndef QT_NO_CURSOR @@ -161,8 +161,8 @@ void ImageWidget::gestureEvent(QGestureEvent *event) update(); } else { // only slide gesture should be accepted - const QPannableGesture *pg = dynamic_cast<const QPannableGesture*>(g); - if (pg && pg->direction() != pg->lastDirection()) { + const QPannableGesture *pg = static_cast<const QPannableGesture*>(g); + if (pg->direction() != pg->lastDirection()) { // ###: event->cancel(); } if (g->state() == Qt::GestureFinished) { @@ -178,7 +178,7 @@ void ImageWidget::gestureEvent(QGestureEvent *event) updateImage(); } } - } else if (const QGesture *g = event->gesture(Qt::LongTap)) { + } else if (const QGesture *g = event->gesture(Qt::TapAndHoldGesture)) { if (g->state() == Qt::GestureFinished) { qDebug() << "tap and hold detected"; touchFeedback.reset(); @@ -190,8 +190,6 @@ void ImageWidget::gestureEvent(QGestureEvent *event) menu.addAction("Action 3"); menu.exec(mapToGlobal(g->hotSpot())); } - } else if (const QGesture *g = event->gesture(Qt::LongTap)) { - qDebug() << "long tap: " << (g->state() == Qt::GestureStarted ? "started" : "finished"); } else { qDebug() << "unknown gesture"; } |