mirror-chatterino2/src/widgets/settingspages/moderationpage.cpp

58 lines
2 KiB
C++
Raw Normal View History

2018-01-12 23:09:05 +01:00
#include "moderationpage.hpp"
2018-01-24 15:08:22 +01:00
#include <QGroupBox>
2018-01-13 03:06:10 +01:00
#include <QHBoxLayout>
#include <QLabel>
#include <QListView>
#include <QPushButton>
#include <QTextEdit>
#include <QVBoxLayout>
#include "util/layoutcreator.hpp"
2018-01-12 23:09:05 +01:00
namespace chatterino {
namespace widgets {
namespace settingspages {
ModerationPage::ModerationPage()
2018-01-13 03:06:10 +01:00
: SettingsPage("Moderation", "")
2018-01-12 23:09:05 +01:00
{
2018-01-13 03:06:10 +01:00
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
util::LayoutCreator<ModerationPage> layoutCreator(this);
2018-01-24 15:08:22 +01:00
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
2018-01-13 03:06:10 +01:00
{
// clang-format off
2018-01-24 15:08:22 +01:00
auto label = layout.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>");
2018-01-13 03:06:10 +01:00
label->setWordWrap(true);
2018-01-24 15:08:22 +01:00
label->setStyleSheet("color: #bbb");
2018-01-13 03:06:10 +01:00
// clang-format on
2018-01-24 15:08:22 +01:00
auto modButtons =
layout.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);
2018-01-13 03:06:10 +01:00
2018-01-24 15:08:22 +01:00
auto text = modButtons.emplace<QTextEdit>().getElement();
2018-01-17 14:14:31 +01:00
2018-01-24 15:08:22 +01:00
text->setPlainText(settings.moderationActions);
2018-01-13 03:06:10 +01:00
2018-01-24 15:08:22 +01:00
QObject::connect(text, &QTextEdit::textChanged, this,
[this] { this->itemsChangedTimer.start(200); });
QObject::connect(&this->itemsChangedTimer, &QTimer::timeout, this, [text, &settings]() {
settings.moderationActions = text->toPlainText();
});
}
2018-01-13 03:06:10 +01:00
}
// ---- misc
this->itemsChangedTimer.setSingleShot(true);
2018-01-12 23:09:05 +01:00
}
2018-01-13 03:06:10 +01:00
2018-01-12 23:09:05 +01:00
} // namespace settingspages
} // namespace widgets
} // namespace chatterino