Changeset View
Changeset View
Standalone View
Standalone View
src/qtquick/qml/private/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 | import org.kde.newstuff 1.1 as NewStuff | ||||
32 | | ||||
33 | Kirigami.AbstractCard { | ||||
34 | id: component | ||||
35 | | ||||
36 | /** | ||||
37 | * The KNSQuick Engine object which handles all our content | ||||
38 | */ | ||||
39 | property QtObject engine | ||||
40 | | ||||
41 | /** | ||||
42 | * The username of the author of whatever the comment is attached to | ||||
43 | */ | ||||
44 | property string entryAuthorId | ||||
45 | /** | ||||
46 | * The provider ID as supplied by the entry the comment is attached to | ||||
47 | */ | ||||
48 | property string entryProviderId | ||||
49 | | ||||
50 | /** | ||||
51 | * The username of the comment's author | ||||
52 | */ | ||||
53 | property string author | ||||
54 | /** | ||||
55 | * The OCS score, an integer from 1 to 100. It will be interpreted | ||||
56 | * as a 5 star rating, with half star support (0-10) | ||||
57 | */ | ||||
58 | property int score | ||||
59 | /** | ||||
60 | * The title or subject line for the comment | ||||
61 | */ | ||||
62 | property string title | ||||
63 | /** | ||||
64 | * The actual text of the comment | ||||
65 | */ | ||||
66 | property alias reviewText: reviewLabel.text | ||||
67 | /** | ||||
68 | * The depth of the comment (in essence, how many parents the comment has) | ||||
69 | */ | ||||
70 | property int depth | ||||
71 | | ||||
72 | property QtObject commentAuthor: NewStuff.Author { | ||||
73 | engine: component.engine | ||||
74 | providerId: component.entryProviderId | ||||
75 | username: component.author | ||||
76 | } | ||||
77 | | ||||
78 | anchors { | ||||
79 | left: parent.left | ||||
80 | right: parent.right | ||||
81 | margins: Kirigami.Units.largeSpacing | ||||
82 | leftMargin: Kirigami.Units.largeSpacing + Kirigami.Units.largeSpacing * component.depth | ||||
83 | } | ||||
84 | | ||||
85 | header: (component.title === "" && component.score === 0) ? null : headerLayout | ||||
86 | property Item headerLayout: QtLayouts.RowLayout { | ||||
87 | Kirigami.Heading { | ||||
88 | id: titleLabel | ||||
89 | text: ((component.title === "") ? i18nc("Placeholder title for when a comment has no subject, but does have a rating", "<i>(no title)</i>") : component.title) | ||||
90 | level: 4 | ||||
91 | QtLayouts.Layout.fillWidth: true | ||||
92 | } | ||||
93 | Rating { | ||||
94 | id: ratingStars | ||||
95 | rating: Math.floor(component.score / 10) | ||||
96 | } | ||||
97 | } | ||||
98 | | ||||
99 | contentItem: QtControls.Label { | ||||
100 | id: reviewLabel | ||||
101 | anchors { | ||||
102 | left: parent.left; | ||||
103 | right: parent.right | ||||
104 | } | ||||
105 | wrapMode: Text.Wrap | ||||
106 | } | ||||
107 | | ||||
108 | footer: QtLayouts.RowLayout { | ||||
109 | Item { | ||||
110 | QtLayouts.Layout.fillWidth: true | ||||
111 | } | ||||
112 | Image { | ||||
113 | id: authorIcon | ||||
114 | QtLayouts.Layout.maximumWidth: height | ||||
115 | QtLayouts.Layout.minimumWidth: height | ||||
116 | QtLayouts.Layout.preferredHeight: Kirigami.Units.iconSizes.medium | ||||
117 | fillMode: Image.PreserveAspectFit | ||||
118 | source: component.commentAuthor.avatarUrl | ||||
119 | Kirigami.Icon { | ||||
120 | anchors.fill: parent; | ||||
121 | source: "user" | ||||
122 | visible: opacity > 0 | ||||
123 | opacity: component.commentAuthor.avatarUrl.toString() === "" ? 1 : 0 | ||||
124 | Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } } | ||||
125 | } | ||||
126 | } | ||||
127 | Kirigami.UrlButton { | ||||
128 | id: authorLabel | ||||
129 | visible: (url !== "") | ||||
130 | url: (component.commentAuthor.homepage === "") ? component.commentAuthor.profilepage : component.commentAuthor.homepage | ||||
131 | text: (component.author === component.entryAuthorId) ? 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.commentAuthor.name) : component.commentAuthor.name | ||||
132 | } | ||||
133 | QtControls.Label { | ||||
134 | visible: !authorLabel.visible | ||||
135 | text: authorLabel.text | ||||
136 | } | ||||
137 | } | ||||
138 | } |