Compare commits

..

4 Commits

Author SHA1 Message Date
flodavid f87425e3d9 Fix qdarkstyle and midnight blue sliders being cropped
- Allow Threshold sliders in control configuration to be up to 40px tall, instead of 15
2024-03-27 22:55:56 +01:00
flodavid e08c432a94 Add dark mode configuration setting in UI tab
- Allows to choose "Auto", "Always On" or "Always Off"
  - Dark mode options are only shown if the style does not support theme
- If Auto is chosen, value is retrieved from OS
  - On Windows, the application needs a restart to apply the settings
- Use the default dark palette for Windows, like on Linux
2024-03-27 22:55:56 +01:00
flodavid 743279c466 Rework themes to easily use light/dark palette, using only different icons
- Renamed themes:
  - "colorful" to "default" and "colorful_dark" to "default_dark"
  - "default" to "monochrome" and "default_dark" to "monochrome_dark"
  - "colorful_midnight_blue" to "qdarkstyle_midnight_blue"
  - "qdarkstyle_midnight_blue" to "qdarkstyle_midnight_blue_monochrome"
  - qdarkstyle is renamed from "Dark" to "Mine Shaft" in the UI
- default and monochrome themes all use the same qss stylesheet
- Remove the ability to select "default_dark" directly
    - Default has better support for light and dark
    - Controller and Keyboard applets icons and style adapt to dark mode
- Add "qdarkstyle_monochrome" theme
- Remove duplicated icon files
2024-03-27 22:55:56 +01:00
flodavid 740247b757 Automatic dark theme switching for Windows and Linux
- Windows dark theme uses "fusion" style, which is better suited, but has minor differences
- Improve OS theme detection
  - Linux:
    - Listen for OS color schemes changes on D-Bus
    - Read OS scheme for D-Bus. Fallback with gsettings, reading org.gnome.desktop.interface.
      First "color-scheme" key, then "gtk-theme". Finally, fallback to checking window palette
  - Windows (dark mode detection was not implemented before):
    - Force dark palette when OS uses dark mode by setting QT_QPA_PLATFORM to "windows:darkmode=2"
    - This enables to detect dark mode by checking the window palette
- Improve theming capabilites:
  - Linux uses custom palette when dark mode is detected.
    By using palette(xxx) in .qss files, there is no need to create a dark stylesheet
  - Allow themes to have stylesheet variants, dark.qss and light.qss
  - If current mode is dark, use dark icons for controller and keyboard applets
  - Add "dark" property to RendererStatusBarButton and GPUStatusBarButton, set to true when dark mode is used.
    Allows to have distinct colors for GPU API and accuracy buttons depending on dark mode or not
  - Enable all themes to have dark icon alternatives, not just "default" and "colorful"
    - If dark mode, icons are loaded from the directory "THEME-NAME_dark/icons"
  - If current mode is dark, use dark icons for controller and keyboard applets
  - Only qdarkstyle, qdarkstyle_midnight_blue, colorful_dark and
    colorful_midnight_blue used elements specific to dark themes
2024-03-27 22:55:55 +01:00
4 changed files with 24 additions and 20 deletions

View File

