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