]> git.sesse.net Git - kdenlive/blobdiff - src/effectstack/effectstackview2.cpp
Cleanup effect stack (part 2) - show monitor scene when required
[kdenlive] / src / effectstack / effectstackview2.cpp
index 46b9afa5dfdb5fc519a2a6e8917f5ab8b78f6340..a7d21662db8374afb9e2187034a230c47e3f5eff 100644 (file)
@@ -2,8 +2,8 @@
                           effecstackview.cpp2  -  description
                              -------------------
     begin                : Feb 15 2008
-    copyright            : (C) 2008 by Marco Gittler
-    email                : g.marco@freenet.de
+    copyright            : (C) 2008 by Marco Gittler (g.marco@freenet.de)
+    copyright            : (C) 2012 by Jean-Baptiste Mardelle (jb@kdenlive.org)
  ***************************************************************************/
 
 /***************************************************************************
@@ -35,6 +35,7 @@
 #include <KStandardDirs>
 #include <KFileDialog>
 #include <KColorScheme>
+#include <KColorUtils>
 
 #include <QMenu>
 #include <QTextStream>
@@ -48,11 +49,13 @@ EffectStackView2::EffectStackView2(Monitor *monitor, QWidget *parent) :
         m_clipref(NULL),
         m_trackindex(-1),
         m_draggedEffect(NULL),
+        m_draggedGroup(NULL),
         m_groupIndex(0)
 {
     m_effectMetaInfo.trackMode = false;
     m_effectMetaInfo.monitor = monitor;
     m_effects = QList <CollapsibleEffect*>();
+    setAcceptDrops(true);
 
     m_ui.setupUi(this);
     setFont(KGlobalSettings::smallestReadableFont());
@@ -67,24 +70,29 @@ EffectStackView2::EffectStackView2(Monitor *monitor, QWidget *parent) :
     setEnabled(false);
 
     
-    setStyleSheet(CollapsibleEffect::getStyleSheet(palette()));
+    setStyleSheet(getStyleSheet());
 }
 
 EffectStackView2::~EffectStackView2()
 {
 }
 
+void EffectStackView2::updatePalette()
+{
+    setStyleSheet(getStyleSheet());
+}
 
 void EffectStackView2::slotRenderPos(int pos)
 {
     if (m_effects.isEmpty()) return;
+    slotCheckMonitorPosition(pos);
     if (!m_effectMetaInfo.trackMode && m_clipref) pos = pos - m_clipref->startPos().frames(KdenliveSettings::project_fps());
 
     for (int i = 0; i< m_effects.count(); i++)
         m_effects.at(i)->slotSyncEffectsPos(pos);
 }
 
-void EffectStackView2::slotClipItemSelected(ClipItem* c, int ix)
+void EffectStackView2::slotClipItemSelected(ClipItem* c)
 {
     if (c && !c->isEnabled()) return;
     if (c && c == m_clipref) {
@@ -102,12 +110,9 @@ void EffectStackView2::slotClipItemSelected(ClipItem* c, int ix)
                 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
             }
             m_ui.checkAll->setEnabled(true);
-            ix = c->selectedEffectIndex();
             QString size = c->baseClip()->getProperty("frame_size");
             double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
             m_effectMetaInfo.frameSize = QPoint((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
-        } else {
-            ix = 0;
         }
     }
     if (m_clipref == NULL) {
@@ -120,7 +125,7 @@ void EffectStackView2::slotClipItemSelected(ClipItem* c, int ix)
     setEnabled(true);
     m_effectMetaInfo.trackMode = false;
     m_currentEffectList = m_clipref->effectList();
-    setupListView(ix);
+    setupListView();
 }
 
 void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
@@ -133,14 +138,15 @@ void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
     m_ui.checkAll->setToolTip(QString());
     m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
     m_trackindex = ix;
-    setupListView(0);
+    setupListView();
 }
 
 
-void EffectStackView2::setupListView(int ix)
+void EffectStackView2::setupListView()
 {
     blockSignals(true);
     m_draggedEffect = NULL;
+    m_draggedGroup = NULL;
     disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
     m_effects.clear();
     m_groupIndex = 0;
@@ -155,8 +161,6 @@ void EffectStackView2::setupListView(int ix)
     QVBoxLayout *vbox1 = new QVBoxLayout(view);
     vbox1->setContentsMargins(0, 0, 0, 0);
     vbox1->setSpacing(0);
-    
-    if (m_currentEffectList.isEmpty()) m_ui.labelComment->setHidden(true);
 
     for (int i = 0; i < m_currentEffectList.count(); i++) {
         QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
@@ -169,8 +173,7 @@ void EffectStackView2::setupListView(int ix)
        EffectInfo effectInfo;
        effectInfo.fromString(d.attribute("kdenlive_info"));
        if (effectInfo.groupIndex >= 0) {
-           // effect is in a group
-           
+           // effect is in a group    
            for (int j = 0; j < vbox1->count(); j++) {
                CollapsibleGroup *eff = static_cast<CollapsibleGroup *>(vbox1->itemAt(j)->widget());
                if (eff->isGroup() &&  eff->groupIndex() == effectInfo.groupIndex) {
@@ -180,11 +183,10 @@ void EffectStackView2::setupListView(int ix)
            }
            
            if (group == NULL) {
-               group = new CollapsibleGroup(effectInfo.groupIndex, i == 0, i == m_currentEffectList.count() - 1, m_ui.container->widget());
-               if (!effectInfo.groupName.isEmpty()) group->title->setText(effectInfo.groupName);
-               connect(group, SIGNAL(moveEffect(int,int,int)), this, SLOT(slotMoveEffect(int,int,int)));
-               connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
+               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 );
            }
            if (effectInfo.groupIndex >= m_groupIndex) m_groupIndex = effectInfo.groupIndex + 1;
        }
@@ -194,6 +196,7 @@ void EffectStackView2::setupListView(int ix)
         kDebug() << "IMPORTED STK: " << doc.toString();*/
        
        ItemInfo info;
