]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
Ask to change profile if first clip does not match project profile:
[kdenlive] / src / customtrackview.cpp
index 7913e0d27616c2722d34abb77cb97a9f84cd2a1b..429ce27297751df61c296a5711d5485ad2772a05 100644 (file)
 #include "configtrackscommand.h"
 #include "rebuildgroupcommand.h"
 #include "razorgroupcommand.h"
+#include "profilesdialog.h"
 
 #include <KDebug>
 #include <KLocale>
 #include <KUrl>
 #include <KIcon>
 #include <KCursor>
-#include <KColorScheme>
 #include <KMessageBox>
 #include <KIO/NetAccess>
 
@@ -123,7 +123,8 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscen
         m_menuPosition(),
         m_blockRefresh(false),
         m_selectionGroup(NULL),
-        m_selectedTrack(0)
+        m_selectedTrack(0),
+        m_controlModifier(false)
 {
     if (doc) m_commandStack = doc->commandStack();
     else m_commandStack = NULL;
@@ -133,8 +134,9 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscen
     setLineWidth(0);
     //setCacheMode(QGraphicsView::CacheBackground);
     //setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
+    setAutoFillBackground(false);
     setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
-
+    m_activeTrackBrush = KStatefulBrush(KColorScheme::View, KColorScheme::ActiveBackground, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
     pixmapCache = new KPixmapCache("kdenlive-thumbs");
     KdenliveSettings::setTrackheight(m_tracksHeight);
     m_animationTimer = new QTimeLine(800);
@@ -173,10 +175,6 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscen
     connect(&m_thumbsTimer, SIGNAL(timeout()), this, SLOT(slotFetchNextThumbs()));
     m_thumbsTimer.setInterval(500);
     m_thumbsTimer.setSingleShot(true);
-
-    connect(&m_audioMonitorTimer, SIGNAL(timeout()), this, SIGNAL(documentModified()));
-    m_audioMonitorTimer.setInterval(2000);
-    m_audioMonitorTimer.setSingleShot(true);
 }
 
 CustomTrackView::~CustomTrackView()
@@ -201,7 +199,6 @@ void CustomTrackView::keyPressEvent(QKeyEvent * event)
 void CustomTrackView::setDocumentModified()
 {
     m_document->setModified(true);
-    m_audioMonitorTimer.start();
 }
 
 void CustomTrackView::setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition, QActionGroup *clipTypeGroup, QMenu *markermenu)
@@ -283,7 +280,7 @@ void CustomTrackView::checkTrackHeight()
         }
     }
     double newHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22();
