aboutsummaryrefslogtreecommitdiffstats
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-12-01 10:32:57 +0100
commiteed31ce275a6457a9dd409a4a481ff63c461bc0d (patch)
tree42254fe4bc890e913543d3ef49c52a132d4d7ead
parent0ac3a5ffe1eaf16be342b5db1ef1f6a5accce514 (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. (cherry picked from commit 84c44a805adbd12401c645869a73c3cb92f44544) Task-number: QTBUG-89006 Change-Id: I0bd82faec89d6e7c2e79541a30d6b98200ebd5a0 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
-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 67cde080..57ce385a 100644
--- a/src/imports/nativestyle/items/qquickstyleitem.cpp
+++ b/src/imports/nativestyle/items/qquickstyleitem.cpp
@@ -135,47 +135,46 @@ QSGNode *QQuickStyleItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePa
if (!node)
node = window()->createNinePatchNode();
- auto texture = window()->createTextureFromImage(m_paintedImage, QQuickWindow::TextureCanUseAtlas);
+ const auto texture = window()->createTextureFromImage(m_paintedImage, QQuickWindow::TextureCanUseAtlas);
QRectF bounds = boundingRect();
- const qreal scale = window()->devicePixelRatio();
- 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(window()->devicePixelRatio());
- node->setPadding(padding.left(), padding.top(), padding.right(), padding.bottom());
+ node->setDevicePixelRatio(dpr);
node->update();
return node;