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