Pasting effect applies to all selected clips

parent aaf88243
Pipeline #1585 passed with stage
in 24 minutes and 21 seconds
......@@ -229,9 +229,18 @@ QDomElement EffectStackModel::toXml(QDomDocument &document)
bool EffectStackModel::fromXml(const QDomElement &effectsXml, Fun &undo, Fun &redo)
{
QDomNodeList nodeList = effectsXml.elementsByTagName(QStringLiteral("effect"));
PlaylistState::ClipState state = pCore->getItemState(m_ownerId);
for (int i = 0; i < nodeList.count(); ++i) {
QDomElement node = nodeList.item(i).toElement();
const QString effectId = node.attribute(QStringLiteral("id"));
bool isAudioEffect = EffectsRepository::get()->getType(effectId) == EffectType::Audio;
if (isAudioEffect) {
if (state != PlaylistState::AudioOnly) {
continue;
}
} else if (state != PlaylistState::VideoOnly) {
continue;
}
auto effect = EffectItemModel::construct(effectId, shared_from_this());
int in = node.attribute(QStringLiteral("in")).toInt();
int out = node.attribute(QStringLiteral("out")).toInt();
......
......@@ -179,10 +179,12 @@ Item {
}
}
onPositionChanged: {
var mapped = parentTrack.mapFromItem(compositionRoot, mouse.x, mouse.y).x
root.mousePosChanged(Math.round(mapped / timeline.scaleFactor))
if (mouse.modifiers & Qt.ShiftModifier) {
timeline.position = Math.round(mapped / timeline.scaleFactor)
if (parentTrack) {
var mapped = parentTrack.mapFromItem(compositionRoot, mouse.x, mouse.y).x
root.mousePosChanged(Math.round(mapped / timeline.scaleFactor))
if (mouse.modifiers & Qt.ShiftModifier) {
timeline.position = Math.round(mapped / timeline.scaleFactor)
}
}
}
onWheel: zoomByWheel(wheel)
......
......@@ -1609,12 +1609,46 @@ void TimelineController::selectCurrentTrack()
void TimelineController::pasteEffects(int targetId)
{
if (targetId == -1 && !m_model->getCurrentSelection().empty()) {
targetId = *m_model->getCurrentSelection().begin();
std::unordered_set<int> targetIds;
if (targetId == -1) {
std::unordered_set<int> sel = m_model->getCurrentSelection();
if (sel.empty()) {
pCore->displayMessage(i18n("No clip selected"), InformationMessage, 500);
}
for (int s : sel) {
if (m_model->isGroup(s)) {
std::unordered_set<int> sub = m_model->m_groups->getLeaves(s);
for (int current_id : sub) {
if (m_model->isClip(current_id)) {
targetIds.insert(current_id);
}
}
} else if (m_model->isClip(s)) {
targetIds.insert(s);
}
}
} else {
if (m_model->m_groups->isInGroup(targetId)) {
targetId = m_model->m_groups->getRootId(targetId);
}
if (m_model->isGroup(targetId)) {
std::unordered_set<int> sub = m_model->m_groups->getLeaves(targetId);
for (int current_id : sub) {
if (m_model->isClip(current_id)) {
targetIds.insert(current_id);
}
}
} else if (m_model->isClip(targetId)) {
targetIds.insert(targetId);
}
}
if (targetIds.empty()) {
pCore->displayMessage(i18n("No clip selected"), InformationMessage, 500);
}
QClipboard *clipboard = QApplication::clipboard();
QString txt = clipboard->text();
if (!m_model->isClip(targetId) || txt.isEmpty()) {
if (txt.isEmpty()) {
pCore->displayMessage(i18n("No information in clipboard"), InformationMessage, 500);
return;
}
......@@ -1624,16 +1658,28 @@ void TimelineController::pasteEffects(int targetId)
pCore->displayMessage(i18n("No information in clipboard"), InformationMessage, 500);
return;
}
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
std::shared_ptr<EffectStackModel> destStack = m_model->getClipEffectStackModel(targetId);
QDomNodeList clips = copiedItems.documentElement().elementsByTagName(QStringLiteral("clip"));
if (clips.isEmpty()) {
pCore->displayMessage(i18n("No information in clipboard"), InformationMessage, 500);
return;
}
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
QDomElement effects = clips.at(0).firstChildElement(QStringLiteral("effects"));
bool result = destStack->fromXml(effects, undo, redo);
for (int i = 1; i < clips.size(); i++) {
QDomNodeList subs = clips.at(i).childNodes();
for (int j = 0; j < subs.size(); j++) {
effects.appendChild(subs.at(j));
}
}
bool result = true;
for (int target : targetIds) {
std::shared_ptr<EffectStackModel> destStack = m_model->getClipEffectStackModel(target);
result = result && destStack->fromXml(effects, undo, redo);
if (!result) {
break;
}
}
if (result) {
pCore->pushUndo(undo, redo, i18n("Paste effects"));
} else {
......
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