KNewStuff

EntryCommentDelegate.qml
1/*
2 SPDX-FileCopyrightText: 2019 Dan Leinir Turthra Jensen <admin@leinir.dk>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7/**
8 * @brief A card based delegate for showing a comment from a KNewStuffQuick::QuickCommentsModel
9 */
10
11import QtQuick
12import QtQuick.Controls as QQC2
13import QtQuick.Layouts
15import org.kde.kirigami as Kirigami
16
17import org.kde.newstuff as NewStuff
18
19RowLayout {
20 id: component
21
22 /**
23 * The KNSQuick Engine object which handles all our content
24 */
25 property NewStuff.Engine engine
26
27 /**
28 * The username of the author of whatever the comment is attached to
29 */
30 property string entryAuthorId
31 /**
32 * The provider ID as supplied by the entry the comment is attached to
33 */
34 property string entryProviderId
35
36 /**
37 * The username of the comment's author
38 */
39 property string author
40 /**
41 * The OCS score, an integer from 1 to 100. It will be interpreted
42 * as a 5 star rating, with half star support (0-10)
43 */
44 property int score
45 /**
46 * The title or subject line for the comment
47 */
48 property string title
49 /**
50 * The actual text of the comment
51 */
52 property alias reviewText: reviewLabel.text
53 /**
54 * The depth of the comment (in essence, how many parents the comment has)
55 */
56 property int depth
57
58 spacing: 0
59
60 property NewStuff.Author commentAuthor: NewStuff.Author {
61 engine: component.engine
62 providerId: component.entryProviderId
63 username: component.author
64 }
65
66 Repeater {
67 model: component.depth
68 delegate: Rectangle {
69 Layout.fillHeight: true
70 Layout.minimumWidth: Kirigami.Units.largeSpacing
71 Layout.maximumWidth: Kirigami.Units.largeSpacing
72 color: Qt.tint(Kirigami.Theme.textColor, Qt.alpha(Kirigami.Theme.backgroundColor, 0.8))
73 Rectangle {
74 anchors {
75 top: parent.top
76 bottom: parent.bottom
77 left: parent.left
78 }
79 width: 1
80 color: Kirigami.Theme.backgroundColor
81 }
82 }
83 }
84
85 ColumnLayout {
86 Item {
87 visible: component.depth === 0
88 Layout.fillWidth: true
89 Layout.minimumHeight: Kirigami.Units.largeSpacing
90 Layout.maximumHeight: Kirigami.Units.largeSpacing
91 }
92
93 Kirigami.Separator {
94 Layout.fillWidth: true
95 }
96
97 RowLayout {
98 visible: (component.title !== "" || component.score !== 0)
99 Layout.fillWidth: true
100 Layout.leftMargin: Kirigami.Units.largeSpacing
101 Kirigami.Heading {
102 id: titleLabel
103 text: ((component.title === "") ? i18ndc("knewstuff6", "Placeholder title for when a comment has no subject, but does have a rating", "<i>(no title)</i>") : component.title)
104 level: 4
105 Layout.fillWidth: true
106 }
107 Rating {
108 id: ratingStars
109 rating: component.score
110 reverseLayout: true
111 }
112 Item {
113 Layout.minimumWidth: Kirigami.Units.largeSpacing
114 Layout.maximumWidth: Kirigami.Units.largeSpacing
115 }
116 }
117
118 QQC2.Label {
119 id: reviewLabel
120 Layout.fillWidth: true
121 Layout.leftMargin: Kirigami.Units.largeSpacing
122 Layout.rightMargin: Kirigami.Units.largeSpacing
123 wrapMode: Text.Wrap
124 }
125
126 RowLayout {
127 Layout.fillWidth: true
128 Item {
129 Layout.fillWidth: true
130 }
131 Kirigami.UrlButton {
132 id: authorLabel
133 visible: url !== ""
134 url: (component.commentAuthor.homepage === "") ? component.commentAuthor.profilepage : component.commentAuthor.homepage
135 text: (component.author === component.entryAuthorId)
136 ? i18ndc("knewstuff6", "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)
137 : component.commentAuthor.name
138 }
139 QQC2.Label {
140 visible: !authorLabel.visible
141 text: authorLabel.text
142 }
143 Image {
144 id: authorIcon
145 Layout.maximumWidth: height
146 Layout.minimumWidth: height
147 Layout.preferredHeight: Kirigami.Units.iconSizes.medium
148 fillMode: Image.PreserveAspectFit
149 source: component.commentAuthor.avatarUrl
150 Kirigami.Icon {
151 anchors.fill: parent
152 source: "user"
153 visible: opacity > 0
154 opacity: authorIcon.status === Image.Ready ? 0 : 1
155 Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
156 }
157 }
158 Item {
159 Layout.minimumWidth: Kirigami.Units.largeSpacing
160 Layout.maximumWidth: Kirigami.Units.largeSpacing
161 }
162 }
163 Item {
164 Layout.fillWidth: true
165 Layout.minimumHeight: Kirigami.Units.largeSpacing
166 Layout.maximumHeight: Kirigami.Units.largeSpacing
167 }
168 }
169}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:02:29 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.