on xenial help sign in
icon-actions preview widget

Approved by: Andrea Cimitan

commit2d0878c75e830576b8305e91a8309bfd331c562c authorAlbert Astals Cid <albert.astals@canonical.com> dateTue 21 Jul 2015, 09:09 (11 years ago) parent3e619a47a0ab97
4 files changed+200
qml/Dash/Previews/PreviewIconActions.qml+72 qml/Dash/Previews/PreviewWidgetFactory.qml+1 tests/qmltests/CMakeLists.txt+1 tests/qmltests/Dash/Previews/tst_PreviewIconActions.qml+126
qml/Dash/Previews/PreviewIconActions.qmlnew file+72
@@ -0,0 +1,72 @@
1+/*
2+ * Copyright (C) 2015 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.1
18+import Ubuntu.Components 1.1
19+
20+/*! This preview widget icons+label for number of items in widgetData["actions"].
21+ * For each of the items we recognize the fields "label", "icon", "temporaryIcon" and "id".
22+ * temporaryIcon is the icon that will be shown just after the user presses icon until the
23+ * scope refreshes the preview
24+ */
25+
26+PreviewWidget {
27+ id: root
28+
29+ implicitHeight: row.height
30+
31+ Row {
32+ id: row
33+ readonly property var actions: root.widgetData ? root.widgetData["actions"] : null
34+ width: parent.width
35+
36+ spacing: units.gu(2)
37+
38+ Repeater {
39+ model: row.actions
40+
41+ AbstractButton {
42+ objectName: "button" + modelData.id
43+ height: label.height
44+ width: childrenRect.width
45+
46+ Image {
47+ id: icon
48+ height: parent.height
49+ width: height
50+ source: modelData.icon
51+ sourceSize { width: icon.width; height: icon.height }
52+ }
53+
54+ Label {
55+ id: label
56+ anchors.left: icon.right
57+ anchors.leftMargin: visible ? units.gu(0.5) : 0
58+ text: modelData.label
59+ visible: text !== ""
60+ }
61+
62+ onClicked: {
63+ if (modelData.temporaryIcon) {
64+ icon.source = modelData.temporaryIcon;
65+ }
66+ root.triggered(root.widgetId, modelData.id, modelData);
67+ }
68+ }
69+ }
70+ }
71+
72+}
qml/Dash/Previews/PreviewWidgetFactory.qml+1
@@ -55,6 +55,7 @@ Loader {
5555 case "expandable": return "PreviewExpandable.qml";
5656 case "gallery": return "PreviewImageGallery.qml";
5757 case "header": return "PreviewHeader.qml";
58+ case "icon-actions": return "PreviewIconActions.qml";
5859 case "image": return "PreviewZoomableImage.qml";
5960 case "progress": return "PreviewProgress.qml";
6061 case "payments": return "PreviewPayments.qml";
tests/qmltests/CMakeLists.txt+1
@@ -31,6 +31,7 @@ add_unity8_qmltest(Dash/Previews PreviewComment)
3131add_unity8_qmltest(Dash/Previews PreviewCommentInput)
3232add_unity8_qmltest(Dash/Previews PreviewExpandable)
3333add_unity8_qmltest(Dash/Previews PreviewHeader)
34+add_unity8_qmltest(Dash/Previews PreviewIconActions)
3435add_unity8_qmltest(Dash/Previews PreviewImageGallery)
3536add_unity8_qmltest(Dash/Previews PreviewPayments)
3637add_unity8_qmltest(Dash/Previews PreviewProgress)
tests/qmltests/Dash/Previews/tst_PreviewIconActions.qmlnew file+126
@@ -0,0 +1,126 @@
1+/*
2+ * Copyright 2015 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 QtTest 1.0
19+import "../../../../qml/Dash/Previews"
20+import Unity.Test 0.1 as UT
21+import Ubuntu.Components 0.1
22+
23+
24+Rectangle {
25+ id: root
26+ width: units.gu(60)
27+ height: units.gu(80)
28+
29+ property var actionDataActions: {
30+ "actions": [{"label": "10", "id": "someid", "icon": Qt.resolvedUrl("../artwork/avatar@12.png"), "temporaryIcon": Qt.resolvedUrl("../artwork/emblem.png")},
31+ {"label": "12", "id": "someid2", "icon": Qt.resolvedUrl("../artwork/checkers.png"), "temporaryIcon": Qt.resolvedUrl("../artwork/background.png")},
32+ {"label": "", "id": "someid3", "icon": Qt.resolvedUrl("../artwork/music-player-design.png")},
33+ ]
34+ }
35+
36+ SignalSpy {
37+ id: spy
38+ signalName: "triggered"
39+ }
40+
41+ PreviewIconActions {
42+ id: preview
43+ widgetId: "iconActions"
44+ widgetData: actionDataActions
45+ onTriggered: {
46+ if (timer.index !== -1) {
47+ if (!testcase.running) {
48+ console.log("Processing other click, ignoring");
49+ }
50+ return;
51+ }
52+
53+ for (var i in actionDataActions.actions) {
54+ if (actionId == actionDataActions.actions[i].id) {
55+ timer.index = i;
56+ break;
57+ }
58+ }
59+
60+ timer.start();
61+ if (!testcase.running) {
62+ console.log("triggered", widgetId, actionId);
63+ }
64+ }
65+ width: parent.width
66+ clip: true
67+ }
68+
69+ Timer {
70+ id: timer
71+ property int index: -1
72+ interval: 500
73+ onTriggered: {
74+ actionDataActions.actions[index].icon = Qt.resolvedUrl("../../UnityLogo.png");
75+ preview.widgetDataChanged();
76+ index = -1;
77+ }
78+ }
79+
80+ UT.UnityTestCase {
81+ id: testcase
82+ name: "PreviewIconActionTest"
83+ when: windowShown
84+
85+ function cleanup()
86+ {
87+ spy.clear();
88+ }
89+
90+ function test_checkButtonWithTemporary_data() {
91+ return [
92+ {tag: "with temporary", temporaryIcon: "emblem", index: 0},
93+ {tag: "without temporary", temporaryIcon: undefined, index: 2},
94+ ];
95+ }
96+
97+ function test_checkButtonWithTemporary(data) {
98+ spy.target = preview;
99+
100+ var buttonId = actionDataActions.actions[data.index].id;
101+ var buttonIcon = actionDataActions.actions[data.index].icon;
102+ var buttonTemporaryIcon = actionDataActions.actions[data.index]["temporaryIcon"];
103+ var buttonLabel = actionDataActions.actions[data.index].label;
104+
105+ var button = findChild(root, "button" + buttonId);
106+ var image = findChildsByType(button, "QQuickImage")[0];
107+ var label = findChildsByType(button, "Label")[0];
108+
109+ compare(image.source, buttonIcon);
110+ compare(label.text, buttonLabel);
111+ mouseClick(button);
112+ compare(spy.count, 1);
113+ compare(spy.signalArguments[0][1], buttonId);
114+
115+ if (buttonTemporaryIcon) {
116+ compare(image.source, buttonTemporaryIcon);
117+ }
118+
119+ tryCompareFunction(function() {
120+ var button = findChild(root, "button" + buttonId);
121+ var image = findChildsByType(button, "QQuickImage")[0];
122+ return image.source && image.source.toString().indexOf("UnityLogo") > -1;
123+ }, true);
124+ }
125+ }
126+}