added settings
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
#ifndef BOOLSETTING_H
|
||||
#define BOOLSETTING_H
|
||||
|
||||
#include "settings/setting.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino {
|
||||
namespace settings {
|
||||
class BoolSetting : public Setting
|
||||
{
|
||||
public:
|
||||
BoolSetting(const QString &name, bool defaultValue)
|
||||
: Setting(name)
|
||||
, value(defaultValue)
|
||||
, defaultValue(defaultValue)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
get() const
|
||||
{
|
||||
return this->value;
|
||||
}
|
||||
|
||||
void
|
||||
set(bool value)
|
||||
{
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
void
|
||||
save(const QSettings &settings) override
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
load(const QSettings &settings) override
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
bool value;
|
||||
bool defaultValue;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // BOOLSETTING_H
|
||||
@@ -0,0 +1,56 @@
|
||||
#ifndef REALSETTING_H
|
||||
#define REALSETTING_H
|
||||
|
||||
#include "settings/setting.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino {
|
||||
namespace settings {
|
||||
|
||||
class FloatSetting : public Setting
|
||||
{
|
||||
public:
|
||||
FloatSetting(const QString &name, qreal defaultValue,
|
||||
qreal minValue = std::numeric_limits<qreal>::min(),
|
||||
qreal maxValue = std::numeric_limits<qreal>::max())
|
||||
: Setting(name)
|
||||
, value(defaultValue)
|
||||
, defaultValue(defaultValue)
|
||||
, minValue(minValue)
|
||||
, maxValue(maxValue)
|
||||
{
|
||||
}
|
||||
|
||||
qreal
|
||||
get() const
|
||||
{
|
||||
return this->value;
|
||||
}
|
||||
|
||||
qreal
|
||||
set(qreal value)
|
||||
{
|
||||
return (this->value = std::max(std::min(value, maxValue), minValue));
|
||||
}
|
||||
|
||||
void
|
||||
save(const QSettings &settings) override
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
load(const QSettings &settings) override
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
qreal value;
|
||||
qreal defaultValue;
|
||||
qreal minValue;
|
||||
qreal maxValue;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // REALSETTING_H
|
||||
@@ -0,0 +1,49 @@
|
||||
#ifndef INTSETTING_H
|
||||
#define INTSETTING_H
|
||||
|
||||
#include "settings/setting.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino {
|
||||
namespace settings {
|
||||
class BoolSetting : public Setting
|
||||
{
|
||||
public:
|
||||
BoolSetting(const QString &name, int defaultValue)
|
||||
: Setting(name)
|
||||
, value(defaultValue)
|
||||
, defaultValue(defaultValue)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
get() const
|
||||
{
|
||||
return this->value;
|
||||
}
|
||||
|
||||
int
|
||||
set(int value)
|
||||
{
|
||||
return (this->value = value);
|
||||
}
|
||||
|
||||
void
|
||||
save(const QSettings &settings) override
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
load(const QSettings &settings) override
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
int value;
|
||||
int defaultValue;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // INTSETTING_H
|
||||
@@ -1,32 +0,0 @@
|
||||
#ifndef REALSETTING_H
|
||||
#define REALSETTING_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino {
|
||||
namespace settings {
|
||||
|
||||
class RealSetting : public Setting
|
||||
{
|
||||
public:
|
||||
RealSetting(const QString &name, qreal defaultValue,
|
||||
qreal minValue = std::numeric_limits<qreal>::min(),
|
||||
qreal maxValue = std::numeric_limits<qreal>::max())
|
||||
: Setting(name)
|
||||
, value(defaultValue)
|
||||
, defaultValue(defaultValue)
|
||||
, minValue(minValue)
|
||||
, maxValue(maxValue)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
qreal value;
|
||||
qreal defaultValue;
|
||||
qreal minValue;
|
||||
qreal maxValue;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // REALSETTING_H
|
||||
+6
-2
@@ -1,6 +1,7 @@
|
||||
#ifndef SETTING_H
|
||||
#define SETTING_H
|
||||
|
||||
#include <QSettings>
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino {
|
||||
@@ -14,17 +15,20 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
virtual void save(const QSettings &settings) = 0;
|
||||
virtual void load(const QSettings &settings) = 0;
|
||||
|
||||
protected:
|
||||
const QString &
|
||||
getName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
virtual QString toString() = 0;
|
||||
|
||||
private:
|
||||
QString name;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SETTING_H
|
||||
|
||||
+52
-1
@@ -1,12 +1,63 @@
|
||||
#include "settings/settings.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
|
||||
namespace chatterino {
|
||||
namespace settings {
|
||||
|
||||
StringSetting Settings::theme("", "dark");
|
||||
StringSetting Settings::user("", "");
|
||||
FloatSetting Settings::emoteScale("", 1.0);
|
||||
BoolSetting Settings::scaleEmotesByLineHeight("", false);
|
||||
BoolSetting Settings::showTimestamps("", true);
|
||||
BoolSetting Settings::showTimestampSeconds("", false);
|
||||
BoolSetting Settings::allowDouplicateMessages("", true);
|
||||
BoolSetting Settings::linksDoubleClickOnly("", false);
|
||||
BoolSetting Settings::hideEmptyInput("", false);
|
||||
BoolSetting Settings::showMessageLength("", false);
|
||||
BoolSetting Settings::seperateMessages("", false);
|
||||
BoolSetting Settings::mentionUsersWithAt("", false);
|
||||
BoolSetting Settings::allowCommandsAtEnd("", false);
|
||||
BoolSetting Settings::enableHighlights("", true);
|
||||
BoolSetting Settings::enableHighlightSound("", true);
|
||||
BoolSetting Settings::enableHighlightTaskbar("", true);
|
||||
BoolSetting Settings::customHighlightSound("", false);
|
||||
BoolSetting Settings::enableTwitchEmotes("", true);
|
||||
BoolSetting Settings::enableBttvEmotes("", true);
|
||||
BoolSetting Settings::enableFFzEmotes("", true);
|
||||
BoolSetting Settings::enableEmojis("", true);
|
||||
BoolSetting Settings::enableGifAnimations("", true);
|
||||
BoolSetting Settings::enableGifs("", true);
|
||||
BoolSetting Settings::inlineWhispers("", true);
|
||||
BoolSetting Settings::windowTopMost("", true);
|
||||
|
||||
QSettings Settings::settings(
|
||||
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation),
|
||||
QSettings::IniFormat);
|
||||
|
||||
std::vector<Setting *> Settings::settingsItems;
|
||||
|
||||
bool Settings::portable(false);
|
||||
|
||||
messages::Word::Type Settings::wordTypeMask = messages::Word::Default;
|
||||
|
||||
Settings::Settings()
|
||||
int Settings::_ = Settings::_init();
|
||||
|
||||
void
|
||||
Settings::save()
|
||||
{
|
||||
for (Setting *item : settingsItems) {
|
||||
item->save(settings);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Settings::load()
|
||||
{
|
||||
for (Setting *item : settingsItems) {
|
||||
item->load(settings);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
|
||||
+217
-13
@@ -2,6 +2,12 @@
|
||||
#define APPSETTINGS_H
|
||||
|
||||
#include "messages/word.h"
|
||||
#include "settings/boolsetting.h"
|
||||
#include "settings/floatsetting.h"
|
||||
#include "settings/setting.h"
|
||||
#include "settings/stringsetting.h"
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
namespace chatterino {
|
||||
namespace settings {
|
||||
@@ -17,27 +23,225 @@ public:
|
||||
|
||||
static bool isIgnoredEmote(const QString &emote);
|
||||
|
||||
static qreal
|
||||
getEmoteScale()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static qreal
|
||||
getBadgeScale()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
static void load();
|
||||
static void save();
|
||||
|
||||
static bool
|
||||
getScaleEmotesByLineHeight()
|
||||
getPortable()
|
||||
{
|
||||
return false;
|
||||
return portable;
|
||||
}
|
||||
|
||||
static void
|
||||
setPortable(bool value)
|
||||
{
|
||||
portable = value;
|
||||
}
|
||||
|
||||
private:
|
||||
Settings();
|
||||
|
||||
static int _;
|
||||
static int
|
||||
_init()
|
||||
{
|
||||
settingsItems.reserve(25);
|
||||
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(&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);
|
||||
}
|
||||
|
||||
static QSettings settings;
|
||||
static std::vector<Setting *> settingsItems;
|
||||
|
||||
template <class T>
|
||||
static T
|
||||
addSetting(T setting)
|
||||
{
|
||||
settingsItems.push_back(setting);
|
||||
return setting;
|
||||
}
|
||||
|
||||
static bool portable;
|
||||
|
||||
static messages::Word::Type wordTypeMask;
|
||||
|
||||
// settings
|
||||
public:
|
||||
static StringSetting
|
||||
getTheme()
|
||||
{
|
||||
return Settings::theme;
|
||||
}
|
||||
static StringSetting
|
||||
getUser()
|
||||
{
|
||||
return Settings::user;
|
||||
}
|
||||
static FloatSetting
|
||||
getEmoteScale()
|
||||
{
|
||||
return Settings::emoteScale;
|
||||
}
|
||||
static BoolSetting
|
||||
getScaleEmotesByLineHeight()
|
||||
{
|
||||
return Settings::scaleEmotesByLineHeight;
|
||||
}
|
||||
static BoolSetting
|
||||
getShowTimestamps()
|
||||
{
|
||||
return Settings::showTimestamps;
|
||||
}
|
||||
static BoolSetting
|
||||
getShowTimestampSeconds()
|
||||
{
|
||||
return Settings::showTimestampSeconds;
|
||||
}
|
||||
static BoolSetting
|
||||
getAllowDouplicateMessages()
|
||||
{
|
||||
return Settings::allowDouplicateMessages;
|
||||
}
|
||||
static BoolSetting
|
||||
getLinksDoubleClickOnly()
|
||||
{
|
||||
return Settings::linksDoubleClickOnly;
|
||||
}
|
||||
static BoolSetting
|
||||
getHideEmptyInput()
|
||||
{
|
||||
return Settings::hideEmptyInput;
|
||||
}
|
||||
static BoolSetting
|
||||
getShowMessageLength()
|
||||
{
|
||||
return Settings::showMessageLength;
|
||||
}
|
||||
static BoolSetting
|
||||
getSeperateMessages()
|
||||
{
|
||||
return Settings::seperateMessages;
|
||||
}
|
||||
static BoolSetting
|
||||
getMentionUsersWithAt()
|
||||
{
|
||||
return Settings::mentionUsersWithAt;
|
||||
}
|
||||
static BoolSetting
|
||||
getAllowCommandsAtEnd()
|
||||
{
|
||||
return Settings::allowCommandsAtEnd;
|
||||
}
|
||||
static BoolSetting
|
||||
getEnableHighlights()
|
||||
{
|
||||
return Settings::enableHighlights;
|
||||
}
|
||||
static BoolSetting
|
||||
getEnableHighlightSound()
|
||||
{
|
||||
return Settings::enableHighlightSound;
|
||||
}
|
||||
static BoolSetting
|
||||
getEnableHighlightTaskbar()
|
||||
{
|
||||
return Settings::enableHighlightTaskbar;
|
||||
}
|
||||
static BoolSetting
|
||||
getCustomHighlightSound()
|
||||
{
|
||||
return Settings::customHighlightSound;
|
||||
}
|
||||
static BoolSetting
|
||||
getEnableTwitchEmotes()
|
||||
{
|
||||
return Settings::enableTwitchEmotes;
|
||||
}
|
||||
static BoolSetting
|
||||
getEnableBttvEmotes()
|
||||
{
|
||||
return Settings::enableBttvEmotes;
|
||||
}
|
||||
static BoolSetting
|
||||
getEnableFFzEmotes()
|
||||
{
|
||||
return Settings::enableFFzEmotes;
|
||||
}
|
||||
static BoolSetting
|
||||
getEnableEmojis()
|
||||
{
|
||||
return Settings::enableEmojis;
|
||||
}
|
||||
static BoolSetting
|
||||
getEnableGifAnimations()
|
||||
{
|
||||
return Settings::enableGifAnimations;
|
||||
}
|
||||
static BoolSetting
|
||||
getEnableGifs()
|
||||
{
|
||||
return Settings::enableGifs;
|
||||
}
|
||||
static BoolSetting
|
||||
getInlineWhispers()
|
||||
{
|
||||
return Settings::inlineWhispers;
|
||||
}
|
||||
static BoolSetting
|
||||
getWindowTopMost()
|
||||
{
|
||||
return Settings::windowTopMost;
|
||||
}
|
||||
|
||||
private:
|
||||
static StringSetting theme;
|
||||
static StringSetting user;
|
||||
static FloatSetting emoteScale;
|
||||
static BoolSetting scaleEmotesByLineHeight;
|
||||
static BoolSetting showTimestamps;
|
||||
static BoolSetting showTimestampSeconds;
|
||||
static BoolSetting allowDouplicateMessages;
|
||||
static BoolSetting linksDoubleClickOnly;
|
||||
static BoolSetting hideEmptyInput;
|
||||
static BoolSetting showMessageLength;
|
||||
static BoolSetting seperateMessages;
|
||||
static BoolSetting mentionUsersWithAt;
|
||||
static BoolSetting allowCommandsAtEnd;
|
||||
static BoolSetting enableHighlights;
|
||||
static BoolSetting enableHighlightSound;
|
||||
static BoolSetting enableHighlightTaskbar;
|
||||
static BoolSetting customHighlightSound;
|
||||
static BoolSetting enableTwitchEmotes;
|
||||
static BoolSetting enableBttvEmotes;
|
||||
static BoolSetting enableFFzEmotes;
|
||||
static BoolSetting enableEmojis;
|
||||
static BoolSetting enableGifAnimations;
|
||||
static BoolSetting enableGifs;
|
||||
static BoolSetting inlineWhispers;
|
||||
static BoolSetting windowTopMost;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#ifndef STRINGSETTING_H
|
||||
#define STRINGSETTING_H
|
||||
|
||||
#include "settings/setting.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino {
|
||||
namespace settings {
|
||||
|
||||
class StringSetting : public Setting
|
||||
{
|
||||
public:
|
||||
StringSetting(const QString &name, const QString &defaultValue)
|
||||
: Setting(name)
|
||||
, value(defaultValue)
|
||||
, defaultValue(defaultValue)
|
||||
{
|
||||
}
|
||||
|
||||
const QString &
|
||||
get() const
|
||||
{
|
||||
return this->value;
|
||||
}
|
||||
|
||||
const QString &
|
||||
set(const QString &value)
|
||||
{
|
||||
return (this->value = value);
|
||||
}
|
||||
|
||||
void
|
||||
save(const QSettings &settings) override
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
load(const QSettings &settings) override
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
QString value;
|
||||
QString defaultValue;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // STRINGSETTING_H
|
||||
Reference in New Issue
Block a user