~seb128/gallery-app/delete-dialogs-tweaks

« back to all changes in this revision

Viewing changes to rc/qml/AlbumViewer/AlbumViewerTransition.qml

  • Committer: CI Train Bot
  • Author(s): Arthur Mello
  • Date: 2015-11-06 14:05:15 UTC
  • mfrom: (1241.1.30 gallery-app-sdk_1_3)
  • Revision ID: ci-train-bot@canonical.com-20151106140515-y27n4x5nt1ajn3jy
Update QML code to work with Ubuntu.Components 1.3 Fixes: #1508363
Approved by: Renato Araujo Oliveira Filho

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2011 Canonical Ltd
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License version 3 as
6
 
 * published by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 *
16
 
 * Authors:
17
 
 * Charles Lindsay <chaz@yorba.org>
18
 
 */
19
 
 
20
 
import QtQuick 2.0
21
 
import Gallery 1.0
22
 
import "../../js/Gallery.js" as Gallery
23
 
import "../Utility"
24
 
 
25
 
// Some custom components and animations that we want to invoke whenever we
26
 
// bring up the album viewer.
27
 
Item {
28
 
    id: albumViewerTransition
29
 
 
30
 
    /*!
31
 
    */
32
 
    signal transitionToAlbumViewerCompleted()
33
 
    /*!
34
 
    */
35
 
    signal transitionFromAlbumViewerCompleted()
36
 
    /*!
37
 
    */
38
 
    signal dissolveCompleted(variant fadeOutTarget, variant fadeInTarget)
39
 
 
40
 
    /*!
41
 
    */
42
 
    property Album album
43
 
    /*!
44
 
    */
45
 
    property Rectangle backgroundGlass
46
 
    /*!
47
 
    */
48
 
    property int duration: Gallery.SLOW_DURATION
49
 
    /*!
50
 
    */
51
 
    property int easing: Easing.InQuint
52
 
    /*!
53
 
    */
54
 
    property bool isPortrait
55
 
 
56
 
    // Read-only
57
 
    /*!
58
 
    */
59
 
    property bool animationRunning: showAlbumViewerAnimation.running ||
60
 
                                    hideAlbumViewerAnimation.running || dissolveAlbumViewerTransition.running
61
 
 
62
 
    // internal
63
 
    /*!
64
 
    */
65
 
    property bool hideStayingOpen
66
 
    /*!
67
 
    */
68
 
    property variant expandAlbum: albumOpenerLandscape
69
 
    /*!
70
 
    */
71
 
    property bool flipOnClose: isPortrait
72
 
 
73
 
    /*!
74
 
    */
75
 
    function transitionToAlbumViewer(album, thumbnailRect) {
76
 
        albumViewerTransition.album = album;
77
 
        expandAlbum = albumOpenerLandscape;
78
 
 
79
 
        expandAlbum.insideLeftPage = (isPortrait
80
 
                                      ? album.currentPage // Anything -- invisible.
81
 
                                      : expandAlbum.defaultInsideLeftPage);
82
 
        expandAlbum.insideRightPage = (isPortrait
83
 
                                       ? album.currentPage
84
 
                                       : expandAlbum.defaultInsideRightPage);
85
 
 
86
 
        expandAlbum.x = thumbnailRect.x;
87
 
        expandAlbum.y = thumbnailRect.y;
88
 
        expandAlbum.width = thumbnailRect.width;
89
 
        expandAlbum.height = thumbnailRect.height;
90
 
 
91
 
        expandAlbum.showCover = album.closed;
92
 
 
93
 
        showAlbumViewerAnimation.screenRect = getFullscreenRect(album.closed);
94
 
        showAlbumViewerAnimation.start();
95
 
    }
96
 
 
97
 
    /*!
98
 
    */
99
 
    function transitionFromAlbumViewer(album, thumbnailRect, stayOpen, viewingPage) {
100
 
        // Set up portrait mode even-numbered page close transition.
101
 
        albumOpenerPortrait.viewingPage = viewingPage;
102
 
        flipOnClose = isPortrait && viewingPage !== album.currentPage && stayOpen &&
103
 
                      !viewingPage == 0;
104
 
 
105
 
        albumViewerTransition.album = album;
106
 
        expandAlbum = flipOnClose ? albumOpenerPortrait : albumOpenerLandscape;
107
 
 
108
 
        expandAlbum.insideLeftPage = (isPortrait
109
 
                                      ? viewingPage // Anything -- invisible.
110
 
                                      : expandAlbum.defaultInsideLeftPage);
111
 
        expandAlbum.insideRightPage = (isPortrait
112
 
                                       ? viewingPage
113
 
                                       : expandAlbum.defaultInsideRightPage);
114
 
 
115
 
        var rect = getFullscreenRect(!stayOpen);
116
 
        expandAlbum.x = rect.x;
117
 
        expandAlbum.y = rect.y;
118
 
        expandAlbum.width = rect.width;
119
 
        expandAlbum.height = rect.height;
120
 
 
121
 
        hideStayingOpen = stayOpen;
122
 
        albumOpenerLandscape.showCover = !stayOpen || viewingPage == 0;
123
 
 
124
 
        /* The Album preview doesn't like when the album is set to page zero,
125
 
           it actually expects its property closed to be set to true in that case.
126
 
           But we cant set that during the animation or it will think we're
127
 
           flipping to closed, so we set it at the end */
128
 
        hideAlbumViewerAnimation.setAlbumClosedAtEnd = viewingPage == 0;
129
 
        hideAlbumViewerAnimation.thumbnailRect = thumbnailRect;
130
 
        hideAlbumViewerAnimation.start();
131
 
    }
132
 
 
133
 
    /*!
134
 
    */
135
 
    function dissolve(fadeOutTarget, fadeInTarget) {
136
 
        dissolveAlbumViewerTransition.fadeOutTarget = fadeOutTarget || dissolveDummy;
137
 
        dissolveAlbumViewerTransition.fadeInTarget = fadeInTarget || dissolveDummy;
138
 
        dissolveAlbumViewerTransition.start();
139
 
    }
140
 
 
141
 
    // internal
142
 
    function getFullscreenRect(portraitHalfOpen) {
143
 
        var rect = {"x": 0, "y": 0, "width": 0, "height": 0};
144
 
 
145
 
        // This code is kind of hacky.  There's just lots of special casing that we
146
 
        // need, and it didn't seem worth it to come up with a cleaner abstraction
147
 
        // for what amounts to one-off animation code.
148
 
 
149
 
        // We have to compensate for the frame, present in the animation but not in
150
 
        // the album viewer.
151
 
        var frameWidth = width * expandAlbum.frameToContentWidth;
152
 
        // Normally, the spread's width is half of how it appears when open.
153
 
        if (!isPortrait)
154
 
            frameWidth /= 2;
155
 
        var frameHeight = height * expandAlbum.frameToContentHeight;
156
 
 
157
 
        // Normally, we center it.  For portrait, we set it flush on one side or
158
 
        // the other (if it'll be half-open, flush left, otherwise right; this is
159
 
        // because of our thumbnail image having a border on only one side).
160
 
        if (isPortrait)
161
 
            rect.x = (portraitHalfOpen ? 0 : width - frameWidth);
162
 
        else
163
 
            rect.x = (width - frameWidth) / 2;
164
 
        rect.y = (height - frameHeight) / 2; // Centered.
165
 
        rect.width = frameWidth;
166
 
        rect.height = frameHeight;
167
 
 
168
 
        // Move the thing left 1/4 of the thing's width.  This is to match the
169
 
        // opener, which slides right 1/4 of the way at its "half-open" state
170
 
        // (actually, 0.25 openFraction).
171
 
        if (isPortrait && portraitHalfOpen)
172
 
            rect.x -= frameWidth / 4;
173
 
 
174
 
        return rect;
175
 
    }
176
 
 
177
 
    AlbumOpener {
178
 
        id: albumOpenerLandscape
179
 
 
180
 
        album: parent.album
181
 
        isPreview: true
182
 
        contentHasPreviewFrame: true
183
 
 
184
 
        visible: false
185
 
        load: visible
186
 
    }
187
 
 
188
 
    AlbumViewerTransitionPortraitPage {
189
 
        id: albumOpenerPortrait
190
 
 
191
 
        album: parent.album
192
 
        isPreview: true
193
 
        contentHasPreviewFrame: true
194
 
 
195
 
        visible: false
196
 
        load: visible
197
 
    }
198
 
 
199
 
    SequentialAnimation {
200
 
        id: showAlbumViewerAnimation
201
 
 
202
 
        property var screenRect: {"x": 0, "y": 0, "width": 0, "height": 0}
203
 
 
204
 
        PropertyAction { target: expandAlbum; property: "visible"; value: true; }
205
 
 
206
 
        ParallelAnimation {
207
 
            ExpandAnimation {
208
 
                target: expandAlbum
209
 
                endX: showAlbumViewerAnimation.screenRect.x
210
 
                endY: showAlbumViewerAnimation.screenRect.y
211
 
                endWidth: showAlbumViewerAnimation.screenRect.width
212
 
                endHeight: showAlbumViewerAnimation.screenRect.height
213
 
                duration: albumViewerTransition.duration
214
 
                easingType: albumViewerTransition.easing
215
 
            }
216
 
 
217
 
            NumberAnimation {
218
 
                target: expandAlbum
219
 
                property: "openFraction"
220
 
                from: (album && album.closed ? 0 : 1)
221
 
                to: isPortrait ? (album && album.closed ? 0.25 : 1) : 0.5
222
 
                duration: albumViewerTransition.duration
223
 
                easing.type: albumViewerTransition.easing
224
 
            }
225
 
 
226
 
            NumberAnimation {
227
 
                target: expandAlbum
228
 
                property: "topMargin"
229
 
                from: expandAlbum.previewTopMargin
230
 
                to: expandAlbum.pageTopMargin
231
 
                duration: albumViewerTransition.duration
232
 
                easing.type: albumViewerTransition.easing
233
 
            }
234
 
            NumberAnimation {
235
 
                target: expandAlbum
236
 
                property: "bottomMargin"
237
 
                from: expandAlbum.previewBottomMargin
238
 
                to: expandAlbum.pageBottomMargin
239
 
                duration: albumViewerTransition.duration
240
 
                easing.type: albumViewerTransition.easing
241
 
            }
242
 
            NumberAnimation {
243
 
                target: expandAlbum
244
 
                property: "gutterMargin"
245
 
                from: expandAlbum.previewGutterMargin
246
 
                to: expandAlbum.pageGutterMargin
247
 
                duration: albumViewerTransition.duration
248
 
                easing.type: albumViewerTransition.easing
249
 
            }
250
 
            NumberAnimation {
251
 
                target: expandAlbum
252
 
                property: "outerMargin"
253
 
                from: expandAlbum.previewOuterMargin
254
 
                to: expandAlbum.pageOuterMargin
255
 
                duration: albumViewerTransition.duration
256
 
                easing.type: albumViewerTransition.easing
257
 
            }
258
 
            NumberAnimation {
259
 
                target: expandAlbum
260
 
                property: "insideMargin"
261
 
                from: expandAlbum.previewInsideMargin
262
 
                to: expandAlbum.pageInsideMargin
263
 
                duration: albumViewerTransition.duration
264
 
                easing.type: albumViewerTransition.easing
265
 
            }
266
 
 
267
 
            FadeInAnimation {
268
 
                target: backgroundGlass
269
 
                duration: albumViewerTransition.duration
270
 
                easingType: albumViewerTransition.easing
271
 
            }
272
 
        }
273
 
 
274
 
        PropertyAction { target: expandAlbum; property: "visible"; value: false; }
275
 
        PropertyAction { target: backgroundGlass; property: "visible"; value: false; }
276
 
 
277
 
        onRunningChanged: {
278
 
            if (running)
279
 
                return;
280
 
 
281
 
            album.closed = false;
282
 
            if (album.currentPage == album.firstValidCurrentPage)
283
 
                album.currentPage = album.firstContentPage;
284
 
 
285
 
            transitionToAlbumViewerCompleted();
286
 
        }
287
 
    }
288
 
 
289
 
    SequentialAnimation {
290
 
        id: hideAlbumViewerAnimation
291
 
 
292
 
        property variant thumbnailRect: {"x": 0, "y": 0, "width": 0, "height": 0}
293
 
        property bool setAlbumClosedAtEnd: false
294
 
 
295
 
        PropertyAction { target: expandAlbum; property: "visible"; value: true; }
296
 
 
297
 
        ParallelAnimation {
298
 
            ExpandAnimation {
299
 
                target: expandAlbum
300
 
                endX: hideAlbumViewerAnimation.thumbnailRect.x
301
 
                endY: hideAlbumViewerAnimation.thumbnailRect.y
302
 
                endWidth: hideAlbumViewerAnimation.thumbnailRect.width
303
 
                endHeight: hideAlbumViewerAnimation.thumbnailRect.height
304
 
                duration: albumViewerTransition.duration
305
 
                easingType: albumViewerTransition.easing
306
 
            }
307
 
 
308
 
            NumberAnimation {
309
 
                target: expandAlbum
310
 
                property: "openFraction"
311
 
 
312
 
                from: {
313
 
                    if (flipOnClose)
314
 
                        return 0;
315
 
                    else if (isPortrait)
316
 
                        return (hideStayingOpen ? 1 : 0.25); // same as "to" property
317
 
                    else
318
 
                        return 0.5;
319
 
                }
320
 
 
321
 
                to: flipOnClose ? 1 : (hideStayingOpen ? 1 : 0)
322
 
 
323
 
                duration: albumViewerTransition.duration
324
 
                easing.type: albumViewerTransition.easing
325
 
            }
326
 
 
327
 
            NumberAnimation {
328
 
                target: expandAlbum
329
 
                property: "topMargin"
330
 
                from: expandAlbum.pageTopMargin
331
 
                to: expandAlbum.previewTopMargin
332
 
                duration: albumViewerTransition.duration
333
 
                easing.type: albumViewerTransition.easing
334
 
            }
335
 
            NumberAnimation {
336
 
                target: expandAlbum
337
 
                property: "bottomMargin"
338
 
                from: expandAlbum.pageBottomMargin
339
 
                to: expandAlbum.previewBottomMargin
340
 
                duration: albumViewerTransition.duration
341
 
                easing.type: albumViewerTransition.easing
342
 
            }
343
 
            NumberAnimation {
344
 
                target: expandAlbum
345
 
                property: "gutterMargin"
346
 
                from: expandAlbum.pageGutterMargin
347
 
                to: expandAlbum.previewGutterMargin
348
 
                duration: albumViewerTransition.duration
349
 
                easing.type: albumViewerTransition.easing
350
 
            }
351
 
            NumberAnimation {
352
 
                target: expandAlbum
353
 
                property: "outerMargin"
354
 
                from: expandAlbum.pageOuterMargin
355
 
                to: expandAlbum.previewOuterMargin
356
 
                duration: albumViewerTransition.duration
357
 
                easing.type: albumViewerTransition.easing
358
 
            }
359
 
            NumberAnimation {
360
 
                target: expandAlbum
361
 
                property: "insideMargin"
362
 
                from: expandAlbum.pageInsideMargin
363
 
                to: expandAlbum.previewInsideMargin
364
 
                duration: albumViewerTransition.duration
365
 
                easing.type: albumViewerTransition.easing
366
 
            }
367
 
 
368
 
            FadeOutAnimation {
369
 
                target: backgroundGlass
370
 
                duration: albumViewerTransition.duration
371
 
                easingType: albumViewerTransition.easing
372
 
            }
373
 
        }
374
 
 
375
 
        PropertyAction { target: expandAlbum; property: "visible"; value: false; }
376
 
 
377
 
        onRunningChanged: {
378
 
            if (running)
379
 
                return;
380
 
 
381
 
            if (album)
382
 
                album.closed = !hideStayingOpen || setAlbumClosedAtEnd;
383
 
 
384
 
            transitionFromAlbumViewerCompleted();
385
 
        }
386
 
    }
387
 
 
388
 
    DissolveAnimation {
389
 
        id: dissolveAlbumViewerTransition
390
 
 
391
 
        fadeOutTarget: dissolveDummy
392
 
        fadeInTarget: dissolveDummy
393
 
        easingType: albumViewerTransition.easing
394
 
 
395
 
        onRunningChanged: {
396
 
            if (!running)
397
 
                dissolveCompleted(fadeOutTarget, fadeInTarget);
398
 
        }
399
 
    }
400
 
 
401
 
    Item {
402
 
        id: dissolveDummy
403
 
    }
404
 
}