Warning, /plasma/discover/discover/qml/ApplicationDelegate.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *   SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
0003  *   SPDX-FileCopyrightText: 2018-2021 Nate Graham <nate@kde.org>
0004  *
0005  *   SPDX-License-Identifier: LGPL-2.0-or-later
0006  */
0007 
0008 import QtQuick 2.15
0009 import QtQuick.Controls 2.1
0010 import QtQuick.Layouts 1.1
0011 import QtQuick.Window 2.1
0012 import "navigation.js" as Navigation
0013 import org.kde.discover 2.0
0014 import org.kde.kirigami 2.14 as Kirigami
0015 
0016 Kirigami.AbstractCard
0017 {
0018     id: delegateArea
0019     property alias application: installButton.application
0020     property bool compact: false
0021     property bool showRating: true
0022     property bool showSize: false
0023 
0024     readonly property bool appIsFromNonDefaultBackend: ResourcesModel.currentApplicationBackend !== application.backend && application.backend.hasApplications
0025     showClickFeedback: true
0026 
0027     function trigger() {
0028         const view = typeof delegateRecycler !== 'undefined' ? delegateRecycler.ListView.view : ListView.view
0029         if (view)
0030             view.currentIndex = index
0031         Navigation.openApplication(application)
0032     }
0033     highlighted: ListView.isCurrentItem || (typeof delegateRecycler !== 'undefined' && delegateRecycler.ListView.isCurrentItem)
0034     Keys.onReturnPressed: trigger()
0035     onClicked: trigger()
0036 
0037     contentItem: Item {
0038         implicitHeight: delegateArea.compact ? Kirigami.Units.gridUnit * 2 : Math.round(Kirigami.Units.gridUnit * 3.5)
0039 
0040         // App icon
0041         Kirigami.Icon {
0042             id: resourceIcon
0043             readonly property real contHeight: delegateArea.compact ? Kirigami.Units.iconSizes.large : Kirigami.Units.iconSizes.huge
0044             source: application.icon
0045             height: contHeight
0046             width: contHeight
0047             anchors {
0048                 verticalCenter: parent.verticalCenter
0049                 left: parent.left
0050                 leftMargin: delegateArea.compact ? Kirigami.Units.largeSpacing : Kirigami.Units.largeSpacing * 2
0051             }
0052         }
0053 
0054         // Container for everything but the app icon
0055         ColumnLayout {
0056             anchors {
0057                 verticalCenter: parent.verticalCenter
0058                 right: parent.right
0059                 left: resourceIcon.right
0060                 leftMargin: Kirigami.Units.largeSpacing * 2
0061             }
0062             spacing: 0
0063 
0064             // Container for app name and backend name labels
0065             RowLayout {
0066 
0067                 // App name label
0068                 Kirigami.Heading {
0069                     id: head
0070                     Layout.fillWidth: true
0071                     level: delegateArea.compact ? 2 : 1
0072                     type: Kirigami.Heading.Type.Primary
0073                     text: delegateArea.application.name
0074                     elide: Text.ElideRight
0075                     maximumLineCount: 1
0076                 }
0077 
0078                 // Backend name label (shown if app is from a non-default backend and
0079                 // we're not using the compact view, where there's no space for it)
0080                 RowLayout {
0081                     Layout.alignment: Qt.AlignRight
0082                     visible: delegateArea.appIsFromNonDefaultBackend && !delegateArea.compact
0083                     spacing: 0
0084 
0085                     Kirigami.Icon {
0086                         source: application.sourceIcon
0087                         implicitWidth: Kirigami.Units.iconSizes.smallMedium
0088                         implicitHeight: Kirigami.Units.iconSizes.smallMedium
0089                     }
0090                     Label {
0091                         text: application.backend.displayName
0092                         font: Kirigami.Theme.smallFont
0093                     }
0094                 }
0095             }
0096 
0097             // Description/"Comment" label
0098             Label {
0099                 id: description
0100                 Layout.fillWidth: true
0101                 text: delegateArea.application.comment
0102                 elide: Text.ElideRight
0103                 maximumLineCount: 1
0104                 textFormat: Text.PlainText
0105             }
0106 
0107             // Container for rating, size, and install button
0108             RowLayout {
0109                 Layout.fillWidth: true
0110                 Layout.topMargin: delegateArea.compact ? Kirigami.Units.smallSpacing : Kirigami.Units.largeSpacing
0111 
0112                 // Container for rating and size labels
0113                 ColumnLayout {
0114                     Layout.fillWidth: true
0115                     // Include height of sizeInfo for full-sized view even when
0116                     // the actual sizeInfo layout isn't visible. This tightens up
0117                     // the layout and prevents the install button from appearing
0118                     // at a different position based on whether or not the
0119                     // sizeInfo text is visible, because the base layout is
0120                     // vertically centered rather than filling a distinct space.
0121                     Layout.preferredHeight: delegateArea.compact ? -1 : rating.implicitHeight + sizeInfo.implicitHeight
0122                     spacing: 0
0123 
0124                     // Rating stars + label
0125                     RowLayout {
0126                         id: rating
0127                         Layout.fillWidth: true
0128                         Layout.alignment: Qt.AlignTop
0129                         visible: showRating
0130                         opacity: 0.6
0131                         spacing: Kirigami.Units.largeSpacing
0132 
0133                         Rating {
0134                             rating: delegateArea.application.rating ? delegateArea.application.rating.sortableRating : 0
0135                             starSize: delegateArea.compact ? description.font.pointSize : head.font.pointSize
0136                         }
0137                         Label {
0138                             Layout.fillWidth: true
0139                             visible: delegateArea.application.rating || (delegateArea.application.backend.reviewsBackend && delegateArea.application.backend.reviewsBackend.isResourceSupported(delegateArea.application))
0140                             text: delegateArea.application.rating ? i18np("%1 rating", "%1 ratings", delegateArea.application.rating.ratingCount) : i18n("No ratings yet")
0141                             font: Kirigami.Theme.smallFont
0142                             elide: Text.ElideRight
0143                         }
0144                     }
0145 
0146                     // Size label
0147                     Label {
0148                         id: sizeInfo
0149                         Layout.fillWidth: true
0150                         visible: !delegateArea.compact && showSize
0151                         text: visible ? delegateArea.application.sizeDescription : ""
0152                         horizontalAlignment: Text.AlignRight
0153                         opacity: 0.6;
0154                         font: Kirigami.Theme.smallFont
0155                         elide: Text.ElideRight
0156                         maximumLineCount: 1
0157                     }
0158                 }
0159 
0160                 // Install button
0161                 InstallApplicationButton {
0162                     id: installButton
0163                     Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
0164                     visible: !delegateArea.compact
0165                 }
0166             }
0167         }
0168     }
0169 }