1 /***************************************************************************
2 effecstackedit.cpp - description
5 copyright : (C) 2008 by Marco Gittler
6 email : g.marco@freenet.de
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #include "effectstackedit.h"
19 #include "ui_listval_ui.h"
20 #include "ui_boolval_ui.h"
21 #include "ui_wipeval_ui.h"
22 #include "ui_urlval_ui.h"
23 #include "ui_keywordval_ui.h"
24 #include "ui_fontval_ui.h"
25 #include "complexparameter.h"
26 #include "geometryval.h"
27 #include "positionedit.h"
28 #include "projectlist.h"
29 #include "effectslist.h"
30 #include "kdenlivesettings.h"
31 #include "profilesdialog.h"
32 #include "kis_curve_widget.h"
33 #include "kis_cubic_curve.h"
34 #include "choosecolorwidget.h"
35 #include "geometrywidget.h"
36 #include "colortools.h"
37 #include "doubleparameterwidget.h"
38 #include "cornerswidget.h"
39 #include "beziercurve/beziersplinewidget.h"
41 #include "rotoscoping/rotowidget.h"
46 #include <KFileDialog>
47 #include <KColorScheme>
49 #include <QVBoxLayout>
51 #include <QPushButton>
53 #include <QScrollArea>
55 // For QDomNode debugging (output into files); leaving here as sample code.
59 class Boolval: public QWidget, public Ui::Boolval_UI
63 class Listval: public QWidget, public Ui::Listval_UI
67 class Wipeval: public QWidget, public Ui::Wipeval_UI
71 class Urlval: public QWidget, public Ui::Urlval_UI
75 class Keywordval: public QWidget, public Ui::Keywordval_UI
79 class Fontval: public QWidget, public Ui::Fontval_UI
83 QMap<QString, QImage> EffectStackEdit::iconCache;
85 EffectStackEdit::EffectStackEdit(Monitor *monitor, QWidget *parent) :
89 m_frameSize(QPoint()),
90 m_keyframeEditor(NULL),
92 m_geometryWidget(NULL)
94 m_baseWidget = new QWidget(this);
95 setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
96 setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
97 setFrameStyle(QFrame::NoFrame);
98 setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
100 QPalette p = palette();
101 KColorScheme scheme(p.currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
102 QColor dark_bg = scheme.shade(KColorScheme::DarkShade);
103 QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
104 QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
105 QColor light_bg = scheme.shade(KColorScheme::LightShade);
107 QString stylesheet(QString("QProgressBar:horizontal {border: 1px solid %1;border-radius:0px;border-top-left-radius: 4px;border-bottom-left-radius: 4px;border-right: 0px;background:%4;padding: 0px;text-align:left center}\
108 QProgressBar:horizontal#dragOnly {background: %1} QProgressBar:horizontal:hover#dragOnly {background: %3} QProgressBar:horizontal:hover {border: 1px solid %3;border-right: 0px;}\
109 QProgressBar::chunk:horizontal {background: %1;} QProgressBar::chunk:horizontal:hover {background: %3;}\
110 QProgressBar:horizontal[inTimeline=\"true\"] { border: 1px solid %2;border-right: 0px;background: %4;padding: 0px;text-align:left center } QProgressBar::chunk:horizontal[inTimeline=\"true\"] {background: %2;}\
111 QAbstractSpinBox#dragBox {border: 1px solid %1;border-top-right-radius: 4px;border-bottom-right-radius: 4px;padding-right:0px;} QAbstractSpinBox::down-button#dragBox {width:0px;padding:0px;}\
112 QAbstractSpinBox::up-button#dragBox {width:0px;padding:0px;} QAbstractSpinBox[inTimeline=\"true\"]#dragBox { border: 1px solid %2;} QAbstractSpinBox:hover#dragBox {border: 1px solid %3;} ")
113 .arg(dark_bg.name()).arg(selected_bg.name()).arg(hover_bg.name()).arg(light_bg.name()));
114 setStyleSheet(stylesheet);
116 setWidget(m_baseWidget);
117 setWidgetResizable(true);
118 m_vbox = new QVBoxLayout(m_baseWidget);
119 m_vbox->setContentsMargins(0, 0, 0, 0);
120 m_vbox->setSpacing(2);
123 EffectStackEdit::~EffectStackEdit()
129 void EffectStackEdit::setFrameSize(QPoint p)
132 QDomNodeList namenode = m_params.elementsByTagName("parameter");
133 for (int i = 0; i < namenode.count() ; i++) {
134 QDomNode pa = namenode.item(i);
135 QDomElement na = pa.firstChildElement("name");
136 QString type = pa.attributes().namedItem("type").nodeValue();
137 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
139 if (type == "geometry") {
140 if (!KdenliveSettings::on_monitor_effects()) {
141 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
142 geom->setFrameSize(m_frameSize);
146 if (m_geometryWidget) m_geometryWidget->setFrameSize(m_frameSize);
153 void EffectStackEdit::updateTimecodeFormat()
155 if (m_keyframeEditor)
156 m_keyframeEditor->updateTimecodeFormat();
158 QDomNodeList namenode = m_params.elementsByTagName("parameter");
159 for (int i = 0; i < namenode.count() ; i++) {
160 QDomNode pa = namenode.item(i);
161 QDomElement na = pa.firstChildElement("name");
162 QString type = pa.attributes().namedItem("type").nodeValue();
163 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
165 if (type == "geometry") {
166 if (KdenliveSettings::on_monitor_effects()) {
167 if (m_geometryWidget) m_geometryWidget->updateTimecodeFormat();
169 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
170 geom->updateTimecodeFormat();
173 } else if (type == "position") {
174 PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
175 posi->updateTimecodeFormat();
177 } else if (type == "roto-spline") {
178 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems[paramName]);
179 widget->updateTimecodeFormat();
184 void EffectStackEdit::meetDependency(const QString& name, QString type, QString value)
186 if (type == "curve") {
187 KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
189 int color = value.toInt();
190 curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
192 } else if (type == "bezier_spline") {
193 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
195 widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10)));
200 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
206 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
208 m_params.setAttribute(name, value);
210 if (name == "disable") {
211 // if effect is disabled, disable parameters widget
212 bool enabled = value.toInt() == 0 || !KdenliveSettings::disable_effect_parameters();
214 emit effectStateChanged(enabled);
218 void EffectStackEdit::transferParamDesc(const QDomElement &d, ItemInfo info, bool isEffect)
221 if (m_keyframeEditor) delete m_keyframeEditor;
222 m_keyframeEditor = NULL;
224 m_in = isEffect ? info.cropStart.frames(KdenliveSettings::project_fps()) : info.startPos.frames(KdenliveSettings::project_fps());
225 m_out = isEffect ? (info.cropStart + info.cropDuration).frames(KdenliveSettings::project_fps()) - 1 : info.endPos.frames(KdenliveSettings::project_fps());
226 if (m_params.isNull()) {
227 // kDebug() << "// EMPTY EFFECT STACK";
231 QDomNodeList namenode = m_params.elementsByTagName("parameter");
233 QFile debugFile("/tmp/namenodes.txt");
234 if (debugFile.open(QFile::WriteOnly | QFile::Truncate)) {
235 QTextStream out(&debugFile);
236 QTextStream out2(stdout);
237 for (int i = 0; i < namenode.size(); i++) {
239 namenode.at(i).save(out, 2);
241 namenode.at(i).save(out2, 2);
245 int minFrame = d.attribute("start").toInt();
246 int maxFrame = d.attribute("end").toInt();
247 // In transitions, maxFrame is in fact one frame after the end of transition
248 if (maxFrame > 0) maxFrame --;
250 bool disable = d.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
251 setEnabled(!disable);
256 for (int i = 0; i < namenode.count() ; i++) {
257 QDomElement pa = namenode.item(i).toElement();
258 QDomElement na = pa.firstChildElement("name");
259 QDomElement commentElem = pa.firstChildElement("comment");
260 QString type = pa.attribute("type");
261 QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
263 if (!commentElem.isNull())
264 comment = i18n(commentElem.text().toUtf8().data());
265 QWidget * toFillin = new QWidget(m_baseWidget);
266 QString value = pa.attribute("value").isNull() ?
267 pa.attribute("default") : pa.attribute("value");
270 /** See effects/README for info on the different types */
272 if (type == "double" || type == "constant") {
275 if (pa.attribute("min").contains('%'))
276 min = ProfilesDialog::getStringEval(m_profile, pa.attribute("min"), m_frameSize);
278 min = pa.attribute("min").toDouble();
279 if (pa.attribute("max").contains('%'))
280 max = ProfilesDialog::getStringEval(m_profile, pa.attribute("max"), m_frameSize);
282 max = pa.attribute("max").toDouble();
284 DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, value.toDouble(), min, max,
285 pa.attribute("default").toDouble(), comment, -1, pa.attribute("suffix"), pa.attribute("decimals").toInt(), this);
286 m_vbox->addWidget(doubleparam);
287 m_valueItems[paramName] = doubleparam;
288 connect(doubleparam, SIGNAL(valueChanged(double)), this, SLOT(collectAllParameters()));
289 connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
290 } else if (type == "list") {
291 Listval *lsval = new Listval;
292 lsval->setupUi(toFillin);
293 QStringList listitems = pa.attribute("paramlist").split(';');
294 if (listitems.count() == 1) {
295 // probably custom effect created before change to ';' as separator
296 listitems = pa.attribute("paramlist").split(',');
298 QDomElement list = pa.firstChildElement("paramlistdisplay");
299 QStringList listitemsdisplay;
300 if (!list.isNull()) {
301 listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
303 listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
305 if (listitemsdisplay.count() != listitems.count())
306 listitemsdisplay = listitems;
307 lsval->list->setIconSize(QSize(30, 30));
308 for (int i = 0; i < listitems.count(); i++) {
309 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
310 QString entry = listitems.at(i);
311 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
312 if (!EffectStackEdit::iconCache.contains(entry)) {
314 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
316 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
319 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
320 lsval->name->setText(paramName);
321 lsval->labelComment->setText(comment);
322 lsval->widgetComment->setHidden(true);
323 m_valueItems[paramName] = lsval;
324 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
325 if (!comment.isEmpty())
326 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
327 m_uiItems.append(lsval);
328 } else if (type == "bool") {
329 Boolval *bval = new Boolval;
330 bval->setupUi(toFillin);
331 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
332 bval->name->setText(paramName);
333 bval->labelComment->setText(comment);
334 bval->widgetComment->setHidden(true);
335 m_valueItems[paramName] = bval;
336 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
337 if (!comment.isEmpty())
338 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
339 m_uiItems.append(bval);
340 } else if (type == "complex") {
341 ComplexParameter *pl = new ComplexParameter;
342 pl->setupParam(d, pa.attribute("name"), 0, 100);
343 m_vbox->addWidget(pl);
344 m_valueItems[paramName+"complex"] = pl;
345 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
346 } else if (type == "geometry") {
347 if (KdenliveSettings::on_monitor_effects()) {
348 m_geometryWidget = new GeometryWidget(m_monitor, m_timecode, isEffect ? 0 : qMax(0, (int)info.startPos.frames(KdenliveSettings::project_fps())), isEffect, m_params.hasAttribute("showrotation"), this);
349 m_geometryWidget->setFrameSize(m_frameSize);
350 m_geometryWidget->slotShowScene(!disable);
351 // connect this before setupParam to make sure the monitor scene shows up at startup
352 connect(m_geometryWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
353 connect(m_geometryWidget, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
354 if (minFrame == maxFrame)
355 m_geometryWidget->setupParam(pa, m_in, m_out);
357 m_geometryWidget->setupParam(pa, minFrame, maxFrame);
358 m_vbox->addWidget(m_geometryWidget);
359 m_valueItems[paramName+"geometry"] = m_geometryWidget;
360 connect(m_geometryWidget, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
361 connect(this, SIGNAL(syncEffectsPos(int)), m_geometryWidget, SLOT(slotSyncPosition(int)));
362 connect(this, SIGNAL(effectStateChanged(bool)), m_geometryWidget, SLOT(slotShowScene(bool)));
364 Geometryval *geo = new Geometryval(m_profile, m_timecode, m_frameSize, isEffect ? 0 : qMax(0, (int)info.startPos.frames(KdenliveSettings::project_fps())));
365 if (minFrame == maxFrame)
366 geo->setupParam(pa, m_in, m_out);
368 geo->setupParam(pa, minFrame, maxFrame);
369 m_vbox->addWidget(geo);
370 m_valueItems[paramName+"geometry"] = geo;
371 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
372 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
373 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
375 } else if (type == "addedgeometry") {
376 // this is a parameter that should be linked to the geometry widget, for example rotation, shear, ...
377 if (m_geometryWidget) m_geometryWidget->addParameter(pa);
378 } else if (type == "keyframe" || type == "simplekeyframe") {
379 // keyframe editor widget
380 if (m_keyframeEditor == NULL) {
382 if (pa.attribute("widget") == "corners") {
383 // we want a corners-keyframe-widget
384 CornersWidget *corners = new CornersWidget(m_monitor, pa, m_in, m_out, m_timecode, d.attribute("active_keyframe", "-1").toInt(), this);
385 corners->slotShowScene(!disable);
386 connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
387 connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool)));
388 connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
389 geo = static_cast<KeyframeEdit *>(corners);
391 geo = new KeyframeEdit(pa, m_in, m_out, m_timecode, d.attribute("active_keyframe", "-1").toInt());
393 m_vbox->addWidget(geo);
394 m_valueItems[paramName+"keyframe"] = geo;
395 m_keyframeEditor = geo;
396 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
397 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
398 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
400 // we already have a keyframe editor, so just add another column for the new param
401 m_keyframeEditor->addParameter(pa);
403 } else if (type == "color") {
404 ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, value, this);
405 choosecolor->setAlphaChannelEnabled(pa.attribute("alpha") == "1");
406 m_vbox->addWidget(choosecolor);
407 m_valueItems[paramName] = choosecolor;
408 connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
409 connect(choosecolor, SIGNAL(modified()) , this, SLOT(collectAllParameters()));
410 } else if (type == "position") {
411 int pos = value.toInt();
412 if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
414 } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
415 // fadeout position starts from clip end
418 PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_timecode);
419 m_vbox->addWidget(posedit);
420 m_valueItems[paramName+"position"] = posedit;
421 connect(posedit, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
422 } else if (type == "curve") {
423 KisCurveWidget *curve = new KisCurveWidget(this);
424 curve->setMaxPoints(pa.attribute("max").toInt());
425 QList<QPointF> points;
427 if (d.attribute("version").toDouble() > 0.2) {
428 number = EffectsList::parameter(d, pa.attribute("number")).toDouble() * 10;
430 number = EffectsList::parameter(d, pa.attribute("number")).toInt();
432 QString inName = pa.attribute("inpoints");
433 QString outName = pa.attribute("outpoints");
434 int start = pa.attribute("min").toInt();
435 for (int j = start; j <= number; j++) {
437 in.replace("%i", QString::number(j));
438 QString out = outName;
439 out.replace("%i", QString::number(j));
440 points << QPointF(EffectsList::parameter(d, in).toDouble(), EffectsList::parameter(d, out).toDouble());
442 if (!points.isEmpty())
443 curve->setCurve(KisCubicCurve(points));
444 QSpinBox *spinin = new QSpinBox();
445 spinin->setRange(0, 1000);
446 QSpinBox *spinout = new QSpinBox();
447 spinout->setRange(0, 1000);
448 curve->setupInOutControls(spinin, spinout, 0, 1000);
449 m_vbox->addWidget(curve);
450 m_vbox->addWidget(spinin);
451 m_vbox->addWidget(spinout);
453 connect(curve, SIGNAL(modified()), this, SLOT(collectAllParameters()));
454 m_valueItems[paramName] = curve;
456 QString depends = pa.attribute("depends");
457 if (!depends.isEmpty())
458 meetDependency(paramName, type, EffectsList::parameter(d, depends));
459 } else if (type == "bezier_spline") {
460 BezierSplineWidget *widget = new BezierSplineWidget(value, this);
462 m_vbox->addWidget(widget);
463 m_valueItems[paramName] = widget;
464 connect(widget, SIGNAL(modified()), this, SLOT(collectAllParameters()));
465 QString depends = pa.attribute("depends");
466 if (!depends.isEmpty())
467 meetDependency(paramName, type, EffectsList::parameter(d, depends));
469 } else if (type == "roto-spline") {
470 RotoWidget *roto = new RotoWidget(value, m_monitor, info, m_timecode, this);
471 roto->slotShowScene(!disable);
472 connect(roto, SIGNAL(valueChanged()), this, SLOT(collectAllParameters()));
473 connect(roto, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
474 connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
475 connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
476 connect(this, SIGNAL(effectStateChanged(bool)), roto, SLOT(slotShowScene(bool)));
477 m_vbox->addWidget(roto);
478 m_valueItems[paramName] = roto;
480 } else if (type == "wipe") {
481 Wipeval *wpval = new Wipeval;
482 wpval->setupUi(toFillin);
483 wipeInfo w = getWipeInfo(value);
486 wpval->start_up->setChecked(true);
489 wpval->start_down->setChecked(true);
492 wpval->start_right->setChecked(true);
495 wpval->start_left->setChecked(true);
498 wpval->start_center->setChecked(true);
503 wpval->end_up->setChecked(true);
506 wpval->end_down->setChecked(true);
509 wpval->end_right->setChecked(true);
512 wpval->end_left->setChecked(true);
515 wpval->end_center->setChecked(true);
518 wpval->start_transp->setValue(w.startTransparency);
519 wpval->end_transp->setValue(w.endTransparency);
520 m_valueItems[paramName] = wpval;
521 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
522 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
523 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
524 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
525 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
526 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
527 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
528 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
529 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
530 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
531 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
532 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
533 //wpval->title->setTitle(na.toElement().text());
534 m_uiItems.append(wpval);
535 } else if (type == "url") {
536 Urlval *cval = new Urlval;
537 cval->setupUi(toFillin);
538 cval->label->setText(paramName);
539 cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
540 m_valueItems[paramName] = cval;
541 cval->urlwidget->setUrl(KUrl(value));
542 connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(collectAllParameters()));
543 connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(collectAllParameters()));
544 m_uiItems.append(cval);
545 } else if (type == "keywords") {
546 Keywordval* kval = new Keywordval;
547 kval->setupUi(toFillin);
548 kval->label->setText(paramName);
549 kval->lineeditwidget->setText(value);
550 QDomElement klistelem = pa.firstChildElement("keywords");
551 QDomElement kdisplaylistelem = pa.firstChildElement("keywordsdisplay");
552 QStringList keywordlist;
553 QStringList keyworddisplaylist;
554 if (!klistelem.isNull()) {
555 keywordlist = klistelem.text().split(';');
556 keyworddisplaylist = i18n(kdisplaylistelem.text().toUtf8().data()).split(';');
558 if (keyworddisplaylist.count() != keywordlist.count()) {
559 keyworddisplaylist = keywordlist;
561 for (int i = 0; i < keywordlist.count(); i++) {
562 kval->comboboxwidget->addItem(keyworddisplaylist.at(i), keywordlist.at(i));
564 // Add disabled user prompt at index 0
565 kval->comboboxwidget->insertItem(0, i18n("<select a keyword>"), "");
566 kval->comboboxwidget->model()->setData( kval->comboboxwidget->model()->index(0,0), QVariant(Qt::NoItemFlags), Qt::UserRole -1);
567 kval->comboboxwidget->setCurrentIndex(0);
568 m_valueItems[paramName] = kval;
569 connect(kval->lineeditwidget, SIGNAL(editingFinished()) , this, SLOT(collectAllParameters()));
570 connect(kval->comboboxwidget, SIGNAL(activated (const QString&)), this, SLOT(collectAllParameters()));
571 m_uiItems.append(kval);
572 } else if (type == "fontfamily") {
573 Fontval* fval = new Fontval;
574 fval->setupUi(toFillin);
575 fval->name->setText(paramName);
576 fval->fontfamilywidget->setCurrentFont(QFont(value));
577 m_valueItems[paramName] = fval;
578 connect(fval->fontfamilywidget, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(collectAllParameters())) ;
579 m_uiItems.append(fval);
586 m_vbox->addWidget(toFillin);
590 m_vbox->addStretch();
592 if (m_keyframeEditor)
593 m_keyframeEditor->checkVisibleParam();
595 // Make sure all doubleparam spinboxes have the same width, looks much better
596 QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
598 for (int i = 0; i < allWidgets.count(); i++) {
599 if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
601 for (int i = 0; i < allWidgets.count(); i++) {
602 allWidgets.at(i)->setSpinSize(minSize);
606 wipeInfo EffectStackEdit::getWipeInfo(QString value)
609 // Convert old geometry values that used a comma as separator
610 if (value.contains(',')) value.replace(',','/');
611 QString start = value.section(';', 0, 0);
612 QString end = value.section(';', 1, 1).section('=', 1, 1);
613 if (start.startsWith("-100%/0"))
615 else if (start.startsWith("100%/0"))
617 else if (start.startsWith("0%/100%"))
619 else if (start.startsWith("0%/-100%"))
624 if (start.count(':') == 2)
625 info.startTransparency = start.section(':', -1).toInt();
627 info.startTransparency = 100;
629 if (end.startsWith("-100%/0"))
631 else if (end.startsWith("100%/0"))
633 else if (end.startsWith("0%/100%"))
635 else if (end.startsWith("0%/-100%"))
640 if (end.count(':') == 2)
641 info.endTransparency = end.section(':', -1).toInt();
643 info.endTransparency = 100;
648 QString EffectStackEdit::getWipeString(wipeInfo info)
653 switch (info.start) {
655 start = "-100%/0%:100%x100%";
658 start = "100%/0%:100%x100%";
661 start = "0%/100%:100%x100%";
664 start = "0%/-100%:100%x100%";
667 start = "0%/0%:100%x100%";
670 start.append(':' + QString::number(info.startTransparency));
674 end = "-100%/0%:100%x100%";
677 end = "100%/0%:100%x100%";
680 end = "0%/100%:100%x100%";
683 end = "0%/-100%:100%x100%";
686 end = "0%/0%:100%x100%";
689 end.append(':' + QString::number(info.endTransparency));
690 return QString(start + ";-1=" + end);
693 void EffectStackEdit::collectAllParameters()
695 if (m_valueItems.isEmpty() || m_params.isNull()) return;
696 const QDomElement oldparam = m_params.cloneNode().toElement();
697 QDomElement newparam = oldparam.cloneNode().toElement();
698 QDomNodeList namenode = newparam.elementsByTagName("parameter");
701 for (int i = 0; i < namenode.count() ; i++) {
702 QDomNode pa = namenode.item(i);
703 QDomElement na = pa.firstChildElement("name");
704 QString type = pa.attributes().namedItem("type").nodeValue();
705 QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
706 if (type == "complex")
707 paramName.append("complex");
708 else if (type == "position")
709 paramName.append("position");
710 else if (type == "geometry")
711 paramName.append("geometry");
712 else if (type == "keyframe")
713 paramName.append("keyframe");
714 if (type != "simplekeyframe" && type != "fixed" && type != "addedgeometry" && !m_valueItems.contains(paramName)) {
715 kDebug() << "// Param: " << paramName << " NOT FOUND";
720 if (type == "double" || type == "constant") {
721 DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
722 setValue = locale.toString(doubleparam->getValue());
723 } else if (type == "list") {
724 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
725 setValue = box->itemData(box->currentIndex()).toString();
726 } else if (type == "bool") {
727 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
728 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
729 } else if (type == "color") {
730 ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
731 setValue = choosecolor->getColor();
732 } else if (type == "complex") {
733 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
734 namenode.item(i) = complex->getParamDesc();
735 } else if (type == "geometry") {
736 if (KdenliveSettings::on_monitor_effects()) {
737 if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getValue());
739 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
740 namenode.item(i).toElement().setAttribute("value", geom->getValue());
742 } else if (type == "addedgeometry") {
743 namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getExtraValue(namenode.item(i).toElement().attribute("name")));
744 } else if (type == "position") {
745 PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
746 int pos = pedit->getPosition();
747 setValue = QString::number(pos);
748 if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_black") {
749 // Make sure duration is not longer than clip
752 pedit->setPosition(pos);
754 EffectsList::setParameter(newparam, "in", QString::number(m_in));
755 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
757 } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
758 // Make sure duration is not longer than clip
761 pedit->setPosition(pos);
763 EffectsList::setParameter(newparam, "in", QString::number(m_out - pos));
764 EffectsList::setParameter(newparam, "out", QString::number(m_out));
767 } else if (type == "curve") {
768 KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
769 QList<QPointF> points = curve->curve().points();
770 QString number = pa.attributes().namedItem("number").nodeValue();
771 QString inName = pa.attributes().namedItem("inpoints").nodeValue();
772 QString outName = pa.attributes().namedItem("outpoints").nodeValue();
773 int off = pa.attributes().namedItem("min").nodeValue().toInt();
774 int end = pa.attributes().namedItem("max").nodeValue().toInt();
775 if (oldparam.attribute("version").toDouble() > 0.2) {
776 EffectsList::setParameter(newparam, number, locale.toString(points.count() / 10.));
778 EffectsList::setParameter(newparam, number, QString::number(points.count()));
780 for (int j = 0; (j < points.count() && j + off <= end); j++) {
782 in.replace("%i", QString::number(j + off));
783 QString out = outName;
784 out.replace("%i", QString::number(j + off));
785 EffectsList::setParameter(newparam, in, locale.toString(points.at(j).x()));
786 EffectsList::setParameter(newparam, out, locale.toString(points.at(j).y()));
788 QString depends = pa.attributes().namedItem("depends").nodeValue();
789 if (!depends.isEmpty())
790 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
791 } else if (type == "bezier_spline") {
792 BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
793 setValue = widget->spline();
794 QString depends = pa.attributes().namedItem("depends").nodeValue();
795 if (!depends.isEmpty())
796 meetDependency(paramName, type, EffectsList::parameter(newparam, depends));
798 } else if (type == "roto-spline") {
799 RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
800 setValue = widget->getSpline();
802 } else if (type == "wipe") {
803 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
805 if (wp->start_left->isChecked())
807 else if (wp->start_right->isChecked())
809 else if (wp->start_up->isChecked())
811 else if (wp->start_down->isChecked())
813 else if (wp->start_center->isChecked())
817 info.startTransparency = wp->start_transp->value();
819 if (wp->end_left->isChecked())
821 else if (wp->end_right->isChecked())
823 else if (wp->end_up->isChecked())
825 else if (wp->end_down->isChecked())
827 else if (wp->end_center->isChecked())
831 info.endTransparency = wp->end_transp->value();
833 setValue = getWipeString(info);
834 } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
835 QDomElement elem = pa.toElement();
836 QString realName = i18n(na.toElement().text().toUtf8().data());
837 QString val = m_keyframeEditor->getValue(realName);
838 elem.setAttribute("keyframes", val);
840 if (m_keyframeEditor->isVisibleParam(realName))
841 elem.setAttribute("intimeline", "1");
842 else if (elem.hasAttribute("intimeline"))
843 elem.removeAttribute("intimeline");
844 } else if (type == "url") {
845 KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
846 setValue = req->url().path();
847 } else if (type == "keywords"){
848 QLineEdit *line = ((Keywordval*)m_valueItems.value(paramName))->lineeditwidget;
849 QComboBox *combo = ((Keywordval*)m_valueItems.value(paramName))->comboboxwidget;
850 if(combo->currentIndex())
852 QString comboval = combo->itemData(combo->currentIndex()).toString();
853 line->insert(comboval);
854 combo->setCurrentIndex(0);
856 setValue = line->text();
857 } else if (type == "fontfamily") {
858 QFontComboBox* fontfamily = ((Fontval*)m_valueItems.value(paramName))->fontfamilywidget;
859 setValue = fontfamily->currentFont().family();
862 if (!setValue.isNull())
863 pa.attributes().namedItem("value").setNodeValue(setValue);
866 emit parameterChanged(oldparam, newparam);
869 void EffectStackEdit::clearAllItems()
872 m_valueItems.clear();
874 /*while (!m_items.isEmpty()) {
875 QWidget *die = m_items.takeFirst();
879 //qDeleteAll(m_uiItems);
881 while ((child = m_vbox->takeAt(0)) != 0) {
882 QWidget *wid = child->widget();
886 m_keyframeEditor = NULL;
887 m_geometryWidget = NULL;
891 void EffectStackEdit::slotSyncEffectsPos(int pos)
893 emit syncEffectsPos(pos);