]> git.sesse.net Git - kdenlive/blobdiff - src/effectstackedit.cpp
New widget for effect group
[kdenlive] / src / effectstackedit.cpp
index 7253b4957a0cab52c6caac74781804f0ccb70029..b56a1a869deaecd76771d6b17472dc601bca5b0e 100644 (file)
@@ -20,6 +20,8 @@
 #include "ui_boolval_ui.h"
 #include "ui_wipeval_ui.h"
 #include "ui_urlval_ui.h"
+#include "ui_keywordval_ui.h"
+#include "ui_fontval_ui.h"
 #include "complexparameter.h"
 #include "geometryval.h"
 #include "positionedit.h"
 #include "doubleparameterwidget.h"
 #include "cornerswidget.h"
 #include "beziercurve/beziersplinewidget.h"
-#ifdef QJSON
+#ifdef USE_QJSON
 #include "rotoscoping/rotowidget.h"
 #endif
 
 #include <KDebug>
 #include <KLocale>
 #include <KFileDialog>
-#include <KColorScheme>
 
 #include <QVBoxLayout>
 #include <QLabel>
@@ -70,44 +71,39 @@ class Urlval: public QWidget, public Ui::Urlval_UI
 {
 };
 
+class Keywordval: public QWidget, public Ui::Keywordval_UI
+{
+};
+
+class Fontval: public QWidget, public Ui::Fontval_UI
+{
+};
+
 QMap<QString, QImage> EffectStackEdit::iconCache;
 
 EffectStackEdit::EffectStackEdit(Monitor *monitor, QWidget *parent) :
     QScrollArea(parent),
     m_in(0),
     m_out(0),
-    m_frameSize(QPoint()),
     m_keyframeEditor(NULL),
     m_monitor(monitor),
-    m_geometryWidget(NULL)
+    m_geometryWidget(NULL),
+    m_paramWidget(NULL)
 {
     m_baseWidget = new QWidget(this);
+    m_metaInfo.monitor = monitor;
+    m_metaInfo.trackMode = false;
     setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
     setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
     setFrameStyle(QFrame::NoFrame);
     setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
     
-    QPalette p = palette();
-    KColorScheme scheme(p.currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
-    QColor dark_bg = scheme.shade(KColorScheme::DarkShade);
-    QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
-    QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();    
-    QColor light_bg = scheme.shade(KColorScheme::LightShade);
-    
-    QString stylesheet(QString("QProgressBar:horizontal {border: 1px solid %1;border-radius:0px;border-top-left-radius: 4px;border-bottom-left-radius: 4px;border-right: 0px;background:%4;padding: 0px;text-align:left center}\
-                                QProgressBar:horizontal#dragOnly {background: %1} QProgressBar:horizontal:hover#dragOnly {background: %3} QProgressBar:horizontal:hover {border: 1px solid %3;border-right: 0px;}\
-                                QProgressBar::chunk:horizontal {background: %1;} QProgressBar::chunk:horizontal:hover {background: %3;}\
-                                QProgressBar:horizontal[inTimeline=\"true\"] { border: 1px solid %2;border-right: 0px;background: %4;padding: 0px;text-align:left center } QProgressBar::chunk:horizontal[inTimeline=\"true\"] {background: %2;}\
-                                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::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(selected_bg.name()).arg(hover_bg.name()).arg(light_bg.name()));
-    setStyleSheet(stylesheet);
-    
-    setWidget(m_baseWidget);
-    setWidgetResizable(true);
-    m_vbox = new QVBoxLayout(m_baseWidget);
+    setStyleSheet(CollapsibleEffect::getStyleSheet(palette()));
+    setWidget(m_baseWidget);   
+    /*m_vbox = new QVBoxLayout(m_baseWidget);
     m_vbox->setContentsMargins(0, 0, 0, 0);
-    m_vbox->setSpacing(2);
+    m_vbox->setSpacing(2);    */
+    setWidgetResizable(true);
 }
 
 EffectStackEdit::~EffectStackEdit()
@@ -116,8 +112,21 @@ EffectStackEdit::~EffectStackEdit()
     delete m_baseWidget;
 }
 
+Monitor *EffectStackEdit::monitor()
+{
+    return m_metaInfo.monitor;
+}
+
+void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
+{
+    m_metaInfo.profile = profile;
+    m_metaInfo.timecode = t;
+}
+
 void EffectStackEdit::setFrameSize(QPoint p)
 {
+    m_metaInfo.frameSize = p;
+    /*
     m_frameSize = p;
     QDomNodeList namenode = m_params.elementsByTagName("parameter");
     for (int i = 0; i < namenode.count() ; i++) {
@@ -137,38 +146,12 @@ void EffectStackEdit::setFrameSize(QPoint p)
                 break;
             }
         }
-    }
+    }*/
 }
 
 void EffectStackEdit::updateTimecodeFormat()
 {
-    if (m_keyframeEditor)
-        m_keyframeEditor->updateTimecodeFormat();
-
-    QDomNodeList namenode = m_params.elementsByTagName("parameter");
-    for (int i = 0; i < namenode.count() ; i++) {
-        QDomNode pa = namenode.item(i);
-        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());
-
-        if (type == "geometry") {
-            if (KdenliveSettings::on_monitor_effects()) {
-                if (m_geometryWidget) m_geometryWidget->updateTimecodeFormat();
-            } else {
-                Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
-                geom->updateTimecodeFormat();
-            }
-            break;
-        } else if (type == "position") {
-            PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
-            posi->updateTimecodeFormat();
-            break;
-        } else if (type == "roto-spline") {
-            RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems[paramName]);
-            widget->updateTimecodeFormat();
-        }
-    }
+    if (m_paramWidget) m_paramWidget->updateTimecodeFormat();
 }
 
 void EffectStackEdit::meetDependency(const QString& name, QString type, QString value)
