summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Mardegan <mardy@users.sourceforge.net>2015-11-12 01:56:30 +0200
committerShawn Rutledge <shawn.rutledge@theqtcompany.com>2016-04-13 20:15:18 +0000
commit10f0ae7c571b7e0de41d5fdc5627db6a1ddeb926 (patch)
tree622ecd0110a02a3b2cdc5d52f1b8aeb08639f1f2
parent726b6ee9b43652ef198a7df590b08e641dd69377 (diff)
downloadqtquickcontrols-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>
-rw-r--r--src/dialogs/DefaultDialogWrapper.qml22
-rw-r--r--tests/auto/dialogs/data/DialogImplicitSize.qml60
-rw-r--r--tests/auto/dialogs/data/DialogMinimumSize.qml63
-rw-r--r--tests/auto/dialogs/dialogs.pro2
-rw-r--r--tests/auto/dialogs/tst_dialogs.cpp61
5 files changed, 201 insertions, 7 deletions
diff --git a/src/dialogs/DefaultDialogWrapper.qml b/src/dialogs/DefaultDialogWrapper.qml
index a34ee97d..531b5c02 100644
--- a/src/dialogs/DefaultDialogWrapper.qml
+++ b/src/dialogs/DefaultDialogWrapper.qml
@@ -50,13 +50,14 @@ AbstractDialog {
id: content
property real spacing: 6
property real outerSpacing: 12
- property real buttonsRowImplicitWidth: minimumWidth
+ property real buttonsRowImplicitHeight: 0
+ property real buttonsRowImplicitWidth: Screen.pixelDensity * 50
property bool buttonsInSingleRow: defaultContentItem.width >= buttonsRowImplicitWidth
property real minimumHeight: implicitHeight
- property real minimumWidth: Screen.pixelDensity * 50
- implicitHeight: defaultContentItem.implicitHeight + spacing + outerSpacing * 2 + buttonsRight.implicitHeight
+ property real minimumWidth: implicitWidth
+ implicitHeight: defaultContentItem.implicitHeight + spacing + outerSpacing * 2 + Math.max(buttonsRight.implicitHeight, buttonsRowImplicitHeight)
implicitWidth: Math.min(root.__maximumDimension, Math.max(
- defaultContentItem.implicitWidth, buttonsRowImplicitWidth, Screen.pixelDensity * 50) + outerSpacing * 2);
+ defaultContentItem.implicitWidth, buttonsRowImplicitWidth, Screen.pixelDensity * 50) + outerSpacing * 2)
color: palette.window
Keys.onPressed: {
event.accepted = true
@@ -82,9 +83,14 @@ AbstractDialog {
left: parent.left
right: parent.right
top: parent.top
+ bottom: buttonsLeft.implicitHeight ? buttonsLeft.top : buttonsRight.top
margins: content.outerSpacing
+ bottomMargin: buttonsLeft.implicitHeight + buttonsRight.implicitHeight > 0 ? content.spacing : 0
}
- implicitHeight: childrenRect.height
+ implicitHeight: children.length === 1 ? children[0].implicitHeight
+ : (children.length ? childrenRect.height : 0)
+ implicitWidth: children.length === 1 ? children[0].implicitWidth
+ : (children.length ? childrenRect.width : 0)
}
Flow {
@@ -135,7 +141,9 @@ AbstractDialog {
function setupButtons() {
buttonsLeftRepeater.model = root.__standardButtonsLeftModel()
buttonsRightRepeater.model = root.__standardButtonsRightModel()
- if (buttonsLeftRepeater.count + buttonsRightRepeater.count < 2)
+ if (buttonsRightRepeater.model && buttonsRightRepeater.model.length > 0)
+ content.buttonsRowImplicitHeight = buttonsRight.visibleChildren[0].implicitHeight
+ if (buttonsLeftRepeater.count + buttonsRightRepeater.count < 1)
return;
var calcWidth = 0;
@@ -150,7 +158,7 @@ AbstractDialog {
for (var i = 0; i < buttonsRight.visibleChildren.length; ++i)
calculateForButton(i, buttonsRight.visibleChildren[i])
- content.minimumWidth = calcWidth + content.outerSpacing * 2
+ content.minimumWidth = Math.max(calcWidth + content.outerSpacing * 2, content.implicitWidth)
for (i = 0; i < buttonsLeft.visibleChildren.length; ++i)
calculateForButton(i, buttonsLeft.visibleChildren[i])
content.buttonsRowImplicitWidth = calcWidth + content.spacing
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;