]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
Improve the export audio automatic setting:
[kdenlive] / src / customtrackview.cpp
index 5c30adffedf927c365ca9766e3f720ab4e9a7734..0dbcbd82f6b0613c43099c39919ce7fbc818bb62 100644 (file)
@@ -369,7 +369,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
     emit mousePosition(mappedXPos);
 
     if (event->buttons() & Qt::MidButton) return;
-    if (dragMode() == QGraphicsView::RubberBandDrag || (event->modifiers() == Qt::ControlModifier && m_tool != SPACERTOOL)) {
+    if (dragMode() == QGraphicsView::RubberBandDrag || (event->modifiers() == Qt::ControlModifier && m_tool != SPACERTOOL && m_operationMode != RESIZESTART && m_operationMode != RESIZEEND)) {
         event->setAccepted(true);
         m_moveOpMode = NONE;
         QGraphicsView::mouseMoveEvent(event);
@@ -393,7 +393,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
                 }
             } else if (m_operationMode == RESIZESTART && move) {
                 m_document->renderer()->pause();
-                if (m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
+                if (event->modifiers() != Qt::ControlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
                     AbstractGroupItem *parent = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
                     if (parent)
                         parent->resizeStart((int)(snappedPos) - m_dragItemInfo.startPos.frames(m_document->fps()));
@@ -402,7 +402,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
                 }
             } else if (m_operationMode == RESIZEEND && move) {
                 m_document->renderer()->pause();
-                if (m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
+                if (event->modifiers() != Qt::ControlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
                     AbstractGroupItem *parent = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
                     if (parent)
                         parent->resizeEnd((int)(snappedPos) - m_dragItemInfo.endPos.frames(m_document->fps()));
@@ -600,8 +600,12 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
             }
         } else if (opMode == RESIZESTART) {
             setCursor(KCursor("left_side", Qt::SizeHorCursor));
+            if (item->type() == AVWIDGET && item->parentItem() && item->parentItem() != m_selectionGroup)
+                emit displayMessage(i18n("Use Ctrl to resize only current item, otherwise all items in this group will be resized at once."), InformationMessage);
         } else if (opMode == RESIZEEND) {
             setCursor(KCursor("right_side", Qt::SizeHorCursor));
+            if (item->type() == AVWIDGET && item->parentItem() && item->parentItem() != m_selectionGroup)
+                emit displayMessage(i18n("Use Ctrl to resize only current item, otherwise all items in this group will be resized at once."), InformationMessage);
         } else if (opMode == FADEIN || opMode == FADEOUT) {
             setCursor(Qt::PointingHandCursor);
             emit displayMessage(i18n("Drag to add or resize a fade effect."), InformationMessage);
@@ -868,31 +872,32 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
 
     // Razor tool
     if (m_tool == RAZORTOOL && m_dragItem) {
+        GenTime cutPos = GenTime((int)(mapToScene(event->pos()).x()), m_document->fps());
         if (m_dragItem->type() == TRANSITIONWIDGET) {
             emit displayMessage(i18n("Cannot cut a transition"), ErrorMessage);
-            event->accept();
-            m_dragItem = NULL;
-            return;
-        } else if (m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
-            emit displayMessage(i18n("Cannot cut a clip in a group"), ErrorMessage);
-            event->accept();
-            m_dragItem = NULL;
-            return;
+        } else {
+            m_document->renderer()->pause();
+            if (m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
+                razorGroup((AbstractGroupItem *)m_dragItem->parentItem(), cutPos);
+            } else {
+                AbstractClipItem *clip = static_cast <AbstractClipItem *>(m_dragItem);
+                RazorClipCommand* command = new RazorClipCommand(this, clip->info(), cutPos);
+                m_commandStack->push(command);
+            }
+            setDocumentModified();
         }
-        AbstractClipItem *clip = static_cast <AbstractClipItem *>(m_dragItem);
-        RazorClipCommand* command = new RazorClipCommand(this, clip->info(), GenTime((int)(mapToScene(event->pos()).x()), m_document->fps()));
-        m_document->renderer()->pause();
-        m_commandStack->push(command);
-        setDocumentModified();
         m_dragItem = NULL;
         event->accept();
         return;
     }
 
     bool itemSelected = false;
-    if (m_dragItem->isSelected()) itemSelected = true;
-    else if (m_dragItem->parentItem() && m_dragItem->parentItem()->isSelected()) itemSelected = true;
-    else if (dragGroup && dragGroup->isSelected()) itemSelected = true;
+    if (m_dragItem->isSelected())
+        itemSelected = true;
+    else if (m_dragItem->parentItem() && m_dragItem->parentItem()->isSelected())
+        itemSelected = true;
+    else if (dragGroup && dragGroup->isSelected())
+        itemSelected = true;
 
     if (event->modifiers() == Qt::ControlModifier || itemSelected == false) {
         if (event->modifiers() != Qt::ControlModifier) {
@@ -907,8 +912,10 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
             dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
         }
         bool selected = !m_dragItem->isSelected();
-        if (dragGroup) dragGroup->setSelected(selected);
-        else m_dragItem->setSelected(selected);
+        if (dragGroup)
+            dragGroup->setSelected(selected);
+        else
+            m_dragItem->setSelected(selected);
 
         groupSelectedItems();
         ClipItem *clip = static_cast <ClipItem *>(m_dragItem);
@@ -920,7 +927,9 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         if (m_dragItem && m_dragItem->type() == AVWIDGET && !m_dragItem->isItemLocked()) {
             ClipItem *selected = static_cast <ClipItem*>(m_dragItem);
             emit clipItemSelected(selected);
-        } else emit clipItemSelected(NULL);
+        } else {
+            emit clipItemSelected(NULL);
+        }
     }
 
     // If clicked item is selected, allow move
@@ -931,8 +940,10 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
 
     // Update snap points
     if (m_selectionGroup == NULL) {
-        if (m_operationMode == RESIZEEND || m_operationMode == RESIZESTART) updateSnapPoints(NULL);
-        else updateSnapPoints(m_dragItem);
+        if (m_operationMode == RESIZEEND || m_operationMode == RESIZESTART)
+            updateSnapPoints(NULL);
+        else
+            updateSnapPoints(m_dragItem);
     } else {
         QList <GenTime> offsetList;
         QList<QGraphicsItem *> children = m_selectionGroup->childItems();
@@ -974,8 +985,10 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
             info.endPos = transitionClip->endPos();
         } else {
             GenTime transitionDuration(65, m_document->fps());
-            if (m_dragItem->cropDuration() < transitionDuration) info.endPos = m_dragItem->endPos();
-            else info.endPos = info.startPos + transitionDuration;
+            if (m_dragItem->cropDuration() < transitionDuration)
+                info.endPos = m_dragItem->endPos();
+            else
+                info.endPos = info.startPos + transitionDuration;
         }
         if (info.endPos == info.startPos) info.endPos = info.startPos + GenTime(65, m_document->fps());
         // Check there is no other transition at that place
@@ -2956,12 +2969,14 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                         trackTransitionStartList[m_document->tracksCount() - info.track] = info.startPos.frames(m_document->fps());
                 }
             }
