]> git.sesse.net Git - kdenlive/blobdiff - src/effectstack/effectstackview2.cpp
Fix transition changes not refreshing monitor
[kdenlive] / src / effectstack / effectstackview2.cpp
index 55827ded1217aa29e96fbc49994e564bd5eac0a1..e5984ee0f253321ae2f4660672a4663f1a50274c 100644 (file)
@@ -68,13 +68,17 @@ EffectStackView2::EffectStackView2(Monitor *monitor, QWidget *parent) :
     setEnabled(false);
 
     
-    setStyleSheet(CollapsibleEffect::getStyleSheet(palette()));
+    setStyleSheet(CollapsibleEffect::getStyleSheet());
 }
 
 EffectStackView2::~EffectStackView2()
 {
 }
 
+void EffectStackView2::updatePalette()
+{
+    setStyleSheet(CollapsibleEffect::getStyleSheet());
+}
 
 void EffectStackView2::slotRenderPos(int pos)
 {
@@ -85,7 +89,7 @@ void EffectStackView2::slotRenderPos(int pos)
         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) {
@@ -103,12 +107,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) {
@@ -121,7 +122,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)
@@ -134,11 +135,11 @@ 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;
@@ -186,6 +187,8 @@ void EffectStackView2::setupListView(int ix)
                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)));
                vbox1->addWidget(group);
                group->installEventFilter( this );
            }
@@ -197,6 +200,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());
@@ -204,16 +208,24 @@ 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 );
@@ -224,7 +236,7 @@ void EffectStackView2::setupListView(int ix)
        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(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)));
@@ -270,14 +282,15 @@ 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) {
@@ -289,10 +302,10 @@ bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
                m_draggedGroup = NULL;
            }
            e->accept();
-           return false;
+           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) {
@@ -304,7 +317,7 @@ bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
                return true;
            }
        }
-    }
+    }*/
     return QWidget::eventFilter(o, e);
 }
 
@@ -353,13 +366,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();
 }
 
 
@@ -417,17 +430,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);
        }
     }
 }
@@ -438,7 +451,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; 
     }
 
@@ -487,9 +500,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);
     }
@@ -498,18 +511,36 @@ 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) {
+               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());
+           }
+           else m_effects.at(i)->setActive(false);
        }
-        else m_effects.at(i)->setActive(false);
     }
 }
 
+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)
@@ -570,12 +601,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);
         }
     }
 
@@ -605,9 +641,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());
@@ -627,6 +663,8 @@ void EffectStackView2::slotCreateGroup(int ix)
     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)));
     l->insertWidget(groupPos, group);
     group->installEventFilter( this );
     group->addGroupEffect(effectToMove);
@@ -653,11 +691,10 @@ void EffectStackView2::slotMoveEffect(int currentIndex, int newIndex, int groupI
         info.cropStart = GenTime(0);
         info.startPos = GenTime(-1);
         info.track = 0;
-       emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->effectIndex());
+       emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->effectIndex(),false);
     } else {
-       emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex());
+       emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex(),false);
     }
-    
     //if (currentIndex == newIndex) return;
     // Update effect index with new position
     if (m_effectMetaInfo.trackMode) {
@@ -684,9 +721,9 @@ void EffectStackView2::slotRenameGroup(CollapsibleGroup *group)
        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());
+           emit updateEffect(NULL, m_trackindex, origin, changed, effects.at(i)->effectIndex(),false);
        } else {
-           emit updateEffect(m_clipref, -1, origin, changed, effects.at(i)->effectIndex());
+           emit updateEffect(m_clipref, -1, origin, changed, effects.at(i)->effectIndex(),false);
        }
     }
 }