-    m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight);
+    m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight - 1);
 
     for (int i = 0; i < m_guides.count(); i++) {
         QLineF l = m_guides.at(i)->line();
@@ -398,7 +395,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
                 }
             } else if (m_operationMode == RESIZESTART && move) {
                 m_document->renderer()->pause();
-                if (event->modifiers() != Qt::ControlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
+                if (!m_controlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
                     AbstractGroupItem *parent = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
                     if (parent)
                         parent->resizeStart((int)(snappedPos) - m_dragItemInfo.startPos.frames(m_document->fps()));
@@ -407,7 +404,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
                 }
             } else if (m_operationMode == RESIZEEND && move) {
                 m_document->renderer()->pause();
-                if (event->modifiers() != Qt::ControlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
+                if (!m_controlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
                     AbstractGroupItem *parent = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
                     if (parent)
                         parent->resizeEnd((int)(snappedPos) - m_dragItemInfo.endPos.frames(m_document->fps()));
@@ -942,6 +939,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
 
     m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps())), (int)(event->pos().y() - m_dragItem->pos().y()));
     m_operationMode = m_dragItem->operationMode(mapToScene(event->pos()));
+    m_controlModifier = (event->modifiers() == Qt::ControlModifier);
 
     // Update snap points
     if (m_selectionGroup == NULL) {
@@ -1073,6 +1071,9 @@ void CustomTrackView::rebuildGroup(int childTrack, GenTime childPos)
 void CustomTrackView::rebuildGroup(AbstractGroupItem *group)
 {
     if (group) {
+        resetSelectionGroup(false);
+        m_scene->clearSelection();
+
         QList <QGraphicsItem *> children = group->childItems();
         m_document->clipManager()->removeGroup(group);
         scene()->destroyItemGroup(group);
@@ -1542,7 +1543,7 @@ void CustomTrackView::slotRefreshEffects(ClipItem *clip)
     }
     bool success = true;
     for (int i = 0; i < clip->effectsCount(); i++) {
-        if (!m_document->renderer()->mltAddEffect(track, pos, clip->getEffectArgs(clip->effectAt(i)), false)) success = false;
+        if (!m_document->renderer()->mltAddEffect(track, pos, getEffectArgs(clip->effectAt(i)), false)) success = false;
     }
     if (!success) emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
     m_document->renderer()->doRefresh();
@@ -1550,6 +1551,14 @@ void CustomTrackView::slotRefreshEffects(ClipItem *clip)
 
 void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect)
 {
+    if (pos < GenTime()) {
+        // Add track effect
+        m_document->addTrackEffect(track - 1, effect);
+        m_document->renderer()->mltAddTrackEffect(track, getEffectArgs(effect));
+        emit updateTrackEffectState(track - 1);
+        emit showTrackEffects(track, m_document->trackInfoAt(track - 1));
+        return;
+    }
     ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
     if (clip) {
         // Special case: speed effect
@@ -1577,6 +1586,14 @@ void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect)
 void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect)
 {
     QString index = effect.attribute("kdenlive_ix");
+    if (pos < GenTime()) {
+        // Delete track effect
+        m_document->removeTrackEffect(track - 1, effect);
+        m_document->renderer()->mltRemoveTrackEffect(track, index, true);
+        emit updateTrackEffectState(track - 1);
+        emit showTrackEffects(track, m_document->trackInfoAt(track - 1));
+        return;
+    }
     // Special case: speed effect
     if (effect.attribute("id") == "speed") {
         ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
@@ -1677,13 +1694,19 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
             if (effect.attribute("type") == "audio") {
                 // Don't add audio effects on video clips
                 if (item->isVideoOnly() || (item->clipType() != AUDIO && item->clipType() != AV && item->clipType() != PLAYLIST)) {
-                    emit displayMessage(i18n("Cannot add an audio effect to this clip"), ErrorMessage);
+                    /* do not show error message when item is part of a group as the user probably knows what he does then
+                     * and the message is annoying when working with the split audio feature */
+                    if (!item->parentItem() || item->parentItem() == m_selectionGroup)
+                        emit displayMessage(i18n("Cannot add an audio effect to this clip"), ErrorMessage);
                     continue;
                 }
-            } else if (effect.hasAttribute("type") == false) {
+            } else if (effect.attribute("type") == "video" || !effect.hasAttribute("type")) {
                 // Don't add video effect on audio clips
                 if (item->isAudioOnly() || item->clipType() == AUDIO) {
-                    emit displayMessage(i18n("Cannot add a video effect to this clip"), ErrorMessage);
+                    /* do not show error message when item is part of a group as the user probably knows what he does then
+                     * and the message is annoying when working with the split audio feature */
+                    if (!item->parentItem() || item->parentItem() == m_selectionGroup)
+                        emit displayMessage(i18n("Cannot add a video effect to this clip"), ErrorMessage);
                     continue;
                 }
             }
@@ -1694,9 +1717,13 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
             if (item->isItemLocked()) {
                 continue;
             }
+
             if (effect.attribute("id") == "freeze" && m_cursorPos > item->startPos().frames(m_document->fps()) && m_cursorPos < item->endPos().frames(m_document->fps())) {
                 item->initEffect(effect, m_cursorPos - item->startPos().frames(m_document->fps()));
-            } else item->initEffect(effect);
+            } else {
+                item->initEffect(effect);
+            }
+
             if (effect.attribute("tag") == "ladspa") {
                 QString ladpsaFile = m_document->getLadspaFile();
                 initEffects::ladspaEffectFile(ladpsaFile, effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
@@ -1711,8 +1738,15 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
     } else delete effectCommand;
 }
 
-void CustomTrackView::slotDeleteEffect(ClipItem *clip, QDomElement effect, bool affectGroup)
+void CustomTrackView::slotDeleteEffect(ClipItem *clip, int track, QDomElement effect, bool affectGroup)
 {
+    if (clip == NULL) {
+        // delete track effect
+        AddEffectCommand *command = new AddEffectCommand(this, track, GenTime(-1), effect, false);
+        m_commandStack->push(command);
+        setDocumentModified();
+        return;
+    }
     if (affectGroup && clip->parentItem() && clip->parentItem() == m_selectionGroup) {
         //clip is in a group, also remove the effect in other clips of the group
         QList<QGraphicsItem *> items = m_selectionGroup->childItems();
@@ -1758,8 +1792,29 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE
         emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
         return;
     }
-    ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
     QDomElement effect = insertedEffect.cloneNode().toElement();
+    //kDebug() << "// update effect ix: " << effect.attribute("kdenlive_ix")<<", TRACK: "<<track;
+    if (pos < GenTime()) {
+        // editing a track effect
+        EffectsParameterList effectParams = getEffectArgs(effect);
+        if (effect.attribute("tag") == "ladspa") {
+            // Update the ladspa affect file
+            initEffects::ladspaEffectFile(effect.attribute("src"), effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
+        }
+        // check if we are trying to reset a keyframe effect
+        if (effectParams.hasParam("keyframes") && effectParams.paramValue("keyframes").isEmpty()) {
+            //clip->initEffect(effect);
+            effectParams = getEffectArgs(effect);
+        }
+        if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - track, pos, effectParams))
+            emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
+        m_document->setTrackEffect(m_document->tracksCount() - track - 1, ix, effect);
+        emit updateTrackEffectState(track);
+        setDocumentModified();
+        return;
+
+    }
+    ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
     if (clip) {
         // Special case: speed effect
         if (effect.attribute("id") == "speed") {
@@ -1778,7 +1833,7 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE
             return;
         }
 
-        EffectsParameterList effectParams = clip->getEffectArgs(effect);
+        EffectsParameterList effectParams = getEffectArgs(effect);
         if (effect.attribute("tag") == "ladspa") {
             // Update the ladspa affect file
             initEffects::ladspaEffectFile(effect.attribute("src"), effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
@@ -1786,7 +1841,7 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE
         // check if we are trying to reset a keyframe effect
         if (effectParams.hasParam("keyframes") && effectParams.paramValue("keyframes").isEmpty()) {
             clip->initEffect(effect);
-            effectParams = clip->getEffectArgs(effect);
+            effectParams = getEffectArgs(effect);
         }
         if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - clip->track(), clip->startPos(), effectParams))
             emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
@@ -1813,6 +1868,19 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE
 
 void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos)
 {
+    if (pos < GenTime()) {
+        // Moving track effect
+        QDomElement act = m_document->getTrackEffect(m_document->tracksCount() - track - 1, newPos - 1);
+        QDomElement before = m_document->getTrackEffect(m_document->tracksCount() - track - 1, oldPos - 1);
+
+        if (!act.isNull() && !before.isNull()) {
+            m_document->setTrackEffect(m_document->tracksCount() - track - 1, oldPos - 1, act);
+            m_document->setTrackEffect(m_document->tracksCount() - track - 1, newPos - 1, before);
+            m_document->renderer()->mltMoveEffect(m_document->tracksCount() - track, pos, oldPos, newPos);
+            emit showTrackEffects(m_document->tracksCount() - track, m_document->trackInfoAt(m_document->tracksCount() - track - 1));
+        } else emit displayMessage(i18n("Cannot move effect"), ErrorMessage);
+        return;
+    }
     ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
     if (clip && !clip->effectAt(newPos - 1).isNull() && !clip->effectAt(oldPos - 1).isNull()) {
         QDomElement act = clip->effectAt(newPos - 1);
@@ -1830,27 +1898,42 @@ void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos)
     } else emit displayMessage(i18n("Cannot move effect"), ErrorMessage);
 }
 
-void CustomTrackView::slotChangeEffectState(ClipItem *clip, int effectPos, bool disable)
+void CustomTrackView::slotChangeEffectState(ClipItem *clip, int track, int effectPos, bool disable)
 {
-    QDomElement effect = clip->effectAt(effectPos);
+    EditEffectCommand *command;
+    QDomElement effect;
+    if (clip == NULL) effect = m_document->getTrackEffect(track - 1, effectPos);
+    else effect = clip->effectAt(effectPos);
     QDomElement oldEffect = effect.cloneNode().toElement();
-
     effect.setAttribute("disable", (int) disable);
-    EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldEffect, effect, effectPos, true);
+
+
+    if (clip == NULL) {
+        // editing track effect
+        command = new EditEffectCommand(this, m_document->tracksCount() - track, GenTime(-1), oldEffect, effect, effectPos, true);
+    } else {
+        command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldEffect, effect, effectPos, true);
+    }
     m_commandStack->push(command);
     setDocumentModified();;
 }
 
