Unity 8
 All Classes Functions Properties
IndicatorRow.qml
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  */
16 
17 import QtQuick 2.0
18 import Ubuntu.Components 0.1
19 import Unity.Indicators 0.1 as Indicators
20 import "../Components"
21 
22 Item {
23  id: indicatorRow
24 
25  readonly property alias currentItem : itemView.currentItem
26  readonly property alias currentItemIndex: itemView.currentIndex
27  readonly property alias row: itemView
28  property QtObject indicatorsModel: null
29  property int overFlowWidth: width
30  property bool showAll: false
31  property real currentItemOffset: 0.0
32  property real unitProgress: 0.0
33 
34  width: units.gu(40)
35  height: units.gu(3)
36 
37  function setDefaultItem() {
38  // The leftmost indicator
39  setCurrentItem(0);
40  }
41 
42  function setCurrentItemIndex(index) {
43  itemView.currentIndex = index;
44  }
45 
46  function setCurrentItem(item) {
47  if (item && item.hasOwnProperty("ownIndex")) {
48  itemView.currentIndex = item.ownIndex;
49  } else {
50  itemView.currentIndex = -1;
51  }
52  }
53 
54  Timer {
55  id: allVisible
56  interval: 1000
57 
58  onTriggered: {
59  showAll = false;
60  }
61  }
62 
63  ListView {
64  id: itemView
65  objectName: "indicatorRowItems"
66  interactive: false
67  model: indicatorsModel ? indicatorsModel : null
68 
69  width: childrenRect.width
70  height: indicatorRow.height
71  anchors.right: parent.right
72  orientation: ListView.Horizontal
73 
74  property int lastCount: 0
75  onCountChanged: {
76  if (lastCount < count) {
77  showAll = true;
78  allVisible.start();
79  }
80  lastCount = count;
81  }
82 
83  delegate: Item {
84  id: itemWrapper
85  objectName: "item" + index
86  height: indicatorRow.height
87  width: indicatorItem.width
88  opacity: 1 - indicatorRow.unitProgress
89  y: 0
90  state: "standard"
91 
92  property int ownIndex: index
93  property bool highlighted: indicatorRow.unitProgress > 0 ? ListView.isCurrentItem : false
94  property bool dimmed: indicatorRow.unitProgress > 0 ? !ListView.isCurrentItem : false
95 
96  property bool hidden: !showAll && !highlighted && (indicatorRow.state == "locked" || indicatorRow.state == "commit")
97  property bool overflow: row.width - itemWrapper.x > overFlowWidth
98 
99  IndicatorItem {
100  id: indicatorItem
101  identifier: model.identifier
102  height: parent.height
103 
104  dimmed: itemWrapper.dimmed
105 
106  widgetSource: model.widgetSource
107  indicatorProperties : model.indicatorProperties
108  }
109 
110  states: [
111  State {
112  name: "standard"
113  when: !hidden && !overflow && !highlighted
114  },
115  State {
116  name: "highlighted"
117  when: highlighted
118  PropertyChanges { target: itemWrapper; opacity: 1.0 }
119  },
120  State {
121  name: "hidden"
122  when: hidden || overflow
123  PropertyChanges { target: itemWrapper; opacity: 0.0 }
124  }
125  ]
126 
127  Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.BriskDuration } }
128  }
129  }
130 
131 
132  Rectangle {
133  id: highlight
134  color: Theme.palette.selected.foreground
135  objectName: "highlight"
136  height: units.dp(2)
137  anchors.top: row.bottom
138  visible: indicatorRow.currentItem != null
139 
140  property real intendedX: row.x + (indicatorRow.currentItem != null ? (indicatorRow.currentItem.x - row.originX) + centerOffset : 0)
141  x: intendedX >= row.x ? (intendedX + width <= row.x + row.width ? intendedX : row.x + row.width - width) : row.x // listview boundaries
142  width: indicatorRow.currentItem != null ? indicatorRow.currentItem.width : 0
143 
144  property real centerOffset: {
145  if (indicatorRow.currentItemOffset > 0.1) {
146  return (indicatorRow.currentItemOffset - 0.1) * units.gu(0.4);
147  } else if (indicatorRow.currentItemOffset < -0.1) {
148  return (indicatorRow.currentItemOffset + 0.1) * units.gu(0.4);
149  }
150  return 0.0;
151  }
152 
153  Behavior on width {
154  enabled: unitProgress > 0;
155  UbuntuNumberAnimation { duration: UbuntuAnimation.FastDuration }
156  }
157  Behavior on x {
158  enabled: unitProgress > 0;
159  UbuntuNumberAnimation { duration: UbuntuAnimation.FastDuration }
160  }
161  }
162 }