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