69 lines
2.3 KiB
C++
69 lines
2.3 KiB
C++
#include <QPainter>
|
|
#include "graphicsItem/itemPort.h"
|
|
#include "graphicsItem/handleRect.h"
|
|
|
|
ItemPort::ItemPort(QGraphicsItem *parent,QString uuid)
|
|
: HandleRect(parent),_uuid(uuid)
|
|
{
|
|
_pos = P_top;
|
|
_ptr = nullptr;
|
|
}
|
|
|
|
ItemPort::~ItemPort()
|
|
{
|
|
}
|
|
|
|
void ItemPort::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
|
{
|
|
Q_UNUSED(option)
|
|
Q_UNUSED(widget)
|
|
|
|
painter->setPen(Qt::SolidLine);
|
|
painter->setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
QPolygonF Triangle;
|
|
QRectF rec = boundingRect();
|
|
qreal left = rec.left();
|
|
qreal right = rec.right();
|
|
qreal width = rec.width();
|
|
qreal height = rec.height();
|
|
qreal bottom = rec.bottom();
|
|
painter->setBrush(Qt::black);
|
|
if((_pos == P_top && m_type == T_lineIn) || (_pos == P_down && m_type == T_lineOut) ) //从上入或者从下出都是向下
|
|
{
|
|
Triangle.append(QPointF(left,0));
|
|
Triangle.append(QPointF(right,0));
|
|
Triangle.append(QPointF(left+width*0.5,bottom));
|
|
painter->drawPolygon(Triangle);
|
|
}
|
|
else if((_pos == P_top && m_type == T_lineOut) || (_pos == P_down && m_type == T_lineIn) ) //从上出或者从下入都是向上
|
|
{
|
|
Triangle.append(QPointF(left,bottom));
|
|
Triangle.append(QPointF(right,bottom));
|
|
Triangle.append(QPointF(left+width*0.5,0));
|
|
painter->drawPolygon(Triangle);
|
|
}
|
|
else if((_pos == P_left && m_type == T_lineIn) || (_pos == P_right && m_type == T_lineOut) ) //从左入或者从右出都是向右
|
|
{
|
|
Triangle.append(QPointF(0,0));
|
|
Triangle.append(QPointF(0,bottom));
|
|
Triangle.append(QPointF(right,height*0.5));
|
|
painter->drawPolygon(Triangle);
|
|
}
|
|
else if((_pos == P_left && m_type == T_lineOut) || (_pos == P_right && m_type == T_lineIn) ) //从左出或者从右入都是向左
|
|
{
|
|
Triangle.append(QPointF(right,0));
|
|
Triangle.append(QPointF(right,bottom));
|
|
Triangle.append(QPointF(0,height*0.5));
|
|
painter->drawPolygon(Triangle);
|
|
}
|
|
else if(m_type == T_lineInOut)
|
|
{
|
|
painter->drawEllipse(boundingRect().center(), HNDLE_SIZE / 4, HNDLE_SIZE / 4);
|
|
}
|
|
else if(m_type == T_newTral)
|
|
{
|
|
painter->drawEllipse(boundingRect().center(), HNDLE_SIZE / 4, HNDLE_SIZE / 4);
|
|
}
|
|
}
|