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 vbox1->setContentsMargins(2, 0, 2, 0);
54 vbox1->addWidget(m_effectedit);
55 m_ui.splitter->setStretchFactor(0, 0);
56 m_ui.splitter->setStretchFactor(1, 200);
58 //m_ui.region_url->fileDialog()->setFilter(ProjectList::getExtensions());
59 //m_ui.effectlist->horizontalHeader()->setVisible(false);
60 //m_ui.effectlist->verticalHeader()->setVisible(false);
62 m_ui.buttonNew->setIcon(KIcon("document-new"));
63 m_ui.buttonNew->setToolTip(i18n("Add new effect"));
64 m_ui.buttonUp->setIcon(KIcon("go-up"));
65 m_ui.buttonUp->setToolTip(i18n("Move effect up"));
66 m_ui.buttonDown->setIcon(KIcon("go-down"));
67 m_ui.buttonDown->setToolTip(i18n("Move effect down"));
68 m_ui.buttonDel->setIcon(KIcon("edit-delete"));
69 m_ui.buttonDel->setToolTip(i18n("Delete effect"));
70 m_ui.buttonSave->setIcon(KIcon("document-save"));
71 m_ui.buttonSave->setToolTip(i18n("Save effect"));
72 m_ui.buttonReset->setIcon(KIcon("view-refresh"));
73 m_ui.buttonReset->setToolTip(i18n("Reset effect"));
74 m_ui.checkAll->setToolTip(i18n("Enable/Disable all effects"));
75 m_ui.buttonShowComments->setIcon(KIcon("help-about"));
76 m_ui.buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
78 m_ui.effectlist->setDragDropMode(QAbstractItemView::NoDragDrop); //use internal if drop is recognised right
80 m_ui.labelComment->setHidden(true);
82 //connect(m_ui.region_url, SIGNAL(urlSelected(const KUrl &)), this , SLOT(slotRegionChanged()));
83 //connect(m_ui.region_url, SIGNAL(returnPressed()), this , SLOT(slotRegionChanged()));
84 connect(m_ui.effectlist, SIGNAL(itemSelectionChanged()), this , SLOT(slotItemSelectionChanged()));
85 connect(m_ui.effectlist, SIGNAL(itemChanged(QListWidgetItem *)), this , SLOT(slotItemChanged(QListWidgetItem *)));
86 connect(m_ui.buttonUp, SIGNAL(clicked()), this, SLOT(slotItemUp()));
87 connect(m_ui.buttonDown, SIGNAL(clicked()), this, SLOT(slotItemDown()));
88 connect(m_ui.buttonDel, SIGNAL(clicked()), this, SLOT(slotItemDel()));
89 connect(m_ui.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveEffect()));
90 connect(m_ui.buttonReset, SIGNAL(clicked()), this, SLOT(slotResetEffect()));
91 connect(m_ui.checkAll, SIGNAL(stateChanged(int)), this, SLOT(slotCheckAll(int)));
92 connect(m_ui.buttonShowComments, SIGNAL(clicked()), this, SLOT(slotShowComments()));
93 connect(m_effectedit, SIGNAL(parameterChanged(const QDomElement, const QDomElement)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement)));
94 connect(m_effectedit, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
95 connect(m_effectedit, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
96 connect(m_effectedit, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
97 connect(monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
98 connect(this, SIGNAL(showComments(bool)), m_effectedit, SIGNAL(showComments(bool)));
99 m_effectLists["audio"] = &MainWindow::audioEffects;
100 m_effectLists["video"] = &MainWindow::videoEffects;
101 m_effectLists["custom"] = &MainWindow::customEffects;
102 m_ui.splitter->setStretchFactor(1, 10);
103 m_ui.splitter->setStretchFactor(0, 1);
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)
235 if (item->checkState() == Qt::Checked) disable = false;
236 m_ui.buttonReset->setEnabled(!disable || !KdenliveSettings::disable_effect_parameters());
237 int activeRow = m_ui.effectlist->currentRow();
238 if (activeRow >= 0) {
239 m_effectedit->updateParameter("disable", QString::number((int) disable));
241 emit changeEffectState(NULL, m_trackindex, activeRow, disable);
243 emit changeEffectState(m_clipref, -1, activeRow, disable);
245 slotUpdateCheckAllButton();
249 void EffectStackView::setupListView(int ix)
251 m_ui.effectlist->blockSignals(true);
252 m_ui.effectlist->clear();
254 // Issue 238: Add icons for effect type in effectstack.
255 KIcon videoIcon("kdenlive-show-video");
256 KIcon audioIcon("kdenlive-show-audio");
257 KIcon customIcon("kdenlive-custom-effect");
258 QListWidgetItem* item;
260 for (int i = 0; i < m_currentEffectList.count(); i++) {
261 const QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
263 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
268 doc.appendChild(doc.importNode(d, true));
269 kDebug() << "IMPORTED STK: " << doc.toString();*/
271 QDomNode namenode = d.elementsByTagName("name").item(0);
272 if (!namenode.isNull()) {
273 // Issue 238: Add icons for effect type in effectstack.
274 // Logic more or less copied from initeffects.cpp
275 QString type = d.attribute("type", QString());
276 if ("audio" == type) {
277 item = new QListWidgetItem(audioIcon, i18n(namenode.toElement().text().toUtf8().data()), m_ui.effectlist);
278 } else if ("custom" == type) {
279 item = new QListWidgetItem(customIcon, i18n(namenode.toElement().text().toUtf8().data()), m_ui.effectlist);
281 item = new QListWidgetItem(videoIcon, i18n(namenode.toElement().text().toUtf8().data()), m_ui.effectlist);
283 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
284 if (d.attribute("disable") == "1")
285 item->setCheckState(Qt::Unchecked);
287 item->setCheckState(Qt::Checked);
290 if (m_ui.effectlist->count() == 0) {
291 m_ui.buttonDel->setEnabled(false);
292 m_ui.buttonSave->setEnabled(false);
293 m_ui.buttonReset->setEnabled(false);
294 m_ui.buttonUp->setEnabled(false);
295 m_ui.buttonDown->setEnabled(false);
296 m_ui.checkAll->setEnabled(false);
297 m_ui.buttonShowComments->setEnabled(false);
298 m_ui.labelComment->setHidden(true);
300 ix = qBound(0, ix, m_ui.effectlist->count() - 1);
301 m_ui.effectlist->setCurrentRow(ix);
302 m_ui.checkAll->setEnabled(true);
304 m_ui.effectlist->blockSignals(false);
305 if (m_ui.effectlist->count() == 0) {
307 m_effectedit->transferParamDesc(QDomElement(), info);
308 //m_ui.region_url->clear();
309 } else slotItemSelectionChanged(false);
310 slotUpdateCheckAllButton();
313 void EffectStackView::slotItemSelectionChanged(bool update)
315 bool hasItem = m_ui.effectlist->currentItem();
316 int activeRow = m_ui.effectlist->currentRow();
317 bool isChecked = false;
318 if (hasItem && m_ui.effectlist->currentItem()->checkState() == Qt::Checked) isChecked = true;
320 if (hasItem && m_ui.effectlist->currentItem()->isSelected()) {
321 eff = m_currentEffectList.at(activeRow);
323 // showing track effects
325 info.track = m_trackInfo.type;
326 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
327 info.cropStart = GenTime(0);
328 info.startPos = GenTime(-1);
330 m_effectedit->transferParamDesc(eff, info);
332 m_effectedit->transferParamDesc(eff, m_clipref->info());
334 //m_ui.region_url->setUrl(KUrl(eff.attribute("region")));
335 m_ui.labelComment->setText(i18n(eff.firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
337 if (!m_trackMode && m_clipref && update) m_clipref->setSelectedEffect(activeRow);
338 m_ui.buttonDel->setEnabled(hasItem);
339 m_ui.buttonSave->setEnabled(hasItem);
340 m_ui.buttonReset->setEnabled(hasItem && (isChecked || !KdenliveSettings::disable_effect_parameters()));
341 m_ui.buttonUp->setEnabled(activeRow > 0);
342 m_ui.buttonDown->setEnabled((activeRow < m_ui.effectlist->count() - 1) && hasItem);
343 m_ui.buttonShowComments->setEnabled(hasItem);
345 emit showComments(m_ui.buttonShowComments->isChecked());
346 m_ui.labelComment->setVisible(hasItem && m_ui.labelComment->text().count() && (m_ui.buttonShowComments->isChecked() || !eff.elementsByTagName("parameter").count()));
349 void EffectStackView::slotItemUp()
351 int activeRow = m_ui.effectlist->currentRow();
352 if (activeRow <= 0) return;
353 if (m_trackMode) emit changeEffectPosition(NULL, m_trackindex, activeRow + 1, activeRow);
354 else emit changeEffectPosition(m_clipref, -1, activeRow + 1, activeRow);
357 void EffectStackView::slotItemDown()
359 int activeRow = m_ui.effectlist->currentRow();
360 if (activeRow >= m_ui.effectlist->count() - 1) return;
361 if (m_trackMode) emit changeEffectPosition(NULL, m_trackindex, activeRow + 1, activeRow + 2);
362 else emit changeEffectPosition(m_clipref, -1, activeRow + 1, activeRow + 2);
365 void EffectStackView::slotItemDel()
367 int activeRow = m_ui.effectlist->currentRow();
368 if (activeRow >= 0) {
370 emit removeEffect(NULL, m_trackindex, m_currentEffectList.at(activeRow).cloneNode().toElement());
372 emit removeEffect(m_clipref, -1, m_clipref->effectAt(activeRow));
373 slotUpdateCheckAllButton();
377 void EffectStackView::slotResetEffect()
379 int activeRow = m_ui.effectlist->currentRow();
380 if (activeRow < 0) return;
381 QDomElement old = m_currentEffectList.at(activeRow).cloneNode().toElement();
383 QString effectName = m_ui.effectlist->currentItem()->text();
384 foreach(const QString &type, m_effectLists.keys()) {
385 EffectsList *list = m_effectLists[type];
386 if (list->effectNames().contains(effectName)) {
387 dom = list->getEffectByName(effectName).cloneNode().toElement();
392 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
394 EffectsList::setParameter(dom, "in", QString::number(0));
395 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
397 info.track = m_trackInfo.type;
398 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
399 info.cropStart = GenTime(0);
400 info.startPos = GenTime(-1);
402 m_effectedit->transferParamDesc(dom, info);
403 emit updateEffect(NULL, m_trackindex, old, dom, activeRow);
405 m_clipref->initEffect(dom);
406 m_effectedit->transferParamDesc(dom, m_clipref->info());
407 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
408 emit updateEffect(m_clipref, -1, old, dom, activeRow);
412 emit showComments(m_ui.buttonShowComments->isChecked());
413 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || !m_ui.labelComment->text().count());
417 void EffectStackView::raiseWindow(QWidget* dock)
419 if ((m_clipref || m_trackMode) && dock)
423 void EffectStackView::clear()
425 m_ui.effectlist->blockSignals(true);
426 m_ui.effectlist->clear();
427 m_ui.buttonDel->setEnabled(false);
428 m_ui.buttonSave->setEnabled(false);
429 m_ui.buttonReset->setEnabled(false);
430 m_ui.buttonUp->setEnabled(false);
431 m_ui.buttonDown->setEnabled(false);
432 m_ui.checkAll->setEnabled(false);
434 m_effectedit->transferParamDesc(QDomElement(), info);
435 //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 #include "effectstackview.moc"