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