mirror-chatterino2/src/singletons/TooltipPreviewImage.cpp

64 lines
1.4 KiB
C++
Raw Normal View History

#include "TooltipPreviewImage.hpp"
#include "Application.hpp"
#include "singletons/WindowManager.hpp"
#include "widgets/TooltipWidget.hpp"
namespace chatterino {
TooltipPreviewImage &TooltipPreviewImage::instance()
2019-06-12 00:31:02 +02:00
{
static TooltipPreviewImage *instance = new TooltipPreviewImage();
return *instance;
}
2019-06-12 00:31:02 +02:00
TooltipPreviewImage::TooltipPreviewImage()
{
auto windows = getApp()->windows;
this->connections_.push_back(windows->gifRepaintRequested.connect([&] {
if (this->image_ && this->image_->animated())
2019-06-12 00:31:02 +02:00
{
this->refreshTooltipWidgetPixmap();
2019-06-12 00:31:02 +02:00
}
}));
this->connections_.push_back(windows->miscUpdate.connect([&] {
if (this->attemptRefresh)
2019-06-12 00:31:02 +02:00
{
this->refreshTooltipWidgetPixmap();
2019-06-12 00:31:02 +02:00
}
}));
}
2019-06-12 00:31:02 +02:00
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();
}
2019-06-12 00:31:02 +02:00
}
} // namespace chatterino