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) :
72 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
73 QVBoxLayout *vbox1 = new QVBoxLayout(parent);
74 vbox1->setContentsMargins(0, 0, 0, 0);
77 QScrollArea *area = new QScrollArea;
78 QWidget *wid = new QWidget(parent);
79 area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
80 area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
81 wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
82 area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
84 vbox1->addWidget(area);
86 area->setWidgetResizable(true);
87 m_vbox = new QVBoxLayout(wid);
88 m_vbox->setContentsMargins(0, 0, 0, 0);
89 m_vbox->setSpacing(0);
94 EffectStackEdit::~EffectStackEdit()
99 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
105 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
107 m_params.setAttribute(name, value);
110 void EffectStackEdit::transferParamDesc(const QDomElement& d, int in, int out)
117 if (m_params.isNull()) return;
120 doc.appendChild(doc.importNode(m_params, true));
121 //kDebug() << "IMPORTED TRANS: " << doc.toString();
122 QDomNodeList namenode = m_params.elementsByTagName("parameter");
123 QDomElement e = m_params.toElement();
124 const int minFrame = e.attribute("start").toInt();
125 const int maxFrame = e.attribute("end").toInt();
128 for (int i = 0;i < namenode.count() ;i++) {
129 kDebug() << "in form";
130 QDomElement pa = namenode.item(i).toElement();
131 QDomNode na = pa.firstChildElement("name");
132 QString type = pa.attribute("type");
133 QString paramName = i18n(na.toElement().text().toUtf8().data());
134 QWidget * toFillin = new QWidget;
135 QString value = pa.attribute("value").isNull() ?
136 pa.attribute("default") : pa.attribute("value");
137 if (type == "geometry") {
138 /*pa.setAttribute("namedesc", "X;Y;Width;Height;Transparency");
139 pa.setAttribute("format", "%d%,%d%:%d%x%d%:%d");
140 pa.setAttribute("min", "-500;-500;0;0;0");
141 pa.setAttribute("max", "500;500;200;200;100");*/
142 } else if (type == "complex") {
143 //pa.setAttribute("namedesc",pa.attribute("name"));
148 //TODO constant, list, bool, complex , color, geometry, position
149 if (type == "double" || type == "constant") {
150 createSliderItem(paramName, value.toInt(), pa.attribute("min").toInt(), pa.attribute("max").toInt());
153 } else if (type == "list") {
154 Listval *lsval = new Listval;
155 lsval->setupUi(toFillin);
156 QStringList listitems = pa.attribute("paramlist").split(',');
157 QStringList listitemsdisplay = pa.attribute("paramlistdisplay").split(',');
158 if (listitemsdisplay.count() != listitems.count()) listitemsdisplay = listitems;
159 //lsval->list->addItems(listitems);
160 lsval->list->setIconSize(QSize(30, 30));
161 for (int i = 0;i < listitems.count();i++) {
162 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
163 QString entry = listitems.at(i);
164 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
165 if (!EffectStackEdit::iconCache.contains(entry)) {
167 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
169 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
172 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
174 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
175 lsval->title->setTitle(paramName);
176 m_valueItems[paramName] = lsval;
177 m_uiItems.append(lsval);
178 } else if (type == "bool") {
179 Boolval *bval = new Boolval;
180 bval->setupUi(toFillin);
181 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
183 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
184 bval->checkBox->setText(paramName);
185 m_valueItems[paramName] = bval;
186 m_uiItems.append(bval);
187 } else if (type == "complex") {
188 /*QStringList names=nodeAtts.namedItem("name").nodeValue().split(';');
189 QStringList max=nodeAtts.namedItem("max").nodeValue().split(';');
190 QStringList min=nodeAtts.namedItem("min").nodeValue().split(';');
191 QStringList val=value.split(';');
192 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
193 if ( (names.size() == max.size() ) &&
194 (names.size()== min.size()) &&
195 (names.size()== val.size()) )
197 for (int i=0;i< names.size();i++){
198 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
201 ComplexParameter *pl = new ComplexParameter;
202 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
203 pl->setupParam(d, pa.attribute("name"), 0, 100);
204 m_vbox->addWidget(pl);
205 m_valueItems[paramName+"complex"] = pl;
207 } else if (type == "geometry") {
208 Geometryval *geo = new Geometryval(m_profile);
209 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
210 connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int)));
211 geo->setupParam(pa, minFrame, maxFrame);
212 m_vbox->addWidget(geo);
213 m_valueItems[paramName+"geometry"] = geo;
215 } else if (type == "color") {
216 Colorval *cval = new Colorval;
217 cval->setupUi(toFillin);
219 if (value.startsWith('#')) value = value.replace('#', "0x");
220 cval->kcolorbutton->setColor(value.toUInt(&ok, 16));
221 //kDebug() << "color: " << value << ", " << value.toUInt(&ok, 16);
223 connect(cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT(collectAllParameters()));
224 cval->label->setText(paramName);
225 m_valueItems[paramName] = cval;
226 m_uiItems.append(cval);
227 } else if (type == "position") {
228 Positionval *pval = new Positionval;
229 pval->setupUi(toFillin);
230 int pos = value.toInt();
231 if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
233 } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
234 // fadeout position starts from clip end
235 pos = m_out - (pos - m_in);
237 pval->krestrictedline->setText(m_timecode.getTimecodeFromFrames(pos));
238 connect(pval->krestrictedline, SIGNAL(editingFinished()), this, SLOT(collectAllParameters()));
239 pval->label->setText(paramName);
240 m_valueItems[paramName + "position"] = pval;
241 m_uiItems.append(pval);
242 } else if (type == "wipe") {
243 Wipeval *wpval = new Wipeval;
244 wpval->setupUi(toFillin);
245 wipeInfo w = getWipeInfo(value);
248 wpval->start_up->setChecked(true);
251 wpval->start_down->setChecked(true);
254 wpval->start_right->setChecked(true);
257 wpval->start_left->setChecked(true);
260 wpval->start_center->setChecked(true);
265 wpval->end_up->setChecked(true);
268 wpval->end_down->setChecked(true);
271 wpval->end_right->setChecked(true);
274 wpval->end_left->setChecked(true);
277 wpval->end_center->setChecked(true);
280 wpval->start_transp->setValue(w.startTransparency);
281 wpval->end_transp->setValue(w.endTransparency);
283 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
284 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
285 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
286 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
287 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
288 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
289 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
290 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
291 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
292 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
293 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
294 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
295 //wpval->title->setTitle(na.toElement().text());
296 m_valueItems[paramName] = wpval;
297 m_uiItems.append(wpval);
304 m_items.append(toFillin);
305 m_vbox->addWidget(toFillin);
308 m_vbox->addStretch();
311 void EffectStackEdit::slotSeekToPos(int pos)
313 emit seekTimeline(m_in + pos);
316 wipeInfo EffectStackEdit::getWipeInfo(QString value)
319 QString start = value.section(';', 0, 0);
320 QString end = value.section(';', 1, 1).section('=', 1, 1);
321 if (start.startsWith("-100%,0")) info.start = LEFT;
322 else if (start.startsWith("100%,0")) info.start = RIGHT;
323 else if (start.startsWith("0%,100%")) info.start = DOWN;
324 else if (start.startsWith("0%,-100%")) info.start = UP;
325 else info.start = CENTER;
326 if (start.count(':') == 2) info.startTransparency = start.section(':', -1).toInt();
327 else info.startTransparency = 100;
329 if (end.startsWith("-100%,0")) info.end = LEFT;
330 else if (end.startsWith("100%,0")) info.end = RIGHT;
331 else if (end.startsWith("0%,100%")) info.end = DOWN;
332 else if (end.startsWith("0%,-100%")) info.end = UP;
333 else info.end = CENTER;
334 if (end.count(':') == 2) info.endTransparency = end.section(':', -1).toInt();
335 else info.endTransparency = 100;
339 QString EffectStackEdit::getWipeString(wipeInfo info)
344 switch (info.start) {
346 start = "-100%,0%:100%x100%";
349 start = "100%,0%:100%x100%";
352 start = "0%,100%:100%x100%";
355 start = "0%,-100%:100%x100%";
358 start = "0%,0%:100%x100%";
361 start.append(':' + QString::number(info.startTransparency));
365 end = "-100%,0%:100%x100%";
368 end = "100%,0%:100%x100%";
371 end = "0%,100%:100%x100%";
374 end = "0%,-100%:100%x100%";
377 end = "0%,0%:100%x100%";
380 end.append(':' + QString::number(info.endTransparency));
381 return QString(start + ";-1=" + end);
384 void EffectStackEdit::collectAllParameters()
386 QDomElement oldparam = m_params.cloneNode().toElement();
387 QDomNodeList namenode = m_params.elementsByTagName("parameter");
389 for (int i = 0;i < namenode.count() ;i++) {
390 QDomNode pa = namenode.item(i);
391 QDomNode na = pa.firstChildElement("name");
392 QString type = pa.attributes().namedItem("type").nodeValue();
393 QString paramName = i18n(na.toElement().text().toUtf8().data());
396 if (type == "double" || type == "constant") {
397 QSlider* slider = ((Constval*)m_valueItems[paramName])->horizontalSlider;
398 setValue = QString::number(slider->value());
399 } else if (type == "list") {
400 KComboBox *box = ((Listval*)m_valueItems[paramName])->list;
401 setValue = box->itemData(box->currentIndex()).toString();
402 } else if (type == "bool") {
403 QCheckBox *box = ((Boolval*)m_valueItems[paramName])->checkBox;
404 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
405 } else if (type == "color") {
406 KColorButton *color = ((Colorval*)m_valueItems[paramName])->kcolorbutton;
407 setValue = color->color().name();
408 } else if (type == "complex") {
409 ComplexParameter *complex = ((ComplexParameter*)m_valueItems[paramName+"complex"]);
410 namenode.item(i) = complex->getParamDesc();
411 } else if (type == "geometry") {
412 Geometryval *geom = ((Geometryval*)m_valueItems[paramName+"geometry"]);
413 namenode.item(i) = geom->getParamDesc();
414 } else if (type == "position") {
415 KRestrictedLine *line = ((Positionval*)m_valueItems[paramName+"position"])->krestrictedline;
416 int pos = m_timecode.getFrameCount(line->text(), KdenliveSettings::project_fps());
417 if (m_params.attribute("id") == "fadein" || m_params.attribute("id") == "fade_from_black") {
421 line->setText(m_timecode.getTimecodeFromFrames(pos));
423 } else if (m_params.attribute("id") == "fadeout" || m_params.attribute("id") == "fade_to_black") {
424 pos = m_out - (pos - m_in);
425 if (pos > m_out - m_in) {
427 line->setText(m_timecode.getTimecodeFromFrames(pos));
430 setValue = QString::number(pos);
431 } else if (type == "wipe") {
432 Wipeval *wp = (Wipeval*)m_valueItems[paramName];
434 if (wp->start_left->isChecked()) info.start = LEFT;
435 else if (wp->start_right->isChecked()) info.start = RIGHT;
436 else if (wp->start_up->isChecked()) info.start = UP;
437 else if (wp->start_down->isChecked()) info.start = DOWN;
438 else if (wp->start_center->isChecked()) info.start = CENTER;
439 else info.start = LEFT;
440 info.startTransparency = wp->start_transp->value();
441 if (wp->end_left->isChecked()) info.end = LEFT;
442 else if (wp->end_right->isChecked()) info.end = RIGHT;
443 else if (wp->end_up->isChecked()) info.end = UP;
444 else if (wp->end_down->isChecked()) info.end = DOWN;
445 else if (wp->end_center->isChecked()) info.end = CENTER;
446 else info.end = RIGHT;
447 info.endTransparency = wp->end_transp->value();
448 setValue = getWipeString(info);
451 if (!setValue.isNull()) {
452 pa.attributes().namedItem("value").setNodeValue(setValue);
455 emit parameterChanged(oldparam, m_params);
458 void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max)
460 QWidget* toFillin = new QWidget;
461 Constval *ctval = new Constval;
462 ctval->setupUi(toFillin);
464 ctval->horizontalSlider->setMinimum(min);
465 ctval->horizontalSlider->setMaximum(max);
466 ctval->spinBox->setMinimum(min);
467 ctval->spinBox->setMaximum(max);
468 ctval->horizontalSlider->setPageStep((int)(max - min) / 10);
469 ctval->horizontalSlider->setValue(val);
470 ctval->label->setText(name);
471 m_valueItems[name] = ctval;
472 m_uiItems.append(ctval);
473 connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters()));
474 m_items.append(toFillin);
475 m_vbox->addWidget(toFillin);
478 void EffectStackEdit::slotSliderMoved(int)
480 collectAllParameters();
483 void EffectStackEdit::clearAllItems()
486 qDeleteAll(m_uiItems);
489 m_valueItems.clear();
490 QLayoutItem *item = m_vbox->itemAt(0);
492 m_vbox->removeItem(item);
494 item = m_vbox->itemAt(0);