aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickpalette.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/items/qquickpalette.cpp')
-rw-r--r--src/quick/items/qquickpalette.cpp133
1 files changed, 71 insertions, 62 deletions
diff --git a/src/quick/items/qquickpalette.cpp b/src/quick/items/qquickpalette.cpp
index a64b309426..79b22bd8a0 100644
--- a/src/quick/items/qquickpalette.cpp
+++ b/src/quick/items/qquickpalette.cpp
@@ -1,38 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtQuick module 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$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qquickpalette_p.h"
@@ -40,11 +7,33 @@
QT_BEGIN_NAMESPACE
+static constexpr bool is_valid(QPalette::ColorGroup cg) noexcept
+{
+ // use a switch to enable "unhandled enum" warnings:
+ switch (cg) {
+ case QPalette::Active:
+ case QPalette::Disabled:
+ case QPalette::Inactive:
+ return true;
+ case QPalette::NColorGroups:
+ case QPalette::Current:
+ case QPalette::All:
+ return false;
+ }
+
+ // GCC 8.x does not tread __builtin_unreachable() as constexpr
+#if defined(Q_CC_INTEL) || defined(Q_CC_CLANG) || (defined(Q_CC_GNU) && Q_CC_GNU >= 900)
+ // NOLINTNEXTLINE(qt-use-unreachable-return): Triggers on Clang, breaking GCC 8
+ Q_UNREACHABLE();
+#endif
+ return false;
+}
+
/*!
\internal
\class QQuickPalette
- \brief The QQuickPalette class contains color groups for each QML item state.
+ \brief Contains color groups for each QML item state.
\inmodule QtQuick
\since 6.0
@@ -59,10 +48,10 @@ QT_BEGIN_NAMESPACE
\inherits QQuickColorGroup
\inqmlmodule QtQuick
\ingroup qtquick-visual
- \brief The QQuickPalette class contains color groups for each QML item state.
+ \brief Contains color groups for each QML item state.
- A palette consists of three color groups: Active, Disabled, and Inactive.
- Active color group is the default group, its colors are used for other groups
+ A palette consists of three color groups: \c active, \c disabled, and \c inactive.
+ The \c active color group is the default group: its colors are used for other groups
if colors of these groups aren't explicitly specified.
In the following example, color is applied for all color groups:
@@ -104,22 +93,23 @@ QT_BEGIN_NAMESPACE
\endcode
It is also possible to specify colors like this:
- \code
- palette {
- buttonText: "azure"
- button: "khaki"
- disabled {
- buttonText: "lavender"
- button: "coral"
- }
- }
- \endcode
- This approach is convenient when you need to specify a whole palette with all color groups.
+ \snippet qtquickcontrols-custom-palette-buttons.qml palette
+
+ This approach is especially convenient when you need to specify a whole
+ palette with all color groups; but as with the other cases above, the
+ colors that are not specified are initialized from SystemPalette, or
+ potentially the \l {Styling Qt Quick Controls}{Qt Quick Controls style},
+ if one is in use.
+
+ \note Some Controls styles use some palette colors, but many styles use
+ independent colors.
+
+ \sa Window::palette, Item::palette, Popup::palette, SystemPalette
*/
/*!
- \qmlproperty QQuickColorGroup QtQuick::Palette::active
+ \qmlproperty ColorGroup QtQuick::Palette::active
The Active group is used for windows that are in focus.
@@ -127,7 +117,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \qmlproperty QQuickColorGroup QtQuick::Palette::inactive
+ \qmlproperty ColorGroup QtQuick::Palette::inactive
The Inactive group is used for windows that have no keyboard focus.
@@ -135,7 +125,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \qmlproperty QQuickColorGroup QtQuick::Palette::disabled
+ \qmlproperty ColorGroup QtQuick::Palette::disabled
The Disabled group is used for elements that are disabled for some reason.
@@ -163,6 +153,24 @@ QQuickColorGroup *QQuickPalette::disabled() const
return colorGroup(QPalette::Disabled);
}
+void QQuickPalette::resetActive()
+{
+ if (colorProvider().resetColor(QPalette::Active))
+ Q_EMIT changed();
+}
+
+void QQuickPalette::resetInactive()
+{
+ if (colorProvider().resetColor(QPalette::Inactive))
+ Q_EMIT changed();
+}
+
+void QQuickPalette::resetDisabled()
+{
+ if (colorProvider().resetColor(QPalette::Disabled))
+ Q_EMIT changed();
+}
+
/*!
\internal
@@ -281,20 +289,19 @@ QQuickColorGroup::GroupPtr QQuickPalette::colorGroup(QPalette::ColorGroup groupT
QQuickColorGroup::GroupPtr QQuickPalette::findColorGroup(QPalette::ColorGroup groupTag) const
{
- if (auto it = m_colorGroups.find(groupTag); it != m_colorGroups.end()) {
- return it->second;
- }
-
- return nullptr;
+ Q_ASSERT(is_valid(groupTag));
+ return m_colorGroups[groupTag];
}
void QQuickPalette::registerColorGroup(QQuickColorGroup *group, QPalette::ColorGroup groupTag)
{
- if (auto it = m_colorGroups.find(groupTag); it != m_colorGroups.end() && it->second) {
- it->second->deleteLater();
+ Q_ASSERT(is_valid(groupTag));
+ auto &g = m_colorGroups[groupTag];
+ if (g) {
+ Q_ASSERT(g != group);
+ g->deleteLater();
}
-
- m_colorGroups[groupTag] = group;
+ g = group;
group->setGroupTag(groupTag);
@@ -334,3 +341,5 @@ bool QQuickPalette::isValidColorGroup(QPalette::ColorGroup groupTag,
}
QT_END_NAMESPACE
+
+#include "moc_qquickpalette_p.cpp"