123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #pragma once
- #include "Common.h"
- #include "CommonDraw.h"
- /// <summary>
- /// 用于绘制功能块的接口Interface
- /// </summary>
- class POU;
- class WindowAppItemInterface : public QObject, public QGraphicsLineItem
- {
- Q_OBJECT
- Q_INTERFACES(QGraphicsItem)
- public:
- WindowAppItemInterface(
- _INTERFACE* pInfEx,
- POU* pPou,
- const TOOL* pTool,
- bool bShowOnly = false,
- QGraphicsItem* parent = nullptr
- );
- // 设定本Item的自定义类型
- enum { Type = ITEM_TYPE_INF };
- int type() const
- {
- // 针对该 item 启用 qgraphicsitem_cast
- return Type;
- }
- // 对应的接口数据信息(仅供绘图读取使用,不允许更改)
- _INTERFACE* m_infInfo;
- public:
- // 更新最新的父矩形区域
- void updateParentRect(QRectF parentRect);
- // 根据Block的位置和自身的序号更新本接口的位置
- void updatePostion(int nIndex = 0);
- // 根据Block的位置计算ToolStart接口的位置
- void updateToolInterfacePostion();
- protected:
- // 矩形边界
- QRectF boundingRect() const override;
- // 形状边界(为了扩大接口区域的可点击范围)
- QPainterPath shape() const override;
- void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
- QWidget* widget = nullptr) override;
- protected slots:
- // 鼠标双击
- void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
- // 显示右键菜单
- void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
- // 菜单 - Link
- void onMenuLink(QAction* action);
- // 菜单 - Unlink
- void onMenuUnlink();
- // 菜单 - Smartlink
- void onMenuSmartlink();
- // 菜单 - Add Watch
- void onMenuAddWatch();
- // 菜单 - Add Port
- void onMenuAddPort();
- // 菜单 - Disable
- void onMenuDisable();
- //void mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
- void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
- //void hoverMoveEvent(QGraphicsSceneHoverEvent* event);
- //void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
- //void mouseReleaseEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
- protected:
- // 判断父Block是否处于选中状态
- bool IsParentSelected();
- // 创建动态右键菜单
- void createDynamicContextMenu();
- // 绘制接口线条
- void drawInterfaceLine(QPainter* painter);
- // 绘制接口文字
- void drawInterfaceText(QPainter* painter);
- // 绘制Goto输出接口的三角形
- void drawArrowOutput(QPainter* painter, int nFixHeight = 0);
- // 绘制并行工具的输出接口(并行母线)
- void drawParallelOutput(QPainter* painter);
- // 更新常规接口位置
- void updateRegularPostion(int nIndex = 0);
- // 更新Goto输出接口位置
- void updateGotoPosition();
- // 更新Parallel输出接口位置
- void updateParallelPosition();
- protected:
- // 接口标题的位置
- QPointF m_ptInfTitle;
- // 是否仅供展示使用(不提供右键菜单以及其他互动)
- bool m_bShowOnly;
- public:
- // Pou的管理对象
- POU* m_pPou;
- // 本接口所属的TOOL
- const TOOL* m_pParentTool;
- // 父控件的矩形区域
- QRectF m_parentRect;
- // 并行母线的线段长度(会随着连线情况动态变化,仅用于接口是并行母线的情况)
- // int m_nParallelLineLen;
- // QLineF m_parallelLine;
- };
|