]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
no ";" after Q_UNUSED
[kdenlive] / src / customtrackview.cpp
index 754ad483fc06696a959597a2b123460d46b7dc75..9bc72157c5a5cc3ee2777ff6b049875b0afe8e67 100644 (file)
@@ -67,7 +67,6 @@
 #include <KUrl>
 #include <KIcon>
 #include <KCursor>
-#include <KColorScheme>
 #include <KMessageBox>
 #include <KIO/NetAccess>
 
@@ -124,49 +123,51 @@ 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;
+    if (doc)
+        m_commandStack = doc->commandStack();
+    else
+        m_commandStack = NULL;
+
     setMouseTracking(true);
     setAcceptDrops(true);
     setFrameShape(QFrame::NoFrame);
     setLineWidth(0);
     //setCacheMode(QGraphicsView::CacheBackground);
-    //setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
+    setAutoFillBackground(false);
     setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
+    setContentsMargins(0, 0, 0, 0);
+
+    m_activeTrackBrush = KStatefulBrush(KColorScheme::View, KColorScheme::ActiveBackground, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
+
+    m_pixmapCache = new KPixmapCache("kdenlive-thumbs");
 
-    pixmapCache = new KPixmapCache("kdenlive-thumbs");
-    KdenliveSettings::setTrackheight(m_tracksHeight);
     m_animationTimer = new QTimeLine(800);
     m_animationTimer->setFrameRange(0, 5);
     m_animationTimer->setUpdateInterval(100);
     m_animationTimer->setLoopCount(0);
+
     m_tipColor = QColor(0, 192, 0, 200);
-    QColor border = QColor(255, 255, 255, 100);
-    m_tipPen.setColor(border);
+    m_tipPen.setColor(QColor(255, 255, 255, 100));
     m_tipPen.setWidth(3);
-    setContentsMargins(0, 0, 0, 0);
+
     const int maxHeight = m_tracksHeight * m_document->tracksCount();
     setSceneRect(0, 0, sceneRect().width(), maxHeight);
     verticalScrollBar()->setMaximum(maxHeight);
+    verticalScrollBar()->setTracking(true);
+    // repaint guides when using vertical scroll
+    connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(slotRefreshGuides()));
+
     m_cursorLine = projectscene->addLine(0, 0, 0, maxHeight);
     m_cursorLine->setZValue(1000);
-
     QPen pen1 = QPen();
     pen1.setWidth(1);
     pen1.setColor(palette().text().color());
     m_cursorLine->setPen(pen1);
     m_cursorLine->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
 
-    KIcon razorIcon("edit-cut");
-    m_razorCursor = QCursor(razorIcon.pixmap(22, 22));
-
-    KIcon spacerIcon("kdenlive-spacer-tool");
-    m_spacerCursor = QCursor(spacerIcon.pixmap(22, 22));
-    verticalScrollBar()->setTracking(true);
-    // Line below was supposed to scroll guides label with scrollbar, not implemented yet
-    //connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(slotRefreshGuides()));
     connect(&m_scrollTimer, SIGNAL(timeout()), this, SLOT(slotCheckMouseScrolling()));
     m_scrollTimer.setInterval(100);
     m_scrollTimer.setSingleShot(true);
@@ -174,6 +175,12 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscen
     connect(&m_thumbsTimer, SIGNAL(timeout()), this, SLOT(slotFetchNextThumbs()));
     m_thumbsTimer.setInterval(500);
     m_thumbsTimer.setSingleShot(true);
+
+    KIcon razorIcon("edit-cut");
+    m_razorCursor = QCursor(razorIcon.pixmap(22, 22));
+
+    KIcon spacerIcon("kdenlive-spacer-tool");
+    m_spacerCursor = QCursor(spacerIcon.pixmap(22, 22));
 }
 
 CustomTrackView::~CustomTrackView()
@@ -181,6 +188,8 @@ CustomTrackView::~CustomTrackView()
     qDeleteAll(m_guides);
     m_guides.clear();
     m_waitingThumbs.clear();
+    delete m_pixmapCache;
+    delete m_animationTimer;
 }
 
 //virtual
@@ -279,7 +288,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();
@@ -327,7 +336,7 @@ void CustomTrackView::slotFetchNextThumbs()
 {
     if (!m_waitingThumbs.isEmpty()) {
         ClipItem *item = m_waitingThumbs.takeFirst();
-        while ((item == NULL) && !m_waitingThumbs.isEmpty()) {
+        while (item == NULL && !m_waitingThumbs.isEmpty()) {
             item = m_waitingThumbs.takeFirst();
         }
         if (item) item->slotFetchThumbs();
@@ -366,6 +375,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
 {
     int pos = event->x();
     int mappedXPos = qMax((int)(mapToScene(event->pos()).x() + 0.5), 0);
+   
     double snappedPos = getSnapPointForPos(mappedXPos);
     emit mousePosition(mappedXPos);
 
@@ -394,22 +404,29 @@ 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()));
+                        parent->resizeStart((int)(snappedPos - m_dragItemInfo.startPos.frames(m_document->fps())));
                 } else {
                     m_dragItem->resizeStart((int)(snappedPos));
                 }
+                QString crop = m_document->timecode().getDisplayTimecode(m_dragItem->cropStart(), KdenliveSettings::frametimecode());
+                QString duration = m_document->timecode().getDisplayTimecode(m_dragItem->cropDuration(), KdenliveSettings::frametimecode());
+                QString offset = m_document->timecode().getDisplayTimecode(m_dragItem->cropStart() - m_dragItemInfo.cropStart, KdenliveSettings::frametimecode());
+                emit displayMessage(i18n("Crop from start:") + ' ' + crop + ' ' + i18n("Duration:") + ' ' + duration + ' ' + i18n("Offset:") + ' ' + offset, InformationMessage);
             } 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()));
+                        parent->resizeEnd((int)(snappedPos - m_dragItemInfo.endPos.frames(m_document->fps())));
                 } else {
                     m_dragItem->resizeEnd((int)(snappedPos));
                 }
+                QString duration = m_document->timecode().getDisplayTimecode(m_dragItem->cropDuration(), KdenliveSettings::frametimecode());
+                QString offset = m_document->timecode().getDisplayTimecode(m_dragItem->cropDuration() - m_dragItemInfo.cropDuration, KdenliveSettings::frametimecode());
+                emit displayMessage(i18n("Duration:") + ' ' + duration + ' ' + i18n("Offset:") + ' ' + offset, InformationMessage);
             } else if (m_operationMode == FADEIN && move) {
                 ((ClipItem*) m_dragItem)->setFadeIn((int)(mappedXPos - m_dragItem->startPos().frames(m_document->fps())));
             } else if (m_operationMode == FADEOUT && move) {
@@ -421,6 +438,8 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
                 double maxh = 100.0 / br.height();
                 pos = (br.bottom() - pos) * maxh;
                 m_dragItem->updateKeyFramePos(keyFramePos, pos);
+                QString position = m_document->timecode().getDisplayTimecodeFromFrames(m_dragItem->editedKeyFramePos(), KdenliveSettings::frametimecode());
+                emit displayMessage(position + " : " + QString::number(m_dragItem->editedKeyFrameValue()), InformationMessage);
             }
             removeTipAnimation();
             return;
