added theme

This commit is contained in:
georgemoralis 2025-06-20 12:18:05 +03:00
parent 23446ff286
commit bd150558c9
8 changed files with 20 additions and 69 deletions

View File

@ -81,7 +81,6 @@ static std::vector<GameInstallDir> settings_install_dirs = {};
std::vector<bool> install_dirs_enabled = {}; std::vector<bool> install_dirs_enabled = {};
std::filesystem::path settings_addon_install_dir = {}; std::filesystem::path settings_addon_install_dir = {};
std::filesystem::path save_data_path = {}; std::filesystem::path save_data_path = {};
u32 mw_themes = 0;
static bool isFullscreen = false; static bool isFullscreen = false;
static std::string fullscreenMode = "Windowed"; static std::string fullscreenMode = "Windowed";
static bool isHDRAllowed = false; static bool isHDRAllowed = false;
@ -481,10 +480,6 @@ void setAddonInstallDir(const std::filesystem::path& dir) {
settings_addon_install_dir = dir; settings_addon_install_dir = dir;
} }
void setMainWindowTheme(u32 theme) {
mw_themes = theme;
}
void setGameInstallDirs(const std::vector<std::filesystem::path>& dirs_config) { void setGameInstallDirs(const std::vector<std::filesystem::path>& dirs_config) {
settings_install_dirs.clear(); settings_install_dirs.clear();
for (const auto& dir : dirs_config) { for (const auto& dir : dirs_config) {
@ -526,10 +521,6 @@ std::filesystem::path getAddonInstallDir() {
return settings_addon_install_dir; return settings_addon_install_dir;
} }
u32 getMainWindowTheme() {
return mw_themes;
}
u32 GetLanguage() { u32 GetLanguage() {
return m_language; return m_language;
} }
@ -639,7 +630,6 @@ void load(const std::filesystem::path& path) {
const toml::value& gui = data.at("GUI"); const toml::value& gui = data.at("GUI");
load_game_size = toml::find_or<bool>(gui, "loadGameSizeEnabled", true); load_game_size = toml::find_or<bool>(gui, "loadGameSizeEnabled", true);
mw_themes = toml::find_or<int>(gui, "theme", 0);
const auto install_dir_array = const auto install_dir_array =
toml::find_or<std::vector<std::u8string>>(gui, "installDirs", {}); toml::find_or<std::vector<std::u8string>>(gui, "installDirs", {});
@ -818,40 +808,6 @@ void save(const std::filesystem::path& path) {
std::ofstream file(path, std::ios::binary); std::ofstream file(path, std::ios::binary);
file << data; file << data;
file.close(); file.close();
saveMainWindow(path);
}
void saveMainWindow(const std::filesystem::path& path) {
toml::ordered_value data;
std::error_code error;
if (std::filesystem::exists(path, error)) {
try {
std::ifstream ifs;
ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
ifs.open(path, std::ios_base::binary);
data = toml::parse<toml::ordered_type_config>(
ifs, std::string{fmt::UTF(path.filename().u8string()).data});
} catch (const std::exception& ex) {
fmt::print("Exception trying to parse config file. Exception: {}\n", ex.what());
return;
}
} else {
if (error) {
fmt::print("Filesystem error: {}\n", error.message());
}
fmt::print("Saving new configuration file {}\n", fmt::UTF(path.u8string()));
}
data["GUI"]["theme"] = mw_themes;
// Sorting of TOML sections
sortTomlSections(data);
std::ofstream file(path, std::ios::binary);
file << data;
file.close();
} }
void setDefaultValues() { void setDefaultValues() {

View File

@ -18,7 +18,6 @@ enum HideCursorState : int { Never, Idle, Always };
void load(const std::filesystem::path& path); void load(const std::filesystem::path& path);
void save(const std::filesystem::path& path); void save(const std::filesystem::path& path);
void saveMainWindow(const std::filesystem::path& path);
std::string getTrophyKey(); std::string getTrophyKey();
void setTrophyKey(std::string key); void setTrophyKey(std::string key);
@ -123,13 +122,10 @@ bool addGameInstallDir(const std::filesystem::path& dir, bool enabled = true);
void removeGameInstallDir(const std::filesystem::path& dir); void removeGameInstallDir(const std::filesystem::path& dir);
void setGameInstallDirEnabled(const std::filesystem::path& dir, bool enabled); void setGameInstallDirEnabled(const std::filesystem::path& dir, bool enabled);
void setAddonInstallDir(const std::filesystem::path& dir); void setAddonInstallDir(const std::filesystem::path& dir);
void setMainWindowTheme(u32 theme);
void setElfViewer(const std::vector<std::string>& elfList);
const std::vector<std::filesystem::path> getGameInstallDirs(); const std::vector<std::filesystem::path> getGameInstallDirs();
const std::vector<bool> getGameInstallDirsEnabled(); const std::vector<bool> getGameInstallDirsEnabled();
std::filesystem::path getAddonInstallDir(); std::filesystem::path getAddonInstallDir();
u32 getMainWindowTheme();
void setDefaultValues(); void setDefaultValues();

View File

@ -58,10 +58,7 @@ Emulator::Emulator() {
#endif #endif
} }
Emulator::~Emulator() { Emulator::~Emulator() {}
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
Config::saveMainWindow(config_dir / "config.toml");
}
void Emulator::Run(std::filesystem::path file, const std::vector<std::string> args) { void Emulator::Run(std::filesystem::path file, const std::vector<std::string> args) {
if (std::filesystem::is_directory(file)) { if (std::filesystem::is_directory(file)) {

View File

@ -12,7 +12,8 @@
#include "main_window_themes.h" #include "main_window_themes.h"
#include "ui_about_dialog.h" #include "ui_about_dialog.h"
AboutDialog::AboutDialog(QWidget* parent) : QDialog(parent), ui(new Ui::AboutDialog) { AboutDialog::AboutDialog(std::shared_ptr<gui_settings> gui_settings, QWidget* parent)
: QDialog(parent), ui(new Ui::AboutDialog), m_gui_settings(std::move(gui_settings)) {
ui->setupUi(this); ui->setupUi(this);
preloadImages(); preloadImages();
@ -57,7 +58,7 @@ void AboutDialog::preloadImages() {
} }
void AboutDialog::updateImagesForCurrentTheme() { void AboutDialog::updateImagesForCurrentTheme() {
Theme currentTheme = static_cast<Theme>(Config::getMainWindowTheme()); Theme currentTheme = static_cast<Theme>(m_gui_settings->GetValue(gui::gen_theme).toInt());
bool isDarkTheme = (currentTheme == Theme::Dark || currentTheme == Theme::Green || bool isDarkTheme = (currentTheme == Theme::Dark || currentTheme == Theme::Green ||
currentTheme == Theme::Blue || currentTheme == Theme::Violet); currentTheme == Theme::Blue || currentTheme == Theme::Violet);
if (isDarkTheme) { if (isDarkTheme) {
@ -188,7 +189,7 @@ void AboutDialog::removeHoverEffect(QLabel* label) {
} }
bool AboutDialog::isDarkTheme() const { bool AboutDialog::isDarkTheme() const {
Theme currentTheme = static_cast<Theme>(Config::getMainWindowTheme()); Theme currentTheme = static_cast<Theme>(m_gui_settings->GetValue(gui::gen_theme).toInt());
return currentTheme == Theme::Dark || currentTheme == Theme::Green || return currentTheme == Theme::Dark || currentTheme == Theme::Green ||
currentTheme == Theme::Blue || currentTheme == Theme::Violet; currentTheme == Theme::Blue || currentTheme == Theme::Violet;
} }

View File

@ -8,6 +8,7 @@
#include <QLabel> #include <QLabel>
#include <QPixmap> #include <QPixmap>
#include <QUrl> #include <QUrl>
#include "gui_settings.h"
namespace Ui { namespace Ui {
class AboutDialog; class AboutDialog;
@ -17,7 +18,7 @@ class AboutDialog : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
explicit AboutDialog(QWidget* parent = nullptr); explicit AboutDialog(std::shared_ptr<gui_settings> gui_settings, QWidget* parent = nullptr);
~AboutDialog(); ~AboutDialog();
bool eventFilter(QObject* obj, QEvent* event); bool eventFilter(QObject* obj, QEvent* event);
@ -33,4 +34,5 @@ private:
QPixmap originalImages[5]; QPixmap originalImages[5];
QPixmap invertedImages[5]; QPixmap invertedImages[5];
std::shared_ptr<gui_settings> m_gui_settings;
}; };

View File

@ -22,6 +22,7 @@ const gui_value gen_recentFiles =
const gui_value gen_guiLanguage = gui_value(general_settings, "guiLanguage", "en_US"); const gui_value gen_guiLanguage = gui_value(general_settings, "guiLanguage", "en_US");
const gui_value gen_elfDirs = const gui_value gen_elfDirs =
gui_value(main_window, "elfDirs", QVariant::fromValue(QList<QString>())); gui_value(main_window, "elfDirs", QVariant::fromValue(QList<QString>()));
const gui_value gen_theme = gui_value(general_settings, "theme", 0);
// main window settings // main window settings
const gui_value mw_geometry = gui_value(main_window, "geometry", QByteArray()); const gui_value mw_geometry = gui_value(main_window, "geometry", QByteArray());

View File

@ -39,8 +39,6 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi
MainWindow::~MainWindow() { MainWindow::~MainWindow() {
SaveWindowState(); SaveWindowState();
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
Config::saveMainWindow(config_dir / "config.toml");
} }
bool MainWindow::Init() { bool MainWindow::Init() {
@ -492,7 +490,7 @@ void MainWindow::CreateConnects() {
#endif #endif
connect(ui->aboutAct, &QAction::triggered, this, [this]() { connect(ui->aboutAct, &QAction::triggered, this, [this]() {
auto aboutDialog = new AboutDialog(this); auto aboutDialog = new AboutDialog(m_gui_settings, this);
aboutDialog->exec(); aboutDialog->exec();
}); });
@ -778,7 +776,7 @@ void MainWindow::CreateConnects() {
// Themes // Themes
connect(ui->setThemeDark, &QAction::triggered, &m_window_themes, [this]() { connect(ui->setThemeDark, &QAction::triggered, &m_window_themes, [this]() {
m_window_themes.SetWindowTheme(Theme::Dark, ui->mw_searchbar); m_window_themes.SetWindowTheme(Theme::Dark, ui->mw_searchbar);
Config::setMainWindowTheme(static_cast<int>(Theme::Dark)); m_gui_settings->SetValue(gui::gen_theme, static_cast<int>(Theme::Dark));
if (isIconBlack) { if (isIconBlack) {
SetUiIcons(false); SetUiIcons(false);
isIconBlack = false; isIconBlack = false;
@ -786,7 +784,7 @@ void MainWindow::CreateConnects() {
}); });
connect(ui->setThemeLight, &QAction::triggered, &m_window_themes, [this]() { connect(ui->setThemeLight, &QAction::triggered, &m_window_themes, [this]() {
m_window_themes.SetWindowTheme(Theme::Light, ui->mw_searchbar); m_window_themes.SetWindowTheme(Theme::Light, ui->mw_searchbar);
Config::setMainWindowTheme(static_cast<int>(Theme::Light)); m_gui_settings->SetValue(gui::gen_theme, static_cast<int>(Theme::Light));
if (!isIconBlack) { if (!isIconBlack) {
SetUiIcons(true); SetUiIcons(true);
isIconBlack = true; isIconBlack = true;
@ -794,7 +792,7 @@ void MainWindow::CreateConnects() {
}); });
connect(ui->setThemeGreen, &QAction::triggered, &m_window_themes, [this]() { connect(ui->setThemeGreen, &QAction::triggered, &m_window_themes, [this]() {
m_window_themes.SetWindowTheme(Theme::Green, ui->mw_searchbar); m_window_themes.SetWindowTheme(Theme::Green, ui->mw_searchbar);
Config::setMainWindowTheme(static_cast<int>(Theme::Green)); m_gui_settings->SetValue(gui::gen_theme, static_cast<int>(Theme::Green));
if (isIconBlack) { if (isIconBlack) {
SetUiIcons(false); SetUiIcons(false);
isIconBlack = false; isIconBlack = false;
@ -802,7 +800,7 @@ void MainWindow::CreateConnects() {
}); });
connect(ui->setThemeBlue, &QAction::triggered, &m_window_themes, [this]() { connect(ui->setThemeBlue, &QAction::triggered, &m_window_themes, [this]() {
m_window_themes.SetWindowTheme(Theme::Blue, ui->mw_searchbar); m_window_themes.SetWindowTheme(Theme::Blue, ui->mw_searchbar);
Config::setMainWindowTheme(static_cast<int>(Theme::Blue)); m_gui_settings->SetValue(gui::gen_theme, static_cast<int>(Theme::Blue));
if (isIconBlack) { if (isIconBlack) {
SetUiIcons(false); SetUiIcons(false);
isIconBlack = false; isIconBlack = false;
@ -810,7 +808,7 @@ void MainWindow::CreateConnects() {
}); });
connect(ui->setThemeViolet, &QAction::triggered, &m_window_themes, [this]() { connect(ui->setThemeViolet, &QAction::triggered, &m_window_themes, [this]() {
m_window_themes.SetWindowTheme(Theme::Violet, ui->mw_searchbar); m_window_themes.SetWindowTheme(Theme::Violet, ui->mw_searchbar);
Config::setMainWindowTheme(static_cast<int>(Theme::Violet)); m_gui_settings->SetValue(gui::gen_theme, static_cast<int>(Theme::Violet));
if (isIconBlack) { if (isIconBlack) {
SetUiIcons(false); SetUiIcons(false);
isIconBlack = false; isIconBlack = false;
@ -818,7 +816,7 @@ void MainWindow::CreateConnects() {
}); });
connect(ui->setThemeGruvbox, &QAction::triggered, &m_window_themes, [this]() { connect(ui->setThemeGruvbox, &QAction::triggered, &m_window_themes, [this]() {
m_window_themes.SetWindowTheme(Theme::Gruvbox, ui->mw_searchbar); m_window_themes.SetWindowTheme(Theme::Gruvbox, ui->mw_searchbar);
Config::setMainWindowTheme(static_cast<int>(Theme::Gruvbox)); m_gui_settings->SetValue(gui::gen_theme, static_cast<int>(Theme::Gruvbox));
if (isIconBlack) { if (isIconBlack) {
SetUiIcons(false); SetUiIcons(false);
isIconBlack = false; isIconBlack = false;
@ -826,7 +824,7 @@ void MainWindow::CreateConnects() {
}); });
connect(ui->setThemeTokyoNight, &QAction::triggered, &m_window_themes, [this]() { connect(ui->setThemeTokyoNight, &QAction::triggered, &m_window_themes, [this]() {
m_window_themes.SetWindowTheme(Theme::TokyoNight, ui->mw_searchbar); m_window_themes.SetWindowTheme(Theme::TokyoNight, ui->mw_searchbar);
Config::setMainWindowTheme(static_cast<int>(Theme::TokyoNight)); m_gui_settings->SetValue(gui::gen_theme, static_cast<int>(Theme::TokyoNight));
if (isIconBlack) { if (isIconBlack) {
SetUiIcons(false); SetUiIcons(false);
isIconBlack = false; isIconBlack = false;
@ -834,7 +832,7 @@ void MainWindow::CreateConnects() {
}); });
connect(ui->setThemeOled, &QAction::triggered, &m_window_themes, [this]() { connect(ui->setThemeOled, &QAction::triggered, &m_window_themes, [this]() {
m_window_themes.SetWindowTheme(Theme::Oled, ui->mw_searchbar); m_window_themes.SetWindowTheme(Theme::Oled, ui->mw_searchbar);
Config::setMainWindowTheme(static_cast<int>(Theme::Oled)); m_gui_settings->SetValue(gui::gen_theme, static_cast<int>(Theme::Oled));
if (isIconBlack) { if (isIconBlack) {
SetUiIcons(false); SetUiIcons(false);
isIconBlack = false; isIconBlack = false;
@ -981,7 +979,7 @@ void MainWindow::InstallDirectory() {
} }
void MainWindow::SetLastUsedTheme() { void MainWindow::SetLastUsedTheme() {
Theme lastTheme = static_cast<Theme>(Config::getMainWindowTheme()); Theme lastTheme = static_cast<Theme>(m_gui_settings->GetValue(gui::gen_theme).toInt());
m_window_themes.SetWindowTheme(lastTheme, ui->mw_searchbar); m_window_themes.SetWindowTheme(lastTheme, ui->mw_searchbar);
switch (lastTheme) { switch (lastTheme) {

View File

@ -465,7 +465,7 @@ void TrophyViewer::SetTableItem(QTableWidget* parent, int row, int column, QStri
item->setTextAlignment(Qt::AlignCenter); item->setTextAlignment(Qt::AlignCenter);
item->setFont(QFont("Arial", 12, QFont::Bold)); item->setFont(QFont("Arial", 12, QFont::Bold));
Theme theme = static_cast<Theme>(Config::getMainWindowTheme()); Theme theme = static_cast<Theme>(m_gui_settings->GetValue(gui::gen_theme).toInt());
if (theme == Theme::Light) { if (theme == Theme::Light) {
item->setForeground(QBrush(Qt::black)); item->setForeground(QBrush(Qt::black));