added timeout and ban actions to the user popup

This commit is contained in:
fourtf 2018-06-06 16:17:34 +02:00
parent 45cda9b7a5
commit 7a515355e4
2 changed files with 70 additions and 113 deletions

View file

@ -108,6 +108,31 @@ UserInfoPopup::UserInfoPopup()
timeout->setVisible(twitchChannel->hasModRights()); 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;"); this->setStyleSheet("font-size: 11pt;");
@ -269,155 +294,83 @@ UserInfoPopup::TimeoutWidget::TimeoutWidget()
QColor color1(255, 255, 255, 80); QColor color1(255, 255, 255, 80);
QColor color2(255, 255, 255, 0); QColor color2(255, 255, 255, 0);
int buttonWidth = 40; int buttonWidth = 32;
int buttonWidth2 = 24; int buttonWidth2 = 24;
int buttonHeight = 32; int buttonHeight = 32;
layout->setSpacing(16); layout->setSpacing(16);
{ auto addButton = [&](Action action, const QString &text, const QPixmap &pixmap) {
auto vbox = layout.emplace<QVBoxLayout>().withoutMargin(); auto vbox = layout.emplace<QVBoxLayout>().withoutMargin();
{ {
auto title = vbox.emplace<QHBoxLayout>().withoutMargin(); auto title = vbox.emplace<QHBoxLayout>().withoutMargin();
title->addStretch(1); title->addStretch(1);
auto label = title.emplace<QLabel>("unban"); auto label = title.emplace<QLabel>(text);
label->setStyleSheet("color: #BBB"); label->setStyleSheet("color: #BBB");
title->addStretch(1); title->addStretch(1);
auto hbox = vbox.emplace<QHBoxLayout>().withoutMargin(); auto hbox = vbox.emplace<QHBoxLayout>().withoutMargin();
hbox->setSpacing(0); hbox->setSpacing(0);
{ {
auto unban = hbox.emplace<RippleEffectButton>(nullptr); auto button = hbox.emplace<RippleEffectButton>(nullptr);
unban->setPixmap(getApp()->resources->buttons.unban); button->setPixmap(pixmap);
unban->setScaleIndependantSize(buttonHeight, buttonHeight); button->setScaleIndependantSize(buttonHeight, buttonHeight);
unban->setBorderColor(QColor(255, 255, 255, 127)); 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<std::pair<QString, int>> &items) {
auto vbox = layout.emplace<QVBoxLayout>().withoutMargin(); auto vbox = layout.emplace<QVBoxLayout>().withoutMargin();
{ {
auto title = vbox.emplace<QHBoxLayout>().withoutMargin(); auto title = vbox.emplace<QHBoxLayout>().withoutMargin();
title->addStretch(1); title->addStretch(1);
auto label = title.emplace<QLabel>("sec"); auto label = title.emplace<QLabel>(title_);
label->setStyleSheet("color: #BBB"); label->setStyleSheet("color: #BBB");
title->addStretch(1); title->addStretch(1);
auto hbox = vbox.emplace<QHBoxLayout>().withoutMargin(); auto hbox = vbox.emplace<QHBoxLayout>().withoutMargin();
hbox->setSpacing(0); hbox->setSpacing(0);
{
auto a = hbox.emplace<RippleEffectLabel>();
a->getLabel().setText("1");
a->setScaleIndependantSize(buttonWidth2, buttonHeight);
a->setBorderColor(color1);
}
}
}
{ for (const auto &item : items) {
auto vbox = layout.emplace<QVBoxLayout>().withoutMargin();
{
auto title = vbox.emplace<QHBoxLayout>().withoutMargin();
title->addStretch(1);
auto label = title.emplace<QLabel>("min");
label->setStyleSheet("color: #BBB");
title->addStretch(1);
auto hbox = vbox.emplace<QHBoxLayout>().withoutMargin();
hbox->setSpacing(0);
{
auto a = hbox.emplace<RippleEffectLabel>(); auto a = hbox.emplace<RippleEffectLabel>();
a->getLabel().setText("1"); a->getLabel().setText(std::get<0>(item));
a->setScaleIndependantSize(buttonWidth2, buttonHeight);
a->setBorderColor(color1);
}
{
auto a = hbox.emplace<RippleEffectLabel>();
a->getLabel().setText("5");
a->setScaleIndependantSize(buttonWidth2, buttonHeight);
a->setBorderColor(color1);
}
{
auto a = hbox.emplace<RippleEffectLabel>();
a->getLabel().setText("10");
a->setScaleIndependantSize(buttonWidth, buttonHeight); a->setScaleIndependantSize(buttonWidth, buttonHeight);
a->setBorderColor(color1); a->setBorderColor(color1);
// connect
QObject::connect(
*a, &RippleEffectLabel::clicked, [this, timeout = std::get<1>(item)] {
this->buttonClicked.invoke(std::make_pair(Action::Timeout, timeout));
});
} }
} }
} };
{ addButton(Unban, "unban", getApp()->resources->buttons.unban);
auto vbox = layout.emplace<QVBoxLayout>().withoutMargin();
{
auto title = vbox.emplace<QHBoxLayout>().withoutMargin();
title->addStretch(1);
auto label = title.emplace<QLabel>("hour");
label->setStyleSheet("color: #BBB");
title->addStretch(1);
auto hbox = vbox.emplace<QHBoxLayout>().withoutMargin(); addTimeouts("sec", {{"1", 1}});
hbox->setSpacing(0); addTimeouts("min", {
{ {"1", 1 * 60},
auto a = hbox.emplace<RippleEffectLabel>(); {"5", 5 * 60},
a->getLabel().setText("1"); {"10", 10 * 60},
a->setScaleIndependantSize(buttonWidth2, buttonHeight); });
a->setBorderColor(color1); addTimeouts("hour", {
} {"1", 1 * 60 * 60},
{ {"4", 4 * 60 * 60},
auto a = hbox.emplace<RippleEffectLabel>(); });
a->getLabel().setText("4"); addTimeouts("weeks", {
a->setScaleIndependantSize(buttonWidth2, buttonHeight); {"1", 1 * 60 * 60 * 30},
a->setBorderColor(color1); {"2", 2 * 60 * 60 * 30},
} });
}
}
{ addButton(Ban, "ban", getApp()->resources->buttons.ban);
auto vbox = layout.emplace<QVBoxLayout>().withoutMargin();
{
auto title = vbox.emplace<QHBoxLayout>().withoutMargin();
title->addStretch(1);
auto label = title.emplace<QLabel>("week");
label->setStyleSheet("color: #BBB");
title->addStretch(1);
auto hbox = vbox.emplace<QHBoxLayout>().withoutMargin();
hbox->setSpacing(0);
{
auto a = hbox.emplace<RippleEffectLabel>();
a->getLabel().setText("1");
a->setScaleIndependantSize(buttonWidth2, buttonHeight);
a->setBorderColor(color1);
}
{
auto a = hbox.emplace<RippleEffectLabel>();
a->getLabel().setText("2");
a->setScaleIndependantSize(buttonWidth2, buttonHeight);
a->setBorderColor(color1);
}
}
}
{
auto vbox = layout.emplace<QVBoxLayout>().withoutMargin();
{
auto title = vbox.emplace<QHBoxLayout>().withoutMargin();
title->addStretch(1);
auto label = title.emplace<QLabel>("ban");
label->setStyleSheet("color: #BBB");
title->addStretch(1);
auto hbox = vbox.emplace<QHBoxLayout>().withoutMargin();
hbox->setSpacing(0);
{
auto ban = hbox.emplace<RippleEffectButton>(nullptr);
ban->setPixmap(getApp()->resources->buttons.ban);
ban->setScaleIndependantSize(buttonHeight, buttonHeight);
ban->setBorderColor(QColor(255, 255, 255, 127));
}
}
}
} }
void UserInfoPopup::TimeoutWidget::paintEvent(QPaintEvent *) void UserInfoPopup::TimeoutWidget::paintEvent(QPaintEvent *)

View file

@ -53,8 +53,12 @@ private:
class TimeoutWidget : public BaseWidget class TimeoutWidget : public BaseWidget
{ {
public: public:
enum Action { Ban, Unban, Timeout };
TimeoutWidget(); TimeoutWidget();
pajlada::Signals::Signal<std::pair<Action, int>> buttonClicked;
protected: protected:
void paintEvent(QPaintEvent *event) override; void paintEvent(QPaintEvent *event) override;
}; };