]> git.sesse.net Git - kdenlive/commitdiff
Fix several timeline corruption when moving groups: http://kdenlive.org/mantis/view...
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 27 Oct 2012 21:28:08 +0000 (23:28 +0200)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 27 Oct 2012 21:28:08 +0000 (23:28 +0200)
src/abstractgroupitem.cpp
src/customtrackview.cpp
src/customtrackview.h
src/renderer.cpp

index f2a475f6b2bbc5ef02bac47889a9bad9b5a9515d..9442aa2ba08c227bfc31e582e675790832489e0e 100644 (file)
@@ -115,7 +115,7 @@ QPainterPath AbstractGroupItem::groupShape(GRAPHICSRECTITEM type, QPointF offset
 void AbstractGroupItem::addItem(QGraphicsItem * item)
 {
     addToGroup(item);
-    //fixItemRect();
+    item->setFlag(QGraphicsItem::ItemIsMovable, false);
 }
 
 void AbstractGroupItem::fixItemRect()
index d78def43d8ab6502d3cc783a0fdc60e9691cc7de..addd479fc335faed2f50d77d86aba51fa321aab8 100644 (file)
@@ -424,9 +424,9 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
 
     if (event->buttons() != Qt::NoButton) {
         bool move = (event->pos() - m_clickEvent).manhattanLength() >= QApplication::startDragDistance();
+       if (m_dragItem && move) m_clipDrag = true;
         if (m_dragItem && m_tool == SELECTTOOL) {
-            if (m_operationMode == MOVE && move) {
-               //m_dragItem->setProperty("y_absolute", event->pos().y());
+            if (m_operationMode == MOVE && m_clipDrag) {
                 QGraphicsView::mouseMoveEvent(event);
                 // If mouse is at a border of the view, scroll
                 if (pos < 5) {
@@ -726,6 +726,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
 {
     setFocus(Qt::MouseFocusReason);
     m_menuPosition = QPoint();
+    m_clipDrag = false;
 
     // special cases (middle click button or ctrl / shift click
     if (event->button() == Qt::MidButton) {
@@ -803,17 +804,19 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
             collisionClip = static_cast <AbstractClipItem *>(collisionList.at(ct));
             if (collisionClip->isItemLocked())
                 break;
-            if (collisionClip == m_dragItem)
+            if (collisionClip == m_dragItem) {
                 collisionClip = NULL;
-            else
+           }
+            else {
                 m_dragItem = collisionClip;
+           }
             found = true;
            m_dragItem->setProperty("y_absolute", mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y());
             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) {
-                // kDebug()<<"// KLIK FOUND GRP: "<<m_dragItem->sceneBoundingRect();
                 dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
+               dragGroup->setProperty("y_absolute", mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y());
             }
             break;
         }
@@ -823,13 +826,14 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         if (m_dragItem) emit clipItemSelected(NULL);
         m_dragItem = NULL;
     }
-#if QT_VERSION >= 0x040600
+#if QT_VERSION >= 0x040800
     // Add shadow to dragged item, currently disabled because of painting artifacts
-    //TODO: re-enable when fixed
-    /*QGraphicsDropShadowEffect *eff = new QGraphicsDropShadowEffect();
-    eff->setBlurRadius(5);
-    eff->setOffset(3, 3);
-    m_dragItem->setGraphicsEffect(eff);*/
+    /*if (m_dragItem) {
+       QGraphicsDropShadowEffect *eff = new QGraphicsDropShadowEffect();
+       eff->setBlurRadius(5);
+       eff->setOffset(3, 3);
+       m_dragItem->setGraphicsEffect(eff);
+    }*/
 #endif
     if (m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) {
         // update transition menu action
@@ -917,8 +921,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
                     if (item->isItemLocked()) continue;
                     offsetList.append(item->startPos());
                     offsetList.append(item->endPos());
-                    m_selectionGroup->addToGroup(selection.at(i));
-                    selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
+                    m_selectionGroup->addItem(selection.at(i));
                 } else if (/*selection.at(i)->parentItem() == 0 && */selection.at(i)->type() == GROUPWIDGET) {
                     if (static_cast<AbstractGroupItem *>(selection.at(i))->isItemLocked()) continue;
                     QList<QGraphicsItem *> children = selection.at(i)->childItems();
@@ -927,13 +930,10 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
                         offsetList.append(item->startPos());
                         offsetList.append(item->endPos());
                     }
-                    m_selectionGroup->addToGroup(selection.at(i));
-                    selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
+                    m_selectionGroup->addItem(selection.at(i));
                 } else if (selection.at(i)->parentItem() && !selection.contains(selection.at(i)->parentItem())) {
                     if (static_cast<AbstractGroupItem *>(selection.at(i)->parentItem())->isItemLocked()) continue;
-                    //AbstractGroupItem *grp = static_cast<AbstractGroupItem *>(selection.at(i)->parentItem());
-                    m_selectionGroup->addToGroup(selection.at(i)->parentItem());
-                    selection.at(i)->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
+                    m_selectionGroup->addItem(selection.at(i)->parentItem());
                 }
             }
             m_spacerOffset = m_selectionGroup->sceneBoundingRect().left() - (int)(mapToScene(m_clickEvent).x());
@@ -953,7 +953,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         } else {
             seekCursorPos((int)(mapToScene(event->x(), 0).x()));
         }
-        //QGraphicsView::mousePressEvent(event);
+        QGraphicsView::mousePressEvent(event);
         event->ignore();
         return;
     }
@@ -980,12 +980,15 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
     }
 
     bool itemSelected = false;
