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 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 Wipeval: public EffectStackEdit::UiItem, public Ui::Wipeval_UI
65 QMap<QString, QImage> EffectStackEdit::iconCache;
67 EffectStackEdit::EffectStackEdit(QWidget *parent) :
73 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
74 QVBoxLayout *vbox1 = new QVBoxLayout(parent);
75 vbox1->setContentsMargins(0, 0, 0, 0);
78 QScrollArea *area = new QScrollArea;
79 QWidget *wid = new QWidget(parent);
80 area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
81 area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
82 area->setFrameStyle(QFrame::NoFrame);
83 wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
84 area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
86 vbox1->addWidget(area);
88 area->setWidgetResizable(true);
89 m_vbox = new QVBoxLayout(wid);
90 m_vbox->setContentsMargins(0, 0, 0, 0);
91 m_vbox->setSpacing(0);
96 EffectStackEdit::~EffectStackEdit()
101 void EffectStackEdit::setFrameSize(QPoint p)
104 QDomNodeList namenode = m_params.elementsByTagName("parameter");
105 for (int i = 0; i < namenode.count() ; i++) {
106 QDomNode pa = namenode.item(i);
107 QDomNode na = pa.firstChildElement("name");
108 QString type = pa.attributes().namedItem("type").nodeValue();
109 QString paramName = i18n(na.toElement().text().toUtf8().data());
111 if (type == "geometry") {
112 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
113 geom->setFrameSize(m_frameSize);
120 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
126 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
128 m_params.setAttribute(name, value);
131 void EffectStackEdit::transferParamDesc(const QDomElement d, int in, int out)
138 if (m_params.isNull()) return;
141 doc.appendChild(doc.importNode(m_params, true));
142 //kDebug() << "IMPORTED TRANS: " << doc.toString();
143 QDomNodeList namenode = m_params.elementsByTagName("parameter");
144 QDomElement e = m_params.toElement();
145 const int minFrame = e.attribute("start").toInt();
146 const int maxFrame = e.attribute("end").toInt();
149 for (int i = 0; i < namenode.count() ; i++) {
150 kDebug() << "in form";
151 QDomElement pa = namenode.item(i).toElement();
152 QDomNode na = pa.firstChildElement("name");
153 QString type = pa.attribute("type");
154 QString paramName = i18n(na.toElement().text().toUtf8().data());
155 QWidget * toFillin = new QWidget;
156 QString value = pa.attribute("value").isNull() ?
157 pa.attribute("default") : pa.attribute("value");
159 if (type == "geometry") {
160 /*pa.setAttribute("namedesc", "X;Y;Width;Height;Transparency");
161 pa.setAttribute("format", "%d%,%d%:%d%x%d%:%d");
162 pa.setAttribute("min", "-500;-500;0;0;0");
163 pa.setAttribute("max", "500;500;200;200;100");*/
164 } else if (type == "complex") {
165 //pa.setAttribute("namedesc",pa.attribute("name"));
170 //TODO constant, list, bool, complex , color, geometry, position
171 if (type == "double" || type == "constant") {
174 if (pa.attribute("min").startsWith('%')) {
175 min = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("min"));
176 } else min = pa.attribute("min").toInt();
177 if (pa.attribute("max").startsWith('%')) {
178 max = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("max"));
179 } else max = pa.attribute("max").toInt();
180 createSliderItem(paramName, (int)(value.toDouble() + 0.5) , min, max, pa.attribute("suffix", QString()));
183 } else if (type == "list") {
184 Listval *lsval = new Listval;
185 lsval->setupUi(toFillin);
186 QStringList listitems = pa.attribute("paramlist").split(',');
187 QStringList listitemsdisplay = pa.attribute("paramlistdisplay").split(',');
188 if (listitemsdisplay.count() != listitems.count()) listitemsdisplay = listitems;
189 //lsval->list->addItems(listitems);
190 lsval->list->setIconSize(QSize(30, 30));
191 for (int i = 0; i < listitems.count(); i++) {
192 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
193 QString entry = listitems.at(i);
194 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
195 if (!EffectStackEdit::iconCache.contains(entry)) {
197 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
199 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
202 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
203 lsval->title->setTitle(paramName);
204 m_valueItems[paramName] = lsval;
205 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
206 m_uiItems.append(lsval);
207 } else if (type == "bool") {
208 Boolval *bval = new Boolval;
209 bval->setupUi(toFillin);
210 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
211 bval->checkBox->setText(paramName);
212 m_valueItems[paramName] = bval;
213 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
214 m_uiItems.append(bval);
215 } else if (type == "complex") {
216 /*QStringList names=nodeAtts.namedItem("name").nodeValue().split(';');
217 QStringList max=nodeAtts.namedItem("max").nodeValue().split(';');
218 QStringList min=nodeAtts.namedItem("min").nodeValue().split(';');
219 QStringList val=value.split(';');
220 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
221 if ( (names.size() == max.size() ) &&
222 (names.size()== min.size()) &&
223 (names.size()== val.size()) )
225 for (int i=0;i< names.size();i++){
226 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
229 ComplexParameter *pl = new ComplexParameter;
230 pl->setupParam(d, pa.attribute("name"), 0, 100);
231 m_vbox->addWidget(pl);
232 m_valueItems[paramName+"complex"] = pl;
233 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
235 } else if (type == "geometry") {
236 Geometryval *geo = new Geometryval(m_profile, m_frameSize);
237 geo->setupParam(pa, minFrame, maxFrame);
238 m_vbox->addWidget(geo);
239 m_valueItems[paramName+"geometry"] = geo;
240 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
241 connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int)));
243 } else if (type == "keyframe") {
244 // keyframe editor widget
245 kDebug() << "min: " << m_in << ", MAX: " << m_out;
246 KeyframeEdit *geo = new KeyframeEdit(pa, m_out - m_in, pa.attribute("min").toInt(), pa.attribute("max").toInt(), m_timecode);
247 //geo->setupParam(100, pa.attribute("min").toInt(), pa.attribute("max").toInt(), pa.attribute("keyframes"));
248 //connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int)));
249 //geo->setupParam(pa, minFrame, maxFrame);
250 m_vbox->addWidget(geo);
251 m_valueItems[paramName+"keyframe"] = geo;
252 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
254 } else if (type == "color") {
255 Colorval *cval = new Colorval;
256 cval->setupUi(toFillin);
258 if (value.startsWith('#')) value = value.replace('#', "0x");
259 cval->kcolorbutton->setColor(value.toUInt(&ok, 16));
260 //kDebug() << "color: " << value << ", " << value.toUInt(&ok, 16);
261 cval->label->setText(paramName);
262 m_valueItems[paramName] = cval;
263 connect(cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT(collectAllParameters()));
264 m_uiItems.append(cval);
265 } else if (type == "position") {
266 int pos = value.toInt();
267 if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
269 } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
270 // fadeout position starts from clip end
271 pos = m_out - (pos - m_in);
273 PositionEdit *posedit = new PositionEdit(paramName, pos, 1, m_out, m_timecode);
274 m_vbox->addWidget(posedit);
275 m_valueItems[paramName+"position"] = posedit;
276 connect(posedit, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
277 m_items.append(posedit);
278 } else if (type == "wipe") {
279 Wipeval *wpval = new Wipeval;
280 wpval->setupUi(toFillin);
281 wipeInfo w = getWipeInfo(value);
284 wpval->start_up->setChecked(true);
287 wpval->start_down->setChecked(true);
290 wpval->start_right->setChecked(true);
293 wpval->start_left->setChecked(true);
296 wpval->start_center->setChecked(true);
301 wpval->end_up->setChecked(true);
304 wpval->end_down->setChecked(true);
307 wpval->end_right->setChecked(true);
310 wpval->end_left->setChecked(true);
313 wpval->end_center->setChecked(true);
316 wpval->start_transp->setValue(w.startTransparency);
317 wpval->end_transp->setValue(w.endTransparency);
318 m_valueItems[paramName] = wpval;
319 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
320 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
321 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
322 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
323 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
324 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
325 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
326 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
327 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
328 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
329 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
330 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
331 //wpval->title->setTitle(na.toElement().text());
332 m_uiItems.append(wpval);
339 m_items.append(toFillin);
340 m_vbox->addWidget(toFillin);
343 m_vbox->addStretch();
346 void EffectStackEdit::slotSeekToPos(int pos)
348 emit seekTimeline(m_in + pos);
351 wipeInfo EffectStackEdit::getWipeInfo(QString value)
354 QString start = value.section(';', 0, 0);
355 QString end = value.section(';', 1, 1).section('=', 1, 1);
356 if (start.startsWith("-100%,0")) info.start = LEFT;
357 else if (start.startsWith("100%,0")) info.start = RIGHT;
358 else if (start.startsWith("0%,100%")) info.start = DOWN;
359 else if (start.startsWith("0%,-100%")) info.start = UP;
360 else info.start = CENTER;
361 if (start.count(':') == 2) info.startTransparency = start.section(':', -1).toInt();
362 else info.startTransparency = 100;
364 if (end.startsWith("-100%,0")) info.end = LEFT;
365 else if (end.startsWith("100%,0")) info.end = RIGHT;
366 else if (end.startsWith("0%,100%")) info.end = DOWN;
367 else if (end.startsWith("0%,-100%")) info.end = UP;
368 else info.end = CENTER;
369 if (end.count(':') == 2) info.endTransparency = end.section(':', -1).toInt();
370 else info.endTransparency = 100;
374 QString EffectStackEdit::getWipeString(wipeInfo info)
379 switch (info.start) {
381 start = "-100%,0%:100%x100%";
384 start = "100%,0%:100%x100%";
387 start = "0%,100%:100%x100%";
390 start = "0%,-100%:100%x100%";
393 start = "0%,0%:100%x100%";
396 start.append(':' + QString::number(info.startTransparency));
400 end = "-100%,0%:100%x100%";
403 end = "100%,0%:100%x100%";
406 end = "0%,100%:100%x100%";
409 end = "0%,-100%:100%x100%";
412 end = "0%,0%:100%x100%";
415 end.append(':' + QString::number(info.endTransparency));
416 return QString(start + ";-1=" + end);
419 void EffectStackEdit::collectAllParameters()
421 if (m_valueItems.isEmpty()) return;
422 QDomElement oldparam = m_params.cloneNode().toElement();
423 QDomNodeList namenode = m_params.elementsByTagName("parameter");
425 for (int i = 0; i < namenode.count() ; i++) {
426 QDomNode pa = namenode.item(i);
427 QDomNode na = pa.firstChildElement("name");
428 QString type = pa.attributes().namedItem("type").nodeValue();
429 QString paramName = i18n(na.toElement().text().toUtf8().data());
430 if (type == "complex") paramName.append("complex");
431 else if (type == "position") paramName.append("position");
432 else if (type == "geometry") paramName.append("geometry");
433 else if (type == "keyframe") paramName.append("keyframe");
434 if (!m_valueItems.contains(paramName)) {
435 kDebug() << "// Param: " << paramName << " NOT FOUND";
440 if (type == "double" || type == "constant") {
441 QSlider* slider = ((Constval*)m_valueItems.value(paramName))->horizontalSlider;
442 setValue = QString::number(slider->value());
443 } else if (type == "list") {
444 KComboBox *box = ((Listval*)m_valueItems.value(paramName))->list;
445 setValue = box->itemData(box->currentIndex()).toString();
446 } else if (type == "bool") {
447 QCheckBox *box = ((Boolval*)m_valueItems.value(paramName))->checkBox;
448 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
449 } else if (type == "color") {
450 KColorButton *color = ((Colorval*)m_valueItems.value(paramName))->kcolorbutton;
451 setValue = color->color().name();
452 } else if (type == "complex") {
453 ComplexParameter *complex = ((ComplexParameter*)m_valueItems.value(paramName));
454 namenode.item(i) = complex->getParamDesc();
455 } else if (type == "geometry") {
456 Geometryval *geom = ((Geometryval*)m_valueItems.value(paramName));
457 namenode.item(i) = geom->getParamDesc();
458 } else if (type == "position") {
459 PositionEdit *pedit = ((PositionEdit*)m_valueItems.value(paramName));
460 int pos = pedit->getPosition();
461 setValue = QString::number(pos);
462 if (m_params.attribute("id") == "fadein" || m_params.attribute("id") == "fade_from_black") {
463 // Make sure duration is not longer than clip
466 pedit->setPosition(pos);
468 EffectsList::setParameter(m_params, "in", QString::number(m_in));
469 EffectsList::setParameter(m_params, "out", QString::number(m_in + pos));
471 } else if (m_params.attribute("id") == "fadeout" || m_params.attribute("id") == "fade_to_black") {
472 // Make sure duration is not longer than clip
475 pedit->setPosition(pos);
477 EffectsList::setParameter(m_params, "in", QString::number(m_out + m_in - pos));
478 EffectsList::setParameter(m_params, "out", QString::number(m_out + m_in));
481 } else if (type == "wipe") {
482 Wipeval *wp = (Wipeval*)m_valueItems.value(paramName);
484 if (wp->start_left->isChecked()) info.start = LEFT;
485 else if (wp->start_right->isChecked()) info.start = RIGHT;
486 else if (wp->start_up->isChecked()) info.start = UP;
487 else if (wp->start_down->isChecked()) info.start = DOWN;
488 else if (wp->start_center->isChecked()) info.start = CENTER;
489 else info.start = LEFT;
490 info.startTransparency = wp->start_transp->value();
491 if (wp->end_left->isChecked()) info.end = LEFT;
492 else if (wp->end_right->isChecked()) info.end = RIGHT;
493 else if (wp->end_up->isChecked()) info.end = UP;
494 else if (wp->end_down->isChecked()) info.end = DOWN;
495 else if (wp->end_center->isChecked()) info.end = CENTER;
496 else info.end = RIGHT;
497 info.endTransparency = wp->end_transp->value();
498 setValue = getWipeString(info);
501 if (!setValue.isNull()) {
502 pa.attributes().namedItem("value").setNodeValue(setValue);
505 emit parameterChanged(oldparam, m_params);
508 void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max, const QString suffix)
510 QWidget* toFillin = new QWidget;
511 Constval *ctval = new Constval;
512 ctval->setupUi(toFillin);
513 ctval->horizontalSlider->setMinimum(min);
514 ctval->horizontalSlider->setMaximum(max);
515 if (!suffix.isEmpty()) ctval->spinBox->setSuffix(suffix);
516 ctval->spinBox->setMinimum(min);
517 ctval->spinBox->setMaximum(max);
518 ctval->horizontalSlider->setPageStep((int)(max - min) / 10);
519 ctval->horizontalSlider->setValue(val);
520 ctval->label->setText(name);
521 m_valueItems[name] = ctval;
522 m_uiItems.append(ctval);
523 connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters()));
524 m_items.append(toFillin);
525 m_vbox->addWidget(toFillin);
528 void EffectStackEdit::slotSliderMoved(int)
530 collectAllParameters();
533 void EffectStackEdit::clearAllItems()
536 m_valueItems.clear();
538 while (!m_items.isEmpty()) {
539 QWidget * die = m_items.takeFirst();
544 qDeleteAll(m_uiItems);
547 QLayoutItem *item = m_vbox->itemAt(0);
549 m_vbox->removeItem(item);
551 item = m_vbox->itemAt(0);