@@ -578,11 +597,14 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
         }
         m_moveOpMode = opMode;
         setTipAnimation(clip, opMode, size);
+        ClipItem *ci = NULL;
+        if (item->type() == AVWIDGET)
+            ci = static_cast <ClipItem *>(item);
+        QString message;
         if (opMode == MOVE) {
             setCursor(Qt::OpenHandCursor);
-            if (item->type() == AVWIDGET) {
-                ClipItem *ci = static_cast <ClipItem *>(item);
-                QString message = ci->clipName() + i18n(":");
+            if (ci) {
+                message = ci->clipName() + i18n(":");
                 message.append(i18n(" Position:") + m_document->timecode().getDisplayTimecode(ci->info().startPos, KdenliveSettings::frametimecode()));
                 message.append(i18n(" Duration:") + m_document->timecode().getDisplayTimecode(ci->cropDuration(),  KdenliveSettings::frametimecode()));
                 if (clip->parentItem() && clip->parentItem()->type() == GROUPWIDGET) {
@@ -597,26 +619,40 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
                         message.append(i18n(" Selection duration:") + m_document->timecode().getDisplayTimecode(parent2->duration(), KdenliveSettings::frametimecode()));
                     }
                 }
-                emit displayMessage(message, InformationMessage);
             }
         } else if (opMode == RESIZESTART) {
             setCursor(KCursor("left_side", Qt::SizeHorCursor));
+            if (ci)
+                message = i18n("Crop from start: ") + m_document->timecode().getDisplayTimecode(ci->cropStart(), KdenliveSettings::frametimecode());
             if (item->type() == AVWIDGET && item->parentItem() && item->parentItem() != m_selectionGroup)
-                emit displayMessage(i18n("Use Ctrl to resize only current item, otherwise all items in this group will be resized at once."), InformationMessage);
+                message.append(i18n("Use Ctrl to resize only current item, otherwise all items in this group will be resized at once."));
         } else if (opMode == RESIZEEND) {
             setCursor(KCursor("right_side", Qt::SizeHorCursor));
+            if (ci)
+                message = i18n("Duration: ") + m_document->timecode().getDisplayTimecode(ci->cropDuration(), KdenliveSettings::frametimecode());
             if (item->type() == AVWIDGET && item->parentItem() && item->parentItem() != m_selectionGroup)
-                emit displayMessage(i18n("Use Ctrl to resize only current item, otherwise all items in this group will be resized at once."), InformationMessage);
+                message.append(i18n("Use Ctrl to resize only current item, otherwise all items in this group will be resized at once."));
         } else if (opMode == FADEIN || opMode == FADEOUT) {
             setCursor(Qt::PointingHandCursor);
-            emit displayMessage(i18n("Drag to add or resize a fade effect."), InformationMessage);
+            if (ci && opMode == FADEIN && ci->fadeIn()) {
+                message = i18n("Fade in duration: ");
+                message.append(m_document->timecode().getDisplayTimecodeFromFrames(ci->fadeIn(), KdenliveSettings::frametimecode()));
+            } else if (ci && opMode == FADEOUT && ci->fadeOut()) {
+                message = i18n("Fade out duration: ");
+                message.append(m_document->timecode().getDisplayTimecodeFromFrames(ci->fadeOut(), KdenliveSettings::frametimecode()));
+            } else {
+                message = i18n("Drag to add or resize a fade effect.");
+            }
         } else if (opMode == TRANSITIONSTART || opMode == TRANSITIONEND) {
             setCursor(Qt::PointingHandCursor);
-            emit displayMessage(i18n("Click to add a transition."), InformationMessage);
+            message = i18n("Click to add a transition.");
         } else if (opMode == KEYFRAME) {
             setCursor(Qt::PointingHandCursor);
             emit displayMessage(i18n("Move keyframe above or below clip to remove it, double click to add a new one."), InformationMessage);
         }
+
+        if (!message.isEmpty())
+            emit displayMessage(message, InformationMessage);
     } // no clip under mouse
     else if (m_tool == RAZORTOOL) {
         event->accept();
@@ -909,7 +945,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         } else resetSelectionGroup();
         dragGroup = NULL;
         if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET) {
-            //kDebug()<<"// KLIK FOUND GRP: "<<m_dragItem->sceneBoundingRect();
             dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
         }
         bool selected = !m_dragItem->isSelected();
@@ -938,6 +973,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) {
@@ -1101,6 +1137,7 @@ void CustomTrackView::resetSelectionGroup(bool selectItems)
                 children.at(i)->setSelected(selectItems);
             }
         }
+
         m_selectionGroup = NULL;
         KdenliveSettings::setSnaptopoints(snap);
     }
@@ -1282,6 +1319,7 @@ void CustomTrackView::editItemDuration()
                 clipInfo.endPos = clipInfo.startPos + d.duration();
                 clipInfo.track = item->track();
                 MoveTransitionCommand *command = new MoveTransitionCommand(this, startInfo, clipInfo, true);
+                updateTrackDuration(clipInfo.track, command);
                 m_commandStack->push(command);
             } else {
                 // move and resize clip
@@ -1306,6 +1344,7 @@ void CustomTrackView::editItemDuration()
                     clipInfo.cropStart = d.cropStart();
                     new ResizeClipCommand(this, startInfo, clipInfo, true, false, moveCommand);
                 }
+                updateTrackDuration(clipInfo.track, moveCommand);
                 m_commandStack->push(moveCommand);
             }
         }
@@ -1390,6 +1429,7 @@ void CustomTrackView::insertClipCut(DocClipBase *clip, int in, int out)
     }
 
     AddTimelineClipCommand *command = new AddTimelineClipCommand(this, clip->toXML(), clip->getId(), pasteInfo, EffectsList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, true, false);
+    updateTrackDuration(pasteInfo.track, command);
     m_commandStack->push(command);
 
     selectClip(true, false);
@@ -1410,6 +1450,10 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos)
             kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << list.at(0);
             return false;
         }
+        if (clip->producer() == NULL) {
+            emit displayMessage(i18n("Clip not ready"), ErrorMessage);
+            return false;
+        }
         QPointF framePos = mapToScene(pos);
         ItemInfo info;
         info.startPos = GenTime();
@@ -1461,6 +1505,10 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos)
                 kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << ids.at(i);
                 return false;
             }
+            if (clip->producer() == NULL) {
+                emit displayMessage(i18n("Clip not ready"), ErrorMessage);
+                return false;
+            }
             ItemInfo info;
             info.startPos = start;
             info.cropDuration = clip->duration();
@@ -1551,8 +1599,10 @@ void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect)
 {
     if (pos < GenTime()) {
         // Add track effect
+        clearSelection();
         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;
     }
@@ -1585,8 +1635,11 @@ 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);
+        if (m_document->renderer()->mltRemoveTrackEffect(track, index, true)) {
+           m_document->removeTrackEffect(track - 1, effect);
+       }
+       else emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
+        emit updateTrackEffectState(track - 1);
         emit showTrackEffects(track, m_document->trackInfoAt(track - 1));
         return;
     }
