]> git.sesse.net Git - kdenlive/commitdiff
add / edit effect keyframe is now integrated in the undo framework
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Fri, 27 Jun 2008 17:18:40 +0000 (17:18 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Fri, 27 Jun 2008 17:18:40 +0000 (17:18 +0000)
svn path=/branches/KDE4/; revision=2280

src/CMakeLists.txt
src/clipitem.cpp
src/clipitem.h
src/customtrackview.cpp
src/customtrackview.h
src/editeffectcommand.h
src/editkeyframecommand.cpp [new file with mode: 0644]
src/editkeyframecommand.h [new file with mode: 0644]
src/edittransitioncommand.h
src/moveclipcommand.h

index 468cc8adf3de0e83055589a0d312f9682a8cefa9..70a13dcdae586d0025d5ebc2624545fc859bb57c 100644 (file)
@@ -116,6 +116,7 @@ set(kdenlive_SRCS
   editguidecommand.cpp
   statusbarmessagelabel.cpp
   regiongrabber.cpp
+  editkeyframecommand.cpp
 )
 
 kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc )
index 16a173e6c0aa4257a97eb97601a595f5d81e146e..585902988e08084d9bad386d5d5e2270cdb5871d 100644 (file)
@@ -122,8 +122,37 @@ void ClipItem::initEffect(QDomElement effect) {
     }
 }
 
+void ClipItem::setKeyframes(const int ix, const QString keyframes) {
+    QDomElement effect = effectAt(ix);
+    QDomNodeList params = effect.elementsByTagName("parameter");
+    for (int i = 0; i < params.count(); i++) {
+        QDomElement e = params.item(i).toElement();
+        if (!e.isNull() && e.attribute("type") == "keyframe") {
+           e.setAttribute("keyframes", keyframes);
+           if (ix == m_selectedEffect) {
+             m_keyframes.clear();
+             double max = e.attribute("max").toDouble();
+             double min = e.attribute("min").toDouble();
+             m_keyframeFactor = 100.0 / (max - min);
+             m_keyframeDefault = e.attribute("default").toDouble();
+             // parse keyframes
+             QStringList keyframes = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
+             foreach(QString str, keyframes) {
+                 int pos = str.section(":", 0, 0).toInt();
+                 double val = str.section(":", 1, 1).toDouble();
+                 m_keyframes[pos] = val;
+             }
+             update();
+             return;
+           }
+           break;
+        }
+    }
+
+}
+
 
-void ClipItem::setSelectedEffect(int ix) {
+void ClipItem::setSelectedEffect(const int ix) {
 
     m_selectedEffect = ix;
     QDomElement effect = effectAt(m_selectedEffect);
@@ -153,6 +182,21 @@ void ClipItem::setSelectedEffect(int ix) {
     }
 }
 
+QString ClipItem::keyframes(const int index) {
+    QString result;
+    QDomElement effect = effectAt(index);
+    QDomNodeList params = effect.elementsByTagName("parameter");
+
+    for (int i = 0; i < params.count(); i++) {
+        QDomElement e = params.item(i).toElement();
+        if (!e.isNull() && e.attribute("type") == "keyframe") {
+           result = e.attribute("keyframes");
+           break;
+       }
+    }
+    return result;
+}
+
 void ClipItem::updateKeyframeEffect() {
     // regenerate xml parameter from the clip keyframes
     QDomElement effect = effectAt(m_selectedEffect);
index e091916af28e3d43efaad556b361f59a0c20a85e..190c669b1749116df26e55c1bd21059605f7401a 100644 (file)
@@ -81,11 +81,13 @@ public:
     QList <GenTime> snapMarkers() const;
     uint fadeIn() const;
     uint fadeOut() const;
-    void setSelectedEffect(int ix);
+    void setSelectedEffect(const int ix);
     void updateKeyframeEffect();
     QDomElement selectedEffect();
     int selectedEffectIndex() const;
     void initEffect(QDomElement effect);
+    QString keyframes(const int index);
+    void setKeyframes(const int ix, const QString keyframes);
 
 protected:
     //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
index 8866ce5be7360eed4fbeb4707deda5cd00087f9b..96f904875f78a501ac1a4361f347adea85db9dfc 100644 (file)
@@ -45,6 +45,7 @@
 #include "moveeffectcommand.h"
 #include "addtransitioncommand.h"
 #include "edittransitioncommand.h"
+#include "editkeyframecommand.h"
 #include "addmarkercommand.h"
 #include "razorclipcommand.h"
 #include "kdenlivesettings.h"
@@ -569,7 +570,11 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) {
                 int pos = m_document->timecode().getFrameCount(view.kfr_position->text(), m_document->fps());
                 m_dragItem->updateKeyFramePos(GenTime(pos, m_document->fps()) + m_dragItem->cropStart(), (double) view.kfr_value->value() * m_dragItem->keyFrameFactor());
                 ClipItem *item = (ClipItem *)m_dragItem;
-                item->updateKeyframeEffect();
+               QString previous = item->keyframes(item->selectedEffectIndex());
+               item->updateKeyframeEffect();
+               QString next = item->keyframes(item->selectedEffectIndex());
+               EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false);
+               m_commandStack->push(command);
                 updateEffect(m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect());
             }
 
