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>
47 class Boolval: public EffectStackEdit::UiItem, public Ui::Boolval_UI
51 class Colorval: public EffectStackEdit::UiItem, public Ui::Colorval_UI
55 class Constval: public EffectStackEdit::UiItem, public Ui::Constval_UI
59 class Listval: public EffectStackEdit::UiItem, public Ui::Listval_UI
63 class Wipeval: public EffectStackEdit::UiItem, public Ui::Wipeval_UI
68 QMap<QString, QImage> EffectStackEdit::iconCache;
70 EffectStackEdit::EffectStackEdit(QWidget *parent) :
76 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
77 QVBoxLayout *vbox1 = new QVBoxLayout(parent);
78 vbox1->setContentsMargins(0, 0, 0, 0);
81 QScrollArea *area = new QScrollArea;
82 QWidget *wid = new QWidget(parent);
83 area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
84 area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
85 area->setFrameStyle(QFrame::NoFrame);
86 wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
87 area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
89 vbox1->addWidget(area);
91 area->setWidgetResizable(true);
92 m_vbox = new QVBoxLayout(wid);
93 m_vbox->setContentsMargins(0, 0, 0, 0);
94 m_vbox->setSpacing(0);
99 EffectStackEdit::~EffectStackEdit()
104 void EffectStackEdit::setFrameSize(QPoint p)
107 QDomNodeList namenode = m_params.elementsByTagName("parameter");
108 for (int i = 0; i < namenode.count() ; i++) {
109 QDomNode pa = namenode.item(i);
110 QDomNode na = pa.firstChildElement("name");
111 QString type = pa.attributes().namedItem("type").nodeValue();
112 QString paramName = i18n(na.toElement().text().toUtf8().data());
114 if (type == "geometry") {
115 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
116 geom->setFrameSize(m_frameSize);
123 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
129 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
131 m_params.setAttribute(name, value);
134 void EffectStackEdit::transferParamDesc(const QDomElement d, int in, int out)
136 kDebug() << " + + + +DELETING EFFECT STACK";
142 if (m_params.isNull()) {
148 doc.appendChild(doc.importNode(m_params, true));
149 //kDebug() << "IMPORTED TRANS: " << doc.toString();
150 QDomNodeList namenode = m_params.elementsByTagName("parameter");
151 QDomElement e = m_params.toElement();
152 const int minFrame = e.attribute("start").toInt();
153 const int maxFrame = e.attribute("end").toInt();
156 for (int i = 0; i < namenode.count() ; i++) {
157 kDebug() << "in form";
158 QDomElement pa = namenode.item(i).toElement();
159 QDomNode na = pa.firstChildElement("name");
160 QString type = pa.attribute("type");
161 QString paramName = i18n(na.toElement().text().toUtf8().data());
162 QWidget * toFillin = new QWidget;
163 QString value = pa.attribute("value").isNull() ?
164 pa.attribute("default") : pa.attribute("value");
166 if (type == "geometry") {
167 /*pa.setAttribute("namedesc", "X;Y;Width;Height;Transparency");
168 pa.setAttribute("format", "%d%,%d%:%d%x%d%:%d");
169 pa.setAttribute("min", "-500;-500;0;0;0");
170 pa.setAttribute("max", "500;500;200;200;100");*/
171 } else if (type == "complex") {
172 //pa.setAttribute("namedesc",pa.attribute("name"));
177 //TODO constant, list, bool, complex , color, geometry, position
178 if (type == "double" || type == "constant") {
181 if (pa.attribute("min").startsWith('%')) {
182 min = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("min"));
183 } else min = pa.attribute("min").toInt();
184 if (pa.attribute("max").startsWith('%')) {
185 max = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("max"));
186 } else max = pa.attribute("max").toInt();
187 createSliderItem(paramName, (int)(value.toDouble() + 0.5) , min, max, pa.attribute("suffix", QString()));
190 } else if (type == "list") {
191 Listval *lsval = new Listval;
192 lsval->setupUi(toFillin);
193 QStringList listitems = pa.attribute("paramlist").split(',');
194 QStringList listitemsdisplay = pa.attribute("paramlistdisplay").split(',');
195 if (listitemsdisplay.count() != listitems.count()) listitemsdisplay = listitems;
196 //lsval->list->addItems(listitems);
197 lsval->list->setIconSize(QSize(30, 30));
198 for (int i = 0; i < listitems.count(); i++) {
199 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
200 QString entry = listitems.at(i);
201 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
202 if (!EffectStackEdit::iconCache.contains(entry)) {
204 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
206 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
209 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
210 lsval->title->setTitle(paramName);
211 m_valueItems[paramName] = lsval;
212 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
213 m_uiItems.append(lsval);
214 } else if (type == "bool") {
215 Boolval *bval = new Boolval;
216 bval->setupUi(toFillin);
217 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
218 bval->checkBox->setText(paramName);
219 m_valueItems[paramName] = bval;
220 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
221 m_uiItems.append(bval);
222 } else if (type == "complex") {
223 /*QStringList names=nodeAtts.namedItem("name").nodeValue().split(';');
224 QStringList max=nodeAtts.namedItem("max").nodeValue().split(';');
225 QStringList min=nodeAtts.namedItem("min").nodeValue().split(';');
226 QStringList val=value.split(';');
227 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
228 if ( (names.size() == max.size() ) &&
229 (names.size()== min.size()) &&
230 (names.size()== val.size()) )
232 for (int i=0;i< names.size();i++){
233 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
236 ComplexParameter *pl = new ComplexParameter;
237 pl->setupParam(d, pa.attribute("name"), 0, 100);
238 m_vbox->addWidget(pl);
239 m_valueItems[paramName+"complex"] = pl;
240 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
242 } else if (type == "geometry") {
243 Geometryval *geo = new Geometryval(m_profile, m_frameSize);
244 geo->setupParam(pa, minFrame, maxFrame);
245 m_vbox->addWidget(geo);
246 m_valueItems[paramName+"geometry"] = geo;
247 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
248 connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int)));
250 } else if (type == "keyframe") {
251 //Â keyframe editor widget
252 kDebug() << "min: " << m_in << ", MAX: " << m_out;
253 KeyframeEdit *geo = new KeyframeEdit(pa, m_out - m_in, pa.attribute("min").toInt(), pa.attribute("max").toInt(), m_timecode);
254 //geo->setupParam(100, pa.attribute("min").toInt(), pa.attribute("max").toInt(), pa.attribute("keyframes"));
255 //connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int)));
256 //geo->setupParam(pa, minFrame, maxFrame);
257 m_vbox->addWidget(geo);
258 m_valueItems[paramName+"keyframe"] = geo;
259 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
261 } else if (type == "color") {
262 Colorval *cval = new Colorval;
263 cval->setupUi(toFillin);
265 if (value.startsWith('#')) value = value.replace('#', "0x");
266 cval->kcolorbutton->setColor(value.toUInt(&ok, 16));
267 //kDebug() << "color: " << value << ", " << value.toUInt(&ok, 16);
268 cval->label->setText(paramName);
269 m_valueItems[paramName] = cval;
270 connect(cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT(collectAllParameters()));
271 m_uiItems.append(cval);
272 } else if (type == "position") {
273 int pos = value.toInt();
274 if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
276 } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
277 // fadeout position starts from clip end
278 pos = m_out - (pos - m_in);
280 PositionEdit *posedit = new PositionEdit(paramName, pos, 1, m_out, m_timecode);
281 m_vbox->addWidget(posedit);
282 m_valueItems[paramName+"position"] = posedit;
283 connect(posedit, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
284 m_items.append(posedit);
285 } else if (type == "wipe") {
286 Wipeval *wpval = new Wipeval;
287 wpval->setupUi(toFillin);
288 wipeInfo w = getWipeInfo(value);
291 wpval->start_up->setChecked(true);
294 wpval->start_down->setChecked(true);
297 wpval->start_right->setChecked(true);
300 wpval->start_left->setChecked(true);
303 wpval->start_center->setChecked(true);
308 wpval->end_up->setChecked(true);
311 wpval->end_down->setChecked(true);
314 wpval->end_right->setChecked(true);
317 wpval->end_left->setChecked(true);
320 wpval->end_center->setChecked(true);
323 wpval->start_transp->setValue(w.startTransparency);
324 wpval->end_transp->setValue(w.endTransparency);
325 m_valueItems[paramName] = wpval;
326 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
327 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
328 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
329 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
330 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
331 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
332 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
333 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
334 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
335 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
336 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
337 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
338 //wpval->title->setTitle(na.toElement().text());
339 m_uiItems.append(wpval);
346 m_items.append(toFillin);
347 m_vbox->addWidget(toFillin);
350 m_vbox->addStretch();
354 void EffectStackEdit::slotSeekToPos(int pos)
356 emit seekTimeline(m_in + pos);
359 wipeInfo EffectStackEdit::getWipeInfo(QString value)
362 QString start = value.section(';', 0, 0);
363 QString end = value.section(';', 1, 1).section('=', 1, 1);
364 if (start.startsWith("-100%,0")) info.start = LEFT;
365 else if (start.startsWith("100%,0")) info.start = RIGHT;
366 else if (start.startsWith("0%,100%")) info.start = DOWN;
367 else if (start.startsWith("0%,-100%")) info.start = UP;
368 else info.start = CENTER;
369 if (start.count(':') == 2) info.startTransparency = start.section(':', -1).toInt();
370 else info.startTransparency = 100;
372 if (end.startsWith("-100%,0")) info.end = LEFT;
373 else if (end.startsWith("100%,0")) info.end = RIGHT;
374 else if (end.startsWith("0%,100%")) info.end = DOWN;
375 else if (end.startsWith("0%,-100%")) info.end = UP;
376 else info.end = CENTER;
377 if (end.count(':') == 2) info.endTransparency = end.section(':', -1).toInt();
378 else info.endTransparency = 100;
382 QString EffectStackEdit::getWipeString(wipeInfo info)
387 switch (info.start) {
389 start = "-100%,0%:100%x100%";
392 start = "100%,0%:100%x100%";
395 start = "0%,100%:100%x100%";
398 start = "0%,-100%:100%x100%";
401 start = "0%,0%:100%x100%";
404 start.append(':' + QString::number(info.startTransparency));
408 end = "-100%,0%:100%x100%";
411 end = "100%,0%:100%x100%";
414 end = "0%,100%:100%x100%";
417 end = "0%,-100%:100%x100%";
420 end = "0%,0%:100%x100%";
423 end.append(':' + QString::number(info.endTransparency));
424 return QString(start + ";-1=" + end);
427 void EffectStackEdit::collectAllParameters()
429 if (m_valueItems.isEmpty()) return;
431 // Make sure we don't modify params
433 QDomElement oldparam = m_params.cloneNode().toElement();
434 QDomNodeList namenode = m_params.elementsByTagName("parameter");
436 for (int i = 0; i < namenode.count() ; i++) {
437 QDomNode pa = namenode.item(i);
438 QDomNode na = pa.firstChildElement("name");
439 QString type = pa.attributes().namedItem("type").nodeValue();
440 QString paramName = i18n(na.toElement().text().toUtf8().data());
441 if (type == "complex") paramName.append("complex");
442 else if (type == "position") paramName.append("position");
443 else if (type == "geometry") paramName.append("geometry");
444 else if (type == "keyframe") paramName.append("keyframe");
445 if (!m_valueItems.contains(paramName)) {
446 kDebug() << "// Param: " << paramName << " NOT FOUND";
451 if (type == "double" || type == "constant") {
452 QSlider* slider = ((Constval*)m_valueItems.value(paramName))->horizontalSlider;
453 setValue = QString::number(slider->value());
454 } else if (type == "list") {
455 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
456 setValue = box->itemData(box->currentIndex()).toString();
457 } else if (type == "bool") {
458 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
459 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
460 } else if (type == "color") {
461 KColorButton *color = ((Colorval*)m_valueItems.value(paramName))->kcolorbutton;
462 setValue = color->color().name();
463 } else if (type == "complex") {
464 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
465 namenode.item(i) = complex->getParamDesc();
466 } else if (type == "geometry") {
467 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
468 namenode.item(i) = geom->getParamDesc();
469 } else if (type == "position") {
470 PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
471 int pos = pedit->getPosition();
472 setValue = QString::number(pos);
473 if (m_params.attribute("id") == "fadein" || m_params.attribute("id") == "fade_from_black") {
474 // Make sure duration is not longer than clip
477 pedit->setPosition(pos);
479 EffectsList::setParameter(m_params, "in", QString::number(m_in));
480 EffectsList::setParameter(m_params, "out", QString::number(m_in + pos));
482 } else if (m_params.attribute("id") == "fadeout" || m_params.attribute("id") == "fade_to_black") {
483 // Make sure duration is not longer than clip
486 pedit->setPosition(pos);
488 EffectsList::setParameter(m_params, "in", QString::number(m_out + m_in - pos));
489 EffectsList::setParameter(m_params, "out", QString::number(m_out + m_in));
492 } else if (type == "wipe") {
493 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
495 if (wp->start_left->isChecked()) info.start = LEFT;
496 else if (wp->start_right->isChecked()) info.start = RIGHT;
497 else if (wp->start_up->isChecked()) info.start = UP;
498 else if (wp->start_down->isChecked()) info.start = DOWN;
499 else if (wp->start_center->isChecked()) info.start = CENTER;
500 else info.start = LEFT;
501 info.startTransparency = wp->start_transp->value();
502 if (wp->end_left->isChecked()) info.end = LEFT;
503 else if (wp->end_right->isChecked()) info.end = RIGHT;
504 else if (wp->end_up->isChecked()) info.end = UP;
505 else if (wp->end_down->isChecked()) info.end = DOWN;
506 else if (wp->end_center->isChecked()) info.end = CENTER;
507 else info.end = RIGHT;
508 info.endTransparency = wp->end_transp->value();
509 setValue = getWipeString(info);
512 if (!setValue.isNull()) {
513 pa.attributes().namedItem("value").setNodeValue(setValue);
516 emit parameterChanged(oldparam, m_params);
520 void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max, const QString suffix)
522 QWidget* toFillin = new QWidget;
523 Constval *ctval = new Constval;
524 ctval->setupUi(toFillin);
525 ctval->horizontalSlider->setMinimum(min);
526 ctval->horizontalSlider->setMaximum(max);
527 if (!suffix.isEmpty()) ctval->spinBox->setSuffix(suffix);
528 ctval->spinBox->setMinimum(min);
529 ctval->spinBox->setMaximum(max);
530 ctval->horizontalSlider->setPageStep((int)(max - min) / 10);
531 ctval->horizontalSlider->setValue(val);
532 ctval->label->setText(name);
533 m_valueItems[name] = ctval;
534 m_uiItems.append(ctval);
535 connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters()));
536 m_items.append(toFillin);
537 m_vbox->addWidget(toFillin);
540 void EffectStackEdit::slotSliderMoved(int)
542 collectAllParameters();
545 void EffectStackEdit::clearAllItems()
548 m_valueItems.clear();
550 while (!m_items.isEmpty()) {
551 QWidget * die = m_items.takeFirst();
556 qDeleteAll(m_uiItems);
559 QLayoutItem *item = m_vbox->itemAt(0);
561 m_vbox->removeItem(item);
563 item = m_vbox->itemAt(0);