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-08-11 22:23:06 +02:00
|
|
|
#include "singletons/Settings.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"
|
2018-08-08 15:35:54 +02:00
|
|
|
#include "util/LayoutHelper.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/Label.hpp"
|
2018-06-26 17:20:03 +02:00
|
|
|
#include "widgets/TooltipWidget.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "widgets/helper/EffectLabel.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-08-11 22:23:06 +02:00
|
|
|
#include <QHBoxLayout>
|
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-08-08 15:35:54 +02:00
|
|
|
#include <cmath>
|
2017-01-15 16:38:30 +01:00
|
|
|
|
2018-01-19 14:48:17 +01:00
|
|
|
#ifdef USEWEBENGINE
|
2018-08-15 22:46:20 +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 {
|
2018-08-08 15:35:54 +02:00
|
|
|
namespace {
|
2018-08-15 22:46:20 +02:00
|
|
|
auto formatRoomMode(TwitchChannel &channel) -> QString
|
2018-01-13 04:05:38 +01:00
|
|
|
{
|
2018-08-15 22:46:20 +02:00
|
|
|
QString text;
|
2018-01-14 22:24:21 +01:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
{
|
|
|
|
auto modes = channel.accessRoomModes();
|
2018-06-24 12:22:50 +02:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
if (modes->r9k) text += "r9k, ";
|
|
|
|
if (modes->slowMode)
|
|
|
|
text +=
|
|
|
|
QString("slow(%1), ").arg(QString::number(modes->slowMode));
|
|
|
|
if (modes->emoteOnly) text += "emote, ";
|
|
|
|
if (modes->submode) text += "sub, ";
|
|
|
|
}
|
2018-05-24 08:58:34 +02:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
if (text.length() > 2) {
|
|
|
|
text = text.mid(0, text.size() - 2);
|
|
|
|
}
|
2018-07-04 19:43:41 +02:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
if (!text.isEmpty()) {
|
|
|
|
static QRegularExpression commaReplacement("^(.+?, .+?,) (.+)$");
|
2018-05-24 08:58:34 +02:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
auto match = commaReplacement.match(text);
|
|
|
|
if (match.hasMatch())
|
|
|
|
text = match.captured(1) + '\n' + match.captured(2);
|
|
|
|
}
|
2018-01-17 16:52:51 +01:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
if (text.isEmpty() && channel.hasModRights()) return "none";
|
2018-07-04 13:05:54 +02:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
return text;
|
|
|
|
}
|
|
|
|
auto formatTooltip(const TwitchChannel::StreamStatus &s)
|
|
|
|
{
|
|
|
|
return QStringList{"<style>.center { text-align: center; }</style>",
|
|
|
|
"<p class=\"center\">",
|
|
|
|
s.title,
|
|
|
|
"<br><br>",
|
|
|
|
s.game,
|
|
|
|
"<br>",
|
|
|
|
s.rerun ? "Vod-casting" : "Live",
|
|
|
|
" for ",
|
|
|
|
s.uptime,
|
|
|
|
" with ",
|
|
|
|
QString::number(s.viewerCount),
|
|
|
|
" viewers",
|
|
|
|
"</p>"}
|
|
|
|
.join("");
|
|
|
|
}
|
|
|
|
auto formatTitle(const TwitchChannel::StreamStatus &s, Settings &settings)
|
|
|
|
{
|
|
|
|
auto title = QString();
|
|
|
|
|
|
|
|
// live
|
|
|
|
if (s.rerun)
|
|
|
|
title += " (rerun)";
|
|
|
|
else if (s.streamType.isEmpty())
|
|
|
|
title += " (" + s.streamType + ")";
|
|
|
|
else
|
|
|
|
title += " (live)";
|
|
|
|
|
|
|
|
// description
|
2018-09-04 21:39:54 +02:00
|
|
|
if (settings.showUptime) title += " - " + s.uptime;
|
2018-08-15 22:46:20 +02:00
|
|
|
if (settings.showViewerCount)
|
|
|
|
title += " - " + QString::number(s.viewerCount);
|
|
|
|
if (settings.showGame) title += " - " + s.game;
|
2018-09-04 21:39:54 +02:00
|
|
|
if (settings.showTitle) title += " - " + s.title;
|
2018-08-15 22:46:20 +02:00
|
|
|
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
auto distance(QPoint a, QPoint b)
|
|
|
|
{
|
|
|
|
auto x = std::abs(a.x() - b.x());
|
|
|
|
auto y = std::abs(a.y() - b.y());
|
2018-01-17 16:52:51 +01:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
return std::sqrt(x * x + y * y);
|
2018-01-13 04:05:38 +01:00
|
|
|
}
|
2018-08-08 15:35:54 +02:00
|
|
|
} // namespace
|
2018-01-13 04:05:38 +01:00
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
SplitHeader::SplitHeader(Split *_split)
|
|
|
|
: BaseWidget(_split)
|
|
|
|
, split_(_split)
|
|
|
|
{
|
|
|
|
this->initializeLayout();
|
2017-07-02 14:28:37 +02:00
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
this->setMouseTracking(true);
|
2017-06-11 09:11:55 +02:00
|
|
|
this->updateChannelText();
|
2018-08-08 15:35:54 +02:00
|
|
|
this->handleChannelChanged();
|
|
|
|
this->updateModerationModeIcon();
|
2017-01-15 16:38:30 +01:00
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
this->split_->focused.connect([this]() { this->themeChangedEvent(); });
|
|
|
|
this->split_->focusLost.connect([this]() { this->themeChangedEvent(); });
|
|
|
|
this->split_->channelChanged.connect(
|
|
|
|
[this]() { this->handleChannelChanged(); });
|
2018-05-26 16:31:43 +02:00
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
this->managedConnect(getApp()->accounts->twitch.currentUserChanged,
|
2018-05-26 17:20:16 +02:00
|
|
|
[this] { this->updateModerationModeIcon(); });
|
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
auto _ = [this](const auto &, const auto &) { this->updateChannelText(); };
|
|
|
|
getSettings()->showViewerCount.connect(_, this->managedConnections_);
|
|
|
|
getSettings()->showTitle.connect(_, this->managedConnections_);
|
|
|
|
getSettings()->showGame.connect(_, this->managedConnections_);
|
|
|
|
getSettings()->showUptime.connect(_, this->managedConnections_);
|
2017-11-04 14:57:29 +01:00
|
|
|
}
|
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
void SplitHeader::initializeLayout()
|
2018-01-13 04:05:38 +01:00
|
|
|
{
|
2018-09-04 21:39:54 +02:00
|
|
|
auto layout = makeLayout<QHBoxLayout>({
|
|
|
|
// title
|
|
|
|
this->titleLabel_ = makeWidget<Label>([](auto w) {
|
|
|
|
w->setSizePolicy(QSizePolicy::MinimumExpanding,
|
|
|
|
QSizePolicy::Preferred);
|
|
|
|
w->setCentered(true);
|
|
|
|
w->setHasOffset(false);
|
|
|
|
}),
|
|
|
|
// mode
|
|
|
|
this->modeButton_ = makeWidget<EffectLabel>([&](auto w) {
|
|
|
|
w->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
|
|
|
w->hide();
|
|
|
|
this->initializeModeSignals(*w);
|
|
|
|
w->setMenu(this->createChatModeMenu());
|
|
|
|
}),
|
|
|
|
// moderator
|
|
|
|
this->moderationButton_ = makeWidget<Button>([&](auto w) {
|
|
|
|
QObject::connect(w, &Button::clicked, this, [this, w]() mutable {
|
|
|
|
this->split_->setModerationMode(
|
|
|
|
!this->split_->getModerationMode());
|
|
|
|
|
|
|
|
w->setDim(!this->split_->getModerationMode());
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
// dropdown
|
|
|
|
this->dropdownButton_ = makeWidget<Button>(
|
|
|
|
[&](auto w) { w->setMenu(this->createMainMenu()); }),
|
|
|
|
// add split
|
|
|
|
this->addButton_ = makeWidget<Button>([&](auto w) {
|
|
|
|
w->setPixmap(getApp()->resources->buttons.addSplitDark);
|
|
|
|
w->setEnableMargin(false);
|
|
|
|
|
|
|
|
QObject::connect(w, &Button::clicked, this,
|
|
|
|
[this]() { this->split_->addSibling(); });
|
|
|
|
}),
|
|
|
|
});
|
2018-08-08 15:35:54 +02:00
|
|
|
|
|
|
|
layout->setMargin(0);
|
|
|
|
layout->setSpacing(0);
|
|
|
|
this->setLayout(layout);
|
2018-10-07 19:25:46 +02:00
|
|
|
|
|
|
|
this->setAddButtonVisible(false);
|
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>();
|
2018-09-04 21:39:54 +02:00
|
|
|
menu->addAction("Close channel", this->split_, &Split::deleteFromContainer,
|
2018-08-08 15:35:54 +02:00
|
|
|
QKeySequence("Ctrl+W"));
|
|
|
|
menu->addAction("Change channel", this->split_, &Split::changeChannel,
|
|
|
|
QKeySequence("Ctrl+R"));
|
2018-08-07 23:46:00 +02:00
|
|
|
menu->addSeparator();
|
2018-09-04 21:39:54 +02:00
|
|
|
menu->addAction("Popup", this->split_, &Split::popup);
|
2018-08-07 23:46:00 +02:00
|
|
|
menu->addAction("Viewer list", this->split_, &Split::showViewerList);
|
2018-08-08 15:35:54 +02:00
|
|
|
menu->addAction("Search", this->split_, &Split::showSearch,
|
|
|
|
QKeySequence("Ctrl+F"));
|
2018-08-07 23:46:00 +02:00
|
|
|
menu->addSeparator();
|
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_,
|
2018-08-08 15:35:54 +02:00
|
|
|
&Split::openBrowserPlayer);
|
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]() {
|
|
|
|
action->setChecked(getApp()->notifications->isChannelNotified(
|
2018-08-12 18:54:32 +02:00
|
|
|
this->split_->getChannel()->getName(), Platform::Twitch));
|
2018-08-09 15:41:03 +02:00
|
|
|
});
|
|
|
|
action->connect(action, &QAction::triggered, this, [this]() {
|
|
|
|
getApp()->notifications->updateChannelNotification(
|
2018-08-12 18:54:32 +02:00
|
|
|
this->split_->getChannel()->getName(), Platform::Twitch);
|
2018-08-09 15:41:03 +02:00
|
|
|
});
|
2018-08-24 18:05:36 +02:00
|
|
|
|
2018-08-09 15:41:03 +02:00
|
|
|
menu->addAction(action);
|
|
|
|
|
2018-08-07 23:46:00 +02:00
|
|
|
menu->addSeparator();
|
2018-08-08 15:35:54 +02:00
|
|
|
menu->addAction("Reload channel emotes", this, SLOT(reloadChannelEmotes()));
|
2018-10-06 19:18:53 +02:00
|
|
|
menu->addAction("Reload subscriber emotes", this,
|
|
|
|
SLOT(reloadSubscriberEmotes()));
|
2018-08-08 15:35:54 +02:00
|
|
|
menu->addAction("Reconnect", this, SLOT(reconnect()));
|
2018-09-01 14:19:15 +02:00
|
|
|
menu->addAction("Clear messages", this->split_, &Split::clear);
|
2018-08-07 23:46:00 +02:00
|
|
|
// 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-08-08 15:35:54 +02:00
|
|
|
auto toggle = [this](const QString &command, QAction *action) mutable {
|
|
|
|
this->split_->getChannel().get()->sendMessage(
|
|
|
|
command + (action->isChecked() ? "" : "off"));
|
2018-07-04 19:43:41 +02:00
|
|
|
action->setChecked(!action->isChecked());
|
|
|
|
};
|
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;
|
|
|
|
};
|
2018-08-08 15:35:54 +02:00
|
|
|
auto ok = bool();
|
|
|
|
auto seconds = 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(
|
2018-08-08 15:35:54 +02:00
|
|
|
QString("/slow %1").arg(seconds));
|
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();
|
|
|
|
}
|
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
void SplitHeader::initializeModeSignals(EffectLabel &label)
|
2018-08-07 23:46:00 +02:00
|
|
|
{
|
2018-08-08 15:35:54 +02:00
|
|
|
this->modeUpdateRequested_.connect([this, &label] {
|
2018-08-08 15:50:43 +02:00
|
|
|
if (auto twitchChannel = dynamic_cast<TwitchChannel *>(
|
|
|
|
this->split_->getChannel().get())) //
|
|
|
|
{
|
2018-08-07 23:46:00 +02:00
|
|
|
label.setEnable(twitchChannel->hasModRights());
|
|
|
|
|
|
|
|
// set the label text
|
2018-08-08 15:50:43 +02:00
|
|
|
auto text = formatRoomMode(*twitchChannel);
|
2018-08-07 23:46:00 +02:00
|
|
|
|
2018-08-08 15:50:43 +02:00
|
|
|
if (!text.isEmpty()) {
|
2018-08-07 23:46:00 +02:00
|
|
|
label.getLabel().setText(text);
|
|
|
|
label.show();
|
2018-08-08 15:50:43 +02:00
|
|
|
return;
|
2018-08-07 23:46:00 +02:00
|
|
|
}
|
2018-08-08 15:35:54 +02:00
|
|
|
}
|
2018-08-08 15:50:43 +02:00
|
|
|
|
|
|
|
label.hide();
|
2018-08-08 15:35:54 +02:00
|
|
|
});
|
2018-06-24 12:22:50 +02:00
|
|
|
}
|
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
void SplitHeader::handleChannelChanged()
|
2017-11-04 14:57:29 +01:00
|
|
|
{
|
2018-08-08 15:35:54 +02:00
|
|
|
this->channelConnections_.clear();
|
2017-11-04 14:57:29 +01:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
auto channel = this->split_->getChannel();
|
2018-08-08 15:35:54 +02:00
|
|
|
if (auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get())) {
|
|
|
|
this->channelConnections_.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-09-04 21:39:54 +02:00
|
|
|
this->addButton_->setFixedWidth(w * 5 / 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SplitHeader::setAddButtonVisible(bool value)
|
|
|
|
{
|
|
|
|
this->addButton_->setVisible(value);
|
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-08-08 15:35:54 +02:00
|
|
|
this->isLive_ = false;
|
|
|
|
this->tooltipText_ = QString();
|
2018-04-20 19:54:45 +02:00
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
auto title = channel->getName();
|
2018-04-20 22:33:28 +02:00
|
|
|
|
2018-08-08 15:35:54 +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
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
if (auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get())) {
|
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;
|
2018-08-08 15:35:54 +02:00
|
|
|
this->tooltipText_ = formatTooltip(*streamStatus);
|
|
|
|
title += formatTitle(*streamStatus, *getSettings());
|
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-09-04 21:39:54 +02:00
|
|
|
this->titleLabel_->setText(title.isEmpty() ? "<empty>" : title);
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
|
|
|
|
2018-01-17 16:52:51 +01:00
|
|
|
void SplitHeader::updateModerationModeIcon()
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
this->moderationButton_->setPixmap(
|
|
|
|
this->split_->getModerationMode()
|
2018-08-08 15:35:54 +02:00
|
|
|
? getApp()->resources->buttons.modModeEnabled
|
|
|
|
: getApp()->resources->buttons.modModeDisabled);
|
2018-01-17 18:36:12 +01:00
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
auto channel = this->split_->getChannel();
|
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-08 15:35:54 +02:00
|
|
|
if (twitchChannel != nullptr && twitchChannel->hasModRights())
|
|
|
|
this->moderationButton_->show();
|
|
|
|
else
|
|
|
|
this->moderationButton_->hide();
|
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-08-08 15:35:54 +02:00
|
|
|
auto pos = event->globalPos();
|
2018-05-16 14:55:45 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
auto tooltip = new TooltipWidget();
|
2018-05-16 14:55:45 +02:00
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
tooltip->setText("Double click or press <Ctrl+R> to change the "
|
|
|
|
"channel.\nClick and "
|
|
|
|
"drag to move the split.");
|
|
|
|
tooltip->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
tooltip->move(pos);
|
|
|
|
tooltip->show();
|
|
|
|
tooltip->raise();
|
2018-05-16 14:55:45 +02:00
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
QTimer::singleShot(3000, tooltip, [this, tooltip] {
|
|
|
|
tooltip->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-08 15:35:54 +02:00
|
|
|
if (distance(this->dragStart_, event->pos()) > 15 * 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-08-08 15:35:54 +02:00
|
|
|
this->split_->changeChannel();
|
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-08-08 15:35:54 +02:00
|
|
|
if (!this->tooltipText_.isEmpty()) {
|
|
|
|
auto tooltip = TooltipWidget::getInstance();
|
|
|
|
tooltip->moveTo(this, this->mapToGlobal(this->rect().bottomLeft()),
|
|
|
|
false);
|
|
|
|
tooltip->setText(this->tooltipText_);
|
2018-08-24 11:56:42 +02:00
|
|
|
tooltip->setWordWrap(false);
|
|
|
|
tooltip->adjustSize();
|
2018-08-08 15:35:54 +02:00
|
|
|
tooltip->show();
|
|
|
|
tooltip->raise();
|
2018-05-26 16:31:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-07-06 17:11:37 +02:00
|
|
|
void SplitHeader::themeChangedEvent()
|
2017-07-02 14:28:37 +02:00
|
|
|
{
|
2018-08-08 15:35:54 +02:00
|
|
|
auto palette = QPalette();
|
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
|
|
|
}
|
2018-09-04 21:39:54 +02:00
|
|
|
this->titleLabel_->setPalette(palette);
|
2017-07-02 14:28:37 +02:00
|
|
|
|
2018-08-08 15:35:54 +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-09-21 20:18:52 +02:00
|
|
|
this->addButton_->setPixmap(getApp()->resources->buttons.addSplit);
|
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-09-21 20:18:52 +02:00
|
|
|
this->addButton_->setPixmap(getApp()->resources->buttons.addSplitDark);
|
2018-07-04 14:13:29 +02:00
|
|
|
}
|
2017-07-02 14:28:37 +02:00
|
|
|
}
|
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
void SplitHeader::moveSplit()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-06-10 23:53:39 +02:00
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
void SplitHeader::reloadChannelEmotes()
|
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
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
if (auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get()))
|
2018-07-14 14:24:18 +02:00
|
|
|
twitchChannel->refreshChannelEmotes();
|
2017-01-15 16:38:30 +01:00
|
|
|
}
|
2017-06-10 23:53:39 +02:00
|
|
|
|
2018-10-04 22:34:57 +02:00
|
|
|
void SplitHeader::reloadSubscriberEmotes()
|
|
|
|
{
|
|
|
|
getApp()->accounts->twitch.getCurrent()->loadEmotes();
|
|
|
|
}
|
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
void SplitHeader::reconnect()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
2018-08-08 15:35:54 +02:00
|
|
|
getApp()->twitch.server->connect();
|
2017-01-15 16:38:30 +01:00
|
|
|
}
|
2017-06-07 10:09:24 +02:00
|
|
|
|
|
|
|
} // namespace chatterino
|