2 * Copyright 2014 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
17 * Daniel d'Andrada <daniel.dandrada@canonical.com>
21 import Ubuntu.Components 1.1
22 import "../Components"
27 // to be read from outside
28 readonly property bool dragged: dragArea.moving
32 // to be set from outside
33 property bool interactive: true
34 property bool dropShadow: true
35 property real maximizedAppTopMargin
36 property alias swipeToCloseEnabled: dragArea.enabled
37 property bool closeable
38 property alias application: appWindow.application
39 property int orientation
42 objectName: "appWindowWithShadow"
44 readonly property real limit: root.height / 4
46 y: root.closeable ? dragArea.distance : elastic(dragArea.distance)
50 function elastic(distance) {
51 var k = distance < 0 ? -limit : limit
52 return k * (1 - Math.pow((k - 1) / k, distance))
60 source: "graphics/dropshadow2gu.sci"
61 opacity: root.dropShadow ? .3 : 0
62 Behavior on opacity { UbuntuNumberAnimation {} }
67 objectName: application ? "appWindow_" + application.appId : "appWindow_null"
71 topMargin: appWindow.fullscreen ? 0 : maximizedAppTopMargin
74 interactive: root.interactive
75 orientation: root.orientation
81 objectName: "dragArea"
84 property bool moving: false
85 property real distance: 0
86 readonly property int threshold: units.gu(2)
87 property int offset: 0
89 readonly property real minSpeedToClose: units.gu(40)
95 moving = moving || Math.abs(dragValue) > threshold;
97 distance = dragValue + offset;
103 offset = (dragValue > 0 ? -threshold: threshold)
116 if (!root.closeable) {
117 animation.animate("center")
121 // velocity and distance values specified by design prototype
122 if ((dragVelocity < -minSpeedToClose && distance < -units.gu(8)) || distance < -root.height / 2) {
123 animation.animate("up")
124 } else if ((dragVelocity > minSpeedToClose && distance > units.gu(8)) || distance > root.height / 2) {
125 animation.animate("down")
127 animation.animate("center")
131 UbuntuNumberAnimation {
133 objectName: "closeAnimation"
136 property bool requestClose: false
138 function animate(direction) {
139 animation.from = dragArea.distance;
142 animation.to = -root.height * 1.5;
146 animation.to = root.height * 1.5;
157 dragArea.moving = false;
161 dragArea.distance = 0;