2025-07-11 18:13:54 +08:00
|
|
|
#include "graphicsItem/electricBayItem.h"
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QStyleOption>
|
|
|
|
|
|
|
|
|
|
ElectricBayItem::ElectricBayItem(const QRectF &rect,QGraphicsItem *parent)
|
|
|
|
|
: GraphicsNonStandardItem(parent)
|
|
|
|
|
{
|
|
|
|
|
m_showRect = rect;
|
2025-10-21 18:46:51 +08:00
|
|
|
//m_boundingRect = rect;
|
2025-07-11 18:13:54 +08:00
|
|
|
m_dWidth = rect.width();
|
|
|
|
|
m_dHeight = rect.height();
|
|
|
|
|
m_font.setPointSize(12);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ElectricBayItem::~ElectricBayItem()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ElectricBayItem::setText(const QString& text)
|
|
|
|
|
{
|
|
|
|
|
prepareGeometryChange(); // 通知框架几何变化
|
|
|
|
|
m_text = text;
|
|
|
|
|
updateTextShape();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPainterPath ElectricBayItem::shape()
|
|
|
|
|
{
|
|
|
|
|
QPainterPath path;
|
|
|
|
|
path.addRect(_recLabel);
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ElectricBayItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
|
|
|
|
{
|
|
|
|
|
painter->setPen(m_pen);
|
|
|
|
|
painter->drawText(_recLabel,m_text);
|
|
|
|
|
m_pen.setStyle(Qt::DashLine);
|
|
|
|
|
if (option->state & QStyle::State_Selected) //是选中状态,绘制选中框
|
|
|
|
|
{
|
|
|
|
|
painter->drawRect(m_showRect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ElectricBayItem::updateTextShape()
|
|
|
|
|
{
|
|
|
|
|
QFontMetricsF metrics(m_font);
|
|
|
|
|
QRectF recText = metrics.boundingRect(m_text);
|
|
|
|
|
//_recLabel = recText.translated(g_offsetX,g_offsetY);
|
2025-10-21 18:46:51 +08:00
|
|
|
recText.moveTo(m_showRect.topLeft()-QPointF(recText.width(),recText.height()));
|
2025-07-11 18:13:54 +08:00
|
|
|
_recLabel = recText;
|
|
|
|
|
shape();
|
|
|
|
|
}
|