]> git.sesse.net Git - kdenlive/commitdiff
effect stack cleanup
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 25 Mar 2012 23:30:53 +0000 (01:30 +0200)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 25 Mar 2012 23:30:53 +0000 (01:30 +0200)
src/clipitem.cpp
src/clipitem.h
src/customtrackview.cpp
src/effectslist.cpp
src/effectslist.h
src/effectstack/collapsibleeffect.cpp
src/effectstack/collapsibleeffect.h
src/effectstack/effectstackview2.cpp
src/effectstack/effectstackview2.h
src/kdenlivedoc.cpp

index 09d7304dcb2e992ac920eb5c85d64407264e6a1e..b934e217f0202108dcb63bbd12468a1fa3ba56d7 100644 (file)
@@ -63,6 +63,7 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, i
         m_limitedKeyFrames(false)
 {
     setZValue(2);
+    m_effectList = EffectsList(true);
     FRAME_SIZE = frame_width;
     setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (double) itemHeight());
     setPos(info.startPos.frames(fps), (double)(info.track * KdenliveSettings::trackheight()) + 1 + itemOffset());
@@ -159,9 +160,10 @@ void ClipItem::setEffectList(const EffectsList effectList)
     m_effectNames = m_effectList.effectNames().join(" / ");
     if (!m_effectList.isEmpty()) {
         for (int i = 0; i < m_effectList.count(); i++) {
-            QString effectId = m_effectList.item(i).attribute("id");
+           QDomElement effect = m_effectList.itemFromIndex(i + 1);
+            QString effectId = effect.attribute("id");
             // check if it is a fade effect
-            QDomNodeList params = m_effectList.item(i).elementsByTagName("parameter");
+            QDomNodeList params = effect.elementsByTagName("parameter");
             int fade = 0;
             for (int j = 0; j < params.count(); j++) {
                 QDomElement e = params.item(j).toElement();
@@ -1361,25 +1363,41 @@ QStringList ClipItem::effectNames()
 
 QDomElement ClipItem::effectAt(int ix) const
 {
-    if (ix > m_effectList.count() - 1 || ix < 0 || m_effectList.at(ix).isNull()) return QDomElement();
-    return m_effectList.at(ix).cloneNode().toElement();
+    if (ix > m_effectList.count() || ix <= 0) return QDomElement();
+    return m_effectList.itemFromIndex(ix).cloneNode().toElement();
 }
 
 QDomElement ClipItem::getEffectAt(int ix) const
 {
-    if (ix > m_effectList.count() - 1 || ix < 0 || m_effectList.at(ix).isNull()) return QDomElement();
-    return m_effectList.at(ix);
+    if (ix > m_effectList.count() || ix < 0) return QDomElement();
+    return m_effectList.itemFromIndex(ix);
 }
 
-bool ClipItem::setEffectAt(int ix, QDomElement effect)
+bool ClipItem::updateEffect(QDomElement effect)
+{
+    //kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
+    m_effectList.updateEffect(effect);
+    m_effectNames = m_effectList.effectNames().join(" / ");
+    QString id = effect.attribute("id");
+    if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
+        update();
+    else {
+        QRectF r = boundingRect();
+        r.setHeight(20);
+        update(r);
+    }
+    return true;
+}
+
+bool ClipItem::moveEffect(QDomElement effect, int ix)
 {
     if (ix < 0 || ix > (m_effectList.count() - 1) || effect.isNull()) {
         kDebug() << "Invalid effect index: " << ix;
         return false;
     }
-    //kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
-    effect.setAttribute("kdenlive_ix", ix + 1);
-    m_effectList.replace(ix, effect);
+    m_effectList.removeAt(effect.attribute("kdenlive_ix").toInt());
+    effect.setAttribute("kdenlive_ix", ix);
+    m_effectList.insert(effect);
     m_effectNames = m_effectList.effectNames().join(" / ");
     QString id = effect.attribute("id");
     if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
@@ -1402,11 +1420,7 @@ EffectsParameterList ClipItem::addEffect(const QDomElement effect, bool /*animat
     } else ix = effect.attribute("kdenlive_ix").toInt();
     if (!m_effectList.isEmpty() && ix <= m_effectList.count()) {
         needRepaint = true;
-        m_effectList.insert(ix - 1, effect);
-        for (int i = ix; i < m_effectList.count(); i++) {
-            int index = m_effectList.item(i).attribute("kdenlive_ix").toInt();
-            if (index >= ix) m_effectList.item(i).setAttribute("kdenlive_ix", index + 1);
-        }
+        m_effectList.insert(effect);
     } else m_effectList.append(effect);
     EffectsParameterList parameters;
     parameters.addParam("tag", effect.attribute("tag"));
@@ -1537,34 +1551,27 @@ EffectsParameterList ClipItem::addEffect(const QDomElement effect, bool /*animat
 void ClipItem::deleteEffect(QString index)
 {
     bool needRepaint = false;
-    QString ix;
-
-    for (int i = 0; i < m_effectList.count(); ++i) {
-        ix = m_effectList.at(i).attribute("kdenlive_ix");
-        if (ix == index) {
-            QString effectId = m_effectList.at(i).attribute("id");
-            if ((effectId == "fadein" && hasEffect(QString(), "fade_from_black") == -1) ||
-                    (effectId == "fade_from_black" && hasEffect(QString(), "fadein") == -1)) {
-                m_startFade = 0;
-                needRepaint = true;
-            } else if ((effectId == "fadeout" && hasEffect(QString(), "fade_to_black") == -1) ||
-                       (effectId == "fade_to_black" && hasEffect(QString(), "fadeout") == -1)) {
-                m_endFade = 0;
-                needRepaint = true;
-            } else if (EffectsList::hasKeyFrames(m_effectList.at(i))) needRepaint = true;
-            m_effectList.removeAt(i);
-            i--;
-        } else if (ix.toInt() > index.toInt()) {
-            m_effectList.item(i).setAttribute("kdenlive_ix", ix.toInt() - 1);
-        }
-    }
+    int ix = index.toInt();
+
+    QDomElement effect = m_effectList.itemFromIndex(ix);
+    QString effectId = effect.attribute("id");
+    if ((effectId == "fadein" && hasEffect(QString(), "fade_from_black") == -1) ||
+       (effectId == "fade_from_black" && hasEffect(QString(), "fadein") == -1)) {
+        m_startFade = 0;
+        needRepaint = true;
+    } else if ((effectId == "fadeout" && hasEffect(QString(), "fade_to_black") == -1) ||
+       (effectId == "fade_to_black" && hasEffect(QString(), "fadeout") == -1)) {
+        m_endFade = 0;
+        needRepaint = true;
+    } else if (EffectsList::hasKeyFrames(effect)) needRepaint = true;
+    m_effectList.removeAt(ix);
     m_effectNames = m_effectList.effectNames().join(" / ");
 
-    if (m_effectList.isEmpty() || m_selectedEffect + 1 == index.toInt()) {
+    if (m_effectList.isEmpty() || m_selectedEffect + 1 == ix) {
         // Current effect was removed
-        if (index.toInt() > m_effectList.count() - 1) {
+        if (ix > m_effectList.count() - 1) {
             setSelectedEffect(m_effectList.count() - 1);
-        } else setSelectedEffect(index.toInt());
+        } else setSelectedEffect(ix);
     }
     if (needRepaint) update(boundingRect());
     else {
index c9ada892e294431de67b71a14cdb6676e1a19608..6457dbcb956f45689672fae882af9bc6145cc81f 100644 (file)
@@ -99,7 +99,8 @@ public:
     /** @brief Replaces an effect.
     * @param ix The effect's index in effectlist
     * @param effect The new effect */
-    bool setEffectAt(int ix, QDomElement effect);
+    bool updateEffect(QDomElement effect);
+    bool moveEffect(QDomElement effect, int ix);
     void flashClip();
     void addTransition(Transition*);
 
index 863d005f86b3862ea1d2fde63e3c9810d0085c7f..94de517ac33829b30c8996aa2cd7c1e16a9ff12a 100644 (file)
@@ -1818,6 +1818,7 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
             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 {
+               kDebug()<<"PREIT 0: "<<effect.attribute("kdenlive_ix");
                 item->initEffect(effect);
             }
             new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), effect, true, effectCommand);
@@ -1932,7 +1933,7 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE
                 if (strobe == 0) strobe = 1;
                 doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), speed, clip->speed(), strobe, clip->baseClip()->getId());
             }
