refactor(SettingWidget): use custom setting widgets (#6361)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QPainter>
|
||||
#include <QPushButton>
|
||||
|
||||
#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
|
||||
@@ -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 <QBoxLayout>
|
||||
@@ -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);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "widgets/settingspages/CustomWidgets.hpp"
|
||||
|
||||
#include <pajlada/settings.hpp>
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
#include <QCheckBox>
|
||||
@@ -10,38 +12,8 @@
|
||||
#include <QPushButton>
|
||||
#include <QSpinBox>
|
||||
|
||||
#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
|
||||
|
||||
Reference in New Issue
Block a user