]> git.sesse.net Git - kdenlive/blob - src/effectstackview.cpp
Edit effect parameter can be undone / redone
[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&, const QDomElement& ) ), this , SLOT (slotUpdateEffectParams( const QDomElement&, const QDomElement& )));
56         effectLists["audio"]=audioEffectList;
57         effectLists["video"]=videoEffectList;
58         effectLists["custom"]=customEffectList;
59         
60         ui.infoBox->hide();
61         setEnabled(false);
62         setEnabled(false);
63         
64 }
65
66 void EffectStackView::slotUpdateEffectParams(const QDomElement& old, const QDomElement& e){
67         if (clipref)
68                 emit updateClipEffect(clipref, old, 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         setupListView();
80         
81 }
82
83 void EffectStackView::setupListView(){
84
85         ui.effectlist->clear();
86         for (int i=0;i<clipref->effectsCount();i++){
87                 QDomElement d=clipref->effectAt(i);
88                 QDomNode namenode = d.elementsByTagName("name").item(0);
89                 if (!namenode.isNull()) {
90                         QListWidgetItem* item = new QListWidgetItem(namenode.toElement().text(), ui.effectlist);
91                         item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsDragEnabled|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
92                         item->setCheckState(Qt::Checked);
93                 }
94         }
95         if (clipref->effectsCount() == 0)
96           emit transferParamDesc(QDomElement(), 0, 100);
97         ui.effectlist->setCurrentRow(0);
98         
99 }
100
101 void EffectStackView::slotItemSelectionChanged(){
102         bool hasItem = ui.effectlist->currentItem();
103         int activeRow = ui.effectlist->currentRow();
104         if (hasItem && ui.effectlist->currentItem()->isSelected() ){
105                 emit transferParamDesc(clipref->effectAt(activeRow), 0, 100);//minx max frame
106         }
107         ui.buttonDel->setEnabled( hasItem );
108         ui.buttonUp->setEnabled( activeRow >0 );
109         ui.buttonDown->setEnabled( (activeRow < ui.effectlist->count()-1) && hasItem );
110 }
111
112 void EffectStackView::slotItemUp(){
113         int activeRow = ui.effectlist->currentRow();
114         if (activeRow>0){
115                 QDomElement act = clipref->effectAt(activeRow).cloneNode().toElement();
116                 QDomElement before = clipref->effectAt(activeRow-1).cloneNode().toElement();
117                 clipref->setEffectAt(activeRow-1, act);
118                 clipref->setEffectAt(activeRow, before);
119         }
120         QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
121         ui.effectlist->insertItem (activeRow-1, item);
122         ui.effectlist->setCurrentItem(item);
123         emit refreshEffectStack(clipref);
124 }
125
126 void EffectStackView::slotItemDown(){
127         int activeRow = ui.effectlist->currentRow();
128         if (activeRow < ui.effectlist->count()-1){
129                 QDomElement act = clipref->effectAt(activeRow).cloneNode().toElement();
130                 QDomElement after = clipref->effectAt(activeRow+1).cloneNode().toElement();
131                 clipref->setEffectAt(activeRow+1, act);
132                 clipref->setEffectAt(activeRow, after);
133         }
134         QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
135         ui.effectlist->insertItem (activeRow+1, item);
136         ui.effectlist->setCurrentItem(item);
137         emit refreshEffectStack(clipref);
138 }
139
140 void EffectStackView::slotItemDel(){
141         int activeRow = ui.effectlist->currentRow();
142         if ( activeRow>=0  ){
143                 emit removeEffect(clipref, clipref->effectAt(activeRow));
144         }
145 }
146
147
148 void EffectStackView::slotNewEffect(){
149         
150
151         QMenu *displayMenu=new QMenu (this);
152         displayMenu->setTitle("Filters");
153         foreach (QString type, effectLists.keys() ){
154                 QAction *a=new QAction(type,displayMenu);
155                 EffectsList *list=effectLists[type];
156
157                 QMenu *parts=new QMenu(type,displayMenu);
158                 parts->setTitle(type);
159                 foreach (QString name, list->effectNames()){
160                         QAction *entry=new QAction(name,parts);
161                         entry->setData(name);
162                         entry->setToolTip(list->getInfo(name));
163                         entry->setStatusTip(list->getInfo(name));
164                         parts->addAction(entry);
165                         //QAction
166                 }
167                 displayMenu->addMenu(parts);
168
169         }
170
171         QAction *result=displayMenu->exec(mapToGlobal(ui.buttonNew->pos()+ui.buttonNew->rect().bottomRight()));
172         
173         if (result){
174                 //TODO effects.append(result->data().toString());
175                 foreach (EffectsList* e, effectLists.values()){
176                         QDomElement dom=e->getEffectByName(result->data().toString());
177                         if (clipref)
178                                 clipref->addEffect(dom);
179                         slotClipItemSelected(clipref);
180                 }
181                 
182                 setupListView();
183                 //kDebug()<< result->data();
184         }
185         delete displayMenu;
186         
187 }
188
189 void EffectStackView::itemSelectionChanged (){
190         //kDebug() << "drop";
191 }
192 #include "effectstackview.moc"