on xenial help sign in
WIP PreviewRatingDisplay
commite070112e6e246f6482d706e7d008fdbbfab80b19 authorAndrea Cimitan <andrea.cimitan@canonical.com> dateThu 20 Feb 2014, 17:01 (13 years ago) parent30770e2
3 files changed+143
qml/Dash/Previews/PreviewRatingDisplay.qml+96 tests/qmltests/CMakeLists.txt+1 tests/qmltests/Dash/Previews/tst_PreviewRatingDisplay.qml+46
qml/Dash/Previews/PreviewRatingDisplay.qmlnew file+96
@@ -0,0 +1,96 @@
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+import "../../Components"
20+
21+/*! \brief Preview widget for rating display.
22+
23+ The widget can show a rating widget and a field showing a comment.
24+ The icons used in the rating widget can be customised with
25+ widgetData["rating-icon-empty"], widgetData["rating-icon-full"]
26+ and widgetData["rating-icon-half"].
27+
28+ This widget shows reviews contained in widgetData["reviews"], each of which should be of the form:
29+
30+ \code{.json}
31+ {
32+ "rating": null,
33+ "review": null,
34+ "author": null
35+ }
36+ \endcode
37+ */
38+
39+PreviewWidget {
40+ id: root
41+ height: childrenRect.height
42+
43+ Column {
44+ anchors { left: parent.left; right: parent.right; }
45+ visible: reviewsRepeater.count > 0
46+
47+ Repeater {
48+ id: reviewsRepeater
49+ objectName: "reviewsRepeater"
50+ model: root.widgetData["reviews"]
51+
52+ delegate: Column {
53+ id: reviewColumn
54+ objectName: "reviewItem" + index
55+ anchors { left: parent.left; right: parent.right;}
56+ spacing: units.gu(1)
57+
58+ Rating {
59+ id: rating
60+ objectName: "rating"
61+ size: 5
62+ value: modelData["rating"]
63+
64+ property var urlIconEmpty: widgetData["rating-icon-empty"]
65+ property var urlIconFull: widgetData["rating-icon-full"]
66+ property var urlIconHalf: widgetData["rating-icon-half"]
67+ }
68+
69+ Label {
70+ id: authorLabel
71+ objectName: "authorLabel"
72+ anchors { left: parent.left; right: parent.right }
73+ color: Theme.palette.selected.backgroundText
74+ opacity: .8
75+ text: modelData["author"]
76+ wrapMode: Text.Wrap
77+ }
78+
79+ Label {
80+ id: reviewLabel
81+ objectName: "reviewLabel"
82+ anchors { left: parent.left; right: parent.right }
83+ color: Theme.palette.selected.backgroundText
84+ opacity: .8
85+ text: modelData["review"]
86+ wrapMode: Text.Wrap
87+ }
88+
89+ Item {
90+ anchors { left: parent.left; right: parent.right }
91+ height: units.gu(2)
92+ }
93+ }
94+ }
95+ }
96+}
tests/qmltests/CMakeLists.txt+1
@@ -62,6 +62,7 @@ add_qml_test(Dash/Previews PreviewAudioPlayback IMPORT_PATHS ${qmltest_DEFAULT_I
6262add_qml_test(Dash/Previews PreviewHeader IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
6363add_qml_test(Dash/Previews PreviewImageGallery IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
6464add_qml_test(Dash/Previews PreviewProgress IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
65+add_qml_test(Dash/Previews PreviewRatingDisplay IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
6566add_qml_test(Dash/Previews PreviewRatingInput IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
6667add_qml_test(Dash/Previews PreviewTextSummary IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
6768add_qml_test(Dash/Previews PreviewVideoPlayback IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
tests/qmltests/Dash/Previews/tst_PreviewRatingDisplay.qmlnew file+46
@@ -0,0 +1,46 @@
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 Ubuntu.Components 0.1
20+import "../../../../qml/Dash/Previews"
21+import Unity.Test 0.1 as UT
22+
23+Rectangle {
24+ id: root
25+ width: units.gu(40)
26+ height: units.gu(80)
27+ color: Theme.palette.selected.background
28+
29+ property var reviewsModel: {
30+ "reviews": [ { author: "Some dude", rating: "4.5", review: "Very cool app" },
31+ { author: "Another dude", rating: "3", review: "Average app. Lorem ipsum dolor sit amet, consectetur adipiscing elit.\nPhasellus a mi vitae augue rhoncus lobortis ut rutrum metus.\nCurabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit.\nPhasellus a mi vitae augue rhoncus lobortis ut rutrum metus.\nCurabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh." },
32+ { author: "Yet Another dude", rating: "5", review: "Very cool app" }, ]
33+ }
34+
35+ PreviewRatingDisplay {
36+ id: previewRatingDisplay
37+ anchors.left: parent.left
38+ anchors.right: parent.right
39+ widgetData: reviewsModel
40+ }
41+
42+ UT.UnityTestCase {
43+ name: "PreviewRatingDisplayTest"
44+ when: windowShown
45+ }
46+}