@@ -578,12 +583,27 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) {
             GenTime keyFramePos = GenTime((int)(mapToScene(event->pos()).x() / m_scale), m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart();
             m_dragItem->addKeyFrame(keyFramePos, mapToScene(event->pos()).toPoint().y());
             ClipItem * item = (ClipItem *) m_dragItem;
+           QString previous = item->keyframes(item->selectedEffectIndex());
             item->updateKeyframeEffect();
+           QString next = item->keyframes(item->selectedEffectIndex());
+           EditKeyFrameCommand *command = new EditKeyFrameCommand(this, m_dragItem->track(), m_dragItem->startPos(), item->selectedEffectIndex(), previous, next, false);
+           m_commandStack->push(command);
             updateEffect(m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect());
         }
     }
 }
 
+
+void CustomTrackView::editKeyFrame(const GenTime pos, const int track, const int index, const QString keyframes) {
+    ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), track);
+    if (clip) {
+      clip->setKeyframes(index, keyframes);
+      updateEffect(m_tracksList.count() - clip->track(), clip->startPos(), clip->effectAt(index));      
+    }
+    else emit displayMessage(i18n("Cannot find clip with keyframe"), ErrorMessage);
+}
+
+
 void CustomTrackView::displayContextMenu(QPoint pos, AbstractClipItem *clip) {
     if (clip == NULL) m_timelineContextMenu->popup(pos);
     else if (clip->type() == AVWIDGET) m_timelineContextClipMenu->popup(pos);
@@ -1064,7 +1084,11 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
     } else if (m_operationMode == KEYFRAME) {
         // update the MLT effect
         ClipItem * item = (ClipItem *) m_dragItem;
+       QString previous = item->keyframes(item->selectedEffectIndex());
         item->updateKeyframeEffect();
+       QString next = item->keyframes(item->selectedEffectIndex());
+       EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false);
+       m_commandStack->push(command);
         updateEffect(m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect());
     }
 
index 76352ac6bcc76d9fadd16fe83a3110269776c807..f0869f1f25870ff9888fbe51e11c6109d5d0a07c 100644 (file)
@@ -84,6 +84,7 @@ public:
     void slotSeekToNextSnap();
     double getSnapPointForPos(double pos);
     QDomElement xmlInfo();
+    void editKeyFrame(const GenTime pos, const int track, const int index, const QString keyframes);
 
 public slots:
     void setCursorPos(int pos, bool seek = true);
index 369868349ed27a07043fa0914b12f2aa206ace78..c06fe93143b1b0a051dacd0caaf39bff9cdb4df5 100644 (file)
@@ -39,10 +39,10 @@ public:
 
 private:
     CustomTrackView *m_view;
-    int m_track;
+    const int m_track;
     QDomElement m_effect;
     QDomElement m_oldeffect;
-    GenTime m_pos;
+    const GenTime m_pos;
     bool m_doIt;
 };
 
