diff options
author | bd <bdunahu@operationnull.com> | 2025-04-21 15:56:38 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-04-21 15:56:38 -0400 |
commit | 40dfec9ae067d3f8e3868d259bfc4251aeca8724 (patch) | |
tree | 28316cbc00a8e89ead3225d80b9199381a996d86 | |
parent | 89763e6f696a96ad310f031c66960bcaaba3ffdb (diff) |
Add functionality to toggle button.
-rw-r--r-- | gui/digitlabel.cc | 20 | ||||
-rw-r--r-- | gui/digitlabel.h | 12 | ||||
-rw-r--r-- | gui/gui.cc | 22 | ||||
-rw-r--r-- | gui/gui.h | 9 | ||||
-rw-r--r-- | gui/gui.ui | 5 |
5 files changed, 42 insertions, 26 deletions
diff --git a/gui/digitlabel.cc b/gui/digitlabel.cc index ffecfff..8314943 100644 --- a/gui/digitlabel.cc +++ b/gui/digitlabel.cc @@ -16,11 +16,9 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. #include "digitlabel.h" +#include "gui.h" -DigitLabel::DigitLabel(QWidget *parent) : QLabel(parent) -{ - this->update_display(); -} +DigitLabel::DigitLabel(QWidget *parent) : QLabel(parent) { setText(QString()); } void DigitLabel::clear() { @@ -31,16 +29,14 @@ void DigitLabel::clear() void DigitLabel::set_value(int v) { this->is_cleared = false; - if (this->v != v) { - this->v = v; - update_display(); - } + this->v = v; + update_display(); } -void DigitLabel::toggle_mode() +void DigitLabel::on_hex_toggle(bool is_hex) { - this->is_hex = !this->is_hex; - this->update_display(); + this->is_hex = is_hex; + update_display(); } void DigitLabel::update_display() @@ -49,7 +45,7 @@ void DigitLabel::update_display() if (this->is_cleared) { setText(QString()); } else { - t = (this->is_hex) ? QString::number(this->v, 6).toUpper() + t = (this->is_hex) ? QString::number(this->v, 16).toUpper() : QString::number(this->v); setText(t); } diff --git a/gui/digitlabel.h b/gui/digitlabel.h index 2916426..68b01cb 100644 --- a/gui/digitlabel.h +++ b/gui/digitlabel.h @@ -29,7 +29,7 @@ class DigitLabel : public QLabel * Constructor. * @return a newly allocated DigitLabel. */ - explicit DigitLabel(QWidget *parent = nullptr); + explicit DigitLabel(QWidget *parent); /** * Sets the empty flag. @@ -44,7 +44,7 @@ class DigitLabel : public QLabel /** * Toggles the base this label displays in, by setting `this->is_hex'. */ - void toggle_mode(); + void on_hex_toggle(bool is_hex); private: /** @@ -55,13 +55,13 @@ class DigitLabel : public QLabel /** * The decimal value associated with this label. */ - int v = 0; + int v; /** - * To display in hexidecimal or not. + * If this digit should display in hexidecinmal. */ - bool is_hex = true; + int is_hex; /** - * To display in hexidecimal or not. + * If this digit should not display. */ bool is_cleared = true; }; @@ -48,6 +48,13 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::GUI) worker = new Worker(); worker->moveToThread(&workerThread); + // find all the labels + QList<DigitLabel*> labels = this->findChildren<DigitLabel*>(); + for (DigitLabel* label : labels) { + connect(this, &GUI::hex_toggled, label, &DigitLabel::on_hex_toggle); + } + emit this->hex_toggled(this->is_hex); + // display clock cycles and PC connect(worker, &Worker::clock_cycles, this, &GUI::on_worker_refresh_gui); @@ -207,6 +214,7 @@ void GUI::onWorkerExecuteInfo(const std::vector<int> info) void GUI::onWorkerMemoryInfo(const std::vector<int> info) { if (!info.empty()) { + std::cout << "this " << info[3] << std::endl; ui->memory_mnemonic->setText(mnemonicToString((Mnemonic)info[0])); ui->memory_squashed->setText(QString::number(info[1])); ui->memory_s1->set_value(info[2]); @@ -299,13 +307,13 @@ void GUI::on_upload_program_state_btn_clicked() void GUI::on_enable_pipeline_checkbox_checkStateChanged( const Qt::CheckState &arg1) { - if (arg1 == Qt::CheckState::Checked) { - qDebug() << "enable pipeline checkbox checked."; - this->is_pipelined = true; - } else { - qDebug() << "enable pipeline checkbox unchecked."; - this->is_pipelined = false; - } + this->is_pipelined = (arg1 == Qt::CheckState::Checked) ? true : false; +} + +void GUI::on_base_toggle_checkbox_checkStateChanged(const Qt::CheckState &state) +{ + this->is_hex = (state == Qt::CheckState::Checked) ? false : true; + emit this->hex_toggled(this->is_hex); } void GUI::on_step_btn_clicked() @@ -58,6 +58,7 @@ class GUI : public QMainWindow const QString &img = "idle.png"); signals: + void hex_toggled(bool is_hex); void sendRunSteps(int steps); void sendConfigure( std::vector<unsigned int> ways, vector<int> program, bool is_pipelined); @@ -92,6 +93,9 @@ class GUI : public QMainWindow void on_enable_pipeline_checkbox_checkStateChanged(const Qt::CheckState &arg1); + void + on_base_toggle_checkbox_checkStateChanged(const Qt::CheckState &state); + void on_step_btn_clicked(); void on_save_program_state_btn_clicked(); @@ -113,6 +117,11 @@ class GUI : public QMainWindow bool ready; /** + * Whether or not numerical values are currently displaying in hex. + */ + bool is_hex = true; + + /** * The message displayed on the status bar. */ QLabel *status_label; @@ -541,7 +541,10 @@ </widget> </item> <item> - <widget class="QCheckBox" name="checkBox"> + <widget class="QCheckBox" name="base_toggle_checkbox"> + <property name="enabled"> + <bool>true</bool> + </property> <property name="text"> <string>Decimal</string> </property> |