timeline.qml 85.7 KB
Newer Older
1
2
3
import QtQuick 2.11
import QtQml.Models 2.11
import QtQuick.Controls 2.4
4
import Kdenlive.Controls 1.0
5
6
7
8
9
10
11
import 'Timeline.js' as Logic

Rectangle {
    id: root
    objectName: "timelineview"
    SystemPalette { id: activePalette }
    color: activePalette.window
12
    property bool validMenu: false
13
    property color textColor: activePalette.text
14
15
    property var groupTrimData
    property bool dragInProgress: dragProxyArea.pressed || dragProxyArea.drag.active || groupTrimData != undefined
16

17
    signal clipClicked()
18
    signal mousePosChanged(int position)
19
    signal showClipMenu(int cid)
20
    signal showCompositionMenu()
21
    signal showTimelineMenu()
22
23
    signal showRulerMenu()
    signal showHeaderMenu()
24
    signal showTargetMenu(int ix)
25
26
    signal zoomIn(bool onMouse)
    signal zoomOut(bool onMouse)
27
    signal processingDrag(bool dragging)
Sashmita Raghav's avatar
Sashmita Raghav committed
28
    signal showSubtitleClipMenu()
29

30
31
    FontMetrics {
        id: fontMetrics
32
        font: miniFont
33
    }
34

35
36
37
38
    onDragInProgressChanged: {
        processingDrag(!root.dragInProgress)
    }

39
40
41
42
    function endBinDrag() {
        clipDropArea.processDrop()
    }

43
44
45
46
47
    function fitZoom() {
        return scrollView.width / (timeline.duration * 1.1)
    }

    function scrollPos() {
48
        return scrollView.contentX
49
50
51
    }

    function goToStart(pos) {
52
        scrollView.contentX = pos
53
54
    }

55
56
57
58
59
60
61
62
    function switchSubtitleTrack() {
        if (subtitleTrack.height > root.collapsedHeight) {
            subtitleTrack.height = root.collapsedHeight
        } else {
            subtitleTrack.height = 5 * root.baseUnit
        }
    }
    
63
64
65
66
    function checkDeletion(itemId) {
        if (dragProxy.draggedItem == itemId) {
            endDrag()
        }
67
68
69
        if (itemId == mainItemId) {
            mainItemId = -1
        }
70
    }
71
72
73
74
    
    function getActiveTrackStreamPos() {
        return Logic.getTrackYFromId(timeline.activeTrack) + rulercontainer.height
    }
75

76
77
    function updatePalette() {
        root.color = activePalette.window
78
        root.textColor = activePalette.text
79
80
        playhead.fillColor = activePalette.windowText
        ruler.repaintRuler()
81
        // Disable caching for track header icons
82
        root.paletteUnchanged = false
83
    }
84

85
    function moveSelectedTrack(offset) {
86
87
88
89
90
91
92
93
94
95
96
        var newTrack
        if (timeline.activeTrack < 0 ) {
            if (offset <0) {
                newTrack = -2
            } else {
                newTrack = max
            }
        } else {
            var cTrack = Logic.getTrackIndexFromId(timeline.activeTrack)
            newTrack = cTrack + offset
        }
97
98
        var max = tracksRepeater.count;
        if (newTrack < 0) {
99
100
101
102
            if (showSubtitles && newTrack == -1) {
                timeline.activeTrack = -2
                return
            }
103
104
            newTrack = max - 1;
        } else if (newTrack >= max) {
105
106
107
108
            if (showSubtitles) {
                timeline.activeTrack = -2
                return
            }
109
110
            newTrack = 0;
        }
111
        timeline.activeTrack = tracksRepeater.itemAt(newTrack).trackInternalId
112
113
    }

114
    function zoomByWheel(wheel) {
115
        if (wheel.modifiers & Qt.AltModifier) {
116
            // Seek to next snap
117
118
119
120
121
122
            if (wheel.angleDelta.x > 0) {
                timeline.triggerAction('monitor_seek_snap_backward')
            } else {
                timeline.triggerAction('monitor_seek_snap_forward')
            }
        } else if (wheel.modifiers & Qt.ControlModifier) {
123
            root.wheelAccumulatedDelta += wheel.angleDelta.y;
124
            // Zoom
125
            if (root.wheelAccumulatedDelta >= defaultDeltasPerStep) {
126
                root.zoomIn(true);
127
128
                root.wheelAccumulatedDelta = 0;
            } else if (root.wheelAccumulatedDelta <= -defaultDeltasPerStep) {
129
                root.zoomOut(true);
130
                root.wheelAccumulatedDelta = 0;
131
            }
132
133
        } else if (wheel.modifiers & Qt.ShiftModifier) {
            // Vertical scroll
134
            var newScroll = Math.min(scrollView.contentY - wheel.angleDelta.y, trackHeaders.height - tracksArea.height + horScroll.height + ruler.height)
135
            scrollView.contentY = Math.max(newScroll, 0)
136
        } else {
137
            // Horizontal scroll
138
            var newScroll = Math.min(scrollView.contentX - wheel.angleDelta.y, timeline.fullDuration * root.timeScale - scrollView.width)
139
            scrollView.contentX = Math.max(newScroll, 0)
140
        }
141
        wheel.accepted = true
142
143
    }

144
    function continuousScrolling(x, y) {
145
        // This provides continuous scrolling at the left/right edges.
146
        if (x > scrollView.contentX + scrollView.width - root.baseUnit * 3) {
147
            scrollTimer.horizontal = root.baseUnit
148
149
            scrollTimer.start()
        } else if (x < 50) {
150
            scrollView.contentX = 0;
151
            scrollTimer.horizontal = 0
152
            scrollTimer.stop()
153
        } else if (x < scrollView.contentX + root.baseUnit * 3) {
154
            scrollTimer.horizontal = -root.baseUnit
155
156
            scrollTimer.start()
        } else {
157
158
            if (y > scrollView.contentY + scrollView.height + ruler.height - root.baseUnit) {
                scrollTimer.vertical = root.baseUnit
159
                scrollTimer.horizontal = 0
160
                scrollTimer.start()
161
162
            } else if (scrollView.contentY > 0 && (y - (scrollView.contentY + ruler.height ) < root.baseUnit)) {
                scrollTimer.vertical = -root.baseUnit
163
                scrollTimer.horizontal = 0
164
165
                scrollTimer.start()
            } else {
166
                console.log('TRIGGERING VERTICAL STOP: ', y, ', SCROLL: ',scrollView.contentY, 'SCH:', scrollView.height)
167
168
169
170
                scrollTimer.vertical = 0
                scrollTimer.horizontal = 0
                scrollTimer.stop()
            }
171
172
        }
    }
173
174
175
    function getTrackYFromId(a_track) {
        return Logic.getTrackYFromId(a_track)
    }
176

177
178
179
180
    function getTrackYFromMltIndex(a_track) {
        return Logic.getTrackYFromMltIndex(a_track)
    }

181
    function getMousePos() {
182
183
184
        if (dragProxy.draggedItem > -1 && dragProxy.masterObject) {
            return (dragProxy.masterObject.x + dragProxy.masterObject.mouseXPos) / timeline.scaleFactor
        }
185
186
187
188
189
        if (tracksArea.containsMouse) {
            return (scrollView.contentX + tracksArea.mouseX) / timeline.scaleFactor
        } else {
            return -1;
        }
190
    }
191
192
193
194
195
196
197
198
199
200
    function getMouseX() {
        if (dragProxy.draggedItem > -1 && dragProxy.masterObject) {
            return (dragProxy.masterObject.x + dragProxy.masterObject.mouseXPos) - scrollView.contentX
        }
        if (tracksArea.containsMouse) {
            return tracksArea.mouseX
        } else {
            return -1;
        }
    }
201

202
    function getScrollPos() {
203
        return scrollView.contentX
204
205
206
    }

    function setScrollPos(pos) {
207
        return scrollView.contentX = pos
208
209
    }

210
211
212
213
    function getCopiedItemId() {
        return copiedClip
    }

214
    function getMouseTrack() {
215
216
217
        if (dragProxy.draggedItem > -1 && dragProxy.masterObject) {
            return dragProxy.masterObject.trackId
        }
218
        return Logic.getTrackIdFromPos(tracksArea.mouseY - ruler.height + scrollView.contentY - subtitleTrack.height)
219
220
    }

221
222
223
    function getTrackColor(audio, header) {
        var col = activePalette.alternateBase
        if (audio) {
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
224
            col = Qt.tint(col, "#06FF00CC")
225
226
        }
        if (header) {
227
            col = Qt.darker(col, 1.05)
228
        }
229
        return col
230
    }
231
232
233
234
    
    function centerViewOnCursor() {
        scrollView.contentX = Math.max(0, root.consumerPosition * timeline.scaleFactor - (scrollView.width / 2))
    }
235

236
237
238
239
240
    function clearDropData() {
        clipBeingDroppedId = -1
        droppedPosition = -1
        droppedTrack = -1
        scrollTimer.running = false
241
        scrollTimer.stop()
242
    }
243

244
    function isDragging() {
245
        return dragInProgress
246
    }
247

248
    function initDrag(itemObject, itemCoord, itemId, itemPos, itemTrack, isComposition) {
249
        dragProxy.x = itemObject.modelStart * timeScale
250
        dragProxy.y = itemCoord.y
251
        dragProxy.width = itemObject.clipDuration * timeScale
252
253
254
255
256
257
        dragProxy.height = itemCoord.height
        dragProxy.masterObject = itemObject
        dragProxy.draggedItem = itemId
        dragProxy.sourceTrack = itemTrack
        dragProxy.sourceFrame = itemPos
        dragProxy.isComposition = isComposition
258
        dragProxy.verticalOffset = isComposition ? itemObject.displayHeight : 0
259
260
261
262
263
264
265
    }
    function endDrag() {
        dragProxy.draggedItem = -1
        dragProxy.x = 0
        dragProxy.y = 0
        dragProxy.width = 0
        dragProxy.height = 0
266
        dragProxy.verticalOffset = 0
267
268
    }

269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
    function getItemAtPos(tk, posx, isComposition) {
        var track = Logic.getTrackById(tk)
        var container = track.children[0]
        var tentativeClip = undefined
        for (var i = 0 ; i < container.children.length; i++) {
            if (container.children[i].children.length == 0 || container.children[i].children[0].children.length == 0) {
                continue
            }
            tentativeClip = container.children[i].children[0].childAt(posx, 1)
            if (tentativeClip && tentativeClip.clipId && (tentativeClip.isComposition == isComposition)) {
                break
            }
        }
        return tentativeClip
    }
284
285
286
287
288
289
    Keys.onDownPressed: {
        root.moveSelectedTrack(1)
    }
    Keys.onUpPressed: {
        root.moveSelectedTrack(-1)
    }
290

291
    property int activeTool: 0
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
292
    property real baseUnit: fontMetrics.font.pixelSize
293
    property real fontUnit: fontMetrics.font.pointSize
294
295
296
    property int collapsedHeight: Math.max(28, baseUnit * 1.8)
    property int minHeaderWidth: 6 * collapsedHeight
    property int headerWidth: Math.max(minHeaderWidth, timeline.headerWidth())
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
297
298
    property color selectedTrackColor: Qt.rgba(activePalette.highlight.r, activePalette.highlight.g, activePalette.highlight.b, 0.2)
    property color frameColor: Qt.rgba(activePalette.shadow.r, activePalette.shadow.g, activePalette.shadow.b, 0.3)
299
    property bool autoScrolling: timeline.autoScroll
300
    property int duration: timeline.duration
301
302
    property color audioColor: timeline.audioColor
    property color videoColor: timeline.videoColor
303
    property color titleColor: timeline.titleColor
Sashmita Raghav's avatar
Sashmita Raghav committed
304
    property color imageColor: timeline.imageColor
305
    property color slideshowColor: timeline.slideshowColor
306
    property color lockedColor: timeline.lockedColor
Vincent Pinon's avatar
Vincent Pinon committed
307
    property color selectionColor: timeline.selectionColor
308
    property color groupColor: timeline.groupColor
309
310
    property color thumbColor1: timeline.thumbColor1
    property color thumbColor2: timeline.thumbColor2
311
    property int mainItemId: -1
312
    property int mainFrame: -1
Nicolas Carion's avatar
Nicolas Carion committed
313
    property int clipBeingDroppedId: -1
314
    property string clipBeingDroppedData
315
316
    property int droppedPosition: -1
    property int droppedTrack: -1
317
    property int clipBeingMovedId: -1
318
    property int consumerPosition: proxy.position
319
    property int spacerGroup: -1
320
    property int spacerTrack: -1
321
    property int spacerFrame: -1
322
    property int finalSpacerFrame: -1
323
    property int spacerClickFrame: -1
324
    property real timeScale: timeline.scaleFactor
325
    property int snapping: (timeline.snap && (timeline.scaleFactor < 2 * baseUnit)) ? Math.floor(baseUnit / (timeline.scaleFactor > 3 ? timeline.scaleFactor / 2 : timeline.scaleFactor)) : -1
326
    property var timelineSelection: timeline.selection
327
    property int selectedMix: timeline.selectedMix
328
    property int trackHeight
329
    property int copiedClip: -1
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
330
    property int zoomOnMouse: -1
331
    property int viewActiveTrack: timeline.activeTrack
332
333
    property int wheelAccumulatedDelta: 0
    readonly property int defaultDeltasPerStep: 120
334
    property bool seekingFinished : proxy.seekFinished
335
    property int scrollMin: scrollView.contentX / timeline.scaleFactor
336
    property int scrollMax: scrollMin + scrollView.contentItem.width / timeline.scaleFactor
337
    property double dar: 16/9
338
    property bool paletteUnchanged: true
339
    property int maxLabelWidth: 20 * root.baseUnit * Math.sqrt(root.timeScale)
340
    property bool showSubtitles: false
341
342
    property bool subtitlesLocked: timeline.subtitlesLocked
    property bool subtitlesDisabled: timeline.subtitlesDisabled
343
    property int trackTagWidth: fontMetrics.boundingRect("M").width * (trackHeaderRepeater.count < 10 ? 2 : 3)
344
345
346
347

    onSeekingFinishedChanged : {
        playhead.opacity = seekingFinished ? 1 : 0.5
    }
348
349
350
351
    
    onShowSubtitlesChanged: {
        subtitleTrack.height = showSubtitles? root.baseUnit * 5 : 0
    }
352

353
    //onCurrentTrackChanged: timeline.selection = []
354
    onTimeScaleChanged: {
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
355
        if (root.zoomOnMouse >= 0) {
356
            scrollView.contentX = Math.max(0, root.zoomOnMouse * timeline.scaleFactor - getMouseX())
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
357
358
            root.zoomOnMouse = -1
        } else {
359
            scrollView.contentX = Math.max(0, root.consumerPosition * timeline.scaleFactor - (scrollView.width / 2))
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
360
        }
361
        //root.snapping = timeline.snap ? 10 / Math.sqrt(root.timeScale) : -1
362
        ruler.adjustStepSize()
363
364
365
366
        if (dragProxy.draggedItem > -1 && dragProxy.masterObject) {
            // update dragged item pos
            dragProxy.masterObject.updateDrag()
        }
367
    }
368

369
    onConsumerPositionChanged: {
370
        if (root.autoScrolling) Logic.scrollIfNeeded()
371
372
    }

373
374
    onViewActiveTrackChanged: {
        var tk = Logic.getTrackById(timeline.activeTrack)
375
376
377
378
        if (tk.y + subtitleTrack.height < scrollView.contentY) {
            scrollView.contentY = Math.max(0, tk.y + subtitleTrack.height)
        } else if (tk.y + tk.height + subtitleTrack.height > scrollView.contentY + scrollView.height) {
            var newY = Math.min(trackHeaders.height + subtitleTrack.height - scrollView.height + scrollView.ScrollBar.horizontal.height, tk.y + tk.height - scrollView.height + subtitleTrack.height)
379
380
381
            if (newY >= 0) {
                scrollView.contentY = newY
            }
382
383
384
        }
    }

385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
    onActiveToolChanged: {
        if (root.activeTool == 2) {
            // Spacer activated
            endDrag()
        } else if (root.activeTool == 0) {
            var tk = getMouseTrack()
            if (tk < 0) {
                return
            }
            var pos = getMousePos() * timeline.scaleFactor
            var sourceTrack = Logic.getTrackById(tk)
            var allowComposition = tracksArea.mouseY- sourceTrack.y > sourceTrack.height / 2
            var tentativeItem = undefined
            if (allowComposition) {
                tentativeItem = getItemAtPos(tk, pos, true)
            }
            if (!tentativeItem) {
                tentativeItem = getItemAtPos(tk, pos, false)
            }
            if (tentativeItem) {
                tentativeItem.updateDrag()
            }
        }
    }

410
411
412
413
414
415
416
    DropArea { //Drop area for compositions
        width: root.width - headerWidth
        height: root.height - ruler.height
        y: ruler.height
        x: headerWidth
        keys: 'kdenlive/composition'
        onEntered: {
417
            if (clipBeingMovedId == -1 && clipBeingDroppedId == -1) {
418
                var track = Logic.getTrackIdFromPos(drag.y + scrollView.contentY - subtitleTrack.height)
419
                var frame = Math.round((drag.x + scrollView.contentX) / timeline.scaleFactor)
420
                droppedPosition = frame
421
                if (track >= 0 && !controller.isAudioTrack(track)) {
422
423
                    clipBeingDroppedData = drag.getDataAsString('kdenlive/composition')
                    clipBeingDroppedId = timeline.insertComposition(track, frame, clipBeingDroppedData, false)
424
                    continuousScrolling(drag.x + scrollView.contentX, drag.y + scrollView.contentY)
425
426
427
428
429
430
                    drag.acceptProposedAction()
                } else {
                    drag.accepted = false
                }
            }
        }
431
432
        onPositionChanged: {
            if (clipBeingMovedId == -1) {
433
                var track = Logic.getTrackIdFromPos(drag.y + scrollView.contentY - subtitleTrack.height)
434
                if (track !=-1) {
435
                    var frame = Math.round((drag.x + scrollView.contentX) / timeline.scaleFactor)
436
                    if (clipBeingDroppedId >= 0){
437
438
439
440
                        if (controller.isAudioTrack(track)) {
                            // Don't allow moving composition to an audio track
                            track = controller.getCompositionTrackId(clipBeingDroppedId)
                        }
441
                        controller.suggestCompositionMove(clipBeingDroppedId, track, frame, root.consumerPosition, root.snapping)
442
                        continuousScrolling(drag.x + scrollView.contentX, drag.y + scrollView.contentY)
443
                    } else if (!controller.isAudioTrack(track)) {
444
                        frame = controller.suggestSnapPoint(frame, root.snapping)
445
446
                        clipBeingDroppedData = drag.getDataAsString('kdenlive/composition')
                        clipBeingDroppedId = timeline.insertComposition(track, frame, clipBeingDroppedData , false)
447
                        continuousScrolling(drag.x + scrollView.contentX, drag.y + scrollView.contentY)
448
                    }
449
450
451
                }
            }
        }
452
        onExited:{
453
454
            if (clipBeingDroppedId != -1) {
                // If we exit, remove composition
455
                controller.requestItemDeletion(clipBeingDroppedId, false)
456
                clearDropData()
457
458
            }
        }
459
460
461
462
463
        onDropped: {
            if (clipBeingDroppedId != -1) {
                var frame = controller.getCompositionPosition(clipBeingDroppedId)
                var track = controller.getCompositionTrackId(clipBeingDroppedId)
                // we simulate insertion at the final position so that stored undo has correct value
464
                controller.requestItemDeletion(clipBeingDroppedId, false)
465
                timeline.insertNewComposition(track, frame, clipBeingDroppedData, true)
466
            }
467
            clearDropData()
468
        }
469
    }
470
471
472
    DropArea {
        //Drop area for bin/clips
        id: clipDropArea
473
474
475
476
477
478
479
480
481
        /** @brief local helper function to handle the insertion of multiple dragged items */
        function insertAndMaybeGroup(track, frame, droppedData) {
            var binIds = droppedData.split(";")
            if (binIds.length == 0) {
                return -1
            }

            var id = -1
            if (binIds.length == 1) {
482
                id = timeline.insertClip(timeline.activeTrack, frame, clipBeingDroppedData, false, true, false)
483
            } else {
484
                var ids = timeline.insertClips(timeline.activeTrack, frame, binIds, false, true, false)
485
486
487

                // if the clip insertion succeeded, request the clips to be grouped
                if (ids.length > 0) {
488
                    timeline.selectItems(ids)
489
490
491
492
493
494
                    id = ids[0]
                }
            }
            return id
        }

495
496
        property int fakeFrame: -1
        property int fakeTrack: -1
497
498
499
500
        width: root.width - headerWidth
        height: root.height - ruler.height
        y: ruler.height
        x: headerWidth
501
        keys: 'kdenlive/producerslist'
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
        function processDrop()
        {
            // Process the drop event, useful if drop event happens outside of drop area
            if (clipBeingDroppedId != -1) {
                var frame = controller.getClipPosition(clipBeingDroppedId)
                var track = controller.getClipTrackId(clipBeingDroppedId)
                if (!controller.normalEdit()) {
                    frame = fakeFrame
                    track = fakeTrack
                }
                /* We simulate insertion at the final position so that stored undo has correct value
                 * NOTE: even if dropping multiple clips, requesting the deletion of the first one is
                 * enough as internally it will request the group deletion
                 */
                controller.requestItemDeletion(clipBeingDroppedId, false)

                var binIds = clipBeingDroppedData.split(";")
                if (binIds.length == 1) {
                    if (controller.normalEdit()) {
                        timeline.insertClip(track, frame, clipBeingDroppedData, true, true, false)
                    } else {
                        timeline.insertClipZone(clipBeingDroppedData, track, frame)
                    }
                } else {
                    if (controller.normalEdit()) {
                        timeline.insertClips(track, frame, binIds, true, true)
                    } else {
                        // TODO
                        console.log('multiple clips insert/overwrite not supported yet')
                    }
                }
                fakeTrack = -1
                fakeFrame = -1
            }
            clearDropData()
        }
538
        onEntered: {
539
            if (clipBeingMovedId == -1 && clipBeingDroppedId == -1) {
540
                //var track = Logic.getTrackIdFromPos(drag.y)
541
542
543
544
545
                var yOffset = 0
                if (root.showSubtitles) {
                    yOffset = subtitleTrack.height
                }
                var track = Logic.getTrackIndexFromPos(drag.y + scrollView.contentY - yOffset)
546
                if (track >= 0  && track < tracksRepeater.count) {
547
                    var frame = Math.round((drag.x + scrollView.contentX) / timeline.scaleFactor)
548
                    droppedPosition = frame
549
                    timeline.activeTrack = tracksRepeater.itemAt(track).trackInternalId
Nicolas Carion's avatar
Nicolas Carion committed
550
                    //drag.acceptProposedAction()
551
                    clipBeingDroppedData = drag.getDataAsString('kdenlive/producerslist')
552
553
554
555
                    if (controller.normalEdit()) {
                        clipBeingDroppedId = insertAndMaybeGroup(timeline.activeTrack, frame, clipBeingDroppedData)
                    } else {
                        // we want insert/overwrite mode, make a fake insert at end of timeline, then move to position
556
557
                        frame = controller.adjustFrame(frame, timeline.activeTrack)
                        clipBeingDroppedId = insertAndMaybeGroup(timeline.activeTrack, frame, clipBeingDroppedData)
558
                        if (clipBeingDroppedId > -1) {
559
560
561
                            var moveData = controller.suggestClipMove(clipBeingDroppedId, timeline.activeTrack, frame, root.consumerPosition, root.snapping)
                            fakeFrame = moveData[0]
                            fakeTrack = moveData[1]
562
563
564
                        } else {
                            drag.accepted = false
                        }
565
                    }
566
                    continuousScrolling(drag.x + scrollView.contentX, drag.y + scrollView.contentY)
567
568
569
570
                } else {
                    drag.accepted = false
                }
            }
571
        }
Nicolas Carion's avatar
Nicolas Carion committed
572
        onExited:{
573
574
            if (clipBeingDroppedId != -1 && drag.y < drag.x) {
                // If we exit on top, remove clip
575
                controller.requestItemDeletion(clipBeingDroppedId, false)
576
577
578
                clearDropData()
            } else {
                // Clip is dropped
Nicolas Carion's avatar
Nicolas Carion committed
579
580
            }
        }
581
        onPositionChanged: {
582
            if (clipBeingMovedId == -1) {
583
584
585
586
587
                var yOffset = 0
                if (root.showSubtitles) {
                    yOffset = subtitleTrack.height
                }
                var track = Logic.getTrackIndexFromPos(drag.y + scrollView.contentY - yOffset)
588
                if (track >= 0  && track < tracksRepeater.count) {
589
590
                    //timeline.activeTrack = tracksRepeater.itemAt(track).trackInternalId
                    var targetTrack = tracksRepeater.itemAt(track).trackInternalId
591
                    var frame = Math.round((drag.x + scrollView.contentX) / timeline.scaleFactor)
592
593
594
595
596
                    if (clipBeingDroppedId > -1) {
                        var moveData = controller.suggestClipMove(clipBeingDroppedId, targetTrack, frame, root.consumerPosition, root.snapping)
                        fakeFrame = moveData[0]
                        fakeTrack = moveData[1]
                        timeline.activeTrack = fakeTrack
597
                        //controller.requestClipMove(clipBeingDroppedId, timeline.activeTrack, frame, true, false, false)
598
                        continuousScrolling(drag.x + scrollView.contentX, drag.y + scrollView.contentY)
599
                    } else {
600
                        frame = controller.suggestSnapPoint(frame, root.snapping)
601
                        if (controller.normalEdit()) {
602
603
                            timeline.activeTrack = targetTrack
                            clipBeingDroppedId = insertAndMaybeGroup(targetTrack, frame, drag.getDataAsString('kdenlive/producerslist'), false, true)
604
605
                        } else {
                            // we want insert/overwrite mode, make a fake insert at end of timeline, then move to position
606
607
608
609
610
611
612
                            clipBeingDroppedId = insertAndMaybeGroup(targetTrack, timeline.fullDuration, clipBeingDroppedData)
                            if (clipBeingDroppedId > -1) {
                                var moveData = controller.suggestClipMove(clipBeingDroppedId, targetTrack, frame, root.consumerPosition, root.snapping)
                                fakeFrame = moveData[0]
                                fakeTrack = moveData[1]
                                timeline.activeTrack = fakeTrack
                            }
613
                        }
614
                        continuousScrolling(drag.x + scrollView.contentX, drag.y + scrollView.contentY)
615
                    }
616
                }
Nicolas Carion's avatar
Nicolas Carion committed
617
            }
618
619
        }
        onDropped: {
620
            processDrop()
621
622
        }
    }
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
    DropArea { //Drop area for urls (direct drop from file manager)
        /** @brief local helper function to handle the insertion of multiple dragged items */
        property int fakeFrame: -1
        property int fakeTrack: -1
        property var droppedUrls: []
        width: root.width - headerWidth
        height: root.height - ruler.height
        y: ruler.height
        x: headerWidth
        keys: 'text/uri-list'
        onEntered: {
            drag.accepted = true
            droppedUrls.length = 0
            for(var i in drag.urls){
                var url = drag.urls[i]
                droppedUrls.push(Qt.resolvedUrl(url))
            }
        }
        onExited:{
            if (clipBeingDroppedId != -1) {
                controller.requestItemDeletion(clipBeingDroppedId, false)
            }
            clearDropData()
        }
        onPositionChanged: {
            if (clipBeingMovedId == -1) {
649
650
651
652
653
                var yOffset = 0
                if (root.showSubtitles) {
                    yOffset = subtitleTrack.height
                }
                var track = Logic.getTrackIndexFromPos(drag.y + scrollView.contentY - yOffset)
654
655
                if (track >= 0  && track < tracksRepeater.count) {
                    timeline.activeTrack = tracksRepeater.itemAt(track).trackInternalId
656
                    var frame = Math.round((drag.x + scrollView.contentX) / timeline.scaleFactor)
657
658
                    if (clipBeingDroppedId >= 0) {
                        //fakeFrame = controller.suggestClipMove(clipBeingDroppedId, timeline.activeTrack, frame, root.consumerPosition, Math.floor(root.snapping))
659
                        //fakeTrack = timeline.activeTrack
660
                        //controller.requestClipMove(clipBeingDroppedId, timeline.activeTrack, frame, true, false, false)
661
                        continuousScrolling(drag.x + scrollView.contentX, drag.y + scrollView.contentY)
662
                    } else {
663
                        frame = controller.suggestSnapPoint(frame, root.snapping)
664
665
666
667
668
669
670
671
                        if (controller.normalEdit()) {
                            //clipBeingDroppedId = insertAndMaybeGroup(timeline.activeTrack, frame, drag.getDataAsString('kdenlive/producerslist'), false, true)
                        } else {
                            // we want insert/overwrite mode, make a fake insert at end of timeline, then move to position
                            //clipBeingDroppedId = insertAndMaybeGroup(timeline.activeTrack, timeline.fullDuration, clipBeingDroppedData)
                            //fakeFrame = controller.suggestClipMove(clipBeingDroppedId, timeline.activeTrack, frame, root.consumerPosition, Math.floor(root.snapping))
                            fakeTrack = timeline.activeTrack
                        }
672
                        continuousScrolling(drag.x + scrollView.contentX, drag.y + scrollView.contentY)
673
674
675
676
677
                    }
                }
            }
        }
        onDropped: {
678
            var frame = Math.round((drag.x + scrollView.contentX) / timeline.scaleFactor)
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
            var track = timeline.activeTrack
            //var binIds = clipBeingDroppedData.split(";")
            //if (binIds.length == 1) {
                if (controller.normalEdit()) {
                    timeline.urlDropped(droppedUrls, frame, track)
                } else {
                    //timeline.insertClipZone(clipBeingDroppedData, track, frame)
                }
            /*} else {
                if (controller.normalEdit()) {
                    timeline.insertClips(track, frame, binIds, true, true)
                } else {
                    // TODO
                    console.log('multiple clips insert/overwrite not supported yet')
                }
            }*/
            clearDropData()
        }
    }
698

699
700
    Row {
        Column {
701
            id: headerContainer
702
            width: headerWidth
703
            z: 1
704
            Item {
705
                // Padding between toolbar and track headers.
706
                width: parent.width
707
                height: ruler.height
708
                Button {
709
                    text: parent.width > metrics.boundingRect.width * 1.4 ? metrics.text : i18nc("Initial for Master", "M")
710
711
712
                    anchors.fill: parent
                    anchors.leftMargin: 2
                    anchors.rightMargin: 2
713
714
715
716
                    ToolTip.delay: 1000
                    ToolTip.timeout: 5000
                    ToolTip.visible: hovered
                    ToolTip.text: i18n("Show master effects")
717
718
719
720
                    TextMetrics {
                        id: metrics
                        text: i18n("Master")
                    }
721
722
723
724
                    onClicked: {
                        timeline.showMasterEffects()
                    }
                }
725
726
727
            }
            Flickable {
                // Non-slider scroll area for the track headers.
728
                id: headerFlick
729
                contentY: scrollView.contentY
730
731
732
                width: parent.width
                y: ruler.height
                height: root.height - ruler.height
733
                interactive: false
734
                clip: true
735

736
737
738
739
740
                MouseArea {
                    width: trackHeaders.width
                    height: trackHeaders.height
                    acceptedButtons: Qt.NoButton
                    onWheel: {
741
742
                        var newScroll = Math.min(scrollView.contentY - wheel.angleDelta.y, height - tracksArea.height + scrollView.ScrollBar.horizontal.height + ruler.height)
                        scrollView.contentY = Math.max(newScroll, 0)
743
744
                    }
                }
745
                Rectangle {
746
                    id: subtitleTrackHeader
747
                    width: trackHeaders.width
748
749
                    height: subtitleTrack.height
                    property bool collapsed: subtitleTrack.height == root.collapsedHeight
750
                    visible: height > 0
751
752
753
754
755
756
757
                    color: (timeline.activeTrack == -2) ? Qt.tint(getTrackColor(false, false), selectedTrackColor) : getTrackColor(false, false)
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            timeline.activeTrack = -2
                        }
                    }
758
759
760
761
762
                    ToolButton {
                        id: expandSubButton
                        focusPolicy: Qt.NoFocus
                        property var modifier: 0
                        anchors.left: parent.left
763
                        anchors.leftMargin: 1.5 * root.baseUnit
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
                        width: root.collapsedHeight
                        height: root.collapsedHeight   
                        contentItem: Item {
                            Image {
                                source: subtitleTrackHeader.collapsed ? "image://icon/go-next" : "image://icon/go-down"
                                anchors.centerIn: parent
                                width: root.collapsedHeight - 4
                                height: root.collapsedHeight - 4
                                cache: root.paletteUnchanged
                            }
                        }
                        onClicked: {
                            if (subtitleTrack.height > root.collapsedHeight) {
                                subtitleTrack.height = root.collapsedHeight
                            } else {
                                subtitleTrack.height = 5 * root.baseUnit
                            }
                        }
                    }
                    Label {
784
                        id: subLabel
785
786
787
788
                        anchors.left: expandSubButton.left
                        anchors.top: expandSubButton.bottom
                        font: miniFont
                        text: i18n("Subtitles")
789
                        visible: (subtitleTrackHeader.height > root.collapsedHeight + subLabel.height)
790
                    }
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
                    
                    Row {
                        id: subButtonsRow
                        width: childrenRect.width
                        x: Math.max(2 * root.collapsedHeight + 2, parent.width - width - 4)
                        spacing: 0
                        ToolButton {
                            id: muteButton
                            focusPolicy: Qt.NoFocus
                            contentItem: Item {
                                Image {
                                    source: root.subtitlesDisabled ? "image://icon/view-hidden" : "image://icon/view-visible"
                                    anchors.centerIn: parent
                                    width: root.collapsedHeight - 4
                                    height: root.collapsedHeight - 4
                                    cache: root.paletteUnchanged
                                }
                            }
                            width: root.collapsedHeight
                            height: root.collapsedHeight
                            onClicked: timeline.triggerAction('disable_subtitle')
                            ToolTip {
                                visible: muteButton.hovered
                                font: miniFont
                                delay: 1500
                                timeout: 5000
                                background: Rectangle {
                                    color: activePalette.alternateBase
                                    border.color: activePalette.light
                                }
                                contentItem: Label {
                                    color: activePalette.text
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
823
                                    text: root.subtitlesDisabled? i18n("Show") : i18n("Hide")
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
                                }
                            }
                        }

                        ToolButton {
                            id: lockButton
                            width: root.collapsedHeight
                            height: root.collapsedHeight
                            focusPolicy: Qt.NoFocus
                            contentItem: Item {
                                Image {
                                    source: root.subtitlesLocked ? "image://icon/kdenlive-lock" : "image://icon/kdenlive-unlock"
                                    anchors.centerIn: parent
                                    width: root.collapsedHeight - 4
                                    height: root.collapsedHeight - 4
                                    cache: root.paletteUnchanged
                                }
                            }
                            onClicked: timeline.triggerAction('lock_subtitle')
                            ToolTip {
                                visible: lockButton.hovered
                                font: miniFont
                                delay: 1500
                                timeout: 5000
                                background: Rectangle {
                                    color: activePalette.alternateBase
                                    border.color: activePalette.light
                                }
                                contentItem: Label {
                                    color: activePalette.text
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
854
                                    text: root.subtitlesLocked? i18n("Unlock track") : i18n("Lock track")
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
                                }
                            }
                            SequentialAnimation {
                                id: flashLock
                                loops: 1
                                ScaleAnimator {
                                    target: lockButton
                                    from: 1
                                    to: 1.6
                                    duration: 200
                                }
                                ScaleAnimator {
                                    target: lockButton
                                    from: 1.6
                                    to: 1
                                    duration: 200
                                }
                            }
                        }
                    }
875
                }
876
877
                Column {
                    id: trackHeaders
878
                    y: subtitleTrack.height
879
                    spacing: 0
880
881
882
883
884
                    Repeater {
                        id: trackHeaderRepeater
                        model: multitrack
                        TrackHead {
                            trackName: model.name
885
                            thumbsFormat: model.thumbsFormat
886
                            trackTag: model.trackTag
887
                            isDisabled: model.disabled
888
889
                            isComposite: model.composite
                            isLocked: model.locked
890
                            isActive: model.trackActive
891
                            isAudio: model.audio
892
                            showAudioRecord: model.audioRecord
893
894
                            effectNames: model.effectNames
                            isStackEnabled: model.isStackEnabled
895
                            width: headerWidth
896
                            current: item === timeline.activeTrack
897
                            trackId: item
898
                            height: model.trackHeight
899
                            onIsLockedChanged: tracksRepeater.itemAt(index).isLocked = isLocked
900
                            collapsed: height <= root.collapsedHeight
901
902
903
                            Component.onCompleted: {
                                root.collapsedHeight = collapsedHeight
                            }
904
905
                            onHeightChanged: {
                                collapsed = height <= root.collapsedHeight
906
                            }
907
908
909
910
911
912
                        }
                    }
                }
                Column {
                    id: trackHeadersResizer
                    spacing: 0
913
                    width: root.baseUnit / 2
914
915
                    Rectangle {
                        id: resizer
916
                        height: trackHeaders.height + subtitleTrackHeader.height
917
                        width: root.baseUnit / 2
918
919
920
921
922
923
924
925
926
927
928
929
930
                        x: root.headerWidth - 2
                        color: 'red'
                        opacity: 0
                        Drag.active: headerMouseArea.drag.active
                        Drag.proposedAction: Qt.MoveAction

                        MouseArea {
                            id: headerMouseArea
                            anchors.fill: parent
                            hoverEnabled: true
                            cursorShape: Qt.SizeHorCursor
                            drag.target: parent
                            drag.axis: Drag.XAxis
931
                            drag.minimumX: root.minHeaderWidth
932
933
934
935
936
                            property double startX
                            property double originalX
                            drag.smoothed: false

                            onPressed: {
937
                                root.autoScrolling = false
938
939
                            }
                            onReleased: {
940
                                root.autoScrolling = timeline.autoScroll
941
942
943
944
945
946
947
                                parent.opacity = 0
                            }
                            onEntered: parent.opacity = 0.5
                            onExited: parent.opacity = 0
                            onPositionChanged: {
                                if (mouse.buttons === Qt.LeftButton) {
                                    parent.opacity = 0.5
948
                                    headerWidth = Math.max( root.minHeaderWidth, mapToItem(null, x, y).x + 2)