-    if (m_dragItem->isSelected())
+    if (m_dragItem->isSelected()) {
         itemSelected = true;
-    else if (m_dragItem->parentItem() && m_dragItem->parentItem()->isSelected())
+    }
+    else if (m_dragItem->parentItem() && m_dragItem->parentItem()->isSelected()) {
         itemSelected = true;
-    else if (dragGroup && dragGroup->isSelected())
+    }
+    else if (dragGroup && dragGroup->isSelected()) {
         itemSelected = true;
+    }
 
     if ((event->modifiers() == Qt::ControlModifier) || itemSelected == false) {
         if (event->modifiers() != Qt::ControlModifier) {
@@ -1000,10 +1003,16 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET) {
             dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
         }
+
         bool selected = !m_dragItem->isSelected();
-        /*if (dragGroup)
+       QGraphicsView::mousePressEvent(event);
+         
+        if (dragGroup) {
             dragGroup->setSelected(selected);
-        else*/
+           if (dragGroup->parentItem())
+               dragGroup->parentItem()->setSelected(selected);
+       }
+        else
             m_dragItem->setSelected(selected);
        if (selected == false) {
            m_dragItem = NULL;
@@ -1016,6 +1025,20 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
        }
        else updateClipTypeActions(NULL);
     }
+    else {
+       QGraphicsView::mousePressEvent(event);
+       if (m_selectionGroup) {
+           QList<QGraphicsItem *> children = m_selectionGroup->childItems();
+           for (int i = 0; i < children.count(); i++) {
+               children.at(i)->setSelected(itemSelected);
+           }
+            m_selectionGroup->setSelected(itemSelected);
+           
+       }
+       if (dragGroup)
+            dragGroup->setSelected(itemSelected);
+       m_dragItem->setSelected(itemSelected);
+    }
 
     if (collisionClip != NULL || m_dragItem == NULL) {
         if (m_dragItem && m_dragItem->type() == AVWIDGET && !m_dragItem->isItemLocked()) {
@@ -1028,7 +1051,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
 
     // If clicked item is selected, allow move
     //if (!(event->modifiers() | Qt::ControlModifier) && m_operationMode == NONE)
-    QGraphicsView::mousePressEvent(event);
+    //QGraphicsView::mousePressEvent(event);
 
     if (m_dragItem) {
        m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps())), (int)(event->pos().y() - m_dragItem->pos().y()));
@@ -1153,8 +1176,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
     }
 
     m_blockRefresh = false;
-    //kDebug()<<pos;
-    QGraphicsView::mousePressEvent(event);
 }
 
 void CustomTrackView::rebuildGroup(int childTrack, GenTime childPos)
