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