diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c427d8f3..201b0be80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,3 +2,4 @@ ## Unversioned - Minor: Emotes in the emote popup are now sorted in the same order as the tab completion (#1549) +- Bugfix: Fix preview on hover not working when Animated emotes options was disabled (#1546) diff --git a/src/singletons/TooltipPreviewImage.cpp b/src/singletons/TooltipPreviewImage.cpp index 5355b7d8e..ebb0fe6a6 100644 --- a/src/singletons/TooltipPreviewImage.cpp +++ b/src/singletons/TooltipPreviewImage.cpp @@ -5,6 +5,7 @@ #include "widgets/TooltipWidget.hpp" namespace chatterino { + TooltipPreviewImage &TooltipPreviewImage::instance() { static TooltipPreviewImage *instance = new TooltipPreviewImage(); @@ -13,19 +14,19 @@ TooltipPreviewImage &TooltipPreviewImage::instance() TooltipPreviewImage::TooltipPreviewImage() { - connections_.push_back(getApp()->windows->gifRepaintRequested.connect([&] { - auto tooltipWidget = TooltipWidget::instance(); - if (this->image_ && !tooltipWidget->isHidden()) + auto windows = getApp()->windows; + + this->connections_.push_back(windows->gifRepaintRequested.connect([&] { + if (this->image_ && this->image_->animated()) { - auto pixmap = this->image_->pixmapOrLoad(); - if (pixmap) - { - tooltipWidget->setImage(*pixmap); - } + this->refreshTooltipWidgetPixmap(); } - else + })); + + this->connections_.push_back(windows->miscUpdate.connect([&] { + if (this->attemptRefresh) { - tooltipWidget->clearImage(); + this->refreshTooltipWidgetPixmap(); } })); } @@ -33,5 +34,30 @@ TooltipPreviewImage::TooltipPreviewImage() void TooltipPreviewImage::setImage(ImagePtr image) { this->image_ = image; + + this->refreshTooltipWidgetPixmap(); } + +void TooltipPreviewImage::refreshTooltipWidgetPixmap() +{ + auto tooltipWidget = TooltipWidget::instance(); + + if (this->image_ && !tooltipWidget->isHidden()) + { + if (auto pixmap = this->image_->pixmapOrLoad()) + { + tooltipWidget->setImage(*pixmap); + this->attemptRefresh = false; + } + else + { + this->attemptRefresh = true; + } + } + else + { + tooltipWidget->clearImage(); + } +} + } // namespace chatterino diff --git a/src/singletons/TooltipPreviewImage.hpp b/src/singletons/TooltipPreviewImage.hpp index 5b23945f4..0d1f6f070 100644 --- a/src/singletons/TooltipPreviewImage.hpp +++ b/src/singletons/TooltipPreviewImage.hpp @@ -3,6 +3,7 @@ #include "messages/Image.hpp" namespace chatterino { + class TooltipPreviewImage { public: @@ -17,5 +18,13 @@ private: private: ImagePtr image_ = nullptr; std::vector connections_; + + // attemptRefresh is set to true in case we want to preview an image that has not loaded yet (if pixmapOrLoad fails) + bool attemptRefresh{false}; + + // Refresh the pixmap used in the Tooltip Widget + // Called from setImage and from the "gif repaint" signal if the image is animated + void refreshTooltipWidgetPixmap(); }; + } // namespace chatterino diff --git a/src/singletons/WindowManager.cpp b/src/singletons/WindowManager.cpp index bddb948f7..fb1a28a3b 100644 --- a/src/singletons/WindowManager.cpp +++ b/src/singletons/WindowManager.cpp @@ -111,6 +111,12 @@ WindowManager::WindowManager() QObject::connect(this->saveTimer, &QTimer::timeout, [] { getApp()->windows->save(); // }); + + this->miscUpdateTimer_.start(100); + + QObject::connect(&this->miscUpdateTimer_, &QTimer::timeout, [this] { + this->miscUpdate.invoke(); // + }); } MessageElementFlags WindowManager::getWordFlags() diff --git a/src/singletons/WindowManager.hpp b/src/singletons/WindowManager.hpp index 77084eaa0..9dfd8d9bb 100644 --- a/src/singletons/WindowManager.hpp +++ b/src/singletons/WindowManager.hpp @@ -80,6 +80,10 @@ public: pajlada::Signals::NoArgSignal wordFlagsChanged; + // This signal fires every 100ms and can be used to trigger random things that require a recheck. + // It is currently being used by the "Tooltip Preview Image" system to recheck if an image is ready to be rendered. + pajlada::Signals::NoArgSignal miscUpdate; + private: void encodeNodeRecusively(SplitContainer::Node *node, QJsonObject &obj); @@ -96,6 +100,7 @@ private: pajlada::SettingListener wordFlagsListener_; QTimer *saveTimer; + QTimer miscUpdateTimer_; }; } // namespace chatterino