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"));
47 ui.effectlist->setDragDropMode(QAbstractItemView::NoDragDrop);//use internal if drop is recognised right
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;
65 void EffectStackView::slotUpdateEffectParams(const QDomElement& e){
66 //effects[ui.effectlist->currentRow()]=e;
68 emit updateClipEffect(clipref, e);
71 void EffectStackView::slotClipItemSelected(ClipItem* c)
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");
87 void EffectStackView::setupListView(){
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);
99 ui.effectlist->setCurrentRow(0);
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
108 ui.buttonDel->setEnabled( hasItem );
109 ui.buttonUp->setEnabled( activeRow >0 );
110 ui.buttonDown->setEnabled( (activeRow < ui.effectlist->count()-1) && hasItem );
113 void EffectStackView::slotItemUp(){
114 int activeRow = ui.effectlist->currentRow();
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);
121 //effects.swap(activeRow, activeRow-1);
123 QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
124 ui.effectlist->insertItem (activeRow-1, item);
125 ui.effectlist->setCurrentItem(item);
126 emit refreshEffectStack(clipref);
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);
137 //effects.swap(activeRow, activeRow+1);
139 QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
140 ui.effectlist->insertItem (activeRow+1, item);
141 ui.effectlist->setCurrentItem(item);
142 emit refreshEffectStack(clipref);
145 void EffectStackView::slotItemDel(){
146 int activeRow = ui.effectlist->currentRow();
148 emit removeEffect(clipref, clipref->effectAt(activeRow));
149 //effects.take(activeRow);
151 //effects.removeAt(activeRow);
153 /*if (effects.size()>0 && activeRow>0) {
154 QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
155 kDebug()<<"777777 DELETING ITEM: "<<activeRow;
161 void EffectStackView::renumberEffects(){/*
162 QMap<int,QDomElement> tmplist=effects;
163 QMapIterator<int,QDomElement> it(tmplist);
167 while (it.hasNext()){
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));
173 if (clipref && i != currentVal)
174 emit updateClipEffect(clipref,item);
176 QTextStream str(&outstr);
178 kDebug() << "nummer: " << i << " " << outstr;
179 kDebug()<<"EFFECT "<<i<<" = "<<item.attribute("tag");
185 void EffectStackView::slotNewEffect(){
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];
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);
204 displayMenu->addMenu(parts);
208 QAction *result=displayMenu->exec(mapToGlobal(ui.buttonNew->pos()+ui.buttonNew->rect().bottomRight()));
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);
219 //kDebug()<< result->data();
225 void EffectStackView::itemSelectionChanged (){
226 //kDebug() << "drop";
228 #include "effectstackview.moc"