Warning, /multimedia/kdenlive/src/monitor/view/kdenlivemonitorcornerscene.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2016 Jean-Baptiste Mardelle <jb@kdenlive.org>
0003     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 import QtQuick 2.15
0007 
0008 Item {
0009     id: root
0010     objectName: "rootcornerscene"
0011     SystemPalette { id: activePalette }
0012 
0013     // default size, but scalable by user
0014     height: 300; width: 400
0015     property string comment
0016     property string framenum
0017     property rect framesize
0018     property point profile: controller.profile
0019     property int overlayType: controller.overlayType
0020     property color overlayColor: controller.overlayColor
0021     property point center
0022     property double scalex
0023     property double scaley
0024     property bool captureRightClick: false
0025     // Zoombar properties
0026     property double zoomStart: 0
0027     property double zoomFactor: 1
0028     property int zoomOffset: 0
0029     property bool showZoomBar: false
0030     property double stretch : 1
0031     property double sourcedar : 1
0032     onScalexChanged: canvas.requestPaint()
0033     onScaleyChanged: canvas.requestPaint()
0034     property double offsetx : 0
0035     property double offsety : 0
0036     onOffsetxChanged: canvas.requestPaint()
0037     onOffsetyChanged: canvas.requestPaint()
0038     onSourcedarChanged: refreshdar()
0039     property bool iskeyframe
0040     property int requestedKeyFrame
0041     property real baseUnit: fontMetrics.font.pixelSize * 0.8
0042     property int duration: 300
0043     property int mouseRulerPos: 0
0044     property double frameSize: 10
0045     property double timeScale: 1
0046     property var centerPoints: []
0047     onCenterPointsChanged: canvas.requestPaint()
0048     signal effectPolygonChanged()
0049 
0050     function updateClickCapture() {
0051         root.captureRightClick = false
0052     }
0053 
0054     function refreshdar() {
0055         canvas.darOffset = root.sourcedar < root.profile.x * root.stretch / root.profile.y ? (root.profile.x * root.stretch - root.profile.y * root.sourcedar) / (2 * root.profile.x * root.stretch) :(root.profile.y - root.profile.x * root.stretch / root.sourcedar) / (2 * root.profile.y);
0056         canvas.requestPaint()
0057     }
0058 
0059     onDurationChanged: {
0060         clipMonitorRuler.updateRuler()
0061     }
0062     onWidthChanged: {
0063         clipMonitorRuler.updateRuler()
0064     }
0065 
0066     FontMetrics {
0067         id: fontMetrics
0068         font.family: "Arial"
0069     }
0070 
0071     Canvas {
0072       id: canvas
0073       property double handleSize
0074       property double darOffset : 0
0075       width: root.width
0076       height: root.height
0077       anchors.centerIn: root
0078       contextType: "2d";
0079       handleSize: root.baseUnit / 2
0080       renderTarget: Canvas.FramebufferObject
0081       renderStrategy: Canvas.Cooperative
0082       onPaint:
0083       {
0084         var ctx = getContext('2d')
0085         //if (context) {
0086             ctx.clearRect(0,0, width, height);
0087             ctx.beginPath()
0088             ctx.strokeStyle = Qt.rgba(1, 0, 0, 0.5)
0089             ctx.fillStyle = Qt.rgba(1, 0, 0, 0.5)
0090             ctx.lineWidth = 2
0091             var p1 = convertPoint(root.centerPoints[0])
0092             var p2 = convertPoint(root.centerPoints[1])
0093             var p3 = convertPoint(root.centerPoints[2])
0094             var p4 = convertPoint(root.centerPoints[3])
0095             //console.log('paint' + p1);
0096 
0097           // Handles
0098           if (root.iskeyframe == true) {
0099             if (root.requestedKeyFrame == 0) {
0100                 ctx.fillStyle = Qt.rgba(1, 1, 0, 1)
0101                 ctx.fillRect(p1.x - handleSize, p1.y - handleSize, 2 * handleSize, 2 * handleSize);
0102                 ctx.fillStyle = Qt.rgba(1, 0, 0, 0.5)
0103             }
0104             else ctx.fillRect(p1.x - handleSize, p1.y - handleSize, 2 * handleSize, 2 * handleSize);
0105             if (root.requestedKeyFrame == 1) {
0106                 ctx.fillStyle = Qt.rgba(1, 1, 0, 1)
0107                 ctx.fillRect(p2.x - handleSize, p2.y - handleSize, 2 * handleSize, 2 * handleSize);
0108                 ctx.fillStyle = Qt.rgba(1, 0, 0, 0.5)
0109             }
0110             else ctx.fillRect(p2.x - handleSize, p2.y - handleSize, 2 * handleSize, 2 * handleSize);
0111             if (root.requestedKeyFrame == 2) {
0112                 ctx.fillStyle = Qt.rgba(1, 1, 0, 1)
0113                 ctx.fillRect(p3.x - handleSize, p3.y - handleSize, 2 * handleSize, 2 * handleSize);
0114                 ctx.fillStyle = Qt.rgba(1, 0, 0, 0.5)
0115             }
0116             else ctx.fillRect(p3.x - handleSize, p3.y - handleSize, 2 * handleSize, 2 * handleSize);
0117             if (root.requestedKeyFrame == 3) {
0118                 ctx.fillStyle = Qt.rgba(1, 1, 0, 1)
0119                 ctx.fillRect(p4.x - handleSize, p4.y - handleSize, 2 * handleSize, 2 * handleSize);
0120                 ctx.fillStyle = Qt.rgba(1, 0, 0, 0.5)
0121             }
0122             else ctx.fillRect(p4.x - handleSize, p4.y - handleSize, 2 * handleSize, 2 * handleSize);
0123           }
0124           // Rect
0125           ctx.moveTo(p1.x, p1.y)
0126           ctx.lineTo(p2.x, p2.y)
0127           ctx.lineTo(p3.x, p3.y)
0128           ctx.lineTo(p4.x, p4.y)
0129           ctx.lineTo(p1.x, p1.y)
0130 
0131           // Source rect
0132           if (canvas.darOffset != 0 && root.sourcedar > 0) {
0133               if (root.sourcedar < root.profile.x / root.profile.y) {
0134                   // vertical bars
0135                   ctx.moveTo(p1.x + (darOffset * (p2.x - p1.x)), p1.y + (darOffset * (p2.y - p1.y)))
0136                   ctx.lineTo(p4.x + (darOffset * (p3.x - p4.x)), p4.y + (darOffset * (p3.y-p4.y)))
0137                   ctx.moveTo(p2.x + (darOffset * (p1.x - p2.x)), p2.y + (darOffset * (p1.y - p2.y)))
0138                   ctx.lineTo(p3.x + (darOffset * (p4.x - p3.x)), p3.y + (darOffset * (p4.y-p3.y)))
0139               } else {
0140                   // horizontal bars
0141                   ctx.moveTo(p1.x + (darOffset * (p4.x - p1.x)), p1.y + (darOffset * (p4.y - p1.y)))
0142                   ctx.lineTo(p2.x + (darOffset * (p3.x - p2.x)), p2.y + (darOffset * (p3.y-p2.y)))
0143                   ctx.moveTo(p4.x + (darOffset * (p1.x - p4.x)), p4.y + (darOffset * (p1.y - p4.y)))
0144                   ctx.lineTo(p3.x + (darOffset * (p2.x - p3.x)), p3.y + (darOffset * (p2.y-p3.y)))
0145               }
0146           }
0147           ctx.stroke()
0148             //ctx.restore()
0149         //}
0150     }
0151 
0152     function convertPoint(p)
0153     {
0154         var x = frame.x + p.x * root.scalex
0155         var y = frame.y + p.y * root.scaley
0156         return Qt.point(x,y);
0157     }
0158   }
0159     Rectangle {
0160         id: frame
0161         objectName: "referenceframe"
0162         property color hoverColor: "#ff0000"
0163         width: root.profile.x * root.scalex
0164         height: root.profile.y * root.scaley
0165         x: root.center.x - width / 2 - root.offsetx
0166         y: root.center.y - height / 2 - root.offsety
0167         color: "transparent"
0168         border.color: "#ffffff00"
0169         Loader {
0170             anchors.fill: parent
0171             source: {
0172                 switch(root.overlayType)
0173                 {
0174                     case 0:
0175                         return '';
0176                     case 1:
0177                         return "OverlayStandard.qml";
0178                     case 2:
0179                         return "OverlayMinimal.qml";
0180                     case 3:
0181                         return "OverlayCenter.qml";
0182                     case 4:
0183                         return "OverlayCenterDiagonal.qml";
0184                     case 5:
0185                         return "OverlayThirds.qml";
0186                 }
0187             }
0188         }
0189     }
0190     MouseArea {
0191         id: global
0192         objectName: "global"
0193         width: root.width; height: root.height
0194         property bool kfrContainsMouse: false
0195         anchors.centerIn: root
0196         hoverEnabled: true
0197         cursorShape: kfrContainsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor
0198         onWheel: wheel => {
0199             controller.seek(wheel.angleDelta.x + wheel.angleDelta.y, wheel.modifiers)
0200         }
0201         onDoubleClicked: {
0202             controller.addRemoveKeyframe()
0203         }
0204 
0205         onPositionChanged: {
0206             if (root.iskeyframe == false) return;
0207             if (pressed && root.requestedKeyFrame >= 0) {
0208                 root.centerPoints[root.requestedKeyFrame].x = (mouseX - frame.x) / root.scalex;
0209                 root.centerPoints[root.requestedKeyFrame].y = (mouseY - frame.y) / root.scaley;
0210                 canvas.requestPaint()
0211                 root.effectPolygonChanged()
0212             } else {
0213               for(var i = 0; i < root.centerPoints.length; i++)
0214               {
0215                 var p1 = canvas.convertPoint(root.centerPoints[i])
0216                 if (Math.abs(p1.x - mouseX) <= canvas.handleSize && Math.abs(p1.y - mouseY) <= canvas.handleSize) {
0217                     if (i == root.requestedKeyFrame) {
0218                         kfrContainsMouse = true;
0219                         return;
0220                     }
0221                     root.requestedKeyFrame = i
0222                     canvas.requestPaint()
0223                     kfrContainsMouse = true;
0224                     return;
0225                 }
0226               }
0227               if (root.requestedKeyFrame == -1) {
0228                   return;
0229               }
0230               root.requestedKeyFrame = -1
0231               kfrContainsMouse = false;
0232               canvas.requestPaint()
0233             }
0234         }
0235     }
0236     EffectToolBar {
0237         id: effectToolBar
0238         anchors {
0239             right: parent.right
0240             top: parent.top
0241             bottom: parent.bottom
0242             rightMargin: 4
0243             leftMargin: 4
0244         }
0245     }
0246     MonitorRuler {
0247         id: clipMonitorRuler
0248         anchors {
0249             left: root.left
0250             right: root.right
0251             bottom: root.bottom
0252         }
0253         height: controller.rulerHeight
0254     }
0255 }