ApplicationScreenshots.qml 5.38 KB
Newer Older
1
/*
2
 *   SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
3
 *   SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
4
 *
5
 *   SPDX-License-Identifier: LGPL-2.0-or-later
6
7
8
9
 */


import QtQuick 2.1
10
import QtQuick.Layouts 1.1
11
import QtQuick.Controls 2.1
12
import org.kde.discover 2.0
13
import org.kde.kirigami 2.12 as Kirigami
14

15
ListView {
16
    id: root
17
    readonly property alias count: screenshotsModel.count
18
    property alias resource: screenshotsModel.application
19
    property var resource
20
21
22
23
24

    spacing: Kirigami.Units.largeSpacing
    focus: overlay.visible
    orientation: Qt.Horizontal

Carl Schwan's avatar
Carl Schwan committed
25
    Layout.preferredHeight: Kirigami.Units.gridUnit * 10
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

    Keys.onLeftPressed:  if (leftAction.visible)  leftAction.trigger()
    Keys.onRightPressed: if (rightAction.visible) rightAction.trigger()

    model: ScreenshotsModel {
        id: screenshotsModel
    }

    delegate: AbstractButton {
        readonly property url imageSource: large_image_url
        readonly property real proportion: thumbnail.sourceSize.width>1 ? thumbnail.sourceSize.height/thumbnail.sourceSize.width : 1

        implicitWidth: thumbnail.width
        implicitHeight: root.height
        padding: Kirigami.Units.largeSpacing
        hoverEnabled: true
42
43
44
45
        onClicked: {
            root.currentIndex = model.row
            overlay.open()
        }
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
        // TODO cursorShape: Qt.PointingHandCursor

        background: Image {
            id: thumbnail
            readonly property real proportion: thumbnail.sourceSize.width>1 ? thumbnail.sourceSize.height/thumbnail.sourceSize.width : 1
            width: root.height / proportion
            height: root.height

            BusyIndicator {
                visible: running
                running: thumbnail.status == Image.Loading
                anchors.centerIn: parent
            }
            source: small_image_url
        }
    }
62

63
    Popup {
64
        id: overlay
65
66
        parent: applicationWindow().overlay
        modal: true
67
        clip: false
68
69
70

        x: (parent.width - width)/2
        y: (parent.height - height)/2
71
        readonly property real proportion: overlayImage.sourceSize.width>1 ? overlayImage.sourceSize.height/overlayImage.sourceSize.width : 1
72
        height: overlayImage.status == Image.Loading ? Kirigami.Units.gridUnit * 5 : Math.min(parent.height * 0.9, (parent.width * 0.9) * proportion, overlayImage.sourceSize.height)
73
        width: (height - 2 * padding)/proportion
74

75
        BusyIndicator {
76
            id: indicator
77
78
79
80
81
            visible: running
            running: overlayImage.status == Image.Loading
            anchors.fill: parent
        }

82
83
        Image {
            id: overlayImage
84
            anchors.fill: parent
85
            source: root.currentItem ? root.currentItem.imageSource : ""
86
            fillMode: Image.PreserveAspectFit
87
            smooth: true
88
        }
89
90
91
92
93
94

        Button {
            anchors {
                right: parent.left
                verticalCenter: parent.verticalCenter
            }
95
            visible: leftAction.visible
96
            icon.name: leftAction.iconName
97
98
99
100
101
102
103
104
            onClicked: leftAction.triggered(null)
        }

        Button {
            anchors {
                left: parent.right
                verticalCenter: parent.verticalCenter
            }
105
            visible: rightAction.visible
106
            icon.name: rightAction.iconName
107
108
109
110
111
            onClicked: rightAction.triggered(null)
        }

        Kirigami.Action {
            id: leftAction
112
            icon.name: "arrow-left"
113
            enabled: overlay.visible && visible
114
            visible: root.currentIndex >= 1 && !indicator.running
115
            onTriggered: root.currentIndex = (root.currentIndex - 1) % screenshotsModel.count
116
117
118
119
        }

        Kirigami.Action {
            id: rightAction
120
            icon.name: "arrow-right"
121
            enabled: overlay.visible && visible
122
            visible: root.currentIndex < (root.count - 1) && !indicator.running
123
            onTriggered: root.currentIndex = (root.currentIndex + 1) % screenshotsModel.count
124
        }
125
126
    }

127

128
    clip: true
129
130

    Shadow {
131
132
133
134
135
        parent: root
        anchors {
            left: parent.left
            top: parent.top
            bottom: parent.bottom
136
        }
137
138
        edge: Qt.LeftEdge
        width: Math.max(0, Math.min(root.width/5, root.contentX))
139
    }
140

141
    Shadow {
142
143
144
145
146
147
148
149
        parent: root
        anchors {
            right: parent.right
            top: parent.top
            bottom: parent.bottom
        }
        edge: Qt.RightEdge
        width: Math.max(0, Math.min(root.contentWidth - root.contentX - root.width)/5)
150
    }
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178

    RoundButton {
        anchors {
            left: parent.left
            leftMargin: Kirigami.Units.largeSpacing
            verticalCenter: parent.verticalCenter
        }
        width: Kirigami.Units.gridUnit * 2
        height: width
        icon.name: "arrow-left"
        visible: !Kirigami.Settings.isMobile && root.currentIndex > 0
        Keys.forwardTo: [root]
        onClicked: root.currentIndex -= 1
    }

    RoundButton {
        anchors {
            right: parent.right
            rightMargin: Kirigami.Units.largeSpacing
            verticalCenter: parent.verticalCenter
        }
        width: Kirigami.Units.gridUnit * 2
        height: width
        icon.name: "arrow-right"
        visible: !Kirigami.Settings.isMobile && root.currentIndex < root.count - 1
        Keys.forwardTo: [root]
        onClicked: root.currentIndex += 1
    }
179
}