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 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->checkBox->setText(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 connect (pl, SIGNAL ( parameterChanged()),this, SLOT( collectAllParameters ()) );
127 pl->setupParam(d,0,100);
129 valueItems[paramName+"complex"]=pl;
131 }else if (type=="color"){
132 Ui::Colorval_UI *cval=new Ui::Colorval_UI;
133 cval->setupUi(toFillin);
135 cval->kcolorbutton->setColor (value.toUInt(&ok,16));
136 kDebug() << value.toUInt(&ok,16);
138 connect (cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT (collectAllParameters()));
139 cval->label->setText(na.toElement().text() );
140 valueItems[paramName]=cval;
141 uiItems.append(cval);
148 items.append(toFillin);
149 vbox->addWidget(toFillin);
153 void EffectStackEdit::collectAllParameters(){
154 QDomElement oldparam = params.cloneNode().toElement();
155 QDomNodeList namenode = params.elementsByTagName("parameter");
157 for (int i=0;i< namenode.count() ;i++){
158 QDomNode pa=namenode.item(i);
159 QDomNode na=pa.firstChildElement("name");
160 QString type=pa.attributes().namedItem("type").nodeValue();
162 if (type=="double" || type=="constant"){
163 QSlider* slider=((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider;
164 setValue=QString::number(slider->value());
167 KComboBox *box=((Ui::Listval_UI*)valueItems[na.toElement().text()])->list;
168 setValue=box->currentText();
171 QCheckBox *box=((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox;
172 setValue=box->checkState() == Qt::Checked ? "1" :"0" ;
175 KColorButton *color=((Ui::Colorval_UI*)valueItems[na.toElement().text()])->kcolorbutton;
176 setValue.sprintf("0x%08x",color->color().rgba());
178 if (type=="complex"){
179 ComplexParameter *complex=((ComplexParameter*)valueItems[na.toElement().text()+"complex"]);
180 namenode.item(i)=complex->getParamDesc();
182 if (!setValue.isEmpty()){
183 pa.attributes().namedItem("value").setNodeValue(setValue);
186 emit parameterChanged(oldparam, params);
189 void EffectStackEdit::createSliderItem(const QString& name, int val ,int min, int max){
190 QWidget* toFillin=new QWidget;
191 Ui::Constval_UI *ctval=new Ui::Constval_UI;
192 ctval->setupUi(toFillin);
194 ctval->horizontalSlider->setMinimum(min);
195 ctval->horizontalSlider->setMaximum(max);
196 ctval->spinBox->setMinimum(min);
197 ctval->spinBox->setMaximum(max);
198 ctval->horizontalSlider->setPageStep((int) (max - min)/10);
199 ctval->horizontalSlider->setValue(val);
200 ctval->label->setText(name);
201 valueItems[name]=ctval;
202 uiItems.append(ctval);
203 connect (ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT (collectAllParameters()));
204 items.append(toFillin);
205 vbox->addWidget(toFillin);
208 void EffectStackEdit::slotSliderMoved(int){
209 collectAllParameters();
212 void EffectStackEdit::clearAllItems(){
213 foreach (QWidget* w,items){
214 vbox->removeWidget(w);
217 foreach(void * p, uiItems){