Warning, /frameworks/kirigami/autotests/tst_sceneposition.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
0003 *
0004 * SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006
0007 import QtQuick
0008 import QtQuick.Controls as QQC2
0009 import org.kde.kirigami as Kirigami
0010 import QtTest
0011
0012 TestCase {
0013 id: root
0014
0015 name: "ScenePositionTest"
0016 visible: true
0017 when: windowShown
0018
0019 width: 300
0020 height: 300
0021
0022 Item {
0023 id: anchorsFillItem
0024 anchors.fill: parent
0025
0026 Item {
0027 id: itemA
0028 x: 50
0029 y: 100
0030 }
0031
0032 Item {
0033 id: itemB
0034 x: 150
0035 y: 200
0036
0037 Item {
0038 id: itemB1
0039 x: 25
0040 y: 50
0041 }
0042 }
0043
0044 Item {
0045 id: itemF
0046 x: 3.5
0047 y: 6.25
0048
0049 Item {
0050 id: itemF1
0051 x: -0.25
0052 y: 1.125
0053 }
0054 }
0055
0056 Item {
0057 id: itemPlaceholder
0058 x: 56
0059 y: 78
0060
0061 property Item __reparentedItem: Item {
0062 id: reparentedItem
0063 parent: null
0064 x: 12
0065 y: 34
0066 }
0067 }
0068
0069 Rectangle {
0070 id: itemTransform
0071
0072 x: 100
0073 y: 200
0074 width: 10
0075 height: 10
0076 color: "red"
0077
0078 scale: 2.0
0079 rotation: 30
0080 transform: [
0081 Rotation {
0082 angle: 30
0083 },
0084 Scale {
0085 xScale: 2.0
0086 yScale: 3.0
0087 },
0088 Translate {
0089 x: 12
0090 y: 34
0091 },
0092 Matrix4x4 {
0093 property real a: Math.PI / 4
0094 matrix: Qt.matrix4x4(Math.cos(a), -Math.sin(a), 0, 0,
0095 Math.sin(a), Math.cos(a), 0, 0,
0096 0, 0, 1, 0,
0097 0, 0, 0, 1)
0098 }
0099 ]
0100 }
0101 }
0102
0103 function test_root() {
0104 compare(root.Kirigami.ScenePosition.x, 0);
0105 compare(root.Kirigami.ScenePosition.y, 0);
0106
0107 compare(anchorsFillItem.Kirigami.ScenePosition.x, 0);
0108 compare(anchorsFillItem.Kirigami.ScenePosition.y, 0);
0109 }
0110
0111 function test_not_nested() {
0112 compare(itemA.Kirigami.ScenePosition.x, itemA.x);
0113 compare(itemA.Kirigami.ScenePosition.y, itemA.y);
0114
0115 compare(itemB.Kirigami.ScenePosition.x, itemB.x);
0116 compare(itemB.Kirigami.ScenePosition.y, itemB.y);
0117 }
0118
0119 function test_nested() {
0120 compare(itemB1.Kirigami.ScenePosition.x, itemB.x + itemB1.x);
0121 compare(itemB1.Kirigami.ScenePosition.y, itemB.y + itemB1.y);
0122 }
0123
0124 function test_floating() {
0125 compare(itemF1.Kirigami.ScenePosition.x, 3.25);
0126 compare(itemF1.Kirigami.ScenePosition.y, 7.375);
0127 }
0128
0129 function test_reparented() {
0130 reparentedItem.parent = null;
0131 compare(reparentedItem.Kirigami.ScenePosition.x, reparentedItem.x);
0132 compare(reparentedItem.Kirigami.ScenePosition.y, reparentedItem.y);
0133
0134 itemPlaceholder.x = 56;
0135 itemPlaceholder.y = 78;
0136 reparentedItem.parent = itemPlaceholder;
0137 compare(reparentedItem.Kirigami.ScenePosition.x, itemPlaceholder.x + reparentedItem.x);
0138 compare(reparentedItem.Kirigami.ScenePosition.y, itemPlaceholder.y + reparentedItem.y);
0139
0140 itemPlaceholder.x += 10;
0141 itemPlaceholder.y += 20;
0142 compare(reparentedItem.Kirigami.ScenePosition.x, itemPlaceholder.x + reparentedItem.x);
0143 compare(reparentedItem.Kirigami.ScenePosition.y, itemPlaceholder.y + reparentedItem.y);
0144 }
0145
0146 function test_transform() {
0147 // transformations are not supported by ScenePosition
0148 compare(itemTransform.Kirigami.ScenePosition.x, itemTransform.x);
0149 compare(itemTransform.Kirigami.ScenePosition.y, itemTransform.y);
0150 }
0151
0152 Item {
0153 id: oldParent
0154 Item {
0155 id: reparentedChildItem
0156 }
0157 }
0158 Item {
0159 id: newParent
0160 }
0161
0162 SignalSpy {
0163 id: reparentingXSpy
0164 target: reparentedChildItem.Kirigami.ScenePosition
0165 signalName: "xChanged"
0166 }
0167 SignalSpy {
0168 id: reparentingYSpy
0169 target: reparentedChildItem.Kirigami.ScenePosition
0170 signalName: "yChanged"
0171 }
0172
0173 function test_disconnectOldAncestors() {
0174 verify(reparentingXSpy.valid);
0175 verify(reparentingYSpy.valid);
0176 reparentingXSpy.clear();
0177 reparentingYSpy.clear();
0178
0179 // change position of the item itself
0180 reparentedChildItem.x = 12;
0181 compare(reparentingXSpy.count, 1);
0182 compare(reparentingYSpy.count, 0);
0183 reparentedChildItem.y = 34;
0184 compare(reparentingXSpy.count, 1);
0185 compare(reparentingYSpy.count, 1);
0186
0187 // change position of the current parent
0188 oldParent.x = 56;
0189 compare(reparentedChildItem.Kirigami.ScenePosition.x, 12 + 56);
0190 compare(reparentingXSpy.count, 2);
0191 compare(reparentingYSpy.count, 1);
0192 oldParent.y = 78;
0193 compare(reparentedChildItem.Kirigami.ScenePosition.y, 34 + 78);
0194 compare(reparentingXSpy.count, 2);
0195 compare(reparentingYSpy.count, 2);
0196
0197 // reparent
0198 reparentedChildItem.parent = newParent;
0199 compare(reparentingXSpy.count, 3);
0200 compare(reparentingYSpy.count, 3);
0201 compare(reparentedChildItem.Kirigami.ScenePosition.x, 12);
0202 compare(reparentedChildItem.Kirigami.ScenePosition.y, 34);
0203
0204 // change position of the new parent
0205 newParent.x = 11;
0206 compare(reparentedChildItem.Kirigami.ScenePosition.x, 12 + 11);
0207 compare(reparentingXSpy.count, 4);
0208 compare(reparentingYSpy.count, 3);
0209 newParent.y = 22;
0210 compare(reparentedChildItem.Kirigami.ScenePosition.y, 34 + 22);
0211 compare(reparentingXSpy.count, 4);
0212 compare(reparentingYSpy.count, 4);
0213
0214 // change position of the item itself (again, but with new parent)
0215 reparentedChildItem.x = 33;
0216 compare(reparentedChildItem.Kirigami.ScenePosition.x, 33 + 11);
0217 compare(reparentingXSpy.count, 5);
0218 compare(reparentingYSpy.count, 4);
0219 reparentedChildItem.y = 44;
0220 compare(reparentedChildItem.Kirigami.ScenePosition.y, 44 + 22);
0221 compare(reparentingXSpy.count, 5);
0222 compare(reparentingYSpy.count, 5);
0223
0224 // change position of the old parent, should not trigger signals of the item anymore
0225 oldParent.x = 55;
0226 compare(reparentedChildItem.Kirigami.ScenePosition.x, 33 + 11);
0227 compare(reparentingXSpy.count, 5);
0228 compare(reparentingYSpy.count, 5);
0229 oldParent.y = 66;
0230 compare(reparentedChildItem.Kirigami.ScenePosition.y, 44 + 22);
0231 compare(reparentingXSpy.count, 5);
0232 compare(reparentingYSpy.count, 5);
0233 }
0234 }