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 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 2.1 0008 import QtQuick.Controls 2.2 as QQC2 0009 import org.kde.kirigami 2.4 as Kirigami 0010 import "private" as P 0011 0012 /** 0013 * A specialized type of drawer that will show a list of actions 0014 * relevant to the application's current page. 0015 * 0016 * Example usage: 0017 * @code{.qml} 0018 * import org.kde.kirigami 2.4 as Kirigami 0019 * 0020 * Kirigami.ApplicationWindow { 0021 * [...] 0022 * contextDrawer: Kirigami.ContextDrawer { 0023 * id: contextDrawer 0024 * } 0025 * [...] 0026 * } 0027 * @endcode 0028 * 0029 * @code{.qml} 0030 * import org.kde.kirigami 2.4 as Kirigami 0031 * 0032 * Kirigami.Page { 0033 * [...] 0034 * actions.contextualActions: [ 0035 * Kirigami.Action { 0036 * icon.name: "edit" 0037 * text: "Action text" 0038 * onTriggered: { 0039 * // do stuff 0040 * } 0041 * }, 0042 * Kirigami.Action { 0043 * icon.name: "edit" 0044 * text: "Action text" 0045 * onTriggered: { 0046 * // do stuff 0047 * } 0048 * } 0049 * ] 0050 * [...] 0051 * } 0052 * @endcode 0053 * @see <a href="https://develop.kde.org/hig/components/navigation/contextdrawer">Human Interface Guidelines on Context Drawers</a> 0054 * @see <a href="https://develop.kde.org/hig/patterns-command/drawer/#context-drawer">KDE Human Interface Guidelines' Short Introduction of Context Drawers</a> 0055 * @inherit OverlayDrawer 0056 */ 0057 Kirigami.OverlayDrawer { 0058 id: root 0059 handleClosedIcon.source: null 0060 handleOpenIcon.source: null 0061 0062 /** 0063 * @brief A title for the action list that will be shown to the user when opens the drawer 0064 * 0065 * default: ``qsTr("Actions")`` 0066 */ 0067 property string title: qsTr("Actions") 0068 0069 /** 0070 * This can be any type of object that a ListView can accept as model. 0071 * It expects items compatible with either QtQuick.Controls.Action or 0072 * Kirigami.Action. 0073 * 0074 * @see QtQuick.Controls.Action 0075 * @see kirigami::Action 0076 * @property list<Action> actions 0077 */ 0078 property var actions: page ? page.contextualActions : [] 0079 0080 /** 0081 * @brief Arbitrary content to show above the list view. 0082 * 0083 * default: `an Item containing a Kirigami.Heading that displays a title whose text is 0084 * controlled by the title property.` 0085 * 0086 * @property Component header 0087 * @since org.kde.kirigami 2.7 0088 */ 0089 property alias header: menu.header 0090 0091 /** 0092 * @brief Arbitrary content to show below the list view. 0093 * @property Component footer 0094 * @since org.kde.kirigami 2.7 0095 */ 0096 property alias footer: menu.footer 0097 0098 property Page page: { 0099 if (applicationWindow().pageStack.layers && applicationWindow().pageStack.layers.depth > 1 && applicationWindow().pageStack.layers.currentItem.hasOwnProperty("contextualActions")) { 0100 return applicationWindow().pageStack.layers.currentItem; 0101 } 0102 else if ((applicationWindow().pageStack.currentItem || {}).hasOwnProperty("contextualActions")) { 0103 return applicationWindow().pageStack.currentItem; 0104 } 0105 else { 0106 return applicationWindow().pageStack.lastVisibleItem; 0107 } 0108 } 0109 0110 // Disable for empty menus or when we have a global toolbar 0111 enabled: menu.count > 0 && 0112 (typeof applicationWindow() === "undefined" || !applicationWindow().pageStack.globalToolBar || 0113 (applicationWindow().pageStack.lastVisibleItem && applicationWindow().pageStack.lastVisibleItem.globalToolBarStyle !== Kirigami.ApplicationHeaderStyle.ToolBar) || 0114 (applicationWindow().pageStack.layers && applicationWindow().pageStack.layers.depth > 1 && applicationWindow().pageStack.layers.currentItem && applicationWindow().pageStack.layers.currentItem.globalToolBarStyle !== Kirigami.ApplicationHeaderStyle.ToolBar)) 0115 edge: Qt.application.layoutDirection === Qt.RightToLeft ? Qt.LeftEdge : Qt.RightEdge 0116 drawerOpen: false 0117 0118 // list items go to edges, have their own padding 0119 topPadding: 0 0120 leftPadding: 0 0121 rightPadding: 0 0122 bottomPadding: 0 0123 0124 handleVisible: applicationWindow === undefined ? false : applicationWindow().controlsVisible 0125 0126 onPeekingChanged: { 0127 if (page) { 0128 page.contextualActionsAboutToShow(); 0129 } 0130 } 0131 contentItem: QQC2.ScrollView { 0132 // this just to create the attached property 0133 Kirigami.Theme.inherit: true 0134 implicitWidth: Kirigami.Units.gridUnit * 20 0135 ListView { 0136 id: menu 0137 interactive: contentHeight > height 0138 model: { 0139 if (typeof root.actions === "undefined") { 0140 return null; 0141 } 0142 if (root.actions.length === 0) { 0143 return null; 0144 } else { 0145 0146 // Check if at least one action is visible 0147 let somethingVisible = false; 0148 for (let i = 0; i < root.actions.length; i++) { 0149 if (root.actions[i].visible) { 0150 somethingVisible = true; 0151 break; 0152 } 0153 } 0154 0155 if (!somethingVisible) { 0156 return null; 0157 } 0158 0159 return root.actions[0].text !== undefined && 0160 root.actions[0].trigger !== undefined ? 0161 root.actions : 0162 root.actions[0]; 0163 } 0164 } 0165 topMargin: root.handle.y > 0 ? menu.height - menu.contentHeight : 0 0166 header: Item { 0167 height: heading.height 0168 width: menu.width 0169 Kirigami.Heading { 0170 id: heading 0171 anchors { 0172 left: parent.left 0173 right: parent.right 0174 margins: Kirigami.Units.largeSpacing 0175 } 0176 elide: Text.ElideRight 0177 level: 2 0178 text: root.title 0179 } 0180 } 0181 delegate: Column { 0182 width: parent.width 0183 P.ContextDrawerActionItem { 0184 width: parent.width 0185 } 0186 Repeater { 0187 model: modelData.hasOwnProperty("expandible") && modelData.expandible ? modelData.children : null 0188 delegate: P.ContextDrawerActionItem { 0189 width: parent.width 0190 leftPadding: Kirigami.Units.largeSpacing * 2 0191 opacity: !root.collapsed 0192 } 0193 } 0194 } 0195 } 0196 } 0197 }