Skip to content

Commit

Permalink
Qt: Fix "Show app version on window" option
Browse files Browse the repository at this point in the history
  • Loading branch information
wheremyfoodat authored Dec 1, 2024
1 parent 156328f commit c3e3b23
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
6 changes: 3 additions & 3 deletions include/panda_qt/config_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ConfigWindow : public QDialog {

private:
using ConfigCallback = std::function<void()>;
using IconCallback = std::function<void(const QString&)>;
using MainWindowCallback = std::function<QWidget*()>;

using Theme = FrontendSettings::Theme;
using WindowIcon = FrontendSettings::WindowIcon;
Expand All @@ -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; }
Expand Down
26 changes: 20 additions & 6 deletions src/panda_qt/config_window.cpp
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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<float>(value) / 100.0f;
updateConfig();
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 4 additions & 9 deletions src/panda_qt/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include <cstdio>
#include <fstream>

#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");
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c3e3b23

Please sign in to comment.