-            if (clip->setEffectAt(ix, effect)) {
+            if (clip->updateEffect(effect)) {
                if (ix == clip->selectedEffectIndex()) {
                    clip->setSelectedEffect(ix);
                    if (!triggeredByUser)
@@ -1963,7 +1964,7 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE
        bool success = true;
         if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - clip->track(), clip->startPos(), effectParams)) success = false;
 
-        if (success && clip->setEffectAt(ix, effect)) {
+        if (success && clip->updateEffect(effect)) {
            if (ix == clip->selectedEffectIndex()) {
                clip->setSelectedEffect(ix);
                if (!triggeredByUser)
@@ -1983,12 +1984,12 @@ void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos)
         if (newPos > m_document->getTrackEffects(m_document->tracksCount() - track - 1).count()) {
            newPos = m_document->getTrackEffects(m_document->tracksCount() - track - 1).count();
        }
-        QDomElement act = m_document->getTrackEffect(m_document->tracksCount() - track - 1, newPos - 1);
-        QDomElement before = m_document->getTrackEffect(m_document->tracksCount() - track - 1, oldPos - 1);
+        QDomElement act = m_document->getTrackEffect(m_document->tracksCount() - track - 1, newPos);
+        QDomElement before = m_document->getTrackEffect(m_document->tracksCount() - track - 1, oldPos);
 
         if (!act.isNull() && !before.isNull()) {
-            m_document->setTrackEffect(m_document->tracksCount() - track - 1, oldPos - 1, act);
-            m_document->setTrackEffect(m_document->tracksCount() - track - 1, newPos - 1, before);
+            m_document->setTrackEffect(m_document->tracksCount() - track - 1, oldPos, act);
+            m_document->setTrackEffect(m_document->tracksCount() - track - 1, newPos, before);
             m_document->renderer()->mltMoveEffect(m_document->tracksCount() - track, pos, oldPos, newPos);
             emit showTrackEffects(m_document->tracksCount() - track, m_document->trackInfoAt(m_document->tracksCount() - track - 1));
         } else emit displayMessage(i18n("Cannot move effect"), ErrorMessage);
@@ -1998,11 +1999,11 @@ void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos)
     if (newPos > clip->effectsCount()) {
        newPos = clip->effectsCount();
     }
-    if (clip && !clip->effectAt(newPos - 1).isNull() && !clip->effectAt(oldPos - 1).isNull()) {
-        QDomElement act = clip->effectAt(newPos - 1);
-        QDomElement before = clip->effectAt(oldPos - 1);
-        clip->setEffectAt(oldPos - 1, act);
-        clip->setEffectAt(newPos - 1, before);
+    if (clip && !clip->effectAt(newPos ).isNull() && !clip->effectAt(oldPos).isNull()) {
+        QDomElement act = clip->effectAt(newPos);
+        QDomElement before = clip->effectAt(oldPos);
+        clip->moveEffect(act, oldPos);
+        clip->moveEffect(before, newPos);
         // special case: speed effect, which is a pseudo-effect, not appearing in MLT's effects
         if (act.attribute("id") == "speed") {
             m_document->renderer()->mltUpdateEffectPosition(track, pos, oldPos, newPos);
@@ -2051,7 +2052,6 @@ void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, int track, QDomElemen
     if (clip) command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldeffect, effect, ix, true);
     else command = new EditEffectCommand(this, m_document->tracksCount() - track, GenTime(-1), oldeffect, effect, ix, true);
     m_commandStack->push(command);
-    kDebug()<<"// UPDATE EFFECT, "<<EffectsList::property(effect, "kdenlive_ix")<<" / "<<EffectsList::property(effect, "kdenlive_info");
 }
 
 void CustomTrackView::slotUpdateClipRegion(ClipItem *clip, int ix, QString region)
index cb6184251349018430403f80e16b403156c4d9e1..77c1f41e1f235a335182480d7e813364e46009f9 100644 (file)
@@ -22,7 +22,7 @@
 #include <KLocale>
 
 
-EffectsList::EffectsList()
+EffectsList::EffectsList(bool indexRequired) : m_useIndex(indexRequired)
 {
     m_baseElement = createElement("list");
     appendChild(m_baseElement);
@@ -299,7 +299,10 @@ void EffectsList::removeMetaProperties(QDomElement producer)
 
 void EffectsList::append(QDomElement e)
 {
-    m_baseElement.appendChild(importNode(e, true));
+    if (!e.isNull()) {
+       m_baseElement.appendChild(importNode(e, true));
+       if (m_useIndex) updateIndexes(m_baseElement.childNodes());
+    }
 }
 
 int EffectsList::count() const
@@ -322,30 +325,52 @@ const QDomElement EffectsList::at(int ix) const
 void EffectsList::removeAt(int ix)
 {
     QDomNodeList effects = m_baseElement.childNodes();
-    if (ix < 0 || ix >= effects.count()) return;
-    m_baseElement.removeChild(effects.at(ix));
+    if (ix <= 0 || ix > effects.count()) return;
+    m_baseElement.removeChild(effects.at(ix - 1));
+    if (m_useIndex) updateIndexes(effects);
 }
 
-QDomElement EffectsList::item(int ix)
+QDomElement EffectsList::itemFromIndex(int ix) const
 {
     QDomNodeList effects = m_baseElement.childNodes();
-    if (ix < 0 || ix >= effects.count()) return QDomElement();
-    return effects.at(ix).toElement();
+    if (ix <= 0 || ix > effects.count()) return QDomElement();
+    return effects.at(ix - 1).toElement();
 }
 
-void EffectsList::insert(int ix, QDomElement effect)
+void EffectsList::insert(QDomElement effect)
 {
     QDomNodeList effects = m_baseElement.childNodes();
-    if (ix < 0) ix = 0;
-    if (ix >= effects.count()) m_baseElement.appendChild(importNode(effect, true));
-    else m_baseElement.insertBefore(importNode(effect, true), effects.at(ix));
+    int ix = effect.attribute("kdenlive_ix").toInt();
+    if (ix > effects.count()) m_baseElement.appendChild(importNode(effect, true));
+    else {
+        QDomElement listeffect =  effects.at(ix - 1).toElement();
+       m_baseElement.insertBefore(importNode(effect, true), listeffect);
+    }
+    if (m_useIndex) updateIndexes(effects);
 }
 
-void EffectsList::replace(int ix, QDomElement effect)
+void EffectsList::updateIndexes(QDomNodeList effects)
+{
+    for (int i = 0; i < effects.count(); i++) {
+        QDomElement listeffect =  effects.at(i).toElement();
+       listeffect.setAttribute("kdenlive_ix", i + 1);
+    }
+}
+
+QDomElement EffectsList::effectFromIndex(QDomNodeList effects, int ix)
+{
+    if (ix <= 0 || ix > effects.count()) return QDomElement();
+    return effects.at(ix - 1).toElement();
+}
+
+void EffectsList::updateEffect(QDomElement effect)
 {
     QDomNodeList effects = m_baseElement.childNodes();
-    if (ix < 0) ix = 0;
-    if (ix < effects.count()) m_baseElement.removeChild(effects.at(ix));
-    if (ix == effects.count()) m_baseElement.appendChild(importNode(effect, true));
-    else m_baseElement.insertBefore(importNode(effect, true), effects.at(ix));
+    int ix = effect.attribute("kdenlive_ix").toInt();
+    QDomElement current = effectFromIndex(effects, ix);
+    if (!current.isNull()) {
+       m_baseElement.insertBefore(importNode(effect, true), current);
+       m_baseElement.removeChild(current);
+    }
+    else m_baseElement.appendChild(importNode(effect, true));
 }
index 0d170b35431a87f6b3f9766da88d83aa14cbf4df..0e26b05f5abd1cd2512044dd886113d4a205f719 100644 (file)
@@ -35,7 +35,7 @@
 class EffectsList: public QDomDocument
 {
 public:
-    EffectsList();
+    EffectsList(bool indexRequired = false);
     ~EffectsList();
 
     /** @brief Returns the XML element of an effect.
@@ -65,9 +65,9 @@ public:
     int count() const;
     const QDomElement at(int ix) const;
     void removeAt(int ix);
-    QDomElement item(int ix);
-    void insert(int ix, QDomElement effect);
-    void replace(int ix, QDomElement effect);
+    QDomElement itemFromIndex(int ix) const;
+    void insert(QDomElement effect);
+    void updateEffect(QDomElement effect);
     static bool hasKeyFrames(QDomElement effect);
     static bool hasSimpleKeyFrames(QDomElement effect);
     static bool hasGeometryKeyFrames(QDomElement effect);
@@ -84,9 +84,14 @@ public:
     /** @brief Remove all 'meta.*' properties from a producer, used when replacing proxy producers in xml for rendering. */
     static void removeMetaProperties(QDomElement producer);
     void clearList();
+    /** @brief Get am effect with effect index equal to ix. */
+    QDomElement effectFromIndex(QDomNodeList effects, int ix);
+    /** @brief Update all effects indexes to make sure they are 1, 2, 3, ... */
+    void updateIndexes(QDomNodeList effects);
 
 private:
     QDomElement m_baseElement;
+    bool m_useIndex;
 
 };
 
index e533b2f911c3748821415ee886d51dcb1de75c92..4f1e3cc4b0e295f8cb77b1db8135aee44a51003d 100644 (file)
@@ -173,6 +173,7 @@ CollapsibleEffect::CollapsibleEffect(QDomElement effect, QDomElement original_ef
        setAcceptDrops(true);
        title->setText(i18n("Effect Group"));
        title->setIcon(KIcon("folder"));
+       m_menu->addAction(KIcon("list-remove"), i18n("Ungroup"), this, SLOT(slotUnGroup()));
     }
     
     title->setMenu(m_menu);
@@ -213,7 +214,12 @@ CollapsibleEffect::~CollapsibleEffect()
 
 void CollapsibleEffect::slotCreateGroup()
 {
-    emit createGroup(m_paramWidget->index());
+    emit createGroup(effectIndex());
+}
+
+void CollapsibleEffect::slotUnGroup()
+{
+    emit unGroup(this);
 }
 
 bool CollapsibleEffect::eventFilter( QObject * o, QEvent * e ) 
@@ -328,17 +334,17 @@ void CollapsibleEffect::slotEnable(bool enable)
 
 void CollapsibleEffect::slotDeleteEffect()
 {
-    if (!m_isGroup) emit deleteEffect(m_effect, m_paramWidget->index());
+    if (!m_isGroup) emit deleteEffect(m_effect);
 }
 
 void CollapsibleEffect::slotEffectUp()
 {
-    if (!m_isGroup) emit changeEffectPosition(m_paramWidget->index(), true);
+    if (!m_isGroup) emit changeEffectPosition(effectIndex(), true);
 }
 
 void CollapsibleEffect::slotEffectDown()
 {
-    if (!m_isGroup) emit changeEffectPosition(m_paramWidget->index(), false);
+    if (!m_isGroup) emit changeEffectPosition(effectIndex(), false);
 }
 
 void CollapsibleEffect::slotSaveEffect()
@@ -377,7 +383,7 @@ void CollapsibleEffect::slotSaveEffect()
 
 void CollapsibleEffect::slotResetEffect()
 {
-    emit resetEffect(m_paramWidget->index());
+    emit resetEffect(effectIndex());
 }
 
 void CollapsibleEffect::slotSwitch()
@@ -398,8 +404,14 @@ void CollapsibleEffect::slotShow(bool show)
        m_info.isCollapsed = true;
     }
     m_effect.setAttribute("kdenlive_info", m_info.toString());
+    emit parameterChanged(m_original_effect, m_effect, m_index);   
+}
+
+void CollapsibleEffect::updateGroupIndex(int groupIndex)
+{
+    m_info.groupIndex = groupIndex;
+    m_effect.setAttribute("kdenlive_info", m_info.toString());
     emit parameterChanged(m_original_effect, m_effect, m_index);
-    
 }
 
 void CollapsibleEffect::setGroupIndex(int ix)
@@ -420,6 +432,25 @@ void CollapsibleEffect::addGroupEffect(CollapsibleEffect *effect)
     vbox->addWidget(effect);
 }
 
+QString CollapsibleEffect::infoString() const
+{
+    return m_info.toString();
+}
+
+void CollapsibleEffect::removeGroup(int ix, QVBoxLayout *layout)
+{
+    QVBoxLayout *vbox = static_cast<QVBoxLayout *>(widgetFrame->layout());
+    if (vbox == NULL) return;
+    
+    for (int j = vbox->count() - 1; j >= 0; j--) {
+       QLayoutItem *child = vbox->takeAt(j);
+       CollapsibleEffect *e = static_cast<CollapsibleEffect *>(child->widget());
+       layout->insertWidget(ix, e);
+       e->updateGroupIndex(-1);
+       delete child;
+    }
+}
+
 int CollapsibleEffect::index() const
 {
     return m_index;
index 3e058b9f8b78f80743def718157353f7decbdf61..0a282629ffba4843c56c354e9b82057a36c1dcd9 100644 (file)
@@ -129,6 +129,8 @@ public:
     int groupIndex() const;
     int effectIndex() const;
     void setGroupIndex(int ix);
+    void removeGroup(int ix, QVBoxLayout *layout);
+    QString infoString() const;
 
 public slots:
     void slotSyncEffectsPos(int pos);
@@ -143,6 +145,7 @@ private slots:
     void slotSaveEffect();
     void slotResetEffect();
     void slotCreateGroup();
+    void slotUnGroup();
 
 private:
     ParameterContainer *m_paramWidget;
@@ -160,6 +163,8 @@ private:
     int m_index;
     EffectInfo m_info;
     
+    void updateGroupIndex(int groupIndex);
+    
 protected:
     virtual void mouseDoubleClickEvent ( QMouseEvent * event );
     virtual void mousePressEvent ( QMouseEvent * event );
@@ -172,7 +177,7 @@ signals:
     void parameterChanged(const QDomElement, const QDomElement, int);
     void syncEffectsPos(int);
     void effectStateChanged(bool, int ix = -1);
-    void deleteEffect(const QDomElement, int);
+    void deleteEffect(const QDomElement);
     void changeEffectPosition(int, bool);
     void activateEffect(int);
     void checkMonitorPosition(int);
@@ -186,6 +191,7 @@ signals:
     /** @brief Ask for creation of a group. */
     void createGroup(int ix);
     void moveEffect(int ix, CollapsibleEffect *group, int lastEffectIndex);
+    void unGroup(CollapsibleEffect *);
 };
 
 
index 415a6fee40208058324f87a7c119e28cbb851ad2..26131529bbef087b0dc005bd9b048f3d68ba894c 100644 (file)
@@ -167,7 +167,6 @@ void EffectStackView2::setupListView(int ix)
     QWidget *view = m_ui.container->takeWidget();
     if (view) {
        delete view;
-       //view->deleteLater();
     }
     blockSignals(false);
     view = new QWidget(m_ui.container);
@@ -200,6 +199,7 @@ void EffectStackView2::setupListView(int ix)
                group = new CollapsibleEffect(QDomElement(), QDomElement(), ItemInfo(), effectInfo.groupIndex, &m_effectMetaInfo, false, true, m_ui.container->widget());
                if (!effectInfo.groupName.isEmpty()) group->title->setText(effectInfo.groupName);
                connect(group, SIGNAL(moveEffect(int,CollapsibleEffect*,int)), this , SLOT(slotMoveEffectToGroup(int,CollapsibleEffect*,int)));
+               connect(group, SIGNAL(unGroup(CollapsibleEffect*)), this , SLOT(slotUnGroup(CollapsibleEffect*)));
                vbox1->addWidget(group);
            }
            if (effectInfo.groupIndex >= m_groupIndex) m_groupIndex = effectInfo.groupIndex + 1;
