1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include "collapsibleeffect.h"
23 #include "ui_listval_ui.h"
24 #include "ui_boolval_ui.h"
25 #include "ui_wipeval_ui.h"
26 #include "ui_urlval_ui.h"
27 #include "complexparameter.h"
28 #include "geometryval.h"
29 #include "positionedit.h"
30 #include "projectlist.h"
31 #include "effectslist.h"
32 #include "kdenlivesettings.h"
33 #include "profilesdialog.h"
34 #include "kis_curve_widget.h"
35 #include "kis_cubic_curve.h"
36 #include "choosecolorwidget.h"
37 #include "geometrywidget.h"
38 #include "colortools.h"
39 #include "doubleparameterwidget.h"
40 #include "cornerswidget.h"
41 #include "beziercurve/beziersplinewidget.h"
43 #include "rotoscoping/rotowidget.h"
48 #include <QVBoxLayout>
50 #include <KGlobalSettings>
52 #include <KFileDialog>
53 #include <KUrlRequester>
55 class Boolval: public QWidget, public Ui::Boolval_UI
59 class Listval: public QWidget, public Ui::Listval_UI
63 class Wipeval: public QWidget, public Ui::Wipeval_UI
67 class Urlval: public QWidget, public Ui::Urlval_UI
71 QMap<QString, QImage> CollapsibleEffect::iconCache;
73 void clearLayout(QLayout *layout)
76 while((item = layout->takeAt(0))) {
78 clearLayout(item->layout());
79 delete item->layout();
82 delete item->widget();
88 CollapsibleEffect::CollapsibleEffect(QDomElement effect, QDomElement original_effect, ItemInfo info, int ix, EffectMetaInfo *metaInfo, bool lastEffect, QWidget * parent) :
92 m_original_effect(original_effect),
93 m_lastEffect(lastEffect),
96 //setMouseTracking(true);
98 frame->setBackgroundRole(QPalette::Midlight);
99 frame->setAutoFillBackground(true);
100 setFont(KGlobalSettings::smallestReadableFont());
101 QDomElement namenode = m_effect.firstChildElement("name");
102 if (namenode.isNull()) return;
103 QString type = m_effect.attribute("type", QString());
105 if (type == "audio") icon = KIcon("kdenlive-show-audio");
106 else if (m_effect.attribute("tag") == "region") icon = KIcon("kdenlive-mask-effect");
107 else if (type == "custom") icon = KIcon("kdenlive-custom-effect");
108 else icon = KIcon("kdenlive-show-video");
110 buttonUp->setIcon(KIcon("go-up"));
111 buttonUp->setToolTip(i18n("Move effect up"));
113 buttonDown->setIcon(KIcon("go-down"));
114 buttonDown->setToolTip(i18n("Move effect down"));
116 buttonDel->setIcon(KIcon("edit-delete"));
117 buttonDel->setToolTip(i18n("Delete effect"));
118 buttonSave->setIcon(KIcon("document-save"));
119 buttonSave->setToolTip(i18n("Save effect"));
121 buttonUp->setVisible(false);
122 buttonDown->setVisible(false);
123 buttonSave->setVisible(false);
124 buttonDel->setVisible(false);
126 /*buttonReset->setIcon(KIcon("view-refresh"));
127 buttonReset->setToolTip(i18n("Reset effect"));*/
128 //checkAll->setToolTip(i18n("Enable/Disable all effects"));
129 //buttonShowComments->setIcon(KIcon("help-about"));
130 //buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
132 title->setText(i18n(namenode.text().toUtf8().data()));
133 effectIcon->setPixmap(icon.pixmap(QSize(16,16)));
135 //QLabel *lab = new QLabel("HEllo", widgetFrame);
136 //m_vbox->addWidget(lab);
137 if (m_effect.attribute("disable") == "1") {
138 enabledBox->setCheckState(Qt::Unchecked);
139 title->setEnabled(false);
142 enabledBox->setCheckState(Qt::Checked);
145 connect(collapseButton, SIGNAL(clicked()), this, SLOT(slotSwitch()));
146 connect(enabledBox, SIGNAL(toggled(bool)), this, SLOT(slotEnable(bool)));
147 connect(buttonUp, SIGNAL(clicked()), this, SLOT(slotEffectUp()));
148 connect(buttonDown, SIGNAL(clicked()), this, SLOT(slotEffectDown()));
149 connect(buttonDel, SIGNAL(clicked()), this, SLOT(slotDeleteEffect()));
150 setupWidget(info, ix, metaInfo);
153 CollapsibleEffect::~CollapsibleEffect()
155 if (m_paramWidget) delete m_paramWidget;
159 void CollapsibleEffect::setActive(bool activate)
162 frame->setBackgroundRole(m_active ? QPalette::Mid : QPalette::Midlight);
163 frame->setAutoFillBackground(activate);
166 void CollapsibleEffect::mouseDoubleClickEvent ( QMouseEvent * event )
168 if (frame->underMouse() && collapseButton->isEnabled()) slotSwitch();
169 QWidget::mouseDoubleClickEvent(event);
172 void CollapsibleEffect::mousePressEvent ( QMouseEvent *event )
174 if (!m_active) emit activateEffect(m_paramWidget->index());
175 QWidget::mousePressEvent(event);
178 void CollapsibleEffect::enterEvent ( QEvent * event )
180 if (m_paramWidget->index() > 0) buttonUp->setVisible(true);
181 if (!m_lastEffect) buttonDown->setVisible(true);
182 buttonSave->setVisible(true);
183 buttonDel->setVisible(true);
184 if (!m_active) frame->setBackgroundRole(QPalette::Midlight);
185 frame->setAutoFillBackground(true);
186 QWidget::enterEvent(event);
189 void CollapsibleEffect::leaveEvent ( QEvent * event )
191 buttonUp->setVisible(false);
192 buttonDown->setVisible(false);
193 buttonSave->setVisible(false);
194 buttonDel->setVisible(false);
195 if (!m_active) frame->setAutoFillBackground(false);
196 QWidget::leaveEvent(event);
199 void CollapsibleEffect::slotEnable(bool enable)
201 title->setEnabled(enable);
202 m_effect.setAttribute("disable", enable ? 0 : 1);
203 if (enable || KdenliveSettings::disable_effect_parameters()) {
204 widgetFrame->setEnabled(enable);
206 emit effectStateChanged(!enable, m_paramWidget->index());
209 void CollapsibleEffect::slotDeleteEffect()
211 emit deleteEffect(m_effect, m_paramWidget->index());
214 void CollapsibleEffect::slotEffectUp()
216 emit changeEffectPosition(m_paramWidget->index(), true);
219 void CollapsibleEffect::slotEffectDown()
221 emit changeEffectPosition(m_paramWidget->index(), false);
224 void CollapsibleEffect::slotSwitch()
226 bool enable = !widgetFrame->isVisible();
230 void CollapsibleEffect::slotShow(bool show)
232 widgetFrame->setVisible(show);
234 collapseButton->setArrowType(Qt::DownArrow);
235 m_original_effect.removeAttribute("k_collapsed");
238 collapseButton->setArrowType(Qt::RightArrow);
239 m_original_effect.setAttribute("k_collapsed", 1);
244 void CollapsibleEffect::setupWidget(ItemInfo info, int index, EffectMetaInfo *metaInfo)
246 if (m_effect.isNull()) {
247 // kDebug() << "// EMPTY EFFECT STACK";
250 if (m_effect.attribute("tag") == "region") {
251 QVBoxLayout *vbox = new QVBoxLayout(widgetFrame);
252 vbox->setContentsMargins(0, 0, 0, 0);
254 QDomNodeList effects = m_effect.elementsByTagName("effect");
255 QDomNodeList origin_effects = m_original_effect.elementsByTagName("effect");
256 QWidget *container = new QWidget(widgetFrame);
257 vbox->addWidget(container);
258 m_paramWidget = new ParameterContainer(m_effect.toElement(), info, metaInfo, index, container);
259 for (int i = 0; i < effects.count(); i++) {
260 CollapsibleEffect *coll = new CollapsibleEffect(effects.at(i).toElement(), origin_effects.at(i).toElement(), info, i, metaInfo, container);
261 m_subParamWidgets.append(coll);
262 //container = new QWidget(widgetFrame);
263 vbox->addWidget(coll);
264 //p = new ParameterContainer(effects.at(i).toElement(), info, isEffect, container);
269 m_paramWidget = new ParameterContainer(m_effect, info, metaInfo, index, widgetFrame);
270 if (m_effect.firstChildElement("parameter").isNull()) {
271 // Effect has no parameter, don't allow expand
272 collapseButton->setEnabled(false);
273 widgetFrame->setVisible(false);
276 if (collapseButton->isEnabled()) slotShow(!m_effect.hasAttribute("k_collapsed"));
277 connect (m_paramWidget, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)));
278 connect (this, SIGNAL(syncEffectsPos(int)), m_paramWidget, SIGNAL(syncEffectsPos(int)));
279 connect (this, SIGNAL(effectStateChanged(bool)), m_paramWidget, SIGNAL(effectStateChanged(bool)));
280 connect (m_paramWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
281 connect (m_paramWidget, SIGNAL(seekTimeline(int)), this, SIGNAL(seekTimeline(int)));
286 void CollapsibleEffect::updateTimecodeFormat()
288 m_paramWidget->updateTimecodeFormat();
289 if (!m_subParamWidgets.isEmpty()) {
291 for (int i = 0; i < m_subParamWidgets.count(); i++)
292 m_subParamWidgets.at(i)->updateTimecodeFormat();
296 void CollapsibleEffect::slotSyncEffectsPos(int pos)
298 emit syncEffectsPos(pos);
303 ParameterContainer::ParameterContainer(QDomElement effect, ItemInfo info, EffectMetaInfo *metaInfo, int index, QWidget * parent) :
305 m_keyframeEditor(NULL),
306 m_geometryWidget(NULL),
307 m_metaInfo(metaInfo),
310 m_in = info.cropStart.frames(KdenliveSettings::project_fps());
311 m_out = (info.cropStart + info.cropDuration).frames(KdenliveSettings::project_fps()) - 1;
313 QDomNodeList namenode = effect.childNodes(); //elementsByTagName("parameter");
315 QDomElement e = effect.toElement();
316 int minFrame = e.attribute("start").toInt();
317 int maxFrame = e.attribute("end").toInt();
318 // In transitions, maxFrame is in fact one frame after the end of transition
319 if (maxFrame > 0) maxFrame --;
321 bool disable = effect.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
322 parent->setEnabled(!disable);
325 m_vbox = new QVBoxLayout(parent);
326 m_vbox->setContentsMargins(0, 0, 0, 0);
327 m_vbox->setSpacing(2);
329 for (int i = 0; i < namenode.count() ; i++) {
330 QDomElement pa = namenode.item(i).toElement();
331 if (pa.tagName() != "parameter") continue;
332 QDomElement na = pa.firstChildElement("name");
333 QDomElement commentElem = pa.firstChildElement("comment");
334 QString type = pa.attribute("type");
335 QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
337 if (!commentElem.isNull())
338 comment = i18n(commentElem.text().toUtf8().data());
339 QWidget * toFillin = new QWidget(parent);
340 QString value = pa.attribute("value").isNull() ?
341 pa.attribute("default") : pa.attribute("value");
344 /** See effects/README for info on the different types */
346 if (type == "double" || type == "constant") {
349 if (pa.attribute("min").contains('%'))
350 min = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("min"), m_metaInfo->frameSize);
352 min = pa.attribute("min").toDouble();
353 if (pa.attribute("max").contains('%'))
354 max = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("max"), m_metaInfo->frameSize);
356 max = pa.attribute("max").toDouble();
358 DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, value.toDouble(), min, max,
359 pa.attribute("default").toDouble(), comment, -1, pa.attribute("suffix"), pa.attribute("decimals").toInt(), parent);
360 m_vbox->addWidget(doubleparam);
361 m_valueItems[paramName] = doubleparam;
362 connect(doubleparam, SIGNAL(valueChanged(double)), this, SLOT(slotCollectAllParameters()));
363 connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
364 } else if (type == "list") {
365 Listval *lsval = new Listval;
366 lsval->setupUi(toFillin);
367 QStringList listitems = pa.attribute("paramlist").split(';');
368 if (listitems.count() == 1) {
369 // probably custom effect created before change to ';' as separator
370 listitems = pa.attribute("paramlist").split(",");
372 QDomElement list = pa.firstChildElement("paramlistdisplay");
373 QStringList listitemsdisplay;
374 if (!list.isNull()) {
375 listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
377 listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
379 if (listitemsdisplay.count() != listitems.count())
380 listitemsdisplay = listitems;
381 lsval->list->setIconSize(QSize(30, 30));
382 for (int i = 0; i < listitems.count(); i++) {
383 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
384 QString entry = listitems.at(i);
385 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
386 if (!CollapsibleEffect::iconCache.contains(entry)) {
388 CollapsibleEffect::iconCache[entry] = pix.scaled(30, 30);
390 lsval->list->setItemIcon(i, QPixmap::fromImage(CollapsibleEffect::iconCache[entry]));
393 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
394 lsval->name->setText(paramName);
395 lsval->labelComment->setText(comment);
396 lsval->widgetComment->setHidden(true);
397 m_valueItems[paramName] = lsval;
398 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(slotCollectAllParameters()));
399 if (!comment.isEmpty())
400 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
401 m_uiItems.append(lsval);
402 } else if (type == "bool") {
403 Boolval *bval = new Boolval;
404 bval->setupUi(toFillin);
405 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
406 bval->name->setText(paramName);
407 bval->labelComment->setText(comment);
408 bval->widgetComment->setHidden(true);
409 m_valueItems[paramName] = bval;
410 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(slotCollectAllParameters()));
411 if (!comment.isEmpty())
412 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
413 m_uiItems.append(bval);
414 } else if (type == "complex") {
415 ComplexParameter *pl = new ComplexParameter;
416 pl->setupParam(effect, pa.attribute("name"), 0, 100);
417 m_vbox->addWidget(pl);
418 m_valueItems[paramName+"complex"] = pl;
419 connect(pl, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
420 } else if (type == "geometry") {
421 if (KdenliveSettings::on_monitor_effects()) {
422 m_geometryWidget = new GeometryWidget(m_metaInfo->monitor, m_metaInfo->timecode, 0, true, effect.hasAttribute("showrotation"), parent);
423 m_geometryWidget->setFrameSize(m_metaInfo->frameSize);
424 m_geometryWidget->slotShowScene(!disable);
425 // connect this before setupParam to make sure the monitor scene shows up at startup
426 connect(m_geometryWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
427 connect(m_geometryWidget, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
428 if (minFrame == maxFrame)
429 m_geometryWidget->setupParam(pa, m_in, m_out);
431 m_geometryWidget->setupParam(pa, minFrame, maxFrame);
432 m_vbox->addWidget(m_geometryWidget);
433 m_valueItems[paramName+"geometry"] = m_geometryWidget;
434 connect(m_geometryWidget, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
435 connect(this, SIGNAL(syncEffectsPos(int)), m_geometryWidget, SLOT(slotSyncPosition(int)));
436 connect(this, SIGNAL(effectStateChanged(bool)), m_geometryWidget, SLOT(slotShowScene(bool)));
438 Geometryval *geo = new Geometryval(m_metaInfo->profile, m_metaInfo->timecode, m_metaInfo->frameSize, 0);
439 if (minFrame == maxFrame)
440 geo->setupParam(pa, m_in, m_out);
442 geo->setupParam(pa, minFrame, maxFrame);
443 m_vbox->addWidget(geo);
444 m_valueItems[paramName+"geometry"] = geo;
445 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
446 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
447 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
449 } else if (type == "addedgeometry") {
450 // this is a parameter that should be linked to the geometry widget, for example rotation, shear, ...
451 if (m_geometryWidget) m_geometryWidget->addParameter(pa);
452 } else if (type == "keyframe" || type == "simplekeyframe") {
453 // keyframe editor widget
454 if (m_keyframeEditor == NULL) {
456 if (pa.attribute("widget") == "corners") {
457 // we want a corners-keyframe-widget
458 CornersWidget *corners = new CornersWidget(m_metaInfo->monitor, pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt(), parent);
459 corners->slotShowScene(!disable);
460 connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
461 connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
462 connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
463 geo = static_cast<KeyframeEdit *>(corners);
465 geo = new KeyframeEdit(pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt());
467 m_vbox->addWidget(geo);
468 m_valueItems[paramName+"keyframe"] = geo;
469 m_keyframeEditor = geo;
470 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
471 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
472 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
474 // we already have a keyframe editor, so just add another column for the new param
475 m_keyframeEditor->addParameter(pa);
477 } else if (type == "color") {
478 if (value.startsWith('#'))
479 value = value.replace('#', "0x");
480 ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, value, parent);
481 m_vbox->addWidget(choosecolor);
482 m_valueItems[paramName] = choosecolor;
483 connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
484 connect(choosecolor, SIGNAL(modified()) , this, SLOT(slotCollectAllParameters()));
485 } else if (type == "position") {
486 int pos = value.toInt();
487 if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
489 } else if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
490 // fadeout position starts from clip end
493 PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_metaInfo->timecode);
494 m_vbox->addWidget(posedit);
495 m_valueItems[paramName+"position"] = posedit;
496 connect(posedit, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
497 } else if (type == "curve") {
498 KisCurveWidget *curve = new KisCurveWidget(parent);
499 curve->setMaxPoints(pa.attribute("max").toInt());
500 QList<QPointF> points;
501 int number = EffectsList::parameter(e, pa.attribute("number")).toInt();
502 QString inName = pa.attribute("inpoints");
503 QString outName = pa.attribute("outpoints");
504 int start = pa.attribute("min").toInt();
505 for (int j = start; j <= number; j++) {
507 in.replace("%i", QString::number(j));
508 QString out = outName;
509 out.replace("%i", QString::number(j));
510 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
512 if (!points.isEmpty())
513 curve->setCurve(KisCubicCurve(points));
514 QSpinBox *spinin = new QSpinBox();
515 spinin->setRange(0, 1000);
516 QSpinBox *spinout = new QSpinBox();
517 spinout->setRange(0, 1000);
518 curve->setupInOutControls(spinin, spinout, 0, 1000);
519 m_vbox->addWidget(curve);
520 m_vbox->addWidget(spinin);
521 m_vbox->addWidget(spinout);
523 connect(curve, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
524 m_valueItems[paramName] = curve;
526 QString depends = pa.attribute("depends");
527 if (!depends.isEmpty())
528 meetDependency(paramName, type, EffectsList::parameter(e, depends));
529 } else if (type == "bezier_spline") {
530 BezierSplineWidget *widget = new BezierSplineWidget(value, parent);
532 m_vbox->addWidget(widget);
533 m_valueItems[paramName] = widget;
534 connect(widget, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
535 QString depends = pa.attribute("depends");
536 if (!depends.isEmpty())
537 meetDependency(paramName, type, EffectsList::parameter(e, depends));
539 } else if (type == "roto-spline") {
540 RotoWidget *roto = new RotoWidget(value, m_metaInfo->monitor, info, m_metaInfo->timecode, parent);
541 roto->slotShowScene(!disable);
542 connect(roto, SIGNAL(valueChanged()), this, SLOT(slotCollectAllParameters()));
543 connect(roto, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
544 connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
545 connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
546 connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
547 m_vbox->addWidget(roto);
548 m_valueItems[paramName] = roto;
550 } else if (type == "wipe") {
551 Wipeval *wpval = new Wipeval;
552 wpval->setupUi(toFillin);
553 wipeInfo w = getWipeInfo(value);
556 wpval->start_up->setChecked(true);
559 wpval->start_down->setChecked(true);
562 wpval->start_right->setChecked(true);
565 wpval->start_left->setChecked(true);
568 wpval->start_center->setChecked(true);
573 wpval->end_up->setChecked(true);
576 wpval->end_down->setChecked(true);
579 wpval->end_right->setChecked(true);
582 wpval->end_left->setChecked(true);
585 wpval->end_center->setChecked(true);
588 wpval->start_transp->setValue(w.startTransparency);
589 wpval->end_transp->setValue(w.endTransparency);
590 m_valueItems[paramName] = wpval;
591 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
592 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
593 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
594 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
595 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
596 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
597 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
598 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
599 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
600 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
601 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
602 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
603 //wpval->title->setTitle(na.toElement().text());
604 m_uiItems.append(wpval);
605 } else if (type == "url") {
606 Urlval *cval = new Urlval;
607 cval->setupUi(toFillin);
608 cval->label->setText(paramName);
609 cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
610 m_valueItems[paramName] = cval;
611 cval->urlwidget->setUrl(KUrl(value));
612 connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(slotCollectAllParameters()));
613 connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(slotCollectAllParameters()));
614 m_uiItems.append(cval);
621 m_vbox->addWidget(toFillin);
625 m_vbox->addStretch();
627 if (m_keyframeEditor)
628 m_keyframeEditor->checkVisibleParam();
630 // Make sure all doubleparam spinboxes have the same width, looks much better
631 QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
633 for (int i = 0; i < allWidgets.count(); i++) {
634 if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
636 for (int i = 0; i < allWidgets.count(); i++) {
637 allWidgets.at(i)->setSpinSize(minSize);
641 ParameterContainer::~ParameterContainer()
647 void ParameterContainer::meetDependency(const QString& name, QString type, QString value)
649 if (type == "curve") {
650 KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
652 int color = value.toInt();
653 curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
655 } else if (type == "bezier_spline") {
656 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
658 widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10)));
663 wipeInfo ParameterContainer::getWipeInfo(QString value)
666 // Convert old geometry values that used a comma as separator
667 if (value.contains(',')) value.replace(',','/');
668 QString start = value.section(';', 0, 0);
669 QString end = value.section(';', 1, 1).section('=', 1, 1);
670 if (start.startsWith("-100%/0"))
672 else if (start.startsWith("100%/0"))
674 else if (start.startsWith("0%/100%"))
676 else if (start.startsWith("0%/-100%"))
681 if (start.count(':') == 2)
682 info.startTransparency = start.section(':', -1).toInt();
684 info.startTransparency = 100;
686 if (end.startsWith("-100%/0"))
688 else if (end.startsWith("100%/0"))
690 else if (end.startsWith("0%/100%"))
692 else if (end.startsWith("0%/-100%"))
697 if (end.count(':') == 2)
698 info.endTransparency = end.section(':', -1).toInt();
700 info.endTransparency = 100;
705 void ParameterContainer::updateTimecodeFormat()
707 if (m_keyframeEditor)
708 m_keyframeEditor->updateTimecodeFormat();
710 QDomNodeList namenode = m_effect.elementsByTagName("parameter");
711 for (int i = 0; i < namenode.count() ; i++) {
712 QDomNode pa = namenode.item(i);
713 QDomElement na = pa.firstChildElement("name");
714 QString type = pa.attributes().namedItem("type").nodeValue();
715 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
717 if (type == "geometry") {
718 if (KdenliveSettings::on_monitor_effects()) {
719 if (m_geometryWidget) m_geometryWidget->updateTimecodeFormat();
721 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
722 geom->updateTimecodeFormat();
725 } else if (type == "position") {
726 PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
727 posi->updateTimecodeFormat();
730 } else if (type == "roto-spline") {
731 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems[paramName]);
732 widget->updateTimecodeFormat();
738 void ParameterContainer::slotCollectAllParameters()
740 if (m_valueItems.isEmpty() || m_effect.isNull()) return;
742 locale.setNumberOptions(QLocale::OmitGroupSeparator);
743 const QDomElement oldparam = m_effect.cloneNode().toElement();
744 QDomElement newparam = oldparam.cloneNode().toElement();
745 QDomNodeList namenode = newparam.elementsByTagName("parameter");
747 for (int i = 0; i < namenode.count() ; i++) {
748 QDomNode pa = namenode.item(i);
749 QDomElement na = pa.firstChildElement("name");
750 QString type = pa.attributes().namedItem("type").nodeValue();
751 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
752 if (type == "complex")
753 paramName.append("complex");
754 else if (type == "position")
755 paramName.append("position");
756 else if (type == "geometry")
757 paramName.append("geometry");
758 else if (type == "keyframe")
759 paramName.append("keyframe");
760 if (type != "simplekeyframe" && type != "fixed" && type != "addedgeometry" && !m_valueItems.contains(paramName)) {
761 kDebug() << "// Param: " << paramName << " NOT FOUND";
766 if (type == "double" || type == "constant") {
767 DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
768 setValue = locale.toString(doubleparam->getValue());
769 } else if (type == "list") {
770 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
771 setValue = box->itemData(box->currentIndex()).toString();
772 } else if (type == "bool") {
773 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
774 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
775 } else if (type == "color") {
776 ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
777 setValue = choosecolor->getColor();
778 } else if (type == "complex") {
779 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
780 namenode.item(i) = complex->getParamDesc();
781 } else if (type == "geometry") {
782 if (KdenliveSettings::on_monitor_effects()) {
783 if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getValue());
785 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
786 namenode.item(i).toElement().setAttribute("value", geom->getValue());
788 } else if (type == "addedgeometry") {
789 namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getExtraValue(namenode.item(i).toElement().attribute("name")));
790 } else if (type == "position") {
791 PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
792 int pos = pedit->getPosition();
793 setValue = QString::number(pos);
794 if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_black") {
795 // Make sure duration is not longer than clip
798 pedit->setPosition(pos);
800 EffectsList::setParameter(newparam, "in", QString::number(m_in));
801 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
803 } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
804 // Make sure duration is not longer than clip
807 pedit->setPosition(pos);
809 EffectsList::setParameter(newparam, "in", QString::number(m_out - pos));
810 EffectsList::setParameter(newparam, "out", QString::number(m_out));
813 } else if (type == "curve") {
814 KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
815 QList<QPointF> points = curve->curve().points();
816 QString number = pa.attributes().namedItem("number").nodeValue();
817 QString inName = pa.attributes().namedItem("inpoints").nodeValue();
818 QString outName = pa.attributes().namedItem("outpoints").nodeValue();
819 int off = pa.attributes().namedItem("min").nodeValue().toInt();
820 int end = pa.attributes().namedItem("max").nodeValue().toInt();
821 EffectsList::setParameter(newparam, number, QString::number(points.count()));
822 for (int j = 0; (j < points.count() && j + off <= end); j++) {
824 in.replace("%i", QString::number(j + off));
825 QString out = outName;
826 out.replace("%i", QString::number(j + off));
827 EffectsList::setParameter(newparam, in, locale.toString(points.at(j).x()));
828 EffectsList::setParameter(newparam, out, locale.toString(points.at(j).y()));
830 QString depends = pa.attributes().namedItem("depends").nodeValue();
831 if (!depends.isEmpty())
832 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
833 } else if (type == "bezier_spline") {
834 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
835 setValue = widget->spline();
836 QString depends = pa.attributes().namedItem("depends").nodeValue();
837 if (!depends.isEmpty())
838 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
840 } else if (type == "roto-spline") {
841 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
842 setValue = widget->getSpline();
844 } else if (type == "wipe") {
845 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
847 if (wp->start_left->isChecked())
849 else if (wp->start_right->isChecked())
851 else if (wp->start_up->isChecked())
853 else if (wp->start_down->isChecked())
855 else if (wp->start_center->isChecked())
859 info.startTransparency = wp->start_transp->value();
861 if (wp->end_left->isChecked())
863 else if (wp->end_right->isChecked())
865 else if (wp->end_up->isChecked())
867 else if (wp->end_down->isChecked())
869 else if (wp->end_center->isChecked())
873 info.endTransparency = wp->end_transp->value();
875 setValue = getWipeString(info);
876 } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
877 QDomElement elem = pa.toElement();
878 QString realName = i18n(na.toElement().text().toUtf8().data());
879 QString val = m_keyframeEditor->getValue(realName);
880 elem.setAttribute("keyframes", val);
882 if (m_keyframeEditor->isVisibleParam(realName))
883 elem.setAttribute("intimeline", "1");
884 else if (elem.hasAttribute("intimeline"))
885 elem.removeAttribute("intimeline");
886 } else if (type == "url") {
887 KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
888 setValue = req->url().path();
891 if (!setValue.isNull())
892 pa.attributes().namedItem("value").setNodeValue(setValue);
895 emit parameterChanged(oldparam, newparam, m_index);
898 QString ParameterContainer::getWipeString(wipeInfo info)
903 switch (info.start) {
905 start = "-100%/0%:100%x100%";
908 start = "100%/0%:100%x100%";
911 start = "0%/100%:100%x100%";
914 start = "0%/-100%:100%x100%";
917 start = "0%/0%:100%x100%";
920 start.append(':' + QString::number(info.startTransparency));
924 end = "-100%/0%:100%x100%";
927 end = "100%/0%:100%x100%";
930 end = "0%/100%:100%x100%";
933 end = "0%/-100%:100%x100%";
936 end = "0%/0%:100%x100%";
939 end.append(':' + QString::number(info.endTransparency));
940 return QString(start + ";-1=" + end);
943 int ParameterContainer::index()