]> git.sesse.net Git - kdenlive/blob - src/effectstackedit.cpp
use and save order of filters
[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 <QCheckBox>
25 #include "ui_constval_ui.h"
26 #include "ui_listval_ui.h"
27 #include "ui_boolval_ui.h"
28
29 EffectStackEdit::EffectStackEdit(QGroupBox* gbox,QWidget *parent): QWidget(parent)
30 {
31         
32         vbox=new QVBoxLayout;
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);
38         
39 }
40 void EffectStackEdit::transferParamDesc(const QDomElement& d,int ,int){
41         kDebug() << "in";
42         params=d;
43         QDomNodeList namenode = params.elementsByTagName("parameter");
44         
45         clearAllItems();
46                 QString outstr;
47                 QTextStream str(&outstr);
48                 d.save(str,2);
49                 kDebug() << 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();
60                 
61                 //TODO constant, list, bool, complex , color, geometry, position
62                 if (type=="double" || type=="constant"){
63                         
64                         Ui::Constval_UI *ctval=new Ui::Constval_UI;
65                         ctval->setupUi(toFillin);
66                         
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());
71                         
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"){
78                         
79                         Ui::Listval_UI *lsval=new Ui::Listval_UI;
80                         lsval->setupUi(toFillin);
81                         nodeAtts.namedItem("paramlist");
82                         
83                         lsval->list->addItems(nodeAtts.namedItem("paramlist").nodeValue().split(","));
84                         /*if (nodeAtts.namedItem("value").isNull())
85                                 lsval->list->setCurrentText(nodeAtts.namedItem("default").nodeValue());
86                         else
87                                 lsval->list->setCurrentText(nodeAtts.namedItem("value").nodeValue());
88                         */
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);
97                         
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);
102                 }else{
103                         delete toFillin;
104                         toFillin=NULL;
105                 }
106
107                 if (toFillin){
108                         items.append(toFillin);
109                         vbox->addWidget(toFillin);
110                 }       
111         }
112 }
113 void EffectStackEdit::collectAllParameters(){
114         QDomNodeList namenode = params.elementsByTagName("parameter");
115
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();
120                 QString setValue;
121                 if (type=="double" || type=="constant"){
122                         QSlider* slider=((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider;
123                         setValue=QString::number(slider->value());
124                 }
125                 if (type=="list"){
126                         KComboBox *box=((Ui::Listval_UI*)valueItems[na.toElement().text()])->list;
127                         setValue=box->currentText();
128                 }
129                 if (type=="bool"){
130                         QCheckBox *box=((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox;
131                         setValue=box->checkState() == Qt::Checked ? "1" :"0" ;
132                 }
133                 if (!setValue.isEmpty()){
134                         pa.attributes().namedItem("value").setNodeValue(setValue);
135                 }
136         }
137         emit parameterChanged(params);
138 }
139 void EffectStackEdit::slotSliderMoved(int){
140         collectAllParameters();
141 }
142
143 void EffectStackEdit::clearAllItems(){
144         foreach (QWidget* w,items){
145                 vbox->removeWidget(w);
146                 delete w;
147         }
148         foreach(void * p, uiItems){
149                 delete p;
150         }
151         uiItems.clear();
152         items.clear();
153         valueItems.clear();
154 }