|
- #ifndef HMIEDITOR_H
- #define HMIEDITOR_H
-
- #include <QWidget>
- #include <QPainter>
- #include <QMouseEvent>
- #include <vector>
-
- // 图形元素基类
- class Shape {
- public:
- enum Type { Circle, Rectangle };
-
- Shape(Type type, const QRect& rect) : type(type), rect(rect) {}
- virtual void draw(QPainter& painter) const;
-
- Type type;
- QRect rect;
- };
-
- class HMIEditor : public QWidget
- {
- Q_OBJECT
-
- public:
- explicit HMIEditor(QWidget *parent = nullptr);
-
- public slots:
- void onDrawCircle();
- void onDrawRect();
-
- protected:
- void paintEvent(QPaintEvent *event) override;
- void mousePressEvent(QMouseEvent *event) override;
- void mouseReleaseEvent(QMouseEvent *event) override;
- void mouseMoveEvent(QMouseEvent *event) override;
-
- private:
- std::vector<Shape> shapes;
- Shape::Type currentShapeType;
- bool isDrawing;
- QRect currentDrawingRect;
- };
-
- #endif // HMIEDITOR_H
|