2017-06-11 09:31:45 +02:00
|
|
|
#include "widgets/settingsdialog.hpp"
|
2018-01-12 23:09:05 +01:00
|
|
|
#include "util/layoutcreator.hpp"
|
2017-11-12 17:21:50 +01:00
|
|
|
#include "widgets/helper/settingsdialogtab.hpp"
|
2018-01-12 23:09:05 +01:00
|
|
|
#include "widgets/settingspages/aboutpage.hpp"
|
|
|
|
#include "widgets/settingspages/accountspage.hpp"
|
|
|
|
#include "widgets/settingspages/appearancepage.hpp"
|
|
|
|
#include "widgets/settingspages/behaviourpage.hpp"
|
|
|
|
#include "widgets/settingspages/commandpage.hpp"
|
|
|
|
#include "widgets/settingspages/emotespage.hpp"
|
|
|
|
#include "widgets/settingspages/highlightingpage.hpp"
|
2018-01-23 21:33:49 +01:00
|
|
|
#include "widgets/settingspages/ignoremessagespage.hpp"
|
|
|
|
#include "widgets/settingspages/ignoreuserspage.hpp"
|
2018-01-12 23:09:05 +01:00
|
|
|
#include "widgets/settingspages/logspage.hpp"
|
|
|
|
#include "widgets/settingspages/moderationpage.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 {
|
|
|
|
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()
|
2018-01-14 21:55:36 +01:00
|
|
|
: BaseWindow()
|
2017-01-01 18:43:52 +01:00
|
|
|
{
|
2018-01-12 23:09:05 +01:00
|
|
|
this->initUi();
|
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-12 23:09:05 +01:00
|
|
|
void SettingsDialog::initUi()
|
2017-10-08 16:31:16 +02:00
|
|
|
{
|
2018-01-12 23:09:05 +01:00
|
|
|
util::LayoutCreator<SettingsDialog> layoutCreator(this);
|
2017-04-13 16:06:23 +02:00
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
// tab pages
|
|
|
|
layoutCreator.emplace<QWidget>()
|
|
|
|
.assign(&this->ui.tabContainerContainer)
|
|
|
|
.emplace<QVBoxLayout>()
|
|
|
|
.withoutMargin()
|
|
|
|
.assign(&this->ui.tabContainer);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
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-01-13 02:00:02 +01: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-01-12 23:09:05 +01: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-01-12 23:09:05 +01:00
|
|
|
// ---- misc
|
|
|
|
QPalette palette;
|
|
|
|
palette.setColor(QPalette::Background, QColor("#444"));
|
|
|
|
this->setPalette(palette);
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
this->ui.tabContainerContainer->setObjectName("tabWidget");
|
|
|
|
this->ui.pageStack->setObjectName("pages");
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
QObject::connect(this->ui.okButton, &QPushButton::clicked, this,
|
|
|
|
&SettingsDialog::okButtonClicked);
|
|
|
|
QObject::connect(this->ui.cancelButton, &QPushButton::clicked, this,
|
|
|
|
&SettingsDialog::cancelButtonClicked);
|
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-01-12 23:09:05 +01:00
|
|
|
this->addTab(new settingspages::AccountsPage);
|
|
|
|
this->addTab(new settingspages::AppearancePage);
|
|
|
|
this->addTab(new settingspages::BehaviourPage);
|
|
|
|
this->addTab(new settingspages::CommandPage);
|
|
|
|
this->addTab(new settingspages::EmotesPage);
|
2018-01-23 21:33:49 +01:00
|
|
|
this->addTab(new settingspages::IgnoreUsersPage);
|
|
|
|
this->addTab(new settingspages::IgnoreMessagesPage);
|
2018-01-13 02:00:02 +01:00
|
|
|
this->addTab(new settingspages::HighlightingPage);
|
2018-01-12 23:09:05 +01:00
|
|
|
// this->addTab(new settingspages::LogsPage);
|
2018-01-13 03:06:10 +01:00
|
|
|
this->addTab(new settingspages::ModerationPage);
|
2018-01-12 23:09:05 +01:00
|
|
|
this->ui.tabContainer->addStretch(1);
|
|
|
|
this->addTab(new settingspages::AboutPage, Qt::AlignBottom);
|
2017-01-02 03:02:32 +01:00
|
|
|
}
|
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
void SettingsDialog::addTab(settingspages::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());
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
this->ui.pageStack->addWidget(page);
|
|
|
|
this->ui.tabContainer->addWidget(tab, 0, alignment);
|
|
|
|
this->tabs.push_back(tab);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
if (this->tabs.size() == 1) {
|
2017-07-02 12:36:50 +02:00
|
|
|
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
|
|
|
{
|
2018-01-12 23:09:05 +01:00
|
|
|
this->ui.pageStack->setCurrentWidget(tab->getSettingsPage());
|
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()
|
|
|
|
{
|
2018-01-12 23:09:05 +01:00
|
|
|
// 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);
|
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
this->ui.tabContainerContainer->setFixedWidth((int)(200 * newDpi));
|
2017-07-23 11:59:05 +02:00
|
|
|
}
|
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
// 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);
|
|
|
|
// // }
|
2017-08-12 14:44:27 +02:00
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
// // if (object->itemAt(i)->widget()) {
|
|
|
|
// // object->itemAt(i)->widget()->setFont(font);
|
2017-08-12 14:44:27 +02:00
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
// // if (object->itemAt(i)->widget()->layout() &&
|
|
|
|
// // !object->itemAt(i)->widget()->layout()->isEmpty()) {
|
|
|
|
// // setChildrensFont(object->itemAt(i)->widget()->layout(), font, indent +
|
|
|
|
// 2);
|
|
|
|
// // }
|
|
|
|
// // }
|
|
|
|
// // }
|
|
|
|
//}
|
2017-08-12 14:44:27 +02:00
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
///// Widget creation helpers
|
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
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
for (auto &tab : this->tabs) {
|
|
|
|
tab->getSettingsPage()->cancel();
|
|
|
|
}
|
|
|
|
|
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
|