]> git.sesse.net Git - kdenlive/blob - src/effectstackview.cpp
ee58d49b63865cc6a7c7b71c382f6eafda24d2f2
[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         //ui.effectlist->horizontalHeader()->setVisible(false);
32         //ui.effectlist->verticalHeader()->setVisible(false);
33         activeRow=-1;
34         clipref=NULL;
35         
36         ui.buttonNew->setIcon(KIcon("document-new"));
37         ui.buttonUp->setIcon(KIcon("go-up"));
38         ui.buttonDown->setIcon(KIcon("go-down"));
39         ui.buttonDel->setIcon(KIcon("trash-empty"));
40         
41         ui.buttonLeftRight->setIcon(KIcon("go-next"));//better icons needed
42         ui.buttonUpDown->setIcon(KIcon("go-up"));
43         ui.buttonShowInTimeline->setIcon(KIcon("kmplayer"));
44         ui.buttonHelp->setIcon(KIcon("help-about"));
45         ui.buttonNewPoints->setIcon(KIcon("xedit"));
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 (ui.buttonLeftRight, SIGNAL (clicked()), this , SLOT ( slotSetMoveX() ) );
55         connect (ui.buttonUpDown, SIGNAL (clicked()), this , SLOT ( slotSetMoveY() ) );
56         connect (ui.buttonShowInTimeline, SIGNAL (clicked()), this , SLOT ( slotShowInTimeline() ) );
57         connect (ui.buttonNewPoints, SIGNAL (clicked()), this , SLOT ( slotSetNew() ) );
58         connect (ui.buttonHelp, SIGNAL (clicked()), this , SLOT ( slotSetHelp() ) );
59         connect (ui.parameterList, SIGNAL (currentIndexChanged ( const QString &  ) ), this, SLOT( slotParameterChanged(const QString&) ) );
60         connect (ui.effectlist, SIGNAL (itemSelectionChanged() ) , this, SLOT ( itemSelectionChanged()));
61         
62         effectLists["audio"]=audioEffectList;
63         effectLists["video"]=videoEffectList;
64         effectLists["custom"]=customEffectList;
65         
66         ui.infoBox->hide();     
67         updateButtonStatus();
68         
69         
70         QList< QPair<QString, QMap<int,QVariant> > > points;
71         QMap<int,QVariant> data;
72         data[0]=0.1;
73         data[100]=30;
74         data[255]=50;
75         data[300]=100;
76         QPair<QString,QMap<int,QVariant> > testpair("gray",data);
77         points.append(testpair);
78         
79         QMap<int,QVariant> data1;
80         data1[0]=20;
81         data1[10]=70;
82         data1[155]=110;
83         data1[300]=133;
84         QPair<QString,QMap<int,QVariant> > testpair1("dx",data1);
85         points.append(testpair1);
86         ui.parameterList->addItem("all");
87         ui.parameterList->addItem("gray");
88         ui.parameterList->addItem("dx");
89         
90         ui.kplotwidget->setPointLists(points,0,305);
91         
92 }
93
94 void EffectStackView::slotClipItemSelected(ClipItem* c)
95 {
96         clipref=c;
97         if (clipref==NULL)
98                 return;
99         effects=clipref->effectNames();
100         setupListView(effects);
101         
102 }
103
104 void EffectStackView::setupListView(const QStringList& effects_list){
105
106         ui.effectlist->clear();
107         ui.effectlist->addItems(effects);
108         for (int i=0;i< ui.effectlist->count();i++){
109                 QListWidgetItem* item=ui.effectlist->item(i);
110                 item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsDragEnabled|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
111                 item->setCheckState(Qt::Checked);
112                 if (activeRow==i){
113                         item->setSelected(true);
114                         ui.effectlist->setCurrentRow(activeRow);
115                 }
116         }
117
118 }
119
120 void EffectStackView::slotItemSelectionChanged(){
121         
122         if (ui.effectlist->currentItem() && ui.effectlist->currentItem()->isSelected() ){
123                 activeRow=ui.effectlist->row( ui.effectlist->currentItem() );
124         }else{
125                 activeRow=-1;
126         }
127         ui.buttonDel->setEnabled( activeRow!=-1);
128         ui.buttonUp->setEnabled( activeRow >0 );
129         ui.buttonDown->setEnabled( (activeRow<ui.effectlist->count()-1) && activeRow>=0 );
130 }
131
132 void EffectStackView::slotItemUp(){
133         if (activeRow>0 && activeRow <effects.size() ){
134                 effects.swap(activeRow, activeRow-1);
135         }
136         activeRow--;
137         setupListView(effects);
138         
139 }
140
141 void EffectStackView::slotItemDown(){
142         if (activeRow<effects.size()-1  ){
143                 effects.swap(activeRow, activeRow+1);
144         }
145         activeRow++;
146         setupListView(effects);
147         
148 }
149
150 void EffectStackView::slotItemDel(){
151         if (activeRow<effects.size() && activeRow>=0  ){
152                 effects.removeAt(activeRow);
153         }
154         if (effects.size()>0 && activeRow>0)
155         activeRow--;
156         setupListView(effects);
157         
158 }
159
160 void EffectStackView::slotSetMoveX(){
161         ui.kplotwidget->setMoveX(!ui.kplotwidget->isMoveX());
162         updateButtonStatus();
163 }
164
165 void EffectStackView::slotSetMoveY(){
166         ui.kplotwidget->setMoveY(!ui.kplotwidget->isMoveY());
167         updateButtonStatus();
168 }
169
170 void EffectStackView::slotSetNew(){
171         ui.kplotwidget->setNewPoints(!ui.kplotwidget->isNewPoints());
172         updateButtonStatus();
173 }
174
175 void EffectStackView::slotSetHelp(){
176         ui.infoBox->setVisible(!ui.infoBox->isVisible());
177         ui.buttonHelp->setDown(ui.infoBox->isVisible());
178 }
179
180 void EffectStackView::slotShowInTimeline(){
181
182         ui.kplotwidget->setMoveTimeLine(!ui.kplotwidget->isMoveTimeline());
183         updateButtonStatus();
184         
185 }
186
187 void EffectStackView::updateButtonStatus(){
188         ui.buttonLeftRight->setDown(ui.kplotwidget->isMoveX());
189         ui.buttonUpDown->setDown(ui.kplotwidget->isMoveY());
190         
191         ui.buttonShowInTimeline->setEnabled( ui.kplotwidget->isMoveX() || ui.kplotwidget->isMoveY ()  );
192         ui.buttonShowInTimeline->setDown(ui.kplotwidget->isMoveTimeline());
193         
194         ui.buttonNewPoints->setEnabled(ui.parameterList->currentText()!="all");
195         ui.buttonNewPoints->setDown(ui.kplotwidget->isNewPoints());
196 }
197
198 void EffectStackView::slotParameterChanged(const QString& text){
199         
200         //ui.buttonNewPoints->setEnabled(text!="all");
201         updateButtonStatus();
202 }
203
204 void EffectStackView::slotNewEffect(){
205         
206
207         QMenu *displayMenu=new QMenu (this);
208         displayMenu->setTitle("Filters");
209         foreach (QString type, effectLists.keys() ){
210                 QAction *a=new QAction(type,displayMenu);
211                 EffectsList *list=effectLists[type];
212
213                 QMenu *parts=new QMenu(type,displayMenu);
214                 parts->setTitle(type);
215                 foreach (QString name, list->effectNames()){
216                         QAction *entry=new QAction(name,parts);
217                         entry->setData(name);
218                         entry->setToolTip(list->getInfo(name));
219                         entry->setStatusTip(list->getInfo(name));
220                         parts->addAction(entry);
221                         //QAction
222                 }
223                 displayMenu->addMenu(parts);
224
225         }
226
227         QAction *result=displayMenu->exec(mapToGlobal(ui.buttonNew->pos()+ui.buttonNew->rect().bottomRight()));
228         
229         if (result){
230                 effects.append(result->data().toString());
231                 setupListView(effects);
232                 kDebug()<< result->data();
233         }
234         delete displayMenu;
235         
236 }
237
238 void EffectStackView::itemSelectionChanged (){
239         //kDebug() << "drop";
240 }
241 #include "effectstackview.moc"