mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
each Setting is now responsible for adding themselves to the settings list
This commit is contained in:
parent
5429e62e73
commit
1e6e395623
3 changed files with 55 additions and 66 deletions
|
@ -11,18 +11,34 @@ namespace settings {
|
||||||
class BaseSetting
|
class BaseSetting
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
BaseSetting(const QString &_name)
|
||||||
|
: name(_name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
virtual void save(QSettings &settings) = 0;
|
virtual void save(QSettings &settings) = 0;
|
||||||
virtual void load(const QSettings &settings) = 0;
|
virtual void load(const QSettings &settings) = 0;
|
||||||
|
|
||||||
|
const QString &
|
||||||
|
getName() const
|
||||||
|
{
|
||||||
|
return this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString name;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class Setting : public BaseSetting
|
class Setting : public BaseSetting
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Setting(const QString &_name, const T &defaultValue)
|
Setting(std::vector<std::reference_wrapper<BaseSetting>> &settingItems,
|
||||||
: name(_name)
|
const QString &_name, const T &defaultValue)
|
||||||
|
: BaseSetting(_name)
|
||||||
, value(defaultValue)
|
, value(defaultValue)
|
||||||
{
|
{
|
||||||
|
settingItems.push_back(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
const T &
|
const T &
|
||||||
|
@ -53,21 +69,13 @@ public:
|
||||||
QVariant newValue = settings.value(this->getName(), QVariant());
|
QVariant newValue = settings.value(this->getName(), QVariant());
|
||||||
if (newValue.isValid()) {
|
if (newValue.isValid()) {
|
||||||
assert(newValue.canConvert<T>());
|
assert(newValue.canConvert<T>());
|
||||||
this->value = newValue.value<T>();
|
this->set(newValue.value<T>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::signals2::signal<void(const T &newValue)> valueChanged;
|
boost::signals2::signal<void(const T &newValue)> valueChanged;
|
||||||
|
|
||||||
protected:
|
|
||||||
const QString &
|
|
||||||
getName() const
|
|
||||||
{
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString name;
|
|
||||||
T value;
|
T value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "settings/settings.h"
|
#include "settings/settings.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
|
||||||
|
@ -14,62 +15,38 @@ Settings::Settings()
|
||||||
QSettings::IniFormat)
|
QSettings::IniFormat)
|
||||||
, portable(false)
|
, portable(false)
|
||||||
, wordTypeMask(messages::Word::Default)
|
, wordTypeMask(messages::Word::Default)
|
||||||
, theme("", "dark")
|
, theme(this->settingsItems, "theme", "dark")
|
||||||
, user("", "")
|
, user(this->settingsItems, "userNotSureWhatThisMaybeOAuthOrSomething", "")
|
||||||
, emoteScale("", 1.0)
|
, emoteScale(this->settingsItems, "emoteScale", 1.0)
|
||||||
, scaleEmotesByLineHeight("", false)
|
, scaleEmotesByLineHeight(this->settingsItems, "scaleEmotesByLineHeight",
|
||||||
, showTimestamps("", true)
|
false)
|
||||||
, showTimestampSeconds("", false)
|
, showTimestamps(this->settingsItems, "showTimestamps", true)
|
||||||
, showLastMessageIndicator("", false)
|
, showTimestampSeconds(this->settingsItems, "showTimestampSeconds", false)
|
||||||
, allowDouplicateMessages("", true)
|
, showLastMessageIndicator(this->settingsItems, "showLastMessageIndicator",
|
||||||
, linksDoubleClickOnly("", false)
|
false)
|
||||||
, hideEmptyInput("", false)
|
, allowDouplicateMessages(this->settingsItems, "allowDouplicateMessages",
|
||||||
, showMessageLength("", false)
|
true)
|
||||||
, seperateMessages("", false)
|
, linksDoubleClickOnly(this->settingsItems, "linksDoubleClickOnly", false)
|
||||||
, mentionUsersWithAt("", false)
|
, hideEmptyInput(this->settingsItems, "hideEmptyInput", false)
|
||||||
, allowCommandsAtEnd("", false)
|
, showMessageLength(this->settingsItems, "showMessageLength", false)
|
||||||
, enableHighlights("", true)
|
, seperateMessages(this->settingsItems, "seperateMessages", false)
|
||||||
, enableHighlightSound("", true)
|
, mentionUsersWithAt(this->settingsItems, "mentionUsersWithAt", false)
|
||||||
, enableHighlightTaskbar("", true)
|
, allowCommandsAtEnd(this->settingsItems, "allowCommandsAtEnd", false)
|
||||||
, customHighlightSound("", false)
|
, enableHighlights(this->settingsItems, "enableHighlights", true)
|
||||||
, enableTwitchEmotes("", true)
|
, enableHighlightSound(this->settingsItems, "enableHighlightSound", true)
|
||||||
, enableBttvEmotes("", true)
|
, enableHighlightTaskbar(this->settingsItems, "enableHighlightTaskbar",
|
||||||
, enableFfzEmotes("", true)
|
true)
|
||||||
, enableEmojis("", true)
|
, customHighlightSound(this->settingsItems, "customHighlightSound", false)
|
||||||
, enableGifAnimations("", true)
|
, enableTwitchEmotes(this->settingsItems, "enableTwitchEmotes", true)
|
||||||
, enableGifs("", true)
|
, enableBttvEmotes(this->settingsItems, "enableBttvEmotes", true)
|
||||||
, inlineWhispers("", true)
|
, enableFfzEmotes(this->settingsItems, "enableFfzEmotes", true)
|
||||||
, windowTopMost("", true)
|
, enableEmojis(this->settingsItems, "enableEmojis", true)
|
||||||
, hideTabX("", false)
|
, enableGifAnimations(this->settingsItems, "enableGifAnimations", true)
|
||||||
|
, enableGifs(this->settingsItems, "enableGifs", true)
|
||||||
|
, inlineWhispers(this->settingsItems, "inlineWhispers", true)
|
||||||
|
, windowTopMost(this->settingsItems, "windowTopMost", true)
|
||||||
|
, hideTabX(this->settingsItems, "hideTabX", false)
|
||||||
{
|
{
|
||||||
settingsItems.push_back(theme);
|
|
||||||
settingsItems.push_back(user);
|
|
||||||
settingsItems.push_back(emoteScale);
|
|
||||||
settingsItems.push_back(scaleEmotesByLineHeight);
|
|
||||||
settingsItems.push_back(showTimestamps);
|
|
||||||
settingsItems.push_back(showTimestampSeconds);
|
|
||||||
settingsItems.push_back(showLastMessageIndicator);
|
|
||||||
settingsItems.push_back(allowDouplicateMessages);
|
|
||||||
settingsItems.push_back(linksDoubleClickOnly);
|
|
||||||
settingsItems.push_back(hideEmptyInput);
|
|
||||||
settingsItems.push_back(showMessageLength);
|
|
||||||
settingsItems.push_back(seperateMessages);
|
|
||||||
settingsItems.push_back(mentionUsersWithAt);
|
|
||||||
settingsItems.push_back(allowCommandsAtEnd);
|
|
||||||
settingsItems.push_back(enableHighlights);
|
|
||||||
settingsItems.push_back(enableHighlightSound);
|
|
||||||
settingsItems.push_back(enableHighlightTaskbar);
|
|
||||||
settingsItems.push_back(customHighlightSound);
|
|
||||||
settingsItems.push_back(enableTwitchEmotes);
|
|
||||||
settingsItems.push_back(enableBttvEmotes);
|
|
||||||
settingsItems.push_back(enableFfzEmotes);
|
|
||||||
settingsItems.push_back(enableEmojis);
|
|
||||||
settingsItems.push_back(enableGifAnimations);
|
|
||||||
settingsItems.push_back(enableGifs);
|
|
||||||
settingsItems.push_back(inlineWhispers);
|
|
||||||
settingsItems.push_back(windowTopMost);
|
|
||||||
settingsItems.push_back(hideTabX);
|
|
||||||
|
|
||||||
this->showTimestamps.valueChanged.connect(
|
this->showTimestamps.valueChanged.connect(
|
||||||
[this](const auto &) { this->updateWordTypeMask(); });
|
[this](const auto &) { this->updateWordTypeMask(); });
|
||||||
this->showTimestampSeconds.valueChanged.connect(
|
this->showTimestampSeconds.valueChanged.connect(
|
||||||
|
@ -96,6 +73,7 @@ void
|
||||||
Settings::load()
|
Settings::load()
|
||||||
{
|
{
|
||||||
for (auto &item : settingsItems) {
|
for (auto &item : settingsItems) {
|
||||||
|
qDebug() << "Loading settings for " << item.get().getName();
|
||||||
item.get().load(settings);
|
item.get().load(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,6 +231,9 @@ SettingsDialog::createCheckbox(const QString &title,
|
||||||
{
|
{
|
||||||
auto checkbox = new QCheckBox(title);
|
auto checkbox = new QCheckBox(title);
|
||||||
|
|
||||||
|
// Set checkbox initial state
|
||||||
|
checkbox->setChecked(setting.get());
|
||||||
|
|
||||||
QObject::connect(checkbox, &QCheckBox::toggled, this,
|
QObject::connect(checkbox, &QCheckBox::toggled, this,
|
||||||
[&setting, this](bool state) { setting.set(state); });
|
[&setting, this](bool state) { setting.set(state); });
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue