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