on xenial help sign in
PreviewActions Widget
c251e13Albert Astals
qml/Dash/Previews/PreviewActionButton.qmlnew file+30
@@ -0,0 +1,30 @@
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 Ubuntu.Components 0.1
18+
19+Button {
20+ signal triggeredAction(var data)
21+
22+ property var data: null
23+ objectName: "button" + (data && data.id || "")
24+ // TODO missing property for color
25+ color: Theme.palette.selected.foreground
26+ text: data && data.label || ""
27+ iconSource: data && data.icon || ""
28+ iconPosition: "left"
29+ onClicked: triggeredAction(data)
30+}
qml/Dash/Previews/PreviewActionCombo.qmlnew file+70
@@ -0,0 +1,70 @@
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.0
18+import Ubuntu.Components 0.1
19+
20+Item {
21+ id: root
22+
23+ width: childrenRect.width
24+ height: childrenRect.height
25+
26+ signal triggeredAction(var data)
27+
28+ property alias model: actionRepeater.model
29+
30+ Button {
31+ id: moreButton
32+ property bool expanded: false
33+
34+ objectName: "button1"
35+ text: !expanded ? i18n.tr("More...") : i18n.tr("Less...")
36+ gradient: UbuntuColors.orangeGradient
37+ onClicked: expanded = !expanded
38+ width: c.maxWidth
39+ }
40+
41+ Column {
42+ id: c
43+ property real maxWidth: -1
44+ anchors.top: moreButton.bottom
45+ anchors.topMargin: spacing
46+ objectName: "buttonColumn"
47+ spacing: height > 0 ? units.gu(1) : 0
48+ width: maxWidth
49+
50+ Repeater {
51+ id: actionRepeater
52+
53+ delegate: Button {
54+ objectName: "button" + index
55+ text: modelData.label || ""
56+ iconSource: modelData.icon || ""
57+ gradient: UbuntuColors.orangeGradient
58+ height: moreButton.expanded ? implicitHeight : 0
59+ width: implicitWidth < parent.width ? parent.width : implicitWidth
60+ visible: height > 0
61+ Component.onCompleted: {
62+ c.maxWidth = Math.max(c.maxWidth, implicitWidth);
63+ }
64+ onClicked: {
65+ root.triggeredAction(modelData)
66+ }
67+ }
68+ }
69+ }
70+}
qml/Dash/Previews/PreviewActions.qmlnew file+57
@@ -0,0 +1,57 @@
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+
19+PreviewWidget {
20+ id: root
21+
22+ height: childrenRect.height
23+ width: childrenRect.width
24+
25+ readonly property var actions: root.widgetData ? root.widgetData["actions"] : null
26+
27+ Row {
28+ spacing: units.gu(1)
29+
30+ Loader {
31+ id: loader
32+ readonly property bool button: actions && actions.length == 2
33+ readonly property bool combo: actions && actions.length > 2
34+ source: button ? "PreviewActionButton.qml" : (combo ? "PreviewActionCombo.qml" : "")
35+ onLoaded: {
36+ if (button) {
37+ item.data = actions[1];
38+ } else if (combo) {
39+ item.model = actions.splice(1)
40+ }
41+ }
42+ Connections {
43+ target: loader.item
44+ onTriggeredAction: {
45+ root.triggered(root.widgetId, data.id, data);
46+ }
47+ }
48+ }
49+
50+ PreviewActionButton {
51+ data: visible ? actions[0] : null
52+ visible: actions && actions.length > 0
53+ onTriggeredAction: root.triggered(root.widgetId, data.id, data);
54+ }
55+
56+ }
57+}
qml/Dash/Previews/PreviewWidget.qml+10
@@ -22,6 +22,16 @@ Item {
22 /// type:bool Specifies the preview widget being currently used or not
22 /// type:bool Specifies the preview widget being currently used or not
23 property bool isCurrentPreview: true
23 property bool isCurrentPreview: true
24
24
25+ // The id of the widget
26+ property string widgetId
27+
25 /// Variable used to contain widget's data
28 /// Variable used to contain widget's data
26 property var widgetData
29 property var widgetData
30+
31+ /*! \brief This signal should be emitted when a preview action was triggered.
32+ *
33+ * \param widgetId,actionId Respective identifiers from widgetData.
34+ * \param data Optional widget-specific data sent to the scope.
35+ */
36+ signal triggered(string widgetId, string actionId, var data)
27}
37}
tests/qmltests/CMakeLists.txt+1
@@ -54,6 +54,7 @@ add_qml_test(Dash/Apps RunningApplicationsGrid IMPORT_PATHS ${qmltest_DEFAULT_IM
54add_qml_test(Dash/Apps AppPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
54add_qml_test(Dash/Apps AppPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
55add_qml_test(Dash/Movie MoviePreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
55add_qml_test(Dash/Movie MoviePreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
56add_qml_test(Dash/Music MusicPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
56add_qml_test(Dash/Music MusicPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
57+add_qml_test(Dash/Previews PreviewActions IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
57add_qml_test(Dash/Previews PreviewAudioPlayback IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
58add_qml_test(Dash/Previews PreviewAudioPlayback IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
58add_qml_test(Dash/Previews PreviewImageGallery IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
59add_qml_test(Dash/Previews PreviewImageGallery IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
59add_qml_test(Dash/Previews PreviewTextSummary IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
60add_qml_test(Dash/Previews PreviewTextSummary IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
tests/qmltests/Dash/Previews/tst_PreviewActions.qmlnew file+81
@@ -0,0 +1,81 @@
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 actionDataOneAction: {
30+ "actions": [{"label": "Some Label", "icon": "../graphics/play_button.png", "id": "someid"}]
31+ }
32+
33+ property var actionDataTwoActions: {
34+ "actions": [{"label": "Some Label A", "icon": "../graphics/icon_clear.png", "id": "someid1"},
35+ {"label": "Some Label B", "icon": "../graphics/play_button.png", "id": "someid2"}
36+ ]
37+ }
38+
39+ property var actionDataFiveActions: {
40+ "actions": [{"label": "Some Label C", "icon": "../graphics/play_button.png", "id": "someid3"},
41+ {"label": "Some Label D", "icon": "../graphics/icon_clear.png", "id": "someid4"},
42+ {"label": "Some Label E", "icon": "../graphics/play_button.png", "id": "someid5"},
43+ {"label": "Some Label F", "icon": "../graphics/icon_clear.png", "id": "someid6"},
44+ {"label": "Some Label G", "icon": "../graphics/play_button.png", "id": "someid7"}
45+ ]
46+ }
47+
48+ Column {
49+ spacing: units.gu(1)
50+
51+ PreviewActions {
52+ widgetId: "button"
53+ widgetData: actionDataOneAction
54+ onTriggered: console.log("triggered", widgetId, actionId, data);
55+ }
56+
57+ PreviewActions {
58+ widgetId: "buttonAndCombo"
59+ widgetData: actionDataFiveActions
60+ onTriggered: console.log("triggered", widgetId, actionId, data);
61+ }
62+
63+ PreviewActions {
64+ widgetId: "2buttons"
65+ widgetData: actionDataTwoActions
66+ onTriggered: console.log("triggered", widgetId, actionId, data);
67+ }
68+ }
69+
70+ UT.UnityTestCase {
71+ name: "PreviewActionTest"
72+ when: windowShown
73+
74+ function test_changeEmptyModel() {
75+ wait(5000);
76+// imageGallery.widgetData = sourcesModel0;
77+// var placeholderScreenshot = findChild(imageGallery, "placeholderScreenshot");
78+// compare(placeholderScreenshot.visible, true);
79+ }
80+ }
81+}