KNewStuff

EntryCommentDelegate.qml
1 /*
2  * Copyright (C) 2019 Dan Leinir Turthra Jensen <[email protected]>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) version 3, or any
8  * later version accepted by the membership of KDE e.V. (or its
9  * successor approved by the membership of KDE e.V.), which shall
10  * act as a proxy defined in Section 6 of version 3 of the license.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
26 import QtQuick 2.11
27 import QtQuick.Controls 2.11 as QtControls
28 import QtQuick.Layouts 1.11 as QtLayouts
29 
30 import org.kde.kirigami 2.7 as Kirigami
31 
32 import org.kde.newstuff 1.62 as NewStuff
33 
34 QtLayouts.RowLayout {
35  id: component
36 
40  property QtObject engine
41 
45  property string entryAuthorId
49  property string entryProviderId
50 
54  property string author
59  property int score
63  property string title
67  property alias reviewText: reviewLabel.text
71  property int depth
72 
73  spacing: 0
74 
75  property QtObject commentAuthor: NewStuff.Author {
76  engine: component.engine
77  providerId: component.entryProviderId
78  username: component.author
79  }
80 
81  anchors {
82  left: parent.left
83  right: parent.right
84  leftMargin: Kirigami.Units.largeSpacing
85  rightMargin: Kirigami.Units.largeSpacing
86  }
87 
88  Repeater {
89  model: component.depth
90  delegate: Rectangle {
91  QtLayouts.Layout.fillHeight: true
92  QtLayouts.Layout.minimumWidth: Kirigami.Units.largeSpacing
93  QtLayouts.Layout.maximumWidth: Kirigami.Units.largeSpacing
94  color: Qt.tint(Kirigami.Theme.textColor, Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.8))
95  Rectangle {
96  anchors {
97  top: parent.top
98  bottom: parent.bottom
99  left: parent.left
100  }
101  width: 1
102  color: Kirigami.Theme.backgroundColor
103  }
104  }
105  }
106 
107  QtLayouts.ColumnLayout {
108  Item {
109  visible: component.depth === 0
110  QtLayouts.Layout.fillWidth: true
111  QtLayouts.Layout.minimumHeight: Kirigami.Units.largeSpacing
112  QtLayouts.Layout.maximumHeight: Kirigami.Units.largeSpacing
113  }
114 
115  Kirigami.Separator {
116  QtLayouts.Layout.fillWidth: true
117  }
118 
119  QtLayouts.RowLayout {
120  visible: (component.title !== "" || component.score !== 0)
121  QtLayouts.Layout.fillWidth: true
122  QtLayouts.Layout.leftMargin: Kirigami.Units.largeSpacing
123  Kirigami.Heading {
124  id: titleLabel
125  text: ((component.title === "") ? i18ndc("knewstuff5", "Placeholder title for when a comment has no subject, but does have a rating", "<i>(no title)</i>") : component.title)
126  level: 4
127  QtLayouts.Layout.fillWidth: true
128  }
129  Rating {
130  id: ratingStars
131  rating: Math.floor(component.score / 10)
132  }
133  Item {
134  QtLayouts.Layout.minimumWidth: Kirigami.Units.largeSpacing
135  QtLayouts.Layout.maximumWidth: Kirigami.Units.largeSpacing
136  }
137  }
138 
139  QtControls.Label {
140  id: reviewLabel
141  QtLayouts.Layout.fillWidth: true
142  QtLayouts.Layout.leftMargin: Kirigami.Units.largeSpacing
143  QtLayouts.Layout.rightMargin: Kirigami.Units.largeSpacing
144  wrapMode: Text.Wrap
145  }
146 
147  QtLayouts.RowLayout {
148  QtLayouts.Layout.fillWidth: true
149  Item {
150  QtLayouts.Layout.fillWidth: true
151  }
152  Kirigami.UrlButton {
153  id: authorLabel
154  visible: (url !== "")
155  url: (component.commentAuthor.homepage === "") ? component.commentAuthor.profilepage : component.commentAuthor.homepage
156  text: (component.author === component.entryAuthorId) ? i18ndc("knewstuff5", "The author label in case the comment was written by the author of the content entry the comment is attached to", "%1 <i>(author)</i>", component.commentAuthor.name) : component.commentAuthor.name
157  }
158  QtControls.Label {
159  visible: !authorLabel.visible
160  text: authorLabel.text
161  }
162  Image {
163  id: authorIcon
164  QtLayouts.Layout.maximumWidth: height
165  QtLayouts.Layout.minimumWidth: height
166  QtLayouts.Layout.preferredHeight: Kirigami.Units.iconSizes.medium
167  fillMode: Image.PreserveAspectFit
168  source: component.commentAuthor.avatarUrl
169  Kirigami.Icon {
170  anchors.fill: parent;
171  source: "user"
172  visible: opacity > 0
173  opacity: authorIcon.status == Image.Ready ? 0 : 1
174  Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
175  }
176  }
177  Item {
178  QtLayouts.Layout.minimumWidth: Kirigami.Units.largeSpacing
179  QtLayouts.Layout.maximumWidth: Kirigami.Units.largeSpacing
180  }
181  }
182  Item {
183  QtLayouts.Layout.fillWidth: true
184  QtLayouts.Layout.minimumHeight: Kirigami.Units.largeSpacing
185  QtLayouts.Layout.maximumHeight: Kirigami.Units.largeSpacing
186  }
187 
188  }
189 }
Rating
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
QTextStream & left(QTextStream &s)
QTextStream & right(QTextStream &s)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Aug 9 2020 22:43:40 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.