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