7#include <QtCore/QObject>
8#include <QtCore/QTimer>
9#include <QtQml/QQmlEngine>
10#include <QtGui/QColor>
12#include "qml_material/core/attached_property.hpp"
13#include "qml_material/style/motion_settings.hpp"
14#include "qml_material/token/color.hpp"
15#include "qml_material/control/page_context.hpp"
17#define ATTACH_PROPERTY(Type, Name) \
19 Q_PROPERTY(Type Name READ Name WRITE set_##Name RESET reset_##Name NOTIFY Name##Changed FINAL) \
22 void set_##Name(Type); \
23 void reset_##Name(); \
24 AttachProp<Type>& get_##Name(); \
25 Q_SIGNAL void Name##Changed(); \
28 AttachProp<Type> m_##Name { &Self::Name##Changed };
33class ThemeSize :
public QObject {
37 ThemeSize(QObject* parent =
nullptr);
40 qint32 windowClass READ windowClass WRITE setWindowClass NOTIFY windowClassChanged FINAL)
41 Q_PROPERTY(
bool isCompact READ isCompact NOTIFY windowClassChanged FINAL)
42 Q_PROPERTY(
bool isMedium READ isMedium NOTIFY windowClassChanged FINAL)
43 Q_PROPERTY(
bool isExpanded READ isExpanded NOTIFY windowClassChanged FINAL)
44 Q_PROPERTY(
bool isLarge READ isLarge NOTIFY windowClassChanged FINAL)
45 Q_PROPERTY(
bool isExtraLarge READ isExtraLarge NOTIFY windowClassChanged FINAL)
47 Q_PROPERTY(qint32 duration READ duration WRITE setDuration NOTIFY durationChanged FINAL)
48 Q_PROPERTY(qint32 width READ width WRITE setWidth NOTIFY widthChanged FINAL)
50 auto isCompact() const ->
bool;
51 auto isMedium() const ->
bool;
52 auto isExpanded() const ->
bool;
53 auto isLarge() const ->
bool;
54 auto isExtraLarge() const ->
bool;
56 auto width() const -> qint32;
57 void setWidth(qint32 w);
58 Q_SIGNAL
void widthChanged(qint32);
60 auto duration() const -> qint32;
61 void setDuration(qint32 w);
62 Q_SIGNAL
void durationChanged(qint32);
64 auto windowClass() const -> qint32;
65 void setWindowClass(qint32);
66 Q_SIGNAL
void windowClassChanged(qint32);
68 Q_PROPERTY(qint32 verticalPadding READ verticalPadding NOTIFY verticalPaddingChanged FINAL)
69 auto verticalPadding() const -> qint32;
70 Q_SIGNAL
void verticalPaddingChanged();
73 qint32 m_window_class;
79class QML_MATERIAL_API Theme final : public AttachedPropertyNode {
82 QML_NAMED_ELEMENT(MProp)
87 Q_PROPERTY(qml_material::MotionSettings* motion READ motion CONSTANT FINAL)
88 MotionSettings* motion() {
return &m_motion; }
93 using SigFunc = void (Theme::*)();
94 using ReadFunc = V (Theme::*
const)();
95 using WriteFunc = void (Theme::*)(V);
96 using GetFunc = AttachProp<V>& (Theme::*
const)();
98 std::optional<V> value;
102 AttachProp(SigFunc s): value(), explicited(false), sig_func(s) {}
105 Q_PROPERTY(QColor textColor READ textColor WRITE set_textColor RESET reset_textColor NOTIFY
106 textColorChanged BINDABLE bindableTextColor FINAL)
107 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE set_backgroundColor RESET
108 reset_backgroundColor NOTIFY backgroundColorChanged BINDABLE
109 bindableBackgroundColor FINAL)
110 QColor textColor()
const;
111 void set_textColor(QColor);
112 void reset_textColor();
113 QBindable<QColor> bindableTextColor() {
return QBindable<QColor>(&m_textColor); }
114 QColor backgroundColor()
const;
115 void set_backgroundColor(QColor);
116 void reset_backgroundColor();
117 QBindable<QColor> bindableBackgroundColor() {
return QBindable<QColor>(&m_backgroundColor); }
118 Q_SIGNAL
void textColorChanged();
119 Q_SIGNAL
void backgroundColorChanged();
120 ATTACH_PROPERTY(
int, elevation)
123 colorChanged BINDABLE bindableColor FINAL)
124 MdColorMgr* color()
const;
125 void set_color(MdColorMgr*);
127 QBindable<MdColorMgr*> bindableColor() {
return QBindable<MdColorMgr*>(&m_color); }
128 Q_SIGNAL
void colorChanged();
132 QProperty<Theme*> m_colorParent {
nullptr };
133 QMetaObject::Connection m_colorParentDestroyed;
134 QMetaObject::Connection m_colorDestroyed;
135 Q_OBJECT_BINDABLE_PROPERTY(Theme, MdColorMgr*, m_color, &Theme::colorChange)
136 Q_OBJECT_BINDABLE_PROPERTY(Theme, QColor, m_textColor, &Theme::textColorChanged)
137 Q_OBJECT_BINDABLE_PROPERTY(Theme, QColor, m_backgroundColor, &Theme::backgroundColorChanged)
138 ATTACH_PROPERTY(qml_material::ThemeSize*, size)
139 ATTACH_PROPERTY(qml_material::PageContext*, page)
142 Theme(QObject* parent);
145 static Theme* qmlAttachedProperties(QObject*
object);
148 void updateInheritedValues()
override;
151 MotionSettings m_motion {
this };
153 void setProp(AttachProp<V>& property,
const V& value);
156 void resetProp(AttachProp<V>& property,
const V& inheritedValue);
159 bool inheritProp(AttachProp<V>& property,
const V& value);
163#undef ATTACH_PROPERTY
Material Design Color Manager class.
Definition color.hpp:20