1 /***************************************************************************
2 effecstackview.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_constval_ui.h"
20 #include "ui_listval_ui.h"
21 #include "ui_boolval_ui.h"
22 #include "ui_colorval_ui.h"
23 #include "ui_wipeval_ui.h"
24 #include "ui_keyframeeditor_ui.h"
25 #include "complexparameter.h"
26 #include "geometryval.h"
27 #include "keyframeedit.h"
28 #include "positionedit.h"
29 #include "effectslist.h"
30 #include "kdenlivesettings.h"
31 #include "profilesdialog.h"
36 #include <QVBoxLayout>
39 #include <QPushButton>
41 #include <QScrollArea>
44 class Boolval: public QWidget, public Ui::Boolval_UI
48 class Colorval: public QWidget, public Ui::Colorval_UI
52 class Constval: public QWidget, public Ui::Constval_UI
56 class Listval: public QWidget, public Ui::Listval_UI
60 class Wipeval: public QWidget, public Ui::Wipeval_UI
65 QMap<QString, QImage> EffectStackEdit::iconCache;
67 EffectStackEdit::EffectStackEdit(QWidget *parent) :
73 m_baseWidget = new QWidget(this);
74 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
75 setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
76 setFrameStyle(QFrame::NoFrame);
77 setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
79 setWidget(m_baseWidget);
80 setWidgetResizable(true);
81 m_vbox = new QVBoxLayout(m_baseWidget);
82 m_vbox->setContentsMargins(0, 0, 0, 0);
83 m_vbox->setSpacing(0);
87 EffectStackEdit::~EffectStackEdit()
92 void EffectStackEdit::setFrameSize(QPoint p)
95 QDomNodeList namenode = m_params.elementsByTagName("parameter");
96 for (int i = 0; i < namenode.count() ; i++) {
97 QDomNode pa = namenode.item(i);
98 QDomNode na = pa.firstChildElement("name");
99 QString type = pa.attributes().namedItem("type").nodeValue();
100 QString paramName = i18n(na.toElement().text().toUtf8().data());
102 if (type == "geometry") {
103 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
104 geom->setFrameSize(m_frameSize);
111 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
117 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
119 m_params.setAttribute(name, value);
122 void EffectStackEdit::transferParamDesc(const QDomElement d, int in, int out)
128 if (m_params.isNull()) {
129 kDebug() << "// EMPTY EFFECT STACK";
134 doc.appendChild(doc.importNode(m_params, true));
135 kDebug() << "IMPORTED TRANS: " << doc.toString();*/
137 QDomNodeList namenode = m_params.elementsByTagName("parameter");
138 QDomElement e = m_params.toElement();
139 const int minFrame = e.attribute("start").toInt();
140 const int maxFrame = e.attribute("end").toInt();
143 for (int i = 0; i < namenode.count() ; i++) {
144 QDomElement pa = namenode.item(i).toElement();
145 QDomNode na = pa.firstChildElement("name");
146 QString type = pa.attribute("type");
147 QString paramName = i18n(na.toElement().text().toUtf8().data());
148 QWidget * toFillin = new QWidget(m_baseWidget);
149 QString value = pa.attribute("value").isNull() ?
150 pa.attribute("default") : pa.attribute("value");
152 if (type == "geometry") {
153 /*pa.setAttribute("namedesc", "X;Y;Width;Height;Transparency");
154 pa.setAttribute("format", "%d%,%d%:%d%x%d%:%d");
155 pa.setAttribute("min", "-500;-500;0;0;0");
156 pa.setAttribute("max", "500;500;200;200;100");*/
157 } else if (type == "complex") {
158 //pa.setAttribute("namedesc",pa.attribute("name"));
163 //TODO constant, list, bool, complex , color, geometry, position
164 if (type == "double" || type == "constant") {
167 if (pa.attribute("min").startsWith('%')) {
168 min = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("min"));
169 } else min = pa.attribute("min").toInt();
170 if (pa.attribute("max").startsWith('%')) {
171 max = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("max"));
172 } else max = pa.attribute("max").toInt();
173 createSliderItem(paramName, (int)(value.toDouble() + 0.5) , min, max, pa.attribute("suffix", QString()));
176 } else if (type == "list") {
177 Listval *lsval = new Listval;
178 lsval->setupUi(toFillin);
179 QStringList listitems = pa.attribute("paramlist").split(',');
180 QStringList listitemsdisplay = pa.attribute("paramlistdisplay").split(',');
181 if (listitemsdisplay.count() != listitems.count()) listitemsdisplay = listitems;
182 //lsval->list->addItems(listitems);
183 lsval->list->setIconSize(QSize(30, 30));
184 for (int i = 0; i < listitems.count(); i++) {
185 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
186 QString entry = listitems.at(i);
187 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
188 if (!EffectStackEdit::iconCache.contains(entry)) {
190 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
192 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
195 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
196 lsval->title->setTitle(paramName);
197 m_valueItems[paramName] = lsval;
198 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
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->checkBox->setText(paramName);
205 m_valueItems[paramName] = bval;
206 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
207 m_uiItems.append(bval);
208 } else if (type == "complex") {
209 /*QStringList names=nodeAtts.namedItem("name").nodeValue().split(';');
210 QStringList max=nodeAtts.namedItem("max").nodeValue().split(';');
211 QStringList min=nodeAtts.namedItem("min").nodeValue().split(';');
212 QStringList val=value.split(';');
213 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
214 if ( (names.size() == max.size() ) &&
215 (names.size()== min.size()) &&
216 (names.size()== val.size()) )
218 for (int i=0;i< names.size();i++){
219 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
222 ComplexParameter *pl = new ComplexParameter;
223 pl->setupParam(d, pa.attribute("name"), 0, 100);
224 m_vbox->addWidget(pl);
225 m_valueItems[paramName+"complex"] = pl;
226 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
227 } else if (type == "geometry") {
228 Geometryval *geo = new Geometryval(m_profile, m_frameSize);
229 geo->setupParam(pa, minFrame, maxFrame);
230 m_vbox->addWidget(geo);
231 m_valueItems[paramName+"geometry"] = geo;
232 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
233 connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int)));
234 } else if (type == "keyframe") {
235 //Â keyframe editor widget
236 kDebug() << "min: " << m_in << ", MAX: " << m_out;
237 KeyframeEdit *geo = new KeyframeEdit(pa, m_out - m_in - 1, pa.attribute("min").toInt(), pa.attribute("max").toInt(), m_timecode);
238 //geo->setupParam(100, pa.attribute("min").toInt(), pa.attribute("max").toInt(), pa.attribute("keyframes"));
239 //connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int)));
240 //geo->setupParam(pa, minFrame, maxFrame);
241 m_vbox->addWidget(geo);
242 m_valueItems[paramName+"keyframe"] = geo;
243 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
244 } else if (type == "color") {
245 Colorval *cval = new Colorval;
246 cval->setupUi(toFillin);
248 if (value.startsWith('#')) value = value.replace('#', "0x");
249 cval->kcolorbutton->setColor(value.toUInt(&ok, 16));
250 //kDebug() << "color: " << value << ", " << value.toUInt(&ok, 16);
251 cval->label->setText(paramName);
252 m_valueItems[paramName] = cval;
253 connect(cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT(collectAllParameters()));
254 m_uiItems.append(cval);
255 } else if (type == "position") {
256 int pos = value.toInt();
257 if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
259 } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
260 // fadeout position starts from clip end
261 pos = m_out - (pos - m_in);
263 PositionEdit *posedit = new PositionEdit(paramName, pos, 1, m_out, m_timecode);
264 m_vbox->addWidget(posedit);
265 m_valueItems[paramName+"position"] = posedit;
266 connect(posedit, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
267 } else if (type == "wipe") {
268 Wipeval *wpval = new Wipeval;
269 wpval->setupUi(toFillin);
270 wipeInfo w = getWipeInfo(value);
273 wpval->start_up->setChecked(true);
276 wpval->start_down->setChecked(true);
279 wpval->start_right->setChecked(true);
282 wpval->start_left->setChecked(true);
285 wpval->start_center->setChecked(true);
290 wpval->end_up->setChecked(true);
293 wpval->end_down->setChecked(true);
296 wpval->end_right->setChecked(true);
299 wpval->end_left->setChecked(true);
302 wpval->end_center->setChecked(true);
305 wpval->start_transp->setValue(w.startTransparency);
306 wpval->end_transp->setValue(w.endTransparency);
307 m_valueItems[paramName] = wpval;
308 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
309 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
310 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
311 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
312 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
313 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
314 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
315 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
316 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
317 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
318 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
319 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
320 //wpval->title->setTitle(na.toElement().text());
321 m_uiItems.append(wpval);
328 m_vbox->addWidget(toFillin);
331 m_vbox->addStretch();
334 void EffectStackEdit::slotSeekToPos(int pos)
336 emit seekTimeline(m_in + pos);
339 wipeInfo EffectStackEdit::getWipeInfo(QString value)
342 QString start = value.section(';', 0, 0);
343 QString end = value.section(';', 1, 1).section('=', 1, 1);
344 if (start.startsWith("-100%,0")) info.start = LEFT;
345 else if (start.startsWith("100%,0")) info.start = RIGHT;
346 else if (start.startsWith("0%,100%")) info.start = DOWN;
347 else if (start.startsWith("0%,-100%")) info.start = UP;
348 else info.start = CENTER;
349 if (start.count(':') == 2) info.startTransparency = start.section(':', -1).toInt();
350 else info.startTransparency = 100;
352 if (end.startsWith("-100%,0")) info.end = LEFT;
353 else if (end.startsWith("100%,0")) info.end = RIGHT;
354 else if (end.startsWith("0%,100%")) info.end = DOWN;
355 else if (end.startsWith("0%,-100%")) info.end = UP;
356 else info.end = CENTER;
357 if (end.count(':') == 2) info.endTransparency = end.section(':', -1).toInt();
358 else info.endTransparency = 100;
362 QString EffectStackEdit::getWipeString(wipeInfo info)
367 switch (info.start) {
369 start = "-100%,0%:100%x100%";
372 start = "100%,0%:100%x100%";
375 start = "0%,100%:100%x100%";
378 start = "0%,-100%:100%x100%";
381 start = "0%,0%:100%x100%";
384 start.append(':' + QString::number(info.startTransparency));
388 end = "-100%,0%:100%x100%";
391 end = "100%,0%:100%x100%";
394 end = "0%,100%:100%x100%";
397 end = "0%,-100%:100%x100%";
400 end = "0%,0%:100%x100%";
403 end.append(':' + QString::number(info.endTransparency));
404 return QString(start + ";-1=" + end);
407 void EffectStackEdit::collectAllParameters()
409 if (m_valueItems.isEmpty() || m_params.isNull()) return;
410 const QDomElement oldparam = m_params.cloneNode().toElement();
411 QDomElement newparam = oldparam.cloneNode().toElement();
412 QDomNodeList namenode = newparam.elementsByTagName("parameter");
414 for (int i = 0; i < namenode.count() ; i++) {
415 QDomNode pa = namenode.item(i);
416 QDomNode na = pa.firstChildElement("name");
417 QString type = pa.attributes().namedItem("type").nodeValue();
418 QString paramName = i18n(na.toElement().text().toUtf8().data());
419 if (type == "complex") paramName.append("complex");
420 else if (type == "position") paramName.append("position");
421 else if (type == "geometry") paramName.append("geometry");
422 else if (type == "keyframe") paramName.append("keyframe");
423 if (!m_valueItems.contains(paramName)) {
424 // kDebug() << "// Param: " << paramName << " NOT FOUND";
429 if (type == "double" || type == "constant") {
430 QSlider* slider = ((Constval*)m_valueItems.value(paramName))->horizontalSlider;
431 setValue = QString::number(slider->value());
432 } else if (type == "list") {
433 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
434 setValue = box->itemData(box->currentIndex()).toString();
435 } else if (type == "bool") {
436 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
437 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
438 } else if (type == "color") {
439 KColorButton *color = ((Colorval*)m_valueItems.value(paramName))->kcolorbutton;
440 setValue = color->color().name();
441 } else if (type == "complex") {
442 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
443 namenode.item(i) = complex->getParamDesc();
444 } else if (type == "geometry") {
445 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
446 namenode.item(i).toElement().setAttribute("value", geom->getValue());
447 } else if (type == "position") {
448 PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
449 int pos = pedit->getPosition();
450 setValue = QString::number(pos);
451 if (newparam.attribute("id") == "fadein" || newparam.attribute("id") == "fade_from_black") {
452 // Make sure duration is not longer than clip
455 pedit->setPosition(pos);
457 EffectsList::setParameter(newparam, "in", QString::number(m_in));
458 EffectsList::setParameter(newparam, "out", QString::number(m_in + pos));
460 } else if (newparam.attribute("id") == "fadeout" || newparam.attribute("id") == "fade_to_black") {
461 // Make sure duration is not longer than clip
464 pedit->setPosition(pos);
466 EffectsList::setParameter(newparam, "in", QString::number(m_out + m_in - pos));
467 EffectsList::setParameter(newparam, "out", QString::number(m_out + m_in));
470 } else if (type == "wipe") {
471 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
473 if (wp->start_left->isChecked()) info.start = LEFT;
474 else if (wp->start_right->isChecked()) info.start = RIGHT;
475 else if (wp->start_up->isChecked()) info.start = UP;
476 else if (wp->start_down->isChecked()) info.start = DOWN;
477 else if (wp->start_center->isChecked()) info.start = CENTER;
478 else info.start = LEFT;
479 info.startTransparency = wp->start_transp->value();
480 if (wp->end_left->isChecked()) info.end = LEFT;
481 else if (wp->end_right->isChecked()) info.end = RIGHT;
482 else if (wp->end_up->isChecked()) info.end = UP;
483 else if (wp->end_down->isChecked()) info.end = DOWN;
484 else if (wp->end_center->isChecked()) info.end = CENTER;
485 else info.end = RIGHT;
486 info.endTransparency = wp->end_transp->value();
487 setValue = getWipeString(info);
490 if (!setValue.isNull()) {
491 pa.attributes().namedItem("value").setNodeValue(setValue);
494 emit parameterChanged(oldparam, newparam);
497 void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max, const QString suffix)
499 QWidget* toFillin = new QWidget(m_baseWidget);
500 Constval *ctval = new Constval;
501 ctval->setupUi(toFillin);
502 ctval->horizontalSlider->setMinimum(min);
503 ctval->horizontalSlider->setMaximum(max);
504 if (!suffix.isEmpty()) ctval->spinBox->setSuffix(suffix);
505 ctval->spinBox->setMinimum(min);
506 ctval->spinBox->setMaximum(max);
507 ctval->horizontalSlider->setPageStep((int)(max - min) / 10);
508 ctval->horizontalSlider->setValue(val);
509 ctval->label->setText(name);
510 m_valueItems[name] = ctval;
511 m_uiItems.append(ctval);
512 connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters()));
513 m_vbox->addWidget(toFillin);
516 void EffectStackEdit::slotSliderMoved(int)
518 collectAllParameters();
521 void EffectStackEdit::clearAllItems()
524 m_valueItems.clear();
526 /*while (!m_items.isEmpty()) {
527 QWidget *die = m_items.takeFirst();
531 //qDeleteAll(m_uiItems);
533 while ((child = m_vbox->takeAt(0)) != 0) {
534 QWidget *wid = child->widget();