1 /***************************************************************************
2 effecstackview.cpp - description
5 copyright : (C) 2008 by Marco Gittler
6 email : g.marco@freenet.de
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
21 #include "effectstackview.h"
22 #include "effectslist.h"
24 #include <QHeaderView>
27 EffectStackView::EffectStackView(EffectsList *audioEffectList, EffectsList *videoEffectList, EffectsList *customEffectList, QWidget *parent)
31 effectedit=new EffectStackEdit(ui.frame,this);
32 //ui.effectlist->horizontalHeader()->setVisible(false);
33 //ui.effectlist->verticalHeader()->setVisible(false);
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"));
48 ui.effectlist->setDragDropMode(QAbstractItemView::NoDragDrop);//use internal if drop is recognised right
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;
69 void EffectStackView::slotUpdateEffectParams(const QDomElement& old, const QDomElement& e){
71 emit updateClipEffect(clipref, old, e);
74 void EffectStackView::slotClipItemSelected(ClipItem* c)
86 void EffectStackView::slotItemChanged(QListWidgetItem *item)
89 if (item->checkState() == Qt::Checked) disable = false;
90 int activeRow = ui.effectlist->currentRow();
92 emit changeEffectState(clipref, clipref->effectAt(activeRow), disable);
94 kDebug()<<"--- EFFECT CHANGED!!!!!!!!!!!!!!!!!";
98 void EffectStackView::setupListView(){
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);
111 if (clipref->effectsCount() == 0)
112 emit transferParamDesc(QDomElement(), 0, 100);
113 ui.effectlist->setCurrentRow(0);
117 void EffectStackView::slotItemSelectionChanged(){
118 bool hasItem = ui.effectlist->currentItem();
119 int activeRow = ui.effectlist->currentRow();
120 if (hasItem && ui.effectlist->currentItem()->isSelected() ){
121 emit transferParamDesc(clipref->effectAt(activeRow), 0, 100);//minx max frame
123 ui.buttonDel->setEnabled( hasItem );
124 ui.buttonReset->setEnabled( hasItem );
125 ui.buttonUp->setEnabled( activeRow >0 );
126 ui.buttonDown->setEnabled( (activeRow < ui.effectlist->count()-1) && hasItem );
129 void EffectStackView::slotItemUp(){
130 int activeRow = ui.effectlist->currentRow();
132 QDomElement act = clipref->effectAt(activeRow).cloneNode().toElement();
133 QDomElement before = clipref->effectAt(activeRow-1).cloneNode().toElement();
134 clipref->setEffectAt(activeRow-1, act);
135 clipref->setEffectAt(activeRow, before);
137 QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
138 ui.effectlist->insertItem (activeRow-1, item);
139 ui.effectlist->setCurrentItem(item);
140 emit refreshEffectStack(clipref);
143 void EffectStackView::slotItemDown(){
144 int activeRow = ui.effectlist->currentRow();
145 if (activeRow < ui.effectlist->count()-1){
146 QDomElement act = clipref->effectAt(activeRow).cloneNode().toElement();
147 QDomElement after = clipref->effectAt(activeRow+1).cloneNode().toElement();
148 clipref->setEffectAt(activeRow+1, act);
149 clipref->setEffectAt(activeRow, after);
151 QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
152 ui.effectlist->insertItem (activeRow+1, item);
153 ui.effectlist->setCurrentItem(item);
154 emit refreshEffectStack(clipref);
157 void EffectStackView::slotItemDel(){
158 int activeRow = ui.effectlist->currentRow();
160 emit removeEffect(clipref, clipref->effectAt(activeRow));
164 void EffectStackView::slotResetEffect()
166 int activeRow = ui.effectlist->currentRow();
167 QDomElement old = clipref->effectAt(activeRow).cloneNode().toElement();
169 QString effectName = ui.effectlist->currentItem()->text();
170 foreach (QString type, effectLists.keys() ){
171 EffectsList *list=effectLists[type];
172 if (list->effectNames().contains(effectName)) {
173 dom = list->getEffectByName(effectName);
177 if (!dom.isNull()) emit updateClipEffect(clipref, old, dom);
180 void EffectStackView::slotNewEffect(){
183 QMenu *displayMenu=new QMenu (this);
184 displayMenu->setTitle("Filters");
185 foreach (QString type, effectLists.keys() ){
186 QAction *a=new QAction(type,displayMenu);
187 EffectsList *list=effectLists[type];
189 QMenu *parts=new QMenu(type,displayMenu);
190 parts->setTitle(type);
191 foreach (QString name, list->effectNames()){
192 QAction *entry=new QAction(name,parts);
193 entry->setData(name);
194 entry->setToolTip(list->getInfo(name));
195 entry->setStatusTip(list->getInfo(name));
196 parts->addAction(entry);
199 displayMenu->addMenu(parts);
203 QAction *result=displayMenu->exec(mapToGlobal(ui.buttonNew->pos()+ui.buttonNew->rect().bottomRight()));
206 //TODO effects.append(result->data().toString());
207 foreach (EffectsList* e, effectLists.values()){
208 QDomElement dom=e->getEffectByName(result->data().toString());
210 clipref->addEffect(dom);
211 slotClipItemSelected(clipref);
215 //kDebug()<< result->data();
221 void EffectStackView::itemSelectionChanged (){
222 //kDebug() << "drop";
224 #include "effectstackview.moc"