KNewStuff

BigPreviewDelegate.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  actionsAnchors.topMargin: bigPreview.height + Kirigami.Units.smallSpacing * 2
21  function showDetails() {
22  pageStack.push(detailsPage, {
23  newStuffModel: GridView.view.model,
24  index: model.index,
25  name: model.name,
26  author: model.author,
27  previews: model.previews,
28  shortSummary: model.shortSummary,
29  summary: model.summary,
30  homepage: model.homepage,
31  donationLink: model.donationLink,
32  status: model.status,
33  commentsCount: model.numberOfComments,
34  rating: model.rating,
35  downloadCount: model.downloadCount,
36  downloadLinks: model.downloadLinks,
37  providerId: model.providerId
38  });
39  }
40  actions: [
41  Kirigami.Action {
42  text: root.useLabel
43  iconName: "dialog-ok-apply"
44  onTriggered: { model.adoptItem(model.index); }
45  enabled: (model.status == NewStuff.ItemsModel.InstalledStatus || model.status == NewStuff.ItemsModel.UpdateableStatus) && newStuffEngine.hasAdoptionCommand
46  visible: enabled
47  },
48  Kirigami.Action {
49  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...");
50  iconName: "install"
51  onTriggered: {
52  if (model.downloadLinks.length === 1) {
53  newStuffModel.installItem(model.index, NewStuff.ItemsModel.FirstLinkId);
54  } else {
55  downloadItemsSheet.downloadLinks = model.downloadLinks;
56  downloadItemsSheet.entryId = model.index;
57  downloadItemsSheet.open();
58  }
59  }
60  enabled: model.status == NewStuff.ItemsModel.DownloadableStatus || model.status == NewStuff.ItemsModel.DeletedStatus;
61  visible: enabled;
62  },
63  Kirigami.Action {
64  text: i18ndc("knewstuff5", "Request updating of this item", "Update");
65  iconName: "update-none"
66  onTriggered: { newStuffModel.updateItem(model.index); }
67  enabled: model.status == NewStuff.ItemsModel.UpdateableStatus;
68  visible: enabled;
69  },
70  Kirigami.Action {
71  text: root.uninstallLabel
72  iconName: "edit-delete"
73  onTriggered: { newStuffModel.uninstallItem(model.index); }
74  enabled: model.status == NewStuff.ItemsModel.InstalledStatus || model.status == NewStuff.ItemsModel.UpdateableStatus
75  visible: enabled;
76  }
77  ]
78  thumbnailAvailable: model.previewsSmall.length > 0
79  tile: Item {
80  anchors {
81  fill: parent
82  margins: Kirigami.Units.smallSpacing
83  }
84  QtLayouts.ColumnLayout {
85  anchors.fill: parent;
86  Item {
87  QtLayouts.Layout.fillWidth: true
88  QtLayouts.Layout.minimumHeight: width / 1.8
89  QtLayouts.Layout.maximumHeight: width / 1.8
90  Kirigami.ShadowedRectangle {
91  visible: bigPreview.status == Image.Ready
92  anchors.centerIn: bigPreview;
93  width: Math.min(bigPreview.paintedWidth, bigPreview.width);
94  height: Math.min(bigPreview.paintedHeight, bigPreview.height);
95  Kirigami.Theme.colorSet: Kirigami.Theme.View
96  shadow.size: 10
97  shadow.color: Qt.rgba(0, 0, 0, 0.3)
98  }
99  Image {
100  id: bigPreview
101  asynchronous: true;
102  fillMode: Image.PreserveAspectCrop;
103  source: thumbnailAvailable ? model.previews[0] : "";
104  anchors.fill: parent
105  }
106  Kirigami.Icon {
107  id: updateAvailableBadge;
108  opacity: (model.status == NewStuff.ItemsModel.UpdateableStatus) ? 1 : 0;
109  Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
110  anchors {
111  top: parent.top;
112  left: parent.left;
113  margins: -Kirigami.Units.smallSpacing;
114  }
115  height: Kirigami.Units.iconSizes.medium;
116  width: height;
117  source: "package-installed-outdated";
118  }
119  Kirigami.Icon {
120  id: installedBadge;
121  opacity: (model.status == NewStuff.ItemsModel.InstalledStatus) ? 1 : 0;
122  Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
123  anchors {
124  top: parent.top;
125  left: parent.left;
126  }
127  height: Kirigami.Units.iconSizes.medium;
128  width: height;
129  source: "package-installed-updated";
130  }
131  }
132  Private.Rating {
133  QtLayouts.Layout.fillWidth: true
134  rating: model.rating / 10
135  }
136  Kirigami.Heading {
137  QtLayouts.Layout.fillWidth: true
138  level: 5
139  elide: Text.ElideRight
140  text: i18ndc("knewstuff5", "The number of times the item has been downloaded", "%1 downloads", model.downloadCount)
141  }
142  Kirigami.Heading {
143  QtLayouts.Layout.fillWidth: true
144  elide: Text.ElideRight
145  level: 3
146  text: model.name
147  }
148  Kirigami.Heading {
149  QtLayouts.Layout.fillWidth: true
150  elide: Text.ElideRight
151  level: 4
152  textFormat: Text.StyledText
153  text: i18ndc("knewstuff5", "Subheading for the tile view, located immediately underneath the name of the item", "By <i>%1</i>", model.author.name)
154  }
155  QtControls.Label {
156  QtLayouts.Layout.fillWidth: true
157  QtLayouts.Layout.fillHeight: true
158  wrapMode: Text.Wrap
159  text: model.shortSummary.length > 0 ? model.shortSummary : model.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  FeedbackOverlay {
165  anchors.fill: parent
166  newStuffModel: component.GridView.view.model
167  }
168  MouseArea {
169  anchors.fill: parent;
170  cursorShape: Qt.PointingHandCursor;
171  onClicked: component.showDetails();
172  }
173  }
174 }
QString name(const QVariant &location)
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-2020 The KDE developers.
Generated on Tue Aug 11 2020 22:43:23 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.