Highlight least-recently changed register
MODIFY
src/defines.h
src/defines.h
@@ -46,7 +46,8 @@ enum Colors {
BerkeleyBlue = 0x003262,
FoundersRock = 0x3B7EA1,
CaliforniaGold = 0xFDB515,
- Medalist = 0xC4820E
+ Medalist = 0xC4820E,
+ FlatGreen = 0x4cde75
};
namespace {

MODIFY
src/registercontainerwidget.cpp
src/registercontainerwidget.cpp
#include "registercontainerwidget.h"
+#include <QScrollBar>
#include "ui_registercontainerwidget.h"
#include "registerwidget.h"
@@ -72,7 +73,20 @@ void RegisterContainerWidget::init() {
reg->setDisplayType(qvariant_cast<displayTypeN>(m_ui->displayType->currentData()));
connect(m_ui->displayType, QOverload<const QString&>::of(&QComboBox::currentTextChanged),
[=] { reg->setDisplayType(qvariant_cast<displayTypeN>(m_ui->displayType->currentData())); });
+ connect(reg, &RegisterWidget::valueChanged, this, &RegisterContainerWidget::registerHasChanged);
m_ui->registerLayout->addWidget(reg);
m_registers.append(reg);
}
}
+
+void RegisterContainerWidget::registerHasChanged() {
+ RegisterWidget* sender = qobject_cast<RegisterWidget*>(QObject::sender());
+ sender->setHighlightState(true);
+ if (m_currentHighlightedReg != sender && m_currentHighlightedReg != nullptr) {
+ m_currentHighlightedReg->setHighlightState(false);
+ }
+ m_currentHighlightedReg = sender;
+
+ // Least recently changed register should always be visible in the container
+ m_ui->scrollArea->ensureWidgetVisible(sender);
+}

MODIFY
src/registercontainerwidget.h
src/registercontainerwidget.h
@@ -18,12 +18,14 @@ public:
public slots:
void update();
+ void registerHasChanged();
private:
Ui::RegisterContainerWidget* m_ui;
std::vector<uint32_t>* m_regPtr;
QList<RegisterWidget*> m_registers;
+ RegisterWidget* m_currentHighlightedReg = nullptr;
};
#endif // REGISTERCONTAINERWIDGET_H

MODIFY
src/registerwidget.cpp
src/registerwidget.cpp
@@ -34,18 +34,19 @@ void RegisterWidget::validateInput() {
void RegisterWidget::setText() {
// Sets line edit text based on current display type and register value
+ QString newValue;
if (m_displayType == displayTypeN::Hex) {
// hex
- m_ui->value->setText(QString().setNum(*m_regPtr, 16).rightJustified(8, '0')); // zero padding on hex numbers
+ newValue = QString().setNum(*m_regPtr, 16).rightJustified(8, '0'); // zero padding on hex numbers
} else if (m_displayType == displayTypeN::Binary) {
// binary
- m_ui->value->setText(QString().setNum(*m_regPtr, 2));
+ newValue = QString().setNum(*m_regPtr, 2);
} else if (m_displayType == displayTypeN::Decimal) {
// Decimal
- m_ui->value->setText(QString().setNum(*(int32_t*)m_regPtr, 10));
+ newValue = QString().setNum(*(int32_t*)m_regPtr, 10);
} else if (m_displayType == displayTypeN::Unsigned) {
// Unsigned
- m_ui->value->setText(QString().setNum(*m_regPtr, 10));
+ newValue = QString().setNum(*m_regPtr, 10);
} else if (m_displayType == displayTypeN::ASCII) {
// ASCII - valid ascii characters will not be able to fill the 32-bit
// range
@@ -55,9 +56,25 @@ void RegisterWidget::setText() {
out.append(QChar(value & 0xff));
value >>= 8;
}
- m_ui->value->setText(out);
+ newValue = out;
m_ui->value->setInputMask("nnnn");
}
+
+ // RegisterContainerWidget will set the background color for the most recently edited register
+ if (m_ui->value->text() != newValue) {
+ emit valueChanged();
+ }
+ m_ui->value->setText(newValue);
+}
+
+void RegisterWidget::setHighlightState(bool state) {
+ if (state) {
+ QPalette palette;
+ palette.setColor(QPalette::Base, QColor(Colors::Medalist).lighter(200));
+ m_ui->value->setPalette(palette);
+ } else {
+ m_ui->value->setPalette(QPalette());
+ }
}
void RegisterWidget::setNumber(int number) {

MODIFY
src/registerwidget.h
src/registerwidget.h
@@ -33,6 +33,7 @@ public:
public slots:
void setText();
void setDisplayType(displayTypeN type);
+ void setHighlightState(bool state);
private slots:
void validateInput();
@@ -45,6 +46,9 @@ private:
uint32_t* m_regPtr;
rangePair m_range;
+
+signals:
+ void valueChanged();
};
#endif // REGISTERWIDGET_H

Highlight least-recently changed register