Reintroduce the much requested rotoscoping effect, now ported to qml

parent 891fe441
This diff is collapsed.
......@@ -1565,6 +1565,24 @@ QVariantList Monitor::effectPolygon() const
return root->property("centerPoints").toList();
}
QVariantList Monitor::effectRoto() const
{
QQuickItem *root = m_glMonitor->rootObject();
if (!root) {
return QVariantList();
}
QVariantList points = root->property("centerPoints").toList();
QVariantList controlPoints = root->property("centerPointsTypes").toList();
// rotoscoping effect needs a list of
QVariantList mix;
for (int i = 0; i < points.count(); i++) {
mix << controlPoints.at(2 * i);
mix << points.at(i);
mix << controlPoints.at(2 * i + 1);
}
return mix;
}
void Monitor::setEffectKeyframe(bool enable)
{
QQuickItem *root = m_glMonitor->rootObject();
......
......@@ -129,6 +129,7 @@ public:
QSize profileSize() const;
QRect effectRect() const;
QVariantList effectPolygon() const;
QVariantList effectRoto() const;
void setEffectKeyframe(bool enable);
void sendFrameForAnalysis(bool analyse);
void updateAudioForAnalysis();
......
......@@ -88,7 +88,7 @@ void QmlManager::setScene(Kdenlive::MonitorId id, MonitorSceneType type, QSize p
//TODO
m_view->setSource(QUrl(QStringLiteral("qrc:/qml/kdenlivemonitorrotoscene.qml")));
root = m_view->rootObject();
QObject::connect(root, SIGNAL(effectPolygonChanged()), this, SLOT(effectPolygonChanged()), Qt::UniqueConnection);
QObject::connect(root, SIGNAL(effectPolygonChanged()), this, SLOT(effectRotoChanged()), Qt::UniqueConnection);
root->setProperty("profile", QPoint(profile.width(), profile.height()));
root->setProperty("framesize", QRect(0, 0, profile.width(), profile.height()));
root->setProperty("scalex", (double) displayRect.width() / profile.width() * zoom);
......@@ -129,3 +129,18 @@ void QmlManager::effectPolygonChanged()
QVariantList points = m_view->rootObject()->property("centerPoints").toList();
emit effectPointsChanged(points);
}
void QmlManager::effectRotoChanged()
{
if (!m_view->rootObject()) return;
QVariantList points = m_view->rootObject()->property("centerPoints").toList();
QVariantList controlPoints = m_view->rootObject()->property("centerPointsTypes").toList();
// rotoscoping effect needs a list of
QVariantList mix;
for (int i = 0; i < points.count(); i++) {
mix << controlPoints.at(2 * i);
mix << points.at(i);
mix << controlPoints.at(2 * i + 1);
}
emit effectPointsChanged(mix);
}
......@@ -55,6 +55,7 @@ private:
private slots:
void effectRectChanged();
void effectPolygonChanged();
void effectRotoChanged();
signals:
void effectChanged(const QRect);
......
......@@ -53,25 +53,23 @@ RotoWidget::RotoWidget(const QByteArray &data, Monitor *monitor, const ItemInfo
QVBoxLayout *l = new QVBoxLayout(this);
m_keyframeWidget = new SimpleKeyframeWidget(t, m_out - m_in, this);
l->addWidget(m_keyframeWidget);
connect(m_monitor, SIGNAL(effectPointsChanged(QVariantList)), this, SLOT(slotUpdateDataPoints(QVariantList)));
//MonitorEditWidget *edit = NULL; //monitor->getEffectEdit();
//m_scene = NULL;//edit->getScene();
//m_scene->cleanup();
// 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_scene, SIGNAL(addKeyframe()), this, SLOT(slotAddKeyframe()));
*/
connect(m_keyframeWidget, SIGNAL(positionChanged(int)), this, SLOT(slotPositionChanged(int)));
connect(m_keyframeWidget, SIGNAL(keyframeAdded(int)), this, SLOT(slotAddKeyframe(int)));
connect(m_keyframeWidget, SIGNAL(keyframeRemoved(int)), this, SLOT(slotRemoveKeyframe(int)));
connect(m_keyframeWidget, SIGNAL(keyframeMoved(int,int)), this, SLOT(slotMoveKeyframe(int,int)));
connect(m_scene, SIGNAL(addKeyframe()), this, SLOT(slotAddKeyframe()));
setSpline(data, false);
setupTrackingListen(info);
m_scene->centerView();
*/
}
RotoWidget::~RotoWidget()
......@@ -93,18 +91,14 @@ void RotoWidget::slotSyncPosition(int relTimelinePos)
slotPositionChanged(relTimelinePos, false);
}
void RotoWidget::slotUpdateData(int pos, bool editing)
void RotoWidget::slotUpdateData(int pos, QList <BPoint> spline)
{
Q_UNUSED(editing)
int width = m_monitor->render->frameRenderWidth();
int height = m_monitor->render->renderHeight();
/*
* use the position of the on-monitor points to create a storable list
*/
//TODO: get points from monitor qml scene
QList <BPoint> spline; // = m_item->getPoints();
QList <QVariant> vlist;
foreach (const BPoint &point, spline) {
QList <QVariant> pl;
......@@ -131,9 +125,14 @@ void RotoWidget::slotUpdateData(int pos, bool editing)
emit valueChanged();
}
void RotoWidget::slotUpdateData(bool editing)
void RotoWidget::slotUpdateDataPoints(QVariantList points, int pos)
{
slotUpdateData(-1, editing);
QList <BPoint> bPoints;
for (int i = 0; i < points.size() / 3; i++) {
BPoint b(points.at(3 * i).toPointF(), points.at(3 * i + 1).toPointF(), points.at(3 * i + 2).toPointF());
bPoints << b;
}
slotUpdateData(pos, bPoints);
}
QByteArray RotoWidget::getSpline()
......@@ -154,6 +153,7 @@ void RotoWidget::slotPositionChanged(int pos, bool seek)
pos += m_in;
QList <BPoint> p;
bool isKeyframe = false;
if (m_data.canConvert(QVariant::Map)) {
QMap <QString, QVariant> map = m_data.toMap();
......@@ -187,13 +187,9 @@ void RotoWidget::slotPositionChanged(int pos, bool seek)
}
p.append(bp);
}
// TODO: port to qml monitor scene
/*m_item->setPoints(p);
m_item->setEnabled(false);*/
//m_scene->setEnabled(false);
} else {
p = getPoints(keyframe2);
isKeyframe = pos == keyframe2;
// only update if necessary to preserve the current point selection
// TODO: port to qml monitor scene
/*
......@@ -204,6 +200,7 @@ void RotoWidget::slotPositionChanged(int pos, bool seek)
}
} else {
p = getPoints(-1);
isKeyframe = true;
// only update if necessary to preserve the current point selection
// TODO: port to qml monitor scene
/*if (p != m_item->getPoints())
......@@ -211,6 +208,15 @@ void RotoWidget::slotPositionChanged(int pos, bool seek)
m_item->setEnabled(true);*/
//m_scene->setEnabled(true);
}
QVariantList centerPoints;
QVariantList controlPoints;
for (int i = 0; i < p.size(); i++) {
centerPoints << QVariant(p.at(i).p);
controlPoints << QVariant(p.at(i).h1);
controlPoints << QVariant(p.at(i).h2);
}
m_monitor->setUpEffectGeometry(QRect(), centerPoints, controlPoints);
m_monitor->setEffectKeyframe(isKeyframe);
if (seek)
emit seekToPos(pos - m_in);
......@@ -252,11 +258,7 @@ void RotoWidget::slotAddKeyframe(int pos)
if (pos < 0)
m_keyframeWidget->addKeyframe();
slotUpdateData(pos);
// TODO: port to qml monitor scene
//m_item->setEnabled(true);
//m_scene->setEnabled(true);
slotUpdateDataPoints(m_monitor->effectRoto(), pos);
}
void RotoWidget::slotRemoveKeyframe(int pos)
......
......@@ -87,9 +87,9 @@ private:
private slots:
/** @brief Updates/Creates the spline at @param pos based on the on-monitor items. */
void slotUpdateData(int pos = -1, bool editing = false);
void slotUpdateData(int pos, QList <BPoint> spline);
/** @brief Updates/Creates the spline at the current timeline position based on the on-monitor items. */
void slotUpdateData(bool editing);
void slotUpdateDataPoints(QVariantList points, int pos = -1);
/** @brief Updates the on-monitor items to fit the spline at position @param pos. */
void slotPositionChanged(int pos, bool seek = true);
......
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