@@ -1731,6 +1784,21 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
     if (effectCommand->childCount() > 0) {
         m_commandStack->push(effectCommand);
         setDocumentModified();
+       if (effectCommand->childCount() == 1) {
+           // Display newly added clip effect
+           for (int i = 0; i < itemList.count(); i++) {
+               if (itemList.at(i)->type() == AVWIDGET) {
+                   ClipItem *clip = static_cast<ClipItem *>(itemList.at(i));
+                   if (!clip->isSelected()) {
+                       clearSelection();
+                       clip->setSelected(true);
+                   }
+                   clip->setSelectedEffect(clip->effectsCount() - 1);
+                   emit clipItemSelected(clip, clip->effectsCount() - 1);
+                   break;
+               }
+           }
+       }
     } else delete effectCommand;
 }
 
@@ -1773,8 +1841,11 @@ void CustomTrackView::slotDeleteEffect(ClipItem *clip, int track, QDomElement ef
                 }
             }
         }
-        if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
-        else delete delCommand;
+        if (delCommand->childCount() > 0)
+            m_commandStack->push(delCommand);
+        else
+            delete delCommand;
+        setDocumentModified();
         return;
     }
     AddEffectCommand *command = new AddEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effect, false);
@@ -1789,7 +1860,7 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE
         return;
     }
     QDomElement effect = insertedEffect.cloneNode().toElement();
-    kDebug() << "// update effect ix: " << effect.attribute("kdenlive_ix");
+    //kDebug() << "// update effect ix: " << effect.attribute("kdenlive_ix")<<", TRACK: "<<track;
     if (pos < GenTime()) {
         // editing a track effect
         EffectsParameterList effectParams = getEffectArgs(effect);
@@ -1805,6 +1876,7 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE
         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;
 
@@ -1956,8 +2028,6 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo
             return NULL;
         }
 
-        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);
         int cutPos = (int) cutTime.frames(m_document->fps());
         ItemInfo newPos;
@@ -1970,29 +2040,49 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo
         bool snap = KdenliveSettings::snaptopoints();
         KdenliveSettings::setSnaptopoints(false);
         ClipItem *dup = item->clone(newPos);
-        // remove unwanted effects (fade in) from 2nd part of cutted clip
+
+        // remove unwanted effects
+        // fade in from 2nd part of the clip
         int ix = dup->hasEffect(QString(), "fadein");
         if (ix != -1) {
-            QDomElement oldeffect = item->effectAt(ix);
+            QDomElement oldeffect = dup->effectAt(ix);
             dup->deleteEffect(oldeffect.attribute("kdenlive_ix"));
         }
         ix = dup->hasEffect(QString(), "fade_from_black");
         if (ix != -1) {
-            QDomElement oldeffect = item->effectAt(ix);
+            QDomElement oldeffect = dup->effectAt(ix);
             dup->deleteEffect(oldeffect.attribute("kdenlive_ix"));
         }
+        // fade out from 1st part of the clip
+        ix = item->hasEffect(QString(), "fadeout");
+        if (ix != -1) {
+            QDomElement oldeffect = item->effectAt(ix);
+            item->deleteEffect(oldeffect.attribute("kdenlive_ix"));
+        }
+        ix = item->hasEffect(QString(), "fade_to_black");
+        if (ix != -1) {
+            QDomElement oldeffect = item->effectAt(ix);
+            item->deleteEffect(oldeffect.attribute("kdenlive_ix"));
+        }
+
+
         item->resizeEnd(cutPos);
         scene()->addItem(dup);
         if (item->checkKeyFrames())
             slotRefreshEffects(item);
         if (dup->checkKeyFrames())
             slotRefreshEffects(dup);
+
+        updatePanZoom(item);
+        updatePanZoom(dup, cutTime - item->startPos());
+
         item->baseClip()->addReference();
         m_document->updateClip(item->baseClip()->getId());
         setDocumentModified();
         KdenliveSettings::setSnaptopoints(snap);
+        if (execute && item->isSelected())
+            emit clipItemSelected(item);
         return dup;
-        //kDebug() << "/////////  CUTTING CLIP RESULT: (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), DUP: (" << dup->startPos().frames(25) << "-" << dup->endPos().frames(25) << ")" << ", CUT: " << cutTime.frames(25);
     } else {
         // uncut clip
 
@@ -2009,30 +2099,49 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo
             return NULL;
         }
 
-        /*kDebug() << "// UNCUTTING CLIPS: ITEM 1 (" << item->startPos().frames(25) << "x" << item->endPos().frames(25) << ")";
-        kDebug() << "// UNCUTTING CLIPS: ITEM 2 (" << dup->startPos().frames(25) << "x" << dup->endPos().frames(25) << ")";
-        kDebug() << "// UNCUTTING CLIPS, INFO (" << info.startPos.frames(25) << "x" << info.endPos.frames(25) << ") , CUT: " << cutTime.frames(25);;*/
-        //deleteClip(dup->info());
-
         bool snap = KdenliveSettings::snaptopoints();
         KdenliveSettings::setSnaptopoints(false);
 
-        if (dup->isSelected()) emit clipItemSelected(NULL);
+        // join fade effects again
+        int ix = dup->hasEffect(QString(), "fadeout");
+        if (ix != -1) {
+            QDomElement effect = dup->effectAt(ix);
+            item->addEffect(effect);
+        }
+        ix = dup->hasEffect(QString(), "fade_to_black");
+        if (ix != -1) {
+            QDomElement effect = dup->effectAt(ix);
+            item->addEffect(effect);
+        }
+
+        m_waitingThumbs.removeAll(dup);
+        bool selected = item->isSelected();
+        if (dup->isSelected()) {
+            selected = true;
+            item->setSelected(true);
+            emit clipItemSelected(NULL);
+        }
         dup->baseClip()->removeReference();
         m_document->updateClip(dup->baseClip()->getId());
         scene()->removeItem(dup);
         delete dup;
+        dup = NULL;
 
         ItemInfo clipinfo = item->info();
         clipinfo.track = m_document->tracksCount() - clipinfo.track;
         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);
         }
         KdenliveSettings::setSnaptopoints(snap);
+        if (execute && selected)
+            emit clipItemSelected(item);
         return item;
     }
     //QTimer::singleShot(3000, this, SLOT(slotEnableRefresh()));
@@ -2185,6 +2294,7 @@ void CustomTrackView::slotTransitionUpdated(Transition *tr, QDomElement old)
         return;
     }
     EditTransitionCommand *command = new EditTransitionCommand(this, tr->track(), tr->startPos(), old, xml, false);
+    updateTrackDuration(tr->track(), command);
     m_commandStack->push(command);
     setDocumentModified();
 }
@@ -2196,8 +2306,10 @@ void CustomTrackView::updateTransition(int track, GenTime pos, QDomElement oldTr
         kWarning() << "Unable to find transition at pos :" << pos.frames(m_document->fps()) << ", ON track: " << track;
         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);
@@ -2288,6 +2400,7 @@ void CustomTrackView::dropEvent(QDropEvent * event)
             adjustTimelineClips(m_scene->editMode(), item, ItemInfo(), addCommand);
 
             new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, false, false, addCommand);
+            updateTrackDuration(info.track, addCommand);
 
             if (item->baseClip()->isTransparent() && getTransitionItemAtStart(info.startPos, info.track) == NULL) {
                 // add transparency transition
@@ -2325,8 +2438,12 @@ 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));
+        if (items.count() > 1) {
+            groupSelectedItems(true);
+        } else if (items.count() == 1) {
+            m_dragItem = static_cast <AbstractClipItem *>(items.at(0));
+            emit clipItemSelected((ClipItem*)m_dragItem);
+        }
         event->setDropAction(Qt::MoveAction);
         event->accept();
     } else QGraphicsView::dropEvent(event);
