]> git.sesse.net Git - kdenlive/blob - src/effectstackedit.cpp
transitions movable
[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 static QMap<QString, QIcon> iconCache;
34
35 EffectStackEdit::EffectStackEdit(QFrame* frame, QWidget *parent): QObject(parent) {
36     QScrollArea *area;
37     QVBoxLayout *vbox1 = new QVBoxLayout(frame);
38     QVBoxLayout *vbox2 = new QVBoxLayout(frame);
39     vbox = new QVBoxLayout(frame);
40     vbox1->setContentsMargins(0, 0, 0, 0);
41     vbox1->setSpacing(0);
42     vbox2->setContentsMargins(0, 0, 0, 0);
43     vbox2->setSpacing(0);
44     vbox->setContentsMargins(0, 0, 0, 0);
45     vbox->setSpacing(0);
46     frame->setLayout(vbox1);
47     QFont widgetFont = frame->font();
48     widgetFont.setPointSize(widgetFont.pointSize() - 2);
49     frame->setFont(widgetFont);
50
51     area = new QScrollArea(frame);
52     QWidget *wid = new QWidget(area);
53     area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
54     area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
55     wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
56     //area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::MinimumExpanding));
57
58     vbox1->addWidget(area);
59     wid->setLayout(vbox2);
60     vbox2->addLayout(vbox);
61     vbox2->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding));
62     area->setWidget(wid);
63     area->setWidgetResizable(true);
64     wid->show();
65
66 }
67 void EffectStackEdit::transferParamDesc(const QDomElement& d, int , int) {
68     kDebug() << "in";
69     params = d;
70     QDomNodeList namenode = params.elementsByTagName("parameter");
71
72     clearAllItems();
73
74     for (int i = 0;i < namenode.count() ;i++) {
75         kDebug() << "in form";
76         QDomNode pa = namenode.item(i);
77         QDomNode na = pa.firstChildElement("name");
78         QDomNamedNodeMap nodeAtts = pa.attributes();
79         QString type = nodeAtts.namedItem("type").nodeValue();
80         QString paramName = na.toElement().text();
81         QWidget * toFillin = new QWidget;
82         QString value = nodeAtts.namedItem("value").isNull() ?
83                         nodeAtts.namedItem("default").nodeValue() :
84                         nodeAtts.namedItem("value").nodeValue();
85
86         //TODO constant, list, bool, complex , color, geometry, position
87         if (type == "double" || type == "constant") {
88             createSliderItem(paramName, value.toInt(), nodeAtts.namedItem("min").nodeValue().toInt(), nodeAtts.namedItem("max").nodeValue().toInt());
89             delete toFillin;
90             toFillin = NULL;
91         } else if (type == "list") {
92
93             Ui::Listval_UI *lsval = new Ui::Listval_UI;
94             lsval->setupUi(toFillin);
95             nodeAtts.namedItem("paramlist");
96             QStringList listitems = nodeAtts.namedItem("paramlist").nodeValue().split(",");
97             lsval->list->addItems(listitems);
98             lsval->list->setCurrentIndex(listitems.indexOf(value));
99             for (int i = 0;i < lsval->list->count();i++) {
100                 QString entry = lsval->list->itemText(i);
101                 if (!entry.isEmpty() && (entry.endsWith(".png") || entry.endsWith(".pgm"))) {
102                     if (!iconCache.contains(entry)) {
103                         QPixmap pix(entry);
104                         iconCache[entry] = pix.scaled(30, 30);
105                     }
106                     lsval->list->setIconSize(QSize(30, 30));
107                     lsval->list->setItemIcon(i, iconCache[entry]);
108                 }
109             }
110             connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters()));
111             lsval->title->setTitle(na.toElement().text());
112             valueItems[paramName] = lsval;
113             uiItems.append(lsval);
114         } else if (type == "bool") {
115             Ui::Boolval_UI *bval = new Ui::Boolval_UI;
116             bval->setupUi(toFillin);
117             bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked);
118
119             connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters()));
120             bval->checkBox->setText(na.toElement().text());
121             valueItems[paramName] = bval;
122             uiItems.append(bval);
123         } else if (type == "complex") {
124             /*QStringList names=nodeAtts.namedItem("name").nodeValue().split(";");
125             QStringList max=nodeAtts.namedItem("max").nodeValue().split(";");
126             QStringList min=nodeAtts.namedItem("min").nodeValue().split(";");
127             QStringList val=value.split(";");
128             kDebug() << "in complex"<<names.size() << " " << max.size() << " " << min.size() << " " << val.size()  ;
129             if ( (names.size() == max.size() ) &&
130                  (names.size()== min.size()) &&
131                  (names.size()== val.size()) )
132             {
133              for (int i=0;i< names.size();i++){
134               createSliderItem(names[i],val[i].toInt(),min[i].toInt(),max[i].toInt());
135              };
136             }*/
137             ComplexParameter *pl = new ComplexParameter;
138             connect(pl, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters()));
139             pl->setupParam(d, 0, 100);
140             vbox->addWidget(pl);
141             valueItems[paramName+"complex"] = pl;
142             items.append(pl);
143         } else if (type == "color") {
144             Ui::Colorval_UI *cval = new Ui::Colorval_UI;
145             cval->setupUi(toFillin);
146             bool ok;
147             cval->kcolorbutton->setColor(value.toUInt(&ok, 16));
148             kDebug() << value.toUInt(&ok, 16);
149
150             connect(cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT(collectAllParameters()));
151             cval->label->setText(na.toElement().text());
152             valueItems[paramName] = cval;
153             uiItems.append(cval);
154         } else {
155             delete toFillin;
156             toFillin = NULL;
157         }
158
159         if (toFillin) {
160             items.append(toFillin);
161             vbox->addWidget(toFillin);
162         }
163     }
164 }
165 void EffectStackEdit::collectAllParameters() {
166     QDomElement oldparam = params.cloneNode().toElement();
167     QDomNodeList namenode = params.elementsByTagName("parameter");
168
169     for (int i = 0;i < namenode.count() ;i++) {
170         QDomNode pa = namenode.item(i);
171         QDomNode na = pa.firstChildElement("name");
172         QString type = pa.attributes().namedItem("type").nodeValue();
173         QString setValue;
174         if (type == "double" || type == "constant") {
175             QSlider* slider = ((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider;
176             setValue = QString::number(slider->value());
177         } else
178             if (type == "list") {
179                 KComboBox *box = ((Ui::Listval_UI*)valueItems[na.toElement().text()])->list;
180                 setValue = box->currentText();
181             } else
182                 if (type == "bool") {
183                     QCheckBox *box = ((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox;
184                     setValue = box->checkState() == Qt::Checked ? "1" : "0" ;
185                 } else
186                     if (type == "color") {
187                         KColorButton *color = ((Ui::Colorval_UI*)valueItems[na.toElement().text()])->kcolorbutton;
188                         setValue.sprintf("0x%08x", color->color().rgba());
189                     } else
190                         if (type == "complex") {
191                             ComplexParameter *complex = ((ComplexParameter*)valueItems[na.toElement().text()+"complex"]);
192                             namenode.item(i) = complex->getParamDesc();
193                         }
194         if (!setValue.isEmpty()) {
195             pa.attributes().namedItem("value").setNodeValue(setValue);
196         }
197     }
198     emit parameterChanged(oldparam, params);
199 }
200
201 void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max) {
202     QWidget* toFillin = new QWidget;
203     Ui::Constval_UI *ctval = new Ui::Constval_UI;
204     ctval->setupUi(toFillin);
205
206     ctval->horizontalSlider->setMinimum(min);
207     ctval->horizontalSlider->setMaximum(max);
208     ctval->spinBox->setMinimum(min);
209     ctval->spinBox->setMaximum(max);
210     ctval->horizontalSlider->setPageStep((int)(max - min) / 10);
211     ctval->horizontalSlider->setValue(val);
212     ctval->label->setText(name);
213     valueItems[name] = ctval;
214     uiItems.append(ctval);
215     connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters()));
216     items.append(toFillin);
217     vbox->addWidget(toFillin);
218 }
219
220 void EffectStackEdit::slotSliderMoved(int) {
221     collectAllParameters();
222 }
223
224 void EffectStackEdit::clearAllItems() {
225     foreach(QWidget* w, items) {
226         vbox->removeWidget(w);
227         delete w;
228     }
229     foreach(void * p, uiItems) {
230         delete p;
231     }
232     uiItems.clear();
233     items.clear();
234     valueItems.clear();
235 }