Debian Codegraph @

rc/qml/OrganicView/OrganicMediaList.qml

raw
1 /*
2 * Copyright (C) 2012-2015 Canonical Ltd.
3 * Copyright (C) 2025 UBports Foundation
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors:
18 * Charles Lindsay <[email protected]>
19 */
20
21 import QtQuick 2.9
22 import Gallery 1.0
23 import Lomiri.Components 1.3
24 import Lomiri.Thumbnailer 0.1
25 import "../Components"
26 import "../Utility"
27 import "../../js/Gallery.js" as Gallery
28 import "../../js/GalleryUtility.js" as GalleryUtility
29
30 /*!
31 An "organic" list of photos. Used as the "tray" contents for each event in
32 the OrganicEventView, and the layout of the OrganicAlbumView.
33 */
34 Item {
35 id: organicMediaList
36 objectName: "organicMediaList"
37
38 ///
39 signal pressed(var mediaSource, var thumbnailRect)
40
41 ///
42 property var event
43 ///
44 property alias mediaModel: eventView.model
45 readonly property real organicMediaListHeight: __bigSize + __smallSize + __photosTopMargin + __margin + __margin/2
46 readonly property alias mediaModelCount: mediaModel.count
47 ///
48 property SelectionState selection
49
50 ///
51 property int animationDuration: Gallery.FAST_DURATION
52 ///
53 property int animationEasingType: Easing.InQuint
54
55 // readonly
56 ///
57 property int __mediaPerPattern: 6
58 /// Size of the bigger thumbnails
59 property var __bigSize: units.gu(19)
60 /// Size of the smaller thumbnails
61 property var __smallSize: units.gu(12)
62 /// Space between the thumbnails
63 property real __margin: units.gu(2)
64
65 // internal, used to get the organix effect
66 /// X-position shift for the delegates in one of the organic blocks
67 property var __photoX: [-__margin, 0, 0, 0, 0, 0]
68 /// Y-position shift for the delegates in one of the organic blocks
69 property var __photoY: [__smallSize + __margin, 0, __bigSize + __margin,
70 0, __bigSize + __margin, 0]
71 /// Size of the delegate in one of the organic blocks
72 property var __photoSize: [__bigSize,__smallSize, __smallSize,
73 __bigSize, __smallSize, __smallSize]
74 /// Size to be adapted for the organic effect
75 property var __photoWidth: [__smallSize-__margin, __bigSize - (__smallSize + __margin),
76 2 * __smallSize - __bigSize,__bigSize - (__smallSize + __margin),
77 __smallSize, 0]
78 /// Extra space on the right, for correct scroll boundary
79 property var __footerWidth: [__smallSize, __bigSize - __smallSize,
80 2 * __smallSize - __bigSize + __margin,
81 __bigSize - __smallSize, __smallSize + __margin,
82 0]
83
84 /// Used to generate a spacing between the events
85 property real __photosTopMargin: __margin / 2
86
87 property alias mediaTypeFilter: mediaModel.mediaTypeFilter
88
89 height: organicMediaListHeight
90
91 function positionViewAtSelected(index) {
92 eventView.positionViewAtIndex(index, ListView.Center);
93 }
94
95 Behavior on height {
96 NumberAnimation {
97 duration: animationDuration
98 easing.type: animationEasingType
99 }
100 }
101
102 Component {
103 id: eventHeader
104 Item {
105 width: eventView.leftBuffer + 2*__margin //+ __smallSize
106 height: __smallSize
107 EventCard {
108 x: eventView.leftBuffer + __margin
109 y: __photosTopMargin
110 width: __smallSize
111 height: __smallSize
112
113 visible: Boolean(event)
114
115 event: organicMediaList.event
116
117 OrganicItemInteraction {
118 selectionItem: event
119 selection: organicMediaList.selection
120 isEventHeader: true
121 }
122 }
123 }
124 }
125
126 Component {
127 id: thumbnailDelegate
128 Item {
129 objectName: "eventPhoto"
130 property variant model
131 property int index: 0
132 property int patternPhoto: index % __mediaPerPattern
133 property alias thumbnailLoaded: thumbnail.visible
134
135 width: __photoWidth[patternPhoto]
136 height: __photoSize[patternPhoto]
137
138 LomiriShape {
139 id: thumbnail
140
141 property bool isLoading: source.status === Image.Loading
142
143 x: __photoX[patternPhoto]
144 y: __photosTopMargin + __photoY[patternPhoto]
145 width: parent.height
146 height: parent.height
147
148 Behavior on x {
149 NumberAnimation {
150 duration: animationDuration
151 easing.type: animationEasingType
152 }
153 }
154 Behavior on y {
155 NumberAnimation {
156 duration: animationDuration
157 easing.type: animationEasingType
158 }
159 }
160 Behavior on width {
161 NumberAnimation {
162 duration: animationDuration
163 easing.type: animationEasingType
164 }
165 }
166 Behavior on height {
167 NumberAnimation {
168 duration: animationDuration
169 easing.type: animationEasingType
170 }
171 }
172
173 visible: source.status === Image.Ready || source.status === Image.Error
174
175 radius: "medium"
176
177 backgroundColor: "black"
178 sourceFillMode: LomiriShape.PreserveAspectCrop
179 source: Image {
180 id: thumbImage
181 source: "image://thumbnailer/" + model.mediaSource.path + "?at=" + model.mediaSource.lastModified
182 asynchronous: true
183
184 /* The SDK thumbnailer respects the freedesktop.org standard and uses 128 for the small
185 * thumbnail size, while the previous thumbnailer used 216. To maintain the same visual
186 * result as the previous thumbnailer, we force it to generate a large thumbnail, which
187 * is closer to the older one in size and looks identical when downscaled */
188 sourceSize {
189 // Make sure to request a thumbnail big enough to handle all the possible sizes
190 // that way media items will not request a new one every time it changes its
191 // position
192 width: __bigSize
193 height: __bigSize
194 }
195 fillMode: Image.PreserveAspectCrop
196 }
197
198 Icon {
199 // Display a image icon if there is an error with the photo
200 anchors.centerIn: parent
201 width: units.gu(6)
202 height: width
203 visible: thumbImage.status == Image.Error
204 name: "stock_image"
205 color: "white"
206 opacity: 0.8
207 }
208
209 // Display a play icon if the thumbnail is from a video
210 PlayIcon {
211 anchors.centerIn: parent
212 width: units.gu(5.5)
213 height: width
214 visible: model.mediaSource.type === MediaSource.Video && thumbImage.status == Image.Ready
215 }
216
217 OrganicItemInteraction {
218 objectName: "eventsViewPhoto"
219 selectionItem: model.mediaSource
220 selection: organicMediaList.selection
221
222 onPressed: {
223 var rect = GalleryUtility.getRectRelativeTo(thumbnail,
224 organicMediaList);
225 organicMediaList.pressed(selectionItem, rect);
226 }
227 }
228 }
229
230 Component {
231 id: component_loadIndicator
232 ActivityIndicator {
233 id: loadIndicator
234 running: true
235 }
236 }
237
238 Loader {
239 id: loader_loadIndicator
240 anchors.centerIn: thumbnail
241 sourceComponent: delayTimer.showIndicator && thumbnail.isLoading ?
242 component_loadIndicator : undefined
243 asynchronous: true
244
245 Timer {
246 id: delayTimer
247 property bool showIndicator: false
248 interval: 35
249 onTriggered: showIndicator = true
250 Component.onCompleted: start()
251 }
252 }
253 }
254 }
255
256 function positionViewAtBeginning() {
257 eventView.positionViewAtBeginning();
258 }
259
260 ListView {
261 id: eventView
262 // the buffers are needed, as the listview does not draw items outside is visible area
263 // but for the organic effect, x and width are "displaced" for some items (first, last)
264 property int leftBuffer: __smallSize + __margin
265 property int rightBuffer: __smallSize
266 anchors {
267 top: parent.top
268 bottom: parent.bottom
269 left: parent.left
270 leftMargin: -leftBuffer
271 right: parent.right
272 rightMargin: -rightBuffer
273 }
274
275 maximumFlickVelocity: units.gu(300)
276 flickDeceleration: maximumFlickVelocity / 3
277 cacheBuffer: width
278
279 model: MediaCollectionModel {
280 id: mediaModel
281 forCollection: organicMediaList.event
282 monitored: true
283 }
284
285 orientation: Qt.Horizontal
286
287 header: eventHeader
288 spacing: __margin
289 delegate: Loader {
290 id: thumbnailLoader
291 objectName: "thumbnailLoader" + index
292
293 property int patternPhoto: index % __mediaPerPattern
294
295 sourceComponent: eventView.header.status == Component.Ready ? thumbnailDelegate : undefined
296 asynchronous: true
297
298 width: __photoWidth[patternPhoto]
299 height: __photoSize[patternPhoto]
300
301 Binding {
302 target: thumbnailLoader.item
303 property: "model"
304 value: model
305 when: thumbnailLoader.status == Loader.Ready
306 }
307 Binding {
308 target: thumbnailLoader.item
309 property: "index"
310 value: index
311 when: thumbnailLoader.status == Loader.Ready
312 }
313 }
314 footer: Item {
315 width: eventView.rightBuffer +
316 __footerWidth[mediaModel.count % __mediaPerPattern] +
317 __margin
318 }
319
320 // discplacement animations does not always work see
321 // https://bugreports.qt-project.org/browse/QTBUG-29944
322 add: Transition {
323 NumberAnimation {
324 properties: "opacity"
325 from:0 ; to: 1
326 duration: animationDuration
327 easing.type: animationEasingType
328 }
329 }
330 displaced: Transition {
331 NumberAnimation {
332 properties: "x,y"
333 duration: animationDuration
334 easing.type: animationEasingType
335 }
336 }
337 }
338 }