2 * Copyright (C) 2016 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 as published by
6 * the Free Software Foundation; version 3.
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/>.
18import Lomiri.Components 1.3
19import QtMir.Application 0.1
20import "MathUtils.js" as MathUtils
26 property int itemIndex: 0
27 property int normalZ: 0
28 property int startWidth: 0
29 property int startHeight: 0
30 property int startX: 0
31 property int targetX: 0
32 property int startY: 0
33 property int targetY: 0
34 property real targetAngle: 0
35 property int targetHeight: 0
36 property real targetScale: 0
37 property real swipeProgress: 0
38 property real pushProgress: 0
41 property real breakPoint: 0.4
44 readonly property real progress: {
45 if (pushProgress > 0) {
46 // we don't do the full animation when pushing, just a little bit
47 return MathUtils.linearAnimation(0, 1, 0, breakPoint + .1, pushProgress)
55 readonly property real scaleToPreviewProgress: {
56 return progress < breakPoint ? 0 : MathUtils.clamp(MathUtils.linearAnimation(breakPoint, 1, 0, 1, progress), 0, 1)
58 readonly property int animatedWidth: {
59 return progress < breakPoint ? root.startWidth : MathUtils.linearAnimation(breakPoint, 1, root.startWidth, targetHeight, progress)
62 readonly property int animatedHeight: {
63 return progress < breakPoint ? root.startHeight : MathUtils.linearAnimation(breakPoint, 1, root.startHeight, targetHeight, progress)
66 readonly property int animatedX: {
67 if (progress < breakPoint) {
70 return MathUtils.linearAnimation(breakPoint, 1, startX, targetX, progress)
73 readonly property int animatedY: progress < breakPoint ? startY : MathUtils.linearAnimation(breakPoint, 1, startY, targetY, progress)
75 readonly property real animatedAngle: progress < breakPoint ? 0 : MathUtils.linearAnimation(breakPoint, 1, 0, targetAngle, progress);
77 readonly property real decorationHeight: progress < breakPoint ? 1 : MathUtils.linearAnimation(breakPoint, 1, 1, 0, progress);
79 readonly property int animatedZ: {
80 if (progress < breakPoint + (1 - breakPoint) / 2) {
81 if (swipeProgress > 0) {
82 return itemIndex == 1 ? normalZ + 2 : normalZ
84 if (pushProgress > 0) {
91 readonly property real opacityMask: (swipeProgress > 0 && itemIndex == 1) ? MathUtils.linearAnimation(0, breakPoint, 0, 1, progress) : 1
93 readonly property real animatedScale: progress < breakPoint ? 1 : MathUtils.linearAnimation(breakPoint, 1, 1, targetScale, progress)
95// readonly property bool itemVisible: true //animatedX < sceneWidth