ApplicationDelegate.qml 5.72 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 *   Copyright (C) 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library/Lesser General Public License
 *   version 2, or (at your option) any later version, as published by the
 *   Free Software Foundation
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details
 *
 *   You should have received a copy of the GNU Library/Lesser General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

import QtQuick 2.1
21
import QtQuick.Controls 2.1
22
23
24
import QtQuick.Layouts 1.1
import QtQuick.Window 2.1
import "navigation.js" as Navigation
25
import org.kde.kirigami 2.6 as Kirigami
26

27
Kirigami.AbstractCard
28
29
{
    id: delegateArea
30
    property alias application: installButton.application
31
    property bool compact: false
Nate Graham's avatar
Nate Graham committed
32
    property bool showRating: true
33
    showClickFeedback: true
34

35
    function trigger() {
36
37
        if (delegateRecycler.ListView.view)
            delegateRecycler.ListView.view.currentIndex = index
38
39
        Navigation.openApplication(application)
    }
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
40
    highlighted: delegateRecycler && delegateRecycler.ListView.isCurrentItem
41
42
    Keys.onReturnPressed: trigger()
    onClicked: trigger()
43

44
    contentItem: Item {
45
        implicitHeight: delegateArea.compact ? Kirigami.Units.gridUnit * 2 : Kirigami.Units.gridUnit * 4
46

47
        Kirigami.Icon {
48
            id: resourceIcon
49
            source: application.icon
50
            readonly property real contHeight: delegateArea.compact ? Kirigami.Units.gridUnit * 3 : Kirigami.Units.gridUnit * 5
51
            height: contHeight
52
53
54
55
56
            width: contHeight
            anchors {
                verticalCenter: parent.verticalCenter
                left: parent.left
            }
57
58
        }

59
60
61
        GridLayout {
            columnSpacing: delegateArea.compact ? 0 : 5
            rowSpacing: delegateArea.compact ? 0 : 5
62
            anchors {
Nate Graham's avatar
Nate Graham committed
63
                verticalCenter: parent.verticalCenter
64
65
66
67
                right: parent.right
                left: resourceIcon.right
                leftMargin: Kirigami.Units.largeSpacing
            }
68
69
            columns: 2
            rows: delegateArea.compact ? 4 : 3
70

71
            RowLayout {
72
                Layout.fillWidth: true
73
                readonly property bool bigTitle: (head.implicitWidth + installButton.width) > parent.width
74
75
76
77

                Kirigami.Heading {
                    id: head
                    level: delegateArea.compact ? 3 : 2
78
                    Layout.fillWidth: !category.visible || parent.bigTitle
79
80
81
82
83
84
85
86
87
88
89
90
91
                    elide: Text.ElideRight
                    text: delegateArea.application.name
                    maximumLineCount: 1
                }

                Kirigami.Heading {
                    id: category
                    level: 5
                    Layout.fillWidth: true
                    elide: Text.ElideRight
                    text: i18nc("Part of a string like this: '<app name> - <category>'", "- %1", delegateArea.application.categoryDisplay)
                    maximumLineCount: 1
                    opacity: 0.6
92
                    visible: delegateArea.application.categoryDisplay && delegateArea.application.categoryDisplay !== page.title && !parent.bigTitle
93
                }
94
            }
95

96
97
98
99
            InstallApplicationButton {
                id: installButton
                Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
                Layout.rowSpan: delegateArea.compact ? 3 : 1
100
                compact: delegateArea.compact
101
            }
102

Nate Graham's avatar
Nate Graham committed
103
104
105
            RowLayout {
                visible: showRating
                spacing: Kirigami.Units.largeSpacing
106
                Layout.fillWidth: true
Nate Graham's avatar
Nate Graham committed
107
108
109
110
                Rating {
                    rating: delegateArea.application.rating ? delegateArea.application.rating.sortableRating : 0
                    starSize: delegateArea.compact ? summary.font.pointSize : head.font.pointSize
                }
111
                Label {
112
                    Layout.fillWidth: true
113
                    text: delegateArea.application.rating ? i18np("%1 rating", "%1 ratings", delegateArea.application.rating.ratingCount) : i18n("No ratings yet")
114
                    visible: delegateArea.application.rating || delegateArea.application.backend.reviewsBackend.isResourceSupported(delegateArea.application)
Nate Graham's avatar
Nate Graham committed
115
                    opacity: 0.5
116
                    elide: Text.ElideRight
Nate Graham's avatar
Nate Graham committed
117
                }
118
119
            }

120
            Label {
Nate Graham's avatar
Nate Graham committed
121
                id: summary
122
                Layout.columnSpan: delegateArea.compact ? 1 : 2
123
                Layout.fillWidth: true
124

125
126
                rightPadding: soup.visible ? soup.width : 0
                bottomPadding: soup.visible ? Kirigami.Units.gridUnit : Kirigami.Units.smallSpacing
127
                elide: Text.ElideRight
128
                text: delegateArea.application.comment
129
                maximumLineCount: 1
130
                textFormat: Text.PlainText
131
132
133
134
135
136
137

                Kirigami.Icon {
                    id: soup
                    source: application.sourceIcon
                    height: Kirigami.Units.gridUnit
                    width: Kirigami.Units.gridUnit
                    smooth: true
138
                    visible: !delegateArea.compact && ResourcesModel.currentApplicationBackend !== application.backend && application.backend.hasApplications
139
140
141
142
143
                    anchors {
                        bottom: parent.bottom
                        right: parent.right
                    }
                }
144
145
146
147
            }
        }
    }
}