From 05339aad2dc2bb2e4ab92a0a56f5eb4f52f044cf Mon Sep 17 00:00:00 2001 From: fourtf Date: Wed, 24 Jan 2018 20:58:53 +0100 Subject: [PATCH] started fixing clicking emtoes --- src/widgets/emotepopup.cpp | 5 +++++ src/widgets/emotepopup.hpp | 4 ++++ src/widgets/helper/channelview.cpp | 2 ++ src/widgets/helper/channelview.hpp | 1 + src/widgets/helper/splitinput.cpp | 14 ++++++++++++-- src/widgets/helper/splitinput.hpp | 3 ++- 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/widgets/emotepopup.cpp b/src/widgets/emotepopup.cpp index 1fce82c50..e2aa58256 100644 --- a/src/widgets/emotepopup.cpp +++ b/src/widgets/emotepopup.cpp @@ -30,6 +30,11 @@ EmotePopup::EmotePopup(singletons::ThemeManager &themeManager) tabs->addTab(this->viewEmojis, "Emojis"); this->loadEmojis(); + + this->viewEmotes->linkClicked.connect( + [this](const Link &link) { this->linkClicked.invoke(link); }); + this->viewEmojis->linkClicked.connect( + [this](const Link &link) { this->linkClicked.invoke(link); }); } void EmotePopup::loadChannel(ChannelPtr _channel) diff --git a/src/widgets/emotepopup.hpp b/src/widgets/emotepopup.hpp index e6727dd74..53fd9885d 100644 --- a/src/widgets/emotepopup.hpp +++ b/src/widgets/emotepopup.hpp @@ -4,6 +4,8 @@ #include "widgets/basewindow.hpp" #include "widgets/helper/channelview.hpp" +#include + namespace chatterino { namespace widgets { @@ -15,6 +17,8 @@ public: void loadChannel(ChannelPtr channel); void loadEmojis(); + pajlada::Signals::Signal linkClicked; + private: ChannelView *viewEmotes; ChannelView *viewEmojis; diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index 6f25aba52..b6c18e828 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -834,6 +834,8 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event) this->channel->sendMessage(value); } } + + this->linkClicked.invoke(link); } bool ChannelView::tryGetMessageAt(QPoint p, std::shared_ptr &_message, diff --git a/src/widgets/helper/channelview.hpp b/src/widgets/helper/channelview.hpp index 2661f2031..a57691154 100644 --- a/src/widgets/helper/channelview.hpp +++ b/src/widgets/helper/channelview.hpp @@ -50,6 +50,7 @@ public: boost::signals2::signal mouseDown; boost::signals2::signal selectionChanged; pajlada::Signals::NoArgSignal highlightedMessageReceived; + pajlada::Signals::Signal linkClicked; protected: virtual void refreshTheme() override; diff --git a/src/widgets/helper/splitinput.cpp b/src/widgets/helper/splitinput.cpp index 125920c3d..8e17a0500 100644 --- a/src/widgets/helper/splitinput.cpp +++ b/src/widgets/helper/splitinput.cpp @@ -52,8 +52,13 @@ SplitInput::SplitInput(Split *_chatWidget) "/>"); connect(&this->emotesLabel, &RippleEffectLabel::clicked, [this] { - if (this->emotePopup == nullptr) { - this->emotePopup = new EmotePopup(this->themeManager); + if (!this->emotePopup) { + this->emotePopup = std::make_unique(this->themeManager); + this->emotePopup->linkClicked.connect([this](const messages::Link &link) { + if (link.getType() == messages::Link::InsertText) { + this->insertText(link.getValue()); + } + }); } this->emotePopup->resize((int)(300 * this->emotePopup->getDpiMultiplier()), @@ -210,6 +215,11 @@ QString SplitInput::getInputText() const return this->textInput.toPlainText(); } +void SplitInput::insertText(const QString &text) +{ + this->textInput.insertPlainText(text); +} + void SplitInput::refreshTheme() { QPalette palette; diff --git a/src/widgets/helper/splitinput.hpp b/src/widgets/helper/splitinput.hpp index 63321af74..951efd9c2 100644 --- a/src/widgets/helper/splitinput.hpp +++ b/src/widgets/helper/splitinput.hpp @@ -27,6 +27,7 @@ public: void clearSelection(); QString getInputText() const; + void insertText(const QString &text); pajlada::Signals::Signal textChanged; @@ -38,7 +39,7 @@ protected: private: Split *const chatWidget; - EmotePopup *emotePopup = nullptr; + std::unique_ptr emotePopup; std::vector managedConnections; QHBoxLayout hbox;