@@ -2374,6 +2491,7 @@ void CustomTrackView::adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInf
                     }
                 } else if (clip->endPos() <= info.endPos) {
                     new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), clip->info(), clip->effectList(), false, false, false, true, command);
+                    m_waitingThumbs.removeAll(clip);
                     scene()->removeItem(clip);
                     delete clip;
                     clip = NULL;
@@ -2532,10 +2650,7 @@ void CustomTrackView::addTrack(TrackInfo type, int ix)
                 if (clip->speed() != 1.0) continue;
                 // We add a move clip command so that we get the correct producer for new track number
                 if (clip->clipType() == AV || clip->clipType() == AUDIO) {
-                    Mlt::Producer *prod;
-                    if (clip->isAudioOnly()) prod = clip->baseClip()->audioProducer(clipinfo.track);
-                    else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer();
-                    else prod = clip->baseClip()->producer(clipinfo.track);
+                    Mlt::Producer *prod = clip->getProducer(clipinfo.track);
                     if (m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod) == false) {
                         // problem updating clip
                         emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", clipinfo.startPos.frames(m_document->fps()), clipinfo.track), ErrorMessage);
@@ -2558,12 +2673,14 @@ 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();
     //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged()));
     //setFixedHeight(50 * m_tracksCount);
+
+    updateTrackNames(ix, true);
 }
 
 void CustomTrackView::removeTrack(int ix)
@@ -2605,10 +2722,7 @@ void CustomTrackView::removeTrack(int ix)
             ItemInfo clipinfo = clip->info();
             // We add a move clip command so that we get the correct producer for new track number
             if (clip->clipType() == AV || clip->clipType() == AUDIO) {
-                Mlt::Producer *prod;
-                if (clip->isAudioOnly()) prod = clip->baseClip()->audioProducer(clipinfo.track);
-                else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer();
-                else prod = clip->baseClip()->producer(clipinfo.track);
+                Mlt::Producer *prod = clip->getProducer(clipinfo.track);
                 if (!m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod)) {
                     emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", clipinfo.startPos.frames(m_document->fps()), clipinfo.track), ErrorMessage);
                 }
@@ -2631,12 +2745,13 @@ 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);
     viewport()->update();
-    emit tracksChanged();
+
+    updateTrackNames(ix, false);
     //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged()));
 }
 
@@ -2645,10 +2760,11 @@ 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()));
     viewport()->update();
+    emit trackHeightChanged();
 }
 
 void CustomTrackView::slotSwitchTrackAudio(int ix)
@@ -2670,24 +2786,71 @@ 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);
 
     for (int i = 0; i < selection.count(); i++) {
-        if (selection.at(i)->type() != AVWIDGET && selection.at(i)->type() != TRANSITIONWIDGET) continue;
-        if (selection.at(i)->isSelected()) {
-            if (selection.at(i)->type() == AVWIDGET) emit clipItemSelected(NULL);
-            else emit transitionItemSelected(NULL);
+        if (selection.at(i)->type() == GROUPWIDGET && (AbstractGroupItem *)selection.at(i) != m_selectionGroup) {
+            if (selection.at(i)->parentItem() && m_selectionGroup) {
+                selection.removeAll((QGraphicsItem*)m_selectionGroup);
+                resetSelectionGroup();
+            }
+
+            bool changeGroupLock = true;
+            bool hasClipOnTrack = false;
+            QList <QGraphicsItem *> children =  selection.at(i)->childItems();
+            for (int j = 0; j < children.count(); ++j) {
+                if (children.at(j)->isSelected()) {
+                    if (children.at(j)->type() == AVWIDGET)
+                        emit clipItemSelected(NULL);
+                    else if (children.at(j)->type() == TRANSITIONWIDGET)
+                        emit transitionItemSelected(NULL);
+                    else
+                        continue;
+                }
+
+                AbstractClipItem * child = static_cast <AbstractClipItem *>(children.at(j));
+                if (child == m_dragItem)
+                    m_dragItem = NULL;
+
+                // only unlock group, if it is not locked by another track too
+                if (!lock && child->track() != ix && m_document->trackInfoAt(m_document->tracksCount() - child->track() - 1).isLocked)
+                    changeGroupLock = false;
+                
+                // only (un-)lock if at least one clip is on the track
+                if (child->track() == ix)
+                    hasClipOnTrack = true;
+            }
+            if (changeGroupLock && hasClipOnTrack)
+                ((AbstractGroupItem*)selection.at(i))->setItemLocked(lock);
+        } else if((selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET)) {
+            if (selection.at(i)->parentItem()) {
+                if (selection.at(i)->parentItem() == m_selectionGroup) {
+                    selection.removeAll((QGraphicsItem*)m_selectionGroup);
+                    resetSelectionGroup();
+                } else {
+                    // groups are handled separately
+                    continue;
+                }
+            }
+
+            if (selection.at(i)->isSelected()) {
+                if (selection.at(i)->type() == AVWIDGET)
+                    emit clipItemSelected(NULL);
+                else
+                    emit transitionItemSelected(NULL);
+            }
+            clip = static_cast <AbstractClipItem *>(selection.at(i));
+            clip->setItemLocked(lock);
+            if (clip == m_dragItem)
+                m_dragItem = NULL;
         }
-        clip = static_cast <AbstractClipItem *>(selection.at(i));
-        clip->setItemLocked(lock);
-        if (clip == m_dragItem)
-            m_dragItem = NULL;
     }
     kDebug() << "NEXT TRK STATE: " << m_document->trackInfoAt(tracknumber).isLocked;
     viewport()->update();
@@ -2779,6 +2942,7 @@ void CustomTrackView::slotRemoveSpace()
     }
 
     InsertSpaceCommand *command = new InsertSpaceCommand(this, clipsToMove, transitionsToMove, track, GenTime(-length, m_document->fps()), true);
+    updateTrackDuration(track, command);
     m_commandStack->push(command);
 }
 
@@ -2798,7 +2962,7 @@ void CustomTrackView::slotInsertSpace()
     track = d.selectedTrack();
 
     QList<QGraphicsItem *> items;
-    if (track > 0) {
+    if (track >= 0) {
         if (m_document->isTrackLocked(m_document->tracksCount() - track - 1)) {
             emit displayMessage(i18n("Cannot insert space in a locked track"), ErrorMessage);
             return;
@@ -2837,6 +3001,7 @@ void CustomTrackView::slotInsertSpace()
 
     if (!clipsToMove.isEmpty() || !transitionsToMove.isEmpty()) {
         InsertSpaceCommand *command = new InsertSpaceCommand(this, clipsToMove, transitionsToMove, track, spaceDuration, true);
+        updateTrackDuration(track, command);
         m_commandStack->push(command);
     }
 }
@@ -2931,8 +3096,12 @@ void CustomTrackView::deleteClip(const QString &clipId)
         }
     }
     deleteCommand->setText(i18np("Delete timeline clip", "Delete timeline clips", count));
