]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
Only use exiftool / ML on video clips
[kdenlive] / src / customtrackview.cpp
index 01274517a8aa2b7c74db17288f38b07a016498c0..30e6b13da9d67f7546911085c3352b11906f9a23 100644 (file)
@@ -324,12 +324,9 @@ bool CustomTrackView::checkTrackHeight()
         }
     }
     double newHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22();
-    m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight - 1);
-
+    m_cursorLine->setLine(0, 0, 0, newHeight - 1);
     for (int i = 0; i < m_guides.count(); i++) {
-        QLineF l = m_guides.at(i)->line();
-        l.setP2(QPointF(l.x2(), newHeight));
-        m_guides.at(i)->setLine(l);
+        m_guides.at(i)->setLine(0, 0, 0, newHeight - 1);
     }
 
     setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount());
@@ -731,8 +728,10 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
         if (event->buttons() != Qt::NoButton && event->modifiers() == Qt::NoModifier) {
             QGraphicsView::mouseMoveEvent(event);
             m_moveOpMode = SEEK;
-            seekCursorPos(mappedXPos);
-            slotCheckPositionScrolling();
+           if (mappedXPos != m_document->renderer()->getCurrentSeekPosition() && mappedXPos != cursorPos()) {
+               seekCursorPos(mappedXPos);
+               slotCheckPositionScrolling();
+           }
             return;
         } else m_moveOpMode = NONE;
     }
@@ -817,6 +816,8 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
     AbstractGroupItem *dragGroup = NULL;
     AbstractClipItem *collisionClip = NULL;
     bool found = false;
+    QStringList lockedTracks;
+    double yOffset = 0;
     while (!m_dragGuide && ct < collisionList.count()) {
         if (collisionList.at(ct)->type() == AVWIDGET || collisionList.at(ct)->type() == TRANSITIONWIDGET) {
             collisionClip = static_cast <AbstractClipItem *>(collisionList.at(ct));
@@ -831,13 +832,25 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
                 m_dragItem = collisionClip;
            }
             found = true;
-           
-           m_dragItem->setProperty("y_absolute", mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y());
+           for (int i = 0; i < m_document->tracksCount(); i++) {
+               if (m_document->trackInfoAt(i).isLocked) lockedTracks << QString::number(m_document->tracksCount() - i - 1);
+           }
+           yOffset = mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y();
+           m_dragItem->setProperty("y_absolute", yOffset);
+           m_dragItem->setProperty("locked_tracks", lockedTracks);
             m_dragItemInfo = m_dragItem->info();
-           if (m_selectionGroup) m_selectionGroup->setProperty("y_absolute", mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y());
-            if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET && m_dragItem->parentItem() != m_selectionGroup) {
-                dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
-               dragGroup->setProperty("y_absolute", mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y());
+           if (m_selectionGroup) {
+               m_selectionGroup->setProperty("y_absolute", yOffset);
+               m_selectionGroup->setProperty("locked_tracks", lockedTracks);
+           }
+           if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET && m_dragItem->parentItem() != m_selectionGroup) {
+               QGraphicsItem *topGroup = m_dragItem->parentItem();
+               while (topGroup->parentItem() && topGroup->parentItem()->type() == GROUPWIDGET && topGroup->parentItem() != m_selectionGroup) {
+                   topGroup = topGroup->parentItem();
+               }
+                dragGroup = static_cast <AbstractGroupItem *>(topGroup);
+               dragGroup->setProperty("y_absolute", yOffset);
+               dragGroup->setProperty("locked_tracks", lockedTracks);
             }
             break;
         }
@@ -896,6 +909,10 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         }
 
         m_operationMode = NONE;
+       if (dragGroup == NULL) {
+           if (m_dragItem && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup)
+               dragGroup = static_cast<AbstractGroupItem*> (m_dragItem->parentItem());
+       }
         displayContextMenu(event->globalPos(), m_dragItem, dragGroup);
         m_menuPosition = m_clickEvent;
     }
