|
|
#include "registerwidget.h"
|
|
|
#include <QPaintEvent>
|
|
|
#include <QPainter>
|
|
|
|
|
|
registerWidget::registerWidget(const QString &name, qint32 address, QWidget *parent) :
|
|
|
QWidget(parent)
|
|
|
{
|
|
|
p_address = address;
|
|
|
p_value = 0;
|
|
|
p_addressEl = new regWidgetElement(QString("0x%1").arg(p_address,8,16).replace(" ","0"),QFont("Utopia", 12),4,4);
|
|
|
p_fieldsEl = new bitfieldsElement(QString("%1").arg(p_value,32,2).replace(" ","0"),QFont("Utopia", 12),4,4);
|
|
|
p_nameEl = new regWidgetElement(name,QFont("Utopia", 12,QFont::Bold),4,4);
|
|
|
p_xMargins = 4;
|
|
|
p_yMargins = 4;
|
|
|
updateBoundingRect();
|
|
|
}
|
|
|
|
|
|
registerWidget::~registerWidget()
|
|
|
{
|
|
|
delete p_addressEl;
|
|
|
delete p_fieldsEl;
|
|
|
delete p_nameEl;
|
|
|
}
|
|
|
|
|
|
void registerWidget::paintEvent(QPaintEvent *event)
|
|
|
{
|
|
|
Q_UNUSED(event)
|
|
|
QPainter painter(this);
|
|
|
painter.translate(p_addressEl->paint(&painter));
|
|
|
painter.translate(p_fieldsEl->paint(&painter));
|
|
|
p_nameEl->paint(&painter);
|
|
|
setMinimumSize(p_boundingRect);
|
|
|
updateGeometry();
|
|
|
}
|
|
|
|
|
|
void registerWidget::setValue(qint32 value)
|
|
|
{
|
|
|
this->p_value = value;
|
|
|
this->p_fieldsEl->setValue(QString("%1").arg(p_value,32,2).replace(" ","0"));
|
|
|
this->repaint();
|
|
|
}
|
|
|
|
|
|
void registerWidget::updateBoundingRect()
|
|
|
{
|
|
|
p_boundingRect.setHeight(p_fieldsEl->boundingRect().height()+(p_yMargins*2));
|
|
|
p_boundingRect.setWidth(p_fieldsEl->boundingRect().width()+p_addressEl->boundingRect().width()+p_nameEl->boundingRect().width()+(p_xMargins*2));
|
|
|
}
|
|
|
|
|
|
|