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),
83 m_baseWidget = new QWidget(this);
84 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
85 setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
86 setFrameStyle(QFrame::NoFrame);
87 setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
89 QPalette p = palette();
90 KColorScheme scheme(p.currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
91 QColor dark_bg = scheme.shade(KColorScheme::DarkShade);
92 QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
93 QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
94 QColor light_bg = scheme.shade(KColorScheme::LightShade);
96 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()));
97 setStyleSheet(stylesheet);
99 setWidget(m_baseWidget);
100 setWidgetResizable(true);
101 m_vbox = new QVBoxLayout(m_baseWidget);
102 m_vbox->setContentsMargins(0, 0, 0, 0);
103 m_vbox->setSpacing(2);
106 EffectStackEdit::~EffectStackEdit()
112 void EffectStackEdit::setFrameSize(QPoint p)
115 QDomNodeList namenode = m_params.elementsByTagName("parameter");
116 for (int i = 0; i < namenode.count() ; i++) {
117 QDomNode pa = namenode.item(i);
118 QDomNode na = pa.firstChildElement("name");
119 QString type = pa.attributes().namedItem("type").nodeValue();
120 QString paramName = i18n(na.toElement().text().toUtf8().data());
122 if (type == "geometry") {
123 if (!KdenliveSettings::on_monitor_effects()) {
124 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
125 geom->setFrameSize(m_frameSize);
129 GeometryWidget *geom = ((GeometryWidget*)m_valueItems[paramName+"geometry"]);
130 geom->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 GeometryWidget *geom = (GeometryWidget*)m_valueItems[paramName+"geometry"];
152 geom->updateTimecodeFormat();
154 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
155 geom->updateTimecodeFormat();
159 if (type == "position") {
160 PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
161 posi->updateTimecodeFormat();
167 void EffectStackEdit::meetDependency(const QString& name, QString type, QString value)
169 if (type == "curve") {
170 KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
172 int color = value.toInt();
173 curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
175 } else if (type == "bezier_spline") {
176 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
178 widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10)));
183 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
189 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
191 m_params.setAttribute(name, value);
193 if (name == "disable") {
194 // if effect is disabled, disable parameters widget
195 bool enabled = value.toInt() == 0 || !KdenliveSettings::disable_effect_parameters();
197 emit effectStateChanged(enabled);
201 void EffectStackEdit::transferParamDesc(const QDomElement d, int pos, int in, int out, bool isEffect)
204 if (m_keyframeEditor) delete m_keyframeEditor;
205 m_keyframeEditor = NULL;
209 if (m_params.isNull()) {
210 kDebug() << "// EMPTY EFFECT STACK";
214 QDomNodeList namenode = m_params.elementsByTagName("parameter");
216 QFile debugFile("/tmp/namenodes.txt");
217 if (debugFile.open(QFile::WriteOnly | QFile::Truncate)) {
218 QTextStream out(&debugFile);
219 QTextStream out2(stdout);
220 for (int i = 0; i < namenode.size(); i++) {
222 namenode.at(i).save(out, 2);
224 namenode.at(i).save(out2, 2);
228 QDomElement e = m_params.toElement();
229 const int minFrame = e.attribute("start").toInt();
230 const int maxFrame = e.attribute("end").toInt();
232 bool disable = d.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
233 setEnabled(!disable);
238 for (int i = 0; i < namenode.count() ; i++) {
239 QDomElement pa = namenode.item(i).toElement();
240 QDomElement na = pa.firstChildElement("name");
241 QDomElement commentElem = pa.firstChildElement("comment");
242 QString type = pa.attribute("type");
243 QString paramName = i18n(na.text().toUtf8().data());
245 if (!commentElem.isNull())
246 comment = i18n(commentElem.text().toUtf8().data());
247 QWidget * toFillin = new QWidget(m_baseWidget);
248 QString value = pa.attribute("value").isNull() ?
249 pa.attribute("default") : pa.attribute("value");
251 /** Currently supported parameter types are:
252 * constant (=double): a slider with an integer value (use the "factor" attribute to divide the value so that you can get a double
253 * list: a combobox containing a list of values to choose
255 * complex: designed for keyframe parameters, but old and not finished, do not use
256 * geometry: a rectangle that can be moved & resized, with possible keyframes, used in composite transition
257 * keyframe: a list widget with a list of entries (position and value)
258 * color: a color chooser button
259 * position: a slider representing the position of a frame in the current clip
260 * curve: a single curve representing multiple points
261 * wipe: a widget designed for the wipe transition, allowing to choose a position (left, right, top,...)
264 if (type == "double" || type == "constant") {
267 if (pa.attribute("min").startsWith('%'))
268 min = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("min"));
270 min = pa.attribute("min").toInt();
271 if (pa.attribute("max").startsWith('%'))
272 max = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("max"));
274 max = pa.attribute("max").toInt();
276 DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, (int)(value.toDouble() + 0.5), min, max,
277 pa.attribute("default").toInt(), comment, -1, pa.attribute("suffix"), this);
278 m_vbox->addWidget(doubleparam);
279 m_valueItems[paramName] = doubleparam;
280 connect(doubleparam, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
281 connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
282 } else if (type == "list") {
283 Listval *lsval = new Listval;
284 lsval->setupUi(toFillin);
285 QStringList listitems = pa.attribute("paramlist").split(',');
286 QDomElement list = pa.firstChildElement("paramlistdisplay");
287 QStringList listitemsdisplay;
288 if (!list.isNull()) listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
289 else listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
290 if (listitemsdisplay.count() != listitems.count())
291 listitemsdisplay = listitems;
292 lsval->list->setIconSize(QSize(30, 30));
293 for (int i = 0; i < listitems.count(); i++) {
294 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
295 QString entry = listitems.at(i);
296 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
297 if (!EffectStackEdit::iconCache.contains(entry)) {
299 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
301 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
304 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
305 lsval->name->setText(paramName);
306 lsval->labelComment->setText(comment);
307 lsval->widgetComment->setHidden(true);
308 m_valueItems[paramName] = lsval;
309 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
310 if (!comment.isEmpty())
311 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
312 m_uiItems.append(lsval);
313 } else if (type == "bool") {
314 Boolval *bval = new Boolval;
315 bval->setupUi(toFillin);
316 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
317 bval->name->setText(paramName);
318 bval->labelComment->setText(comment);
319 bval->widgetComment->setHidden(true);
320 m_valueItems[paramName] = bval;
321 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
322 if (!comment.isEmpty())
323 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
324 m_uiItems.append(bval);
325 } else if (type == "complex") {
326 ComplexParameter *pl = new ComplexParameter;
327 pl->setupParam(d, pa.attribute("name"), 0, 100);
328 m_vbox->addWidget(pl);
329 m_valueItems[paramName+"complex"] = pl;
330 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
331 } else if (type == "geometry") {
332 if (KdenliveSettings::on_monitor_effects()) {
333 GeometryWidget *geometry = new GeometryWidget(m_monitor, m_timecode, pos, isEffect, this);
334 geometry->setFrameSize(m_frameSize);
335 geometry->slotShowScene(!disable);
336 // connect this before setupParam to make sure the monitor scene shows up at startup
337 connect(geometry, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
338 connect(geometry, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
339 if (minFrame == maxFrame)
340 geometry->setupParam(pa, m_in, m_out);
342 geometry->setupParam(pa, minFrame, maxFrame);
343 m_vbox->addWidget(geometry);
344 m_valueItems[paramName+"geometry"] = geometry;
345 connect(geometry, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
346 connect(this, SIGNAL(syncEffectsPos(int)), geometry, SLOT(slotSyncPosition(int)));
347 connect(this, SIGNAL(effectStateChanged(bool)), geometry, SLOT(slotShowScene(bool)));
349 Geometryval *geo = new Geometryval(m_profile, m_timecode, m_frameSize, pos);
350 if (minFrame == maxFrame)
351 geo->setupParam(pa, m_in, m_out);
353 geo->setupParam(pa, minFrame, maxFrame);
354 m_vbox->addWidget(geo);
355 m_valueItems[paramName+"geometry"] = geo;
356 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
357 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
358 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
360 } else if (type == "keyframe" || type == "simplekeyframe") {
361 // keyframe editor widget
362 if (m_keyframeEditor == NULL) {
364 if (pa.attribute("widget") == "corners") {
365 // we want a corners-keyframe-widget
366 CornersWidget *corners = new CornersWidget(m_monitor, pa, m_in, m_in + m_out, m_timecode, e.attribute("active_keyframe", "-1").toInt(), this);
367 corners->slotShowScene(!disable);
368 connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
369 connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
370 connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
371 geo = static_cast<KeyframeEdit *>(corners);
373 geo = new KeyframeEdit(pa, m_in, m_in + m_out, m_timecode, e.attribute("active_keyframe", "-1").toInt());
375 m_vbox->addWidget(geo);
376 m_valueItems[paramName+"keyframe"] = geo;
377 m_keyframeEditor = geo;
378 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
379 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
380 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
382 // we already have a keyframe editor, so just add another column for the new param
383 m_keyframeEditor->addParameter(pa);
385 } else if (type == "color") {
386 if (value.startsWith('#'))
387 value = value.replace('#', "0x");
389 ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, QColor(value.toUInt(&ok, 16)), this);
390 m_vbox->addWidget(choosecolor);
391 m_valueItems[paramName] = choosecolor;
392 connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
393 connect(choosecolor, SIGNAL(modified()) , this, SLOT(collectAllParameters()));
394 } else if (type == "position") {
395 int pos = value.toInt();
396 if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
398 } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
399 // fadeout position starts from clip end
402 PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_timecode);
403 m_vbox->addWidget(posedit);
404 m_valueItems[paramName+"position"] = posedit;
405 connect(posedit, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
406 } else if (type == "curve") {
407 KisCurveWidget *curve = new KisCurveWidget(this);
408 curve->setMaxPoints(pa.attribute("max").toInt());
409 QList<QPointF> points;
410 int number = EffectsList::parameter(e, pa.attribute("number")).toInt();
411 QString inName = pa.attribute("inpoints");
412 QString outName = pa.attribute("outpoints");
413 int start = pa.attribute("min").toInt();
414 for (int j = start; j <= number; j++) {
416 in.replace("%i", QString::number(j));
417 QString out = outName;
418 out.replace("%i", QString::number(j));
419 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
421 if (!points.isEmpty())
422 curve->setCurve(KisCubicCurve(points));
423 QSpinBox *spinin = new QSpinBox();
424 spinin->setRange(0, 1000);
425 QSpinBox *spinout = new QSpinBox();
426 spinout->setRange(0, 1000);
427 curve->setupInOutControls(spinin, spinout, 0, 1000);
428 m_vbox->addWidget(curve);
429 m_vbox->addWidget(spinin);
430 m_vbox->addWidget(spinout);
432 connect(curve, SIGNAL(modified()), this, SLOT(collectAllParameters()));
433 m_valueItems[paramName] = curve;
435 QString depends = pa.attribute("depends");
436 if (!depends.isEmpty())
437 meetDependency(paramName, type, EffectsList::parameter(e, depends));
438 } else if (type == "bezier_spline") {
439 BezierSplineWidget *widget = new BezierSplineWidget(value, this);
441 m_vbox->addWidget(widget);
442 m_valueItems[paramName] = widget;
443 connect(widget, SIGNAL(modified()), this, SLOT(collectAllParameters()));
444 QString depends = pa.attribute("depends");
445 if (!depends.isEmpty())
446 meetDependency(paramName, type, EffectsList::parameter(e, depends));
448 } else if (type == "roto-spline") {
449 RotoWidget *roto = new RotoWidget(value, m_monitor, m_in, m_out, m_timecode, this);
450 roto->slotShowScene(!disable);
451 connect(roto, SIGNAL(valueChanged()), this, SLOT(collectAllParameters()));
452 connect(roto, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
453 connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
454 connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
455 connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
456 m_vbox->addWidget(roto);
457 m_valueItems[paramName] = roto;
459 } else if (type == "wipe") {
460 Wipeval *wpval = new Wipeval;
461 wpval->setupUi(toFillin);
462 wipeInfo w = getWipeInfo(value);
465 wpval->start_up->setChecked(true);
468 wpval->start_down->setChecked(true);
471 wpval->start_right->setChecked(true);
474 wpval->start_left->setChecked(true);
477 wpval->start_center->setChecked(true);
482 wpval->end_up->setChecked(true);
485 wpval->end_down->setChecked(true);
488 wpval->end_right->setChecked(true);
491 wpval->end_left->setChecked(true);
494 wpval->end_center->setChecked(true);
497 wpval->start_transp->setValue(w.startTransparency);
498 wpval->end_transp->setValue(w.endTransparency);
499 m_valueItems[paramName] = wpval;
500 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
501 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
502 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
503 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
504 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
505 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
506 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
507 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
508 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
509 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
510 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
511 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
512 //wpval->title->setTitle(na.toElement().text());
513 m_uiItems.append(wpval);
514 } else if (type == "url") {
515 Urlval *cval = new Urlval;
516 cval->setupUi(toFillin);
517 cval->label->setText(paramName);
518 cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
519 m_valueItems[paramName] = cval;
520 cval->urlwidget->setUrl(KUrl(value));
521 connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(collectAllParameters()));
522 connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(collectAllParameters()));
523 m_uiItems.append(cval);
530 m_vbox->addWidget(toFillin);
534 m_vbox->addStretch();
536 if (m_keyframeEditor)
537 m_keyframeEditor->checkVisibleParam();
539 // Make sure all doubleparam spinboxes have the same width, looks much better
540 QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
542 for (int i = 0; i < allWidgets.count(); i++) {
543 if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
545 for (int i = 0; i < allWidgets.count(); i++) {
546 allWidgets.at(i)->setSpinSize(minSize);
550 wipeInfo EffectStackEdit::getWipeInfo(QString value)
553 QString start = value.section(';', 0, 0);
554 QString end = value.section(';', 1, 1).section('=', 1, 1);
556 if (start.startsWith("-100%,0"))
558 else if (start.startsWith("100%,0"))
560 else if (start.startsWith("0%,100%"))
562 else if (start.startsWith("0%,-100%"))
567 if (start.count(':') == 2)
568 info.startTransparency = start.section(':', -1).toInt();
570 info.startTransparency = 100;
572 if (end.startsWith("-100%,0"))
574 else if (end.startsWith("100%,0"))
576 else if (end.startsWith("0%,100%"))
578 else if (end.startsWith("0%,-100%"))
583 if (end.count(':') == 2)
584 info.endTransparency = end.section(':', -1).toInt();
586 info.endTransparency = 100;
591 QString EffectStackEdit::getWipeString(wipeInfo info)
596 switch (info.start) {
598 start = "-100%,0%:100%x100%";
601 start = "100%,0%:100%x100%";
604 start = "0%,100%:100%x100%";
607 start = "0%,-100%:100%x100%";
610 start = "0%,0%:100%x100%";
613 start.append(':' + QString::number(info.startTransparency));
617 end = "-100%,0%:100%x100%";
620 end = "100%,0%:100%x100%";
623 end = "0%,100%:100%x100%";
626 end = "0%,-100%:100%x100%";
629 end = "0%,0%:100%x100%";
632 end.append(':' + QString::number(info.endTransparency));
633 return QString(start + ";-1=" + end);
636 void EffectStackEdit::collectAllParameters()
638 if (m_valueItems.isEmpty() || m_params.isNull()) return;
639 const QDomElement oldparam = m_params.cloneNode().toElement();
640 QDomElement newparam = oldparam.cloneNode().toElement();
641 QDomNodeList namenode = newparam.elementsByTagName("parameter");
643 for (int i = 0; i < namenode.count() ; i++) {
644 QDomNode pa = namenode.item(i);
645 QDomNode na = pa.firstChildElement("name");
646 QString type = pa.attributes().namedItem("type").nodeValue();
647 QString paramName = i18n(na.toElement().text().toUtf8().data());
648 if (type == "complex")
649 paramName.append("complex");
650 else if (type == "position")
651 paramName.append("position");
652 else if (type == "geometry")
653 paramName.append("geometry");
654 else if (type == "keyframe")
655 paramName.append("keyframe");
656 if (type != "simplekeyframe" && !m_valueItems.contains(paramName)) {
657 kDebug() << "// Param: " << paramName << " NOT FOUND";
662 if (type == "double" || type == "constant") {
663 DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
664 setValue = QString::number(doubleparam->getValue());
665 } else if (type == "list") {
666 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
667 setValue = box->itemData(box->currentIndex()).toString();
668 } else if (type == "bool") {
669 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
670 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
671 } else if (type == "color") {
672 ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
673 setValue = choosecolor->getColor().name();
674 } else if (type == "complex") {
675 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
676 namenode.item(i) = complex->getParamDesc();
677 } else if (type == "geometry") {
678 if (KdenliveSettings::on_monitor_effects()) {
679 GeometryWidget *geometry = ((GeometryWidget*)m_valueItems.value(paramName));
680 namenode.item(i).toElement().setAttribute("value", geometry->getValue());
682 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
683 namenode.item(i).toElement().setAttribute("value", geom->getValue());
685 } else if (type == "position") {
686 PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
687 int pos = pedit->getPosition();
688 setValue = QString::number(pos);
689 if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_black") {
690 // Make sure duration is not longer than clip
693 pedit->setPosition(pos);
695 EffectsList::setParameter(newparam, "in", QString::number(m_in));
696 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
698 } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
699 // Make sure duration is not longer than clip
702 pedit->setPosition(pos);
704 EffectsList::setParameter(newparam, "in", QString::number(m_out - pos));
705 EffectsList::setParameter(newparam, "out", QString::number(m_out));
708 } else if (type == "curve") {
709 KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
710 QList<QPointF> points = curve->curve().points();
711 QString number = pa.attributes().namedItem("number").nodeValue();
712 QString inName = pa.attributes().namedItem("inpoints").nodeValue();
713 QString outName = pa.attributes().namedItem("outpoints").nodeValue();
714 int off = pa.attributes().namedItem("min").nodeValue().toInt();
715 int end = pa.attributes().namedItem("max").nodeValue().toInt();
716 EffectsList::setParameter(newparam, number, QString::number(points.count()));
717 for (int j = 0; (j < points.count() && j + off <= end); j++) {
719 in.replace("%i", QString::number(j + off));
720 QString out = outName;
721 out.replace("%i", QString::number(j + off));
722 EffectsList::setParameter(newparam, in, QString::number(points.at(j).x()));
723 EffectsList::setParameter(newparam, out, QString::number(points.at(j).y()));
725 QString depends = pa.attributes().namedItem("depends").nodeValue();
726 if (!depends.isEmpty())
727 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
728 } else if (type == "bezier_spline") {
729 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
730 setValue = widget->spline();
731 QString depends = pa.attributes().namedItem("depends").nodeValue();
732 if (!depends.isEmpty())
733 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
735 } else if (type == "roto-spline") {
736 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
737 setValue = widget->getSpline();
739 } else if (type == "wipe") {
740 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
742 if (wp->start_left->isChecked())
744 else if (wp->start_right->isChecked())
746 else if (wp->start_up->isChecked())
748 else if (wp->start_down->isChecked())
750 else if (wp->start_center->isChecked())
754 info.startTransparency = wp->start_transp->value();
756 if (wp->end_left->isChecked())
758 else if (wp->end_right->isChecked())
760 else if (wp->end_up->isChecked())
762 else if (wp->end_down->isChecked())
764 else if (wp->end_center->isChecked())
768 info.endTransparency = wp->end_transp->value();
770 setValue = getWipeString(info);
771 } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
772 QDomElement elem = pa.toElement();
773 QString realName = i18n(na.toElement().text().toUtf8().data());
774 QString val = m_keyframeEditor->getValue(realName);
775 elem.setAttribute("keyframes", val);
777 if (m_keyframeEditor->isVisibleParam(realName))
778 elem.setAttribute("intimeline", "1");
779 else if (elem.hasAttribute("intimeline"))
780 elem.removeAttribute("intimeline");
781 } else if (type == "url") {
782 KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
783 setValue = req->url().path();
786 if (!setValue.isNull())
787 pa.attributes().namedItem("value").setNodeValue(setValue);
790 emit parameterChanged(oldparam, newparam);
793 void EffectStackEdit::clearAllItems()
796 m_valueItems.clear();
798 /*while (!m_items.isEmpty()) {
799 QWidget *die = m_items.takeFirst();
803 //qDeleteAll(m_uiItems);
805 while ((child = m_vbox->takeAt(0)) != 0) {
806 QWidget *wid = child->widget();
810 m_keyframeEditor = NULL;
814 void EffectStackEdit::slotSyncEffectsPos(int pos)
816 emit syncEffectsPos(pos);