@ -220,9 +220,9 @@ void ConfigureUi::UpdateDarkModeOptions() {
QString selected_theme = ui->theme_combobox->currentData().toString();
/* Dark mode option are added according to the modes the current style supports */
bool has_common_style = QFile::exists(selected_theme + QStringLiteral("style.qss"));
bool has_light_style = QFile::exists(selected_theme + QStringLiteral("light.qss"));
bool has_dark_style = QFile::exists(selected_theme + QStringLiteral("dark.qss"));
bool has_common_style = QFile::exists(selected_theme + QStringLiteral("/style.qss"));
bool has_light_style = QFile::exists(selected_theme + QStringLiteral("/light.qss"));
bool has_dark_style = QFile::exists(selected_theme + QStringLiteral("/dark.qss"));
#ifdef _WIN32
// Indicate which option needs a restart to be applied, depending on current environment
// variable

View File

@ -4810,7 +4810,7 @@ void GMainWindow::UpdateUITheme() {
LOG_ERROR(Frontend, "Unable to open style \"{}\", fallback to the default theme",
current_theme.toStdString());
if (TryLoadStylesheet(QStringLiteral(":/%1/").arg(default_theme))) {
if (TryLoadStylesheet(QStringLiteral(":/%1").arg(default_theme))) {
return;
}
@ -4821,14 +4821,18 @@ void GMainWindow::UpdateUITheme() {
setStyleSheet({});
}
void GMainWindow::UpdateIcons(const QString& theme_used) {
void GMainWindow::UpdateIcons(const QString& theme_path) {
// Get the theme directory from its path
std::size_t last_slash = theme_path.toStdString().find_last_of("/");
QString theme_dir = QString::fromStdString(theme_path.toStdString().substr(last_slash + 1));
// Append _dark to the theme name to use dark variant icons
if (CheckDarkMode()) {
LOG_DEBUG(Frontend, "Using icons from: {}", theme_used.toStdString() + "_dark");
QIcon::setThemeName(theme_used + QStringLiteral("_dark"));
LOG_DEBUG(Frontend, "Using icons from: {}", theme_dir.toStdString() + "_dark");
QIcon::setThemeName(theme_dir + QStringLiteral("_dark"));
} else {
LOG_DEBUG(Frontend, "Using icons from: {}", theme_used.toStdString());
QIcon::setThemeName(theme_used);
LOG_DEBUG(Frontend, "Using icons from: {}", theme_dir.toStdString());
QIcon::setThemeName(theme_dir);
}
const QString theme_directory{
@ -4840,7 +4844,7 @@ void GMainWindow::UpdateIcons(const QString& theme_used) {
theme_paths << QString::fromStdString(":/icons") << QStringLiteral("%1").arg(theme_directory);
QIcon::setThemeSearchPaths(theme_paths);
// Change current directory, to allow user themes to use their own icons
// Change current directory, to allow user themes to add their own icons
QDir::setCurrent(QStringLiteral("%1/%2").arg(theme_directory, UISettings::values.theme));
emit UpdateThemedIcons();
@ -4851,14 +4855,14 @@ bool GMainWindow::TryLoadStylesheet(const QString& theme_uri) {
// Use themed stylesheet if it exists
if (CheckDarkMode()) {
style_path = theme_uri + QStringLiteral("dark.qss");
style_path = theme_uri + QStringLiteral("/dark.qss");
} else {
style_path = theme_uri + QStringLiteral("light.qss");
style_path = theme_uri + QStringLiteral("/light.qss");
}
if (!QFile::exists(style_path)) {
LOG_DEBUG(Frontend, "No themed (light/dark) stylesheet, using default one");
// Use common stylesheet if themed one does not exist
style_path = theme_uri + QStringLiteral("style.qss");
style_path = theme_uri + QStringLiteral("/style.qss");
}
// Loading stylesheet

View File

@ -23,12 +23,12 @@ namespace FS = Common::FS;
namespace UISettings {
const Themes included_themes{{
{"Default", ":/default/"},
{"Default monochrome", ":/monochrome/"},
{"Mine Shaft", ":/qdarkstyle/"},
{"Mine Shaft monochrome", ":/qdarkstyle_monochrome/"},
{"Midnight Blue", ":/qdarkstyle_midnight_blue/"},
{"Midnight Blue monochrome", ":/qdarkstyle_midnight_blue_monochrome/"},
{"Default", ":/default"},
{"Default monochrome", ":/monochrome"},
{"Mine Shaft", ":/qdarkstyle"},
{"Mine Shaft monochrome", ":/qdarkstyle_monochrome"},
{"Midnight Blue", ":/qdarkstyle_midnight_blue"},
{"Midnight Blue monochrome", ":/qdarkstyle_midnight_blue_monochrome"},
}};
Values values = {};

View File

@ -49,7 +49,7 @@ struct Shortcut {
ContextualShortcut shortcut;
};
static constexpr std::string_view default_theme{"default"};
static constexpr std::string_view default_theme{":/default"};
using Themes = std::array<std::pair<const char*, const char*>, 6>;
extern const Themes included_themes;