]> git.sesse.net Git - kdenlive/blob - src/effectstackedit.cpp
more params can be set up
[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=NULL,*labelToFillIn=NULL;
57                 //TODO constant, list, bool, complex , color, geometry, position
58                 if (type=="double" || type=="constant"){
59                         toFillin=new QWidget;
60                         Ui::Constval_UI *ctval=new Ui::Constval_UI;
61                         ctval->setupUi(toFillin);
62                         
63                         ctval->horizontalSlider->setMinimum(nodeAtts.namedItem("min").nodeValue().toInt());
64                         ctval->horizontalSlider->setMaximum(nodeAtts.namedItem("max").nodeValue().toInt());
65                         ctval->spinBox->setMinimum(ctval->horizontalSlider->minimum());
66                         ctval->spinBox->setMaximum(ctval->horizontalSlider->maximum());
67                         if (nodeAtts.namedItem("value").isNull())
68                                 ctval->horizontalSlider->setValue(nodeAtts.namedItem("default").nodeValue().toInt());
69                         else
70                                 ctval->horizontalSlider->setValue(nodeAtts.namedItem("value").nodeValue().toInt());
71                         ctval->title->setTitle(na.toElement().text() );
72                         valueItems[na.toElement().text()]=ctval;
73                         connect (ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT (slotSliderMoved(int)));
74                 }
75                 if (type=="list"){
76                         toFillin=new QWidget;
77                         Ui::Listval_UI *lsval=new Ui::Listval_UI;
78                         lsval->setupUi(toFillin);
79                         nodeAtts.namedItem("paramlist");
80                         
81                         lsval->list->addItems(nodeAtts.namedItem("paramlist").nodeValue().split(","));
82                         /*if (nodeAtts.namedItem("value").isNull())
83                                 lsval->list->setCurrentText(nodeAtts.namedItem("default").nodeValue());
84                         else
85                                 lsval->list->setCurrentText(nodeAtts.namedItem("value").nodeValue());
86                         */
87                         connect (lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT (slotSliderMoved(int)));
88                         lsval->title->setTitle(na.toElement().text() );
89                         valueItems[na.toElement().text()]=lsval;
90                 }
91                 if (type=="bool"){
92                         toFillin=new QWidget;
93                         Ui::Boolval_UI *bval=new Ui::Boolval_UI;
94                         bval->setupUi(toFillin);
95                         if (nodeAtts.namedItem("value").isNull())
96                                 bval->checkBox->setCheckState(nodeAtts.namedItem("default").nodeValue()=="0" ? Qt::Unchecked : Qt::Checked);
97                         else
98                                 bval->checkBox->setCheckState(nodeAtts.namedItem("value").nodeValue()=="0" ? Qt::Unchecked : Qt::Checked);              
99                         
100                         connect (bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT (slotSliderMoved(int)));
101                         bval->title->setTitle(na.toElement().text() );
102                         valueItems[na.toElement().text()]=bval;
103                 }
104
105                 if (toFillin){
106                         items.append(toFillin);
107                         vbox->addWidget(toFillin);
108                 }       
109         }
110 }
111 void EffectStackEdit::collectAllParameters(){
112         QDomNodeList namenode = params.elementsByTagName("parameter");
113
114         for (int i=0;i< namenode.count() ;i++){
115                 QDomNode pa=namenode.item(i);
116                 QDomNode na=pa.firstChildElement("name");
117                 QString type=pa.attributes().namedItem("type").nodeValue();
118                 if (type=="double" || type=="constant"){
119                         QSlider* slider=((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider;
120                         pa.attributes().namedItem("value").setNodeValue(QString::number(slider->value()));
121                 }
122                 if (type=="list"){
123                         KComboBox *box=((Ui::Listval_UI*)valueItems[na.toElement().text()])->list;
124                         pa.attributes().namedItem("value").setNodeValue(box->currentText());
125                 }
126                 if (type=="bool"){
127                         QCheckBox *box=((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox;
128                         pa.attributes().namedItem("value").setNodeValue(box->checkState() == Qt::Checked ? "1" :"0" );
129                 }
130         }
131         emit parameterChanged(params);
132 }
133 void EffectStackEdit::slotSliderMoved(int){
134         collectAllParameters();
135 }
136
137 void EffectStackEdit::clearAllItems(){
138         foreach (QWidget* w,items){
139                 kDebug() << "delete" << w;
140                 vbox->removeWidget(w);
141                 delete w;
142         }
143         items.clear();
144         valueItems.clear();
145 }