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