-void CustomTrackView::slotChangeEffectPosition(ClipItem *clip, int currentPos, int newPos)
+void CustomTrackView::slotChangeEffectPosition(ClipItem *clip, int track, int currentPos, int newPos)
 {
-    MoveEffectCommand *command = new MoveEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), currentPos, newPos);
+    MoveEffectCommand *command;
+    if (clip == NULL) {
+        // editing track effect
+        command = new MoveEffectCommand(this, m_document->tracksCount() - track, GenTime(-1), currentPos, newPos);
+    } else command = new MoveEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), currentPos, newPos);
     m_commandStack->push(command);
     setDocumentModified();
 }
 
-void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect, int ix)
+void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, int track, QDomElement oldeffect, QDomElement effect, int ix)
 {
-    EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldeffect, effect, ix, true);
+    EditEffectCommand *command;
+    if (clip) command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldeffect, effect, ix, true);
+    else command = new EditEffectCommand(this, m_document->tracksCount() - track, GenTime(-1), oldeffect, effect, ix, true);
     m_commandStack->push(command);
 }
 
@@ -1877,10 +1960,7 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo
             m_blockRefresh = false;
             return NULL;
         }
-        if (item->parentItem()) {
-            // Item is part of a group, reset group
-            resetSelectionGroup();
-        }
+
         kDebug() << "/////////  CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25);
 
         if (execute) m_document->renderer()->mltCutClip(m_document->tracksCount() - info.track, cutTime);
@@ -1912,6 +1992,10 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo
             slotRefreshEffects(item);
         if (dup->checkKeyFrames())
             slotRefreshEffects(dup);
+
+        updatePanZoom(item);
+        updatePanZoom(dup, cutTime - item->startPos());
+
         item->baseClip()->addReference();
         m_document->updateClip(item->baseClip()->getId());
         setDocumentModified();
@@ -1953,6 +2037,9 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo
         bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, info.endPos - info.startPos);
         if (success) {
             item->resizeEnd((int) info.endPos.frames(m_document->fps()));
+
+            updatePanZoom(item);
+
             setDocumentModified();
         } else {
             emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
@@ -2122,7 +2209,8 @@ void CustomTrackView::updateTransition(int track, GenTime pos, QDomElement oldTr
         return;
     }
     bool force = false;
-    if (oldTransition.attribute("transition_atrack") != transition.attribute("transition_atrack") || oldTransition.attribute("transition_btrack") != transition.attribute("transition_btrack")) force = true;
+    if (oldTransition.attribute("transition_atrack") != transition.attribute("transition_atrack") || oldTransition.attribute("transition_btrack") != transition.attribute("transition_btrack"))
+        force = true;
     m_document->renderer()->mltUpdateTransition(oldTransition.attribute("tag"), transition.attribute("tag"), transition.attribute("transition_btrack").toInt(), m_document->tracksCount() - transition.attribute("transition_atrack").toInt(), item->startPos(), item->endPos(), transition, force);
     //kDebug() << "ORIGINAL TRACK: "<< oldTransition.attribute("transition_btrack") << ", NEW TRACK: "<<transition.attribute("transition_btrack");
     item->setTransitionParameters(transition);
@@ -2251,6 +2339,7 @@ void CustomTrackView::dropEvent(QDropEvent * event)
 
         m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
         if (items.count() > 1) groupSelectedItems(true);
+        else if (items.count() == 1) m_dragItem = static_cast <ClipItem *>(items.at(0));
         event->setDropAction(Qt::MoveAction);
         event->accept();
     } else QGraphicsView::dropEvent(event);
@@ -2482,7 +2571,8 @@ void CustomTrackView::addTrack(TrackInfo type, int ix)
         l.setP2(QPointF(l.x2(), maxHeight));
         m_guides.at(i)->setLine(l);
     }
-    m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight);
+
+    m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight - 1);
     setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount());
     viewport()->update();
     emit tracksChanged();
@@ -2555,7 +2645,7 @@ void CustomTrackView::removeTrack(int ix)
         l.setP2(QPointF(l.x2(), maxHeight));
         m_guides.at(i)->setLine(l);
     }
-    m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight);
+    m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight - 1);
     setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount());
 
     m_selectedTrack = qMin(m_selectedTrack, m_document->tracksCount() - 1);
