on xenial help sign in
merge Movie preview branch in here
commit7b3ee91ecd5b23a93fcba1a9348e60d2c636737e authorMichael Zanetti <michael.zanetti@canonical.com> dateMon 30 Sep 2013, 17:11 (13 years ago) parent3222e0c1a42863
4 files changed+251
Dash/Movie/MoviePreview.qml+165 Dash/PreviewDelegateMapper.qml+1 tests/qmltests/CMakeLists.txt+1 tests/qmltests/Dash/Movie/tst_MoviePreview.qml+84
Dash/Movie/MoviePreview.qmlnew file+165
@@ -0,0 +1,165 @@
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 ".."
20+import "../../Components"
21+
22+DashPreview {
23+ id: root
24+
25+ property bool ready: previewData ? true : false
26+ property bool playable: previewData.imageSourceUri != null
27+ property url url: ready ? previewData.image : ""
28+
29+ title: root.ready ? previewData.title : ""
30+ previewWidthRatio: 0.6
31+
32+ onPreviewImageClicked: {
33+ if (playable) {
34+ shell.activateApplication('/usr/share/applications/mediaplayer-app.desktop', previewData.imageSourceUri);
35+ }
36+ }
37+
38+ header: UbuntuShape {
39+ id: urlLoader
40+ anchors.left: parent.left
41+ anchors.right: parent.right
42+ radius: "medium"
43+ image: Image {
44+ id: previewImage
45+ asynchronous: true
46+ source: root.url
47+ fillMode: Image.PreserveAspectCrop
48+ }
49+
50+ Image {
51+ objectName: "playButton"
52+ anchors.centerIn: parent
53+ visible: root.playable
54+ readonly property bool bigButton: parent.width > units.gu(40)
55+ width: bigButton ? units.gu(8) : units.gu(4.5)
56+ height: width
57+ source: "../graphics/play_button%1%2.png".arg(previewImageMouseArea.pressed ? "_active" : "").arg(bigButton ? "_big" : "")
58+ }
59+
60+ MouseArea {
61+ id: previewImageMouseArea
62+ anchors.fill: parent
63+ onClicked: root.previewImageClicked()
64+ }
65+ }
66+
67+ buttons: GridView {
68+ id: buttons
69+ objectName: "gridButtons"
70+ model: root.previewData.actions
71+ interactive: false
72+
73+ anchors.left: parent.left
74+ anchors.right: parent.right
75+
76+ property int numOfRows: (count + numOfColumns - 1) / numOfColumns
77+ property int numOfColumns: Math.max(1, Math.floor(width / (buttonWidth + spacing)))
78+ property int spacing: units.gu(1)
79+ height: Math.max(units.gu(4), units.gu(4)*numOfRows + spacing*(numOfRows - 1))
80+
81+ cellWidth: width / buttons.numOfColumns
82+ cellHeight: buttonHeight + buttons.spacing
83+ property int buttonWidth: units.gu(17) - spacing
84+ property int buttonHeight: units.gu(4)
85+
86+ delegate: Button {
87+ width: Math.max(units.gu(4), buttons.buttonWidth)
88+ height: buttons.buttonHeight
89+ color: "#dd4814"
90+ text: modelData.displayName
91+ iconSource: modelData.iconHint
92+ iconPosition: "right"
93+ visible: true
94+ onClicked: {
95+ root.previewData.execute(modelData.id, { })
96+ }
97+ }
98+ focus: false
99+ }
100+
101+ body: Column {
102+ spacing: units.gu(2)
103+ RatingStars {
104+ visible: previewData.rating >= 0.0
105+ rating: previewData.rating >= 0.0 ? previewData.rating * 5 : 0
106+ }
107+
108+ Label {
109+ text: ready ? previewData.description : ""
110+ color: Theme.palette.selected.backgroundText
111+ opacity: .6
112+ fontSize: "medium"
113+ width: parent.width
114+ wrapMode: Text.WordWrap
115+ style: Text.Raised
116+ styleColor: "black"
117+ }
118+
119+ Grid {
120+ columns: 2
121+ spacing: units.gu(1)
122+ width: parent.width
123+ property int firstColWidth: units.gu(9)
124+ property int secondColWidth: width - firstColWidth - spacing
125+ Label {
126+ visible: directedLabel.visible
127+ fontSize: "small"
128+ opacity: 0.9
129+ color: "white"
130+ horizontalAlignment: Text.AlignRight
131+ width: parent.firstColWidth
132+ text: i18n.tr("Date:")
133+ style: Text.Raised
134+ styleColor: "black"
135+ }
136+ Label {
137+ id: directedLabel
138+ visible: text != ""
139+ fontSize: "small"
140+ opacity: 0.6
141+ color: "white"
142+ width: parent.secondColWidth
143+ text: ready ? previewData.subtitle : ""
144+ style: Text.Raised
145+ styleColor: "black"
146+ wrapMode: Text.WordWrap
147+ }
148+ }
149+
150+ Label {
151+ fontSize: "small"
152+ opacity: 0.6
153+ color: "white"
154+ text: {
155+ var parts = []
156+ if (ready) {
157+ if (previewData.year) parts.push(previewData.year)
158+ }
159+ return parts.join(", ");
160+ }
161+ style: Text.Raised
162+ styleColor: "black"
163+ }
164+ }
165+}
Dash/PreviewDelegateMapper.qml+1
@@ -22,6 +22,7 @@ QtObject {
2222 readonly property string appPreview: "Apps/AppPreview.qml"
2323 property var previewDelegateMapping: {"preview-generic": genericPreview,
2424 "preview-application": appPreview,
25+ "preview-movie": "Movie/MoviePreview.qml",
2526 }
2627 }
2728
tests/qmltests/CMakeLists.txt+1
@@ -52,6 +52,7 @@ add_qml_test(Dash FilterGrids IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMA
5252add_qml_test(Dash/Apps RunningApplicationsGrid IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
5353add_qml_test(Dash/Apps AppPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
5454add_qml_test(Dash/Video VideoPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
55+add_qml_test(Dash/Movie MoviePreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
5556add_qml_test(Greeter Lockscreen IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS}
5657 PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
5758add_qml_test(Greeter Tablet IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS}
tests/qmltests/Dash/Movie/tst_MoviePreview.qmlnew file+84
@@ -0,0 +1,84 @@
1+/*
2+ * Copyright 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 QtTest 1.0
19+import "../../../../Dash/Movie"
20+import Unity.Test 0.1 as UT
21+
22+Item {
23+ id: root
24+ width: units.gu(60)
25+ height: units.gu(80)
26+
27+ property var calls: []
28+ property int counter: 0
29+
30+ function get_actions_data() {
31+ return [
32+ { id: 123, displayName: "Play", iconHint: "image://theme/search" },
33+ { id: 456, displayName: "Buy", iconHint: "image://theme/search" },
34+ { id: 789, displayName: "Delete", iconHint: "image//theme/search" }
35+ ]
36+ }
37+
38+ function fake_callback(id, data){
39+ root.calls[root.calls.length] = id;
40+ }
41+
42+ // The component under test
43+ MoviePreview {
44+ id: moviePreview
45+ anchors.fill: parent
46+
47+ previewData: QtObject {
48+ property string rendererName: "preview-movie"
49+ property string title: "Unity Movie"
50+ property string subtitle: "Subtitle"
51+ property string description: "This is the description"
52+ property string image: "image://theme/syncing"
53+ property var actions: get_actions_data()
54+ property string year: "2013"
55+ property real rating: 0.3
56+ property int numRatings: 1
57+ property var execute: fake_callback
58+ }
59+ }
60+
61+ UT.UnityTestCase {
62+ name: "MoviePreviewTest"
63+ when: windowShown
64+
65+ function init() {
66+ root.calls = new Array();
67+ }
68+
69+ function test_numofbuttons() {
70+ var buttons = findChild(moviePreview, "gridButtons");
71+ compare(buttons.count, 3);
72+
73+ for(var i = 0; i < buttons.count; i++) {
74+ buttons.currentIndex = i;
75+ buttons.currentItem.clicked();
76+ }
77+
78+ var actions = get_actions_data();
79+ for(var i = 0; i < actions.length; i++) {
80+ compare(root.calls[i], actions[i].id);
81+ }
82+ }
83+ }
84+}