+       bool isSelected = false;
        if (m_effectMetaInfo.trackMode) { 
             info.track = m_trackInfo.type;
             info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
@@ -201,44 +204,65 @@ void EffectStackView2::setupListView(int ix)
             info.startPos = GenTime(-1);
             info.track = 0;
        }
-       else info = m_clipref->info();
+       else {
+           info = m_clipref->info();
+       }
 
         CollapsibleEffect *currentEffect = new CollapsibleEffect(d, m_currentEffectList.at(i), info, &m_effectMetaInfo, i == m_currentEffectList.count() - 1, view);
+       if (m_effectMetaInfo.trackMode) {
+           isSelected = currentEffect->effectIndex() == 1;
+       }
+       else {
+           isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
+       }
+       if (isSelected) currentEffect->setActive(true);
         m_effects.append(currentEffect);
         if (group) {
            group->addGroupEffect(currentEffect);
        } else {
            vbox1->addWidget(currentEffect);
        }
-       if (currentEffect->effectIndex() == ix) currentEffect->setActive(true);
-
-       // Check drag & drop
-       currentEffect->installEventFilter( this );
-
-        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)), 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(effectStateChanged(bool, int)), this, SLOT(slotUpdateEffectState(bool, int)));
-        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)), this , SLOT(slotMoveEffect(int,int,int)));
-       connect(currentEffect, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
-       
-        //ui.title->setPixmap(icon.pixmap(QSize(12, 12)));
+       connectEffect(currentEffect);
     }
+    
+    if (m_currentEffectList.isEmpty()) {
+       m_ui.labelComment->setHidden(true);
+    }
+    else {
+       // Adjust group effects (up / down buttons)
+       QList<CollapsibleGroup *> allGroups = m_ui.container->widget()->findChildren<CollapsibleGroup *>();
+       for (int i = 0; i < allGroups.count(); i++) {
+           allGroups.at(i)->adjustEffects();
+       }
+       connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
+    }
+    
     vbox1->addStretch(10);
     slotUpdateCheckAllButton();
