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