@@ -1175,15 +1196,13 @@ void CustomTrackView::rebuildGroup(int childTrack, GenTime childPos)
 void CustomTrackView::rebuildGroup(AbstractGroupItem *group)
 {
     if (group) {
-        resetSelectionGroup(false);
-        m_scene->clearSelection();
-
         QList <QGraphicsItem *> children = group->childItems();
         m_document->clipManager()->removeGroup(group);
-        scene()->destroyItemGroup(group);
-        for (int i = 0; i < children.count(); i++)
-            children.at(i)->setSelected(true);
-        groupSelectedItems(false, true);
+       /*for (int i = 0; i < children.count(); i++) {
+           group->removeFromGroup(children.at(i));
+       }*/
+       scene()->destroyItemGroup(group);
+        groupSelectedItems(children, false, true, true);
     }
 }
 
@@ -1196,6 +1215,7 @@ void CustomTrackView::resetSelectionGroup(bool selectItems)
 
         QList<QGraphicsItem *> children = m_selectionGroup->childItems();
         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()) {
@@ -1207,33 +1227,46 @@ void CustomTrackView::resetSelectionGroup(bool selectItems)
                 children.at(i)->setSelected(selectItems);
             }
         }
-
-        m_selectionGroup = NULL;
         KdenliveSettings::setSnaptopoints(snap);
     }
 }
 
-void CustomTrackView::groupSelectedItems(bool force, bool createNewGroup)
+void CustomTrackView::groupSelectedItems(QList <QGraphicsItem *> selection, bool force, bool createNewGroup, bool selectNewGroup)
 {
     if (m_selectionGroup) {
         kDebug() << "///// ERROR, TRYING TO OVERRIDE EXISTING GROUP";
         return;
     }
-    QList<QGraphicsItem *> selection = m_scene->selectedItems();
-    if (m_dragItem && !selection.contains(m_dragItem)) {
-       selection << m_dragItem;
+    if (selection.isEmpty()) selection = m_scene->selectedItems();
+    // Split groups and items
+    QSet <QGraphicsItemGroup *> groupsList;
+    QSet <QGraphicsItem *> itemsList;
+
+    for (int i = 0; i < selection.count(); i++) {
+       if (selection.at(i)->type() == GROUPWIDGET) {
+           groupsList.insert(static_cast<AbstractGroupItem*> (selection.at(i)));
+       }
+    }
+    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()));
+           }
+           else {
+               itemsList.insert(selection.at(i));
+           }
+       }
     }
-    if (selection.isEmpty()) return;
+    if (itemsList.isEmpty() && groupsList.isEmpty()) return;
+    
     QRectF rectUnion;
     // Find top left position of selection
-    for (int i = 0; i < selection.count(); i++) {
-        if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
-            rectUnion = rectUnion.united(selection.at(i)->sceneBoundingRect());
-        } else if (selection.at(i)->parentItem()) {
-            rectUnion = rectUnion.united(selection.at(i)->parentItem()->sceneBoundingRect());
-        }
+    foreach (const QGraphicsItemGroup *value, groupsList) {
+        rectUnion = rectUnion.united(value->sceneBoundingRect());
+    }
+    foreach (const QGraphicsItem *value, itemsList) {
+        rectUnion = rectUnion.united(value->sceneBoundingRect());
     }
