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