@@ -232,7 +232,7 @@ void EffectStackView2::setupListView(int ix)
 
         connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
        connect(currentEffect, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,QString,QString)));
-        connect(currentEffect, SIGNAL(deleteEffect(const QDomElement, int)), this , SLOT(slotDeleteEffect(const QDomElement, int)));
+        connect(currentEffect, SIGNAL(deleteEffect(const QDomElement)), this , SLOT(slotDeleteEffect(const QDomElement)));
        connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
        connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
         connect(currentEffect, SIGNAL(changeEffectPosition(int,bool)), this , SLOT(slotMoveEffect(int , bool)));
@@ -285,7 +285,6 @@ bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
 {
     if (m_draggedEffect && (event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
-       kDebug()<<"DRAGG: "<<event->pos()<<"/"<<m_clickPoint;
        startDrag();
     }
 }
@@ -415,7 +414,7 @@ void EffectStackView2::slotSetCurrentEffect(int ix)
     }
 }
 
-void EffectStackView2::slotDeleteEffect(const QDomElement effect, int index)
+void EffectStackView2::slotDeleteEffect(const QDomElement effect)
 {
     if (m_effectMetaInfo.trackMode)
         emit removeEffect(NULL, m_trackindex, effect);
@@ -425,20 +424,17 @@ void EffectStackView2::slotDeleteEffect(const QDomElement effect, int index)
 
 void EffectStackView2::slotMoveEffect(int index, bool up)
 {
-    if (up && index <= 0) return;
-    if (!up && index >= m_currentEffectList.count() - 1) return;
-    int startPos;
+    if (up && index <= 1) return;
+    if (!up && index >= m_currentEffectList.count()) return;
     int endPos;
     if (up) {
-        startPos =  index + 1;
-        endPos = index;
+        endPos = index - 1;
     }
     else {
-        startPos =  index + 1;
-        endPos =  index + 2;
+        endPos =  index + 1;
     }
-    if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, startPos, endPos);
-    else emit changeEffectPosition(m_clipref, -1, startPos, endPos);
+    if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, index, endPos);
+    else emit changeEffectPosition(m_clipref, -1, index, endPos);
 }
 
 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