-
     if (force || selection.count() > 1) {
         bool snap = KdenliveSettings::snaptopoints();
         KdenliveSettings::setSnaptopoints(false);
@@ -1245,32 +1278,23 @@ void CustomTrackView::groupSelectedItems(bool force, bool createNewGroup)
             //newGroup->translate((int) -rectUnion.left(), (int) -rectUnion.top() + 1);
 
             scene()->addItem(newGroup);
-
             // Check if we are trying to include a group in a group
-            QList <AbstractGroupItem *> groups;
-            for (int i = 0; i < selection.count(); i++) {
-                if (selection.at(i)->type() == GROUPWIDGET && !groups.contains(static_cast<AbstractGroupItem *>(selection.at(i))))
-                    groups.append(static_cast<AbstractGroupItem *>(selection.at(i)));
-                else if (selection.at(i)->parentItem() && !groups.contains(static_cast<AbstractGroupItem *>(selection.at(i)->parentItem())))
-                    groups.append(static_cast<AbstractGroupItem *>(selection.at(i)->parentItem()));
-            }
-            if (!groups.isEmpty()) {
-                // ungroup previous groups
-                while (!groups.isEmpty()) {
-                    AbstractGroupItem *grp = groups.takeFirst();
-                    m_document->clipManager()->removeGroup(grp);
-                    scene()->destroyItemGroup(grp);
-                }
-                selection = m_scene->selectedItems();
-            }
+           foreach (QGraphicsItemGroup *value, groupsList) {
+               QList<QGraphicsItem *> children = value->childItems();
+               for (int i = 0; i < children.count(); i++) {
+                   if (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET)
+                       itemsList.insert(children.at(i));
+               }
+               AbstractGroupItem *grp = static_cast<AbstractGroupItem *>(value);
+               m_document->clipManager()->removeGroup(grp);
+               scene()->destroyItemGroup(grp);
+           }
 
-            for (int i = 0; i < selection.count(); i++) {
-                if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET) {
-                    newGroup->addToGroup(selection.at(i));
-                    selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
-                }
+           foreach (QGraphicsItem *value, itemsList) {
+                newGroup->addItem(value);
             }
             KdenliveSettings::setSnaptopoints(snap);
+           if (selectNewGroup) newGroup->setSelected(true);
         } else {
             m_selectionGroup = new AbstractGroupItem(m_document->fps());
             m_selectionGroup->setPos(rectUnion.left(), rectUnion.top() - 1);
@@ -1279,16 +1303,17 @@ void CustomTrackView::groupSelectedItems(bool force, bool createNewGroup)
             m_selectionGroup->translate(- diff.x(), -diff.y());
 
             scene()->addItem(m_selectionGroup);
-            for (int i = 0; i < selection.count(); i++) {
-                if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
-                    m_selectionGroup->addToGroup(selection.at(i));
-                    selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
-                }
+            foreach (QGraphicsItemGroup *value, groupsList) {
+                m_selectionGroup->addItem(value);
+            }
+            foreach (QGraphicsItem *value, itemsList) {
+                m_selectionGroup->addItem(value);
             }
             KdenliveSettings::setSnaptopoints(snap);
             if (m_selectionGroup) {
                 m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps());
                 m_selectionGroupInfo.track = m_selectionGroup->track();
+               if (selectNewGroup) m_selectionGroup->setSelected(true);
             }
         }
     } else resetSelectionGroup();
@@ -1568,8 +1593,7 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos)
         }
         m_selectionGroup = new AbstractGroupItem(m_document->fps());
         ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, getFrameWidth());
-        m_selectionGroup->addToGroup(item);
-        item->setFlag(QGraphicsItem::ItemIsMovable, false);
+        m_selectionGroup->addItem(item);
 
         QList <GenTime> offsetList;
         offsetList.append(info.endPos);
@@ -1646,8 +1670,7 @@ 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);
-            item->setFlag(QGraphicsItem::ItemIsMovable, false);
-            m_selectionGroup->addToGroup(item);
+            m_selectionGroup->addItem(item);
             if (!clip->isPlaceHolder()) m_waitingThumbs.append(item);
         }
 
@@ -2607,6 +2630,7 @@ void CustomTrackView::dropEvent(QDropEvent * event)
     if (m_selectionGroup && m_clipDrag) {
         QList<QGraphicsItem *> items = m_selectionGroup->childItems();
         resetSelectionGroup();
+       m_dragItem = NULL;
         m_scene->clearSelection();
         bool hasVideoClip = false;
         QUndoCommand *addCommand = new QUndoCommand();
@@ -2682,11 +2706,12 @@ void CustomTrackView::dropEvent(QDropEvent * event)
 
         m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
         if (items.count() > 1) {
-            groupSelectedItems(true);
+            groupSelectedItems(items, true);
         } else if (items.count() == 1) {
             m_dragItem = static_cast <AbstractClipItem *>(items.at(0));
             emit clipItemSelected((ClipItem*) m_dragItem, false);
         }
+        m_document->renderer()->doRefresh();
         event->setDropAction(Qt::MoveAction);
         event->accept();
 
@@ -2874,8 +2899,7 @@ void CustomTrackView::addTrack(TrackInfo type, int ix)
         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)) {
-                m_selectionGroup->addToGroup(selection.at(i));
-                selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
+                m_selectionGroup->addItem(selection.at(i));
             }
         }
         // Move graphic items
@@ -2959,8 +2983,7 @@ void CustomTrackView::removeTrack(int ix)
     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)) {
-            m_selectionGroup->addToGroup(selection.at(i));
-            selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
+            m_selectionGroup->addItem(selection.at(i));
         }
     }
     // Move graphic items
