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