DiagramDesigner/diagramCavas/source/graphicsItem/electricSvgItemRect.cpp

78 lines
2.1 KiB
C++

#include "graphicsItem/electricSvgItemRect.h"
#include "graphicsItem/itemPort.h"
#include <QPainter>
#include <QStyleOption>
#include <QGraphicsScene>
#include <QGraphicsView>
ElectricSvgItemRect::ElectricSvgItemRect(const QRect &rect, QGraphicsItem *parent)
: ElectricSvgItem(rect,parent)
{
loadSvg(":/images/element/svg_rect.svg");
setHandleIfShow(H_textCaption,false);
setHandleIfShow(H_textCurrent,false);
setHandleIfShow(h_textVoltage,false);
setHandleVisible(false);
setFunctionHandleIfShow(false);
setFunctionHandleEnaable(false);
//入线口
ItemPort* pHandle1 = new ItemPort(this);
pHandle1->setType(T_lineIn);
pHandle1->setTag(H_connect);
pHandle1->setPortPos(P_top);
pHandle1->setParent(this);
m_vecHanle.insert(H_connect,pHandle1);
//出线口
ItemPort* pHandle2 = new ItemPort(this);
pHandle2->setType(T_lineOut);
pHandle2->setTag(H_connect+1);
pHandle2->setPortPos(P_down);
pHandle2->setParent(this);
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);
qRegisterMetaType<PropertyInfo>("PropertyInfo"); //注册自定义数据类型
}
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);
}
void ElectricSvgItemRect::updateByProperty()
{
}