Add the ability to select custom themes in the settings dialog (#4570)
Themes are loaded from the Themes directory (under the Chatterino directory, so %APPDATA%/Chatterino2/Themes). Themes are json files (see the built in themes as an example). After importing a theme, you must restart Chatterino for it to show up in the settings
This commit is contained in:
@@ -114,8 +114,18 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
||||
auto &s = *getSettings();
|
||||
|
||||
layout.addTitle("Interface");
|
||||
layout.addDropdown("Theme", {"White", "Light", "Dark", "Black"},
|
||||
getApp()->themes->themeName);
|
||||
|
||||
layout.addDropdown<QString>(
|
||||
"Theme", getApp()->themes->availableThemes(),
|
||||
getApp()->themes->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);
|
||||
|
||||
layout.addDropdown<QString>(
|
||||
"Font", {"Segoe UI", "Arial", "Choose..."},
|
||||
getApp()->fonts->chatFontFamily,
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <QSpinBox>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <utility>
|
||||
|
||||
class QScrollArea;
|
||||
|
||||
namespace chatterino {
|
||||
@@ -192,6 +194,59 @@ public:
|
||||
|
||||
return combo;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ComboBox *addDropdown(
|
||||
const QString &text,
|
||||
const std::vector<std::pair<QString, QVariant>> &items,
|
||||
pajlada::Settings::Setting<T> &setting,
|
||||
std::function<boost::variant<int, QString>(ComboBox *, T)> getValue,
|
||||
std::function<T(DropdownArgs)> setValue, QString toolTipText = {},
|
||||
const QString &defaultValueText = {})
|
||||
{
|
||||
auto *combo = this->addDropdown(text, {}, std::move(toolTipText));
|
||||
|
||||
for (const auto &[text, userData] : items)
|
||||
{
|
||||
combo->addItem(text, userData);
|
||||
}
|
||||
|
||||
if (!defaultValueText.isEmpty())
|
||||
{
|
||||
combo->setCurrentText(defaultValueText);
|
||||
}
|
||||
|
||||
setting.connect(
|
||||
[getValue = std::move(getValue), combo](const T &value, auto) {
|
||||
auto var = getValue(combo, value);
|
||||
if (var.which() == 0)
|
||||
{
|
||||
const auto index = boost::get<int>(var);
|
||||
if (index >= 0)
|
||||
{
|
||||
combo->setCurrentIndex(index);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
combo->setCurrentText(boost::get<QString>(var));
|
||||
combo->setEditText(boost::get<QString>(var));
|
||||
}
|
||||
},
|
||||
this->managedConnections_);
|
||||
|
||||
QObject::connect(
|
||||
combo, QOverload<const int>::of(&QComboBox::currentIndexChanged),
|
||||
[combo, &setting,
|
||||
setValue = std::move(setValue)](const int newIndex) {
|
||||
setting = setValue(DropdownArgs{combo->itemText(newIndex),
|
||||
combo->currentIndex(), combo});
|
||||
getApp()->windows->forceLayoutChannelViews();
|
||||
});
|
||||
|
||||
return combo;
|
||||
}
|
||||
|
||||
DescriptionLabel *addDescription(const QString &text);
|
||||
|
||||
void addSeperator();
|
||||
|
||||
Reference in New Issue
Block a user