Commit ad2c3f22 authored by Julius Künzel's avatar Julius Künzel
Browse files

Make it possible to copy and import rotoscoping keyframes

BUG: 442372
FIXED-IN: 21.12.0
parent a17e839c
Pipeline #82837 canceled with stage
......@@ -41,6 +41,11 @@ void KeyframeMonitorHelper::addIndex(const QPersistentModelIndex &index)
m_indexes << index;
}
QList<QPersistentModelIndex> KeyframeMonitorHelper::getIndexes()
{
return m_indexes;
}
void KeyframeMonitorHelper::refreshParams(int /* pos */ )
{
QVariantList points;
......
......@@ -41,6 +41,8 @@ public:
*/
virtual void refreshParams(int pos);
QList<QPersistentModelIndex> getIndexes();
protected:
Monitor *m_monitor;
std::shared_ptr<AssetParameterModel> m_model;
......
......@@ -873,7 +873,7 @@ QJsonDocument AssetParameterModel::toJson(bool includeFixed) const
QString x, y, w, h;
int rectIn = 0, rectOut = 0;
for (const auto &param : m_params) {
if (!includeFixed && param.second.type != ParamType::KeyframeParam && param.second.type != ParamType::AnimatedRect) {
if (!includeFixed && param.second.type != ParamType::KeyframeParam && param.second.type != ParamType::AnimatedRect && param.second.type != ParamType::Roto_spline) {
continue;
}
QJsonObject currentParam;
......
......@@ -151,6 +151,9 @@ KeyframeImport::KeyframeImport(const QString &animData, std::shared_ptr<AssetPar
if(name.contains("Position X") || name.contains("Position Y") || name.contains("Size X") || name.contains("Size Y")) {
count++;
}
} else if (type == ParamType::Roto_spline) {
m_simpleTargets.insert(i18n("Rotoscoping shape"), idx);
QString name(m_model->data(idx, AssetParameterModel::NameRole).toString());
} else if (type == ParamType::AnimatedRect) {
m_geometryTargets.insert(m_model->data(idx, Qt::DisplayRole).toString(), idx);
}
......@@ -341,6 +344,10 @@ void KeyframeImport::updateDataDisplay()
updateRange();
return;
}
if (type == ParamType::Roto_spline) {
m_sourceCombo->addItem(i18n("Rotoscoping shape"), ImportRoles::RotoData);
return;
}
double wDist = m_maximas.at(2).y() - m_maximas.at(2).x();
double hDist = m_maximas.at(3).y() - m_maximas.at(3).x();
m_sourceCombo->addItem(i18n("Geometry"), ImportRoles::FullGeometry);
......@@ -538,6 +545,10 @@ QString KeyframeImport::selectedData() const
maximas = QPoint(qMin(m_maximas.at(ix).x(), 0), qMax(m_maximas.at(ix).y(), pCore->getCurrentProfile()->height()));
}
std::shared_ptr<Mlt::Properties> animData = KeyframeModel::getAnimation(m_model, m_dataCombo->currentData().toString());
if (m_dataCombo->currentText() == "spline") {
QJsonDocument doc = QJsonDocument::fromJson(m_dataCombo->currentData().toString().toLocal8Bit());
return QString(doc.toJson(QJsonDocument::Compact));
}
std::shared_ptr<Mlt::Animation> anim(new Mlt::Animation(animData->get_animation("key")));
animData->anim_get_double("key", m_inPoint->getPosition(), m_outPoint->getPosition());
int existingKeys = anim->key_count();
......@@ -807,6 +818,14 @@ void KeyframeImport::importSelectedData()
// Import our keyframes
int frame = 0;
KeyframeImport::ImportRoles convertMode = static_cast<KeyframeImport::ImportRoles> (m_sourceCombo->currentData().toInt());
if (convertMode == ImportRoles::RotoData && m_targetCombo->currentText() == i18n("Rotoscoping shape")) {
QJsonObject json = QJsonDocument::fromJson(selectedData().toLocal8Bit()).object();
for (int i = 0; i < json.count(); i++) {
int frame = json.keys().at(i).toInt();
km->addKeyframe(GenTime(frame - m_inPoint->getPosition() + m_offsetPoint->getPosition(), pCore->getCurrentFps()), KeyframeType::Linear, json.value(json.keys().at(i)), true, undo, redo);
}
continue;
}
mlt_keyframe_type type;
mlt_rect firstRect = animData->anim_get_rect("key", anim->key_get_frame(0));
for (int i = 0; i < anim->key_count(); i++) {
......
......@@ -66,6 +66,7 @@ private:
protected:
enum ImportRoles {
SimpleValue,
RotoData,
FullGeometry,
Position,
InvertedPosition,
......
......@@ -705,6 +705,9 @@ void KeyframeWidget::slotImportKeyframes()
for (const auto &w : m_parameters) {
indexes << w.first;
}
if (m_neededScene == MonitorSceneRoto) {
indexes << m_monitorHelper->getIndexes();
}
QPointer<KeyframeImport> import = new KeyframeImport(values, m_model, indexes, m_model->data(m_index, AssetParameterModel::ParentInRole).toInt(), m_model->data(m_index, AssetParameterModel::ParentDurationRole).toInt(), this);
import->show();
connect(import, &KeyframeImport::updateQmlView, this, &KeyframeWidget::slotRefreshParams);
......
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