WindowAppItemInterface.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #pragma once
  2. #include "Common.h"
  3. #include "CommonDraw.h"
  4. /// <summary>
  5. /// 用于绘制功能块的接口Interface
  6. /// </summary>
  7. class POU;
  8. class WindowAppItemInterface : public QObject, public QGraphicsLineItem
  9. {
  10. Q_OBJECT
  11. Q_INTERFACES(QGraphicsItem)
  12. public:
  13. WindowAppItemInterface(
  14. _INTERFACE* pInfEx,
  15. POU* pPou,
  16. const TOOL* pTool,
  17. bool bShowOnly = false,
  18. QGraphicsItem* parent = nullptr
  19. );
  20. // 设定本Item的自定义类型
  21. enum { Type = ITEM_TYPE_INF };
  22. int type() const
  23. {
  24. // 针对该 item 启用 qgraphicsitem_cast
  25. return Type;
  26. }
  27. // 对应的接口数据信息(仅供绘图读取使用,不允许更改)
  28. _INTERFACE* m_infInfo;
  29. public:
  30. // 更新最新的父矩形区域
  31. void updateParentRect(QRectF parentRect);
  32. // 根据Block的位置和自身的序号更新本接口的位置
  33. void updatePostion(int nIndex = 0);
  34. // 根据Block的位置计算ToolStart接口的位置
  35. void updateToolInterfacePostion();
  36. protected:
  37. // 矩形边界
  38. QRectF boundingRect() const override;
  39. // 形状边界(为了扩大接口区域的可点击范围)
  40. QPainterPath shape() const override;
  41. void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
  42. QWidget* widget = nullptr) override;
  43. protected slots:
  44. // 鼠标双击
  45. void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
  46. // 显示右键菜单
  47. void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
  48. // 菜单 - Link
  49. void onMenuLink(QAction* action);
  50. // 菜单 - Unlink
  51. void onMenuUnlink();
  52. // 菜单 - Smartlink
  53. void onMenuSmartlink();
  54. // 菜单 - Add Watch
  55. void onMenuAddWatch();
  56. // 菜单 - Add Port
  57. void onMenuAddPort();
  58. // 菜单 - Disable
  59. void onMenuDisable();
  60. //void mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
  61. void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
  62. //void hoverMoveEvent(QGraphicsSceneHoverEvent* event);
  63. //void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
  64. //void mouseReleaseEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
  65. protected:
  66. // 判断父Block是否处于选中状态
  67. bool IsParentSelected();
  68. // 创建动态右键菜单
  69. void createDynamicContextMenu();
  70. // 绘制接口线条
  71. void drawInterfaceLine(QPainter* painter);
  72. // 绘制接口文字
  73. void drawInterfaceText(QPainter* painter);
  74. // 绘制Goto输出接口的三角形
  75. void drawArrowOutput(QPainter* painter, int nFixHeight = 0);
  76. // 绘制并行工具的输出接口(并行母线)
  77. void drawParallelOutput(QPainter* painter);
  78. // 更新常规接口位置
  79. void updateRegularPostion(int nIndex = 0);
  80. // 更新Goto输出接口位置
  81. void updateGotoPosition();
  82. // 更新Parallel输出接口位置
  83. void updateParallelPosition();
  84. protected:
  85. // 接口标题的位置
  86. QPointF m_ptInfTitle;
  87. // 是否仅供展示使用(不提供右键菜单以及其他互动)
  88. bool m_bShowOnly;
  89. public:
  90. // Pou的管理对象
  91. POU* m_pPou;
  92. // 本接口所属的TOOL
  93. const TOOL* m_pParentTool;
  94. // 父控件的矩形区域
  95. QRectF m_parentRect;
  96. // 并行母线的线段长度(会随着连线情况动态变化,仅用于接口是并行母线的情况)
  97. // int m_nParallelLineLen;
  98. // QLineF m_parallelLine;
  99. };