#include "graphicsItem/electricSvgItemRect.h" #include "graphicsItem/itemControlHandle.h" #include #include ElectricSvgItemRect::ElectricSvgItemRect(const QRect &rect, QGraphicsItem *parent) : ElectricSvgItem(rect,parent) { loadSvg(":/images/element/svg_rect.svg"); //入线口 ItemControlHandle* pHandle1 = new ItemControlHandle(this); pHandle1->setType(T_lineIn); pHandle1->setTag(H_connect); m_vecHanle.insert(H_connect,pHandle1); //出线口 ItemControlHandle* pHandle2 = new ItemControlHandle(this); pHandle2->setType(T_lineOut); pHandle2->setTag(H_connect+1); m_vecHanle.insert(H_connect+1,pHandle2); m_dRatioX = 0.5; } 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); }