| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qquicksystempalette_p.h" |
| 5 | |
| 6 | #include <QGuiApplication> |
| 7 | |
| 8 | #include <private/qobject_p.h> |
| 9 | |
| 10 | QT_BEGIN_NAMESPACE |
| 11 | |
| 12 | class QQuickSystemPalettePrivate : public QObjectPrivate |
| 13 | { |
| 14 | public: |
| 15 | QPalette::ColorGroup group; |
| 16 | }; |
| 17 | |
| 18 | |
| 19 | |
| 20 | /*! |
| 21 | \qmltype SystemPalette |
| 22 | \nativetype QQuickSystemPalette |
| 23 | \inqmlmodule QtQuick |
| 24 | \ingroup qtquick-visual-utility |
| 25 | \brief Provides access to the Qt palettes. |
| 26 | |
| 27 | The SystemPalette type provides access to the Qt application |
| 28 | palettes. This provides information about the standard colors used |
| 29 | for application windows, buttons and other features. These colors |
| 30 | are grouped into three \e {color groups}: \c active, \c inactive, |
| 31 | and \c disabled. See the QPalette documentation for details about |
| 32 | color groups and the properties provided by SystemPalette. |
| 33 | |
| 34 | This can be used to color items in a way that provides a more |
| 35 | native look and feel. |
| 36 | |
| 37 | The following example creates a palette from the \c Active color |
| 38 | group and uses this to color the window and text items |
| 39 | appropriately: |
| 40 | |
| 41 | \snippet qml/systempalette.qml 0 |
| 42 | |
| 43 | \sa QPalette |
| 44 | */ |
| 45 | QQuickSystemPalette::QQuickSystemPalette(QObject *parent) |
| 46 | : QObject(*(new QQuickSystemPalettePrivate), parent) |
| 47 | { |
| 48 | Q_D(QQuickSystemPalette); |
| 49 | d->group = QPalette::Active; |
| 50 | connect(qApp, SIGNAL(paletteChanged(QPalette)), receiver: this, SIGNAL(paletteChanged())); |
| 51 | } |
| 52 | |
| 53 | /*! |
| 54 | \qmlproperty color QtQuick::SystemPalette::window |
| 55 | The window (general background) color of the current color group. |
| 56 | |
| 57 | \sa QPalette::ColorRole |
| 58 | */ |
| 59 | QColor QQuickSystemPalette::window() const |
| 60 | { |
| 61 | Q_D(const QQuickSystemPalette); |
| 62 | return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Window); |
| 63 | } |
| 64 | |
| 65 | /*! |
| 66 | \qmlproperty color QtQuick::SystemPalette::windowText |
| 67 | The window text (general foreground) color of the current color group. |
| 68 | |
| 69 | \sa QPalette::ColorRole |
| 70 | */ |
| 71 | QColor QQuickSystemPalette::windowText() const |
| 72 | { |
| 73 | Q_D(const QQuickSystemPalette); |
| 74 | return QGuiApplication::palette().color(cg: d->group, cr: QPalette::WindowText); |
| 75 | } |
| 76 | |
| 77 | /*! |
| 78 | \qmlproperty color QtQuick::SystemPalette::base |
| 79 | The base color of the current color group. |
| 80 | |
| 81 | \sa QPalette::ColorRole |
| 82 | */ |
| 83 | QColor QQuickSystemPalette::base() const |
| 84 | { |
| 85 | Q_D(const QQuickSystemPalette); |
| 86 | return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Base); |
| 87 | } |
| 88 | |
| 89 | /*! |
| 90 | \qmlproperty color QtQuick::SystemPalette::text |
| 91 | The text color of the current color group. |
| 92 | |
| 93 | \sa QPalette::ColorRole |
| 94 | */ |
| 95 | QColor QQuickSystemPalette::text() const |
| 96 | { |
| 97 | Q_D(const QQuickSystemPalette); |
| 98 | return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Text); |
| 99 | } |
| 100 | |
| 101 | /*! |
| 102 | \qmlproperty color QtQuick::SystemPalette::alternateBase |
| 103 | The alternate base color of the current color group. |
| 104 | |
| 105 | \sa QPalette::ColorRole |
| 106 | */ |
| 107 | QColor QQuickSystemPalette::alternateBase() const |
| 108 | { |
| 109 | Q_D(const QQuickSystemPalette); |
| 110 | return QGuiApplication::palette().color(cg: d->group, cr: QPalette::AlternateBase); |
| 111 | } |
| 112 | |
| 113 | /*! |
| 114 | \qmlproperty color QtQuick::SystemPalette::button |
| 115 | The button color of the current color group. |
| 116 | |
| 117 | \sa QPalette::ColorRole |
| 118 | */ |
| 119 | QColor QQuickSystemPalette::button() const |
| 120 | { |
| 121 | Q_D(const QQuickSystemPalette); |
| 122 | return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Button); |
| 123 | } |
| 124 | |
| 125 | /*! |
| 126 | \qmlproperty color QtQuick::SystemPalette::buttonText |
| 127 | The button text foreground color of the current color group. |
| 128 | |
| 129 | \sa QPalette::ColorRole |
| 130 | */ |
| 131 | QColor QQuickSystemPalette::buttonText() const |
| 132 | { |
| 133 | Q_D(const QQuickSystemPalette); |
| 134 | return QGuiApplication::palette().color(cg: d->group, cr: QPalette::ButtonText); |
| 135 | } |
| 136 | |
| 137 | /*! |
| 138 | \qmlproperty color QtQuick::SystemPalette::light |
| 139 | The light color of the current color group. |
| 140 | |
| 141 | \sa QPalette::ColorRole |
| 142 | */ |
| 143 | QColor QQuickSystemPalette::light() const |
| 144 | { |
| 145 | Q_D(const QQuickSystemPalette); |
| 146 | return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Light); |
| 147 | } |
| 148 | |
| 149 | /*! |
| 150 | \qmlproperty color QtQuick::SystemPalette::midlight |
| 151 | The midlight color of the current color group. |
| 152 | |
| 153 | \sa QPalette::ColorRole |
| 154 | */ |
| 155 | QColor QQuickSystemPalette::midlight() const |
| 156 | { |
| 157 | Q_D(const QQuickSystemPalette); |
| 158 | return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Midlight); |
| 159 | } |
| 160 | |
| 161 | /*! |
| 162 | \qmlproperty color QtQuick::SystemPalette::dark |
| 163 | The dark color of the current color group. |
| 164 | |
| 165 | \sa QPalette::ColorRole |
| 166 | */ |
| 167 | QColor QQuickSystemPalette::dark() const |
| 168 | { |
| 169 | Q_D(const QQuickSystemPalette); |
| 170 | return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Dark); |
| 171 | } |
| 172 | |
| 173 | /*! |
| 174 | \qmlproperty color QtQuick::SystemPalette::mid |
| 175 | The mid color of the current color group. |
| 176 | |
| 177 | \sa QPalette::ColorRole |
| 178 | */ |
| 179 | QColor QQuickSystemPalette::mid() const |
| 180 | { |
| 181 | Q_D(const QQuickSystemPalette); |
| 182 | return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Mid); |
| 183 | } |
| 184 | |
| 185 | /*! |
| 186 | \qmlproperty color QtQuick::SystemPalette::shadow |
| 187 | The shadow color of the current color group. |
| 188 | |
| 189 | \sa QPalette::ColorRole |
| 190 | */ |
| 191 | QColor QQuickSystemPalette::shadow() const |
| 192 | { |
| 193 | Q_D(const QQuickSystemPalette); |
| 194 | return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Shadow); |
| 195 | } |
| 196 | |
| 197 | /*! |
| 198 | \qmlproperty color QtQuick::SystemPalette::highlight |
| 199 | The highlight color of the current color group. |
| 200 | |
| 201 | \sa QPalette::ColorRole |
| 202 | */ |
| 203 | QColor QQuickSystemPalette::highlight() const |
| 204 | { |
| 205 | Q_D(const QQuickSystemPalette); |
| 206 | return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Highlight); |
| 207 | } |
| 208 | |
| 209 | /*! |
| 210 | \qmlproperty color QtQuick::SystemPalette::highlightedText |
| 211 | The highlighted text color of the current color group. |
| 212 | |
| 213 | \sa QPalette::ColorRole |
| 214 | */ |
| 215 | QColor QQuickSystemPalette::highlightedText() const |
| 216 | { |
| 217 | Q_D(const QQuickSystemPalette); |
| 218 | return QGuiApplication::palette().color(cg: d->group, cr: QPalette::HighlightedText); |
| 219 | } |
| 220 | |
| 221 | /*! |
| 222 | \qmlproperty color QtQuick::SystemPalette::placeholderText |
| 223 | The placeholder text color of the current color group. |
| 224 | |
| 225 | \since 6.2 |
| 226 | \sa QPalette::ColorRole |
| 227 | */ |
| 228 | QColor QQuickSystemPalette::placeholderText() const |
| 229 | { |
| 230 | Q_D(const QQuickSystemPalette); |
| 231 | return QGuiApplication::palette().color(cg: d->group, cr: QPalette::PlaceholderText); |
| 232 | } |
| 233 | |
| 234 | /*! |
| 235 | \qmlproperty color QtQuick::SystemPalette::accent |
| 236 | The accent color of the current color group. |
| 237 | |
| 238 | \since 6.7 |
| 239 | \sa QPalette::ColorRole |
| 240 | */ |
| 241 | QColor QQuickSystemPalette::accent() const |
| 242 | { |
| 243 | Q_D(const QQuickSystemPalette); |
| 244 | return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Accent); |
| 245 | } |
| 246 | |
| 247 | /*! |
| 248 | \qmlproperty enumeration QtQuick::SystemPalette::colorGroup |
| 249 | |
| 250 | The color group of the palette. This can be one of: |
| 251 | |
| 252 | \value SystemPalette.Active (default) QPalette::Active |
| 253 | \value SystemPalette.Inactive QPalette::Inactive |
| 254 | \value SystemPalette.Disabled QPalette::Disabled |
| 255 | |
| 256 | \sa QPalette::ColorGroup |
| 257 | */ |
| 258 | QQuickSystemPalette::ColorGroup QQuickSystemPalette::colorGroup() const |
| 259 | { |
| 260 | Q_D(const QQuickSystemPalette); |
| 261 | return (QQuickSystemPalette::ColorGroup)d->group; |
| 262 | } |
| 263 | |
| 264 | void QQuickSystemPalette::setColorGroup(QQuickSystemPalette::ColorGroup colorGroup) |
| 265 | { |
| 266 | Q_D(QQuickSystemPalette); |
| 267 | d->group = (QPalette::ColorGroup)colorGroup; |
| 268 | emit paletteChanged(); |
| 269 | } |
| 270 | |
| 271 | QT_END_NAMESPACE |
| 272 | |
| 273 | #include "moc_qquicksystempalette_p.cpp" |
| 274 | |