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 "complexparameter.h"
32 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);
47 area=new QScrollArea(frame);
48 QWidget *wid=new QWidget(area);
49 area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
50 area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
51 wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum));
52 //area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::MinimumExpanding));
54 vbox1->addWidget(area);
55 wid->setLayout(vbox2);
56 vbox2->addLayout(vbox);
57 vbox2->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding));
59 area->setWidgetResizable(true);
63 void EffectStackEdit::transferParamDesc(const QDomElement& d,int ,int){
66 QDomNodeList namenode = params.elementsByTagName("parameter");
70 QTextStream str(&outstr);
73 for (int i=0;i< namenode.count() ;i++){
74 kDebug() << "in form";
75 QDomNode pa=namenode.item(i);
76 QDomNode na=pa.firstChildElement("name");
77 QDomNamedNodeMap nodeAtts=pa.attributes();
78 QString type=nodeAtts.namedItem("type").nodeValue();
79 QString paramName=na.toElement().text();
80 QWidget * toFillin=new QWidget;
81 QString value=nodeAtts.namedItem("value").isNull()?
82 nodeAtts.namedItem("default").nodeValue():
83 nodeAtts.namedItem("value").nodeValue();
85 //TODO constant, list, bool, complex , color, geometry, position
86 if (type=="double" || type=="constant"){
87 createSliderItem(paramName,value.toInt(),nodeAtts.namedItem("min").nodeValue().toInt(),nodeAtts.namedItem("max").nodeValue().toInt() );
90 }else if (type=="list"){
92 Ui::Listval_UI *lsval=new Ui::Listval_UI;
93 lsval->setupUi(toFillin);
94 nodeAtts.namedItem("paramlist");
95 QStringList listitems=nodeAtts.namedItem("paramlist").nodeValue().split(",");
96 lsval->list->addItems(listitems);
97 lsval->list->setCurrentIndex(listitems.indexOf(value));;
98 connect (lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT (collectAllParameters()));
99 lsval->title->setTitle(na.toElement().text() );
100 valueItems[paramName]=lsval;
101 uiItems.append(lsval);
102 }else if (type=="bool"){
103 Ui::Boolval_UI *bval=new Ui::Boolval_UI;
104 bval->setupUi(toFillin);
105 bval->checkBox->setCheckState(value=="0" ? Qt::Unchecked : Qt::Checked);
107 connect (bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT (collectAllParameters()));
108 bval->title->setTitle(na.toElement().text() );
109 valueItems[paramName]=bval;
110 uiItems.append(bval);
111 }else if(type=="complex"){
112 QStringList names=nodeAtts.namedItem("name").nodeValue().split(";");
113 QStringList max=nodeAtts.namedItem("max").nodeValue().split(";");
114 QStringList min=nodeAtts.namedItem("min").nodeValue().split(";");
115 QStringList val=value.split(";");
116 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
117 if ( (names.size() == max.size() ) &&
118 (names.size()== min.size()) &&
119 (names.size()== val.size()) )
121 for (int i=0;i< names.size();i++){
122 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
125 ComplexParameter *pl=new ComplexParameter;
126 pl->setupParam(d,0,100);
135 items.append(toFillin);
136 vbox->addWidget(toFillin);
140 void EffectStackEdit::collectAllParameters(){
141 QDomNodeList namenode = params.elementsByTagName("parameter");
143 for (int i=0;i< namenode.count() ;i++){
144 QDomNode pa=namenode.item(i);
145 QDomNode na=pa.firstChildElement("name");
146 QString type=pa.attributes().namedItem("type").nodeValue();
148 if (type=="double" || type=="constant"){
149 QSlider* slider=((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider;
150 setValue=QString::number(slider->value());
153 KComboBox *box=((Ui::Listval_UI*)valueItems[na.toElement().text()])->list;
154 setValue=box->currentText();
157 QCheckBox *box=((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox;
158 setValue=box->checkState() == Qt::Checked ? "1" :"0" ;
160 if (!setValue.isEmpty()){
161 pa.attributes().namedItem("value").setNodeValue(setValue);
164 emit parameterChanged(params);
167 void EffectStackEdit::createSliderItem(const QString& name, int val ,int min, int max){
168 QWidget* toFillin=new QWidget;
169 Ui::Constval_UI *ctval=new Ui::Constval_UI;
170 ctval->setupUi(toFillin);
172 ctval->horizontalSlider->setMinimum(min);
173 ctval->horizontalSlider->setMaximum(max);
174 ctval->spinBox->setMinimum(min);
175 ctval->spinBox->setMaximum(max);
177 ctval->horizontalSlider->setValue(val);
178 ctval->title->setTitle(name);
179 valueItems[name]=ctval;
180 uiItems.append(ctval);
181 connect (ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT (collectAllParameters()));
182 items.append(toFillin);
183 vbox->addWidget(toFillin);
186 void EffectStackEdit::slotSliderMoved(int){
187 collectAllParameters();
190 void EffectStackEdit::clearAllItems(){
191 foreach (QWidget* w,items){
192 vbox->removeWidget(w);
195 foreach(void * p, uiItems){