]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
Fix painting issues (disappearing cursor, clip borders)
[kdenlive] / src / customtrackview.cpp
index 791bdf793123c616c21ce163aeb4f541203494b1..32d5b94b74e54dca560d80aa46c4c20dbc067e39 100644 (file)
 #include <QInputDialog>
 
 
+bool sortGuidesList(const Guide *g1 , const Guide *g2)
+{
+    return (*g1).position() < (*g2).position();
+}
+
+
 //TODO:
 // disable animation if user asked it in KDE's global settings
 // http://lists.kde.org/?l=kde-commits&m=120398724717624&w=2
@@ -128,6 +134,10 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscen
     verticalScrollBar()->setMaximum(maxWidth);
     m_cursorLine = projectscene->addLine(0, 0, 0, maxWidth);
     m_cursorLine->setZValue(1000);
+    QPen pen1;
+    pen1.setWidthF(1.0);
+    pen1.setCosmetic(true);
+    m_cursorLine->setPen(pen1);
 
     KIcon razorIcon("edit-cut");
     m_razorCursor = QCursor(razorIcon.pixmap(22, 22));
@@ -349,13 +359,14 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
                 pos = (br.bottom() - pos) * maxh;
                 m_dragItem->updateKeyFramePos(keyFramePos, pos);
             }
