diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-05-28 17:59:34 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-05-28 17:59:40 +0200 |
commit | 1f3c157ec6b8be5de1eb89295713c2980fb1a7aa (patch) | |
tree | b85888d73518f6abc7bbde74ab71a27887682f9d /src/quick/handlers/qquickdraghandler.cpp | |
parent | 44ca7e31ee9365a72cd17ecd335ec4d0161420a9 (diff) | |
parent | 0f5c34f2c6b64bae3429706a6c4211334c689092 (diff) |
Merge "Merge remote-tracking branch 'origin/dev' into wip/scenegraphng"wip/scenegraphng
Diffstat (limited to 'src/quick/handlers/qquickdraghandler.cpp')
-rw-r--r-- | src/quick/handlers/qquickdraghandler.cpp | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/quick/handlers/qquickdraghandler.cpp b/src/quick/handlers/qquickdraghandler.cpp index 22fe3df4d0..61b66beff4 100644 --- a/src/quick/handlers/qquickdraghandler.cpp +++ b/src/quick/handlers/qquickdraghandler.cpp @@ -114,8 +114,14 @@ void QQuickDragHandler::onGrabChanged(QQuickPointerHandler *grabber, QQuickEvent QQuickMultiPointHandler::onGrabChanged(grabber, transition, point); if (grabber == this && transition == QQuickEventPoint::GrabExclusive && target()) { // In case the grab got handed over from another grabber, we might not get the Press. - if (!m_pressedInsideTarget) { - if (target() != parentItem()) + + auto isDescendant = [](QQuickItem *parent, QQuickItem *target) { + return (target != parent) && !target->isAncestorOf(parent); + }; + if (m_snapMode == SnapAlways + || (m_snapMode == SnapIfPressedOutsideTarget && !m_pressedInsideTarget) + || (m_snapMode == SnapAuto && !m_pressedInsideTarget && isDescendant(parentItem(), target())) + ) { m_pressTargetPos = QPointF(target()->width(), target()->height()) / 2; } else if (m_pressTargetPos.isNull()) { m_pressTargetPos = targetCentroidPosition(); @@ -123,6 +129,33 @@ void QQuickDragHandler::onGrabChanged(QQuickPointerHandler *grabber, QQuickEvent } } +/*! + \qmlproperty enumeration QtQuick.DragHandler::snapMode + + This property holds the snap mode. + + The snap mode configures snapping of the \l target item's center to the event point. + + Possible values: + \value DragHandler.SnapNever Never snap + \value DragHandler.SnapAuto The \l target snaps if the event point was pressed outside of the \l target + item \e and the \l target is a descendant of \l parentItem (default) + \value DragHandler.SnapWhenPressedOutsideTarget The \l target snaps if the event point was pressed outside of the \l target + \value DragHandler.SnapAlways Always snap +*/ +QQuickDragHandler::SnapMode QQuickDragHandler::snapMode() const +{ + return m_snapMode; +} + +void QQuickDragHandler::setSnapMode(QQuickDragHandler::SnapMode mode) +{ + if (mode == m_snapMode) + return; + m_snapMode = mode; + emit snapModeChanged(); +} + void QQuickDragHandler::onActiveChanged() { QQuickMultiPointHandler::onActiveChanged(); |