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}\
98 QProgressBar:horizontal#dragOnly {background: %1} QProgressBar:horizontal:hover#dragOnly {background: %3} QProgressBar:horizontal:hover {border: 1px solid %3;border-right: 0px;}\
99 QProgressBar::chunk:horizontal {background: %1;} QProgressBar::chunk:horizontal:hover {background: %3;}\
100 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;}\
101 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;}\
102 QAbstractSpinBox::up-button#dragBox {width:0px;padding:0px;} QAbstractSpinBox[inTimeline=\"true\"]#dragBox { border: 1px solid %2;} QAbstractSpinBox:hover#dragBox {border: 1px solid %3;} ")
103 .arg(dark_bg.name()).arg(selected_bg.name()).arg(hover_bg.name()).arg(light_bg.name()));
104 setStyleSheet(stylesheet);
106 setWidget(m_baseWidget);
107 setWidgetResizable(true);
108 m_vbox = new QVBoxLayout(m_baseWidget);
109 m_vbox->setContentsMargins(0, 0, 0, 0);
110 m_vbox->setSpacing(2);
113 EffectStackEdit::~EffectStackEdit()
119 void EffectStackEdit::setFrameSize(QPoint p)
122 QDomNodeList namenode = m_params.elementsByTagName("parameter");
123 for (int i = 0; i < namenode.count() ; i++) {
124 QDomNode pa = namenode.item(i);
125 QDomNode na = pa.firstChildElement("name");
126 QString type = pa.attributes().namedItem("type").nodeValue();
127 QString paramName = i18n(na.toElement().text().toUtf8().data());
129 if (type == "geometry") {
130 if (!KdenliveSettings::on_monitor_effects()) {
131 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
132 geom->setFrameSize(m_frameSize);
136 if (m_geometryWidget) m_geometryWidget->setFrameSize(m_frameSize);
143 void EffectStackEdit::updateTimecodeFormat()
145 if (m_keyframeEditor)
146 m_keyframeEditor->updateTimecodeFormat();
148 QDomNodeList namenode = m_params.elementsByTagName("parameter");
149 for (int i = 0; i < namenode.count() ; i++) {
150 QDomNode pa = namenode.item(i);
151 QDomNode na = pa.firstChildElement("name");
152 QString type = pa.attributes().namedItem("type").nodeValue();
153 QString paramName = i18n(na.toElement().text().toUtf8().data());
155 if (type == "geometry") {
156 if (KdenliveSettings::on_monitor_effects()) {
157 if (m_geometryWidget) m_geometryWidget->updateTimecodeFormat();
159 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
160 geom->updateTimecodeFormat();
163 } else if (type == "position") {
164 PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
165 posi->updateTimecodeFormat();
167 } else if (type == "roto-spline") {
168 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems[paramName]);
169 widget->updateTimecodeFormat();
174 void EffectStackEdit::meetDependency(const QString& name, QString type, QString value)
176 if (type == "curve") {
177 KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
179 int color = value.toInt();
180 curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
182 } else if (type == "bezier_spline") {
183 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
185 widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10)));
190 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
196 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
198 m_params.setAttribute(name, value);
200 if (name == "disable") {
201 // if effect is disabled, disable parameters widget
202 bool enabled = value.toInt() == 0 || !KdenliveSettings::disable_effect_parameters();
204 emit effectStateChanged(enabled);
208 void EffectStackEdit::transferParamDesc(const QDomElement d, int pos, int in, int out, bool isEffect)
211 if (m_keyframeEditor) delete m_keyframeEditor;
212 m_keyframeEditor = NULL;
216 if (m_params.isNull()) {
217 // kDebug() << "// EMPTY EFFECT STACK";
221 QDomNodeList namenode = m_params.elementsByTagName("parameter");
223 QFile debugFile("/tmp/namenodes.txt");
224 if (debugFile.open(QFile::WriteOnly | QFile::Truncate)) {
225 QTextStream out(&debugFile);
226 QTextStream out2(stdout);
227 for (int i = 0; i < namenode.size(); i++) {
229 namenode.at(i).save(out, 2);
231 namenode.at(i).save(out2, 2);
235 QDomElement e = m_params.toElement();
236 const int minFrame = e.attribute("start").toInt();
237 const int maxFrame = e.attribute("end").toInt();
239 bool disable = d.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
240 setEnabled(!disable);
245 for (int i = 0; i < namenode.count() ; i++) {
246 QDomElement pa = namenode.item(i).toElement();
247 QDomElement na = pa.firstChildElement("name");
248 QDomElement commentElem = pa.firstChildElement("comment");
249 QString type = pa.attribute("type");
250 QString paramName = i18n(na.text().toUtf8().data());
252 if (!commentElem.isNull())
253 comment = i18n(commentElem.text().toUtf8().data());
254 QWidget * toFillin = new QWidget(m_baseWidget);
255 QString value = pa.attribute("value").isNull() ?
256 pa.attribute("default") : pa.attribute("value");
258 /** Currently supported parameter types are:
259 * constant (=double): a slider with an integer value (use the "factor" attribute to divide the value so that you can get a double
260 * list: a combobox containing a list of values to choose
262 * complex: designed for keyframe parameters, but old and not finished, do not use
263 * geometry: a rectangle that can be moved & resized, with possible keyframes, used in composite transition
264 * keyframe: a list widget with a list of entries (position and value)
265 * color: a color chooser button
266 * position: a slider representing the position of a frame in the current clip
267 * curve: a single curve representing multiple points
268 * wipe: a widget designed for the wipe transition, allowing to choose a position (left, right, top,...)
271 if (type == "double" || type == "constant") {
274 if (pa.attribute("min").startsWith('%'))
275 min = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("min"));
277 min = pa.attribute("min").toInt();
278 if (pa.attribute("max").startsWith('%'))
279 max = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("max"));
281 max = pa.attribute("max").toInt();
283 DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, (int)(value.toDouble() + 0.5), min, max,
284 pa.attribute("default").toInt(), comment, -1, pa.attribute("suffix"), this);
285 m_vbox->addWidget(doubleparam);
286 m_valueItems[paramName] = doubleparam;
287 connect(doubleparam, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
288 connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
289 } else if (type == "list") {
290 Listval *lsval = new Listval;
291 lsval->setupUi(toFillin);
292 QStringList listitems = pa.attribute("paramlist").split(',');
293 QDomElement list = pa.firstChildElement("paramlistdisplay");
294 QStringList listitemsdisplay;
295 if (!list.isNull()) listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
296 else listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
297 if (listitemsdisplay.count() != listitems.count())
298 listitemsdisplay = listitems;
299 lsval->list->setIconSize(QSize(30, 30));
300 for (int i = 0; i < listitems.count(); i++) {
301 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
302 QString entry = listitems.at(i);
303 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
304 if (!EffectStackEdit::iconCache.contains(entry)) {
306 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
308 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
311 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
312 lsval->name->setText(paramName);
313 lsval->labelComment->setText(comment);
314 lsval->widgetComment->setHidden(true);
315 m_valueItems[paramName] = lsval;
316 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
317 if (!comment.isEmpty())
318 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
319 m_uiItems.append(lsval);
320 } else if (type == "bool") {
321 Boolval *bval = new Boolval;
322 bval->setupUi(toFillin);
323 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
324 bval->name->setText(paramName);
325 bval->labelComment->setText(comment);
326 bval->widgetComment->setHidden(true);
327 m_valueItems[paramName] = bval;
328 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
329 if (!comment.isEmpty())
330 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
331 m_uiItems.append(bval);
332 } else if (type == "complex") {
333 ComplexParameter *pl = new ComplexParameter;
334 pl->setupParam(d, pa.attribute("name"), 0, 100);
335 m_vbox->addWidget(pl);
336 m_valueItems[paramName+"complex"] = pl;
337 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
338 } else if (type == "geometry") {
339 if (KdenliveSettings::on_monitor_effects()) {
340 m_geometryWidget = new GeometryWidget(m_monitor, m_timecode, pos, isEffect, m_params.hasAttribute("showrotation"), this);
341 m_geometryWidget->setFrameSize(m_frameSize);
342 m_geometryWidget->slotShowScene(!disable);
343 // connect this before setupParam to make sure the monitor scene shows up at startup
344 connect(m_geometryWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
345 connect(m_geometryWidget, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
346 if (minFrame == maxFrame)
347 m_geometryWidget->setupParam(pa, m_in, m_out);
349 m_geometryWidget->setupParam(pa, minFrame, maxFrame);
350 m_vbox->addWidget(m_geometryWidget);
351 m_valueItems[paramName+"geometry"] = m_geometryWidget;
352 connect(m_geometryWidget, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
353 connect(this, SIGNAL(syncEffectsPos(int)), m_geometryWidget, SLOT(slotSyncPosition(int)));
354 connect(this, SIGNAL(effectStateChanged(bool)), m_geometryWidget, SLOT(slotShowScene(bool)));
356 Geometryval *geo = new Geometryval(m_profile, m_timecode, m_frameSize, pos);
357 if (minFrame == maxFrame)
358 geo->setupParam(pa, m_in, m_out);
360 geo->setupParam(pa, minFrame, maxFrame);
361 m_vbox->addWidget(geo);
362 m_valueItems[paramName+"geometry"] = geo;
363 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
364 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
365 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
367 } else if (type == "addedgeometry") {
368 // this is a parameter that should be linked to the geometry widget, for example rotation, shear, ...
369 if (m_geometryWidget) m_geometryWidget->addParameter(pa);
370 } else if (type == "keyframe" || type == "simplekeyframe") {
371 // keyframe editor widget
372 if (m_keyframeEditor == NULL) {
374 if (pa.attribute("widget") == "corners") {
375 // we want a corners-keyframe-widget
376 CornersWidget *corners = new CornersWidget(m_monitor, pa, m_in, m_in + m_out, m_timecode, e.attribute("active_keyframe", "-1").toInt(), this);
377 corners->slotShowScene(!disable);
378 connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
379 connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
380 connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
381 geo = static_cast<KeyframeEdit *>(corners);
383 geo = new KeyframeEdit(pa, m_in, m_in + m_out, m_timecode, e.attribute("active_keyframe", "-1").toInt());
385 m_vbox->addWidget(geo);
386 m_valueItems[paramName+"keyframe"] = geo;
387 m_keyframeEditor = geo;
388 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
389 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
390 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
392 // we already have a keyframe editor, so just add another column for the new param
393 m_keyframeEditor->addParameter(pa);
395 } else if (type == "color") {
396 if (value.startsWith('#'))
397 value = value.replace('#', "0x");
399 ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, QColor(value.toUInt(&ok, 16)), this);
400 m_vbox->addWidget(choosecolor);
401 m_valueItems[paramName] = choosecolor;
402 connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
403 connect(choosecolor, SIGNAL(modified()) , this, SLOT(collectAllParameters()));
404 } else if (type == "position") {
405 int pos = value.toInt();
406 if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
408 } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
409 // fadeout position starts from clip end
412 PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_timecode);
413 m_vbox->addWidget(posedit);
414 m_valueItems[paramName+"position"] = posedit;
415 connect(posedit, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
416 } else if (type == "curve") {
417 KisCurveWidget *curve = new KisCurveWidget(this);
418 curve->setMaxPoints(pa.attribute("max").toInt());
419 QList<QPointF> points;
420 int number = EffectsList::parameter(e, pa.attribute("number")).toInt();
421 QString inName = pa.attribute("inpoints");
422 QString outName = pa.attribute("outpoints");
423 int start = pa.attribute("min").toInt();
424 for (int j = start; j <= number; j++) {
426 in.replace("%i", QString::number(j));
427 QString out = outName;
428 out.replace("%i", QString::number(j));
429 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
431 if (!points.isEmpty())
432 curve->setCurve(KisCubicCurve(points));
433 QSpinBox *spinin = new QSpinBox();
434 spinin->setRange(0, 1000);
435 QSpinBox *spinout = new QSpinBox();
436 spinout->setRange(0, 1000);
437 curve->setupInOutControls(spinin, spinout, 0, 1000);
438 m_vbox->addWidget(curve);
439 m_vbox->addWidget(spinin);
440 m_vbox->addWidget(spinout);
442 connect(curve, SIGNAL(modified()), this, SLOT(collectAllParameters()));
443 m_valueItems[paramName] = curve;
445 QString depends = pa.attribute("depends");
446 if (!depends.isEmpty())
447 meetDependency(paramName, type, EffectsList::parameter(e, depends));
448 } else if (type == "bezier_spline") {
449 BezierSplineWidget *widget = new BezierSplineWidget(value, this);
451 m_vbox->addWidget(widget);
452 m_valueItems[paramName] = widget;
453 connect(widget, SIGNAL(modified()), this, SLOT(collectAllParameters()));
454 QString depends = pa.attribute("depends");
455 if (!depends.isEmpty())
456 meetDependency(paramName, type, EffectsList::parameter(e, depends));
458 } else if (type == "roto-spline") {
459 RotoWidget *roto = new RotoWidget(value, m_monitor, m_in, m_out, m_timecode, this);
460 roto->slotShowScene(!disable);
461 connect(roto, SIGNAL(valueChanged()), this, SLOT(collectAllParameters()));
462 connect(roto, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
463 connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
464 connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
465 connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
466 m_vbox->addWidget(roto);
467 m_valueItems[paramName] = roto;
469 } else if (type == "wipe") {
470 Wipeval *wpval = new Wipeval;
471 wpval->setupUi(toFillin);
472 wipeInfo w = getWipeInfo(value);
475 wpval->start_up->setChecked(true);
478 wpval->start_down->setChecked(true);
481 wpval->start_right->setChecked(true);
484 wpval->start_left->setChecked(true);
487 wpval->start_center->setChecked(true);
492 wpval->end_up->setChecked(true);
495 wpval->end_down->setChecked(true);
498 wpval->end_right->setChecked(true);
501 wpval->end_left->setChecked(true);
504 wpval->end_center->setChecked(true);
507 wpval->start_transp->setValue(w.startTransparency);
508 wpval->end_transp->setValue(w.endTransparency);
509 m_valueItems[paramName] = wpval;
510 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
511 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
512 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
513 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
514 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
515 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
516 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
517 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
518 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
519 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
520 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
521 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
522 //wpval->title->setTitle(na.toElement().text());
523 m_uiItems.append(wpval);
524 } else if (type == "url") {
525 Urlval *cval = new Urlval;
526 cval->setupUi(toFillin);
527 cval->label->setText(paramName);
528 cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
529 m_valueItems[paramName] = cval;
530 cval->urlwidget->setUrl(KUrl(value));
531 connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(collectAllParameters()));
532 connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(collectAllParameters()));
533 m_uiItems.append(cval);
540 m_vbox->addWidget(toFillin);
544 m_vbox->addStretch();
546 if (m_keyframeEditor)
547 m_keyframeEditor->checkVisibleParam();
549 // Make sure all doubleparam spinboxes have the same width, looks much better
550 QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
552 for (int i = 0; i < allWidgets.count(); i++) {
553 if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
555 for (int i = 0; i < allWidgets.count(); i++) {
556 allWidgets.at(i)->setSpinSize(minSize);
560 wipeInfo EffectStackEdit::getWipeInfo(QString value)
563 QString start = value.section(';', 0, 0);
564 QString end = value.section(';', 1, 1).section('=', 1, 1);
566 if (start.startsWith("-100%,0"))
568 else if (start.startsWith("100%,0"))
570 else if (start.startsWith("0%,100%"))
572 else if (start.startsWith("0%,-100%"))
577 if (start.count(':') == 2)
578 info.startTransparency = start.section(':', -1).toInt();
580 info.startTransparency = 100;
582 if (end.startsWith("-100%,0"))
584 else if (end.startsWith("100%,0"))
586 else if (end.startsWith("0%,100%"))
588 else if (end.startsWith("0%,-100%"))
593 if (end.count(':') == 2)
594 info.endTransparency = end.section(':', -1).toInt();
596 info.endTransparency = 100;
601 QString EffectStackEdit::getWipeString(wipeInfo info)
606 switch (info.start) {
608 start = "-100%,0%:100%x100%";
611 start = "100%,0%:100%x100%";
614 start = "0%,100%:100%x100%";
617 start = "0%,-100%:100%x100%";
620 start = "0%,0%:100%x100%";
623 start.append(':' + QString::number(info.startTransparency));
627 end = "-100%,0%:100%x100%";
630 end = "100%,0%:100%x100%";
633 end = "0%,100%:100%x100%";
636 end = "0%,-100%:100%x100%";
639 end = "0%,0%:100%x100%";
642 end.append(':' + QString::number(info.endTransparency));
643 return QString(start + ";-1=" + end);
646 void EffectStackEdit::collectAllParameters()
648 if (m_valueItems.isEmpty() || m_params.isNull()) return;
649 const QDomElement oldparam = m_params.cloneNode().toElement();
650 QDomElement newparam = oldparam.cloneNode().toElement();
651 QDomNodeList namenode = newparam.elementsByTagName("parameter");
653 for (int i = 0; i < namenode.count() ; i++) {
654 QDomNode pa = namenode.item(i);
655 QDomNode na = pa.firstChildElement("name");
656 QString type = pa.attributes().namedItem("type").nodeValue();
657 QString paramName = i18n(na.toElement().text().toUtf8().data());
658 if (type == "complex")
659 paramName.append("complex");
660 else if (type == "position")
661 paramName.append("position");
662 else if (type == "geometry")
663 paramName.append("geometry");
664 else if (type == "keyframe")
665 paramName.append("keyframe");
666 if (type != "simplekeyframe" && type != "fixed" && type != "addedgeometry" && !m_valueItems.contains(paramName)) {
667 kDebug() << "// Param: " << paramName << " NOT FOUND";
672 if (type == "double" || type == "constant") {
673 DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
674 setValue = QString::number(doubleparam->getValue());
675 } else if (type == "list") {
676 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
677 setValue = box->itemData(box->currentIndex()).toString();
678 } else if (type == "bool") {
679 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
680 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
681 } else if (type == "color") {
682 ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
683 setValue = choosecolor->getColor().name();
684 } else if (type == "complex") {
685 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
686 namenode.item(i) = complex->getParamDesc();
687 } else if (type == "geometry") {
688 if (KdenliveSettings::on_monitor_effects()) {
689 if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getValue());
691 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
692 namenode.item(i).toElement().setAttribute("value", geom->getValue());
694 } else if (type == "addedgeometry") {
695 namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getExtraValue(namenode.item(i).toElement().attribute("name")));
696 } else if (type == "position") {
697 PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
698 int pos = pedit->getPosition();
699 setValue = QString::number(pos);
700 if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_black") {
701 // Make sure duration is not longer than clip
704 pedit->setPosition(pos);
706 EffectsList::setParameter(newparam, "in", QString::number(m_in));
707 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
709 } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
710 // Make sure duration is not longer than clip
713 pedit->setPosition(pos);
715 EffectsList::setParameter(newparam, "in", QString::number(m_out - pos));
716 EffectsList::setParameter(newparam, "out", QString::number(m_out));
719 } else if (type == "curve") {
720 KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
721 QList<QPointF> points = curve->curve().points();
722 QString number = pa.attributes().namedItem("number").nodeValue();
723 QString inName = pa.attributes().namedItem("inpoints").nodeValue();
724 QString outName = pa.attributes().namedItem("outpoints").nodeValue();
725 int off = pa.attributes().namedItem("min").nodeValue().toInt();
726 int end = pa.attributes().namedItem("max").nodeValue().toInt();
727 EffectsList::setParameter(newparam, number, QString::number(points.count()));
728 for (int j = 0; (j < points.count() && j + off <= end); j++) {
730 in.replace("%i", QString::number(j + off));
731 QString out = outName;
732 out.replace("%i", QString::number(j + off));
733 EffectsList::setParameter(newparam, in, QString::number(points.at(j).x()));
734 EffectsList::setParameter(newparam, out, QString::number(points.at(j).y()));
736 QString depends = pa.attributes().namedItem("depends").nodeValue();
737 if (!depends.isEmpty())
738 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
739 } else if (type == "bezier_spline") {
740 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
741 setValue = widget->spline();
742 QString depends = pa.attributes().namedItem("depends").nodeValue();
743 if (!depends.isEmpty())
744 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
746 } else if (type == "roto-spline") {
747 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
748 setValue = widget->getSpline();
750 } else if (type == "wipe") {
751 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
753 if (wp->start_left->isChecked())
755 else if (wp->start_right->isChecked())
757 else if (wp->start_up->isChecked())
759 else if (wp->start_down->isChecked())
761 else if (wp->start_center->isChecked())
765 info.startTransparency = wp->start_transp->value();
767 if (wp->end_left->isChecked())
769 else if (wp->end_right->isChecked())
771 else if (wp->end_up->isChecked())
773 else if (wp->end_down->isChecked())
775 else if (wp->end_center->isChecked())
779 info.endTransparency = wp->end_transp->value();
781 setValue = getWipeString(info);
782 } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
783 QDomElement elem = pa.toElement();
784 QString realName = i18n(na.toElement().text().toUtf8().data());
785 QString val = m_keyframeEditor->getValue(realName);
786 elem.setAttribute("keyframes", val);
788 if (m_keyframeEditor->isVisibleParam(realName))
789 elem.setAttribute("intimeline", "1");
790 else if (elem.hasAttribute("intimeline"))
791 elem.removeAttribute("intimeline");
792 } else if (type == "url") {
793 KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
794 setValue = req->url().path();
797 if (!setValue.isNull())
798 pa.attributes().namedItem("value").setNodeValue(setValue);
801 emit parameterChanged(oldparam, newparam);
804 void EffectStackEdit::clearAllItems()
807 m_valueItems.clear();
809 /*while (!m_items.isEmpty()) {
810 QWidget *die = m_items.takeFirst();
814 //qDeleteAll(m_uiItems);
816 while ((child = m_vbox->takeAt(0)) != 0) {
817 QWidget *wid = child->widget();
821 m_keyframeEditor = NULL;
822 m_geometryWidget = NULL;
826 void EffectStackEdit::slotSyncEffectsPos(int pos)
828 emit syncEffectsPos(pos);