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