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 "ui_keywordval_ui.h"
28 #include "ui_fontval_ui.h"
29 #include "complexparameter.h"
30 #include "geometryval.h"
31 #include "positionedit.h"
32 #include "projectlist.h"
33 #include "effectslist.h"
34 #include "kdenlivesettings.h"
35 #include "profilesdialog.h"
36 #include "kis_curve_widget.h"
37 #include "kis_cubic_curve.h"
38 #include "choosecolorwidget.h"
39 #include "geometrywidget.h"
40 #include "colortools.h"
41 #include "doubleparameterwidget.h"
42 #include "cornerswidget.h"
43 #include "dragvalue.h"
44 #include "beziercurve/beziersplinewidget.h"
46 #include "rotoscoping/rotowidget.h"
51 #include <QVBoxLayout>
53 #include <KGlobalSettings>
55 #include <KFileDialog>
56 #include <KUrlRequester>
58 class Boolval: public QWidget, public Ui::Boolval_UI
62 class Listval: public QWidget, public Ui::Listval_UI
66 class Wipeval: public QWidget, public Ui::Wipeval_UI
70 class Urlval: public QWidget, public Ui::Urlval_UI
74 class Keywordval: public QWidget, public Ui::Keywordval_UI
78 class Fontval: public QWidget, public Ui::Fontval_UI
82 QMap<QString, QImage> CollapsibleEffect::iconCache;
84 void clearLayout(QLayout *layout)
87 while((item = layout->takeAt(0))) {
89 clearLayout(item->layout());
90 delete item->layout();
93 delete item->widget();
99 MySpinBox::MySpinBox(QWidget * parent):
102 setFocusPolicy(Qt::StrongFocus);
105 void MySpinBox::focusInEvent(QFocusEvent*)
107 setFocusPolicy(Qt::WheelFocus);
110 void MySpinBox::focusOutEvent(QFocusEvent*)
112 setFocusPolicy(Qt::StrongFocus);
115 CollapsibleEffect::CollapsibleEffect(QDomElement effect, QDomElement original_effect, ItemInfo info, int ix, EffectMetaInfo *metaInfo, bool lastEffect, QWidget * parent) :
119 m_original_effect(original_effect),
120 m_lastEffect(lastEffect),
123 //setMouseTracking(true);
125 frame->setBackgroundRole(QPalette::Midlight);
126 frame->setAutoFillBackground(true);
127 setFont(KGlobalSettings::smallestReadableFont());
128 QDomElement namenode = m_effect.firstChildElement("name");
129 if (namenode.isNull()) return;
130 QString type = m_effect.attribute("type", QString());
132 if (type == "audio") icon = KIcon("kdenlive-show-audio");
133 else if (m_effect.attribute("tag") == "region") icon = KIcon("kdenlive-mask-effect");
134 else if (type == "custom") icon = KIcon("kdenlive-custom-effect");
135 else icon = KIcon("kdenlive-show-video");
137 buttonUp->setIcon(KIcon("go-up"));
138 buttonUp->setToolTip(i18n("Move effect up"));
140 buttonDown->setIcon(KIcon("go-down"));
141 buttonDown->setToolTip(i18n("Move effect down"));
143 buttonDel->setIcon(KIcon("edit-delete"));
144 buttonDel->setToolTip(i18n("Delete effect"));
145 buttonSave->setIcon(KIcon("document-save"));
146 buttonSave->setToolTip(i18n("Save effect"));
148 buttonUp->setVisible(false);
149 buttonDown->setVisible(false);
150 buttonSave->setVisible(false);
151 buttonDel->setVisible(false);
153 /*buttonReset->setIcon(KIcon("view-refresh"));
154 buttonReset->setToolTip(i18n("Reset effect"));*/
155 //checkAll->setToolTip(i18n("Enable/Disable all effects"));
156 //buttonShowComments->setIcon(KIcon("help-about"));
157 //buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
159 title->setText(i18n(namenode.text().toUtf8().data()));
160 effectIcon->setPixmap(icon.pixmap(QSize(16,16)));
162 //QLabel *lab = new QLabel("HEllo", widgetFrame);
163 //m_vbox->addWidget(lab);
164 if (m_effect.attribute("disable") == "1") {
165 enabledBox->setCheckState(Qt::Unchecked);
166 title->setEnabled(false);
169 enabledBox->setCheckState(Qt::Checked);
172 connect(collapseButton, SIGNAL(clicked()), this, SLOT(slotSwitch()));
173 connect(enabledBox, SIGNAL(toggled(bool)), this, SLOT(slotEnable(bool)));
174 connect(buttonUp, SIGNAL(clicked()), this, SLOT(slotEffectUp()));
175 connect(buttonDown, SIGNAL(clicked()), this, SLOT(slotEffectDown()));
176 connect(buttonDel, SIGNAL(clicked()), this, SLOT(slotDeleteEffect()));
177 setupWidget(info, ix, metaInfo);
178 Q_FOREACH( QSpinBox * sp, findChildren<QSpinBox*>() ) {
179 sp->installEventFilter( this );
180 sp->setFocusPolicy( Qt::StrongFocus );
182 Q_FOREACH( KComboBox * cb, findChildren<KComboBox*>() ) {
183 cb->installEventFilter( this );
184 cb->setFocusPolicy( Qt::StrongFocus );
186 Q_FOREACH( QProgressBar * cb, findChildren<QProgressBar*>() ) {
187 cb->installEventFilter( this );
188 cb->setFocusPolicy( Qt::StrongFocus );
193 CollapsibleEffect::~CollapsibleEffect()
195 if (m_paramWidget) delete m_paramWidget;
198 bool CollapsibleEffect::eventFilter( QObject * o, QEvent * e )
200 if(e->type() == QEvent::Wheel) {
201 if (qobject_cast<QAbstractSpinBox*>(o)) {
202 if(qobject_cast<QAbstractSpinBox*>(o)->focusPolicy() == Qt::WheelFocus)
213 if (qobject_cast<KComboBox*>(o)) {
214 if(qobject_cast<KComboBox*>(o)->focusPolicy() == Qt::WheelFocus)
225 if (qobject_cast<QProgressBar*>(o)) {
226 if(qobject_cast<QProgressBar*>(o)->focusPolicy() == Qt::WheelFocus)
238 return QWidget::eventFilter(o, e);
242 void CollapsibleEffect::setActive(bool activate)
245 frame->setBackgroundRole(m_active ? QPalette::Mid : QPalette::Midlight);
246 frame->setAutoFillBackground(activate);
249 void CollapsibleEffect::mouseDoubleClickEvent ( QMouseEvent * event )
251 if (frame->underMouse() && collapseButton->isEnabled()) slotSwitch();
252 QWidget::mouseDoubleClickEvent(event);
255 void CollapsibleEffect::mousePressEvent ( QMouseEvent *event )
257 if (!m_active) emit activateEffect(m_paramWidget->index());
258 QWidget::mousePressEvent(event);
261 void CollapsibleEffect::enterEvent ( QEvent * event )
263 if (m_paramWidget->index() > 0) buttonUp->setVisible(true);
264 if (!m_lastEffect) buttonDown->setVisible(true);
265 buttonSave->setVisible(true);
266 buttonDel->setVisible(true);
267 if (!m_active) frame->setBackgroundRole(QPalette::Midlight);
268 frame->setAutoFillBackground(true);
269 QWidget::enterEvent(event);
272 void CollapsibleEffect::leaveEvent ( QEvent * event )
274 buttonUp->setVisible(false);
275 buttonDown->setVisible(false);
276 buttonSave->setVisible(false);
277 buttonDel->setVisible(false);
278 if (!m_active) frame->setAutoFillBackground(false);
279 QWidget::leaveEvent(event);
282 void CollapsibleEffect::slotEnable(bool enable)
284 title->setEnabled(enable);
285 m_effect.setAttribute("disable", enable ? 0 : 1);
286 if (enable || KdenliveSettings::disable_effect_parameters()) {
287 widgetFrame->setEnabled(enable);
289 emit effectStateChanged(!enable, m_paramWidget->index());
292 void CollapsibleEffect::slotDeleteEffect()
294 emit deleteEffect(m_effect, m_paramWidget->index());
297 void CollapsibleEffect::slotEffectUp()
299 emit changeEffectPosition(m_paramWidget->index(), true);
302 void CollapsibleEffect::slotEffectDown()
304 emit changeEffectPosition(m_paramWidget->index(), false);
307 void CollapsibleEffect::slotSwitch()
309 bool enable = !widgetFrame->isVisible();
313 void CollapsibleEffect::slotShow(bool show)
315 widgetFrame->setVisible(show);
317 collapseButton->setArrowType(Qt::DownArrow);
318 m_original_effect.removeAttribute("k_collapsed");
321 collapseButton->setArrowType(Qt::RightArrow);
322 m_original_effect.setAttribute("k_collapsed", 1);
327 void CollapsibleEffect::setupWidget(ItemInfo info, int index, EffectMetaInfo *metaInfo)
329 if (m_effect.isNull()) {
330 // kDebug() << "// EMPTY EFFECT STACK";
333 if (m_effect.attribute("tag") == "region") {
334 QVBoxLayout *vbox = new QVBoxLayout(widgetFrame);
335 vbox->setContentsMargins(0, 0, 0, 0);
337 QDomNodeList effects = m_effect.elementsByTagName("effect");
338 QDomNodeList origin_effects = m_original_effect.elementsByTagName("effect");
339 QWidget *container = new QWidget(widgetFrame);
340 vbox->addWidget(container);
341 m_paramWidget = new ParameterContainer(m_effect.toElement(), info, metaInfo, index, container);
342 for (int i = 0; i < effects.count(); i++) {
343 CollapsibleEffect *coll = new CollapsibleEffect(effects.at(i).toElement(), origin_effects.at(i).toElement(), info, i, metaInfo, container);
344 m_subParamWidgets.append(coll);
345 //container = new QWidget(widgetFrame);
346 vbox->addWidget(coll);
347 //p = new ParameterContainer(effects.at(i).toElement(), info, isEffect, container);
352 m_paramWidget = new ParameterContainer(m_effect, info, metaInfo, index, widgetFrame);
353 if (m_effect.firstChildElement("parameter").isNull()) {
354 // Effect has no parameter, don't allow expand
355 collapseButton->setEnabled(false);
356 widgetFrame->setVisible(false);
359 if (collapseButton->isEnabled()) slotShow(!m_effect.hasAttribute("k_collapsed"));
360 connect (m_paramWidget, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)));
362 connect(m_paramWidget, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)));
364 connect (this, SIGNAL(syncEffectsPos(int)), m_paramWidget, SIGNAL(syncEffectsPos(int)));
365 connect (this, SIGNAL(effectStateChanged(bool)), m_paramWidget, SIGNAL(effectStateChanged(bool)));
366 connect (m_paramWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
367 connect (m_paramWidget, SIGNAL(seekTimeline(int)), this, SIGNAL(seekTimeline(int)));
372 void CollapsibleEffect::updateTimecodeFormat()
374 m_paramWidget->updateTimecodeFormat();
375 if (!m_subParamWidgets.isEmpty()) {
377 for (int i = 0; i < m_subParamWidgets.count(); i++)
378 m_subParamWidgets.at(i)->updateTimecodeFormat();
382 void CollapsibleEffect::slotSyncEffectsPos(int pos)
384 emit syncEffectsPos(pos);
389 ParameterContainer::ParameterContainer(QDomElement effect, ItemInfo info, EffectMetaInfo *metaInfo, int index, QWidget * parent) :
391 m_keyframeEditor(NULL),
392 m_geometryWidget(NULL),
393 m_metaInfo(metaInfo),
396 m_in = info.cropStart.frames(KdenliveSettings::project_fps());
397 m_out = (info.cropStart + info.cropDuration).frames(KdenliveSettings::project_fps()) - 1;
399 QDomNodeList namenode = effect.childNodes(); //elementsByTagName("parameter");
401 QDomElement e = effect.toElement();
402 int minFrame = e.attribute("start").toInt();
403 int maxFrame = e.attribute("end").toInt();
404 // In transitions, maxFrame is in fact one frame after the end of transition
405 if (maxFrame > 0) maxFrame --;
407 bool disable = effect.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
408 parent->setEnabled(!disable);
411 m_vbox = new QVBoxLayout(parent);
412 m_vbox->setContentsMargins(0, 0, 0, 0);
413 m_vbox->setSpacing(2);
415 for (int i = 0; i < namenode.count() ; i++) {
416 QDomElement pa = namenode.item(i).toElement();
417 if (pa.tagName() != "parameter") continue;
418 QDomElement na = pa.firstChildElement("name");
419 QDomElement commentElem = pa.firstChildElement("comment");
420 QString type = pa.attribute("type");
421 QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
423 if (!commentElem.isNull())
424 comment = i18n(commentElem.text().toUtf8().data());
425 QWidget * toFillin = new QWidget(parent);
426 QString value = pa.attribute("value").isNull() ?
427 pa.attribute("default") : pa.attribute("value");
430 /** See effects/README for info on the different types */
432 if (type == "double" || type == "constant") {
435 if (pa.attribute("min").contains('%'))
436 min = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("min"), m_metaInfo->frameSize);
438 min = pa.attribute("min").toDouble();
439 if (pa.attribute("max").contains('%'))
440 max = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("max"), m_metaInfo->frameSize);
442 max = pa.attribute("max").toDouble();
444 DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, value.toDouble(), min, max,
445 pa.attribute("default").toDouble(), comment, -1, pa.attribute("suffix"), pa.attribute("decimals").toInt(), parent);
446 doubleparam->setFocusPolicy(Qt::StrongFocus);
447 m_vbox->addWidget(doubleparam);
448 m_valueItems[paramName] = doubleparam;
449 connect(doubleparam, SIGNAL(valueChanged(double)), this, SLOT(slotCollectAllParameters()));
450 connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
451 } else if (type == "list") {
452 Listval *lsval = new Listval;
453 lsval->setupUi(toFillin);
454 lsval->list->setFocusPolicy(Qt::StrongFocus);
455 QStringList listitems = pa.attribute("paramlist").split(';');
456 if (listitems.count() == 1) {
457 // probably custom effect created before change to ';' as separator
458 listitems = pa.attribute("paramlist").split(",");
460 QDomElement list = pa.firstChildElement("paramlistdisplay");
461 QStringList listitemsdisplay;
462 if (!list.isNull()) {
463 listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
465 listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
467 if (listitemsdisplay.count() != listitems.count())
468 listitemsdisplay = listitems;
469 lsval->list->setIconSize(QSize(30, 30));
470 for (int i = 0; i < listitems.count(); i++) {
471 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
472 QString entry = listitems.at(i);
473 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
474 if (!CollapsibleEffect::iconCache.contains(entry)) {
476 CollapsibleEffect::iconCache[entry] = pix.scaled(30, 30);
478 lsval->list->setItemIcon(i, QPixmap::fromImage(CollapsibleEffect::iconCache[entry]));
481 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
482 lsval->name->setText(paramName);
483 lsval->labelComment->setText(comment);
484 lsval->widgetComment->setHidden(true);
485 m_valueItems[paramName] = lsval;
486 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(slotCollectAllParameters()));
487 if (!comment.isEmpty())
488 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
489 m_uiItems.append(lsval);
490 } else if (type == "bool") {
491 Boolval *bval = new Boolval;
492 bval->setupUi(toFillin);
493 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
494 bval->name->setText(paramName);
495 bval->labelComment->setText(comment);
496 bval->widgetComment->setHidden(true);
497 m_valueItems[paramName] = bval;
498 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(slotCollectAllParameters()));
499 if (!comment.isEmpty())
500 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
501 m_uiItems.append(bval);
502 } else if (type == "complex") {
503 ComplexParameter *pl = new ComplexParameter;
504 pl->setupParam(effect, pa.attribute("name"), 0, 100);
505 m_vbox->addWidget(pl);
506 m_valueItems[paramName+"complex"] = pl;
507 connect(pl, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
508 } else if (type == "geometry") {
509 if (KdenliveSettings::on_monitor_effects()) {
510 m_geometryWidget = new GeometryWidget(m_metaInfo->monitor, m_metaInfo->timecode, 0, true, effect.hasAttribute("showrotation"), parent);
511 m_geometryWidget->setFrameSize(m_metaInfo->frameSize);
512 m_geometryWidget->slotShowScene(!disable);
513 // connect this before setupParam to make sure the monitor scene shows up at startup
514 connect(m_geometryWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
515 connect(m_geometryWidget, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
516 if (minFrame == maxFrame)
517 m_geometryWidget->setupParam(pa, m_in, m_out);
519 m_geometryWidget->setupParam(pa, minFrame, maxFrame);
520 m_vbox->addWidget(m_geometryWidget);
521 m_valueItems[paramName+"geometry"] = m_geometryWidget;
522 connect(m_geometryWidget, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
523 connect(this, SIGNAL(syncEffectsPos(int)), m_geometryWidget, SLOT(slotSyncPosition(int)));
524 connect(this, SIGNAL(effectStateChanged(bool)), m_geometryWidget, SLOT(slotShowScene(bool)));
526 Geometryval *geo = new Geometryval(m_metaInfo->profile, m_metaInfo->timecode, m_metaInfo->frameSize, 0);
527 if (minFrame == maxFrame)
528 geo->setupParam(pa, m_in, m_out);
530 geo->setupParam(pa, minFrame, maxFrame);
531 m_vbox->addWidget(geo);
532 m_valueItems[paramName+"geometry"] = geo;
533 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
534 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
535 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
537 } else if (type == "addedgeometry") {
538 // this is a parameter that should be linked to the geometry widget, for example rotation, shear, ...
539 if (m_geometryWidget) m_geometryWidget->addParameter(pa);
540 } else if (type == "keyframe" || type == "simplekeyframe") {
541 // keyframe editor widget
542 if (m_keyframeEditor == NULL) {
544 if (pa.attribute("widget") == "corners") {
545 // we want a corners-keyframe-widget
546 CornersWidget *corners = new CornersWidget(m_metaInfo->monitor, pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt(), parent);
547 corners->slotShowScene(!disable);
548 connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
549 connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
550 connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
551 geo = static_cast<KeyframeEdit *>(corners);
553 geo = new KeyframeEdit(pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt());
555 m_vbox->addWidget(geo);
556 m_valueItems[paramName+"keyframe"] = geo;
557 m_keyframeEditor = geo;
558 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
559 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
560 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
562 // we already have a keyframe editor, so just add another column for the new param
563 m_keyframeEditor->addParameter(pa);
565 } else if (type == "color") {
566 if (value.startsWith('#'))
567 value = value.replace('#', "0x");
568 ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, value, parent);
569 m_vbox->addWidget(choosecolor);
570 m_valueItems[paramName] = choosecolor;
571 connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
572 connect(choosecolor, SIGNAL(modified()) , this, SLOT(slotCollectAllParameters()));
573 } else if (type == "position") {
574 int pos = value.toInt();
575 if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
577 } else if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
578 // fadeout position starts from clip end
581 PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_metaInfo->timecode);
582 m_vbox->addWidget(posedit);
583 m_valueItems[paramName+"position"] = posedit;
584 connect(posedit, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
585 } else if (type == "curve") {
586 KisCurveWidget *curve = new KisCurveWidget(parent);
587 curve->setMaxPoints(pa.attribute("max").toInt());
588 QList<QPointF> points;
589 int number = EffectsList::parameter(e, pa.attribute("number")).toInt();
590 QString inName = pa.attribute("inpoints");
591 QString outName = pa.attribute("outpoints");
592 int start = pa.attribute("min").toInt();
593 for (int j = start; j <= number; j++) {
595 in.replace("%i", QString::number(j));
596 QString out = outName;
597 out.replace("%i", QString::number(j));
598 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
600 if (!points.isEmpty())
601 curve->setCurve(KisCubicCurve(points));
602 MySpinBox *spinin = new MySpinBox();
603 spinin->setRange(0, 1000);
604 MySpinBox *spinout = new MySpinBox();
605 spinout->setRange(0, 1000);
606 curve->setupInOutControls(spinin, spinout, 0, 1000);
607 m_vbox->addWidget(curve);
608 m_vbox->addWidget(spinin);
609 m_vbox->addWidget(spinout);
611 connect(curve, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
612 m_valueItems[paramName] = curve;
614 QString depends = pa.attribute("depends");
615 if (!depends.isEmpty())
616 meetDependency(paramName, type, EffectsList::parameter(e, depends));
617 } else if (type == "bezier_spline") {
618 BezierSplineWidget *widget = new BezierSplineWidget(value, parent);
620 m_vbox->addWidget(widget);
621 m_valueItems[paramName] = widget;
622 connect(widget, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
623 QString depends = pa.attribute("depends");
624 if (!depends.isEmpty())
625 meetDependency(paramName, type, EffectsList::parameter(e, depends));
627 } else if (type == "roto-spline") {
628 RotoWidget *roto = new RotoWidget(value, m_metaInfo->monitor, info, m_metaInfo->timecode, parent);
629 roto->slotShowScene(!disable);
630 connect(roto, SIGNAL(valueChanged()), this, SLOT(slotCollectAllParameters()));
631 connect(roto, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
632 connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
633 connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
634 connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
635 m_vbox->addWidget(roto);
636 m_valueItems[paramName] = roto;
638 } else if (type == "wipe") {
639 Wipeval *wpval = new Wipeval;
640 wpval->setupUi(toFillin);
641 wipeInfo w = getWipeInfo(value);
644 wpval->start_up->setChecked(true);
647 wpval->start_down->setChecked(true);
650 wpval->start_right->setChecked(true);
653 wpval->start_left->setChecked(true);
656 wpval->start_center->setChecked(true);
661 wpval->end_up->setChecked(true);
664 wpval->end_down->setChecked(true);
667 wpval->end_right->setChecked(true);
670 wpval->end_left->setChecked(true);
673 wpval->end_center->setChecked(true);
676 wpval->start_transp->setValue(w.startTransparency);
677 wpval->end_transp->setValue(w.endTransparency);
678 m_valueItems[paramName] = wpval;
679 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
680 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
681 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
682 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
683 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
684 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
685 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
686 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
687 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
688 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
689 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
690 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
691 //wpval->title->setTitle(na.toElement().text());
692 m_uiItems.append(wpval);
693 } else if (type == "url") {
694 Urlval *cval = new Urlval;
695 cval->setupUi(toFillin);
696 cval->label->setText(paramName);
697 cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
698 m_valueItems[paramName] = cval;
699 cval->urlwidget->setUrl(KUrl(value));
700 connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(slotCollectAllParameters()));
701 connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(slotCollectAllParameters()));
702 m_uiItems.append(cval);
703 } else if (type == "keywords") {
704 Keywordval* kval = new Keywordval;
705 kval->setupUi(toFillin);
706 kval->label->setText(paramName);
707 kval->lineeditwidget->setText(value);
708 QDomElement klistelem = pa.firstChildElement("keywords");
709 QDomElement kdisplaylistelem = pa.firstChildElement("keywordsdisplay");
710 QStringList keywordlist;
711 QStringList keyworddisplaylist;
712 if (!klistelem.isNull()) {
713 keywordlist = klistelem.text().split(';');
714 keyworddisplaylist = i18n(kdisplaylistelem.text().toUtf8().data()).split(';');
716 if (keyworddisplaylist.count() != keywordlist.count()) {
717 keyworddisplaylist = keywordlist;
719 for (int i = 0; i < keywordlist.count(); i++) {
720 kval->comboboxwidget->addItem(keyworddisplaylist.at(i), keywordlist.at(i));
722 // Add disabled user prompt at index 0
723 kval->comboboxwidget->insertItem(0, i18n("<select a keyword>"), "");
724 kval->comboboxwidget->model()->setData( kval->comboboxwidget->model()->index(0,0), QVariant(Qt::NoItemFlags), Qt::UserRole -1);
725 kval->comboboxwidget->setCurrentIndex(0);
726 m_valueItems[paramName] = kval;
727 connect(kval->lineeditwidget, SIGNAL(editingFinished()) , this, SLOT(collectAllParameters()));
728 connect(kval->comboboxwidget, SIGNAL(activated (const QString&)), this, SLOT(collectAllParameters()));
729 m_uiItems.append(kval);
730 } else if (type == "fontfamily") {
731 Fontval* fval = new Fontval;
732 fval->setupUi(toFillin);
733 fval->name->setText(paramName);
734 fval->fontfamilywidget->setCurrentFont(QFont(value));
735 m_valueItems[paramName] = fval;
736 connect(fval->fontfamilywidget, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(collectAllParameters())) ;
737 m_uiItems.append(fval);
738 } else if (type == "filterjob") {
739 QVBoxLayout *l= new QVBoxLayout(toFillin);
740 QPushButton *button = new QPushButton(paramName, toFillin);
741 l->addWidget(button);
742 m_valueItems[paramName] = button;
743 connect(button, SIGNAL(pressed()), this, SLOT(slotStartFilterJobAction()));
750 m_vbox->addWidget(toFillin);
754 m_vbox->addStretch();
756 if (m_keyframeEditor)
757 m_keyframeEditor->checkVisibleParam();
759 // Make sure all doubleparam spinboxes have the same width, looks much better
760 QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
762 for (int i = 0; i < allWidgets.count(); i++) {
763 if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
765 for (int i = 0; i < allWidgets.count(); i++) {
766 allWidgets.at(i)->setSpinSize(minSize);
770 ParameterContainer::~ParameterContainer()
776 void ParameterContainer::meetDependency(const QString& name, QString type, QString value)
778 if (type == "curve") {
779 KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
781 int color = value.toInt();
782 curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
784 } else if (type == "bezier_spline") {
785 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
787 widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10)));
792 wipeInfo ParameterContainer::getWipeInfo(QString value)
795 // Convert old geometry values that used a comma as separator
796 if (value.contains(',')) value.replace(',','/');
797 QString start = value.section(';', 0, 0);
798 QString end = value.section(';', 1, 1).section('=', 1, 1);
799 if (start.startsWith("-100%/0"))
801 else if (start.startsWith("100%/0"))
803 else if (start.startsWith("0%/100%"))
805 else if (start.startsWith("0%/-100%"))
810 if (start.count(':') == 2)
811 info.startTransparency = start.section(':', -1).toInt();
813 info.startTransparency = 100;
815 if (end.startsWith("-100%/0"))
817 else if (end.startsWith("100%/0"))
819 else if (end.startsWith("0%/100%"))
821 else if (end.startsWith("0%/-100%"))
826 if (end.count(':') == 2)
827 info.endTransparency = end.section(':', -1).toInt();
829 info.endTransparency = 100;
834 void ParameterContainer::updateTimecodeFormat()
836 if (m_keyframeEditor)
837 m_keyframeEditor->updateTimecodeFormat();
839 QDomNodeList namenode = m_effect.elementsByTagName("parameter");
840 for (int i = 0; i < namenode.count() ; i++) {
841 QDomNode pa = namenode.item(i);
842 QDomElement na = pa.firstChildElement("name");
843 QString type = pa.attributes().namedItem("type").nodeValue();
844 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
846 if (type == "geometry") {
847 if (KdenliveSettings::on_monitor_effects()) {
848 if (m_geometryWidget) m_geometryWidget->updateTimecodeFormat();
850 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
851 geom->updateTimecodeFormat();
854 } else if (type == "position") {
855 PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
856 posi->updateTimecodeFormat();
859 } else if (type == "roto-spline") {
860 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems[paramName]);
861 widget->updateTimecodeFormat();
867 void ParameterContainer::slotCollectAllParameters()
869 if (m_valueItems.isEmpty() || m_effect.isNull()) return;
871 locale.setNumberOptions(QLocale::OmitGroupSeparator);
872 const QDomElement oldparam = m_effect.cloneNode().toElement();
873 QDomElement newparam = oldparam.cloneNode().toElement();
874 QDomNodeList namenode = newparam.elementsByTagName("parameter");
876 for (int i = 0; i < namenode.count() ; i++) {
877 QDomNode pa = namenode.item(i);
878 QDomElement na = pa.firstChildElement("name");
879 QString type = pa.attributes().namedItem("type").nodeValue();
880 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
881 if (type == "complex")
882 paramName.append("complex");
883 else if (type == "position")
884 paramName.append("position");
885 else if (type == "geometry")
886 paramName.append("geometry");
887 else if (type == "keyframe")
888 paramName.append("keyframe");
889 if (type != "simplekeyframe" && type != "fixed" && type != "addedgeometry" && !m_valueItems.contains(paramName)) {
890 kDebug() << "// Param: " << paramName << " NOT FOUND";
895 if (type == "double" || type == "constant") {
896 DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
897 setValue = locale.toString(doubleparam->getValue());
898 } else if (type == "list") {
899 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
900 setValue = box->itemData(box->currentIndex()).toString();
901 } else if (type == "bool") {
902 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
903 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
904 } else if (type == "color") {
905 ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
906 setValue = choosecolor->getColor();
907 } else if (type == "complex") {
908 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
909 namenode.item(i) = complex->getParamDesc();
910 } else if (type == "geometry") {
911 if (KdenliveSettings::on_monitor_effects()) {
912 if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getValue());
914 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
915 namenode.item(i).toElement().setAttribute("value", geom->getValue());
917 } else if (type == "addedgeometry") {
918 namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getExtraValue(namenode.item(i).toElement().attribute("name")));
919 } else if (type == "position") {
920 PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
921 int pos = pedit->getPosition();
922 setValue = QString::number(pos);
923 if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_black") {
924 // Make sure duration is not longer than clip
927 pedit->setPosition(pos);
929 EffectsList::setParameter(newparam, "in", QString::number(m_in));
930 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
932 } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
933 // Make sure duration is not longer than clip
936 pedit->setPosition(pos);
938 EffectsList::setParameter(newparam, "in", QString::number(m_out - pos));
939 EffectsList::setParameter(newparam, "out", QString::number(m_out));
942 } else if (type == "curve") {
943 KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
944 QList<QPointF> points = curve->curve().points();
945 QString number = pa.attributes().namedItem("number").nodeValue();
946 QString inName = pa.attributes().namedItem("inpoints").nodeValue();
947 QString outName = pa.attributes().namedItem("outpoints").nodeValue();
948 int off = pa.attributes().namedItem("min").nodeValue().toInt();
949 int end = pa.attributes().namedItem("max").nodeValue().toInt();
950 EffectsList::setParameter(newparam, number, QString::number(points.count()));
951 for (int j = 0; (j < points.count() && j + off <= end); j++) {
953 in.replace("%i", QString::number(j + off));
954 QString out = outName;
955 out.replace("%i", QString::number(j + off));
956 EffectsList::setParameter(newparam, in, locale.toString(points.at(j).x()));
957 EffectsList::setParameter(newparam, out, locale.toString(points.at(j).y()));
959 QString depends = pa.attributes().namedItem("depends").nodeValue();
960 if (!depends.isEmpty())
961 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
962 } else if (type == "bezier_spline") {
963 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
964 setValue = widget->spline();
965 QString depends = pa.attributes().namedItem("depends").nodeValue();
966 if (!depends.isEmpty())
967 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
969 } else if (type == "roto-spline") {
970 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
971 setValue = widget->getSpline();
973 } else if (type == "wipe") {
974 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
976 if (wp->start_left->isChecked())
978 else if (wp->start_right->isChecked())
980 else if (wp->start_up->isChecked())
982 else if (wp->start_down->isChecked())
984 else if (wp->start_center->isChecked())
988 info.startTransparency = wp->start_transp->value();
990 if (wp->end_left->isChecked())
992 else if (wp->end_right->isChecked())
994 else if (wp->end_up->isChecked())
996 else if (wp->end_down->isChecked())
998 else if (wp->end_center->isChecked())
1002 info.endTransparency = wp->end_transp->value();
1004 setValue = getWipeString(info);
1005 } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
1006 QDomElement elem = pa.toElement();
1007 QString realName = i18n(na.toElement().text().toUtf8().data());
1008 QString val = m_keyframeEditor->getValue(realName);
1009 elem.setAttribute("keyframes", val);
1011 if (m_keyframeEditor->isVisibleParam(realName))
1012 elem.setAttribute("intimeline", "1");
1013 else if (elem.hasAttribute("intimeline"))
1014 elem.removeAttribute("intimeline");
1015 } else if (type == "url") {
1016 KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
1017 setValue = req->url().path();
1018 } else if (type == "keywords"){
1019 QLineEdit *line = ((Keywordval*)m_valueItems.value(paramName))->lineeditwidget;
1020 QComboBox *combo = ((Keywordval*)m_valueItems.value(paramName))->comboboxwidget;
1021 if(combo->currentIndex())
1023 QString comboval = combo->itemData(combo->currentIndex()).toString();
1024 line->insert(comboval);
1025 combo->setCurrentIndex(0);
1027 setValue = line->text();
1028 } else if (type == "fontfamily") {
1029 QFontComboBox* fontfamily = ((Fontval*)m_valueItems.value(paramName))->fontfamilywidget;
1030 setValue = fontfamily->currentFont().family();
1032 if (!setValue.isNull())
1033 pa.attributes().namedItem("value").setNodeValue(setValue);
1036 emit parameterChanged(oldparam, newparam, m_index);
1039 QString ParameterContainer::getWipeString(wipeInfo info)
1044 switch (info.start) {
1046 start = "-100%/0%:100%x100%";
1049 start = "100%/0%:100%x100%";
1052 start = "0%/100%:100%x100%";
1055 start = "0%/-100%:100%x100%";
1058 start = "0%/0%:100%x100%";
1061 start.append(':' + QString::number(info.startTransparency));
1065 end = "-100%/0%:100%x100%";
1068 end = "100%/0%:100%x100%";
1071 end = "0%/100%:100%x100%";
1074 end = "0%/-100%:100%x100%";
1077 end = "0%/0%:100%x100%";
1080 end.append(':' + QString::number(info.endTransparency));
1081 return QString(start + ";-1=" + end);
1084 int ParameterContainer::index()
1089 void ParameterContainer::slotStartFilterJobAction()
1091 QDomNodeList namenode = m_effect.elementsByTagName("parameter");
1092 for (int i = 0; i < namenode.count() ; i++) {
1093 QDomElement pa = namenode.item(i).toElement();
1094 QString type = pa.attribute("type");
1095 if (type == "filterjob") {
1096 emit startFilterJob(pa.attribute("filtertag"), pa.attribute("filterparams"), pa.attribute("finalfilter"), pa.attribute("consumer"), pa.attribute("consumerparams"), pa.attribute("wantedproperties"));
1097 kDebug()<<" - - -PROPS:\n"<<pa.attribute("filtertag")<<"-"<< pa.attribute("filterparams")<<"-"<< pa.attribute("consumer")<<"-"<< pa.attribute("consumerparams")<<"-"<< pa.attribute("wantedproperties");