Fix crash on rotoscoping, effect still need porting to qml to be usable

parent 8c348991
# crashing effects
frei0r.transparency
frei0r.water
rotoscoping
# duplicate effects
frei0r.bluescreen0r
......
import QtQuick 2.0
Item {
id: root
objectName: "rootrotoscene"
// default size, but scalable by user
height: 300; width: 400
property string comment
property string framenum
property rect framesize
property point profile
property point center
property double scalex
property double scaley
property double stretch : 1
property double sourcedar : 1
onScalexChanged: canvas.requestPaint()
onScaleyChanged: canvas.requestPaint()
onSourcedarChanged: refreshdar()
property bool iskeyframe
property int requestedKeyFrame
property var centerPoints: []
property var centerPointsTypes: []
onCenterPointsChanged: canvas.requestPaint()
signal effectPolygonChanged()
signal addKeyframe()
signal seekToKeyframe()
function refreshdar() {
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);
canvas.requestPaint()
}
Text {
id: fontReference
property int fontSize
fontSize: font.pointSize
}
Canvas {
id: canvas
property double handleSize
property double darOffset : 0
width: root.width
height: root.height
anchors.centerIn: root
contextType: "2d";
handleSize: fontReference.fontSize / 2
renderTarget: Canvas.FramebufferObject
renderStrategy: Canvas.Cooperative
onPaint:
{
var ctx = getContext('2d')
//if (context) {
ctx.clearRect(0,0, width, height);
ctx.beginPath()
ctx.strokeStyle = Qt.rgba(1, 0, 0, 0.5)
ctx.fillStyle = Qt.rgba(1, 0, 0, 0.5)
ctx.lineWidth = 2
var p1 = convertPoint(root.centerPoints[0])
ctx.moveTo(p1.x, p1.y)
for (int i = 0; i < root.centerPoints.length - 1; i++) {
p1 = convertPoint(root.centerPoints[i + 1])
// Control points
var c1 = convertPoint(root.centerPointsTypes[i])
var c2 = convertPoint(root.centerPointsTypes[i + 1])
ctx.bezierCurveTo(c1.x, c1.y, c2.x, c2.y, p1.x, p1.y);;
}
// Handles
/*if (root.iskeyframe == true) {
if (root.requestedKeyFrame == 0) {
ctx.fillStyle = Qt.rgba(1, 1, 0, 1)
ctx.fillRect(p1.x - handleSize, p1.y - handleSize, 2 * handleSize, 2 * handleSize);
ctx.fillStyle = Qt.rgba(1, 0, 0, 0.5)
}
else ctx.fillRect(p1.x - handleSize, p1.y - handleSize, 2 * handleSize, 2 * handleSize);
if (root.requestedKeyFrame == 1) {
ctx.fillStyle = Qt.rgba(1, 1, 0, 1)
ctx.fillRect(p2.x - handleSize, p2.y - handleSize, 2 * handleSize, 2 * handleSize);
ctx.fillStyle = Qt.rgba(1, 0, 0, 0.5)
}
else ctx.fillRect(p2.x - handleSize, p2.y - handleSize, 2 * handleSize, 2 * handleSize);
if (root.requestedKeyFrame == 2) {
ctx.fillStyle = Qt.rgba(1, 1, 0, 1)
ctx.fillRect(p3.x - handleSize, p3.y - handleSize, 2 * handleSize, 2 * handleSize);
ctx.fillStyle = Qt.rgba(1, 0, 0, 0.5)
}
else ctx.fillRect(p3.x - handleSize, p3.y - handleSize, 2 * handleSize, 2 * handleSize);
if (root.requestedKeyFrame == 3) {
ctx.fillStyle = Qt.rgba(1, 1, 0, 1)
ctx.fillRect(p4.x - handleSize, p4.y - handleSize, 2 * handleSize, 2 * handleSize);
ctx.fillStyle = Qt.rgba(1, 0, 0, 0.5)
}
else ctx.fillRect(p4.x - handleSize, p4.y - handleSize, 2 * handleSize, 2 * handleSize);
}*/
// Rect
/*ctx.moveTo(p1.x, p1.y)
ctx.lineTo(p2.x, p2.y)
ctx.lineTo(p3.x, p3.y)
ctx.lineTo(p4.x, p4.y)
ctx.lineTo(p1.x, p1.y)*/
// Source rect
/*if (canvas.darOffset != 0 && root.sourcedar > 0) {
if (root.sourcedar < root.profile.x / root.profile.y) {
// vertical bars
ctx.moveTo(p1.x + (darOffset * (p2.x - p1.x)), p1.y + (darOffset * (p2.y - p1.y)))
ctx.lineTo(p4.x + (darOffset * (p3.x - p4.x)), p4.y + (darOffset * (p3.y-p4.y)))
ctx.moveTo(p2.x + (darOffset * (p1.x - p2.x)), p2.y + (darOffset * (p1.y - p2.y)))
ctx.lineTo(p3.x + (darOffset * (p4.x - p3.x)), p3.y + (darOffset * (p4.y-p3.y)))
} else {
// horizontal bars
ctx.moveTo(p1.x + (darOffset * (p4.x - p1.x)), p1.y + (darOffset * (p4.y - p1.y)))
ctx.lineTo(p2.x + (darOffset * (p3.x - p2.x)), p2.y + (darOffset * (p3.y-p2.y)))
ctx.moveTo(p4.x + (darOffset * (p1.x - p4.x)), p4.y + (darOffset * (p1.y - p4.y)))
ctx.lineTo(p3.x + (darOffset * (p2.x - p3.x)), p3.y + (darOffset * (p2.y-p3.y)))
}
}*/
ctx.stroke()
//ctx.restore()
//}
}
function convertPoint(p)
{
var x = frame.x + p.x * root.scalex
var y = frame.y + p.y * root.scaley
return Qt.point(x,y);
}
}
Rectangle {
id: frame
objectName: "referenceframe"
property color hoverColor: "#ff0000"
width: root.profile.x * root.scalex
height: root.profile.y * root.scaley
x: root.center.x - width / 2
y: root.center.y - height / 2
color: "transparent"
border.color: "#ffffff00"
}
MouseArea {
id: global
objectName: "global"
width: root.width; height: root.height
property bool containsMouse
anchors.centerIn: root
hoverEnabled: true
cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor
onDoubleClicked: {
root.addKeyframe()
}
onPositionChanged: {
if (root.iskeyframe == false) return;
if (pressed && root.requestedKeyFrame >= 0) {
root.centerPoints[root.requestedKeyFrame].x = (mouseX - frame.x) / root.scalex;
root.centerPoints[root.requestedKeyFrame].y = (mouseY - frame.y) / root.scaley;
canvas.requestPaint()
root.effectPolygonChanged()
} else {
for(var i = 0; i < root.centerPoints.length; i++)
{
var p1 = canvas.convertPoint(root.centerPoints[i])
if (Math.abs(p1.x - mouseX) <= canvas.handleSize && Math.abs(p1.y - mouseY) <= canvas.handleSize) {
if (i == root.requestedKeyFrame) {
containsMouse = true;
return;
}
root.requestedKeyFrame = i
canvas.requestPaint()
containsMouse = true;
return;
}
}
if (root.requestedKeyFrame == -1) {
return;
}
root.requestedKeyFrame = -1
containsMouse = false;
canvas.requestPaint()
}
}
}
}
......@@ -86,7 +86,7 @@ void QmlManager::setScene(Kdenlive::MonitorId id, MonitorSceneType type, QSize p
break;
case MonitorSceneRoto:
//TODO
m_view->setSource(QUrl(QStringLiteral("qrc:/qml/kdenlivemonitorcornerscene.qml")));
m_view->setSource(QUrl(QStringLiteral("qrc:/qml/kdenlivemonitorrotoscene.qml")));
root = m_view->rootObject();
QObject::connect(root, SIGNAL(effectPolygonChanged()), this, SLOT(effectPolygonChanged()), Qt::UniqueConnection);
root->setProperty("profile", QPoint(profile.width(), profile.height()));
......
......@@ -58,7 +58,8 @@ RotoWidget::RotoWidget(const QByteArray &data, Monitor *monitor, const ItemInfo
//m_scene = NULL;//edit->getScene();
//m_scene->cleanup();
m_item = NULL;/*new SplineItem(QList <BPoint>(), NULL, m_scene);
// TODO: port to qml monitor scene
/*m_item = new SplineItem(QList <BPoint>(), NULL, m_scene);
connect(m_item, SIGNAL(changed(bool)), this, SLOT(slotUpdateData(bool)));
connect(m_keyframeWidget, SIGNAL(positionChanged(int)), this, SLOT(slotPositionChanged(int)));
......@@ -80,12 +81,7 @@ RotoWidget::~RotoWidget()
delete m_keyframeWidget;
//if (m_scene) m_scene->removeItem(m_item);
delete m_item;
if (m_monitor) {
/*MonitorEditWidget *edit = m_monitor->getEffectEdit();
edit->removeCustomControls();*/
m_monitor->slotShowEffectScene(MonitorSceneDefault);
}
}
......@@ -107,7 +103,8 @@ void RotoWidget::slotUpdateData(int pos, bool editing)
/*
* use the position of the on-monitor points to create a storable list
*/
QList <BPoint> spline = m_item->getPoints();
//TODO: get points from monitor qml scene
QList <BPoint> spline; // = m_item->getPoints();
QList <QVariant> vlist;
foreach (const BPoint &point, spline) {
QList <QVariant> pl;
......@@ -148,8 +145,9 @@ QByteArray RotoWidget::getSpline()
void RotoWidget::slotPositionChanged(int pos, bool seek)
{
// do not update while the spline is being edited (points are being dragged)
if (m_item->editing())
return;
// TODO: port to qml monitor scene
/*if (m_item->editing())
return;*/
m_keyframeWidget->slotSetPosition(pos, false);
......@@ -190,23 +188,27 @@ void RotoWidget::slotPositionChanged(int pos, bool seek)
p.append(bp);
}
m_item->setPoints(p);
m_item->setEnabled(false);
// TODO: port to qml monitor scene
/*m_item->setPoints(p);
m_item->setEnabled(false);*/
//m_scene->setEnabled(false);
} else {
p = getPoints(keyframe2);
// only update if necessary to preserve the current point selection
// TODO: port to qml monitor scene
/*
if (p != m_item->getPoints())
m_item->setPoints(p);
m_item->setEnabled(pos == keyframe2);
m_item->setEnabled(pos == keyframe2);*/
//m_scene->setEnabled(pos == keyframe2);
}
} else {
p = getPoints(-1);
// only update if necessary to preserve the current point selection
if (p != m_item->getPoints())
// TODO: port to qml monitor scene
/*if (p != m_item->getPoints())
m_item->setPoints(p);
m_item->setEnabled(true);
m_item->setEnabled(true);*/
//m_scene->setEnabled(true);
}
......@@ -252,7 +254,8 @@ void RotoWidget::slotAddKeyframe(int pos)
m_keyframeWidget->addKeyframe();
slotUpdateData(pos);
m_item->setEnabled(true);
// TODO: port to qml monitor scene
//m_item->setEnabled(true);
//m_scene->setEnabled(true);
}
......
......@@ -3130,14 +3130,14 @@ void CustomTrackView::dropEvent(QDropEvent * event)
else
updateTrackDuration(info.track, addCommand);
// TODO: disabled when qtblend transition is fully implemented
if (item->binClip()->isTransparent() && getTransitionItemAtStart(info.startPos, info.track) == NULL) {
// Disabled since we now have working track compositing
/*if (item->binClip()->isTransparent() && getTransitionItemAtStart(info.startPos, info.track) == NULL) {
// add transparency transition if space is available
if (canBePastedTo(info, TransitionWidget)) {
QDomElement trans = MainWindow::transitions.getEffectByTag(QStringLiteral("affine"), QString()).cloneNode().toElement();
new AddTransitionCommand(this, info, getPreviousVideoTrack(info.track), trans, false, true, addCommand);
}
}
}*/
}
qDeleteAll(items);
// Add refresh command for redo
......
......@@ -7,6 +7,7 @@
<file alias="kdenliveclipmonitor.qml">../data/kdenliveclipmonitor.qml</file>
<file alias="kdenlivemonitoreffectscene.qml">../data/kdenlivemonitoreffectscene.qml</file>
<file alias="kdenlivemonitorcornerscene.qml">../data/kdenlivemonitorcornerscene.qml</file>
<file alias="kdenlivemonitorrotoscene.qml">../data/kdenlivemonitorsplit.qml</file>
<file alias="kdenlivemonitorsplit.qml">../data/kdenlivemonitorsplit.qml</file>
<file alias="kdenlivemonitorripple.qml">../data/kdenlivemonitorripple.qml</file>
<file alias="SceneToolBar.qml">../data/SceneToolBar.qml</file>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment