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",
|
.key = "Black",
|
||||||
.path = ":/themes/Black.json",
|
.path = ":/themes/Black.json",
|
||||||
.name = "Black",
|
.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
|
// Dark is our default & fallback theme
|
||||||
|
@ -244,6 +236,14 @@ void Theme::initialize(Settings &settings, const Paths &paths)
|
||||||
this->update();
|
this->update();
|
||||||
},
|
},
|
||||||
false);
|
false);
|
||||||
|
auto updateIfSystem = [this](const auto &) {
|
||||||
|
if (this->isSystemTheme())
|
||||||
|
{
|
||||||
|
this->update();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this->darkSystemThemeName.connect(updateIfSystem, false);
|
||||||
|
this->lightSystemThemeName.connect(updateIfSystem, false);
|
||||||
|
|
||||||
this->loadAvailableThemes(paths);
|
this->loadAvailableThemes(paths);
|
||||||
|
|
||||||
|
@ -270,10 +270,10 @@ void Theme::update()
|
||||||
switch (qApp->styleHints()->colorScheme())
|
switch (qApp->styleHints()->colorScheme())
|
||||||
{
|
{
|
||||||
case Qt::ColorScheme::Light:
|
case Qt::ColorScheme::Light:
|
||||||
return u"Light"_s;
|
return this->lightSystemThemeName;
|
||||||
case Qt::ColorScheme::Unknown:
|
case Qt::ColorScheme::Unknown:
|
||||||
case Qt::ColorScheme::Dark:
|
case Qt::ColorScheme::Dark:
|
||||||
return u"Dark"_s;
|
return this->darkSystemThemeName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -154,6 +154,9 @@ public:
|
||||||
pajlada::Signals::NoArgSignal updated;
|
pajlada::Signals::NoArgSignal updated;
|
||||||
|
|
||||||
QStringSetting themeName{"/appearance/theme/name", "Dark"};
|
QStringSetting themeName{"/appearance/theme/name", "Dark"};
|
||||||
|
QStringSetting lightSystemThemeName{"/appearance/theme/lightSystem",
|
||||||
|
"Light"};
|
||||||
|
QStringSetting darkSystemThemeName{"/appearance/theme/darkSystem", "Dark"};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool isLight_ = false;
|
bool isLight_ = false;
|
||||||
|
|
|
@ -122,16 +122,49 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
||||||
|
|
||||||
layout.addTitle("Interface");
|
layout.addTitle("Interface");
|
||||||
|
|
||||||
layout.addDropdown<QString>(
|
{
|
||||||
"Theme", getIApp()->getThemes()->availableThemes(),
|
auto *themes = getIApp()->getThemes();
|
||||||
getIApp()->getThemes()->themeName,
|
auto available = themes->availableThemes();
|
||||||
[](const auto *combo, const auto &themeKey) {
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
|
||||||
return combo->findData(themeKey, Qt::UserRole);
|
available.emplace_back("System", "System");
|
||||||
},
|
#endif
|
||||||
[](const auto &args) {
|
|
||||||
return args.combobox->itemData(args.index, Qt::UserRole).toString();
|
auto addThemeDropdown = [&](auto name, auto &setting,
|
||||||
},
|
const auto &options,
|
||||||
{}, Theme::fallbackTheme.name);
|
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>(
|
layout.addDropdown<QString>(
|
||||||
"Font", {"Segoe UI", "Arial", "Choose..."},
|
"Font", {"Segoe UI", "Arial", "Choose..."},
|
||||||
|
|
|
@ -306,6 +306,15 @@ public:
|
||||||
return combo;
|
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);
|
DescriptionLabel *addDescription(const QString &text);
|
||||||
|
|
||||||
void addSeperator();
|
void addSeperator();
|
||||||
|
|
Loading…
Reference in a new issue