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