diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-04-24 23:00:04 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-04-25 13:27:27 +0000 |
commit | 6a9042ad7d79865fb2077081d4357536d8e460a9 (patch) | |
tree | 53d72a60a77c33fa6d6c35c2e95beb2254ebb568 /src/quicktemplates2/qquickdrawer.cpp | |
parent | 279ab48f8bf61a06d5a334924f0b01f45e202cef (diff) |
Simplify QQuickDrawerPrivate::startDrag()
The purpose is to calculate whether a press is within the drag margin
ie. whether a drawer can start dragging. There seems to be no reason to
call the clumsy QQuickWindowPrivate::dragOverThreshold() method, which
is different for mouse and touch events. In addition to the start drag
distance, it actually calculates start drag velocity too, which is
entirely irrelevant for us. Instead, we can do ourselves a very simple
mouse vs. touch agnostic calculation whether a press lands within the
drag margin.
Change-Id: I356a349fdef3df1455715ae7572dbcb9e8100f93
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickdrawer.cpp')
-rw-r--r-- | src/quicktemplates2/qquickdrawer.cpp | 38 |
1 files changed, 10 insertions, 28 deletions
diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp index 02281d5e..0fb26772 100644 --- a/src/quicktemplates2/qquickdrawer.cpp +++ b/src/quicktemplates2/qquickdrawer.cpp @@ -234,35 +234,17 @@ void QQuickDrawerPrivate::resizeOverlay() dimmer->setSize(geometry.size()); } -static bool mouseDragOverThreshold(QQuickDrawer *drawer, QMouseEvent *event) +static bool isWithinDragMargin(QQuickDrawer *drawer, const QPointF &pos) { switch (drawer->edge()) { case Qt::LeftEdge: - return !QQuickWindowPrivate::dragOverThreshold(event->windowPos().x(), Qt::XAxis, event, drawer->dragMargin()); + return pos.x() <= drawer->dragMargin(); case Qt::RightEdge: - return !QQuickWindowPrivate::dragOverThreshold(drawer->window()->width() - event->windowPos().x(), Qt::XAxis, event, drawer->dragMargin()); + return pos.x() >= drawer->window()->width() - drawer->dragMargin(); case Qt::TopEdge: - return !QQuickWindowPrivate::dragOverThreshold(event->windowPos().y(), Qt::YAxis, event, drawer->dragMargin()); + return pos.y() <= 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; -} - -static bool touchDragOverThreshold(QQuickDrawer *drawer, const QTouchEvent::TouchPoint &point) -{ - switch (drawer->edge()) { - case Qt::LeftEdge: - return !QQuickWindowPrivate::dragOverThreshold(point.scenePos().x(), Qt::XAxis, &point, drawer->dragMargin()); - case Qt::RightEdge: - return !QQuickWindowPrivate::dragOverThreshold(drawer->window()->width() - point.scenePos().x(), Qt::XAxis, &point, drawer->dragMargin()); - case Qt::TopEdge: - return !QQuickWindowPrivate::dragOverThreshold(point.scenePos().y(), Qt::YAxis, &point, drawer->dragMargin()); - case Qt::BottomEdge: - return !QQuickWindowPrivate::dragOverThreshold(drawer->window()->height() - point.scenePos().y(), Qt::YAxis, &point, drawer->dragMargin()); + return pos.y() >= drawer->window()->height() - drawer->dragMargin(); default: Q_UNREACHABLE(); break; @@ -276,19 +258,19 @@ bool QQuickDrawerPrivate::startDrag(QEvent *event) if (!window || !interactive || dragMargin < 0.0 || qFuzzyIsNull(dragMargin)) return false; - bool overThreshold = false; + bool withinMargin = false; bool mouse = event->type() == QEvent::MouseButtonPress; if (mouse) { - overThreshold = mouseDragOverThreshold(q, static_cast<QMouseEvent *>(event)); + withinMargin = isWithinDragMargin(q, static_cast<QMouseEvent *>(event)->windowPos()); } else { for (const QTouchEvent::TouchPoint &point : static_cast<QTouchEvent *>(event)->touchPoints()) { - if (touchDragOverThreshold(q, point)) { - overThreshold = true; + if (isWithinDragMargin(q, point.scenePos())) { + withinMargin = true; break; } } } - if (!overThreshold) + if (!withinMargin) return false; prepareEnterTransition(); |