From 63a596ef16380d5ebbdb9e44d6060665ed20aadf Mon Sep 17 00:00:00 2001 From: fourtf Date: Tue, 3 Jul 2018 14:59:18 +0200 Subject: [PATCH] added moderation action settings back in --- chatterino.pro | 6 ++-- .../moderationactions/ModerationAction.hpp | 2 +- .../ModerationActionModel.cpp | 27 ++++++++++++++++ .../ModerationActionModel.hpp | 31 ++++++++++++++++++ .../moderationactions/ModerationActions.cpp | 9 ++++++ .../moderationactions/ModerationActions.hpp | 6 +++- src/messages/MessageElement.cpp | 2 +- src/widgets/settingspages/ModerationPage.cpp | 32 ++++++++----------- 8 files changed, 91 insertions(+), 24 deletions(-) create mode 100644 src/controllers/moderationactions/ModerationActionModel.cpp create mode 100644 src/controllers/moderationactions/ModerationActionModel.hpp diff --git a/chatterino.pro b/chatterino.pro index 96d8bd3a6..f5b32d67c 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -223,7 +223,8 @@ SOURCES += \ src/singletons/Resources.cpp \ src/singletons/Settings.cpp \ src/singletons/Updates.cpp \ - src/singletons/Theme.cpp + src/singletons/Theme.cpp \ + src/controllers/moderationactions/ModerationActionModel.cpp HEADERS += \ src/Application.hpp \ @@ -393,7 +394,8 @@ HEADERS += \ src/singletons/Theme.hpp \ src/common/SimpleSignalVector.hpp \ src/common/SignalVector.hpp \ - src/common/Singleton.hpp + src/common/Singleton.hpp \ + src/controllers/moderationactions/ModerationActionModel.hpp RESOURCES += \ resources/resources.qrc \ diff --git a/src/controllers/moderationactions/ModerationAction.hpp b/src/controllers/moderationactions/ModerationAction.hpp index fe51be353..cc5adc39b 100644 --- a/src/controllers/moderationactions/ModerationAction.hpp +++ b/src/controllers/moderationactions/ModerationAction.hpp @@ -24,7 +24,7 @@ public: private: bool isImage_; - Image *image_; + Image *image_ = nullptr; QString line1_; QString line2_; QString action_; diff --git a/src/controllers/moderationactions/ModerationActionModel.cpp b/src/controllers/moderationactions/ModerationActionModel.cpp new file mode 100644 index 000000000..aa0fe134c --- /dev/null +++ b/src/controllers/moderationactions/ModerationActionModel.cpp @@ -0,0 +1,27 @@ +#include "ModerationActionModel.hpp" + +#include "util/StandardItemHelper.hpp" + +namespace chatterino { + +// commandmodel +ModerationActionModel ::ModerationActionModel(QObject *parent) + : SignalVectorModel(1, parent) +{ +} + +// turn a vector item into a model row +ModerationAction ModerationActionModel::getItemFromRow(std::vector &row, + const ModerationAction &original) +{ + return ModerationAction(row[0]->data(Qt::DisplayRole).toString()); +} + +// turns a row in the model into a vector item +void ModerationActionModel::getRowFromItem(const ModerationAction &item, + std::vector &row) +{ + setStringItem(row[0], item.getAction()); +} + +} // namespace chatterino diff --git a/src/controllers/moderationactions/ModerationActionModel.hpp b/src/controllers/moderationactions/ModerationActionModel.hpp new file mode 100644 index 000000000..3c8a11675 --- /dev/null +++ b/src/controllers/moderationactions/ModerationActionModel.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include + +#include "common/SignalVectorModel.hpp" +#include "controllers/moderationactions/ModerationAction.hpp" + +namespace chatterino { + +class ModerationActions; + +class ModerationActionModel : public SignalVectorModel +{ +public: + explicit ModerationActionModel(QObject *parent); + +protected: + // turn a vector item into a model row + virtual ModerationAction getItemFromRow(std::vector &row, + const ModerationAction &original) override; + + // turns a row in the model into a vector item + virtual void getRowFromItem(const ModerationAction &item, + std::vector &row) override; + + friend class HighlightController; + + friend class ModerationActions; +}; + +} // namespace chatterino diff --git a/src/controllers/moderationactions/ModerationActions.cpp b/src/controllers/moderationactions/ModerationActions.cpp index 9d5095647..2b7b38ee5 100644 --- a/src/controllers/moderationactions/ModerationActions.cpp +++ b/src/controllers/moderationactions/ModerationActions.cpp @@ -1,6 +1,7 @@ #include "ModerationActions.hpp" #include "Application.hpp" +#include "controllers/moderationactions/ModerationActionModel.hpp" #include "singletons/Settings.hpp" #include @@ -25,4 +26,12 @@ void ModerationActions::initialize() }); } +ModerationActionModel *ModerationActions::createModel(QObject *parent) +{ + ModerationActionModel *model = new ModerationActionModel(parent); + model->init(&this->items); + + return model; +} + } // namespace chatterino diff --git a/src/controllers/moderationactions/ModerationActions.hpp b/src/controllers/moderationactions/ModerationActions.hpp index 823f97bad..1dcf77dc9 100644 --- a/src/controllers/moderationactions/ModerationActions.hpp +++ b/src/controllers/moderationactions/ModerationActions.hpp @@ -1,11 +1,13 @@ #pragma once +#include "common/ChatterinoSetting.hpp" #include "common/SignalVector.hpp" #include "controllers/moderationactions/ModerationAction.hpp" -#include "common/ChatterinoSetting.hpp" namespace chatterino { +class ModerationActionModel; + class ModerationActions { public: @@ -15,6 +17,8 @@ public: UnsortedSignalVector items; + ModerationActionModel *createModel(QObject *parent); + private: ChatterinoSetting> setting = {"/moderation/actions"}; bool initialized = false; diff --git a/src/messages/MessageElement.cpp b/src/messages/MessageElement.cpp index 81d55b0d6..90420df17 100644 --- a/src/messages/MessageElement.cpp +++ b/src/messages/MessageElement.cpp @@ -247,7 +247,7 @@ void TwitchModerationElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags _flags) { if (_flags & MessageElement::ModeratorTools) { - QSize size((int)(container.getScale() * 16), (int)(container.getScale() * 16)); + QSize size(int(container.getScale() * 16), int(container.getScale() * 16)); for (const ModerationAction &m : getApp()->moderationActions->items.getVector()) { if (m.isImage()) { diff --git a/src/widgets/settingspages/ModerationPage.cpp b/src/widgets/settingspages/ModerationPage.cpp index 20afe8ebe..4555e1834 100644 --- a/src/widgets/settingspages/ModerationPage.cpp +++ b/src/widgets/settingspages/ModerationPage.cpp @@ -1,6 +1,8 @@ #include "ModerationPage.hpp" #include "Application.hpp" +#include "controllers/moderationactions/ModerationActionModel.hpp" +#include "controllers/moderationactions/ModerationActions.hpp" #include "controllers/taggedusers/TaggedUsersController.hpp" #include "controllers/taggedusers/TaggedUsersModel.hpp" #include "singletons/Logging.hpp" @@ -8,6 +10,7 @@ #include "util/LayoutCreator.hpp" #include "widgets/helper/EditableModelView.hpp" +#include #include #include #include @@ -82,7 +85,7 @@ ModerationPage::ModerationPage() // Logs end } - auto modMode = tabs.appendTab(new QVBoxLayout, "Moderation mode"); + 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.
"); @@ -97,26 +100,17 @@ ModerationPage::ModerationPage() // app->settings->timeoutAction)); // } - // auto modButtons = - // modMode.emplace("Custom moderator buttons").setLayoutType(); - // { - // auto label2 = - // modButtons.emplace("One action per line. {user} will be replaced with the - // " - // "username.
Example `/timeout {user} 120`
"); - // label2->setWordWrap(true); + EditableModelView *view = + modMode.emplace(app->moderationActions->createModel(nullptr)) + .getElement(); - // auto text = modButtons.emplace().getElement(); + view->setTitles({"Actions"}); + view->getTableView()->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + view->getTableView()->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); - // text->setPlainText(app->moderationActions->items); - - // QObject::connect(text, &QTextEdit::textChanged, this, - // [this] { this->itemsChangedTimer.start(200); }); - - // QObject::connect(&this->itemsChangedTimer, &QTimer::timeout, this, [text, app]() { - // app->windows->moderationActions = text->toPlainText(); - // }); - // } + view->addButtonPressed.connect([] { + getApp()->moderationActions->items.appendItem(ModerationAction("/timeout {user} 300")); + }); /*auto taggedUsers = tabs.appendTab(new QVBoxLayout, "Tagged users"); {