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->initPubsub();
this->moderationActions->items.delayedItemsChanged.connect(
[this] { this->windows->forceLayoutChannelViews(); });
}
int Application::run(QApplication &qtApp)

View file

@ -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)

View file

@ -16,6 +16,8 @@ enum class MessageElementFlag;
using MessageElementFlags = FlagsEnum<MessageElementFlag>;
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);

View file

@ -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);

View file

@ -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;
case SettingsDialogPreference::ModerationActions:
instance->selectPage(instance->ui_.moderationPage);
instance->ui_.moderationPage->selectModerationActions();
break;
default:;
}
instance->show();

View file

@ -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<SettingsDialogTab *> tabs_;
SettingsDialogTab *selectedTab_ = nullptr;
SettingsDialogTab *selectedTab_{};
friend class SettingsDialogTab;
};

View file

@ -84,6 +84,7 @@ ModerationPage::ModerationPage()
LayoutCreator<ModerationPage> layoutCreator(this);
auto tabs = layoutCreator.emplace<QTabWidget>();
this->tabWidget_ = tabs.getElement();
auto logs = tabs.appendTab(new QVBoxLayout, "Logs");
{
@ -109,7 +110,7 @@ ModerationPage::ModerationPage()
}
QString pathShortened =
"Logs saved at <a href=\"file:///" + pathOriginal +
"Logs are saved at <a href=\"file:///" + pathOriginal +
"\"><span style=\"color: white;\">" +
shortenString(pathOriginal, 50) + "</span></a>";
@ -158,7 +159,9 @@ ModerationPage::ModerationPage()
auto modMode = tabs.appendTab(new QVBoxLayout, "Moderation buttons");
{
// 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->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

View file

@ -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

View file

@ -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();

View file

@ -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<pajlada::Signals::ScopedConnection> managedConnections_;
};

View file

@ -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<Button>([&](auto w) {
QObject::connect(w, &Button::clicked, this, [this, w]() mutable {
this->split_->setModerationMode(
!this->split_->getModerationMode());
if (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());
});