Warning, /frameworks/kirigami/src/controls/MenuDialog.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2021 Devin Lin <espidev@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 import QtQuick 2.15
0007 import QtQuick.Layouts 1.2
0008 import QtQuick.Controls 2.15 as QQC2
0009 import org.kde.kirigami 2.19 as Kirigami
0010 
0011 /**
0012  * A dialog that prompts users with a context menu, with
0013  * list items that perform actions.
0014  *
0015  * Example usage:
0016  * @code{.qml}
0017  * Kirigami.MenuDialog {
0018  *     title: i18n("Track Options")
0019  *
0020  *     actions: [
0021  *         Kirigami.Action {
0022  *             iconName: "media-playback-start"
0023  *             text: i18nc("Start playback of the selected track", "Play")
0024  *             tooltip: i18n("Start playback of the selected track")
0025  *         },
0026  *         Kirigami.Action {
0027  *             enabled: false
0028  *             iconName: "document-open-folder"
0029  *             text: i18nc("Show the file for this song in the file manager", "Show in folder")
0030  *             tooltip: i18n("Show the file for this song in the file manager")
0031  *         },
0032  *         Kirigami.Action {
0033  *             iconName: "documentinfo"
0034  *             text: i18nc("Show track metadata", "View details")
0035  *             tooltip: i18n("Show track metadata")
0036  *         },
0037  *         Kirigami.Action {
0038  *             iconName: "list-add"
0039  *             text: i18nc("Add the track to the queue, right after the current track", "Play next")
0040  *             tooltip: i18n("Add the track to the queue, right after the current track")
0041  *         },
0042  *         Kirigami.Action {
0043  *             iconName: "list-add"
0044  *             text: i18nc("Enqueue current track", "Add to queue")
0045  *             tooltip: i18n("Enqueue current track")
0046  *         }
0047  *     ]
0048  * }
0049  * @endcode
0050  * @see kirigami::Dialog
0051  * @see kirigami::PromptDialog
0052  * @see <a href="https://develop.kde.org/hig/components/navigation/dialog">Human Interface Guidelines on Dialogs</a>
0053  * @see <a href="https://develop.kde.org/hig/components/assistance/message">Human Interface Guidelines on Modal Message Dialogs</a>
0054  * @inherit kirigami::Dialog
0055  */
0056 Kirigami.Dialog {
0057 
0058     /**
0059      * @brief This property holds the actions displayed in the context menu.
0060      */
0061     property list<QtObject> actions
0062 
0063     /**
0064      * @brief This property holds the content header, which appears above the actions.
0065      * but below the header bar.
0066      */
0067     property Item contentHeader
0068 
0069     /**
0070      * @brief This property holds the content header.
0071      *
0072      * This makes it possible to access its internal properties to, for example, change its padding:
0073      * ``contentHeaderControl.topPadding``
0074      *
0075      * @property QtQuick.Controls.Control contentHeaderControl
0076      */
0077     property alias contentHeaderControl: columnHeader
0078 
0079     preferredWidth: Kirigami.Units.gridUnit * 20
0080     padding: 0
0081 
0082     ColumnLayout {
0083         id: column
0084         spacing: 0
0085 
0086         QQC2.Control {
0087             id: columnHeader
0088             topPadding: 0
0089             bottomPadding: 0
0090             leftPadding: 0
0091             rightPadding: 0
0092             contentItem: contentHeader
0093         }
0094 
0095         Repeater {
0096             model: actions
0097 
0098             delegate: Kirigami.BasicListItem {
0099                 Layout.fillWidth: true
0100                 Layout.preferredHeight: Kirigami.Units.gridUnit * 2
0101 
0102                 iconSize: Kirigami.Units.gridUnit
0103                 leftPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
0104                 rightPadding: Kirigami.Units.largeSpacing + + Kirigami.Units.smallSpacing
0105 
0106                 icon: modelData.icon.name
0107                 text: modelData.text
0108                 onClicked: modelData.trigger(this)
0109 
0110                 enabled: modelData.enabled
0111 
0112                 visible: modelData.visible
0113 
0114                 QQC2.ToolTip.visible: modelData.tooltip !== "" && hoverHandler.hovered
0115                 QQC2.ToolTip.text: modelData.tooltip
0116                 HoverHandler { id: hoverHandler }
0117             }
0118         }
0119     }
0120 }