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 "ui_keywordval_ui.h"
24 #include "ui_fontval_ui.h"
25 #include "complexparameter.h"
26 #include "geometryval.h"
27 #include "positionedit.h"
28 #include "projectlist.h"
29 #include "effectslist.h"
30 #include "kdenlivesettings.h"
31 #include "profilesdialog.h"
32 #include "kis_curve_widget.h"
33 #include "kis_cubic_curve.h"
34 #include "choosecolorwidget.h"
35 #include "geometrywidget.h"
36 #include "colortools.h"
37 #include "doubleparameterwidget.h"
38 #include "cornerswidget.h"
39 #include "beziercurve/beziersplinewidget.h"
41 #include "rotoscoping/rotowidget.h"
46 #include <KFileDialog>
48 #include <QVBoxLayout>
50 #include <QPushButton>
52 #include <QScrollArea>
54 // For QDomNode debugging (output into files); leaving here as sample code.
58 class Boolval: public QWidget, public Ui::Boolval_UI
62 class Listval: public QWidget, public Ui::Listval_UI
66 class Wipeval: public QWidget, public Ui::Wipeval_UI
70 class Urlval: public QWidget, public Ui::Urlval_UI
74 class Keywordval: public QWidget, public Ui::Keywordval_UI
78 class Fontval: public QWidget, public Ui::Fontval_UI
82 QMap<QString, QImage> EffectStackEdit::iconCache;
84 EffectStackEdit::EffectStackEdit(Monitor *monitor, QWidget *parent) :
88 m_keyframeEditor(NULL),
90 m_geometryWidget(NULL),
93 m_baseWidget = new QWidget(this);
94 m_metaInfo.monitor = monitor;
95 m_metaInfo.trackMode = false;
96 setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
97 setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
98 setFrameStyle(QFrame::NoFrame);
99 setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
101 setStyleSheet(CollapsibleEffect::getStyleSheet(palette()));
102 setWidget(m_baseWidget);
103 /*m_vbox = new QVBoxLayout(m_baseWidget);
104 m_vbox->setContentsMargins(0, 0, 0, 0);
105 m_vbox->setSpacing(2); */
106 setWidgetResizable(true);
109 EffectStackEdit::~EffectStackEdit()
115 Monitor *EffectStackEdit::monitor()
117 return m_metaInfo.monitor;
120 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
122 m_metaInfo.profile = profile;
123 m_metaInfo.timecode = t;
126 void EffectStackEdit::setFrameSize(QPoint p)
128 m_metaInfo.frameSize = p;
131 QDomNodeList namenode = m_params.elementsByTagName("parameter");
132 for (int i = 0; i < namenode.count() ; i++) {
133 QDomNode pa = namenode.item(i);
134 QDomElement na = pa.firstChildElement("name");
135 QString type = pa.attributes().namedItem("type").nodeValue();
136 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
138 if (type == "geometry") {
139 if (!KdenliveSettings::on_monitor_effects()) {
140 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
141 geom->setFrameSize(m_frameSize);
145 if (m_geometryWidget) m_geometryWidget->setFrameSize(m_frameSize);
152 void EffectStackEdit::updateTimecodeFormat()
154 if (m_paramWidget) m_paramWidget->updateTimecodeFormat();
157 void EffectStackEdit::meetDependency(const QString& name, QString type, QString value)
159 if (type == "curve") {
160 KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
162 int color = value.toInt();
163 curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
165 } else if (type == "bezier_spline") {
166 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
168 widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10)));
173 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
175 m_params.setAttribute(name, value);
177 if (name == "disable") {
178 // if effect is disabled, disable parameters widget
179 bool enabled = value.toInt() == 0 || !KdenliveSettings::disable_effect_parameters();
181 emit effectStateChanged(enabled);
185 void EffectStackEdit::transferParamDesc(const QDomElement &d, ItemInfo info, bool /*isEffect*/)
187 if (m_paramWidget) delete m_paramWidget;
188 m_paramWidget = new ParameterContainer(d, info, &m_metaInfo, m_baseWidget);
189 connect (m_paramWidget, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)));
191 connect(m_paramWidget, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)));
193 connect (this, SIGNAL(syncEffectsPos(int)), m_paramWidget, SIGNAL(syncEffectsPos(int)));
194 connect (m_paramWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
195 connect (m_paramWidget, SIGNAL(seekTimeline(int)), this, SIGNAL(seekTimeline(int)));
199 if (m_keyframeEditor) delete m_keyframeEditor;
200 m_keyframeEditor = NULL;
202 m_in = isEffect ? info.cropStart.frames(KdenliveSettings::project_fps()) : info.startPos.frames(KdenliveSettings::project_fps());
203 m_out = isEffect ? (info.cropStart + info.cropDuration).frames(KdenliveSettings::project_fps()) - 1 : info.endPos.frames(KdenliveSettings::project_fps());
204 if (m_params.isNull()) {
205 // kDebug() << "// EMPTY EFFECT STACK";
209 QDomNodeList namenode = m_params.elementsByTagName("parameter");
211 QFile debugFile("/tmp/namenodes.txt");
212 if (debugFile.open(QFile::WriteOnly | QFile::Truncate)) {
213 QTextStream out(&debugFile);
214 QTextStream out2(stdout);
215 for (int i = 0; i < namenode.size(); i++) {
217 namenode.at(i).save(out, 2);
219 namenode.at(i).save(out2, 2);
223 int minFrame = d.attribute("start").toInt();
224 int maxFrame = d.attribute("end").toInt();
225 // In transitions, maxFrame is in fact one frame after the end of transition
226 if (maxFrame > 0) maxFrame --;
228 bool disable = d.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
229 setEnabled(!disable);
234 for (int i = 0; i < namenode.count() ; i++) {
235 QDomElement pa = namenode.item(i).toElement();
236 QDomElement na = pa.firstChildElement("name");
237 QDomElement commentElem = pa.firstChildElement("comment");
238 QString type = pa.attribute("type");
239 QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
241 if (!commentElem.isNull())
242 comment = i18n(commentElem.text().toUtf8().data());
243 QString value = pa.attribute("value").isNull() ?
244 pa.attribute("default") : pa.attribute("value");
249 if (type == "double" || type == "constant") {
252 if (pa.attribute("min").contains('%'))
253 min = ProfilesDialog::getStringEval(m_profile, pa.attribute("min"), m_frameSize);
255 min = pa.attribute("min").toDouble();
256 if (pa.attribute("max").contains('%'))
257 max = ProfilesDialog::getStringEval(m_profile, pa.attribute("max"), m_frameSize);
259 max = pa.attribute("max").toDouble();
261 DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, value.toDouble(), min, max,
262 pa.attribute("default").toDouble(), comment, -1, pa.attribute("suffix"), pa.attribute("decimals").toInt(), this);
263 m_vbox->addWidget(doubleparam);
264 m_valueItems[paramName] = doubleparam;
265 connect(doubleparam, SIGNAL(valueChanged(double)), this, SLOT(collectAllParameters()));
266 connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
267 } else if (type == "list") {
268 Listval *lsval = new Listval;
269 QWidget * toFillin = new QWidget(m_baseWidget);
270 lsval->setupUi(toFillin);
271 m_vbox->addWidget(toFillin);
272 QStringList listitems = pa.attribute("paramlist").split(';');
273 if (listitems.count() == 1) {
274 // probably custom effect created before change to ';' as separator
275 listitems = pa.attribute("paramlist").split(',');
277 QDomElement list = pa.firstChildElement("paramlistdisplay");
278 QStringList listitemsdisplay;
279 if (!list.isNull()) {
280 listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
282 listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
284 if (listitemsdisplay.count() != listitems.count())
285 listitemsdisplay = listitems;
286 lsval->list->setIconSize(QSize(30, 30));
287 for (int i = 0; i < listitems.count(); i++) {
288 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
289 QString entry = listitems.at(i);
290 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
291 if (!EffectStackEdit::iconCache.contains(entry)) {
293 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
295 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
298 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
299 lsval->name->setText(paramName);
300 lsval->labelComment->setText(comment);
301 lsval->widgetComment->setHidden(true);
302 m_valueItems[paramName] = lsval;
303 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
304 if (!comment.isEmpty())
305 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
306 m_uiItems.append(lsval);
307 } else if (type == "bool") {
308 Boolval *bval = new Boolval;
309 QWidget * toFillin = new QWidget(m_baseWidget);
310 bval->setupUi(toFillin);
311 m_vbox->addWidget(toFillin);
312 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
313 bval->name->setText(paramName);
314 bval->labelComment->setText(comment);
315 bval->widgetComment->setHidden(true);
316 m_valueItems[paramName] = bval;
317 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
318 if (!comment.isEmpty())
319 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
320 m_uiItems.append(bval);
321 } else if (type == "complex") {
322 ComplexParameter *pl = new ComplexParameter;
323 pl->setupParam(d, pa.attribute("name"), 0, 100);
324 m_vbox->addWidget(pl);
325 m_valueItems[paramName+"complex"] = pl;
326 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
327 } else if (type == "geometry") {
328 if (KdenliveSettings::on_monitor_effects()) {
329 m_geometryWidget = new GeometryWidget(m_monitor, m_timecode, isEffect ? 0 : qMax(0, (int)info.startPos.frames(KdenliveSettings::project_fps())), isEffect, m_params.hasAttribute("showrotation"), this);
330 m_geometryWidget->setFrameSize(m_frameSize);
331 m_geometryWidget->slotShowScene(!disable);
332 // connect this before setupParam to make sure the monitor scene shows up at startup
333 connect(m_geometryWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
334 connect(m_geometryWidget, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
335 if (minFrame == maxFrame)
336 m_geometryWidget->setupParam(pa, m_in, m_out);
338 m_geometryWidget->setupParam(pa, minFrame, maxFrame);
339 m_vbox->addWidget(m_geometryWidget);
340 m_valueItems[paramName+"geometry"] = m_geometryWidget;
341 connect(m_geometryWidget, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
342 connect(this, SIGNAL(syncEffectsPos(int)), m_geometryWidget, SLOT(slotSyncPosition(int)));
343 connect(this, SIGNAL(effectStateChanged(bool)), m_geometryWidget, SLOT(slotShowScene(bool)));
345 Geometryval *geo = new Geometryval(m_profile, m_timecode, m_frameSize, isEffect ? 0 : qMax(0, (int)info.startPos.frames(KdenliveSettings::project_fps())));
346 if (minFrame == maxFrame)
347 geo->setupParam(pa, m_in, m_out);
349 geo->setupParam(pa, minFrame, maxFrame);
350 m_vbox->addWidget(geo);
351 m_valueItems[paramName+"geometry"] = geo;
352 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
353 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
354 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
356 } else if (type == "addedgeometry") {
357 // this is a parameter that should be linked to the geometry widget, for example rotation, shear, ...
358 if (m_geometryWidget) m_geometryWidget->addParameter(pa);
359 } else if (type == "keyframe" || type == "simplekeyframe") {
360 // keyframe editor widget
361 if (m_keyframeEditor == NULL) {
363 if (pa.attribute("widget") == "corners") {
364 // we want a corners-keyframe-widget
365 CornersWidget *corners = new CornersWidget(m_monitor, pa, m_in, m_out, m_timecode, d.attribute("active_keyframe", "-1").toInt(), this);
366 corners->slotShowScene(!disable);
367 connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
368 connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
369 connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
370 geo = static_cast<KeyframeEdit *>(corners);
372 geo = new KeyframeEdit(pa, m_in, m_out, m_timecode, d.attribute("active_keyframe", "-1").toInt());
374 m_vbox->addWidget(geo);
375 m_valueItems[paramName+"keyframe"] = geo;
376 m_keyframeEditor = geo;
377 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
378 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
379 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
381 // we already have a keyframe editor, so just add another column for the new param
382 m_keyframeEditor->addParameter(pa);
384 } else if (type == "color") {
385 ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, value, this);
386 choosecolor->setAlphaChannelEnabled(pa.attribute("alpha") == "1");
387 m_vbox->addWidget(choosecolor);
388 m_valueItems[paramName] = choosecolor;
389 connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
390 connect(choosecolor, SIGNAL(modified()) , this, SLOT(collectAllParameters()));
391 } else if (type == "position") {
392 int pos = value.toInt();
393 if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
395 } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
396 // fadeout position starts from clip end
399 PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_timecode);
400 m_vbox->addWidget(posedit);
401 m_valueItems[paramName+"position"] = posedit;
402 connect(posedit, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
403 } else if (type == "curve") {
404 KisCurveWidget *curve = new KisCurveWidget(this);
405 curve->setMaxPoints(pa.attribute("max").toInt());
406 QList<QPointF> points;
408 if (d.attribute("version").toDouble() > 0.2) {
409 number = EffectsList::parameter(d, pa.attribute("number")).toDouble() * 10;
411 number = EffectsList::parameter(d, 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(d, in).toDouble(), EffectsList::parameter(d, 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(d, 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(d, depends));
450 } else if (type == "roto-spline") {
451 RotoWidget *roto = new RotoWidget(value, m_monitor, info, 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 QWidget * toFillin = new QWidget(m_baseWidget);
464 wpval->setupUi(toFillin);
465 m_vbox->addWidget(toFillin);
466 wipeInfo w = getWipeInfo(value);
469 wpval->start_up->setChecked(true);
472 wpval->start_down->setChecked(true);
475 wpval->start_right->setChecked(true);
478 wpval->start_left->setChecked(true);
481 wpval->start_center->setChecked(true);
486 wpval->end_up->setChecked(true);
489 wpval->end_down->setChecked(true);
492 wpval->end_right->setChecked(true);
495 wpval->end_left->setChecked(true);
498 wpval->end_center->setChecked(true);
501 wpval->start_transp->setValue(w.startTransparency);
502 wpval->end_transp->setValue(w.endTransparency);
503 m_valueItems[paramName] = wpval;
504 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
505 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
506 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
507 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
508 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
509 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
510 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
511 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
512 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
513 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
514 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
515 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
516 //wpval->title->setTitle(na.toElement().text());
517 m_uiItems.append(wpval);
518 } else if (type == "url") {
519 Urlval *cval = new Urlval;
520 QWidget * toFillin = new QWidget(m_baseWidget);
521 cval->setupUi(toFillin);
522 m_vbox->addWidget(toFillin);
523 cval->label->setText(paramName);
524 cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
525 m_valueItems[paramName] = cval;
526 cval->urlwidget->setUrl(KUrl(value));
527 connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(collectAllParameters()));
528 connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(collectAllParameters()));
529 m_uiItems.append(cval);
530 } else if (type == "keywords") {
531 Keywordval* kval = new Keywordval;
532 QWidget * toFillin = new QWidget(m_baseWidget);
533 kval->setupUi(toFillin);
534 m_vbox->addWidget(toFillin);
535 kval->label->setText(paramName);
536 kval->lineeditwidget->setText(value);
537 QDomElement klistelem = pa.firstChildElement("keywords");
538 QDomElement kdisplaylistelem = pa.firstChildElement("keywordsdisplay");
539 QStringList keywordlist;
540 QStringList keyworddisplaylist;
541 if (!klistelem.isNull()) {
542 keywordlist = klistelem.text().split(';');
543 keyworddisplaylist = i18n(kdisplaylistelem.text().toUtf8().data()).split(';');
545 if (keyworddisplaylist.count() != keywordlist.count()) {
546 keyworddisplaylist = keywordlist;
548 for (int i = 0; i < keywordlist.count(); i++) {
549 kval->comboboxwidget->addItem(keyworddisplaylist.at(i), keywordlist.at(i));
551 // Add disabled user prompt at index 0
552 kval->comboboxwidget->insertItem(0, i18n("<select a keyword>"), "");
553 kval->comboboxwidget->model()->setData( kval->comboboxwidget->model()->index(0,0), QVariant(Qt::NoItemFlags), Qt::UserRole -1);
554 kval->comboboxwidget->setCurrentIndex(0);
555 m_valueItems[paramName] = kval;
556 connect(kval->lineeditwidget, SIGNAL(editingFinished()) , this, SLOT(collectAllParameters()));
557 connect(kval->comboboxwidget, SIGNAL(activated (const QString&)), this, SLOT(collectAllParameters()));
558 m_uiItems.append(kval);
559 } else if (type == "fontfamily") {
560 Fontval* fval = new Fontval;
561 QWidget * toFillin = new QWidget(m_baseWidget);
562 fval->setupUi(toFillin);
563 m_vbox->addWidget(toFillin);
564 fval->name->setText(paramName);
565 fval->fontfamilywidget->setCurrentFont(QFont(value));
566 m_valueItems[paramName] = fval;
567 connect(fval->fontfamilywidget, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(collectAllParameters())) ;
568 m_uiItems.append(fval);
569 } else if (type == "filterjob") {
570 QPushButton *button = new QPushButton(paramName, m_baseWidget);
571 m_vbox->addWidget(button);
572 m_valueItems[paramName] = button;
573 connect(button, SIGNAL(pressed()), this, SLOT(slotStartFilterJobAction()));
578 m_vbox->addStretch();
580 if (m_keyframeEditor)
581 m_keyframeEditor->checkVisibleParam();
583 // Make sure all doubleparam spinboxes have the same width, looks much better
584 QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
586 for (int i = 0; i < allWidgets.count(); i++) {
587 if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
589 for (int i = 0; i < allWidgets.count(); i++) {
590 allWidgets.at(i)->setSpinSize(minSize);
594 void EffectStackEdit::collectAllParameters()
597 if (m_valueItems.isEmpty() || m_params.isNull()) return;
598 const QDomElement oldparam = m_params.cloneNode().toElement();
599 QDomElement newparam = oldparam.cloneNode().toElement();
600 QDomNodeList namenode = newparam.elementsByTagName("parameter");
603 for (int i = 0; i < namenode.count() ; i++) {
604 QDomNode pa = namenode.item(i);
605 QDomElement na = pa.firstChildElement("name");
606 QString type = pa.attributes().namedItem("type").nodeValue();
607 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
608 if (type == "complex")
609 paramName.append("complex");
610 else if (type == "position")
611 paramName.append("position");
612 else if (type == "geometry")
613 paramName.append("geometry");
614 else if (type == "keyframe")
615 paramName.append("keyframe");
616 if (type != "simplekeyframe" && type != "fixed" && type != "addedgeometry" && !m_valueItems.contains(paramName)) {
617 kDebug() << "// Param: " << paramName << " NOT FOUND";
622 if (type == "double" || type == "constant") {
623 DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
624 setValue = locale.toString(doubleparam->getValue());
625 } else if (type == "list") {
626 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
627 setValue = box->itemData(box->currentIndex()).toString();
628 } else if (type == "bool") {
629 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
630 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
631 } else if (type == "color") {
632 ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
633 setValue = choosecolor->getColor();
634 } else if (type == "complex") {
635 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
636 namenode.item(i) = complex->getParamDesc();
637 } else if (type == "geometry") {
638 if (KdenliveSettings::on_monitor_effects()) {
639 if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getValue());
641 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
642 namenode.item(i).toElement().setAttribute("value", geom->getValue());
644 } else if (type == "addedgeometry") {
645 namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getExtraValue(namenode.item(i).toElement().attribute("name")));
646 } else if (type == "position") {
647 PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
648 int pos = pedit->getPosition();
649 setValue = QString::number(pos);
650 if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_black") {
651 // Make sure duration is not longer than clip
653 EffectsList::setParameter(newparam, "in", QString::number(m_in));
654 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
656 } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
657 // Make sure duration is not longer than clip
659 EffectsList::setParameter(newparam, "in", QString::number(m_out - pos));
660 EffectsList::setParameter(newparam, "out", QString::number(m_out));
663 } else if (type == "curve") {
664 KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
665 QList<QPointF> points = curve->curve().points();
666 QString number = pa.attributes().namedItem("number").nodeValue();
667 QString inName = pa.attributes().namedItem("inpoints").nodeValue();
668 QString outName = pa.attributes().namedItem("outpoints").nodeValue();
669 int off = pa.attributes().namedItem("min").nodeValue().toInt();
670 int end = pa.attributes().namedItem("max").nodeValue().toInt();
671 if (oldparam.attribute("version").toDouble() > 0.2) {
672 EffectsList::setParameter(newparam, number, locale.toString(points.count() / 10.));
674 EffectsList::setParameter(newparam, number, QString::number(points.count()));
676 for (int j = 0; (j < points.count() && j + off <= end); j++) {
678 in.replace("%i", QString::number(j + off));
679 QString out = outName;
680 out.replace("%i", QString::number(j + off));
681 EffectsList::setParameter(newparam, in, locale.toString(points.at(j).x()));
682 EffectsList::setParameter(newparam, out, locale.toString(points.at(j).y()));
684 QString depends = pa.attributes().namedItem("depends").nodeValue();
685 if (!depends.isEmpty())
686 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
687 } else if (type == "bezier_spline") {
688 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
689 setValue = widget->spline();
690 QString depends = pa.attributes().namedItem("depends").nodeValue();
691 if (!depends.isEmpty())
692 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
694 } else if (type == "roto-spline") {
695 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
696 setValue = widget->getSpline();
698 } else if (type == "wipe") {
699 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
701 if (wp->start_left->isChecked())
703 else if (wp->start_right->isChecked())
705 else if (wp->start_up->isChecked())
707 else if (wp->start_down->isChecked())
709 else if (wp->start_center->isChecked())
713 info.startTransparency = wp->start_transp->value();
715 if (wp->end_left->isChecked())
717 else if (wp->end_right->isChecked())
719 else if (wp->end_up->isChecked())
721 else if (wp->end_down->isChecked())
723 else if (wp->end_center->isChecked())
727 info.endTransparency = wp->end_transp->value();
729 setValue = getWipeString(info);
730 } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
731 QDomElement elem = pa.toElement();
732 QString realName = i18n(na.toElement().text().toUtf8().data());
733 QString val = m_keyframeEditor->getValue(realName);
734 elem.setAttribute("keyframes", val);
736 if (m_keyframeEditor->isVisibleParam(realName))
737 elem.setAttribute("intimeline", "1");
738 else if (elem.hasAttribute("intimeline"))
739 elem.removeAttribute("intimeline");
740 } else if (type == "url") {
741 KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
742 setValue = req->url().path();
743 } else if (type == "keywords"){
744 QLineEdit *line = ((Keywordval*)m_valueItems.value(paramName))->lineeditwidget;
745 QComboBox *combo = ((Keywordval*)m_valueItems.value(paramName))->comboboxwidget;
746 if(combo->currentIndex())
748 QString comboval = combo->itemData(combo->currentIndex()).toString();
749 line->insert(comboval);
750 combo->setCurrentIndex(0);
752 setValue = line->text();
753 } else if (type == "fontfamily") {
754 QFontComboBox* fontfamily = ((Fontval*)m_valueItems.value(paramName))->fontfamilywidget;
755 setValue = fontfamily->currentFont().family();
758 if (!setValue.isNull())
759 pa.attributes().namedItem("value").setNodeValue(setValue);
762 emit parameterChanged(oldparam, newparam);*/
765 void EffectStackEdit::clearAllItems()
768 m_valueItems.clear();
770 /*while (!m_items.isEmpty()) {
771 QWidget *die = m_items.takeFirst();
775 //qDeleteAll(m_uiItems);
777 while ((child = m_vbox->takeAt(0)) != 0) {
778 QWidget *wid = child->widget();
782 m_keyframeEditor = NULL;
783 m_geometryWidget = NULL;
787 void EffectStackEdit::slotSyncEffectsPos(int pos)
789 emit syncEffectsPos(pos);
792 void EffectStackEdit::slotStartFilterJobAction()
794 QDomNodeList namenode = m_params.elementsByTagName("parameter");
795 for (int i = 0; i < namenode.count() ; i++) {
796 QDomElement pa = namenode.item(i).toElement();
797 QString type = pa.attribute("type");
798 if (type == "filterjob") {
799 emit startFilterJob(pa.attribute("filtertag"), pa.attribute("filterparams"), pa.attribute("finalfilter"), pa.attribute("consumer"), pa.attribute("consumerparams"), pa.attribute("wantedproperties"));
800 kDebug()<<" - - -PROPS:\n"<<pa.attribute("filtertag")<<"-"<< pa.attribute("filterparams")<<"-"<< pa.attribute("consumer")<<"-"<< pa.attribute("consumerparams")<<"-"<< pa.attribute("wantedproperties");