|
|
@@ -7,6 +7,11 @@ Comparator::Comparator(const QString &type) : Item(type) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
QRectF Comparator::boundingRect() const |
|
|
|
{ |
|
|
|
return QRectF(-22, -20, 44, 40); |
|
|
|
} |
|
|
|
|
|
|
|
void Comparator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) |
|
|
|
{ |
|
|
|
painter->setRenderHint(QPainter::Antialiasing); |
|
|
@@ -21,15 +26,20 @@ void Comparator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option |
|
|
|
painter->drawEllipse(QPointF(-18, 0), 4, 4); |
|
|
|
painter->drawEllipse(QPointF(18, 0), 4, 4); |
|
|
|
} |
|
|
|
if (!registerId_.isEmpty()) { |
|
|
|
painter->save(); |
|
|
|
painter->setFont(QFont("Arial", 8)); |
|
|
|
painter->setPen(Qt::black); |
|
|
|
// 在元件底部居中绘制寄存器ID |
|
|
|
painter->drawText(boundingRect().adjusted(0, 20, 0, 0), |
|
|
|
Qt::AlignCenter, registerId_); |
|
|
|
if (!registerId_.isEmpty()) { |
|
|
|
QString text = QString("%1: %2").arg(registerId_).arg(registerValue_); |
|
|
|
painter->drawText(QRectF(-20, -25, 40, 20), Qt::AlignCenter, text); |
|
|
|
} |
|
|
|
|
|
|
|
// 在右上角显示第二个寄存器 |
|
|
|
if (!registerId2_.isEmpty()) { |
|
|
|
QString text = QString("%1: %2").arg(registerId2_).arg(registerValue2_); |
|
|
|
painter->drawText(QRectF(-20, 5, 40, 20), Qt::AlignCenter, text); |
|
|
|
} |
|
|
|
painter->restore(); |
|
|
|
} |
|
|
|
if (option->state & QStyle::State_Selected) { |
|
|
|
QPen pen(Qt::DashLine); |
|
|
|
pen.setColor(Qt::blue); |
|
|
@@ -39,3 +49,29 @@ void Comparator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option |
|
|
|
painter->drawRect(boundingRect()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void Comparator::setRegisterId(const QString &id) |
|
|
|
{ |
|
|
|
if (registerId_.isEmpty()) |
|
|
|
{ |
|
|
|
registerId_ = id; |
|
|
|
} |
|
|
|
else if(registerId2_.isEmpty()) |
|
|
|
{ |
|
|
|
registerId2_ = id; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void Comparator::setRegisterValue(const QString ®isterId, quint16 value) |
|
|
|
{ |
|
|
|
if (registerId_ == registerId) |
|
|
|
{ |
|
|
|
registerValue_ = value; |
|
|
|
update(); // 触发重绘 |
|
|
|
} |
|
|
|
if (registerId2_ == registerId) |
|
|
|
{ |
|
|
|
registerValue2_ = value; |
|
|
|
update(); // 触发重绘 |
|
|
|
} |
|
|
|
} |