ref: merge TooltipPreviewImage and TooltipWidget (#4268)
* merge TooltipPreviewImage and TooltipWidget * changelog * add empty line before return * fix signalholder include * add changelog for bugfix * fix custom scaling issue Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -1,81 +0,0 @@
|
||||
#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_.managedConnect(windows->gifRepaintRequested, [&] {
|
||||
if (this->image_ && this->image_->animated())
|
||||
{
|
||||
this->refreshTooltipWidgetPixmap();
|
||||
}
|
||||
});
|
||||
|
||||
this->connections_.managedConnect(windows->miscUpdate, [&] {
|
||||
if (this->attemptRefresh)
|
||||
{
|
||||
this->refreshTooltipWidgetPixmap();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void TooltipPreviewImage::setImage(ImagePtr image)
|
||||
{
|
||||
this->image_ = std::move(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
|
||||
@@ -1,36 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "messages/Image.hpp"
|
||||
|
||||
#include <pajlada/signals/signalholder.hpp>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class TooltipPreviewImage
|
||||
{
|
||||
public:
|
||||
static TooltipPreviewImage &instance();
|
||||
void setImage(ImagePtr image);
|
||||
void setImageScale(int w, int h);
|
||||
|
||||
TooltipPreviewImage(const TooltipPreviewImage &) = delete;
|
||||
|
||||
private:
|
||||
TooltipPreviewImage();
|
||||
|
||||
private:
|
||||
ImagePtr image_ = nullptr;
|
||||
int imageWidth_ = 0;
|
||||
int imageHeight_ = 0;
|
||||
|
||||
pajlada::Signals::SignalHolder 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
|
||||
Reference in New Issue
Block a user