mirror-chatterino2/src/widgets/settingspages/SettingsPage.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

94 lines
3.1 KiB
C++
Raw Normal View History

2018-01-12 23:09:05 +01:00
#pragma once
#include <pajlada/settings.hpp>
#include <pajlada/signals/signal.hpp>
#include <QCheckBox>
#include <QComboBox>
#include <QLabel>
#include <QLineEdit>
#include <QPainter>
#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.7); \
painter.fillRect(this->rect(), color); \
} \
} \
};
2018-01-12 23:09:05 +01:00
namespace chatterino {
2019-09-03 11:15:38 +02:00
// 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)
2019-09-03 11:15:38 +02:00
SETTINGS_PAGE_WIDGET_BOILERPLATE(SPushButton, QPushButton)
class SettingsDialogTab;
2018-10-31 19:45:51 +01:00
class SettingsPage : public QFrame
2018-01-12 23:09:05 +01:00
{
2018-10-31 19:45:51 +01:00
Q_OBJECT
2018-01-12 23:09:05 +01:00
public:
2020-02-21 01:59:58 +01:00
SettingsPage();
2019-09-02 16:39:21 +02:00
virtual bool filterElements(const QString &query);
SettingsDialogTab *tab() const;
void setTab(SettingsDialogTab *tab);
2018-01-12 23:09:05 +01:00
void cancel();
2018-01-12 23:09:05 +01:00
QCheckBox *createCheckBox(const QString &text,
pajlada::Settings::Setting<bool> &setting);
QComboBox *createComboBox(const QStringList &items,
pajlada::Settings::Setting<QString> &setting);
QLineEdit *createLineEdit(pajlada::Settings::Setting<QString> &setting);
QSpinBox *createSpinBox(pajlada::Settings::Setting<int> &setting,
int min = 0, int max = 2500);
template <typename T>
SLabel *createLabel(const std::function<QString(const T &)> &makeText,
pajlada::Settings::Setting<T> &setting)
{
auto *label = new SLabel();
setting.connect(
[label, makeText](const T &value, auto) {
label->setText(makeText(value));
},
this->managedConnections_);
return label;
}
virtual void onShow()
{
}
2018-01-12 23:09:05 +01:00
protected:
SettingsDialogTab *tab_{};
2018-07-06 19:23:47 +02:00
pajlada::Signals::NoArgSignal onCancel_;
pajlada::Signals::SignalHolder managedConnections_;
2018-01-12 23:09:05 +01:00
};
2018-01-12 23:09:05 +01:00
} // namespace chatterino