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);
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 QTextStream str(&outstr);
75 for (int i=0;i< namenode.count() ;i++){
76 kDebug() << "in form";
77 QDomNode pa=namenode.item(i);
78 QDomNode na=pa.firstChildElement("name");
79 QDomNamedNodeMap nodeAtts=pa.attributes();
80 QString type=nodeAtts.namedItem("type").nodeValue();
81 QString paramName=na.toElement().text();
82 QWidget * toFillin=new QWidget;
83 QString value=nodeAtts.namedItem("value").isNull()?
84 nodeAtts.namedItem("default").nodeValue():
85 nodeAtts.namedItem("value").nodeValue();
87 //TODO constant, list, bool, complex , color, geometry, position
88 if (type=="double" || type=="constant"){
89 createSliderItem(paramName,value.toInt(),nodeAtts.namedItem("min").nodeValue().toInt(),nodeAtts.namedItem("max").nodeValue().toInt() );
92 }else if (type=="list"){
94 Ui::Listval_UI *lsval=new Ui::Listval_UI;
95 lsval->setupUi(toFillin);
96 nodeAtts.namedItem("paramlist");
97 QStringList listitems=nodeAtts.namedItem("paramlist").nodeValue().split(",");
98 lsval->list->addItems(listitems);
99 lsval->list->setCurrentIndex(listitems.indexOf(value));;
100 connect (lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT (collectAllParameters()));
101 lsval->title->setTitle(na.toElement().text() );
102 valueItems[paramName]=lsval;
103 uiItems.append(lsval);
104 }else if (type=="bool"){
105 Ui::Boolval_UI *bval=new Ui::Boolval_UI;
106 bval->setupUi(toFillin);
107 bval->checkBox->setCheckState(value=="0" ? Qt::Unchecked : Qt::Checked);
109 connect (bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT (collectAllParameters()));
110 bval->checkBox->setText(na.toElement().text() );
111 valueItems[paramName]=bval;
112 uiItems.append(bval);
113 }else if(type=="complex"){
114 QStringList names=nodeAtts.namedItem("name").nodeValue().split(";");
115 QStringList max=nodeAtts.namedItem("max").nodeValue().split(";");
116 QStringList min=nodeAtts.namedItem("min").nodeValue().split(";");
117 QStringList val=value.split(";");
118 kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size() ;
119 if ( (names.size() == max.size() ) &&
120 (names.size()== min.size()) &&
121 (names.size()== val.size()) )
123 for (int i=0;i< names.size();i++){
124 createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
127 ComplexParameter *pl=new ComplexParameter;
128 pl->setupParam(d,0,100);
137 items.append(toFillin);
138 vbox->addWidget(toFillin);
142 void EffectStackEdit::collectAllParameters(){
143 QDomNodeList namenode = params.elementsByTagName("parameter");
145 for (int i=0;i< namenode.count() ;i++){
146 QDomNode pa=namenode.item(i);
147 QDomNode na=pa.firstChildElement("name");
148 QString type=pa.attributes().namedItem("type").nodeValue();
150 if (type=="double" || type=="constant"){
151 QSlider* slider=((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider;
152 setValue=QString::number(slider->value());
155 KComboBox *box=((Ui::Listval_UI*)valueItems[na.toElement().text()])->list;
156 setValue=box->currentText();
159 QCheckBox *box=((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox;
160 setValue=box->checkState() == Qt::Checked ? "1" :"0" ;
162 if (!setValue.isEmpty()){
163 pa.attributes().namedItem("value").setNodeValue(setValue);
166 emit parameterChanged(params);
169 void EffectStackEdit::createSliderItem(const QString& name, int val ,int min, int max){
170 QWidget* toFillin=new QWidget;
171 Ui::Constval_UI *ctval=new Ui::Constval_UI;
172 ctval->setupUi(toFillin);
174 ctval->horizontalSlider->setMinimum(min);
175 ctval->horizontalSlider->setMaximum(max);
176 ctval->spinBox->setMinimum(min);
177 ctval->spinBox->setMaximum(max);
178 ctval->horizontalSlider->setPageStep((int) (max - min)/10);
179 ctval->horizontalSlider->setValue(val);
180 ctval->label->setText(name);
181 valueItems[name]=ctval;
182 uiItems.append(ctval);
183 connect (ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT (collectAllParameters()));
184 items.append(toFillin);
185 vbox->addWidget(toFillin);
188 void EffectStackEdit::slotSliderMoved(int){
189 collectAllParameters();
192 void EffectStackEdit::clearAllItems(){
193 foreach (QWidget* w,items){
194 vbox->removeWidget(w);
197 foreach(void * p, uiItems){