Clip.qml 38.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
 * Copyright (c) 2013-2016 Meltytech, LLC
 * Author: Dan Dennedy <dan@dennedy.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

19
20
import QtQuick 2.11
import QtQuick.Controls 2.4
21
import Kdenlive.Controls 1.0
22
import QtQml.Models 2.11
23
import QtQuick.Window 2.2
24
import 'Timeline.js' as Logic
25
import com.enums 1.0
26
27
28

Rectangle {
    id: clipRoot
29
    property real timeScale: 1
30
31
32
    property string clipName: ''
    property string clipResource: ''
    property string mltService: ''
33
    property string effectNames
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
34
    property int modelStart
35
    property real scrollX: 0
36
37
38
    property int inPoint: 0
    property int outPoint: 0
    property int clipDuration: 0
39
    property int maxDuration: 0
40
    property bool isAudio: false
41
    property int audioChannels
42
    property bool showKeyframes: false
43
    property bool isGrabbed: false
44
    property bool grouped: false
45
    property var markers
46
    property var keyframeModel
47
48
    property int clipStatus: 0
    property int itemType: 0
49
50
    property int fadeIn: 0
    property int fadeOut: 0
51
    property int binId: 0
52
    property int positionOffset: 0
53
    property var parentTrack
54
55
    property int trackIndex //Index in track repeater
    property int clipId     //Id of the clip in the model
56
57
58
    property int trackId: -1 // Id of the parent track in the model
    property int fakeTid: -1
    property int fakePosition: 0
59
    property int originalTrackId: -1
60
    property int originalX: x
61
62
    property int originalDuration: clipDuration
    property int lastValidDuration: clipDuration
63
    property int draggedX: x
64
    property bool selected: false
65
    property bool isLocked: parentTrack && parentTrack.isLocked == true
66
    property bool hasAudio
67
68
    property bool canBeAudio
    property bool canBeVideo
69
    property double speed: 1.0
70
    property color borderColor: 'black'
71
    property bool forceReloadThumb
72
    property bool isComposition: false
73
    property bool hideClipViews: false
74
    property var groupTrimData
75
    property int scrollStart: scrollView.contentX - (clipRoot.modelStart * timeline.scaleFactor)
76
    width : clipDuration * timeScale
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
77
    opacity: dragProxyArea.drag.active && dragProxy.draggedItem == clipId ? 0.8 : 1.0
78

79
80
    signal trimmingIn(var clip, real newDuration, var mouse, bool shiftTrim, bool controlTrim)
    signal trimmedIn(var clip, bool shiftTrim, bool controlTrim)
81
    signal initGroupTrim(var clip)
82
83
    signal trimmingOut(var clip, real newDuration, var mouse, bool shiftTrim, bool controlTrim)
    signal trimmedOut(var clip, bool shiftTrim, bool controlTrim)
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
84

85
    onScrollStartChanged: {
86
        clipRoot.hideClipViews = scrollStart > (clipDuration * timeline.scaleFactor) || scrollStart + scrollView.contentItem.width < 0
87
    }
88

89
90
    onIsGrabbedChanged: {
        if (clipRoot.isGrabbed) {
91
            grabItem()
92
93
        } else {
            mouseArea.focus = false
94
95
96
        }
    }

97
98
99
100
101
    function grabItem() {
        clipRoot.forceActiveFocus()
        mouseArea.focus = true
    }

102
103
    function clearAndMove(offset) {
        controller.requestClearSelection()
104
105
        controller.requestClipMove(clipRoot.clipId, clipRoot.trackId, clipRoot.modelStart - offset, true, true, true)
        controller.requestAddToSelection(clipRoot.clipId)
106
107
    }

108
    onClipResourceChanged: {
109
        if (itemType == ProducerType.Color) {
110
            color: Qt.darker(getColor(), 1.5)
111
112
        }
    }
113
    ToolTip {
114
        visible: mouseArea.containsMouse && !dragProxyArea.pressed
115
116
117
118
119
120
121
122
        delay: 1000
        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
123
            font.pointSize: root.fontUnit
124
            text: label.text + ' (' + timeline.simplifiedTC(clipRoot.inPoint) + '-' + timeline.simplifiedTC(clipRoot.outPoint) + ')'
125
126
127
        }
    }

128
    onKeyframeModelChanged: {
129
        if (effectRow.keyframecanvas) {
130
            console.log('keyframe model changed............')
131
132
            effectRow.keyframecanvas.requestPaint()
        }
133
134
    }

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
135
136
    onClipDurationChanged: {
        width = clipDuration * timeScale;
137
138
        if (parentTrack && parentTrack.isAudio && thumbsLoader.item) {
            // Duration changed, we may need a different number of repeaters
139
            thumbsLoader.item.reload(1)
140
        }
141
    }
