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 ***************************************************************************/
20 #include "effectstackedit.h"
21 #include <QVBoxLayout>
24 #include <QPushButton>
26 #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_wipeval_ui.h"
33 #include "complexparameter.h"
35 #include "geometryval.h"
37 QMap<QString, QImage> EffectStackEdit::iconCache;
39 EffectStackEdit::EffectStackEdit(QFrame* frame, QWidget *parent): QObject(parent), m_in(0), m_out(0) {
41 QVBoxLayout *vbox1 = new QVBoxLayout(frame);
42 QVBoxLayout *vbox2 = new QVBoxLayout(frame);
43 vbox = new QVBoxLayout(frame);
44 vbox1->setContentsMargins(0, 0, 0, 0);
46 vbox2->setContentsMargins(0, 0, 0, 0);
48 vbox->setContentsMargins(0, 0, 0, 0);
50 frame->setLayout(vbox1);
51 QFont widgetFont = frame->font();
52 widgetFont.setPointSize(widgetFont.pointSize() - 2);
53 frame->setFont(widgetFont);
55 area = new QScrollArea(frame);
56 QWidget *wid = new QWidget(area);
57 area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
58 area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
59 wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
60 //area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::MinimumExpanding));
62 vbox1->addWidget(area);
63 wid->setLayout(vbox2);
64 vbox2->addLayout(vbox);
65 vbox2->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding));
67 area->setWidgetResizable(true);
72 EffectStackEdit::~EffectStackEdit() {
76 void EffectStackEdit::updateProjectFormat(MltVideoProfile profile) {
80 void EffectStackEdit::transferParamDesc(const QDomElement& d, int in, int out) {
86 if (params.isNull()) return;
89 doc.appendChild(doc.importNode(params, true));
90 kDebug() << "IMPORTED TRANS: " << doc.toString();
91 QDomNodeList namenode = params.elementsByTagName("parameter");
92 QDomElement e = params.toElement();
93 const int minFrame = e.attribute("start").toInt();
94 const int maxFrame = e.attribute("end").toInt();
97 for (int i = 0;i < namenode.count() ;i++) {
98 kDebug() << "in form";
99 QDomElement pa = namenode.item(i).toElement();
100 QDomNode na = pa.firstChildElement("name");
101 QString type = pa.attribute("type");
102 QString paramName = na.toElement().text();
103 QWidget * toFillin = new QWidget;
104 QString value = pa.attribute("value").isNull() ?
105 pa.attribute("default") : pa.attribute("value");
106 if (type == "geometry") {
107 /*pa.setAttribute("namedesc", "X;Y;Width;Height;Transparency");
108 pa.setAttribute("format", "%d%,%d%:%d%x%d%:%d");
109 pa.setAttribute("min", "-500;-500;0;0;0");
110 pa.setAttribute("max", "500;500;200;200;100");*/
111 } else if (type == "complex") {
112 //pa.setAttribute("namedesc",pa.attribute("name"));
117 //TODO constant, list, bool, complex , color, geometry, position
118 if (type == "double" || type == "constant") {
119 createSliderItem(paramName, value.toInt(), pa.attribute("min").toInt(), pa.attribute("max").toInt());
122 } else if (type == "list") {
123 Ui::Listval_UI *lsval = new Ui::Listval_UI;
124 lsval->setupUi(toFillin);
125 QStringList listitems = pa.attribute("paramlist").split(",");
126 QStringList listitemsdisplay = pa.attribute("paramlistdisplay").split(",");
127 if (listitemsdisplay.count() != listitems.count()) listitemsdisplay = listitems;
128 //lsval->list->addItems(listitems);
129 for (int i = 0;i < listitems.count();i++) {
130 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
132 lsval->list->setCurrentIndex(listitems.indexOf(value));
133 for (int i = 0;i < lsval->list->count();i++) {
134 QString entry = lsval->list->itemData(i).toString();
135 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
136 if (!EffectStackEdit::iconCache.contains(entry)) {
138 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
140 lsval->list->setIconSize(QSize(30, 30));
141 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
144 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
145 lsval->title->setTitle(na.toElement().text());
146 valueItems[paramName] = lsval;
147 uiItems.append(lsval);
148 } else if (type == "bool") {
149 Ui::Boolval_UI *bval = new Ui::Boolval_UI;
150 bval->setupUi(toFillin);
151 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
153 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
154 bval->checkBox->setText(na.toElement().text());
155 valueItems[paramName] = bval;
156 uiItems.append(bval);
157 } else if (type == "complex") {
158 /*QStringList names=nodeAtts.namedItem("name").nodeValue().split(";");
159 QStringList max=nodeAtts.namedItem("max").nodeValue().split(";");
160 QStringList min=nodeAtts.namedItem("min").nodeValue().split(";");
161 QStringList val=value.split(";");
162 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
163 if ( (names.size() == max.size() ) &&
164 (names.size()== min.size()) &&
165 (names.size()== val.size()) )
167 for (int i=0;i< names.size();i++){
168 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
171 ComplexParameter *pl = new ComplexParameter;
172 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
173 pl->setupParam(d, pa.attribute("name"), 0, 100);
175 valueItems[paramName+"complex"] = pl;
177 } else if (type == "geometry") {
178 Geometryval *geo = new Geometryval(m_profile);
179 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
180 connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int)));
181 geo->setupParam(pa, minFrame, maxFrame);
182 vbox->addWidget(geo);
183 valueItems[paramName+"geometry"] = geo;
185 } else if (type == "color") {
186 Ui::Colorval_UI *cval = new Ui::Colorval_UI;
187 cval->setupUi(toFillin);
189 cval->kcolorbutton->setColor(value.toUInt(&ok, 16));
190 kDebug() << value.toUInt(&ok, 16);
192 connect(cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT(collectAllParameters()));
193 cval->label->setText(na.toElement().text());
194 valueItems[paramName] = cval;
195 uiItems.append(cval);
196 } else if (type == "wipe") {
197 Ui::Wipeval_UI *wpval = new Ui::Wipeval_UI;
198 wpval->setupUi(toFillin);
199 wipeInfo w = getWipeInfo(value);
202 wpval->start_up->setChecked(true);
205 wpval->start_down->setChecked(true);
208 wpval->start_right->setChecked(true);
211 wpval->start_left->setChecked(true);
214 wpval->start_center->setChecked(true);
219 wpval->end_up->setChecked(true);
222 wpval->end_down->setChecked(true);
225 wpval->end_right->setChecked(true);
228 wpval->end_left->setChecked(true);
231 wpval->end_center->setChecked(true);
234 wpval->start_transp->setValue(w.startTransparency);
235 wpval->end_transp->setValue(w.endTransparency);
237 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
238 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
239 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
240 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
241 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
242 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
243 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
244 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
245 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
246 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
247 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
248 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
249 //wpval->title->setTitle(na.toElement().text());
250 valueItems[paramName] = wpval;
251 uiItems.append(wpval);
258 items.append(toFillin);
259 vbox->addWidget(toFillin);
264 void EffectStackEdit::slotSeekToPos(int pos) {
265 emit seekTimeline(m_in + pos);
268 wipeInfo EffectStackEdit::getWipeInfo(QString value) {
270 QString start = value.section(";", 0, 0);
271 QString end = value.section(";", 1, 1).section("=", 1, 1);
272 if (start.startsWith("-100%,0")) info.start = LEFT;
273 else if (start.startsWith("100%,0")) info.start = RIGHT;
274 else if (start.startsWith("0%,100%")) info.start = DOWN;
275 else if (start.startsWith("0%,-100%")) info.start = UP;
276 else if (start.startsWith("0%,0%")) info.start = CENTER;
277 if (start.count(':') == 2) info.startTransparency = start.section(':', -1).toInt();
278 else info.startTransparency = 100;
280 if (end.startsWith("-100%,0")) info.end = LEFT;
281 else if (end.startsWith("100%,0")) info.end = RIGHT;
282 else if (end.startsWith("0%,100%")) info.end = DOWN;
283 else if (end.startsWith("0%,-100%")) info.end = UP;
284 else if (end.startsWith("0%,0%")) info.end = CENTER;
285 if (end.count(':') == 2) info.endTransparency = end.section(':', -1).toInt();
286 else info.endTransparency = 100;
290 QString EffectStackEdit::getWipeString(wipeInfo info) {
294 switch (info.start) {
296 start = "-100%,0%:100%x100%";
299 start = "100%,0%:100%x100%";
302 start = "0%,100%:100%x100%";
305 start = "0%,-100%:100%x100%";
308 start = "0%,0%:100%x100%";
311 start.append(":" + QString::number(info.startTransparency));
315 end = "-100%,0%:100%x100%";
318 end = "100%,0%:100%x100%";
321 end = "0%,100%:100%x100%";
324 end = "0%,-100%:100%x100%";
327 end = "0%,0%:100%x100%";
330 end.append(":" + QString::number(info.endTransparency));
331 return QString(start + ";-1=" + end);
334 void EffectStackEdit::collectAllParameters() {
335 QDomElement oldparam = params.cloneNode().toElement();
336 QDomNodeList namenode = params.elementsByTagName("parameter");
338 for (int i = 0;i < namenode.count() ;i++) {
339 QDomNode pa = namenode.item(i);
340 QDomNode na = pa.firstChildElement("name");
341 QString type = pa.attributes().namedItem("type").nodeValue();
343 if (type == "double" || type == "constant") {
344 QSlider* slider = ((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider;
345 setValue = QString::number(slider->value());
346 } else if (type == "list") {
347 KComboBox *box = ((Ui::Listval_UI*)valueItems[na.toElement().text()])->list;
348 setValue = box->itemData(box->currentIndex()).toString();
349 } else if (type == "bool") {
350 QCheckBox *box = ((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox;
351 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
352 } else if (type == "color") {
353 KColorButton *color = ((Ui::Colorval_UI*)valueItems[na.toElement().text()])->kcolorbutton;
354 setValue.sprintf("0x%08x", color->color().rgba());
355 } else if (type == "complex") {
356 ComplexParameter *complex = ((ComplexParameter*)valueItems[na.toElement().text()+"complex"]);
357 namenode.item(i) = complex->getParamDesc();
358 } else if (type == "geometry") {
359 Geometryval *geom = ((Geometryval*)valueItems[na.toElement().text()+"geometry"]);
360 namenode.item(i) = geom->getParamDesc();
361 } else if (type == "wipe") {
362 Ui::Wipeval_UI *wp = (Ui::Wipeval_UI*)valueItems[na.toElement().text()];
364 if (wp->start_left->isChecked()) info.start = LEFT;
365 else if (wp->start_right->isChecked()) info.start = RIGHT;
366 else if (wp->start_up->isChecked()) info.start = UP;
367 else if (wp->start_down->isChecked()) info.start = DOWN;
368 else if (wp->start_center->isChecked()) info.start = CENTER;
369 info.startTransparency = wp->start_transp->value();
370 if (wp->end_left->isChecked()) info.end = LEFT;
371 else if (wp->end_right->isChecked()) info.end = RIGHT;
372 else if (wp->end_up->isChecked()) info.end = UP;
373 else if (wp->end_down->isChecked()) info.end = DOWN;
374 else if (wp->end_center->isChecked()) info.end = CENTER;
375 info.endTransparency = wp->end_transp->value();
376 setValue = getWipeString(info);
379 if (!setValue.isNull()) {
380 pa.attributes().namedItem("value").setNodeValue(setValue);
383 emit parameterChanged(oldparam, params);
386 void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max) {
387 QWidget* toFillin = new QWidget;
388 Ui::Constval_UI *ctval = new Ui::Constval_UI;
389 ctval->setupUi(toFillin);
391 ctval->horizontalSlider->setMinimum(min);
392 ctval->horizontalSlider->setMaximum(max);
393 ctval->spinBox->setMinimum(min);
394 ctval->spinBox->setMaximum(max);
395 ctval->horizontalSlider->setPageStep((int)(max - min) / 10);
396 ctval->horizontalSlider->setValue(val);
397 ctval->label->setText(name);
398 valueItems[name] = ctval;
399 uiItems.append(ctval);
400 connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters()));
401 items.append(toFillin);
402 vbox->addWidget(toFillin);
405 void EffectStackEdit::slotSliderMoved(int) {
406 collectAllParameters();
409 void EffectStackEdit::clearAllItems() {
411 foreach(void *p, uiItems) {