@@ -449,7 +445,7 @@ void EffectStackView2::slotStartFilterJob(const QString&filterName, const QStrin
 
 void EffectStackView2::slotResetEffect(int ix)
 {
-    QDomElement old = m_currentEffectList.at(ix);
+    QDomElement old = m_currentEffectList.itemFromIndex(ix);
     QDomElement dom;
     QString effectId = old.attribute("id");
     QMap<QString, EffectsList*> effectLists;
@@ -489,7 +485,7 @@ void EffectStackView2::slotResetEffect(int ix)
 
 void EffectStackView2::slotCreateGroup(int ix)
 {
-    QDomElement oldeffect = m_currentEffectList.at(ix);
+    QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
     QDomElement neweffect = oldeffect.cloneNode().toElement();
     QString groupName = QString::number(m_groupIndex);
     EffectInfo effectinfo;
@@ -510,30 +506,41 @@ void EffectStackView2::slotCreateGroup(int ix)
     }
     
     QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
-    int groupPos = l->indexOf(m_effects.at(ix));
+    int groupPos = 0;
+    
+    CollapsibleEffect *effectToMove = NULL;
+    for (int j = 0; j < l->count(); j++) {
+       CollapsibleEffect *gp = static_cast<CollapsibleEffect *>(l->itemAt(j)->widget());
+       if (gp->effectIndex() == ix) {
+           effectToMove = gp;
+           groupPos = l->indexOf(gp);
+           l->removeWidget(gp);
+           break;
+       }
+    }
     
     CollapsibleEffect *group = new CollapsibleEffect(QDomElement(), QDomElement(), ItemInfo(), m_groupIndex, &m_effectMetaInfo, false, true, m_ui.container->widget());
     m_groupIndex++;
     connect(group, SIGNAL(moveEffect(int,CollapsibleEffect*,int)), this , SLOT(slotMoveEffectToGroup(int,CollapsibleEffect*,int)));
-    CollapsibleEffect *w = static_cast<CollapsibleEffect*>(l->takeAt(groupPos)->widget());
+    connect(group, SIGNAL(unGroup(CollapsibleEffect*)), this , SLOT(slotUnGroup(CollapsibleEffect*)));
     l->insertWidget(groupPos, group);
-    group->addGroupEffect(w);
+    group->addGroupEffect(effectToMove);
 }
 
-void EffectStackView2::slotMoveEffectToGroup(int ix, CollapsibleEffect* group, int lastEffectIndex)
+void EffectStackView2::slotMoveEffectToGroup(int effectIndex, CollapsibleEffect* group, int lastEffectIndex)
 {
     QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
-    CollapsibleEffect *effectToMove = getEffectByIndex(ix);
+    CollapsibleEffect *effectToMove = getEffectByIndex(effectIndex);
     if (effectToMove == NULL) return;
     l->removeWidget(effectToMove);
     group->addGroupEffect(effectToMove);
     
-    QDomElement oldeffect = m_currentEffectList.at(effectToMove->index());
+    QDomElement oldeffect = effectToMove->effect();
     QDomElement neweffect = oldeffect.cloneNode().toElement();
     
     EffectInfo effectinfo;
     effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
-    effectinfo.groupIndex = group->index();
+    effectinfo.groupIndex = group->groupIndex();
     neweffect.setAttribute("kdenlive_info", effectinfo.toString());
 
     ItemInfo info;
@@ -558,5 +565,12 @@ void EffectStackView2::slotMoveEffectToGroup(int ix, CollapsibleEffect* group, i
     }
 }
 
+void EffectStackView2::slotUnGroup(CollapsibleEffect* group)
+{
+    QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
+    int ix = l->indexOf(group);
+    group->removeGroup(ix, l);
+    group->deleteLater();
+}
 
 #include "effectstackview2.moc"
index fc8e601f8126788cb05af0cde0b94de135ca8c03..d169285368c29650539d302826788fc323ee67db 100644 (file)
@@ -133,7 +133,7 @@ private slots:
     void slotMoveEffect(int index, bool up);
 
     /** @brief Delete an effect in the stack. */
-    void slotDeleteEffect(const QDomElement effect, int index);
+    void slotDeleteEffect(const QDomElement effect);
 
     /** @brief Pass position changes of the timeline cursor to the effects to keep their local timelines in sync. */
     void slotRenderPos(int pos);
@@ -157,8 +157,9 @@ private slots:
       ** @param group the effect group where the effect is moved
       ** @param lastEffectIndex the last effect index in the group, effect will be inserted after that index
       */
-    void slotMoveEffectToGroup(int ix, CollapsibleEffect *group, int lastEffectIndex);
-
+    void slotMoveEffectToGroup(int effectIndex, CollapsibleEffect *group, int lastEffectIndex);
+    /** @brief Remove effects from a group */
+    void slotUnGroup(CollapsibleEffect* group);
 
 signals:
     void removeEffect(ClipItem*, int, QDomElement);
index d16167cbed876f0df7b855cede0951a1d02a2f58..530a1d1ee440d8184bfd458905ef24c9af70f7bc 100644 (file)
@@ -1502,15 +1502,13 @@ void KdenliveDoc::removeTrackEffect(int ix, QDomElement effect)
         kWarning() << "Remove Track effect outisde of range";
         return;
     }
