]> git.sesse.net Git - kdenlive/blob - src/effectstackedit.cpp
Merge branch 'master' into buildsystem
[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 USE_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     int minFrame = d.attribute("start").toInt();
236     int maxFrame = d.attribute("end").toInt();
237     // In transitions, maxFrame is in fact one frame after the end of transition
238     if (maxFrame > 0) maxFrame --;
239
240     bool disable = d.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
241     setEnabled(!disable);
242
243     bool stretch = true;
244
245
246     for (int i = 0; i < namenode.count() ; i++) {
247         QDomElement pa = namenode.item(i).toElement();
248         QDomElement na = pa.firstChildElement("name");
249         QDomElement commentElem = pa.firstChildElement("comment");
250         QString type = pa.attribute("type");
251         QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
252         QString comment;
253         if (!commentElem.isNull())
254             comment = i18n(commentElem.text().toUtf8().data());
255         QWidget * toFillin = new QWidget(m_baseWidget);
256         QString value = pa.attribute("value").isNull() ?
257                         pa.attribute("default") : pa.attribute("value");
258
259
260         /** See effects/README for info on the different types */
261
262         if (type == "double" || type == "constant") {
263             double min;
264             double max;
265             if (pa.attribute("min").contains('%'))
266                 min = ProfilesDialog::getStringEval(m_profile, pa.attribute("min"), m_frameSize);
267             else
268                 min = pa.attribute("min").toDouble();
269             if (pa.attribute("max").contains('%'))
270                 max = ProfilesDialog::getStringEval(m_profile, pa.attribute("max"), m_frameSize);
271             else
272                 max = pa.attribute("max").toDouble();
273
274             DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, value.toDouble(), min, max,
275                     pa.attribute("default").toDouble(), comment, -1, pa.attribute("suffix"), pa.attribute("decimals").toInt(), this);
276             m_vbox->addWidget(doubleparam);
277             m_valueItems[paramName] = doubleparam;
278             connect(doubleparam, SIGNAL(valueChanged(double)), this, SLOT(collectAllParameters()));
279             connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
280         } else if (type == "list") {
281             Listval *lsval = new Listval;
282             lsval->setupUi(toFillin);
283             QStringList listitems = pa.attribute("paramlist").split(';');
284             if (listitems.count() == 1) {
285                 // probably custom effect created before change to ';' as separator
286                 listitems = pa.attribute("paramlist").split(',');
287             }
288             QDomElement list = pa.firstChildElement("paramlistdisplay");
289             QStringList listitemsdisplay;
290             if (!list.isNull()) {
291                 listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
292             } else {
293                 listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
294             }
295             if (listitemsdisplay.count() != listitems.count())
296                 listitemsdisplay = listitems;
297             lsval->list->setIconSize(QSize(30, 30));
298             for (int i = 0; i < listitems.count(); i++) {
299                 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
300                 QString entry = listitems.at(i);
301                 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
302                     if (!EffectStackEdit::iconCache.contains(entry)) {
303                         QImage pix(entry);
304                         EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
305                     }
306                     lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
307                 }
308             }
309             if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
310             lsval->name->setText(paramName);
311             lsval->labelComment->setText(comment);
312             lsval->widgetComment->setHidden(true);
313             m_valueItems[paramName] = lsval;
314             connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
315             if (!comment.isEmpty())
316                 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
317             m_uiItems.append(lsval);
318         } else if (type == "bool") {
319             Boolval *bval = new Boolval;
320             bval->setupUi(toFillin);
321             bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
322             bval->name->setText(paramName);
323             bval->labelComment->setText(comment);
324             bval->widgetComment->setHidden(true);
325             m_valueItems[paramName] = bval;
326             connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
327             if (!comment.isEmpty())
328                 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
329             m_uiItems.append(bval);
330         } else if (type == "complex") {
331             ComplexParameter *pl = new ComplexParameter;
332             pl->setupParam(d, pa.attribute("name"), 0, 100);
333             m_vbox->addWidget(pl);
334             m_valueItems[paramName+"complex"] = pl;
335             connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
336         } else if (type == "geometry") {
337             if (KdenliveSettings::on_monitor_effects()) {
338                 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);
339                 m_geometryWidget->setFrameSize(m_frameSize);
340                 m_geometryWidget->slotShowScene(!disable);
341                 // connect this before setupParam to make sure the monitor scene shows up at startup
342                 connect(m_geometryWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
343                 connect(m_geometryWidget, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
344                 if (minFrame == maxFrame)
345                     m_geometryWidget->setupParam(pa, m_in, m_out);
346                 else
347                     m_geometryWidget->setupParam(pa, minFrame, maxFrame);
348                 m_vbox->addWidget(m_geometryWidget);
349                 m_valueItems[paramName+"geometry"] = m_geometryWidget;
350                 connect(m_geometryWidget, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
351                 connect(this, SIGNAL(syncEffectsPos(int)), m_geometryWidget, SLOT(slotSyncPosition(int)));
352                 connect(this, SIGNAL(effectStateChanged(bool)), m_geometryWidget, SLOT(slotShowScene(bool)));
353             } else {
354                 Geometryval *geo = new Geometryval(m_profile, m_timecode, m_frameSize, isEffect ? 0 : qMax(0, (int)info.startPos.frames(KdenliveSettings::project_fps())));
355                 if (minFrame == maxFrame)
356                     geo->setupParam(pa, m_in, m_out);
357                 else
358                     geo->setupParam(pa, minFrame, maxFrame);
359                 m_vbox->addWidget(geo);
360                 m_valueItems[paramName+"geometry"] = geo;
361                 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
362                 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
363                 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
364             }
365         } else if (type == "addedgeometry") {
366             // this is a parameter that should be linked to the geometry widget, for example rotation, shear, ...
367             if (m_geometryWidget) m_geometryWidget->addParameter(pa);
368         } else if (type == "keyframe" || type == "simplekeyframe") {
369             // keyframe editor widget
370             if (m_keyframeEditor == NULL) {
371                 KeyframeEdit *geo;
372                 if (pa.attribute("widget") == "corners") {
373                     // we want a corners-keyframe-widget
374                     CornersWidget *corners = new CornersWidget(m_monitor, pa, m_in, m_out, m_timecode, d.attribute("active_keyframe", "-1").toInt(), this);
375                     corners->slotShowScene(!disable);
376                     connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
377                     connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
378                     connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
379                     geo = static_cast<KeyframeEdit *>(corners);
380                 } else {
381                     geo = new KeyframeEdit(pa, m_in, m_out, m_timecode, d.attribute("active_keyframe", "-1").toInt());
382                 }
383                 m_vbox->addWidget(geo);
384                 m_valueItems[paramName+"keyframe"] = geo;
385                 m_keyframeEditor = geo;
386                 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
387                 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
388                 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
389             } else {
390                 // we already have a keyframe editor, so just add another column for the new param
391                 m_keyframeEditor->addParameter(pa);
392             }
393         } else if (type == "color") {
394             if (value.startsWith('#'))
395                 value = value.replace('#', "0x");
396             bool ok;
397             ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, QColor(value.toUInt(&ok, 16)), this);
398             m_vbox->addWidget(choosecolor);
399             m_valueItems[paramName] = choosecolor;
400             connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
401             connect(choosecolor, SIGNAL(modified()) , this, SLOT(collectAllParameters()));
402         } else if (type == "position") {
403             int pos = value.toInt();
404             if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
405                 pos = pos - m_in;
406             } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
407                 // fadeout position starts from clip end
408                 pos = m_out - pos;
409             }
410             PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_timecode);
411             m_vbox->addWidget(posedit);
412             m_valueItems[paramName+"position"] = posedit;
413             connect(posedit, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
414         } else if (type == "curve") {
415             KisCurveWidget *curve = new KisCurveWidget(this);
416             curve->setMaxPoints(pa.attribute("max").toInt());
417             QList<QPointF> points;
418             int number;
419             if (d.attribute("version").toDouble() > 0.2) {
420                 number = EffectsList::parameter(d, pa.attribute("number")).toDouble() * 10;
421             } else {
422                 number = EffectsList::parameter(d, pa.attribute("number")).toInt();
423             }
424             QString inName = pa.attribute("inpoints");
425             QString outName = pa.attribute("outpoints");
426             int start = pa.attribute("min").toInt();
427             for (int j = start; j <= number; j++) {
428                 QString in = inName;
429                 in.replace("%i", QString::number(j));
430                 QString out = outName;
431                 out.replace("%i", QString::number(j));
432                 points << QPointF(EffectsList::parameter(d, in).toDouble(), EffectsList::parameter(d, out).toDouble());
433             }
434             if (!points.isEmpty())
435                 curve->setCurve(KisCubicCurve(points));
436             QSpinBox *spinin = new QSpinBox();
437             spinin->setRange(0, 1000);
438             QSpinBox *spinout = new QSpinBox();
439             spinout->setRange(0, 1000);
440             curve->setupInOutControls(spinin, spinout, 0, 1000);
441             m_vbox->addWidget(curve);
442             m_vbox->addWidget(spinin);
443             m_vbox->addWidget(spinout);
444
445             connect(curve, SIGNAL(modified()), this, SLOT(collectAllParameters()));
446             m_valueItems[paramName] = curve;
447
448             QString depends = pa.attribute("depends");
449             if (!depends.isEmpty())
450                 meetDependency(paramName, type, EffectsList::parameter(d, depends));
451         } else if (type == "bezier_spline") {
452             BezierSplineWidget *widget = new BezierSplineWidget(value, this);
453             stretch = false;
454             m_vbox->addWidget(widget);
455             m_valueItems[paramName] = widget;
456             connect(widget, SIGNAL(modified()), this, SLOT(collectAllParameters()));
457             QString depends = pa.attribute("depends");
458             if (!depends.isEmpty())
459                 meetDependency(paramName, type, EffectsList::parameter(d, depends));
460 #ifdef USE_QJSON
461         } else if (type == "roto-spline") {
462             RotoWidget *roto = new RotoWidget(value, m_monitor, info, m_timecode, this);
463             roto->slotShowScene(!disable);
464             connect(roto, SIGNAL(valueChanged()), this, SLOT(collectAllParameters()));
465             connect(roto, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
466             connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
467             connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
468             connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
469             m_vbox->addWidget(roto);
470             m_valueItems[paramName] = roto;
471 #endif
472         } else if (type == "wipe") {
473             Wipeval *wpval = new Wipeval;
474             wpval->setupUi(toFillin);
475             wipeInfo w = getWipeInfo(value);
476             switch (w.start) {
477             case UP:
478                 wpval->start_up->setChecked(true);
479                 break;
480             case DOWN:
481                 wpval->start_down->setChecked(true);
482                 break;
483             case RIGHT:
484                 wpval->start_right->setChecked(true);
485                 break;
486             case LEFT:
487                 wpval->start_left->setChecked(true);
488                 break;
489             default:
490                 wpval->start_center->setChecked(true);
491                 break;
492             }
493             switch (w.end) {
494             case UP:
495                 wpval->end_up->setChecked(true);
496                 break;
497             case DOWN:
498                 wpval->end_down->setChecked(true);
499                 break;
500             case RIGHT:
501                 wpval->end_right->setChecked(true);
502                 break;
503             case LEFT:
504                 wpval->end_left->setChecked(true);
505                 break;
506             default:
507                 wpval->end_center->setChecked(true);
508                 break;
509             }
510             wpval->start_transp->setValue(w.startTransparency);
511             wpval->end_transp->setValue(w.endTransparency);
512             m_valueItems[paramName] = wpval;
513             connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
514             connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
515             connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
516             connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
517             connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
518             connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
519             connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
520             connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
521             connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
522             connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
523             connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
524             connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
525             //wpval->title->setTitle(na.toElement().text());
526             m_uiItems.append(wpval);
527         } else if (type == "url") {
528             Urlval *cval = new Urlval;
529             cval->setupUi(toFillin);
530             cval->label->setText(paramName);
531             cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
532             m_valueItems[paramName] = cval;
533             cval->urlwidget->setUrl(KUrl(value));
534             connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(collectAllParameters()));
535             connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(collectAllParameters()));
536             m_uiItems.append(cval);
537         } else {
538             delete toFillin;
539             toFillin = NULL;
540         }
541
542         if (toFillin)
543             m_vbox->addWidget(toFillin);
544     }
545
546     if (stretch)
547         m_vbox->addStretch();
548
549     if (m_keyframeEditor)
550         m_keyframeEditor->checkVisibleParam();
551     
552     // Make sure all doubleparam spinboxes have the same width, looks much better
553     QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
554     int minSize = 0;
555     for (int i = 0; i < allWidgets.count(); i++) {
556         if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
557     }
558     for (int i = 0; i < allWidgets.count(); i++) {
559         allWidgets.at(i)->setSpinSize(minSize);
560     }
561 }
562
563 wipeInfo EffectStackEdit::getWipeInfo(QString value)
564 {
565     wipeInfo info;
566     // Convert old geometry values that used a comma as separator
567     if (value.contains(',')) value.replace(',','/');
568     QString start = value.section(';', 0, 0);
569     QString end = value.section(';', 1, 1).section('=', 1, 1);
570     if (start.startsWith("-100%/0"))
571         info.start = LEFT;
572     else if (start.startsWith("100%/0"))
573         info.start = RIGHT;
574     else if (start.startsWith("0%/100%"))
575         info.start = DOWN;
576     else if (start.startsWith("0%/-100%"))
577         info.start = UP;
578     else
579         info.start = CENTER;
580
581     if (start.count(':') == 2)
582         info.startTransparency = start.section(':', -1).toInt();
583     else
584         info.startTransparency = 100;
585
586     if (end.startsWith("-100%/0"))
587         info.end = LEFT;
588     else if (end.startsWith("100%/0"))
589         info.end = RIGHT;
590     else if (end.startsWith("0%/100%"))
591         info.end = DOWN;
592     else if (end.startsWith("0%/-100%"))
593         info.end = UP;
594     else
595         info.end = CENTER;
596
597     if (end.count(':') == 2)
598         info.endTransparency = end.section(':', -1).toInt();
599     else
600         info.endTransparency = 100;
601
602     return info;
603 }
604
605 QString EffectStackEdit::getWipeString(wipeInfo info)
606 {
607
608     QString start;
609     QString end;
610     switch (info.start) {
611     case LEFT:
612         start = "-100%/0%:100%x100%";
613         break;
614     case RIGHT:
615         start = "100%/0%:100%x100%";
616         break;
617     case DOWN:
618         start = "0%/100%:100%x100%";
619         break;
620     case UP:
621         start = "0%/-100%:100%x100%";
622         break;
623     default:
624         start = "0%/0%:100%x100%";
625         break;
626     }
627     start.append(':' + QString::number(info.startTransparency));
628
629     switch (info.end) {
630     case LEFT:
631         end = "-100%/0%:100%x100%";
632         break;
633     case RIGHT:
634         end = "100%/0%:100%x100%";
635         break;
636     case DOWN:
637         end = "0%/100%:100%x100%";
638         break;
639     case UP:
640         end = "0%/-100%:100%x100%";
641         break;
642     default:
643         end = "0%/0%:100%x100%";
644         break;
645     }
646     end.append(':' + QString::number(info.endTransparency));
647     return QString(start + ";-1=" + end);
648 }
649
650 void EffectStackEdit::collectAllParameters()
651 {
652     if (m_valueItems.isEmpty() || m_params.isNull()) return;
653     const QDomElement oldparam = m_params.cloneNode().toElement();
654     QDomElement newparam = oldparam.cloneNode().toElement();
655     QDomNodeList namenode = newparam.elementsByTagName("parameter");
656     QLocale locale;
657
658     for (int i = 0; i < namenode.count() ; i++) {
659         QDomNode pa = namenode.item(i);
660         QDomElement na = pa.firstChildElement("name");
661         QString type = pa.attributes().namedItem("type").nodeValue();
662         QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
663         if (type == "complex")
664             paramName.append("complex");
665         else if (type == "position")
666             paramName.append("position");
667         else if (type == "geometry")
668             paramName.append("geometry");
669         else if (type == "keyframe")
670             paramName.append("keyframe");
671         if (type != "simplekeyframe" && type != "fixed" && type != "addedgeometry" && !m_valueItems.contains(paramName)) {
672             kDebug() << "// Param: " << paramName << " NOT FOUND";
673             continue;
674         }
675
676         QString setValue;
677         if (type == "double" || type == "constant") {
678             DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
679             setValue = locale.toString(doubleparam->getValue());
680         } else if (type == "list") {
681             KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
682             setValue = box->itemData(box->currentIndex()).toString();
683         } else if (type == "bool") {
684             QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
685             setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
686         } else if (type == "color") {
687             ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
688             setValue = choosecolor->getColor().name();
689         } else if (type == "complex") {
690             ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
691             namenode.item(i) = complex->getParamDesc();
692         } else if (type == "geometry") {
693             if (KdenliveSettings::on_monitor_effects()) {
694                 if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getValue());
695             } else {
696                 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
697                 namenode.item(i).toElement().setAttribute("value", geom->getValue());
698             }
699         } else if (type == "addedgeometry") {
700             namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getExtraValue(namenode.item(i).toElement().attribute("name")));
701         } else if (type == "position") {
702             PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
703             int pos = pedit->getPosition();
704             setValue = QString::number(pos);
705             if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_black") {
706                 // Make sure duration is not longer than clip
707                 /*if (pos > m_out) {
708                     pos = m_out;
709                     pedit->setPosition(pos);
710                 }*/
711                 EffectsList::setParameter(newparam, "in", QString::number(m_in));
712                 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
713                 setValue.clear();
714             } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
715                 // Make sure duration is not longer than clip
716                 /*if (pos > m_out) {
717                     pos = m_out;
718                     pedit->setPosition(pos);
719                 }*/
720                 EffectsList::setParameter(newparam, "in", QString::number(m_out - pos));
721                 EffectsList::setParameter(newparam, "out", QString::number(m_out));
722                 setValue.clear();
723             }
724         } else if (type == "curve") {
725             KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
726             QList<QPointF> points = curve->curve().points();
727             QString number = pa.attributes().namedItem("number").nodeValue();
728             QString inName = pa.attributes().namedItem("inpoints").nodeValue();
729             QString outName = pa.attributes().namedItem("outpoints").nodeValue();
730             int off = pa.attributes().namedItem("min").nodeValue().toInt();
731             int end = pa.attributes().namedItem("max").nodeValue().toInt();
732             if (oldparam.attribute("version").toDouble() > 0.2) {
733                 EffectsList::setParameter(newparam, number, locale.toString(points.count() / 10.));
734             } else {
735                 EffectsList::setParameter(newparam, number, QString::number(points.count()));
736             }
737             for (int j = 0; (j < points.count() && j + off <= end); j++) {
738                 QString in = inName;
739                 in.replace("%i", QString::number(j + off));
740                 QString out = outName;
741                 out.replace("%i", QString::number(j + off));
742                 EffectsList::setParameter(newparam, in, locale.toString(points.at(j).x()));
743                 EffectsList::setParameter(newparam, out, locale.toString(points.at(j).y()));
744             }
745             QString depends = pa.attributes().namedItem("depends").nodeValue();
746             if (!depends.isEmpty())
747                 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
748         } else if (type == "bezier_spline") {
749             BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
750             setValue = widget->spline();
751             QString depends = pa.attributes().namedItem("depends").nodeValue();
752             if (!depends.isEmpty())
753                 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
754 #ifdef USE_QJSON
755         } else if (type == "roto-spline") {
756             RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
757             setValue = widget->getSpline();
758 #endif
759         } else if (type == "wipe") {
760             Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
761             wipeInfo info;
762             if (wp->start_left->isChecked())
763                 info.start = LEFT;
764             else if (wp->start_right->isChecked())
765                 info.start = RIGHT;
766             else if (wp->start_up->isChecked())
767                 info.start = UP;
768             else if (wp->start_down->isChecked())
769                 info.start = DOWN;
770             else if (wp->start_center->isChecked())
771                 info.start = CENTER;
772             else
773                 info.start = LEFT;
774             info.startTransparency = wp->start_transp->value();
775
776             if (wp->end_left->isChecked())
777                 info.end = LEFT;
778             else if (wp->end_right->isChecked())
779                 info.end = RIGHT;
780             else if (wp->end_up->isChecked())
781                 info.end = UP;
782             else if (wp->end_down->isChecked())
783                 info.end = DOWN;
784             else if (wp->end_center->isChecked())
785                 info.end = CENTER;
786             else
787                 info.end = RIGHT;
788             info.endTransparency = wp->end_transp->value();
789
790             setValue = getWipeString(info);
791         } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
792             QDomElement elem = pa.toElement();
793             QString realName = i18n(na.toElement().text().toUtf8().data());
794             QString val = m_keyframeEditor->getValue(realName);
795             elem.setAttribute("keyframes", val);
796
797             if (m_keyframeEditor->isVisibleParam(realName))
798                 elem.setAttribute("intimeline", "1");
799             else if (elem.hasAttribute("intimeline"))
800                 elem.removeAttribute("intimeline");
801         } else if (type == "url") {
802             KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
803             setValue = req->url().path();
804         }
805
806         if (!setValue.isNull())
807             pa.attributes().namedItem("value").setNodeValue(setValue);
808
809     }
810     emit parameterChanged(oldparam, newparam);
811 }
812
813 void EffectStackEdit::clearAllItems()
814 {
815     blockSignals(true);
816     m_valueItems.clear();
817     m_uiItems.clear();
818     /*while (!m_items.isEmpty()) {
819         QWidget *die = m_items.takeFirst();
820         die->disconnect();
821         delete die;
822     }*/
823     //qDeleteAll(m_uiItems);
824     QLayoutItem *child;
825     while ((child = m_vbox->takeAt(0)) != 0) {
826         QWidget *wid = child->widget();
827         delete child;
828         if (wid) delete wid;
829     }
830     m_keyframeEditor = NULL;
831     m_geometryWidget = NULL;
832     blockSignals(false);
833 }
834
835 void EffectStackEdit::slotSyncEffectsPos(int pos)
836 {
837     emit syncEffectsPos(pos);
838 }