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 * SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 import QtQuick 0010 import QtQuick.Controls as QQC2 0011 import QtQuick.Layouts 0012 import org.kde.discover as Discover 0013 import org.kde.kirigami as Kirigami 0014 0015 BasicAbstractCard { 0016 id: root 0017 0018 required property int index 0019 required property Discover.AbstractResource application 0020 0021 property bool compact: false 0022 property bool showRating: true 0023 property bool showSize: false 0024 0025 readonly property bool appIsFromNonDefaultBackend: Discover.ResourcesModel.currentApplicationBackend !== application.backend && application.backend.hasApplications 0026 showClickFeedback: true 0027 0028 function trigger() { 0029 ListView.currentIndex = index 0030 Navigation.openApplication(application) 0031 } 0032 padding: Kirigami.Units.largeSpacing * 2 0033 highlighted: ListView.isCurrentItem 0034 0035 Keys.onReturnPressed: trigger() 0036 onClicked: trigger() 0037 0038 content: Item { 0039 implicitHeight: Math.max(columnLayout.implicitHeight, resourceIconFrame.implicitHeight) 0040 0041 Kirigami.Padding { 0042 id: resourceIconFrame 0043 anchors { 0044 top: parent.top 0045 left: parent.left 0046 bottom: parent.bottom 0047 } 0048 padding: Kirigami.Units.largeSpacing 0049 contentItem: Kirigami.Icon { 0050 source: root.application.icon 0051 animated: false 0052 0053 implicitHeight: root.compact ? Kirigami.Units.iconSizes.large : Kirigami.Units.iconSizes.huge 0054 implicitWidth: implicitHeight 0055 } 0056 } 0057 0058 // Container for everything but the app icon 0059 ColumnLayout { 0060 id: columnLayout 0061 0062 anchors { 0063 top: parent.top 0064 right: parent.right 0065 bottom: parent.bottom 0066 left: resourceIconFrame.right 0067 leftMargin: Kirigami.Units.gridUnit 0068 } 0069 spacing: 0 0070 0071 // Container for app name and backend name labels 0072 RowLayout { 0073 spacing: Kirigami.Units.largeSpacing 0074 0075 // App name label 0076 Kirigami.Heading { 0077 id: head 0078 Layout.fillWidth: true 0079 // We want the heading visually top-aligned with the top margin, the icon background and that in general 0080 // it's root.padding away from the border. We can't just align the label to the top for it because internally 0081 // everything is aligned respecting the text boundingRect, which includes blank space on the top as a "line" height, called "leading". Instead we need to base ourselves on tightBoundingRect which is a rect only around the 0082 // painted area of the label, not including the leading 0083 topPadding: headMetrics.boundingRect.y - headMetrics.tightBoundingRect.y 0084 level: root.compact ? 2 : 1 0085 type: Kirigami.Heading.Type.Primary 0086 text: root.application.name 0087 elide: Text.ElideRight 0088 maximumLineCount: 1 0089 TextMetrics { 0090 id: headMetrics 0091 font: head.font 0092 text: head.text 0093 } 0094 } 0095 0096 // Backend name label (shown if app is from a non-default backend and 0097 // we're not using the compact view, where there's no space for it) 0098 RowLayout { 0099 Layout.alignment: Qt.AlignRight 0100 visible: root.appIsFromNonDefaultBackend && !root.compact 0101 spacing: Kirigami.Units.smallSpacing 0102 0103 Kirigami.Icon { 0104 source: root.application.sourceIcon 0105 implicitWidth: Kirigami.Units.iconSizes.smallMedium 0106 implicitHeight: Kirigami.Units.iconSizes.smallMedium 0107 } 0108 QQC2.Label { 0109 text: root.application.backend.displayName 0110 font: Kirigami.Theme.smallFont 0111 } 0112 } 0113 } 0114 0115 // Description/"Comment" label 0116 QQC2.Label { 0117 id: description 0118 Layout.fillWidth: true 0119 Layout.preferredHeight: descriptionMetrics.height 0120 text: root.application.comment 0121 elide: Text.ElideRight 0122 maximumLineCount: 1 0123 textFormat: Text.PlainText 0124 0125 // reserve space for description even if none is available 0126 TextMetrics { 0127 id: descriptionMetrics 0128 font: description.font 0129 text: "Sample text" 0130 } 0131 } 0132 // Container for rating, size, and install button 0133 RowLayout { 0134 Layout.fillWidth: true 0135 spacing: Kirigami.Units.largeSpacing 0136 0137 // Combined condition of both children items 0138 visible: root.showRating || (!root.compact && root.showSize) || !root.compact 0139 0140 // Container for rating and size labels 0141 ColumnLayout { 0142 Layout.fillWidth: true 0143 // Include height of sizeInfo for full-sized view even when 0144 // the actual sizeInfo layout isn't visible. This tightens up 0145 // the layout and prevents the install button from appearing 0146 // at a different position based on whether or not the 0147 // sizeInfo text is visible, because the base layout is 0148 // vertically centered rather than filling a distinct space. 0149 Layout.preferredHeight: root.compact ? -1 : rating.implicitHeight + sizeInfo.implicitHeight 0150 Layout.alignment: Qt.AlignBottom 0151 spacing: 0 0152 0153 // Combined condition of both children items 0154 visible: root.showRating || (!root.compact && root.showSize) 0155 0156 // Rating stars + label 0157 RowLayout { 0158 id: rating 0159 Layout.fillWidth: true 0160 Layout.alignment: Qt.AlignBottom 0161 visible: root.showRating 0162 opacity: 0.6 0163 spacing: Kirigami.Units.largeSpacing 0164 0165 Rating { 0166 Layout.alignment: Qt.AlignVCenter 0167 value: root.application.rating ? root.application.rating.sortableRating : 0 0168 starSize: root.compact ? description.font.pointSize : head.font.pointSize 0169 precision: Rating.Precision.HalfStar 0170 padding: 0 0171 } 0172 QQC2.Label { 0173 Layout.fillWidth: true 0174 Layout.alignment: Qt.AlignVCenter 0175 topPadding: (ratingLabelMetrics.boundingRect.y - ratingLabelMetrics.tightBoundingRect.y)/2 0176 visible: root.application.rating || (root.application.backend.reviewsBackend && root.application.backend.reviewsBackend.isResourceSupported(root.application)) 0177 text: root.application.rating ? i18np("%1 rating", "%1 ratings", root.application.rating.ratingCount) : i18n("No ratings yet") 0178 font: Kirigami.Theme.smallFont 0179 elide: Text.ElideRight 0180 TextMetrics { 0181 id: ratingLabelMetrics 0182 font: head.font 0183 text: head.text 0184 } 0185 } 0186 } 0187 0188 // Size label 0189 QQC2.Label { 0190 id: sizeInfo 0191 Layout.fillWidth: true 0192 Layout.alignment: Qt.AlignBottom 0193 visible: !root.compact && root.showSize 0194 text: visible ? root.application.sizeDescription : "" 0195 horizontalAlignment: Text.AlignRight 0196 opacity: 0.6; 0197 font: Kirigami.Theme.smallFont 0198 elide: Text.ElideRight 0199 maximumLineCount: 1 0200 } 0201 } 0202 0203 // Install button 0204 InstallApplicationButton { 0205 id: installButton 0206 Layout.alignment: Qt.AlignBottom | Qt.AlignRight 0207 visible: !root.compact 0208 application: root.application 0209 } 0210 } 0211 } 0212 } 0213 0214 Accessible.name: head.text 0215 Accessible.onPressAction: trigger() 0216 }