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

599 lines
16 KiB
C++
Raw Normal View History

#include "widgets/splits/Split.hpp"
2018-06-26 15:33:51 +02:00
#include "common/Common.hpp"
2018-07-15 14:11:46 +02:00
#include "common/NetworkRequest.hpp"
#include "debug/Log.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"
#include "widgets/Notebook.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"
#include "widgets/helper/ChannelView.hpp"
2018-06-26 17:20:03 +02:00
#include "widgets/helper/DebugPopup.hpp"
#include "widgets/helper/ResizingTextEdit.hpp"
2018-06-26 17:20:03 +02:00
#include "widgets/helper/SearchPopup.hpp"
#include "widgets/helper/Shortcut.hpp"
#include "widgets/splits/SplitContainer.hpp"
#include "widgets/splits/SplitHeader.hpp"
#include "widgets/splits/SplitInput.hpp"
2018-06-26 17:20:03 +02:00
#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>
2018-07-15 14:11:46 +02:00
#include <QJsonArray>
#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 {
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_(new QVBoxLayout(this))
, header_(new SplitHeader(this))
, view_(new ChannelView(this))
, input_(new SplitInput(this))
2018-07-06 19:23:47 +02:00
, overlay_(new SplitOverlay(this))
2016-12-29 17:31:07 +01:00
{
this->setMouseTracking(true);
this->vbox_->setSpacing(0);
this->vbox_->setMargin(1);
2017-01-01 02:30:42 +01: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-08-08 15:35:54 +02:00
createShortcut(this, "CTRL+W", &Split::deleteFromContainer);
// CTRL+R: Change Channel
2018-08-08 15:35:54 +02:00
createShortcut(this, "CTRL+R", &Split::changeChannel);
2017-11-12 17:21:50 +01:00
2018-01-05 13:42:23 +01:00
// CTRL+F: Search
2018-08-08 15:35:54 +02:00
createShortcut(this, "CTRL+F", &Split::showSearch);
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);
this->input_->ui_.textEdit->installEventFilter(parent);
this->view_->mouseDown.connect([this](QMouseEvent *) {
2018-06-04 21:44:03 +02:00
//
this->giveFocus(Qt::MouseFocusReason);
});
this->view_->selectionChanged.connect([this]() {
if (view_->hasSelection()) {
this->input_->clearSelection();
}
});
this->input_->textChanged.connect([=](const QString &newText) {
2018-08-08 15:35:54 +02:00
if (getSettings()->showEmptyInput) {
return;
}
if (newText.length() == 0) {
this->input_->hide();
} else if (this->input_->isHidden()) {
this->input_->show();
}
});
2018-08-08 15:35:54 +02:00
getSettings()->showEmptyInput.connect(
2018-07-05 18:17:12 +02:00
[this](const bool &showEmptyInput, auto) {
if (!showEmptyInput && this->input_->getInputText().length() == 0) {
this->input_->hide();
2018-01-02 02:15:11 +01:00
} else {
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
this->header_->updateModerationModeIcon();
2018-07-06 19:23:47 +02:00
this->overlay_->hide();
2018-08-06 21:17:03 +02:00
this->setSizePolicy(QSizePolicy::MinimumExpanding,
QSizePolicy::MinimumExpanding);
2018-08-06 21:17:03 +02:00
this->managedConnect(modifierStatusChanged,
[this](Qt::KeyboardModifiers status) {
if ((status == showSplitOverlayModifiers /*|| status == showAddSplitRegions*/) &&
2018-07-06 19:23:47 +02:00
this->isMouseOver_) {
2018-08-06 21:17:03 +02:00
this->overlay_->show();
} else {
this->overlay_->hide();
}
});
2018-05-25 14:57:17 +02:00
this->input_->ui_.textEdit->focused.connect(
2018-08-06 21:17:03 +02:00
[this] { this->focused.invoke(); });
this->input_->ui_.textEdit->focusLost.connect(
2018-08-06 21:17:03 +02:00
[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()
{
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;
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-08-06 21:17:03 +02:00
this->roomModeChangedConnection_ = tc->roomModesChanged.connect(
[this] { this->header_->updateRoomModes(); });
2018-01-17 18:36:12 +01:00
}
2018-08-06 21:17:03 +02:00
this->indirectChannelChangedConnection_ =
newChannel.getChannelChanged().connect([this] { //
QTimer::singleShot(0, [this] { this->setChannel(this->channel_); });
});
2018-04-20 19:54:45 +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
{
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
{
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();
2018-01-23 22:48:33 +01:00
}
2017-11-12 17:21:50 +01:00
void Split::giveFocus(Qt::FocusReason reason)
{
this->input_->ui_.textEdit->setFocus(reason);
}
2017-11-12 17:21:50 +01:00
bool Split::hasFocus() const
{
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)
{
this->view_->unsetCursor();
2018-05-31 16:02:20 +02:00
this->handleModifiers(QGuiApplication::queryKeyboardModifiers());
}
void Split::keyReleaseEvent(QKeyEvent *event)
{
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
2018-08-08 15:35:54 +02:00
void Split::addSibling()
{
2018-07-06 19:23:47 +02:00
if (this->container_) {
this->container_->appendNewSplit(true);
}
}
2018-08-08 15:35:54 +02:00
void Split::deleteFromContainer()
{
2018-07-06 19:23:47 +02:00
if (this->container_) {
this->container_->deleteSplit(this);
}
}
2018-08-08 15:35:54 +02:00
void Split::changeChannel()
{
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 *>();
2018-08-06 21:17:03 +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();
2018-08-02 14:23:27 +02:00
showViewerList();
2017-09-12 22:10:30 +02:00
}
}
2018-08-08 15:35:54 +02:00
void Split::popup()
2017-06-11 09:11:55 +02:00
{
auto app = getApp();
Window &window = app->windows->createWindow(WindowType::Popup);
2017-11-12 17:21:50 +01:00
2018-08-06 21:17:03 +02: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
}
2018-08-08 15:35:54 +02:00
void Split::clear()
2017-06-11 09:11:55 +02:00
{
this->view_->clearMessages();
2017-06-11 09:11:55 +02:00
}
2018-08-02 14:23:27 +02:00
void Split::openInBrowser()
2017-06-11 09:11:55 +02:00
{
2018-08-02 14:23:27 +02:00
auto channel = this->getChannel();
2018-01-17 03:18:47 +01:00
2018-08-02 14:23:27 +02:00
if (auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get())) {
2018-08-06 21:17:03 +02:00
QDesktopServices::openUrl("https://twitch.tv/" +
twitchChannel->getName());
2018-01-17 03:18:47 +01:00
}
2017-06-11 09:11:55 +02:00
}
2018-08-08 15:35:54 +02:00
void Split::openBrowserPlayer()
2017-06-11 09:11:55 +02:00
{
2018-08-02 14:23:27 +02:00
ChannelPtr channel = this->getChannel();
if (auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get())) {
2018-08-06 21:17:03 +02:00
QDesktopServices::openUrl("https://player.twitch.tv/?channel=" +
twitchChannel->getName());
2018-01-17 03:18:47 +01:00
}
2017-06-11 09:11:55 +02:00
}
2018-08-02 14:23:27 +02:00
void Split::openInStreamlink()
{
try {
2018-08-02 14:23:27 +02:00
openStreamlinkForChannel(this->getChannel()->getName());
2018-06-26 17:06:17 +02:00
} catch (const Exception &ex) {
2018-08-11 14:20:53 +02:00
log("Error in doOpenStreamlink: {}", ex.what());
}
}
2018-08-02 14:23:27 +02:00
void Split::showViewerList()
{
2017-09-15 17:23:49 +02:00
auto viewerDock = new QDockWidget("Viewer List", this);
viewerDock->setAllowedAreas(Qt::LeftDockWidgetArea);
viewerDock->setFeatures(QDockWidget::DockWidgetVerticalTitleBar |
2018-08-06 21:17:03 +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());
auto multiWidget = new QWidget(viewerDock);
auto dockVbox = new QVBoxLayout(viewerDock);
auto searchBar = new QLineEdit(viewerDock);
auto chattersList = new QListWidget();
auto resultList = new QListWidget();
2018-08-06 21:17:03 +02:00
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...");
2018-08-06 21:17:03 +02:00
auto request = NetworkRequest::twitchRequest(
"https://tmi.twitch.tv/group/user/" + this->getChannel()->getName() +
"/chatters");
request.setCaller(this);
2018-08-02 14:23:27 +02:00
request.onSuccess([=](auto result) -> Outcome {
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));
2018-08-06 21:17:03 +02:00
foreach (const QJsonValue &v,
chattersObj.value(jsonLabels.at(i)).toArray())
chattersList->addItem(v.toString());
}
2018-08-02 14:23:27 +02:00
return Success;
});
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) {
2018-08-06 21:17:03 +02:00
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-08-02 14:23:27 +02:00
showUserInfoPopup(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-08-02 14:23:27 +02:00
showUserInfoPopup(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-08-02 14:23:27 +02:00
void Split::showUserInfoPopup(const UserName &user)
2017-09-12 22:10:30 +02:00
{
2018-06-06 16:29:35 +02:00
auto *userPopup = new UserInfoPopup;
2018-08-02 14:23:27 +02:00
userPopup->setData(user.string, this->getChannel());
2018-06-06 16:29:35 +02:00
userPopup->setAttribute(Qt::WA_DeleteOnClose);
2018-08-06 21:17:03 +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
}
2018-08-02 14:23:27 +02:00
void Split::copyToClipboard()
2017-09-12 19:06:16 +02:00
{
QApplication::clipboard()->setText(this->view_->getSelectedText());
2017-09-12 19:06:16 +02:00
}
2018-08-08 15:35:54 +02:00
void Split::showSearch()
2018-01-05 13:42:23 +01:00
{
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()
{
2018-08-02 14:23:27 +02:00
if (auto container = dynamic_cast<SplitContainer *>(this->parentWidget())) {
SplitContainer::isDraggingSplit = true;
SplitContainer::draggingSplit = this;
2018-05-10 19:50:31 +02:00
auto originalLocation = container->releaseSplit(this);
2018-08-02 14:23:27 +02:00
auto drag = new QDrag(this);
auto mimeData = new QMimeData;
mimeData->setData("chatterino/split", "xD");
drag->setMimeData(mimeData);
2018-08-02 14:23:27 +02:00
if (drag->exec(Qt::MoveAction) == Qt::IgnoreAction) {
container->insertSplit(this, originalLocation);
}
SplitContainer::isDraggingSplit = false;
}
}
2017-04-14 17:52:22 +02:00
} // namespace chatterino