Debian Codegraph @

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

raw
1 import QtQuick
2 import QtQuick.Controls
3
4 import Muse.Ui
5 import Muse.UiComponents
6
7 import Audacity.ProjectScene
8 import Audacity.Project
9
10 Rectangle {
11
12 id: root
13
14 property bool clipHovered: false
15 color: ui.theme.backgroundPrimaryColor
16
17 TracksListClipsModel {
18 id: tracksModel
19
20 onTotalTracksHeightChanged: {
21 timeline.context.onResizeFrameContentHeight(tracksModel.totalTracksHeight)
22 }
23 }
24
25 ProjectPropertiesModel {
26 id: project
27
28 onCaptureThumbnail: function captureThumbnail() {
29 // hide playCursor for the time grabbing image
30 playCursor.visible = false
31 content.grabToImage(function(result) {
32 playCursor.visible = true
33 result.saveToFile(project.thumbnailUrl)
34 })
35 }
36 }
37
38 //! NOTE Sync with TracksPanel
39 TracksViewStateModel {
40 id: tracksViewState
41 onTracksVericalYChanged: {
42 tracksClipsView.contentY = tracksViewState.tracksVericalY
43 }
44 }
45
46 PlayCursorController {
47 id: playCursorController
48 context: timeline.context
49 }
50
51 PlayPositionActionController {
52 id: playPositionActionController
53 context: timeline.context
54 }
55
56 SelectionViewController {
57 id: selectionController
58 context: timeline.context
59 }
60
61 Component.onCompleted: {
62 //! NOTE Models depend on geometry, so let's create a page first and then initialize the models
63 Qt.callLater(root.init)
64 }
65
66 function init() {
67 timeline.init()
68 playCursorController.init()
69 playPositionActionController.init()
70 tracksViewState.init()
71 project.init()
72 //! NOTE Loading tracks, or rather clips, is the most havy operation.
73 // Let's make sure that everything is loaded and initialized before this,
74 // to avoid double loading at the beginning, when some parameters are initialized.
75 Qt.callLater(tracksModel.load)
76 }
77
78 Rectangle {
79 id: timelineIndent
80 anchors.top: parent.top
81 anchors.left: parent.left
82 height: timeline.height
83 width: content.anchors.leftMargin
84 color: timeline.color
85
86 SeparatorLine {
87 id: topBorder
88 width: parent.width
89 anchors.bottom: parent.bottom
90 color: ui.theme.strokeColor
91 }
92 }
93
94 Rectangle {
95 id: canvasIndent
96 anchors.top: timelineIndent.bottom
97 anchors.bottom: parent.bottom
98 height: timeline.height
99 width: content.anchors.leftMargin
100 color: ui.theme.backgroundTertiaryColor
101 }
102
103 Timeline {
104 id: timeline
105
106 anchors.top: parent.top
107 anchors.left: timelineIndent.right
108 anchors.right: parent.right
109
110 clip: true
111
112 height: 40
113
114 function updateCursorPosition(x) {
115 lineCursor.x = x
116 timeline.context.updateMousePositionTime(x)
117 }
118
119 MouseArea {
120 id: timelineMouseArea
121 anchors.fill: parent
122 hoverEnabled: true
123
124 onPositionChanged: function(e) {
125 timeline.updateCursorPosition(e.x)
126
127 if (pressed) {
128 playCursorController.seekToX(e.x)
129 }
130 }
131
132 onClicked: function (e) {
133 playCursorController.seekToX(e.x)
134 }
135 }
136
137 Rectangle {
138 id: lineCursor
139
140 y: parent.top
141 height: timeline.height
142 width: 1
143
144 color: ui.theme.fontPrimaryColor
145 }
146
147 Rectangle {
148 id: timelineSelRect
149
150 x: timeline.context.selectionStartPosition
151 width: timeline.context.selectionEndPosition - x
152
153 anchors.top: parent.top
154 anchors.bottom: parent.bottom
155
156 color: "#ABE7FF"
157 opacity: 0.3
158 }
159 }
160
161 Rectangle {
162 id: content
163 objectName: "clipsView"
164 anchors.leftMargin: 12
165 anchors.top: timeline.bottom
166 anchors.bottom: parent.bottom
167 anchors.left: parent.left
168 anchors.right: parent.right
169
170 // anchors.leftMargin: 130
171 // anchors.rightMargin: 130
172
173 GridLines {
174 timelineRuler: timeline.ruler
175 anchors.fill: parent
176 }
177
178 MouseArea {
179 id: mainMouseArea
180 anchors.fill: parent
181
182 property bool mouseOnTracks: false
183 property bool isNeedSelectionCursor: !selectionController.selectionActive && mainMouseArea.mouseOnTracks
184 hoverEnabled: true
185 onContainsMouseChanged: {
186 if (!containsMouse) {
187 mouseOnTracks = false
188 }
189 }
190 onIsNeedSelectionCursorChanged: {
191 if (isNeedSelectionCursor) {
192 tracksViewState.setOverrideCursor(Qt.IBeamCursor)
193 } else {
194 tracksViewState.resetOverrideCursor()
195 }
196 }
197
198 onWheel: function(wheelEvent) {
199 timeline.onWheel(wheelEvent.x, wheelEvent.pixelDelta, wheelEvent.angleDelta)
200 }
201
202 onPressed: function(e) {
203 playCursorController.seekToX(e.x)
204 selectionController.onPressed(e.x, e.y)
205 selectionController.resetSelectedClip()
206 clipsSelection.visible = true
207 }
208 onPositionChanged: function(e) {
209 mouseOnTracks = e.y < tracksClipsView.visibleContentHeight
210 selectionController.onPositionChanged(e.x, e.y)
211
212 timeline.updateCursorPosition(e.x)
213
214 if (root.clipHovered) {
215 root.clipHovered = false
216 }
217 }
218 onReleased: e => {
219 if (selectionController.isLeftSelection(e.x)) {
220 playCursorController.seekToX(e.x)
221 }
222 selectionController.onReleased(e.x, e.y)
223 clipsSelection.visible = false
224 }
225
226 onClicked: e => {
227 if (!root.clipHovered) {
228 selectionController.resetSelectedClip()
229 }
230 }
231 }
232
233 StyledViewScrollAndZoomArea {
234 id: tracksClipsViewArea
235
236 anchors.fill: parent
237
238 view: tracksClipsView
239
240 horizontalScrollbarSize: timeline.context.horizontalScrollbarSize
241 startHorizontalScrollPosition: timeline.context.startHorizontalScrollPosition
242
243 verticalScrollbarSize: timeline.context.verticalScrollbarSize
244 startVerticalScrollPosition: timeline.context.startVerticalScrollPosition
245
246 StyledListView {
247 id: tracksClipsView
248
249 anchors.fill: parent
250 clip: true
251
252 property real visibleContentHeight: tracksModel.totalTracksHeight - tracksClipsView.contentY
253
254 ScrollBar.horizontal: null
255 ScrollBar.vertical: null
256
257 onContentYChanged: {
258 tracksViewState.changeTracksVericalY(tracksClipsView.contentY)
259 timeline.context.startVerticalScrollPosition = tracksClipsView.contentY
260 }
261
262 onHeightChanged: {
263 timeline.context.onResizeFrameHeight(tracksClipsView.height)
264 }
265
266 Connections {
267 target: timeline.context
268
269 function onViewContentYChangeRequested(contentY) {
270 if (tracksClipsView.contentY + contentY + tracksClipsView.height > tracksModel.totalTracksHeight) {
271 tracksClipsView.contentY += tracksModel.totalTracksHeight - (tracksClipsView.contentY + tracksClipsView.height)
272 } else if (tracksClipsView.contentY + contentY < 0) {
273 tracksClipsView.contentY = 0
274 } else {
275 tracksClipsView.contentY += contentY
276 }
277 }
278 }
279
280 interactive: false
281
282 model: tracksModel
283
284 delegate: TrackClipsItem {
285 width: tracksClipsView.width
286 context: timeline.context
287 canvas: content
288 trackId: model.trackId
289 isDataSelected: model.isDataSelected
290 isTrackSelected: model.isTrackSelected
291
292 onTrackItemMousePositionChanged: function(xWithinTrack, yWithinTrack) {
293 timeline.updateCursorPosition(xWithinTrack)
294
295 if (!root.clipHovered) {
296 root.clipHovered = true
297 }
298 }
299
300 onClipSelectedRequested: {
301 selectionController.resetDataSelection()
302 clipsSelection.visible = false
303 }
304
305 onSelectionDraged: function(x1, x2, completed) {
306 selectionController.onSelectionDraged(x1, x2, completed)
307 }
308
309 onSeekToX: function(x) {
310 playCursorController.seekToX(x)
311 }
312 }
313 }
314
315 onPinchToZoom: function(scale, pos) {
316 timeline.context.pinchToZoom(scale, pos)
317 }
318
319 onScrollHorizontal: function(newPos) {
320 timeline.context.scrollHorizontal(newPos)
321 }
322
323 onScrollVertical: function(newPos) {
324 timeline.context.scrollVertical(newPos)
325 }
326 }
327
328 Rectangle {
329 id: clipsSelection
330
331 anchors.top: parent.top
332 anchors.bottom: parent.bottom
333 color: "#ABE7FF"
334 opacity: 0.05
335 visible: false
336
337 x: timeline.context.selectionStartPosition
338 width: timeline.context.selectionEndPosition - x
339 }
340
341 PlayCursor {
342 id: playCursor
343 anchors.top: tracksClipsViewArea.top
344 anchors.bottom: parent.bottom
345 x: playCursorController.positionX
346 z: 2
347 timelinePressed: timelineMouseArea.pressed
348
349 onSetPlaybackPosition: function(ix) {
350 playCursorController.seekToX(ix)
351 }
352
353 onPlayCursorMousePositionChanged: function(ix) {
354 timeline.updateCursorPosition(ix)
355 }
356 }
357
358 VerticalRulersPanel {
359 id: verticalRulers
360
361 height: parent.height - timeline.height
362 anchors.right: tracksClipsViewArea.right
363 anchors.bottom: tracksClipsViewArea.bottom
364
365 visible: tracksModel.isVerticalRulersVisible
366 }
367 }
368 }