mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
refactored the SplitHeader
This commit is contained in:
parent
c79f88ed10
commit
61d0229b4c
|
@ -1,6 +1,7 @@
|
||||||
#include "widgets/helper/splitheader.hpp"
|
#include "widgets/helper/splitheader.hpp"
|
||||||
#include "singletons/thememanager.hpp"
|
#include "singletons/thememanager.hpp"
|
||||||
#include "twitch/twitchchannel.hpp"
|
#include "twitch/twitchchannel.hpp"
|
||||||
|
#include "util/layoutcreator.hpp"
|
||||||
#include "util/urlfetch.hpp"
|
#include "util/urlfetch.hpp"
|
||||||
#include "widgets/split.hpp"
|
#include "widgets/split.hpp"
|
||||||
#include "widgets/splitcontainer.hpp"
|
#include "widgets/splitcontainer.hpp"
|
||||||
|
@ -14,79 +15,101 @@
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
namespace widgets {
|
namespace widgets {
|
||||||
|
|
||||||
SplitHeader::SplitHeader(Split *_chatWidget)
|
SplitHeader::SplitHeader(Split *_split)
|
||||||
: BaseWidget(_chatWidget)
|
: BaseWidget(_split)
|
||||||
, chatWidget(_chatWidget)
|
, split(_split)
|
||||||
, leftLabel(this)
|
|
||||||
, leftMenu(this)
|
|
||||||
, rightLabel(this)
|
|
||||||
, rightMenu(this)
|
|
||||||
{
|
{
|
||||||
this->setMouseTracking(true);
|
this->setMouseTracking(true);
|
||||||
this->leftLabel.setMouseTracking(true);
|
|
||||||
this->channelNameLabel.setMouseTracking(true);
|
|
||||||
this->rightLabel.setMouseTracking(true);
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
dropdown->setMouseTracking(true);
|
||||||
|
this->addDropdownItems(dropdown.getElement());
|
||||||
|
QObject::connect(dropdown.getElement(), &RippleEffectLabel::clicked, this, [this] {
|
||||||
|
QTimer::singleShot(80, [&] {
|
||||||
|
this->dropdownMenu.move(
|
||||||
|
this->dropdownLabel->mapToGlobal(QPoint(0, this->dropdownLabel->height())));
|
||||||
|
this->dropdownMenu.show();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// channel name label
|
||||||
|
auto title = layout.emplace<SignalLabel>().assign(&this->titleLabel);
|
||||||
|
title->setMouseTracking(true);
|
||||||
|
QSizePolicy policy;
|
||||||
|
policy.setHorizontalStretch(1);
|
||||||
|
policy.setHorizontalPolicy(QSizePolicy::Policy::Expanding);
|
||||||
|
title->setSizePolicy(policy);
|
||||||
|
// title->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||||
|
// layout->setStretch(1, 1000);
|
||||||
|
QObject::connect(this->titleLabel, &SignalLabel::mouseDoubleClick, this,
|
||||||
|
&SplitHeader::mouseDoubleClickEvent);
|
||||||
|
|
||||||
|
// 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/tool_moreCollapser_off16.png' />");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- misc
|
||||||
|
this->layout()->setMargin(0);
|
||||||
this->refreshTheme();
|
this->refreshTheme();
|
||||||
|
|
||||||
this->updateChannelText();
|
this->updateChannelText();
|
||||||
|
|
||||||
this->setLayout(&this->hbox);
|
// this->titleLabel.setAlignment(Qt::AlignCenter);
|
||||||
this->hbox.setMargin(0);
|
|
||||||
this->hbox.addWidget(&this->leftLabel);
|
|
||||||
this->hbox.addWidget(&this->channelNameLabel, 1);
|
|
||||||
this->hbox.addWidget(&this->rightLabel);
|
|
||||||
|
|
||||||
// left
|
|
||||||
this->leftLabel.getLabel().setTextFormat(Qt::RichText);
|
|
||||||
this->leftLabel.getLabel().setText("<img src=':/images/tool_moreCollapser_off16.png' />");
|
|
||||||
|
|
||||||
connect(&this->leftLabel, &RippleEffectLabel::clicked, this, &SplitHeader::leftButtonClicked);
|
|
||||||
|
|
||||||
this->leftMenu.addAction("Add new split", this->chatWidget, &Split::doAddSplit,
|
|
||||||
QKeySequence(tr("Ctrl+T")));
|
|
||||||
this->leftMenu.addAction("Close split", this->chatWidget, &Split::doCloseSplit,
|
|
||||||
QKeySequence(tr("Ctrl+W")));
|
|
||||||
this->leftMenu.addAction("Move split", this, SLOT(menuMoveSplit()));
|
|
||||||
this->leftMenu.addAction("Popup", this->chatWidget, &Split::doPopup);
|
|
||||||
this->leftMenu.addAction("Open viewer list", this->chatWidget, &Split::doOpenViewerList);
|
|
||||||
this->leftMenu.addSeparator();
|
|
||||||
this->leftMenu.addAction("Change channel", this->chatWidget, &Split::doChangeChannel,
|
|
||||||
QKeySequence(tr("Ctrl+R")));
|
|
||||||
this->leftMenu.addAction("Clear chat", this->chatWidget, &Split::doClearChat);
|
|
||||||
this->leftMenu.addAction("Open channel", this->chatWidget, &Split::doOpenChannel);
|
|
||||||
this->leftMenu.addAction("Open popup player", this->chatWidget, &Split::doOpenPopupPlayer);
|
|
||||||
this->leftMenu.addAction("Open in Streamlink", this->chatWidget, &Split::doOpenStreamlink);
|
|
||||||
this->leftMenu.addSeparator();
|
|
||||||
this->leftMenu.addAction("Reload channel emotes", this, SLOT(menuReloadChannelEmotes()));
|
|
||||||
this->leftMenu.addAction("Manual reconnect", this, SLOT(menuManualReconnect()));
|
|
||||||
this->leftMenu.addSeparator();
|
|
||||||
this->leftMenu.addAction("Show changelog", this, SLOT(menuShowChangelog()));
|
|
||||||
|
|
||||||
// middle
|
|
||||||
this->channelNameLabel.setAlignment(Qt::AlignCenter);
|
|
||||||
|
|
||||||
connect(&this->channelNameLabel, &SignalLabel::mouseDoubleClick, this,
|
|
||||||
&SplitHeader::mouseDoubleClickEvent);
|
|
||||||
|
|
||||||
// right
|
|
||||||
this->rightLabel.setMinimumWidth(this->height());
|
|
||||||
this->rightLabel.getLabel().setTextFormat(Qt::RichText);
|
|
||||||
this->rightLabel.getLabel().setText("ayy");
|
|
||||||
|
|
||||||
this->initializeChannelSignals();
|
this->initializeChannelSignals();
|
||||||
|
|
||||||
this->chatWidget->channelChanged.connect([this]() {
|
this->split->channelChanged.connect([this]() {
|
||||||
this->initializeChannelSignals(); //
|
this->initializeChannelSignals(); //
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SplitHeader::~SplitHeader()
|
||||||
|
{
|
||||||
|
this->onlineStatusChangedConnection.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplitHeader::addDropdownItems(RippleEffectLabel *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")));
|
||||||
|
this->dropdownMenu.addAction("Move split", this, SLOT(menuMoveSplit()));
|
||||||
|
this->dropdownMenu.addAction("Popup", this->split, &Split::doPopup);
|
||||||
|
this->dropdownMenu.addAction("Open viewer list", this->split, &Split::doOpenViewerList);
|
||||||
|
this->dropdownMenu.addSeparator();
|
||||||
|
this->dropdownMenu.addAction("Change channel", this->split, &Split::doChangeChannel, QKeySequence(tr("Ctrl+R")));
|
||||||
|
this->dropdownMenu.addAction("Clear chat", this->split, &Split::doClearChat);
|
||||||
|
this->dropdownMenu.addAction("Open channel", this->split, &Split::doOpenChannel);
|
||||||
|
this->dropdownMenu.addAction("Open popup player", this->split, &Split::doOpenPopupPlayer);
|
||||||
|
this->dropdownMenu.addAction("Open in Streamlink", this->split, &Split::doOpenStreamlink);
|
||||||
|
this->dropdownMenu.addSeparator();
|
||||||
|
this->dropdownMenu.addAction("Reload channel emotes", this, SLOT(menuReloadChannelEmotes()));
|
||||||
|
this->dropdownMenu.addAction("Manual reconnect", this, SLOT(menuManualReconnect()));
|
||||||
|
this->dropdownMenu.addSeparator();
|
||||||
|
this->dropdownMenu.addAction("Show changelog", this, SLOT(menuShowChangelog()));
|
||||||
|
// clang-format on
|
||||||
|
}
|
||||||
|
|
||||||
void SplitHeader::initializeChannelSignals()
|
void SplitHeader::initializeChannelSignals()
|
||||||
{
|
{
|
||||||
// Disconnect any previous signal first
|
// Disconnect any previous signal first
|
||||||
this->onlineStatusChangedConnection.disconnect();
|
this->onlineStatusChangedConnection.disconnect();
|
||||||
|
|
||||||
auto channel = this->chatWidget->getChannel();
|
auto channel = this->split->getChannel();
|
||||||
twitch::TwitchChannel *twitchChannel = dynamic_cast<twitch::TwitchChannel *>(channel.get());
|
twitch::TwitchChannel *twitchChannel = dynamic_cast<twitch::TwitchChannel *>(channel.get());
|
||||||
|
|
||||||
if (twitchChannel) {
|
if (twitchChannel) {
|
||||||
|
@ -98,16 +121,20 @@ void SplitHeader::initializeChannelSignals()
|
||||||
|
|
||||||
void SplitHeader::resizeEvent(QResizeEvent *event)
|
void SplitHeader::resizeEvent(QResizeEvent *event)
|
||||||
{
|
{
|
||||||
this->setFixedHeight(static_cast<float>(28 * getDpiMultiplier()));
|
int w = 28 * getDpiMultiplier();
|
||||||
|
|
||||||
|
this->setFixedHeight(w);
|
||||||
|
this->dropdownLabel->setFixedWidth(w);
|
||||||
|
this->moderationLabel->setFixedWidth(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplitHeader::updateChannelText()
|
void SplitHeader::updateChannelText()
|
||||||
{
|
{
|
||||||
const std::string channelName = this->chatWidget->channelName;
|
const std::string channelName = this->split->channelName;
|
||||||
if (channelName.empty()) {
|
if (channelName.empty()) {
|
||||||
this->channelNameLabel.setText("<no channel>");
|
this->titleLabel->setText("<no channel>");
|
||||||
} else {
|
} else {
|
||||||
auto channel = this->chatWidget->getChannel();
|
auto channel = this->split->getChannel();
|
||||||
|
|
||||||
twitch::TwitchChannel *twitchChannel = dynamic_cast<twitch::TwitchChannel *>(channel.get());
|
twitch::TwitchChannel *twitchChannel = dynamic_cast<twitch::TwitchChannel *>(channel.get());
|
||||||
|
|
||||||
|
@ -119,12 +146,13 @@ void SplitHeader::updateChannelText()
|
||||||
"<br>"
|
"<br>"
|
||||||
"Live for " +
|
"Live for " +
|
||||||
twitchChannel->streamUptime + " with " +
|
twitchChannel->streamUptime + " with " +
|
||||||
twitchChannel->streamViewerCount + " viewers"
|
twitchChannel->streamViewerCount +
|
||||||
"</p>";
|
" viewers"
|
||||||
this->channelNameLabel.setText(QString::fromStdString(channelName) + " (live)");
|
"</p>";
|
||||||
|
this->titleLabel->setText(QString::fromStdString(channelName) + " (live)");
|
||||||
} else {
|
} else {
|
||||||
this->isLive = false;
|
this->isLive = false;
|
||||||
this->channelNameLabel.setText(QString::fromStdString(channelName));
|
this->titleLabel->setText(QString::fromStdString(channelName));
|
||||||
this->tooltip = "";
|
this->tooltip = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,17 +186,17 @@ void SplitHeader::mouseMoveEvent(QMouseEvent *event)
|
||||||
if (this->dragging) {
|
if (this->dragging) {
|
||||||
if (std::abs(this->dragStart.x() - event->pos().x()) > 12 ||
|
if (std::abs(this->dragStart.x() - event->pos().x()) > 12 ||
|
||||||
std::abs(this->dragStart.y() - event->pos().y()) > 12) {
|
std::abs(this->dragStart.y() - event->pos().y()) > 12) {
|
||||||
auto page = static_cast<SplitContainer *>(this->chatWidget->parentWidget());
|
auto page = static_cast<SplitContainer *>(this->split->parentWidget());
|
||||||
|
|
||||||
if (page != nullptr) {
|
if (page != nullptr) {
|
||||||
SplitContainer::isDraggingSplit = true;
|
SplitContainer::isDraggingSplit = true;
|
||||||
SplitContainer::draggingSplit = this->chatWidget;
|
SplitContainer::draggingSplit = this->split;
|
||||||
|
|
||||||
auto originalLocation = page->removeFromLayout(this->chatWidget);
|
auto originalLocation = page->removeFromLayout(this->split);
|
||||||
|
|
||||||
// page->update();
|
// page->update();
|
||||||
|
|
||||||
QDrag *drag = new QDrag(this->chatWidget);
|
QDrag *drag = new QDrag(this->split);
|
||||||
QMimeData *mimeData = new QMimeData;
|
QMimeData *mimeData = new QMimeData;
|
||||||
|
|
||||||
mimeData->setData("chatterino/split", "xD");
|
mimeData->setData("chatterino/split", "xD");
|
||||||
|
@ -178,7 +206,7 @@ void SplitHeader::mouseMoveEvent(QMouseEvent *event)
|
||||||
Qt::DropAction dropAction = drag->exec(Qt::MoveAction);
|
Qt::DropAction dropAction = drag->exec(Qt::MoveAction);
|
||||||
|
|
||||||
if (dropAction == Qt::IgnoreAction) {
|
if (dropAction == Qt::IgnoreAction) {
|
||||||
page->addToLayout(this->chatWidget, originalLocation);
|
page->addToLayout(this->split, originalLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
SplitContainer::isDraggingSplit = false;
|
SplitContainer::isDraggingSplit = false;
|
||||||
|
@ -197,16 +225,12 @@ void SplitHeader::leaveEvent(QEvent *event)
|
||||||
void SplitHeader::mouseDoubleClickEvent(QMouseEvent *event)
|
void SplitHeader::mouseDoubleClickEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
this->chatWidget->doChangeChannel();
|
this->split->doChangeChannel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplitHeader::leftButtonClicked()
|
void SplitHeader::leftButtonClicked()
|
||||||
{
|
{
|
||||||
QTimer::singleShot(80, [&] {
|
|
||||||
this->leftMenu.move(this->leftLabel.mapToGlobal(QPoint(0, this->leftLabel.height())));
|
|
||||||
this->leftMenu.show();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplitHeader::rightButtonClicked()
|
void SplitHeader::rightButtonClicked()
|
||||||
|
@ -218,9 +242,9 @@ void SplitHeader::refreshTheme()
|
||||||
QPalette palette;
|
QPalette palette;
|
||||||
palette.setColor(QPalette::Foreground, this->themeManager.splits.header.text);
|
palette.setColor(QPalette::Foreground, this->themeManager.splits.header.text);
|
||||||
|
|
||||||
this->leftLabel.setPalette(palette);
|
this->dropdownLabel->setPalette(palette);
|
||||||
this->channelNameLabel.setPalette(palette);
|
this->titleLabel->setPalette(palette);
|
||||||
this->rightLabel.setPalette(palette);
|
this->moderationLabel->setPalette(palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplitHeader::menuMoveSplit()
|
void SplitHeader::menuMoveSplit()
|
||||||
|
|
|
@ -26,6 +26,8 @@ class SplitHeader : public BaseWidget
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SplitHeader(Split *_chatWidget);
|
explicit SplitHeader(Split *_chatWidget);
|
||||||
|
~SplitHeader();
|
||||||
|
|
||||||
// Update channel text from chat widget
|
// Update channel text from chat widget
|
||||||
void updateChannelText();
|
void updateChannelText();
|
||||||
|
|
||||||
|
@ -38,25 +40,18 @@ protected:
|
||||||
virtual void resizeEvent(QResizeEvent *event) override;
|
virtual void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Split *const chatWidget;
|
Split *const split;
|
||||||
|
|
||||||
QPoint dragStart;
|
QPoint dragStart;
|
||||||
bool dragging = false;
|
bool dragging = false;
|
||||||
|
|
||||||
boost::signals2::connection onlineStatusChangedConnection;
|
boost::signals2::connection onlineStatusChangedConnection;
|
||||||
|
|
||||||
QHBoxLayout hbox;
|
RippleEffectLabel *dropdownLabel;
|
||||||
|
SignalLabel *titleLabel;
|
||||||
|
RippleEffectLabel *moderationLabel;
|
||||||
|
|
||||||
// top left
|
QMenu dropdownMenu;
|
||||||
RippleEffectLabel leftLabel;
|
|
||||||
QMenu leftMenu;
|
|
||||||
|
|
||||||
// center
|
|
||||||
SignalLabel channelNameLabel;
|
|
||||||
|
|
||||||
// top right
|
|
||||||
RippleEffectLabel rightLabel;
|
|
||||||
QMenu rightMenu;
|
|
||||||
|
|
||||||
void leftButtonClicked();
|
void leftButtonClicked();
|
||||||
void rightButtonClicked();
|
void rightButtonClicked();
|
||||||
|
@ -69,6 +64,8 @@ private:
|
||||||
bool isLive;
|
bool isLive;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void addDropdownItems(RippleEffectLabel *label);
|
||||||
|
|
||||||
void menuMoveSplit();
|
void menuMoveSplit();
|
||||||
void menuReloadChannelEmotes();
|
void menuReloadChannelEmotes();
|
||||||
void menuManualReconnect();
|
void menuManualReconnect();
|
||||||
|
|
Loading…
Reference in a new issue