Kirigami2

MenuDialog.qml
1/*
2 SPDX-FileCopyrightText: 2021 Devin Lin <espidev@gmail.com>
3 SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7pragma ComponentBehavior: Bound
8
9import QtQuick
10import QtQuick.Controls as QQC2
11import QtQuick.Layouts
12import QtQuick.Templates as T
13import org.kde.kirigami as Kirigami
14
15/**
16 * A dialog that prompts users with a context menu, with
17 * list items that perform actions.
18 *
19 * Example usage:
20 * @code{.qml}
21 * Kirigami.MenuDialog {
22 * title: i18n("Track Options")
23 *
24 * actions: [
25 * Kirigami.Action {
26 * icon.name: "media-playback-start"
27 * text: i18nc("Start playback of the selected track", "Play")
28 * tooltip: i18n("Start playback of the selected track")
29 * },
30 * Kirigami.Action {
31 * enabled: false
32 * icon.name: "document-open-folder"
33 * text: i18nc("Show the file for this song in the file manager", "Show in folder")
34 * tooltip: i18n("Show the file for this song in the file manager")
35 * },
36 * Kirigami.Action {
37 * icon.name: "documentinfo"
38 * text: i18nc("Show track metadata", "View details")
39 * tooltip: i18n("Show track metadata")
40 * },
41 * Kirigami.Action {
42 * icon.name: "list-add"
43 * text: i18nc("Add the track to the queue, right after the current track", "Play next")
44 * tooltip: i18n("Add the track to the queue, right after the current track")
45 * },
46 * Kirigami.Action {
47 * icon.name: "list-add"
48 * text: i18nc("Enqueue current track", "Add to queue")
49 * tooltip: i18n("Enqueue current track")
50 * }
51 * ]
52 * }
53 * @endcode
54 *
55 * @see Dialog
56 * @see PromptDialog
57 * @inherit org::kde::kirigami::Dialog
58 */
59Kirigami.Dialog {
60 id: root
61
62 /**
63 * @brief This property holds the actions displayed in the context menu.
64 */
65 property list<T.Action> actions
66
67 /**
68 * @brief This property holds the content header, which appears above the actions.
69 * but below the header bar.
70 */
71 property alias contentHeader: columnHeader.contentItem
72
73 /**
74 * @brief This property holds the content header.
75 *
76 * This makes it possible to access its internal properties to, for example, change its padding:
77 * ``contentHeaderControl.topPadding``
78 *
79 * @property QtQuick.Controls.Control contentHeaderControl
80 */
81 property alias contentHeaderControl: columnHeader
82
83 preferredWidth: Kirigami.Units.gridUnit * 20
84 padding: 0
85
86 ColumnLayout {
87 id: column
88
89 spacing: 0
90
91 QQC2.Control {
92 id: columnHeader
93
94 topPadding: 0
95 leftPadding: 0
96 rightPadding: 0
97 bottomPadding: 0
98 }
99
100 Repeater {
101 model: root.actions
102
103 delegate: QQC2.ItemDelegate {
104 required property T.Action modelData
105
106 Layout.fillWidth: true
107 Layout.preferredHeight: Kirigami.Units.gridUnit * 2
108
109 action: modelData
110 visible: !(modelData instanceof Kirigami.Action) || modelData.visible
111
112 icon.width: Kirigami.Units.gridUnit
113 icon.height: Kirigami.Units.gridUnit
114
115 horizontalPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
116 leftPadding: undefined
117 rightPadding: undefined
118
119 QQC2.ToolTip.text: modelData instanceof Kirigami.Action ? modelData.tooltip : ""
120 QQC2.ToolTip.visible: QQC2.ToolTip.text.length > 0 && (Kirigami.Settings.tabletMode ? pressed : hovered)
121 QQC2.ToolTip.delay: Kirigami.Settings.tabletMode ? Qt.styleHints.mousePressAndHoldInterval : Kirigami.Units.toolTipDelay
122
123 onClicked: root.close()
124 }
125 }
126 }
127
128 standardButtons: QQC2.DialogButtonBox.NoButton
129 showCloseButton: true
130}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.