diff --git a/lib/settings b/lib/settings index fd457602..b0a6b529 160000 --- a/lib/settings +++ b/lib/settings @@ -1 +1 @@ -Subproject commit fd457602eac17c9a2ea624b7551f2cac2026610a +Subproject commit b0a6b529a0702d69c085d76ef832639ca1c02dcd diff --git a/src/colorscheme.cpp b/src/colorscheme.cpp index 8c4b9d6f..fe433d67 100644 --- a/src/colorscheme.cpp +++ b/src/colorscheme.cpp @@ -1,7 +1,6 @@ #define LOOKUP_COLOR_COUNT 360 #include "colorscheme.hpp" -#include "settingsmanager.hpp" #include "windowmanager.hpp" #include @@ -28,14 +27,16 @@ double getMultiplierByTheme(const std::string &themeName) } // namespace detail ColorScheme::ColorScheme(WindowManager &windowManager) + : themeName("/appearance/theme/name", "Dark") + , themeHue("/appearance/theme/hue", 0.0) { this->update(); - SettingsManager::getInstance().themeName.getValueChangedSignal().connect([=](const auto &) { + this->themeName.getValueChangedSignal().connect([=](const auto &) { this->update(); // }); - SettingsManager::getInstance().themeHue.getValueChangedSignal().connect([=](const auto &) { + this->themeHue.getValueChangedSignal().connect([=](const auto &) { this->update(); // }); @@ -46,9 +47,7 @@ ColorScheme::ColorScheme(WindowManager &windowManager) void ColorScheme::update() { - SettingsManager &settings = SettingsManager::getInstance(); - - this->setColors(settings.themeHue, detail::getMultiplierByTheme(settings.themeName)); + this->setColors(this->themeHue, detail::getMultiplierByTheme(this->themeName)); } // hue: theme color (0 - 1) diff --git a/src/colorscheme.hpp b/src/colorscheme.hpp index 17a77d24..7f4fd89d 100644 --- a/src/colorscheme.hpp +++ b/src/colorscheme.hpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace chatterino { @@ -75,6 +76,9 @@ public: boost::signals2::signal updated; private: + pajlada::Settings::Setting themeName; + pajlada::Settings::Setting themeHue; + void setColors(double hue, double multiplier); double middleLookupTable[360] = {}; @@ -83,7 +87,7 @@ private: void fillLookupTableValues(double (&array)[360], double from, double to, double fromValue, double toValue); - bool lightTheme; + bool lightTheme = false; }; } // namespace chatterino diff --git a/src/settingsmanager.cpp b/src/settingsmanager.cpp index fe5bc49f..33134ff6 100644 --- a/src/settingsmanager.cpp +++ b/src/settingsmanager.cpp @@ -14,8 +14,6 @@ SettingsManager::SettingsManager() , showTimestamps("/appearance/messages/showTimestamps", true) , showTimestampSeconds("/appearance/messages/showTimestampSeconds", true) , showBadges("/appearance/messages/showBadges", true) - , themeName("/appearance/theme/name", "Dark") - , themeHue("/appearance/theme/hue", 0.0) , selectedUser(_settingsItems, "selectedUser", "") , emoteScale(_settingsItems, "emoteScale", 1.0) , mouseScrollMultiplier(_settingsItems, "mouseScrollMultiplier", 1.0) diff --git a/src/settingsmanager.hpp b/src/settingsmanager.hpp index 767cc361..57ad8337 100644 --- a/src/settingsmanager.hpp +++ b/src/settingsmanager.hpp @@ -42,8 +42,6 @@ public: pajlada::Settings::Setting showTimestamps; pajlada::Settings::Setting showTimestampSeconds; pajlada::Settings::Setting showBadges; - pajlada::Settings::Setting themeName; - pajlada::Settings::Setting themeHue; // Settings Setting selectedUser; diff --git a/src/widgets/settingsdialog.cpp b/src/widgets/settingsdialog.cpp index 948a9039..b819e6a7 100644 --- a/src/widgets/settingsdialog.cpp +++ b/src/widgets/settingsdialog.cpp @@ -19,47 +19,48 @@ namespace chatterino { namespace widgets { SettingsDialog::SettingsDialog() - : _snapshot(SettingsManager::getInstance().createSnapshot()) + : snapshot(SettingsManager::getInstance().createSnapshot()) { QFile file(":/qss/settings.qss"); file.open(QFile::ReadOnly); QString styleSheet = QLatin1String(file.readAll()); - setStyleSheet(styleSheet); + this->setStyleSheet(styleSheet); QPalette palette; palette.setColor(QPalette::Background, QColor("#444")); - setPalette(palette); + this->setPalette(palette); - _pageStack.setObjectName("pages"); + this->ui.pageStack.setObjectName("pages"); - setLayout(&_vbox); + this->setLayout(&this->ui.vbox); - _vbox.addLayout(&_hbox); + this->ui.vbox.addLayout(&this->ui.hbox); - _vbox.addWidget(&_buttonBox); + this->ui.vbox.addWidget(&this->ui.buttonBox); auto tabWidget = new QWidget(); tabWidget->setObjectName("tabWidget"); - tabWidget->setLayout(&_tabs); + tabWidget->setLayout(&this->ui.tabs); tabWidget->setFixedWidth(200); - _hbox.addWidget(tabWidget); - _hbox.addLayout(&_pageStack); + this->ui.hbox.addWidget(tabWidget); + this->ui.hbox.addLayout(&this->ui.pageStack); - _buttonBox.addButton(&_okButton, QDialogButtonBox::ButtonRole::AcceptRole); - _buttonBox.addButton(&_cancelButton, QDialogButtonBox::ButtonRole::RejectRole); + this->ui.buttonBox.addButton(&this->ui.okButton, QDialogButtonBox::ButtonRole::AcceptRole); + this->ui.buttonBox.addButton(&this->ui.cancelButton, QDialogButtonBox::ButtonRole::RejectRole); - QObject::connect(&_okButton, &QPushButton::clicked, this, &SettingsDialog::okButtonClicked); - QObject::connect(&_cancelButton, &QPushButton::clicked, this, + QObject::connect(&this->ui.okButton, &QPushButton::clicked, this, + &SettingsDialog::okButtonClicked); + QObject::connect(&this->ui.cancelButton, &QPushButton::clicked, this, &SettingsDialog::cancelButtonClicked); - _okButton.setText("OK"); - _cancelButton.setText("Cancel"); + this->ui.okButton.setText("OK"); + this->ui.cancelButton.setText("Cancel"); - resize(600, 500); + this->resize(600, 500); - addTabs(); + this->addTabs(); } void SettingsDialog::addTabs() @@ -161,7 +162,9 @@ void SettingsDialog::addTabs() slider->setMinimum(0); slider->setMaximum(1000); - slider->setValue(std::min(std::max(settings.themeHue.getValue(), 0.0), 1.0) * 1000); + pajlada::Settings::Setting themeHue("/appearance/theme/hue"); + + slider->setValue(std::min(std::max(themeHue.getValue(), 0.0), 1.0) * 1000); hbox->addWidget(slider); @@ -172,12 +175,15 @@ void SettingsDialog::addTabs() form->addRow("Theme color:", hbox); - QObject::connect(slider, &QSlider::valueChanged, this, [&settings, button](int value) { - settings.themeHue.setValue(value / 1000.0); + QObject::connect(slider, &QSlider::valueChanged, this, [button](int value) mutable { + double newValue = value / 1000.0; + pajlada::Settings::Setting themeHue("/appearance/theme/hue"); + + themeHue.setValue(newValue); QPalette pal = button->palette(); QColor color; - color.setHsvF(settings.themeHue.getValue(), 1.0, 1.0, 1.0); + color.setHsvF(newValue, 1.0, 1.0, 1.0); pal.setColor(QPalette::Button, color); button->setAutoFillBackground(true); button->setPalette(pal); @@ -193,20 +199,29 @@ void SettingsDialog::addTabs() form->addRow("", hidePreferencesButton); form->addRow("", hideUserButton); - // Theme name - combo->addItem("White"); - combo->addItem("Light"); - combo->addItem("Dark"); - combo->addItem("Black"); + { + // Theme name + combo->addItems({ + "White", // + "Light", // + "Dark", // + "Black", // + }); + // combo->addItem("White"); + // combo->addItem("Light"); + // combo->addItem("Dark"); + // combo->addItem("Black"); - auto xD = QString::fromStdString(settings.themeName); + QString currentComboText = QString::fromStdString( + pajlada::Settings::Setting::get("/appearance/theme/name")); - combo->setCurrentText(xD); + combo->setCurrentText(currentComboText); - QObject::connect(combo, &QComboBox::currentTextChanged, this, - [&settings](const QString &value) { - settings.themeName.setValue(value.toStdString()); // - }); + QObject::connect(combo, &QComboBox::currentTextChanged, this, [](const QString &value) { + pajlada::Settings::Setting::set("/appearance/theme/name", + value.toStdString()); + }); + } group->setLayout(form); @@ -317,7 +332,7 @@ void SettingsDialog::addTabs() addTab(vbox, "Whispers", ":/images/Message_16xLG.png"); // Add stretch - _tabs.addStretch(1); + this->ui.tabs.addStretch(1); } void SettingsDialog::addTab(QLayout *layout, QString title, QString imageRes) @@ -330,27 +345,27 @@ void SettingsDialog::addTab(QLayout *layout, QString title, QString imageRes) tab->setWidget(widget); - _tabs.addWidget(tab, 0, Qt::AlignTop); + this->ui.tabs.addWidget(tab, 0, Qt::AlignTop); - _pageStack.addWidget(widget); + this->ui.pageStack.addWidget(widget); - if (_tabs.count() == 1) { - select(tab); + if (this->ui.tabs.count() == 1) { + this->select(tab); } } void SettingsDialog::select(SettingsDialogTab *tab) { - _pageStack.setCurrentWidget(tab->getWidget()); + this->ui.pageStack.setCurrentWidget(tab->getWidget()); - if (_selectedTab != nullptr) { - _selectedTab->setSelected(false); - _selectedTab->setStyleSheet("color: #FFF"); + if (this->selectedTab != nullptr) { + this->selectedTab->setSelected(false); + this->selectedTab->setStyleSheet("color: #FFF"); } tab->setSelected(true); tab->setStyleSheet("background: #555; color: #FFF"); - _selectedTab = tab; + this->selectedTab = tab; } void SettingsDialog::showDialog() @@ -371,8 +386,9 @@ QCheckBox *SettingsDialog::createCheckbox(const QString &title, Setting &s // Set checkbox initial state checkbox->setChecked(setting.get()); - QObject::connect(checkbox, &QCheckBox::toggled, this, - [&setting](bool state) { setting.set(state); }); + QObject::connect(checkbox, &QCheckBox::toggled, this, [&setting](bool state) { + setting.set(state); // + }); return checkbox; } @@ -400,7 +416,8 @@ void SettingsDialog::okButtonClicked() void SettingsDialog::cancelButtonClicked() { - _snapshot.apply(); + // TODO: Re-implement the snapshot feature properly + this->snapshot.apply(); this->close(); } diff --git a/src/widgets/settingsdialog.hpp b/src/widgets/settingsdialog.hpp index 1e4c5c04..f564572c 100644 --- a/src/widgets/settingsdialog.hpp +++ b/src/widgets/settingsdialog.hpp @@ -30,21 +30,23 @@ public: static void showDialog(); private: - SettingsSnapshot _snapshot; + SettingsSnapshot snapshot; - QVBoxLayout _tabs; - QVBoxLayout _vbox; - QHBoxLayout _hbox; - QStackedLayout _pageStack; - QDialogButtonBox _buttonBox; - QPushButton _okButton; - QPushButton _cancelButton; + struct { + QVBoxLayout tabs; + QVBoxLayout vbox; + QHBoxLayout hbox; + QStackedLayout pageStack; + QDialogButtonBox buttonBox; + QPushButton okButton; + QPushButton cancelButton; + } ui; void addTab(QLayout *layout, QString title, QString imageRes); void addTabs(); - SettingsDialogTab *_selectedTab = nullptr; + SettingsDialogTab *selectedTab = nullptr; /// Widget creation helpers QCheckBox *createCheckbox(const QString &title, Setting &setting); diff --git a/src/widgets/settingsdialogtab.cpp b/src/widgets/settingsdialogtab.cpp index 3ea0a6d6..658d4afb 100644 --- a/src/widgets/settingsdialogtab.cpp +++ b/src/widgets/settingsdialogtab.cpp @@ -7,41 +7,39 @@ namespace chatterino { namespace widgets { -SettingsDialogTab::SettingsDialogTab(SettingsDialog *dialog, QString label, QString imageRes) - : _label(label) - , _image(QImage(imageRes)) - , _dialog(dialog) - , _selected(false) +SettingsDialogTab::SettingsDialogTab(SettingsDialog *_dialog, QString _labelText, + QString imageFileName) + : dialog(_dialog) { - setFixedHeight(32); + this->ui.labelText = _labelText; + this->ui.image.load(imageFileName); - setCursor(QCursor(Qt::PointingHandCursor)); + // XXX: DPI (not sure if this is auto-adjusted with custom DPI) + this->setFixedHeight(32); - setStyleSheet("color: #FFF"); + this->setCursor(QCursor(Qt::PointingHandCursor)); + + this->setStyleSheet("color: #FFF"); } -void SettingsDialogTab::setSelected(bool selected) +void SettingsDialogTab::setSelected(bool _selected) { - if (_selected == selected) + if (this->selected == _selected) { return; + } - _selected = selected; + this->selected = _selected; emit selectedChanged(selected); } -bool SettingsDialogTab::getSelected() const -{ - return _selected; -} - QWidget *SettingsDialogTab::getWidget() { - return _widget; + return this->ui.widget; } void SettingsDialogTab::setWidget(QWidget *widget) { - _widget = widget; + this->ui.widget = widget; } void SettingsDialogTab::paintEvent(QPaintEvent *) @@ -51,15 +49,15 @@ void SettingsDialogTab::paintEvent(QPaintEvent *) QStyleOption opt; opt.init(this); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); + this->style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); - int a = (height() - _image.width()) / 2; + int a = (this->height() - this->ui.image.width()) / 2; - painter.drawImage(a, a, _image); + painter.drawImage(a, a, this->ui.image); - a = a + a + _image.width(); + a = a + a + this->ui.image.width(); - painter.drawText(QRect(a, 0, width() - a, height()), _label, + painter.drawText(QRect(a, 0, width() - a, height()), this->ui.labelText, QTextOption(Qt::AlignLeft | Qt::AlignVCenter)); } @@ -69,7 +67,7 @@ void SettingsDialogTab::mousePressEvent(QMouseEvent *event) return; } - _dialog->select(this); + this->dialog->select(this); } } // namespace widgets diff --git a/src/widgets/settingsdialogtab.hpp b/src/widgets/settingsdialogtab.hpp index f6a720f4..d2396605 100644 --- a/src/widgets/settingsdialogtab.hpp +++ b/src/widgets/settingsdialogtab.hpp @@ -11,13 +11,11 @@ class SettingsDialog; class SettingsDialogTab : public QWidget { Q_OBJECT - Q_PROPERTY(bool getSelected READ getSelected WRITE setSelected NOTIFY selectedChanged) public: - SettingsDialogTab(SettingsDialog *_dialog, QString _label, QString imageRes); + SettingsDialogTab(SettingsDialog *dialog, QString _label, QString imageFileName); void setSelected(bool selected); - bool getSelected() const; QWidget *getWidget(); void setWidget(QWidget *widget); @@ -28,13 +26,16 @@ private: void paintEvent(QPaintEvent *); void mousePressEvent(QMouseEvent *event); - QWidget *_widget; - QString _label; - QImage _image; + struct { + QWidget *widget; + QString labelText; + QImage image; + } ui; - SettingsDialog *_dialog; + // Parent settings dialog + SettingsDialog *dialog; - bool _selected; + bool selected = false; }; } // namespace widgets