58 lines
1.3 KiB
C++
58 lines
1.3 KiB
C++
#include "graphicsItem/electricConnectLineItem.h"
|
|
#include <QGraphicsScene>
|
|
#include <QPainter>
|
|
|
|
|
|
ElectricConnectLineItem::ElectricConnectLineItem(QGraphicsItem *parent)
|
|
: GraphicsBaseItem(parent)
|
|
{
|
|
m_pen = QPen(Qt::black);
|
|
m_brush = QBrush(Qt::NoBrush);
|
|
setHandleVisible(false);
|
|
setFunctionHandleIfShow(false);
|
|
setFunctionHandleEnaable(false);
|
|
}
|
|
|
|
ElectricConnectLineItem::~ElectricConnectLineItem()
|
|
{
|
|
}
|
|
|
|
QPainterPath ElectricConnectLineItem::shape()
|
|
{
|
|
QPainterPath path;
|
|
path.addPath(m_points);
|
|
path.closeSubpath(); //将路径闭合
|
|
return path;
|
|
}
|
|
|
|
void ElectricConnectLineItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
|
{
|
|
painter->setPen(m_pen);
|
|
painter->setBrush(m_brush);
|
|
|
|
painter->drawPath(m_points);
|
|
}
|
|
|
|
|
|
void ElectricConnectLineItem::calculatePath()
|
|
{
|
|
prepareGeometryChange();
|
|
m_points.clear();
|
|
|
|
m_points.moveTo(m_pStart);
|
|
m_points.lineTo(m_pEnd.x(),m_pStart.y());
|
|
m_points.lineTo(m_pEnd);
|
|
}
|
|
|
|
void ElectricConnectLineItem::updateConnection(int callerId,QPointF pos)
|
|
{
|
|
qDebug()<<pos;
|
|
if(callerId == m_connectState.nSrcNodeId)
|
|
setStartPoint(pos);
|
|
else if(callerId == m_connectState.nDestNodeId)
|
|
setEndPoint(pos);
|
|
else
|
|
qDebug()<<"ConnectLine update err";
|
|
calculatePath();
|
|
}
|