summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quicktemplates2/qquickdrawer.cpp18
-rw-r--r--tests/auto/qquickdrawer/data/slider.qml74
-rw-r--r--tests/auto/qquickdrawer/tst_qquickdrawer.cpp55
3 files changed, 139 insertions, 8 deletions
diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp
index 202d02d1..2d60e649 100644
--- a/src/quicktemplates2/qquickdrawer.cpp
+++ b/src/quicktemplates2/qquickdrawer.cpp
@@ -319,12 +319,17 @@ bool QQuickDrawerPrivate::startDrag(QEvent *event)
return false;
}
+static inline bool keepGrab(QQuickItem *item)
+{
+ return item->keepMouseGrab() || item->keepTouchGrab();
+}
+
bool QQuickDrawerPrivate::grabMouse(QQuickItem *item, QMouseEvent *event)
{
Q_Q(QQuickDrawer);
handleMouseEvent(item, event);
- if (!window || !interactive || popupItem->keepMouseGrab() || popupItem->keepTouchGrab())
+ if (!window || !interactive || keepGrab(popupItem) || keepGrab(item))
return false;
const QPointF movePoint = event->windowPos();
@@ -352,12 +357,9 @@ bool QQuickDrawerPrivate::grabMouse(QQuickItem *item, QMouseEvent *event)
}
if (overThreshold) {
- QQuickItem *grabber = window->mouseGrabberItem();
- if (!grabber || !grabber->keepMouseGrab()) {
- popupItem->grabMouse();
- popupItem->setKeepMouseGrab(true);
- offset = offsetAt(movePoint);
- }
+ popupItem->grabMouse();
+ popupItem->setKeepMouseGrab(true);
+ offset = offsetAt(movePoint);
}
return overThreshold;
@@ -369,7 +371,7 @@ bool QQuickDrawerPrivate::grabTouch(QQuickItem *item, QTouchEvent *event)
Q_Q(QQuickDrawer);
bool handled = handleTouchEvent(item, event);
- if (!window || !interactive || popupItem->keepTouchGrab() || !event->touchPointStates().testFlag(Qt::TouchPointMoved))
+ if (!window || !interactive || keepGrab(popupItem) || keepGrab(item) || !event->touchPointStates().testFlag(Qt::TouchPointMoved))
return handled;
bool overThreshold = false;
diff --git a/tests/auto/qquickdrawer/data/slider.qml b/tests/auto/qquickdrawer/data/slider.qml
new file mode 100644
index 00000000..595e7091
--- /dev/null
+++ b/tests/auto/qquickdrawer/data/slider.qml
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.9
+import QtQuick.Controls 2.0
+
+ApplicationWindow {
+ width: 400
+ height: 400
+
+ property alias drawer: drawer
+ property alias slider: slider
+
+ Drawer {
+ id: drawer
+ width: 300
+ height: 400
+ position: 1.0
+ visible: true
+
+ Slider {
+ id: slider
+ value: 1
+ width: parent.width
+ }
+ }
+}
diff --git a/tests/auto/qquickdrawer/tst_qquickdrawer.cpp b/tests/auto/qquickdrawer/tst_qquickdrawer.cpp
index 60c5b189..bba1cf45 100644
--- a/tests/auto/qquickdrawer/tst_qquickdrawer.cpp
+++ b/tests/auto/qquickdrawer/tst_qquickdrawer.cpp
@@ -106,6 +106,9 @@ private slots:
void nonModal_data();
void nonModal();
+ void slider_data();
+ void slider();
+
private:
struct TouchDeviceDeleter
{
@@ -1257,6 +1260,58 @@ void tst_QQuickDrawer::nonModal()
QVERIFY(closedSpy.wait());
}
+void tst_QQuickDrawer::slider_data()
+{
+ QTest::addColumn<bool>("mouse");
+ QTest::newRow("mouse") << true;
+ QTest::newRow("touch") << false;
+}
+
+void tst_QQuickDrawer::slider()
+{
+ QFETCH(bool, mouse);
+
+ QQuickApplicationHelper helper(this, QStringLiteral("slider.qml"));
+ QQuickWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QQuickDrawer *drawer = window->property("drawer").value<QQuickDrawer *>();
+ QVERIFY(drawer);
+
+ QQuickSlider *slider = window->property("slider").value<QQuickSlider *>();
+ QVERIFY(slider);
+
+ QCOMPARE(slider->value(), 1.0);
+ QCOMPARE(drawer->position(), 1.0);
+
+ const qreal y = slider->height() / 2;
+ const QPoint from(slider->width() - 1, y);
+ const QPoint to(1, y);
+
+ if (mouse)
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, from);
+ else
+ QTest::touchEvent(window, touchDevice.data()).press(0, from);
+
+ int distance = qAbs(from.x() - to.x());
+ for (int dx = 2; dx < distance; dx += 2) {
+ if (mouse)
+ QTest::mouseMove(window, from - QPoint(dx, 0));
+ else
+ QTest::touchEvent(window, touchDevice.data()).move(0, from - QPoint(dx, 0));
+ QTest::qWait(1); // avoid infinite velocity
+ }
+
+ QCOMPARE(slider->value(), 0.0);
+ QCOMPARE(drawer->position(), 1.0);
+
+ if (mouse)
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, to);
+ else
+ QTest::touchEvent(window, touchDevice.data()).release(0, to);
+}
+
QTEST_QUICKCONTROLS_MAIN(tst_QQuickDrawer)
#include "tst_qquickdrawer.moc"