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
10import QtQuick.Layouts
11
12import org.kde.kirigami as Kirigami
13
14Flickable {
15 id: root
16 property alias screenshotsModel: screenshotsRep.model
17 readonly property alias count: screenshotsRep.count
18 property int currentIndex: -1
19 property Item currentItem: screenshotsRep.itemAt(currentIndex)
20 Layout.preferredHeight: Kirigami.Units.gridUnit * 13
21 contentHeight: height
22 contentWidth: screenshotsLayout.width
23
24 Popup {
25 id: overlay
26 parent: applicationWindow().Overlay.overlay
27 modal: true
28 clip: false
29
30 x: (parent.width - width)/2
31 y: (parent.height - height)/2
32 readonly property real proportion: overlayImage.sourceSize.width>1 ? overlayImage.sourceSize.height/overlayImage.sourceSize.width : 1
33 height: overlayImage.status == Image.Loading ? Kirigami.Units.gridUnit * 5 : Math.min(parent.height * 0.9, (parent.width * 0.9) * proportion, overlayImage.sourceSize.height)
34 width: height/proportion
35
36 BusyIndicator {
37 id: indicator
38 visible: running
39 running: overlayImage.status == Image.Loading
40 anchors.fill: parent
41 }
42
43 // Only animate the images in the detail view; in the overview it would be irritating and not useful anyway due to the small previews
44 AnimatedImage {
45 id: overlayImage
46 anchors.fill: parent
47 source: root.currentItem ? root.currentItem.imageSource : ""
48 fillMode: Image.PreserveAspectFit
49 smooth: true
50 }
51
52 Button {
53 anchors {
54 right: parent.left
55 verticalCenter: parent.verticalCenter
56 }
57 action: leftAction
58 visible: leftAction.visible
59 }
60
61 Button {
62 anchors {
63 left: parent.right
64 verticalCenter: parent.verticalCenter
65 }
66 action: rightAction
67 visible: rightAction.visible
68 }
69
70 Kirigami.Action {
71 id: leftAction
72 icon.name: "arrow-left"
73 enabled: overlay.visible && visible
74 visible: root.currentIndex >= 1 && !indicator.running
75 onTriggered: root.currentIndex = (root.currentIndex - 1) % root.count
76 }
77
78 Kirigami.Action {
79 id: rightAction
80 icon.name: "arrow-right"
81 enabled: overlay.visible && visible
82 visible: root.currentIndex < (root.count - 1) && !indicator.running
83 onTriggered: root.currentIndex = (root.currentIndex + 1) % root.count
84 }
85 }
86
87 Row {
88 id: screenshotsLayout
89 height: root.contentHeight
90 spacing: Kirigami.Units.largeSpacing
91 leftPadding: spacing
92 rightPadding: spacing
93 focus: overlay.visible
94
95 Keys.onLeftPressed: if (leftAction.visible) leftAction.trigger()
96 Keys.onRightPressed: if (rightAction.visible) rightAction.trigger()
97
98 Repeater {
99 id: screenshotsRep
100
101 delegate: MouseArea {
102 readonly property url imageSource: modelData
103 readonly property real proportion: thumbnail.sourceSize.width>1 ? thumbnail.sourceSize.height/thumbnail.sourceSize.width : 1
104 anchors.verticalCenter: parent.verticalCenter
105 width: Math.max(50, height/proportion)
106 height: screenshotsLayout.height - 2 * Kirigami.Units.largeSpacing
107
108 hoverEnabled: true
109 cursorShape: Qt.PointingHandCursor
110
111 onClicked: {
112 root.currentIndex = index
113 overlay.open()
114 }
115
116 Kirigami.ShadowedRectangle {
117 visible: thumbnail.status == Image.Ready
118 anchors.fill: thumbnail
119 Kirigami.Theme.colorSet: Kirigami.Theme.View
120 shadow.size: Kirigami.Units.largeSpacing
121 shadow.color: Qt.rgba(0, 0, 0, 0.3)
122 }
123
124 BusyIndicator {
125 visible: running
126 running: thumbnail.status == Image.Loading
127 anchors.centerIn: parent
128 }
129
130 AnimatedImage {
131 id: thumbnail
132 source: modelData
133 height: parent.height
134 fillMode: Image.PreserveAspectFit
135 smooth: true
136 }
137 }
138 }
139 }
140 clip: true
141 readonly property var leftShadow: Shadow {
142 parent: root
143 anchors {
144 left: parent.left
145 top: parent.top
146 bottom: parent.bottom
147 }
148 edge: Qt.LeftEdge
149 width: Math.max(0, Math.min(root.width/5, root.contentX))
150 }
151
152 readonly property var rightShadow: Shadow {
153 parent: root
154 anchors {
155 right: parent.right
156 top: parent.top
157 bottom: parent.bottom
158 }
159 edge: Qt.RightEdge
160 width: Math.max(0, Math.min(root.contentWidth - root.contentX - root.width)/5)
161 }
162}
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 Tue Mar 26 2024 11:21:35 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.