Open settings when clicking moderation button and no moderation actions are found

This commit is contained in:
fourtf 2018-10-21 15:32:28 +02:00
parent 27ac236115
commit 1872163ec4
11 changed files with 97 additions and 28 deletions

View file

@ -84,6 +84,9 @@ void Application::initialize(Settings &settings, Paths &paths)
this->initNm(paths); this->initNm(paths);
this->initPubsub(); this->initPubsub();
this->moderationActions->items.delayedItemsChanged.connect(
[this] { this->windows->forceLayoutChannelViews(); });
} }
int Application::run(QApplication &qtApp) int Application::run(QApplication &qtApp)

View file

@ -35,9 +35,10 @@ using SplitDirection = SplitContainer::Direction;
const int WindowManager::uiScaleMin = -5; const int WindowManager::uiScaleMin = -5;
const int WindowManager::uiScaleMax = 10; 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) void WindowManager::showAccountSelectPopup(QPoint point)

View file

@ -16,6 +16,8 @@ enum class MessageElementFlag;
using MessageElementFlags = FlagsEnum<MessageElementFlag>; using MessageElementFlags = FlagsEnum<MessageElementFlag>;
enum class WindowType; enum class WindowType;
enum class SettingsDialogPreference;
class WindowManager final : public Singleton class WindowManager final : public Singleton
{ {
public: public:
@ -31,7 +33,8 @@ public:
static const int uiScaleMin; static const int uiScaleMin;
static const int uiScaleMax; static const int uiScaleMax;
void showSettingsDialog(); void showSettingsDialog(
SettingsDialogPreference preference = SettingsDialogPreference());
// Show the account selector widget at point // Show the account selector widget at point
void showAccountSelectPopup(QPoint point); void showAccountSelectPopup(QPoint point);

View file

@ -31,7 +31,7 @@ AccountSwitchPopupWidget::AccountSwitchPopupWidget(QWidget *parent)
vbox->addLayout(hbox); vbox->addLayout(hbox);
connect(manageAccountsButton, &QPushButton::clicked, []() { connect(manageAccountsButton, &QPushButton::clicked, []() {
SettingsDialog::showDialog(SettingsDialog::PreferredTab::Accounts); // SettingsDialog::showDialog(SettingsDialogPreference::Accounts); //
}); });
this->setLayout(vbox); this->setLayout(vbox);

View file

@ -102,7 +102,7 @@ void SettingsDialog::addTabs()
this->addTab(new KeyboardSettingsPage); this->addTab(new KeyboardSettingsPage);
// this->addTab(new LogsPage); // this->addTab(new LogsPage);
this->addTab(new ModerationPage); this->addTab(this->ui_.moderationPage = new ModerationPage);
this->addTab(new NotificationPage); this->addTab(new NotificationPage);
// this->addTab(new SpecialChannelsPage); // this->addTab(new SpecialChannelsPage);
this->addTab(new BrowserExtensionPage); this->addTab(new BrowserExtensionPage);
@ -116,6 +116,7 @@ void SettingsDialog::addTabs()
void SettingsDialog::addTab(SettingsPage *page, Qt::Alignment alignment) void SettingsDialog::addTab(SettingsPage *page, Qt::Alignment alignment)
{ {
auto tab = new SettingsDialogTab(this, page, page->getIconResource()); auto tab = new SettingsDialogTab(this, page, page->getIconResource());
page->setTab(tab);
this->ui_.pageStack->addWidget(page); this->ui_.pageStack->addWidget(page);
this->ui_.tabContainer->addWidget(tab, 0, alignment); this->ui_.tabContainer->addWidget(tab, 0, alignment);
@ -142,18 +143,31 @@ void SettingsDialog::selectTab(SettingsDialogTab *tab)
this->selectedTab_ = 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(); static SettingsDialog *instance = new SettingsDialog();
instance->refresh(); instance->refresh();
switch (preferredTab) switch (preferredTab)
{ {
case SettingsDialog::PreferredTab::Accounts: case SettingsDialogPreference::Accounts:
{
instance->selectTab(instance->tabs_.at(0)); instance->selectTab(instance->tabs_.at(0));
} break;
break;
case SettingsDialogPreference::ModerationActions:
instance->selectPage(instance->ui_.moderationPage);
instance->ui_.moderationPage->selectModerationActions();
break;
default:;
} }
instance->show(); instance->show();

View file

@ -12,6 +12,13 @@ namespace chatterino {
class SettingsPage; class SettingsPage;
class SettingsDialogTab; class SettingsDialogTab;
class ModerationPage;
enum class SettingsDialogPreference {
NoPreference,
Accounts,
ModerationActions,
};
class SettingsDialog : public BaseWindow class SettingsDialog : public BaseWindow
{ {
@ -19,14 +26,8 @@ public:
SettingsDialog(); SettingsDialog();
static SettingsDialog *getHandle(); // may be NULL static SettingsDialog *getHandle(); // may be NULL
static void showDialog(SettingsDialogPreference preferredTab =
enum class PreferredTab { SettingsDialogPreference::NoPreference);
NoPreference,
Accounts,
};
static void showDialog(
PreferredTab preferredTab = PreferredTab::NoPreference);
protected: protected:
virtual void scaleChangedEvent(float newDpi) override; virtual void scaleChangedEvent(float newDpi) override;
@ -41,19 +42,21 @@ private:
void addTabs(); void addTabs();
void addTab(SettingsPage *page, Qt::Alignment alignment = Qt::AlignTop); void addTab(SettingsPage *page, Qt::Alignment alignment = Qt::AlignTop);
void selectTab(SettingsDialogTab *tab); void selectTab(SettingsDialogTab *tab);
void selectPage(SettingsPage *page);
void onOkClicked(); void onOkClicked();
void onCancelClicked(); void onCancelClicked();
struct { struct {
QWidget *tabContainerContainer; QWidget *tabContainerContainer{};
QVBoxLayout *tabContainer; QVBoxLayout *tabContainer{};
QStackedLayout *pageStack; QStackedLayout *pageStack{};
QPushButton *okButton; QPushButton *okButton{};
QPushButton *cancelButton; QPushButton *cancelButton{};
ModerationPage *moderationPage{};
} ui_; } ui_;
std::vector<SettingsDialogTab *> tabs_; std::vector<SettingsDialogTab *> tabs_;
SettingsDialogTab *selectedTab_ = nullptr; SettingsDialogTab *selectedTab_{};
friend class SettingsDialogTab; friend class SettingsDialogTab;
}; };

View file

@ -84,6 +84,7 @@ ModerationPage::ModerationPage()
LayoutCreator<ModerationPage> layoutCreator(this); LayoutCreator<ModerationPage> layoutCreator(this);
auto tabs = layoutCreator.emplace<QTabWidget>(); auto tabs = layoutCreator.emplace<QTabWidget>();
this->tabWidget_ = tabs.getElement();
auto logs = tabs.appendTab(new QVBoxLayout, "Logs"); auto logs = tabs.appendTab(new QVBoxLayout, "Logs");
{ {
@ -109,7 +110,7 @@ ModerationPage::ModerationPage()
} }
QString pathShortened = QString pathShortened =
"Logs saved at <a href=\"file:///" + pathOriginal + "Logs are saved at <a href=\"file:///" + pathOriginal +
"\"><span style=\"color: white;\">" + "\"><span style=\"color: white;\">" +
shortenString(pathOriginal, 50) + "</span></a>"; shortenString(pathOriginal, 50) + "</span></a>";
@ -158,7 +159,9 @@ ModerationPage::ModerationPage()
auto modMode = tabs.appendTab(new QVBoxLayout, "Moderation buttons"); auto modMode = tabs.appendTab(new QVBoxLayout, "Moderation buttons");
{ {
// clang-format off // clang-format off
auto label = modMode.emplace<QLabel>("Click the moderation mod button (<img width='18' height='18' src=':/buttons/modModeDisabled.png'>) in a channel that you moderate to enable moderator mode.<br>"); auto label = modMode.emplace<QLabel>(
"Moderation mode is enabled by clicking <img width='18' height='18' src=':/buttons/modModeDisabled.png'> in a channel that you moderate.<br><br>"
"Moderation buttons can be bound to chat commands such as \"/ban {user}\", \"/timeout {user} 1000\" or any other custom text commands.<br>");
label->setWordWrap(true); label->setWordWrap(true);
label->setStyleSheet("color: #bbb"); label->setStyleSheet("color: #bbb");
// clang-format on // clang-format on
@ -207,4 +210,9 @@ ModerationPage::ModerationPage()
this->itemsChangedTimer_.setSingleShot(true); this->itemsChangedTimer_.setSingleShot(true);
} }
void ModerationPage::selectModerationActions()
{
this->tabWidget_->setCurrentIndex(1);
}
} // namespace chatterino } // namespace chatterino

View file

@ -4,6 +4,7 @@
#include "widgets/settingspages/SettingsPage.hpp" #include "widgets/settingspages/SettingsPage.hpp"
class QTabWidget;
class QPushButton; class QPushButton;
namespace chatterino { namespace chatterino {
@ -13,8 +14,11 @@ class ModerationPage : public SettingsPage
public: public:
ModerationPage(); ModerationPage();
void selectModerationActions();
private: private:
QTimer itemsChangedTimer_; QTimer itemsChangedTimer_;
QTabWidget *tabWidget_{};
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -21,6 +21,16 @@ const QString &SettingsPage::getIconResource()
return this->iconResource_; return this->iconResource_;
} }
SettingsDialogTab *SettingsPage::tab() const
{
return this->tab_;
}
void SettingsPage::setTab(SettingsDialogTab *tab)
{
this->tab_ = tab;
}
void SettingsPage::cancel() void SettingsPage::cancel()
{ {
this->onCancel_.invoke(); this->onCancel_.invoke();

View file

@ -10,6 +10,8 @@
namespace chatterino { namespace chatterino {
class SettingsDialogTab;
class SettingsPage : public QWidget class SettingsPage : public QWidget
{ {
public: public:
@ -18,6 +20,9 @@ public:
const QString &getName(); const QString &getName();
const QString &getIconResource(); const QString &getIconResource();
SettingsDialogTab *tab() const;
void setTab(SettingsDialogTab *tab);
void cancel(); void cancel();
QCheckBox *createCheckBox(const QString &text, QCheckBox *createCheckBox(const QString &text,
@ -36,6 +41,8 @@ protected:
QString name_; QString name_;
QString iconResource_; QString iconResource_;
SettingsDialogTab *tab_;
pajlada::Signals::NoArgSignal onCancel_; pajlada::Signals::NoArgSignal onCancel_;
std::vector<pajlada::Signals::ScopedConnection> managedConnections_; std::vector<pajlada::Signals::ScopedConnection> managedConnections_;
}; };

View file

@ -2,16 +2,19 @@
#include "Application.hpp" #include "Application.hpp"
#include "controllers/accounts/AccountController.hpp" #include "controllers/accounts/AccountController.hpp"
#include "controllers/moderationactions/ModerationActions.hpp"
#include "controllers/notifications/NotificationController.hpp" #include "controllers/notifications/NotificationController.hpp"
#include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchServer.hpp" #include "providers/twitch/TwitchServer.hpp"
#include "singletons/Resources.hpp" #include "singletons/Resources.hpp"
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"
#include "singletons/Theme.hpp" #include "singletons/Theme.hpp"
#include "singletons/WindowManager.hpp"
#include "util/LayoutCreator.hpp" #include "util/LayoutCreator.hpp"
#include "util/LayoutHelper.hpp" #include "util/LayoutHelper.hpp"
#include "widgets/Label.hpp" #include "widgets/Label.hpp"
#include "widgets/TooltipWidget.hpp" #include "widgets/TooltipWidget.hpp"
#include "widgets/dialogs/SettingsDialog.hpp"
#include "widgets/helper/EffectLabel.hpp" #include "widgets/helper/EffectLabel.hpp"
#include "widgets/splits/Split.hpp" #include "widgets/splits/Split.hpp"
#include "widgets/splits/SplitContainer.hpp" #include "widgets/splits/SplitContainer.hpp"
@ -165,8 +168,21 @@ void SplitHeader::initializeLayout()
// moderator // moderator
this->moderationButton_ = makeWidget<Button>([&](auto w) { this->moderationButton_ = makeWidget<Button>([&](auto w) {
QObject::connect(w, &Button::clicked, this, [this, w]() mutable { QObject::connect(w, &Button::clicked, this, [this, w]() mutable {
this->split_->setModerationMode( if (this->split_->getModerationMode())
!this->split_->getModerationMode()); this->split_->setModerationMode(false);
else
{
if (getApp()->moderationActions->items.getVector().empty())
{
getApp()->windows->showSettingsDialog(
SettingsDialogPreference::ModerationActions);
this->split_->setModerationMode(true);
}
else
{
this->split_->setModerationMode(true);
}
}
w->setDim(!this->split_->getModerationMode()); w->setDim(!this->split_->getModerationMode());
}); });