diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2016-11-29 14:50:05 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-02-10 13:04:47 +0000 |
commit | 50aaca40fe09a3ab6c927f7a550b2e97cf332a9c (patch) | |
tree | 9353a10e848499b14ff8ae0254cbfde67dbce721 /src/quick/handlers | |
parent | 02f430462b4e9256b6ae021e3d415c0d2180404d (diff) |
start making explicit exclusive or passive grabs
Change-Id: I4a6e3c72d69e893fec2e39f4faab24af6d00c7e0
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/quick/handlers')
-rw-r--r-- | src/quick/handlers/qquickdraghandler.cpp | 5 | ||||
-rw-r--r-- | src/quick/handlers/qquickdraghandler_p.h | 2 | ||||
-rw-r--r-- | src/quick/handlers/qquickmultipointerhandler.cpp | 2 | ||||
-rw-r--r-- | src/quick/handlers/qquickpointerhandler.cpp | 34 | ||||
-rw-r--r-- | src/quick/handlers/qquickpointerhandler_p.h | 6 | ||||
-rw-r--r-- | src/quick/handlers/qquickpointersinglehandler.cpp | 8 | ||||
-rw-r--r-- | src/quick/handlers/qquicktaphandler.cpp | 3 |
7 files changed, 42 insertions, 18 deletions
diff --git a/src/quick/handlers/qquickdraghandler.cpp b/src/quick/handlers/qquickdraghandler.cpp index 6caee6be13..9575f7ede9 100644 --- a/src/quick/handlers/qquickdraghandler.cpp +++ b/src/quick/handlers/qquickdraghandler.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtQuick module of the Qt Toolkit. @@ -80,6 +80,7 @@ void QQuickDragHandler::handleEventPoint(QQuickEventPoint *point) case QQuickEventPoint::Pressed: if (target() && target()->parentItem()) m_startPos = target()->parentItem()->mapToScene(target()->position()); + setPassiveGrab(point); break; case QQuickEventPoint::Updated: { QPointF delta = point->scenePos() - point->scenePressPos(); @@ -96,7 +97,7 @@ void QQuickDragHandler::handleEventPoint(QQuickEventPoint *point) } } else if ((m_xAxis.enabled() && QQuickWindowPrivate::dragOverThreshold(delta.x(), Qt::XAxis, point)) || (m_yAxis.enabled() && QQuickWindowPrivate::dragOverThreshold(delta.y(), Qt::YAxis, point))) { - setGrab(point, true); + setExclusiveGrab(point); } } break; default: diff --git a/src/quick/handlers/qquickdraghandler_p.h b/src/quick/handlers/qquickdraghandler_p.h index 69fa297b3c..6250615091 100644 --- a/src/quick/handlers/qquickdraghandler_p.h +++ b/src/quick/handlers/qquickdraghandler_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtQuick module of the Qt Toolkit. diff --git a/src/quick/handlers/qquickmultipointerhandler.cpp b/src/quick/handlers/qquickmultipointerhandler.cpp index d3b986bcce..4b931641a2 100644 --- a/src/quick/handlers/qquickmultipointerhandler.cpp +++ b/src/quick/handlers/qquickmultipointerhandler.cpp @@ -213,7 +213,7 @@ void QQuickMultiPointerHandler::acceptPoints(const QVector<QQuickEventPoint *> & void QQuickMultiPointerHandler::grabPoints(QVector<QQuickEventPoint *> points) { for (QQuickEventPoint* point : points) - setGrab(point, true); + setExclusiveGrab(point); } QT_END_NAMESPACE diff --git a/src/quick/handlers/qquickpointerhandler.cpp b/src/quick/handlers/qquickpointerhandler.cpp index 0398863ba3..c91fb2de88 100644 --- a/src/quick/handlers/qquickpointerhandler.cpp +++ b/src/quick/handlers/qquickpointerhandler.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtQuick module of the Qt Toolkit. @@ -42,6 +42,7 @@ QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcPointerHandlerDispatch, "qt.quick.handler.dispatch") +Q_LOGGING_CATEGORY(lcPointerHandlerActive, "qt.quick.handler.active") /*! \qmltype PointerHandler @@ -73,22 +74,42 @@ QQuickPointerHandler::~QQuickPointerHandler() } } -void QQuickPointerHandler::setGrab(QQuickEventPoint *point, bool grab) +void QQuickPointerHandler::setPassiveGrab(QQuickEventPoint *point, bool grab) +{ + if (grab) { + point->setGrabberPointerHandler(this, false); + emit grabChanged(point); + } else if (point->grabberPointerHandler() == this) { + // TODO should giving up passive grab imply giving up exclusive grab too? + // we're being inconsistent here: check whether the exclusive grabber is this, + // then say that the passive grab was canceled. + point->cancelPassiveGrab(this); + emit grabChanged(point); + } +} + +void QQuickPointerHandler::setExclusiveGrab(QQuickEventPoint *point, bool grab) { QQuickPointerHandler *oldGrabber = point->grabberPointerHandler(); if (grab && oldGrabber != this) { if (oldGrabber) oldGrabber->handleGrabCancel(point); - point->setGrabberPointerHandler(this); + point->setGrabberPointerHandler(this, true); onGrabChanged(point); - emit grabChanged(point); +// emit grabChanged(point); // TODO maybe } else if (!grab && oldGrabber == this) { - point->setGrabberPointerHandler(nullptr); + point->setGrabberPointerHandler(nullptr, true); onGrabChanged(point); - emit grabChanged(point); +// emit grabChanged(point); // TODO maybe } } +void QQuickPointerHandler::cancelAllGrabs(QQuickEventPoint *point) +{ + point->cancelAllGrabs(this); + emit grabChanged(point); +} + QPointF QQuickPointerHandler::eventPos(const QQuickEventPoint *point) const { return (target() ? target()->mapFromScene(point->scenePos()) : point->scenePos()); @@ -164,6 +185,7 @@ bool QQuickPointerHandler::wantsPointerEvent(QQuickPointerEvent *event) void QQuickPointerHandler::setActive(bool active) { if (m_active != active) { + qCDebug(lcPointerHandlerActive) << this << m_active << "->" << active; m_active = active; onActiveChanged(); emit activeChanged(); diff --git a/src/quick/handlers/qquickpointerhandler_p.h b/src/quick/handlers/qquickpointerhandler_p.h index 85f1096410..526a60262b 100644 --- a/src/quick/handlers/qquickpointerhandler_p.h +++ b/src/quick/handlers/qquickpointerhandler_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtQuick module of the Qt Toolkit. @@ -99,7 +99,9 @@ protected: void setActive(bool active); virtual void onActiveChanged() { } virtual void onGrabChanged(QQuickEventPoint *) { } - void setGrab(QQuickEventPoint *point, bool grab); + void setPassiveGrab(QQuickEventPoint *point, bool grab = true); + void setExclusiveGrab(QQuickEventPoint *point, bool grab = true); + void cancelAllGrabs(QQuickEventPoint *point); virtual void handleGrabCancel(QQuickEventPoint *point); QPointF eventPos(const QQuickEventPoint *point) const; bool parentContains(const QQuickEventPoint *point) const; diff --git a/src/quick/handlers/qquickpointersinglehandler.cpp b/src/quick/handlers/qquickpointersinglehandler.cpp index aeaa9d8309..41c9e1f322 100644 --- a/src/quick/handlers/qquickpointersinglehandler.cpp +++ b/src/quick/handlers/qquickpointersinglehandler.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtQuick module of the Qt Toolkit. @@ -70,8 +70,8 @@ bool QQuickPointerSingleHandler::wantsPointerEvent(QQuickPointerEvent *event) if (wantsEventPoint(point)) { point->setAccepted(); return true; - } else if (point->grabber() == this) { - point->cancelGrab(); + } else { + point->cancelAllGrabs(this); } } else { qCWarning(DBG_TOUCH_TARGET) << this << "pointId" << m_pointId @@ -125,7 +125,7 @@ void QQuickPointerSingleHandler::handlePointerEventImpl(QQuickPointerEvent *even emit pointIdChanged(); break; case QQuickEventPoint::Released: - setGrab(currentPoint, false); + setExclusiveGrab(currentPoint, false); reset(); break; default: diff --git a/src/quick/handlers/qquicktaphandler.cpp b/src/quick/handlers/qquicktaphandler.cpp index 51a496001c..5065e87e8e 100644 --- a/src/quick/handlers/qquicktaphandler.cpp +++ b/src/quick/handlers/qquicktaphandler.cpp @@ -253,8 +253,7 @@ void QQuickTapHandler::setPressed(bool press, bool cancel, QQuickEventPoint *poi m_longPressTimer.stop(); m_holdTimer.invalidate(); } - if (m_gesturePolicy != DragThreshold) - setGrab(point, press); + setPassiveGrab(point, press); if (!cancel && !press && point->timeHeld() < longPressThreshold()) { // Assuming here that pointerEvent()->timestamp() is in ms. qreal ts = point->pointerEvent()->timestamp() / 1000.0; |