diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-08-03 15:02:58 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-08-04 14:22:46 (GMT) |
commit | 6b85ec8790aad8ac01c04f7e7bd4913d8cd8d104 (patch) | |
tree | b45584416ababa562478ca35a7f2ef2c63936942 /examples/gestures/imageviewer/tapandholdgesture.cpp | |
parent | 6e7a6478279a94a82af46e6814f113244aca46dd (diff) | |
download | Qt-6b85ec8790aad8ac01c04f7e7bd4913d8cd8d104.zip Qt-6b85ec8790aad8ac01c04f7e7bd4913d8cd8d104.tar.gz Qt-6b85ec8790aad8ac01c04f7e7bd4913d8cd8d104.tar.bz2 |
Removed the QTapAndHoldGesture
Moved the gesture implementation to the imageviewer example as it cannot be
fully implemented in a crossplatform way - for example on Windows tap and hold
is a system gesture that is transparent to the application.
Reviewed-by: trustme
Diffstat (limited to 'examples/gestures/imageviewer/tapandholdgesture.cpp')
-rw-r--r-- | examples/gestures/imageviewer/tapandholdgesture.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/examples/gestures/imageviewer/tapandholdgesture.cpp b/examples/gestures/imageviewer/tapandholdgesture.cpp new file mode 100644 index 0000000..c6f6779 --- /dev/null +++ b/examples/gestures/imageviewer/tapandholdgesture.cpp @@ -0,0 +1,97 @@ +#include "tapandholdgesture.h" + +#include <QtGui/qevent.h> + +/*! + \class TapAndHoldGesture + \since 4.6 + + \brief The TapAndHoldGesture class represents a Tap-and-Hold gesture, + providing additional information. +*/ + +const int TapAndHoldGesture::iterationCount = 40; +const int TapAndHoldGesture::iterationTimeout = 50; + +/*! + Creates a new Tap and Hold gesture handler object and marks it as a child + of \a parent. + + On some platforms like Windows there is a system-wide tap and hold gesture + that cannot be overriden, hence the gesture might never trigger and default + context menu will be shown instead. +*/ +TapAndHoldGesture::TapAndHoldGesture(QWidget *parent) + : QGesture(parent), iteration(0) +{ +} + +/*! \internal */ +bool TapAndHoldGesture::filterEvent(QEvent *event) +{ + if (!event->spontaneous()) + return false; + const QTouchEvent *ev = static_cast<const QTouchEvent*>(event); + switch (event->type()) { + case QEvent::TouchBegin: { + if (timer.isActive()) + timer.stop(); + timer.start(TapAndHoldGesture::iterationTimeout, this); + const QPoint p = ev->touchPoints().at(0).pos().toPoint(); + position = p; + break; + } + case QEvent::TouchUpdate: + if (ev->touchPoints().size() == 1) { + const QPoint startPos = ev->touchPoints().at(0).startPos().toPoint(); + const QPoint pos = ev->touchPoints().at(0).pos().toPoint(); + if ((startPos - pos).manhattanLength() > 15) + reset(); + } else { + reset(); + } + break; + case QEvent::TouchEnd: + reset(); + break; + default: + break; + } + return false; +} + +/*! \internal */ +void TapAndHoldGesture::timerEvent(QTimerEvent *event) +{ + if (event->timerId() != timer.timerId()) + return; + if (iteration == TapAndHoldGesture::iterationCount) { + timer.stop(); + setState(Qt::GestureFinished); + emit triggered(); + } else { + setState(Qt::GestureStarted); + emit triggered(); + } + ++iteration; +} + +/*! \internal */ +void TapAndHoldGesture::reset() +{ + if (state() != Qt::NoGesture) + emit cancelled(); + setState(Qt::NoGesture); + timer.stop(); + iteration = 0; +} + +/*! + \property TapAndHoldGesture::pos + + \brief The position of the gesture. +*/ +QPoint TapAndHoldGesture::pos() const +{ + return position; +} |