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>
25 #include "ui_constval_ui.h"
26 #include "ui_listval_ui.h"
27 #include "ui_boolval_ui.h"
29 EffectStackEdit::EffectStackEdit(QGroupBox* gbox,QWidget *parent): QObject(parent)
33 gbox->setSizePolicy(QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum));
34 QVBoxLayout *tmpvbox=new QVBoxLayout;
35 tmpvbox->addLayout(vbox);
36 tmpvbox->addItem(new QSpacerItem(0,0,QSizePolicy::Expanding,QSizePolicy::Expanding));
37 gbox->setLayout(tmpvbox);
40 void EffectStackEdit::transferParamDesc(const QDomElement& d,int ,int){
43 QDomNodeList namenode = params.elementsByTagName("parameter");
47 QTextStream str(&outstr);
50 for (int i=0;i< namenode.count() ;i++){
51 kDebug() << "in form";
52 QDomNode pa=namenode.item(i);
53 QDomNode na=pa.firstChildElement("name");
54 QDomNamedNodeMap nodeAtts=pa.attributes();
55 QString type=nodeAtts.namedItem("type").nodeValue();
56 QWidget * toFillin=new QWidget;
57 QString value=nodeAtts.namedItem("value").isNull()?
58 nodeAtts.namedItem("default").nodeValue():
59 nodeAtts.namedItem("value").nodeValue();
61 //TODO constant, list, bool, complex , color, geometry, position
62 if (type=="double" || type=="constant"){
64 Ui::Constval_UI *ctval=new Ui::Constval_UI;
65 ctval->setupUi(toFillin);
67 ctval->horizontalSlider->setMinimum(nodeAtts.namedItem("min").nodeValue().toInt());
68 ctval->horizontalSlider->setMaximum(nodeAtts.namedItem("max").nodeValue().toInt());
69 ctval->spinBox->setMinimum(ctval->horizontalSlider->minimum());
70 ctval->spinBox->setMaximum(ctval->horizontalSlider->maximum());
72 ctval->horizontalSlider->setValue(value.toInt());
73 ctval->title->setTitle(na.toElement().text() );
74 valueItems[na.toElement().text()]=ctval;
75 uiItems.append(ctval);
76 connect (ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT (collectAllParameters()));
77 }else if (type=="list"){
79 Ui::Listval_UI *lsval=new Ui::Listval_UI;
80 lsval->setupUi(toFillin);
81 nodeAtts.namedItem("paramlist");
83 lsval->list->addItems(nodeAtts.namedItem("paramlist").nodeValue().split(","));
84 /*if (nodeAtts.namedItem("value").isNull())
85 lsval->list->setCurrentText(nodeAtts.namedItem("default").nodeValue());
87 lsval->list->setCurrentText(nodeAtts.namedItem("value").nodeValue());
89 connect (lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT (collectAllParameters()));
90 lsval->title->setTitle(na.toElement().text() );
91 valueItems[na.toElement().text()]=lsval;
92 uiItems.append(lsval);
93 }else if (type=="bool"){
94 Ui::Boolval_UI *bval=new Ui::Boolval_UI;
95 bval->setupUi(toFillin);
96 bval->checkBox->setCheckState(value=="0" ? Qt::Unchecked : Qt::Checked);
98 connect (bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT (collectAllParameters()));
99 bval->title->setTitle(na.toElement().text() );
100 valueItems[na.toElement().text()]=bval;
101 uiItems.append(bval);
108 items.append(toFillin);
109 vbox->addWidget(toFillin);
113 void EffectStackEdit::collectAllParameters(){
114 QDomNodeList namenode = params.elementsByTagName("parameter");
116 for (int i=0;i< namenode.count() ;i++){
117 QDomNode pa=namenode.item(i);
118 QDomNode na=pa.firstChildElement("name");
119 QString type=pa.attributes().namedItem("type").nodeValue();
121 if (type=="double" || type=="constant"){
122 QSlider* slider=((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider;
123 setValue=QString::number(slider->value());
126 KComboBox *box=((Ui::Listval_UI*)valueItems[na.toElement().text()])->list;
127 setValue=box->currentText();
130 QCheckBox *box=((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox;
131 setValue=box->checkState() == Qt::Checked ? "1" :"0" ;
133 if (!setValue.isEmpty()){
134 pa.attributes().namedItem("value").setNodeValue(setValue);
137 emit parameterChanged(params);
139 void EffectStackEdit::slotSliderMoved(int){
140 collectAllParameters();
143 void EffectStackEdit::clearAllItems(){
144 foreach (QWidget* w,items){
145 vbox->removeWidget(w);
148 foreach(void * p, uiItems){