diff --git a/include/panda_qt/config_window.hpp b/include/panda_qt/config_window.hpp index 3cf4a1c82..9c0037534 100644 --- a/include/panda_qt/config_window.hpp +++ b/include/panda_qt/config_window.hpp @@ -22,7 +22,7 @@ class ConfigWindow : public QDialog { private: using ConfigCallback = std::function; - using IconCallback = std::function; + using MainWindowCallback = std::function; using Theme = FrontendSettings::Theme; using WindowIcon = FrontendSettings::WindowIcon; @@ -39,14 +39,14 @@ class ConfigWindow : public QDialog { EmulatorConfig config; ConfigCallback updateConfig; - IconCallback updateIcon; + MainWindowCallback getMainWindow; void addWidget(QWidget* widget, QString title, QString icon, QString helpText); void setTheme(FrontendSettings::Theme theme); void setIcon(FrontendSettings::WindowIcon icon); public: - ConfigWindow(ConfigCallback configCallback, IconCallback iconCallback, const EmulatorConfig& config, QWidget* parent = nullptr); + ConfigWindow(ConfigCallback configCallback, MainWindowCallback windowCallback, const EmulatorConfig& config, QWidget* parent = nullptr); ~ConfigWindow(); EmulatorConfig& getConfig() { return config; } diff --git a/src/panda_qt/config_window.cpp b/src/panda_qt/config_window.cpp index 64cade49b..92fa0741e 100644 --- a/src/panda_qt/config_window.cpp +++ b/src/panda_qt/config_window.cpp @@ -1,16 +1,20 @@ #include "panda_qt/config_window.hpp" -ConfigWindow::ConfigWindow(ConfigCallback configCallback, IconCallback iconCallback, const EmulatorConfig& emuConfig, QWidget* parent) - : QDialog(parent), config(emuConfig) { - setWindowTitle(tr("Configuration")); +#include "version.hpp" - updateConfig = std::move(configCallback); - updateIcon = std::move(iconCallback); +ConfigWindow::ConfigWindow(ConfigCallback configCallback, MainWindowCallback windowCallback, const EmulatorConfig& emuConfig, QWidget* parent) + : QDialog(parent), config(emuConfig), updateConfig(std::move(configCallback)), getMainWindow(std::move(windowCallback)) { + setWindowTitle(tr("Configuration")); // Set up theme selection setTheme(config.frontendSettings.theme); setIcon(config.frontendSettings.icon); + // Set the window title of the main window appropriately if we enable showing the app version on the window + if (config.windowSettings.showAppVersion) { + getMainWindow()->setWindowTitle("Alber v" PANDA3DS_VERSION); + } + // Initialize the widget list and the widget container widgets widgetList = new QListWidget(this); widgetContainer = new QStackedWidget(this); @@ -92,6 +96,14 @@ ConfigWindow::ConfigWindow(ConfigCallback configCallback, IconCallback iconCallb guiLayout->addRow(tr("Window icon"), iconSelect); QCheckBox* showAppVersion = new QCheckBox(tr("Show version on window title")); + showAppVersion->setChecked(config.windowSettings.showAppVersion); + connect(showAppVersion, &QCheckBox::toggled, this, [&](bool checked) { + config.windowSettings.showAppVersion = checked; + updateConfig(); + + // Update main window title + getMainWindow()->setWindowTitle(checked ? "Alber v" PANDA3DS_VERSION : "Alber"); + }); connectCheckbox(showAppVersion, config.windowSettings.showAppVersion); guiLayout->addRow(showAppVersion); @@ -229,7 +241,7 @@ ConfigWindow::ConfigWindow(ConfigCallback configCallback, IconCallback iconCallb QSpinBox* volumeRaw = new QSpinBox(); volumeRaw->setRange(0, 200); - volumeRaw->setValue(config.audioDeviceConfig.volumeRaw* 100); + volumeRaw->setValue(config.audioDeviceConfig.volumeRaw * 100); connect(volumeRaw, &QSpinBox::valueChanged, this, [&](int value) { config.audioDeviceConfig.volumeRaw = static_cast(value) / 100.0f; updateConfig(); @@ -380,6 +392,8 @@ void ConfigWindow::setTheme(Theme theme) { } void ConfigWindow::setIcon(WindowIcon icon) { + auto updateIcon = [&](const QString& iconPath) { getMainWindow()->setWindowIcon(QIcon(iconPath)); }; + switch (icon) { case WindowIcon::Rsyn: updateIcon(":/docs/img/rsyn_icon.png"); break; case WindowIcon::Rnap: updateIcon(":/docs/img/rnap_icon.png"); break; diff --git a/src/panda_qt/main_window.cpp b/src/panda_qt/main_window.cpp index fa3efae7f..2c714e2ac 100644 --- a/src/panda_qt/main_window.cpp +++ b/src/panda_qt/main_window.cpp @@ -7,11 +7,11 @@ #include #include -#include "version.hpp" #include "cheats.hpp" #include "input_mappings.hpp" #include "sdl_sensors.hpp" #include "services/dsp.hpp" +#include "version.hpp" MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent), keyboardMappings(InputMappings::defaultKeyboardMappings()) { setWindowTitle("Alber"); @@ -95,7 +95,7 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent) EmulatorMessage message{.type = MessageType::UpdateConfig}; sendMessage(message); }, - [&](const QString& icon) { setWindowIcon(QIcon(icon)); }, emu->getConfig(), this + [&]() { return this; }, emu->getConfig(), this ); auto args = QCoreApplication::arguments(); @@ -112,10 +112,6 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent) auto& config = emu->getConfig(); auto& windowSettings = config.windowSettings; - if (windowSettings.showAppVersion) { - setWindowTitle("Alber v" PANDA3DS_VERSION); - } - if (windowSettings.rememberPosition) { setGeometry(windowSettings.x, windowSettings.y, windowSettings.width, config.windowSettings.height); } @@ -236,7 +232,7 @@ void MainWindow::selectLuaFile() { } // Stop emulator thread when the main window closes -void MainWindow::closeEvent(QCloseEvent *event) { +void MainWindow::closeEvent(QCloseEvent* event) { appRunning = false; // Set our running atomic to false in order to make the emulator thread stop, and join it if (emuThread.joinable()) { @@ -319,8 +315,7 @@ void MainWindow::dumpDspFirmware() { case DSPService::ComponentDumpResult::Success: break; case DSPService::ComponentDumpResult::NotLoaded: { QMessageBox messageBox( - QMessageBox::Icon::Warning, tr("No DSP firmware loaded"), - tr("The currently loaded app has not uploaded a firmware to the DSP") + QMessageBox::Icon::Warning, tr("No DSP firmware loaded"), tr("The currently loaded app has not uploaded a firmware to the DSP") ); QAbstractButton* button = messageBox.addButton(tr("OK"), QMessageBox::ButtonRole::YesRole);