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_positionval_ui.h"
24 #include "ui_wipeval_ui.h"
25 #include "ui_keyframeeditor_ui.h"
26 #include "complexparameter.h"
27 #include "geometryval.h"
28 #include "keyframeedit.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 EffectStackEdit::UiItem, public Ui::Boolval_UI
48 class Colorval: public EffectStackEdit::UiItem, public Ui::Colorval_UI
52 class Constval: public EffectStackEdit::UiItem, public Ui::Constval_UI
56 class Listval: public EffectStackEdit::UiItem, public Ui::Listval_UI
60 class Positionval: public EffectStackEdit::UiItem, public Ui::Positionval_UI
64 class Wipeval: public EffectStackEdit::UiItem, public Ui::Wipeval_UI
69 QMap<QString, QImage> EffectStackEdit::iconCache;
71 EffectStackEdit::EffectStackEdit(QWidget *parent) :
77 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
78 QVBoxLayout *vbox1 = new QVBoxLayout(parent);
79 vbox1->setContentsMargins(0, 0, 0, 0);
82 QScrollArea *area = new QScrollArea;
83 QWidget *wid = new QWidget(parent);
84 area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
85 area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
86 area->setFrameStyle(QFrame::NoFrame);
87 wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
88 area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
90 vbox1->addWidget(area);
92 area->setWidgetResizable(true);
93 m_vbox = new QVBoxLayout(wid);
94 m_vbox->setContentsMargins(0, 0, 0, 0);
95 m_vbox->setSpacing(0);
100 EffectStackEdit::~EffectStackEdit()
105 void EffectStackEdit::setFrameSize(QPoint p)
108 QDomNodeList namenode = m_params.elementsByTagName("parameter");
109 for (int i = 0; i < namenode.count() ; i++) {
110 QDomNode pa = namenode.item(i);
111 QDomNode na = pa.firstChildElement("name");
112 QString type = pa.attributes().namedItem("type").nodeValue();
113 QString paramName = i18n(na.toElement().text().toUtf8().data());
115 if (type == "geometry") {
116 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
117 geom->setFrameSize(m_frameSize);
124 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
130 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
132 m_params.setAttribute(name, value);
135 void EffectStackEdit::transferParamDesc(const QDomElement& d, int in, int out)
142 if (m_params.isNull()) return;
145 doc.appendChild(doc.importNode(m_params, true));
146 //kDebug() << "IMPORTED TRANS: " << doc.toString();
147 QDomNodeList namenode = m_params.elementsByTagName("parameter");
148 QDomElement e = m_params.toElement();
149 const int minFrame = e.attribute("start").toInt();
150 const int maxFrame = e.attribute("end").toInt();
153 for (int i = 0; i < namenode.count() ; i++) {
154 kDebug() << "in form";
155 QDomElement pa = namenode.item(i).toElement();
156 QDomNode na = pa.firstChildElement("name");
157 QString type = pa.attribute("type");
158 QString paramName = i18n(na.toElement().text().toUtf8().data());
159 QWidget * toFillin = new QWidget;
160 QString value = pa.attribute("value").isNull() ?
161 pa.attribute("default") : pa.attribute("value");
163 if (type == "geometry") {
164 /*pa.setAttribute("namedesc", "X;Y;Width;Height;Transparency");
165 pa.setAttribute("format", "%d%,%d%:%d%x%d%:%d");
166 pa.setAttribute("min", "-500;-500;0;0;0");
167 pa.setAttribute("max", "500;500;200;200;100");*/
168 } else if (type == "complex") {
169 //pa.setAttribute("namedesc",pa.attribute("name"));
174 //TODO constant, list, bool, complex , color, geometry, position
175 if (type == "double" || type == "constant") {
178 if (pa.attribute("min").startsWith('%')) {
179 min = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("min"));
180 } else min = pa.attribute("min").toInt();
181 if (pa.attribute("max").startsWith('%')) {
182 max = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("max"));
183 } else max = pa.attribute("max").toInt();
184 createSliderItem(paramName, (int)(value.toDouble() + 0.5) , min, max);
187 } else if (type == "list") {
188 Listval *lsval = new Listval;
189 lsval->setupUi(toFillin);
190 QStringList listitems = pa.attribute("paramlist").split(',');
191 QStringList listitemsdisplay = pa.attribute("paramlistdisplay").split(',');
192 if (listitemsdisplay.count() != listitems.count()) listitemsdisplay = listitems;
193 //lsval->list->addItems(listitems);
194 lsval->list->setIconSize(QSize(30, 30));
195 for (int i = 0; i < listitems.count(); i++) {
196 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
197 QString entry = listitems.at(i);
198 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
199 if (!EffectStackEdit::iconCache.contains(entry)) {
201 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
203 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
206 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
207 lsval->title->setTitle(paramName);
208 m_valueItems[paramName] = lsval;
209 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
210 m_uiItems.append(lsval);
211 } else if (type == "bool") {
212 Boolval *bval = new Boolval;
213 bval->setupUi(toFillin);
214 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
215 bval->checkBox->setText(paramName);
216 m_valueItems[paramName] = bval;
217 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
218 m_uiItems.append(bval);
219 } else if (type == "complex") {
220 /*QStringList names=nodeAtts.namedItem("name").nodeValue().split(';');
221 QStringList max=nodeAtts.namedItem("max").nodeValue().split(';');
222 QStringList min=nodeAtts.namedItem("min").nodeValue().split(';');
223 QStringList val=value.split(';');
224 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
225 if ( (names.size() == max.size() ) &&
226 (names.size()== min.size()) &&
227 (names.size()== val.size()) )
229 for (int i=0;i< names.size();i++){
230 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
233 ComplexParameter *pl = new ComplexParameter;
234 pl->setupParam(d, pa.attribute("name"), 0, 100);
235 m_vbox->addWidget(pl);
236 m_valueItems[paramName+"complex"] = pl;
237 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
239 } else if (type == "geometry") {
240 Geometryval *geo = new Geometryval(m_profile, m_frameSize);
241 geo->setupParam(pa, minFrame, maxFrame);
242 m_vbox->addWidget(geo);
243 m_valueItems[paramName+"geometry"] = geo;
244 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
245 connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int)));
247 } else if (type == "keyframe") {
248 // keyframe editor widget
249 kDebug() << "min: " << m_in << ", MAX: " << m_out;
250 KeyframeEdit *geo = new KeyframeEdit(pa, m_out - m_in, m_timecode);
251 //geo->setupParam(100, pa.attribute("min").toInt(), pa.attribute("max").toInt(), pa.attribute("keyframes"));
252 //connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int)));
253 //geo->setupParam(pa, minFrame, maxFrame);
254 m_vbox->addWidget(geo);
255 m_valueItems[paramName+"keyframe"] = geo;
256 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
258 } else if (type == "color") {
259 Colorval *cval = new Colorval;
260 cval->setupUi(toFillin);
262 if (value.startsWith('#')) value = value.replace('#', "0x");
263 cval->kcolorbutton->setColor(value.toUInt(&ok, 16));
264 //kDebug() << "color: " << value << ", " << value.toUInt(&ok, 16);
265 cval->label->setText(paramName);
266 m_valueItems[paramName] = cval;
267 connect(cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT(collectAllParameters()));
268 m_uiItems.append(cval);
269 } else if (type == "position") {
270 Positionval *pval = new Positionval;
271 pval->setupUi(toFillin);
272 int pos = value.toInt();
273 if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
275 } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
276 // fadeout position starts from clip end
277 pos = m_out - (pos - m_in);
279 pval->krestrictedline->setText(m_timecode.getTimecodeFromFrames(pos));
280 pval->label->setText(paramName);
281 m_valueItems[paramName + "position"] = pval;
282 connect(pval->krestrictedline, SIGNAL(editingFinished()), this, SLOT(collectAllParameters()));
283 m_uiItems.append(pval);
284 } else if (type == "wipe") {
285 Wipeval *wpval = new Wipeval;
286 wpval->setupUi(toFillin);
287 wipeInfo w = getWipeInfo(value);
290 wpval->start_up->setChecked(true);
293 wpval->start_down->setChecked(true);
296 wpval->start_right->setChecked(true);
299 wpval->start_left->setChecked(true);
302 wpval->start_center->setChecked(true);
307 wpval->end_up->setChecked(true);
310 wpval->end_down->setChecked(true);
313 wpval->end_right->setChecked(true);
316 wpval->end_left->setChecked(true);
319 wpval->end_center->setChecked(true);
322 wpval->start_transp->setValue(w.startTransparency);
323 wpval->end_transp->setValue(w.endTransparency);
324 m_valueItems[paramName] = wpval;
325 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
326 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
327 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
328 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
329 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
330 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
331 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
332 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
333 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
334 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
335 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
336 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
337 //wpval->title->setTitle(na.toElement().text());
338 m_uiItems.append(wpval);
345 m_items.append(toFillin);
346 m_vbox->addWidget(toFillin);
349 m_vbox->addStretch();
352 void EffectStackEdit::slotSeekToPos(int pos)
354 emit seekTimeline(m_in + pos);
357 wipeInfo EffectStackEdit::getWipeInfo(QString value)
360 QString start = value.section(';', 0, 0);
361 QString end = value.section(';', 1, 1).section('=', 1, 1);
362 if (start.startsWith("-100%,0")) info.start = LEFT;
363 else if (start.startsWith("100%,0")) info.start = RIGHT;
364 else if (start.startsWith("0%,100%")) info.start = DOWN;
365 else if (start.startsWith("0%,-100%")) info.start = UP;
366 else info.start = CENTER;
367 if (start.count(':') == 2) info.startTransparency = start.section(':', -1).toInt();
368 else info.startTransparency = 100;
370 if (end.startsWith("-100%,0")) info.end = LEFT;
371 else if (end.startsWith("100%,0")) info.end = RIGHT;
372 else if (end.startsWith("0%,100%")) info.end = DOWN;
373 else if (end.startsWith("0%,-100%")) info.end = UP;
374 else info.end = CENTER;
375 if (end.count(':') == 2) info.endTransparency = end.section(':', -1).toInt();
376 else info.endTransparency = 100;
380 QString EffectStackEdit::getWipeString(wipeInfo info)
385 switch (info.start) {
387 start = "-100%,0%:100%x100%";
390 start = "100%,0%:100%x100%";
393 start = "0%,100%:100%x100%";
396 start = "0%,-100%:100%x100%";
399 start = "0%,0%:100%x100%";
402 start.append(':' + QString::number(info.startTransparency));
406 end = "-100%,0%:100%x100%";
409 end = "100%,0%:100%x100%";
412 end = "0%,100%:100%x100%";
415 end = "0%,-100%:100%x100%";
418 end = "0%,0%:100%x100%";
421 end.append(':' + QString::number(info.endTransparency));
422 return QString(start + ";-1=" + end);
425 void EffectStackEdit::collectAllParameters()
427 if (m_valueItems.isEmpty()) return;
428 QDomElement oldparam = m_params.cloneNode().toElement();
429 QDomNodeList namenode = m_params.elementsByTagName("parameter");
431 for (int i = 0; i < namenode.count() ; i++) {
432 QDomNode pa = namenode.item(i);
433 QDomNode na = pa.firstChildElement("name");
434 QString type = pa.attributes().namedItem("type").nodeValue();
435 QString paramName = i18n(na.toElement().text().toUtf8().data());
436 if (type == "complex") paramName.append("complex");
437 else if (type == "position") paramName.append("position");
438 else if (type == "geometry") paramName.append("geometry");
439 if (!m_valueItems.contains(paramName)) {
440 kDebug() << "// Param: " << paramName << " NOT FOUND";
445 if (type == "double" || type == "constant") {
446 QSlider* slider = ((Constval*)m_valueItems.value(paramName))->horizontalSlider;
447 setValue = QString::number(slider->value());
448 } else if (type == "list") {
449 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
450 setValue = box->itemData(box->currentIndex()).toString();
451 } else if (type == "bool") {
452 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
453 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
454 } else if (type == "color") {
455 KColorButton *color = ((Colorval*)m_valueItems.value(paramName))->kcolorbutton;
456 setValue = color->color().name();
457 } else if (type == "complex") {
458 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
459 namenode.item(i) = complex->getParamDesc();
460 } else if (type == "geometry") {
461 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
462 namenode.item(i) = geom->getParamDesc();
463 } else if (type == "position") {
464 KRestrictedLine *line = ((Positionval*)m_valueItems.value(paramName))->krestrictedline;
465 int pos = m_timecode.getFrameCount(line->text(), KdenliveSettings::project_fps());
466 setValue = QString::number(pos);
467 if (m_params.attribute("id") == "fadein" || m_params.attribute("id") == "fade_from_black") {
468 // Make sure duration is not longer than clip
471 line->setText(m_timecode.getTimecodeFromFrames(pos));
473 EffectsList::setParameter(m_params, "in", QString::number(m_in));
474 EffectsList::setParameter(m_params, "out", QString::number(m_in + pos));
476 } else if (m_params.attribute("id") == "fadeout" || m_params.attribute("id") == "fade_to_black") {
477 // Make sure duration is not longer than clip
480 line->setText(m_timecode.getTimecodeFromFrames(pos));
482 EffectsList::setParameter(m_params, "in", QString::number(m_out + m_in - pos));
483 EffectsList::setParameter(m_params, "out", QString::number(m_out + m_in));
486 } else if (type == "wipe") {
487 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
489 if (wp->start_left->isChecked()) info.start = LEFT;
490 else if (wp->start_right->isChecked()) info.start = RIGHT;
491 else if (wp->start_up->isChecked()) info.start = UP;
492 else if (wp->start_down->isChecked()) info.start = DOWN;
493 else if (wp->start_center->isChecked()) info.start = CENTER;
494 else info.start = LEFT;
495 info.startTransparency = wp->start_transp->value();
496 if (wp->end_left->isChecked()) info.end = LEFT;
497 else if (wp->end_right->isChecked()) info.end = RIGHT;
498 else if (wp->end_up->isChecked()) info.end = UP;
499 else if (wp->end_down->isChecked()) info.end = DOWN;
500 else if (wp->end_center->isChecked()) info.end = CENTER;
501 else info.end = RIGHT;
502 info.endTransparency = wp->end_transp->value();
503 setValue = getWipeString(info);
506 if (!setValue.isNull()) {
507 pa.attributes().namedItem("value").setNodeValue(setValue);
510 emit parameterChanged(oldparam, m_params);
513 void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max)
515 QWidget* toFillin = new QWidget;
516 Constval *ctval = new Constval;
517 ctval->setupUi(toFillin);
518 ctval->horizontalSlider->setMinimum(min);
519 ctval->horizontalSlider->setMaximum(max);
520 ctval->spinBox->setMinimum(min);
521 ctval->spinBox->setMaximum(max);
522 ctval->horizontalSlider->setPageStep((int)(max - min) / 10);
523 ctval->horizontalSlider->setValue(val);
524 ctval->label->setText(name);
525 m_valueItems[name] = ctval;
526 m_uiItems.append(ctval);
527 connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters()));
528 m_items.append(toFillin);
529 m_vbox->addWidget(toFillin);
532 void EffectStackEdit::slotSliderMoved(int)
534 collectAllParameters();
537 void EffectStackEdit::clearAllItems()
540 m_valueItems.clear();
542 while (!m_items.isEmpty()) {
543 QWidget * die = m_items.takeFirst();
548 qDeleteAll(m_uiItems);
551 QLayoutItem *item = m_vbox->itemAt(0);
553 m_vbox->removeItem(item);
555 item = m_vbox->itemAt(0);