-    QString index;
-    QString toRemove = effect.attribute("kdenlive_ix");
+    int index;
+    int toRemove = effect.attribute("kdenlive_ix").toInt();
     for (int i = 0; i < m_tracksList.at(ix).effectsList.count(); ++i) {
-        index = m_tracksList.at(ix).effectsList.at(i).attribute("kdenlive_ix");
+        index = m_tracksList.at(ix).effectsList.at(i).attribute("kdenlive_ix").toInt();
         if (toRemove == index) {
-            m_tracksList[ix].effectsList.removeAt(i);
-            i--;
-        } else if (index.toInt() > toRemove.toInt()) {
-            m_tracksList[ix].effectsList.item(i).setAttribute("kdenlive_ix", index.toInt() - 1);
+            m_tracksList[ix].effectsList.removeAt(toRemove);
+            break;
         }
     }
 }
@@ -1521,12 +1519,12 @@ void KdenliveDoc::setTrackEffect(int trackIndex, int effectIndex, QDomElement ef
         kWarning() << "Set Track effect outisde of range";
         return;
     }
-    if (effectIndex < 0 || effectIndex > (m_tracksList.at(trackIndex).effectsList.count() - 1) || effect.isNull()) {
+    if (effectIndex <= 0 || effectIndex > (m_tracksList.at(trackIndex).effectsList.count()) || effect.isNull()) {
         kDebug() << "Invalid effect index: " << effectIndex;
         return;
     }
-    effect.setAttribute("kdenlive_ix", effectIndex + 1);
-    m_tracksList[trackIndex].effectsList.replace(effectIndex, effect);
+    effect.setAttribute("kdenlive_ix", effectIndex);
+    m_tracksList[trackIndex].effectsList.updateEffect(effect);
 }
 
 const EffectsList KdenliveDoc::getTrackEffects(int ix)
@@ -1545,8 +1543,8 @@ QDomElement KdenliveDoc::getTrackEffect(int trackIndex, int effectIndex) const
         return QDomElement();
     }
     EffectsList list = m_tracksList.at(trackIndex).effectsList;
-    if (effectIndex > list.count() - 1 || effectIndex < 0 || list.at(effectIndex).isNull()) return QDomElement();
-    return list.at(effectIndex).cloneNode().toElement();
+    if (effectIndex > list.count() || effectIndex < 1 || list.itemFromIndex(effectIndex).isNull()) return QDomElement();
+    return list.itemFromIndex(effectIndex).cloneNode().toElement();
 }
 
 bool KdenliveDoc::saveCustomEffects(QDomNodeList customeffects)