diff --git a/src/editkeyframecommand.cpp b/src/editkeyframecommand.cpp
new file mode 100644 (file)
index 0000000..edc8981
--- /dev/null
@@ -0,0 +1,44 @@
+/***************************************************************************
+                          editkeyframecommand.cpp  -  description
+                             -------------------
+    begin                : 2008
+    copyright            : (C) 2008 by Jean-Baptiste Mardelle
+    email                : 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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+#include <KLocale>
+
+#include "editkeyframecommand.h"
+#include "customtrackview.h"
+
+EditKeyFrameCommand::EditKeyFrameCommand(CustomTrackView *view, const int track, GenTime pos, const int effectIndex, const QString& oldkeyframes, const QString& newkeyframes, bool doIt) : m_view(view), m_track(track), m_pos(pos), m_index(effectIndex), m_oldkfr(oldkeyframes), m_newkfr(newkeyframes), m_doIt(doIt) {
+    int prev = m_oldkfr.split(";", QString::SkipEmptyParts).count();
+    int next = m_newkfr.split(";", QString::SkipEmptyParts).count();
+    if (prev == next) setText(i18n("Edit keyframe"));
+    else if (prev > next) setText(i18n("Delete keyframe"));
+    else setText(i18n("Add keyframe"));
+    //kDebug() << "///  CREATE GUIDE COMMAND, TIMES: " << m_oldPos.frames(25) << "x" << m_pos.frames(25);
+}
+
+
+// virtual
+void EditKeyFrameCommand::undo() {
+    m_view->editKeyFrame(m_pos, m_track, m_index, m_oldkfr);
+}
+// virtual
+void EditKeyFrameCommand::redo() {
+    if (m_doIt) {
+    m_view->editKeyFrame(m_pos, m_track, m_index, m_newkfr);
+    }
+    m_doIt = true;
+}
+
+#include "editkeyframecommand.moc"
diff --git a/src/editkeyframecommand.h b/src/editkeyframecommand.h
new file mode 100644 (file)
index 0000000..9c591e0
--- /dev/null
@@ -0,0 +1,49 @@
+/***************************************************************************
+                          editkeyframecommand.h  -  description
+                             -------------------
+    begin                : 2008
+    copyright            : (C) 2008 by Jean-Baptiste Mardelle
+    email                : 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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef KEYFRAMECOMMAND_H
+#define KEYFRAMECOMMAND_H
+
+#include <QUndoCommand>
+#include <QGraphicsView>
+#include <QPointF>
+#include <QDomElement>
+#include <KDebug>
+
+#include "gentime.h"
+#include "definitions.h"
+class CustomTrackView;
+
+
+class EditKeyFrameCommand : public QUndoCommand {
+public:
+    EditKeyFrameCommand(CustomTrackView *view, const int track, GenTime pos, const int effectIndex, const QString& oldkeyframes, const QString& newkeyframes, bool doIt);
+    virtual void undo();
+    virtual void redo();
+
+private:
+    CustomTrackView *m_view;
+    const QString m_oldkfr;
+    const QString m_newkfr;
+    const int m_track;
+    const int m_index;
+    const GenTime m_pos;
+    bool m_doIt;
+};
+
+#endif
+
index 0a6c16d8552b048a69992ee89a1cbbf7242dca26..9a12d5b19f1501197cf7a0e86afb962537774bcb 100644 (file)
@@ -36,10 +36,10 @@ public:
 
 private:
     CustomTrackView *m_view;
-    int m_track;
+    const int m_track;
     QDomElement m_effect;
     QDomElement m_oldeffect;
-    GenTime m_pos;
+    const GenTime m_pos;
     bool m_doIt;
 };
 
index 54a4a721c460a3eab28de3a21e383e9b2cc78c40..7cf002ec6a5dd6b3b0188a4994796f131538928d 100644 (file)
@@ -38,8 +38,8 @@ public:
 
 private:
     CustomTrackView *m_view;
-    ItemInfo m_startPos;
-    ItemInfo m_endPos;
+    const ItemInfo m_startPos;
+    const ItemInfo m_endPos;
     bool m_doIt;
 };