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 //connect(m_ui.region_url, SIGNAL(urlSelected(const KUrl &)), this , SLOT(slotRegionChanged()));
78 //connect(m_ui.region_url, SIGNAL(returnPressed()), this , SLOT(slotRegionChanged()));
79 connect(m_ui.effectlist, SIGNAL(itemSelectionChanged()), this , SLOT(slotItemSelectionChanged()));
80 connect(m_ui.effectlist, SIGNAL(itemChanged(QListWidgetItem *)), this , SLOT(slotItemChanged(QListWidgetItem *)));
81 connect(m_ui.buttonUp, SIGNAL(clicked()), this, SLOT(slotItemUp()));
82 connect(m_ui.buttonDown, SIGNAL(clicked()), this, SLOT(slotItemDown()));
83 connect(m_ui.buttonDel, SIGNAL(clicked()), this, SLOT(slotItemDel()));
84 connect(m_ui.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveEffect()));
85 connect(m_ui.buttonReset, SIGNAL(clicked()), this, SLOT(slotResetEffect()));
86 connect(m_ui.checkAll, SIGNAL(stateChanged(int)), this, SLOT(slotCheckAll(int)));
87 connect(m_ui.buttonShowComments, SIGNAL(clicked()), this, SIGNAL(showComments()));
88 connect(m_effectedit, SIGNAL(parameterChanged(const QDomElement, const QDomElement)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement)));
89 connect(m_effectedit, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
90 connect(m_effectedit, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
91 connect(m_effectedit, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
92 connect(monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
93 connect(this, SIGNAL(showComments()), m_effectedit, SIGNAL(showComments()));
94 m_effectLists["audio"] = &MainWindow::audioEffects;
95 m_effectLists["video"] = &MainWindow::videoEffects;
96 m_effectLists["custom"] = &MainWindow::customEffects;
97 m_ui.splitter->setStretchFactor(1, 10);
98 m_ui.splitter->setStretchFactor(0, 1);
103 EffectStackView::~EffectStackView()
105 m_effectLists.clear();
109 void EffectStackView::updateTimecodeFormat()
111 m_effectedit->updateTimecodeFormat();
114 void EffectStackView::setMenu(QMenu *menu)
116 m_ui.buttonNew->setMenu(menu);
119 void EffectStackView::updateProjectFormat(MltVideoProfile profile, Timecode t)
121 m_effectedit->updateProjectFormat(profile, t);
124 void EffectStackView::slotSaveEffect()
126 QString name = QInputDialog::getText(this, i18n("Save Effect"), i18n("Name for saved effect: "));
127 if (name.isEmpty()) return;
128 QString path = KStandardDirs::locateLocal("appdata", "effects/", true);
129 path = path + name + ".xml";
130 if (QFile::exists(path)) if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", path)) == KMessageBox::No) return;
132 int i = m_ui.effectlist->currentRow();
134 QDomElement effect = m_currentEffectList.at(i).cloneNode().toElement();
135 doc.appendChild(doc.importNode(effect, true));
136 effect = doc.firstChild().toElement();
137 effect.removeAttribute("kdenlive_ix");
138 effect.setAttribute("id", name);
139 effect.setAttribute("type", "custom");
140 QDomElement effectname = effect.firstChildElement("name");
141 effect.removeChild(effectname);
142 effectname = doc.createElement("name");
143 QDomText nametext = doc.createTextNode(name);
144 effectname.appendChild(nametext);
145 effect.insertBefore(effectname, QDomNode());
146 QDomElement effectprops = effect.firstChildElement("properties");
147 effectprops.setAttribute("id", name);
148 effectprops.setAttribute("type", "custom");
151 if (file.open(QFile::WriteOnly | QFile::Truncate)) {
152 QTextStream out(&file);
153 out << doc.toString();
156 emit reloadEffects();
159 void EffectStackView::slotUpdateEffectParams(const QDomElement old, const QDomElement e)
162 emit updateEffect(NULL, m_trackindex, old, e, m_ui.effectlist->currentRow());
164 emit updateEffect(m_clipref, -1, old, e, m_ui.effectlist->currentRow());
167 void EffectStackView::slotClipItemSelected(ClipItem* c, int ix)
169 if (c && !c->isEnabled()) return;
170 if (c && c == m_clipref) {
171 if (ix == -1) ix = m_ui.effectlist->currentRow();
172 //if (ix == -1 || ix == m_ui.effectlist->currentRow()) return;
176 QString cname = m_clipref->clipName();
177 if (cname.length() > 20) {
178 m_ui.checkAll->setToolTip(i18n("Effects for %1").arg(cname));
180 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "...");
182 m_ui.checkAll->setToolTip(QString());
183 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
185 ix = c->selectedEffectIndex();
186 QString size = c->baseClip()->getProperty("frame_size");
187 double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
188 QPoint p((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
189 m_effectedit->setFrameSize(p);
190 m_effectedit->setFrameSize(p);
193 if (m_clipref == NULL) {
194 m_ui.effectlist->blockSignals(true);
195 m_ui.effectlist->clear();
196 m_effectedit->transferParamDesc(QDomElement(), 0, 0, 0);
197 //m_ui.region_url->clear();
198 m_ui.effectlist->blockSignals(false);
199 m_ui.checkAll->setToolTip(QString());
200 m_ui.checkAll->setText(QString());
206 m_currentEffectList = m_clipref->effectList();
210 void EffectStackView::slotTrackItemSelected(int ix, const TrackInfo info)
214 m_currentEffectList = info.effectsList;
216 kDebug() << "// TRACK; " << ix << ", EFFECTS: " << m_currentEffectList.count();
218 m_ui.checkAll->setToolTip(QString());
219 m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
224 void EffectStackView::slotItemChanged(QListWidgetItem *item)
227 if (item->checkState() == Qt::Checked) disable = false;
228 m_ui.frame->setEnabled(!disable);
229 m_ui.buttonReset->setEnabled(!disable);
230 int activeRow = m_ui.effectlist->currentRow();
231 if (activeRow >= 0) {
232 m_effectedit->updateParameter("disable", QString::number((int) disable));
234 emit changeEffectState(NULL, m_trackindex, activeRow, disable);
236 emit changeEffectState(m_clipref, -1, activeRow, disable);
238 slotUpdateCheckAllButton();
242 void EffectStackView::setupListView(int ix)
244 m_ui.effectlist->blockSignals(true);
245 m_ui.effectlist->clear();
247 // Issue 238: Add icons for effect type in effectstack.
248 KIcon videoIcon("kdenlive-show-video");
249 KIcon audioIcon("kdenlive-show-audio");
250 KIcon customIcon("kdenlive-custom-effect");
251 QListWidgetItem* item;
253 for (int i = 0; i < m_currentEffectList.count(); i++) {
254 const QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
256 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
261 doc.appendChild(doc.importNode(d, true));
262 kDebug() << "IMPORTED STK: " << doc.toString();*/
264 QDomNode namenode = d.elementsByTagName("name").item(0);
265 if (!namenode.isNull()) {
266 // Issue 238: Add icons for effect type in effectstack.
267 // Logic more or less copied from initeffects.cpp
268 QString type = d.attribute("type", QString());
269 if ("audio" == type) {
270 item = new QListWidgetItem(audioIcon, i18n(namenode.toElement().text().toUtf8().data()), m_ui.effectlist);
271 } else if ("custom" == type) {
272 item = new QListWidgetItem(customIcon, i18n(namenode.toElement().text().toUtf8().data()), m_ui.effectlist);
274 item = new QListWidgetItem(videoIcon, i18n(namenode.toElement().text().toUtf8().data()), m_ui.effectlist);
276 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
277 if (d.attribute("disable") == "1")
278 item->setCheckState(Qt::Unchecked);
280 item->setCheckState(Qt::Checked);
283 if (m_ui.effectlist->count() == 0) {
284 m_ui.buttonDel->setEnabled(false);
285 m_ui.buttonSave->setEnabled(false);
286 m_ui.buttonReset->setEnabled(false);
287 m_ui.buttonUp->setEnabled(false);
288 m_ui.buttonDown->setEnabled(false);
289 m_ui.checkAll->setEnabled(false);
292 qMax(ix, m_ui.effectlist->count() - 1);
293 m_ui.effectlist->setCurrentRow(ix);
294 m_ui.checkAll->setEnabled(true);
296 m_ui.effectlist->blockSignals(false);
297 if (m_ui.effectlist->count() == 0) {
298 m_effectedit->transferParamDesc(QDomElement(), 0, 0, 0);
299 //m_ui.region_url->clear();
300 } else slotItemSelectionChanged(false);
301 slotUpdateCheckAllButton();
304 void EffectStackView::slotItemSelectionChanged(bool update)
306 bool hasItem = m_ui.effectlist->currentItem();
307 int activeRow = m_ui.effectlist->currentRow();
308 bool isChecked = false;
309 if (hasItem && m_ui.effectlist->currentItem()->checkState() == Qt::Checked) isChecked = true;
310 if (hasItem && m_ui.effectlist->currentItem()->isSelected()) {
311 QDomElement eff = m_currentEffectList.at(activeRow);
313 // showing track effects
314 m_effectedit->transferParamDesc(eff, 0, 0, m_trackInfo.duration);
315 } else m_effectedit->transferParamDesc(eff,
317 m_clipref->cropStart().frames(KdenliveSettings::project_fps()),
318 (m_clipref->cropStart() + m_clipref->cropDuration()).frames(KdenliveSettings::project_fps()) - 1); //minx max frame
319 //m_ui.region_url->setUrl(KUrl(eff.attribute("region")));
321 if (!m_trackMode && m_clipref && update) m_clipref->setSelectedEffect(activeRow);
322 m_ui.buttonDel->setEnabled(hasItem);
323 m_ui.buttonSave->setEnabled(hasItem);
324 m_ui.buttonReset->setEnabled(hasItem && isChecked);
325 m_ui.buttonUp->setEnabled(activeRow > 0);
326 m_ui.buttonDown->setEnabled((activeRow < m_ui.effectlist->count() - 1) && hasItem);
327 m_ui.frame->setEnabled(isChecked);
329 if (m_ui.buttonShowComments->isChecked())
333 void EffectStackView::slotItemUp()
335 int activeRow = m_ui.effectlist->currentRow();
336 if (activeRow <= 0) return;
337 if (m_trackMode) emit changeEffectPosition(NULL, m_trackindex, activeRow + 1, activeRow);
338 else emit changeEffectPosition(m_clipref, -1, activeRow + 1, activeRow);
341 void EffectStackView::slotItemDown()
343 int activeRow = m_ui.effectlist->currentRow();
344 if (activeRow >= m_ui.effectlist->count() - 1) return;
345 if (m_trackMode) emit changeEffectPosition(NULL, m_trackindex, activeRow + 1, activeRow + 2);
346 else emit changeEffectPosition(m_clipref, -1, activeRow + 1, activeRow + 2);
349 void EffectStackView::slotItemDel()
351 int activeRow = m_ui.effectlist->currentRow();
352 if (activeRow >= 0) {
354 emit removeEffect(NULL, m_trackindex, m_currentEffectList.at(activeRow).cloneNode().toElement());
356 emit removeEffect(m_clipref, -1, m_clipref->effectAt(activeRow));
357 slotUpdateCheckAllButton();
361 void EffectStackView::slotResetEffect()
363 int activeRow = m_ui.effectlist->currentRow();
364 if (activeRow < 0) return;
365 QDomElement old = m_currentEffectList.at(activeRow).cloneNode().toElement();
367 QString effectName = m_ui.effectlist->currentItem()->text();
368 foreach(const QString &type, m_effectLists.keys()) {
369 EffectsList *list = m_effectLists[type];
370 if (list->effectNames().contains(effectName)) {
371 dom = list->getEffectByName(effectName).cloneNode().toElement();
376 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
378 EffectsList::setParameter(dom, "in", QString::number(0));
379 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
380 m_effectedit->transferParamDesc(dom, 0, 0, m_trackInfo.duration);//minx max frame
381 emit updateEffect(NULL, m_trackindex, old, dom, activeRow);
383 m_clipref->initEffect(dom);
384 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
385 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
386 emit updateEffect(m_clipref, -1, old, dom, activeRow);
390 if (m_ui.buttonShowComments->isChecked())
395 void EffectStackView::raiseWindow(QWidget* dock)
397 if ((m_clipref || m_trackMode) && dock)
401 void EffectStackView::clear()
403 m_ui.effectlist->blockSignals(true);
404 m_ui.effectlist->clear();
405 m_ui.buttonDel->setEnabled(false);
406 m_ui.buttonSave->setEnabled(false);
407 m_ui.buttonReset->setEnabled(false);
408 m_ui.buttonUp->setEnabled(false);
409 m_ui.buttonDown->setEnabled(false);
410 m_ui.checkAll->setEnabled(false);
411 m_effectedit->transferParamDesc(QDomElement(), 0, 0, 0);
412 //m_ui.region_url->clear();
413 m_ui.effectlist->blockSignals(false);
417 void EffectStackView::slotSeekTimeline(int pos)
420 emit seekTimeline(pos);
421 } else if (m_clipref) {
422 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
426 void EffectStackView::slotUpdateCheckAllButton()
428 bool hasEnabled = false;
429 bool hasDisabled = false;
430 for (int i = 0; i < m_ui.effectlist->count(); ++i) {
431 if (m_ui.effectlist->item(i)->checkState() == Qt::Checked)
437 m_ui.checkAll->blockSignals(true);
438 if (hasEnabled && hasDisabled)
439 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
441 m_ui.checkAll->setCheckState(Qt::Checked);
443 m_ui.checkAll->setCheckState(Qt::Unchecked);
444 m_ui.checkAll->blockSignals(false);
447 void EffectStackView::slotCheckAll(int state)
451 m_ui.checkAll->blockSignals(true);
452 m_ui.checkAll->setCheckState(Qt::Checked);
453 m_ui.checkAll->blockSignals(false);
456 bool disabled = (state != 2);
457 m_effectedit->updateParameter("disable", QString::number((int) disabled));
458 for (int i = 0; i < m_ui.effectlist->count(); ++i) {
459 if (m_ui.effectlist->item(i)->checkState() != (Qt::CheckState)state) {
460 m_ui.effectlist->item(i)->setCheckState((Qt::CheckState)state);
462 emit changeEffectState(NULL, m_trackindex, i, disabled);
464 emit changeEffectState(m_clipref, -1, i, disabled);
469 /*void EffectStackView::slotRegionChanged()
471 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
474 void EffectStackView::slotCheckMonitorPosition(int renderPos)
476 if (m_trackMode || (renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
477 if (!m_monitor->getEffectScene()->views().at(0)->isVisible())
478 m_monitor->slotEffectScene(true);
480 m_monitor->slotEffectScene(false);
484 void EffectStackView::slotRenderPos(int pos)
488 m_effectedit->slotSyncEffectsPos(pos);
489 } else if (m_clipref) {
490 m_effectedit->slotSyncEffectsPos(pos - m_clipref->startPos().frames(KdenliveSettings::project_fps()));
495 int EffectStackView::isTrackMode(bool *ok) const
501 #include "effectstackview.moc"