-
-            InsertSpaceCommand *command = new InsertSpaceCommand(this, clipsToMove, transitionsToMove, track, timeOffset, false);
-            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());
+            if (!clipsToMove.isEmpty() || !transitionsToMove.isEmpty()) {
+                InsertSpaceCommand *command = new InsertSpaceCommand(this, clipsToMove, transitionsToMove, track, timeOffset, false);
+                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();
+            }
         }
         resetSelectionGroup(false);
         m_operationMode = NONE;
@@ -3124,6 +3139,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                     adjustTimelineTransitions(m_scene->editMode(), transition, moveCommand);
                     new MoveTransitionCommand(this, m_dragItemInfo, info, false, moveCommand);
                     m_commandStack->push(moveCommand);
+                    setDocumentModified();
                 }
             }
         } else {
@@ -3208,7 +3224,6 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                         m_document->renderer()->mltAddTransition(tr->transitionTag(), newTrack, m_document->tracksCount() - info.track, info.startPos, info.endPos, tr->toXML());
                     }
                 }
-                rebuildGroup((AbstractGroupItem *)group);
                 new MoveGroupCommand(this, clipsToMove, transitionsToMove, timeOffset, trackOffset, false, moveGroup);
                 m_commandStack->push(moveGroup);
 
@@ -3220,6 +3235,8 @@ 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();
+                } else {
+                    rebuildGroup((AbstractGroupItem *)group);
                 }
                 setDocumentModified();
             }
