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);
119 CollapsibleEffect::CollapsibleEffect(QDomElement effect, QDomElement original_effect, ItemInfo info, int ix, EffectMetaInfo *metaInfo, bool lastEffect, QWidget * parent) :
123 m_original_effect(original_effect),
124 m_lastEffect(lastEffect),
127 //setMouseTracking(true);
129 frame->setBackgroundRole(QPalette::Midlight);
130 frame->setAutoFillBackground(true);
131 setFont(KGlobalSettings::smallestReadableFont());
133 buttonUp->setIcon(KIcon("go-up"));
134 buttonUp->setToolTip(i18n("Move effect up"));
136 buttonDown->setIcon(KIcon("go-down"));
137 buttonDown->setToolTip(i18n("Move effect down"));
139 buttonDel->setIcon(KIcon("edit-delete"));
140 buttonDel->setToolTip(i18n("Delete effect"));
142 buttonUp->setVisible(false);
143 buttonDown->setVisible(false);
144 buttonDel->setVisible(false);
146 /*buttonReset->setIcon(KIcon("view-refresh"));
147 buttonReset->setToolTip(i18n("Reset effect"));*/
148 //checkAll->setToolTip(i18n("Enable/Disable all effects"));
149 //buttonShowComments->setIcon(KIcon("help-about"));
150 //buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
151 QDomElement namenode = m_effect.firstChildElement("name");
152 if (namenode.isNull()) return;
153 title->setText(i18n(namenode.text().toUtf8().data()));
154 QString type = m_effect.attribute("type", QString());
156 if (type == "audio") icon = KIcon("kdenlive-show-audio");
157 else if (m_effect.attribute("tag") == "region") icon = KIcon("kdenlive-mask-effect");
158 else if (type == "custom") icon = KIcon("kdenlive-custom-effect");
159 else icon = KIcon("kdenlive-show-video");
160 title->setIcon(icon);
163 m_menu->addAction(KIcon("view-refresh"), i18n("Reset effect"), this, SLOT(slotResetEffect()));
164 m_menu->addAction(KIcon("document-save"), i18n("Save effect"), this, SLOT(slotSaveEffect()));
165 title->setMenu(m_menu);
167 if (m_effect.attribute("disable") == "1") {
168 enabledBox->setCheckState(Qt::Unchecked);
169 title->setEnabled(false);
172 enabledBox->setCheckState(Qt::Checked);
175 connect(collapseButton, SIGNAL(clicked()), this, SLOT(slotSwitch()));
176 connect(enabledBox, SIGNAL(toggled(bool)), this, SLOT(slotEnable(bool)));
177 connect(buttonUp, SIGNAL(clicked()), this, SLOT(slotEffectUp()));
178 connect(buttonDown, SIGNAL(clicked()), this, SLOT(slotEffectDown()));
179 connect(buttonDel, SIGNAL(clicked()), this, SLOT(slotDeleteEffect()));
181 setupWidget(info, ix, metaInfo);
182 Q_FOREACH( QSpinBox * sp, findChildren<QSpinBox*>() ) {
183 sp->installEventFilter( this );
184 sp->setFocusPolicy( Qt::StrongFocus );
186 Q_FOREACH( KComboBox * cb, findChildren<KComboBox*>() ) {
187 cb->installEventFilter( this );
188 cb->setFocusPolicy( Qt::StrongFocus );
190 Q_FOREACH( QProgressBar * cb, findChildren<QProgressBar*>() ) {
191 cb->installEventFilter( this );
192 cb->setFocusPolicy( Qt::StrongFocus );
196 CollapsibleEffect::~CollapsibleEffect()
198 if (m_paramWidget) delete m_paramWidget;
202 bool CollapsibleEffect::eventFilter( QObject * o, QEvent * e )
204 if (e->type() == QEvent::Wheel) {
205 QWheelEvent *we = static_cast<QWheelEvent *>(e);
206 if (we->modifiers() != Qt::NoModifier) {
210 if (qobject_cast<QAbstractSpinBox*>(o)) {
211 if(qobject_cast<QAbstractSpinBox*>(o)->focusPolicy() == Qt::WheelFocus)
222 if (qobject_cast<KComboBox*>(o)) {
223 if(qobject_cast<KComboBox*>(o)->focusPolicy() == Qt::WheelFocus)
234 if (qobject_cast<QProgressBar*>(o)) {
235 if(qobject_cast<QProgressBar*>(o)->focusPolicy() == Qt::WheelFocus)
247 return QWidget::eventFilter(o, e);
250 QDomElement CollapsibleEffect::effect() const
255 void CollapsibleEffect::setActive(bool activate)
258 frame->setBackgroundRole(m_active ? QPalette::Mid : QPalette::Midlight);
259 frame->setAutoFillBackground(activate);
262 void CollapsibleEffect::mouseDoubleClickEvent ( QMouseEvent * event )
264 if (frame->underMouse() && collapseButton->isEnabled()) slotSwitch();
265 QWidget::mouseDoubleClickEvent(event);
268 void CollapsibleEffect::mousePressEvent ( QMouseEvent *event )
270 if (!m_active) emit activateEffect(m_paramWidget->index());
271 QWidget::mousePressEvent(event);
274 void CollapsibleEffect::enterEvent ( QEvent * event )
276 if (m_paramWidget->index() > 0) buttonUp->setVisible(true);
277 if (!m_lastEffect) buttonDown->setVisible(true);
278 buttonDel->setVisible(true);
279 if (!m_active) frame->setBackgroundRole(QPalette::Midlight);
280 frame->setAutoFillBackground(true);
281 QWidget::enterEvent(event);
284 void CollapsibleEffect::leaveEvent ( QEvent * event )
286 buttonUp->setVisible(false);
287 buttonDown->setVisible(false);
288 buttonDel->setVisible(false);
289 if (!m_active) frame->setAutoFillBackground(false);
290 QWidget::leaveEvent(event);
293 void CollapsibleEffect::slotEnable(bool enable)
295 title->setEnabled(enable);
296 m_effect.setAttribute("disable", enable ? 0 : 1);
297 if (enable || KdenliveSettings::disable_effect_parameters()) {
298 widgetFrame->setEnabled(enable);
300 emit effectStateChanged(!enable, m_paramWidget->index());
303 void CollapsibleEffect::slotDeleteEffect()
305 emit deleteEffect(m_effect, m_paramWidget->index());
308 void CollapsibleEffect::slotEffectUp()
310 emit changeEffectPosition(m_paramWidget->index(), true);
313 void CollapsibleEffect::slotEffectDown()
315 emit changeEffectPosition(m_paramWidget->index(), false);
318 void CollapsibleEffect::slotSaveEffect()
320 QString name = QInputDialog::getText(this, i18n("Save Effect"), i18n("Name for saved effect: "));
321 if (name.isEmpty()) return;
322 QString path = KStandardDirs::locateLocal("appdata", "effects/", true);
323 path = path + name + ".xml";
324 if (QFile::exists(path)) if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", path)) == KMessageBox::No) return;
327 QDomElement effect = m_effect.cloneNode().toElement();
328 doc.appendChild(doc.importNode(effect, true));
329 effect = doc.firstChild().toElement();
330 effect.removeAttribute("kdenlive_ix");
331 effect.setAttribute("id", name);
332 effect.setAttribute("type", "custom");
333 QDomElement effectname = effect.firstChildElement("name");
334 effect.removeChild(effectname);
335 effectname = doc.createElement("name");
336 QDomText nametext = doc.createTextNode(name);
337 effectname.appendChild(nametext);
338 effect.insertBefore(effectname, QDomNode());
339 QDomElement effectprops = effect.firstChildElement("properties");
340 effectprops.setAttribute("id", name);
341 effectprops.setAttribute("type", "custom");
344 if (file.open(QFile::WriteOnly | QFile::Truncate)) {
345 QTextStream out(&file);
346 out << doc.toString();
349 emit reloadEffects();
352 void CollapsibleEffect::slotResetEffect()
354 emit resetEffect(m_paramWidget->index());
357 void CollapsibleEffect::slotSwitch()
359 bool enable = !widgetFrame->isVisible();
363 void CollapsibleEffect::slotShow(bool show)
365 widgetFrame->setVisible(show);
367 collapseButton->setArrowType(Qt::DownArrow);
368 m_original_effect.removeAttribute("k_collapsed");
371 collapseButton->setArrowType(Qt::RightArrow);
372 m_original_effect.setAttribute("k_collapsed", 1);
376 void CollapsibleEffect::updateWidget(ItemInfo info, int index, QDomElement effect, EffectMetaInfo *metaInfo)
380 delete m_paramWidget;
381 m_paramWidget = NULL;
384 setupWidget(info, index, metaInfo);
387 void CollapsibleEffect::setupWidget(ItemInfo info, int index, EffectMetaInfo *metaInfo)
389 if (m_effect.isNull()) {
390 // kDebug() << "// EMPTY EFFECT STACK";
394 if (m_effect.attribute("tag") == "region") {
395 QVBoxLayout *vbox = new QVBoxLayout(widgetFrame);
396 vbox->setContentsMargins(0, 0, 0, 0);
398 QDomNodeList effects = m_effect.elementsByTagName("effect");
399 QDomNodeList origin_effects = m_original_effect.elementsByTagName("effect");
400 QWidget *container = new QWidget(widgetFrame);
401 vbox->addWidget(container);
402 m_paramWidget = new ParameterContainer(m_effect.toElement(), info, metaInfo, index, container);
403 for (int i = 0; i < effects.count(); i++) {
404 CollapsibleEffect *coll = new CollapsibleEffect(effects.at(i).toElement(), origin_effects.at(i).toElement(), info, i, metaInfo, container);
405 m_subParamWidgets.append(coll);
406 //container = new QWidget(widgetFrame);
407 vbox->addWidget(coll);
408 //p = new ParameterContainer(effects.at(i).toElement(), info, isEffect, container);
413 m_paramWidget = new ParameterContainer(m_effect, info, metaInfo, index, widgetFrame);
414 if (m_effect.firstChildElement("parameter").isNull()) {
415 // Effect has no parameter, don't allow expand
416 collapseButton->setEnabled(false);
417 widgetFrame->setVisible(false);
420 if (collapseButton->isEnabled()) slotShow(!m_effect.hasAttribute("k_collapsed"));
421 connect (m_paramWidget, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)));
423 connect(m_paramWidget, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)));
425 connect (this, SIGNAL(syncEffectsPos(int)), m_paramWidget, SIGNAL(syncEffectsPos(int)));
426 connect (this, SIGNAL(effectStateChanged(bool)), m_paramWidget, SIGNAL(effectStateChanged(bool)));
427 connect (m_paramWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
428 connect (m_paramWidget, SIGNAL(seekTimeline(int)), this, SIGNAL(seekTimeline(int)));
433 void CollapsibleEffect::updateTimecodeFormat()
435 m_paramWidget->updateTimecodeFormat();
436 if (!m_subParamWidgets.isEmpty()) {
438 for (int i = 0; i < m_subParamWidgets.count(); i++)
439 m_subParamWidgets.at(i)->updateTimecodeFormat();
443 void CollapsibleEffect::slotSyncEffectsPos(int pos)
445 emit syncEffectsPos(pos);
450 ParameterContainer::ParameterContainer(QDomElement effect, ItemInfo info, EffectMetaInfo *metaInfo, int index, QWidget * parent) :
452 m_keyframeEditor(NULL),
453 m_geometryWidget(NULL),
454 m_metaInfo(metaInfo),
457 m_in = info.cropStart.frames(KdenliveSettings::project_fps());
458 m_out = (info.cropStart + info.cropDuration).frames(KdenliveSettings::project_fps()) - 1;
460 QDomNodeList namenode = effect.childNodes(); //elementsByTagName("parameter");
462 QDomElement e = effect.toElement();
463 int minFrame = e.attribute("start").toInt();
464 int maxFrame = e.attribute("end").toInt();
465 // In transitions, maxFrame is in fact one frame after the end of transition
466 if (maxFrame > 0) maxFrame --;
468 bool disable = effect.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
469 parent->setEnabled(!disable);
472 m_vbox = new QVBoxLayout(parent);
473 m_vbox->setContentsMargins(0, 0, 0, 0);
474 m_vbox->setSpacing(2);
476 for (int i = 0; i < namenode.count() ; i++) {
477 QDomElement pa = namenode.item(i).toElement();
478 if (pa.tagName() != "parameter") continue;
479 QDomElement na = pa.firstChildElement("name");
480 QDomElement commentElem = pa.firstChildElement("comment");
481 QString type = pa.attribute("type");
482 QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
484 if (!commentElem.isNull())
485 comment = i18n(commentElem.text().toUtf8().data());
486 QWidget * toFillin = new QWidget(parent);
487 QString value = pa.attribute("value").isNull() ?
488 pa.attribute("default") : pa.attribute("value");
491 /** See effects/README for info on the different types */
493 if (type == "double" || type == "constant") {
496 if (pa.attribute("min").contains('%'))
497 min = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("min"), m_metaInfo->frameSize);
499 min = pa.attribute("min").toDouble();
500 if (pa.attribute("max").contains('%'))
501 max = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("max"), m_metaInfo->frameSize);
503 max = pa.attribute("max").toDouble();
505 DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, value.toDouble(), min, max,
506 pa.attribute("default").toDouble(), comment, -1, pa.attribute("suffix"), pa.attribute("decimals").toInt(), parent);
507 doubleparam->setFocusPolicy(Qt::StrongFocus);
508 m_vbox->addWidget(doubleparam);
509 m_valueItems[paramName] = doubleparam;
510 connect(doubleparam, SIGNAL(valueChanged(double)), this, SLOT(slotCollectAllParameters()));
511 connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
512 } else if (type == "list") {
513 Listval *lsval = new Listval;
514 lsval->setupUi(toFillin);
515 lsval->list->setFocusPolicy(Qt::StrongFocus);
516 QStringList listitems = pa.attribute("paramlist").split(';');
517 if (listitems.count() == 1) {
518 // probably custom effect created before change to ';' as separator
519 listitems = pa.attribute("paramlist").split(",");
521 QDomElement list = pa.firstChildElement("paramlistdisplay");
522 QStringList listitemsdisplay;
523 if (!list.isNull()) {
524 listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
526 listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
528 if (listitemsdisplay.count() != listitems.count())
529 listitemsdisplay = listitems;
530 lsval->list->setIconSize(QSize(30, 30));
531 for (int i = 0; i < listitems.count(); i++) {
532 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
533 QString entry = listitems.at(i);
534 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
535 if (!CollapsibleEffect::iconCache.contains(entry)) {
537 CollapsibleEffect::iconCache[entry] = pix.scaled(30, 30);
539 lsval->list->setItemIcon(i, QPixmap::fromImage(CollapsibleEffect::iconCache[entry]));
542 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
543 lsval->name->setText(paramName);
544 lsval->labelComment->setText(comment);
545 lsval->widgetComment->setHidden(true);
546 m_valueItems[paramName] = lsval;
547 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(slotCollectAllParameters()));
548 if (!comment.isEmpty())
549 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
550 m_uiItems.append(lsval);
551 } else if (type == "bool") {
552 Boolval *bval = new Boolval;
553 bval->setupUi(toFillin);
554 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
555 bval->name->setText(paramName);
556 bval->labelComment->setText(comment);
557 bval->widgetComment->setHidden(true);
558 m_valueItems[paramName] = bval;
559 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(slotCollectAllParameters()));
560 if (!comment.isEmpty())
561 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
562 m_uiItems.append(bval);
563 } else if (type == "complex") {
564 ComplexParameter *pl = new ComplexParameter;
565 pl->setupParam(effect, pa.attribute("name"), 0, 100);
566 m_vbox->addWidget(pl);
567 m_valueItems[paramName+"complex"] = pl;
568 connect(pl, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
569 } else if (type == "geometry") {
570 if (KdenliveSettings::on_monitor_effects()) {
571 m_geometryWidget = new GeometryWidget(m_metaInfo->monitor, m_metaInfo->timecode, 0, true, effect.hasAttribute("showrotation"), parent);
572 m_geometryWidget->setFrameSize(m_metaInfo->frameSize);
573 m_geometryWidget->slotShowScene(!disable);
574 // connect this before setupParam to make sure the monitor scene shows up at startup
575 connect(m_geometryWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
576 connect(m_geometryWidget, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
577 if (minFrame == maxFrame)
578 m_geometryWidget->setupParam(pa, m_in, m_out);
580 m_geometryWidget->setupParam(pa, minFrame, maxFrame);
581 m_vbox->addWidget(m_geometryWidget);
582 m_valueItems[paramName+"geometry"] = m_geometryWidget;
583 connect(m_geometryWidget, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
584 connect(this, SIGNAL(syncEffectsPos(int)), m_geometryWidget, SLOT(slotSyncPosition(int)));
585 connect(this, SIGNAL(effectStateChanged(bool)), m_geometryWidget, SLOT(slotShowScene(bool)));
587 Geometryval *geo = new Geometryval(m_metaInfo->profile, m_metaInfo->timecode, m_metaInfo->frameSize, 0);
588 if (minFrame == maxFrame)
589 geo->setupParam(pa, m_in, m_out);
591 geo->setupParam(pa, minFrame, maxFrame);
592 m_vbox->addWidget(geo);
593 m_valueItems[paramName+"geometry"] = geo;
594 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
595 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
596 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
598 } else if (type == "addedgeometry") {
599 // this is a parameter that should be linked to the geometry widget, for example rotation, shear, ...
600 if (m_geometryWidget) m_geometryWidget->addParameter(pa);
601 } else if (type == "keyframe" || type == "simplekeyframe") {
602 // keyframe editor widget
603 if (m_keyframeEditor == NULL) {
605 if (pa.attribute("widget") == "corners") {
606 // we want a corners-keyframe-widget
607 CornersWidget *corners = new CornersWidget(m_metaInfo->monitor, pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt(), parent);
608 corners->slotShowScene(!disable);
609 connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
610 connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
611 connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
612 geo = static_cast<KeyframeEdit *>(corners);
614 geo = new KeyframeEdit(pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt());
616 m_vbox->addWidget(geo);
617 m_valueItems[paramName+"keyframe"] = geo;
618 m_keyframeEditor = geo;
619 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
620 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
621 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
623 // we already have a keyframe editor, so just add another column for the new param
624 m_keyframeEditor->addParameter(pa);
626 } else if (type == "color") {
627 if (value.startsWith('#'))
628 value = value.replace('#', "0x");
629 ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, value, parent);
630 m_vbox->addWidget(choosecolor);
631 m_valueItems[paramName] = choosecolor;
632 connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
633 connect(choosecolor, SIGNAL(modified()) , this, SLOT(slotCollectAllParameters()));
634 } else if (type == "position") {
635 int pos = value.toInt();
636 if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
638 } else if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
639 // fadeout position starts from clip end
642 PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_metaInfo->timecode);
643 m_vbox->addWidget(posedit);
644 m_valueItems[paramName+"position"] = posedit;
645 connect(posedit, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
646 } else if (type == "curve") {
647 KisCurveWidget *curve = new KisCurveWidget(parent);
648 curve->setMaxPoints(pa.attribute("max").toInt());
649 QList<QPointF> points;
650 int number = EffectsList::parameter(e, pa.attribute("number")).toInt();
651 QString inName = pa.attribute("inpoints");
652 QString outName = pa.attribute("outpoints");
653 int start = pa.attribute("min").toInt();
654 for (int j = start; j <= number; j++) {
656 in.replace("%i", QString::number(j));
657 QString out = outName;
658 out.replace("%i", QString::number(j));
659 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
661 if (!points.isEmpty())
662 curve->setCurve(KisCubicCurve(points));
663 MySpinBox *spinin = new MySpinBox();
664 spinin->setRange(0, 1000);
665 MySpinBox *spinout = new MySpinBox();
666 spinout->setRange(0, 1000);
667 curve->setupInOutControls(spinin, spinout, 0, 1000);
668 m_vbox->addWidget(curve);
669 m_vbox->addWidget(spinin);
670 m_vbox->addWidget(spinout);
672 connect(curve, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
673 m_valueItems[paramName] = curve;
675 QString depends = pa.attribute("depends");
676 if (!depends.isEmpty())
677 meetDependency(paramName, type, EffectsList::parameter(e, depends));
678 } else if (type == "bezier_spline") {
679 BezierSplineWidget *widget = new BezierSplineWidget(value, parent);
681 m_vbox->addWidget(widget);
682 m_valueItems[paramName] = widget;
683 connect(widget, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
684 QString depends = pa.attribute("depends");
685 if (!depends.isEmpty())
686 meetDependency(paramName, type, EffectsList::parameter(e, depends));
688 } else if (type == "roto-spline") {
689 RotoWidget *roto = new RotoWidget(value, m_metaInfo->monitor, info, m_metaInfo->timecode, parent);
690 roto->slotShowScene(!disable);
691 connect(roto, SIGNAL(valueChanged()), this, SLOT(slotCollectAllParameters()));
692 connect(roto, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
693 connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
694 connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
695 connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
696 m_vbox->addWidget(roto);
697 m_valueItems[paramName] = roto;
699 } else if (type == "wipe") {
700 Wipeval *wpval = new Wipeval;
701 wpval->setupUi(toFillin);
702 wipeInfo w = getWipeInfo(value);
705 wpval->start_up->setChecked(true);
708 wpval->start_down->setChecked(true);
711 wpval->start_right->setChecked(true);
714 wpval->start_left->setChecked(true);
717 wpval->start_center->setChecked(true);
722 wpval->end_up->setChecked(true);
725 wpval->end_down->setChecked(true);
728 wpval->end_right->setChecked(true);
731 wpval->end_left->setChecked(true);
734 wpval->end_center->setChecked(true);
737 wpval->start_transp->setValue(w.startTransparency);
738 wpval->end_transp->setValue(w.endTransparency);
739 m_valueItems[paramName] = wpval;
740 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
741 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
742 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
743 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
744 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
745 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
746 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
747 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
748 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
749 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
750 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
751 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
752 //wpval->title->setTitle(na.toElement().text());
753 m_uiItems.append(wpval);
754 } else if (type == "url") {
755 Urlval *cval = new Urlval;
756 cval->setupUi(toFillin);
757 cval->label->setText(paramName);
758 cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
759 m_valueItems[paramName] = cval;
760 cval->urlwidget->setUrl(KUrl(value));
761 connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(slotCollectAllParameters()));
762 connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(slotCollectAllParameters()));
763 m_uiItems.append(cval);
764 } else if (type == "keywords") {
765 Keywordval* kval = new Keywordval;
766 kval->setupUi(toFillin);
767 kval->label->setText(paramName);
768 kval->lineeditwidget->setText(value);
769 QDomElement klistelem = pa.firstChildElement("keywords");
770 QDomElement kdisplaylistelem = pa.firstChildElement("keywordsdisplay");
771 QStringList keywordlist;
772 QStringList keyworddisplaylist;
773 if (!klistelem.isNull()) {
774 keywordlist = klistelem.text().split(';');
775 keyworddisplaylist = i18n(kdisplaylistelem.text().toUtf8().data()).split(';');
777 if (keyworddisplaylist.count() != keywordlist.count()) {
778 keyworddisplaylist = keywordlist;
780 for (int i = 0; i < keywordlist.count(); i++) {
781 kval->comboboxwidget->addItem(keyworddisplaylist.at(i), keywordlist.at(i));
783 // Add disabled user prompt at index 0
784 kval->comboboxwidget->insertItem(0, i18n("<select a keyword>"), "");
785 kval->comboboxwidget->model()->setData( kval->comboboxwidget->model()->index(0,0), QVariant(Qt::NoItemFlags), Qt::UserRole -1);
786 kval->comboboxwidget->setCurrentIndex(0);
787 m_valueItems[paramName] = kval;
788 connect(kval->lineeditwidget, SIGNAL(editingFinished()) , this, SLOT(collectAllParameters()));
789 connect(kval->comboboxwidget, SIGNAL(activated (const QString&)), this, SLOT(collectAllParameters()));
790 m_uiItems.append(kval);
791 } else if (type == "fontfamily") {
792 Fontval* fval = new Fontval;
793 fval->setupUi(toFillin);
794 fval->name->setText(paramName);
795 fval->fontfamilywidget->setCurrentFont(QFont(value));
796 m_valueItems[paramName] = fval;
797 connect(fval->fontfamilywidget, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(collectAllParameters())) ;
798 m_uiItems.append(fval);
799 } else if (type == "filterjob") {
800 QVBoxLayout *l= new QVBoxLayout(toFillin);
801 QPushButton *button = new QPushButton(paramName, toFillin);
802 l->addWidget(button);
803 m_valueItems[paramName] = button;
804 connect(button, SIGNAL(pressed()), this, SLOT(slotStartFilterJobAction()));
811 m_vbox->addWidget(toFillin);
815 m_vbox->addStretch();
817 if (m_keyframeEditor)
818 m_keyframeEditor->checkVisibleParam();
820 // Make sure all doubleparam spinboxes have the same width, looks much better
821 QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
823 for (int i = 0; i < allWidgets.count(); i++) {
824 if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
826 for (int i = 0; i < allWidgets.count(); i++) {
827 allWidgets.at(i)->setSpinSize(minSize);
831 ParameterContainer::~ParameterContainer()
833 //clearLayout(m_vbox);
837 void ParameterContainer::meetDependency(const QString& name, QString type, QString value)
839 if (type == "curve") {
840 KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
842 int color = value.toInt();
843 curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
845 } else if (type == "bezier_spline") {
846 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
848 widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10)));
853 wipeInfo ParameterContainer::getWipeInfo(QString value)
856 // Convert old geometry values that used a comma as separator
857 if (value.contains(',')) value.replace(',','/');
858 QString start = value.section(';', 0, 0);
859 QString end = value.section(';', 1, 1).section('=', 1, 1);
860 if (start.startsWith("-100%/0"))
862 else if (start.startsWith("100%/0"))
864 else if (start.startsWith("0%/100%"))
866 else if (start.startsWith("0%/-100%"))
871 if (start.count(':') == 2)
872 info.startTransparency = start.section(':', -1).toInt();
874 info.startTransparency = 100;
876 if (end.startsWith("-100%/0"))
878 else if (end.startsWith("100%/0"))
880 else if (end.startsWith("0%/100%"))
882 else if (end.startsWith("0%/-100%"))
887 if (end.count(':') == 2)
888 info.endTransparency = end.section(':', -1).toInt();
890 info.endTransparency = 100;
895 void ParameterContainer::updateTimecodeFormat()
897 if (m_keyframeEditor)
898 m_keyframeEditor->updateTimecodeFormat();
900 QDomNodeList namenode = m_effect.elementsByTagName("parameter");
901 for (int i = 0; i < namenode.count() ; i++) {
902 QDomNode pa = namenode.item(i);
903 QDomElement na = pa.firstChildElement("name");
904 QString type = pa.attributes().namedItem("type").nodeValue();
905 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
907 if (type == "geometry") {
908 if (KdenliveSettings::on_monitor_effects()) {
909 if (m_geometryWidget) m_geometryWidget->updateTimecodeFormat();
911 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
912 geom->updateTimecodeFormat();
915 } else if (type == "position") {
916 PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
917 posi->updateTimecodeFormat();
920 } else if (type == "roto-spline") {
921 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems[paramName]);
922 widget->updateTimecodeFormat();
928 void ParameterContainer::slotCollectAllParameters()
930 if (m_valueItems.isEmpty() || m_effect.isNull()) return;
932 locale.setNumberOptions(QLocale::OmitGroupSeparator);
933 const QDomElement oldparam = m_effect.cloneNode().toElement();
934 //QDomElement newparam = oldparam.cloneNode().toElement();
935 QDomNodeList namenode = m_effect.elementsByTagName("parameter");
937 for (int i = 0; i < namenode.count() ; i++) {
938 QDomNode pa = namenode.item(i);
939 QDomElement na = pa.firstChildElement("name");
940 QString type = pa.attributes().namedItem("type").nodeValue();
941 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
942 if (type == "complex")
943 paramName.append("complex");
944 else if (type == "position")
945 paramName.append("position");
946 else if (type == "geometry")
947 paramName.append("geometry");
948 else if (type == "keyframe")
949 paramName.append("keyframe");
950 if (type != "simplekeyframe" && type != "fixed" && type != "addedgeometry" && !m_valueItems.contains(paramName)) {
951 kDebug() << "// Param: " << paramName << " NOT FOUND";
956 if (type == "double" || type == "constant") {
957 DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
958 setValue = locale.toString(doubleparam->getValue());
959 } else if (type == "list") {
960 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
961 setValue = box->itemData(box->currentIndex()).toString();
962 } else if (type == "bool") {
963 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
964 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
965 } else if (type == "color") {
966 ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
967 setValue = choosecolor->getColor();
968 } else if (type == "complex") {
969 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
970 namenode.item(i) = complex->getParamDesc();
971 } else if (type == "geometry") {
972 if (KdenliveSettings::on_monitor_effects()) {
973 if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getValue());
975 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
976 namenode.item(i).toElement().setAttribute("value", geom->getValue());
978 } else if (type == "addedgeometry") {
979 namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getExtraValue(namenode.item(i).toElement().attribute("name")));
980 } else if (type == "position") {
981 PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
982 int pos = pedit->getPosition();
983 setValue = QString::number(pos);
984 if (m_effect.attribute("id") == "fadein" || m_effect.attribute("id") == "fade_from_black") {
985 // Make sure duration is not longer than clip
988 pedit->setPosition(pos);
990 EffectsList::setParameter(m_effect, "in", QString::number(m_in));
991 EffectsList::setParameter(m_effect, "out", QString::number(m_in + pos));
993 } else if (m_effect.attribute("id") == "fadeout" || m_effect.attribute("id") == "fade_to_black") {
994 // Make sure duration is not longer than clip
997 pedit->setPosition(pos);
999 EffectsList::setParameter(m_effect, "in", QString::number(m_out - pos));
1000 EffectsList::setParameter(m_effect, "out", QString::number(m_out));
1003 } else if (type == "curve") {
1004 KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
1005 QList<QPointF> points = curve->curve().points();
1006 QString number = pa.attributes().namedItem("number").nodeValue();
1007 QString inName = pa.attributes().namedItem("inpoints").nodeValue();
1008 QString outName = pa.attributes().namedItem("outpoints").nodeValue();
1009 int off = pa.attributes().namedItem("min").nodeValue().toInt();
1010 int end = pa.attributes().namedItem("max").nodeValue().toInt();
1011 EffectsList::setParameter(m_effect, number, QString::number(points.count()));
1012 for (int j = 0; (j < points.count() && j + off <= end); j++) {
1013 QString in = inName;
1014 in.replace("%i", QString::number(j + off));
1015 QString out = outName;
1016 out.replace("%i", QString::number(j + off));
1017 EffectsList::setParameter(m_effect, in, locale.toString(points.at(j).x()));
1018 EffectsList::setParameter(m_effect, out, locale.toString(points.at(j).y()));
1020 QString depends = pa.attributes().namedItem("depends").nodeValue();
1021 if (!depends.isEmpty())
1022 meetDependency(paramName, type, EffectsList::parameter(m_effect, depends));
1023 } else if (type == "bezier_spline") {
1024 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
1025 setValue = widget->spline();
1026 QString depends = pa.attributes().namedItem("depends").nodeValue();
1027 if (!depends.isEmpty())
1028 meetDependency(paramName, type, EffectsList::parameter(m_effect, depends));
1030 } else if (type == "roto-spline") {
1031 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
1032 setValue = widget->getSpline();
1034 } else if (type == "wipe") {
1035 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
1037 if (wp->start_left->isChecked())
1039 else if (wp->start_right->isChecked())
1041 else if (wp->start_up->isChecked())
1043 else if (wp->start_down->isChecked())
1045 else if (wp->start_center->isChecked())
1046 info.start = CENTER;
1049 info.startTransparency = wp->start_transp->value();
1051 if (wp->end_left->isChecked())
1053 else if (wp->end_right->isChecked())
1055 else if (wp->end_up->isChecked())
1057 else if (wp->end_down->isChecked())
1059 else if (wp->end_center->isChecked())
1063 info.endTransparency = wp->end_transp->value();
1065 setValue = getWipeString(info);
1066 } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
1067 QDomElement elem = pa.toElement();
1068 QString realName = i18n(na.toElement().text().toUtf8().data());
1069 QString val = m_keyframeEditor->getValue(realName);
1070 elem.setAttribute("keyframes", val);
1072 if (m_keyframeEditor->isVisibleParam(realName))
1073 elem.setAttribute("intimeline", "1");
1074 else if (elem.hasAttribute("intimeline"))
1075 elem.removeAttribute("intimeline");
1076 } else if (type == "url") {
1077 KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
1078 setValue = req->url().path();
1079 } else if (type == "keywords"){
1080 QLineEdit *line = ((Keywordval*)m_valueItems.value(paramName))->lineeditwidget;
1081 QComboBox *combo = ((Keywordval*)m_valueItems.value(paramName))->comboboxwidget;
1082 if(combo->currentIndex())
1084 QString comboval = combo->itemData(combo->currentIndex()).toString();
1085 line->insert(comboval);
1086 combo->setCurrentIndex(0);
1088 setValue = line->text();
1089 } else if (type == "fontfamily") {
1090 QFontComboBox* fontfamily = ((Fontval*)m_valueItems.value(paramName))->fontfamilywidget;
1091 setValue = fontfamily->currentFont().family();
1093 if (!setValue.isNull())
1094 pa.attributes().namedItem("value").setNodeValue(setValue);
1097 emit parameterChanged(oldparam, m_effect, m_index);
1100 QString ParameterContainer::getWipeString(wipeInfo info)
1105 switch (info.start) {
1107 start = "-100%/0%:100%x100%";
1110 start = "100%/0%:100%x100%";
1113 start = "0%/100%:100%x100%";
1116 start = "0%/-100%:100%x100%";
1119 start = "0%/0%:100%x100%";
1122 start.append(':' + QString::number(info.startTransparency));
1126 end = "-100%/0%:100%x100%";
1129 end = "100%/0%:100%x100%";
1132 end = "0%/100%:100%x100%";
1135 end = "0%/-100%:100%x100%";
1138 end = "0%/0%:100%x100%";
1141 end.append(':' + QString::number(info.endTransparency));
1142 return QString(start + ";-1=" + end);
1145 int ParameterContainer::index()
1150 void ParameterContainer::slotStartFilterJobAction()
1152 QDomNodeList namenode = m_effect.elementsByTagName("parameter");
1153 for (int i = 0; i < namenode.count() ; i++) {
1154 QDomElement pa = namenode.item(i).toElement();
1155 QString type = pa.attribute("type");
1156 if (type == "filterjob") {
1157 emit startFilterJob(pa.attribute("filtertag"), pa.attribute("filterparams"), pa.attribute("finalfilter"), pa.attribute("consumer"), pa.attribute("consumerparams"), pa.attribute("wantedproperties"));
1158 kDebug()<<" - - -PROPS:\n"<<pa.attribute("filtertag")<<"-"<< pa.attribute("filterparams")<<"-"<< pa.attribute("consumer")<<"-"<< pa.attribute("consumerparams")<<"-"<< pa.attribute("wantedproperties");