mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
reworked splitheader a bit
This commit is contained in:
parent
4ea613503e
commit
19fdfaef42
BIN
resources/images/menu_black.png
Normal file
BIN
resources/images/menu_black.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 331 B |
BIN
resources/images/menu_white.png
Normal file
BIN
resources/images/menu_white.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 328 B |
|
@ -67,6 +67,8 @@
|
|||
<file>images/buttons/unmod.png</file>
|
||||
<file>images/emote_dark.svg</file>
|
||||
<file>tlds.txt</file>
|
||||
<file>images/menu_black.png</file>
|
||||
<file>images/menu_white.png</file>
|
||||
</qresource>
|
||||
<qresource prefix="/qt/etc">
|
||||
<file>qt.conf</file>
|
||||
|
|
|
@ -417,25 +417,36 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
|
|||
#ifdef USEWINSDK
|
||||
MSG *msg = reinterpret_cast<MSG *>(message);
|
||||
|
||||
bool returnValue = false;
|
||||
|
||||
switch (msg->message) {
|
||||
case WM_DPICHANGED:
|
||||
return handleDPICHANGED(msg);
|
||||
returnValue = handleDPICHANGED(msg);
|
||||
break;
|
||||
|
||||
case WM_SHOWWINDOW:
|
||||
return this->handleSHOWWINDOW(msg);
|
||||
returnValue = this->handleSHOWWINDOW(msg);
|
||||
break;
|
||||
|
||||
case WM_NCCALCSIZE:
|
||||
return this->handleNCCALCSIZE(msg, result);
|
||||
returnValue = this->handleNCCALCSIZE(msg, result);
|
||||
break;
|
||||
|
||||
case WM_SIZE:
|
||||
return this->handleSIZE(msg);
|
||||
returnValue = this->handleSIZE(msg);
|
||||
break;
|
||||
|
||||
case WM_NCHITTEST:
|
||||
return this->handleNCHITTEST(msg, result);
|
||||
returnValue = this->handleNCHITTEST(msg, result);
|
||||
break;
|
||||
|
||||
default:
|
||||
return QWidget::nativeEvent(eventType, message, result);
|
||||
}
|
||||
|
||||
QWidget::nativeEvent(eventType, message, result);
|
||||
|
||||
return returnValue;
|
||||
#else
|
||||
return QWidget::nativeEvent(eventType, message, result);
|
||||
#endif
|
||||
|
@ -603,7 +614,7 @@ bool BaseWindow::handleSIZE(MSG *msg)
|
|||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
|
|
@ -34,6 +34,18 @@ const QPixmap &RippleEffectButton::getPixmap() const
|
|||
return this->pixmap_;
|
||||
}
|
||||
|
||||
void RippleEffectButton::setDimPixmap(bool value)
|
||||
{
|
||||
this->dimPixmap_ = value;
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
bool RippleEffectButton::getDimPixmap() const
|
||||
{
|
||||
return this->dimPixmap_;
|
||||
}
|
||||
|
||||
void RippleEffectButton::setBorderColor(const QColor &color)
|
||||
{
|
||||
this->borderColor_ = color;
|
||||
|
@ -51,6 +63,10 @@ void RippleEffectButton::paintEvent(QPaintEvent *)
|
|||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
|
||||
if (!this->pixmap_.isNull()) {
|
||||
if (!this->mouseOver_ && this->dimPixmap_) {
|
||||
painter.setOpacity(0.7);
|
||||
}
|
||||
|
||||
QRect rect = this->rect();
|
||||
int s = int(6 * this->getScale());
|
||||
|
||||
|
@ -60,6 +76,8 @@ void RippleEffectButton::paintEvent(QPaintEvent *)
|
|||
rect.setBottom(rect.bottom() - s - s);
|
||||
|
||||
painter.drawPixmap(rect, this->pixmap_);
|
||||
|
||||
painter.setOpacity(1);
|
||||
}
|
||||
|
||||
this->fancyPaint(painter);
|
||||
|
|
|
@ -33,6 +33,9 @@ public:
|
|||
void setPixmap(const QPixmap &pixmap_);
|
||||
const QPixmap &getPixmap() const;
|
||||
|
||||
void setDimPixmap(bool value);
|
||||
bool getDimPixmap() const;
|
||||
|
||||
void setBorderColor(const QColor &color);
|
||||
const QColor &getBorderColor() const;
|
||||
|
||||
|
@ -56,6 +59,7 @@ protected:
|
|||
private:
|
||||
QColor borderColor_;
|
||||
QPixmap pixmap_;
|
||||
bool dimPixmap_ = true;
|
||||
QPoint mousePos_;
|
||||
double hoverMultiplier_ = 0.0;
|
||||
QTimer effectTimer_;
|
||||
|
|
|
@ -35,20 +35,8 @@ SplitHeader::SplitHeader(Split *_split)
|
|||
|
||||
LayoutCreator<SplitHeader> layoutCreator(this);
|
||||
auto layout = layoutCreator.emplace<QHBoxLayout>().withoutMargin();
|
||||
layout->setSpacing(0);
|
||||
{
|
||||
// dropdown label
|
||||
auto dropdown = layout.emplace<RippleEffectButton>(this).assign(&this->dropdownButton);
|
||||
dropdown->setMouseTracking(true);
|
||||
dropdown->setPixmap(*app->resources->splitHeaderContext->getPixmap());
|
||||
this->addDropdownItems(dropdown.getElement());
|
||||
QObject::connect(dropdown.getElement(), &RippleEffectButton::clicked, this, [this] {
|
||||
QTimer::singleShot(80, [&, this] {
|
||||
this->dropdownMenu.move(
|
||||
this->dropdownButton->mapToGlobal(QPoint(0, this->dropdownButton->height())));
|
||||
this->dropdownMenu.show();
|
||||
});
|
||||
});
|
||||
|
||||
// channel name label
|
||||
auto title = layout.emplace<Label>().assign(&this->titleLabel);
|
||||
title->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
||||
|
@ -56,19 +44,8 @@ SplitHeader::SplitHeader(Split *_split)
|
|||
title->setHasOffset(false);
|
||||
|
||||
// mode button
|
||||
auto mode = layout.emplace<RippleEffectLabel>(this).assign(&this->modeButton);
|
||||
this->addModeItems(mode.getElement());
|
||||
auto mode = layout.emplace<Label>(this).assign(&this->modeButton);
|
||||
|
||||
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->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
mode->hide();
|
||||
|
||||
|
@ -80,11 +57,46 @@ SplitHeader::SplitHeader(Split *_split)
|
|||
// moderation mode
|
||||
auto moderator = layout.emplace<RippleEffectButton>(this).assign(&this->moderationButton);
|
||||
|
||||
QObject::connect(moderator.getElement(), &RippleEffectButton::clicked, this, [this] {
|
||||
this->split->setModerationMode(!this->split->getModerationMode());
|
||||
});
|
||||
QObject::connect(moderator.getElement(), &RippleEffectButton::clicked, this,
|
||||
[this, moderator]() mutable {
|
||||
this->split->setModerationMode(!this->split->getModerationMode());
|
||||
|
||||
moderator->setDimPixmap(!this->split->getModerationMode());
|
||||
});
|
||||
|
||||
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->setPixmap(QPixmap(":/images/menu_white.png"));
|
||||
// dropdown->setScaleIndependantSize(23, 23);
|
||||
this->addDropdownItems(dropdown.getElement());
|
||||
QObject::connect(dropdown.getElement(), &RippleEffectButton::clicked, this, [this] {
|
||||
QTimer::singleShot(80, [&, this] {
|
||||
this->dropdownMenu.move(
|
||||
this->dropdownButton->mapToGlobal(QPoint(0, this->dropdownButton->height())));
|
||||
this->dropdownMenu.show();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ---- misc
|
||||
|
@ -147,11 +159,67 @@ void SplitHeader::addDropdownItems(RippleEffectButton *)
|
|||
// clang-format on
|
||||
}
|
||||
|
||||
void SplitHeader::addModeItems(RippleEffectLabel *)
|
||||
void SplitHeader::updateModes()
|
||||
{
|
||||
QAction *setSub = new QAction("Submode", this);
|
||||
this->setSub = setSub;
|
||||
setSub->setCheckable(true);
|
||||
this->modeUpdateRequested_.invoke();
|
||||
}
|
||||
|
||||
void SplitHeader::addModeActions(QMenu &menu)
|
||||
{
|
||||
auto setSub = new QAction("Subscriber only", this);
|
||||
auto setEmote = new QAction("Emote only", this);
|
||||
auto setSlow = new QAction("Slow", this);
|
||||
auto setR9k = new QAction("R9K", this);
|
||||
|
||||
menu.addAction(setEmote);
|
||||
menu.addAction(setSub);
|
||||
menu.addAction(setSlow);
|
||||
menu.addAction(setR9k);
|
||||
|
||||
this->managedConnections.push_back(this->modeUpdateRequested_.connect( //
|
||||
[this, setSub, setEmote, setSlow, setR9k]() {
|
||||
auto twitchChannel = dynamic_cast<TwitchChannel *>(this->split->getChannel().get());
|
||||
if (twitchChannel == nullptr) {
|
||||
this->modeButton->hide();
|
||||
return;
|
||||
}
|
||||
|
||||
auto roomModes = twitchChannel->getRoomModes();
|
||||
|
||||
setR9k->setChecked(roomModes.r9k);
|
||||
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";
|
||||
|
@ -161,10 +229,6 @@ void SplitHeader::addModeItems(RippleEffectLabel *)
|
|||
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()) {
|
||||
|
@ -173,10 +237,6 @@ void SplitHeader::addModeItems(RippleEffectLabel *)
|
|||
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");
|
||||
|
@ -193,10 +253,6 @@ void SplitHeader::addModeItems(RippleEffectLabel *)
|
|||
}
|
||||
});
|
||||
|
||||
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()) {
|
||||
|
@ -204,11 +260,10 @@ void SplitHeader::addModeItems(RippleEffectLabel *)
|
|||
};
|
||||
this->split->getChannel().get()->sendMessage(sendCommand);
|
||||
});
|
||||
}
|
||||
|
||||
this->modeMenu.addAction(setEmote);
|
||||
this->modeMenu.addAction(setSub);
|
||||
this->modeMenu.addAction(setSlow);
|
||||
this->modeMenu.addAction(setR9k);
|
||||
void SplitHeader::addModeItems(RippleEffectLabel *)
|
||||
{
|
||||
}
|
||||
|
||||
void SplitHeader::initializeChannelSignals()
|
||||
|
@ -303,62 +358,6 @@ void SplitHeader::updateModerationModeIcon()
|
|||
this->moderationButton->setVisible(modButtonVisible);
|
||||
}
|
||||
|
||||
void SplitHeader::updateModes()
|
||||
{
|
||||
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(this->split->getChannel().get());
|
||||
if (tc == nullptr) {
|
||||
this->modeButton->hide();
|
||||
return;
|
||||
}
|
||||
|
||||
TwitchChannel::RoomModes roomModes = tc->getRoomModes();
|
||||
|
||||
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()) {
|
||||
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->getLabel().setText(text);
|
||||
this->modeButton->show();
|
||||
}
|
||||
}
|
||||
|
||||
void SplitHeader::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
|
|
@ -49,6 +49,10 @@ protected:
|
|||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
void rightButtonClicked();
|
||||
void initializeChannelSignals();
|
||||
void addModeActions(QMenu &menu);
|
||||
|
||||
Split *const split;
|
||||
|
||||
QPoint dragStart;
|
||||
|
@ -58,23 +62,17 @@ private:
|
|||
|
||||
pajlada::Signals::Connection onlineStatusChangedConnection;
|
||||
|
||||
RippleEffectButton *dropdownButton;
|
||||
RippleEffectButton *dropdownButton = nullptr;
|
||||
// Label *titleLabel;
|
||||
Label *titleLabel;
|
||||
RippleEffectLabel *modeButton;
|
||||
RippleEffectButton *moderationButton;
|
||||
Label *titleLabel = nullptr;
|
||||
Label *modeButton = nullptr;
|
||||
RippleEffectButton *moderationButton = nullptr;
|
||||
RippleEffectButton *moderationExtraButton = nullptr;
|
||||
|
||||
QMenu dropdownMenu;
|
||||
QMenu modeMenu;
|
||||
|
||||
QAction *setSub = nullptr;
|
||||
QAction *setEmote = nullptr;
|
||||
QAction *setSlow = nullptr;
|
||||
QAction *setR9k = nullptr;
|
||||
|
||||
void rightButtonClicked();
|
||||
|
||||
void initializeChannelSignals();
|
||||
pajlada::Signals::NoArgSignal modeUpdateRequested_;
|
||||
|
||||
QString tooltip;
|
||||
bool isLive;
|
||||
|
|
Loading…
Reference in a new issue