]> git.sesse.net Git - kdenlive/blobdiff - src/clipitem.cpp
const'ify
[kdenlive] / src / clipitem.cpp
index aa86d6f284b2a0f23976a84f0ed673cf26a3e940..479c28c9397ae31e8f2448c504f4888975f4e113 100644 (file)
@@ -90,7 +90,7 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, i
     setAcceptDrops(true);
     m_audioThumbReady = m_clip->audioThumbCreated();
     //setAcceptsHoverEvents(true);
-    connect(this , SIGNAL(prepareAudioThumb(double, int, int, int, int)) , this, SLOT(slotPrepareAudioThumb(double, int, int, int, int)));
+    connect(this , SIGNAL(prepareAudioThumb(double,int,int,int,int)) , this, SLOT(slotPrepareAudioThumb(double,int,int,int,int)));
 
     if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
         m_baseColor = QColor(141, 166, 215);
@@ -100,7 +100,7 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, i
             connect(&m_startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
             m_endThumbTimer.setSingleShot(true);
             connect(&m_endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
-            connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
+            connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int,QImage)), this, SLOT(slotThumbReady(int,QImage)));
             connect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
             if (generateThumbs) QTimer::singleShot(200, this, SLOT(slotFetchThumbs()));
         }
@@ -112,13 +112,14 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, i
     } else if (m_clipType == IMAGE || m_clipType == TEXT) {
         m_baseColor = QColor(141, 166, 215);
         if (m_clipType == TEXT) {
-            connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
+            connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int,QImage)), this, SLOT(slotThumbReady(int,QImage)));
         }
         //m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
     } else if (m_clipType == AUDIO) {
         m_baseColor = QColor(141, 215, 166);
         connect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
     }
+    m_paintColor = m_baseColor;
 }
 
 
@@ -129,7 +130,7 @@ ClipItem::~ClipItem()
     m_startThumbTimer.stop();
     if (scene()) scene()->removeItem(this);
     if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
-        //disconnect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
+        //disconnect(m_clip->thumbProducer(), SIGNAL(thumbReady(int,QImage)), this, SLOT(slotThumbReady(int,QImage)));
         //disconnect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
     }
     delete m_timeLine;
@@ -212,7 +213,7 @@ void ClipItem::setEffectList(const EffectsList effectList)
             else if (fade < 0)
                 m_endFade = -fade;
         }
-        setSelectedEffect(0);
+        setSelectedEffect(1);
     }
 }
 
@@ -261,7 +262,7 @@ void ClipItem::initEffect(QDomElement effect, int diff, int offset)
         if (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") {
            if (e.attribute("keyframes").isEmpty()) {
                // Effect has a keyframe type parameter, we need to set the values
-               e.setAttribute("keyframes", QString::number(cropStart().frames(m_fps)) + ':' + e.attribute("default"));
+               e.setAttribute("keyframes", QString::number((int) cropStart().frames(m_fps)) + ':' + e.attribute("default"));
            }
            else if (offset != 0) {
                // adjust keyframes to this clip
@@ -272,8 +273,8 @@ void ClipItem::initEffect(QDomElement effect, int diff, int offset)
 
         if (e.attribute("type") == "geometry" && !e.hasAttribute("fixed")) {
             // Effects with a geometry parameter need to sync in / out with parent clip
-           effect.setAttribute("in", QString::number(cropStart().frames(m_fps)));
-           effect.setAttribute("out", QString::number((cropStart() + cropDuration()).frames(m_fps) - 1));
+           effect.setAttribute("in", QString::number((int) cropStart().frames(m_fps)));
+           effect.setAttribute("out", QString::number((int) (cropStart() + cropDuration()).frames(m_fps) - 1));
            effect.setAttribute("_sync_in_out", "1");
        }
     }
@@ -349,12 +350,16 @@ const QString ClipItem::adjustKeyframes(QString keyframes, int offset)
     return result.join(";");
 }
 
