From f6ee585152c056105045f204111fdb14b5bacff1 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Fri, 22 Feb 2013 15:14:17 +0100 Subject: [PATCH] Fix double click in a timeline clip to add keyframe --- src/abstractclipitem.cpp | 15 +++++++++++++++ src/abstractclipitem.h | 1 + src/customtrackview.cpp | 7 ++++++- src/monitor.cpp | 1 - src/monitor.h | 1 - src/trackview.cpp | 2 +- 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/abstractclipitem.cpp b/src/abstractclipitem.cpp index 865edd12..0abf87aa 100644 --- a/src/abstractclipitem.cpp +++ b/src/abstractclipitem.cpp @@ -449,6 +449,21 @@ int AbstractClipItem::keyFrameNumber() const return m_keyframes.count(); } +int AbstractClipItem::checkForSingleKeyframe() +{ + // Check if we have only one keyframe + if (!m_keyframes.isEmpty() && m_keyframes.count() == 1) { + int min = (int) cropStart().frames(m_fps); + int max = (int)(cropStart() + cropDuration()).frames(m_fps) - 1; + if (m_keyframes.contains(min)) { + // Add keyframe at end of clip to allow inserting a new keframe in between + m_keyframes[max] = m_keyframes.value(min); + return m_keyframes.value(min); + } + } + return -1; +} + int AbstractClipItem::addKeyFrame(const GenTime &pos, const double value) { QRectF br = sceneBoundingRect(); diff --git a/src/abstractclipitem.h b/src/abstractclipitem.h index 0737952c..db71b10e 100644 --- a/src/abstractclipitem.h +++ b/src/abstractclipitem.h @@ -49,6 +49,7 @@ public: * @param pos new Position * @param value new Value */ void updateKeyFramePos(const GenTime &pos, const double value); + int checkForSingleKeyframe(); int addKeyFrame(const GenTime &pos, const double value); bool hasKeyFrames() const; int editedKeyFramePos() const; diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 0d219f3b..41fcf285 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -1433,10 +1433,14 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) } else*/ { // add keyframe GenTime keyFramePos = GenTime((int)(mapToScene(event->pos()).x()), m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart(); + int single = m_dragItem->checkForSingleKeyframe(); int val = m_dragItem->addKeyFrame(keyFramePos, mapToScene(event->pos()).toPoint().y()); ClipItem * item = static_cast (m_dragItem); + QDomElement oldEffect = item->selectedEffect().cloneNode().toElement(); + if (single > -1) { + item->insertKeyframe(item->getEffectAtIndex(item->selectedEffectIndex()), (item->cropStart() + item->cropDuration()).frames(m_document->fps()) - 1, single); + } //QString previous = item->keyframes(item->selectedEffectIndex()); - QDomElement oldEffect = item->selectedEffect().cloneNode().toElement(); item->insertKeyframe(item->getEffectAtIndex(item->selectedEffectIndex()), keyFramePos.frames(m_document->fps()), val); //item->updateKeyframeEffect(); //QString next = item->keyframes(item->selectedEffectIndex()); @@ -3014,6 +3018,7 @@ Qt::DropActions CustomTrackView::supportedDropActions() const void CustomTrackView::setDuration(int duration) { + if (m_projectDuration == duration) return; int diff = qAbs(duration - sceneRect().width()); if (diff * matrix().m11() > -50) { if (matrix().m11() < 0.4) setSceneRect(0, 0, (duration + 100 / matrix().m11()), sceneRect().height()); diff --git a/src/monitor.cpp b/src/monitor.cpp index 27b28de3..309e79cb 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -49,7 +49,6 @@ Monitor::Monitor(Kdenlive::MONITORID id, MonitorManager *manager, QString profile, QWidget *parent) : AbstractMonitor(id, manager, parent) , render(NULL) - , m_name(Kdenlive::noMonitor) , m_currentClip(NULL) , m_overlay(NULL) , m_scale(1) diff --git a/src/monitor.h b/src/monitor.h index 0658ca5d..c7821273 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -122,7 +122,6 @@ protected: //virtual void paintEvent(QPaintEvent * event); private: - Kdenlive::MONITORID m_name; DocClipBase *m_currentClip; SmallRuler *m_ruler; Overlay *m_overlay; diff --git a/src/trackview.cpp b/src/trackview.cpp index e46a750b..5ffa2af6 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -201,7 +201,7 @@ void TrackView::parseDocument(QDomDocument doc) QDomElement tractor = mlt.firstChildElement("tractor"); QDomNodeList tracks = tractor.elementsByTagName("track"); QDomNodeList playlists = doc.elementsByTagName("playlist"); - int duration = 300; + int duration = 1; m_projectTracks = tracks.count(); int trackduration = 0; QDomElement e; -- 2.39.2