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 "monitorscene.h"
27 #include "kdenlivesettings.h"
31 #include <KMessageBox>
32 #include <KStandardDirs>
33 #include <KFileDialog>
36 #include <QTextStream>
38 #include <QInputDialog>
41 EffectStackView::EffectStackView(Monitor *monitor, QWidget *parent) :
49 QVBoxLayout *vbox1 = new QVBoxLayout(m_ui.frame);
50 m_effectedit = new EffectStackEdit(monitor, m_ui.frame);
51 vbox1->setContentsMargins(0, 0, 0, 0);
53 vbox1->addWidget(m_effectedit);
55 //m_ui.region_url->fileDialog()->setFilter(ProjectList::getExtensions());
56 //m_ui.effectlist->horizontalHeader()->setVisible(false);
57 //m_ui.effectlist->verticalHeader()->setVisible(false);
59 m_ui.buttonNew->setIcon(KIcon("document-new"));
60 m_ui.buttonNew->setToolTip(i18n("Add new effect"));
61 m_ui.buttonUp->setIcon(KIcon("go-up"));
62 m_ui.buttonUp->setToolTip(i18n("Move effect up"));
63 m_ui.buttonDown->setIcon(KIcon("go-down"));
64 m_ui.buttonDown->setToolTip(i18n("Move effect down"));
65 m_ui.buttonDel->setIcon(KIcon("edit-delete"));
66 m_ui.buttonDel->setToolTip(i18n("Delete effect"));
67 m_ui.buttonSave->setIcon(KIcon("document-save"));
68 m_ui.buttonSave->setToolTip(i18n("Save effect"));
69 m_ui.buttonReset->setIcon(KIcon("view-refresh"));
70 m_ui.buttonReset->setToolTip(i18n("Reset effect"));
71 m_ui.checkAll->setToolTip(i18n("Enable/Disable all effects"));
72 m_ui.buttonShowComments->setIcon(KIcon("help-about"));
73 m_ui.buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
75 m_ui.effectlist->setDragDropMode(QAbstractItemView::NoDragDrop); //use internal if drop is recognised right
77 m_ui.labelComment->setHidden(true);
79 //connect(m_ui.region_url, SIGNAL(urlSelected(const KUrl &)), this , SLOT(slotRegionChanged()));
80 //connect(m_ui.region_url, SIGNAL(returnPressed()), this , SLOT(slotRegionChanged()));
81 connect(m_ui.effectlist, SIGNAL(itemSelectionChanged()), this , SLOT(slotItemSelectionChanged()));
82 connect(m_ui.effectlist, SIGNAL(itemChanged(QListWidgetItem *)), this , SLOT(slotItemChanged(QListWidgetItem *)));
83 connect(m_ui.buttonUp, SIGNAL(clicked()), this, SLOT(slotItemUp()));
84 connect(m_ui.buttonDown, SIGNAL(clicked()), this, SLOT(slotItemDown()));
85 connect(m_ui.buttonDel, SIGNAL(clicked()), this, SLOT(slotItemDel()));
86 connect(m_ui.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveEffect()));
87 connect(m_ui.buttonReset, SIGNAL(clicked()), this, SLOT(slotResetEffect()));
88 connect(m_ui.checkAll, SIGNAL(stateChanged(int)), this, SLOT(slotCheckAll(int)));
89 connect(m_ui.buttonShowComments, SIGNAL(clicked()), this, SLOT(slotShowComments()));
90 connect(m_effectedit, SIGNAL(parameterChanged(const QDomElement, const QDomElement)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement)));
91 connect(m_effectedit, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
92 connect(m_effectedit, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
93 connect(m_effectedit, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
94 connect(monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
95 connect(this, SIGNAL(showComments()), m_effectedit, SIGNAL(showComments()));
96 m_effectLists["audio"] = &MainWindow::audioEffects;
97 m_effectLists["video"] = &MainWindow::videoEffects;
98 m_effectLists["custom"] = &MainWindow::customEffects;
99 m_ui.splitter->setStretchFactor(1, 10);
100 m_ui.splitter->setStretchFactor(0, 1);
105 EffectStackView::~EffectStackView()
107 m_effectLists.clear();
111 void EffectStackView::updateTimecodeFormat()
113 m_effectedit->updateTimecodeFormat();
116 void EffectStackView::setMenu(QMenu *menu)
118 m_ui.buttonNew->setMenu(menu);
121 void EffectStackView::updateProjectFormat(MltVideoProfile profile, Timecode t)
123 m_effectedit->updateProjectFormat(profile, t);
126 void EffectStackView::slotSaveEffect()
128 QString name = QInputDialog::getText(this, i18n("Save Effect"), i18n("Name for saved effect: "));
129 if (name.isEmpty()) return;
130 QString path = KStandardDirs::locateLocal("appdata", "effects/", true);
131 path = path + name + ".xml";
132 if (QFile::exists(path)) if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", path)) == KMessageBox::No) return;
134 int i = m_ui.effectlist->currentRow();
136 QDomElement effect = m_currentEffectList.at(i).cloneNode().toElement();
137 doc.appendChild(doc.importNode(effect, true));
138 effect = doc.firstChild().toElement();
139 effect.removeAttribute("kdenlive_ix");
140 effect.setAttribute("id", name);
141 effect.setAttribute("type", "custom");
142 QDomElement effectname = effect.firstChildElement("name");
143 effect.removeChild(effectname);
144 effectname = doc.createElement("name");
145 QDomText nametext = doc.createTextNode(name);
146 effectname.appendChild(nametext);
147 effect.insertBefore(effectname, QDomNode());
148 QDomElement effectprops = effect.firstChildElement("properties");
149 effectprops.setAttribute("id", name);
150 effectprops.setAttribute("type", "custom");
153 if (file.open(QFile::WriteOnly | QFile::Truncate)) {
154 QTextStream out(&file);
155 out << doc.toString();
158 emit reloadEffects();
161 void EffectStackView::slotUpdateEffectParams(const QDomElement old, const QDomElement e)
164 emit updateEffect(NULL, m_trackindex, old, e, m_ui.effectlist->currentRow());
166 emit updateEffect(m_clipref, -1, old, e, m_ui.effectlist->currentRow());
169 void EffectStackView::slotClipItemSelected(ClipItem* c, int ix)
171 if (c && !c->isEnabled()) return;
172 if (c && c == m_clipref) {
173 if (ix == -1) ix = m_ui.effectlist->currentRow();
174 //if (ix == -1 || ix == m_ui.effectlist->currentRow()) return;
178 QString cname = m_clipref->clipName();
179 if (cname.length() > 20) {
180 m_ui.checkAll->setToolTip(i18n("Effects for %1").arg(cname));
182 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "...");
184 m_ui.checkAll->setToolTip(QString());
185 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
187 ix = c->selectedEffectIndex();
188 QString size = c->baseClip()->getProperty("frame_size");
189 double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
190 QPoint p((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
191 m_effectedit->setFrameSize(p);
196 if (m_clipref == NULL) {
197 m_ui.effectlist->blockSignals(true);
198 m_ui.effectlist->clear();
199 m_effectedit->transferParamDesc(QDomElement(), 0, 0, 0);
200 //m_ui.region_url->clear();
201 m_ui.effectlist->blockSignals(false);
202 m_ui.checkAll->setToolTip(QString());
203 m_ui.checkAll->setText(QString());
204 m_ui.labelComment->setText(QString());
210 m_currentEffectList = m_clipref->effectList();
214 void EffectStackView::slotTrackItemSelected(int ix, const TrackInfo info)
218 m_currentEffectList = info.effectsList;
220 kDebug() << "// TRACK; " << ix << ", EFFECTS: " << m_currentEffectList.count();
222 m_ui.checkAll->setToolTip(QString());
223 m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
228 void EffectStackView::slotItemChanged(QListWidgetItem *item)
231 if (item->checkState() == Qt::Checked) disable = false;
232 m_ui.frame->setEnabled(!disable);
233 m_ui.buttonReset->setEnabled(!disable);
234 int activeRow = m_ui.effectlist->currentRow();
235 if (activeRow >= 0) {
236 m_effectedit->updateParameter("disable", QString::number((int) disable));
238 emit changeEffectState(NULL, m_trackindex, activeRow, disable);
240 emit changeEffectState(m_clipref, -1, activeRow, disable);
242 slotUpdateCheckAllButton();
246 void EffectStackView::setupListView(int ix)
248 m_ui.effectlist->blockSignals(true);
249 m_ui.effectlist->clear();
251 // Issue 238: Add icons for effect type in effectstack.
252 KIcon videoIcon("kdenlive-show-video");
253 KIcon audioIcon("kdenlive-show-audio");
254 KIcon customIcon("kdenlive-custom-effect");
255 QListWidgetItem* item;
257 for (int i = 0; i < m_currentEffectList.count(); i++) {
258 const QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
260 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
265 doc.appendChild(doc.importNode(d, true));
266 kDebug() << "IMPORTED STK: " << doc.toString();*/
268 QDomNode namenode = d.elementsByTagName("name").item(0);
269 if (!namenode.isNull()) {
270 // Issue 238: Add icons for effect type in effectstack.
271 // Logic more or less copied from initeffects.cpp
272 QString type = d.attribute("type", QString());
273 if ("audio" == type) {
274 item = new QListWidgetItem(audioIcon, i18n(namenode.toElement().text().toUtf8().data()), m_ui.effectlist);
275 } else if ("custom" == type) {
276 item = new QListWidgetItem(customIcon, i18n(namenode.toElement().text().toUtf8().data()), m_ui.effectlist);
278 item = new QListWidgetItem(videoIcon, i18n(namenode.toElement().text().toUtf8().data()), m_ui.effectlist);
280 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
281 if (d.attribute("disable") == "1")
282 item->setCheckState(Qt::Unchecked);
284 item->setCheckState(Qt::Checked);
287 if (m_ui.effectlist->count() == 0) {
288 m_ui.buttonDel->setEnabled(false);
289 m_ui.buttonSave->setEnabled(false);
290 m_ui.buttonReset->setEnabled(false);
291 m_ui.buttonUp->setEnabled(false);
292 m_ui.buttonDown->setEnabled(false);
293 m_ui.checkAll->setEnabled(false);
294 m_ui.buttonShowComments->setEnabled(false);
295 m_ui.labelComment->setHidden(true);
298 qMax(ix, m_ui.effectlist->count() - 1);
299 m_ui.effectlist->setCurrentRow(ix);
300 m_ui.checkAll->setEnabled(true);
302 m_ui.effectlist->blockSignals(false);
303 if (m_ui.effectlist->count() == 0) {
304 m_effectedit->transferParamDesc(QDomElement(), 0, 0, 0);
305 //m_ui.region_url->clear();
306 } else slotItemSelectionChanged(false);
307 slotUpdateCheckAllButton();
310 void EffectStackView::slotItemSelectionChanged(bool update)
312 bool hasItem = m_ui.effectlist->currentItem();
313 int activeRow = m_ui.effectlist->currentRow();
314 bool isChecked = false;
315 if (hasItem && m_ui.effectlist->currentItem()->checkState() == Qt::Checked) isChecked = true;
316 if (hasItem && m_ui.effectlist->currentItem()->isSelected()) {
317 QDomElement eff = m_currentEffectList.at(activeRow);
319 // showing track effects
320 m_effectedit->transferParamDesc(eff, 0, 0, m_trackInfo.duration);
321 } else m_effectedit->transferParamDesc(eff,
323 m_clipref->cropStart().frames(KdenliveSettings::project_fps()),
324 (m_clipref->cropStart() + m_clipref->cropDuration()).frames(KdenliveSettings::project_fps()) - 1); //minx max frame
325 //m_ui.region_url->setUrl(KUrl(eff.attribute("region")));
326 m_ui.labelComment->setText(i18n(eff.firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
328 if (!m_trackMode && m_clipref && update) m_clipref->setSelectedEffect(activeRow);
329 m_ui.buttonDel->setEnabled(hasItem);
330 m_ui.buttonSave->setEnabled(hasItem);
331 m_ui.buttonReset->setEnabled(hasItem && isChecked);
332 m_ui.buttonUp->setEnabled(activeRow > 0);
333 m_ui.buttonDown->setEnabled((activeRow < m_ui.effectlist->count() - 1) && hasItem);
334 m_ui.frame->setEnabled(isChecked);
335 m_ui.buttonShowComments->setEnabled(hasItem);
337 if (m_ui.buttonShowComments->isChecked())
339 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || !m_ui.labelComment->text().count() || !hasItem);
342 void EffectStackView::slotItemUp()
344 int activeRow = m_ui.effectlist->currentRow();
345 if (activeRow <= 0) return;
346 if (m_trackMode) emit changeEffectPosition(NULL, m_trackindex, activeRow + 1, activeRow);
347 else emit changeEffectPosition(m_clipref, -1, activeRow + 1, activeRow);
350 void EffectStackView::slotItemDown()
352 int activeRow = m_ui.effectlist->currentRow();
353 if (activeRow >= m_ui.effectlist->count() - 1) return;
354 if (m_trackMode) emit changeEffectPosition(NULL, m_trackindex, activeRow + 1, activeRow + 2);
355 else emit changeEffectPosition(m_clipref, -1, activeRow + 1, activeRow + 2);
358 void EffectStackView::slotItemDel()
360 int activeRow = m_ui.effectlist->currentRow();
361 if (activeRow >= 0) {
363 emit removeEffect(NULL, m_trackindex, m_currentEffectList.at(activeRow).cloneNode().toElement());
365 emit removeEffect(m_clipref, -1, m_clipref->effectAt(activeRow));
366 slotUpdateCheckAllButton();
370 void EffectStackView::slotResetEffect()
372 int activeRow = m_ui.effectlist->currentRow();
373 if (activeRow < 0) return;
374 QDomElement old = m_currentEffectList.at(activeRow).cloneNode().toElement();
376 QString effectName = m_ui.effectlist->currentItem()->text();
377 foreach(const QString &type, m_effectLists.keys()) {
378 EffectsList *list = m_effectLists[type];
379 if (list->effectNames().contains(effectName)) {
380 dom = list->getEffectByName(effectName).cloneNode().toElement();
385 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
387 EffectsList::setParameter(dom, "in", QString::number(0));
388 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
389 m_effectedit->transferParamDesc(dom, 0, 0, m_trackInfo.duration);//minx max frame
390 emit updateEffect(NULL, m_trackindex, old, dom, activeRow);
392 m_clipref->initEffect(dom);
393 m_effectedit->transferParamDesc(dom, 0, m_clipref->cropStart().frames(KdenliveSettings::project_fps()), (m_clipref->cropStart() + m_clipref->cropDuration()).frames(KdenliveSettings::project_fps()));//minx max frame
394 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
395 emit updateEffect(m_clipref, -1, old, dom, activeRow);
399 if (m_ui.buttonShowComments->isChecked())
401 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || !m_ui.labelComment->text().count());
405 void EffectStackView::raiseWindow(QWidget* dock)
407 if ((m_clipref || m_trackMode) && dock)
411 void EffectStackView::clear()
413 m_ui.effectlist->blockSignals(true);
414 m_ui.effectlist->clear();
415 m_ui.buttonDel->setEnabled(false);
416 m_ui.buttonSave->setEnabled(false);
417 m_ui.buttonReset->setEnabled(false);
418 m_ui.buttonUp->setEnabled(false);
419 m_ui.buttonDown->setEnabled(false);
420 m_ui.checkAll->setEnabled(false);
421 m_effectedit->transferParamDesc(QDomElement(), 0, 0, 0);
422 //m_ui.region_url->clear();
423 m_ui.buttonShowComments->setEnabled(false);
424 m_ui.labelComment->setText(QString());
425 m_ui.effectlist->blockSignals(false);
429 void EffectStackView::slotSeekTimeline(int pos)
432 emit seekTimeline(pos);
433 } else if (m_clipref) {
434 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
438 void EffectStackView::slotUpdateCheckAllButton()
440 bool hasEnabled = false;
441 bool hasDisabled = false;
442 for (int i = 0; i < m_ui.effectlist->count(); ++i) {
443 if (m_ui.effectlist->item(i)->checkState() == Qt::Checked)
449 m_ui.checkAll->blockSignals(true);
450 if (hasEnabled && hasDisabled)
451 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
453 m_ui.checkAll->setCheckState(Qt::Checked);
455 m_ui.checkAll->setCheckState(Qt::Unchecked);
456 m_ui.checkAll->blockSignals(false);
459 void EffectStackView::slotCheckAll(int state)
463 m_ui.checkAll->blockSignals(true);
464 m_ui.checkAll->setCheckState(Qt::Checked);
465 m_ui.checkAll->blockSignals(false);
468 bool disabled = (state != 2);
469 m_effectedit->updateParameter("disable", QString::number((int) disabled));
470 for (int i = 0; i < m_ui.effectlist->count(); ++i) {
471 if (m_ui.effectlist->item(i)->checkState() != (Qt::CheckState)state) {
472 m_ui.effectlist->item(i)->setCheckState((Qt::CheckState)state);
474 emit changeEffectState(NULL, m_trackindex, i, disabled);
476 emit changeEffectState(m_clipref, -1, i, disabled);
481 /*void EffectStackView::slotRegionChanged()
483 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
486 void EffectStackView::slotCheckMonitorPosition(int renderPos)
488 if (m_trackMode || (renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
489 if (!m_monitor->getEffectScene()->views().at(0)->isVisible())
490 m_monitor->slotEffectScene(true);
492 m_monitor->slotEffectScene(false);
496 void EffectStackView::slotRenderPos(int pos)
500 m_effectedit->slotSyncEffectsPos(pos);
501 } else if (m_clipref) {
502 m_effectedit->slotSyncEffectsPos(pos - m_clipref->startPos().frames(KdenliveSettings::project_fps()));
507 int EffectStackView::isTrackMode(bool *ok) const
513 void EffectStackView::slotShowComments()
515 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || !m_ui.labelComment->text().count());
519 #include "effectstackview.moc"