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/>.
19import Lomiri.Components 1.3
20import Lomiri.Settings.Components 0.1
26 property string identifier
27 property alias 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
42 // Prevent ListView from removing us from the view while expanding.
43 // If we're the PanelBar's initial item, our removal will make it lose
44 // track of us and cause its positioning to go wrong.
45 ListView.delayRemove: stateTransition.running
48 readonly property int stepUp: 1
49 readonly property int stepDown: -1
52 acceptedButtons: Qt.MiddleButton
54 if ((!expanded || selected) && secondaryAction.valid) {
55 secondaryAction.activate();
59 if ((!expanded || selected) && scrollAction.valid) {
60 scrollAction.activate(wheel.angleDelta.y > 0 ? stepUp : stepDown);
67 anchors.centerIn: parent
69 width: leftLabelItem.width + iconsItem.width + rightLabelItem.width
70 implicitHeight: units.gu(2)
74 objectName: "leftLabel"
78 verticalCenter: parent.verticalCenter
80 width: contentWidth > 0 ? contentWidth + units.gu(1) : 0
81 horizontalAlignment: Text.AlignHCenter
84 font.family: "Noto Sans"
86 font.weight: Font.Light
88 Behavior on color { ColorAnimation { duration: LomiriAnimation.FastDuration; easing: LomiriAnimation.StandardEasing } }
95 width: iconRow.width > 0 ? iconRow.width + units.gu(1) : 0
97 left: leftLabelItem.right
98 verticalCenter: parent.verticalCenter
103 anchors.centerIn: iconsItem
108 objectName: "iconRepeater"
110 model: d.useFallbackIcon ? [ "image://theme/settings" ] : root.icons
114 objectName: "icon"+index
116 // FIXME Workaround for bug https://bugs.launchpad.net/lomiri/+source/lomiri-ui-toolkit/+bug/1421293
117 width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth;
120 Behavior on color { ColorAnimation { duration: LomiriAnimation.FastDuration; easing: LomiriAnimation.StandardEasing } }
122 // Workaround indicators getting stretched/squished when (un)plugging external/virtual monitor
134 objectName: "rightLabel"
137 left: iconsItem.right
138 verticalCenter: parent.verticalCenter
140 width: contentWidth > 0 ? contentWidth + units.gu(1) : 0
141 horizontalAlignment: Text.AlignHCenter
144 font.family: "Noto Sans"
146 font.weight: Font.Light
148 Behavior on color { ColorAnimation { duration: LomiriAnimation.FastDuration; easing: LomiriAnimation.StandardEasing } }
154 objectName: "indicatorName"
156 anchors.top: mainItems.bottom
157 anchors.topMargin: units.gu(0.5)
158 anchors.horizontalCenter: parent.horizontalCenter
159 width: contentWidth > 0 ? contentWidth + units.gu(1) : 0
163 font.weight: Font.Light
164 horizontalAlignment: Text.AlignHCenter
167 Behavior on color { ColorAnimation { duration: LomiriAnimation.FastDuration; easing: LomiriAnimation.StandardEasing } }
171 objectName: "indicatorItemState"
176 when: !expanded && ((icons && icons.length > 0) || leftLabel !== "" || rightLabel !== "")
177 PropertyChanges { target: indicatorName; opacity: 0}
181 name: "minimised_fallback"
182 when: !expanded && (!icons || icons.length === 0) && leftLabel == "" && rightLabel == ""
183 PropertyChanges { target: indicatorName; opacity: 0}
184 PropertyChanges { target: d; useFallbackIcon: true }
189 PropertyChanges { target: indicatorName; visible: true; opacity: 1}
190 PropertyChanges { target: mainItems; anchors.verticalCenterOffset: -units.gu(1) }
194 name: "expanded_icon"
196 when: expanded && (icons && icons.length > 0)
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_fallback"
208 when: expanded && (!icons || icons.length === 0) && leftLabel == "" && rightLabel == ""
209 PropertyChanges { target: d; useFallbackIcon: true }
210 AnchorChanges { target: iconsItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
211 AnchorChanges { target: leftLabelItem; anchors.left: undefined; anchors.right: iconsItem.left }
212 PropertyChanges { target: leftLabelItem; opacity: 0 }
213 PropertyChanges { target: leftLabelItem; opacity: 0 }
214 PropertyChanges { target: rightLabelItem; opacity: 0 }
215 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(iconsItem.width, indicatorName.width)) }
219 name: "expanded_rightLabel"
221 when: expanded && (!icons || icons.length === 0) && rightLabel !== ""
222 AnchorChanges { target: rightLabelItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
223 PropertyChanges { target: iconsItem; opacity: 0 }
224 PropertyChanges { target: leftLabelItem; opacity: 0 }
225 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(rightLabelItem.width, indicatorName.width)) }
229 name: "expanded_leftLabel"
231 when: expanded && (!icons || icons.length === 0) && leftLabel !== ""
232 AnchorChanges { target: leftLabelItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
233 PropertyChanges { target: iconsItem; opacity: 0 }
234 PropertyChanges { target: rightLabelItem; opacity: 0 }
235 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(leftLabelItem.width, indicatorName.width)) }
242 PropertyAction { target: d; property: "useFallbackIcon" }
244 targets: [ mainItems, iconsItem, leftLabelItem, rightLabelItem ]
245 duration: LomiriAnimation.SnapDuration; easing: LomiriAnimation.StandardEasing
248 targets: [ root, mainItems, iconsItem, leftLabelItem, rightLabelItem, indicatorName ]
249 properties: "width, opacity, anchors.verticalCenterOffset";
250 duration: LomiriAnimation.SnapDuration; easing: LomiriAnimation.StandardEasing
256 rootActionState.onUpdated: {
257 if (rootActionState == undefined) {
265 title = rootActionState.title ? rootActionState.title : rootActionState.accessibleName;
266 leftLabel = rootActionState.leftLabel ? rootActionState.leftLabel : "";
267 rightLabel = rootActionState.rightLabel ? rootActionState.rightLabel : "";
268 icons = rootActionState.icons;
274 property bool useFallbackIcon: false
275 property var shouldIndicatorBeShown: undefined
277 onShouldIndicatorBeShownChanged: {
278 if (shouldIndicatorBeShown !== undefined) {
279 submenuAction.changeState(shouldIndicatorBeShown);
288 name: rootActionState.secondaryAction
295 name: rootActionState.scrollAction
302 name: rootActionState.submenuAction
307 property: "shouldIndicatorBeShown"
308 restoreMode: Binding.RestoreBinding
309 when: submenuAction.valid
310 value: root.selected && root.expanded