综合平台编辑器
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.

44 line
1.1 KiB

  1. #ifndef CUSTOMGRAPHICSSCENE_H
  2. #define CUSTOMGRAPHICSSCENE_H
  3. #include <QGraphicsScene>
  4. #include "customgraphics.h"
  5. class QGraphicsSceneMouseEvent;
  6. class QGraphicsSceneContextMenuEvent;
  7. class QGraphicsView;
  8. class QKeyEvent;
  9. class CustomGraphicsScene : public QGraphicsScene
  10. {
  11. Q_OBJECT
  12. public:
  13. enum Mode { Normal, CreateItem };
  14. explicit CustomGraphicsScene(QGraphicsView* view, QObject *parent = nullptr);
  15. void setMode(Mode mode);
  16. void setComponentTypeToCreate(ComponentType type);
  17. signals:
  18. void componentCreated(HmiComponent* item);
  19. // 转发键盘操作请求
  20. void copyRequestFromScene();
  21. void pasteRequestFromScene(const QPointF& scenePos); // 传递粘贴位置
  22. void deleteRequestFromScene();
  23. protected:
  24. void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
  25. void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
  26. void keyPressEvent(QKeyEvent *keyEvent) override;
  27. void contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent) override;
  28. private:
  29. Mode m_mode;
  30. ComponentType m_componentTypeToCreate;
  31. QGraphicsView* m_view;
  32. };
  33. #endif // CUSTOMGRAPHICSSCENE_H