Add thumbnails to link tooltips if available (#1664)
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>
This commit is contained in:
@@ -161,6 +161,7 @@ public:
|
||||
/// Links
|
||||
BoolSetting linksDoubleClickOnly = {"/links/doubleClickToOpen", false};
|
||||
BoolSetting linkInfoTooltip = {"/links/linkInfoTooltip", false};
|
||||
IntSetting thumbnailSize = {"/appearance/thumbnailSize", 0};
|
||||
BoolSetting unshortLinks = {"/links/unshortLinks", false};
|
||||
BoolSetting lowercaseDomains = {"/links/linkLowercase", true};
|
||||
|
||||
|
||||
@@ -38,6 +38,14 @@ void TooltipPreviewImage::setImage(ImagePtr 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();
|
||||
@@ -46,7 +54,17 @@ void TooltipPreviewImage::refreshTooltipWidgetPixmap()
|
||||
{
|
||||
if (auto pixmap = this->image_->pixmapOrLoad())
|
||||
{
|
||||
tooltipWidget->setImage(*pixmap);
|
||||
if (this->imageWidth_ != 0 && this->imageHeight_)
|
||||
{
|
||||
tooltipWidget->setImage(pixmap->scaled(this->imageWidth_,
|
||||
this->imageHeight_,
|
||||
Qt::KeepAspectRatio));
|
||||
}
|
||||
else
|
||||
{
|
||||
tooltipWidget->setImage(*pixmap);
|
||||
}
|
||||
|
||||
this->attemptRefresh = false;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -9,6 +9,7 @@ class TooltipPreviewImage
|
||||
public:
|
||||
static TooltipPreviewImage &instance();
|
||||
void setImage(ImagePtr image);
|
||||
void setImageScale(int w, int h);
|
||||
|
||||
TooltipPreviewImage(const TooltipPreviewImage &) = delete;
|
||||
|
||||
@@ -17,6 +18,9 @@ private:
|
||||
|
||||
private:
|
||||
ImagePtr image_ = nullptr;
|
||||
int imageWidth_ = 0;
|
||||
int imageHeight_ = 0;
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user