diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/palette/data/bindings.qml | 95 | ||||
-rw-r--r-- | tests/auto/palette/data/set-palette.qml | 66 | ||||
-rw-r--r-- | tests/auto/palette/tst_palette.cpp | 169 | ||||
-rw-r--r-- | tests/auto/qquickpopup/tst_qquickpopup.cpp | 41 | ||||
-rw-r--r-- | tests/auto/qquickstyle/tst_qquickstyle.cpp | 3 |
5 files changed, 307 insertions, 67 deletions
diff --git a/tests/auto/palette/data/bindings.qml b/tests/auto/palette/data/bindings.qml new file mode 100644 index 00000000..f87b6572 --- /dev/null +++ b/tests/auto/palette/data/bindings.qml @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 6.0 +import QtQuick.Window 2.14 +import QtQuick.Controls 2.14 +import QtQuick.Layouts 1.13 + +ApplicationWindow { + id: window + objectName: "window" + width: 600 + height: 800 + visible: true + + property alias disabledButton: disabledButton + property alias enabledButton: enabledButton + + palette { + active { + button: "khaki" + buttonText: "bisque" + } + + disabled { + buttonText: "lavender" + button: "coral" + } + } + + ColumnLayout { + Button { + id: disabledButton + text: "Disabled" + enabled: false + + palette.disabled.button: "aqua" + palette.disabled.buttonText: "azure" + } + + Button { + id: enabledButton + text: "Enabled" + + palette: disabledButton.palette + } + } +} diff --git a/tests/auto/palette/data/set-palette.qml b/tests/auto/palette/data/set-palette.qml new file mode 100644 index 00000000..f9f067e0 --- /dev/null +++ b/tests/auto/palette/data/set-palette.qml @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 6.0 +import QtQuick.Controls 2.14 + +Control { + palette { + active { + buttonText: "azure" + button: "khaki" + } + + disabled { + buttonText: "lavender" + button: "coral" + } + } +} diff --git a/tests/auto/palette/tst_palette.cpp b/tests/auto/palette/tst_palette.cpp index e91fd732..9d635ff7 100644 --- a/tests/auto/palette/tst_palette.cpp +++ b/tests/auto/palette/tst_palette.cpp @@ -41,11 +41,14 @@ #include <QtGui/private/qguiapplication_p.h> #include <QtQml/qqmlengine.h> #include <QtQml/qqmlcomponent.h> +#include <QtQuick/private/qquickitem_p.h> #include <QtQuickTemplates2/private/qquickapplicationwindow_p.h> #include <QtQuickTemplates2/private/qquickcontrol_p.h> #include <QtQuickTemplates2/private/qquickcontrol_p_p.h> #include <QtQuickTemplates2/private/qquickpopup_p.h> +#include <QtQuickTemplates2/private/qquickpopup_p_p.h> #include <QtQuickTemplates2/private/qquicktheme_p_p.h> +#include <QtQuickTemplates2/private/qquickbutton_p.h> using namespace QQuickVisualTestUtil; @@ -67,6 +70,10 @@ private slots: void listView_data(); void listView(); + + void setDynamicallyCreatedPalette(); + void createBindings(); + void updateBindings(); }; void tst_palette::initTestCase() @@ -136,8 +143,7 @@ void tst_palette::palette() QVariant var = object->property("palette"); QVERIFY(var.isValid()); - QPalette actualPalette = var.value<QPalette>(); - QCOMPARE(actualPalette, expectedPalette); + QCOMPARE(var.value<QQuickPalette*>()->toQPalette(), expectedPalette); } void tst_palette::inheritance_data() @@ -175,55 +181,54 @@ void tst_palette::inheritance() defaultPalette.setColor(QPalette::Base, QColor("#efefef")); defaultPalette.setColor(QPalette::Text, QColor("#101010")); - QCOMPARE(window->palette(), defaultPalette); - - QCOMPARE(control->property("palette").value<QPalette>(), defaultPalette); - QCOMPARE(child->property("palette").value<QPalette>(), defaultPalette); - QCOMPARE(grandChild->property("palette").value<QPalette>(), defaultPalette); - - QPalette childPalette(defaultPalette); - childPalette.setColor(QPalette::Base, Qt::red); - childPalette.setColor(QPalette::Text, Qt::green); - childPalette.setColor(QPalette::Button, Qt::blue); - child->setProperty("palette", childPalette); - QCOMPARE(child->property("palette").value<QPalette>(), childPalette); - QCOMPARE(grandChild->property("palette").value<QPalette>(), childPalette); - - QPalette grandChildPalette(childPalette); - grandChildPalette.setColor(QPalette::Base, Qt::cyan); - grandChildPalette.setColor(QPalette::Mid, Qt::magenta); - grandChild->setProperty("palette", grandChildPalette); - QCOMPARE(child->property("palette").value<QPalette>(), childPalette); - QCOMPARE(grandChild->property("palette").value<QPalette>(), grandChildPalette); - - QPalette windowPalette(defaultPalette); - windowPalette.setColor(QPalette::Window, Qt::gray); - window->setPalette(windowPalette); - QCOMPARE(window->palette(), windowPalette); - QCOMPARE(control->property("palette").value<QPalette>(), windowPalette); - - childPalette.setColor(QPalette::Window, Qt::gray); - QCOMPARE(child->property("palette").value<QPalette>(), childPalette); - - grandChildPalette.setColor(QPalette::Window, Qt::gray); - QCOMPARE(grandChild->property("palette").value<QPalette>(), grandChildPalette); - - child->setProperty("palette", QVariant()); - QCOMPARE(child->property("palette").value<QPalette>(), windowPalette); - QCOMPARE(grandChild->property("palette").value<QPalette>(), grandChildPalette); - - grandChild->setProperty("palette", QVariant()); - QCOMPARE(grandChild->property("palette").value<QPalette>(), windowPalette); + auto windowPalette = QQuickWindowPrivate::get(window.get())->palette(); + + QCOMPARE(windowPalette->toQPalette(), defaultPalette); + + auto controlPalette = control->property("palette").value<QQuickPalette*>(); + auto childPalette = child->property("palette").value<QQuickPalette*>(); + auto grandChildPalette = grandChild->property("palette").value<QQuickPalette*>(); + QVERIFY(controlPalette && childPalette && grandChildPalette); + + QCOMPARE(controlPalette->toQPalette(), defaultPalette); + QCOMPARE(childPalette->toQPalette(), defaultPalette); + QCOMPARE(grandChildPalette->toQPalette(), defaultPalette); + + childPalette->setBase(Qt::red); + childPalette->setText(Qt::green); + childPalette->setButton(Qt::blue); + + QCOMPARE(childPalette->base(), grandChildPalette->base()); + QCOMPARE(childPalette->text(), grandChildPalette->text()); + QCOMPARE(childPalette->button(), grandChildPalette->button()); + + windowPalette->setWindow(Qt::gray); + QCOMPARE(controlPalette->window(), windowPalette->window()); + + childPalette->setWindow(Qt::red); + QCOMPARE(childPalette->window(), Qt::red); + + grandChildPalette->setWindow(Qt::blue); + QCOMPARE(grandChildPalette->window(), Qt::blue); + + auto childMo = child->metaObject(); + childMo->property(childMo->indexOfProperty("palette")).reset(child); + QCOMPARE(childPalette->window(), windowPalette->window()); + QCOMPARE(grandChildPalette->window(), Qt::blue); + + auto grandChildMo = grandChild->metaObject(); + grandChildMo->property(grandChildMo->indexOfProperty("palette")).reset(grandChild); + QCOMPARE(grandChildPalette->window(), windowPalette->window()); } class TestTheme : public QQuickTheme { public: - static const int NPalettes = QQuickTheme::Tumbler + 1; + static const uint NPalettes = QQuickTheme::Tumbler + 1; TestTheme() { - for (int i = 0; i < NPalettes; ++i) + for (uint i = 0; i < NPalettes; ++i) setPalette(static_cast<Scope>(i), QPalette(QColor::fromRgb(i))); } }; @@ -291,6 +296,7 @@ void tst_palette::defaultPalette() // The call to setData() above causes QQuickDefaultTheme to be set as the current theme, // so we must make sure we only set our theme afterwards. + std::unique_ptr<QQuickTheme> oldTheme(QQuickThemePrivate::instance.take()); QQuickThemePrivate::instance.reset(new TestTheme); QScopedPointer<QObject> object(component.create()); @@ -300,8 +306,11 @@ void tst_palette::defaultPalette() QVERIFY(var.isValid()); QPalette expectedPalette = QQuickTheme::palette(scope); - QPalette actualPalette = var.value<QPalette>(); - QCOMPARE(actualPalette, expectedPalette); + auto actualPalette = var.value<QQuickPalette*>(); + QVERIFY(actualPalette); + QCOMPARE(actualPalette->toQPalette(), expectedPalette); + + QQuickThemePrivate::instance.reset(oldTheme.release()); } void tst_palette::listView_data() @@ -342,7 +351,75 @@ void tst_palette::listView() QQuickItem *control = column->property(objectName.toUtf8()).value<QQuickItem *>(); QVERIFY(control); - QCOMPARE(control->property("palette").value<QPalette>().color(QPalette::Highlight), QColor(Qt::red)); + QCOMPARE(QQuickItemPrivate::get(control)->palette()->highlight(), Qt::red); +} + +void tst_palette::setDynamicallyCreatedPalette() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("set-palette.qml")); + + QScopedPointer<QObject> object(component.create()); + QVERIFY2(!object.isNull(), qPrintable(component.errorString())); + + QVariant var = object->property("palette"); + QVERIFY(var.isValid()); + + auto palette = var.value<QQuickPalette*>(); + QVERIFY(palette); + + QCOMPARE(palette->buttonText(), QColor("azure")); + QCOMPARE(palette->button(), QColor("khaki")); + + QCOMPARE(palette->disabled()->buttonText(), QColor("lavender")); + QCOMPARE(palette->disabled()->button(), QColor("coral")); +} + +void tst_palette::createBindings() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("bindings.qml")); + + QScopedPointer<QObject> window(component.create()); + QVERIFY2(!window.isNull(), qPrintable(component.errorString())); + + auto disabledButton = window->property("disabledButton").value<QQuickButton*>(); + QVERIFY(disabledButton); + + auto enabledButton = window->property("enabledButton").value<QQuickButton*>(); + QVERIFY(enabledButton); + + QCOMPARE(QQuickItemPrivate::get(disabledButton)->palette()->button(), QColor("aqua")); + QCOMPARE(QQuickItemPrivate::get(disabledButton)->palette()->buttonText(), QColor("azure")); + + QCOMPARE(QQuickItemPrivate::get(enabledButton)->palette()->button(), QColor("khaki")); + QCOMPARE(QQuickItemPrivate::get(enabledButton)->palette()->buttonText(), QColor("bisque")); + + QCOMPARE(QQuickItemPrivate::get(enabledButton)->palette()->disabled()->button(), QColor("aqua")); + QCOMPARE(QQuickItemPrivate::get(enabledButton)->palette()->disabled()->buttonText(), QColor("azure")); +} + +void tst_palette::updateBindings() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("bindings.qml")); + + QScopedPointer<QObject> window(component.create()); + QVERIFY2(!window.isNull(), qPrintable(component.errorString())); + + auto disabledButton = window->property("disabledButton").value<QQuickButton*>(); + QVERIFY(disabledButton); + + auto enabledButton = window->property("enabledButton").value<QQuickButton*>(); + QVERIFY(enabledButton); + + QQuickItemPrivate::get(disabledButton)->palette()->disabled()->setButton(QColor("navy")); + enabledButton->setEnabled(false); + + QCOMPARE(QQuickItemPrivate::get(enabledButton)->palette()->button(), QColor("navy")); } QTEST_MAIN(tst_palette) diff --git a/tests/auto/qquickpopup/tst_qquickpopup.cpp b/tests/auto/qquickpopup/tst_qquickpopup.cpp index d96436de..0ec7870b 100644 --- a/tests/auto/qquickpopup/tst_qquickpopup.cpp +++ b/tests/auto/qquickpopup/tst_qquickpopup.cpp @@ -42,14 +42,17 @@ #include <QtGui/qpa/qwindowsysteminterface.h> #include <QtQuick/qquickview.h> +#include <QtQuick/private/qquickpalette_p.h> #include <QtQuickTemplates2/private/qquickapplicationwindow_p.h> #include <QtQuickTemplates2/private/qquickcombobox_p.h> #include <QtQuickTemplates2/private/qquickdialog_p.h> #include <QtQuickTemplates2/private/qquickoverlay_p.h> #include <QtQuickTemplates2/private/qquickpopup_p.h> +#include <QtQuickTemplates2/private/qquickpopupitem_p_p.h> #include <QtQuickTemplates2/private/qquickbutton_p.h> #include <QtQuickTemplates2/private/qquickslider_p.h> #include <QtQuickTemplates2/private/qquickstackview_p.h> +#include <QtQuickTemplates2/private/qquickpopup_p_p.h> using namespace QQuickVisualTestUtil; @@ -1174,29 +1177,28 @@ void tst_QQuickPopup::disabledPalette() QQuickPopup *popup = window->property("popup").value<QQuickPopup*>(); QVERIFY(popup); - QSignalSpy popupEnabledSpy(popup, SIGNAL(enabledChanged())); + QSignalSpy popupEnabledSpy(popup, &QQuickPopup::enabledChanged); QVERIFY(popupEnabledSpy.isValid()); - QSignalSpy popupPaletteSpy(popup, SIGNAL(paletteChanged())); + QSignalSpy popupPaletteSpy(popup, &QQuickPopup::paletteChanged); QVERIFY(popupPaletteSpy.isValid()); - QSignalSpy popupItemEnabledSpy(popup->popupItem(), SIGNAL(enabledChanged())); + QSignalSpy popupItemEnabledSpy(popup->popupItem(), &QQuickItem::enabledChanged); QVERIFY(popupItemEnabledSpy.isValid()); - QSignalSpy popupItemPaletteSpy(popup->popupItem(), SIGNAL(paletteChanged())); + QSignalSpy popupItemPaletteSpy(popup->popupItem(), &QQuickItem::paletteChanged); QVERIFY(popupItemPaletteSpy.isValid()); - QPalette palette = popup->palette(); - palette.setColor(QPalette::Active, QPalette::Base, Qt::green); - palette.setColor(QPalette::Disabled, QPalette::Base, Qt::red); - popup->setPalette(palette); - QCOMPARE(popupPaletteSpy.count(), 1); - QCOMPARE(popupItemPaletteSpy.count(), 1); + auto palette = QQuickPopupPrivate::get(popup)->palette(); + palette->setBase(Qt::green); + palette->disabled()->setBase(Qt::red); + QCOMPARE(popupPaletteSpy.count(), 2); + QCOMPARE(popupItemPaletteSpy.count(), 2); QCOMPARE(popup->background()->property("color").value<QColor>(), Qt::green); popup->setEnabled(false); QCOMPARE(popupEnabledSpy.count(), 1); QCOMPARE(popupItemEnabledSpy.count(), 1); - QCOMPARE(popupPaletteSpy.count(), 2); - QCOMPARE(popupItemPaletteSpy.count(), 2); + QCOMPARE(popupPaletteSpy.count(), 3); + QCOMPARE(popupItemPaletteSpy.count(), 3); QCOMPARE(popup->background()->property("color").value<QColor>(), Qt::red); } @@ -1221,12 +1223,11 @@ void tst_QQuickPopup::disabledParentPalette() QSignalSpy popupItemPaletteSpy(popup->popupItem(), SIGNAL(paletteChanged())); QVERIFY(popupItemPaletteSpy.isValid()); - QPalette palette = popup->palette(); - palette.setColor(QPalette::Active, QPalette::Base, Qt::green); - palette.setColor(QPalette::Disabled, QPalette::Base, Qt::red); - popup->setPalette(palette); - QCOMPARE(popupPaletteSpy.count(), 1); - QCOMPARE(popupItemPaletteSpy.count(), 1); + auto palette = QQuickPopupPrivate::get(popup)->palette(); + palette->setBase(Qt::green); + palette->disabled()->setBase(Qt::red); + QCOMPARE(popupPaletteSpy.count(), 2); + QCOMPARE(popupItemPaletteSpy.count(), 2); QCOMPARE(popup->background()->property("color").value<QColor>(), Qt::green); // Disable the overlay (which is QQuickPopupItem's parent) to ensure that @@ -1239,8 +1240,8 @@ void tst_QQuickPopup::disabledParentPalette() QCOMPARE(popup->background()->property("color").value<QColor>(), Qt::red); QCOMPARE(popupEnabledSpy.count(), 1); QCOMPARE(popupItemEnabledSpy.count(), 1); - QCOMPARE(popupPaletteSpy.count(), 2); - QCOMPARE(popupItemPaletteSpy.count(), 2); + QCOMPARE(popupPaletteSpy.count(), 3); + QCOMPARE(popupItemPaletteSpy.count(), 3); popup->close(); QTRY_VERIFY(!popup->isVisible()); diff --git a/tests/auto/qquickstyle/tst_qquickstyle.cpp b/tests/auto/qquickstyle/tst_qquickstyle.cpp index e99dad62..48cc88b7 100644 --- a/tests/auto/qquickstyle/tst_qquickstyle.cpp +++ b/tests/auto/qquickstyle/tst_qquickstyle.cpp @@ -40,6 +40,7 @@ #include <QtQuickControls2/qquickstyle.h> #include <QtQuickControls2/private/qquickstyle_p.h> #include <QtQuickTemplates2/private/qquicklabel_p.h> +#include <QtQuickTemplates2/private/qquicklabel_p_p.h> #include <QtQuickTemplates2/private/qquicktheme_p.h> #include <QtGui/private/qguiapplication_p.h> @@ -152,7 +153,7 @@ void tst_QQuickStyle::configurationFile() // Make it small so that there's less possibility for the default/system // pixel size to match it and give us false positives. QCOMPARE(label->font().pixelSize(), 3); - QCOMPARE(label->palette().windowText(), Qt::red); + QCOMPARE(QQuickLabelPrivate::get(label)->palette()->windowText(), Qt::red); } void tst_QQuickStyle::commandLineArgument() |