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 "kdenlivesettings.h"
32 #include <QVBoxLayout>
35 #include <QPushButton>
37 #include <QScrollArea>
40 class Boolval: public EffectStackEdit::UiItem, public Ui::Boolval_UI
44 class Colorval: public EffectStackEdit::UiItem, public Ui::Colorval_UI
48 class Constval: public EffectStackEdit::UiItem, public Ui::Constval_UI
52 class Listval: public EffectStackEdit::UiItem, public Ui::Listval_UI
56 class Positionval: public EffectStackEdit::UiItem, public Ui::Positionval_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 wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
83 area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
85 vbox1->addWidget(area);
87 area->setWidgetResizable(true);
88 m_vbox = new QVBoxLayout(wid);
89 m_vbox->setContentsMargins(0, 0, 0, 0);
90 m_vbox->setSpacing(0);
95 EffectStackEdit::~EffectStackEdit()
100 void EffectStackEdit::setFrameSize(QPoint p)
103 QDomNodeList namenode = m_params.elementsByTagName("parameter");
104 for (int i = 0;i < namenode.count() ;i++) {
105 QDomNode pa = namenode.item(i);
106 QDomNode na = pa.firstChildElement("name");
107 QString type = pa.attributes().namedItem("type").nodeValue();
108 QString paramName = i18n(na.toElement().text().toUtf8().data());
110 if (type == "geometry") {
111 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
112 geom->setFrameSize(m_frameSize);
119 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
125 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
127 m_params.setAttribute(name, value);
130 void EffectStackEdit::transferParamDesc(const QDomElement& d, int in, int out)
137 if (m_params.isNull()) return;
140 doc.appendChild(doc.importNode(m_params, true));
141 //kDebug() << "IMPORTED TRANS: " << doc.toString();
142 QDomNodeList namenode = m_params.elementsByTagName("parameter");
143 QDomElement e = m_params.toElement();
144 const int minFrame = e.attribute("start").toInt();
145 const int maxFrame = e.attribute("end").toInt();
148 for (int i = 0;i < namenode.count() ;i++) {
149 kDebug() << "in form";
150 QDomElement pa = namenode.item(i).toElement();
151 QDomNode na = pa.firstChildElement("name");
152 QString type = pa.attribute("type");
153 QString paramName = i18n(na.toElement().text().toUtf8().data());
154 QWidget * toFillin = new QWidget;
155 QString value = pa.attribute("value").isNull() ?
156 pa.attribute("default") : pa.attribute("value");
157 if (type == "geometry") {
158 /*pa.setAttribute("namedesc", "X;Y;Width;Height;Transparency");
159 pa.setAttribute("format", "%d%,%d%:%d%x%d%:%d");
160 pa.setAttribute("min", "-500;-500;0;0;0");
161 pa.setAttribute("max", "500;500;200;200;100");*/
162 } else if (type == "complex") {
163 //pa.setAttribute("namedesc",pa.attribute("name"));
168 //TODO constant, list, bool, complex , color, geometry, position
169 if (type == "double" || type == "constant") {
170 createSliderItem(paramName, value.toInt(), pa.attribute("min").toInt(), pa.attribute("max").toInt());
173 } else if (type == "list") {
174 Listval *lsval = new Listval;
175 lsval->setupUi(toFillin);
176 QStringList listitems = pa.attribute("paramlist").split(',');
177 QStringList listitemsdisplay = pa.attribute("paramlistdisplay").split(',');
178 if (listitemsdisplay.count() != listitems.count()) listitemsdisplay = listitems;
179 //lsval->list->addItems(listitems);
180 lsval->list->setIconSize(QSize(30, 30));
181 for (int i = 0;i < listitems.count();i++) {
182 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
183 QString entry = listitems.at(i);
184 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
185 if (!EffectStackEdit::iconCache.contains(entry)) {
187 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
189 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
192 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
194 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
195 lsval->title->setTitle(paramName);
196 m_valueItems[paramName] = lsval;
197 m_uiItems.append(lsval);
198 } else if (type == "bool") {
199 Boolval *bval = new Boolval;
200 bval->setupUi(toFillin);
201 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
203 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
204 bval->checkBox->setText(paramName);
205 m_valueItems[paramName] = bval;
206 m_uiItems.append(bval);
207 } else if (type == "complex") {
208 /*QStringList names=nodeAtts.namedItem("name").nodeValue().split(';');
209 QStringList max=nodeAtts.namedItem("max").nodeValue().split(';');
210 QStringList min=nodeAtts.namedItem("min").nodeValue().split(';');
211 QStringList val=value.split(';');
212 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
213 if ( (names.size() == max.size() ) &&
214 (names.size()== min.size()) &&
215 (names.size()== val.size()) )
217 for (int i=0;i< names.size();i++){
218 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
221 ComplexParameter *pl = new ComplexParameter;
222 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
223 pl->setupParam(d, pa.attribute("name"), 0, 100);
224 m_vbox->addWidget(pl);
225 m_valueItems[paramName+"complex"] = pl;
227 } else if (type == "geometry") {
228 Geometryval *geo = new Geometryval(m_profile, m_frameSize);
229 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
230 connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int)));
231 geo->setupParam(pa, minFrame, maxFrame);
232 m_vbox->addWidget(geo);
233 m_valueItems[paramName+"geometry"] = geo;
235 } else if (type == "color") {
236 Colorval *cval = new Colorval;
237 cval->setupUi(toFillin);
239 if (value.startsWith('#')) value = value.replace('#', "0x");
240 cval->kcolorbutton->setColor(value.toUInt(&ok, 16));
241 //kDebug() << "color: " << value << ", " << value.toUInt(&ok, 16);
243 connect(cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT(collectAllParameters()));
244 cval->label->setText(paramName);
245 m_valueItems[paramName] = cval;
246 m_uiItems.append(cval);
247 } else if (type == "position") {
248 Positionval *pval = new Positionval;
249 pval->setupUi(toFillin);
250 int pos = value.toInt();
251 if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
253 } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
254 // fadeout position starts from clip end
255 pos = m_out - (pos - m_in);
257 pval->krestrictedline->setText(m_timecode.getTimecodeFromFrames(pos));
258 connect(pval->krestrictedline, SIGNAL(editingFinished()), this, SLOT(collectAllParameters()));
259 pval->label->setText(paramName);
260 m_valueItems[paramName + "position"] = pval;
261 m_uiItems.append(pval);
262 } else if (type == "wipe") {
263 Wipeval *wpval = new Wipeval;
264 wpval->setupUi(toFillin);
265 wipeInfo w = getWipeInfo(value);
268 wpval->start_up->setChecked(true);
271 wpval->start_down->setChecked(true);
274 wpval->start_right->setChecked(true);
277 wpval->start_left->setChecked(true);
280 wpval->start_center->setChecked(true);
285 wpval->end_up->setChecked(true);
288 wpval->end_down->setChecked(true);
291 wpval->end_right->setChecked(true);
294 wpval->end_left->setChecked(true);
297 wpval->end_center->setChecked(true);
300 wpval->start_transp->setValue(w.startTransparency);
301 wpval->end_transp->setValue(w.endTransparency);
303 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
304 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
305 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
306 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
307 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
308 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
309 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
310 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
311 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
312 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
313 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
314 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
315 //wpval->title->setTitle(na.toElement().text());
316 m_valueItems[paramName] = wpval;
317 m_uiItems.append(wpval);
324 m_items.append(toFillin);
325 m_vbox->addWidget(toFillin);
328 m_vbox->addStretch();
331 void EffectStackEdit::slotSeekToPos(int pos)
333 emit seekTimeline(m_in + pos);
336 wipeInfo EffectStackEdit::getWipeInfo(QString value)
339 QString start = value.section(';', 0, 0);
340 QString end = value.section(';', 1, 1).section('=', 1, 1);
341 if (start.startsWith("-100%,0")) info.start = LEFT;
342 else if (start.startsWith("100%,0")) info.start = RIGHT;
343 else if (start.startsWith("0%,100%")) info.start = DOWN;
344 else if (start.startsWith("0%,-100%")) info.start = UP;
345 else info.start = CENTER;
346 if (start.count(':') == 2) info.startTransparency = start.section(':', -1).toInt();
347 else info.startTransparency = 100;
349 if (end.startsWith("-100%,0")) info.end = LEFT;
350 else if (end.startsWith("100%,0")) info.end = RIGHT;
351 else if (end.startsWith("0%,100%")) info.end = DOWN;
352 else if (end.startsWith("0%,-100%")) info.end = UP;
353 else info.end = CENTER;
354 if (end.count(':') == 2) info.endTransparency = end.section(':', -1).toInt();
355 else info.endTransparency = 100;
359 QString EffectStackEdit::getWipeString(wipeInfo info)
364 switch (info.start) {
366 start = "-100%,0%:100%x100%";
369 start = "100%,0%:100%x100%";
372 start = "0%,100%:100%x100%";
375 start = "0%,-100%:100%x100%";
378 start = "0%,0%:100%x100%";
381 start.append(':' + QString::number(info.startTransparency));
385 end = "-100%,0%:100%x100%";
388 end = "100%,0%:100%x100%";
391 end = "0%,100%:100%x100%";
394 end = "0%,-100%:100%x100%";
397 end = "0%,0%:100%x100%";
400 end.append(':' + QString::number(info.endTransparency));
401 return QString(start + ";-1=" + end);
404 void EffectStackEdit::collectAllParameters()
406 QDomElement oldparam = m_params.cloneNode().toElement();
407 QDomNodeList namenode = m_params.elementsByTagName("parameter");
409 for (int i = 0;i < namenode.count() ;i++) {
410 QDomNode pa = namenode.item(i);
411 QDomNode na = pa.firstChildElement("name");
412 QString type = pa.attributes().namedItem("type").nodeValue();
413 QString paramName = i18n(na.toElement().text().toUtf8().data());
416 if (type == "double" || type == "constant") {
417 QSlider* slider = ((Constval*)m_valueItems[paramName])->horizontalSlider;
418 setValue = QString::number(slider->value());
419 } else if (type == "list") {
420 KComboBox *box = ((Listval*)m_valueItems[paramName])->list;
421 setValue = box->itemData(box->currentIndex()).toString();
422 } else if (type == "bool") {
423 QCheckBox *box = ((Boolval*)m_valueItems[paramName])->checkBox;
424 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
425 } else if (type == "color") {
426 KColorButton *color = ((Colorval*)m_valueItems[paramName])->kcolorbutton;
427 setValue = color->color().name();
428 } else if (type == "complex") {
429 ComplexParameter *complex = ((ComplexParameter*)m_valueItems[paramName+"complex"]);
430 namenode.item(i) = complex->getParamDesc();
431 } else if (type == "geometry") {
432 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
433 namenode.item(i) = geom->getParamDesc();
434 } else if (type == "position") {
435 KRestrictedLine *line = ((Positionval*)m_valueItems[paramName+"position"])->krestrictedline;
436 int pos = m_timecode.getFrameCount(line->text(), KdenliveSettings::project_fps());
437 if (m_params.attribute("id") == "fadein" || m_params.attribute("id") == "fade_from_black") {
441 line->setText(m_timecode.getTimecodeFromFrames(pos));
443 } else if (m_params.attribute("id") == "fadeout" || m_params.attribute("id") == "fade_to_black") {
444 pos = m_out - (pos - m_in);
445 if (pos > m_out - m_in) {
447 line->setText(m_timecode.getTimecodeFromFrames(pos));
450 setValue = QString::number(pos);
451 } else if (type == "wipe") {
452 Wipeval *wp = (Wipeval*)m_valueItems[paramName];
454 if (wp->start_left->isChecked()) info.start = LEFT;
455 else if (wp->start_right->isChecked()) info.start = RIGHT;
456 else if (wp->start_up->isChecked()) info.start = UP;
457 else if (wp->start_down->isChecked()) info.start = DOWN;
458 else if (wp->start_center->isChecked()) info.start = CENTER;
459 else info.start = LEFT;
460 info.startTransparency = wp->start_transp->value();
461 if (wp->end_left->isChecked()) info.end = LEFT;
462 else if (wp->end_right->isChecked()) info.end = RIGHT;
463 else if (wp->end_up->isChecked()) info.end = UP;
464 else if (wp->end_down->isChecked()) info.end = DOWN;
465 else if (wp->end_center->isChecked()) info.end = CENTER;
466 else info.end = RIGHT;
467 info.endTransparency = wp->end_transp->value();
468 setValue = getWipeString(info);
471 if (!setValue.isNull()) {
472 pa.attributes().namedItem("value").setNodeValue(setValue);
475 emit parameterChanged(oldparam, m_params);
478 void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max)
480 QWidget* toFillin = new QWidget;
481 Constval *ctval = new Constval;
482 ctval->setupUi(toFillin);
484 ctval->horizontalSlider->setMinimum(min);
485 ctval->horizontalSlider->setMaximum(max);
486 ctval->spinBox->setMinimum(min);
487 ctval->spinBox->setMaximum(max);
488 ctval->horizontalSlider->setPageStep((int)(max - min) / 10);
489 ctval->horizontalSlider->setValue(val);
490 ctval->label->setText(name);
491 m_valueItems[name] = ctval;
492 m_uiItems.append(ctval);
493 connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters()));
494 m_items.append(toFillin);
495 m_vbox->addWidget(toFillin);
498 void EffectStackEdit::slotSliderMoved(int)
500 collectAllParameters();
503 void EffectStackEdit::clearAllItems()
506 qDeleteAll(m_uiItems);
509 m_valueItems.clear();
510 QLayoutItem *item = m_vbox->itemAt(0);
512 m_vbox->removeItem(item);
514 item = m_vbox->itemAt(0);