WindowAppBlockPort.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #include "WindowAppBlockBase.h"
  3. /// <summary>
  4. /// Port类型的工具功能块图 (Port Block Diagram, PBD)
  5. /// </summary>
  6. class WindowAppBlockPort : public WindowAppBlockBase
  7. {
  8. Q_OBJECT
  9. // 添加这一行,否则会出现警告:Warning: qobject_cast to QGraphicsItem will not work!
  10. Q_INTERFACES(QGraphicsItem)
  11. public:
  12. WindowAppBlockPort(TOOL* newPort, POU* Pou, bool bShowOnly = false, QGraphicsObject* parent = nullptr);
  13. // 添加接口
  14. void addItemInterfaces();
  15. // 绑定一个接口
  16. void bindInterface(_INTERFACE* pNewInf);
  17. // 设定本Item的自定义类型
  18. enum { Type = ITEM_TYPE_PORT };
  19. int type() const
  20. {
  21. // 针对该 item 启用 qgraphicsitem_cast
  22. return Type;
  23. }
  24. protected:
  25. void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
  26. // QVariant itemChange(GraphicsItemChange change, const QVariant& value) override;
  27. // QRectF boundingRect() const override;
  28. // 绘制功能块
  29. void DrawBlock(QPainter* painter);
  30. protected slots:
  31. //// 显示右键菜单
  32. //void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
  33. // 鼠标单击
  34. // void mousePressEvent(QGraphicsSceneMouseEvent* event)override;
  35. // 鼠标双击
  36. void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
  37. protected:
  38. // 根据用户的输入实时更新矩形区域的尺寸
  39. virtual void updateRect();
  40. // 各个菜单的响应函数
  41. // 初始化功能块的右键菜单
  42. void createContextMenu();
  43. // 菜单 - Delete
  44. void onMenuDelete();
  45. // 2022-3-22 为Port中显示的接口名称做调整(局部变量不加Pou前缀,全局变量加Pou前缀)
  46. QString genPortInfName(const _INTERFACE* pNewInf);
  47. protected:
  48. // 本port上绑定的接口显示的文字
  49. QString m_strInfTitle;
  50. };