| 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 |
| 8 |
import QtQuick.Controls as QQC2 |
| 9 |
import QtQuick.Layouts |
| 10 |
|
| 11 |
import org.kde.kirigami as Kirigami |
| 12 |
|
| 13 |
import org.kde.newstuff as NewStuff |
| 14 |
|
| 15 |
import ".." as Private |
| 16 |
|
| 17 |
Private.GridTileDelegate { |
| 18 |
id: component |
| 19 |
|
| 20 |
property var entry: model.entry |
| 21 |
|
| 22 |
function showDetails() { |
| 23 |
pageStack.push(detailsPage, { |
| 24 |
newStuffModel: GridView.view.model, |
| 25 |
entry: model.entry, |
| 26 |
}); |
| 27 |
} |
| 28 |
|
| 29 |
actionsAnchors.topMargin: bigPreview.height + Kirigami.Units.smallSpacing * 2 |
| 30 |
|
| 31 |
actions: [ |
| 32 |
Kirigami.Action { |
| 33 |
text: root.useLabel |
| 34 |
icon.name: "dialog-ok-apply" |
| 35 |
onTriggered: source => { |
| 36 |
newStuffModel.engine.adoptEntry(model.entry); |
| 37 |
} |
| 38 |
enabled: (entry.status === NewStuff.Entry.Installed || entry.status === NewStuff.Entry.Updateable) && newStuffEngine.hasAdoptionCommand |
| 39 |
visible: enabled |
| 40 |
}, |
| 41 |
Kirigami.Action { |
| 42 |
text: model.downloadLinks.length === 1 |
| 43 |
? i18ndc("knewstuff6", "Request installation of this item, available when there is exactly one downloadable item", "Install") |
| 44 |
: i18ndc("knewstuff6", "Show installation options, where there is more than one downloadable item", "Install…") |
| 45 |
icon.name: "install" |
| 46 |
onTriggered: source => { |
| 47 |
if (model.downloadLinks.length === 1) { |
| 48 |
newStuffModel.engine.installLinkId(model.entry, NewStuff.ItemsModel.FirstLinkId); |
| 49 |
} else { |
| 50 |
downloadItemsSheet.downloadLinks = model.downloadLinks; |
| 51 |
downloadItemsSheet.entry = model.entry; |
| 52 |
downloadItemsSheet.open(); |
| 53 |
} |
| 54 |
} |
| 55 |
enabled: entry.status === NewStuff.Entry.Downloadable || entry.status === NewStuff.Entry.Deleted |
| 56 |
visible: enabled |
| 57 |
}, |
| 58 |
Kirigami.Action { |
| 59 |
text: i18ndc("knewstuff6", "Request updating of this item", "Update") |
| 60 |
icon.name: "update-none" |
| 61 |
onTriggered: source => { |
| 62 |
newStuffModel.engine.installLatest(model.entry); |
| 63 |
} |
| 64 |
enabled: entry.status === NewStuff.Entry.Updateable |
| 65 |
visible: enabled |
| 66 |
}, |
| 67 |
Kirigami.Action { |
| 68 |
text: root.uninstallLabel |
| 69 |
icon.name: "edit-delete" |
| 70 |
onTriggered: source => { |
| 71 |
newStuffModel.engine.uninstall(model.entry); |
| 72 |
} |
| 73 |
enabled: entry.status === NewStuff.Entry.Installed || entry.status === NewStuff.Entry.Updateable |
| 74 |
visible: enabled |
| 75 |
} |
| 76 |
] |
| 77 |
thumbnailArea: bigPreview |
| 78 |
thumbnailAvailable: model.previewsSmall.length > 0 |
| 79 |
tile: Item { |
| 80 |
anchors { |
| 81 |
fill: parent |
| 82 |
margins: Kirigami.Units.smallSpacing |
| 83 |
} |
| 84 |
ColumnLayout { |
| 85 |
anchors.fill: parent |
| 86 |
Item { |
| 87 |
Layout.fillWidth: true |
| 88 |
Layout.fillHeight: true |
| 89 |
Layout.minimumHeight: width / 5 |
| 90 |
Layout.maximumHeight: width / 1.8 |
| 91 |
Kirigami.ShadowedRectangle { |
| 92 |
visible: bigPreview.status === Image.Ready |
| 93 |
anchors.centerIn: bigPreview |
| 94 |
width: Math.min(bigPreview.paintedWidth, bigPreview.width) |
| 95 |
height: Math.min(bigPreview.paintedHeight, bigPreview.height) |
| 96 |
Kirigami.Theme.colorSet: Kirigami.Theme.View |
| 97 |
shadow.size: 10 |
| 98 |
shadow.color: Qt.rgba(0, 0, 0, 0.3) |
| 99 |
} |
| 100 |
Image { |
| 101 |
id: bigPreview |
| 102 |
asynchronous: true |
| 103 |
fillMode: Image.PreserveAspectCrop |
| 104 |
source: thumbnailAvailable ? model.previews[0] : "" |
| 105 |
anchors.fill: parent |
| 106 |
} |
| 107 |
Kirigami.Icon { |
| 108 |
id: updateAvailableBadge |
| 109 |
opacity: (entry.status === NewStuff.Entry.Updateable) ? 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-outdated" |
| 118 |
} |
| 119 |
Kirigami.Icon { |
| 120 |
id: installedBadge |
| 121 |
opacity: (entry.status === NewStuff.Entry.Installed) ? 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 |
Layout.fillWidth: true |
| 134 |
rating: model.rating |
| 135 |
} |
| 136 |
Kirigami.Heading { |
| 137 |
Layout.fillWidth: true |
| 138 |
level: 5 |
| 139 |
elide: Text.ElideRight |
| 140 |
text: i18ndc("knewstuff6", "The number of times the item has been downloaded", "%1 downloads", model.downloadCount) |
| 141 |
} |
| 142 |
Kirigami.Heading { |
| 143 |
Layout.fillWidth: true |
| 144 |
elide: Text.ElideRight |
| 145 |
level: 3 |
| 146 |
text: model.name |
| 147 |
} |
| 148 |
Kirigami.Heading { |
| 149 |
Layout.fillWidth: true |
| 150 |
elide: Text.ElideRight |
| 151 |
level: 4 |
| 152 |
textFormat: Text.StyledText |
| 153 |
text: i18ndc("knewstuff6", "Subheading for the tile view, located immediately underneath the name of the item", "By <i>%1</i>", model.author.name) |
| 154 |
} |
| 155 |
QQC2.Label { |
| 156 |
Layout.fillWidth: true |
| 157 |
Layout.fillHeight: true |
| 158 |
Layout.minimumHeight: Kirigami.Units.gridUnit |
| 159 |
Layout.maximumHeight: Kirigami.Units.gridUnit * 3 |
| 160 |
wrapMode: Text.Wrap |
| 161 |
text: model.shortSummary.length > 0 ? model.shortSummary : model.summary |
| 162 |
elide: Text.ElideRight |
| 163 |
} |
| 164 |
clip: true // We are dealing with content over which we have very little control. Sometimes that means being a bit abrupt. |
| 165 |
} |
| 166 |
FeedbackOverlay { |
| 167 |
anchors.fill: parent |
| 168 |
newStuffModel: component.GridView.view.model |
| 169 |
} |
| 170 |
MouseArea { |
| 171 |
anchors.fill: parent |
| 172 |
cursorShape: Qt.PointingHandCursor |
| 173 |
onClicked: mouse => { |
| 174 |
component.showDetails(); |
| 175 |
} |
| 176 |
} |
| 177 |
} |
| 178 |
} |