Warning, /frameworks/qqc2-desktop-style/tests/ContextMenuStacking.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.Layouts
0009 import QtQuick.Controls as QQC2
0010 import QtQuick.Templates as T
0011 import org.kde.kirigami as Kirigami
0012 
0013 QQC2.ApplicationWindow {
0014     id: root
0015 
0016     width: 400
0017     height: 400
0018     visible: true
0019 
0020     Kirigami.SelectableLabel {
0021         anchors {
0022             top: parent.top
0023             left: parent.left
0024             right: parent.right
0025             margins: Kirigami.Units.largeSpacing
0026             topMargin: Kirigami.Units.gridUnit * 3
0027         }
0028         text: `<ol>
0029             <li>TextField is parented to an item in Popup A.</li>
0030             <li>Context menu opens for the TextField, inheriting z index of Popup A.</li>
0031             <li>Then TextField is moved to a Popup B which is stacked much higher (e.g. in Notification layer).</li>
0032             <li>Context menu is requested again for the same TextField.</li>
0033             <li>Menu should inherit new z index and be stacked on top of Popup B.</li>
0034             </ol>`
0035     }
0036 
0037     QQC2.TextField {
0038         id: textField
0039         anchors.top: parent.top
0040         anchors.right: parent.right
0041         anchors.margins: Kirigami.Units.largeSpacing
0042         placeholderText: "Right click me"
0043     }
0044 
0045     component ControlPanel: Column {
0046         anchors.left: parent.left
0047         anchors.bottom: parent.bottom
0048         anchors.margins: Kirigami.Units.largeSpacing
0049         spacing: Kirigami.Units.smallSpacing
0050 
0051         QQC2.Button {
0052             text: "Move TextField to Popup A"
0053             onClicked: {
0054                 textField.parent = placeholderA;
0055             }
0056         }
0057         QQC2.Button {
0058             text: "Open Popup A"
0059             onClicked: {
0060                 popupA.open();
0061             }
0062         }
0063         QQC2.Button {
0064             text: "Move TextField to Popup B"
0065             onClicked: {
0066                 textField.parent = placeholderB;
0067             }
0068         }
0069         QQC2.Button {
0070             text: "Open Popup B"
0071             onClicked: {
0072                 popupB.open();
0073             }
0074         }
0075     }
0076 
0077     ControlPanel {}
0078 
0079     QQC2.Popup {
0080         id: popupA
0081 
0082         Kirigami.OverlayZStacking.layer: Kirigami.OverlayZStacking.Dialog
0083         z: Kirigami.OverlayZStacking.z
0084 
0085         parent: root.QQC2.Overlay.overlay
0086         x: 0
0087         y: 0
0088         width: 300
0089         height: 300
0090         margins: Kirigami.Units.gridUnit
0091         closePolicy: QQC2.Popup.NoAutoClose | QQC2.Popup.CloseOnPressOutside
0092         modal: false
0093 
0094         contentItem: Item {
0095             id: placeholderA
0096 
0097             ControlPanel {}
0098         }
0099     }
0100 
0101     QQC2.Popup {
0102         id: popupB
0103 
0104         Kirigami.OverlayZStacking.layer: Kirigami.OverlayZStacking.Notification
0105         z: Kirigami.OverlayZStacking.z
0106 
0107         parent: root.QQC2.Overlay.overlay
0108         anchors.centerIn: parent
0109         width: 300
0110         height: 300
0111         margins: Kirigami.Units.gridUnit
0112         closePolicy: QQC2.Popup.NoAutoClose | QQC2.Popup.CloseOnPressOutside
0113         modal: false
0114 
0115         contentItem: Item {
0116             id: placeholderB
0117 
0118             ControlPanel {}
0119         }
0120     }
0121 }