@@ -3337,11 +3360,9 @@ void CustomTrackView::insertSpace(QList<ItemInfo> clipsToMove, QList<ItemInfo> t
             clip = getClipItemAtStart(clipsToMove.at(i).startPos + offset, clipsToMove.at(i).track);
             if (clip) {
                 if (clip->parentItem()) {
-                    m_selectionGroup->addToGroup(clip->parentItem());
-                    clip->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
+                    m_selectionGroup->addItem(clip->parentItem());
                 } else {
-                    m_selectionGroup->addToGroup(clip);
-                    clip->setFlag(QGraphicsItem::ItemIsMovable, false);
+                    m_selectionGroup->addItem(clip);
                 }
                 if (trackClipStartList.value(m_document->tracksCount() - clipsToMove.at(i).track) == -1 || clipsToMove.at(i).startPos.frames(m_document->fps()) < trackClipStartList.value(m_document->tracksCount() - clipsToMove.at(i).track))
                     trackClipStartList[m_document->tracksCount() - clipsToMove.at(i).track] = clipsToMove.at(i).startPos.frames(m_document->fps());
@@ -3353,11 +3374,9 @@ void CustomTrackView::insertSpace(QList<ItemInfo> clipsToMove, QList<ItemInfo> t
             transition = getTransitionItemAtStart(transToMove.at(i).startPos + offset, transToMove.at(i).track);
             if (transition) {
                 if (transition->parentItem()) {
-                    m_selectionGroup->addToGroup(transition->parentItem());
-                    transition->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
+                    m_selectionGroup->addItem(transition->parentItem());
                 } else {
-                    m_selectionGroup->addToGroup(transition);
-                    transition->setFlag(QGraphicsItem::ItemIsMovable, false);
+                    m_selectionGroup->addItem(transition);
                 }
                 if (trackTransitionStartList.value(m_document->tracksCount() - transToMove.at(i).track) == -1 || transToMove.at(i).startPos.frames(m_document->fps()) < trackTransitionStartList.value(m_document->tracksCount() - transToMove.at(i).track))
                     trackTransitionStartList[m_document->tracksCount() - transToMove.at(i).track] = transToMove.at(i).startPos.frames(m_document->fps());
@@ -3475,16 +3494,22 @@ void CustomTrackView::checkScrolling()
 void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
 {
     if (m_moveOpMode == SEEK) m_moveOpMode = NONE;
-    if (!m_controlModifier) QGraphicsView::mouseReleaseEvent(event);
-    setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
-#if QT_VERSION >= 0x040600
-    if (m_dragItem) m_dragItem->setGraphicsEffect(NULL);
+    if (!m_controlModifier && m_operationMode != RUBBERSELECTION) {
+       //event->accept();
+       if (m_clipDrag) QGraphicsView::mouseReleaseEvent(event);
+    }
+    m_clipDrag = false;
+    //setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
+#if QT_VERSION >= 0x040800
+    if (m_dragItem) {
+       m_dragItem->setGraphicsEffect(NULL);
+    }
 #endif
     if (m_scrollTimer.isActive()) m_scrollTimer.stop();
     if (event->button() == Qt::MidButton) {
         return;
     }
-    setDragMode(QGraphicsView::NoDrag);
+
     if (m_operationMode == MOVEGUIDE) {
         setCursor(Qt::ArrowCursor);
         m_operationMode = NONE;
@@ -3554,20 +3579,25 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                 updateTrackDuration(track, command);
                 m_commandStack->push(command);
                 if (track != -1) track = m_document->tracksCount() - track;
-                kDebug() << "SPACER TRACK:" << track;
                 m_document->renderer()->mltInsertSpace(trackClipStartList, trackTransitionStartList, track, timeOffset, GenTime());
                 setDocumentModified();
             }
         }
-        for (int i = 0; i < groups.count(); i++)
+        resetSelectionGroup();
+        for (int i = 0; i < groups.count(); i++) {
            rebuildGroup(groups.at(i));
+       }
 
-       resetSelectionGroup();
        
         clearSelection();
        
         m_operationMode = NONE;
     } else if (m_operationMode == RUBBERSELECTION) {
+       //event->accept();
+       QGraphicsView::mouseReleaseEvent(event);
+       setDragMode(QGraphicsView::NoDrag);
+       setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
+       if (event->modifiers() != Qt::ControlModifier) m_dragItem = NULL;
         resetSelectionGroup();
         groupSelectedItems();
         m_operationMode = NONE;
@@ -3734,10 +3764,12 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             // Moving several clips. We need to delete them and readd them to new position,
             // or they might overlap each other during the move
             QGraphicsItemGroup *group;
-            if (m_selectionGroup)
+            if (m_selectionGroup) {
                 group = static_cast <QGraphicsItemGroup *>(m_selectionGroup);
-            else
+           }
+            else {
                 group = static_cast <QGraphicsItemGroup *>(m_dragItem->parentItem());
+           }
             QList<QGraphicsItem *> items = group->childItems();
             QList<ItemInfo> clipsToMove;
             QList<ItemInfo> transitionsToMove;
@@ -3821,31 +3853,43 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                 if (m_selectionGroup) {
                     m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps());
                     m_selectionGroupInfo.track = m_selectionGroup->track();
-
-                   QList <AbstractGroupItem*> groupList;
-                    for (int i = 0; i < items.count(); ++i) {
-                        if (items.at(i)->type() == GROUPWIDGET) {
-                           AbstractGroupItem* group = (AbstractGroupItem*)items.at(i);
-                           if (!groupList.contains(group)) groupList.append(group);
-                            items.removeAt(i);
-                            --i;
+                   items = m_selectionGroup->childItems();
+                   resetSelectionGroup(false);
+
+                   QSet <QGraphicsItem*> groupList;
+                   QSet <QGraphicsItem*> itemList;
+                   while (!items.isEmpty()) {
+                       QGraphicsItem *first = items.takeFirst();
+                       if (first->type() == GROUPWIDGET) {
+                           if (first != m_selectionGroup) {
+                               groupList.insert(first);
+                           }
                         }
-                    }
-                    for (int i = 0; i < groupList.count(); ++i) {
-                       rebuildGroup(groupList.at(i));
+                        else if (first->type() == AVWIDGET || first->type() == TRANSITIONWIDGET) {
+                           if (first->parentItem() && first->parentItem()->type() == GROUPWIDGET) {
+                               if (first->parentItem() != m_selectionGroup) {
+                                   groupList.insert(first->parentItem());
+                               }
+                               else itemList.insert(first);
+                           }
+                           else itemList.insert(first);
+                       }
                    }
-                    
-                    for (int i = 0; i < items.count(); ++i) {
-                        if (items.at(i)) {
-                            items.at(i)->setSelected(true);
-                            if (items.at(i)->parentItem())
-                                items.at(i)->parentItem()->setSelected(true);
-                        }
+                   foreach(QGraphicsItem *item, groupList) {
+                       itemList.unite(item->childItems().toSet());
+                       rebuildGroup(static_cast <AbstractGroupItem*>(item));
+                   }
+
+                    foreach(QGraphicsItem *item, itemList) {
+                       item->setSelected(true);
+                        if (item->parentItem())
+                            item->parentItem()->setSelected(true);
                     }
                     resetSelectionGroup();
-                    groupSelectedItems();
+                    groupSelectedItems(itemList.toList());
                 } else {
-                    rebuildGroup((AbstractGroupItem *)group);
+                   AbstractGroupItem *grp = static_cast <AbstractGroupItem *>(group);
+                    rebuildGroup(grp);
                 }
                 setDocumentModified();
             }
@@ -4345,21 +4389,22 @@ void CustomTrackView::doGroupClips(QList <ItemInfo> clipInfos, QList <ItemInfo>
         setDocumentModified();
         return;
     }
-
-    QList <QGraphicsItemGroup *> groups;
+    QList <QGraphicsItem *>list;
     for (int i = 0; i < clipInfos.count(); i++) {
         ClipItem *clip = getClipItemAt(clipInfos.at(i).startPos, clipInfos.at(i).track);
         if (clip) {
-            clip->setSelected(true);
+           list.append(clip);
+            //clip->setSelected(true);
         }
     }
     for (int i = 0; i < transitionInfos.count(); i++) {
         Transition *clip = getTransitionItemAt(transitionInfos.at(i).startPos, transitionInfos.at(i).track);
         if (clip) {
-            clip->setSelected(true);
+           list.append(clip);
+            //clip->setSelected(true);
         }
     }
-    groupSelectedItems(false, true);
+    groupSelectedItems(list, false, true);
     setDocumentModified();
 }
 
@@ -4642,11 +4687,9 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
         if (clip) {
             clip->setItemLocked(false);
             if (clip->parentItem()) {
-                m_selectionGroup->addToGroup(clip->parentItem());
-                clip->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
+                m_selectionGroup->addItem(clip->parentItem());
             } else {
-                m_selectionGroup->addToGroup(clip);
-                clip->setFlag(QGraphicsItem::ItemIsMovable, false);
+                m_selectionGroup->addItem(clip);
             }
             m_document->renderer()->mltRemoveClip(m_document->tracksCount() - startClip.at(i).track, startClip.at(i).startPos);
         } else kDebug() << "//MISSING CLIP AT: " << startClip.at(i).startPos.frames(25);
@@ -4660,11 +4703,9 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
         if (tr) {
             tr->setItemLocked(false);
             if (tr->parentItem()) {
-                m_selectionGroup->addToGroup(tr->parentItem());
-                tr->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
+                m_selectionGroup->addItem(tr->parentItem());
             } else {
-                m_selectionGroup->addToGroup(tr);
-                tr->setFlag(QGraphicsItem::ItemIsMovable, false);
+                m_selectionGroup->addItem(tr);
             }
             m_document->renderer()->mltDeleteTransition(tr->transitionTag(), tr->transitionEndTrack(), m_document->tracksCount() - startTransition.at(i).track, startTransition.at(i).startPos, startTransition.at(i).endPos, tr->toXML());
         } else kDebug() << "//MISSING TRANSITION AT: " << startTransition.at(i).startPos.frames(25);
@@ -4732,8 +4773,9 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
         }
 
         resetSelectionGroup(false);
-       for (int i = 0; i < groupList.count(); i++)
+       for (int i = 0; i < groupList.count(); i++) {
            rebuildGroup(groupList.at(i));
+       }
 
         clearSelection();
 
@@ -6414,19 +6456,20 @@ void CustomTrackView::loadGroups(const QDomNodeList &groups)
     for (int i = 0; i < groups.count(); i++) {
         QDomNodeList children = groups.at(i).childNodes();
         scene()->clearSelection();
+       QList <QGraphicsItem*>list;
         for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) {
             QDomElement elem = children.item(nodeindex).toElement();
             int pos = elem.attribute("position").toInt();
             int track = elem.attribute("track").toInt();
             if (elem.tagName() == "clipitem") {
                 ClipItem *clip = getClipItemAt(pos, track); //m_document->tracksCount() - transitiontrack);
-                if (clip) clip->setSelected(true);
+                if (clip) list.append(clip);//clip->setSelected(true);
             } else {
                 Transition *clip = getTransitionItemAt(pos, track); //m_document->tracksCount() - transitiontrack);
-                if (clip) clip->setSelected(true);
+                if (clip) list.append(clip);//clip->setSelected(true);
             }
         }
-        groupSelectedItems(false, true);
+        groupSelectedItems(list, false, true);
     }
 }
 
@@ -6623,28 +6666,25 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, EffectsList ef
                 }
             }
         }
