File indexing completed on 2024-05-05 04:46:53
0001 #pragma once 0002 0003 #include <QObject> 0004 #include <QFont> 0005 #include <QColor> 0006 #include <QVariant> 0007 #include <QQmlEngine> 0008 #include <QFontMetrics> 0009 0010 namespace MauiMan 0011 { 0012 class ThemeManager; 0013 class BackgroundManager; 0014 class AccessibilityManager; 0015 } 0016 0017 /** 0018 * @brief The Unit group properties. 0019 * These properties are standard values meant to be used across the UI elements for a cohesive look and feel. 0020 * 0021 * @note This object can not be instantiated. It only exists as part of the Style::units implementation, which ca be accessed via the global Style singleton. 0022 */ 0023 class Units : public QObject 0024 { 0025 Q_OBJECT 0026 Q_PROPERTY(uint gridUnit MEMBER m_gridUnit CONSTANT FINAL) 0027 Q_PROPERTY(uint veryLongDuration MEMBER m_veryLongDuration CONSTANT FINAL) 0028 Q_PROPERTY(uint longDuration MEMBER m_longDuration CONSTANT FINAL) 0029 Q_PROPERTY(uint shortDuration MEMBER m_shortDuration CONSTANT FINAL) 0030 Q_PROPERTY(uint veryShortDuration MEMBER m_veryShortDuration CONSTANT FINAL) 0031 Q_PROPERTY(uint humanMoment MEMBER m_humanMoment CONSTANT FINAL) 0032 Q_PROPERTY(uint toolTipDelay MEMBER m_toolTipDelay CONSTANT FINAL) 0033 0034 public: 0035 explicit Units(QObject *parent = nullptr); 0036 0037 private: 0038 QFontMetricsF m_fontMetrics; 0039 uint m_gridUnit; 0040 uint m_veryLongDuration; 0041 uint m_longDuration; 0042 uint m_shortDuration; 0043 uint m_veryShortDuration; 0044 uint m_humanMoment; 0045 uint m_toolTipDelay; 0046 }; 0047 0048 /** 0049 * @brief The sizes group for some Style properties, such as Style::iconSize, Style::space, etc. 0050 * 0051 * @note This object can not be instantiated. It only exists as part of some of the Style property implementations, which ca be accessed via the global Style singleton. 0052 */ 0053 class GroupSizes : public QObject 0054 { 0055 Q_OBJECT 0056 Q_PROPERTY(uint tiny MEMBER m_tiny NOTIFY sizesChanged FINAL) 0057 Q_PROPERTY(uint small MEMBER m_small NOTIFY sizesChanged FINAL) 0058 Q_PROPERTY(uint medium MEMBER m_medium NOTIFY sizesChanged FINAL) 0059 Q_PROPERTY(uint big MEMBER m_big NOTIFY sizesChanged FINAL) 0060 Q_PROPERTY(uint large MEMBER m_large NOTIFY sizesChanged FINAL) 0061 Q_PROPERTY(uint huge MEMBER m_huge NOTIFY sizesChanged FINAL) 0062 Q_PROPERTY(uint enormous MEMBER m_enormous NOTIFY sizesChanged FINAL) 0063 0064 public: 0065 explicit GroupSizes(const uint tiny,const uint small, const uint medium, const uint big, const uint large, const uint huge, const uint enormous, QObject *parent = nullptr); 0066 GroupSizes(QObject *parent = nullptr); 0067 0068 uint m_tiny; 0069 uint m_small; 0070 uint m_medium; 0071 uint m_big; 0072 uint m_large; 0073 uint m_huge; 0074 uint m_enormous; 0075 0076 Q_SIGNALS: 0077 void sizesChanged(); 0078 }; 0079 0080 /** 0081 * @brief The MauiKit Style preferences singleton object. 0082 * 0083 */ 0084 class Style : public QObject 0085 { 0086 Q_OBJECT 0087 QML_ELEMENT 0088 QML_ATTACHED(Style) 0089 QML_UNCREATABLE("Cannot be created Style") 0090 Q_DISABLE_COPY(Style) 0091 0092 /** 0093 * The standard height size for the toolbars, such as ToolBar, TabBar, etc. Usually this is used as the minimum height fo those bars. 0094 * @note This property is read only. 0095 */ 0096 Q_PROPERTY(uint toolBarHeight MEMBER m_toolBarHeight CONSTANT FINAL) 0097 0098 /** 0099 * An alternative size for the tab bars, this is a bit smaller then the `toolBarHeight`. 0100 * @see toolBarHeight 0101 * 0102 */ 0103 Q_PROPERTY(uint toolBarHeightAlt MEMBER m_toolBarHeightAlt CONSTANT FINAL) 0104 0105 /** 0106 * The preferred radius for the border corners of the UI elements. 0107 * @note This property is read only. It can only be modified from the MauiMan global preferences. 0108 */ 0109 Q_PROPERTY(uint radiusV MEMBER m_radiusV NOTIFY radiusVChanged FINAL) 0110 0111 /** 0112 * The preferred size for painting the icons in places, such as menus, buttons and delegates. 0113 * @note This property is read only. It can only be modified from the MauiMan global preferences. 0114 */ 0115 Q_PROPERTY(uint iconSize READ iconSize NOTIFY iconSizeChanged FINAL) 0116 0117 /** 0118 * The standard size for the height of elements represented as a row. Such as items in lists. 0119 * This can be used for keeping a coherent look, when an implicit height is not desired, or as the minimum height. 0120 */ 0121 Q_PROPERTY(uint rowHeight MEMBER m_rowHeight CONSTANT FINAL) 0122 0123 /** 0124 * An alternative height to the `rowHeight`, this size is a bit smaller. 0125 */ 0126 Q_PROPERTY(uint rowHeightAlt MEMBER m_rowHeightAlt CONSTANT FINAL) 0127 0128 /** 0129 * The preferred size for the margins in the browsing views, such as the ListBrowser and GridBrowser, but also for the margins in menus. 0130 * @note This property is read only. It can only be modified from the MauiMan global preferences. 0131 */ 0132 Q_PROPERTY(uint contentMargins MEMBER m_contentMargins NOTIFY contentMarginsChanged) 0133 0134 /** 0135 * The preferred font size for the text labels in the UI elements. 0136 * @note This property is read only. It can only be modified from the MauiMan global preferences. 0137 */ 0138 Q_PROPERTY(uint defaultFontSize MEMBER m_defaultFontSize CONSTANT FINAL) 0139 0140 /** 0141 * The preferred padding size for the UI elements, such a menu entries, buttons, bars, etc. 0142 * The padding refers to the outer-space around the visible background area of the elements. 0143 * @note This property is read only. It can only be modified from the MauiMan global preferences. 0144 */ 0145 Q_PROPERTY(uint defaultPadding MEMBER m_defaultPadding NOTIFY defaultPaddingChanged) 0146 0147 /** 0148 * The preferred spacing size between elements in rows or columns, etc. 0149 * @note This property is read only. It can only be modified from the MauiMan global preferences. 0150 */ 0151 Q_PROPERTY(uint defaultSpacing MEMBER m_defaultSpacing NOTIFY defaultSpacingChanged) 0152 0153 /** 0154 * The preferred font for the text in labels. 0155 * @note This property is read only. It can only be modified from the MauiMan global preferences. 0156 */ 0157 Q_PROPERTY(QFont defaultFont MEMBER m_defaultFont NOTIFY defaultFontChanged) 0158 0159 /** 0160 * The preferred font for titles and headers. 0161 */ 0162 Q_PROPERTY(QFont h1Font MEMBER m_h1Font NOTIFY h1FontChanged) 0163 0164 /** 0165 * The preferred font for subtitles. 0166 */ 0167 Q_PROPERTY(QFont h2Font MEMBER m_h2Font NOTIFY h2FontChanged) 0168 0169 /** 0170 * The preferred mono spaced font. 0171 * @note This property is read only. It can only be modified from the MauiMan global preferences. 0172 */ 0173 Q_PROPERTY(QFont monospacedFont MEMBER m_monospacedFont NOTIFY monospacedFontChanged) 0174 0175 /** 0176 * The group of different standard font sizes for the MauiKit applications. 0177 * @see GroupSizes 0178 */ 0179 Q_PROPERTY(GroupSizes *fontSizes MEMBER m_fontSizes NOTIFY fontSizesChanged) 0180 0181 /** 0182 * The group of different standard spacing values for consistency in the MauiKit apps. 0183 * @see GroupSizes 0184 */ 0185 Q_PROPERTY(GroupSizes *space MEMBER m_space CONSTANT FINAL) 0186 0187 /** 0188 * The group of different standard icon sizes for consistency in the MauiKit apps. 0189 * @see GroupSizes 0190 * Values are the standard: 16, 22, 32 ,48, 64, 128 [pixels] 0191 */ 0192 Q_PROPERTY(GroupSizes *iconSizes MEMBER m_iconSizes CONSTANT FINAL) 0193 0194 /** 0195 * The standard units group. See the Units documentation for more information. 0196 */ 0197 Q_PROPERTY(Units *units MEMBER m_units CONSTANT FINAL) 0198 0199 /** 0200 * Sets the color to be used for highlighted, active, checked and such states of the UI elements. 0201 * By default this color is set to the global preferences via MauiMan. 0202 * This can be overridden by each application to a custom color. To reset it back to the system preference set the property to `undefined`. 0203 */ 0204 Q_PROPERTY(QColor accentColor READ accentColor WRITE setAccentColor NOTIFY accentColorChanged FINAL RESET unsetAccentColor) 0205 0206 /** 0207 * The source for picking up the application color palette when the style type is set to Style.Adaptive. 0208 * The source can be an image URL, and QQC2 Image, or a QQC2 Item, or even an icon name. 0209 * By default the source for this is set to the MauiMan wallpaper source preference. 0210 */ 0211 Q_PROPERTY(QVariant adaptiveColorSchemeSource READ adaptiveColorSchemeSource WRITE setAdaptiveColorSchemeSource NOTIFY adaptiveColorSchemeSourceChanged RESET unsetAdaptiveColorSchemeSource) 0212 0213 /** 0214 * The preferred style type for setting the color scheme of the application. 0215 * @see StyleType 0216 * By default this is set to the MauiMan global preference. 0217 * It can be overridden by the application, and to reset it - back to the original system preference - by setting this to `undefined`. 0218 */ 0219 Q_PROPERTY(StyleType styleType READ styleType WRITE setStyleType NOTIFY styleTypeChanged RESET unsetStyeType) 0220 0221 /** 0222 * Whether special effects are desired. This can be tweaked in the MauiMan system preferences in cases where the resources need to be preserved. 0223 * Consider using this property when using special effects in your applications. 0224 * @note This property is read-only. It can only be modified from the MauiMan global preferences. 0225 */ 0226 Q_PROPERTY(bool enableEffects READ enableEffects NOTIFY enableEffectsChanged FINAL) 0227 0228 /** 0229 * The current system icon theme picked up by the user. 0230 * @note This property is read-only. It can only be modified from the MauiMan global preferences. 0231 * @warning This only works when using the Maui Shell ecosystem. There is not support for Plasma or GNOME desktops. 0232 */ 0233 Q_PROPERTY(QString currentIconTheme READ currentIconTheme NOTIFY currentIconThemeChanged) 0234 0235 /** 0236 * Whether the menu entries should display the icon image. 0237 * @note This property is read-only. This is picked by from the QPA Qt Theme integration platform, so its default value will depend on the desktop shell being used. 0238 */ 0239 Q_PROPERTY(bool menusHaveIcons READ menusHaveIcons CONSTANT FINAL) 0240 0241 /** 0242 * The preferred scroll bars policy for displaying them or not. 0243 * @note This property is read-only. This is picked by from the QPA Qt Theme integration platform, so its default value will depend on the desktop shell being used. 0244 */ 0245 Q_PROPERTY(uint scrollBarPolicy READ scrollBarPolicy NOTIFY scrollBarPolicyChanged FINAL) 0246 0247 /** 0248 * Whether the user desires for the application to play sounds or not. 0249 * @note This property is read-only. It can only be modified from the MauiMan global preferences. 0250 */ 0251 Q_PROPERTY(bool playSounds READ playSounds NOTIFY playSoundsChanged FINAL) 0252 0253 /** 0254 * Whether the application window surface should be transparent and request the compositor to blur the background area of the window surface. 0255 * By default this is set to `false`. 0256 */ 0257 Q_PROPERTY(bool translucencyAvailable READ translucencyAvailable NOTIFY translucencyAvailableChanged) 0258 0259 public: 0260 /** 0261 * @brief The different options for the color scheme style. 0262 */ 0263 enum StyleType : uint 0264 { 0265 /** 0266 * A light variant designed for Maui. 0267 */ 0268 Light = 0, 0269 0270 /** 0271 * A dark variant designed for Maui. 0272 */ 0273 Dark, 0274 0275 /** 0276 * Picks the color scheme based on an source input, such as an image. The generated color palette determines if it is a dark or light scheme, and also its accent color. 0277 */ 0278 Adaptive, 0279 0280 /** 0281 * Picks the colors from the system palette, usually from Plasma color-scheme files. 0282 * @note Use this type when mixing MauiKit with Kirigami controls, so both frameworks pick up the color palette from the same source. 0283 */ 0284 Auto, 0285 0286 /** 0287 * A fully black color palette with a full white accent color. This is might be useful as a accessibility enhance or for performance on E-Ink and AMOLED displays. 0288 */ 0289 TrueBlack, 0290 0291 /** 0292 * A fully white color palette with a true black accent color. This is the inverted version of the TrueBlack type. 0293 */ 0294 Inverted 0295 }; Q_ENUM(StyleType) 0296 0297 /** 0298 * @private 0299 */ 0300 static Style *qmlAttachedProperties(QObject *object); 0301 0302 /** 0303 * @private 0304 */ 0305 static Style *instance() 0306 { 0307 if (m_instance) 0308 return m_instance; 0309 0310 m_instance = new Style; 0311 return m_instance; 0312 } 0313 0314 QVariant adaptiveColorSchemeSource() const; 0315 void setAdaptiveColorSchemeSource(const QVariant &source); 0316 void unsetAdaptiveColorSchemeSource(); 0317 0318 QColor accentColor() const; 0319 void setAccentColor(const QColor &color); 0320 void unsetAccentColor(); 0321 0322 StyleType styleType() const; 0323 void setStyleType(const StyleType &type); 0324 void unsetStyeType(); 0325 0326 void setRadiusV(const uint &radius); 0327 0328 bool enableEffects() const; 0329 0330 uint iconSize() const; 0331 0332 QString currentIconTheme() const; 0333 0334 bool menusHaveIcons() const; 0335 bool playSounds() const; 0336 uint scrollBarPolicy() const; 0337 0338 bool translucencyAvailable() const; 0339 void setTranslucencyAvailable(const bool &value); 0340 0341 public Q_SLOTS: 0342 /** 0343 * @brief Given a `size` as argument this function will return the best fitted icon size from the standard icon sizes. 0344 * For example for the a size of 36, this function should return a size of 32. 0345 */ 0346 int mapToIconSizes(const int &size); 0347 0348 private: 0349 explicit Style(QObject *parent = nullptr); 0350 static Style *m_instance; 0351 0352 QFont m_defaultFont; 0353 QFont m_h1Font = QFont {}; 0354 QFont m_h2Font = QFont {}; 0355 QFont m_monospacedFont = QFont {}; 0356 0357 GroupSizes *m_iconSizes; 0358 GroupSizes *m_space; 0359 GroupSizes *m_fontSizes; 0360 Units *m_units; 0361 0362 uint m_defaultFontSize; 0363 0364 uint m_toolBarHeight = 42; 0365 uint m_toolBarHeightAlt = 38; 0366 uint m_radiusV = 4; 0367 uint m_iconSize = 22; 0368 uint m_rowHeight = 32; 0369 uint m_rowHeightAlt = 28; 0370 0371 uint m_contentMargins; 0372 uint m_defaultPadding; 0373 uint m_defaultSpacing; 0374 0375 QColor m_accentColor; 0376 bool m_accentColor_blocked = false; 0377 0378 QVariant m_adaptiveColorSchemeSource; 0379 bool m_adaptiveColorSchemeSource_blocked = false; 0380 0381 StyleType m_styleType; 0382 bool m_styleType_blocked = false; 0383 0384 MauiMan::ThemeManager *m_themeSettings; 0385 MauiMan::BackgroundManager *m_backgroundSettings; 0386 MauiMan::AccessibilityManager *m_accessibilitySettings; 0387 0388 bool m_enableEffects = true; 0389 bool m_translucencyAvailable = false; 0390 0391 QString m_currentIconTheme; 0392 0393 void setFontSizes(); 0394 void styleChanged(); 0395 0396 Q_SIGNALS: 0397 void defaultFontChanged(); 0398 void h1FontChanged(); 0399 void h2FontChanged(); 0400 void monospacedFontChanged(); 0401 void fontSizesChanged(); 0402 0403 void adaptiveColorSchemeSourceChanged(QVariant source); 0404 void accentColorChanged(QColor color); 0405 void colorSchemeChanged(); 0406 void styleTypeChanged(StyleType type); 0407 void radiusVChanged(uint radius); 0408 void iconSizeChanged(uint size); 0409 void enableEffectsChanged(bool enableEffects); 0410 void defaultPaddingChanged(); 0411 void contentMarginsChanged(); 0412 void currentIconThemeChanged(QString currentIconTheme); 0413 void defaultSpacingChanged(); 0414 void scrollBarPolicyChanged(uint); 0415 void playSoundsChanged(bool); 0416 void translucencyAvailableChanged(bool translucencyAvailable); 0417 }; 0418 0419 // QML_DECLARE_TYPEINFO(Style, QML_HAS_ATTACHED_PROPERTIES) 0420