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