You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 rivejä
906 B

  1. #ifndef HMIEDITOR_H
  2. #define HMIEDITOR_H
  3. #include <QWidget>
  4. #include <QPainter>
  5. #include <QMouseEvent>
  6. #include <vector>
  7. // 图形元素基类
  8. class Shape {
  9. public:
  10. enum Type { Circle, Rectangle };
  11. Shape(Type type, const QRect& rect) : type(type), rect(rect) {}
  12. virtual void draw(QPainter& painter) const;
  13. Type type;
  14. QRect rect;
  15. };
  16. class HMIEditor : public QWidget
  17. {
  18. Q_OBJECT
  19. public:
  20. explicit HMIEditor(QWidget *parent = nullptr);
  21. public slots:
  22. void onDrawCircle();
  23. void onDrawRect();
  24. protected:
  25. void paintEvent(QPaintEvent *event) override;
  26. void mousePressEvent(QMouseEvent *event) override;
  27. void mouseReleaseEvent(QMouseEvent *event) override;
  28. void mouseMoveEvent(QMouseEvent *event) override;
  29. private:
  30. std::vector<Shape> shapes;
  31. Shape::Type currentShapeType;
  32. bool isDrawing;
  33. QRect currentDrawingRect;
  34. };
  35. #endif // HMIEDITOR_H