]> git.sesse.net Git - kdenlive/blob - src/effectstack/collapsibleeffect.cpp
4d49f10d9e9fbbd882fc350d91a4581891e5e6fe
[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 "ui_keywordval_ui.h"
28 #include "ui_fontval_ui.h"
29 #include "complexparameter.h"
30 #include "geometryval.h"
31 #include "positionedit.h"
32 #include "projectlist.h"
33 #include "effectslist.h"
34 #include "kdenlivesettings.h"
35 #include "profilesdialog.h"
36 #include "kis_curve_widget.h"
37 #include "kis_cubic_curve.h"
38 #include "choosecolorwidget.h"
39 #include "geometrywidget.h"
40 #include "colortools.h"
41 #include "doubleparameterwidget.h"
42 #include "cornerswidget.h"
43 #include "dragvalue.h"
44 #include "beziercurve/beziersplinewidget.h"
45 #ifdef USE_QJSON
46 #include "rotoscoping/rotowidget.h"
47 #endif
48
49 #include <QInputDialog>
50 #include <QDialog>
51 #include <QMenu>
52 #include <QVBoxLayout>
53 #include <KDebug>
54 #include <KGlobalSettings>
55 #include <KLocale>
56 #include <KMessageBox>
57 #include <KStandardDirs>
58 #include <KFileDialog>
59 #include <KUrlRequester>
60
61 class Boolval: public QWidget, public Ui::Boolval_UI
62 {
63 };
64
65 class Listval: public QWidget, public Ui::Listval_UI
66 {
67 };
68
69 class Wipeval: public QWidget, public Ui::Wipeval_UI
70 {
71 };
72
73 class Urlval: public QWidget, public Ui::Urlval_UI
74 {
75 };
76
77 class Keywordval: public QWidget, public Ui::Keywordval_UI
78 {
79 };
80
81 class Fontval: public QWidget, public Ui::Fontval_UI
82 {
83 };
84
85 QMap<QString, QImage> CollapsibleEffect::iconCache;
86
87 void clearLayout(QLayout *layout)
88 {
89     QLayoutItem *item;
90     while((item = layout->takeAt(0))) {
91         if (item->layout()) {
92             clearLayout(item->layout());
93             delete item->layout();
94         }
95         if (item->widget()) {
96             delete item->widget();
97         }
98         delete item;
99     }
100 }
101
102 MySpinBox::MySpinBox(QWidget * parent):
103     QSpinBox(parent)
104 {
105     setFocusPolicy(Qt::StrongFocus);
106 }
107
108 void MySpinBox::focusInEvent(QFocusEvent*)
109 {
110      setFocusPolicy(Qt::WheelFocus);
111 }
112
113 void MySpinBox::focusOutEvent(QFocusEvent*)
114 {
115      setFocusPolicy(Qt::StrongFocus);
116 }
117
118
119 CollapsibleEffect::CollapsibleEffect(QDomElement effect, QDomElement original_effect, ItemInfo info, int ix, EffectMetaInfo *metaInfo, bool lastEffect, bool isGroup, QWidget * parent) :
120         QWidget(parent),
121         m_paramWidget(NULL),
122         m_effect(effect),
123         m_original_effect(original_effect),
124         m_lastEffect(lastEffect),
125         m_isGroup(isGroup),
126         m_active(false),
127         m_index(ix)
128 {
129     //setMouseTracking(true);
130     setupUi(this);
131     filterWheelEvent = true;
132     m_info.fromString(effect.attribute("kdenlive_info"));
133     frame->setBackgroundRole(QPalette::Midlight);
134     frame->setAutoFillBackground(true);
135     setFont(KGlobalSettings::smallestReadableFont());
136    
137     buttonUp->setIcon(KIcon("go-up"));
138     buttonUp->setToolTip(i18n("Move effect up"));
139     if (!lastEffect) {
140         buttonDown->setIcon(KIcon("go-down"));
141         buttonDown->setToolTip(i18n("Move effect down"));
142     }
143     buttonDel->setIcon(KIcon("edit-delete"));
144     buttonDel->setToolTip(i18n("Delete effect"));
145
146     buttonUp->setVisible(false);
147     buttonDown->setVisible(false);
148     buttonDel->setVisible(false);
149     
150     /*buttonReset->setIcon(KIcon("view-refresh"));
151     buttonReset->setToolTip(i18n("Reset effect"));*/
152     //checkAll->setToolTip(i18n("Enable/Disable all effects"));
153     //buttonShowComments->setIcon(KIcon("help-about"));
154     //buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
155     m_menu = new QMenu;
156     m_menu->addAction(KIcon("view-refresh"), i18n("Reset effect"), this, SLOT(slotResetEffect()));
157     m_menu->addAction(KIcon("document-save"), i18n("Save effect"), this, SLOT(slotSaveEffect()));
158     
159     if (!m_isGroup) {
160         QDomElement namenode = m_effect.firstChildElement("name");
161         if (namenode.isNull()) return;
162         title->setText(i18n(namenode.text().toUtf8().data()));
163         QString type = m_effect.attribute("type", QString());
164         KIcon icon;
165         if (type == "audio") icon = KIcon("kdenlive-show-audio");
166         else if (m_effect.attribute("tag") == "region") icon = KIcon("kdenlive-mask-effect");
167         else if (type == "custom") icon = KIcon("kdenlive-custom-effect");
168         else icon = KIcon("kdenlive-show-video");
169         title->setIcon(icon);
170         m_menu->addAction(KIcon("folder-new"), i18n("Create Group"), this, SLOT(slotCreateGroup()));
171         setupWidget(info, ix, metaInfo);
172     }
173     else {
174         title->setText(i18n("Effect Group"));
175         title->setIcon(KIcon("folder"));
176         m_menu->addAction(KIcon("list-remove"), i18n("Ungroup"), this, SLOT(slotUnGroup()));
177     }
178     setAcceptDrops(true);
179     title->setMenu(m_menu);
180     
181     if (m_effect.attribute("disable") == "1") {
182         enabledBox->setCheckState(Qt::Unchecked);
183         title->setEnabled(false);
184     }
185     else {
186         enabledBox->setCheckState(Qt::Checked);
187     }
188
189     connect(collapseButton, SIGNAL(clicked()), this, SLOT(slotSwitch()));
190     connect(enabledBox, SIGNAL(toggled(bool)), this, SLOT(slotEnable(bool)));
191     connect(buttonUp, SIGNAL(clicked()), this, SLOT(slotEffectUp()));
192     connect(buttonDown, SIGNAL(clicked()), this, SLOT(slotEffectDown()));
193     connect(buttonDel, SIGNAL(clicked()), this, SLOT(slotDeleteEffect()));
194
195     Q_FOREACH( QSpinBox * sp, findChildren<QSpinBox*>() ) {
196         sp->installEventFilter( this );
197         sp->setFocusPolicy( Qt::StrongFocus );
198     }
199     Q_FOREACH( KComboBox * cb, findChildren<KComboBox*>() ) {
200         cb->installEventFilter( this );
201         cb->setFocusPolicy( Qt::StrongFocus );
202     }
203     Q_FOREACH( QProgressBar * cb, findChildren<QProgressBar*>() ) {
204         cb->installEventFilter( this );
205         cb->setFocusPolicy( Qt::StrongFocus );
206     }
207 }
208
209 CollapsibleEffect::~CollapsibleEffect()
210 {
211     if (m_paramWidget) delete m_paramWidget;
212     delete m_menu;
213 }
214
215 void CollapsibleEffect::slotCreateGroup()
216 {
217     emit createGroup(effectIndex());
218 }
219
220 void CollapsibleEffect::slotUnGroup()
221 {
222     emit unGroup(this);
223 }
224
225 bool CollapsibleEffect::eventFilter( QObject * o, QEvent * e ) 
226 {
227     if (e->type() == QEvent::Wheel) {
228         QWheelEvent *we = static_cast<QWheelEvent *>(e);
229         if (!filterWheelEvent || we->modifiers() != Qt::NoModifier) {
230             e->accept();
231             return false;
232         }
233         if (qobject_cast<QAbstractSpinBox*>(o)) {
234             if(qobject_cast<QAbstractSpinBox*>(o)->focusPolicy() == Qt::WheelFocus)
235             {
236                 e->accept();
237                 return false;
238             }
239             else
240             {
241                 e->ignore();
242                 return true;
243             }
244         }
245         if (qobject_cast<KComboBox*>(o)) {
246             if(qobject_cast<KComboBox*>(o)->focusPolicy() == Qt::WheelFocus)
247             {
248                 e->accept();
249                 return false;
250             }
251             else
252             {
253                 e->ignore();
254                 return true;
255             }
256         }
257         if (qobject_cast<QProgressBar*>(o)) {
258             if(qobject_cast<QProgressBar*>(o)->focusPolicy() == Qt::WheelFocus)
259             {
260                 e->accept();
261                 return false;
262             }
263             else
264             {
265                 e->ignore();
266                 return true;
267             }
268         }
269     }
270     return QWidget::eventFilter(o, e);
271 }
272
273 QDomElement CollapsibleEffect::effect() const
274 {
275     return m_effect;
276 }
277
278 bool CollapsibleEffect::isActive() const
279 {
280     return m_active;
281 }
282
283 void CollapsibleEffect::setActive(bool activate, bool focused)
284 {
285     m_active = activate;
286     if (focused) {
287         frame->setBackgroundRole(QPalette::Highlight);
288     }
289     else frame->setBackgroundRole(m_active ? QPalette::Mid : QPalette::Midlight);
290 }
291
292 void CollapsibleEffect::mouseDoubleClickEvent ( QMouseEvent * event )
293 {
294     if (frame->underMouse() && collapseButton->isEnabled()) slotSwitch();
295     QWidget::mouseDoubleClickEvent(event);
296 }
297
298 void CollapsibleEffect::mousePressEvent ( QMouseEvent *event )
299 {
300     if (!m_active && m_paramWidget) emit activateEffect(effectIndex());
301     QWidget::mousePressEvent(event);
302 }
303
304 void CollapsibleEffect::enterEvent ( QEvent * event )
305 {
306     if (m_paramWidget == NULL || m_paramWidget->index() > 0) buttonUp->setVisible(true);
307     if (!m_lastEffect) buttonDown->setVisible(true);
308     buttonDel->setVisible(true);
309     QWidget::enterEvent(event);
310 }
311
312 void CollapsibleEffect::leaveEvent ( QEvent * event )
313 {
314     buttonUp->setVisible(false);
315     buttonDown->setVisible(false);
316     buttonDel->setVisible(false);
317     QWidget::leaveEvent(event);
318 }
319
320 void CollapsibleEffect::slotEnable(bool enable)
321 {
322     title->setEnabled(enable);
323     enabledBox->blockSignals(true);
324     enabledBox->setChecked(enable);
325     enabledBox->blockSignals(false);
326     if (m_isGroup) {
327         QVBoxLayout *vbox = static_cast<QVBoxLayout *>(widgetFrame->layout());
328         if (vbox == NULL) return;
329         for (int i = 0; i < vbox->count(); i++) {
330             CollapsibleEffect *e = static_cast<CollapsibleEffect *>(vbox->itemAt(i)->widget());
331             if (e) e->enabledBox->setChecked(enable);// slotEnable(enable);
332         }
333     } else {
334         m_effect.setAttribute("disable", enable ? 0 : 1);
335         if (enable || KdenliveSettings::disable_effect_parameters()) {
336             widgetFrame->setEnabled(enable);
337         }
338         emit effectStateChanged(!enable, m_paramWidget->index());
339     }
340 }
341
342 void CollapsibleEffect::slotDeleteEffect()
343 {
344     if (!m_isGroup) emit deleteEffect(m_effect);
345 }
346
347 void CollapsibleEffect::slotEffectUp()
348 {
349     if (!m_isGroup) emit changeEffectPosition(effectIndex(), true);
350 }
351
352 void CollapsibleEffect::slotEffectDown()
353 {
354     if (!m_isGroup) emit changeEffectPosition(effectIndex(), false);
355 }
356
357 void CollapsibleEffect::slotSaveEffect()
358 {
359     QString name = QInputDialog::getText(this, i18n("Save Effect"), i18n("Name for saved effect: "));
360     if (name.isEmpty()) return;
361     QString path = KStandardDirs::locateLocal("appdata", "effects/", true);
362     path = path + name + ".xml";
363     if (QFile::exists(path)) if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", path)) == KMessageBox::No) return;
364
365     QDomDocument doc;
366     QDomElement effect = m_effect.cloneNode().toElement();
367     doc.appendChild(doc.importNode(effect, true));
368     effect = doc.firstChild().toElement();
369     effect.removeAttribute("kdenlive_ix");
370     effect.setAttribute("id", name);
371     effect.setAttribute("type", "custom");
372     QDomElement effectname = effect.firstChildElement("name");
373     effect.removeChild(effectname);
374     effectname = doc.createElement("name");
375     QDomText nametext = doc.createTextNode(name);
376     effectname.appendChild(nametext);
377     effect.insertBefore(effectname, QDomNode());
378     QDomElement effectprops = effect.firstChildElement("properties");
379     effectprops.setAttribute("id", name);
380     effectprops.setAttribute("type", "custom");
381
382     QFile file(path);
383     if (file.open(QFile::WriteOnly | QFile::Truncate)) {
384         QTextStream out(&file);
385         out << doc.toString();
386     }
387     file.close();
388     emit reloadEffects();
389 }
390
391 void CollapsibleEffect::slotResetEffect()
392 {
393     emit resetEffect(effectIndex());
394 }
395
396 void CollapsibleEffect::slotSwitch()
397 {
398     bool enable = !widgetFrame->isVisible();
399     slotShow(enable);
400 }
401
402 void CollapsibleEffect::slotShow(bool show)
403 {
404     widgetFrame->setVisible(show);
405     if (show) {
406         collapseButton->setArrowType(Qt::DownArrow);
407         m_info.isCollapsed = false;
408     }
409     else {
410         collapseButton->setArrowType(Qt::RightArrow);
411         m_info.isCollapsed = true;
412     }
413     m_effect.setAttribute("kdenlive_info", m_info.toString());
414     emit parameterChanged(m_original_effect, m_effect, m_index);   
415 }
416
417 void CollapsibleEffect::updateGroupIndex(int groupIndex)
418 {
419     m_info.groupIndex = groupIndex;
420     m_effect.setAttribute("kdenlive_info", m_info.toString());
421     emit parameterChanged(m_original_effect, m_effect, m_index);
422 }
423
424 void CollapsibleEffect::setGroupIndex(int ix)
425 {
426     m_info.groupIndex = ix;
427 }
428
429 void CollapsibleEffect::addGroupEffect(CollapsibleEffect *effect)
430 {
431     QVBoxLayout *vbox = static_cast<QVBoxLayout *>(widgetFrame->layout());
432     if (vbox == NULL) {
433         vbox = new QVBoxLayout();
434         vbox->setContentsMargins(10, 0, 0, 0);
435         vbox->setSpacing(2);
436         widgetFrame->setLayout(vbox);
437     }
438     effect->setGroupIndex(groupIndex());
439     vbox->addWidget(effect);
440 }
441
442 QString CollapsibleEffect::infoString() const
443 {
444     return m_info.toString();
445 }
446
447 void CollapsibleEffect::removeGroup(int ix, QVBoxLayout *layout)
448 {
449     QVBoxLayout *vbox = static_cast<QVBoxLayout *>(widgetFrame->layout());
450     if (vbox == NULL) return;
451     
452     for (int j = vbox->count() - 1; j >= 0; j--) {
453         QLayoutItem *child = vbox->takeAt(j);
454         CollapsibleEffect *e = static_cast<CollapsibleEffect *>(child->widget());
455         layout->insertWidget(ix, e);
456         e->updateGroupIndex(-1);
457         delete child;
458     }
459 }
460
461 int CollapsibleEffect::index() const
462 {
463     return m_index;
464 }
465
466 int CollapsibleEffect::groupIndex() const
467 {
468     if (m_isGroup) return m_index;
469     return -1;
470 }
471
472 int CollapsibleEffect::effectIndex() const
473 {
474     if (m_effect.isNull()) return -1;
475     return m_effect.attribute("kdenlive_ix").toInt();
476 }
477
478 void CollapsibleEffect::updateWidget(ItemInfo info, int index, QDomElement effect, EffectMetaInfo *metaInfo)
479 {
480     if (m_paramWidget) {
481         // cleanup
482         delete m_paramWidget;
483         m_paramWidget = NULL;
484     }
485     m_effect = effect;
486     setupWidget(info, index, metaInfo);
487 }
488
489 void CollapsibleEffect::setupWidget(ItemInfo info, int index, EffectMetaInfo *metaInfo)
490 {
491     if (m_effect.isNull()) {
492 //         kDebug() << "// EMPTY EFFECT STACK";
493         return;
494     }
495
496     if (m_effect.attribute("tag") == "region") {
497         QVBoxLayout *vbox = new QVBoxLayout(widgetFrame);
498         vbox->setContentsMargins(0, 0, 0, 0);
499         vbox->setSpacing(2);
500         QDomNodeList effects =  m_effect.elementsByTagName("effect");
501         QDomNodeList origin_effects =  m_original_effect.elementsByTagName("effect");
502         QWidget *container = new QWidget(widgetFrame);
503         vbox->addWidget(container);
504         m_paramWidget = new ParameterContainer(m_effect.toElement(), info, metaInfo, index, container);
505         for (int i = 0; i < effects.count(); i++) {
506             CollapsibleEffect *coll = new CollapsibleEffect(effects.at(i).toElement(), origin_effects.at(i).toElement(), info, i, metaInfo, container);
507             m_subParamWidgets.append(coll);
508             //container = new QWidget(widgetFrame);
509             vbox->addWidget(coll);
510             //p = new ParameterContainer(effects.at(i).toElement(), info, isEffect, container);
511         }
512         
513     }
514     else {
515         m_paramWidget = new ParameterContainer(m_effect, info, metaInfo, index, widgetFrame);
516         if (m_effect.firstChildElement("parameter").isNull()) {
517             // Effect has no parameter, don't allow expand
518             collapseButton->setEnabled(false);
519             widgetFrame->setVisible(false);            
520         }
521     }
522     if (collapseButton->isEnabled() && m_info.isCollapsed) {
523         widgetFrame->setVisible(false);
524         collapseButton->setArrowType(Qt::RightArrow);
525         
526     }
527     connect (m_paramWidget, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)));
528     
529     connect(m_paramWidget, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)));
530     
531     connect (this, SIGNAL(syncEffectsPos(int)), m_paramWidget, SIGNAL(syncEffectsPos(int)));
532     connect (this, SIGNAL(effectStateChanged(bool)), m_paramWidget, SIGNAL(effectStateChanged(bool)));
533     connect (m_paramWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
534     connect (m_paramWidget, SIGNAL(seekTimeline(int)), this, SIGNAL(seekTimeline(int)));
535     
536     
537 }
538
539 void CollapsibleEffect::updateTimecodeFormat()
540 {
541     m_paramWidget->updateTimecodeFormat();
542     if (!m_subParamWidgets.isEmpty()) {
543         // we have a group
544         for (int i = 0; i < m_subParamWidgets.count(); i++)
545             m_subParamWidgets.at(i)->updateTimecodeFormat();
546     }
547 }
548
549 void CollapsibleEffect::slotSyncEffectsPos(int pos)
550 {
551     emit syncEffectsPos(pos);
552 }
553
554 void CollapsibleEffect::dragEnterEvent(QDragEnterEvent *event)
555 {
556     if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
557         setActive(m_active, true);
558         event->acceptProposedAction();
559     }
560 }
561
562 void CollapsibleEffect::dragLeaveEvent(QDragLeaveEvent */*event*/)
563 {
564     setActive(m_active, false);
565 }
566
567 void CollapsibleEffect::dropEvent(QDropEvent *event)
568 {
569     const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
570     //event->acceptProposedAction();
571     QDomDocument doc;
572     doc.setContent(effects, true);
573     QDomElement e = doc.documentElement();
574     int ix = e.attribute("kdenlive_ix").toInt();
575     if (ix == effectIndex()) {
576         // effect dropped on itself, reject
577         event->ignore();
578         return;
579     }
580     if (ix == 0) {
581         // effect dropped from effects list, add it
582         e.setAttribute("kdenlive_ix", ix);
583         event->setDropAction(Qt::CopyAction);
584         event->accept();
585         emit addEffect(e);
586         return;
587     }
588     int new_index = -1;
589     if (m_isGroup) {
590         QVBoxLayout *vbox = static_cast<QVBoxLayout *>(widgetFrame->layout());
591         if (vbox == NULL) return;
592         CollapsibleEffect *e = static_cast<CollapsibleEffect *>(vbox->itemAt(vbox->count() -1)->widget());
593         new_index = e->effectIndex() + 1;
594     }
595     else {
596         new_index = effectIndex();
597     }
598     emit moveEffect(ix, new_index, this);
599     event->setDropAction(Qt::MoveAction);
600     event->accept();
601 }
602
603 ParameterContainer::ParameterContainer(QDomElement effect, ItemInfo info, EffectMetaInfo *metaInfo, int index, QWidget * parent) :
604         m_index(index),
605         m_keyframeEditor(NULL),
606         m_geometryWidget(NULL),
607         m_metaInfo(metaInfo),
608         m_effect(effect)
609 {
610     m_in = info.cropStart.frames(KdenliveSettings::project_fps());
611     m_out = (info.cropStart + info.cropDuration).frames(KdenliveSettings::project_fps()) - 1;
612
613     QDomNodeList namenode = effect.childNodes(); //elementsByTagName("parameter");
614     
615     QDomElement e = effect.toElement();
616     int minFrame = e.attribute("start").toInt();
617     int maxFrame = e.attribute("end").toInt();
618     // In transitions, maxFrame is in fact one frame after the end of transition
619     if (maxFrame > 0) maxFrame --;
620
621     bool disable = effect.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
622     parent->setEnabled(!disable);
623
624     bool stretch = true;
625     m_vbox = new QVBoxLayout(parent);
626     m_vbox->setContentsMargins(0, 0, 0, 0);
627     m_vbox->setSpacing(2);
628
629     for (int i = 0; i < namenode.count() ; i++) {
630         QDomElement pa = namenode.item(i).toElement();
631         if (pa.tagName() != "parameter") continue;
632         QDomElement na = pa.firstChildElement("name");
633         QDomElement commentElem = pa.firstChildElement("comment");
634         QString type = pa.attribute("type");
635         QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
636         QString comment;
637         if (!commentElem.isNull())
638             comment = i18n(commentElem.text().toUtf8().data());
639         QWidget * toFillin = new QWidget(parent);
640         QString value = pa.attribute("value").isNull() ?
641                         pa.attribute("default") : pa.attribute("value");
642
643
644         /** See effects/README for info on the different types */
645
646         if (type == "double" || type == "constant") {
647             double min;
648             double max;
649             if (pa.attribute("min").contains('%'))
650                 min = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("min"), m_metaInfo->frameSize);
651             else
652                 min = pa.attribute("min").toDouble();
653             if (pa.attribute("max").contains('%'))
654                 max = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("max"), m_metaInfo->frameSize);
655             else
656                 max = pa.attribute("max").toDouble();
657
658             DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, value.toDouble(), min, max,
659                     pa.attribute("default").toDouble(), comment, -1, pa.attribute("suffix"), pa.attribute("decimals").toInt(), parent);
660             doubleparam->setFocusPolicy(Qt::StrongFocus);
661             m_vbox->addWidget(doubleparam);
662             m_valueItems[paramName] = doubleparam;
663             connect(doubleparam, SIGNAL(valueChanged(double)), this, SLOT(slotCollectAllParameters()));
664             connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
665         } else if (type == "list") {
666             Listval *lsval = new Listval;
667             lsval->setupUi(toFillin);
668             lsval->list->setFocusPolicy(Qt::StrongFocus);
669             QStringList listitems = pa.attribute("paramlist").split(';');
670             if (listitems.count() == 1) {
671                 // probably custom effect created before change to ';' as separator
672                 listitems = pa.attribute("paramlist").split(",");
673             }
674             QDomElement list = pa.firstChildElement("paramlistdisplay");
675             QStringList listitemsdisplay;
676             if (!list.isNull()) {
677                 listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
678             } else {
679                 listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
680             }
681             if (listitemsdisplay.count() != listitems.count())
682                 listitemsdisplay = listitems;
683             lsval->list->setIconSize(QSize(30, 30));
684             for (int i = 0; i < listitems.count(); i++) {
685                 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
686                 QString entry = listitems.at(i);
687                 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
688                     if (!CollapsibleEffect::iconCache.contains(entry)) {
689                         QImage pix(entry);
690                         CollapsibleEffect::iconCache[entry] = pix.scaled(30, 30);
691                     }
692                     lsval->list->setItemIcon(i, QPixmap::fromImage(CollapsibleEffect::iconCache[entry]));
693                 }
694             }
695             if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
696             lsval->name->setText(paramName);
697             lsval->labelComment->setText(comment);
698             lsval->widgetComment->setHidden(true);
699             m_valueItems[paramName] = lsval;
700             connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(slotCollectAllParameters()));
701             if (!comment.isEmpty())
702                 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
703             m_uiItems.append(lsval);
704         } else if (type == "bool") {
705             Boolval *bval = new Boolval;
706             bval->setupUi(toFillin);
707             bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
708             bval->name->setText(paramName);
709             bval->labelComment->setText(comment);
710             bval->widgetComment->setHidden(true);
711             m_valueItems[paramName] = bval;
712             connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(slotCollectAllParameters()));
713             if (!comment.isEmpty())
714                 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
715             m_uiItems.append(bval);
716         } else if (type == "complex") {
717             ComplexParameter *pl = new ComplexParameter;
718             pl->setupParam(effect, pa.attribute("name"), 0, 100);
719             m_vbox->addWidget(pl);
720             m_valueItems[paramName+"complex"] = pl;
721             connect(pl, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
722         } else if (type == "geometry") {
723             if (KdenliveSettings::on_monitor_effects()) {
724                 m_geometryWidget = new GeometryWidget(m_metaInfo->monitor, m_metaInfo->timecode, 0, true, effect.hasAttribute("showrotation"), parent);
725                 m_geometryWidget->setFrameSize(m_metaInfo->frameSize);
726                 m_geometryWidget->slotShowScene(!disable);
727                 // connect this before setupParam to make sure the monitor scene shows up at startup
728                 connect(m_geometryWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
729                 connect(m_geometryWidget, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
730                 if (minFrame == maxFrame)
731                     m_geometryWidget->setupParam(pa, m_in, m_out);
732                 else
733                     m_geometryWidget->setupParam(pa, minFrame, maxFrame);
734                 m_vbox->addWidget(m_geometryWidget);
735                 m_valueItems[paramName+"geometry"] = m_geometryWidget;
736                 connect(m_geometryWidget, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
737                 connect(this, SIGNAL(syncEffectsPos(int)), m_geometryWidget, SLOT(slotSyncPosition(int)));
738                 connect(this, SIGNAL(effectStateChanged(bool)), m_geometryWidget, SLOT(slotShowScene(bool)));
739             } else {
740                 Geometryval *geo = new Geometryval(m_metaInfo->profile, m_metaInfo->timecode, m_metaInfo->frameSize, 0);
741                 if (minFrame == maxFrame)
742                     geo->setupParam(pa, m_in, m_out);
743                 else
744                     geo->setupParam(pa, minFrame, maxFrame);
745                 m_vbox->addWidget(geo);
746                 m_valueItems[paramName+"geometry"] = geo;
747                 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
748                 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
749                 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
750             }
751         } else if (type == "addedgeometry") {
752             // this is a parameter that should be linked to the geometry widget, for example rotation, shear, ...
753             if (m_geometryWidget) m_geometryWidget->addParameter(pa);
754         } else if (type == "keyframe" || type == "simplekeyframe") {
755             // keyframe editor widget
756             if (m_keyframeEditor == NULL) {
757                 KeyframeEdit *geo;
758                 if (pa.attribute("widget") == "corners") {
759                     // we want a corners-keyframe-widget
760                     CornersWidget *corners = new CornersWidget(m_metaInfo->monitor, pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt(), parent);
761                     corners->slotShowScene(!disable);
762                     connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
763                     connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
764                     connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
765                     geo = static_cast<KeyframeEdit *>(corners);
766                 } else {
767                     geo = new KeyframeEdit(pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt());
768                 }
769                 m_vbox->addWidget(geo);
770                 m_valueItems[paramName+"keyframe"] = geo;
771                 m_keyframeEditor = geo;
772                 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
773                 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
774                 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
775             } else {
776                 // we already have a keyframe editor, so just add another column for the new param
777                 m_keyframeEditor->addParameter(pa);
778             }
779         } else if (type == "color") {
780             if (value.startsWith('#'))
781                 value = value.replace('#', "0x");
782             ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, value, parent);
783             m_vbox->addWidget(choosecolor);
784             m_valueItems[paramName] = choosecolor;
785             connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
786             connect(choosecolor, SIGNAL(modified()) , this, SLOT(slotCollectAllParameters()));
787         } else if (type == "position") {
788             int pos = value.toInt();
789             if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
790                 pos = pos - m_in;
791             } else if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
792                 // fadeout position starts from clip end
793                 pos = m_out - pos;
794             }
795             PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_metaInfo->timecode);
796             m_vbox->addWidget(posedit);
797             m_valueItems[paramName+"position"] = posedit;
798             connect(posedit, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
799         } else if (type == "curve") {
800             KisCurveWidget *curve = new KisCurveWidget(parent);
801             curve->setMaxPoints(pa.attribute("max").toInt());
802             QList<QPointF> points;
803             int number = EffectsList::parameter(e, pa.attribute("number")).toInt();
804             QString inName = pa.attribute("inpoints");
805             QString outName = pa.attribute("outpoints");
806             int start = pa.attribute("min").toInt();
807             for (int j = start; j <= number; j++) {
808                 QString in = inName;
809                 in.replace("%i", QString::number(j));
810                 QString out = outName;
811                 out.replace("%i", QString::number(j));
812                 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
813             }
814             if (!points.isEmpty())
815                 curve->setCurve(KisCubicCurve(points));
816             MySpinBox *spinin = new MySpinBox();
817             spinin->setRange(0, 1000);
818             MySpinBox *spinout = new MySpinBox();
819             spinout->setRange(0, 1000);
820             curve->setupInOutControls(spinin, spinout, 0, 1000);
821             m_vbox->addWidget(curve);
822             m_vbox->addWidget(spinin);
823             m_vbox->addWidget(spinout);
824
825             connect(curve, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
826             m_valueItems[paramName] = curve;
827
828             QString depends = pa.attribute("depends");
829             if (!depends.isEmpty())
830                 meetDependency(paramName, type, EffectsList::parameter(e, depends));
831         } else if (type == "bezier_spline") {
832             BezierSplineWidget *widget = new BezierSplineWidget(value, parent);
833             stretch = false;
834             m_vbox->addWidget(widget);
835             m_valueItems[paramName] = widget;
836             connect(widget, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
837             QString depends = pa.attribute("depends");
838             if (!depends.isEmpty())
839                 meetDependency(paramName, type, EffectsList::parameter(e, depends));
840 #ifdef USE_QJSON
841         } else if (type == "roto-spline") {
842             RotoWidget *roto = new RotoWidget(value, m_metaInfo->monitor, info, m_metaInfo->timecode, parent);
843             roto->slotShowScene(!disable);
844             connect(roto, SIGNAL(valueChanged()), this, SLOT(slotCollectAllParameters()));
845             connect(roto, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
846             connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
847             connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
848             connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
849             m_vbox->addWidget(roto);
850             m_valueItems[paramName] = roto;
851 #endif
852         } else if (type == "wipe") {
853             Wipeval *wpval = new Wipeval;
854             wpval->setupUi(toFillin);
855             wipeInfo w = getWipeInfo(value);
856             switch (w.start) {
857             case UP:
858                 wpval->start_up->setChecked(true);
859                 break;
860             case DOWN:
861                 wpval->start_down->setChecked(true);
862                 break;
863             case RIGHT:
864                 wpval->start_right->setChecked(true);
865                 break;
866             case LEFT:
867                 wpval->start_left->setChecked(true);
868                 break;
869             default:
870                 wpval->start_center->setChecked(true);
871                 break;
872             }
873             switch (w.end) {
874             case UP:
875                 wpval->end_up->setChecked(true);
876                 break;
877             case DOWN:
878                 wpval->end_down->setChecked(true);
879                 break;
880             case RIGHT:
881                 wpval->end_right->setChecked(true);
882                 break;
883             case LEFT:
884                 wpval->end_left->setChecked(true);
885                 break;
886             default:
887                 wpval->end_center->setChecked(true);
888                 break;
889             }
890             wpval->start_transp->setValue(w.startTransparency);
891             wpval->end_transp->setValue(w.endTransparency);
892             m_valueItems[paramName] = wpval;
893             connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
894             connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
895             connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
896             connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
897             connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
898             connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
899             connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
900             connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
901             connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
902             connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
903             connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
904             connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
905             //wpval->title->setTitle(na.toElement().text());
906             m_uiItems.append(wpval);
907         } else if (type == "url") {
908             Urlval *cval = new Urlval;
909             cval->setupUi(toFillin);
910             cval->label->setText(paramName);
911             cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
912             m_valueItems[paramName] = cval;
913             cval->urlwidget->setUrl(KUrl(value));
914             connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(slotCollectAllParameters()));
915             connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(slotCollectAllParameters()));
916             m_uiItems.append(cval);
917         } else if (type == "keywords") {
918             Keywordval* kval = new Keywordval;
919             kval->setupUi(toFillin);
920             kval->label->setText(paramName);
921             kval->lineeditwidget->setText(value);
922             QDomElement klistelem = pa.firstChildElement("keywords");
923             QDomElement kdisplaylistelem = pa.firstChildElement("keywordsdisplay");
924             QStringList keywordlist;
925             QStringList keyworddisplaylist;
926             if (!klistelem.isNull()) {
927                 keywordlist = klistelem.text().split(';');
928                 keyworddisplaylist = i18n(kdisplaylistelem.text().toUtf8().data()).split(';');
929             }
930             if (keyworddisplaylist.count() != keywordlist.count()) {
931                 keyworddisplaylist = keywordlist;
932             }
933             for (int i = 0; i < keywordlist.count(); i++) {
934                 kval->comboboxwidget->addItem(keyworddisplaylist.at(i), keywordlist.at(i));
935             }
936             // Add disabled user prompt at index 0
937             kval->comboboxwidget->insertItem(0, i18n("<select a keyword>"), "");
938             kval->comboboxwidget->model()->setData( kval->comboboxwidget->model()->index(0,0), QVariant(Qt::NoItemFlags), Qt::UserRole -1);
939             kval->comboboxwidget->setCurrentIndex(0);
940             m_valueItems[paramName] = kval;
941             connect(kval->lineeditwidget, SIGNAL(editingFinished()) , this, SLOT(collectAllParameters()));
942             connect(kval->comboboxwidget, SIGNAL(activated (const QString&)), this, SLOT(collectAllParameters()));
943             m_uiItems.append(kval);
944         } else if (type == "fontfamily") {
945             Fontval* fval = new Fontval;
946             fval->setupUi(toFillin);
947             fval->name->setText(paramName);
948             fval->fontfamilywidget->setCurrentFont(QFont(value));
949             m_valueItems[paramName] = fval;
950             connect(fval->fontfamilywidget, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(collectAllParameters())) ;
951             m_uiItems.append(fval);
952         } else if (type == "filterjob") {
953             QVBoxLayout *l= new QVBoxLayout(toFillin);
954             QPushButton *button = new QPushButton(paramName, toFillin);
955             l->addWidget(button);
956             m_valueItems[paramName] = button;
957             connect(button, SIGNAL(pressed()), this, SLOT(slotStartFilterJobAction()));   
958         } else {
959             delete toFillin;
960             toFillin = NULL;
961         }
962
963         if (toFillin)
964             m_vbox->addWidget(toFillin);
965     }
966
967     if (stretch)
968         m_vbox->addStretch();
969
970     if (m_keyframeEditor)
971         m_keyframeEditor->checkVisibleParam();
972
973     // Make sure all doubleparam spinboxes have the same width, looks much better
974     QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
975     int minSize = 0;
976     for (int i = 0; i < allWidgets.count(); i++) {
977         if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
978     }
979     for (int i = 0; i < allWidgets.count(); i++) {
980         allWidgets.at(i)->setSpinSize(minSize);
981     }
982 }
983
984 ParameterContainer::~ParameterContainer()
985 {
986     //clearLayout(m_vbox);
987     delete m_vbox;
988 }
989
990 void ParameterContainer::meetDependency(const QString& name, QString type, QString value)
991 {
992     if (type == "curve") {
993         KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
994         if (curve) {
995             int color = value.toInt();
996             curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
997         }
998     } else if (type == "bezier_spline") {
999         BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
1000         if (widget) {
1001             widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10)));
1002         }
1003     }
1004 }
1005
1006 wipeInfo ParameterContainer::getWipeInfo(QString value)
1007 {
1008     wipeInfo info;
1009     // Convert old geometry values that used a comma as separator
1010     if (value.contains(',')) value.replace(',','/');
1011     QString start = value.section(';', 0, 0);
1012     QString end = value.section(';', 1, 1).section('=', 1, 1);
1013     if (start.startsWith("-100%/0"))
1014         info.start = LEFT;
1015     else if (start.startsWith("100%/0"))
1016         info.start = RIGHT;
1017     else if (start.startsWith("0%/100%"))
1018         info.start = DOWN;
1019     else if (start.startsWith("0%/-100%"))
1020         info.start = UP;
1021     else
1022         info.start = CENTER;
1023
1024     if (start.count(':') == 2)
1025         info.startTransparency = start.section(':', -1).toInt();
1026     else
1027         info.startTransparency = 100;
1028
1029     if (end.startsWith("-100%/0"))
1030         info.end = LEFT;
1031     else if (end.startsWith("100%/0"))
1032         info.end = RIGHT;
1033     else if (end.startsWith("0%/100%"))
1034         info.end = DOWN;
1035     else if (end.startsWith("0%/-100%"))
1036         info.end = UP;
1037     else
1038         info.end = CENTER;
1039
1040     if (end.count(':') == 2)
1041         info.endTransparency = end.section(':', -1).toInt();
1042     else
1043         info.endTransparency = 100;
1044
1045     return info;
1046 }
1047
1048 void ParameterContainer::updateTimecodeFormat()
1049 {
1050     if (m_keyframeEditor)
1051         m_keyframeEditor->updateTimecodeFormat();
1052
1053     QDomNodeList namenode = m_effect.elementsByTagName("parameter");
1054     for (int i = 0; i < namenode.count() ; i++) {
1055         QDomNode pa = namenode.item(i);
1056         QDomElement na = pa.firstChildElement("name");
1057         QString type = pa.attributes().namedItem("type").nodeValue();
1058         QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
1059
1060         if (type == "geometry") {
1061             if (KdenliveSettings::on_monitor_effects()) {
1062                 if (m_geometryWidget) m_geometryWidget->updateTimecodeFormat();
1063             } else {
1064                 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
1065                 geom->updateTimecodeFormat();
1066             }
1067             break;
1068         } else if (type == "position") {
1069             PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
1070             posi->updateTimecodeFormat();
1071             break;
1072 #ifdef USE_QJSON
1073         } else if (type == "roto-spline") {
1074             RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems[paramName]);
1075             widget->updateTimecodeFormat();
1076 #endif
1077         }
1078     }
1079 }
1080
1081 void ParameterContainer::slotCollectAllParameters()
1082 {
1083     if (m_valueItems.isEmpty() || m_effect.isNull()) return;
1084     QLocale locale;
1085     locale.setNumberOptions(QLocale::OmitGroupSeparator);
1086     const QDomElement oldparam = m_effect.cloneNode().toElement();
1087     //QDomElement newparam = oldparam.cloneNode().toElement();
1088     QDomNodeList namenode = m_effect.elementsByTagName("parameter");
1089
1090     for (int i = 0; i < namenode.count() ; i++) {
1091         QDomNode pa = namenode.item(i);
1092         QDomElement na = pa.firstChildElement("name");
1093         QString type = pa.attributes().namedItem("type").nodeValue();
1094         QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
1095         if (type == "complex")
1096             paramName.append("complex");
1097         else if (type == "position")
1098             paramName.append("position");
1099         else if (type == "geometry")
1100             paramName.append("geometry");
1101         else if (type == "keyframe")
1102             paramName.append("keyframe");
1103         if (type != "simplekeyframe" && type != "fixed" && type != "addedgeometry" && !m_valueItems.contains(paramName)) {
1104             kDebug() << "// Param: " << paramName << " NOT FOUND";
1105             continue;
1106         }
1107
1108         QString setValue;
1109         if (type == "double" || type == "constant") {
1110             DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
1111             setValue = locale.toString(doubleparam->getValue());
1112         } else if (type == "list") {
1113             KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
1114             setValue = box->itemData(box->currentIndex()).toString();
1115         } else if (type == "bool") {
1116             QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
1117             setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
1118         } else if (type == "color") {
1119             ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
1120             setValue = choosecolor->getColor();
1121         } else if (type == "complex") {
1122             ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
1123             namenode.item(i) = complex->getParamDesc();
1124         } else if (type == "geometry") {
1125             if (KdenliveSettings::on_monitor_effects()) {
1126                 if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getValue());
1127             } else {
1128                 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
1129                 namenode.item(i).toElement().setAttribute("value", geom->getValue());
1130             }
1131         } else if (type == "addedgeometry") {
1132             namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getExtraValue(namenode.item(i).toElement().attribute("name")));
1133         } else if (type == "position") {
1134             PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
1135             int pos = pedit->getPosition();
1136             setValue = QString::number(pos);
1137             if (m_effect.attribute("id") == "fadein" || m_effect.attribute("id") == "fade_from_black") {
1138                 // Make sure duration is not longer than clip
1139                 /*if (pos > m_out) {
1140                     pos = m_out;
1141                     pedit->setPosition(pos);
1142                 }*/
1143                 EffectsList::setParameter(m_effect, "in", QString::number(m_in));
1144                 EffectsList::setParameter(m_effect, "out", QString::number(m_in + pos));
1145                 setValue.clear();
1146             } else if (m_effect.attribute("id") == "fadeout" || m_effect.attribute("id") == "fade_to_black") {
1147                 // Make sure duration is not longer than clip
1148                 /*if (pos > m_out) {
1149                     pos = m_out;
1150                     pedit->setPosition(pos);
1151                 }*/
1152                 EffectsList::setParameter(m_effect, "in", QString::number(m_out - pos));
1153                 EffectsList::setParameter(m_effect, "out", QString::number(m_out));
1154                 setValue.clear();
1155             }
1156         } else if (type == "curve") {
1157             KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
1158             QList<QPointF> points = curve->curve().points();
1159             QString number = pa.attributes().namedItem("number").nodeValue();
1160             QString inName = pa.attributes().namedItem("inpoints").nodeValue();
1161             QString outName = pa.attributes().namedItem("outpoints").nodeValue();
1162             int off = pa.attributes().namedItem("min").nodeValue().toInt();
1163             int end = pa.attributes().namedItem("max").nodeValue().toInt();
1164             EffectsList::setParameter(m_effect, number, QString::number(points.count()));
1165             for (int j = 0; (j < points.count() && j + off <= end); j++) {
1166                 QString in = inName;
1167                 in.replace("%i", QString::number(j + off));
1168                 QString out = outName;
1169                 out.replace("%i", QString::number(j + off));
1170                 EffectsList::setParameter(m_effect, in, locale.toString(points.at(j).x()));
1171                 EffectsList::setParameter(m_effect, out, locale.toString(points.at(j).y()));
1172             }
1173             QString depends = pa.attributes().namedItem("depends").nodeValue();
1174             if (!depends.isEmpty())
1175                 meetDependency(paramName, type, EffectsList::parameter(m_effect, depends));
1176         } else if (type == "bezier_spline") {
1177             BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
1178             setValue = widget->spline();
1179             QString depends = pa.attributes().namedItem("depends").nodeValue();
1180             if (!depends.isEmpty())
1181                 meetDependency(paramName, type, EffectsList::parameter(m_effect, depends));
1182 #ifdef USE_QJSON
1183         } else if (type == "roto-spline") {
1184             RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
1185             setValue = widget->getSpline();
1186 #endif
1187         } else if (type == "wipe") {
1188             Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
1189             wipeInfo info;
1190             if (wp->start_left->isChecked())
1191                 info.start = LEFT;
1192             else if (wp->start_right->isChecked())
1193                 info.start = RIGHT;
1194             else if (wp->start_up->isChecked())
1195                 info.start = UP;
1196             else if (wp->start_down->isChecked())
1197                 info.start = DOWN;
1198             else if (wp->start_center->isChecked())
1199                 info.start = CENTER;
1200             else
1201                 info.start = LEFT;
1202             info.startTransparency = wp->start_transp->value();
1203
1204             if (wp->end_left->isChecked())
1205                 info.end = LEFT;
1206             else if (wp->end_right->isChecked())
1207                 info.end = RIGHT;
1208             else if (wp->end_up->isChecked())
1209                 info.end = UP;
1210             else if (wp->end_down->isChecked())
1211                 info.end = DOWN;
1212             else if (wp->end_center->isChecked())
1213                 info.end = CENTER;
1214             else
1215                 info.end = RIGHT;
1216             info.endTransparency = wp->end_transp->value();
1217
1218             setValue = getWipeString(info);
1219         } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
1220             QDomElement elem = pa.toElement();
1221             QString realName = i18n(na.toElement().text().toUtf8().data());
1222             QString val = m_keyframeEditor->getValue(realName);
1223             elem.setAttribute("keyframes", val);
1224
1225             if (m_keyframeEditor->isVisibleParam(realName))
1226                 elem.setAttribute("intimeline", "1");
1227             else if (elem.hasAttribute("intimeline"))
1228                 elem.removeAttribute("intimeline");
1229         } else if (type == "url") {
1230             KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
1231             setValue = req->url().path();
1232         } else if (type == "keywords"){
1233             QLineEdit *line = ((Keywordval*)m_valueItems.value(paramName))->lineeditwidget;
1234             QComboBox *combo = ((Keywordval*)m_valueItems.value(paramName))->comboboxwidget;
1235             if(combo->currentIndex())
1236             {
1237                 QString comboval = combo->itemData(combo->currentIndex()).toString();
1238                 line->insert(comboval);
1239                 combo->setCurrentIndex(0);
1240             }
1241             setValue = line->text();
1242         } else if (type == "fontfamily") {
1243             QFontComboBox* fontfamily = ((Fontval*)m_valueItems.value(paramName))->fontfamilywidget;
1244             setValue = fontfamily->currentFont().family();
1245         }
1246         if (!setValue.isNull())
1247             pa.attributes().namedItem("value").setNodeValue(setValue);
1248
1249     }
1250     emit parameterChanged(oldparam, m_effect, m_index);
1251 }
1252
1253 QString ParameterContainer::getWipeString(wipeInfo info)
1254 {
1255
1256     QString start;
1257     QString end;
1258     switch (info.start) {
1259     case LEFT:
1260         start = "-100%/0%:100%x100%";
1261         break;
1262     case RIGHT:
1263         start = "100%/0%:100%x100%";
1264         break;
1265     case DOWN:
1266         start = "0%/100%:100%x100%";
1267         break;
1268     case UP:
1269         start = "0%/-100%:100%x100%";
1270         break;
1271     default:
1272         start = "0%/0%:100%x100%";
1273         break;
1274     }
1275     start.append(':' + QString::number(info.startTransparency));
1276
1277     switch (info.end) {
1278     case LEFT:
1279         end = "-100%/0%:100%x100%";
1280         break;
1281     case RIGHT:
1282         end = "100%/0%:100%x100%";
1283         break;
1284     case DOWN:
1285         end = "0%/100%:100%x100%";
1286         break;
1287     case UP:
1288         end = "0%/-100%:100%x100%";
1289         break;
1290     default:
1291         end = "0%/0%:100%x100%";
1292         break;
1293     }
1294     end.append(':' + QString::number(info.endTransparency));
1295     return QString(start + ";-1=" + end);
1296 }
1297
1298 int ParameterContainer::index() const
1299 {
1300     return m_index;
1301 }
1302
1303 void ParameterContainer::slotStartFilterJobAction()
1304 {
1305     QDomNodeList namenode = m_effect.elementsByTagName("parameter");
1306     for (int i = 0; i < namenode.count() ; i++) {
1307         QDomElement pa = namenode.item(i).toElement();
1308         QString type = pa.attribute("type");
1309         if (type == "filterjob") {
1310             emit startFilterJob(pa.attribute("filtertag"), pa.attribute("filterparams"), pa.attribute("finalfilter"), pa.attribute("consumer"), pa.attribute("consumerparams"), pa.attribute("wantedproperties"));
1311             kDebug()<<" - - -PROPS:\n"<<pa.attribute("filtertag")<<"-"<< pa.attribute("filterparams")<<"-"<< pa.attribute("consumer")<<"-"<< pa.attribute("consumerparams")<<"-"<< pa.attribute("wantedproperties");
1312             break;
1313         }
1314     }
1315 }
1316