-    if (count == 0) delete deleteCommand;
-    else m_commandStack->push(deleteCommand);
+    if (count == 0) {
+        delete deleteCommand;
+    } else {
+        updateTrackDuration(-1, deleteCommand);
+        m_commandStack->push(deleteCommand);
+    }
 }
 
 void CustomTrackView::setCursorPos(int pos, bool seek)
@@ -2940,7 +3109,7 @@ void CustomTrackView::setCursorPos(int pos, bool seek)
     if (pos == m_cursorPos) return;
     emit cursorMoved((int)(m_cursorPos), (int)(pos));
     m_cursorPos = pos;
-    if (seek) m_document->renderer()->seek(GenTime(m_cursorPos, m_document->fps()));
+    if (seek) m_document->renderer()->seek(m_cursorPos);
     else if (m_autoScroll) checkScrolling();
     m_cursorLine->setPos(m_cursorPos, 0);
 }
@@ -2961,7 +3130,7 @@ void CustomTrackView::moveCursorPos(int delta)
     emit cursorMoved((int)(m_cursorPos), (int)((m_cursorPos + delta)));
     m_cursorPos += delta;
     m_cursorLine->setPos(m_cursorPos, 0);
-    m_document->renderer()->seek(GenTime(m_cursorPos, m_document->fps()));
+    m_document->renderer()->seek(m_cursorPos);
 }
 
 void CustomTrackView::initCursorPos(int pos)
@@ -3052,6 +3221,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             }
             if (!clipsToMove.isEmpty() || !transitionsToMove.isEmpty()) {
                 InsertSpaceCommand *command = new InsertSpaceCommand(this, clipsToMove, transitionsToMove, track, timeOffset, false);
+                updateTrackDuration(track, command);
                 m_commandStack->push(command);
                 if (track != -1) track = m_document->tracksCount() - track;
                 kDebug() << "SPACER TRACK:" << track;
@@ -3062,7 +3232,6 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         resetSelectionGroup(false);
         m_operationMode = NONE;
     } else if (m_operationMode == RUBBERSELECTION) {
-        //kDebug() << "// END RUBBER SELECT";
         resetSelectionGroup();
         groupSelectedItems();
         m_operationMode = NONE;
@@ -3081,10 +3250,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             // we are moving one clip, easy
             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(info.track);
-                else if (item->isVideoOnly()) prod = item->baseClip()->videoProducer();
-                else prod = item->baseClip()->producer(info.track);
+                Mlt::Producer *prod = item->getProducer(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) {
@@ -3195,6 +3361,9 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                             }
                         }
                     }
+                    updateTrackDuration(info.track, moveCommand);
+                    if (m_dragItemInfo.track != info.track)
+                        updateTrackDuration(m_dragItemInfo.track, moveCommand);
                     m_commandStack->push(moveCommand);
                     //checkTrackSequence(m_dragItem->track());
                 } else {
@@ -3218,6 +3387,9 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                     moveCommand->setText(i18n("Move transition"));
                     adjustTimelineTransitions(m_scene->editMode(), transition, moveCommand);
                     new MoveTransitionCommand(this, m_dragItemInfo, info, false, moveCommand);
+                    updateTrackDuration(info.track, moveCommand);
+                    if (m_dragItemInfo.track != info.track)
+                        updateTrackDuration(m_dragItemInfo.track, moveCommand);
                     m_commandStack->push(moveCommand);
                     setDocumentModified();
                 }
@@ -3237,7 +3409,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
 
             GenTime timeOffset = GenTime(m_dragItem->scenePos().x(), m_document->fps()) - m_dragItemInfo.startPos;
             const int trackOffset = (int)(m_dragItem->scenePos().y() / m_tracksHeight) - m_dragItemInfo.track;
-            //kDebug() << "// MOVED SEVERAL CLIPS" << timeOffset.frames(25);
+
             QUndoCommand *moveGroup = new QUndoCommand();
             moveGroup->setText(i18n("Move group"));
             if (timeOffset != GenTime() || trackOffset != 0) {
@@ -3285,15 +3457,8 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                     if (item->type() == AVWIDGET) {
                         ClipItem *clip = static_cast <ClipItem*>(item);
                         info.track = m_document->tracksCount() - info.track;
-                        Mlt::Producer *prod;
                         adjustTimelineClips(m_scene->editMode(), clip, ItemInfo(), moveGroup);
-                        if (clip->isAudioOnly())
-                            prod = clip->baseClip()->audioProducer(info.track);
-                        else if (clip->isVideoOnly())
-                            prod = clip->baseClip()->videoProducer();
-                        else
-                            prod = clip->baseClip()->producer(info.track);
-                        m_document->renderer()->mltInsertClip(info, clip->xml(), prod, m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT);
+                        m_document->renderer()->mltInsertClip(info, clip->xml(), clip->getProducer(info.track), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT);
                         for (int i = 0; i < clip->effectsCount(); i++) {
                             m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effectAt(i)), false);
                         }
@@ -3309,6 +3474,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                     }
                 }
                 new MoveGroupCommand(this, clipsToMove, transitionsToMove, timeOffset, trackOffset, false, moveGroup);
+                updateTrackDuration(-1, moveGroup);
                 m_commandStack->push(moveGroup);
 
                 //QPointF top = group->sceneBoundingRect().topLeft();
@@ -3334,6 +3500,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                                 items.at(i)->parentItem()->setSelected(true);
                         }
                     }
+                    resetSelectionGroup();
                     groupSelectedItems();
                 } else {
                     rebuildGroup((AbstractGroupItem *)group);
@@ -3344,7 +3511,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();
@@ -3368,7 +3535,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();
@@ -3385,6 +3552,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                         ++itemcount;
                     }
                 }
+                updateTrackDuration(-1, resizeCommand);
                 m_commandStack->push(resizeCommand);
             }
         } else {
@@ -3492,7 +3660,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         int start = item->cropStart().frames(m_document->fps());
         int end = (item->cropStart() + item->cropDuration()).frames(m_document->fps()) - 1;
 
-        if ((val < -50 || val > 150) && item->editedKeyFramePos() != start && item->editedKeyFramePos() != end) {
+        if ((val < -50 || val > 150) && item->editedKeyFramePos() != start && item->editedKeyFramePos() != end && item->keyFrameNumber() > 1) {
             //delete keyframe
             item->movedKeyframe(item->getEffectAt(item->selectedEffectIndex()), item->selectedKeyFramePos(), -1, 0);
         } else {
@@ -3534,6 +3702,7 @@ void CustomTrackView::deleteClip(ItemInfo info, bool refresh)
         emit displayMessage(i18n("Error removing clip at %1 on track %2", m_document->timecode().getTimecodeFromFrames(info.startPos.frames(m_document->fps())), info.track), ErrorMessage);
         return;
     }
+    m_waitingThumbs.removeAll(item);
     if (item->isSelected()) emit clipItemSelected(NULL);
     item->baseClip()->removeReference();
     m_document->updateClip(item->baseClip()->getId());
@@ -3547,8 +3716,9 @@ void CustomTrackView::deleteClip(ItemInfo info, bool refresh)
             delete tr;
         }
     }*/
-    m_waitingThumbs.removeAll(item);
+
     if (m_dragItem == item) m_dragItem = NULL;
+
 #if QT_VERSION >= 0x040600
     // animate item deletion
     item->closeAnimation();
