From 7a515355e467149c0d9720e1c4f82650378971b4 Mon Sep 17 00:00:00 2001 From: fourtf Date: Wed, 6 Jun 2018 16:17:34 +0200 Subject: [PATCH] added timeout and ban actions to the user popup --- src/widgets/userinfopopup.cpp | 179 +++++++++++++--------------------- src/widgets/userinfopopup.hpp | 4 + 2 files changed, 70 insertions(+), 113 deletions(-) diff --git a/src/widgets/userinfopopup.cpp b/src/widgets/userinfopopup.cpp index f0fa9dda7..021dfe950 100644 --- a/src/widgets/userinfopopup.cpp +++ b/src/widgets/userinfopopup.cpp @@ -108,6 +108,31 @@ UserInfoPopup::UserInfoPopup() timeout->setVisible(twitchChannel->hasModRights()); } }); + + timeout->buttonClicked.connect([this](auto item) { + TimeoutWidget::Action action; + int arg; + std::tie(action, arg) = item; + + switch (action) { + case TimeoutWidget::Ban: { + if (this->channel_) { + this->channel_->sendMessage("/ban " + this->userName_); + } + } break; + case TimeoutWidget::Unban: { + if (this->channel_) { + this->channel_->sendMessage("/unban " + this->userName_); + } + } break; + case TimeoutWidget::Timeout: { + if (this->channel_) { + this->channel_->sendMessage("/timeout " + this->userName_ + " " + + QString::number(arg)); + } + } break; + } + }); } this->setStyleSheet("font-size: 11pt;"); @@ -269,155 +294,83 @@ UserInfoPopup::TimeoutWidget::TimeoutWidget() QColor color1(255, 255, 255, 80); QColor color2(255, 255, 255, 0); - int buttonWidth = 40; + int buttonWidth = 32; int buttonWidth2 = 24; int buttonHeight = 32; layout->setSpacing(16); - { + auto addButton = [&](Action action, const QString &text, const QPixmap &pixmap) { auto vbox = layout.emplace().withoutMargin(); { auto title = vbox.emplace().withoutMargin(); title->addStretch(1); - auto label = title.emplace("unban"); + auto label = title.emplace(text); label->setStyleSheet("color: #BBB"); title->addStretch(1); auto hbox = vbox.emplace().withoutMargin(); hbox->setSpacing(0); { - auto unban = hbox.emplace(nullptr); - unban->setPixmap(getApp()->resources->buttons.unban); - unban->setScaleIndependantSize(buttonHeight, buttonHeight); - unban->setBorderColor(QColor(255, 255, 255, 127)); + auto button = hbox.emplace(nullptr); + button->setPixmap(pixmap); + button->setScaleIndependantSize(buttonHeight, buttonHeight); + button->setBorderColor(QColor(255, 255, 255, 127)); + + QObject::connect(*button, &RippleEffectButton::clicked, [this, action] { + this->buttonClicked.invoke(std::make_pair(action, -1)); + }); } } - } + }; - { + auto addTimeouts = [&](const QString &title_, + const std::vector> &items) { auto vbox = layout.emplace().withoutMargin(); { auto title = vbox.emplace().withoutMargin(); title->addStretch(1); - auto label = title.emplace("sec"); + auto label = title.emplace(title_); label->setStyleSheet("color: #BBB"); title->addStretch(1); auto hbox = vbox.emplace().withoutMargin(); hbox->setSpacing(0); - { - auto a = hbox.emplace(); - a->getLabel().setText("1"); - a->setScaleIndependantSize(buttonWidth2, buttonHeight); - a->setBorderColor(color1); - } - } - } - { - auto vbox = layout.emplace().withoutMargin(); - { - auto title = vbox.emplace().withoutMargin(); - title->addStretch(1); - auto label = title.emplace("min"); - label->setStyleSheet("color: #BBB"); - title->addStretch(1); - - auto hbox = vbox.emplace().withoutMargin(); - hbox->setSpacing(0); - { + for (const auto &item : items) { auto a = hbox.emplace(); - a->getLabel().setText("1"); - a->setScaleIndependantSize(buttonWidth2, buttonHeight); - a->setBorderColor(color1); - } - { - auto a = hbox.emplace(); - a->getLabel().setText("5"); - a->setScaleIndependantSize(buttonWidth2, buttonHeight); - a->setBorderColor(color1); - } - { - auto a = hbox.emplace(); - a->getLabel().setText("10"); + a->getLabel().setText(std::get<0>(item)); a->setScaleIndependantSize(buttonWidth, buttonHeight); a->setBorderColor(color1); + + // connect + + QObject::connect( + *a, &RippleEffectLabel::clicked, [this, timeout = std::get<1>(item)] { + this->buttonClicked.invoke(std::make_pair(Action::Timeout, timeout)); + }); } } - } + }; - { - auto vbox = layout.emplace().withoutMargin(); - { - auto title = vbox.emplace().withoutMargin(); - title->addStretch(1); - auto label = title.emplace("hour"); - label->setStyleSheet("color: #BBB"); - title->addStretch(1); + addButton(Unban, "unban", getApp()->resources->buttons.unban); - auto hbox = vbox.emplace().withoutMargin(); - hbox->setSpacing(0); - { - auto a = hbox.emplace(); - a->getLabel().setText("1"); - a->setScaleIndependantSize(buttonWidth2, buttonHeight); - a->setBorderColor(color1); - } - { - auto a = hbox.emplace(); - a->getLabel().setText("4"); - a->setScaleIndependantSize(buttonWidth2, buttonHeight); - a->setBorderColor(color1); - } - } - } + addTimeouts("sec", {{"1", 1}}); + addTimeouts("min", { + {"1", 1 * 60}, + {"5", 5 * 60}, + {"10", 10 * 60}, + }); + addTimeouts("hour", { + {"1", 1 * 60 * 60}, + {"4", 4 * 60 * 60}, + }); + addTimeouts("weeks", { + {"1", 1 * 60 * 60 * 30}, + {"2", 2 * 60 * 60 * 30}, + }); - { - auto vbox = layout.emplace().withoutMargin(); - { - auto title = vbox.emplace().withoutMargin(); - title->addStretch(1); - auto label = title.emplace("week"); - label->setStyleSheet("color: #BBB"); - title->addStretch(1); - - auto hbox = vbox.emplace().withoutMargin(); - hbox->setSpacing(0); - { - auto a = hbox.emplace(); - a->getLabel().setText("1"); - a->setScaleIndependantSize(buttonWidth2, buttonHeight); - a->setBorderColor(color1); - } - { - auto a = hbox.emplace(); - a->getLabel().setText("2"); - a->setScaleIndependantSize(buttonWidth2, buttonHeight); - a->setBorderColor(color1); - } - } - } - - { - auto vbox = layout.emplace().withoutMargin(); - { - auto title = vbox.emplace().withoutMargin(); - title->addStretch(1); - auto label = title.emplace("ban"); - label->setStyleSheet("color: #BBB"); - title->addStretch(1); - - auto hbox = vbox.emplace().withoutMargin(); - hbox->setSpacing(0); - { - auto ban = hbox.emplace(nullptr); - ban->setPixmap(getApp()->resources->buttons.ban); - ban->setScaleIndependantSize(buttonHeight, buttonHeight); - ban->setBorderColor(QColor(255, 255, 255, 127)); - } - } - } + addButton(Ban, "ban", getApp()->resources->buttons.ban); } void UserInfoPopup::TimeoutWidget::paintEvent(QPaintEvent *) diff --git a/src/widgets/userinfopopup.hpp b/src/widgets/userinfopopup.hpp index 34ff9efde..8394f4e49 100644 --- a/src/widgets/userinfopopup.hpp +++ b/src/widgets/userinfopopup.hpp @@ -53,8 +53,12 @@ private: class TimeoutWidget : public BaseWidget { public: + enum Action { Ban, Unban, Timeout }; + TimeoutWidget(); + pajlada::Signals::Signal> buttonClicked; + protected: void paintEvent(QPaintEvent *event) override; };