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