]> git.sesse.net Git - kdenlive/blob - src/effectstackedit.cpp
1cb9d1d24df264e8e4e114965b31d8c2f4776d04
[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             lsval->labelComment->setText(comment);
271             lsval->widgetComment->setHidden(true);
272             m_valueItems[paramName] = lsval;
273             connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
274             if (!comment.isEmpty())
275                 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
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             bval->labelComment->setText(comment);
283             bval->widgetComment->setHidden(true);
284             m_valueItems[paramName] = bval;
285             connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
286             if (!comment.isEmpty())
287                 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
288             m_uiItems.append(bval);
289         } else if (type == "complex") {
290             ComplexParameter *pl = new ComplexParameter;
291             pl->setupParam(d, pa.attribute("name"), 0, 100);
292             m_vbox->addWidget(pl);
293             m_valueItems[paramName+"complex"] = pl;
294             connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
295         } else if (type == "geometry") {
296             if (KdenliveSettings::on_monitor_effects()) {
297                 GeometryWidget *geometry = new GeometryWidget(m_monitor, m_timecode, pos, isEffect, this);
298                 geometry->slotShowScene(!disable);
299                 // connect this before setupParam to make sure the monitor scene shows up at startup
300                 connect(geometry, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
301                 connect(geometry, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
302                 if (minFrame == maxFrame)
303                     geometry->setupParam(pa, m_in, m_out);
304                 else
305                     geometry->setupParam(pa, minFrame, maxFrame);
306                 m_vbox->addWidget(geometry);
307                 m_valueItems[paramName+"geometry"] = geometry;
308                 connect(geometry, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
309                 connect(this, SIGNAL(syncEffectsPos(int)), geometry, SLOT(slotSyncPosition(int)));
310                 connect(this, SIGNAL(effectStateChanged(bool)), geometry, SLOT(slotShowScene(bool)));
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;
327                 if (pa.attribute("widget") == "corners") {
328                     // we want a corners-keyframe-widget
329                     CornersWidget *corners = new CornersWidget(m_monitor, pa, m_in, m_in + m_out, m_timecode, e.attribute("active_keyframe", "-1").toInt(), this);
330                     corners->slotShowScene(!disable);
331                     connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
332                     connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
333                     connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
334                     geo = static_cast<KeyframeEdit *>(corners);
335                 } else {
336                     geo = new KeyframeEdit(pa, m_in, m_in + m_out, m_timecode, e.attribute("active_keyframe", "-1").toInt());
337                 }
338                 m_vbox->addWidget(geo);
339                 m_valueItems[paramName+"keyframe"] = geo;
340                 m_keyframeEditor = geo;
341                 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
342                 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
343                 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
344             } else {
345                 // we already have a keyframe editor, so just add another column for the new param
346                 m_keyframeEditor->addParameter(pa);
347             }
348         } else if (type == "color") {
349             if (value.startsWith('#'))
350                 value = value.replace('#', "0x");
351             bool ok;
352             ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, QColor(value.toUInt(&ok, 16)), this);
353             m_vbox->addWidget(choosecolor);
354             m_valueItems[paramName] = choosecolor;
355             connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
356             connect(choosecolor, SIGNAL(modified()) , this, SLOT(collectAllParameters()));
357         } else if (type == "position") {
358             int pos = value.toInt();
359             if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
360                 pos = pos - m_in;
361             } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
362                 // fadeout position starts from clip end
363                 pos = m_out - pos;
364             }
365             PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_timecode);
366             m_vbox->addWidget(posedit);
367             m_valueItems[paramName+"position"] = posedit;
368             connect(posedit, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
369         } else if (type == "curve") {
370             KisCurveWidget *curve = new KisCurveWidget(this);
371             curve->setMaxPoints(pa.attribute("max").toInt());
372             QList<QPointF> points;
373             int number = EffectsList::parameter(e, pa.attribute("number")).toInt();
374             QString inName = pa.attribute("inpoints");
375             QString outName = pa.attribute("outpoints");
376             int start = pa.attribute("min").toInt();
377             for (int j = start; j <= number; j++) {
378                 QString in = inName;
379                 in.replace("%i", QString::number(j));
380                 QString out = outName;
381                 out.replace("%i", QString::number(j));
382                 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
383             }
384             if (!points.isEmpty())
385                 curve->setCurve(KisCubicCurve(points));
386             QSpinBox *spinin = new QSpinBox();
387             spinin->setRange(0, 1000);
388             QSpinBox *spinout = new QSpinBox();
389             spinout->setRange(0, 1000);
390             curve->setupInOutControls(spinin, spinout, 0, 1000);
391             m_vbox->addWidget(curve);
392             m_vbox->addWidget(spinin);
393             m_vbox->addWidget(spinout);
394
395             connect(curve, SIGNAL(modified()), this, SLOT(collectAllParameters()));
396             m_valueItems[paramName] = curve;
397
398             QString depends = pa.attribute("depends");
399             if (!depends.isEmpty())
400                 meetDependency(paramName, type, EffectsList::parameter(e, depends));
401         } else if (type == "bezier_spline") {
402             BezierSplineWidget *widget = new BezierSplineWidget(value, this);
403             stretch = false;
404             m_vbox->addWidget(widget);
405             m_valueItems[paramName] = widget;
406             connect(widget, SIGNAL(modified()), this, SLOT(collectAllParameters()));
407             QString depends = pa.attribute("depends");
408             if (!depends.isEmpty())
409                 meetDependency(paramName, type, EffectsList::parameter(e, depends));
410         } else if (type == "wipe") {
411             Wipeval *wpval = new Wipeval;
412             wpval->setupUi(toFillin);
413             wipeInfo w = getWipeInfo(value);
414             switch (w.start) {
415             case UP:
416                 wpval->start_up->setChecked(true);
417                 break;
418             case DOWN:
419                 wpval->start_down->setChecked(true);
420                 break;
421             case RIGHT:
422                 wpval->start_right->setChecked(true);
423                 break;
424             case LEFT:
425                 wpval->start_left->setChecked(true);
426                 break;
427             default:
428                 wpval->start_center->setChecked(true);
429                 break;
430             }
431             switch (w.end) {
432             case UP:
433                 wpval->end_up->setChecked(true);
434                 break;
435             case DOWN:
436                 wpval->end_down->setChecked(true);
437                 break;
438             case RIGHT:
439                 wpval->end_right->setChecked(true);
440                 break;
441             case LEFT:
442                 wpval->end_left->setChecked(true);
443                 break;
444             default:
445                 wpval->end_center->setChecked(true);
446                 break;
447             }
448             wpval->start_transp->setValue(w.startTransparency);
449             wpval->end_transp->setValue(w.endTransparency);
450             m_valueItems[paramName] = wpval;
451             connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
452             connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
453             connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
454             connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
455             connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
456             connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
457             connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
458             connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
459             connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
460             connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
461             connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
462             connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
463             //wpval->title->setTitle(na.toElement().text());
464             m_uiItems.append(wpval);
465         } else if (type == "url") {
466             Urlval *cval = new Urlval;
467             cval->setupUi(toFillin);
468             cval->label->setText(paramName);
469             cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
470             m_valueItems[paramName] = cval;
471             cval->urlwidget->setUrl(KUrl(value));
472             connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(collectAllParameters()));
473             connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(collectAllParameters()));
474             m_uiItems.append(cval);
475         } else {
476             delete toFillin;
477             toFillin = NULL;
478         }
479
480         if (toFillin)
481             m_vbox->addWidget(toFillin);
482     }
483
484     if (stretch)
485         m_vbox->addStretch();
486
487     if (m_keyframeEditor)
488         m_keyframeEditor->checkVisibleParam();
489 }
490
491 wipeInfo EffectStackEdit::getWipeInfo(QString value)
492 {
493     wipeInfo info;
494     QString start = value.section(';', 0, 0);
495     QString end = value.section(';', 1, 1).section('=', 1, 1);
496
497     if (start.startsWith("-100%,0"))
498         info.start = LEFT;
499     else if (start.startsWith("100%,0"))
500         info.start = RIGHT;
501     else if (start.startsWith("0%,100%"))
502         info.start = DOWN;
503     else if (start.startsWith("0%,-100%"))
504         info.start = UP;
505     else
506         info.start = CENTER;
507
508     if (start.count(':') == 2)
509         info.startTransparency = start.section(':', -1).toInt();
510     else
511         info.startTransparency = 100;
512
513     if (end.startsWith("-100%,0"))
514         info.end = LEFT;
515     else if (end.startsWith("100%,0"))
516         info.end = RIGHT;
517     else if (end.startsWith("0%,100%"))
518         info.end = DOWN;
519     else if (end.startsWith("0%,-100%"))
520         info.end = UP;
521     else
522         info.end = CENTER;
523
524     if (end.count(':') == 2)
525         info.endTransparency = end.section(':', -1).toInt();
526     else
527         info.endTransparency = 100;
528
529     return info;
530 }
531
532 QString EffectStackEdit::getWipeString(wipeInfo info)
533 {
534
535     QString start;
536     QString end;
537     switch (info.start) {
538     case LEFT:
539         start = "-100%,0%:100%x100%";
540         break;
541     case RIGHT:
542         start = "100%,0%:100%x100%";
543         break;
544     case DOWN:
545         start = "0%,100%:100%x100%";
546         break;
547     case UP:
548         start = "0%,-100%:100%x100%";
549         break;
550     default:
551         start = "0%,0%:100%x100%";
552         break;
553     }
554     start.append(':' + QString::number(info.startTransparency));
555
556     switch (info.end) {
557     case LEFT:
558         end = "-100%,0%:100%x100%";
559         break;
560     case RIGHT:
561         end = "100%,0%:100%x100%";
562         break;
563     case DOWN:
564         end = "0%,100%:100%x100%";
565         break;
566     case UP:
567         end = "0%,-100%:100%x100%";
568         break;
569     default:
570         end = "0%,0%:100%x100%";
571         break;
572     }
573     end.append(':' + QString::number(info.endTransparency));
574     return QString(start + ";-1=" + end);
575 }
576
577 void EffectStackEdit::collectAllParameters()
578 {
579     if (m_valueItems.isEmpty() || m_params.isNull()) return;
580     const QDomElement oldparam = m_params.cloneNode().toElement();
581     QDomElement newparam = oldparam.cloneNode().toElement();
582     QDomNodeList namenode = newparam.elementsByTagName("parameter");
583
584     for (int i = 0; i < namenode.count() ; i++) {
585         QDomNode pa = namenode.item(i);
586         QDomNode na = pa.firstChildElement("name");
587         QString type = pa.attributes().namedItem("type").nodeValue();
588         QString paramName = i18n(na.toElement().text().toUtf8().data());
589         if (type == "complex")
590             paramName.append("complex");
591         else if (type == "position")
592             paramName.append("position");
593         else if (type == "geometry")
594             paramName.append("geometry");
595         else if (type == "keyframe")
596             paramName.append("keyframe");
597         if (type != "simplekeyframe" && !m_valueItems.contains(paramName)) {
598             kDebug() << "// Param: " << paramName << " NOT FOUND";
599             continue;
600         }
601
602         QString setValue;
603         if (type == "double" || type == "constant") {
604             DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
605             setValue = QString::number(doubleparam->getValue());
606         } else if (type == "list") {
607             KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
608             setValue = box->itemData(box->currentIndex()).toString();
609         } else if (type == "bool") {
610             QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
611             setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
612         } else if (type == "color") {
613             ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
614             setValue = choosecolor->getColor().name();
615         } else if (type == "complex") {
616             ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
617             namenode.item(i) = complex->getParamDesc();
618         } else if (type == "geometry") {
619             if (KdenliveSettings::on_monitor_effects()) {
620                 GeometryWidget *geometry = ((GeometryWidget*)m_valueItems.value(paramName));
621                 namenode.item(i).toElement().setAttribute("value", geometry->getValue());
622             } else {
623                 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
624                 namenode.item(i).toElement().setAttribute("value", geom->getValue());
625             }
626         } else if (type == "position") {
627             PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
628             int pos = pedit->getPosition();
629             setValue = QString::number(pos);
630             if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_black") {
631                 // Make sure duration is not longer than clip
632                 /*if (pos > m_out) {
633                     pos = m_out;
634                     pedit->setPosition(pos);
635                 }*/
636                 EffectsList::setParameter(newparam, "in", QString::number(m_in));
637                 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
638                 setValue.clear();
639             } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
640                 // Make sure duration is not longer than clip
641                 /*if (pos > m_out) {
642                     pos = m_out;
643                     pedit->setPosition(pos);
644                 }*/
645                 EffectsList::setParameter(newparam, "in", QString::number(m_out - pos));
646                 EffectsList::setParameter(newparam, "out", QString::number(m_out));
647                 setValue.clear();
648             }
649         } else if (type == "curve") {
650             KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
651             QList<QPointF> points = curve->curve().points();
652             QString number = pa.attributes().namedItem("number").nodeValue();
653             QString inName = pa.attributes().namedItem("inpoints").nodeValue();
654             QString outName = pa.attributes().namedItem("outpoints").nodeValue();
655             int off = pa.attributes().namedItem("min").nodeValue().toInt();
656             int end = pa.attributes().namedItem("max").nodeValue().toInt();
657             EffectsList::setParameter(newparam, number, QString::number(points.count()));
658             for (int j = 0; (j < points.count() && j + off <= end); j++) {
659                 QString in = inName;
660                 in.replace("%i", QString::number(j + off));
661                 QString out = outName;
662                 out.replace("%i", QString::number(j + off));
663                 EffectsList::setParameter(newparam, in, QString::number(points.at(j).x()));
664                 EffectsList::setParameter(newparam, out, QString::number(points.at(j).y()));
665             }
666             QString depends = pa.attributes().namedItem("depends").nodeValue();
667             if (!depends.isEmpty())
668                 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
669         } else if (type == "bezier_spline") {
670             BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
671             setValue = widget->spline();
672             QString depends = pa.attributes().namedItem("depends").nodeValue();
673             if (!depends.isEmpty())
674                 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
675         } else if (type == "wipe") {
676             Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
677             wipeInfo info;
678             if (wp->start_left->isChecked())
679                 info.start = LEFT;
680             else if (wp->start_right->isChecked())
681                 info.start = RIGHT;
682             else if (wp->start_up->isChecked())
683                 info.start = UP;
684             else if (wp->start_down->isChecked())
685                 info.start = DOWN;
686             else if (wp->start_center->isChecked())
687                 info.start = CENTER;
688             else
689                 info.start = LEFT;
690             info.startTransparency = wp->start_transp->value();
691
692             if (wp->end_left->isChecked())
693                 info.end = LEFT;
694             else if (wp->end_right->isChecked())
695                 info.end = RIGHT;
696             else if (wp->end_up->isChecked())
697                 info.end = UP;
698             else if (wp->end_down->isChecked())
699                 info.end = DOWN;
700             else if (wp->end_center->isChecked())
701                 info.end = CENTER;
702             else
703                 info.end = RIGHT;
704             info.endTransparency = wp->end_transp->value();
705
706             setValue = getWipeString(info);
707         } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
708             QDomElement elem = pa.toElement();
709             QString realName = i18n(na.toElement().text().toUtf8().data());
710             QString val = m_keyframeEditor->getValue(realName);
711             elem.setAttribute("keyframes", val);
712
713             if (m_keyframeEditor->isVisibleParam(realName))
714                 elem.setAttribute("intimeline", "1");
715             else if (elem.hasAttribute("intimeline"))
716                 elem.removeAttribute("intimeline");
717         } else if (type == "url") {
718             KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
719             setValue = req->url().path();
720         }
721
722         if (!setValue.isNull())
723             pa.attributes().namedItem("value").setNodeValue(setValue);
724
725     }
726     emit parameterChanged(oldparam, newparam);
727 }
728
729 void EffectStackEdit::clearAllItems()
730 {
731     blockSignals(true);
732     m_valueItems.clear();
733     m_uiItems.clear();
734     /*while (!m_items.isEmpty()) {
735         QWidget *die = m_items.takeFirst();
736         die->disconnect();
737         delete die;
738     }*/
739     //qDeleteAll(m_uiItems);
740     QLayoutItem *child;
741     while ((child = m_vbox->takeAt(0)) != 0) {
742         QWidget *wid = child->widget();
743         delete child;
744         if (wid) delete wid;
745     }
746     m_keyframeEditor = NULL;
747     blockSignals(false);
748 }
749
750 void EffectStackEdit::slotSyncEffectsPos(int pos)
751 {
752     emit syncEffectsPos(pos);
753 }