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