1 /***************************************************************************
2 effecstackedit.cpp - description
5 copyright : (C) 2008 by Marco Gittler
6 email : g.marco@freenet.de
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
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"
39 #include "rotoscoping/rotowidget.h"
44 #include <KFileDialog>
45 #include <KColorScheme>
47 #include <QVBoxLayout>
49 #include <QPushButton>
51 #include <QScrollArea>
53 // For QDomNode debugging (output into files); leaving here as sample code.
57 class Boolval: public QWidget, public Ui::Boolval_UI
61 class Listval: public QWidget, public Ui::Listval_UI
65 class Wipeval: public QWidget, public Ui::Wipeval_UI
69 class Urlval: public QWidget, public Ui::Urlval_UI
73 QMap<QString, QImage> EffectStackEdit::iconCache;
75 EffectStackEdit::EffectStackEdit(Monitor *monitor, QWidget *parent) :
79 m_frameSize(QPoint()),
80 m_keyframeEditor(NULL),
82 m_geometryWidget(NULL)
84 m_baseWidget = new QWidget(this);
85 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
86 setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
87 setFrameStyle(QFrame::NoFrame);
88 setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
90 QPalette p = palette();
91 KColorScheme scheme(p.currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
92 QColor dark_bg = scheme.shade(KColorScheme::DarkShade);
93 QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
94 QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
95 QColor light_bg = scheme.shade(KColorScheme::LightShade);
97 QString stylesheet(QString("QProgressBar:horizontal {border: 1px solid %1;border-radius:0px;border-top-left-radius: 4px;border-bottom-left-radius: 4px;border-right: 0px;background:%4;padding: 0px;text-align:left center} QProgressBar:horizontal#dragOnly {background: %1} QProgressBar:horizontal:hover#dragOnly {background: %3} QProgressBar:horizontal:hover {border: 1px solid %3;border-right: 0px;} QProgressBar::chunk:horizontal {background: %1;} QProgressBar::chunk:horizontal:hover {background: %3;} QProgressBar:horizontal[inTimeline=\"true\"] { border: 1px solid %2;border-right: 0px;background: %4;padding: 0px;text-align:left center } QProgressBar::chunk:horizontal[inTimeline=\"true\"] {background: %2;} QAbstractSpinBox#dragBox {border: 1px solid %1;border-top-right-radius: 4px;border-bottom-right-radius: 4px;padding-right:0px;} QAbstractSpinBox::down-button#dragBox {width:0px;padding:0px;} QAbstractSpinBox::up-button#dragBox {width:0px;padding:0px;} QAbstractSpinBox[inTimeline=\"true\"]#dragBox { border: 1px solid %2;} QAbstractSpinBox:hover#dragBox {border: 1px solid %3;} ").arg(dark_bg.name()).arg(selected_bg.name()).arg(hover_bg.name()).arg(light_bg.name()));
98 setStyleSheet(stylesheet);
100 setWidget(m_baseWidget);
101 setWidgetResizable(true);
102 m_vbox = new QVBoxLayout(m_baseWidget);
103 m_vbox->setContentsMargins(0, 0, 0, 0);
104 m_vbox->setSpacing(2);
107 EffectStackEdit::~EffectStackEdit()
113 void EffectStackEdit::setFrameSize(QPoint p)
116 QDomNodeList namenode = m_params.elementsByTagName("parameter");
117 for (int i = 0; i < namenode.count() ; i++) {
118 QDomNode pa = namenode.item(i);
119 QDomNode na = pa.firstChildElement("name");
120 QString type = pa.attributes().namedItem("type").nodeValue();
121 QString paramName = i18n(na.toElement().text().toUtf8().data());
123 if (type == "geometry") {
124 if (!KdenliveSettings::on_monitor_effects()) {
125 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
126 geom->setFrameSize(m_frameSize);
130 if (m_geometryWidget) m_geometryWidget->setFrameSize(m_frameSize);
137 void EffectStackEdit::updateTimecodeFormat()
139 if (m_keyframeEditor)
140 m_keyframeEditor->updateTimecodeFormat();
142 QDomNodeList namenode = m_params.elementsByTagName("parameter");
143 for (int i = 0; i < namenode.count() ; i++) {
144 QDomNode pa = namenode.item(i);
145 QDomNode na = pa.firstChildElement("name");
146 QString type = pa.attributes().namedItem("type").nodeValue();
147 QString paramName = i18n(na.toElement().text().toUtf8().data());
149 if (type == "geometry") {
150 if (KdenliveSettings::on_monitor_effects()) {
151 if (m_geometryWidget) m_geometryWidget->updateTimecodeFormat();
153 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
154 geom->updateTimecodeFormat();
158 if (type == "position") {
159 PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
160 posi->updateTimecodeFormat();
166 void EffectStackEdit::meetDependency(const QString& name, QString type, QString value)
168 if (type == "curve") {
169 KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
171 int color = value.toInt();
172 curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
174 } else if (type == "bezier_spline") {
175 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
177 widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10)));
182 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
188 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
190 m_params.setAttribute(name, value);
192 if (name == "disable") {
193 // if effect is disabled, disable parameters widget
194 bool enabled = value.toInt() == 0 || !KdenliveSettings::disable_effect_parameters();
196 emit effectStateChanged(enabled);
200 void EffectStackEdit::transferParamDesc(const QDomElement d, int pos, int in, int out, bool isEffect)
203 if (m_keyframeEditor) delete m_keyframeEditor;
204 m_keyframeEditor = NULL;
208 if (m_params.isNull()) {
209 kDebug() << "// EMPTY EFFECT STACK";
213 QDomNodeList namenode = m_params.elementsByTagName("parameter");
215 QFile debugFile("/tmp/namenodes.txt");
216 if (debugFile.open(QFile::WriteOnly | QFile::Truncate)) {
217 QTextStream out(&debugFile);
218 QTextStream out2(stdout);
219 for (int i = 0; i < namenode.size(); i++) {
221 namenode.at(i).save(out, 2);
223 namenode.at(i).save(out2, 2);
227 QDomElement e = m_params.toElement();
228 const int minFrame = e.attribute("start").toInt();
229 const int maxFrame = e.attribute("end").toInt();
231 bool disable = d.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
232 setEnabled(!disable);
237 for (int i = 0; i < namenode.count() ; i++) {
238 QDomElement pa = namenode.item(i).toElement();
239 QDomElement na = pa.firstChildElement("name");
240 QDomElement commentElem = pa.firstChildElement("comment");
241 QString type = pa.attribute("type");
242 QString paramName = i18n(na.text().toUtf8().data());
244 if (!commentElem.isNull())
245 comment = i18n(commentElem.text().toUtf8().data());
246 QWidget * toFillin = new QWidget(m_baseWidget);
247 QString value = pa.attribute("value").isNull() ?
248 pa.attribute("default") : pa.attribute("value");
250 /** Currently supported parameter types are:
251 * constant (=double): a slider with an integer value (use the "factor" attribute to divide the value so that you can get a double
252 * list: a combobox containing a list of values to choose
254 * complex: designed for keyframe parameters, but old and not finished, do not use
255 * geometry: a rectangle that can be moved & resized, with possible keyframes, used in composite transition
256 * keyframe: a list widget with a list of entries (position and value)
257 * color: a color chooser button
258 * position: a slider representing the position of a frame in the current clip
259 * curve: a single curve representing multiple points
260 * wipe: a widget designed for the wipe transition, allowing to choose a position (left, right, top,...)
263 if (type == "double" || type == "constant") {
266 if (pa.attribute("min").startsWith('%'))
267 min = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("min"));
269 min = pa.attribute("min").toInt();
270 if (pa.attribute("max").startsWith('%'))
271 max = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("max"));
273 max = pa.attribute("max").toInt();
275 DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, (int)(value.toDouble() + 0.5), min, max,
276 pa.attribute("default").toInt(), comment, -1, pa.attribute("suffix"), this);
277 m_vbox->addWidget(doubleparam);
278 m_valueItems[paramName] = doubleparam;
279 connect(doubleparam, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
280 connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
281 } else if (type == "list") {
282 Listval *lsval = new Listval;
283 lsval->setupUi(toFillin);
284 QStringList listitems = pa.attribute("paramlist").split(',');
285 QDomElement list = pa.firstChildElement("paramlistdisplay");
286 QStringList listitemsdisplay;
287 if (!list.isNull()) listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
288 else listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
289 if (listitemsdisplay.count() != listitems.count())
290 listitemsdisplay = listitems;
291 lsval->list->setIconSize(QSize(30, 30));
292 for (int i = 0; i < listitems.count(); i++) {
293 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
294 QString entry = listitems.at(i);
295 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
296 if (!EffectStackEdit::iconCache.contains(entry)) {
298 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
300 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
303 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
304 lsval->name->setText(paramName);
305 lsval->labelComment->setText(comment);
306 lsval->widgetComment->setHidden(true);
307 m_valueItems[paramName] = lsval;
308 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
309 if (!comment.isEmpty())
310 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
311 m_uiItems.append(lsval);
312 } else if (type == "bool") {
313 Boolval *bval = new Boolval;
314 bval->setupUi(toFillin);
315 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
316 bval->name->setText(paramName);
317 bval->labelComment->setText(comment);
318 bval->widgetComment->setHidden(true);
319 m_valueItems[paramName] = bval;
320 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
321 if (!comment.isEmpty())
322 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
323 m_uiItems.append(bval);
324 } else if (type == "complex") {
325 ComplexParameter *pl = new ComplexParameter;
326 pl->setupParam(d, pa.attribute("name"), 0, 100);
327 m_vbox->addWidget(pl);
328 m_valueItems[paramName+"complex"] = pl;
329 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
330 } else if (type == "geometry") {
331 if (KdenliveSettings::on_monitor_effects()) {
332 m_geometryWidget = new GeometryWidget(m_monitor, m_timecode, pos, isEffect, m_params.hasAttribute("showrotation"), this);
333 m_geometryWidget->setFrameSize(m_frameSize);
334 m_geometryWidget->slotShowScene(!disable);
335 // connect this before setupParam to make sure the monitor scene shows up at startup
336 connect(m_geometryWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
337 connect(m_geometryWidget, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
338 if (minFrame == maxFrame)
339 m_geometryWidget->setupParam(pa, m_in, m_out);
341 m_geometryWidget->setupParam(pa, minFrame, maxFrame);
342 m_vbox->addWidget(m_geometryWidget);
343 m_valueItems[paramName+"geometry"] = m_geometryWidget;
344 connect(m_geometryWidget, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
345 connect(this, SIGNAL(syncEffectsPos(int)), m_geometryWidget, SLOT(slotSyncPosition(int)));
346 connect(this, SIGNAL(effectStateChanged(bool)), m_geometryWidget, SLOT(slotShowScene(bool)));
348 Geometryval *geo = new Geometryval(m_profile, m_timecode, m_frameSize, pos);
349 if (minFrame == maxFrame)
350 geo->setupParam(pa, m_in, m_out);
352 geo->setupParam(pa, minFrame, maxFrame);
353 m_vbox->addWidget(geo);
354 m_valueItems[paramName+"geometry"] = geo;
355 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
356 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
357 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
359 } else if (type == "addedgeometry") {
360 // this is a parameter that should be linked to the geometry widget, for example rotation, shear, ...
361 if (m_geometryWidget) m_geometryWidget->addParameter(pa);
362 } else if (type == "keyframe" || type == "simplekeyframe") {
363 // keyframe editor widget
364 if (m_keyframeEditor == NULL) {
366 if (pa.attribute("widget") == "corners") {
367 // we want a corners-keyframe-widget
368 CornersWidget *corners = new CornersWidget(m_monitor, pa, m_in, m_in + m_out, m_timecode, e.attribute("active_keyframe", "-1").toInt(), this);
369 corners->slotShowScene(!disable);
370 connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
371 connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
372 connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
373 geo = static_cast<KeyframeEdit *>(corners);
375 geo = new KeyframeEdit(pa, m_in, m_in + m_out, m_timecode, e.attribute("active_keyframe", "-1").toInt());
377 m_vbox->addWidget(geo);
378 m_valueItems[paramName+"keyframe"] = geo;
379 m_keyframeEditor = geo;
380 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
381 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
382 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
384 // we already have a keyframe editor, so just add another column for the new param
385 m_keyframeEditor->addParameter(pa);
387 } else if (type == "color") {
388 if (value.startsWith('#'))
389 value = value.replace('#', "0x");
391 ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, QColor(value.toUInt(&ok, 16)), this);
392 m_vbox->addWidget(choosecolor);
393 m_valueItems[paramName] = choosecolor;
394 connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
395 connect(choosecolor, SIGNAL(modified()) , this, SLOT(collectAllParameters()));
396 } else if (type == "position") {
397 int pos = value.toInt();
398 if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
400 } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
401 // fadeout position starts from clip end
404 PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_timecode);
405 m_vbox->addWidget(posedit);
406 m_valueItems[paramName+"position"] = posedit;
407 connect(posedit, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
408 } else if (type == "curve") {
409 KisCurveWidget *curve = new KisCurveWidget(this);
410 curve->setMaxPoints(pa.attribute("max").toInt());
411 QList<QPointF> points;
412 int number = EffectsList::parameter(e, pa.attribute("number")).toInt();
413 QString inName = pa.attribute("inpoints");
414 QString outName = pa.attribute("outpoints");
415 int start = pa.attribute("min").toInt();
416 for (int j = start; j <= number; j++) {
418 in.replace("%i", QString::number(j));
419 QString out = outName;
420 out.replace("%i", QString::number(j));
421 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
423 if (!points.isEmpty())
424 curve->setCurve(KisCubicCurve(points));
425 QSpinBox *spinin = new QSpinBox();
426 spinin->setRange(0, 1000);
427 QSpinBox *spinout = new QSpinBox();
428 spinout->setRange(0, 1000);
429 curve->setupInOutControls(spinin, spinout, 0, 1000);
430 m_vbox->addWidget(curve);
431 m_vbox->addWidget(spinin);
432 m_vbox->addWidget(spinout);
434 connect(curve, SIGNAL(modified()), this, SLOT(collectAllParameters()));
435 m_valueItems[paramName] = curve;
437 QString depends = pa.attribute("depends");
438 if (!depends.isEmpty())
439 meetDependency(paramName, type, EffectsList::parameter(e, depends));
440 } else if (type == "bezier_spline") {
441 BezierSplineWidget *widget = new BezierSplineWidget(value, this);
443 m_vbox->addWidget(widget);
444 m_valueItems[paramName] = widget;
445 connect(widget, SIGNAL(modified()), this, SLOT(collectAllParameters()));
446 QString depends = pa.attribute("depends");
447 if (!depends.isEmpty())
448 meetDependency(paramName, type, EffectsList::parameter(e, depends));
450 } else if (type == "roto-spline") {
451 RotoWidget *roto = new RotoWidget(value, m_monitor, m_in, m_out, m_timecode, this);
452 roto->slotShowScene(!disable);
453 connect(roto, SIGNAL(valueChanged()), this, SLOT(collectAllParameters()));
454 connect(roto, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
455 connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
456 connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
457 connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
458 m_vbox->addWidget(roto);
459 m_valueItems[paramName] = roto;
461 } else if (type == "wipe") {
462 Wipeval *wpval = new Wipeval;
463 wpval->setupUi(toFillin);
464 wipeInfo w = getWipeInfo(value);
467 wpval->start_up->setChecked(true);
470 wpval->start_down->setChecked(true);
473 wpval->start_right->setChecked(true);
476 wpval->start_left->setChecked(true);
479 wpval->start_center->setChecked(true);
484 wpval->end_up->setChecked(true);
487 wpval->end_down->setChecked(true);
490 wpval->end_right->setChecked(true);
493 wpval->end_left->setChecked(true);
496 wpval->end_center->setChecked(true);
499 wpval->start_transp->setValue(w.startTransparency);
500 wpval->end_transp->setValue(w.endTransparency);
501 m_valueItems[paramName] = wpval;
502 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
503 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
504 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
505 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
506 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
507 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
508 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
509 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
510 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
511 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
512 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
513 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
514 //wpval->title->setTitle(na.toElement().text());
515 m_uiItems.append(wpval);
516 } else if (type == "url") {
517 Urlval *cval = new Urlval;
518 cval->setupUi(toFillin);
519 cval->label->setText(paramName);
520 cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
521 m_valueItems[paramName] = cval;
522 cval->urlwidget->setUrl(KUrl(value));
523 connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(collectAllParameters()));
524 connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(collectAllParameters()));
525 m_uiItems.append(cval);
532 m_vbox->addWidget(toFillin);
536 m_vbox->addStretch();
538 if (m_keyframeEditor)
539 m_keyframeEditor->checkVisibleParam();
541 // Make sure all doubleparam spinboxes have the same width, looks much better
542 QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
544 for (int i = 0; i < allWidgets.count(); i++) {
545 if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
547 for (int i = 0; i < allWidgets.count(); i++) {
548 allWidgets.at(i)->setSpinSize(minSize);
552 wipeInfo EffectStackEdit::getWipeInfo(QString value)
555 QString start = value.section(';', 0, 0);
556 QString end = value.section(';', 1, 1).section('=', 1, 1);
558 if (start.startsWith("-100%,0"))
560 else if (start.startsWith("100%,0"))
562 else if (start.startsWith("0%,100%"))
564 else if (start.startsWith("0%,-100%"))
569 if (start.count(':') == 2)
570 info.startTransparency = start.section(':', -1).toInt();
572 info.startTransparency = 100;
574 if (end.startsWith("-100%,0"))
576 else if (end.startsWith("100%,0"))
578 else if (end.startsWith("0%,100%"))
580 else if (end.startsWith("0%,-100%"))
585 if (end.count(':') == 2)
586 info.endTransparency = end.section(':', -1).toInt();
588 info.endTransparency = 100;
593 QString EffectStackEdit::getWipeString(wipeInfo info)
598 switch (info.start) {
600 start = "-100%,0%:100%x100%";
603 start = "100%,0%:100%x100%";
606 start = "0%,100%:100%x100%";
609 start = "0%,-100%:100%x100%";
612 start = "0%,0%:100%x100%";
615 start.append(':' + QString::number(info.startTransparency));
619 end = "-100%,0%:100%x100%";
622 end = "100%,0%:100%x100%";
625 end = "0%,100%:100%x100%";
628 end = "0%,-100%:100%x100%";
631 end = "0%,0%:100%x100%";
634 end.append(':' + QString::number(info.endTransparency));
635 return QString(start + ";-1=" + end);
638 void EffectStackEdit::collectAllParameters()
640 if (m_valueItems.isEmpty() || m_params.isNull()) return;
641 const QDomElement oldparam = m_params.cloneNode().toElement();
642 QDomElement newparam = oldparam.cloneNode().toElement();
643 QDomNodeList namenode = newparam.elementsByTagName("parameter");
645 for (int i = 0; i < namenode.count() ; i++) {
646 QDomNode pa = namenode.item(i);
647 QDomNode na = pa.firstChildElement("name");
648 QString type = pa.attributes().namedItem("type").nodeValue();
649 QString paramName = i18n(na.toElement().text().toUtf8().data());
650 if (type == "complex")
651 paramName.append("complex");
652 else if (type == "position")
653 paramName.append("position");
654 else if (type == "geometry")
655 paramName.append("geometry");
656 else if (type == "keyframe")
657 paramName.append("keyframe");
658 if (type != "simplekeyframe" && type != "fixed" && type != "addedgeometry" && !m_valueItems.contains(paramName)) {
659 kDebug() << "// Param: " << paramName << " NOT FOUND";
664 if (type == "double" || type == "constant") {
665 DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
666 setValue = QString::number(doubleparam->getValue());
667 } else if (type == "list") {
668 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
669 setValue = box->itemData(box->currentIndex()).toString();
670 } else if (type == "bool") {
671 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
672 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
673 } else if (type == "color") {
674 ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
675 setValue = choosecolor->getColor().name();
676 } else if (type == "complex") {
677 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
678 namenode.item(i) = complex->getParamDesc();
679 } else if (type == "geometry") {
680 if (KdenliveSettings::on_monitor_effects()) {
681 if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getValue());
683 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
684 namenode.item(i).toElement().setAttribute("value", geom->getValue());
686 } else if (type == "addedgeometry") {
687 namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getExtraValue(namenode.item(i).toElement().attribute("name")));
688 } else if (type == "position") {
689 PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
690 int pos = pedit->getPosition();
691 setValue = QString::number(pos);
692 if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_black") {
693 // Make sure duration is not longer than clip
696 pedit->setPosition(pos);
698 EffectsList::setParameter(newparam, "in", QString::number(m_in));
699 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
701 } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
702 // Make sure duration is not longer than clip
705 pedit->setPosition(pos);
707 EffectsList::setParameter(newparam, "in", QString::number(m_out - pos));
708 EffectsList::setParameter(newparam, "out", QString::number(m_out));
711 } else if (type == "curve") {
712 KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
713 QList<QPointF> points = curve->curve().points();
714 QString number = pa.attributes().namedItem("number").nodeValue();
715 QString inName = pa.attributes().namedItem("inpoints").nodeValue();
716 QString outName = pa.attributes().namedItem("outpoints").nodeValue();
717 int off = pa.attributes().namedItem("min").nodeValue().toInt();
718 int end = pa.attributes().namedItem("max").nodeValue().toInt();
719 EffectsList::setParameter(newparam, number, QString::number(points.count()));
720 for (int j = 0; (j < points.count() && j + off <= end); j++) {
722 in.replace("%i", QString::number(j + off));
723 QString out = outName;
724 out.replace("%i", QString::number(j + off));
725 EffectsList::setParameter(newparam, in, QString::number(points.at(j).x()));
726 EffectsList::setParameter(newparam, out, QString::number(points.at(j).y()));
728 QString depends = pa.attributes().namedItem("depends").nodeValue();
729 if (!depends.isEmpty())
730 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
731 } else if (type == "bezier_spline") {
732 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
733 setValue = widget->spline();
734 QString depends = pa.attributes().namedItem("depends").nodeValue();
735 if (!depends.isEmpty())
736 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
738 } else if (type == "roto-spline") {
739 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
740 setValue = widget->getSpline();
742 } else if (type == "wipe") {
743 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
745 if (wp->start_left->isChecked())
747 else if (wp->start_right->isChecked())
749 else if (wp->start_up->isChecked())
751 else if (wp->start_down->isChecked())
753 else if (wp->start_center->isChecked())
757 info.startTransparency = wp->start_transp->value();
759 if (wp->end_left->isChecked())
761 else if (wp->end_right->isChecked())
763 else if (wp->end_up->isChecked())
765 else if (wp->end_down->isChecked())
767 else if (wp->end_center->isChecked())
771 info.endTransparency = wp->end_transp->value();
773 setValue = getWipeString(info);
774 } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
775 QDomElement elem = pa.toElement();
776 QString realName = i18n(na.toElement().text().toUtf8().data());
777 QString val = m_keyframeEditor->getValue(realName);
778 elem.setAttribute("keyframes", val);
780 if (m_keyframeEditor->isVisibleParam(realName))
781 elem.setAttribute("intimeline", "1");
782 else if (elem.hasAttribute("intimeline"))
783 elem.removeAttribute("intimeline");
784 } else if (type == "url") {
785 KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
786 setValue = req->url().path();
789 if (!setValue.isNull())
790 pa.attributes().namedItem("value").setNodeValue(setValue);
793 emit parameterChanged(oldparam, newparam);
796 void EffectStackEdit::clearAllItems()
799 m_valueItems.clear();
801 /*while (!m_items.isEmpty()) {
802 QWidget *die = m_items.takeFirst();
806 //qDeleteAll(m_uiItems);
808 while ((child = m_vbox->takeAt(0)) != 0) {
809 QWidget *wid = child->widget();
813 m_keyframeEditor = NULL;
814 m_geometryWidget = NULL;
818 void EffectStackEdit::slotSyncEffectsPos(int pos)
820 emit syncEffectsPos(pos);