From 9fe7235d7c06677f152e20b9deac85e633f429a6 Mon Sep 17 00:00:00 2001 From: bd Date: Mon, 21 Apr 2025 13:41:45 -0400 Subject: Add some expression --- gui/gui.cc | 52 ++++++++++++++++++++++++++++++++++------------- gui/gui.h | 14 +++++++++---- gui/messages.h | 14 +++++-------- gui/resources.qrc | 4 ++++ gui/resources/angry.png | Bin 0 -> 319 bytes gui/resources/busy.png | Bin 0 -> 329 bytes gui/resources/happy.png | Bin 0 -> 322 bytes gui/resources/idle.png | Bin 0 -> 322 bytes gui/resources/styles.qss | 22 ++++++++++++++++++++ 9 files changed, 79 insertions(+), 27 deletions(-) create mode 100644 gui/resources/angry.png create mode 100644 gui/resources/busy.png create mode 100644 gui/resources/happy.png create mode 100644 gui/resources/idle.png (limited to 'gui') diff --git a/gui/gui.cc b/gui/gui.cc index 3440916..2744a06 100644 --- a/gui/gui.cc +++ b/gui/gui.cc @@ -19,16 +19,29 @@ #include "./ui_gui.h" #include "dynamicwaysentry.h" #include "messages.h" +#include +#include GUI::GUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::GUI) { ui->setupUi(this); + /* setup the status bar */ + ui->statusBar->setFixedHeight(20); + + this->avatar = new QLabel(this); this->status_label = new QLabel("", this); - this->set_status(get_waiting); QLabel *risc_vector = new QLabel("RISC V[ECTOR], CS535 UMASS AMHERST", this); - status_label->setMinimumWidth(1200); + + avatar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + avatar->setObjectName("avatar_label"); + status_label->setObjectName("msg_label"); + risc_vector->setObjectName("info_label"); + ui->statusBar->setSizeGripEnabled(false); + + this->set_status(get_waiting, "idle.png"); + ui->statusBar->addWidget(avatar); ui->statusBar->addWidget(status_label); ui->statusBar->addPermanentWidget(risc_vector); @@ -252,7 +265,7 @@ void GUI::on_upload_intructions_btn_clicked() "Binary Files (*.bin *.rv);;All Files (*.*)"); QFile file(filePath); if (filePath.isEmpty() || !file.open(QIODevice::ReadOnly)) { - this->set_status(get_no_instructions); + this->set_status(get_no_instructions, "angry"); return; } @@ -270,9 +283,9 @@ void GUI::on_upload_intructions_btn_clicked() } if (this->p.empty()) - this->set_status(get_no_instructions); + this->set_status(get_no_instructions, "angry"); else - this->set_status(get_load_file); + this->set_status(get_load_file, "happy"); file.close(); } @@ -305,10 +318,10 @@ void GUI::on_step_btn_clicked() if (!this->ready) return; - this->set_status(get_running); + this->set_status(get_running, "busy"); int steps = step_values[ui->step_slider->value()]; emit sendRunSteps(steps); - this->set_status(get_waiting); + this->set_status(get_waiting, "idle"); } void GUI::on_save_program_state_btn_clicked() @@ -333,13 +346,13 @@ void GUI::on_config_clicked() if (i != -1) { ways.push_back((unsigned int)i); } else { - this->set_status(get_bad_cache); + this->set_status(get_bad_cache, "angry"); return; } } if (this->p.empty()) { - this->set_status(get_no_instructions); + this->set_status(get_no_instructions, "angry"); return; } @@ -347,17 +360,28 @@ void GUI::on_config_clicked() // say something snarky if (!is_pipelined) - this->set_status(get_no_pipeline); + this->set_status(get_no_pipeline, "angry"); else if (ways.size() == 0) - this->set_status(get_no_cache); + this->set_status(get_no_cache, "angry"); else - this->set_status(get_initialize); + this->set_status(get_initialize, "happy"); emit sendConfigure(ways, this->p, is_pipelined); } -void GUI::set_status(const std::function &func) +void GUI::set_status( + const std::function &func, const QString &img) { this->status_label->setText( - "COMPUTER SAYS: \"" + QString::fromStdString(func()) + "\""); + "-> \"" + QString::fromStdString(func()) + "\""); + + QString img_path = ":resources/" + img; + QPixmap pixmap(img_path); + + if (!pixmap) { + return; + } + + this->avatar->setPixmap(pixmap); + this->avatar->show(); } diff --git a/gui/gui.h b/gui/gui.h index 7c5b440..7efde1f 100644 --- a/gui/gui.h +++ b/gui/gui.h @@ -51,15 +51,16 @@ class GUI : public QMainWindow /** * Uses `func' to set the current status. * @param a function which returns a string. + * @param a path to the desired avatar */ - void set_status(const std::function &func); + void set_status( + const std::function &func, + const QString &img = "idle.png"); signals: void sendRunSteps(int steps); void sendConfigure( - std::vector ways, - vector program, - bool is_pipelined); + std::vector ways, vector program, bool is_pipelined); private slots: void on_worker_refresh_gui(int value, int pc); @@ -116,6 +117,11 @@ class GUI : public QMainWindow */ QLabel *status_label; + /** + * The robot image displayed on the status bar. + */ + QLabel *avatar; + /** * The currently loaded program. */ diff --git a/gui/messages.h b/gui/messages.h index adae777..03c0ab3 100644 --- a/gui/messages.h +++ b/gui/messages.h @@ -9,19 +9,15 @@ #define RANDOM_MESSAGE(v) (v[std::rand() % v.size()]) const std::vector waiting = { - "WAITING FOR USER", "READY", "BORED", "SLEEPING"}; -const std::vector running = { - "COMPUTING", "WORKING", "BUSY"}; + "WAITING FOR USER", "IDLE", "BORED", "SLEEPING"}; +const std::vector running = {"COMPUTING", "WORKING", "BUSY"}; const std::vector load_file = {"FILE LOADED"}; const std::vector no_instructions = { - "NO PROGRAM PROVIDED", "INSTRUCTIONS NOT INCLUDED", - "NOTHING TO DO, GIVING UP"}; + "NO PROGRAM PROVIDED", "NOTHING TO DO, GIVING UP"}; const std::vector bad_cache = { "WAYS CANNOT BE BELOW 0 OR ABOVE 5"}; -const std::vector no_pipeline = { - "SIMULATION READY: NO PIPE :(", "SIMULATION READY"}; -const std::vector no_cache = { - "SIMULATION READY: NO WAYS", "SIMULATION READY"}; +const std::vector no_pipeline = {"SIMULATION READY: NO PIPE"}; +const std::vector no_cache = {"SIMULATION READY: NO CACHE"}; const std::vector initialize = {"SIMULATION READY"}; /** diff --git a/gui/resources.qrc b/gui/resources.qrc index 59fb36f..569cc22 100644 --- a/gui/resources.qrc +++ b/gui/resources.qrc @@ -2,6 +2,10 @@ resources/styles.qss + resources/idle.png + resources/angry.png + resources/happy.png + resources/busy.png resources/BigBlueTermPlusNerdFontMono-Regular.ttf diff --git a/gui/resources/angry.png b/gui/resources/angry.png new file mode 100644 index 0000000..3299eb4 Binary files /dev/null and b/gui/resources/angry.png differ diff --git a/gui/resources/busy.png b/gui/resources/busy.png new file mode 100644 index 0000000..df1b36a Binary files /dev/null and b/gui/resources/busy.png differ diff --git a/gui/resources/happy.png b/gui/resources/happy.png new file mode 100644 index 0000000..6168e89 Binary files /dev/null and b/gui/resources/happy.png differ diff --git a/gui/resources/idle.png b/gui/resources/idle.png new file mode 100644 index 0000000..f894716 Binary files /dev/null and b/gui/resources/idle.png differ diff --git a/gui/resources/styles.qss b/gui/resources/styles.qss index 9562b69..dbaa623 100644 --- a/gui/resources/styles.qss +++ b/gui/resources/styles.qss @@ -6,6 +6,28 @@ border: 0px solid "#000200"; } +QStatusBar { + font-size: 12pt; + color: "#000200"; + background-color: "#00cc00"; +} + +QLabel#msg_label { + font-size: 12pt; + color: "#000200"; + background-color: "#00cc00"; +} + +QLabel#info_label { + font-size: 12pt; + color: "#000200"; + background-color: "#00cc00"; +} + +QLabel#avatar_label { + background-color: "#00cc00"; +} + /* main window */ QWidget { } -- cgit v1.2.3