]> git.sesse.net Git - kdenlive/blob - src/effectstackview.cpp
When resetting an effect, also reset the edit widget
[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         ui.buttonReset->setIcon(KIcon("view-refresh"));
45         ui.buttonReset->setToolTip(i18n("Reset effect"));       
46
47         
48         ui.effectlist->setDragDropMode(QAbstractItemView::NoDragDrop);//use internal if drop is recognised right
49         
50         connect (ui.effectlist, SIGNAL ( itemSelectionChanged()), this , SLOT( slotItemSelectionChanged() ));
51         connect (ui.effectlist, SIGNAL(itemChanged ( QListWidgetItem *)), this , SLOT( slotItemChanged(QListWidgetItem *) ));
52         connect (ui.buttonNew, SIGNAL (clicked()), this, SLOT (slotNewEffect()) );
53         connect (ui.buttonUp, SIGNAL (clicked()), this, SLOT (slotItemUp()) );
54         connect (ui.buttonDown, SIGNAL (clicked()), this, SLOT (slotItemDown()) );
55         connect (ui.buttonDel, SIGNAL (clicked()), this, SLOT (slotItemDel()) );
56         connect (ui.buttonReset, SIGNAL (clicked()), this, SLOT (slotResetEffect()) );
57         connect( this, SIGNAL (transferParamDesc(const QDomElement&,int ,int) ), effectedit , SLOT(transferParamDesc(const QDomElement&,int ,int)));
58         connect(effectedit, SIGNAL (parameterChanged( const QDomElement&, const QDomElement& ) ), this , SLOT (slotUpdateEffectParams( const QDomElement&, const QDomElement& )));
59         effectLists["audio"]=audioEffectList;
60         effectLists["video"]=videoEffectList;
61         effectLists["custom"]=customEffectList;
62         
63         ui.infoBox->hide();
64         setEnabled(false);
65         setEnabled(false);
66         
67 }
68
69 void EffectStackView::slotUpdateEffectParams(const QDomElement& old, const QDomElement& e){
70         if (clipref)
71                 emit updateClipEffect(clipref, old, e);
72 }
73
74 void EffectStackView::slotClipItemSelected(ClipItem* c)
75 {
76         clipref=c;
77         if (clipref==NULL) {
78                 setEnabled(false);
79                 return;
80         }
81         setEnabled(true);
82         setupListView();
83         
84 }
85
86 void EffectStackView::slotItemChanged(QListWidgetItem *item)
87 {
88     bool disable = true;
89     if (item->checkState() == Qt::Checked) disable = false;
90     ui.buttonReset->setEnabled( !disable);
91     int activeRow = ui.effectlist->currentRow();
92     if ( activeRow>=0  ){
93         emit changeEffectState(clipref, clipref->effectAt(activeRow), disable);
94     }
95 }
96
97
98 void EffectStackView::setupListView(){
99
100         ui.effectlist->clear();
101         for (int i=0;i<clipref->effectsCount();i++){
102                 QDomElement d=clipref->effectAt(i);
103                 QDomNode namenode = d.elementsByTagName("name").item(0);
104                 if (!namenode.isNull()) {
105                         QListWidgetItem* item = new QListWidgetItem(namenode.toElement().text(), ui.effectlist);
106                         item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsDragEnabled|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
107                         if (d.attribute("disabled") == "1") item->setCheckState(Qt::Unchecked);
108                         else item->setCheckState(Qt::Checked);
109                 }
110         }
111         if (clipref->effectsCount() == 0)
112           emit transferParamDesc(QDomElement(), 0, 100);
113         ui.effectlist->setCurrentRow(0);
114         
115 }
116
117 void EffectStackView::slotItemSelectionChanged(){
118         bool hasItem = ui.effectlist->currentItem();
119         int activeRow = ui.effectlist->currentRow();
120         bool isChecked = ui.effectlist->currentItem()->checkState() == Qt::Checked;
121         if (hasItem && ui.effectlist->currentItem()->isSelected() ){
122                 emit transferParamDesc(clipref->effectAt(activeRow), 0, 100);//minx max frame
123         }
124         ui.buttonDel->setEnabled( hasItem );
125         ui.buttonReset->setEnabled( hasItem && isChecked);
126         ui.buttonUp->setEnabled( activeRow >0 );
127         ui.buttonDown->setEnabled( (activeRow < ui.effectlist->count()-1) && hasItem );
128 }
129
130 void EffectStackView::slotItemUp(){
131         int activeRow = ui.effectlist->currentRow();
132         if (activeRow>0){
133                 QDomElement act = clipref->effectAt(activeRow).cloneNode().toElement();
134                 QDomElement before = clipref->effectAt(activeRow-1).cloneNode().toElement();
135                 clipref->setEffectAt(activeRow-1, act);
136                 clipref->setEffectAt(activeRow, before);
137         }
138         QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
139         ui.effectlist->insertItem (activeRow-1, item);
140         ui.effectlist->setCurrentItem(item);
141         emit refreshEffectStack(clipref);
142 }
143
144 void EffectStackView::slotItemDown(){
145         int activeRow = ui.effectlist->currentRow();
146         if (activeRow < ui.effectlist->count()-1){
147                 QDomElement act = clipref->effectAt(activeRow).cloneNode().toElement();
148                 QDomElement after = clipref->effectAt(activeRow+1).cloneNode().toElement();
149                 clipref->setEffectAt(activeRow+1, act);
150                 clipref->setEffectAt(activeRow, after);
151         }
152         QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
153         ui.effectlist->insertItem (activeRow+1, item);
154         ui.effectlist->setCurrentItem(item);
155         emit refreshEffectStack(clipref);
156 }
157
158 void EffectStackView::slotItemDel(){
159         int activeRow = ui.effectlist->currentRow();
160         if ( activeRow>=0  ){
161                 emit removeEffect(clipref, clipref->effectAt(activeRow));
162         }
163 }
164
165 void EffectStackView::slotResetEffect()
166 {
167         int activeRow = ui.effectlist->currentRow();
168         QDomElement old = clipref->effectAt(activeRow).cloneNode().toElement();
169         QDomElement dom;
170         QString effectName = ui.effectlist->currentItem()->text();
171         foreach (QString type, effectLists.keys() ){
172                 EffectsList *list=effectLists[type];
173                 if (list->effectNames().contains(effectName)) {
174                     dom = list->getEffectByName(effectName);
175                     break;
176                 }
177         }
178         if (!dom.isNull()) {
179             emit updateClipEffect(clipref, old, dom);
180             slotItemSelectionChanged();
181         }
182 }
183
184 void EffectStackView::slotNewEffect(){
185         
186
187         QMenu *displayMenu=new QMenu (this);
188         displayMenu->setTitle("Filters");
189         foreach (QString type, effectLists.keys() ){
190                 QAction *a=new QAction(type,displayMenu);
191                 EffectsList *list=effectLists[type];
192
193                 QMenu *parts=new QMenu(type,displayMenu);
194                 parts->setTitle(type);
195                 foreach (QString name, list->effectNames()){
196                         QAction *entry=new QAction(name,parts);
197                         entry->setData(name);
198                         entry->setToolTip(list->getInfo(name));
199                         entry->setStatusTip(list->getInfo(name));
200                         parts->addAction(entry);
201                         //QAction
202                 }
203                 displayMenu->addMenu(parts);
204
205         }
206
207         QAction *result=displayMenu->exec(mapToGlobal(ui.buttonNew->pos()+ui.buttonNew->rect().bottomRight()));
208         
209         if (result){
210                 //TODO effects.append(result->data().toString());
211                 foreach (EffectsList* e, effectLists.values()){
212                         QDomElement dom=e->getEffectByName(result->data().toString());
213                         if (clipref)
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"