Allow moving effects in the stack with up/down buttons

parent 68a4d4c1
......@@ -102,6 +102,34 @@ void TreeItem::appendChild(std::shared_ptr<TreeItem> child)
}
}
void TreeItem::moveChild(int ix, std::shared_ptr<TreeItem> child)
{
if (auto ptr = m_model.lock()) {
auto childPtr = child->m_parentItem.lock();
if (childPtr && childPtr->getId() == m_id) {
childPtr->removeChild(child);
} else {
// deletion of child
auto it = m_iteratorTable[child->getId()];
m_childItems.erase(it);
}
ptr->notifyRowAboutToAppend(shared_from_this());
child->m_depth = m_depth + 1;
child->m_parentItem = shared_from_this();
qDebug() << "appending child2" << child->getId() << "to " << m_id;
int id = child->getId();
auto pos = m_childItems.cbegin();
std::advance(pos, ix);
auto it = m_childItems.insert(pos, child);
m_iteratorTable[id] = it;
ptr->notifyRowAppended(child);
m_isInModel = true;
} else {
qDebug() << "ERROR: Something went wrong when inserting child in TreeItem. Model is not available anymore";
Q_ASSERT(false);
}
}
void TreeItem::removeChild(const std::shared_ptr<TreeItem> &child)
{
if (auto ptr = m_model.lock()) {
......
......@@ -62,6 +62,7 @@ public:
Useful for example if the child should be a subclass of TreeItem
*/
void appendChild(std::shared_ptr<TreeItem> child);
void moveChild(int ix, std::shared_ptr<TreeItem> child);
/* @brief Remove given child from children list. The parent of the child is updated
accordingly
......
......@@ -63,6 +63,26 @@ void EffectStackModel::appendEffect(const QString &effectId, int cid)
pCore->pushUndo(undo, redo, i18n("Add effect %1", effectName));
}
void EffectStackModel::moveEffect(int destRow, std::shared_ptr<EffectItemModel> effect)
{
QModelIndex ix = getIndexFromItem(effect);
int currentRow = effect->row();
//effect->unplant(m_service);
rootItem->moveChild(destRow, effect);
QList < std::shared_ptr<EffectItemModel> > effects;
for (int i = destRow; i < rootItem->childCount(); i++) {
auto eff = getEffect(i);
eff->unplant(m_service);
effects << eff;
}
for (int i = 0; i < effects.count(); i++) {
auto eff = effects.at(i);
eff->plant(m_service);
}
pCore->refreshProjectItem(effect->getParentId());
emit dataChanged(ix, ix, QVector<int>());
}
Fun EffectStackModel::deleteEffect_lambda(std::shared_ptr<EffectItemModel> effect, int cid, bool isAudio)
{
QWriteLocker locker(&m_lock);
......@@ -106,7 +126,7 @@ void EffectStackModel::setEffectStackEnabled(bool enabled)
}
}
std::shared_ptr<EffectItemModel> EffectStackModel::effect(int row)
std::shared_ptr<EffectItemModel> EffectStackModel::getEffect(int row)
{
return std::static_pointer_cast<EffectItemModel>(rootItem->child(row));
}
......@@ -115,7 +135,7 @@ void EffectStackModel::importEffects(int cid, std::shared_ptr<EffectStackModel>s
{
//TODO: manage fades, keyframes if clips don't have same size / in point
for (int i = 0; i < sourceStack->rowCount(); i++) {
std::shared_ptr<EffectItemModel> effect = sourceStack->effect(i);
std::shared_ptr<EffectItemModel> effect = sourceStack->getEffect(i);
auto clone = EffectItemModel::construct(effect->getAssetId(), shared_from_this(), rootItem);
clone->setParameters(effect->getAllParameters());
Fun redo = addEffect_lambda(clone, cid, true);
......
......@@ -59,7 +59,10 @@ public:
void setEffectStackEnabled(bool enabled);
/* @brief Returns an effect from the stack (at the given row) */
std::shared_ptr<EffectItemModel> effect(int row);
std::shared_ptr<EffectItemModel> getEffect(int row);
/* @brief Move an effect in the stack */
void moveEffect(int destRow, std::shared_ptr<EffectItemModel> effect);
public slots:
/* @brief Delete an effect from the stack */
......
......@@ -342,12 +342,12 @@ void CollapsibleEffectView::slotDeleteEffect()
void CollapsibleEffectView::slotEffectUp()
{
emit changeEffectPosition(QList<int>() << effectIndex(), true);
emit moveEffect(qMax(0, m_model->row() -1), m_model);
}
void CollapsibleEffectView::slotEffectDown()
{
emit changeEffectPosition(QList<int>() << effectIndex(), false);
emit moveEffect(m_model->row() + 1, m_model);
}
void CollapsibleEffectView::slotSaveEffect()
......@@ -701,7 +701,7 @@ void CollapsibleEffectView::dropEvent(QDropEvent *event)
QDomElement effect = subeffects.at(i).toElement();
effectsIds << effect.attribute(QStringLiteral("kdenlive_ix")).toInt();
}
emit moveEffect(effectsIds, currentEffectIx, info.groupIndex, info.groupName);
//emit moveEffect(effectsIds, currentEffectIx, info.groupIndex, info.groupName);
} else {
// group effect dropped from effect list
if (m_info.groupIndex > -1) {
......@@ -722,7 +722,7 @@ void CollapsibleEffectView::dropEvent(QDropEvent *event)
emit addEffect(e);
return;
}
emit moveEffect(QList<int>() << ix, currentEffectIx, m_info.groupIndex, m_info.groupName);
//emit moveEffect(QList<int>() << ix, currentEffectIx, m_info.groupIndex, m_info.groupName);
event->setDropAction(Qt::MoveAction);
event->accept();
}
......
......@@ -150,6 +150,7 @@ signals:
void syncEffectsPos(int);
void effectStateChanged(bool, int ix, MonitorSceneType effectNeedsMonitorScene);
void deleteEffect(std::shared_ptr<EffectItemModel> effect);
void moveEffect(int destRow, std::shared_ptr<EffectItemModel> effect);
void activateEffect(int);
void checkMonitorPosition(int);
void seekTimeline(int);
......
......@@ -69,11 +69,12 @@ void EffectStackView::setModel(std::shared_ptr<EffectStackModel>model)
m_model = model;
int max = m_model->rowCount();
for (int i = 0; i < max; i++) {
std::shared_ptr<EffectItemModel> effectModel = m_model->effect(i);
std::shared_ptr<EffectItemModel> effectModel = m_model->getEffect(i);
QSize size;
QImage effectIcon = m_thumbnailer->requestImage(effectModel->getAssetId(), &size, QSize(QStyle::PM_SmallIconSize,QStyle::PM_SmallIconSize));
CollapsibleEffectView *view = new CollapsibleEffectView(effectModel, effectIcon, this);
connect(view, &CollapsibleEffectView::deleteEffect, m_model.get(), &EffectStackModel::removeEffect);
connect(view, &CollapsibleEffectView::moveEffect, m_model.get(), &EffectStackModel::moveEffect);
m_lay->addWidget(view);
m_widgets.push_back(view);
}
......@@ -86,11 +87,12 @@ void EffectStackView::refresh(const QModelIndex &topLeft, const QModelIndex &bot
unsetModel(false);
int max = m_model->rowCount();
for (int i = 0; i < max; i++) {
std::shared_ptr<EffectItemModel> effectModel = m_model->effect(i);
std::shared_ptr<EffectItemModel> effectModel = m_model->getEffect(i);
QSize size;
QImage effectIcon = m_thumbnailer->requestImage(effectModel->getAssetId(), &size, QSize(QStyle::PM_SmallIconSize,QStyle::PM_SmallIconSize));
CollapsibleEffectView *view = new CollapsibleEffectView(effectModel, effectIcon, this);
connect(view, &CollapsibleEffectView::deleteEffect, m_model.get(), &EffectStackModel::removeEffect);
connect(view, &CollapsibleEffectView::moveEffect, m_model.get(), &EffectStackModel::moveEffect);
m_lay->addWidget(view);
m_widgets.push_back(view);
}
......
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