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>
39 QMap<QString, QImage> EffectStackEdit::iconCache;
41 EffectStackEdit::EffectStackEdit(QWidget *parent) :
46 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
47 QVBoxLayout *vbox1 = new QVBoxLayout(parent);
48 vbox1->setContentsMargins(0, 0, 0, 0);
51 QScrollArea *area = new QScrollArea;
52 QWidget *wid = new QWidget(parent);
53 area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
54 area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
55 wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
56 area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
58 vbox1->addWidget(area);
60 area->setWidgetResizable(true);
61 vbox = new QVBoxLayout(wid);
62 vbox->setContentsMargins(0, 0, 0, 0);
68 EffectStackEdit::~EffectStackEdit()
73 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t)
79 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
81 params.setAttribute(name, value);
84 void EffectStackEdit::transferParamDesc(const QDomElement& d, int in, int out)
91 if (params.isNull()) return;
94 doc.appendChild(doc.importNode(params, true));
95 //kDebug() << "IMPORTED TRANS: " << doc.toString();
96 QDomNodeList namenode = params.elementsByTagName("parameter");
97 QDomElement e = params.toElement();
98 const int minFrame = e.attribute("start").toInt();
99 const int maxFrame = e.attribute("end").toInt();
102 for (int i = 0;i < namenode.count() ;i++) {
103 kDebug() << "in form";
104 QDomElement pa = namenode.item(i).toElement();
105 QDomNode na = pa.firstChildElement("name");
106 QString type = pa.attribute("type");
107 QString paramName = i18n(na.toElement().text().toUtf8().data());
108 QWidget * toFillin = new QWidget;
109 QString value = pa.attribute("value").isNull() ?
110 pa.attribute("default") : pa.attribute("value");
111 if (type == "geometry") {
112 /*pa.setAttribute("namedesc", "X;Y;Width;Height;Transparency");
113 pa.setAttribute("format", "%d%,%d%:%d%x%d%:%d");
114 pa.setAttribute("min", "-500;-500;0;0;0");
115 pa.setAttribute("max", "500;500;200;200;100");*/
116 } else if (type == "complex") {
117 //pa.setAttribute("namedesc",pa.attribute("name"));
122 //TODO constant, list, bool, complex , color, geometry, position
123 if (type == "double" || type == "constant") {
124 createSliderItem(paramName, value.toInt(), pa.attribute("min").toInt(), pa.attribute("max").toInt());
127 } else if (type == "list") {
128 Ui::Listval_UI *lsval = new Ui::Listval_UI;
129 lsval->setupUi(toFillin);
130 QStringList listitems = pa.attribute("paramlist").split(',');
131 QStringList listitemsdisplay = pa.attribute("paramlistdisplay").split(',');
132 if (listitemsdisplay.count() != listitems.count()) listitemsdisplay = listitems;
133 //lsval->list->addItems(listitems);
134 lsval->list->setIconSize(QSize(30, 30));
135 for (int i = 0;i < listitems.count();i++) {
136 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
137 QString entry = listitems.at(i);
138 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
139 if (!EffectStackEdit::iconCache.contains(entry)) {
141 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
143 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
146 if (!value.isEmpty()) lsval->list->setCurrentIndex(listitems.indexOf(value));
148 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
149 lsval->title->setTitle(paramName);
150 valueItems[paramName] = lsval;
151 uiItems.append(lsval);
152 } else if (type == "bool") {
153 Ui::Boolval_UI *bval = new Ui::Boolval_UI;
154 bval->setupUi(toFillin);
155 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
157 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
158 bval->checkBox->setText(paramName);
159 valueItems[paramName] = bval;
160 uiItems.append(bval);
161 } else if (type == "complex") {
162 /*QStringList names=nodeAtts.namedItem("name").nodeValue().split(';');
163 QStringList max=nodeAtts.namedItem("max").nodeValue().split(';');
164 QStringList min=nodeAtts.namedItem("min").nodeValue().split(';');
165 QStringList val=value.split(';');
166 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
167 if ( (names.size() == max.size() ) &&
168 (names.size()== min.size()) &&
169 (names.size()== val.size()) )
171 for (int i=0;i< names.size();i++){
172 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
175 ComplexParameter *pl = new ComplexParameter;
176 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
177 pl->setupParam(d, pa.attribute("name"), 0, 100);
179 valueItems[paramName+"complex"] = pl;
181 } else if (type == "geometry") {
182 Geometryval *geo = new Geometryval(m_profile);
183 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
184 connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int)));
185 geo->setupParam(pa, minFrame, maxFrame);
186 vbox->addWidget(geo);
187 valueItems[paramName+"geometry"] = geo;
189 } else if (type == "color") {
190 Ui::Colorval_UI *cval = new Ui::Colorval_UI;
191 cval->setupUi(toFillin);
193 cval->kcolorbutton->setColor(value.toUInt(&ok, 16));
194 kDebug() << value.toUInt(&ok, 16);
196 connect(cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT(collectAllParameters()));
197 cval->label->setText(paramName);
198 valueItems[paramName] = cval;
199 uiItems.append(cval);
200 } else if (type == "position") {
201 Ui::Positionval_UI *pval = new Ui::Positionval_UI;
202 pval->setupUi(toFillin);
203 int pos = value.toInt();
204 if (d.attribute("id") == "fadein" || d.attribute("id") == "fade_from_black") {
206 } else if (d.attribute("id") == "fadeout" || d.attribute("id") == "fade_to_black") {
207 // fadeout position starts from clip end
208 pos = m_out - (pos - m_in);
210 pval->krestrictedline->setText(m_timecode.getTimecodeFromFrames(pos));
211 connect(pval->krestrictedline, SIGNAL(editingFinished()), this, SLOT(collectAllParameters()));
212 pval->label->setText(paramName);
213 valueItems[paramName + "position"] = pval;
214 uiItems.append(pval);
215 } else if (type == "wipe") {
216 Ui::Wipeval_UI *wpval = new Ui::Wipeval_UI;
217 wpval->setupUi(toFillin);
218 wipeInfo w = getWipeInfo(value);
221 wpval->start_up->setChecked(true);
224 wpval->start_down->setChecked(true);
227 wpval->start_right->setChecked(true);
230 wpval->start_left->setChecked(true);
233 wpval->start_center->setChecked(true);
238 wpval->end_up->setChecked(true);
241 wpval->end_down->setChecked(true);
244 wpval->end_right->setChecked(true);
247 wpval->end_left->setChecked(true);
250 wpval->end_center->setChecked(true);
253 wpval->start_transp->setValue(w.startTransparency);
254 wpval->end_transp->setValue(w.endTransparency);
256 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
257 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
258 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
259 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
260 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
261 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
262 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
263 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
264 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
265 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
266 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
267 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
268 //wpval->title->setTitle(na.toElement().text());
269 valueItems[paramName] = wpval;
270 uiItems.append(wpval);
277 items.append(toFillin);
278 vbox->addWidget(toFillin);
284 void EffectStackEdit::slotSeekToPos(int pos)
286 emit seekTimeline(m_in + pos);
289 wipeInfo EffectStackEdit::getWipeInfo(QString value)
292 QString start = value.section(';', 0, 0);
293 QString end = value.section(';', 1, 1).section('=', 1, 1);
294 if (start.startsWith("-100%,0")) info.start = LEFT;
295 else if (start.startsWith("100%,0")) info.start = RIGHT;
296 else if (start.startsWith("0%,100%")) info.start = DOWN;
297 else if (start.startsWith("0%,-100%")) info.start = UP;
298 else info.start = CENTER;
299 if (start.count(':') == 2) info.startTransparency = start.section(':', -1).toInt();
300 else info.startTransparency = 100;
302 if (end.startsWith("-100%,0")) info.end = LEFT;
303 else if (end.startsWith("100%,0")) info.end = RIGHT;
304 else if (end.startsWith("0%,100%")) info.end = DOWN;
305 else if (end.startsWith("0%,-100%")) info.end = UP;
306 else info.end = CENTER;
307 if (end.count(':') == 2) info.endTransparency = end.section(':', -1).toInt();
308 else info.endTransparency = 100;
312 QString EffectStackEdit::getWipeString(wipeInfo info)
317 switch (info.start) {
319 start = "-100%,0%:100%x100%";
322 start = "100%,0%:100%x100%";
325 start = "0%,100%:100%x100%";
328 start = "0%,-100%:100%x100%";
331 start = "0%,0%:100%x100%";
334 start.append(':' + QString::number(info.startTransparency));
338 end = "-100%,0%:100%x100%";
341 end = "100%,0%:100%x100%";
344 end = "0%,100%:100%x100%";
347 end = "0%,-100%:100%x100%";
350 end = "0%,0%:100%x100%";
353 end.append(':' + QString::number(info.endTransparency));
354 return QString(start + ";-1=" + end);
357 void EffectStackEdit::collectAllParameters()
359 QDomElement oldparam = params.cloneNode().toElement();
360 QDomNodeList namenode = params.elementsByTagName("parameter");
362 for (int i = 0;i < namenode.count() ;i++) {
363 QDomNode pa = namenode.item(i);
364 QDomNode na = pa.firstChildElement("name");
365 QString type = pa.attributes().namedItem("type").nodeValue();
366 QString paramName = i18n(na.toElement().text().toUtf8().data());
369 if (type == "double" || type == "constant") {
370 QSlider* slider = ((Ui::Constval_UI*)valueItems[paramName])->horizontalSlider;
371 setValue = QString::number(slider->value());
372 } else if (type == "list") {
373 KComboBox *box = ((Ui::Listval_UI*)valueItems[paramName])->list;
374 setValue = box->itemData(box->currentIndex()).toString();
375 } else if (type == "bool") {
376 QCheckBox *box = ((Ui::Boolval_UI*)valueItems[paramName])->checkBox;
377 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
378 } else if (type == "color") {
379 KColorButton *color = ((Ui::Colorval_UI*)valueItems[paramName])->kcolorbutton;
380 setValue = color->color().name();
381 } else if (type == "complex") {
382 ComplexParameter *complex = ((ComplexParameter*)valueItems[paramName+"complex"]);
383 namenode.item(i) = complex->getParamDesc();
384 } else if (type == "geometry") {
385 Geometryval *geom = ((Geometryval*)valueItems[paramName+"geometry"]);
386 namenode.item(i) = geom->getParamDesc();
387 } else if (type == "position") {
388 KRestrictedLine *line = ((Ui::Positionval_UI*)valueItems[paramName+"position"])->krestrictedline;
389 int pos = m_timecode.getFrameCount(line->text(), KdenliveSettings::project_fps());
390 if (params.attribute("id") == "fadein" || params.attribute("id") == "fade_from_black") {
394 line->setText(m_timecode.getTimecodeFromFrames(pos));
396 } else if (params.attribute("id") == "fadeout" || params.attribute("id") == "fade_to_black") {
397 pos = m_out - (pos - m_in);
398 if (pos > m_out - m_in) {
400 line->setText(m_timecode.getTimecodeFromFrames(pos));
403 setValue = QString::number(pos);
404 } else if (type == "wipe") {
405 Ui::Wipeval_UI *wp = (Ui::Wipeval_UI*)valueItems[paramName];
407 if (wp->start_left->isChecked()) info.start = LEFT;
408 else if (wp->start_right->isChecked()) info.start = RIGHT;
409 else if (wp->start_up->isChecked()) info.start = UP;
410 else if (wp->start_down->isChecked()) info.start = DOWN;
411 else if (wp->start_center->isChecked()) info.start = CENTER;
412 else info.start = LEFT;
413 info.startTransparency = wp->start_transp->value();
414 if (wp->end_left->isChecked()) info.end = LEFT;
415 else if (wp->end_right->isChecked()) info.end = RIGHT;
416 else if (wp->end_up->isChecked()) info.end = UP;
417 else if (wp->end_down->isChecked()) info.end = DOWN;
418 else if (wp->end_center->isChecked()) info.end = CENTER;
419 else info.end = RIGHT;
420 info.endTransparency = wp->end_transp->value();
421 setValue = getWipeString(info);
424 if (!setValue.isNull()) {
425 pa.attributes().namedItem("value").setNodeValue(setValue);
428 emit parameterChanged(oldparam, params);
431 void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max)
433 QWidget* toFillin = new QWidget;
434 Ui::Constval_UI *ctval = new Ui::Constval_UI;
435 ctval->setupUi(toFillin);
437 ctval->horizontalSlider->setMinimum(min);
438 ctval->horizontalSlider->setMaximum(max);
439 ctval->spinBox->setMinimum(min);
440 ctval->spinBox->setMaximum(max);
441 ctval->horizontalSlider->setPageStep((int)(max - min) / 10);
442 ctval->horizontalSlider->setValue(val);
443 ctval->label->setText(name);
444 valueItems[name] = ctval;
445 uiItems.append(ctval);
446 connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters()));
447 items.append(toFillin);
448 vbox->addWidget(toFillin);
451 void EffectStackEdit::slotSliderMoved(int)
453 collectAllParameters();
456 void EffectStackEdit::clearAllItems()
459 foreach(void *p, uiItems) {
465 QLayoutItem *item = vbox->itemAt(0);
467 vbox->removeItem(item);
469 item = vbox->itemAt(0);