1 #pragma once 2 3 #include <QString> 4 #include <pajlada/settings.hpp> 5 6 namespace chatterino { 7 8 void _registerSetting(std::weak_ptr<pajlada::Settings::SettingData> setting); 9 10 template <typename Type> 11 class ChatterinoSetting : public pajlada::Settings::Setting<Type> 12 { 13 public: ChatterinoSetting(const std::string & path)14 ChatterinoSetting(const std::string &path) 15 : pajlada::Settings::Setting<Type>(path) 16 { 17 _registerSetting(this->getData()); 18 } 19 ChatterinoSetting(const std::string & path,const Type & defaultValue)20 ChatterinoSetting(const std::string &path, const Type &defaultValue) 21 : pajlada::Settings::Setting<Type>(path, defaultValue) 22 { 23 _registerSetting(this->getData()); 24 } 25 26 template <typename T2> operator =(const T2 & newValue)27 ChatterinoSetting &operator=(const T2 &newValue) 28 { 29 this->setValue(newValue); 30 31 return *this; 32 } 33 operator =(Type && newValue)34 ChatterinoSetting &operator=(Type &&newValue) noexcept 35 { 36 pajlada::Settings::Setting<Type>::operator=(newValue); 37 38 return *this; 39 } 40 41 using pajlada::Settings::Setting<Type>::operator==; 42 using pajlada::Settings::Setting<Type>::operator!=; 43 44 using pajlada::Settings::Setting<Type>::operator Type; 45 }; 46 47 using BoolSetting = ChatterinoSetting<bool>; 48 using FloatSetting = ChatterinoSetting<float>; 49 using DoubleSetting = ChatterinoSetting<double>; 50 using IntSetting = ChatterinoSetting<int>; 51 using StringSetting = ChatterinoSetting<std::string>; 52 using QStringSetting = ChatterinoSetting<QString>; 53 54 template <typename Enum> 55 class EnumSetting 56 : public ChatterinoSetting<typename std::underlying_type<Enum>::type> 57 { 58 using Underlying = typename std::underlying_type<Enum>::type; 59 60 public: 61 using ChatterinoSetting<Underlying>::ChatterinoSetting; 62 EnumSetting(const std::string & path,const Enum & defaultValue)63 EnumSetting(const std::string &path, const Enum &defaultValue) 64 : ChatterinoSetting<Underlying>(path, Underlying(defaultValue)) 65 { 66 _registerSetting(this->getData()); 67 } 68 69 template <typename T2> operator =(Enum newValue)70 EnumSetting<Enum> &operator=(Enum newValue) 71 { 72 this->setValue(Underlying(newValue)); 73 74 return *this; 75 } 76 operator Enum()77 operator Enum() 78 { 79 return Enum(this->getValue()); 80 } 81 getEnum()82 Enum getEnum() 83 { 84 return Enum(this->getValue()); 85 } 86 }; 87 88 } // namespace chatterino 89