KNewStuff

EntryScreenshots.qml
1 /*
2  SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <[email protected]>
3  SPDX-FileCopyrightText: 2019 Dan Leinir Turthra Jensen <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 import QtQuick 2.11
9 import QtQuick.Controls 2.11
10 import QtQuick.Layouts 1.11
11 import QtGraphicalEffects 1.11
12 
13 import org.kde.kirigami 2.12 as Kirigami
14 
15 Flickable {
16  id: root
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  Layout.preferredHeight: Kirigami.Units.gridUnit * 13
22  contentHeight: height
23  contentWidth: screenshotsLayout.width
24 
25  Popup {
26  id: overlay
27  parent: applicationWindow().overlay
28  modal: true
29  clip: false
30 
31  x: (parent.width - width)/2
32  y: (parent.height - height)/2
33  readonly property real proportion: overlayImage.sourceSize.width>1 ? overlayImage.sourceSize.height/overlayImage.sourceSize.width : 1
34  height: overlayImage.status == Image.Loading ? Kirigami.Units.gridUnit * 5 : Math.min(parent.height * 0.9, (parent.width * 0.9) * proportion, overlayImage.sourceSize.height)
35  width: height/proportion
36 
37  BusyIndicator {
38  id: indicator
39  visible: running
40  running: overlayImage.status == Image.Loading
41  anchors.fill: parent
42  }
43 
44  Image {
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  visible: leftAction.visible
58  icon.name: leftAction.iconName
59  onClicked: leftAction.triggered(null)
60  }
61 
62  Button {
63  anchors {
64  left: parent.right
65  verticalCenter: parent.verticalCenter
66  }
67  visible: rightAction.visible
68  icon.name: rightAction.iconName
69  onClicked: rightAction.triggered(null)
70  }
71 
72  Kirigami.Action {
73  id: leftAction
74  icon.name: "arrow-left"
75  enabled: overlay.visible && visible
76  visible: root.currentIndex >= 1 && !indicator.running
77  onTriggered: root.currentIndex = (root.currentIndex - 1) % root.count
78  }
79 
80  Kirigami.Action {
81  id: rightAction
82  icon.name: "arrow-right"
83  enabled: overlay.visible && visible
84  visible: root.currentIndex < (root.count - 1) && !indicator.running
85  onTriggered: root.currentIndex = (root.currentIndex + 1) % root.count
86  }
87  }
88 
89  Row {
90  id: screenshotsLayout
91  height: root.contentHeight
92  spacing: Kirigami.Units.largeSpacing
93  leftPadding: spacing
94  rightPadding: spacing
95  focus: overlay.visible
96 
97  Keys.onLeftPressed: if (leftAction.visible) leftAction.trigger()
98  Keys.onRightPressed: if (rightAction.visible) rightAction.trigger()
99 
100  Repeater {
101  id: screenshotsRep
102 
103  delegate: MouseArea {
104  readonly property url imageSource: modelData
105  readonly property real proportion: thumbnail.sourceSize.width>1 ? thumbnail.sourceSize.height/thumbnail.sourceSize.width : 1
106  anchors.verticalCenter: parent.verticalCenter
107  width: Math.max(50, height/proportion)
108  height: screenshotsLayout.height - 2 * Kirigami.Units.largeSpacing
109 
110  hoverEnabled: true
111  cursorShape: Qt.PointingHandCursor
112 
113  onClicked: {
114  root.currentIndex = index
115  overlay.open()
116  }
117 
118  Kirigami.ShadowedRectangle {
119  visible: thumbnail.status == Image.Ready
120  anchors.fill: thumbnail
121  Kirigami.Theme.colorSet: Kirigami.Theme.View
122  shadow.size: Kirigami.Units.largeSpacing
123  shadow.color: Qt.rgba(0, 0, 0, 0.3)
124  }
125 
126  BusyIndicator {
127  visible: running
128  running: thumbnail.status == Image.Loading
129  anchors.centerIn: parent
130  }
131 
132  Image {
133  id: thumbnail
134  source: modelData
135  height: parent.height
136  fillMode: Image.PreserveAspectFit
137  smooth: true
138  }
139  }
140  }
141  }
142  clip: true
143  readonly property var leftShadow: Shadow {
144  parent: root
145  anchors {
146  left: parent.left
147  top: parent.top
148  bottom: parent.bottom
149  }
150  edge: Qt.LeftEdge
151  width: Math.max(0, Math.min(root.width/5, root.contentX))
152  }
153 
154  readonly property var rightShadow: Shadow {
155  parent: root
156  anchors {
157  right: parent.right
158  top: parent.top
159  bottom: parent.bottom
160  }
161  edge: Qt.RightEdge
162  width: Math.max(0, Math.min(root.contentWidth - root.contentX - root.width)/5)
163  }
164 }
QTextStream & right(QTextStream &stream)
QTextStream & left(QTextStream &stream)
QTextStream & left(QTextStream &s)
QTextStream & right(QTextStream &s)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Aug 11 2020 22:43:23 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.