Kirigami-addons

ContextMenuPage.qml
1// SPDX-FileCopyrightText: 2024 Joshua Goins <josh@redstrate.com>
2// SPDX-FileCopyrightText: 2024 Carl Schwan <carl@carlschwan.eu>
3// SPDX-License-Identifier: LGPL-2.0-or-later
4
5pragma ComponentBehavior: Bound
6
7import QtQuick
8import QtQuick.Controls as QQC2
9import QtQuick.Controls as T
10import QtQuick.Layouts
11import Qt.labs.qmlmodels
12
13import org.kde.kirigami as Kirigami
14import org.kde.kirigamiaddons.components as KirigamiComponents
15import org.kde.kirigamiaddons.formcard as FormCard
16
17QQC2.ScrollView {
18 id: root
19
20 required property list<T.Action> actions
21 required property T.StackView stackView
22 required property KirigamiComponents.BottomDrawer drawer
23 property string title
24
25 Layout.fillWidth: true
26
27 property Component itemDelegate: FormCard.FormButtonDelegate {
28 id: button
29
30 required property T.Action modelData
31
32 action: modelData
33 visible: modelData.visible === undefined || modelData.visible
34
35 leading: RowLayout {
36 spacing: 0
37 visible: modelData.checkable
38
39 QQC2.CheckBox {
40 id: checkBoxItem
41
42 focusPolicy: Qt.NoFocus // provided by delegate
43 visible: !(modelData instanceof Kirigami.Action) || !modelData.autoExclusive
44
45 action: modelData
46
47 topPadding: 0
48 leftPadding: 0
49 rightPadding: 0
50 bottomPadding: 0
51
52 contentItem: null // Remove right margin
53 spacing: 0
54
55 Accessible.ignored: true
56 }
57
58 QQC2.RadioButton {
59 id: radioBoxItem
60
61 focusPolicy: Qt.NoFocus // provided by delegate
62 visible: modelData instanceof Kirigami.Action && modelData.autoExclusive
63
64 action: modelData
65
66 topPadding: 0
67 leftPadding: 0
68 rightPadding: 0
69 bottomPadding: 0
70
71 contentItem: null // Remove right margin
72 spacing: 0
73
74 Accessible.ignored: true
75 }
76 }
77
78 Binding {
79 when: !(modelData instanceof Kirigami.Action) || modelData.children.length === 0
80 target: button.trailingLogo
81 property: "source"
82 value: ""
83 }
84
85 onClicked: {
86 if (modelData instanceof Kirigami.Action && modelData.children.length > 0) {
87 root.stackView.push(Qt.resolvedUrl('./ContextMenuPage.qml'), {
88 stackView: root.stackView,
89 actions: modelData.children,
90 title: modelData.text,
91 drawer: root.drawer,
92 });
93 return;
94 }
95 drawer.close();
96 }
97 }
98 property Component separatorDelegate: FormCard.FormDelegateSeparator {
99 property T.Action action
100 visible: !(action instanceof Kirigami.Action) || action.visible
101 }
102 property Component loaderDelegate: Loader {
103 property T.Action action
104 Layout.fillWidth: item?.Layout.fillWidth ?? true
105 }
106
107 Instantiator {
108 id: actionsInstantiator
109
110 model: root.actions
111 delegate: QtObject {
112 id: delegate
113
114 required property T.Action modelData
115 readonly property T.Action action: modelData
116
117 property QtObject item: null
118 property bool isSubMenu: false
119
120 Component.onCompleted: {
121 const isKirigamiAction = delegate.action instanceof Kirigami.Action;
122 if (isKirigamiAction && delegate.action.separator) {
123 item = root.separatorDelegate.createObject(null, { action: delegate.action });
124 } else if (delegate.action.displayComponent) {
125 item = root.loaderDelegate.createObject(null, {
126 actions: delegate.action,
127 sourceComponent: action.displayComponent,
128 });
129 } else {
130 item = root.itemDelegate.createObject(null, { modelData: delegate.action });
131 }
132 columnLayout.children.push(item);
133 }
134 }
135 }
136
137 ColumnLayout {
138 id: columnLayout
139
140 width: root.availableWidth
141 spacing: 0
142 }
143}
A single card that follows a form style.
Definition FormCard.qml:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:49:11 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.