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>
47 #include <KColorScheme>
49 #include <QVBoxLayout>
51 #include <QPushButton>
53 #include <QScrollArea>
55 // For QDomNode debugging (output into files); leaving here as sample code.
59 class Boolval: public QWidget, public Ui::Boolval_UI
63 class Listval: public QWidget, public Ui::Listval_UI
67 class Wipeval: public QWidget, public Ui::Wipeval_UI
71 class Urlval: public QWidget, public Ui::Urlval_UI
75 class Keywordval: public QWidget, public Ui::Keywordval_UI
79 class Fontval: public QWidget, public Ui::Fontval_UI
83 QMap<QString, QImage> EffectStackEdit::iconCache;
85 EffectStackEdit::EffectStackEdit(Monitor *monitor, QWidget *parent) :
89 m_frameSize(QPoint()),
90 m_keyframeEditor(NULL),
92 m_geometryWidget(NULL)
94 m_baseWidget = new QWidget(this);
95 setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
96 setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
97 setFrameStyle(QFrame::NoFrame);
98 setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
100 QPalette p = palette();
101 KColorScheme scheme(p.currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
102 QColor dark_bg = scheme.shade(KColorScheme::DarkShade);
103 QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
104 QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
105 QColor light_bg = scheme.shade(KColorScheme::LightShade);
107 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}\
108 QProgressBar:horizontal#dragOnly {background: %1} QProgressBar:horizontal:hover#dragOnly {background: %3} QProgressBar:horizontal:hover {border: 1px solid %3;border-right: 0px;}\
109 QProgressBar::chunk:horizontal {background: %1;} QProgressBar::chunk:horizontal:hover {background: %3;}\
110 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;}\
111 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;}\
112 QAbstractSpinBox::up-button#dragBox {width:0px;padding:0px;} QAbstractSpinBox[inTimeline=\"true\"]#dragBox { border: 1px solid %2;} QAbstractSpinBox:hover#dragBox {border: 1px solid %3;} ")
113 .arg(dark_bg.name()).arg(selected_bg.name()).arg(hover_bg.name()).arg(light_bg.name()));
114 setStyleSheet(stylesheet);
116 setWidget(m_baseWidget);
117 setWidgetResizable(true);
118 m_vbox = new QVBoxLayout(m_baseWidget);
119 m_vbox->setContentsMargins(0, 0, 0, 0);
120 m_vbox->setSpacing(2);
123 EffectStackEdit::~EffectStackEdit()
129 void EffectStackEdit::setFrameSize(QPoint p)
132 QDomNodeList namenode = m_params.elementsByTagName("parameter");
133 for (int i = 0; i < namenode.count() ; i++) {
134 QDomNode pa = namenode.item(i);
135 QDomElement na = pa.firstChildElement("name");
136 QString type = pa.attributes().namedItem("type").nodeValue();
137 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
139 if (type == "geometry") {
140 if (!KdenliveSettings::on_monitor_effects()) {
141 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
142 geom->setFrameSize(m_frameSize);
146 if (m_geometryWidget) m_geometryWidget->setFrameSize(m_frameSize);
153 void EffectStackEdit::updateTimecodeFormat()
155 if (m_keyframeEditor)
156 m_keyframeEditor->updateTimecodeFormat();
158 QDomNodeList namenode = m_params.elementsByTagName("parameter");
159 for (int i = 0; i < namenode.count() ; i++) {
160 QDomNode pa = namenode.item(i);
161 QDomElement na = pa.firstChildElement("name");
162 QString type = pa.attributes().namedItem("type").nodeValue();
163 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
165 if (type == "geometry") {
166 if (KdenliveSettings::on_monitor_effects()) {
167 if (m_geometryWidget) m_geometryWidget->updateTimecodeFormat();
169 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
170 geom->updateTimecodeFormat();
173 } else if (type == "position") {
174 PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
175 posi->updateTimecodeFormat();
177 } else if (type == "roto-spline") {
178 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems[paramName]);
179 widget->updateTimecodeFormat();
184 void EffectStackEdit::meetDependency(const QString& name, QString type, QString value)
186 if (type == "curve") {
187 KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
189 int color = value.toInt();
190 curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
192 } else if (type == "bezier_spline") {
193 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
195 widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10)));
200 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
206 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
208 m_params.setAttribute(name, value);
210 if (name == "disable") {
211 // if effect is disabled, disable parameters widget
212 bool enabled = value.toInt() == 0 || !KdenliveSettings::disable_effect_parameters();
214 emit effectStateChanged(enabled);
218 void EffectStackEdit::transferParamDesc(const QDomElement &d, ItemInfo info, bool isEffect)
221 if (m_keyframeEditor) delete m_keyframeEditor;
222 m_keyframeEditor = NULL;
224 m_in = isEffect ? info.cropStart.frames(KdenliveSettings::project_fps()) : info.startPos.frames(KdenliveSettings::project_fps());
225 m_out = isEffect ? (info.cropStart + info.cropDuration).frames(KdenliveSettings::project_fps()) - 1 : info.endPos.frames(KdenliveSettings::project_fps());
226 if (m_params.isNull()) {
227 // kDebug() << "// EMPTY EFFECT STACK";
231 QDomNodeList namenode = m_params.elementsByTagName("parameter");
233 QFile debugFile("/tmp/namenodes.txt");
234 if (debugFile.open(QFile::WriteOnly | QFile::Truncate)) {
235 QTextStream out(&debugFile);
236 QTextStream out2(stdout);
237 for (int i = 0; i < namenode.size(); i++) {
239 namenode.at(i).save(out, 2);
241 namenode.at(i).save(out2, 2);
245 int minFrame = d.attribute("start").toInt();
246 int maxFrame = d.attribute("end").toInt();
247 // In transitions, maxFrame is in fact one frame after the end of transition
248 if (maxFrame > 0) maxFrame --;
250 bool disable = d.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
251 setEnabled(!disable);
256 for (int i = 0; i < namenode.count() ; i++) {
257 QDomElement pa = namenode.item(i).toElement();
258 QDomElement na = pa.firstChildElement("name");
259 QDomElement commentElem = pa.firstChildElement("comment");
260 QString type = pa.attribute("type");
261 QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
263 if (!commentElem.isNull())
264 comment = i18n(commentElem.text().toUtf8().data());
265 QString value = pa.attribute("value").isNull() ?
266 pa.attribute("default") : pa.attribute("value");
269 /** See effects/README for info on the different types */
271 if (type == "double" || type == "constant") {
274 if (pa.attribute("min").contains('%'))
275 min = ProfilesDialog::getStringEval(m_profile, pa.attribute("min"), m_frameSize);
277 min = pa.attribute("min").toDouble();
278 if (pa.attribute("max").contains('%'))
279 max = ProfilesDialog::getStringEval(m_profile, pa.attribute("max"), m_frameSize);
281 max = pa.attribute("max").toDouble();
283 DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, value.toDouble(), min, max,
284 pa.attribute("default").toDouble(), comment, -1, pa.attribute("suffix"), pa.attribute("decimals").toInt(), this);
285 m_vbox->addWidget(doubleparam);
286 m_valueItems[paramName] = doubleparam;
287 connect(doubleparam, SIGNAL(valueChanged(double)), this, SLOT(collectAllParameters()));
288 connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
289 } else if (type == "list") {
290 Listval *lsval = new Listval;
291 QWidget * toFillin = new QWidget(m_baseWidget);
292 lsval->setupUi(toFillin);
293 m_vbox->addWidget(toFillin);
294 QStringList listitems = pa.attribute("paramlist").split(';');
295 if (listitems.count() == 1) {
296 // probably custom effect created before change to ';' as separator
297 listitems = pa.attribute("paramlist").split(',');
299 QDomElement list = pa.firstChildElement("paramlistdisplay");
300 QStringList listitemsdisplay;
301 if (!list.isNull()) {
302 listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
304 listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
306 if (listitemsdisplay.count() != listitems.count())
307 listitemsdisplay = listitems;
308 lsval->list->setIconSize(QSize(30, 30));
309 for (int i = 0; i < listitems.count(); i++) {
310 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
311 QString entry = listitems.at(i);
312 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
313 if (!EffectStackEdit::iconCache.contains(entry)) {
315 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
317 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
320 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
321 lsval->name->setText(paramName);
322 lsval->labelComment->setText(comment);
323 lsval->widgetComment->setHidden(true);
324 m_valueItems[paramName] = lsval;
325 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
326 if (!comment.isEmpty())
327 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
328 m_uiItems.append(lsval);
329 } else if (type == "bool") {
330 Boolval *bval = new Boolval;
331 QWidget * toFillin = new QWidget(m_baseWidget);
332 bval->setupUi(toFillin);
333 m_vbox->addWidget(toFillin);
334 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
335 bval->name->setText(paramName);
336 bval->labelComment->setText(comment);
337 bval->widgetComment->setHidden(true);
338 m_valueItems[paramName] = bval;
339 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
340 if (!comment.isEmpty())
341 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
342 m_uiItems.append(bval);
343 } else if (type == "complex") {
344 ComplexParameter *pl = new ComplexParameter;
345 pl->setupParam(d, pa.attribute("name"), 0, 100);
346 m_vbox->addWidget(pl);
347 m_valueItems[paramName+"complex"] = pl;
348 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
349 } else if (type == "geometry") {
350 if (KdenliveSettings::on_monitor_effects()) {
351 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);
352 m_geometryWidget->setFrameSize(m_frameSize);
353 m_geometryWidget->slotShowScene(!disable);
354 // connect this before setupParam to make sure the monitor scene shows up at startup
355 connect(m_geometryWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
356 connect(m_geometryWidget, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
357 if (minFrame == maxFrame)
358 m_geometryWidget->setupParam(pa, m_in, m_out);
360 m_geometryWidget->setupParam(pa, minFrame, maxFrame);
361 m_vbox->addWidget(m_geometryWidget);
362 m_valueItems[paramName+"geometry"] = m_geometryWidget;
363 connect(m_geometryWidget, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
364 connect(this, SIGNAL(syncEffectsPos(int)), m_geometryWidget, SLOT(slotSyncPosition(int)));
365 connect(this, SIGNAL(effectStateChanged(bool)), m_geometryWidget, SLOT(slotShowScene(bool)));
367 Geometryval *geo = new Geometryval(m_profile, m_timecode, m_frameSize, isEffect ? 0 : qMax(0, (int)info.startPos.frames(KdenliveSettings::project_fps())));
368 if (minFrame == maxFrame)
369 geo->setupParam(pa, m_in, m_out);
371 geo->setupParam(pa, minFrame, maxFrame);
372 m_vbox->addWidget(geo);
373 m_valueItems[paramName+"geometry"] = geo;
374 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
375 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
376 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
378 } else if (type == "addedgeometry") {
379 // this is a parameter that should be linked to the geometry widget, for example rotation, shear, ...
380 if (m_geometryWidget) m_geometryWidget->addParameter(pa);
381 } else if (type == "keyframe" || type == "simplekeyframe") {
382 // keyframe editor widget
383 if (m_keyframeEditor == NULL) {
385 if (pa.attribute("widget") == "corners") {
386 // we want a corners-keyframe-widget
387 CornersWidget *corners = new CornersWidget(m_monitor, pa, m_in, m_out, m_timecode, d.attribute("active_keyframe", "-1").toInt(), this);
388 corners->slotShowScene(!disable);
389 connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
390 connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
391 connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
392 geo = static_cast<KeyframeEdit *>(corners);
394 geo = new KeyframeEdit(pa, m_in, m_out, m_timecode, d.attribute("active_keyframe", "-1").toInt());
396 m_vbox->addWidget(geo);
397 m_valueItems[paramName+"keyframe"] = geo;
398 m_keyframeEditor = geo;
399 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
400 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
401 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
403 // we already have a keyframe editor, so just add another column for the new param
404 m_keyframeEditor->addParameter(pa);
406 } else if (type == "color") {
407 ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, value, this);
408 choosecolor->setAlphaChannelEnabled(pa.attribute("alpha") == "1");
409 m_vbox->addWidget(choosecolor);
410 m_valueItems[paramName] = choosecolor;
411 connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
412 connect(choosecolor, SIGNAL(modified()) , this, SLOT(collectAllParameters()));
413 } else if (type == "position") {
414 int pos = value.toInt();
415 if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
417 } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
418 // fadeout position starts from clip end
421 PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_timecode);
422 m_vbox->addWidget(posedit);
423 m_valueItems[paramName+"position"] = posedit;
424 connect(posedit, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
425 } else if (type == "curve") {
426 KisCurveWidget *curve = new KisCurveWidget(this);
427 curve->setMaxPoints(pa.attribute("max").toInt());
428 QList<QPointF> points;
430 if (d.attribute("version").toDouble() > 0.2) {
431 number = EffectsList::parameter(d, pa.attribute("number")).toDouble() * 10;
433 number = EffectsList::parameter(d, pa.attribute("number")).toInt();
435 QString inName = pa.attribute("inpoints");
436 QString outName = pa.attribute("outpoints");
437 int start = pa.attribute("min").toInt();
438 for (int j = start; j <= number; j++) {
440 in.replace("%i", QString::number(j));
441 QString out = outName;
442 out.replace("%i", QString::number(j));
443 points << QPointF(EffectsList::parameter(d, in).toDouble(), EffectsList::parameter(d, out).toDouble());
445 if (!points.isEmpty())
446 curve->setCurve(KisCubicCurve(points));
447 QSpinBox *spinin = new QSpinBox();
448 spinin->setRange(0, 1000);
449 QSpinBox *spinout = new QSpinBox();
450 spinout->setRange(0, 1000);
451 curve->setupInOutControls(spinin, spinout, 0, 1000);
452 m_vbox->addWidget(curve);
453 m_vbox->addWidget(spinin);
454 m_vbox->addWidget(spinout);
456 connect(curve, SIGNAL(modified()), this, SLOT(collectAllParameters()));
457 m_valueItems[paramName] = curve;
459 QString depends = pa.attribute("depends");
460 if (!depends.isEmpty())
461 meetDependency(paramName, type, EffectsList::parameter(d, depends));
462 } else if (type == "bezier_spline") {
463 BezierSplineWidget *widget = new BezierSplineWidget(value, this);
465 m_vbox->addWidget(widget);
466 m_valueItems[paramName] = widget;
467 connect(widget, SIGNAL(modified()), this, SLOT(collectAllParameters()));
468 QString depends = pa.attribute("depends");
469 if (!depends.isEmpty())
470 meetDependency(paramName, type, EffectsList::parameter(d, depends));
472 } else if (type == "roto-spline") {
473 RotoWidget *roto = new RotoWidget(value, m_monitor, info, m_timecode, this);
474 roto->slotShowScene(!disable);
475 connect(roto, SIGNAL(valueChanged()), this, SLOT(collectAllParameters()));
476 connect(roto, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
477 connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
478 connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
479 connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
480 m_vbox->addWidget(roto);
481 m_valueItems[paramName] = roto;
483 } else if (type == "wipe") {
484 Wipeval *wpval = new Wipeval;
485 QWidget * toFillin = new QWidget(m_baseWidget);
486 wpval->setupUi(toFillin);
487 m_vbox->addWidget(toFillin);
488 wipeInfo w = getWipeInfo(value);
491 wpval->start_up->setChecked(true);
494 wpval->start_down->setChecked(true);
497 wpval->start_right->setChecked(true);
500 wpval->start_left->setChecked(true);
503 wpval->start_center->setChecked(true);
508 wpval->end_up->setChecked(true);
511 wpval->end_down->setChecked(true);
514 wpval->end_right->setChecked(true);
517 wpval->end_left->setChecked(true);
520 wpval->end_center->setChecked(true);
523 wpval->start_transp->setValue(w.startTransparency);
524 wpval->end_transp->setValue(w.endTransparency);
525 m_valueItems[paramName] = wpval;
526 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
527 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
528 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
529 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
530 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
531 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
532 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
533 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
534 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
535 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
536 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
537 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
538 //wpval->title->setTitle(na.toElement().text());
539 m_uiItems.append(wpval);
540 } else if (type == "url") {
541 Urlval *cval = new Urlval;
542 QWidget * toFillin = new QWidget(m_baseWidget);
543 cval->setupUi(toFillin);
544 m_vbox->addWidget(toFillin);
545 cval->label->setText(paramName);
546 cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
547 m_valueItems[paramName] = cval;
548 cval->urlwidget->setUrl(KUrl(value));
549 connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(collectAllParameters()));
550 connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(collectAllParameters()));
551 m_uiItems.append(cval);
552 } else if (type == "keywords") {
553 Keywordval* kval = new Keywordval;
554 QWidget * toFillin = new QWidget(m_baseWidget);
555 kval->setupUi(toFillin);
556 m_vbox->addWidget(toFillin);
557 kval->label->setText(paramName);
558 kval->lineeditwidget->setText(value);
559 QDomElement klistelem = pa.firstChildElement("keywords");
560 QDomElement kdisplaylistelem = pa.firstChildElement("keywordsdisplay");
561 QStringList keywordlist;
562 QStringList keyworddisplaylist;
563 if (!klistelem.isNull()) {
564 keywordlist = klistelem.text().split(';');
565 keyworddisplaylist = i18n(kdisplaylistelem.text().toUtf8().data()).split(';');
567 if (keyworddisplaylist.count() != keywordlist.count()) {
568 keyworddisplaylist = keywordlist;
570 for (int i = 0; i < keywordlist.count(); i++) {
571 kval->comboboxwidget->addItem(keyworddisplaylist.at(i), keywordlist.at(i));
573 // Add disabled user prompt at index 0
574 kval->comboboxwidget->insertItem(0, i18n("<select a keyword>"), "");
575 kval->comboboxwidget->model()->setData( kval->comboboxwidget->model()->index(0,0), QVariant(Qt::NoItemFlags), Qt::UserRole -1);
576 kval->comboboxwidget->setCurrentIndex(0);
577 m_valueItems[paramName] = kval;
578 connect(kval->lineeditwidget, SIGNAL(editingFinished()) , this, SLOT(collectAllParameters()));
579 connect(kval->comboboxwidget, SIGNAL(activated (const QString&)), this, SLOT(collectAllParameters()));
580 m_uiItems.append(kval);
581 } else if (type == "fontfamily") {
582 Fontval* fval = new Fontval;
583 QWidget * toFillin = new QWidget(m_baseWidget);
584 fval->setupUi(toFillin);
585 m_vbox->addWidget(toFillin);
586 fval->name->setText(paramName);
587 fval->fontfamilywidget->setCurrentFont(QFont(value));
588 m_valueItems[paramName] = fval;
589 connect(fval->fontfamilywidget, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(collectAllParameters())) ;
590 m_uiItems.append(fval);
591 } else if (type == "filterjob") {
592 QPushButton *button = new QPushButton(paramName, m_baseWidget);
593 m_vbox->addWidget(button);
594 m_valueItems[paramName] = button;
595 connect(button, SIGNAL(pressed()), this, SLOT(slotStartFilterJobAction()));
600 m_vbox->addStretch();
602 if (m_keyframeEditor)
603 m_keyframeEditor->checkVisibleParam();
605 // Make sure all doubleparam spinboxes have the same width, looks much better
606 QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
608 for (int i = 0; i < allWidgets.count(); i++) {
609 if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
611 for (int i = 0; i < allWidgets.count(); i++) {
612 allWidgets.at(i)->setSpinSize(minSize);
616 wipeInfo EffectStackEdit::getWipeInfo(QString value)
619 // Convert old geometry values that used a comma as separator
620 if (value.contains(',')) value.replace(',','/');
621 QString start = value.section(';', 0, 0);
622 QString end = value.section(';', 1, 1).section('=', 1, 1);
623 if (start.startsWith("-100%/0"))
625 else if (start.startsWith("100%/0"))
627 else if (start.startsWith("0%/100%"))
629 else if (start.startsWith("0%/-100%"))
634 if (start.count(':') == 2)
635 info.startTransparency = start.section(':', -1).toInt();
637 info.startTransparency = 100;
639 if (end.startsWith("-100%/0"))
641 else if (end.startsWith("100%/0"))
643 else if (end.startsWith("0%/100%"))
645 else if (end.startsWith("0%/-100%"))
650 if (end.count(':') == 2)
651 info.endTransparency = end.section(':', -1).toInt();
653 info.endTransparency = 100;
658 QString EffectStackEdit::getWipeString(wipeInfo info)
663 switch (info.start) {
665 start = "-100%/0%:100%x100%";
668 start = "100%/0%:100%x100%";
671 start = "0%/100%:100%x100%";
674 start = "0%/-100%:100%x100%";
677 start = "0%/0%:100%x100%";
680 start.append(':' + QString::number(info.startTransparency));
684 end = "-100%/0%:100%x100%";
687 end = "100%/0%:100%x100%";
690 end = "0%/100%:100%x100%";
693 end = "0%/-100%:100%x100%";
696 end = "0%/0%:100%x100%";
699 end.append(':' + QString::number(info.endTransparency));
700 return QString(start + ";-1=" + end);
703 void EffectStackEdit::collectAllParameters()
705 if (m_valueItems.isEmpty() || m_params.isNull()) return;
706 const QDomElement oldparam = m_params.cloneNode().toElement();
707 QDomElement newparam = oldparam.cloneNode().toElement();
708 QDomNodeList namenode = newparam.elementsByTagName("parameter");
711 for (int i = 0; i < namenode.count() ; i++) {
712 QDomNode pa = namenode.item(i);
713 QDomElement na = pa.firstChildElement("name");
714 QString type = pa.attributes().namedItem("type").nodeValue();
715 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
716 if (type == "complex")
717 paramName.append("complex");
718 else if (type == "position")
719 paramName.append("position");
720 else if (type == "geometry")
721 paramName.append("geometry");
722 else if (type == "keyframe")
723 paramName.append("keyframe");
724 if (type != "simplekeyframe" && type != "fixed" && type != "addedgeometry" && !m_valueItems.contains(paramName)) {
725 kDebug() << "// Param: " << paramName << " NOT FOUND";
730 if (type == "double" || type == "constant") {
731 DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
732 setValue = locale.toString(doubleparam->getValue());
733 } else if (type == "list") {
734 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
735 setValue = box->itemData(box->currentIndex()).toString();
736 } else if (type == "bool") {
737 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
738 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
739 } else if (type == "color") {
740 ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
741 setValue = choosecolor->getColor();
742 } else if (type == "complex") {
743 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
744 namenode.item(i) = complex->getParamDesc();
745 } else if (type == "geometry") {
746 if (KdenliveSettings::on_monitor_effects()) {
747 if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getValue());
749 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
750 namenode.item(i).toElement().setAttribute("value", geom->getValue());
752 } else if (type == "addedgeometry") {
753 namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getExtraValue(namenode.item(i).toElement().attribute("name")));
754 } else if (type == "position") {
755 PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
756 int pos = pedit->getPosition();
757 setValue = QString::number(pos);
758 if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_black") {
759 // Make sure duration is not longer than clip
762 pedit->setPosition(pos);
764 EffectsList::setParameter(newparam, "in", QString::number(m_in));
765 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
767 } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
768 // Make sure duration is not longer than clip
771 pedit->setPosition(pos);
773 EffectsList::setParameter(newparam, "in", QString::number(m_out - pos));
774 EffectsList::setParameter(newparam, "out", QString::number(m_out));
777 } else if (type == "curve") {
778 KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
779 QList<QPointF> points = curve->curve().points();
780 QString number = pa.attributes().namedItem("number").nodeValue();
781 QString inName = pa.attributes().namedItem("inpoints").nodeValue();
782 QString outName = pa.attributes().namedItem("outpoints").nodeValue();
783 int off = pa.attributes().namedItem("min").nodeValue().toInt();
784 int end = pa.attributes().namedItem("max").nodeValue().toInt();
785 if (oldparam.attribute("version").toDouble() > 0.2) {
786 EffectsList::setParameter(newparam, number, locale.toString(points.count() / 10.));
788 EffectsList::setParameter(newparam, number, QString::number(points.count()));
790 for (int j = 0; (j < points.count() && j + off <= end); j++) {
792 in.replace("%i", QString::number(j + off));
793 QString out = outName;
794 out.replace("%i", QString::number(j + off));
795 EffectsList::setParameter(newparam, in, locale.toString(points.at(j).x()));
796 EffectsList::setParameter(newparam, out, locale.toString(points.at(j).y()));
798 QString depends = pa.attributes().namedItem("depends").nodeValue();
799 if (!depends.isEmpty())
800 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
801 } else if (type == "bezier_spline") {
802 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
803 setValue = widget->spline();
804 QString depends = pa.attributes().namedItem("depends").nodeValue();
805 if (!depends.isEmpty())
806 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
808 } else if (type == "roto-spline") {
809 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
810 setValue = widget->getSpline();
812 } else if (type == "wipe") {
813 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
815 if (wp->start_left->isChecked())
817 else if (wp->start_right->isChecked())
819 else if (wp->start_up->isChecked())
821 else if (wp->start_down->isChecked())
823 else if (wp->start_center->isChecked())
827 info.startTransparency = wp->start_transp->value();
829 if (wp->end_left->isChecked())
831 else if (wp->end_right->isChecked())
833 else if (wp->end_up->isChecked())
835 else if (wp->end_down->isChecked())
837 else if (wp->end_center->isChecked())
841 info.endTransparency = wp->end_transp->value();
843 setValue = getWipeString(info);
844 } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
845 QDomElement elem = pa.toElement();
846 QString realName = i18n(na.toElement().text().toUtf8().data());
847 QString val = m_keyframeEditor->getValue(realName);
848 elem.setAttribute("keyframes", val);
850 if (m_keyframeEditor->isVisibleParam(realName))
851 elem.setAttribute("intimeline", "1");
852 else if (elem.hasAttribute("intimeline"))
853 elem.removeAttribute("intimeline");
854 } else if (type == "url") {
855 KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
856 setValue = req->url().path();
857 } else if (type == "keywords"){
858 QLineEdit *line = ((Keywordval*)m_valueItems.value(paramName))->lineeditwidget;
859 QComboBox *combo = ((Keywordval*)m_valueItems.value(paramName))->comboboxwidget;
860 if(combo->currentIndex())
862 QString comboval = combo->itemData(combo->currentIndex()).toString();
863 line->insert(comboval);
864 combo->setCurrentIndex(0);
866 setValue = line->text();
867 } else if (type == "fontfamily") {
868 QFontComboBox* fontfamily = ((Fontval*)m_valueItems.value(paramName))->fontfamilywidget;
869 setValue = fontfamily->currentFont().family();
872 if (!setValue.isNull())
873 pa.attributes().namedItem("value").setNodeValue(setValue);
876 emit parameterChanged(oldparam, newparam);
879 void EffectStackEdit::clearAllItems()
882 m_valueItems.clear();
884 /*while (!m_items.isEmpty()) {
885 QWidget *die = m_items.takeFirst();
889 //qDeleteAll(m_uiItems);
891 while ((child = m_vbox->takeAt(0)) != 0) {
892 QWidget *wid = child->widget();
896 m_keyframeEditor = NULL;
897 m_geometryWidget = NULL;
901 void EffectStackEdit::slotSyncEffectsPos(int pos)
903 emit syncEffectsPos(pos);
906 void EffectStackEdit::slotStartFilterJobAction()
908 QDomNodeList namenode = m_params.elementsByTagName("parameter");
909 for (int i = 0; i < namenode.count() ; i++) {
910 QDomElement pa = namenode.item(i).toElement();
911 QString type = pa.attribute("type");
912 if (type == "filterjob") {
913 emit startFilterJob(pa.attribute("filtertag"), pa.attribute("filterparams"), pa.attribute("finalfilter"), pa.attribute("consumer"), pa.attribute("consumerparams"), pa.attribute("wantedproperties"));
914 kDebug()<<" - - -PROPS:\n"<<pa.attribute("filtertag")<<"-"<< pa.attribute("filterparams")<<"-"<< pa.attribute("consumer")<<"-"<< pa.attribute("consumerparams")<<"-"<< pa.attribute("wantedproperties");