Unity 8
BaseSessionAnimation.qml
1 /*
2  * Copyright (C) 2014 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.4
18 
19 /* This is the base case for surface animations, used when adding/removing * child surfaces.
20  * The class is meant to be overridden and changes/animations provided for state changes.
21  * NB. It is important to release the surface at the end of the "out" animation.
22  *
23  * Example - Simple fade in/out
24  *
25  * BaseSurfaceAnimation {
26  * outChanges: [ PropertyChanges { target: animation.surface; opacity: 0.0 } ]
27  * outAnimations: [
28  SequentialAnimation {
29  * NumberAnimation { target: animation.surface; property: "opacity"; duration: 300 }
30  * ScriptAction { script: { if (animation.parent.removing) animation.surface.release(); } }
31  * }
32  * ]
33  *
34  * inChanges: [ PropertyChanges { target: animation.surface; opacity: 1.0 } ]
35  * inAnimations: [ NumberAnimation { target: animation.surface; property: "opacity"; duration: 300 } ]
36  * }
37  */
38 Item {
39  id: base
40  property var container
41  objectName: "sessionAnimation"
42 
43  // changes applied when state changes to "from"
44  property list<QtObject> fromChanges
45  // transition animations when changing state to "from"
46  property list<QtObject> fromAnimations
47 
48  // changes applied when state changes to "to"
49  property list<QtObject> toChanges
50  // transition animations when changing state to "to"
51  property list<QtObject> toAnimations
52 
53  function start() {
54  // "prep" state forces toChanges without transition animations.
55  state = "prep"
56  state = "to";
57  }
58  function end() {
59  state = "from";
60  }
61 
62  signal completed()
63 
64  states: [
65  State {
66  name: "baseAnimation"
67  PropertyChanges { target: container; anchors.fill: undefined }
68  },
69 
70  State {
71  name: "prep"
72  extend: "baseAnimation"
73  changes: fromChanges
74  },
75  State {
76  name: "from"
77  extend: "prep"
78  },
79  State {
80  name: "in"
81  extend: "baseAnimation"
82  changes: toChanges
83  }
84  ]
85 
86  transitions: [
87  Transition {
88  to: "from"
89  animations: fromAnimations
90  },
91  Transition {
92  to: "to"
93  animations: toAnimations
94  }
95  ]
96 }