Fix ImageItem ratio.
This commit is contained in:
parent
d708c9aab6
commit
38afdeeb8e
|
@ -107,8 +107,8 @@ ColumnLayout {
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
readOnly: true
|
readOnly: true
|
||||||
wrapMode: Label.Wrap
|
wrapMode: Label.Wrap
|
||||||
selectedTextColor: "white"
|
selectedTextColor: Material.accent
|
||||||
selectionColor: Material.accent
|
selectionColor: "white"
|
||||||
textFormat: Text.RichText
|
textFormat: Text.RichText
|
||||||
|
|
||||||
onLinkActivated: Qt.openUrlExternally(link)
|
onLinkActivated: Qt.openUrlExternally(link)
|
||||||
|
|
|
@ -54,13 +54,22 @@ void ImageItem::paint(QPainter *painter) {
|
||||||
painter->setFont(font);
|
painter->setFont(font);
|
||||||
painter->drawText(bounding_rect, Qt::AlignCenter, m_hint.at(0).toUpper());
|
painter->drawText(bounding_rect, Qt::AlignCenter, m_hint.at(0).toUpper());
|
||||||
} else {
|
} 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) {
|
if (m_round) {
|
||||||
QPainterPath clip;
|
QPainterPath clip;
|
||||||
clip.addEllipse(bounding_rect); // this is the shape we want to clip to
|
clip.addEllipse(bounding_rect); // this is the shape we want to clip to
|
||||||
painter->setClipPath(clip);
|
painter->setClipPath(clip);
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->drawImage(bounding_rect, image);
|
painter->drawImage(bounding_rect, scaled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue