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 "complexparameter.h"
26 #include "geometryval.h"
27 #include "effectslist.h"
28 #include "kdenlivesettings.h"
33 #include <QVBoxLayout>
36 #include <QPushButton>
38 #include <QScrollArea>
41 class Boolval: public EffectStackEdit::UiItem, public Ui::Boolval_UI
45 class Colorval: public EffectStackEdit::UiItem, public Ui::Colorval_UI
49 class Constval: public EffectStackEdit::UiItem, public Ui::Constval_UI
53 class Listval: public EffectStackEdit::UiItem, public Ui::Listval_UI
57 class Positionval: public EffectStackEdit::UiItem, public Ui::Positionval_UI
61 class Wipeval: public EffectStackEdit::UiItem, public Ui::Wipeval_UI
66 QMap<QString, QImage> EffectStackEdit::iconCache;
68 EffectStackEdit::EffectStackEdit(QWidget *parent) :
74 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
75 QVBoxLayout *vbox1 = new QVBoxLayout(parent);
76 vbox1->setContentsMargins(0, 0, 0, 0);
79 QScrollArea *area = new QScrollArea;
80 QWidget *wid = new QWidget(parent);
81 area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
82 area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
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");
158 if (type == "geometry") {
159 /*pa.setAttribute("namedesc", "X;Y;Width;Height;Transparency");
160 pa.setAttribute("format", "%d%,%d%:%d%x%d%:%d");
161 pa.setAttribute("min", "-500;-500;0;0;0");
162 pa.setAttribute("max", "500;500;200;200;100");*/
163 } else if (type == "complex") {
164 //pa.setAttribute("namedesc",pa.attribute("name"));
169 //TODO constant, list, bool, complex , color, geometry, position
170 if (type == "double" || type == "constant") {
171 createSliderItem(paramName, value.toInt(), pa.attribute("min").toInt(), pa.attribute("max").toInt());
174 } else if (type == "list") {
175 Listval *lsval = new Listval;
176 lsval->setupUi(toFillin);
177 QStringList listitems = pa.attribute("paramlist").split(',');
178 QStringList listitemsdisplay = pa.attribute("paramlistdisplay").split(',');
179 if (listitemsdisplay.count() != listitems.count()) listitemsdisplay = listitems;
180 //lsval->list->addItems(listitems);
181 lsval->list->setIconSize(QSize(30, 30));
182 for (int i = 0;i < listitems.count();i++) {
183 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
184 QString entry = listitems.at(i);
185 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
186 if (!EffectStackEdit::iconCache.contains(entry)) {
188 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
190 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
193 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
195 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
196 lsval->title->setTitle(paramName);
197 m_valueItems[paramName] = lsval;
198 m_uiItems.append(lsval);
199 } else if (type == "bool") {
200 Boolval *bval = new Boolval;
201 bval->setupUi(toFillin);
202 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
204 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
205 bval->checkBox->setText(paramName);
206 m_valueItems[paramName] = bval;
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 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
224 pl->setupParam(d, pa.attribute("name"), 0, 100);
225 m_vbox->addWidget(pl);
226 m_valueItems[paramName+"complex"] = pl;
228 } else if (type == "geometry") {
229 Geometryval *geo = new Geometryval(m_profile, m_frameSize);
230 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
231 connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int)));
232 geo->setupParam(pa, minFrame, maxFrame);
233 m_vbox->addWidget(geo);
234 m_valueItems[paramName+"geometry"] = geo;
236 } else if (type == "color") {
237 Colorval *cval = new Colorval;
238 cval->setupUi(toFillin);
240 if (value.startsWith('#')) value = value.replace('#', "0x");
241 cval->kcolorbutton->setColor(value.toUInt(&ok, 16));
242 //kDebug() << "color: " << value << ", " << value.toUInt(&ok, 16);
244 connect(cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT(collectAllParameters()));
245 cval->label->setText(paramName);
246 m_valueItems[paramName] = cval;
247 m_uiItems.append(cval);
248 } else if (type == "position") {
249 Positionval *pval = new Positionval;
250 pval->setupUi(toFillin);
251 int pos = value.toInt();
252 if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
254 } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
255 // fadeout position starts from clip end
256 pos = m_out - (pos - m_in);
258 pval->krestrictedline->setText(m_timecode.getTimecodeFromFrames(pos));
259 connect(pval->krestrictedline, SIGNAL(editingFinished()), this, SLOT(collectAllParameters()));
260 pval->label->setText(paramName);
261 m_valueItems[paramName + "position"] = pval;
262 m_uiItems.append(pval);
263 } else if (type == "wipe") {
264 Wipeval *wpval = new Wipeval;
265 wpval->setupUi(toFillin);
266 wipeInfo w = getWipeInfo(value);
269 wpval->start_up->setChecked(true);
272 wpval->start_down->setChecked(true);
275 wpval->start_right->setChecked(true);
278 wpval->start_left->setChecked(true);
281 wpval->start_center->setChecked(true);
286 wpval->end_up->setChecked(true);
289 wpval->end_down->setChecked(true);
292 wpval->end_right->setChecked(true);
295 wpval->end_left->setChecked(true);
298 wpval->end_center->setChecked(true);
301 wpval->start_transp->setValue(w.startTransparency);
302 wpval->end_transp->setValue(w.endTransparency);
304 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
305 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
306 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
307 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
308 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
309 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
310 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
311 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
312 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
313 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
314 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
315 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
316 //wpval->title->setTitle(na.toElement().text());
317 m_valueItems[paramName] = wpval;
318 m_uiItems.append(wpval);
325 m_items.append(toFillin);
326 m_vbox->addWidget(toFillin);
329 m_vbox->addStretch();
332 void EffectStackEdit::slotSeekToPos(int pos)
334 emit seekTimeline(m_in + pos);
337 wipeInfo EffectStackEdit::getWipeInfo(QString value)
340 QString start = value.section(';', 0, 0);
341 QString end = value.section(';', 1, 1).section('=', 1, 1);
342 if (start.startsWith("-100%,0")) info.start = LEFT;
343 else if (start.startsWith("100%,0")) info.start = RIGHT;
344 else if (start.startsWith("0%,100%")) info.start = DOWN;
345 else if (start.startsWith("0%,-100%")) info.start = UP;
346 else info.start = CENTER;
347 if (start.count(':') == 2) info.startTransparency = start.section(':', -1).toInt();
348 else info.startTransparency = 100;
350 if (end.startsWith("-100%,0")) info.end = LEFT;
351 else if (end.startsWith("100%,0")) info.end = RIGHT;
352 else if (end.startsWith("0%,100%")) info.end = DOWN;
353 else if (end.startsWith("0%,-100%")) info.end = UP;
354 else info.end = CENTER;
355 if (end.count(':') == 2) info.endTransparency = end.section(':', -1).toInt();
356 else info.endTransparency = 100;
360 QString EffectStackEdit::getWipeString(wipeInfo info)
365 switch (info.start) {
367 start = "-100%,0%:100%x100%";
370 start = "100%,0%:100%x100%";
373 start = "0%,100%:100%x100%";
376 start = "0%,-100%:100%x100%";
379 start = "0%,0%:100%x100%";
382 start.append(':' + QString::number(info.startTransparency));
386 end = "-100%,0%:100%x100%";
389 end = "100%,0%:100%x100%";
392 end = "0%,100%:100%x100%";
395 end = "0%,-100%:100%x100%";
398 end = "0%,0%:100%x100%";
401 end.append(':' + QString::number(info.endTransparency));
402 return QString(start + ";-1=" + end);
405 void EffectStackEdit::collectAllParameters()
407 QDomElement oldparam = m_params.cloneNode().toElement();
408 QDomNodeList namenode = m_params.elementsByTagName("parameter");
410 for (int i = 0;i < namenode.count() ;i++) {
411 QDomNode pa = namenode.item(i);
412 QDomNode na = pa.firstChildElement("name");
413 QString type = pa.attributes().namedItem("type").nodeValue();
414 QString paramName = i18n(na.toElement().text().toUtf8().data());
417 if (type == "double" || type == "constant") {
418 QSlider* slider = ((Constval*)m_valueItems[paramName])->horizontalSlider;
419 setValue = QString::number(slider->value());
420 } else if (type == "list") {
421 KComboBox *box = ((Listval*)m_valueItems[paramName])->list;
422 setValue = box->itemData(box->currentIndex()).toString();
423 } else if (type == "bool") {
424 QCheckBox *box = ((Boolval*)m_valueItems[paramName])->checkBox;
425 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
426 } else if (type == "color") {
427 KColorButton *color = ((Colorval*)m_valueItems[paramName])->kcolorbutton;
428 setValue = color->color().name();
429 } else if (type == "complex") {
430 ComplexParameter *complex = ((ComplexParameter*)m_valueItems[paramName+"complex"]);
431 namenode.item(i) = complex->getParamDesc();
432 } else if (type == "geometry") {
433 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
434 namenode.item(i) = geom->getParamDesc();
435 } else if (type == "position") {
436 KRestrictedLine *line = ((Positionval*)m_valueItems[paramName+"position"])->krestrictedline;
437 int pos = m_timecode.getFrameCount(line->text(), KdenliveSettings::project_fps());
438 setValue = QString::number(pos);
439 if (m_params.attribute("id") == "fadein" || m_params.attribute("id") == "fade_from_black") {
440 // Make sure duration is not longer than clip
443 line->setText(m_timecode.getTimecodeFromFrames(pos));
445 EffectsList::setParameter(m_params, "in", QString::number(m_in));
446 EffectsList::setParameter(m_params, "out", QString::number(m_in + pos));
448 } else if (m_params.attribute("id") == "fadeout" || m_params.attribute("id") == "fade_to_black") {
449 // Make sure duration is not longer than clip
452 line->setText(m_timecode.getTimecodeFromFrames(pos));
454 EffectsList::setParameter(m_params, "in", QString::number(m_out + m_in - pos));
455 EffectsList::setParameter(m_params, "out", QString::number(m_out + m_in));
458 } else if (type == "wipe") {
459 Wipeval *wp = (Wipeval*)m_valueItems[paramName];
461 if (wp->start_left->isChecked()) info.start = LEFT;
462 else if (wp->start_right->isChecked()) info.start = RIGHT;
463 else if (wp->start_up->isChecked()) info.start = UP;
464 else if (wp->start_down->isChecked()) info.start = DOWN;
465 else if (wp->start_center->isChecked()) info.start = CENTER;
466 else info.start = LEFT;
467 info.startTransparency = wp->start_transp->value();
468 if (wp->end_left->isChecked()) info.end = LEFT;
469 else if (wp->end_right->isChecked()) info.end = RIGHT;
470 else if (wp->end_up->isChecked()) info.end = UP;
471 else if (wp->end_down->isChecked()) info.end = DOWN;
472 else if (wp->end_center->isChecked()) info.end = CENTER;
473 else info.end = RIGHT;
474 info.endTransparency = wp->end_transp->value();
475 setValue = getWipeString(info);
478 if (!setValue.isNull()) {
479 pa.attributes().namedItem("value").setNodeValue(setValue);
482 emit parameterChanged(oldparam, m_params);
485 void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max)
487 QWidget* toFillin = new QWidget;
488 Constval *ctval = new Constval;
489 ctval->setupUi(toFillin);
491 ctval->horizontalSlider->setMinimum(min);
492 ctval->horizontalSlider->setMaximum(max);
493 ctval->spinBox->setMinimum(min);
494 ctval->spinBox->setMaximum(max);
495 ctval->horizontalSlider->setPageStep((int)(max - min) / 10);
496 ctval->horizontalSlider->setValue(val);
497 ctval->label->setText(name);
498 m_valueItems[name] = ctval;
499 m_uiItems.append(ctval);
500 connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters()));
501 m_items.append(toFillin);
502 m_vbox->addWidget(toFillin);
505 void EffectStackEdit::slotSliderMoved(int)
507 collectAllParameters();
510 void EffectStackEdit::clearAllItems()
513 qDeleteAll(m_uiItems);
516 m_valueItems.clear();
517 QLayoutItem *item = m_vbox->itemAt(0);
519 m_vbox->removeItem(item);
521 item = m_vbox->itemAt(0);