]> git.sesse.net Git - kdenlive/blob - src/effectstack/parametercontainer.cpp
Moving widget files into widgets folder.
[kdenlive] / src / effectstack / parametercontainer.cpp
1 /***************************************************************************
2  *   Copyright (C) 2012 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20 #include "ui_listval_ui.h"
21 #include "ui_boolval_ui.h"
22 #include "ui_wipeval_ui.h"
23 #include "ui_urlval_ui.h"
24 #include "ui_keywordval_ui.h"
25 #include "ui_fontval_ui.h"
26 #include "complexparameter.h"
27 #include "geometryval.h"
28 #include "positionedit.h"
29 #include "widgets/kis_curve_widget.h"
30 #include "kis_cubic_curve.h"
31 #include "widgets/choosecolorwidget.h"
32 #include "widgets/geometrywidget.h"
33 #include "colortools.h"
34 #include "widgets/doubleparameterwidget.h"
35 #include "widgets/cornerswidget.h"
36 #include "dragvalue.h"
37 #include "beziercurve/beziersplinewidget.h"
38 #ifdef USE_QJSON
39 #include "rotoscoping/rotowidget.h"
40 #endif
41 #include "kdenlivesettings.h"
42 #include "profilesdialog.h"
43 #include "projectlist.h"
44 #include "mainwindow.h"
45 #include "parametercontainer.h"
46 #include "../customtrackview.h"
47
48 #include <KUrlRequester>
49 #include <KFileDialog>
50
51 #include <QMap>
52 #include <QString>
53 #include <QImage>
54
55 MySpinBox::MySpinBox(QWidget * parent):
56     QSpinBox(parent)
57 {
58     setFocusPolicy(Qt::StrongFocus);
59 }
60
61 void MySpinBox::focusInEvent(QFocusEvent *e)
62 {
63      setFocusPolicy(Qt::WheelFocus);
64      e->accept();
65 }
66
67 void MySpinBox::focusOutEvent(QFocusEvent *e)
68 {
69      setFocusPolicy(Qt::StrongFocus);
70      e->accept();
71 }
72
73 class Boolval: public QWidget, public Ui::Boolval_UI
74 {
75 };
76
77 class Listval: public QWidget, public Ui::Listval_UI
78 {
79 };
80
81 class Wipeval: public QWidget, public Ui::Wipeval_UI
82 {
83 };
84
85 class Urlval: public QWidget, public Ui::Urlval_UI
86 {
87 };
88
89 class Keywordval: public QWidget, public Ui::Keywordval_UI
90 {
91 };
92
93 class Fontval: public QWidget, public Ui::Fontval_UI
94 {
95 };
96
97
98 ParameterContainer::ParameterContainer(const QDomElement &effect, const ItemInfo &info, EffectMetaInfo *metaInfo, QWidget * parent) :
99         m_keyframeEditor(NULL),
100         m_geometryWidget(NULL),
101         m_metaInfo(metaInfo),
102         m_effect(effect),
103         m_needsMonitorEffectScene(false)
104 {
105     m_in = info.cropStart.frames(KdenliveSettings::project_fps());
106     m_out = (info.cropStart + info.cropDuration).frames(KdenliveSettings::project_fps()) - 1;
107
108     QDomNodeList namenode = effect.childNodes(); //elementsByTagName("parameter");
109     
110     QDomElement e = effect.toElement();
111     int minFrame = e.attribute("start").toInt();
112     int maxFrame = e.attribute("end").toInt();
113     // In transitions, maxFrame is in fact one frame after the end of transition
114     if (maxFrame > 0) maxFrame --;
115
116     bool disable = effect.attribute("disable") == "1" && KdenliveSettings::disable_effect_parameters();
117     parent->setEnabled(!disable);
118
119     bool stretch = true;
120     m_vbox = new QVBoxLayout(parent);
121     m_vbox->setContentsMargins(4, 0, 4, 0);
122     m_vbox->setSpacing(2);
123
124     for (int i = 0; i < namenode.count() ; ++i) {
125         QDomElement pa = namenode.item(i).toElement();
126         if (pa.tagName() != "parameter") continue;
127         QDomElement na = pa.firstChildElement("name");
128         QDomElement commentElem = pa.firstChildElement("comment");
129         QString type = pa.attribute("type");
130         QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
131         QString comment;
132         if (!commentElem.isNull())
133             comment = i18n(commentElem.text().toUtf8().data());
134         QWidget * toFillin = new QWidget(parent);
135         QString value = pa.attribute("value").isNull() ?
136                         pa.attribute("default") : pa.attribute("value");
137
138
139         /** See effects/README for info on the different types */
140
141         if (type == "double" || type == "constant") {
142             double min;
143             double max;
144             if (pa.attribute("min").contains('%'))
145                 min = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("min"), m_metaInfo->frameSize);
146             else
147                 min = pa.attribute("min").toDouble();
148             if (pa.attribute("max").contains('%'))
149                 max = ProfilesDialog::getStringEval(m_metaInfo->profile, pa.attribute("max"), m_metaInfo->frameSize);
150             else
151                 max = pa.attribute("max").toDouble();
152
153             DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, value.toDouble(), min, max,
154                     pa.attribute("default").toDouble(), comment, -1, pa.attribute("suffix"), pa.attribute("decimals").toInt(), parent);
155             doubleparam->setFocusPolicy(Qt::StrongFocus);
156             m_vbox->addWidget(doubleparam);
157             m_valueItems[paramName] = doubleparam;
158             connect(doubleparam, SIGNAL(valueChanged(double)), this, SLOT(slotCollectAllParameters()));
159             connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
160         } else if (type == "list") {
161             Listval *lsval = new Listval;
162             lsval->setupUi(toFillin);
163             lsval->list->setFocusPolicy(Qt::StrongFocus);
164             QStringList listitems = pa.attribute("paramlist").split(';');
165             if (listitems.count() == 1) {
166                 // probably custom effect created before change to ';' as separator
167                 listitems = pa.attribute("paramlist").split(',');
168             }
169             QDomElement list = pa.firstChildElement("paramlistdisplay");
170             QStringList listitemsdisplay;
171             if (!list.isNull()) {
172                 listitemsdisplay = i18n(list.text().toUtf8().data()).split(',');
173             } else {
174                 listitemsdisplay = i18n(pa.attribute("paramlistdisplay").toUtf8().data()).split(',');
175             }
176             if (listitemsdisplay.count() != listitems.count())
177                 listitemsdisplay = listitems;
178             lsval->list->setIconSize(QSize(30, 30));
179             for (int i = 0; i < listitems.count(); ++i) {
180                 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
181                 QString entry = listitems.at(i);
182                 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
183                     if (!MainWindow::m_lumacache.contains(entry)) {
184                         QImage pix(entry);
185                         MainWindow::m_lumacache.insert(entry, pix.scaled(30, 30, Qt::KeepAspectRatio, Qt::SmoothTransformation));
186                     }
187                     lsval->list->setItemIcon(i, QPixmap::fromImage(MainWindow::m_lumacache.value(entry)));
188                 }
189             }
190             if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
191             lsval->name->setText(paramName);
192             lsval->setToolTip(comment);
193             lsval->labelComment->setText(comment);
194             lsval->widgetComment->setHidden(true);
195             m_valueItems[paramName] = lsval;
196             connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(slotCollectAllParameters()));
197             if (!comment.isEmpty())
198                 connect(this, SIGNAL(showComments(bool)), lsval->widgetComment, SLOT(setVisible(bool)));
199             m_uiItems.append(lsval);
200         } else if (type == "bool") {
201             Boolval *bval = new Boolval;
202             bval->setupUi(toFillin);
203             bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
204             bval->name->setText(paramName);
205             bval->name->setToolTip(comment);
206             bval->labelComment->setText(comment);
207             bval->widgetComment->setHidden(true);
208             m_valueItems[paramName] = bval;
209             connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(slotCollectAllParameters()));
210             if (!comment.isEmpty())
211                 connect(this, SIGNAL(showComments(bool)), bval->widgetComment, SLOT(setVisible(bool)));
212             m_uiItems.append(bval);
213         } else if (type == "complex") {
214             ComplexParameter *pl = new ComplexParameter;
215             pl->setupParam(effect, pa.attribute("name"), 0, 100);
216             m_vbox->addWidget(pl);
217             m_valueItems[paramName+"complex"] = pl;
218             connect(pl, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
219         } else if (type == "geometry") {
220             if (KdenliveSettings::on_monitor_effects()) {
221                 m_needsMonitorEffectScene = true;
222                 m_geometryWidget = new GeometryWidget(m_metaInfo->monitor, m_metaInfo->timecode, 0, true, effect.hasAttribute("showrotation"), parent);
223                 m_geometryWidget->setFrameSize(m_metaInfo->frameSize);
224                 connect(m_geometryWidget, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
225                 if (minFrame == maxFrame) {
226                     m_geometryWidget->setupParam(pa, m_in, m_out);
227                     connect(this, SIGNAL(updateRange(int,int)), m_geometryWidget, SLOT(slotUpdateRange(int,int)));
228                 }
229                 else
230                     m_geometryWidget->setupParam(pa, minFrame, maxFrame);
231                 m_vbox->addWidget(m_geometryWidget);
232                 m_valueItems[paramName+"geometry"] = m_geometryWidget;
233                 connect(m_geometryWidget, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
234                 connect(m_geometryWidget, SIGNAL(importClipKeyframes()), this, SIGNAL(importClipKeyframes()));
235                 connect(this, SIGNAL(syncEffectsPos(int)), m_geometryWidget, SLOT(slotSyncPosition(int)));
236             } else {
237                 Geometryval *geo = new Geometryval(m_metaInfo->profile, m_metaInfo->timecode, m_metaInfo->frameSize, 0);
238                 if (minFrame == maxFrame) {
239                     geo->setupParam(pa, m_in, m_out);
240                     connect(this, SIGNAL(updateRange(int,int)), geo, SLOT(slotUpdateRange(int,int)));
241                 }
242                 else
243                     geo->setupParam(pa, minFrame, maxFrame);
244                 m_vbox->addWidget(geo);
245                 m_valueItems[paramName+"geometry"] = geo;
246                 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
247                 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
248                 connect(this, SIGNAL(syncEffectsPos(int)), geo, SLOT(slotSyncPosition(int)));
249             }
250         } else if (type == "addedgeometry") {
251             // this is a parameter that should be linked to the geometry widget, for example rotation, shear, ...
252             if (m_geometryWidget) m_geometryWidget->addParameter(pa);
253         } else if (type == "keyframe" || type == "simplekeyframe") {
254             // keyframe editor widget
255             if (m_keyframeEditor == NULL) {
256                 KeyframeEdit *geo;
257                 if (pa.attribute("widget") == "corners") {
258                     // we want a corners-keyframe-widget
259                     CornersWidget *corners = new CornersWidget(m_metaInfo->monitor, pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt(), parent);
260                     connect(this, SIGNAL(updateRange(int,int)), corners, SLOT(slotUpdateRange(int,int)));
261                     m_needsMonitorEffectScene = true;
262                     connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
263                     geo = static_cast<KeyframeEdit *>(corners);
264                 } else {
265                     geo = new KeyframeEdit(pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt());
266                     connect(this, SIGNAL(updateRange(int,int)), geo, SLOT(slotUpdateRange(int,int)));
267                 }
268                 m_vbox->addWidget(geo);
269                 m_valueItems[paramName+"keyframe"] = geo;
270                 m_keyframeEditor = geo;
271                 connect(geo, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
272                 connect(geo, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
273                 connect(this, SIGNAL(showComments(bool)), geo, SIGNAL(showComments(bool)));
274             } else {
275                 // we already have a keyframe editor, so just add another column for the new param
276                 m_keyframeEditor->addParameter(pa);
277             }
278         } else if (type == "color") {
279             if (pa.hasAttribute("paramprefix")) value.remove(0, pa.attribute("paramprefix").size());
280             if (value.startsWith('#'))
281                 value = value.replace('#', "0x");
282             ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, value, pa.hasAttribute("alpha"), parent);
283             choosecolor->setToolTip(comment);
284             m_vbox->addWidget(choosecolor);
285             m_valueItems[paramName] = choosecolor;
286             connect(choosecolor, SIGNAL(displayMessage(QString,int)), this, SIGNAL(displayMessage(QString,int)));
287             connect(choosecolor, SIGNAL(modified()) , this, SLOT(slotCollectAllParameters()));
288             connect(choosecolor, SIGNAL(disableCurrentFilter(bool)) , this, SIGNAL(disableCurrentFilter(bool)));
289         } else if (type == "position") {
290             int pos = value.toInt();
291             if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
292                 pos = pos - m_in;
293             } else if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
294                 // fadeout position starts from clip end
295                 pos = m_out - pos;
296             }
297             PositionEdit *posedit = new PositionEdit(paramName, pos, 0, m_out - m_in, m_metaInfo->timecode);
298             posedit->setToolTip(comment);
299             connect(this, SIGNAL(updateRange(int,int)), posedit, SLOT(setRange(int,int)));
300             m_vbox->addWidget(posedit);
301             m_valueItems[paramName+"position"] = posedit;
302             connect(posedit, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
303         } else if (type == "curve") {
304             KisCurveWidget *curve = new KisCurveWidget(parent);
305             curve->setMaxPoints(pa.attribute("max").toInt());
306             QList<QPointF> points;
307             int number;
308             if (e.attribute("version").toDouble() > 0.2) {
309                 // Rounding gives really weird results. (int) (10 * 0.3) gives 2! So for now, add 0.5 to get correct result
310                 number = EffectsList::parameter(e, pa.attribute("number")).toDouble() * 10 + 0.5;
311             } else {
312                 number = EffectsList::parameter(e, pa.attribute("number")).toInt();
313             }
314             QString inName = pa.attribute("inpoints");
315             QString outName = pa.attribute("outpoints");
316             int start = pa.attribute("min").toInt();
317             for (int j = start; j <= number; j++) {
318                 QString in = inName;
319                 in.replace("%i", QString::number(j));
320                 QString out = outName;
321                 out.replace("%i", QString::number(j));
322                 points << QPointF(EffectsList::parameter(e, in).toDouble(), EffectsList::parameter(e, out).toDouble());
323             }
324             if (!points.isEmpty())
325                 curve->setCurve(KisCubicCurve(points));
326             MySpinBox *spinin = new MySpinBox();
327             spinin->setRange(0, 1000);
328             MySpinBox *spinout = new MySpinBox();
329             spinout->setRange(0, 1000);
330             curve->setupInOutControls(spinin, spinout, 0, 1000);
331             m_vbox->addWidget(curve);
332             m_vbox->addWidget(spinin);
333             m_vbox->addWidget(spinout);
334
335             connect(curve, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
336             m_valueItems[paramName] = curve;
337
338             QString depends = pa.attribute("depends");
339             if (!depends.isEmpty())
340                 meetDependency(paramName, type, EffectsList::parameter(e, depends));
341         } else if (type == "bezier_spline") {
342             BezierSplineWidget *widget = new BezierSplineWidget(value, parent);
343             stretch = false;
344             m_vbox->addWidget(widget);
345             m_valueItems[paramName] = widget;
346             connect(widget, SIGNAL(modified()), this, SLOT(slotCollectAllParameters()));
347             QString depends = pa.attribute("depends");
348             if (!depends.isEmpty())
349                 meetDependency(paramName, type, EffectsList::parameter(e, depends));
350 #ifdef USE_QJSON
351         } else if (type == "roto-spline") {
352             m_needsMonitorEffectScene = true;
353             RotoWidget *roto = new RotoWidget(value, m_metaInfo->monitor, info, m_metaInfo->timecode, parent);
354             connect(roto, SIGNAL(valueChanged()), this, SLOT(slotCollectAllParameters()));
355             connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
356             connect(this, SIGNAL(syncEffectsPos(int)), roto, SLOT(slotSyncPosition(int)));
357             m_vbox->addWidget(roto);
358             m_valueItems[paramName] = roto;
359 #endif
360         } else if (type == "wipe") {
361             Wipeval *wpval = new Wipeval;
362             wpval->setupUi(toFillin);
363             wipeInfo w = getWipeInfo(value);
364             switch (w.start) {
365             case UP:
366                 wpval->start_up->setChecked(true);
367                 break;
368             case DOWN:
369                 wpval->start_down->setChecked(true);
370                 break;
371             case RIGHT:
372                 wpval->start_right->setChecked(true);
373                 break;
374             case LEFT:
375                 wpval->start_left->setChecked(true);
376                 break;
377             default:
378                 wpval->start_center->setChecked(true);
379                 break;
380             }
381             switch (w.end) {
382             case UP:
383                 wpval->end_up->setChecked(true);
384                 break;
385             case DOWN:
386                 wpval->end_down->setChecked(true);
387                 break;
388             case RIGHT:
389                 wpval->end_right->setChecked(true);
390                 break;
391             case LEFT:
392                 wpval->end_left->setChecked(true);
393                 break;
394             default:
395                 wpval->end_center->setChecked(true);
396                 break;
397             }
398             wpval->start_transp->setValue(w.startTransparency);
399             wpval->end_transp->setValue(w.endTransparency);
400             m_valueItems[paramName] = wpval;
401             connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
402             connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
403             connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
404             connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
405             connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
406             connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
407             connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
408             connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
409             connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
410             connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(slotCollectAllParameters()));
411             connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
412             connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(slotCollectAllParameters()));
413             //wpval->title->setTitle(na.toElement().text());
414             m_uiItems.append(wpval);
415         } else if (type == "url") {
416             Urlval *cval = new Urlval;
417             cval->setupUi(toFillin);
418             cval->label->setText(paramName);
419             cval->setToolTip(comment);
420             cval->urlwidget->fileDialog()->setFilter(ProjectList::getExtensions());
421             m_valueItems[paramName] = cval;
422             cval->urlwidget->setUrl(KUrl(value));
423             connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(slotCollectAllParameters()));
424             connect(cval->urlwidget, SIGNAL(urlSelected(KUrl)) , this, SLOT(slotCollectAllParameters()));
425             m_uiItems.append(cval);
426         } else if (type == "keywords") {
427             Keywordval* kval = new Keywordval;
428             kval->setupUi(toFillin);
429             kval->label->setText(paramName);
430             kval->lineeditwidget->setText(value);
431             kval->setToolTip(comment);
432             QDomElement klistelem = pa.firstChildElement("keywords");
433             QDomElement kdisplaylistelem = pa.firstChildElement("keywordsdisplay");
434             QStringList keywordlist;
435             QStringList keyworddisplaylist;
436             if (!klistelem.isNull()) {
437                 keywordlist = klistelem.text().split(';');
438                 keyworddisplaylist = i18n(kdisplaylistelem.text().toUtf8().data()).split(';');
439             }
440             if (keyworddisplaylist.count() != keywordlist.count()) {
441                 keyworddisplaylist = keywordlist;
442             }
443             for (int i = 0; i < keywordlist.count(); ++i) {
444                 kval->comboboxwidget->addItem(keyworddisplaylist.at(i), keywordlist.at(i));
445             }
446             // Add disabled user prompt at index 0
447             kval->comboboxwidget->insertItem(0, i18n("<select a keyword>"), "");
448             kval->comboboxwidget->model()->setData( kval->comboboxwidget->model()->index(0,0), QVariant(Qt::NoItemFlags), Qt::UserRole -1);
449             kval->comboboxwidget->setCurrentIndex(0);
450             m_valueItems[paramName] = kval;
451             connect(kval->lineeditwidget, SIGNAL(editingFinished()) , this, SLOT(slotCollectAllParameters()));
452             connect(kval->comboboxwidget, SIGNAL(activated(QString)), this, SLOT(slotCollectAllParameters()));
453             m_uiItems.append(kval);
454         } else if (type == "fontfamily") {
455             Fontval* fval = new Fontval;
456             fval->setupUi(toFillin);
457             fval->name->setText(paramName);
458             fval->fontfamilywidget->setCurrentFont(QFont(value));
459             m_valueItems[paramName] = fval;
460             connect(fval->fontfamilywidget, SIGNAL(currentFontChanged(QFont)), this, SLOT(slotCollectAllParameters())) ;
461             m_uiItems.append(fval);
462         } else if (type == "filterjob") {
463             QVBoxLayout *l= new QVBoxLayout(toFillin);
464             QPushButton *button = new QPushButton(paramName, toFillin);
465             l->addWidget(button);
466             m_valueItems[paramName] = button;
467             connect(button, SIGNAL(pressed()), this, SLOT(slotStartFilterJobAction()));   
468         } else {
469             delete toFillin;
470             toFillin = NULL;
471         }
472
473         if (toFillin)
474             m_vbox->addWidget(toFillin);
475     }
476
477     if (stretch)
478         m_vbox->addStretch();
479
480     if (m_keyframeEditor)
481         m_keyframeEditor->checkVisibleParam();
482
483     // Make sure all doubleparam spinboxes have the same width, looks much better
484     QList<DoubleParameterWidget *> allWidgets = findChildren<DoubleParameterWidget *>();
485     int minSize = 0;
486     for (int i = 0; i < allWidgets.count(); ++i) {
487         if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize();
488     }
489     for (int i = 0; i < allWidgets.count(); ++i) {
490         allWidgets.at(i)->setSpinSize(minSize);
491     }
492 }
493
494 ParameterContainer::~ParameterContainer()
495 {
496     clearLayout(m_vbox);
497     delete m_vbox;
498 }
499
500 void ParameterContainer::meetDependency(const QString& name, const QString &type, const QString &value)
501 {
502     if (type == "curve") {
503         KisCurveWidget *curve = (KisCurveWidget*)m_valueItems[name];
504         if (curve) {
505             const int color = value.toInt();
506             curve->setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(curve->size(), (ColorTools::ColorsRGB)(color == 3 ? 4 : color), 0.8)));
507         }
508     } else if (type == "bezier_spline") {
509         BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems[name];
510         if (widget) {
511             widget->setMode((BezierSplineWidget::CurveModes)((int)(value.toDouble() * 10 + 0.5)));
512         }
513     }
514 }
515
516 wipeInfo ParameterContainer::getWipeInfo(QString value)
517 {
518     wipeInfo info;
519     // Convert old geometry values that used a comma as separator
520     if (value.contains(',')) value.replace(',','/');
521     QString start = value.section(';', 0, 0);
522     QString end = value.section(';', 1, 1).section('=', 1, 1);
523     if (start.startsWith("-100%/0"))
524         info.start = LEFT;
525     else if (start.startsWith("100%/0"))
526         info.start = RIGHT;
527     else if (start.startsWith("0%/100%"))
528         info.start = DOWN;
529     else if (start.startsWith("0%/-100%"))
530         info.start = UP;
531     else
532         info.start = CENTER;
533
534     if (start.count(':') == 2)
535         info.startTransparency = start.section(':', -1).toInt();
536     else
537         info.startTransparency = 100;
538
539     if (end.startsWith("-100%/0"))
540         info.end = LEFT;
541     else if (end.startsWith("100%/0"))
542         info.end = RIGHT;
543     else if (end.startsWith("0%/100%"))
544         info.end = DOWN;
545     else if (end.startsWith("0%/-100%"))
546         info.end = UP;
547     else
548         info.end = CENTER;
549
550     if (end.count(':') == 2)
551         info.endTransparency = end.section(':', -1).toInt();
552     else
553         info.endTransparency = 100;
554
555     return info;
556 }
557
558 void ParameterContainer::updateTimecodeFormat()
559 {
560     if (m_keyframeEditor)
561         m_keyframeEditor->updateTimecodeFormat();
562
563     QDomNodeList namenode = m_effect.elementsByTagName("parameter");
564     for (int i = 0; i < namenode.count() ; ++i) {
565         QDomNode pa = namenode.item(i);
566         QDomElement na = pa.firstChildElement("name");
567         QString type = pa.attributes().namedItem("type").nodeValue();
568         QString paramName = na.isNull() ? pa.attributes().namedItem("name").nodeValue() : i18n(na.text().toUtf8().data());
569
570         if (type == "geometry") {
571             if (KdenliveSettings::on_monitor_effects()) {
572                 if (m_geometryWidget) m_geometryWidget->updateTimecodeFormat();
573             } else {
574                 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
575                 geom->updateTimecodeFormat();
576             }
577             break;
578         } else if (type == "position") {
579             PositionEdit *posi = ((PositionEdit*)m_valueItems[paramName+"position"]);
580             posi->updateTimecodeFormat();
581             break;
582 #ifdef USE_QJSON
583         } else if (type == "roto-spline") {
584             RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems[paramName]);
585             widget->updateTimecodeFormat();
586 #endif
587         }
588     }
589 }
590
591 void ParameterContainer::slotCollectAllParameters()
592 {
593     if (m_valueItems.isEmpty() || m_effect.isNull()) return;
594     QLocale locale;
595     locale.setNumberOptions(QLocale::OmitGroupSeparator);
596     const QDomElement oldparam = m_effect.cloneNode().toElement();
597     //QDomElement newparam = oldparam.cloneNode().toElement();
598     QDomNodeList namenode = m_effect.elementsByTagName("parameter");
599
600     for (int i = 0; i < namenode.count() ; ++i) {
601         QDomElement pa = namenode.item(i).toElement();
602         QDomElement na = pa.firstChildElement("name");
603         QString type = pa.attribute("type");
604         QString paramName = na.isNull() ? pa.attribute("name") : i18n(na.text().toUtf8().data());
605         if (type == "complex")
606             paramName.append("complex");
607         else if (type == "position")
608             paramName.append("position");
609         else if (type == "geometry")
610             paramName.append("geometry");
611         else if (type == "keyframe")
612             paramName.append("keyframe");
613         if (type != "simplekeyframe" && type != "fixed" && type != "addedgeometry" && !m_valueItems.contains(paramName)) {
614             kDebug() << "// Param: " << paramName << " NOT FOUND";
615             continue;
616         }
617
618         QString setValue;
619         if (type == "double" || type == "constant") {
620             DoubleParameterWidget *doubleparam = (DoubleParameterWidget*)m_valueItems.value(paramName);
621             setValue = locale.toString(doubleparam->getValue());
622         } else if (type == "list") {
623             KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
624             setValue = box->itemData(box->currentIndex()).toString();
625         } else if (type == "bool") {
626             QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
627             setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
628         } else if (type == "color") {
629             ChooseColorWidget *choosecolor = ((ChooseColorWidget*)m_valueItems.value(paramName));
630             setValue = choosecolor->getColor();
631             if (pa.hasAttribute("paramprefix")) setValue.prepend(pa.attribute("paramprefix"));
632         } else if (type == "complex") {
633             ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
634             namenode.item(i) = complex->getParamDesc();
635         } else if (type == "geometry") {
636             if (KdenliveSettings::on_monitor_effects()) {
637                 if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getValue());
638             } else {
639                 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
640                 namenode.item(i).toElement().setAttribute("value", geom->getValue());
641             }
642         } else if (type == "addedgeometry") {
643             if (m_geometryWidget) namenode.item(i).toElement().setAttribute("value", m_geometryWidget->getExtraValue(namenode.item(i).toElement().attribute("name")));
644         } else if (type == "position") {
645             PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
646             int pos = pedit->getPosition();
647             setValue = QString::number(pos);
648             if (m_effect.attribute("id") == "fadein" || m_effect.attribute("id") == "fade_from_black") {
649                 // Make sure duration is not longer than clip
650                 /*if (pos > m_out) {
651                     pos = m_out;
652                     pedit->setPosition(pos);
653                 }*/
654                 EffectsList::setParameter(m_effect, "in", QString::number(m_in));
655                 EffectsList::setParameter(m_effect, "out", QString::number(m_in + pos));
656                 setValue.clear();
657             } else if (m_effect.attribute("id") == "fadeout" || m_effect.attribute("id") == "fade_to_black") {
658                 // Make sure duration is not longer than clip
659                 /*if (pos > m_out) {
660                     pos = m_out;
661                     pedit->setPosition(pos);
662                 }*/
663                 EffectsList::setParameter(m_effect, "in", QString::number(m_out - pos));
664                 EffectsList::setParameter(m_effect, "out", QString::number(m_out));
665                 setValue.clear();
666             }
667         } else if (type == "curve") {
668             KisCurveWidget *curve = ((KisCurveWidget*)m_valueItems.value(paramName));
669             QList<QPointF> points = curve->curve().points();
670             QString number = pa.attribute("number");
671             QString inName = pa.attribute("inpoints");
672             QString outName = pa.attribute("outpoints");
673             int off = pa.attribute("min").toInt();
674             int end = pa.attribute("max").toInt();
675             if (oldparam.attribute("version").toDouble() > 0.2) {
676                 EffectsList::setParameter(m_effect, number, locale.toString(points.count() / 10.));
677             } else {
678                 EffectsList::setParameter(m_effect, number, QString::number(points.count()));
679             }
680             for (int j = 0; (j < points.count() && j + off <= end); j++) {
681                 QString in = inName;
682                 in.replace("%i", QString::number(j + off));
683                 QString out = outName;
684                 out.replace("%i", QString::number(j + off));
685                 EffectsList::setParameter(m_effect, in, locale.toString(points.at(j).x()));
686                 EffectsList::setParameter(m_effect, out, locale.toString(points.at(j).y()));
687             }
688             QString depends = pa.attribute("depends");
689             if (!depends.isEmpty())
690                 meetDependency(paramName, type, EffectsList::parameter(m_effect, depends));
691         } else if (type == "bezier_spline") {
692             BezierSplineWidget *widget = (BezierSplineWidget*)m_valueItems.value(paramName);
693             setValue = widget->spline();
694             QString depends = pa.attribute("depends");
695             if (!depends.isEmpty())
696                 meetDependency(paramName, type, EffectsList::parameter(m_effect, depends));
697 #ifdef USE_QJSON
698         } else if (type == "roto-spline") {
699             RotoWidget *widget = static_cast<RotoWidget *>(m_valueItems.value(paramName));
700             setValue = widget->getSpline();
701 #endif
702         } else if (type == "wipe") {
703             Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
704             wipeInfo info;
705             if (wp->start_left->isChecked())
706                 info.start = LEFT;
707             else if (wp->start_right->isChecked())
708                 info.start = RIGHT;
709             else if (wp->start_up->isChecked())
710                 info.start = UP;
711             else if (wp->start_down->isChecked())
712                 info.start = DOWN;
713             else if (wp->start_center->isChecked())
714                 info.start = CENTER;
715             else
716                 info.start = LEFT;
717             info.startTransparency = wp->start_transp->value();
718
719             if (wp->end_left->isChecked())
720                 info.end = LEFT;
721             else if (wp->end_right->isChecked())
722                 info.end = RIGHT;
723             else if (wp->end_up->isChecked())
724                 info.end = UP;
725             else if (wp->end_down->isChecked())
726                 info.end = DOWN;
727             else if (wp->end_center->isChecked())
728                 info.end = CENTER;
729             else
730                 info.end = RIGHT;
731             info.endTransparency = wp->end_transp->value();
732
733             setValue = getWipeString(info);
734         } else if ((type == "simplekeyframe" || type == "keyframe") && m_keyframeEditor) {
735             QString realName = i18n(na.toElement().text().toUtf8().data());
736             QString val = m_keyframeEditor->getValue(realName);
737             pa.setAttribute("keyframes", val);
738
739             if (m_keyframeEditor->isVisibleParam(realName)) {
740                 pa.setAttribute("intimeline", "1");
741             }
742             else if (pa.hasAttribute("intimeline"))
743                 pa.setAttribute("intimeline", "0");
744         } else if (type == "url") {
745             KUrlRequester *req = ((Urlval*)m_valueItems.value(paramName))->urlwidget;
746             setValue = req->url().path();
747         } else if (type == "keywords"){
748             QLineEdit *line = ((Keywordval*)m_valueItems.value(paramName))->lineeditwidget;
749             QComboBox *combo = ((Keywordval*)m_valueItems.value(paramName))->comboboxwidget;
750             if(combo->currentIndex())
751             {
752                 QString comboval = combo->itemData(combo->currentIndex()).toString();
753                 line->insert(comboval);
754                 combo->setCurrentIndex(0);
755             }
756             setValue = line->text();
757         } else if (type == "fontfamily") {
758             QFontComboBox* fontfamily = ((Fontval*)m_valueItems.value(paramName))->fontfamilywidget;
759             setValue = fontfamily->currentFont().family();
760         }
761         if (!setValue.isNull())
762             pa.setAttribute("value", setValue);
763
764     }
765     emit parameterChanged(oldparam, m_effect, m_effect.attribute("kdenlive_ix").toInt());
766 }
767
768 QString ParameterContainer::getWipeString(wipeInfo info)
769 {
770
771     QString start;
772     QString end;
773     switch (info.start) {
774     case LEFT:
775         start = "-100%/0%:100%x100%";
776         break;
777     case RIGHT:
778         start = "100%/0%:100%x100%";
779         break;
780     case DOWN:
781         start = "0%/100%:100%x100%";
782         break;
783     case UP:
784         start = "0%/-100%:100%x100%";
785         break;
786     default:
787         start = "0%/0%:100%x100%";
788         break;
789     }
790     start.append(':' + QString::number(info.startTransparency));
791
792     switch (info.end) {
793     case LEFT:
794         end = "-100%/0%:100%x100%";
795         break;
796     case RIGHT:
797         end = "100%/0%:100%x100%";
798         break;
799     case DOWN:
800         end = "0%/100%:100%x100%";
801         break;
802     case UP:
803         end = "0%/-100%:100%x100%";
804         break;
805     default:
806         end = "0%/0%:100%x100%";
807         break;
808     }
809     end.append(':' + QString::number(info.endTransparency));
810     return QString(start + ";-1=" + end);
811 }
812
813 void ParameterContainer::updateParameter(const QString &key, const QString &value)
814 {
815     m_effect.setAttribute(key, value);
816 }
817
818 void ParameterContainer::slotStartFilterJobAction()
819 {
820     QDomNodeList namenode = m_effect.elementsByTagName("parameter");
821     for (int i = 0; i < namenode.count() ; ++i) {
822         QDomElement pa = namenode.item(i).toElement();
823         QString type = pa.attribute("type");
824         if (type == "filterjob") {
825             QString filterparams = pa.attribute("filterparams");
826             if (filterparams.contains("%position")) {
827                 if (m_geometryWidget) filterparams.replace("%position", QString::number(m_geometryWidget->currentPosition()));
828             }
829             if (filterparams.contains("%params")) {
830                 // Replace with current geometry
831                 EffectsParameterList parameters;
832                 QDomNodeList params = m_effect.elementsByTagName("parameter");
833                 CustomTrackView::adjustEffectParameters(parameters, params, m_metaInfo->profile);
834                 QString paramData;
835                 for (int j = 0; j < parameters.count(); j++)
836                     paramData.append(parameters.at(j).name()+"="+parameters.at(j).value()+" ");
837                 filterparams.replace("%params", paramData);
838             }
839             QMap <QString, QString> extraParams;
840             QDomNodeList jobparams = pa.elementsByTagName("jobparam");
841             for (int j = 0; j < jobparams.count(); j++) {
842                 QDomElement e = jobparams.item(j).toElement();
843                 extraParams.insert(e.attribute("name"), e.text().toUtf8());
844             }
845             extraParams.insert("offset", QString::number(m_in));
846             emit startFilterJob(pa.attribute("filtertag"), filterparams, pa.attribute("consumer"), pa.attribute("consumerparams"), extraParams);
847             kDebug()<<" - - -PROPS:\n"<<pa.attribute("filtertag")<<"-"<< filterparams<<"-"<< pa.attribute("consumer")<<"-"<< pa.attribute("consumerparams")<<"-"<< pa.attribute("extraparams");
848             break;
849         }
850     }
851 }
852
853
854 void ParameterContainer::clearLayout(QLayout *layout)
855 {
856     QLayoutItem *item;
857     while((item = layout->takeAt(0))) {
858         if (item->layout()) {
859             clearLayout(item->layout());
860             delete item->layout();
861         }
862         if (item->widget()) {
863             delete item->widget();
864         }
865         delete item;
866     }
867 }
868
869 bool ParameterContainer::needsMonitorEffectScene() const
870 {
871     return m_needsMonitorEffectScene;
872 }
873
874 void ParameterContainer::setKeyframes(const QString &data, int maximum)
875 {
876     if (!m_geometryWidget) {
877         kDebug()<<" / / NO GEOMETRY WIDGET FOUND FOR IMPORTING DATA";
878         return;
879     }
880     m_geometryWidget->importKeyframes(data, maximum);
881     
882 }
883
884 void ParameterContainer::setRange(int inPoint, int outPoint)
885 {
886     m_in = inPoint;
887     m_out = outPoint;
888     emit updateRange(m_in, m_out);
889 }
890
891
892
893 #include "parametercontainer.moc"