From 8ab0fa437824f9ad6ab254b2ef32b2112d4a778c Mon Sep 17 00:00:00 2001 From: fourtf Date: Wed, 24 Jan 2018 22:09:26 +0100 Subject: [PATCH] Fixes #259 dropping split on + button --- src/singletons/ircmanager.cpp | 8 ++--- src/widgets/helper/channelview.cpp | 3 +- src/widgets/helper/notebookbutton.cpp | 47 +++++++++++++++++++++++++++ src/widgets/helper/notebookbutton.hpp | 7 ++-- 4 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/singletons/ircmanager.cpp b/src/singletons/ircmanager.cpp index 59f829ec9..aa5753cf0 100644 --- a/src/singletons/ircmanager.cpp +++ b/src/singletons/ircmanager.cpp @@ -256,12 +256,12 @@ void IrcManager::privateMessageReceived(Communi::IrcPrivateMessage *message) twitch::TwitchMessageBuilder builder(c.get(), message, args); if (!builder.isIgnored()) { - messages::MessagePtr message = builder.build(); - if (message->hasFlags(messages::Message::Highlighted)) { - singletons::ChannelManager::getInstance().mentionsChannel->addMessage(message); + messages::MessagePtr _message = builder.build(); + if (_message->hasFlags(messages::Message::Highlighted)) { + singletons::ChannelManager::getInstance().mentionsChannel->addMessage(_message); } - c->addMessage(message); + c->addMessage(_message); } } diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index c6eb3a512..12944c25a 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -813,7 +813,8 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event) } auto &link = hoverLayoutElement->getLink(); - if (!singletons::SettingManager::getInstance().linksDoubleClickOnly) { + if (event->button() != Qt::LeftButton || + !singletons::SettingManager::getInstance().linksDoubleClickOnly) { this->handleLinkClick(event, link, layout.get()); } diff --git a/src/widgets/helper/notebookbutton.cpp b/src/widgets/helper/notebookbutton.cpp index 3f567f3ff..6aa06dc1a 100644 --- a/src/widgets/helper/notebookbutton.cpp +++ b/src/widgets/helper/notebookbutton.cpp @@ -1,12 +1,16 @@ #include "widgets/helper/notebookbutton.hpp" #include "singletons/thememanager.hpp" #include "widgets/helper/rippleeffectbutton.hpp" +#include "widgets/notebook.hpp" +#include "widgets/splitcontainer.hpp" #include #include #include #include +#define nuuls nullptr + namespace chatterino { namespace widgets { @@ -14,6 +18,8 @@ NotebookButton::NotebookButton(BaseWidget *parent) : RippleEffectButton(parent) { setMouseEffectColor(QColor(0, 0, 0)); + + this->setAcceptDrops(true); } void NotebookButton::paintEvent(QPaintEvent *) @@ -97,5 +103,46 @@ void NotebookButton::mouseReleaseEvent(QMouseEvent *event) RippleEffectButton::mouseReleaseEvent(event); } +void NotebookButton::dragEnterEvent(QDragEnterEvent *event) +{ + if (!event->mimeData()->hasFormat("chatterino/split")) + return; + + event->acceptProposedAction(); + + auto e = new QMouseEvent(QMouseEvent::MouseButtonPress, + QPointF(this->width() / 2, this->height() / 2), Qt::LeftButton, + Qt::LeftButton, 0); + RippleEffectButton::mousePressEvent(e); + delete e; +} + +void NotebookButton::dragLeaveEvent(QDragLeaveEvent *) +{ + this->mouseDown = true; + this->update(); + + auto e = new QMouseEvent(QMouseEvent::MouseButtonRelease, + QPointF(this->width() / 2, this->height() / 2), Qt::LeftButton, + Qt::LeftButton, 0); + RippleEffectButton::mouseReleaseEvent(e); + delete e; +} + +void NotebookButton::dropEvent(QDropEvent *event) +{ + if (SplitContainer::isDraggingSplit) { + event->acceptProposedAction(); + + Notebook *notebook = dynamic_cast(this->parentWidget()); + + if (notebook != nuuls) { + SplitContainer *tab = notebook->addNewPage(); + + SplitContainer::draggingSplit->setParent(tab); + tab->addToLayout(SplitContainer::draggingSplit); + } + } +} } // namespace widgets } // namespace chatterino diff --git a/src/widgets/helper/notebookbutton.hpp b/src/widgets/helper/notebookbutton.hpp index 811c21667..a62b80026 100644 --- a/src/widgets/helper/notebookbutton.hpp +++ b/src/widgets/helper/notebookbutton.hpp @@ -21,8 +21,11 @@ public: NotebookButton(BaseWidget *parent); protected: - void paintEvent(QPaintEvent *) override; - void mouseReleaseEvent(QMouseEvent *event) override; + virtual void paintEvent(QPaintEvent *) override; + virtual void mouseReleaseEvent(QMouseEvent *) override; + virtual void dragEnterEvent(QDragEnterEvent *) override; + virtual void dragLeaveEvent(QDragLeaveEvent *) override; + virtual void dropEvent(QDropEvent *) override; signals: void clicked();