on xenial help sign in
Add social comment
395b27eAndrea Cimitan
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 {
50 switch (widgetType) {
50 switch (widgetType) {
51 case "actions": return "PreviewActions.qml";
51 case "actions": return "PreviewActions.qml";
52 case "audio": return "PreviewAudioPlayback.qml";
52 case "audio": return "PreviewAudioPlayback.qml";
53+ case "comment-input": return "PreviewCommentInput.qml";
53 case "expandable": return "PreviewExpandable.qml";
54 case "expandable": return "PreviewExpandable.qml";
54 case "gallery": return "PreviewImageGallery.qml";
55 case "gallery": return "PreviewImageGallery.qml";
55 case "header": return "PreviewHeader.qml";
56 case "header": return "PreviewHeader.qml";
@@ -59,10 +60,10 @@ Loader {
59 case "rating-input": return "PreviewRatingInput.qml";
60 case "rating-input": return "PreviewRatingInput.qml";
60 case "rating-edit": return "PreviewRatingEdit.qml";
61 case "rating-edit": return "PreviewRatingEdit.qml";
61 case "reviews": return "PreviewRatingDisplay.qml";
62 case "reviews": return "PreviewRatingDisplay.qml";
63+ case "social-comment": return "PreviewSocialComment.qml";
62 case "table": return "PreviewTable.qml";
64 case "table": return "PreviewTable.qml";
63 case "text": return "PreviewTextSummary.qml";
65 case "text": return "PreviewTextSummary.qml";
64 case "video": return "PreviewVideoPlayback.qml";
66 case "video": return "PreviewVideoPlayback.qml";
65− case "comment-input": return "PreviewCommentInput.qml";
66 default: return "";
67 default: return "";
67 }
68 }
68 }
69 }
tests/qmltests/CMakeLists.txt+1
@@ -36,6 +36,7 @@ add_unity8_qmltest(Dash/Previews PreviewProgress)
36add_unity8_qmltest(Dash/Previews PreviewRatingDisplay)
36add_unity8_qmltest(Dash/Previews PreviewRatingDisplay)
37add_unity8_qmltest(Dash/Previews PreviewRatingEdit)
37add_unity8_qmltest(Dash/Previews PreviewRatingEdit)
38add_unity8_qmltest(Dash/Previews PreviewRatingInput)
38add_unity8_qmltest(Dash/Previews PreviewRatingInput)
39+add_unity8_qmltest(Dash/Previews PreviewSocialComment)
39add_unity8_qmltest(Dash/Previews PreviewTable)
40add_unity8_qmltest(Dash/Previews PreviewTable)
40add_unity8_qmltest(Dash/Previews PreviewTextSummary)
41add_unity8_qmltest(Dash/Previews PreviewTextSummary)
41add_unity8_qmltest(Dash/Previews PreviewVideoPlayback)
42add_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 {
85 { tag: "Progress", type: "progress", source: "PreviewProgress.qml" },
85 { tag: "Progress", type: "progress", source: "PreviewProgress.qml" },
86 { tag: "Rating Input", type: "rating-input", source: "PreviewRatingInput.qml" },
86 { tag: "Rating Input", type: "rating-input", source: "PreviewRatingInput.qml" },
87 { tag: "Rating Display", type: "reviews", source: "PreviewRatingDisplay.qml" },
87 { tag: "Rating Display", type: "reviews", source: "PreviewRatingDisplay.qml" },
88+ { tag: "Social Comment", type: "social-comment", source: "PreviewSocialComment.qml" },
88 { tag: "Table", type: "table", source: "PreviewTable.qml" },
89 { tag: "Table", type: "table", source: "PreviewTable.qml" },
89 { tag: "Text", type: "text", source: "PreviewTextSummary.qml" },
90 { tag: "Text", type: "text", source: "PreviewTextSummary.qml" },
90 { tag: "Video", type: "video", source: "PreviewVideoPlayback.qml" },
91 { tag: "Video", type: "video", source: "PreviewVideoPlayback.qml" },