]> git.sesse.net Git - kdenlive/blob - src/effectstackedit.cpp
Make c0rners keyframable
[kdenlive] / src / effectstackedit.cpp
1 /***************************************************************************
2                           effecstackedit.cpp  -  description
3                              -------------------
4     begin                : Feb 15 2008
5     copyright            : (C) 2008 by Marco Gittler
6     email                : g.marco@freenet.de
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #include "effectstackedit.h"
19 #include "ui_listval_ui.h"
20 #include "ui_boolval_ui.h"
21 #include "ui_wipeval_ui.h"
22 #include "ui_urlval_ui.h"
23 #include "complexparameter.h"
24 #include "geometryval.h"
25 #include "positionedit.h"
26 #include "projectlist.h"
27 #include "effectslist.h"
28 #include "kdenlivesettings.h"
29 #include "profilesdialog.h"
30 #include "kis_curve_widget.h"
31 #include "kis_cubic_curve.h"
32 #include "choosecolorwidget.h"
33 #include "geometrywidget.h"
34 #include "colortools.h"
35 #include "doubleparameterwidget.h"
36 #include "cornerswidget.h"
37 #include "beziercurve/beziersplinewidget.h"
38
39 #include <KDebug>
40 #include <KLocale>
41 #include <KFileDialog>
42
43 #include <QVBoxLayout>
44 #include <QLabel>
45 #include <QPushButton>
46 #include <QCheckBox>
47 #include <QScrollArea>
48
49
50 class Boolval: public QWidget, public Ui::Boolval_UI
51 {
52 };
53
54 class Listval: public QWidget, public Ui::Listval_UI
55 {
56 };
57
58 class Wipeval: public QWidget, public Ui::Wipeval_UI
59 {
60 };
61
62 class Urlval: public QWidget, public Ui::Urlval_UI
63 {
64 };
65
66 QMap<QString, QImage> EffectStackEdit::iconCache;
67
68 EffectStackEdit::EffectStackEdit(Monitor *monitor, QWidget *parent) :
69     QScrollArea(parent),
70     m_in(0),
71     m_out(0),
72     m_frameSize(QPoint()),
73     m_keyframeEditor(NULL),
74     m_monitor(monitor)
75 {
76     m_baseWidget = new QWidget(this);
77     setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
78     setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
79     setFrameStyle(QFrame::NoFrame);
80     setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
81
82     setWidget(m_baseWidget);
83     setWidgetResizable(true);
84     m_vbox = new QVBoxLayout(m_baseWidget);
85     m_vbox->setContentsMargins(0, 0, 0, 0);
86     m_vbox->setSpacing(0);
87     //wid->show();
88 }
89
90 EffectStackEdit::~EffectStackEdit()
91 {
92     iconCache.clear();
93     delete m_baseWidget;
94 }
95
96 void EffectStackEdit::setFrameSize(QPoint p)
97 {
98     m_frameSize = p;
99     QDomNodeList namenode = m_params.elementsByTagName("parameter");
100     for (int i = 0; i < namenode.count() ; i++) {
101         QDomNode pa = namenode.item(i);
102         QDomNode na = pa.firstChildElement("name");
103         QString type = pa.attributes().namedItem("type").nodeValue();
104         QString paramName = i18n(na.toElement().text().toUtf8().data());
105
106         if (type == "geometry" && !KdenliveSettings::on_monitor_effects()) {
107             Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
108             geom->setFrameSize(m_frameSize);
109             break;
110         }
111     }
112 }
113
114 void EffectStackEdit::updateTimecodeFormat()
115 {
116     if (m_keyframeEditor)
117         m_keyframeEditor->updateTimecodeFormat();
118
119     QDomNodeList namenode = m_params.elementsByTagName("parameter");
120     for (int i = 0; i < namenode.count() ; i++) {
121         QDomNode pa = namenode.item(i);
122         QDomNode na = pa.firstChildElement("name");
123         QString type = pa.attributes().namedItem("type").nodeValue();
124         QString paramName = i18n(na.toElement().text().toUtf8().data());
125
126         if (type == "geometry") {
127             if (KdenliveSettings::on_monitor_effects()) {
128                 GeometryWidget *geom = (GeometryWidget*)m_valueItems[paramName+"geometry"];
129                 geom->updateTimecodeFormat();
130             } else {
131                 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
132                 geom->updateTimecodeFormat();
133             }
134             break;
135         }
136         if (type == "position") {
137             PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
138             posi->updateTimecodeFormat();
139             break;
140         }
141     }
142 }
143
144 void EffectStackEdit::meetDependency(const QString& name, QString type, QString value)
145 {
146     if (type == "curve") {
147         KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
148         if (curve) {
149             int color = value.toInt();
150             curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
151         }
152     } else if (type == "bezier_spline") {
153         BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
154         if (widget) {
155             widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10)));
156         }
157     }
158 }
159
160 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
161 {
162     m_profile = profile;
163     m_timecode = t;
164 }
165
166 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
167 {
168     m_params.setAttribute(name, value);
169
170     if (name == "disable") {
171         // if effect is disabled, disable parameters widget
172         bool enabled = value.toInt() == 0 || !KdenliveSettings::disable_effect_parameters();
173         setEnabled(enabled);
174         emit effectStateChanged(enabled);
175     }
176 }
177
178 void EffectStackEdit::transferParamDesc(const QDomElement d, int pos, int in, int out, bool isEffect)
179 {
180     clearAllItems();
181     if (m_keyframeEditor) delete m_keyframeEditor;
182     m_keyframeEditor = NULL;
183     m_params = d;
184     m_in = in;
185     m_out = out;
186     if (m_params.isNull()) {
187         kDebug() << "// EMPTY EFFECT STACK";
188         return;
189     }
190
191     QDomNodeList namenode = m_params.elementsByTagName("parameter");
192     QDomElement e = m_params.toElement();
193     const int minFrame = e.attribute("start").toInt();
194     const int maxFrame = e.attribute("end").toInt();
195
196     bool disable = d.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
197     setEnabled(!disable);
198
199     bool stretch = true;
200
201
202     for (int i = 0; i < namenode.count() ; i++) {
203         QDomElement pa = namenode.item(i).toElement();
204         QDomElement na = pa.firstChildElement("name");
205         QDomElement commentElem = pa.firstChildElement("comment");
206         QString type = pa.attribute("type");
207         QString paramName = i18n(na.text().toUtf8().data());
208         QString comment;
209         if (!commentElem.isNull())
210             comment = i18n(commentElem.text().toUtf8().data());
211         QWidget * toFillin = new QWidget(m_baseWidget);
212         QString value = pa.attribute("value").isNull() ?
213                         pa.attribute("default") : pa.attribute("value");
214
215         /** Currently supported parameter types are:
216             * constant (=double): a slider with an integer value (use the "factor" attribute to divide the value so that you can get a double
217             * list: a combobox containing a list of values to choose
218             * bool: a checkbox
219             * complex: designed for keyframe parameters, but old and not finished, do not use
220             * geometry: a rectangle that can be moved & resized, with possible keyframes, used in composite transition
221             * keyframe: a list widget with a list of entries (position and value)
222             * color: a color chooser button
223             * position: a slider representing the position of a frame in the current clip
224             * curve: a single curve representing multiple points
225             * wipe: a widget designed for the wipe transition, allowing to choose a position (left, right, top,...)
226         */
227
228         if (type == "double" || type == "constant") {
229             int min;
230             int max;
231             if (pa.attribute("min").startsWith('%'))
232                 min = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("min"));
233             else
234                 min = pa.attribute("min").toInt();
235             if (pa.attribute("max").startsWith('%'))
236                 max = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("max"));
237             else
238                 max = pa.attribute("max").toInt();
239
240             DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, (int)(value.toDouble() + 0.5), min, max,
241                     pa.attribute("default").toInt(), comment, pa.attribute("suffix"), this);
242             m_vbox->addWidget(doubleparam);
243             m_valueItems[paramName] = doubleparam;
244             connect(doubleparam, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
245             connect(this, SIGNAL(showComments()), doubleparam, SLOT(slotShowComment()));
246         } else if (type == "list") {
247             Listval *lsval = new Listval;
248             lsval->setupUi(toFillin);
249             QStringList listitems = pa.attribute("paramlist").split(',');
250             QDomElement list = pa.firstChildElement("paramlistdisplay");
251             QStringList listitemsdisplay;
252             if (!list.isNull()) listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
253             else listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
254             if (listitemsdisplay.count() != listitems.count())
255                 listitemsdisplay = listitems;
256             lsval->list->setIconSize(QSize(30, 30));
257             for (int i = 0; i < listitems.count(); i++) {
258                 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
259                 QString entry = listitems.at(i);
260                 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
261                     if (!EffectStackEdit::iconCache.contains(entry)) {
262                         QImage pix(entry);
263                         EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
264                     }
265                     lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
266                 }
267             }
268             if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
269             lsval->name->setText(paramName);
270             m_valueItems[paramName] = lsval;
271             connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
272             m_uiItems.append(lsval);
273         } else if (type == "bool") {
274             Boolval *bval = new Boolval;
275             bval->setupUi(toFillin);
276             bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
277             bval->name->setText(paramName);
278             m_valueItems[paramName] = bval;
279             connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
280             m_uiItems.append(bval);
281         } else if (type == "complex") {
282             ComplexParameter *pl = new ComplexParameter;
283             pl->setupParam(d, pa.attribute("name"), 0, 100);
284             m_vbox->addWidget(pl);
285             m_valueItems[paramName+"complex"] = pl;
286             connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
287         } else if (type == "geometry") {
288             if (KdenliveSettings::on_monitor_effects()) {
289                 GeometryWidget *geometry = new GeometryWidget(m_monitor, m_timecode, pos, isEffect, this);
290                 geometry->slotShowScene(!disable);
291                 // connect this before setupParam to make sure the monitor scene shows up at startup
292                 connect(geometry, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
293                 connect(geometry, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
294                 if (minFrame == maxFrame)
295                     geometry->setupParam(pa, m_in, m_out);
296                 else
297                     geometry->setupParam(pa, minFrame, maxFrame);
298                 m_vbox->addWidget(geometry);
299                 m_valueItems[paramName+"geometry"] = geometry;
300                 connect(geometry, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
301                 connect(this, SIGNAL(syncEffectsPos(int)), geometry, SLOT(slotSyncPosition(int)));
302                 connect(this, SIGNAL(effectStateChanged(bool)), geometry, SLOT(slotShowScene(bool)));
303             } else {
304                 Geometryval *geo = new Geometryval(m_profile, m_timecode, m_frameSize, pos);
305                 if (minFrame == maxFrame)
306                     geo->setupParam(pa, m_in, m_out);
307                 else
308                     geo->setupParam(pa, minFrame, maxFrame);
309                 m_vbox->addWidget(geo);
310                 m_valueItems[paramName+"geometry"] = geo;
311                 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
312                 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
313                 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
314             }
315         } else if (type == "keyframe" || type == "simplekeyframe") {
316             // keyframe editor widget
317             if (m_keyframeEditor == NULL) {
318                 KeyframeEdit *geo;
319                 if (pa.attribute("widget") == "corners") {
320                     // we want a corners-keyframe-widget
321                     CornersWidget *corners = new CornersWidget(m_monitor, pa, m_in, m_in + m_out, m_timecode, e.attribute("active_keyframe", "-1").toInt(), this);
322                     corners->slotShowScene(!disable);
323                     connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
324                     connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
325                     geo = static_cast<KeyframeEdit *>(corners);
326                 } else {
327                     geo = new KeyframeEdit(pa, m_in, m_in + m_out, m_timecode, e.attribute("active_keyframe", "-1").toInt());
328                 }
329                 m_vbox->addWidget(geo);
330                 m_valueItems[paramName+"keyframe"] = geo;
331                 m_keyframeEditor = geo;
332                 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
333                 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
334                 connect(this, SIGNAL(showComments()), geo, SIGNAL(showComments()));
335             } else {
336                 // we already have a keyframe editor, so just add another column for the new param
337                 m_keyframeEditor->addParameter(pa);
338             }
339         } else if (type == "color") {
340             if (value.startsWith('#'))
341                 value = value.replace('#', "0x");
342             bool ok;
343             ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, QColor(value.toUInt(&ok, 16)), this);
344             m_vbox->addWidget(choosecolor);
345             m_valueItems[paramName] = choosecolor;
346             connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
347             connect(choosecolor, SIGNAL(modified()) , this, SLOT(collectAllParameters()));
348         } else if (type == "position") {
349             int pos = value.toInt();
350             if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
351                 pos = pos - m_in;
352             } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
353                 // fadeout position starts from clip end
354                 pos = m_out - pos;
355             }
356             PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_timecode);
357             m_vbox->addWidget(posedit);
358             m_valueItems[paramName+"position"] = posedit;
359             connect(posedit, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
360         } else if (type == "curve") {
361             KisCurveWidget *curve = new KisCurveWidget(this);
362             curve->setMaxPoints(pa.attribute("max").toInt());
363             QList<QPointF> points;
364             int number = EffectsList::parameter(e, pa.attribute("number")).toInt();
365             QString inName = pa.attribute("inpoints");
366             QString outName = pa.attribute("outpoints");
367             int start = pa.attribute("min").toInt();
368             for (int j = start; j <= number; j++) {
369                 QString in = inName;
370                 in.replace("%i", QString::number(j));
371                 QString out = outName;
372                 out.replace("%i", QString::number(j));
373                 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
374             }
375             if (!points.isEmpty())
376                 curve->setCurve(KisCubicCurve(points));
377             QSpinBox *spinin = new QSpinBox();
378             spinin->setRange(0, 1000);
379             QSpinBox *spinout = new QSpinBox();
380             spinout->setRange(0, 1000);
381             curve->setupInOutControls(spinin, spinout, 0, 1000);
382             m_vbox->addWidget(curve);
383             m_vbox->addWidget(spinin);
384             m_vbox->addWidget(spinout);
385
386             connect(curve, SIGNAL(modified()), this, SLOT(collectAllParameters()));
387             m_valueItems[paramName] = curve;
388
389             QString depends = pa.attribute("depends");
390             if (!depends.isEmpty())
391                 meetDependency(paramName, type, EffectsList::parameter(e, depends));
392         } else if (type == "bezier_spline") {
393             BezierSplineWidget *widget = new BezierSplineWidget(value, this);
394             stretch = false;
395             m_vbox->addWidget(widget);
396             m_valueItems[paramName] = widget;
397             connect(widget, SIGNAL(modified()), this, SLOT(collectAllParameters()));
398             QString depends = pa.attribute("depends");
399             if (!depends.isEmpty())
400                 meetDependency(paramName, type, EffectsList::parameter(e, depends));
401         } else if (type == "wipe") {
402             Wipeval *wpval = new Wipeval;
403             wpval->setupUi(toFillin);
404             wipeInfo w = getWipeInfo(value);
405             switch (w.start) {
406             case UP:
407                 wpval->start_up->setChecked(true);
408                 break;
409             case DOWN:
410                 wpval->start_down->setChecked(true);
411                 break;
412             case RIGHT:
413                 wpval->start_right->setChecked(true);
414                 break;
415             case LEFT:
416                 wpval->start_left->setChecked(true);
417                 break;
418             default:
419                 wpval->start_center->setChecked(true);
420                 break;
421             }
422             switch (w.end) {
423             case UP:
424                 wpval->end_up->setChecked(true);
425                 break;
426             case DOWN:
427                 wpval->end_down->setChecked(true);
428                 break;
429             case RIGHT:
430                 wpval->end_right->setChecked(true);
431                 break;
432             case LEFT:
433                 wpval->end_left->setChecked(true);
434                 break;
435             default:
436                 wpval->end_center->setChecked(true);
437                 break;
438             }
439             wpval->start_transp->setValue(w.startTransparency);
440             wpval->end_transp->setValue(w.endTransparency);
441             m_valueItems[paramName] = wpval;
442             connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
443             connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
444             connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
445             connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
446             connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
447             connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
448             connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
449             connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
450             connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
451             connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
452             connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
453             connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
454             //wpval->title->setTitle(na.toElement().text());
455             m_uiItems.append(wpval);
456         } else if (type == "url") {
457             Urlval *cval = new Urlval;
458             cval->setupUi(toFillin);
459             cval->label->setText(paramName);
460             cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
461             m_valueItems[paramName] = cval;
462             cval->urlwidget->setUrl(KUrl(value));
463             connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(collectAllParameters()));
464             connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(collectAllParameters()));
465             m_uiItems.append(cval);
466         } else {
467             delete toFillin;
468             toFillin = NULL;
469         }
470
471         if (toFillin)
472             m_vbox->addWidget(toFillin);
473     }
474
475     if (stretch)
476         m_vbox->addStretch();
477
478     if (m_keyframeEditor)
479         m_keyframeEditor->checkVisibleParam();
480 }
481
482 wipeInfo EffectStackEdit::getWipeInfo(QString value)
483 {
484     wipeInfo info;
485     QString start = value.section(';', 0, 0);
486     QString end = value.section(';', 1, 1).section('=', 1, 1);
487
488     if (start.startsWith("-100%,0"))
489         info.start = LEFT;
490     else if (start.startsWith("100%,0"))
491         info.start = RIGHT;
492     else if (start.startsWith("0%,100%"))
493         info.start = DOWN;
494     else if (start.startsWith("0%,-100%"))
495         info.start = UP;
496     else
497         info.start = CENTER;
498
499     if (start.count(':') == 2)
500         info.startTransparency = start.section(':', -1).toInt();
501     else
502         info.startTransparency = 100;
503
504     if (end.startsWith("-100%,0"))
505         info.end = LEFT;
506     else if (end.startsWith("100%,0"))
507         info.end = RIGHT;
508     else if (end.startsWith("0%,100%"))
509         info.end = DOWN;
510     else if (end.startsWith("0%,-100%"))
511         info.end = UP;
512     else
513         info.end = CENTER;
514
515     if (end.count(':') == 2)
516         info.endTransparency = end.section(':', -1).toInt();
517     else
518         info.endTransparency = 100;
519
520     return info;
521 }
522
523 QString EffectStackEdit::getWipeString(wipeInfo info)
524 {
525
526     QString start;
527     QString end;
528     switch (info.start) {
529     case LEFT:
530         start = "-100%,0%:100%x100%";
531         break;
532     case RIGHT:
533         start = "100%,0%:100%x100%";
534         break;
535     case DOWN:
536         start = "0%,100%:100%x100%";
537         break;
538     case UP:
539         start = "0%,-100%:100%x100%";
540         break;
541     default:
542         start = "0%,0%:100%x100%";
543         break;
544     }
545     start.append(':' + QString::number(info.startTransparency));
546
547     switch (info.end) {
548     case LEFT:
549         end = "-100%,0%:100%x100%";
550         break;
551     case RIGHT:
552         end = "100%,0%:100%x100%";
553         break;
554     case DOWN:
555         end = "0%,100%:100%x100%";
556         break;
557     case UP:
558         end = "0%,-100%:100%x100%";
559         break;
560     default:
561         end = "0%,0%:100%x100%";
562         break;
563     }
564     end.append(':' + QString::number(info.endTransparency));
565     return QString(start + ";-1=" + end);
566 }
567
568 void EffectStackEdit::collectAllParameters()
569 {
570     if (m_valueItems.isEmpty() || m_params.isNull()) return;
571     const QDomElement oldparam = m_params.cloneNode().toElement();
572     QDomElement newparam = oldparam.cloneNode().toElement();
573     QDomNodeList namenode = newparam.elementsByTagName("parameter");
574
575     for (int i = 0; i < namenode.count() ; i++) {
576         QDomNode pa = namenode.item(i);
577         QDomNode na = pa.firstChildElement("name");
578         QString type = pa.attributes().namedItem("type").nodeValue();
579         QString paramName = i18n(na.toElement().text().toUtf8().data());
580         if (type == "complex")
581             paramName.append("complex");
582         else if (type == "position")
583             paramName.append("position");
584         else if (type == "geometry")
585             paramName.append("geometry");
586         else if (type == "keyframe")
587             paramName.append("keyframe");
588         if (type != "simplekeyframe" && !m_valueItems.contains(paramName)) {
589             kDebug() << "// Param: " << paramName << " NOT FOUND";
590             continue;
591         }
592
593         QString setValue;
594         if (type == "double" || type == "constant") {
595             DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
596             setValue = QString::number(doubleparam->getValue());
597         } else if (type == "list") {
598             KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
599             setValue = box->itemData(box->currentIndex()).toString();
600         } else if (type == "bool") {
601             QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
602             setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
603         } else if (type == "color") {
604             ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
605             setValue = choosecolor->getColor().name();
606         } else if (type == "complex") {
607             ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
608             namenode.item(i) = complex->getParamDesc();
609         } else if (type == "geometry") {
610             if (KdenliveSettings::on_monitor_effects()) {
611                 GeometryWidget *geometry = ((GeometryWidget*)m_valueItems.value(paramName));
612                 namenode.item(i).toElement().setAttribute("value", geometry->getValue());
613             } else {
614                 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
615                 namenode.item(i).toElement().setAttribute("value", geom->getValue());
616             }
617         } else if (type == "position") {
618             PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
619             int pos = pedit->getPosition();
620             setValue = QString::number(pos);
621             if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_black") {
622                 // Make sure duration is not longer than clip
623                 /*if (pos > m_out) {
624                     pos = m_out;
625                     pedit->setPosition(pos);
626                 }*/
627                 EffectsList::setParameter(newparam, "in", QString::number(m_in));
628                 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
629                 setValue.clear();
630             } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
631                 // Make sure duration is not longer than clip
632                 /*if (pos > m_out) {
633                     pos = m_out;
634                     pedit->setPosition(pos);
635                 }*/
636                 EffectsList::setParameter(newparam, "in", QString::number(m_out - pos));
637                 EffectsList::setParameter(newparam, "out", QString::number(m_out));
638                 setValue.clear();
639             }
640         } else if (type == "curve") {
641             KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
642             QList<QPointF> points = curve->curve().points();
643             QString number = pa.attributes().namedItem("number").nodeValue();
644             QString inName = pa.attributes().namedItem("inpoints").nodeValue();
645             QString outName = pa.attributes().namedItem("outpoints").nodeValue();
646             int off = pa.attributes().namedItem("min").nodeValue().toInt();
647             int end = pa.attributes().namedItem("max").nodeValue().toInt();
648             EffectsList::setParameter(newparam, number, QString::number(points.count()));
649             for (int j = 0; (j < points.count() && j + off <= end); j++) {
650                 QString in = inName;
651                 in.replace("%i", QString::number(j + off));
652                 QString out = outName;
653                 out.replace("%i", QString::number(j + off));
654                 EffectsList::setParameter(newparam, in, QString::number(points.at(j).x()));
655                 EffectsList::setParameter(newparam, out, QString::number(points.at(j).y()));
656             }
657             QString depends = pa.attributes().namedItem("depends").nodeValue();
658             if (!depends.isEmpty())
659                 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
660         } else if (type == "bezier_spline") {
661             BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
662             setValue = widget->spline();
663             QString depends = pa.attributes().namedItem("depends").nodeValue();
664             if (!depends.isEmpty())
665                 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
666         } else if (type == "wipe") {
667             Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
668             wipeInfo info;
669             if (wp->start_left->isChecked())
670                 info.start = LEFT;
671             else if (wp->start_right->isChecked())
672                 info.start = RIGHT;
673             else if (wp->start_up->isChecked())
674                 info.start = UP;
675             else if (wp->start_down->isChecked())
676                 info.start = DOWN;
677             else if (wp->start_center->isChecked())
678                 info.start = CENTER;
679             else
680                 info.start = LEFT;
681             info.startTransparency = wp->start_transp->value();
682
683             if (wp->end_left->isChecked())
684                 info.end = LEFT;
685             else if (wp->end_right->isChecked())
686                 info.end = RIGHT;
687             else if (wp->end_up->isChecked())
688                 info.end = UP;
689             else if (wp->end_down->isChecked())
690                 info.end = DOWN;
691             else if (wp->end_center->isChecked())
692                 info.end = CENTER;
693             else
694                 info.end = RIGHT;
695             info.endTransparency = wp->end_transp->value();
696
697             setValue = getWipeString(info);
698         } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
699             QDomElement elem = pa.toElement();
700             QString realName = i18n(na.toElement().text().toUtf8().data());
701             QString val = m_keyframeEditor->getValue(realName);
702             elem.setAttribute("keyframes", val);
703
704             if (m_keyframeEditor->isVisibleParam(realName))
705                 elem.setAttribute("intimeline", "1");
706             else if (elem.hasAttribute("intimeline"))
707                 elem.removeAttribute("intimeline");
708         } else if (type == "url") {
709             KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
710             setValue = req->url().path();
711         }
712
713         if (!setValue.isNull())
714             pa.attributes().namedItem("value").setNodeValue(setValue);
715
716     }
717     emit parameterChanged(oldparam, newparam);
718 }
719
720 void EffectStackEdit::clearAllItems()
721 {
722     blockSignals(true);
723     m_valueItems.clear();
724     m_uiItems.clear();
725     /*while (!m_items.isEmpty()) {
726         QWidget *die = m_items.takeFirst();
727         die->disconnect();
728         delete die;
729     }*/
730     //qDeleteAll(m_uiItems);
731     QLayoutItem *child;
732     while ((child = m_vbox->takeAt(0)) != 0) {
733         QWidget *wid = child->widget();
734         delete child;
735         if (wid) delete wid;
736     }
737     m_keyframeEditor = NULL;
738     blockSignals(false);
739 }
740
741 void EffectStackEdit::slotSyncEffectsPos(int pos)
742 {
743     emit syncEffectsPos(pos);
744 }