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),
103 m_in = info.cropStart.frames(KdenliveSettings::project_fps());
104 m_out = (info.cropStart + info.cropDuration).frames(KdenliveSettings::project_fps()) - 1;
106 QDomNodeList namenode = effect.childNodes(); //elementsByTagName("parameter");
108 QDomElement e = effect.toElement();
109 int minFrame = e.attribute("start").toInt();
110 int maxFrame = e.attribute("end").toInt();
111 // In transitions, maxFrame is in fact one frame after the end of transition
112 if (maxFrame > 0) maxFrame --;
114 bool disable = effect.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
115 parent->setEnabled(!disable);
118 m_vbox = new QVBoxLayout(parent);
119 m_vbox->setContentsMargins(4, 0, 4, 0);
120 m_vbox->setSpacing(2);
122 for (int i = 0; i < namenode.count() ; i++) {
123 QDomElement pa = namenode.item(i).toElement();
124 if (pa.tagName() != "parameter") continue;
125 QDomElement na = pa.firstChildElement("name");
126 QDomElement commentElem = pa.firstChildElement("comment");
127 QString type = pa.attribute("type");
128 QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
130 if (!commentElem.isNull())
131 comment = i18n(commentElem.text().toUtf8().data());
132 QWidget * toFillin = new QWidget(parent);
133 QString value = pa.attribute("value").isNull() ?
134 pa.attribute("default") : pa.attribute("value");
137 /** See effects/README for info on the different types */
139 if (type == "double" || type == "constant") {
142 if (pa.attribute("min").contains('%'))
143 min = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("min"), m_metaInfo->frameSize);
145 min = pa.attribute("min").toDouble();
146 if (pa.attribute("max").contains('%'))
147 max = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("max"), m_metaInfo->frameSize);
149 max = pa.attribute("max").toDouble();
151 DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, value.toDouble(), min, max,
152 pa.attribute("default").toDouble(), comment, -1, pa.attribute("suffix"), pa.attribute("decimals").toInt(), parent);
153 doubleparam->setFocusPolicy(Qt::StrongFocus);
154 m_vbox->addWidget(doubleparam);
155 m_valueItems[paramName] = doubleparam;
156 connect(doubleparam, SIGNAL(valueChanged(double)), this, SLOT(slotCollectAllParameters()));
157 connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
158 } else if (type == "list") {
159 Listval *lsval = new Listval;
160 lsval->setupUi(toFillin);
161 lsval->list->setFocusPolicy(Qt::StrongFocus);
162 QStringList listitems = pa.attribute("paramlist").split(';');
163 if (listitems.count() == 1) {
164 // probably custom effect created before change to ';' as separator
165 listitems = pa.attribute("paramlist").split(",");
167 QDomElement list = pa.firstChildElement("paramlistdisplay");
168 QStringList listitemsdisplay;
169 if (!list.isNull()) {
170 listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
172 listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
174 if (listitemsdisplay.count() != listitems.count())
175 listitemsdisplay = listitems;
176 lsval->list->setIconSize(QSize(30, 30));
177 for (int i = 0; i < listitems.count(); i++) {
178 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
179 QString entry = listitems.at(i);
180 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
181 if (!MainWindow::m_lumacache.contains(entry)) {
183 MainWindow::m_lumacache.insert(entry, pix.scaled(30, 30, Qt::KeepAspectRatio, Qt::SmoothTransformation));
185 lsval->list->setItemIcon(i, QPixmap::fromImage(MainWindow::m_lumacache.value(entry)));
188 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
189 lsval->name->setText(paramName);
190 lsval->labelComment->setText(comment);
191 lsval->widgetComment->setHidden(true);
192 m_valueItems[paramName] = lsval;
193 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(slotCollectAllParameters()));
194 if (!comment.isEmpty())
195 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
196 m_uiItems.append(lsval);
197 } else if (type == "bool") {
198 Boolval *bval = new Boolval;
199 bval->setupUi(toFillin);
200 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
201 bval->name->setText(paramName);
202 bval->labelComment->setText(comment);
203 bval->widgetComment->setHidden(true);
204 m_valueItems[paramName] = bval;
205 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(slotCollectAllParameters()));
206 if (!comment.isEmpty())
207 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
208 m_uiItems.append(bval);
209 } else if (type == "complex") {
210 ComplexParameter *pl = new ComplexParameter;
211 pl->setupParam(effect, pa.attribute("name"), 0, 100);
212 m_vbox->addWidget(pl);
213 m_valueItems[paramName+"complex"] = pl;
214 connect(pl, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
215 } else if (type == "geometry") {
216 if (KdenliveSettings::on_monitor_effects()) {
217 m_geometryWidget = new GeometryWidget(m_metaInfo->monitor, m_metaInfo->timecode, 0, true, effect.hasAttribute("showrotation"), parent);
218 m_geometryWidget->setFrameSize(m_metaInfo->frameSize);
219 m_geometryWidget->slotShowScene(!disable);
220 // connect this before setupParam to make sure the monitor scene shows up at startup
221 connect(m_geometryWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
222 connect(m_geometryWidget, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
223 if (minFrame == maxFrame)
224 m_geometryWidget->setupParam(pa, m_in, m_out);
226 m_geometryWidget->setupParam(pa, minFrame, maxFrame);
227 m_vbox->addWidget(m_geometryWidget);
228 m_valueItems[paramName+"geometry"] = m_geometryWidget;
229 connect(m_geometryWidget, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
230 connect(this, SIGNAL(syncEffectsPos(int)), m_geometryWidget, SLOT(slotSyncPosition(int)));
231 connect(this, SIGNAL(effectStateChanged(bool)), m_geometryWidget, SLOT(slotShowScene(bool)));
233 Geometryval *geo = new Geometryval(m_metaInfo->profile, m_metaInfo->timecode, m_metaInfo->frameSize, 0);
234 if (minFrame == maxFrame)
235 geo->setupParam(pa, m_in, m_out);
237 geo->setupParam(pa, minFrame, maxFrame);
238 m_vbox->addWidget(geo);
239 m_valueItems[paramName+"geometry"] = geo;
240 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
241 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
242 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
244 } else if (type == "addedgeometry") {
245 // this is a parameter that should be linked to the geometry widget, for example rotation, shear, ...
246 if (m_geometryWidget) m_geometryWidget->addParameter(pa);
247 } else if (type == "keyframe" || type == "simplekeyframe") {
248 // keyframe editor widget
249 if (m_keyframeEditor == NULL) {
251 if (pa.attribute("widget") == "corners") {
252 // we want a corners-keyframe-widget
253 CornersWidget *corners = new CornersWidget(m_metaInfo->monitor, pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt(), parent);
254 corners->slotShowScene(!disable);
255 connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
256 connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
257 connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
258 geo = static_cast<KeyframeEdit *>(corners);
260 geo = new KeyframeEdit(pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt());
262 m_vbox->addWidget(geo);
263 m_valueItems[paramName+"keyframe"] = geo;
264 m_keyframeEditor = geo;
265 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
266 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
267 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
269 // we already have a keyframe editor, so just add another column for the new param
270 m_keyframeEditor->addParameter(pa);
272 } else if (type == "color") {
273 if (pa.hasAttribute("paramprefix")) value.remove(0, pa.attribute("paramprefix").size());
274 if (value.startsWith('#'))
275 value = value.replace('#', "0x");
276 ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, value, parent);
277 choosecolor->setAlphaChannelEnabled(true);
278 m_vbox->addWidget(choosecolor);
279 m_valueItems[paramName] = choosecolor;
280 connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
281 connect(choosecolor, SIGNAL(modified()) , this, SLOT(slotCollectAllParameters()));
282 } else if (type == "position") {
283 int pos = value.toInt();
284 if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
286 } else if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
287 // fadeout position starts from clip end
290 PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_metaInfo->timecode);
291 m_vbox->addWidget(posedit);
292 m_valueItems[paramName+"position"] = posedit;
293 connect(posedit, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
294 } else if (type == "curve") {
295 KisCurveWidget *curve = new KisCurveWidget(parent);
296 curve->setMaxPoints(pa.attribute("max").toInt());
297 QList<QPointF> points;
299 if (e.attribute("version").toDouble() > 0.2) {
300 // Rounding gives really weird results. (int) (10 * 0.3) gives 2! So for now, add 0.5 to get correct result
301 number = EffectsList::parameter(e, pa.attribute("number")).toDouble() * 10 + 0.5;
303 number = EffectsList::parameter(e, pa.attribute("number")).toInt();
305 QString inName = pa.attribute("inpoints");
306 QString outName = pa.attribute("outpoints");
307 int start = pa.attribute("min").toInt();
308 for (int j = start; j <= number; j++) {
310 in.replace("%i", QString::number(j));
311 QString out = outName;
312 out.replace("%i", QString::number(j));
313 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
315 if (!points.isEmpty())
316 curve->setCurve(KisCubicCurve(points));
317 MySpinBox *spinin = new MySpinBox();
318 spinin->setRange(0, 1000);
319 MySpinBox *spinout = new MySpinBox();
320 spinout->setRange(0, 1000);
321 curve->setupInOutControls(spinin, spinout, 0, 1000);
322 m_vbox->addWidget(curve);
323 m_vbox->addWidget(spinin);
324 m_vbox->addWidget(spinout);
326 connect(curve, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
327 m_valueItems[paramName] = curve;
329 QString depends = pa.attribute("depends");
330 if (!depends.isEmpty())
331 meetDependency(paramName, type, EffectsList::parameter(e, depends));
332 } else if (type == "bezier_spline") {
333 BezierSplineWidget *widget = new BezierSplineWidget(value, parent);
335 m_vbox->addWidget(widget);
336 m_valueItems[paramName] = widget;
337 connect(widget, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
338 QString depends = pa.attribute("depends");
339 if (!depends.isEmpty())
340 meetDependency(paramName, type, EffectsList::parameter(e, depends));
342 } else if (type == "roto-spline") {
343 RotoWidget *roto = new RotoWidget(value, m_metaInfo->monitor, info, m_metaInfo->timecode, parent);
344 roto->slotShowScene(!disable);
345 connect(roto, SIGNAL(valueChanged()), this, SLOT(slotCollectAllParameters()));
346 connect(roto, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
347 connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
348 connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
349 connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
350 m_vbox->addWidget(roto);
351 m_valueItems[paramName] = roto;
353 } else if (type == "wipe") {
354 Wipeval *wpval = new Wipeval;
355 wpval->setupUi(toFillin);
356 wipeInfo w = getWipeInfo(value);
359 wpval->start_up->setChecked(true);
362 wpval->start_down->setChecked(true);
365 wpval->start_right->setChecked(true);
368 wpval->start_left->setChecked(true);
371 wpval->start_center->setChecked(true);
376 wpval->end_up->setChecked(true);
379 wpval->end_down->setChecked(true);
382 wpval->end_right->setChecked(true);
385 wpval->end_left->setChecked(true);
388 wpval->end_center->setChecked(true);
391 wpval->start_transp->setValue(w.startTransparency);
392 wpval->end_transp->setValue(w.endTransparency);
393 m_valueItems[paramName] = wpval;
394 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
395 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
396 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
397 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
398 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
399 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
400 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
401 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
402 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
403 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
404 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
405 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
406 //wpval->title->setTitle(na.toElement().text());
407 m_uiItems.append(wpval);
408 } else if (type == "url") {
409 Urlval *cval = new Urlval;
410 cval->setupUi(toFillin);
411 cval->label->setText(paramName);
412 cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
413 m_valueItems[paramName] = cval;
414 cval->urlwidget->setUrl(KUrl(value));
415 connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(slotCollectAllParameters()));
416 connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(slotCollectAllParameters()));
417 m_uiItems.append(cval);
418 } else if (type == "keywords") {
419 Keywordval* kval = new Keywordval;
420 kval->setupUi(toFillin);
421 kval->label->setText(paramName);
422 kval->lineeditwidget->setText(value);
423 QDomElement klistelem = pa.firstChildElement("keywords");
424 QDomElement kdisplaylistelem = pa.firstChildElement("keywordsdisplay");
425 QStringList keywordlist;
426 QStringList keyworddisplaylist;
427 if (!klistelem.isNull()) {
428 keywordlist = klistelem.text().split(';');
429 keyworddisplaylist = i18n(kdisplaylistelem.text().toUtf8().data()).split(';');
431 if (keyworddisplaylist.count() != keywordlist.count()) {
432 keyworddisplaylist = keywordlist;
434 for (int i = 0; i < keywordlist.count(); i++) {
435 kval->comboboxwidget->addItem(keyworddisplaylist.at(i), keywordlist.at(i));
437 // Add disabled user prompt at index 0
438 kval->comboboxwidget->insertItem(0, i18n("<select a keyword>"), "");
439 kval->comboboxwidget->model()->setData( kval->comboboxwidget->model()->index(0,0), QVariant(Qt::NoItemFlags), Qt::UserRole -1);
440 kval->comboboxwidget->setCurrentIndex(0);
441 m_valueItems[paramName] = kval;
442 connect(kval->lineeditwidget, SIGNAL(editingFinished()) , this, SLOT(collectAllParameters()));
443 connect(kval->comboboxwidget, SIGNAL(activated (const QString&)), this, SLOT(collectAllParameters()));
444 m_uiItems.append(kval);
445 } else if (type == "fontfamily") {
446 Fontval* fval = new Fontval;
447 fval->setupUi(toFillin);
448 fval->name->setText(paramName);
449 fval->fontfamilywidget->setCurrentFont(QFont(value));
450 m_valueItems[paramName] = fval;
451 connect(fval->fontfamilywidget, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(collectAllParameters())) ;
452 m_uiItems.append(fval);
453 } else if (type == "filterjob") {
454 QVBoxLayout *l= new QVBoxLayout(toFillin);
455 QPushButton *button = new QPushButton(paramName, toFillin);
456 l->addWidget(button);
457 m_valueItems[paramName] = button;
458 connect(button, SIGNAL(pressed()), this, SLOT(slotStartFilterJobAction()));
465 m_vbox->addWidget(toFillin);
469 m_vbox->addStretch();
471 if (m_keyframeEditor)
472 m_keyframeEditor->checkVisibleParam();
474 // Make sure all doubleparam spinboxes have the same width, looks much better
475 QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
477 for (int i = 0; i < allWidgets.count(); i++) {
478 if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
480 for (int i = 0; i < allWidgets.count(); i++) {
481 allWidgets.at(i)->setSpinSize(minSize);
485 ParameterContainer::~ParameterContainer()
491 void ParameterContainer::meetDependency(const QString& name, QString type, QString value)
493 if (type == "curve") {
494 KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
496 int color = value.toInt();
497 curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
499 } else if (type == "bezier_spline") {
500 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
502 widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10 + 0.5)));
507 wipeInfo ParameterContainer::getWipeInfo(QString value)
510 // Convert old geometry values that used a comma as separator
511 if (value.contains(',')) value.replace(',','/');
512 QString start = value.section(';', 0, 0);
513 QString end = value.section(';', 1, 1).section('=', 1, 1);
514 if (start.startsWith("-100%/0"))
516 else if (start.startsWith("100%/0"))
518 else if (start.startsWith("0%/100%"))
520 else if (start.startsWith("0%/-100%"))
525 if (start.count(':') == 2)
526 info.startTransparency = start.section(':', -1).toInt();
528 info.startTransparency = 100;
530 if (end.startsWith("-100%/0"))
532 else if (end.startsWith("100%/0"))
534 else if (end.startsWith("0%/100%"))
536 else if (end.startsWith("0%/-100%"))
541 if (end.count(':') == 2)
542 info.endTransparency = end.section(':', -1).toInt();
544 info.endTransparency = 100;
549 void ParameterContainer::updateTimecodeFormat()
551 if (m_keyframeEditor)
552 m_keyframeEditor->updateTimecodeFormat();
554 QDomNodeList namenode = m_effect.elementsByTagName("parameter");
555 for (int i = 0; i < namenode.count() ; i++) {
556 QDomNode pa = namenode.item(i);
557 QDomElement na = pa.firstChildElement("name");
558 QString type = pa.attributes().namedItem("type").nodeValue();
559 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
561 if (type == "geometry") {
562 if (KdenliveSettings::on_monitor_effects()) {
563 if (m_geometryWidget) m_geometryWidget->updateTimecodeFormat();
565 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
566 geom->updateTimecodeFormat();
569 } else if (type == "position") {
570 PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
571 posi->updateTimecodeFormat();
574 } else if (type == "roto-spline") {
575 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems[paramName]);
576 widget->updateTimecodeFormat();
582 void ParameterContainer::slotCollectAllParameters()
584 if (m_valueItems.isEmpty() || m_effect.isNull()) return;
586 locale.setNumberOptions(QLocale::OmitGroupSeparator);
587 const QDomElement oldparam = m_effect.cloneNode().toElement();
588 //QDomElement newparam = oldparam.cloneNode().toElement();
589 QDomNodeList namenode = m_effect.elementsByTagName("parameter");
591 for (int i = 0; i < namenode.count() ; i++) {
592 QDomElement pa = namenode.item(i).toElement();
593 QDomElement na = pa.firstChildElement("name");
594 QString type = pa.attribute("type");
595 QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
596 if (type == "complex")
597 paramName.append("complex");
598 else if (type == "position")
599 paramName.append("position");
600 else if (type == "geometry")
601 paramName.append("geometry");
602 else if (type == "keyframe")
603 paramName.append("keyframe");
604 if (type != "simplekeyframe" && type != "fixed" && type != "addedgeometry" && !m_valueItems.contains(paramName)) {
605 kDebug() << "// Param: " << paramName << " NOT FOUND";
610 if (type == "double" || type == "constant") {
611 DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
612 setValue = locale.toString(doubleparam->getValue());
613 } else if (type == "list") {
614 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
615 setValue = box->itemData(box->currentIndex()).toString();
616 } else if (type == "bool") {
617 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
618 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
619 } else if (type == "color") {
620 ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
621 setValue = choosecolor->getColor();
622 if (pa.hasAttribute("paramprefix")) setValue.prepend(pa.attribute("paramprefix"));
623 } else if (type == "complex") {
624 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
625 namenode.item(i) = complex->getParamDesc();
626 } else if (type == "geometry") {
627 if (KdenliveSettings::on_monitor_effects()) {
628 if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getValue());
630 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
631 namenode.item(i).toElement().setAttribute("value", geom->getValue());
633 } else if (type == "addedgeometry") {
634 namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getExtraValue(namenode.item(i).toElement().attribute("name")));
635 } else if (type == "position") {
636 PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
637 int pos = pedit->getPosition();
638 setValue = QString::number(pos);
639 if (m_effect.attribute("id") == "fadein" || m_effect.attribute("id") == "fade_from_black") {
640 // Make sure duration is not longer than clip
643 pedit->setPosition(pos);
645 EffectsList::setParameter(m_effect, "in", QString::number(m_in));
646 EffectsList::setParameter(m_effect, "out", QString::number(m_in + pos));
648 } else if (m_effect.attribute("id") == "fadeout" || m_effect.attribute("id") == "fade_to_black") {
649 // Make sure duration is not longer than clip
652 pedit->setPosition(pos);
654 EffectsList::setParameter(m_effect, "in", QString::number(m_out - pos));
655 EffectsList::setParameter(m_effect, "out", QString::number(m_out));
658 } else if (type == "curve") {
659 KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
660 QList<QPointF> points = curve->curve().points();
661 QString number = pa.attribute("number");
662 QString inName = pa.attribute("inpoints");
663 QString outName = pa.attribute("outpoints");
664 int off = pa.attribute("min").toInt();
665 int end = pa.attribute("max").toInt();
666 if (oldparam.attribute("version").toDouble() > 0.2) {
667 EffectsList::setParameter(m_effect, number, locale.toString(points.count() / 10.));
669 EffectsList::setParameter(m_effect, number, QString::number(points.count()));
671 for (int j = 0; (j < points.count() && j + off <= end); j++) {
673 in.replace("%i", QString::number(j + off));
674 QString out = outName;
675 out.replace("%i", QString::number(j + off));
676 EffectsList::setParameter(m_effect, in, locale.toString(points.at(j).x()));
677 EffectsList::setParameter(m_effect, out, locale.toString(points.at(j).y()));
679 QString depends = pa.attribute("depends");
680 if (!depends.isEmpty())
681 meetDependency(paramName, type, EffectsList::parameter(m_effect, depends));
682 } else if (type == "bezier_spline") {
683 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
684 setValue = widget->spline();
685 QString depends = pa.attribute("depends");
686 if (!depends.isEmpty())
687 meetDependency(paramName, type, EffectsList::parameter(m_effect, depends));
689 } else if (type == "roto-spline") {
690 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
691 setValue = widget->getSpline();
693 } else if (type == "wipe") {
694 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
696 if (wp->start_left->isChecked())
698 else if (wp->start_right->isChecked())
700 else if (wp->start_up->isChecked())
702 else if (wp->start_down->isChecked())
704 else if (wp->start_center->isChecked())
708 info.startTransparency = wp->start_transp->value();
710 if (wp->end_left->isChecked())
712 else if (wp->end_right->isChecked())
714 else if (wp->end_up->isChecked())
716 else if (wp->end_down->isChecked())
718 else if (wp->end_center->isChecked())
722 info.endTransparency = wp->end_transp->value();
724 setValue = getWipeString(info);
725 } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
726 QString realName = i18n(na.toElement().text().toUtf8().data());
727 QString val = m_keyframeEditor->getValue(realName);
728 pa.setAttribute("keyframes", val);
730 if (m_keyframeEditor->isVisibleParam(realName)) {
731 pa.setAttribute("intimeline", "1");
733 else if (pa.hasAttribute("intimeline"))
734 pa.removeAttribute("intimeline");
735 } else if (type == "url") {
736 KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
737 setValue = req->url().path();
738 } else if (type == "keywords"){
739 QLineEdit *line = ((Keywordval*)m_valueItems.value(paramName))->lineeditwidget;
740 QComboBox *combo = ((Keywordval*)m_valueItems.value(paramName))->comboboxwidget;
741 if(combo->currentIndex())
743 QString comboval = combo->itemData(combo->currentIndex()).toString();
744 line->insert(comboval);
745 combo->setCurrentIndex(0);
747 setValue = line->text();
748 } else if (type == "fontfamily") {
749 QFontComboBox* fontfamily = ((Fontval*)m_valueItems.value(paramName))->fontfamilywidget;
750 setValue = fontfamily->currentFont().family();
752 if (!setValue.isNull())
753 pa.setAttribute("value", setValue);
756 emit parameterChanged(oldparam, m_effect, m_effect.attribute("kdenlive_ix").toInt());
759 QString ParameterContainer::getWipeString(wipeInfo info)
764 switch (info.start) {
766 start = "-100%/0%:100%x100%";
769 start = "100%/0%:100%x100%";
772 start = "0%/100%:100%x100%";
775 start = "0%/-100%:100%x100%";
778 start = "0%/0%:100%x100%";
781 start.append(':' + QString::number(info.startTransparency));
785 end = "-100%/0%:100%x100%";
788 end = "100%/0%:100%x100%";
791 end = "0%/100%:100%x100%";
794 end = "0%/-100%:100%x100%";
797 end = "0%/0%:100%x100%";
800 end.append(':' + QString::number(info.endTransparency));
801 return QString(start + ";-1=" + end);
804 void ParameterContainer::updateParameter(const QString &key, const QString &value)
806 m_effect.setAttribute(key, value);
809 void ParameterContainer::slotStartFilterJobAction()
811 QDomNodeList namenode = m_effect.elementsByTagName("parameter");
812 for (int i = 0; i < namenode.count() ; i++) {
813 QDomElement pa = namenode.item(i).toElement();
814 QString type = pa.attribute("type");
815 if (type == "filterjob") {
816 emit startFilterJob(pa.attribute("filtertag"), pa.attribute("filterparams"), pa.attribute("finalfilter"), pa.attribute("consumer"), pa.attribute("consumerparams"), pa.attribute("wantedproperties"));
817 kDebug()<<" - - -PROPS:\n"<<pa.attribute("filtertag")<<"-"<< pa.attribute("filterparams")<<"-"<< pa.attribute("consumer")<<"-"<< pa.attribute("consumerparams")<<"-"<< pa.attribute("wantedproperties");
824 void ParameterContainer::clearLayout(QLayout *layout)
827 while((item = layout->takeAt(0))) {
828 if (item->layout()) {
829 clearLayout(item->layout());
830 delete item->layout();
832 if (item->widget()) {
833 delete item->widget();
839 bool ParameterContainer::needsMonitorEffectScene()