added room mode selector for mods again

This commit is contained in:
fourtf 2018-07-04 19:43:41 +02:00
parent e9a112f8b3
commit 14f125ff87
9 changed files with 148 additions and 97 deletions

View file

@ -203,6 +203,12 @@ bool Channel::isBroadcaster() const
return false; return false;
} }
bool Channel::hasModRights() const
{
// fourtf: check if staff
return this->isMod() || this->isBroadcaster();
}
std::shared_ptr<Channel> Channel::getEmpty() std::shared_ptr<Channel> Channel::getEmpty()
{ {
static std::shared_ptr<Channel> channel(new Channel("", None)); static std::shared_ptr<Channel> channel(new Channel("", None));

View file

@ -61,6 +61,7 @@ public:
virtual void sendMessage(const QString &message); virtual void sendMessage(const QString &message);
virtual bool isMod() const; virtual bool isMod() const;
virtual bool isBroadcaster() const; virtual bool isBroadcaster() const;
virtual bool hasModRights() const;
static std::shared_ptr<Channel> getEmpty(); static std::shared_ptr<Channel> getEmpty();

View file

@ -197,12 +197,6 @@ bool TwitchChannel::isBroadcaster() const
return this->name == app->accounts->twitch.getCurrent()->getUserName(); 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) void TwitchChannel::addRecentChatter(const std::shared_ptr<Message> &message)
{ {
assert(!message->loginName.isEmpty()); assert(!message->loginName.isEmpty());

View file

@ -54,10 +54,9 @@ public:
bool canSendMessage() const override; bool canSendMessage() const override;
void sendMessage(const QString &message) override; void sendMessage(const QString &message) override;
bool isMod() const override; virtual bool isMod() const override;
void setMod(bool value); void setMod(bool value);
bool isBroadcaster() const override; virtual bool isBroadcaster() const override;
bool hasModRights();
void addRecentChatter(const std::shared_ptr<Message> &message) final; void addRecentChatter(const std::shared_ptr<Message> &message) final;
void addJoinedUser(const QString &user); void addJoinedUser(const QString &user);

View file

@ -46,6 +46,18 @@ bool RippleEffectButton::getDim() const
return this->dimPixmap_; return this->dimPixmap_;
} }
void RippleEffectButton::setEnable(bool value)
{
this->enabled_ = value;
this->update();
}
bool RippleEffectButton::getEnable() const
{
return this->enabled_;
}
qreal RippleEffectButton::getCurrentDimAmount() const qreal RippleEffectButton::getCurrentDimAmount() const
{ {
return this->dimPixmap_ && !this->mouseOver_ ? 0.7 : 1; return this->dimPixmap_ && !this->mouseOver_ ? 0.7 : 1;
@ -54,6 +66,8 @@ qreal RippleEffectButton::getCurrentDimAmount() const
void RippleEffectButton::setBorderColor(const QColor &color) void RippleEffectButton::setBorderColor(const QColor &color)
{ {
this->borderColor_ = color; this->borderColor_ = color;
this->update();
} }
const QColor &RippleEffectButton::getBorderColor() const const QColor &RippleEffectButton::getBorderColor() const
@ -68,7 +82,7 @@ void RippleEffectButton::paintEvent(QPaintEvent *)
painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.setRenderHint(QPainter::SmoothPixmapTransform);
if (!this->pixmap_.isNull()) { if (!this->pixmap_.isNull()) {
if (!this->mouseOver_ && this->dimPixmap_) { if (!this->mouseOver_ && this->dimPixmap_ && this->enabled_) {
painter.setOpacity(this->getCurrentDimAmount()); painter.setOpacity(this->getCurrentDimAmount());
} }
@ -96,6 +110,10 @@ void RippleEffectButton::paintEvent(QPaintEvent *)
void RippleEffectButton::fancyPaint(QPainter &painter) void RippleEffectButton::fancyPaint(QPainter &painter)
{ {
if (!this->enabled_) {
return;
}
painter.setRenderHint(QPainter::HighQualityAntialiasing); painter.setRenderHint(QPainter::HighQualityAntialiasing);
painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::Antialiasing);
QColor c; QColor c;
@ -144,6 +162,10 @@ void RippleEffectButton::leaveEvent(QEvent *)
void RippleEffectButton::mousePressEvent(QMouseEvent *event) void RippleEffectButton::mousePressEvent(QMouseEvent *event)
{ {
if (!this->enabled_) {
return;
}
if (event->button() != Qt::LeftButton) { if (event->button() != Qt::LeftButton) {
return; return;
} }
@ -151,10 +173,16 @@ void RippleEffectButton::mousePressEvent(QMouseEvent *event)
this->clickEffects_.push_back(ClickEffect(event->pos())); this->clickEffects_.push_back(ClickEffect(event->pos()));
this->mouseDown_ = true; this->mouseDown_ = true;
emit this->leftMousePress();
} }
void RippleEffectButton::mouseReleaseEvent(QMouseEvent *event) void RippleEffectButton::mouseReleaseEvent(QMouseEvent *event)
{ {
if (!this->enabled_) {
return;
}
if (event->button() != Qt::LeftButton) { if (event->button() != Qt::LeftButton) {
return; return;
} }
@ -168,6 +196,10 @@ void RippleEffectButton::mouseReleaseEvent(QMouseEvent *event)
void RippleEffectButton::mouseMoveEvent(QMouseEvent *event) void RippleEffectButton::mouseMoveEvent(QMouseEvent *event)
{ {
if (!this->enabled_) {
return;
}
this->mousePos_ = event->pos(); this->mousePos_ = event->pos();
this->update(); this->update();

View file

@ -37,13 +37,18 @@ public:
bool getDim() const; bool getDim() const;
qreal getCurrentDimAmount() const; qreal getCurrentDimAmount() const;
void setEnable(bool value);
bool getEnable() const;
void setBorderColor(const QColor &color); void setBorderColor(const QColor &color);
const QColor &getBorderColor() const; const QColor &getBorderColor() const;
signals: signals:
void clicked(); void clicked();
void leftMousePress();
protected: protected:
bool enabled_ = true;
bool selected_ = false; bool selected_ = false;
bool mouseOver_ = false; bool mouseOver_ = false;
bool mouseDown_ = false; bool mouseDown_ = false;

View file

@ -193,11 +193,13 @@ void Split::setChannel(IndirectChannel newChannel)
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(newChannel.get().get()); TwitchChannel *tc = dynamic_cast<TwitchChannel *>(newChannel.get().get());
if (tc != nullptr) { if (tc != nullptr) {
this->usermodeChangedConnection = this->usermodeChangedConnection = tc->userStateChanged.connect([this] {
tc->userStateChanged.connect([this] { this->header.updateModerationModeIcon(); }); this->header.updateModerationModeIcon();
this->header.updateRoomModes();
});
this->roomModeChangedConnection = this->roomModeChangedConnection =
tc->roomModesChanged.connect([this] { this->header.updateModes(); }); tc->roomModesChanged.connect([this] { this->header.updateRoomModes(); });
} }
this->indirectChannelChangedConnection = newChannel.getChannelChanged().connect([this] { // this->indirectChannelChangedConnection = newChannel.getChannelChanged().connect([this] { //
@ -206,7 +208,7 @@ void Split::setChannel(IndirectChannel newChannel)
this->header.updateModerationModeIcon(); this->header.updateModerationModeIcon();
this->header.updateChannelText(); this->header.updateChannelText();
this->header.updateModes(); this->header.updateRoomModes();
this->channelChanged.invoke(); this->channelChanged.invoke();
} }

View file

@ -44,15 +44,23 @@ SplitHeader::SplitHeader(Split *_split)
title->setHasOffset(false); title->setHasOffset(false);
// mode button // 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->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
mode->hide(); 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 // moderation mode
auto moderator = layout.emplace<RippleEffectButton>(this).assign(&this->moderationButton); auto moderator = layout.emplace<RippleEffectButton>(this).assign(&this->moderationButton);
@ -66,30 +74,13 @@ SplitHeader::SplitHeader(Split *_split)
this->updateModerationModeIcon(); 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 // dropdown label
auto dropdown = layout.emplace<RippleEffectButton>(this).assign(&this->dropdownButton); auto dropdown = layout.emplace<RippleEffectButton>(this).assign(&this->dropdownButton);
dropdown->setMouseTracking(true); dropdown->setMouseTracking(true);
// dropdown->setPixmap(*app->resources->splitHeaderContext->getPixmap()); // dropdown->setPixmap(*app->resources->splitHeaderContext->getPixmap());
// dropdown->setScaleIndependantSize(23, 23); // dropdown->setScaleIndependantSize(23, 23);
this->addDropdownItems(dropdown.getElement()); this->addDropdownItems(dropdown.getElement());
QObject::connect(dropdown.getElement(), &RippleEffectButton::clicked, this, [this] { QObject::connect(dropdown.getElement(), &RippleEffectButton::leftMousePress, this, [this] {
QTimer::singleShot(80, [&, this] { 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())));
@ -113,6 +104,8 @@ SplitHeader::SplitHeader(Split *_split)
this->managedConnect(app->accounts->twitch.currentUserChanged, this->managedConnect(app->accounts->twitch.currentUserChanged,
[this] { this->updateModerationModeIcon(); }); [this] { this->updateModerationModeIcon(); });
this->addModeActions(this->modeMenu);
this->setMouseTracking(true); this->setMouseTracking(true);
} }
@ -158,11 +151,62 @@ void SplitHeader::addDropdownItems(RippleEffectButton *)
// clang-format on // clang-format on
} }
void SplitHeader::updateModes() void SplitHeader::updateRoomModes()
{ {
this->modeUpdateRequested_.invoke(); 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) void SplitHeader::addModeActions(QMenu &menu)
{ {
auto setSub = new QAction("Subscriber only", this); auto setSub = new QAction("Subscriber only", this);
@ -170,6 +214,11 @@ void SplitHeader::addModeActions(QMenu &menu)
auto setSlow = new QAction("Slow", this); auto setSlow = new QAction("Slow", this);
auto setR9k = new QAction("R9K", this); auto setR9k = new QAction("R9K", this);
setSub->setCheckable(true);
setEmote->setCheckable(true);
setSlow->setCheckable(true);
setR9k->setCheckable(true);
menu.addAction(setEmote); menu.addAction(setEmote);
menu.addAction(setSub); menu.addAction(setSub);
menu.addAction(setSlow); menu.addAction(setSlow);
@ -189,52 +238,25 @@ void SplitHeader::addModeActions(QMenu &menu)
setSlow->setChecked(roomModes.slowMode); setSlow->setChecked(roomModes.slowMode);
setEmote->setChecked(roomModes.emoteOnly); setEmote->setChecked(roomModes.emoteOnly);
setSub->setChecked(roomModes.submode); 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]() { auto toggle = [this](const QString &_command, QAction *action) mutable {
QString sendCommand = "/subscribers"; QString command = _command;
if (!setSub->isChecked()) {
sendCommand.append("off");
};
this->split->getChannel().get()->sendMessage(sendCommand);
});
QObject::connect(setEmote, &QAction::triggered, this, [setEmote, this]() { if (!action->isChecked()) {
QString sendCommand = "/emoteonly"; command += "off";
if (!setEmote->isChecked()) {
sendCommand.append("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]() { QObject::connect(setSlow, &QAction::triggered, this, [setSlow, this]() {
if (!setSlow->isChecked()) { if (!setSlow->isChecked()) {
@ -252,17 +274,8 @@ void SplitHeader::addModeActions(QMenu &menu)
} }
}); });
QObject::connect(setR9k, &QAction::triggered, this, [setR9k, this]() { QObject::connect(setR9k, &QAction::triggered, this,
QString sendCommand = "/r9kbeta"; [setR9k, toggle]() mutable { toggle("/r9kbeta", setR9k); });
if (!setR9k->isChecked()) {
sendCommand.append("off");
};
this->split->getChannel().get()->sendMessage(sendCommand);
});
}
void SplitHeader::addModeItems(RippleEffectLabel *)
{
} }
void SplitHeader::initializeChannelSignals() void SplitHeader::initializeChannelSignals()
@ -282,7 +295,7 @@ void SplitHeader::initializeChannelSignals()
void SplitHeader::scaleChangedEvent(float scale) void SplitHeader::scaleChangedEvent(float scale)
{ {
int w = 28 * scale; int w = int(28 * scale);
this->setFixedHeight(w); this->setFixedHeight(w);
this->dropdownButton->setFixedWidth(w); this->dropdownButton->setFixedWidth(w);

View file

@ -34,7 +34,7 @@ public:
// Update channel text from chat widget // Update channel text from chat widget
void updateChannelText(); void updateChannelText();
void updateModerationModeIcon(); void updateModerationModeIcon();
void updateModes(); void updateRoomModes();
protected: protected:
virtual void scaleChangedEvent(float) override; virtual void scaleChangedEvent(float) override;
@ -52,6 +52,8 @@ private:
void rightButtonClicked(); void rightButtonClicked();
void initializeChannelSignals(); void initializeChannelSignals();
void addModeActions(QMenu &menu); void addModeActions(QMenu &menu);
void setupModeLabel(RippleEffectLabel &label);
void addDropdownItems(RippleEffectButton *label);
Split *const split; Split *const split;
@ -65,9 +67,8 @@ private:
RippleEffectButton *dropdownButton = nullptr; RippleEffectButton *dropdownButton = nullptr;
// Label *titleLabel; // Label *titleLabel;
Label *titleLabel = nullptr; Label *titleLabel = nullptr;
Label *modeButton = nullptr; RippleEffectLabel *modeButton = nullptr;
RippleEffectButton *moderationButton = nullptr; RippleEffectButton *moderationButton = nullptr;
RippleEffectButton *moderationExtraButton = nullptr;
QMenu dropdownMenu; QMenu dropdownMenu;
QMenu modeMenu; QMenu modeMenu;
@ -80,8 +81,6 @@ private:
std::vector<pajlada::Signals::ScopedConnection> managedConnections; std::vector<pajlada::Signals::ScopedConnection> managedConnections;
public slots: public slots:
void addDropdownItems(RippleEffectButton *label);
void addModeItems(RippleEffectLabel *label);
void menuMoveSplit(); void menuMoveSplit();
void menuReloadChannelEmotes(); void menuReloadChannelEmotes();