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 <QVBoxLayout>
21 #include <QPushButton>
23 #include <QScrollArea>
28 #include "ui_constval_ui.h"
29 #include "ui_listval_ui.h"
30 #include "ui_boolval_ui.h"
31 #include "ui_colorval_ui.h"
32 #include "ui_positionval_ui.h"
33 #include "ui_wipeval_ui.h"
34 #include "complexparameter.h"
35 #include "effectstackedit.h"
36 #include "geometryval.h"
38 #include "kdenlivesettings.h"
40 QMap<QString, QImage> EffectStackEdit::iconCache;
42 EffectStackEdit::EffectStackEdit(QWidget *parent): QWidget(parent), m_in(0), m_out(0) {
43 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
44 QVBoxLayout *vbox1 = new QVBoxLayout(parent);
45 vbox1->setContentsMargins(0, 0, 0, 0);
48 QScrollArea *area = new QScrollArea;
49 QWidget *wid = new QWidget(parent);
50 area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
51 area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
52 wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
53 area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
55 vbox1->addWidget(area);
57 area->setWidgetResizable(true);
58 vbox = new QVBoxLayout(wid);
59 vbox->setContentsMargins(0, 0, 0, 0);
65 EffectStackEdit::~EffectStackEdit() {
69 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile, Timecode t) {
74 void EffectStackEdit::transferParamDesc(const QDomElement& d, int in, int out) {
80 if (params.isNull()) return;
83 doc.appendChild(doc.importNode(params, true));
84 kDebug() << "IMPORTED TRANS: " << doc.toString();
85 QDomNodeList namenode = params.elementsByTagName("parameter");
86 QDomElement e = params.toElement();
87 const int minFrame = e.attribute("start").toInt();
88 const int maxFrame = e.attribute("end").toInt();
91 for (int i = 0;i < namenode.count() ;i++) {
92 kDebug() << "in form";
93 QDomElement pa = namenode.item(i).toElement();
94 QDomNode na = pa.firstChildElement("name");
95 QString type = pa.attribute("type");
96 QString paramName = i18n(na.toElement().text().toUtf8().data());
97 QWidget * toFillin = new QWidget;
98 QString value = pa.attribute("value").isNull() ?
99 pa.attribute("default") : pa.attribute("value");
100 if (type == "geometry") {
101 /*pa.setAttribute("namedesc", "X;Y;Width;Height;Transparency");
102 pa.setAttribute("format", "%d%,%d%:%d%x%d%:%d");
103 pa.setAttribute("min", "-500;-500;0;0;0");
104 pa.setAttribute("max", "500;500;200;200;100");*/
105 } else if (type == "complex") {
106 //pa.setAttribute("namedesc",pa.attribute("name"));
111 //TODO constant, list, bool, complex , color, geometry, position
112 if (type == "double" || type == "constant") {
113 createSliderItem(paramName, value.toInt(), pa.attribute("min").toInt(), pa.attribute("max").toInt());
116 } else if (type == "list") {
117 Ui::Listval_UI *lsval = new Ui::Listval_UI;
118 lsval->setupUi(toFillin);
119 QStringList listitems = pa.attribute("paramlist").split(",");
120 QStringList listitemsdisplay = pa.attribute("paramlistdisplay").split(",");
121 if (listitemsdisplay.count() != listitems.count()) listitemsdisplay = listitems;
122 //lsval->list->addItems(listitems);
123 for (int i = 0;i < listitems.count();i++) {
124 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
126 lsval->list->setCurrentIndex(listitems.indexOf(value));
127 for (int i = 0;i < lsval->list->count();i++) {
128 QString entry = lsval->list->itemData(i).toString();
129 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
130 if (!EffectStackEdit::iconCache.contains(entry)) {
132 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
134 lsval->list->setIconSize(QSize(30, 30));
135 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
138 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
139 lsval->title->setTitle(paramName);
140 valueItems[paramName] = lsval;
141 uiItems.append(lsval);
142 } else if (type == "bool") {
143 Ui::Boolval_UI *bval = new Ui::Boolval_UI;
144 bval->setupUi(toFillin);
145 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
147 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
148 bval->checkBox->setText(paramName);
149 valueItems[paramName] = bval;
150 uiItems.append(bval);
151 } else if (type == "complex") {
152 /*QStringList names=nodeAtts.namedItem("name").nodeValue().split(";");
153 QStringList max=nodeAtts.namedItem("max").nodeValue().split(";");
154 QStringList min=nodeAtts.namedItem("min").nodeValue().split(";");
155 QStringList val=value.split(";");
156 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
157 if ( (names.size() == max.size() ) &&
158 (names.size()== min.size()) &&
159 (names.size()== val.size()) )
161 for (int i=0;i< names.size();i++){
162 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
165 ComplexParameter *pl = new ComplexParameter;
166 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
167 pl->setupParam(d, pa.attribute("name"), 0, 100);
169 valueItems[paramName+"complex"] = pl;
171 } else if (type == "geometry") {
172 Geometryval *geo = new Geometryval(m_profile);
173 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
174 connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int)));
175 geo->setupParam(pa, minFrame, maxFrame);
176 vbox->addWidget(geo);
177 valueItems[paramName+"geometry"] = geo;
179 } else if (type == "color") {
180 Ui::Colorval_UI *cval = new Ui::Colorval_UI;
181 cval->setupUi(toFillin);
183 cval->kcolorbutton->setColor(value.toUInt(&ok, 16));
184 kDebug() << value.toUInt(&ok, 16);
186 connect(cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT(collectAllParameters()));
187 cval->label->setText(paramName);
188 valueItems[paramName] = cval;
189 uiItems.append(cval);
190 } else if (type == "position") {
191 Ui::Positionval_UI *pval = new Ui::Positionval_UI;
192 pval->setupUi(toFillin);
193 int pos = value.toInt();
194 if (d.attribute("id") == "fadein") {
196 } else if (d.attribute("id") == "fadeout") {
197 // fadeout position starts from clip end
198 pos = m_out - (pos - m_in);
200 pval->krestrictedline->setText(m_timecode.getTimecodeFromFrames(pos));
201 connect(pval->krestrictedline, SIGNAL(editingFinished()), this, SLOT(collectAllParameters()));
202 pval->label->setText(paramName);
203 valueItems[paramName + "position"] = pval;
204 uiItems.append(pval);
205 } else if (type == "wipe") {
206 Ui::Wipeval_UI *wpval = new Ui::Wipeval_UI;
207 wpval->setupUi(toFillin);
208 wipeInfo w = getWipeInfo(value);
211 wpval->start_up->setChecked(true);
214 wpval->start_down->setChecked(true);
217 wpval->start_right->setChecked(true);
220 wpval->start_left->setChecked(true);
223 wpval->start_center->setChecked(true);
228 wpval->end_up->setChecked(true);
231 wpval->end_down->setChecked(true);
234 wpval->end_right->setChecked(true);
237 wpval->end_left->setChecked(true);
240 wpval->end_center->setChecked(true);
243 wpval->start_transp->setValue(w.startTransparency);
244 wpval->end_transp->setValue(w.endTransparency);
246 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
247 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
248 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
249 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
250 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
251 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
252 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
253 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
254 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
255 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
256 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
257 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
258 //wpval->title->setTitle(na.toElement().text());
259 valueItems[paramName] = wpval;
260 uiItems.append(wpval);
267 items.append(toFillin);
268 vbox->addWidget(toFillin);
274 void EffectStackEdit::slotSeekToPos(int pos) {
275 emit seekTimeline(m_in + pos);
278 wipeInfo EffectStackEdit::getWipeInfo(QString value) {
280 QString start = value.section(";", 0, 0);
281 QString end = value.section(";", 1, 1).section("=", 1, 1);
282 if (start.startsWith("-100%,0")) info.start = LEFT;
283 else if (start.startsWith("100%,0")) info.start = RIGHT;
284 else if (start.startsWith("0%,100%")) info.start = DOWN;
285 else if (start.startsWith("0%,-100%")) info.start = UP;
286 else if (start.startsWith("0%,0%")) info.start = CENTER;
287 if (start.count(':') == 2) info.startTransparency = start.section(':', -1).toInt();
288 else info.startTransparency = 100;
290 if (end.startsWith("-100%,0")) info.end = LEFT;
291 else if (end.startsWith("100%,0")) info.end = RIGHT;
292 else if (end.startsWith("0%,100%")) info.end = DOWN;
293 else if (end.startsWith("0%,-100%")) info.end = UP;
294 else if (end.startsWith("0%,0%")) info.end = CENTER;
295 if (end.count(':') == 2) info.endTransparency = end.section(':', -1).toInt();
296 else info.endTransparency = 100;
300 QString EffectStackEdit::getWipeString(wipeInfo info) {
304 switch (info.start) {
306 start = "-100%,0%:100%x100%";
309 start = "100%,0%:100%x100%";
312 start = "0%,100%:100%x100%";
315 start = "0%,-100%:100%x100%";
318 start = "0%,0%:100%x100%";
321 start.append(":" + QString::number(info.startTransparency));
325 end = "-100%,0%:100%x100%";
328 end = "100%,0%:100%x100%";
331 end = "0%,100%:100%x100%";
334 end = "0%,-100%:100%x100%";
337 end = "0%,0%:100%x100%";
340 end.append(":" + QString::number(info.endTransparency));
341 return QString(start + ";-1=" + end);
344 void EffectStackEdit::collectAllParameters() {
345 QDomElement oldparam = params.cloneNode().toElement();
346 QDomNodeList namenode = params.elementsByTagName("parameter");
348 for (int i = 0;i < namenode.count() ;i++) {
349 QDomNode pa = namenode.item(i);
350 QDomNode na = pa.firstChildElement("name");
351 QString type = pa.attributes().namedItem("type").nodeValue();
352 QString paramName = i18n(na.toElement().text().toUtf8().data());
355 if (type == "double" || type == "constant") {
356 QSlider* slider = ((Ui::Constval_UI*)valueItems[paramName])->horizontalSlider;
357 setValue = QString::number(slider->value());
358 } else if (type == "list") {
359 KComboBox *box = ((Ui::Listval_UI*)valueItems[paramName])->list;
360 setValue = box->itemData(box->currentIndex()).toString();
361 } else if (type == "bool") {
362 QCheckBox *box = ((Ui::Boolval_UI*)valueItems[paramName])->checkBox;
363 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
364 } else if (type == "color") {
365 KColorButton *color = ((Ui::Colorval_UI*)valueItems[paramName])->kcolorbutton;
366 setValue = color->color().name();
367 setValue.replace('#', "0x");
368 } else if (type == "complex") {
369 ComplexParameter *complex = ((ComplexParameter*)valueItems[paramName+"complex"]);
370 namenode.item(i) = complex->getParamDesc();
371 } else if (type == "geometry") {
372 Geometryval *geom = ((Geometryval*)valueItems[paramName+"geometry"]);
373 namenode.item(i) = geom->getParamDesc();
374 } else if (type == "position") {
375 KRestrictedLine *line = ((Ui::Positionval_UI*)valueItems[paramName+"position"])->krestrictedline;
376 int pos = m_timecode.getFrameCount(line->text(), KdenliveSettings::project_fps());
377 if (params.attribute("id") == "fadein") {
381 line->setText(m_timecode.getTimecodeFromFrames(pos));
383 } else if (params.attribute("id") == "fadeout") {
384 pos = m_out - (pos - m_in);
385 if (pos > m_out - m_in) {
387 line->setText(m_timecode.getTimecodeFromFrames(pos));
390 setValue = QString::number(pos);
391 } else if (type == "wipe") {
392 Ui::Wipeval_UI *wp = (Ui::Wipeval_UI*)valueItems[paramName];
394 if (wp->start_left->isChecked()) info.start = LEFT;
395 else if (wp->start_right->isChecked()) info.start = RIGHT;
396 else if (wp->start_up->isChecked()) info.start = UP;
397 else if (wp->start_down->isChecked()) info.start = DOWN;
398 else if (wp->start_center->isChecked()) info.start = CENTER;
399 info.startTransparency = wp->start_transp->value();
400 if (wp->end_left->isChecked()) info.end = LEFT;
401 else if (wp->end_right->isChecked()) info.end = RIGHT;
402 else if (wp->end_up->isChecked()) info.end = UP;
403 else if (wp->end_down->isChecked()) info.end = DOWN;
404 else if (wp->end_center->isChecked()) info.end = CENTER;
405 info.endTransparency = wp->end_transp->value();
406 setValue = getWipeString(info);
409 if (!setValue.isNull()) {
410 pa.attributes().namedItem("value").setNodeValue(setValue);
413 emit parameterChanged(oldparam, params);
416 void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max) {
417 QWidget* toFillin = new QWidget;
418 Ui::Constval_UI *ctval = new Ui::Constval_UI;
419 ctval->setupUi(toFillin);
421 ctval->horizontalSlider->setMinimum(min);
422 ctval->horizontalSlider->setMaximum(max);
423 ctval->spinBox->setMinimum(min);
424 ctval->spinBox->setMaximum(max);
425 ctval->horizontalSlider->setPageStep((int)(max - min) / 10);
426 ctval->horizontalSlider->setValue(val);
427 ctval->label->setText(name);
428 valueItems[name] = ctval;
429 uiItems.append(ctval);
430 connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters()));
431 items.append(toFillin);
432 vbox->addWidget(toFillin);
435 void EffectStackEdit::slotSliderMoved(int) {
436 collectAllParameters();
439 void EffectStackEdit::clearAllItems() {
441 foreach(void *p, uiItems) {
447 QLayoutItem *item = vbox->itemAt(0);
449 vbox->removeItem(item);
451 item = vbox->itemAt(0);