aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/handlers/qquicktaphandler.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2015-08-05 12:45:48 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2017-02-09 14:32:32 +0000
commit12f3f20be7e160b4f8de4ee267909fec61673111 (patch)
tree46bb48b514d537315a920dbe135c60f05d49d4f8 /src/quick/handlers/qquicktaphandler.cpp
parentcb78d5c91ed33543a8e7fe7717f74f95834e4cc3 (diff)
TapHandler: add timeHeld property
It enables long-press gestures to have continuous feedback. Change-Id: Idd0838aff6213ebfc2fce66639bbc932e77208b4 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/quick/handlers/qquicktaphandler.cpp')
-rw-r--r--src/quick/handlers/qquicktaphandler.cpp34
1 files changed, 32 insertions, 2 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