Skip to content

Commit

Permalink
Change how new fusion styles are selected
Browse files Browse the repository at this point in the history
  • Loading branch information
AdenKoperczak committed Oct 21, 2024
1 parent 5c57ae0 commit 57d65cf
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 10 deletions.
6 changes: 6 additions & 0 deletions scwx-qt/scwx-qt.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@
<file>res/palettes/wct/SW.pal</file>
<file>res/palettes/wct/VIL.pal</file>
<file>res/palettes/wct/ZDR.pal</file>
<file>res/qt6ct_colors/airy.conf</file>
<file>res/qt6ct_colors/darker.conf</file>
<file>res/qt6ct_colors/dusk.conf</file>
<file>res/qt6ct_colors/ia_ora.conf</file>
<file>res/qt6ct_colors/sand.conf</file>
<file>res/qt6ct_colors/simple.conf</file>
<file>res/qt6ct_colors/waves.conf</file>
<file>res/textures/lines/default-1x7.png</file>
<file>res/textures/lines/test-pattern.png</file>
<file>res/textures/images/cursor-17.png</file>
Expand Down
20 changes: 17 additions & 3 deletions scwx-qt/source/scwx/qt/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,24 @@ static void ConfigureTheme(const std::vector<std::string>& args)

QGuiApplication::styleHints()->setColorScheme(qtColorScheme);

if (uiStyle == scwx::qt::types::UiStyle::FusionQt6Ct)
std::optional<std::string> paletteFile =
scwx::qt::types::GetQtPaletteFile(uiStyle);
if (paletteFile)
{
QPalette palette = Qt6CT::loadColorScheme(":res/qt6ct_colors/darker.conf",
QApplication::style()->standardPalette());;
QPalette defaultPalette = QApplication::style()->standardPalette();
QPalette palette =
Qt6CT::loadColorScheme(QString::fromStdString(*paletteFile),
defaultPalette);

if (defaultPalette == palette)
{
logger_->warn("Failed to load palette file '{}'", *paletteFile);
}
else
{
logger_->info("Loaded palette file '{}'", *paletteFile);
}

QApplication::setPalette(palette);
}
}
Expand Down
39 changes: 36 additions & 3 deletions scwx-qt/source/scwx/qt/types/qt_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,48 @@ static const std::unordered_map<UiStyle, std::string> qtStyleName_ {
{UiStyle::Fusion, "Fusion"},
{UiStyle::FusionLight, "Fusion"},
{UiStyle::FusionDark, "Fusion"},
{UiStyle::FusionQt6Ct, "Fusion"},
{UiStyle::FusionAiry, "Fusion"},
{UiStyle::FusionDarker, "Fusion"},
{UiStyle::FusionDusk, "Fusion"},
{UiStyle::FusionIaOra, "Fusion"},
{UiStyle::FusionSand, "Fusion"},
{UiStyle::FusionWaves, "Fusion"},
{UiStyle::Unknown, "?"}};

static const std::unordered_map<UiStyle, std::string> uiStyleName_ {
{UiStyle::Default, "Default"},
{UiStyle::Fusion, "Fusion"},
{UiStyle::FusionLight, "Fusion Light"},
{UiStyle::FusionDark, "Fusion Dark"},
{UiStyle::FusionQt6Ct, "Fusion with qt6ct Palette"},
{UiStyle::FusionAiry, "Fusion Airy"},
{UiStyle::FusionDarker, "Fusion Darker"},
{UiStyle::FusionDusk, "Fusion Dusk"},
{UiStyle::FusionIaOra, "Fusion IA Ora"},
{UiStyle::FusionSand, "Fusion Sand"},
{UiStyle::FusionWaves, "Fusion Waves"},
{UiStyle::Unknown, "?"}};

static const std::unordered_map<UiStyle, Qt::ColorScheme> qtColorSchemeMap_ {
{UiStyle::Default, Qt::ColorScheme::Unknown},
{UiStyle::Fusion, Qt::ColorScheme::Unknown},
{UiStyle::FusionLight, Qt::ColorScheme::Light},
{UiStyle::FusionDark, Qt::ColorScheme::Dark},
{UiStyle::FusionQt6Ct, Qt::ColorScheme::Unknown},
{UiStyle::FusionAiry, Qt::ColorScheme::Unknown},
{UiStyle::FusionDarker, Qt::ColorScheme::Unknown},
{UiStyle::FusionDusk, Qt::ColorScheme::Unknown},
{UiStyle::FusionIaOra, Qt::ColorScheme::Unknown},
{UiStyle::FusionSand, Qt::ColorScheme::Unknown},
{UiStyle::FusionWaves, Qt::ColorScheme::Unknown},
{UiStyle::Unknown, Qt::ColorScheme::Unknown}};

static const std::unordered_map<UiStyle, std::string> paletteFile_ {
{UiStyle::FusionAiry, ":res/qt6ct_colors/airy.conf"},
{UiStyle::FusionDarker, ":res/qt6ct_colors/darker.conf"},
{UiStyle::FusionDusk, ":res/qt6ct_colors/dusk.conf"},
{UiStyle::FusionIaOra, ":res/qt6ct_colors/ia_ora.conf"},
{UiStyle::FusionSand, ":res/qt6ct_colors/sand.conf"},
{UiStyle::FusionWaves, ":res/qt6ct_colors/waves.conf"}};

SCWX_GET_ENUM(UiStyle, GetUiStyle, uiStyleName_)

Qt::ColorScheme GetQtColorScheme(UiStyle uiStyle)
Expand All @@ -46,6 +69,16 @@ std::string GetQtStyleName(UiStyle uiStyle)
return qtStyleName_.at(uiStyle);
}

std::optional<std::string> GetQtPaletteFile(UiStyle uiStyle)
{
if (paletteFile_.contains(uiStyle))
{
return paletteFile_.at(uiStyle);
}

return std::nullopt;
}

std::string GetUiStyleName(UiStyle uiStyle)
{
return uiStyleName_.at(uiStyle);
Expand Down
16 changes: 12 additions & 4 deletions scwx-qt/source/scwx/qt/types/qt_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <scwx/util/iterator.hpp>

#include <optional>
#include <string>

#include <Qt>
Expand All @@ -26,14 +27,21 @@ enum class UiStyle
Fusion,
FusionLight,
FusionDark,
FusionQt6Ct,
FusionAiry,
FusionDarker,
FusionDusk,
FusionIaOra,
FusionSand,
FusionWaves,
Unknown
};
typedef scwx::util::Iterator<UiStyle, UiStyle::Default, UiStyle::FusionQt6Ct>
typedef scwx::util::Iterator<UiStyle, UiStyle::Default, UiStyle::FusionWaves>
UiStyleIterator;

Qt::ColorScheme GetQtColorScheme(UiStyle uiStyle);
std::string GetQtStyleName(UiStyle uiStyle);
Qt::ColorScheme GetQtColorScheme(UiStyle uiStyle);
std::string GetQtStyleName(UiStyle uiStyle);

std::optional<std::string> GetQtPaletteFile(UiStyle uiStyle);

UiStyle GetUiStyle(const std::string& name);
std::string GetUiStyleName(UiStyle uiStyle);
Expand Down

0 comments on commit 57d65cf

Please sign in to comment.