142

143
144
145
    onModelStartChanged: {
        x = modelStart * timeScale;
    }
146

147
148
149
150
151
    onFakePositionChanged: {
        x = fakePosition * timeScale;
    }
    onFakeTidChanged: {
        if (clipRoot.fakeTid > -1 && parentTrack) {
152
153
154
155
156
157
158
            if (clipRoot.parent != dragContainer) {
                var pos = clipRoot.mapToGlobal(clipRoot.x, clipRoot.y);
                clipRoot.parent = dragContainer
                pos = clipRoot.mapFromGlobal(pos.x, pos.y)
                clipRoot.x = pos.x
                clipRoot.y = pos.y
            }
159
160
            clipRoot.y = Logic.getTrackById(clipRoot.fakeTid).y
        }
161
162
    }

163
    onForceReloadThumbChanged: {
164
        // TODO: find a way to force reload of clip thumbs
165
        if (thumbsLoader.item) {
166
            thumbsLoader.item.reload(0)
167
        }
168
169
    }

170
    onTimeScaleChanged: {
171
        x = modelStart * timeScale;
172
        width = clipDuration * timeScale;
173
        labelRect.x = scrollX > modelStart * timeScale ? scrollX - modelStart * timeScale : clipRoot.border.width
174
175
    }
    onScrollXChanged: {
176
        labelRect.x = scrollX > modelStart * timeScale ? scrollX - modelStart * timeScale : clipRoot.border.width
177
178
    }

Vincent Pinon's avatar
Vincent Pinon committed
179
    border.color: selected ? root.selectionColor : grouped ? root.groupColor : borderColor
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
180
    border.width: isGrabbed ? 8 : 2
181

182
183
184
185
186
    function updateDrag() {
        var itemPos = mapToItem(tracksContainerArea, 0, 0, clipRoot.width, clipRoot.height)
        initDrag(clipRoot, itemPos, clipRoot.clipId, clipRoot.modelStart, clipRoot.trackId, false)
    }

187
    function getColor() {
188
189
190
        if (clipStatus == ClipState.Disabled) {
            return 'grey'
        }
191
192
193
        if (itemType == ProducerType.Text) {
            return titleColor
        }
194
        if (itemType == ProducerType.Image) {
195
196
            return imageColor
        }
197
198
199
        if (itemType == ProducerType.SlideShow) {
            return slideshowColor
        }
200
        if (itemType == ProducerType.Color) {
201
202
203
            var color = clipResource.substring(clipResource.length - 9)
            if (color[0] == '#') {
                return color
204
            }
205
            return '#' + color.substring(color.length - 8, color.length - 2)
206
        }
207
        return isAudio? root.audioColor : root.videoColor
208
209
    }

210
/*    function reparent(track) {
211
        console.log('TrackId: ',trackId)
212
213
        parent = track
        height = track.height
214
        parentTrack = track
215
        trackId = parentTrack.trackId
216
        console.log('Reparenting clip to Track: ', trackId)
217
        //generateWaveform()
218
    }
219
*/
220
    property bool noThumbs: (isAudio || itemType == ProducerType.Color || mltService === '')
221
    property string baseThumbPath: noThumbs ? '' : 'image://thumbnail/' + binId + '/' + documentId + '/#'
222

223
    DropArea { //Drop area for clips
224
225
226
        anchors.fill: clipRoot
        keys: 'kdenlive/effect'
        property string dropData
227
        property string dropSource
228
        property int dropRow: -1
229
230
        onEntered: {
            dropData = drag.getDataAsString('kdenlive/effect')
231
            dropSource = drag.getDataAsString('kdenlive/effectsource')
232
233
234
        }
        onDropped: {
            console.log("Add effect: ", dropData)
235
            if (dropSource == '') {
236
237
238
                // drop from effects list
                controller.addClipEffect(clipRoot.clipId, dropData);
            } else {
239
                controller.copyClipEffect(clipRoot.clipId, dropSource);
240
            }
241
            dropSource = ''
242
            dropRow = -1
243
            drag.acceptProposedAction
244
245
        }
    }
