Warning, /frameworks/kirigami/autotests/tst_overlayzstacking.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 QtQuick.Templates as T 0010 import QtTest 0011 import org.kde.kirigami as Kirigami 0012 0013 TestCase { 0014 id: root 0015 0016 name: "OverlayZStackingTest" 0017 visible: true 0018 when: windowShown 0019 0020 width: 300 0021 height: 300 0022 0023 // Layers are not set 0024 Component { 0025 id: defaultComponent 0026 T.Popup { 0027 z: Kirigami.OverlayZStacking.z 0028 } 0029 } 0030 Component { 0031 id: defaultDrawerComponent 0032 T.Drawer { 0033 z: Kirigami.OverlayZStacking.z 0034 } 0035 } 0036 Component { 0037 id: defaultDialogComponent 0038 T.Dialog { 0039 z: Kirigami.OverlayZStacking.z 0040 } 0041 } 0042 Component { 0043 id: defaultMenuComponent 0044 T.Menu { 0045 z: Kirigami.OverlayZStacking.z 0046 } 0047 } 0048 Component { 0049 id: defaultToolTipComponent 0050 T.ToolTip { 0051 z: Kirigami.OverlayZStacking.z 0052 } 0053 } 0054 0055 function test_defaultLayers() { 0056 let popup = null; 0057 0058 popup = createTemporaryObject(defaultComponent, this); 0059 verify(popup); 0060 compare(popup.Kirigami.OverlayZStacking.layer, Kirigami.OverlayZStacking.DefaultLowest); 0061 compare(popup.z, 0); 0062 0063 popup = createTemporaryObject(defaultDrawerComponent, this); 0064 compare(popup.Kirigami.OverlayZStacking.layer, Kirigami.OverlayZStacking.Drawer); 0065 verify(popup); 0066 compare(popup.z, 100); 0067 0068 popup = createTemporaryObject(defaultDialogComponent, this); 0069 verify(popup); 0070 compare(popup.Kirigami.OverlayZStacking.layer, Kirigami.OverlayZStacking.Dialog); 0071 compare(popup.z, 300); 0072 0073 popup = createTemporaryObject(defaultMenuComponent, this); 0074 verify(popup); 0075 compare(popup.Kirigami.OverlayZStacking.layer, Kirigami.OverlayZStacking.Menu); 0076 compare(popup.z, 400); 0077 0078 popup = createTemporaryObject(defaultToolTipComponent, this); 0079 verify(popup); 0080 compare(popup.Kirigami.OverlayZStacking.layer, Kirigami.OverlayZStacking.ToolTip); 0081 compare(popup.z, 600); 0082 } 0083 0084 // Layers are set 0085 Component { 0086 id: drawerComponent 0087 T.Drawer { 0088 Kirigami.OverlayZStacking.layer: Kirigami.OverlayZStacking.Drawer 0089 z: Kirigami.OverlayZStacking.z 0090 } 0091 } 0092 Component { 0093 id: fullScreenComponent 0094 T.Popup { 0095 Kirigami.OverlayZStacking.layer: Kirigami.OverlayZStacking.FullScreen 0096 z: Kirigami.OverlayZStacking.z 0097 } 0098 } 0099 Component { 0100 id: dialogComponent 0101 T.Dialog { 0102 Kirigami.OverlayZStacking.layer: Kirigami.OverlayZStacking.Dialog 0103 z: Kirigami.OverlayZStacking.z 0104 } 0105 } 0106 Component { 0107 id: menuComponent 0108 T.Menu { 0109 Kirigami.OverlayZStacking.layer: Kirigami.OverlayZStacking.Menu 0110 z: Kirigami.OverlayZStacking.z 0111 } 0112 } 0113 Component { 0114 id: notificationComponent 0115 T.ToolTip { 0116 Kirigami.OverlayZStacking.layer: Kirigami.OverlayZStacking.Notification 0117 z: Kirigami.OverlayZStacking.z 0118 } 0119 } 0120 Component { 0121 id: toolTipComponent 0122 T.ToolTip { 0123 Kirigami.OverlayZStacking.layer: Kirigami.OverlayZStacking.ToolTip 0124 z: Kirigami.OverlayZStacking.z 0125 } 0126 } 0127 0128 function createWithLayers() { 0129 const drawer = createTemporaryObject(drawerComponent, this); 0130 verify(drawer); 0131 const fullScreen = createTemporaryObject(fullScreenComponent, this); 0132 verify(fullScreen); 0133 const dialog = createTemporaryObject(dialogComponent, this); 0134 verify(dialog); 0135 const menu = createTemporaryObject(menuComponent, this); 0136 verify(menu); 0137 const notification = createTemporaryObject(notificationComponent, this); 0138 verify(notification); 0139 const toolTip = createTemporaryObject(toolTipComponent, this); 0140 verify(toolTip); 0141 return ({ 0142 drawer, 0143 fullScreen, 0144 dialog, 0145 menu, 0146 notification, 0147 toolTip, 0148 }); 0149 } 0150 0151 function test_stackingNaturalOrder() { 0152 const all = createWithLayers(); 0153 const { drawer, fullScreen, dialog, menu, notification, toolTip } = all; 0154 0155 drawer .parent = this; 0156 fullScreen .parent = drawer .contentItem; 0157 dialog .parent = fullScreen .contentItem; 0158 menu .parent = dialog .contentItem; 0159 notification.parent = menu .contentItem; 0160 toolTip .parent = notification .contentItem; 0161 0162 drawer.open(); 0163 compare(drawer.z, 100); 0164 fullScreen.open(); 0165 compare(fullScreen.z, 200); 0166 dialog.open(); 0167 compare(dialog.z, 300); 0168 menu.open(); 0169 compare(menu.z, 400); 0170 notification.open(); 0171 compare(notification.z, 500); 0172 toolTip.open(); 0173 compare(toolTip.z, 600); 0174 } 0175 0176 function test_stackingReverseOrder() { 0177 const all = createWithLayers(); 0178 const { drawer, fullScreen, dialog, menu, notification, toolTip } = all; 0179 0180 toolTip .parent = this; 0181 notification.parent = toolTip .contentItem; 0182 menu .parent = notification.contentItem; 0183 dialog .parent = menu .contentItem; 0184 fullScreen .parent = dialog .contentItem; 0185 drawer .parent = fullScreen .contentItem; 0186 0187 toolTip.open(); 0188 compare(toolTip.z, 600); 0189 notification.open(); 0190 compare(notification.z, 601); 0191 menu.open(); 0192 compare(menu.z, 602); 0193 dialog.open(); 0194 compare(dialog.z, 603); 0195 fullScreen.open(); 0196 compare(fullScreen.z, 604); 0197 drawer.open(); 0198 compare(drawer.z, 605); 0199 } 0200 0201 Component { 0202 id: spyComponent 0203 SignalSpy {} 0204 } 0205 0206 function test_parentChangesZ() { 0207 const parent = createTemporaryObject(defaultComponent, this, { parent: this }); 0208 const child = createTemporaryObject(defaultComponent, this); 0209 const spy = createTemporaryObject(spyComponent, this, { 0210 target: child, 0211 signalName: "zChanged", 0212 }); 0213 verify(spy.valid); 0214 compare(spy.count, 0); 0215 compare(parent.z, 0); 0216 0217 child.parent = parent.contentItem; 0218 compare(spy.count, 1); 0219 compare(child.z, 1); 0220 0221 parent.z = 42; 0222 compare(spy.count, 2); 0223 compare(child.z, 43); 0224 0225 spy.clear(); 0226 parent.open(); 0227 child.open(); 0228 // deferred signal 0229 parent.z = 9000; 0230 compare(spy.count, 0); 0231 compare(child.z, 43); 0232 0233 child.close(); 0234 compare(spy.count, 1); 0235 compare(child.z, 9001); 0236 } 0237 }