diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2016-08-19 16:00:03 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2016-08-19 14:12:00 +0000 |
commit | 9b7e62a88b9d86ba6b391bf7abc18cba3c147ed5 (patch) | |
tree | ee0e87b37b314dd5357bb192613bf91bb91793a1 | |
parent | 47f32f2f768edbaa96c9356f0b2b4cb4f566b814 (diff) |
Universal: ensure setting background/foreground works
- Add HasGlobalForeground and HasGlobalBackground. These are set
to true when a foreground/background color is specified via settings
(qtquickcontrols2.conf file or environment variables), and then used
to initialize each attached style object's m_hasForeground and
m_hasBackground property.
- Add tst_qquickuniversalstyleconf auto test to ensure that global
settings are respected.
Task-number: QTBUG-55366
Change-Id: I7a8b219506f9528c4ae323bd890b418ba056ed23
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
7 files changed, 169 insertions, 5 deletions
diff --git a/src/imports/controls/universal/qquickuniversalstyle.cpp b/src/imports/controls/universal/qquickuniversalstyle.cpp index 51776fbd..c5516a9e 100644 --- a/src/imports/controls/universal/qquickuniversalstyle.cpp +++ b/src/imports/controls/universal/qquickuniversalstyle.cpp @@ -136,10 +136,14 @@ static QQuickUniversalStyle::Theme GlobalTheme = QQuickUniversalStyle::Light; static QRgb GlobalAccent = qquickuniversal_accent_color(QQuickUniversalStyle::Cobalt); static QRgb GlobalForeground = qquickuniversal_light_color(QQuickUniversalStyle::BaseHigh); static QRgb GlobalBackground = qquickuniversal_light_color(QQuickUniversalStyle::AltHigh); +// These represent whether a global foreground/background was set. +// Each style's m_hasForeground/m_hasBackground are initialized to these values. +static bool HasGlobalForeground = false; +static bool HasGlobalBackground = false; QQuickUniversalStyle::QQuickUniversalStyle(QObject *parent) : QQuickStyleAttached(parent), m_explicitTheme(false), m_explicitAccent(false), m_explicitForeground(false), m_explicitBackground(false), - m_hasForeground(false), m_hasBackground(false), m_theme(GlobalTheme), + m_hasForeground(HasGlobalForeground), m_hasBackground(HasGlobalBackground), m_theme(GlobalTheme), m_accent(GlobalAccent), m_foreground(GlobalForeground), m_background(GlobalBackground) { init(); @@ -549,24 +553,30 @@ void QQuickUniversalStyle::init() Color foregroundEnum = toEnumValue<Color>(foregroundValue, &ok); if (ok) { GlobalForeground = m_foreground = qquickuniversal_accent_color(foregroundEnum); + HasGlobalForeground = m_hasForeground = true; } else if (!foregroundValue.isEmpty()) { QColor color(foregroundValue.constData()); - if (color.isValid()) + if (color.isValid()) { GlobalForeground = m_foreground = color.rgba(); - else + HasGlobalForeground = m_hasForeground = true; + } else { qWarning().nospace().noquote() << "Universal: unknown foreground value: " << foregroundValue; + } } QByteArray backgroundValue = resolveSetting("QT_QUICK_CONTROLS_UNIVERSAL_BACKGROUND", settings, QStringLiteral("Background")); Color backgroundEnum = toEnumValue<Color>(backgroundValue, &ok); if (ok) { GlobalBackground = m_background = qquickuniversal_accent_color(backgroundEnum); + HasGlobalBackground = m_hasBackground = true; } else if (!backgroundValue.isEmpty()) { QColor color(backgroundValue.constData()); - if (color.isValid()) + if (color.isValid()) { GlobalBackground = m_background = color.rgba(); - else + HasGlobalBackground = m_hasBackground = true; + } else { qWarning().nospace().noquote() << "Universal: unknown background value: " << backgroundValue; + } } globalsInitialized = true; diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index c3acd8f1..91850968 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -13,6 +13,7 @@ SUBDIRS += \ qquickstyle \ qquickstyleselector \ qquickuniversalstyle \ + qquickuniversalstyleconf \ sanity \ snippets diff --git a/tests/auto/qquickuniversalstyleconf/data/applicationwindow.qml b/tests/auto/qquickuniversalstyleconf/data/applicationwindow.qml new file mode 100644 index 00000000..a1657a69 --- /dev/null +++ b/tests/auto/qquickuniversalstyleconf/data/applicationwindow.qml @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** 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.7 +import QtQuick.Controls 2.0 + +ApplicationWindow { + width: 400 + height: 400 + + property alias label: label + + Label { + id: label + } +} diff --git a/tests/auto/qquickuniversalstyleconf/qquickuniversalstyleconf.pro b/tests/auto/qquickuniversalstyleconf/qquickuniversalstyleconf.pro new file mode 100644 index 00000000..9aaedbee --- /dev/null +++ b/tests/auto/qquickuniversalstyleconf/qquickuniversalstyleconf.pro @@ -0,0 +1,17 @@ +CONFIG += testcase +TARGET = tst_qquickuniversalstyleconf +SOURCES += tst_qquickuniversalstyleconf.cpp + +macos:CONFIG -= app_bundle + +QT += core-private gui-private qml-private quick-private testlib quicktemplates2-private quickcontrols2-private + +include (../shared/util.pri) + +RESOURCES += qquickuniversalstyleconf.qrc + +TESTDATA = data/* + +OTHER_FILES += \ + data/* + diff --git a/tests/auto/qquickuniversalstyleconf/qquickuniversalstyleconf.qrc b/tests/auto/qquickuniversalstyleconf/qquickuniversalstyleconf.qrc new file mode 100644 index 00000000..53ba6450 --- /dev/null +++ b/tests/auto/qquickuniversalstyleconf/qquickuniversalstyleconf.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>qtquickcontrols2.conf</file> +</qresource> +</RCC> diff --git a/tests/auto/qquickuniversalstyleconf/qtquickcontrols2.conf b/tests/auto/qquickuniversalstyleconf/qtquickcontrols2.conf new file mode 100644 index 00000000..836372c9 --- /dev/null +++ b/tests/auto/qquickuniversalstyleconf/qtquickcontrols2.conf @@ -0,0 +1,6 @@ +[Controls] +Style=Universal + +[Universal] +Background=#444444 +Foreground=Red diff --git a/tests/auto/qquickuniversalstyleconf/tst_qquickuniversalstyleconf.cpp b/tests/auto/qquickuniversalstyleconf/tst_qquickuniversalstyleconf.cpp new file mode 100644 index 00000000..c676ae6d --- /dev/null +++ b/tests/auto/qquickuniversalstyleconf/tst_qquickuniversalstyleconf.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qtest.h> +#include <QtQuick/private/qquickitem_p.h> +#include "../shared/util.h" +#include "../shared/visualtestutil.h" + +using namespace QQuickVisualTestUtil; + +class tst_qquickuniversalstyleconf : public QQmlDataTest +{ + Q_OBJECT + +public: + +private slots: + void conf(); +}; + +void tst_qquickuniversalstyleconf::conf() +{ + QQuickApplicationHelper helper(this, QLatin1String("applicationwindow.qml")); + + QQuickApplicationWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + // We specified a custom background color, so the window should have it. + QCOMPARE(window->property("color").value<QColor>(), QColor("#444444")); + + // We specified a custom foreground color, so the label should have it. + QQuickItem *label = window->property("label").value<QQuickItem*>(); + QVERIFY(label); + QCOMPARE(label->property("color").value<QColor>(), QColor("#E51400")); +} + +QTEST_MAIN(tst_qquickuniversalstyleconf) + +#include "tst_qquickuniversalstyleconf.moc" |