From e98f56b0b7d2a880e08f08bddb53d92789312c97 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 5 Nov 2023 18:10:27 +0300 Subject: [PATCH] Fixed aspect ratio of non-standard stickers in photo editor. --- Telegram/SourceFiles/editor/scene/scene_item_image.cpp | 8 +++++++- Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/editor/scene/scene_item_image.cpp b/Telegram/SourceFiles/editor/scene/scene_item_image.cpp index b932b11ad..b3cc544cf 100644 --- a/Telegram/SourceFiles/editor/scene/scene_item_image.cpp +++ b/Telegram/SourceFiles/editor/scene/scene_item_image.cpp @@ -23,7 +23,13 @@ void ItemImage::paint( QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *w) { - p->drawPixmap(contentRect().toRect(), _pixmap); + const auto rect = contentRect(); + const auto pixmapSize = QSizeF(_pixmap.size() / style::DevicePixelRatio()) + .scaled(rect.size(), Qt::KeepAspectRatio); + const auto resultRect = QRectF(rect.topLeft(), pixmapSize).translated( + (rect.width() - pixmapSize.width()) / 2., + (rect.height() - pixmapSize.height()) / 2.); + p->drawPixmap(resultRect.toRect(), _pixmap); ItemBase::paint(p, option, w); } diff --git a/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp b/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp index a60f487e0..c678452e9 100644 --- a/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp +++ b/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp @@ -110,7 +110,13 @@ void ItemSticker::paint( QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *w) { - p->drawImage(contentRect().toRect(), _image); + const auto rect = contentRect(); + const auto imageSize = QSizeF(_image.size() / style::DevicePixelRatio()) + .scaled(rect.size(), Qt::KeepAspectRatio); + const auto resultRect = QRectF(rect.topLeft(), imageSize).translated( + (rect.width() - imageSize.width()) / 2., + (rect.height() - imageSize.height()) / 2.); + p->drawImage(resultRect, _image); ItemBase::paint(p, option, w); }