2019-06-11 20:03:04 +02:00
|
|
|
#include "TooltipPreviewImage.hpp"
|
|
|
|
|
|
|
|
#include "Application.hpp"
|
|
|
|
#include "singletons/WindowManager.hpp"
|
|
|
|
#include "widgets/TooltipWidget.hpp"
|
|
|
|
|
|
|
|
namespace chatterino {
|
2020-02-15 17:16:10 +01:00
|
|
|
|
2019-10-07 22:42:34 +02:00
|
|
|
TooltipPreviewImage &TooltipPreviewImage::instance()
|
2019-06-12 00:31:02 +02:00
|
|
|
{
|
|
|
|
static TooltipPreviewImage *instance = new TooltipPreviewImage();
|
|
|
|
return *instance;
|
|
|
|
}
|
2019-06-11 20:03:04 +02:00
|
|
|
|
2019-06-12 00:31:02 +02:00
|
|
|
TooltipPreviewImage::TooltipPreviewImage()
|
|
|
|
{
|
2020-02-15 17:16:10 +01:00
|
|
|
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
|
|
|
{
|
2020-02-15 17:16:10 +01:00
|
|
|
this->refreshTooltipWidgetPixmap();
|
2019-06-12 00:31:02 +02:00
|
|
|
}
|
2020-02-15 17:16:10 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
this->connections_.push_back(windows->miscUpdate.connect([&] {
|
|
|
|
if (this->attemptRefresh)
|
2019-06-12 00:31:02 +02:00
|
|
|
{
|
2020-02-15 17:16:10 +01:00
|
|
|
this->refreshTooltipWidgetPixmap();
|
2019-06-12 00:31:02 +02:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
2019-06-11 20:03:04 +02:00
|
|
|
|
2019-06-12 00:31:02 +02:00
|
|
|
void TooltipPreviewImage::setImage(ImagePtr image)
|
|
|
|
{
|
2021-04-10 14:34:40 +02:00
|
|
|
this->image_ = std::move(image);
|
2020-02-15 17:16:10 +01:00
|
|
|
|
|
|
|
this->refreshTooltipWidgetPixmap();
|
|
|
|
}
|
|
|
|
|
2020-05-10 12:11:10 +02:00
|
|
|
void TooltipPreviewImage::setImageScale(int w, int h)
|
|
|
|
{
|
|
|
|
this->imageWidth_ = w;
|
|
|
|
this->imageHeight_ = h;
|
|
|
|
|
|
|
|
this->refreshTooltipWidgetPixmap();
|
|
|
|
}
|
|
|
|
|
2020-02-15 17:16:10 +01:00
|
|
|
void TooltipPreviewImage::refreshTooltipWidgetPixmap()
|
|
|
|
{
|
|
|
|
auto tooltipWidget = TooltipWidget::instance();
|
|
|
|
|
|
|
|
if (this->image_ && !tooltipWidget->isHidden())
|
|
|
|
{
|
|
|
|
if (auto pixmap = this->image_->pixmapOrLoad())
|
|
|
|
{
|
2020-05-10 12:11:10 +02:00
|
|
|
if (this->imageWidth_ != 0 && this->imageHeight_)
|
|
|
|
{
|
|
|
|
tooltipWidget->setImage(pixmap->scaled(this->imageWidth_,
|
|
|
|
this->imageHeight_,
|
|
|
|
Qt::KeepAspectRatio));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tooltipWidget->setImage(*pixmap);
|
|
|
|
}
|
|
|
|
|
2020-02-15 17:16:10 +01:00
|
|
|
this->attemptRefresh = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->attemptRefresh = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tooltipWidget->clearImage();
|
|
|
|
}
|
2019-06-12 00:31:02 +02:00
|
|
|
}
|
2020-02-15 17:16:10 +01:00
|
|
|
|
2019-06-11 20:03:04 +02:00
|
|
|
} // namespace chatterino
|