2019-09-08 22:27:57 +02:00
|
|
|
#include "SettingsPage.hpp"
|
|
|
|
|
|
|
|
#include "Application.hpp"
|
|
|
|
#include "singletons/WindowManager.hpp"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <util/FunctionEventFilter.hpp>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
bool filterItemsRec(QObject *object, const QString &query)
|
|
|
|
{
|
|
|
|
bool any{};
|
|
|
|
|
|
|
|
for (auto &&child : object->children())
|
|
|
|
{
|
|
|
|
auto setOpacity = [&](auto *widget, bool condition) {
|
|
|
|
any |= condition;
|
|
|
|
widget->greyedOut = !condition;
|
|
|
|
widget->update();
|
|
|
|
};
|
|
|
|
|
|
|
|
if (auto x = dynamic_cast<SCheckBox *>(child); x)
|
|
|
|
{
|
|
|
|
setOpacity(x, x->text().contains(query, Qt::CaseInsensitive));
|
|
|
|
}
|
|
|
|
else if (auto x = dynamic_cast<SLabel *>(child); x)
|
|
|
|
{
|
|
|
|
setOpacity(x, x->text().contains(query, Qt::CaseInsensitive));
|
|
|
|
}
|
|
|
|
else if (auto x = dynamic_cast<SComboBox *>(child); x)
|
|
|
|
{
|
|
|
|
setOpacity(x, [=]() {
|
|
|
|
for (int i = 0; i < x->count(); i++)
|
|
|
|
{
|
|
|
|
if (x->itemText(i).contains(query, Qt::CaseInsensitive))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}());
|
|
|
|
}
|
|
|
|
else if (auto x = dynamic_cast<QTabWidget *>(child); x)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < x->count(); i++)
|
|
|
|
{
|
|
|
|
bool tabAny{};
|
|
|
|
|
|
|
|
if (x->tabText(i).contains(query, Qt::CaseInsensitive))
|
|
|
|
{
|
|
|
|
tabAny = true;
|
|
|
|
}
|
|
|
|
auto widget = x->widget(i);
|
|
|
|
tabAny |= filterItemsRec(widget, query);
|
|
|
|
|
|
|
|
any |= tabAny;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
any |= filterItemsRec(child, query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return any;
|
|
|
|
}
|
|
|
|
|
2020-02-21 01:59:58 +01:00
|
|
|
SettingsPage::SettingsPage()
|
2019-09-08 22:27:57 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SettingsPage::filterElements(const QString &query)
|
|
|
|
{
|
2020-02-21 01:59:58 +01:00
|
|
|
return filterItemsRec(this, query) || query.isEmpty();
|
2019-09-08 22:27:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SettingsDialogTab *SettingsPage::tab() const
|
|
|
|
{
|
|
|
|
return this->tab_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsPage::setTab(SettingsDialogTab *tab)
|
|
|
|
{
|
|
|
|
this->tab_ = tab;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsPage::cancel()
|
|
|
|
{
|
|
|
|
this->onCancel_.invoke();
|
|
|
|
}
|
|
|
|
|
|
|
|
QCheckBox *SettingsPage::createCheckBox(
|
|
|
|
const QString &text, pajlada::Settings::Setting<bool> &setting)
|
|
|
|
{
|
|
|
|
QCheckBox *checkbox = new SCheckBox(text);
|
|
|
|
|
|
|
|
// update when setting changes
|
|
|
|
setting.connect(
|
|
|
|
[checkbox](const bool &value, auto) {
|
2020-11-08 12:02:19 +01:00
|
|
|
checkbox->setChecked(value);
|
2019-09-08 22:27:57 +02:00
|
|
|
},
|
|
|
|
this->managedConnections_);
|
|
|
|
|
|
|
|
// update setting on toggle
|
|
|
|
QObject::connect(checkbox, &QCheckBox::toggled, this,
|
|
|
|
[&setting](bool state) {
|
|
|
|
setting = state;
|
|
|
|
getApp()->windows->forceLayoutChannelViews();
|
|
|
|
});
|
|
|
|
|
|
|
|
return checkbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
QComboBox *SettingsPage::createComboBox(
|
|
|
|
const QStringList &items, pajlada::Settings::Setting<QString> &setting)
|
|
|
|
{
|
|
|
|
QComboBox *combo = new SComboBox();
|
|
|
|
|
|
|
|
// update setting on toogle
|
|
|
|
combo->addItems(items);
|
|
|
|
|
|
|
|
// update when setting changes
|
|
|
|
setting.connect(
|
2020-11-08 12:02:19 +01:00
|
|
|
[combo](const QString &value, auto) {
|
|
|
|
combo->setCurrentText(value);
|
|
|
|
},
|
2019-09-08 22:27:57 +02:00
|
|
|
this->managedConnections_);
|
|
|
|
|
2020-11-08 12:02:19 +01:00
|
|
|
QObject::connect(combo, &QComboBox::currentTextChanged,
|
|
|
|
[&setting](const QString &newValue) {
|
|
|
|
setting = newValue;
|
|
|
|
});
|
2019-09-08 22:27:57 +02:00
|
|
|
|
|
|
|
return combo;
|
|
|
|
}
|
|
|
|
|
|
|
|
QLineEdit *SettingsPage::createLineEdit(
|
|
|
|
pajlada::Settings::Setting<QString> &setting)
|
|
|
|
{
|
|
|
|
QLineEdit *edit = new QLineEdit();
|
|
|
|
|
|
|
|
edit->setText(setting);
|
|
|
|
|
|
|
|
// update when setting changes
|
2020-11-08 12:02:19 +01:00
|
|
|
QObject::connect(edit, &QLineEdit::textChanged,
|
|
|
|
[&setting](const QString &newValue) {
|
|
|
|
setting = newValue;
|
|
|
|
});
|
2019-09-08 22:27:57 +02:00
|
|
|
|
|
|
|
return edit;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSpinBox *SettingsPage::createSpinBox(pajlada::Settings::Setting<int> &setting,
|
|
|
|
int min, int max)
|
|
|
|
{
|
|
|
|
QSpinBox *w = new QSpinBox;
|
|
|
|
|
|
|
|
w->setMinimum(min);
|
|
|
|
w->setMaximum(max);
|
|
|
|
|
2020-11-08 12:02:19 +01:00
|
|
|
setting.connect([w](const int &value, auto) {
|
|
|
|
w->setValue(value);
|
|
|
|
});
|
2019-09-08 22:27:57 +02:00
|
|
|
QObject::connect(w, QOverload<int>::of(&QSpinBox::valueChanged),
|
2020-11-08 12:02:19 +01:00
|
|
|
[&setting](int value) {
|
|
|
|
setting.setValue(value);
|
|
|
|
});
|
2019-09-08 22:27:57 +02:00
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|