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