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