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