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