2
* Copyright 2013-2014 Canonical Ltd.
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.
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.
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/>.
18
import QtQuick.Layouts 1.1
20
import "../../../qml/Panel"
21
import Ubuntu.Components 0.1
22
import Unity.Test 0.1 as UT
23
import Unity.Indicators 0.1 as Indicators
33
anchors.margins: units.gu(1)
38
Layout.fillWidth: true
39
Layout.fillHeight: true
43
anchors.fill: indicatorsBar
48
height: expanded ? units.gu(7) : units.gu(3)
50
anchors.centerIn: parent
51
indicatorsModel: root.indicatorsModel
52
interactive: expanded && height === units.gu(7)
57
duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing
63
enabled: !indicatorsBar.expanded
65
indicatorsBar.selectItemAt(mouse.x);
66
indicatorsBar.expanded = true
73
Layout.alignment: Qt.AlignTop
74
Layout.fillWidth: false
77
Layout.fillWidth: true
78
text: indicatorsBar.expanded ? "Collapse" : "Expand"
79
onClicked: indicatorsBar.expanded = !indicatorsBar.expanded
83
Layout.preferredHeight: units.dp(1);
84
Layout.fillWidth: true;
89
model: root.originalModelData
93
onCheckedChanged: checked ? insertIndicator(index) : removeIndicator(index);
96
Layout.fillWidth: true
97
text: modelData["identifier"]
102
onCheckedChanged: setIndicatorVisible(index, checked);
113
name: "IndicatorsBar"
117
indicatorsBar.expanded = false;
118
wait_for_expansion_to_settle();
121
function test_expandSelectedItem_data() {
129
function wait_for_expansion_to_settle() {
130
tryCompare(heightAnimation, "running", false);
131
wait(UbuntuAnimation.SnapDuration); // put a little extra wait in for things to settle
134
// Rough check that expanding a selected item keeps it within the area of the original item.
135
function test_expandSelectedItem(data) {
136
var dataItem = findChild(indicatorsBar, root.originalModelData[data.index]["identifier"] + "-panelItem");
137
verify(dataItem !== null);
139
var mappedPosition = indicatorsBar.mapFromItem(dataItem, dataItem.width/2, dataItem.height/2);
141
indicatorsBar.selectItemAt(mappedPosition.x);
142
indicatorsBar.expanded = true;
143
wait_for_expansion_to_settle();
146
// mappedPosition contained within mappedRect
147
tryCompareFunction(function() {
148
var mappedRect = indicatorsBar.mapFromItem(dataItem, 0, 0, dataItem.width, dataItem.height);
149
return mappedRect.x <= mappedPosition.x; },
151
tryCompareFunction(function() {
152
var mappedRect = indicatorsBar.mapFromItem(dataItem, 0, 0, dataItem.width, dataItem.height);
153
return mappedRect.x + mappedRect.width >= mappedPosition.x;
157
function test_scrollOffset() {
158
indicatorsBar.expanded = true;
159
wait_for_expansion_to_settle();
161
var lastItemIndex = root.originalModelData.length-1;
162
var dataItem = findChild(indicatorsBar, root.originalModelData[lastItemIndex]["identifier"] + "-panelItem");
163
verify(dataItem !== null);
165
var row = findChild(indicatorsBar, "indicatorItemRow");
166
// test will not work without these conditions
167
verify(row.width >= indicatorsBar.width + dataItem.width);
169
var mappedPosition = indicatorsBar.mapFromItem(dataItem, dataItem.width/2, dataItem.height/2);
170
indicatorsBar.addScrollOffset(-dataItem.width);
171
var newMappedPosition = indicatorsBar.mapFromItem(dataItem, dataItem.width/2, dataItem.height/2);
173
compare(mappedPosition.x, newMappedPosition.x - dataItem.width);
176
function test_selectItemWhenExpanded_data() {
183
function test_selectItemWhenExpanded(data) {
184
indicatorsBar.expanded = true;
185
wait_for_expansion_to_settle();
187
var dataItem = findChild(indicatorsBar, root.originalModelData[data.index]["identifier"] + "-panelItem");
188
if (indicatorsBar.mapFromItem(dataItem, dataItem.width/2, dataItem.height/2).x < 0) {
189
skip("Out of bounds");
191
mouseClick(dataItem, dataItem.width/2, dataItem.height/2);
192
verify(dataItem.selected === true);
195
function test_visibleIndicators_data() {
197
{ visible: [true, false, true, false, true, true] },
198
{ visible: [false, false, false, false, false, false] }
202
function test_visibleIndicators(data) {
203
for (var i = 0; i < data.visible.length; i++) {
204
var visible = data.visible[i];
205
root.setIndicatorVisible(i, visible);
207
var dataItem = findChild(indicatorsBar, root.originalModelData[i]["identifier"] + "-panelItem");
208
tryCompare(dataItem, "opacity", visible ? 1.0 : 0.0);
209
tryCompareFunction(function() { return dataItem.width > 0.0; }, visible);
212
indicatorsBar.expanded = true;
213
wait_for_expansion_to_settle();
215
for (var i = 0; i < data.visible.length; i++) {
216
root.setIndicatorVisible(i, data.visible[i]);
218
var dataItem = findChild(indicatorsBar, root.originalModelData[i]["identifier"] + "-panelItem");
219
tryCompareFunction(function() { return dataItem.opacity > 0.0; }, true);
220
tryCompareFunction(function() { return dataItem.width > 0.0; }, true);