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"
49 #include <QInputDialog>
52 #include <QVBoxLayout>
54 #include <KGlobalSettings>
56 #include <KMessageBox>
57 #include <KStandardDirs>
58 #include <KFileDialog>
59 #include <KUrlRequester>
61 class Boolval: public QWidget, public Ui::Boolval_UI
65 class Listval: public QWidget, public Ui::Listval_UI
69 class Wipeval: public QWidget, public Ui::Wipeval_UI
73 class Urlval: public QWidget, public Ui::Urlval_UI
77 class Keywordval: public QWidget, public Ui::Keywordval_UI
81 class Fontval: public QWidget, public Ui::Fontval_UI
85 QMap<QString, QImage> CollapsibleEffect::iconCache;
87 void clearLayout(QLayout *layout)
90 while((item = layout->takeAt(0))) {
92 clearLayout(item->layout());
93 delete item->layout();
96 delete item->widget();
102 MySpinBox::MySpinBox(QWidget * parent):
105 setFocusPolicy(Qt::StrongFocus);
108 void MySpinBox::focusInEvent(QFocusEvent*)
110 setFocusPolicy(Qt::WheelFocus);
113 void MySpinBox::focusOutEvent(QFocusEvent*)
115 setFocusPolicy(Qt::StrongFocus);
118 CollapsibleEffect::CollapsibleEffect(QDomElement effect, QDomElement original_effect, ItemInfo info, int ix, EffectMetaInfo *metaInfo, bool lastEffect, QWidget * parent) :
122 m_original_effect(original_effect),
123 m_lastEffect(lastEffect),
126 //setMouseTracking(true);
128 frame->setBackgroundRole(QPalette::Midlight);
129 frame->setAutoFillBackground(true);
130 setFont(KGlobalSettings::smallestReadableFont());
131 QDomElement namenode = m_effect.firstChildElement("name");
132 if (namenode.isNull()) return;
133 QString type = m_effect.attribute("type", QString());
135 if (type == "audio") icon = KIcon("kdenlive-show-audio");
136 else if (m_effect.attribute("tag") == "region") icon = KIcon("kdenlive-mask-effect");
137 else if (type == "custom") icon = KIcon("kdenlive-custom-effect");
138 else icon = KIcon("kdenlive-show-video");
140 buttonUp->setIcon(KIcon("go-up"));
141 buttonUp->setToolTip(i18n("Move effect up"));
143 buttonDown->setIcon(KIcon("go-down"));
144 buttonDown->setToolTip(i18n("Move effect down"));
146 buttonDel->setIcon(KIcon("edit-delete"));
147 buttonDel->setToolTip(i18n("Delete effect"));
149 buttonUp->setVisible(false);
150 buttonDown->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 title->setIcon(icon);
161 QMenu *menu = new QMenu;
162 menu->addAction(KIcon("view-refresh"), i18n("Reset effect"), this, SLOT(slotResetEffect()));
163 menu->addAction(KIcon("document-save"), i18n("Save effect"), this, SLOT(slotSaveEffect()));
164 title->setMenu(menu);
166 if (m_effect.attribute("disable") == "1") {
167 enabledBox->setCheckState(Qt::Unchecked);
168 title->setEnabled(false);
171 enabledBox->setCheckState(Qt::Checked);
174 connect(collapseButton, SIGNAL(clicked()), this, SLOT(slotSwitch()));
175 connect(enabledBox, SIGNAL(toggled(bool)), this, SLOT(slotEnable(bool)));
176 connect(buttonUp, SIGNAL(clicked()), this, SLOT(slotEffectUp()));
177 connect(buttonDown, SIGNAL(clicked()), this, SLOT(slotEffectDown()));
178 connect(buttonDel, SIGNAL(clicked()), this, SLOT(slotDeleteEffect()));
180 setupWidget(info, ix, metaInfo);
181 Q_FOREACH( QSpinBox * sp, findChildren<QSpinBox*>() ) {
182 sp->installEventFilter( this );
183 sp->setFocusPolicy( Qt::StrongFocus );
185 Q_FOREACH( KComboBox * cb, findChildren<KComboBox*>() ) {
186 cb->installEventFilter( this );
187 cb->setFocusPolicy( Qt::StrongFocus );
189 Q_FOREACH( QProgressBar * cb, findChildren<QProgressBar*>() ) {
190 cb->installEventFilter( this );
191 cb->setFocusPolicy( Qt::StrongFocus );
196 CollapsibleEffect::~CollapsibleEffect()
198 if (m_paramWidget) delete m_paramWidget;
201 bool CollapsibleEffect::eventFilter( QObject * o, QEvent * e )
203 if(e->type() == QEvent::Wheel) {
204 if (qobject_cast<QAbstractSpinBox*>(o)) {
205 if(qobject_cast<QAbstractSpinBox*>(o)->focusPolicy() == Qt::WheelFocus)
216 if (qobject_cast<KComboBox*>(o)) {
217 if(qobject_cast<KComboBox*>(o)->focusPolicy() == Qt::WheelFocus)
228 if (qobject_cast<QProgressBar*>(o)) {
229 if(qobject_cast<QProgressBar*>(o)->focusPolicy() == Qt::WheelFocus)
241 return QWidget::eventFilter(o, e);
245 void CollapsibleEffect::setActive(bool activate)
248 frame->setBackgroundRole(m_active ? QPalette::Mid : QPalette::Midlight);
249 frame->setAutoFillBackground(activate);
252 void CollapsibleEffect::mouseDoubleClickEvent ( QMouseEvent * event )
254 if (frame->underMouse() && collapseButton->isEnabled()) slotSwitch();
255 QWidget::mouseDoubleClickEvent(event);
258 void CollapsibleEffect::mousePressEvent ( QMouseEvent *event )
260 if (!m_active) emit activateEffect(m_paramWidget->index());
261 QWidget::mousePressEvent(event);
264 void CollapsibleEffect::enterEvent ( QEvent * event )
266 if (m_paramWidget->index() > 0) buttonUp->setVisible(true);
267 if (!m_lastEffect) buttonDown->setVisible(true);
268 buttonDel->setVisible(true);
269 if (!m_active) frame->setBackgroundRole(QPalette::Midlight);
270 frame->setAutoFillBackground(true);
271 QWidget::enterEvent(event);
274 void CollapsibleEffect::leaveEvent ( QEvent * event )
276 buttonUp->setVisible(false);
277 buttonDown->setVisible(false);
278 buttonDel->setVisible(false);
279 if (!m_active) frame->setAutoFillBackground(false);
280 QWidget::leaveEvent(event);
283 void CollapsibleEffect::slotEnable(bool enable)
285 title->setEnabled(enable);
286 m_effect.setAttribute("disable", enable ? 0 : 1);
287 if (enable || KdenliveSettings::disable_effect_parameters()) {
288 widgetFrame->setEnabled(enable);
290 emit effectStateChanged(!enable, m_paramWidget->index());
293 void CollapsibleEffect::slotDeleteEffect()
295 emit deleteEffect(m_effect, m_paramWidget->index());
298 void CollapsibleEffect::slotEffectUp()
300 emit changeEffectPosition(m_paramWidget->index(), true);
303 void CollapsibleEffect::slotEffectDown()
305 emit changeEffectPosition(m_paramWidget->index(), false);
308 void CollapsibleEffect::slotSaveEffect()
310 QString name = QInputDialog::getText(this, i18n("Save Effect"), i18n("Name for saved effect: "));
311 if (name.isEmpty()) return;
312 QString path = KStandardDirs::locateLocal("appdata", "effects/", true);
313 path = path + name + ".xml";
314 if (QFile::exists(path)) if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", path)) == KMessageBox::No) return;
317 QDomElement effect = m_effect.cloneNode().toElement();
318 doc.appendChild(doc.importNode(effect, true));
319 effect = doc.firstChild().toElement();
320 effect.removeAttribute("kdenlive_ix");
321 effect.setAttribute("id", name);
322 effect.setAttribute("type", "custom");
323 QDomElement effectname = effect.firstChildElement("name");
324 effect.removeChild(effectname);
325 effectname = doc.createElement("name");
326 QDomText nametext = doc.createTextNode(name);
327 effectname.appendChild(nametext);
328 effect.insertBefore(effectname, QDomNode());
329 QDomElement effectprops = effect.firstChildElement("properties");
330 effectprops.setAttribute("id", name);
331 effectprops.setAttribute("type", "custom");
334 if (file.open(QFile::WriteOnly | QFile::Truncate)) {
335 QTextStream out(&file);
336 out << doc.toString();
339 emit reloadEffects();
342 void CollapsibleEffect::slotResetEffect()
344 emit resetEffect(m_paramWidget->index());
347 void CollapsibleEffect::slotSwitch()
349 bool enable = !widgetFrame->isVisible();
353 void CollapsibleEffect::slotShow(bool show)
355 widgetFrame->setVisible(show);
357 collapseButton->setArrowType(Qt::DownArrow);
358 m_original_effect.removeAttribute("k_collapsed");
361 collapseButton->setArrowType(Qt::RightArrow);
362 m_original_effect.setAttribute("k_collapsed", 1);
366 void CollapsibleEffect::updateWidget(ItemInfo info, int index, QDomElement effect, EffectMetaInfo *metaInfo)
370 delete m_paramWidget;
371 m_paramWidget = NULL;
374 setupWidget(info, index, metaInfo);
377 void CollapsibleEffect::setupWidget(ItemInfo info, int index, EffectMetaInfo *metaInfo)
379 if (m_effect.isNull()) {
380 // kDebug() << "// EMPTY EFFECT STACK";
384 if (m_effect.attribute("tag") == "region") {
385 QVBoxLayout *vbox = new QVBoxLayout(widgetFrame);
386 vbox->setContentsMargins(0, 0, 0, 0);
388 QDomNodeList effects = m_effect.elementsByTagName("effect");
389 QDomNodeList origin_effects = m_original_effect.elementsByTagName("effect");
390 QWidget *container = new QWidget(widgetFrame);
391 vbox->addWidget(container);
392 m_paramWidget = new ParameterContainer(m_effect.toElement(), info, metaInfo, index, container);
393 for (int i = 0; i < effects.count(); i++) {
394 CollapsibleEffect *coll = new CollapsibleEffect(effects.at(i).toElement(), origin_effects.at(i).toElement(), info, i, metaInfo, container);
395 m_subParamWidgets.append(coll);
396 //container = new QWidget(widgetFrame);
397 vbox->addWidget(coll);
398 //p = new ParameterContainer(effects.at(i).toElement(), info, isEffect, container);
403 m_paramWidget = new ParameterContainer(m_effect, info, metaInfo, index, widgetFrame);
404 if (m_effect.firstChildElement("parameter").isNull()) {
405 // Effect has no parameter, don't allow expand
406 collapseButton->setEnabled(false);
407 widgetFrame->setVisible(false);
410 if (collapseButton->isEnabled()) slotShow(!m_effect.hasAttribute("k_collapsed"));
411 connect (m_paramWidget, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)));
413 connect(m_paramWidget, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)));
415 connect (this, SIGNAL(syncEffectsPos(int)), m_paramWidget, SIGNAL(syncEffectsPos(int)));
416 connect (this, SIGNAL(effectStateChanged(bool)), m_paramWidget, SIGNAL(effectStateChanged(bool)));
417 connect (m_paramWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
418 connect (m_paramWidget, SIGNAL(seekTimeline(int)), this, SIGNAL(seekTimeline(int)));
423 void CollapsibleEffect::updateTimecodeFormat()
425 m_paramWidget->updateTimecodeFormat();
426 if (!m_subParamWidgets.isEmpty()) {
428 for (int i = 0; i < m_subParamWidgets.count(); i++)
429 m_subParamWidgets.at(i)->updateTimecodeFormat();
433 void CollapsibleEffect::slotSyncEffectsPos(int pos)
435 emit syncEffectsPos(pos);
440 ParameterContainer::ParameterContainer(QDomElement effect, ItemInfo info, EffectMetaInfo *metaInfo, int index, QWidget * parent) :
442 m_keyframeEditor(NULL),
443 m_geometryWidget(NULL),
444 m_metaInfo(metaInfo),
447 m_in = info.cropStart.frames(KdenliveSettings::project_fps());
448 m_out = (info.cropStart + info.cropDuration).frames(KdenliveSettings::project_fps()) - 1;
450 QDomNodeList namenode = effect.childNodes(); //elementsByTagName("parameter");
452 QDomElement e = effect.toElement();
453 int minFrame = e.attribute("start").toInt();
454 int maxFrame = e.attribute("end").toInt();
455 // In transitions, maxFrame is in fact one frame after the end of transition
456 if (maxFrame > 0) maxFrame --;
458 bool disable = effect.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
459 parent->setEnabled(!disable);
462 m_vbox = new QVBoxLayout(parent);
463 m_vbox->setContentsMargins(0, 0, 0, 0);
464 m_vbox->setSpacing(2);
466 for (int i = 0; i < namenode.count() ; i++) {
467 QDomElement pa = namenode.item(i).toElement();
468 if (pa.tagName() != "parameter") continue;
469 QDomElement na = pa.firstChildElement("name");
470 QDomElement commentElem = pa.firstChildElement("comment");
471 QString type = pa.attribute("type");
472 QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
474 if (!commentElem.isNull())
475 comment = i18n(commentElem.text().toUtf8().data());
476 QWidget * toFillin = new QWidget(parent);
477 QString value = pa.attribute("value").isNull() ?
478 pa.attribute("default") : pa.attribute("value");
481 /** See effects/README for info on the different types */
483 if (type == "double" || type == "constant") {
486 if (pa.attribute("min").contains('%'))
487 min = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("min"), m_metaInfo->frameSize);
489 min = pa.attribute("min").toDouble();
490 if (pa.attribute("max").contains('%'))
491 max = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("max"), m_metaInfo->frameSize);
493 max = pa.attribute("max").toDouble();
495 DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, value.toDouble(), min, max,
496 pa.attribute("default").toDouble(), comment, -1, pa.attribute("suffix"), pa.attribute("decimals").toInt(), parent);
497 doubleparam->setFocusPolicy(Qt::StrongFocus);
498 m_vbox->addWidget(doubleparam);
499 m_valueItems[paramName] = doubleparam;
500 connect(doubleparam, SIGNAL(valueChanged(double)), this, SLOT(slotCollectAllParameters()));
501 connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
502 } else if (type == "list") {
503 Listval *lsval = new Listval;
504 lsval->setupUi(toFillin);
505 lsval->list->setFocusPolicy(Qt::StrongFocus);
506 QStringList listitems = pa.attribute("paramlist").split(';');
507 if (listitems.count() == 1) {
508 // probably custom effect created before change to ';' as separator
509 listitems = pa.attribute("paramlist").split(",");
511 QDomElement list = pa.firstChildElement("paramlistdisplay");
512 QStringList listitemsdisplay;
513 if (!list.isNull()) {
514 listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
516 listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
518 if (listitemsdisplay.count() != listitems.count())
519 listitemsdisplay = listitems;
520 lsval->list->setIconSize(QSize(30, 30));
521 for (int i = 0; i < listitems.count(); i++) {
522 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
523 QString entry = listitems.at(i);
524 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
525 if (!CollapsibleEffect::iconCache.contains(entry)) {
527 CollapsibleEffect::iconCache[entry] = pix.scaled(30, 30);
529 lsval->list->setItemIcon(i, QPixmap::fromImage(CollapsibleEffect::iconCache[entry]));
532 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
533 lsval->name->setText(paramName);
534 lsval->labelComment->setText(comment);
535 lsval->widgetComment->setHidden(true);
536 m_valueItems[paramName] = lsval;
537 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(slotCollectAllParameters()));
538 if (!comment.isEmpty())
539 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
540 m_uiItems.append(lsval);
541 } else if (type == "bool") {
542 Boolval *bval = new Boolval;
543 bval->setupUi(toFillin);
544 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
545 bval->name->setText(paramName);
546 bval->labelComment->setText(comment);
547 bval->widgetComment->setHidden(true);
548 m_valueItems[paramName] = bval;
549 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(slotCollectAllParameters()));
550 if (!comment.isEmpty())
551 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
552 m_uiItems.append(bval);
553 } else if (type == "complex") {
554 ComplexParameter *pl = new ComplexParameter;
555 pl->setupParam(effect, pa.attribute("name"), 0, 100);
556 m_vbox->addWidget(pl);
557 m_valueItems[paramName+"complex"] = pl;
558 connect(pl, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
559 } else if (type == "geometry") {
560 if (KdenliveSettings::on_monitor_effects()) {
561 m_geometryWidget = new GeometryWidget(m_metaInfo->monitor, m_metaInfo->timecode, 0, true, effect.hasAttribute("showrotation"), parent);
562 m_geometryWidget->setFrameSize(m_metaInfo->frameSize);
563 m_geometryWidget->slotShowScene(!disable);
564 // connect this before setupParam to make sure the monitor scene shows up at startup
565 connect(m_geometryWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
566 connect(m_geometryWidget, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
567 if (minFrame == maxFrame)
568 m_geometryWidget->setupParam(pa, m_in, m_out);
570 m_geometryWidget->setupParam(pa, minFrame, maxFrame);
571 m_vbox->addWidget(m_geometryWidget);
572 m_valueItems[paramName+"geometry"] = m_geometryWidget;
573 connect(m_geometryWidget, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
574 connect(this, SIGNAL(syncEffectsPos(int)), m_geometryWidget, SLOT(slotSyncPosition(int)));
575 connect(this, SIGNAL(effectStateChanged(bool)), m_geometryWidget, SLOT(slotShowScene(bool)));
577 Geometryval *geo = new Geometryval(m_metaInfo->profile, m_metaInfo->timecode, m_metaInfo->frameSize, 0);
578 if (minFrame == maxFrame)
579 geo->setupParam(pa, m_in, m_out);
581 geo->setupParam(pa, minFrame, maxFrame);
582 m_vbox->addWidget(geo);
583 m_valueItems[paramName+"geometry"] = geo;
584 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
585 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
586 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
588 } else if (type == "addedgeometry") {
589 // this is a parameter that should be linked to the geometry widget, for example rotation, shear, ...
590 if (m_geometryWidget) m_geometryWidget->addParameter(pa);
591 } else if (type == "keyframe" || type == "simplekeyframe") {
592 // keyframe editor widget
593 if (m_keyframeEditor == NULL) {
595 if (pa.attribute("widget") == "corners") {
596 // we want a corners-keyframe-widget
597 CornersWidget *corners = new CornersWidget(m_metaInfo->monitor, pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt(), parent);
598 corners->slotShowScene(!disable);
599 connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
600 connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
601 connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
602 geo = static_cast<KeyframeEdit *>(corners);
604 geo = new KeyframeEdit(pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt());
606 m_vbox->addWidget(geo);
607 m_valueItems[paramName+"keyframe"] = geo;
608 m_keyframeEditor = geo;
609 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
610 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
611 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
613 // we already have a keyframe editor, so just add another column for the new param
614 m_keyframeEditor->addParameter(pa);
616 } else if (type == "color") {
617 if (value.startsWith('#'))
618 value = value.replace('#', "0x");
619 ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, value, parent);
620 m_vbox->addWidget(choosecolor);
621 m_valueItems[paramName] = choosecolor;
622 connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
623 connect(choosecolor, SIGNAL(modified()) , this, SLOT(slotCollectAllParameters()));
624 } else if (type == "position") {
625 int pos = value.toInt();
626 if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
628 } else if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
629 // fadeout position starts from clip end
632 PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_metaInfo->timecode);
633 m_vbox->addWidget(posedit);
634 m_valueItems[paramName+"position"] = posedit;
635 connect(posedit, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
636 } else if (type == "curve") {
637 KisCurveWidget *curve = new KisCurveWidget(parent);
638 curve->setMaxPoints(pa.attribute("max").toInt());
639 QList<QPointF> points;
640 int number = EffectsList::parameter(e, pa.attribute("number")).toInt();
641 QString inName = pa.attribute("inpoints");
642 QString outName = pa.attribute("outpoints");
643 int start = pa.attribute("min").toInt();
644 for (int j = start; j <= number; j++) {
646 in.replace("%i", QString::number(j));
647 QString out = outName;
648 out.replace("%i", QString::number(j));
649 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
651 if (!points.isEmpty())
652 curve->setCurve(KisCubicCurve(points));
653 MySpinBox *spinin = new MySpinBox();
654 spinin->setRange(0, 1000);
655 MySpinBox *spinout = new MySpinBox();
656 spinout->setRange(0, 1000);
657 curve->setupInOutControls(spinin, spinout, 0, 1000);
658 m_vbox->addWidget(curve);
659 m_vbox->addWidget(spinin);
660 m_vbox->addWidget(spinout);
662 connect(curve, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
663 m_valueItems[paramName] = curve;
665 QString depends = pa.attribute("depends");
666 if (!depends.isEmpty())
667 meetDependency(paramName, type, EffectsList::parameter(e, depends));
668 } else if (type == "bezier_spline") {
669 BezierSplineWidget *widget = new BezierSplineWidget(value, parent);
671 m_vbox->addWidget(widget);
672 m_valueItems[paramName] = widget;
673 connect(widget, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
674 QString depends = pa.attribute("depends");
675 if (!depends.isEmpty())
676 meetDependency(paramName, type, EffectsList::parameter(e, depends));
678 } else if (type == "roto-spline") {
679 RotoWidget *roto = new RotoWidget(value, m_metaInfo->monitor, info, m_metaInfo->timecode, parent);
680 roto->slotShowScene(!disable);
681 connect(roto, SIGNAL(valueChanged()), this, SLOT(slotCollectAllParameters()));
682 connect(roto, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
683 connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
684 connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
685 connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
686 m_vbox->addWidget(roto);
687 m_valueItems[paramName] = roto;
689 } else if (type == "wipe") {
690 Wipeval *wpval = new Wipeval;
691 wpval->setupUi(toFillin);
692 wipeInfo w = getWipeInfo(value);
695 wpval->start_up->setChecked(true);
698 wpval->start_down->setChecked(true);
701 wpval->start_right->setChecked(true);
704 wpval->start_left->setChecked(true);
707 wpval->start_center->setChecked(true);
712 wpval->end_up->setChecked(true);
715 wpval->end_down->setChecked(true);
718 wpval->end_right->setChecked(true);
721 wpval->end_left->setChecked(true);
724 wpval->end_center->setChecked(true);
727 wpval->start_transp->setValue(w.startTransparency);
728 wpval->end_transp->setValue(w.endTransparency);
729 m_valueItems[paramName] = wpval;
730 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
731 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
732 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
733 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
734 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
735 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
736 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
737 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
738 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
739 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
740 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
741 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
742 //wpval->title->setTitle(na.toElement().text());
743 m_uiItems.append(wpval);
744 } else if (type == "url") {
745 Urlval *cval = new Urlval;
746 cval->setupUi(toFillin);
747 cval->label->setText(paramName);
748 cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
749 m_valueItems[paramName] = cval;
750 cval->urlwidget->setUrl(KUrl(value));
751 connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(slotCollectAllParameters()));
752 connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(slotCollectAllParameters()));
753 m_uiItems.append(cval);
754 } else if (type == "keywords") {
755 Keywordval* kval = new Keywordval;
756 kval->setupUi(toFillin);
757 kval->label->setText(paramName);
758 kval->lineeditwidget->setText(value);
759 QDomElement klistelem = pa.firstChildElement("keywords");
760 QDomElement kdisplaylistelem = pa.firstChildElement("keywordsdisplay");
761 QStringList keywordlist;
762 QStringList keyworddisplaylist;
763 if (!klistelem.isNull()) {
764 keywordlist = klistelem.text().split(';');
765 keyworddisplaylist = i18n(kdisplaylistelem.text().toUtf8().data()).split(';');
767 if (keyworddisplaylist.count() != keywordlist.count()) {
768 keyworddisplaylist = keywordlist;
770 for (int i = 0; i < keywordlist.count(); i++) {
771 kval->comboboxwidget->addItem(keyworddisplaylist.at(i), keywordlist.at(i));
773 // Add disabled user prompt at index 0
774 kval->comboboxwidget->insertItem(0, i18n("<select a keyword>"), "");
775 kval->comboboxwidget->model()->setData( kval->comboboxwidget->model()->index(0,0), QVariant(Qt::NoItemFlags), Qt::UserRole -1);
776 kval->comboboxwidget->setCurrentIndex(0);
777 m_valueItems[paramName] = kval;
778 connect(kval->lineeditwidget, SIGNAL(editingFinished()) , this, SLOT(collectAllParameters()));
779 connect(kval->comboboxwidget, SIGNAL(activated (const QString&)), this, SLOT(collectAllParameters()));
780 m_uiItems.append(kval);
781 } else if (type == "fontfamily") {
782 Fontval* fval = new Fontval;
783 fval->setupUi(toFillin);
784 fval->name->setText(paramName);
785 fval->fontfamilywidget->setCurrentFont(QFont(value));
786 m_valueItems[paramName] = fval;
787 connect(fval->fontfamilywidget, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(collectAllParameters())) ;
788 m_uiItems.append(fval);
789 } else if (type == "filterjob") {
790 QVBoxLayout *l= new QVBoxLayout(toFillin);
791 QPushButton *button = new QPushButton(paramName, toFillin);
792 l->addWidget(button);
793 m_valueItems[paramName] = button;
794 connect(button, SIGNAL(pressed()), this, SLOT(slotStartFilterJobAction()));
801 m_vbox->addWidget(toFillin);
805 m_vbox->addStretch();
807 if (m_keyframeEditor)
808 m_keyframeEditor->checkVisibleParam();
810 // Make sure all doubleparam spinboxes have the same width, looks much better
811 QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
813 for (int i = 0; i < allWidgets.count(); i++) {
814 if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
816 for (int i = 0; i < allWidgets.count(); i++) {
817 allWidgets.at(i)->setSpinSize(minSize);
821 ParameterContainer::~ParameterContainer()
827 void ParameterContainer::meetDependency(const QString& name, QString type, QString value)
829 if (type == "curve") {
830 KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
832 int color = value.toInt();
833 curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
835 } else if (type == "bezier_spline") {
836 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
838 widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10)));
843 wipeInfo ParameterContainer::getWipeInfo(QString value)
846 // Convert old geometry values that used a comma as separator
847 if (value.contains(',')) value.replace(',','/');
848 QString start = value.section(';', 0, 0);
849 QString end = value.section(';', 1, 1).section('=', 1, 1);
850 if (start.startsWith("-100%/0"))
852 else if (start.startsWith("100%/0"))
854 else if (start.startsWith("0%/100%"))
856 else if (start.startsWith("0%/-100%"))
861 if (start.count(':') == 2)
862 info.startTransparency = start.section(':', -1).toInt();
864 info.startTransparency = 100;
866 if (end.startsWith("-100%/0"))
868 else if (end.startsWith("100%/0"))
870 else if (end.startsWith("0%/100%"))
872 else if (end.startsWith("0%/-100%"))
877 if (end.count(':') == 2)
878 info.endTransparency = end.section(':', -1).toInt();
880 info.endTransparency = 100;
885 void ParameterContainer::updateTimecodeFormat()
887 if (m_keyframeEditor)
888 m_keyframeEditor->updateTimecodeFormat();
890 QDomNodeList namenode = m_effect.elementsByTagName("parameter");
891 for (int i = 0; i < namenode.count() ; i++) {
892 QDomNode pa = namenode.item(i);
893 QDomElement na = pa.firstChildElement("name");
894 QString type = pa.attributes().namedItem("type").nodeValue();
895 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
897 if (type == "geometry") {
898 if (KdenliveSettings::on_monitor_effects()) {
899 if (m_geometryWidget) m_geometryWidget->updateTimecodeFormat();
901 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
902 geom->updateTimecodeFormat();
905 } else if (type == "position") {
906 PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
907 posi->updateTimecodeFormat();
910 } else if (type == "roto-spline") {
911 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems[paramName]);
912 widget->updateTimecodeFormat();
918 void ParameterContainer::slotCollectAllParameters()
920 if (m_valueItems.isEmpty() || m_effect.isNull()) return;
922 locale.setNumberOptions(QLocale::OmitGroupSeparator);
923 const QDomElement oldparam = m_effect.cloneNode().toElement();
924 //QDomElement newparam = oldparam.cloneNode().toElement();
925 QDomNodeList namenode = m_effect.elementsByTagName("parameter");
927 for (int i = 0; i < namenode.count() ; i++) {
928 QDomNode pa = namenode.item(i);
929 QDomElement na = pa.firstChildElement("name");
930 QString type = pa.attributes().namedItem("type").nodeValue();
931 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
932 if (type == "complex")
933 paramName.append("complex");
934 else if (type == "position")
935 paramName.append("position");
936 else if (type == "geometry")
937 paramName.append("geometry");
938 else if (type == "keyframe")
939 paramName.append("keyframe");
940 if (type != "simplekeyframe" && type != "fixed" && type != "addedgeometry" && !m_valueItems.contains(paramName)) {
941 kDebug() << "// Param: " << paramName << " NOT FOUND";
946 if (type == "double" || type == "constant") {
947 DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
948 setValue = locale.toString(doubleparam->getValue());
949 } else if (type == "list") {
950 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
951 setValue = box->itemData(box->currentIndex()).toString();
952 } else if (type == "bool") {
953 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
954 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
955 } else if (type == "color") {
956 ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
957 setValue = choosecolor->getColor();
958 } else if (type == "complex") {
959 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
960 namenode.item(i) = complex->getParamDesc();
961 } else if (type == "geometry") {
962 if (KdenliveSettings::on_monitor_effects()) {
963 if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getValue());
965 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
966 namenode.item(i).toElement().setAttribute("value", geom->getValue());
968 } else if (type == "addedgeometry") {
969 namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getExtraValue(namenode.item(i).toElement().attribute("name")));
970 } else if (type == "position") {
971 PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
972 int pos = pedit->getPosition();
973 setValue = QString::number(pos);
974 if (m_effect.attribute("id") == "fadein" || m_effect.attribute("id") == "fade_from_black") {
975 // Make sure duration is not longer than clip
978 pedit->setPosition(pos);
980 EffectsList::setParameter(m_effect, "in", QString::number(m_in));
981 EffectsList::setParameter(m_effect, "out", QString::number(m_in + pos));
983 } else if (m_effect.attribute("id") == "fadeout" || m_effect.attribute("id") == "fade_to_black") {
984 // Make sure duration is not longer than clip
987 pedit->setPosition(pos);
989 EffectsList::setParameter(m_effect, "in", QString::number(m_out - pos));
990 EffectsList::setParameter(m_effect, "out", QString::number(m_out));
993 } else if (type == "curve") {
994 KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
995 QList<QPointF> points = curve->curve().points();
996 QString number = pa.attributes().namedItem("number").nodeValue();
997 QString inName = pa.attributes().namedItem("inpoints").nodeValue();
998 QString outName = pa.attributes().namedItem("outpoints").nodeValue();
999 int off = pa.attributes().namedItem("min").nodeValue().toInt();
1000 int end = pa.attributes().namedItem("max").nodeValue().toInt();
1001 EffectsList::setParameter(m_effect, number, QString::number(points.count()));
1002 for (int j = 0; (j < points.count() && j + off <= end); j++) {
1003 QString in = inName;
1004 in.replace("%i", QString::number(j + off));
1005 QString out = outName;
1006 out.replace("%i", QString::number(j + off));
1007 EffectsList::setParameter(m_effect, in, locale.toString(points.at(j).x()));
1008 EffectsList::setParameter(m_effect, out, locale.toString(points.at(j).y()));
1010 QString depends = pa.attributes().namedItem("depends").nodeValue();
1011 if (!depends.isEmpty())
1012 meetDependency(paramName, type, EffectsList::parameter(m_effect, depends));
1013 } else if (type == "bezier_spline") {
1014 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
1015 setValue = widget->spline();
1016 QString depends = pa.attributes().namedItem("depends").nodeValue();
1017 if (!depends.isEmpty())
1018 meetDependency(paramName, type, EffectsList::parameter(m_effect, depends));
1020 } else if (type == "roto-spline") {
1021 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
1022 setValue = widget->getSpline();
1024 } else if (type == "wipe") {
1025 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
1027 if (wp->start_left->isChecked())
1029 else if (wp->start_right->isChecked())
1031 else if (wp->start_up->isChecked())
1033 else if (wp->start_down->isChecked())
1035 else if (wp->start_center->isChecked())
1036 info.start = CENTER;
1039 info.startTransparency = wp->start_transp->value();
1041 if (wp->end_left->isChecked())
1043 else if (wp->end_right->isChecked())
1045 else if (wp->end_up->isChecked())
1047 else if (wp->end_down->isChecked())
1049 else if (wp->end_center->isChecked())
1053 info.endTransparency = wp->end_transp->value();
1055 setValue = getWipeString(info);
1056 } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
1057 QDomElement elem = pa.toElement();
1058 QString realName = i18n(na.toElement().text().toUtf8().data());
1059 QString val = m_keyframeEditor->getValue(realName);
1060 elem.setAttribute("keyframes", val);
1062 if (m_keyframeEditor->isVisibleParam(realName))
1063 elem.setAttribute("intimeline", "1");
1064 else if (elem.hasAttribute("intimeline"))
1065 elem.removeAttribute("intimeline");
1066 } else if (type == "url") {
1067 KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
1068 setValue = req->url().path();
1069 } else if (type == "keywords"){
1070 QLineEdit *line = ((Keywordval*)m_valueItems.value(paramName))->lineeditwidget;
1071 QComboBox *combo = ((Keywordval*)m_valueItems.value(paramName))->comboboxwidget;
1072 if(combo->currentIndex())
1074 QString comboval = combo->itemData(combo->currentIndex()).toString();
1075 line->insert(comboval);
1076 combo->setCurrentIndex(0);
1078 setValue = line->text();
1079 } else if (type == "fontfamily") {
1080 QFontComboBox* fontfamily = ((Fontval*)m_valueItems.value(paramName))->fontfamilywidget;
1081 setValue = fontfamily->currentFont().family();
1083 if (!setValue.isNull())
1084 pa.attributes().namedItem("value").setNodeValue(setValue);
1087 emit parameterChanged(oldparam, m_effect, m_index);
1090 QString ParameterContainer::getWipeString(wipeInfo info)
1095 switch (info.start) {
1097 start = "-100%/0%:100%x100%";
1100 start = "100%/0%:100%x100%";
1103 start = "0%/100%:100%x100%";
1106 start = "0%/-100%:100%x100%";
1109 start = "0%/0%:100%x100%";
1112 start.append(':' + QString::number(info.startTransparency));
1116 end = "-100%/0%:100%x100%";
1119 end = "100%/0%:100%x100%";
1122 end = "0%/100%:100%x100%";
1125 end = "0%/-100%:100%x100%";
1128 end = "0%/0%:100%x100%";
1131 end.append(':' + QString::number(info.endTransparency));
1132 return QString(start + ";-1=" + end);
1135 int ParameterContainer::index()
1140 void ParameterContainer::slotStartFilterJobAction()
1142 QDomNodeList namenode = m_effect.elementsByTagName("parameter");
1143 for (int i = 0; i < namenode.count() ; i++) {
1144 QDomElement pa = namenode.item(i).toElement();
1145 QString type = pa.attribute("type");
1146 if (type == "filterjob") {
1147 emit startFilterJob(pa.attribute("filtertag"), pa.attribute("filterparams"), pa.attribute("finalfilter"), pa.attribute("consumer"), pa.attribute("consumerparams"), pa.attribute("wantedproperties"));
1148 kDebug()<<" - - -PROPS:\n"<<pa.attribute("filtertag")<<"-"<< pa.attribute("filterparams")<<"-"<< pa.attribute("consumer")<<"-"<< pa.attribute("consumerparams")<<"-"<< pa.attribute("wantedproperties");