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