]> git.sesse.net Git - kdenlive/blobdiff - src/effectstack/collapsibleeffect.cpp
Fix transition changes not refreshing monitor
[kdenlive] / src / effectstack / collapsibleeffect.cpp
index 96c34e87f20b051f5fe04777d994dda0fda16077..2ce042cb857cc4a6432fc5640663a1f1f375b7fe 100644 (file)
@@ -59,6 +59,7 @@
 #include <KFileDialog>
 #include <KUrlRequester>
 #include <KColorScheme>
+#include <KColorUtils>
 
 class Boolval: public QWidget, public Ui::Boolval_UI
 {
@@ -131,7 +132,6 @@ CollapsibleEffect::CollapsibleEffect(QDomElement effect, QDomElement original_ef
     filterWheelEvent = true;
     m_info.fromString(effect.attribute("kdenlive_info"));
     setFont(KGlobalSettings::smallestReadableFont());
-   
     buttonUp->setIcon(KIcon("kdenlive-up"));
     buttonUp->setToolTip(i18n("Move effect up"));
     if (!lastEffect) {
@@ -157,13 +157,16 @@ CollapsibleEffect::CollapsibleEffect(QDomElement effect, QDomElement original_ef
     QDomElement namenode = m_effect.firstChildElement("name");
     if (namenode.isNull()) return;
     title->setText(i18n(namenode.text().toUtf8().data()));
+    /*
+     * Do not show icon, makes too much visual noise
     QString type = m_effect.attribute("type", QString());
     KIcon icon;
     if (type == "audio") icon = KIcon("kdenlive-show-audio");
     else if (m_effect.attribute("tag") == "region") icon = KIcon("kdenlive-mask-effect");
     else if (type == "custom") icon = KIcon("kdenlive-custom-effect");
     else icon = KIcon("kdenlive-show-video");
-    effecticon->setPixmap(icon.pixmap(16,16));
+    effecticon->setPixmap(icon.pixmap(16,16));*/
+    
     m_menu->addAction(KIcon("folder-new"), i18n("Create Group"), this, SLOT(slotCreateGroup()));
     setupWidget(info, metaInfo);
     setAcceptDrops(true);
@@ -172,14 +175,16 @@ CollapsibleEffect::CollapsibleEffect(QDomElement effect, QDomElement original_ef
     
     if (m_effect.attribute("disable") == "1") {
         title->setEnabled(false);
-       enabledBox->setChecked(false);
+       enabledButton->setChecked(true);
+       enabledButton->setIcon(KIcon("novisible"));
     }
     else {
-        enabledBox->setChecked(true);
+        enabledButton->setChecked(false);
+       enabledButton->setIcon(KIcon("visible"));
     }
 
     connect(collapseButton, SIGNAL(clicked()), this, SLOT(slotSwitch()));
-    connect(enabledBox, SIGNAL(toggled(bool)), this, SLOT(slotEnable(bool)));
+    connect(enabledButton, SIGNAL(toggled(bool)), this, SLOT(slotEnable(bool)));
     connect(buttonUp, SIGNAL(clicked()), this, SLOT(slotEffectUp()));
     connect(buttonDown, SIGNAL(clicked()), this, SLOT(slotEffectDown()));
     connect(buttonDel, SIGNAL(clicked()), this, SLOT(slotDeleteEffect()));
@@ -205,47 +210,43 @@ CollapsibleEffect::~CollapsibleEffect()
 }
 
 //static
-const QString CollapsibleEffect::getStyleSheet(QPalette p)
+const QString CollapsibleEffect::getStyleSheet()
 {
-    KColorScheme scheme(p.currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
-    QColor dark_bg = scheme.shade(KColorScheme::DarkShade);
+    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 midlight_bg = scheme.shade(KColorScheme::MidlightShade);
-    QColor normal_bg = scheme.background(KColorScheme::AlternateBackground).color();
     QColor alt_bg = scheme.background(KColorScheme::NormalBackground).color();
     
-    KColorScheme scheme2(p.currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
-    QColor normal_bg2 = scheme2.background(KColorScheme::NormalBackground).color();
-    QColor normal_bg3 = scheme2.background(KColorScheme::AlternateBackground).color();
-    
     QString stylesheet;
     
     // group editable labels
-    stylesheet.append(QString("MyEditableLabel { background-color: transparent;} "));
+    stylesheet.append(QString("MyEditableLabel { background-color: transparent;color: palette(bright-text);} "));
     
     // effect background
-    stylesheet.append(QString("QFrame#decoframe {border-radius:5px;border:0px solid %1;background:%3;}  QFrame:hover#decoframe {background:%4;} QFrame#decoframe[active=\"true\"] {background:%2;} ").arg(dark_bg.name()).arg(alt_bg.name()).arg(normal_bg2.name()).arg(normal_bg.name()));
+    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()));
     
-    // effect group background
-    stylesheet.append(QString("QFrame#decoframegroup {border-radius:5px;border:1px solid %1;background:%2;} QFrame#decoframegroup[active=\"true\"] {background:%3;} ").arg(dark_bg.name()).arg(normal_bg2.name()).arg(alt_bg.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 {border-radius: 5px;} QFrame#frame[active=\"true\"] {background:%1;}").arg(selected_bg.name()));
-    
+    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-radius: 5px; background: %2;}  QFrame#framegroup[active=\"true\"] {background:%1;} ").arg(selected_bg.name()).arg(normal_bg3.name()));
-    
-    // draggable effect content bar
-    stylesheet.append(QString("QProgressBar::chunk:horizontal {background: %1;border-top-left-radius: 4px;border-bottom-left-radius: 4px;} QProgressBar::chunk:horizontal#dragOnly {background: %2;border-top-left-radius: 4px;border-bottom-left-radius: 4px;} QProgressBar::chunk:horizontal:hover {background: %3;}").arg(normal_bg2.name()).arg(alt_bg.name()).arg(selected_bg.name()));
+    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 content bar
-    stylesheet.append(QString("QProgressBar:horizontal {border: 1px solid %1;border-top-left-radius: 4px;border-bottom-left-radius: 4px;border-right:0px;background:%4;padding: 0px;text-align:left center} QProgressBar:horizontal:disabled {border: 1px solid %5} QProgressBar:horizontal#dragOnly {background: %4} QProgressBar:horizontal[inTimeline=\"true\"] { border: 1px solid %2;border-right: 0px;background: %3;padding: 0px;text-align:left center } QProgressBar::chunk:horizontal[inTimeline=\"true\"] {background: %2;}").arg(dark_bg.name()).arg(hover_bg.name()).arg(light_bg.name()).arg(alt_bg.name()).arg(normal_bg2.name()));
+    // 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 %1;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 %4;} QAbstractSpinBox::up-button#dragBox {width:0px;padding:0px;} QAbstractSpinBox[inTimeline=\"true\"]#dragBox { border: 1px solid %2;} QAbstractSpinBox:hover#dragBox {border: 1px solid %3;} ").arg(dark_bg.name()).arg(hover_bg.name()).arg(selected_bg.name()).arg(normal_bg2.name()));
+    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()));
 
     return stylesheet;
 }
@@ -262,6 +263,11 @@ void CollapsibleEffect::slotUnGroup()
 
 bool CollapsibleEffect::eventFilter( QObject * o, QEvent * e ) 
 {
+    if (e->type() == QEvent::Enter) {
+       frame->setProperty("mouseover", true);
+       frame->setStyleSheet(frame->styleSheet());
+       return QWidget::eventFilter(o, e);
+    }
     if (e->type() == QEvent::Wheel) {
        QWheelEvent *we = static_cast<QWheelEvent *>(e);
        if (!filterWheelEvent || we->modifiers() != Qt::NoModifier) {
@@ -326,29 +332,31 @@ void CollapsibleEffect::setActive(bool activate)
 
 void CollapsibleEffect::mouseDoubleClickEvent ( QMouseEvent * event )
 {
-    if (frame->underMouse() && collapseButton->isEnabled()) slotSwitch();
-    QWidget::mouseDoubleClickEvent(event);
+    if (frame->underMouse() && collapseButton->isEnabled()) {
+        event->accept();
+        slotSwitch();
+    }
+    else event->ignore();
 }
 
-void CollapsibleEffect::mousePressEvent ( QMouseEvent *event )
+void CollapsibleEffect::mouseReleaseEvent( QMouseEvent *event )
 {
-  
-    if (!decoframe->property("active").toBool() && !isGroup()) emit activateEffect(effectIndex());
-    QWidget::mousePressEvent(event);
+  if (!decoframe->property("active").toBool()) emit activateEffect(effectIndex());
+  QWidget::mouseReleaseEvent(event);
 }
 
-
-void CollapsibleEffect::slotEnable(bool enable)
+void CollapsibleEffect::slotEnable(bool disable, bool updateMainStatus)
 {
-    title->setEnabled(enable);
-    enabledBox->blockSignals(true);
-    enabledBox->setChecked(enable);
-    enabledBox->blockSignals(false);
-    m_effect.setAttribute("disable", enable ? 0 : 1);
-    if (enable || KdenliveSettings::disable_effect_parameters()) {
-       widgetFrame->setEnabled(enable);
+    title->setEnabled(!disable);
+    enabledButton->blockSignals(true);
+    enabledButton->setChecked(disable);
+    enabledButton->blockSignals(false);
+    enabledButton->setIcon(disable ? KIcon("novisible") : KIcon("visible"));
+    m_effect.setAttribute("disable", disable ? 1 : 0);
+    if (!disable || KdenliveSettings::disable_effect_parameters()) {
+        widgetFrame->setEnabled(!disable);
     }
-    emit effectStateChanged(!enable, effectIndex());
+    emit effectStateChanged(disable, effectIndex(), updateMainStatus);
 }
 
 void CollapsibleEffect::slotDeleteEffect()
@@ -416,11 +424,11 @@ void CollapsibleEffect::slotShow(bool show)
     widgetFrame->setVisible(show);
     if (show) {
         collapseButton->setArrowType(Qt::DownArrow);
-       m_info.isCollapsed = false;
+        m_info.isCollapsed = false;
     }
     else {
         collapseButton->setArrowType(Qt::RightArrow);
-       m_info.isCollapsed = true;
+        m_info.isCollapsed = true;
     }
     m_effect.setAttribute("kdenlive_info", m_info.toString());
     emit parameterChanged(m_original_effect, m_effect, effectIndex());   
@@ -463,9 +471,9 @@ int CollapsibleEffect::effectIndex() const
 void CollapsibleEffect::updateWidget(ItemInfo info, QDomElement effect, EffectMetaInfo *metaInfo)
 {
     if (m_paramWidget) {
-       // cleanup
-       delete m_paramWidget;
-       m_paramWidget = NULL;
+        // cleanup
+        delete m_paramWidget;
+        m_paramWidget = NULL;
     }
     m_effect = effect;
     setupWidget(info, metaInfo);
@@ -480,10 +488,10 @@ void CollapsibleEffect::setupWidget(ItemInfo info, EffectMetaInfo *metaInfo)
 
     if (m_effect.attribute("tag") == "region") {
         QVBoxLayout *vbox = new QVBoxLayout(widgetFrame);
-        vbox->setContentsMargins(2, 0, 2, 0);
-       vbox->setSpacing(2);
+        vbox->setContentsMargins(0, 0, 0, 0);
+        vbox->setSpacing(2);
         QDomNodeList effects =  m_effect.elementsByTagName("effect");
-       QDomNodeList origin_effects =  m_original_effect.elementsByTagName("effect");
+        QDomNodeList origin_effects =  m_original_effect.elementsByTagName("effect");
         QWidget *container = new QWidget(widgetFrame);
         vbox->addWidget(container);
         m_paramWidget = new ParameterContainer(m_effect.toElement(), info, metaInfo, container);
@@ -545,7 +553,7 @@ void CollapsibleEffect::slotSyncEffectsPos(int pos)
 void CollapsibleEffect::dragEnterEvent(QDragEnterEvent *event)
 {
     if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
-       frame->setProperty("active", true);
+       frame->setProperty("target", true);
        frame->setStyleSheet(frame->styleSheet());
        event->acceptProposedAction();
     }
@@ -553,13 +561,13 @@ void CollapsibleEffect::dragEnterEvent(QDragEnterEvent *event)
 
 void CollapsibleEffect::dragLeaveEvent(QDragLeaveEvent */*event*/)
 {
-    frame->setProperty("active", false);
+    frame->setProperty("target", false);
     frame->setStyleSheet(frame->styleSheet());
 }
 
 void CollapsibleEffect::dropEvent(QDropEvent *event)
 {
-    frame->setProperty("active", false);
+    frame->setProperty("target", false);
     frame->setStyleSheet(frame->styleSheet());
     const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
     //event->acceptProposedAction();
@@ -607,7 +615,7 @@ ParameterContainer::ParameterContainer(QDomElement effect, ItemInfo info, Effect
 
     bool stretch = true;
     m_vbox = new QVBoxLayout(parent);
-    m_vbox->setContentsMargins(2, 0, 2, 0);
+    m_vbox->setContentsMargins(4, 0, 4, 0);
     m_vbox->setSpacing(2);
 
     for (int i = 0; i < namenode.count() ; i++) {
@@ -761,9 +769,11 @@ ParameterContainer::ParameterContainer(QDomElement effect, ItemInfo info, Effect
                 m_keyframeEditor->addParameter(pa);
             }
         } else if (type == "color") {
+           if (pa.hasAttribute("paramprefix")) value.remove(0, pa.attribute("paramprefix").size());
             if (value.startsWith('#'))
                 value = value.replace('#', "0x");
             ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, value, parent);
+           choosecolor->setAlphaChannelEnabled(true);
             m_vbox->addWidget(choosecolor);
             m_valueItems[paramName] = choosecolor;
             connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
@@ -784,7 +794,13 @@ ParameterContainer::ParameterContainer(QDomElement effect, ItemInfo info, Effect
             KisCurveWidget *curve = new KisCurveWidget(parent);
             curve->setMaxPoints(pa.attribute("max").toInt());
             QList<QPointF> points;
-            int number = EffectsList::parameter(e, pa.attribute("number")).toInt();
+            int number;
+           if (e.attribute("version").toDouble() > 0.2) {
+               // Rounding gives really weird results. (int) (10 * 0.3) gives 2! So for now, add 0.5 to get correct result
+                number = EffectsList::parameter(e, pa.attribute("number")).toDouble() * 10 + 0.5;
+            } else {
+                number = EffectsList::parameter(e, pa.attribute("number")).toInt();
+            }
             QString inName = pa.attribute("inpoints");
             QString outName = pa.attribute("outpoints");
             int start = pa.attribute("min").toInt();
@@ -982,7 +998,7 @@ void ParameterContainer::meetDependency(const QString& name, QString type, QStri
     } else if (type == "bezier_spline") {
         BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
         if (widget) {
-            widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10)));
+            widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10 + 0.5)));
         }
     }
 }
@@ -1072,10 +1088,10 @@ void ParameterContainer::slotCollectAllParameters()
     QDomNodeList namenode = m_effect.elementsByTagName("parameter");
 
     for (int i = 0; i < namenode.count() ; i++) {
-        QDomNode pa = namenode.item(i);
+        QDomElement pa = namenode.item(i).toElement();
         QDomElement na = pa.firstChildElement("name");
-        QString type = pa.attributes().namedItem("type").nodeValue();
-        QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
+        QString type = pa.attribute("type");
+        QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
         if (type == "complex")
             paramName.append("complex");
         else if (type == "position")
@@ -1102,6 +1118,7 @@ void ParameterContainer::slotCollectAllParameters()
         } else if (type == "color") {
             ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
             setValue = choosecolor->getColor();
+           if (pa.hasAttribute("paramprefix")) setValue.prepend(pa.attribute("paramprefix"));
         } else if (type == "complex") {
             ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
             namenode.item(i) = complex->getParamDesc();
@@ -1140,12 +1157,16 @@ void ParameterContainer::slotCollectAllParameters()
         } else if (type == "curve") {
             KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
             QList<QPointF> points = curve->curve().points();
-            QString number = pa.attributes().namedItem("number").nodeValue();
-            QString inName = pa.attributes().namedItem("inpoints").nodeValue();
-            QString outName = pa.attributes().namedItem("outpoints").nodeValue();
-            int off = pa.attributes().namedItem("min").nodeValue().toInt();
-            int end = pa.attributes().namedItem("max").nodeValue().toInt();
-            EffectsList::setParameter(m_effect, number, QString::number(points.count()));
+            QString number = pa.attribute("number");
+            QString inName = pa.attribute("inpoints");
+            QString outName = pa.attribute("outpoints");
+            int off = pa.attribute("min").toInt();
+            int end = pa.attribute("max").toInt();
+            if (oldparam.attribute("version").toDouble() > 0.2) {
+                EffectsList::setParameter(m_effect, number, locale.toString(points.count() / 10.));
+            } else {
+                EffectsList::setParameter(m_effect, number, QString::number(points.count()));
+            }
             for (int j = 0; (j < points.count() && j + off <= end); j++) {
                 QString in = inName;
                 in.replace("%i", QString::number(j + off));
@@ -1154,13 +1175,13 @@ void ParameterContainer::slotCollectAllParameters()
                 EffectsList::setParameter(m_effect, in, locale.toString(points.at(j).x()));
                 EffectsList::setParameter(m_effect, out, locale.toString(points.at(j).y()));
             }
-            QString depends = pa.attributes().namedItem("depends").nodeValue();
+            QString depends = pa.attribute("depends");
             if (!depends.isEmpty())
                 meetDependency(paramName, type, EffectsList::parameter(m_effect, depends));
         } else if (type == "bezier_spline") {
             BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
             setValue = widget->spline();
-            QString depends = pa.attributes().namedItem("depends").nodeValue();
+            QString depends = pa.attribute("depends");
             if (!depends.isEmpty())
                 meetDependency(paramName, type, EffectsList::parameter(m_effect, depends));
 #ifdef USE_QJSON
@@ -1201,15 +1222,15 @@ void ParameterContainer::slotCollectAllParameters()
 
             setValue = getWipeString(info);
         } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
-            QDomElement elem = pa.toElement();
             QString realName = i18n(na.toElement().text().toUtf8().data());
             QString val = m_keyframeEditor->getValue(realName);
-            elem.setAttribute("keyframes", val);
+            pa.setAttribute("keyframes", val);
 
-            if (m_keyframeEditor->isVisibleParam(realName))
-                elem.setAttribute("intimeline", "1");
-            else if (elem.hasAttribute("intimeline"))
-                elem.removeAttribute("intimeline");
+            if (m_keyframeEditor->isVisibleParam(realName)) {
+                pa.setAttribute("intimeline", "1");
+           }
+            else if (pa.hasAttribute("intimeline"))
+                pa.removeAttribute("intimeline");
         } else if (type == "url") {
             KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
             setValue = req->url().path();
@@ -1228,9 +1249,10 @@ void ParameterContainer::slotCollectAllParameters()
             setValue = fontfamily->currentFont().family();
         }
         if (!setValue.isNull())
-            pa.attributes().namedItem("value").setNodeValue(setValue);
+            pa.setAttribute("value", setValue);
 
     }
+    kDebug()<<"// PARAM STK CHANGED";
     emit parameterChanged(oldparam, m_effect, m_effect.attribute("kdenlive_ix").toInt());
 }