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

KDE's Doxygen guidelines are available online.