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 ***************************************************************************/
19 #include "effectstackview.h"
20 #include "effectslist.h"
22 #include "mainwindow.h"
23 #include "docclipbase.h"
24 #include "projectlist.h"
26 #include "monitoreditwidget.h"
27 #include "monitorscene.h"
28 #include "kdenlivesettings.h"
32 #include <KMessageBox>
33 #include <KStandardDirs>
34 #include <KFileDialog>
37 #include <QTextStream>
39 #include <QInputDialog>
42 EffectStackView::EffectStackView(Monitor *monitor, QWidget *parent) :
50 QVBoxLayout *vbox1 = new QVBoxLayout(m_ui.frame);
51 m_effectedit = new EffectStackEdit(monitor, m_ui.frame);
52 m_ui.frame->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
53 vbox1->setContentsMargins(2, 0, 2, 0);
55 vbox1->addWidget(m_effectedit);
56 m_ui.splitter->setStretchFactor(0, 1);
57 m_ui.splitter->setStretchFactor(1, 20);
59 //m_ui.region_url->fileDialog()->setFilter(ProjectList::getExtensions());
60 //m_ui.effectlist->horizontalHeader()->setVisible(false);
61 //m_ui.effectlist->verticalHeader()->setVisible(false);
63 m_ui.buttonNew->setIcon(KIcon("document-new"));
64 m_ui.buttonNew->setToolTip(i18n("Add new effect"));
65 m_ui.buttonUp->setIcon(KIcon("go-up"));
66 m_ui.buttonUp->setToolTip(i18n("Move effect up"));
67 m_ui.buttonDown->setIcon(KIcon("go-down"));
68 m_ui.buttonDown->setToolTip(i18n("Move effect down"));
69 m_ui.buttonDel->setIcon(KIcon("edit-delete"));
70 m_ui.buttonDel->setToolTip(i18n("Delete effect"));
71 m_ui.buttonSave->setIcon(KIcon("document-save"));
72 m_ui.buttonSave->setToolTip(i18n("Save effect"));
73 m_ui.buttonReset->setIcon(KIcon("view-refresh"));
74 m_ui.buttonReset->setToolTip(i18n("Reset effect"));
75 m_ui.checkAll->setToolTip(i18n("Enable/Disable all effects"));
76 m_ui.buttonShowComments->setIcon(KIcon("help-about"));
77 m_ui.buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
79 m_ui.effectlist->setDragDropMode(QAbstractItemView::NoDragDrop); //use internal if drop is recognised right
81 m_ui.labelComment->setHidden(true);
83 //connect(m_ui.region_url, SIGNAL(urlSelected(const KUrl &)), this , SLOT(slotRegionChanged()));
84 //connect(m_ui.region_url, SIGNAL(returnPressed()), this , SLOT(slotRegionChanged()));
85 connect(m_ui.effectlist, SIGNAL(itemSelectionChanged()), this , SLOT(slotItemSelectionChanged()));
86 connect(m_ui.effectlist, SIGNAL(itemChanged(QListWidgetItem *)), this , SLOT(slotItemChanged(QListWidgetItem *)));
87 connect(m_ui.buttonUp, SIGNAL(clicked()), this, SLOT(slotItemUp()));
88 connect(m_ui.buttonDown, SIGNAL(clicked()), this, SLOT(slotItemDown()));
89 connect(m_ui.buttonDel, SIGNAL(clicked()), this, SLOT(slotItemDel()));
90 connect(m_ui.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveEffect()));
91 connect(m_ui.buttonReset, SIGNAL(clicked()), this, SLOT(slotResetEffect()));
92 connect(m_ui.checkAll, SIGNAL(stateChanged(int)), this, SLOT(slotCheckAll(int)));
93 connect(m_ui.buttonShowComments, SIGNAL(clicked()), this, SLOT(slotShowComments()));
94 connect(m_effectedit, SIGNAL(parameterChanged(const QDomElement &, const QDomElement &)), this , SLOT(slotUpdateEffectParams(const QDomElement &, const QDomElement &)));
95 connect(m_effectedit, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,QString,QString)));
96 connect(m_effectedit, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
97 connect(m_effectedit, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
98 connect(m_effectedit, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
100 connect(monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
101 connect(this, SIGNAL(showComments(bool)), m_effectedit, SIGNAL(showComments(bool)));
102 m_effectLists["audio"] = &MainWindow::audioEffects;
103 m_effectLists["video"] = &MainWindow::videoEffects;
104 m_effectLists["custom"] = &MainWindow::customEffects;
108 EffectStackView::~EffectStackView()
110 m_effectLists.clear();
114 void EffectStackView::updateTimecodeFormat()
116 m_effectedit->updateTimecodeFormat();
119 void EffectStackView::setMenu(QMenu *menu)
121 m_ui.buttonNew->setMenu(menu);
124 void EffectStackView::updateProjectFormat(MltVideoProfile profile, Timecode t)
126 m_effectedit->updateProjectFormat(profile, t);
129 void EffectStackView::slotSaveEffect()
131 QString name = QInputDialog::getText(this, i18n("Save Effect"), i18n("Name for saved effect: "));
132 if (name.isEmpty()) return;
133 QString path = KStandardDirs::locateLocal("appdata", "effects/", true);
134 path = path + name + ".xml";
135 if (QFile::exists(path)) if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", path)) == KMessageBox::No) return;
137 int i = m_ui.effectlist->currentRow();
139 QDomElement effect = m_currentEffectList.at(i).cloneNode().toElement();
140 doc.appendChild(doc.importNode(effect, true));
141 effect = doc.firstChild().toElement();
142 effect.removeAttribute("kdenlive_ix");
143 effect.setAttribute("id", name);
144 effect.setAttribute("type", "custom");
145 QDomElement effectname = effect.firstChildElement("name");
146 effect.removeChild(effectname);
147 effectname = doc.createElement("name");
148 QDomText nametext = doc.createTextNode(name);
149 effectname.appendChild(nametext);
150 effect.insertBefore(effectname, QDomNode());
151 QDomElement effectprops = effect.firstChildElement("properties");
152 effectprops.setAttribute("id", name);
153 effectprops.setAttribute("type", "custom");
156 if (file.open(QFile::WriteOnly | QFile::Truncate)) {
157 QTextStream out(&file);
158 out << doc.toString();
161 emit reloadEffects();
164 void EffectStackView::slotUpdateEffectParams(const QDomElement &old, const QDomElement &e)
167 emit updateEffect(NULL, m_trackindex, old, e, m_ui.effectlist->currentRow());
169 emit updateEffect(m_clipref, -1, old, e, m_ui.effectlist->currentRow());
172 void EffectStackView::slotClipItemSelected(ClipItem* c, int ix)
174 if (c && !c->isEnabled()) return;
175 if (c && c == m_clipref) {
176 if (ix == -1) ix = m_ui.effectlist->currentRow();
177 //if (ix == -1 || ix == m_ui.effectlist->currentRow()) return;
181 QString cname = m_clipref->clipName();
182 if (cname.length() > 30) {
183 m_ui.checkAll->setToolTip(i18n("Effects for %1").arg(cname));
185 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "...");
187 m_ui.checkAll->setToolTip(QString());
188 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
190 ix = c->selectedEffectIndex();
191 QString size = c->baseClip()->getProperty("frame_size");
192 double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
193 QPoint p((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
194 m_effectedit->setFrameSize(p);
199 if (m_clipref == NULL) {
200 m_ui.effectlist->blockSignals(true);
201 m_ui.effectlist->clear();
203 m_effectedit->transferParamDesc(QDomElement(), info);
204 //m_ui.region_url->clear();
205 m_ui.effectlist->blockSignals(false);
206 m_ui.checkAll->setToolTip(QString());
207 m_ui.checkAll->setText(QString());
208 m_ui.labelComment->setText(QString());
214 m_currentEffectList = m_clipref->effectList();
218 void EffectStackView::slotTrackItemSelected(int ix, const TrackInfo info)
222 m_currentEffectList = info.effectsList;
224 kDebug() << "// TRACK; " << ix << ", EFFECTS: " << m_currentEffectList.count();
226 m_ui.checkAll->setToolTip(QString());
227 m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
232 void EffectStackView::slotItemChanged(QListWidgetItem *item)
234 bool disable = item->checkState() == Qt::Unchecked;
235 int row = m_ui.effectlist->row(item);
236 int activeRow = m_ui.effectlist->currentRow();
238 if (row == activeRow) {
239 m_ui.buttonReset->setEnabled(!disable || !KdenliveSettings::disable_effect_parameters());
240 m_effectedit->updateParameter("disable", QString::number((int) disable));
244 emit changeEffectState(NULL, m_trackindex, row, disable);
246 emit changeEffectState(m_clipref, -1, row, disable);
248 slotUpdateCheckAllButton();
252 void EffectStackView::setupListView(int ix)
254 m_ui.effectlist->blockSignals(true);
255 m_ui.effectlist->clear();
257 // Issue 238: Add icons for effect type in effectstack.
258 KIcon videoIcon("kdenlive-show-video");
259 KIcon audioIcon("kdenlive-show-audio");
260 KIcon customIcon("kdenlive-custom-effect");
261 QListWidgetItem* item;
263 for (int i = 0; i < m_currentEffectList.count(); i++) {
264 const QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
266 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
271 doc.appendChild(doc.importNode(d, true));
272 kDebug() << "IMPORTED STK: " << doc.toString();*/
274 QDomElement namenode = d.firstChildElement("name");
275 if (!namenode.isNull()) {
276 // Issue 238: Add icons for effect type in effectstack.
277 // Logic more or less copied from initeffects.cpp
278 QString type = d.attribute("type", QString());
279 if ("audio" == type) {
280 item = new QListWidgetItem(audioIcon, i18n(namenode.text().toUtf8().data()), m_ui.effectlist);
281 } else if ("custom" == type) {
282 item = new QListWidgetItem(customIcon, i18n(namenode.text().toUtf8().data()), m_ui.effectlist);
284 item = new QListWidgetItem(videoIcon, i18n(namenode.text().toUtf8().data()), m_ui.effectlist);
286 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
287 if (d.attribute("disable") == "1")
288 item->setCheckState(Qt::Unchecked);
290 item->setCheckState(Qt::Checked);
293 if (m_ui.effectlist->count() == 0) {
294 m_ui.buttonDel->setEnabled(false);
295 m_ui.buttonSave->setEnabled(false);
296 m_ui.buttonReset->setEnabled(false);
297 m_ui.buttonUp->setEnabled(false);
298 m_ui.buttonDown->setEnabled(false);
299 m_ui.checkAll->setEnabled(false);
300 m_ui.buttonShowComments->setEnabled(false);
301 m_ui.labelComment->setHidden(true);
303 ix = qBound(0, ix, m_ui.effectlist->count() - 1);
304 m_ui.effectlist->setCurrentRow(ix);
305 m_ui.checkAll->setEnabled(true);
307 m_ui.effectlist->blockSignals(false);
308 if (m_ui.effectlist->count() == 0) {
310 m_effectedit->transferParamDesc(QDomElement(), info);
311 //m_ui.region_url->clear();
312 } else slotItemSelectionChanged(false);
313 slotUpdateCheckAllButton();
316 void EffectStackView::slotItemSelectionChanged(bool update)
318 bool hasItem = m_ui.effectlist->currentItem();
319 int activeRow = m_ui.effectlist->currentRow();
320 bool isChecked = false;
321 if (hasItem && m_ui.effectlist->currentItem()->checkState() == Qt::Checked) isChecked = true;
323 if (hasItem && m_ui.effectlist->currentItem()->isSelected()) {
324 eff = m_currentEffectList.at(activeRow);
326 // showing track effects
328 info.track = m_trackInfo.type;
329 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
330 info.cropStart = GenTime(0);
331 info.startPos = GenTime(-1);
333 m_effectedit->transferParamDesc(eff, info);
335 m_effectedit->transferParamDesc(eff, m_clipref->info());
337 //m_ui.region_url->setUrl(KUrl(eff.attribute("region")));
338 m_ui.labelComment->setText(i18n(eff.firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
340 if (!m_trackMode && m_clipref && update) m_clipref->setSelectedEffect(activeRow);
341 m_ui.buttonDel->setEnabled(hasItem);
342 m_ui.buttonSave->setEnabled(hasItem);
343 m_ui.buttonReset->setEnabled(hasItem && (isChecked || !KdenliveSettings::disable_effect_parameters()));
344 m_ui.buttonUp->setEnabled(activeRow > 0);
345 m_ui.buttonDown->setEnabled((activeRow < m_ui.effectlist->count() - 1) && hasItem);
346 m_ui.buttonShowComments->setEnabled(hasItem);
348 emit showComments(m_ui.buttonShowComments->isChecked());
349 m_ui.labelComment->setVisible(hasItem && m_ui.labelComment->text().count() && (m_ui.buttonShowComments->isChecked() || !eff.elementsByTagName("parameter").count()));
352 void EffectStackView::slotItemUp()
354 int activeRow = m_ui.effectlist->currentRow();
355 if (activeRow <= 0) return;
356 if (m_trackMode) emit changeEffectPosition(NULL, m_trackindex, activeRow + 1, activeRow);
357 else emit changeEffectPosition(m_clipref, -1, activeRow + 1, activeRow);
360 void EffectStackView::slotItemDown()
362 int activeRow = m_ui.effectlist->currentRow();
363 if (activeRow >= m_ui.effectlist->count() - 1) return;
364 if (m_trackMode) emit changeEffectPosition(NULL, m_trackindex, activeRow + 1, activeRow + 2);
365 else emit changeEffectPosition(m_clipref, -1, activeRow + 1, activeRow + 2);
368 void EffectStackView::slotItemDel()
370 int activeRow = m_ui.effectlist->currentRow();
371 if (activeRow >= 0) {
373 emit removeEffect(NULL, m_trackindex, m_currentEffectList.at(activeRow).cloneNode().toElement());
375 emit removeEffect(m_clipref, -1, m_clipref->effectAt(activeRow));
376 slotUpdateCheckAllButton();
380 void EffectStackView::slotResetEffect()
382 int activeRow = m_ui.effectlist->currentRow();
383 if (activeRow < 0) return;
384 QDomElement old = m_currentEffectList.at(activeRow).cloneNode().toElement();
386 QString effectName = m_ui.effectlist->currentItem()->text();
387 foreach(const QString &type, m_effectLists.keys()) {
388 EffectsList *list = m_effectLists[type];
389 if (list->effectNames().contains(effectName)) {
390 dom = list->getEffectByName(effectName).cloneNode().toElement();
395 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
397 EffectsList::setParameter(dom, "in", QString::number(0));
398 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
400 info.track = m_trackInfo.type;
401 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
402 info.cropStart = GenTime(0);
403 info.startPos = GenTime(-1);
405 m_effectedit->transferParamDesc(dom, info);
406 emit updateEffect(NULL, m_trackindex, old, dom, activeRow);
408 m_clipref->initEffect(dom);
409 m_effectedit->transferParamDesc(dom, m_clipref->info());
410 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
411 emit updateEffect(m_clipref, -1, old, dom, activeRow);
415 emit showComments(m_ui.buttonShowComments->isChecked());
416 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || !m_ui.labelComment->text().count());
420 void EffectStackView::raiseWindow(QWidget* dock)
422 if ((m_clipref || m_trackMode) && dock)
426 void EffectStackView::clear()
428 m_ui.effectlist->blockSignals(true);
429 m_ui.effectlist->clear();
430 m_ui.buttonDel->setEnabled(false);
431 m_ui.buttonSave->setEnabled(false);
432 m_ui.buttonReset->setEnabled(false);
433 m_ui.buttonUp->setEnabled(false);
434 m_ui.buttonDown->setEnabled(false);
435 m_ui.checkAll->setEnabled(false);
437 m_effectedit->transferParamDesc(QDomElement(), info);
438 //m_ui.region_url->clear();
440 m_ui.buttonShowComments->setEnabled(false);
441 m_ui.labelComment->setText(QString());
442 m_ui.effectlist->blockSignals(false);
446 void EffectStackView::slotSeekTimeline(int pos)
449 emit seekTimeline(pos);
450 } else if (m_clipref) {
451 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
455 void EffectStackView::slotUpdateCheckAllButton()
457 bool hasEnabled = false;
458 bool hasDisabled = false;
459 for (int i = 0; i < m_ui.effectlist->count(); ++i) {
460 if (m_ui.effectlist->item(i)->checkState() == Qt::Checked)
466 m_ui.checkAll->blockSignals(true);
467 if (hasEnabled && hasDisabled)
468 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
470 m_ui.checkAll->setCheckState(Qt::Checked);
472 m_ui.checkAll->setCheckState(Qt::Unchecked);
473 m_ui.checkAll->blockSignals(false);
476 void EffectStackView::slotCheckAll(int state)
480 m_ui.checkAll->blockSignals(true);
481 m_ui.checkAll->setCheckState(Qt::Checked);
482 m_ui.checkAll->blockSignals(false);
485 bool disabled = (state != 2);
486 m_effectedit->updateParameter("disable", QString::number((int) disabled));
487 for (int i = 0; i < m_ui.effectlist->count(); ++i) {
488 if (m_ui.effectlist->item(i)->checkState() != (Qt::CheckState)state) {
489 m_ui.effectlist->item(i)->setCheckState((Qt::CheckState)state);
491 emit changeEffectState(NULL, m_trackindex, i, disabled);
493 emit changeEffectState(m_clipref, -1, i, disabled);
498 /*void EffectStackView::slotRegionChanged()
500 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
503 void EffectStackView::slotCheckMonitorPosition(int renderPos)
505 if (m_trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
506 if (!m_monitor->getEffectEdit()->getScene()->views().at(0)->isVisible())
507 m_monitor->slotEffectScene(true);
509 m_monitor->slotEffectScene(false);
513 void EffectStackView::slotRenderPos(int pos)
517 m_effectedit->slotSyncEffectsPos(pos);
518 } else if (m_clipref) {
519 m_effectedit->slotSyncEffectsPos(pos - m_clipref->startPos().frames(KdenliveSettings::project_fps()));
524 int EffectStackView::isTrackMode(bool *ok) const
530 void EffectStackView::slotShowComments()
532 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || !m_ui.labelComment->text().count());
533 emit showComments(m_ui.buttonShowComments->isChecked());
536 void EffectStackView::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
538 if (!m_clipref) return;
539 emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, finalFilterName, consumer, consumerParams, properties);
542 #include "effectstackview.moc"