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