@@ -187,12 +170,6 @@ void EffectStackEdit::meetDependency(const QString& name, QString type, QString
     }
 }
 
-void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
-{
-    m_profile = profile;
-    m_timecode = t;
-}
-
 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
 {
     m_params.setAttribute(name, value);
@@ -205,9 +182,20 @@ void EffectStackEdit::updateParameter(const QString &name, const QString &value)
     }
 }
 
-void EffectStackEdit::transferParamDesc(const QDomElement &d, ItemInfo info, bool isEffect)
+void EffectStackEdit::transferParamDesc(const QDomElement &d, ItemInfo info, bool /*isEffect*/)
 {
-    clearAllItems();
+    if (m_paramWidget) delete m_paramWidget;
+    m_paramWidget = new ParameterContainer(d, info, &m_metaInfo, m_baseWidget);
+    connect (m_paramWidget, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)));
+    
+    connect(m_paramWidget, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)));
+    
+    connect (this, SIGNAL(syncEffectsPos(int)), m_paramWidget, SIGNAL(syncEffectsPos(int)));
+    connect (m_paramWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
+    connect (m_paramWidget, SIGNAL(seekTimeline(int)), this, SIGNAL(seekTimeline(int)));
+    return;
+    /*
+    //clearAllItems();
     if (m_keyframeEditor) delete m_keyframeEditor;
     m_keyframeEditor = NULL;
     m_params = d;
@@ -252,12 +240,11 @@ void EffectStackEdit::transferParamDesc(const QDomElement &d, ItemInfo info, boo
         QString comment;
         if (!commentElem.isNull())
             comment = i18n(commentElem.text().toUtf8().data());
-        QWidget * toFillin = new QWidget(m_baseWidget);
         QString value = pa.attribute("value").isNull() ?
                         pa.attribute("default") : pa.attribute("value");
 
 
-        /** See effects/README for info on the different types */
+      
 
         if (type == "double" || type == "constant") {
             double min;
@@ -279,7 +266,9 @@ void EffectStackEdit::transferParamDesc(const QDomElement &d, ItemInfo info, boo
             connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
         } else if (type == "list") {
             Listval *lsval = new Listval;
+            QWidget * toFillin = new QWidget(m_baseWidget);
             lsval->setupUi(toFillin);
+            m_vbox->addWidget(toFillin);
             QStringList listitems = pa.attribute("paramlist").split(';');
             if (listitems.count() == 1) {
                 // probably custom effect created before change to ';' as separator
@@ -317,7 +306,9 @@ void EffectStackEdit::transferParamDesc(const QDomElement &d, ItemInfo info, boo
             m_uiItems.append(lsval);
         } else if (type == "bool") {
             Boolval *bval = new Boolval;
+            QWidget * toFillin = new QWidget(m_baseWidget);
             bval->setupUi(toFillin);
+            m_vbox->addWidget(toFillin);
             bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
             bval->name->setText(paramName);
             bval->labelComment->setText(comment);
@@ -391,10 +382,8 @@ void EffectStackEdit::transferParamDesc(const QDomElement &d, ItemInfo info, boo
                 m_keyframeEditor->addParameter(pa);
             }
         } else if (type == "color") {
-            if (value.startsWith('#'))
-                value = value.replace('#', "0x");
-            bool ok;
-            ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, QColor(value.toUInt(&ok, 16)), this);
+            ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, value, this);
+            choosecolor->setAlphaChannelEnabled(pa.attribute("alpha") == "1");
             m_vbox->addWidget(choosecolor);
             m_valueItems[paramName] = choosecolor;
             connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
@@ -457,7 +446,7 @@ void EffectStackEdit::transferParamDesc(const QDomElement &d, ItemInfo info, boo
             QString depends = pa.attribute("depends");
             if (!depends.isEmpty())
                 meetDependency(paramName, type, EffectsList::parameter(d, depends));
-#ifdef QJSON
+#ifdef USE_QJSON
         } else if (type == "roto-spline") {
             RotoWidget *roto = new RotoWidget(value, m_monitor, info, m_timecode, this);
             roto->slotShowScene(!disable);
@@ -471,7 +460,9 @@ void EffectStackEdit::transferParamDesc(const QDomElement &d, ItemInfo info, boo
 #endif
         } else if (type == "wipe") {
             Wipeval *wpval = new Wipeval;
+            QWidget * toFillin = new QWidget(m_baseWidget);
             wpval->setupUi(toFillin);
+            m_vbox->addWidget(toFillin);
             wipeInfo w = getWipeInfo(value);
             switch (w.start) {
             case UP:
@@ -526,7 +517,9 @@ void EffectStackEdit::transferParamDesc(const QDomElement &d, ItemInfo info, boo
             m_uiItems.append(wpval);
         } else if (type == "url") {
             Urlval *cval = new Urlval;
+            QWidget * toFillin = new QWidget(m_baseWidget);
             cval->setupUi(toFillin);
+            m_vbox->addWidget(toFillin);
             cval->label->setText(paramName);
             cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
             m_valueItems[paramName] = cval;
@@ -534,13 +527,51 @@ void EffectStackEdit::transferParamDesc(const QDomElement &d, ItemInfo info, boo
             connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(collectAllParameters()));
             connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(collectAllParameters()));
             m_uiItems.append(cval);
-        } else {
-            delete toFillin;
-            toFillin = NULL;
-        }
-
-        if (toFillin)
+        } else if (type == "keywords") {
+            Keywordval* kval = new Keywordval;
+            QWidget * toFillin = new QWidget(m_baseWidget);
+            kval->setupUi(toFillin);
             m_vbox->addWidget(toFillin);
+            kval->label->setText(paramName);
+            kval->lineeditwidget->setText(value);
+            QDomElement klistelem = pa.firstChildElement("keywords");
+            QDomElement kdisplaylistelem = pa.firstChildElement("keywordsdisplay");
+            QStringList keywordlist;
+            QStringList keyworddisplaylist;
+            if (!klistelem.isNull()) {
+                keywordlist = klistelem.text().split(';');
+                keyworddisplaylist = i18n(kdisplaylistelem.text().toUtf8().data()).split(';');
+            }
+            if (keyworddisplaylist.count() != keywordlist.count()) {
+                keyworddisplaylist = keywordlist;
+            }
+            for (int i = 0; i < keywordlist.count(); i++) {
+                kval->comboboxwidget->addItem(keyworddisplaylist.at(i), keywordlist.at(i));
+            }
+            // Add disabled user prompt at index 0
+            kval->comboboxwidget->insertItem(0, i18n("<select a keyword>"), "");
+            kval->comboboxwidget->model()->setData( kval->comboboxwidget->model()->index(0,0), QVariant(Qt::NoItemFlags), Qt::UserRole -1);
+            kval->comboboxwidget->setCurrentIndex(0);
+            m_valueItems[paramName] = kval;
+            connect(kval->lineeditwidget, SIGNAL(editingFinished()) , this, SLOT(collectAllParameters()));
+            connect(kval->comboboxwidget, SIGNAL(activated (const QString&)), this, SLOT(collectAllParameters()));
+            m_uiItems.append(kval);
+        } else if (type == "fontfamily") {
+            Fontval* fval = new Fontval;
+            QWidget * toFillin = new QWidget(m_baseWidget);
+            fval->setupUi(toFillin);
+            m_vbox->addWidget(toFillin);
+            fval->name->setText(paramName);
+            fval->fontfamilywidget->setCurrentFont(QFont(value));
+            m_valueItems[paramName] = fval;
+            connect(fval->fontfamilywidget, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(collectAllParameters())) ;
+            m_uiItems.append(fval);
+        } else if (type == "filterjob") {
+            QPushButton *button = new QPushButton(paramName, m_baseWidget);
+            m_vbox->addWidget(button);
+            m_valueItems[paramName] = button;
+            connect(button, SIGNAL(pressed()), this, SLOT(slotStartFilterJobAction()));   
+        }
     }
 
     if (stretch)
@@ -557,98 +588,12 @@ void EffectStackEdit::transferParamDesc(const QDomElement &d, ItemInfo info, boo
     }
     for (int i = 0; i < allWidgets.count(); i++) {
         allWidgets.at(i)->setSpinSize(minSize);
-    }
-}
-
-wipeInfo EffectStackEdit::getWipeInfo(QString value)
-{
-    wipeInfo info;
-    // Convert old geometry values that used a comma as separator
-    if (value.contains(',')) value.replace(',','/');
-    QString start = value.section(';', 0, 0);
-    QString end = value.section(';', 1, 1).section('=', 1, 1);
-    if (start.startsWith("-100%/0"))
-        info.start = LEFT;
-    else if (start.startsWith("100%/0"))
-        info.start = RIGHT;
-    else if (start.startsWith("0%/100%"))
-        info.start = DOWN;
-    else if (start.startsWith("0%/-100%"))
-        info.start = UP;
-    else
-        info.start = CENTER;
-
-    if (start.count(':') == 2)
-        info.startTransparency = start.section(':', -1).toInt();
-    else
-        info.startTransparency = 100;
-
-    if (end.startsWith("-100%/0"))
-        info.end = LEFT;
-    else if (end.startsWith("100%/0"))
-        info.end = RIGHT;
-    else if (end.startsWith("0%/100%"))
-        info.end = DOWN;
-    else if (end.startsWith("0%/-100%"))
-        info.end = UP;
-    else
-        info.end = CENTER;
-
-    if (end.count(':') == 2)
-        info.endTransparency = end.section(':', -1).toInt();
-    else
-        info.endTransparency = 100;
-
-    return info;
-}
-
-QString EffectStackEdit::getWipeString(wipeInfo info)
-{
-
-    QString start;
-    QString end;
-    switch (info.start) {
-    case LEFT:
-        start = "-100%/0%:100%x100%";
-        break;
-    case RIGHT:
-        start = "100%/0%:100%x100%";
-        break;
-    case DOWN:
-        start = "0%/100%:100%x100%";
-        break;
-    case UP:
-        start = "0%/-100%:100%x100%";
-        break;
-    default:
-        start = "0%/0%:100%x100%";
-        break;
-    }
-    start.append(':' + QString::number(info.startTransparency));
-
-    switch (info.end) {
-    case LEFT:
-        end = "-100%/0%:100%x100%";
-        break;
-    case RIGHT:
-        end = "100%/0%:100%x100%";
-        break;
-    case DOWN:
-        end = "0%/100%:100%x100%";
-        break;
-    case UP:
-        end = "0%/-100%:100%x100%";
-        break;
-    default:
-        end = "0%/0%:100%x100%";
-        break;
-    }
-    end.append(':' + QString::number(info.endTransparency));
-    return QString(start + ";-1=" + end);
+    }*/
 }
 
 void EffectStackEdit::collectAllParameters()
 {
+  /*
     if (m_valueItems.isEmpty() || m_params.isNull()) return;
     const QDomElement oldparam = m_params.cloneNode().toElement();
     QDomElement newparam = oldparam.cloneNode().toElement();
@@ -685,7 +630,7 @@ void EffectStackEdit::collectAllParameters()
             setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
         } else if (type == "color") {
             ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
-            setValue = choosecolor->getColor().name();
+            setValue = choosecolor->getColor();
         } else if (type == "complex") {
             ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
             namenode.item(i) = complex->getParamDesc();
@@ -704,19 +649,13 @@ void EffectStackEdit::collectAllParameters()
             setValue = QString::number(pos);
             if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_black") {
                 // Make sure duration is not longer than clip
-                /*if (pos > m_out) {
-                    pos = m_out;
-                    pedit->setPosition(pos);
-                }*/
+
                 EffectsList::setParameter(newparam, "in", QString::number(m_in));
                 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
                 setValue.clear();
             } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
                 // Make sure duration is not longer than clip
-                /*if (pos > m_out) {
-                    pos = m_out;
-                    pedit->setPosition(pos);
-                }*/
+
                 EffectsList::setParameter(newparam, "in", QString::number(m_out - pos));
                 EffectsList::setParameter(newparam, "out", QString::number(m_out));
                 setValue.clear();
@@ -751,7 +690,7 @@ void EffectStackEdit::collectAllParameters()
             QString depends = pa.attributes().namedItem("depends").nodeValue();
             if (!depends.isEmpty())
                 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
-#ifdef QJSON
+#ifdef USE_QJSON
         } else if (type == "roto-spline") {
             RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
             setValue = widget->getSpline();
@@ -801,13 +740,26 @@ void EffectStackEdit::collectAllParameters()
         } else if (type == "url") {
             KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
             setValue = req->url().path();
+        } else if (type == "keywords"){
+            QLineEdit *line = ((Keywordval*)m_valueItems.value(paramName))->lineeditwidget;
+            QComboBox *combo = ((Keywordval*)m_valueItems.value(paramName))->comboboxwidget;
+            if(combo->currentIndex())
+            {
+                QString comboval = combo->itemData(combo->currentIndex()).toString();
+                line->insert(comboval);
+                combo->setCurrentIndex(0);
+            }
+            setValue = line->text();
+        } else if (type == "fontfamily") {
+            QFontComboBox* fontfamily = ((Fontval*)m_valueItems.value(paramName))->fontfamilywidget;
+            setValue = fontfamily->currentFont().family();
         }
 
         if (!setValue.isNull())
             pa.attributes().namedItem("value").setNodeValue(setValue);
 
     }
-    emit parameterChanged(oldparam, newparam);
+    emit parameterChanged(oldparam, newparam);*/
 }
 
 void EffectStackEdit::clearAllItems()
@@ -836,3 +788,19 @@ void EffectStackEdit::slotSyncEffectsPos(int pos)
 {
     emit syncEffectsPos(pos);
 }
+
+void EffectStackEdit::slotStartFilterJobAction()
+{
+    QDomNodeList namenode = m_params.elementsByTagName("parameter");
+    for (int i = 0; i < namenode.count() ; i++) {
+        QDomElement pa = namenode.item(i).toElement();
+        QString type = pa.attribute("type");
+        if (type == "filterjob") {
+            emit startFilterJob(pa.attribute("filtertag"), pa.attribute("filterparams"), pa.attribute("finalfilter"), pa.attribute("consumer"), pa.attribute("consumerparams"), pa.attribute("wantedproperties"));
+            kDebug()<<" - - -PROPS:\n"<<pa.attribute("filtertag")<<"-"<< pa.attribute("filterparams")<<"-"<< pa.attribute("consumer")<<"-"<< pa.attribute("consumerparams")<<"-"<< pa.attribute("wantedproperties");
+            break;
+        }
+    }
+}
+
+