KNewStuff

TileDelegate.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
7import QtQuick
8import QtQuick.Controls as QQC2
9import QtQuick.Layouts
10
11import org.kde.kirigami as Kirigami
12
13import org.kde.newstuff as NewStuff
14
15import ".." as Private
16
17Private.GridTileDelegate {
18 id: component
19
20 property var entry: model.entry
21 property string useLabel
22 property string uninstallLabel
23
24 function showDetails() {
25 if (entry.entryType === NewStuff.Entry.GroupEntry) {
26 newStuffEngine.storeSearch();
27 newStuffEngine.searchTerm = model.payload;
28 } else {
29 pageStack.push(detailsPage, {
30 newStuffModel: GridView.view.model,
31 entry,
32 });
33 }
34 }
35
36 actions: [
37 Kirigami.Action {
38 text: component.useLabel
39 icon.name: "dialog-ok-apply"
40 onTriggered: source => {
41 newStuffModel.engine.adoptEntry(model.entry);
42 }
43 enabled: (entry.status === NewStuff.Entry.Installed || entry.status === NewStuff.Entry.Updateable) && newStuffEngine.hasAdoptionCommand
44 visible: enabled
45 },
47 text: model.downloadLinks.length === 1
48 ? i18ndc("knewstuff6", "Request installation of this item, available when there is exactly one downloadable item", "Install")
49 : i18ndc("knewstuff6", "Show installation options, where there is more than one downloadable item", "Install…")
50 icon.name: "install"
51 onTriggered: source => {
52 if (model.downloadLinks.length === 1) {
53 newStuffEngine.installLinkId(entry, NewStuff.ItemsModel.FirstLinkId);
54 } else {
55 downloadItemsSheet.downloadLinks = model.downloadLinks;
56 downloadItemsSheet.entry = entry;
57 downloadItemsSheet.open();
58 }
59 }
60 enabled: entry.status === NewStuff.Entry.Downloadable || entry.status === NewStuff.Entry.Deleted
61 visible: enabled
62 },
63 Kirigami.Action {
64 text: i18ndc("knewstuff6", "Request updating of this item", "Update")
65 icon.name: "update-none"
66 onTriggered: source => {
67 newStuffEngine.installLatest(entry);
68 }
69 enabled: entry.status === NewStuff.Entry.Updateable
70 visible: enabled
71 },
72 Kirigami.Action {
73 text: component.uninstallLabel
74 icon.name: "edit-delete"
75 onTriggered: source => {
76 newStuffEngine.uninstall(model.entry);
77 }
78 enabled: entry.status === NewStuff.Entry.Installed || entry.status === NewStuff.Entry.Updateable
79 visible: enabled && hovered
80 }
81 ]
82 thumbnailArea: tilePreview
83 thumbnailAvailable: model.previewsSmall.length > 0
84 tile: Item {
85 anchors {
86 fill: parent
87 margins: Kirigami.Units.smallSpacing
88 }
89 GridLayout {
90 anchors.fill: parent
91 columns: 2
92 ColumnLayout {
93 Layout.minimumWidth: view.implicitCellWidth / 5
94 Layout.maximumWidth: view.implicitCellWidth / 5
95 Item {
96 Layout.fillWidth: true
97 Layout.minimumHeight: width
98 Layout.maximumHeight: width
99 Kirigami.ShadowedRectangle {
100 visible: tilePreview.status === Image.Ready
101 anchors.centerIn: tilePreview
102 width: Math.min(tilePreview.paintedWidth, tilePreview.width)
103 height: Math.min(tilePreview.paintedHeight, tilePreview.height)
104 Kirigami.Theme.colorSet: Kirigami.Theme.View
105 shadow.size: Kirigami.Units.largeSpacing
106 shadow.color: Qt.rgba(0, 0, 0, 0.3)
107 }
108 Image {
109 id: tilePreview
110 asynchronous: true
111 fillMode: Image.PreserveAspectFit
112 source: thumbnailAvailable ? model.previewsSmall[0] : ""
113 anchors {
114 fill: parent
115 margins: Kirigami.Units.smallSpacing
116 }
117 verticalAlignment: Image.AlignTop
118 }
119 Kirigami.Icon {
120 id: updateAvailableBadge
121 opacity: (entry.status === NewStuff.Entry.Updateable) ? 1 : 0
122 Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration } }
123 anchors {
124 top: parent.top
125 left: parent.left
126 margins: -Kirigami.Units.smallSpacing
127 }
128 height: Kirigami.Units.iconSizes.smallMedium
129 width: height
130 source: "package-installed-outdated"
131 }
132 Kirigami.Icon {
133 id: installedBadge
134 opacity: (entry.status === NewStuff.Entry.Installed) ? 1 : 0
135 Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration } }
136 anchors {
137 top: parent.top
138 left: parent.left
139 margins: -Kirigami.Units.smallSpacing
140 }
141 height: Kirigami.Units.iconSizes.smallMedium
142 width: height
143 source: "package-installed-updated"
144 }
145 }
146 Item {
147 Layout.fillHeight: true
148 }
149 }
150 ColumnLayout {
151 Layout.fillWidth: true
152 Layout.fillHeight: true
154 Layout.fillWidth: true
155 elide: Text.ElideRight
156 level: 3
157 text: entry.name
158 }
160 Layout.fillWidth: true
161 elide: Text.ElideRight
162 level: 4
163 textFormat: Text.StyledText
164 text: i18ndc("knewstuff6", "Subheading for the tile view, located immediately underneath the name of the item", "By <i>%1</i>", entry.author.name)
165 }
166 QQC2.Label {
167 Layout.fillWidth: true
168 Layout.fillHeight: true
169 wrapMode: Text.Wrap
170 text: entry.shortSummary.length > 0 ? entry.shortSummary : entry.summary
171 elide: Text.ElideRight
172 clip: true // We are dealing with content over which we have very little control. Sometimes that means being a bit abrupt.
173 }
174 }
175 Private.Rating {
176 Layout.fillWidth: true
177 rating: entry.rating
178 visible: entry.entryType === NewStuff.Entry.CatalogEntry
179 }
181 Layout.fillWidth: true
182 horizontalAlignment: Text.AlignRight
183 level: 5
184 elide: Text.ElideRight
185 text: i18ndc("knewstuff6", "The number of times the item has been downloaded", "%1 downloads", entry.downloadCount)
186 visible: entry.entryType === NewStuff.Entry.CatalogEntry
187 }
188 }
189 FeedbackOverlay {
190 anchors.fill: parent
191 newStuffModel: component.GridView.view.model
192 }
193 MouseArea {
194 anchors.fill: parent
195 cursorShape: Qt.PointingHandCursor
196 onClicked: mouse => {
197 component.showDetails();
198 }
199 }
200 }
201}
alias view
Q_SCRIPTABLE CaptureState status()
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
QStringView level(QStringView ifopt)
QString name(StandardAction id)
AlignRight
PointingHandCursor
ElideRight
QTextStream & left(QTextStream &stream)
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.