-bool ClipItem::checkKeyFrames()
+bool ClipItem::checkKeyFrames(int width, int height, int previousDuration, int cutPos)
 {
     bool clipEffectsModified = false;
     QLocale locale;
     // go through all effects this clip has
     for (int ix = 0; ix < m_effectList.count(); ++ix) {
+       // Check geometry params
+       resizeGeometries(ix, width, height, previousDuration, cutPos == -1 ? 0 : cutPos, cropDuration().frames(m_fps) - 1);
+
+       // Check keyframe params
         QStringList keyframeParams = keyframes(ix);
         QStringList newKeyFrameParams;
         bool effModified = false;
@@ -368,7 +373,7 @@ bool ClipItem::checkKeyFrames()
             int lastPos = -1;
             double lastValue = -1;
             int start = cropStart().frames(m_fps);
-            int end = (cropStart() + cropDuration()).frames(m_fps);
+            int end = (cropStart() + cropDuration()).frames(m_fps) - 1;
 
             // go through all keyframes for one param
             foreach(const QString &str, keyframes) {
@@ -382,8 +387,8 @@ bool ClipItem::checkKeyFrames()
                     if (pos > start) {
                         int diff = pos - lastPos;
                         double ratio = (double)(start - lastPos) / diff;
-                        double newValue = lastValue + (val - lastValue) * ratio;
-                        newKeyFrames.append(QString::number(start) + ':' + locale.toString(newValue));
+                        int newValue = lastValue + (val - lastValue) * ratio;
+                        newKeyFrames.append(QString::number(start) + ':' + QString::number(newValue));
                         modified = true;
                     }
                     cutKeyFrame = false;
@@ -394,13 +399,13 @@ bool ClipItem::checkKeyFrames()
                         int diff = pos - lastPos;
                         if (diff != 0) {
                             double ratio = (double)(end - lastPos) / diff;
-                            double newValue = lastValue + (val - lastValue) * ratio;
-                            newKeyFrames.append(QString::number(end) + ':' + locale.toString(newValue));
+                            int newValue = lastValue + (val - lastValue) * ratio;
+                            newKeyFrames.append(QString::number(end) + ':' + QString::number(newValue));
                             modified = true;
                         }
                         break;
                     } else {
-                        newKeyFrames.append(QString::number(pos) + ':' + locale.toString(val));
+                        newKeyFrames.append(QString::number(pos) + ':' + QString::number(val));
                     }
                 }
                 lastPos = pos;
@@ -430,9 +435,9 @@ 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") && e.attribute("intimeline") == "1") {
+        if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") && (!e.hasAttribute("intimeline") || e.attribute("intimeline") == "1")) {
             e.setAttribute("keyframes", keyframes.at(keyframeParams));
-            if (ix == m_selectedEffect && keyframeParams == 0) {
+            if (ix + 1 == m_selectedEffect && keyframeParams == 0) {
                 m_keyframes.clear();
                 m_visibleParam = i;
                 double max = locale.toDouble(e.attribute("max"));
@@ -467,7 +472,7 @@ void ClipItem::setSelectedEffect(const int ix)
         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") && e.attribute("intimeline") == "1") {
+            if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") && (!e.hasAttribute("intimeline") || e.attribute("intimeline") == "1")) {
                 m_keyframes.clear();
                 m_limitedKeyFrames = e.attribute("type") == "keyframe";
                 m_visibleParam = i;
@@ -499,6 +504,22 @@ void ClipItem::setSelectedEffect(const int ix)
     }
 }
 
+void ClipItem::resizeGeometries(const int index, int width, int height, int previousDuration, int start, int duration)
+{
+    QString geom;
+    QDomElement effect = m_effectList.at(index);
+    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") == "geometry") {
+            geom = e.attribute("value");
+           Mlt::Geometry geometry(geom.toUtf8().data(), previousDuration, width, height);
+           e.setAttribute("value", geometry.serialise(start, start + duration));
+       }
+    }
+}
+
 QStringList ClipItem::keyframes(const int index)
 {
     QStringList result;
@@ -769,23 +790,21 @@ void ClipItem::paint(QPainter *painter,
                      QWidget *)
 {
     QPalette palette = scene()->palette();
-    QColor paintColor;
+    QColor paintColor = m_paintColor;
     QColor textColor;
     QColor textBgColor;
     QPen framePen;
-    if (parentItem()) paintColor = QColor(255, 248, 149);
-    else paintColor = m_baseColor;
     if (isSelected() || (parentItem() && parentItem()->isSelected())) {
        textColor = palette.highlightedText().color();
        textBgColor = palette.highlight().color();
-        paintColor = paintColor.darker();
         framePen.setColor(textBgColor);
+       paintColor.setRed(qMin(paintColor.red() * 2, 255));
     }
     else {
        textColor = palette.text().color();
        textBgColor = palette.window().color();
        textBgColor.setAlpha(200);
-        framePen.setColor(paintColor.darker());
+        framePen.setColor(m_paintColor.darker());
     }
     const QRectF exposed = option->exposedRect;
     const QTransform transformation = painter->worldTransform();
@@ -800,7 +819,7 @@ void ClipItem::paint(QPainter *painter,
     painter->setClipPath(p.intersected(q));
     painter->setPen(Qt::NoPen);
     painter->fillRect(mappedExposed, paintColor);
-    painter->setPen(paintColor.darker());
+    painter->setPen(m_paintColor.darker());
     // draw thumbnails
     if (KdenliveSettings::videothumbnails() && !isAudioOnly()) {
        QRectF thumbRect;
@@ -1366,8 +1385,10 @@ void ClipItem::resizeEnd(int posx, bool emitChange)
 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value)
 {
     if (change == QGraphicsItem::ItemSelectedChange) {
-        if (value.toBool()) setZValue(10);
-        else setZValue(2);
+        if (value.toBool())
+           setZValue(10);
+        else
+           setZValue(2);
     }
     if (change == ItemPositionChange && scene()) {
         // calculate new position.
@@ -1444,6 +1465,11 @@ QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value)
         //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
         return newPos;
     }
+    if (change == ItemParentChange) {
+       QGraphicsItem* parent = value.value<QGraphicsItem*>();
+       if (parent) m_paintColor = m_baseColor.lighter(135);
+       else m_paintColor = m_baseColor;
+    }
     return QGraphicsItem::itemChange(change, value);
 }
 
@@ -1659,8 +1685,8 @@ EffectsParameterList ClipItem::addEffect(QDomElement effect, bool /*animate*/)
         }
     }
     if (needInOutSync) {
-        parameters.addParam("in", QString::number(cropStart().frames(m_fps)));
-        parameters.addParam("out", QString::number((cropStart() + cropDuration()).frames(m_fps) - 1));
+        parameters.addParam("in", QString::number((int) cropStart().frames(m_fps)));
+        parameters.addParam("out", QString::number((int) (cropStart() + cropDuration()).frames(m_fps) - 1));
         parameters.addParam("_sync_in_out", "1");
     }
     m_effectNames = m_effectList.effectNames().join(" / ");
