2018-06-26 14:39:22 +02:00
|
|
|
#include "widgets/splits/SplitHeader.hpp"
|
2018-04-28 15:20:18 +02:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
2018-07-07 13:08:57 +02:00
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
2018-08-09 15:41:03 +02:00
|
|
|
#include "controllers/notifications/NotificationController.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "providers/twitch/TwitchChannel.hpp"
|
|
|
|
#include "providers/twitch/TwitchServer.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Resources.hpp"
|
2018-06-28 20:03:04 +02:00
|
|
|
#include "singletons/Theme.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "util/LayoutCreator.hpp"
|
|
|
|
#include "widgets/Label.hpp"
|
2018-06-26 17:20:03 +02:00
|
|
|
#include "widgets/TooltipWidget.hpp"
|
2018-06-26 14:39:22 +02:00
|
|
|
#include "widgets/splits/Split.hpp"
|
|
|
|
#include "widgets/splits/SplitContainer.hpp"
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
#include <QByteArray>
|
2018-08-07 09:05:27 +02:00
|
|
|
#include <QDesktopWidget>
|
2017-01-15 16:38:30 +01:00
|
|
|
#include <QDrag>
|
2018-06-24 12:22:50 +02:00
|
|
|
#include <QInputDialog>
|
2018-08-07 23:46:00 +02:00
|
|
|
#include <QMenu>
|
2017-01-15 16:38:30 +01:00
|
|
|
#include <QMimeData>
|
|
|
|
#include <QPainter>
|
|
|
|
|
2018-01-19 14:48:17 +01:00
|
|
|
#ifdef USEWEBENGINE
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/StreamView.hpp"
|
2018-01-19 14:48:17 +01:00
|
|
|
#endif
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2018-01-13 04:05:38 +01:00
|
|
|
SplitHeader::SplitHeader(Split *_split)
|
|
|
|
: BaseWidget(_split)
|
2018-07-06 19:23:47 +02:00
|
|
|
, split_(_split)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->split_->focused.connect([this]() { this->themeChangedEvent(); });
|
|
|
|
this->split_->focusLost.connect([this]() { this->themeChangedEvent(); });
|
2018-06-23 13:54:00 +02:00
|
|
|
|
2018-04-28 15:20:18 +02:00
|
|
|
auto app = getApp();
|
2017-12-23 22:17:38 +01:00
|
|
|
|
2018-06-26 17:06:17 +02:00
|
|
|
LayoutCreator<SplitHeader> layoutCreator(this);
|
2018-01-13 04:05:38 +01:00
|
|
|
auto layout = layoutCreator.emplace<QHBoxLayout>().withoutMargin();
|
2018-07-04 13:05:54 +02:00
|
|
|
layout->setSpacing(0);
|
2018-01-13 04:05:38 +01:00
|
|
|
{
|
|
|
|
// channel name label
|
2018-06-11 15:04:54 +02:00
|
|
|
auto title = layout.emplace<Label>().assign(&this->titleLabel);
|
2018-08-06 21:17:03 +02:00
|
|
|
title->setSizePolicy(QSizePolicy::MinimumExpanding,
|
|
|
|
QSizePolicy::Preferred);
|
2018-06-11 15:04:54 +02:00
|
|
|
title->setCentered(true);
|
|
|
|
title->setHasOffset(false);
|
2018-01-14 22:24:21 +01:00
|
|
|
|
2018-05-24 08:58:34 +02:00
|
|
|
// mode button
|
2018-08-06 21:17:03 +02:00
|
|
|
auto mode = layout.emplace<RippleEffectLabel>(nullptr).assign(
|
|
|
|
&this->modeButton_);
|
2018-06-24 12:22:50 +02:00
|
|
|
|
2018-06-24 14:21:11 +02:00
|
|
|
mode->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
2018-05-24 10:07:31 +02:00
|
|
|
mode->hide();
|
2018-05-24 08:58:34 +02:00
|
|
|
|
2018-07-04 19:43:41 +02:00
|
|
|
this->setupModeLabel(*mode);
|
|
|
|
|
2018-08-07 23:46:00 +02:00
|
|
|
mode->setMenu(this->createChatModeMenu());
|
2018-05-24 08:58:34 +02:00
|
|
|
|
2018-01-13 04:05:38 +01:00
|
|
|
// moderation mode
|
2018-08-06 21:17:03 +02:00
|
|
|
auto moderator = layout.emplace<RippleEffectButton>(this).assign(
|
|
|
|
&this->moderationButton_);
|
2018-01-17 16:52:51 +01:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
QObject::connect(
|
|
|
|
moderator.getElement(), &RippleEffectButton::clicked, this,
|
|
|
|
[this, moderator]() mutable {
|
|
|
|
this->split_->setModerationMode(
|
|
|
|
!this->split_->getModerationMode());
|
2018-07-04 13:05:54 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
moderator->setDim(!this->split_->getModerationMode());
|
|
|
|
});
|
2018-01-17 16:52:51 +01:00
|
|
|
|
|
|
|
this->updateModerationModeIcon();
|
2018-07-04 13:05:54 +02:00
|
|
|
|
|
|
|
// dropdown label
|
2018-08-06 21:17:03 +02:00
|
|
|
auto dropdown = layout.emplace<RippleEffectButton>(this).assign(
|
|
|
|
&this->dropdownButton_);
|
2018-07-04 13:05:54 +02:00
|
|
|
dropdown->setMouseTracking(true);
|
|
|
|
// dropdown->setPixmap(*app->resources->splitHeaderContext->getPixmap());
|
|
|
|
// dropdown->setScaleIndependantSize(23, 23);
|
2018-08-07 23:46:00 +02:00
|
|
|
dropdown->setMenu(this->createMainMenu());
|
2018-08-07 09:38:18 +02:00
|
|
|
QObject::connect(dropdown.getElement(),
|
2018-08-07 23:46:00 +02:00
|
|
|
&RippleEffectButton::leftMousePress, this, [this] {});
|
2018-01-13 04:05:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---- misc
|
|
|
|
this->layout()->setMargin(0);
|
2018-01-25 21:11:14 +01:00
|
|
|
this->scaleChangedEvent(this->getScale());
|
2017-07-02 14:28:37 +02:00
|
|
|
|
2017-06-11 09:11:55 +02:00
|
|
|
this->updateChannelText();
|
2017-01-15 16:38:30 +01:00
|
|
|
|
2017-11-04 14:57:29 +01:00
|
|
|
this->initializeChannelSignals();
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->split_->channelChanged.connect([this]() {
|
2017-11-04 14:57:29 +01:00
|
|
|
this->initializeChannelSignals(); //
|
|
|
|
});
|
2018-05-26 16:31:43 +02:00
|
|
|
|
2018-05-26 20:26:25 +02:00
|
|
|
this->managedConnect(app->accounts->twitch.currentUserChanged,
|
2018-05-26 17:20:16 +02:00
|
|
|
[this] { this->updateModerationModeIcon(); });
|
|
|
|
|
2018-05-26 16:31:43 +02:00
|
|
|
this->setMouseTracking(true);
|
2018-08-06 16:42:23 +02:00
|
|
|
|
|
|
|
// Update title on title-settings-change
|
|
|
|
getSettings()->showViewerCount.connect(
|
|
|
|
[this](const auto &, const auto &) { this->updateChannelText(); },
|
|
|
|
this->managedConnections_);
|
|
|
|
getSettings()->showTitle.connect(
|
|
|
|
[this](const auto &, const auto &) { this->updateChannelText(); },
|
|
|
|
this->managedConnections_);
|
|
|
|
getSettings()->showGame.connect(
|
|
|
|
[this](const auto &, const auto &) { this->updateChannelText(); },
|
|
|
|
this->managedConnections_);
|
|
|
|
getSettings()->showUptime.connect(
|
|
|
|
[this](const auto &, const auto &) { this->updateChannelText(); },
|
|
|
|
this->managedConnections_);
|
2017-11-04 14:57:29 +01:00
|
|
|
}
|
|
|
|
|
2018-01-13 04:05:38 +01:00
|
|
|
SplitHeader::~SplitHeader()
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->onlineStatusChangedConnection_.disconnect();
|
2018-01-13 04:05:38 +01:00
|
|
|
}
|
|
|
|
|
2018-08-07 23:46:00 +02:00
|
|
|
std::unique_ptr<QMenu> SplitHeader::createMainMenu()
|
2018-01-13 04:05:38 +01:00
|
|
|
{
|
2018-08-07 23:46:00 +02:00
|
|
|
auto menu = std::make_unique<QMenu>();
|
|
|
|
menu->addAction("New split", this->split_, &Split::doAddSplit,
|
|
|
|
QKeySequence(tr("Ctrl+T")));
|
|
|
|
menu->addAction("Close split", this->split_, &Split::doCloseSplit,
|
|
|
|
QKeySequence(tr("Ctrl+W")));
|
|
|
|
menu->addAction("Change channel", this->split_, &Split::doChangeChannel,
|
|
|
|
QKeySequence(tr("Ctrl+R")));
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction("Viewer list", this->split_, &Split::showViewerList);
|
|
|
|
menu->addAction("Search", this->split_, &Split::showSearchPopup,
|
|
|
|
QKeySequence(tr("Ctrl+F")));
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction("Popup", this->split_, &Split::doPopup);
|
2018-01-19 14:48:17 +01:00
|
|
|
#ifdef USEWEBENGINE
|
2018-08-07 23:46:00 +02:00
|
|
|
this->dropdownMenu.addAction("Start watching", this, [this] {
|
2018-01-24 13:15:41 +01:00
|
|
|
ChannelPtr _channel = this->split->getChannel();
|
2018-02-05 15:11:50 +01:00
|
|
|
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(_channel.get());
|
2018-01-19 14:48:17 +01:00
|
|
|
|
|
|
|
if (tc != nullptr) {
|
2018-08-07 23:46:00 +02:00
|
|
|
StreamView *view = new StreamView(
|
|
|
|
_channel, "https://player.twitch.tv/?channel=" + tc->name);
|
2018-01-19 14:48:17 +01:00
|
|
|
view->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
view->show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
#endif
|
2018-08-07 23:46:00 +02:00
|
|
|
menu->addAction("Open in browser", this->split_, &Split::openInBrowser);
|
2018-01-19 14:48:17 +01:00
|
|
|
#ifndef USEWEBENGINE
|
2018-08-07 23:46:00 +02:00
|
|
|
menu->addAction("Open player in browser", this->split_,
|
|
|
|
&Split::openInPopupPlayer);
|
2018-01-19 14:48:17 +01:00
|
|
|
#endif
|
2018-08-07 23:46:00 +02:00
|
|
|
menu->addAction("Open streamlink", this->split_, &Split::openInStreamlink);
|
2018-08-09 15:41:03 +02:00
|
|
|
|
|
|
|
auto action = new QAction(this);
|
|
|
|
action->setText("Notify when live");
|
|
|
|
action->setCheckable(true);
|
2018-08-12 15:29:40 +02:00
|
|
|
|
2018-08-09 15:41:03 +02:00
|
|
|
QObject::connect(menu.get(), &QMenu::aboutToShow, this, [action, this]() {
|
2018-08-12 15:29:40 +02:00
|
|
|
int i = 0;
|
2018-08-09 15:41:03 +02:00
|
|
|
action->setChecked(getApp()->notifications->isChannelNotified(
|
2018-08-12 15:29:40 +02:00
|
|
|
this->split_->getChannel()->getName(), i));
|
2018-08-09 15:41:03 +02:00
|
|
|
});
|
|
|
|
action->connect(action, &QAction::triggered, this, [this]() {
|
2018-08-12 15:29:40 +02:00
|
|
|
int i = 0;
|
2018-08-09 15:41:03 +02:00
|
|
|
getApp()->notifications->updateChannelNotification(
|
2018-08-12 15:29:40 +02:00
|
|
|
this->split_->getChannel()->getName(), i);
|
2018-08-09 15:41:03 +02:00
|
|
|
});
|
|
|
|
menu->addAction(action);
|
|
|
|
|
2018-08-07 23:46:00 +02:00
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction("Reload channel emotes", this,
|
|
|
|
SLOT(menuReloadChannelEmotes()));
|
|
|
|
menu->addAction("Reconnect", this, SLOT(menuManualReconnect()));
|
|
|
|
// menu->addAction("Clear messages", this->split_, &Split::doClearChat);
|
|
|
|
// menu->addSeparator();
|
|
|
|
// menu->addAction("Show changelog", this, SLOT(menuShowChangelog()));
|
|
|
|
|
|
|
|
return menu;
|
2018-07-04 13:05:54 +02:00
|
|
|
}
|
|
|
|
|
2018-08-07 23:46:00 +02:00
|
|
|
std::unique_ptr<QMenu> SplitHeader::createChatModeMenu()
|
2018-07-04 19:43:41 +02:00
|
|
|
{
|
2018-08-07 23:46:00 +02:00
|
|
|
auto menu = std::make_unique<QMenu>();
|
2018-07-04 19:43:41 +02:00
|
|
|
|
2018-07-04 13:05:54 +02:00
|
|
|
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);
|
|
|
|
|
2018-07-04 19:43:41 +02:00
|
|
|
setSub->setCheckable(true);
|
|
|
|
setEmote->setCheckable(true);
|
|
|
|
setSlow->setCheckable(true);
|
|
|
|
setR9k->setCheckable(true);
|
|
|
|
|
2018-08-07 23:46:00 +02:00
|
|
|
menu->addAction(setEmote);
|
|
|
|
menu->addAction(setSub);
|
|
|
|
menu->addAction(setSlow);
|
|
|
|
menu->addAction(setR9k);
|
2018-07-04 13:05:54 +02:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->managedConnections_.push_back(this->modeUpdateRequested_.connect( //
|
2018-07-04 13:05:54 +02:00
|
|
|
[this, setSub, setEmote, setSlow, setR9k]() {
|
2018-08-06 21:17:03 +02:00
|
|
|
auto twitchChannel =
|
|
|
|
dynamic_cast<TwitchChannel *>(this->split_->getChannel().get());
|
2018-07-04 13:05:54 +02:00
|
|
|
if (twitchChannel == nullptr) {
|
2018-07-06 19:23:47 +02:00
|
|
|
this->modeButton_->hide();
|
2018-07-04 13:05:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-15 20:28:54 +02:00
|
|
|
auto roomModes = twitchChannel->accessRoomModes();
|
2018-07-04 13:05:54 +02:00
|
|
|
|
2018-07-15 20:28:54 +02:00
|
|
|
setR9k->setChecked(roomModes->r9k);
|
|
|
|
setSlow->setChecked(roomModes->slowMode);
|
|
|
|
setEmote->setChecked(roomModes->emoteOnly);
|
|
|
|
setSub->setChecked(roomModes->submode);
|
2018-07-04 19:43:41 +02:00
|
|
|
}));
|
2018-07-04 13:05:54 +02:00
|
|
|
|
2018-07-04 19:43:41 +02:00
|
|
|
auto toggle = [this](const QString &_command, QAction *action) mutable {
|
|
|
|
QString command = _command;
|
2018-07-04 13:05:54 +02:00
|
|
|
|
2018-07-04 19:43:41 +02:00
|
|
|
if (!action->isChecked()) {
|
|
|
|
command += "off";
|
|
|
|
};
|
|
|
|
action->setChecked(!action->isChecked());
|
2018-07-04 13:05:54 +02:00
|
|
|
|
2018-07-04 19:43:41 +02:00
|
|
|
qDebug() << command;
|
2018-07-06 19:23:47 +02:00
|
|
|
this->split_->getChannel().get()->sendMessage(command);
|
2018-07-04 19:43:41 +02:00
|
|
|
};
|
2018-06-24 12:22:50 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
QObject::connect(
|
|
|
|
setSub, &QAction::triggered, this,
|
|
|
|
[setSub, toggle]() mutable { toggle("/subscribers", setSub); });
|
2018-06-24 12:22:50 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
QObject::connect(
|
|
|
|
setEmote, &QAction::triggered, this,
|
|
|
|
[setEmote, toggle]() mutable { toggle("/emoteonly", setEmote); });
|
2018-06-24 12:22:50 +02:00
|
|
|
|
|
|
|
QObject::connect(setSlow, &QAction::triggered, this, [setSlow, this]() {
|
|
|
|
if (!setSlow->isChecked()) {
|
2018-07-06 19:23:47 +02:00
|
|
|
this->split_->getChannel().get()->sendMessage("/slowoff");
|
2018-06-24 12:22:50 +02:00
|
|
|
setSlow->setChecked(false);
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
bool ok;
|
2018-08-06 21:17:03 +02:00
|
|
|
int slowSec = QInputDialog::getInt(this, "", "Seconds:", 10, 0, 500, 1,
|
|
|
|
&ok, Qt::FramelessWindowHint);
|
2018-06-24 12:22:50 +02:00
|
|
|
if (ok) {
|
2018-08-06 21:17:03 +02:00
|
|
|
this->split_->getChannel().get()->sendMessage(
|
|
|
|
QString("/slow %1").arg(slowSec));
|
2018-06-24 12:22:50 +02:00
|
|
|
} else {
|
2018-06-26 20:36:33 +02:00
|
|
|
setSlow->setChecked(false);
|
2018-06-24 12:22:50 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
QObject::connect(
|
|
|
|
setR9k, &QAction::triggered, this,
|
|
|
|
[setR9k, toggle]() mutable { toggle("/r9kbeta", setR9k); });
|
2018-08-07 23:46:00 +02:00
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SplitHeader::updateRoomModes()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
QString text;
|
|
|
|
|
|
|
|
{
|
|
|
|
auto roomModes = twitchChannel->accessRoomModes();
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}));
|
2018-06-24 12:22:50 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitHeader::initializeChannelSignals()
|
2017-11-04 14:57:29 +01:00
|
|
|
{
|
|
|
|
// Disconnect any previous signal first
|
2018-07-06 19:23:47 +02:00
|
|
|
this->onlineStatusChangedConnection_.disconnect();
|
2017-11-04 14:57:29 +01:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
auto channel = this->split_->getChannel();
|
2018-02-05 15:11:50 +01:00
|
|
|
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
2017-11-04 14:57:29 +01:00
|
|
|
|
|
|
|
if (twitchChannel) {
|
2018-08-06 21:17:03 +02:00
|
|
|
this->managedConnections_.emplace_back(
|
|
|
|
twitchChannel->liveStatusChanged.connect([this]() {
|
|
|
|
this->updateChannelText(); //
|
|
|
|
}));
|
2017-11-04 14:57:29 +01:00
|
|
|
}
|
2017-01-15 16:38:30 +01:00
|
|
|
}
|
|
|
|
|
2018-01-25 21:11:14 +01:00
|
|
|
void SplitHeader::scaleChangedEvent(float scale)
|
2017-09-22 00:50:43 +02:00
|
|
|
{
|
2018-07-04 19:43:41 +02:00
|
|
|
int w = int(28 * scale);
|
2018-01-13 04:05:38 +01:00
|
|
|
|
|
|
|
this->setFixedHeight(w);
|
2018-07-06 19:23:47 +02:00
|
|
|
this->dropdownButton_->setFixedWidth(w);
|
|
|
|
this->moderationButton_->setFixedWidth(w);
|
2018-01-27 21:13:22 +01:00
|
|
|
// this->titleLabel->setFont(
|
2018-06-28 19:38:57 +02:00
|
|
|
// FontManager::getInstance().getFont(FontStyle::Medium, scale));
|
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
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
auto indirectChannel = this->split_->getIndirectChannel();
|
|
|
|
auto channel = this->split_->getChannel();
|
2018-04-20 19:54:45 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
QString title = channel->getName();
|
2018-04-20 22:33:28 +02:00
|
|
|
|
2018-07-06 17:30:12 +02:00
|
|
|
if (indirectChannel.getType() == Channel::Type::TwitchWatching) {
|
2018-04-20 22:33:28 +02:00
|
|
|
title = "watching: " + (title.isEmpty() ? "none" : title);
|
2018-03-30 15:05:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
2017-09-22 00:50:43 +02:00
|
|
|
|
2018-03-30 15:05:33 +02:00
|
|
|
if (twitchChannel != nullptr) {
|
2018-07-15 20:28:54 +02:00
|
|
|
const auto streamStatus = twitchChannel->accessStreamStatus();
|
2018-03-30 15:05:33 +02:00
|
|
|
|
2018-07-15 20:28:54 +02:00
|
|
|
if (streamStatus->live) {
|
2018-07-06 19:23:47 +02:00
|
|
|
this->isLive_ = true;
|
|
|
|
this->tooltip_ = "<style>.center { text-align: center; }</style>"
|
2018-07-07 13:08:57 +02:00
|
|
|
"<p class = \"center\">" +
|
2018-08-06 21:17:03 +02:00
|
|
|
streamStatus->title + "<br><br>" +
|
|
|
|
streamStatus->game + "<br>" +
|
|
|
|
(streamStatus->rerun ? "Vod-casting" : "Live") +
|
|
|
|
" for " + streamStatus->uptime + " with " +
|
2018-07-15 20:28:54 +02:00
|
|
|
QString::number(streamStatus->viewerCount) +
|
2018-07-07 13:08:57 +02:00
|
|
|
" viewers"
|
|
|
|
"</p>";
|
2018-07-15 20:28:54 +02:00
|
|
|
if (streamStatus->rerun) {
|
2018-04-20 22:33:28 +02:00
|
|
|
title += " (rerun)";
|
2018-07-15 20:28:54 +02:00
|
|
|
} else if (streamStatus->streamType.isEmpty()) {
|
|
|
|
title += " (" + streamStatus->streamType + ")";
|
2018-04-08 15:14:14 +02:00
|
|
|
} else {
|
2018-04-20 22:33:28 +02:00
|
|
|
title += " (live)";
|
2018-04-08 15:14:14 +02:00
|
|
|
}
|
2018-08-06 16:42:23 +02:00
|
|
|
if (getSettings()->showViewerCount) {
|
2018-08-06 21:17:03 +02:00
|
|
|
title += " - " + QString::number(streamStatus->viewerCount) +
|
|
|
|
" viewers";
|
2018-08-06 16:42:23 +02:00
|
|
|
}
|
|
|
|
if (getSettings()->showTitle) {
|
|
|
|
title += " - " + streamStatus->title;
|
|
|
|
}
|
|
|
|
if (getSettings()->showGame) {
|
|
|
|
title += " - " + streamStatus->game;
|
|
|
|
}
|
|
|
|
if (getSettings()->showUptime) {
|
|
|
|
title += " - uptime: " + streamStatus->uptime;
|
|
|
|
}
|
2018-05-26 16:31:43 +02:00
|
|
|
} else {
|
2018-07-06 19:23:47 +02:00
|
|
|
this->tooltip_ = QString();
|
2017-09-11 22:37:39 +02:00
|
|
|
}
|
2017-07-09 17:49:02 +02:00
|
|
|
}
|
2018-03-30 15:05:33 +02:00
|
|
|
|
2018-04-20 22:33:28 +02:00
|
|
|
if (title.isEmpty()) {
|
|
|
|
title = "<empty>";
|
|
|
|
}
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->isLive_ = false;
|
2018-04-20 22:33:28 +02:00
|
|
|
this->titleLabel->setText(title);
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
|
|
|
|
2018-01-17 16:52:51 +01:00
|
|
|
void SplitHeader::updateModerationModeIcon()
|
|
|
|
{
|
2018-04-28 15:20:18 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
this->moderationButton_->setPixmap(
|
|
|
|
this->split_->getModerationMode()
|
|
|
|
? app->resources->buttons.modModeEnabled
|
|
|
|
: app->resources->buttons.modModeDisabled);
|
2018-01-17 17:17:26 +01:00
|
|
|
|
2018-01-17 18:36:12 +01:00
|
|
|
bool modButtonVisible = false;
|
2018-07-06 19:23:47 +02:00
|
|
|
ChannelPtr channel = this->split_->getChannel();
|
2018-01-17 18:36:12 +01:00
|
|
|
|
2018-08-07 23:46:00 +02:00
|
|
|
auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
2018-01-17 18:36:12 +01:00
|
|
|
|
2018-08-07 23:46:00 +02:00
|
|
|
if (twitchChannel != nullptr && twitchChannel->hasModRights()) {
|
2018-01-17 18:36:12 +01:00
|
|
|
modButtonVisible = true;
|
|
|
|
}
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->moderationButton_->setVisible(modButtonVisible);
|
2018-01-17 16:52:51 +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);
|
|
|
|
|
2018-07-06 17:11:37 +02:00
|
|
|
painter.fillRect(rect(), this->theme->splits.header.background);
|
|
|
|
painter.setPen(this->theme->splits.header.border);
|
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
|
|
|
{
|
2018-05-16 14:55:45 +02:00
|
|
|
if (event->button() == Qt::LeftButton) {
|
2018-07-06 19:23:47 +02:00
|
|
|
this->dragging_ = true;
|
2018-05-16 14:55:45 +02:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->dragStart_ = event->pos();
|
2018-05-16 14:55:45 +02:00
|
|
|
}
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->doubleClicked_ = false;
|
2018-05-16 14:55:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SplitHeader::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
if (this->dragging_ && event->button() == Qt::LeftButton) {
|
2018-05-16 14:55:45 +02:00
|
|
|
QPoint pos = event->globalPos();
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
if (!showingHelpTooltip_) {
|
|
|
|
this->showingHelpTooltip_ = true;
|
2018-05-16 14:55:45 +02:00
|
|
|
|
|
|
|
QTimer::singleShot(400, this, [this, pos] {
|
2018-07-06 19:23:47 +02:00
|
|
|
if (this->doubleClicked_) {
|
|
|
|
this->doubleClicked_ = false;
|
|
|
|
this->showingHelpTooltip_ = false;
|
2018-05-16 14:55:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TooltipWidget *widget = new TooltipWidget();
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
widget->setText("Double click or press <Ctrl+R> to change the "
|
|
|
|
"channel.\nClick and "
|
2018-05-16 14:55:45 +02:00
|
|
|
"drag to move the split.");
|
|
|
|
widget->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
widget->move(pos);
|
|
|
|
widget->show();
|
2018-05-24 10:07:31 +02:00
|
|
|
widget->raise();
|
2018-05-16 14:55:45 +02:00
|
|
|
|
|
|
|
QTimer::singleShot(3000, widget, [this, widget] {
|
|
|
|
widget->close();
|
2018-07-06 19:23:47 +02:00
|
|
|
this->showingHelpTooltip_ = false;
|
2018-05-16 14:55:45 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->dragging_ = false;
|
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
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
if (this->dragging_) {
|
2018-08-06 21:17:03 +02:00
|
|
|
if (std::abs(this->dragStart_.x() - event->pos().x()) >
|
|
|
|
int(12 * this->getScale()) ||
|
|
|
|
std::abs(this->dragStart_.y() - event->pos().y()) >
|
|
|
|
int(12 * this->getScale())) {
|
2018-07-06 19:23:47 +02:00
|
|
|
this->split_->drag();
|
|
|
|
this->dragging_ = false;
|
2018-05-11 13:55:10 +02:00
|
|
|
}
|
|
|
|
}
|
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) {
|
2018-07-06 19:23:47 +02:00
|
|
|
this->split_->doChangeChannel();
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
2018-07-06 19:23:47 +02:00
|
|
|
this->doubleClicked_ = true;
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
|
|
|
|
2018-05-26 16:31:43 +02:00
|
|
|
void SplitHeader::enterEvent(QEvent *event)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
if (!this->tooltip_.isEmpty()) {
|
2018-05-26 16:31:43 +02:00
|
|
|
auto tooltipWidget = TooltipWidget::getInstance();
|
2018-08-06 21:17:03 +02:00
|
|
|
tooltipWidget->moveTo(
|
|
|
|
this, this->mapToGlobal(this->rect().bottomLeft()), false);
|
2018-07-06 19:23:47 +02:00
|
|
|
tooltipWidget->setText(this->tooltip_);
|
2018-05-26 16:31:43 +02:00
|
|
|
tooltipWidget->show();
|
|
|
|
tooltipWidget->raise();
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseWidget::enterEvent(event);
|
|
|
|
}
|
|
|
|
|
2018-05-16 14:55:45 +02:00
|
|
|
void SplitHeader::leaveEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
TooltipWidget::getInstance()->hide();
|
2018-05-26 16:31:43 +02:00
|
|
|
|
2018-05-16 14:55:45 +02:00
|
|
|
BaseWidget::leaveEvent(event);
|
|
|
|
}
|
2018-05-26 16:31:43 +02:00
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitHeader::rightButtonClicked()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-07-06 17:11:37 +02:00
|
|
|
void SplitHeader::themeChangedEvent()
|
2017-07-02 14:28:37 +02:00
|
|
|
{
|
|
|
|
QPalette palette;
|
2018-06-23 13:54:00 +02:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
if (this->split_->hasFocus()) {
|
2018-08-06 21:17:03 +02:00
|
|
|
palette.setColor(QPalette::Foreground,
|
|
|
|
this->theme->splits.header.focusedText);
|
2018-06-23 13:54:00 +02:00
|
|
|
} else {
|
2018-07-06 17:11:37 +02:00
|
|
|
palette.setColor(QPalette::Foreground, this->theme->splits.header.text);
|
2018-06-23 13:54:00 +02:00
|
|
|
}
|
2017-07-02 14:28:37 +02:00
|
|
|
|
2018-07-06 17:11:37 +02:00
|
|
|
if (this->theme->isLightTheme()) {
|
2018-08-02 14:23:27 +02:00
|
|
|
this->dropdownButton_->setPixmap(getApp()->resources->buttons.menuDark);
|
2018-07-04 14:13:29 +02:00
|
|
|
} else {
|
2018-08-06 21:17:03 +02:00
|
|
|
this->dropdownButton_->setPixmap(
|
|
|
|
getApp()->resources->buttons.menuLight);
|
2018-07-04 14:13:29 +02:00
|
|
|
}
|
|
|
|
|
2018-01-13 04:05:38 +01:00
|
|
|
this->titleLabel->setPalette(palette);
|
2017-07-02 14:28:37 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
auto channel = this->split_->getChannel();
|
2018-06-05 15:03:34 +02:00
|
|
|
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
|
|
|
|
|
|
|
if (twitchChannel) {
|
2018-07-14 14:24:18 +02:00
|
|
|
twitchChannel->refreshChannelEmotes();
|
2018-06-05 15:03:34 +02:00
|
|
|
}
|
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
|
|
|
{
|
2018-04-28 15:20:18 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
// fourtf: connection
|
2018-04-28 15:20:18 +02:00
|
|
|
app->twitch.server->connect();
|
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 chatterino
|