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
26 property string identifier
27 property string title: indicatorName.text
28 property alias leftLabel: leftLabelItem.text
29 property alias rightLabel: rightLabelItem.text
30 property var icons: undefined
31 property bool expanded: false
32 property bool selected: false
33 property real iconHeight: units.gu(2)
34 readonly property color color: {
35 if (!expanded) return theme.palette.normal.backgroundText;
36 if (!selected) return theme.palette.disabled.backgroundText;
37 return theme.palette.normal.backgroundText;
40 implicitWidth: mainItems.width
43 readonly property int stepUp: 1
44 readonly property int stepDown: -1
47 acceptedButtons: Qt.MiddleButton
49 if ((!expanded || selected) && secondaryAction.valid) {
50 secondaryAction.activate();
54 if ((!expanded || selected) && scrollAction.valid) {
55 scrollAction.activate(wheel.angleDelta.y > 0 ? stepUp : stepDown);
62 anchors.centerIn: parent
64 width: leftLabelItem.width + iconsItem.width + rightLabelItem.width
65 implicitHeight: units.gu(2)
69 objectName: "leftLabel"
73 verticalCenter: parent.verticalCenter
75 width: contentWidth > 0 ? contentWidth + units.gu(1) : 0
76 horizontalAlignment: Text.AlignHCenter
81 font.weight: Font.Light
83 Behavior on color { ColorAnimation { duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing } }
90 width: iconRow.width > 0 ? iconRow.width + units.gu(1) : 0
92 left: leftLabelItem.right
93 verticalCenter: parent.verticalCenter
98 anchors.centerIn: iconsItem
103 objectName: "iconRepeater"
105 model: d.useFallbackIcon ? [ "image://theme/settings" ] : root.icons
109 objectName: "icon"+index
111 // FIXME Workaround for bug https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1421293
112 width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth;
115 Behavior on color { ColorAnimation { duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing } }
118 if (!expanded) return 1.0;
119 if (!selected) return 0.6;
122 Behavior on opacity { NumberAnimation { duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing } }
130 objectName: "rightLabel"
133 left: iconsItem.right
134 verticalCenter: parent.verticalCenter
136 width: contentWidth > 0 ? contentWidth + units.gu(1) : 0
137 horizontalAlignment: Text.AlignHCenter
140 font.family: "Ubuntu"
142 font.weight: Font.Light
144 Behavior on color { ColorAnimation { duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing } }
150 objectName: "indicatorName"
152 anchors.top: mainItems.bottom
153 anchors.topMargin: units.gu(0.5)
154 anchors.horizontalCenter: parent.horizontalCenter
155 width: contentWidth > 0 ? contentWidth + units.gu(1) : 0
157 text: title !== "" ? title : identifier
159 font.weight: Font.Light
160 horizontalAlignment: Text.AlignHCenter
163 Behavior on color { ColorAnimation { duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing } }
170 when: !expanded && ((icons && icons.length > 0) || leftLabel !== "" || rightLabel !== "")
171 PropertyChanges { target: indicatorName; opacity: 0}
175 name: "minimised_fallback"
176 when: !expanded && (!icons || icons.length === 0) && leftLabel == "" && rightLabel == ""
177 PropertyChanges { target: indicatorName; opacity: 0}
178 PropertyChanges { target: d; useFallbackIcon: true }
183 PropertyChanges { target: indicatorName; visible: true; opacity: 1}
184 PropertyChanges { target: mainItems; anchors.verticalCenterOffset: -units.gu(1) }
188 name: "expanded_icon"
190 when: expanded && (icons && icons.length > 0)
191 AnchorChanges { target: iconsItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
192 AnchorChanges { target: leftLabelItem; anchors.left: undefined; anchors.right: iconsItem.left }
193 PropertyChanges { target: leftLabelItem; opacity: 0 }
194 PropertyChanges { target: leftLabelItem; opacity: 0 }
195 PropertyChanges { target: rightLabelItem; opacity: 0 }
196 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(iconsItem.width, indicatorName.width)) }
200 name: "expanded_fallback"
202 when: expanded && (!icons || icons.length === 0) && leftLabel == "" && rightLabel == ""
203 PropertyChanges { target: d; useFallbackIcon: true }
204 AnchorChanges { target: iconsItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
205 AnchorChanges { target: leftLabelItem; anchors.left: undefined; anchors.right: iconsItem.left }
206 PropertyChanges { target: leftLabelItem; opacity: 0 }
207 PropertyChanges { target: leftLabelItem; opacity: 0 }
208 PropertyChanges { target: rightLabelItem; opacity: 0 }
209 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(iconsItem.width, indicatorName.width)) }
213 name: "expanded_rightLabel"
215 when: expanded && (!icons || icons.length === 0) && rightLabel !== ""
216 AnchorChanges { target: rightLabelItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
217 PropertyChanges { target: iconsItem; opacity: 0 }
218 PropertyChanges { target: leftLabelItem; opacity: 0 }
219 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(rightLabelItem.width, indicatorName.width)) }
223 name: "expanded_leftLabel"
225 when: expanded && (!icons || icons.length === 0) && leftLabel !== ""
226 AnchorChanges { target: leftLabelItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
227 PropertyChanges { target: iconsItem; opacity: 0 }
228 PropertyChanges { target: rightLabelItem; opacity: 0 }
229 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(leftLabelItem.width, indicatorName.width)) }
235 PropertyAction { target: d; property: "useFallbackIcon" }
237 targets: [ mainItems, iconsItem, leftLabelItem, rightLabelItem ]
238 duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing
241 targets: [ root, mainItems, iconsItem, leftLabelItem, rightLabelItem, indicatorName ]
242 properties: "width, opacity, anchors.verticalCenterOffset";
243 duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing
249 rootActionState.onUpdated: {
250 if (rootActionState == undefined) {
258 title = rootActionState.title ? rootActionState.title : rootActionState.accessibleName;
259 leftLabel = rootActionState.leftLabel ? rootActionState.leftLabel : "";
260 rightLabel = rootActionState.rightLabel ? rootActionState.rightLabel : "";
261 icons = rootActionState.icons;
267 property bool useFallbackIcon: false
268 property var shouldIndicatorBeShown: undefined
270 onShouldIndicatorBeShownChanged: {
271 if (shouldIndicatorBeShown !== undefined) {
272 submenuAction.changeState(shouldIndicatorBeShown);
281 name: rootActionState.secondaryAction
288 name: rootActionState.scrollAction
295 name: rootActionState.submenuAction
300 property: "shouldIndicatorBeShown"
301 when: submenuAction.valid
302 value: root.selected && root.expanded