Warning, /frameworks/kirigami/src/controls/ContextDrawer.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
0003 * SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
0004 *
0005 * SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007
0008 import QtQuick
0009 import QtQuick.Controls as QQC2
0010 import QtQuick.Templates as T
0011 import org.kde.kirigami as Kirigami
0012 import "private" as KP
0013
0014 /**
0015 * A specialized type of drawer that will show a list of actions
0016 * relevant to the application's current page.
0017 *
0018 * Example usage:
0019 *
0020 * @code
0021 * import org.kde.kirigami as Kirigami
0022 *
0023 * Kirigami.ApplicationWindow {
0024 * contextDrawer: Kirigami.ContextDrawer {
0025 * enabled: true
0026 * actions: [
0027 * Kirigami.Action {
0028 * icon.name: "edit"
0029 * text: "Action text"
0030 * onTriggered: {
0031 * // do stuff
0032 * }
0033 * },
0034 * Kirigami.Action {
0035 * icon.name: "edit"
0036 * text: "Action text"
0037 * onTriggered: {
0038 * // do stuff
0039 * }
0040 * }
0041 * ]
0042 * }
0043 * }
0044 * @endcode
0045 *
0046 * @inherit OverlayDrawer
0047 */
0048 Kirigami.OverlayDrawer {
0049 id: root
0050
0051 handleClosedIcon.source: null
0052 handleOpenIcon.source: null
0053
0054 /**
0055 * @brief A title for the action list that will be shown to the user when opens the drawer
0056 *
0057 * default: ``qsTr("Actions")``
0058 */
0059 property string title: qsTr("Actions")
0060
0061 /**
0062 * List of contextual actions to be displayed in a ListView.
0063 *
0064 * @see QtQuick.Action
0065 * @see org::kde::kirigami::Action
0066 * @property list<T.Action> actions
0067 */
0068 property list<T.Action> actions
0069
0070 /**
0071 * @brief Arbitrary content to show above the list view.
0072 *
0073 * default: `an Item containing a Kirigami.Heading that displays a title whose text is
0074 * controlled by the title property.`
0075 *
0076 * @property Component header
0077 * @since 2.7
0078 */
0079 property alias header: menu.header
0080
0081 /**
0082 * @brief Arbitrary content to show below the list view.
0083 * @property Component footer
0084 * @since 2.7
0085 */
0086 property alias footer: menu.footer
0087
0088 // Not stored in a property, so we don't have to waste memory on an extra list.
0089 function visibleActions() {
0090 return actions.filter(
0091 action => !(action instanceof Kirigami.Action) || action.visible
0092 );
0093 }
0094
0095 // Disable for empty menus or when we have a global toolbar
0096 enabled: {
0097 const pageStack = typeof applicationWindow !== "undefined" ? applicationWindow().pageStack : null;
0098 const itemExistsButStyleIsNotToolBar = item => item && item.globalToolBarStyle !== Kirigami.ApplicationHeaderStyle.ToolBar;
0099 return menu.count > 0
0100 && (!pageStack
0101 || !pageStack.globalToolBar
0102 || (pageStack.layers.depth > 1
0103 && itemExistsButStyleIsNotToolBar(pageStack.layers.currentItem))
0104 || itemExistsButStyleIsNotToolBar(pageStack.trailingVisibleItem));
0105 }
0106
0107 edge: Qt.application.layoutDirection === Qt.RightToLeft ? Qt.LeftEdge : Qt.RightEdge
0108 drawerOpen: false
0109
0110 // list items go to edges, have their own padding
0111 topPadding: 0
0112 leftPadding: 0
0113 rightPadding: 0
0114 bottomPadding: 0
0115
0116 property bool handleVisible: {
0117 if (typeof applicationWindow === "function") {
0118 const w = applicationWindow();
0119 if (w) {
0120 return w.controlsVisible;
0121 }
0122 }
0123 // For a ContextDrawer its handle is hidden by default
0124 return false;
0125 }
0126
0127 contentItem: QQC2.ScrollView {
0128 // this just to create the attached property
0129 Kirigami.Theme.inherit: true
0130 implicitWidth: Kirigami.Units.gridUnit * 20
0131 ListView {
0132 id: menu
0133 interactive: contentHeight > height
0134
0135 model: root.visibleActions()
0136
0137 topMargin: root.handle.y > 0 ? menu.height - menu.contentHeight : 0
0138 header: QQC2.ToolBar {
0139 height: pageStack.globalToolBar.preferredHeight
0140 width: parent.width
0141
0142 Kirigami.Heading {
0143 id: heading
0144 elide: Text.ElideRight
0145 text: root.title
0146
0147 anchors {
0148 verticalCenter: parent.verticalCenter
0149 left: parent.left
0150 right: parent.right
0151 leftMargin: Kirigami.Units.largeSpacing
0152 rightMargin: Kirigami.Units.largeSpacing
0153 }
0154 }
0155 }
0156
0157 delegate: Column {
0158 id: delegate
0159
0160 required property T.Action modelData
0161
0162 width: parent.width
0163
0164 KP.ContextDrawerActionItem {
0165 tAction: delegate.modelData
0166 width: parent.width
0167 }
0168
0169 Repeater {
0170 model: delegate.modelData instanceof Kirigami.Action && delegate.modelData.expandible
0171 ? delegate.modelData.children : null
0172
0173 delegate: KP.ContextDrawerActionItem {
0174 width: parent.width
0175 leftPadding: Kirigami.Units.gridUnit
0176 opacity: !root.collapsed
0177 }
0178 }
0179 }
0180 }
0181 }
0182 }