mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Fixed always loading 1x, 2x and 3x images
This commit is contained in:
parent
294c2aecdc
commit
6274c05520
5 changed files with 19 additions and 10 deletions
|
@ -275,7 +275,14 @@ const Url &Image::url() const
|
||||||
return this->url_;
|
return this->url_;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<QPixmap> Image::pixmap() const
|
bool Image::loaded() const
|
||||||
|
{
|
||||||
|
assertInGuiThread();
|
||||||
|
|
||||||
|
return bool(this->frames_->current());
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::optional<QPixmap> Image::pixmapOrLoad() const
|
||||||
{
|
{
|
||||||
assertInGuiThread();
|
assertInGuiThread();
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,9 @@ public:
|
||||||
static ImagePtr getEmpty();
|
static ImagePtr getEmpty();
|
||||||
|
|
||||||
const Url &url() const;
|
const Url &url() const;
|
||||||
boost::optional<QPixmap> pixmap() const;
|
bool loaded() const;
|
||||||
|
// either returns the current pixmap, or triggers loading it (lazy loading)
|
||||||
|
boost::optional<QPixmap> pixmapOrLoad() const;
|
||||||
qreal scale() const;
|
qreal scale() const;
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
int width() const;
|
int width() const;
|
||||||
|
|
|
@ -84,16 +84,16 @@ const ImagePtr &ImageSet::getImage(float scale) const
|
||||||
return this->imageX1_;
|
return this->imageX1_;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
// prefere other image if selected image is not loaded yet
|
// prefer other image if selected image is not loaded yet
|
||||||
if (result->pixmap())
|
if (result->loaded())
|
||||||
return result;
|
return result;
|
||||||
else if (this->imageX1_->pixmap())
|
else if (this->imageX1_->loaded())
|
||||||
return this->imageX1_;
|
return this->imageX1_;
|
||||||
else if (this->imageX2_ && !this->imageX2_->isEmpty() &&
|
else if (this->imageX2_ && !this->imageX2_->isEmpty() &&
|
||||||
this->imageX2_->pixmap())
|
this->imageX2_->loaded())
|
||||||
return this->imageX2_;
|
return this->imageX2_;
|
||||||
else if (this->imageX3_ && !this->imageX3_->isEmpty() &&
|
else if (this->imageX3_ && !this->imageX3_->isEmpty() &&
|
||||||
this->imageX3_->pixmap())
|
this->imageX3_->loaded())
|
||||||
return this->imageX3_;
|
return this->imageX3_;
|
||||||
else
|
else
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -120,7 +120,7 @@ void ImageLayoutElement::paint(QPainter &painter)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pixmap = this->image_->pixmap();
|
auto pixmap = this->image_->pixmapOrLoad();
|
||||||
if (pixmap && !this->image_->animated())
|
if (pixmap && !this->image_->animated())
|
||||||
{
|
{
|
||||||
// fourtf: make it use qreal values
|
// fourtf: make it use qreal values
|
||||||
|
@ -137,7 +137,7 @@ void ImageLayoutElement::paintAnimated(QPainter &painter, int yOffset)
|
||||||
|
|
||||||
if (this->image_->animated())
|
if (this->image_->animated())
|
||||||
{
|
{
|
||||||
if (auto pixmap = this->image_->pixmap())
|
if (auto pixmap = this->image_->pixmapOrLoad())
|
||||||
{
|
{
|
||||||
auto rect = this->getRect();
|
auto rect = this->getRect();
|
||||||
rect.moveTop(rect.y() + yOffset);
|
rect.moveTop(rect.y() + yOffset);
|
||||||
|
|
|
@ -17,7 +17,7 @@ TooltipPreviewImage::TooltipPreviewImage()
|
||||||
auto tooltipWidget = TooltipWidget::getInstance();
|
auto tooltipWidget = TooltipWidget::getInstance();
|
||||||
if (this->image_ && !tooltipWidget->isHidden())
|
if (this->image_ && !tooltipWidget->isHidden())
|
||||||
{
|
{
|
||||||
auto pixmap = this->image_->pixmap();
|
auto pixmap = this->image_->pixmapOrLoad();
|
||||||
if (pixmap)
|
if (pixmap)
|
||||||
{
|
{
|
||||||
tooltipWidget->setImage(*pixmap);
|
tooltipWidget->setImage(*pixmap);
|
||||||
|
|
Loading…
Reference in a new issue