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