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);
62 int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
63 QSize iconSize(size, size);
65 m_ui.buttonNew->setIcon(KIcon("document-new"));
66 m_ui.buttonNew->setToolTip(i18n("Add new effect"));
67 m_ui.buttonNew->setIconSize(iconSize);
68 m_ui.buttonUp->setIcon(KIcon("go-up"));
69 m_ui.buttonUp->setToolTip(i18n("Move effect up"));
70 m_ui.buttonUp->setIconSize(iconSize);
71 m_ui.buttonDown->setIcon(KIcon("go-down"));
72 m_ui.buttonDown->setToolTip(i18n("Move effect down"));
73 m_ui.buttonDown->setIconSize(iconSize);
74 m_ui.buttonDel->setIcon(KIcon("edit-delete"));
75 m_ui.buttonDel->setToolTip(i18n("Delete effect"));
76 m_ui.buttonDel->setIconSize(iconSize);
77 m_ui.buttonSave->setIcon(KIcon("document-save"));
78 m_ui.buttonSave->setToolTip(i18n("Save effect"));
79 m_ui.buttonSave->setIconSize(iconSize);
80 m_ui.buttonReset->setIcon(KIcon("view-refresh"));
81 m_ui.buttonReset->setToolTip(i18n("Reset effect"));
82 m_ui.buttonReset->setIconSize(iconSize);
83 m_ui.checkAll->setToolTip(i18n("Enable/Disable all effects"));
84 m_ui.buttonShowComments->setIcon(KIcon("help-about"));
85 m_ui.buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
87 m_ui.effectlist->setDragDropMode(QAbstractItemView::NoDragDrop); //use internal if drop is recognised right
89 m_ui.labelComment->setHidden(true);
91 //connect(m_ui.region_url, SIGNAL(urlSelected(const KUrl &)), this , SLOT(slotRegionChanged()));
92 //connect(m_ui.region_url, SIGNAL(returnPressed()), this , SLOT(slotRegionChanged()));
93 connect(m_ui.effectlist, SIGNAL(itemSelectionChanged()), this , SLOT(slotItemSelectionChanged()));
94 connect(m_ui.effectlist, SIGNAL(itemChanged(QListWidgetItem *)), this , SLOT(slotItemChanged(QListWidgetItem *)));
95 connect(m_ui.buttonUp, SIGNAL(clicked()), this, SLOT(slotItemUp()));
96 connect(m_ui.buttonDown, SIGNAL(clicked()), this, SLOT(slotItemDown()));
97 connect(m_ui.buttonDel, SIGNAL(clicked()), this, SLOT(slotItemDel()));
98 connect(m_ui.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveEffect()));
99 connect(m_ui.buttonReset, SIGNAL(clicked()), this, SLOT(slotResetEffect()));
100 connect(m_ui.checkAll, SIGNAL(stateChanged(int)), this, SLOT(slotCheckAll(int)));
101 connect(m_ui.buttonShowComments, SIGNAL(clicked()), this, SLOT(slotShowComments()));
102 connect(m_effectedit, SIGNAL(parameterChanged(const QDomElement &, const QDomElement &)), this , SLOT(slotUpdateEffectParams(const QDomElement &, const QDomElement &)));
103 connect(m_effectedit, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,QString,QString)));
104 connect(m_effectedit, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
105 connect(m_effectedit, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
106 connect(m_effectedit, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
108 connect(monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
109 connect(this, SIGNAL(showComments(bool)), m_effectedit, SIGNAL(showComments(bool)));
110 m_effectLists["audio"] = &MainWindow::audioEffects;
111 m_effectLists["video"] = &MainWindow::videoEffects;
112 m_effectLists["custom"] = &MainWindow::customEffects;
116 EffectStackView::~EffectStackView()
118 m_effectLists.clear();
122 void EffectStackView::updateTimecodeFormat()
124 m_effectedit->updateTimecodeFormat();
127 void EffectStackView::setMenu(QMenu *menu)
129 m_ui.buttonNew->setMenu(menu);
132 void EffectStackView::updateProjectFormat(MltVideoProfile profile, Timecode t)
134 m_effectedit->updateProjectFormat(profile, t);
137 void EffectStackView::slotSaveEffect()
139 QString name = QInputDialog::getText(this, i18n("Save Effect"), i18n("Name for saved effect: "));
140 if (name.isEmpty()) return;
141 QString path = KStandardDirs::locateLocal("appdata", "effects/", true);
142 path = path + name + ".xml";
143 if (QFile::exists(path)) if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", path)) == KMessageBox::No) return;
145 int i = m_ui.effectlist->currentRow();
147 QDomElement effect = m_currentEffectList.at(i).cloneNode().toElement();
148 doc.appendChild(doc.importNode(effect, true));
149 effect = doc.firstChild().toElement();
150 effect.removeAttribute("kdenlive_ix");
151 effect.setAttribute("id", name);
152 effect.setAttribute("type", "custom");
153 QDomElement effectname = effect.firstChildElement("name");
154 effect.removeChild(effectname);
155 effectname = doc.createElement("name");
156 QDomText nametext = doc.createTextNode(name);
157 effectname.appendChild(nametext);
158 effect.insertBefore(effectname, QDomNode());
159 QDomElement effectprops = effect.firstChildElement("properties");
160 effectprops.setAttribute("id", name);
161 effectprops.setAttribute("type", "custom");
164 if (file.open(QFile::WriteOnly | QFile::Truncate)) {
165 QTextStream out(&file);
166 out << doc.toString();
169 emit reloadEffects();
172 void EffectStackView::slotUpdateEffectParams(const QDomElement &old, const QDomElement &e)
175 emit updateEffect(NULL, m_trackindex, old, e, m_ui.effectlist->currentRow());
177 emit updateEffect(m_clipref, -1, old, e, m_ui.effectlist->currentRow());
180 void EffectStackView::slotClipItemSelected(ClipItem* c, int ix)
182 if (c && !c->isEnabled()) return;
183 if (c && c == m_clipref) {
184 if (ix == -1) ix = m_ui.effectlist->currentRow();
185 //if (ix == -1 || ix == m_ui.effectlist->currentRow()) return;
189 QString cname = m_clipref->clipName();
190 if (cname.length() > 30) {
191 m_ui.checkAll->setToolTip(i18n("Effects for %1").arg(cname));
193 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "...");
195 m_ui.checkAll->setToolTip(QString());
196 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
198 ix = c->selectedEffectIndex();
199 QString size = c->baseClip()->getProperty("frame_size");
200 double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
201 QPoint p((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
202 m_effectedit->setFrameSize(p);
207 if (m_clipref == NULL) {
208 m_ui.effectlist->blockSignals(true);
209 m_ui.effectlist->clear();
211 m_effectedit->transferParamDesc(QDomElement(), info);
212 //m_ui.region_url->clear();
213 m_ui.effectlist->blockSignals(false);
214 m_ui.checkAll->setToolTip(QString());
215 m_ui.checkAll->setText(QString());
216 m_ui.labelComment->setText(QString());
222 m_currentEffectList = m_clipref->effectList();
226 void EffectStackView::slotTrackItemSelected(int ix, const TrackInfo info)
230 m_currentEffectList = info.effectsList;
232 kDebug() << "// TRACK; " << ix << ", EFFECTS: " << m_currentEffectList.count();
234 m_ui.checkAll->setToolTip(QString());
235 m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
240 void EffectStackView::slotItemChanged(QListWidgetItem *item)
242 bool disable = item->checkState() == Qt::Unchecked;
243 int row = m_ui.effectlist->row(item);
244 int activeRow = m_ui.effectlist->currentRow();
246 if (row == activeRow) {
247 m_ui.buttonReset->setEnabled(!disable || !KdenliveSettings::disable_effect_parameters());
248 m_effectedit->updateParameter("disable", QString::number((int) disable));
252 emit changeEffectState(NULL, m_trackindex, row, disable);
254 emit changeEffectState(m_clipref, -1, row, disable);
256 slotUpdateCheckAllButton();
260 void EffectStackView::setupListView(int ix)
262 m_ui.effectlist->blockSignals(true);
263 m_ui.effectlist->clear();
265 // Issue 238: Add icons for effect type in effectstack.
266 KIcon videoIcon("kdenlive-show-video");
267 KIcon audioIcon("kdenlive-show-audio");
268 KIcon customIcon("kdenlive-custom-effect");
269 QListWidgetItem* item;
271 for (int i = 0; i < m_currentEffectList.count(); i++) {
272 const QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
274 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
279 doc.appendChild(doc.importNode(d, true));
280 kDebug() << "IMPORTED STK: " << doc.toString();*/
282 QDomElement namenode = d.firstChildElement("name");
283 if (!namenode.isNull()) {
284 // Issue 238: Add icons for effect type in effectstack.
285 // Logic more or less copied from initeffects.cpp
286 QString type = d.attribute("type", QString());
287 if ("audio" == type) {
288 item = new QListWidgetItem(audioIcon, i18n(namenode.text().toUtf8().data()), m_ui.effectlist);
289 } else if ("custom" == type) {
290 item = new QListWidgetItem(customIcon, i18n(namenode.text().toUtf8().data()), m_ui.effectlist);
292 item = new QListWidgetItem(videoIcon, i18n(namenode.text().toUtf8().data()), m_ui.effectlist);
294 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
295 if (d.attribute("disable") == "1")
296 item->setCheckState(Qt::Unchecked);
298 item->setCheckState(Qt::Checked);
301 if (m_ui.effectlist->count() == 0) {
302 m_ui.buttonDel->setEnabled(false);
303 m_ui.buttonSave->setEnabled(false);
304 m_ui.buttonReset->setEnabled(false);
305 m_ui.buttonUp->setEnabled(false);
306 m_ui.buttonDown->setEnabled(false);
307 m_ui.checkAll->setEnabled(false);
308 m_ui.buttonShowComments->setEnabled(false);
309 m_ui.labelComment->setHidden(true);
311 ix = qBound(0, ix, m_ui.effectlist->count() - 1);
312 m_ui.effectlist->setCurrentRow(ix);
313 m_ui.checkAll->setEnabled(true);
315 m_ui.effectlist->blockSignals(false);
316 if (m_ui.effectlist->count() == 0) {
318 m_effectedit->transferParamDesc(QDomElement(), info);
319 //m_ui.region_url->clear();
320 } else slotItemSelectionChanged(false);
321 slotUpdateCheckAllButton();
324 void EffectStackView::slotItemSelectionChanged(bool update)
326 bool hasItem = m_ui.effectlist->currentItem();
327 int activeRow = m_ui.effectlist->currentRow();
328 bool isChecked = false;
329 if (hasItem && m_ui.effectlist->currentItem()->checkState() == Qt::Checked) isChecked = true;
331 if (hasItem && m_ui.effectlist->currentItem()->isSelected()) {
332 eff = m_currentEffectList.at(activeRow);
334 // showing track effects
336 info.track = m_trackInfo.type;
337 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
338 info.cropStart = GenTime(0);
339 info.startPos = GenTime(-1);
341 m_effectedit->transferParamDesc(eff, info);
343 m_effectedit->transferParamDesc(eff, m_clipref->info());
345 //m_ui.region_url->setUrl(KUrl(eff.attribute("region")));
346 m_ui.labelComment->setText(i18n(eff.firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
348 if (!m_trackMode && m_clipref && update) m_clipref->setSelectedEffect(activeRow);
349 m_ui.buttonDel->setEnabled(hasItem);
350 m_ui.buttonSave->setEnabled(hasItem);
351 m_ui.buttonReset->setEnabled(hasItem && (isChecked || !KdenliveSettings::disable_effect_parameters()));
352 m_ui.buttonUp->setEnabled(activeRow > 0);
353 m_ui.buttonDown->setEnabled((activeRow < m_ui.effectlist->count() - 1) && hasItem);
354 m_ui.buttonShowComments->setEnabled(hasItem);
356 emit showComments(m_ui.buttonShowComments->isChecked());
357 m_ui.labelComment->setVisible(hasItem && m_ui.labelComment->text().count() && (m_ui.buttonShowComments->isChecked() || !eff.elementsByTagName("parameter").count()));
360 void EffectStackView::slotItemUp()
362 int activeRow = m_ui.effectlist->currentRow();
363 if (activeRow <= 0) return;
364 if (m_trackMode) emit changeEffectPosition(NULL, m_trackindex, activeRow + 1, activeRow);
365 else emit changeEffectPosition(m_clipref, -1, activeRow + 1, activeRow);
368 void EffectStackView::slotItemDown()
370 int activeRow = m_ui.effectlist->currentRow();
371 if (activeRow >= m_ui.effectlist->count() - 1) return;
372 if (m_trackMode) emit changeEffectPosition(NULL, m_trackindex, activeRow + 1, activeRow + 2);
373 else emit changeEffectPosition(m_clipref, -1, activeRow + 1, activeRow + 2);
376 void EffectStackView::slotItemDel()
378 int activeRow = m_ui.effectlist->currentRow();
379 if (activeRow >= 0) {
381 emit removeEffect(NULL, m_trackindex, m_currentEffectList.at(activeRow).cloneNode().toElement());
383 emit removeEffect(m_clipref, -1, m_clipref->effectAt(activeRow));
384 slotUpdateCheckAllButton();
388 void EffectStackView::slotResetEffect()
390 int activeRow = m_ui.effectlist->currentRow();
391 if (activeRow < 0) return;
392 QDomElement old = m_currentEffectList.at(activeRow).cloneNode().toElement();
394 QString effectName = m_ui.effectlist->currentItem()->text();
395 foreach(const QString &type, m_effectLists.keys()) {
396 EffectsList *list = m_effectLists[type];
397 if (list->effectNames().contains(effectName)) {
398 dom = list->getEffectByName(effectName).cloneNode().toElement();
403 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
405 EffectsList::setParameter(dom, "in", QString::number(0));
406 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
408 info.track = m_trackInfo.type;
409 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
410 info.cropStart = GenTime(0);
411 info.startPos = GenTime(-1);
413 m_effectedit->transferParamDesc(dom, info);
414 emit updateEffect(NULL, m_trackindex, old, dom, activeRow);
416 m_clipref->initEffect(dom);
417 m_effectedit->transferParamDesc(dom, m_clipref->info());
418 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
419 emit updateEffect(m_clipref, -1, old, dom, activeRow);
423 emit showComments(m_ui.buttonShowComments->isChecked());
424 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || !m_ui.labelComment->text().count());
428 void EffectStackView::raiseWindow(QWidget* dock)
430 if ((m_clipref || m_trackMode) && dock)
434 void EffectStackView::clear()
436 m_ui.effectlist->blockSignals(true);
437 m_ui.effectlist->clear();
438 m_ui.buttonDel->setEnabled(false);
439 m_ui.buttonSave->setEnabled(false);
440 m_ui.buttonReset->setEnabled(false);
441 m_ui.buttonUp->setEnabled(false);
442 m_ui.buttonDown->setEnabled(false);
443 m_ui.checkAll->setEnabled(false);
445 m_effectedit->transferParamDesc(QDomElement(), info);
446 //m_ui.region_url->clear();
448 m_ui.buttonShowComments->setEnabled(false);
449 m_ui.labelComment->setText(QString());
450 m_ui.effectlist->blockSignals(false);
454 void EffectStackView::slotSeekTimeline(int pos)
457 emit seekTimeline(pos);
458 } else if (m_clipref) {
459 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
463 void EffectStackView::slotUpdateCheckAllButton()
465 bool hasEnabled = false;
466 bool hasDisabled = false;
467 for (int i = 0; i < m_ui.effectlist->count(); ++i) {
468 if (m_ui.effectlist->item(i)->checkState() == Qt::Checked)
474 m_ui.checkAll->blockSignals(true);
475 if (hasEnabled && hasDisabled)
476 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
478 m_ui.checkAll->setCheckState(Qt::Checked);
480 m_ui.checkAll->setCheckState(Qt::Unchecked);
481 m_ui.checkAll->blockSignals(false);
484 void EffectStackView::slotCheckAll(int state)
488 m_ui.checkAll->blockSignals(true);
489 m_ui.checkAll->setCheckState(Qt::Checked);
490 m_ui.checkAll->blockSignals(false);
493 bool disabled = (state != 2);
494 m_effectedit->updateParameter("disable", QString::number((int) disabled));
495 for (int i = 0; i < m_ui.effectlist->count(); ++i) {
496 if (m_ui.effectlist->item(i)->checkState() != (Qt::CheckState)state) {
497 m_ui.effectlist->item(i)->setCheckState((Qt::CheckState)state);
499 emit changeEffectState(NULL, m_trackindex, i, disabled);
501 emit changeEffectState(m_clipref, -1, i, disabled);
506 /*void EffectStackView::slotRegionChanged()
508 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
511 void EffectStackView::slotCheckMonitorPosition(int renderPos)
513 if (m_trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
514 if (!m_monitor->getEffectEdit()->getScene()->views().at(0)->isVisible())
515 m_monitor->slotEffectScene(true);
517 m_monitor->slotEffectScene(false);
521 void EffectStackView::slotRenderPos(int pos)
525 m_effectedit->slotSyncEffectsPos(pos);
526 } else if (m_clipref) {
527 m_effectedit->slotSyncEffectsPos(pos - m_clipref->startPos().frames(KdenliveSettings::project_fps()));
532 int EffectStackView::isTrackMode(bool *ok) const
538 void EffectStackView::slotShowComments()
540 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || !m_ui.labelComment->text().count());
541 emit showComments(m_ui.buttonShowComments->isChecked());
544 void EffectStackView::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
546 if (!m_clipref) return;
547 emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, finalFilterName, consumer, consumerParams, properties);
550 #include "effectstackview.moc"