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/>.
18import Lomiri.Components 1.3
19import Utils 0.1 // For EdgeBarrierSettings
20import "../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
38 property PanelState panelState
40 readonly property real hintThreshold: 0.1
43 // Value range is [0.0, 1.0]
44 readonly property real progress: priv.directProgress != -1 ? priv.directProgress : priv.accumulatedProgress
46 signal passed(int origin)
51 readonly property real accumulatedProgress: MathUtils.clamp(accumulatedPush / EdgeBarrierSettings.pushThreshold, 0.0, 1.0)
52 property real directProgress: -1
53 property real accumulatedPush: 0
55 function push(amount) {
56 if (accumulatedPush === EdgeBarrierSettings.pushThreshold) {
61 if (accumulatedPush + amount > EdgeBarrierSettings.pushThreshold) {
62 accumulatedPush = EdgeBarrierSettings.pushThreshold;
64 accumulatedPush += amount;
67 if (accumulatedPush === EdgeBarrierSettings.pushThreshold) {
69 // commit(); // NB: uncomment to have automatic maximization on 100% progress
73 function setup(edge) {
74 if (edge !== fakeRectangle.edge) {
75 stop(); // a different edge, start anew
77 fakeRectangle.x = target.x;
78 fakeRectangle.y = target.y;
79 fakeRectangle.width = target.width;
80 fakeRectangle.height = target.height;
81 fakeRectangle.edge = edge;
82 fakeRectangle.transformOrigin = edge;
85 function processAnimation(amount, animation, isProgress) {
87 priv.directProgress = amount;
89 priv.directProgress = -1;
93 if (progress > hintThreshold) { // above 10% we start the full preview animation
100 if (progress > hintThreshold && edge != -1) {
101 if (edge == Item.Top) {
102 target.requestMaximize();
103 } else if (edge == Item.Left) {
104 target.requestMaximizeLeft();
105 } else if (edge == Item.Right) {
106 target.requestMaximizeRight();
107 } else if (edge == Item.TopLeft) {
108 target.requestMaximizeTopLeft();
109 } else if (edge == Item.TopRight) {
110 target.requestMaximizeTopRight();
111 } else if (edge == Item.BottomLeft) {
112 target.requestMaximizeBottomLeft();
113 } else if (edge == Item.BottomRight) {
114 target.requestMaximizeBottomRight();
122 priv.accumulatedPush = 0;
123 priv.directProgress = -1;
127 function maximize(amount, isProgress) {
128 if (fakeRectangle.edge != Item.Top) {
129 priv.setup(Item.Top);
131 priv.processAnimation(amount, fakeMaximizeAnimation, isProgress);
134 function maximizeLeft(amount, isProgress) {
135 if (fakeRectangle.edge != Item.Left) {
136 priv.setup(Item.Left);
138 priv.processAnimation(amount, fakeMaximizeLeftAnimation, isProgress);
141 function maximizeRight(amount, isProgress) {
142 if (fakeRectangle.edge != Item.Right) {
143 priv.setup(Item.Right);
145 priv.processAnimation(amount, fakeMaximizeRightAnimation, isProgress);
148 function maximizeTopLeft(amount, isProgress) {
149 if (fakeRectangle.edge != Item.TopLeft) {
150 priv.setup(Item.TopLeft);
152 priv.processAnimation(amount, fakeMaximizeTopLeftAnimation, isProgress);
155 function maximizeTopRight(amount, isProgress) {
156 if (fakeRectangle.edge != Item.TopRight) {
157 priv.setup(Item.TopRight);
159 priv.processAnimation(amount, fakeMaximizeTopRightAnimation, isProgress);
162 function maximizeBottomLeft(amount, isProgress) {
163 if (fakeRectangle.edge != Item.BottomLeft) {
164 priv.setup(Item.BottomLeft);
166 priv.processAnimation(amount, fakeMaximizeBottomLeftAnimation, isProgress);
169 function maximizeBottomRight(amount, isProgress) {
170 if (fakeRectangle.edge != Item.BottomRight) {
171 priv.setup(Item.BottomRight);
173 priv.processAnimation(amount, fakeMaximizeBottomRightAnimation, isProgress);
176 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.BriskDuration } }
177 Behavior on scale { LomiriNumberAnimation { duration: LomiriAnimation.BriskDuration } }
180 id: fakeMaximizeAnimation
181 LomiriNumberAnimation { target: fakeRectangle; properties: "x"; duration: LomiriAnimation.BriskDuration; to: leftMargin }
182 LomiriNumberAnimation { target: fakeRectangle; properties: "y"; duration: LomiriAnimation.BriskDuration; to: panelState.panelHeight }
183 LomiriNumberAnimation { target: fakeRectangle; properties: "width"; duration: LomiriAnimation.BriskDuration; to: appContainerWidth - leftMargin }
184 LomiriNumberAnimation { target: fakeRectangle; properties: "height"; duration: LomiriAnimation.BriskDuration; to: appContainerHeight }
188 id: fakeMaximizeLeftAnimation
189 LomiriNumberAnimation { target: fakeRectangle; properties: "x"; duration: LomiriAnimation.BriskDuration; to: leftMargin }
190 LomiriNumberAnimation { target: fakeRectangle; properties: "y"; duration: LomiriAnimation.BriskDuration; to: panelState.panelHeight }
191 LomiriNumberAnimation { target: fakeRectangle; properties: "width"; duration: LomiriAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
192 LomiriNumberAnimation { target: fakeRectangle; properties: "height"; duration: LomiriAnimation.BriskDuration; to: appContainerHeight - panelState.panelHeight }
196 id: fakeMaximizeRightAnimation
197 LomiriNumberAnimation { target: fakeRectangle; properties: "x"; duration: LomiriAnimation.BriskDuration; to: (appContainerWidth + leftMargin)/2 }
198 LomiriNumberAnimation { target: fakeRectangle; properties: "y"; duration: LomiriAnimation.BriskDuration; to: panelState.panelHeight }
199 LomiriNumberAnimation { target: fakeRectangle; properties: "width"; duration: LomiriAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
200 LomiriNumberAnimation { target: fakeRectangle; properties: "height"; duration: LomiriAnimation.BriskDuration; to: appContainerHeight - panelState.panelHeight }
204 id: fakeMaximizeTopLeftAnimation
205 LomiriNumberAnimation { target: fakeRectangle; properties: "x"; duration: LomiriAnimation.BriskDuration; to: leftMargin }
206 LomiriNumberAnimation { target: fakeRectangle; properties: "y"; duration: LomiriAnimation.BriskDuration; to: panelState.panelHeight }
207 LomiriNumberAnimation { target: fakeRectangle; properties: "width"; duration: LomiriAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
208 LomiriNumberAnimation { target: fakeRectangle; properties: "height"; duration: LomiriAnimation.BriskDuration; to: (appContainerHeight - panelState.panelHeight)/2 }
212 id: fakeMaximizeTopRightAnimation
213 LomiriNumberAnimation { target: fakeRectangle; properties: "x"; duration: LomiriAnimation.BriskDuration; to: (appContainerWidth + leftMargin)/2 }
214 LomiriNumberAnimation { target: fakeRectangle; properties: "y"; duration: LomiriAnimation.BriskDuration; to: panelState.panelHeight }
215 LomiriNumberAnimation { target: fakeRectangle; properties: "width"; duration: LomiriAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
216 LomiriNumberAnimation { target: fakeRectangle; properties: "height"; duration: LomiriAnimation.BriskDuration; to: (appContainerHeight - panelState.panelHeight)/2 }
220 id: fakeMaximizeBottomLeftAnimation
221 LomiriNumberAnimation { target: fakeRectangle; properties: "x"; duration: LomiriAnimation.BriskDuration; to: leftMargin }
222 LomiriNumberAnimation { target: fakeRectangle; properties: "y"; duration: LomiriAnimation.BriskDuration; to: (appContainerHeight + panelState.panelHeight)/2 }
223 LomiriNumberAnimation { target: fakeRectangle; properties: "width"; duration: LomiriAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
224 LomiriNumberAnimation { target: fakeRectangle; properties: "height"; duration: LomiriAnimation.BriskDuration; to: appContainerHeight/2 }
228 id: fakeMaximizeBottomRightAnimation
229 LomiriNumberAnimation { target: fakeRectangle; properties: "x"; duration: LomiriAnimation.BriskDuration; to: (appContainerWidth + leftMargin)/2 }
230 LomiriNumberAnimation { target: fakeRectangle; properties: "y"; duration: LomiriAnimation.BriskDuration; to: (appContainerHeight + panelState.panelHeight)/2 }
231 LomiriNumberAnimation { target: fakeRectangle; properties: "width"; duration: LomiriAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
232 LomiriNumberAnimation { target: fakeRectangle; properties: "height"; duration: LomiriAnimation.BriskDuration; to: appContainerHeight/2 }