mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
added room mode selector for mods again
This commit is contained in:
parent
e9a112f8b3
commit
14f125ff87
9 changed files with 148 additions and 97 deletions
|
@ -203,6 +203,12 @@ bool Channel::isBroadcaster() const
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Channel::hasModRights() const
|
||||
{
|
||||
// fourtf: check if staff
|
||||
return this->isMod() || this->isBroadcaster();
|
||||
}
|
||||
|
||||
std::shared_ptr<Channel> Channel::getEmpty()
|
||||
{
|
||||
static std::shared_ptr<Channel> channel(new Channel("", None));
|
||||
|
|
|
@ -61,6 +61,7 @@ public:
|
|||
virtual void sendMessage(const QString &message);
|
||||
virtual bool isMod() const;
|
||||
virtual bool isBroadcaster() const;
|
||||
virtual bool hasModRights() const;
|
||||
|
||||
static std::shared_ptr<Channel> getEmpty();
|
||||
|
||||
|
|
|
@ -197,12 +197,6 @@ bool TwitchChannel::isBroadcaster() const
|
|||
return this->name == app->accounts->twitch.getCurrent()->getUserName();
|
||||
}
|
||||
|
||||
bool TwitchChannel::hasModRights()
|
||||
{
|
||||
// fourtf: check if staff
|
||||
return this->isMod() || this->isBroadcaster();
|
||||
}
|
||||
|
||||
void TwitchChannel::addRecentChatter(const std::shared_ptr<Message> &message)
|
||||
{
|
||||
assert(!message->loginName.isEmpty());
|
||||
|
|
|
@ -54,10 +54,9 @@ public:
|
|||
bool canSendMessage() const override;
|
||||
void sendMessage(const QString &message) override;
|
||||
|
||||
bool isMod() const override;
|
||||
virtual bool isMod() const override;
|
||||
void setMod(bool value);
|
||||
bool isBroadcaster() const override;
|
||||
bool hasModRights();
|
||||
virtual bool isBroadcaster() const override;
|
||||
|
||||
void addRecentChatter(const std::shared_ptr<Message> &message) final;
|
||||
void addJoinedUser(const QString &user);
|
||||
|
|
|
@ -46,6 +46,18 @@ bool RippleEffectButton::getDim() const
|
|||
return this->dimPixmap_;
|
||||
}
|
||||
|
||||
void RippleEffectButton::setEnable(bool value)
|
||||
{
|
||||
this->enabled_ = value;
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
bool RippleEffectButton::getEnable() const
|
||||
{
|
||||
return this->enabled_;
|
||||
}
|
||||
|
||||
qreal RippleEffectButton::getCurrentDimAmount() const
|
||||
{
|
||||
return this->dimPixmap_ && !this->mouseOver_ ? 0.7 : 1;
|
||||
|
@ -54,6 +66,8 @@ qreal RippleEffectButton::getCurrentDimAmount() const
|
|||
void RippleEffectButton::setBorderColor(const QColor &color)
|
||||
{
|
||||
this->borderColor_ = color;
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
const QColor &RippleEffectButton::getBorderColor() const
|
||||
|
@ -68,7 +82,7 @@ void RippleEffectButton::paintEvent(QPaintEvent *)
|
|||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
|
||||
if (!this->pixmap_.isNull()) {
|
||||
if (!this->mouseOver_ && this->dimPixmap_) {
|
||||
if (!this->mouseOver_ && this->dimPixmap_ && this->enabled_) {
|
||||
painter.setOpacity(this->getCurrentDimAmount());
|
||||
}
|
||||
|
||||
|
@ -96,6 +110,10 @@ void RippleEffectButton::paintEvent(QPaintEvent *)
|
|||
|
||||
void RippleEffectButton::fancyPaint(QPainter &painter)
|
||||
{
|
||||
if (!this->enabled_) {
|
||||
return;
|
||||
}
|
||||
|
||||
painter.setRenderHint(QPainter::HighQualityAntialiasing);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
QColor c;
|
||||
|
@ -144,6 +162,10 @@ void RippleEffectButton::leaveEvent(QEvent *)
|
|||
|
||||
void RippleEffectButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (!this->enabled_) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->button() != Qt::LeftButton) {
|
||||
return;
|
||||
}
|
||||
|
@ -151,10 +173,16 @@ void RippleEffectButton::mousePressEvent(QMouseEvent *event)
|
|||
this->clickEffects_.push_back(ClickEffect(event->pos()));
|
||||
|
||||
this->mouseDown_ = true;
|
||||
|
||||
emit this->leftMousePress();
|
||||
}
|
||||
|
||||
void RippleEffectButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (!this->enabled_) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->button() != Qt::LeftButton) {
|
||||
return;
|
||||
}
|
||||
|
@ -168,6 +196,10 @@ void RippleEffectButton::mouseReleaseEvent(QMouseEvent *event)
|
|||
|
||||
void RippleEffectButton::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (!this->enabled_) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->mousePos_ = event->pos();
|
||||
|
||||
this->update();
|
||||
|
|
|
@ -37,13 +37,18 @@ public:
|
|||
bool getDim() const;
|
||||
qreal getCurrentDimAmount() const;
|
||||
|
||||
void setEnable(bool value);
|
||||
bool getEnable() const;
|
||||
|
||||
void setBorderColor(const QColor &color);
|
||||
const QColor &getBorderColor() const;
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
void leftMousePress();
|
||||
|
||||
protected:
|
||||
bool enabled_ = true;
|
||||
bool selected_ = false;
|
||||
bool mouseOver_ = false;
|
||||
bool mouseDown_ = false;
|
||||
|
|
|
@ -193,11 +193,13 @@ void Split::setChannel(IndirectChannel newChannel)
|
|||
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(newChannel.get().get());
|
||||
|
||||
if (tc != nullptr) {
|
||||
this->usermodeChangedConnection =
|
||||
tc->userStateChanged.connect([this] { this->header.updateModerationModeIcon(); });
|
||||
this->usermodeChangedConnection = tc->userStateChanged.connect([this] {
|
||||
this->header.updateModerationModeIcon();
|
||||
this->header.updateRoomModes();
|
||||
});
|
||||
|
||||
this->roomModeChangedConnection =
|
||||
tc->roomModesChanged.connect([this] { this->header.updateModes(); });
|
||||
tc->roomModesChanged.connect([this] { this->header.updateRoomModes(); });
|
||||
}
|
||||
|
||||
this->indirectChannelChangedConnection = newChannel.getChannelChanged().connect([this] { //
|
||||
|
@ -206,7 +208,7 @@ void Split::setChannel(IndirectChannel newChannel)
|
|||
|
||||
this->header.updateModerationModeIcon();
|
||||
this->header.updateChannelText();
|
||||
this->header.updateModes();
|
||||
this->header.updateRoomModes();
|
||||
|
||||
this->channelChanged.invoke();
|
||||
}
|
||||
|
|
|
@ -44,15 +44,23 @@ SplitHeader::SplitHeader(Split *_split)
|
|||
title->setHasOffset(false);
|
||||
|
||||
// mode button
|
||||
auto mode = layout.emplace<Label>(this).assign(&this->modeButton);
|
||||
auto mode = layout.emplace<RippleEffectLabel>(nullptr).assign(&this->modeButton);
|
||||
|
||||
mode->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
mode->hide();
|
||||
|
||||
// QObject::connect(mode.getElement(), &RippleEffectButton::clicked, this, [this]
|
||||
// {
|
||||
// //
|
||||
// });
|
||||
this->setupModeLabel(*mode);
|
||||
|
||||
QObject::connect(mode.getElement(), &RippleEffectLabel::clicked, this, [this] {
|
||||
QTimer::singleShot(80, this, [&, this] {
|
||||
ChannelPtr _channel = this->split->getChannel();
|
||||
if (_channel->hasModRights()) {
|
||||
this->modeMenu.move(
|
||||
this->modeButton->mapToGlobal(QPoint(0, this->modeButton->height())));
|
||||
this->modeMenu.show();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// moderation mode
|
||||
auto moderator = layout.emplace<RippleEffectButton>(this).assign(&this->moderationButton);
|
||||
|
@ -66,30 +74,13 @@ SplitHeader::SplitHeader(Split *_split)
|
|||
|
||||
this->updateModerationModeIcon();
|
||||
|
||||
// auto misc = layout.emplace<RippleEffectButton>(this)
|
||||
// RippleEffectButton *moderationExtraButton;
|
||||
|
||||
// this->addModeItems(mode.getElement());
|
||||
// moderation misc actions
|
||||
// QObject::connect(mode.getElement(), &RippleEffectLabel::clicked, this, [this] {
|
||||
// QTimer::singleShot(80, this, [&, 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();
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
|
||||
// dropdown label
|
||||
auto dropdown = layout.emplace<RippleEffectButton>(this).assign(&this->dropdownButton);
|
||||
dropdown->setMouseTracking(true);
|
||||
// dropdown->setPixmap(*app->resources->splitHeaderContext->getPixmap());
|
||||
// dropdown->setScaleIndependantSize(23, 23);
|
||||
this->addDropdownItems(dropdown.getElement());
|
||||
QObject::connect(dropdown.getElement(), &RippleEffectButton::clicked, this, [this] {
|
||||
QObject::connect(dropdown.getElement(), &RippleEffectButton::leftMousePress, this, [this] {
|
||||
QTimer::singleShot(80, [&, this] {
|
||||
this->dropdownMenu.move(
|
||||
this->dropdownButton->mapToGlobal(QPoint(0, this->dropdownButton->height())));
|
||||
|
@ -113,6 +104,8 @@ SplitHeader::SplitHeader(Split *_split)
|
|||
this->managedConnect(app->accounts->twitch.currentUserChanged,
|
||||
[this] { this->updateModerationModeIcon(); });
|
||||
|
||||
this->addModeActions(this->modeMenu);
|
||||
|
||||
this->setMouseTracking(true);
|
||||
}
|
||||
|
||||
|
@ -158,11 +151,62 @@ void SplitHeader::addDropdownItems(RippleEffectButton *)
|
|||
// clang-format on
|
||||
}
|
||||
|
||||
void SplitHeader::updateModes()
|
||||
void SplitHeader::updateRoomModes()
|
||||
{
|
||||
this->modeUpdateRequested_.invoke();
|
||||
}
|
||||
|
||||
void SplitHeader::setupModeLabel(RippleEffectLabel &label)
|
||||
{
|
||||
this->managedConnections.push_back(this->modeUpdateRequested_.connect([this, &label] {
|
||||
auto twitchChannel = dynamic_cast<TwitchChannel *>(this->split->getChannel().get());
|
||||
|
||||
// return if the channel is not a twitch channel
|
||||
if (twitchChannel == nullptr) {
|
||||
label.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
// set lable enabled
|
||||
label.setEnable(twitchChannel->hasModRights());
|
||||
|
||||
// set the label text
|
||||
auto roomModes = twitchChannel->getRoomModes();
|
||||
QString text;
|
||||
|
||||
if (roomModes.r9k)
|
||||
text += "r9k, ";
|
||||
if (roomModes.slowMode)
|
||||
text += QString("slow(%1), ").arg(QString::number(roomModes.slowMode));
|
||||
if (roomModes.emoteOnly)
|
||||
text += "emote, ";
|
||||
if (roomModes.submode)
|
||||
text += "sub, ";
|
||||
|
||||
if (text.length() > 2) {
|
||||
text = text.mid(0, text.size() - 2);
|
||||
}
|
||||
|
||||
if (text.isEmpty()) {
|
||||
if (twitchChannel->hasModRights()) {
|
||||
label.getLabel().setText("none");
|
||||
label.show();
|
||||
} else {
|
||||
label.hide();
|
||||
}
|
||||
} else {
|
||||
static QRegularExpression commaReplacement("^.+?, .+?,( ).+$");
|
||||
QRegularExpressionMatch match = commaReplacement.match(text);
|
||||
if (match.hasMatch()) {
|
||||
text = text.mid(0, match.capturedStart(1)) + '\n' + text.mid(match.capturedEnd(1));
|
||||
}
|
||||
|
||||
label.getLabel().setText(text);
|
||||
label.show();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void SplitHeader::addModeActions(QMenu &menu)
|
||||
{
|
||||
auto setSub = new QAction("Subscriber only", this);
|
||||
|
@ -170,6 +214,11 @@ void SplitHeader::addModeActions(QMenu &menu)
|
|||
auto setSlow = new QAction("Slow", this);
|
||||
auto setR9k = new QAction("R9K", this);
|
||||
|
||||
setSub->setCheckable(true);
|
||||
setEmote->setCheckable(true);
|
||||
setSlow->setCheckable(true);
|
||||
setR9k->setCheckable(true);
|
||||
|
||||
menu.addAction(setEmote);
|
||||
menu.addAction(setSub);
|
||||
menu.addAction(setSlow);
|
||||
|
@ -189,52 +238,25 @@ void SplitHeader::addModeActions(QMenu &menu)
|
|||
setSlow->setChecked(roomModes.slowMode);
|
||||
setEmote->setChecked(roomModes.emoteOnly);
|
||||
setSub->setChecked(roomModes.submode);
|
||||
|
||||
QString text;
|
||||
|
||||
if (roomModes.r9k)
|
||||
text += "r9k, ";
|
||||
if (roomModes.slowMode)
|
||||
text += QString("slow(%1), ").arg(QString::number(roomModes.slowMode));
|
||||
if (roomModes.emoteOnly)
|
||||
text += "emote, ";
|
||||
if (roomModes.submode)
|
||||
text += "sub, ";
|
||||
|
||||
if (text.length() > 2) {
|
||||
text = text.mid(0, text.size() - 2);
|
||||
}
|
||||
|
||||
if (text.isEmpty()) {
|
||||
this->modeButton->hide();
|
||||
} else {
|
||||
static QRegularExpression commaReplacement("^.+?, .+?,( ).+$");
|
||||
QRegularExpressionMatch match = commaReplacement.match(text);
|
||||
if (match.hasMatch()) {
|
||||
text =
|
||||
text.mid(0, match.capturedStart(1)) + '\n' + text.mid(match.capturedEnd(1));
|
||||
}
|
||||
|
||||
this->modeButton->setText(text);
|
||||
this->modeButton->show();
|
||||
}
|
||||
}));
|
||||
|
||||
QObject::connect(setSub, &QAction::triggered, this, [setSub, this]() {
|
||||
QString sendCommand = "/subscribers";
|
||||
if (!setSub->isChecked()) {
|
||||
sendCommand.append("off");
|
||||
};
|
||||
this->split->getChannel().get()->sendMessage(sendCommand);
|
||||
});
|
||||
auto toggle = [this](const QString &_command, QAction *action) mutable {
|
||||
QString command = _command;
|
||||
|
||||
QObject::connect(setEmote, &QAction::triggered, this, [setEmote, this]() {
|
||||
QString sendCommand = "/emoteonly";
|
||||
if (!setEmote->isChecked()) {
|
||||
sendCommand.append("off");
|
||||
if (!action->isChecked()) {
|
||||
command += "off";
|
||||
};
|
||||
this->split->getChannel().get()->sendMessage(sendCommand);
|
||||
});
|
||||
action->setChecked(!action->isChecked());
|
||||
|
||||
qDebug() << command;
|
||||
this->split->getChannel().get()->sendMessage(command);
|
||||
};
|
||||
|
||||
QObject::connect(setSub, &QAction::triggered, this,
|
||||
[setSub, toggle]() mutable { toggle("/subscribers", setSub); });
|
||||
|
||||
QObject::connect(setEmote, &QAction::triggered, this,
|
||||
[setEmote, toggle]() mutable { toggle("/emoteonly", setEmote); });
|
||||
|
||||
QObject::connect(setSlow, &QAction::triggered, this, [setSlow, this]() {
|
||||
if (!setSlow->isChecked()) {
|
||||
|
@ -252,17 +274,8 @@ void SplitHeader::addModeActions(QMenu &menu)
|
|||
}
|
||||
});
|
||||
|
||||
QObject::connect(setR9k, &QAction::triggered, this, [setR9k, this]() {
|
||||
QString sendCommand = "/r9kbeta";
|
||||
if (!setR9k->isChecked()) {
|
||||
sendCommand.append("off");
|
||||
};
|
||||
this->split->getChannel().get()->sendMessage(sendCommand);
|
||||
});
|
||||
}
|
||||
|
||||
void SplitHeader::addModeItems(RippleEffectLabel *)
|
||||
{
|
||||
QObject::connect(setR9k, &QAction::triggered, this,
|
||||
[setR9k, toggle]() mutable { toggle("/r9kbeta", setR9k); });
|
||||
}
|
||||
|
||||
void SplitHeader::initializeChannelSignals()
|
||||
|
@ -282,7 +295,7 @@ void SplitHeader::initializeChannelSignals()
|
|||
|
||||
void SplitHeader::scaleChangedEvent(float scale)
|
||||
{
|
||||
int w = 28 * scale;
|
||||
int w = int(28 * scale);
|
||||
|
||||
this->setFixedHeight(w);
|
||||
this->dropdownButton->setFixedWidth(w);
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
// Update channel text from chat widget
|
||||
void updateChannelText();
|
||||
void updateModerationModeIcon();
|
||||
void updateModes();
|
||||
void updateRoomModes();
|
||||
|
||||
protected:
|
||||
virtual void scaleChangedEvent(float) override;
|
||||
|
@ -52,6 +52,8 @@ private:
|
|||
void rightButtonClicked();
|
||||
void initializeChannelSignals();
|
||||
void addModeActions(QMenu &menu);
|
||||
void setupModeLabel(RippleEffectLabel &label);
|
||||
void addDropdownItems(RippleEffectButton *label);
|
||||
|
||||
Split *const split;
|
||||
|
||||
|
@ -65,9 +67,8 @@ private:
|
|||
RippleEffectButton *dropdownButton = nullptr;
|
||||
// Label *titleLabel;
|
||||
Label *titleLabel = nullptr;
|
||||
Label *modeButton = nullptr;
|
||||
RippleEffectLabel *modeButton = nullptr;
|
||||
RippleEffectButton *moderationButton = nullptr;
|
||||
RippleEffectButton *moderationExtraButton = nullptr;
|
||||
|
||||
QMenu dropdownMenu;
|
||||
QMenu modeMenu;
|
||||
|
@ -80,8 +81,6 @@ private:
|
|||
std::vector<pajlada::Signals::ScopedConnection> managedConnections;
|
||||
|
||||
public slots:
|
||||
void addDropdownItems(RippleEffectButton *label);
|
||||
void addModeItems(RippleEffectLabel *label);
|
||||
|
||||
void menuMoveSplit();
|
||||
void menuReloadChannelEmotes();
|
||||
|
|
Loading…
Reference in a new issue