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