Warning, /graphics/peruse/src/app/qml/PeruseContextDrawer.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * Copyright 2016 Dan Leinir Turthra Jensen <admin@leinir.dk> 0003 * 0004 * This program is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU Library General Public License as 0006 * published by the Free Software Foundation; either version 2, or 0007 * (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU Library General Public License for more details 0013 * 0014 * You should have received a copy of the GNU Library General Public 0015 * License along with this program; if not, write to the 0016 * Free Software Foundation, Inc., 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0018 */ 0019 0020 import QtQuick 2.12 0021 import QtQuick.Layouts 1.2 0022 import QtQuick.Controls 2.12 as QtControls 0023 0024 import org.kde.kirigami 2.7 0025 0026 // Modified version of the ContextDrawer component found in the Plasma Components 0027 // In addition to the original drawer, this will allow you to optionally insert an item 0028 // at the top of the menu, which can be any item, but originally designed for the thumbnail 0029 // navigation system for comic book pages found in Peruse. 0030 OverlayDrawer { 0031 id: root 0032 0033 /** 0034 * title: string 0035 * A title for the action list that will be shown to the user when opens the drawer 0036 */ 0037 property string title: typeof i18n !== "undefined" ? i18n("Actions") : "Actions" 0038 0039 // This can be any list of objects which can be a child of a column 0040 property Item topContent: pageStack.layers.depth > 1 0041 ? (pageStack.layers.currentItem.contextualTopItems ? pageStack.layers.currentItem.contextualTopItems : null) 0042 : (pageStack.currentItem && pageStack.currentItem.contextualTopItems ? pageStack.currentItem.contextualTopItems : null); 0043 0044 /** 0045 * actions: list<Action> 0046 * This can be any type of object that a ListView can accept as model. 0047 * It expects items compatible with either QAction or Kirigami Action 0048 */ 0049 property var actions: pageStack.layers.depth > 1 0050 ? pageStack.layers.currentItem.contextualActions 0051 : (pageStack.currentItem ? pageStack.currentItem.contextualActions : null) 0052 enabled: actions !== undefined && actions !== null && actions.length > 0; 0053 edge: Qt.RightEdge 0054 drawerOpen: false 0055 0056 //list items go to edges, have their own padding 0057 leftPadding: 0 0058 rightPadding: 0 0059 bottomPadding: 0 0060 0061 handleVisible: applicationWindow == undefined || applicationWindow().wideScreen == true ? false : applicationWindow().controlsVisible 0062 0063 contentItem: QtControls.StackView { 0064 id: sidebarStack; 0065 implicitWidth: Units.gridUnit * 20 0066 initialItem: sidebarPage; 0067 } 0068 Component { 0069 id: sidebarPage; 0070 Item { 0071 id: localRoot; 0072 implicitWidth: Units.gridUnit * 20 0073 property Item topContent: root.topContent; 0074 property var actions: root.actions; 0075 property int level: 0 0076 Item { 0077 id: topContainer; 0078 anchors { 0079 top: parent.top; 0080 left: parent.left; 0081 right: parent.right; 0082 bottom: menu.top; 0083 } 0084 children: localRoot.topContent; 0085 } 0086 Column { 0087 id: menu 0088 anchors { 0089 left: parent.left; 0090 right: parent.right; 0091 bottom: parent.bottom; 0092 } 0093 height: childrenRect.height; 0094 Item { 0095 height: localRoot.level === 0 ? heading.height : 0; 0096 visible: height > 0; 0097 width: menu.width 0098 Heading { 0099 id: heading 0100 anchors { 0101 left: parent.left 0102 right: parent.right 0103 margins: Units.largeSpacing 0104 } 0105 elide: Text.ElideRight 0106 level: 2 0107 text: root.title 0108 } 0109 } 0110 Repeater { 0111 model: localRoot.actions; 0112 delegate: Item { 0113 width: menu.width; 0114 height: listItemHeader.visible ? listItemHeader.height : (listItem.visible ? listItem.height : (modelData.trigger === undefined ? Units.largeSpacing : 0)); 0115 Item { 0116 id: listItemHeader; 0117 anchors { top: parent.top; left: parent.left; } 0118 visible: modelData.trigger === undefined && heading.text !== ""; 0119 width: menu.width 0120 height: heading.height; 0121 Heading { 0122 id: heading 0123 anchors { 0124 left: parent.left 0125 right: parent.right 0126 margins: Units.largeSpacing 0127 } 0128 elide: Text.ElideRight 0129 level: 2 0130 text: model && model.text ? model.text : (modelData.text ? modelData.text : "") 0131 } 0132 } 0133 BasicListItem { 0134 id: listItem; 0135 checked: modelData.checked 0136 icon: modelData.iconName 0137 supportsMouseEvents: true 0138 separatorVisible: false 0139 label: model ? (model.tooltip ? model.tooltip : model.text) : (modelData.tooltip ? modelData.tooltip : modelData.text) 0140 enabled: model && model.enabled !== undefined ? model.enabled : (modelData.enabled !== undefined ? modelData.enabled : true) 0141 visible: model && model.visible !== undefined ? model.visible : (modelData.visible !== undefined ? modelData.visible : true) 0142 opacity: enabled ? 1.0 : 0.6 0143 onClicked: { 0144 if (modelData.children!==undefined && modelData.children.length > 0) { 0145 sidebarStack.push(sidebarPage, { actions: modelData.children, "level": level + 1, topContent: null }); 0146 } else if (modelData && modelData.trigger !== undefined) { 0147 modelData.trigger(); 0148 // assume the model is a list of QAction or Action 0149 } else if (menu.model.length > index) { 0150 menu.model[index].trigger(); 0151 } else { 0152 console.warning("Don't know how to trigger the action") 0153 } 0154 } 0155 Icon { 0156 Layout.alignment: Qt.AlignVCenter 0157 Layout.rightMargin: Settings.isMobile ? 0 : Units.gridUnit 0158 height: Units.iconSizes.smallMedium 0159 selected: listItem.checked || listItem.pressed 0160 width: height 0161 source: "go-next" 0162 visible: modelData.children!==undefined && modelData.children.length > 0 0163 } 0164 } 0165 } 0166 } 0167 BasicListItem { 0168 visible: level > 0 0169 supportsMouseEvents: true 0170 icon: "go-previous" 0171 label: typeof i18n !== "undefined" ? i18n("Back") : "Back" 0172 onClicked: sidebarStack.pop() 0173 } 0174 } 0175 } 0176 } 0177 }