2017-11-12 17:21:50 +01:00
|
|
|
#include "widgets/helper/splitheader.hpp"
|
2017-06-11 09:31:45 +02:00
|
|
|
#include "colorscheme.hpp"
|
2017-09-16 00:05:06 +02:00
|
|
|
#include "twitch/twitchchannel.hpp"
|
2017-09-15 17:23:49 +02:00
|
|
|
#include "util/urlfetch.hpp"
|
2017-11-12 17:21:50 +01:00
|
|
|
#include "widgets/split.hpp"
|
|
|
|
#include "widgets/splitcontainer.hpp"
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
#include <QByteArray>
|
|
|
|
#include <QDrag>
|
|
|
|
#include <QMimeData>
|
|
|
|
#include <QPainter>
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
SplitHeader::SplitHeader(Split *_chatWidget)
|
2017-06-26 16:41:20 +02:00
|
|
|
: BaseWidget(_chatWidget)
|
2017-06-10 22:48:28 +02:00
|
|
|
, chatWidget(_chatWidget)
|
2017-06-26 16:41:20 +02:00
|
|
|
, leftLabel(this)
|
2017-06-11 09:11:55 +02:00
|
|
|
, leftMenu(this)
|
2017-06-26 16:41:20 +02:00
|
|
|
, rightLabel(this)
|
2017-06-11 09:11:55 +02:00
|
|
|
, rightMenu(this)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
2017-07-02 14:28:37 +02:00
|
|
|
this->refreshTheme();
|
|
|
|
|
2017-06-11 09:11:55 +02:00
|
|
|
this->updateChannelText();
|
2017-01-15 16:38:30 +01:00
|
|
|
|
2017-06-11 09:11:55 +02:00
|
|
|
this->setLayout(&this->hbox);
|
|
|
|
this->hbox.setMargin(0);
|
|
|
|
this->hbox.addWidget(&this->leftLabel);
|
|
|
|
this->hbox.addWidget(&this->channelNameLabel, 1);
|
|
|
|
this->hbox.addWidget(&this->rightLabel);
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
// left
|
2017-06-11 09:11:55 +02:00
|
|
|
this->leftLabel.getLabel().setTextFormat(Qt::RichText);
|
|
|
|
this->leftLabel.getLabel().setText("<img src=':/images/tool_moreCollapser_off16.png' />");
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
connect(&this->leftLabel, &RippleEffectLabel::clicked, this, &SplitHeader::leftButtonClicked);
|
2017-06-11 09:11:55 +02:00
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
this->leftMenu.addAction("Add new split", this->chatWidget, &Split::doAddSplit,
|
2017-06-11 09:11:55 +02:00
|
|
|
QKeySequence(tr("Ctrl+T")));
|
2017-11-12 17:21:50 +01:00
|
|
|
this->leftMenu.addAction("Close split", this->chatWidget, &Split::doCloseSplit,
|
2017-06-11 09:11:55 +02:00
|
|
|
QKeySequence(tr("Ctrl+W")));
|
|
|
|
this->leftMenu.addAction("Move split", this, SLOT(menuMoveSplit()));
|
2017-11-12 17:21:50 +01:00
|
|
|
this->leftMenu.addAction("Popup", this->chatWidget, &Split::doPopup);
|
|
|
|
this->leftMenu.addAction("Open viewer list", this->chatWidget, &Split::doOpenViewerList);
|
2017-06-11 09:11:55 +02:00
|
|
|
this->leftMenu.addSeparator();
|
2017-11-12 17:21:50 +01:00
|
|
|
this->leftMenu.addAction("Change channel", this->chatWidget, &Split::doChangeChannel,
|
2017-06-11 09:11:55 +02:00
|
|
|
QKeySequence(tr("Ctrl+R")));
|
2017-11-12 17:21:50 +01:00
|
|
|
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);
|
2017-06-11 09:11:55 +02:00
|
|
|
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()));
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
// middle
|
2017-06-11 09:11:55 +02:00
|
|
|
this->channelNameLabel.setAlignment(Qt::AlignCenter);
|
2017-01-22 05:58:23 +01:00
|
|
|
|
2017-06-11 09:11:55 +02:00
|
|
|
connect(&this->channelNameLabel, &SignalLabel::mouseDoubleClick, this,
|
2017-11-12 17:21:50 +01:00
|
|
|
&SplitHeader::mouseDoubleClickEvent);
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
// right
|
2017-06-11 09:11:55 +02:00
|
|
|
this->rightLabel.setMinimumWidth(this->height());
|
|
|
|
this->rightLabel.getLabel().setTextFormat(Qt::RichText);
|
|
|
|
this->rightLabel.getLabel().setText("ayy");
|
2017-09-11 22:37:39 +02:00
|
|
|
|
2017-11-04 14:57:29 +01:00
|
|
|
this->initializeChannelSignals();
|
|
|
|
|
|
|
|
this->chatWidget->channelChanged.connect([this]() {
|
|
|
|
this->initializeChannelSignals(); //
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitHeader::initializeChannelSignals()
|
2017-11-04 14:57:29 +01:00
|
|
|
{
|
|
|
|
// Disconnect any previous signal first
|
|
|
|
this->onlineStatusChangedConnection.disconnect();
|
|
|
|
|
|
|
|
auto channel = this->chatWidget->getChannel();
|
|
|
|
twitch::TwitchChannel *twitchChannel = dynamic_cast<twitch::TwitchChannel *>(channel.get());
|
|
|
|
|
|
|
|
if (twitchChannel) {
|
|
|
|
twitchChannel->onlineStatusChanged.connect([this]() {
|
|
|
|
this->updateChannelText(); //
|
|
|
|
});
|
|
|
|
}
|
2017-01-15 16:38:30 +01:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitHeader::resizeEvent(QResizeEvent *event)
|
2017-09-22 00:50:43 +02:00
|
|
|
{
|
2017-11-12 17:21:50 +01:00
|
|
|
this->setFixedHeight(static_cast<float>(28 * getDpiMultiplier()));
|
2017-09-22 00:50:43 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitHeader::updateChannelText()
|
2017-01-17 00:15:44 +01:00
|
|
|
{
|
2017-07-09 17:49:02 +02:00
|
|
|
const std::string channelName = this->chatWidget->channelName;
|
|
|
|
if (channelName.empty()) {
|
|
|
|
this->channelNameLabel.setText("<no channel>");
|
|
|
|
} else {
|
2017-09-16 00:05:06 +02:00
|
|
|
auto channel = this->chatWidget->getChannel();
|
|
|
|
|
|
|
|
twitch::TwitchChannel *twitchChannel = dynamic_cast<twitch::TwitchChannel *>(channel.get());
|
2017-09-22 00:50:43 +02:00
|
|
|
|
2017-09-20 18:12:29 +02:00
|
|
|
if (twitchChannel != nullptr && twitchChannel->isLive) {
|
2017-09-11 22:37:39 +02:00
|
|
|
this->channelNameLabel.setText(QString::fromStdString(channelName) + " (live)");
|
2017-09-20 18:12:29 +02:00
|
|
|
this->setToolTip("<style>.center { text-align: center; }</style>"
|
|
|
|
"<p class = \"center\">" +
|
2017-09-22 00:50:43 +02:00
|
|
|
twitchChannel->streamStatus + "<br><br>" + twitchChannel->streamGame +
|
|
|
|
"<br>"
|
|
|
|
"Live for " +
|
2017-09-20 18:12:29 +02:00
|
|
|
twitchChannel->streamUptime + " with " +
|
2017-11-12 17:21:50 +01:00
|
|
|
twitchChannel->streamViewerCount + " viewers"
|
|
|
|
"</p>");
|
2017-09-15 17:23:49 +02:00
|
|
|
} else {
|
2017-09-11 22:37:39 +02:00
|
|
|
this->channelNameLabel.setText(QString::fromStdString(channelName));
|
|
|
|
this->setToolTip("");
|
|
|
|
}
|
2017-07-09 17:49:02 +02:00
|
|
|
}
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitHeader::paintEvent(QPaintEvent *)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
painter.fillRect(rect(), this->colorScheme.ChatHeaderBackground);
|
|
|
|
painter.setPen(this->colorScheme.ChatHeaderBorder);
|
2017-01-01 02:30:42 +01:00
|
|
|
painter.drawRect(0, 0, width() - 1, height() - 1);
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitHeader::mousePressEvent(QMouseEvent *event)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
2017-06-11 09:11:55 +02:00
|
|
|
this->dragging = true;
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-06-11 09:11:55 +02:00
|
|
|
this->dragStart = event->pos();
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitHeader::mouseMoveEvent(QMouseEvent *event)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
2017-06-11 09:11:55 +02:00
|
|
|
if (this->dragging) {
|
|
|
|
if (std::abs(this->dragStart.x() - event->pos().x()) > 12 ||
|
|
|
|
std::abs(this->dragStart.y() - event->pos().y()) > 12) {
|
2017-11-12 17:21:50 +01:00
|
|
|
auto page = static_cast<SplitContainer *>(this->chatWidget->parentWidget());
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-06-10 22:48:28 +02:00
|
|
|
if (page != nullptr) {
|
2017-11-12 17:21:50 +01:00
|
|
|
SplitContainer::isDraggingSplit = true;
|
|
|
|
SplitContainer::draggingSplit = this->chatWidget;
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-06-10 22:48:28 +02:00
|
|
|
auto originalLocation = page->removeFromLayout(this->chatWidget);
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-01-26 07:10:46 +01:00
|
|
|
// page->update();
|
2017-01-01 13:07:36 +01:00
|
|
|
|
2017-06-10 22:48:28 +02:00
|
|
|
QDrag *drag = new QDrag(this->chatWidget);
|
2017-01-11 18:52:09 +01:00
|
|
|
QMimeData *mimeData = new QMimeData;
|
2017-01-01 02:30:42 +01:00
|
|
|
|
|
|
|
mimeData->setData("chatterino/split", "xD");
|
|
|
|
|
|
|
|
drag->setMimeData(mimeData);
|
|
|
|
|
|
|
|
Qt::DropAction dropAction = drag->exec(Qt::MoveAction);
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (dropAction == Qt::IgnoreAction) {
|
2017-06-10 22:48:28 +02:00
|
|
|
page->addToLayout(this->chatWidget, originalLocation);
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
SplitContainer::isDraggingSplit = false;
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitHeader::mouseDoubleClickEvent(QMouseEvent *event)
|
2017-01-17 00:15:44 +01:00
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton) {
|
2017-09-12 22:10:30 +02:00
|
|
|
this->chatWidget->doChangeChannel();
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitHeader::leftButtonClicked()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
2017-09-16 00:05:06 +02:00
|
|
|
QTimer::singleShot(80, [&] {
|
2017-09-15 17:23:49 +02:00
|
|
|
this->leftMenu.move(this->leftLabel.mapToGlobal(QPoint(0, this->leftLabel.height())));
|
|
|
|
this->leftMenu.show();
|
|
|
|
});
|
2017-01-15 16:38:30 +01:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitHeader::rightButtonClicked()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitHeader::refreshTheme()
|
2017-07-02 14:28:37 +02:00
|
|
|
{
|
|
|
|
QPalette palette;
|
|
|
|
palette.setColor(QPalette::Foreground, this->colorScheme.Text);
|
|
|
|
|
|
|
|
this->leftLabel.setPalette(palette);
|
|
|
|
this->channelNameLabel.setPalette(palette);
|
|
|
|
this->rightLabel.setPalette(palette);
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitHeader::menuMoveSplit()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-06-10 23:53:39 +02:00
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitHeader::menuReloadChannelEmotes()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-06-10 23:53:39 +02:00
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitHeader::menuManualReconnect()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-06-10 23:53:39 +02:00
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitHeader::menuShowChangelog()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-06-07 10:09:24 +02:00
|
|
|
|
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|