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