Fix ImageItem ratio.

This commit is contained in:
Black Hat
2018-11-22 21:04:04 +08:00
parent d708c9aab6
commit 38afdeeb8e
2 changed files with 12 additions and 3 deletions

View File

@@ -54,13 +54,22 @@ void ImageItem::paint(QPainter *painter) {
painter->setFont(font);
painter->drawText(bounding_rect, Qt::AlignCenter, m_hint.at(0).toUpper());
} else {
QImage scaled;
if (image.width() > image.height()) {
scaled = image.copy((image.width() - image.height()) / 2, 0,
image.height(), image.height());
} else {
scaled = image.copy(0, (image.height() - image.width()) / 2,
image.width(), image.width());
}
if (m_round) {
QPainterPath clip;
clip.addEllipse(bounding_rect); // this is the shape we want to clip to
painter->setClipPath(clip);
}
painter->drawImage(bounding_rect, image);
painter->drawImage(bounding_rect, scaled);
}
}