Changeset View
Changeset View
Standalone View
Standalone View
src/controls/private/ContextDrawerActionItem.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2019 Marco Martin <mart@kde.org> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU Library General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU Library General Public License for more details | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Library General Public | ||||
15 | * License along with this program; if not, write to the | ||||
16 | * Free Software Foundation, Inc., | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | import QtQuick 2.6 | ||||
21 | import QtQuick.Controls 2.0 as QQC2 | ||||
22 | import QtQuick.Layouts 1.2 | ||||
23 | import org.kde.kirigami 2.5 | ||||
24 | | ||||
25 | BasicListItem { | ||||
26 | id: listItem | ||||
27 | | ||||
28 | readonly property bool isSeparator: modelData.hasOwnProperty("separator") && modelData.separator | ||||
29 | | ||||
30 | readonly property bool isExpandible: modelData && modelData.hasOwnProperty("expandible") && modelData.expandible | ||||
31 | | ||||
32 | checked: modelData.checked | ||||
33 | icon: modelData.icon | ||||
34 | separatorVisible: false | ||||
35 | reserveSpaceForIcon: !isSeparator | ||||
36 | reserveSpaceForLabel: !isSeparator | ||||
37 | | ||||
38 | label: model ? (model.tooltip ? model.tooltip : model.text) : (modelData.tooltip ? modelData.tooltip : modelData.text) | ||||
39 | hoverEnabled: (!isExpandible || root.collapsed) && !Settings.tabletMode | ||||
40 | sectionDelegate: isExpandible | ||||
41 | font.pointSize: isExpandible ? Theme.defaultFont.pointSize * 1.30 : Theme.defaultFont.pointSize | ||||
42 | | ||||
43 | enabled: !isExpandible && !isSeparator && (model ? model.enabled : modelData.enabled) | ||||
44 | visible: model ? model.visible : modelData.visible | ||||
45 | opacity: enabled || isExpandible ? 1.0 : 0.6 | ||||
46 | | ||||
47 | Separator { | ||||
48 | id: separatorAction | ||||
49 | | ||||
50 | visible: listItem.isSeparator | ||||
51 | Layout.fillWidth: true | ||||
52 | | ||||
53 | ActionsMenu { | ||||
54 | id: actionsMenu | ||||
55 | y: Settings.isMobile ? -height : listItem.height | ||||
56 | z: 9999 | ||||
57 | actions: modelData.children | ||||
58 | submenuComponent: Component { | ||||
59 | ActionsMenu {} | ||||
60 | } | ||||
61 | } | ||||
62 | } | ||||
63 | | ||||
64 | Icon { | ||||
65 | isMask: true | ||||
66 | Layout.alignment: Qt.AlignVCenter | ||||
67 | Layout.rightMargin: !Settings.isMobile && mainFlickable.contentHeight > mainFlickable.height ? Units.gridUnit : 0 | ||||
68 | Layout.preferredHeight: Units.iconSizes.small/2 | ||||
69 | selected: listItem.checked || listItem.pressed | ||||
70 | Layout.preferredWidth: Layout.preferredHeight | ||||
71 | source: "go-up-symbolic" | ||||
72 | visible: !isExpandible && !listItem.isSeparator && modelData.children!== undefined && modelData.children.length > 0 | ||||
73 | } | ||||
74 | | ||||
75 | onPressed: { | ||||
76 | if (modelData.children.length > 0) { | ||||
77 | actionsMenu.open(); | ||||
78 | } | ||||
79 | } | ||||
80 | onClicked: { | ||||
81 | if (modelData.children.length == 0) { | ||||
82 | root.drawerOpen = false; | ||||
83 | } | ||||
84 | | ||||
85 | if (modelData && modelData.trigger !== undefined) { | ||||
86 | modelData.trigger(); | ||||
87 | // assume the model is a list of QAction or Action | ||||
88 | } else if (menu.model.length > index) { | ||||
89 | menu.model[index].trigger(); | ||||
90 | } else { | ||||
91 | console.warning("Don't know how to trigger the action") | ||||
92 | } | ||||
93 | } | ||||
94 | } |