diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fe9fb02d..09a5978a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -741,6 +741,7 @@ set(SOURCE_FILES widgets/settingspages/AccountsPage.hpp widgets/settingspages/CommandPage.cpp widgets/settingspages/CommandPage.hpp + widgets/settingspages/CustomWidgets.hpp widgets/settingspages/ExternalToolsPage.cpp widgets/settingspages/ExternalToolsPage.hpp widgets/settingspages/FiltersPage.cpp diff --git a/src/widgets/settingspages/CustomWidgets.hpp b/src/widgets/settingspages/CustomWidgets.hpp new file mode 100644 index 00000000..a955a2df --- /dev/null +++ b/src/widgets/settingspages/CustomWidgets.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include +#include +#include +#include +#include + +#define SETTINGS_PAGE_WIDGET_BOILERPLATE(type, parent) \ + class type : public parent \ + { \ + using parent::parent; \ + \ + public: \ + bool greyedOut{}; \ + \ + protected: \ + void paintEvent(QPaintEvent *e) override \ + { \ + parent::paintEvent(e); \ + \ + if (this->greyedOut) \ + { \ + QPainter painter(this); \ + QColor color = QColor("#222222"); \ + color.setAlphaF(0.7F); \ + painter.fillRect(this->rect(), color); \ + } \ + } \ + }; + +namespace chatterino { + +// S* widgets are the same as their Q* counterparts, +// but they can be greyed out and will be if you search. +SETTINGS_PAGE_WIDGET_BOILERPLATE(SCheckBox, QCheckBox) +SETTINGS_PAGE_WIDGET_BOILERPLATE(SLabel, QLabel) +SETTINGS_PAGE_WIDGET_BOILERPLATE(SComboBox, QComboBox) +SETTINGS_PAGE_WIDGET_BOILERPLATE(SPushButton, QPushButton) + +} // namespace chatterino diff --git a/src/widgets/settingspages/SettingWidget.cpp b/src/widgets/settingspages/SettingWidget.cpp index 320a410b..d24c64c9 100644 --- a/src/widgets/settingspages/SettingWidget.cpp +++ b/src/widgets/settingspages/SettingWidget.cpp @@ -6,6 +6,7 @@ #include "util/RapidJsonSerializeQString.hpp" // IWYU pragma: keep #include "widgets/dialogs/ColorPickerDialog.hpp" #include "widgets/helper/color/ColorButton.hpp" +#include "widgets/settingspages/CustomWidgets.hpp" #include "widgets/settingspages/GeneralPageView.hpp" #include @@ -44,13 +45,13 @@ SettingWidget *SettingWidget::checkbox(const QString &label, { auto *widget = new SettingWidget(label); - auto *check = new QCheckBox(label); + auto *check = new SCheckBox(label); widget->hLayout->addWidget(check); // update when setting changes setting.connect( - [check](const bool &value, auto) { + [check](const bool &value) { check->setChecked(value); }, widget->managedConnections); @@ -72,13 +73,13 @@ SettingWidget *SettingWidget::inverseCheckbox(const QString &label, { auto *widget = new SettingWidget(label); - auto *check = new QCheckBox(label); + auto *check = new SCheckBox(label); widget->hLayout->addWidget(check); // update when setting changes setting.connect( - [check](const bool &value, auto) { + [check](const bool &value) { check->setChecked(!value); }, widget->managedConnections); @@ -101,7 +102,7 @@ SettingWidget *SettingWidget::customCheckbox( { auto *widget = new SettingWidget(label); - auto *check = new QCheckBox(label); + auto *check = new SCheckBox(label); widget->hLayout->addWidget(check); @@ -473,7 +474,7 @@ SettingWidget *SettingWidget::fontButton(const QString &label, auto *lbl = new QLabel(label + ":"); - auto *button = new QPushButton(currentFont().family()); + auto *button = new SPushButton(currentFont().family()); widget->hLayout->addWidget(lbl); widget->hLayout->addStretch(1); diff --git a/src/widgets/settingspages/SettingsPage.hpp b/src/widgets/settingspages/SettingsPage.hpp index 80f36b8e..80aede70 100644 --- a/src/widgets/settingspages/SettingsPage.hpp +++ b/src/widgets/settingspages/SettingsPage.hpp @@ -1,5 +1,7 @@ #pragma once +#include "widgets/settingspages/CustomWidgets.hpp" + #include #include #include @@ -10,38 +12,8 @@ #include #include -#define SETTINGS_PAGE_WIDGET_BOILERPLATE(type, parent) \ - class type : public parent \ - { \ - using parent::parent; \ - \ - public: \ - bool greyedOut{}; \ - \ - protected: \ - void paintEvent(QPaintEvent *e) override \ - { \ - parent::paintEvent(e); \ - \ - if (this->greyedOut) \ - { \ - QPainter painter(this); \ - QColor color = QColor("#222222"); \ - color.setAlphaF(0.7F); \ - painter.fillRect(this->rect(), color); \ - } \ - } \ - }; - namespace chatterino { -// S* widgets are the same as their Q* counterparts, -// but they can be greyed out and will be if you search. -SETTINGS_PAGE_WIDGET_BOILERPLATE(SCheckBox, QCheckBox) -SETTINGS_PAGE_WIDGET_BOILERPLATE(SLabel, QLabel) -SETTINGS_PAGE_WIDGET_BOILERPLATE(SComboBox, QComboBox) -SETTINGS_PAGE_WIDGET_BOILERPLATE(SPushButton, QPushButton) - class SettingsDialogTab; class SettingsPage : public QFrame