+void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo oldInfo, int pos, bool check, QUndoCommand *command)
+{
+ if (pos == oldInfo.startPos.frames(m_document->fps()))
+ return;
+ bool snap = KdenliveSettings::snaptopoints();
+ if (check) {
+ KdenliveSettings::setSnaptopoints(false);
+ item->resizeStart(pos);
+ if (item->startPos().frames(m_document->fps()) != pos) {
+ item->resizeStart(oldInfo.startPos.frames(m_document->fps()));
+ emit displayMessage(i18n("Not possible to resize"), ErrorMessage);
+ KdenliveSettings::setSnaptopoints(snap);
+ return;
+ }
+ KdenliveSettings::setSnaptopoints(snap);
+ }
+
+ bool hasParentCommand = false;
+ if (command) {
+ hasParentCommand = true;
+ } else {
+ command = new QUndoCommand();
+ command->setText(i18n("Resize clip start"));
+ }
+
+ // do this here, too, because otherwise undo won't update the group
+ if (item->parentItem() && item->parentItem() != m_selectionGroup)
+ new RebuildGroupCommand(this, item->info().track, item->endPos() - GenTime(1, m_document->fps()), command);
+
+ ItemInfo info = item->info();
+ if (item->type() == AVWIDGET) {
+ ItemInfo resizeinfo = oldInfo;
+ resizeinfo.track = m_document->tracksCount() - resizeinfo.track;
+ bool success = m_document->renderer()->mltResizeClipStart(resizeinfo, item->startPos() - oldInfo.startPos);
+ if (success) {
+ // Check if there is an automatic transition on that clip (lower track)
+ Transition *transition = getTransitionItemAtStart(oldInfo.startPos, oldInfo.track);
+ if (transition && transition->isAutomatic()) {
+ ItemInfo trInfo = transition->info();
+ ItemInfo newTrInfo = trInfo;
+ newTrInfo.startPos = item->startPos();
+ if (newTrInfo.startPos < newTrInfo.endPos)
+ new MoveTransitionCommand(this, trInfo, newTrInfo, true, command);
+ }
+ // Check if there is an automatic transition on that clip (upper track)
+ transition = getTransitionItemAtStart(oldInfo.startPos, oldInfo.track - 1);
+ if (transition && transition->isAutomatic() && (m_document->tracksCount() - transition->transitionEndTrack()) == oldInfo.track) {
+ ItemInfo trInfo = transition->info();
+ ItemInfo newTrInfo = trInfo;
+ newTrInfo.startPos = item->startPos();
+ ClipItem * upperClip = getClipItemAt(oldInfo.startPos, oldInfo.track - 1);
+ if ((!upperClip || !upperClip->baseClip()->isTransparent()) && newTrInfo.startPos < newTrInfo.endPos)
+ new MoveTransitionCommand(this, trInfo, newTrInfo, true, command);
+ }
+
+ ClipItem *clip = static_cast < ClipItem * >(item);
+ updatePositionEffects(clip, oldInfo);
+
+ // check keyframes
+ QDomDocument doc;
+ QDomElement root = doc.createElement("list");
+ doc.appendChild(root);
+ QList <int> indexes;
+ for (int i = 0; i < clip->effectsCount(); i++) {
+ QDomElement effect = clip->effectAt(i);
+ if (EffectsList::hasKeyFrames(effect)) {
+ doc.appendChild(doc.importNode(effect, true));
+ indexes.append(i);
+ }
+ }
+
+ if (clip->checkEffectsKeyframesPos(oldInfo.cropStart.frames(m_document->fps()), clip->cropStart().frames(m_document->fps()), true)) {
+ // Keyframes were modified, updateClip
+ QDomNodeList effs = doc.elementsByTagName("effect");
+ // Hack:
+ // Since we must always resize clip before updating the keyframes, we
+ // put a resize command before & after checking keyframes so that
+ // we are sure the resize is performed before whenever we do or undo the action
+
+ new ResizeClipCommand(this, oldInfo, info, false, true, command);
+ for (int i = 0; i < indexes.count(); i++) {
+ new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effs.at(i).cloneNode().toElement(), clip->effectAt(indexes.at(i)), indexes.at(i), false, command);
+ updateEffect(m_document->tracksCount() - clip->track(), clip->startPos(), clip->effectAt(indexes.at(i)), indexes.at(i));
+ }
+ new ResizeClipCommand(this, oldInfo, info, false, true, command);
+ emit clipItemSelected(clip);
+ } else {
+ new ResizeClipCommand(this, oldInfo, info, false, false, command);
+ }
+ } else {
+ KdenliveSettings::setSnaptopoints(false);
+ item->resizeStart((int) oldInfo.startPos.frames(m_document->fps()));
+ KdenliveSettings::setSnaptopoints(snap);
+ emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
+ }
+ } else if (item->type() == TRANSITIONWIDGET) {
+ Transition *transition = static_cast <Transition *>(item);
+ if (!m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_document->tracksCount() - oldInfo.track), (int)(m_document->tracksCount() - oldInfo.track), transition->transitionEndTrack(), oldInfo.startPos, oldInfo.endPos, info.startPos, info.endPos)) {
+ // Cannot resize transition
+ KdenliveSettings::setSnaptopoints(false);
+ transition->resizeStart((int) oldInfo.startPos.frames(m_document->fps()));
+ KdenliveSettings::setSnaptopoints(snap);
+ emit displayMessage(i18n("Cannot resize transition"), ErrorMessage);
+ } else {
+ MoveTransitionCommand *moveCommand = new MoveTransitionCommand(this, oldInfo, info, false, command);
+ if (command == NULL)
+ m_commandStack->push(moveCommand);
+ }
+
+ }
+ if (item->parentItem() && item->parentItem() != m_selectionGroup)
+ new RebuildGroupCommand(this, item->info().track, item->endPos() - GenTime(1, m_document->fps()), command);
+
+ if (!hasParentCommand)
+ m_commandStack->push(command);
+}
+
+void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldInfo, int pos, bool check, QUndoCommand *command)
+{
+ if (pos == oldInfo.endPos.frames(m_document->fps()))
+ return;
+ bool snap = KdenliveSettings::snaptopoints();
+ if (check) {
+ KdenliveSettings::setSnaptopoints(false);
+ item->resizeEnd(pos);
+ if (item->endPos().frames(m_document->fps()) != pos) {
+ item->resizeEnd(oldInfo.endPos.frames(m_document->fps()));
+ emit displayMessage(i18n("Not possible to resize"), ErrorMessage);
+ KdenliveSettings::setSnaptopoints(snap);
+ return;
+ }
+ KdenliveSettings::setSnaptopoints(snap);
+ }
+
+ bool hasParentCommand = false;
+ if (command) {
+ hasParentCommand = true;
+ } else {
+ command = new QUndoCommand();
+ command->setText(i18n("Resize clip end"));
+ }
+
+ // do this here, too, because otherwise undo won't update the group
+ if (item->parentItem() && item->parentItem() != m_selectionGroup)
+ new RebuildGroupCommand(this, item->info().track, item->startPos(), command);
+
+ ItemInfo info = item->info();
+ if (item->type() == AVWIDGET) {
+ ItemInfo resizeinfo = info;
+ resizeinfo.track = m_document->tracksCount() - resizeinfo.track;
+ bool success = m_document->renderer()->mltResizeClipEnd(resizeinfo, resizeinfo.endPos - resizeinfo.startPos);
+ if (success) {
+ // Check if there is an automatic transition on that clip (lower track)
+ Transition *tr = getTransitionItemAtEnd(oldInfo.endPos, oldInfo.track);
+ if (tr && tr->isAutomatic()) {
+ ItemInfo trInfo = tr->info();
+ ItemInfo newTrInfo = trInfo;
+ newTrInfo.endPos = item->endPos();
+ if (newTrInfo.endPos > newTrInfo.startPos)
+ new MoveTransitionCommand(this, trInfo, newTrInfo, true, command);
+ }
+
+ // Check if there is an automatic transition on that clip (upper track)
+ tr = getTransitionItemAtEnd(oldInfo.endPos, oldInfo.track - 1);
+ if (tr && tr->isAutomatic() && (m_document->tracksCount() - tr->transitionEndTrack()) == oldInfo.track) {
+ ItemInfo trInfo = tr->info();
+ ItemInfo newTrInfo = trInfo;
+ newTrInfo.endPos = item->endPos();
+ ClipItem * upperClip = getClipItemAtEnd(oldInfo.endPos, oldInfo.track - 1);
+ if ((!upperClip || !upperClip->baseClip()->isTransparent()) && newTrInfo.endPos > newTrInfo.startPos)
+ new MoveTransitionCommand(this, trInfo, newTrInfo, true, command);
+
+ }
+
+ // check keyframes
+ ClipItem *clip = static_cast < ClipItem * >(item);
+ QDomDocument doc;
+ QDomElement root = doc.createElement("list");
+ doc.appendChild(root);
+ QList <int> indexes;
+ for (int i = 0; i < clip->effectsCount(); i++) {
+ QDomElement effect = clip->effectAt(i);
+ if (EffectsList::hasKeyFrames(effect)) {
+ doc.appendChild(doc.importNode(effect, true));
+ indexes.append(i);
+ }
+ }
+
+ if (clip->checkEffectsKeyframesPos((oldInfo.cropStart + oldInfo.endPos - oldInfo.startPos).frames(m_document->fps()) - 1, (clip->cropStart() + clip->cropDuration()).frames(m_document->fps()) - 1, false)) {
+ // Keyframes were modified, updateClip
+ QDomNodeList effs = doc.elementsByTagName("effect");
+ // Hack:
+ // Since we must always resize clip before updating the keyframes, we
+ // put a resize command before & after checking keyframes so that
+ // we are sure the resize is performed before whenever we do or undo the action
+
+ new ResizeClipCommand(this, oldInfo, info, false, true, command);
+ for (int i = 0; i < indexes.count(); i++) {
+ new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effs.at(i).cloneNode().toElement(), clip->effectAt(indexes.at(i)), indexes.at(i), false, command);
+ updateEffect(m_document->tracksCount() - clip->track(), clip->startPos(), clip->effectAt(indexes.at(i)), indexes.at(i));
+ }
+ new ResizeClipCommand(this, oldInfo, info, false, true, command);
+ emit clipItemSelected(clip);
+ } else {
+ new ResizeClipCommand(this, oldInfo, info, false, false, command);
+ }
+
+ updatePositionEffects(clip, oldInfo);
+ } else {
+ KdenliveSettings::setSnaptopoints(false);
+ item->resizeEnd((int) oldInfo.endPos.frames(m_document->fps()));
+ KdenliveSettings::setSnaptopoints(true);
+ emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
+ }
+ } else if (item->type() == TRANSITIONWIDGET) {
+ Transition *transition = static_cast <Transition *>(item);
+ if (!m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_document->tracksCount() - oldInfo.track), (int)(m_document->tracksCount() - oldInfo.track), transition->transitionEndTrack(), oldInfo.startPos, oldInfo.endPos, info.startPos, info.endPos)) {
+ // Cannot resize transition
+ KdenliveSettings::setSnaptopoints(false);
+ transition->resizeEnd((int) oldInfo.endPos.frames(m_document->fps()));
+ KdenliveSettings::setSnaptopoints(true);
+ emit displayMessage(i18n("Cannot resize transition"), ErrorMessage);
+ } else {
+ MoveTransitionCommand *moveCommand = new MoveTransitionCommand(this, oldInfo, info, false, command);
+ if (command == NULL)
+ m_commandStack->push(moveCommand);
+ }
+ }
+ if (item->parentItem() && item->parentItem() != m_selectionGroup)
+ new RebuildGroupCommand(this, item->info().track, item->startPos(), command);
+
+ if (!hasParentCommand)
+ m_commandStack->push(command);
+}
+