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 } }
123 objectName: "rightLabel"
126 left: iconsItem.right
127 verticalCenter: parent.verticalCenter
129 width: contentWidth > 0 ? contentWidth + units.gu(1) : 0
130 horizontalAlignment: Text.AlignHCenter
133 font.family: "Ubuntu"
135 font.weight: Font.Light
137 Behavior on color { ColorAnimation { duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing } }
143 objectName: "indicatorName"
145 anchors.top: mainItems.bottom
146 anchors.topMargin: units.gu(0.5)
147 anchors.horizontalCenter: parent.horizontalCenter
148 width: contentWidth > 0 ? contentWidth + units.gu(1) : 0
150 text: title !== "" ? title : identifier
152 font.weight: Font.Light
153 horizontalAlignment: Text.AlignHCenter
156 Behavior on color { ColorAnimation { duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing } }
163 when: !expanded && ((icons && icons.length > 0) || leftLabel !== "" || rightLabel !== "")
164 PropertyChanges { target: indicatorName; opacity: 0}
168 name: "minimised_fallback"
169 when: !expanded && (!icons || icons.length === 0) && leftLabel == "" && rightLabel == ""
170 PropertyChanges { target: indicatorName; opacity: 0}
171 PropertyChanges { target: d; useFallbackIcon: true }
176 PropertyChanges { target: indicatorName; visible: true; opacity: 1}
177 PropertyChanges { target: mainItems; anchors.verticalCenterOffset: -units.gu(1) }
181 name: "expanded_icon"
183 when: expanded && (icons && icons.length > 0)
184 AnchorChanges { target: iconsItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
185 AnchorChanges { target: leftLabelItem; anchors.left: undefined; anchors.right: iconsItem.left }
186 PropertyChanges { target: leftLabelItem; opacity: 0 }
187 PropertyChanges { target: leftLabelItem; opacity: 0 }
188 PropertyChanges { target: rightLabelItem; opacity: 0 }
189 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(iconsItem.width, indicatorName.width)) }
193 name: "expanded_fallback"
195 when: expanded && (!icons || icons.length === 0) && leftLabel == "" && rightLabel == ""
196 PropertyChanges { target: d; useFallbackIcon: true }
197 AnchorChanges { target: iconsItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
198 AnchorChanges { target: leftLabelItem; anchors.left: undefined; anchors.right: iconsItem.left }
199 PropertyChanges { target: leftLabelItem; opacity: 0 }
200 PropertyChanges { target: leftLabelItem; opacity: 0 }
201 PropertyChanges { target: rightLabelItem; opacity: 0 }
202 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(iconsItem.width, indicatorName.width)) }
206 name: "expanded_rightLabel"
208 when: expanded && (!icons || icons.length === 0) && rightLabel !== ""
209 AnchorChanges { target: rightLabelItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
210 PropertyChanges { target: iconsItem; opacity: 0 }
211 PropertyChanges { target: leftLabelItem; opacity: 0 }
212 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(rightLabelItem.width, indicatorName.width)) }
216 name: "expanded_leftLabel"
218 when: expanded && (!icons || icons.length === 0) && leftLabel !== ""
219 AnchorChanges { target: leftLabelItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
220 PropertyChanges { target: iconsItem; opacity: 0 }
221 PropertyChanges { target: rightLabelItem; opacity: 0 }
222 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(leftLabelItem.width, indicatorName.width)) }
228 PropertyAction { target: d; property: "useFallbackIcon" }
230 targets: [ mainItems, iconsItem, leftLabelItem, rightLabelItem ]
231 duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing
234 targets: [ root, mainItems, iconsItem, leftLabelItem, rightLabelItem, indicatorName ]
235 properties: "width, opacity, anchors.verticalCenterOffset";
236 duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing
242 rootActionState.onUpdated: {
243 if (rootActionState == undefined) {
251 title = rootActionState.title ? rootActionState.title : rootActionState.accessibleName;
252 leftLabel = rootActionState.leftLabel ? rootActionState.leftLabel : "";
253 rightLabel = rootActionState.rightLabel ? rootActionState.rightLabel : "";
254 icons = rootActionState.icons;
260 property bool useFallbackIcon: false
261 property var shouldIndicatorBeShown: undefined
263 onShouldIndicatorBeShownChanged: {
264 if (shouldIndicatorBeShown !== undefined) {
265 submenuAction.changeState(shouldIndicatorBeShown);
274 name: rootActionState.secondaryAction
281 name: rootActionState.scrollAction
288 name: rootActionState.submenuAction
293 property: "shouldIndicatorBeShown"
294 when: submenuAction.valid
295 value: root.selected && root.expanded