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