@@ -3227,7 +3244,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         m_document->renderer()->doRefresh();
     } else if (m_operationMode == RESIZESTART && m_dragItem->startPos() != m_dragItemInfo.startPos) {
         // resize start
-        if (m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
+        if (event->modifiers() != Qt::ControlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
             AbstractGroupItem *parent = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
             if (parent) {
                 QUndoCommand *resizeCommand = new QUndoCommand();
@@ -3251,7 +3268,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         }
     } else if (m_operationMode == RESIZEEND && m_dragItem->endPos() != m_dragItemInfo.endPos) {
         // resize end
-        if (m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
+        if (event->modifiers() != Qt::ControlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
             AbstractGroupItem *parent = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
             if (parent) {
                 QUndoCommand *resizeCommand = new QUndoCommand();
@@ -3604,12 +3621,9 @@ void CustomTrackView::razorGroup(AbstractGroupItem* group, GenTime cutPos)
 {
     if (group) {
         QList <QGraphicsItem *> children = group->childItems();
-        QList <ItemInfo> clips1;
-        QList <ItemInfo> transitions1;
-        QList <ItemInfo> clipsCut;
-        QList <ItemInfo> transitionsCut;
-        QList <ItemInfo> clips2;
-        QList <ItemInfo> transitions2;
+        QList <ItemInfo> clips1, transitions1;
+        QList <ItemInfo> clipsCut, transitionsCut;
+        QList <ItemInfo> clips2, transitions2;
         for (int i = 0; i < children.count(); ++i) {
             children.at(i)->setSelected(false);
             AbstractClipItem *child = static_cast <AbstractClipItem *>(children.at(i));
@@ -3629,6 +3643,8 @@ void CustomTrackView::razorGroup(AbstractGroupItem* group, GenTime cutPos)
                     transitionsCut << child->info();
             }
         }
+        if (clipsCut.isEmpty() && transitionsCut.isEmpty() && ((clips1.isEmpty() && transitions1.isEmpty()) || (clips2.isEmpty() && transitions2.isEmpty())))
+            return;
         RazorGroupCommand *command = new RazorGroupCommand(this, clips1, transitions1, clipsCut, transitionsCut, clips2, transitions2, cutPos);
         m_commandStack->push(command);
     }
@@ -3646,12 +3662,14 @@ void CustomTrackView::slotRazorGroup(QList <ItemInfo> clips1, QList <ItemInfo> t
                     clips2 << clipBehind->info();
             }
         }
-        // TODO: cut transitionsCut
+        /* TODO: cut transitionsCut
+         * For now just append them to group1 */
+        transitions1 << transitionsCut;
         doGroupClips(clips1, transitions1, true);
         doGroupClips(clips2, transitions2, true);
     } else {
         /* we might also just use clipsCut.at(0)->parentItem().
-           Do this loop just in case something went wrong during cut */
+         * Do this loop just in case something went wrong during cut */
         for (int i = 0; i < clipsCut.count(); ++i) {
             ClipItem *clip = getClipItemAt(cutPos.frames(m_document->fps()), clipsCut.at(i).track);
             if (clip && clip->parentItem() && clip->parentItem()->type() == GROUPWIDGET) {
@@ -3669,7 +3687,7 @@ void CustomTrackView::slotRazorGroup(QList <ItemInfo> clips1, QList <ItemInfo> t
                 break;
             }
         }
-        for(int i = 0; i < clipsCut.count(); ++i)
+        for (int i = 0; i < clipsCut.count(); ++i)
             cutClip(clipsCut.at(i), cutPos, false);
         // TODO: uncut transitonsCut
         doGroupClips(QList <ItemInfo>() << clips1 << clipsCut << clips2, QList <ItemInfo>() << transitions1 << transitionsCut << transitions2, true);
@@ -4191,6 +4209,14 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol
         KdenliveSettings::setSnaptopoints(snap);
     }
 
+    bool hasParentCommand = false;
+    if (command) {
+        hasParentCommand = true;
+    } else {
+        command = new QUndoCommand();
+        command->setText(i18n("Resize clip start"));
+    }
+
     // do this here, too, because otherwise undo won't update the group
     if (item->parentItem() && item->parentItem() != m_selectionGroup)
         new RebuildGroupCommand(this, item->info().track, item->endPos() - GenTime(1, m_document->fps()), command);
@@ -4201,14 +4227,6 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol
         resizeinfo.track = m_document->tracksCount() - resizeinfo.track;
         bool success = m_document->renderer()->mltResizeClipStart(resizeinfo, item->startPos() - oldInfo.startPos);
         if (success) {
-            bool hasParentCommand = false;
-            if (command) {
-                hasParentCommand = true;
-            } else {
-                command = new QUndoCommand();
-                command->setText(i18n("Resize clip start"));
-            }
-
             // Check if there is an automatic transition on that clip (lower track)
             Transition *transition = getTransitionItemAtStart(oldInfo.startPos, oldInfo.track);
             if (transition && transition->isAutomatic()) {
@@ -4263,9 +4281,6 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol
             } else {
                 new ResizeClipCommand(this, oldInfo, info, false, false, command);
             }
-
-            if (!hasParentCommand)
-                m_commandStack->push(command);
         } else {
             KdenliveSettings::setSnaptopoints(false);
             item->resizeStart((int) oldInfo.startPos.frames(m_document->fps()));
@@ -4289,6 +4304,9 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol
     }
     if (item->parentItem() && item->parentItem() != m_selectionGroup)
         new RebuildGroupCommand(this, item->info().track, item->endPos() - GenTime(1, m_document->fps()), command);
+
+    if (!hasParentCommand)
+        m_commandStack->push(command);
 }
 
 void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldInfo, int pos, bool check, QUndoCommand *command)
@@ -4308,6 +4326,14 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
         KdenliveSettings::setSnaptopoints(snap);
     }
 
+    bool hasParentCommand = false;
+    if (command) {
+        hasParentCommand = true;
+    } else {
+        command = new QUndoCommand();
+        command->setText(i18n("Resize clip end"));
+    }
+
     // do this here, too, because otherwise undo won't update the group
     if (item->parentItem() && item->parentItem() != m_selectionGroup)
         new RebuildGroupCommand(this, item->info().track, item->startPos(), command);
@@ -4318,14 +4344,6 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
         resizeinfo.track = m_document->tracksCount() - resizeinfo.track;
         bool success = m_document->renderer()->mltResizeClipEnd(resizeinfo, resizeinfo.endPos - resizeinfo.startPos);
         if (success) {
-            bool hasParentCommand = false;
-            if (command) {
-                hasParentCommand = true;
-            } else {
-                command = new QUndoCommand();
-                command->setText(i18n("Resize clip end"));
-            }
-
             // Check if there is an automatic transition on that clip (lower track)
             Transition *tr = getTransitionItemAtEnd(oldInfo.endPos, oldInfo.track);
             if (tr && tr->isAutomatic()) {
@@ -4381,8 +4399,6 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
                 new ResizeClipCommand(this, oldInfo, info, false, false, command);
             }
 
-            if (!hasParentCommand)
-                m_commandStack->push(command);
             updatePositionEffects(clip, oldInfo);
         } else {
             KdenliveSettings::setSnaptopoints(false);
@@ -4406,6 +4422,9 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
     }
     if (item->parentItem() && item->parentItem() != m_selectionGroup)
         new RebuildGroupCommand(this, item->info().track, item->startPos(), command);
+
+    if (!hasParentCommand)
+        m_commandStack->push(command);
 }
 
 void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info)
@@ -6177,3 +6196,19 @@ void CustomTrackView::setTipAnimation(AbstractClipItem *clip, OPERATIONTYPE mode
         m_animationTimer->start();
     }
 }
+
+bool CustomTrackView::hasAudio(int track) const
+{
+    QRectF rect(0, (double)(track * m_tracksHeight + 1), (double) sceneRect().width(), (double)(m_tracksHeight - 1));
+    QList<QGraphicsItem *> collisions = scene()->items(rect, Qt::IntersectsItemBoundingRect);
+    QGraphicsItem *item;
+    for (int i = 0; i < collisions.count(); i++) {
+        item = collisions.at(i);
+        if (!item->isEnabled()) continue;
+        if (item->type() == AVWIDGET) {
+            ClipItem *clip = static_cast <ClipItem *>(item);
+            if (!clip->isVideoOnly() && (clip->clipType() == AUDIO || clip->clipType() == AV || clip->clipType() == PLAYLIST)) return true;
+        }
+    }
+    return false;
+}