2018-10-31 19:45:51 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
2018-10-31 20:40:57 +01:00
|
|
|
#include "Application.hpp"
|
2018-10-31 19:45:51 +01:00
|
|
|
#include "boost/variant.hpp"
|
|
|
|
#include "pajlada/signals/signal.hpp"
|
|
|
|
#include "singletons/Settings.hpp"
|
2018-10-31 20:40:57 +01:00
|
|
|
#include "singletons/WindowManager.hpp"
|
2018-10-31 19:45:51 +01:00
|
|
|
#include "widgets/settingspages/SettingsPage.hpp"
|
|
|
|
|
|
|
|
class QLabel;
|
|
|
|
class QCheckBox;
|
|
|
|
class QComboBox;
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
class TitleLabel : public QLabel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
TitleLabel(const QString &text)
|
|
|
|
: QLabel(text)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DescriptionLabel : public QLabel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
DescriptionLabel(const QString &text)
|
|
|
|
: QLabel(text)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DropdownArgs {
|
|
|
|
QString value;
|
|
|
|
int index;
|
|
|
|
QComboBox *combobox;
|
|
|
|
};
|
|
|
|
|
2018-10-31 20:57:29 +01:00
|
|
|
class ComboBox : public QComboBox
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
void wheelEvent(QWheelEvent *event) override
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-31 19:45:51 +01:00
|
|
|
class SettingsLayout : public QVBoxLayout
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
TitleLabel *addTitle(const QString &text);
|
2019-08-26 13:18:23 +02:00
|
|
|
/// @param inverse Inverses true to false and vice versa
|
|
|
|
QCheckBox *addCheckbox(const QString &text, BoolSetting &setting,
|
|
|
|
bool inverse = false);
|
2018-10-31 20:57:29 +01:00
|
|
|
ComboBox *addDropdown(const QString &text, const QStringList &items);
|
|
|
|
ComboBox *addDropdown(const QString &text, const QStringList &items,
|
2018-10-31 21:13:01 +01:00
|
|
|
pajlada::Settings::Setting<QString> &setting,
|
|
|
|
bool editable = false);
|
2018-10-31 19:45:51 +01:00
|
|
|
|
2019-09-03 11:38:15 +02:00
|
|
|
template <typename OnClick>
|
|
|
|
QPushButton *addButton(const QString &text, OnClick onClick)
|
|
|
|
{
|
|
|
|
auto button = new QPushButton(text);
|
|
|
|
this->groups_.back().widgets.push_back({button, {text}});
|
|
|
|
QObject::connect(button, &QPushButton::clicked, onClick);
|
|
|
|
this->addWidget(button);
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2018-10-31 19:45:51 +01:00
|
|
|
template <typename T>
|
2018-10-31 20:57:29 +01:00
|
|
|
ComboBox *addDropdown(
|
2018-10-31 19:45:51 +01:00
|
|
|
const QString &text, const QStringList &items,
|
|
|
|
pajlada::Settings::Setting<T> &setting,
|
|
|
|
std::function<boost::variant<int, QString>(T)> getValue,
|
|
|
|
std::function<T(DropdownArgs)> setValue, bool editable = true)
|
|
|
|
{
|
|
|
|
auto items2 = items;
|
|
|
|
auto selected = getValue(setting.getValue());
|
|
|
|
|
|
|
|
if (selected.which() == 1)
|
|
|
|
{
|
|
|
|
// QString
|
|
|
|
if (!editable && !items2.contains(boost::get<QString>(selected)))
|
|
|
|
items2.insert(0, boost::get<QString>(selected));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto combo = this->addDropdown(text, items2);
|
|
|
|
if (editable)
|
|
|
|
combo->setEditable(true);
|
|
|
|
|
|
|
|
if (selected.which() == 0)
|
|
|
|
{
|
|
|
|
// int
|
|
|
|
auto value = boost::get<int>(selected);
|
|
|
|
if (value >= 0 && value < items2.size())
|
|
|
|
combo->setCurrentIndex(value);
|
|
|
|
}
|
|
|
|
else if (selected.which() == 1)
|
|
|
|
{
|
|
|
|
// QString
|
|
|
|
combo->setEditText(boost::get<QString>(selected));
|
|
|
|
}
|
|
|
|
|
|
|
|
setting.connect(
|
|
|
|
[getValue = std::move(getValue), combo](const T &value, auto) {
|
|
|
|
auto var = getValue(value);
|
|
|
|
if (var.which() == 0)
|
|
|
|
combo->setCurrentIndex(boost::get<int>(var));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
combo->setCurrentText(boost::get<QString>(var));
|
|
|
|
combo->setEditText(boost::get<QString>(var));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
this->managedConnections_);
|
|
|
|
|
|
|
|
QObject::connect(
|
|
|
|
combo,
|
|
|
|
QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
|
|
|
|
// &QComboBox::editTextChanged,
|
|
|
|
[combo, &setting,
|
|
|
|
setValue = std::move(setValue)](const QString &newValue) {
|
|
|
|
setting = setValue(
|
|
|
|
DropdownArgs{newValue, combo->currentIndex(), combo});
|
|
|
|
getApp()->windows->forceLayoutChannelViews();
|
|
|
|
});
|
|
|
|
|
|
|
|
return combo;
|
|
|
|
}
|
|
|
|
DescriptionLabel *addDescription(const QString &text);
|
2019-09-01 23:23:20 +02:00
|
|
|
|
2018-10-31 19:45:51 +01:00
|
|
|
void addSeperator();
|
2019-09-02 16:39:21 +02:00
|
|
|
bool filterElements(const QString &query);
|
2018-10-31 19:45:51 +01:00
|
|
|
|
|
|
|
private:
|
2019-09-01 23:23:20 +02:00
|
|
|
struct Widget {
|
|
|
|
QWidget *element;
|
|
|
|
QStringList keywords;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Group {
|
|
|
|
QString name;
|
|
|
|
QWidget *title{};
|
|
|
|
std::vector<Widget> widgets;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<Group> groups_;
|
2018-10-31 19:45:51 +01:00
|
|
|
std::vector<pajlada::Signals::ScopedConnection> managedConnections_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GeneralPage : public SettingsPage
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
GeneralPage();
|
|
|
|
|
2019-09-02 16:39:21 +02:00
|
|
|
bool filterElements(const QString &query);
|
2019-09-01 23:23:20 +02:00
|
|
|
|
2018-10-31 19:45:51 +01:00
|
|
|
private:
|
|
|
|
void initLayout(SettingsLayout &layout);
|
|
|
|
void initExtra();
|
|
|
|
|
2018-11-03 13:00:07 +01:00
|
|
|
QString getFont(const DropdownArgs &args) const;
|
2018-10-31 19:45:51 +01:00
|
|
|
|
2019-09-01 23:23:20 +02:00
|
|
|
DescriptionLabel *cachePath_{};
|
|
|
|
SettingsLayout *settingsLayout_{};
|
2018-10-31 19:45:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace chatterino
|