]> git.sesse.net Git - kdenlive/blob - src/effectstack/collapsibleeffect.cpp
Cleanup effect stack stylesheet
[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     m_effect.setAttribute("kdenlive_info", m_info.toString());
432     emit parameterChanged(m_original_effect, m_effect, effectIndex());
433 }
434
435 void CollapsibleEffect::setGroupIndex(int ix)
436 {
437     m_info.groupIndex = ix;
438 }
439
440 void CollapsibleEffect::setGroupName(const QString &groupName)
441 {
442     m_info.groupName = groupName;
443 }
444
445 QString CollapsibleEffect::infoString() const
446 {
447     return m_info.toString();
448 }
449
450 void CollapsibleEffect::removeGroup(int ix, QVBoxLayout *layout)
451 {
452     QVBoxLayout *vbox = static_cast<QVBoxLayout *>(widgetFrame->layout());
453     if (vbox == NULL) return;
454     
455     for (int j = vbox->count() - 1; j >= 0; j--) {
456         QLayoutItem *child = vbox->takeAt(j);
457         CollapsibleEffect *e = static_cast<CollapsibleEffect *>(child->widget());
458         layout->insertWidget(ix, e);
459         e->updateGroupIndex(-1);
460         delete child;
461     }
462 }
463
464 int CollapsibleEffect::groupIndex() const
465 {
466     return m_info.groupIndex;
467 }
468
469 int CollapsibleEffect::effectIndex() const
470 {
471     if (m_effect.isNull()) return -1;
472     return m_effect.attribute("kdenlive_ix").toInt();
473 }
474
475 void CollapsibleEffect::updateWidget(ItemInfo info, QDomElement effect, EffectMetaInfo *metaInfo)
476 {
477     if (m_paramWidget) {
478         // cleanup
479         delete m_paramWidget;
480         m_paramWidget = NULL;
481     }
482     m_effect = effect;
483     setupWidget(info, metaInfo);
484 }
485
486 void CollapsibleEffect::setupWidget(ItemInfo info, EffectMetaInfo *metaInfo)
487 {
488     if (m_effect.isNull()) {
489 //         kDebug() << "// EMPTY EFFECT STACK";
490         return;
491     }
492
493     if (m_effect.attribute("tag") == "region") {
494         QVBoxLayout *vbox = new QVBoxLayout(widgetFrame);
495         vbox->setContentsMargins(2, 0, 2, 0);
496         vbox->setSpacing(2);
497         QDomNodeList effects =  m_effect.elementsByTagName("effect");
498         QDomNodeList origin_effects =  m_original_effect.elementsByTagName("effect");
499         QWidget *container = new QWidget(widgetFrame);
500         vbox->addWidget(container);
501         m_paramWidget = new ParameterContainer(m_effect.toElement(), info, metaInfo, container);
502         for (int i = 0; i < effects.count(); i++) {
503             CollapsibleEffect *coll = new CollapsibleEffect(effects.at(i).toElement(), origin_effects.at(i).toElement(), info, metaInfo, container);
504             m_subParamWidgets.append(coll);
505             //container = new QWidget(widgetFrame);
506             vbox->addWidget(coll);
507             //p = new ParameterContainer(effects.at(i).toElement(), info, isEffect, container);
508         }
509         
510     }
511     else {
512         m_paramWidget = new ParameterContainer(m_effect, info, metaInfo, widgetFrame);
513         if (m_effect.firstChildElement("parameter").isNull()) {
514             // Effect has no parameter, don't allow expand
515             collapseButton->setEnabled(false);
516             collapseButton->setVisible(false);
517             widgetFrame->setVisible(false);            
518         }
519     }
520     if (collapseButton->isEnabled() && m_info.isCollapsed) {
521         widgetFrame->setVisible(false);
522         collapseButton->setArrowType(Qt::RightArrow);
523         
524     }
525     connect (m_paramWidget, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)));
526     
527     connect(m_paramWidget, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)));
528     
529     connect (this, SIGNAL(syncEffectsPos(int)), m_paramWidget, SIGNAL(syncEffectsPos(int)));
530     connect (this, SIGNAL(effectStateChanged(bool)), m_paramWidget, SIGNAL(effectStateChanged(bool)));
531     connect (m_paramWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
532     connect (m_paramWidget, SIGNAL(seekTimeline(int)), this, SIGNAL(seekTimeline(int)));
533     
534     
535 }
536
537 bool CollapsibleEffect::isGroup() const
538 {
539     return false;
540 }
541
542 void CollapsibleEffect::updateTimecodeFormat()
543 {
544     m_paramWidget->updateTimecodeFormat();
545     if (!m_subParamWidgets.isEmpty()) {
546         // we have a group
547         for (int i = 0; i < m_subParamWidgets.count(); i++)
548             m_subParamWidgets.at(i)->updateTimecodeFormat();
549     }
550 }
551
552 void CollapsibleEffect::slotSyncEffectsPos(int pos)
553 {
554     emit syncEffectsPos(pos);
555 }
556
557 void CollapsibleEffect::dragEnterEvent(QDragEnterEvent *event)
558 {
559     if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
560         frame->setProperty("active", true);
561         frame->setStyleSheet(frame->styleSheet());
562         event->acceptProposedAction();
563     }
564 }
565
566 void CollapsibleEffect::dragLeaveEvent(QDragLeaveEvent */*event*/)
567 {
568     frame->setProperty("active", false);
569     frame->setStyleSheet(frame->styleSheet());
570 }
571
572 void CollapsibleEffect::dropEvent(QDropEvent *event)
573 {
574     frame->setProperty("active", false);
575     frame->setStyleSheet(frame->styleSheet());
576     const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
577     //event->acceptProposedAction();
578     QDomDocument doc;
579     doc.setContent(effects, true);
580     QDomElement e = doc.documentElement();
581     int ix = e.attribute("kdenlive_ix").toInt();
582     if (ix == effectIndex()) {
583         // effect dropped on itself, reject
584         event->ignore();
585         return;
586     }
587     if (ix == 0) {
588         // effect dropped from effects list, add it
589         e.setAttribute("kdenlive_ix", ix);
590         event->setDropAction(Qt::CopyAction);
591         event->accept();
592         emit addEffect(e);
593         return;
594     }
595     emit moveEffect(ix, effectIndex(), groupIndex());
596     event->setDropAction(Qt::MoveAction);
597     event->accept();
598 }
599
600 ParameterContainer::ParameterContainer(QDomElement effect, ItemInfo info, EffectMetaInfo *metaInfo, QWidget * parent) :
601         m_keyframeEditor(NULL),
602         m_geometryWidget(NULL),
603         m_metaInfo(metaInfo),
604         m_effect(effect)
605 {
606     m_in = info.cropStart.frames(KdenliveSettings::project_fps());
607     m_out = (info.cropStart + info.cropDuration).frames(KdenliveSettings::project_fps()) - 1;
608
609     QDomNodeList namenode = effect.childNodes(); //elementsByTagName("parameter");
610     
611     QDomElement e = effect.toElement();
612     int minFrame = e.attribute("start").toInt();
613     int maxFrame = e.attribute("end").toInt();
614     // In transitions, maxFrame is in fact one frame after the end of transition
615     if (maxFrame > 0) maxFrame --;
616
617     bool disable = effect.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
618     parent->setEnabled(!disable);
619
620     bool stretch = true;
621     m_vbox = new QVBoxLayout(parent);
622     m_vbox->setContentsMargins(2, 0, 2, 0);
623     m_vbox->setSpacing(2);
624
625     for (int i = 0; i < namenode.count() ; i++) {
626         QDomElement pa = namenode.item(i).toElement();
627         if (pa.tagName() != "parameter") continue;
628         QDomElement na = pa.firstChildElement("name");
629         QDomElement commentElem = pa.firstChildElement("comment");
630         QString type = pa.attribute("type");
631         QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
632         QString comment;
633         if (!commentElem.isNull())
634             comment = i18n(commentElem.text().toUtf8().data());
635         QWidget * toFillin = new QWidget(parent);
636         QString value = pa.attribute("value").isNull() ?
637                         pa.attribute("default") : pa.attribute("value");
638
639
640         /** See effects/README for info on the different types */
641
642         if (type == "double" || type == "constant") {
643             double min;
644             double max;
645             if (pa.attribute("min").contains('%'))
646                 min = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("min"), m_metaInfo->frameSize);
647             else
648                 min = pa.attribute("min").toDouble();
649             if (pa.attribute("max").contains('%'))
650                 max = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("max"), m_metaInfo->frameSize);
651             else
652                 max = pa.attribute("max").toDouble();
653
654             DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, value.toDouble(), min, max,
655                     pa.attribute("default").toDouble(), comment, -1, pa.attribute("suffix"), pa.attribute("decimals").toInt(), parent);
656             doubleparam->setFocusPolicy(Qt::StrongFocus);
657             m_vbox->addWidget(doubleparam);
658             m_valueItems[paramName] = doubleparam;
659             connect(doubleparam, SIGNAL(valueChanged(double)), this, SLOT(slotCollectAllParameters()));
660             connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
661         } else if (type == "list") {
662             Listval *lsval = new Listval;
663             lsval->setupUi(toFillin);
664             lsval->list->setFocusPolicy(Qt::StrongFocus);
665             QStringList listitems = pa.attribute("paramlist").split(';');
666             if (listitems.count() == 1) {
667                 // probably custom effect created before change to ';' as separator
668                 listitems = pa.attribute("paramlist").split(",");
669             }
670             QDomElement list = pa.firstChildElement("paramlistdisplay");
671             QStringList listitemsdisplay;
672             if (!list.isNull()) {
673                 listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
674             } else {
675                 listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
676             }
677             if (listitemsdisplay.count() != listitems.count())
678                 listitemsdisplay = listitems;
679             lsval->list->setIconSize(QSize(30, 30));
680             for (int i = 0; i < listitems.count(); i++) {
681                 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
682                 QString entry = listitems.at(i);
683                 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
684                     if (!CollapsibleEffect::iconCache.contains(entry)) {
685                         QImage pix(entry);
686                         CollapsibleEffect::iconCache[entry] = pix.scaled(30, 30);
687                     }
688                     lsval->list->setItemIcon(i, QPixmap::fromImage(CollapsibleEffect::iconCache[entry]));
689                 }
690             }
691             if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
692             lsval->name->setText(paramName);
693             lsval->labelComment->setText(comment);
694             lsval->widgetComment->setHidden(true);
695             m_valueItems[paramName] = lsval;
696             connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(slotCollectAllParameters()));
697             if (!comment.isEmpty())
698                 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
699             m_uiItems.append(lsval);
700         } else if (type == "bool") {
701             Boolval *bval = new Boolval;
702             bval->setupUi(toFillin);
703             bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
704             bval->name->setText(paramName);
705             bval->labelComment->setText(comment);
706             bval->widgetComment->setHidden(true);
707             m_valueItems[paramName] = bval;
708             connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(slotCollectAllParameters()));
709             if (!comment.isEmpty())
710                 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
711             m_uiItems.append(bval);
712         } else if (type == "complex") {
713             ComplexParameter *pl = new ComplexParameter;
714             pl->setupParam(effect, pa.attribute("name"), 0, 100);
715             m_vbox->addWidget(pl);
716             m_valueItems[paramName+"complex"] = pl;
717             connect(pl, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
718         } else if (type == "geometry") {
719             if (KdenliveSettings::on_monitor_effects()) {
720                 m_geometryWidget = new GeometryWidget(m_metaInfo->monitor, m_metaInfo->timecode, 0, true, effect.hasAttribute("showrotation"), parent);
721                 m_geometryWidget->setFrameSize(m_metaInfo->frameSize);
722                 m_geometryWidget->slotShowScene(!disable);
723                 // connect this before setupParam to make sure the monitor scene shows up at startup
724                 connect(m_geometryWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
725                 connect(m_geometryWidget, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
726                 if (minFrame == maxFrame)
727                     m_geometryWidget->setupParam(pa, m_in, m_out);
728                 else
729                     m_geometryWidget->setupParam(pa, minFrame, maxFrame);
730                 m_vbox->addWidget(m_geometryWidget);
731                 m_valueItems[paramName+"geometry"] = m_geometryWidget;
732                 connect(m_geometryWidget, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
733                 connect(this, SIGNAL(syncEffectsPos(int)), m_geometryWidget, SLOT(slotSyncPosition(int)));
734                 connect(this, SIGNAL(effectStateChanged(bool)), m_geometryWidget, SLOT(slotShowScene(bool)));
735             } else {
736                 Geometryval *geo = new Geometryval(m_metaInfo->profile, m_metaInfo->timecode, m_metaInfo->frameSize, 0);
737                 if (minFrame == maxFrame)
738                     geo->setupParam(pa, m_in, m_out);
739                 else
740                     geo->setupParam(pa, minFrame, maxFrame);
741                 m_vbox->addWidget(geo);
742                 m_valueItems[paramName+"geometry"] = geo;
743                 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
744                 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
745                 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
746             }
747         } else if (type == "addedgeometry") {
748             // this is a parameter that should be linked to the geometry widget, for example rotation, shear, ...
749             if (m_geometryWidget) m_geometryWidget->addParameter(pa);
750         } else if (type == "keyframe" || type == "simplekeyframe") {
751             // keyframe editor widget
752             if (m_keyframeEditor == NULL) {
753                 KeyframeEdit *geo;
754                 if (pa.attribute("widget") == "corners") {
755                     // we want a corners-keyframe-widget
756                     CornersWidget *corners = new CornersWidget(m_metaInfo->monitor, pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt(), parent);
757                     corners->slotShowScene(!disable);
758                     connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
759                     connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
760                     connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
761                     geo = static_cast<KeyframeEdit *>(corners);
762                 } else {
763                     geo = new KeyframeEdit(pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt());
764                 }
765                 m_vbox->addWidget(geo);
766                 m_valueItems[paramName+"keyframe"] = geo;
767                 m_keyframeEditor = geo;
768                 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
769                 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
770                 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
771             } else {
772                 // we already have a keyframe editor, so just add another column for the new param
773                 m_keyframeEditor->addParameter(pa);
774             }
775         } else if (type == "color") {
776             if (value.startsWith('#'))
777                 value = value.replace('#', "0x");
778             ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, value, parent);
779             m_vbox->addWidget(choosecolor);
780             m_valueItems[paramName] = choosecolor;
781             connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
782             connect(choosecolor, SIGNAL(modified()) , this, SLOT(slotCollectAllParameters()));
783         } else if (type == "position") {
784             int pos = value.toInt();
785             if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
786                 pos = pos - m_in;
787             } else if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
788                 // fadeout position starts from clip end
789                 pos = m_out - pos;
790             }
791             PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_metaInfo->timecode);
792             m_vbox->addWidget(posedit);
793             m_valueItems[paramName+"position"] = posedit;
794             connect(posedit, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
795         } else if (type == "curve") {
796             KisCurveWidget *curve = new KisCurveWidget(parent);
797             curve->setMaxPoints(pa.attribute("max").toInt());
798             QList<QPointF> points;
799             int number = EffectsList::parameter(e, pa.attribute("number")).toInt();
800             QString inName = pa.attribute("inpoints");
801             QString outName = pa.attribute("outpoints");
802             int start = pa.attribute("min").toInt();
803             for (int j = start; j <= number; j++) {
804                 QString in = inName;
805                 in.replace("%i", QString::number(j));
806                 QString out = outName;
807                 out.replace("%i", QString::number(j));
808                 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
809             }
810             if (!points.isEmpty())
811                 curve->setCurve(KisCubicCurve(points));
812             MySpinBox *spinin = new MySpinBox();
813             spinin->setRange(0, 1000);
814             MySpinBox *spinout = new MySpinBox();
815             spinout->setRange(0, 1000);
816             curve->setupInOutControls(spinin, spinout, 0, 1000);
817             m_vbox->addWidget(curve);
818             m_vbox->addWidget(spinin);
819             m_vbox->addWidget(spinout);
820
821             connect(curve, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
822             m_valueItems[paramName] = curve;
823
824             QString depends = pa.attribute("depends");
825             if (!depends.isEmpty())
826                 meetDependency(paramName, type, EffectsList::parameter(e, depends));
827         } else if (type == "bezier_spline") {
828             BezierSplineWidget *widget = new BezierSplineWidget(value, parent);
829             stretch = false;
830             m_vbox->addWidget(widget);
831             m_valueItems[paramName] = widget;
832             connect(widget, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
833             QString depends = pa.attribute("depends");
834             if (!depends.isEmpty())
835                 meetDependency(paramName, type, EffectsList::parameter(e, depends));
836 #ifdef USE_QJSON
837         } else if (type == "roto-spline") {
838             RotoWidget *roto = new RotoWidget(value, m_metaInfo->monitor, info, m_metaInfo->timecode, parent);
839             roto->slotShowScene(!disable);
840             connect(roto, SIGNAL(valueChanged()), this, SLOT(slotCollectAllParameters()));
841             connect(roto, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
842             connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
843             connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
844             connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
845             m_vbox->addWidget(roto);
846             m_valueItems[paramName] = roto;
847 #endif
848         } else if (type == "wipe") {
849             Wipeval *wpval = new Wipeval;
850             wpval->setupUi(toFillin);
851             wipeInfo w = getWipeInfo(value);
852             switch (w.start) {
853             case UP:
854                 wpval->start_up->setChecked(true);
855                 break;
856             case DOWN:
857                 wpval->start_down->setChecked(true);
858                 break;
859             case RIGHT:
860                 wpval->start_right->setChecked(true);
861                 break;
862             case LEFT:
863                 wpval->start_left->setChecked(true);
864                 break;
865             default:
866                 wpval->start_center->setChecked(true);
867                 break;
868             }
869             switch (w.end) {
870             case UP:
871                 wpval->end_up->setChecked(true);
872                 break;
873             case DOWN:
874                 wpval->end_down->setChecked(true);
875                 break;
876             case RIGHT:
877                 wpval->end_right->setChecked(true);
878                 break;
879             case LEFT:
880                 wpval->end_left->setChecked(true);
881                 break;
882             default:
883                 wpval->end_center->setChecked(true);
884                 break;
885             }
886             wpval->start_transp->setValue(w.startTransparency);
887             wpval->end_transp->setValue(w.endTransparency);
888             m_valueItems[paramName] = wpval;
889             connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
890             connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
891             connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
892             connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
893             connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
894             connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
895             connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
896             connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
897             connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
898             connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
899             connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
900             connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
901             //wpval->title->setTitle(na.toElement().text());
902             m_uiItems.append(wpval);
903         } else if (type == "url") {
904             Urlval *cval = new Urlval;
905             cval->setupUi(toFillin);
906             cval->label->setText(paramName);
907             cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
908             m_valueItems[paramName] = cval;
909             cval->urlwidget->setUrl(KUrl(value));
910             connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(slotCollectAllParameters()));
911             connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(slotCollectAllParameters()));
912             m_uiItems.append(cval);
913         } else if (type == "keywords") {
914             Keywordval* kval = new Keywordval;
915             kval->setupUi(toFillin);
916             kval->label->setText(paramName);
917             kval->lineeditwidget->setText(value);
918             QDomElement klistelem = pa.firstChildElement("keywords");
919             QDomElement kdisplaylistelem = pa.firstChildElement("keywordsdisplay");
920             QStringList keywordlist;
921             QStringList keyworddisplaylist;
922             if (!klistelem.isNull()) {
923                 keywordlist = klistelem.text().split(';');
924                 keyworddisplaylist = i18n(kdisplaylistelem.text().toUtf8().data()).split(';');
925             }
926             if (keyworddisplaylist.count() != keywordlist.count()) {
927                 keyworddisplaylist = keywordlist;
928             }
929             for (int i = 0; i < keywordlist.count(); i++) {
930                 kval->comboboxwidget->addItem(keyworddisplaylist.at(i), keywordlist.at(i));
931             }
932             // Add disabled user prompt at index 0
933             kval->comboboxwidget->insertItem(0, i18n("<select a keyword>"), "");
934             kval->comboboxwidget->model()->setData( kval->comboboxwidget->model()->index(0,0), QVariant(Qt::NoItemFlags), Qt::UserRole -1);
935             kval->comboboxwidget->setCurrentIndex(0);
936             m_valueItems[paramName] = kval;
937             connect(kval->lineeditwidget, SIGNAL(editingFinished()) , this, SLOT(collectAllParameters()));
938             connect(kval->comboboxwidget, SIGNAL(activated (const QString&)), this, SLOT(collectAllParameters()));
939             m_uiItems.append(kval);
940         } else if (type == "fontfamily") {
941             Fontval* fval = new Fontval;
942             fval->setupUi(toFillin);
943             fval->name->setText(paramName);
944             fval->fontfamilywidget->setCurrentFont(QFont(value));
945             m_valueItems[paramName] = fval;
946             connect(fval->fontfamilywidget, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(collectAllParameters())) ;
947             m_uiItems.append(fval);
948         } else if (type == "filterjob") {
949             QVBoxLayout *l= new QVBoxLayout(toFillin);
950             QPushButton *button = new QPushButton(paramName, toFillin);
951             l->addWidget(button);
952             m_valueItems[paramName] = button;
953             connect(button, SIGNAL(pressed()), this, SLOT(slotStartFilterJobAction()));   
954         } else {
955             delete toFillin;
956             toFillin = NULL;
957         }
958
959         if (toFillin)
960             m_vbox->addWidget(toFillin);
961     }
962
963     if (stretch)
964         m_vbox->addStretch();
965
966     if (m_keyframeEditor)
967         m_keyframeEditor->checkVisibleParam();
968
969     // Make sure all doubleparam spinboxes have the same width, looks much better
970     QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
971     int minSize = 0;
972     for (int i = 0; i < allWidgets.count(); i++) {
973         if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
974     }
975     for (int i = 0; i < allWidgets.count(); i++) {
976         allWidgets.at(i)->setSpinSize(minSize);
977     }
978 }
979
980 ParameterContainer::~ParameterContainer()
981 {
982     clearLayout(m_vbox);
983     delete m_vbox;
984 }
985
986 void ParameterContainer::meetDependency(const QString& name, QString type, QString value)
987 {
988     if (type == "curve") {
989         KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
990         if (curve) {
991             int color = value.toInt();
992             curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
993         }
994     } else if (type == "bezier_spline") {
995         BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
996         if (widget) {
997             widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10)));
998         }
999     }
1000 }
1001
1002 wipeInfo ParameterContainer::getWipeInfo(QString value)
1003 {
1004     wipeInfo info;
1005     // Convert old geometry values that used a comma as separator
1006     if (value.contains(',')) value.replace(',','/');
1007     QString start = value.section(';', 0, 0);
1008     QString end = value.section(';', 1, 1).section('=', 1, 1);
1009     if (start.startsWith("-100%/0"))
1010         info.start = LEFT;
1011     else if (start.startsWith("100%/0"))
1012         info.start = RIGHT;
1013     else if (start.startsWith("0%/100%"))
1014         info.start = DOWN;
1015     else if (start.startsWith("0%/-100%"))
1016         info.start = UP;
1017     else
1018         info.start = CENTER;
1019
1020     if (start.count(':') == 2)
1021         info.startTransparency = start.section(':', -1).toInt();
1022     else
1023         info.startTransparency = 100;
1024
1025     if (end.startsWith("-100%/0"))
1026         info.end = LEFT;
1027     else if (end.startsWith("100%/0"))
1028         info.end = RIGHT;
1029     else if (end.startsWith("0%/100%"))
1030         info.end = DOWN;
1031     else if (end.startsWith("0%/-100%"))
1032         info.end = UP;
1033     else
1034         info.end = CENTER;
1035
1036     if (end.count(':') == 2)
1037         info.endTransparency = end.section(':', -1).toInt();
1038     else
1039         info.endTransparency = 100;
1040
1041     return info;
1042 }
1043
1044 void ParameterContainer::updateTimecodeFormat()
1045 {
1046     if (m_keyframeEditor)
1047         m_keyframeEditor->updateTimecodeFormat();
1048
1049     QDomNodeList namenode = m_effect.elementsByTagName("parameter");
1050     for (int i = 0; i < namenode.count() ; i++) {
1051         QDomNode pa = namenode.item(i);
1052         QDomElement na = pa.firstChildElement("name");
1053         QString type = pa.attributes().namedItem("type").nodeValue();
1054         QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
1055
1056         if (type == "geometry") {
1057             if (KdenliveSettings::on_monitor_effects()) {
1058                 if (m_geometryWidget) m_geometryWidget->updateTimecodeFormat();
1059             } else {
1060                 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
1061                 geom->updateTimecodeFormat();
1062             }
1063             break;
1064         } else if (type == "position") {
1065             PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
1066             posi->updateTimecodeFormat();
1067             break;
1068 #ifdef USE_QJSON
1069         } else if (type == "roto-spline") {
1070             RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems[paramName]);
1071             widget->updateTimecodeFormat();
1072 #endif
1073         }
1074     }
1075 }
1076
1077 void ParameterContainer::slotCollectAllParameters()
1078 {
1079     if (m_valueItems.isEmpty() || m_effect.isNull()) return;
1080     QLocale locale;
1081     locale.setNumberOptions(QLocale::OmitGroupSeparator);
1082     const QDomElement oldparam = m_effect.cloneNode().toElement();
1083     //QDomElement newparam = oldparam.cloneNode().toElement();
1084     QDomNodeList namenode = m_effect.elementsByTagName("parameter");
1085
1086     for (int i = 0; i < namenode.count() ; i++) {
1087         QDomNode pa = namenode.item(i);
1088         QDomElement na = pa.firstChildElement("name");
1089         QString type = pa.attributes().namedItem("type").nodeValue();
1090         QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
1091         if (type == "complex")
1092             paramName.append("complex");
1093         else if (type == "position")
1094             paramName.append("position");
1095         else if (type == "geometry")
1096             paramName.append("geometry");
1097         else if (type == "keyframe")
1098             paramName.append("keyframe");
1099         if (type != "simplekeyframe" && type != "fixed" && type != "addedgeometry" && !m_valueItems.contains(paramName)) {
1100             kDebug() << "// Param: " << paramName << " NOT FOUND";
1101             continue;
1102         }
1103
1104         QString setValue;
1105         if (type == "double" || type == "constant") {
1106             DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
1107             setValue = locale.toString(doubleparam->getValue());
1108         } else if (type == "list") {
1109             KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
1110             setValue = box->itemData(box->currentIndex()).toString();
1111         } else if (type == "bool") {
1112             QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
1113             setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
1114         } else if (type == "color") {
1115             ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
1116             setValue = choosecolor->getColor();
1117         } else if (type == "complex") {
1118             ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
1119             namenode.item(i) = complex->getParamDesc();
1120         } else if (type == "geometry") {
1121             if (KdenliveSettings::on_monitor_effects()) {
1122                 if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getValue());
1123             } else {
1124                 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
1125                 namenode.item(i).toElement().setAttribute("value", geom->getValue());
1126             }
1127         } else if (type == "addedgeometry") {
1128             namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getExtraValue(namenode.item(i).toElement().attribute("name")));
1129         } else if (type == "position") {
1130             PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
1131             int pos = pedit->getPosition();
1132             setValue = QString::number(pos);
1133             if (m_effect.attribute("id") == "fadein" || m_effect.attribute("id") == "fade_from_black") {
1134                 // Make sure duration is not longer than clip
1135                 /*if (pos > m_out) {
1136                     pos = m_out;
1137                     pedit->setPosition(pos);
1138                 }*/
1139                 EffectsList::setParameter(m_effect, "in", QString::number(m_in));
1140                 EffectsList::setParameter(m_effect, "out", QString::number(m_in + pos));
1141                 setValue.clear();
1142             } else if (m_effect.attribute("id") == "fadeout" || m_effect.attribute("id") == "fade_to_black") {
1143                 // Make sure duration is not longer than clip
1144                 /*if (pos > m_out) {
1145                     pos = m_out;
1146                     pedit->setPosition(pos);
1147                 }*/
1148                 EffectsList::setParameter(m_effect, "in", QString::number(m_out - pos));
1149                 EffectsList::setParameter(m_effect, "out", QString::number(m_out));
1150                 setValue.clear();
1151             }
1152         } else if (type == "curve") {
1153             KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
1154             QList<QPointF> points = curve->curve().points();
1155             QString number = pa.attributes().namedItem("number").nodeValue();
1156             QString inName = pa.attributes().namedItem("inpoints").nodeValue();
1157             QString outName = pa.attributes().namedItem("outpoints").nodeValue();
1158             int off = pa.attributes().namedItem("min").nodeValue().toInt();
1159             int end = pa.attributes().namedItem("max").nodeValue().toInt();
1160             EffectsList::setParameter(m_effect, number, QString::number(points.count()));
1161             for (int j = 0; (j < points.count() && j + off <= end); j++) {
1162                 QString in = inName;
1163                 in.replace("%i", QString::number(j + off));
1164                 QString out = outName;
1165                 out.replace("%i", QString::number(j + off));
1166                 EffectsList::setParameter(m_effect, in, locale.toString(points.at(j).x()));
1167                 EffectsList::setParameter(m_effect, out, locale.toString(points.at(j).y()));
1168             }
1169             QString depends = pa.attributes().namedItem("depends").nodeValue();
1170             if (!depends.isEmpty())
1171                 meetDependency(paramName, type, EffectsList::parameter(m_effect, depends));
1172         } else if (type == "bezier_spline") {
1173             BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
1174             setValue = widget->spline();
1175             QString depends = pa.attributes().namedItem("depends").nodeValue();
1176             if (!depends.isEmpty())
1177                 meetDependency(paramName, type, EffectsList::parameter(m_effect, depends));
1178 #ifdef USE_QJSON
1179         } else if (type == "roto-spline") {
1180             RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
1181             setValue = widget->getSpline();
1182 #endif
1183         } else if (type == "wipe") {
1184             Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
1185             wipeInfo info;
1186             if (wp->start_left->isChecked())
1187                 info.start = LEFT;
1188             else if (wp->start_right->isChecked())
1189                 info.start = RIGHT;
1190             else if (wp->start_up->isChecked())
1191                 info.start = UP;
1192             else if (wp->start_down->isChecked())
1193                 info.start = DOWN;
1194             else if (wp->start_center->isChecked())
1195                 info.start = CENTER;
1196             else
1197                 info.start = LEFT;
1198             info.startTransparency = wp->start_transp->value();
1199
1200             if (wp->end_left->isChecked())
1201                 info.end = LEFT;
1202             else if (wp->end_right->isChecked())
1203                 info.end = RIGHT;
1204             else if (wp->end_up->isChecked())
1205                 info.end = UP;
1206             else if (wp->end_down->isChecked())
1207                 info.end = DOWN;
1208             else if (wp->end_center->isChecked())
1209                 info.end = CENTER;
1210             else
1211                 info.end = RIGHT;
1212             info.endTransparency = wp->end_transp->value();
1213
1214             setValue = getWipeString(info);
1215         } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
1216             QDomElement elem = pa.toElement();
1217             QString realName = i18n(na.toElement().text().toUtf8().data());
1218             QString val = m_keyframeEditor->getValue(realName);
1219             elem.setAttribute("keyframes", val);
1220
1221             if (m_keyframeEditor->isVisibleParam(realName))
1222                 elem.setAttribute("intimeline", "1");
1223             else if (elem.hasAttribute("intimeline"))
1224                 elem.removeAttribute("intimeline");
1225         } else if (type == "url") {
1226             KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
1227             setValue = req->url().path();
1228         } else if (type == "keywords"){
1229             QLineEdit *line = ((Keywordval*)m_valueItems.value(paramName))->lineeditwidget;
1230             QComboBox *combo = ((Keywordval*)m_valueItems.value(paramName))->comboboxwidget;
1231             if(combo->currentIndex())
1232             {
1233                 QString comboval = combo->itemData(combo->currentIndex()).toString();
1234                 line->insert(comboval);
1235                 combo->setCurrentIndex(0);
1236             }
1237             setValue = line->text();
1238         } else if (type == "fontfamily") {
1239             QFontComboBox* fontfamily = ((Fontval*)m_valueItems.value(paramName))->fontfamilywidget;
1240             setValue = fontfamily->currentFont().family();
1241         }
1242         if (!setValue.isNull())
1243             pa.attributes().namedItem("value").setNodeValue(setValue);
1244
1245     }
1246     emit parameterChanged(oldparam, m_effect, m_effect.attribute("kdenlive_ix").toInt());
1247 }
1248
1249 QString ParameterContainer::getWipeString(wipeInfo info)
1250 {
1251
1252     QString start;
1253     QString end;
1254     switch (info.start) {
1255     case LEFT:
1256         start = "-100%/0%:100%x100%";
1257         break;
1258     case RIGHT:
1259         start = "100%/0%:100%x100%";
1260         break;
1261     case DOWN:
1262         start = "0%/100%:100%x100%";
1263         break;
1264     case UP:
1265         start = "0%/-100%:100%x100%";
1266         break;
1267     default:
1268         start = "0%/0%:100%x100%";
1269         break;
1270     }
1271     start.append(':' + QString::number(info.startTransparency));
1272
1273     switch (info.end) {
1274     case LEFT:
1275         end = "-100%/0%:100%x100%";
1276         break;
1277     case RIGHT:
1278         end = "100%/0%:100%x100%";
1279         break;
1280     case DOWN:
1281         end = "0%/100%:100%x100%";
1282         break;
1283     case UP:
1284         end = "0%/-100%:100%x100%";
1285         break;
1286     default:
1287         end = "0%/0%:100%x100%";
1288         break;
1289     }
1290     end.append(':' + QString::number(info.endTransparency));
1291     return QString(start + ";-1=" + end);
1292 }
1293
1294 void ParameterContainer::slotStartFilterJobAction()
1295 {
1296     QDomNodeList namenode = m_effect.elementsByTagName("parameter");
1297     for (int i = 0; i < namenode.count() ; i++) {
1298         QDomElement pa = namenode.item(i).toElement();
1299         QString type = pa.attribute("type");
1300         if (type == "filterjob") {
1301             emit startFilterJob(pa.attribute("filtertag"), pa.attribute("filterparams"), pa.attribute("finalfilter"), pa.attribute("consumer"), pa.attribute("consumerparams"), pa.attribute("wantedproperties"));
1302             kDebug()<<" - - -PROPS:\n"<<pa.attribute("filtertag")<<"-"<< pa.attribute("filterparams")<<"-"<< pa.attribute("consumer")<<"-"<< pa.attribute("consumerparams")<<"-"<< pa.attribute("wantedproperties");
1303             break;
1304         }
1305     }
1306 }