]> git.sesse.net Git - kdenlive/blobdiff - src/effectstack/effectstackview2.cpp
collapsible effects cleanup
[kdenlive] / src / effectstack / effectstackview2.cpp
index 22b9f91c1e10f8f4fb5ae361d1ed7ed2bbac84d9..831e066eec6981dede71d0e9b462725a1ee223a3 100644 (file)
@@ -183,12 +183,8 @@ void EffectStackView2::setupListView()
            }
            
            if (group == NULL) {
-               group = new CollapsibleGroup(effectInfo.groupIndex, i == 0, i == m_currentEffectList.count() - 1, effectInfo.groupName, m_ui.container->widget());
-               connect(group, SIGNAL(moveEffect(int,int,int,QString)), this, SLOT(slotMoveEffect(int,int,int,QString)));
-               connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
-               connect(group, SIGNAL(groupRenamed(CollapsibleGroup *)), this, SLOT(slotRenameGroup(CollapsibleGroup*)));
-                connect(group, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
-               connect(group, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
+               group = new CollapsibleGroup(effectInfo.groupIndex, i == 0, i == m_currentEffectList.count() - 1, effectInfo, m_ui.container->widget());
+               connectGroup(group);
                vbox1->addWidget(group);
                group->installEventFilter( this );
            }
@@ -245,15 +241,16 @@ void EffectStackView2::connectEffect(CollapsibleEffect *currentEffect)
     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(slotMoveEffectUp(int , bool)));
+    connect(currentEffect, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
     connect(currentEffect, SIGNAL(effectStateChanged(bool,int,bool)), this, SLOT(slotUpdateEffectState(bool,int,bool)));
     connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
     connect(currentEffect, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
     connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
     connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
-    connect(currentEffect, SIGNAL(moveEffect(int,int,int,QString)), this , SLOT(slotMoveEffect(int,int,int,QString)));
+    connect(currentEffect, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
     connect(currentEffect, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
     connect(currentEffect, SIGNAL(createRegion(int,KUrl)), this, SLOT(slotCreateRegion(int,KUrl)));
+    connect(currentEffect, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
 }
 
 void EffectStackView2::slotCheckWheelEventFilter()
@@ -296,7 +293,7 @@ bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
        m_draggedGroup = qobject_cast<CollapsibleGroup*>(o);
        if (m_draggedGroup) {
            QMouseEvent *me = static_cast<QMouseEvent *>(e);
-           if (me->button() == Qt::LeftButton && (m_draggedGroup->framegroup->underMouse() || m_draggedGroup->title()->underMouse()))
+           if (me->button() == Qt::LeftButton && (m_draggedGroup->frame->underMouse() || m_draggedGroup->title()->underMouse()))
                m_clickPoint = me->globalPos();
            else {
                m_clickPoint = QPoint();
@@ -555,19 +552,19 @@ void EffectStackView2::slotAddEffect(QDomElement effect)
     emit addEffect(m_clipref, effect);
 }
 
-void EffectStackView2::slotMoveEffectUp(int index, bool up)
+void EffectStackView2::slotMoveEffectUp(QList <int> indexes, bool up)
 {
-    if (up && index <= 1) return;
-    if (!up && index >= m_currentEffectList.count()) return;
+    if (up && indexes.first() <= 1) return;
+    if (!up && indexes.last() >= m_currentEffectList.count()) return;
     int endPos;
     if (up) {
-        endPos = index - 1;
+        endPos = indexes.first() - 1;
     }
     else {
-        endPos =  index + 1;
+        endPos =  indexes.last() + 1;
     }
-    if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, index, endPos);
-    else emit changeEffectPosition(m_clipref, -1, index, endPos);
+    if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, indexes, endPos);
+    else emit changeEffectPosition(m_clipref, -1, indexes, endPos);
 }
 
 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
@@ -719,50 +716,62 @@ void EffectStackView2::slotCreateGroup(int ix)
        }
     }
     
-    CollapsibleGroup *group = new CollapsibleGroup(m_groupIndex, ix == 1, ix == m_currentEffectList.count() - 2, QString(), m_ui.container->widget());
+    CollapsibleGroup *group = new CollapsibleGroup(m_groupIndex, ix == 1, ix == m_currentEffectList.count() - 2, effectinfo, m_ui.container->widget());
     m_groupIndex++;
-    connect(group, SIGNAL(moveEffect(int,int,int,QString)), this , SLOT(slotMoveEffect(int,int,int,QString)));
+    connectGroup(group);
+    l->insertWidget(groupPos, group);
+    group->installEventFilter( this );
+    group->addGroupEffect(effectToMove);
+}
+
+void EffectStackView2::connectGroup(CollapsibleGroup *group)
+{
+    connect(group, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
+    connect(group, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
     connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
     connect(group, SIGNAL(groupRenamed(CollapsibleGroup *)), this , SLOT(slotRenameGroup(CollapsibleGroup*)));
     connect(group, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
     connect(group, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
-    l->insertWidget(groupPos, group);
-    group->installEventFilter( this );
-    group->addGroupEffect(effectToMove);
+    connect(group, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
 }
 
-void EffectStackView2::slotMoveEffect(int currentIndex, int newIndex, int groupIndex, QString groupName)
+void EffectStackView2::slotMoveEffect(QList <int> currentIndexes, int newIndex, int groupIndex, QString groupName)
 {
-    CollapsibleEffect *effectToMove = getEffectByIndex(currentIndex);
-    if (effectToMove == NULL) return;
+    if (currentIndexes.count() == 1) {
+       CollapsibleEffect *effectToMove = getEffectByIndex(currentIndexes.at(0));
+       if (effectToMove == NULL) return;
 
-    QDomElement oldeffect = effectToMove->effect();
-    QDomElement neweffect = oldeffect.cloneNode().toElement();
+       QDomElement oldeffect = effectToMove->effect();
+       QDomElement neweffect = oldeffect.cloneNode().toElement();
     
-    EffectInfo effectinfo;
-    effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
-    effectinfo.groupIndex = groupIndex;
-    effectinfo.groupName = groupName;
-    neweffect.setAttribute("kdenlive_info", effectinfo.toString());
-
-    ItemInfo info;
-    if (m_effectMetaInfo.trackMode) { 
-       info.track = m_trackInfo.type;
-        info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
-        info.cropStart = GenTime(0);
-        info.startPos = GenTime(-1);
-        info.track = 0;
-       emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->effectIndex(),false);
-    } else {
-       emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex(),false);
+       EffectInfo effectinfo;
+       effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
+       effectinfo.groupIndex = groupIndex;
+       effectinfo.groupName = groupName;
+       neweffect.setAttribute("kdenlive_info", effectinfo.toString());
+    
+       if (oldeffect.attribute("kdenlive_info") != effectinfo.toString()) {
+           // effect's group info or collapsed state changed
+           ItemInfo info;
+           if (m_effectMetaInfo.trackMode) { 
+               info.track = m_trackInfo.type;
+               info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
+               info.cropStart = GenTime(0);
+               info.startPos = GenTime(-1);
+               info.track = 0;
+               emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->effectIndex(),false);
+           } else {
+               emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex(),false);
+           }
+       }
     }
-    //if (currentIndex == newIndex) return;
+
     // Update effect index with new position
     if (m_effectMetaInfo.trackMode) {
-       emit changeEffectPosition(NULL, m_trackindex, currentIndex, newIndex);
+       emit changeEffectPosition(NULL, m_trackindex, currentIndexes, newIndex);
     }
     else {
-       emit changeEffectPosition(m_clipref, -1, currentIndex, newIndex);
+       emit changeEffectPosition(m_clipref, -1, currentIndexes, newIndex);
     }
 }
 
@@ -796,13 +805,8 @@ void EffectStackView2::dragEnterEvent(QDragEnterEvent *event)
     }
 }
 
-void EffectStackView2::dropEvent(QDropEvent *event)
+void EffectStackView2::processDroppedEffect(QDomElement e, QDropEvent *event)
 {
-    const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
-    //event->acceptProposedAction();
-    QDomDocument doc;
-    doc.setContent(effects, true);
-    QDomElement e = doc.documentElement();
     int ix = e.attribute("kdenlive_ix").toInt();
     if (e.tagName() == "effectgroup") {
        // We are dropping a group, all effects in group should be moved
@@ -814,16 +818,21 @@ void EffectStackView2::dropEvent(QDropEvent *event)
        EffectInfo info;
        info.fromString(effects.at(0).toElement().attribute("kdenlive_info"));
        if (info.groupIndex < 0) {
+           kDebug()<<"// ADDING EFFECT!!!";
            // Adding a new group effect to the stack
            event->setDropAction(Qt::CopyAction);
            event->accept();
            slotAddEffect(e);
            return;
        }
+       // Moving group: delete all effects and re-add them
+       QList <int> indexes;
        for (int i = 0; i < effects.count(); i++) {
-           //TODO: not working because wee need to move all effects in one go
-           slotMoveEffect(effects.at(i).toElement().attribute("kdenlive_ix").toInt(), m_currentEffectList.count() + 1 + i, info.groupIndex, info.groupName);
+           QDomElement effect = effects.at(i).cloneNode().toElement();
+           indexes << effect.attribute("kdenlive_ix").toInt();
        }
+       kDebug()<<"// Moving: "<<indexes<<" TO "<<m_currentEffectList.count();
+       slotMoveEffect(indexes, m_currentEffectList.count(), info.groupIndex, info.groupName);
     }
     else if (ix == 0) {
        // effect dropped from effects list, add it
@@ -835,10 +844,19 @@ void EffectStackView2::dropEvent(QDropEvent *event)
     }
     else {
        // User is moving an effect
-       slotMoveEffect(ix, m_currentEffectList.count() + 1, -1);
+       slotMoveEffect(QList<int> () << ix, m_currentEffectList.count() + 1, -1);
     }
     event->setDropAction(Qt::MoveAction);
     event->accept();
 }
 
+void EffectStackView2::dropEvent(QDropEvent *event)
+{
+    const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
+    //event->acceptProposedAction();
+    QDomDocument doc;
+    doc.setContent(effects, true);
+    processDroppedEffect(doc.documentElement(), event);
+}
+
 #include "effectstackview2.moc"