2 * Copyright 2016 Canonical Ltd.
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.
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.
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/>.
18import QtQuick.Layouts 1.1
19import Lomiri.Components 1.3
23 implicitHeight: units.gu(5)
24 implicitWidth: requiredWidth
26 property var menuData: undefined
28 readonly property real requiredWidth: {
30 val += units.gu(1) + flagGutter.width;
31 if (iconSource != "") {
32 val += units.gu(1) + icon.width
34 val += units.gu(1) + title.contentWidth;
36 val += units.gu(1) + chevronIcon.width;
37 } else if (menuData && menuData.shortcut != undefined) {
38 val += units.gu(3) + shortcutLabel.contentWidth;
40 return val + units.gu(1);
43 readonly property bool hasSubmenu: menuData ? menuData.hasSubmenu : false
44 readonly property bool _checked : action && action.checkable ? action.checked : false
46 enabled: menuData ? menuData.sensitive : false
51 // FIXME - SDK Action:text modifies menu text with html underline for mnemonic
52 text: menuData ? menuData.label.replace("_", "&").replace("<u>", "&").replace("</u>", "") : ""
53 checkable: menuData && (menuData.isCheck || menuData.isRadio)
54 checked: menuData && menuData.isToggled
58 if (!parent) return implicitWidth;
59 if (parent.width > implicitWidth) return parent.width;
63 Keys.onRightPressed: {
67 event.accepted = false;
70 Keys.onReturnPressed: {
73 Keys.onEnterPressed: {
80 anchors.left: root.left
81 anchors.right: root.right
82 anchors.leftMargin: units.gu(1)
83 anchors.rightMargin: units.gu(1)
84 anchors.verticalCenter: root.verticalCenter
87 Layout.minimumWidth: units.gu(1.5)
88 Layout.minimumHeight: units.gu(1.5)
104 visible: root.iconSource != "" || false
105 source: root.iconSource || ""
113 elide: Text.ElideNone
114 wrapMode: Text.NoWrap
116 color: enabled ? theme.palette.normal.overlayText : theme.palette.disabled.overlayText
117 Layout.fillWidth: true
119 text: root.text ? root.text : ""
124 elide: Text.ElideNone
125 wrapMode: Text.NoWrap
127 color: enabled ? theme.palette.normal.overlaySecondaryText :
128 theme.palette.disabled.overlaySecondaryText
130 visible: menuData && menuData.shortcut != undefined && !root.hasSubmenu && QuickUtils.keyboardAttached
131 text: menuData && menuData.shortcut ? menuData.shortcut : ""
139 color: enabled ? theme.palette.normal.overlayText :
140 theme.palette.disabled.overlayText
142 visible: root.hasSubmenu
143 name: "toolkit_chevron-ltr_2gu"