@@ -3636,6 +3806,7 @@ void CustomTrackView::deleteSelectedClips()
     else if (transitionCount > 0 && groupCount == 0 && clipCount == 0)
         deleteSelected->setText(i18np("Delete selected transition", "Delete selected transitions", transitionCount));
     else deleteSelected->setText(i18n("Delete selected items"));
+    updateTrackDuration(-1, deleteSelected);
     m_commandStack->push(deleteSelected);
 }
 
@@ -3670,7 +3841,9 @@ void CustomTrackView::changeClipSpeed()
 
 void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, const double speed, const double oldspeed, int strobe, const QString &id)
 {
-    DocClipBase *baseclip = m_document->clipManager()->getClipById(id);
+    Q_UNUSED(id)
+    //DocClipBase *baseclip = m_document->clipManager()->getClipById(id);
+
     ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
     if (!item) {
         kDebug() << "ERROR: Cannot find clip for speed change";
@@ -3678,22 +3851,17 @@ void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependant
         return;
     }
     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());
+    int endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, item->getProducer(item->track(), false));
     if (endPos >= 0) {
         item->setSpeed(speed, strobe);
         item->updateRectGeometry();
-        if (item->cropDuration().frames(m_document->fps()) != endPos) {
+        if (item->cropDuration().frames(m_document->fps()) != endPos)
             item->resizeEnd((int) info.startPos.frames(m_document->fps()) + endPos - 1);
-        }
         updatePositionEffects(item, info);
         setDocumentModified();
-    } else emit displayMessage(i18n("Invalid clip"), ErrorMessage);
+    } else {
+        emit displayMessage(i18n("Invalid clip"), ErrorMessage);
+    }
 }
 
 void CustomTrackView::cutSelectedClips()
@@ -3874,7 +4042,6 @@ void CustomTrackView::doGroupClips(QList <ItemInfo> clipInfos, QList <ItemInfo>
             clip->setSelected(true);
         }
     }
-
     groupSelectedItems(false, true);
     setDocumentModified();
 }
@@ -3920,17 +4087,15 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i
     baseclip->addReference();
     m_document->updateClip(baseclip->getId());
     info.track = m_document->tracksCount() - info.track;
-    Mlt::Producer *prod;
-    if (item->isAudioOnly()) prod = baseclip->audioProducer(info.track);
-    else if (item->isVideoOnly()) prod = baseclip->videoProducer();
-    else prod = baseclip->producer(info.track);
-    m_document->renderer()->mltInsertClip(info, xml, prod, overwrite, push);
+    m_document->renderer()->mltInsertClip(info, xml, item->getProducer(info.track), overwrite, push);
     for (int i = 0; i < item->effectsCount(); i++) {
         m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(item->effectAt(i)), false);
     }
     setDocumentModified();
-    if (refresh) m_document->renderer()->doRefresh();
-    if (!baseclip->isPlaceHolder()) m_waitingThumbs.append(item);
+    if (refresh)
+        m_document->renderer()->doRefresh();
+    if (!baseclip->isPlaceHolder())
+        m_waitingThumbs.append(item);
     m_thumbsTimer.start();
 }
 
@@ -3944,11 +4109,10 @@ void CustomTrackView::slotUpdateClip(const QString &clipId, bool reload)
             if (clip->clipProducer() == clipId) {
                 ItemInfo info = clip->info();
                 info.track = m_document->tracksCount() - clip->track();
-                if (reload && !m_document->renderer()->mltUpdateClip(info, clip->xml(), clip->baseClip()->producer())) {
+                if (reload && !m_document->renderer()->mltUpdateClip(info, clip->xml(), clip->baseClip()->producer(info.track))) {
                     emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", info.startPos.frames(m_document->fps()), info.track), ErrorMessage);
                 }
-                clip->refreshClip(true);
-                clip->update();
+                clip->refreshClip(true, true);
             }
         }
     }
@@ -4067,10 +4231,7 @@ void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end, bool re
         kDebug() << "----------------  ERROR, CANNOT find clip to move at.. ";
         return;
     }
-    Mlt::Producer *prod;
-    if (item->isAudioOnly()) prod = item->baseClip()->audioProducer(end.track);
-    else if (item->isVideoOnly()) prod = item->baseClip()->videoProducer();
-    else prod = item->baseClip()->producer(end.track);
+    Mlt::Producer *prod = item->getProducer(end.track);
 
     bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - start.track), (int)(m_document->tracksCount() - end.track), (int) start.startPos.frames(m_document->fps()), (int)end.startPos.frames(m_document->fps()), prod);
     if (success) {
@@ -4102,14 +4263,11 @@ void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end, bool re
         emit displayMessage(i18n("Cannot move clip to position %1", m_document->timecode().getTimecodeFromFrames(end.startPos.frames(m_document->fps()))), ErrorMessage);
     }
     if (refresh) m_document->renderer()->doRefresh();
-    //kDebug() << " // MOVED CLIP TO: " << end.startPos.frames(25) << ", ITEM START: " << item->startPos().frames(25);
 }
 
 void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> startTransition, const GenTime offset, const int trackOffset, bool reverseMove)
 {
     // Group Items
-    /*kDebug() << "//GRP MOVE, REVERS:" << reverseMove;
-    kDebug() << "// GROUP MOV; OFFSET: " << offset.frames(25) << ", TK OFF: " << trackOffset;*/
     resetSelectionGroup();
     m_scene->clearSelection();
 
@@ -4122,7 +4280,6 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
             startClip[i].startPos = startClip.at(i).startPos - offset;
             startClip[i].track = startClip.at(i).track - trackOffset;
         }
-        //kDebug()<<"//LKING FR CLIP AT:"<<startClip.at(i).startPos.frames(25)<<", TK:"<<startClip.at(i).track;
         ClipItem *clip = getClipItemAt(startClip.at(i).startPos, startClip.at(i).track);
         if (clip) {
             clip->setItemLocked(false);
@@ -4194,14 +4351,7 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
             if (item->type() == AVWIDGET) {
                 ClipItem *clip = static_cast <ClipItem*>(item);
                 info.track = m_document->tracksCount() - info.track;
-                Mlt::Producer *prod;
-                if (clip->isAudioOnly())
-                    prod = clip->baseClip()->audioProducer(info.track);
-                else if (clip->isVideoOnly())
-                    prod = clip->baseClip()->videoProducer();
-                else
-                    prod = clip->baseClip()->producer(info.track);
-                m_document->renderer()->mltInsertClip(info, clip->xml(), prod);
+                m_document->renderer()->mltInsertClip(info, clip->xml(), clip->getProducer(info.track));
                 for (int i = 0; i < clip->effectsCount(); i++) {
                     m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effectAt(i)), false);
                 }
@@ -4240,10 +4390,10 @@ void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end, b
         kDebug() << "----------------  ERROR, CANNOT find transition to move... ";// << startPos.x() * m_scale * FRAME_SIZE + 1 << ", " << startPos.y() * m_tracksHeight + m_tracksHeight / 2;
         return;
     }
-    //kDebug() << "----------------  Move TRANSITION FROM: " << startPos.x() << ", END:" << endPos.x() << ",TRACKS: " << oldtrack << " TO " << newtrack;
+
     bool snap = KdenliveSettings::snaptopoints();
     KdenliveSettings::setSnaptopoints(false);