@@ -2569,6 +2659,7 @@ void CustomTrackView::configTracks(QList < TrackInfo > trackInfos)
     for (int i = 0; i < trackInfos.count(); ++i) {
         m_document->setTrackType(i, trackInfos.at(i));
         m_document->renderer()->mltChangeTrackState(i + 1, m_document->trackInfoAt(i).isMute, m_document->trackInfoAt(i).isBlind);
+        lockTrack(m_document->tracksCount() - i - 1, m_document->trackInfoAt(i).isLocked, false);
     }
 
     QTimer::singleShot(300, this, SIGNAL(trackHeightChanged()));
@@ -2594,11 +2685,12 @@ void CustomTrackView::slotSwitchTrackLock(int ix)
 }
 
 
-void CustomTrackView::lockTrack(int ix, bool lock)
+void CustomTrackView::lockTrack(int ix, bool lock, bool requestUpdate)
 {
     int tracknumber = m_document->tracksCount() - ix - 1;
     m_document->switchTrackLock(tracknumber, lock);
-    emit doTrackLock(ix, lock);
+    if (requestUpdate)
+        emit doTrackLock(ix, lock);
     AbstractClipItem *clip = NULL;
     QList<QGraphicsItem *> selection = m_scene->items(0, ix * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), m_tracksHeight / 2 - 2);
 
@@ -3006,10 +3098,10 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             if (m_dragItem->type() == AVWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
                 ClipItem *item = static_cast <ClipItem *>(m_dragItem);
                 Mlt::Producer *prod;
-                if (item->isAudioOnly()) prod = item->baseClip()->audioProducer(m_dragItemInfo.track);
+                if (item->isAudioOnly()) prod = item->baseClip()->audioProducer(info.track);
                 else if (item->isVideoOnly()) prod = item->baseClip()->videoProducer();
-                else prod = item->baseClip()->producer(m_dragItemInfo.track);
-                bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - m_dragItemInfo.track), (int)(m_document->tracksCount() - m_dragItem->track()), (int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(m_dragItem->startPos().frames(m_document->fps())), prod, m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT);
+                else prod = item->baseClip()->producer(info.track);
+                bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - m_dragItemInfo.track), (int)(m_document->tracksCount() - info.track), (int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(info.startPos.frames(m_document->fps())), prod, m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT);
 
                 if (success) {
                     QUndoCommand *moveCommand = new QUndoCommand();
@@ -3130,8 +3222,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                     emit displayMessage(i18n("Cannot move clip to position %1", m_document->timecode().getTimecodeFromFrames(m_dragItemInfo.startPos.frames(m_document->fps()))), ErrorMessage);
                 }
                 setDocumentModified();
-            }
-            if (m_dragItem->type() == TRANSITIONWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
+            } else if (m_dragItem->type() == TRANSITIONWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
                 Transition *transition = static_cast <Transition *>(m_dragItem);
                 transition->updateTransitionEndTrack(getPreviousVideoTrack(m_dragItem->track()));
                 if (!m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_document->tracksCount() - m_dragItemInfo.track), (int)(m_document->tracksCount() - m_dragItem->track()), transition->transitionEndTrack(), m_dragItemInfo.startPos, m_dragItemInfo.endPos, info.startPos, info.endPos)) {
@@ -3150,7 +3241,11 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         } else {
             // Moving several clips. We need to delete them and readd them to new position,
             // or they might overlap each other during the move
-            QGraphicsItemGroup *group = static_cast <QGraphicsItemGroup *>(m_dragItem->parentItem());
+            QGraphicsItemGroup *group;
+            if (m_selectionGroup)
+                group = static_cast <QGraphicsItemGroup *>(m_selectionGroup);
+            else
+                group = static_cast <QGraphicsItemGroup *>(m_dragItem->parentItem());
             QList<QGraphicsItem *> items = group->childItems();
 
             QList<ItemInfo> clipsToMove;
@@ -3216,7 +3311,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                             prod = clip->baseClip()->producer(info.track);
                         m_document->renderer()->mltInsertClip(info, clip->xml(), prod, m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT);
                         for (int i = 0; i < clip->effectsCount(); i++) {
-                            m_document->renderer()->mltAddEffect(info.track, info.startPos, clip->getEffectArgs(clip->effectAt(i)), false);
+                            m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effectAt(i)), false);
                         }
                     } else {
                         Transition *tr = static_cast <Transition*>(item);
@@ -3240,6 +3335,22 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                 if (m_selectionGroup) {
                     m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps());
                     m_selectionGroupInfo.track = m_selectionGroup->track();
+
+                    for (int i = 0; i < items.count(); ++i) {
+                        if (items.at(i)->type() == GROUPWIDGET) {
+                            rebuildGroup((AbstractGroupItem*)items.at(i));
+                            items.removeAt(i);
+                            --i;
+                        }
+                    }
+                    for (int i = 0; i < items.count(); ++i) {
+                        if (items.at(i)) {
+                            items.at(i)->setSelected(true);
+                            if (items.at(i)->parentItem())
+                                items.at(i)->parentItem()->setSelected(true);
+                        }
+                    }
+                    groupSelectedItems();
                 } else {
                     rebuildGroup((AbstractGroupItem *)group);
                 }