-        kDebug() << "GOT TRK: " << track;
         if (freetrack == 0) {
             emit displayMessage(i18n("No empty space to put clip audio"), ErrorMessage);
         } else {
             ItemInfo info = clip->info();
             info.track = m_document->tracksCount() - freetrack;
-            addClip(clip->xml(), clip->clipProducer(), info, clip->effectList());
-            scene()->clearSelection();
+           QDomElement xml = clip->xml();
+           xml.setAttribute("audio_only", 1);
+           scene()->clearSelection();
+            addClip(xml, clip->clipProducer(), info, clip->effectList(), false, false, false);
             clip->setSelected(true);
             ClipItem *audioClip = getClipItemAt(start, info.track);
             if (audioClip) {
+               clip->setVideoOnly(true);
                 Mlt::Tractor *tractor = m_document->renderer()->lockService();
-                clip->setVideoOnly(true);
                 if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - track, start, clip->baseClip()->videoProducer(info.track)) == false) {
                     emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
                 }
-                if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - info.track, start, clip->baseClip()->audioProducer(info.track)) == false) {
-                    emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, info.track), ErrorMessage);
-                }
                 m_document->renderer()->unlockService(tractor);
                 audioClip->setSelected(true);
-                audioClip->setAudioOnly(true);
 
                 // keep video effects, move audio effects to audio clip
                 int videoIx = 0;
