]> git.sesse.net Git - kdenlive/commitdiff
Fix move effects up and down in stack
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 11 May 2008 16:24:34 +0000 (16:24 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 11 May 2008 16:24:34 +0000 (16:24 +0000)
svn path=/branches/KDE4/; revision=2180

src/CMakeLists.txt
src/customtrackview.cpp
src/customtrackview.h
src/effectstackview.cpp
src/effectstackview.h
src/mainwindow.cpp
src/moveeffectcommand.cpp [new file with mode: 0644]
src/moveeffectcommand.h [new file with mode: 0644]
src/renderer.cpp
src/renderer.h

index c08a1d864bdf4784146a785aac8885f93dc9d1fc..67a74c307ccd07c322513d506f95794a48a991f3 100644 (file)
@@ -81,6 +81,7 @@ set(kdenlive_SRCS
   effectslistview.cpp
   addeffectcommand.cpp
   editeffectcommand.cpp
+  moveeffectcommand.cpp
   effectstackview.cpp
   effectstackedit.cpp
   parameterplotter.cpp
index c02ed596281d26c1a8ddb671408fd3220bfb7e9d..42df48663bd87411f02e8d5d1ec8dbb7a89b62fa 100644 (file)
@@ -40,6 +40,7 @@
 #include "addtimelineclipcommand.h"
 #include "addeffectcommand.h"
 #include "editeffectcommand.h"
+#include "moveeffectcommand.h"
 #include "addtransitioncommand.h"
 #include "edittransitioncommand.h"
 #include "razorclipcommand.h"
@@ -555,14 +556,22 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement effect) {
     ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_tracksList.count() - track);
     if (clip) {
         QMap <QString, QString> effectParams = clip->getEffectArgs(effect);
-        if (effectParams["disabled"] == "1") {
-            QString index = effectParams["kdenlive_ix"];
+        if (effectParams.value("disabled") == "1") {
+            QString index = effectParams.value("kdenlive_ix");
             m_document->renderer()->mltRemoveEffect(track, pos, index);
         } else m_document->renderer()->mltEditEffect(m_tracksList.count() - clip->track(), clip->startPos(), effectParams);
     }
     m_document->setModified(true);
 }
 
+void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos) {
+    ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_tracksList.count() - track);
+    if (clip) {
+        m_document->renderer()->mltMoveEffect(track, pos, oldPos, newPos);
+    }
+    m_document->setModified(true);
+}
+
 void CustomTrackView::slotChangeEffectState(ClipItem *clip, QDomElement effect, bool disable) {
     QDomElement oldEffect = effect.cloneNode().toElement();
     effect.setAttribute("disabled", disable);
@@ -571,6 +580,12 @@ void CustomTrackView::slotChangeEffectState(ClipItem *clip, QDomElement effect,
     m_document->setModified(true);
 }
 
+void CustomTrackView::slotChangeEffectPosition(ClipItem *clip, int currentPos, int newPos) {
+    MoveEffectCommand *command = new MoveEffectCommand(this, m_tracksList.count() - clip->track(), clip->startPos(), currentPos, newPos, true);
+    m_commandStack->push(command);
+    m_document->setModified(true);
+}
+
 void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect) {
     EditEffectCommand *command = new EditEffectCommand(this, m_tracksList.count() - clip->track(), clip->startPos(), oldeffect, effect, true);
     m_commandStack->push(command);
index 6d21ade0278e9e7985434215d12abbb7b0b73cdf..fec0f391f145e190e6ab9cd09cc8fff0bb297aef 100644 (file)
@@ -58,6 +58,7 @@ public:
     void addEffect(int track, GenTime pos, QDomElement effect);
     void deleteEffect(int track, GenTime pos, QDomElement effect);
     void updateEffect(int track, GenTime pos, QDomElement effect);
+    void moveEffect(int track, GenTime pos, int oldPos, int newPos);
     void addTransition(ItemInfo transitionInfo, int endTrack, QDomElement params);
     void deleteTransition(ItemInfo transitionInfo, int endTrack, QDomElement params);
     void updateTransition(int track, GenTime pos,  QDomElement oldTransition, QDomElement transition);
@@ -80,6 +81,7 @@ public slots:
     void updateCursorPos();
     void slotDeleteEffect(ClipItem *clip, QDomElement effect);
     void slotChangeEffectState(ClipItem *clip, QDomElement effect, bool disable);
+    void slotChangeEffectPosition(ClipItem *clip, int currentPos, int newPos);
     void slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect);
     void slotRefreshEffects(ClipItem *clip);
     void setDuration(int duration);
