Start reimplementation of animwidget parameter

parent 64de6f29
......@@ -160,13 +160,13 @@ QVariant AssetParameterModel::data(const QModelIndex &index, int role) const
case DecimalsRole:
return (int)parseDoubleAttribute(QStringLiteral("decimals"), element);
case DefaultRole:
return element.attribute(QStringLiteral("default"));
return parseAttribute(QStringLiteral("default"), element);
case SuffixRole:
return element.attribute(QStringLiteral("suffix"));
case OpacityRole:
return element.attribute(QStringLiteral("opacity")) != QLatin1String("false");
case ValueRole:
return element.attribute(QStringLiteral("value")).isNull() ? element.attribute(QStringLiteral("default")) : element.attribute(QStringLiteral("value"));
return element.attribute(QStringLiteral("value")).isNull() ? parseAttribute(QStringLiteral("default"), element) : element.attribute(QStringLiteral("value"));
case ListValuesRole:
return element.attribute(QStringLiteral("paramlist")).split(QLatin1Char(';'));
case ListNamesRole: {
......@@ -235,6 +235,42 @@ ParamType AssetParameterModel::paramTypeFromStr(const QString &type)
return ParamType::Double;
}
// static
QVariant AssetParameterModel::parseAttribute(const QString &attribute, const QDomElement &element, QVariant defaultValue)
{
if (!element.hasAttribute(attribute)) {
return defaultValue;
}
ParamType type = paramTypeFromStr(element.attribute(QStringLiteral("type")));
QString content = element.attribute(attribute);
if (content.contains(QLatin1Char('%'))) {
std::unique_ptr<ProfileModel> &profile = pCore->getCurrentProfile();
int width = profile->width();
int height = profile->height();
// replace symbols in the double parameter
content.replace(QLatin1String("%maxWidth"), QString::number(width))
.replace(QLatin1String("%maxHeight"), QString::number(height))
.replace(QLatin1String("%width"), QString::number(width))
.replace(QLatin1String("%height"), QString::number(height));
if (type == ParamType::Double) {
// Use a Mlt::Properties to parse mathematical operators
Mlt::Properties p;
p.set("eval", content.toLatin1().constData());
return p.get_double("eval");
}
}
qDebug()<<"__RESTLT VAL: "<<content;
if (type == ParamType::Double) {
QLocale locale;
locale.setNumberOptions(QLocale::OmitGroupSeparator);
return locale.toDouble(content);
}
return content;
}
// static
double AssetParameterModel::parseDoubleAttribute(const QString &attribute, const QDomElement &element, double defaultValue)
{
......
......@@ -125,7 +125,7 @@ protected:
If keywords are found, mathematical operations are supported. For example "%width -1" is a valid value.
*/
static double parseDoubleAttribute(const QString &attribute, const QDomElement &element, double defaultValue = -1);
static QVariant parseAttribute(const QString &attribute, const QDomElement &element, QVariant defaultValue = QString());
struct ParamRow
{
ParamType type;
......
......@@ -302,7 +302,7 @@ void EffectStackView2::setupListView()
m_monitorSceneWanted = MonitorSceneDefault;
m_draggedEffect = nullptr;
m_draggedGroup = nullptr;
disconnect(m_effectMetaInfo.monitor, &Monitor::renderPosition, this, &EffectStackView2::slotRenderPos);
disconnect(m_effectMetaInfo.monitor, &Monitor::seekPosition, this, &EffectStackView2::slotRenderPos);
QWidget *view = m_effect->container->takeWidget();
if (view) {
/*QList<CollapsibleEffect *> allChildren = view->findChildren<CollapsibleEffect *>();
......@@ -433,7 +433,7 @@ void EffectStackView2::setupListView()
for (int i = 0; i < allGroups.count(); ++i) {
allGroups.at(i)->adjustEffects();
}
connect(m_effectMetaInfo.monitor, &Monitor::renderPosition, this, &EffectStackView2::slotRenderPos);
connect(m_effectMetaInfo.monitor, &Monitor::seekPosition, this, &EffectStackView2::slotRenderPos);
}
vbox1->addStretch(10);
......
......@@ -93,6 +93,7 @@ AnimationWidget::AnimationWidget(std::shared_ptr<AssetParameterModel> model, QMo
connect(m_ruler, &AnimKeyframeRuler::requestSeek, this, &AnimationWidget::requestSeek);
connect(m_ruler, &AnimKeyframeRuler::moveKeyframe, this, &AnimationWidget::moveKeyframe);
connect(m_timePos, SIGNAL(timeCodeEditingFinished()), this, SLOT(slotPositionChanged()));
connect(m_monitor, &Monitor::seekPosition, this, &AnimationWidget::monitorSeek, Qt::UniqueConnection);
if (m_frameSize.isNull() || m_frameSize.width() == 0 || m_frameSize.height() == 0) {
m_frameSize = m_monitorSize;
......@@ -322,7 +323,7 @@ void AnimationWidget::doAddKeyframe(int pos, QString paramName, bool directUpdat
if (directUpdate) {
m_ruler->setActiveKeyframe(pos);
rebuildKeyframes();
emit valueChanged();
emit valueChanged(m_index, QString(m_animController.serialize_cut()));
}
}
......@@ -365,7 +366,7 @@ void AnimationWidget::slotAddDeleteKeyframe(bool add, int pos)
m_animController = m_animProperties.get_animation(m_inTimeline.toUtf8().constData());
// Rebuild
rebuildKeyframes();
emit valueChanged();
emit valueChanged(m_index, QString(m_animController.serialize_cut()));
}
void AnimationWidget::slotRemoveNext()
......@@ -396,7 +397,7 @@ void AnimationWidget::slotRemoveNext()
m_animController = m_animProperties.get_animation(m_inTimeline.toUtf8().constData());
// Rebuild
rebuildKeyframes();
emit valueChanged();
emit valueChanged(m_index, QString(m_animController.serialize_cut()));
}
void AnimationWidget::slotSyncPosition(int relTimelinePos)
......@@ -438,7 +439,7 @@ void AnimationWidget::moveKeyframe(int oldPos, int newPos)
}
rebuildKeyframes();
slotPositionChanged(m_ruler->position(), false);
emit valueChanged();
emit valueChanged(m_index, QString(m_animController.serialize_cut()));
}
void AnimationWidget::rebuildKeyframes()
......@@ -712,7 +713,7 @@ void AnimationWidget::slotEditKeyframeType(QAction *action)
}*/
rebuildKeyframes();
setupMonitor();
emit valueChanged();
emit valueChanged(m_index, QString(m_animController.serialize_cut()));
}
}
......@@ -925,7 +926,7 @@ void AnimationWidget::slotUpdateVisibleParameter(bool display)
m_inTimeline = slider->objectName();
m_animController = m_animProperties.get_animation(m_inTimeline.toUtf8().constData());
rebuildKeyframes();
emit valueChanged();
emit valueChanged(m_index, QString(m_animController.serialize_cut()));
}
}
......@@ -945,7 +946,7 @@ void AnimationWidget::slotAdjustKeyframeValue(double value)
// This is a keyframe
type = m_animController.keyframe_type(pos);
m_animProperties.anim_set(m_inTimeline.toUtf8().constData(), value / slider->factor, pos, m_outPoint, type);
emit valueChanged();
emit valueChanged(m_index, QString(m_animController.serialize_cut()));
} else if (m_animController.key_count() <= 1) {
pos = m_animController.key_get_frame(0);
if (pos >= 0) {
......@@ -953,7 +954,7 @@ void AnimationWidget::slotAdjustKeyframeValue(double value)
type = m_animController.keyframe_type(pos);
}
m_animProperties.anim_set(m_inTimeline.toUtf8().constData(), value / slider->factor, pos, m_outPoint, type);
emit valueChanged();
emit valueChanged(m_index, QString(m_animController.serialize_cut()));
}
}
}
......@@ -991,14 +992,14 @@ void AnimationWidget::slotAdjustRectKeyframeValue()
// This is a keyframe
m_animProperties.anim_set(m_rectParameter.toUtf8().constData(), rect, pos, m_outPoint,
(mlt_keyframe_type)m_selectType->currentAction()->data().toInt());
emit valueChanged();
emit valueChanged(m_index, QString(m_animController.serialize_cut()));
setupMonitor(QRect(rect.x, rect.y, rect.w, rect.h));
} else if (m_animController.key_count() <= 1) {
pos = m_animController.key_get_frame(0);
if (pos >= 0) {
m_animProperties.anim_set(m_rectParameter.toUtf8().constData(), rect, pos, m_outPoint,
(mlt_keyframe_type)m_selectType->currentAction()->data().toInt());
emit valueChanged();
emit valueChanged(m_index, QString(m_animController.serialize_cut()));
setupMonitor(QRect(rect.x, rect.y, rect.w, rect.h));
}
}
......@@ -1087,7 +1088,7 @@ void AnimationWidget::slotReverseKeyframeType(bool reverse)
m_attachedToEnd = -2;
}
rebuildKeyframes();
emit valueChanged();
emit valueChanged(m_index, QString(m_animController.serialize_cut()));
}
}
......@@ -1157,7 +1158,7 @@ void AnimationWidget::applyPreset(int ix)
}
m_animController = m_animProperties.get_animation(m_inTimeline.toUtf8().constData());
rebuildKeyframes();
emit valueChanged();
emit valueChanged(m_index, QString(m_animController.serialize_cut()));
}
void AnimationWidget::savePreset()
......@@ -1298,6 +1299,9 @@ void AnimationWidget::slotSeekToKeyframe(int ix)
void AnimationWidget::connectMonitor(bool activate)
{
if (m_active == activate) {
return;
}
m_active = activate;
if (!m_spinX) {
// No animated rect displayed in monitor, return
......@@ -1312,7 +1316,7 @@ void AnimationWidget::connectMonitor(bool activate)
connect(m_monitor, &Monitor::seekToPreviousKeyframe, this, &AnimationWidget::slotPrevious, Qt::UniqueConnection);
connect(m_monitor, SIGNAL(addKeyframe()), this, SLOT(slotAddKeyframe()), Qt::UniqueConnection);
connect(m_monitor, SIGNAL(deleteKeyframe()), this, SLOT(slotDeleteKeyframe()), Qt::UniqueConnection);
int framePos = qBound<int>(0, m_monitor->position() - m_clipPos, m_timePos->maximum());
int framePos = qBound<int>(0, m_monitor->position() - m_inPoint, m_timePos->maximum());
slotPositionChanged(framePos, false);
double ratio = (double)m_spinWidth->value() / m_spinHeight->value();
if (m_frameSize.width() != m_monitorSize.width() || m_frameSize.height() != m_monitorSize.height()) {
......@@ -1424,7 +1428,7 @@ void AnimationWidget::reload(const QString &tag, const QString &data)
m_animProperties.anim_get_rect(m_rectParameter.toUtf8().constData(), 0, m_outPoint);
}
rebuildKeyframes();
emit valueChanged();
emit valueChanged(m_index, QString(m_animController.serialize_cut()));
}
QString AnimationWidget::defaultValue(const QString &paramName)
......@@ -1446,6 +1450,7 @@ void AnimationWidget::slotAdjustToSource()
{
m_spinWidth->blockSignals(true);
m_spinHeight->blockSignals(true);
qDebug()<<"ADjust src: "<<m_frameSize.width() / pCore->getCurrentSar();
m_spinWidth->setValue((int)(m_frameSize.width() / pCore->getCurrentSar() + 0.5), false);
m_spinHeight->setValue(m_frameSize.height(), false);
m_spinWidth->blockSignals(false);
......@@ -1477,6 +1482,7 @@ void AnimationWidget::slotAdjustToFrameSize()
// Fit to height
double factor = (double)m_monitorSize.height() / m_frameSize.height();
m_spinHeight->setValue(m_monitorSize.height());
qDebug()<<"*** ADJ WIRGH FIT: "<<m_frameSize.width() / pCore->getCurrentSar();
m_spinWidth->setValue((int)(m_frameSize.width() / pCore->getCurrentSar() * factor + 0.5));
// Center
m_spinX->blockSignals(true);
......@@ -1605,6 +1611,18 @@ void AnimationWidget::slotAdjustRectHeight()
slotAdjustRectKeyframeValue();
}
void AnimationWidget::monitorSeek(int pos)
{
slotPositionChanged(pos - m_inPoint, false);
if (pos > m_inPoint && pos < m_outPoint) {
connectMonitor(true);
m_monitor->slotShowEffectScene(MonitorSceneGeometry);
} else {
connectMonitor(false);
m_monitor->slotShowEffectScene(MonitorSceneDefault);
}
}
void AnimationWidget::slotShowComment(bool show)
{
}
......
......@@ -179,11 +179,13 @@ private slots:
void slotAdjustRectWidth();
/** @brief Seek monitor. */
void requestSeek(int pos);
/** @brief monitor seek pos changed. */
void monitorSeek(int pos);
signals:
/** @brief keyframes dropped / pasted on widget, import them. */
void setKeyframes(const QString &);
void valueChanged();
};
#endif
......@@ -1551,7 +1551,7 @@ void Monitor::slotEnableEffectScene(bool enable)
MonitorSceneType sceneType = enable ? m_lastMonitorSceneType : MonitorSceneDefault;
slotShowEffectScene(sceneType, true);
if (enable) {
emit renderPosition(render->seekFramePosition());
emit seekPosition(m_glMonitor->getCurrentPos());
}
}
......
......@@ -335,7 +335,6 @@ public slots:
void checkOverlay(int pos = -1);
signals:
void renderPosition(int);
void seekPosition(int);
/** @brief Request a timeline seeking if diff is true, position is a relative offset, otherwise an absolute position */
void seekTimeline(int position);
......
......@@ -164,13 +164,13 @@ void TransitionSettings::slotTransitionChanged(bool reinit, bool updateCurrent)
QDomElement e = m_usedTransition->toXML().cloneNode().toElement();
if (reinit) {
// Reset the transition parameters to the default one
disconnect(m_effectEdit->monitor(), &Monitor::renderPosition, this, &TransitionSettings::slotRenderPos);
disconnect(m_effectEdit->monitor(), &Monitor::seekPosition, this, &TransitionSettings::slotRenderPos);
QDomElement newTransition = MainWindow::transitions.getEffectByName(transitionList->currentText()).cloneNode().toElement();
pCore->projectManager()->currentTimeline()->transitionHandler->initTransition(newTransition);
slotUpdateEffectParams(e, newTransition);
m_effectEdit->transferParamDesc(newTransition, m_usedTransition->info(), false);
if (m_effectEdit->needsMonitorEffectScene() != 0u) {
connect(m_effectEdit->monitor(), &Monitor::renderPosition, this, &TransitionSettings::slotRenderPos, Qt::UniqueConnection);
connect(m_effectEdit->monitor(), &Monitor::seekPosition, this, &TransitionSettings::slotRenderPos, Qt::UniqueConnection);
}
} else if (!updateCurrent) {
// Transition changed, update parameters dialog
......@@ -192,7 +192,7 @@ void TransitionSettings::slotTransitionChanged(bool reinit, bool updateCurrent)
}
}
if (m_effectEdit->needsMonitorEffectScene() != 0u) {
connect(m_effectEdit->monitor(), &Monitor::renderPosition, this, &TransitionSettings::slotRenderPos, Qt::UniqueConnection);
connect(m_effectEdit->monitor(), &Monitor::seekPosition, this, &TransitionSettings::slotRenderPos, Qt::UniqueConnection);
}
}
slotCheckMonitorPosition(m_effectEdit->monitor()->render->seekFramePosition());
......@@ -223,7 +223,7 @@ void TransitionSettings::slotTransitionItemSelected(Transition *t, int nextTrack
setEnabled(t != nullptr);
m_effectEdit->setFrameSize(p);
m_autoTrackTransition = nextTrack;
disconnect(m_effectEdit->monitor(), &Monitor::renderPosition, this, &TransitionSettings::slotRenderPos);
disconnect(m_effectEdit->monitor(), &Monitor::seekPosition, this, &TransitionSettings::slotRenderPos);
if (t == m_usedTransition) {
if (t == nullptr) {
return;
......@@ -245,7 +245,7 @@ void TransitionSettings::slotTransitionItemSelected(Transition *t, int nextTrack
}
if (m_effectEdit->needsMonitorEffectScene() != 0u) {
slotRenderPos(m_effectEdit->monitor()->position());
connect(m_effectEdit->monitor(), &Monitor::renderPosition, this, &TransitionSettings::slotRenderPos, Qt::UniqueConnection);
connect(m_effectEdit->monitor(), &Monitor::seekPosition, this, &TransitionSettings::slotRenderPos, Qt::UniqueConnection);
}
return;
}
......@@ -273,7 +273,7 @@ void TransitionSettings::slotTransitionItemSelected(Transition *t, int nextTrack
}
if (m_effectEdit->needsMonitorEffectScene() != 0u) {
slotRenderPos(m_effectEdit->monitor()->position());
connect(m_effectEdit->monitor(), &Monitor::renderPosition, this, &TransitionSettings::slotRenderPos, Qt::UniqueConnection);
connect(m_effectEdit->monitor(), &Monitor::seekPosition, this, &TransitionSettings::slotRenderPos, Qt::UniqueConnection);
}
} else {
// null transition selected
......
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