]> git.sesse.net Git - kdenlive/blob - src/effectstackedit.cpp
9c782a0c5c7c55f76b0713333d34c5d1dcec5bad
[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                 QString outstr;
73                 QTextStream str(&outstr);
74                 d.save(str,2);
75                 kDebug() << outstr;
76         for (int i=0;i< namenode.count() ;i++){
77                 kDebug() << "in form";
78                 QDomNode pa=namenode.item(i);
79                 QDomNode na=pa.firstChildElement("name");
80                 QDomNamedNodeMap nodeAtts=pa.attributes();
81                 QString type=nodeAtts.namedItem("type").nodeValue();
82                 QString paramName=na.toElement().text();
83                 QWidget * toFillin=new QWidget;
84                 QString value=nodeAtts.namedItem("value").isNull()?
85                         nodeAtts.namedItem("default").nodeValue():
86                         nodeAtts.namedItem("value").nodeValue();
87                 
88                 //TODO constant, list, bool, complex , color, geometry, position
89                 if (type=="double" || type=="constant"){
90                         createSliderItem(paramName,value.toInt(),nodeAtts.namedItem("min").nodeValue().toInt(),nodeAtts.namedItem("max").nodeValue().toInt() );
91                         delete toFillin;
92                         toFillin=NULL;
93                 }else if (type=="list"){
94                         
95                         Ui::Listval_UI *lsval=new Ui::Listval_UI;
96                         lsval->setupUi(toFillin);
97                         nodeAtts.namedItem("paramlist");
98                         QStringList listitems=nodeAtts.namedItem("paramlist").nodeValue().split(",");
99                         lsval->list->addItems(listitems);
100                         lsval->list->setCurrentIndex(listitems.indexOf(value));;
101                         connect (lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT (collectAllParameters()));
102                         lsval->title->setTitle(na.toElement().text() );
103                         valueItems[paramName]=lsval;
104                         uiItems.append(lsval);
105                 }else if (type=="bool"){
106                         Ui::Boolval_UI *bval=new Ui::Boolval_UI;
107                         bval->setupUi(toFillin);
108                         bval->checkBox->setCheckState(value=="0" ? Qt::Unchecked : Qt::Checked);
109                         
110                         connect (bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT (collectAllParameters()));
111                         bval->checkBox->setText(na.toElement().text() );
112                         valueItems[paramName]=bval;
113                         uiItems.append(bval);
114                 }else if(type=="complex"){
115                         QStringList names=nodeAtts.namedItem("name").nodeValue().split(";");
116                         QStringList max=nodeAtts.namedItem("max").nodeValue().split(";");
117                         QStringList min=nodeAtts.namedItem("min").nodeValue().split(";");
118                         QStringList val=value.split(";");
119                         kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size()  ;
120                         if ( (names.size() == max.size() ) && 
121                              (names.size()== min.size()) && 
122                              (names.size()== val.size()) )
123                         {
124                                 for (int i=0;i< names.size();i++){
125                                         createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
126                                 };
127                         }
128                         ComplexParameter *pl=new ComplexParameter;
129                         connect (pl, SIGNAL ( parameterChanged()),this, SLOT( collectAllParameters ()) );
130                         pl->setupParam(d,0,100);
131                         vbox->addWidget(pl);
132                         valueItems[paramName+"complex"]=pl;
133                         items.append(pl);
134                 }else if (type=="color"){
135                         Ui::Colorval_UI *cval=new Ui::Colorval_UI;
136                         cval->setupUi(toFillin);
137                         bool ok;
138                         cval->kcolorbutton->setColor (value.toUInt(&ok,16));
139                         kDebug() << value.toUInt(&ok,16);
140                         
141                         connect (cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT (collectAllParameters()));
142                         cval->label->setText(na.toElement().text() );
143                         valueItems[paramName]=cval;
144                         uiItems.append(cval);
145                 }else{
146                         delete toFillin;
147                         toFillin=NULL;
148                 }
149
150                 if (toFillin){
151                         items.append(toFillin);
152                         vbox->addWidget(toFillin);
153                 }       
154         }
155 }
156 void EffectStackEdit::collectAllParameters(){
157         
158         QDomNodeList namenode = params.elementsByTagName("parameter");
159
160         for (int i=0;i< namenode.count() ;i++){
161                 QDomNode pa=namenode.item(i);
162                 QDomNode na=pa.firstChildElement("name");
163                 QString type=pa.attributes().namedItem("type").nodeValue();
164                 QString setValue;
165                 if (type=="double" || type=="constant"){
166                         QSlider* slider=((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider;
167                         setValue=QString::number(slider->value());
168                 }else 
169                 if (type=="list"){
170                         KComboBox *box=((Ui::Listval_UI*)valueItems[na.toElement().text()])->list;
171                         setValue=box->currentText();
172                 }else 
173                 if (type=="bool"){
174                         QCheckBox *box=((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox;
175                         setValue=box->checkState() == Qt::Checked ? "1" :"0" ;
176                 }else
177                 if (type=="color"){
178                         KColorButton *color=((Ui::Colorval_UI*)valueItems[na.toElement().text()])->kcolorbutton;
179                         setValue.sprintf("0x%08x",color->color().rgba());
180                 }else
181                         if (type=="complex"){
182                                 ComplexParameter *complex=((ComplexParameter*)valueItems[na.toElement().text()+"complex"]);
183                                 namenode.item(i)=complex->getParamDesc();
184                         }
185                 if (!setValue.isEmpty()){
186                         pa.attributes().namedItem("value").setNodeValue(setValue);
187                 }
188         }
189         emit parameterChanged(params);
190 }
191
192 void EffectStackEdit::createSliderItem(const QString& name, int val ,int min, int max){
193         QWidget* toFillin=new QWidget;
194         Ui::Constval_UI *ctval=new Ui::Constval_UI;
195         ctval->setupUi(toFillin);
196         
197         ctval->horizontalSlider->setMinimum(min);
198         ctval->horizontalSlider->setMaximum(max);
199         ctval->spinBox->setMinimum(min);
200         ctval->spinBox->setMaximum(max);
201         ctval->horizontalSlider->setPageStep((int) (max - min)/10);     
202         ctval->horizontalSlider->setValue(val);
203         ctval->label->setText(name);
204         valueItems[name]=ctval;
205         uiItems.append(ctval);
206         connect (ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT (collectAllParameters()));
207         items.append(toFillin);
208         vbox->addWidget(toFillin);
209 }
210
211 void EffectStackEdit::slotSliderMoved(int){
212         collectAllParameters();
213 }
214
215 void EffectStackEdit::clearAllItems(){
216         foreach (QWidget* w,items){
217                 vbox->removeWidget(w);
218                 delete w;
219         }
220         foreach(void * p, uiItems){
221                 delete p;
222         }
223         uiItems.clear();
224         items.clear();
225         valueItems.clear();
226 }