]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
Several effect fixes (mostly track effect issues)
[kdenlive] / src / customtrackview.cpp
index 72720936905b7bdc2b7596f2790e56b58c8d521c..6d910500d27d35906b0bfbdfb2ef75e4ca043b91 100644 (file)
@@ -1690,13 +1690,19 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
             if (effect.attribute("type") == "audio") {
                 // Don't add audio effects on video clips
                 if (item->isVideoOnly() || (item->clipType() != AUDIO && item->clipType() != AV && item->clipType() != PLAYLIST)) {
-                    emit displayMessage(i18n("Cannot add an audio effect to this clip"), ErrorMessage);
+                    /* do not show error message when item is part of a group as the user probably knows what he does then
+                     * and the message is annoying when working with the split audio feature */
+                    if (!item->parentItem() || item->parentItem() == m_selectionGroup)
+                        emit displayMessage(i18n("Cannot add an audio effect to this clip"), ErrorMessage);
                     continue;
                 }
-            } else if (effect.hasAttribute("type") == false) {
+            } else if (effect.attribute("type") == "video" || !effect.hasAttribute("type")) {
                 // Don't add video effect on audio clips
                 if (item->isAudioOnly() || item->clipType() == AUDIO) {
-                    emit displayMessage(i18n("Cannot add a video effect to this clip"), ErrorMessage);
+                    /* do not show error message when item is part of a group as the user probably knows what he does then
+                     * and the message is annoying when working with the split audio feature */
+                    if (!item->parentItem() || item->parentItem() == m_selectionGroup)
+                        emit displayMessage(i18n("Cannot add a video effect to this clip"), ErrorMessage);
                     continue;
                 }
             }
@@ -1707,9 +1713,13 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
             if (item->isItemLocked()) {
                 continue;
             }
+
             if (effect.attribute("id") == "freeze" && m_cursorPos > item->startPos().frames(m_document->fps()) && m_cursorPos < item->endPos().frames(m_document->fps())) {
                 item->initEffect(effect, m_cursorPos - item->startPos().frames(m_document->fps()));
-            } else item->initEffect(effect);
+            } else {
+                item->initEffect(effect);
+            }
+
             if (effect.attribute("tag") == "ladspa") {
                 QString ladpsaFile = m_document->getLadspaFile();
                 initEffects::ladspaEffectFile(ladpsaFile, effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
@@ -1779,6 +1789,7 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE
         return;
     }
     QDomElement effect = insertedEffect.cloneNode().toElement();
+    kDebug() << "// update effect ix: " << effect.attribute("kdenlive_ix");
     if (pos < GenTime()) {
         // editing a track effect
         EffectsParameterList effectParams = getEffectArgs(effect);
@@ -1793,7 +1804,8 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE
         }
         if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - track, pos, effectParams))
             emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
-        m_document->setTrackEffect(track - 1, ix, effect);
+        m_document->setTrackEffect(m_document->tracksCount() - track - 1, ix, effect);
+        setDocumentModified();
         return;
 
     }
@@ -2314,6 +2326,7 @@ void CustomTrackView::dropEvent(QDropEvent * event)
 
         m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
         if (items.count() > 1) groupSelectedItems(true);
+        else if (items.count() == 1) m_dragItem = static_cast <ClipItem *>(items.at(0));
         event->setDropAction(Qt::MoveAction);
         event->accept();
     } else QGraphicsView::dropEvent(event);
@@ -3308,9 +3321,20 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                     m_selectionGroupInfo.track = m_selectionGroup->track();
 
                     for (int i = 0; i < items.count(); ++i) {
-                        if (items.at(i)->type() == GROUPWIDGET)
+                        if (items.at(i)->type() == GROUPWIDGET) {
                             rebuildGroup((AbstractGroupItem*)items.at(i));
+                            items.removeAt(i);
+                            --i;
+                        }
                     }
+                    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);
+                        }
+                    }
+                    groupSelectedItems();
                 } else {
                     rebuildGroup((AbstractGroupItem *)group);
                 }
@@ -3675,6 +3699,7 @@ void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependant
 void CustomTrackView::cutSelectedClips()
 {
     QList<QGraphicsItem *> itemList = scene()->selectedItems();
+    QList<AbstractGroupItem *> groups;
     GenTime currentPos = GenTime(m_cursorPos, m_document->fps());
     for (int i = 0; i < itemList.count(); ++i) {
         if (!itemList.at(i))
@@ -3682,45 +3707,22 @@ void CustomTrackView::cutSelectedClips()
         if (itemList.at(i)->type() == AVWIDGET) {
             ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
             if (item->parentItem() && item->parentItem() != m_selectionGroup) {
-                // 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);
+                AbstractGroupItem *group = static_cast <AbstractGroupItem *>(item->parentItem());
+                if (!groups.contains(group))
+                    groups << group;
             } 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) {
-            // 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);
+            if (!groups.contains(group))
+                groups << group;
         }
     }
+
+    for (int i = 0; i < groups.count(); ++i)
+        razorGroup(groups.at(i), currentPos);
 }
 
 void CustomTrackView::razorGroup(AbstractGroupItem* group, GenTime cutPos)
@@ -4200,6 +4202,9 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
                 else
                     prod = clip->baseClip()->producer(info.track);
                 m_document->renderer()->mltInsertClip(info, clip->xml(), prod);
+                for (int i = 0; i < clip->effectsCount(); i++) {
+                    m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effectAt(i)), false);
+                }
             } else if (item->type() == TRANSITIONWIDGET) {
                 Transition *tr = static_cast <Transition*>(item);
                 int newTrack;
@@ -4220,6 +4225,7 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
             if (children.at(i)->parentItem())
                 rebuildGroup((AbstractGroupItem*)children.at(i)->parentItem());
         }
+        clearSelection();
 
         KdenliveSettings::setSnaptopoints(snap);
         m_document->renderer()->doRefresh();