forked from CURTLab/LVGLBuilder
-
Notifications
You must be signed in to change notification settings - Fork 18
/
LVGLSimulator.h
107 lines (82 loc) · 2.64 KB
/
LVGLSimulator.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
#ifndef LVGLSIMULATOR_H
#define LVGLSIMULATOR_H
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QTextStream>
#include "lvgl/lvgl.h"
class LVGLObject;
class LVGLItem;
class LVGLObjectModel;
class LVGLPropertyModel;
class LVGLScene : public QGraphicsScene {
Q_OBJECT
public:
LVGLScene(QObject *parent = nullptr);
LVGLObject *selected() const;
LVGLObject *hoverObject() const;
void setHoverObject(LVGLObject *hoverObject);
public slots:
void setSelected(LVGLObject *selected);
protected:
virtual void drawBackground(QPainter *painter, const QRectF &rect) override;
private:
LVGLObject *m_selected;
LVGLObject *m_hoverObject;
};
class LVGLSimulator : public QGraphicsView {
Q_OBJECT
public:
explicit LVGLSimulator(QWidget *parent = nullptr);
~LVGLSimulator() override;
LVGLObject *selectedObject() const;
LVGLItem *item() const;
void moveObject(LVGLObject *obj, int dx, int dy);
void addObject(LVGLObject *obj);
void removeObject(LVGLObject *obj);
void setObjectModel(LVGLObjectModel *objectModel);
void setPropertyModel(LVGLPropertyModel *propertyModel);
void setobjParent(lv_obj_t *parent);
public slots:
void setSelectedObject(LVGLObject *obj);
void setZoomLevel(int level);
void clear();
void setMouseEnable(bool enable);
void changeResolution(QSize size);
signals:
void objectSelected(LVGLObject *obj);
void objectPositionChanged();
void objectAdded(LVGLObject *obj);
protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseDoubleClickEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void dropEvent(QDropEvent *event) override;
void dragMoveEvent(QDragMoveEvent *event) override;
void dragEnterEvent(QDragEnterEvent *event) override;
private slots:
void update();
private:
LVGLObject *selectObject(QList<LVGLObject *> objs, bool doubleClick) const;
QList<LVGLObject *> objectsUnderCoords(QPoint pos, bool includeLocked) const;
void generateCodeObject(QTextStream &stream, LVGLObject *o);
// void parseJson(QJsonObject object, LVGLObject *parent = nullptr);
LVGLScene *m_scene;
LVGLObject *m_selectedObject;
bool m_mouseEnabled;
LVGLItem *m_item;
LVGLObjectModel *m_objectModel;
lv_obj_t *m_parent;
LVGLPropertyModel *m_propertyModel;
};
class LVGLKeyPressEventFilter : public QObject {
Q_OBJECT
public:
explicit LVGLKeyPressEventFilter(LVGLSimulator *sim,
QObject *parent = nullptr);
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
private:
LVGLSimulator *m_sim;
};
#endif // LVGLSIMULATOR_H