| 1 |
/* |
| 2 |
* Copyright (C) 2011-2015 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 <[email protected]> |
| 18 |
*/ |
| 19 |
|
| 20 |
import QtQuick 2.9 |
| 21 |
import "../Utility" |
| 22 |
import "../../js/GraphicsRoutines.js" as GraphicsRoutines |
| 23 |
|
| 24 |
// Some custom components and animations that we want to invoke whenever we |
| 25 |
// bring up the photo viewer. |
| 26 |
Item { |
| 27 |
id: photoViewerTransition |
| 28 |
objectName: "photoViewerTransition" |
| 29 |
|
| 30 |
// Read-only |
| 31 |
/*! |
| 32 |
*/ |
| 33 |
property bool animationRunning: showPhotoViewerAnimation.running || |
| 34 |
hidePhotoViewerAnimation.running || expandPhoto.visible || fadeRectangle.visible |
| 35 |
/*! |
| 36 |
*/ |
| 37 |
property alias forMediaSource: expandPhoto.mediaSource |
| 38 |
|
| 39 |
/*! |
| 40 |
*/ |
| 41 |
function transitionToPhotoViewer(photo, thumbnailRect) { |
| 42 |
expandPhoto.setOverThumbnail(photo, thumbnailRect); |
| 43 |
showPhotoViewerAnimation.start(); |
| 44 |
} |
| 45 |
|
| 46 |
/*! |
| 47 |
*/ |
| 48 |
function transitionFromPhotoViewer(photo, thumbnailRect) { |
| 49 |
expandPhoto.setOverThumbnail(photo, thumbnailRect); |
| 50 |
hidePhotoViewerAnimation.thumbnailRect = GraphicsRoutines.cloneRect(expandPhoto); |
| 51 |
|
| 52 |
// Start part of the way in so the jump to the scaled thumbnail isn't so noticeable. |
| 53 |
expandPhoto.x /= 10; |
| 54 |
expandPhoto.y /= 10; |
| 55 |
expandPhoto.width = parent.width - expandPhoto.x * 2; |
| 56 |
expandPhoto.height = parent.height - expandPhoto.y * 2; |
| 57 |
hidePhotoViewerAnimation.start(); |
| 58 |
} |
| 59 |
|
| 60 |
// Hides the transition. |
| 61 |
/*! |
| 62 |
*/ |
| 63 |
function hide() { |
| 64 |
expandPhoto.visible = false; |
| 65 |
fadeRectangle.visible = false; |
| 66 |
} |
| 67 |
|
| 68 |
/*! |
| 69 |
*/ |
| 70 |
signal transitionToPhotoViewerCompleted() |
| 71 |
/*! |
| 72 |
*/ |
| 73 |
signal transitionFromPhotoViewerCompleted() |
| 74 |
|
| 75 |
Rectangle { |
| 76 |
id: fadeRectangle |
| 77 |
|
| 78 |
visible: false |
| 79 |
color: "black" |
| 80 |
anchors.fill: parent |
| 81 |
} |
| 82 |
|
| 83 |
GalleryPhotoComponent { |
| 84 |
id: expandPhoto |
| 85 |
|
| 86 |
visible: false |
| 87 |
isCropped: false |
| 88 |
isPreview: true |
| 89 |
isAnimate: true |
| 90 |
ownerName: "PhotoViewerTransition" |
| 91 |
load: true |
| 92 |
|
| 93 |
color: "transparent" |
| 94 |
|
| 95 |
function setOverThumbnail(photo, thumbnailRect) { |
| 96 |
mediaSource = photo; |
| 97 |
|
| 98 |
x = thumbnailRect.x; |
| 99 |
y = thumbnailRect.y; |
| 100 |
width = thumbnailRect.width; |
| 101 |
height = thumbnailRect.height; |
| 102 |
|
| 103 |
// Expand the photo based on its real aspect ratio. |
| 104 |
if (width == paintedWidth) { |
| 105 |
var oldWidth = width; |
| 106 |
width *= height / paintedHeight; |
| 107 |
x += (oldWidth - width) / 2; |
| 108 |
} else { |
| 109 |
var oldHeight = height; |
| 110 |
height *= width / paintedWidth; |
| 111 |
y += (oldHeight - height) / 2; |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
SequentialAnimation { |
| 117 |
id: showPhotoViewerAnimation |
| 118 |
|
| 119 |
ParallelAnimation { |
| 120 |
SequentialAnimation { |
| 121 |
FadeInAnimation { target: expandPhoto; duration: 40; } |
| 122 |
ExpandAnimation { target: expandPhoto; duration: 160; } |
| 123 |
} |
| 124 |
FadeInAnimation { target: fadeRectangle; duration: 200; } |
| 125 |
} |
| 126 |
|
| 127 |
// Don't attempt to simplify this by rewriting it as a handler in response |
| 128 |
// to showPhotoViewerAnimation's onRunningChanged. Due to some timing |
| 129 |
// subtleties between the event thread and the QML animation thread, |
| 130 |
// emitting transitionToPhotoViewerCompleted() in response to |
| 131 |
// onRunningChanged can cause visual stuttering. |
| 132 |
ScriptAction { |
| 133 |
script: photoViewerTransition.transitionToPhotoViewerCompleted() |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
SequentialAnimation { |
| 138 |
id: hidePhotoViewerAnimation |
| 139 |
|
| 140 |
property variant thumbnailRect: {"x": 0, "y": 0, "width": 0, "height": 0} |
| 141 |
|
| 142 |
ParallelAnimation { |
| 143 |
FadeOutAnimation { target: fadeRectangle; duration: 200; } |
| 144 |
SequentialAnimation { |
| 145 |
PropertyAction { target: expandPhoto; property: "visible"; value: true; } |
| 146 |
ExpandAnimation { |
| 147 |
target: expandPhoto |
| 148 |
endX: hidePhotoViewerAnimation.thumbnailRect.x |
| 149 |
endY: hidePhotoViewerAnimation.thumbnailRect.y |
| 150 |
endWidth: hidePhotoViewerAnimation.thumbnailRect.width |
| 151 |
endHeight: hidePhotoViewerAnimation.thumbnailRect.height |
| 152 |
duration: 160 |
| 153 |
easingType: Easing.OutQuad |
| 154 |
} |
| 155 |
FadeOutAnimation { target: expandPhoto; duration: 40; } |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
onRunningChanged: { |
| 160 |
if (!running) |
| 161 |
transitionFromPhotoViewerCompleted(); |
| 162 |
} |
| 163 |
} |
| 164 |
} |