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
41 objectName: "appWindowWithShadow"
52 source: "graphics/dropshadow2gu.sci"
53 opacity: root.dropShadow ? .3 : 0
54 Behavior on opacity { UbuntuNumberAnimation {} }
61 topMargin: appWindow.fullscreen ? 0 : maximizedAppTopMargin
64 interactive: root.interactive
70 objectName: "dragArea"
73 property bool moving: false
74 property real distance: 0
76 readonly property real minSpeedToClose: units.gu(40)
82 moving = moving || Math.abs(dragValue) > units.gu(1)
95 if (!root.closeable) {
96 animation.animate("center")
100 // velocity and distance values specified by design prototype
101 if ((dragVelocity < -minSpeedToClose && distance < -units.gu(8)) || distance < -root.height / 2) {
102 animation.animate("up")
103 } else if ((dragVelocity > minSpeedToClose && distance > units.gu(8)) || distance > root.height / 2) {
104 animation.animate("down")
106 animation.animate("center")
110 UbuntuNumberAnimation {
112 objectName: "closeAnimation"
115 property bool requestClose: false
117 function animate(direction) {
118 animation.from = dragArea.distance;
121 animation.to = -root.height * 1.5;
125 animation.to = root.height * 1.5;
136 dragArea.moving = false;
140 dragArea.distance = 0;