@@ -3249,7 +3360,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         m_document->renderer()->doRefresh();
     } else if (m_operationMode == RESIZESTART && m_dragItem->startPos() != m_dragItemInfo.startPos) {
         // resize start
-        if (event->modifiers() != Qt::ControlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
+        if (!m_controlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
             AbstractGroupItem *parent = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
             if (parent) {
                 QUndoCommand *resizeCommand = new QUndoCommand();
@@ -3273,7 +3384,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         }
     } else if (m_operationMode == RESIZEEND && m_dragItem->endPos() != m_dragItemInfo.endPos) {
         // resize end
-        if (event->modifiers() != Qt::ControlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
+        if (!m_controlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
             AbstractGroupItem *parent = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
             if (parent) {
                 QUndoCommand *resizeCommand = new QUndoCommand();
@@ -3305,13 +3416,13 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             int start = item->cropStart().frames(m_document->fps());
             int end = item->fadeIn();
             if (end == 0) {
-                slotDeleteEffect(item, oldeffect, false);
+                slotDeleteEffect(item, -1, oldeffect, false);
             } else {
                 end += start;
                 QDomElement effect = oldeffect.cloneNode().toElement();
                 EffectsList::setParameter(oldeffect, "in", QString::number(start));
                 EffectsList::setParameter(oldeffect, "out", QString::number(end));
-                slotUpdateClipEffect(item, effect, oldeffect, ix);
+                slotUpdateClipEffect(item, -1, effect, oldeffect, ix);
                 emit clipItemSelected(item, ix);
             }
         } else if (item->fadeIn() != 0 && ix2 == -1) {
@@ -3328,13 +3439,13 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             int start = item->cropStart().frames(m_document->fps());
             int end = item->fadeIn();
             if (end == 0) {
-                slotDeleteEffect(item, oldeffect, false);
+                slotDeleteEffect(item, -1, oldeffect, false);
             } else {
                 end += start;
                 QDomElement effect = oldeffect.cloneNode().toElement();
                 EffectsList::setParameter(oldeffect, "in", QString::number(start));
                 EffectsList::setParameter(oldeffect, "out", QString::number(end));
-                slotUpdateClipEffect(item, effect, oldeffect, ix2);
+                slotUpdateClipEffect(item, -1, effect, oldeffect, ix2);
                 emit clipItemSelected(item, ix2);
             }
         }
@@ -3348,14 +3459,14 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps());
             int start = item->fadeOut();
             if (start == 0) {
-                slotDeleteEffect(item, oldeffect, false);
+                slotDeleteEffect(item, -1, oldeffect, false);
             } else {
                 start = end - start;
                 QDomElement effect = oldeffect.cloneNode().toElement();
                 EffectsList::setParameter(oldeffect, "in", QString::number(start));
                 EffectsList::setParameter(oldeffect, "out", QString::number(end));
                 // kDebug()<<"EDIT FADE OUT : "<<start<<"x"<<end;
-                slotUpdateClipEffect(item, effect, oldeffect, ix);
+                slotUpdateClipEffect(item, -1, effect, oldeffect, ix);
                 emit clipItemSelected(item, ix);
             }
         } else if (item->fadeOut() != 0 && ix2 == -1) {
@@ -3373,14 +3484,14 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps());
             int start = item->fadeOut();
             if (start == 0) {
-                slotDeleteEffect(item, oldeffect, false);
+                slotDeleteEffect(item, -1, oldeffect, false);
             } else {
                 start = end - start;
                 QDomElement effect = oldeffect.cloneNode().toElement();
                 EffectsList::setParameter(oldeffect, "in", QString::number(start));
                 EffectsList::setParameter(oldeffect, "out", QString::number(end));
                 // kDebug()<<"EDIT FADE OUT : "<<start<<"x"<<end;
-                slotUpdateClipEffect(item, effect, oldeffect, ix2);
+                slotUpdateClipEffect(item, -1, effect, oldeffect, ix2);
                 emit clipItemSelected(item, ix2);
             }
         }
@@ -3584,9 +3695,12 @@ void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependant
     }
     info.track = m_document->tracksCount() - item->track();
     int endPos;
-    if (item->isVideoOnly()) endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->videoProducer());
-    else if (item->isAudioOnly()) endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->audioProducer(item->track()));
-    else endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->producer());
+    if (item->isVideoOnly())
+        endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->videoProducer());
+    else if (item->isAudioOnly())
+        endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->audioProducer(item->track()));
+    else
+        endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->producer());
     if (endPos >= 0) {
         item->setSpeed(speed, strobe);
         item->updateRectGeometry();
@@ -3601,25 +3715,30 @@ void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependant
 void CustomTrackView::cutSelectedClips()
 {
     QList<QGraphicsItem *> itemList = scene()->selectedItems();
+    QList<AbstractGroupItem *> groups;
     GenTime currentPos = GenTime(m_cursorPos, m_document->fps());
-    QList <QGraphicsItem *> skipList;
     for (int i = 0; i < itemList.count(); ++i) {
-        if (skipList.indexOf(itemList.at(i)) != -1)
+        if (!itemList.at(i))
             continue;
         if (itemList.at(i)->type() == AVWIDGET) {
             ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
             if (item->parentItem() && item->parentItem() != m_selectionGroup) {
-                skipList.append(item->parentItem()->childItems());
-                razorGroup((AbstractGroupItem *)item->parentItem(), currentPos);
+                AbstractGroupItem *group = static_cast <AbstractGroupItem *>(item->parentItem());
+                if (!groups.contains(group))
+                    groups << group;
             } else if (currentPos > item->startPos() && currentPos < item->endPos()) {
                 RazorClipCommand *command = new RazorClipCommand(this, item->info(), currentPos);
                 m_commandStack->push(command);
             }
         } else if (itemList.at(i)->type() == GROUPWIDGET && itemList.at(i) != m_selectionGroup) {
-            skipList.append(itemList.at(i)->childItems());
-            razorGroup((AbstractGroupItem *)itemList.at(i), currentPos);
+            AbstractGroupItem *group = static_cast<AbstractGroupItem *>(itemList.at(i));
+            if (!groups.contains(group))
+                groups << group;
         }
     }
+
+    for (int i = 0; i < groups.count(); ++i)
+        razorGroup(groups.at(i), currentPos);
 }
 
 void CustomTrackView::razorGroup(AbstractGroupItem* group, GenTime cutPos)
@@ -3783,6 +3902,27 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i
         emit displayMessage(i18n("No clip copied"), ErrorMessage);
         return;
     }
