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>
27 #include "ui_constval_ui.h"
28 #include "ui_listval_ui.h"
29 #include "ui_boolval_ui.h"
30 #include "ui_colorval_ui.h"
31 #include "ui_wipeval_ui.h"
32 #include "complexparameter.h"
33 #include "geometryval.h"
35 QMap<QString, QImage> EffectStackEdit::iconCache;
37 EffectStackEdit::EffectStackEdit(QFrame* frame, QWidget *parent): QObject(parent) {
39 QVBoxLayout *vbox1 = new QVBoxLayout(frame);
40 QVBoxLayout *vbox2 = new QVBoxLayout(frame);
41 vbox = new QVBoxLayout(frame);
42 vbox1->setContentsMargins(0, 0, 0, 0);
44 vbox2->setContentsMargins(0, 0, 0, 0);
46 vbox->setContentsMargins(0, 0, 0, 0);
48 frame->setLayout(vbox1);
49 QFont widgetFont = frame->font();
50 widgetFont.setPointSize(widgetFont.pointSize() - 2);
51 frame->setFont(widgetFont);
53 area = new QScrollArea(frame);
54 QWidget *wid = new QWidget(area);
55 area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
56 area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
57 wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
58 //area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::MinimumExpanding));
60 vbox1->addWidget(area);
61 wid->setLayout(vbox2);
62 vbox2->addLayout(vbox);
63 vbox2->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding));
65 area->setWidgetResizable(true);
70 EffectStackEdit::~EffectStackEdit() {
74 void EffectStackEdit::transferParamDesc(const QDomElement& d, int , int) {
77 QDomNodeList namenode = params.elementsByTagName("parameter");
81 for (int i = 0;i < namenode.count() ;i++) {
82 kDebug() << "in form";
83 QDomElement pa = namenode.item(i).toElement();
84 QDomNode na = pa.firstChildElement("name");
85 QString type = pa.attribute("type");
86 QString paramName = na.toElement().text();
87 QWidget * toFillin = new QWidget;
88 QString value = pa.attribute("value").isNull() ?
89 pa.attribute("default") : pa.attribute("value");
90 if (type == "geometry") {
91 pa.setAttribute("namedesc", "X;Y;Width;Height;Transparency");
92 pa.setAttribute("format", "%d%,%d%:%d%x%d%:%d");
93 pa.setAttribute("min", "-500;-500;0;0;0");
94 pa.setAttribute("max", "500;500;200;200;100");
95 } else if (type == "complex") {
96 //pa.setAttribute("namedesc",pa.attribute("name"));
101 //TODO constant, list, bool, complex , color, geometry, position
102 if (type == "double" || type == "constant") {
103 createSliderItem(paramName, value.toInt(), pa.attribute("min").toInt(), pa.attribute("max").toInt());
106 } else if (type == "list") {
107 Ui::Listval_UI *lsval = new Ui::Listval_UI;
108 lsval->setupUi(toFillin);
109 QStringList listitems = pa.attribute("paramlist").split(",");
110 QStringList listitemsdisplay = pa.attribute("paramlistdisplay").split(",");
111 if (listitemsdisplay.count() != listitems.count()) listitemsdisplay = listitems;
112 //lsval->list->addItems(listitems);
113 for (int i = 0;i < listitems.count();i++) {
114 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
116 lsval->list->setCurrentIndex(listitems.indexOf(value));
117 for (int i = 0;i < lsval->list->count();i++) {
118 QString entry = lsval->list->itemData(i).toString();
119 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
120 if (!EffectStackEdit::iconCache.contains(entry)) {
122 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
124 lsval->list->setIconSize(QSize(30, 30));
125 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
128 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
129 lsval->title->setTitle(na.toElement().text());
130 valueItems[paramName] = lsval;
131 uiItems.append(lsval);
132 } else if (type == "bool") {
133 Ui::Boolval_UI *bval = new Ui::Boolval_UI;
134 bval->setupUi(toFillin);
135 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
137 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
138 bval->checkBox->setText(na.toElement().text());
139 valueItems[paramName] = bval;
140 uiItems.append(bval);
141 } else if (type == "complex") {
142 /*QStringList names=nodeAtts.namedItem("name").nodeValue().split(";");
143 QStringList max=nodeAtts.namedItem("max").nodeValue().split(";");
144 QStringList min=nodeAtts.namedItem("min").nodeValue().split(";");
145 QStringList val=value.split(";");
146 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
147 if ( (names.size() == max.size() ) &&
148 (names.size()== min.size()) &&
149 (names.size()== val.size()) )
151 for (int i=0;i< names.size();i++){
152 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
155 ComplexParameter *pl = new ComplexParameter;
156 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
157 pl->setupParam(d, pa.attribute("name"), 0, 100);
159 valueItems[paramName+"complex"] = pl;
161 } else if (type == "geometry") {
162 Geometryval *geo = new Geometryval;
163 connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
164 geo->setupParam(d, pa.attribute("name"), 0, 100);
165 vbox->addWidget(geo);
166 valueItems[paramName+"geometry"] = geo;
168 } else if (type == "color") {
169 Ui::Colorval_UI *cval = new Ui::Colorval_UI;
170 cval->setupUi(toFillin);
172 cval->kcolorbutton->setColor(value.toUInt(&ok, 16));
173 kDebug() << value.toUInt(&ok, 16);
175 connect(cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT(collectAllParameters()));
176 cval->label->setText(na.toElement().text());
177 valueItems[paramName] = cval;
178 uiItems.append(cval);
179 } else if (type == "wipe") {
180 Ui::Wipeval_UI *wpval = new Ui::Wipeval_UI;
181 wpval->setupUi(toFillin);
182 wipeInfo w = getWipeInfo(value);
185 wpval->start_up->setChecked(true);
188 wpval->start_down->setChecked(true);
191 wpval->start_right->setChecked(true);
194 wpval->start_left->setChecked(true);
197 wpval->start_center->setChecked(true);
202 wpval->end_up->setChecked(true);
205 wpval->end_down->setChecked(true);
208 wpval->end_right->setChecked(true);
211 wpval->end_left->setChecked(true);
214 wpval->end_center->setChecked(true);
217 wpval->start_transp->setValue(w.startTransparency);
218 wpval->end_transp->setValue(w.endTransparency);
220 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
221 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
222 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
223 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
224 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
225 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
226 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
227 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
228 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
229 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
230 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
231 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
232 //wpval->title->setTitle(na.toElement().text());
233 valueItems[paramName] = wpval;
234 uiItems.append(wpval);
241 items.append(toFillin);
242 vbox->addWidget(toFillin);
247 wipeInfo EffectStackEdit::getWipeInfo(QString value) {
249 QString start = value.section(";", 0, 0);
250 QString end = value.section(";", 1, 1).section("=", 1, 1);
251 if (start.startsWith("-100%,0")) info.start = LEFT;
252 else if (start.startsWith("100%,0")) info.start = RIGHT;
253 else if (start.startsWith("0%,100%")) info.start = DOWN;
254 else if (start.startsWith("0%,-100%")) info.start = UP;
255 else if (start.startsWith("0%,0%")) info.start = CENTER;
256 if (start.count(':') == 2) info.startTransparency = start.section(':', -1).toInt();
257 else info.startTransparency = 100;
259 if (end.startsWith("-100%,0")) info.end = LEFT;
260 else if (end.startsWith("100%,0")) info.end = RIGHT;
261 else if (end.startsWith("0%,100%")) info.end = DOWN;
262 else if (end.startsWith("0%,-100%")) info.end = UP;
263 else if (end.startsWith("0%,0%")) info.end = CENTER;
264 if (end.count(':') == 2) info.endTransparency = end.section(':', -1).toInt();
265 else info.endTransparency = 100;
269 QString EffectStackEdit::getWipeString(wipeInfo info) {
273 switch (info.start) {
275 start = "-100%,0%:100%x100%";
278 start = "100%,0%:100%x100%";
281 start = "0%,100%:100%x100%";
284 start = "0%,-100%:100%x100%";
287 start = "0%,0%:100%x100%";
290 start.append(":" + QString::number(info.startTransparency));
294 end = "-100%,0%:100%x100%";
297 end = "100%,0%:100%x100%";
300 end = "0%,100%:100%x100%";
303 end = "0%,-100%:100%x100%";
306 end = "0%,0%:100%x100%";
309 end.append(":" + QString::number(info.endTransparency));
310 return QString(start + ";-1=" + end);
313 void EffectStackEdit::collectAllParameters() {
314 QDomElement oldparam = params.cloneNode().toElement();
315 QDomNodeList namenode = params.elementsByTagName("parameter");
317 for (int i = 0;i < namenode.count() ;i++) {
318 QDomNode pa = namenode.item(i);
319 QDomNode na = pa.firstChildElement("name");
320 QString type = pa.attributes().namedItem("type").nodeValue();
322 if (type == "double" || type == "constant") {
323 QSlider* slider = ((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider;
324 setValue = QString::number(slider->value());
325 } else if (type == "list") {
326 KComboBox *box = ((Ui::Listval_UI*)valueItems[na.toElement().text()])->list;
327 setValue = box->itemData(box->currentIndex()).toString();
328 } else if (type == "bool") {
329 QCheckBox *box = ((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox;
330 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
331 } else if (type == "color") {
332 KColorButton *color = ((Ui::Colorval_UI*)valueItems[na.toElement().text()])->kcolorbutton;
333 setValue.sprintf("0x%08x", color->color().rgba());
334 } else if (type == "complex") {
335 ComplexParameter *complex = ((ComplexParameter*)valueItems[na.toElement().text()+"complex"]);
336 namenode.item(i) = complex->getParamDesc();
337 } else if (type == "geometry") {
338 Geometryval *geom = ((Geometryval*)valueItems[na.toElement().text()+"geometry"]);
339 namenode.item(i) = geom->getParamDesc();
340 } else if (type == "wipe") {
341 Ui::Wipeval_UI *wp = (Ui::Wipeval_UI*)valueItems[na.toElement().text()];
343 if (wp->start_left->isChecked()) info.start = LEFT;
344 else if (wp->start_right->isChecked()) info.start = RIGHT;
345 else if (wp->start_up->isChecked()) info.start = UP;
346 else if (wp->start_down->isChecked()) info.start = DOWN;
347 else if (wp->start_center->isChecked()) info.start = CENTER;
348 info.startTransparency = wp->start_transp->value();
349 if (wp->end_left->isChecked()) info.end = LEFT;
350 else if (wp->end_right->isChecked()) info.end = RIGHT;
351 else if (wp->end_up->isChecked()) info.end = UP;
352 else if (wp->end_down->isChecked()) info.end = DOWN;
353 else if (wp->end_center->isChecked()) info.end = CENTER;
354 info.endTransparency = wp->end_transp->value();
355 setValue = getWipeString(info);
358 if (!setValue.isNull()) {
359 pa.attributes().namedItem("value").setNodeValue(setValue);
362 emit parameterChanged(oldparam, params);
365 void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max) {
366 QWidget* toFillin = new QWidget;
367 Ui::Constval_UI *ctval = new Ui::Constval_UI;
368 ctval->setupUi(toFillin);
370 ctval->horizontalSlider->setMinimum(min);
371 ctval->horizontalSlider->setMaximum(max);
372 ctval->spinBox->setMinimum(min);
373 ctval->spinBox->setMaximum(max);
374 ctval->horizontalSlider->setPageStep((int)(max - min) / 10);
375 ctval->horizontalSlider->setValue(val);
376 ctval->label->setText(name);
377 valueItems[name] = ctval;
378 uiItems.append(ctval);
379 connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters()));
380 items.append(toFillin);
381 vbox->addWidget(toFillin);
384 void EffectStackEdit::slotSliderMoved(int) {
385 collectAllParameters();
388 void EffectStackEdit::clearAllItems() {
390 foreach(void *p, uiItems) {