-    connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
     
     // Wait a little bit for the new layout to be ready, then check if we have a scrollbar
     QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
 }
 
+void EffectStackView2::connectEffect(CollapsibleEffect *currentEffect)
+{
+    // Check drag & drop
+    currentEffect->installEventFilter( this );
+    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)), 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(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(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
+    connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
+    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()
 {
@@ -267,17 +291,30 @@ bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
        m_draggedEffect = qobject_cast<CollapsibleEffect*>(o);
        if (m_draggedEffect) {
            QMouseEvent *me = static_cast<QMouseEvent *>(e);
-           if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse()))
+           if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse())) {
                m_clickPoint = me->globalPos();
+           }
            else {
                m_clickPoint = QPoint();
                m_draggedEffect = NULL;
            }
            e->accept();
-           return false;
+           return true;
+       }
+       m_draggedGroup = qobject_cast<CollapsibleGroup*>(o);
+       if (m_draggedGroup) {
+           QMouseEvent *me = static_cast<QMouseEvent *>(e);
+           if (me->button() == Qt::LeftButton && (m_draggedGroup->frame->underMouse() || m_draggedGroup->title()->underMouse()))
+               m_clickPoint = me->globalPos();
+           else {
+               m_clickPoint = QPoint();
+               m_draggedGroup = NULL;
+           }
+           e->accept();
+           return true;
        }
     }  