-
+            m_animationTimer->stop();
             delete m_animation;
             m_animation = NULL;
             delete m_visualTip;
             m_visualTip = NULL;
             return;
         } else if (m_operationMode == MOVEGUIDE) {
+            m_animationTimer->stop();
             delete m_animation;
             m_animation = NULL;
             delete m_visualTip;
@@ -395,9 +406,9 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
         AbstractClipItem *clip = static_cast <AbstractClipItem*>(item);
         if (m_tool == RAZORTOOL) {
             // razor tool over a clip, display current frame in monitor
-            if (!m_blockRefresh && item->type() == AVWIDGET) {
+            if (false && /*!m_blockRefresh && */item->type() == AVWIDGET) {
                 //TODO: solve crash when showing frame when moving razor over clip
-                //emit showClipFrame(((ClipItem *) item)->baseClip(), mappedXPos - (clip->startPos() - clip->cropStart()).frames(m_document->fps()));
+                emit showClipFrame(((ClipItem *) item)->baseClip(), mappedXPos - (clip->startPos() - clip->cropStart()).frames(m_document->fps()));
             }
             event->accept();
             return;
@@ -587,7 +598,6 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
 // virtual
 void CustomTrackView::mousePressEvent(QMouseEvent * event)
 {
-    //kDebug() << "mousePressEvent STARTED";
     setFocus(Qt::MouseFocusReason);
     m_menuPosition = QPoint();
 
@@ -600,6 +610,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
     }
 
     if (event->modifiers() & Qt::ShiftModifier) {
+        // Rectangle selection
         setDragMode(QGraphicsView::RubberBandDrag);
         if (!(event->modifiers() & Qt::ControlModifier)) {
             resetSelectionGroup();
@@ -612,7 +623,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
     }
 
     m_blockRefresh = true;
-    m_dragItem = NULL;
     m_dragGuide = NULL;
     bool collision = false;
 
@@ -627,6 +637,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
     QList<QGraphicsItem *> collisionList = items(m_clickEvent);
 
     if (event->modifiers() == Qt::ControlModifier && m_tool != SPACERTOOL && collisionList.count() == 0) {
+        // Pressing Ctrl + left mouse button in an empty area scrolls the timeline
         setDragMode(QGraphicsView::ScrollHandDrag);
         QGraphicsView::mousePressEvent(event);
         m_blockRefresh = false;
@@ -657,9 +668,15 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
     // Find first clip, transition or group under mouse (when no guides selected)
     int ct = 0;
     AbstractGroupItem *dragGroup = NULL;
+    AbstractClipItem *collisionClip = NULL;
+    bool found = false;
     while (!m_dragGuide && ct < collisionList.count()) {
         if (collisionList.at(ct)->type() == AVWIDGET || collisionList.at(ct)->type() == TRANSITIONWIDGET) {
-            m_dragItem = static_cast <AbstractClipItem *>(collisionList.at(ct));
+            collisionClip = static_cast <AbstractClipItem *>(collisionList.at(ct));
+            if (collisionClip == m_dragItem) {
+                collisionClip = NULL;
+            } else m_dragItem = collisionClip;
+            found = true;
             m_dragItemInfo = m_dragItem->info();
             if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET && m_dragItem->parentItem() != m_selectionGroup) {
                 // kDebug()<<"// KLIK FOUND GRP: "<<m_dragItem->sceneBoundingRect();
@@ -669,6 +686,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         }
         ct++;
     }
+    if (!found) m_dragItem = NULL;
 
     if (m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) {
         // update transition menu action
@@ -732,16 +750,41 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
                 kDebug() << "SELELCTING ELEMENTS WITHIN =" << event->pos().x() << "/" <<  1 << ", " << mapFromScene(sceneRect().width(), 0).x() - event->pos().x() << "/" << sceneRect().height();
             }
 
+            QList <GenTime> offsetList;
             for (int i = 0; i < selection.count(); i++) {
-                if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET) {
+                if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET) {
+                    AbstractClipItem *item = static_cast<AbstractClipItem *>(selection.at(i));
+                    offsetList.append(item->startPos());
+                    offsetList.append(item->endPos());
                     selection.at(i)->setSelected(true);
                 }
+                if (selection.at(i)->type() == GROUPWIDGET) {
+                    QList<QGraphicsItem *> children = selection.at(i)->childItems();
+                    for (int j = 0; j < children.count(); j++) {
+                        AbstractClipItem *item = static_cast<AbstractClipItem *>(children.at(j));
+                        offsetList.append(item->startPos());
+                        offsetList.append(item->endPos());
+                    }
+                    selection.at(i)->setSelected(true);
+                }
+            }
+
+            if (!offsetList.isEmpty()) {
+                qSort(offsetList);
+                QList <GenTime> cleandOffsetList;
+                GenTime startOffset = offsetList.takeFirst();
+                for (int k = 0; k < offsetList.size(); k++) {
+                    GenTime newoffset = offsetList.at(k) - startOffset;
+                    if (newoffset != GenTime() && !cleandOffsetList.contains(newoffset)) {
+                        cleandOffsetList.append(newoffset);
+                    }
+                }
+                updateSnapPoints(NULL, cleandOffsetList, true);
             }
             groupSelectedItems(true);
             m_operationMode = SPACER;
         } else setCursorPos((int)(mapToScene(event->x(), 0).x()));
         QGraphicsView::mousePressEvent(event);
-        kDebug() << "END mousePress EVENT ";
         return;
     }
 
@@ -768,10 +811,36 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         return;
     }
 
-    if (dragGroup == NULL) updateSnapPoints(m_dragItem);
+    bool itemSelected = false;
+    if (m_dragItem->isSelected()) itemSelected = true;
+    else if (m_dragItem->parentItem() && m_dragItem->parentItem()->isSelected()) itemSelected = true;
+    else if (dragGroup && dragGroup->isSelected()) itemSelected = true;
+
+    if (event->modifiers() == Qt::ControlModifier || itemSelected == false) {
+        if (event->modifiers() != Qt::ControlModifier) {
+            m_scene->clearSelection();
+            resetSelectionGroup(false);
+        } 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();
+        if (dragGroup) dragGroup->setSelected(selected);
+        else m_dragItem->setSelected(selected);
+
+        groupSelectedItems();
+        ClipItem *clip = static_cast <ClipItem *>(m_dragItem);
+        updateClipTypeActions(dragGroup == NULL ? clip : NULL);
+        m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
+    }
+
+    // Update snap points
+    if (m_selectionGroup == NULL) updateSnapPoints(m_dragItem);
     else {
         QList <GenTime> offsetList;
-        QList<QGraphicsItem *> children = dragGroup->childItems();
+        QList<QGraphicsItem *> children = m_selectionGroup->childItems();
         for (int i = 0; i < children.count(); i++) {
             if (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET) {
                 AbstractClipItem *item = static_cast <AbstractClipItem *>(children.at(i));
@@ -793,29 +862,11 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         }
     }
 
-    if (m_dragItem->type() == AVWIDGET && !m_dragItem->isItemLocked()) emit clipItemSelected((ClipItem*) m_dragItem);
-    else emit clipItemSelected(NULL);
-
-    bool itemSelected = false;
-    if (m_dragItem->isSelected()) itemSelected = true;
-    else if (m_dragItem->parentItem() && m_dragItem->parentItem()->isSelected()) itemSelected = true;
-    else if (dragGroup && dragGroup->isSelected()) itemSelected = true;
-    if (event->modifiers() == Qt::ControlModifier || itemSelected == false) {
-        resetSelectionGroup();
-        if (event->modifiers() != Qt::ControlModifier) m_scene->clearSelection();
-        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();
-        if (dragGroup) dragGroup->setSelected(selected);
-        else m_dragItem->setSelected(selected);
-
-        groupSelectedItems();
-        ClipItem *clip = static_cast <ClipItem *>(m_dragItem);
-        updateClipTypeActions(dragGroup == NULL ? clip : NULL);
-        m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
+    if (collisionClip != NULL || m_dragItem == NULL) {
+        if (m_dragItem && m_dragItem->type() == AVWIDGET && !m_dragItem->isItemLocked()) {
+            ClipItem *selected = static_cast <ClipItem*>(m_dragItem);
+            emit clipItemSelected(selected);
+        } else emit clipItemSelected(NULL);
     }
 
     // If clicked item is selected, allow move
@@ -994,20 +1045,19 @@ void CustomTrackView::groupSelectedItems(bool force, bool createNewGroup)
 
 void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event)
 {
-    kDebug() << "++++++++++++ DBL CLK";
     if (m_dragItem && m_dragItem->hasKeyFrames()) {
         if (m_moveOpMode == KEYFRAME) {
             // user double clicked on a keyframe, open edit dialog
             QDialog d(parentWidget());
             Ui::KeyFrameDialog_UI view;
             view.setupUi(&d);
-            view.kfr_position->setText(m_document->timecode().getTimecode(GenTime(m_dragItem->selectedKeyFramePos(), m_document->fps()) - m_dragItem->cropStart(), m_document->fps()));
+            view.kfr_position->setText(m_document->timecode().getTimecode(GenTime(m_dragItem->selectedKeyFramePos(), m_document->fps()) - m_dragItem->cropStart()));
             view.kfr_value->setValue(m_dragItem->selectedKeyFrameValue());
             view.kfr_value->setFocus();
             if (d.exec() == QDialog::Accepted) {
-                int pos = m_document->timecode().getFrameCount(view.kfr_position->text(), m_document->fps());
+                int pos = m_document->timecode().getFrameCount(view.kfr_position->text());
                 m_dragItem->updateKeyFramePos(GenTime(pos, m_document->fps()) + m_dragItem->cropStart(), (double) view.kfr_value->value() * m_dragItem->keyFrameFactor());
-                ClipItem *item = (ClipItem *)m_dragItem;
+                ClipItem *item = static_cast <ClipItem *>(m_dragItem);
                 QString previous = item->keyframes(item->selectedEffectIndex());
                 item->updateKeyframeEffect();
                 QString next = item->keyframes(item->selectedEffectIndex());
@@ -1021,7 +1071,7 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event)
             // add keyframe
             GenTime keyFramePos = GenTime((int)(mapToScene(event->pos()).x()), m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart();
             m_dragItem->addKeyFrame(keyFramePos, mapToScene(event->pos()).toPoint().y());
-            ClipItem * item = (ClipItem *) m_dragItem;
+            ClipItem * item = static_cast <ClipItem *>(m_dragItem);
             QString previous = item->keyframes(item->selectedEffectIndex());
             item->updateKeyframeEffect();
             QString next = item->keyframes(item->selectedEffectIndex());
@@ -1137,7 +1187,10 @@ void CustomTrackView::dragEnterEvent(QDragEnterEvent * event)
         m_selectionGroup = new AbstractGroupItem(m_document->fps());
         QPoint pos;
         DocClipBase *clip = m_document->getBaseClip(list.at(0));
-        if (clip == NULL) kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << list.at(0);
+        if (clip == NULL) {
+            kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << list.at(0);
+            return;
+        }
         ItemInfo info;
         info.startPos = GenTime();
         info.cropStart = GenTime(list.at(1).toInt(), m_document->fps());
@@ -1165,7 +1218,10 @@ void CustomTrackView::dragEnterEvent(QDragEnterEvent * event)
         QList <GenTime> offsetList;
         for (int i = 0; i < ids.size(); ++i) {
             DocClipBase *clip = m_document->getBaseClip(ids.at(i));
-            if (clip == NULL) kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << ids.at(i);
+            if (clip == NULL) {
+                kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << ids.at(i);
+                return;
+            }
             ItemInfo info;
             info.startPos = start;
             info.endPos = info.startPos + clip->duration();
@@ -1275,13 +1331,14 @@ void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect)
             if (strobe == 0) strobe = 1;
             doChangeClipSpeed(info, speed, 1.0, strobe, clip->baseClip()->getId());
             clip->addEffect(effect);
-            emit clipItemSelected(clip);
+            if (clip->isSelected()) emit clipItemSelected(clip);
             return;
         }
 
-        if (!m_document->renderer()->mltAddEffect(track, pos, clip->addEffect(effect)))
+        EffectsParameterList params = clip->addEffect(effect);
+        if (!m_document->renderer()->mltAddEffect(track, pos, params))
             emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
-        emit clipItemSelected(clip);
+        if (clip->isSelected()) emit clipItemSelected(clip);
     } else emit displayMessage(i18n("Cannot find clip to add effect"), ErrorMessage);
 }
 
@@ -1367,14 +1424,14 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
     int count = 0;
     if (track == -1) itemList = scene()->selectedItems();
     if (itemList.isEmpty()) {
-        ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, track);
+        ClipItem *clip = getClipItemAt((int) pos.frames(m_document->fps()), track);
         if (clip) itemList.append(clip);
         else emit displayMessage(i18n("Select a clip if you want to apply an effect"), ErrorMessage);
     }
     kDebug() << "// REQUESTING EFFECT ON CLIP: " << pos.frames(25) << ", TRK: " << track << "SELECTED ITEMS: " << itemList.count();
     for (int i = 0; i < itemList.count(); i++) {
         if (itemList.at(i)->type() == AVWIDGET) {
-            ClipItem *item = (ClipItem *)itemList.at(i);
+            ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
             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)) {
@@ -1423,7 +1480,6 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement effect, i
     ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_document->tracksCount() - track);
     if (clip) {
 
-
         // Special case: speed effect
         if (effect.attribute("id") == "speed") {
             ItemInfo info = clip->info();
@@ -1438,9 +1494,6 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement effect, i
             return;
         }
 
-
-
-
         EffectsParameterList effectParams = clip->getEffectArgs(effect);
         if (effect.attribute("tag") == "ladspa") {
             // Update the ladspa affect file
@@ -1481,26 +1534,25 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement effect, i
 void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos)
 {
     ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_document->tracksCount() - track);
-    if (clip) {
-        m_document->renderer()->mltMoveEffect(track, pos, oldPos, newPos);
+    if (clip && !clip->effectAt(newPos - 1).isNull() && !clip->effectAt(oldPos - 1).isNull()) {
         QDomElement act = clip->effectAt(newPos - 1).cloneNode().toElement();
         QDomElement before = clip->effectAt(oldPos - 1).cloneNode().toElement();
         clip->setEffectAt(oldPos - 1, act);
         clip->setEffectAt(newPos - 1, before);
+        m_document->renderer()->mltMoveEffect(track, pos, oldPos, newPos);
         emit clipItemSelected(clip, newPos - 1);
-    }
-    setDocumentModified();
+        setDocumentModified();
+    } else emit displayMessage(i18n("Cannot move effect"), ErrorMessage);
 }
 
 void CustomTrackView::slotChangeEffectState(ClipItem *clip, int effectPos, bool disable)
 {
-    QDomElement effect = clip->effectAt(effectPos);
+    QDomElement effect = clip->effectAt(effectPos).cloneNode().toElement();
     QDomElement oldEffect = effect.cloneNode().toElement();
-
     if (effect.attribute("id") == "speed") {
         if (clip) {
             ItemInfo info = clip->info();
-            effect.setAttribute("disabled", disable);
+            effect.setAttribute("disabled", (int) disable);
             if (disable) doChangeClipSpeed(info, 1.0, clip->speed(), 1, clip->baseClip()->getId());
             else {
                 double speed = EffectsList::parameter(effect, "speed").toDouble() / 100.0;
@@ -1511,7 +1563,7 @@ void CustomTrackView::slotChangeEffectState(ClipItem *clip, int effectPos, bool
             return;
         }
     }
-    effect.setAttribute("disabled", disable);
+    effect.setAttribute("disabled", (int) disable);
     EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldEffect, effect, effectPos, true);
     m_commandStack->push(command);
     setDocumentModified();;
@@ -1534,7 +1586,7 @@ void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut)
 {
     if (cut) {
         // cut clip
-        ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()) + 1, info.track);
+        ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
         if (!item || cutTime >= item->endPos() || cutTime <= item->startPos()) {
             emit displayMessage(i18n("Cannot find clip to cut"), ErrorMessage);
             kDebug() << "/////////  ERROR CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25);
@@ -1575,8 +1627,7 @@ void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut)
         item->baseClip()->addReference();
         m_document->updateClip(item->baseClip()->getId());
         setDocumentModified();
-        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);
-        kDebug() << "//  CUTTING CLIP dONE";
+        //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
 
@@ -1592,9 +1643,9 @@ void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut)
             return;
         }
 
