aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick/handlers/qquicktaphandler.cpp34
-rw-r--r--src/quick/handlers/qquicktaphandler_p.h6
-rw-r--r--tests/manual/pointer/tapHandler.qml16
3 files changed, 53 insertions, 3 deletions
diff --git a/src/quick/handlers/qquicktaphandler.cpp b/src/quick/handlers/qquicktaphandler.cpp
index 11d4301eb6..51a496001c 100644
--- a/src/quick/handlers/qquicktaphandler.cpp
+++ b/src/quick/handlers/qquicktaphandler.cpp
@@ -245,10 +245,14 @@ void QQuickTapHandler::setPressed(bool press, bool cancel, QQuickEventPoint *poi
{
if (m_pressed != press) {
m_pressed = press;
- if (press)
+ connectPreRenderSignal(press);
+ if (press) {
m_longPressTimer.start(longPressThresholdMilliseconds(), this);
- else
+ m_holdTimer.start();
+ } else {
m_longPressTimer.stop();
+ m_holdTimer.invalidate();
+ }
if (m_gesturePolicy != DragThreshold)
setGrab(point, press);
if (!cancel && !press && point->timeHeld() < longPressThreshold()) {
@@ -276,6 +280,19 @@ void QQuickTapHandler::handleGrabCancel(QQuickEventPoint *point)
setPressed(false, true, point);
}
+void QQuickTapHandler::connectPreRenderSignal(bool conn)
+{
+ if (conn)
+ connect(parentItem()->window(), &QQuickWindow::beforeSynchronizing, this, &QQuickTapHandler::updateTimeHeld);
+ else
+ disconnect(parentItem()->window(), &QQuickWindow::beforeSynchronizing, this, &QQuickTapHandler::updateTimeHeld);
+}
+
+void QQuickTapHandler::updateTimeHeld()
+{
+ emit timeHeldChanged();
+}
+
/*!
\qmlproperty tapCount
@@ -294,4 +311,17 @@ void QQuickTapHandler::handleGrabCancel(QQuickEventPoint *point)
}
*/
+/*!
+ \qmlproperty timeHeld
+
+ The amount of time in seconds that a pressed point has been held, without
+ moving beyond the drag threshold. It will be updated at least once per
+ frame rendered, which enables rendering an animation showing the progress
+ towards an action which will be triggered by a long-press. It is also
+ possible to trigger one of a series of actions depending on how long the
+ press is held.
+
+ A value less than zero means no point is being held within this handler's Item.
+*/
+
QT_END_NAMESPACE
diff --git a/src/quick/handlers/qquicktaphandler_p.h b/src/quick/handlers/qquicktaphandler_p.h
index 93fe817844..bc292ecb12 100644
--- a/src/quick/handlers/qquicktaphandler_p.h
+++ b/src/quick/handlers/qquicktaphandler_p.h
@@ -63,6 +63,7 @@ class Q_AUTOTEST_EXPORT QQuickTapHandler : public QQuickPointerSingleHandler
Q_OBJECT
Q_PROPERTY(bool isPressed READ isPressed NOTIFY pressedChanged)
Q_PROPERTY(int tapCount READ tapCount NOTIFY tapCountChanged)
+ Q_PROPERTY(qreal timeHeld READ timeHeld NOTIFY timeHeldChanged)
Q_PROPERTY(qreal longPressThreshold READ longPressThreshold WRITE setLongPressThreshold NOTIFY longPressThresholdChanged)
Q_PROPERTY(GesturePolicy gesturePolicy READ gesturePolicy WRITE setGesturePolicy NOTIFY gesturePolicyChanged)
@@ -83,6 +84,7 @@ public:
bool isPressed() const { return m_pressed; }
int tapCount() const { return m_tapCount; }
+ qreal timeHeld() const { return (m_holdTimer.isValid() ? m_holdTimer.elapsed() / 1000.0 : -1.0); }
qreal longPressThreshold() const;
void setLongPressThreshold(qreal longPressThreshold);
@@ -93,6 +95,7 @@ public:
Q_SIGNALS:
void pressedChanged();
void tapCountChanged();
+ void timeHeldChanged();
void longPressThresholdChanged();
void gesturePolicyChanged();
void tapped(QQuickEventPoint *point);
@@ -105,6 +108,8 @@ protected:
private:
void setPressed(bool press, bool cancel, QQuickEventPoint *point);
int longPressThresholdMilliseconds() const;
+ void connectPreRenderSignal(bool conn = true);
+ void updateTimeHeld();
private:
bool m_pressed;
@@ -112,6 +117,7 @@ private:
int m_tapCount;
int m_longPressThreshold;
QBasicTimer m_longPressTimer;
+ QElapsedTimer m_holdTimer;
QPointF m_lastTapPos;
qreal m_lastTapTimestamp;
diff --git a/tests/manual/pointer/tapHandler.qml b/tests/manual/pointer/tapHandler.qml
index 2e45b1c369..06070a02ff 100644
--- a/tests/manual/pointer/tapHandler.qml
+++ b/tests/manual/pointer/tapHandler.qml
@@ -81,7 +81,7 @@ Item {
}
onLongPressed: longPressFeedback.createObject(rect,
{"x": pos.x, "y": pos.y,
- "text": "long press",
+ "text": Math.round(handler.timeHeld).toFixed(3) + " sec",
"color": borderBlink.blinkColor})
}
@@ -112,6 +112,20 @@ Item {
}
}
+ Rectangle {
+ id: expandingCircle
+ radius: handler.timeHeld * 100
+ visible: radius > 0 && handler.isPressed
+ border.width: 3
+ border.color: borderBlink.blinkColor
+ color: "transparent"
+ width: radius * 2
+ height: radius * 2
+ x: handler.pressPos.x - radius
+ y: handler.pressPos.y - radius
+ opacity: 0.25
+ }
+
Component {
id: longPressFeedback
Text { }