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)
105 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
111 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
113 m_params.setAttribute(name, value);
116 void EffectStackEdit::transferParamDesc(const QDomElement& d, int in, int out)
123 if (m_params.isNull()) return;
126 doc.appendChild(doc.importNode(m_params, true));
127 //kDebug() << "IMPORTED TRANS: " << doc.toString();
128 QDomNodeList namenode = m_params.elementsByTagName("parameter");
129 QDomElement e = m_params.toElement();
130 const int minFrame = e.attribute("start").toInt();
131 const int maxFrame = e.attribute("end").toInt();
134 for (int i = 0;i < namenode.count() ;i++) {
135 kDebug() << "in form";
136 QDomElement pa = namenode.item(i).toElement();
137 QDomNode na = pa.firstChildElement("name");
138 QString type = pa.attribute("type");
139 QString paramName = i18n(na.toElement().text().toUtf8().data());
140 QWidget * toFillin = new QWidget;
141 QString value = pa.attribute("value").isNull() ?
142 pa.attribute("default") : pa.attribute("value");
143 if (type == "geometry") {
144 /*pa.setAttribute("namedesc", "X;Y;Width;Height;Transparency");
145 pa.setAttribute("format", "%d%,%d%:%d%x%d%:%d");
146 pa.setAttribute("min", "-500;-500;0;0;0");
147 pa.setAttribute("max", "500;500;200;200;100");*/
148 } else if (type == "complex") {
149 //pa.setAttribute("namedesc",pa.attribute("name"));
154 //TODO constant, list, bool, complex , color, geometry, position
155 if (type == "double" || type == "constant") {
156 createSliderItem(paramName, value.toInt(), pa.attribute("min").toInt(), pa.attribute("max").toInt());
159 } else if (type == "list") {
160 Listval *lsval = new Listval;
161 lsval->setupUi(toFillin);
162 QStringList listitems = pa.attribute("paramlist").split(',');
163 QStringList listitemsdisplay = pa.attribute("paramlistdisplay").split(',');
164 if (listitemsdisplay.count() != listitems.count()) listitemsdisplay = listitems;
165 //lsval->list->addItems(listitems);
166 lsval->list->setIconSize(QSize(30, 30));
167 for (int i = 0;i < listitems.count();i++) {
168 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
169 QString entry = listitems.at(i);
170 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
171 if (!EffectStackEdit::iconCache.contains(entry)) {
173 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
175 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
178 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
180 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
181 lsval->title->setTitle(paramName);
182 m_valueItems[paramName] = lsval;
183 m_uiItems.append(lsval);
184 } else if (type == "bool") {
185 Boolval *bval = new Boolval;
186 bval->setupUi(toFillin);
187 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
189 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
190 bval->checkBox->setText(paramName);
191 m_valueItems[paramName] = bval;
192 m_uiItems.append(bval);
193 } else if (type == "complex") {
194 /*QStringList names=nodeAtts.namedItem("name").nodeValue().split(';');
195 QStringList max=nodeAtts.namedItem("max").nodeValue().split(';');
196 QStringList min=nodeAtts.namedItem("min").nodeValue().split(';');
197 QStringList val=value.split(';');
198 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
199 if ( (names.size() == max.size() ) &&
200 (names.size()== min.size()) &&
201 (names.size()== val.size()) )
203 for (int i=0;i< names.size();i++){
204 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
207 ComplexParameter *pl = new ComplexParameter;
208 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
209 pl->setupParam(d, pa.attribute("name"), 0, 100);
210 m_vbox->addWidget(pl);
211 m_valueItems[paramName+"complex"] = pl;
213 } else if (type == "geometry") {
214 Geometryval *geo = new Geometryval(m_profile, m_frameSize);
215 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
216 connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int)));
217 geo->setupParam(pa, minFrame, maxFrame);
218 m_vbox->addWidget(geo);
219 m_valueItems[paramName+"geometry"] = geo;
221 } else if (type == "color") {
222 Colorval *cval = new Colorval;
223 cval->setupUi(toFillin);
225 if (value.startsWith('#')) value = value.replace('#', "0x");
226 cval->kcolorbutton->setColor(value.toUInt(&ok, 16));
227 //kDebug() << "color: " << value << ", " << value.toUInt(&ok, 16);
229 connect(cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT(collectAllParameters()));
230 cval->label->setText(paramName);
231 m_valueItems[paramName] = cval;
232 m_uiItems.append(cval);
233 } else if (type == "position") {
234 Positionval *pval = new Positionval;
235 pval->setupUi(toFillin);
236 int pos = value.toInt();
237 if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
239 } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
240 // fadeout position starts from clip end
241 pos = m_out - (pos - m_in);
243 pval->krestrictedline->setText(m_timecode.getTimecodeFromFrames(pos));
244 connect(pval->krestrictedline, SIGNAL(editingFinished()), this, SLOT(collectAllParameters()));
245 pval->label->setText(paramName);
246 m_valueItems[paramName + "position"] = pval;
247 m_uiItems.append(pval);
248 } else if (type == "wipe") {
249 Wipeval *wpval = new Wipeval;
250 wpval->setupUi(toFillin);
251 wipeInfo w = getWipeInfo(value);
254 wpval->start_up->setChecked(true);
257 wpval->start_down->setChecked(true);
260 wpval->start_right->setChecked(true);
263 wpval->start_left->setChecked(true);
266 wpval->start_center->setChecked(true);
271 wpval->end_up->setChecked(true);
274 wpval->end_down->setChecked(true);
277 wpval->end_right->setChecked(true);
280 wpval->end_left->setChecked(true);
283 wpval->end_center->setChecked(true);
286 wpval->start_transp->setValue(w.startTransparency);
287 wpval->end_transp->setValue(w.endTransparency);
289 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
290 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
291 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
292 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
293 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
294 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
295 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
296 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
297 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
298 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
299 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
300 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
301 //wpval->title->setTitle(na.toElement().text());
302 m_valueItems[paramName] = wpval;
303 m_uiItems.append(wpval);
310 m_items.append(toFillin);
311 m_vbox->addWidget(toFillin);
314 m_vbox->addStretch();
317 void EffectStackEdit::slotSeekToPos(int pos)
319 emit seekTimeline(m_in + pos);
322 wipeInfo EffectStackEdit::getWipeInfo(QString value)
325 QString start = value.section(';', 0, 0);
326 QString end = value.section(';', 1, 1).section('=', 1, 1);
327 if (start.startsWith("-100%,0")) info.start = LEFT;
328 else if (start.startsWith("100%,0")) info.start = RIGHT;
329 else if (start.startsWith("0%,100%")) info.start = DOWN;
330 else if (start.startsWith("0%,-100%")) info.start = UP;
331 else info.start = CENTER;
332 if (start.count(':') == 2) info.startTransparency = start.section(':', -1).toInt();
333 else info.startTransparency = 100;
335 if (end.startsWith("-100%,0")) info.end = LEFT;
336 else if (end.startsWith("100%,0")) info.end = RIGHT;
337 else if (end.startsWith("0%,100%")) info.end = DOWN;
338 else if (end.startsWith("0%,-100%")) info.end = UP;
339 else info.end = CENTER;
340 if (end.count(':') == 2) info.endTransparency = end.section(':', -1).toInt();
341 else info.endTransparency = 100;
345 QString EffectStackEdit::getWipeString(wipeInfo info)
350 switch (info.start) {
352 start = "-100%,0%:100%x100%";
355 start = "100%,0%:100%x100%";
358 start = "0%,100%:100%x100%";
361 start = "0%,-100%:100%x100%";
364 start = "0%,0%:100%x100%";
367 start.append(':' + QString::number(info.startTransparency));
371 end = "-100%,0%:100%x100%";
374 end = "100%,0%:100%x100%";
377 end = "0%,100%:100%x100%";
380 end = "0%,-100%:100%x100%";
383 end = "0%,0%:100%x100%";
386 end.append(':' + QString::number(info.endTransparency));
387 return QString(start + ";-1=" + end);
390 void EffectStackEdit::collectAllParameters()
392 QDomElement oldparam = m_params.cloneNode().toElement();
393 QDomNodeList namenode = m_params.elementsByTagName("parameter");
395 for (int i = 0;i < namenode.count() ;i++) {
396 QDomNode pa = namenode.item(i);
397 QDomNode na = pa.firstChildElement("name");
398 QString type = pa.attributes().namedItem("type").nodeValue();
399 QString paramName = i18n(na.toElement().text().toUtf8().data());
402 if (type == "double" || type == "constant") {
403 QSlider* slider = ((Constval*)m_valueItems[paramName])->horizontalSlider;
404 setValue = QString::number(slider->value());
405 } else if (type == "list") {
406 KComboBox *box = ((Listval*)m_valueItems[paramName])->list;
407 setValue = box->itemData(box->currentIndex()).toString();
408 } else if (type == "bool") {
409 QCheckBox *box = ((Boolval*)m_valueItems[paramName])->checkBox;
410 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
411 } else if (type == "color") {
412 KColorButton *color = ((Colorval*)m_valueItems[paramName])->kcolorbutton;
413 setValue = color->color().name();
414 } else if (type == "complex") {
415 ComplexParameter *complex = ((ComplexParameter*)m_valueItems[paramName+"complex"]);
416 namenode.item(i) = complex->getParamDesc();
417 } else if (type == "geometry") {
418 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
419 namenode.item(i) = geom->getParamDesc();
420 } else if (type == "position") {
421 KRestrictedLine *line = ((Positionval*)m_valueItems[paramName+"position"])->krestrictedline;
422 int pos = m_timecode.getFrameCount(line->text(), KdenliveSettings::project_fps());
423 if (m_params.attribute("id") == "fadein" || m_params.attribute("id") == "fade_from_black") {
427 line->setText(m_timecode.getTimecodeFromFrames(pos));
429 } else if (m_params.attribute("id") == "fadeout" || m_params.attribute("id") == "fade_to_black") {
430 pos = m_out - (pos - m_in);
431 if (pos > m_out - m_in) {
433 line->setText(m_timecode.getTimecodeFromFrames(pos));
436 setValue = QString::number(pos);
437 } else if (type == "wipe") {
438 Wipeval *wp = (Wipeval*)m_valueItems[paramName];
440 if (wp->start_left->isChecked()) info.start = LEFT;
441 else if (wp->start_right->isChecked()) info.start = RIGHT;
442 else if (wp->start_up->isChecked()) info.start = UP;
443 else if (wp->start_down->isChecked()) info.start = DOWN;
444 else if (wp->start_center->isChecked()) info.start = CENTER;
445 else info.start = LEFT;
446 info.startTransparency = wp->start_transp->value();
447 if (wp->end_left->isChecked()) info.end = LEFT;
448 else if (wp->end_right->isChecked()) info.end = RIGHT;
449 else if (wp->end_up->isChecked()) info.end = UP;
450 else if (wp->end_down->isChecked()) info.end = DOWN;
451 else if (wp->end_center->isChecked()) info.end = CENTER;
452 else info.end = RIGHT;
453 info.endTransparency = wp->end_transp->value();
454 setValue = getWipeString(info);
457 if (!setValue.isNull()) {
458 pa.attributes().namedItem("value").setNodeValue(setValue);
461 emit parameterChanged(oldparam, m_params);
464 void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max)
466 QWidget* toFillin = new QWidget;
467 Constval *ctval = new Constval;
468 ctval->setupUi(toFillin);
470 ctval->horizontalSlider->setMinimum(min);
471 ctval->horizontalSlider->setMaximum(max);
472 ctval->spinBox->setMinimum(min);
473 ctval->spinBox->setMaximum(max);
474 ctval->horizontalSlider->setPageStep((int)(max - min) / 10);
475 ctval->horizontalSlider->setValue(val);
476 ctval->label->setText(name);
477 m_valueItems[name] = ctval;
478 m_uiItems.append(ctval);
479 connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters()));
480 m_items.append(toFillin);
481 m_vbox->addWidget(toFillin);
484 void EffectStackEdit::slotSliderMoved(int)
486 collectAllParameters();
489 void EffectStackEdit::clearAllItems()
492 qDeleteAll(m_uiItems);
495 m_valueItems.clear();
496 QLayoutItem *item = m_vbox->itemAt(0);
498 m_vbox->removeItem(item);
500 item = m_vbox->itemAt(0);