QmlMaterial 0.1.0
Loading...
Searching...
No Matches
color.hpp
1#pragma once
2
3#include <unordered_map>
4
5#include <QtQml/QQmlEngine>
6#include <QtGui/QColor>
7
8#include "qml_material/core.hpp"
9#include "qml_material/enum.hpp"
10#include "qml_material/helper.hpp"
11
12namespace qml_material
13{
14
15struct QColorCompare {
16 using is_transparent = void;
17 bool operator()(const QColor& a, const QColor& b) const noexcept { return a.rgba() < b.rgba(); }
18};
19
26class MdColorMgr : public QObject {
27 Q_OBJECT
28 QML_ELEMENT
29public:
30 using Self = MdColorMgr;
31
32 MdColorMgr(QObject* = nullptr);
33
38 Q_PROPERTY(qml_material::Enum::ThemeMode mode READ mode WRITE setMode NOTIFY modeChanged FINAL)
39
40
44 Q_PROPERTY(qml_material::Enum::PaletteType paletteType READ paletteType WRITE setPaletteType
45 NOTIFY paletteTypeChanged FINAL)
46
47
51 Q_PROPERTY(
52 QColor accentColor READ accentColor WRITE setAccentColor NOTIFY accentColorChanged FINAL)
53
58 Q_PROPERTY(bool useSysColorSM READ useSysColorSM WRITE setUseSysColorSM NOTIFY
59 useSysColorSMChanged FINAL)
60
65 Q_PROPERTY(bool useSysAccentColor READ useSysAccentColor WRITE setUseSysAccentColor NOTIFY
66 useSysAccentColorChanged FINAL)
67
68#define X(_n_) \
69 Q_PROPERTY(QColor _n_ READ _n_ NOTIFY schemeChanged) \
70 QColor _n_() const { return m_scheme._n_; }
71
154#undef X
155
156public:
157 auto mode() const -> Enum::ThemeMode;
158 auto sysColorScheme() const -> Enum::ThemeMode;
159
160 QColor sysAccentColor() const;
161 QColor accentColor() const;
162 bool useSysColorSM() const;
163 bool useSysAccentColor() const;
164 auto paletteType() const -> Enum::PaletteType;
165 void setPaletteType(Enum::PaletteType);
166
167 Q_INVOKABLE QColor getOn(QColor) const;
168
169 Q_SLOT void setMode(Enum::ThemeMode);
170 Q_SLOT void setAccentColor(QColor);
171 Q_SLOT void setUseSysColorSM(bool);
172 Q_SLOT void setUseSysAccentColor(bool);
173 Q_SLOT void genScheme();
174 Q_SLOT void refrehFromSystem();
175
176 Q_SIGNAL void modeChanged(Enum::ThemeMode);
177 Q_SIGNAL void schemeChanged();
178 Q_SIGNAL void paletteTypeChanged();
179 Q_SIGNAL void accentColorChanged(QColor);
180 Q_SIGNAL void useSysColorSMChanged();
181 Q_SIGNAL void useSysAccentColorChanged();
182
183private:
184 void genSchemeImpl(Enum::ThemeMode);
185
186 QColor m_accent_color;
187 Enum::ThemeMode m_mode;
188 Enum::ThemeMode m_last_mode;
189 Enum::PaletteType m_scheme_type;
190 MdScheme m_scheme;
191 std::map<QColor, QColor, QColorCompare> m_on_map;
192 bool m_use_sys_color_scheme;
193 bool m_use_sys_accent_color;
194};
195
196void sysNotifyInit(MdColorMgr&);
197auto sysColorScheme() -> Enum::ThemeMode;
198auto sysAccentColor() -> QColor;
199
200} // namespace qml_material
Enum.
Definition enum.hpp:13
ThemeMode
Definition enum.hpp:20
Material Design Color Manager class.
Definition color.hpp:26
QColor surface_container_lowest
Lowest container variant of surface color.
Definition color.hpp:149
QColor surface_3
Third elevation variant of surface color.
Definition color.hpp:135
bool useSysColorSM
Whether to use system color scheme mode.
Definition color.hpp:59
QColor surface_dim
Dimmed version of surface color.
Definition color.hpp:141
QColor surface_container_low
Low container variant of surface color.
Definition color.hpp:147
QColor on_surface
Color for content on surface.
Definition color.hpp:111
QColor background
Main background color.
Definition color.hpp:105
QColor primary_container
A softer background color related to primary.
Definition color.hpp:77
QColor on_primary
Color used for content (text/icons) on primary color.
Definition color.hpp:75
QColor surface_container_highest
Highest container variant of surface color.
Definition color.hpp:153
QColor on_secondary
Color for content on secondary color.
Definition color.hpp:83
QColor surface_container
Base container variant of surface color.
Definition color.hpp:145
QColor error
Color used for error states.
Definition color.hpp:97
QColor shadow
Color used for shadows.
Definition color.hpp:121
QColor surface_container_high
High container variant of surface color.
Definition color.hpp:151
QColor on_error_container
Color for content on error container.
Definition color.hpp:103
QColor error_container
A softer background color for error states.
Definition color.hpp:101
QColor inverse_surface
Inverse of the surface color.
Definition color.hpp:125
QColor tertiary_container
A softer background color related to tertiary.
Definition color.hpp:93
QColor surface_1
First elevation variant of surface color.
Definition color.hpp:131
qml_material::Enum::ThemeMode mode
Current theme mode (light/dark)
Definition color.hpp:38
QColor inverse_on_surface
Color for content on inverse surface.
Definition color.hpp:127
QColor on_error
Color for content on error color.
Definition color.hpp:99
QColor on_background
Color for content on background.
Definition color.hpp:107
QColor surface
Surface color for cards, sheets, and menus.
Definition color.hpp:109
QColor surface_bright
Brightened version of surface color.
Definition color.hpp:143
QColor surface_4
Fourth elevation variant of surface color.
Definition color.hpp:137
QColor secondary
The secondary color used for less prominent components.
Definition color.hpp:81
QColor primary
The primary color of the theme.
Definition color.hpp:73
QColor inverse_primary
Inverse of the primary color.
Definition color.hpp:129
QColor on_tertiary_container
Color for content on tertiary container.
Definition color.hpp:95
QColor surface_variant
Alternative surface color.
Definition color.hpp:113
QColor on_tertiary
Color for content on tertiary color.
Definition color.hpp:91
QColor accentColor
Primary accent color for the theme.
Definition color.hpp:52
QColor on_surface_variant
Color for content on surface variant.
Definition color.hpp:115
QColor outline
Color for borders and dividers.
Definition color.hpp:117
QColor surface_5
Fifth elevation variant of surface color.
Definition color.hpp:139
QColor secondary_container
A softer background color related to secondary.
Definition color.hpp:85
QColor tertiary
The tertiary color for specific emphasis.
Definition color.hpp:89
QColor scrim
Color used for screen dimming.
Definition color.hpp:123
QColor on_primary_container
Color for content on primary container.
Definition color.hpp:79
QColor outline_variant
Subtle version of outline color.
Definition color.hpp:119
bool useSysAccentColor
Whether to use system accent color.
Definition color.hpp:66
QColor surface_2
Second elevation variant of surface color.
Definition color.hpp:133
QColor on_secondary_container
Color for content on secondary container.
Definition color.hpp:87