]> git.sesse.net Git - kdenlive/commitdiff
Fix crashes when cutting multiple selected clips
authorTill Theato <root@ttill.de>
Sun, 15 Aug 2010 08:48:27 +0000 (08:48 +0000)
committerTill Theato <root@ttill.de>
Sun, 15 Aug 2010 08:48:27 +0000 (08:48 +0000)
svn path=/trunk/kdenlive/; revision=4720

src/customtrackview.cpp
src/effectstackview.cpp

index 1730722c418ea0aee77d50aec8ffdac385d73b8d..61e096a92b1ca0233b41924ef6a375fce3576071 100644 (file)
@@ -1872,10 +1872,7 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo
             m_blockRefresh = false;
             return NULL;
         }
-        if (item->parentItem()) {
-            // Item is part of a group, reset group
-            resetSelectionGroup();
-        }
+
         kDebug() << "/////////  CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25);
 
         if (execute) m_document->renderer()->mltCutClip(m_document->tracksCount() - info.track, cutTime);
@@ -3597,22 +3594,49 @@ void CustomTrackView::cutSelectedClips()
 {
     QList<QGraphicsItem *> itemList = scene()->selectedItems();
     GenTime currentPos = GenTime(m_cursorPos, m_document->fps());
-    QList <QGraphicsItem *> skipList;
     for (int i = 0; i < itemList.count(); ++i) {
-        if (skipList.indexOf(itemList.at(i)) != -1)
+        if (!itemList.at(i))
             continue;
         if (itemList.at(i)->type() == AVWIDGET) {
             ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
             if (item->parentItem() && item->parentItem() != m_selectionGroup) {
-                skipList.append(item->parentItem()->childItems());
+                // remove all group children from itemList so we do not attempt to cut them twice
+                QList <QGraphicsItem *> children = item->parentItem()->childItems();
+                QList <int> toRemove;
+                for (int j = 0; j < children.count(); ++j) {
+                    for (int k = 0; k < itemList.count(); ++k) {
+                        if (children.at(j)->pos() == itemList.at(k)->pos()
+                            && children.at(j)->boundingRect() == itemList.at(k)->boundingRect()) {
+                            toRemove.append(k);
+                        }
+                    }
+                }
+                for (int j = 0; j < toRemove.count(); ++j)
+                    itemList.removeAt(toRemove.at(j));
+
                 razorGroup((AbstractGroupItem *)item->parentItem(), currentPos);
             } else if (currentPos > item->startPos() && currentPos < item->endPos()) {
                 RazorClipCommand *command = new RazorClipCommand(this, item->info(), currentPos);
                 m_commandStack->push(command);
             }
         } else if (itemList.at(i)->type() == GROUPWIDGET && itemList.at(i) != m_selectionGroup) {
-            skipList.append(itemList.at(i)->childItems());
-            razorGroup((AbstractGroupItem *)itemList.at(i), currentPos);
+            // remove all group children from itemList so we do not attempt to cut them twice
+            AbstractGroupItem *group = static_cast<AbstractGroupItem *>(itemList.at(i));
+
+            QList <QGraphicsItem *> children = itemList.at(i)->childItems();
+            QList <int> toRemove;
+            for (int j = 0; j < children.count(); ++j) {
+                for (int k = 0; k < itemList.count(); ++k) {
+                    if (children.at(j)->pos() == itemList.at(k)->pos()
+                        && children.at(j)->boundingRect() == itemList.at(k)->boundingRect()) {
+                        toRemove.append(k);
+                    }
+                }
+            }
+            for (int j = 0; j < toRemove.count(); ++j)
+                itemList.removeAt(toRemove.at(j));
+
+            razorGroup(group, currentPos);
         }
     }
 }
index 8f11455ba3e583ecae12c88a835b61f7d944c63c..1bbf9fda2788e7d60bd0b51a844371fc349e847e 100644 (file)
@@ -410,7 +410,7 @@ void EffectStackView::slotCheckMonitorPosition(int renderPos)
 
 void EffectStackView::slotRenderPos(int pos)
 {
-    if (m_clipref)
+    if (m_clipref && m_effectedit)
         m_effectedit->slotSyncEffectsPos(pos - m_clipref->startPos().frames(KdenliveSettings::project_fps()));
 }