From e31bb48384a4b49f1faf9d3cff504124aaa75564 Mon Sep 17 00:00:00 2001 From: fourtf Date: Sun, 17 Sep 2017 02:13:57 +0200 Subject: [PATCH] fixed gifs on the emotepicker --- src/channelmanager.cpp | 5 +++++ src/channelmanager.hpp | 1 + src/widgets/channelview.cpp | 7 ++++++- src/widgets/channelview.hpp | 5 ++++- src/widgets/chatwidget.cpp | 6 +++--- src/widgets/chatwidgetinput.cpp | 7 +++++-- src/widgets/chatwidgetinput.hpp | 3 ++- src/widgets/emotepopup.cpp | 5 +++-- src/widgets/emotepopup.hpp | 2 +- src/widgets/mainwindow.cpp | 17 ----------------- src/widgets/mainwindow.hpp | 1 - src/windowmanager.cpp | 4 +--- src/windowmanager.hpp | 2 ++ 13 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/channelmanager.cpp b/src/channelmanager.cpp index 5ddc9d340..7f26232c9 100644 --- a/src/channelmanager.cpp +++ b/src/channelmanager.cpp @@ -131,4 +131,9 @@ EmoteManager &ChannelManager::getEmoteManager() return this->emoteManager; } +WindowManager &ChannelManager::getWindowManager() +{ + return this->windowManager; +} + } // namespace chatterino diff --git a/src/channelmanager.hpp b/src/channelmanager.hpp index c8269b1b4..8a669e94e 100644 --- a/src/channelmanager.hpp +++ b/src/channelmanager.hpp @@ -30,6 +30,7 @@ public: const std::string &getUserID(const std::string &username); EmoteManager &getEmoteManager(); + WindowManager &getWindowManager(); // Special channels const std::shared_ptr whispersChannel; diff --git a/src/widgets/channelview.cpp b/src/widgets/channelview.cpp index c0b93387f..e7b2734c6 100644 --- a/src/widgets/channelview.cpp +++ b/src/widgets/channelview.cpp @@ -8,6 +8,7 @@ #include "ui_accountpopupform.h" #include "util/distancebetweenpoints.hpp" #include "widgets/chatwidget.hpp" +#include "windowmanager.hpp" #include #include @@ -25,8 +26,9 @@ using namespace chatterino::messages; namespace chatterino { namespace widgets { -ChannelView::ChannelView(BaseWidget *parent) +ChannelView::ChannelView(WindowManager &windowManager, BaseWidget *parent) : BaseWidget(parent) + , windowManager(windowManager) , scrollBar(this) , userPopupWidget(std::shared_ptr()) { @@ -44,6 +46,9 @@ ChannelView::ChannelView(BaseWidget *parent) this->layoutMessages(); }); + + this->repaintGifsConnection = + windowManager.repaintGifs.connect([&] { this->updateGifEmotes(); }); } ChannelView::~ChannelView() diff --git a/src/widgets/channelview.hpp b/src/widgets/channelview.hpp index a98405920..1ce7780bc 100644 --- a/src/widgets/channelview.hpp +++ b/src/widgets/channelview.hpp @@ -83,7 +83,7 @@ class ChannelView : public BaseWidget Q_OBJECT public: - explicit ChannelView(BaseWidget *parent = 0); + explicit ChannelView(WindowManager &windowManager, BaseWidget *parent = 0); ~ChannelView(); void updateGifEmotes(); @@ -117,6 +117,8 @@ private: QRect rect; }; + WindowManager &windowManager; + void detachChannel(); void drawMessages(QPainter &painter); @@ -149,6 +151,7 @@ private: boost::signals2::connection messageAppendedConnection; boost::signals2::connection messageRemovedConnection; + boost::signals2::connection repaintGifsConnection; private slots: void wordTypeMaskChanged() diff --git a/src/widgets/chatwidget.cpp b/src/widgets/chatwidget.cpp index 3d2622043..ebd1146b8 100644 --- a/src/widgets/chatwidget.cpp +++ b/src/widgets/chatwidget.cpp @@ -52,8 +52,8 @@ ChatWidget::ChatWidget(ChannelManager &_channelManager, NotebookPage *parent) , channel(_channelManager.emptyChannel) , vbox(this) , header(this) - , view(this) - , input(this, _channelManager.getEmoteManager()) + , view(_channelManager.getWindowManager(), this) + , input(this, _channelManager.getEmoteManager(), _channelManager.getWindowManager()) { this->vbox.setSpacing(0); this->vbox.setMargin(1); @@ -87,7 +87,7 @@ ChatWidget::ChatWidget(ChannelManager &_channelManager, NotebookPage *parent) ChatWidget::~ChatWidget() { - channelNameUpdated(""); + this->channelNameUpdated(""); } std::shared_ptr ChatWidget::getChannel() const diff --git a/src/widgets/chatwidgetinput.cpp b/src/widgets/chatwidgetinput.cpp index 1a1ff45a4..8666513df 100644 --- a/src/widgets/chatwidgetinput.cpp +++ b/src/widgets/chatwidgetinput.cpp @@ -13,10 +13,12 @@ namespace chatterino { namespace widgets { -ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget, EmoteManager &emoteManager) +ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget, EmoteManager &emoteManager, + WindowManager &windowManager) : BaseWidget(_chatWidget) , chatWidget(_chatWidget) , emoteManager(emoteManager) + , windowManager(windowManager) , emotesLabel(this) { this->setMaximumHeight(150); @@ -47,7 +49,8 @@ ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget, EmoteManager &emoteMan connect(&this->emotesLabel, &RippleEffectLabel::clicked, [this] { if (this->emotePopup == nullptr) { - this->emotePopup = new EmotePopup(this->colorScheme, this->emoteManager); + this->emotePopup = + new EmotePopup(this->colorScheme, this->emoteManager, this->windowManager); } this->emotePopup->resize(300, 500); diff --git a/src/widgets/chatwidgetinput.hpp b/src/widgets/chatwidgetinput.hpp index a12a983e2..3a1724781 100644 --- a/src/widgets/chatwidgetinput.hpp +++ b/src/widgets/chatwidgetinput.hpp @@ -26,7 +26,7 @@ class ChatWidgetInput : public BaseWidget Q_OBJECT public: - ChatWidgetInput(ChatWidget *_chatWidget, EmoteManager &); + ChatWidgetInput(ChatWidget *_chatWidget, EmoteManager &, WindowManager &); ~ChatWidgetInput(); protected: @@ -39,6 +39,7 @@ private: ChatWidget *const chatWidget; EmotePopup *emotePopup = nullptr; EmoteManager &emoteManager; + WindowManager &windowManager; boost::signals2::connection textLengthVisibleChangedConnection; QHBoxLayout hbox; diff --git a/src/widgets/emotepopup.cpp b/src/widgets/emotepopup.cpp index 17891cc53..281dd1d68 100644 --- a/src/widgets/emotepopup.cpp +++ b/src/widgets/emotepopup.cpp @@ -11,7 +11,8 @@ using namespace chatterino::messages; namespace chatterino { namespace widgets { -EmotePopup::EmotePopup(ColorScheme &colorScheme, EmoteManager &emoteManager) +EmotePopup::EmotePopup(ColorScheme &colorScheme, EmoteManager &emoteManager, + WindowManager &windowManager) : BaseWidget(colorScheme, 0) , emoteManager(emoteManager) { @@ -19,7 +20,7 @@ EmotePopup::EmotePopup(ColorScheme &colorScheme, EmoteManager &emoteManager) this->setLayout(layout); layout->setMargin(0); - view = new ChannelView(this); + view = new ChannelView(windowManager, this); layout->addWidget(view); } diff --git a/src/widgets/emotepopup.hpp b/src/widgets/emotepopup.hpp index 4c8255213..5df4cf7e7 100644 --- a/src/widgets/emotepopup.hpp +++ b/src/widgets/emotepopup.hpp @@ -11,7 +11,7 @@ namespace widgets { class EmotePopup : public BaseWidget { public: - explicit EmotePopup(ColorScheme &, EmoteManager &); + explicit EmotePopup(ColorScheme &, EmoteManager &, WindowManager &); void loadChannel(std::shared_ptr channel); diff --git a/src/widgets/mainwindow.cpp b/src/widgets/mainwindow.cpp index a35e07239..7a3380101 100644 --- a/src/widgets/mainwindow.cpp +++ b/src/widgets/mainwindow.cpp @@ -108,23 +108,6 @@ void MainWindow::repaintVisibleChatWidgets(Channel *channel) } } -void MainWindow::repaintGifEmotes() -{ - auto *page = this->notebook.getSelectedPage(); - - if (page == nullptr) { - return; - } - - const std::vector &widgets = page->getChatWidgets(); - - for (auto it = widgets.begin(); it != widgets.end(); ++it) { - ChatWidget *widget = *it; - - widget->updateGifEmotes(); - } -} - void MainWindow::load(const boost::property_tree::ptree &tree) { this->notebook.load(tree); diff --git a/src/widgets/mainwindow.hpp b/src/widgets/mainwindow.hpp index cfbe2a960..758fc7898 100644 --- a/src/widgets/mainwindow.hpp +++ b/src/widgets/mainwindow.hpp @@ -32,7 +32,6 @@ public: void layoutVisibleChatWidgets(Channel *channel = nullptr); void repaintVisibleChatWidgets(Channel *channel = nullptr); - void repaintGifEmotes(); void load(const boost::property_tree::ptree &tree); boost::property_tree::ptree save(); diff --git a/src/windowmanager.cpp b/src/windowmanager.cpp index 3904862ea..f71c5ca7f 100644 --- a/src/windowmanager.cpp +++ b/src/windowmanager.cpp @@ -41,9 +41,7 @@ void WindowManager::repaintVisibleChatWidgets(Channel *channel) void WindowManager::repaintGifEmotes() { - if (this->mainWindow != nullptr) { - this->mainWindow->repaintGifEmotes(); - } + this->repaintGifs(); } // void WindowManager::updateAll() diff --git a/src/windowmanager.hpp b/src/windowmanager.hpp index 69f50aa85..c5f1231d3 100644 --- a/src/windowmanager.hpp +++ b/src/windowmanager.hpp @@ -30,6 +30,8 @@ public: void load(); void save(); + boost::signals2::signal repaintGifs; + private: std::mutex windowMutex;