DiagramDesigner/source/graphicsItem/itemPort.cpp

78 lines
2.5 KiB
C++
Raw Normal View History

2024-12-07 17:24:36 +08:00
#include <QPainter>
#include "graphicsItem/itemPort.h"
ItemPort::ItemPort(QGraphicsItem *parent)
: ItemControlHandle(parent)
{
_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 = rect();
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(rect().center(), HNDLE_SIZE / 4, HNDLE_SIZE / 4);
}
/*if(m_type==T_lineIn)
{
painter->setPen(Qt::NoPen);
painter->setBrush(Qt::green);
painter->drawEllipse(rect().center(), HNDLE_SIZE / 2, HNDLE_SIZE / 2);
}
else if(m_type==T_lineOut)
{
painter->setPen(Qt::NoPen);
painter->setBrush(Qt::red);
painter->drawEllipse(rect().center(), HNDLE_SIZE / 2, HNDLE_SIZE / 2);
}*/
//ItemControlHandle::paint(painter,option,widget);
}