]> git.sesse.net Git - kdenlive/blob - src/effectstackview.cpp
* NEW: find as you type feature. You can now type a text and the timeline will scroll...
[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 "mainwindow.h"
25 #include <QHeaderView>
26 #include <QMenu>
27
28 EffectStackView::EffectStackView(QWidget *parent)
29         : QWidget(parent) {
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"] = &MainWindow::audioEffects;
60     effectLists["video"] = &MainWindow::videoEffects;
61     effectLists["custom"] = &MainWindow::customEffects;
62
63     ui.infoBox->hide();
64     setEnabled(false);
65 }
66
67 void EffectStackView::slotUpdateEffectParams(const QDomElement& old, const QDomElement& e) {
68     if (clipref)
69         emit updateClipEffect(clipref, old, e, ui.effectlist->currentRow());
70 }
71
72 void EffectStackView::slotClipItemSelected(ClipItem* c) {
73     int ix = 0;
74     if (c && c == clipref) {
75         ix = ui.effectlist->currentRow();
76     } else {
77         clipref = c;
78         if (c) ix = c->selectedEffectIndex();
79     }
80     if (clipref == NULL) {
81         ui.effectlist->clear();
82         setEnabled(false);
83         return;
84     }
85     setEnabled(true);
86     setupListView(ix);
87 }
88
89 void EffectStackView::slotItemChanged(QListWidgetItem *item) {
90     bool disable = true;
91     if (item->checkState() == Qt::Checked) disable = false;
92     ui.buttonReset->setEnabled(!disable);
93     int activeRow = ui.effectlist->currentRow();
94     if (activeRow >= 0) {
95         emit changeEffectState(clipref, activeRow, disable);
96     }
97 }
98
99
100 void EffectStackView::setupListView(int ix) {
101     ui.effectlist->clear();
102     for (int i = 0;i < clipref->effectsCount();i++) {
103         QDomElement d = clipref->effectAt(i);
104         QDomNode namenode = d.elementsByTagName("name").item(0);
105         if (!namenode.isNull()) {
106             QListWidgetItem* item = new QListWidgetItem(namenode.toElement().text(), ui.effectlist);
107             item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
108             if (d.attribute("disabled") == "1") item->setCheckState(Qt::Unchecked);
109             else item->setCheckState(Qt::Checked);
110         }
111     }
112     if (clipref->effectsCount() == 0)
113         emit transferParamDesc(QDomElement(), 0, 100);
114     if (ix < 0) ix = 0;
115     ui.effectlist->setCurrentRow(ix);
116 }
117
118 void EffectStackView::slotItemSelectionChanged() {
119     bool hasItem = ui.effectlist->currentItem();
120     int activeRow = ui.effectlist->currentRow();
121     bool isChecked = ui.effectlist->currentItem()->checkState() == Qt::Checked;
122     if (hasItem && ui.effectlist->currentItem()->isSelected()) {
123         emit transferParamDesc(clipref->effectAt(activeRow), 0, 100);//minx max frame
124     }
125     if (clipref) clipref->setSelectedEffect(activeRow);
126     ui.buttonDel->setEnabled(hasItem);
127     ui.buttonReset->setEnabled(hasItem && isChecked);
128     ui.buttonUp->setEnabled(activeRow > 0);
129     ui.buttonDown->setEnabled((activeRow < ui.effectlist->count() - 1) && hasItem);
130 }
131
132 void EffectStackView::slotItemUp() {
133     int activeRow = ui.effectlist->currentRow();
134     if (activeRow > 0) {
135         QDomElement act = clipref->effectAt(activeRow).cloneNode().toElement();
136         QDomElement before = clipref->effectAt(activeRow - 1).cloneNode().toElement();
137         clipref->setEffectAt(activeRow - 1, act);
138         clipref->setEffectAt(activeRow, before);
139     }
140     QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
141     ui.effectlist->insertItem(activeRow - 1, item);
142     ui.effectlist->setCurrentItem(item);
143     emit changeEffectPosition(clipref, activeRow + 1, activeRow);
144 }
145
146 void EffectStackView::slotItemDown() {
147     int activeRow = ui.effectlist->currentRow();
148     if (activeRow < ui.effectlist->count() - 1) {
149         QDomElement act = clipref->effectAt(activeRow).cloneNode().toElement();
150         QDomElement after = clipref->effectAt(activeRow + 1).cloneNode().toElement();
151         clipref->setEffectAt(activeRow + 1, act);
152         clipref->setEffectAt(activeRow, after);
153     }
154     QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
155     ui.effectlist->insertItem(activeRow + 1, item);
156     ui.effectlist->setCurrentItem(item);
157     emit changeEffectPosition(clipref, activeRow + 1, activeRow + 2);
158 }
159
160 void EffectStackView::slotItemDel() {
161     int activeRow = ui.effectlist->currentRow();
162     if (activeRow >= 0) {
163         emit removeEffect(clipref, clipref->effectAt(activeRow));
164     }
165 }
166
167 void EffectStackView::slotResetEffect() {
168     int activeRow = ui.effectlist->currentRow();
169     QDomElement old = clipref->effectAt(activeRow).cloneNode().toElement();
170     QDomElement dom;
171     QString effectName = ui.effectlist->currentItem()->text();
172     foreach(const QString &type, effectLists.keys()) {
173         EffectsList *list = effectLists[type];
174         if (list->effectNames().contains(effectName)) {
175             dom = list->getEffectByName(effectName);
176             break;
177         }
178     }
179     if (!dom.isNull()) {
180         dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
181         emit transferParamDesc(dom, 0, 100);//minx max frame
182         emit updateClipEffect(clipref, old, dom, activeRow);
183     }
184 }
185
186 void EffectStackView::slotNewEffect() {
187     int ix = ui.effectlist->currentRow();
188     QMenu *displayMenu = new QMenu(this);
189     displayMenu->setTitle("Filters");
190     foreach(const QString &type, effectLists.keys()) {
191         QAction *a = new QAction(type, displayMenu);
192         EffectsList *list = effectLists[type];
193
194         QMenu *parts = new QMenu(type, displayMenu);
195         parts->setTitle(type);
196         foreach(const 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);
202             //QAction
203         }
204         displayMenu->addMenu(parts);
205
206     }
207
208     QAction *result = displayMenu->exec(mapToGlobal(ui.buttonNew->pos() + ui.buttonNew->rect().bottomRight()));
209
210     if (result) {
211         //TODO effects.append(result->data().toString());
212         foreach(const EffectsList *e, effectLists.values()) {
213             QDomElement dom = e->getEffectByName(result->data().toString());
214             if (clipref)
215                 clipref->addEffect(dom);
216             slotClipItemSelected(clipref);
217         }
218
219         setupListView(ix);
220         //kDebug()<< result->data();
221     }
222     delete displayMenu;
223
224 }
225
226 void EffectStackView::raiseWindow(QWidget* dock) {
227     if (clipref && dock)
228         dock->raise();
229 }
230
231 #include "effectstackview.moc"