Fixed aspect ratio of non-standard stickers in photo editor.

This commit is contained in:
23rd 2023-11-05 18:10:27 +03:00 committed by John Preston
parent b2eeab53c5
commit e98f56b0b7
2 changed files with 14 additions and 2 deletions

View File

@ -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);
}

View File

@ -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);
}