Changeset View
Changeset View
Standalone View
Standalone View
src/qtquick/qml/private/EntryScreenshots.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com> | ||||
3 | * Copyright (C) 2019 Dan Leinir Turthra Jensen <admin@leinir.dk> | ||||
4 | * | ||||
5 | * This program is free software; you can redistribute it and/or modify | ||||
6 | * it under the terms of the GNU Library/Lesser General Public License | ||||
7 | * version 2, or (at your option) any later version, as published by the | ||||
8 | * Free Software Foundation | ||||
9 | * | ||||
10 | * This program is distributed in the hope that it will be useful, | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
13 | * GNU General Public License for more details | ||||
14 | * | ||||
15 | * You should have received a copy of the GNU Library/Lesser General Public | ||||
16 | * License along with this program; if not, write to the | ||||
17 | * Free Software Foundation, Inc., | ||||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
19 | */ | ||||
20 | | ||||
21 | import QtQuick 2.11 | ||||
22 | import QtQuick.Controls 2.11 | ||||
23 | import QtQuick.Layouts 1.11 | ||||
24 | import QtGraphicalEffects 1.11 | ||||
25 | | ||||
26 | import org.kde.kirigami 2.5 as Kirigami | ||||
27 | | ||||
28 | Flickable { | ||||
29 | id: root | ||||
30 | property alias screenshotsModel: screenshotsRep.model | ||||
31 | readonly property alias count: screenshotsRep.count | ||||
32 | property int currentIndex: -1 | ||||
33 | property Item currentItem: screenshotsRep.itemAt(currentIndex) | ||||
34 | Layout.preferredHeight: Kirigami.Units.gridUnit * 13 | ||||
35 | contentHeight: height | ||||
36 | contentWidth: screenshotsLayout.width | ||||
37 | | ||||
38 | Popup { | ||||
39 | id: overlay | ||||
40 | parent: applicationWindow().overlay | ||||
41 | modal: true | ||||
42 | clip: false | ||||
43 | | ||||
44 | x: (parent.width - width)/2 | ||||
45 | y: (parent.height - height)/2 | ||||
46 | readonly property real proportion: overlayImage.sourceSize.width>1 ? overlayImage.sourceSize.height/overlayImage.sourceSize.width : 1 | ||||
47 | height: overlayImage.status == Image.Loading ? Kirigami.Units.gridUnit * 5 : Math.min(parent.height * 0.9, (parent.width * 0.9) * proportion, overlayImage.sourceSize.height) | ||||
48 | width: height/proportion | ||||
49 | | ||||
50 | BusyIndicator { | ||||
51 | id: indicator | ||||
52 | visible: running | ||||
53 | running: overlayImage.status == Image.Loading | ||||
54 | anchors.fill: parent | ||||
55 | } | ||||
56 | | ||||
57 | Image { | ||||
58 | id: overlayImage | ||||
59 | anchors.fill: parent | ||||
60 | source: root.currentItem ? root.currentItem.imageSource : "" | ||||
61 | fillMode: Image.PreserveAspectFit | ||||
62 | smooth: true | ||||
63 | } | ||||
64 | | ||||
65 | Button { | ||||
66 | anchors { | ||||
67 | right: parent.left | ||||
68 | verticalCenter: parent.verticalCenter | ||||
69 | } | ||||
70 | visible: leftAction.visible | ||||
71 | icon.name: leftAction.iconName | ||||
72 | onClicked: leftAction.triggered(null) | ||||
73 | } | ||||
74 | | ||||
75 | Button { | ||||
76 | anchors { | ||||
77 | left: parent.right | ||||
78 | verticalCenter: parent.verticalCenter | ||||
79 | } | ||||
80 | visible: rightAction.visible | ||||
81 | icon.name: rightAction.iconName | ||||
82 | onClicked: rightAction.triggered(null) | ||||
83 | } | ||||
84 | | ||||
85 | Kirigami.Action { | ||||
86 | id: leftAction | ||||
87 | icon.name: "arrow-left" | ||||
88 | enabled: overlay.visible && visible | ||||
89 | visible: root.currentIndex >= 1 && !indicator.running | ||||
90 | onTriggered: root.currentIndex = (root.currentIndex - 1) % root.count | ||||
91 | } | ||||
92 | | ||||
93 | Kirigami.Action { | ||||
94 | id: rightAction | ||||
95 | icon.name: "arrow-right" | ||||
96 | enabled: overlay.visible && visible | ||||
97 | visible: root.currentIndex < (root.count - 1) && !indicator.running | ||||
98 | onTriggered: root.currentIndex = (root.currentIndex + 1) % root.count | ||||
99 | } | ||||
100 | } | ||||
101 | | ||||
102 | Row { | ||||
103 | id: screenshotsLayout | ||||
104 | height: root.contentHeight | ||||
105 | spacing: Kirigami.Units.largeSpacing | ||||
106 | focus: overlay.visible | ||||
107 | | ||||
108 | Keys.onLeftPressed: if (leftAction.visible) leftAction.trigger() | ||||
109 | Keys.onRightPressed: if (rightAction.visible) rightAction.trigger() | ||||
110 | | ||||
111 | Repeater { | ||||
112 | id: screenshotsRep | ||||
113 | | ||||
114 | delegate: MouseArea { | ||||
115 | readonly property url imageSource: modelData | ||||
116 | readonly property real proportion: thumbnail.sourceSize.width>1 ? thumbnail.sourceSize.height/thumbnail.sourceSize.width : 1 | ||||
117 | width: Math.max(50, height/proportion) | ||||
118 | height: screenshotsLayout.height | ||||
119 | | ||||
120 | hoverEnabled: true | ||||
121 | cursorShape: Qt.PointingHandCursor | ||||
122 | | ||||
123 | onClicked: { | ||||
124 | root.currentIndex = index | ||||
125 | overlay.open() | ||||
126 | } | ||||
127 | | ||||
128 | DropShadow { | ||||
129 | source: thumbnail | ||||
130 | anchors.fill: thumbnail | ||||
131 | verticalOffset: Kirigami.Units.largeSpacing | ||||
132 | horizontalOffset: 0 | ||||
133 | radius: 12.0 | ||||
134 | samples: 25 | ||||
135 | color: Kirigami.Theme.disabledTextColor | ||||
136 | cached: true | ||||
137 | } | ||||
138 | | ||||
139 | BusyIndicator { | ||||
140 | visible: running | ||||
141 | running: thumbnail.status == Image.Loading | ||||
142 | anchors.centerIn: parent | ||||
143 | } | ||||
144 | | ||||
145 | Image { | ||||
146 | id: thumbnail | ||||
147 | source: modelData | ||||
148 | height: parent.height | ||||
149 | fillMode: Image.PreserveAspectFit | ||||
150 | smooth: true | ||||
151 | } | ||||
152 | } | ||||
153 | } | ||||
154 | } | ||||
155 | clip: true | ||||
156 | readonly property var leftShadow: Shadow { | ||||
157 | parent: root | ||||
158 | anchors { | ||||
159 | left: parent.left | ||||
160 | top: parent.top | ||||
161 | bottom: parent.bottom | ||||
162 | } | ||||
163 | edge: Qt.LeftEdge | ||||
164 | width: Math.max(0, Math.min(root.width/5, root.contentX)) | ||||
165 | } | ||||
166 | | ||||
167 | readonly property var rightShadow: Shadow { | ||||
168 | parent: root | ||||
169 | anchors { | ||||
170 | right: parent.right | ||||
171 | top: parent.top | ||||
172 | bottom: parent.bottom | ||||
173 | } | ||||
174 | edge: Qt.RightEdge | ||||
175 | width: Math.max(0, Math.min(root.contentWidth - root.contentX - root.width)/5) | ||||
176 | } | ||||
177 | } |