2
* Copyright (C) 2011 Canonical Ltd
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.
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.
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/>.
17
* Charles Lindsay <chaz@yorba.org>
22
import "../../js/Gallery.js" as Gallery
25
// Some custom components and animations that we want to invoke whenever we
26
// bring up the album viewer.
28
id: albumViewerTransition
32
signal transitionToAlbumViewerCompleted()
35
signal transitionFromAlbumViewerCompleted()
38
signal dissolveCompleted(variant fadeOutTarget, variant fadeInTarget)
45
property Rectangle backgroundGlass
48
property int duration: Gallery.SLOW_DURATION
51
property int easing: Easing.InQuint
54
property bool isPortrait
59
property bool animationRunning: showAlbumViewerAnimation.running ||
60
hideAlbumViewerAnimation.running || dissolveAlbumViewerTransition.running
65
property bool hideStayingOpen
68
property variant expandAlbum: albumOpenerLandscape
71
property bool flipOnClose: isPortrait
75
function transitionToAlbumViewer(album, thumbnailRect) {
76
albumViewerTransition.album = album;
77
expandAlbum = albumOpenerLandscape;
79
expandAlbum.insideLeftPage = (isPortrait
80
? album.currentPage // Anything -- invisible.
81
: expandAlbum.defaultInsideLeftPage);
82
expandAlbum.insideRightPage = (isPortrait
84
: expandAlbum.defaultInsideRightPage);
86
expandAlbum.x = thumbnailRect.x;
87
expandAlbum.y = thumbnailRect.y;
88
expandAlbum.width = thumbnailRect.width;
89
expandAlbum.height = thumbnailRect.height;
91
expandAlbum.showCover = album.closed;
93
showAlbumViewerAnimation.screenRect = getFullscreenRect(album.closed);
94
showAlbumViewerAnimation.start();
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 &&
105
albumViewerTransition.album = album;
106
expandAlbum = flipOnClose ? albumOpenerPortrait : albumOpenerLandscape;
108
expandAlbum.insideLeftPage = (isPortrait
109
? viewingPage // Anything -- invisible.
110
: expandAlbum.defaultInsideLeftPage);
111
expandAlbum.insideRightPage = (isPortrait
113
: expandAlbum.defaultInsideRightPage);
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;
121
hideStayingOpen = stayOpen;
122
albumOpenerLandscape.showCover = !stayOpen || viewingPage == 0;
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();
135
function dissolve(fadeOutTarget, fadeInTarget) {
136
dissolveAlbumViewerTransition.fadeOutTarget = fadeOutTarget || dissolveDummy;
137
dissolveAlbumViewerTransition.fadeInTarget = fadeInTarget || dissolveDummy;
138
dissolveAlbumViewerTransition.start();
142
function getFullscreenRect(portraitHalfOpen) {
143
var rect = {"x": 0, "y": 0, "width": 0, "height": 0};
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.
149
// We have to compensate for the frame, present in the animation but not in
151
var frameWidth = width * expandAlbum.frameToContentWidth;
152
// Normally, the spread's width is half of how it appears when open.
155
var frameHeight = height * expandAlbum.frameToContentHeight;
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).
161
rect.x = (portraitHalfOpen ? 0 : width - frameWidth);
163
rect.x = (width - frameWidth) / 2;
164
rect.y = (height - frameHeight) / 2; // Centered.
165
rect.width = frameWidth;
166
rect.height = frameHeight;
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;
178
id: albumOpenerLandscape
182
contentHasPreviewFrame: true
188
AlbumViewerTransitionPortraitPage {
189
id: albumOpenerPortrait
193
contentHasPreviewFrame: true
199
SequentialAnimation {
200
id: showAlbumViewerAnimation
202
property var screenRect: {"x": 0, "y": 0, "width": 0, "height": 0}
204
PropertyAction { target: expandAlbum; property: "visible"; value: true; }
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
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
228
property: "topMargin"
229
from: expandAlbum.previewTopMargin
230
to: expandAlbum.pageTopMargin
231
duration: albumViewerTransition.duration
232
easing.type: albumViewerTransition.easing
236
property: "bottomMargin"
237
from: expandAlbum.previewBottomMargin
238
to: expandAlbum.pageBottomMargin
239
duration: albumViewerTransition.duration
240
easing.type: albumViewerTransition.easing
244
property: "gutterMargin"
245
from: expandAlbum.previewGutterMargin
246
to: expandAlbum.pageGutterMargin
247
duration: albumViewerTransition.duration
248
easing.type: albumViewerTransition.easing
252
property: "outerMargin"
253
from: expandAlbum.previewOuterMargin
254
to: expandAlbum.pageOuterMargin
255
duration: albumViewerTransition.duration
256
easing.type: albumViewerTransition.easing
260
property: "insideMargin"
261
from: expandAlbum.previewInsideMargin
262
to: expandAlbum.pageInsideMargin
263
duration: albumViewerTransition.duration
264
easing.type: albumViewerTransition.easing
268
target: backgroundGlass
269
duration: albumViewerTransition.duration
270
easingType: albumViewerTransition.easing
274
PropertyAction { target: expandAlbum; property: "visible"; value: false; }
275
PropertyAction { target: backgroundGlass; property: "visible"; value: false; }
281
album.closed = false;
282
if (album.currentPage == album.firstValidCurrentPage)
283
album.currentPage = album.firstContentPage;
285
transitionToAlbumViewerCompleted();
289
SequentialAnimation {
290
id: hideAlbumViewerAnimation
292
property variant thumbnailRect: {"x": 0, "y": 0, "width": 0, "height": 0}
293
property bool setAlbumClosedAtEnd: false
295
PropertyAction { target: expandAlbum; property: "visible"; value: true; }
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
310
property: "openFraction"
316
return (hideStayingOpen ? 1 : 0.25); // same as "to" property
321
to: flipOnClose ? 1 : (hideStayingOpen ? 1 : 0)
323
duration: albumViewerTransition.duration
324
easing.type: albumViewerTransition.easing
329
property: "topMargin"
330
from: expandAlbum.pageTopMargin
331
to: expandAlbum.previewTopMargin
332
duration: albumViewerTransition.duration
333
easing.type: albumViewerTransition.easing
337
property: "bottomMargin"
338
from: expandAlbum.pageBottomMargin
339
to: expandAlbum.previewBottomMargin
340
duration: albumViewerTransition.duration
341
easing.type: albumViewerTransition.easing
345
property: "gutterMargin"
346
from: expandAlbum.pageGutterMargin
347
to: expandAlbum.previewGutterMargin
348
duration: albumViewerTransition.duration
349
easing.type: albumViewerTransition.easing
353
property: "outerMargin"
354
from: expandAlbum.pageOuterMargin
355
to: expandAlbum.previewOuterMargin
356
duration: albumViewerTransition.duration
357
easing.type: albumViewerTransition.easing
361
property: "insideMargin"
362
from: expandAlbum.pageInsideMargin
363
to: expandAlbum.previewInsideMargin
364
duration: albumViewerTransition.duration
365
easing.type: albumViewerTransition.easing
369
target: backgroundGlass
370
duration: albumViewerTransition.duration
371
easingType: albumViewerTransition.easing
375
PropertyAction { target: expandAlbum; property: "visible"; value: false; }
382
album.closed = !hideStayingOpen || setAlbumClosedAtEnd;
384
transitionFromAlbumViewerCompleted();
389
id: dissolveAlbumViewerTransition
391
fadeOutTarget: dissolveDummy
392
fadeInTarget: dissolveDummy
393
easingType: albumViewerTransition.easing
397
dissolveCompleted(fadeOutTarget, fadeInTarget);