@@ -6658,8 +6698,7 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, EffectsList ef
                         videoIx++;
                     }
                 }
-
-                groupSelectedItems(false, true);
+                groupSelectedItems(QList <QGraphicsItem*>()<<clip<<audioClip, false, true);
             }
         }
     } else {
@@ -6929,13 +6968,13 @@ void CustomTrackView::updateProjectFps()
             m_scene->addItem(grp);
             scene()->destroyItemGroup(grp);
             scene()->clearSelection();
-            for (int j = 0; j < children.count(); j++) {
+            /*for (int j = 0; j < children.count(); j++) {
                 if (children.at(j)->type() == AVWIDGET || children.at(j)->type() == TRANSITIONWIDGET) {
                     //children.at(j)->setParentItem(0);
                     children.at(j)->setSelected(true);
                 }
-            }
-            groupSelectedItems(true, true);
+            }*/
+            groupSelectedItems(children, true, true);
         } else if (itemList.at(i)->type() == GUIDEITEM) {
             Guide *g = static_cast<Guide *>(itemList.at(i));
             g->updatePos();
@@ -7010,26 +7049,22 @@ void CustomTrackView::slotSelectClipsInTrack()
     QRectF rect(0, m_selectedTrack * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), m_tracksHeight / 2 - 1);
     QList<QGraphicsItem *> selection = m_scene->items(rect);
     m_scene->clearSelection();
+    QList<QGraphicsItem *> list;
     for (int i = 0; i < selection.count(); i++) {
         if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET) {
-            selection.at(i)->setSelected(true);
+           list.append(selection.at(i));
         }
     }    
     resetSelectionGroup();
