]> git.sesse.net Git - kdenlive/blob - src/effectstackview.cpp
Comment out names of unused parameters [PATCH by Ray Lehtiniemi]
[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
19 #include "effectstackview.h"
20 #include "effectslist.h"
21 #include "clipitem.h"
22 #include "mainwindow.h"
23 #include "kdenlivesettings.h"
24
25 #include <KDebug>
26 #include <KLocale>
27 #include <KMessageBox>
28 #include <KStandardDirs>
29
30 #include <QMenu>
31 #include <QTextStream>
32 #include <QFile>
33 #include <QInputDialog>
34
35
36 EffectStackView::EffectStackView(QWidget *parent)
37         : QWidget(parent) {
38     ui.setupUi(this);
39     effectedit = new EffectStackEdit(ui.frame);
40     //ui.effectlist->horizontalHeader()->setVisible(false);
41     //ui.effectlist->verticalHeader()->setVisible(false);
42     clipref = NULL;
43
44     ui.buttonNew->setIcon(KIcon("document-new"));
45     ui.buttonNew->setToolTip(i18n("Add new effect"));
46     ui.buttonUp->setIcon(KIcon("go-up"));
47     ui.buttonUp->setToolTip(i18n("Move effect up"));
48     ui.buttonDown->setIcon(KIcon("go-down"));
49     ui.buttonDown->setToolTip(i18n("Move effect down"));
50     ui.buttonDel->setIcon(KIcon("trash-empty"));
51     ui.buttonDel->setToolTip(i18n("Delete effect"));
52     ui.buttonSave->setIcon(KIcon("document-save"));
53     ui.buttonSave->setToolTip(i18n("Save effect"));
54     ui.buttonReset->setIcon(KIcon("view-refresh"));
55     ui.buttonReset->setToolTip(i18n("Reset effect"));
56
57
58     ui.effectlist->setDragDropMode(QAbstractItemView::NoDragDrop);//use internal if drop is recognised right
59
60     connect(ui.effectlist, SIGNAL(itemSelectionChanged()), this , SLOT(slotItemSelectionChanged()));
61     connect(ui.effectlist, SIGNAL(itemChanged(QListWidgetItem *)), this , SLOT(slotItemChanged(QListWidgetItem *)));
62     connect(ui.buttonUp, SIGNAL(clicked()), this, SLOT(slotItemUp()));
63     connect(ui.buttonDown, SIGNAL(clicked()), this, SLOT(slotItemDown()));
64     connect(ui.buttonDel, SIGNAL(clicked()), this, SLOT(slotItemDel()));
65     connect(ui.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveEffect()));
66     connect(ui.buttonReset, SIGNAL(clicked()), this, SLOT(slotResetEffect()));
67     connect(this, SIGNAL(transferParamDesc(const QDomElement&, int , int)), effectedit , SLOT(transferParamDesc(const QDomElement&, int , int)));
68     connect(effectedit, SIGNAL(parameterChanged(const QDomElement&, const QDomElement&)), this , SLOT(slotUpdateEffectParams(const QDomElement&, const QDomElement&)));
69     effectLists["audio"] = &MainWindow::audioEffects;
70     effectLists["video"] = &MainWindow::videoEffects;
71     effectLists["custom"] = &MainWindow::customEffects;
72     ui.splitter->setStretchFactor(1, 10);
73     ui.splitter->setStretchFactor(0, 1);
74     setEnabled(false);
75 }
76
77 void EffectStackView::setMenu(QMenu *menu) {
78     ui.buttonNew->setMenu(menu);
79 }
80
81 void EffectStackView::updateProjectFormat(MltVideoProfile profile, Timecode t) {
82     effectedit->updateProjectFormat(profile, t);
83 }
84
85 void EffectStackView::slotSaveEffect() {
86     QString name = QInputDialog::getText(this, i18n("Save Effect"), i18n("Name for saved effect: "));
87     if (name.isEmpty()) return;
88     QString path = KStandardDirs::locateLocal("appdata", "effects/", true);
89     path = path + name + ".xml";
90     if (QFile::exists(path)) if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it?")) == KMessageBox::No) return;
91
92     int i = ui.effectlist->currentRow();
93     QDomDocument doc;
94     QDomElement effect = clipref->effectAt(i).cloneNode().toElement();
95     doc.appendChild(doc.importNode(effect, true));
96     effect = doc.firstChild().toElement();
97     effect.removeAttribute("kdenlive_ix");
98     effect.setAttribute("id", name);
99     effect.setAttribute("type", "custom");
100     QDomElement effectname = effect.firstChildElement("name");
101     effect.removeChild(effectname);
102     effectname = doc.createElement("name");
103     QDomText nametext = doc.createTextNode(name);
104     effectname.appendChild(nametext);
105     effect.insertBefore(effectname, QDomNode());
106     QDomElement effectprops = effect.firstChildElement("properties");
107     effectprops.setAttribute("id", name);
108     effectprops.setAttribute("type", "custom");
109
110
111     QFile file(path);
112     if (file.open(QFile::WriteOnly | QFile::Truncate)) {
113         QTextStream out(&file);
114         out << doc.toString();
115     }
116     file.close();
117     emit reloadEffects();
118 }
119
120 void EffectStackView::slotUpdateEffectParams(const QDomElement& old, const QDomElement& e) {
121     if (clipref)
122         emit updateClipEffect(clipref, old, e, ui.effectlist->currentRow());
123 }
124
125 void EffectStackView::slotClipItemSelected(ClipItem* c, int ix) {
126     if (c && c == clipref) {
127         if (ix == -1) ix = ui.effectlist->currentRow();
128     } else {
129         clipref = c;
130         if (c) ix = c->selectedEffectIndex();
131         else ix = 0;
132     }
133     if (clipref == NULL) {
134         ui.effectlist->clear();
135         effectedit->transferParamDesc(QDomElement(), 0, 0);
136         setEnabled(false);
137         return;
138     }
139     setEnabled(true);
140     setupListView(ix);
141 }
142
143 void EffectStackView::slotItemChanged(QListWidgetItem *item) {
144     bool disable = true;
145     if (item->checkState() == Qt::Checked) disable = false;
146     ui.buttonReset->setEnabled(!disable);
147     int activeRow = ui.effectlist->currentRow();
148     if (activeRow >= 0) {
149         emit changeEffectState(clipref, activeRow, disable);
150     }
151 }
152
153
154 void EffectStackView::setupListView(int ix) {
155     ui.effectlist->clear();
156
157     // Issue 238: Add icons for effect type in effectstack.
158     KIcon videoIcon("kdenlive-show-video");
159     KIcon audioIcon("kdenlive-show-audio");
160     QListWidgetItem* item;
161
162     for (int i = 0;i < clipref->effectsCount();i++) {
163         QDomElement d = clipref->effectAt(i);
164
165         QDomNode namenode = d.elementsByTagName("name").item(0);
166         if (!namenode.isNull()) {
167             // Issue 238: Add icons for effect type in effectstack.
168             // Logic more or less copied from initeffects.cpp
169             QString type = d.attribute("type", QString());
170             if ("audio" == type) {
171                 item = new QListWidgetItem(audioIcon, i18n(namenode.toElement().text().toUtf8().data()), ui.effectlist);
172             } else if ("custom" == type) {
173                 item = new QListWidgetItem(i18n(namenode.toElement().text().toUtf8().data()), ui.effectlist);
174             } else {
175                 item = new QListWidgetItem(videoIcon, i18n(namenode.toElement().text().toUtf8().data()), ui.effectlist);
176             }
177             item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
178             if (d.attribute("disabled") == "1") item->setCheckState(Qt::Unchecked);
179             else item->setCheckState(Qt::Checked);
180         }
181     }
182     if (clipref->effectsCount() == 0) {
183         emit transferParamDesc(QDomElement(), 0, 0);
184         ui.buttonDel->setEnabled(false);
185         ui.buttonSave->setEnabled(false);
186         ui.buttonReset->setEnabled(false);
187         ui.buttonUp->setEnabled(false);
188         ui.buttonDown->setEnabled(false);
189     } else {
190         if (ix < 0) ix = 0;
191         if (ix > ui.effectlist->count() - 1) ix = ui.effectlist->count() - 1;
192         ui.effectlist->setCurrentRow(ix);
193         ui.buttonDel->setEnabled(true);
194         ui.buttonSave->setEnabled(true);
195         ui.buttonReset->setEnabled(true);
196         ui.buttonUp->setEnabled(ix > 0);
197         ui.buttonDown->setEnabled(ix < clipref->effectsCount() - 1);
198     }
199 }
200
201 void EffectStackView::slotItemSelectionChanged() {
202     bool hasItem = ui.effectlist->currentItem();
203     int activeRow = ui.effectlist->currentRow();
204     bool isChecked = false;
205     if (hasItem && ui.effectlist->currentItem()->checkState() == Qt::Checked) isChecked = true;
206     if (hasItem && ui.effectlist->currentItem()->isSelected()) {
207         emit transferParamDesc(clipref->effectAt(activeRow), clipref->cropStart().frames(KdenliveSettings::project_fps()), clipref->cropDuration().frames(KdenliveSettings::project_fps()));//minx max frame
208     }
209     if (clipref) clipref->setSelectedEffect(activeRow);
210     ui.buttonDel->setEnabled(hasItem);
211     ui.buttonSave->setEnabled(hasItem);
212     ui.buttonReset->setEnabled(hasItem && isChecked);
213     ui.buttonUp->setEnabled(activeRow > 0);
214     ui.buttonDown->setEnabled((activeRow < ui.effectlist->count() - 1) && hasItem);
215 }
216
217 void EffectStackView::slotItemUp() {
218     int activeRow = ui.effectlist->currentRow();
219     if (activeRow <= 0) return;
220     emit changeEffectPosition(clipref, activeRow + 1, activeRow);
221 }
222
223 void EffectStackView::slotItemDown() {
224     int activeRow = ui.effectlist->currentRow();
225     if (activeRow >= ui.effectlist->count() - 1) return;
226     emit changeEffectPosition(clipref, activeRow + 1, activeRow + 2);
227 }
228
229 void EffectStackView::slotItemDel() {
230     int activeRow = ui.effectlist->currentRow();
231     if (activeRow >= 0) {
232         emit removeEffect(clipref, clipref->effectAt(activeRow));
233     }
234 }
235
236 void EffectStackView::slotResetEffect() {
237     int activeRow = ui.effectlist->currentRow();
238     if (activeRow < 0) return;
239     QDomElement old = clipref->effectAt(activeRow).cloneNode().toElement();
240     QDomElement dom;
241     QString effectName = ui.effectlist->currentItem()->text();
242     foreach(const QString &type, effectLists.keys()) {
243         EffectsList *list = effectLists[type];
244         if (list->effectNames().contains(effectName)) {
245             dom = list->getEffectByName(effectName);
246             break;
247         }
248     }
249     if (!dom.isNull()) {
250         dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
251         emit transferParamDesc(dom, clipref->cropStart().frames(KdenliveSettings::project_fps()), clipref->cropDuration().frames(KdenliveSettings::project_fps()));//minx max frame
252         emit updateClipEffect(clipref, old, dom, activeRow);
253     }
254 }
255
256
257 void EffectStackView::raiseWindow(QWidget* dock) {
258     if (clipref && dock)
259         dock->raise();
260 }
261
262 void EffectStackView::clear() {
263     ui.effectlist->clear();
264     ui.buttonDel->setEnabled(false);
265     ui.buttonSave->setEnabled(false);
266     ui.buttonReset->setEnabled(false);
267     ui.buttonUp->setEnabled(false);
268     ui.buttonDown->setEnabled(false);
269     effectedit->transferParamDesc(QDomElement(), 0, 0);
270 }
271
272 #include "effectstackview.moc"