]> git.sesse.net Git - kdenlive/blobdiff - src/effectstackedit.cpp
Fix crash in thumbnails when deleting a clip
[kdenlive] / src / effectstackedit.cpp
index 7ade3c50e773669ecd4746635f664b5c46007524..7efab0f218314f9592ec2efe3a8bcfcd2c325180 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"
@@ -35,7 +37,7 @@
 #include "doubleparameterwidget.h"
 #include "cornerswidget.h"
 #include "beziercurve/beziersplinewidget.h"
-#ifdef QJSON
+#ifdef USE_QJSON
 #include "rotoscoping/rotowidget.h"
 #endif
 
@@ -70,6 +72,14 @@ 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) :
@@ -205,7 +215,7 @@ 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_keyframeEditor) delete m_keyframeEditor;
@@ -232,9 +242,8 @@ void EffectStackEdit::transferParamDesc(const QDomElement d, ItemInfo info, bool
         }
     }
 #endif
-    QDomElement e = m_params.toElement();
-    int minFrame = e.attribute("start").toInt();
-    int maxFrame = e.attribute("end").toInt();
+    int minFrame = d.attribute("start").toInt();
+    int maxFrame = d.attribute("end").toInt();
     // In transitions, maxFrame is in fact one frame after the end of transition
     if (maxFrame > 0) maxFrame --;
 
@@ -284,7 +293,7 @@ void EffectStackEdit::transferParamDesc(const QDomElement d, ItemInfo info, bool
             QStringList listitems = pa.attribute("paramlist").split(';');
             if (listitems.count() == 1) {
                 // probably custom effect created before change to ';' as separator
-                listitems = pa.attribute("paramlist").split(",");
+                listitems = pa.attribute("paramlist").split(',');
             }
             QDomElement list = pa.firstChildElement("paramlistdisplay");
             QStringList listitemsdisplay;
@@ -372,14 +381,14 @@ void EffectStackEdit::transferParamDesc(const QDomElement d, ItemInfo info, bool
                 KeyframeEdit *geo;
                 if (pa.attribute("widget") == "corners") {
                     // we want a corners-keyframe-widget
-                    CornersWidget *corners = new CornersWidget(m_monitor, pa, m_in, m_out, m_timecode, e.attribute("active_keyframe", "-1").toInt(), this);
+                    CornersWidget *corners = new CornersWidget(m_monitor, pa, m_in, m_out, m_timecode, d.attribute("active_keyframe", "-1").toInt(), this);
                     corners->slotShowScene(!disable);
                     connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
                     connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
                     connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
                     geo = static_cast<KeyframeEdit *>(corners);
                 } else {
-                    geo = new KeyframeEdit(pa, m_in, m_out, m_timecode, e.attribute("active_keyframe", "-1").toInt());
+                    geo = new KeyframeEdit(pa, m_in, m_out, m_timecode, d.attribute("active_keyframe", "-1").toInt());
                 }
                 m_vbox->addWidget(geo);
                 m_valueItems[paramName+"keyframe"] = geo;
@@ -392,10 +401,8 @@ void EffectStackEdit::transferParamDesc(const QDomElement d, ItemInfo info, bool
                 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)));
@@ -416,7 +423,12 @@ void EffectStackEdit::transferParamDesc(const QDomElement d, ItemInfo info, bool
             KisCurveWidget *curve = new KisCurveWidget(this);
             curve->setMaxPoints(pa.attribute("max").toInt());
             QList<QPointF> points;
-            int number = EffectsList::parameter(e, pa.attribute("number")).toInt();
+            int number;
+            if (d.attribute("version").toDouble() > 0.2) {
+                number = EffectsList::parameter(d, pa.attribute("number")).toDouble() * 10;
+            } else {
+                number = EffectsList::parameter(d, pa.attribute("number")).toInt();
+            }
             QString inName = pa.attribute("inpoints");
             QString outName = pa.attribute("outpoints");
             int start = pa.attribute("min").toInt();
@@ -425,7 +437,7 @@ void EffectStackEdit::transferParamDesc(const QDomElement d, ItemInfo info, bool
                 in.replace("%i", QString::number(j));
                 QString out = outName;
                 out.replace("%i", QString::number(j));
-                points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
+                points << QPointF(EffectsList::parameter(d, in).toDouble(), EffectsList::parameter(d, out).toDouble());
             }
             if (!points.isEmpty())
                 curve->setCurve(KisCubicCurve(points));
@@ -443,7 +455,7 @@ void EffectStackEdit::transferParamDesc(const QDomElement d, ItemInfo info, bool
 
             QString depends = pa.attribute("depends");
             if (!depends.isEmpty())
-                meetDependency(paramName, type, EffectsList::parameter(e, depends));
+                meetDependency(paramName, type, EffectsList::parameter(d, depends));
         } else if (type == "bezier_spline") {
             BezierSplineWidget *widget = new BezierSplineWidget(value, this);
             stretch = false;
@@ -452,8 +464,8 @@ void EffectStackEdit::transferParamDesc(const QDomElement d, ItemInfo info, bool
             connect(widget, SIGNAL(modified()), this, SLOT(collectAllParameters()));
             QString depends = pa.attribute("depends");
             if (!depends.isEmpty())
-                meetDependency(paramName, type, EffectsList::parameter(e, depends));
-#ifdef QJSON
+                meetDependency(paramName, type, EffectsList::parameter(d, depends));
+#ifdef USE_QJSON
         } else if (type == "roto-spline") {
             RotoWidget *roto = new RotoWidget(value, m_monitor, info, m_timecode, this);
             roto->slotShowScene(!disable);
@@ -530,6 +542,41 @@ void EffectStackEdit::transferParamDesc(const QDomElement d, ItemInfo info, bool
             connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(collectAllParameters()));
             connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(collectAllParameters()));
             m_uiItems.append(cval);
+        } else if (type == "keywords") {
+            Keywordval* kval = new Keywordval;
+            kval->setupUi(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;
+            fval->setupUi(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 {
             delete toFillin;
             toFillin = NULL;
@@ -681,7 +728,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();
@@ -725,7 +772,11 @@ void EffectStackEdit::collectAllParameters()
             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(newparam, number, QString::number(points.count()));
+            if (oldparam.attribute("version").toDouble() > 0.2) {
+                EffectsList::setParameter(newparam, number, locale.toString(points.count() / 10.));
+            } else {
+                EffectsList::setParameter(newparam, 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));
@@ -743,7 +794,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();
@@ -793,6 +844,19 @@ 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())