+
+    if (baseclip->producer() == NULL) {
+        // If the clip has no producer, we must wait until it is created...
+        m_mutex.lock();
+        emit displayMessage(i18n("Waiting for clip..."), InformationMessage);
+        emit forceClipProcessing(clipId);
+        qApp->processEvents();
+        for (int i = 0; i < 3; i++) {
+            if (baseclip->producer() == NULL) {
+                m_producerNotReady.wait(&m_mutex, 500 + 500 * i);
+            } else break;
+        }
+        if (baseclip->producer() == NULL) {
+            emit displayMessage(i18n("Cannot insert clip..."), ErrorMessage);
+            m_mutex.unlock();
+            return;
+        }
+        emit displayMessage(QString(), InformationMessage);
+        m_mutex.unlock();
+    }
+
     ClipItem *item = new ClipItem(baseclip, info, m_document->fps(), xml.attribute("speed", "1").toDouble(), xml.attribute("strobe", "1").toInt());
     item->setEffectList(effects);
     if (xml.hasAttribute("audio_only")) item->setAudioOnly(true);
@@ -3802,7 +3942,7 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i
     else prod = baseclip->producer(info.track);
     m_document->renderer()->mltInsertClip(info, xml, prod, overwrite, push);
     for (int i = 0; i < item->effectsCount(); i++) {
-        m_document->renderer()->mltAddEffect(info.track, info.startPos, item->getEffectArgs(item->effectAt(i)), false);
+        m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(item->effectAt(i)), false);
     }
     setDocumentModified();
     if (refresh) m_document->renderer()->doRefresh();
@@ -4078,6 +4218,9 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
                 else
                     prod = clip->baseClip()->producer(info.track);
                 m_document->renderer()->mltInsertClip(info, clip->xml(), prod);
+                for (int i = 0; i < clip->effectsCount(); i++) {
+                    m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effectAt(i)), false);
+                }
             } else if (item->type() == TRANSITIONWIDGET) {
                 Transition *tr = static_cast <Transition*>(item);
                 int newTrack;
@@ -4091,9 +4234,15 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
                 m_document->renderer()->mltAddTransition(tr->transitionTag(), newTrack, m_document->tracksCount() - info.track, info.startPos, info.endPos, tr->toXML());
             }
         }
-        if (!reverseMove)
-            rebuildGroup(m_selectionGroup);
+
         resetSelectionGroup(false);
+
+        for (int i = 0; i < children.count(); i++) {
+            if (children.at(i)->parentItem())
+                rebuildGroup((AbstractGroupItem*)children.at(i)->parentItem());
+        }
+        clearSelection();
+
         KdenliveSettings::setSnaptopoints(snap);
         m_document->renderer()->doRefresh();
     } else kDebug() << "///////// WARNING; NO GROUP TO MOVE";
@@ -4252,7 +4401,11 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol
                     new MoveTransitionCommand(this, trInfo, newTrInfo, true, command);
             }
 
+            /*
+                TODO: cleanup the effect update process
+             */
             ClipItem *clip = static_cast < ClipItem * >(item);
+
             updatePositionEffects(clip, oldInfo);
 
             // check keyframes
@@ -4347,7 +4500,7 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
     if (item->type() == AVWIDGET) {
         ItemInfo resizeinfo = info;
         resizeinfo.track = m_document->tracksCount() - resizeinfo.track;
-        bool success = m_document->renderer()->mltResizeClipEnd(resizeinfo, resizeinfo.endPos - resizeinfo.startPos);
+        bool success = m_document->renderer()->mltResizeClipEnd(resizeinfo, resizeinfo.cropDuration);
         if (success) {
             // Check if there is an automatic transition on that clip (lower track)
             Transition *tr = getTransitionItemAtEnd(oldInfo.endPos, oldInfo.track);
@@ -4371,8 +4524,11 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
 
             }
 
-            // check keyframes
             ClipItem *clip = static_cast < ClipItem * >(item);
+
+            updatePositionEffects(clip, oldInfo);
+
+            // check keyframes
             QDomDocument doc;
             QDomElement root = doc.createElement("list");
             doc.appendChild(root);
@@ -4403,8 +4559,6 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
             } else {
                 new ResizeClipCommand(this, oldInfo, info, false, false, command);
             }
-
-            updatePositionEffects(clip, oldInfo);
         } else {
             KdenliveSettings::setSnaptopoints(false);
             item->resizeEnd((int) oldInfo.endPos.frames(m_document->fps()));
@@ -4450,7 +4604,7 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info)
             end += start;
             EffectsList::setParameter(oldeffect, "in", QString::number(start));
             EffectsList::setParameter(oldeffect, "out", QString::number(end));
-            if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), item->getEffectArgs(oldeffect)))
+            if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect)))
                 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
             // if fade effect is displayed, update the effect edit widget with new clip duration
             if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
@@ -4468,7 +4622,7 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info)
             end += start;
             EffectsList::setParameter(oldeffect, "in", QString::number(start));
             EffectsList::setParameter(oldeffect, "out", QString::number(end));
-            if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), item->getEffectArgs(oldeffect)))
+            if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect)))
                 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
             // if fade effect is displayed, update the effect edit widget with new clip duration
             if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
@@ -4490,7 +4644,7 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info)
             start = end - start;
             EffectsList::setParameter(oldeffect, "in", QString::number(start));
             EffectsList::setParameter(oldeffect, "out", QString::number(end));
-            if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), item->getEffectArgs(oldeffect)))
+            if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect)))
                 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
             // if fade effect is displayed, update the effect edit widget with new clip duration
             if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
@@ -4508,7 +4662,7 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info)
             start = end - start;
             EffectsList::setParameter(oldeffect, "in", QString::number(start));
             EffectsList::setParameter(oldeffect, "out", QString::number(end));
-            if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), item->getEffectArgs(oldeffect)))
+            if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect)))
                 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
             // if fade effect is displayed, update the effect edit widget with new clip duration
             if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
@@ -4529,22 +4683,7 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info)
         }
     }
 
