aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2022-06-29 17:33:01 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-06-30 22:14:13 +0000
commite105b81805691c18f8baff363bebe6785b0d49b3 (patch)
treeb2a366bd933018fea96f20d01a7d1b267c4f512e /tests
parent0b5ca08a28f25de96c49655512a4956fb0e37604 (diff)
Ensure that when an item resizes, its layer resizes immediately
geometryChange() notifies QQuickItemLayer::updateGeometry() to update its internal bounds; at that moment, QQuickImagePrivate::paintedHeight has not yet been updated, so the QQuickImage::boundingRect() override returns the old size. It gets updated in updatePaintedGeometry(); but until then, it's better to use QQuickItem::boundingRect() without polymorphism, because that simply returns the item width and height. An alternative would be to use clipRect(), as it was before 9b62f4c27ac3fb3dc563c7f4657094c14d752bac; but that is more complex now: in case ItemObservesViewport is set, we would need to worry about whether it's more appropriate to have the item's layer the same size as the viewport (and update it more often during scrolling), or the same size as the item, as it was before. Amends 9b62f4c27ac3fb3dc563c7f4657094c14d752bac Fixes: QTBUG-104442 Fixes: QTBUG-104536 Change-Id: I51e25402d358a57cea9fd718ee8fe759b572b1a2 Reviewed-by: Igor Bugaev <freedbrt@gmail.com> Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io> (cherry picked from commit b0fc5287b8378e0be13765e2f8dc90aa938a25fb) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquickitemlayer/data/itemImageLayer.qml14
-rw-r--r--tests/auto/quick/qquickitemlayer/data/qt-logo.pngbin0 -> 1301 bytes
-rw-r--r--tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp23
3 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickitemlayer/data/itemImageLayer.qml b/tests/auto/quick/qquickitemlayer/data/itemImageLayer.qml
new file mode 100644
index 0000000000..1f05aa882f
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/data/itemImageLayer.qml
@@ -0,0 +1,14 @@
+import QtQuick
+
+Item {
+ width: 300
+ height: 300
+
+ Image {
+ objectName: "image"
+ anchors.fill: parent
+ fillMode: Image.PreserveAspectFit
+ source: "qt-logo.png"
+ layer.enabled: true
+ }
+}
diff --git a/tests/auto/quick/qquickitemlayer/data/qt-logo.png b/tests/auto/quick/qquickitemlayer/data/qt-logo.png
new file mode 100644
index 0000000000..dff7729515
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/data/qt-logo.png
Binary files differ
diff --git a/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp b/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp
index ae6947f01b..90e1ab0a66 100644
--- a/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp
+++ b/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp
@@ -31,10 +31,12 @@
#include <QtQuick/qquickitem.h>
#include <QtQuick/qquickview.h>
#include <QtQuick/qsgrendererinterface.h>
+#include <QtQuick/private/qquickitem_p.h>
#include <qopenglcontext.h>
#include <qopenglfunctions.h>
#include <QtQuickTestUtils/private/qmlutils_p.h>
+#include <QtQuickTestUtils/private/viewtestutils_p.h>
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/qpa/qplatformintegration.h>
@@ -85,6 +87,8 @@ private slots:
void textureMirroring_data();
void textureMirroring();
+ void effectSourceResizeToItem();
+
private:
void mirroringCheck(int mirroring, int x, bool shouldMirror, const QImage &fb);
};
@@ -468,6 +472,25 @@ void tst_QQuickItemLayer::textureMirroring()
mirroringCheck(mirroring, 200, true, fb);
}
+void tst_QQuickItemLayer::effectSourceResizeToItem() // QTBUG-104442
+{
+ QQuickView window;
+ QVERIFY(QQuickTest::showView(window, testFileUrl("itemImageLayer.qml")));
+ window.setResizeMode(QQuickView::SizeRootObjectToView);
+ QQuickItem *image = window.rootObject()->findChild<QQuickItem*>("image");
+ QVERIFY(image);
+ QCOMPARE(image->size(), window.rootObject()->size());
+ QQuickItemLayer *layer = QQuickItemPrivate::get(image)->layer();
+ QVERIFY(layer);
+ auto *effectSource = layer->effectSource();
+ QVERIFY(effectSource);
+ QCOMPARE(effectSource->size(), image->size());
+
+ window.resize(200, 200); // shrink it a bit
+ QTRY_COMPARE(image->size().toSize(), QSize(200, 200)); // wait for the window system
+ QCOMPARE(effectSource->size(), image->size());
+}
+
void tst_QQuickItemLayer::mirroringCheck(int mirroring, int x, bool shouldMirror, const QImage &fb)
{
int offset = 10;