Changeset View
Changeset View
Standalone View
Standalone View
src/qtquick/qml/EntryCommentDelegate.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Dan Leinir Turthra Jensen <admin@leinir.dk> | ||||
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 | | ||||
22 | /** | ||||
23 | * @brief A card based delegate for showing a comment from a KNewStuffQuick::QuickCommentsModel | ||||
24 | */ | ||||
25 | | ||||
26 | import QtQuick 2.7 | ||||
27 | | ||||
28 | import org.kde.kirigami 2.7 as Kirigami | ||||
29 | import QtQuick.Controls 2.5 as QtControls | ||||
30 | import QtQuick.Layouts 1.12 as QtLayouts | ||||
31 | | ||||
32 | Kirigami.AbstractCard { | ||||
33 | id: component | ||||
34 | | ||||
35 | /** | ||||
36 | * The KNSQuick Engine object which handles all our content | ||||
37 | */ | ||||
38 | property QtObject engine | ||||
39 | | ||||
40 | /** | ||||
41 | * The username of the author of whatever the comment is attached to | ||||
42 | */ | ||||
43 | property string entryAuthor | ||||
44 | /** | ||||
45 | * The provider ID as supplied by the entry the comment is attached to | ||||
46 | */ | ||||
47 | property string entryProviderId | ||||
48 | | ||||
49 | /** | ||||
50 | * The username of the comment's author | ||||
51 | */ | ||||
52 | property string author | ||||
53 | /** | ||||
54 | * The OCS score, an integer from 1 to 100. It will be interpreted | ||||
55 | * as a 5 star rating, with half star support (0-10) | ||||
56 | */ | ||||
57 | property int score | ||||
58 | /** | ||||
59 | * The title or subject line for the comment | ||||
60 | */ | ||||
61 | property string title | ||||
62 | /** | ||||
63 | * The actual text of the comment | ||||
64 | */ | ||||
65 | property alias reviewText: reviewLabel.text | ||||
66 | /** | ||||
67 | * The depth of the comment (in essence, how many parents the comment has) | ||||
68 | */ | ||||
69 | property int depth | ||||
70 | | ||||
71 | anchors { | ||||
72 | left: parent.left | ||||
73 | right: parent.right | ||||
74 | margins: Kirigami.Units.largeSpacing | ||||
75 | leftMargin: Kirigami.Units.largeSpacing + Kirigami.Units.largeSpacing * component.depth | ||||
76 | } | ||||
77 | | ||||
78 | header: (component.title === "" && component.score === 0) ? null : headerLayout | ||||
79 | property Item headerLayout: QtLayouts.RowLayout { | ||||
80 | Kirigami.Heading { | ||||
81 | id: titleLabel | ||||
82 | text: (component.title === "") ? i18nc("Placeholder title for when a comment has no subject, but does have a rating", "<i>(no title)</i>") : component.title | ||||
83 | level: 4 | ||||
84 | QtLayouts.Layout.fillWidth: true | ||||
85 | } | ||||
86 | Rating { | ||||
87 | id: ratingStars | ||||
88 | rating: Math.floor(component.score / 10) | ||||
89 | } | ||||
90 | } | ||||
91 | | ||||
92 | contentItem: QtControls.Label { | ||||
93 | id: reviewLabel | ||||
94 | anchors { | ||||
95 | left: parent.left; | ||||
96 | right: parent.right | ||||
97 | } | ||||
98 | wrapMode: Text.Wrap | ||||
99 | } | ||||
100 | | ||||
101 | footer: QtLayouts.RowLayout { | ||||
102 | Item { | ||||
103 | QtLayouts.Layout.fillWidth: true | ||||
104 | } | ||||
105 | Kirigami.Icon { | ||||
106 | id: authorIcon | ||||
107 | QtLayouts.Layout.maximumWidth: height | ||||
108 | QtLayouts.Layout.minimumWidth: height | ||||
109 | QtLayouts.Layout.preferredHeight: Kirigami.Units.iconSizes.medium | ||||
110 | source: "user" | ||||
111 | // source: engine.provider(entry.providerId).baseUrl() + "/user/avatar/" + component.author | ||||
112 | } | ||||
113 | Kirigami.UrlButton { | ||||
114 | id: authorLabel | ||||
115 | // url: engine.provider(component.entryProviderId).baseUrl() + "/profile/" + component.author | ||||
116 | text: (component.author === component.entryAuthor) ? i18nc("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>").arg(component.author) : component.author | ||||
117 | } | ||||
118 | } | ||||
119 | } |