-        kDebug() << "// UNCUTTING CLIPS: ITEM 1 (" << item->startPos().frames(25) << "x" << item->endPos().frames(25) << ")";
+        /*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);;
+        kDebug() << "// UNCUTTING CLIPS, INFO (" << info.startPos.frames(25) << "x" << info.endPos.frames(25) << ") , CUT: " << cutTime.frames(25);;*/
         //deleteClip(dup->info());
 
 
@@ -1751,7 +1802,7 @@ void CustomTrackView::deleteTransition(ItemInfo transitionInfo, int endTrack, QD
 
 void CustomTrackView::slotTransitionUpdated(Transition *tr, QDomElement old)
 {
-    kDebug() << "TRANS UPDATE, TRACKS: " << old.attribute("transition_btrack") << ", NEW: " << tr->toXML().attribute("transition_btrack");
+    //kDebug() << "TRANS UPDATE, TRACKS: " << old.attribute("transition_btrack") << ", NEW: " << tr->toXML().attribute("transition_btrack");
     EditTransitionCommand *command = new EditTransitionCommand(this, tr->track(), tr->startPos(), old, tr->toXML(), false);
     m_commandStack->push(command);
     setDocumentModified();
@@ -1773,7 +1824,8 @@ void CustomTrackView::updateTransition(int track, GenTime pos, QDomElement oldTr
         ClipItem *transitionClip = getClipItemAt(info.startPos, info.track);
         if (transitionClip && transitionClip->baseClip()) {
             QString size = transitionClip->baseClip()->getProperty("frame_size");
-            p.setX(size.section('x', 0, 0).toInt());
+            double factor = transitionClip->baseClip()->getProperty("aspect_ratio").toDouble();
+            p.setX((int)(size.section('x', 0, 0).toInt() * factor + 0.5));
             p.setY(size.section('x', 1, 1).toInt());
         }
         emit transitionItemSelected(item, getPreviousVideoTrack(info.track), p, true);
@@ -1834,14 +1886,17 @@ void CustomTrackView::dropEvent(QDropEvent * event)
             int tracknumber = m_document->tracksCount() - info.track - 1;
             bool isLocked = m_document->trackInfoAt(tracknumber).isLocked;
             if (isLocked) item->setItemLocked(true);
+            ItemInfo clipInfo = info;
+            clipInfo.track = m_document->tracksCount() - item->track();
+            if (m_document->renderer()->mltInsertClip(clipInfo, item->xml(), item->baseClip()->producer(item->track())) == -1) {
+                emit displayMessage(i18n("Cannot insert clip in timeline"), ErrorMessage);
+            }
 
             if (item->baseClip()->isTransparent() && getTransitionItemAtStart(info.startPos, info.track) == NULL) {
                 // add transparency transition
-               QDomElement trans = MainWindow::transitions.getEffectByTag("composite", "composite").cloneNode().toElement();
+                QDomElement trans = MainWindow::transitions.getEffectByTag("composite", "composite").cloneNode().toElement();
                 new AddTransitionCommand(this, info, getPreviousVideoTrack(info.track), trans, false, true, addCommand);
             }
-            info.track = m_document->tracksCount() - item->track();
-            m_document->renderer()->mltInsertClip(info, item->xml(), item->baseClip()->producer(item->track()));
             item->setSelected(true);
         }
         m_commandStack->push(addCommand);
@@ -1932,7 +1987,6 @@ void CustomTrackView::addTrack(TrackInfo type, int ix)
                     else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer();
                     else prod = clip->baseClip()->producer(clipinfo.track);
                     m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod);
-                    kDebug() << "// UPDATING CLIP TO TRACK PROD: " << clipinfo.track;
                 }
             } else if (item->type() == TRANSITIONWIDGET) {
                 Transition *tr = static_cast <Transition *>(item);
@@ -2322,6 +2376,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), newPos, m_dragGuide->label(), false);
             m_commandStack->push(command);
             m_dragGuide->updateGuide(GenTime(m_dragGuide->pos().x(), m_document->fps()));
