1 /***************************************************************************
2 * Copyright (C) 2012 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "ui_listval_ui.h"
21 #include "ui_boolval_ui.h"
22 #include "ui_wipeval_ui.h"
23 #include "ui_urlval_ui.h"
24 #include "ui_keywordval_ui.h"
25 #include "ui_fontval_ui.h"
26 #include "complexparameter.h"
27 #include "geometryval.h"
28 #include "positionedit.h"
29 #include "kis_curve_widget.h"
30 #include "kis_cubic_curve.h"
31 #include "choosecolorwidget.h"
32 #include "geometrywidget.h"
33 #include "colortools.h"
34 #include "doubleparameterwidget.h"
35 #include "cornerswidget.h"
36 #include "dragvalue.h"
37 #include "beziercurve/beziersplinewidget.h"
39 #include "rotoscoping/rotowidget.h"
41 #include "kdenlivesettings.h"
42 #include "profilesdialog.h"
43 #include "projectlist.h"
44 #include "mainwindow.h"
45 #include "parametercontainer.h"
47 #include <KUrlRequester>
48 #include <KFileDialog>
54 MySpinBox::MySpinBox(QWidget * parent):
57 setFocusPolicy(Qt::StrongFocus);
60 void MySpinBox::focusInEvent(QFocusEvent *e)
62 setFocusPolicy(Qt::WheelFocus);
66 void MySpinBox::focusOutEvent(QFocusEvent *e)
68 setFocusPolicy(Qt::StrongFocus);
72 class Boolval: public QWidget, public Ui::Boolval_UI
76 class Listval: public QWidget, public Ui::Listval_UI
80 class Wipeval: public QWidget, public Ui::Wipeval_UI
84 class Urlval: public QWidget, public Ui::Urlval_UI
88 class Keywordval: public QWidget, public Ui::Keywordval_UI
92 class Fontval: public QWidget, public Ui::Fontval_UI
97 ParameterContainer::ParameterContainer(QDomElement effect, ItemInfo info, EffectMetaInfo *metaInfo, QWidget * parent) :
98 m_keyframeEditor(NULL),
99 m_geometryWidget(NULL),
100 m_metaInfo(metaInfo),
102 m_needsMonitorEffectScene(false)
104 m_in = info.cropStart.frames(KdenliveSettings::project_fps());
105 m_out = (info.cropStart + info.cropDuration).frames(KdenliveSettings::project_fps()) - 1;
107 QDomNodeList namenode = effect.childNodes(); //elementsByTagName("parameter");
109 QDomElement e = effect.toElement();
110 int minFrame = e.attribute("start").toInt();
111 int maxFrame = e.attribute("end").toInt();
112 // In transitions, maxFrame is in fact one frame after the end of transition
113 if (maxFrame > 0) maxFrame --;
115 bool disable = effect.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
116 parent->setEnabled(!disable);
119 m_vbox = new QVBoxLayout(parent);
120 m_vbox->setContentsMargins(4, 0, 4, 0);
121 m_vbox->setSpacing(2);
123 for (int i = 0; i < namenode.count() ; i++) {
124 QDomElement pa = namenode.item(i).toElement();
125 if (pa.tagName() != "parameter") continue;
126 QDomElement na = pa.firstChildElement("name");
127 QDomElement commentElem = pa.firstChildElement("comment");
128 QString type = pa.attribute("type");
129 QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
131 if (!commentElem.isNull())
132 comment = i18n(commentElem.text().toUtf8().data());
133 QWidget * toFillin = new QWidget(parent);
134 QString value = pa.attribute("value").isNull() ?
135 pa.attribute("default") : pa.attribute("value");
138 /** See effects/README for info on the different types */
140 if (type == "double" || type == "constant") {
143 if (pa.attribute("min").contains('%'))
144 min = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("min"), m_metaInfo->frameSize);
146 min = pa.attribute("min").toDouble();
147 if (pa.attribute("max").contains('%'))
148 max = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("max"), m_metaInfo->frameSize);
150 max = pa.attribute("max").toDouble();
152 DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, value.toDouble(), min, max,
153 pa.attribute("default").toDouble(), comment, -1, pa.attribute("suffix"), pa.attribute("decimals").toInt(), parent);
154 doubleparam->setFocusPolicy(Qt::StrongFocus);
155 m_vbox->addWidget(doubleparam);
156 m_valueItems[paramName] = doubleparam;
157 connect(doubleparam, SIGNAL(valueChanged(double)), this, SLOT(slotCollectAllParameters()));
158 connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
159 } else if (type == "list") {
160 Listval *lsval = new Listval;
161 lsval->setupUi(toFillin);
162 lsval->list->setFocusPolicy(Qt::StrongFocus);
163 QStringList listitems = pa.attribute("paramlist").split(';');
164 if (listitems.count() == 1) {
165 // probably custom effect created before change to ';' as separator
166 listitems = pa.attribute("paramlist").split(",");
168 QDomElement list = pa.firstChildElement("paramlistdisplay");
169 QStringList listitemsdisplay;
170 if (!list.isNull()) {
171 listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
173 listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
175 if (listitemsdisplay.count() != listitems.count())
176 listitemsdisplay = listitems;
177 lsval->list->setIconSize(QSize(30, 30));
178 for (int i = 0; i < listitems.count(); i++) {
179 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
180 QString entry = listitems.at(i);
181 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
182 if (!MainWindow::m_lumacache.contains(entry)) {
184 MainWindow::m_lumacache.insert(entry, pix.scaled(30, 30, Qt::KeepAspectRatio, Qt::SmoothTransformation));
186 lsval->list->setItemIcon(i, QPixmap::fromImage(MainWindow::m_lumacache.value(entry)));
189 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
190 lsval->name->setText(paramName);
191 lsval->labelComment->setText(comment);
192 lsval->widgetComment->setHidden(true);
193 m_valueItems[paramName] = lsval;
194 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(slotCollectAllParameters()));
195 if (!comment.isEmpty())
196 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
197 m_uiItems.append(lsval);
198 } else if (type == "bool") {
199 Boolval *bval = new Boolval;
200 bval->setupUi(toFillin);
201 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
202 bval->name->setText(paramName);
203 bval->labelComment->setText(comment);
204 bval->widgetComment->setHidden(true);
205 m_valueItems[paramName] = bval;
206 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(slotCollectAllParameters()));
207 if (!comment.isEmpty())
208 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
209 m_uiItems.append(bval);
210 } else if (type == "complex") {
211 ComplexParameter *pl = new ComplexParameter;
212 pl->setupParam(effect, pa.attribute("name"), 0, 100);
213 m_vbox->addWidget(pl);
214 m_valueItems[paramName+"complex"] = pl;
215 connect(pl, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
216 } else if (type == "geometry") {
217 if (KdenliveSettings::on_monitor_effects()) {
218 m_needsMonitorEffectScene = true;
219 m_geometryWidget = new GeometryWidget(m_metaInfo->monitor, m_metaInfo->timecode, 0, true, effect.hasAttribute("showrotation"), parent);
220 m_geometryWidget->setFrameSize(m_metaInfo->frameSize);
221 // connect this before setupParam to make sure the monitor scene shows up at startup
222 connect(m_geometryWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
223 connect(m_geometryWidget, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
224 if (minFrame == maxFrame)
225 m_geometryWidget->setupParam(pa, m_in, m_out);
227 m_geometryWidget->setupParam(pa, minFrame, maxFrame);
228 m_vbox->addWidget(m_geometryWidget);
229 m_valueItems[paramName+"geometry"] = m_geometryWidget;
230 connect(m_geometryWidget, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
231 connect(this, SIGNAL(syncEffectsPos(int)), m_geometryWidget, SLOT(slotSyncPosition(int)));
232 connect(this, SIGNAL(effectStateChanged(bool)), m_geometryWidget, SLOT(slotShowScene(bool)));
234 Geometryval *geo = new Geometryval(m_metaInfo->profile, m_metaInfo->timecode, m_metaInfo->frameSize, 0);
235 if (minFrame == maxFrame)
236 geo->setupParam(pa, m_in, m_out);
238 geo->setupParam(pa, minFrame, maxFrame);
239 m_vbox->addWidget(geo);
240 m_valueItems[paramName+"geometry"] = geo;
241 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
242 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
243 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
245 } else if (type == "addedgeometry") {
246 // this is a parameter that should be linked to the geometry widget, for example rotation, shear, ...
247 if (m_geometryWidget) m_geometryWidget->addParameter(pa);
248 } else if (type == "keyframe" || type == "simplekeyframe") {
249 // keyframe editor widget
250 if (m_keyframeEditor == NULL) {
252 if (pa.attribute("widget") == "corners") {
253 // we want a corners-keyframe-widget
254 CornersWidget *corners = new CornersWidget(m_metaInfo->monitor, pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt(), parent);
255 m_needsMonitorEffectScene = true;
256 connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
257 connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
258 connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
259 geo = static_cast<KeyframeEdit *>(corners);
261 geo = new KeyframeEdit(pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt());
263 m_vbox->addWidget(geo);
264 m_valueItems[paramName+"keyframe"] = geo;
265 m_keyframeEditor = geo;
266 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
267 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
268 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
270 // we already have a keyframe editor, so just add another column for the new param
271 m_keyframeEditor->addParameter(pa);
273 } else if (type == "color") {
274 if (pa.hasAttribute("paramprefix")) value.remove(0, pa.attribute("paramprefix").size());
275 if (value.startsWith('#'))
276 value = value.replace('#', "0x");
277 ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, value, parent);
278 choosecolor->setAlphaChannelEnabled(true);
279 m_vbox->addWidget(choosecolor);
280 m_valueItems[paramName] = choosecolor;
281 connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
282 connect(choosecolor, SIGNAL(modified()) , this, SLOT(slotCollectAllParameters()));
283 } else if (type == "position") {
284 int pos = value.toInt();
285 if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
287 } else if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
288 // fadeout position starts from clip end
291 PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_metaInfo->timecode);
292 m_vbox->addWidget(posedit);
293 m_valueItems[paramName+"position"] = posedit;
294 connect(posedit, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
295 } else if (type == "curve") {
296 KisCurveWidget *curve = new KisCurveWidget(parent);
297 curve->setMaxPoints(pa.attribute("max").toInt());
298 QList<QPointF> points;
300 if (e.attribute("version").toDouble() > 0.2) {
301 // Rounding gives really weird results. (int) (10 * 0.3) gives 2! So for now, add 0.5 to get correct result
302 number = EffectsList::parameter(e, pa.attribute("number")).toDouble() * 10 + 0.5;
304 number = EffectsList::parameter(e, pa.attribute("number")).toInt();
306 QString inName = pa.attribute("inpoints");
307 QString outName = pa.attribute("outpoints");
308 int start = pa.attribute("min").toInt();
309 for (int j = start; j <= number; j++) {
311 in.replace("%i", QString::number(j));
312 QString out = outName;
313 out.replace("%i", QString::number(j));
314 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
316 if (!points.isEmpty())
317 curve->setCurve(KisCubicCurve(points));
318 MySpinBox *spinin = new MySpinBox();
319 spinin->setRange(0, 1000);
320 MySpinBox *spinout = new MySpinBox();
321 spinout->setRange(0, 1000);
322 curve->setupInOutControls(spinin, spinout, 0, 1000);
323 m_vbox->addWidget(curve);
324 m_vbox->addWidget(spinin);
325 m_vbox->addWidget(spinout);
327 connect(curve, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
328 m_valueItems[paramName] = curve;
330 QString depends = pa.attribute("depends");
331 if (!depends.isEmpty())
332 meetDependency(paramName, type, EffectsList::parameter(e, depends));
333 } else if (type == "bezier_spline") {
334 BezierSplineWidget *widget = new BezierSplineWidget(value, parent);
336 m_vbox->addWidget(widget);
337 m_valueItems[paramName] = widget;
338 connect(widget, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
339 QString depends = pa.attribute("depends");
340 if (!depends.isEmpty())
341 meetDependency(paramName, type, EffectsList::parameter(e, depends));
343 } else if (type == "roto-spline") {
344 m_needsMonitorEffectScene = true;
345 RotoWidget *roto = new RotoWidget(value, m_metaInfo->monitor, info, m_metaInfo->timecode, parent);
346 connect(roto, SIGNAL(valueChanged()), this, SLOT(slotCollectAllParameters()));
347 connect(roto, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
348 connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
349 connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
350 connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
351 m_vbox->addWidget(roto);
352 m_valueItems[paramName] = roto;
354 } else if (type == "wipe") {
355 Wipeval *wpval = new Wipeval;
356 wpval->setupUi(toFillin);
357 wipeInfo w = getWipeInfo(value);
360 wpval->start_up->setChecked(true);
363 wpval->start_down->setChecked(true);
366 wpval->start_right->setChecked(true);
369 wpval->start_left->setChecked(true);
372 wpval->start_center->setChecked(true);
377 wpval->end_up->setChecked(true);
380 wpval->end_down->setChecked(true);
383 wpval->end_right->setChecked(true);
386 wpval->end_left->setChecked(true);
389 wpval->end_center->setChecked(true);
392 wpval->start_transp->setValue(w.startTransparency);
393 wpval->end_transp->setValue(w.endTransparency);
394 m_valueItems[paramName] = wpval;
395 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
396 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
397 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
398 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
399 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
400 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
401 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
402 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
403 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
404 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
405 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
406 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
407 //wpval->title->setTitle(na.toElement().text());
408 m_uiItems.append(wpval);
409 } else if (type == "url") {
410 Urlval *cval = new Urlval;
411 cval->setupUi(toFillin);
412 cval->label->setText(paramName);
413 cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
414 m_valueItems[paramName] = cval;
415 cval->urlwidget->setUrl(KUrl(value));
416 connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(slotCollectAllParameters()));
417 connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(slotCollectAllParameters()));
418 m_uiItems.append(cval);
419 } else if (type == "keywords") {
420 Keywordval* kval = new Keywordval;
421 kval->setupUi(toFillin);
422 kval->label->setText(paramName);
423 kval->lineeditwidget->setText(value);
424 QDomElement klistelem = pa.firstChildElement("keywords");
425 QDomElement kdisplaylistelem = pa.firstChildElement("keywordsdisplay");
426 QStringList keywordlist;
427 QStringList keyworddisplaylist;
428 if (!klistelem.isNull()) {
429 keywordlist = klistelem.text().split(';');
430 keyworddisplaylist = i18n(kdisplaylistelem.text().toUtf8().data()).split(';');
432 if (keyworddisplaylist.count() != keywordlist.count()) {
433 keyworddisplaylist = keywordlist;
435 for (int i = 0; i < keywordlist.count(); i++) {
436 kval->comboboxwidget->addItem(keyworddisplaylist.at(i), keywordlist.at(i));
438 // Add disabled user prompt at index 0
439 kval->comboboxwidget->insertItem(0, i18n("<select a keyword>"), "");
440 kval->comboboxwidget->model()->setData( kval->comboboxwidget->model()->index(0,0), QVariant(Qt::NoItemFlags), Qt::UserRole -1);
441 kval->comboboxwidget->setCurrentIndex(0);
442 m_valueItems[paramName] = kval;
443 connect(kval->lineeditwidget, SIGNAL(editingFinished()) , this, SLOT(collectAllParameters()));
444 connect(kval->comboboxwidget, SIGNAL(activated (const QString&)), this, SLOT(collectAllParameters()));
445 m_uiItems.append(kval);
446 } else if (type == "fontfamily") {
447 Fontval* fval = new Fontval;
448 fval->setupUi(toFillin);
449 fval->name->setText(paramName);
450 fval->fontfamilywidget->setCurrentFont(QFont(value));
451 m_valueItems[paramName] = fval;
452 connect(fval->fontfamilywidget, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(collectAllParameters())) ;
453 m_uiItems.append(fval);
454 } else if (type == "filterjob") {
455 QVBoxLayout *l= new QVBoxLayout(toFillin);
456 QPushButton *button = new QPushButton(paramName, toFillin);
457 l->addWidget(button);
458 m_valueItems[paramName] = button;
459 connect(button, SIGNAL(pressed()), this, SLOT(slotStartFilterJobAction()));
466 m_vbox->addWidget(toFillin);
470 m_vbox->addStretch();
472 if (m_keyframeEditor)
473 m_keyframeEditor->checkVisibleParam();
475 // Make sure all doubleparam spinboxes have the same width, looks much better
476 QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
478 for (int i = 0; i < allWidgets.count(); i++) {
479 if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
481 for (int i = 0; i < allWidgets.count(); i++) {
482 allWidgets.at(i)->setSpinSize(minSize);
486 ParameterContainer::~ParameterContainer()
492 void ParameterContainer::meetDependency(const QString& name, QString type, QString value)
494 if (type == "curve") {
495 KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
497 int color = value.toInt();
498 curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
500 } else if (type == "bezier_spline") {
501 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
503 widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10 + 0.5)));
508 wipeInfo ParameterContainer::getWipeInfo(QString value)
511 // Convert old geometry values that used a comma as separator
512 if (value.contains(',')) value.replace(',','/');
513 QString start = value.section(';', 0, 0);
514 QString end = value.section(';', 1, 1).section('=', 1, 1);
515 if (start.startsWith("-100%/0"))
517 else if (start.startsWith("100%/0"))
519 else if (start.startsWith("0%/100%"))
521 else if (start.startsWith("0%/-100%"))
526 if (start.count(':') == 2)
527 info.startTransparency = start.section(':', -1).toInt();
529 info.startTransparency = 100;
531 if (end.startsWith("-100%/0"))
533 else if (end.startsWith("100%/0"))
535 else if (end.startsWith("0%/100%"))
537 else if (end.startsWith("0%/-100%"))
542 if (end.count(':') == 2)
543 info.endTransparency = end.section(':', -1).toInt();
545 info.endTransparency = 100;
550 void ParameterContainer::updateTimecodeFormat()
552 if (m_keyframeEditor)
553 m_keyframeEditor->updateTimecodeFormat();
555 QDomNodeList namenode = m_effect.elementsByTagName("parameter");
556 for (int i = 0; i < namenode.count() ; i++) {
557 QDomNode pa = namenode.item(i);
558 QDomElement na = pa.firstChildElement("name");
559 QString type = pa.attributes().namedItem("type").nodeValue();
560 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
562 if (type == "geometry") {
563 if (KdenliveSettings::on_monitor_effects()) {
564 if (m_geometryWidget) m_geometryWidget->updateTimecodeFormat();
566 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
567 geom->updateTimecodeFormat();
570 } else if (type == "position") {
571 PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
572 posi->updateTimecodeFormat();
575 } else if (type == "roto-spline") {
576 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems[paramName]);
577 widget->updateTimecodeFormat();
583 void ParameterContainer::slotCollectAllParameters()
585 if (m_valueItems.isEmpty() || m_effect.isNull()) return;
587 locale.setNumberOptions(QLocale::OmitGroupSeparator);
588 const QDomElement oldparam = m_effect.cloneNode().toElement();
589 //QDomElement newparam = oldparam.cloneNode().toElement();
590 QDomNodeList namenode = m_effect.elementsByTagName("parameter");
592 for (int i = 0; i < namenode.count() ; i++) {
593 QDomElement pa = namenode.item(i).toElement();
594 QDomElement na = pa.firstChildElement("name");
595 QString type = pa.attribute("type");
596 QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
597 if (type == "complex")
598 paramName.append("complex");
599 else if (type == "position")
600 paramName.append("position");
601 else if (type == "geometry")
602 paramName.append("geometry");
603 else if (type == "keyframe")
604 paramName.append("keyframe");
605 if (type != "simplekeyframe" && type != "fixed" && type != "addedgeometry" && !m_valueItems.contains(paramName)) {
606 kDebug() << "// Param: " << paramName << " NOT FOUND";
611 if (type == "double" || type == "constant") {
612 DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
613 setValue = locale.toString(doubleparam->getValue());
614 } else if (type == "list") {
615 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
616 setValue = box->itemData(box->currentIndex()).toString();
617 } else if (type == "bool") {
618 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
619 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
620 } else if (type == "color") {
621 ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
622 setValue = choosecolor->getColor();
623 if (pa.hasAttribute("paramprefix")) setValue.prepend(pa.attribute("paramprefix"));
624 } else if (type == "complex") {
625 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
626 namenode.item(i) = complex->getParamDesc();
627 } else if (type == "geometry") {
628 if (KdenliveSettings::on_monitor_effects()) {
629 if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getValue());
631 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
632 namenode.item(i).toElement().setAttribute("value", geom->getValue());
634 } else if (type == "addedgeometry") {
635 namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getExtraValue(namenode.item(i).toElement().attribute("name")));
636 } else if (type == "position") {
637 PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
638 int pos = pedit->getPosition();
639 setValue = QString::number(pos);
640 if (m_effect.attribute("id") == "fadein" || m_effect.attribute("id") == "fade_from_black") {
641 // Make sure duration is not longer than clip
644 pedit->setPosition(pos);
646 EffectsList::setParameter(m_effect, "in", QString::number(m_in));
647 EffectsList::setParameter(m_effect, "out", QString::number(m_in + pos));
649 } else if (m_effect.attribute("id") == "fadeout" || m_effect.attribute("id") == "fade_to_black") {
650 // Make sure duration is not longer than clip
653 pedit->setPosition(pos);
655 EffectsList::setParameter(m_effect, "in", QString::number(m_out - pos));
656 EffectsList::setParameter(m_effect, "out", QString::number(m_out));
659 } else if (type == "curve") {
660 KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
661 QList<QPointF> points = curve->curve().points();
662 QString number = pa.attribute("number");
663 QString inName = pa.attribute("inpoints");
664 QString outName = pa.attribute("outpoints");
665 int off = pa.attribute("min").toInt();
666 int end = pa.attribute("max").toInt();
667 if (oldparam.attribute("version").toDouble() > 0.2) {
668 EffectsList::setParameter(m_effect, number, locale.toString(points.count() / 10.));
670 EffectsList::setParameter(m_effect, number, QString::number(points.count()));
672 for (int j = 0; (j < points.count() && j + off <= end); j++) {
674 in.replace("%i", QString::number(j + off));
675 QString out = outName;
676 out.replace("%i", QString::number(j + off));
677 EffectsList::setParameter(m_effect, in, locale.toString(points.at(j).x()));
678 EffectsList::setParameter(m_effect, out, locale.toString(points.at(j).y()));
680 QString depends = pa.attribute("depends");
681 if (!depends.isEmpty())
682 meetDependency(paramName, type, EffectsList::parameter(m_effect, depends));
683 } else if (type == "bezier_spline") {
684 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
685 setValue = widget->spline();
686 QString depends = pa.attribute("depends");
687 if (!depends.isEmpty())
688 meetDependency(paramName, type, EffectsList::parameter(m_effect, depends));
690 } else if (type == "roto-spline") {
691 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
692 setValue = widget->getSpline();
694 } else if (type == "wipe") {
695 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
697 if (wp->start_left->isChecked())
699 else if (wp->start_right->isChecked())
701 else if (wp->start_up->isChecked())
703 else if (wp->start_down->isChecked())
705 else if (wp->start_center->isChecked())
709 info.startTransparency = wp->start_transp->value();
711 if (wp->end_left->isChecked())
713 else if (wp->end_right->isChecked())
715 else if (wp->end_up->isChecked())
717 else if (wp->end_down->isChecked())
719 else if (wp->end_center->isChecked())
723 info.endTransparency = wp->end_transp->value();
725 setValue = getWipeString(info);
726 } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
727 QString realName = i18n(na.toElement().text().toUtf8().data());
728 QString val = m_keyframeEditor->getValue(realName);
729 pa.setAttribute("keyframes", val);
731 if (m_keyframeEditor->isVisibleParam(realName)) {
732 pa.setAttribute("intimeline", "1");
734 else if (pa.hasAttribute("intimeline"))
735 pa.removeAttribute("intimeline");
736 } else if (type == "url") {
737 KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
738 setValue = req->url().path();
739 } else if (type == "keywords"){
740 QLineEdit *line = ((Keywordval*)m_valueItems.value(paramName))->lineeditwidget;
741 QComboBox *combo = ((Keywordval*)m_valueItems.value(paramName))->comboboxwidget;
742 if(combo->currentIndex())
744 QString comboval = combo->itemData(combo->currentIndex()).toString();
745 line->insert(comboval);
746 combo->setCurrentIndex(0);
748 setValue = line->text();
749 } else if (type == "fontfamily") {
750 QFontComboBox* fontfamily = ((Fontval*)m_valueItems.value(paramName))->fontfamilywidget;
751 setValue = fontfamily->currentFont().family();
753 if (!setValue.isNull())
754 pa.setAttribute("value", setValue);
757 emit parameterChanged(oldparam, m_effect, m_effect.attribute("kdenlive_ix").toInt());
760 QString ParameterContainer::getWipeString(wipeInfo info)
765 switch (info.start) {
767 start = "-100%/0%:100%x100%";
770 start = "100%/0%:100%x100%";
773 start = "0%/100%:100%x100%";
776 start = "0%/-100%:100%x100%";
779 start = "0%/0%:100%x100%";
782 start.append(':' + QString::number(info.startTransparency));
786 end = "-100%/0%:100%x100%";
789 end = "100%/0%:100%x100%";
792 end = "0%/100%:100%x100%";
795 end = "0%/-100%:100%x100%";
798 end = "0%/0%:100%x100%";
801 end.append(':' + QString::number(info.endTransparency));
802 return QString(start + ";-1=" + end);
805 void ParameterContainer::updateParameter(const QString &key, const QString &value)
807 m_effect.setAttribute(key, value);
810 void ParameterContainer::slotStartFilterJobAction()
812 QDomNodeList namenode = m_effect.elementsByTagName("parameter");
813 for (int i = 0; i < namenode.count() ; i++) {
814 QDomElement pa = namenode.item(i).toElement();
815 QString type = pa.attribute("type");
816 if (type == "filterjob") {
817 emit startFilterJob(pa.attribute("filtertag"), pa.attribute("filterparams"), pa.attribute("finalfilter"), pa.attribute("consumer"), pa.attribute("consumerparams"), pa.attribute("wantedproperties"));
818 kDebug()<<" - - -PROPS:\n"<<pa.attribute("filtertag")<<"-"<< pa.attribute("filterparams")<<"-"<< pa.attribute("consumer")<<"-"<< pa.attribute("consumerparams")<<"-"<< pa.attribute("wantedproperties");
825 void ParameterContainer::clearLayout(QLayout *layout)
828 while((item = layout->takeAt(0))) {
829 if (item->layout()) {
830 clearLayout(item->layout());
831 delete item->layout();
833 if (item->widget()) {
834 delete item->widget();
840 bool ParameterContainer::needsMonitorEffectScene() const
842 return m_needsMonitorEffectScene;