on 5ab40fb help sign in
unity8/Panel/IndicatorRow.qml
93 lines 3.0 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 "../Components"
21Item {
22 id: indicatorRow
24 property QtObject currentItem : null
25 readonly property int currentItemIndex: currentItem ? currentItem.ownIndex : -1
26 property alias row: row
27 property QtObject indicatorsModel: null
29 Behavior on y { StandardAnimation {} }
31 width: units.gu(40)
32 height: units.gu(3)
34 function setDefaultItem() {
35 // The leftmost indicator
36 setCurrentItem(0);
37 }
39 function setCurrentItem(index) {
40 if (currentItemIndex !== index) {
41 currentItem = rowRepeater.itemAt(index);
42 }
43 }
45 Row {
46 id: row
48 width: children.width
49 height: parent.height
50 anchors.right: parent.right
52 Repeater {
53 id: rowRepeater
54 objectName: "rowRepeater"
55 model: indicatorsModel ? indicatorsModel : undefined
57 Item {
58 id: itemWrapper
59 height: indicatorRow.height
60 width: childrenRect.width
62 property int ownIndex: index
63 property alias highlighted: indicatorItem.highlighted
64 property alias dimmed: indicatorItem.dimmed
66 IndicatorItem {
67 id: indicatorItem
68 height: parent.height
70 highlighted: indicatorRow.state != "initial" ? itemWrapper.ownIndex == indicatorRow.currentItemIndex : false
71 dimmed: indicatorRow.state != "initial" ? itemWrapper.ownIndex != indicatorRow.currentItemIndex : false
73 widgetSource: model.widgetSource
74 indicatorProperties : model.indicatorProperties
75 }
77 opacity: {
78 if (!indicatorItem.highlighted && (indicatorRow.state == "locked" || indicatorRow.state == "commit")) {
79 return 0.0;
80 } else {
81 return 1.0;
82 }
83 }
84 Behavior on opacity {
85 StandardAnimation {
86 // flow away from current index
87 duration: (rowRepeater.count - Math.abs(indicatorRow.currentItemIndex - index)) * (500/rowRepeater.count)
88 }
89 }
90 }
91 }
92 }