diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-04-20 16:50:41 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-04-21 08:35:10 +0000 |
commit | 7301f73ce019aca49e7c9367e22733022bc3680c (patch) | |
tree | 816e134619552b1fc18a03143df9fc19e158aa89 /src | |
parent | 7c65f4f7e6167b868e3357d85dabe19e68f3c1b6 (diff) |
QQuickDrawer: allow passing a touch event to startDrag()
Task-number: QTBUG-58389
Change-Id: I4fbdcc2ff4e45a4cbda3e4904c610ab1b269cba3
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quicktemplates2/qquickdrawer.cpp | 75 | ||||
-rw-r--r-- | src/quicktemplates2/qquickdrawer_p_p.h | 2 |
2 files changed, 53 insertions, 24 deletions
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<QMouseEvent *>(event)); + } else { + for (const QTouchEvent::TouchPoint &point : static_cast<QTouchEvent *>(event)->touchPoints()) { + if (touchDragOverThreshold(q, point)) { + overThreshold = true; + break; + } + } } + if (!overThreshold) + return false; - return drag; + prepareEnterTransition(); + reposition(); + if (mouse) { + handleMousePressEvent(window->contentItem(), static_cast<QMouseEvent *>(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) diff --git a/src/quicktemplates2/qquickdrawer_p_p.h b/src/quicktemplates2/qquickdrawer_p_p.h index 388e926b..dc17647d 100644 --- a/src/quicktemplates2/qquickdrawer_p_p.h +++ b/src/quicktemplates2/qquickdrawer_p_p.h @@ -70,7 +70,7 @@ public: void reposition() override; void resizeOverlay() override; - bool startDrag(QMouseEvent *event); + bool startDrag(QEvent *event); bool grabMouse(QMouseEvent *event); bool ungrabMouse(QMouseEvent *event); |