@@ -1024,18 +1041,24 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         } else {
            resetSelectionGroup();
        }
-        dragGroup = NULL;
-        if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET) {
-            dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
-        }
+        /*if () {
+           dragGroup = NULL;
+           if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET) {
+               dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
+           }
+       }*/
 
         bool selected = !m_dragItem->isSelected();
        QGraphicsView::mousePressEvent(event);
-         
         if (dragGroup) {
             dragGroup->setSelected(selected);
-           if (dragGroup->parentItem())
+           QList<QGraphicsItem *> children = dragGroup->childItems();
+           for (int i = 0; i < children.count(); i++) {
+               children.at(i)->setSelected(selected);
+           }
+           if (dragGroup->parentItem()) {
                dragGroup->parentItem()->setSelected(selected);
+           }
        }
         else
             m_dragItem->setSelected(selected);
@@ -1043,6 +1066,11 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
            m_dragItem = NULL;
        }
         groupSelectedItems(QList <QGraphicsItem*>(), false, true);
+       if (m_selectionGroup) {
+           m_selectionGroup->setProperty("y_absolute", yOffset);
+           m_selectionGroup->setProperty("locked_tracks", lockedTracks);
+       }
+       
        if (m_dragItem) { 
            ClipItem *clip = static_cast <ClipItem *>(m_dragItem);
            updateClipTypeActions(dragGroup == NULL ? clip : NULL);
@@ -1060,8 +1088,9 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
             m_selectionGroup->setSelected(itemSelected);
            
        }
-       if (dragGroup)
+       if (dragGroup) {
             dragGroup->setSelected(itemSelected);
+       }
        m_dragItem->setSelected(itemSelected);
     }
 
@@ -1222,11 +1251,11 @@ void CustomTrackView::rebuildGroup(AbstractGroupItem *group)
     if (group) {
         QList <QGraphicsItem *> children = group->childItems();
         m_document->clipManager()->removeGroup(group);
-       /*for (int i = 0; i < children.count(); i++) {
+       for (int i = 0; i < children.count(); i++) {
            group->removeFromGroup(children.at(i));
-       }*/
+       }
        scene()->destroyItemGroup(group);
-        groupSelectedItems(children, true, true);
+        groupSelectedItems(children, group != m_selectionGroup, true);
     }
 }
 
