]> git.sesse.net Git - kdenlive/blob - src/effectstackedit.cpp
3e3f2d070e4c17c18c6d7076409b594b2f06c2f8
[kdenlive] / src / effectstackedit.cpp
1 /***************************************************************************
2                           effecstackedit.cpp  -  description
3                              -------------------
4     begin                : Feb 15 2008
5     copyright            : (C) 2008 by Marco Gittler
6     email                : g.marco@freenet.de
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #include "effectstackedit.h"
19 #include "ui_listval_ui.h"
20 #include "ui_boolval_ui.h"
21 #include "ui_wipeval_ui.h"
22 #include "ui_urlval_ui.h"
23 #include "complexparameter.h"
24 #include "geometryval.h"
25 #include "positionedit.h"
26 #include "projectlist.h"
27 #include "effectslist.h"
28 #include "kdenlivesettings.h"
29 #include "profilesdialog.h"
30 #include "kis_curve_widget.h"
31 #include "kis_cubic_curve.h"
32 #include "choosecolorwidget.h"
33 #include "geometrywidget.h"
34 #include "colortools.h"
35 #include "doubleparameterwidget.h"
36 #include "cornerswidget.h"
37
38 #include <KDebug>
39 #include <KLocale>
40 #include <KFileDialog>
41
42 #include <QVBoxLayout>
43 #include <QLabel>
44 #include <QPushButton>
45 #include <QCheckBox>
46 #include <QScrollArea>
47
48
49 class Boolval: public QWidget, public Ui::Boolval_UI
50 {
51 };
52
53 class Listval: public QWidget, public Ui::Listval_UI
54 {
55 };
56
57 class Wipeval: public QWidget, public Ui::Wipeval_UI
58 {
59 };
60
61 class Urlval: public QWidget, public Ui::Urlval_UI
62 {
63 };
64
65 QMap<QString, QImage> EffectStackEdit::iconCache;
66
67 EffectStackEdit::EffectStackEdit(Monitor *monitor, QWidget *parent) :
68     QScrollArea(parent),
69     m_in(0),
70     m_out(0),
71     m_frameSize(QPoint()),
72     m_keyframeEditor(NULL),
73     m_monitor(monitor)
74 {
75     m_baseWidget = new QWidget(this);
76     setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
77     setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
78     setFrameStyle(QFrame::NoFrame);
79     setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
80
81     setWidget(m_baseWidget);
82     setWidgetResizable(true);
83     m_vbox = new QVBoxLayout(m_baseWidget);
84     m_vbox->setContentsMargins(0, 0, 0, 0);
85     m_vbox->setSpacing(0);
86     //wid->show();
87 }
88
89 EffectStackEdit::~EffectStackEdit()
90 {
91     iconCache.clear();
92     delete m_baseWidget;
93 }
94
95 void EffectStackEdit::setFrameSize(QPoint p)
96 {
97     m_frameSize = p;
98     QDomNodeList namenode = m_params.elementsByTagName("parameter");
99     for (int i = 0; i < namenode.count() ; i++) {
100         QDomNode pa = namenode.item(i);
101         QDomNode na = pa.firstChildElement("name");
102         QString type = pa.attributes().namedItem("type").nodeValue();
103         QString paramName = i18n(na.toElement().text().toUtf8().data());
104
105         if (type == "geometry" && !KdenliveSettings::on_monitor_effects()) {
106             Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
107             geom->setFrameSize(m_frameSize);
108             break;
109         }
110     }
111 }
112
113 void EffectStackEdit::updateTimecodeFormat()
114 {
115     if (m_keyframeEditor)
116         m_keyframeEditor->updateTimecodeFormat();
117
118     QDomNodeList namenode = m_params.elementsByTagName("parameter");
119     for (int i = 0; i < namenode.count() ; i++) {
120         QDomNode pa = namenode.item(i);
121         QDomNode na = pa.firstChildElement("name");
122         QString type = pa.attributes().namedItem("type").nodeValue();
123         QString paramName = i18n(na.toElement().text().toUtf8().data());
124
125         if (type == "geometry") {
126             if (KdenliveSettings::on_monitor_effects()) {
127                 GeometryWidget *geom = (GeometryWidget*)m_valueItems[paramName+"geometry"];
128                 geom->updateTimecodeFormat();
129             } else {
130                 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
131                 geom->updateTimecodeFormat();
132             }
133             break;
134         }
135         if (type == "position") {
136             PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
137             posi->updateTimecodeFormat();
138             break;
139         }
140     }
141 }
142
143 void EffectStackEdit::meetDependency(const QString& name, QString type, QString value)
144 {
145     if (type == "curve") {
146         KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
147         if (curve) {
148             int color = value.toInt();
149             curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)color, 0.8)));
150         }
151     }
152 }
153
154 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
155 {
156     m_profile = profile;
157     m_timecode = t;
158 }
159
160 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
161 {
162     m_params.setAttribute(name, value);
163
164     if (name == "disable") {
165         // if effect is disabled, disable parameters widget
166         setEnabled(value.toInt() == 0 || !KdenliveSettings::disable_effect_parameters());
167         if (KdenliveSettings::on_monitor_effects()) {
168             // effect disabled, hide monitor scene if any
169             QDomNodeList namenode = m_params.elementsByTagName("parameter");
170             for (int i = 0; i < namenode.count() ; i++) {
171                 QDomNode pa = namenode.item(i);
172                 QDomNode na = pa.firstChildElement("name");
173                 QString type = pa.attributes().namedItem("type").nodeValue();
174                 if (type == "geometry") {
175                     QString paramName = i18n(na.toElement().text().toUtf8().data());
176                     paramName.append("geometry");
177                     GeometryWidget *geometry = ((GeometryWidget*)m_valueItems.value(paramName));
178                     geometry->slotShowScene(value.toInt() == 0 || !KdenliveSettings::disable_effect_parameters());
179                 }
180             }
181         }
182     }
183 }
184
185 void EffectStackEdit::transferParamDesc(const QDomElement d, int pos, int in, int out, bool isEffect)
186 {
187     clearAllItems();
188     if (m_keyframeEditor) delete m_keyframeEditor;
189     m_keyframeEditor = NULL;
190     m_params = d;
191     m_in = in;
192     m_out = out;
193     if (m_params.isNull()) {
194         kDebug() << "// EMPTY EFFECT STACK";
195         return;
196     }
197
198     QDomNodeList namenode = m_params.elementsByTagName("parameter");
199     QDomElement e = m_params.toElement();
200     const int minFrame = e.attribute("start").toInt();
201     const int maxFrame = e.attribute("end").toInt();
202
203     bool disable = d.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
204     setEnabled(!disable);
205
206
207     for (int i = 0; i < namenode.count() ; i++) {
208         QDomElement pa = namenode.item(i).toElement();
209         QDomNode na = pa.firstChildElement("name");
210         QDomNode commentNode = pa.firstChildElement("comment");
211         QString type = pa.attribute("type");
212         QString paramName = i18n(na.toElement().text().toUtf8().data());
213         QString comment;
214         if (!commentNode.isNull())
215             comment = i18n(commentNode.toElement().text().toUtf8().data());
216         QWidget * toFillin = new QWidget(m_baseWidget);
217         QString value = pa.attribute("value").isNull() ?
218                         pa.attribute("default") : pa.attribute("value");
219
220         /** Currently supported parameter types are:
221             * constant (=double): a slider with an integer value (use the "factor" attribute to divide the value so that you can get a double
222             * list: a combobox containing a list of values to choose
223             * bool: a checkbox
224             * complex: designed for keyframe parameters, but old and not finished, do not use
225             * geometry: a rectangle that can be moved & resized, with possible keyframes, used in composite transition
226             * keyframe: a list widget with a list of entries (position and value)
227             * color: a color chooser button
228             * position: a slider representing the position of a frame in the current clip
229             * curve: a single curve representing multiple points
230             * wipe: a widget designed for the wipe transition, allowing to choose a position (left, right, top,...)
231         */
232
233         if (type == "double" || type == "constant") {
234             int min;
235             int max;
236             if (pa.attribute("min").startsWith('%'))
237                 min = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("min"));
238             else
239                 min = pa.attribute("min").toInt();
240             if (pa.attribute("max").startsWith('%'))
241                 max = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("max"));
242             else
243                 max = pa.attribute("max").toInt();
244
245             DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, (int)(value.toDouble() + 0.5), min, max,
246                     pa.attribute("default").toInt(), comment, pa.attribute("suffix"), this);
247             m_vbox->addWidget(doubleparam);
248             m_valueItems[paramName] = doubleparam;
249             connect(doubleparam, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
250         } else if (type == "list") {
251             Listval *lsval = new Listval;
252             lsval->setupUi(toFillin);
253             QStringList listitems = pa.attribute("paramlist").split(',');
254             QStringList listitemsdisplay = pa.attribute("paramlistdisplay").split(',');
255             if (listitemsdisplay.count() != listitems.count())
256                 listitemsdisplay = listitems;
257             lsval->list->setIconSize(QSize(30, 30));
258             for (int i = 0; i < listitems.count(); i++) {
259                 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
260                 QString entry = listitems.at(i);
261                 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
262                     if (!EffectStackEdit::iconCache.contains(entry)) {
263                         QImage pix(entry);
264                         EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
265                     }
266                     lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
267                 }
268             }
269             if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
270             lsval->name->setText(paramName);
271             m_valueItems[paramName] = lsval;
272             connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
273             m_uiItems.append(lsval);
274         } else if (type == "bool") {
275             Boolval *bval = new Boolval;
276             bval->setupUi(toFillin);
277             bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
278             bval->name->setText(paramName);
279             m_valueItems[paramName] = bval;
280             connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
281             m_uiItems.append(bval);
282         } else if (type == "complex") {
283             ComplexParameter *pl = new ComplexParameter;
284             pl->setupParam(d, pa.attribute("name"), 0, 100);
285             m_vbox->addWidget(pl);
286             m_valueItems[paramName+"complex"] = pl;
287             connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
288         } else if (type == "geometry") {
289             if (KdenliveSettings::on_monitor_effects()) {
290                 GeometryWidget *geometry = new GeometryWidget(m_monitor, m_timecode, pos, isEffect, disable, this);
291                 // connect this before setupParam to make sure the monitor scene shows up at startup
292                 connect(geometry, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
293                 connect(geometry, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
294                 if (minFrame == maxFrame)
295                     geometry->setupParam(pa, m_in, m_out);
296                 else
297                     geometry->setupParam(pa, minFrame, maxFrame);
298                 m_vbox->addWidget(geometry);
299                 m_valueItems[paramName+"geometry"] = geometry;
300                 connect(geometry, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
301                 connect(this, SIGNAL(syncEffectsPos(int)), geometry, SLOT(slotSyncPosition(int)));
302             } else {
303                 Geometryval *geo = new Geometryval(m_profile, m_timecode, m_frameSize, pos);
304                 if (minFrame == maxFrame)
305                     geo->setupParam(pa, m_in, m_out);
306                 else
307                     geo->setupParam(pa, minFrame, maxFrame);
308                 m_vbox->addWidget(geo);
309                 m_valueItems[paramName+"geometry"] = geo;
310                 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
311                 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
312                 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
313             }
314         } else if (type == "keyframe" || type == "simplekeyframe") {
315             // keyframe editor widget
316             kDebug() << "min: " << m_in << ", MAX: " << m_out;
317             if (m_keyframeEditor == NULL) {
318                 KeyframeEdit *geo = new KeyframeEdit(pa, m_in, m_in + m_out, m_timecode, e.attribute("active_keyframe", "-1").toInt());
319                 m_vbox->addWidget(geo);
320                 m_valueItems[paramName+"keyframe"] = geo;
321                 m_keyframeEditor = geo;
322                 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
323                 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
324             } else {
325                 // we already have a keyframe editor, so just add another column for the new param
326                 m_keyframeEditor->addParameter(pa);
327             }
328         } else if (type == "color") {
329             if (value.startsWith('#'))
330                 value = value.replace('#', "0x");
331             bool ok;
332             ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, QColor(value.toUInt(&ok, 16)), this);
333             m_vbox->addWidget(choosecolor);
334             m_valueItems[paramName] = choosecolor;
335             connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
336             connect(choosecolor, SIGNAL(modified()) , this, SLOT(collectAllParameters()));
337         } else if (type == "position") {
338             int pos = value.toInt();
339             if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
340                 pos = pos - m_in;
341             } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
342                 // fadeout position starts from clip end
343                 pos = m_out - pos;
344             }
345             PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_timecode);
346             m_vbox->addWidget(posedit);
347             m_valueItems[paramName+"position"] = posedit;
348             connect(posedit, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
349         } else if (type == "curve") {
350             KisCurveWidget *curve = new KisCurveWidget(this);
351             curve->setMaxPoints(pa.attribute("max").toInt());
352             QList<QPointF> points;
353             int number = EffectsList::parameter(e, pa.attribute("number")).toInt();
354             QString inName = pa.attribute("inpoints");
355             QString outName = pa.attribute("outpoints");
356             int start = pa.attribute("min").toInt();
357             for (int j = start; j <= number; j++) {
358                 QString in = inName;
359                 in.replace("%i", QString::number(j));
360                 QString out = outName;
361                 out.replace("%i", QString::number(j));
362                 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
363             }
364             if (!points.isEmpty())
365                 curve->setCurve(KisCubicCurve(points));
366             QSpinBox *spinin = new QSpinBox();
367             spinin->setRange(0, 1000);
368             QSpinBox *spinout = new QSpinBox();
369             spinout->setRange(0, 1000);
370             curve->setupInOutControls(spinin, spinout, 0, 1000);
371             m_vbox->addWidget(curve);
372             m_vbox->addWidget(spinin);
373             m_vbox->addWidget(spinout);
374
375             connect(curve, SIGNAL(modified()), this, SLOT(collectAllParameters()));
376             m_valueItems[paramName] = curve;
377
378             QString depends = pa.attribute("depends");
379             if (!depends.isEmpty())
380                 meetDependency(paramName, type, EffectsList::parameter(e, depends));
381         } else if (type == "corners") {
382             CornersWidget *corners = new CornersWidget(m_monitor, pos, isEffect, pa.attribute("factor").toInt(), this);
383             connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
384             if (minFrame == maxFrame)
385                 corners->setRange(m_in, m_out);
386             else
387                 corners->setRange(minFrame, maxFrame);
388
389             QString xName = pa.attribute("xpoints");
390             QString yName = pa.attribute("ypoints");
391             QPolygon points;
392             int x, y;
393             for (int j = 1; j <= 4; ++j) {
394                 x = EffectsList::parameter(e, QString(xName).replace("%i", QString::number(j))).toInt();
395                 y = EffectsList::parameter(e, QString(yName).replace("%i", QString::number(j))).toInt();
396                 points << QPoint(x, y);
397             }
398             corners->setValue(points);
399
400             m_vbox->addWidget(corners);
401             connect(corners, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
402             m_valueItems[paramName] = corners;
403         } else if (type == "wipe") {
404             Wipeval *wpval = new Wipeval;
405             wpval->setupUi(toFillin);
406             wipeInfo w = getWipeInfo(value);
407             switch (w.start) {
408             case UP:
409                 wpval->start_up->setChecked(true);
410                 break;
411             case DOWN:
412                 wpval->start_down->setChecked(true);
413                 break;
414             case RIGHT:
415                 wpval->start_right->setChecked(true);
416                 break;
417             case LEFT:
418                 wpval->start_left->setChecked(true);
419                 break;
420             default:
421                 wpval->start_center->setChecked(true);
422                 break;
423             }
424             switch (w.end) {
425             case UP:
426                 wpval->end_up->setChecked(true);
427                 break;
428             case DOWN:
429                 wpval->end_down->setChecked(true);
430                 break;
431             case RIGHT:
432                 wpval->end_right->setChecked(true);
433                 break;
434             case LEFT:
435                 wpval->end_left->setChecked(true);
436                 break;
437             default:
438                 wpval->end_center->setChecked(true);
439                 break;
440             }
441             wpval->start_transp->setValue(w.startTransparency);
442             wpval->end_transp->setValue(w.endTransparency);
443             m_valueItems[paramName] = wpval;
444             connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
445             connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
446             connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
447             connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
448             connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
449             connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
450             connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
451             connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
452             connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
453             connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
454             connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
455             connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
456             //wpval->title->setTitle(na.toElement().text());
457             m_uiItems.append(wpval);
458         } else if (type == "url") {
459             Urlval *cval = new Urlval;
460             cval->setupUi(toFillin);
461             cval->label->setText(paramName);
462             cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
463             m_valueItems[paramName] = cval;
464             cval->urlwidget->setUrl(KUrl(value));
465             connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(collectAllParameters()));
466             connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(collectAllParameters()));
467             m_uiItems.append(cval);
468         } else {
469             delete toFillin;
470             toFillin = NULL;
471         }
472
473         if (toFillin)
474             m_vbox->addWidget(toFillin);
475     }
476     m_vbox->addStretch();
477
478     if (m_keyframeEditor)
479         m_keyframeEditor->checkVisibleParam();
480 }
481
482 wipeInfo EffectStackEdit::getWipeInfo(QString value)
483 {
484     wipeInfo info;
485     QString start = value.section(';', 0, 0);
486     QString end = value.section(';', 1, 1).section('=', 1, 1);
487
488     if (start.startsWith("-100%,0"))
489         info.start = LEFT;
490     else if (start.startsWith("100%,0"))
491         info.start = RIGHT;
492     else if (start.startsWith("0%,100%"))
493         info.start = DOWN;
494     else if (start.startsWith("0%,-100%"))
495         info.start = UP;
496     else
497         info.start = CENTER;
498
499     if (start.count(':') == 2)
500         info.startTransparency = start.section(':', -1).toInt();
501     else
502         info.startTransparency = 100;
503
504     if (end.startsWith("-100%,0"))
505         info.end = LEFT;
506     else if (end.startsWith("100%,0"))
507         info.end = RIGHT;
508     else if (end.startsWith("0%,100%"))
509         info.end = DOWN;
510     else if (end.startsWith("0%,-100%"))
511         info.end = UP;
512     else
513         info.end = CENTER;
514
515     if (end.count(':') == 2)
516         info.endTransparency = end.section(':', -1).toInt();
517     else
518         info.endTransparency = 100;
519
520     return info;
521 }
522
523 QString EffectStackEdit::getWipeString(wipeInfo info)
524 {
525
526     QString start;
527     QString end;
528     switch (info.start) {
529     case LEFT:
530         start = "-100%,0%:100%x100%";
531         break;
532     case RIGHT:
533         start = "100%,0%:100%x100%";
534         break;
535     case DOWN:
536         start = "0%,100%:100%x100%";
537         break;
538     case UP:
539         start = "0%,-100%:100%x100%";
540         break;
541     default:
542         start = "0%,0%:100%x100%";
543         break;
544     }
545     start.append(':' + QString::number(info.startTransparency));
546
547     switch (info.end) {
548     case LEFT:
549         end = "-100%,0%:100%x100%";
550         break;
551     case RIGHT:
552         end = "100%,0%:100%x100%";
553         break;
554     case DOWN:
555         end = "0%,100%:100%x100%";
556         break;
557     case UP:
558         end = "0%,-100%:100%x100%";
559         break;
560     default:
561         end = "0%,0%:100%x100%";
562         break;
563     }
564     end.append(':' + QString::number(info.endTransparency));
565     return QString(start + ";-1=" + end);
566 }
567
568 void EffectStackEdit::collectAllParameters()
569 {
570     if (m_valueItems.isEmpty() || m_params.isNull()) return;
571     const QDomElement oldparam = m_params.cloneNode().toElement();
572     QDomElement newparam = oldparam.cloneNode().toElement();
573     QDomNodeList namenode = newparam.elementsByTagName("parameter");
574
575     for (int i = 0; i < namenode.count() ; i++) {
576         QDomNode pa = namenode.item(i);
577         QDomNode na = pa.firstChildElement("name");
578         QString type = pa.attributes().namedItem("type").nodeValue();
579         QString paramName = i18n(na.toElement().text().toUtf8().data());
580         if (type == "complex")
581             paramName.append("complex");
582         else if (type == "position")
583             paramName.append("position");
584         else if (type == "geometry")
585             paramName.append("geometry");
586         else if (type == "keyframe")
587             paramName.append("keyframe");
588         if (type != "simplekeyframe" && !m_valueItems.contains(paramName)) {
589             kDebug() << "// Param: " << paramName << " NOT FOUND";
590             continue;
591         }
592
593         QString setValue;
594         if (type == "double" || type == "constant") {
595             DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
596             setValue = QString::number(doubleparam->getValue());
597         } else if (type == "list") {
598             KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
599             setValue = box->itemData(box->currentIndex()).toString();
600         } else if (type == "bool") {
601             QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
602             setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
603         } else if (type == "color") {
604             ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
605             setValue = choosecolor->getColor().name();
606         } else if (type == "complex") {
607             ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
608             namenode.item(i) = complex->getParamDesc();
609         } else if (type == "geometry") {
610             if (KdenliveSettings::on_monitor_effects()) {
611                 GeometryWidget *geometry = ((GeometryWidget*)m_valueItems.value(paramName));
612                 namenode.item(i).toElement().setAttribute("value", geometry->getValue());
613             } else {
614                 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
615                 namenode.item(i).toElement().setAttribute("value", geom->getValue());
616             }
617         } else if (type == "position") {
618             PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
619             int pos = pedit->getPosition();
620             setValue = QString::number(pos);
621             if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_black") {
622                 // Make sure duration is not longer than clip
623                 /*if (pos > m_out) {
624                     pos = m_out;
625                     pedit->setPosition(pos);
626                 }*/
627                 EffectsList::setParameter(newparam, "in", QString::number(m_in));
628                 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
629                 setValue.clear();
630             } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
631                 // Make sure duration is not longer than clip
632                 /*if (pos > m_out) {
633                     pos = m_out;
634                     pedit->setPosition(pos);
635                 }*/
636                 EffectsList::setParameter(newparam, "in", QString::number(m_out - pos));
637                 EffectsList::setParameter(newparam, "out", QString::number(m_out));
638                 setValue.clear();
639             }
640         } else if (type == "curve") {
641             KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
642             QList<QPointF> points = curve->curve().points();
643             QString number = pa.attributes().namedItem("number").nodeValue();
644             QString inName = pa.attributes().namedItem("inpoints").nodeValue();
645             QString outName = pa.attributes().namedItem("outpoints").nodeValue();
646             int off = pa.attributes().namedItem("min").nodeValue().toInt();
647             int end = pa.attributes().namedItem("max").nodeValue().toInt();
648             EffectsList::setParameter(newparam, number, QString::number(points.count()));
649             for (int j = 0; (j < points.count() && j + off <= end); j++) {
650                 QString in = inName;
651                 in.replace("%i", QString::number(j + off));
652                 QString out = outName;
653                 out.replace("%i", QString::number(j + off));
654                 EffectsList::setParameter(newparam, in, QString::number(points.at(j).x()));
655                 EffectsList::setParameter(newparam, out, QString::number(points.at(j).y()));
656             }
657             QString depends = pa.attributes().namedItem("depends").nodeValue();
658             if (!depends.isEmpty())
659                 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
660         } else if (type == "corners") {
661             CornersWidget *corners = ((CornersWidget*)m_valueItems.value(paramName));
662             QString xName = pa.attributes().namedItem("xpoints").nodeValue();
663             QString yName = pa.attributes().namedItem("ypoints").nodeValue();
664             QPolygon points = corners->getValue();
665             QPoint p;
666             for (int j = 1; j <= 4; ++j) {
667                 p = points.at(j - 1);
668                 EffectsList::setParameter(newparam, QString(xName).replace("%i", QString::number(j)), QString::number(p.x()));
669                 EffectsList::setParameter(newparam, QString(yName).replace("%i", QString::number(j)), QString::number(p.y()));
670             }
671         } else if (type == "wipe") {
672             Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
673             wipeInfo info;
674             if (wp->start_left->isChecked())
675                 info.start = LEFT;
676             else if (wp->start_right->isChecked())
677                 info.start = RIGHT;
678             else if (wp->start_up->isChecked())
679                 info.start = UP;
680             else if (wp->start_down->isChecked())
681                 info.start = DOWN;
682             else if (wp->start_center->isChecked())
683                 info.start = CENTER;
684             else
685                 info.start = LEFT;
686             info.startTransparency = wp->start_transp->value();
687
688             if (wp->end_left->isChecked())
689                 info.end = LEFT;
690             else if (wp->end_right->isChecked())
691                 info.end = RIGHT;
692             else if (wp->end_up->isChecked())
693                 info.end = UP;
694             else if (wp->end_down->isChecked())
695                 info.end = DOWN;
696             else if (wp->end_center->isChecked())
697                 info.end = CENTER;
698             else
699                 info.end = RIGHT;
700             info.endTransparency = wp->end_transp->value();
701
702             setValue = getWipeString(info);
703         } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
704             QDomElement elem = pa.toElement();
705             QString realName = i18n(na.toElement().text().toUtf8().data());
706             QString val = m_keyframeEditor->getValue(realName);
707             elem.setAttribute("keyframes", val);
708
709             if (m_keyframeEditor->isVisibleParam(realName))
710                 elem.setAttribute("intimeline", "1");
711             else if (elem.hasAttribute("intimeline"))
712                 elem.removeAttribute("intimeline");
713         } else if (type == "url") {
714             KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
715             setValue = req->url().path();
716         }
717
718         if (!setValue.isNull())
719             pa.attributes().namedItem("value").setNodeValue(setValue);
720
721     }
722     emit parameterChanged(oldparam, newparam);
723 }
724
725 void EffectStackEdit::clearAllItems()
726 {
727     blockSignals(true);
728     m_valueItems.clear();
729     m_uiItems.clear();
730     /*while (!m_items.isEmpty()) {
731         QWidget *die = m_items.takeFirst();
732         die->disconnect();
733         delete die;
734     }*/
735     //qDeleteAll(m_uiItems);
736     QLayoutItem *child;
737     while ((child = m_vbox->takeAt(0)) != 0) {
738         QWidget *wid = child->widget();
739         delete child;
740         if (wid) delete wid;
741     }
742     m_keyframeEditor = NULL;
743     blockSignals(false);
744 }
745
746 void EffectStackEdit::slotSyncEffectsPos(int pos)
747 {
748     emit syncEffectsPos(pos);
749 }