]> git.sesse.net Git - kdenlive/blobdiff - src/clipitem.cpp
const'ify/ref + minor optimization
[kdenlive] / src / clipitem.cpp
index 9c7a9a178d8d11bd33d4e2af7cdc75b0289aa3de..269e7a7642464eb5385f834c1595c9c95b07d362 100644 (file)
@@ -42,7 +42,7 @@
 
 static int FRAME_SIZE;
 
-ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, int strobe, int frame_width, bool generateThumbs) :
+ClipItem::ClipItem(DocClipBase *clip, const ItemInfo& info, double fps, double speed, int strobe, int frame_width, bool generateThumbs) :
         AbstractClipItem(info, QRectF(), fps),
         m_clip(clip),
         m_startFade(0),
@@ -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;
@@ -159,7 +160,7 @@ void ClipItem::setEffectList(const EffectsList effectList)
     m_effectList.clone(effectList);
     m_effectNames = m_effectList.effectNames().join(" / ");
     if (!m_effectList.isEmpty()) {
-        for (int i = 0; i < m_effectList.count(); i++) {
+        for (int i = 0; i < m_effectList.count(); ++i) {
            QDomElement effect = m_effectList.at(i);
             QString effectId = effect.attribute("id");
             // check if it is a fade effect
@@ -237,7 +238,7 @@ void ClipItem::initEffect(QDomElement effect, int diff, int offset)
 
     // Init parameter value & keyframes if required
     QDomNodeList params = effect.elementsByTagName("parameter");
-    for (int i = 0; i < params.count(); i++) {
+    for (int i = 0; i < params.count(); ++i) {
         QDomElement e = params.item(i).toElement();
 
         if (e.isNull())
@@ -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;
@@ -428,7 +433,7 @@ void ClipItem::setKeyframes(const int ix, const QStringList keyframes)
     QLocale locale;
     QDomNodeList params = effect.elementsByTagName("parameter");
     int keyframeParams = 0;
-    for (int i = 0; i < params.count(); i++) {
+    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.hasAttribute("intimeline") || e.attribute("intimeline") == "1")) {
             e.setAttribute("keyframes", keyframes.at(keyframeParams));
@@ -465,7 +470,7 @@ void ClipItem::setSelectedEffect(const int ix)
     QDomElement effect = effectAtIndex(m_selectedEffect);
     if (!effect.isNull() && effect.attribute("disable") != "1") {
         QDomNodeList params = effect.elementsByTagName("parameter");
-        for (int i = 0; i < params.count(); i++) {
+        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.hasAttribute("intimeline") || e.attribute("intimeline") == "1")) {
                 m_keyframes.clear();
@@ -499,13 +504,29 @@ 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;
     QDomElement effect = m_effectList.at(index);
     QDomNodeList params = effect.elementsByTagName("parameter");
 
-    for (int i = 0; i < params.count(); i++) {
+    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"))
             result.append(e.attribute("keyframes"));
@@ -627,7 +648,7 @@ void ClipItem::slotGetEndThumb()
 }
 
 
-void ClipItem::slotSetStartThumb(QImage img)
+void ClipItem::slotSetStartThumb(const QImage &img)
 {
     if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
         QPixmap pix = QPixmap::fromImage(img);
@@ -638,7 +659,7 @@ void ClipItem::slotSetStartThumb(QImage img)
     }
 }
 
-void ClipItem::slotSetEndThumb(QImage img)
+void ClipItem::slotSetEndThumb(const QImage &img)
 {
     if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
         QPixmap pix = QPixmap::fromImage(img);
@@ -669,12 +690,12 @@ void ClipItem::slotThumbReady(int frame, QImage img)
     }
 }
 
-void ClipItem::slotSetStartThumb(const QPixmap pix)
+void ClipItem::slotSetStartThumb(const QPixmap &pix)
 {
     m_startPix = pix;
 }
 
-void ClipItem::slotSetEndThumb(const QPixmap pix)
+void ClipItem::slotSetEndThumb(const QPixmap &pix)
 {
     m_endPix = pix;
 }
@@ -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;
@@ -838,7 +857,7 @@ void ClipItem::paint(QPainter *painter,
             QPointF startPos = mapped.topLeft();
             int startOffset = m_info.cropStart.frames(m_fps);
             if (clipType() == IMAGE || clipType() == TEXT) {
-                for (int i = left; i <= right; i++) {
+                for (int i = left; i <= right; ++i) {
                     painter->drawPixmap(startPos + QPointF(FRAME_SIZE *(i - startOffset), 0), m_startPix);
                 }
             }
@@ -850,7 +869,7 @@ void ClipItem::paint(QPainter *painter,
                     QPen pen(Qt::white);
                     pen.setStyle(Qt::DotLine);
                     QList <int> missing;
-                    for (int i = left; i <= right; i++) {
+                    for (int i = left; i <= right; ++i) {
                         img = m_clip->thumbProducer()->findCachedThumb(path + QString::number(i));
                         QPointF xpos = startPos + QPointF(FRAME_SIZE *(i - startOffset), 0);
                         if (img.isNull()) missing << i;
@@ -1062,7 +1081,7 @@ OPERATIONTYPE ClipItem::operationMode(QPointF pos)
        if (parentItem()) {
            QGraphicsItemGroup *dragGroup = static_cast <QGraphicsItemGroup *>(parentItem());
            QList<QGraphicsItem *> list = dragGroup->childItems();
-           for (int i = 0; i < list.count(); i++) {
+           for (int i = 0; i < list.count(); ++i) {
                if (list.at(i)->type() == AVWIDGET) {
                    ClipItem *c = static_cast <ClipItem*>(list.at(i));
                    if (c->startPos() != startPos()) return MOVE;
@@ -1077,7 +1096,7 @@ OPERATIONTYPE ClipItem::operationMode(QPointF pos)
        if (parentItem()) {
            QGraphicsItemGroup *dragGroup = static_cast <QGraphicsItemGroup *>(parentItem());
            QList<QGraphicsItem *> list = dragGroup->childItems();
-           for (int i = 0; i < list.count(); i++) {
+           for (int i = 0; i < list.count(); ++i) {
                if (list.at(i)->type() == AVWIDGET) {
                    ClipItem *c = static_cast <ClipItem*>(list.at(i));
                    if (c->endPos() != endPos()) return MOVE;
@@ -1112,7 +1131,7 @@ QList <GenTime> ClipItem::snapMarkers() const
     QList < GenTime > markers = m_clip->snapMarkers();
     GenTime pos;
 
-    for (int i = 0; i < markers.size(); i++) {
+    for (int i = 0; i < markers.size(); ++i) {
         pos = GenTime((int)(markers.at(i).frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
         if (pos > GenTime()) {
             if (pos > cropDuration()) break;
@@ -1129,7 +1148,7 @@ QList <CommentedTime> ClipItem::commentedSnapMarkers() const
     QList < CommentedTime > markers = m_clip->commentedSnapMarkers();
     GenTime pos;
 
-    for (int i = 0; i < markers.size(); i++) {
+    for (int i = 0; i < markers.size(); ++i) {
         pos = GenTime((int)(markers.at(i).time().frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
         if (pos > GenTime()) {
             if (pos > cropDuration()) break;
@@ -1175,7 +1194,7 @@ void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, in
         
         QPainter pixpainter(&m_audioThumbCachePic[startCache]);
 
-       for (int i = 0; i < channels; i++) {
+       for (int i = 0; i < channels; ++i) {
            if (simplifiedAudio) {
                positiveChannelPaths[i].moveTo(-1, channelHeight);
            }
@@ -1233,7 +1252,7 @@ void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, in
            pixpainter.setBrush(Qt::NoBrush);
        }
        pixpainter.setRenderHint(QPainter::Antialiasing, false);
-        for (int i = 0; i < channels; i++) {
+        for (int i = 0; i < channels; ++i) {
             if (fullAreaDraw) {
                 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths.value(i)));
             } else
@@ -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.
@@ -1398,7 +1419,7 @@ QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value)
         bool forwardMove = newPos.x() > pos().x();
         int offset = 0;
         if (!items.isEmpty()) {
-            for (int i = 0; i < items.count(); i++) {
+            for (int i = 0; i < items.count(); ++i) {
                 if (!items.at(i)->isEnabled()) continue;
                 if (items.at(i)->type() == type()) {
                     // Collision!
@@ -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);
 }
 
@@ -1613,7 +1639,7 @@ EffectsParameterList ClipItem::addEffect(QDomElement effect, bool /*animate*/)
         }*/
     }
 
-    for (int i = 0; i < params.count(); i++) {
+    for (int i = 0; i < params.count(); ++i) {
         QDomElement e = params.item(i).toElement();
         if (!e.isNull()) {
             if (e.attribute("type") == "geometry" && !e.hasAttribute("fixed")) {
@@ -1763,7 +1789,7 @@ const ItemInfo ClipItem::speedIndependantInfo() const
 int ClipItem::nextFreeEffectGroupIndex() const
 {
     int freeGroupIndex = 0;
-    for (int i = 0; i < m_effectList.count(); i++) {
+    for (int i = 0; i < m_effectList.count(); ++i) {
         QDomElement effect = m_effectList.at(i);
        EffectInfo effectInfo;
        effectInfo.fromString(effect.attribute("kdenlive_info"));
@@ -1788,7 +1814,7 @@ void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event)
            QDomNodeList effectlist = e.elementsByTagName("effect");
            int freeGroupIndex = nextFreeEffectGroupIndex();
            EffectInfo effectInfo;
-           for (int i = 0; i < effectlist.count(); i++) {
+           for (int i = 0; i < effectlist.count(); ++i) {
                QDomElement effect = effectlist.at(i).toElement();
                effectInfo.fromString(effect.attribute("kdenlive_info"));
                effectInfo.groupIndex = freeGroupIndex;
@@ -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();
 }
 
@@ -1865,7 +1895,7 @@ void ClipItem::insertKeyframe(QDomElement effect, int pos, int val)
     effect.setAttribute("active_keyframe", pos);
     m_editedKeyframe = pos;
     QDomNodeList params = effect.elementsByTagName("parameter");
-    for (int i = 0; i < params.count(); i++) {
+    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 kfr = e.attribute("keyframes");
@@ -1905,7 +1935,7 @@ void ClipItem::movedKeyframe(QDomElement effect, int oldpos, int newpos, double
     QDomNodeList params = effect.elementsByTagName("parameter");
     int start = cropStart().frames(m_fps);
     int end = (cropStart() + cropDuration()).frames(m_fps) - 1;
-    for (int i = 0; i < params.count(); i++) {
+    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 kfr = e.attribute("keyframes");
@@ -1965,7 +1995,7 @@ Mlt::Producer *ClipItem::getProducer(int track, bool trackSpecific)
 QMap<int, QDomElement> ClipItem::adjustEffectsToDuration(int width, int height, ItemInfo oldInfo)
 {
     QMap<int, QDomElement> effects;
-    for (int i = 0; i < m_effectList.count(); i++) {
+    for (int i = 0; i < m_effectList.count(); ++i) {
         QDomElement effect = m_effectList.at(i);
 
         if (effect.attribute("id").startsWith("fade")) {