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)
36 QVBoxLayout *vbox1=new QVBoxLayout(frame);
37 QVBoxLayout *vbox2=new QVBoxLayout(frame);
38 vbox=new QVBoxLayout(frame);
39 vbox1->setContentsMargins (0,0,0,0);
41 vbox2->setContentsMargins (0,0,0,0);
43 vbox->setContentsMargins (0,0,0,0);
45 frame->setLayout(vbox1);
46 QFont widgetFont = frame->font();
47 widgetFont.setPointSize(widgetFont.pointSize() - 2);
48 frame->setFont(widgetFont);
50 area=new QScrollArea(frame);
51 QWidget *wid=new QWidget(area);
52 area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
53 area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
54 wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum));
55 //area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::MinimumExpanding));
57 vbox1->addWidget(area);
58 wid->setLayout(vbox2);
59 vbox2->addLayout(vbox);
60 vbox2->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding));
62 area->setWidgetResizable(true);
66 void EffectStackEdit::transferParamDesc(const QDomElement& d,int ,int){
69 QDomNodeList namenode = params.elementsByTagName("parameter");
73 QTextStream str(&outstr);
76 for (int i=0;i< namenode.count() ;i++){
77 kDebug() << "in form";
78 QDomNode pa=namenode.item(i);
79 QDomNode na=pa.firstChildElement("name");
80 QDomNamedNodeMap nodeAtts=pa.attributes();
81 QString type=nodeAtts.namedItem("type").nodeValue();
82 QString paramName=na.toElement().text();
83 QWidget * toFillin=new QWidget;
84 QString value=nodeAtts.namedItem("value").isNull()?
85 nodeAtts.namedItem("default").nodeValue():
86 nodeAtts.namedItem("value").nodeValue();
88 //TODO constant, list, bool, complex , color, geometry, position
89 if (type=="double" || type=="constant"){
90 createSliderItem(paramName,value.toInt(),nodeAtts.namedItem("min").nodeValue().toInt(),nodeAtts.namedItem("max").nodeValue().toInt() );
93 }else if (type=="list"){
95 Ui::Listval_UI *lsval=new Ui::Listval_UI;
96 lsval->setupUi(toFillin);
97 nodeAtts.namedItem("paramlist");
98 QStringList listitems=nodeAtts.namedItem("paramlist").nodeValue().split(",");
99 lsval->list->addItems(listitems);
100 lsval->list->setCurrentIndex(listitems.indexOf(value));;
101 connect (lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT (collectAllParameters()));
102 lsval->title->setTitle(na.toElement().text() );
103 valueItems[paramName]=lsval;
104 uiItems.append(lsval);
105 }else if (type=="bool"){
106 Ui::Boolval_UI *bval=new Ui::Boolval_UI;
107 bval->setupUi(toFillin);
108 bval->checkBox->setCheckState(value=="0" ? Qt::Unchecked : Qt::Checked);
110 connect (bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT (collectAllParameters()));
111 bval->checkBox->setText(na.toElement().text() );
112 valueItems[paramName]=bval;
113 uiItems.append(bval);
114 }else if(type=="complex"){
115 QStringList names=nodeAtts.namedItem("name").nodeValue().split(";");
116 QStringList max=nodeAtts.namedItem("max").nodeValue().split(";");
117 QStringList min=nodeAtts.namedItem("min").nodeValue().split(";");
118 QStringList val=value.split(";");
119 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
120 if ( (names.size() == max.size() ) &&
121 (names.size()== min.size()) &&
122 (names.size()== val.size()) )
124 for (int i=0;i< names.size();i++){
125 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
128 ComplexParameter *pl=new ComplexParameter;
129 connect (pl, SIGNAL ( parameterChanged()),this, SLOT( collectAllParameters ()) );
130 pl->setupParam(d,0,100);
132 valueItems[paramName+"complex"]=pl;
134 }else if (type=="color"){
135 Ui::Colorval_UI *cval=new Ui::Colorval_UI;
136 cval->setupUi(toFillin);
138 cval->kcolorbutton->setColor (value.toUInt(&ok,16));
139 kDebug() << value.toUInt(&ok,16);
141 connect (cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT (collectAllParameters()));
142 cval->label->setText(na.toElement().text() );
143 valueItems[paramName]=cval;
144 uiItems.append(cval);
151 items.append(toFillin);
152 vbox->addWidget(toFillin);
156 void EffectStackEdit::collectAllParameters(){
158 QDomNodeList namenode = params.elementsByTagName("parameter");
160 for (int i=0;i< namenode.count() ;i++){
161 QDomNode pa=namenode.item(i);
162 QDomNode na=pa.firstChildElement("name");
163 QString type=pa.attributes().namedItem("type").nodeValue();
165 if (type=="double" || type=="constant"){
166 QSlider* slider=((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider;
167 setValue=QString::number(slider->value());
170 KComboBox *box=((Ui::Listval_UI*)valueItems[na.toElement().text()])->list;
171 setValue=box->currentText();
174 QCheckBox *box=((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox;
175 setValue=box->checkState() == Qt::Checked ? "1" :"0" ;
178 KColorButton *color=((Ui::Colorval_UI*)valueItems[na.toElement().text()])->kcolorbutton;
179 setValue.sprintf("0x%08x",color->color().rgba());
181 if (type=="complex"){
182 ComplexParameter *complex=((ComplexParameter*)valueItems[na.toElement().text()+"complex"]);
183 namenode.item(i)=complex->getParamDesc();
185 if (!setValue.isEmpty()){
186 pa.attributes().namedItem("value").setNodeValue(setValue);
189 emit parameterChanged(params);
192 void EffectStackEdit::createSliderItem(const QString& name, int val ,int min, int max){
193 QWidget* toFillin=new QWidget;
194 Ui::Constval_UI *ctval=new Ui::Constval_UI;
195 ctval->setupUi(toFillin);
197 ctval->horizontalSlider->setMinimum(min);
198 ctval->horizontalSlider->setMaximum(max);
199 ctval->spinBox->setMinimum(min);
200 ctval->spinBox->setMaximum(max);
201 ctval->horizontalSlider->setPageStep((int) (max - min)/10);
202 ctval->horizontalSlider->setValue(val);
203 ctval->label->setText(name);
204 valueItems[name]=ctval;
205 uiItems.append(ctval);
206 connect (ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT (collectAllParameters()));
207 items.append(toFillin);
208 vbox->addWidget(toFillin);
211 void EffectStackEdit::slotSliderMoved(int){
212 collectAllParameters();
215 void EffectStackEdit::clearAllItems(){
216 foreach (QWidget* w,items){
217 vbox->removeWidget(w);
220 foreach(void * p, uiItems){