2017-06-11 09:31:45 +02:00
|
|
|
#include "widgets/settingsdialog.hpp"
|
2017-12-19 16:13:02 +01:00
|
|
|
#include "const.hpp"
|
2017-12-19 02:47:55 +01:00
|
|
|
#include "debug/log.hpp"
|
2018-01-02 02:15:11 +01:00
|
|
|
#include "singletons/accountmanager.hpp"
|
2018-01-04 04:03:51 +01:00
|
|
|
#include "singletons/commandmanager.hpp"
|
2018-01-02 02:15:11 +01:00
|
|
|
#include "singletons/windowmanager.hpp"
|
2017-07-23 11:59:05 +02:00
|
|
|
#include "twitch/twitchmessagebuilder.hpp"
|
2017-06-11 09:31:45 +02:00
|
|
|
#include "twitch/twitchuser.hpp"
|
2017-11-12 17:21:50 +01:00
|
|
|
#include "widgets/helper/settingsdialogtab.hpp"
|
2017-07-28 19:46:53 +02:00
|
|
|
#include "widgets/logindialog.hpp"
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
#include <QComboBox>
|
2017-06-11 20:53:43 +02:00
|
|
|
#include <QDebug>
|
2017-01-18 04:33:30 +01:00
|
|
|
#include <QFile>
|
2017-07-31 00:57:42 +02:00
|
|
|
#include <QFileDialog>
|
2017-12-18 00:54:17 +01:00
|
|
|
#include <QFont>
|
2017-06-17 11:37:13 +02:00
|
|
|
#include <QFontDialog>
|
2017-01-18 04:33:30 +01:00
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QLabel>
|
2017-04-13 16:06:23 +02:00
|
|
|
#include <QListWidget>
|
2017-01-18 04:33:30 +01:00
|
|
|
#include <QPalette>
|
|
|
|
#include <QResource>
|
2017-07-31 00:57:42 +02:00
|
|
|
#include <QTextEdit>
|
2018-01-02 03:44:52 +01:00
|
|
|
#include <QtSvg>
|
2018-01-07 09:05:41 +01:00
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QGraphicsView>
|
2017-01-01 18:43:52 +01:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2018-01-02 02:15:11 +01:00
|
|
|
SettingsDialog *SettingsDialog::handle = nullptr;
|
|
|
|
|
2017-01-01 18:43:52 +01:00
|
|
|
SettingsDialog::SettingsDialog()
|
2017-12-17 16:45:15 +01:00
|
|
|
: BaseWidget()
|
2017-07-23 11:59:05 +02:00
|
|
|
, usernameDisplayMode(
|
|
|
|
"/appearance/messages/usernameDisplayMode",
|
|
|
|
twitch::TwitchMessageBuilder::UsernameDisplayMode::UsernameAndLocalizedName)
|
2017-01-01 18:43:52 +01:00
|
|
|
{
|
2017-12-17 16:45:15 +01:00
|
|
|
this->initAsWindow();
|
|
|
|
|
2017-01-02 03:02:32 +01:00
|
|
|
QPalette palette;
|
|
|
|
palette.setColor(QPalette::Background, QColor("#444"));
|
2017-07-02 12:36:50 +02:00
|
|
|
this->setPalette(palette);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
this->ui.pageStack.setObjectName("pages");
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
this->setLayout(&this->ui.vbox);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
this->ui.vbox.addLayout(&this->ui.hbox);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
this->ui.vbox.addWidget(&this->ui.buttonBox);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-12-18 00:54:17 +01:00
|
|
|
auto tabWidget = &ui.tabWidget;
|
2017-01-02 03:02:32 +01:00
|
|
|
tabWidget->setObjectName("tabWidget");
|
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
tabWidget->setLayout(&this->ui.tabs);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
this->ui.hbox.addWidget(tabWidget);
|
|
|
|
this->ui.hbox.addLayout(&this->ui.pageStack);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
this->ui.buttonBox.addButton(&this->ui.okButton, QDialogButtonBox::ButtonRole::AcceptRole);
|
|
|
|
this->ui.buttonBox.addButton(&this->ui.cancelButton, QDialogButtonBox::ButtonRole::RejectRole);
|
2017-01-24 19:51:57 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
QObject::connect(&this->ui.okButton, &QPushButton::clicked, this,
|
|
|
|
&SettingsDialog::okButtonClicked);
|
|
|
|
QObject::connect(&this->ui.cancelButton, &QPushButton::clicked, this,
|
2017-01-24 19:51:57 +01:00
|
|
|
&SettingsDialog::cancelButtonClicked);
|
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
this->ui.okButton.setText("OK");
|
|
|
|
this->ui.cancelButton.setText("Cancel");
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
this->resize(600, 500);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
this->addTabs();
|
2017-12-18 00:54:17 +01:00
|
|
|
|
2017-12-18 02:47:01 +01:00
|
|
|
this->dpiMultiplierChanged(this->getDpiMultiplier(), this->getDpiMultiplier());
|
2017-01-02 03:02:32 +01:00
|
|
|
}
|
|
|
|
|
2018-01-02 02:15:11 +01:00
|
|
|
SettingsDialog *SettingsDialog::getHandle()
|
|
|
|
{
|
|
|
|
return SettingsDialog::handle;
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void SettingsDialog::addTabs()
|
2017-01-02 03:02:32 +01:00
|
|
|
{
|
2018-01-02 03:44:52 +01:00
|
|
|
this->addTab(this->createAccountsTab(), "Accounts", ":/images/accounts.svg");
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2018-01-02 03:44:52 +01:00
|
|
|
this->addTab(this->createAppearanceTab(), "Appearance", ":/images/theme.svg");
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2018-01-02 03:44:52 +01:00
|
|
|
this->addTab(this->createBehaviourTab(), "Behaviour", ":/images/behave.svg");
|
2017-04-13 16:06:23 +02:00
|
|
|
|
2018-01-07 02:59:02 +01:00
|
|
|
this->addTab(this->createCommandsTab(), "Commands", ":/images/commands.svg");
|
2017-04-13 16:06:23 +02:00
|
|
|
|
2018-01-02 03:44:52 +01:00
|
|
|
this->addTab(this->createEmotesTab(), "Emotes", ":/images/emote.svg");
|
2017-07-28 19:46:53 +02:00
|
|
|
|
2017-12-19 03:37:07 +01:00
|
|
|
// this->addTab(this->createIgnoredUsersTab(), "Ignored Users",
|
|
|
|
// ":/images/StatusAnnotations_Blocked_16xLG_color.png");
|
2017-07-28 19:46:53 +02:00
|
|
|
|
2017-12-19 03:37:07 +01:00
|
|
|
// this->addTab(this->createIgnoredMessagesTab(), "Ignored Messages",
|
|
|
|
// ":/images/Filter_16x.png");
|
2017-04-13 16:06:23 +02:00
|
|
|
|
2017-12-19 03:37:07 +01:00
|
|
|
// this->addTab(this->createLinksTab(), "Links", ":/images/VSO_Link_blue_16x.png");
|
2017-04-13 16:06:23 +02:00
|
|
|
|
2017-12-19 03:37:07 +01:00
|
|
|
// this->addTab(this->createLogsTab(), "Logs", ":/images/VSO_Link_blue_16x.png");
|
2017-04-13 16:06:23 +02:00
|
|
|
|
2018-01-02 03:44:52 +01:00
|
|
|
this->addTab(this->createHighlightingTab(), "Highlighting", ":/images/notifications.svg");
|
2017-04-13 16:06:23 +02:00
|
|
|
|
2017-12-19 03:37:07 +01:00
|
|
|
// this->addTab(this->createWhispersTab(), "Whispers", ":/images/Message_16xLG.png");
|
2017-04-13 16:06:23 +02:00
|
|
|
|
2018-01-07 09:05:41 +01:00
|
|
|
this->addTab(this->createAboutTab(), "About", ":/images/about.svg");
|
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
// Add stretch
|
|
|
|
this->ui.tabs.addStretch(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
QVBoxLayout *SettingsDialog::createAccountsTab()
|
|
|
|
{
|
|
|
|
auto layout = new QVBoxLayout();
|
|
|
|
|
|
|
|
// add remove buttons
|
|
|
|
auto buttonBox = new QDialogButtonBox(this);
|
|
|
|
|
|
|
|
auto addButton = new QPushButton("Add", this);
|
2017-12-20 00:39:33 +01:00
|
|
|
addButton->setToolTip("Log in with a new account");
|
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
auto removeButton = new QPushButton("Remove", this);
|
2017-12-20 00:39:33 +01:00
|
|
|
removeButton->setToolTip("Remove selected account");
|
2017-10-08 16:31:16 +02:00
|
|
|
|
|
|
|
connect(addButton, &QPushButton::clicked, []() {
|
2017-12-20 00:39:33 +01:00
|
|
|
static auto loginWidget = new LoginWidget();
|
2017-10-08 16:31:16 +02:00
|
|
|
loginWidget->show();
|
|
|
|
});
|
|
|
|
|
|
|
|
buttonBox->addButton(addButton, QDialogButtonBox::YesRole);
|
|
|
|
buttonBox->addButton(removeButton, QDialogButtonBox::NoRole);
|
|
|
|
|
|
|
|
layout->addWidget(buttonBox);
|
|
|
|
|
2017-12-19 02:16:01 +01:00
|
|
|
this->ui.accountSwitchWidget = new AccountSwitchWidget(this);
|
2017-10-08 16:31:16 +02:00
|
|
|
|
2017-12-19 15:12:33 +01:00
|
|
|
connect(removeButton, &QPushButton::clicked, [this]() {
|
|
|
|
auto selectedUser = this->ui.accountSwitchWidget->currentItem()->text();
|
2017-12-19 16:13:02 +01:00
|
|
|
if (selectedUser == ANONYMOUS_USERNAME_LABEL) {
|
2017-12-19 15:12:33 +01:00
|
|
|
// Do nothing
|
|
|
|
return;
|
|
|
|
}
|
2017-12-20 00:39:33 +01:00
|
|
|
|
2017-12-31 22:58:35 +01:00
|
|
|
singletons::AccountManager::getInstance().Twitch.removeUser(selectedUser);
|
2017-12-19 15:12:33 +01:00
|
|
|
});
|
|
|
|
|
2017-12-19 02:16:01 +01:00
|
|
|
layout->addWidget(this->ui.accountSwitchWidget);
|
2017-04-13 16:06:23 +02:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
return layout;
|
|
|
|
}
|
2017-04-13 16:06:23 +02:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
QVBoxLayout *SettingsDialog::createAppearanceTab()
|
|
|
|
{
|
2017-12-31 22:58:35 +01:00
|
|
|
auto &settings = singletons::SettingManager::getInstance();
|
2017-10-08 16:31:16 +02:00
|
|
|
auto layout = this->createTabLayout();
|
2017-01-02 03:02:32 +01:00
|
|
|
|
|
|
|
{
|
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();
|
2017-06-17 11:37:13 +02:00
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
auto fontLayout = new QHBoxLayout();
|
2017-12-17 20:48:15 +01:00
|
|
|
auto fontFamilyLabel = new QLabel("font family, size");
|
2017-06-26 16:41:20 +02:00
|
|
|
auto fontButton = new QPushButton("Select");
|
|
|
|
|
|
|
|
fontLayout->addWidget(fontButton);
|
|
|
|
fontLayout->addWidget(fontFamilyLabel);
|
|
|
|
|
|
|
|
{
|
2017-12-31 22:58:35 +01:00
|
|
|
auto &fontManager = singletons::FontManager::getInstance();
|
2017-06-26 16:41:20 +02:00
|
|
|
|
2017-12-17 21:11:19 +01:00
|
|
|
auto UpdateFontFamilyLabel = [fontFamilyLabel, &fontManager](auto) {
|
|
|
|
fontFamilyLabel->setText(
|
|
|
|
QString::fromStdString(fontManager.currentFontFamily.getValue()) + ", " +
|
|
|
|
QString::number(fontManager.currentFontSize) + "pt");
|
|
|
|
};
|
|
|
|
|
|
|
|
fontManager.currentFontFamily.connectSimple(UpdateFontFamilyLabel,
|
|
|
|
this->managedConnections);
|
|
|
|
fontManager.currentFontSize.connectSimple(UpdateFontFamilyLabel,
|
|
|
|
this->managedConnections);
|
2017-06-26 16:41:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fontButton->connect(fontButton, &QPushButton::clicked, []() {
|
2017-12-31 22:58:35 +01:00
|
|
|
auto &fontManager = singletons::FontManager::getInstance();
|
|
|
|
QFontDialog dialog(fontManager.getFont(singletons::FontManager::Medium, 1.));
|
2017-06-17 11:37:13 +02:00
|
|
|
|
2017-08-12 15:58:46 +02:00
|
|
|
dialog.connect(&dialog, &QFontDialog::fontSelected, [](const QFont &font) {
|
2017-12-31 22:58:35 +01:00
|
|
|
auto &fontManager = singletons::FontManager::getInstance();
|
2017-06-17 11:37:13 +02:00
|
|
|
fontManager.currentFontFamily = font.family().toStdString();
|
|
|
|
fontManager.currentFontSize = font.pointSize();
|
|
|
|
});
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
dialog.exec();
|
|
|
|
});
|
|
|
|
|
2017-02-02 02:46:33 +01:00
|
|
|
auto compactTabs = createCheckbox("Hide tab X", settings.hideTabX);
|
2017-04-12 17:46:44 +02:00
|
|
|
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-06-26 16:41:20 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
auto hbox = new QHBoxLayout();
|
|
|
|
|
|
|
|
auto slider = new QSlider(Qt::Horizontal);
|
|
|
|
// Theme hue
|
|
|
|
slider->setMinimum(0);
|
|
|
|
slider->setMaximum(1000);
|
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
pajlada::Settings::Setting<double> themeHue("/appearance/theme/hue");
|
|
|
|
|
|
|
|
slider->setValue(std::min(std::max(themeHue.getValue(), 0.0), 1.0) * 1000);
|
2017-06-26 16:41:20 +02:00
|
|
|
|
|
|
|
hbox->addWidget(slider);
|
|
|
|
|
|
|
|
auto button = new QPushButton();
|
|
|
|
button->setFlat(true);
|
|
|
|
|
|
|
|
hbox->addWidget(button);
|
|
|
|
|
|
|
|
form->addRow("Theme color:", hbox);
|
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
QObject::connect(slider, &QSlider::valueChanged, this, [button](int value) mutable {
|
|
|
|
double newValue = value / 1000.0;
|
|
|
|
pajlada::Settings::Setting<double> themeHue("/appearance/theme/hue");
|
|
|
|
|
|
|
|
themeHue.setValue(newValue);
|
2017-06-26 16:41:20 +02:00
|
|
|
|
|
|
|
QPalette pal = button->palette();
|
|
|
|
QColor color;
|
2017-07-02 12:36:50 +02:00
|
|
|
color.setHsvF(newValue, 1.0, 1.0, 1.0);
|
2017-06-26 16:41:20 +02:00
|
|
|
pal.setColor(QPalette::Button, color);
|
|
|
|
button->setAutoFillBackground(true);
|
|
|
|
button->setPalette(pal);
|
|
|
|
button->update();
|
|
|
|
|
|
|
|
// TODO(pajlada): re-implement
|
|
|
|
// this->windowManager.updateAll();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
form->addRow("Font:", fontLayout);
|
|
|
|
form->addRow("Tab bar:", compactTabs);
|
2017-02-02 02:46:33 +01:00
|
|
|
form->addRow("", hidePreferencesButton);
|
|
|
|
form->addRow("", hideUserButton);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
{
|
|
|
|
// Theme name
|
|
|
|
combo->addItems({
|
|
|
|
"White", //
|
|
|
|
"Light", //
|
|
|
|
"Dark", //
|
|
|
|
"Black", //
|
|
|
|
});
|
|
|
|
// combo->addItem("White");
|
|
|
|
// combo->addItem("Light");
|
|
|
|
// combo->addItem("Dark");
|
|
|
|
// combo->addItem("Black");
|
2017-02-02 01:23:26 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
QString currentComboText = QString::fromStdString(
|
|
|
|
pajlada::Settings::Setting<std::string>::get("/appearance/theme/name"));
|
2017-02-02 01:23:26 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
combo->setCurrentText(currentComboText);
|
2017-02-02 01:23:26 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
QObject::connect(combo, &QComboBox::currentTextChanged, this, [](const QString &value) {
|
2017-12-19 01:54:51 +01:00
|
|
|
// dirty hack
|
2017-12-31 22:58:35 +01:00
|
|
|
singletons::EmoteManager::getInstance().incGeneration();
|
2017-07-02 12:36:50 +02:00
|
|
|
pajlada::Settings::Setting<std::string>::set("/appearance/theme/name",
|
|
|
|
value.toStdString());
|
|
|
|
});
|
|
|
|
}
|
2017-02-02 01:23:26 +01:00
|
|
|
|
2017-12-18 20:18:20 +01:00
|
|
|
auto enableSmoothScrolling =
|
|
|
|
createCheckbox("Enable smooth scrolling", settings.enableSmoothScrolling);
|
|
|
|
form->addRow("Scrolling:", enableSmoothScrolling);
|
|
|
|
|
2018-01-05 03:14:46 +01:00
|
|
|
auto enableSmoothScrollingNewMessages = createCheckbox(
|
2018-01-05 03:19:41 +01:00
|
|
|
"Enable smooth scrolling for new messages", settings.enableSmoothScrollingNewMessages);
|
2018-01-05 03:14:46 +01:00
|
|
|
form->addRow("", enableSmoothScrollingNewMessages);
|
|
|
|
|
2017-01-03 21:19:33 +01:00
|
|
|
group->setLayout(form);
|
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
layout->addWidget(group);
|
2017-01-03 21:19:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
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-04-12 17:46:44 +02:00
|
|
|
v->addWidget(createCheckbox("Show seconds in timestamp", settings.showTimestampSeconds));
|
2017-06-11 20:53:43 +02:00
|
|
|
v->addWidget(createCheckbox("Show badges", settings.showBadges));
|
2017-04-12 17:46:44 +02:00
|
|
|
v->addWidget(createCheckbox("Allow sending duplicate messages (add a space at the end)",
|
2017-12-17 13:48:02 +01:00
|
|
|
settings.allowDuplicateMessages));
|
2017-04-12 17:46:44 +02:00
|
|
|
v->addWidget(createCheckbox("Seperate messages", settings.seperateMessages));
|
|
|
|
v->addWidget(createCheckbox("Show message length", settings.showMessageLength));
|
2017-07-23 11:59:05 +02:00
|
|
|
v->addLayout(this->createCombobox(
|
|
|
|
"Username display mode", this->usernameDisplayMode,
|
|
|
|
{"Username (Localized name)", "Username", "Localized name"},
|
|
|
|
[](const QString &newValue, pajlada::Settings::Setting<int> &setting) {
|
|
|
|
if (newValue == "Username (Localized name)") {
|
|
|
|
setting =
|
|
|
|
twitch::TwitchMessageBuilder::UsernameDisplayMode::UsernameAndLocalizedName;
|
|
|
|
} else if (newValue == "Username") {
|
|
|
|
setting = twitch::TwitchMessageBuilder::UsernameDisplayMode::Username;
|
|
|
|
} else if (newValue == "Localized name") {
|
|
|
|
setting = twitch::TwitchMessageBuilder::UsernameDisplayMode::LocalizedName;
|
|
|
|
}
|
|
|
|
}));
|
2017-01-03 21:19:33 +01:00
|
|
|
|
|
|
|
group->setLayout(v);
|
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
layout->addWidget(group);
|
2017-01-02 03:02:32 +01:00
|
|
|
}
|
2017-10-08 16:31:16 +02:00
|
|
|
return layout;
|
|
|
|
}
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
QVBoxLayout *SettingsDialog::createBehaviourTab()
|
|
|
|
{
|
2017-12-31 22:58:35 +01:00
|
|
|
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
|
2017-10-08 16:31:16 +02:00
|
|
|
auto layout = this->createTabLayout();
|
|
|
|
|
|
|
|
auto form = new QFormLayout();
|
|
|
|
|
2018-01-05 11:22:51 +01:00
|
|
|
// WINDOW
|
|
|
|
{
|
|
|
|
form->addRow("Window:", createCheckbox("Window always on top (requires restart)",
|
|
|
|
settings.windowTopMost));
|
|
|
|
// form->addRow("Messages:", createCheckbox("Mention users with a @ (except in
|
|
|
|
// commands)",
|
|
|
|
// settings.mentionUsersWithAt));
|
|
|
|
}
|
|
|
|
// MESSAGES
|
|
|
|
{
|
|
|
|
form->addRow("Messages:",
|
|
|
|
createCheckbox("Hide input box if empty", settings.hideEmptyInput));
|
|
|
|
form->addRow("", createCheckbox("Show last read message indicator",
|
|
|
|
settings.showLastMessageIndicator));
|
|
|
|
}
|
|
|
|
// PAUSE
|
|
|
|
{
|
|
|
|
form->addRow("Pause chat:", createCheckbox("When hovering", settings.pauseChatHover));
|
|
|
|
}
|
|
|
|
// MOUSE SCROLL SPEED
|
|
|
|
{
|
|
|
|
auto scroll = new QSlider(Qt::Horizontal);
|
|
|
|
form->addRow("Mouse scroll speed:", scroll);
|
|
|
|
|
|
|
|
float currentValue = singletons::SettingManager::getInstance().mouseScrollMultiplier;
|
|
|
|
int scrollValue = ((currentValue - 0.1f) / 2.f) * 99.f;
|
|
|
|
scroll->setValue(scrollValue);
|
2017-12-19 02:47:55 +01:00
|
|
|
|
2018-01-05 11:22:51 +01:00
|
|
|
connect(scroll, &QSlider::valueChanged, [](int newValue) {
|
|
|
|
float mul = static_cast<float>(newValue) / 99.f;
|
|
|
|
float newScrollValue = (mul * 2.1f) + 0.1f;
|
|
|
|
singletons::SettingManager::getInstance().mouseScrollMultiplier = newScrollValue;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// STREAMLINK
|
|
|
|
{
|
|
|
|
form->addRow("Streamlink path:", createLineEdit(settings.streamlinkPath));
|
|
|
|
form->addRow(this->createCombobox(
|
|
|
|
"Preferred quality:", settings.preferredQuality,
|
|
|
|
{"Choose", "Source", "High", "Medium", "Low", "Audio only"},
|
|
|
|
[](const QString &newValue, pajlada::Settings::Setting<std::string> &setting) {
|
|
|
|
setting = newValue.toStdString();
|
|
|
|
}));
|
|
|
|
}
|
2017-10-08 16:31:16 +02:00
|
|
|
|
|
|
|
layout->addLayout(form);
|
|
|
|
|
|
|
|
return layout;
|
|
|
|
}
|
2017-08-12 14:44:27 +02:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
QVBoxLayout *SettingsDialog::createCommandsTab()
|
|
|
|
{
|
2018-01-04 04:03:51 +01:00
|
|
|
singletons::CommandManager &commandManager = singletons::CommandManager::getInstance();
|
|
|
|
|
|
|
|
this->commandsTextChangedDelay.setSingleShot(true);
|
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
auto layout = this->createTabLayout();
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2018-01-05 11:04:37 +01:00
|
|
|
layout->addWidget(new QLabel("One command per line."));
|
2018-01-04 04:03:51 +01:00
|
|
|
layout->addWidget(new QLabel("\"/cmd example command\" will print "
|
|
|
|
"\"example command\" when you type /cmd in chat."));
|
|
|
|
layout->addWidget(new QLabel("{1} will be replaced with the first word you type after the "
|
|
|
|
"command, {2} with the second and so on."));
|
|
|
|
layout->addWidget(new QLabel("{1+} will be replaced with first word and everything after, {2+} "
|
|
|
|
"with everything after the second word and so on"));
|
|
|
|
layout->addWidget(new QLabel("Duplicate commands will be ignored."));
|
|
|
|
|
|
|
|
QTextEdit *textEdit = new QTextEdit();
|
|
|
|
textEdit->setPlainText(QString(commandManager.getCommands().join('\n')));
|
|
|
|
|
|
|
|
layout->addWidget(textEdit);
|
|
|
|
|
|
|
|
QObject::connect(textEdit, &QTextEdit::textChanged,
|
|
|
|
[this] { this->commandsTextChangedDelay.start(200); });
|
|
|
|
|
|
|
|
QObject::connect(&this->commandsTextChangedDelay, &QTimer::timeout,
|
|
|
|
[textEdit, &commandManager] {
|
|
|
|
QString text = textEdit->toPlainText();
|
|
|
|
QStringList lines = text.split(QRegularExpression("(\r?\n|\r\n?)"));
|
|
|
|
|
|
|
|
commandManager.setCommands(lines);
|
|
|
|
});
|
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
return layout;
|
|
|
|
}
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
QVBoxLayout *SettingsDialog::createEmotesTab()
|
|
|
|
{
|
2017-12-31 22:58:35 +01:00
|
|
|
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
|
2017-10-08 16:31:16 +02:00
|
|
|
auto layout = this->createTabLayout();
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
layout->addWidget(createCheckbox("Enable Twitch Emotes", settings.enableTwitchEmotes));
|
|
|
|
layout->addWidget(createCheckbox("Enable BetterTTV Emotes", settings.enableBttvEmotes));
|
|
|
|
layout->addWidget(createCheckbox("Enable FrankerFaceZ Emotes", settings.enableFfzEmotes));
|
2017-12-17 01:19:56 +01:00
|
|
|
layout->addWidget(createCheckbox("Enable Gif Emotes", settings.enableGifAnimations));
|
2017-10-08 16:31:16 +02:00
|
|
|
layout->addWidget(createCheckbox("Enable Emojis", settings.enableEmojis));
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
layout->addWidget(createCheckbox("Enable Twitch Emotes", settings.enableTwitchEmotes));
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2018-01-07 02:56:45 +01:00
|
|
|
// Preferred emote quality
|
|
|
|
{
|
|
|
|
auto box = new QHBoxLayout();
|
|
|
|
auto label = new QLabel("Preferred emote quality");
|
|
|
|
label->setToolTip("Select which emote quality you prefer to download");
|
|
|
|
auto widget = new QComboBox();
|
|
|
|
widget->addItems({"1x", "2x", "4x"});
|
|
|
|
box->addWidget(label);
|
|
|
|
box->addWidget(widget);
|
|
|
|
|
|
|
|
settings.preferredEmoteQuality.connect([widget](int newIndex, auto) {
|
|
|
|
widget->setCurrentIndex(newIndex); //
|
|
|
|
});
|
|
|
|
|
|
|
|
QObject::connect(
|
|
|
|
widget, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [](int index) {
|
|
|
|
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
|
|
|
|
settings.preferredEmoteQuality = index; //
|
|
|
|
});
|
|
|
|
|
|
|
|
layout->addLayout(box);
|
|
|
|
}
|
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
return layout;
|
|
|
|
}
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2018-01-07 09:05:41 +01:00
|
|
|
QVBoxLayout *SettingsDialog::createAboutTab()
|
|
|
|
{
|
|
|
|
auto layout = this->createTabLayout();
|
|
|
|
QPixmap image;
|
|
|
|
image.load(":/images/aboutlogo.png");
|
|
|
|
auto scene = new QGraphicsScene(this);
|
|
|
|
scene->addPixmap(image);
|
|
|
|
scene->setSceneRect(image.rect());
|
|
|
|
|
|
|
|
QGraphicsView *view = new QGraphicsView(scene);
|
|
|
|
view->setStyleSheet("background: transparent");
|
|
|
|
layout->addWidget(view);
|
|
|
|
|
|
|
|
auto created = new QLabel();
|
|
|
|
created->setText("Twitch Chat Client created by <a href=\"github.com/fourtf\">fourtf</a>");
|
|
|
|
created->setTextFormat(Qt::RichText);
|
|
|
|
created->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
|
|
|
created->setOpenExternalLinks(true);
|
|
|
|
layout->addWidget(created);
|
|
|
|
|
|
|
|
auto github = new QLabel();
|
|
|
|
github->setText("<a href=\"github.com/fourt/chatterino2\">Chatterino on Github</a>");
|
|
|
|
github->setTextFormat(Qt::RichText);
|
|
|
|
github->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
|
|
|
github->setOpenExternalLinks(true);
|
|
|
|
layout->addWidget(github);
|
|
|
|
|
|
|
|
return layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
QVBoxLayout *SettingsDialog::createIgnoredUsersTab()
|
|
|
|
{
|
|
|
|
auto layout = this->createTabLayout();
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
return layout;
|
|
|
|
}
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
QVBoxLayout *SettingsDialog::createIgnoredMessagesTab()
|
|
|
|
{
|
|
|
|
auto layout = this->createTabLayout();
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
return layout;
|
|
|
|
}
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
QVBoxLayout *SettingsDialog::createLinksTab()
|
|
|
|
{
|
|
|
|
auto layout = this->createTabLayout();
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
return layout;
|
|
|
|
}
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
QVBoxLayout *SettingsDialog::createLogsTab()
|
|
|
|
{
|
|
|
|
auto layout = this->createTabLayout();
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
return layout;
|
|
|
|
}
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
QVBoxLayout *SettingsDialog::createHighlightingTab()
|
|
|
|
{
|
2017-12-31 22:58:35 +01:00
|
|
|
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
|
2017-10-08 16:31:16 +02:00
|
|
|
auto layout = this->createTabLayout();
|
2017-01-29 13:23:22 +01:00
|
|
|
|
2017-07-31 00:37:22 +02:00
|
|
|
auto highlights = new QListWidget();
|
2017-09-23 19:23:10 +02:00
|
|
|
auto highlightUserBlacklist = new QTextEdit();
|
2017-07-31 00:37:22 +02:00
|
|
|
globalHighlights = highlights;
|
2018-01-04 01:52:37 +01:00
|
|
|
const auto highlightProperties = settings.highlightProperties.getValue();
|
|
|
|
for (const auto &highlightProperty : highlightProperties) {
|
|
|
|
highlights->addItem(highlightProperty.key);
|
|
|
|
}
|
2018-01-04 02:19:35 +01:00
|
|
|
highlightUserBlacklist->setText(settings.highlightUserBlacklist);
|
2017-09-23 19:23:10 +02:00
|
|
|
auto highlightTab = new QTabWidget();
|
2017-07-31 00:37:22 +02:00
|
|
|
auto customSound = new QHBoxLayout();
|
|
|
|
auto soundForm = new QFormLayout();
|
|
|
|
{
|
2017-10-08 16:31:16 +02:00
|
|
|
layout->addWidget(createCheckbox("Enable Highlighting", settings.enableHighlights));
|
|
|
|
layout->addWidget(createCheckbox("Highlight messages containing your name",
|
|
|
|
settings.enableHighlightsSelf));
|
|
|
|
layout->addWidget(createCheckbox("Play sound when your name is mentioned",
|
|
|
|
settings.enableHighlightSound));
|
|
|
|
layout->addWidget(createCheckbox("Flash taskbar when your name is mentioned",
|
|
|
|
settings.enableHighlightTaskbar));
|
2017-07-31 00:37:22 +02:00
|
|
|
customSound->addWidget(createCheckbox("Custom sound", settings.customHighlightSound));
|
|
|
|
auto selectBtn = new QPushButton("Select");
|
2017-07-31 00:57:42 +02:00
|
|
|
QObject::connect(selectBtn, &QPushButton::clicked, this, [&settings, this] {
|
|
|
|
auto fileName = QFileDialog::getOpenFileName(this, tr("Open Sound"), "",
|
2017-07-31 01:36:33 +02:00
|
|
|
tr("Audio Files (*.mp3 *.wav)"));
|
2018-01-04 02:19:35 +01:00
|
|
|
settings.pathHighlightSound = fileName;
|
2017-07-31 00:37:22 +02:00
|
|
|
});
|
|
|
|
customSound->addWidget(selectBtn);
|
|
|
|
}
|
|
|
|
|
|
|
|
soundForm->addRow(customSound);
|
|
|
|
|
|
|
|
{
|
2017-07-31 00:57:42 +02:00
|
|
|
auto hbox = new QHBoxLayout();
|
|
|
|
auto addBtn = new QPushButton("Add");
|
|
|
|
auto editBtn = new QPushButton("Edit");
|
|
|
|
auto delBtn = new QPushButton("Remove");
|
|
|
|
|
2018-01-04 01:52:37 +01:00
|
|
|
// Open "Add new highlight" dialog
|
2017-07-31 00:57:42 +02:00
|
|
|
QObject::connect(addBtn, &QPushButton::clicked, this, [highlights, this, &settings] {
|
|
|
|
auto show = new QWidget();
|
|
|
|
auto box = new QBoxLayout(QBoxLayout::TopToBottom);
|
|
|
|
|
|
|
|
auto edit = new QLineEdit();
|
|
|
|
auto add = new QPushButton("Add");
|
|
|
|
|
|
|
|
auto sound = new QCheckBox("Play sound");
|
|
|
|
auto task = new QCheckBox("Flash taskbar");
|
|
|
|
|
2018-01-04 01:52:37 +01:00
|
|
|
// Save highlight
|
2017-07-31 00:57:42 +02:00
|
|
|
QObject::connect(add, &QPushButton::clicked, this, [=, &settings] {
|
|
|
|
if (edit->text().length()) {
|
2018-01-04 01:52:37 +01:00
|
|
|
QString highlightKey = edit->text();
|
|
|
|
highlights->addItem(highlightKey);
|
|
|
|
|
|
|
|
auto properties = settings.highlightProperties.getValue();
|
|
|
|
|
|
|
|
messages::HighlightPhrase newHighlightProperty;
|
|
|
|
newHighlightProperty.key = highlightKey;
|
|
|
|
newHighlightProperty.sound = sound->isChecked();
|
|
|
|
newHighlightProperty.alert = task->isChecked();
|
|
|
|
|
|
|
|
properties.push_back(newHighlightProperty);
|
|
|
|
|
|
|
|
settings.highlightProperties = properties;
|
|
|
|
|
2017-07-31 00:57:42 +02:00
|
|
|
show->close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
box->addWidget(edit);
|
|
|
|
box->addWidget(add);
|
|
|
|
box->addWidget(sound);
|
|
|
|
box->addWidget(task);
|
|
|
|
show->setLayout(box);
|
|
|
|
show->show();
|
|
|
|
});
|
2018-01-04 01:52:37 +01:00
|
|
|
|
|
|
|
// Open "Edit selected highlight" dialog
|
2017-07-31 00:57:42 +02:00
|
|
|
QObject::connect(editBtn, &QPushButton::clicked, this, [highlights, this, &settings] {
|
2018-01-04 01:52:37 +01:00
|
|
|
if (highlights->selectedItems().isEmpty()) {
|
|
|
|
// No item selected
|
|
|
|
return;
|
2017-07-31 00:37:22 +02:00
|
|
|
}
|
2018-01-04 01:52:37 +01:00
|
|
|
|
|
|
|
QListWidgetItem *selectedHighlight = highlights->selectedItems().first();
|
|
|
|
QString highlightKey = selectedHighlight->text();
|
|
|
|
auto properties = settings.highlightProperties.getValue();
|
|
|
|
auto highlightIt = std::find_if(properties.begin(), properties.end(),
|
|
|
|
[highlightKey](const auto &highlight) {
|
|
|
|
return highlight.key == highlightKey; //
|
|
|
|
});
|
|
|
|
|
|
|
|
if (highlightIt == properties.end()) {
|
|
|
|
debug::Log("Unable to find highlight key {} in highlight properties. "
|
|
|
|
"This is weird",
|
|
|
|
highlightKey);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
messages::HighlightPhrase &selectedSetting = *highlightIt;
|
|
|
|
auto show = new QWidget();
|
|
|
|
auto box = new QBoxLayout(QBoxLayout::TopToBottom);
|
|
|
|
|
|
|
|
auto edit = new QLineEdit(highlightKey);
|
|
|
|
auto apply = new QPushButton("Apply");
|
|
|
|
|
|
|
|
auto sound = new QCheckBox("Play sound");
|
|
|
|
sound->setChecked(selectedSetting.sound);
|
|
|
|
auto task = new QCheckBox("Flash taskbar");
|
|
|
|
task->setChecked(selectedSetting.alert);
|
|
|
|
|
|
|
|
// Apply edited changes
|
|
|
|
QObject::connect(apply, &QPushButton::clicked, this, [=, &settings] {
|
|
|
|
QString newHighlightKey = edit->text();
|
|
|
|
|
|
|
|
if (newHighlightKey.length() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto properties = settings.highlightProperties.getValue();
|
|
|
|
auto highlightIt =
|
|
|
|
std::find_if(properties.begin(), properties.end(), [=](const auto &highlight) {
|
|
|
|
return highlight.key == highlightKey; //
|
|
|
|
});
|
|
|
|
|
|
|
|
if (highlightIt == properties.end()) {
|
|
|
|
debug::Log("Unable to find highlight key {} in highlight properties. "
|
|
|
|
"This is weird",
|
|
|
|
highlightKey);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto &highlightProperty = *highlightIt;
|
|
|
|
highlightProperty.key = newHighlightKey;
|
|
|
|
highlightProperty.sound = sound->isCheckable();
|
|
|
|
highlightProperty.alert = task->isCheckable();
|
|
|
|
|
|
|
|
settings.highlightProperties = properties;
|
|
|
|
|
|
|
|
selectedHighlight->setText(newHighlightKey);
|
|
|
|
|
|
|
|
show->close();
|
|
|
|
});
|
|
|
|
|
|
|
|
box->addWidget(edit);
|
|
|
|
box->addWidget(apply);
|
|
|
|
box->addWidget(sound);
|
|
|
|
box->addWidget(task);
|
|
|
|
show->setLayout(box);
|
|
|
|
show->show();
|
2017-07-31 00:37:22 +02:00
|
|
|
});
|
2018-01-04 01:52:37 +01:00
|
|
|
|
|
|
|
// Delete selected highlight
|
2017-07-31 00:57:42 +02:00
|
|
|
QObject::connect(delBtn, &QPushButton::clicked, this, [highlights, &settings] {
|
2018-01-04 01:52:37 +01:00
|
|
|
if (highlights->selectedItems().isEmpty()) {
|
|
|
|
// No highlight selected
|
|
|
|
return;
|
2017-07-31 00:37:22 +02:00
|
|
|
}
|
2018-01-04 01:52:37 +01:00
|
|
|
|
|
|
|
QListWidgetItem *selectedHighlight = highlights->selectedItems().first();
|
|
|
|
QString highlightKey = selectedHighlight->text();
|
|
|
|
|
|
|
|
auto properties = settings.highlightProperties.getValue();
|
|
|
|
properties.erase(std::remove_if(properties.begin(), properties.end(),
|
|
|
|
[highlightKey](const auto &highlight) {
|
|
|
|
return highlight.key == highlightKey; //
|
|
|
|
}),
|
|
|
|
properties.end());
|
|
|
|
|
|
|
|
settings.highlightProperties = properties;
|
|
|
|
|
|
|
|
delete selectedHighlight;
|
2017-07-31 00:37:22 +02:00
|
|
|
});
|
2018-01-04 01:52:37 +01:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
layout->addLayout(soundForm);
|
|
|
|
layout->addWidget(
|
2017-10-08 15:58:28 +02:00
|
|
|
createCheckbox("Always play highlight sound (Even if Chatterino is focused)",
|
|
|
|
settings.highlightAlwaysPlaySound));
|
2017-09-23 19:23:10 +02:00
|
|
|
auto layoutVbox = new QVBoxLayout();
|
|
|
|
auto btnHbox = new QHBoxLayout();
|
|
|
|
|
|
|
|
auto highlightWidget = new QWidget();
|
|
|
|
auto btnWidget = new QWidget();
|
|
|
|
|
|
|
|
btnHbox->addWidget(addBtn);
|
|
|
|
btnHbox->addWidget(editBtn);
|
|
|
|
btnHbox->addWidget(delBtn);
|
|
|
|
btnWidget->setLayout(btnHbox);
|
|
|
|
|
|
|
|
layoutVbox->addWidget(highlights);
|
|
|
|
layoutVbox->addWidget(btnWidget);
|
|
|
|
highlightWidget->setLayout(layoutVbox);
|
2017-07-31 00:37:22 +02:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
highlightTab->addTab(highlightWidget, "Highlights");
|
|
|
|
highlightTab->addTab(highlightUserBlacklist, "Disabled Users");
|
|
|
|
layout->addWidget(highlightTab);
|
2017-07-31 00:37:22 +02:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
layout->addLayout(hbox);
|
2017-07-31 00:37:22 +02:00
|
|
|
}
|
2017-09-23 19:23:10 +02:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
QObject::connect(&this->ui.okButton, &QPushButton::clicked, this, [=, &settings]() {
|
|
|
|
QStringList list =
|
|
|
|
highlightUserBlacklist->toPlainText().split("\n", QString::SkipEmptyParts);
|
2017-09-23 19:23:10 +02:00
|
|
|
list.removeDuplicates();
|
2018-01-04 02:19:35 +01:00
|
|
|
settings.highlightUserBlacklist = list.join("\n") + "\n";
|
2017-09-23 19:23:10 +02:00
|
|
|
});
|
|
|
|
|
2018-01-04 02:19:35 +01:00
|
|
|
settings.highlightUserBlacklist.connect([=](const QString &str, auto) {
|
|
|
|
highlightUserBlacklist->setPlainText(str); //
|
|
|
|
});
|
2017-09-23 19:23:10 +02:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
return layout;
|
|
|
|
}
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
QVBoxLayout *SettingsDialog::createWhispersTab()
|
|
|
|
{
|
|
|
|
auto layout = this->createTabLayout();
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
return layout;
|
2017-01-02 03:02:32 +01:00
|
|
|
}
|
|
|
|
|
2017-10-08 16:31:16 +02:00
|
|
|
void SettingsDialog::addTab(QBoxLayout *layout, QString title, QString imageRes)
|
2017-01-02 03:02:32 +01:00
|
|
|
{
|
2017-10-08 16:31:16 +02:00
|
|
|
layout->addStretch(1);
|
|
|
|
|
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
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
this->ui.tabs.addWidget(tab, 0, Qt::AlignTop);
|
2017-12-18 00:54:17 +01:00
|
|
|
tabs.push_back(tab);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
this->ui.pageStack.addWidget(widget);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
if (this->ui.tabs.count() == 1) {
|
|
|
|
this->select(tab);
|
2017-01-02 03:02:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void SettingsDialog::select(SettingsDialogTab *tab)
|
2017-01-02 03:02:32 +01:00
|
|
|
{
|
2017-07-02 12:36:50 +02:00
|
|
|
this->ui.pageStack.setCurrentWidget(tab->getWidget());
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
if (this->selectedTab != nullptr) {
|
|
|
|
this->selectedTab->setSelected(false);
|
|
|
|
this->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-07-02 12:36:50 +02:00
|
|
|
this->selectedTab = tab;
|
2017-01-01 18:43:52 +01:00
|
|
|
}
|
2017-01-22 23:00:35 +01:00
|
|
|
|
2017-12-19 02:16:01 +01:00
|
|
|
void SettingsDialog::showDialog(PreferredTab preferredTab)
|
2017-05-27 15:40:06 +02:00
|
|
|
{
|
|
|
|
static SettingsDialog *instance = new SettingsDialog();
|
2017-12-19 02:16:01 +01:00
|
|
|
instance->refresh();
|
|
|
|
|
|
|
|
switch (preferredTab) {
|
|
|
|
case SettingsDialog::PreferredTab::Accounts: {
|
|
|
|
instance->select(instance->tabs.at(0));
|
|
|
|
} break;
|
|
|
|
}
|
2017-05-27 15:40:06 +02:00
|
|
|
|
|
|
|
instance->show();
|
|
|
|
instance->activateWindow();
|
|
|
|
instance->raise();
|
|
|
|
instance->setFocus();
|
|
|
|
}
|
|
|
|
|
2017-12-19 02:16:01 +01:00
|
|
|
void SettingsDialog::refresh()
|
|
|
|
{
|
|
|
|
this->ui.accountSwitchWidget->refresh();
|
2017-12-28 19:03:52 +01:00
|
|
|
|
2017-12-31 22:58:35 +01:00
|
|
|
singletons::SettingManager::getInstance().saveSnapshot();
|
2017-12-19 02:16:01 +01:00
|
|
|
}
|
|
|
|
|
2017-12-18 02:47:01 +01:00
|
|
|
void SettingsDialog::dpiMultiplierChanged(float oldDpi, float newDpi)
|
2017-12-18 00:54:17 +01:00
|
|
|
{
|
|
|
|
QFile file(":/qss/settings.qss");
|
|
|
|
file.open(QFile::ReadOnly);
|
|
|
|
QString styleSheet = QLatin1String(file.readAll());
|
|
|
|
styleSheet.replace("<font-size>", QString::number((int)(14 * newDpi)));
|
|
|
|
styleSheet.replace("<checkbox-size>", QString::number((int)(14 * newDpi)));
|
|
|
|
|
|
|
|
for (SettingsDialogTab *tab : this->tabs) {
|
|
|
|
tab->setFixedHeight((int)(30 * newDpi));
|
|
|
|
}
|
|
|
|
|
|
|
|
this->setStyleSheet(styleSheet);
|
|
|
|
|
|
|
|
this->ui.tabWidget.setFixedWidth((int)(200 * newDpi));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::setChildrensFont(QLayout *object, QFont &font, int indent)
|
|
|
|
{
|
|
|
|
// for (QWidget *widget : this->widgets) {
|
|
|
|
// widget->setFont(font);
|
|
|
|
// }
|
|
|
|
// for (int i = 0; i < object->count(); i++) {
|
|
|
|
// if (object->itemAt(i)->layout()) {
|
|
|
|
// setChildrensFont(object->layout()->itemAt(i)->layout(), font, indent + 2);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (object->itemAt(i)->widget()) {
|
|
|
|
// object->itemAt(i)->widget()->setFont(font);
|
|
|
|
|
|
|
|
// if (object->itemAt(i)->widget()->layout() &&
|
|
|
|
// !object->itemAt(i)->widget()->layout()->isEmpty()) {
|
|
|
|
// setChildrensFont(object->itemAt(i)->widget()->layout(), font, indent + 2);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
2017-01-22 23:00:35 +01:00
|
|
|
/// Widget creation helpers
|
2017-10-08 16:31:16 +02:00
|
|
|
QVBoxLayout *SettingsDialog::createTabLayout()
|
|
|
|
{
|
|
|
|
auto layout = new QVBoxLayout();
|
|
|
|
|
|
|
|
return layout;
|
|
|
|
}
|
|
|
|
|
2017-06-11 20:53:43 +02:00
|
|
|
QCheckBox *SettingsDialog::createCheckbox(const QString &title,
|
|
|
|
pajlada::Settings::Setting<bool> &setting)
|
|
|
|
{
|
|
|
|
auto checkbox = new QCheckBox(title);
|
|
|
|
|
|
|
|
// Set checkbox initial state
|
2017-12-28 19:03:52 +01:00
|
|
|
setting.connect([checkbox](const bool &value, auto) {
|
|
|
|
checkbox->setChecked(value); //
|
|
|
|
});
|
2017-06-11 20:53:43 +02:00
|
|
|
|
|
|
|
QObject::connect(checkbox, &QCheckBox::toggled, this, [&setting](bool state) {
|
|
|
|
qDebug() << "update checkbox value";
|
|
|
|
setting = state; //
|
|
|
|
});
|
|
|
|
|
|
|
|
return checkbox;
|
|
|
|
}
|
|
|
|
|
2017-07-23 11:59:05 +02:00
|
|
|
QHBoxLayout *SettingsDialog::createCombobox(
|
|
|
|
const QString &title, pajlada::Settings::Setting<int> &setting, QStringList items,
|
|
|
|
std::function<void(QString, pajlada::Settings::Setting<int> &)> cb)
|
|
|
|
{
|
|
|
|
auto box = new QHBoxLayout();
|
|
|
|
auto label = new QLabel(title);
|
|
|
|
auto widget = new QComboBox();
|
|
|
|
widget->addItems(items);
|
|
|
|
|
|
|
|
QObject::connect(widget, &QComboBox::currentTextChanged, this,
|
|
|
|
[&setting, cb](const QString &newValue) {
|
|
|
|
cb(newValue, setting); //
|
|
|
|
});
|
|
|
|
|
|
|
|
box->addWidget(label);
|
2017-09-11 23:35:59 +02:00
|
|
|
box->addWidget(widget);
|
|
|
|
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
|
|
|
QHBoxLayout *SettingsDialog::createCombobox(
|
|
|
|
const QString &title, pajlada::Settings::Setting<std::string> &setting, QStringList items,
|
|
|
|
std::function<void(QString, pajlada::Settings::Setting<std::string> &)> cb)
|
|
|
|
{
|
|
|
|
auto box = new QHBoxLayout();
|
|
|
|
auto label = new QLabel(title);
|
|
|
|
auto widget = new QComboBox();
|
|
|
|
widget->addItems(items);
|
|
|
|
widget->setCurrentText(QString::fromStdString(setting.getValue()));
|
|
|
|
|
|
|
|
QObject::connect(widget, &QComboBox::currentTextChanged, this,
|
|
|
|
[&setting, cb](const QString &newValue) {
|
|
|
|
cb(newValue, setting); //
|
|
|
|
});
|
|
|
|
|
|
|
|
box->addWidget(label);
|
2017-07-23 11:59:05 +02:00
|
|
|
box->addWidget(widget);
|
|
|
|
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
2017-08-12 14:44:27 +02:00
|
|
|
QLineEdit *SettingsDialog::createLineEdit(pajlada::Settings::Setting<std::string> &setting)
|
|
|
|
{
|
|
|
|
auto widget = new QLineEdit(QString::fromStdString(setting.getValue()));
|
|
|
|
|
|
|
|
QObject::connect(widget, &QLineEdit::textChanged, this,
|
2017-08-12 15:58:46 +02:00
|
|
|
[&setting](const QString &newValue) { setting = newValue.toStdString(); });
|
2017-08-12 14:44:27 +02:00
|
|
|
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void SettingsDialog::okButtonClicked()
|
2017-01-24 19:51:57 +01:00
|
|
|
{
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void SettingsDialog::cancelButtonClicked()
|
2017-01-24 19:51:57 +01:00
|
|
|
{
|
2017-12-31 22:58:35 +01:00
|
|
|
auto &settings = singletons::SettingManager::getInstance();
|
2017-07-31 00:37:22 +02:00
|
|
|
|
2017-12-28 19:03:52 +01:00
|
|
|
settings.recallSnapshot();
|
2017-07-31 00:37:22 +02:00
|
|
|
|
2017-01-24 19:51:57 +01:00
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|