#include "widgets/splits/SplitHeader.hpp" #include "Application.hpp" #include "controllers/accounts/AccountController.hpp" #include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchServer.hpp" #include "singletons/Resources.hpp" #include "singletons/Settings.hpp" #include "singletons/Theme.hpp" #include "util/LayoutCreator.hpp" #include "util/LayoutHelper.hpp" #include "widgets/Label.hpp" #include "widgets/TooltipWidget.hpp" #include "widgets/helper/EffectLabel.hpp" #include "widgets/splits/Split.hpp" #include "widgets/splits/SplitContainer.hpp" #include #include #include #include #include #include #include #include #include #ifdef USEWEBENGINE #include "widgets/StreamView.hpp" #endif namespace chatterino { namespace { auto formatRoomMode(TwitchChannel &channel) -> QString { QString text; { auto modes = channel.accessRoomModes(); 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, "; } if (text.length() > 2) { text = text.mid(0, text.size() - 2); } if (!text.isEmpty()) { static QRegularExpression commaReplacement("^(.+?, .+?,) (.+)$"); auto match = commaReplacement.match(text); if (match.hasMatch()) text = match.captured(1) + '\n' + match.captured(2); } if (text.isEmpty() && channel.hasModRights()) return "none"; return text; } auto formatTooltip(const TwitchChannel::StreamStatus &s) { return QStringList{"", "

", s.title, "

", s.game, "
", s.rerun ? "Vod-casting" : "Live", " for ", s.uptime, " with ", QString::number(s.viewerCount), " viewers", "

"} .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 if (settings.showViewerCount) title += " - " + QString::number(s.viewerCount); if (settings.showTitle) title += " - " + s.title; if (settings.showGame) title += " - " + s.game; if (settings.showUptime) title += " - " + s.uptime; return title; } auto distance(QPoint a, QPoint b) { auto x = std::abs(a.x() - b.x()); auto y = std::abs(a.y() - b.y()); return std::sqrt(x * x + y * y); } } // namespace SplitHeader::SplitHeader(Split *_split) : BaseWidget(_split) , split_(_split) { this->initializeLayout(); this->setMouseTracking(true); this->updateChannelText(); this->handleChannelChanged(); this->updateModerationModeIcon(); this->split_->focused.connect([this]() { this->themeChangedEvent(); }); this->split_->focusLost.connect([this]() { this->themeChangedEvent(); }); this->split_->channelChanged.connect( [this]() { this->handleChannelChanged(); }); this->managedConnect(getApp()->accounts->twitch.currentUserChanged, [this] { this->updateModerationModeIcon(); }); 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_); } void SplitHeader::initializeLayout() { auto layout = makeLayout( {// title this->titleLabel = makeWidget