From 0764003773e3db3ffdd76021f1a17359cb52452c Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 8 Aug 2016 20:50:13 +0200 Subject: AppWindow: take header & footer visibility into account in relayout() Task-number: QTBUG-55143 Change-Id: I2acf8ca720df33a0417d850b5b0410ec9166dc89 Reviewed-by: Mitch Curtis --- tests/auto/applicationwindow/data/layout.qml | 51 ++++++++++++++++++++++ .../applicationwindow/tst_applicationwindow.cpp | 48 ++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 tests/auto/applicationwindow/data/layout.qml (limited to 'tests/auto/applicationwindow') diff --git a/tests/auto/applicationwindow/data/layout.qml b/tests/auto/applicationwindow/data/layout.qml new file mode 100644 index 00000000..2174b78e --- /dev/null +++ b/tests/auto/applicationwindow/data/layout.qml @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** 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 QtQuick.Controls 2.0 + +ApplicationWindow { + width: 200 + height: 200 + visible: true + + header: ToolBar { } + footer: ToolBar { } +} diff --git a/tests/auto/applicationwindow/tst_applicationwindow.cpp b/tests/auto/applicationwindow/tst_applicationwindow.cpp index bec8aa81..02528fdc 100644 --- a/tests/auto/applicationwindow/tst_applicationwindow.cpp +++ b/tests/auto/applicationwindow/tst_applicationwindow.cpp @@ -72,6 +72,7 @@ private slots: void activeFocusControl_data(); void activeFocusControl(); void focusAfterPopupClosed(); + void layout(); }; void tst_applicationwindow::qmlCreation() @@ -684,6 +685,53 @@ void tst_applicationwindow::focusAfterPopupClosed() QCOMPARE(spy.count(), 2); } +void tst_applicationwindow::layout() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("layout.qml")); + QScopedPointer object(component.create()); + QVERIFY(!object.isNull()); + + QQuickApplicationWindow* window = qobject_cast(object.data()); + QVERIFY(window); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickItem *content = window->contentItem(); + QVERIFY(content); + QQuickItem *header = window->header(); + QVERIFY(header); + QQuickItem *footer = window->footer(); + QVERIFY(footer); + + QCOMPARE(header->x(), 0.0); + QCOMPARE(header->y(), -header->height()); + QCOMPARE(header->width(), qreal(window->width())); + QVERIFY(header->height() > 0); + + QCOMPARE(footer->x(), 0.0); + QCOMPARE(footer->y(), content->height()); + QCOMPARE(footer->width(), qreal(window->width())); + QVERIFY(footer->height() > 0.0); + + QCOMPARE(content->x(), 0.0); + QCOMPARE(content->y(), header->height()); + QCOMPARE(content->width(), qreal(window->width())); + QCOMPARE(content->height(), window->height() - header->height() - footer->height()); + + header->setVisible(false); + QCOMPARE(content->x(), 0.0); + QCOMPARE(content->y(), 0.0); + QCOMPARE(content->width(), qreal(window->width())); + QCOMPARE(content->height(), window->height() - footer->height()); + + footer->setVisible(false); + QCOMPARE(content->x(), 0.0); + QCOMPARE(content->y(), 0.0); + QCOMPARE(content->width(), qreal(window->width())); + QCOMPARE(content->height(), qreal(window->height())); +} + QTEST_MAIN(tst_applicationwindow) #include "tst_applicationwindow.moc" -- cgit v1.2.3