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