mirror of https://github.com/mgba-emu/mgba.git
Qt: Improve I/O viewer UI
This commit is contained in:
parent
142940cc69
commit
8db357979a
|
@ -7,9 +7,9 @@
|
||||||
|
|
||||||
#include "GameController.h"
|
#include "GameController.h"
|
||||||
|
|
||||||
|
#include <QComboBox>
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QRadioButton>
|
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -840,7 +840,17 @@ void IOViewer::selectRegister(unsigned address) {
|
||||||
QSpinBox* sbox = new QSpinBox;
|
QSpinBox* sbox = new QSpinBox;
|
||||||
sbox->setEnabled(!ri.readonly);
|
sbox->setEnabled(!ri.readonly);
|
||||||
sbox->setMaximum((1 << ri.size) - 1);
|
sbox->setMaximum((1 << ri.size) - 1);
|
||||||
|
sbox->setAccelerated(true);
|
||||||
box->addWidget(sbox, i, 1, Qt::AlignRight);
|
box->addWidget(sbox, i, 1, Qt::AlignRight);
|
||||||
|
|
||||||
|
connect(sbox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [sbox, this, &ri](int v) {
|
||||||
|
for (int o = 0; o < ri.size; ++o) {
|
||||||
|
bool signalsBlocked = m_b[o + ri.start]->blockSignals(true);
|
||||||
|
m_b[o + ri.start]->setChecked(v & (1 << o));
|
||||||
|
m_b[o + ri.start]->blockSignals(signalsBlocked);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
auto connection = connect(this, &IOViewer::valueChanged, [sbox, &ri, this]() {
|
auto connection = connect(this, &IOViewer::valueChanged, [sbox, &ri, this]() {
|
||||||
int v = (m_value >> ri.start) & ((1 << ri.size) - 1);
|
int v = (m_value >> ri.start) & ((1 << ri.size) - 1);
|
||||||
bool signalsBlocked = sbox->blockSignals(true);
|
bool signalsBlocked = sbox->blockSignals(true);
|
||||||
|
@ -851,32 +861,35 @@ void IOViewer::selectRegister(unsigned address) {
|
||||||
this->disconnect(connection);
|
this->disconnect(connection);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
QButtonGroup* group = new QButtonGroup(box);
|
QComboBox* cbox = new QComboBox;
|
||||||
group->setExclusive(true);
|
cbox->setEnabled(!ri.readonly);
|
||||||
|
++i;
|
||||||
|
box->addWidget(cbox, i, 0, 1, 2, Qt::AlignRight);
|
||||||
for (int o = 0; o < 1 << ri.size; ++o) {
|
for (int o = 0; o < 1 << ri.size; ++o) {
|
||||||
if (ri.items.at(o).isNull()) {
|
if (ri.items.at(o).isNull()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
++i;
|
cbox->addItem(ri.items.at(o), o);
|
||||||
QRadioButton* button = new QRadioButton(ri.items.at(o));
|
|
||||||
button->setEnabled(!ri.readonly);
|
|
||||||
box->addWidget(button, i, 0, 1, 2, Qt::AlignLeft);
|
|
||||||
group->addButton(button, o);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto connection = connect(this, &IOViewer::valueChanged, [group, this, &ri]() {
|
connect(cbox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [cbox, this, &ri](int index) {
|
||||||
unsigned v = (m_value >> ri.start) & ((1 << ri.size) - 1);
|
unsigned v = cbox->itemData(index).toUInt();
|
||||||
for (int i = 0; i < 1 << ri.size; ++i) {
|
for (int o = 0; o < ri.size; ++o) {
|
||||||
QAbstractButton* button = group->button(i);
|
bool signalsBlocked = m_b[o + ri.start]->blockSignals(true);
|
||||||
if (!button) {
|
m_b[o + ri.start]->setChecked(v & (1 << o));
|
||||||
continue;
|
m_b[o + ri.start]->blockSignals(signalsBlocked);
|
||||||
}
|
|
||||||
bool signalsBlocked = button->blockSignals(true);
|
|
||||||
button->setChecked(i == v);
|
|
||||||
button->blockSignals(signalsBlocked);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connect(group, &QObject::destroyed, [connection, this]() {
|
|
||||||
|
auto connection = connect(this, &IOViewer::valueChanged, [cbox, this, &ri]() {
|
||||||
|
unsigned v = (m_value >> ri.start) & ((1 << ri.size) - 1);
|
||||||
|
for (int i = 0; i < 1 << ri.size; ++i) {
|
||||||
|
if (cbox->itemData(i) == v) {
|
||||||
|
cbox->setCurrentIndex(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
connect(cbox, &QObject::destroyed, [connection, this]() {
|
||||||
this->disconnect(connection);
|
this->disconnect(connection);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue