From 7301f73ce019aca49e7c9367e22733022bc3680c Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 20 Apr 2017 16:50:41 +0200 Subject: QQuickDrawer: allow passing a touch event to startDrag() Task-number: QTBUG-58389 Change-Id: I4fbdcc2ff4e45a4cbda3e4904c610ab1b269cba3 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickdrawer.cpp | 75 +++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 23 deletions(-) (limited to 'src/quicktemplates2/qquickdrawer.cpp') diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp index e848c160..0c53093b 100644 --- a/src/quicktemplates2/qquickdrawer.cpp +++ b/src/quicktemplates2/qquickdrawer.cpp @@ -234,41 +234,70 @@ void QQuickDrawerPrivate::resizeOverlay() dimmer->setSize(geometry.size()); } -static bool dragOverThreshold(qreal d, Qt::Axis axis, QMouseEvent *event, int threshold = -1) +static bool mouseDragOverThreshold(QQuickDrawer *drawer, QMouseEvent *event) { - return QQuickWindowPrivate::dragOverThreshold(d, axis, event, threshold); + switch (drawer->edge()) { + case Qt::LeftEdge: + return !QQuickWindowPrivate::dragOverThreshold(event->windowPos().x(), Qt::XAxis, event, drawer->dragMargin()); + case Qt::RightEdge: + return !QQuickWindowPrivate::dragOverThreshold(drawer->window()->width() - event->windowPos().x(), Qt::XAxis, event, drawer->dragMargin()); + case Qt::TopEdge: + return !QQuickWindowPrivate::dragOverThreshold(event->windowPos().y(), Qt::YAxis, event, drawer->dragMargin()); + case Qt::BottomEdge: + return !QQuickWindowPrivate::dragOverThreshold(drawer->window()->height() - event->windowPos().y(), Qt::YAxis, event, drawer->dragMargin()); + default: + Q_UNREACHABLE(); + break; + } + return false; } -bool QQuickDrawerPrivate::startDrag(QMouseEvent *event) +static bool touchDragOverThreshold(QQuickDrawer *drawer, const QTouchEvent::TouchPoint &point) { - if (!window || !interactive || dragMargin < 0.0 || qFuzzyIsNull(dragMargin)) - return false; - - bool drag = false; - switch (edge) { + switch (drawer->edge()) { case Qt::LeftEdge: - drag = !dragOverThreshold(event->windowPos().x(), Qt::XAxis, event, dragMargin); - break; + return !QQuickWindowPrivate::dragOverThreshold(point.scenePos().x(), Qt::XAxis, &point, drawer->dragMargin()); case Qt::RightEdge: - drag = !dragOverThreshold(window->width() - event->windowPos().x(), Qt::XAxis, event, dragMargin); - break; + return !QQuickWindowPrivate::dragOverThreshold(drawer->window()->width() - point.scenePos().x(), Qt::XAxis, &point, drawer->dragMargin()); case Qt::TopEdge: - drag = !dragOverThreshold(event->windowPos().y(), Qt::YAxis, event, dragMargin); - break; + return !QQuickWindowPrivate::dragOverThreshold(point.scenePos().y(), Qt::YAxis, &point, drawer->dragMargin()); case Qt::BottomEdge: - drag = !dragOverThreshold(window->height() - event->windowPos().y(), Qt::YAxis, event, dragMargin); - break; + return !QQuickWindowPrivate::dragOverThreshold(drawer->window()->height() - point.scenePos().y(), Qt::YAxis, &point, drawer->dragMargin()); default: + Q_UNREACHABLE(); break; } + return false; +} - if (drag) { - prepareEnterTransition(); - reposition(); - handleMousePressEvent(window->contentItem(), event); +bool QQuickDrawerPrivate::startDrag(QEvent *event) +{ + Q_Q(QQuickDrawer); + if (!window || !interactive || dragMargin < 0.0 || qFuzzyIsNull(dragMargin)) + return false; + + bool overThreshold = false; + bool mouse = event->type() == QEvent::MouseButtonPress; + if (mouse) { + overThreshold = mouseDragOverThreshold(q, static_cast(event)); + } else { + for (const QTouchEvent::TouchPoint &point : static_cast(event)->touchPoints()) { + if (touchDragOverThreshold(q, point)) { + overThreshold = true; + break; + } + } } + if (!overThreshold) + return false; - return drag; + prepareEnterTransition(); + reposition(); + if (mouse) { + handleMousePressEvent(window->contentItem(), static_cast(event)); + return true; + } + return false; } bool QQuickDrawerPrivate::grabMouse(QMouseEvent *event) @@ -286,9 +315,9 @@ bool QQuickDrawerPrivate::grabMouse(QMouseEvent *event) bool overThreshold = false; if (position > 0 || dragMargin > 0) { if (edge == Qt::LeftEdge || edge == Qt::RightEdge) - overThreshold = dragOverThreshold(movePoint.x() - pressPoint.x(), Qt::XAxis, event, threshold); + overThreshold = QQuickWindowPrivate::dragOverThreshold(movePoint.x() - pressPoint.x(), Qt::XAxis, event, threshold); else - overThreshold = dragOverThreshold(movePoint.y() - pressPoint.y(), Qt::YAxis, event, threshold); + overThreshold = QQuickWindowPrivate::dragOverThreshold(movePoint.y() - pressPoint.y(), Qt::YAxis, event, threshold); } // Don't be too eager to steal presses outside the drawer (QTBUG-53929) -- cgit v1.2.3