File: menu.qml

package info (click to toggle)
libplasma 6.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,796 kB
  • sloc: cpp: 17,769; sh: 286; xml: 95; python: 57; javascript: 29; makefile: 7
file content (135 lines) | stat: -rw-r--r-- 4,753 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
/*
 * SPDX-FileCopyrightText: 2015 Kai Uwe Broulik <kde@privat.broulik.de>
 * SPDX-FileCopyrightText: 2019 David Edmundson <kde@davidedmundson.co.uk>
 * SPDX-FileCopyrightText: 2020 Noah Davis <noahadvs@gmail.com>
 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
 */
import QtQuick
import QtQuick.Layouts
import org.kde.plasma.extras as PlasmaExtras
import org.kde.plasma.components as PC3
import org.kde.kirigami as Kirigami

ComponentBase {
    id: root
    title: "Plasma Extras Menu"
    contentItem: ColumnLayout {
        spacing: Kirigami.Units.gridUnit

        PC3.Button {
            text: "Simple menu"
            onClicked: simpleMenu.open(0, height)

            PlasmaExtras.Menu {
                id: simpleMenu

                PlasmaExtras.MenuItem { text: "Hello" }
                PlasmaExtras.MenuItem { text: "This is just a simple" }
                PlasmaExtras.MenuItem { text: "Menu" }
                PlasmaExtras.MenuItem { text: "without separators" }
                PlasmaExtras.MenuItem { text: "and other stuff" }
            }
        }

        PC3.Button {
            text: "Checkable menu items"
            onClicked: checkableMenu.open(0, height)

            PlasmaExtras.Menu {
                id: checkableMenu

                PlasmaExtras.MenuItem { text: "Apple"; checkable: true }
                PlasmaExtras.MenuItem { text: "Banana"; checkable: true }
                PlasmaExtras.MenuItem { text: "Orange"; checkable: true }
            }
        }


        PC3.Button {
            text: "Icons"
            onClicked: iconsMenu.open(0, height)

            PlasmaExtras.Menu {
                id: iconsMenu

                PlasmaExtras.MenuItem { text: "Error"; icon: "dialog-error" }
                PlasmaExtras.MenuItem { text: "Warning"; icon: "dialog-warning" }
                PlasmaExtras.MenuItem { text: "Information"; icon: "dialog-information" }
            }
        }

        PC3.Button {
            text: "Separators and sections"
            onClicked: sectionsMenu.open(0, height)

            PlasmaExtras.Menu {
                id: sectionsMenu

                PlasmaExtras.MenuItem { text: "A menu"; section: true }
                PlasmaExtras.MenuItem { text: "One entry" }
                PlasmaExtras.MenuItem { text: "Another entry" }
                PlasmaExtras.MenuItem { separator: true }
                PlasmaExtras.MenuItem { text: "One item" }
                PlasmaExtras.MenuItem { text: "Another item" }
            }
        }

        RowLayout {
            spacing: Kirigami.Units.smallSpacing

            PC3.Button {
                id: minMaxButton
                text: "Fixed minimum and maximum width"
                onClicked: minMaxMenu.open(0, height)

                PlasmaExtras.Menu {
                    id: minMaxMenu

                    minimumWidth: minMaxButton.width
                    maximumWidth: limitMenuMaxWidth.checked ? minMaxButton.width : undefined // has a RESET property

                    PlasmaExtras.MenuItem { text: "Hello" }
                    PlasmaExtras.MenuItem { text: "This is just a simple" }
                    PlasmaExtras.MenuItem { text: "Menu" }
                    PlasmaExtras.MenuItem { text: "with some very very long text in one item that will "
                                                    + "make the menu super huge if you don't do anything about it" }
                    PlasmaExtras.MenuItem { text: "and other stuff" }
                }
            }

            PC3.CheckBox {
                id: limitMenuMaxWidth
                anchors.verticalCenter: parent.verticalCenter
                text: "Limit maximum width"
                checked: true
            }
        }

        PC3.Button {
            text: "Don't crash on null MenuItem action"
            onClicked: noActionCrashMenu.open(0, height)

            PlasmaExtras.Menu {
                id: noActionCrashMenu

                PlasmaExtras.MenuItem { text: "This is an item" }
                PlasmaExtras.MenuItem { text: "Below me should NOT be an empty item"}
                PlasmaExtras.MenuItem { action: null }
                PlasmaExtras.MenuItem { text: "I am not empty" }
            }
        }

        PC3.Button {
            text: "Disabled menu items"
            onClicked: disabledMenuItemsMenu.open(0, height)

            PlasmaExtras.Menu {
                id: disabledMenuItemsMenu

                PlasmaExtras.MenuItem { text: "I'm disabled"; enabled: false }
                PlasmaExtras.MenuItem { text: "And I'm enabled"}
                PlasmaExtras.MenuItem { text: "I'm disabled too"; enabled: false }
            }
        }
    }
}