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