Kirigami2

MenuDialog.qml
1 /*
2  SPDX-FileCopyrightText: 2021 Devin Lin <[email protected]>
3  SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 import QtQuick 2.15
7 import QtQuick.Layouts 1.2
8 import QtQuick.Controls 2.15 as Controls
9 import org.kde.kirigami 2.19 as Kirigami
10 
11 /**
12  * A dialog that prompts users with a context menu, with
13  * list items that perform actions.
14  *
15  * Example usage:
16  * @code{.qml}
17  * Kirigami.MenuDialog {
18  * title: i18n("Track Options")
19  *
20  * actions: [
21  * Kirigami.Action {
22  * iconName: "media-playback-start"
23  * text: i18nc("Start playback of the selected track", "Play")
24  * tooltip: i18n("Start playback of the selected track")
25  * },
26  * Kirigami.Action {
27  * enabled: false
28  * iconName: "document-open-folder"
29  * text: i18nc("Show the file for this song in the file manager", "Show in folder")
30  * tooltip: i18n("Show the file for this song in the file manager")
31  * },
32  * Kirigami.Action {
33  * iconName: "documentinfo"
34  * text: i18nc("Show track metadata", "View details")
35  * tooltip: i18n("Show track metadata")
36  * },
37  * Kirigami.Action {
38  * iconName: "list-add"
39  * text: i18nc("Add the track to the queue, right after the current track", "Play next")
40  * tooltip: i18n("Add the track to the queue, right after the current track")
41  * },
42  * Kirigami.Action {
43  * iconName: "list-add"
44  * text: i18nc("Enqueue current track", "Add to queue")
45  * tooltip: i18n("Enqueue current track")
46  * }
47  * ]
48  * }
49  * @endcode
50  *
51  * @see Dialog
52  * @see PromptDialog
53  * @inherit org::kde::kirigami::Dialog
54  */
55 Kirigami.Dialog {
56 
57  /**
58  * @brief This property holds the actions displayed in the context menu.
59  */
60  property list<QtObject> actions
61 
62  /**
63  * @brief This property holds the content header, which appears above the actions.
64  * but below the header bar.
65  */
66  property Item contentHeader
67 
68  /**
69  * @brief This property holds the content header.
70  *
71  * This makes it possible to access its internal properties to, for example, change its padding:
72  * ``contentHeaderControl.topPadding``
73  *
74  * @property QtQuick.Controls.Control contentHeaderControl
75  */
76  property alias contentHeaderControl: columnHeader
77 
78  preferredWidth: Kirigami.Units.gridUnit * 20
79  padding: 0
80 
81  ColumnLayout {
82  id: column
83  spacing: 0
84 
85  Controls.Control {
86  id: columnHeader
87  topPadding: 0
88  bottomPadding: 0
89  leftPadding: 0
90  rightPadding: 0
91  contentItem: contentHeader
92  }
93 
94  Repeater {
95  model: actions
96 
97  delegate: Kirigami.BasicListItem {
98  Layout.fillWidth: true
99  Layout.preferredHeight: Kirigami.Units.gridUnit * 2
100 
101  iconSize: Kirigami.Units.gridUnit
102  leftPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
103  rightPadding: Kirigami.Units.largeSpacing + + Kirigami.Units.smallSpacing
104 
105  icon: modelData.icon.name
106  text: modelData.text
107  onClicked: modelData.trigger(this)
108 
109  enabled: modelData.enabled
110 
111  visible: modelData.visible
112 
113  Controls.ToolTip.visible: modelData.tooltip !== "" && hoverHandler.hovered
114  Controls.ToolTip.text: modelData.tooltip
115  HoverHandler { id: hoverHandler }
116  }
117  }
118  }
119 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Oct 3 2022 04:09:21 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.