KNewStuff

TileDelegate.qml
1 /*
2  SPDX-FileCopyrightText: 2019 Dan Leinir Turthra Jensen <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 
7 import QtQuick 2.11
8 import QtQuick.Controls 2.11 as QtControls
9 import QtQuick.Layouts 1.11 as QtLayouts
10 import QtGraphicalEffects 1.11 as QtEffects
11 
12 import org.kde.kirigami 2.12 as Kirigami
13 
14 import org.kde.newstuff 1.62 as NewStuff
15 
16 import ".." as Private
17 
18 Private.GridTileDelegate {
19  id: component
20  property string useLabel
21  property string uninstallLabel
22  function showDetails() {
23  pageStack.push(detailsPage, {
24  newStuffModel: GridView.view.model,
25  index: model.index,
26  name: model.name,
27  author: model.author,
28  previews: model.previews,
29  shortSummary: model.shortSummary,
30  summary: model.summary,
31  homepage: model.homepage,
32  donationLink: model.donationLink,
33  status: model.status,
34  commentsCount: model.numberOfComments,
35  rating: model.rating,
36  downloadCount: model.downloadCount,
37  downloadLinks: model.downloadLinks,
38  providerId: model.providerId
39  });
40  }
41  actions: [
42  Kirigami.Action {
43  text: component.useLabel
44  iconName: "dialog-ok-apply"
45  onTriggered: { newStuffModel.adoptItem(model.index); }
46  enabled: (model.status == NewStuff.ItemsModel.InstalledStatus || model.status == NewStuff.ItemsModel.UpdateableStatus) && newStuffEngine.hasAdoptionCommand
47  visible: enabled
48  },
49  Kirigami.Action {
50  text: model.downloadLinks.length === 1 ? i18ndc("knewstuff5", "Request installation of this item, available when there is exactly one downloadable item", "Install") : i18ndc("knewstuff5", "Show installation options, where there is more than one downloadable item", "Install...");
51  iconName: "install"
52  onTriggered: {
53  if (model.downloadLinks.length === 1) {
54  newStuffModel.installItem(model.index, NewStuff.ItemsModel.FirstLinkId);
55  } else {
56  downloadItemsSheet.downloadLinks = model.downloadLinks;
57  downloadItemsSheet.entryId = model.index;
58  downloadItemsSheet.open();
59  }
60  }
61  enabled: model.status == NewStuff.ItemsModel.DownloadableStatus || model.status == NewStuff.ItemsModel.DeletedStatus;
62  visible: enabled;
63  },
64  Kirigami.Action {
65  text: i18ndc("knewstuff5", "Request updating of this item", "Update");
66  iconName: "update-none"
67  onTriggered: { newStuffModel.updateItem(model.index); }
68  enabled: model.status == NewStuff.ItemsModel.UpdateableStatus;
69  visible: enabled;
70  },
71  Kirigami.Action {
72  text: component.uninstallLabel
73  iconName: "edit-delete"
74  onTriggered: { newStuffModel.uninstallItem(model.index); }
75  enabled: model.status == NewStuff.ItemsModel.InstalledStatus || model.status == NewStuff.ItemsModel.UpdateableStatus
76  visible: enabled && hovered;
77  }
78  ]
79  thumbnailAvailable: model.previewsSmall.length > 0
80  tile: Item {
81  anchors {
82  fill: parent
83  margins: Kirigami.Units.smallSpacing
84  }
85  QtLayouts.GridLayout {
86  anchors.fill: parent;
87  columns: 2
88  QtLayouts.ColumnLayout {
89  QtLayouts.Layout.minimumWidth: view.implicitCellWidth / 5
90  QtLayouts.Layout.maximumWidth: view.implicitCellWidth / 5
91  Item {
92  QtLayouts.Layout.fillWidth: true
93  QtLayouts.Layout.minimumHeight: width
94  QtLayouts.Layout.maximumHeight: width
95  Kirigami.ShadowedRectangle {
96  visible: tilePreview.status == Image.Ready
97  anchors.centerIn: tilePreview;
98  width: Math.min(tilePreview.paintedWidth, tilePreview.width);
99  height: Math.min(tilePreview.paintedHeight, tilePreview.height);
100  Kirigami.Theme.colorSet: Kirigami.Theme.View
101  shadow.size: Kirigami.Units.largeSpacing
102  shadow.color: Qt.rgba(0, 0, 0, 0.3)
103  }
104  Image {
105  id: tilePreview
106  asynchronous: true;
107  fillMode: Image.PreserveAspectFit;
108  source: thumbnailAvailable ? model.previewsSmall[0] : "";
109  anchors {
110  fill: parent
111  margins: Kirigami.Units.smallSpacing
112  }
113  verticalAlignment: Image.AlignTop
114  }
115  Kirigami.Icon {
116  id: updateAvailableBadge;
117  opacity: (model.status == NewStuff.ItemsModel.UpdateableStatus) ? 1 : 0;
118  Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
119  anchors {
120  top: parent.top;
121  left: parent.left;
122  margins: -Kirigami.Units.smallSpacing;
123  }
124  height: Kirigami.Units.iconSizes.smallMedium;
125  width: height;
126  source: "package-installed-outdated";
127  }
128  Kirigami.Icon {
129  id: installedBadge;
130  opacity: (model.status == NewStuff.ItemsModel.InstalledStatus) ? 1 : 0;
131  Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
132  anchors {
133  top: parent.top;
134  left: parent.left;
135  margins: -Kirigami.Units.smallSpacing;
136  }
137  height: Kirigami.Units.iconSizes.smallMedium;
138  width: height;
139  source: "package-installed-updated";
140  }
141  }
142  Item {
143  QtLayouts.Layout.fillHeight: true
144  }
145  }
146  QtLayouts.ColumnLayout {
147  QtLayouts.Layout.fillWidth: true
148  QtLayouts.Layout.fillHeight: true
149  Kirigami.Heading {
150  QtLayouts.Layout.fillWidth: true
151  elide: Text.ElideRight
152  level: 3
153  text: model.name
154  }
155  Kirigami.Heading {
156  QtLayouts.Layout.fillWidth: true
157  elide: Text.ElideRight
158  level: 4
159  textFormat: Text.StyledText
160  text: i18ndc("knewstuff5", "Subheading for the tile view, located immediately underneath the name of the item", "By <i>%1</i>", model.author.name)
161  }
162  QtControls.Label {
163  QtLayouts.Layout.fillWidth: true
164  QtLayouts.Layout.fillHeight: true
165  wrapMode: Text.Wrap
166  text: model.shortSummary.length > 0 ? model.shortSummary : model.summary
167  elide: Text.ElideRight
168  clip: true // We are dealing with content over which we have very little control. Sometimes that means being a bit abrupt.
169  }
170  }
171  Private.Rating {
172  QtLayouts.Layout.fillWidth: true
173  rating: model.rating / 10
174  }
175  Kirigami.Heading {
176  QtLayouts.Layout.fillWidth: true
177  level: 5
178  elide: Text.ElideRight
179  text: i18ndc("knewstuff5", "The number of times the item has been downloaded", "%1 downloads", model.downloadCount)
180  }
181  }
182  FeedbackOverlay {
183  anchors.fill: parent
184  newStuffModel: component.GridView.view.model
185  }
186  MouseArea {
187  anchors.fill: parent;
188  cursorShape: Qt.PointingHandCursor;
189  onClicked: component.showDetails();
190  }
191  }
192 }
QString name(const QVariant &location)
QString & fill(QChar ch, int size)
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
QTextStream & left(QTextStream &stream)
QTextStream & left(QTextStream &s)
Base delegate for KControlmodules based on Grid views of thumbnails Use the onClicked signal handler ...
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 18 2021 22:43:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.