]> git.sesse.net Git - kdenlive/blob - src/effectstackedit.cpp
Continue work on slider widget, rewrote layout for geometry param (used in composite...
[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, 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(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
455             connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
456             m_vbox->addWidget(roto);
457             m_valueItems[paramName] = roto;
458 #endif
459         } else if (type == "wipe") {
460             Wipeval *wpval = new Wipeval;
461             wpval->setupUi(toFillin);
462             wipeInfo w = getWipeInfo(value);
463             switch (w.start) {
464             case UP:
465                 wpval->start_up->setChecked(true);
466                 break;
467             case DOWN:
468                 wpval->start_down->setChecked(true);
469                 break;
470             case RIGHT:
471                 wpval->start_right->setChecked(true);
472                 break;
473             case LEFT:
474                 wpval->start_left->setChecked(true);
475                 break;
476             default:
477                 wpval->start_center->setChecked(true);
478                 break;
479             }
480             switch (w.end) {
481             case UP:
482                 wpval->end_up->setChecked(true);
483                 break;
484             case DOWN:
485                 wpval->end_down->setChecked(true);
486                 break;
487             case RIGHT:
488                 wpval->end_right->setChecked(true);
489                 break;
490             case LEFT:
491                 wpval->end_left->setChecked(true);
492                 break;
493             default:
494                 wpval->end_center->setChecked(true);
495                 break;
496             }
497             wpval->start_transp->setValue(w.startTransparency);
498             wpval->end_transp->setValue(w.endTransparency);
499             m_valueItems[paramName] = wpval;
500             connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
501             connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
502             connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
503             connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
504             connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
505             connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
506             connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
507             connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
508             connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
509             connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
510             connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
511             connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
512             //wpval->title->setTitle(na.toElement().text());
513             m_uiItems.append(wpval);
514         } else if (type == "url") {
515             Urlval *cval = new Urlval;
516             cval->setupUi(toFillin);
517             cval->label->setText(paramName);
518             cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
519             m_valueItems[paramName] = cval;
520             cval->urlwidget->setUrl(KUrl(value));
521             connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(collectAllParameters()));
522             connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(collectAllParameters()));
523             m_uiItems.append(cval);
524         } else {
525             delete toFillin;
526             toFillin = NULL;
527         }
528
529         if (toFillin)
530             m_vbox->addWidget(toFillin);
531     }
532
533     if (stretch)
534         m_vbox->addStretch();
535
536     if (m_keyframeEditor)
537         m_keyframeEditor->checkVisibleParam();
538     
539     // Make sure all doubleparam spinboxes have the same width, looks much better
540     QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
541     int minSize = 0;
542     for (int i = 0; i < allWidgets.count(); i++) {
543         if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
544     }
545     for (int i = 0; i < allWidgets.count(); i++) {
546         allWidgets.at(i)->setSpinSize(minSize);
547     }
548 }
549
550 wipeInfo EffectStackEdit::getWipeInfo(QString value)
551 {
552     wipeInfo info;
553     QString start = value.section(';', 0, 0);
554     QString end = value.section(';', 1, 1).section('=', 1, 1);
555
556     if (start.startsWith("-100%,0"))
557         info.start = LEFT;
558     else if (start.startsWith("100%,0"))
559         info.start = RIGHT;
560     else if (start.startsWith("0%,100%"))
561         info.start = DOWN;
562     else if (start.startsWith("0%,-100%"))
563         info.start = UP;
564     else
565         info.start = CENTER;
566
567     if (start.count(':') == 2)
568         info.startTransparency = start.section(':', -1).toInt();
569     else
570         info.startTransparency = 100;
571
572     if (end.startsWith("-100%,0"))
573         info.end = LEFT;
574     else if (end.startsWith("100%,0"))
575         info.end = RIGHT;
576     else if (end.startsWith("0%,100%"))
577         info.end = DOWN;
578     else if (end.startsWith("0%,-100%"))
579         info.end = UP;
580     else
581         info.end = CENTER;
582
583     if (end.count(':') == 2)
584         info.endTransparency = end.section(':', -1).toInt();
585     else
586         info.endTransparency = 100;
587
588     return info;
589 }
590
591 QString EffectStackEdit::getWipeString(wipeInfo info)
592 {
593
594     QString start;
595     QString end;
596     switch (info.start) {
597     case LEFT:
598         start = "-100%,0%:100%x100%";
599         break;
600     case RIGHT:
601         start = "100%,0%:100%x100%";
602         break;
603     case DOWN:
604         start = "0%,100%:100%x100%";
605         break;
606     case UP:
607         start = "0%,-100%:100%x100%";
608         break;
609     default:
610         start = "0%,0%:100%x100%";
611         break;
612     }
613     start.append(':' + QString::number(info.startTransparency));
614
615     switch (info.end) {
616     case LEFT:
617         end = "-100%,0%:100%x100%";
618         break;
619     case RIGHT:
620         end = "100%,0%:100%x100%";
621         break;
622     case DOWN:
623         end = "0%,100%:100%x100%";
624         break;
625     case UP:
626         end = "0%,-100%:100%x100%";
627         break;
628     default:
629         end = "0%,0%:100%x100%";
630         break;
631     }
632     end.append(':' + QString::number(info.endTransparency));
633     return QString(start + ";-1=" + end);
634 }
635
636 void EffectStackEdit::collectAllParameters()
637 {
638     if (m_valueItems.isEmpty() || m_params.isNull()) return;
639     const QDomElement oldparam = m_params.cloneNode().toElement();
640     QDomElement newparam = oldparam.cloneNode().toElement();
641     QDomNodeList namenode = newparam.elementsByTagName("parameter");
642
643     for (int i = 0; i < namenode.count() ; i++) {
644         QDomNode pa = namenode.item(i);
645         QDomNode na = pa.firstChildElement("name");
646         QString type = pa.attributes().namedItem("type").nodeValue();
647         QString paramName = i18n(na.toElement().text().toUtf8().data());
648         if (type == "complex")
649             paramName.append("complex");
650         else if (type == "position")
651             paramName.append("position");
652         else if (type == "geometry")
653             paramName.append("geometry");
654         else if (type == "keyframe")
655             paramName.append("keyframe");
656         if (type != "simplekeyframe" && !m_valueItems.contains(paramName)) {
657             kDebug() << "// Param: " << paramName << " NOT FOUND";
658             continue;
659         }
660
661         QString setValue;
662         if (type == "double" || type == "constant") {
663             DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
664             setValue = QString::number(doubleparam->getValue());
665         } else if (type == "list") {
666             KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
667             setValue = box->itemData(box->currentIndex()).toString();
668         } else if (type == "bool") {
669             QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
670             setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
671         } else if (type == "color") {
672             ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
673             setValue = choosecolor->getColor().name();
674         } else if (type == "complex") {
675             ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
676             namenode.item(i) = complex->getParamDesc();
677         } else if (type == "geometry") {
678             if (KdenliveSettings::on_monitor_effects()) {
679                 GeometryWidget *geometry = ((GeometryWidget*)m_valueItems.value(paramName));
680                 namenode.item(i).toElement().setAttribute("value", geometry->getValue());
681             } else {
682                 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
683                 namenode.item(i).toElement().setAttribute("value", geom->getValue());
684             }
685         } else if (type == "position") {
686             PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
687             int pos = pedit->getPosition();
688             setValue = QString::number(pos);
689             if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_black") {
690                 // Make sure duration is not longer than clip
691                 /*if (pos > m_out) {
692                     pos = m_out;
693                     pedit->setPosition(pos);
694                 }*/
695                 EffectsList::setParameter(newparam, "in", QString::number(m_in));
696                 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
697                 setValue.clear();
698             } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
699                 // Make sure duration is not longer than clip
700                 /*if (pos > m_out) {
701                     pos = m_out;
702                     pedit->setPosition(pos);
703                 }*/
704                 EffectsList::setParameter(newparam, "in", QString::number(m_out - pos));
705                 EffectsList::setParameter(newparam, "out", QString::number(m_out));
706                 setValue.clear();
707             }
708         } else if (type == "curve") {
709             KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
710             QList<QPointF> points = curve->curve().points();
711             QString number = pa.attributes().namedItem("number").nodeValue();
712             QString inName = pa.attributes().namedItem("inpoints").nodeValue();
713             QString outName = pa.attributes().namedItem("outpoints").nodeValue();
714             int off = pa.attributes().namedItem("min").nodeValue().toInt();
715             int end = pa.attributes().namedItem("max").nodeValue().toInt();
716             EffectsList::setParameter(newparam, number, QString::number(points.count()));
717             for (int j = 0; (j < points.count() && j + off <= end); j++) {
718                 QString in = inName;
719                 in.replace("%i", QString::number(j + off));
720                 QString out = outName;
721                 out.replace("%i", QString::number(j + off));
722                 EffectsList::setParameter(newparam, in, QString::number(points.at(j).x()));
723                 EffectsList::setParameter(newparam, out, QString::number(points.at(j).y()));
724             }
725             QString depends = pa.attributes().namedItem("depends").nodeValue();
726             if (!depends.isEmpty())
727                 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
728         } else if (type == "bezier_spline") {
729             BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
730             setValue = widget->spline();
731             QString depends = pa.attributes().namedItem("depends").nodeValue();
732             if (!depends.isEmpty())
733                 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
734 #ifdef QJSON
735         } else if (type == "roto-spline") {
736             RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
737             setValue = widget->getSpline();
738 #endif
739         } else if (type == "wipe") {
740             Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
741             wipeInfo info;
742             if (wp->start_left->isChecked())
743                 info.start = LEFT;
744             else if (wp->start_right->isChecked())
745                 info.start = RIGHT;
746             else if (wp->start_up->isChecked())
747                 info.start = UP;
748             else if (wp->start_down->isChecked())
749                 info.start = DOWN;
750             else if (wp->start_center->isChecked())
751                 info.start = CENTER;
752             else
753                 info.start = LEFT;
754             info.startTransparency = wp->start_transp->value();
755
756             if (wp->end_left->isChecked())
757                 info.end = LEFT;
758             else if (wp->end_right->isChecked())
759                 info.end = RIGHT;
760             else if (wp->end_up->isChecked())
761                 info.end = UP;
762             else if (wp->end_down->isChecked())
763                 info.end = DOWN;
764             else if (wp->end_center->isChecked())
765                 info.end = CENTER;
766             else
767                 info.end = RIGHT;
768             info.endTransparency = wp->end_transp->value();
769
770             setValue = getWipeString(info);
771         } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
772             QDomElement elem = pa.toElement();
773             QString realName = i18n(na.toElement().text().toUtf8().data());
774             QString val = m_keyframeEditor->getValue(realName);
775             elem.setAttribute("keyframes", val);
776
777             if (m_keyframeEditor->isVisibleParam(realName))
778                 elem.setAttribute("intimeline", "1");
779             else if (elem.hasAttribute("intimeline"))
780                 elem.removeAttribute("intimeline");
781         } else if (type == "url") {
782             KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
783             setValue = req->url().path();
784         }
785
786         if (!setValue.isNull())
787             pa.attributes().namedItem("value").setNodeValue(setValue);
788
789     }
790     emit parameterChanged(oldparam, newparam);
791 }
792
793 void EffectStackEdit::clearAllItems()
794 {
795     blockSignals(true);
796     m_valueItems.clear();
797     m_uiItems.clear();
798     /*while (!m_items.isEmpty()) {
799         QWidget *die = m_items.takeFirst();
800         die->disconnect();
801         delete die;
802     }*/
803     //qDeleteAll(m_uiItems);
804     QLayoutItem *child;
805     while ((child = m_vbox->takeAt(0)) != 0) {
806         QWidget *wid = child->widget();
807         delete child;
808         if (wid) delete wid;
809     }
810     m_keyframeEditor = NULL;
811     blockSignals(false);
812 }
813
814 void EffectStackEdit::slotSyncEffectsPos(int pos)
815 {
816     emit syncEffectsPos(pos);
817 }