summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel
diff options
context:
space:
mode:
authorAhmad Samir <[email protected]>2024-09-04 00:24:13 +0300
committerAhmad Samir <[email protected]>2024-09-13 21:05:35 +0300
commit33ad8cc1b43196e000e0dc2f3ffa05482881c2aa (patch)
tree14969b70e7f9777a6619f3173cec5c3e4456becc /src/widgets/kernel
parent18d5bb41a755fae4f4d770f6555234f09c0d8118 (diff)
QTapAndHoldGesture: port to QBasicTimer instead of handling timer IDs
Change-Id: I132696340d46b906a61412222529ad51fc988390 Reviewed-by: Richard Moe Gustavsen <[email protected]>
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r--src/widgets/kernel/qgesture_p.h4
-rw-r--r--src/widgets/kernel/qstandardgestures.cpp27
2 files changed, 12 insertions, 19 deletions
diff --git a/src/widgets/kernel/qgesture_p.h b/src/widgets/kernel/qgesture_p.h
index 1e4292abf92..4b7aaa8daed 100644
--- a/src/widgets/kernel/qgesture_p.h
+++ b/src/widgets/kernel/qgesture_p.h
@@ -19,6 +19,7 @@
#include "qrect.h"
#include "qpoint.h"
#include "qgesture.h"
+#include "qbasictimer.h"
#include "qelapsedtimer.h"
#include "private/qobject_p.h"
@@ -150,12 +151,11 @@ class QTapAndHoldGesturePrivate : public QGesturePrivate
public:
QTapAndHoldGesturePrivate()
- : timerId(0)
{
}
QPointF position;
- int timerId;
+ QBasicTimer tapAndHoldTimer;
static int Timeout;
};
diff --git a/src/widgets/kernel/qstandardgestures.cpp b/src/widgets/kernel/qstandardgestures.cpp
index 337a6879a9b..9e56c5a8d79 100644
--- a/src/widgets/kernel/qstandardgestures.cpp
+++ b/src/widgets/kernel/qstandardgestures.cpp
@@ -16,6 +16,8 @@
#ifndef QT_NO_GESTURES
+using namespace std::chrono_literals;
+
QT_BEGIN_NAMESPACE
// If the change in scale for a single touch event is out of this range,
@@ -469,8 +471,7 @@ QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object,
QTapAndHoldGesturePrivate *d = q->d_func();
if (object == state && event->type() == QEvent::Timer) {
- q->killTimer(d->timerId);
- d->timerId = 0;
+ d->tapAndHoldTimer.stop();
return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint;
}
@@ -482,9 +483,7 @@ QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object,
const QGraphicsSceneMouseEvent *gsme = static_cast<const QGraphicsSceneMouseEvent *>(event);
d->position = gsme->screenPos();
q->setHotSpot(d->position);
- if (d->timerId)
- q->killTimer(d->timerId);
- d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout);
+ d->tapAndHoldTimer.start(QTapAndHoldGesturePrivate::Timeout * 1ms, q);
return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout
}
#endif
@@ -492,18 +491,14 @@ QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object,
const QMouseEvent *me = static_cast<const QMouseEvent *>(event);
d->position = me->globalPosition().toPoint();
q->setHotSpot(d->position);
- if (d->timerId)
- q->killTimer(d->timerId);
- d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout);
+ d->tapAndHoldTimer.start(QTapAndHoldGesturePrivate::Timeout * 1ms, q);
return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout
}
case QEvent::TouchBegin: {
const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
d->position = ev->points().at(0).globalPressPosition();
q->setHotSpot(d->position);
- if (d->timerId)
- q->killTimer(d->timerId);
- d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout);
+ d->tapAndHoldTimer.start(QTapAndHoldGesturePrivate::Timeout * 1ms, q);
return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout
}
#if QT_CONFIG(graphicsview)
@@ -514,7 +509,7 @@ QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object,
return QGestureRecognizer::CancelGesture; // get out of the MayBeGesture state
case QEvent::TouchUpdate: {
const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
- if (d->timerId && ev->points().size() == 1) {
+ if (d->tapAndHoldTimer.isActive() && ev->points().size() == 1) {
const QEventPoint &p = ev->points().at(0);
QPoint delta = p.position().toPoint() - p.pressPosition().toPoint();
if (delta.manhattanLength() <= TapRadius)
@@ -525,7 +520,7 @@ QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object,
case QEvent::MouseMove: {
const QMouseEvent *me = static_cast<const QMouseEvent *>(event);
QPoint delta = me->globalPosition().toPoint() - d->position.toPoint();
- if (d->timerId && delta.manhattanLength() <= TapRadius)
+ if (d->tapAndHoldTimer.isActive() && delta.manhattanLength() <= TapRadius)
return QGestureRecognizer::MayBeGesture;
return QGestureRecognizer::CancelGesture;
}
@@ -533,7 +528,7 @@ QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object,
case QEvent::GraphicsSceneMouseMove: {
const QGraphicsSceneMouseEvent *gsme = static_cast<const QGraphicsSceneMouseEvent *>(event);
QPoint delta = gsme->screenPos() - d->position.toPoint();
- if (d->timerId && delta.manhattanLength() <= TapRadius)
+ if (d->tapAndHoldTimer.isActive() && delta.manhattanLength() <= TapRadius)
return QGestureRecognizer::MayBeGesture;
return QGestureRecognizer::CancelGesture;
}
@@ -549,9 +544,7 @@ void QTapAndHoldGestureRecognizer::reset(QGesture *state)
QTapAndHoldGesturePrivate *d = q->d_func();
d->position = QPointF();
- if (d->timerId)
- q->killTimer(d->timerId);
- d->timerId = 0;
+ d->tapAndHoldTimer.stop();
QGestureRecognizer::reset(state);
}