]> git.sesse.net Git - kdenlive/commitdiff
rotoscoping: allow to move keyframes
authorTill Theato <root@ttill.de>
Sat, 19 Feb 2011 21:51:46 +0000 (21:51 +0000)
committerTill Theato <root@ttill.de>
Sat, 19 Feb 2011 21:51:46 +0000 (21:51 +0000)
svn path=/trunk/kdenlive/; revision=5430

src/rotoscoping/rotowidget.cpp
src/rotoscoping/rotowidget.h
src/simplekeyframes/simplekeyframewidget.cpp
src/simplekeyframes/simplekeyframewidget.h
src/simplekeyframes/simpletimelinewidget.cpp

index 44cbfe6045f6412f28031ac97e53bb3b86c60f16..d1c2133d73d8814932a0b7ecf1df020fd13d5b09 100644 (file)
@@ -88,6 +88,7 @@ RotoWidget::RotoWidget(QString data, Monitor *monitor, int in, int out, Timecode
     connect(m_keyframeWidget, SIGNAL(positionChanged(int)), this, SLOT(slotPositionChanged(int)));
     connect(m_keyframeWidget, SIGNAL(keyframeAdded(int)), this, SLOT(slotAddKeyframe(int)));
     connect(m_keyframeWidget, SIGNAL(keyframeRemoved(int)), this, SLOT(slotRemoveKeyframe(int)));
+    connect(m_keyframeWidget, SIGNAL(keyframeMoved(int,int)), this, SLOT(slotMoveKeyframe(int,int)));
     connect(m_scene, SIGNAL(addKeyframe()), this, SLOT(slotAddKeyframe()));
 
     slotPositionChanged(0, false);
@@ -276,4 +277,16 @@ void RotoWidget::slotRemoveKeyframe(int pos)
     slotPositionChanged(m_keyframeWidget->getPosition(), false);
 }
 
+void RotoWidget::slotMoveKeyframe(int oldPos, int newPos)
+{
+    if (m_data.canConvert(QVariant::Map)) {
+        QMap<QString, QVariant> map = m_data.toMap();
+        map[QString::number(newPos + m_in).rightJustified(qRound(log10((double)m_out)), '0')] = map.take(QString::number(oldPos + m_in).rightJustified(qRound(log10((double)m_out)), '0'));
+        m_data = QVariant(map);
+    }
+
+    slotPositionChanged(m_keyframeWidget->getPosition(), false);
+    emit valueChanged();
+}
+
 #include "rotowidget.moc"
index 668e3e21734fb7e26d9deb7c69a7a2a0367c88ef..ef3a376a8612e08ba5ecd5eab48eeb1d91fdbfba 100644 (file)
@@ -76,6 +76,7 @@ private slots:
 
     void slotAddKeyframe(int pos = -1);
     void slotRemoveKeyframe(int pos = -1);
+    void slotMoveKeyframe(int oldPos, int newPos);
 };
 
 #endif
index 9221549ad5c4c81ffb3d8a6885d047a81759290d..92491019b743aa896b8924f97e097c81d31298fa 100644 (file)
@@ -64,6 +64,7 @@ SimpleKeyframeWidget::SimpleKeyframeWidget(Timecode t, int duration, QWidget *pa
     connect(m_timeline, SIGNAL(positionChanged(int)), this, SLOT(slotSetPosition(int)));
     connect(m_timeline, SIGNAL(keyframeAdded(int)), this, SIGNAL(keyframeAdded(int)));
     connect(m_timeline, SIGNAL(keyframeRemoved(int)), this, SIGNAL(keyframeRemoved(int)));
+    connect(m_timeline, SIGNAL(keyframeMoved(int,int)), this, SIGNAL(keyframeMoved(int,int)));
 
     connect(m_buttonAddDelete, SIGNAL(pressed()), m_timeline, SLOT(slotAddRemove()));
     connect(m_buttonPrevious, SIGNAL(pressed()), m_timeline, SLOT(slotGoToPrev()));
index fb1d500d395e790ebb064b727aa2b4d2e055ffc7..0af2752ad086f666f2540b6977a3f8e5527d1bfb 100644 (file)
@@ -48,6 +48,7 @@ signals:
     void positionChanged(int pos);
     void keyframeAdded(int pos);
     void keyframeRemoved(int pos);
+    void keyframeMoved(int oldPos, int newPos);
 
 private:
     SimpleTimelineWidget *m_timeline;
index 95700aa163d32ecee8b99187909b81e5626054ef..c3e88136baf4475d6f9a340861f547dba5067dc8 100644 (file)
@@ -133,6 +133,7 @@ void SimpleTimelineWidget::mousePressEvent(QMouseEvent* event)
         foreach(const int &keyframe, m_keyframes) {
             if (qAbs(keyframe - pos) < 5) {
                 m_currentKeyframeOriginal = keyframe;
+                m_keyframes[m_keyframes.indexOf(keyframe)] = pos;
                 m_currentKeyframe = pos;
                 update();
                 return;
@@ -152,6 +153,8 @@ void SimpleTimelineWidget::mouseMoveEvent(QMouseEvent* event)
     if (event->buttons() & Qt::LeftButton) {
         int pos = qBound(0, (int)(event->x() / m_scale), m_duration);
         if (m_currentKeyframe >= 0) {
+            // should we maybe sort here?
+            m_keyframes[m_keyframes.indexOf(m_currentKeyframe)] = pos;
             m_currentKeyframe = pos;
             emit keyframeMoving(m_currentKeyframeOriginal, m_currentKeyframe);
         } else {
@@ -169,7 +172,8 @@ void SimpleTimelineWidget::mouseReleaseEvent(QMouseEvent* event)
 {
     Q_UNUSED(event)
 
-    if (m_currentKeyframe > 0) {
+    if (m_currentKeyframe >= 0) {
+        qSort(m_keyframes);
         emit keyframeMoved(m_currentKeyframeOriginal, m_currentKeyframe);
     }
 }
@@ -216,7 +220,6 @@ void SimpleTimelineWidget::paintEvent(QPaintEvent* event)
             p.setBrush(m_colKeyframeBg);
     }
 
-
     p.setPen(palette().dark().color());
 
     /*