]> git.sesse.net Git - kdenlive/blob - src/effectstackedit.cpp
remove frame from effects parameter
[kdenlive] / src / effectstackedit.cpp
1 /***************************************************************************
2                           effecstackview.cpp  -  description
3                              -------------------
4     begin                : Feb 15 2008
5     copyright            : (C) 2008 by Marco Gittler
6     email                : g.marco@freenet.de
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
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.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #include <KDebug>
19 #include <KLocale>
20 #include "effectstackedit.h"
21 #include <QVBoxLayout>
22 #include <QSlider>
23 #include <QLabel>
24 #include <QPushButton>
25 #include <QCheckBox>
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"
31
32 EffectStackEdit::EffectStackEdit(QFrame* frame,QWidget *parent): QObject(parent)
33 {
34         QScrollArea *area;
35         QVBoxLayout *vbox1=new QVBoxLayout(frame);
36         QVBoxLayout *vbox2=new QVBoxLayout(frame);
37         vbox=new QVBoxLayout(frame);
38         vbox1->setContentsMargins (0,0,0,0);
39         vbox1->setSpacing(0);
40         vbox2->setContentsMargins (0,0,0,0);
41         vbox2->setSpacing(0);
42         vbox->setContentsMargins (0,0,0,0);
43         vbox->setSpacing(0);
44         frame->setLayout(vbox1);
45         QFont widgetFont = frame->font();
46         widgetFont.setPointSize(widgetFont.pointSize() - 2);
47         frame->setFont(widgetFont);
48         
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));
55
56         vbox1->addWidget(area);
57         wid->setLayout(vbox2);
58         vbox2->addLayout(vbox);
59         vbox2->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding));
60         area->setWidget(wid);
61         area->setWidgetResizable(true);
62         wid->show();
63         
64 }
65 void EffectStackEdit::transferParamDesc(const QDomElement& d,int ,int){
66         kDebug() << "in";
67         params=d;
68         QDomNodeList namenode = params.elementsByTagName("parameter");
69         
70         clearAllItems();
71                 QString outstr;
72                 QTextStream str(&outstr);
73                 d.save(str,2);
74                 kDebug() << 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();
86                 
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() );
90                         delete toFillin;
91                         toFillin=NULL;
92                 }else if (type=="list"){
93                         
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);
108                         
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()) )
122                         {
123                                 for (int i=0;i< names.size();i++){
124                                         createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
125                                 };
126                         }
127                         ComplexParameter *pl=new ComplexParameter;
128                         pl->setupParam(d,0,100);
129                         vbox->addWidget(pl);
130                         items.append(pl);
131                 }else{
132                         delete toFillin;
133                         toFillin=NULL;
134                 }
135
136                 if (toFillin){
137                         items.append(toFillin);
138                         vbox->addWidget(toFillin);
139                 }       
140         }
141 }
142 void EffectStackEdit::collectAllParameters(){
143         QDomNodeList namenode = params.elementsByTagName("parameter");
144
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();
149                 QString setValue;
150                 if (type=="double" || type=="constant"){
151                         QSlider* slider=((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider;
152                         setValue=QString::number(slider->value());
153                 }
154                 if (type=="list"){
155                         KComboBox *box=((Ui::Listval_UI*)valueItems[na.toElement().text()])->list;
156                         setValue=box->currentText();
157                 }
158                 if (type=="bool"){
159                         QCheckBox *box=((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox;
160                         setValue=box->checkState() == Qt::Checked ? "1" :"0" ;
161                 }
162                 if (!setValue.isEmpty()){
163                         pa.attributes().namedItem("value").setNodeValue(setValue);
164                 }
165         }
166         emit parameterChanged(params);
167 }
168
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);
173         
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);
186 }
187
188 void EffectStackEdit::slotSliderMoved(int){
189         collectAllParameters();
190 }
191
192 void EffectStackEdit::clearAllItems(){
193         foreach (QWidget* w,items){
194                 vbox->removeWidget(w);
195                 delete w;
196         }
197         foreach(void * p, uiItems){
198                 delete p;
199         }
200         uiItems.clear();
201         items.clear();
202         valueItems.clear();
203 }