Lomiri
MoveHandler.qml
1/*
2 * Copyright (C) 2014-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
17import QtQuick 2.12
18import QtMir.Application 0.1 // For Mir singleton
19import Lomiri.Components 1.3
20import Utils 0.1
21import "../Components"
22
23QtObject {
24 id: root
25
26 property Item target // appDelegate
27 property real buttonsWidth: 0
28 property Item boundsItem
29 property real boundsTopMargin: 0
30
31 readonly property bool dragging: priv.dragging
32 readonly property bool moving: priv.moving
33
34 signal fakeMaximizeAnimationRequested(real amount)
35 signal fakeMaximizeLeftAnimationRequested(real amount)
36 signal fakeMaximizeRightAnimationRequested(real amount)
37 signal fakeMaximizeTopLeftAnimationRequested(real amount)
38 signal fakeMaximizeTopRightAnimationRequested(real amount)
39 signal fakeMaximizeBottomLeftAnimationRequested(real amount)
40 signal fakeMaximizeBottomRightAnimationRequested(real amount)
41 signal stopFakeAnimation()
42
43 property QtObject priv: QtObject {
44 property real distanceX
45 property real distanceY
46 property bool dragging
47 property bool moving
48
49 readonly property int triggerArea: units.gu(8)
50 property bool nearLeftEdge: target && target.maximizedLeft
51 property bool nearTopEdge: target && target.maximized
52 property bool nearRightEdge: target && target.maximizedRight
53 property bool nearTopLeftCorner: target && target.maximizedTopLeft
54 property bool nearTopRightCorner: target && target.maximizedTopRight
55 property bool nearBottomLeftCorner: target && target.maximizedBottomLeft
56 property bool nearBottomRightCorner: target && target.maximizedBottomRight
57
58 property Timer mouseDownTimer: Timer {
59 interval: 175
60 onTriggered: Mir.cursorName = "grabbing"
61 }
62
63 function resetEdges() {
64 nearLeftEdge = false;
65 nearRightEdge = false;
66 nearTopEdge = false;
67 nearTopLeftCorner = false;
68 nearTopRightCorner = false;
69 nearBottomLeftCorner = false;
70 nearBottomRightCorner = false;
71 }
72
73 // return the progress of mouse pointer movement from 0 to 1 within a corner square of the screen
74 // 0 -> before the mouse enters the square
75 // 1 -> mouse is in the outer corner
76 // a is the corner, b is the mouse pos
77 function progressInCorner(ax, ay, bx, by) {
78 // distance of two points, a and b, in pixels
79 var distance = Math.sqrt(Math.pow(bx-ax, 2) + Math.pow(by-ay, 2));
80 // length of the triggerArea square diagonal