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 "complexparameter.h"
33 EffectStackEdit::EffectStackEdit(QFrame* frame, QWidget *parent): QObject(parent) {
35 QVBoxLayout *vbox1 = new QVBoxLayout(frame);
36 QVBoxLayout *vbox2 = new QVBoxLayout(frame);
37 vbox = new QVBoxLayout(frame);
38 vbox1->setContentsMargins(0, 0, 0, 0);
40 vbox2->setContentsMargins(0, 0, 0, 0);
42 vbox->setContentsMargins(0, 0, 0, 0);
44 frame->setLayout(vbox1);
45 QFont widgetFont = frame->font();
46 widgetFont.setPointSize(widgetFont.pointSize() - 2);
47 frame->setFont(widgetFont);
49 area = new QScrollArea(frame);
50 QWidget *wid = new QWidget(area);
51 area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
52 area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
53 wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
54 //area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::MinimumExpanding));
56 vbox1->addWidget(area);
57 wid->setLayout(vbox2);
58 vbox2->addLayout(vbox);
59 vbox2->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding));
61 area->setWidgetResizable(true);
65 void EffectStackEdit::transferParamDesc(const QDomElement& d, int , int) {
68 QDomNodeList namenode = params.elementsByTagName("parameter");
72 for (int i = 0;i < namenode.count() ;i++) {
73 kDebug() << "in form";
74 QDomNode pa = namenode.item(i);
75 QDomNode na = pa.firstChildElement("name");
76 QDomNamedNodeMap nodeAtts = pa.attributes();
77 QString type = nodeAtts.namedItem("type").nodeValue();
78 QString paramName = na.toElement().text();
79 QWidget * toFillin = new QWidget;
80 QString value = nodeAtts.namedItem("value").isNull() ?
81 nodeAtts.namedItem("default").nodeValue() :
82 nodeAtts.namedItem("value").nodeValue();
84 //TODO constant, list, bool, complex , color, geometry, position
85 if (type == "double" || type == "constant") {
86 createSliderItem(paramName, value.toInt(), nodeAtts.namedItem("min").nodeValue().toInt(), nodeAtts.namedItem("max").nodeValue().toInt());
89 } else if (type == "list") {
91 Ui::Listval_UI *lsval = new Ui::Listval_UI;
92 lsval->setupUi(toFillin);
93 nodeAtts.namedItem("paramlist");
94 QStringList listitems = nodeAtts.namedItem("paramlist").nodeValue().split(",");
95 lsval->list->addItems(listitems);
96 lsval->list->setCurrentIndex(listitems.indexOf(value));;
97 connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
98 lsval->title->setTitle(na.toElement().text());
99 valueItems[paramName] = lsval;
100 uiItems.append(lsval);
101 } else if (type == "bool") {
102 Ui::Boolval_UI *bval = new Ui::Boolval_UI;
103 bval->setupUi(toFillin);
104 bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
106 connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
107 bval->checkBox->setText(na.toElement().text());
108 valueItems[paramName] = bval;
109 uiItems.append(bval);
110 } else if (type == "complex") {
111 /*QStringList names=nodeAtts.namedItem("name").nodeValue().split(";");
112 QStringList max=nodeAtts.namedItem("max").nodeValue().split(";");
113 QStringList min=nodeAtts.namedItem("min").nodeValue().split(";");
114 QStringList val=value.split(";");
115 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
116 if ( (names.size() == max.size() ) &&
117 (names.size()== min.size()) &&
118 (names.size()== val.size()) )
120 for (int i=0;i< names.size();i++){
121 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
124 ComplexParameter *pl = new ComplexParameter;
125 connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
126 pl->setupParam(d, 0, 100);
128 valueItems[paramName+"complex"] = pl;
130 } else if (type == "color") {
131 Ui::Colorval_UI *cval = new Ui::Colorval_UI;
132 cval->setupUi(toFillin);
134 cval->kcolorbutton->setColor(value.toUInt(&ok, 16));
135 kDebug() << value.toUInt(&ok, 16);
137 connect(cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT(collectAllParameters()));
138 cval->label->setText(na.toElement().text());
139 valueItems[paramName] = cval;
140 uiItems.append(cval);
147 items.append(toFillin);
148 vbox->addWidget(toFillin);
152 void EffectStackEdit::collectAllParameters() {
153 QDomElement oldparam = params.cloneNode().toElement();
154 QDomNodeList namenode = params.elementsByTagName("parameter");
156 for (int i = 0;i < namenode.count() ;i++) {
157 QDomNode pa = namenode.item(i);
158 QDomNode na = pa.firstChildElement("name");
159 QString type = pa.attributes().namedItem("type").nodeValue();
161 if (type == "double" || type == "constant") {
162 QSlider* slider = ((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider;
163 setValue = QString::number(slider->value());
165 if (type == "list") {
166 KComboBox *box = ((Ui::Listval_UI*)valueItems[na.toElement().text()])->list;
167 setValue = box->currentText();
169 if (type == "bool") {
170 QCheckBox *box = ((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox;
171 setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
173 if (type == "color") {
174 KColorButton *color = ((Ui::Colorval_UI*)valueItems[na.toElement().text()])->kcolorbutton;
175 setValue.sprintf("0x%08x", color->color().rgba());
177 if (type == "complex") {
178 ComplexParameter *complex = ((ComplexParameter*)valueItems[na.toElement().text()+"complex"]);
179 namenode.item(i) = complex->getParamDesc();
181 if (!setValue.isEmpty()) {
182 pa.attributes().namedItem("value").setNodeValue(setValue);
185 emit parameterChanged(oldparam, params);
188 void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max) {
189 QWidget* toFillin = new QWidget;
190 Ui::Constval_UI *ctval = new Ui::Constval_UI;
191 ctval->setupUi(toFillin);
193 ctval->horizontalSlider->setMinimum(min);
194 ctval->horizontalSlider->setMaximum(max);
195 ctval->spinBox->setMinimum(min);
196 ctval->spinBox->setMaximum(max);
197 ctval->horizontalSlider->setPageStep((int)(max - min) / 10);
198 ctval->horizontalSlider->setValue(val);
199 ctval->label->setText(name);
200 valueItems[name] = ctval;
201 uiItems.append(ctval);
202 connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters()));
203 items.append(toFillin);
204 vbox->addWidget(toFillin);
207 void EffectStackEdit::slotSliderMoved(int) {
208 collectAllParameters();
211 void EffectStackEdit::clearAllItems() {
212 foreach(QWidget* w, items) {
213 vbox->removeWidget(w);
216 foreach(void * p, uiItems) {