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