Merge branch 'accent_colors_feat' into 'main'

feat(ui): Implement customizable accent color and rainbow mode

See merge request citron/emulator!79
This commit is contained in:
Zephyron
2025-10-04 12:04:52 +10:00
10 changed files with 1109 additions and 1175 deletions

View File

@@ -209,6 +209,7 @@ add_executable(citron
qt_common.h
startup_checks.cpp
startup_checks.h
theme.h
uisettings.cpp
uisettings.h
util/clickable_label.cpp

View File

@@ -16,15 +16,16 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<!-- High DPI support: Enable automatic scaling and proper window modality -->
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<!-- High DPI scaling attributes -->
<property name="windowTitle">
<string>citron Configuration</string>
</property>
<property name="styleSheet">
<string/>
</property>
<property name="templateStyleSheet" stdset="0">
<string>QDialog {
background-color: #2b2b2b;
color: #ffffff;
@@ -68,7 +69,7 @@
}
QScrollBar::handle:vertical:hover {
background-color: #4a9eff;
background-color: %%ACCENT_COLOR%%;
}
QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical {
@@ -92,7 +93,7 @@
}
QScrollBar::handle:horizontal:hover {
background-color: #4a9eff;
background-color: %%ACCENT_COLOR%%;
}
QScrollBar::add-line:horizontal, QScrollBar::sub-line:horizontal {
@@ -118,10 +119,10 @@
}
QPushButton.tabButton:checked {
background-color: #4a9eff;
background-color: %%ACCENT_COLOR%%;
color: #ffffff;
font-weight: bold;
border-color: #4a9eff;
border-color: %%ACCENT_COLOR%%;
}
QPushButton.tabButton:hover:!checked {
@@ -130,7 +131,7 @@
}
QPushButton.tabButton:pressed {
background-color: #2980b9;
background-color: %%ACCENT_COLOR_PRESSED%%;
}
QTabWidget {
@@ -170,10 +171,10 @@
}
QTabBar::tab:selected {
background-color: #4a9eff;
background-color: %%ACCENT_COLOR%%;
color: #ffffff;
font-weight: bold;
border-color: #4a9eff;
border-color: %%ACCENT_COLOR%%;
}
QTabBar::tab:hover:!selected {
@@ -191,7 +192,7 @@
QTabBar QToolButton:hover {
background-color: #4d4d4d;
border-color: #4a9eff;
border-color: %%ACCENT_COLOR%%;
}
QTabBar::scroller {
@@ -232,12 +233,12 @@
}
QCheckBox::indicator:checked {
background-color: #4a9eff;
border-color: #4a9eff;
background-color: %%ACCENT_COLOR%%;
border-color: %%ACCENT_COLOR%%;
}
QCheckBox::indicator:hover {
border-color: #4a9eff;
border-color: %%ACCENT_COLOR%%;
}
QComboBox {
@@ -248,16 +249,16 @@
color: #ffffff;
min-width: 120px;
min-height: 28px;
selection-background-color: #4a9eff;
selection-background-color: %%ACCENT_COLOR%%;
}
QComboBox:hover {
border-color: #4a9eff;
border-color: %%ACCENT_COLOR%%;
background-color: #404040;
}
QComboBox:focus {
border-color: #4a9eff;
border-color: %%ACCENT_COLOR%%;
background-color: #404040;
}
@@ -277,8 +278,8 @@
QComboBox QAbstractItemView {
background-color: #3d3d3d;
border: 1px solid #4a9eff;
selection-background-color: #4a9eff;
border: 1px solid %%ACCENT_COLOR%%;
selection-background-color: %%ACCENT_COLOR%%;
color: #ffffff;
outline: none;
}
@@ -290,12 +291,12 @@
}
QComboBox QAbstractItemView::item:selected {
background-color: #4a9eff;
background-color: %%ACCENT_COLOR%%;
color: #ffffff;
}
QComboBox QAbstractItemView::item:hover {
background-color: #5dafff;
background-color: %%ACCENT_COLOR_HOVER%%;
color: #ffffff;
}
@@ -306,16 +307,16 @@
padding: 8px 12px;
color: #ffffff;
min-height: 20px;
selection-background-color: #4a9eff;
selection-background-color: %%ACCENT_COLOR%%;
}
QLineEdit:focus {
border-color: #4a9eff;
border-color: %%ACCENT_COLOR%%;
background-color: #404040;
}
QPushButton {
background-color: #4a9eff;
background-color: %%ACCENT_COLOR%%;
color: #ffffff;
border: none;
padding: 10px 20px;
@@ -325,11 +326,11 @@
}
QPushButton:hover {
background-color: #5dafff;
background-color: %%ACCENT_COLOR_HOVER%%;
}
QPushButton:pressed {
background-color: #2980b9;
background-color: %%ACCENT_COLOR_PRESSED%%;
}
QPushButton:disabled {
@@ -338,7 +339,7 @@
}
QToolButton {
background-color: #4a9eff;
background-color: %%ACCENT_COLOR%%;
color: #ffffff;
border: none;
padding: 8px 12px;
@@ -349,11 +350,11 @@
}
QToolButton:hover {
background-color: #5dafff;
background-color: %%ACCENT_COLOR_HOVER%%;
}
QToolButton:pressed {
background-color: #2980b9;
background-color: %%ACCENT_COLOR_PRESSED%%;
}
QLabel {
@@ -377,7 +378,7 @@
}
QListWidget::item:selected {
background-color: #4a9eff;
background-color: %%ACCENT_COLOR%%;
color: #ffffff;
}
@@ -393,15 +394,15 @@
}
QSlider::handle:horizontal {
background-color: #4a9eff;
border: 1px solid #4a9eff;
background-color: %%ACCENT_COLOR%%;
border: 1px solid %%ACCENT_COLOR%%;
width: 18px;
margin: -5px 0;
border-radius: 9px;
}
QSlider::handle:horizontal:hover {
background-color: #5dafff;
background-color: %%ACCENT_COLOR_HOVER%%;
}
QSpinBox, QDoubleSpinBox {
@@ -414,7 +415,7 @@
}
QSpinBox:focus, QDoubleSpinBox:focus {
border-color: #4a9eff;
border-color: %%ACCENT_COLOR%%;
background-color: #404040;
}
@@ -433,12 +434,12 @@
}
QRadioButton::indicator:checked {
background-color: #4a9eff;
border-color: #4a9eff;
background-color: %%ACCENT_COLOR%%;
border-color: %%ACCENT_COLOR%%;
}
QRadioButton::indicator:hover {
border-color: #4a9eff;
border-color: %%ACCENT_COLOR%%;
}
/* High DPI specific styles */

