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)), this , SLOT(slotStartFilterJob(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)));
99 connect(monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
100 connect(this, SIGNAL(showComments(bool)), m_effectedit, SIGNAL(showComments(bool)));
101 m_effectLists["audio"] = &MainWindow::audioEffects;
102 m_effectLists["video"] = &MainWindow::videoEffects;
103 m_effectLists["custom"] = &MainWindow::customEffects;
107 EffectStackView::~EffectStackView()
109 m_effectLists.clear();
113 void EffectStackView::updateTimecodeFormat()
115 m_effectedit->updateTimecodeFormat();
118 void EffectStackView::setMenu(QMenu *menu)
120 m_ui.buttonNew->setMenu(menu);
123 void EffectStackView::updateProjectFormat(MltVideoProfile profile, Timecode t)
125 m_effectedit->updateProjectFormat(profile, t);
128 void EffectStackView::slotSaveEffect()
130 QString name = QInputDialog::getText(this, i18n("Save Effect"), i18n("Name for saved effect: "));
131 if (name.isEmpty()) return;
132 QString path = KStandardDirs::locateLocal("appdata", "effects/", true);
133 path = path + name + ".xml";
134 if (QFile::exists(path)) if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", path)) == KMessageBox::No) return;
136 int i = m_ui.effectlist->currentRow();
138 QDomElement effect = m_currentEffectList.at(i).cloneNode().toElement();
139 doc.appendChild(doc.importNode(effect, true));
140 effect = doc.firstChild().toElement();
141 effect.removeAttribute("kdenlive_ix");
142 effect.setAttribute("id", name);
143 effect.setAttribute("type", "custom");
144 QDomElement effectname = effect.firstChildElement("name");
145 effect.removeChild(effectname);
146 effectname = doc.createElement("name");
147 QDomText nametext = doc.createTextNode(name);
148 effectname.appendChild(nametext);
149 effect.insertBefore(effectname, QDomNode());
150 QDomElement effectprops = effect.firstChildElement("properties");
151 effectprops.setAttribute("id", name);
152 effectprops.setAttribute("type", "custom");
155 if (file.open(QFile::WriteOnly | QFile::Truncate)) {
156 QTextStream out(&file);
157 out << doc.toString();
160 emit reloadEffects();
163 void EffectStackView::slotUpdateEffectParams(const QDomElement &old, const QDomElement &e)
166 emit updateEffect(NULL, m_trackindex, old, e, m_ui.effectlist->currentRow());
168 emit updateEffect(m_clipref, -1, old, e, m_ui.effectlist->currentRow());
171 void EffectStackView::slotClipItemSelected(ClipItem* c, int ix)
173 if (c && !c->isEnabled()) return;
174 if (c && c == m_clipref) {
175 if (ix == -1) ix = m_ui.effectlist->currentRow();
176 //if (ix == -1 || ix == m_ui.effectlist->currentRow()) return;
180 QString cname = m_clipref->clipName();
181 if (cname.length() > 30) {
182 m_ui.checkAll->setToolTip(i18n("Effects for %1").arg(cname));
184 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "...");
186 m_ui.checkAll->setToolTip(QString());
187 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
189 ix = c->selectedEffectIndex();
190 QString size = c->baseClip()->getProperty("frame_size");
191 double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
192 QPoint p((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
193 m_effectedit->setFrameSize(p);
198 if (m_clipref == NULL) {
199 m_ui.effectlist->blockSignals(true);
200 m_ui.effectlist->clear();
202 m_effectedit->transferParamDesc(QDomElement(), info);
203 //m_ui.region_url->clear();
204 m_ui.effectlist->blockSignals(false);
205 m_ui.checkAll->setToolTip(QString());
206 m_ui.checkAll->setText(QString());
207 m_ui.labelComment->setText(QString());
213 m_currentEffectList = m_clipref->effectList();
217 void EffectStackView::slotTrackItemSelected(int ix, const TrackInfo info)
221 m_currentEffectList = info.effectsList;
223 kDebug() << "// TRACK; " << ix << ", EFFECTS: " << m_currentEffectList.count();
225 m_ui.checkAll->setToolTip(QString());
226 m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
231 void EffectStackView::slotItemChanged(QListWidgetItem *item)
234 if (item->checkState() == Qt::Checked) disable = false;
235 m_ui.buttonReset->setEnabled(!disable || !KdenliveSettings::disable_effect_parameters());
236 int activeRow = m_ui.effectlist->currentRow();
237 if (activeRow >= 0) {
238 m_effectedit->updateParameter("disable", QString::number((int) disable));
240 emit changeEffectState(NULL, m_trackindex, activeRow, disable);
242 emit changeEffectState(m_clipref, -1, activeRow, disable);
244 slotUpdateCheckAllButton();
248 void EffectStackView::setupListView(int ix)
250 m_ui.effectlist->blockSignals(true);
251 m_ui.effectlist->clear();
253 // Issue 238: Add icons for effect type in effectstack.
254 KIcon videoIcon("kdenlive-show-video");
255 KIcon audioIcon("kdenlive-show-audio");
256 KIcon customIcon("kdenlive-custom-effect");
257 QListWidgetItem* item;
259 for (int i = 0; i < m_currentEffectList.count(); i++) {
260 const QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
262 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
267 doc.appendChild(doc.importNode(d, true));
268 kDebug() << "IMPORTED STK: " << doc.toString();*/
270 QDomElement namenode = d.firstChildElement("name");
271 if (!namenode.isNull()) {
272 // Issue 238: Add icons for effect type in effectstack.
273 // Logic more or less copied from initeffects.cpp
274 QString type = d.attribute("type", QString());
275 if ("audio" == type) {
276 item = new QListWidgetItem(audioIcon, i18n(namenode.text().toUtf8().data()), m_ui.effectlist);
277 } else if ("custom" == type) {
278 item = new QListWidgetItem(customIcon, i18n(namenode.text().toUtf8().data()), m_ui.effectlist);
280 item = new QListWidgetItem(videoIcon, i18n(namenode.text().toUtf8().data()), m_ui.effectlist);
282 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
283 if (d.attribute("disable") == "1")
284 item->setCheckState(Qt::Unchecked);
286 item->setCheckState(Qt::Checked);
289 if (m_ui.effectlist->count() == 0) {
290 m_ui.buttonDel->setEnabled(false);
291 m_ui.buttonSave->setEnabled(false);
292 m_ui.buttonReset->setEnabled(false);
293 m_ui.buttonUp->setEnabled(false);
294 m_ui.buttonDown->setEnabled(false);
295 m_ui.checkAll->setEnabled(false);
296 m_ui.buttonShowComments->setEnabled(false);
297 m_ui.labelComment->setHidden(true);
299 ix = qBound(0, ix, m_ui.effectlist->count() - 1);
300 m_ui.effectlist->setCurrentRow(ix);
301 m_ui.checkAll->setEnabled(true);
303 m_ui.effectlist->blockSignals(false);
304 if (m_ui.effectlist->count() == 0) {
306 m_effectedit->transferParamDesc(QDomElement(), info);
307 //m_ui.region_url->clear();
308 } else slotItemSelectionChanged(false);
309 slotUpdateCheckAllButton();
312 void EffectStackView::slotItemSelectionChanged(bool update)
314 bool hasItem = m_ui.effectlist->currentItem();
315 int activeRow = m_ui.effectlist->currentRow();
316 bool isChecked = false;
317 if (hasItem && m_ui.effectlist->currentItem()->checkState() == Qt::Checked) isChecked = true;
319 if (hasItem && m_ui.effectlist->currentItem()->isSelected()) {
320 eff = m_currentEffectList.at(activeRow);
322 // showing track effects
324 info.track = m_trackInfo.type;
325 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
326 info.cropStart = GenTime(0);
327 info.startPos = GenTime(-1);
329 m_effectedit->transferParamDesc(eff, info);
331 m_effectedit->transferParamDesc(eff, m_clipref->info());
333 //m_ui.region_url->setUrl(KUrl(eff.attribute("region")));
334 m_ui.labelComment->setText(i18n(eff.firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
336 if (!m_trackMode && m_clipref && update) m_clipref->setSelectedEffect(activeRow);
337 m_ui.buttonDel->setEnabled(hasItem);
338 m_ui.buttonSave->setEnabled(hasItem);
339 m_ui.buttonReset->setEnabled(hasItem && (isChecked || !KdenliveSettings::disable_effect_parameters()));
340 m_ui.buttonUp->setEnabled(activeRow > 0);
341 m_ui.buttonDown->setEnabled((activeRow < m_ui.effectlist->count() - 1) && hasItem);
342 m_ui.buttonShowComments->setEnabled(hasItem);
344 emit showComments(m_ui.buttonShowComments->isChecked());
345 m_ui.labelComment->setVisible(hasItem && m_ui.labelComment->text().count() && (m_ui.buttonShowComments->isChecked() || !eff.elementsByTagName("parameter").count()));
348 void EffectStackView::slotItemUp()
350 int activeRow = m_ui.effectlist->currentRow();
351 if (activeRow <= 0) return;
352 if (m_trackMode) emit changeEffectPosition(NULL, m_trackindex, activeRow + 1, activeRow);
353 else emit changeEffectPosition(m_clipref, -1, activeRow + 1, activeRow);
356 void EffectStackView::slotItemDown()
358 int activeRow = m_ui.effectlist->currentRow();
359 if (activeRow >= m_ui.effectlist->count() - 1) return;
360 if (m_trackMode) emit changeEffectPosition(NULL, m_trackindex, activeRow + 1, activeRow + 2);
361 else emit changeEffectPosition(m_clipref, -1, activeRow + 1, activeRow + 2);
364 void EffectStackView::slotItemDel()
366 int activeRow = m_ui.effectlist->currentRow();
367 if (activeRow >= 0) {
369 emit removeEffect(NULL, m_trackindex, m_currentEffectList.at(activeRow).cloneNode().toElement());
371 emit removeEffect(m_clipref, -1, m_clipref->effectAt(activeRow));
372 slotUpdateCheckAllButton();
376 void EffectStackView::slotResetEffect()
378 int activeRow = m_ui.effectlist->currentRow();
379 if (activeRow < 0) return;
380 QDomElement old = m_currentEffectList.at(activeRow).cloneNode().toElement();
382 QString effectName = m_ui.effectlist->currentItem()->text();
383 foreach(const QString &type, m_effectLists.keys()) {
384 EffectsList *list = m_effectLists[type];
385 if (list->effectNames().contains(effectName)) {
386 dom = list->getEffectByName(effectName).cloneNode().toElement();
391 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
393 EffectsList::setParameter(dom, "in", QString::number(0));
394 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
396 info.track = m_trackInfo.type;
397 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
398 info.cropStart = GenTime(0);
399 info.startPos = GenTime(-1);
401 m_effectedit->transferParamDesc(dom, info);
402 emit updateEffect(NULL, m_trackindex, old, dom, activeRow);
404 m_clipref->initEffect(dom);
405 m_effectedit->transferParamDesc(dom, m_clipref->info());
406 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
407 emit updateEffect(m_clipref, -1, old, dom, activeRow);
411 emit showComments(m_ui.buttonShowComments->isChecked());
412 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || !m_ui.labelComment->text().count());
416 void EffectStackView::raiseWindow(QWidget* dock)
418 if ((m_clipref || m_trackMode) && dock)
422 void EffectStackView::clear()
424 m_ui.effectlist->blockSignals(true);
425 m_ui.effectlist->clear();
426 m_ui.buttonDel->setEnabled(false);
427 m_ui.buttonSave->setEnabled(false);
428 m_ui.buttonReset->setEnabled(false);
429 m_ui.buttonUp->setEnabled(false);
430 m_ui.buttonDown->setEnabled(false);
431 m_ui.checkAll->setEnabled(false);
433 m_effectedit->transferParamDesc(QDomElement(), info);
434 //m_ui.region_url->clear();
436 m_ui.buttonShowComments->setEnabled(false);
437 m_ui.labelComment->setText(QString());
438 m_ui.effectlist->blockSignals(false);
442 void EffectStackView::slotSeekTimeline(int pos)
445 emit seekTimeline(pos);
446 } else if (m_clipref) {
447 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
451 void EffectStackView::slotUpdateCheckAllButton()
453 bool hasEnabled = false;
454 bool hasDisabled = false;
455 for (int i = 0; i < m_ui.effectlist->count(); ++i) {
456 if (m_ui.effectlist->item(i)->checkState() == Qt::Checked)
462 m_ui.checkAll->blockSignals(true);
463 if (hasEnabled && hasDisabled)
464 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
466 m_ui.checkAll->setCheckState(Qt::Checked);
468 m_ui.checkAll->setCheckState(Qt::Unchecked);
469 m_ui.checkAll->blockSignals(false);
472 void EffectStackView::slotCheckAll(int state)
476 m_ui.checkAll->blockSignals(true);
477 m_ui.checkAll->setCheckState(Qt::Checked);
478 m_ui.checkAll->blockSignals(false);
481 bool disabled = (state != 2);
482 m_effectedit->updateParameter("disable", QString::number((int) disabled));
483 for (int i = 0; i < m_ui.effectlist->count(); ++i) {
484 if (m_ui.effectlist->item(i)->checkState() != (Qt::CheckState)state) {
485 m_ui.effectlist->item(i)->setCheckState((Qt::CheckState)state);
487 emit changeEffectState(NULL, m_trackindex, i, disabled);
489 emit changeEffectState(m_clipref, -1, i, disabled);
494 /*void EffectStackView::slotRegionChanged()
496 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
499 void EffectStackView::slotCheckMonitorPosition(int renderPos)
501 if (m_trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
502 if (!m_monitor->getEffectEdit()->getScene()->views().at(0)->isVisible())
503 m_monitor->slotEffectScene(true);
505 m_monitor->slotEffectScene(false);
509 void EffectStackView::slotRenderPos(int pos)
513 m_effectedit->slotSyncEffectsPos(pos);
514 } else if (m_clipref) {
515 m_effectedit->slotSyncEffectsPos(pos - m_clipref->startPos().frames(KdenliveSettings::project_fps()));
520 int EffectStackView::isTrackMode(bool *ok) const
526 void EffectStackView::slotShowComments()
528 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || !m_ui.labelComment->text().count());
529 emit showComments(m_ui.buttonShowComments->isChecked());
532 void EffectStackView::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&consumer, const QString&consumerParams, const QString&properties)
534 if (!m_clipref) return;
535 emit startFilterJob(m_clipref->clipProducer(), filterName, filterParams, consumer, consumerParams, properties);
538 #include "effectstackview.moc"