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/>.
18
import Ubuntu.Components 1.3
19
import Utils 0.1 // For EdgeBarrierSettings
20
import "../Components/PanelState"
24
visible: opacity > 0 && target && !target.anyMaximized // we go from 0.2 to 0.5
27
border.width: units.dp(2)
28
border.color: "#99ffffff"
30
scale: progress > 0 && progress <= hintThreshold ? MathUtils.projectValue(progress, 0.0, 1.0, 1, 2) : 1
31
opacity: progress > 0 ? MathUtils.projectValue(progress, 0.0, 1.0, 0.2, 0.5) : 0
33
property int edge: -1 // Item.TransformOrigin
34
property var target // appDelegate
35
property int leftMargin
36
property real appContainerWidth
37
property real appContainerHeight
39
readonly property real hintThreshold: 0.1
42
// Value range is [0.0, 1.0]
43
readonly property real progress: priv.directProgress != -1 ? priv.directProgress : priv.accumulatedProgress
45
signal passed(int origin)
50
readonly property real accumulatedProgress: MathUtils.clamp(accumulatedPush / EdgeBarrierSettings.pushThreshold, 0.0, 1.0)
51
property real directProgress: -1
52
property real accumulatedPush: 0
54
function push(amount) {
55
if (accumulatedPush === EdgeBarrierSettings.pushThreshold) {
60
if (accumulatedPush + amount > EdgeBarrierSettings.pushThreshold) {
61
accumulatedPush = EdgeBarrierSettings.pushThreshold;
63
accumulatedPush += amount;
66
if (accumulatedPush === EdgeBarrierSettings.pushThreshold) {
68
// commit(); // NB: uncomment to have automatic maximization on 100% progress
72
function setup(edge) {
73
if (edge !== fakeRectangle.edge) {
74
stop(); // a different edge, start anew
76
fakeRectangle.x = target.x;
77
fakeRectangle.y = target.y;
78
fakeRectangle.width = target.width;
79
fakeRectangle.height = target.height;
80
fakeRectangle.edge = edge;
81
fakeRectangle.transformOrigin = edge;
84
function processAnimation(amount, animation, isProgress) {
86
priv.directProgress = amount;
88
priv.directProgress = -1;
92
if (progress > hintThreshold) { // above 10% we start the full preview animation
99
if (progress > hintThreshold && edge != -1) {
100
if (edge == Item.Top) {
102
} else if (edge == Item.Left) {
103
target.maximizeLeft();
104
} else if (edge == Item.Right) {
105
target.maximizeRight();
106
} else if (edge == Item.TopLeft) {
107
target.maximizeTopLeft();
108
} else if (edge == Item.TopRight) {
109
target.maximizeTopRight();
110
} else if (edge == Item.BottomLeft) {
111
target.maximizeBottomLeft();
112
} else if (edge == Item.BottomRight) {
113
target.maximizeBottomRight();
121
priv.accumulatedPush = 0;
122
priv.directProgress = -1;
126
function maximize(amount, isProgress) {
127
if (fakeRectangle.edge != Item.Top) {
128
priv.setup(Item.Top);
130
priv.processAnimation(amount, fakeMaximizeAnimation, isProgress);
133
function maximizeLeft(amount, isProgress) {
134
if (fakeRectangle.edge != Item.Left) {
135
priv.setup(Item.Left);
137
priv.processAnimation(amount, fakeMaximizeLeftAnimation, isProgress);
140
function maximizeRight(amount, isProgress) {
141
if (fakeRectangle.edge != Item.Right) {
142
priv.setup(Item.Right);
144
priv.processAnimation(amount, fakeMaximizeRightAnimation, isProgress);
147
function maximizeTopLeft(amount, isProgress) {
148
if (fakeRectangle.edge != Item.TopLeft) {
149
priv.setup(Item.TopLeft);
151
priv.processAnimation(amount, fakeMaximizeTopLeftAnimation, isProgress);
154
function maximizeTopRight(amount, isProgress) {
155
if (fakeRectangle.edge != Item.TopRight) {
156
priv.setup(Item.TopRight);
158
priv.processAnimation(amount, fakeMaximizeTopRightAnimation, isProgress);
161
function maximizeBottomLeft(amount, isProgress) {
162
if (fakeRectangle.edge != Item.BottomLeft) {
163
priv.setup(Item.BottomLeft);
165
priv.processAnimation(amount, fakeMaximizeBottomLeftAnimation, isProgress);
168
function maximizeBottomRight(amount, isProgress) {
169
if (fakeRectangle.edge != Item.BottomRight) {
170
priv.setup(Item.BottomRight);
172
priv.processAnimation(amount, fakeMaximizeBottomRightAnimation, isProgress);
175
Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.BriskDuration } }
176
Behavior on scale { UbuntuNumberAnimation { duration: UbuntuAnimation.BriskDuration } }
179
id: fakeMaximizeAnimation
180
UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: leftMargin }
181
UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: PanelState.panelHeight }
182
UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: appContainerWidth - leftMargin }
183
UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight }
187
id: fakeMaximizeLeftAnimation
188
UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: leftMargin }
189
UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: PanelState.panelHeight }
190
UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
191
UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight - PanelState.panelHeight }
195
id: fakeMaximizeRightAnimation
196
UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth + leftMargin)/2 }
197
UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: PanelState.panelHeight }
198
UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
199
UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight - PanelState.panelHeight }
203
id: fakeMaximizeTopLeftAnimation
204
UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: leftMargin }
205
UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: PanelState.panelHeight }
206
UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
207
UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: (appContainerHeight - PanelState.panelHeight)/2 }
211
id: fakeMaximizeTopRightAnimation
212
UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth + leftMargin)/2 }
213
UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: PanelState.panelHeight }
214
UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
215
UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: (appContainerHeight - PanelState.panelHeight)/2 }
219
id: fakeMaximizeBottomLeftAnimation
220
UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: leftMargin }
221
UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: (appContainerHeight + PanelState.panelHeight)/2 }
222
UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
223
UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight/2 }
227
id: fakeMaximizeBottomRightAnimation
228
UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth + leftMargin)/2 }
229
UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: (appContainerHeight + PanelState.panelHeight)/2 }
230
UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
231
UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight/2 }