Update to latest settings library version
This commit is contained in:
+32
-26
@@ -32,37 +32,43 @@ Fonts::Fonts()
|
||||
|
||||
void Fonts::initialize(Settings &, Paths &)
|
||||
{
|
||||
this->chatFontFamily.connect([this](const std::string &, auto) {
|
||||
assertInGuiThread();
|
||||
this->chatFontFamily.connect(
|
||||
[this]() {
|
||||
assertInGuiThread();
|
||||
|
||||
for (auto &map : this->fontsByType_)
|
||||
{
|
||||
map.clear();
|
||||
}
|
||||
this->fontChanged.invoke();
|
||||
});
|
||||
for (auto &map : this->fontsByType_)
|
||||
{
|
||||
map.clear();
|
||||
}
|
||||
this->fontChanged.invoke();
|
||||
},
|
||||
false);
|
||||
|
||||
this->chatFontSize.connect([this](const int &, auto) {
|
||||
assertInGuiThread();
|
||||
this->chatFontSize.connect(
|
||||
[this]() {
|
||||
assertInGuiThread();
|
||||
|
||||
for (auto &map : this->fontsByType_)
|
||||
{
|
||||
map.clear();
|
||||
}
|
||||
this->fontChanged.invoke();
|
||||
});
|
||||
for (auto &map : this->fontsByType_)
|
||||
{
|
||||
map.clear();
|
||||
}
|
||||
this->fontChanged.invoke();
|
||||
},
|
||||
false);
|
||||
|
||||
getSettings()->boldScale.connect([this](const int &, auto) {
|
||||
assertInGuiThread();
|
||||
getSettings()->boldScale.connect(
|
||||
[this]() {
|
||||
assertInGuiThread();
|
||||
|
||||
getApp()->windows->incGeneration();
|
||||
getApp()->windows->incGeneration();
|
||||
|
||||
for (auto &map : this->fontsByType_)
|
||||
{
|
||||
map.clear();
|
||||
}
|
||||
this->fontChanged.invoke();
|
||||
});
|
||||
for (auto &map : this->fontsByType_)
|
||||
{
|
||||
map.clear();
|
||||
}
|
||||
this->fontChanged.invoke();
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
QFont Fonts::getFont(FontStyle type, float scale)
|
||||
@@ -118,7 +124,7 @@ Fonts::FontData Fonts::createFontData(FontStyle type, float scale)
|
||||
1, false, QFont::Weight(getSettings()->boldScale.getValue())};
|
||||
auto data = sizeScale[type];
|
||||
return FontData(
|
||||
QFont(QString::fromStdString(this->chatFontFamily.getValue()),
|
||||
QFont(this->chatFontFamily.getValue(),
|
||||
int(this->chatFontSize.getValue() * data.scale * scale),
|
||||
data.weight, data.italic));
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/ChatterinoSetting.hpp"
|
||||
#include "common/Singleton.hpp"
|
||||
|
||||
#include <QFont>
|
||||
#include <QFontDatabase>
|
||||
#include <QFontMetrics>
|
||||
#include <array>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <pajlada/settings/setting.hpp>
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace chatterino {
|
||||
@@ -49,8 +50,8 @@ public:
|
||||
QFont getFont(FontStyle type, float scale);
|
||||
QFontMetrics getFontMetrics(FontStyle type, float scale);
|
||||
|
||||
pajlada::Settings::Setting<std::string> chatFontFamily;
|
||||
pajlada::Settings::Setting<int> chatFontSize;
|
||||
QStringSetting chatFontFamily;
|
||||
IntSetting chatFontSize;
|
||||
|
||||
pajlada::Signals::NoArgSignal fontChanged;
|
||||
|
||||
|
||||
+29
-11
@@ -8,12 +8,12 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
std::vector<std::weak_ptr<pajlada::Settings::ISettingData>> _settings;
|
||||
std::vector<std::weak_ptr<pajlada::Settings::SettingData>> _settings;
|
||||
|
||||
Settings *Settings::instance = nullptr;
|
||||
|
||||
void _actuallyRegisterSetting(
|
||||
std::weak_ptr<pajlada::Settings::ISettingData> setting)
|
||||
std::weak_ptr<pajlada::Settings::SettingData> setting)
|
||||
{
|
||||
_settings.push_back(setting);
|
||||
}
|
||||
@@ -24,7 +24,15 @@ Settings::Settings(Paths &paths)
|
||||
|
||||
QString settingsPath = paths.settingsDirectory + "/settings.json";
|
||||
|
||||
pajlada::Settings::SettingManager::gLoad(qPrintable(settingsPath));
|
||||
// get global instance of the settings library
|
||||
auto settingsInstance = pajlada::Settings::SettingManager::getInstance();
|
||||
|
||||
settingsInstance->load(qPrintable(settingsPath));
|
||||
|
||||
settingsInstance->setBackupEnabled(true);
|
||||
settingsInstance->setBackupSlots(9);
|
||||
settingsInstance->saveMethod =
|
||||
pajlada::Settings::SettingManager::SaveMethod::SaveOnExit;
|
||||
}
|
||||
|
||||
Settings &Settings::getInstance()
|
||||
@@ -46,13 +54,20 @@ void Settings::saveSnapshot()
|
||||
}
|
||||
|
||||
rapidjson::Value key(setting->getPath().c_str(), a);
|
||||
rapidjson::Value val = setting->marshalInto(*d);
|
||||
auto curVal = setting->unmarshalJSON();
|
||||
if (curVal == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
rapidjson::Value val;
|
||||
val.CopyFrom(*curVal, a);
|
||||
d->AddMember(key.Move(), val.Move(), a);
|
||||
}
|
||||
|
||||
this->snapshot_.reset(d);
|
||||
// log("Snapshot state: {}", rj::stringify(*d));
|
||||
|
||||
log("hehe: {}", pajlada::Settings::SettingManager::stringify(*d));
|
||||
this->snapshot_.reset(d);
|
||||
}
|
||||
|
||||
void Settings::restoreSnapshot()
|
||||
@@ -62,26 +77,29 @@ void Settings::restoreSnapshot()
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &snapshotObject = this->snapshot_->GetObject();
|
||||
const auto &snapshot = *(this->snapshot_.get());
|
||||
|
||||
if (!snapshot.IsObject())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto &weakSetting : _settings)
|
||||
{
|
||||
auto setting = weakSetting.lock();
|
||||
if (!setting)
|
||||
{
|
||||
log("Error stage 1 of loading");
|
||||
continue;
|
||||
}
|
||||
|
||||
const char *path = setting->getPath().c_str();
|
||||
|
||||
if (!snapshotObject.HasMember(path))
|
||||
if (!snapshot.HasMember(path))
|
||||
{
|
||||
log("Error stage 2 of loading");
|
||||
continue;
|
||||
}
|
||||
|
||||
setting->unmarshalValue(snapshotObject[path]);
|
||||
setting->marshalJSON(snapshot[path]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace chatterino {
|
||||
|
||||
void _actuallyRegisterSetting(
|
||||
std::weak_ptr<pajlada::Settings::ISettingData> setting);
|
||||
std::weak_ptr<pajlada::Settings::SettingData> setting);
|
||||
|
||||
class Settings
|
||||
{
|
||||
|
||||
@@ -39,8 +39,6 @@ namespace detail {
|
||||
} // namespace detail
|
||||
|
||||
Theme::Theme()
|
||||
: themeName("/appearance/theme/name", "Dark")
|
||||
, themeHue("/appearance/theme/hue", 0.0)
|
||||
{
|
||||
this->update();
|
||||
|
||||
|
||||
@@ -130,8 +130,8 @@ public:
|
||||
|
||||
pajlada::Signals::NoArgSignal updated;
|
||||
|
||||
pajlada::Settings::Setting<QString> themeName;
|
||||
pajlada::Settings::Setting<double> themeHue;
|
||||
QStringSetting themeName{"/appearance/theme/name", "Dark"};
|
||||
DoubleSetting themeHue{"/appearance/theme/hue", 0.0};
|
||||
|
||||
private:
|
||||
void actuallyUpdate(double hue, double multiplier);
|
||||
|
||||
Reference in New Issue
Block a user