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