]> git.sesse.net Git - kdenlive/blob - src/effectstackedit.cpp
Fix effect parameters disabled when they should not be
[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::ScrollBarAlwaysOff);
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         QDomNode na = pa.firstChildElement("name");
126         QString type = pa.attributes().namedItem("type").nodeValue();
127         QString paramName = i18n(na.toElement().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         QDomNode na = pa.firstChildElement("name");
152         QString type = pa.attributes().namedItem("type").nodeValue();
153         QString paramName = i18n(na.toElement().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         }
164         if (type == "position") {
165             PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
166             posi->updateTimecodeFormat();
167             break;
168         }
169     }
170 }
171
172 void EffectStackEdit::meetDependency(const QString& name, QString type, QString value)
173 {
174     if (type == "curve") {
175         KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
176         if (curve) {
177             int color = value.toInt();
178             curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
179         }
180     } else if (type == "bezier_spline") {
181         BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
182         if (widget) {
183             widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10)));
184         }
185     }
186 }
187
188 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
189 {
190     m_profile = profile;
191     m_timecode = t;
192 }
193
194 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
195 {
196     m_params.setAttribute(name, value);
197
198     if (name == "disable") {
199         // if effect is disabled, disable parameters widget
200         bool enabled = value.toInt() == 0 || !KdenliveSettings::disable_effect_parameters();
201         setEnabled(enabled);
202         emit effectStateChanged(enabled);
203     }
204 }
205
206 void EffectStackEdit::transferParamDesc(const QDomElement d, int pos, int in, int out, bool isEffect)
207 {
208     clearAllItems();
209     if (m_keyframeEditor) delete m_keyframeEditor;
210     m_keyframeEditor = NULL;
211     m_params = d;
212     m_in = in;
213     m_out = out;
214     if (m_params.isNull()) {
215 //         kDebug() << "// EMPTY EFFECT STACK";
216         return;
217     }
218
219     QDomNodeList namenode = m_params.elementsByTagName("parameter");
220 #ifdef DEBUG_ESE
221     QFile debugFile("/tmp/namenodes.txt");
222     if (debugFile.open(QFile::WriteOnly | QFile::Truncate)) {
223         QTextStream out(&debugFile);
224         QTextStream out2(stdout);
225         for (int i = 0; i < namenode.size(); i++) {
226             out << i << ": \n";
227             namenode.at(i).save(out, 2);
228             out2 << i << ": \n";
229             namenode.at(i).save(out2, 2);
230         }
231     }
232 #endif
233     QDomElement e = m_params.toElement();
234     const int minFrame = e.attribute("start").toInt();
235     const int maxFrame = e.attribute("end").toInt();
236
237     bool disable = d.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
238     setEnabled(!disable);
239
240     bool stretch = true;
241
242
243     for (int i = 0; i < namenode.count() ; i++) {
244         QDomElement pa = namenode.item(i).toElement();
245         QDomElement na = pa.firstChildElement("name");
246         QDomElement commentElem = pa.firstChildElement("comment");
247         QString type = pa.attribute("type");
248         QString paramName = i18n(na.text().toUtf8().data());
249         QString comment;
250         if (!commentElem.isNull())
251             comment = i18n(commentElem.text().toUtf8().data());
252         QWidget * toFillin = new QWidget(m_baseWidget);
253         QString value = pa.attribute("value").isNull() ?
254                         pa.attribute("default") : pa.attribute("value");
255
256         /** Currently supported parameter types are:
257             * constant (=double): a slider with an integer value (use the "factor" attribute to divide the value so that you can get a double
258             * list: a combobox containing a list of values to choose
259             * bool: a checkbox
260             * complex: designed for keyframe parameters, but old and not finished, do not use
261             * geometry: a rectangle that can be moved & resized, with possible keyframes, used in composite transition
262             * keyframe: a list widget with a list of entries (position and value)
263             * color: a color chooser button
264             * position: a slider representing the position of a frame in the current clip
265             * curve: a single curve representing multiple points
266             * wipe: a widget designed for the wipe transition, allowing to choose a position (left, right, top,...)
267         */
268
269         if (type == "double" || type == "constant") {
270             int min;
271             int max;
272             if (pa.attribute("min").startsWith('%'))
273                 min = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("min"));
274             else
275                 min = pa.attribute("min").toInt();
276             if (pa.attribute("max").startsWith('%'))
277                 max = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("max"));
278             else
279                 max = pa.attribute("max").toInt();
280
281             DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, (int)(value.toDouble() + 0.5), min, max,
282                     pa.attribute("default").toInt(), comment, -1, pa.attribute("suffix"), this);
283             m_vbox->addWidget(doubleparam);
284             m_valueItems[paramName] = doubleparam;
285             connect(doubleparam, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
286             connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
287         } else if (type == "list") {
288             Listval *lsval = new Listval;
289             lsval->setupUi(toFillin);
290             QStringList listitems = pa.attribute("paramlist").split(',');
291             QDomElement list = pa.firstChildElement("paramlistdisplay");
292             QStringList listitemsdisplay;
293             if (!list.isNull()) listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
294             else listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
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, pos, 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, pos);
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_in + m_out, m_timecode, e.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_in + m_out, m_timecode, e.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 = EffectsList::parameter(e, pa.attribute("number")).toInt();
419             QString inName = pa.attribute("inpoints");
420             QString outName = pa.attribute("outpoints");
421             int start = pa.attribute("min").toInt();
422             for (int j = start; j <= number; j++) {
423                 QString in = inName;
424                 in.replace("%i", QString::number(j));
425                 QString out = outName;
426                 out.replace("%i", QString::number(j));
427                 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
428             }
429             if (!points.isEmpty())
430                 curve->setCurve(KisCubicCurve(points));
431             QSpinBox *spinin = new QSpinBox();
432             spinin->setRange(0, 1000);
433             QSpinBox *spinout = new QSpinBox();
434             spinout->setRange(0, 1000);
435             curve->setupInOutControls(spinin, spinout, 0, 1000);
436             m_vbox->addWidget(curve);
437             m_vbox->addWidget(spinin);
438             m_vbox->addWidget(spinout);
439
440             connect(curve, SIGNAL(modified()), this, SLOT(collectAllParameters()));
441             m_valueItems[paramName] = curve;
442
443             QString depends = pa.attribute("depends");
444             if (!depends.isEmpty())
445                 meetDependency(paramName, type, EffectsList::parameter(e, depends));
446         } else if (type == "bezier_spline") {
447             BezierSplineWidget *widget = new BezierSplineWidget(value, this);
448             stretch = false;
449             m_vbox->addWidget(widget);
450             m_valueItems[paramName] = widget;
451             connect(widget, SIGNAL(modified()), this, SLOT(collectAllParameters()));
452             QString depends = pa.attribute("depends");
453             if (!depends.isEmpty())
454                 meetDependency(paramName, type, EffectsList::parameter(e, depends));
455 #ifdef QJSON
456         } else if (type == "roto-spline") {
457             RotoWidget *roto = new RotoWidget(value, m_monitor, m_in, m_out, m_timecode, this);
458             roto->slotShowScene(!disable);
459             connect(roto, SIGNAL(valueChanged()), this, SLOT(collectAllParameters()));
460             connect(roto, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
461             connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
462             connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
463             connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
464             m_vbox->addWidget(roto);
465             m_valueItems[paramName] = roto;
466 #endif
467         } else if (type == "wipe") {
468             Wipeval *wpval = new Wipeval;
469             wpval->setupUi(toFillin);
470             wipeInfo w = getWipeInfo(value);
471             switch (w.start) {
472             case UP:
473                 wpval->start_up->setChecked(true);
474                 break;
475             case DOWN:
476                 wpval->start_down->setChecked(true);
477                 break;
478             case RIGHT:
479                 wpval->start_right->setChecked(true);
480                 break;
481             case LEFT:
482                 wpval->start_left->setChecked(true);
483                 break;
484             default:
485                 wpval->start_center->setChecked(true);
486                 break;
487             }
488             switch (w.end) {
489             case UP:
490                 wpval->end_up->setChecked(true);
491                 break;
492             case DOWN:
493                 wpval->end_down->setChecked(true);
494                 break;
495             case RIGHT:
496                 wpval->end_right->setChecked(true);
497                 break;
498             case LEFT:
499                 wpval->end_left->setChecked(true);
500                 break;
501             default:
502                 wpval->end_center->setChecked(true);
503                 break;
504             }
505             wpval->start_transp->setValue(w.startTransparency);
506             wpval->end_transp->setValue(w.endTransparency);
507             m_valueItems[paramName] = wpval;
508             connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
509             connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
510             connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
511             connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
512             connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
513             connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
514             connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
515             connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
516             connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
517             connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
518             connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
519             connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
520             //wpval->title->setTitle(na.toElement().text());
521             m_uiItems.append(wpval);
522         } else if (type == "url") {
523             Urlval *cval = new Urlval;
524             cval->setupUi(toFillin);
525             cval->label->setText(paramName);
526             cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
527             m_valueItems[paramName] = cval;
528             cval->urlwidget->setUrl(KUrl(value));
529             connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(collectAllParameters()));
530             connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(collectAllParameters()));
531             m_uiItems.append(cval);
532         } else {
533             delete toFillin;
534             toFillin = NULL;
535         }
536
537         if (toFillin)
538             m_vbox->addWidget(toFillin);
539     }
540
541     if (stretch)
542         m_vbox->addStretch();
543
544     if (m_keyframeEditor)
545         m_keyframeEditor->checkVisibleParam();
546     
547     // Make sure all doubleparam spinboxes have the same width, looks much better
548     QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
549     int minSize = 0;
550     for (int i = 0; i < allWidgets.count(); i++) {
551         if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
552     }
553     for (int i = 0; i < allWidgets.count(); i++) {
554         allWidgets.at(i)->setSpinSize(minSize);
555     }
556 }
557
558 wipeInfo EffectStackEdit::getWipeInfo(QString value)
559 {
560     wipeInfo info;
561     QString start = value.section(';', 0, 0);
562     QString end = value.section(';', 1, 1).section('=', 1, 1);
563
564     if (start.startsWith("-100%,0"))
565         info.start = LEFT;
566     else if (start.startsWith("100%,0"))
567         info.start = RIGHT;
568     else if (start.startsWith("0%,100%"))
569         info.start = DOWN;
570     else if (start.startsWith("0%,-100%"))
571         info.start = UP;
572     else
573         info.start = CENTER;
574
575     if (start.count(':') == 2)
576         info.startTransparency = start.section(':', -1).toInt();
577     else
578         info.startTransparency = 100;
579
580     if (end.startsWith("-100%,0"))
581         info.end = LEFT;
582     else if (end.startsWith("100%,0"))
583         info.end = RIGHT;
584     else if (end.startsWith("0%,100%"))
585         info.end = DOWN;
586     else if (end.startsWith("0%,-100%"))
587         info.end = UP;
588     else
589         info.end = CENTER;
590
591     if (end.count(':') == 2)
592         info.endTransparency = end.section(':', -1).toInt();
593     else
594         info.endTransparency = 100;
595
596     return info;
597 }
598
599 QString EffectStackEdit::getWipeString(wipeInfo info)
600 {
601
602     QString start;
603     QString end;
604     switch (info.start) {
605     case LEFT:
606         start = "-100%,0%:100%x100%";
607         break;
608     case RIGHT:
609         start = "100%,0%:100%x100%";
610         break;
611     case DOWN:
612         start = "0%,100%:100%x100%";
613         break;
614     case UP:
615         start = "0%,-100%:100%x100%";
616         break;
617     default:
618         start = "0%,0%:100%x100%";
619         break;
620     }
621     start.append(':' + QString::number(info.startTransparency));
622
623     switch (info.end) {
624     case LEFT:
625         end = "-100%,0%:100%x100%";
626         break;
627     case RIGHT:
628         end = "100%,0%:100%x100%";
629         break;
630     case DOWN:
631         end = "0%,100%:100%x100%";
632         break;
633     case UP:
634         end = "0%,-100%:100%x100%";
635         break;
636     default:
637         end = "0%,0%:100%x100%";
638         break;
639     }
640     end.append(':' + QString::number(info.endTransparency));
641     return QString(start + ";-1=" + end);
642 }
643
644 void EffectStackEdit::collectAllParameters()
645 {
646     if (m_valueItems.isEmpty() || m_params.isNull()) return;
647     const QDomElement oldparam = m_params.cloneNode().toElement();
648     QDomElement newparam = oldparam.cloneNode().toElement();
649     QDomNodeList namenode = newparam.elementsByTagName("parameter");
650
651     for (int i = 0; i < namenode.count() ; i++) {
652         QDomNode pa = namenode.item(i);
653         QDomNode na = pa.firstChildElement("name");
654         QString type = pa.attributes().namedItem("type").nodeValue();
655         QString paramName = i18n(na.toElement().text().toUtf8().data());
656         if (type == "complex")
657             paramName.append("complex");
658         else if (type == "position")
659             paramName.append("position");
660         else if (type == "geometry")
661             paramName.append("geometry");
662         else if (type == "keyframe")
663             paramName.append("keyframe");
664         if (type != "simplekeyframe" && type != "fixed" && type != "addedgeometry" && !m_valueItems.contains(paramName)) {
665             kDebug() << "// Param: " << paramName << " NOT FOUND";
666             continue;
667         }
668
669         QString setValue;
670         if (type == "double" || type == "constant") {
671             DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
672             setValue = QString::number(doubleparam->getValue());
673         } else if (type == "list") {
674             KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
675             setValue = box->itemData(box->currentIndex()).toString();
676         } else if (type == "bool") {
677             QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
678             setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
679         } else if (type == "color") {
680             ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
681             setValue = choosecolor->getColor().name();
682         } else if (type == "complex") {
683             ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
684             namenode.item(i) = complex->getParamDesc();
685         } else if (type == "geometry") {
686             if (KdenliveSettings::on_monitor_effects()) {
687                 if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getValue());
688             } else {
689                 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
690                 namenode.item(i).toElement().setAttribute("value", geom->getValue());
691             }
692         } else if (type == "addedgeometry") {
693             namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getExtraValue(namenode.item(i).toElement().attribute("name")));
694         } else if (type == "position") {
695             PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
696             int pos = pedit->getPosition();
697             setValue = QString::number(pos);
698             if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_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_in));
705                 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
706                 setValue.clear();
707             } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
708                 // Make sure duration is not longer than clip
709                 /*if (pos > m_out) {
710                     pos = m_out;
711                     pedit->setPosition(pos);
712                 }*/
713                 EffectsList::setParameter(newparam, "in", QString::number(m_out - pos));
714                 EffectsList::setParameter(newparam, "out", QString::number(m_out));
715                 setValue.clear();
716             }
717         } else if (type == "curve") {
718             KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
719             QList<QPointF> points = curve->curve().points();
720             QString number = pa.attributes().namedItem("number").nodeValue();
721             QString inName = pa.attributes().namedItem("inpoints").nodeValue();
722             QString outName = pa.attributes().namedItem("outpoints").nodeValue();
723             int off = pa.attributes().namedItem("min").nodeValue().toInt();
724             int end = pa.attributes().namedItem("max").nodeValue().toInt();
725             EffectsList::setParameter(newparam, number, QString::number(points.count()));
726             for (int j = 0; (j < points.count() && j + off <= end); j++) {
727                 QString in = inName;
728                 in.replace("%i", QString::number(j + off));
729                 QString out = outName;
730                 out.replace("%i", QString::number(j + off));
731                 EffectsList::setParameter(newparam, in, QString::number(points.at(j).x()));
732                 EffectsList::setParameter(newparam, out, QString::number(points.at(j).y()));
733             }
734             QString depends = pa.attributes().namedItem("depends").nodeValue();
735             if (!depends.isEmpty())
736                 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
737         } else if (type == "bezier_spline") {
738             BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
739             setValue = widget->spline();
740             QString depends = pa.attributes().namedItem("depends").nodeValue();
741             if (!depends.isEmpty())
742                 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
743 #ifdef QJSON
744         } else if (type == "roto-spline") {
745             RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
746             setValue = widget->getSpline();
747 #endif
748         } else if (type == "wipe") {
749             Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
750             wipeInfo info;
751             if (wp->start_left->isChecked())
752                 info.start = LEFT;
753             else if (wp->start_right->isChecked())
754                 info.start = RIGHT;
755             else if (wp->start_up->isChecked())
756                 info.start = UP;
757             else if (wp->start_down->isChecked())
758                 info.start = DOWN;
759             else if (wp->start_center->isChecked())
760                 info.start = CENTER;
761             else
762                 info.start = LEFT;
763             info.startTransparency = wp->start_transp->value();
764
765             if (wp->end_left->isChecked())
766                 info.end = LEFT;
767             else if (wp->end_right->isChecked())
768                 info.end = RIGHT;
769             else if (wp->end_up->isChecked())
770                 info.end = UP;
771             else if (wp->end_down->isChecked())
772                 info.end = DOWN;
773             else if (wp->end_center->isChecked())
774                 info.end = CENTER;
775             else
776                 info.end = RIGHT;
777             info.endTransparency = wp->end_transp->value();
778
779             setValue = getWipeString(info);
780         } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
781             QDomElement elem = pa.toElement();
782             QString realName = i18n(na.toElement().text().toUtf8().data());
783             QString val = m_keyframeEditor->getValue(realName);
784             elem.setAttribute("keyframes", val);
785
786             if (m_keyframeEditor->isVisibleParam(realName))
787                 elem.setAttribute("intimeline", "1");
788             else if (elem.hasAttribute("intimeline"))
789                 elem.removeAttribute("intimeline");
790         } else if (type == "url") {
791             KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
792             setValue = req->url().path();
793         }
794
795         if (!setValue.isNull())
796             pa.attributes().namedItem("value").setNodeValue(setValue);
797
798     }
799     emit parameterChanged(oldparam, newparam);
800 }
801
802 void EffectStackEdit::clearAllItems()
803 {
804     blockSignals(true);
805     m_valueItems.clear();
806     m_uiItems.clear();
807     /*while (!m_items.isEmpty()) {
808         QWidget *die = m_items.takeFirst();
809         die->disconnect();
810         delete die;
811     }*/
812     //qDeleteAll(m_uiItems);
813     QLayoutItem *child;
814     while ((child = m_vbox->takeAt(0)) != 0) {
815         QWidget *wid = child->widget();
816         delete child;
817         if (wid) delete wid;
818     }
819     m_keyframeEditor = NULL;
820     m_geometryWidget = NULL;
821     blockSignals(false);
822 }
823
824 void EffectStackEdit::slotSyncEffectsPos(int pos)
825 {
826     emit syncEffectsPos(pos);
827 }