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 "parameterplotter.h"
32 EffectStackEdit::EffectStackEdit(QFrame* frame,QWidget *parent): QObject(parent)
35 QVBoxLayout *vbox1=new QVBoxLayout;
36 frame->setLayout(vbox1);
37 vbox=new QVBoxLayout(frame);
39 area=new QScrollArea(frame);
40 QWidget *wid=new QWidget(area);
41 area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
42 area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
43 wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum));
44 //area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::MinimumExpanding));
46 vbox1->addWidget(area);
49 area->setWidgetResizable(true);
53 void EffectStackEdit::transferParamDesc(const QDomElement& d,int ,int){
56 QDomNodeList namenode = params.elementsByTagName("parameter");
60 QTextStream str(&outstr);
63 for (int i=0;i< namenode.count() ;i++){
64 kDebug() << "in form";
65 QDomNode pa=namenode.item(i);
66 QDomNode na=pa.firstChildElement("name");
67 QDomNamedNodeMap nodeAtts=pa.attributes();
68 QString type=nodeAtts.namedItem("type").nodeValue();
69 QString paramName=na.toElement().text();
70 QWidget * toFillin=new QWidget;
71 QString value=nodeAtts.namedItem("value").isNull()?
72 nodeAtts.namedItem("default").nodeValue():
73 nodeAtts.namedItem("value").nodeValue();
75 //TODO constant, list, bool, complex , color, geometry, position
76 if (type=="double" || type=="constant"){
77 createSliderItem(paramName,value.toInt(),nodeAtts.namedItem("min").nodeValue().toInt(),nodeAtts.namedItem("max").nodeValue().toInt() );
80 }else if (type=="list"){
82 Ui::Listval_UI *lsval=new Ui::Listval_UI;
83 lsval->setupUi(toFillin);
84 nodeAtts.namedItem("paramlist");
85 QStringList listitems=nodeAtts.namedItem("paramlist").nodeValue().split(",");
86 lsval->list->addItems(listitems);
87 lsval->list->setCurrentIndex(listitems.indexOf(value));;
88 connect (lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT (collectAllParameters()));
89 lsval->title->setTitle(na.toElement().text() );
90 valueItems[paramName]=lsval;
91 uiItems.append(lsval);
92 }else if (type=="bool"){
93 Ui::Boolval_UI *bval=new Ui::Boolval_UI;
94 bval->setupUi(toFillin);
95 bval->checkBox->setCheckState(value=="0" ? Qt::Unchecked : Qt::Checked);
97 connect (bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT (collectAllParameters()));
98 bval->title->setTitle(na.toElement().text() );
99 valueItems[paramName]=bval;
100 uiItems.append(bval);
101 }else if(type=="complex"){
102 QStringList names=nodeAtts.namedItem("name").nodeValue().split(";");
103 QStringList max=nodeAtts.namedItem("max").nodeValue().split(";");
104 QStringList min=nodeAtts.namedItem("min").nodeValue().split(";");
105 QStringList val=value.split(";");
106 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
107 if ( (names.size() == max.size() ) &&
108 (names.size()== min.size()) &&
109 (names.size()== val.size()) )
111 for (int i=0;i< names.size();i++){
112 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
115 ParameterPlotter *pl=new ParameterPlotter;
124 items.append(toFillin);
125 vbox->addWidget(toFillin);
129 void EffectStackEdit::collectAllParameters(){
130 QDomNodeList namenode = params.elementsByTagName("parameter");
132 for (int i=0;i< namenode.count() ;i++){
133 QDomNode pa=namenode.item(i);
134 QDomNode na=pa.firstChildElement("name");
135 QString type=pa.attributes().namedItem("type").nodeValue();
137 if (type=="double" || type=="constant"){
138 QSlider* slider=((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider;
139 setValue=QString::number(slider->value());
142 KComboBox *box=((Ui::Listval_UI*)valueItems[na.toElement().text()])->list;
143 setValue=box->currentText();
146 QCheckBox *box=((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox;
147 setValue=box->checkState() == Qt::Checked ? "1" :"0" ;
149 if (!setValue.isEmpty()){
150 pa.attributes().namedItem("value").setNodeValue(setValue);
153 emit parameterChanged(params);
156 void EffectStackEdit::createSliderItem(const QString& name, int val ,int min, int max){
157 QWidget* toFillin=new QWidget;
158 Ui::Constval_UI *ctval=new Ui::Constval_UI;
159 ctval->setupUi(toFillin);
161 ctval->horizontalSlider->setMinimum(min);
162 ctval->horizontalSlider->setMaximum(max);
163 ctval->spinBox->setMinimum(min);
164 ctval->spinBox->setMaximum(max);
166 ctval->horizontalSlider->setValue(val);
167 ctval->title->setTitle(name);
168 valueItems[name]=ctval;
169 uiItems.append(ctval);
170 connect (ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT (collectAllParameters()));
171 items.append(toFillin);
172 vbox->addWidget(toFillin);
175 void EffectStackEdit::slotSliderMoved(int){
176 collectAllParameters();
179 void EffectStackEdit::clearAllItems(){
180 foreach (QWidget* w,items){
181 vbox->removeWidget(w);
184 foreach(void * p, uiItems){