diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-08-11 08:45:54 +1000 |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-08-11 08:45:54 +1000 |
commit | 6bb93ab2fd79ae0a04c826d9027503b644b6e374 (patch) | |
tree | 060d9765cf3f009c86fe6e421dac4ea8930d076e /examples/gestures/imageviewer/tapandholdgesture.cpp | |
parent | 40db84c97769141f3f2351de1b2d5c64904fe5c2 (diff) | |
parent | 6c3c9d812a730d5bc1bcd6261befe077a65be594 (diff) |
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt
Diffstat (limited to 'examples/gestures/imageviewer/tapandholdgesture.cpp')
-rw-r--r-- | examples/gestures/imageviewer/tapandholdgesture.cpp | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/examples/gestures/imageviewer/tapandholdgesture.cpp b/examples/gestures/imageviewer/tapandholdgesture.cpp index ff5284e45..5fe52ccbc 100644 --- a/examples/gestures/imageviewer/tapandholdgesture.cpp +++ b/examples/gestures/imageviewer/tapandholdgesture.cpp @@ -43,6 +43,8 @@ #include <QtGui/qevent.h> +// #define TAPANDHOLD_USING_MOUSE + /*! \class TapAndHoldGesture \since 4.6 @@ -95,6 +97,26 @@ bool TapAndHoldGesture::filterEvent(QEvent *event) case QEvent::TouchEnd: reset(); break; +#ifdef TAPANDHOLD_USING_MOUSE + case QEvent::MouseButtonPress: { + if (timer.isActive()) + timer.stop(); + timer.start(TapAndHoldGesture::iterationTimeout, this); + const QPoint p = static_cast<QMouseEvent*>(event)->pos(); + position = startPosition = p; + break; + } + case QEvent::MouseMove: { + const QPoint startPos = startPosition; + const QPoint pos = static_cast<QMouseEvent*>(event)->pos(); + if ((startPos - pos).manhattanLength() > 15) + reset(); + break; + } + case QEvent::MouseButtonRelease: + reset(); + break; +#endif // TAPANDHOLD_USING_MOUSE default: break; } @@ -108,11 +130,9 @@ void TapAndHoldGesture::timerEvent(QTimerEvent *event) return; if (iteration == TapAndHoldGesture::iterationCount) { timer.stop(); - setState(Qt::GestureFinished); - emit triggered(); + updateState(Qt::GestureFinished); } else { - setState(Qt::GestureStarted); - emit triggered(); + updateState(Qt::GestureUpdated); } ++iteration; } @@ -120,11 +140,10 @@ void TapAndHoldGesture::timerEvent(QTimerEvent *event) /*! \internal */ void TapAndHoldGesture::reset() { - if (state() != Qt::NoGesture) - emit cancelled(); - setState(Qt::NoGesture); timer.stop(); iteration = 0; + position = startPosition = QPoint(); + updateState(Qt::NoGesture); } /*! |