2017-01-18 21:30:23 +01:00
|
|
|
#include "widgets/settingsdialog.h"
|
|
|
|
#include "widgets/settingsdialogtab.h"
|
2017-02-02 01:23:26 +01:00
|
|
|
#include "windows.h"
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
#include <QComboBox>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPalette>
|
|
|
|
#include <QResource>
|
2017-01-01 18:43:52 +01:00
|
|
|
|
2017-01-18 21:30:23 +01:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
|
|
|
|
2017-01-01 18:43:52 +01:00
|
|
|
SettingsDialog::SettingsDialog()
|
2017-01-24 19:51:57 +01:00
|
|
|
: snapshot(Settings::getInstance().createSnapshot())
|
2017-01-01 18:43:52 +01:00
|
|
|
{
|
2017-01-02 03:02:32 +01:00
|
|
|
QFile file(":/qss/settings.qss");
|
|
|
|
file.open(QFile::ReadOnly);
|
|
|
|
QString styleSheet = QLatin1String(file.readAll());
|
|
|
|
setStyleSheet(styleSheet);
|
|
|
|
|
|
|
|
QPalette palette;
|
|
|
|
palette.setColor(QPalette::Background, QColor("#444"));
|
|
|
|
setPalette(palette);
|
|
|
|
|
|
|
|
pageStack.setObjectName("pages");
|
|
|
|
|
|
|
|
setLayout(&vbox);
|
|
|
|
|
|
|
|
vbox.addLayout(&hbox);
|
|
|
|
|
|
|
|
vbox.addWidget(&buttonBox);
|
|
|
|
|
|
|
|
auto tabWidget = new QWidget();
|
|
|
|
tabWidget->setObjectName("tabWidget");
|
|
|
|
|
|
|
|
tabWidget->setLayout(&tabs);
|
|
|
|
tabWidget->setFixedWidth(200);
|
|
|
|
|
|
|
|
hbox.addWidget(tabWidget);
|
|
|
|
hbox.addLayout(&pageStack);
|
|
|
|
|
|
|
|
buttonBox.addButton(&okButton, QDialogButtonBox::ButtonRole::AcceptRole);
|
2017-01-11 18:52:09 +01:00
|
|
|
buttonBox.addButton(&cancelButton,
|
|
|
|
QDialogButtonBox::ButtonRole::RejectRole);
|
2017-01-24 19:51:57 +01:00
|
|
|
|
|
|
|
QObject::connect(&okButton, &QPushButton::clicked, this,
|
|
|
|
&SettingsDialog::okButtonClicked);
|
|
|
|
QObject::connect(&cancelButton, &QPushButton::clicked, this,
|
|
|
|
&SettingsDialog::cancelButtonClicked);
|
|
|
|
|
2017-01-02 03:02:32 +01:00
|
|
|
okButton.setText("OK");
|
|
|
|
cancelButton.setText("Cancel");
|
|
|
|
|
|
|
|
resize(600, 500);
|
|
|
|
|
|
|
|
addTabs();
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
SettingsDialog::addTabs()
|
2017-01-02 03:02:32 +01:00
|
|
|
{
|
2017-01-23 16:38:06 +01:00
|
|
|
Settings &settings = Settings::getInstance();
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
QVBoxLayout *vbox;
|
2017-01-02 03:02:32 +01:00
|
|
|
|
|
|
|
// Appearance
|
|
|
|
vbox = new QVBoxLayout();
|
|
|
|
|
|
|
|
{
|
2017-01-03 21:19:33 +01:00
|
|
|
auto group = new QGroupBox("Application");
|
|
|
|
|
2017-01-02 03:02:32 +01:00
|
|
|
auto form = new QFormLayout();
|
|
|
|
auto combo = new QComboBox();
|
|
|
|
auto slider = new QSlider(Qt::Horizontal);
|
|
|
|
auto font = new QPushButton("select");
|
2017-02-02 02:46:33 +01:00
|
|
|
auto compactTabs = createCheckbox("Hide tab X", settings.hideTabX);
|
|
|
|
auto hidePreferencesButton =
|
|
|
|
createCheckbox("Hide preferences button (ctrl+p to show)",
|
|
|
|
settings.hidePreferencesButton);
|
|
|
|
auto hideUserButton =
|
|
|
|
createCheckbox("Hide user button", settings.hideUserButton);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
|
|
|
form->addRow("Theme:", combo);
|
2017-01-03 21:19:33 +01:00
|
|
|
form->addRow("Theme color:", slider);
|
2017-01-02 03:02:32 +01:00
|
|
|
form->addRow("Font:", font);
|
2017-02-02 02:46:33 +01:00
|
|
|
form->addRow("", compactTabs);
|
|
|
|
form->addRow("", hidePreferencesButton);
|
|
|
|
form->addRow("", hideUserButton);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-02-02 01:23:26 +01:00
|
|
|
// theme
|
|
|
|
combo->addItem("White");
|
|
|
|
combo->addItem("Light");
|
|
|
|
combo->addItem("Dark");
|
|
|
|
combo->addItem("Black");
|
|
|
|
|
|
|
|
QString theme = settings.theme.get();
|
|
|
|
theme = theme.toLower();
|
|
|
|
|
|
|
|
if (theme == "light") {
|
|
|
|
combo->setCurrentIndex(0);
|
|
|
|
} else if (theme == "white") {
|
|
|
|
combo->setCurrentIndex(1);
|
|
|
|
} else if (theme == "black") {
|
|
|
|
combo->setCurrentIndex(3);
|
|
|
|
} else {
|
|
|
|
combo->setCurrentIndex(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
QObject::connect(combo, &QComboBox::currentTextChanged, this,
|
|
|
|
[this, &settings](const QString &value) {
|
|
|
|
settings.theme.set(value);
|
|
|
|
});
|
|
|
|
|
|
|
|
// theme hue
|
|
|
|
slider->setMinimum(0);
|
|
|
|
slider->setMaximum(1000);
|
|
|
|
|
|
|
|
float hue = settings.themeHue.get();
|
|
|
|
|
|
|
|
slider->setValue(std::min(std::max(hue, (float)0.0), (float)1.0) *
|
|
|
|
1000);
|
|
|
|
|
|
|
|
QObject::connect(slider, &QSlider::valueChanged, this,
|
|
|
|
[this, &settings](int value) {
|
|
|
|
settings.themeHue.set(value / 1000.0);
|
|
|
|
Windows::updateAll();
|
|
|
|
});
|
|
|
|
|
2017-01-03 21:19:33 +01:00
|
|
|
group->setLayout(form);
|
|
|
|
|
|
|
|
vbox->addWidget(group);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto group = new QGroupBox("Messages");
|
|
|
|
|
|
|
|
auto v = new QVBoxLayout();
|
2017-01-22 23:00:35 +01:00
|
|
|
v->addWidget(createCheckbox("Show timestamp", settings.showTimestamps));
|
2017-01-22 12:46:35 +01:00
|
|
|
v->addWidget(createCheckbox("Show seconds in timestamp",
|
2017-01-22 23:00:35 +01:00
|
|
|
settings.showTimestampSeconds));
|
2017-01-11 18:52:09 +01:00
|
|
|
v->addWidget(createCheckbox(
|
2017-01-22 12:46:35 +01:00
|
|
|
"Allow sending duplicate messages (add a space at the end)",
|
2017-01-22 23:00:35 +01:00
|
|
|
settings.allowDouplicateMessages));
|
|
|
|
v->addWidget(
|
|
|
|
createCheckbox("Seperate messages", settings.seperateMessages));
|
|
|
|
v->addWidget(
|
|
|
|
createCheckbox("Show message length", settings.showMessageLength));
|
2017-01-03 21:19:33 +01:00
|
|
|
|
|
|
|
group->setLayout(v);
|
|
|
|
|
|
|
|
vbox->addWidget(group);
|
2017-01-02 03:02:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
vbox->addStretch(1);
|
|
|
|
|
|
|
|
addTab(vbox, "Appearance", ":/images/AppearanceEditorPart_16x.png");
|
|
|
|
|
2017-01-03 21:19:33 +01:00
|
|
|
// Behaviour
|
|
|
|
vbox = new QVBoxLayout();
|
|
|
|
|
2017-01-22 23:00:35 +01:00
|
|
|
vbox->addWidget(
|
|
|
|
createCheckbox("Hide input box if empty", settings.hideEmptyInput));
|
2017-01-22 12:46:35 +01:00
|
|
|
vbox->addWidget(
|
|
|
|
createCheckbox("Mention users with a @ (except in commands)",
|
2017-01-22 23:00:35 +01:00
|
|
|
settings.mentionUsersWithAt));
|
2017-01-11 18:52:09 +01:00
|
|
|
vbox->addWidget(
|
2017-01-22 23:00:35 +01:00
|
|
|
createCheckbox("Window always on top", settings.windowTopMost));
|
2017-01-22 12:46:35 +01:00
|
|
|
vbox->addWidget(createCheckbox("Show last read message indicator",
|
2017-01-22 23:00:35 +01:00
|
|
|
settings.showLastMessageIndicator));
|
2017-01-03 21:19:33 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
auto v = new QVBoxLayout();
|
|
|
|
v->addWidget(new QLabel("Mouse scroll speed"));
|
|
|
|
|
|
|
|
auto scroll = new QSlider(Qt::Horizontal);
|
|
|
|
|
|
|
|
v->addWidget(scroll);
|
|
|
|
v->addStretch(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
vbox->addStretch(1);
|
|
|
|
|
|
|
|
addTab(vbox, "Behaviour", ":/images/AppearanceEditorPart_16x.png");
|
|
|
|
|
2017-01-02 03:02:32 +01:00
|
|
|
// Commands
|
|
|
|
vbox = new QVBoxLayout();
|
|
|
|
|
|
|
|
vbox->addWidget(new QLabel());
|
|
|
|
|
|
|
|
vbox->addStretch(1);
|
|
|
|
|
|
|
|
addTab(vbox, "Commands", ":/images/CustomActionEditor_16x.png");
|
|
|
|
|
2017-01-22 12:46:35 +01:00
|
|
|
// Emotes
|
|
|
|
vbox = new QVBoxLayout();
|
|
|
|
|
|
|
|
vbox->addWidget(
|
2017-01-22 23:00:35 +01:00
|
|
|
createCheckbox("Enable Twitch Emotes", settings.enableTwitchEmotes));
|
2017-01-22 12:46:35 +01:00
|
|
|
vbox->addWidget(
|
2017-01-22 23:00:35 +01:00
|
|
|
createCheckbox("Enable BetterTTV Emotes", settings.enableBttvEmotes));
|
|
|
|
vbox->addWidget(
|
|
|
|
createCheckbox("Enable FrankerFaceZ Emotes", settings.enableFfzEmotes));
|
|
|
|
vbox->addWidget(createCheckbox("Enable Gif Emotes", settings.enableGifs));
|
|
|
|
vbox->addWidget(createCheckbox("Enable Emojis", settings.enableEmojis));
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2017-01-22 23:00:35 +01:00
|
|
|
vbox->addWidget(
|
|
|
|
createCheckbox("Enable Twitch Emotes", settings.enableTwitchEmotes));
|
2017-01-22 12:46:35 +01:00
|
|
|
|
|
|
|
vbox->addStretch(1);
|
|
|
|
addTab(vbox, "Emotes", ":/images/Emoji_Color_1F60A_19.png");
|
|
|
|
|
|
|
|
// Ignored Users
|
|
|
|
vbox = new QVBoxLayout();
|
|
|
|
vbox->addStretch(1);
|
|
|
|
addTab(vbox, "Ignored Users",
|
|
|
|
":/images/StatusAnnotations_Blocked_16xLG_color.png");
|
|
|
|
|
|
|
|
// Ignored Messages
|
|
|
|
vbox = new QVBoxLayout();
|
|
|
|
vbox->addStretch(1);
|
|
|
|
addTab(vbox, "Ignored Messages", ":/images/Filter_16x.png");
|
|
|
|
|
|
|
|
// Links
|
|
|
|
vbox = new QVBoxLayout();
|
|
|
|
vbox->addStretch(1);
|
|
|
|
addTab(vbox, "Links", ":/images/VSO_Link_blue_16x.png");
|
|
|
|
|
2017-01-29 13:23:22 +01:00
|
|
|
// Logging
|
|
|
|
vbox = new QVBoxLayout();
|
|
|
|
vbox->addStretch(1);
|
|
|
|
addTab(vbox, "Logs", ":/images/VSO_Link_blue_16x.png");
|
|
|
|
|
2017-01-22 12:46:35 +01:00
|
|
|
// Highlighting
|
|
|
|
vbox = new QVBoxLayout();
|
|
|
|
vbox->addStretch(1);
|
|
|
|
addTab(vbox, "Highlighting", ":/images/format_Bold_16xLG.png");
|
|
|
|
|
|
|
|
// Whispers
|
|
|
|
vbox = new QVBoxLayout();
|
|
|
|
vbox->addStretch(1);
|
|
|
|
addTab(vbox, "Whispers", ":/images/Message_16xLG.png");
|
|
|
|
|
2017-01-02 03:02:32 +01:00
|
|
|
// Add stretch
|
|
|
|
tabs.addStretch(1);
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
SettingsDialog::addTab(QLayout *layout, QString title, QString imageRes)
|
2017-01-02 03:02:32 +01:00
|
|
|
{
|
|
|
|
auto widget = new QWidget();
|
|
|
|
|
|
|
|
widget->setLayout(layout);
|
|
|
|
|
|
|
|
auto tab = new SettingsDialogTab(this, title, imageRes);
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
tab->setWidget(widget);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
|
|
|
tabs.addWidget(tab, 0, Qt::AlignTop);
|
|
|
|
|
|
|
|
pageStack.addWidget(widget);
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (tabs.count() == 1) {
|
2017-01-02 03:02:32 +01:00
|
|
|
select(tab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
SettingsDialog::select(SettingsDialogTab *tab)
|
2017-01-02 03:02:32 +01:00
|
|
|
{
|
2017-01-18 04:33:30 +01:00
|
|
|
pageStack.setCurrentWidget(tab->getWidget());
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (selectedTab != NULL) {
|
2017-01-02 03:02:32 +01:00
|
|
|
selectedTab->setSelected(false);
|
2017-02-02 00:25:57 +01:00
|
|
|
selectedTab->setStyleSheet("color: #FFF");
|
2017-01-02 03:02:32 +01:00
|
|
|
}
|
2017-01-01 18:43:52 +01:00
|
|
|
|
2017-01-02 03:02:32 +01:00
|
|
|
tab->setSelected(true);
|
2017-02-02 00:25:57 +01:00
|
|
|
tab->setStyleSheet("background: #555; color: #FFF");
|
2017-01-02 03:02:32 +01:00
|
|
|
selectedTab = tab;
|
2017-01-01 18:43:52 +01:00
|
|
|
}
|
2017-01-22 23:00:35 +01:00
|
|
|
|
|
|
|
/// Widget creation helpers
|
|
|
|
QCheckBox *
|
2017-01-24 19:51:57 +01:00
|
|
|
SettingsDialog::createCheckbox(const QString &title, Setting<bool> &setting)
|
2017-01-22 23:00:35 +01:00
|
|
|
{
|
|
|
|
auto checkbox = new QCheckBox(title);
|
|
|
|
|
2017-01-23 09:48:32 +01:00
|
|
|
// Set checkbox initial state
|
|
|
|
checkbox->setChecked(setting.get());
|
|
|
|
|
2017-01-22 23:00:35 +01:00
|
|
|
QObject::connect(checkbox, &QCheckBox::toggled, this,
|
|
|
|
[&setting, this](bool state) { setting.set(state); });
|
|
|
|
|
|
|
|
return checkbox;
|
2017-01-18 21:30:23 +01:00
|
|
|
}
|
2017-01-22 23:00:35 +01:00
|
|
|
|
2017-01-24 19:51:57 +01:00
|
|
|
void
|
|
|
|
SettingsDialog::okButtonClicked()
|
|
|
|
{
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SettingsDialog::cancelButtonClicked()
|
|
|
|
{
|
|
|
|
snapshot.apply();
|
|
|
|
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
2017-01-22 23:00:35 +01:00
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|