mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Fix preview on hover not working when Animated emotes options was disabled.
Fixes #1546 This change introduces a "window timer" that runs every 100ms that we use to update the pixmap if necessary, since there is no signal for "let me know when this image is done loading".
This commit is contained in:
parent
64c58e724a
commit
7a08d73434
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "messages/Image.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class TooltipPreviewImage
|
||||
{
|
||||
public:
|
||||
|
@ -17,5 +18,13 @@ private:
|
|||
private:
|
||||
ImagePtr image_ = nullptr;
|
||||
std::vector<pajlada::Signals::ScopedConnection> 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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue