]> git.sesse.net Git - kdenlive/blobdiff - src/clipitem.cpp
Keyframable rotation for affine transition
[kdenlive] / src / clipitem.cpp
index f26e53241629c8112fef04a79c874112159f43e9..73573ec44b96556ac5c7956cc560224925fbda3c 100644 (file)
@@ -389,13 +389,15 @@ void ClipItem::setKeyframes(const int ix, const QStringList keyframes)
     int keyframeParams = 0;
     for (int i = 0; i < params.count(); i++) {
         QDomElement e = params.item(i).toElement();
-        if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
+        if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") && e.attribute("intimeline") == "1") {
             e.setAttribute("keyframes", keyframes.at(keyframeParams));
             if (ix == m_selectedEffect && keyframeParams == 0) {
                 m_keyframes.clear();
+                m_visibleParam = i;
                 double max = e.attribute("max").toDouble();
                 double min = e.attribute("min").toDouble();
                 m_keyframeFactor = 100.0 / (max - min);
+                m_keyframeOffset = min;
                 m_keyframeDefault = e.attribute("default").toDouble();
                 m_selectedKeyframe = 0;
                 // parse keyframes
@@ -424,11 +426,13 @@ void ClipItem::setSelectedEffect(const int ix)
         if (effect.attribute("disable") != "1")
             for (int i = 0; i < params.count(); i++) {
                 QDomElement e = params.item(i).toElement();
-                if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
+                if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") && e.attribute("intimeline") == "1") {
                     m_keyframes.clear();
+                    m_visibleParam = i;
                     double max = e.attribute("max").toDouble();
                     double min = e.attribute("min").toDouble();
                     m_keyframeFactor = 100.0 / (max - min);
+                    m_keyframeOffset = min;
                     m_keyframeDefault = e.attribute("default").toDouble();
                     m_selectedKeyframe = 0;
 
@@ -471,23 +475,19 @@ void ClipItem::updateKeyframeEffect()
     QDomElement effect = getEffectAt(m_selectedEffect);
     if (effect.attribute("disable") == "1") return;
     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.attribute("type") == "simplekeyframe")) {
-            QString keyframes;
-            if (m_keyframes.count() > 0) {
-                QMap<int, int>::const_iterator i = m_keyframes.constBegin();
-                while (i != m_keyframes.constEnd()) {
-                    keyframes.append(QString::number(i.key()) + ':' + QString::number(i.value()) + ';');
-                    ++i;
-                }
+    QDomElement e = params.item(m_visibleParam).toElement();
+
+    if (!e.isNull()) {
+        QString keyframes;
+        if (m_keyframes.count() > 0) {
+            QMap<int, int>::const_iterator i = m_keyframes.constBegin();
+            while (i != m_keyframes.constEnd()) {
+                keyframes.append(QString::number(i.key()) + ':' + QString::number(i.value()) + ';');
+                ++i;
             }
-            // Effect has a keyframe type parameter, we need to set the values
-            //kDebug() << ":::::::::::::::   SETTING EFFECT KEYFRAMES: " << keyframes;
-            e.setAttribute("keyframes", keyframes);
-            break;
         }
+        // Effect has a keyframe type parameter, we need to set the values
+        e.setAttribute("keyframes", keyframes);
     }
 }
 
@@ -508,7 +508,7 @@ void ClipItem::resetThumbs(bool clearExistingThumbs)
 }
 
 
-void ClipItem::refreshClip(bool checkDuration)
+void ClipItem::refreshClip(bool checkDuration, bool forceResetThumbs)
 {
     if (checkDuration && (m_maxDuration != m_clip->maxDuration())) {
         m_maxDuration = m_clip->maxDuration();
@@ -529,7 +529,8 @@ void ClipItem::refreshClip(bool checkDuration)
         QString colour = m_clip->getProperty("colour");
         colour = colour.replace(0, 2, "#");
         m_baseColor = QColor(colour.left(7));
-    } else resetThumbs(checkDuration);
+        update();
+    } else resetThumbs(forceResetThumbs);
 }
 
 void ClipItem::slotFetchThumbs()
@@ -945,36 +946,19 @@ OPERATIONTYPE ClipItem::operationMode(QPointF pos)
     if (rect.height() < 30) addtransitionOffset = 0;
 
     if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset  && qAbs((int)(pos.y() - rect.y())) < 6) {
-        if (m_startFade == 0) setToolTip(i18n("Add audio fade"));
-        // xgettext:no-c-format
-        else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_startFade, m_fps).seconds()));
         return FADEIN;
     } else if (pos.x() - rect.x() < maximumOffset && (rect.bottom() - pos.y() > addtransitionOffset)) {
-        // xgettext:no-c-format
-        setToolTip(i18n("Crop from start: %1s", cropStart().seconds()));
         return RESIZESTART;
     } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - m_endFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
-        if (m_endFade == 0) setToolTip(i18n("Add audio fade"));
-        // xgettext:no-c-format
-        else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_endFade, m_fps).seconds()));
         return FADEOUT;
     } else if ((rect.right() - pos.x() < maximumOffset) && (rect.bottom() - pos.y() > addtransitionOffset)) {
-        // xgettext:no-c-format
-        setToolTip(i18n("Clip duration: %1s", cropDuration().seconds()));
         return RESIZEEND;
     } else if ((pos.x() - rect.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
-        setToolTip(i18n("Add transition"));
         return TRANSITIONSTART;
     } else if ((rect.right() - pos.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
-        setToolTip(i18n("Add transition"));
         return TRANSITIONEND;
     }
-    QString tooltip = "<b>" + m_clipName + "</b>";
-    if (!baseClip()->fileURL().isEmpty())
-        tooltip.append("<br />" + baseClip()->fileURL().path());
-    if (!baseClip()->description().isEmpty())
-        tooltip.append("<br />" + baseClip()->description());
-    setToolTip(tooltip);
+
     return MOVE;
 }
 
@@ -1221,9 +1205,7 @@ bool ClipItem::checkEffectsKeyframesPos(const int previous, const int current, b
         for (int j = 0; j < params.count(); j++) {
             bool modified = false;
             QDomElement e = params.item(j).toElement();
-            if (e.isNull())
-                continue;
-            if (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") {
+            if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
                 // parse keyframes and adjust values
                 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
                 QMap <int, double> kfr;
@@ -1613,7 +1595,7 @@ const ItemInfo ClipItem::speedIndependantInfo() const
 //virtual
 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event)
 {
-    const QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
+    const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
     QDomDocument doc;
     doc.setContent(effects, true);
     const QDomElement e = doc.documentElement();
@@ -1683,24 +1665,33 @@ void ClipItem::insertKeyframe(QDomElement effect, int pos, int val)
     QDomNodeList params = effect.elementsByTagName("parameter");
     for (int i = 0; i < params.count(); i++) {
         QDomElement e = params.item(i).toElement();
-        QString kfr = e.attribute("keyframes");
-        const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
-        QStringList newkfr;
-        bool added = false;
-        foreach(const QString &str, keyframes) {
-            int kpos = str.section(':', 0, 0).toInt();
-            double newval = str.section(':', 1, 1).toDouble();
-            if (kpos < pos) {
-                newkfr.append(str);
-            } else if (!added) {
-                if (i == 0) newkfr.append(QString::number(pos) + ":" + QString::number(val));
-                else newkfr.append(QString::number(pos) + ":" + QString::number(newval));
-                if (kpos > pos) newkfr.append(str);
-                added = true;
-            } else newkfr.append(str);
+        if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
+            QString kfr = e.attribute("keyframes");
+            const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
+            QStringList newkfr;
+            bool added = false;
+            foreach(const QString &str, keyframes) {
+                int kpos = str.section(':', 0, 0).toInt();
+                double newval = str.section(':', 1, 1).toDouble();
+                if (kpos < pos) {
+                    newkfr.append(str);
+                } else if (!added) {
+                    if (i == m_visibleParam)
+                        newkfr.append(QString::number(pos) + ":" + QString::number(val));
+                    else
+                        newkfr.append(QString::number(pos) + ":" + QString::number(newval));
+                    if (kpos > pos) newkfr.append(str);
+                    added = true;
+                } else newkfr.append(str);
+            }
+            if (!added) {
+                if (i == m_visibleParam)
+                    newkfr.append(QString::number(pos) + ":" + QString::number(val));
+                else
+                    newkfr.append(QString::number(pos) + ":" + e.attribute("default"));
+            }
+            e.setAttribute("keyframes", newkfr.join(";"));
         }
-        if (!added) newkfr.append(QString::number(pos) + ":" + QString::number(val));
-        e.setAttribute("keyframes", newkfr.join(";"));
     }
 }
 
@@ -1713,20 +1704,24 @@ void ClipItem::movedKeyframe(QDomElement effect, int oldpos, int newpos, double
     int end = (cropStart() + cropDuration()).frames(m_fps) - 1;
     for (int i = 0; i < params.count(); i++) {
         QDomElement e = params.item(i).toElement();
-        QString kfr = e.attribute("keyframes");
-        const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
-        QStringList newkfr;
-        foreach(const QString &str, keyframes) {
-            if (str.section(':', 0, 0).toInt() != oldpos) {
-                newkfr.append(str);
-            } else if (newpos != -1) {
-                newpos = qMax(newpos, start);
-                newpos = qMin(newpos, end);
-                if (i == 0) newkfr.append(QString::number(newpos) + ":" + QString::number(value));
-                else newkfr.append(QString::number(newpos) + ":" + str.section(':', 1, 1));
+        if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
+            QString kfr = e.attribute("keyframes");
+            const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
+            QStringList newkfr;
+            foreach(const QString &str, keyframes) {
+                if (str.section(':', 0, 0).toInt() != oldpos) {
+                    newkfr.append(str);
+                } else if (newpos != -1) {
+                    newpos = qMax(newpos, start);
+                    newpos = qMin(newpos, end);
+                    if (i == m_visibleParam)
+                        newkfr.append(QString::number(newpos) + ":" + QString::number(value));
+                    else
+                        newkfr.append(QString::number(newpos) + ":" + str.section(':', 1, 1));
+                }
             }
+            e.setAttribute("keyframes", newkfr.join(";"));
         }
-        e.setAttribute("keyframes", newkfr.join(";"));
     }
 
     updateKeyframes(effect);
@@ -1738,7 +1733,11 @@ void ClipItem::updateKeyframes(QDomElement effect)
     m_keyframes.clear();
     // parse keyframes
     QDomNodeList params = effect.elementsByTagName("parameter");
-    QDomElement e = params.item(0).toElement();
+    QDomElement e = params.item(m_visibleParam).toElement();
+    if (e.attribute("intimeline") != "1") {
+        setSelectedEffect(m_selectedEffect);
+        return;
+    }
     const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
     foreach(const QString &str, keyframes) {
         int pos = str.section(':', 0, 0).toInt();