mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Add room mode options to splitheader (#497)
This commit is contained in:
parent
02214c38a6
commit
5135309508
2 changed files with 97 additions and 1 deletions
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include <QByteArray>
|
||||
#include <QDrag>
|
||||
#include <QInputDialog>
|
||||
#include <QMimeData>
|
||||
#include <QPainter>
|
||||
|
||||
|
@ -44,7 +45,7 @@ SplitHeader::SplitHeader(Split *_split)
|
|||
dropdown->setPixmap(*app->resources->splitHeaderContext->getPixmap());
|
||||
this->addDropdownItems(dropdown.getElement());
|
||||
QObject::connect(dropdown.getElement(), &RippleEffectButton::clicked, this, [this] {
|
||||
QTimer::singleShot(80, [&] {
|
||||
QTimer::singleShot(80, [&, this] {
|
||||
this->dropdownMenu.move(
|
||||
this->dropdownButton->mapToGlobal(QPoint(0, this->dropdownButton->height())));
|
||||
this->dropdownMenu.show();
|
||||
|
@ -59,7 +60,18 @@ SplitHeader::SplitHeader(Split *_split)
|
|||
|
||||
// mode button
|
||||
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();
|
||||
|
||||
// QObject::connect(mode.getElement(), &RippleEffectButton::clicked, this, [this]
|
||||
|
@ -137,6 +149,70 @@ void SplitHeader::addDropdownItems(RippleEffectButton *)
|
|||
// 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()
|
||||
{
|
||||
// Disconnect any previous signal first
|
||||
|
@ -241,21 +317,34 @@ void SplitHeader::updateModes()
|
|||
|
||||
QString text;
|
||||
|
||||
this->setSlow->setChecked(false);
|
||||
this->setEmote->setChecked(false);
|
||||
this->setSub->setChecked(false);
|
||||
this->setR9k->setChecked(false);
|
||||
|
||||
if (roomModes.r9k) {
|
||||
text += "r9k, ";
|
||||
this->setR9k->setChecked(true);
|
||||
}
|
||||
if (roomModes.slowMode) {
|
||||
text += QString("slow(%1), ").arg(QString::number(roomModes.slowMode));
|
||||
this->setSlow->setChecked(true);
|
||||
}
|
||||
if (roomModes.emoteOnly) {
|
||||
text += "emote, ";
|
||||
this->setEmote->setChecked(true);
|
||||
}
|
||||
if (roomModes.submode) {
|
||||
text += "sub, ";
|
||||
this->setSub->setChecked(true);
|
||||
}
|
||||
|
||||
if (text.length() > 2) {
|
||||
text = text.mid(0, text.size() - 2);
|
||||
} else {
|
||||
if (tc->hasModRights()) {
|
||||
text = "-";
|
||||
}
|
||||
}
|
||||
|
||||
if (text.isEmpty()) {
|
||||
|
|
|
@ -66,6 +66,12 @@ private:
|
|||
RippleEffectButton *moderationButton;
|
||||
|
||||
QMenu dropdownMenu;
|
||||
QMenu modeMenu;
|
||||
|
||||
QAction *setSub = nullptr;
|
||||
QAction *setEmote = nullptr;
|
||||
QAction *setSlow = nullptr;
|
||||
QAction *setR9k = nullptr;
|
||||
|
||||
void rightButtonClicked();
|
||||
|
||||
|
@ -78,6 +84,7 @@ private:
|
|||
|
||||
public slots:
|
||||
void addDropdownItems(RippleEffectButton *label);
|
||||
void addModeItems(RippleEffectLabel *label);
|
||||
|
||||
void menuMoveSplit();
|
||||
void menuReloadChannelEmotes();
|
||||
|
|
Loading…
Reference in a new issue