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);
95 QColor mid_bg = scheme.shade(KColorScheme::DarkShade);
97 QString stylesheet(QString("QProgressBar:horizontal {border: 1px solid %5;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: %5} QProgressBar:horizontal:hover#dragOnly {background: %3} QProgressBar:horizontal:hover {border: 1px solid %3;border-right: 0px;} QProgressBar::chunk:horizontal {background: %5;} 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()).arg(mid_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 GeometryWidget *geom = ((GeometryWidget*)m_valueItems[paramName+"geometry"]);
131 geom->setFrameSize(m_frameSize);
138 void EffectStackEdit::updateTimecodeFormat()
140 if (m_keyframeEditor)
141 m_keyframeEditor->updateTimecodeFormat();
143 QDomNodeList namenode = m_params.elementsByTagName("parameter");
144 for (int i = 0; i < namenode.count() ; i++) {
145 QDomNode pa = namenode.item(i);
146 QDomNode na = pa.firstChildElement("name");
147 QString type = pa.attributes().namedItem("type").nodeValue();
148 QString paramName = i18n(na.toElement().text().toUtf8().data());
150 if (type == "geometry") {
151 if (KdenliveSettings::on_monitor_effects()) {
152 GeometryWidget *geom = (GeometryWidget*)m_valueItems[paramName+"geometry"];
153 geom->updateTimecodeFormat();
155 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
156 geom->updateTimecodeFormat();
160 if (type == "position") {
161 PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
162 posi->updateTimecodeFormat();
168 void EffectStackEdit::meetDependency(const QString& name, QString type, QString value)
170 if (type == "curve") {
171 KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
173 int color = value.toInt();
174 curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
176 } else if (type == "bezier_spline") {
177 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
179 widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10)));
184 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
190 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
192 m_params.setAttribute(name, value);
194 if (name == "disable") {
195 // if effect is disabled, disable parameters widget
196 bool enabled = value.toInt() == 0 || !KdenliveSettings::disable_effect_parameters();
198 emit effectStateChanged(enabled);
202 void EffectStackEdit::transferParamDesc(const QDomElement d, int pos, int in, int out, bool isEffect)
205 if (m_keyframeEditor) delete m_keyframeEditor;
206 m_keyframeEditor = NULL;
210 if (m_params.isNull()) {
211 kDebug() << "// EMPTY EFFECT STACK";
215 QDomNodeList namenode = m_params.elementsByTagName("parameter");
217 QFile debugFile("/tmp/namenodes.txt");
218 if (debugFile.open(QFile::WriteOnly | QFile::Truncate)) {
219 QTextStream out(&debugFile);
220 QTextStream out2(stdout);
221 for (int i = 0; i < namenode.size(); i++) {
223 namenode.at(i).save(out, 2);
225 namenode.at(i).save(out2, 2);
229 QDomElement e = m_params.toElement();
230 const int minFrame = e.attribute("start").toInt();
231 const int maxFrame = e.attribute("end").toInt();
233 bool disable = d.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
234 setEnabled(!disable);
239 for (int i = 0; i < namenode.count() ; i++) {
240 QDomElement pa = namenode.item(i).toElement();
241 QDomElement na = pa.firstChildElement("name");
242 QDomElement commentElem = pa.firstChildElement("comment");
243 QString type = pa.attribute("type");
244 QString paramName = i18n(na.text().toUtf8().data());
246 if (!commentElem.isNull())
247 comment = i18n(commentElem.text().toUtf8().data());
248 QWidget * toFillin = new QWidget(m_baseWidget);
249 QString value = pa.attribute("value").isNull() ?
250 pa.attribute("default") : pa.attribute("value");
252 /** Currently supported parameter types are:
253 * constant (=double): a slider with an integer value (use the "factor" attribute to divide the value so that you can get a double
254 * list: a combobox containing a list of values to choose
256 * complex: designed for keyframe parameters, but old and not finished, do not use
257 * geometry: a rectangle that can be moved & resized, with possible keyframes, used in composite transition
258 * keyframe: a list widget with a list of entries (position and value)
259 * color: a color chooser button
260 * position: a slider representing the position of a frame in the current clip
261 * curve: a single curve representing multiple points
262 * wipe: a widget designed for the wipe transition, allowing to choose a position (left, right, top,...)
265 if (type == "double" || type == "constant") {
268 if (pa.attribute("min").startsWith('%'))
269 min = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("min"));
271 min = pa.attribute("min").toInt();
272 if (pa.attribute("max").startsWith('%'))
273 max = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("max"));
275 max = pa.attribute("max").toInt();
277 DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, (int)(value.toDouble() + 0.5), min, max,
278 pa.attribute("default").toInt(), comment, -1, pa.attribute("suffix"), this);
279 m_vbox->addWidget(doubleparam);
280 m_valueItems[paramName] = doubleparam;
281 connect(doubleparam, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
282 connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
283 } else if (type == "list") {
284 Listval *lsval = new Listval;
285 lsval->setupUi(toFillin);
286 QStringList listitems = pa.attribute("paramlist").split(',');
287 QDomElement list = pa.firstChildElement("paramlistdisplay");
288 QStringList listitemsdisplay;
289 if (!list.isNull()) listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
290 else listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
291 if (listitemsdisplay.count() != listitems.count())
292 listitemsdisplay = listitems;
293 lsval->list->setIconSize(QSize(30, 30));
294 for (int i = 0; i < listitems.count(); i++) {
295 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
296 QString entry = listitems.at(i);
297 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
298 if (!EffectStackEdit::iconCache.contains(entry)) {
300 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
302 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
305 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
306 lsval->name->setText(paramName);
307 lsval->labelComment->setText(comment);
308 lsval->widgetComment->setHidden(true);
309 m_valueItems[paramName] = lsval;
310 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
311 if (!comment.isEmpty())
312 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
313 m_uiItems.append(lsval);
314 } else if (type == "bool") {
315 Boolval *bval = new Boolval;
316 bval->setupUi(toFillin);
317 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
318 bval->name->setText(paramName);
319 bval->labelComment->setText(comment);
320 bval->widgetComment->setHidden(true);
321 m_valueItems[paramName] = bval;
322 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
323 if (!comment.isEmpty())
324 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
325 m_uiItems.append(bval);
326 } else if (type == "complex") {
327 ComplexParameter *pl = new ComplexParameter;
328 pl->setupParam(d, pa.attribute("name"), 0, 100);
329 m_vbox->addWidget(pl);
330 m_valueItems[paramName+"complex"] = pl;
331 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
332 } else if (type == "geometry") {
333 if (KdenliveSettings::on_monitor_effects()) {
334 GeometryWidget *geometry = new GeometryWidget(m_monitor, m_timecode, pos, isEffect, this);
335 geometry->setFrameSize(m_frameSize);
336 geometry->slotShowScene(!disable);
337 // connect this before setupParam to make sure the monitor scene shows up at startup
338 connect(geometry, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
339 connect(geometry, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
340 if (minFrame == maxFrame)
341 geometry->setupParam(pa, m_in, m_out);
343 geometry->setupParam(pa, minFrame, maxFrame);
344 m_vbox->addWidget(geometry);
345 m_valueItems[paramName+"geometry"] = geometry;
346 connect(geometry, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
347 connect(this, SIGNAL(syncEffectsPos(int)), geometry, SLOT(slotSyncPosition(int)));
348 connect(this, SIGNAL(effectStateChanged(bool)), geometry, SLOT(slotShowScene(bool)));
350 Geometryval *geo = new Geometryval(m_profile, m_timecode, m_frameSize, pos);
351 if (minFrame == maxFrame)
352 geo->setupParam(pa, m_in, m_out);
354 geo->setupParam(pa, minFrame, maxFrame);
355 m_vbox->addWidget(geo);
356 m_valueItems[paramName+"geometry"] = geo;
357 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
358 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
359 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
361 } else if (type == "keyframe" || type == "simplekeyframe") {
362 // keyframe editor widget
363 if (m_keyframeEditor == NULL) {
365 if (pa.attribute("widget") == "corners") {
366 // we want a corners-keyframe-widget
367 CornersWidget *corners = new CornersWidget(m_monitor, pa, m_in, m_in + m_out, m_timecode, e.attribute("active_keyframe", "-1").toInt(), this);
368 corners->slotShowScene(!disable);
369 connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
370 connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
371 connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
372 geo = static_cast<KeyframeEdit *>(corners);
374 geo = new KeyframeEdit(pa, m_in, m_in + m_out, m_timecode, e.attribute("active_keyframe", "-1").toInt());
376 m_vbox->addWidget(geo);
377 m_valueItems[paramName+"keyframe"] = geo;
378 m_keyframeEditor = geo;
379 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
380 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
381 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
383 // we already have a keyframe editor, so just add another column for the new param
384 m_keyframeEditor->addParameter(pa);
386 } else if (type == "color") {
387 if (value.startsWith('#'))
388 value = value.replace('#', "0x");
390 ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, QColor(value.toUInt(&ok, 16)), this);
391 m_vbox->addWidget(choosecolor);
392 m_valueItems[paramName] = choosecolor;
393 connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
394 connect(choosecolor, SIGNAL(modified()) , this, SLOT(collectAllParameters()));
395 } else if (type == "position") {
396 int pos = value.toInt();
397 if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
399 } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
400 // fadeout position starts from clip end
403 PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_timecode);
404 m_vbox->addWidget(posedit);
405 m_valueItems[paramName+"position"] = posedit;
406 connect(posedit, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
407 } else if (type == "curve") {
408 KisCurveWidget *curve = new KisCurveWidget(this);
409 curve->setMaxPoints(pa.attribute("max").toInt());
410 QList<QPointF> points;
411 int number = EffectsList::parameter(e, pa.attribute("number")).toInt();
412 QString inName = pa.attribute("inpoints");
413 QString outName = pa.attribute("outpoints");
414 int start = pa.attribute("min").toInt();
415 for (int j = start; j <= number; j++) {
417 in.replace("%i", QString::number(j));
418 QString out = outName;
419 out.replace("%i", QString::number(j));
420 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
422 if (!points.isEmpty())
423 curve->setCurve(KisCubicCurve(points));
424 QSpinBox *spinin = new QSpinBox();
425 spinin->setRange(0, 1000);
426 QSpinBox *spinout = new QSpinBox();
427 spinout->setRange(0, 1000);
428 curve->setupInOutControls(spinin, spinout, 0, 1000);
429 m_vbox->addWidget(curve);
430 m_vbox->addWidget(spinin);
431 m_vbox->addWidget(spinout);
433 connect(curve, SIGNAL(modified()), this, SLOT(collectAllParameters()));
434 m_valueItems[paramName] = curve;
436 QString depends = pa.attribute("depends");
437 if (!depends.isEmpty())
438 meetDependency(paramName, type, EffectsList::parameter(e, depends));
439 } else if (type == "bezier_spline") {
440 BezierSplineWidget *widget = new BezierSplineWidget(value, this);
442 m_vbox->addWidget(widget);
443 m_valueItems[paramName] = widget;
444 connect(widget, SIGNAL(modified()), this, SLOT(collectAllParameters()));
445 QString depends = pa.attribute("depends");
446 if (!depends.isEmpty())
447 meetDependency(paramName, type, EffectsList::parameter(e, depends));
449 } else if (type == "roto-spline") {
450 RotoWidget *roto = new RotoWidget(value, m_monitor, m_in, m_out, m_timecode, this);
451 roto->slotShowScene(!disable);
452 connect(roto, SIGNAL(valueChanged()), this, SLOT(collectAllParameters()));
453 connect(roto, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
454 connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
455 connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
456 connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
457 m_vbox->addWidget(roto);
458 m_valueItems[paramName] = roto;
460 } else if (type == "wipe") {
461 Wipeval *wpval = new Wipeval;
462 wpval->setupUi(toFillin);
463 wipeInfo w = getWipeInfo(value);
466 wpval->start_up->setChecked(true);
469 wpval->start_down->setChecked(true);
472 wpval->start_right->setChecked(true);
475 wpval->start_left->setChecked(true);
478 wpval->start_center->setChecked(true);
483 wpval->end_up->setChecked(true);
486 wpval->end_down->setChecked(true);
489 wpval->end_right->setChecked(true);
492 wpval->end_left->setChecked(true);
495 wpval->end_center->setChecked(true);
498 wpval->start_transp->setValue(w.startTransparency);
499 wpval->end_transp->setValue(w.endTransparency);
500 m_valueItems[paramName] = wpval;
501 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
502 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
503 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
504 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
505 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
506 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
507 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
508 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
509 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
510 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
511 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
512 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
513 //wpval->title->setTitle(na.toElement().text());
514 m_uiItems.append(wpval);
515 } else if (type == "url") {
516 Urlval *cval = new Urlval;
517 cval->setupUi(toFillin);
518 cval->label->setText(paramName);
519 cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
520 m_valueItems[paramName] = cval;
521 cval->urlwidget->setUrl(KUrl(value));
522 connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(collectAllParameters()));
523 connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(collectAllParameters()));
524 m_uiItems.append(cval);
531 m_vbox->addWidget(toFillin);
535 m_vbox->addStretch();
537 if (m_keyframeEditor)
538 m_keyframeEditor->checkVisibleParam();
540 // Make sure all doubleparam spinboxes have the same width, looks much better
541 QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
543 for (int i = 0; i < allWidgets.count(); i++) {
544 if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
546 for (int i = 0; i < allWidgets.count(); i++) {
547 allWidgets.at(i)->setSpinSize(minSize);
551 wipeInfo EffectStackEdit::getWipeInfo(QString value)
554 QString start = value.section(';', 0, 0);
555 QString end = value.section(';', 1, 1).section('=', 1, 1);
557 if (start.startsWith("-100%,0"))
559 else if (start.startsWith("100%,0"))
561 else if (start.startsWith("0%,100%"))
563 else if (start.startsWith("0%,-100%"))
568 if (start.count(':') == 2)
569 info.startTransparency = start.section(':', -1).toInt();
571 info.startTransparency = 100;
573 if (end.startsWith("-100%,0"))
575 else if (end.startsWith("100%,0"))
577 else if (end.startsWith("0%,100%"))
579 else if (end.startsWith("0%,-100%"))
584 if (end.count(':') == 2)
585 info.endTransparency = end.section(':', -1).toInt();
587 info.endTransparency = 100;
592 QString EffectStackEdit::getWipeString(wipeInfo info)
597 switch (info.start) {
599 start = "-100%,0%:100%x100%";
602 start = "100%,0%:100%x100%";
605 start = "0%,100%:100%x100%";
608 start = "0%,-100%:100%x100%";
611 start = "0%,0%:100%x100%";
614 start.append(':' + QString::number(info.startTransparency));
618 end = "-100%,0%:100%x100%";
621 end = "100%,0%:100%x100%";
624 end = "0%,100%:100%x100%";
627 end = "0%,-100%:100%x100%";
630 end = "0%,0%:100%x100%";
633 end.append(':' + QString::number(info.endTransparency));
634 return QString(start + ";-1=" + end);
637 void EffectStackEdit::collectAllParameters()
639 if (m_valueItems.isEmpty() || m_params.isNull()) return;
640 const QDomElement oldparam = m_params.cloneNode().toElement();
641 QDomElement newparam = oldparam.cloneNode().toElement();
642 QDomNodeList namenode = newparam.elementsByTagName("parameter");
644 for (int i = 0; i < namenode.count() ; i++) {
645 QDomNode pa = namenode.item(i);
646 QDomNode na = pa.firstChildElement("name");
647 QString type = pa.attributes().namedItem("type").nodeValue();
648 QString paramName = i18n(na.toElement().text().toUtf8().data());
649 if (type == "complex")
650 paramName.append("complex");
651 else if (type == "position")
652 paramName.append("position");
653 else if (type == "geometry")
654 paramName.append("geometry");
655 else if (type == "keyframe")
656 paramName.append("keyframe");
657 if (type != "simplekeyframe" && !m_valueItems.contains(paramName)) {
658 kDebug() << "// Param: " << paramName << " NOT FOUND";
663 if (type == "double" || type == "constant") {
664 DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
665 setValue = QString::number(doubleparam->getValue());
666 } else if (type == "list") {
667 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
668 setValue = box->itemData(box->currentIndex()).toString();
669 } else if (type == "bool") {
670 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
671 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
672 } else if (type == "color") {
673 ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
674 setValue = choosecolor->getColor().name();
675 } else if (type == "complex") {
676 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
677 namenode.item(i) = complex->getParamDesc();
678 } else if (type == "geometry") {
679 if (KdenliveSettings::on_monitor_effects()) {
680 GeometryWidget *geometry = ((GeometryWidget*)m_valueItems.value(paramName));
681 namenode.item(i).toElement().setAttribute("value", geometry->getValue());
683 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
684 namenode.item(i).toElement().setAttribute("value", geom->getValue());
686 } else if (type == "position") {
687 PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
688 int pos = pedit->getPosition();
689 setValue = QString::number(pos);
690 if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_black") {
691 // Make sure duration is not longer than clip
694 pedit->setPosition(pos);
696 EffectsList::setParameter(newparam, "in", QString::number(m_in));
697 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
699 } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
700 // Make sure duration is not longer than clip
703 pedit->setPosition(pos);
705 EffectsList::setParameter(newparam, "in", QString::number(m_out - pos));
706 EffectsList::setParameter(newparam, "out", QString::number(m_out));
709 } else if (type == "curve") {
710 KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
711 QList<QPointF> points = curve->curve().points();
712 QString number = pa.attributes().namedItem("number").nodeValue();
713 QString inName = pa.attributes().namedItem("inpoints").nodeValue();
714 QString outName = pa.attributes().namedItem("outpoints").nodeValue();
715 int off = pa.attributes().namedItem("min").nodeValue().toInt();
716 int end = pa.attributes().namedItem("max").nodeValue().toInt();
717 EffectsList::setParameter(newparam, number, QString::number(points.count()));
718 for (int j = 0; (j < points.count() && j + off <= end); j++) {
720 in.replace("%i", QString::number(j + off));
721 QString out = outName;
722 out.replace("%i", QString::number(j + off));
723 EffectsList::setParameter(newparam, in, QString::number(points.at(j).x()));
724 EffectsList::setParameter(newparam, out, QString::number(points.at(j).y()));
726 QString depends = pa.attributes().namedItem("depends").nodeValue();
727 if (!depends.isEmpty())
728 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
729 } else if (type == "bezier_spline") {
730 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
731 setValue = widget->spline();
732 QString depends = pa.attributes().namedItem("depends").nodeValue();
733 if (!depends.isEmpty())
734 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
736 } else if (type == "roto-spline") {
737 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
738 setValue = widget->getSpline();
740 } else if (type == "wipe") {
741 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
743 if (wp->start_left->isChecked())
745 else if (wp->start_right->isChecked())
747 else if (wp->start_up->isChecked())
749 else if (wp->start_down->isChecked())
751 else if (wp->start_center->isChecked())
755 info.startTransparency = wp->start_transp->value();
757 if (wp->end_left->isChecked())
759 else if (wp->end_right->isChecked())
761 else if (wp->end_up->isChecked())
763 else if (wp->end_down->isChecked())
765 else if (wp->end_center->isChecked())
769 info.endTransparency = wp->end_transp->value();
771 setValue = getWipeString(info);
772 } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
773 QDomElement elem = pa.toElement();
774 QString realName = i18n(na.toElement().text().toUtf8().data());
775 QString val = m_keyframeEditor->getValue(realName);
776 elem.setAttribute("keyframes", val);
778 if (m_keyframeEditor->isVisibleParam(realName))
779 elem.setAttribute("intimeline", "1");
780 else if (elem.hasAttribute("intimeline"))
781 elem.removeAttribute("intimeline");
782 } else if (type == "url") {
783 KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
784 setValue = req->url().path();
787 if (!setValue.isNull())
788 pa.attributes().namedItem("value").setNodeValue(setValue);
791 emit parameterChanged(oldparam, newparam);
794 void EffectStackEdit::clearAllItems()
797 m_valueItems.clear();
799 /*while (!m_items.isEmpty()) {
800 QWidget *die = m_items.takeFirst();
804 //qDeleteAll(m_uiItems);
806 while ((child = m_vbox->takeAt(0)) != 0) {
807 QWidget *wid = child->widget();
811 m_keyframeEditor = NULL;
815 void EffectStackEdit::slotSyncEffectsPos(int pos)
817 emit syncEffectsPos(pos);