65 lines
1.7 KiB
C++
65 lines
1.7 KiB
C++
#include "graphicsItem/electricSvgItemRect.h"
|
|
#include "graphicsItem/itemPort.h"
|
|
|
|
#include <QPainter>
|
|
#include <QStyleOption>
|
|
|
|
ElectricSvgItemRect::ElectricSvgItemRect(const QRect &rect, QGraphicsItem *parent)
|
|
: ElectricSvgItem(rect,parent)
|
|
{
|
|
loadSvg(":/images/element/svg_rect.svg");
|
|
setHandleIfShow(H_textCaption,false);
|
|
setHandleVisible(false);
|
|
setFunctionHandleIfShow(false);
|
|
setFunctionHandleEnaable(false);
|
|
|
|
//入线口
|
|
ItemPort* pHandle1 = new ItemPort(this);
|
|
pHandle1->setType(T_lineIn);
|
|
pHandle1->setTag(H_connect);
|
|
pHandle1->setPortPos(P_top);
|
|
m_vecHanle.insert(H_connect,pHandle1);
|
|
//出线口
|
|
ItemPort* pHandle2 = new ItemPort(this);
|
|
pHandle2->setType(T_lineOut);
|
|
pHandle2->setTag(H_connect+1);
|
|
pHandle2->setPortPos(P_down);
|
|
m_vecHanle.insert(H_connect+1,pHandle2);
|
|
|
|
m_dRatioX = 0.5;
|
|
|
|
m_mapPort.insert(QString::number(_portId++),pHandle1);
|
|
m_mapPort.insert(QString::number(_portId++),pHandle2);
|
|
}
|
|
|
|
ElectricSvgItemRect::~ElectricSvgItemRect()
|
|
{
|
|
|
|
}
|
|
|
|
void ElectricSvgItemRect::updateHandles()
|
|
{
|
|
ElectricSvgItem::updateHandles();
|
|
if( m_vecHanle.contains(H_connect))
|
|
{
|
|
const QRectF& boundingRect = this->boundingRect();
|
|
|
|
if(m_vecHanle.contains(H_connect))
|
|
{
|
|
m_vecHanle[H_connect]->move(boundingRect.right() - boundingRect.width() * m_dRatioX, boundingRect.top());
|
|
}
|
|
|
|
if(m_vecHanle.contains(H_connect + 1))
|
|
{
|
|
m_vecHanle[H_connect + 1]->move(boundingRect.right() - boundingRect.width() * m_dRatioX, boundingRect.bottom());
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void ElectricSvgItemRect::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
|
{
|
|
ElectricSvgItem::paint(painter,option,widget);
|
|
}
|
|
|