246
247
    MouseArea {
        id: mouseArea
248
        enabled: root.activeTool === 0
249
        anchors.fill: clipRoot
250
        acceptedButtons: Qt.RightButton
251
        hoverEnabled: root.activeTool === 0
252
        cursorShape: (trimInMouseArea.drag.active || trimOutMouseArea.drag.active)? Qt.SizeHorCursor : dragProxyArea.cursorShape
253
        onPressed: {
254
            root.autoScrolling = false
255
            root.mainItemId = clipRoot.clipId
256
            if (mouse.button == Qt.RightButton) {
257
                if (timeline.selection.indexOf(clipRoot.clipId) == -1) {
258
                    controller.requestAddToSelection(clipRoot.clipId, true)
259
                }
260
                root.mainFrame = Math.round(mouse.x / timeline.scaleFactor)
261
                root.showClipMenu()
262
            }
263
        }
264
        Keys.onShortcutOverride: event.accepted = clipRoot.isGrabbed && (event.key === Qt.Key_Left || event.key === Qt.Key_Right || event.key === Qt.Key_Up || event.key === Qt.Key_Down || event.key === Qt.Key_Escape)
265
        Keys.onLeftPressed: {
266
267
            var offset = event.modifiers === Qt.ShiftModifier ? timeline.fps() : 1
            controller.requestClipMove(clipRoot.clipId, clipRoot.trackId, clipRoot.modelStart - offset, true, true, true);
268
269
        }
        Keys.onRightPressed: {
270
271
            var offset = event.modifiers === Qt.ShiftModifier ? timeline.fps() : 1
            controller.requestClipMove(clipRoot.clipId, clipRoot.trackId, clipRoot.modelStart + offset, true, true, true);
272
        }
273
274
275
276
277
278
        Keys.onUpPressed: {
            controller.requestClipMove(clipRoot.clipId, controller.getNextTrackId(clipRoot.trackId), clipRoot.modelStart, true, true, true);
        }
        Keys.onDownPressed: {
            controller.requestClipMove(clipRoot.clipId, controller.getPreviousTrackId(clipRoot.trackId), clipRoot.modelStart, true, true, true);
        }
279
280
        Keys.onEscapePressed: {
            timeline.grabCurrent()
281
            //focus = false
282
        }
283
        onPositionChanged: {
284
285
            var mapped = parentTrack.mapFromItem(clipRoot, mouse.x, mouse.y).x
            root.mousePosChanged(Math.round(mapped / timeline.scaleFactor))
286
        }
287
288
289
290
        onEntered: {
            var itemPos = mapToItem(tracksContainerArea, 0, 0, width, height)
            initDrag(clipRoot, itemPos, clipRoot.clipId, clipRoot.modelStart, clipRoot.trackId, false)
        }
291

292
293
        onExited: {
            endDrag()
294
        }
295
        onWheel: zoomByWheel(wheel)
296

297
        Loader {
298
            // Thumbs container
299
            id: thumbsLoader
300
            anchors.fill: parent
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
301
302
            anchors.leftMargin: parentTrack.isAudio ? 0 : clipRoot.border.width
            anchors.rightMargin: parentTrack.isAudio ? 0 : clipRoot.border.width
303
304
305
            anchors.topMargin: clipRoot.border.width
            anchors.bottomMargin: clipRoot.border.width
            clip: true
306
307
            asynchronous: true
            visible: status == Loader.Ready
308
            source: clipRoot.hideClipViews || clipRoot.itemType == 0 || clipRoot.itemType === ProducerType.Color ? "" : parentTrack.isAudio ? (timeline.showAudioThumbnails ? "ClipAudioThumbs.qml" : "") : timeline.showThumbnails ? "ClipThumbs.qml" : ""
309
        }
310

311
312
313
314
        Item {
            // Clipping container
            id: container
            anchors.fill: parent
315
316
            anchors.margins: clipRoot.border.width
            //clip: true
317
            property bool showDetails: (!clipRoot.selected || !effectRow.visible) && container.height > 2.2 * labelRect.height
318
319

            Repeater {
320
                // Clip markers
321
322
323
324
                model: markers
                delegate:
                Item {
                    anchors.fill: parent
325
                    visible: markerBase.x >= 0 && markerBase.x < clipRoot.width
326
327
328
329
                    Rectangle {
                        id: markerBase
                        width: 1
                        height: parent.height
330
                        x: clipRoot.speed < 0 ? clipRoot.clipDuration * timeScale + (Math.round(model.frame / clipRoot.speed) - (clipRoot.maxDuration - clipRoot.outPoint)) * timeScale - clipRoot.border.width : (Math.round(model.frame / clipRoot.speed) - clipRoot.inPoint) * timeScale - clipRoot.border.width;
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
                        color: model.color
                    }
                    Rectangle {
                        visible: mlabel.visible
                        opacity: 0.7
                        x: markerBase.x
                        radius: 2
                        width: mlabel.width + 4
                        height: mlabel.height
                        anchors {
                            bottom: parent.verticalCenter
                        }
                        color: model.color
                        MouseArea {
                            z: 10
                            anchors.fill: parent
                            acceptedButtons: Qt.LeftButton
                            cursorShape: Qt.PointingHandCursor
                            hoverEnabled: true
350
                            onDoubleClicked: timeline.editMarker(clipRoot.clipId, model.frame)
351
                            onClicked: proxy.position = (clipRoot.x + markerBase.x) / timeline.scaleFactor
352
353
354
355
356
357
                        }
                    }
                    Text {
                        id: mlabel
                        visible: timeline.showMarkers && parent.width > width * 1.5
                        text: model.comment
358
                        font.pointSize: root.fontUnit
359
360
361
362
363
364
365
366
                        x: markerBase.x
                        anchors {
                            bottom: parent.verticalCenter
                            topMargin: 2
                            leftMargin: 2
                        }
                        color: 'white'
                    }
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
367
                }
368
369
            }

370
371
372
            MouseArea {
                // Left resize handle
                id: trimInMouseArea
373
                x: -clipRoot.border.width
374
375
                height: parent.height
                width: root.baseUnit / 2
376
                enabled: !isLocked && (pressed || clipRoot.width > 3 * width)
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
                hoverEnabled: true
                drag.target: trimInMouseArea
                drag.axis: Drag.XAxis
                drag.smoothed: false
                property bool shiftTrim: false
                property bool controlTrim: false
                property bool sizeChanged: false
                cursorShape: (containsMouse ? Qt.SizeHorCursor : Qt.ClosedHandCursor);
                onPressed: {
                    root.autoScrolling = false
                    clipRoot.originalX = clipRoot.x
                    clipRoot.originalDuration = clipDuration
                    shiftTrim = mouse.modifiers & Qt.ShiftModifier
                    controlTrim = mouse.modifiers & Qt.ControlModifier
                    if (!shiftTrim && clipRoot.grouped) {
                        clipRoot.initGroupTrim(clipRoot)
                    }
                    trimIn.opacity = 0
                }
                onReleased: {
                    root.autoScrolling = timeline.autoScroll
398
                    x = -clipRoot.border.width
399
400
401
402
403
404
405
                    if (sizeChanged) {
                        clipRoot.trimmedIn(clipRoot, shiftTrim, controlTrim)
                        sizeChanged = false
                    }
                }
                onPositionChanged: {
                    if (mouse.buttons === Qt.LeftButton) {
406
407
408
                        var currentFrame = Math.round((clipRoot.x + (x + clipRoot.border.width)) / timeScale)
                        var currentClipPos = clipRoot.modelStart
                        var delta = currentFrame - currentClipPos
409
                        if (delta !== 0) {
410
                            if (maxDuration > 0 && delta < -inPoint && !(mouse.modifiers & Qt.ControlModifier)) {
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
                                delta = -inPoint
                            }
                            var newDuration =  clipDuration - delta
                            sizeChanged = true
                            clipRoot.trimmingIn(clipRoot, newDuration, mouse, shiftTrim, controlTrim)
                        }
                    }
                }
                onEntered: {
                    if (!pressed) {
                        trimIn.opacity = 1
                    }
                }
                onExited: {
                    trimIn.opacity = 0
                }
                Rectangle {
                    id: trimIn
                    anchors.left: parent.left
                    width: clipRoot.border.width
                    height: parent.height
                    color: 'lawngreen'
                    opacity: 0
                    Drag.active: trimInMouseArea.drag.active
                    Drag.proposedAction: Qt.MoveAction
436
                    visible: trimInMouseArea.pressed || (root.activeTool === 0 && !mouseArea.drag.active && parent.enabled)
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463

                    ToolTip {
                        visible: trimInMouseArea.containsMouse && !trimInMouseArea.pressed
                        delay: 1000
                        timeout: 5000
                        background: Rectangle {
                            color: activePalette.alternateBase
                            border.color: activePalette.light
                        }
                        contentItem: Label {
                            color: activePalette.text
                            font.pointSize: root.fontUnit
                            text: i18n("In:%1\nPosition:%2", timeline.simplifiedTC(clipRoot.inPoint),timeline.simplifiedTC(clipRoot.modelStart))
                        }
                    }
                }
            }

            MouseArea {
                // Right resize handle
                id: trimOutMouseArea
                anchors.right: parent.right
                anchors.rightMargin: -clipRoot.border.width
                anchors.top: parent.top
                height: parent.height
                width: root.baseUnit / 2
                hoverEnabled: true
464
                enabled: !isLocked && (pressed || clipRoot.width > 3 * width)
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
                property bool shiftTrim: false
                property bool controlTrim: false
                property bool sizeChanged: false
                cursorShape: (containsMouse ? Qt.SizeHorCursor : Qt.ClosedHandCursor);
                drag.target: trimOutMouseArea
                drag.axis: Drag.XAxis
                drag.smoothed: false

                onPressed: {
                    root.autoScrolling = false
                    clipRoot.originalDuration = clipDuration
                    anchors.right = undefined
                    shiftTrim = mouse.modifiers & Qt.ShiftModifier
                    controlTrim = mouse.modifiers & Qt.ControlModifier
                    if (!shiftTrim && clipRoot.grouped) {
                        clipRoot.initGroupTrim(clipRoot)
                    }
                    trimOut.opacity = 0
                }
                onReleased: {
                    root.autoScrolling = timeline.autoScroll
                    anchors.right = parent.right
                    if (sizeChanged) {
                        clipRoot.trimmedOut(clipRoot, shiftTrim, controlTrim)
                        sizeChanged = false
                    }
                }
                onPositionChanged: {
                    if (mouse.buttons === Qt.LeftButton) {
                        var newDuration = Math.round((x + width) / timeScale)
495
                        if (maxDuration > 0 && (newDuration > maxDuration - inPoint) && !(mouse.modifiers & Qt.ControlModifier)) {
496
497
498
499
500
501
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
                            newDuration = maxDuration - inPoint
                        }
                        if (newDuration != clipDuration) {
                            sizeChanged = true
                            clipRoot.trimmingOut(clipRoot, newDuration, mouse, shiftTrim, controlTrim)
                        }
                    }
                }
                onEntered: {
                    if (!pressed) {
                        trimOut.opacity = 1
                    }
                }
                onExited: trimOut.opacity = 0
                ToolTip {
                    visible: trimOutMouseArea.containsMouse && !trimOutMouseArea.pressed
                    delay: 1000
                    timeout: 5000
                    background: Rectangle {
                        color: activePalette.alternateBase
                        border.color: activePalette.light
                    }
                    contentItem: Label {
                        color: activePalette.text
                        font.pointSize: root.fontUnit
                        text: i18n("Out: ") + timeline.simplifiedTC(clipRoot.outPoint)
                    }
                }
                Rectangle {
                    id: trimOut
                    anchors.right: parent.right
                    width: clipRoot.border.width
                    height: parent.height
                    color: 'red'
                    opacity: 0
                    Drag.active: trimOutMouseArea.drag.active
                    Drag.proposedAction: Qt.MoveAction
533
                    visible: trimOutMouseArea.pressed || (root.activeTool === 0 && !mouseArea.drag.active && parent.enabled)
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
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
649
650
651
652
653
654
655
656
657
658
659
660
661
662
                }
            }

            TimelineTriangle {
                // Green fade in triangle
                id: fadeInTriangle
                fillColor: 'green'
                width: Math.min(clipRoot.fadeIn * timeScale, container.width)
                height: parent.height
                anchors.left: parent.left
                anchors.top: parent.top
                opacity: 0.4
            }

            TimelineTriangle {
                // Red fade out triangle
                id: fadeOutCanvas
                fillColor: 'red'
                width: Math.min(clipRoot.fadeOut * timeScale, container.width)
                height: parent.height
                anchors.right: parent.right
                anchors.top: parent.top
                opacity: 0.4
                transform: Scale { xScale: -1; origin.x: fadeOutCanvas.width / 2}
            }

            Item {
                // Clipping container for clip names
                anchors.fill: parent
                clip: true
                Rectangle {
                    // Clip name background
                    id: labelRect
                    color: clipRoot.selected ? 'darkred' : '#66000000'
                    y: 0
                    width: label.width + 2 * clipRoot.border.width
                    height: label.height
                    visible: clipRoot.width > width / 2
                    Text {
                        // Clip name text
                        id: label
                        text: clipName + (clipRoot.speed != 1.0 ? ' [' + Math.round(clipRoot.speed*100) + '%]': '')
                        font.pointSize: root.fontUnit
                        anchors {
                            top: labelRect.top
                            left: labelRect.left
                            leftMargin: clipRoot.border.width
                        }
                        color: 'white'
                        //style: Text.Outline
                        //styleColor: 'black'
                    }
                }

                Rectangle {
                    // Offset info
                    id: offsetRect
                    color: 'darkgreen'
                    width: offsetLabel.width + radius
                    height: offsetLabel.height
                    radius: height/3
                    x: labelRect.width + 4
                    y: 2
                    visible: labelRect.visible && positionOffset != 0
                    MouseArea {
                        id: offsetArea
                        hoverEnabled: true
                        cursorShape: Qt.PointingHandCursor
                        anchors.fill: parent
                        onClicked: {
                            clearAndMove(positionOffset)
                        }
                        ToolTip {
                            visible: offsetArea.containsMouse
                            delay: 1000
                            timeout: 5000
                            background: Rectangle {
                                color: activePalette.alternateBase
                                border.color: activePalette.light
                            }
                            contentItem: Label {
                                color: activePalette.text
                                font.pointSize: root.fontUnit
                                text: positionOffset < 0 ? i18n("Offset: -%1", timeline.simplifiedTC(-positionOffset)) : i18n("Offset: %1", timeline.simplifiedTC(positionOffset))
                            }
                        }
                        Text {
                            id: offsetLabel
                            text: positionOffset
                            font.pointSize: root.fontUnit
                            anchors {
                                horizontalCenter: parent.horizontalCenter
                                topMargin: 1
                                leftMargin: 1
                            }
                            color: 'white'
                            style: Text.Outline
                            styleColor: 'black'
                        }
                    }
                }

                Rectangle {
                    // effect names background
                    id: effectsRect
                    color: '#555555'
                    width: effectLabel.width + 2
                    height: effectLabel.height
                    x: labelRect.x
                    anchors.top: labelRect.bottom
                    visible: labelRect.visible && clipRoot.effectNames != '' && container.showDetails
                    Text {
                        // Effect names text
                        id: effectLabel
                        text: clipRoot.effectNames
                        font.pointSize: root.fontUnit
                        visible: effectsRect.visible
                        anchors {
                            top: effectsRect.top
                            left: effectsRect.left
                            leftMargin: 1
                            // + ((isAudio || !settings.timelineShowThumbnails) ? 0 : inThumbnail.width) + 1
                        }
                        color: 'white'
                        //style: Text.Outline
                        styleColor: 'black'
                    }
                }
            }
663
664
665
666
667
668
669
670
671
672
673
674

            KeyframeView {
                id: effectRow
                clip: true
                anchors.fill: parent
                visible: clipRoot.showKeyframes && clipRoot.keyframeModel
                selected: clipRoot.selected
                inPoint: clipRoot.inPoint
                outPoint: clipRoot.outPoint
                masterObject: clipRoot
                kfrModel: clipRoot.hideClipViews ? 0 : clipRoot.keyframeModel
            }
675
        }
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707

        states: [
            State {
                name: 'locked'
                when: isLocked
                PropertyChanges {
                    target: clipRoot
                    color: root.lockedColor
                    opacity: 0.8
                    z: 0
                }
            },
            State {
                name: 'normal'
                when: clipRoot.selected === false
                PropertyChanges {
                    target: clipRoot
                    color: Qt.darker(getColor(), 1.5)
                    z: 0
                }
            },
            State {
                name: 'selected'
                when: clipRoot.selected === true
                PropertyChanges {
                    target: clipRoot
                    color: getColor()
                    z: 3
                }
            }
        ]

708
709
710
        MouseArea {
            // Add start composition area
            id: compInArea
711
712
            anchors.left: parent.left
            anchors.bottom: parent.bottom
713
            width: Math.min(root.baseUnit, container.height / 3)
714
            height: width
715
716
717
718
719
720
721
722
723
724
725
726
727
728
            hoverEnabled: true
            cursorShape: Qt.PointingHandCursor
            visible: !clipRoot.isAudio
            enabled: !clipRoot.isAudio && dragProxy.draggedItem === clipRoot.clipId && compositionIn.visible
            onPressed: {
                timeline.addCompositionToClip('', clipRoot.clipId, 0)
            }
            ToolTip {
                visible: compInArea.containsMouse && !dragProxyArea.pressed
                delay: 1000
                timeout: 5000
                background: Rectangle {
                    color: activePalette.alternateBase
                    border.color: activePalette.light
729
                }
730
731
732
733
                contentItem: Label {
                    color: activePalette.text
                    font.pointSize: root.fontUnit
                    text: i18n("Click to add composition")
734
735
                }
            }
736
737
738
739
740
            Rectangle {
                // Start composition box
                id: compositionIn
                anchors.bottom: parent.bottom
                anchors.left: parent.left
741
                width: compInArea.containsMouse ? parent.width : 5
742
743
744
745
746
747
748
749
                height: width
                radius: width / 2
                visible: clipRoot.width > 4 * parent.width && mouseArea.containsMouse && !dragProxyArea.pressed
                color: Qt.darker('mediumpurple')
                border.width: 3
                border.color: 'mediumpurple'
                Behavior on width { NumberAnimation { duration: 100 } }
            }
750
        }
751
752
753
754

        MouseArea {
            // Add end composition area
            id: compOutArea
755
756
            anchors.right: parent.right
            anchors.bottom: parent.bottom
757
            width: Math.min(root.baseUnit, container.height / 3)
758
            height: width
759
760
761
762
763
764
            hoverEnabled: true
            cursorShape: Qt.PointingHandCursor
            enabled: !clipRoot.isAudio && dragProxy.draggedItem === clipRoot.clipId && compositionOut.visible
            visible: !clipRoot.isAudio
            onPressed: {
                timeline.addCompositionToClip('', clipRoot.clipId, clipRoot.clipDuration - 1)
765
            }
766
            ToolTip {
767
                visible: compOutArea.containsMouse && !dragProxyArea.pressed
768
769
770
771
772
773
774
775
776
                delay: 1000
                timeout: 5000
                background: Rectangle {
                    color: activePalette.alternateBase
                    border.color: activePalette.light
                }
                contentItem: Label {
                    color: activePalette.text
                    font.pointSize: root.fontUnit
777
                    text: i18n("Click to add composition")
778
779
                }
            }
780
781
782
783
784
            Rectangle {
                // End composition box
                id: compositionOut
                anchors.bottom: parent.bottom
                anchors.right: parent.right
785
                width: compOutArea.containsMouse ? parent.height : 5
786
787
788
789
790
791
792
                height: width
                radius: width / 2
                visible: clipRoot.width > 4 * parent.width && mouseArea.containsMouse && !dragProxyArea.pressed
                color: Qt.darker('mediumpurple')
                border.width: 3
                border.color: 'mediumpurple'
                Behavior on width { NumberAnimation { duration: 100 } }
793
794
            }
        }
795
796
797

        MouseArea {
            // Fade out drag zone
798
            id: fadeOutMouseArea
799
800
801
            anchors.right: parent.right
            anchors.rightMargin: clipRoot.fadeOut <= 0 ? 0 : fadeOutCanvas.width - width / 2
            anchors.top: parent.top
802
            width: Math.min(root.baseUnit, container.height / 3)
803
            height: width
804
            hoverEnabled: true
805
806
            cursorShape: Qt.PointingHandCursor
            drag.target: fadeOutMouseArea
807
            drag.axis: Drag.XAxis
808
            drag.minimumX: - Math.ceil(width / 2)
809
810
            drag.maximumX: container.width + Math.ceil(width / 4)
            visible: clipRoot.width > 3 * width && mouseArea.containsMouse && !dragProxyArea.pressed
811
812
            property int startFadeOut
            property int lastDuration: -1
813
814
815
816
            drag.smoothed: false
            onClicked: {
                if (clipRoot.fadeOut == 0) {
                    timeline.adjustFade(clipRoot.clipId, 'fadeout', 0, -2)
817
818
                }
            }
819
            onPressed: {
820
                root.autoScrolling = false
821
822
                startFadeOut = clipRoot.fadeOut
                anchors.right = undefined
823
                fadeOutCanvas.opacity = 0.6
824
825
            }
            onReleased: {
826
                fadeOutCanvas.opacity = 0.4
827
                root.autoScrolling = timeline.autoScroll
828
                anchors.right = parent.right
829
830
831
                var duration = clipRoot.fadeOut
                timeline.adjustFade(clipRoot.clipId, 'fadeout', duration, startFadeOut)
                bubbleHelp.hide()
832
833
834
            }
            onPositionChanged: {
                if (mouse.buttons === Qt.LeftButton) {
835
                    var delta = clipRoot.clipDuration - Math.floor((x + width / 2 - clipRoot.border.width)/ timeScale)
836
837
838
839
840
841
                    var duration = Math.max(0, delta)
                    duration = Math.min(duration, clipRoot.clipDuration)
                    if (lastDuration != duration) {
                        lastDuration = duration
                        timeline.adjustFade(clipRoot.clipId, 'fadeout', duration, -1)
                        // Show fade duration as time in a "bubble" help.
842
                        var s = timeline.simplifiedTC(clipRoot.fadeOut)
843
                        bubbleHelp.show(clipRoot.x + x, parentTrack.y + parentTrack.height, s)
844
                    }
845
846
                }
            }
847
848
            Rectangle {
                id: fadeOutControl
849
850
851
                anchors.top: parent.top
                anchors.right: clipRoot.fadeOut > 0 ? undefined : parent.right
                anchors.horizontalCenter: clipRoot.fadeOut > 0 ? parent.horizontalCenter : undefined
852
                width: fadeOutMouseArea.containsMouse || Drag.active ? parent.width : 5
853
                height: width
854
                radius: width / 2
855
856
                color: 'darkred'
                border.width: 3
857
858
859
                border.color: 'red'
                enabled: !isLocked && !dragProxy.isComposition
                Drag.active: fadeOutMouseArea.drag.active
860
                Behavior on width { NumberAnimation { duration: 100 } }
861
862
863
864
865
                Rectangle {
                    id: fadeOutMarker
                    anchors.horizontalCenter: parent.horizontalCenter
                    anchors.top: parent.top
                    color: 'red'
866
                    height: container.height
867
                    width: 1
868
                    visible : clipRoot.fadeOut > 0 && (fadeOutMouseArea.containsMouse || fadeOutMouseArea.drag.active)
869
                }
870
            }
871
        }
872

873
        MouseArea {
874
            // Fade in drag zone
875
            id: fadeInMouseArea
876
877
878
            anchors.left: container.left
            anchors.leftMargin: clipRoot.fadeIn <= 0 ? 0 : (fadeInTriangle.width - width / 2)
            anchors.top: parent.top
879
            width: Math.min(root.baseUnit, container.height / 3)
880
            height: width
881
            hoverEnabled: true
882
883
884
885
            cursorShape: Qt.PointingHandCursor
            drag.target: fadeInMouseArea
            drag.minimumX: - Math.ceil(width / 2)
            drag.maximumX: container.width - width / 2
886
            drag.axis: Drag.XAxis
887
            drag.smoothed: false
888
            property int startFadeIn
889
890
891
892
            visible: clipRoot.width > 3 * width && mouseArea.containsMouse && !dragProxyArea.pressed
            onClicked: {
                if (clipRoot.fadeIn == 0) {
                    timeline.adjustFade(clipRoot.clipId, 'fadein', 0, -2)
893
894
                }
            }
895
            onPressed: {
896
                root.autoScrolling = false
897
898
                startFadeIn = clipRoot.fadeIn
                anchors.left = undefined
899
                fadeInTriangle.opacity = 0.6
900
                // parentTrack.clipSelected(clipRoot, parentTrack) TODO
901
902
            }
            onReleased: {
903
                root.autoScrolling = timeline.autoScroll
904
                fadeInTriangle.opacity = 0.4
905
906
                timeline.adjustFade(clipRoot.clipId, 'fadein', clipRoot.fadeIn, startFadeIn)
                bubbleHelp.hide()
907
                anchors.left = container.left
908
909
910
            }
            onPositionChanged: {
                if (mouse.buttons === Qt.LeftButton) {
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
911
                    var delta = Math.round((x + width / 2) / timeScale)
912
913
914
915
916
917
918
                    var duration = Math.max(0, delta)
                    duration = Math.min(duration, clipRoot.clipDuration - 1)
                    if (duration != clipRoot.fadeIn) {
                        timeline.adjustFade(clipRoot.clipId, 'fadein', duration, -1)
                        // Show fade duration as time in a "bubble" help.
                        var s = timeline.simplifiedTC(clipRoot.fadeIn)
                        bubbleHelp.show(clipRoot.x + x, parentTrack.y + parentTrack.height, s)
919
                    }
920
921
                }
            }
922
923
            Rectangle {
                id: fadeInControl
924
925
926
                anchors.top: parent.top
                anchors.left: clipRoot.fadeIn > 0 ? undefined : parent.left
                anchors.horizontalCenter: clipRoot.fadeIn > 0 ? parent.horizontalCenter : undefined
927
                width: fadeInMouseArea.containsMouse || Drag.active ? parent.width : 5
928
                height: width
929
                radius: width / 2
930
931
932
                color: 'green'
                border.width: 3
                border.color: '#FF66FFFF'
933
934
                enabled: !isLocked && !dragProxy.isComposition
                Drag.active: fadeInMouseArea.drag.active
935
                Behavior on width { NumberAnimation { duration: 100 } }
936
937
938
939
                Rectangle {
                    id: fadeInMarker
                    anchors.horizontalCenter: parent.horizontalCenter
                    anchors.top: parent.top
940
941
                    color: '#FF66FFFF'
                    height: container.height
942
                    width: 1
943
                    visible : clipRoot.fadeIn > 0 && (fadeInMouseArea.containsMouse || fadeInMouseArea.drag.active)
944
945
                }
            }
946
        }
947
    }
948
}