2018-06-26 15:11:45 +02:00
|
|
|
#include "widgets/dialogs/SettingsDialog.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
|
|
|
|
#include "Application.hpp"
|
|
|
|
#include "util/LayoutCreator.hpp"
|
|
|
|
#include "widgets/helper/SettingsDialogTab.hpp"
|
|
|
|
#include "widgets/settingspages/AboutPage.hpp"
|
|
|
|
#include "widgets/settingspages/AccountsPage.hpp"
|
2018-08-19 16:20:14 +02:00
|
|
|
#include "widgets/settingspages/AdvancedPage.hpp"
|
2018-06-26 17:42:35 +02:00
|
|
|
#include "widgets/settingspages/BrowserExtensionPage.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/settingspages/CommandPage.hpp"
|
|
|
|
#include "widgets/settingspages/EmotesPage.hpp"
|
2018-06-26 17:42:35 +02:00
|
|
|
#include "widgets/settingspages/ExternalToolsPage.hpp"
|
2018-07-03 17:39:20 +02:00
|
|
|
#include "widgets/settingspages/FeelPage.hpp"
|
2018-10-31 19:45:51 +01:00
|
|
|
#include "widgets/settingspages/GeneralPage.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/settingspages/HighlightingPage.hpp"
|
2018-07-05 16:45:34 +02:00
|
|
|
#include "widgets/settingspages/IgnoresPage.hpp"
|
2018-06-26 17:42:35 +02:00
|
|
|
#include "widgets/settingspages/KeyboardSettingsPage.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/settingspages/LogsPage.hpp"
|
2018-07-03 17:39:20 +02:00
|
|
|
#include "widgets/settingspages/LookPage.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/settingspages/ModerationPage.hpp"
|
2018-08-09 15:41:03 +02:00
|
|
|
#include "widgets/settingspages/NotificationPage.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/settingspages/SpecialChannelsPage.hpp"
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2018-01-12 23:33:04 +01:00
|
|
|
#include <QDialogButtonBox>
|
2017-01-01 18:43:52 +01:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
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()
|
2018-06-11 15:04:54 +02:00
|
|
|
: BaseWindow(nullptr, BaseWindow::DisableCustomScaling)
|
2017-01-01 18:43:52 +01:00
|
|
|
{
|
2018-01-12 23:09:05 +01:00
|
|
|
this->initUi();
|
2017-07-02 12:36:50 +02:00
|
|
|
this->addTabs();
|
2017-12-18 00:54:17 +01:00
|
|
|
|
2018-11-21 21:37:41 +01:00
|
|
|
this->scaleChangedEvent(this->scale());
|
2018-07-03 16:55:02 +02:00
|
|
|
|
2018-10-31 20:57:29 +01:00
|
|
|
this->overrideBackgroundColor_ = QColor("#111111");
|
2018-09-04 22:29:21 +02:00
|
|
|
this->themeChangedEvent();
|
2018-10-31 19:45:51 +01:00
|
|
|
|
|
|
|
this->resize(766, 600);
|
2017-01-02 03:02:32 +01:00
|
|
|
}
|
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
void SettingsDialog::initUi()
|
2017-10-08 16:31:16 +02:00
|
|
|
{
|
2018-06-26 17:06:17 +02:00
|
|
|
LayoutCreator<SettingsDialog> layoutCreator(this);
|
2017-04-13 16:06:23 +02:00
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
// tab pages
|
2018-10-31 19:45:51 +01:00
|
|
|
layoutCreator.setLayoutType<QHBoxLayout>()
|
|
|
|
.withoutSpacing()
|
|
|
|
.emplace<QWidget>()
|
2018-06-11 15:04:54 +02:00
|
|
|
.assign(&this->ui_.tabContainerContainer)
|
2018-01-12 23:09:05 +01:00
|
|
|
.emplace<QVBoxLayout>()
|
|
|
|
.withoutMargin()
|
2018-06-11 15:04:54 +02:00
|
|
|
.assign(&this->ui_.tabContainer);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2018-10-31 19:45:51 +01:00
|
|
|
this->ui_.tabContainerContainer->layout()->setContentsMargins(8, 8, 0, 8);
|
|
|
|
|
|
|
|
this->layout()->setSpacing(0);
|
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
// right side layout
|
2018-01-13 02:00:02 +01:00
|
|
|
auto right = layoutCreator.emplace<QVBoxLayout>().withoutMargin();
|
2017-01-02 03:02:32 +01:00
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
right.emplace<QStackedLayout>()
|
|
|
|
.assign(&this->ui_.pageStack)
|
|
|
|
.withoutMargin();
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
auto buttons = right.emplace<QDialogButtonBox>(Qt::Horizontal);
|
2017-07-02 12:36:50 +02:00
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
this->ui_.okButton =
|
|
|
|
buttons->addButton("Ok", QDialogButtonBox::YesRole);
|
|
|
|
this->ui_.cancelButton =
|
|
|
|
buttons->addButton("Cancel", QDialogButtonBox::NoRole);
|
2017-07-02 12:36:50 +02:00
|
|
|
}
|
2018-01-05 11:22:51 +01:00
|
|
|
}
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2018-10-31 19:45:51 +01:00
|
|
|
this->ui_.pageStack->setMargin(0);
|
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
// ---- misc
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.tabContainerContainer->setObjectName("tabWidget");
|
|
|
|
this->ui_.pageStack->setObjectName("pages");
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
QObject::connect(this->ui_.okButton, &QPushButton::clicked, this,
|
|
|
|
&SettingsDialog::onOkClicked);
|
2018-06-11 15:04:54 +02:00
|
|
|
QObject::connect(this->ui_.cancelButton, &QPushButton::clicked, this,
|
2018-07-06 19:23:47 +02:00
|
|
|
&SettingsDialog::onCancelClicked);
|
2017-10-08 16:31:16 +02:00
|
|
|
}
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
SettingsDialog *SettingsDialog::getHandle()
|
2017-10-08 16:31:16 +02:00
|
|
|
{
|
2018-01-12 23:09:05 +01:00
|
|
|
return SettingsDialog::handle;
|
2017-10-08 16:31:16 +02:00
|
|
|
}
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
void SettingsDialog::addTabs()
|
2017-10-08 16:31:16 +02:00
|
|
|
{
|
2018-10-31 19:45:51 +01:00
|
|
|
this->ui_.tabContainer->setMargin(0);
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.tabContainer->setSpacing(0);
|
2018-01-24 15:34:04 +01:00
|
|
|
|
2018-10-31 20:57:29 +01:00
|
|
|
this->ui_.tabContainer->addSpacing(16);
|
|
|
|
|
2018-10-31 19:45:51 +01:00
|
|
|
this->addTab(new GeneralPage);
|
2018-04-25 20:35:32 +02:00
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.tabContainer->addSpacing(16);
|
2018-04-25 20:35:32 +02:00
|
|
|
|
2018-10-31 19:45:51 +01:00
|
|
|
this->addTab(new AccountsPage);
|
|
|
|
|
|
|
|
// this->ui_.tabContainer->addSpacing(16);
|
|
|
|
|
|
|
|
// this->addTab(new LookPage);
|
|
|
|
// this->addTab(new FeelPage);
|
2018-04-25 20:35:32 +02:00
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.tabContainer->addSpacing(16);
|
2018-04-25 20:35:32 +02:00
|
|
|
|
2018-06-26 17:06:17 +02:00
|
|
|
this->addTab(new CommandPage);
|
|
|
|
// this->addTab(new EmotesPage);
|
|
|
|
this->addTab(new HighlightingPage);
|
2018-07-05 16:22:25 +02:00
|
|
|
this->addTab(new IgnoresPage);
|
2018-01-24 15:34:04 +01:00
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.tabContainer->addSpacing(16);
|
2018-01-24 15:34:04 +01:00
|
|
|
|
2018-06-26 17:06:17 +02:00
|
|
|
this->addTab(new KeyboardSettingsPage);
|
|
|
|
// this->addTab(new LogsPage);
|
2018-10-21 15:32:28 +02:00
|
|
|
this->addTab(this->ui_.moderationPage = new ModerationPage);
|
2018-08-09 15:41:03 +02:00
|
|
|
this->addTab(new NotificationPage);
|
2018-06-26 17:06:17 +02:00
|
|
|
// this->addTab(new SpecialChannelsPage);
|
2018-10-31 19:45:51 +01:00
|
|
|
// this->addTab(new BrowserExtensionPage);
|
2018-06-26 17:06:17 +02:00
|
|
|
this->addTab(new ExternalToolsPage);
|
2018-08-19 16:20:14 +02:00
|
|
|
this->addTab(new AdvancedPage);
|
2018-01-23 23:10:27 +01:00
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.tabContainer->addStretch(1);
|
2018-06-26 17:06:17 +02:00
|
|
|
this->addTab(new AboutPage, Qt::AlignBottom);
|
2017-01-02 03:02:32 +01:00
|
|
|
}
|
|
|
|
|
2018-06-26 17:06:17 +02:00
|
|
|
void SettingsDialog::addTab(SettingsPage *page, Qt::Alignment alignment)
|
2017-01-02 03:02:32 +01:00
|
|
|
{
|
2018-01-13 00:18:18 +01:00
|
|
|
auto tab = new SettingsDialogTab(this, page, page->getIconResource());
|
2018-10-21 15:32:28 +02:00
|
|
|
page->setTab(tab);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.pageStack->addWidget(page);
|
|
|
|
this->ui_.tabContainer->addWidget(tab, 0, alignment);
|
2018-07-06 19:23:47 +02:00
|
|
|
this->tabs_.push_back(tab);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->tabs_.size() == 1)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->selectTab(tab);
|
2017-01-02 03:02:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
void SettingsDialog::selectTab(SettingsDialogTab *tab)
|
2017-01-02 03:02:32 +01:00
|
|
|
{
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.pageStack->setCurrentWidget(tab->getSettingsPage());
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->selectedTab_ != nullptr)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
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);
|
2018-10-31 20:57:29 +01:00
|
|
|
tab->setStyleSheet("background: #222; color: #4FC3F7;"
|
|
|
|
"border-left: 1px solid #444;"
|
|
|
|
"border-top: 1px solid #444;"
|
|
|
|
"border-bottom: 1px solid #444;");
|
2018-07-06 19:23:47 +02:00
|
|
|
this->selectedTab_ = tab;
|
2017-01-01 18:43:52 +01:00
|
|
|
}
|
2017-01-22 23:00:35 +01:00
|
|
|
|
2018-10-21 15:32:28 +02:00
|
|
|
void SettingsDialog::selectPage(SettingsPage *page)
|
|
|
|
{
|
|
|
|
assert(page);
|
|
|
|
assert(page->tab());
|
|
|
|
|
|
|
|
this->selectTab(page->tab());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::showDialog(SettingsDialogPreference preferredTab)
|
2017-05-27 15:40:06 +02:00
|
|
|
{
|
|
|
|
static SettingsDialog *instance = new SettingsDialog();
|
2017-12-19 02:16:01 +01:00
|
|
|
instance->refresh();
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
switch (preferredTab)
|
|
|
|
{
|
2018-10-21 15:32:28 +02:00
|
|
|
case SettingsDialogPreference::Accounts:
|
2018-07-06 19:23:47 +02:00
|
|
|
instance->selectTab(instance->tabs_.at(0));
|
2018-10-21 15:32:28 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SettingsDialogPreference::ModerationActions:
|
|
|
|
instance->selectPage(instance->ui_.moderationPage);
|
|
|
|
instance->ui_.moderationPage->selectModerationActions();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:;
|
2017-12-19 02:16:01 +01:00
|
|
|
}
|
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()
|
|
|
|
{
|
2018-08-12 12:56:28 +02:00
|
|
|
getSettings()->saveSnapshot();
|
2018-05-12 20:34:13 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto *tab : this->tabs_)
|
|
|
|
{
|
2018-05-12 20:34:13 +02:00
|
|
|
tab->getSettingsPage()->onShow();
|
|
|
|
}
|
2017-12-19 02:16:01 +01:00
|
|
|
}
|
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
void SettingsDialog::scaleChangedEvent(float newDpi)
|
2017-12-18 00:54:17 +01:00
|
|
|
{
|
|
|
|
QFile file(":/qss/settings.qss");
|
|
|
|
file.open(QFile::ReadOnly);
|
|
|
|
QString styleSheet = QLatin1String(file.readAll());
|
2018-07-03 16:55:02 +02:00
|
|
|
styleSheet.replace("<font-size>", QString::number(int(14 * newDpi)));
|
|
|
|
styleSheet.replace("<checkbox-size>", QString::number(int(14 * newDpi)));
|
2017-12-18 00:54:17 +01:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (SettingsDialogTab *tab : this->tabs_)
|
|
|
|
{
|
2018-07-03 16:55:02 +02:00
|
|
|
tab->setFixedHeight(int(30 * newDpi));
|
2017-12-18 00:54:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this->setStyleSheet(styleSheet);
|
|
|
|
|
2018-10-31 19:45:51 +01:00
|
|
|
this->ui_.tabContainerContainer->setFixedWidth(int(150 * newDpi));
|
2017-07-23 11:59:05 +02:00
|
|
|
}
|
|
|
|
|
2018-07-06 17:11:37 +02:00
|
|
|
void SettingsDialog::themeChangedEvent()
|
2018-04-18 09:33:05 +02:00
|
|
|
{
|
2018-07-06 17:11:37 +02:00
|
|
|
BaseWindow::themeChangedEvent();
|
2018-04-18 09:33:05 +02:00
|
|
|
|
|
|
|
QPalette palette;
|
2018-10-31 20:57:29 +01:00
|
|
|
palette.setColor(QPalette::Background, QColor("#111"));
|
2018-04-18 09:33:05 +02:00
|
|
|
this->setPalette(palette);
|
|
|
|
}
|
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
///// Widget creation helpers
|
2018-07-06 19:23:47 +02:00
|
|
|
void SettingsDialog::onOkClicked()
|
2017-01-24 19:51:57 +01:00
|
|
|
{
|
2018-10-29 19:20:23 +01:00
|
|
|
pajlada::Settings::SettingManager::gSave();
|
2017-01-24 19:51:57 +01:00
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
void SettingsDialog::onCancelClicked()
|
2017-01-24 19:51:57 +01:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto &tab : this->tabs_)
|
|
|
|
{
|
2018-01-12 23:09:05 +01:00
|
|
|
tab->getSettingsPage()->cancel();
|
|
|
|
}
|
|
|
|
|
2018-08-12 12:56:28 +02:00
|
|
|
getSettings()->restoreSnapshot();
|
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 chatterino
|