@@ -1241,14 +1270,16 @@ void CustomTrackView::resetSelectionGroup(bool selectItems)
         scene()->destroyItemGroup(m_selectionGroup);
        m_selectionGroup = NULL;
         for (int i = 0; i < children.count(); i++) {
-            if (children.at(i)->parentItem() == 0 && (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET)) {
-                if (!static_cast <AbstractClipItem *>(children.at(i))->isItemLocked()) {
-                    children.at(i)->setFlag(QGraphicsItem::ItemIsMovable, true);
-                    children.at(i)->setSelected(selectItems);
-                }
-            } else if (children.at(i)->type() == GROUPWIDGET) {
-                children.at(i)->setFlag(QGraphicsItem::ItemIsMovable, true);
-                children.at(i)->setSelected(selectItems);
+            if (children.at(i)->parentItem() == 0) {
+               if ((children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET)) {
+                   if (!static_cast <AbstractClipItem *>(children.at(i))->isItemLocked()) {
+                       children.at(i)->setFlag(QGraphicsItem::ItemIsMovable, true);
+                       children.at(i)->setSelected(selectItems);
+                   }
+               } else if (children.at(i)->type() == GROUPWIDGET) {
+                   children.at(i)->setFlag(QGraphicsItem::ItemIsMovable, true);
+                   children.at(i)->setSelected(selectItems);
+               }
             }
         }
         KdenliveSettings::setSnaptopoints(snap);
@@ -1269,15 +1300,27 @@ void CustomTrackView::groupSelectedItems(QList <QGraphicsItem *> selection, bool
     for (int i = 0; i < selection.count(); i++) {
        if (selectNewGroup) selection.at(i)->setSelected(true);
        if (selection.at(i)->type() == GROUPWIDGET) {
-           groupsList.insert(static_cast<AbstractGroupItem*> (selection.at(i)));
+           AbstractGroupItem *it = static_cast <AbstractGroupItem *> (selection.at(i));
+           while (it->parentItem() && it->parentItem()->type() == GROUPWIDGET) {
+               it = static_cast <AbstractGroupItem *>(it->parentItem());
+           }
+           if (!it || it->isItemLocked()) continue;
+           groupsList.insert(it);
        }
     }
     for (int i = 0; i < selection.count(); i++) {
        if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET) {
            if (selection.at(i)->parentItem() && selection.at(i)->parentItem()->type() == GROUPWIDGET) {
-               groupsList.insert(static_cast <QGraphicsItemGroup *> (selection.at(i)->parentItem()));
+               AbstractGroupItem *it = static_cast <AbstractGroupItem *> (selection.at(i)->parentItem());
+               while (it->parentItem() && it->parentItem()->type() == GROUPWIDGET) {
+                   it = static_cast <AbstractGroupItem *>(it->parentItem());
+               }
+               if (!it || it->isItemLocked()) continue;
+               groupsList.insert(it);
            }
            else {
+               AbstractClipItem *it = static_cast<AbstractClipItem *> (selection.at(i));
+               if (!it || it->isItemLocked()) continue;
                itemsList.insert(selection.at(i));
            }
        }
@@ -1308,8 +1351,11 @@ void CustomTrackView::groupSelectedItems(QList <QGraphicsItem *> selection, bool
         newGroup->translate(-diff.x(), -diff.y());
         //newGroup->translate((int) -rectUnion.left(), (int) -rectUnion.top() + 1);
 
-        scene()->addItem(newGroup);
         // Check if we are trying to include a group in a group
+       foreach (QGraphicsItemGroup *value, groupsList) {
+           newGroup->addItem(value);
+        }
+       
        foreach (QGraphicsItemGroup *value, groupsList) {
            QList<QGraphicsItem *> children = value->childItems();
            for (int i = 0; i < children.count(); i++) {
@@ -1324,6 +1370,7 @@ void CustomTrackView::groupSelectedItems(QList <QGraphicsItem *> selection, bool
        foreach (QGraphicsItem *value, itemsList) {
            newGroup->addItem(value);
         }
+        scene()->addItem(newGroup);
         KdenliveSettings::setSnaptopoints(snap);
        if (selectNewGroup) newGroup->setSelected(true);
     } else {
@@ -1595,10 +1642,16 @@ void CustomTrackView::insertClipCut(DocClipBase *clip, int in, int out)
 
 bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos)
 {
-    if (data->hasFormat("kdenlive/clip")) {
-        m_clipDrag = true;
-        m_scene->clearSelection();
-        resetSelectionGroup(false);
+    QPointF framePos = mapToScene(pos);
+    int track = framePos.y() / KdenliveSettings::trackheight();
+    m_scene->clearSelection();
+    m_dragItem = NULL;
+    resetSelectionGroup(false);
+    m_clipDrag = data->hasFormat("kdenlive/clip") || data->hasFormat("kdenlive/producerslist");
+    // This is not a clip drag, maybe effect or other...
+    if (!m_clipDrag) return false;
+    if (track < 0 || track > m_document->tracksCount() - 1 || m_document->trackInfoAt(m_document->tracksCount() - track - 1).isLocked) return true;
+    if (data->hasFormat("kdenlive/clip")) {    
         QStringList list = QString(data->data("kdenlive/clip")).split(';');
         DocClipBase *clip = m_document->getBaseClip(list.at(0));
         if (clip == NULL) {
@@ -1609,7 +1662,6 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos)
             emit displayMessage(i18n("Clip not ready"), ErrorMessage);
             return false;
         }
-        QPointF framePos = mapToScene(pos);
         ItemInfo info;
         info.startPos = GenTime();
         info.cropStart = GenTime(list.at(1).toInt(), m_document->fps());
@@ -1634,19 +1686,19 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos)
         QList <GenTime> offsetList;
         offsetList.append(info.endPos);
         updateSnapPoints(NULL, offsetList);
+       QStringList lockedTracks;
+       for (int i = 0; i < m_document->tracksCount(); i++) {
+           if (m_document->trackInfoAt(i).isLocked) lockedTracks << QString::number(m_document->tracksCount() - i - 1);
+       }
+       m_selectionGroup->setProperty("locked_tracks", lockedTracks);
         m_selectionGroup->setPos(framePos);
         scene()->addItem(m_selectionGroup);
         m_selectionGroup->setSelected(true);
-        return true;
     } else if (data->hasFormat("kdenlive/producerslist")) {
-        m_clipDrag = true;
         QStringList ids = QString(data->data("kdenlive/producerslist")).split(';');
-        m_scene->clearSelection();
-        resetSelectionGroup(false);
 
         QList <GenTime> offsetList;
         QList <ItemInfo> infoList;
-        QPointF framePos = mapToScene(pos);
         GenTime start = GenTime((int)(framePos.x() + 0.5), m_document->fps());
         int track = (int)(framePos.y() / m_tracksHeight);
         framePos.setX((int)(framePos.x() + 0.5));
@@ -1684,7 +1736,7 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos)
         if (!canBePastedTo(infoList, AVWIDGET)) {
             return true;
         }
-        m_selectionGroup = new AbstractGroupItem(m_document->fps());
+        if (ids.size() > 1) m_selectionGroup = new AbstractGroupItem(m_document->fps());
         start = GenTime();
         for (int i = 0; i < ids.size(); ++i) {
             QString clipData = ids.at(i);
@@ -1706,22 +1758,32 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos)
             start += info.cropDuration;
             offsetList.append(start);
             ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, getFrameWidth(), false);
-            m_selectionGroup->addItem(item);
+            if (ids.size() > 1) m_selectionGroup->addItem(item);
+           else m_dragItem = item;
+           item->setSelected(true);
             if (!clip->isPlaceHolder()) m_waitingThumbs.append(item);
         }
 
         updateSnapPoints(NULL, offsetList);
-        m_selectionGroup->setPos(framePos);
-        scene()->addItem(m_selectionGroup);
+       QStringList lockedTracks;
+       for (int i = 0; i < m_document->tracksCount(); i++) {
+           if (m_document->trackInfoAt(i).isLocked) lockedTracks << QString::number(m_document->tracksCount() - i - 1);
+       }   
+           
+        if (m_selectionGroup) {
+           m_selectionGroup->setProperty("locked_tracks", lockedTracks);
+           m_selectionGroup->setPos(framePos);
+           scene()->addItem(m_selectionGroup);
+       }
+       else if (m_dragItem) {
+           m_dragItem->setProperty("locked_tracks", lockedTracks);
+           m_dragItem->setPos(framePos);
+           scene()->addItem(m_dragItem);
+       }
         //m_selectionGroup->setZValue(10);
         m_thumbsTimer.start();
-        return true;
-
-    } else {
-        // the drag is not a clip (may be effect, ...)
-        m_clipDrag = false;
-        return false;
     }
+    return true;
 }
 
 
@@ -2643,7 +2705,11 @@ void CustomTrackView::dragMoveEvent(QDragMoveEvent * event)
             m_selectionGroup->setPos(pos);
             emit mousePosition((int)(m_selectionGroup->scenePos().x() + 0.5));
             event->acceptProposedAction();
-        } else {
+        } else if (m_dragItem) {
+           m_dragItem->setPos(pos);
+            emit mousePosition((int)(m_dragItem->scenePos().x() + 0.5));
+            event->acceptProposedAction();
+       } else {
             // Drag enter was not possible, try again at mouse position
             insertDropClips(event->mimeData(), event->pos());
             event->accept();
@@ -2655,20 +2721,26 @@ void CustomTrackView::dragMoveEvent(QDragMoveEvent * event)
 
 void CustomTrackView::dragLeaveEvent(QDragLeaveEvent * event)
 {
-    if (m_selectionGroup && m_clipDrag) {
+    if ((m_selectionGroup || m_dragItem) && m_clipDrag) {
         m_thumbsTimer.stop();
         m_waitingThumbs.clear();
-        QList<QGraphicsItem *> items = m_selectionGroup->childItems();
+        QList<QGraphicsItem *> items;
+       if (m_selectionGroup) items = m_selectionGroup->childItems();
+       else if (m_dragItem) items.append(m_dragItem);
         qDeleteAll(items);
-        scene()->destroyItemGroup(m_selectionGroup);
+        if (m_selectionGroup) scene()->destroyItemGroup(m_selectionGroup);
         m_selectionGroup = NULL;
+       m_dragItem = NULL;
+       event->accept();
     } else QGraphicsView::dragLeaveEvent(event);
 }
 
 void CustomTrackView::dropEvent(QDropEvent * event)
 {
-    if (m_selectionGroup && m_clipDrag) {
-        QList<QGraphicsItem *> items = m_selectionGroup->childItems();
+    if ((m_selectionGroup || m_dragItem) && m_clipDrag) {
+        QList<QGraphicsItem *> items;
+       if (m_selectionGroup) items = m_selectionGroup->childItems();
+       else if (m_dragItem) items.append(m_dragItem);
         resetSelectionGroup();
        m_dragItem = NULL;
         m_scene->clearSelection();
@@ -3001,12 +3073,10 @@ void CustomTrackView::addTrack(TrackInfo type, int ix)
 
     int maxHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22();
     for (int i = 0; i < m_guides.count(); i++) {
-        QLineF l = m_guides.at(i)->line();
-        l.setP2(QPointF(l.x2(), maxHeight));
-        m_guides.at(i)->setLine(l);
+        m_guides.at(i)->setLine(0, 0, 0, maxHeight - 1);
     }
 
-    m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight - 1);
+    m_cursorLine->setLine(0, 0, 0, maxHeight - 1);
     setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount());
     viewport()->update();
     //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged()));
@@ -3017,6 +3087,10 @@ void CustomTrackView::addTrack(TrackInfo type, int ix)
 
 void CustomTrackView::removeTrack(int ix)
 {
+    // Clear effect stack
+    clearSelection();
+    emit transitionItemSelected(NULL);
+
     // Delete track in MLT playlist
     m_document->renderer()->mltDeleteTrack(m_document->tracksCount() - ix);
     m_document->deleteTrack(m_document->tracksCount() - ix - 1);
@@ -3025,12 +3099,10 @@ void CustomTrackView::removeTrack(int ix)
     QRectF r(0, startY, sceneRect().width(), sceneRect().height() - startY);
     QList<QGraphicsItem *> selection = m_scene->items(r);
 
-    resetSelectionGroup();
-
     m_selectionGroup = new AbstractGroupItem(m_document->fps());
     scene()->addItem(m_selectionGroup);
     for (int i = 0; i < selection.count(); i++) {
-        if ((!selection.at(i)->parentItem()) && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
+        if ((selection.at(i) && !selection.at(i)->parentItem() && selection.at(i)->isEnabled()) && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
             m_selectionGroup->addItem(selection.at(i));
         }
     }
@@ -3074,11 +3146,9 @@ void CustomTrackView::removeTrack(int ix)
 
     int maxHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22();
     for (int i = 0; i < m_guides.count(); i++) {
-        QLineF l = m_guides.at(i)->line();
-        l.setP2(QPointF(l.x2(), maxHeight));
-        m_guides.at(i)->setLine(l);
+        m_guides.at(i)->setLine(0, 0, 0, maxHeight - 1);
     }
-    m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight - 1);
+    m_cursorLine->setLine(0, 0, 0, maxHeight - 1);
     setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount());
 
     m_selectedTrack = qMin(m_selectedTrack, m_document->tracksCount() - 1);
@@ -3581,6 +3651,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         }
         m_dragGuide = NULL;
         m_dragItem = NULL;
+       QGraphicsView::mouseReleaseEvent(event);
         return;
     } else if (m_operationMode == SPACER && m_selectionGroup) {
         int track;
@@ -4198,7 +4269,7 @@ void CustomTrackView::deleteSelectedClips()
     int groupCount = 0;
     int clipCount = 0;
     int transitionCount = 0;
-    // expand & destroy groups
+    // expand & destroy groups    
     for (int i = 0; i < itemList.count(); i++) {
         if (itemList.at(i)->type() == GROUPWIDGET) {
             groupCount++;
@@ -4225,20 +4296,19 @@ void CustomTrackView::deleteSelectedClips()
         } else if (itemList.at(i)->parentItem() && itemList.at(i)->parentItem()->type() == GROUPWIDGET)
             itemList.insert(i + 1, itemList.at(i)->parentItem());
     }
-
+    emit clipItemSelected(NULL);
+    emit transitionItemSelected(NULL);
     for (int i = 0; i < itemList.count(); i++) {
         if (itemList.at(i)->type() == AVWIDGET) {
             clipCount++;
             ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
             //kDebug()<<"// DELETE CLP AT: "<<item->info().startPos.frames(25);
             new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, true, true, deleteSelected);
-            emit clipItemSelected(NULL);
         } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
             transitionCount++;
             Transition *item = static_cast <Transition *>(itemList.at(i));
             //kDebug()<<"// DELETE TRANS AT: "<<item->info().startPos.frames(25);
             new AddTransitionCommand(this, item->info(), item->transitionEndTrack(), item->toXML(), true, true, deleteSelected);
-            emit transitionItemSelected(NULL);
         }
     }
     if (groupCount > 0 && clipCount == 0 && transitionCount == 0)
