added moderation action settings back in

This commit is contained in:
fourtf 2018-07-03 14:59:18 +02:00
parent 7d4feb2781
commit 63a596ef16
8 changed files with 91 additions and 24 deletions

View file

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

View file

@ -24,7 +24,7 @@ public:
private:
bool isImage_;
Image *image_;
Image *image_ = nullptr;
QString line1_;
QString line2_;
QString action_;

View file

@ -0,0 +1,27 @@
#include "ModerationActionModel.hpp"
#include "util/StandardItemHelper.hpp"
namespace chatterino {
// commandmodel
ModerationActionModel ::ModerationActionModel(QObject *parent)
: SignalVectorModel<ModerationAction>(1, parent)
{
}
// turn a vector item into a model row
ModerationAction ModerationActionModel::getItemFromRow(std::vector<QStandardItem *> &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<QStandardItem *> &row)
{
setStringItem(row[0], item.getAction());
}
} // namespace chatterino

View file

@ -0,0 +1,31 @@
#pragma once
#include <QObject>
#include "common/SignalVectorModel.hpp"
#include "controllers/moderationactions/ModerationAction.hpp"
namespace chatterino {
class ModerationActions;
class ModerationActionModel : public SignalVectorModel<ModerationAction>
{
public:
explicit ModerationActionModel(QObject *parent);
protected:
// turn a vector item into a model row
virtual ModerationAction getItemFromRow(std::vector<QStandardItem *> &row,
const ModerationAction &original) override;
// turns a row in the model into a vector item
virtual void getRowFromItem(const ModerationAction &item,
std::vector<QStandardItem *> &row) override;
friend class HighlightController;
friend class ModerationActions;
};
} // namespace chatterino

View file

@ -1,6 +1,7 @@
#include "ModerationActions.hpp"
#include "Application.hpp"
#include "controllers/moderationactions/ModerationActionModel.hpp"
#include "singletons/Settings.hpp"
#include <QRegularExpression>
@ -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

View file

@ -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<ModerationAction> items;
ModerationActionModel *createModel(QObject *parent);
private:
ChatterinoSetting<std::vector<ModerationAction>> setting = {"/moderation/actions"};
bool initialized = false;

View file

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

View file

@ -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 <QFileDialog>
#include <QFormLayout>
#include <QGroupBox>
#include <QHBoxLayout>
@ -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<QLabel>("Click the moderation mod button (<img width='18' height='18' src=':/images/moderatormode_disabled.png'>) in a channel that you moderate to enable moderator mode.<br>");
@ -97,26 +100,17 @@ ModerationPage::ModerationPage()
// app->settings->timeoutAction));
// }
// auto modButtons =
// modMode.emplace<QGroupBox>("Custom moderator buttons").setLayoutType<QVBoxLayout>();
// {
// auto label2 =
// modButtons.emplace<QLabel>("One action per line. {user} will be replaced with the
// "
// "username.<br>Example `/timeout {user} 120`<br>");
// label2->setWordWrap(true);
EditableModelView *view =
modMode.emplace<EditableModelView>(app->moderationActions->createModel(nullptr))
.getElement();
// auto text = modButtons.emplace<QTextEdit>().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");
{