-    //kDebug()<<"///  RESIZE TRANS START: ("<< startPos.x()<<"x"<< startPos.y()<<") / ("<<endPos.x()<<"x"<< endPos.y()<<")";
+
     if (end.endPos - end.startPos == start.endPos - start.startPos) {
         // Transition was moved
         item->setPos((int) end.startPos.frames(m_document->fps()), (end.track) * m_tracksHeight + 1);
@@ -4297,6 +4447,7 @@ void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end, bool
 
     bool snap = KdenliveSettings::snaptopoints();
     KdenliveSettings::setSnaptopoints(false);
+
     if (resizeClipStart) {
         ItemInfo clipinfo = item->info();
         clipinfo.track = m_document->tracksCount() - clipinfo.track;
@@ -4386,9 +4537,10 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol
             }
 
             /*
-                TODO: cleanup the effect update process
+             * TODO: cleanup the effect update process
              */
             ClipItem *clip = static_cast < ClipItem * >(item);
+
             updatePositionEffects(clip, oldInfo);
 
             // check keyframes
@@ -4404,13 +4556,7 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol
                 }
             }
 
-            /*int panZoomPos = clip->hasEffect("affine", "pan_zoom");
-            if (panZoomPos != -1) {
-                doc.appendChild(doc.importNode(clip->effectAt(panZoomPos), true));
-                indexes.append(panZoomPos);
-            }*/
-
-            if (clip->checkEffectsKeyframesPos(oldInfo.cropStart.frames(m_document->fps()), clip->cropStart().frames(m_document->fps()), true, m_document->width(), m_document->height())) {
+            if (clip->checkEffectsKeyframesPos(oldInfo.cropStart.frames(m_document->fps()), clip->cropStart().frames(m_document->fps()), true)) {
                 // Keyframes were modified, updateClip
                 QDomNodeList effs = doc.elementsByTagName("effect");
                 // Hack:
@@ -4478,7 +4624,6 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
         hasParentCommand = true;
     } else {
         command = new QUndoCommand();
-        command->setText(i18n("Resize clip end"));
     }
 
     // do this here, too, because otherwise undo won't update the group
@@ -4487,9 +4632,10 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
 
     ItemInfo info = item->info();
     if (item->type() == AVWIDGET) {
+        if (!hasParentCommand) command->setText(i18n("Resize clip end"));
         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);
@@ -4513,8 +4659,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);
@@ -4527,7 +4676,7 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
                 }
             }
 
-            if (clip->checkEffectsKeyframesPos((oldInfo.cropStart + oldInfo.endPos - oldInfo.startPos).frames(m_document->fps()) - 1, (clip->cropStart() + clip->cropDuration()).frames(m_document->fps()) - 1, false, m_document->width(), m_document->height())) {
+            if (clip->checkEffectsKeyframesPos((oldInfo.cropStart + oldInfo.endPos - oldInfo.startPos).frames(m_document->fps()) - 1, (clip->cropStart() + clip->cropDuration()).frames(m_document->fps()) - 1, false)) {
                 // Keyframes were modified, updateClip
                 QDomNodeList effs = doc.elementsByTagName("effect");
                 // Hack:
@@ -4545,8 +4694,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()));
@@ -4554,6 +4701,7 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
             emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
         }
     } else if (item->type() == TRANSITIONWIDGET) {
+        if (!hasParentCommand) command->setText(i18n("Resize transition end"));
         Transition *transition = static_cast <Transition *>(item);
         if (!m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_document->tracksCount() - oldInfo.track), (int)(m_document->tracksCount() - oldInfo.track), transition->transitionEndTrack(), oldInfo.startPos, oldInfo.endPos, info.startPos, info.endPos)) {
             // Cannot resize transition
@@ -4562,16 +4710,23 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
             KdenliveSettings::setSnaptopoints(true);
             emit displayMessage(i18n("Cannot resize transition"), ErrorMessage);
         } else {
-            MoveTransitionCommand *moveCommand = new MoveTransitionCommand(this, oldInfo, info, false, command);
-            if (command == NULL)
-                m_commandStack->push(moveCommand);
+            // Check transition keyframes
+            QDomElement old = transition->toXML();
+            if (transition->updateKeyframes()) {
+                QDomElement xml = transition->toXML();
+                m_document->renderer()->mltUpdateTransition(xml.attribute("tag"), xml.attribute("tag"), xml.attribute("transition_btrack").toInt(), m_document->tracksCount() - xml.attribute("transition_atrack").toInt(), transition->startPos(), transition->endPos(), xml);
+                new EditTransitionCommand(this, transition->track(), transition->startPos(), old, xml, false, command);
+            }
+            new MoveTransitionCommand(this, oldInfo, info, false, command);
         }
     }
     if (item->parentItem() && item->parentItem() != m_selectionGroup)
         new RebuildGroupCommand(this, item->info().track, item->startPos(), command);
 
-    if (!hasParentCommand)
+    if (!hasParentCommand) {
+        updateTrackDuration(oldInfo.track, command);
         m_commandStack->push(command);
+    }
 }
 
 void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info)
@@ -4671,23 +4826,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(), 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)
@@ -4760,6 +4899,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)
@@ -4907,13 +5051,19 @@ bool CustomTrackView::addGuide(const GenTime pos, const QString &comment)
     return true;
 }
 
-void CustomTrackView::slotAddGuide()
+void CustomTrackView::slotAddGuide(bool dialog)
 {
     CommentedTime marker(GenTime(m_cursorPos, m_document->fps()), i18n("Guide"));
-    MarkerDialog d(NULL, marker, m_document->timecode(), i18n("Add Guide"), this);
-    if (d.exec() != QDialog::Accepted) return;
-    if (addGuide(d.newMarker().time(), d.newMarker().comment())) {
-        EditGuideCommand *command = new EditGuideCommand(this, GenTime(), QString(), d.newMarker().time(), d.newMarker().comment(), false);
+    if (dialog) {
+        MarkerDialog d(NULL, marker, m_document->timecode(), i18n("Add Guide"), this);
+        if (d.exec() != QDialog::Accepted) return;
+        marker = d.newMarker();
+        
+    } else {
+        marker.setComment(m_document->timecode().getDisplayTimecodeFromFrames(m_cursorPos, false));
+    }
+    if (addGuide(marker.time(), marker.comment())) {
+        EditGuideCommand *command = new EditGuideCommand(this, GenTime(), QString(), marker.time(), marker.comment(), false);
         m_commandStack->push(command);
     }
 }
@@ -5002,13 +5152,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));
@@ -5024,6 +5173,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));
 }
 
@@ -5037,35 +5187,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)
@@ -5320,6 +5462,7 @@ void CustomTrackView::pasteClip()
             } else emit displayMessage(i18n("Cannot paste transition to selected place"), ErrorMessage);
         }
     }
+    updateTrackDuration(-1, pasteClips);
     m_commandStack->push(pasteClips);
 }
 
@@ -5348,7 +5491,6 @@ void CustomTrackView::pasteClipEffects()
         }
     }
 
-
     for (int i = 0; i < clips.count(); ++i) {
         if (clips.at(i)->type() == AVWIDGET) {
             ClipItem *item = static_cast < ClipItem *>(clips.at(i));
@@ -5519,7 +5661,7 @@ void CustomTrackView::slotUpdateAllThumbs()
                         item->slotSetEndThumb(pix);
                     }
                 }