-    groupSelectedItems();
+    groupSelectedItems(list);
 }
 
 void CustomTrackView::slotSelectAllClips()
 {
     QList<QGraphicsItem *> selection = m_scene->items();
     m_scene->clearSelection();
-    for (int i = 0; i < selection.count(); i++) {
-        if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET  || selection.at(i)->type() == GROUPWIDGET) {
-            selection.at(i)->setSelected(true);
-        }
-    }
     resetSelectionGroup();
-    groupSelectedItems();
+    groupSelectedItems(selection);
 }
 
 void CustomTrackView::selectClip(bool add, bool group, int track, int pos)
index 3312e74ebd95f561412b6bfe0e259bccd196119b..5515c7e8185b33dbf86033e677f87187ca16e5d6 100644 (file)
@@ -406,7 +406,7 @@ private:
     ClipItem *getClipUnderCursor() const;
     AbstractClipItem *getMainActiveClip() const;
     void resetSelectionGroup(bool selectItems = true);
-    void groupSelectedItems(bool force = false, bool createNewGroup = false);
+    void groupSelectedItems(QList <QGraphicsItem *> selection = QList <QGraphicsItem *>(), bool force = false, bool createNewGroup = false, bool selectNewGroup = false);
     /** Get available space for clip move (min and max free positions) */
     void getClipAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
     /** Get available space for transition move (min and max free positions) */
index 207637070816b22f72e6a9a1f872d92e4f64adb6..12e30d94d2714c4c33e49c43096b2b8d28d486ad 100644 (file)
@@ -1107,6 +1107,7 @@ int Render::setProducer(Mlt::Producer *producer, int position)
     if (!producer || !producer->is_valid()) {
         if (producer) delete producer;
         producer = m_blackClip->cut(0, 1);
+       producer->set("id", "black");
     }
 
     if (!producer || !producer->is_valid()) {
@@ -2064,15 +2065,13 @@ bool Render::mltCutClip(int track, GenTime position)
 Mlt::Tractor *Render::lockService()
 {
     // we are going to replace some clips, purge consumer
-    QMutexLocker locker(&m_mutex);
     if (!m_mltProducer) return NULL;
+    QMutexLocker locker(&m_mutex);
     if (m_mltConsumer) {
-        if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
         m_mltConsumer->purge();
     }
     Mlt::Service service(m_mltProducer->parent().get_service());
     if (service.type() != tractor_type) {
-        kWarning() << "// TRACTOR PROBLEM";
         return NULL;
     }
     service.lock();