mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
refactor: add separate settings
This commit is contained in:
parent
c339fe486c
commit
c5a800280f
|
@ -212,15 +212,7 @@ const std::vector<ThemeDescriptor> Theme::builtInThemes{
|
|||
.key = "Black",
|
||||
.path = ":/themes/Black.json",
|
||||
.name = "Black",
|
||||
}
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
|
||||
,
|
||||
{
|
||||
.key = "System",
|
||||
.path = ":/themes/Dark.json",
|
||||
.name = "System",
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
// Dark is our default & fallback theme
|
||||
|
@ -244,6 +236,14 @@ void Theme::initialize(Settings &settings, const Paths &paths)
|
|||
this->update();
|
||||
},
|
||||
false);
|
||||
auto updateIfSystem = [this](const auto &) {
|
||||
if (this->isSystemTheme())
|
||||
{
|
||||
this->update();
|
||||
}
|
||||
};
|
||||
this->darkSystemThemeName.connect(updateIfSystem, false);
|
||||
this->lightSystemThemeName.connect(updateIfSystem, false);
|
||||
|
||||
this->loadAvailableThemes(paths);
|
||||
|
||||
|
@ -270,10 +270,10 @@ void Theme::update()
|
|||
switch (qApp->styleHints()->colorScheme())
|
||||
{
|
||||
case Qt::ColorScheme::Light:
|
||||
return u"Light"_s;
|
||||
return this->lightSystemThemeName;
|
||||
case Qt::ColorScheme::Unknown:
|
||||
case Qt::ColorScheme::Dark:
|
||||
return u"Dark"_s;
|
||||
return this->darkSystemThemeName;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -154,6 +154,9 @@ public:
|
|||
pajlada::Signals::NoArgSignal updated;
|
||||
|
||||
QStringSetting themeName{"/appearance/theme/name", "Dark"};
|
||||
QStringSetting lightSystemThemeName{"/appearance/theme/lightSystem",
|
||||
"Light"};
|
||||
QStringSetting darkSystemThemeName{"/appearance/theme/darkSystem", "Dark"};
|
||||
|
||||
private:
|
||||
bool isLight_ = false;
|
||||
|
|
|
@ -122,16 +122,49 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
|||
|
||||
layout.addTitle("Interface");
|
||||
|
||||
layout.addDropdown<QString>(
|
||||
"Theme", getIApp()->getThemes()->availableThemes(),
|
||||
getIApp()->getThemes()->themeName,
|
||||
{
|
||||
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();
|
||||
return args.combobox->itemData(args.index, Qt::UserRole)
|
||||
.toString();
|
||||
},
|
||||
{}, Theme::fallbackTheme.name);
|
||||
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..."},
|
||||
|
|
|
@ -306,6 +306,15 @@ public:
|
|||
return combo;
|
||||
}
|
||||
|
||||
void enableIf(QComboBox *widget, auto &setting, auto cb)
|
||||
{
|
||||
auto updateVisibility = [cb = std::move(cb), &setting, widget]() {
|
||||
auto enabled = cb(setting.getValue());
|
||||
widget->setEnabled(enabled);
|
||||
};
|
||||
setting.connect(updateVisibility, this->managedConnections_);
|
||||
}
|
||||
|
||||
DescriptionLabel *addDescription(const QString &text);
|
||||
|
||||
void addSeperator();
|
||||
|
|
Loading…
Reference in a new issue