KNewStuff

EntryScreenshots.qml
1/*
2 SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
3 SPDX-FileCopyrightText: 2019 Dan Leinir Turthra Jensen <admin@leinir.dk>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8import QtQuick
9import QtQuick.Controls as QQC2
10import QtQuick.Layouts
11
12import org.kde.kirigami as Kirigami
13
14Flickable {
15 id: root
16
17 property alias screenshotsModel: screenshotsRep.model
18 readonly property alias count: screenshotsRep.count
19 property int currentIndex: -1
20 property Item currentItem: screenshotsRep.itemAt(currentIndex)
21
22 Layout.preferredHeight: Kirigami.Units.gridUnit * 13
23 contentHeight: height
24 contentWidth: screenshotsLayout.width
25
26 QQC2.Popup {
27 id: overlay
28 parent: applicationWindow().QQC2.Overlay.overlay
29 modal: true
30 clip: false
31
32 x: (parent.width - width) / 2
33 y: (parent.height - height) / 2
34
35 readonly property real proportion: overlayImage.sourceSize.width > 1
36 ? overlayImage.sourceSize.height / overlayImage.sourceSize.width
37 : 1
38
39 height: overlayImage.status === Image.Loading
40 ? Kirigami.Units.gridUnit * 5
41 : Math.min(parent.height * 0.9, (parent.width * 0.9) * proportion, overlayImage.sourceSize.height)
42 width: height / proportion
43
44 QQC2.BusyIndicator {
45 id: indicator
46 visible: running
47 running: overlayImage.status === Image.Loading
48 anchors.fill: parent
49 }
50
51 // Only animate the images in the detail view; in the overview it would be irritating and not useful anyway due to the small previews
52 AnimatedImage {
53 id: overlayImage
54 anchors.fill: parent
55 source: root.currentItem ? root.currentItem.imageSource : ""
56 fillMode: Image.PreserveAspectFit
57 smooth: true
58 }
59
60 QQC2.Button {
61 anchors {
62 right: parent.left
63 verticalCenter: parent.verticalCenter
64 }
65 action: leftAction
66 visible: leftAction.visible
67 }
68
69 QQC2.Button {
70 anchors {
71 left: parent.right
72 verticalCenter: parent.verticalCenter
73 }
74 action: rightAction
75 visible: rightAction.visible
76 }
77
78 Kirigami.Action {
79 id: leftAction
80 icon.name: "arrow-left"
81 enabled: overlay.visible && visible
82 visible: root.currentIndex >= 1 && !indicator.running
83 onTriggered: source => {
84 root.currentIndex = (root.currentIndex - 1) % root.count;
85 }
86 }
87
88 Kirigami.Action {
89 id: rightAction
90 icon.name: "arrow-right"
91 enabled: overlay.visible && visible
92 visible: root.currentIndex < (root.count - 1) && !indicator.running
93 onTriggered: source => {
94 root.currentIndex = (root.currentIndex + 1) % root.count;
95 }
96 }
97 }
98
99 Row {
100 id: screenshotsLayout
101 height: root.contentHeight
102 spacing: Kirigami.Units.largeSpacing
103 leftPadding: spacing
104 rightPadding: spacing
105 focus: overlay.visible
106
107 Keys.onLeftPressed: event => {
108 if (leftAction.visible) {
109 leftAction.trigger();
110 }
111 }
112 Keys.onRightPressed: event => {
113 if (rightAction.visible) {
114 rightAction.trigger();
115 }
116 }
117
118 Repeater {
119 id: screenshotsRep
120
121 delegate: MouseArea {
122 readonly property url imageSource: modelData
123 readonly property real proportion: thumbnail.sourceSize.width > 1
124 ? thumbnail.sourceSize.height / thumbnail.sourceSize.width
125 : 1
126
127 anchors.verticalCenter: parent.verticalCenter
128 width: Math.max(50, height / proportion)
129 height: screenshotsLayout.height - 2 * Kirigami.Units.largeSpacing
130
131 hoverEnabled: true
132 cursorShape: Qt.PointingHandCursor
133
134 onClicked: mouse => {
135 root.currentIndex = index
136 overlay.open()
137 }
138
139 Kirigami.ShadowedRectangle {
140 visible: thumbnail.status === Image.Ready
141 anchors.fill: thumbnail
142 Kirigami.Theme.colorSet: Kirigami.Theme.View
143 shadow.size: Kirigami.Units.largeSpacing
144 shadow.color: Qt.rgba(0, 0, 0, 0.3)
145 }
146
147 QQC2.BusyIndicator {
148 running: thumbnail.status === Image.Loading
149 anchors.centerIn: parent
150 }
151
152 AnimatedImage {
153 id: thumbnail
154 source: modelData
155 height: parent.height
156 fillMode: Image.PreserveAspectFit
157 smooth: true
158 }
159 }
160 }
161 }
162 clip: true
163 readonly property var leftShadow: Shadow {
164 parent: root
165 anchors {
166 left: parent.left
167 top: parent.top
168 bottom: parent.bottom
169 }
170 edge: Qt.LeftEdge
171 width: Math.max(0, Math.min(root.width / 5, root.contentX))
172 }
173
174 readonly property var rightShadow: Shadow {
175 parent: root
176 anchors {
177 right: parent.right
178 top: parent.top
179 bottom: parent.bottom
180 }
181 edge: Qt.RightEdge
182 width: Math.max(0, Math.min(root.contentWidth - root.contentX - root.width) / 5)
183 }
184}
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:56:35 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.