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