]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
Optimize seek requests
[kdenlive] / src / customtrackview.cpp
index 04f80b8defbf8cef55f17404aadbfe402dfcfcf3..84513036bad2dd0542abc085c0bd46a3147122e2 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;
         }
@@ -1031,11 +1043,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 +1059,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);
@@ -1577,9 +1598,15 @@ void CustomTrackView::insertClipCut(DocClipBase *clip, int in, int out)
         return;
     }
 
-    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);
+    // Add refresh command for undo
+    QUndoCommand *addCommand = new QUndoCommand();
+    addCommand->setText(i18n("Add timeline clip"));
+    new RefreshMonitorCommand(this, false, true, addCommand);
+    new AddTimelineClipCommand(this, clip->toXML(), clip->getId(), pasteInfo, EffectsList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, true, false, addCommand);
+    new RefreshMonitorCommand(this, true, false, addCommand);
+    updateTrackDuration(pasteInfo.track, addCommand);
+    
+    m_commandStack->push(addCommand);
 
     selectClip(true, false);
     // Automatic audio split
@@ -2432,7 +2459,7 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo
 
         ItemInfo clipinfo = item->info();
         clipinfo.track = m_document->tracksCount() - clipinfo.track;
-        bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, info.endPos - info.startPos);
+        bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, info.endPos - info.startPos, false);
         if (success) {
             item->resizeEnd((int) info.endPos.frames(m_document->fps()));
             setDocumentModified();
@@ -2670,6 +2697,9 @@ void CustomTrackView::dropEvent(QDropEvent * event)
         QUndoCommand *addCommand = new QUndoCommand();
         addCommand->setText(i18n("Add timeline clip"));
         QList <ClipItem *> brokenClips;
+       
+       // Add refresh command for undo
+       new RefreshMonitorCommand(this, false, true, addCommand);
 
         for (int i = 0; i < items.count(); i++) {
             ClipItem *item = static_cast <ClipItem *>(items.at(i));
@@ -2710,6 +2740,9 @@ void CustomTrackView::dropEvent(QDropEvent * event)
             }
             item->setSelected(true);
         }
+        // Add refresh command for redo
+       new RefreshMonitorCommand(this, false, false, addCommand);
+       
         qDeleteAll(brokenClips);
         brokenClips.clear();
         if (addCommand->childCount() > 0) m_commandStack->push(addCommand);
@@ -4260,7 +4293,7 @@ void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependant
         item->updateRectGeometry();
         if (item->cropDuration().frames(m_document->fps()) != endPos)
             item->resizeEnd((int) info.startPos.frames(m_document->fps()) + endPos - 1);
-        updatePositionEffects(item, info);
+        updatePositionEffects(item, info, false);
         setDocumentModified();
     } else {
         emit displayMessage(i18n("Invalid clip"), ErrorMessage);
@@ -5174,7 +5207,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);
@@ -5195,7 +5228,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);
@@ -5579,28 +5612,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);
 }
@@ -5690,7 +5724,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;
@@ -5703,7 +5737,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);
 }
 
@@ -5713,7 +5747,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);
 }
@@ -6422,6 +6456,7 @@ void CustomTrackView::deleteTimelineTrack(int ix, TrackInfo trackinfo)
     QList<QGraphicsItem *> selection = m_scene->items(r);
     QUndoCommand *deleteTrack = new QUndoCommand();
     deleteTrack->setText("Delete track");
+    new RefreshMonitorCommand(this, false, true, deleteTrack);
 
     // Delete all clips in selected track
     for (int i = 0; i < selection.count(); i++) {
@@ -6442,6 +6477,7 @@ void CustomTrackView::deleteTimelineTrack(int ix, TrackInfo trackinfo)
     }
 
     new AddTrackCommand(this, ix, trackinfo, false, deleteTrack);
+    new RefreshMonitorCommand(this, true, false, deleteTrack);
     m_commandStack->push(deleteTrack);
 }