| 1 | // Copyright (C) 2017 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 | #ifndef QQUICKMATERIALSTYLE_P_H | 
| 5 | #define QQUICKMATERIALSTYLE_P_H | 
| 6 |  | 
| 7 | // | 
| 8 | //  W A R N I N G | 
| 9 | //  ------------- | 
| 10 | // | 
| 11 | // This file is not part of the Qt API.  It exists purely as an | 
| 12 | // implementation detail.  This header file may change from version to | 
| 13 | // version without notice, or even be removed. | 
| 14 | // | 
| 15 | // We mean it. | 
| 16 | // | 
| 17 |  | 
| 18 | #include <QtGui/qcolor.h> | 
| 19 | #include <QtQml/qqml.h> | 
| 20 | #include <QtQuickControls2/qquickattachedpropertypropagator.h> | 
| 21 | #include <QtQuickControls2Material/qtquickcontrols2materialexports.h> | 
| 22 |  | 
| 23 | QT_BEGIN_NAMESPACE | 
| 24 |  | 
| 25 | class Q_QUICKCONTROLS2MATERIAL_EXPORT QQuickMaterialStyle : public QQuickAttachedPropertyPropagator | 
| 26 | { | 
| 27 |     Q_OBJECT | 
| 28 |     Q_PROPERTY(Theme theme READ theme WRITE setTheme RESET resetTheme NOTIFY themeChanged FINAL) | 
| 29 |     Q_PROPERTY(QVariant primary READ primary WRITE setPrimary RESET resetPrimary NOTIFY primaryChanged FINAL) | 
| 30 |     Q_PROPERTY(QVariant accent READ accent WRITE setAccent RESET resetAccent NOTIFY accentChanged FINAL) | 
| 31 |     Q_PROPERTY(QVariant foreground READ foreground WRITE setForeground RESET resetForeground NOTIFY foregroundChanged FINAL) | 
| 32 |     Q_PROPERTY(QVariant background READ background WRITE setBackground RESET resetBackground NOTIFY backgroundChanged FINAL) | 
| 33 |     Q_PROPERTY(int elevation READ elevation WRITE setElevation RESET resetElevation NOTIFY elevationChanged FINAL) | 
| 34 |     Q_PROPERTY(RoundedScale roundedScale READ roundedScale WRITE setRoundedScale RESET resetRoundedScale | 
| 35 |         NOTIFY roundedScaleChanged FINAL) | 
| 36 |     Q_PROPERTY(ContainerStyle containerStyle READ containerStyle WRITE setContainerStyle RESET resetContainerStyle | 
| 37 |         NOTIFY containerStyleChanged FINAL) | 
| 38 |  | 
| 39 |     Q_PROPERTY(QColor primaryColor READ primaryColor NOTIFY primaryChanged FINAL) // TODO: remove? | 
| 40 |     Q_PROPERTY(QColor accentColor READ accentColor NOTIFY accentChanged FINAL) // TODO: remove? | 
| 41 |     Q_PROPERTY(QColor backgroundColor READ backgroundColor NOTIFY backgroundChanged FINAL) | 
| 42 |     Q_PROPERTY(QColor primaryTextColor READ primaryTextColor NOTIFY themeChanged FINAL) | 
| 43 |     Q_PROPERTY(QColor primaryHighlightedTextColor READ primaryHighlightedTextColor NOTIFY primaryHighlightedTextColorChanged FINAL) | 
| 44 |     Q_PROPERTY(QColor secondaryTextColor READ secondaryTextColor NOTIFY themeChanged FINAL) | 
| 45 |     Q_PROPERTY(QColor hintTextColor READ hintTextColor NOTIFY themeChanged FINAL) | 
| 46 |     Q_PROPERTY(QColor textSelectionColor READ textSelectionColor NOTIFY themeOrAccentChanged FINAL) | 
| 47 |     Q_PROPERTY(QColor dropShadowColor READ dropShadowColor CONSTANT FINAL) | 
| 48 |     Q_PROPERTY(QColor dividerColor READ dividerColor NOTIFY themeChanged FINAL) | 
| 49 |     Q_PROPERTY(QColor iconColor READ iconColor NOTIFY themeChanged FINAL) | 
| 50 |     Q_PROPERTY(QColor iconDisabledColor READ iconDisabledColor NOTIFY themeChanged FINAL) | 
| 51 |     Q_PROPERTY(QColor frameColor READ frameColor NOTIFY themeChanged FINAL) | 
| 52 |     Q_PROPERTY(QColor rippleColor READ rippleColor NOTIFY themeChanged FINAL) | 
| 53 |     Q_PROPERTY(QColor highlightedRippleColor READ highlightedRippleColor NOTIFY themeOrAccentChanged FINAL) | 
| 54 |     Q_PROPERTY(QColor switchUncheckedTrackColor READ switchUncheckedTrackColor NOTIFY themeChanged FINAL) | 
| 55 |     Q_PROPERTY(QColor switchCheckedTrackColor READ switchCheckedTrackColor NOTIFY themeOrAccentChanged FINAL) | 
| 56 |     Q_PROPERTY(QColor switchUncheckedHandleColor READ switchUncheckedHandleColor NOTIFY themeChanged FINAL) | 
| 57 |     Q_PROPERTY(QColor switchUncheckedHoveredHandleColor READ switchUncheckedHoveredHandleColor NOTIFY themeChanged FINAL) | 
| 58 |     Q_PROPERTY(QColor switchDisabledUncheckedTrackColor READ switchDisabledUncheckedTrackColor NOTIFY themeChanged FINAL) | 
| 59 |     Q_PROPERTY(QColor switchDisabledCheckedTrackColor READ switchDisabledCheckedTrackColor NOTIFY themeChanged FINAL) | 
| 60 |     Q_PROPERTY(QColor switchDisabledUncheckedTrackBorderColor READ switchDisabledUncheckedTrackBorderColor NOTIFY themeChanged FINAL) | 
| 61 |     Q_PROPERTY(QColor switchCheckedHandleColor READ switchCheckedHandleColor NOTIFY themeOrAccentChanged FINAL) | 
| 62 |     Q_PROPERTY(QColor switchDisabledUncheckedHandleColor READ switchDisabledUncheckedHandleColor NOTIFY themeChanged FINAL) | 
| 63 |     Q_PROPERTY(QColor switchDisabledCheckedHandleColor READ switchDisabledCheckedHandleColor NOTIFY themeChanged FINAL) | 
| 64 |     Q_PROPERTY(QColor switchDisabledCheckedIconColor READ switchDisabledCheckedIconColor NOTIFY themeChanged FINAL) | 
| 65 |     Q_PROPERTY(QColor switchDisabledUncheckedIconColor READ switchDisabledUncheckedIconColor NOTIFY themeChanged FINAL) | 
| 66 |     Q_PROPERTY(QColor scrollBarColor READ scrollBarColor NOTIFY themeChanged FINAL) | 
| 67 |     Q_PROPERTY(QColor scrollBarHoveredColor READ scrollBarHoveredColor NOTIFY themeChanged FINAL) | 
| 68 |     Q_PROPERTY(QColor scrollBarPressedColor READ scrollBarPressedColor NOTIFY themeChanged FINAL) | 
| 69 |     Q_PROPERTY(QColor dialogColor READ dialogColor NOTIFY dialogColorChanged FINAL) | 
| 70 |     Q_PROPERTY(QColor backgroundDimColor READ backgroundDimColor NOTIFY themeChanged FINAL) | 
| 71 |     Q_PROPERTY(QColor listHighlightColor READ listHighlightColor NOTIFY themeChanged FINAL) | 
| 72 |     Q_PROPERTY(QColor tooltipColor READ tooltipColor NOTIFY tooltipColorChanged FINAL) | 
| 73 |     Q_PROPERTY(QColor toolBarColor READ toolBarColor NOTIFY toolBarColorChanged FINAL) | 
| 74 |     Q_PROPERTY(QColor toolTextColor READ toolTextColor NOTIFY toolTextColorChanged FINAL) | 
| 75 |     Q_PROPERTY(QColor spinBoxDisabledIconColor READ spinBoxDisabledIconColor NOTIFY themeChanged FINAL) | 
| 76 |     Q_PROPERTY(QColor sliderDisabledColor READ sliderDisabledColor NOTIFY themeChanged FINAL REVISION(2, 15)) | 
| 77 |     Q_PROPERTY(QColor textFieldFilledContainerColor READ textFieldFilledContainerColor NOTIFY themeChanged FINAL) | 
| 78 |  | 
| 79 |     Q_PROPERTY(int touchTarget READ touchTarget CONSTANT FINAL) | 
| 80 |     Q_PROPERTY(int buttonVerticalPadding READ buttonVerticalPadding CONSTANT FINAL) | 
| 81 |     Q_PROPERTY(int buttonHeight READ buttonHeight CONSTANT FINAL) | 
| 82 |     Q_PROPERTY(int delegateHeight READ delegateHeight CONSTANT FINAL) | 
| 83 |     Q_PROPERTY(int dialogButtonBoxHeight READ dialogButtonBoxHeight CONSTANT FINAL) | 
| 84 |     Q_PROPERTY(int dialogTitleFontPixelSize READ dialogTitleFontPixelSize CONSTANT FINAL) | 
| 85 |     Q_PROPERTY(RoundedScale dialogRoundedScale READ dialogRoundedScale CONSTANT FINAL) | 
| 86 |     Q_PROPERTY(int frameVerticalPadding READ frameVerticalPadding CONSTANT FINAL) | 
| 87 |     Q_PROPERTY(int menuItemHeight READ menuItemHeight CONSTANT FINAL) | 
| 88 |     Q_PROPERTY(int menuItemVerticalPadding READ menuItemVerticalPadding CONSTANT FINAL) | 
| 89 |     Q_PROPERTY(int switchIndicatorWidth READ switchIndicatorWidth CONSTANT FINAL) | 
| 90 |     Q_PROPERTY(int switchIndicatorHeight READ switchIndicatorHeight CONSTANT FINAL) | 
| 91 |     Q_PROPERTY(int switchNormalHandleHeight READ switchNormalHandleHeight CONSTANT FINAL) | 
| 92 |     Q_PROPERTY(int switchCheckedHandleHeight READ switchCheckedHandleHeight CONSTANT FINAL) | 
| 93 |     Q_PROPERTY(int switchLargestHandleHeight READ switchLargestHandleHeight CONSTANT FINAL) | 
| 94 |     Q_PROPERTY(int switchDelegateVerticalPadding READ switchDelegateVerticalPadding CONSTANT FINAL) | 
| 95 |     Q_PROPERTY(int textFieldHeight READ textFieldHeight CONSTANT FINAL) | 
| 96 |     Q_PROPERTY(int textFieldHorizontalPadding READ textFieldHorizontalPadding CONSTANT FINAL) | 
| 97 |     Q_PROPERTY(int textFieldVerticalPadding READ textFieldVerticalPadding CONSTANT FINAL) | 
| 98 |     Q_PROPERTY(int tooltipHeight READ tooltipHeight CONSTANT FINAL) | 
| 99 |  | 
| 100 |     QML_NAMED_ELEMENT(Material) | 
| 101 |     QML_ATTACHED(QQuickMaterialStyle) | 
| 102 |     QML_UNCREATABLE("" ) | 
| 103 |     QML_ADDED_IN_VERSION(2, 0) | 
| 104 |  | 
| 105 | public: | 
| 106 |     enum Theme { | 
| 107 |         Light, | 
| 108 |         Dark, | 
| 109 |         System | 
| 110 |     }; | 
| 111 |  | 
| 112 |     enum Variant { | 
| 113 |         Normal, | 
| 114 |         Dense | 
| 115 |     }; | 
| 116 |  | 
| 117 |     enum Color { | 
| 118 |         Red, | 
| 119 |         Pink, | 
| 120 |         Purple, | 
| 121 |         DeepPurple, | 
| 122 |         Indigo, | 
| 123 |         Blue, | 
| 124 |         LightBlue, | 
| 125 |         Cyan, | 
| 126 |         Teal, | 
| 127 |         Green, | 
| 128 |         LightGreen, | 
| 129 |         Lime, | 
| 130 |         Yellow, | 
| 131 |         Amber, | 
| 132 |         Orange, | 
| 133 |         DeepOrange, | 
| 134 |         Brown, | 
| 135 |         Grey, | 
| 136 |         BlueGrey | 
| 137 |     }; | 
| 138 |  | 
| 139 |     enum Shade { | 
| 140 |         Shade50, | 
| 141 |         Shade100, | 
| 142 |         Shade200, | 
| 143 |         Shade300, | 
| 144 |         Shade400, | 
| 145 |         Shade500, | 
| 146 |         Shade600, | 
| 147 |         Shade700, | 
| 148 |         Shade800, | 
| 149 |         Shade900, | 
| 150 |         ShadeA100, | 
| 151 |         ShadeA200, | 
| 152 |         ShadeA400, | 
| 153 |         ShadeA700, | 
| 154 |     }; | 
| 155 |  | 
| 156 |     enum class RoundedScale { | 
| 157 |         NotRounded, | 
| 158 |          = 4, | 
| 159 |         SmallScale = 8, | 
| 160 |         MediumScale = 12, | 
| 161 |         LargeScale = 16, | 
| 162 |          = 28, | 
| 163 |         FullScale = 0xFF // For full we use half the height of the item. | 
| 164 |     }; | 
| 165 |  | 
| 166 |     enum class ContainerStyle { | 
| 167 |         Filled, | 
| 168 |         Outlined | 
| 169 |     }; | 
| 170 |  | 
| 171 |     Q_ENUM(Theme) | 
| 172 |     Q_ENUM(Variant) | 
| 173 |     Q_ENUM(Color) | 
| 174 |     Q_ENUM(Shade) | 
| 175 |     Q_ENUM(RoundedScale) | 
| 176 |     Q_ENUM(ContainerStyle) | 
| 177 |  | 
| 178 |     explicit QQuickMaterialStyle(QObject *parent = nullptr); | 
| 179 |  | 
| 180 |     static QQuickMaterialStyle *qmlAttachedProperties(QObject *object); | 
| 181 |  | 
| 182 |     Theme theme() const; | 
| 183 |     void setTheme(Theme theme); | 
| 184 |     void inheritTheme(Theme theme); | 
| 185 |     void propagateTheme(); | 
| 186 |     void resetTheme(); | 
| 187 |     void themeChange(); | 
| 188 |  | 
| 189 |     QVariant primary() const; | 
| 190 |     void setPrimary(const QVariant &accent); | 
| 191 |     void inheritPrimary(uint primary, bool custom); | 
| 192 |     void propagatePrimary(); | 
| 193 |     void resetPrimary(); | 
| 194 |     void primaryChange(); | 
| 195 |  | 
| 196 |     QVariant accent() const; | 
| 197 |     void setAccent(const QVariant &accent); | 
| 198 |     void inheritAccent(uint accent, bool custom); | 
| 199 |     void propagateAccent(); | 
| 200 |     void resetAccent(); | 
| 201 |     void accentChange(); | 
| 202 |  | 
| 203 |     QVariant foreground() const; | 
| 204 |     void setForeground(const QVariant &foreground); | 
| 205 |     void inheritForeground(uint foreground, bool custom, bool has); | 
| 206 |     void propagateForeground(); | 
| 207 |     void resetForeground(); | 
| 208 |     void foregroundChange(); | 
| 209 |  | 
| 210 |     QVariant background() const; | 
| 211 |     void setBackground(const QVariant &background); | 
| 212 |     void inheritBackground(uint background, bool custom, bool has); | 
| 213 |     void propagateBackground(); | 
| 214 |     void resetBackground(); | 
| 215 |     void backgroundChange(); | 
| 216 |  | 
| 217 |     int elevation() const; | 
| 218 |     void setElevation(int elevation); | 
| 219 |     void resetElevation(); | 
| 220 |     void elevationChange(); | 
| 221 |  | 
| 222 |     RoundedScale roundedScale() const; | 
| 223 |     void setRoundedScale(RoundedScale roundedScale); | 
| 224 |     void resetRoundedScale(); | 
| 225 |  | 
| 226 |     ContainerStyle containerStyle() const; | 
| 227 |     void setContainerStyle(ContainerStyle containerStyle); | 
| 228 |     void resetContainerStyle(); | 
| 229 |  | 
| 230 |     QColor primaryColor() const; | 
| 231 |     QColor accentColor() const; | 
| 232 |     QColor backgroundColor() const; | 
| 233 |     QColor primaryTextColor() const; | 
| 234 |     QColor primaryHighlightedTextColor() const; | 
| 235 |     QColor secondaryTextColor() const; | 
| 236 |     QColor hintTextColor() const; | 
| 237 |     QColor textSelectionColor() const; | 
| 238 |     QColor dropShadowColor() const; | 
| 239 |     QColor dividerColor() const; | 
| 240 |     QColor iconColor() const; | 
| 241 |     QColor iconDisabledColor() const; | 
| 242 |     Q_INVOKABLE QColor buttonColor(Theme theme, const QVariant &background, const QVariant &accent, | 
| 243 |         bool enabled, bool flat, bool highlighted, bool checked) const; | 
| 244 |     QColor frameColor() const; | 
| 245 |     QColor rippleColor() const; | 
| 246 |     QColor highlightedRippleColor() const; | 
| 247 |     QColor switchUncheckedTrackColor() const; | 
| 248 |     QColor switchCheckedTrackColor() const; | 
| 249 |     QColor switchDisabledUncheckedTrackColor() const; | 
| 250 |     QColor switchDisabledCheckedTrackColor() const; | 
| 251 |     QColor switchDisabledUncheckedTrackBorderColor() const; | 
| 252 |     QColor switchUncheckedHandleColor() const; | 
| 253 |     QColor switchUncheckedHoveredHandleColor() const; | 
| 254 |     QColor switchCheckedHandleColor() const; | 
| 255 |     QColor switchDisabledUncheckedHandleColor() const; | 
| 256 |     QColor switchDisabledCheckedHandleColor() const; | 
| 257 |     QColor switchDisabledCheckedIconColor() const; | 
| 258 |     QColor switchDisabledUncheckedIconColor() const; | 
| 259 |     QColor scrollBarColor() const; | 
| 260 |     QColor scrollBarHoveredColor() const; | 
| 261 |     QColor scrollBarPressedColor() const; | 
| 262 |     QColor dialogColor() const; | 
| 263 |     QColor backgroundDimColor() const; | 
| 264 |     QColor listHighlightColor() const; | 
| 265 |     QColor tooltipColor() const; | 
| 266 |     QColor toolBarColor() const; | 
| 267 |     QColor toolTextColor() const; | 
| 268 |     QColor spinBoxDisabledIconColor() const; | 
| 269 |     QColor sliderDisabledColor() const; | 
| 270 |     QColor textFieldFilledContainerColor() const; | 
| 271 |  | 
| 272 |     Q_INVOKABLE QColor color(Color color, Shade shade = Shade500) const; | 
| 273 |     Q_INVOKABLE QColor shade(const QColor &color, Shade shade) const; | 
| 274 |  | 
| 275 |     int touchTarget() const; | 
| 276 |     int buttonVerticalPadding() const; | 
| 277 |     Q_INVOKABLE int buttonLeftPadding(bool flat, bool hasIcon) const; | 
| 278 |     Q_INVOKABLE int buttonRightPadding(bool flat, bool hasIcon, bool hasText) const; | 
| 279 |     int buttonHeight() const; | 
| 280 |     int delegateHeight() const; | 
| 281 |     int dialogButtonBoxHeight() const; | 
| 282 |     int dialogTitleFontPixelSize() const; | 
| 283 |     RoundedScale dialogRoundedScale() const; | 
| 284 |     int frameVerticalPadding() const; | 
| 285 |     int () const; | 
| 286 |     int () const; | 
| 287 |     int switchIndicatorWidth() const; | 
| 288 |     int switchIndicatorHeight() const; | 
| 289 |     int switchNormalHandleHeight() const; | 
| 290 |     int switchCheckedHandleHeight() const; | 
| 291 |     int switchLargestHandleHeight() const; | 
| 292 |     int switchDelegateVerticalPadding() const; | 
| 293 |     int textFieldHeight() const; | 
| 294 |     int textFieldHorizontalPadding() const; | 
| 295 |     int textFieldVerticalPadding() const; | 
| 296 |     int tooltipHeight() const; | 
| 297 |  | 
| 298 |     static void initGlobals(); | 
| 299 |  | 
| 300 |     static Variant variant(); | 
| 301 |  | 
| 302 | Q_SIGNALS: | 
| 303 |     void themeChanged(); | 
| 304 |     void primaryChanged(); | 
| 305 |     void accentChanged(); | 
| 306 |     void foregroundChanged(); | 
| 307 |     void backgroundChanged(); | 
| 308 |     void elevationChanged(); | 
| 309 |  | 
| 310 |     void themeOrAccentChanged(); | 
| 311 |  | 
| 312 |     void primaryHighlightedTextColorChanged(); | 
| 313 |     void dialogColorChanged(); | 
| 314 |     void tooltipColorChanged(); | 
| 315 |     void toolBarColorChanged(); | 
| 316 |     void toolTextColorChanged(); | 
| 317 |     void roundedScaleChanged(); | 
| 318 |     void containerStyleChanged(); | 
| 319 |  | 
| 320 | protected: | 
| 321 |     void attachedParentChange(QQuickAttachedPropertyPropagator *newParent, QQuickAttachedPropertyPropagator *oldParent) override; | 
| 322 |  | 
| 323 | private: | 
| 324 |     void init(); | 
| 325 |     bool variantToRgba(const QVariant &var, const char *name, QRgb *rgba, bool *custom) const; | 
| 326 |  | 
| 327 |     QColor backgroundColor(Shade shade) const; | 
| 328 |     QColor accentColor(Shade shade) const; | 
| 329 |  | 
| 330 |     Shade themeShade() const; | 
| 331 |  | 
| 332 |     // These reflect whether a color value was explicitly set on the specific | 
| 333 |     // item that this attached style object represents. | 
| 334 |     bool m_explicitTheme = false; | 
| 335 |     bool m_explicitPrimary = false; | 
| 336 |     bool m_explicitAccent = false; | 
| 337 |     bool m_explicitForeground = false; | 
| 338 |     bool m_explicitBackground = false; | 
| 339 |     // These reflect whether the color value that was either inherited or | 
| 340 |     // explicitly set is in the form that QColor expects, rather than one of | 
| 341 |     // our pre-defined color enum values. | 
| 342 |     bool m_customPrimary = false; | 
| 343 |     bool m_customAccent = false; | 
| 344 |     bool m_customForeground = false; | 
| 345 |     bool m_customBackground = false; | 
| 346 |     // These will be true when this item has an explicit or inherited foreground/background | 
| 347 |     // color, or these colors were declared globally via settings (e.g. conf or env vars). | 
| 348 |     // Some color properties of the style will return different values depending on whether | 
| 349 |     // or not these are set. | 
| 350 |     bool m_hasForeground = false; | 
| 351 |     bool m_hasBackground = false; | 
| 352 |     // The actual values for this item, whether explicit, inherited or globally set. | 
| 353 |     bool m_systemTheme = false; | 
| 354 |     Theme m_theme = Light; | 
| 355 |     uint m_primary = 0; | 
| 356 |     uint m_accent = 0; | 
| 357 |     uint m_foreground = 0; | 
| 358 |     uint m_background = 0; | 
| 359 |     int m_elevation = 0; | 
| 360 |     RoundedScale m_roundedScale = RoundedScale::NotRounded; | 
| 361 |     ContainerStyle m_containerStyle = ContainerStyle::Filled; | 
| 362 | }; | 
| 363 |  | 
| 364 | QT_END_NAMESPACE | 
| 365 |  | 
| 366 | #endif // QQUICKMATERIALSTYLE_P_H | 
| 367 |  |