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 2.11
12import QtQuick.Controls 2.11 as QtControls
13import QtQuick.Layouts 1.11 as QtLayouts
15import org.kde.kirigami 2.7 as Kirigami
16
17import org.kde.newstuff 1.62 as NewStuff
18
19QtLayouts.RowLayout {
20 id: component
21
22 /**
23 * The KNSQuick Engine object which handles all our content
24 */
25 property QtObject 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 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("knewstuff6", "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: component.score
117 reverseLayout: true
118 }
119 Item {
120 QtLayouts.Layout.minimumWidth: Kirigami.Units.largeSpacing
121 QtLayouts.Layout.maximumWidth: Kirigami.Units.largeSpacing
122 }
123 }
124
125 QtControls.Label {
126 id: reviewLabel
127 QtLayouts.Layout.fillWidth: true
128 QtLayouts.Layout.leftMargin: Kirigami.Units.largeSpacing
129 QtLayouts.Layout.rightMargin: Kirigami.Units.largeSpacing
130 wrapMode: Text.Wrap
131 }
132
133 QtLayouts.RowLayout {
134 QtLayouts.Layout.fillWidth: true
135 Item {
136 QtLayouts.Layout.fillWidth: true
137 }
138 Kirigami.UrlButton {
139 id: authorLabel
140 visible: (url !== "")
141 url: (component.commentAuthor.homepage === "") ? component.commentAuthor.profilepage : component.commentAuthor.homepage
142 text: (component.author === component.entryAuthorId) ? 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) : component.commentAuthor.name
143 }
144 QtControls.Label {
145 visible: !authorLabel.visible
146 text: authorLabel.text
147 }
148 Image {
149 id: authorIcon
150 QtLayouts.Layout.maximumWidth: height
151 QtLayouts.Layout.minimumWidth: height
152 QtLayouts.Layout.preferredHeight: Kirigami.Units.iconSizes.medium
153 fillMode: Image.PreserveAspectFit
154 source: component.commentAuthor.avatarUrl
155 Kirigami.Icon {
156 anchors.fill: parent;
157 source: "user"
158 visible: opacity > 0
159 opacity: authorIcon.status == Image.Ready ? 0 : 1
160 Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
161 }
162 }
163 Item {
164 QtLayouts.Layout.minimumWidth: Kirigami.Units.largeSpacing
165 QtLayouts.Layout.maximumWidth: Kirigami.Units.largeSpacing
166 }
167 }
168 Item {
169 QtLayouts.Layout.fillWidth: true
170 QtLayouts.Layout.minimumHeight: Kirigami.Units.largeSpacing
171 QtLayouts.Layout.maximumHeight: Kirigami.Units.largeSpacing
172 }
173
174 }
175}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:35 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.