1 /***************************************************************************
2 * Copyright (C) 2008 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 ***************************************************************************/
21 #include "collapsibleeffect.h"
23 #include "ui_listval_ui.h"
24 #include "ui_boolval_ui.h"
25 #include "ui_wipeval_ui.h"
26 #include "ui_urlval_ui.h"
27 #include "complexparameter.h"
28 #include "geometryval.h"
29 #include "positionedit.h"
30 #include "projectlist.h"
31 #include "effectslist.h"
32 #include "kdenlivesettings.h"
33 #include "profilesdialog.h"
34 #include "kis_curve_widget.h"
35 #include "kis_cubic_curve.h"
36 #include "choosecolorwidget.h"
37 #include "geometrywidget.h"
38 #include "colortools.h"
39 #include "doubleparameterwidget.h"
40 #include "cornerswidget.h"
41 #include "beziercurve/beziersplinewidget.h"
43 #include "rotoscoping/rotowidget.h"
48 #include <QVBoxLayout>
50 #include <KGlobalSettings>
52 #include <KFileDialog>
53 #include <KUrlRequester>
55 class Boolval: public QWidget, public Ui::Boolval_UI
59 class Listval: public QWidget, public Ui::Listval_UI
63 class Wipeval: public QWidget, public Ui::Wipeval_UI
67 class Urlval: public QWidget, public Ui::Urlval_UI
71 QMap<QString, QImage> CollapsibleEffect::iconCache;
73 void clearLayout(QLayout *layout)
76 while((item = layout->takeAt(0))) {
78 clearLayout(item->layout());
79 delete item->layout();
82 delete item->widget();
88 CollapsibleEffect::CollapsibleEffect(QDomElement effect, ItemInfo info, int ix, EffectMetaInfo *metaInfo, bool lastEffect, QWidget * parent) :
92 m_lastEffect(lastEffect),
95 setMouseTracking(true);
97 setFont(KGlobalSettings::smallestReadableFont());
98 QDomElement namenode = m_effect.firstChildElement("name");
99 if (namenode.isNull()) return;
100 QString type = m_effect.attribute("type", QString());
102 if (type == "audio") icon = KIcon("kdenlive-show-audio");
103 else if (m_effect.attribute("tag") == "region") icon = KIcon("kdenlive-mask-effect");
104 else if (type == "custom") icon = KIcon("kdenlive-custom-effect");
105 else icon = KIcon("kdenlive-show-video");
107 buttonUp->setIcon(KIcon("go-up"));
108 buttonUp->setToolTip(i18n("Move effect up"));
110 buttonDown->setIcon(KIcon("go-down"));
111 buttonDown->setToolTip(i18n("Move effect down"));
113 buttonDel->setIcon(KIcon("edit-delete"));
114 buttonDel->setToolTip(i18n("Delete effect"));
115 buttonSave->setIcon(KIcon("document-save"));
116 buttonSave->setToolTip(i18n("Save effect"));
118 buttonUp->setVisible(false);
119 buttonDown->setVisible(false);
120 buttonSave->setVisible(false);
121 buttonDel->setVisible(false);
123 /*buttonReset->setIcon(KIcon("view-refresh"));
124 buttonReset->setToolTip(i18n("Reset effect"));*/
125 //checkAll->setToolTip(i18n("Enable/Disable all effects"));
126 //buttonShowComments->setIcon(KIcon("help-about"));
127 //buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
129 title->setText(i18n(namenode.text().toUtf8().data()));
130 effectIcon->setPixmap(icon.pixmap(QSize(16,16)));
132 //QLabel *lab = new QLabel("HEllo", widgetFrame);
133 //m_vbox->addWidget(lab);
134 if (m_effect.attribute("disable") == "1") {
135 enabledBox->setCheckState(Qt::Unchecked);
136 title->setEnabled(false);
139 enabledBox->setCheckState(Qt::Checked);
142 connect(collapseButton, SIGNAL(clicked()), this, SLOT(slotSwitch()));
143 connect(enabledBox, SIGNAL(toggled(bool)), this, SLOT(slotEnable(bool)));
144 connect(buttonUp, SIGNAL(clicked()), this, SLOT(slotEffectUp()));
145 connect(buttonDown, SIGNAL(clicked()), this, SLOT(slotEffectDown()));
146 connect(buttonDel, SIGNAL(clicked()), this, SLOT(slotDeleteEffect()));
147 setupWidget(info, ix, metaInfo);
150 CollapsibleEffect::~CollapsibleEffect()
152 if (m_paramWidget) delete m_paramWidget;
156 void CollapsibleEffect::setActive(bool activate)
159 title->setBackgroundRole(m_active ? QPalette::AlternateBase : QPalette::Window);
160 title->setAutoFillBackground(m_active);
163 void CollapsibleEffect::mouseDoubleClickEvent ( QMouseEvent * event )
165 if (title->underMouse() && collapseButton->isEnabled()) slotSwitch();
166 QWidget::mouseDoubleClickEvent(event);
169 void CollapsibleEffect::mousePressEvent ( QMouseEvent * /*event*/ )
171 if (!m_active) emit activateEffect(m_paramWidget->index());
174 void CollapsibleEffect::enterEvent ( QEvent * event )
176 if (m_paramWidget->index() > 0) buttonUp->setVisible(true);
177 if (!m_lastEffect) buttonDown->setVisible(true);
178 buttonSave->setVisible(true);
179 buttonDel->setVisible(true);
180 QWidget::enterEvent(event);
183 void CollapsibleEffect::leaveEvent ( QEvent * event )
185 buttonUp->setVisible(false);
186 buttonDown->setVisible(false);
187 buttonSave->setVisible(false);
188 buttonDel->setVisible(false);
189 QWidget::leaveEvent(event);
192 void CollapsibleEffect::slotEnable(bool enable)
194 title->setEnabled(enable);
195 m_effect.setAttribute("disable", enable ? 0 : 1);
196 if (enable || KdenliveSettings::disable_effect_parameters()) {
197 widgetFrame->setEnabled(enable);
199 emit effectStateChanged(!enable, m_paramWidget->index());
202 void CollapsibleEffect::slotDeleteEffect()
204 emit deleteEffect(m_effect, m_paramWidget->index());
207 void CollapsibleEffect::slotEffectUp()
209 emit changeEffectPosition(m_paramWidget->index(), true);
212 void CollapsibleEffect::slotEffectDown()
214 emit changeEffectPosition(m_paramWidget->index(), false);
217 void CollapsibleEffect::slotSwitch()
219 bool enable = !widgetFrame->isVisible();
223 void CollapsibleEffect::slotShow(bool show)
225 widgetFrame->setVisible(show);
227 collapseButton->setArrowType(Qt::DownArrow);
230 collapseButton->setArrowType(Qt::RightArrow);
235 void CollapsibleEffect::setupWidget(ItemInfo info, int index, EffectMetaInfo *metaInfo)
237 if (m_effect.isNull()) {
238 // kDebug() << "// EMPTY EFFECT STACK";
241 if (m_effect.attribute("tag") == "region") {
242 QVBoxLayout *vbox = new QVBoxLayout(widgetFrame);
243 vbox->setContentsMargins(0, 0, 0, 0);
245 QDomNodeList effects = m_effect.elementsByTagName("effect");
246 QWidget *container = new QWidget(widgetFrame);
247 vbox->addWidget(container);
248 m_paramWidget = new ParameterContainer(m_effect.toElement(), info, metaInfo, index, container);
249 for (int i = 0; i < effects.count(); i++) {
250 CollapsibleEffect *coll = new CollapsibleEffect(effects.at(i).toElement(), info, i, metaInfo, container);
251 m_subParamWidgets.append(coll);
252 //container = new QWidget(widgetFrame);
253 vbox->addWidget(coll);
254 //p = new ParameterContainer(effects.at(i).toElement(), info, isEffect, container);
259 m_paramWidget = new ParameterContainer(m_effect, info, metaInfo, index, widgetFrame);
260 if (m_effect.firstChildElement("parameter").isNull()) {
261 // Effect has no parameter, don't allow expand
262 collapseButton->setEnabled(false);
263 widgetFrame->setVisible(false);
266 if (collapseButton->isEnabled()) slotShow(true);
267 connect (m_paramWidget, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)));
268 connect (this, SIGNAL(syncEffectsPos(int)), m_paramWidget, SIGNAL(syncEffectsPos(int)));
269 connect (this, SIGNAL(effectStateChanged(bool)), m_paramWidget, SIGNAL(effectStateChanged(bool)));
270 connect (m_paramWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
271 connect (m_paramWidget, SIGNAL(seekTimeline(int)), this, SIGNAL(seekTimeline(int)));
276 void CollapsibleEffect::updateTimecodeFormat()
278 m_paramWidget->updateTimecodeFormat();
279 if (!m_subParamWidgets.isEmpty()) {
281 for (int i = 0; i < m_subParamWidgets.count(); i++)
282 m_subParamWidgets.at(i)->updateTimecodeFormat();
286 void CollapsibleEffect::slotSyncEffectsPos(int pos)
288 emit syncEffectsPos(pos);
293 ParameterContainer::ParameterContainer(QDomElement effect, ItemInfo info, EffectMetaInfo *metaInfo, int index, QWidget * parent) :
295 m_keyframeEditor(NULL),
296 m_geometryWidget(NULL),
297 m_metaInfo(metaInfo),
300 m_in = info.cropStart.frames(KdenliveSettings::project_fps());
301 m_out = (info.cropStart + info.cropDuration).frames(KdenliveSettings::project_fps()) - 1;
303 QDomNodeList namenode = effect.childNodes(); //elementsByTagName("parameter");
305 QDomElement e = effect.toElement();
306 int minFrame = e.attribute("start").toInt();
307 int maxFrame = e.attribute("end").toInt();
308 // In transitions, maxFrame is in fact one frame after the end of transition
309 if (maxFrame > 0) maxFrame --;
311 bool disable = effect.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
312 parent->setEnabled(!disable);
315 m_vbox = new QVBoxLayout(parent);
316 m_vbox->setContentsMargins(0, 0, 0, 0);
317 m_vbox->setSpacing(2);
319 for (int i = 0; i < namenode.count() ; i++) {
320 QDomElement pa = namenode.item(i).toElement();
321 if (pa.tagName() != "parameter") continue;
322 QDomElement na = pa.firstChildElement("name");
323 QDomElement commentElem = pa.firstChildElement("comment");
324 QString type = pa.attribute("type");
325 QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
327 if (!commentElem.isNull())
328 comment = i18n(commentElem.text().toUtf8().data());
329 QWidget * toFillin = new QWidget(parent);
330 QString value = pa.attribute("value").isNull() ?
331 pa.attribute("default") : pa.attribute("value");
334 /** See effects/README for info on the different types */
336 if (type == "double" || type == "constant") {
339 if (pa.attribute("min").contains('%'))
340 min = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("min"), m_metaInfo->frameSize);
342 min = pa.attribute("min").toDouble();
343 if (pa.attribute("max").contains('%'))
344 max = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("max"), m_metaInfo->frameSize);
346 max = pa.attribute("max").toDouble();
348 DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, value.toDouble(), min, max,
349 pa.attribute("default").toDouble(), comment, -1, pa.attribute("suffix"), pa.attribute("decimals").toInt(), parent);
350 m_vbox->addWidget(doubleparam);
351 m_valueItems[paramName] = doubleparam;
352 connect(doubleparam, SIGNAL(valueChanged(double)), this, SLOT(slotCollectAllParameters()));
353 connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
354 } else if (type == "list") {
355 Listval *lsval = new Listval;
356 lsval->setupUi(toFillin);
357 QStringList listitems = pa.attribute("paramlist").split(';');
358 if (listitems.count() == 1) {
359 // probably custom effect created before change to ';' as separator
360 listitems = pa.attribute("paramlist").split(",");
362 QDomElement list = pa.firstChildElement("paramlistdisplay");
363 QStringList listitemsdisplay;
364 if (!list.isNull()) {
365 listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
367 listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
369 if (listitemsdisplay.count() != listitems.count())
370 listitemsdisplay = listitems;
371 lsval->list->setIconSize(QSize(30, 30));
372 for (int i = 0; i < listitems.count(); i++) {
373 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
374 QString entry = listitems.at(i);
375 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
376 if (!CollapsibleEffect::iconCache.contains(entry)) {
378 CollapsibleEffect::iconCache[entry] = pix.scaled(30, 30);
380 lsval->list->setItemIcon(i, QPixmap::fromImage(CollapsibleEffect::iconCache[entry]));
383 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
384 lsval->name->setText(paramName);
385 lsval->labelComment->setText(comment);
386 lsval->widgetComment->setHidden(true);
387 m_valueItems[paramName] = lsval;
388 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(slotCollectAllParameters()));
389 if (!comment.isEmpty())
390 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
391 m_uiItems.append(lsval);
392 } else if (type == "bool") {
393 Boolval *bval = new Boolval;
394 bval->setupUi(toFillin);
395 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
396 bval->name->setText(paramName);
397 bval->labelComment->setText(comment);
398 bval->widgetComment->setHidden(true);
399 m_valueItems[paramName] = bval;
400 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(slotCollectAllParameters()));
401 if (!comment.isEmpty())
402 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
403 m_uiItems.append(bval);
404 } else if (type == "complex") {
405 ComplexParameter *pl = new ComplexParameter;
406 pl->setupParam(effect, pa.attribute("name"), 0, 100);
407 m_vbox->addWidget(pl);
408 m_valueItems[paramName+"complex"] = pl;
409 connect(pl, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
410 } else if (type == "geometry") {
411 if (KdenliveSettings::on_monitor_effects()) {
412 m_geometryWidget = new GeometryWidget(m_metaInfo->monitor, m_metaInfo->timecode, 0, true, effect.hasAttribute("showrotation"), parent);
413 m_geometryWidget->setFrameSize(m_metaInfo->frameSize);
414 m_geometryWidget->slotShowScene(!disable);
415 // connect this before setupParam to make sure the monitor scene shows up at startup
416 connect(m_geometryWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
417 connect(m_geometryWidget, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
418 if (minFrame == maxFrame)
419 m_geometryWidget->setupParam(pa, m_in, m_out);
421 m_geometryWidget->setupParam(pa, minFrame, maxFrame);
422 m_vbox->addWidget(m_geometryWidget);
423 m_valueItems[paramName+"geometry"] = m_geometryWidget;
424 connect(m_geometryWidget, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
425 connect(this, SIGNAL(syncEffectsPos(int)), m_geometryWidget, SLOT(slotSyncPosition(int)));
426 connect(this, SIGNAL(effectStateChanged(bool)), m_geometryWidget, SLOT(slotShowScene(bool)));
428 Geometryval *geo = new Geometryval(m_metaInfo->profile, m_metaInfo->timecode, m_metaInfo->frameSize, 0);
429 if (minFrame == maxFrame)
430 geo->setupParam(pa, m_in, m_out);
432 geo->setupParam(pa, minFrame, maxFrame);
433 m_vbox->addWidget(geo);
434 m_valueItems[paramName+"geometry"] = geo;
435 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
436 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
437 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
439 } else if (type == "addedgeometry") {
440 // this is a parameter that should be linked to the geometry widget, for example rotation, shear, ...
441 if (m_geometryWidget) m_geometryWidget->addParameter(pa);
442 } else if (type == "keyframe" || type == "simplekeyframe") {
443 // keyframe editor widget
444 if (m_keyframeEditor == NULL) {
446 if (pa.attribute("widget") == "corners") {
447 // we want a corners-keyframe-widget
448 CornersWidget *corners = new CornersWidget(m_metaInfo->monitor, pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt(), parent);
449 corners->slotShowScene(!disable);
450 connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
451 connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
452 connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
453 geo = static_cast<KeyframeEdit *>(corners);
455 geo = new KeyframeEdit(pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt());
457 m_vbox->addWidget(geo);
458 m_valueItems[paramName+"keyframe"] = geo;
459 m_keyframeEditor = geo;
460 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
461 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
462 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
464 // we already have a keyframe editor, so just add another column for the new param
465 m_keyframeEditor->addParameter(pa);
467 } else if (type == "color") {
468 if (value.startsWith('#'))
469 value = value.replace('#', "0x");
470 ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, value, parent);
471 m_vbox->addWidget(choosecolor);
472 m_valueItems[paramName] = choosecolor;
473 connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
474 connect(choosecolor, SIGNAL(modified()) , this, SLOT(slotCollectAllParameters()));
475 } else if (type == "position") {
476 int pos = value.toInt();
477 if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
479 } else if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
480 // fadeout position starts from clip end
483 PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_metaInfo->timecode);
484 m_vbox->addWidget(posedit);
485 m_valueItems[paramName+"position"] = posedit;
486 connect(posedit, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
487 } else if (type == "curve") {
488 KisCurveWidget *curve = new KisCurveWidget(parent);
489 curve->setMaxPoints(pa.attribute("max").toInt());
490 QList<QPointF> points;
491 int number = EffectsList::parameter(e, pa.attribute("number")).toInt();
492 QString inName = pa.attribute("inpoints");
493 QString outName = pa.attribute("outpoints");
494 int start = pa.attribute("min").toInt();
495 for (int j = start; j <= number; j++) {
497 in.replace("%i", QString::number(j));
498 QString out = outName;
499 out.replace("%i", QString::number(j));
500 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
502 if (!points.isEmpty())
503 curve->setCurve(KisCubicCurve(points));
504 QSpinBox *spinin = new QSpinBox();
505 spinin->setRange(0, 1000);
506 QSpinBox *spinout = new QSpinBox();
507 spinout->setRange(0, 1000);
508 curve->setupInOutControls(spinin, spinout, 0, 1000);
509 m_vbox->addWidget(curve);
510 m_vbox->addWidget(spinin);
511 m_vbox->addWidget(spinout);
513 connect(curve, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
514 m_valueItems[paramName] = curve;
516 QString depends = pa.attribute("depends");
517 if (!depends.isEmpty())
518 meetDependency(paramName, type, EffectsList::parameter(e, depends));
519 } else if (type == "bezier_spline") {
520 BezierSplineWidget *widget = new BezierSplineWidget(value, parent);
522 m_vbox->addWidget(widget);
523 m_valueItems[paramName] = widget;
524 connect(widget, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
525 QString depends = pa.attribute("depends");
526 if (!depends.isEmpty())
527 meetDependency(paramName, type, EffectsList::parameter(e, depends));
529 } else if (type == "roto-spline") {
530 RotoWidget *roto = new RotoWidget(value, m_metaInfo->monitor, info, m_metaInfo->timecode, parent);
531 roto->slotShowScene(!disable);
532 connect(roto, SIGNAL(valueChanged()), this, SLOT(slotCollectAllParameters()));
533 connect(roto, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
534 connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
535 connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
536 connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
537 m_vbox->addWidget(roto);
538 m_valueItems[paramName] = roto;
540 } else if (type == "wipe") {
541 Wipeval *wpval = new Wipeval;
542 wpval->setupUi(toFillin);
543 wipeInfo w = getWipeInfo(value);
546 wpval->start_up->setChecked(true);
549 wpval->start_down->setChecked(true);
552 wpval->start_right->setChecked(true);
555 wpval->start_left->setChecked(true);
558 wpval->start_center->setChecked(true);
563 wpval->end_up->setChecked(true);
566 wpval->end_down->setChecked(true);
569 wpval->end_right->setChecked(true);
572 wpval->end_left->setChecked(true);
575 wpval->end_center->setChecked(true);
578 wpval->start_transp->setValue(w.startTransparency);
579 wpval->end_transp->setValue(w.endTransparency);
580 m_valueItems[paramName] = wpval;
581 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
582 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
583 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
584 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
585 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
586 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
587 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
588 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
589 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
590 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
591 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
592 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
593 //wpval->title->setTitle(na.toElement().text());
594 m_uiItems.append(wpval);
595 } else if (type == "url") {
596 Urlval *cval = new Urlval;
597 cval->setupUi(toFillin);
598 cval->label->setText(paramName);
599 cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
600 m_valueItems[paramName] = cval;
601 cval->urlwidget->setUrl(KUrl(value));
602 connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(slotCollectAllParameters()));
603 connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(slotCollectAllParameters()));
604 m_uiItems.append(cval);
611 m_vbox->addWidget(toFillin);
615 m_vbox->addStretch();
617 if (m_keyframeEditor)
618 m_keyframeEditor->checkVisibleParam();
620 // Make sure all doubleparam spinboxes have the same width, looks much better
621 QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
623 for (int i = 0; i < allWidgets.count(); i++) {
624 if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
626 for (int i = 0; i < allWidgets.count(); i++) {
627 allWidgets.at(i)->setSpinSize(minSize);
631 ParameterContainer::~ParameterContainer()
635 kDebug()<<"// DELETING PARAM CONT: "<<m_effect.attribute("id");
638 void ParameterContainer::meetDependency(const QString& name, QString type, QString value)
640 if (type == "curve") {
641 KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
643 int color = value.toInt();
644 curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
646 } else if (type == "bezier_spline") {
647 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
649 widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10)));
654 wipeInfo ParameterContainer::getWipeInfo(QString value)
657 // Convert old geometry values that used a comma as separator
658 if (value.contains(',')) value.replace(',','/');
659 QString start = value.section(';', 0, 0);
660 QString end = value.section(';', 1, 1).section('=', 1, 1);
661 if (start.startsWith("-100%/0"))
663 else if (start.startsWith("100%/0"))
665 else if (start.startsWith("0%/100%"))
667 else if (start.startsWith("0%/-100%"))
672 if (start.count(':') == 2)
673 info.startTransparency = start.section(':', -1).toInt();
675 info.startTransparency = 100;
677 if (end.startsWith("-100%/0"))
679 else if (end.startsWith("100%/0"))
681 else if (end.startsWith("0%/100%"))
683 else if (end.startsWith("0%/-100%"))
688 if (end.count(':') == 2)
689 info.endTransparency = end.section(':', -1).toInt();
691 info.endTransparency = 100;
696 void ParameterContainer::updateTimecodeFormat()
698 if (m_keyframeEditor)
699 m_keyframeEditor->updateTimecodeFormat();
701 QDomNodeList namenode = m_effect.elementsByTagName("parameter");
702 for (int i = 0; i < namenode.count() ; i++) {
703 QDomNode pa = namenode.item(i);
704 QDomElement na = pa.firstChildElement("name");
705 QString type = pa.attributes().namedItem("type").nodeValue();
706 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
708 if (type == "geometry") {
709 if (KdenliveSettings::on_monitor_effects()) {
710 if (m_geometryWidget) m_geometryWidget->updateTimecodeFormat();
712 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
713 geom->updateTimecodeFormat();
716 } else if (type == "position") {
717 PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
718 posi->updateTimecodeFormat();
721 } else if (type == "roto-spline") {
722 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems[paramName]);
723 widget->updateTimecodeFormat();
729 void ParameterContainer::slotCollectAllParameters()
731 if (m_valueItems.isEmpty() || m_effect.isNull()) return;
733 locale.setNumberOptions(QLocale::OmitGroupSeparator);
734 const QDomElement oldparam = m_effect.cloneNode().toElement();
735 QDomElement newparam = oldparam.cloneNode().toElement();
736 QDomNodeList namenode = newparam.elementsByTagName("parameter");
738 for (int i = 0; i < namenode.count() ; i++) {
739 QDomNode pa = namenode.item(i);
740 QDomElement na = pa.firstChildElement("name");
741 QString type = pa.attributes().namedItem("type").nodeValue();
742 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
743 if (type == "complex")
744 paramName.append("complex");
745 else if (type == "position")
746 paramName.append("position");
747 else if (type == "geometry")
748 paramName.append("geometry");
749 else if (type == "keyframe")
750 paramName.append("keyframe");
751 if (type != "simplekeyframe" && type != "fixed" && type != "addedgeometry" && !m_valueItems.contains(paramName)) {
752 kDebug() << "// Param: " << paramName << " NOT FOUND";
757 if (type == "double" || type == "constant") {
758 DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
759 setValue = locale.toString(doubleparam->getValue());
760 } else if (type == "list") {
761 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
762 setValue = box->itemData(box->currentIndex()).toString();
763 } else if (type == "bool") {
764 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
765 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
766 } else if (type == "color") {
767 ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
768 setValue = choosecolor->getColor();
769 } else if (type == "complex") {
770 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
771 namenode.item(i) = complex->getParamDesc();
772 } else if (type == "geometry") {
773 if (KdenliveSettings::on_monitor_effects()) {
774 if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getValue());
776 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
777 namenode.item(i).toElement().setAttribute("value", geom->getValue());
779 } else if (type == "addedgeometry") {
780 namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getExtraValue(namenode.item(i).toElement().attribute("name")));
781 } else if (type == "position") {
782 PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
783 int pos = pedit->getPosition();
784 setValue = QString::number(pos);
785 if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_black") {
786 // Make sure duration is not longer than clip
789 pedit->setPosition(pos);
791 EffectsList::setParameter(newparam, "in", QString::number(m_in));
792 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
794 } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
795 // Make sure duration is not longer than clip
798 pedit->setPosition(pos);
800 EffectsList::setParameter(newparam, "in", QString::number(m_out - pos));
801 EffectsList::setParameter(newparam, "out", QString::number(m_out));
804 } else if (type == "curve") {
805 KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
806 QList<QPointF> points = curve->curve().points();
807 QString number = pa.attributes().namedItem("number").nodeValue();
808 QString inName = pa.attributes().namedItem("inpoints").nodeValue();
809 QString outName = pa.attributes().namedItem("outpoints").nodeValue();
810 int off = pa.attributes().namedItem("min").nodeValue().toInt();
811 int end = pa.attributes().namedItem("max").nodeValue().toInt();
812 EffectsList::setParameter(newparam, number, QString::number(points.count()));
813 for (int j = 0; (j < points.count() && j + off <= end); j++) {
815 in.replace("%i", QString::number(j + off));
816 QString out = outName;
817 out.replace("%i", QString::number(j + off));
818 EffectsList::setParameter(newparam, in, locale.toString(points.at(j).x()));
819 EffectsList::setParameter(newparam, out, locale.toString(points.at(j).y()));
821 QString depends = pa.attributes().namedItem("depends").nodeValue();
822 if (!depends.isEmpty())
823 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
824 } else if (type == "bezier_spline") {
825 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
826 setValue = widget->spline();
827 QString depends = pa.attributes().namedItem("depends").nodeValue();
828 if (!depends.isEmpty())
829 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
831 } else if (type == "roto-spline") {
832 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
833 setValue = widget->getSpline();
835 } else if (type == "wipe") {
836 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
838 if (wp->start_left->isChecked())
840 else if (wp->start_right->isChecked())
842 else if (wp->start_up->isChecked())
844 else if (wp->start_down->isChecked())
846 else if (wp->start_center->isChecked())
850 info.startTransparency = wp->start_transp->value();
852 if (wp->end_left->isChecked())
854 else if (wp->end_right->isChecked())
856 else if (wp->end_up->isChecked())
858 else if (wp->end_down->isChecked())
860 else if (wp->end_center->isChecked())
864 info.endTransparency = wp->end_transp->value();
866 setValue = getWipeString(info);
867 } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
868 QDomElement elem = pa.toElement();
869 QString realName = i18n(na.toElement().text().toUtf8().data());
870 QString val = m_keyframeEditor->getValue(realName);
871 elem.setAttribute("keyframes", val);
873 if (m_keyframeEditor->isVisibleParam(realName))
874 elem.setAttribute("intimeline", "1");
875 else if (elem.hasAttribute("intimeline"))
876 elem.removeAttribute("intimeline");
877 } else if (type == "url") {
878 KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
879 setValue = req->url().path();
882 if (!setValue.isNull())
883 pa.attributes().namedItem("value").setNodeValue(setValue);
886 emit parameterChanged(oldparam, newparam, m_index);
889 QString ParameterContainer::getWipeString(wipeInfo info)
894 switch (info.start) {
896 start = "-100%/0%:100%x100%";
899 start = "100%/0%:100%x100%";
902 start = "0%/100%:100%x100%";
905 start = "0%/-100%:100%x100%";
908 start = "0%/0%:100%x100%";
911 start.append(':' + QString::number(info.startTransparency));
915 end = "-100%/0%:100%x100%";
918 end = "100%/0%:100%x100%";
921 end = "0%/100%:100%x100%";
924 end = "0%/-100%:100%x100%";
927 end = "0%/0%:100%x100%";
930 end.append(':' + QString::number(info.endTransparency));
931 return QString(start + ";-1=" + end);
934 int ParameterContainer::index()