KNewStuff

BigPreviewDelegate.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 actionsAnchors.topMargin: bigPreview.height + Kirigami.Units.smallSpacing * 2
21 function showDetails() {
22 pageStack.push(detailsPage, {
23 newStuffModel: GridView.view.model,
24 entry: model.entry,
25 });
26 }
27 actions: [
28 Kirigami.Action {
29 text: root.useLabel
30 icon.name: "dialog-ok-apply"
31 onTriggered: { newStuffModel.adoptEntry(model.entry); }
32 enabled: (entry.status === NewStuff.Entry.Installed || entry.status === NewStuff.Entry.Updateable) && newStuffEngine.hasAdoptionCommand
33 visible: enabled
34 },
36 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…");
37 icon.name: "install"
38 onTriggered: {
39 if (model.downloadLinks.length === 1) {
40 newStuffModel.engine.install(model.entry, NewStuff.ItemsModel.FirstLinkId);
41 } else {
42 downloadItemsSheet.downloadLinks = model.downloadLinks;
43 downloadItemsSheet.entry = model.entry;
44 downloadItemsSheet.open();
45 }
46 }
47 enabled: entry.status === NewStuff.Entry.Downloadable || entry.status === NewStuff.Entry.Deleted
48 visible: enabled
49 },
50 Kirigami.Action {
51 text: i18ndc("knewstuff6", "Request updating of this item", "Update");
52 icon.name: "update-none"
53 onTriggered: { newStuffModel.engine.install(model.index, NewStuff.ItemsModel.AutoDetectLinkId); }
54 enabled: entry.status === NewStuff.Entry.Updateable
55 visible: enabled
56 },
57 Kirigami.Action {
58 text: root.uninstallLabel
59 icon.name: "edit-delete"
60 onTriggered: { newStuffModel.engine.uninstall(model.entry); }
61 enabled: entry.status === NewStuff.Entry.Installed || entry.status === NewStuff.Entry.Updateable
62 visible: enabled
63 }
64 ]
65 thumbnailArea: bigPreview
66 thumbnailAvailable: model.previewsSmall.length > 0
67 tile: Item {
68 anchors {
69 fill: parent
70 margins: Kirigami.Units.smallSpacing
71 }
72 QtLayouts.ColumnLayout {
73 anchors.fill: parent;
74 Item {
75 QtLayouts.Layout.fillWidth: true
76 QtLayouts.Layout.fillHeight: true
77 QtLayouts.Layout.minimumHeight: width / 5
78 QtLayouts.Layout.maximumHeight: width / 1.8
79 Kirigami.ShadowedRectangle {
80 visible: bigPreview.status == Image.Ready
81 anchors.centerIn: bigPreview;
82 width: Math.min(bigPreview.paintedWidth, bigPreview.width);
83 height: Math.min(bigPreview.paintedHeight, bigPreview.height);
84 Kirigami.Theme.colorSet: Kirigami.Theme.View
85 shadow.size: 10
86 shadow.color: Qt.rgba(0, 0, 0, 0.3)
87 }
88 Image {
89 id: bigPreview
90 asynchronous: true;
91 fillMode: Image.PreserveAspectCrop;
92 source: thumbnailAvailable ? model.previews[0] : "";
93 anchors.fill: parent
94 }
95 Kirigami.Icon {
97 opacity: (entry.status == NewStuff.Entry.Updateable) ? 1 : 0;
98 Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
99 anchors {
100 top: parent.top;
101 left: parent.left;
102 }
103 height: Kirigami.Units.iconSizes.medium;
104 width: height;
105 source: "package-installed-outdated";
106 }
107 Kirigami.Icon {
108 id: installedBadge;
109 opacity: (entry.status === NewStuff.Entry.Installed) ? 1 : 0;
110 Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
111 anchors {
112 top: parent.top;
113 left: parent.left;
114 }
115 height: Kirigami.Units.iconSizes.medium;
116 width: height;
117 source: "package-installed-updated";
118 }
119 }
120 Private.Rating {
121 QtLayouts.Layout.fillWidth: true
122 rating: model.rating
123 }
124 Kirigami.Heading {
125 QtLayouts.Layout.fillWidth: true
126 level: 5
127 elide: Text.ElideRight
128 text: i18ndc("knewstuff6", "The number of times the item has been downloaded", "%1 downloads", model.downloadCount)
129 }
130 Kirigami.Heading {
131 QtLayouts.Layout.fillWidth: true
132 elide: Text.ElideRight
133 level: 3
134 text: model.name
135 }
136 Kirigami.Heading {
137 QtLayouts.Layout.fillWidth: true
138 elide: Text.ElideRight
139 level: 4
140 textFormat: Text.StyledText
141 text: i18ndc("knewstuff6", "Subheading for the tile view, located immediately underneath the name of the item", "By <i>%1</i>", model.author.name)
142 }
143 QtControls.Label {
144 QtLayouts.Layout.fillWidth: true
145 QtLayouts.Layout.fillHeight: true
146 QtLayouts.Layout.minimumHeight: Kirigami.Units.gridUnit
147 QtLayouts.Layout.maximumHeight: Kirigami.Units.gridUnit * 3
148 wrapMode: Text.Wrap
149 text: model.shortSummary.length > 0 ? model.shortSummary : model.summary
150 elide: Text.ElideRight
151 }
152 clip: true // We are dealing with content over which we have very little control. Sometimes that means being a bit abrupt.
153 }
154 FeedbackOverlay {
155 anchors.fill: parent
156 newStuffModel: component.GridView.view.model
157 }
158 MouseArea {
159 anchors.fill: parent;
160 cursorShape: Qt.PointingHandCursor;
161 onClicked: component.showDetails();
162 }
163 }
164}
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.