mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
This feature is off by default and can be enabled in the settings with the "Show link thumbnail" setting. This feature also requires the "Show link info when hovering" setting to be enabled. thumbnails support is only there for direct image links, twitch clips, and youtube links. can be expanded in the future in the /api repo Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
81 lines
1.9 KiB
C++
81 lines
1.9 KiB
C++
#include "TooltipPreviewImage.hpp"
|
|
|
|
#include "Application.hpp"
|
|
#include "singletons/WindowManager.hpp"
|
|
#include "widgets/TooltipWidget.hpp"
|
|
|
|
namespace chatterino {
|
|
|
|
TooltipPreviewImage &TooltipPreviewImage::instance()
|
|
{
|
|
static TooltipPreviewImage *instance = new TooltipPreviewImage();
|
|
return *instance;
|
|
}
|
|
|
|
TooltipPreviewImage::TooltipPreviewImage()
|
|
{
|
|
auto windows = getApp()->windows;
|
|
|
|
this->connections_.push_back(windows->gifRepaintRequested.connect([&] {
|
|
if (this->image_ && this->image_->animated())
|
|
{
|
|
this->refreshTooltipWidgetPixmap();
|
|
}
|
|
}));
|
|
|
|
this->connections_.push_back(windows->miscUpdate.connect([&] {
|
|
if (this->attemptRefresh)
|
|
{
|
|
this->refreshTooltipWidgetPixmap();
|
|
}
|
|
}));
|
|
}
|
|
|
|
void TooltipPreviewImage::setImage(ImagePtr image)
|
|
{
|
|
this->image_ = image;
|
|
|
|
this->refreshTooltipWidgetPixmap();
|
|
}
|
|
|
|
void TooltipPreviewImage::setImageScale(int w, int h)
|
|
{
|
|
this->imageWidth_ = w;
|
|
this->imageHeight_ = h;
|
|
|
|
this->refreshTooltipWidgetPixmap();
|
|
}
|
|
|
|
void TooltipPreviewImage::refreshTooltipWidgetPixmap()
|
|
{
|
|
auto tooltipWidget = TooltipWidget::instance();
|
|
|
|
if (this->image_ && !tooltipWidget->isHidden())
|
|
{
|
|
if (auto pixmap = this->image_->pixmapOrLoad())
|
|
{
|
|
if (this->imageWidth_ != 0 && this->imageHeight_)
|
|
{
|
|
tooltipWidget->setImage(pixmap->scaled(this->imageWidth_,
|
|
this->imageHeight_,
|
|
Qt::KeepAspectRatio));
|
|
}
|
|
else
|
|
{
|
|
tooltipWidget->setImage(*pixmap);
|
|
}
|
|
|
|
this->attemptRefresh = false;
|
|
}
|
|
else
|
|
{
|
|
this->attemptRefresh = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
tooltipWidget->clearImage();
|
|
}
|
|
}
|
|
|
|
} // namespace chatterino
|