View File

@@ -2,24 +2,27 @@
// SPDX-FileCopyrightText: 2025 citron Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "citron/configuration/configure_dialog.h"
#include <memory>
#include <QApplication>
#include <QButtonGroup>
#include <QMessageBox>
#include <QPushButton>
#include <QScreen>
#include <QApplication>
#include <QButtonGroup>
#include <QScrollArea>
#include <QString>
#include <QTimer>
#include "common/logging/log.h"
#include "common/settings.h"
#include "common/settings_enums.h"
#include "core/core.h"
#include "ui_configure.h"
#include "vk_device_info.h"
#include "citron/configuration/configuration_shared.h" // <-- Full definition included here
#include "citron/configuration/configure_applets.h"
#include "citron/configuration/configure_audio.h"
#include "citron/configuration/configure_cpu.h"
#include "citron/configuration/configure_debug_tab.h"
#include "citron/configuration/configure_dialog.h"
#include "citron/configuration/configure_filesystem.h"
#include "citron/configuration/configure_general.h"
#include "citron/configuration/configure_graphics.h"
@@ -33,9 +36,9 @@
#include "citron/configuration/configure_ui.h"
#include "citron/configuration/configure_web.h"
#include "citron/hotkeys.h"
#include "citron/theme.h"
#include "citron/uisettings.h"
// Helper function to create a scroll area for a widget
static QScrollArea* CreateScrollArea(QWidget* widget) {
auto* scroll_area = new QScrollArea();
scroll_area->setWidget(widget);
@@ -43,60 +46,6 @@ static QScrollArea* CreateScrollArea(QWidget* widget) {
scroll_area->setFrameShape(QFrame::NoFrame);
scroll_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scroll_area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
// High DPI support: Scroll area will inherit scaling from parent
// Set style with high DPI aware styling
scroll_area->setStyleSheet(QLatin1String(
"QScrollArea { "
"border: none; "
"background-color: #2b2b2b; "
"}"
"QScrollArea > QWidget > QWidget { "
"background-color: #2b2b2b; "
"}"
"QScrollBar:vertical { "
"background-color: #3d3d3d; "
"width: 14px; "
"border-radius: 7px; "
"margin: 2px; "
"}"
"QScrollBar::handle:vertical { "
"background-color: #5d5d5d; "
"border-radius: 6px; "
"min-height: 30px; "
"margin: 1px; "
"}"
"QScrollBar::handle:vertical:hover { "
"background-color: #4a9eff; "
"}"
"QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical { "
"border: none; "
"background: none; "
"height: 0px; "
"}"
"QScrollBar:horizontal { "
"background-color: #3d3d3d; "
"height: 14px; "
"border-radius: 7px; "
"margin: 2px; "
"}"
"QScrollBar::handle:horizontal { "
"background-color: #5d5d5d; "
"border-radius: 6px; "
"min-width: 30px; "
"margin: 1px; "
"}"
"QScrollBar::handle:horizontal:hover { "
"background-color: #4a9eff; "
"}"
"QScrollBar::add-line:horizontal, QScrollBar::sub-line:horizontal { "
"border: none; "
"background: none; "
"width: 0px; "
"}"
));
return scroll_area;
}
@@ -104,8 +53,8 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_,
InputCommon::InputSubsystem* input_subsystem,
std::vector<VkDeviceInfo::Record>& vk_device_records,
Core::System& system_, bool enable_web_config)
: QDialog(parent), ui{std::make_unique<Ui::ConfigureDialog>()},
registry(registry_), system{system_}, builder{std::make_unique<ConfigurationShared::Builder>(
: QDialog(parent), ui{std::make_unique<Ui::ConfigureDialog>()},
registry(registry_), system{system_}, builder{std::make_unique<ConfigurationShared::Builder>(
this, !system_.IsPoweredOn())},
applets_tab{std::make_unique<ConfigureApplets>(system_, nullptr, *builder, this)},
audio_tab{std::make_unique<ConfigureAudio>(system_, nullptr, *builder, this)},
@@ -122,48 +71,42 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_,
ui_tab->UpdateScreenshotInfo(ratio, setup);
},
nullptr, *builder, this)},
hotkeys_tab{std::make_unique<ConfigureHotkeys>(system_.HIDCore(), this)},
input_tab{std::make_unique<ConfigureInput>(system_, this)},
network_tab{std::make_unique<ConfigureNetwork>(system_, this)},
profile_tab{std::make_unique<ConfigureProfileManager>(system_, this)},
system_tab{std::make_unique<ConfigureSystem>(system_, nullptr, *builder, this)},
web_tab{std::make_unique<ConfigureWeb>(this)} {
hotkeys_tab{std::make_unique<ConfigureHotkeys>(system_.HIDCore(), this)},
input_tab{std::make_unique<ConfigureInput>(system_, this)},
network_tab{std::make_unique<ConfigureNetwork>(system_, this)},
profile_tab{std::make_unique<ConfigureProfileManager>(system_, this)},
system_tab{std::make_unique<ConfigureSystem>(system_, nullptr, *builder, this)},
web_tab{std::make_unique<ConfigureWeb>(this)},
rainbow_timer{new QTimer(this)} {
Settings::SetConfiguringGlobal(true);
// Set window flags to include maximize button and make it resizable
setWindowFlags(Qt::Dialog | Qt::WindowTitleHint | Qt::WindowSystemMenuHint |
Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
// High DPI support: Set proper attributes for scaling
setAttribute(Qt::WA_TranslucentBackground, false);
setAttribute(Qt::WA_NoSystemBackground, false);
setAttribute(Qt::WA_DontShowOnScreen, false);
ui->setupUi(this);
// Set size policy and enable resizing
UpdateTheme();
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// Get screen geometry and set to fullscreen with high DPI awareness
QScreen* screen = QApplication::primaryScreen();
if (screen) {
QRect screenGeometry = screen->availableGeometry();
// Calculate logical size based on device pixel ratio for high DPI support
qreal devicePixelRatio = screen->devicePixelRatio();
int logicalWidth = static_cast<int>(screenGeometry.width() / devicePixelRatio);
int logicalHeight = static_cast<int>(screenGeometry.height() / devicePixelRatio);
// Set geometry using logical units
setGeometry(0, 0, logicalWidth, logicalHeight);
showMaximized(); // Start maximized/fullscreen
showMaximized();
}
// Create button group for exclusive tab selection
tab_button_group = std::make_unique<QButtonGroup>(this);
tab_button_group->setExclusive(true);
// Add tab buttons to the button group and connect to stacked widget
tab_button_group->addButton(ui->generalTabButton, 0);
tab_button_group->addButton(ui->uiTabButton, 1);
tab_button_group->addButton(ui->systemTabButton, 2);
@@ -180,32 +123,32 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_,
tab_button_group->addButton(ui->appletsTabButton, 13);
tab_button_group->addButton(ui->loggingTabButton, 14);
// Add pages to stacked widget wrapped in scroll areas in the same order as button group
ui->stackedWidget->addWidget(CreateScrollArea(general_tab.get())); // 0
ui->stackedWidget->addWidget(CreateScrollArea(ui_tab.get())); // 1
ui->stackedWidget->addWidget(CreateScrollArea(system_tab.get())); // 2
ui->stackedWidget->addWidget(CreateScrollArea(cpu_tab.get())); // 3
ui->stackedWidget->addWidget(CreateScrollArea(graphics_tab.get())); // 4
ui->stackedWidget->addWidget(CreateScrollArea(graphics_advanced_tab.get())); // 5
ui->stackedWidget->addWidget(CreateScrollArea(audio_tab.get())); // 6
ui->stackedWidget->addWidget(CreateScrollArea(input_tab.get())); // 7
ui->stackedWidget->addWidget(CreateScrollArea(hotkeys_tab.get())); // 8
ui->stackedWidget->addWidget(CreateScrollArea(network_tab.get())); // 9
ui->stackedWidget->addWidget(CreateScrollArea(web_tab.get())); // 10
ui->stackedWidget->addWidget(CreateScrollArea(filesystem_tab.get()));// 11
ui->stackedWidget->addWidget(CreateScrollArea(profile_tab.get())); // 12
ui->stackedWidget->addWidget(CreateScrollArea(applets_tab.get())); // 13
ui->stackedWidget->addWidget(CreateScrollArea(debug_tab_tab.get())); // 14
ui->stackedWidget->addWidget(CreateScrollArea(general_tab.get()));
ui->stackedWidget->addWidget(CreateScrollArea(ui_tab.get()));
ui->stackedWidget->addWidget(CreateScrollArea(system_tab.get()));
ui->stackedWidget->addWidget(CreateScrollArea(cpu_tab.get()));
ui->stackedWidget->addWidget(CreateScrollArea(graphics_tab.get()));
ui->stackedWidget->addWidget(CreateScrollArea(graphics_advanced_tab.get()));
ui->stackedWidget->addWidget(CreateScrollArea(audio_tab.get()));
ui->stackedWidget->addWidget(CreateScrollArea(input_tab.get()));
ui->stackedWidget->addWidget(CreateScrollArea(hotkeys_tab.get()));
ui->stackedWidget->addWidget(CreateScrollArea(network_tab.get()));
ui->stackedWidget->addWidget(CreateScrollArea(web_tab.get()));
ui->stackedWidget->addWidget(CreateScrollArea(filesystem_tab.get()));
ui->stackedWidget->addWidget(CreateScrollArea(profile_tab.get()));
ui->stackedWidget->addWidget(CreateScrollArea(applets_tab.get()));
ui->stackedWidget->addWidget(CreateScrollArea(debug_tab_tab.get()));
// Connect button group to stacked widget
connect(tab_button_group.get(), QOverload<int>::of(&QButtonGroup::idClicked),
[this](int id) {
connect(tab_button_group.get(), qOverload<int>(&QButtonGroup::idClicked), this, [this](int id) {
ui->stackedWidget->setCurrentIndex(id);
if (id == 14) { // Logging tab
if (id == 14) {
debug_tab_tab->SetCurrentIndex(0);
}
});
connect(ui_tab.get(), &ConfigureUi::themeChanged, this, &ConfigureDialog::UpdateTheme);
connect(rainbow_timer, &QTimer::timeout, this, &ConfigureDialog::UpdateTheme);
web_tab->SetWebServiceConfigEnabled(enable_web_config);
hotkeys_tab->Populate(registry);
@@ -225,16 +168,43 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_,
}
}
// Set initial tab to General (index 0)
ui->stackedWidget->setCurrentIndex(0);
ui->generalTabButton->setChecked(true);
// Focus on the OK button by default
ui->buttonBox->setFocus();
}
// This line defines the destructor, completing the type for std::unique_ptr
ConfigureDialog::~ConfigureDialog() = default;
void ConfigureDialog::UpdateTheme() {
QString accent_color_str;
if (UISettings::values.enable_rainbow_mode.GetValue()) {
rainbow_hue += 0.005f;
if (rainbow_hue > 1.0f) {
rainbow_hue = 0.0f;
}
accent_color_str = QColor::fromHsvF(rainbow_hue, 0.8, 1.0).name();
if (!rainbow_timer->isActive()) {
rainbow_timer->start(16); // ~60 FPS
}
} else {
if (rainbow_timer->isActive()) {
rainbow_timer->stop();
}
accent_color_str = Theme::GetAccentColor();
}
QColor accent_color(accent_color_str);
QString accent_color_hover = accent_color.lighter(115).name();
QString accent_color_pressed = accent_color.darker(120).name();
QString style_sheet = property("templateStyleSheet").toString();
style_sheet.replace(QStringLiteral("%%ACCENT_COLOR%%"), accent_color_str);
style_sheet.replace(QStringLiteral("%%ACCENT_COLOR_HOVER%%"), accent_color_hover);
style_sheet.replace(QStringLiteral("%%ACCENT_COLOR_PRESSED%%"), accent_color_pressed);
setStyleSheet(style_sheet);
}
void ConfigureDialog::SetConfiguration() {}
void ConfigureDialog::ApplyConfiguration() {
@@ -281,9 +251,7 @@ void ConfigureDialog::HandleApplyButtonClicked() {
void ConfigureDialog::OnLanguageChanged(const QString& locale) {
emit LanguageChanged(locale);
// Reloading the game list is needed to force retranslation.
UISettings::values.is_game_list_reload_pending = true;
// first apply the configuration, and then restore the display
ApplyConfiguration();
RetranslateUI();
SetConfiguration();

View File

@@ -7,16 +7,25 @@
#include <memory>
#include <vector>
#include <QDialog>
#include <QButtonGroup>
#include "configuration/shared_widget.h"
#include "citron/configuration/configuration_shared.h"
#include "citron/configuration/shared_translation.h"
#include "citron/vk_device_info.h"
#include "common/settings_enums.h"
#include "citron/configuration/shared_widget.h" // <-- Correct header for Builder
namespace Core {
class System;
// Forward declarations for other types
class HotkeyRegistry;
class QButtonGroup;
class QTimer;
namespace InputCommon {
class InputSubsystem;
}
namespace Core {
class System;
}
namespace VkDeviceInfo {
struct Record;
}
namespace Ui {
class ConfigureDialog;
}
class ConfigureApplets;
class ConfigureAudio;
class ConfigureCpu;
@@ -27,56 +36,45 @@ class ConfigureGraphics;
class ConfigureGraphicsAdvanced;
class ConfigureHotkeys;
class ConfigureInput;
class ConfigureNetwork;
class ConfigureProfileManager;
class ConfigureSystem;
class ConfigureNetwork;
class ConfigureUi;
class ConfigureWeb;
class HotkeyRegistry;
namespace InputCommon {
class InputSubsystem;
}
namespace Ui {
class ConfigureDialog;
}
class ConfigureDialog : public QDialog {
class ConfigureDialog final : public QDialog {
Q_OBJECT
public:
explicit ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_,
explicit ConfigureDialog(QWidget* parent, HotkeyRegistry& registry,
InputCommon::InputSubsystem* input_subsystem,
std::vector<VkDeviceInfo::Record>& vk_device_records,
Core::System& system_, bool enable_web_config = true);
Core::System& system, bool enable_web_config);
~ConfigureDialog() override;
void ApplyConfiguration();
private slots:
void OnLanguageChanged(const QString& locale);
public slots:
void UpdateTheme();
signals:
void LanguageChanged(const QString& locale);
private:
void SetConfiguration();
void HandleApplyButtonClicked();
void changeEvent(QEvent* event) override;
void RetranslateUI();
void HandleApplyButtonClicked();
void SetConfiguration();
void OnLanguageChanged(const QString& locale);
// All members are now in the EXACT correct order to match the constructor
std::unique_ptr<Ui::ConfigureDialog> ui;
HotkeyRegistry& registry;
Core::System& system;
std::unique_ptr<ConfigurationShared::Builder> builder;
std::vector<ConfigurationShared::Tab*> tab_group;
std::unique_ptr<QButtonGroup> tab_button_group;
std::unique_ptr<ConfigureApplets> applets_tab;
std::unique_ptr<ConfigureAudio> audio_tab;
std::unique_ptr<ConfigureCpu> cpu_tab;
@@ -92,4 +90,7 @@ private:
std::unique_ptr<ConfigureProfileManager> profile_tab;
std::unique_ptr<ConfigureSystem> system_tab;
std::unique_ptr<ConfigureWeb> web_tab;
std::unique_ptr<QButtonGroup> tab_button_group;
QTimer* rainbow_timer;
float rainbow_hue = 0.0f;
};

View File

@@ -12,6 +12,7 @@
#include <utility>
#include <QCheckBox>
#include <QColorDialog>
#include <QComboBox>
#include <QCoreApplication>
#include <QDirIterator>
@@ -33,42 +34,42 @@
#include "citron/uisettings.h"
namespace {
constexpr std::array default_game_icon_sizes{
constexpr std::array default_game_icon_sizes{
std::make_pair(0, QT_TRANSLATE_NOOP("ConfigureUI", "None")),
std::make_pair(32, QT_TRANSLATE_NOOP("ConfigureUI", "Small (32x32)")),
std::make_pair(64, QT_TRANSLATE_NOOP("ConfigureUI", "Standard (64x64)")),
std::make_pair(128, QT_TRANSLATE_NOOP("ConfigureUI", "Large (128x128)")),
std::make_pair(256, QT_TRANSLATE_NOOP("ConfigureUI", "Full Size (256x256)")),
};
};
constexpr std::array default_folder_icon_sizes{
constexpr std::array default_folder_icon_sizes{
std::make_pair(0, QT_TRANSLATE_NOOP("ConfigureUI", "None")),
std::make_pair(24, QT_TRANSLATE_NOOP("ConfigureUI", "Small (24x24)")),
std::make_pair(48, QT_TRANSLATE_NOOP("ConfigureUI", "Standard (48x48)")),
std::make_pair(72, QT_TRANSLATE_NOOP("ConfigureUI", "Large (72x72)")),
};
};
// clang-format off
constexpr std::array row_text_names{
// clang-format off
constexpr std::array row_text_names{
QT_TRANSLATE_NOOP("ConfigureUI", "Filename"),
QT_TRANSLATE_NOOP("ConfigureUI", "Filetype"),
QT_TRANSLATE_NOOP("ConfigureUI", "Title ID"),
QT_TRANSLATE_NOOP("ConfigureUI", "Title Name"),
QT_TRANSLATE_NOOP("ConfigureUI", "None"),
};
// clang-format on
};
// clang-format on
QString GetTranslatedGameIconSize(size_t index) {
QString GetTranslatedGameIconSize(size_t index) {
return QCoreApplication::translate("ConfigureUI", default_game_icon_sizes[index].second);
}
}
QString GetTranslatedFolderIconSize(size_t index) {
QString GetTranslatedFolderIconSize(size_t index) {
return QCoreApplication::translate("ConfigureUI", default_folder_icon_sizes[index].second);
}
}
QString GetTranslatedRowTextName(size_t index) {
QString GetTranslatedRowTextName(size_t index) {
return QCoreApplication::translate("ConfigureUI", row_text_names[index]);
}
}
} // Anonymous namespace
static float GetUpFactor(Settings::ResolutionSetup res_setup) {
@@ -102,9 +103,9 @@ static u32 ScreenshotDimensionToInt(const QString& height) {
}
ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent)
: QWidget(parent), ui{std::make_unique<Ui::ConfigureUi>()},
ratio{Settings::values.aspect_ratio.GetValue()},
resolution_setting{Settings::values.resolution_setup.GetValue()}, system{system_} {
: QWidget(parent), ui{std::make_unique<Ui::ConfigureUi>()},
ratio{Settings::values.aspect_ratio.GetValue()},
resolution_setting{Settings::values.resolution_setup.GetValue()}, system{system_} {
ui->setupUi(this);
InitializeLanguageComboBox();
@@ -121,26 +122,31 @@ ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent)
SetConfiguration();
connect(ui->accentColorButton, &QPushButton::clicked, this, &ConfigureUi::OnAccentColorButtonPressed);
connect(ui->rainbowModeCheckBox, &QCheckBox::checkStateChanged, this, [this](int state) {
emit themeChanged();
});
// Force game list reload if any of the relevant settings are changed.
connect(ui->show_add_ons, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_compat, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_size, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_types, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_play_time, &QCheckBox::stateChanged, this,
connect(ui->show_add_ons, &QCheckBox::checkStateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_compat, &QCheckBox::checkStateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_size, &QCheckBox::checkStateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_types, &QCheckBox::checkStateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_play_time, &QCheckBox::checkStateChanged, this,
&ConfigureUi::RequestGameListUpdate);
connect(ui->game_icon_size_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
connect(ui->game_icon_size_combobox, &QComboBox::currentIndexChanged, this,
&ConfigureUi::RequestGameListUpdate);
connect(ui->folder_icon_size_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged),
connect(ui->folder_icon_size_combobox, &QComboBox::currentIndexChanged,
this, &ConfigureUi::RequestGameListUpdate);
connect(ui->row_1_text_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
connect(ui->row_1_text_combobox, &QComboBox::currentIndexChanged, this,
&ConfigureUi::RequestGameListUpdate);
connect(ui->row_2_text_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
connect(ui->row_2_text_combobox, &QComboBox::currentIndexChanged, this,
&ConfigureUi::RequestGameListUpdate);
// Update text ComboBoxes after user interaction.
connect(ui->row_1_text_combobox, QOverload<int>::of(&QComboBox::activated),
connect(ui->row_1_text_combobox, &QComboBox::activated,
[this] { ConfigureUi::UpdateSecondRowComboBox(); });
connect(ui->row_2_text_combobox, QOverload<int>::of(&QComboBox::activated),
connect(ui->row_2_text_combobox, &QComboBox::activated,
[this] { ConfigureUi::UpdateFirstRowComboBox(); });
// Set screenshot path to user specification.
@@ -168,6 +174,7 @@ ConfigureUi::~ConfigureUi() = default;
void ConfigureUi::ApplyConfiguration() {
UISettings::values.theme =
ui->theme_combobox->itemData(ui->theme_combobox->currentIndex()).toString().toStdString();
UISettings::values.enable_rainbow_mode = ui->rainbowModeCheckBox->isChecked();
UISettings::values.show_add_ons = ui->show_add_ons->isChecked();
UISettings::values.show_compat = ui->show_compat->isChecked();
UISettings::values.show_size = ui->show_size->isChecked();
@@ -198,6 +205,7 @@ void ConfigureUi::SetConfiguration() {
ui->theme_combobox->findData(QString::fromStdString(UISettings::values.theme)));
ui->language_combobox->setCurrentIndex(ui->language_combobox->findData(
QString::fromStdString(UISettings::values.language.GetValue())));
ui->rainbowModeCheckBox->setChecked(UISettings::values.enable_rainbow_mode.GetValue());
ui->show_add_ons->setChecked(UISettings::values.show_add_ons.GetValue());
ui->show_compat->setChecked(UISettings::values.show_compat.GetValue());
ui->show_size->setChecked(UISettings::values.show_size.GetValue());
@@ -221,6 +229,18 @@ void ConfigureUi::SetConfiguration() {
}
}
void ConfigureUi::OnAccentColorButtonPressed() {
const QColor current_color(QString::fromStdString(UISettings::values.accent_color.GetValue()));
QColorDialog dialog(current_color, this);
if (dialog.exec() == QDialog::Accepted) {
const QColor color = dialog.selectedColor();
if (color.isValid()) {
UISettings::values.accent_color.SetValue(color.name().toStdString());
emit themeChanged();
}
}
}
void ConfigureUi::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
@@ -263,10 +283,7 @@ void ConfigureUi::InitializeLanguageComboBox() {
ui->language_combobox->addItem(QStringLiteral("%1 (%2)").arg(lang, country), locale);
}
// Unlike other configuration changes, interface language changes need to be reflected on the
// interface immediately. This is done by passing a signal to the main window, and then
// retranslating when passing back.
connect(ui->language_combobox, qOverload<int>(&QComboBox::currentIndexChanged), this,
connect(ui->language_combobox, &QComboBox::currentIndexChanged, this,
&ConfigureUi::OnLanguageChanged);
}

View File

@@ -1,4 +1,5 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-FileCopyrightText: 2025 citron Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
@@ -8,11 +9,11 @@
#include "common/settings_enums.h"
namespace Core {
class System;
class System;
}
namespace Ui {
class ConfigureUi;
class ConfigureUi;
}
class ConfigureUi : public QWidget {
@@ -27,11 +28,13 @@ public:
void UpdateScreenshotInfo(Settings::AspectRatio ratio,
Settings::ResolutionSetup resolution_info);
private slots:
void OnLanguageChanged(int index);
signals:
void LanguageChanged(const QString& locale);
void themeChanged();
private slots:
void OnLanguageChanged(int index);
void OnAccentColorButtonPressed();
private:
void RequestGameListUpdate();

View File

@@ -23,131 +23,7 @@
<string>UI</string>
</property>
<property name="styleSheet">
<string>QWidget {
background-color: #2b2b2b;
color: #ffffff;
}
QGroupBox {
font-weight: bold;
border: 1px solid #3d3d3d;
border-radius: 8px;
margin-top: 12px;
padding-top: 12px;
background-color: #2b2b2b;
}
QGroupBox::title {
subcontrol-origin: margin;
left: 12px;
padding: 0 8px 0 8px;
color: #ffffff;
}
QCheckBox {
color: #ffffff;
spacing: 12px;
padding: 6px;
background-color: transparent;
min-height: 24px;
}
QCheckBox::indicator {
width: 18px;
height: 18px;
border: 2px solid #5d5d5d;
border-radius: 4px;
background-color: #3d3d3d;
}
QCheckBox::indicator:checked {
background-color: #4a9eff;
border-color: #4a9eff;
}
QCheckBox::indicator:hover {
border-color: #4a9eff;
}
QComboBox {
background-color: #3d3d3d;
border: 1px solid #5d5d5d;
border-radius: 6px;
padding: 8px 12px;
color: #ffffff;
min-width: 160px;
min-height: 28px;
}
QComboBox:hover {
border-color: #4a9eff;
background-color: #404040;
}
QComboBox:focus {
border-color: #4a9eff;
background-color: #404040;
}
QComboBox::drop-down {
border: none;
width: 24px;
subcontrol-origin: padding;
subcontrol-position: top right;
}
QComboBox::down-arrow {
width: 12px;
height: 12px;
}
QComboBox QAbstractItemView {
background-color: #3d3d3d;
border: 1px solid #4a9eff;
selection-background-color: #4a9eff;
color: #ffffff;
}
QLineEdit {
background-color: #3d3d3d;
border: 1px solid #5d5d5d;
border-radius: 6px;
padding: 8px 12px;
color: #ffffff;
min-height: 28px;
}
QLineEdit:focus {
border-color: #4a9eff;
background-color: #404040;
}
QToolButton {
background-color: #4a9eff;
color: #ffffff;
border: none;
padding: 8px 12px;
border-radius: 6px;
font-weight: bold;
min-width: 40px;
min-height: 32px;
}
QToolButton:hover {
background-color: #5dafff;
}
QToolButton:pressed {
background-color: #2980b9;
}
QLabel {
color: #ffffff;
background-color: transparent;
padding: 4px;
min-width: 140px;
}
</string>
<string>/* This stylesheet is a template. Placeholders like %%ACCENT_COLOR%% are replaced in C++. */</string>
</property>
<layout class="QHBoxLayout" name="mainHorizontalLayout">
<property name="spacing">
@@ -270,6 +146,40 @@ QLabel {
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="accentColorLayout">
<property name="spacing">
<number>16</number>
</property>
<item>
<widget class="QLabel" name="accentColorLabel">
<property name="text">
<string>Accent Color:</string>
</property>
<property name="minimumSize">
<size>
<width>140</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="accentColorButton">
<property name="text">
<string>Choose Color...</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="rainbowModeCheckBox">
<property name="text">
<string>Enable Rainbow Mode</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>

29
src/citron/theme.h Normal file
View File

@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: 2025 citron Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <QColor>
#include <QString>
#include "citron/uisettings.h"
namespace Theme {
// Gets the user-defined accent color from settings, with a default fallback.
inline QString GetAccentColor() {
return QString::fromStdString(UISettings::values.accent_color.GetValue());
}
// Gets a lighter version of the accent color for hover effects.
inline QString GetAccentColorHover() {
QColor color(GetAccentColor());
return color.lighter(115).name(); // 115% of original brightness
}
// Gets a darker version of the accent color for pressed effects.
inline QString GetAccentColorPressed() {
QColor color(GetAccentColor());
return color.darker(120).name(); // 120% of original darkness
}
} // namespace Theme

View File

@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project
// SPDX-FileCopyrightText: 2025 citron Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <QSettings>
@@ -9,13 +9,13 @@
#ifndef CANNOT_EXPLICITLY_INSTANTIATE
namespace Settings {
template class Setting<bool>;
template class Setting<std::string>;
template class Setting<u16, true>;
template class Setting<u32>;
template class Setting<u8, true>;
template class Setting<u8>;
template class Setting<unsigned long long>;
template class Setting<bool>;
template class Setting<std::string>;
template class Setting<u16, true>;
template class Setting<u32>;
template class Setting<u8, true>;
template class Setting<u8>;
template class Setting<unsigned long long>;
} // namespace Settings
#endif
@@ -23,24 +23,24 @@ namespace FS = Common::FS;
namespace UISettings {
const Themes themes{{
const Themes themes{{
{"Default", "default"},
{"Default Colorful", "colorful"},
{"Dark", "qdarkstyle"},
{"Dark Colorful", "colorful_dark"},
{"Midnight Blue", "qdarkstyle_midnight_blue"},
{"Midnight Blue Colorful", "colorful_midnight_blue"},
}};
}};
bool IsDarkTheme() {
bool IsDarkTheme() {
const auto& theme = UISettings::values.theme;
return theme == std::string("qdarkstyle") || theme == std::string("qdarkstyle_midnight_blue") ||
theme == std::string("colorful_dark") || theme == std::string("colorful_midnight_blue");
}
}
Values values = {};
Values values = {};
u32 CalculateWidth(u32 height, Settings::AspectRatio ratio) {
u32 CalculateWidth(u32 height, Settings::AspectRatio ratio) {
switch (ratio) {
case Settings::AspectRatio::R4_3:
return height * 4 / 3;
@@ -56,9 +56,9 @@ u32 CalculateWidth(u32 height, Settings::AspectRatio ratio) {
break;
}
return height * 16 / 9;
}
}
void SaveWindowState() {
void SaveWindowState() {
const auto window_state_config_loc =
FS::PathToUTF8String(FS::GetCitronPath(FS::CitronPath::ConfigDir) / "window_state.ini");
@@ -72,9 +72,9 @@ void SaveWindowState() {
config.setValue(QStringLiteral("microProfileDialogGeometry"), values.microprofile_geometry);
config.sync();
}
}
void RestoreWindowState(std::unique_ptr<QtConfig>& qtConfig) {
void RestoreWindowState(std::unique_ptr<QtConfig>& qtConfig) {
const auto window_state_config_loc =
FS::PathToUTF8String(FS::GetCitronPath(FS::CitronPath::ConfigDir) / "window_state.ini");
@@ -110,6 +110,6 @@ void RestoreWindowState(std::unique_ptr<QtConfig>& qtConfig) {
config.value(QStringLiteral("gameListHeaderState")).toByteArray();
values.microprofile_geometry =
config.value(QStringLiteral("microProfileDialogGeometry")).toByteArray();
}
}
} // namespace UISettings

View File

@@ -1,4 +1,5 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-FileCopyrightText: 2025 citron Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
@@ -23,54 +24,54 @@ using Settings::SwitchableSetting;
#ifndef CANNOT_EXPLICITLY_INSTANTIATE
namespace Settings {
extern template class Setting<bool>;
extern template class Setting<std::string>;
extern template class Setting<u16, true>;
extern template class Setting<u32>;
extern template class Setting<u8, true>;
extern template class Setting<u8>;
extern template class Setting<unsigned long long>;
extern template class Setting<bool>;
extern template class Setting<std::string>;
extern template class Setting<u16, true>;
extern template class Setting<u32>;
extern template class Setting<u8, true>;
extern template class Setting<u8>;
extern template class Setting<unsigned long long>;
} // namespace Settings
#endif
namespace UISettings {
bool IsDarkTheme();
bool IsDarkTheme();
struct ContextualShortcut {
struct ContextualShortcut {
std::string keyseq;
std::string controller_keyseq;
int context;
bool repeat;
};
};
struct Shortcut {
struct Shortcut {
std::string name;
std::string group;
ContextualShortcut shortcut;
};
};
enum class Theme {
enum class Theme {
Default,
DefaultColorful,
Dark,
DarkColorful,
MidnightBlue,
MidnightBlueColorful,
};
};
static constexpr Theme default_theme{
#ifdef _WIN32
static constexpr Theme default_theme{
#ifdef _WIN32
Theme::DarkColorful
#else
#else
Theme::DefaultColorful
#endif
};
#endif
};
using Themes = std::array<std::pair<const char*, const char*>, 6>;
extern const Themes themes;
using Themes = std::array<std::pair<const char*, const char*>, 6>;
extern const Themes themes;
struct GameDir {
struct GameDir {
std::string path;
bool deep_scan = false;
bool expanded = false;
@@ -80,9 +81,9 @@ struct GameDir {
bool operator!=(const GameDir& rhs) const {
return !operator==(rhs);
}
};
};
struct Values {
struct Values {
Settings::Linkage linkage{1000};
QByteArray geometry;
@@ -164,6 +165,9 @@ struct Values {
std::string theme;
Setting<std::string> accent_color{linkage, "#4a9eff", "accent_color", Category::Ui};
Setting<bool> enable_rainbow_mode{linkage, false, "enable_rainbow_mode", Category::Ui};
// Shortcut name <Shortcut, context>
std::vector<Shortcut> shortcuts;
@@ -218,21 +222,21 @@ struct Values {
bool configuration_applied;
bool reset_to_defaults;
bool shortcut_already_warned{false};
};
};
extern Values values;
extern Values values;
u32 CalculateWidth(u32 height, Settings::AspectRatio ratio);
u32 CalculateWidth(u32 height, Settings::AspectRatio ratio);
void SaveWindowState();
void RestoreWindowState(std::unique_ptr<QtConfig>& qtConfig);
void SaveWindowState();
void RestoreWindowState(std::unique_ptr<QtConfig>& qtConfig);
// This shouldn't have anything except static initializers (no functions). So
// QKeySequence(...).toString() is NOT ALLOWED HERE.
// This must be in alphabetical order according to action name as it must have the same order as
// UISetting::values.shortcuts, which is alphabetically ordered.
// clang-format off
const std::array<Shortcut, 29> default_hotkeys{{
// This shouldn't have anything except static initializers (no functions). So
// QKeySequence(...).toString() is NOT ALLOWED HERE.
// This must be in alphabetical order according to action name as it must have the same order as
// UISetting::values.shortcuts, which is alphabetically ordered.
// clang-format off
const std::array<Shortcut, 29> default_hotkeys{{
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Audio Mute/Unmute")).toStdString(), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")).toStdString(), {std::string("Ctrl+M"), std::string("Home+Dpad_Right"), Qt::WindowShortcut, false}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Audio Volume Down")).toStdString(), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")).toStdString(), {std::string("-"), std::string("Home+Dpad_Down"), Qt::ApplicationShortcut, true}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Audio Volume Up")).toStdString(), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")).toStdString(), {std::string("="), std::string("Home+Dpad_Up"), Qt::ApplicationShortcut, true}},
@@ -262,7 +266,7 @@ const std::array<Shortcut, 29> default_hotkeys{{
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Toggle Mouse Panning")).toStdString(), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")).toStdString(), {std::string("Ctrl+F9"), std::string(""), Qt::ApplicationShortcut, false}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Toggle Renderdoc Capture")).toStdString(), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")).toStdString(), {std::string(""), std::string(""), Qt::ApplicationShortcut, false}},
{QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Toggle Status Bar")).toStdString(), QStringLiteral(QT_TRANSLATE_NOOP("Hotkeys", "Main Window")).toStdString(), {std::string("Ctrl+S"), std::string(""), Qt::WindowShortcut, false}},
}};
}};
// clang-format on
} // namespace UISettings