Changeset View
Changeset View
Standalone View
Standalone View
components/containmentlayoutmanager/qml/ConfigOverlayWithHandles.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2019 Marco Martin <mart@kde.org> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU Library General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU Library General Public License for more details | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Library General Public | ||||
15 | * License along with this program; if not, write to the | ||||
16 | * Free Software Foundation, Inc., | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | import QtQuick 2.12 | ||||
21 | import QtQuick.Layouts 1.1 | ||||
22 | | ||||
23 | import org.kde.plasma.core 2.0 as PlasmaCore | ||||
24 | import org.kde.plasma.components 3.0 as PlasmaComponents | ||||
25 | | ||||
26 | import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager | ||||
27 | | ||||
28 | import "private" | ||||
29 | | ||||
30 | ContainmentLayoutManager.ConfigOverlay { | ||||
31 | id: overlay | ||||
32 | | ||||
33 | opacity: open | ||||
34 | Behavior on opacity { | ||||
35 | OpacityAnimator { | ||||
36 | duration: units.longDuration | ||||
37 | easing.type: Easing.InOutQuad | ||||
38 | } | ||||
39 | } | ||||
40 | | ||||
41 | MultiPointTouchArea { | ||||
42 | anchors.fill: parent | ||||
43 | property real previousMinX | ||||
44 | property real previousMinY | ||||
45 | property real previousMaxX | ||||
46 | property real previousMaxY | ||||
47 | property bool pinching: false | ||||
48 | mouseEnabled: false | ||||
49 | maximumTouchPoints: 2 | ||||
50 | touchPoints: [ | ||||
51 | TouchPoint { id: point1 }, | ||||
52 | TouchPoint { id: point2 } | ||||
53 | ] | ||||
54 | | ||||
55 | onPressed: { | ||||
56 | overlay.itemContainer.layout.releaseSpace(overlay.itemContainer); | ||||
57 | previousMinX = point1.sceneX; | ||||
58 | previousMinY = point1.sceneY; | ||||
59 | } | ||||
60 | | ||||
61 | onUpdated: { | ||||
62 | var minX; | ||||
63 | var minY; | ||||
64 | var maxX; | ||||
65 | var maxY; | ||||
66 | | ||||
67 | if (point1.pressed && point2.pressed) { | ||||
68 | minX = Math.min(point1.sceneX, point2.sceneX); | ||||
69 | minY = Math.min(point1.sceneY, point2.sceneY); | ||||
70 | | ||||
71 | maxX = Math.max(point1.sceneX, point2.sceneX); | ||||
72 | maxY = Math.max(point1.sceneY, point2.sceneY); | ||||
73 | } else { | ||||
74 | minX = point1.pressed ? point1.sceneX : point2.sceneX; | ||||
75 | minY = point1.pressed ? point1.sceneY : point2.sceneY; | ||||
76 | maxX = -1; | ||||
77 | maxY = -1; | ||||
78 | } | ||||
79 | | ||||
80 | if (pinching == (point1.pressed && point2.pressed)) { | ||||
81 | overlay.itemContainer.x += minX - previousMinX; | ||||
82 | overlay.itemContainer.y += minY - previousMinY; | ||||
83 | | ||||
84 | if (pinching) { | ||||
85 | overlay.itemContainer.width += maxX - previousMaxX + previousMinX - minX; | ||||
86 | overlay.itemContainer.height += maxY - previousMaxY + previousMinY - minY; | ||||
87 | } | ||||
88 | overlay.itemContainer.layout.showPlaceHolderForItem(overlay.itemContainer); | ||||
89 | } | ||||
90 | | ||||
91 | pinching = point1.pressed && point2.pressed | ||||
92 | previousMinX = minX; | ||||
93 | previousMinY = minY; | ||||
94 | previousMaxX = maxX; | ||||
95 | previousMaxY = maxY; | ||||
96 | } | ||||
97 | onReleased: { | ||||
98 | if (point1.pressed || point2.pressed) { | ||||
99 | return; | ||||
100 | } | ||||
101 | overlay.itemContainer.layout.positionItem(overlay.itemContainer); | ||||
102 | overlay.itemContainer.layout.hidePlaceHolder(); | ||||
103 | pinching = false | ||||
104 | } | ||||
105 | onCanceled: released() | ||||
106 | } | ||||
107 | | ||||
108 | BasicResizeHandle { | ||||
109 | resizeCorner: ContainmentLayoutManager.ResizeHandle.TopLeft | ||||
110 | anchors { | ||||
111 | horizontalCenter: parent.left | ||||
112 | verticalCenter: parent.top | ||||
113 | } | ||||
114 | } | ||||
115 | BasicResizeHandle { | ||||
116 | resizeCorner: ContainmentLayoutManager.ResizeHandle.Left | ||||
117 | anchors { | ||||
118 | horizontalCenter: parent.left | ||||
119 | verticalCenter: parent.verticalCenter | ||||
120 | } | ||||
121 | } | ||||
122 | BasicResizeHandle { | ||||
123 | resizeCorner: ContainmentLayoutManager.ResizeHandle.BottomLeft | ||||
124 | anchors { | ||||
125 | horizontalCenter: parent.left | ||||
126 | verticalCenter: parent.bottom | ||||
127 | } | ||||
128 | } | ||||
129 | BasicResizeHandle { | ||||
130 | resizeCorner: ContainmentLayoutManager.ResizeHandle.Bottom | ||||
131 | anchors { | ||||
132 | horizontalCenter: parent.horizontalCenter | ||||
133 | verticalCenter: parent.bottom | ||||
134 | } | ||||
135 | } | ||||
136 | BasicResizeHandle { | ||||
137 | resizeCorner: ContainmentLayoutManager.ResizeHandle.BottomRight | ||||
138 | anchors { | ||||
139 | horizontalCenter: parent.right | ||||
140 | verticalCenter: parent.bottom | ||||
141 | } | ||||
142 | } | ||||
143 | BasicResizeHandle { | ||||
144 | resizeCorner: ContainmentLayoutManager.ResizeHandle.Right | ||||
145 | anchors { | ||||
146 | horizontalCenter: parent.right | ||||
147 | verticalCenter: parent.verticalCenter | ||||
148 | } | ||||
149 | } | ||||
150 | BasicResizeHandle { | ||||
151 | resizeCorner: ContainmentLayoutManager.ResizeHandle.TopRight | ||||
152 | anchors { | ||||
153 | horizontalCenter: parent.right | ||||
154 | verticalCenter: parent.top | ||||
155 | } | ||||
156 | } | ||||
157 | BasicResizeHandle { | ||||
158 | resizeCorner: ContainmentLayoutManager.ResizeHandle.Top | ||||
159 | anchors { | ||||
160 | horizontalCenter: parent.horizontalCenter | ||||
161 | verticalCenter: parent.top | ||||
162 | } | ||||
163 | } | ||||
164 | } | ||||
165 | |