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