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