-
Notifications
You must be signed in to change notification settings - Fork 142
/
LVGLProperty.h
246 lines (187 loc) · 6.49 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#ifndef LVGLPROPERTY_H
#define LVGLPROPERTY_H
#include <QVariant>
#include <QJsonValue>
#include <lvgl/lvgl.h>
#include <functional>
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:
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 LVGLPropertyCoord : public LVGLPropertyType<lv_coord_t>
{
public:
LVGLPropertyCoord(LVGLProperty *parent = nullptr);
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;
int m_max;
};
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;
};
template<class T>
class LVGLPropertyValT : public LVGLPropertyType<T>
{
public:
LVGLPropertyValT(T min, T max, QString title,
QString functionName, std::function<void(lv_obj_t*, T)> setter,
std::function<T(lv_obj_t*)> getter,
LVGLProperty *parent = nullptr);
QWidget *editor(QWidget *parent) override;
void updateEditor(LVGLObject *obj) override;
void updateWidget(LVGLObject *obj) override;
QString name() const override;
QStringList function(LVGLObject *obj) const override;
protected:
virtual T get(LVGLObject *obj) const override;
virtual void set(LVGLObject *obj, T value) override;
QSpinBox *m_widget;
T m_min;
T m_max;
QString m_title;
QString m_functionName;
std::function<void(lv_obj_t*, T)> m_setter;
std::function<T(lv_obj_t*)> m_getter;
};
class LVGLPropertyValInt16 : public LVGLPropertyValT<int16_t>
{
public:
LVGLPropertyValInt16(int16_t min, int16_t max, QString title,
QString functionName, std::function<void(lv_obj_t*, int16_t)> setter,
std::function<int16_t(lv_obj_t*)> getter,
LVGLProperty *parent = nullptr);
};
class LVGLPropertyValUInt16 : public LVGLPropertyValT<uint16_t>
{
public:
LVGLPropertyValUInt16(uint16_t min, uint16_t max, QString title,
QString functionName, std::function<void(lv_obj_t*, uint16_t)> setter,
std::function<uint16_t(lv_obj_t*)> getter,
LVGLProperty *parent = nullptr);
};
class LVGLPropertyBool : public LVGLPropertyType<bool>
{
public:
LVGLPropertyBool(QString title = "", QString functionName = "", LVGLProperty *parent = nullptr);
LVGLPropertyBool(QString title, QString functionName,
std::function<void(lv_obj_t*, bool)> setter,
std::function<bool(lv_obj_t*)> getter,
LVGLProperty *parent = nullptr);
QWidget *editor(QWidget *parent) override;
void updateEditor(LVGLObject *obj) override;
void updateWidget(LVGLObject *obj) override;
QString name() const override;
QStringList function(LVGLObject *obj) const override;
protected:
bool get(LVGLObject *obj) const override;
void set(LVGLObject *obj, bool boolean) override;
QComboBox *m_widget;
QString m_title;
QString m_functionName;
std::function<void(lv_obj_t*, bool)> m_setter;
std::function<bool(lv_obj_t*)> m_getter;
};
class LVGLPropertyString : public LVGLPropertyType<QString>
{
public:
LVGLPropertyString(QString title = "", QString functionName = "", LVGLProperty *parent = nullptr);
LVGLPropertyString(QString title, QString functionName,
std::function<void(lv_obj_t*, const char*)> setter,
std::function<const char*(lv_obj_t*)> getter,
LVGLProperty *parent = nullptr);
QString name() const override;
QWidget *editor(QWidget *parent) override;
void updateEditor(LVGLObject *obj) override;
void updateWidget(LVGLObject *obj) override;
QStringList function(LVGLObject *obj) const override;
protected:
QString get(LVGLObject *obj) const override;
void set(LVGLObject *obj, QString string) override;
QLineEdit *m_widget;
QString m_title;
QString m_functionName;
std::function<void(lv_obj_t*, const char*)> m_setter;
std::function<const char*(lv_obj_t*)> m_getter;
};
#endif // LVGLPROPERTY_H