Changeset View
Changeset View
Standalone View
Standalone View
src/QuickEditor/SelectionRectangle.qml
Show All 21 Lines | |||||
22 | Item { | 22 | Item { | ||
23 | id: cropRectItem; | 23 | id: cropRectItem; | ||
24 | objectName: "cropRectItem"; | 24 | objectName: "cropRectItem"; | ||
25 | 25 | | |||
26 | property var drawCanvas: null; | 26 | property var drawCanvas: null; | ||
27 | property var imageElement: null; | 27 | property var imageElement: null; | ||
28 | property int minRectSize: 20; | 28 | property int minRectSize: 20; | ||
29 | property int mouseAreaSize: 20; | 29 | property int mouseAreaSize: 20; | ||
30 | property double zoomCenterX: -1; | ||||
31 | property double zoomCenterY: -1; | ||||
ngraham: `int`s please. | |||||
guotao: In HiDPI mode, It's not int | |||||
alexeymin: maybe `double` then? | |||||
Yup, see https://doc.qt.io/qt-5/qml-real.html for what is allowed. Using double seems to work for me in HiDPI mode (as opposed to int). rkflx: Yup, see https://doc.qt.io/qt-5/qml-real.html for what is allowed.
Using `double` seems to… | |||||
I don't really understand why those properties are called zx and zy. Could you come up with a more descriptive name? If not, at least add a comment here describing their purpose. rkflx: I don't really understand why those properties are called `zx` and `zy`. Could you come up with… | |||||
rkflx: Thank you, much better ;) | |||||
32 | | ||||
33 | function resetZoomCenter() { | ||||
34 | zoomCenterX = -1; | ||||
35 | zoomCenterY = -1; | ||||
36 | drawCanvas.requestPaint(); | ||||
37 | } | ||||
30 | 38 | | |||
31 | signal doubleClicked(); | 39 | signal doubleClicked(); | ||
32 | 40 | | |||
33 | onWidthChanged: { | 41 | onWidthChanged: { | ||
34 | var maxWidth = imageElement.width - x; | 42 | var maxWidth = imageElement.width - x; | ||
35 | if (width > maxWidth) { | 43 | if (width > maxWidth) { | ||
36 | width = maxWidth; | 44 | width = maxWidth; | ||
37 | } | 45 | } | ||
Show All 34 Lines | 72 | MouseArea { | |||
72 | 80 | | |||
73 | width: mouseAreaSize; | 81 | width: mouseAreaSize; | ||
74 | height: mouseAreaSize; | 82 | height: mouseAreaSize; | ||
75 | cursorShape: Qt.SizeFDiagCursor; | 83 | cursorShape: Qt.SizeFDiagCursor; | ||
76 | 84 | | |||
77 | onPressed: { | 85 | onPressed: { | ||
78 | brxLimit = (parent.x + parent.width) - minRectSize; | 86 | brxLimit = (parent.x + parent.width) - minRectSize; | ||
79 | bryLimit = (parent.y + parent.height) - minRectSize; | 87 | bryLimit = (parent.y + parent.height) - minRectSize; | ||
88 | parent.zoomCenterX = parent.x; | ||||
89 | parent.zoomCenterY = parent.y; | ||||
80 | } | 90 | } | ||
81 | 91 | | |||
82 | onPositionChanged: { | 92 | onPositionChanged: { | ||
83 | if ((parent.x + mouse.x) < brxLimit) { | 93 | if ((parent.x + mouse.x) < brxLimit) { | ||
84 | parent.x = parent.x + mouse.x; | 94 | parent.x = parent.x + mouse.x; | ||
85 | parent.width = parent.width - mouse.x; | 95 | parent.width = parent.width - mouse.x; | ||
96 | parent.zoomCenterX = parent.zoomCenterX + mouse.x; | ||||
86 | } | 97 | } | ||
87 | 98 | | |||
88 | if ((parent.y + mouse.y) < bryLimit) { | 99 | if ((parent.y + mouse.y) < bryLimit) { | ||
89 | parent.y = parent.y + mouse.y; | 100 | parent.y = parent.y + mouse.y; | ||
90 | parent.height = parent.height - mouse.y; | 101 | parent.height = parent.height - mouse.y; | ||
102 | parent.zoomCenterY = parent.zoomCenterY + mouse.y; | ||||
91 | } | 103 | } | ||
92 | 104 | | |||
93 | drawCanvas.requestPaint(); | 105 | drawCanvas.requestPaint(); | ||
94 | } | 106 | } | ||
107 | | ||||
108 | onReleased: { | ||||
109 | resetZoomCenter(); | ||||
110 | } | ||||
95 | } | 111 | } | ||
96 | 112 | | |||
97 | MouseArea { | 113 | MouseArea { | ||
98 | id: hTopRight; | 114 | id: hTopRight; | ||
99 | 115 | | |||
100 | property int brxLimit: 0; | 116 | property int brxLimit: 0; | ||
101 | property int bryLimit: 0; | 117 | property int bryLimit: 0; | ||
102 | 118 | | |||
103 | anchors.top: parent.top; | 119 | anchors.top: parent.top; | ||
104 | anchors.right: parent.right; | 120 | anchors.right: parent.right; | ||
105 | 121 | | |||
106 | width: mouseAreaSize; | 122 | width: mouseAreaSize; | ||
107 | height: mouseAreaSize; | 123 | height: mouseAreaSize; | ||
108 | cursorShape: Qt.SizeBDiagCursor; | 124 | cursorShape: Qt.SizeBDiagCursor; | ||
109 | 125 | | |||
110 | onPressed: { | 126 | onPressed: { | ||
111 | brxLimit = parent.x + mouseAreaSize + minRectSize; | 127 | brxLimit = parent.x + mouseAreaSize + minRectSize; | ||
112 | bryLimit = (parent.y + parent.height) - minRectSize; | 128 | bryLimit = (parent.y + parent.height) - minRectSize; | ||
129 | parent.zoomCenterX = parent.x + parent.width - 1; | ||||
130 | parent.zoomCenterY = parent.y; | ||||
113 | } | 131 | } | ||
114 | 132 | | |||
115 | onPositionChanged: { | 133 | onPositionChanged: { | ||
116 | if ((parent.x + parent.width + mouse.x) > brxLimit) { | 134 | if ((parent.x + parent.width + mouse.x) > brxLimit) { | ||
117 | parent.width = parent.width + mouse.x - mouseAreaSize + 1; | 135 | parent.width = parent.width + mouse.x - mouseAreaSize + 1; | ||
136 | parent.zoomCenterX = parent.zoomCenterX + mouse.x - mouseAreaSize + 1; | ||||
118 | } | 137 | } | ||
119 | 138 | | |||
120 | if ((parent.y + mouse.y) < bryLimit) { | 139 | if ((parent.y + mouse.y) < bryLimit) { | ||
121 | parent.y = parent.y + mouse.y; | 140 | parent.y = parent.y + mouse.y; | ||
122 | parent.height = parent.height - mouse.y; | 141 | parent.height = parent.height - mouse.y; | ||
142 | parent.zoomCenterY = parent.zoomCenterY + mouse.y; | ||||
123 | } | 143 | } | ||
124 | 144 | | |||
125 | drawCanvas.requestPaint(); | 145 | drawCanvas.requestPaint(); | ||
126 | } | 146 | } | ||
147 | | ||||
148 | onReleased: { | ||||
149 | resetZoomCenter(); | ||||
150 | } | ||||
127 | } | 151 | } | ||
128 | 152 | | |||
129 | MouseArea { | 153 | MouseArea { | ||
130 | id: hBottomLeft; | 154 | id: hBottomLeft; | ||
131 | 155 | | |||
132 | property int brxLimit: 0; | 156 | property int brxLimit: 0; | ||
133 | property int bryLimit: 0; | 157 | property int bryLimit: 0; | ||
134 | 158 | | |||
135 | anchors.bottom: parent.bottom; | 159 | anchors.bottom: parent.bottom; | ||
136 | anchors.left: parent.left; | 160 | anchors.left: parent.left; | ||
137 | 161 | | |||
138 | width: mouseAreaSize; | 162 | width: mouseAreaSize; | ||
139 | height: mouseAreaSize; | 163 | height: mouseAreaSize; | ||
140 | cursorShape: Qt.SizeBDiagCursor; | 164 | cursorShape: Qt.SizeBDiagCursor; | ||
141 | 165 | | |||
142 | onPressed: { | 166 | onPressed: { | ||
143 | brxLimit = (parent.x + parent.width) - minRectSize; | 167 | brxLimit = (parent.x + parent.width) - minRectSize; | ||
144 | bryLimit = parent.y + mouseAreaSize + minRectSize; | 168 | bryLimit = parent.y + mouseAreaSize + minRectSize; | ||
169 | parent.zoomCenterX = parent.x; | ||||
170 | parent.zoomCenterY = parent.y + parent.height - 1; | ||||
145 | } | 171 | } | ||
146 | 172 | | |||
147 | onPositionChanged: { | 173 | onPositionChanged: { | ||
148 | if ((parent.x + mouse.x) < brxLimit) { | 174 | if ((parent.x + mouse.x) < brxLimit) { | ||
149 | parent.x = parent.x + mouse.x; | 175 | parent.x = parent.x + mouse.x; | ||
150 | parent.width = parent.width - mouse.x; | 176 | parent.width = parent.width - mouse.x; | ||
177 | parent.zoomCenterX = parent.zoomCenterX + mouse.x; | ||||
151 | } | 178 | } | ||
152 | 179 | | |||
153 | if ((parent.y + parent.height + mouse.y) > bryLimit) { | 180 | if ((parent.y + parent.height + mouse.y) > bryLimit) { | ||
154 | parent.height = parent.height + mouse.y - mouseAreaSize + 1; | 181 | parent.height = parent.height + mouse.y - mouseAreaSize + 1; | ||
182 | parent.zoomCenterY = parent.zoomCenterY + mouse.y - mouseAreaSize + 1; | ||||
155 | } | 183 | } | ||
156 | 184 | | |||
157 | drawCanvas.requestPaint(); | 185 | drawCanvas.requestPaint(); | ||
158 | } | 186 | } | ||
187 | | ||||
188 | onReleased: { | ||||
189 | resetZoomCenter(); | ||||
190 | } | ||||
159 | } | 191 | } | ||
160 | 192 | | |||
161 | MouseArea { | 193 | MouseArea { | ||
162 | id: hBottomRight; | 194 | id: hBottomRight; | ||
163 | 195 | | |||
164 | property int brxLimit: 0; | 196 | property int brxLimit: 0; | ||
165 | property int bryLimit: 0; | 197 | property int bryLimit: 0; | ||
166 | 198 | | |||
167 | anchors.bottom: parent.bottom; | 199 | anchors.bottom: parent.bottom; | ||
168 | anchors.right: parent.right; | 200 | anchors.right: parent.right; | ||
169 | 201 | | |||
170 | width: mouseAreaSize; | 202 | width: mouseAreaSize; | ||
171 | height: mouseAreaSize; | 203 | height: mouseAreaSize; | ||
172 | cursorShape: Qt.SizeFDiagCursor; | 204 | cursorShape: Qt.SizeFDiagCursor; | ||
173 | 205 | | |||
174 | onPressed: { | 206 | onPressed: { | ||
175 | brxLimit = parent.x + mouseAreaSize + minRectSize; | 207 | brxLimit = parent.x + mouseAreaSize + minRectSize; | ||
176 | bryLimit = parent.y + mouseAreaSize + minRectSize; | 208 | bryLimit = parent.y + mouseAreaSize + minRectSize; | ||
209 | parent.zoomCenterX = parent.x + parent.width - 1; | ||||
210 | parent.zoomCenterY = parent.y + parent.height - 1; | ||||
177 | } | 211 | } | ||
178 | 212 | | |||
179 | onPositionChanged: { | 213 | onPositionChanged: { | ||
180 | if ((parent.x + parent.width + mouse.x) > brxLimit) { | 214 | if ((parent.x + parent.width + mouse.x) > brxLimit) { | ||
181 | parent.width = parent.width + mouse.x - mouseAreaSize + 1; | 215 | parent.width = parent.width + mouse.x - mouseAreaSize + 1; | ||
216 | parent.zoomCenterX = parent.zoomCenterX + mouse.x - mouseAreaSize + 1; | ||||
182 | } | 217 | } | ||
183 | 218 | | |||
184 | if ((parent.y + parent.height + mouse.y) > bryLimit) { | 219 | if ((parent.y + parent.height + mouse.y) > bryLimit) { | ||
185 | parent.height = parent.height + mouse.y - mouseAreaSize + 1; | 220 | parent.height = parent.height + mouse.y - mouseAreaSize + 1; | ||
221 | parent.zoomCenterY = parent.zoomCenterY + mouse.y - mouseAreaSize + 1; | ||||
186 | } | 222 | } | ||
187 | drawCanvas.requestPaint(); | 223 | drawCanvas.requestPaint(); | ||
188 | } | 224 | } | ||
225 | | ||||
226 | onReleased: { | ||||
227 | resetZoomCenter(); | ||||
228 | } | ||||
189 | } | 229 | } | ||
190 | 230 | | |||
191 | MouseArea { | 231 | MouseArea { | ||
192 | id: hTop; | 232 | id: hTop; | ||
193 | 233 | | |||
194 | property int limit: 0; | 234 | property int limit: 0; | ||
195 | 235 | | |||
196 | anchors.horizontalCenter: parent.horizontalCenter; | 236 | anchors.horizontalCenter: parent.horizontalCenter; | ||
197 | anchors.top: parent.top; | 237 | anchors.top: parent.top; | ||
198 | 238 | | |||
199 | width: mouseAreaSize; | 239 | width: mouseAreaSize; | ||
200 | height: mouseAreaSize; | 240 | height: mouseAreaSize; | ||
201 | cursorShape: Qt.SizeVerCursor; | 241 | cursorShape: Qt.SizeVerCursor; | ||
202 | 242 | | |||
203 | onPressed: { | 243 | onPressed: { | ||
204 | limit = (parent.y + parent.height) - minRectSize; | 244 | limit = (parent.y + parent.height) - minRectSize; | ||
245 | parent.zoomCenterX = parent.x + (parent.width >> 1) - mouseAreaSize / 2; | ||||
246 | parent.zoomCenterY = parent.y; | ||||
205 | } | 247 | } | ||
206 | 248 | | |||
207 | onPositionChanged: { | 249 | onPositionChanged: { | ||
208 | if ((parent.y + mouse.y) < limit) { | 250 | if ((parent.y + mouse.y) < limit) { | ||
209 | parent.y = parent.y + mouse.y; | 251 | parent.y = parent.y + mouse.y; | ||
210 | parent.height = parent.height - mouse.y; | 252 | parent.height = parent.height - mouse.y; | ||
253 | parent.zoomCenterY = parent.zoomCenterY + mouse.y; | ||||
211 | } | 254 | } | ||
212 | 255 | parent.zoomCenterX = parent.x + (parent.width >> 1) - mouseAreaSize / 2 + mouse.x + 1; | |||
213 | drawCanvas.requestPaint(); | 256 | drawCanvas.requestPaint(); | ||
214 | } | 257 | } | ||
258 | | ||||
259 | onReleased: { | ||||
260 | resetZoomCenter(); | ||||
261 | } | ||||
215 | } | 262 | } | ||
216 | 263 | | |||
217 | MouseArea { | 264 | MouseArea { | ||
218 | id: hBottom; | 265 | id: hBottom; | ||
219 | 266 | | |||
220 | property int limit: 0; | 267 | property int limit: 0; | ||
221 | 268 | | |||
222 | anchors.horizontalCenter: parent.horizontalCenter; | 269 | anchors.horizontalCenter: parent.horizontalCenter; | ||
223 | anchors.bottom: parent.bottom; | 270 | anchors.bottom: parent.bottom; | ||
224 | 271 | | |||
225 | width: mouseAreaSize; | 272 | width: mouseAreaSize; | ||
226 | height: mouseAreaSize; | 273 | height: mouseAreaSize; | ||
227 | cursorShape: Qt.SizeVerCursor; | 274 | cursorShape: Qt.SizeVerCursor; | ||
228 | 275 | | |||
229 | onPressed: { | 276 | onPressed: { | ||
230 | limit = parent.y + mouseAreaSize + minRectSize; | 277 | limit = parent.y + mouseAreaSize + minRectSize; | ||
278 | parent.zoomCenterX = parent.x + (parent.width >> 1) - mouseAreaSize / 2; | ||||
279 | parent.zoomCenterY = parent.y + parent.height - 1; | ||||
231 | } | 280 | } | ||
232 | 281 | | |||
233 | onPositionChanged: { | 282 | onPositionChanged: { | ||
234 | if ((parent.y + parent.height + mouse.y) > limit) { | 283 | if ((parent.y + parent.height + mouse.y) > limit) { | ||
235 | parent.height = parent.height + mouse.y - mouseAreaSize + 1; | 284 | parent.height = parent.height + mouse.y - mouseAreaSize + 1; | ||
285 | parent.zoomCenterY = parent.zoomCenterY + mouse.y - mouseAreaSize + 1; | ||||
236 | } | 286 | } | ||
237 | 287 | parent.zoomCenterX = parent.x + (parent.width >> 1) - mouseAreaSize / 2 + mouse.x + 1; | |||
238 | drawCanvas.requestPaint(); | 288 | drawCanvas.requestPaint(); | ||
239 | } | 289 | } | ||
290 | | ||||
291 | onReleased: { | ||||
292 | resetZoomCenter(); | ||||
293 | } | ||||
240 | } | 294 | } | ||
241 | 295 | | |||
242 | MouseArea { | 296 | MouseArea { | ||
243 | id: hLeft; | 297 | id: hLeft; | ||
244 | 298 | | |||
245 | property int limit: 0; | 299 | property int limit: 0; | ||
246 | 300 | | |||
247 | anchors.verticalCenter: parent.verticalCenter; | 301 | anchors.verticalCenter: parent.verticalCenter; | ||
248 | anchors.left: parent.left; | 302 | anchors.left: parent.left; | ||
249 | 303 | | |||
250 | width: mouseAreaSize; | 304 | width: mouseAreaSize; | ||
251 | height: mouseAreaSize; | 305 | height: mouseAreaSize; | ||
252 | cursorShape: Qt.SizeHorCursor; | 306 | cursorShape: Qt.SizeHorCursor; | ||
253 | 307 | | |||
254 | onPressed: { | 308 | onPressed: { | ||
255 | limit = (parent.x + parent.width) - minRectSize; | 309 | limit = (parent.x + parent.width) - minRectSize; | ||
310 | parent.zoomCenterX = parent.x; | ||||
311 | parent.zoomCenterY = parent.y + (parent.height >> 1) - mouseAreaSize / 2; | ||||
256 | } | 312 | } | ||
257 | 313 | | |||
258 | onPositionChanged: { | 314 | onPositionChanged: { | ||
259 | if ((parent.x + mouse.x) < limit) { | 315 | if ((parent.x + mouse.x) < limit) { | ||
260 | parent.x = parent.x + mouse.x; | 316 | parent.x = parent.x + mouse.x; | ||
261 | parent.width = parent.width - mouse.x; | 317 | parent.width = parent.width - mouse.x; | ||
318 | parent.zoomCenterX = parent.zoomCenterX + mouse.x; | ||||
262 | } | 319 | } | ||
263 | 320 | parent.zoomCenterY = parent.y + (parent.height >> 1) - mouseAreaSize / 2 + mouse.y + 1; | |||
264 | drawCanvas.requestPaint(); | 321 | drawCanvas.requestPaint(); | ||
265 | } | 322 | } | ||
323 | | ||||
324 | onReleased: { | ||||
325 | resetZoomCenter(); | ||||
326 | } | ||||
266 | } | 327 | } | ||
267 | 328 | | |||
268 | MouseArea { | 329 | MouseArea { | ||
269 | id: hRight; | 330 | id: hRight; | ||
270 | 331 | | |||
271 | property int limit: 0; | 332 | property int limit: 0; | ||
272 | 333 | | |||
273 | anchors.verticalCenter: parent.verticalCenter; | 334 | anchors.verticalCenter: parent.verticalCenter; | ||
274 | anchors.right: parent.right; | 335 | anchors.right: parent.right; | ||
275 | 336 | | |||
276 | width: mouseAreaSize; | 337 | width: mouseAreaSize; | ||
277 | height: mouseAreaSize; | 338 | height: mouseAreaSize; | ||
278 | cursorShape: Qt.SizeHorCursor; | 339 | cursorShape: Qt.SizeHorCursor; | ||
279 | 340 | | |||
280 | onPressed: { | 341 | onPressed: { | ||
281 | limit = parent.x + mouseAreaSize + minRectSize; | 342 | limit = parent.x + mouseAreaSize + minRectSize; | ||
343 | parent.zoomCenterX = parent.x + parent.width - 1; | ||||
344 | parent.zoomCenterY = parent.y + (parent.height >> 1) - mouseAreaSize / 2; | ||||
282 | } | 345 | } | ||
283 | 346 | | |||
284 | onPositionChanged: { | 347 | onPositionChanged: { | ||
285 | if ((parent.x + parent.width + mouse.x) > limit) { | 348 | if ((parent.x + parent.width + mouse.x) > limit) { | ||
286 | parent.width = parent.width + mouse.x - mouseAreaSize + 1; | 349 | parent.width = parent.width + mouse.x - mouseAreaSize + 1; | ||
350 | parent.zoomCenterX = parent.zoomCenterX + mouse.x - mouseAreaSize + 1; | ||||
287 | } | 351 | } | ||
288 | 352 | parent.zoomCenterY = parent.y + (parent.height >> 1) - mouseAreaSize / 2 + mouse.y + 1; | |||
289 | drawCanvas.requestPaint(); | 353 | drawCanvas.requestPaint(); | ||
290 | } | 354 | } | ||
355 | | ||||
356 | onReleased: { | ||||
357 | resetZoomCenter(); | ||||
358 | } | ||||
291 | } | 359 | } | ||
292 | } | 360 | } |
ints please.