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