on xenial help sign in
Add social comment
commit395b27e466841ef46b4be1d2c5696bd6732ae429 authorAndrea Cimitan <andrea.cimitan@gmail.com> dateTue 30 Jun 2015, 12:53 (11 years ago) parent7688045
5 files changed+151−1
qml/Dash/Previews/PreviewSocialComment.qml+79 qml/Dash/Previews/PreviewWidgetFactory.qml+2−1 tests/qmltests/CMakeLists.txt+1 tests/qmltests/Dash/Previews/tst_PreviewSocialComment.qml+68 tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qml+1
qml/Dash/Previews/PreviewSocialComment.qmlnew file+79
@@ -0,0 +1,79 @@
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.0
18+import Ubuntu.Components 1.2
19+
20+/*! \brief Preview widget for social comments.
21+
22+ This widget shows an (optional) avatar contained in widgetData["source"]
23+ along with a label that comes from widgetData["author"],
24+ a date date from widgetData["date"] and the comment widgetData["comment"].
25+*/
26+
27+PreviewWidget {
28+ id: root
29+ implicitHeight: column.implicitHeight
30+
31+ UbuntuShape {
32+ id: avatar
33+ objectName: "avatar"
34+ anchors {
35+ left: parent.left
36+ top: parent.top
37+ }
38+ width: units.gu(6)
39+ height: width
40+ source: Image {
41+ source: widgetData["source"]
42+ }
43+ radius: "medium"
44+ visible: source.status === Image.Ready
45+ }
46+
47+ Column {
48+ id: column
49+ objectName: "column"
50+ anchors {
51+ left: avatar.visible ? avatar.right : parent.left
52+ right: parent.right
53+ top: parent.top
54+ topMargin: units.gu(0.5)
55+ leftMargin: avatar.visible ? units.gu(1) : 0
56+ }
57+ spacing: units.gu(0.24)
58+
59+ Label {
60+ width: parent.width
61+ text: widgetData["author"] || ""
62+ fontSize: "small"
63+ maximumLineCount: 1
64+ elide: Text.ElideRight
65+ }
66+ Label {
67+ width: parent.width
68+ text: widgetData["date"] || ""
69+ fontSize: "xx-small"
70+ maximumLineCount: 1
71+ }
72+ Label {
73+ width: parent.width
74+ text: widgetData["comment"] || ""
75+ fontSize: "small"
76+ wrapMode: Text.Wrap
77+ }
78+ }
79+}
qml/Dash/Previews/PreviewWidgetFactory.qml+2−1
@@ -50,6 +50,7 @@ Loader {
5050 switch (widgetType) {
5151 case "actions": return "PreviewActions.qml";
5252 case "audio": return "PreviewAudioPlayback.qml";
53+ case "comment-input": return "PreviewCommentInput.qml";
5354 case "expandable": return "PreviewExpandable.qml";
5455 case "gallery": return "PreviewImageGallery.qml";
5556 case "header": return "PreviewHeader.qml";
@@ -59,10 +60,10 @@ Loader {
5960 case "rating-input": return "PreviewRatingInput.qml";
6061 case "rating-edit": return "PreviewRatingEdit.qml";
6162 case "reviews": return "PreviewRatingDisplay.qml";
63+ case "social-comment": return "PreviewSocialComment.qml";
6264 case "table": return "PreviewTable.qml";
6365 case "text": return "PreviewTextSummary.qml";
6466 case "video": return "PreviewVideoPlayback.qml";
65− case "comment-input": return "PreviewCommentInput.qml";
6667 default: return "";
6768 }
6869 }
tests/qmltests/CMakeLists.txt+1
@@ -36,6 +36,7 @@ add_unity8_qmltest(Dash/Previews PreviewProgress)
3636add_unity8_qmltest(Dash/Previews PreviewRatingDisplay)
3737add_unity8_qmltest(Dash/Previews PreviewRatingEdit)
3838add_unity8_qmltest(Dash/Previews PreviewRatingInput)
39+add_unity8_qmltest(Dash/Previews PreviewSocialComment)
3940add_unity8_qmltest(Dash/Previews PreviewTable)
4041add_unity8_qmltest(Dash/Previews PreviewTextSummary)
4142add_unity8_qmltest(Dash/Previews PreviewVideoPlayback)
tests/qmltests/Dash/Previews/tst_PreviewSocialComment.qmlnew file+68
@@ -0,0 +1,68 @@
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 Ubuntu.Components 1.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 comment: {
30+ "author": "Claire Thompson",
31+ "date": "28/04/2015 3:48pm",
32+ "comment": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
33+ "source": "../../graphics/avatars/amanda@12.png"
34+ }
35+
36+ property var commentNoImage: {
37+ "author": "Claire Thompson",
38+ "date": "28/04/2015 3:48pm",
39+ "comment": "Been quite a while since I really liked one.",
40+ "source": "null"
41+ }
42+
43+ PreviewSocialComment {
44+ id: previewCommentInput
45+ anchors.left: parent.left
46+ anchors.right: parent.right
47+ widgetData: comment
48+ widgetId: "previewSocialComment"
49+ }
50+
51+ UT.UnityTestCase {
52+ name: "PreviewSocialCommentTest"
53+ when: windowShown
54+
55+ function testAnchorsNoAvatar() {
56+ var column = findChild(previewCommentInput, "column");
57+ var avatar = findChild(previewCommentInput, "avatar");
58+
59+ compare(previewCommentInput.widgetData, comment);
60+ compare(avatar.visible, true);
61+ compare(column.anchors.left, avatar.anchors.right);
62+
63+ previewCommentInput.widgetData = commentNoImage;
64+ tryCompare(avatar, "visible", false);
65+ compare(column.anchors.left, previewCommentInput.anchors.left);
66+ }
67+ }
68+}
tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qml+1
@@ -85,6 +85,7 @@ Rectangle {
8585 { tag: "Progress", type: "progress", source: "PreviewProgress.qml" },
8686 { tag: "Rating Input", type: "rating-input", source: "PreviewRatingInput.qml" },
8787 { tag: "Rating Display", type: "reviews", source: "PreviewRatingDisplay.qml" },
88+ { tag: "Social Comment", type: "social-comment", source: "PreviewSocialComment.qml" },
8889 { tag: "Table", type: "table", source: "PreviewTable.qml" },
8990 { tag: "Text", type: "text", source: "PreviewTextSummary.qml" },
9091 { tag: "Video", type: "video", source: "PreviewVideoPlayback.qml" },