forked from staunchheart/LVGLBuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLVGLProperty.h
161 lines (119 loc) · 3.82 KB
/
LVGLProperty.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#ifndef LVGLPROPERTY_H
#define LVGLPROPERTY_H
#include <QVariant>
#include <QJsonValue>
#include <lvgl/lvgl.h>
class LVGLObject;
class QComboBox;
class QLineEdit;
class QSpinBox;
class LVGLProperty {
public:
LVGLProperty(LVGLProperty *parent = nullptr);
virtual ~LVGLProperty();
virtual QString name() const = 0;
virtual bool hasEditor() const;
virtual QWidget *editor(QWidget *parent);
virtual void updateEditor(LVGLObject *obj);
virtual void updateWidget(LVGLObject *obj);
virtual QVariant defaultValue() const;
virtual QVariant value(LVGLObject *obj) const;
virtual void setValue(LVGLObject *obj, QVariant value);
virtual QJsonValue toJson(LVGLObject *obj) const;
const LVGLProperty *parent() const;
int count() const;
const LVGLProperty *child(int index) const;
int row() const;
int indexOf(const LVGLProperty *item) const;
virtual QStringList function(LVGLObject *obj) const;
protected:
const LVGLProperty *m_parent;
QList<const LVGLProperty*> m_childs;
};
template <class T>
class LVGLPropertyType : public LVGLProperty
{
public:
inline LVGLPropertyType(LVGLProperty *parent = nullptr) : LVGLProperty(parent) {}
inline QVariant value(LVGLObject *obj) const override { return get(obj); }
inline void setValue(LVGLObject *obj, QVariant value) override { return set(obj, value.value<T>()); }
inline bool hasEditor() const override { return true; }
protected:
virtual T get(LVGLObject *obj) const = 0;
virtual void set(LVGLObject *obj, T value) = 0;
};
class LVGLPropertyEnum : public LVGLProperty
{
public:
LVGLPropertyEnum(QStringList enumText, LVGLProperty *parent = nullptr);
QVariant value(LVGLObject *obj) const override;
void setValue(LVGLObject *obj, QVariant value) override;
bool hasEditor() const override;
QWidget *editor(QWidget *parent) override;
void updateEditor(LVGLObject *obj) override;
void updateWidget(LVGLObject *obj) override;
protected:
QStringList m_enum;
QComboBox *m_widget;
virtual int get(LVGLObject *obj) const = 0;
virtual void set(LVGLObject *obj, int value) = 0;
};
class LVGLPropertyBool : public LVGLPropertyType<bool>
{
public:
QWidget *editor(QWidget *parent) override;
void updateEditor(LVGLObject *obj) override;
void updateWidget(LVGLObject *obj) override;
protected:
QComboBox *m_widget;
};
class LVGLPropertyString : public LVGLPropertyType<QString>
{
public:
QWidget *editor(QWidget *parent) override;
void updateEditor(LVGLObject *obj) override;
void updateWidget(LVGLObject *obj) override;
protected:
QLineEdit *m_widget;
};
class LVGLPropertyCoord : public LVGLPropertyType<lv_coord_t>
{
public:
LVGLPropertyCoord(Qt::Orientation orientation, LVGLProperty *parent = nullptr);
QWidget *editor(QWidget *parent) override;
void updateEditor(LVGLObject *obj) override;
void updateWidget(LVGLObject *obj) override;
protected:
QSpinBox *m_widget;
Qt::Orientation m_orientation;
};
class LVGLPropertyInt : public LVGLPropertyType<int>
{
public:
LVGLPropertyInt(int min, int max, LVGLProperty *parent = nullptr);
LVGLPropertyInt(int min, int max, QString surfix, LVGLProperty *parent = nullptr);
QWidget *editor(QWidget *parent) override;
void updateEditor(LVGLObject *obj) override;
void updateWidget(LVGLObject *obj) override;
protected:
QSpinBox *m_widget;
int m_min;
int m_max;
QString m_surfix;
};
class LVGLPropertyFont : public LVGLProperty
{
public:
LVGLPropertyFont(LVGLProperty *parent = nullptr);
QVariant value(LVGLObject *obj) const override;
void setValue(LVGLObject *obj, QVariant value) override;
bool hasEditor() const override;
QWidget *editor(QWidget *parent) override;
void updateEditor(LVGLObject *obj) override;
void updateWidget(LVGLObject *obj) override;
protected:
QComboBox *m_widget;
virtual const lv_font_t *get(LVGLObject *obj) const = 0;
virtual void set(LVGLObject *obj, const lv_font_t *value) = 0;
};
#endif // LVGLPROPERTY_H