on xenial help sign in
icon-actions preview widget
3d2ae71Albert Astals Cid
qml/Dash/Previews/PreviewIconActions.qmlnew file+71
@@ -0,0 +1,71 @@
1+/*
2+ * Copyright (C) 2014 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+ height: 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: widgetData["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+ }
52+
53+ Label {
54+ id: label
55+ anchors.left: icon.right
56+ anchors.leftMargin: visible ? units.gu(0.5) : 0
57+ text: modelData.label
58+ visible: text !== ""
59+ }
60+
61+ onClicked: {
62+ if (modelData.temporaryIcon) {
63+ icon.source = modelData.temporaryIcon;
64+ }
65+ root.triggered(root.widgetId, modelData.id, modelData);
66+ }
67+ }
68+ }
69+ }
70+
71+}
qml/Dash/Previews/PreviewWidgetFactory.qml+1
@@ -53,6 +53,7 @@ Loader {
53 case "expandable": return "PreviewExpandable.qml";
53 case "expandable": return "PreviewExpandable.qml";
54 case "gallery": return "PreviewImageGallery.qml";
54 case "gallery": return "PreviewImageGallery.qml";
55 case "header": return "PreviewHeader.qml";
55 case "header": return "PreviewHeader.qml";
56+ case "icon-actions": return "PreviewIconActions.qml";
56 case "image": return "PreviewZoomableImage.qml";
57 case "image": return "PreviewZoomableImage.qml";
57 case "progress": return "PreviewProgress.qml";
58 case "progress": return "PreviewProgress.qml";
58 case "payments": return "PreviewPayments.qml";
59 case "payments": return "PreviewPayments.qml";
tests/qmltests/CMakeLists.txt+1
@@ -29,6 +29,7 @@ add_unity8_qmltest(Dash/Previews PreviewActions)
29add_unity8_qmltest(Dash/Previews PreviewAudioPlayback)
29add_unity8_qmltest(Dash/Previews PreviewAudioPlayback)
30add_unity8_qmltest(Dash/Previews PreviewExpandable)
30add_unity8_qmltest(Dash/Previews PreviewExpandable)
31add_unity8_qmltest(Dash/Previews PreviewHeader)
31add_unity8_qmltest(Dash/Previews PreviewHeader)
32+add_unity8_qmltest(Dash/Previews PreviewIconActions)
32add_unity8_qmltest(Dash/Previews PreviewImageGallery)
33add_unity8_qmltest(Dash/Previews PreviewImageGallery)
33add_unity8_qmltest(Dash/Previews PreviewPayments)
34add_unity8_qmltest(Dash/Previews PreviewPayments)
34add_unity8_qmltest(Dash/Previews PreviewProgress)
35add_unity8_qmltest(Dash/Previews PreviewProgress)
tests/qmltests/Dash/Previews/tst_PreviewIconActions.qmlnew file+121
@@ -0,0 +1,121 @@
1+/*
2+ * Copyright 2014 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+ console.log("Processing other click, ignoring");
48+ return;
49+ }
50+
51+ for (var i in actionDataActions.actions) {
52+ if (actionId == actionDataActions.actions[i].id) {
53+ timer.index = i;
54+ break;
55+ }
56+ }
57+
58+ timer.start();
59+ console.log("triggered", widgetId, actionId);
60+ }
61+ width: parent.width
62+ clip: true
63+ }
64+
65+ Timer {
66+ id: timer
67+ property int index: -1
68+ interval: 500
69+ onTriggered: {
70+ actionDataActions.actions[index].icon = Qt.resolvedUrl("../../UnityLogo.png");
71+ preview.widgetDataChanged();
72+ index = -1;
73+ }
74+ }
75+
76+ UT.UnityTestCase {
77+ name: "PreviewIconActionTest"
78+ when: windowShown
79+
80+ function cleanup()
81+ {
82+ spy.clear();
83+ }
84+
85+ function test_checkButtonWithTemporary_data() {
86+ return [
87+ {tag: "with temporary", temporaryIcon: "emblem", index: 0},
88+ {tag: "without temporary", temporaryIcon: undefined, index: 2},
89+ ];
90+ }
91+
92+ function test_checkButtonWithTemporary(data) {
93+ spy.target = preview;
94+
95+ var buttonId = actionDataActions.actions[data.index].id;
96+ var buttonIcon = actionDataActions.actions[data.index].icon;
97+ var buttonTemporaryIcon = actionDataActions.actions[data.index]["temporaryIcon"];
98+ var buttonLabel = actionDataActions.actions[data.index].label;
99+
100+ var button = findChild(root, "button" + buttonId);
101+ var image = findChildsByType(button, "QQuickImage")[0];
102+ var label = findChildsByType(button, "Label")[0];
103+
104+ compare(image.source, buttonIcon);
105+ compare(label.text, buttonLabel);
106+ mouseClick(button);
107+ compare(spy.count, 1);
108+ compare(spy.signalArguments[0][1], buttonId);
109+
110+ if (buttonTemporaryIcon) {
111+ compare(image.source, buttonTemporaryIcon);
112+ }
113+
114+ tryCompareFunction(function() {
115+ var button = findChild(root, "button" + buttonId);
116+ var image = findChildsByType(button, "QQuickImage")[0];
117+ return image.source && image.source.toString().indexOf("UnityLogo") > -1;
118+ }, true);
119+ }
120+ }
121+}