-    effectPos = item->hasEffect("affine", "pan_zoom");
-    if (effectPos != -1) {
-        QDomElement oldeffect = item->effectAt(effectPos);
-        int start = item->cropStart().frames(m_document->fps());
-        int max = start + item->cropDuration().frames(m_document->fps());
-        if (start < 0) {
-            max -= start;
-            start = 0;
-        }
-        oldeffect.setAttribute("in", start);
-        oldeffect.setAttribute("out", max);
-        if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), item->getEffectArgs(oldeffect)))
-            emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
-        // if effect is displayed, update the effect edit widget with new clip duration
-        if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
-    }
+    updatePanZoom(item);
 }
 
 double CustomTrackView::getSnapPointForPos(double pos)
@@ -4617,6 +4756,11 @@ void CustomTrackView::updateSnapPoints(AbstractClipItem *selected, QList <GenTim
         }
     }
 
+    // add render zone
+    QPoint z = m_document->zone();
+    snaps.append(GenTime(z.x(), m_document->fps()));
+    snaps.append(GenTime(z.y(), m_document->fps()));
+
     qSort(snaps);
     m_scene->setSnapList(snaps);
     //for (int i = 0; i < m_snapPoints.size(); ++i)
@@ -4859,13 +5003,12 @@ void CustomTrackView::setScale(double scaleFactor, double verticalScale)
     newmatrix = newmatrix.scale(scaleFactor, verticalScale);
     m_scene->setScale(scaleFactor, verticalScale);
     removeTipAnimation();
-    double verticalPos = mapToScene(QPoint(0, viewport()->height() / 2)).y();
     bool adjust = false;
     if (verticalScale != matrix().m22()) adjust = true;
     setMatrix(newmatrix);
     if (adjust) {
         double newHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22();
-        m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight);
+        m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight - 1);
         for (int i = 0; i < m_guides.count(); i++) {
             QLineF l = m_guides.at(i)->line();
             l.setP2(QPointF(l.x2(), newHeight));
@@ -4881,6 +5024,7 @@ void CustomTrackView::setScale(double scaleFactor, double verticalScale)
         else
             setSceneRect(0, 0, (m_projectDuration + 300), sceneRect().height());
     }
+    double verticalPos = mapToScene(QPoint(0, viewport()->height() / 2)).y();
     centerOn(QPointF(cursorPos(), verticalPos));
 }
 
@@ -4894,35 +5038,27 @@ void CustomTrackView::slotRefreshGuides()
 
 void CustomTrackView::drawBackground(QPainter * painter, const QRectF &rect)
 {
-    //kDebug() << "// DRAW BG: " << rect.width();
     painter->setClipRect(rect);
-    KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window);
     QPen pen1 = painter->pen();
-    pen1.setColor(scheme.shade(KColorScheme::DarkShade));
+    pen1.setColor(palette().dark().color());
     painter->setPen(pen1);
     double min = rect.left();
     double max = rect.right();
     painter->drawLine(QPointF(min, 0), QPointF(max, 0));
     int maxTrack = m_document->tracksCount();
-    QColor lockedColor = scheme.background(KColorScheme::NegativeBackground).color();
+    QColor lockedColor = palette().button().color();
     QColor audioColor = palette().alternateBase().color();
-    QColor base = scheme.background(KColorScheme::NormalBackground).color();
     for (int i = 0; i < maxTrack; i++) {
         TrackInfo info = m_document->trackInfoAt(maxTrack - i - 1);
         if (info.isLocked || info.type == AUDIOTRACK || i == m_selectedTrack) {
             const QRectF track(min, m_tracksHeight * i + 1, max - min, m_tracksHeight - 1);
             if (i == m_selectedTrack)
-                painter->fillRect(track, scheme.background(KColorScheme::ActiveBackground).color());
+                painter->fillRect(track, m_activeTrackBrush.brush(this));
             else
                 painter->fillRect(track, info.isLocked ? lockedColor : audioColor);
         }
         painter->drawLine(QPointF(min, m_tracksHeight *(i + 1)), QPointF(max, m_tracksHeight *(i + 1)));
     }
-    int lowerLimit = m_tracksHeight * maxTrack + 1;
-    if (height() > lowerLimit) {
-        const QRectF bg(min, lowerLimit, max - min, height() - lowerLimit);
-        painter->fillRect(bg, base);
-    }
 }
 
 bool CustomTrackView::findString(const QString &text)
@@ -5110,16 +5246,24 @@ void CustomTrackView::pasteClip()
         return;
     }
     QPoint position;
+    int track = -1;
+    GenTime pos = GenTime(-1);
     if (m_menuPosition.isNull()) {
         position = mapFromGlobal(QCursor::pos());
         if (!contentsRect().contains(position) || mapToScene(position).y() / m_tracksHeight > m_document->tracksCount()) {
-            emit displayMessage(i18n("Cannot paste selected clips"), ErrorMessage);
-            return;
+            track = m_selectedTrack;
+            pos = GenTime(m_cursorPos, m_document->fps());
+            /*emit displayMessage(i18n("Cannot paste selected clips"), ErrorMessage);
+            return;*/
         }
-    } else position = m_menuPosition;
+    } else {
+        position = m_menuPosition;
+    }
 
-    GenTime pos = GenTime((int)(mapToScene(position).x()), m_document->fps());
-    int track = (int)(mapToScene(position).y() / m_tracksHeight);
+    if (pos == GenTime(-1))
+        pos = GenTime((int)(mapToScene(position).x()), m_document->fps());
+    if (track == -1)
+        track = (int)(mapToScene(position).y() / m_tracksHeight);
 
     GenTime leftPos = m_copiedItems.at(0)->startPos();
     int lowerTrack = m_copiedItems.at(0)->track();