@@ -4419,7 +4489,8 @@ void CustomTrackView::doGroupClips(QList <ItemInfo> clipInfos, QList <ItemInfo>
     resetSelectionGroup();
     m_scene->clearSelection();
     if (!group) {
-        for (int i = 0; i < clipInfos.count(); i++) {
+       // ungroup, find main group to destroy it...
+       for (int i = 0; i < clipInfos.count(); i++) {
             ClipItem *clip = getClipItemAt(clipInfos.at(i).startPos, clipInfos.at(i).track);
             if (clip == NULL) continue;
             if (clip->parentItem() && clip->parentItem()->type() == GROUPWIDGET) {
@@ -5186,7 +5257,7 @@ void CustomTrackView::updatePositionEffects(ClipItem* item, ItemInfo info, bool
         if (effectPos != -1) {
             QDomElement effect = item->getEffectAtIndex(effectPos);
             int max = item->cropDuration().frames(m_document->fps());
-            int end = max + item->cropStart().frames(m_document->fps());
+            int end = max + item->cropStart().frames(m_document->fps()) - 1;
             if (start > max) {
                 // Make sure the fade effect is not longer than the clip
                 item->setFadeOut(max);
@@ -5207,7 +5278,7 @@ void CustomTrackView::updatePositionEffects(ClipItem* item, ItemInfo info, bool
         if (effectPos != -1) {
             QDomElement effect = item->getEffectAtIndex(effectPos);
             int max = item->cropDuration().frames(m_document->fps());
-            int end = max + item->cropStart().frames(m_document->fps());
+            int end = max + item->cropStart().frames(m_document->fps()) - 1;
             if (start > max) {
                 // Make sure the fade effect is not longer than the clip
                 item->setFadeOut(max);
@@ -5591,28 +5662,29 @@ void CustomTrackView::buildGuidesMenu(QMenu *goMenu) const
 
 void CustomTrackView::editGuide(const GenTime &oldPos, const GenTime &pos, const QString &comment)
 {
-    if (oldPos > GenTime() && pos > GenTime()) {
-        // move guide
+    if (comment.isEmpty() && pos < GenTime()) {
+       // Delete guide
+       bool found = false;
         for (int i = 0; i < m_guides.count(); i++) {
             if (m_guides.at(i)->position() == oldPos) {
-                Guide *item = m_guides.at(i);
-                item->updateGuide(pos, comment);
+                delete m_guides.takeAt(i);
+                found = true;
                 break;
             }
         }
-    } else if (pos > GenTime()) addGuide(pos, comment);
-    else {
-        // remove guide
-        bool found = false;
+        if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
+    }
+    
+    else if (oldPos >= GenTime()) {
+        // move guide
         for (int i = 0; i < m_guides.count(); i++) {
             if (m_guides.at(i)->position() == oldPos) {
-                delete m_guides.takeAt(i);
-                found = true;
+                Guide *item = m_guides.at(i);
+                item->updateGuide(pos, comment);
                 break;
             }
         }
-        if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
-    }
+    } else addGuide(pos, comment);
     qSort(m_guides.begin(), m_guides.end(), sortGuidesList);
     m_document->syncGuides(m_guides);
 }
@@ -5702,7 +5774,7 @@ void CustomTrackView::slotDeleteGuide(int guidePos)
     bool found = false;
     for (int i = 0; i < m_guides.count(); i++) {
         if (m_guides.at(i)->position() == pos) {
-            EditGuideCommand *command = new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true);
+            EditGuideCommand *command = new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(-1), QString(), true);
             m_commandStack->push(command);
             found = true;
             break;
@@ -5715,7 +5787,7 @@ void CustomTrackView::slotDeleteGuide(int guidePos)
 void CustomTrackView::slotDeleteTimeLineGuide()
 {
     if (m_dragGuide == NULL) return;
-    EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), GenTime(), QString(), true);
+    EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), GenTime(-1), QString(), true);
     m_commandStack->push(command);
 }
 
@@ -5725,7 +5797,7 @@ void CustomTrackView::slotDeleteAllGuides()
     QUndoCommand *deleteAll = new QUndoCommand();
     deleteAll->setText("Delete all guides");
     for (int i = 0; i < m_guides.count(); i++) {
-        new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true, deleteAll);
+        new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(-1), QString(), true, deleteAll);
     }
     m_commandStack->push(deleteAll);
 }
@@ -5756,11 +5828,9 @@ void CustomTrackView::setScale(double scaleFactor, double verticalScale)
     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 - 1);
+       m_cursorLine->setLine(0, 0, 0, newHeight - 1);
         for (int i = 0; i < m_guides.count(); i++) {
-            QLineF l = m_guides.at(i)->line();
-            l.setP2(QPointF(l.x2(), newHeight));
-            m_guides.at(i)->setLine(l);
+            m_guides.at(i)->setLine(0, 0, 0, newHeight - 1);
         }
         setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount());
     }
@@ -6429,7 +6499,11 @@ void CustomTrackView::slotConfigTracks(int ix)
 void CustomTrackView::deleteTimelineTrack(int ix, TrackInfo trackinfo)
 {
     if (m_document->tracksCount() < 2) return;
-    double startY = ix * m_tracksHeight + 1 + m_tracksHeight / 2;
+    // Clear effect stack
+    clearSelection();
+    emit transitionItemSelected(NULL);
+    
+    double startY = ix * m_tracksHeight + 1 + m_tracksHeight / 2;    
     QRectF r(0, startY, sceneRect().width(), m_tracksHeight / 2 - 1);
     QList<QGraphicsItem *> selection = m_scene->items(r);
     QUndoCommand *deleteTrack = new QUndoCommand();
@@ -7271,6 +7345,7 @@ void CustomTrackView::insertZoneOverwrite(QStringList data, int in)
 
 void CustomTrackView::clearSelection(bool emitInfo)
 {
+    if (m_dragItem) m_dragItem->setSelected(false);
     resetSelectionGroup();
     scene()->clearSelection();
     m_dragItem = NULL;