Unity 8
PreviewComment.qml
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.4
18 import Ubuntu.Components 1.3
19 
20 /*! \brief Preview widget for 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 (optional) subtitle from widgetData["subtitle"] and the comment widgetData["comment"].
25 */
26 
27 PreviewWidget {
28  id: root
29  implicitHeight: Math.max(avatar.height, 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  aspect: UbuntuShape.Flat
45  opacity: source.status === Image.Ready ? 1 : 0
46  visible: widgetData["source"] !== ""
47  }
48 
49  Column {
50  id: column
51  objectName: "column"
52  anchors {
53  left: avatar.visible ? avatar.right : parent.left
54  right: parent.right
55  top: parent.top
56  topMargin: units.gu(0.5)
57  leftMargin: avatar.visible ? units.gu(1) : 0
58  }
59  spacing: units.gu(0.24)
60 
61  Label {
62  width: parent.width
63  text: widgetData["author"] || ""
64  fontSize: "small"
65  maximumLineCount: 1
66  elide: Text.ElideRight
67  }
68  Label {
69  objectName: "subtitle"
70  width: parent.width
71  visible: text !== ""
72  text: widgetData["subtitle"] || ""
73  fontSize: "xx-small"
74  font.weight: Font.Light
75  maximumLineCount: 1
76  elide: Text.ElideRight
77  }
78  Label {
79  width: parent.width
80  text: widgetData["comment"] || ""
81  fontSize: "small"
82  font.weight: Font.Light
83  wrapMode: Text.Wrap
84  }
85  }
86 }