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