81 lines
2.0 KiB
C
81 lines
2.0 KiB
C
|
|
#ifndef ELECTRICCONNECTLINEITEM_H
|
||
|
|
#define ELECTRICCONNECTLINEITEM_H
|
||
|
|
|
||
|
|
#include <QPainterPath>
|
||
|
|
#include "graphicsBaseItem.h"
|
||
|
|
|
||
|
|
struct Connection
|
||
|
|
{
|
||
|
|
int nSrcNodeId;
|
||
|
|
int nSrcPort;
|
||
|
|
HandleType srcType;
|
||
|
|
int nDestNodeId;
|
||
|
|
int nDestPort;
|
||
|
|
HandleType destType;
|
||
|
|
|
||
|
|
Connection()
|
||
|
|
{
|
||
|
|
|
||
|
|
nSrcNodeId = -1;
|
||
|
|
nSrcPort = -1;
|
||
|
|
srcType = T_none;
|
||
|
|
nDestNodeId = -1;
|
||
|
|
nDestPort = -1;
|
||
|
|
destType = T_none;
|
||
|
|
}
|
||
|
|
|
||
|
|
Connection(int nSNI,int nSP,HandleType sT,int nDNI,int nDP,HandleType dT)
|
||
|
|
{
|
||
|
|
nSrcNodeId = nSNI;
|
||
|
|
nSrcPort = nSP;
|
||
|
|
srcType = sT;
|
||
|
|
nDestNodeId = nDNI;
|
||
|
|
nDestPort = nDP;
|
||
|
|
destType = dT;
|
||
|
|
}
|
||
|
|
bool operator==(Connection& obj)
|
||
|
|
{
|
||
|
|
return ((obj.nSrcNodeId == nSrcNodeId)&&(obj.nSrcPort == nSrcPort)&&(obj.srcType == srcType)&&(obj.nDestNodeId == nDestNodeId)&&(obj.nDestPort == nDestPort)&&(obj.destType == destType));
|
||
|
|
}
|
||
|
|
|
||
|
|
Connection& operator=(Connection& obj)
|
||
|
|
{
|
||
|
|
if(*this == obj)
|
||
|
|
return *this;
|
||
|
|
nSrcNodeId = obj.nSrcNodeId;
|
||
|
|
nSrcPort = obj.nSrcPort;
|
||
|
|
srcType = obj.srcType;
|
||
|
|
nDestNodeId = obj.nDestNodeId;
|
||
|
|
nDestPort = obj.nDestPort;
|
||
|
|
destType = obj.destType;
|
||
|
|
return *this;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
class ElectricConnectLineItem : public GraphicsBaseItem
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
ElectricConnectLineItem(QGraphicsItem *parent = 0);
|
||
|
|
virtual ~ElectricConnectLineItem();
|
||
|
|
|
||
|
|
void setStartPoint(const QPointF& p){m_pStart = p;}
|
||
|
|
void setEndPoint(const QPointF& p){m_pEnd = p;}
|
||
|
|
QPainterPath getPoints(void) const { return m_points; }
|
||
|
|
|
||
|
|
void calculatePath();
|
||
|
|
bool addConnection();
|
||
|
|
|
||
|
|
void updateConnection(int callerId,QPointF pos); //外部调用的更新函数,id为调用者id
|
||
|
|
void setConnection(Connection con){m_connectState = con;}
|
||
|
|
protected:
|
||
|
|
virtual QPainterPath shape();
|
||
|
|
virtual void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*);
|
||
|
|
private:
|
||
|
|
Connection m_connectState;
|
||
|
|
QPainterPath m_points;
|
||
|
|
QPointF m_pStart;
|
||
|
|
QPointF m_pEnd;
|
||
|
|
};
|
||
|
|
|
||
|
|
#endif
|