2 * Copyright 2013-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/>.
18 import Ubuntu.Components 1.3
19 import Ubuntu.Settings.Components 0.1
25 property string identifier
26 property string title: indicatorName.text
27 property alias leftLabel: leftLabelItem.text
28 property alias rightLabel: rightLabelItem.text
29 property var icons: undefined
30 property bool expanded: false
31 property bool selected: false
32 property real iconHeight: units.gu(2)
33 readonly property color color: {
34 if (!expanded) return theme.palette.normal.backgroundText;
35 if (!selected) return theme.palette.disabled.backgroundText;
36 return theme.palette.normal.backgroundText;
39 implicitWidth: mainItems.width
42 readonly property int stepUp: 1
43 readonly property int stepDown: -1
46 acceptedButtons: Qt.MiddleButton
48 if ((!expanded || selected) && secondaryAction.valid) {
49 secondaryAction.activate();
53 if ((!expanded || selected) && scrollAction.valid) {
54 scrollAction.activate(wheel.angleDelta.y > 0 ? stepUp : stepDown);
61 anchors.centerIn: parent
63 width: leftLabelItem.width + iconsItem.width + rightLabelItem.width
64 implicitHeight: units.gu(2)
68 objectName: "leftLabel"
72 verticalCenter: parent.verticalCenter
74 width: contentWidth > 0 ? contentWidth + units.gu(1) : 0
75 horizontalAlignment: Text.AlignHCenter
80 font.weight: Font.Light
82 Behavior on color { ColorAnimation { duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing } }
89 width: iconRow.width > 0 ? iconRow.width + units.gu(1) : 0
91 left: leftLabelItem.right
92 verticalCenter: parent.verticalCenter
97 anchors.centerIn: iconsItem
102 objectName: "iconRepeater"
104 model: d.useFallbackIcon ? [ "image://theme/settings" ] : root.icons
108 objectName: "icon"+index
110 // FIXME Workaround for bug https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1421293
111 width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth;
114 Behavior on color { ColorAnimation { duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing } }
122 objectName: "rightLabel"
125 left: iconsItem.right
126 verticalCenter: parent.verticalCenter
128 width: contentWidth > 0 ? contentWidth + units.gu(1) : 0
129 horizontalAlignment: Text.AlignHCenter
132 font.family: "Ubuntu"
134 font.weight: Font.Light
136 Behavior on color { ColorAnimation { duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing } }
142 objectName: "indicatorName"
144 anchors.top: mainItems.bottom
145 anchors.topMargin: units.gu(0.5)
146 anchors.horizontalCenter: parent.horizontalCenter
147 width: contentWidth > 0 ? contentWidth + units.gu(1) : 0
149 text: title !== "" ? title : identifier
151 font.weight: Font.Light
152 horizontalAlignment: Text.AlignHCenter
155 Behavior on color { ColorAnimation { duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing } }
159 objectName: "indicatorItemState"
164 when: !expanded && ((icons && icons.length > 0) || leftLabel !== "" || rightLabel !== "")
165 PropertyChanges { target: indicatorName; opacity: 0}
169 name: "minimised_fallback"
170 when: !expanded && (!icons || icons.length === 0) && leftLabel == "" && rightLabel == ""
171 PropertyChanges { target: indicatorName; opacity: 0}
172 PropertyChanges { target: d; useFallbackIcon: true }
177 PropertyChanges { target: indicatorName; visible: true; opacity: 1}
178 PropertyChanges { target: mainItems; anchors.verticalCenterOffset: -units.gu(1) }
182 name: "expanded_icon"
184 when: expanded && (icons && icons.length > 0)
185 AnchorChanges { target: iconsItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
186 AnchorChanges { target: leftLabelItem; anchors.left: undefined; anchors.right: iconsItem.left }
187 PropertyChanges { target: leftLabelItem; opacity: 0 }
188 PropertyChanges { target: leftLabelItem; opacity: 0 }
189 PropertyChanges { target: rightLabelItem; opacity: 0 }
190 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(iconsItem.width, indicatorName.width)) }
194 name: "expanded_fallback"
196 when: expanded && (!icons || icons.length === 0) && leftLabel == "" && rightLabel == ""
197 PropertyChanges { target: d; useFallbackIcon: true }
198 AnchorChanges { target: iconsItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
199 AnchorChanges { target: leftLabelItem; anchors.left: undefined; anchors.right: iconsItem.left }
200 PropertyChanges { target: leftLabelItem; opacity: 0 }
201 PropertyChanges { target: leftLabelItem; opacity: 0 }
202 PropertyChanges { target: rightLabelItem; opacity: 0 }
203 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(iconsItem.width, indicatorName.width)) }
207 name: "expanded_rightLabel"
209 when: expanded && (!icons || icons.length === 0) && rightLabel !== ""
210 AnchorChanges { target: rightLabelItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
211 PropertyChanges { target: iconsItem; opacity: 0 }
212 PropertyChanges { target: leftLabelItem; opacity: 0 }
213 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(rightLabelItem.width, indicatorName.width)) }
217 name: "expanded_leftLabel"
219 when: expanded && (!icons || icons.length === 0) && leftLabel !== ""
220 AnchorChanges { target: leftLabelItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
221 PropertyChanges { target: iconsItem; opacity: 0 }
222 PropertyChanges { target: rightLabelItem; opacity: 0 }
223 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(leftLabelItem.width, indicatorName.width)) }
229 PropertyAction { target: d; property: "useFallbackIcon" }
231 targets: [ mainItems, iconsItem, leftLabelItem, rightLabelItem ]
232 duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing
235 targets: [ root, mainItems, iconsItem, leftLabelItem, rightLabelItem, indicatorName ]
236 properties: "width, opacity, anchors.verticalCenterOffset";
237 duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing
243 rootActionState.onUpdated: {
244 if (rootActionState == undefined) {
252 title = rootActionState.title ? rootActionState.title : rootActionState.accessibleName;
253 leftLabel = rootActionState.leftLabel ? rootActionState.leftLabel : "";
254 rightLabel = rootActionState.rightLabel ? rootActionState.rightLabel : "";
255 icons = rootActionState.icons;
261 property bool useFallbackIcon: false
262 property var shouldIndicatorBeShown: undefined
264 onShouldIndicatorBeShownChanged: {
265 if (shouldIndicatorBeShown !== undefined) {
266 submenuAction.changeState(shouldIndicatorBeShown);
275 name: rootActionState.secondaryAction
282 name: rootActionState.scrollAction
289 name: rootActionState.submenuAction
294 property: "shouldIndicatorBeShown"
295 when: submenuAction.valid
296 value: root.selected && root.expanded