diff options
author | Alberto Mardegan <mardy@users.sourceforge.net> | 2015-11-12 01:56:30 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@theqtcompany.com> | 2016-04-13 20:15:18 +0000 |
commit | 10f0ae7c571b7e0de41d5fdc5627db6a1ddeb926 (patch) | |
tree | 622ecd0110a02a3b2cdc5d52f1b8aeb08639f1f2 /tests/auto/dialogs | |
parent | 726b6ee9b43652ef198a7df590b08e641dd69377 (diff) | |
download | qtquickcontrols-10f0ae7c571b7e0de41d5fdc5627db6a1ddeb926.tar.gz |
Dialog: allow proper resize and default size for content
Currently Dialog use implicitly positioned items as content. This makes
impossible to use item, that can be properly resized with change of
dialog window size and has proper default size (set implicit width and
height).
This change made it use implicit size if there is one item or fallback
to previous algorithm, that use childrenRect for explicitly sized and
positioned items, so it won't break behavior of the existing
applications.
[ChangeLog][Dialog] Proper resize and default size for content
Task-number: QTBUG-49058
Change-Id: I7fa4da7d5fd39d47f60ba9f43c88f78e75739b0a
Initial-patch-by: Nikita Krupenko <krnekit@gmail.com>
Reviewed-by: Nikita Krupenko <krnekit@gmail.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
Diffstat (limited to 'tests/auto/dialogs')
-rw-r--r-- | tests/auto/dialogs/data/DialogImplicitSize.qml | 60 | ||||
-rw-r--r-- | tests/auto/dialogs/data/DialogMinimumSize.qml | 63 | ||||
-rw-r--r-- | tests/auto/dialogs/dialogs.pro | 2 | ||||
-rw-r--r-- | tests/auto/dialogs/tst_dialogs.cpp | 61 |
4 files changed, 186 insertions, 0 deletions
diff --git a/tests/auto/dialogs/data/DialogImplicitSize.qml b/tests/auto/dialogs/data/DialogImplicitSize.qml new file mode 100644 index 00000000..8239c451 --- /dev/null +++ b/tests/auto/dialogs/data/DialogImplicitSize.qml @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** 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: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.3 +import QtQuick.Controls 1.2 +import QtQuick.Dialogs 1.2 + +Dialog { + visible: true + title: "Blue sky dialog" + standardButtons: buttonsFromTest + + Rectangle { + color: "lightskyblue" + implicitWidth: 400 + implicitHeight: 150 + Text { + text: "Hello blue sky!" + color: "navy" + anchors.centerIn: parent + } + } +} diff --git a/tests/auto/dialogs/data/DialogMinimumSize.qml b/tests/auto/dialogs/data/DialogMinimumSize.qml new file mode 100644 index 00000000..7f5baa63 --- /dev/null +++ b/tests/auto/dialogs/data/DialogMinimumSize.qml @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** 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: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.3 +import QtQuick.Controls 1.2 +import QtQuick.Dialogs 1.2 + +Dialog { + visible: true + title: "Blue sky dialog" + width: 400 + height: 300 + + Rectangle { + objectName: "userContent" + anchors.fill: parent + implicitWidth: 10 + implicitHeight: 10 + color: "lightskyblue" + Text { + text: "Hello blue sky!" + color: "navy" + anchors.centerIn: parent + } + } +} diff --git a/tests/auto/dialogs/dialogs.pro b/tests/auto/dialogs/dialogs.pro index cf46bed1..3128bb72 100644 --- a/tests/auto/dialogs/dialogs.pro +++ b/tests/auto/dialogs/dialogs.pro @@ -2,6 +2,8 @@ CONFIG += testcase TARGET = tst_dialogs SOURCES += tst_dialogs.cpp +INCLUDEPATH += $$PWD/../../../src/dialogs + include (../shared/util.pri) osx:CONFIG -= app_bundle diff --git a/tests/auto/dialogs/tst_dialogs.cpp b/tests/auto/dialogs/tst_dialogs.cpp index e59c5ea0..28405452 100644 --- a/tests/auto/dialogs/tst_dialogs.cpp +++ b/tests/auto/dialogs/tst_dialogs.cpp @@ -36,6 +36,10 @@ #include <qtest.h> #include "../shared/util.h" +#include "qquickabstractdialog_p.h" +#include <QtQml/QQmlComponent> +#include <QtQml/QQmlContext> +#include <QtQml/QQmlEngine> #include <QtQuick/QQuickItem> #include <QtQuick/QQuickView> #include <QSignalSpy> @@ -51,6 +55,11 @@ private slots: QQmlDataTest::initTestCase(); } + //Dialog + void dialogImplicitWidth_data(); + void dialogImplicitWidth(); + void dialogContentResize(); + // FileDialog void fileDialogDefaultModality(); void fileDialogNonModal(); @@ -59,6 +68,58 @@ private slots: private: }; +void tst_dialogs::dialogImplicitWidth_data() +{ + QTest::addColumn<int>("standardButtons"); + QTest::addColumn<int>("minimumHeight"); + + QTest::newRow("No buttons") << + int(QQuickAbstractDialog::NoButton) << + 150; + QTest::newRow("OK button") << + int(QQuickAbstractDialog::Ok) << + 160; +} + +void tst_dialogs::dialogImplicitWidth() +{ + QFETCH(int, standardButtons); + QFETCH(int, minimumHeight); + + /* This is the outerSpacing from DefaultDialogWrapper.qml, + * which is always present */ + int heightMargins = 12 * 2; + QQmlEngine engine; + engine.rootContext()->setContextProperty("buttonsFromTest", standardButtons); + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("DialogImplicitSize.qml")); + QObject *created = component.create(); + QScopedPointer<QObject> cleanup(created); + QVERIFY(created); + + QTRY_VERIFY(created->property("width").toInt() >= 400); + QTRY_VERIFY(created->property("height").toInt() >= minimumHeight + heightMargins); +} + +void tst_dialogs::dialogContentResize() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("DialogMinimumSize.qml")); + QObject *created = component.create(); + QScopedPointer<QObject> cleanup(created); + QVERIFY(created); + + QTRY_COMPARE(created->property("width").toInt(), 400); + QTRY_COMPARE(created->property("height").toInt(), 300); + + // Check that the content item has been sized up from its implicit size + QQuickItem *userContent = created->findChild<QQuickItem*>("userContent"); + QVERIFY(userContent); + QVERIFY(userContent->width() > 350); + QVERIFY(userContent->height() > 200); +} + void tst_dialogs::fileDialogDefaultModality() { QQuickView *window = new QQuickView; |