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"
34 QMap<QString, QImage> EffectStackEdit::iconCache;
36 EffectStackEdit::EffectStackEdit(QFrame* frame, QWidget *parent): QObject(parent) {
38 QVBoxLayout *vbox1 = new QVBoxLayout(frame);
39 QVBoxLayout *vbox2 = new QVBoxLayout(frame);
40 vbox = new QVBoxLayout(frame);
41 vbox1->setContentsMargins(0, 0, 0, 0);
43 vbox2->setContentsMargins(0, 0, 0, 0);
45 vbox->setContentsMargins(0, 0, 0, 0);
47 frame->setLayout(vbox1);
48 QFont widgetFont = frame->font();
49 widgetFont.setPointSize(widgetFont.pointSize() - 2);
50 frame->setFont(widgetFont);
52 area = new QScrollArea(frame);
53 QWidget *wid = new QWidget(area);
54 area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
55 area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
56 wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
57 //area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::MinimumExpanding));
59 vbox1->addWidget(area);
60 wid->setLayout(vbox2);
61 vbox2->addLayout(vbox);
62 vbox2->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding));
64 area->setWidgetResizable(true);
69 EffectStackEdit::~EffectStackEdit() {
73 void EffectStackEdit::transferParamDesc(const QDomElement& d, int , int) {
76 QDomNodeList namenode = params.elementsByTagName("parameter");
80 for (int i = 0;i < namenode.count() ;i++) {
81 kDebug() << "in form";
82 QDomElement pa = namenode.item(i).toElement();
83 QDomNode na = pa.firstChildElement("name");
84 QString type = pa.attribute("type");
85 QString paramName = na.toElement().text();
86 QWidget * toFillin = new QWidget;
87 QString value = pa.attribute("value").isNull() ?
88 pa.attribute("default") : pa.attribute("value");
89 if (type == "geometry") {
90 pa.setAttribute("namedesc", "X;Y;W;H;M");
91 pa.setAttribute("format", "%d%,%d%:%d%x%d%:%d%");
92 pa.setAttribute("min", "-200;-20;0;0;0");
93 pa.setAttribute("max", "200;200;100;100;100");
94 } else if (type == "complex") {
95 //pa.setAttribute("namedesc",pa.attribute("name"));
100 //TODO constant, list, bool, complex , color, geometry, position
101 if (type == "double") {
102 createSliderItem(paramName, value.toInt(), pa.attribute("min").toInt(), pa.attribute("max").toInt());
105 } else if (type == "list") {
106 Ui::Listval_UI *lsval = new Ui::Listval_UI;
107 lsval->setupUi(toFillin);
108 QStringList listitems = pa.attribute("paramlist").split(",");
109 QStringList listitemsdisplay = pa.attribute("paramlistdisplay").split(",");
110 if (listitemsdisplay.count() != listitems.count()) listitemsdisplay = listitems;
111 //lsval->list->addItems(listitems);
112 for (int i = 0;i < listitems.count();i++) {
113 lsval->list->addItem(listitemsdisplay.at(i), listitems.at(i));
115 lsval->list->setCurrentIndex(listitems.indexOf(value));
116 for (int i = 0;i < lsval->list->count();i++) {
117 QString entry = lsval->list->itemData(i).toString();
118 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
119 if (!EffectStackEdit::iconCache.contains(entry)) {
121 EffectStackEdit::iconCache[entry] = pix.scaled(30, 30);
123 lsval->list->setIconSize(QSize(30, 30));
124 lsval->list->setItemIcon(i, QPixmap::fromImage(iconCache[entry]));
127 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
128 lsval->title->setTitle(na.toElement().text());
129 valueItems[paramName] = lsval;
130 uiItems.append(lsval);
131 } else if (type == "bool") {
132 Ui::Boolval_UI *bval = new Ui::Boolval_UI;
133 bval->setupUi(toFillin);
134 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
136 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
137 bval->checkBox->setText(na.toElement().text());
138 valueItems[paramName] = bval;
139 uiItems.append(bval);
140 } else if (type == "complex" || type == "geometry") {
141 /*QStringList names=nodeAtts.namedItem("name").nodeValue().split(";");
142 QStringList max=nodeAtts.namedItem("max").nodeValue().split(";");
143 QStringList min=nodeAtts.namedItem("min").nodeValue().split(";");
144 QStringList val=value.split(";");
145 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
146 if ( (names.size() == max.size() ) &&
147 (names.size()== min.size()) &&
148 (names.size()== val.size()) )
150 for (int i=0;i< names.size();i++){
151 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
154 ComplexParameter *pl = new ComplexParameter;
155 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
156 pl->setupParam(d, pa.attribute("name"), 0, 100);
158 valueItems[paramName+"complex"] = pl;
160 } else if (type == "color") {
161 Ui::Colorval_UI *cval = new Ui::Colorval_UI;
162 cval->setupUi(toFillin);
164 cval->kcolorbutton->setColor(value.toUInt(&ok, 16));
165 kDebug() << value.toUInt(&ok, 16);
167 connect(cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT(collectAllParameters()));
168 cval->label->setText(na.toElement().text());
169 valueItems[paramName] = cval;
170 uiItems.append(cval);
171 } else if (type == "wipe") {
172 Ui::Wipeval_UI *wpval = new Ui::Wipeval_UI;
173 wpval->setupUi(toFillin);
174 wipeInfo w = getWipeInfo(value);
177 wpval->start_up->setChecked(true);
180 wpval->start_down->setChecked(true);
183 wpval->start_right->setChecked(true);
186 wpval->start_left->setChecked(true);
189 wpval->start_center->setChecked(true);
194 wpval->end_up->setChecked(true);
197 wpval->end_down->setChecked(true);
200 wpval->end_right->setChecked(true);
203 wpval->end_left->setChecked(true);
206 wpval->end_center->setChecked(true);
209 wpval->start_transp->setValue(w.startTransparency);
210 wpval->end_transp->setValue(w.endTransparency);
212 connect(wpval->end_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
213 connect(wpval->end_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
214 connect(wpval->end_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
215 connect(wpval->end_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
216 connect(wpval->end_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
217 connect(wpval->start_up, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
218 connect(wpval->start_down, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
219 connect(wpval->start_left, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
220 connect(wpval->start_right, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
221 connect(wpval->start_center, SIGNAL(clicked()), this, SLOT(collectAllParameters()));
222 connect(wpval->start_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
223 connect(wpval->end_transp, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
224 //wpval->title->setTitle(na.toElement().text());
225 valueItems[paramName] = wpval;
226 uiItems.append(wpval);
233 items.append(toFillin);
234 vbox->addWidget(toFillin);
239 wipeInfo EffectStackEdit::getWipeInfo(QString value) {
241 QString start = value.section(";", 0, 0);
242 QString end = value.section(";", 1, 1).section("=", 1, 1);
243 if (start.startsWith("-100%,0")) info.start = LEFT;
244 else if (start.startsWith("100%,0")) info.start = RIGHT;
245 else if (start.startsWith("0%,100%")) info.start = DOWN;
246 else if (start.startsWith("0%,-100%")) info.start = UP;
247 else if (start.startsWith("0%,0%")) info.start = CENTER;
248 if (start.count(':') == 2) info.startTransparency = start.section(':', -1).toInt();
249 else info.startTransparency = 100;
251 if (end.startsWith("-100%,0")) info.end = LEFT;
252 else if (end.startsWith("100%,0")) info.end = RIGHT;
253 else if (end.startsWith("0%,100%")) info.end = DOWN;
254 else if (end.startsWith("0%,-100%")) info.end = UP;
255 else if (end.startsWith("0%,0%")) info.end = CENTER;
256 if (end.count(':') == 2) info.endTransparency = end.section(':', -1).toInt();
257 else info.endTransparency = 100;
261 QString EffectStackEdit::getWipeString(wipeInfo info) {
265 switch (info.start) {
267 start = "-100%,0%:100%x100%";
270 start = "100%,0%:100%x100%";
273 start = "0%,100%:100%x100%";
276 start = "0%,-100%:100%x100%";
279 start = "0%,0%:100%x100%";
282 start.append(":" + QString::number(info.startTransparency));
286 end = "-100%,0%:100%x100%";
289 end = "100%,0%:100%x100%";
292 end = "0%,100%:100%x100%";
295 end = "0%,-100%:100%x100%";
298 end = "0%,0%:100%x100%";
301 end.append(":" + QString::number(info.endTransparency));
302 return QString(start + ";-1=" + end);
305 void EffectStackEdit::collectAllParameters() {
306 QDomElement oldparam = params.cloneNode().toElement();
307 QDomNodeList namenode = params.elementsByTagName("parameter");
309 for (int i = 0;i < namenode.count() ;i++) {
310 QDomNode pa = namenode.item(i);
311 QDomNode na = pa.firstChildElement("name");
312 QString type = pa.attributes().namedItem("type").nodeValue();
314 if (type == "double") {
315 QSlider* slider = ((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider;
316 setValue = QString::number(slider->value());
317 } else if (type == "list") {
318 KComboBox *box = ((Ui::Listval_UI*)valueItems[na.toElement().text()])->list;
319 setValue = box->itemData(box->currentIndex()).toString();
320 } else if (type == "bool") {
321 QCheckBox *box = ((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox;
322 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
323 } else if (type == "color") {
324 KColorButton *color = ((Ui::Colorval_UI*)valueItems[na.toElement().text()])->kcolorbutton;
325 setValue.sprintf("0x%08x", color->color().rgba());
326 } else if (type == "complex" || type == "geometry") {
327 ComplexParameter *complex = ((ComplexParameter*)valueItems[na.toElement().text()+"complex"]);
328 namenode.item(i) = complex->getParamDesc();
329 } else if (type == "wipe") {
330 Ui::Wipeval_UI *wp = (Ui::Wipeval_UI*)valueItems[na.toElement().text()];
332 if (wp->start_left->isChecked()) info.start = LEFT;
333 else if (wp->start_right->isChecked()) info.start = RIGHT;
334 else if (wp->start_up->isChecked()) info.start = UP;
335 else if (wp->start_down->isChecked()) info.start = DOWN;
336 else if (wp->start_center->isChecked()) info.start = CENTER;
337 info.startTransparency = wp->start_transp->value();
338 if (wp->end_left->isChecked()) info.end = LEFT;
339 else if (wp->end_right->isChecked()) info.end = RIGHT;
340 else if (wp->end_up->isChecked()) info.end = UP;
341 else if (wp->end_down->isChecked()) info.end = DOWN;
342 else if (wp->end_center->isChecked()) info.end = CENTER;
343 info.endTransparency = wp->end_transp->value();
344 setValue = getWipeString(info);
347 if (!setValue.isNull()) {
348 pa.attributes().namedItem("value").setNodeValue(setValue);
351 emit parameterChanged(oldparam, params);
354 void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max) {
355 QWidget* toFillin = new QWidget;
356 Ui::Constval_UI *ctval = new Ui::Constval_UI;
357 ctval->setupUi(toFillin);
359 ctval->horizontalSlider->setMinimum(min);
360 ctval->horizontalSlider->setMaximum(max);
361 ctval->spinBox->setMinimum(min);
362 ctval->spinBox->setMaximum(max);
363 ctval->horizontalSlider->setPageStep((int)(max - min) / 10);
364 ctval->horizontalSlider->setValue(val);
365 ctval->label->setText(name);
366 valueItems[name] = ctval;
367 uiItems.append(ctval);
368 connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters()));
369 items.append(toFillin);
370 vbox->addWidget(toFillin);
373 void EffectStackEdit::slotSliderMoved(int) {
374 collectAllParameters();
377 void EffectStackEdit::clearAllItems() {
378 foreach(QWidget *w, items) {
379 vbox->removeWidget(w);
382 foreach(void *p, uiItems) {