2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/Split.hpp"
|
2018-04-27 22:11:19 +02:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
|
|
|
#include "Common.hpp"
|
|
|
|
#include "providers/twitch/EmoteValue.hpp"
|
|
|
|
#include "providers/twitch/TwitchChannel.hpp"
|
|
|
|
#include "providers/twitch/TwitchMessageBuilder.hpp"
|
|
|
|
#include "providers/twitch/TwitchServer.hpp"
|
|
|
|
#include "singletons/SettingsManager.hpp"
|
|
|
|
#include "singletons/ThemeManager.hpp"
|
|
|
|
#include "singletons/WindowManager.hpp"
|
|
|
|
#include "util/StreamLink.hpp"
|
|
|
|
#include "util/UrlFetch.hpp"
|
|
|
|
#include "widgets/helper/DebugPopup.hpp"
|
|
|
|
#include "widgets/helper/SearchPopup.hpp"
|
|
|
|
#include "widgets/helper/Shortcut.hpp"
|
|
|
|
#include "widgets/helper/SplitOverlay.hpp"
|
|
|
|
#include "widgets/QualityPopup.hpp"
|
|
|
|
#include "widgets/SelectChannelDialog.hpp"
|
|
|
|
#include "widgets/SplitContainer.hpp"
|
|
|
|
#include "widgets/TextInputDialog.hpp"
|
|
|
|
#include "widgets/UserInfoPopup.hpp"
|
|
|
|
#include "widgets/Window.hpp"
|
2017-01-17 00:15:44 +01:00
|
|
|
|
2017-09-12 19:06:16 +02:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
2018-01-17 03:18:47 +01:00
|
|
|
#include <QDesktopServices>
|
2017-09-11 22:37:39 +02:00
|
|
|
#include <QDockWidget>
|
2018-01-17 01:19:42 +01:00
|
|
|
#include <QDrag>
|
2017-09-11 22:37:39 +02:00
|
|
|
#include <QListWidget>
|
2018-01-17 01:19:42 +01:00
|
|
|
#include <QMimeData>
|
2017-01-17 00:15:44 +01:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QVBoxLayout>
|
2016-12-29 17:31:07 +01:00
|
|
|
|
2017-07-09 17:49:02 +02:00
|
|
|
#include <functional>
|
2017-09-17 04:36:48 +02:00
|
|
|
#include <random>
|
2017-07-09 17:49:02 +02:00
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
using namespace chatterino::providers::twitch;
|
2017-04-14 17:52:22 +02:00
|
|
|
using namespace chatterino::messages;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2018-05-10 23:58:07 +02:00
|
|
|
pajlada::Signals::Signal<Qt::KeyboardModifiers> Split::modifierStatusChanged;
|
|
|
|
Qt::KeyboardModifiers Split::modifierStatus = Qt::NoModifier;
|
2018-05-08 15:12:04 +02:00
|
|
|
|
2018-04-28 22:00:05 +02:00
|
|
|
Split::Split(SplitContainer *parent)
|
2018-06-24 11:45:30 +02:00
|
|
|
: Split(static_cast<QWidget *>(parent))
|
2018-04-28 22:00:05 +02:00
|
|
|
{
|
|
|
|
this->container = parent;
|
|
|
|
}
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
Split::Split(QWidget *parent)
|
|
|
|
: BaseWidget(parent)
|
2018-04-25 14:49:30 +02:00
|
|
|
, container(nullptr)
|
2018-02-05 15:11:50 +01:00
|
|
|
, channel(Channel::getEmpty())
|
2017-06-11 11:36:42 +02:00
|
|
|
, vbox(this)
|
|
|
|
, header(this)
|
2017-12-17 02:18:13 +01:00
|
|
|
, view(this)
|
|
|
|
, input(this)
|
2018-05-08 15:12:04 +02:00
|
|
|
, overlay(new SplitOverlay(this))
|
2016-12-29 17:31:07 +01:00
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
2018-01-17 01:19:42 +01:00
|
|
|
this->setMouseTracking(true);
|
|
|
|
|
2017-06-11 11:36:42 +02:00
|
|
|
this->vbox.setSpacing(0);
|
|
|
|
this->vbox.setMargin(1);
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-06-11 11:36:42 +02:00
|
|
|
this->vbox.addWidget(&this->header);
|
|
|
|
this->vbox.addWidget(&this->view, 1);
|
|
|
|
this->vbox.addWidget(&this->input);
|
2017-06-10 23:53:39 +02:00
|
|
|
|
2017-06-11 11:36:42 +02:00
|
|
|
// Initialize chat widget-wide hotkeys
|
2017-06-10 23:53:39 +02:00
|
|
|
// CTRL+W: Close Split
|
2018-01-06 20:24:04 +01:00
|
|
|
CreateShortcut(this, "CTRL+W", &Split::doCloseSplit);
|
2017-06-10 23:53:39 +02:00
|
|
|
|
|
|
|
// CTRL+R: Change Channel
|
2018-01-06 20:24:04 +01:00
|
|
|
CreateShortcut(this, "CTRL+R", &Split::doChangeChannel);
|
2017-11-12 17:21:50 +01:00
|
|
|
|
2018-01-05 13:42:23 +01:00
|
|
|
// CTRL+F: Search
|
2018-01-06 20:24:04 +01:00
|
|
|
CreateShortcut(this, "CTRL+F", &Split::doSearch);
|
2018-01-05 13:42:23 +01:00
|
|
|
|
2018-04-06 16:37:30 +02:00
|
|
|
// F12
|
|
|
|
CreateShortcut(this, "F10", [] {
|
|
|
|
auto *popup = new DebugPopup;
|
|
|
|
popup->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
popup->show();
|
|
|
|
});
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
// xd
|
2018-01-06 20:24:04 +01:00
|
|
|
// CreateShortcut(this, "ALT+SHIFT+RIGHT", &Split::doIncFlexX);
|
|
|
|
// CreateShortcut(this, "ALT+SHIFT+LEFT", &Split::doDecFlexX);
|
|
|
|
// CreateShortcut(this, "ALT+SHIFT+UP", &Split::doIncFlexY);
|
|
|
|
// CreateShortcut(this, "ALT+SHIFT+DOWN", &Split::doDecFlexY);
|
2017-09-17 04:36:48 +02:00
|
|
|
|
2018-06-06 18:57:22 +02:00
|
|
|
this->input.ui_.textEdit->installEventFilter(parent);
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-06-04 21:44:03 +02:00
|
|
|
this->view.mouseDown.connect([this](QMouseEvent *) {
|
|
|
|
//
|
|
|
|
this->giveFocus(Qt::MouseFocusReason);
|
|
|
|
});
|
2017-09-21 02:20:02 +02:00
|
|
|
this->view.selectionChanged.connect([this]() {
|
|
|
|
if (view.hasSelection()) {
|
|
|
|
this->input.clearSelection();
|
2017-12-17 16:19:16 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
this->input.textChanged.connect([=](const QString &newText) {
|
|
|
|
if (!app->settings->hideEmptyInput) {
|
2017-12-17 16:19:16 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newText.length() == 0) {
|
|
|
|
this->input.hide();
|
|
|
|
} else if (this->input.isHidden()) {
|
|
|
|
this->input.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
app->settings->hideEmptyInput.connect(
|
2018-01-02 02:15:11 +01:00
|
|
|
[this](const bool &hideEmptyInput, auto) {
|
|
|
|
if (hideEmptyInput && this->input.getInputText().length() == 0) {
|
|
|
|
this->input.hide();
|
|
|
|
} else {
|
|
|
|
this->input.show();
|
|
|
|
}
|
2018-04-27 22:11:19 +02:00
|
|
|
},
|
|
|
|
this->managedConnections);
|
2018-01-17 16:52:51 +01:00
|
|
|
|
|
|
|
this->header.updateModerationModeIcon();
|
2018-05-08 15:12:04 +02:00
|
|
|
this->overlay->hide();
|
2018-04-18 19:18:14 +02:00
|
|
|
|
|
|
|
this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
2018-05-08 15:12:04 +02:00
|
|
|
|
2018-05-10 23:58:07 +02:00
|
|
|
this->managedConnect(modifierStatusChanged, [this](Qt::KeyboardModifiers status) {
|
2018-06-01 14:20:46 +02:00
|
|
|
if ((status == showSplitOverlayModifiers /*|| status == showAddSplitRegions*/) &&
|
2018-05-10 23:58:07 +02:00
|
|
|
this->isMouseOver) {
|
|
|
|
this->overlay->show();
|
|
|
|
} else {
|
|
|
|
this->overlay->hide();
|
|
|
|
}
|
2018-05-08 15:12:04 +02:00
|
|
|
});
|
2018-05-25 14:57:17 +02:00
|
|
|
|
2018-06-06 18:57:22 +02:00
|
|
|
this->input.ui_.textEdit->focused.connect([this] { this->focused.invoke(); });
|
2018-06-23 13:54:00 +02:00
|
|
|
this->input.ui_.textEdit->focusLost.connect([this] { this->focusLost.invoke(); });
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
Split::~Split()
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
2018-01-17 18:36:12 +01:00
|
|
|
this->usermodeChangedConnection.disconnect();
|
2018-05-28 15:23:17 +02:00
|
|
|
this->roomModeChangedConnection.disconnect();
|
2018-01-17 18:36:12 +01:00
|
|
|
this->channelIDChangedConnection.disconnect();
|
2018-04-20 19:54:45 +02:00
|
|
|
this->indirectChannelChangedConnection.disconnect();
|
2016-12-29 17:31:07 +01:00
|
|
|
}
|
|
|
|
|
2018-05-10 19:50:31 +02:00
|
|
|
ChannelView &Split::getChannelView()
|
|
|
|
{
|
|
|
|
return this->view;
|
|
|
|
}
|
|
|
|
|
|
|
|
SplitContainer *Split::getContainer()
|
|
|
|
{
|
|
|
|
return this->container;
|
|
|
|
}
|
|
|
|
|
2018-04-25 14:49:30 +02:00
|
|
|
bool Split::isInContainer() const
|
|
|
|
{
|
|
|
|
return this->container != nullptr;
|
|
|
|
}
|
|
|
|
|
2018-05-10 23:58:07 +02:00
|
|
|
void Split::setContainer(SplitContainer *_container)
|
|
|
|
{
|
|
|
|
this->container = _container;
|
|
|
|
}
|
|
|
|
|
2018-04-20 19:54:45 +02:00
|
|
|
IndirectChannel Split::getIndirectChannel()
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2017-06-11 11:36:42 +02:00
|
|
|
return this->channel;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2018-04-20 19:54:45 +02:00
|
|
|
ChannelPtr Split::getChannel()
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2018-04-20 19:54:45 +02:00
|
|
|
return this->channel.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Split::setChannel(IndirectChannel newChannel)
|
|
|
|
{
|
2018-04-20 22:33:28 +02:00
|
|
|
this->channel = newChannel;
|
|
|
|
|
2018-04-20 19:54:45 +02:00
|
|
|
this->view.setChannel(newChannel.get());
|
2017-02-02 22:15:09 +01:00
|
|
|
|
2018-01-17 18:36:12 +01:00
|
|
|
this->usermodeChangedConnection.disconnect();
|
2018-05-24 08:58:34 +02:00
|
|
|
this->roomModeChangedConnection.disconnect();
|
2018-04-20 19:54:45 +02:00
|
|
|
this->indirectChannelChangedConnection.disconnect();
|
2018-01-17 18:36:12 +01:00
|
|
|
|
2018-04-20 19:54:45 +02:00
|
|
|
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(newChannel.get().get());
|
2018-01-17 18:36:12 +01:00
|
|
|
|
|
|
|
if (tc != nullptr) {
|
|
|
|
this->usermodeChangedConnection =
|
|
|
|
tc->userStateChanged.connect([this] { this->header.updateModerationModeIcon(); });
|
2018-05-24 08:58:34 +02:00
|
|
|
|
|
|
|
this->roomModeChangedConnection =
|
|
|
|
tc->roomModesChanged.connect([this] { this->header.updateModes(); });
|
2018-01-17 18:36:12 +01:00
|
|
|
}
|
|
|
|
|
2018-04-20 19:54:45 +02:00
|
|
|
this->indirectChannelChangedConnection = newChannel.getChannelChanged().connect([this] { //
|
|
|
|
QTimer::singleShot(0, [this] { this->setChannel(this->channel); });
|
|
|
|
});
|
|
|
|
|
2018-01-17 18:36:12 +01:00
|
|
|
this->header.updateModerationModeIcon();
|
2018-04-06 23:31:34 +02:00
|
|
|
this->header.updateChannelText();
|
2018-05-24 08:58:34 +02:00
|
|
|
this->header.updateModes();
|
2018-01-17 18:36:12 +01:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
this->channelChanged.invoke();
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2018-01-17 16:52:51 +01:00
|
|
|
void Split::setModerationMode(bool value)
|
|
|
|
{
|
|
|
|
if (value != this->moderationMode) {
|
|
|
|
this->moderationMode = value;
|
|
|
|
this->header.updateModerationModeIcon();
|
2018-01-17 17:02:34 +01:00
|
|
|
this->view.layoutMessages();
|
2018-01-17 16:52:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Split::getModerationMode() const
|
|
|
|
{
|
|
|
|
return this->moderationMode;
|
|
|
|
}
|
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
void Split::showChangeChannelPopup(const char *dialogTitle, bool empty,
|
|
|
|
std::function<void(bool)> callback)
|
2017-01-17 00:15:44 +01:00
|
|
|
{
|
2018-06-24 11:45:30 +02:00
|
|
|
if (this->selectChannelDialog.hasElement()) {
|
|
|
|
this->selectChannelDialog->raise();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectChannelDialog *dialog = new SelectChannelDialog(this);
|
2017-07-31 01:36:42 +02:00
|
|
|
if (!empty) {
|
2018-04-20 22:33:28 +02:00
|
|
|
dialog->setSelectedChannel(this->getIndirectChannel());
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
2018-04-18 09:12:29 +02:00
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
dialog->show();
|
|
|
|
dialog->closed.connect([=] {
|
|
|
|
if (dialog->hasSeletedChannel()) {
|
|
|
|
this->setChannel(dialog->getSelectedChannel());
|
2018-04-25 14:49:30 +02:00
|
|
|
if (this->isInContainer()) {
|
2018-05-10 19:50:31 +02:00
|
|
|
this->container->refreshTabTitle();
|
2018-04-25 14:49:30 +02:00
|
|
|
}
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
2017-07-31 01:36:42 +02:00
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
callback(dialog->hasSeletedChannel());
|
2018-06-24 11:45:30 +02:00
|
|
|
this->selectChannelDialog = nullptr;
|
2018-04-18 09:12:29 +02:00
|
|
|
});
|
2018-06-24 11:45:30 +02:00
|
|
|
this->selectChannelDialog = dialog;
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::layoutMessages()
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2017-09-16 00:05:06 +02:00
|
|
|
this->view.layoutMessages();
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::updateGifEmotes()
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
this->view.queueUpdate();
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 22:48:33 +01:00
|
|
|
void Split::updateLastReadMessage()
|
|
|
|
{
|
|
|
|
this->view.updateLastReadMessage();
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::giveFocus(Qt::FocusReason reason)
|
2017-08-12 15:41:14 +02:00
|
|
|
{
|
2018-06-06 18:57:22 +02:00
|
|
|
this->input.ui_.textEdit->setFocus(reason);
|
2017-08-12 15:41:14 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
bool Split::hasFocus() const
|
2017-06-11 20:53:43 +02:00
|
|
|
{
|
2018-06-06 18:57:22 +02:00
|
|
|
return this->input.ui_.textEdit->hasFocus();
|
2017-06-11 20:53:43 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::paintEvent(QPaintEvent *)
|
2016-12-29 17:31:07 +01:00
|
|
|
{
|
2017-04-12 17:46:44 +02:00
|
|
|
// color the background of the chat
|
2017-01-11 18:52:09 +01:00
|
|
|
QPainter painter(this);
|
2016-12-29 17:31:07 +01:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
painter.fillRect(this->rect(), this->themeManager->splits.background);
|
2016-12-29 17:31:07 +01:00
|
|
|
}
|
2017-01-29 11:38:00 +01:00
|
|
|
|
2018-01-17 01:19:42 +01:00
|
|
|
void Split::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
{
|
2018-05-31 16:02:20 +02:00
|
|
|
this->handleModifiers(QGuiApplication::queryKeyboardModifiers());
|
2018-01-17 01:19:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Split::keyPressEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
this->view.unsetCursor();
|
2018-05-31 16:02:20 +02:00
|
|
|
this->handleModifiers(QGuiApplication::queryKeyboardModifiers());
|
2018-01-17 01:19:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Split::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
this->view.unsetCursor();
|
2018-05-31 16:02:20 +02:00
|
|
|
this->handleModifiers(QGuiApplication::queryKeyboardModifiers());
|
2018-01-17 01:19:42 +01:00
|
|
|
}
|
|
|
|
|
2018-05-08 15:12:04 +02:00
|
|
|
void Split::resizeEvent(QResizeEvent *event)
|
|
|
|
{
|
|
|
|
BaseWidget::resizeEvent(event);
|
|
|
|
|
|
|
|
this->overlay->setGeometry(this->rect());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Split::enterEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
this->isMouseOver = true;
|
2018-05-10 23:58:07 +02:00
|
|
|
|
2018-05-31 16:02:20 +02:00
|
|
|
this->handleModifiers(QGuiApplication::queryKeyboardModifiers());
|
2018-05-10 23:58:07 +02:00
|
|
|
|
2018-06-01 14:20:46 +02:00
|
|
|
if (modifierStatus == showSplitOverlayModifiers /*|| modifierStatus == showAddSplitRegions*/) {
|
2018-05-08 15:12:04 +02:00
|
|
|
this->overlay->show();
|
|
|
|
}
|
2018-06-01 14:46:41 +02:00
|
|
|
|
|
|
|
if (this->container != nullptr) {
|
|
|
|
this->container->resetMouseStatus();
|
|
|
|
}
|
2018-05-08 15:12:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Split::leaveEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
this->isMouseOver = false;
|
2018-05-17 16:39:38 +02:00
|
|
|
|
2018-05-08 15:12:04 +02:00
|
|
|
this->overlay->hide();
|
2018-05-17 16:39:38 +02:00
|
|
|
|
2018-05-31 16:02:20 +02:00
|
|
|
this->handleModifiers(QGuiApplication::queryKeyboardModifiers());
|
2018-05-08 15:12:04 +02:00
|
|
|
}
|
|
|
|
|
2018-05-31 16:02:20 +02:00
|
|
|
void Split::focusInEvent(QFocusEvent *event)
|
|
|
|
{
|
|
|
|
this->giveFocus(event->reason());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Split::handleModifiers(Qt::KeyboardModifiers modifiers)
|
2018-01-17 01:19:42 +01:00
|
|
|
{
|
2018-05-10 23:58:07 +02:00
|
|
|
if (modifierStatus != modifiers) {
|
|
|
|
modifierStatus = modifiers;
|
|
|
|
modifierStatusChanged.invoke(modifiers);
|
2018-01-17 01:19:42 +01:00
|
|
|
}
|
2018-05-10 19:50:31 +02:00
|
|
|
}
|
|
|
|
|
2017-06-10 23:53:39 +02:00
|
|
|
/// Slots
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doAddSplit()
|
2017-06-10 23:53:39 +02:00
|
|
|
{
|
2018-04-25 14:49:30 +02:00
|
|
|
if (this->container) {
|
2018-05-10 19:50:31 +02:00
|
|
|
this->container->appendNewSplit(true);
|
2018-04-25 14:49:30 +02:00
|
|
|
}
|
2017-06-10 23:53:39 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doCloseSplit()
|
2017-06-10 23:53:39 +02:00
|
|
|
{
|
2018-04-25 14:49:30 +02:00
|
|
|
if (this->container) {
|
2018-05-10 19:50:31 +02:00
|
|
|
this->container->deleteSplit(this);
|
2018-04-25 14:49:30 +02:00
|
|
|
}
|
2017-06-10 23:53:39 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doChangeChannel()
|
2017-06-10 23:53:39 +02:00
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
this->showChangeChannelPopup("Change channel", false, [](bool) {});
|
2018-06-24 11:45:30 +02:00
|
|
|
|
2017-09-15 17:23:49 +02:00
|
|
|
auto popup = this->findChildren<QDockWidget *>();
|
2017-09-23 19:23:10 +02:00
|
|
|
if (popup.size() && popup.at(0)->isVisible() && !popup.at(0)->isFloating()) {
|
2017-09-12 22:10:30 +02:00
|
|
|
popup.at(0)->hide();
|
|
|
|
doOpenViewerList();
|
|
|
|
}
|
2017-06-10 23:53:39 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doPopup()
|
2017-06-11 09:11:55 +02:00
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
|
|
|
Window &window = app->windows->createWindow(Window::Popup);
|
2017-11-12 17:21:50 +01:00
|
|
|
|
2018-04-06 23:31:34 +02:00
|
|
|
Split *split =
|
|
|
|
new Split(static_cast<SplitContainer *>(window.getNotebook().getOrAddSelectedPage()));
|
2017-11-12 17:21:50 +01:00
|
|
|
|
2018-04-20 22:54:09 +02:00
|
|
|
split->setChannel(this->getIndirectChannel());
|
2018-05-10 19:50:31 +02:00
|
|
|
window.getNotebook().getOrAddSelectedPage()->appendSplit(split);
|
2017-11-12 17:21:50 +01:00
|
|
|
|
|
|
|
window.show();
|
2017-06-11 09:11:55 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doClearChat()
|
2017-06-11 09:11:55 +02:00
|
|
|
{
|
2017-12-26 12:32:24 +01:00
|
|
|
this->view.clearMessages();
|
2017-06-11 09:11:55 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doOpenChannel()
|
2017-06-11 09:11:55 +02:00
|
|
|
{
|
2018-04-20 19:54:45 +02:00
|
|
|
ChannelPtr _channel = this->getChannel();
|
2018-02-05 15:11:50 +01:00
|
|
|
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(_channel.get());
|
2018-01-17 03:18:47 +01:00
|
|
|
|
|
|
|
if (tc != nullptr) {
|
|
|
|
QDesktopServices::openUrl("https://twitch.tv/" + tc->name);
|
|
|
|
}
|
2017-06-11 09:11:55 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doOpenPopupPlayer()
|
2017-06-11 09:11:55 +02:00
|
|
|
{
|
2018-04-20 19:54:45 +02:00
|
|
|
ChannelPtr _channel = this->getChannel();
|
2018-02-05 15:11:50 +01:00
|
|
|
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(_channel.get());
|
2018-01-17 03:18:47 +01:00
|
|
|
|
|
|
|
if (tc != nullptr) {
|
|
|
|
QDesktopServices::openUrl("https://player.twitch.tv/?channel=" + tc->name);
|
|
|
|
}
|
2017-06-11 09:11:55 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doOpenStreamlink()
|
2017-08-12 14:44:27 +02:00
|
|
|
{
|
2018-03-24 14:13:04 +01:00
|
|
|
try {
|
2018-04-20 19:54:45 +02:00
|
|
|
streamlink::Start(this->getChannel()->name);
|
2018-03-24 14:13:04 +01:00
|
|
|
} catch (const streamlink::Exception &ex) {
|
|
|
|
debug::Log("Error in doOpenStreamlink: {}", ex.what());
|
2017-08-12 14:44:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doOpenViewerList()
|
2017-09-11 22:37:39 +02:00
|
|
|
{
|
2017-09-15 17:23:49 +02:00
|
|
|
auto viewerDock = new QDockWidget("Viewer List", this);
|
2017-09-11 22:37:39 +02:00
|
|
|
viewerDock->setAllowedAreas(Qt::LeftDockWidgetArea);
|
|
|
|
viewerDock->setFeatures(QDockWidget::DockWidgetVerticalTitleBar |
|
2017-09-15 17:23:49 +02:00
|
|
|
QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable);
|
|
|
|
viewerDock->resize(0.5 * this->width(),
|
|
|
|
this->height() - this->header.height() - this->input.height());
|
|
|
|
viewerDock->move(0, this->header.height());
|
2017-09-11 22:37:39 +02:00
|
|
|
|
|
|
|
auto multiWidget = new QWidget(viewerDock);
|
|
|
|
auto dockVbox = new QVBoxLayout(viewerDock);
|
|
|
|
auto searchBar = new QLineEdit(viewerDock);
|
|
|
|
|
|
|
|
auto chattersList = new QListWidget();
|
|
|
|
auto resultList = new QListWidget();
|
|
|
|
|
|
|
|
static QStringList labels = {"Moderators", "Staff", "Admins", "Global Moderators", "Viewers"};
|
|
|
|
static QStringList jsonLabels = {"moderators", "staff", "admins", "global_mods", "viewers"};
|
2017-09-15 17:23:49 +02:00
|
|
|
QList<QListWidgetItem *> labelList;
|
|
|
|
for (auto &x : labels) {
|
2017-09-11 22:37:39 +02:00
|
|
|
auto label = new QListWidgetItem(x);
|
2018-04-27 22:11:19 +02:00
|
|
|
label->setBackgroundColor(this->themeManager->splits.header.background);
|
2017-09-11 22:37:39 +02:00
|
|
|
labelList.append(label);
|
2017-08-12 14:44:27 +02:00
|
|
|
}
|
2017-09-11 22:37:39 +02:00
|
|
|
auto loadingLabel = new QLabel("Loading...");
|
|
|
|
|
2018-04-20 19:54:45 +02:00
|
|
|
util::twitch::get("https://tmi.twitch.tv/group/user/" + this->getChannel()->name + "/chatters",
|
|
|
|
this, [=](QJsonObject obj) {
|
2017-10-27 20:09:02 +02:00
|
|
|
QJsonObject chattersObj = obj.value("chatters").toObject();
|
|
|
|
|
|
|
|
loadingLabel->hide();
|
|
|
|
for (int i = 0; i < jsonLabels.size(); i++) {
|
|
|
|
chattersList->addItem(labelList.at(i));
|
|
|
|
foreach (const QJsonValue &v,
|
|
|
|
chattersObj.value(jsonLabels.at(i)).toArray())
|
|
|
|
chattersList->addItem(v.toString());
|
|
|
|
}
|
|
|
|
});
|
2017-09-11 22:37:39 +02:00
|
|
|
|
|
|
|
searchBar->setPlaceholderText("Search User...");
|
2017-09-15 17:23:49 +02:00
|
|
|
QObject::connect(searchBar, &QLineEdit::textEdited, this, [=]() {
|
2017-09-11 22:37:39 +02:00
|
|
|
auto query = searchBar->text();
|
2017-09-15 17:23:49 +02:00
|
|
|
if (!query.isEmpty()) {
|
|
|
|
auto results = chattersList->findItems(query, Qt::MatchStartsWith);
|
2017-09-11 22:37:39 +02:00
|
|
|
chattersList->hide();
|
|
|
|
resultList->clear();
|
2017-09-15 17:23:49 +02:00
|
|
|
for (auto &item : results) {
|
|
|
|
if (!labels.contains(item->text()))
|
2017-09-11 22:37:39 +02:00
|
|
|
resultList->addItem(item->text());
|
|
|
|
}
|
|
|
|
resultList->show();
|
2017-09-15 17:23:49 +02:00
|
|
|
} else {
|
2017-09-11 22:37:39 +02:00
|
|
|
resultList->hide();
|
|
|
|
chattersList->show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-09-15 17:23:49 +02:00
|
|
|
QObject::connect(viewerDock, &QDockWidget::topLevelChanged, this,
|
|
|
|
[=]() { viewerDock->setMinimumWidth(300); });
|
2017-09-11 22:37:39 +02:00
|
|
|
|
2017-09-15 17:23:49 +02:00
|
|
|
QObject::connect(chattersList, &QListWidget::doubleClicked, this, [=]() {
|
|
|
|
if (!labels.contains(chattersList->currentItem()->text())) {
|
2018-06-06 16:29:35 +02:00
|
|
|
doOpenUserInfoPopup(chattersList->currentItem()->text());
|
2017-09-12 22:10:30 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-09-15 17:23:49 +02:00
|
|
|
QObject::connect(resultList, &QListWidget::doubleClicked, this, [=]() {
|
|
|
|
if (!labels.contains(resultList->currentItem()->text())) {
|
2018-06-06 16:29:35 +02:00
|
|
|
doOpenUserInfoPopup(resultList->currentItem()->text());
|
2017-09-12 22:10:30 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-09-11 22:37:39 +02:00
|
|
|
dockVbox->addWidget(searchBar);
|
|
|
|
dockVbox->addWidget(loadingLabel);
|
|
|
|
dockVbox->addWidget(chattersList);
|
|
|
|
dockVbox->addWidget(resultList);
|
|
|
|
resultList->hide();
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
multiWidget->setStyleSheet(this->themeManager->splits.input.styleSheet);
|
2017-09-11 22:37:39 +02:00
|
|
|
multiWidget->setLayout(dockVbox);
|
|
|
|
viewerDock->setWidget(multiWidget);
|
|
|
|
viewerDock->show();
|
2017-08-12 14:44:27 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 16:29:35 +02:00
|
|
|
void Split::doOpenUserInfoPopup(const QString &user)
|
2017-09-12 22:10:30 +02:00
|
|
|
{
|
2018-06-06 16:29:35 +02:00
|
|
|
auto *userPopup = new UserInfoPopup;
|
|
|
|
userPopup->setData(user, this->getChannel());
|
|
|
|
userPopup->setAttribute(Qt::WA_DeleteOnClose);
|
2018-06-19 19:51:08 +02:00
|
|
|
userPopup->move(QCursor::pos() -
|
|
|
|
QPoint(int(150 * this->getScale()), int(70 * this->getScale())));
|
2018-06-06 16:29:35 +02:00
|
|
|
userPopup->show();
|
2017-09-12 22:10:30 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doCopy()
|
2017-09-12 19:06:16 +02:00
|
|
|
{
|
|
|
|
QApplication::clipboard()->setText(this->view.getSelectedText());
|
|
|
|
}
|
|
|
|
|
2018-01-05 13:42:23 +01:00
|
|
|
void Split::doSearch()
|
|
|
|
{
|
|
|
|
SearchPopup *popup = new SearchPopup();
|
|
|
|
|
|
|
|
popup->setChannel(this->getChannel());
|
|
|
|
popup->show();
|
|
|
|
}
|
|
|
|
|
2017-09-17 04:36:48 +02:00
|
|
|
template <typename Iter, typename RandomGenerator>
|
|
|
|
static Iter select_randomly(Iter start, Iter end, RandomGenerator &g)
|
|
|
|
{
|
|
|
|
std::uniform_int_distribution<> dis(0, std::distance(start, end) - 1);
|
|
|
|
std::advance(start, dis(g));
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Iter>
|
|
|
|
static Iter select_randomly(Iter start, Iter end)
|
|
|
|
{
|
|
|
|
static std::random_device rd;
|
|
|
|
static std::mt19937 gen(rd());
|
|
|
|
return select_randomly(start, end, gen);
|
|
|
|
}
|
|
|
|
|
2018-01-17 01:19:42 +01:00
|
|
|
void Split::drag()
|
|
|
|
{
|
|
|
|
auto container = dynamic_cast<SplitContainer *>(this->parentWidget());
|
|
|
|
|
|
|
|
if (container != nullptr) {
|
|
|
|
SplitContainer::isDraggingSplit = true;
|
|
|
|
SplitContainer::draggingSplit = this;
|
|
|
|
|
2018-05-10 19:50:31 +02:00
|
|
|
auto originalLocation = container->releaseSplit(this);
|
2018-01-17 01:19:42 +01:00
|
|
|
|
|
|
|
QDrag *drag = new QDrag(this);
|
|
|
|
QMimeData *mimeData = new QMimeData;
|
|
|
|
|
|
|
|
mimeData->setData("chatterino/split", "xD");
|
|
|
|
|
|
|
|
drag->setMimeData(mimeData);
|
|
|
|
|
|
|
|
Qt::DropAction dropAction = drag->exec(Qt::MoveAction);
|
|
|
|
|
|
|
|
if (dropAction == Qt::IgnoreAction) {
|
2018-05-10 19:50:31 +02:00
|
|
|
container->insertSplit(this,
|
|
|
|
originalLocation); // SplitContainer::dragOriginalPosition);
|
2018-01-17 01:19:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SplitContainer::isDraggingSplit = false;
|
|
|
|
}
|
|
|
|
}
|
2018-03-31 13:44:15 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|