Unity 8
WindowedRightEdgeMaths.qml
1 /*
2  * Copyright (C) 2016 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 as published by
6  * the Free Software Foundation; version 3.
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 
17 import QtQuick 2.12
18 import Ubuntu.Components 1.3
19 import Unity.Application 0.1
20 import "MathUtils.js" as MathUtils
21 
22 QtObject {
23  id: root
24 
25  // Input
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
39 
40  // Config
41  property real breakPoint: 0.4
42 
43  // internal
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)
48  } else {
49  return swipeProgress;
50  }
51  }
52 
53  // Output
54 
55  readonly property real scaleToPreviewProgress: {
56  return progress < breakPoint ? 0 : MathUtils.clamp(MathUtils.linearAnimation(breakPoint, 1, 0, 1, progress), 0, 1)
57  }
58  readonly property int animatedWidth: {
59  return progress < breakPoint ? root.startWidth : MathUtils.linearAnimation(breakPoint, 1, root.startWidth, targetHeight, progress)
60  }
61 
62  readonly property int animatedHeight: {
63  return progress < breakPoint ? root.startHeight : MathUtils.linearAnimation(breakPoint, 1, root.startHeight, targetHeight, progress)
64  }
65 
66  readonly property int animatedX: {
67  if (progress < breakPoint) {
68  return startX;
69  }
70  return MathUtils.linearAnimation(breakPoint, 1, startX, targetX, progress)
71  }
72 
73  readonly property int animatedY: progress < breakPoint ? startY : MathUtils.linearAnimation(breakPoint, 1, startY, targetY, progress)
74 
75  readonly property real animatedAngle: progress < breakPoint ? 0 : MathUtils.linearAnimation(breakPoint, 1, 0, targetAngle, progress);
76 
77  readonly property real decorationHeight: progress < breakPoint ? 1 : MathUtils.linearAnimation(breakPoint, 1, 1, 0, progress);
78 
79  readonly property int animatedZ: {
80  if (progress < breakPoint + (1 - breakPoint) / 2) {
81  if (swipeProgress > 0) {
82  return itemIndex == 1 ? normalZ + 2 : normalZ
83  }
84  if (pushProgress > 0) {
85  return normalZ;
86  }
87  }
88  return itemIndex
89  }
90 
91  readonly property real opacityMask: (swipeProgress > 0 && itemIndex == 1) ? MathUtils.linearAnimation(0, breakPoint, 0, 1, progress) : 1
92 
93  readonly property real animatedScale: progress < breakPoint ? 1 : MathUtils.linearAnimation(breakPoint, 1, 1, targetScale, progress)
94 
95 // readonly property bool itemVisible: true //animatedX < sceneWidth
96 }