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

592 lines
16 KiB
C++
Raw Normal View History

#include "widgets/splits/Split.hpp"
2018-06-26 14:09:39 +02:00
#include "Application.hpp"
2018-06-26 15:33:51 +02:00
#include "common/Common.hpp"
2018-06-26 17:20:03 +02:00
#include "common/UrlFetch.hpp"
2018-06-26 14:09:39 +02:00
#include "providers/twitch/EmoteValue.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "providers/twitch/TwitchServer.hpp"
2018-06-28 19:46:45 +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 "singletons/WindowManager.hpp"
#include "util/StreamLink.hpp"
2018-06-26 17:20:03 +02:00
#include "widgets/Window.hpp"
2018-06-26 15:11:45 +02:00
#include "widgets/dialogs/QualityPopup.hpp"
#include "widgets/dialogs/SelectChannelDialog.hpp"
#include "widgets/dialogs/TextInputDialog.hpp"
#include "widgets/dialogs/UserInfoPopup.hpp"
2018-06-26 17:20:03 +02:00
#include "widgets/helper/DebugPopup.hpp"
#include "widgets/helper/SearchPopup.hpp"
#include "widgets/helper/Shortcut.hpp"
#include "widgets/splits/SplitContainer.hpp"
#include "widgets/splits/SplitOverlay.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>
#include <QDockWidget>
#include <QDrag>
#include <QListWidget>
#include <QMimeData>
2017-01-17 00:15:44 +01:00
#include <QPainter>
#include <QVBoxLayout>
2016-12-29 17:31:07 +01:00
#include <functional>
#include <random>
2017-04-14 17:52:22 +02:00
namespace chatterino {
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-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
{
2018-07-06 19:23:47 +02:00
this->container_ = parent;
2018-04-28 22:00:05 +02:00
}
Split::Split(QWidget *parent)
: BaseWidget(parent)
2018-07-06 19:23:47 +02:00
, container_(nullptr)
, channel_(Channel::getEmpty())
, vbox_(this)
, header_(this)
, view_(this)
, input_(this)
, overlay_(new SplitOverlay(this))
2016-12-29 17:31:07 +01:00
{
auto app = getApp();
this->setMouseTracking(true);
2018-07-06 19:23:47 +02:00
this->vbox_.setSpacing(0);
this->vbox_.setMargin(1);
2017-01-01 02:30:42 +01:00
2018-07-06 19:23:47 +02:00
this->vbox_.addWidget(&this->header_);
this->vbox_.addWidget(&this->view_, 1);
this->vbox_.addWidget(&this->input_);
// Initialize chat widget-wide hotkeys
// CTRL+W: Close Split
2018-07-06 17:02:26 +02:00
createShortcut(this, "CTRL+W", &Split::doCloseSplit);
// CTRL+R: Change Channel
2018-07-06 17:02:26 +02: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-07-06 17:02:26 +02:00
createShortcut(this, "CTRL+F", &Split::doSearch);
2018-01-05 13:42:23 +01:00
2018-04-06 16:37:30 +02:00
// F12
2018-07-06 17:02:26 +02:00
createShortcut(this, "F10", [] {
2018-04-06 16:37:30 +02:00
auto *popup = new DebugPopup;
popup->setAttribute(Qt::WA_DeleteOnClose);
popup->show();
});
2017-11-12 17:21:50 +01:00
// xd
// 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);
2018-07-06 19:23:47 +02:00
this->input_.ui_.textEdit->installEventFilter(parent);
2018-07-06 19:23:47 +02:00
this->view_.mouseDown.connect([this](QMouseEvent *) {
2018-06-04 21:44:03 +02:00
//
this->giveFocus(Qt::MouseFocusReason);
});
2018-07-06 19:23:47 +02:00
this->view_.selectionChanged.connect([this]() {
if (view_.hasSelection()) {
this->input_.clearSelection();
}
});
2018-07-06 19:23:47 +02:00
this->input_.textChanged.connect([=](const QString &newText) {
2018-07-05 18:17:12 +02:00
if (app->settings->showEmptyInput) {
return;
}
if (newText.length() == 0) {
2018-07-06 19:23:47 +02:00
this->input_.hide();
} else if (this->input_.isHidden()) {
this->input_.show();
}
});
2018-07-05 18:17:12 +02:00
app->settings->showEmptyInput.connect(
[this](const bool &showEmptyInput, auto) {
2018-07-06 19:23:47 +02:00
if (!showEmptyInput && this->input_.getInputText().length() == 0) {
this->input_.hide();
2018-01-02 02:15:11 +01:00
} else {
2018-07-06 19:23:47 +02:00
this->input_.show();
2018-01-02 02:15:11 +01:00
}
},
2018-07-06 19:23:47 +02:00
this->managedConnections_);
2018-01-17 16:52:51 +01:00
2018-07-06 19:23:47 +02:00
this->header_.updateModerationModeIcon();
this->overlay_->hide();
this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
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-07-06 19:23:47 +02:00
this->isMouseOver_) {
this->overlay_->show();
2018-05-10 23:58:07 +02:00
} else {
2018-07-06 19:23:47 +02:00
this->overlay_->hide();
2018-05-10 23:58:07 +02:00
}
});
2018-05-25 14:57:17 +02:00
2018-07-06 19:23:47 +02:00
this->input_.ui_.textEdit->focused.connect([this] { this->focused.invoke(); });
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-07-06 19:23:47 +02:00
this->usermodeChangedConnection_.disconnect();
this->roomModeChangedConnection_.disconnect();
this->channelIDChangedConnection_.disconnect();
this->indirectChannelChangedConnection_.disconnect();
2016-12-29 17:31:07 +01:00
}
2018-05-10 19:50:31 +02:00
ChannelView &Split::getChannelView()
{
2018-07-06 19:23:47 +02:00
return this->view_;
2018-05-10 19:50:31 +02:00
}
SplitContainer *Split::getContainer()
{
2018-07-06 19:23:47 +02:00
return this->container_;
2018-05-10 19:50:31 +02:00
}
bool Split::isInContainer() const
{
2018-07-06 19:23:47 +02:00
return this->container_ != nullptr;
}
2018-07-06 19:23:47 +02:00
void Split::setContainer(SplitContainer *container)
2018-05-10 23:58:07 +02:00
{
2018-07-06 19:23:47 +02:00
this->container_ = container;
2018-05-10 23:58:07 +02:00
}
2018-04-20 19:54:45 +02:00
IndirectChannel Split::getIndirectChannel()
2017-04-12 17:46:44 +02:00
{
2018-07-06 19:23:47 +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-07-06 19:23:47 +02:00
return this->channel_.get();
2018-04-20 19:54:45 +02:00
}
void Split::setChannel(IndirectChannel newChannel)
{
2018-07-06 19:23:47 +02:00
this->channel_ = newChannel;
2018-07-06 19:23:47 +02:00
this->view_.setChannel(newChannel.get());
2018-07-06 19:23:47 +02:00
this->usermodeChangedConnection_.disconnect();
this->roomModeChangedConnection_.disconnect();
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) {
2018-07-06 19:23:47 +02:00
this->usermodeChangedConnection_ = tc->userStateChanged.connect([this] {
this->header_.updateModerationModeIcon();
this->header_.updateRoomModes();
});
2018-05-24 08:58:34 +02:00
2018-07-06 19:23:47 +02:00
this->roomModeChangedConnection_ =
tc->roomModesChanged.connect([this] { this->header_.updateRoomModes(); });
2018-01-17 18:36:12 +01:00
}
2018-07-06 19:23:47 +02:00
this->indirectChannelChangedConnection_ = newChannel.getChannelChanged().connect([this] { //
QTimer::singleShot(0, [this] { this->setChannel(this->channel_); });
2018-04-20 19:54:45 +02:00
});
2018-07-06 19:23:47 +02:00
this->header_.updateModerationModeIcon();
this->header_.updateChannelText();
this->header_.updateRoomModes();
2018-01-17 18:36:12 +01: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)
{
2018-07-06 19:23:47 +02:00
if (value != this->moderationMode_) {
this->moderationMode_ = value;
this->header_.updateModerationModeIcon();
this->view_.layoutMessages();
2018-01-17 16:52:51 +01:00
}
}
bool Split::getModerationMode() const
{
2018-07-06 19:23:47 +02:00
return this->moderationMode_;
2018-01-17 16:52:51 +01:00
}
void Split::insertTextToInput(const QString &text)
{
this->input_.insertText(text);
}
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-07-06 19:23:47 +02:00
if (this->selectChannelDialog_.hasElement()) {
this->selectChannelDialog_->raise();
2018-06-24 11:45:30 +02:00
return;
}
SelectChannelDialog *dialog = new SelectChannelDialog(this);
if (!empty) {
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());
if (this->isInContainer()) {
2018-07-06 19:23:47 +02:00
this->container_->refreshTabTitle();
}
2018-04-18 09:12:29 +02:00
}
2018-04-18 09:12:29 +02:00
callback(dialog->hasSeletedChannel());
2018-07-06 19:23:47 +02:00
this->selectChannelDialog_ = nullptr;
2018-04-18 09:12:29 +02:00
});
2018-07-06 19:23:47 +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
{
2018-07-06 19:23:47 +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-07-06 19:23:47 +02:00
this->view_.queueUpdate();
2017-04-12 17:46:44 +02:00
}
2018-01-23 22:48:33 +01:00
void Split::updateLastReadMessage()
{
2018-07-06 19:23:47 +02:00
this->view_.updateLastReadMessage();
2018-01-23 22:48:33 +01:00
}
2017-11-12 17:21:50 +01:00
void Split::giveFocus(Qt::FocusReason reason)
{
2018-07-06 19:23:47 +02:00
this->input_.ui_.textEdit->setFocus(reason);
}
2017-11-12 17:21:50 +01:00
bool Split::hasFocus() const
{
2018-07-06 19:23:47 +02:00
return this->input_.ui_.textEdit->hasFocus();
}
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-07-06 17:11:37 +02:00
painter.fillRect(this->rect(), this->theme->splits.background);
2016-12-29 17:31:07 +01:00
}
2017-01-29 11:38:00 +01:00
void Split::mouseMoveEvent(QMouseEvent *event)
{
2018-05-31 16:02:20 +02:00
this->handleModifiers(QGuiApplication::queryKeyboardModifiers());
}
void Split::keyPressEvent(QKeyEvent *event)
{
2018-07-06 19:23:47 +02:00
this->view_.unsetCursor();
2018-05-31 16:02:20 +02:00
this->handleModifiers(QGuiApplication::queryKeyboardModifiers());
}
void Split::keyReleaseEvent(QKeyEvent *event)
{
2018-07-06 19:23:47 +02:00
this->view_.unsetCursor();
2018-05-31 16:02:20 +02:00
this->handleModifiers(QGuiApplication::queryKeyboardModifiers());
}
void Split::resizeEvent(QResizeEvent *event)
{
BaseWidget::resizeEvent(event);
2018-07-06 19:23:47 +02:00
this->overlay_->setGeometry(this->rect());
}
void Split::enterEvent(QEvent *event)
{
2018-07-06 19:23:47 +02:00
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-07-06 19:23:47 +02:00
this->overlay_->show();
}
2018-07-06 19:23:47 +02:00
if (this->container_ != nullptr) {
this->container_->resetMouseStatus();
}
}
void Split::leaveEvent(QEvent *event)
{
2018-07-06 19:23:47 +02:00
this->isMouseOver_ = false;
2018-07-06 19:23:47 +02:00
this->overlay_->hide();
2018-05-31 16:02:20 +02:00
this->handleModifiers(QGuiApplication::queryKeyboardModifiers());
}
2018-05-31 16:02:20 +02:00
void Split::focusInEvent(QFocusEvent *event)
{
this->giveFocus(event->reason());
}
void Split::handleModifiers(Qt::KeyboardModifiers modifiers)
{
2018-05-10 23:58:07 +02:00
if (modifierStatus != modifiers) {
modifierStatus = modifiers;
modifierStatusChanged.invoke(modifiers);
}
2018-05-10 19:50:31 +02:00
}
/// Slots
2017-11-12 17:21:50 +01:00
void Split::doAddSplit()
{
2018-07-06 19:23:47 +02:00
if (this->container_) {
this->container_->appendNewSplit(true);
}
}
2017-11-12 17:21:50 +01:00
void Split::doCloseSplit()
{
2018-07-06 19:23:47 +02:00
if (this->container_) {
this->container_->deleteSplit(this);
}
}
2017-11-12 17:21:50 +01:00
void Split::doChangeChannel()
{
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 *>();
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-11-12 17:21:50 +01:00
void Split::doPopup()
2017-06-11 09:11:55 +02:00
{
auto app = getApp();
2018-07-06 17:02:26 +02:00
Window &window = app->windows->createWindow(Window::Type::Popup);
2017-11-12 17:21:50 +01:00
Split *split =
new Split(static_cast<SplitContainer *>(window.getNotebook().getOrAddSelectedPage()));
2017-11-12 17:21:50 +01: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
{
2018-07-06 19:23:47 +02: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()
{
try {
2018-07-06 19:23:47 +02:00
openStreamlinkForChannel(this->getChannel()->name);
2018-06-26 17:06:17 +02:00
} catch (const Exception &ex) {
Log("Error in doOpenStreamlink: {}", ex.what());
}
}
2017-11-12 17:21:50 +01:00
void Split::doOpenViewerList()
{
2017-09-15 17:23:49 +02:00
auto viewerDock = new QDockWidget("Viewer List", this);
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(),
2018-07-06 19:23:47 +02:00
this->height() - this->header_.height() - this->input_.height());
viewerDock->move(0, this->header_.height());
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) {
auto label = new QListWidgetItem(x);
2018-07-06 17:11:37 +02:00
label->setBackgroundColor(this->theme->splits.header.background);
labelList.append(label);
}
auto loadingLabel = new QLabel("Loading...");
auto request = NetworkRequest::twitchRequest("https://tmi.twitch.tv/group/user/" +
this->getChannel()->name + "/chatters");
request.setCaller(this);
request.onSuccess([=](auto result) {
auto obj = result.parseJson();
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());
}
return true;
});
request.execute();
searchBar->setPlaceholderText("Search User...");
2017-09-15 17:23:49 +02:00
QObject::connect(searchBar, &QLineEdit::textEdited, this, [=]() {
auto query = searchBar->text();
2017-09-15 17:23:49 +02:00
if (!query.isEmpty()) {
auto results = chattersList->findItems(query, Qt::MatchStartsWith);
chattersList->hide();
resultList->clear();
2017-09-15 17:23:49 +02:00
for (auto &item : results) {
if (!labels.contains(item->text()))
resultList->addItem(item->text());
}
resultList->show();
2017-09-15 17:23:49 +02:00
} else {
resultList->hide();
chattersList->show();
}
});
2017-09-15 17:23:49 +02:00
QObject::connect(viewerDock, &QDockWidget::topLevelChanged, this,
[=]() { viewerDock->setMinimumWidth(300); });
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
}
});
dockVbox->addWidget(searchBar);
dockVbox->addWidget(loadingLabel);
dockVbox->addWidget(chattersList);
dockVbox->addWidget(resultList);
resultList->hide();
2018-07-06 17:11:37 +02:00
multiWidget->setStyleSheet(this->theme->splits.input.styleSheet);
multiWidget->setLayout(dockVbox);
viewerDock->setWidget(multiWidget);
viewerDock->show();
}
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);
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
{
2018-07-06 19:23:47 +02:00
QApplication::clipboard()->setText(this->view_.getSelectedText());
2017-09-12 19:06:16 +02:00
}
2018-01-05 13:42:23 +01:00
void Split::doSearch()
{
SearchPopup *popup = new SearchPopup();
popup->setChannel(this->getChannel());
popup->show();
}
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);
}
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);
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);
}
SplitContainer::isDraggingSplit = false;
}
}
2017-04-14 17:52:22 +02:00
} // namespace chatterino