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