Commit 6a3fac98 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix bug and crash in keyframe apply value to selected keyframes

parent fc7bc4ce
......@@ -189,6 +189,16 @@ void KeyframeView::setDuration(int dur, int inPoint)
m_inPoint = inPoint;
int offset = pCore->getItemIn(m_model->getOwnerId());
emit atKeyframe(m_model->hasKeyframe(m_position + offset), m_model->singleKeyframe());
// Unselect keyframes that are outside range if any
QVector<int> toDelete;
for (auto &p : m_selectedKeyframes) {
if (p < m_inPoint || p >= m_inPoint + m_duration) {
toDelete << p;
}
}
for (auto &p : toDelete) {
m_selectedKeyframes.removeAll(p);
}
update();
}
......@@ -791,38 +801,62 @@ void KeyframeView::paintEvent(QPaintEvent *event)
void KeyframeView::copyCurrentValue(QModelIndex ix, const QString paramName)
{
const QString val = m_model->getInterpolatedValue(m_position, ix).toString();
int offset = pCore->getItemIn(m_model->getOwnerId());
const QString val = m_model->getInterpolatedValue(m_position + offset, ix).toString();
QString newVal;
const QStringList vals = val.split(QLatin1Char(' '));
int offset = pCore->getItemIn(m_model->getOwnerId());
qDebug()<<"=== COPYING VALS: "<<val<<", PARAM NAME_ "<<paramName;
qDebug()<<"=== COPYING VALS: "<<val<<" AT POS: "<<m_position<<", PARAM NAME_ "<<paramName;
auto *parentCommand = new QUndoCommand();
bool multiParams = paramName.contains(QLatin1Char(' '));
for (int kf : qAsConst(m_selectedKeyframes)) {
QString oldValue = m_model->getInterpolatedValue(kf, ix).toString();
QStringList oldVals = oldValue.split(QLatin1Char(' '));
if (paramName == QLatin1String("spinX")) {
bool found = false;
if (paramName.contains(QLatin1String("spinX"))) {
oldVals[0] = vals.at(0);
newVal = oldVals.join(QLatin1Char(' '));
parentCommand->setText(i18n("Update keyframes X position"));
} else if (paramName == QLatin1String("spinY")) {
found = true;
if (!multiParams) {
parentCommand->setText(i18n("Update keyframes X position"));
}
}
if (paramName.contains(QLatin1String("spinY"))) {
oldVals[1] = vals.at(1);
newVal = oldVals.join(QLatin1Char(' '));
parentCommand->setText(i18n("Update keyframes Y position"));
} else if (paramName == QLatin1String("spinW")) {
found = true;
if (!multiParams) {
parentCommand->setText(i18n("Update keyframes Y position"));
}
}
if (paramName.contains(QLatin1String("spinW"))) {
oldVals[2] = vals.at(2);
newVal = oldVals.join(QLatin1Char(' '));
parentCommand->setText(i18n("Update keyframes width"));
} else if (paramName == QLatin1String("spinH")) {
found = true;
if (!multiParams) {
parentCommand->setText(i18n("Update keyframes width"));
}
}
if (paramName.contains(QLatin1String("spinH"))) {
oldVals[3] = vals.at(3);
newVal = oldVals.join(QLatin1Char(' '));
parentCommand->setText(i18n("Update keyframes height"));
} else if (paramName == QLatin1String("spinO")) {
found = true;
if (!multiParams) {
parentCommand->setText(i18n("Update keyframes height"));
}
}
if (paramName.contains(QLatin1String("spinO"))) {
oldVals[4] = vals.at(4);
newVal = oldVals.join(QLatin1Char(' '));
parentCommand->setText(i18n("Update keyframes opacity"));
} else {
found = true;
if (!multiParams) {
parentCommand->setText(i18n("Update keyframes opacity"));
}
}
if (!found) {
newVal = val;
parentCommand->setText(i18n("Update keyframes value"));
} else if (multiParams) {
parentCommand->setText(i18n("Update keyframes value"));
}
bool result = m_model->updateKeyframe(GenTime(kf + offset, pCore->getCurrentFps()), newVal, ix, parentCommand);
if (result) {
......
......@@ -110,7 +110,7 @@ KeyframeWidget::KeyframeWidget(std::shared_ptr<AssetParameterModel> model, QMode
m_buttonApply = new QToolButton(this);
m_buttonApply->setAutoRaise(true);
m_buttonApply->setIcon(QIcon::fromTheme(QStringLiteral("edit-paste")));
m_buttonApply->setToolTip(i18n("Apply value to selected keyframes"));
m_buttonApply->setToolTip(i18n("Apply current position value to selected keyframes"));
m_buttonApply->setFocusPolicy(Qt::StrongFocus);
// Keyframe type widget
......@@ -292,6 +292,7 @@ KeyframeWidget::KeyframeWidget(std::shared_ptr<AssetParameterModel> model, QMode
}
paramList.clear();
QList<QCheckBox *> cbs = d.findChildren<QCheckBox *>();
QMap<QPersistentModelIndex, QStringList> params;
for (auto c : qAsConst(cbs)) {
//qDebug()<<"=== FOUND CBS: "<<KLocalizedString::removeAcceleratorMarker(c->text());
if (c->isChecked()) {
......@@ -299,26 +300,48 @@ KeyframeWidget::KeyframeWidget(std::shared_ptr<AssetParameterModel> model, QMode
if (rectParams.contains(ix)) {
// Check param name
QString cbName = KLocalizedString::removeAcceleratorMarker(c->text());
QString paramName;
if (cbName == i18n("Opacity")) {
paramName = QStringLiteral("spinO");
if (params.contains(ix)) {
params[ix] << QStringLiteral("spinO");
} else {
params.insert(ix, {QStringLiteral("spinO")});
}
} else if (cbName == i18n("Height")) {
paramName = QStringLiteral("spinH");
if (params.contains(ix)) {
params[ix] << QStringLiteral("spinH");
} else {
params.insert(ix, {QStringLiteral("spinH")});
}
} else if (cbName == i18n("Width")) {
paramName = QStringLiteral("spinW");
if (params.contains(ix)) {
params[ix] << QStringLiteral("spinW");
} else {
params.insert(ix, {QStringLiteral("spinW")});
}
} else if (cbName == i18n("X position")) {
paramName = QStringLiteral("spinX");
if (params.contains(ix)) {
params[ix] << QStringLiteral("spinX");
} else {
params.insert(ix, {QStringLiteral("spinX")});
}
} else if (cbName == i18n("Y position")) {
paramName = QStringLiteral("spinY");
if (params.contains(ix)) {
params[ix] << QStringLiteral("spinY");
} else {
params.insert(ix, {QStringLiteral("spinY")});
}
}
if (!paramName.isEmpty()) {
m_keyframeview->copyCurrentValue(ix, paramName);
if (!params.contains(ix)) {
params.insert(ix, {});
}
} else {
m_keyframeview->copyCurrentValue(ix, QString());
}
}
}
QMapIterator<QPersistentModelIndex, QStringList> p(params);
while (p.hasNext()) {
p.next();
m_keyframeview->copyCurrentValue(p.key(), p.value().join(QLatin1Char(' ')));
}
return;
});
//m_baseHeight = m_keyframeview->height() + m_selectType->defaultWidget()->sizeHint().height();
......
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