159 lines
4.1 KiB
C++
159 lines
4.1 KiB
C++
/**
|
|
* @file ModuleConnectGraphicsItem.h
|
|
* @brief 连线Item
|
|
* @date 2011-08-17
|
|
*/
|
|
#ifndef PAI_FRAME_WORKFLOWWIDGET_MODULECONNECTGRAPHICSITEM_H
|
|
#define PAI_FRAME_WORKFLOWWIDGET_MODULECONNECTGRAPHICSITEM_H
|
|
|
|
#include <QGraphicsItem>
|
|
#include "Turtle.h"
|
|
namespace pai
|
|
{
|
|
namespace workflow
|
|
{
|
|
class CModuleConnection;
|
|
}
|
|
namespace graphics2d
|
|
{
|
|
class ModuleGraphicsItem;
|
|
}
|
|
}
|
|
|
|
namespace pai
|
|
{
|
|
namespace graphics2d
|
|
{
|
|
/**
|
|
* @class ModuleConnectGraphicsItem
|
|
* @brief 模块之间的连线
|
|
*/
|
|
class PAI_WORKFLOWWIDGET_EXPORT ModuleConnectGraphicsItem : public QGraphicsLineItem
|
|
{
|
|
public:
|
|
/**
|
|
* @brief 连线类型
|
|
*/
|
|
enum
|
|
{
|
|
Type = UserType + 1001 ///< 当前item类型
|
|
};
|
|
|
|
/**
|
|
* @brief 构造函数
|
|
* @param[in] pParent 父亲
|
|
*/
|
|
ModuleConnectGraphicsItem(QGraphicsItem *pParent = NULL);
|
|
|
|
/**
|
|
* @brief 构造函数
|
|
* @param[in] pStartItem 连线开始模块
|
|
* @param[in] startPortIndex 连线开始端口
|
|
* @param[in] pEndItem 连线结束模块
|
|
* @param[in] endPortIndex 连线结束端口
|
|
* @param[in] pParent 父亲
|
|
*/
|
|
ModuleConnectGraphicsItem(pai::graphics2d::ModuleGraphicsItem *pStartItem, int startPortIndex,
|
|
pai::graphics2d::ModuleGraphicsItem *pEndItem, int endPortIndex,
|
|
QGraphicsItem *pParent = NULL);
|
|
|
|
/**
|
|
* @brief 析构函数
|
|
*/
|
|
virtual ~ModuleConnectGraphicsItem();
|
|
|
|
/**
|
|
* @brief 获取连线类型
|
|
* @return 连线类型
|
|
*/
|
|
virtual int type() const;
|
|
|
|
/**
|
|
* @brief 实现该虚函数,返回模块连线的包围矩形
|
|
* @return 连线的包围矩形
|
|
*/
|
|
virtual QRectF boundingRect() const;
|
|
|
|
/**
|
|
* @brief 重写该虚函数,返回模块连线的形状
|
|
* @return 连线形状
|
|
*/
|
|
virtual QPainterPath shape() const;
|
|
|
|
/**
|
|
* @brief 获取连线信息
|
|
* @return 连线信息指针
|
|
*/
|
|
pai::workflow::CModuleConnection* GetConnection();
|
|
|
|
/**
|
|
* @brief 获得连线起始与终点模块
|
|
* @param[out] pStart 连线起始点
|
|
* @param[out] pEnd 连线终止点
|
|
*/
|
|
void GetConnectLineStartEnd(pai::graphics2d::ModuleGraphicsItem *&pStart,
|
|
pai::graphics2d::ModuleGraphicsItem *&pEnd);
|
|
|
|
/**
|
|
* @brief 获取连线起始端口索引
|
|
* @return 开始端口索引
|
|
*/
|
|
int GetStartPortIndex() const;
|
|
|
|
/**
|
|
* @brief 获取连线结束端口索引
|
|
* @return 结束端口索引
|
|
*/
|
|
int GetEndPortIndex() const;
|
|
|
|
/**
|
|
* @brief 获取连线起始模块
|
|
* @return 起始模块指针
|
|
*/
|
|
ModuleGraphicsItem* GetStartItem() const;
|
|
|
|
/**
|
|
* @brief 设置连线起始模块
|
|
* @param[in] pStartItem 起始模块指针
|
|
*/
|
|
void SetStartItem(ModuleGraphicsItem *pStartItem);
|
|
|
|
/**
|
|
* @brief 获取连线结束模块
|
|
* @return 结束模块指针
|
|
*/
|
|
ModuleGraphicsItem* GetEndItem() const;
|
|
|
|
/**
|
|
* @brief 设置连线结束模块
|
|
* @param[in] pEndItem 结束模块指针
|
|
*/
|
|
void SetEndItem(ModuleGraphicsItem *pEndItem);
|
|
|
|
/**
|
|
* @brief 更新位置
|
|
*/
|
|
void UpdatePosition();
|
|
|
|
protected:
|
|
/**
|
|
* @brief 实现该虚函数,绘制模块连线图元
|
|
* @param[in] pPainter 画笔
|
|
* @param[in] pOption 模块风格
|
|
* @param[in] pWidget 画布
|
|
*/
|
|
void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget *pWidget = NULL);
|
|
|
|
private:
|
|
pai::graphics2d::ModuleGraphicsItem *m_pStartItem; ///< 起始模块图元
|
|
pai::graphics2d::ModuleGraphicsItem *m_pEndItem; ///< 中止模块图元
|
|
int m_StartPortIndex; ///< 指示了起始模块的第几个输出端口
|
|
int m_EndPortIndex; ///< 指示了中止模块的第几个输入端口
|
|
QPolygonF m_ArrowHead; ///< 连线箭头形状
|
|
pai::workflow::CModuleConnection *m_pConnection; ///< 连线对象指针
|
|
};
|
|
|
|
}
|
|
}
|
|
#endif ///< PAI_FRAME_WORKFLOWWIDGET_MODULECONNECTGRAPHICSITEM_H
|