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 pval->krestrictedline->setText(m_timecode.getTimecodeFromFrames(value.toInt()));
194 connect(pval->krestrictedline, SIGNAL(editingFinished()), this, SLOT(collectAllParameters()));
195 pval->label->setText(paramName);
196 valueItems[paramName + "position"] = pval;
197 uiItems.append(pval);
198 } else if (type == "wipe") {
199 Ui::Wipeval_UI *wpval = new Ui::Wipeval_UI;
200 wpval->setupUi(toFillin);
201 wipeInfo w = getWipeInfo(value);
204 wpval->start_up->setChecked(true);
207 wpval->start_down->setChecked(true);
210 wpval->start_right->setChecked(true);
213 wpval->start_left->setChecked(true);
216 wpval->start_center->setChecked(true);
221 wpval->end_up->setChecked(true);
224 wpval->end_down->setChecked(true);
227 wpval->end_right->setChecked(true);
230 wpval->end_left->setChecked(true);
233 wpval->end_center->setChecked(true);
236 wpval->start_transp->setValue(w.startTransparency);
237 wpval->end_transp->setValue(w.endTransparency);
239 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
240 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
241 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
242 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
243 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
244 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
245 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
246 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
247 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
248 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
249 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
250 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
251 //wpval->title->setTitle(na.toElement().text());
252 valueItems[paramName] = wpval;
253 uiItems.append(wpval);
260 items.append(toFillin);
261 vbox->addWidget(toFillin);
267 void EffectStackEdit::slotSeekToPos(int pos) {
268 emit seekTimeline(m_in + pos);
271 wipeInfo EffectStackEdit::getWipeInfo(QString value) {
273 QString start = value.section(";", 0, 0);
274 QString end = value.section(";", 1, 1).section("=", 1, 1);
275 if (start.startsWith("-100%,0")) info.start = LEFT;
276 else if (start.startsWith("100%,0")) info.start = RIGHT;
277 else if (start.startsWith("0%,100%")) info.start = DOWN;
278 else if (start.startsWith("0%,-100%")) info.start = UP;
279 else if (start.startsWith("0%,0%")) info.start = CENTER;
280 if (start.count(':') == 2) info.startTransparency = start.section(':', -1).toInt();
281 else info.startTransparency = 100;
283 if (end.startsWith("-100%,0")) info.end = LEFT;
284 else if (end.startsWith("100%,0")) info.end = RIGHT;
285 else if (end.startsWith("0%,100%")) info.end = DOWN;
286 else if (end.startsWith("0%,-100%")) info.end = UP;
287 else if (end.startsWith("0%,0%")) info.end = CENTER;
288 if (end.count(':') == 2) info.endTransparency = end.section(':', -1).toInt();
289 else info.endTransparency = 100;
293 QString EffectStackEdit::getWipeString(wipeInfo info) {
297 switch (info.start) {
299 start = "-100%,0%:100%x100%";
302 start = "100%,0%:100%x100%";
305 start = "0%,100%:100%x100%";
308 start = "0%,-100%:100%x100%";
311 start = "0%,0%:100%x100%";
314 start.append(":" + QString::number(info.startTransparency));
318 end = "-100%,0%:100%x100%";
321 end = "100%,0%:100%x100%";
324 end = "0%,100%:100%x100%";
327 end = "0%,-100%:100%x100%";
330 end = "0%,0%:100%x100%";
333 end.append(":" + QString::number(info.endTransparency));
334 return QString(start + ";-1=" + end);
337 void EffectStackEdit::collectAllParameters() {
338 QDomElement oldparam = params.cloneNode().toElement();
339 QDomNodeList namenode = params.elementsByTagName("parameter");
341 for (int i = 0;i < namenode.count() ;i++) {
342 QDomNode pa = namenode.item(i);
343 QDomNode na = pa.firstChildElement("name");
344 QString type = pa.attributes().namedItem("type").nodeValue();
345 QString paramName = i18n(na.toElement().text().toUtf8().data());
348 if (type == "double" || type == "constant") {
349 QSlider* slider = ((Ui::Constval_UI*)valueItems[paramName])->horizontalSlider;
350 setValue = QString::number(slider->value());
351 } else if (type == "list") {
352 KComboBox *box = ((Ui::Listval_UI*)valueItems[paramName])->list;
353 setValue = box->itemData(box->currentIndex()).toString();
354 } else if (type == "bool") {
355 QCheckBox *box = ((Ui::Boolval_UI*)valueItems[paramName])->checkBox;
356 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
357 } else if (type == "color") {
358 KColorButton *color = ((Ui::Colorval_UI*)valueItems[paramName])->kcolorbutton;
359 setValue = color->color().name();
360 setValue.replace('#', "0x");
361 } else if (type == "complex") {
362 ComplexParameter *complex = ((ComplexParameter*)valueItems[paramName+"complex"]);
363 namenode.item(i) = complex->getParamDesc();
364 } else if (type == "geometry") {
365 Geometryval *geom = ((Geometryval*)valueItems[paramName+"geometry"]);
366 namenode.item(i) = geom->getParamDesc();
367 } else if (type == "position") {
368 KRestrictedLine *line = ((Ui::Positionval_UI*)valueItems[paramName+"position"])->krestrictedline;
369 setValue = QString::number(m_timecode.getFrameCount(line->text(), KdenliveSettings::project_fps()));
370 kDebug() << "// NEW POSITION: " << setValue << "(" << line->text() << " PARAM: " << paramName + "position";
371 } else if (type == "wipe") {
372 Ui::Wipeval_UI *wp = (Ui::Wipeval_UI*)valueItems[paramName];
374 if (wp->start_left->isChecked()) info.start = LEFT;
375 else if (wp->start_right->isChecked()) info.start = RIGHT;
376 else if (wp->start_up->isChecked()) info.start = UP;
377 else if (wp->start_down->isChecked()) info.start = DOWN;
378 else if (wp->start_center->isChecked()) info.start = CENTER;
379 info.startTransparency = wp->start_transp->value();
380 if (wp->end_left->isChecked()) info.end = LEFT;
381 else if (wp->end_right->isChecked()) info.end = RIGHT;
382 else if (wp->end_up->isChecked()) info.end = UP;
383 else if (wp->end_down->isChecked()) info.end = DOWN;
384 else if (wp->end_center->isChecked()) info.end = CENTER;
385 info.endTransparency = wp->end_transp->value();
386 setValue = getWipeString(info);
389 if (!setValue.isNull()) {
390 pa.attributes().namedItem("value").setNodeValue(setValue);
393 emit parameterChanged(oldparam, params);
396 void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max) {
397 QWidget* toFillin = new QWidget;
398 Ui::Constval_UI *ctval = new Ui::Constval_UI;
399 ctval->setupUi(toFillin);
401 ctval->horizontalSlider->setMinimum(min);
402 ctval->horizontalSlider->setMaximum(max);
403 ctval->spinBox->setMinimum(min);
404 ctval->spinBox->setMaximum(max);
405 ctval->horizontalSlider->setPageStep((int)(max - min) / 10);
406 ctval->horizontalSlider->setValue(val);
407 ctval->label->setText(name);
408 valueItems[name] = ctval;
409 uiItems.append(ctval);
410 connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters()));
411 items.append(toFillin);
412 vbox->addWidget(toFillin);
415 void EffectStackEdit::slotSliderMoved(int) {
416 collectAllParameters();
419 void EffectStackEdit::clearAllItems() {
421 foreach(void *p, uiItems) {
427 QLayoutItem *item = vbox->itemAt(0);
429 vbox->removeItem(item);
431 item = vbox->itemAt(0);