index 2732bc39cfb4d2bd784f1072375fcca8510021c7..d7ad6f69b90360d38cf7546d79d82ea7e2063586 100644 (file)
@@ -134,7 +134,7 @@ void EffectStackView::slotItemUp() {
     QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
     ui.effectlist->insertItem(activeRow - 1, item);
     ui.effectlist->setCurrentItem(item);
-    emit refreshEffectStack(clipref);
+    emit changeEffectPosition(clipref, activeRow + 1, activeRow);
 }
 
 void EffectStackView::slotItemDown() {
@@ -148,7 +148,7 @@ void EffectStackView::slotItemDown() {
     QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
     ui.effectlist->insertItem(activeRow + 1, item);
     ui.effectlist->setCurrentItem(item);
-    emit refreshEffectStack(clipref);
+    emit changeEffectPosition(clipref, activeRow + 1, activeRow + 2);
 }
 
 void EffectStackView::slotItemDel() {
index 72c10d8dad829dbf7a515a5e00be7212e2ed7418..499044b0ff9736db546dd1992f3778d217227a21 100644 (file)
@@ -60,6 +60,8 @@ signals:
     void refreshEffectStack(ClipItem *);
     /** Enable or disable an effect */
     void changeEffectState(ClipItem*, QDomElement, bool);
+    /** An effect in stack was moved */
+    void changeEffectPosition(ClipItem*, int, int);
 
 };
 
index 750920c9e12948666252eec561f91e24ced8c417..f681576cc1fc48aeb7935c1a2b877c7a209b140e 100644 (file)
@@ -778,6 +778,7 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha
             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
             disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
+           disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
             disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
             disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
@@ -816,6 +817,7 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha
     connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
     connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
     connect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
+    connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
     connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
     connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
diff --git a/src/moveeffectcommand.cpp b/src/moveeffectcommand.cpp
new file mode 100644 (file)
index 0000000..0f7f03c
--- /dev/null
@@ -0,0 +1,61 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+#include <KLocale>
+
+#include "moveeffectcommand.h"
+#include "customtrackview.h"
+
+MoveEffectCommand::MoveEffectCommand(CustomTrackView *view, const int track, GenTime pos, int oldPos, int newPos, bool doIt)
+        : m_view(view), m_track(track), m_pos(pos), m_oldindex(oldPos), m_newindex(newPos), m_doIt(doIt) {
+/*    QString effectName;
+    QDomNode namenode = effect.elementsByTagName("name").item(0);
+    if (!namenode.isNull()) effectName = i18n(namenode.toElement().text().toUtf8().data());
+    else effectName = i18n("effect");
+    setText(i18n("Move effect %1", effectName));*/
+    setText(i18n("Move effect"));
+}
+
+// virtual
+int MoveEffectCommand::id() const {
+    return 2;
+}
+
+// virtual
+bool MoveEffectCommand::mergeWith(const QUndoCommand * other) {
+    if (other->id() != id()) return false;
+    if (m_track != static_cast<const MoveEffectCommand*>(other)->m_track) return false;
+    if (m_pos != static_cast<const MoveEffectCommand*>(other)->m_pos) return false;
+    m_oldindex = static_cast<const MoveEffectCommand*>(other)->m_oldindex;
+    m_newindex = static_cast<const MoveEffectCommand*>(other)->m_newindex;
+    return true;
+}
+
+// virtual
+void MoveEffectCommand::undo() {
+    kDebug() << "----  undoing action";
+    m_view->moveEffect(m_track, m_pos, m_newindex, m_oldindex);
+}
+// virtual
+void MoveEffectCommand::redo() {
+    kDebug() << "----  redoing action";
+    m_view->moveEffect(m_track, m_pos, m_oldindex, m_newindex);
+}
+
+#include "moveeffectcommand.moc"
diff --git a/src/moveeffectcommand.h b/src/moveeffectcommand.h
new file mode 100644 (file)
index 0000000..e6f1802
--- /dev/null
@@ -0,0 +1,50 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+
+#ifndef MOVEEFFECTCOMMAND_H
+#define MOVEEFFECTCOMMAND_H
+
+#include <QUndoCommand>
+#include <KDebug>
+#include <gentime.h>
+#include <QDomElement>
+
+class CustomTrackView;
+
+class MoveEffectCommand : public QUndoCommand {
+public:
+    MoveEffectCommand(CustomTrackView *view, const int track, GenTime pos, int oldPos, int newPos, bool doIt);
+
+    virtual int id() const;
+    virtual bool mergeWith(const QUndoCommand * command);
+    virtual void undo();
+    virtual void redo();
+
+private:
+    CustomTrackView *m_view;
+    int m_track;
+    int m_oldindex;
+    int m_newindex;
+    GenTime m_pos;
+    bool m_doIt;
+};
+
+#endif
+
index 9cf86c867096f7e2e9aca23a8efaf3ae5b1954b5..8d370c240cf9d810c81ac13dd90634d9870d9926 100644 (file)
@@ -1182,13 +1182,14 @@ void Render::mltEditEffect(int track, GenTime position, QMap <QString, QString>
        filter = clipService.filter(ct);
        QList <Mlt::Filter *> filtersList;
        while (filter) {
-           if (filter->get("kdenlive_ix") > index) {
+           if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
                filtersList.append(filter);
                clipService.detach(*filter);
            } else ct++;
            filter = clipService.filter(ct);
        }
         mltAddEffect(track, position, args);
+
        for (int i = 0; i < filtersList.count(); i++) {
            clipService.attach(*(filtersList.at(i)));
        }
@@ -1209,6 +1210,78 @@ void Render::mltEditEffect(int track, GenTime position, QMap <QString, QString>
     refresh();
 }
 
+void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
+
+    kDebug() << "MOVING EFFECT FROM " << oldPos<< ", TO: " << newPos;
+    Mlt::Service service(m_mltProducer->parent().get_service());
+
+    Mlt::Tractor tractor(service);
+    Mlt::Producer trackProducer(tractor.track(track));
+    Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
+    //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
+    Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
+    if (!clip) {
+        kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
+        return;
+    }
+    Mlt::Service clipService(clip->get_service());
+    m_isBlocked = true;
+    int ct = 0;
+    QList <Mlt::Filter *> filtersList;
+    Mlt::Filter *filter = clipService.filter(ct);
+    bool found = false;
+    if (newPos > oldPos) {
+       while (filter) {
+           if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
+               filter->set("kdenlive_ix", newPos);
+               filtersList.append(filter);
+               clipService.detach(*filter);
+               filter = clipService.filter(ct);
+               while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
+                   filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
+                   ct++;
+                   filter = clipService.filter(ct);
+               }
+               found = true;
+           }
+           if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
+               filtersList.append(filter);
+               clipService.detach(*filter);
+           } else ct++;
+           filter = clipService.filter(ct);
+       }
+    }
+    else {
+       while (filter) {
+           if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
+               filter->set("kdenlive_ix", newPos);
+               filtersList.append(filter);
+               clipService.detach(*filter);
+           } else ct++;
+           filter = clipService.filter(ct);
+       }
+
+       ct = 0;
+       filter = clipService.filter(ct);
+       while (filter) {
+           int pos = QString(filter->get("kdenlive_ix")).toInt();
+           if (pos >= newPos) {
+               if (pos < oldPos) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() + 1);
+               filtersList.append(filter);
+               clipService.detach(*filter);
+           } else ct++;
+           filter = clipService.filter(ct);
+       }
+    }
+    
+    for (int i = 0; i < filtersList.count(); i++) {
+       clipService.attach(*(filtersList.at(i)));
+    }
+
+    m_isBlocked = false;
+    refresh();
+}
+
 void Render::mltResizeClipEnd(int track, GenTime pos, GenTime in, GenTime out) {
     m_isBlocked = true;
 
index 3061a4c2e38a1aa0a794a8352aff39917b563c4f..833e54e019a6f156a36fdfeeb24f12e19887ebe3 100644 (file)
@@ -157,6 +157,7 @@ Q_OBJECT public:
     void mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh = true);
     void mltAddEffect(int track, GenTime position, QMap <QString, QString> args, bool doRefresh = true);
     void mltEditEffect(int track, GenTime position, QMap <QString, QString> args);
+    void mltMoveEffect(int track, GenTime position, int oldPos, int newPos);
     void mltChangeTrackState(int track, bool mute, bool blind);
     void mltMoveTransition(QString type, int startTrack, int trackOffset, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut);
     void mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);