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