mirror-chatterino2/src/widgets/splits/SplitHeader.cpp

698 lines
21 KiB
C++
Raw Normal View History

#include "widgets/splits/SplitHeader.hpp"
2018-06-26 14:09:39 +02:00
#include "Application.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/moderationactions/ModerationActions.hpp"
#include "controllers/notifications/NotificationController.hpp"
#include "controllers/pings/PingController.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"
#include "singletons/Settings.hpp"
2018-06-28 20:03:04 +02:00
#include "singletons/Theme.hpp"
#include "singletons/TooltipPreviewImage.hpp"
#include "singletons/WindowManager.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"
#include "widgets/dialogs/SettingsDialog.hpp"
#include "widgets/helper/CommonTexts.hpp"
#include "widgets/helper/EffectLabel.hpp"
#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>
#include <QDesktopWidget>
2017-01-15 16:38:30 +01:00
#include <QDrag>
#include <QHBoxLayout>
#include <QInputDialog>
#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-10-21 13:43:02 +02:00
if (modes->r9k)
text += "r9k, ";
2018-08-15 22:46:20 +02:00
if (modes->slowMode)
text +=
QString("slow(%1), ").arg(QString::number(modes->slowMode));
2018-10-21 13:43:02 +02:00
if (modes->emoteOnly)
text += "emote, ";
if (modes->submode)
text += "sub, ";
2018-08-15 22:46:20 +02:00
}
2018-05-24 08:58:34 +02:00
2018-10-21 13:43:02 +02:00
if (text.length() > 2)
{
2018-08-15 22:46:20 +02:00
text = text.mid(0, text.size() - 2);
}
2018-10-21 13:43:02 +02:00
if (!text.isEmpty())
{
2018-08-15 22:46:20 +02:00
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-10-21 13:43:02 +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\">",
2018-12-09 00:21:24 +01:00
s.title.toHtmlEscaped(),
2018-08-15 22:46:20 +02:00
"<br><br>",
2018-12-09 00:21:24 +01:00
s.game.toHtmlEscaped(),
2018-08-15 22:46:20 +02:00
"<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-10-31 19:45:51 +01:00
if (settings.headerUptime)
2018-10-21 13:43:02 +02:00
title += " - " + s.uptime;
2018-10-31 19:45:51 +01:00
if (settings.headerViewerCount)
2018-08-15 22:46:20 +02:00
title += " - " + QString::number(s.viewerCount);
2018-10-31 19:45:51 +01:00
if (settings.headerGame)
2018-10-21 13:43:02 +02:00
title += " - " + s.game;
2018-10-31 19:45:51 +01:00
if (settings.headerStreamTitle)
2018-10-21 13:43:02 +02:00
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();
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-08-08 15:35:54 +02:00
this->managedConnect(getApp()->accounts->twitch.currentUserChanged,
[this] { this->updateModerationModeIcon(); });
2018-08-08 15:35:54 +02:00
auto _ = [this](const auto &, const auto &) { this->updateChannelText(); };
2018-10-31 19:45:51 +01:00
getSettings()->headerViewerCount.connect(_, this->managedConnections_);
getSettings()->headerStreamTitle.connect(_, this->managedConnections_);
getSettings()->headerGame.connect(_, this->managedConnections_);
getSettings()->headerUptime.connect(_, this->managedConnections_);
}
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](Qt::MouseButton button) mutable {
switch (button)
{
case Qt::LeftButton:
if (getApp()
->moderationActions->items
.empty())
{
getApp()->windows->showSettingsDialog(
SettingsDialogPreference::
ModerationActions);
this->split_->setModerationMode(true);
w->setDim(true);
}
else
{
auto moderationMode =
this->split_->getModerationMode();
this->split_->setModerationMode(
!moderationMode);
w->setDim(moderationMode);
}
break;
case Qt::RightButton:
case Qt::MiddleButton:
getApp()->windows->showSettingsDialog(
SettingsDialogPreference::ModerationActions);
break;
}
});
2018-09-04 21:39:54 +02:00
}),
// dropdown
this->dropdownButton_ = makeWidget<Button>([&](auto w) {
auto menu = this->createMainMenu();
this->mainMenu_ = menu.get();
w->setMenu(std::move(menu));
}),
2018-09-04 21:39:54 +02:00
// add split
this->addButton_ = makeWidget<Button>([&](auto w) {
w->setPixmap(getApp()->resources->buttons.addSplitDark);
w->setEnableMargin(false);
QObject::connect(w, &Button::leftClicked, this,
2018-09-04 21:39:54 +02:00
[this]() { this->split_->addSibling(); });
}),
});
2018-08-08 15:35:54 +02:00
// update moderation button when items changed
this->managedConnect(
getApp()->moderationActions->items.delayedItemsChanged, [this] {
if (getApp()->moderationActions->items.empty())
{
if (this->split_->getModerationMode())
this->split_->setModerationMode(true);
}
else
{
if (this->split_->getModerationMode())
this->split_->setModerationMode(true);
}
});
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
}
std::unique_ptr<QMenu> SplitHeader::createMainMenu()
2018-01-13 04:05:38 +01:00
{
// top level menu
auto menu = std::make_unique<QMenu>();
2018-08-08 15:35:54 +02:00
menu->addAction("Change channel", this->split_, &Split::changeChannel,
QKeySequence("Ctrl+R"));
menu->addAction("Close", this->split_, &Split::deleteFromContainer,
QKeySequence("Ctrl+W"));
menu->addSeparator();
2018-09-04 21:39:54 +02:00
menu->addAction("Popup", this->split_, &Split::popup);
2018-08-08 15:35:54 +02:00
menu->addAction("Search", this->split_, &Split::showSearch,
QKeySequence("Ctrl+F"));
menu->addSeparator();
2018-01-19 14:48:17 +01:00
#ifdef USEWEBENGINE
this->dropdownMenu.addAction("Start watching", this, [this] {
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
2018-10-21 13:43:02 +02:00
if (tc != nullptr)
{
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
menu->addAction(OPEN_IN_BROWSER, this->split_, &Split::openInBrowser);
2018-01-19 14:48:17 +01:00
#ifndef USEWEBENGINE
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
menu->addAction(OPEN_IN_STREAMLINK, this->split_, &Split::openInStreamlink);
menu->addSeparator();
{
// "How to..." sub menu
auto subMenu = new QMenu("How to...", this);
subMenu->addAction("move split", this->split_, &Split::explainMoving);
subMenu->addAction("add/split", this->split_, &Split::explainSplitting);
menu->addMenu(subMenu);
}
// sub menu
auto moreMenu = new QMenu("More", this);
moreMenu->addAction("Show viewer list", this->split_,
&Split::showViewerList);
moreMenu->addAction("Subscribe", this->split_, &Split::openSubPage);
auto action = new QAction(this);
action->setText("Notify when live");
action->setCheckable(true);
2018-08-12 15:29:40 +02:00
QObject::connect(moreMenu, &QMenu::aboutToShow, this, [action, this]() {
action->setChecked(getApp()->notifications->isChannelNotified(
2018-08-12 18:54:32 +02:00
this->split_->getChannel()->getName(), Platform::Twitch));
});
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-24 18:05:36 +02:00
moreMenu->addAction(action);
{
auto action = new QAction(this);
action->setText("Mute highlight sound");
action->setCheckable(true);
QObject::connect(moreMenu, &QMenu::aboutToShow, this, [action, this]() {
action->setChecked(getApp()->pings->isMuted(
this->split_->getChannel()->getName()));
});
action->connect(action, &QAction::triggered, this, [this]() {
getApp()->pings->toggleMuteChannel(
this->split_->getChannel()->getName());
});
moreMenu->addAction(action);
}
moreMenu->addSeparator();
moreMenu->addAction("Reconnect", this, SLOT(reconnect()));
moreMenu->addAction("Reload channel emotes", this,
SLOT(reloadChannelEmotes()));
moreMenu->addAction("Reload subscriber emotes", this,
SLOT(reloadSubscriberEmotes()));
moreMenu->addSeparator();
moreMenu->addAction("Clear messages", this->split_, &Split::clear);
// moreMenu->addSeparator();
// moreMenu->addAction("Show changelog", this,
// SLOT(moreMenuShowChangelog()));
menu->addMenu(moreMenu);
return menu;
2018-07-04 13:05:54 +02:00
}
std::unique_ptr<QMenu> SplitHeader::createChatModeMenu()
{
auto menu = std::make_unique<QMenu>();
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);
setSub->setCheckable(true);
setEmote->setCheckable(true);
setSlow->setCheckable(true);
setR9k->setCheckable(true);
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-10-21 13:43:02 +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 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"));
action->setChecked(!action->isChecked());
};
2018-08-06 21:17:03 +02:00
QObject::connect(
setSub, &QAction::triggered, this,
[setSub, toggle]() mutable { toggle("/subscribers", setSub); });
2018-08-06 21:17:03 +02:00
QObject::connect(
setEmote, &QAction::triggered, this,
[setEmote, toggle]() mutable { toggle("/emoteonly", setEmote); });
QObject::connect(setSlow, &QAction::triggered, this, [setSlow, this]() {
2018-10-21 13:43:02 +02:00
if (!setSlow->isChecked())
{
2018-07-06 19:23:47 +02:00
this->split_->getChannel().get()->sendMessage("/slowoff");
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-10-21 13:43:02 +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-10-21 13:43:02 +02:00
}
else
{
setSlow->setChecked(false);
}
});
2018-08-06 21:17:03 +02:00
QObject::connect(
setR9k, &QAction::triggered, this,
[setR9k, toggle]() mutable { toggle("/r9kbeta", setR9k); });
return menu;
}
void SplitHeader::updateRoomModes()
{
this->modeUpdateRequested_.invoke();
}
2018-08-08 15:35:54 +02:00
void SplitHeader::initializeModeSignals(EffectLabel &label)
{
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())) //
{
label.setEnable(twitchChannel->hasModRights());
// set the label text
2018-08-08 15:50:43 +02:00
auto text = formatRoomMode(*twitchChannel);
2018-10-21 13:43:02 +02:00
if (!text.isEmpty())
{
label.getLabel().setText(text);
label.show();
2018-08-08 15:50:43 +02:00
return;
}
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-08-08 15:35:54 +02:00
void SplitHeader::handleChannelChanged()
{
2018-08-08 15:35:54 +02:00
this->channelConnections_.clear();
2018-07-06 19:23:47 +02:00
auto channel = this->split_->getChannel();
2018-10-21 13:43:02 +02:00
if (auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get()))
{
2018-08-08 15:35:54 +02:00
this->channelConnections_.emplace_back(
twitchChannel->liveStatusChanged.connect(
[this]() { this->updateChannelText(); }));
}
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
{
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-08-08 15:35:54 +02:00
if (indirectChannel.getType() == Channel::Type::TwitchWatching)
title = "watching: " + (title.isEmpty() ? "none" : title);
2018-10-21 13:43:02 +02:00
if (auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get()))
{
2018-07-15 20:28:54 +02:00
const auto streamStatus = twitchChannel->accessStreamStatus();
2018-10-21 13:43:02 +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());
}
}
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()
{
auto moderationMode =
this->split_->getModerationMode() &&
!getApp()->moderationActions->items.empty();
2018-08-06 21:17:03 +02:00
this->moderationButton_->setPixmap(
moderationMode ? 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();
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);
painter.drawRect(0, 0, width() - 1, height() - 2);
painter.fillRect(0, height() - 1, width(), 1,
this->theme->splits.background);
2017-01-01 02:30:42 +01:00
}
2017-11-12 17:21:50 +01:00
void SplitHeader::mousePressEvent(QMouseEvent *event)
2017-01-01 02:30:42 +01:00
{
switch (event->button())
2018-10-21 13:43:02 +02:00
{
case Qt::LeftButton:
{
this->dragging_ = true;
this->dragStart_ = event->pos();
}
break;
2018-05-16 14:55:45 +02:00
case Qt::RightButton:
{
this->mainMenu_->popup(this->mapToGlobal(event->pos()));
}
break;
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-10-21 13:43:02 +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-10-21 13:43:02 +02:00
if (!showingHelpTooltip_)
{
2018-07-06 19:23:47 +02:00
this->showingHelpTooltip_ = true;
2018-05-16 14:55:45 +02:00
QTimer::singleShot(400, this, [this, pos] {
2018-10-21 13:43:02 +02:00
if (this->doubleClicked_)
{
2018-07-06 19:23:47 +02:00
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-10-21 13:43:02 +02:00
if (this->dragging_)
{
2018-11-21 21:37:41 +01:00
if (distance(this->dragStart_, event->pos()) > 15 * this->scale())
2018-10-21 13:43:02 +02:00
{
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
{
2018-10-21 13:43:02 +02: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
}
void SplitHeader::enterEvent(QEvent *event)
{
2018-10-21 13:43:02 +02:00
if (!this->tooltipText_.isEmpty())
{
TooltipPreviewImage::getInstance().setImage(nullptr);
2018-08-08 15:35:54 +02:00
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();
}
BaseWidget::enterEvent(event);
}
2018-05-16 14:55:45 +02:00
void SplitHeader::leaveEvent(QEvent *event)
{
TooltipWidget::getInstance()->hide();
2018-05-16 14:55:45 +02:00
BaseWidget::leaveEvent(event);
}
2018-07-06 17:11:37 +02:00
void SplitHeader::themeChangedEvent()
{
2018-08-08 15:35:54 +02:00
auto palette = QPalette();
2018-10-21 13:43:02 +02:00
if (this->split_->hasFocus())
{
2018-08-06 21:17:03 +02:00
palette.setColor(QPalette::Foreground,
this->theme->splits.header.focusedText);
2018-10-21 13:43:02 +02:00
}
else
{
2018-07-06 17:11:37 +02:00
palette.setColor(QPalette::Foreground, this->theme->splits.header.text);
}
2018-09-04 21:39:54 +02:00
this->titleLabel_->setPalette(palette);
2018-08-08 15:35:54 +02:00
// --
2018-10-21 13:43:02 +02:00
if (this->theme->isLightTheme())
{
2018-08-02 14:23:27 +02:00
this->dropdownButton_->setPixmap(getApp()->resources->buttons.menuDark);
this->addButton_->setPixmap(getApp()->resources->buttons.addSplit);
2018-10-21 13:43:02 +02:00
}
else
{
2018-08-06 21:17:03 +02:00
this->dropdownButton_->setPixmap(
getApp()->resources->buttons.menuLight);
this->addButton_->setPixmap(getApp()->resources->buttons.addSplitDark);
2018-07-04 14:13:29 +02:00
}
}
2018-08-08 15:35:54 +02:00
void SplitHeader::moveSplit()
2017-01-15 16:38:30 +01: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-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
}
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
}
} // namespace chatterino