-    if (e->type() == QEvent::MouseMove)  {
+    /*if (e->type() == QEvent::MouseMove)  {
        if (qobject_cast<CollapsibleEffect*>(o)) {
            QMouseEvent *me = static_cast<QMouseEvent *>(e);
            if (me->buttons() != Qt::LeftButton) {
@@ -289,32 +326,43 @@ bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
                return true;
            }
        }
-    }
+    }*/
     return QWidget::eventFilter(o, e);
 }
 
 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
 {
-    if (m_draggedEffect && (event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
-       startDrag();
+    if (m_draggedEffect || m_draggedGroup) {
+       if ((event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
+           startDrag();
+       }
     }
 }
 
 void EffectStackView2::mouseReleaseEvent(QMouseEvent * event)
 {
     m_draggedEffect = NULL;
+    m_draggedGroup = NULL;
     QWidget::mouseReleaseEvent(event);
 }
 
 void EffectStackView2::startDrag()
 {
-    QDrag *drag = new QDrag(this);
     // The data to be transferred by the drag and drop operation is contained in a QMimeData object
-    QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
-    QPixmap pixmap = QPixmap::grabWidget(m_draggedEffect->title);
-    drag->setPixmap(pixmap);
     QDomDocument doc;
-    doc.appendChild(doc.importNode(effect, true));
+    QPixmap pixmap;
+    if (m_draggedEffect) {
+       QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
+       doc.appendChild(doc.importNode(effect, true));
+       pixmap = QPixmap::grabWidget(m_draggedEffect->title);
+    }
+    else if (m_draggedGroup) {
+       doc = m_draggedGroup->effectsData();
+       pixmap = QPixmap::grabWidget(m_draggedGroup->title());
+    }
+    else return;
+    QDrag *drag = new QDrag(this);
+    drag->setPixmap(pixmap);
     QMimeData *mime = new QMimeData;
     QByteArray data;
     data.append(doc.toString().toUtf8());
@@ -327,13 +375,13 @@ void EffectStackView2::startDrag()
 }
 
 
-void EffectStackView2::slotUpdateEffectState(bool disable, int index)
+void EffectStackView2::slotUpdateEffectState(bool disable, int index, bool updateMainStatus)
 {
     if (m_effectMetaInfo.trackMode)
         emit changeEffectState(NULL, m_trackindex, index, disable);
     else
         emit changeEffectState(m_clipref, -1, index, disable);
-    slotUpdateCheckAllButton();
+    if (updateMainStatus) slotUpdateCheckAllButton();
 }
 
 
@@ -361,11 +409,18 @@ void EffectStackView2::slotSeekTimeline(int pos)
 
 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
 {
-    if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
-        if (!m_effectMetaInfo.monitor->getEffectEdit()->getScene()->views().at(0)->isVisible())
-            m_effectMetaInfo.monitor->slotEffectScene(true);
-    } else {
-        m_effectMetaInfo.monitor->slotEffectScene(false);
+    CollapsibleEffect *current = currentEffect();
+    if (current && current->needsMonitorEffectScene()) {
+       if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
+           if (!m_effectMetaInfo.monitor->effectSceneDisplayed()) {
+               m_effectMetaInfo.monitor->slotShowEffectScene(true);
+           }
+       } else {
+           m_effectMetaInfo.monitor->slotShowEffectScene(false);
+       }
+    }
+    else {
+       m_effectMetaInfo.monitor->slotShowEffectScene(false);
     }
 }
 
@@ -391,17 +446,17 @@ void EffectStackView2::clear()
 
 void EffectStackView2::slotCheckAll(int state)
 {
-    if (state == 1) {
-        state = 2;
+    if (state == Qt::PartiallyChecked) {
+        state = Qt::Checked;
         m_ui.checkAll->blockSignals(true);
         m_ui.checkAll->setCheckState(Qt::Checked);
         m_ui.checkAll->blockSignals(false);
     }
 
-    bool disabled = (state != 2);
+    bool disabled = state == Qt::Unchecked;
     for (int i = 0; i < m_effects.count(); i++) {
        if (!m_effects.at(i)->isGroup()) {
-           m_effects.at(i)->slotEnable(!disabled);
+           m_effects.at(i)->slotEnable(disabled, false);
        }
     }
 }
@@ -412,7 +467,7 @@ void EffectStackView2::slotUpdateCheckAllButton()
     bool hasDisabled = false;
     
     for (int i = 0; i < m_effects.count(); i++) {
-       if (m_effects.at(i)->enabledBox->isChecked()) hasEnabled = true;
+       if (!m_effects.at(i)->enabledButton->isChecked()) hasEnabled = true;
        else hasDisabled = true; 
     }
 
@@ -461,9 +516,9 @@ CollapsibleEffect *EffectStackView2::getEffectByIndex(int ix)
 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
 {
     if (m_effectMetaInfo.trackMode)
-        emit updateEffect(NULL, m_trackindex, old, e, ix);
+        emit updateEffect(NULL, m_trackindex, old, e, ix,false);
     else if (m_clipref) {
-        emit updateEffect(m_clipref, -1, old, e, ix);
+        emit updateEffect(m_clipref, -1, old, e, ix, false);
         // Make sure the changed effect is currently displayed
         slotSetCurrentEffect(ix);
     }
@@ -472,18 +527,46 @@ void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomE
 
 void EffectStackView2::slotSetCurrentEffect(int ix)
 {
-    if (m_clipref && ix != m_clipref->selectedEffectIndex())
+    if (m_clipref && ix != m_clipref->selectedEffectIndex()) {
         m_clipref->setSelectedEffect(ix);
-    for (int i = 0; i < m_effects.count(); i++) {
-       if (m_effects.at(i)->effectIndex() == ix) {
-           m_effects.at(i)->setActive(true);
-           m_ui.labelComment->setText(i18n(m_effects.at(i)->effect().firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
-            m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
+       for (int i = 0; i < m_effects.count(); i++) {
+           if (m_effects.at(i)->effectIndex() == ix) {
+               if (m_effects.at(i)->isActive()) return;
+               m_effects.at(i)->setActive(true);
+               slotCheckMonitorPosition(m_effectMetaInfo.monitor->render->seekFramePosition());
+               m_ui.labelComment->setText(i18n(m_effects.at(i)->effect().firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
+               m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
+           }
+           else m_effects.at(i)->setActive(false);
        }
-        else m_effects.at(i)->setActive(false);
     }
 }
 
+CollapsibleEffect *EffectStackView2::currentEffect() const
+{
+    for (int i = 0; i < m_effects.count(); i++) {
+       if (m_effects.at(i)->isActive()) return m_effects.at(i);
+    }
+    return NULL;
+}
+
+void EffectStackView2::slotDeleteGroup(QDomDocument doc)
+{
+    QDomNodeList effects = doc.elementsByTagName("effect");
+    ClipItem * clip = NULL;
+    int ix;
+    if (m_effectMetaInfo.trackMode) {
+       ix = m_trackindex;
+    }
+    else {
+       clip = m_clipref;
+       ix = -1;
+    }
+    
+    for (int i = 0; i < effects.count(); i++)
+       emit removeEffect(clip, ix, effects.at(i).toElement());
+}
+
 void EffectStackView2::slotDeleteEffect(const QDomElement effect)
 {
     if (m_effectMetaInfo.trackMode)
@@ -497,19 +580,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)
@@ -544,12 +627,17 @@ void EffectStackView2::slotResetEffect(int ix)
             info.startPos = GenTime(-1);
             info.track = 0;
            m_effects.at(ix)->updateWidget(info, dom, &m_effectMetaInfo);
-            emit updateEffect(NULL, m_trackindex, old, dom, ix);
+            emit updateEffect(NULL, m_trackindex, old, dom, ix,false);
         } else {
             m_clipref->initEffect(dom);
-           m_effects.at(ix)->updateWidget(m_clipref->info(), dom, &m_effectMetaInfo);
+            for (int i = 0; i < m_effects.count(); i++) {
+                if (m_effects.at(i)->effectIndex() == ix) {
+                    m_effects.at(i)->updateWidget(m_clipref->info(), dom, &m_effectMetaInfo);
+                    break;
+                }
+            }
             //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
-            emit updateEffect(m_clipref, -1, old, dom, ix);
+            emit updateEffect(m_clipref, -1, old, dom, ix,false);
         }
     }
 
@@ -563,6 +651,66 @@ void EffectStackView2::slotShowComments()
     emit showComments(m_ui.buttonShowComments->isChecked());
 }
 
+void EffectStackView2::slotCreateRegion(int ix, KUrl url)
+{
+    QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
+    QDomElement neweffect = oldeffect.cloneNode().toElement();
+    QDomElement region = MainWindow::videoEffects.getEffectByTag("region", "region").cloneNode().toElement();
+    region.appendChild(region.ownerDocument().importNode(neweffect, true));
+    region.setAttribute("kdenlive_ix", ix);
+    EffectsList::setParameter(region, "resource", url.path());
+    if (m_effectMetaInfo.trackMode)
+        emit updateEffect(NULL, m_trackindex, oldeffect, region, ix,false);
+    else if (m_clipref) {
+        emit updateEffect(m_clipref, -1, oldeffect, region, ix, false);
+        // Make sure the changed effect is currently displayed
+        //slotSetCurrentEffect(ix);
+    }
+    // refresh effect stack
+    ItemInfo info;
+    bool isSelected = false;
+    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;
+    }
+    else {
+       info = m_clipref->info();
+    }
+    CollapsibleEffect *current = getEffectByIndex(ix);
+    m_effects.removeAll(current);
+    current->setEnabled(false);
+    m_currentEffectList.removeAt(ix);
+    m_currentEffectList.insert(region);
+    current->deleteLater();
+    CollapsibleEffect *currentEffect = new CollapsibleEffect(region, m_currentEffectList.itemFromIndex(ix), info, &m_effectMetaInfo, ix == m_currentEffectList.count() - 1, m_ui.container->widget());
+    connectEffect(currentEffect);
+    
+    if (m_effectMetaInfo.trackMode) {
+       isSelected = currentEffect->effectIndex() == 1;
+    }
+    else {
+       isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
+    }
+    if (isSelected) currentEffect->setActive(true);
+    m_effects.append(currentEffect);
+    // TODO: region in group?
+    //if (group) {
+    // group->addGroupEffect(currentEffect);
+    //} else {
+    QVBoxLayout *vbox = static_cast <QVBoxLayout *> (m_ui.container->widget()->layout());
+    vbox->insertWidget(ix, currentEffect);
+    //}
+
+    // Check drag & drop
+    currentEffect->installEventFilter( this );
+       
+    QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));    
+    
+}
+
 void EffectStackView2::slotCreateGroup(int ix)
 {
     QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
@@ -579,9 +727,9 @@ void EffectStackView2::slotCreateGroup(int ix)
         info.cropStart = GenTime(0);
         info.startPos = GenTime(-1);
         info.track = 0;
-       emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix);
+       emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix, false);
     } else {
-       emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix);
+       emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix, false);
     }
     
     QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
