KNewStuff

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

KDE's Doxygen guidelines are available online.