]> git.sesse.net Git - kdenlive/blob - src/effectstackview.cpp
Update effect stak stuff
[kdenlive] / src / effectstackview.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
21 #include "effectstackview.h"
22 #include "effectslist.h"
23 #include "clipitem.h"
24 #include <QHeaderView>
25 #include <QMenu>
26
27 EffectStackView::EffectStackView(EffectsList *audioEffectList, EffectsList *videoEffectList, EffectsList *customEffectList, QWidget *parent)
28 : QWidget(parent)
29 {
30         ui.setupUi(this);
31         effectedit=new EffectStackEdit(ui.frame,this);
32         //ui.effectlist->horizontalHeader()->setVisible(false);
33         //ui.effectlist->verticalHeader()->setVisible(false);
34         clipref=NULL;
35         
36         ui.buttonNew->setIcon(KIcon("document-new"));
37         ui.buttonNew->setToolTip(i18n("Add new effect"));
38         ui.buttonUp->setIcon(KIcon("go-up"));
39         ui.buttonUp->setToolTip(i18n("Move effect up"));
40         ui.buttonDown->setIcon(KIcon("go-down"));
41         ui.buttonDown->setToolTip(i18n("Move effect down"));
42         ui.buttonDel->setIcon(KIcon("trash-empty"));
43         ui.buttonDel->setToolTip(i18n("Delete effect"));
44         
45
46         
47         ui.effectlist->setDragDropMode(QAbstractItemView::NoDragDrop);//use internal if drop is recognised right
48         
49         connect (ui.effectlist, SIGNAL ( itemSelectionChanged()), this , SLOT( slotItemSelectionChanged() ));
50         connect (ui.buttonNew, SIGNAL (clicked()), this, SLOT (slotNewEffect()) );
51         connect (ui.buttonUp, SIGNAL (clicked()), this, SLOT (slotItemUp()) );
52         connect (ui.buttonDown, SIGNAL (clicked()), this, SLOT (slotItemDown()) );
53         connect (ui.buttonDel, SIGNAL (clicked()), this, SLOT (slotItemDel()) );
54         connect( this, SIGNAL (transferParamDesc(const QDomElement&,int ,int) ), effectedit , SLOT(transferParamDesc(const QDomElement&,int ,int)));
55         connect(effectedit, SIGNAL (parameterChanged(const QDomElement&  ) ), this , SLOT (slotUpdateEffectParams(const QDomElement&)));
56         effectLists["audio"]=audioEffectList;
57         effectLists["video"]=videoEffectList;
58         effectLists["custom"]=customEffectList;
59         
60         ui.infoBox->hide();     
61         
62         
63 }
64
65 void EffectStackView::slotUpdateEffectParams(const QDomElement& e){
66         //effects[ui.effectlist->currentRow()]=e;
67         if (clipref)
68                 emit updateClipEffect(clipref, e);
69 }
70
71 void EffectStackView::slotClipItemSelected(ClipItem* c)
72 {
73         clipref=c;
74         if (clipref==NULL) {
75                 setEnabled(false);
76                 return;
77         }
78         setEnabled(true);
79         //effects=clipref->effectNames();
80         for (int i=0;i<clipref->effectsCount();i++){
81                 QDomElement element=clipref->effectAt(i);//kDebug()<<"// SET STACK :"<<element.attribute("kdenlive_ix")<<", ("<<i<<") = "<<element.attribute("tag");
82         }
83         setupListView();
84         
85 }
86
87 void EffectStackView::setupListView(){
88
89         ui.effectlist->clear();
90         for (int i=0;i<clipref->effectsCount();i++){
91                 QDomElement d=clipref->effectAt(i);
92                 QDomNode namenode = d.elementsByTagName("name").item(0);
93                 if (!namenode.isNull()) {
94                         QListWidgetItem* item = new QListWidgetItem(namenode.toElement().text(), ui.effectlist);
95                         item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsDragEnabled|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
96                         item->setCheckState(Qt::Checked);
97                 }
98         }
99         ui.effectlist->setCurrentRow(0);
100 }
101
102 void EffectStackView::slotItemSelectionChanged(){
103         bool hasItem = ui.effectlist->currentItem();
104         int activeRow = ui.effectlist->currentRow();
105         if (hasItem && ui.effectlist->currentItem()->isSelected() ){
106                 emit transferParamDesc(clipref->effectAt(activeRow) ,0,100);//minx max frame
107         }
108         ui.buttonDel->setEnabled( hasItem );
109         ui.buttonUp->setEnabled( activeRow >0 );
110         ui.buttonDown->setEnabled( (activeRow < ui.effectlist->count()-1) && hasItem );
111 }
112
113 void EffectStackView::slotItemUp(){
114         int activeRow = ui.effectlist->currentRow();
115         if (activeRow>0){
116                 QDomElement act = clipref->effectAt(activeRow).cloneNode().toElement();
117                 QDomElement before = clipref->effectAt(activeRow-1).cloneNode().toElement();
118                 clipref->setEffectAt(activeRow-1, act);
119                 clipref->setEffectAt(activeRow, before);
120                 //renumberEffects();
121                 //effects.swap(activeRow, activeRow-1);
122         }
123         QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
124         ui.effectlist->insertItem (activeRow-1, item);
125         ui.effectlist->setCurrentItem(item);
126         emit refreshEffectStack(clipref);
127 }
128
129 void EffectStackView::slotItemDown(){
130         int activeRow = ui.effectlist->currentRow();
131         if (activeRow < ui.effectlist->count()-1){
132                 QDomElement act = clipref->effectAt(activeRow).cloneNode().toElement();
133                 QDomElement after = clipref->effectAt(activeRow+1).cloneNode().toElement();
134                 clipref->setEffectAt(activeRow+1, act);
135                 clipref->setEffectAt(activeRow, after);
136                 //renumberEffects();
137                 //effects.swap(activeRow, activeRow+1);
138         }
139         QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
140         ui.effectlist->insertItem (activeRow+1, item);
141         ui.effectlist->setCurrentItem(item);
142         emit refreshEffectStack(clipref);
143 }
144
145 void EffectStackView::slotItemDel(){
146         int activeRow = ui.effectlist->currentRow();
147         if ( activeRow>=0  ){
148                 emit removeEffect(clipref, clipref->effectAt(activeRow));
149                 //effects.take(activeRow);
150                 //renumberEffects();
151                 //effects.removeAt(activeRow);
152         }
153         /*if (effects.size()>0 && activeRow>0) {
154                 QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
155                 kDebug()<<"777777   DELETING ITEM: "<<activeRow;
156                 delete item;
157         }*/
158         
159 }
160
161 void EffectStackView::renumberEffects(){/*
162         QMap<int,QDomElement> tmplist=effects;
163         QMapIterator<int,QDomElement> it(tmplist);
164         effects.clear();
165         int i=0;
166         
167         while (it.hasNext()){
168                 it.next();
169                 QDomElement item=it.value();
170                 int currentVal = item.attributes().namedItem("kdenlive_ix").nodeValue().toInt();
171                 item.attributes().namedItem("kdenlive_ix").setNodeValue(QString::number(i));
172                 effects[i]=item;
173                 if (clipref && i != currentVal)
174                         emit updateClipEffect(clipref,item);
175                 QString outstr;
176                 QTextStream str(&outstr);
177                 item.save(str,2);
178                 kDebug() << "nummer: " << i << " " << outstr;
179                 kDebug()<<"EFFECT "<<i<<" = "<<item.attribute("tag");
180                 i++;
181         }*/
182         
183 }
184
185 void EffectStackView::slotNewEffect(){
186         
187
188         QMenu *displayMenu=new QMenu (this);
189         displayMenu->setTitle("Filters");
190         foreach (QString type, effectLists.keys() ){
191                 QAction *a=new QAction(type,displayMenu);
192                 EffectsList *list=effectLists[type];
193
194                 QMenu *parts=new QMenu(type,displayMenu);
195                 parts->setTitle(type);
196                 foreach (QString name, list->effectNames()){
197                         QAction *entry=new QAction(name,parts);
198                         entry->setData(name);
199                         entry->setToolTip(list->getInfo(name));
200                         entry->setStatusTip(list->getInfo(name));
201                         parts->addAction(entry);
202                         //QAction
203                 }
204                 displayMenu->addMenu(parts);
205
206         }
207
208         QAction *result=displayMenu->exec(mapToGlobal(ui.buttonNew->pos()+ui.buttonNew->rect().bottomRight()));
209         
210         if (result){
211                 //TODO effects.append(result->data().toString());
212                 foreach (EffectsList* e, effectLists.values()){
213                         QDomElement dom=e->getEffectByName(result->data().toString());
214                         clipref->addEffect(dom);
215                         slotClipItemSelected(clipref);
216                 }
217                 
218                 setupListView();
219                 //kDebug()<< result->data();
220         }
221         delete displayMenu;
222         
223 }
224
225 void EffectStackView::itemSelectionChanged (){
226         //kDebug() << "drop";
227 }
228 #include "effectstackview.moc"