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