aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2024-04-23 13:52:21 +0200
committerEirik Aavitsland <eirik.aavitsland@qt.io>2024-05-14 20:06:17 +0200
commit31d652d73b20f43b492ba8c306f932ca6fc3a0c1 (patch)
tree3d80e82650cb273b0608c8216865aa8966563826 /tests
parent8181d2874e2f3825a22fef667b2f5f5b3784dee9 (diff)
Add fillTransform property to ShapePath
This adds functionality corresponding to QBrush transform to QuickShapes. Change-Id: I2b5903f8c228adec65a6f5be64e3816143879302 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquickshape/data/filltransform.qml58
-rw-r--r--tests/auto/quick/qquickshape/tst_qquickshape.cpp37
-rw-r--r--tests/baseline/scenegraph/data/shape/shape_gradient_xf.qml81
-rw-r--r--tests/baseline/scenegraph/data/shape/shape_spread_xf.qml47
-rw-r--r--tests/manual/painterpathquickshape/ControlPanel.qml14
-rw-r--r--tests/manual/painterpathquickshape/ControlledShape.qml1
6 files changed, 238 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickshape/data/filltransform.qml b/tests/auto/quick/qquickshape/data/filltransform.qml
new file mode 100644
index 0000000000..4f83c04c43
--- /dev/null
+++ b/tests/auto/quick/qquickshape/data/filltransform.qml
@@ -0,0 +1,58 @@
+import QtQuick
+import QtQuick.Shapes
+import tst_qquickpathitem
+
+Rectangle {
+ width: 440
+ height: 220
+ color: "white"
+
+ Shape {
+ objectName: "shape1"
+ ShapePath {
+ id: path1
+ objectName: "path1"
+ fillGradient: RadialGradient {
+ centerX: path1.startX + 100
+ centerY: path1.startY + 100
+ centerRadius: 100
+ focalX: centerX
+ focalY: centerY
+ GradientStop { position: 0.0; color: "blue" }
+ GradientStop { position: 0.5; color: "cyan" }
+ GradientStop { position: 1.0; color: "blue" }
+ }
+
+ fillTransform: PlanarTransform.fromScale(2, 1);
+
+ startX: 10
+ startY: 10
+ PathLine { relativeX: 200; relativeY: 0 }
+ PathLine { relativeX: 0; relativeY: 200 }
+ PathLine { relativeX: -200; relativeY: 0 }
+ PathLine { relativeX: 0; relativeY: -200 }
+ }
+
+ ShapePath {
+ id: path2
+ objectName: "path2"
+ fillGradient: RadialGradient {
+ centerX: path2.startX + 100
+ centerY: path2.startY + 100
+ centerRadius: 100
+ focalX: centerX
+ focalY: centerY
+ GradientStop { position: 0.0; color: "blue" }
+ GradientStop { position: 0.5; color: "cyan" }
+ GradientStop { position: 1.0; color: "blue" }
+ }
+
+ startX: 220 + 10
+ startY: 10
+ PathLine { relativeX: 200; relativeY: 0 }
+ PathLine { relativeX: 0; relativeY: 200 }
+ PathLine { relativeX: -200; relativeY: 0 }
+ PathLine { relativeX: 0; relativeY: -200 }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickshape/tst_qquickshape.cpp b/tests/auto/quick/qquickshape/tst_qquickshape.cpp
index f846cc4e4f..707e0037f5 100644
--- a/tests/auto/quick/qquickshape/tst_qquickshape.cpp
+++ b/tests/auto/quick/qquickshape/tst_qquickshape.cpp
@@ -62,6 +62,7 @@ private slots:
void multilineDataTypes_data();
void multilineDataTypes();
void multilineStronglyTyped();
+ void fillTransform();
private:
QVector<QPolygonF> m_lowPolyLogo;
@@ -247,6 +248,8 @@ void tst_QQuickShape::changeSignals()
QCOMPARE(vpChangeSpy.size(), 15);
qobject_cast<QQuickGradientStop *>(stopList.at(1))->setColor(Qt::black);
QCOMPARE(vpChangeSpy.size(), 16);
+ vp->setFillTransform(QMatrix4x4(QTransform::fromScale(3, 0.14)));
+ QCOMPARE(vpChangeSpy.size(), 17);
}
void tst_QQuickShape::render()
@@ -674,6 +677,40 @@ void tst_QQuickShape::multilineStronglyTyped()
}
}
+void tst_QQuickShape::fillTransform()
+{
+ QScopedPointer<QQuickView> window(createView());
+
+ window->setSource(testFileUrl("filltransform.qml"));
+ qApp->processEvents();
+
+ QQuickShape *obj = findItem<QQuickShape>(window->rootObject(), "shape1");
+ QVERIFY(obj != nullptr);
+ QQmlListReference list(obj, "data");
+ QCOMPARE(list.count(), 2);
+
+ QQuickShapePath *p1 = qobject_cast<QQuickShapePath *>(list.at(0));
+ QVERIFY(p1 != nullptr);
+ QVERIFY(p1->objectName() == "path1");
+ QVERIFY(p1->fillTransform() == QMatrix4x4(2,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1));
+
+ QQuickShapePath *p2 = qobject_cast<QQuickShapePath *>(list.at(1));
+ QVERIFY(p2 != nullptr);
+ QVERIFY(p2->objectName() == "path2");
+ QVERIFY(p2->fillTransform().isIdentity());
+
+ QMatrix4x4 xf(QTransform::fromTranslate(-36, 0).shear(0.35, 0));
+ p1->setFillTransform(xf);
+ QVERIFY(p1->fillTransform() == xf);
+
+ QVERIFY(p2->fillTransform().isIdentity());
+ p2->setFillTransform(xf);
+ QVERIFY(p2->fillTransform() == xf);
+
+ p1->setFillTransform(QMatrix4x4{});
+ QVERIFY(p1->fillTransform().isIdentity());
+}
+
QTEST_MAIN(tst_QQuickShape)
#include "tst_qquickshape.moc"
diff --git a/tests/baseline/scenegraph/data/shape/shape_gradient_xf.qml b/tests/baseline/scenegraph/data/shape/shape_gradient_xf.qml
new file mode 100644
index 0000000000..a0a33d9f2c
--- /dev/null
+++ b/tests/baseline/scenegraph/data/shape/shape_gradient_xf.qml
@@ -0,0 +1,81 @@
+import QtQuick
+import QtQuick.Shapes
+
+Item {
+ width: 320
+ height: 480
+
+ ListModel {
+ id: renderers
+ ListElement { renderer: Shape.GeometryRenderer }
+ ListElement { renderer: Shape.CurveRenderer }
+ }
+
+ Row {
+ Repeater {
+ model: renderers
+ Column {
+ Shape {
+ preferredRendererType: renderer
+ width: 160
+ height: 150
+
+ ShapePath {
+ strokeColor: "transparent"
+ fillGradient: LinearGradient {
+ y1: 50; y2: 80
+ GradientStop { position: 0; color: "black" }
+ GradientStop { position: 1; color: "cyan" }
+ }
+ fillTransform: PlanarTransform.fromAffineMatrix(0.8, 0.2, 0.3, 1.5, 20, -50 + startY)
+
+ startX: 10; startY: 10
+ PathLine { relativeX: 140; relativeY: 0 }
+ PathLine { relativeX: 0; relativeY: 100 }
+ PathLine { relativeX: -140; relativeY: 0 }
+ PathLine { relativeX: 0; relativeY: -100 }
+ }
+
+ ShapePath {
+ strokeColor: "transparent"
+ fillGradient: RadialGradient {
+ centerX: 80
+ centerY: 75
+ centerRadius: centerY
+ focalX: centerX
+ focalY: centerY
+ GradientStop { position: 0; color: "black" }
+ GradientStop { position: .5; color: "cyan" }
+ GradientStop { position: 1; color: "black" }
+ }
+ fillTransform: PlanarTransform.fromAffineMatrix(0.8, 0.2, 0.3, 1.5, 20, -50 + startY)
+
+ startX: 10; startY: 10 + 1 * 140
+ PathLine { relativeX: 140; relativeY: 0 }
+ PathLine { relativeX: 0; relativeY: 100 }
+ PathLine { relativeX: -140; relativeY: 0 }
+ PathLine { relativeX: 0; relativeY: -100 }
+ }
+
+ ShapePath {
+ strokeColor: "transparent"
+ fillGradient: ConicalGradient {
+ centerX: 80
+ centerY: 75
+ GradientStop { position: 0; color: "black" }
+ GradientStop { position: .5; color: "cyan" }
+ GradientStop { position: 1; color: "black" }
+ }
+ fillTransform: PlanarTransform.fromAffineMatrix(0.8, 0.2, 0.3, 1.5, 20, -50 + startY)
+
+ startX: 10; startY: 10 + 2 * 140
+ PathLine { relativeX: 140; relativeY: 0 }
+ PathLine { relativeX: 0; relativeY: 100 }
+ PathLine { relativeX: -140; relativeY: 0 }
+ PathLine { relativeX: 0; relativeY: -100 }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/tests/baseline/scenegraph/data/shape/shape_spread_xf.qml b/tests/baseline/scenegraph/data/shape/shape_spread_xf.qml
new file mode 100644
index 0000000000..c9f67e472d
--- /dev/null
+++ b/tests/baseline/scenegraph/data/shape/shape_spread_xf.qml
@@ -0,0 +1,47 @@
+import QtQuick
+import QtQuick.Shapes
+
+Item {
+ width: 320
+ height: 480
+
+ ListModel {
+ id: renderers
+ ListElement { renderer: Shape.GeometryRenderer }
+ ListElement { renderer: Shape.CurveRenderer }
+ }
+
+ Row {
+ Repeater {
+ model: renderers
+ Column {
+ Repeater {
+ model: 3
+ Shape {
+ preferredRendererType: renderer
+ width: 160
+ height: 150
+ ShapePath {
+ strokeColor: "transparent"
+
+ fillGradient: LinearGradient {
+ id: grad
+ y1: 50; y2: 80
+ spread: model.index === 0 ? ShapeGradient.PadSpread : (model.index === 1 ? ShapeGradient.RepeatSpread : ShapeGradient.ReflectSpread)
+ GradientStop { position: 0; color: "black" }
+ GradientStop { position: 1; color: "red" }
+ }
+ fillTransform: PlanarTransform.fromShear(0, 0.2)
+
+ startX: 10; startY: 10
+ PathLine { relativeX: 140; relativeY: 0 }
+ PathLine { relativeX: 0; relativeY: 100 }
+ PathLine { relativeX: -140; relativeY: 0 }
+ PathLine { relativeX: 0; relativeY: -100 }
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/tests/manual/painterpathquickshape/ControlPanel.qml b/tests/manual/painterpathquickshape/ControlPanel.qml
index 87eb9ae3e7..ea3168d124 100644
--- a/tests/manual/painterpathquickshape/ControlPanel.qml
+++ b/tests/manual/painterpathquickshape/ControlPanel.qml
@@ -28,6 +28,7 @@ Item {
property alias painterComparisonAlpha: painterComparisonColorAlpha.value
property alias outlineEnabled: enableOutline.checked
property alias gradientType: gradientType.currentIndex
+ property alias fillScaleX: fillTransformSlider.value
property alias rendererName: rendererLabel.text
property alias preferCurve: rendererLabel.preferCurve
@@ -254,6 +255,19 @@ Item {
}
}
Label {
+ text: "Fill transform (scale x: " + fillTransformSlider.value.toFixed(2) + "):"
+ color: "white"
+ visible: gradientType.currentIndex != 0
+ }
+ Slider {
+ id: fillTransformSlider
+ Layout.fillWidth: true
+ from: 0.2
+ to: 5.0
+ value: 1.0
+ visible: gradientType.currentIndex != 0
+ }
+ Label {
text: "Fill alpha(" + Math.round(alphaSlider.value*100)/100 + "):"
color: "white"
}
diff --git a/tests/manual/painterpathquickshape/ControlledShape.qml b/tests/manual/painterpathquickshape/ControlledShape.qml
index e690f59ccc..26a57163cd 100644
--- a/tests/manual/painterpathquickshape/ControlledShape.qml
+++ b/tests/manual/painterpathquickshape/ControlledShape.qml
@@ -89,6 +89,7 @@ Item {
strokeStyle: controlPanel.outlineStyle
joinStyle: controlPanel.joinStyle
capStyle: controlPanel.capStyle
+ fillTransform: Qt.matrix4x4(controlPanel.fillScaleX,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1)
}
Repeater {