File: ContextMenuApp.qml

package info (click to toggle)
kirigami-addons 1.11.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,324 kB
  • sloc: ansic: 31,525; cpp: 3,607; xml: 82; java: 76; makefile: 4; sh: 1
file content (182 lines) | stat: -rw-r--r-- 5,248 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// SPDX-FileCopyrightText: 2025 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL

import QtQuick
import QtQuick.Controls as Controls
import QtQuick.Layouts
import QtQuick.Layouts

import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.formcard as FormCard
import org.kde.kirigamiaddons.delegates as Delegates
import org.kde.kirigamiaddons.components as Components

Kirigami.ApplicationWindow {
    id: root

    title: "Kirigami Addons Delegates Test"

    width: Kirigami.Settings.isMobile ? 400 : 800
    height: Kirigami.Settings.isMobile ? 550 : 500

    pageStack {
        defaultColumnWidth: Kirigami.Units.gridUnit * 35
        initialPage: FormCard.FormCardPage {

            FormCard.FormCard {
                Layout.topMargin: Kirigami.Units.gridUnit

                FormCard.FormButtonDelegate {
                    text: "Open Context meu"
                    onClicked: menu.popup()
                }
            }

            FormCard.FormHeader {
                title: i18nc("@title:group", "Display Mode")
            }

            FormCard.FormCard {
                FormCard.FormRadioDelegate {
                    text: i18nc("@option:radio", "Bottom Drawer")
                    checked: true
                    onToggled: if (checked) {
                        menu.displayMode = Components.ConvergentContextMenu.BottomDrawer
                    }
                }

                FormCard.FormRadioDelegate {
                    text: i18nc("@option:radio", "Dialog")
                    onToggled: if (checked) {
                        menu.displayMode = Components.ConvergentContextMenu.Dialog
                    }
                }

                FormCard.FormRadioDelegate {
                    text: i18nc("@option:radio", "Context menu")
                    onToggled: if (checked) {
                        menu.displayMode = Components.ConvergentContextMenu.ContextMenu
                    }
                }
            }

            FormCard.FormHeader {
                title: i18nc("@title:group", "Display Mode")
            }

            FormCard.FormCard {
                FormCard.FormSwitchDelegate {
                    text: i18nc("@option:check", "With custom title")
                    checked: true
                    onToggled: if (checked) {
                        menu.headerContentItem = customHeader;
                        customHeader.visible = true;
                    } else {
                        menu.headerContentItem = null;
                        customHeader.visible = false;
                    }
                }
            }

        }
    }

    // Dummy implementation of ki18n
    function i18nd(context, text) {
        return text;
    }

    function i18ndp(context, text1, text2, number) {
        return number === 1 ? text1 : text2;
    }

    function i18ndc(context, text) {
        return text
    }

    function i18nc(context, text) {
        return text;
    }

    Components.ConvergentContextMenu {
        id: menu

        parent: root.Controls.Overlay.overlay

        displayMode: Components.ConvergentContextMenu.BottomDrawer

        headerContentItem: RowLayout {
            id: customHeader

            spacing: Kirigami.Units.largeSpacing

            Components.Avatar {
                name: "Room Name"
            }

            ColumnLayout {
                spacing: 0

                Kirigami.Heading {
                    level: 2
                    text: "Room Name"
                }

                Controls.Label {
                    text: "Room description"
                }
            }
        }

        Controls.Action {
            text: i18nc("@action:inmenu", "Simple Action")
        }

        Kirigami.Action {
            text: i18nc("@action:inmenu", "Nested Action")

            Controls.Action {
                text: i18nc("@action:inmenu", "Simple Action 1")
            }

            Controls.Action {
                text: i18nc("@action:inmenu", "Simple Action 2")
            }

            Controls.Action {
                text: i18nc("@action:inmenu", "Simple Action 3")
            }
        }

        Kirigami.Action {
            text: i18nc("@action:inmenu", "Nested Action with Multiple Choices")

            Kirigami.Action {
                text: i18nc("@action:inmenu", "Follow Global Settings")
                checkable: true
                autoExclusive: true // Since KF 6.10
            }

            Kirigami.Action {
                text: i18nc("@action:inmenu", "Enabled")
                checkable: true
                autoExclusive: true // Since KF 6.10
            }

            Kirigami.Action {
                text: i18nc("@action:inmenu", "Disabled")
                checkable: true
                autoExclusive: true // Since KF 6.10
            }
        }

        // custom FormCard delegate only supported on mobile
        Kirigami.Action {
            visible: Kirigami.Settings.isMobile
            displayComponent: FormCard.FormButtonDelegate { 
                text: "Custom"
                description: "Custom description"
            }
        }
    }
}