diff --git a/src/Application.cpp b/src/Application.cpp index 25942889e..107f0b05f 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -84,6 +84,9 @@ void Application::initialize(Settings &settings, Paths &paths) this->initNm(paths); this->initPubsub(); + + this->moderationActions->items.delayedItemsChanged.connect( + [this] { this->windows->forceLayoutChannelViews(); }); } int Application::run(QApplication &qtApp) diff --git a/src/singletons/WindowManager.cpp b/src/singletons/WindowManager.cpp index 55854ebea..d9fbcaa4a 100644 --- a/src/singletons/WindowManager.cpp +++ b/src/singletons/WindowManager.cpp @@ -35,9 +35,10 @@ using SplitDirection = SplitContainer::Direction; const int WindowManager::uiScaleMin = -5; const int WindowManager::uiScaleMax = 10; -void WindowManager::showSettingsDialog() +void WindowManager::showSettingsDialog(SettingsDialogPreference preference) { - QTimer::singleShot(80, [] { SettingsDialog::showDialog(); }); + QTimer::singleShot( + 80, [preference] { SettingsDialog::showDialog(preference); }); } void WindowManager::showAccountSelectPopup(QPoint point) diff --git a/src/singletons/WindowManager.hpp b/src/singletons/WindowManager.hpp index dc66b0c7f..65ade477b 100644 --- a/src/singletons/WindowManager.hpp +++ b/src/singletons/WindowManager.hpp @@ -16,6 +16,8 @@ enum class MessageElementFlag; using MessageElementFlags = FlagsEnum; enum class WindowType; +enum class SettingsDialogPreference; + class WindowManager final : public Singleton { public: @@ -31,7 +33,8 @@ public: static const int uiScaleMin; static const int uiScaleMax; - void showSettingsDialog(); + void showSettingsDialog( + SettingsDialogPreference preference = SettingsDialogPreference()); // Show the account selector widget at point void showAccountSelectPopup(QPoint point); diff --git a/src/widgets/AccountSwitchPopupWidget.cpp b/src/widgets/AccountSwitchPopupWidget.cpp index 75ac355cb..6e9cfcebe 100644 --- a/src/widgets/AccountSwitchPopupWidget.cpp +++ b/src/widgets/AccountSwitchPopupWidget.cpp @@ -31,7 +31,7 @@ AccountSwitchPopupWidget::AccountSwitchPopupWidget(QWidget *parent) vbox->addLayout(hbox); connect(manageAccountsButton, &QPushButton::clicked, []() { - SettingsDialog::showDialog(SettingsDialog::PreferredTab::Accounts); // + SettingsDialog::showDialog(SettingsDialogPreference::Accounts); // }); this->setLayout(vbox); diff --git a/src/widgets/dialogs/SettingsDialog.cpp b/src/widgets/dialogs/SettingsDialog.cpp index ea848a9d5..c4df874e2 100644 --- a/src/widgets/dialogs/SettingsDialog.cpp +++ b/src/widgets/dialogs/SettingsDialog.cpp @@ -102,7 +102,7 @@ void SettingsDialog::addTabs() this->addTab(new KeyboardSettingsPage); // this->addTab(new LogsPage); - this->addTab(new ModerationPage); + this->addTab(this->ui_.moderationPage = new ModerationPage); this->addTab(new NotificationPage); // this->addTab(new SpecialChannelsPage); this->addTab(new BrowserExtensionPage); @@ -116,6 +116,7 @@ void SettingsDialog::addTabs() void SettingsDialog::addTab(SettingsPage *page, Qt::Alignment alignment) { auto tab = new SettingsDialogTab(this, page, page->getIconResource()); + page->setTab(tab); this->ui_.pageStack->addWidget(page); this->ui_.tabContainer->addWidget(tab, 0, alignment); @@ -142,18 +143,31 @@ void SettingsDialog::selectTab(SettingsDialogTab *tab) this->selectedTab_ = tab; } -void SettingsDialog::showDialog(PreferredTab preferredTab) +void SettingsDialog::selectPage(SettingsPage *page) +{ + assert(page); + assert(page->tab()); + + this->selectTab(page->tab()); +} + +void SettingsDialog::showDialog(SettingsDialogPreference preferredTab) { static SettingsDialog *instance = new SettingsDialog(); instance->refresh(); switch (preferredTab) { - case SettingsDialog::PreferredTab::Accounts: - { + case SettingsDialogPreference::Accounts: instance->selectTab(instance->tabs_.at(0)); - } - break; + break; + + case SettingsDialogPreference::ModerationActions: + instance->selectPage(instance->ui_.moderationPage); + instance->ui_.moderationPage->selectModerationActions(); + break; + + default:; } instance->show(); diff --git a/src/widgets/dialogs/SettingsDialog.hpp b/src/widgets/dialogs/SettingsDialog.hpp index 03ddc90a5..e5bc06595 100644 --- a/src/widgets/dialogs/SettingsDialog.hpp +++ b/src/widgets/dialogs/SettingsDialog.hpp @@ -12,6 +12,13 @@ namespace chatterino { class SettingsPage; class SettingsDialogTab; +class ModerationPage; + +enum class SettingsDialogPreference { + NoPreference, + Accounts, + ModerationActions, +}; class SettingsDialog : public BaseWindow { @@ -19,14 +26,8 @@ public: SettingsDialog(); static SettingsDialog *getHandle(); // may be NULL - - enum class PreferredTab { - NoPreference, - Accounts, - }; - - static void showDialog( - PreferredTab preferredTab = PreferredTab::NoPreference); + static void showDialog(SettingsDialogPreference preferredTab = + SettingsDialogPreference::NoPreference); protected: virtual void scaleChangedEvent(float newDpi) override; @@ -41,19 +42,21 @@ private: void addTabs(); void addTab(SettingsPage *page, Qt::Alignment alignment = Qt::AlignTop); void selectTab(SettingsDialogTab *tab); + void selectPage(SettingsPage *page); void onOkClicked(); void onCancelClicked(); struct { - QWidget *tabContainerContainer; - QVBoxLayout *tabContainer; - QStackedLayout *pageStack; - QPushButton *okButton; - QPushButton *cancelButton; + QWidget *tabContainerContainer{}; + QVBoxLayout *tabContainer{}; + QStackedLayout *pageStack{}; + QPushButton *okButton{}; + QPushButton *cancelButton{}; + ModerationPage *moderationPage{}; } ui_; std::vector tabs_; - SettingsDialogTab *selectedTab_ = nullptr; + SettingsDialogTab *selectedTab_{}; friend class SettingsDialogTab; }; diff --git a/src/widgets/settingspages/ModerationPage.cpp b/src/widgets/settingspages/ModerationPage.cpp index 1a061c922..422da3c05 100644 --- a/src/widgets/settingspages/ModerationPage.cpp +++ b/src/widgets/settingspages/ModerationPage.cpp @@ -84,6 +84,7 @@ ModerationPage::ModerationPage() LayoutCreator layoutCreator(this); auto tabs = layoutCreator.emplace(); + this->tabWidget_ = tabs.getElement(); auto logs = tabs.appendTab(new QVBoxLayout, "Logs"); { @@ -109,7 +110,7 @@ ModerationPage::ModerationPage() } QString pathShortened = - "Logs saved at " + shortenString(pathOriginal, 50) + ""; @@ -158,7 +159,9 @@ ModerationPage::ModerationPage() auto modMode = tabs.appendTab(new QVBoxLayout, "Moderation buttons"); { // clang-format off - auto label = modMode.emplace("Click the moderation mod button () in a channel that you moderate to enable moderator mode.
"); + auto label = modMode.emplace( + "Moderation mode is enabled by clicking in a channel that you moderate.

" + "Moderation buttons can be bound to chat commands such as \"/ban {user}\", \"/timeout {user} 1000\" or any other custom text commands.
"); label->setWordWrap(true); label->setStyleSheet("color: #bbb"); // clang-format on @@ -207,4 +210,9 @@ ModerationPage::ModerationPage() this->itemsChangedTimer_.setSingleShot(true); } +void ModerationPage::selectModerationActions() +{ + this->tabWidget_->setCurrentIndex(1); +} + } // namespace chatterino diff --git a/src/widgets/settingspages/ModerationPage.hpp b/src/widgets/settingspages/ModerationPage.hpp index cd879625f..284536be5 100644 --- a/src/widgets/settingspages/ModerationPage.hpp +++ b/src/widgets/settingspages/ModerationPage.hpp @@ -4,6 +4,7 @@ #include "widgets/settingspages/SettingsPage.hpp" +class QTabWidget; class QPushButton; namespace chatterino { @@ -13,8 +14,11 @@ class ModerationPage : public SettingsPage public: ModerationPage(); + void selectModerationActions(); + private: QTimer itemsChangedTimer_; + QTabWidget *tabWidget_{}; }; } // namespace chatterino diff --git a/src/widgets/settingspages/SettingsPage.cpp b/src/widgets/settingspages/SettingsPage.cpp index a70904bc3..21afcf90e 100644 --- a/src/widgets/settingspages/SettingsPage.cpp +++ b/src/widgets/settingspages/SettingsPage.cpp @@ -21,6 +21,16 @@ const QString &SettingsPage::getIconResource() return this->iconResource_; } +SettingsDialogTab *SettingsPage::tab() const +{ + return this->tab_; +} + +void SettingsPage::setTab(SettingsDialogTab *tab) +{ + this->tab_ = tab; +} + void SettingsPage::cancel() { this->onCancel_.invoke(); diff --git a/src/widgets/settingspages/SettingsPage.hpp b/src/widgets/settingspages/SettingsPage.hpp index 114e9c0fa..f394a3ac7 100644 --- a/src/widgets/settingspages/SettingsPage.hpp +++ b/src/widgets/settingspages/SettingsPage.hpp @@ -10,6 +10,8 @@ namespace chatterino { +class SettingsDialogTab; + class SettingsPage : public QWidget { public: @@ -18,6 +20,9 @@ public: const QString &getName(); const QString &getIconResource(); + SettingsDialogTab *tab() const; + void setTab(SettingsDialogTab *tab); + void cancel(); QCheckBox *createCheckBox(const QString &text, @@ -36,6 +41,8 @@ protected: QString name_; QString iconResource_; + SettingsDialogTab *tab_; + pajlada::Signals::NoArgSignal onCancel_; std::vector managedConnections_; }; diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index db2cd63e8..0041f2972 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -2,16 +2,19 @@ #include "Application.hpp" #include "controllers/accounts/AccountController.hpp" +#include "controllers/moderationactions/ModerationActions.hpp" #include "controllers/notifications/NotificationController.hpp" #include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchServer.hpp" #include "singletons/Resources.hpp" #include "singletons/Settings.hpp" #include "singletons/Theme.hpp" +#include "singletons/WindowManager.hpp" #include "util/LayoutCreator.hpp" #include "util/LayoutHelper.hpp" #include "widgets/Label.hpp" #include "widgets/TooltipWidget.hpp" +#include "widgets/dialogs/SettingsDialog.hpp" #include "widgets/helper/EffectLabel.hpp" #include "widgets/splits/Split.hpp" #include "widgets/splits/SplitContainer.hpp" @@ -165,8 +168,21 @@ void SplitHeader::initializeLayout() // moderator this->moderationButton_ = makeWidget