aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-04-21 11:29:35 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-04-21 14:08:48 +0000
commit00e81ce7a2a2b2f376a105089c861b1a0802c8dc (patch)
tree1389c2fb83d3c3cb93eebd4531a0f13c6c006821
parent231b97436c62091d85405dc513a878c361ddf38a (diff)
Fix QQuickDrawerPrivate::positionAt()
The position on the right and bottom edges is relative to the size of the window, not the drawer itself. Change-Id: Ia1d7418d4091a3a9e26f691bd75448023e0ca1cf Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
-rw-r--r--.gitignore1
-rw-r--r--src/quicktemplates2/qquickdrawer.cpp8
-rw-r--r--tests/auto/auto.pro1
-rw-r--r--tests/auto/drawer/data/applicationwindow.qml55
-rw-r--r--tests/auto/drawer/drawer.pro14
-rw-r--r--tests/auto/drawer/tst_drawer.cpp95
6 files changed, 172 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index dd7f598a..b708509e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,6 +16,7 @@
/tests/auto/applicationwindow/tst_applicationwindow
/tests/auto/calendar/tst_calendar
/tests/auto/controls/tst_controls
+/tests/auto/drawer/tst_drawer
/tests/auto/focus/tst_focus
/tests/auto/material/tst_material
/tests/auto/menu/tst_menu
diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp
index 1ebdc035..03206eb5 100644
--- a/src/quicktemplates2/qquickdrawer.cpp
+++ b/src/quicktemplates2/qquickdrawer.cpp
@@ -116,15 +116,19 @@ public:
qreal QQuickDrawerPrivate::positionAt(const QPointF &point) const
{
Q_Q(const QQuickDrawer);
+ QQuickWindow *window = q->window();
+ if (!window)
+ return 0;
+
switch (edge) {
case Qt::TopEdge:
return point.y() / q->height();
case Qt::LeftEdge:
return point.x() / q->width();
case Qt::RightEdge:
- return (q->width() - point.x()) / popupItem->width();
+ return (window->width() - point.x()) / q->width();
case Qt::BottomEdge:
- return (q->height() - point.y()) / popupItem->height();
+ return (window->height() - point.y()) / q->height();
default:
return 0;
}
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 311f97dc..569ca811 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -4,6 +4,7 @@ SUBDIRS += \
applicationwindow \
calendar \
controls \
+ drawer \
material \
menu \
popup \
diff --git a/tests/auto/drawer/data/applicationwindow.qml b/tests/auto/drawer/data/applicationwindow.qml
new file mode 100644
index 00000000..66e7e9df
--- /dev/null
+++ b/tests/auto/drawer/data/applicationwindow.qml
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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.6
+import Qt.labs.controls 1.0
+
+ApplicationWindow {
+ width: 400
+ height: 400
+
+ property alias drawer: drawer
+
+ Drawer {
+ id: drawer
+ width: 200
+ height: 200
+ }
+}
diff --git a/tests/auto/drawer/drawer.pro b/tests/auto/drawer/drawer.pro
new file mode 100644
index 00000000..95ed44e9
--- /dev/null
+++ b/tests/auto/drawer/drawer.pro
@@ -0,0 +1,14 @@
+CONFIG += testcase
+TARGET = tst_drawer
+SOURCES += tst_drawer.cpp
+
+osx:CONFIG -= app_bundle
+
+QT += core-private gui-private qml-private quick-private testlib quicktemplates2-private
+
+include (../shared/util.pri)
+
+TESTDATA = data/*
+
+OTHER_FILES += \
+ data/*
diff --git a/tests/auto/drawer/tst_drawer.cpp b/tests/auto/drawer/tst_drawer.cpp
new file mode 100644
index 00000000..557064a6
--- /dev/null
+++ b/tests/auto/drawer/tst_drawer.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/qtest.h>
+#include <QtTest/qsignalspy.h>
+#include "../shared/util.h"
+#include "../shared/visualtestutil.h"
+
+#include <QtQuickTemplates2/private/qquickapplicationwindow_p.h>
+#include <QtQuickTemplates2/private/qquickdrawer_p.h>
+
+using namespace QQuickVisualTestUtil;
+
+class tst_Drawer : public QQmlDataTest
+{
+ Q_OBJECT
+
+private slots:
+ void position_data();
+ void position();
+};
+
+void tst_Drawer::position_data()
+{
+ QTest::addColumn<Qt::Edge>("edge");
+ QTest::addColumn<QPoint>("from");
+ QTest::addColumn<QPoint>("to");
+ QTest::addColumn<qreal>("position");
+
+ QTest::newRow("top") << Qt::TopEdge << QPoint(100, 0) << QPoint(100, 100) << qreal(0.5);
+ QTest::newRow("left") << Qt::LeftEdge << QPoint(0, 100) << QPoint(100, 100) << qreal(0.5);
+ QTest::newRow("right") << Qt::RightEdge << QPoint(399, 100) << QPoint(300, 100) << qreal(0.5);
+ QTest::newRow("bottom") << Qt::BottomEdge << QPoint(100, 399) << QPoint(100, 300) << qreal(0.5);
+}
+
+void tst_Drawer::position()
+{
+ QFETCH(Qt::Edge, edge);
+ QFETCH(QPoint, from);
+ QFETCH(QPoint, to);
+ QFETCH(qreal, position);
+
+ 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);
+
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, from);
+ QTest::mouseMove(window, to);
+ QCOMPARE(drawer->position(), position);
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, to);
+}
+
+QTEST_MAIN(tst_Drawer)
+
+#include "tst_drawer.moc"