KNewStuff

EntryCommentDelegate.qml
1 /*
2  SPDX-FileCopyrightText: 2019 Dan Leinir Turthra Jensen <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 
11 import QtQuick 2.11
12 import QtQuick.Controls 2.11 as QtControls
13 import QtQuick.Layouts 1.11 as QtLayouts
14 
15 import org.kde.kirigami 2.7 as Kirigami
16 
17 import org.kde.newstuff 1.62 as NewStuff
18 
19 QtLayouts.RowLayout {
20  id: component
21 
25  property QtObject engine
26 
30  property string entryAuthorId
34  property string entryProviderId
35 
39  property string author
44  property int score
48  property string title
52  property alias reviewText: reviewLabel.text
56  property int depth
57 
58  spacing: 0
59 
60  property QtObject commentAuthor: NewStuff.Author {
61  engine: component.engine
62  providerId: component.entryProviderId
63  username: component.author
64  }
65 
66  anchors {
67  left: parent.left
68  right: parent.right
69  leftMargin: Kirigami.Units.largeSpacing
70  rightMargin: Kirigami.Units.largeSpacing
71  }
72 
73  Repeater {
74  model: component.depth
75  delegate: Rectangle {
76  QtLayouts.Layout.fillHeight: true
77  QtLayouts.Layout.minimumWidth: Kirigami.Units.largeSpacing
78  QtLayouts.Layout.maximumWidth: Kirigami.Units.largeSpacing
79  color: Qt.tint(Kirigami.Theme.textColor, Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.8))
80  Rectangle {
81  anchors {
82  top: parent.top
83  bottom: parent.bottom
84  left: parent.left
85  }
86  width: 1
87  color: Kirigami.Theme.backgroundColor
88  }
89  }
90  }
91 
92  QtLayouts.ColumnLayout {
93  Item {
94  visible: component.depth === 0
95  QtLayouts.Layout.fillWidth: true
96  QtLayouts.Layout.minimumHeight: Kirigami.Units.largeSpacing
97  QtLayouts.Layout.maximumHeight: Kirigami.Units.largeSpacing
98  }
99 
100  Kirigami.Separator {
101  QtLayouts.Layout.fillWidth: true
102  }
103 
104  QtLayouts.RowLayout {
105  visible: (component.title !== "" || component.score !== 0)
106  QtLayouts.Layout.fillWidth: true
107  QtLayouts.Layout.leftMargin: Kirigami.Units.largeSpacing
108  Kirigami.Heading {
109  id: titleLabel
110  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)
111  level: 4
112  QtLayouts.Layout.fillWidth: true
113  }
114  Rating {
115  id: ratingStars
116  rating: Math.floor(component.score / 10)
117  }
118  Item {
119  QtLayouts.Layout.minimumWidth: Kirigami.Units.largeSpacing
120  QtLayouts.Layout.maximumWidth: Kirigami.Units.largeSpacing
121  }
122  }
123 
124  QtControls.Label {
125  id: reviewLabel
126  QtLayouts.Layout.fillWidth: true
127  QtLayouts.Layout.leftMargin: Kirigami.Units.largeSpacing
128  QtLayouts.Layout.rightMargin: Kirigami.Units.largeSpacing
129  wrapMode: Text.Wrap
130  }
131 
132  QtLayouts.RowLayout {
133  QtLayouts.Layout.fillWidth: true
134  Item {
135  QtLayouts.Layout.fillWidth: true
136  }
137  Kirigami.UrlButton {
138  id: authorLabel
139  visible: (url !== "")
140  url: (component.commentAuthor.homepage === "") ? component.commentAuthor.profilepage : component.commentAuthor.homepage
141  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
142  }
143  QtControls.Label {
144  visible: !authorLabel.visible
145  text: authorLabel.text
146  }
147  Image {
148  id: authorIcon
149  QtLayouts.Layout.maximumWidth: height
150  QtLayouts.Layout.minimumWidth: height
151  QtLayouts.Layout.preferredHeight: Kirigami.Units.iconSizes.medium
152  fillMode: Image.PreserveAspectFit
153  source: component.commentAuthor.avatarUrl
154  Kirigami.Icon {
155  anchors.fill: parent;
156  source: "user"
157  visible: opacity > 0
158  opacity: authorIcon.status == Image.Ready ? 0 : 1
159  Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
160  }
161  }
162  Item {
163  QtLayouts.Layout.minimumWidth: Kirigami.Units.largeSpacing
164  QtLayouts.Layout.maximumWidth: Kirigami.Units.largeSpacing
165  }
166  }
167  Item {
168  QtLayouts.Layout.fillWidth: true
169  QtLayouts.Layout.minimumHeight: Kirigami.Units.largeSpacing
170  QtLayouts.Layout.maximumHeight: Kirigami.Units.largeSpacing
171  }
172 
173  }
174 }
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-2021 The KDE developers.
Generated on Mon Jan 18 2021 22:43:49 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.