From b63a5ed56d4842bc509df7787048a5782de6e136 Mon Sep 17 00:00:00 2001 From: Till Theato Date: Sat, 19 Feb 2011 21:51:46 +0000 Subject: [PATCH] rotoscoping: allow to move keyframes svn path=/trunk/kdenlive/; revision=5430 --- src/rotoscoping/rotowidget.cpp | 13 +++++++++++++ src/rotoscoping/rotowidget.h | 1 + src/simplekeyframes/simplekeyframewidget.cpp | 1 + src/simplekeyframes/simplekeyframewidget.h | 1 + src/simplekeyframes/simpletimelinewidget.cpp | 7 +++++-- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/rotoscoping/rotowidget.cpp b/src/rotoscoping/rotowidget.cpp index 44cbfe60..d1c2133d 100644 --- a/src/rotoscoping/rotowidget.cpp +++ b/src/rotoscoping/rotowidget.cpp @@ -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 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" diff --git a/src/rotoscoping/rotowidget.h b/src/rotoscoping/rotowidget.h index 668e3e21..ef3a376a 100644 --- a/src/rotoscoping/rotowidget.h +++ b/src/rotoscoping/rotowidget.h @@ -76,6 +76,7 @@ private slots: void slotAddKeyframe(int pos = -1); void slotRemoveKeyframe(int pos = -1); + void slotMoveKeyframe(int oldPos, int newPos); }; #endif diff --git a/src/simplekeyframes/simplekeyframewidget.cpp b/src/simplekeyframes/simplekeyframewidget.cpp index 9221549a..92491019 100644 --- a/src/simplekeyframes/simplekeyframewidget.cpp +++ b/src/simplekeyframes/simplekeyframewidget.cpp @@ -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())); diff --git a/src/simplekeyframes/simplekeyframewidget.h b/src/simplekeyframes/simplekeyframewidget.h index fb1d500d..0af2752a 100644 --- a/src/simplekeyframes/simplekeyframewidget.h +++ b/src/simplekeyframes/simplekeyframewidget.h @@ -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; diff --git a/src/simplekeyframes/simpletimelinewidget.cpp b/src/simplekeyframes/simpletimelinewidget.cpp index 95700aa1..c3e88136 100644 --- a/src/simplekeyframes/simpletimelinewidget.cpp +++ b/src/simplekeyframes/simpletimelinewidget.cpp @@ -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()); /* -- 2.39.2