Add room mode options to splitheader (#497)

This commit is contained in:
DatGuy1 2018-06-24 13:22:50 +03:00 committed by pajlada
parent 02214c38a6
commit 5135309508
2 changed files with 97 additions and 1 deletions

View file

@ -14,6 +14,7 @@
#include <QByteArray> #include <QByteArray>
#include <QDrag> #include <QDrag>
#include <QInputDialog>
#include <QMimeData> #include <QMimeData>
#include <QPainter> #include <QPainter>
@ -44,7 +45,7 @@ SplitHeader::SplitHeader(Split *_split)
dropdown->setPixmap(*app->resources->splitHeaderContext->getPixmap()); dropdown->setPixmap(*app->resources->splitHeaderContext->getPixmap());
this->addDropdownItems(dropdown.getElement()); this->addDropdownItems(dropdown.getElement());
QObject::connect(dropdown.getElement(), &RippleEffectButton::clicked, this, [this] { QObject::connect(dropdown.getElement(), &RippleEffectButton::clicked, this, [this] {
QTimer::singleShot(80, [&] { QTimer::singleShot(80, [&, this] {
this->dropdownMenu.move( this->dropdownMenu.move(
this->dropdownButton->mapToGlobal(QPoint(0, this->dropdownButton->height()))); this->dropdownButton->mapToGlobal(QPoint(0, this->dropdownButton->height())));
this->dropdownMenu.show(); this->dropdownMenu.show();
@ -59,7 +60,18 @@ SplitHeader::SplitHeader(Split *_split)
// mode button // mode button
auto mode = layout.emplace<RippleEffectLabel>(this).assign(&this->modeButton); auto mode = layout.emplace<RippleEffectLabel>(this).assign(&this->modeButton);
this->addModeItems(mode.getElement());
QObject::connect(mode.getElement(), &RippleEffectLabel::clicked, this, [this] {
QTimer::singleShot(80, [&, this] {
ChannelPtr _channel = this->split->getChannel();
if (_channel.get()->isMod() || _channel.get()->isBroadcaster()) {
this->modeMenu.move(
this->modeButton->mapToGlobal(QPoint(0, this->modeButton->height())));
this->modeMenu.show();
}
});
});
mode->hide(); mode->hide();
// QObject::connect(mode.getElement(), &RippleEffectButton::clicked, this, [this] // QObject::connect(mode.getElement(), &RippleEffectButton::clicked, this, [this]
@ -137,6 +149,70 @@ void SplitHeader::addDropdownItems(RippleEffectButton *)
// clang-format on // clang-format on
} }
void SplitHeader::addModeItems(RippleEffectLabel *)
{
QAction *setSub = new QAction("Submode", this);
this->setSub = setSub;
setSub->setCheckable(true);
QObject::connect(setSub, &QAction::triggered, this, [setSub, this]() {
QString sendCommand = "/subscribers";
if (!setSub->isChecked()) {
sendCommand.append("off");
};
this->split->getChannel().get()->sendMessage(sendCommand);
});
QAction *setEmote = new QAction("Emote only", this);
this->setEmote = setEmote;
setEmote->setCheckable(true);
QObject::connect(setEmote, &QAction::triggered, this, [setEmote, this]() {
QString sendCommand = "/emoteonly";
if (!setEmote->isChecked()) {
sendCommand.append("off");
};
this->split->getChannel().get()->sendMessage(sendCommand);
});
QAction *setSlow = new QAction("Slow mode", this);
this->setSlow = setSlow;
setSlow->setCheckable(true);
QObject::connect(setSlow, &QAction::triggered, this, [setSlow, this]() {
if (!setSlow->isChecked()) {
this->split->getChannel().get()->sendMessage("/slowoff");
setSlow->setChecked(false);
return;
};
bool ok;
int slowSec =
QInputDialog::getInt(this, "", "Seconds:", 10, 0, 500, 1, &ok, Qt::FramelessWindowHint);
if (ok) {
this->split->getChannel().get()->sendMessage(QString("/slow %1").arg(slowSec));
} else {
setSlow->setChecked(true);
}
});
QAction *setR9k = new QAction("R9K mode", this);
this->setR9k = setR9k;
setR9k->setCheckable(true);
QObject::connect(setR9k, &QAction::triggered, this, [setR9k, this]() {
QString sendCommand = "/r9kbeta";
if (!setR9k->isChecked()) {
sendCommand.append("off");
};
this->split->getChannel().get()->sendMessage(sendCommand);
});
this->modeMenu.addAction(setEmote);
this->modeMenu.addAction(setSub);
this->modeMenu.addAction(setSlow);
this->modeMenu.addAction(setR9k);
}
void SplitHeader::initializeChannelSignals() void SplitHeader::initializeChannelSignals()
{ {
// Disconnect any previous signal first // Disconnect any previous signal first
@ -241,21 +317,34 @@ void SplitHeader::updateModes()
QString text; QString text;
this->setSlow->setChecked(false);
this->setEmote->setChecked(false);
this->setSub->setChecked(false);
this->setR9k->setChecked(false);
if (roomModes.r9k) { if (roomModes.r9k) {
text += "r9k, "; text += "r9k, ";
this->setR9k->setChecked(true);
} }
if (roomModes.slowMode) { if (roomModes.slowMode) {
text += QString("slow(%1), ").arg(QString::number(roomModes.slowMode)); text += QString("slow(%1), ").arg(QString::number(roomModes.slowMode));
this->setSlow->setChecked(true);
} }
if (roomModes.emoteOnly) { if (roomModes.emoteOnly) {
text += "emote, "; text += "emote, ";
this->setEmote->setChecked(true);
} }
if (roomModes.submode) { if (roomModes.submode) {
text += "sub, "; text += "sub, ";
this->setSub->setChecked(true);
} }
if (text.length() > 2) { if (text.length() > 2) {
text = text.mid(0, text.size() - 2); text = text.mid(0, text.size() - 2);
} else {
if (tc->hasModRights()) {
text = "-";
}
} }
if (text.isEmpty()) { if (text.isEmpty()) {

View file

@ -66,6 +66,12 @@ private:
RippleEffectButton *moderationButton; RippleEffectButton *moderationButton;
QMenu dropdownMenu; QMenu dropdownMenu;
QMenu modeMenu;
QAction *setSub = nullptr;
QAction *setEmote = nullptr;
QAction *setSlow = nullptr;
QAction *setR9k = nullptr;
void rightButtonClicked(); void rightButtonClicked();
@ -78,6 +84,7 @@ private:
public slots: public slots:
void addDropdownItems(RippleEffectButton *label); void addDropdownItems(RippleEffectButton *label);
void addModeItems(RippleEffectLabel *label);
void menuMoveSplit(); void menuMoveSplit();
void menuReloadChannelEmotes(); void menuReloadChannelEmotes();