@@ -596,46 +744,62 @@ void EffectStackView2::slotCreateGroup(int ix)
        }
     }
     
-    CollapsibleGroup *group = new CollapsibleGroup(m_groupIndex, ix == 1, ix == m_currentEffectList.count() - 2, 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)), this , SLOT(slotMoveEffect(int,int,int)));
-    connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
+    connectGroup(group);
     l->insertWidget(groupPos, group);
+    group->installEventFilter( this );
     group->addGroupEffect(effectToMove);
 }
 
-void EffectStackView2::slotMoveEffect(int currentIndex, int newIndex, int groupIndex)
+void EffectStackView2::connectGroup(CollapsibleGroup *group)
 {
-    CollapsibleEffect *effectToMove = getEffectByIndex(currentIndex);
-    if (effectToMove == NULL) return;
+    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)));
+    connect(group, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
+}
 
-    QDomElement oldeffect = effectToMove->effect();
-    QDomElement neweffect = oldeffect.cloneNode().toElement();
-    
-    EffectInfo effectinfo;
-    effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
-    effectinfo.groupIndex = groupIndex;
-    neweffect.setAttribute("kdenlive_info", effectinfo.toString());
+void EffectStackView2::slotMoveEffect(QList <int> currentIndexes, int newIndex, int groupIndex, QString groupName)
+{
+    if (currentIndexes.count() == 1) {
+       CollapsibleEffect *effectToMove = getEffectByIndex(currentIndexes.at(0));
+       if (effectToMove == NULL) return;
 
-    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());
-    } else {
-       emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex());
-    }
+       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());
     
