diff --git a/chatterino.pro b/chatterino.pro index 41c875862..56517ef3c 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -139,6 +139,7 @@ SOURCES += \ src/singletons/Toasts.cpp \ src/singletons/Updates.cpp \ src/singletons/WindowManager.cpp \ + src/singletons/TooltipPreviewImage.cpp \ src/util/DebugCount.cpp \ src/util/FormatTime.cpp \ src/util/IncognitoBrowser.cpp \ @@ -301,6 +302,7 @@ HEADERS += \ src/providers/twitch/TwitchServer.hpp \ src/providers/twitch/TwitchUser.hpp \ src/RunGui.hpp \ + src/singletons/TooltipPreviewImage.hpp \ src/singletons/Badges.hpp \ src/singletons/Emotes.hpp \ src/singletons/helper/GifTimer.hpp \ diff --git a/src/singletons/TooltipPreviewImage.cpp b/src/singletons/TooltipPreviewImage.cpp new file mode 100644 index 000000000..b2d0445a4 --- /dev/null +++ b/src/singletons/TooltipPreviewImage.cpp @@ -0,0 +1,32 @@ +#include "TooltipPreviewImage.hpp" + +#include "Application.hpp" +#include "singletons/WindowManager.hpp" +#include "widgets/TooltipWidget.hpp" + +namespace chatterino { + TooltipPreviewImage &TooltipPreviewImage::getInstance() { + static TooltipPreviewImage *instance = new TooltipPreviewImage(); + return *instance; + } + + TooltipPreviewImage::TooltipPreviewImage() { + connections_.push_back(getApp()->windows->gifRepaintRequested.connect( + [&] { + auto tooltipWidget = TooltipWidget::getInstance(); + if (this->image_ && !tooltipWidget->isHidden()) { + auto pixmap = this->image_->pixmap(); + if (pixmap) { + tooltipWidget->setImage(*pixmap); + } + } else { + tooltipWidget->clearImage(); + } + })); + + } + + void TooltipPreviewImage::setImage(ImagePtr image) { + this->image_ = image; + } +} // namespace chatterino diff --git a/src/singletons/TooltipPreviewImage.hpp b/src/singletons/TooltipPreviewImage.hpp new file mode 100644 index 000000000..1d2474e04 --- /dev/null +++ b/src/singletons/TooltipPreviewImage.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "messages/Image.hpp" + +namespace chatterino { + class TooltipPreviewImage { + public: + static TooltipPreviewImage &getInstance(); + void setImage(ImagePtr image); + + private: + TooltipPreviewImage(); + + private: + ImagePtr image_ = nullptr; + std::vector connections_; + }; +} // namespace chatterino diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 657c2de0b..61dfbbfbd 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -23,6 +23,7 @@ #include "widgets/dialogs/UserInfoPopup.hpp" #include "widgets/helper/EffectLabel.hpp" #include "widgets/splits/Split.hpp" +#include "TooltipPreviewImage.hpp" #include #include @@ -105,8 +106,6 @@ namespace { } } // namespace -ImagePtr ChannelView::currentPreviewImage = nullptr; - ChannelView::ChannelView(BaseWidget *parent) : BaseWidget(parent) , scrollBar_(new Scrollbar(this)) @@ -314,16 +313,6 @@ void ChannelView::queueUpdate() // this->repaint(); - auto tooltipWidget = TooltipWidget::getInstance(); - if (ChannelView::currentPreviewImage) { - auto pixmap = ChannelView::currentPreviewImage->pixmap(); - if (pixmap) { - tooltipWidget->setImage(*pixmap); - } - } else { - tooltipWidget->clearImage(); - } - this->update(); // this->updateTimer.start(); @@ -1230,11 +1219,12 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) } else { + auto tooltipPreviewImage = TooltipPreviewImage::getInstance(); auto emoteElement = dynamic_cast(&hoverLayoutElement->getCreator()); if (emoteElement && getSettings()->emotesTooltipPreview.getValue()) { - ChannelView::currentPreviewImage = emoteElement->getEmote()->images.getImage(3.0); + tooltipPreviewImage->setImage(emoteElement->getEmote()->images.getImage(3.0)); } else { - ChannelView::currentPreviewImage = nullptr; + tooltipPreviewImage->setImage(nullptr); } tooltipWidget->moveTo(this, event->globalPos()); diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 7a9a6e31d..b4f33bf71 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -210,8 +210,6 @@ private: static constexpr int leftPadding = 8; static constexpr int scrollbarPadding = 8; - static ImagePtr currentPreviewImage; - private slots: void wordFlagsChanged() {