Allow reordering of bin clip effects

CCBUG: 358703
parent 622f1bbb
......@@ -2216,6 +2216,36 @@ void Bin::slotDeleteEffect(const QString &id, QDomElement effect)
m_doc->commandStack()->push(command);
}
void Bin::slotMoveEffect(const QString &id, QList <int> currentPos, int newPos)
{
MoveBinEffectCommand *command = new MoveBinEffectCommand(this, id, currentPos, newPos);
m_doc->commandStack()->push(command);
}
void Bin::moveEffect(const QString &id, const QList <int> &oldPos, const QList <int> &newPos)
{
ProjectClip *clip = m_rootFolder->clip(id);
if (!clip) return;
int new_position = newPos.at(0);
ClipController *ctrl = clip->controller();
int effectsCount = ctrl->effectsCount();
if (new_position > effectsCount) {
new_position = effectsCount;
}
int old_position = oldPos.at(0);
for (int i = 0; i < newPos.count(); ++i) {
if (old_position > new_position) {
// Moving up, we need to adjust index
old_position = oldPos.at(i);
new_position = newPos.at(i);
}
ctrl->moveEffect(old_position, new_position);
}
emit masterClipUpdated(ctrl, m_monitor);
m_monitor->refreshMonitorIfActive();
ctrl->reloadTrackProducers();
}
void Bin::removeEffect(const QString &id, const QDomElement &effect)
{
if (effect.isNull()) {
......
......@@ -486,6 +486,7 @@ public:
void deleteAllClipMarkers(const QString &id);
/** @brief Remove an effect from a bin clip. */
void removeEffect(const QString &id, const QDomElement &effect);
void moveEffect(const QString &id, const QList <int> &oldPos, const QList <int> &newPos);
/** @brief Add an effect to a bin clip. */
void addEffect(const QString &id, QDomElement &effect);
/** @brief Edit an effect settings to a bin clip. */
......@@ -611,6 +612,7 @@ public slots:
void slotSaveClipMarkers(const QString &id);
void slotDuplicateClip();
void slotDeleteEffect(const QString &id, QDomElement effect);
void slotMoveEffect(const QString &id, QList <int> currentPos, int newPos);
/** @brief Request audio thumbnail for clip with id */
void slotCreateAudioThumb(const QString &id);
/** @brief Abort audio thumbnail for clip with id */
......
......@@ -150,6 +150,29 @@ void RemoveBinEffectCommand::redo()
m_bin->removeEffect(m_clipId, m_effect);
}
MoveBinEffectCommand::MoveBinEffectCommand(Bin *bin, const QString &clipId, QList <int> oldPos, int newPos, QUndoCommand *parent) :
QUndoCommand(parent),
m_bin(bin),
m_clipId(clipId),
m_oldindex(oldPos)
{
for (int i = 0; i < m_oldindex.count(); ++i) {
m_newindex << newPos + i;
}
setText(i18n("Move Bin Effect"));
}
// virtual
void MoveBinEffectCommand::undo()
{
m_bin->moveEffect(m_clipId, m_newindex, m_oldindex);
}
// virtual
void MoveBinEffectCommand::redo()
{
m_bin->moveEffect(m_clipId, m_oldindex, m_newindex);
}
RenameBinSubClipCommand::RenameBinSubClipCommand(Bin *bin, const QString &clipId, const QString &newName, const QString &oldName, int in, int out, QUndoCommand *parent) :
QUndoCommand(parent),
m_bin(bin),
......
......@@ -106,6 +106,19 @@ private:
QDomElement m_effect;
};
class MoveBinEffectCommand : public QUndoCommand
{
public:
explicit MoveBinEffectCommand(Bin *bin, const QString &clipId, QList <int> oldPos, int newPos, QUndoCommand *parent = 0);
void undo();
void redo();
private:
Bin *m_bin;
QString m_clipId;
QList <int> m_oldindex;
QList <int> m_newindex;
};
class RenameBinSubClipCommand : public QUndoCommand
{
public:
......
......@@ -840,7 +840,7 @@ void EffectStackView2::slotMoveEffectUp(const QList<int> &indexes, bool up)
if (m_status == TIMELINE_TRACK) emit changeEffectPosition(NULL, m_trackindex, indexes, endPos);
else if (m_status == TIMELINE_CLIP) emit changeEffectPosition(m_clipref, -1, indexes, endPos);
else if (m_status == MASTER_CLIP) {
//TODO
emit changeEffectPosition(m_masterclipref->clipId(), indexes, endPos);
}
}
......@@ -1086,7 +1086,7 @@ void EffectStackView2::slotMoveEffect(QList <int> currentIndexes, int newIndex,
} else if (m_status == TIMELINE_CLIP) {
emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex(),false);
} else if (m_status == MASTER_CLIP) {
//TODO
//emit updateEffect(m_masterclipref, oldeffect, neweffect, effectToMove->effectIndex(),false);
}
}
}
......
......@@ -269,6 +269,8 @@ signals:
void changeEffectState(ClipItem*, int, const QList <int>&, bool);
/** An effect in stack was moved */
void changeEffectPosition(ClipItem*, int, const QList <int>&, int);
/** An effect in stack was moved for a Bin clip */
void changeEffectPosition(const QString &, const QList <int>&, int);
/** an effect was saved, reload list */
void reloadEffects();
/** An effect with position parameter was changed, seek */
......
......@@ -298,9 +298,9 @@ MainWindow::MainWindow(const QString &MltPath, const QUrl &Url, const QString &
connect(pCore->bin(), SIGNAL(masterClipUpdated(ClipController *, Monitor *)), m_effectStack, SLOT(slotRefreshMasterClipEffects(ClipController *, Monitor *)));
connect(m_effectStack, SIGNAL(addMasterEffect(QString,QDomElement)), pCore->bin(), SLOT(slotEffectDropped(QString,QDomElement)));
connect(m_effectStack, SIGNAL(removeMasterEffect(QString,QDomElement)), pCore->bin(), SLOT(slotDeleteEffect(QString,QDomElement)));
connect(m_effectStack, SIGNAL(changeEffectPosition(QString,const QList <int>,int)), pCore->bin(), SLOT(slotMoveEffect(QString,const QList <int>,int)));
connect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
connect(m_effectStack, SIGNAL(displayMessage(QString,int)), this, SLOT(slotGotProgressInfo(QString,int)));
m_effectStackDock = addDock(i18n("Properties"), QStringLiteral("effect_stack"), m_effectStack);
m_effectList = new EffectsListView();
......
......@@ -656,6 +656,33 @@ EffectsList ClipController::effectList()
return xmlEffectList(m_masterProducer->profile(), m_masterProducer->parent());
}
void ClipController::moveEffect(int oldPos, int newPos)
{
QMutexLocker lock(&m_effectMutex);
Mlt::Service service(m_masterProducer->parent());
EffectManager effect(service);
effect.moveEffect(oldPos, newPos);
}
void ClipController::reloadTrackProducers()
{
m_binController->updateTrackProducer(clipId());
}
int ClipController::effectsCount()
{
int count = 0;
Mlt::Service service(m_masterProducer->parent());
for (int ix = 0; ix < service.filter_count(); ++ix) {
Mlt::Filter *effect = service.filter(ix);
QString id = effect->get("kdenlive_id");
if (!id.isEmpty()) {
count++;
}
}
return count;
}
// static
EffectsList ClipController::xmlEffectList(Mlt::Profile *profile, Mlt::Service &service)
{
......
......@@ -187,6 +187,12 @@ public:
void disableEffects(bool disable);
/** @brief Create a Kdenlive EffectList xml data from an MLT service */
static EffectsList xmlEffectList(Mlt::Profile *profile, Mlt::Service &service);
/** @brief Returns the number of Kdenlive added effects for this bin clip */
int effectsCount();
/** @brief Move an effect in stack for this bin clip */
void moveEffect(int oldPos, int newPos);
/** @brief Request an update of all track producers */
void reloadTrackProducers();
private:
Mlt::Producer *m_masterProducer;
......
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