Fix effects with multiple keyframable parameters

parent 04563d25
......@@ -25,7 +25,7 @@
<parameter type="animatedrect" name="rect" default="0 0 %width %height 1">
<name>Rectangle</name>
</parameter>
<parameter type="animated" name="rotation" max="360" min="-360" default="0" notintimeline="1">
<parameter type="keyframe" name="rotation" max="360" min="-360" default="0" notintimeline="1">
<name>Rotation</name>
</parameter>
<parameter type="list" name="compositing" default="0" paramlist="0;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;6;8">
......
......@@ -6,7 +6,7 @@
<parameter type="animatedrect" name="rect" default="0 0 %width %height 1">
<name>Rectangle</name>
</parameter>
<parameter type="animated" name="rotation" max="360" min="-360" default="0" notintimeline="1">
<parameter type="keyframe" name="rotation" max="360" min="-360" default="0" notintimeline="1">
<name>Rotation</name>
</parameter>
<parameter type="list" name="compositing" default="0" paramlist="0;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;6;8">
......
......@@ -26,6 +26,7 @@
#include "assets/view/widgets/abstractparamwidget.hpp"
#include "core.h"
#include "widgets/animationwidget.h"
#include "assets/view/widgets/keyframewidget.hpp"
#include <QDebug>
#include <QFontDatabase>
......@@ -35,6 +36,7 @@
AssetParameterView::AssetParameterView(QWidget *parent)
: QWidget(parent)
, m_mainKeyframeWidget(nullptr)
{
m_lay = new QVBoxLayout(this);
m_lay->setContentsMargins(2, 2, 2, 2);
......@@ -50,19 +52,22 @@ void AssetParameterView::setModel(const std::shared_ptr<AssetParameterModel> &mo
m_model = model;
m_model->prepareKeyframes();
connect(m_model.get(), &AssetParameterModel::dataChanged, this, &AssetParameterView::refresh);
AnimationWidget *animWidget = nullptr;
for (int i = 0; i < model->rowCount(); ++i) {
QModelIndex index = model->index(i, 0);
auto type = model->data(index, AssetParameterModel::TypeRole).value<ParamType>();
if (animWidget && (type == ParamType::Geometry || type == ParamType::Animated || type == ParamType::RestrictedAnim)) {
// Animation widget can have some extra params that should'nt build a new widget
// TODO refac
// animWidget->addParameter(index);
if (m_mainKeyframeWidget && (type == ParamType::Geometry || type == ParamType::Animated || type == ParamType::RestrictedAnim || type == ParamType::KeyframeParam)) {
// Keyframe widget can have some extra params that should'nt build a new widget
qDebug()<<"// FOUND ADDED PARAM";
m_mainKeyframeWidget->addParameter(index);
} else {
auto w = AbstractParamWidget::construct(model, index, range, frameSize, this);
qDebug()<<"// FOUND GEOM PARAM";
/*if (type == ParamType::Geometry || type == ParamType::Animated || type == ParamType::RestrictedAnim || type == ParamType::AnimatedRect) {
animWidget = static_cast<AnimationWidget *>(w);
}*/
if (type == ParamType::KeyframeParam || type == ParamType::AnimatedRect) {
m_mainKeyframeWidget = static_cast<KeyframeWidget *>(w);
}
connect(w, &AbstractParamWidget::valueChanged, this, &AssetParameterView::commitChanges);
connect(w, &AbstractParamWidget::seekToPos, this, &AssetParameterView::seekToPos);
m_lay->addWidget(w);
......@@ -115,6 +120,7 @@ void AssetParameterView::unsetModel()
// if a model is already there, we have to disconnect signals first
disconnect(m_model.get(), &AssetParameterModel::dataChanged, this, &AssetParameterView::refresh);
}
m_mainKeyframeWidget = nullptr;
// clear layout
m_widgets.clear();
......
......@@ -35,6 +35,7 @@
class QVBoxLayout;
class AbstractParamWidget;
class AssetParameterModel;
class KeyframeWidget;
class AssetParameterView : public QWidget
{
......@@ -69,6 +70,7 @@ protected:
QMutex m_lock;
std::shared_ptr<AssetParameterModel> m_model;
std::vector<AbstractParamWidget *> m_widgets;
KeyframeWidget *m_mainKeyframeWidget;
private slots:
/** @brief Apply a change of parameter sent by the view
......
......@@ -124,7 +124,7 @@ void KeyframeWidget::monitorSeek(int pos)
int out = in + pCore->getItemDuration(m_model->getOwnerId());
m_buttonAddDelete->setEnabled(pos -in > 0);
for (const auto & w : m_parameters) {
ParamType type = m_model->data(m_index, AssetParameterModel::TypeRole).value<ParamType>();
ParamType type = m_model->data(w.first, AssetParameterModel::TypeRole).value<ParamType>();
if (type == ParamType::AnimatedRect) {
((GeometryWidget *) w.second)->connectMonitor(pos >= in && pos < out);
break;
......@@ -146,7 +146,7 @@ void KeyframeWidget::slotRefreshParams()
KeyframeType keyType = m_keyframes->keyframeType(GenTime(pos, pCore->getCurrentFps()));
m_selectType->setCurrentItem((int) keyType);
for (const auto & w : m_parameters) {
ParamType type = m_model->data(m_index, AssetParameterModel::TypeRole).value<ParamType>();
ParamType type = m_model->data(w.first, AssetParameterModel::TypeRole).value<ParamType>();
if (type == ParamType::KeyframeParam) {
((DoubleWidget *) w.second)->setValue(m_keyframes->getInterpolatedValue(pos, w.first).toDouble());
} else if (type == ParamType::AnimatedRect) {
......@@ -240,16 +240,16 @@ void KeyframeWidget::addParameter(const QPersistentModelIndex& index)
QLocale locale;
locale.setNumberOptions(QLocale::OmitGroupSeparator);
// Retrieve parameters from the model
QString name = m_model->data(m_index, Qt::DisplayRole).toString();
QString comment = m_model->data(m_index, AssetParameterModel::CommentRole).toString();
QString suffix = m_model->data(m_index, AssetParameterModel::SuffixRole).toString();
QString name = m_model->data(index, Qt::DisplayRole).toString();
QString comment = m_model->data(index, AssetParameterModel::CommentRole).toString();
QString suffix = m_model->data(index, AssetParameterModel::SuffixRole).toString();
ParamType type = m_model->data(m_index, AssetParameterModel::TypeRole).value<ParamType>();
ParamType type = m_model->data(index, AssetParameterModel::TypeRole).value<ParamType>();
// Construct object
QWidget *paramWidget = nullptr;
if (type == ParamType::AnimatedRect) {
int inPos = m_model->data(m_index, AssetParameterModel::ParentInRole).toInt();
QPair <int, int>range(inPos, inPos + m_model->data(m_index, AssetParameterModel::ParentDurationRole).toInt());
int inPos = m_model->data(index, AssetParameterModel::ParentInRole).toInt();
QPair <int, int>range(inPos, inPos + m_model->data(index, AssetParameterModel::ParentDurationRole).toInt());
QSize frameSize = pCore->getCurrentFrameSize();
const QString value = m_keyframes->getInterpolatedValue(getPosition(), index).toString();
QRect rect;
......@@ -264,11 +264,11 @@ void KeyframeWidget::addParameter(const QPersistentModelIndex& index)
paramWidget = geomWidget;
} else {
double value = m_keyframes->getInterpolatedValue(getPosition(), index).toDouble();
double min = m_model->data(m_index, AssetParameterModel::MinRole).toDouble();
double max = m_model->data(m_index, AssetParameterModel::MaxRole).toDouble();
double defaultValue = locale.toDouble(m_model->data(m_index, AssetParameterModel::DefaultRole).toString());
int decimals = m_model->data(m_index, AssetParameterModel::DecimalsRole).toInt();
double factor = m_model->data(m_index, AssetParameterModel::FactorRole).toDouble();
double min = m_model->data(index, AssetParameterModel::MinRole).toDouble();
double max = m_model->data(index, AssetParameterModel::MaxRole).toDouble();
double defaultValue = locale.toDouble(m_model->data(index, AssetParameterModel::DefaultRole).toString());
int decimals = m_model->data(index, AssetParameterModel::DecimalsRole).toInt();
double factor = m_model->data(index, AssetParameterModel::FactorRole).toDouble();
auto doubleWidget = new DoubleWidget(name, value, min, max, defaultValue, comment, -1, suffix, decimals, this);
doubleWidget->factor = factor;
connect(doubleWidget, &DoubleWidget::valueChanged, [this, index](double v){
......
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