]> git.sesse.net Git - kdenlive/commitdiff
Correctly refresh transition widget when resizing a transition, move last keyframe...
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 11 Feb 2013 10:59:33 +0000 (11:59 +0100)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 11 Feb 2013 10:59:33 +0000 (11:59 +0100)
src/customtrackview.cpp
src/keyframehelper.cpp
src/transition.cpp
src/transition.h

index 30e6b13da9d67f7546911085c3352b11906f9a23..8b1b1edc18ba9ee3e9398d0bf423ce40798327ca 100644 (file)
@@ -5184,10 +5184,21 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
         } else {
             // Check transition keyframes
             QDomElement old = transition->toXML();
-            if (transition->updateKeyframes()) {
+            if (transition->updateKeyframes(oldInfo.cropDuration.frames(m_document->fps()) - 1)) {
                 QDomElement xml = transition->toXML();
                 m_document->renderer()->mltUpdateTransition(xml.attribute("tag"), xml.attribute("tag"), xml.attribute("transition_btrack").toInt(), m_document->tracksCount() - xml.attribute("transition_atrack").toInt(), transition->startPos(), transition->endPos(), xml);
                 new EditTransitionCommand(this, transition->track(), transition->startPos(), old, xml, false, command);
+               ItemInfo info = transition->info();
+               QPoint p;
+               ClipItem *transitionClip = getClipItemAt(info.startPos, info.track);
+               if (transitionClip && transitionClip->baseClip()) {
+                   QString size = transitionClip->baseClip()->getProperty("frame_size");
+                   double factor = transitionClip->baseClip()->getProperty("aspect_ratio").toDouble();
+                   if (factor == 0) factor = 1.0;
+                   p.setX((int)(size.section('x', 0, 0).toInt() * factor + 0.5));
+                   p.setY(size.section('x', 1, 1).toInt());
+               }
+               emit transitionItemSelected(transition, getPreviousVideoTrack(info.track), p, true);
             }
             new MoveTransitionCommand(this, oldInfo, info, false, command);
         }
index 52241f6458bf21fb9dd868eb48c8424cc407069a..907e5090a206a727049311c45948a480c6e85c8e 100644 (file)
@@ -100,10 +100,13 @@ void KeyframeHelper::mousePressEvent(QMouseEvent * event)
         }
     }
     if (event->y() >= m_lineHeight && event->y() < height()) {
-        m_drag = true;
-        m_seekPosition = xPos / m_scale;
-        emit requestSeek(m_seekPosition);
-        update();
+       int seekRequest = xPos / m_scale; 
+       m_drag = true;
+       if (seekRequest != m_position) {
+           m_seekPosition = seekRequest;
+           emit requestSeek(m_seekPosition);
+           update();
+       }
     }
 }
 
@@ -289,7 +292,7 @@ void KeyframeHelper::paintEvent(QPaintEvent *e)
     p.setPen(palette().dark().color());
     p.drawLine(margin, m_lineHeight, width() - margin - 1, m_lineHeight);
     p.drawLine(margin, m_lineHeight - 3, margin, m_lineHeight + 3);
-    p.drawLine(width() - margin - 1, m_lineHeight - 3, width() - margin - 1, m_lineHeight + 3);
+    p.drawLine(width() - margin, m_lineHeight - 3, width() - margin, m_lineHeight + 3);
 
     // draw pointer
     if (m_seekPosition != SEEK_INACTIVE) {
index 7ac3a2233a024ace288807b9d49d1f4d2c7a92b7..5b4a7d44590ae2514be6cb0e1d220c4e1f6006a3 100644 (file)
@@ -373,7 +373,7 @@ int Transition::defaultZValue() const
     return 3;
 }
 
-bool Transition::updateKeyframes()
+bool Transition::updateKeyframes(int oldEnd)
 {
     QString keyframes;
     QDomElement pa;
@@ -391,17 +391,38 @@ bool Transition::updateKeyframes()
     QStringList values = keyframes.split(';');
     int frame;
     int i = 0;
-    foreach(const QString &pos, values) {
-        if (!pos.contains('=')) {
-            i++;
-            continue;
-        }
-        frame = pos.section('=', 0, 0).toInt();
-        if (frame > duration) {
-            modified = true;
-            break;
-        }
-        i++;
+    if (oldEnd < duration) {
+       // Transition was expanded, check if we had a keyframe at end position
+       foreach(QString pos, values) {
+           if (!pos.contains('=')) {
+               i++;
+               continue;
+           }
+           frame = pos.section('=', 0, 0).toInt();
+           if (frame == oldEnd) {
+               // Move that keyframe to new end
+                values[i] = QString::number(duration) + '=' + pos.section('=', 1);
+               pa.setAttribute("value", values.join(";"));
+               return true;
+           }
+           i++;
+       }
+       return false;
+    }
+    else {
+       // Transition was shortened, check for out of bounds keyframes
+       foreach(const QString &pos, values) {
+           if (!pos.contains('=')) {
+               i++;
+               continue;
+           }
+           frame = pos.section('=', 0, 0).toInt();
+           if (frame > duration) {
+               modified = true;
+               break;
+           }
+           i++;
+       }
     }
     if (modified) {
         if (i > 0) {
index a26f19d17511b55e6a03f551cfb52fe7b914f588..b0d43081937106c436440e714f41b4798caba413 100644 (file)
@@ -76,8 +76,10 @@ public:
     void setAutomatic(bool automatic);
     bool hasGeometry();
     int defaultZValue() const;
-    /** @brief When a transition is resized, check if keyframes are out of the transition and fix if necessary. */
-    bool updateKeyframes();
+    /** @brief When a transition is resized, check if keyframes are out of the transition and fix if necessary. 
+     * @param oldEnd the previous transition end, so that when we expand the transition, if there is a keyframe at end we move it
+     */
+    bool updateKeyframes(int oldEnd);
 
 protected:
     virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);