diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-09-04 14:31:58 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-09-06 11:41:27 +0000 |
commit | 1d3233e9737b494787941ceefad361fb39488f05 (patch) | |
tree | 3def5859b575e359ff259ab5552311d511e60971 /src | |
parent | b9600bb83536ad3072072a374883ce835302dc56 (diff) |
QQuickDrawerPrivate::grabMouse()
Split grabMouse() out of handleMouseMoveEvent(). This makes the mouse
move handling code a bit easier to read.
Change-Id: I39971e995d8d202e702bddeec0d1f9554c298c0e
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quicktemplates2/qquickdrawer.cpp | 71 | ||||
-rw-r--r-- | src/quicktemplates2/qquickdrawer_p_p.h | 1 |
2 files changed, 40 insertions, 32 deletions
diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp index ae9442f8..b2f9f519 100644 --- a/src/quicktemplates2/qquickdrawer.cpp +++ b/src/quicktemplates2/qquickdrawer.cpp @@ -194,6 +194,37 @@ bool QQuickDrawerPrivate::startDrag(QQuickWindow *window, QMouseEvent *event) return drag; } +bool QQuickDrawerPrivate::grabMouse(QMouseEvent *event) +{ + Q_Q(QQuickDrawer); + if (!window || popupItem->keepMouseGrab()) + return false; + + const QPointF movePoint = event->windowPos(); + + // Flickable uses a hard-coded threshold of 15 for flicking, and + // QStyleHints::startDragDistance for dragging. Drawer uses a bit + // larger threshold to avoid being too eager to steal touch (QTBUG-50045) + const int threshold = qMax(20, QGuiApplication::styleHints()->startDragDistance() + 5); + 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); + else + overThreshold = dragOverThreshold(movePoint.y() - pressPoint.y(), Qt::YAxis, event, threshold); + } + + // Don't be too eager to steal presses outside the drawer (QTBUG-53929) + if (overThreshold && qFuzzyCompare(position, qreal(1.0)) && !popupItem->contains(popupItem->mapFromScene(movePoint))) { + if (edge == Qt::LeftEdge || edge == Qt::RightEdge) + overThreshold = qAbs(movePoint.x() - q->width()) < dragMargin; + else + overThreshold = qAbs(movePoint.y() - q->height()) < dragMargin; + } + + return overThreshold; +} + bool QQuickDrawerPrivate::handleMousePressEvent(QQuickItem *item, QMouseEvent *event) { pressPoint = event->windowPos(); @@ -217,40 +248,16 @@ bool QQuickDrawerPrivate::handleMousePressEvent(QQuickItem *item, QMouseEvent *e bool QQuickDrawerPrivate::handleMouseMoveEvent(QQuickItem *item, QMouseEvent *event) { Q_Q(QQuickDrawer); - QQuickWindow *window = item->window(); - if (!window) - return false; + Q_UNUSED(item); - QPointF movePoint = event->windowPos(); - - if (!popupItem->keepMouseGrab()) { - // Flickable uses a hard-coded threshold of 15 for flicking, and - // QStyleHints::startDragDistance for dragging. Drawer uses a bit - // larger threshold to avoid being too eager to steal touch (QTBUG-50045) - int threshold = qMax(20, QGuiApplication::styleHints()->startDragDistance() + 5); - 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); - else - overThreshold = dragOverThreshold(movePoint.y() - pressPoint.y(), Qt::YAxis, event, threshold); - } + const QPointF movePoint = event->windowPos(); - // Don't be too eager to steal presses outside the drawer (QTBUG-53929) - if (overThreshold && qFuzzyCompare(position, qreal(1.0)) && !popupItem->contains(popupItem->mapFromScene(movePoint))) { - if (edge == Qt::LeftEdge || edge == Qt::RightEdge) - overThreshold = qAbs(movePoint.x() - q->width()) < dragMargin; - else - overThreshold = qAbs(movePoint.y() - q->height()) < dragMargin; - } - - if (overThreshold) { - QQuickItem *grabber = window->mouseGrabberItem(); - if (!grabber || !grabber->keepMouseGrab()) { - popupItem->grabMouse(); - popupItem->setKeepMouseGrab(overThreshold); - offset = qMin<qreal>(0.0, positionAt(movePoint) - position); - } + if (grabMouse(event)) { + QQuickItem *grabber = window->mouseGrabberItem(); + if (!grabber || !grabber->keepMouseGrab()) { + popupItem->grabMouse(); + popupItem->setKeepMouseGrab(true); + offset = qMin<qreal>(0.0, positionAt(movePoint) - position); } } diff --git a/src/quicktemplates2/qquickdrawer_p_p.h b/src/quicktemplates2/qquickdrawer_p_p.h index 2cf752d5..323ba319 100644 --- a/src/quicktemplates2/qquickdrawer_p_p.h +++ b/src/quicktemplates2/qquickdrawer_p_p.h @@ -70,6 +70,7 @@ public: void reposition() override; bool startDrag(QQuickWindow *window, QMouseEvent *event); + bool grabMouse(QMouseEvent *event); bool handleMousePressEvent(QQuickItem *item, QMouseEvent *event); bool handleMouseMoveEvent(QQuickItem *item, QMouseEvent *event); |