1 #pragma once
2 
3 #include <QCheckBox>
4 #include <QComboBox>
5 #include <QLineEdit>
6 #include <QSpinBox>
7 #include <pajlada/signals/signal.hpp>
8 
9 #include "singletons/Settings.hpp"
10 
11 #include <QLabel>
12 #include <QPainter>
13 #include <QPushButton>
14 
15 #define SETTINGS_PAGE_WIDGET_BOILERPLATE(type, parent) \
16     class type : public parent                         \
17     {                                                  \
18         using parent::parent;                          \
19                                                        \
20     public:                                            \
21         bool greyedOut{};                              \
22                                                        \
23     protected:                                         \
24         void paintEvent(QPaintEvent *e) override       \
25         {                                              \
26             parent::paintEvent(e);                     \
27                                                        \
28             if (this->greyedOut)                       \
29             {                                          \
30                 QPainter painter(this);                \
31                 QColor color = QColor("#222222");      \
32                 color.setAlphaF(0.7);                  \
33                 painter.fillRect(this->rect(), color); \
34             }                                          \
35         }                                              \
36     };
37 
38 namespace chatterino {
39 
40 // S* widgets are the same as their Q* counterparts,
41 // but they can be greyed out and will be if you search.
42 SETTINGS_PAGE_WIDGET_BOILERPLATE(SCheckBox, QCheckBox)
43 SETTINGS_PAGE_WIDGET_BOILERPLATE(SLabel, QLabel)
44 SETTINGS_PAGE_WIDGET_BOILERPLATE(SComboBox, QComboBox)
45 SETTINGS_PAGE_WIDGET_BOILERPLATE(SPushButton, QPushButton)
46 
47 class SettingsDialogTab;
48 
49 class SettingsPage : public QFrame
50 {
51     Q_OBJECT
52 
53 public:
54     SettingsPage();
55 
56     virtual bool filterElements(const QString &query);
57 
58     SettingsDialogTab *tab() const;
59     void setTab(SettingsDialogTab *tab);
60 
61     void cancel();
62 
63     QCheckBox *createCheckBox(const QString &text,
64                               pajlada::Settings::Setting<bool> &setting);
65     QComboBox *createComboBox(const QStringList &items,
66                               pajlada::Settings::Setting<QString> &setting);
67     QLineEdit *createLineEdit(pajlada::Settings::Setting<QString> &setting);
68     QSpinBox *createSpinBox(pajlada::Settings::Setting<int> &setting,
69                             int min = 0, int max = 2500);
70 
onShow()71     virtual void onShow()
72     {
73     }
74 
75 protected:
76     SettingsDialogTab *tab_;
77     pajlada::Signals::NoArgSignal onCancel_;
78     std::vector<pajlada::Signals::ScopedConnection> managedConnections_;
79 };
80 
81 }  // namespace chatterino
82