Lomiri
Loading...
Searching...
No Matches
ApplicationMenuItemFactory.qml
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17import QtQuick 2.12
18import Lomiri.Settings.Menus 0.1 as Menus
19import Lomiri.Settings.Components 0.1
20import QMenuModel 1.0
21import Utils 0.1 as Utils
22import Lomiri.Components 1.3
23
24Item {
25 id: menuFactory
26
27 property string context
28 property var rootModel: null
29 property var menuModel: null
30
31 Component {
32 id: applicationMenu;
33
34 ListItem {
35 property QtObject menuData: null
36 property int menuIndex: -1
37
38 height: layout.height
39 enabled: menuData && menuData.sensitive || false
40 divider.visible: false
41
42 onClicked: {
43 menuModel.activate(menuIndex);
44 }
45
46 Action {
47 id: action
48 text: menuData ? menuData.label.replace("_", "&") : ""
49 }
50
51 ListItemLayout {
52 id: layout
53 title.text: action.text
54
55 Icon {
56 source: menuData ? menuData.icon : ""
57 SlotsLayout.position: SlotsLayout.Leading
58 height: units.gu(3)
59 }
60
61 Label {
62 text: menuData ? menuData.shortcut : ""
63 visible: menuData && menuData.shortcut && QuickUtils.keyboardAttached
64 SlotsLayout.position: SlotsLayout.Trailing
65 color: enabled ? theme.palette.normal.backgroundSecondaryText :
66 theme.palette.disabled.backgroundSecondaryText
67 }
68 }
69 }
70 }
71
72 Component {
73 id: submenu
74
75 ListItem {
76 property QtObject menuData: null
77 property int menuIndex: -1
78
79 height: layout.height
80 enabled: menuData && menuData.sensitive || false
81 divider.visible: false
82
83 onClicked: {
84 menuModel.activate(menuIndex);
85 }
86
87 Action {
88 id: action
89 text: menuData ? menuData.label.replace("_", "&") : ""
90 }
91
92 ListItemLayout {
93 id: layout
94 title.text: action.text
95
96 Icon {
97 source: menuData ? menuData.icon : ""
98 SlotsLayout.position: SlotsLayout.Leading
99 height: units.gu(3)
100 }
101
102 Icon {
103 name: "toolkit_chevron-ltr_1gu"
104 SlotsLayout.position: SlotsLayout.Trailing
105 width: units.gu(2)
106 color: enabled ? theme.palette.normal.backgroundSecondaryText :
107 theme.palette.disabled.backgroundSecondaryText
108 }
109 }
110 }
111 }
112
113 Component {
114 id: applicationMenuSeparator;
115
116 Menus.SeparatorMenu {
117 objectName: "separatorMenu"
118 }
119 }
120
121 function load(modelData) {
122 if (modelData.isSeparator) {
123 return applicationMenuSeparator;
124 }
125 if (modelData.isRadio) {
126 }
127 if (modelData.isCheck) {
128
129 }
130 if (modelData.hasSubmenu) {
131 return submenu;
132 }
133 return applicationMenu;
134 }
135}