added toggle for moderation mode
This commit is contained in:
@@ -153,6 +153,8 @@ void ChannelView::actuallyLayoutMessages()
|
||||
// (this->scrollBar.isVisible() ? width() - this->scrollBar.width() : width()) - 4;
|
||||
int layoutWidth = LAYOUT_WIDTH;
|
||||
|
||||
MessageElement::Flags flags = this->getFlags();
|
||||
|
||||
// layout the visible messages in the view
|
||||
if (messagesSnapshot.getLength() > start) {
|
||||
int y =
|
||||
@@ -161,7 +163,7 @@ void ChannelView::actuallyLayoutMessages()
|
||||
for (size_t i = start; i < messagesSnapshot.getLength(); ++i) {
|
||||
auto message = messagesSnapshot[i];
|
||||
|
||||
redrawRequired |= message->layout(layoutWidth, this->getDpiMultiplier());
|
||||
redrawRequired |= message->layout(layoutWidth, this->getDpiMultiplier(), flags);
|
||||
|
||||
y += message->getHeight();
|
||||
|
||||
@@ -177,7 +179,7 @@ void ChannelView::actuallyLayoutMessages()
|
||||
for (int i = (int)messagesSnapshot.getLength() - 1; i >= 0; i--) {
|
||||
auto *message = messagesSnapshot[i].get();
|
||||
|
||||
message->layout(layoutWidth, this->getDpiMultiplier());
|
||||
message->layout(layoutWidth, this->getDpiMultiplier(), flags);
|
||||
|
||||
h -= message->getHeight();
|
||||
|
||||
@@ -432,6 +434,21 @@ void ChannelView::setSelection(const SelectionItem &start, const SelectionItem &
|
||||
// << max.charIndex;
|
||||
}
|
||||
|
||||
messages::MessageElement::Flags ChannelView::getFlags() const
|
||||
{
|
||||
MessageElement::Flags flags = MessageElement::Default;
|
||||
|
||||
Split *split = dynamic_cast<Split *>(this->parentWidget());
|
||||
|
||||
if (split != nullptr) {
|
||||
if (split->getModerationMode()) {
|
||||
flags = (MessageElement::Flags)(flags | MessageElement::ModeratorTools);
|
||||
}
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
void ChannelView::paintEvent(QPaintEvent * /*event*/)
|
||||
{
|
||||
// BENCH(timer);
|
||||
@@ -536,7 +553,8 @@ void ChannelView::wheelEvent(QWheelEvent *event)
|
||||
if (i == 0) {
|
||||
desired = 0;
|
||||
} else {
|
||||
snapshot[i - 1]->layout(LAYOUT_WIDTH, this->getDpiMultiplier());
|
||||
snapshot[i - 1]->layout(LAYOUT_WIDTH, this->getDpiMultiplier(),
|
||||
this->getFlags());
|
||||
scrollFactor = 1;
|
||||
currentScrollLeft = snapshot[i - 1]->getHeight();
|
||||
}
|
||||
@@ -558,7 +576,8 @@ void ChannelView::wheelEvent(QWheelEvent *event)
|
||||
if (i == snapshotLength - 1) {
|
||||
desired = snapshot.getLength();
|
||||
} else {
|
||||
snapshot[i + 1]->layout(LAYOUT_WIDTH, this->getDpiMultiplier());
|
||||
snapshot[i + 1]->layout(LAYOUT_WIDTH, this->getDpiMultiplier(),
|
||||
this->getFlags());
|
||||
|
||||
scrollFactor = 1;
|
||||
currentScrollLeft = snapshot[i + 1]->getHeight();
|
||||
|
||||
@@ -29,7 +29,7 @@ class ChannelView : public BaseWidget
|
||||
|
||||
public:
|
||||
explicit ChannelView(BaseWidget *parent = 0);
|
||||
~ChannelView();
|
||||
virtual ~ChannelView();
|
||||
|
||||
void queueUpdate();
|
||||
Scrollbar &getScrollBar();
|
||||
@@ -80,6 +80,7 @@ private:
|
||||
|
||||
void drawMessages(QPainter &painter);
|
||||
void setSelection(const messages::SelectionItem &start, const messages::SelectionItem &end);
|
||||
messages::MessageElement::Flags getFlags() const;
|
||||
|
||||
SharedChannel channel;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace widgets {
|
||||
|
||||
RippleEffectButton::RippleEffectButton(BaseWidget *parent)
|
||||
: BaseWidget(parent)
|
||||
|
||||
, pixmap(nullptr)
|
||||
{
|
||||
connect(&effectTimer, &QTimer::timeout, this, &RippleEffectButton::onMouseEffectTimeout);
|
||||
|
||||
@@ -23,11 +23,36 @@ void RippleEffectButton::setMouseEffectColor(boost::optional<QColor> color)
|
||||
this->mouseEffectColor = color;
|
||||
}
|
||||
|
||||
void RippleEffectButton::setPixmap(const QPixmap *_pixmap)
|
||||
{
|
||||
this->pixmap = const_cast<QPixmap *>(_pixmap);
|
||||
this->update();
|
||||
}
|
||||
|
||||
const QPixmap *RippleEffectButton::getPixmap() const
|
||||
{
|
||||
return this->pixmap;
|
||||
}
|
||||
|
||||
void RippleEffectButton::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
|
||||
this->fancyPaint(painter);
|
||||
|
||||
if (this->pixmap != nullptr) {
|
||||
QRect rect = this->rect();
|
||||
int xD = 6 * this->getDpiMultiplier();
|
||||
|
||||
rect.moveLeft(xD);
|
||||
rect.setRight(rect.right() - xD - xD);
|
||||
rect.moveTop(xD);
|
||||
rect.setBottom(rect.bottom() - xD - xD);
|
||||
|
||||
painter.drawPixmap(rect, *this->pixmap);
|
||||
}
|
||||
}
|
||||
|
||||
void RippleEffectButton::fancyPaint(QPainter &painter)
|
||||
|
||||
@@ -31,6 +31,8 @@ public:
|
||||
RippleEffectButton(BaseWidget *parent);
|
||||
|
||||
void setMouseEffectColor(boost::optional<QColor> color);
|
||||
void setPixmap(const QPixmap *pixmap);
|
||||
const QPixmap *getPixmap() const;
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
@@ -50,6 +52,7 @@ protected:
|
||||
void fancyPaint(QPainter &painter);
|
||||
|
||||
private:
|
||||
QPixmap *pixmap;
|
||||
QPoint mousePos;
|
||||
double hoverMultiplier = 0.0;
|
||||
QTimer effectTimer;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "widgets/helper/splitheader.hpp"
|
||||
#include "singletons/resourcemanager.hpp"
|
||||
#include "singletons/thememanager.hpp"
|
||||
#include "twitch/twitchchannel.hpp"
|
||||
#include "util/layoutcreator.hpp"
|
||||
@@ -21,20 +22,20 @@ SplitHeader::SplitHeader(Split *_split)
|
||||
{
|
||||
this->setMouseTracking(true);
|
||||
|
||||
singletons::ResourceManager &resourceManager = singletons::ResourceManager::getInstance();
|
||||
|
||||
util::LayoutCreator<SplitHeader> layoutCreator(this);
|
||||
auto layout = layoutCreator.emplace<QHBoxLayout>().withoutMargin();
|
||||
{
|
||||
// dropdown label
|
||||
auto dropdown = layout.emplace<RippleEffectLabel>(this).assign(&this->dropdownLabel);
|
||||
dropdown->getLabel().setTextFormat(Qt::RichText);
|
||||
dropdown->getLabel().setText("<img src=':/images/tool_moreCollapser_off16.png' />");
|
||||
dropdown->getLabel().setScaledContents(true);
|
||||
auto dropdown = layout.emplace<RippleEffectButton>(this).assign(&this->dropdownButton);
|
||||
dropdown->setMouseTracking(true);
|
||||
dropdown->setPixmap(resourceManager.splitHeaderContext->getPixmap());
|
||||
this->addDropdownItems(dropdown.getElement());
|
||||
QObject::connect(dropdown.getElement(), &RippleEffectLabel::clicked, this, [this] {
|
||||
QObject::connect(dropdown.getElement(), &RippleEffectButton::clicked, this, [this] {
|
||||
QTimer::singleShot(80, [&] {
|
||||
this->dropdownMenu.move(
|
||||
this->dropdownLabel->mapToGlobal(QPoint(0, this->dropdownLabel->height())));
|
||||
this->dropdownButton->mapToGlobal(QPoint(0, this->dropdownButton->height())));
|
||||
this->dropdownMenu.show();
|
||||
});
|
||||
});
|
||||
@@ -50,11 +51,13 @@ SplitHeader::SplitHeader(Split *_split)
|
||||
layout->addStretch(1);
|
||||
|
||||
// moderation mode
|
||||
auto moderation = layout.emplace<RippleEffectLabel>(this).assign(&this->moderationLabel);
|
||||
moderation->setMouseTracking(true);
|
||||
moderation->getLabel().setScaledContents(true);
|
||||
moderation->getLabel().setTextFormat(Qt::RichText);
|
||||
moderation->getLabel().setText("<img src=':/images/moderator_bg.png' />");
|
||||
auto moderator = layout.emplace<RippleEffectButton>(this).assign(&this->moderationButton);
|
||||
|
||||
QObject::connect(moderator.getElement(), &RippleEffectButton::clicked, this, [this] {
|
||||
this->split->setModerationMode(!this->split->getModerationMode());
|
||||
});
|
||||
|
||||
this->updateModerationModeIcon();
|
||||
}
|
||||
|
||||
// ---- misc
|
||||
@@ -63,8 +66,6 @@ SplitHeader::SplitHeader(Split *_split)
|
||||
|
||||
this->updateChannelText();
|
||||
|
||||
// this->titleLabel.setAlignment(Qt::AlignCenter);
|
||||
|
||||
this->initializeChannelSignals();
|
||||
|
||||
this->split->channelChanged.connect([this]() {
|
||||
@@ -77,11 +78,8 @@ SplitHeader::~SplitHeader()
|
||||
this->onlineStatusChangedConnection.disconnect();
|
||||
}
|
||||
|
||||
void SplitHeader::addDropdownItems(RippleEffectLabel *label)
|
||||
void SplitHeader::addDropdownItems(RippleEffectButton *label)
|
||||
{
|
||||
connect(this->dropdownLabel, &RippleEffectLabel::clicked, this,
|
||||
&SplitHeader::leftButtonClicked);
|
||||
|
||||
// clang-format off
|
||||
this->dropdownMenu.addAction("Add new split", this->split, &Split::doAddSplit, QKeySequence(tr("Ctrl+T")));
|
||||
this->dropdownMenu.addAction("Close split", this->split, &Split::doCloseSplit, QKeySequence(tr("Ctrl+W")));
|
||||
@@ -122,8 +120,8 @@ void SplitHeader::resizeEvent(QResizeEvent *event)
|
||||
int w = 28 * getDpiMultiplier();
|
||||
|
||||
this->setFixedHeight(w);
|
||||
this->dropdownLabel->setFixedWidth(w);
|
||||
this->moderationLabel->setFixedWidth(w);
|
||||
this->dropdownButton->setFixedWidth(w);
|
||||
this->moderationButton->setFixedWidth(w);
|
||||
}
|
||||
|
||||
void SplitHeader::updateChannelText()
|
||||
@@ -156,6 +154,14 @@ void SplitHeader::updateChannelText()
|
||||
}
|
||||
}
|
||||
|
||||
void SplitHeader::updateModerationModeIcon()
|
||||
{
|
||||
singletons::ResourceManager &resourceManager = singletons::ResourceManager::getInstance();
|
||||
this->moderationButton->setPixmap(this->split->getModerationMode()
|
||||
? resourceManager.moderationmode_enabled->getPixmap()
|
||||
: resourceManager.moderationmode_disabled->getPixmap());
|
||||
}
|
||||
|
||||
void SplitHeader::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
@@ -203,10 +209,6 @@ void SplitHeader::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void SplitHeader::leftButtonClicked()
|
||||
{
|
||||
}
|
||||
|
||||
void SplitHeader::rightButtonClicked()
|
||||
{
|
||||
}
|
||||
@@ -216,9 +218,9 @@ void SplitHeader::refreshTheme()
|
||||
QPalette palette;
|
||||
palette.setColor(QPalette::Foreground, this->themeManager.splits.header.text);
|
||||
|
||||
this->dropdownLabel->setPalette(palette);
|
||||
// this->dropdownButton->setPalette(palette);
|
||||
this->titleLabel->setPalette(palette);
|
||||
this->moderationLabel->setPalette(palette);
|
||||
// this->moderationLabel->setPalette(palette);
|
||||
}
|
||||
|
||||
void SplitHeader::menuMoveSplit()
|
||||
|
||||
@@ -30,6 +30,7 @@ public:
|
||||
|
||||
// Update channel text from chat widget
|
||||
void updateChannelText();
|
||||
void updateModerationModeIcon();
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent *) override;
|
||||
@@ -47,13 +48,12 @@ private:
|
||||
|
||||
boost::signals2::connection onlineStatusChangedConnection;
|
||||
|
||||
RippleEffectLabel *dropdownLabel;
|
||||
RippleEffectButton *dropdownButton;
|
||||
SignalLabel *titleLabel;
|
||||
RippleEffectLabel *moderationLabel;
|
||||
RippleEffectButton *moderationButton;
|
||||
|
||||
QMenu dropdownMenu;
|
||||
|
||||
void leftButtonClicked();
|
||||
void rightButtonClicked();
|
||||
|
||||
virtual void refreshTheme() override;
|
||||
@@ -64,7 +64,7 @@ private:
|
||||
bool isLive;
|
||||
|
||||
public slots:
|
||||
void addDropdownItems(RippleEffectLabel *label);
|
||||
void addDropdownItems(RippleEffectButton *label);
|
||||
|
||||
void menuMoveSplit();
|
||||
void menuReloadChannelEmotes();
|
||||
|
||||
@@ -52,6 +52,7 @@ Split::Split(SplitContainer *parent, const std::string &_uuid)
|
||||
, input(this)
|
||||
, flexSizeX(1)
|
||||
, flexSizeY(1)
|
||||
, moderationMode(false)
|
||||
{
|
||||
this->setMouseTracking(true);
|
||||
|
||||
@@ -115,6 +116,8 @@ Split::Split(SplitContainer *parent, const std::string &_uuid)
|
||||
this->input.show();
|
||||
}
|
||||
});
|
||||
|
||||
this->header.updateModerationModeIcon();
|
||||
}
|
||||
|
||||
Split::~Split()
|
||||
@@ -168,6 +171,19 @@ double Split::getFlexSizeY()
|
||||
return this->flexSizeY;
|
||||
}
|
||||
|
||||
void Split::setModerationMode(bool value)
|
||||
{
|
||||
if (value != this->moderationMode) {
|
||||
this->moderationMode = value;
|
||||
this->header.updateModerationModeIcon();
|
||||
}
|
||||
}
|
||||
|
||||
bool Split::getModerationMode() const
|
||||
{
|
||||
return this->moderationMode;
|
||||
}
|
||||
|
||||
void Split::channelNameUpdated(const std::string &newChannelName)
|
||||
{
|
||||
auto &cman = singletons::ChannelManager::getInstance();
|
||||
|
||||
@@ -62,6 +62,9 @@ public:
|
||||
void setFlexSizeY(double y);
|
||||
double getFlexSizeY();
|
||||
|
||||
void setModerationMode(bool value);
|
||||
bool getModerationMode() const;
|
||||
|
||||
bool showChangeChannelPopup(const char *dialogTitle, bool empty = false);
|
||||
void giveFocus(Qt::FocusReason reason);
|
||||
bool hasFocus() const;
|
||||
@@ -88,6 +91,8 @@ private:
|
||||
double flexSizeX;
|
||||
double flexSizeY;
|
||||
|
||||
bool moderationMode;
|
||||
|
||||
boost::signals2::connection channelIDChangedConnection;
|
||||
|
||||
void setChannel(SharedChannel newChannel);
|
||||
|
||||
Reference in New Issue
Block a user