Debian Codegraph @

au4/src/projectscene/qml/Audacity/ProjectScene/clipsview/ClipHandles.qml

raw
1 import QtQuick
2
3 import Muse.Ui
4 import Muse.UiComponents
5
6 Item {
7 id: root
8
9 property var canvas: null
10 property bool handlesHovered: false
11 property bool handlesVisible: false
12
13 property int animationDuration: 100
14
15 property bool debugRectsVisible: false
16
17 // mouse position event is not propagated on overlapping mouse areas
18 // so we are handling it manually
19 signal clipHandlesMousePositionChanged(real x, real y)
20
21 property var trimStartPos
22
23 signal clipStartEditRequested()
24 signal clipEndEditRequested()
25
26 signal trimLeftRequested(bool completed)
27 signal trimRightRequested(bool completed)
28
29 Item {
30 id: leftTrimHandle
31
32 x: -24
33 height: 32
34 width: 36
35
36 visible: handlesVisible
37
38 Rectangle {
39 anchors.fill: parent
40
41 color: "transparent"
42 border.width: 1
43 border.color: "blue"
44
45 visible: debugRectsVisible
46 }
47
48
49 StyledIconLabel {
50 id: leftArrow
51 anchors.verticalCenter: leftTrimHandle.verticalCenter
52 anchors.left: leftTrimHandle.left
53 // specific icon pivot
54 anchors.leftMargin: -5
55
56 iconCode: IconCode.SMALL_ARROW_LEFT
57 font.pixelSize: 30
58 color: "black"
59 style: Text.Outline
60 styleColor: "white"
61
62 Rectangle {
63 height: 12
64 width: 12
65 anchors.verticalCenter: leftArrow.verticalCenter
66 anchors.horizontalCenter: leftArrow.horizontalCenter
67
68 color: "transparent"
69 border.color: "red"
70 border.width: 1
71
72 visible: debugRectsVisible
73 }
74 }
75
76 MouseArea {
77 id: leftTrimMa
78
79 anchors.fill: parent
80 hoverEnabled: true
81
82 onPressed: function(e) {
83 root.clipStartEditRequested()
84 }
85
86 onReleased: function(e) {
87 root.trimLeftRequested(true)
88
89 // this needs to be always at the very end
90 root.clipEndEditRequested()
91 }
92
93 onEntered: {
94 handlesHovered = true
95 }
96
97 onExited: {
98 if (!leftTimeMa.containsMouse) {
99 handlesHovered = false
100 }
101 }
102
103 onPositionChanged: function(e) {
104 clipHandlesMousePositionChanged(mouseX + leftTrimHandle.x, mouseY)
105
106 if (pressed) {
107 root.trimLeftRequested(false)
108 }
109 }
110 }
111 }
112
113 Item {
114 id: rightTrimHandle
115
116 x: parent.width - 12
117 height: 32
118 width: 36
119
120 visible: handlesVisible
121
122 Rectangle {
123 anchors.fill: parent
124
125 color: "transparent"
126 border.width: 1
127 border.color: "blue"
128
129 visible: debugRectsVisible
130 }
131
132 StyledIconLabel {
133 id: rightArrow
134 anchors.verticalCenter: rightTrimHandle.verticalCenter
135 anchors.right: rightTrimHandle.right
136 // specific icon pivot
137 anchors.rightMargin: -5
138
139 iconCode: IconCode.SMALL_ARROW_RIGHT
140 font.pixelSize: 30
141 color: "black"
142 style: Text.Outline
143 styleColor: "white"
144
145 Rectangle {
146 height: 12
147 width: 12
148 anchors.verticalCenter: rightArrow.verticalCenter
149 anchors.horizontalCenter: rightArrow.horizontalCenter
150 color: "transparent"
151
152 border.color: "red"
153 border.width: 1
154
155 visible: debugRectsVisible
156 }
157 }
158
159 MouseArea {
160 id: rightTrimMa
161
162 anchors.fill: parent
163 hoverEnabled: true
164
165 onPressed: function(e) {
166 root.clipStartEditRequested()
167 }
168
169 onReleased: function(e) {
170 root.trimRightRequested(true)
171
172 // this needs to be always at the very end
173 root.clipEndEditRequested()
174 }
175
176 onEntered: {
177 handlesHovered = true
178 }
179
180 onExited: {
181 if (!rightTimeMa.containsMouse) {
182 handlesHovered = false
183 }
184 }
185
186 onPositionChanged: function(e) {
187 clipHandlesMousePositionChanged(mouseX + rightTrimHandle.x, mouseY)
188
189 if (pressed) {
190 root.trimRightRequested(false)
191 }
192 }
193 }
194 }
195
196 Item {
197 id: leftTimecode
198
199 x: -24
200 y: leftTrimHandle.height
201 height: 32
202 width: 36
203
204 visible: handlesVisible
205
206 Rectangle {
207 anchors.fill: parent
208
209 color: "transparent"
210 border.width: 1
211 border.color: "blue"
212
213 visible: debugRectsVisible
214 }
215
216 Rectangle {
217 id: leftClock
218
219 width: leftClockIcon.font.pixelSize - 2
220 height: leftClockIcon.font.pixelSize - 2
221 radius: (leftClockIcon.font.pixelSize - 2) / 2
222 anchors.verticalCenter: leftTimecode.verticalCenter
223 anchors.left: leftTimecode.left
224 anchors.leftMargin: 4
225
226 color: "black"
227
228 StyledIconLabel {
229 id: leftClockIcon
230
231 anchors.centerIn: parent
232
233 iconCode: IconCode.CLOCK
234 font.pixelSize: 14
235 color: "white"
236
237 Rectangle {
238 height: 12
239 width: 12
240 anchors.verticalCenter: leftClockIcon.verticalCenter
241 anchors.horizontalCenter: leftClockIcon.horizontalCenter
242 color: "transparent"
243
244 border.color: "red"
245 border.width: 1
246
247 visible: debugRectsVisible
248 }
249 }
250 }
251
252 MouseArea {
253 id: leftTimeMa
254 anchors.fill: parent
255 hoverEnabled: true
256
257 onPressed: {
258 //! TODO AU4: implement time-stretch
259 }
260
261 onReleased: {
262 //! TODO AU4: implement time-stretch
263 }
264
265 onEntered: {
266 handlesHovered = true
267 }
268
269 onExited: {
270 if (!leftTrimMa.containsMouse && mouseY > 2) {
271 handlesHovered = false
272 }
273 }
274
275 onPositionChanged: {
276 clipHandlesMousePositionChanged(mouseX + leftTimecode.x, mouseY)
277 }
278 }
279 }
280
281 Item {
282 id: rightTimecode
283
284 x: parent.width - 12
285 y: rightTrimHandle.height
286 height: 32
287 width: 36
288
289 visible: handlesVisible
290
291 Rectangle {
292 anchors.fill: parent
293
294 color: "transparent"
295 border.width: 1
296 border.color: "blue"
297 visible: debugRectsVisible
298 }
299
300 Rectangle {
301 id: rightClock
302
303 width: (rightClockIcon.font.pixelSize - 2)
304 height: (rightClockIcon.font.pixelSize - 2)
305 radius: (rightClockIcon.font.pixelSize - 2) / 2
306 anchors.verticalCenter: rightTimecode.verticalCenter
307 anchors.right: rightTimecode.right
308 anchors.rightMargin: 4
309
310 color: "black"
311
312 StyledIconLabel {
313 id: rightClockIcon
314
315 anchors.centerIn: parent
316 iconCode: IconCode.CLOCK
317 font.pixelSize: 14
318 color: "white"
319
320 Rectangle {
321 height: 12
322 width: 12
323 anchors.verticalCenter: rightClockIcon.verticalCenter
324 anchors.horizontalCenter: rightClockIcon.horizontalCenter
325 color: "transparent"
326
327 border.color: "red"
328 border.width: 1
329 visible: debugRectsVisible
330 }
331 }
332 }
333
334 MouseArea {
335 id: rightTimeMa
336 anchors.fill: parent
337 hoverEnabled: true
338
339 onPressed: {
340 //! TODO AU4: implement time-stretch
341 }
342
343 onReleased: {
344 //! TODO AU4: implement time-stretch
345 }
346
347 onEntered: {
348 handlesHovered = true
349 }
350
351 onExited: {
352 if (!rightTrimMa.containsMouse && mouseY > 2) {
353 handlesHovered = false
354 }
355 }
356
357 onPositionChanged: {
358 clipHandlesMousePositionChanged(mouseX + rightTimecode.x, mouseY)
359 }
360 }
361 }
362
363 state: "NORMAL"
364 states: [
365 State {
366 name: "NORMAL"
367 when: !leftTrimMa.containsMouse && !rightTrimMa.containsMouse && !leftTimeMa.containsMouse && !rightTimeMa.containsMouse
368 },
369
370 State {
371 name: "LEFT_TRIM_HOVERED"
372 when: leftTrimMa.containsMouse
373 PropertyChanges { target: leftArrow; font.pixelSize: 40 }
374 PropertyChanges { target: leftArrow; anchors.leftMargin: -10}
375 },
376
377 State {
378 name: "RIGHT_TRIM_HOVERED"
379 when: rightTrimMa.containsMouse
380 PropertyChanges { target: rightArrow; font.pixelSize: 40 }
381 PropertyChanges { target: rightArrow; anchors.rightMargin: -10}
382 },
383
384 State {
385 name: "LEFT_TIME_HOVERED"
386 when: leftTimeMa.containsMouse
387 PropertyChanges { target: leftClockIcon; font.pixelSize: 18 }
388 PropertyChanges { target: leftClock; anchors.leftMargin: 2 }
389 },
390
391 State {
392 name: "RIGHT_TIME_HOVERED"
393 when: rightTimeMa.containsMouse
394 PropertyChanges { target: rightClockIcon; font.pixelSize: 18 }
395 PropertyChanges { target: rightClock; anchors.rightMargin: 2 }
396 }
397 ]
398
399 transitions: [
400 Transition {
401 from: "*"
402 to: "*"
403 reversible: true
404
405 PropertyAnimation {
406 target: leftArrow
407 properties: "font.pixelSize"
408 duration: animationDuration
409 easing.type: Easing.Linear
410 }
411 PropertyAnimation {
412 target: leftArrow
413 properties: "anchors.leftMargin"
414 duration: animationDuration
415 easing.type: Easing.Linear
416 }
417 PropertyAnimation {
418 target: rightArrow
419 properties: "font.pixelSize"
420 duration: animationDuration
421 easing.type: Easing.Linear
422 }
423 PropertyAnimation {
424 target: rightArrow
425 properties: "anchors.rightMargin"
426 duration: animationDuration
427 easing.type: Easing.Linear
428 }
429 PropertyAnimation {
430 target: leftClockIcon
431 properties: "font.pixelSize"
432 duration: animationDuration
433 easing.type: Easing.Linear
434 }
435 PropertyAnimation {
436 target: leftClock
437 properties: "anchors.leftMargin"
438 duration: animationDuration
439 easing.type: Easing.Linear
440 }
441 PropertyAnimation {
442 target: rightClockIcon
443 properties: "font.pixelSize"
444 duration: animationDuration
445 easing.type: Easing.Linear
446 }
447 PropertyAnimation {
448 target: rightClock
449 properties: "anchors.rightMargin"
450 duration: animationDuration
451 easing.type: Easing.Linear
452 }
453 }
454 ]
455 }