@@ -1668,7 +1694,7 @@ EffectsParameterList ClipItem::addEffect(QDomElement effect, bool /*animate*/)
     else if (fade < 0) m_endFade = -fade;
 
     if (m_selectedEffect == -1) {
-        setSelectedEffect(0);
+        setSelectedEffect(1);
     } else if (m_selectedEffect == ix - 1) setSelectedEffect(m_selectedEffect);
     if (needRepaint) update(boundingRect());
     /*if (animate) {
@@ -1800,7 +1826,7 @@ void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event)
            e.removeAttribute("kdenlive_ix");
        }
         CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
-        if (view) view->slotAddEffect(e, m_info.startPos, track());
+        if (view) view->slotDropEffect(this, e, m_info.startPos, track());
     }
     else return;
 }
@@ -1845,6 +1871,10 @@ void ClipItem::setAudioOnly(bool force)
         } else if (m_clipType == AUDIO) m_baseColor = QColor(141, 215, 166);
         else m_baseColor = QColor(141, 166, 215);
     }
+    if (parentItem())
+       m_paintColor = m_baseColor.lighter(135);
+    else
+       m_paintColor = m_baseColor;
     m_audioThumbCachePic.clear();
 }
 
@@ -2002,7 +2032,7 @@ QMap<int, QDomElement> ClipItem::adjustEffectsToDuration(int width, int height,
                 if (in < cropStart().frames(m_fps)) {
                     if (!effects.contains(i))
                         effects[i] = effect.cloneNode().toElement();
-                    EffectsList::setParameter(effect, "in", QString::number(cropStart().frames(m_fps)));
+                    EffectsList::setParameter(effect, "in", QString::number((int) cropStart().frames(m_fps)));
                 }
                 if (effects.contains(i))
                     setFadeOut(out - in);