@@ -0,0 +1,103 @@
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 0.1
19+import "../../Components"
20+
21+/*! \brief Preview widget for rating.
22+
23+ The widget can show a rating widget and a field to enter a comment.
24+ The visibility of the two widgets is specified by widgetData["visible"],
25+ accepting "both", "rating" or "review".
26+ The requirement of the review is specified by widgetData["visible"],
27+ accepting "both", "rating" or "review".
28+ It is possible to customise labels, widgetData["rating-label"] for the rating,
29+ widgetData["rewiew-label"] for the comment field and widgetData["submit-label"]
30+ for the submit button.
31+ The icons used in the rating widget can be customised with
32+ widgetData["rating-icon-empty"] and widgetData["rating-icon-full"].
33+ The successeful submit emits triggered(widgetId, widgetData["required"], data),
34+ with data being {"rating": rating value, "review": review comment, "author": null (for now)}.
35+*/
36+
37+PreviewWidget {
38+ id: root
39+ implicitHeight: commentContainer.implicitHeight
40+
41+ property alias commentText: commentTextArea.text
42+
43+ function submit() {
44+ // checks if comment text area actually contains something
45+ if (commentTextArea.text === "") return;
46+
47+ var data = { "comment": commentTextArea.text };
48+ triggered(root.widgetId, "commented", data);
49+ }
50+
51+ Item {
52+ id: commentContainer
53+ implicitHeight: commentSubmitContainer.implicitHeight + anchors.topMargin
54+
55+ readonly property real innerMargin: units.gu(1)
56+
57+ anchors {
58+ left: parent.left
59+ right: parent.right
60+ top: parent.top
61+ bottom: parent.bottom
62+ }
63+
64+ Item {
65+ id: commentSubmitContainer
66+ anchors {
67+ top: parent.top
68+ left: parent.left
69+ right: parent.right
70+ bottom: parent.bottom
71+ }
72+ implicitHeight: commentTextArea.implicitHeight + anchors.topMargin
73+
74+ TextField {
75+ id: commentTextArea
76+ objectName: "commentTextArea"
77+ anchors {
78+ top: parent.top
79+ left: parent.left
80+ right: submitButton.left
81+ rightMargin: commentContainer.innerMargin
82+ }
83+ }
84+
85+ Button {
86+ id: submitButton
87+ objectName: "submitButton"
88+
89+ readonly property bool readyToSubmit: commentTextArea.text.length > 0
90+
91+ anchors {
92+ top: parent.top
93+ right: parent.right
94+ }
95+ color: readyToSubmit ? Theme.palette.selected.base : Theme.palette.normal.base
96+ text: widgetData["submit-label"] || i18n.tr("Send")
97+ onClicked: {
98+ if (readyToSubmit) root.submit()
99+ }
100+ }
101+ }
102+ }
103+}