+            qSort(m_guides.begin(), m_guides.end(), sortGuidesList);
             m_document->syncGuides(m_guides);
         }
         m_dragGuide = NULL;
@@ -2409,7 +2464,6 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                 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);
 
                 if (success) {
-                    kDebug() << "// get trans info";
                     int tracknumber = m_document->tracksCount() - item->track() - 1;
                     bool isLocked = m_document->trackInfoAt(tracknumber).isLocked;
                     if (isLocked) item->setItemLocked(true);
@@ -2419,7 +2473,6 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                     new MoveClipCommand(this, m_dragItemInfo, info, false, moveCommand);
                     // Also move automatic transitions (on lower track)
                     Transition *tr = getTransitionItemAtStart(m_dragItemInfo.startPos, m_dragItemInfo.track);
-                    kDebug() << "// get trans info2";
                     if (tr && tr->isAutomatic()) {
                         ItemInfo trInfo = tr->info();
                         ItemInfo newTrInfo = trInfo;
@@ -2722,10 +2775,10 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         //m_document->renderer()->doRefresh();
     } else if (m_operationMode == FADEIN) {
         // resize fade in effect
-        ClipItem * item = (ClipItem *) m_dragItem;
+        ClipItem * item = static_cast <ClipItem *>(m_dragItem);
         int ix = item->hasEffect("volume", "fadein");
         if (ix != -1) {
-            QDomElement oldeffect = item->effectAt(ix);
+            QDomElement oldeffect = item->effectAt(ix).cloneNode().toElement();
             int start = item->cropStart().frames(m_document->fps());
             int end = item->fadeIn();
             if (end == 0) {
@@ -2745,7 +2798,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         }
         ix = item->hasEffect("volume", "fade_from_black");
         if (ix != -1) {
-            QDomElement oldeffect = item->effectAt(ix);
+            QDomElement oldeffect = item->effectAt(ix).cloneNode().toElement();
             int start = item->cropStart().frames(m_document->fps());
             int end = item->fadeIn();
             if (end == 0) {
@@ -2761,10 +2814,10 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         }
     } else if (m_operationMode == FADEOUT) {
         // resize fade in effect
-        ClipItem * item = (ClipItem *) m_dragItem;
+        ClipItem * item = static_cast <ClipItem *>(m_dragItem);
         int ix = item->hasEffect("volume", "fadeout");
         if (ix != -1) {
-            QDomElement oldeffect = item->effectAt(ix);
+            QDomElement oldeffect = item->effectAt(ix).cloneNode().toElement();
             int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps());
             int start = item->fadeOut();
             if (start == 0) {
@@ -2786,7 +2839,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         }
         ix = item->hasEffect("brightness", "fade_to_black");
         if (ix != -1) {
-            QDomElement oldeffect = item->effectAt(ix);
+            QDomElement oldeffect = item->effectAt(ix).cloneNode().toElement();
             int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps());
             int start = item->fadeOut();
             if (start == 0) {
@@ -2803,7 +2856,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         }
     } else if (m_operationMode == KEYFRAME) {
         // update the MLT effect
-        ClipItem * item = (ClipItem *) m_dragItem;
+        ClipItem * item = static_cast <ClipItem *>(m_dragItem);
         QString previous = item->keyframes(item->selectedEffectIndex());
         item->updateKeyframeEffect();
         QString next = item->keyframes(item->selectedEffectIndex());
@@ -2818,7 +2871,8 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         ClipItem *transitionClip = getClipItemAt(m_dragItemInfo.startPos, m_dragItemInfo.track);
         if (transitionClip && transitionClip->baseClip()) {
             QString size = transitionClip->baseClip()->getProperty("frame_size");
-            p.setX(size.section('x', 0, 0).toInt());
+            double factor = transitionClip->baseClip()->getProperty("aspect_ratio").toDouble();
+            p.setX((int)(size.section('x', 0, 0).toInt() * factor + 0.5));
             p.setY(size.section('x', 1, 1).toInt());
         }
         emit transitionItemSelected(static_cast <Transition *>(m_dragItem), getPreviousVideoTrack(m_dragItem->track()), p);
@@ -3151,8 +3205,7 @@ ClipItem *CustomTrackView::getClipItemAt(int pos, int track)
 
 ClipItem *CustomTrackView::getClipItemAt(GenTime pos, int track)
 {
-    int framepos = (int)(pos.frames(m_document->fps()));
-    return getClipItemAt(framepos, track);
+    return getClipItemAt((int) pos.frames(m_document->fps()), track);
 }
 
 Transition *CustomTrackView::getTransitionItemAt(int pos, int track)
@@ -3205,7 +3258,7 @@ Transition *CustomTrackView::getTransitionItemAtStart(GenTime pos, int track)
 void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end)
 {
     if (m_selectionGroup) resetSelectionGroup(false);
-    ClipItem *item = getClipItemAt((int) start.startPos.frames(m_document->fps()) + 1, start.track);
+    ClipItem *item = getClipItemAt((int) start.startPos.frames(m_document->fps()), start.track);
     if (!item) {
         emit displayMessage(i18n("Cannot move clip at time: %1 on track %2", m_document->timecode().getTimecodeFromFrames(start.startPos.frames(m_document->fps())), start.track), ErrorMessage);
         kDebug() << "----------------  ERROR, CANNOT find clip to move at.. ";
@@ -3291,8 +3344,6 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
 
         m_selectionGroup->moveBy(offset.frames(m_document->fps()), trackOffset *(qreal) m_tracksHeight);
 
-        kDebug() << "%% GRP NEW POS: " << m_selectionGroup->scenePos().x();
-
         QList<QGraphicsItem *> children = m_selectionGroup->childItems();
         // Expand groups
         int max = children.count();
@@ -3301,7 +3352,6 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
                 children += children.at(i)->childItems();
             }
         }
-        kDebug() << "// GRP MOVE; FOUND CHILDREN:" << children.count();
 
         for (int i = 0; i < children.count(); i++) {
             // re-add items in correct place
@@ -3377,7 +3427,8 @@ void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end)
         ClipItem *transitionClip = getClipItemAt(item->startPos(), item->track());
         if (transitionClip && transitionClip->baseClip()) {
             QString size = transitionClip->baseClip()->getProperty("frame_size");
-            p.setX(size.section('x', 0, 0).toInt());
+            double factor = transitionClip->baseClip()->getProperty("aspect_ratio").toDouble();
+            p.setX((int)(size.section('x', 0, 0).toInt() * factor + 0.5));
             p.setY(size.section('x', 1, 1).toInt());
         }
         emit transitionItemSelected(item, getPreviousVideoTrack(item->track()), p);
@@ -3669,11 +3720,6 @@ void CustomTrackView::addMarker(const QString &id, const GenTime &pos, const QSt
     viewport()->update();
 }
 
-bool sortGuidesList(const Guide *g1 , const Guide *g2)
-{
-    return (*g1).position() < (*g2).position();
-}
-
 int CustomTrackView::hasGuide(int pos, int offset)
 {
     for (int i = 0; i < m_guides.count(); i++) {
@@ -3840,7 +3886,6 @@ void CustomTrackView::setScale(double scaleFactor, double verticalScale)
 void CustomTrackView::slotRefreshGuides()
 {
     if (KdenliveSettings::showmarkers()) {
-        kDebug() << "// refresh GUIDES";
         for (int i = 0; i < m_guides.count(); i++) {
             m_guides.at(i)->update();
         }
@@ -3945,8 +3990,9 @@ void CustomTrackView::copyClip()
     }
     for (int i = 0; i < itemList.count(); i++) {
         if (itemList.at(i)->type() == AVWIDGET) {
-            ClipItem *dup = static_cast <ClipItem *>(itemList.at(i));
-            m_copiedItems.append(dup->clone(dup->info()));
+            ClipItem *clip = static_cast <ClipItem *>(itemList.at(i));
+            ClipItem *clone = clip->clone(clip->info());
+            m_copiedItems.append(clone);
         } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
             Transition *dup = static_cast <Transition *>(itemList.at(i));
             m_copiedItems.append(dup->clone());
@@ -4066,7 +4112,6 @@ void CustomTrackView::pasteClipEffects()
         return;
     }
     ClipItem *clip = static_cast < ClipItem *>(m_copiedItems.at(0));
-    EffectsList effects = clip->effectList();
 
     QUndoCommand *paste = new QUndoCommand();
     paste->setText("Paste effects");
@@ -4075,8 +4120,8 @@ 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));
-            for (int i = 0; i < clip->effectsCount(); i++) {
-                new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), clip->effectAt(i), true, paste);
+            for (int j = 0; j < clip->effectsCount(); j++) {
+                new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), clip->effectAt(j), true, paste);
             }
         }
     }