aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-11-27 14:14:53 +0100
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-11-30 16:38:11 +0100
commit84c44a805adbd12401c645869a73c3cb92f44544 (patch)
tree20b3cf21b4e466d72ffe90558de163890f7d1d98 /src/imports
parent3013fce9931913b4f38d4707cb1327be1727a1ef (diff)
qquickstyleitem: ensure that the size of the node is at least the size of the texture
The size of the node should not be smaller than the size of the texture. Otherwise the image will look truncated or wrapped. This is especially important now that the image can be scaled up to be dpr aligned. Task-number: QTBUG-89006 Pick-to: 6.0 6.0.0 Change-Id: I0bd82faec89d6e7c2e79541a30d6b98200ebd5a0 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/nativestyle/items/qquickstyleitem.cpp41
1 files changed, 20 insertions, 21 deletions
diff --git a/src/imports/nativestyle/items/qquickstyleitem.cpp b/src/imports/nativestyle/items/qquickstyleitem.cpp
index b50a38c5..2397525a 100644
--- a/src/imports/nativestyle/items/qquickstyleitem.cpp
+++ b/src/imports/nativestyle/items/qquickstyleitem.cpp
@@ -117,47 +117,46 @@ QSGNode *QQuickStyleItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePa
if (m_paintedImage.isNull())
return node;
- auto texture = window()->createTextureFromImage(m_paintedImage, QQuickWindow::TextureCanUseAtlas);
+ const auto texture = window()->createTextureFromImage(m_paintedImage, QQuickWindow::TextureCanUseAtlas);
QRectF bounds = boundingRect();
- const qreal scale = m_paintedImage.devicePixelRatioF();
- const QSizeF ninePatchImageSize = m_paintedImage.rect().size() / scale;
+ const qreal dpr = window()->devicePixelRatio();
+ const QSizeF unscaledImageSize = QSizeF(m_paintedImage.size()) / dpr;
+
+ // We can scale the image up with a nine patch node, but should
+ // avoid to scale it down. Otherwise the nine patch image will look
+ // wrapped (or look truncated, in case of no padding). So if the
+ // item is smaller that the image, don't scale.
+ if (bounds.width() < unscaledImageSize.width())
+ bounds.setWidth(unscaledImageSize.width());
+ if (bounds.height() < unscaledImageSize.height())
+ bounds.setHeight(unscaledImageSize.height());
+
#ifdef QT_DEBUG
if (m_debugFlags.testFlag(Unscaled)) {
- bounds = QRectF(QPointF(), ninePatchImageSize);
- qqc2Info() << "Setting paint node bounds to size of image:" << bounds;
+ bounds.setSize(unscaledImageSize);
+ qqc2Info() << "Setting qsg node size to the unscaled size of m_paintedImage:" << bounds;
}
#endif
- QMargins padding;
if (m_useNinePatchImage) {
- padding = m_styleItemGeometry.ninePatchMargins;
+ QMargins padding = m_styleItemGeometry.ninePatchMargins;
if (padding.right() == -1) {
- // Special case: a right padding of -1 means that
- // the image should not scale horizontally.
- bounds.setWidth(ninePatchImageSize.width());
- padding.setLeft(0);
- padding.setRight(0);
- } else if (boundingRect().width() < imageSize().width()) {
- // If the item size is smaller that the image, using nine-patch scaling
- // ends up wrapping it. In that case we scale the whole image instead.
+ // Special case: a padding of -1 means that
+ // the image shouldn't scale in the given direction.
padding.setLeft(0);
padding.setRight(0);
}
if (padding.bottom() == -1) {
- bounds.setHeight(ninePatchImageSize.height());
- padding.setTop(0);
- padding.setBottom(0);
- } else if (boundingRect().height() < imageSize().height()) {
padding.setTop(0);
padding.setBottom(0);
}
+ node->setPadding(padding.left(), padding.top(), padding.right(), padding.bottom());
}
node->setBounds(bounds);
node->setTexture(texture);
- node->setDevicePixelRatio(scale);
- node->setPadding(padding.left(), padding.top(), padding.right(), padding.bottom());
+ node->setDevicePixelRatio(dpr);
node->update();
return node;