-                item->refreshClip(false);
+                item->refreshClip(false, false);
             }
         }
     }
@@ -5574,6 +5716,7 @@ void CustomTrackView::slotInsertTrack(int ix)
         if (d.before_select->currentIndex() == 1)
             ix++;
         TrackInfo info;
+        info.duration = 0;
         info.isMute = false;
         info.isLocked = false;
         if (d.video_track->isChecked()) {
@@ -5638,6 +5781,7 @@ void CustomTrackView::deleteTimelineTrack(int ix, TrackInfo trackinfo)
         if (selection.at(i)->type() == AVWIDGET) {
             ClipItem *item =  static_cast <ClipItem *>(selection.at(i));
             new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, false, true, deleteTrack);
+            m_waitingThumbs.removeAll(item);
             m_scene->removeItem(item);
             delete item;
             item = NULL;
@@ -5740,8 +5884,7 @@ void CustomTrackView::loadGroups(const QDomNodeList groups)
         QDomNodeList children = groups.at(i).childNodes();
         scene()->clearSelection();
         for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) {
-            QDomNode n = children.item(nodeindex);
-            QDomElement elem = n.toElement();
+            QDomElement elem = children.item(nodeindex).toElement();
             int pos = elem.attribute("position").toInt();
             int track = elem.attribute("track").toInt();
             if (elem.tagName() == "clipitem") {
@@ -5778,8 +5921,10 @@ void CustomTrackView::splitAudio()
             }
         }
     }
-    if (splitCommand->childCount() > 0)
+    if (splitCommand->childCount()) {
+        updateTrackDuration(-1, splitCommand);
         m_commandStack->push(splitCommand);
+    }
 }
 
 void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split)
@@ -5792,12 +5937,17 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split)
     if (split) {
         int start = pos.frames(m_document->fps());
         int freetrack = m_document->tracksCount() - track - 1;
+
+        // do not split audio when we are on an audio track
+        if (m_document->trackInfoAt(freetrack).type == AUDIOTRACK)
+            return;
+
         for (; freetrack > 0; freetrack--) {
-            kDebug() << "// CHK DOC TRK:" << freetrack << ", DUR:" << m_document->renderer()->mltTrackDuration(freetrack);
+            //kDebug() << "// CHK DOC TRK:" << freetrack << ", DUR:" << m_document->renderer()->mltTrackDuration(freetrack);
             if (m_document->trackInfoAt(freetrack - 1).type == AUDIOTRACK && !m_document->trackInfoAt(freetrack - 1).isLocked) {
-                kDebug() << "// CHK DOC TRK:" << freetrack << ", DUR:" << m_document->renderer()->mltTrackDuration(freetrack);
+                //kDebug() << "// CHK DOC TRK:" << freetrack << ", DUR:" << m_document->renderer()->mltTrackDuration(freetrack);
                 if (m_document->renderer()->mltTrackDuration(freetrack) < start || m_document->renderer()->mltGetSpaceLength(pos, freetrack, false) >= clip->cropDuration().frames(m_document->fps())) {
-                    kDebug() << "FOUND SPACE ON TRK: " << freetrack;
+                    //kDebug() << "FOUND SPACE ON TRK: " << freetrack;
                     break;
                 }
             }
@@ -6072,6 +6222,7 @@ void CustomTrackView::updateProjectFps()
             m_document->clipManager()->removeGroup(grp);
             m_scene->addItem(grp);
             scene()->destroyItemGroup(grp);
+            scene()->clearSelection();
             for (int j = 0; j < children.count(); j++) {
                 if (children.at(j)->type() == AVWIDGET || children.at(j)->type() == TRANSITIONWIDGET) {
                     //children.at(j)->setParentItem(0);
@@ -6240,6 +6391,7 @@ void CustomTrackView::insertZoneOverwrite(QStringList data, int in)
     addCommand->setText(i18n("Insert clip"));
     adjustTimelineClips(OVERWRITEEDIT, NULL, info, addCommand);
     new AddTimelineClipCommand(this, clip->toXML(), clip->getId(), info, EffectsList(), true, false, true, false, addCommand);
+    updateTrackDuration(info.track, addCommand);
     m_commandStack->push(addCommand);
 
     selectClip(true, false, m_selectedTrack, in);
@@ -6258,12 +6410,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()
@@ -6397,8 +6551,8 @@ EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect)
             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;
+                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;
@@ -6441,4 +6595,102 @@ EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect)
         }
     }
     return parameters;
-}
\ No newline at end of file
+}
+
+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());
+}
+
+void CustomTrackView::updateTrackNames(int track, bool added)
+{
+    QList <TrackInfo> tracks = m_document->tracksList();
+    int max = tracks.count();
+    int docTrack = max - track - 1;
+
+    // count number of tracks of each type
+    int videoTracks = 0;
+    int audioTracks = 0;
+    for (int i = max - 1; i >= 0; --i) {
+        TrackInfo info = tracks.at(i);
+        if (info.type == VIDEOTRACK)
+            videoTracks++;
+        else
+            audioTracks++;
+
+        if (i <= docTrack) {
+            QString type = (info.type == VIDEOTRACK ? "Video " : "Audio ");
+            int typeNumber = (info.type == VIDEOTRACK ? videoTracks : audioTracks);
+
+            if (added) {
+                if (i == docTrack || info.trackName == type + QString::number(typeNumber - 1)) {
+                    info.trackName = type + QString::number(typeNumber);
+                    m_document->setTrackType(i, info);
+                }
+            } else {
+                if (info.trackName == type + QString::number(typeNumber + 1)) {
+                    info.trackName = type + QString::number(typeNumber);
+                    m_document->setTrackType(i, info);
+                }
+            }
+        }
+    }
+    emit tracksChanged();
+}
+
+void CustomTrackView::updateTrackDuration(int track, QUndoCommand *command)
+{
+    Q_UNUSED(command)
+
+    QList<int> tracks;
+    if (track >= 0) {
+        tracks << m_document->tracksCount() - track - 1;
+    } else {
+        // negative track number -> update all tracks
+        for (int i = 0; i < m_document->tracksCount(); ++i)
+            tracks << i;
+    }
+    int t, duration;
+    for (int i = 0; i < tracks.count(); ++i) {
+        t = tracks.at(i);
+        // t + 1 because of black background track
+        duration = m_document->renderer()->mltTrackDuration(t + 1);
+        if (duration != m_document->trackDuration(t)) {
+            m_document->setTrackDuration(t, duration);
+
+            // update effects
+            EffectsList effects = m_document->getTrackEffects(t);
+            for (int j = 0; j < effects.count(); ++j) {
+                /* TODO
+                 * - lookout for keyframable parameters and update them so all keyframes are in the new range (0 - duration)
+                 * - update the effectstack if necessary
+                 */
+            }
+        }
+    }
+}
+
+void CustomTrackView::slotRefreshThumbs(const QString &id, bool resetThumbs)
+{
+    QList<QGraphicsItem *> list = scene()->items();
+    ClipItem *clip = NULL;
+    for (int i = 0; i < list.size(); ++i) {
+        if (list.at(i)->type() == AVWIDGET) {
+            clip = static_cast <ClipItem *>(list.at(i));
+            if (clip->clipProducer() == id) {
+                clip->refreshClip(true, resetThumbs);
+            }
+        }
+    }
+}