diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-04-21 11:31:26 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-04-21 14:08:55 +0000 |
commit | b44194ecc62e7c2d51a90bad17a41451319f7c1f (patch) | |
tree | 5b866b24bbc827e139c52d0a3d8087ac0c0ccf50 /src | |
parent | 00e81ce7a2a2b2f376a105089c861b1a0802c8dc (diff) |
Add Drawer::dragMargin
Allows controlling "sensitivity" of the edge drag, or disabling
(dragMargin<=0) the entire drag operation if preferred.
Change-Id: Icfe6f186704ca7f11abc66abeec603f29345af98
Task-number: QTBUG-52730
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/quicktemplates2/qquickdrawer.cpp | 42 | ||||
-rw-r--r-- | src/quicktemplates2/qquickdrawer_p.h | 6 |
2 files changed, 43 insertions, 5 deletions
diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp index 03206eb5..5c21e163 100644 --- a/src/quicktemplates2/qquickdrawer.cpp +++ b/src/quicktemplates2/qquickdrawer.cpp @@ -92,7 +92,8 @@ class QQuickDrawerPrivate : public QQuickPopupPrivate, public QQuickItemChangeLi Q_DECLARE_PUBLIC(QQuickDrawer) public: - QQuickDrawerPrivate() : edge(Qt::LeftEdge), offset(0), position(0) { } + QQuickDrawerPrivate() : edge(Qt::LeftEdge), offset(0), position(0), + dragMargin(QGuiApplication::styleHints()->startDragDistance()) { } qreal positionAt(const QPointF &point) const; void reposition() override; @@ -109,6 +110,7 @@ public: Qt::Edge edge; qreal offset; qreal position; + qreal dragMargin; QPointF pressPoint; QQuickVelocityCalculator velocityCalculator; }; @@ -175,16 +177,16 @@ bool QQuickDrawerPrivate::handleMousePressEvent(QQuickItem *item, QMouseEvent *e // only accept pressing at drag margins when fully closed switch (edge) { case Qt::LeftEdge: - event->setAccepted(!dragOverThreshold(event->windowPos().x(), Qt::XAxis, event)); + event->setAccepted(dragMargin > 0 && !dragOverThreshold(event->windowPos().x(), Qt::XAxis, event, dragMargin)); break; case Qt::RightEdge: - event->setAccepted(!dragOverThreshold(window->width() - event->windowPos().x(), Qt::XAxis, event)); + event->setAccepted(dragMargin > 0 && !dragOverThreshold(window->width() - event->windowPos().x(), Qt::XAxis, event, dragMargin)); break; case Qt::TopEdge: - event->setAccepted(!dragOverThreshold(event->windowPos().y(), Qt::YAxis, event)); + event->setAccepted(dragMargin > 0 && !dragOverThreshold(event->windowPos().y(), Qt::YAxis, event, dragMargin)); break; case Qt::BottomEdge: - event->setAccepted(!dragOverThreshold(window->height() - event->windowPos().y(), Qt::YAxis, event)); + event->setAccepted(dragMargin > 0 && !dragOverThreshold(window->height() - event->windowPos().y(), Qt::YAxis, event, dragMargin)); break; } } else { @@ -391,6 +393,36 @@ void QQuickDrawer::setPosition(qreal position) emit positionChanged(); } +/*! + \qmlproperty real Qt.labs.controls::Drawer::dragMargin + + This property holds the distance from the screen edge within which + drag actions will open the drawer. Setting the value to \c 0 or less + prevents opening the drawer by dragging. + + The default value is \c Qt.styleHints.startDragDistance. +*/ +qreal QQuickDrawer::dragMargin() const +{ + Q_D(const QQuickDrawer); + return d->dragMargin; +} + +void QQuickDrawer::setDragMargin(qreal margin) +{ + Q_D(QQuickDrawer); + if (qFuzzyCompare(d->dragMargin, margin)) + return; + + d->dragMargin = margin; + emit dragMarginChanged(); +} + +void QQuickDrawer::resetDragMargin() +{ + setDragMargin(QGuiApplication::styleHints()->startDragDistance()); +} + bool QQuickDrawer::childMouseEventFilter(QQuickItem *child, QEvent *event) { Q_D(QQuickDrawer); diff --git a/src/quicktemplates2/qquickdrawer_p.h b/src/quicktemplates2/qquickdrawer_p.h index c2c44efe..5dd9d974 100644 --- a/src/quicktemplates2/qquickdrawer_p.h +++ b/src/quicktemplates2/qquickdrawer_p.h @@ -59,6 +59,7 @@ class Q_QUICKTEMPLATES2_EXPORT QQuickDrawer : public QQuickPopup Q_OBJECT Q_PROPERTY(Qt::Edge edge READ edge WRITE setEdge NOTIFY edgeChanged FINAL) Q_PROPERTY(qreal position READ position WRITE setPosition NOTIFY positionChanged FINAL) + Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin RESET resetDragMargin NOTIFY dragMarginChanged FINAL) public: explicit QQuickDrawer(QObject *parent = nullptr); @@ -69,9 +70,14 @@ public: qreal position() const; void setPosition(qreal position); + qreal dragMargin() const; + void setDragMargin(qreal margin); + void resetDragMargin(); + Q_SIGNALS: void edgeChanged(); void positionChanged(); + void dragMarginChanged(); protected: bool childMouseEventFilter(QQuickItem *child, QEvent *event) override; |