on df73bd5 help sign in
unity8/qml/Panel/IndicatorRow.qml
202 lines 7.2 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
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 General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17import QtQuick 2.0
18import Ubuntu.Components 0.1
19import Unity.Indicators 0.1 as Indicators
20import "../Components"
22Item {
23 id: indicatorRow
25 property QtObject currentItem : null
26 readonly property int currentItemIndex: currentItem ? currentItem.ownIndex : -1
27 property alias row: row
28 property QtObject indicatorsModel: null
29 property var visibleIndicators: undefined
30 property int overFlowWidth: width
31 property bool showAll: false
32 property real currentItemOffset: 0.0
33 property real unitProgress: 0.0
35 width: units.gu(40)
36 height: units.gu(3)
38 function setDefaultItem() {
39 // The leftmost indicator
40 setCurrentItem(0);
41 }
43 function setCurrentItem(index) {
44 if (currentItemIndex !== index) {
45 currentItem = rowRepeater.itemAt(index);
46 }
47 }
49 Timer {
50 id: allVisible
51 interval: 1000
53 onTriggered: {
54 showAll = false;
55 }
56 }
58 Row {
59 id: row
61 width: children.width
62 height: parent.height
63 anchors.right: parent.right
65 Repeater {
66 id: rowRepeater
67 objectName: "rowRepeater"
68 model: indicatorsModel ? indicatorsModel : undefined
70 property int lastCount: 0
71 onCountChanged: {
72 if (lastCount < count) {
73 showAll = true;
74 allVisible.start();
75 }
76 lastCount = count;
77 }
79 Item {
80 id: itemWrapper
81 height: indicatorRow.height
82 width: indicatorItem.width
83 visible: indicatorItem.indicatorVisible
84 opacity: 1.0 * opacityMultiplier
85 y: 0
86 state: "standard"
88 property int ownIndex: index
89 property bool highlighted: indicatorRow.state != "initial" ? ownIndex == indicatorRow.currentItemIndex : false
90 property bool dimmed: indicatorRow.state != "initial" ? ownIndex != indicatorRow.currentItemIndex : false
92 property bool hidden: !showAll && !highlighted && (indicatorRow.state == "locked" || indicatorRow.state == "commit")
93 property bool overflow: row.width - itemWrapper.x > overFlowWidth
94 property real opacityMultiplier: highlighted ? 1 : (1 - indicatorRow.unitProgress)
96 IndicatorItem {
97 id: indicatorItem
98 identifier: model.identifier
99 height: parent.height
101 dimmed: itemWrapper.dimmed
103 widgetSource: model.widgetSource
104 indicatorProperties : model.indicatorProperties
106 Component.onCompleted: {
107 updateVisiblility();
108 }
109 onIndicatorVisibleChanged: {
110 updateVisiblility();
112 if (indicatorVisible) {
113 showAll = true;
114 allVisible.start();
115 }
116 }
118 function updateVisiblility() {
119 if (visibleIndicators == undefined) {
120 visibleIndicators = {}
121 }
122 indicatorRow.visibleIndicators[model.identifier] = indicatorVisible;
124 // removed current index?
125 if (indicatorRow.currentItemIndex === index && !indicatorVisible) {
126 // find the next closest visible indicator (after current, else before)
127 var newIndex = -1;
128 for (var i = index+1; i < rowRepeater.count; i++) {
129 if (indicatorRow.visibleIndicators[i] === undefined || indicatorRow.visibleIndicators[model.identifier]) {
130 newIndex = i;
131 break;
132 }
133 }
134 if (newIndex === -1) {
135 for (i = index - 1; i >= 0; i--) {
136 if (indicatorRow.visibleIndicators[i] === undefined || indicatorRow.visibleIndicators[model.identifier]) {
137 newIndex = i;
138 break;
139 }
140 }
141 }
142 indicatorRow.setCurrentItem(newIndex);
143 }
145 indicatorRow.visibleIndicatorsChanged();
146 }
147 }
149 states: [
150 State {
151 name: "standard"
152 when: !hidden && !overflow
153 },
154 State {
155 name: "overflow"
156 when: hidden || overflow
157 PropertyChanges { target: itemWrapper; opacity: 0.0 }
158 }
159 ]
161 transitions: [
162 Transition {
163 UbuntuNumberAnimation {
164 target: itemWrapper
165 property: "opacity"
166 duration: UbuntuAnimation.BriskDuration
167 }
168 }
169 ]
170 }
171 }
172 }
174 Rectangle {
175 id: highlight
176 color: Theme.palette.selected.foreground
177 objectName: "highlight"
178 height: units.dp(2)
179 anchors.top: row.bottom
180 visible: indicatorRow.currentItem != null
181 x: row.x + (indicatorRow.currentItem != null ? indicatorRow.currentItem.x + centerOffset : 0)
182 width: indicatorRow.currentItem != null ? indicatorRow.currentItem.width : 0
184 property real centerOffset: {
185 if (indicatorRow.currentItemOffset > 0.1) {
186 return (indicatorRow.currentItemOffset - 0.1) * units.gu(0.4);
187 } else if (indicatorRow.currentItemOffset < -0.1) {
188 return (indicatorRow.currentItemOffset + 0.1) * units.gu(0.4);
189 }
190 return 0.0;
191 }
193 Behavior on width {
194 enabled: unitProgress > 0;
195 UbuntuNumberAnimation { duration: UbuntuAnimation.FastDuration }
196 }
197 Behavior on x {
198 enabled: unitProgress > 0;
199 UbuntuNumberAnimation { duration: UbuntuAnimation.FastDuration }
200 }
201 }