Add simple fontChanged signal

Delete copy/move constructor of FontManager :kkona:
Fix places that were using the copy constructor of the FontManager
This commit is contained in:
Rasmus Karlsson 2017-10-27 21:02:58 +02:00
parent 37571ae613
commit c08059c6a8
3 changed files with 13 additions and 4 deletions

View file

@ -11,9 +11,11 @@ FontManager::FontManager()
{ {
this->currentFontFamily.getValueChangedSignal().connect([this](const std::string &newValue) { this->currentFontFamily.getValueChangedSignal().connect([this](const std::string &newValue) {
this->currentFont.setFamily(newValue.c_str()); // this->currentFont.setFamily(newValue.c_str()); //
this->fontChanged.invoke();
}); });
this->currentFontSize.getValueChangedSignal().connect([this](const int &newValue) { this->currentFontSize.getValueChangedSignal().connect([this](const int &newValue) {
this->currentFont.setSize(newValue); // this->currentFont.setSize(newValue); //
this->fontChanged.invoke();
}); });
} }

View file

@ -3,11 +3,15 @@
#include <QFont> #include <QFont>
#include <QFontMetrics> #include <QFontMetrics>
#include <pajlada/settings/setting.hpp> #include <pajlada/settings/setting.hpp>
#include <pajlada/signals/signal.hpp>
namespace chatterino { namespace chatterino {
class FontManager class FontManager
{ {
FontManager(const FontManager &) = delete;
FontManager(FontManager &&) = delete;
public: public:
enum Type : uint8_t { enum Type : uint8_t {
Small, Small,
@ -42,6 +46,8 @@ public:
pajlada::Settings::Setting<std::string> currentFontFamily; pajlada::Settings::Setting<std::string> currentFontFamily;
pajlada::Settings::Setting<int> currentFontSize; pajlada::Settings::Setting<int> currentFontSize;
pajlada::Signals::NoArgSignal fontChanged;
private: private:
FontManager(); FontManager();

View file

@ -158,7 +158,7 @@ QVBoxLayout *SettingsDialog::createAccountsTab()
QVBoxLayout *SettingsDialog::createAppearanceTab() QVBoxLayout *SettingsDialog::createAppearanceTab()
{ {
SettingsManager &settings = SettingsManager::getInstance(); auto &settings = SettingsManager::getInstance();
auto layout = this->createTabLayout(); auto layout = this->createTabLayout();
{ {
@ -176,8 +176,9 @@ QVBoxLayout *SettingsDialog::createAppearanceTab()
fontLayout->addWidget(fontFamilyLabel); fontLayout->addWidget(fontFamilyLabel);
fontLayout->addWidget(fontSizeLabel); fontLayout->addWidget(fontSizeLabel);
{ {
auto fontManager = FontManager::getInstance(); auto &fontManager = FontManager::getInstance();
fontManager.currentFontFamily.getValueChangedSignal().connect( fontManager.currentFontFamily.getValueChangedSignal().connect(
[fontFamilyLabel](const std::string &newValue) { [fontFamilyLabel](const std::string &newValue) {
@ -191,11 +192,11 @@ QVBoxLayout *SettingsDialog::createAppearanceTab()
} }
fontButton->connect(fontButton, &QPushButton::clicked, []() { fontButton->connect(fontButton, &QPushButton::clicked, []() {
auto fontManager = FontManager::getInstance(); auto &fontManager = FontManager::getInstance();
QFontDialog dialog(fontManager.getFont(FontManager::Medium)); QFontDialog dialog(fontManager.getFont(FontManager::Medium));
dialog.connect(&dialog, &QFontDialog::fontSelected, [](const QFont &font) { dialog.connect(&dialog, &QFontDialog::fontSelected, [](const QFont &font) {
auto fontManager = FontManager::getInstance(); auto &fontManager = FontManager::getInstance();
fontManager.currentFontFamily = font.family().toStdString(); fontManager.currentFontFamily = font.family().toStdString();
fontManager.currentFontSize = font.pointSize(); fontManager.currentFontSize = font.pointSize();
}); });