Changeset View
Changeset View
Standalone View
Standalone View
src/qtquick/qml/private/entrygriddelegates/TileDelegate.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Dan Leinir Turthra Jensen <admin@leinir.dk> | ||||
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.7 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.adopt(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.downloadCount == 1 ? i18nc("Request installation of this item, available when there is exactly one downloadable item", "Install") : i18nc("Show installation options, where there is more than one downloadable item", "Install..."); | ||||
66 | iconName: "install" | ||||
67 | onTriggered: { | ||||
68 | if (model.downloadCount == 1) { | ||||
69 | newStuffModel.installItem(model.index, 1); | ||||
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: i18nc("Request updating of this item", "Update"); | ||||
81 | iconName: "update" | ||||
82 | onTriggered: { newStuffModel.installItem(model.index); } | ||||
83 | enabled: model.status == NewStuff.ItemsModel.UpdateableStatus; | ||||
84 | visible: enabled; | ||||
85 | }, | ||||
86 | Kirigami.Action { | ||||
87 | text: component.uninstallLabel | ||||
88 | iconName: "uninstall" | ||||
89 | onTriggered: { newStuffModel.uninstallItem(model.index); } | ||||
90 | enabled: model.status == NewStuff.ItemsModel.InstalledStatus | ||||
91 | visible: enabled; | ||||
92 | }, | ||||
93 | Kirigami.Action { | ||||
94 | text: i18nc("Show a page with details for this item", "Details...") | ||||
95 | iconName: "documentinfo" | ||||
96 | onTriggered: { component.showDetails(); } | ||||
97 | } | ||||
98 | ] | ||||
99 | thumbnailAvailable: model.previewsSmall.length > 0 | ||||
100 | tile: Item { | ||||
101 | anchors { | ||||
102 | fill: parent | ||||
103 | margins: Kirigami.Units.smallSpacing | ||||
104 | } | ||||
105 | QtLayouts.GridLayout { | ||||
106 | anchors.fill: parent; | ||||
107 | columns: 2 | ||||
108 | QtLayouts.ColumnLayout { | ||||
109 | QtLayouts.Layout.minimumWidth: view.implicitCellWidth / 5 | ||||
110 | QtLayouts.Layout.maximumWidth: view.implicitCellWidth / 5 | ||||
111 | Item { | ||||
112 | QtLayouts.Layout.fillWidth: true | ||||
113 | QtLayouts.Layout.minimumHeight: width | ||||
114 | QtLayouts.Layout.maximumHeight: width | ||||
115 | Image { | ||||
116 | id: tilePreview | ||||
117 | asynchronous: true; | ||||
118 | fillMode: Image.PreserveAspectFit; | ||||
119 | source: thumbnailAvailable ? model.previewsSmall[0] : ""; | ||||
120 | anchors { | ||||
121 | fill: parent | ||||
122 | margins: Kirigami.Units.smallSpacing | ||||
123 | } | ||||
124 | verticalAlignment: Image.AlignTop | ||||
125 | } | ||||
126 | QtEffects.DropShadow { | ||||
127 | anchors.fill: tilePreview | ||||
128 | horizontalOffset: 0 | ||||
129 | verticalOffset: 0 | ||||
130 | radius: Kirigami.Units.largeSpacing | ||||
131 | samples: radius * 2 | ||||
132 | color: "#80000000" | ||||
133 | source: tilePreview | ||||
134 | } | ||||
135 | Kirigami.Icon { | ||||
136 | id: updateAvailableBadge; | ||||
137 | opacity: (model.status == NewStuff.ItemsModel.UpdateableStatus) ? 1 : 0; | ||||
138 | Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } } | ||||
139 | anchors { | ||||
140 | top: parent.top; | ||||
141 | left: parent.left; | ||||
142 | margins: -Kirigami.Units.smallSpacing; | ||||
143 | } | ||||
144 | height: Kirigami.Units.iconSizes.smallMedium; | ||||
145 | width: height; | ||||
146 | source: "package-installed-outdated"; | ||||
147 | } | ||||
148 | Kirigami.Icon { | ||||
149 | id: installedBadge; | ||||
150 | opacity: (model.status == NewStuff.ItemsModel.InstalledStatus) ? 1 : 0; | ||||
151 | Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } } | ||||
152 | anchors { | ||||
153 | top: parent.top; | ||||
154 | left: parent.left; | ||||
155 | margins: -Kirigami.Units.smallSpacing; | ||||
156 | } | ||||
157 | height: Kirigami.Units.iconSizes.smallMedium; | ||||
158 | width: height; | ||||
159 | source: "package-installed-updated"; | ||||
160 | } | ||||
161 | } | ||||
162 | Item { | ||||
163 | QtLayouts.Layout.fillHeight: true | ||||
164 | } | ||||
165 | } | ||||
166 | QtLayouts.ColumnLayout { | ||||
167 | QtLayouts.Layout.fillWidth: true | ||||
168 | QtLayouts.Layout.fillHeight: true | ||||
169 | Kirigami.Heading { | ||||
170 | QtLayouts.Layout.fillWidth: true | ||||
171 | elide: Text.ElideRight | ||||
172 | level: 3 | ||||
173 | text: model.name | ||||
174 | } | ||||
175 | Kirigami.Heading { | ||||
176 | QtLayouts.Layout.fillWidth: true | ||||
177 | elide: Text.ElideRight | ||||
178 | level: 4 | ||||
179 | textFormat: Text.StyledText | ||||
180 | text: i18nc("Subheading for the tile view, located immediately underneath the name of the item", "By <i>%1</i>").arg(model.author.name) | ||||
181 | } | ||||
182 | QtControls.Label { | ||||
183 | QtLayouts.Layout.fillWidth: true | ||||
184 | QtLayouts.Layout.fillHeight: true | ||||
185 | wrapMode: Text.Wrap | ||||
186 | text: model.shortSummary.length > 0 ? model.shortSummary : model.summary | ||||
187 | elide: Text.ElideRight | ||||
188 | } | ||||
189 | } | ||||
190 | Private.Rating { | ||||
191 | QtLayouts.Layout.fillWidth: true | ||||
192 | rating: model.rating / 10 | ||||
193 | } | ||||
194 | Kirigami.Heading { | ||||
195 | QtLayouts.Layout.fillWidth: true | ||||
196 | level: 5 | ||||
197 | elide: Text.ElideRight | ||||
198 | text: i18nc("The number of times the item has been downloaded", "%1 downloads").arg(model.downloadCount) | ||||
199 | } | ||||
200 | } | ||||
201 | Item { | ||||
202 | anchors.fill: parent | ||||
203 | opacity: (model.status == NewStuff.ItemsModel.InstallingStatus || model.status == NewStuff.ItemsModel.UpdatingStatus) ? 1 : 0 | ||||
204 | Behavior on opacity { NumberAnimation { duration: Kirigami.Units.longDuration; } } | ||||
205 | Rectangle { | ||||
206 | anchors.fill: parent | ||||
207 | color: Kirigami.Theme.backgroundColor | ||||
208 | opacity: 0.5; | ||||
209 | } | ||||
210 | QtControls.BusyIndicator { | ||||
211 | anchors.centerIn: parent | ||||
212 | running: parent.opacity > 0 | ||||
213 | } | ||||
214 | } | ||||
215 | MouseArea { | ||||
216 | anchors.fill: parent; | ||||
217 | onClicked: component.showDetails(); | ||||
218 | } | ||||
219 | } | ||||
220 | } |