@@ -5343,7 +5487,7 @@ void CustomTrackView::slotUpdateAllThumbs()
     for (int i = 0; i < itemList.count(); i++) {
         if (itemList.at(i)->type() == AVWIDGET) {
             item = static_cast <ClipItem *>(itemList.at(i));
-            if (item->clipType() != COLOR && item->clipType() != AUDIO) {
+            if (item && item->isEnabled() && item->clipType() != COLOR && item->clipType() != AUDIO) {
                 // Check if we have a cached thumbnail
                 if (item->clipType() == IMAGE || item->clipType() == TEXT) {
                     QString thumb = thumbBase + item->baseClip()->getClipHash() + "_0.png";
@@ -5368,9 +5512,8 @@ void CustomTrackView::slotUpdateAllThumbs()
                         item->slotSetEndThumb(pix);
                     }
                 }
+                item->refreshClip(false);
             }
-            item->refreshClip(false);
-            //qApp->processEvents();
         }
     }
     viewport()->update();
@@ -6108,12 +6251,14 @@ void CustomTrackView::clearSelection()
 
 void CustomTrackView::updatePalette()
 {
+    m_activeTrackBrush = KStatefulBrush(KColorScheme::View, KColorScheme::ActiveBackground, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
     if (m_cursorLine) {
         QPen pen1 = QPen();
         pen1.setWidth(1);
         pen1.setColor(palette().text().color());
         m_cursorLine->setPen(pen1);
     }
+    emit tracksChanged();
 }
 
 void CustomTrackView::removeTipAnimation()
@@ -6217,3 +6362,94 @@ bool CustomTrackView::hasAudio(int track) const
     }
     return false;
 }
+
+void CustomTrackView::slotAddTrackEffect(const QDomElement effect, int ix)
+{
+    AddEffectCommand *command = new AddEffectCommand(this, m_document->tracksCount() - ix, GenTime(-1), effect, true);
+    m_commandStack->push(command);
+    setDocumentModified();
+}
+
+
+EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect)
+{
+    EffectsParameterList parameters;
+    parameters.addParam("tag", effect.attribute("tag"));
+    if (effect.hasAttribute("region")) parameters.addParam("region", effect.attribute("region"));
+    parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
+    parameters.addParam("id", effect.attribute("id"));
+    if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
+    if (effect.hasAttribute("disable")) parameters.addParam("disable", effect.attribute("disable"));
+    if (effect.hasAttribute("in")) parameters.addParam("in", effect.attribute("in"));
+    if (effect.hasAttribute("out")) parameters.addParam("out", effect.attribute("out"));
+
+    QDomNodeList params = effect.elementsByTagName("parameter");
+    for (int i = 0; i < params.count(); i++) {
+        QDomElement e = params.item(i).toElement();
+        //kDebug() << "/ / / /SENDING EFFECT PARAM: " << e.attribute("type") << ", NAME_ " << e.attribute("tag");
+        if (e.attribute("type") == "simplekeyframe") {
+
+            QStringList values = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
+            double factor = e.attribute("factor", "1").toDouble();
+            for (int j = 0; j < values.count(); j++) {
+                QString pos = values.at(j).section(':', 0, 0);
+                double val = values.at(j).section(':', 1, 1).toDouble() / factor;
+                values[j] = pos + "=" + QString::number(val);
+            }
+            // kDebug() << "/ / / /SENDING KEYFR:" << values;
+            parameters.addParam(e.attribute("name"), values.join(";"));
+            /*parameters.addParam(e.attribute("name"), e.attribute("keyframes").replace(":", "="));
+            parameters.addParam("max", e.attribute("max"));
+            parameters.addParam("min", e.attribute("min"));
+            parameters.addParam("factor", e.attribute("factor", "1"));*/
+        } else if (e.attribute("type") == "keyframe") {
+            kDebug() << "/ / / /SENDING KEYFR EFFECT TYPE";
+            parameters.addParam("keyframes", e.attribute("keyframes"));
+            parameters.addParam("max", e.attribute("max"));
+            parameters.addParam("min", e.attribute("min"));
+            parameters.addParam("factor", e.attribute("factor", "1"));
+            parameters.addParam("starttag", e.attribute("starttag", "start"));
+            parameters.addParam("endtag", e.attribute("endtag", "end"));
+        } else if (e.attribute("namedesc").contains(';')) {
+            QString format = e.attribute("format");
+            QStringList separators = format.split("%d", QString::SkipEmptyParts);
+            QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
+            QString neu;
+            QTextStream txtNeu(&neu);
+            if (values.size() > 0)
+                txtNeu << (int)values[0].toDouble();
+            for (int i = 0; i < separators.size() && i + 1 < values.size(); i++) {
+                txtNeu << separators[i];
+                txtNeu << (int)(values[i+1].toDouble());
+            }
+            parameters.addParam("start", neu);
+        } else {
+            if (e.attribute("factor", "1") != "1") {
+                double fact;
+                if (e.attribute("factor").startsWith('%')) {
+                    fact = ProfilesDialog::getStringEval(m_document->mltProfile(), e.attribute("factor"));
+                } else fact = e.attribute("factor", "1").toDouble();
+                parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / fact));
+            } else {
+                parameters.addParam(e.attribute("name"), e.attribute("value"));
+            }
+        }
+    }
+    return parameters;
+}
+
+void CustomTrackView::updatePanZoom(ClipItem* item, GenTime cutPos)
+{
+    QList <int> effects = item->updatePanZoom(m_document->width(), m_document->height(), cutPos.frames(m_document->fps()));
+    for (int i = 0; i < effects.count(); ++i) {
+        if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(item->effectAt(effects.at(i)))))
+            emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
+
+        // if effect is displayed, update the effect edit widget with new clip duration
+        /*if (item->isSelected() && effects.at(i) == item->selectedEffectIndex())
+            emit clipItemSelected(item, effects.at(i));*/
+    }
+    // update always, otherwise there might problems when resizing groups
+    if (effects.count() > 0)
+        emit clipItemSelected(item, item->selectedEffectIndex());
+}