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 finishedExpanding: false
33 property bool selected: false
34 property real iconHeight: units.gu(2)
35 readonly property color color: {
36 if (!expanded) return theme.palette.normal.backgroundText;
37 if (!selected) return theme.palette.disabled.backgroundText;
38 return theme.palette.normal.backgroundText;
42 enabled: expanded && finishedExpanding && !stateTransition.running
43 NumberAnimation { duration: LomiriAnimation.SnapDuration }
46 implicitWidth: mainItems.width
48 // Prevent ListView from removing us from the view while expanding.
49 // If we're the PanelBar's initial item, our removal will make it lose
50 // track of us and cause its positioning to go wrong.
51 ListView.delayRemove: stateTransition.running
54 readonly property int stepUp: 1
55 readonly property int stepDown: -1
58 acceptedButtons: Qt.MiddleButton
60 if ((!expanded || selected) && secondaryAction.valid) {
61 secondaryAction.activate();
65 if ((!expanded || selected) && scrollAction.valid) {
66 scrollAction.activate(wheel.angleDelta.y > 0 ? stepUp : stepDown);
73 anchors.centerIn: parent
75 width: leftLabelItem.width + iconsItem.width + rightLabelItem.width
76 implicitHeight: units.gu(2)
80 objectName: "leftLabel"
84 verticalCenter: parent.verticalCenter
86 width: contentWidth > 0 ? contentWidth + units.gu(1) : 0
87 horizontalAlignment: Text.AlignHCenter
90 font.family: "Noto Sans"
92 font.weight: Font.Light
94 Behavior on color { ColorAnimation { duration: LomiriAnimation.FastDuration; easing: LomiriAnimation.StandardEasing } }
101 width: iconRow.width > 0 ? iconRow.width + units.gu(1) : 0
103 left: leftLabelItem.right
104 verticalCenter: parent.verticalCenter
109 anchors.centerIn: iconsItem
114 objectName: "iconRepeater"
116 model: d.useFallbackIcon ? [ "image://theme/settings" ] : root.icons
120 objectName: "icon"+index
122 // FIXME Workaround for bug https://bugs.launchpad.net/lomiri/+source/lomiri-ui-toolkit/+bug/1421293
123 width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth;
126 Behavior on color { ColorAnimation { duration: LomiriAnimation.FastDuration; easing: LomiriAnimation.StandardEasing } }
128 // Workaround indicators getting stretched/squished when (un)plugging external/virtual monitor
140 objectName: "rightLabel"
143 left: iconsItem.right
144 verticalCenter: parent.verticalCenter
146 width: contentWidth > 0 ? contentWidth + units.gu(1) : 0
147 horizontalAlignment: Text.AlignHCenter
150 font.family: "Noto Sans"
152 font.weight: Font.Light
154 Behavior on color { ColorAnimation { duration: LomiriAnimation.FastDuration; easing: LomiriAnimation.StandardEasing } }
160 objectName: "indicatorName"
162 anchors.top: mainItems.bottom
163 anchors.topMargin: units.gu(0.5)
164 anchors.horizontalCenter: parent.horizontalCenter
165 width: contentWidth > 0 ? contentWidth + units.gu(1) : 0
169 font.weight: Font.Light
170 horizontalAlignment: Text.AlignHCenter
173 Behavior on color { ColorAnimation { duration: LomiriAnimation.FastDuration; easing: LomiriAnimation.StandardEasing } }
177 objectName: "indicatorItemState"
182 when: !expanded && ((icons && icons.length > 0) || leftLabel !== "" || rightLabel !== "")
183 PropertyChanges { target: indicatorName; opacity: 0}
187 name: "minimised_fallback"
188 when: !expanded && (!icons || icons.length === 0) && leftLabel == "" && rightLabel == ""
189 PropertyChanges { target: indicatorName; opacity: 0}
190 PropertyChanges { target: d; useFallbackIcon: true }
195 PropertyChanges { target: indicatorName; visible: true; opacity: 1}
196 PropertyChanges { target: mainItems; anchors.verticalCenterOffset: -units.gu(1) }
200 name: "expanded_icon"
202 when: expanded && (icons && icons.length > 0)
203 AnchorChanges { target: iconsItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
204 AnchorChanges { target: leftLabelItem; anchors.left: undefined; anchors.right: iconsItem.left }
205 PropertyChanges { target: leftLabelItem; opacity: 0 }
206 PropertyChanges { target: leftLabelItem; opacity: 0 }
207 PropertyChanges { target: rightLabelItem; opacity: 0 }
208 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(iconsItem.width, indicatorName.width)) }
212 name: "expanded_fallback"
214 when: expanded && (!icons || icons.length === 0) && leftLabel == "" && rightLabel == ""
215 PropertyChanges { target: d; useFallbackIcon: true }
216 AnchorChanges { target: iconsItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
217 AnchorChanges { target: leftLabelItem; anchors.left: undefined; anchors.right: iconsItem.left }
218 PropertyChanges { target: leftLabelItem; opacity: 0 }
219 PropertyChanges { target: leftLabelItem; opacity: 0 }
220 PropertyChanges { target: rightLabelItem; opacity: 0 }
221 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(iconsItem.width, indicatorName.width)) }
225 name: "expanded_rightLabel"
227 when: expanded && (!icons || icons.length === 0) && rightLabel !== ""
228 AnchorChanges { target: rightLabelItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
229 PropertyChanges { target: iconsItem; opacity: 0 }
230 PropertyChanges { target: leftLabelItem; opacity: 0 }
231 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(rightLabelItem.width, indicatorName.width)) }
235 name: "expanded_leftLabel"
237 when: expanded && (!icons || icons.length === 0) && leftLabel !== ""
238 AnchorChanges { target: leftLabelItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
239 PropertyChanges { target: iconsItem; opacity: 0 }
240 PropertyChanges { target: rightLabelItem; opacity: 0 }
241 PropertyChanges { target: root; width: Math.max(units.gu(10), Math.max(leftLabelItem.width, indicatorName.width)) }
248 PropertyAction { target: d; property: "useFallbackIcon" }
250 targets: [ mainItems, iconsItem, leftLabelItem, rightLabelItem ]
251 duration: LomiriAnimation.SnapDuration; easing: LomiriAnimation.StandardEasing
254 targets: [ root, mainItems, iconsItem, leftLabelItem, rightLabelItem, indicatorName ]
255 properties: "width, opacity, anchors.verticalCenterOffset";
256 duration: LomiriAnimation.SnapDuration; easing: LomiriAnimation.StandardEasing
262 rootActionState.onUpdated: {
263 if (rootActionState == undefined) {
271 title = rootActionState.title ? rootActionState.title : rootActionState.accessibleName;
272 leftLabel = rootActionState.leftLabel ? rootActionState.leftLabel : "";
273 rightLabel = rootActionState.rightLabel ? rootActionState.rightLabel : "";
274 icons = rootActionState.icons;
280 property bool useFallbackIcon: false
281 property var shouldIndicatorBeShown: undefined
283 onShouldIndicatorBeShownChanged: {
284 if (shouldIndicatorBeShown !== undefined) {
285 submenuAction.changeState(shouldIndicatorBeShown);
294 name: rootActionState.secondaryAction
301 name: rootActionState.scrollAction
308 name: rootActionState.submenuAction
313 property: "shouldIndicatorBeShown"
314 restoreMode: Binding.RestoreBinding
315 when: submenuAction.valid
316 value: root.selected && root.expanded