-    //if (currentIndex == newIndex) return;
+       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);
+           }
+       }
+    }
+
     // 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);
     }
 }
 
@@ -647,4 +811,122 @@ void EffectStackView2::slotUnGroup(CollapsibleGroup* group)
     group->deleteLater();
 }
 
+void EffectStackView2::slotRenameGroup(CollapsibleGroup *group)
+{
+    QList <CollapsibleEffect*> effects = group->effects();
+    for (int i = 0; i < effects.count(); i++) {
+       QDomElement origin = effects.at(i)->effect();
+       QDomElement changed = origin.cloneNode().toElement();
+       changed.setAttribute("kdenlive_info", effects.at(i)->infoString());
+       if (m_effectMetaInfo.trackMode) { 
+           emit updateEffect(NULL, m_trackindex, origin, changed, effects.at(i)->effectIndex(),false);
+       } else {
+           emit updateEffect(m_clipref, -1, origin, changed, effects.at(i)->effectIndex(),false);
+       }
+    }
+}
+
+void EffectStackView2::dragEnterEvent(QDragEnterEvent *event)
+{
+    if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
+       event->acceptProposedAction();
+    }
+}
+
+void EffectStackView2::processDroppedEffect(QDomElement e, QDropEvent *event)
+{
+    int ix = e.attribute("kdenlive_ix").toInt();
+    if (e.tagName() == "effectgroup") {
+       // We are dropping a group, all effects in group should be moved
+       QDomNodeList effects = e.elementsByTagName("effect");
+       if (effects.count() == 0) {
+           event->ignore();
+           return;
+       }
+       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++) {
+           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
+       e.setAttribute("kdenlive_ix", m_currentEffectList.count() + 1);
+       event->setDropAction(Qt::CopyAction);
+       event->accept();
+       slotAddEffect(e);
+       return;
+    }
+    else {
+       // User is moving an effect
+       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);
+}
+
+//static
+const QString EffectStackView2::getStyleSheet()
+{
+    KColorScheme scheme(QApplication::palette().currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
+    QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
+    QColor hgh = KColorUtils::mix(QApplication::palette().window().color(), selected_bg, 0.2);
+    QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
+    QColor light_bg = scheme.shade(KColorScheme::LightShade);
+    QColor alt_bg = scheme.background(KColorScheme::NormalBackground).color();
+    
+    QString stylesheet;
+    
+    // effect background
+    stylesheet.append(QString("QFrame#decoframe {border-top-left-radius:5px;border-top-right-radius:5px;border-bottom:2px solid palette(mid);border-top:1px solid palette(light);} QFrame#decoframe[active=\"true\"] {background: %1;}").arg(hgh.name()));
+    
+    // effect in group background
+    stylesheet.append(QString("QFrame#decoframesub {border-top:1px solid palette(light);}  QFrame#decoframesub[active=\"true\"] {background: %1;}").arg(hgh.name()));
+    
+    // group background
+    stylesheet.append(QString("QFrame#decoframegroup {border-top-left-radius:5px;border-top-right-radius:5px;border:2px solid palette(dark);margin:0px;margin-top:2px;} "));
+    
+    // effect title bar
+    stylesheet.append(QString("QFrame#frame {margin-bottom:2px;border-top-left-radius:5px;border-top-right-radius:5px;}  QFrame#frame[target=\"true\"] {background: palette(highlight);}"));
+
+    // group effect title bar
+    stylesheet.append(QString("QFrame#framegroup {border-top-left-radius:2px;border-top-right-radius:2px;background: palette(dark);}  QFrame#framegroup[target=\"true\"] {background: palette(highlight);} "));
+    
+    // draggable effect bar content
+    stylesheet.append(QString("QProgressBar::chunk:horizontal {background: palette(button);border-top-left-radius: 4px;border-bottom-left-radius: 4px;} QProgressBar::chunk:horizontal#dragOnly {background: %1;border-top-left-radius: 4px;border-bottom-left-radius: 4px;} QProgressBar::chunk:horizontal:hover {background: %2;}").arg(alt_bg.name()).arg(selected_bg.name()));
+    
+    // draggable effect bar
+    stylesheet.append(QString("QProgressBar:horizontal {border: 1px solid palette(dark);border-top-left-radius: 4px;border-bottom-left-radius: 4px;border-right:0px;background:%3;padding: 0px;text-align:left center} QProgressBar:horizontal:disabled {border: 1px solid palette(button)} QProgressBar:horizontal#dragOnly {background: %3} QProgressBar:horizontal[inTimeline=\"true\"] { border: 1px solid %1;border-right: 0px;background: %2;padding: 0px;text-align:left center } QProgressBar::chunk:horizontal[inTimeline=\"true\"] {background: %1;}").arg(hover_bg.name()).arg(light_bg.name()).arg(alt_bg.name()));
+    
+    // spin box for draggable widget
+    stylesheet.append(QString("QAbstractSpinBox#dragBox {border: 1px solid palette(dark);border-top-right-radius: 4px;border-bottom-right-radius: 4px;padding-right:0px;} QAbstractSpinBox::down-button#dragBox {width:0px;padding:0px;} QAbstractSpinBox:disabled#dragBox {border: 1px solid palette(button);} QAbstractSpinBox::up-button#dragBox {width:0px;padding:0px;} QAbstractSpinBox[inTimeline=\"true\"]#dragBox { border: 1px solid %1;} QAbstractSpinBox:hover#dragBox {border: 1px solid %2;} ").arg(hover_bg.name()).arg(selected_bg.name()));
+    
+    // group editable labels
+    stylesheet.append(QString("MyEditableLabel { background-color: transparent; color: palette(bright-text); border-radius: 2px;border: 1px solid transparent;} MyEditableLabel:hover {border: 1px solid palette(highlight);} "));
+    
+    return stylesheet;
+}
+
 #include "effectstackview2.moc"