diff options
Diffstat (limited to 'tests')
11 files changed, 510 insertions, 7 deletions
diff --git a/tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml b/tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml index 34754420d0..fd62a5693b 100644 --- a/tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml +++ b/tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml @@ -35,6 +35,7 @@ TestCase { Material.accent: Material.DeepPurple Material.background: Material.Green Material.foreground: Material.Blue + Material.roundedScale: Material.SmallScale } } @@ -158,6 +159,8 @@ TestCase { compare(control.Material.foreground, "#dd000000") compare(control.Material.background, "#fafafa") compare(control.Material.theme, Material.Light) + // This doesn't propagate but we check its default anyway. + compare(control.Material.roundedScale, Material.FullScale) } function test_set() { @@ -168,11 +171,13 @@ TestCase { control.Material.background = Material.Red control.Material.foreground = Material.Blue control.Material.theme = Material.Dark + control.Material.roundedScale = Material.SmallScale compare(control.Material.primary, Material.color(Material.Green)) compare(control.Material.accent, Material.color(Material.Brown, themeshade(control.Material.theme))) compare(control.Material.background, Material.color(Material.Red, themeshade(control.Material.theme))) compare(control.Material.foreground, Material.color(Material.Blue)) compare(control.Material.theme, Material.Dark) + compare(control.Material.roundedScale, Material.SmallScale) } function test_reset() { @@ -183,16 +188,21 @@ TestCase { compare(control.Material.background, Material.color(Material.Green, themeshade(control.Material.theme))) compare(control.Material.foreground, Material.color(Material.Blue)) compare(control.Material.theme, Material.Dark) + compare(control.Material.roundedScale, Material.SmallScale) control.Material.primary = undefined control.Material.accent = undefined control.Material.background = undefined control.Material.foreground = undefined control.Material.theme = undefined + control.Material.roundedScale = undefined compare(control.Material.primary, testCase.Material.primary) compare(control.Material.accent, testCase.Material.accent) compare(control.Material.background, testCase.Material.background) compare(control.Material.foreground, testCase.Material.foreground) compare(control.Material.theme, testCase.Material.theme) + // Button's default is FullyRounded, but it specifies that default in QML, + // which means we have no way of knowing how to reset that in resetRoundedScale(). + compare(control.Material.roundedScale, Material.NotRounded) } function test_inheritance_data() { @@ -817,9 +827,6 @@ TestCase { property Component row_foregroundToDividerColor: Item { Material.foreground: Material.dividerColor } property Component row_foregroundToIconColor: Item { Material.foreground: Material.iconColor } property Component row_foregroundToIconDisabledColor: Item { Material.foreground: Material.iconDisabledColor } - property Component row_foregroundToButtonColor: Item { Material.foreground: Material.buttonColor } - property Component row_foregroundToButtonDisabledColor: Item { Material.foreground: Material.buttonDisabledColor } - property Component row_foregroundToHighlightedButtonColor: Item { Material.foreground: Material.highlightedButtonColor } property Component row_foregroundToFrameColor: Item { Material.foreground: Material.frameColor } property Component row_foregroundToRippleColor: Item { Material.foreground: Material.rippleColor } property Component row_foregroundToHighlightedRippleColor: Item { Material.foreground: Material.highlightedRippleColor } diff --git a/tests/auto/quickcontrols/qquickmaterialstyleconf/tst_qquickmaterialstyleconf.cpp b/tests/auto/quickcontrols/qquickmaterialstyleconf/tst_qquickmaterialstyleconf.cpp index 722f846d90..cec4149149 100644 --- a/tests/auto/quickcontrols/qquickmaterialstyleconf/tst_qquickmaterialstyleconf.cpp +++ b/tests/auto/quickcontrols/qquickmaterialstyleconf/tst_qquickmaterialstyleconf.cpp @@ -58,8 +58,8 @@ void tst_qquickmaterialstyleconf::variants_data() // Just to ensure that the correct conf is loaded. QTest::addColumn<QColor>("expectedColor"); - // (36 button height + 12 touchable area) - QTest::newRow("normal") << QByteArray(":/variant-normal.conf") << 48 << QColor::fromRgb(0x123456); + // (40 button height + 12 touchable area) + QTest::newRow("normal") << QByteArray(":/variant-normal.conf") << 52 << QColor::fromRgb(0x123456); // We specified a custom variant (dense), so the button should be small. // (32 button height + 12 touchable area) QTest::newRow("dense") << QByteArray(":/variant-dense.conf") << 44 << QColor::fromRgb(0x789abc); diff --git a/tests/manual/quickcontrols/material/CMakeLists.txt b/tests/manual/quickcontrols/material/CMakeLists.txt new file mode 100644 index 0000000000..1cd3a98d0f --- /dev/null +++ b/tests/manual/quickcontrols/material/CMakeLists.txt @@ -0,0 +1,34 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if (NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(material LANGUAGES C CXX ASM) + find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_manual_test(material + GUI + SOURCES + material.cpp + LIBRARIES + Qt::Gui + Qt::Qml + Qt::QuickControls2 +) + +set(qmake_immediate_resource_files + "material.qml" + "Constants.qml" + "pages/ButtonPage.qml" + "pages/DelayButtonPage.qml" + "pages/RoundButtonPage.qml" + "qmldir" +) + +qt_internal_add_resource(material "qmake_immediate" + PREFIX + "/" + FILES + ${qmake_immediate_resource_files} +) diff --git a/tests/manual/quickcontrols/material/Constants.qml b/tests/manual/quickcontrols/material/Constants.qml new file mode 100644 index 0000000000..51b9b6ff23 --- /dev/null +++ b/tests/manual/quickcontrols/material/Constants.qml @@ -0,0 +1,11 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +pragma Singleton + +import QtQml + +QtObject { + readonly property url iconSource: "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png" + readonly property int pageTopPadding: 20 + readonly property int spacing: 40 +} diff --git a/tests/manual/quickcontrols/material/material.cpp b/tests/manual/quickcontrols/material/material.cpp new file mode 100644 index 0000000000..2e257b0902 --- /dev/null +++ b/tests/manual/quickcontrols/material/material.cpp @@ -0,0 +1,32 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QGuiApplication> +#include <QQmlApplicationEngine> +#include <QSettings> + +int main(int argc, char *argv[]) +{ + QGuiApplication::setApplicationName("material"); + QGuiApplication::setOrganizationName("QtProject"); + + QGuiApplication app(argc, argv); + + const char *variantEnvVar = "QT_QUICK_CONTROLS_MATERIAL_VARIANT"; + if (!qEnvironmentVariableIsSet(variantEnvVar)) { + QSettings settings; + const char *variant = "variant"; + if (settings.contains(variant)) + qputenv(variantEnvVar, settings.value(variant).toByteArray()); + } + + QQmlApplicationEngine engine; + const QUrl url(QStringLiteral("qrc:/material.qml")); + QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, + &app, [url](QObject *obj, const QUrl &objUrl) { + if (!obj && url == objUrl) + QCoreApplication::exit(-1); + }, Qt::QueuedConnection); + engine.load(url); + + return app.exec(); +} diff --git a/tests/manual/quickcontrols/material/material.qml b/tests/manual/quickcontrols/material/material.qml new file mode 100644 index 0000000000..720ff0a5ec --- /dev/null +++ b/tests/manual/quickcontrols/material/material.qml @@ -0,0 +1,126 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +import QtCore +import QtQuick +import QtQuick.Controls.Material +import QtQuick.Layouts + +ApplicationWindow { + id: window + title: "Material" + width: screen.desktopAvailableWidth * 0.8 + height: screen.desktopAvailableHeight * 0.8 + visible: true + + Material.theme: settings.theme + + Settings { + id: settings + + property alias windowX: window.x + property alias windowY: window.y + property alias windowWidth: window.width + property alias windowHeight: window.height + + property int theme: darkThemeSwitch.checked ? Material.Dark : Material.Light + property string variant: denseSwitch.checked ? "Dense" : "Normal" + + property alias currentControlIndex: listView.currentIndex + } + + Shortcut { + sequences: ["Esc", "Back"] + onActivated: openDrawerAction.trigger() + } + + Shortcut { + sequence: "Ctrl+Q" + onActivated: Qt.quit() + } + + Action { + id: openDrawerAction + text: "Controls" + onTriggered: drawer.open() + } + + header: ToolBar { + RowLayout { + spacing: 20 + anchors.fill: parent + + Material.theme: Material.Dark + + ToolButton { + action: openDrawerAction + } + + Label { + id: titleLabel + text: listView.currentItem ? listView.currentItem.text : "Material" + font.pixelSize: 20 + elide: Label.ElideRight + horizontalAlignment: Qt.AlignHCenter + verticalAlignment: Qt.AlignVCenter + Layout.fillWidth: true + } + + Item { + Layout.fillWidth: true + } + + Switch { + id: darkThemeSwitch + text: "Dark" + checked: settings.theme === Material.Dark + } + + Switch { + id: denseSwitch + text: "Dense" + checked: settings.variant === "Dense" + + ToolTip.text: "Requires restart" + ToolTip.visible: hovered + } + } + } + + Drawer { + id: drawer + width: window.width / 3 + height: window.height + interactive: stackView.depth === 1 + + ListView { + id: listView + focus: true + currentIndex: settings.currentControlIndex + anchors.fill: parent + model: ["Button", "DelayButton", "RoundButton"] + delegate: ItemDelegate { + width: listView.width + text: modelData + highlighted: ListView.isCurrentItem + onClicked: listView.currentIndex = index + } + + ScrollIndicator.vertical: ScrollIndicator { } + + // Need to wait until our count is non-zero before setting a default currentIndex. + // This also allows us to use an alias for the settings property. + Component.onCompleted: if (currentIndex === -1) currentIndex = 0 + + onCurrentIndexChanged: { + if (currentIndex >= 0 && currentIndex < count) + stackView.replace("qrc:/pages/" + model[currentIndex] + "Page.qml") + drawer.close() + } + } + } + + StackView { + id: stackView + anchors.fill: parent + } +} diff --git a/tests/manual/quickcontrols/material/pages/ButtonPage.qml b/tests/manual/quickcontrols/material/pages/ButtonPage.qml new file mode 100644 index 0000000000..3f861e7a70 --- /dev/null +++ b/tests/manual/quickcontrols/material/pages/ButtonPage.qml @@ -0,0 +1,125 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +import QtQuick +import QtQuick.Controls.Material +import QtQuick.Layouts + +import ".." + +Page { + topPadding: 20 + + property var backgroundColor + + header: RowLayout { + CheckBox { + id: iconCheckBox + text: "Icon" + } + + CheckBox { + id: disabledCheckBox + text: "Disabled" + } + + Item { + Layout.fillWidth: true + } + } + + component RoundedScaleLayout: ColumnLayout { + id: roundedScaleLayout + enabled: !disabledCheckBox.checked + + property bool allowFlat + property var backgroundColor: undefined + property var foregroundColor: undefined + + property int contentLeftMargin + property int contentRightMargin + + RowLayout { + enabled: roundedScaleLayout.allowFlat + + CheckBox { + id: flatCheckBox + text: "Flat" + + Layout.leftMargin: roundedScaleLayout.contentLeftMargin + } + } + + RowLayout { + spacing: Constants.spacing + + Repeater { + id: roundedScaleRepeater + model: ListModel { + ListElement { displayName: "NotRounded"; roundedScale: Material.NotRounded } + ListElement { displayName: "ExtraSmall"; roundedScale: Material.ExtraSmallScale } + ListElement { displayName: "Small"; roundedScale: Material.SmallScale } + ListElement { displayName: "Medium"; roundedScale: Material.MediumScale } + ListElement { displayName: "Large"; roundedScale: Material.LargeScale } + ListElement { displayName: "ExtraLarge"; roundedScale: Material.ExtraLargeScale } + ListElement { displayName: "Full"; roundedScale: Material.FullScale } + } + + // Workaround for QTBUG-98859. + delegate: Component { + ColumnLayout { + id: scaleLayout + spacing: Constants.spacing + + required property int index + required property string displayName + required property int roundedScale + + Layout.leftMargin: index === 0 ? roundedScaleLayout.contentLeftMargin : 0 + Layout.rightMargin: index === roundedScaleRepeater.count - 1 ? roundedScaleLayout.contentRightMargin : 0 + Layout.bottomMargin: Constants.spacing + + Label { + text: scaleLayout.displayName + + Layout.alignment: Qt.AlignHCenter + } + + Repeater { + model: 13 + + Button { + text: modelData + flat: flatCheckBox.checked + icon.source: iconCheckBox.checked ? "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png" : "" + + Material.background: roundedScaleLayout.backgroundColor + Material.foreground: roundedScaleLayout.foregroundColor + Material.elevation: modelData + Material.roundedScale: scaleLayout.roundedScale + } + } + } + } + } + } + } + + ScrollView { + anchors.fill: parent + + RowLayout { + spacing: Constants.spacing + + RoundedScaleLayout { + contentLeftMargin: Constants.spacing + allowFlat: true + } + + RoundedScaleLayout { + backgroundColor: Material.Teal + foregroundColor: "white" + contentRightMargin: Constants.spacing + } + } + } +} diff --git a/tests/manual/quickcontrols/material/pages/DelayButtonPage.qml b/tests/manual/quickcontrols/material/pages/DelayButtonPage.qml new file mode 100644 index 0000000000..ee9c12f446 --- /dev/null +++ b/tests/manual/quickcontrols/material/pages/DelayButtonPage.qml @@ -0,0 +1,73 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +import QtQuick +import QtQuick.Controls.Material +import QtQuick.Layouts + +import ".." + +Page { + topPadding: 20 + + property var backgroundColor + + header: RowLayout { + CheckBox { + id: disabledCheckBox + text: "Disabled" + } + + Item { + Layout.fillWidth: true + } + } + + component ElevationLayout: ColumnLayout { + id: elevationLayout + enabled: !disabledCheckBox.checked + + property var backgroundColor: undefined + property var foregroundColor: undefined + + property int contentLeftMargin + property int contentRightMargin + + ColumnLayout { + spacing: Constants.spacing + + Repeater { + model: 13 + + DelayButton { + text: modelData + + Material.background: elevationLayout.backgroundColor + Material.foreground: elevationLayout.foregroundColor + Material.elevation: modelData + + Layout.leftMargin: elevationLayout.contentLeftMargin + } + } + + Layout.bottomMargin: Constants.spacing + } + } + + ScrollView { + anchors.fill: parent + + RowLayout { + spacing: Constants.spacing + + ElevationLayout { + contentLeftMargin: Constants.spacing + } + + ElevationLayout { + backgroundColor: Material.Teal + foregroundColor: "white" + contentRightMargin: Constants.spacing + } + } + } +} diff --git a/tests/manual/quickcontrols/material/pages/RoundButtonPage.qml b/tests/manual/quickcontrols/material/pages/RoundButtonPage.qml new file mode 100644 index 0000000000..1fbcbf2e45 --- /dev/null +++ b/tests/manual/quickcontrols/material/pages/RoundButtonPage.qml @@ -0,0 +1,93 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +import QtQuick +import QtQuick.Controls.Material +import QtQuick.Layouts + +import ".." + +Page { + topPadding: 20 + + property var backgroundColor + + header: RowLayout { + CheckBox { + id: iconCheckBox + text: "Icon" + } + + CheckBox { + id: disabledCheckBox + text: "Disabled" + } + + Item { + Layout.fillWidth: true + } + } + + component ElevationLayout: ColumnLayout { + id: elevationLayout + enabled: !disabledCheckBox.checked + + property bool allowFlat + property var backgroundColor: undefined + property var foregroundColor: undefined + + property int contentLeftMargin + property int contentRightMargin + + RowLayout { + enabled: elevationLayout.allowFlat + + CheckBox { + id: flatCheckBox + text: "Flat" + + Layout.leftMargin: elevationLayout.contentLeftMargin + } + } + + ColumnLayout { + spacing: Constants.spacing + + Repeater { + model: 13 + + RoundButton { + text: iconCheckBox.checked ? "" : modelData + flat: flatCheckBox.checked + icon.source: iconCheckBox.checked ? Constants.iconSource : "" + + Material.background: elevationLayout.backgroundColor + Material.foreground: elevationLayout.foregroundColor + Material.elevation: modelData + + Layout.leftMargin: elevationLayout.contentLeftMargin + } + } + + Layout.bottomMargin: Constants.spacing + } + } + + ScrollView { + anchors.fill: parent + + RowLayout { + spacing: Constants.spacing + + ElevationLayout { + contentLeftMargin: Constants.spacing + allowFlat: true + } + + ElevationLayout { + backgroundColor: Material.Teal + foregroundColor: "white" + contentRightMargin: Constants.spacing + } + } + } +} diff --git a/tests/manual/quickcontrols/material/qmldir b/tests/manual/quickcontrols/material/qmldir new file mode 100644 index 0000000000..e56896abb6 --- /dev/null +++ b/tests/manual/quickcontrols/material/qmldir @@ -0,0 +1,2 @@ +module MaterialHelper +singleton Constants 1.0 Constants.qml diff --git a/tests/manual/quickcontrols/testbench/testbench.qml b/tests/manual/quickcontrols/testbench/testbench.qml index c9185e35d0..c88e16425a 100644 --- a/tests/manual/quickcontrols/testbench/testbench.qml +++ b/tests/manual/quickcontrols/testbench/testbench.qml @@ -430,8 +430,8 @@ Ui.ApplicationWindow { Label { text: statesAsString.length > 0 ? statesAsString : "normal" - // 4 is the most states for any element (Button) - Layout.preferredHeight: (fontMetrics.lineSpacing) * (rootDelegate.maxStateCombinations + 1) + // Ensure that each row of the Flow has the same height for the labels. + Layout.preferredHeight: fontMetrics.lineSpacing * rootDelegate.maxStateCombinations } ControlContainer { |