]> git.sesse.net Git - kdenlive/blob - src/effectstackedit.cpp
ab4785190e25a04c3807304ae15364993bae3be5
[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 "ui_colorval_ui.h"
31 #include "complexparameter.h"
32
33 EffectStackEdit::EffectStackEdit(QFrame* frame,QWidget *parent): QObject(parent)
34 {
35         QScrollArea *area;
36         QVBoxLayout *vbox1=new QVBoxLayout(frame);
37         QVBoxLayout *vbox2=new QVBoxLayout(frame);
38         vbox=new QVBoxLayout(frame);
39         vbox1->setContentsMargins (0,0,0,0);
40         vbox1->setSpacing(0);
41         vbox2->setContentsMargins (0,0,0,0);
42         vbox2->setSpacing(0);
43         vbox->setContentsMargins (0,0,0,0);
44         vbox->setSpacing(0);
45         frame->setLayout(vbox1);
46         QFont widgetFont = frame->font();
47         widgetFont.setPointSize(widgetFont.pointSize() - 2);
48         frame->setFont(widgetFont);
49         
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));
56
57         vbox1->addWidget(area);
58         wid->setLayout(vbox2);
59         vbox2->addLayout(vbox);
60         vbox2->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding));
61         area->setWidget(wid);
62         area->setWidgetResizable(true);
63         wid->show();
64         
65 }
66 void EffectStackEdit::transferParamDesc(const QDomElement& d,int ,int){
67         kDebug() << "in";
68         params=d;
69         QDomNodeList namenode = params.elementsByTagName("parameter");
70         
71         clearAllItems();
72
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();
84                 
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() );
88                         delete toFillin;
89                         toFillin=NULL;
90                 }else if (type=="list"){
91                         
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);
106                         
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()) )
120                         {
121                                 for (int i=0;i< names.size();i++){
122                                         createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
123                                 };
124                         }*/
125                         ComplexParameter *pl=new ComplexParameter;
126                         connect (pl, SIGNAL ( parameterChanged()),this, SLOT( collectAllParameters ()) );
127                         pl->setupParam(d,0,100);
128                         vbox->addWidget(pl);
129                         valueItems[paramName+"complex"]=pl;
130                         items.append(pl);
131                 }else if (type=="color"){
132                         Ui::Colorval_UI *cval=new Ui::Colorval_UI;
133                         cval->setupUi(toFillin);
134                         bool ok;
135                         cval->kcolorbutton->setColor (value.toUInt(&ok,16));
136                         kDebug() << value.toUInt(&ok,16);
137                         
138                         connect (cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT (collectAllParameters()));
139                         cval->label->setText(na.toElement().text() );
140                         valueItems[paramName]=cval;
141                         uiItems.append(cval);
142                 }else{
143                         delete toFillin;
144                         toFillin=NULL;
145                 }
146
147                 if (toFillin){
148                         items.append(toFillin);
149                         vbox->addWidget(toFillin);
150                 }       
151         }
152 }
153 void EffectStackEdit::collectAllParameters(){
154         QDomElement oldparam = params.cloneNode().toElement();
155         QDomNodeList namenode = params.elementsByTagName("parameter");
156
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();
161                 QString setValue;
162                 if (type=="double" || type=="constant"){
163                         QSlider* slider=((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider;
164                         setValue=QString::number(slider->value());
165                 }else 
166                 if (type=="list"){
167                         KComboBox *box=((Ui::Listval_UI*)valueItems[na.toElement().text()])->list;
168                         setValue=box->currentText();
169                 }else 
170                 if (type=="bool"){
171                         QCheckBox *box=((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox;
172                         setValue=box->checkState() == Qt::Checked ? "1" :"0" ;
173                 }else
174                 if (type=="color"){
175                         KColorButton *color=((Ui::Colorval_UI*)valueItems[na.toElement().text()])->kcolorbutton;
176                         setValue.sprintf("0x%08x",color->color().rgba());
177                 }else
178                         if (type=="complex"){
179                                 ComplexParameter *complex=((ComplexParameter*)valueItems[na.toElement().text()+"complex"]);
180                                 namenode.item(i)=complex->getParamDesc();
181                         }
182                 if (!setValue.isEmpty()){
183                         pa.attributes().namedItem("value").setNodeValue(setValue);
184                 }
185         }
186         emit parameterChanged(oldparam, params);
187 }
188
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);
193         
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);
206 }
207
208 void EffectStackEdit::slotSliderMoved(int){
209         collectAllParameters();
210 }
211
212 void EffectStackEdit::clearAllItems(){
213         foreach (QWidget* w,items){
214                 vbox->removeWidget(w);
215                 delete w;
216         }
217         foreach(void * p, uiItems){
218                 delete p;
219         }
220         uiItems.clear();
221         items.clear();
222         valueItems.clear();
223 }