aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quicktemplates2/qquickdrawer.cpp42
-rw-r--r--src/quicktemplates2/qquickdrawer_p.h6
-rw-r--r--tests/auto/controls/data/tst_drawer.qml1
-rw-r--r--tests/auto/drawer/tst_drawer.cpp60
4 files changed, 104 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;
diff --git a/tests/auto/controls/data/tst_drawer.qml b/tests/auto/controls/data/tst_drawer.qml
index 83e04187..72bf6e76 100644
--- a/tests/auto/controls/data/tst_drawer.qml
+++ b/tests/auto/controls/data/tst_drawer.qml
@@ -59,6 +59,7 @@ TestCase {
var control = drawer.createObject(testCase)
compare(control.edge, Qt.LeftEdge)
compare(control.position, 0.0)
+ compare(control.dragMargin, Qt.styleHints.startDragDistance)
control.destroy()
}
diff --git a/tests/auto/drawer/tst_drawer.cpp b/tests/auto/drawer/tst_drawer.cpp
index 557064a6..6a19af91 100644
--- a/tests/auto/drawer/tst_drawer.cpp
+++ b/tests/auto/drawer/tst_drawer.cpp
@@ -39,6 +39,8 @@
#include "../shared/util.h"
#include "../shared/visualtestutil.h"
+#include <QtGui/qstylehints.h>
+#include <QtGui/qguiapplication.h>
#include <QtQuickTemplates2/private/qquickapplicationwindow_p.h>
#include <QtQuickTemplates2/private/qquickdrawer_p.h>
@@ -51,6 +53,9 @@ class tst_Drawer : public QQmlDataTest
private slots:
void position_data();
void position();
+
+ void dragMargin_data();
+ void dragMargin();
};
void tst_Drawer::position_data()
@@ -90,6 +95,61 @@ void tst_Drawer::position()
QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, to);
}
+void tst_Drawer::dragMargin_data()
+{
+ QTest::addColumn<Qt::Edge>("edge");
+ QTest::addColumn<qreal>("dragMargin");
+ QTest::addColumn<qreal>("dragFromLeft");
+ QTest::addColumn<qreal>("dragFromRight");
+
+ QTest::newRow("left:0") << Qt::LeftEdge << qreal(0) << qreal(0) << qreal(0);
+ QTest::newRow("left:-1") << Qt::LeftEdge << qreal(-1) << qreal(0) << qreal(0);
+ QTest::newRow("left:startDragDistance") << Qt::LeftEdge << qreal(QGuiApplication::styleHints()->startDragDistance()) << qreal(0.25) << qreal(0);
+ QTest::newRow("left:startDragDistance*2") << Qt::LeftEdge << qreal(QGuiApplication::styleHints()->startDragDistance() * 2) << qreal(0.25) << qreal(0);
+
+ QTest::newRow("right:0") << Qt::RightEdge << qreal(0) << qreal(0) << qreal(0);
+ QTest::newRow("right:-1") << Qt::RightEdge << qreal(-1) << qreal(0) << qreal(0);
+ QTest::newRow("right:startDragDistance") << Qt::RightEdge << qreal(QGuiApplication::styleHints()->startDragDistance()) << qreal(0) << qreal(0.75);
+ QTest::newRow("right:startDragDistance*2") << Qt::RightEdge << qreal(QGuiApplication::styleHints()->startDragDistance() * 2) << qreal(0) << qreal(0.75);
+}
+
+void tst_Drawer::dragMargin()
+{
+ QFETCH(Qt::Edge, edge);
+ QFETCH(qreal, dragMargin);
+ QFETCH(qreal, dragFromLeft);
+ QFETCH(qreal, dragFromRight);
+
+ QQuickApplicationHelper helper(this, QStringLiteral("applicationwindow.qml"));
+
+ QQuickApplicationWindow *window = helper.window;
+ window->show();
+ window->requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QQuickDrawer *drawer = helper.window->property("drawer").value<QQuickDrawer*>();
+ QVERIFY(drawer);
+ drawer->setEdge(edge);
+ drawer->setDragMargin(dragMargin);
+
+ // drag from the left
+ int leftX = qMax<int>(0, dragMargin);
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(leftX, drawer->height() / 2));
+ QTest::mouseMove(window, QPoint(drawer->width() * 0.25, drawer->height() / 2));
+ QCOMPARE(drawer->position(), dragFromLeft);
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(drawer->width() * 0.25, drawer->height() / 2));
+
+ drawer->close();
+ QTRY_COMPARE(drawer->position(), qreal(0.0));
+
+ // drag from the right
+ int rightX = qMin<int>(window->width() - 1, window->width() - dragMargin);
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(rightX, drawer->height() / 2));
+ QTest::mouseMove(window, QPoint(window->width() - drawer->width() * 0.75, drawer->height() / 2));
+ QCOMPARE(drawer->position(), dragFromRight);
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(window->width() - drawer->width() * 0.75, drawer->height() / 2));
+}
+
QTEST_MAIN(tst_Drawer)
#include "tst_drawer.moc"