feat: add system theme on Qt 6.5 and up (#5118)

* feat: add system theme on Qt 6.5

* chroe: add changelog entry

* refactor: add separate settings

* fix: qt 5

* Update changelog entry

---------

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix
2024-01-27 11:53:19 +01:00
committed by GitHub
parent 7d7f1b3bea
commit c32ee8e5b5
5 changed files with 105 additions and 11 deletions
+43 -10
View File
@@ -122,16 +122,49 @@ void GeneralPage::initLayout(GeneralPageView &layout)
layout.addTitle("Interface");
layout.addDropdown<QString>(
"Theme", getIApp()->getThemes()->availableThemes(),
getIApp()->getThemes()->themeName,
[](const auto *combo, const auto &themeKey) {
return combo->findData(themeKey, Qt::UserRole);
},
[](const auto &args) {
return args.combobox->itemData(args.index, Qt::UserRole).toString();
},
{}, Theme::fallbackTheme.name);
{
auto *themes = getIApp()->getThemes();
auto available = themes->availableThemes();
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
available.emplace_back("System", "System");
#endif
auto addThemeDropdown = [&](auto name, auto &setting,
const auto &options,
const QString &tooltip = {}) {
return layout.addDropdown<QString>(
name, options, setting,
[](const auto *combo, const auto &themeKey) {
return combo->findData(themeKey, Qt::UserRole);
},
[](const auto &args) {
return args.combobox->itemData(args.index, Qt::UserRole)
.toString();
},
tooltip, Theme::fallbackTheme.name);
};
addThemeDropdown("Theme", themes->themeName, available);
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
auto *darkDropdown = addThemeDropdown(
"Dark system theme", themes->darkSystemThemeName,
themes->availableThemes(),
"This theme is selected if your system is in a dark theme and you "
"enabled the adaptive 'System' theme.");
auto *lightDropdown = addThemeDropdown(
"Light system theme", themes->lightSystemThemeName,
themes->availableThemes(),
"This theme is selected if your system is in a light theme and you "
"enabled the adaptive 'System' theme.");
auto isSystem = [](const auto &s) {
return s == "System";
};
layout.enableIf(darkDropdown, themes->themeName, isSystem);
layout.enableIf(lightDropdown, themes->themeName, isSystem);
#endif
}
layout.addDropdown<QString>(
"Font", {"Segoe UI", "Arial", "Choose..."},