~unity-team/unity8/dash-only

« back to all changes in this revision

Viewing changes to qml/Stages/FakeMaximizeDelegate.qml

  • Committer: Kevin Gunn
  • Date: 2016-10-24 19:51:33 UTC
  • Revision ID: kevin.gunn@canonical.com-20161024195133-61lwdzzdwsnue1mn
shave some more

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2016 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
 
import Ubuntu.Components 1.3
19
 
import Utils 0.1 // For EdgeBarrierSettings
20
 
import "../Components/PanelState"
21
 
 
22
 
Rectangle {
23
 
    id: fakeRectangle
24
 
    visible: opacity > 0 && target && !target.anyMaximized // we go from 0.2 to 0.5
25
 
    enabled: visible
26
 
    color: "#ffffff"
27
 
    border.width: units.dp(2)
28
 
    border.color: "#99ffffff"
29
 
 
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
32
 
 
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
 
 
39
 
    readonly property real hintThreshold: 0.1
40
 
 
41
 
    // Edge push progress
42
 
    // Value range is [0.0, 1.0]
43
 
    readonly property real progress: priv.directProgress != -1 ? priv.directProgress : priv.accumulatedProgress
44
 
 
45
 
    signal passed(int origin)
46
 
 
47
 
    QtObject {
48
 
        id: priv
49
 
 
50
 
        readonly property real accumulatedProgress: MathUtils.clamp(accumulatedPush / EdgeBarrierSettings.pushThreshold, 0.0, 1.0)
51
 
        property real directProgress: -1
52
 
        property real accumulatedPush: 0
53
 
 
54
 
        function push(amount) {
55
 
            if (accumulatedPush === EdgeBarrierSettings.pushThreshold) {
56
 
                // NO-OP
57
 
                return;
58
 
            }
59
 
 
60
 
            if (accumulatedPush + amount > EdgeBarrierSettings.pushThreshold) {
61
 
                accumulatedPush = EdgeBarrierSettings.pushThreshold;
62
 
            } else {
63
 
                accumulatedPush += amount;
64
 
            }
65
 
 
66
 
            if (accumulatedPush === EdgeBarrierSettings.pushThreshold) {
67
 
                passed(edge);
68
 
                // commit(); // NB: uncomment to have automatic maximization on 100% progress
69
 
            }
70
 
        }
71
 
 
72
 
        function setup(edge) {
73
 
            if (edge !== fakeRectangle.edge) {
74
 
                stop(); // a different edge, start anew
75
 
            }
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;
82
 
        }
83
 
 
84
 
        function processAnimation(amount, animation, isProgress) {
85
 
            if (isProgress) {
86
 
                priv.directProgress = amount;
87
 
            } else {
88
 
                priv.directProgress = -1;
89
 
                priv.push(amount);
90
 
            }
91
 
 
92
 
            if (progress > hintThreshold) { // above 10% we start the full preview animation
93
 
                animation.start();
94
 
            }
95
 
        }
96
 
    }
97
 
 
98
 
    function commit() {
99
 
        if (progress > hintThreshold && edge != -1) {
100
 
            if (edge == Item.Top) {
101
 
                target.maximize();
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();
114
 
            }
115
 
        } else {
116
 
            stop();
117
 
        }
118
 
    }
119
 
 
120
 
    function stop() {
121
 
        priv.accumulatedPush = 0;
122
 
        priv.directProgress = -1;
123
 
        edge = -1;
124
 
    }
125
 
 
126
 
    function maximize(amount, isProgress) {
127
 
        if (fakeRectangle.edge != Item.Top) {
128
 
            priv.setup(Item.Top);
129
 
        }
130
 
        priv.processAnimation(amount, fakeMaximizeAnimation, isProgress);
131
 
    }
132
 
 
133
 
    function maximizeLeft(amount, isProgress) {
134
 
        if (fakeRectangle.edge != Item.Left) {
135
 
            priv.setup(Item.Left);
136
 
        }
137
 
        priv.processAnimation(amount, fakeMaximizeLeftAnimation, isProgress);
138
 
    }
139
 
 
140
 
    function maximizeRight(amount, isProgress) {
141
 
        if (fakeRectangle.edge != Item.Right) {
142
 
            priv.setup(Item.Right);
143
 
        }
144
 
        priv.processAnimation(amount, fakeMaximizeRightAnimation, isProgress);
145
 
    }
146
 
 
147
 
    function maximizeTopLeft(amount, isProgress) {
148
 
        if (fakeRectangle.edge != Item.TopLeft) {
149
 
            priv.setup(Item.TopLeft);
150
 
        }
151
 
        priv.processAnimation(amount, fakeMaximizeTopLeftAnimation, isProgress);
152
 
    }
153
 
 
154
 
    function maximizeTopRight(amount, isProgress) {
155
 
        if (fakeRectangle.edge != Item.TopRight) {
156
 
            priv.setup(Item.TopRight);
157
 
        }
158
 
        priv.processAnimation(amount, fakeMaximizeTopRightAnimation, isProgress);
159
 
    }
160
 
 
161
 
    function maximizeBottomLeft(amount, isProgress) {
162
 
        if (fakeRectangle.edge != Item.BottomLeft) {
163
 
            priv.setup(Item.BottomLeft);
164
 
        }
165
 
        priv.processAnimation(amount, fakeMaximizeBottomLeftAnimation, isProgress);
166
 
    }
167
 
 
168
 
    function maximizeBottomRight(amount, isProgress) {
169
 
        if (fakeRectangle.edge != Item.BottomRight) {
170
 
            priv.setup(Item.BottomRight);
171
 
        }
172
 
        priv.processAnimation(amount, fakeMaximizeBottomRightAnimation, isProgress);
173
 
    }
174
 
 
175
 
    Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.BriskDuration } }
176
 
    Behavior on scale { UbuntuNumberAnimation { duration: UbuntuAnimation.BriskDuration } }
177
 
 
178
 
    ParallelAnimation {
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 }
184
 
    }
185
 
 
186
 
    ParallelAnimation {
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 }
192
 
    }
193
 
 
194
 
    ParallelAnimation {
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 }
200
 
    }
201
 
 
202
 
    ParallelAnimation {
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 }
208
 
    }
209
 
 
210
 
    ParallelAnimation {
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 }
216
 
    }
217
 
 
218
 
    ParallelAnimation {
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 }
224
 
    }
225
 
 
226
 
    ParallelAnimation {
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 }
232
 
    }
233
 
}