]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
Select all should not select items in locked tracks: http://kdenlive.org/mantis/view...
[kdenlive] / src / customtrackview.cpp
index 01274517a8aa2b7c74db17288f38b07a016498c0..263db774fdc4ac80044384a0ebb5776cb15aa615 100644 (file)
@@ -731,8 +731,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 +819,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 +835,21 @@ 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) {
+           if (m_selectionGroup) {
+               m_selectionGroup->setProperty("y_absolute", yOffset);
+               m_selectionGroup->setProperty("locked_tracks", lockedTracks);
+           }
+            if (dragGroup) {
                 dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
-               dragGroup->setProperty("y_absolute", mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y());
+               dragGroup->setProperty("y_absolute", yOffset);
+               dragGroup->setProperty("locked_tracks", lockedTracks);
             }
             break;
         }
@@ -896,6 +908,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;
     }
@@ -1031,11 +1047,15 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
 
         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 +1063,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);
@@ -1269,15 +1294,21 @@ 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));
+           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());
+               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));
            }
        }
@@ -1595,10 +1626,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 +1646,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 +1670,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 +1720,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 +1742,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 +2689,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 +2705,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();
@@ -5186,7 +5242,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 +5263,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 +5647,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 +5759,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 +5772,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 +5782,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);
 }