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 {
43 class Colorval: public EffectStackEdit::UiItem, public Ui::Colorval_UI {
46 class Constval: public EffectStackEdit::UiItem, public Ui::Constval_UI {
49 class Listval: public EffectStackEdit::UiItem, public Ui::Listval_UI {
52 class Positionval: public EffectStackEdit::UiItem, public Ui::Positionval_UI {
55 class Wipeval: public EffectStackEdit::UiItem, public Ui::Wipeval_UI {
59 QMap<QString, QImage> EffectStackEdit::iconCache;
61 EffectStackEdit::EffectStackEdit(QWidget *parent) :
66 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
67 QVBoxLayout *vbox1 = new QVBoxLayout(parent);
68 vbox1->setContentsMargins(0, 0, 0, 0);
71 QScrollArea *area = new QScrollArea;
72 QWidget *wid = new QWidget(parent);
73 area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
74 area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
75 wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
76 area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
78 vbox1->addWidget(area);
80 area->setWidgetResizable(true);
81 m_vbox = new QVBoxLayout(wid);
82 m_vbox->setContentsMargins(0, 0, 0, 0);
83 m_vbox->setSpacing(0);
88 EffectStackEdit::~EffectStackEdit()
93 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
99 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
101 m_params.setAttribute(name, value);
104 void EffectStackEdit::transferParamDesc(const QDomElement& d, int in, int out)
111 if (m_params.isNull()) return;
114 doc.appendChild(doc.importNode(m_params, true));
115 //kDebug() << "IMPORTED TRANS: " << doc.toString();
116 QDomNodeList namenode = m_params.elementsByTagName("parameter");
117 QDomElement e = m_params.toElement();
118 const int minFrame = e.attribute("start").toInt();
119 const int maxFrame = e.attribute("end").toInt();
122 for (int i = 0;i < namenode.count() ;i++) {
123 kDebug() << "in form";
124 QDomElement pa = namenode.item(i).toElement();
125 QDomNode na = pa.firstChildElement("name");
126 QString type = pa.attribute("type");
127 QString paramName = i18n(na.toElement().text().toUtf8().data());
128 QWidget * toFillin = new QWidget;
129 QString value = pa.attribute("value").isNull() ?
130 pa.attribute("default") : pa.attribute("value");
131 if (type == "geometry") {
132 /*pa.setAttribute("namedesc", "X;Y;Width;Height;Transparency");
133 pa.setAttribute("format", "%d%,%d%:%d%x%d%:%d");
134 pa.setAttribute("min", "-500;-500;0;0;0");
135 pa.setAttribute("max", "500;500;200;200;100");*/
136 } else if (type == "complex") {
137 //pa.setAttribute("namedesc",pa.attribute("name"));
142 //TODO constant, list, bool, complex , color, geometry, position
143 if (type == "double" || type == "constant") {
144 createSliderItem(paramName, value.toInt(), pa.attribute("min").toInt(), pa.attribute("max").toInt());
147 } else if (type == "list") {
148 Listval *lsval = new Listval;
149 lsval->setupUi(toFillin);
150 QStringList listitems = pa.attribute("paramlist").split(',');
151 QStringList listitemsdisplay = pa.attribute("paramlistdisplay").split(',');
152 if (listitemsdisplay.count() != listitems.count()) listitemsdisplay = listitems;
153 //lsval->list->addItems(listitems);
154 lsval->list->setIconSize(QSize(30, 30));
155 for (int i = 0;i < listitems.count();i++) {
156 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
157 QString entry = listitems.at(i);
158 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
159 if (!EffectStackEdit::iconCache.contains(entry)) {
161 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
163 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
166 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
168 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
169 lsval->title->setTitle(paramName);
170 m_valueItems[paramName] = lsval;
171 m_uiItems.append(lsval);
172 } else if (type == "bool") {
173 Boolval *bval = new Boolval;
174 bval->setupUi(toFillin);
175 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
177 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
178 bval->checkBox->setText(paramName);
179 m_valueItems[paramName] = bval;
180 m_uiItems.append(bval);
181 } else if (type == "complex") {
182 /*QStringList names=nodeAtts.namedItem("name").nodeValue().split(';');
183 QStringList max=nodeAtts.namedItem("max").nodeValue().split(';');
184 QStringList min=nodeAtts.namedItem("min").nodeValue().split(';');
185 QStringList val=value.split(';');
186 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
187 if ( (names.size() == max.size() ) &&
188 (names.size()== min.size()) &&
189 (names.size()== val.size()) )
191 for (int i=0;i< names.size();i++){
192 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
195 ComplexParameter *pl = new ComplexParameter;
196 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
197 pl->setupParam(d, pa.attribute("name"), 0, 100);
198 m_vbox->addWidget(pl);
199 m_valueItems[paramName+"complex"] = pl;
201 } else if (type == "geometry") {
202 Geometryval *geo = new Geometryval(m_profile);
203 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
204 connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int)));
205 geo->setupParam(pa, minFrame, maxFrame);
206 m_vbox->addWidget(geo);
207 m_valueItems[paramName+"geometry"] = geo;
209 } else if (type == "color") {
210 Colorval *cval = new Colorval;
211 cval->setupUi(toFillin);
213 cval->kcolorbutton->setColor(value.toUInt(&ok, 16));
214 kDebug() << value.toUInt(&ok, 16);
216 connect(cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT(collectAllParameters()));
217 cval->label->setText(paramName);
218 m_valueItems[paramName] = cval;
219 m_uiItems.append(cval);
220 } else if (type == "position") {
221 Positionval *pval = new Positionval;
222 pval->setupUi(toFillin);
223 int pos = value.toInt();
224 if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
226 } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
227 // fadeout position starts from clip end
228 pos = m_out - (pos - m_in);
230 pval->krestrictedline->setText(m_timecode.getTimecodeFromFrames(pos));
231 connect(pval->krestrictedline, SIGNAL(editingFinished()), this, SLOT(collectAllParameters()));
232 pval->label->setText(paramName);
233 m_valueItems[paramName + "position"] = pval;
234 m_uiItems.append(pval);
235 } else if (type == "wipe") {
236 Wipeval *wpval = new Wipeval;
237 wpval->setupUi(toFillin);
238 wipeInfo w = getWipeInfo(value);
241 wpval->start_up->setChecked(true);
244 wpval->start_down->setChecked(true);
247 wpval->start_right->setChecked(true);
250 wpval->start_left->setChecked(true);
253 wpval->start_center->setChecked(true);
258 wpval->end_up->setChecked(true);
261 wpval->end_down->setChecked(true);
264 wpval->end_right->setChecked(true);
267 wpval->end_left->setChecked(true);
270 wpval->end_center->setChecked(true);
273 wpval->start_transp->setValue(w.startTransparency);
274 wpval->end_transp->setValue(w.endTransparency);
276 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
277 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
278 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
279 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
280 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
281 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
282 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
283 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
284 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
285 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
286 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
287 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
288 //wpval->title->setTitle(na.toElement().text());
289 m_valueItems[paramName] = wpval;
290 m_uiItems.append(wpval);
297 m_items.append(toFillin);
298 m_vbox->addWidget(toFillin);
301 m_vbox->addStretch();
304 void EffectStackEdit::slotSeekToPos(int pos)
306 emit seekTimeline(m_in + pos);
309 wipeInfo EffectStackEdit::getWipeInfo(QString value)
312 QString start = value.section(';', 0, 0);
313 QString end = value.section(';', 1, 1).section('=', 1, 1);
314 if (start.startsWith("-100%,0")) info.start = LEFT;
315 else if (start.startsWith("100%,0")) info.start = RIGHT;
316 else if (start.startsWith("0%,100%")) info.start = DOWN;
317 else if (start.startsWith("0%,-100%")) info.start = UP;
318 else info.start = CENTER;
319 if (start.count(':') == 2) info.startTransparency = start.section(':', -1).toInt();
320 else info.startTransparency = 100;
322 if (end.startsWith("-100%,0")) info.end = LEFT;
323 else if (end.startsWith("100%,0")) info.end = RIGHT;
324 else if (end.startsWith("0%,100%")) info.end = DOWN;
325 else if (end.startsWith("0%,-100%")) info.end = UP;
326 else info.end = CENTER;
327 if (end.count(':') == 2) info.endTransparency = end.section(':', -1).toInt();
328 else info.endTransparency = 100;
332 QString EffectStackEdit::getWipeString(wipeInfo info)
337 switch (info.start) {
339 start = "-100%,0%:100%x100%";
342 start = "100%,0%:100%x100%";
345 start = "0%,100%:100%x100%";
348 start = "0%,-100%:100%x100%";
351 start = "0%,0%:100%x100%";
354 start.append(':' + QString::number(info.startTransparency));
358 end = "-100%,0%:100%x100%";
361 end = "100%,0%:100%x100%";
364 end = "0%,100%:100%x100%";
367 end = "0%,-100%:100%x100%";
370 end = "0%,0%:100%x100%";
373 end.append(':' + QString::number(info.endTransparency));
374 return QString(start + ";-1=" + end);
377 void EffectStackEdit::collectAllParameters()
379 QDomElement oldparam = m_params.cloneNode().toElement();
380 QDomNodeList namenode = m_params.elementsByTagName("parameter");
382 for (int i = 0;i < namenode.count() ;i++) {
383 QDomNode pa = namenode.item(i);
384 QDomNode na = pa.firstChildElement("name");
385 QString type = pa.attributes().namedItem("type").nodeValue();
386 QString paramName = i18n(na.toElement().text().toUtf8().data());
389 if (type == "double" || type == "constant") {
390 QSlider* slider = ((Constval*)m_valueItems[paramName])->horizontalSlider;
391 setValue = QString::number(slider->value());
392 } else if (type == "list") {
393 KComboBox *box = ((Listval*)m_valueItems[paramName])->list;
394 setValue = box->itemData(box->currentIndex()).toString();
395 } else if (type == "bool") {
396 QCheckBox *box = ((Boolval*)m_valueItems[paramName])->checkBox;
397 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
398 } else if (type == "color") {
399 KColorButton *color = ((Colorval*)m_valueItems[paramName])->kcolorbutton;
400 setValue = color->color().name();
401 } else if (type == "complex") {
402 ComplexParameter *complex = ((ComplexParameter*)m_valueItems[paramName+"complex"]);
403 namenode.item(i) = complex->getParamDesc();
404 } else if (type == "geometry") {
405 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
406 namenode.item(i) = geom->getParamDesc();
407 } else if (type == "position") {
408 KRestrictedLine *line = ((Positionval*)m_valueItems[paramName+"position"])->krestrictedline;
409 int pos = m_timecode.getFrameCount(line->text(), KdenliveSettings::project_fps());
410 if (m_params.attribute("id") == "fadein" || m_params.attribute("id") == "fade_from_black") {
414 line->setText(m_timecode.getTimecodeFromFrames(pos));
416 } else if (m_params.attribute("id") == "fadeout" || m_params.attribute("id") == "fade_to_black") {
417 pos = m_out - (pos - m_in);
418 if (pos > m_out - m_in) {
420 line->setText(m_timecode.getTimecodeFromFrames(pos));
423 setValue = QString::number(pos);
424 } else if (type == "wipe") {
425 Wipeval *wp = (Wipeval*)m_valueItems[paramName];
427 if (wp->start_left->isChecked()) info.start = LEFT;
428 else if (wp->start_right->isChecked()) info.start = RIGHT;
429 else if (wp->start_up->isChecked()) info.start = UP;
430 else if (wp->start_down->isChecked()) info.start = DOWN;
431 else if (wp->start_center->isChecked()) info.start = CENTER;
432 else info.start = LEFT;
433 info.startTransparency = wp->start_transp->value();
434 if (wp->end_left->isChecked()) info.end = LEFT;
435 else if (wp->end_right->isChecked()) info.end = RIGHT;
436 else if (wp->end_up->isChecked()) info.end = UP;
437 else if (wp->end_down->isChecked()) info.end = DOWN;
438 else if (wp->end_center->isChecked()) info.end = CENTER;
439 else info.end = RIGHT;
440 info.endTransparency = wp->end_transp->value();
441 setValue = getWipeString(info);
444 if (!setValue.isNull()) {
445 pa.attributes().namedItem("value").setNodeValue(setValue);
448 emit parameterChanged(oldparam, m_params);
451 void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max)
453 QWidget* toFillin = new QWidget;
454 Constval *ctval = new Constval;
455 ctval->setupUi(toFillin);
457 ctval->horizontalSlider->setMinimum(min);
458 ctval->horizontalSlider->setMaximum(max);
459 ctval->spinBox->setMinimum(min);
460 ctval->spinBox->setMaximum(max);
461 ctval->horizontalSlider->setPageStep((int)(max - min) / 10);
462 ctval->horizontalSlider->setValue(val);
463 ctval->label->setText(name);
464 m_valueItems[name] = ctval;
465 m_uiItems.append(ctval);
466 connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters()));
467 m_items.append(toFillin);
468 m_vbox->addWidget(toFillin);
471 void EffectStackEdit::slotSliderMoved(int)
473 collectAllParameters();
476 void EffectStackEdit::clearAllItems()
479 qDeleteAll(m_uiItems);
482 m_valueItems.clear();
483 QLayoutItem *item = m_vbox->itemAt(0);
485 m_vbox->removeItem(item);
487 item = m_vbox->itemAt(0);