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);
54 m_ui.frame->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
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"));
74 m_ui.effectlist->setDragDropMode(QAbstractItemView::NoDragDrop); //use internal if drop is recognised right
76 //connect(m_ui.region_url, SIGNAL(urlSelected(const KUrl &)), this , SLOT(slotRegionChanged()));
77 //connect(m_ui.region_url, SIGNAL(returnPressed()), this , SLOT(slotRegionChanged()));
78 connect(m_ui.effectlist, SIGNAL(itemSelectionChanged()), this , SLOT(slotItemSelectionChanged()));
79 connect(m_ui.effectlist, SIGNAL(itemChanged(QListWidgetItem *)), this , SLOT(slotItemChanged(QListWidgetItem *)));
80 connect(m_ui.buttonUp, SIGNAL(clicked()), this, SLOT(slotItemUp()));
81 connect(m_ui.buttonDown, SIGNAL(clicked()), this, SLOT(slotItemDown()));
82 connect(m_ui.buttonDel, SIGNAL(clicked()), this, SLOT(slotItemDel()));
83 connect(m_ui.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveEffect()));
84 connect(m_ui.buttonReset, SIGNAL(clicked()), this, SLOT(slotResetEffect()));
85 connect(m_ui.checkAll, SIGNAL(stateChanged(int)), this, SLOT(slotCheckAll(int)));
86 connect(m_effectedit, SIGNAL(parameterChanged(const QDomElement, const QDomElement)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement)));
87 connect(m_effectedit, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
88 connect(m_effectedit, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int)));
89 connect(m_effectedit, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
90 connect(monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
91 m_effectLists["audio"] = &MainWindow::audioEffects;
92 m_effectLists["video"] = &MainWindow::videoEffects;
93 m_effectLists["custom"] = &MainWindow::customEffects;
94 m_ui.splitter->setStretchFactor(1, 10);
95 m_ui.splitter->setStretchFactor(0, 1);
99 EffectStackView::~EffectStackView()
101 m_effectLists.clear();
105 void EffectStackView::updateTimecodeFormat()
107 m_effectedit->updateTimecodeFormat();
110 void EffectStackView::setMenu(QMenu *menu)
112 m_ui.buttonNew->setMenu(menu);
115 void EffectStackView::updateProjectFormat(MltVideoProfile profile, Timecode t)
117 m_effectedit->updateProjectFormat(profile, t);
120 void EffectStackView::slotSaveEffect()
122 QString name = QInputDialog::getText(this, i18n("Save Effect"), i18n("Name for saved effect: "));
123 if (name.isEmpty()) return;
124 QString path = KStandardDirs::locateLocal("appdata", "effects/", true);
125 path = path + name + ".xml";
126 if (QFile::exists(path)) if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it?")) == KMessageBox::No) return;
128 int i = m_ui.effectlist->currentRow();
130 QDomElement effect = m_currentEffectList.at(i).cloneNode().toElement();
131 doc.appendChild(doc.importNode(effect, true));
132 effect = doc.firstChild().toElement();
133 effect.removeAttribute("kdenlive_ix");
134 effect.setAttribute("id", name);
135 effect.setAttribute("type", "custom");
136 QDomElement effectname = effect.firstChildElement("name");
137 effect.removeChild(effectname);
138 effectname = doc.createElement("name");
139 QDomText nametext = doc.createTextNode(name);
140 effectname.appendChild(nametext);
141 effect.insertBefore(effectname, QDomNode());
142 QDomElement effectprops = effect.firstChildElement("properties");
143 effectprops.setAttribute("id", name);
144 effectprops.setAttribute("type", "custom");
147 if (file.open(QFile::WriteOnly | QFile::Truncate)) {
148 QTextStream out(&file);
149 out << doc.toString();
152 emit reloadEffects();
155 void EffectStackView::slotUpdateEffectParams(const QDomElement old, const QDomElement e)
158 emit updateEffect(NULL, m_trackindex, old, e, m_ui.effectlist->currentRow());
160 emit updateEffect(m_clipref, -1, old, e, m_ui.effectlist->currentRow());
163 void EffectStackView::slotClipItemSelected(ClipItem* c, int ix)
165 if (c && !c->isEnabled()) return;
166 if (c && c == m_clipref) {
167 if (ix == -1) ix = m_ui.effectlist->currentRow();
168 //if (ix == -1 || ix == m_ui.effectlist->currentRow()) return;
172 m_ui.checkAll->setText(i18n("Effects for %1").arg(m_clipref->clipName()));
173 ix = c->selectedEffectIndex();
174 QString size = c->baseClip()->getProperty("frame_size");
175 double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
176 QPoint p((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
177 m_effectedit->setFrameSize(p);
178 m_effectedit->setFrameSize(p);
181 if (m_clipref == NULL) {
182 m_ui.effectlist->blockSignals(true);
183 m_ui.effectlist->clear();
184 m_effectedit->transferParamDesc(QDomElement(), 0, 0, 0);
185 //m_ui.region_url->clear();
186 m_ui.effectlist->blockSignals(false);
192 m_currentEffectList = m_clipref->effectList();
196 void EffectStackView::slotTrackItemSelected(int ix, const TrackInfo info)
200 m_currentEffectList = info.effectsList;
201 kDebug() << "// TRACK; " << ix << ", EFFECTS: " << m_currentEffectList.count();
203 m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
208 void EffectStackView::slotItemChanged(QListWidgetItem *item)
211 if (item->checkState() == Qt::Checked) disable = false;
212 m_ui.frame_layout->setEnabled(!disable);
213 m_ui.buttonReset->setEnabled(!disable);
214 int activeRow = m_ui.effectlist->currentRow();
215 if (activeRow >= 0) {
216 m_effectedit->updateParameter("disable", QString::number((int) disable));
217 if (m_trackMode) emit changeEffectState(NULL, m_trackindex, activeRow, disable);
218 else emit changeEffectState(m_clipref, -1, activeRow, disable);
220 slotUpdateCheckAllButton();
224 void EffectStackView::setupListView(int ix)
226 m_ui.effectlist->blockSignals(true);
227 m_ui.effectlist->clear();
229 // Issue 238: Add icons for effect type in effectstack.
230 KIcon videoIcon("kdenlive-show-video");
231 KIcon audioIcon("kdenlive-show-audio");
232 KIcon customIcon("kdenlive-custom-effect");
233 QListWidgetItem* item;
235 for (int i = 0; i < m_currentEffectList.count(); i++) {
236 const QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
238 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
243 doc.appendChild(doc.importNode(d, true));
244 kDebug() << "IMPORTED STK: " << doc.toString();*/
246 QDomNode namenode = d.elementsByTagName("name").item(0);
247 if (!namenode.isNull()) {
248 // Issue 238: Add icons for effect type in effectstack.
249 // Logic more or less copied from initeffects.cpp
250 QString type = d.attribute("type", QString());
251 if ("audio" == type) {
252 item = new QListWidgetItem(audioIcon, i18n(namenode.toElement().text().toUtf8().data()), m_ui.effectlist);
253 } else if ("custom" == type) {
254 item = new QListWidgetItem(customIcon, i18n(namenode.toElement().text().toUtf8().data()), m_ui.effectlist);
256 item = new QListWidgetItem(videoIcon, i18n(namenode.toElement().text().toUtf8().data()), m_ui.effectlist);
258 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
259 if (d.attribute("disable") == "1") item->setCheckState(Qt::Unchecked);
260 else item->setCheckState(Qt::Checked);
263 if (m_ui.effectlist->count() == 0) {
264 m_ui.buttonDel->setEnabled(false);
265 m_ui.buttonSave->setEnabled(false);
266 m_ui.buttonReset->setEnabled(false);
267 m_ui.buttonUp->setEnabled(false);
268 m_ui.buttonDown->setEnabled(false);
269 m_ui.checkAll->setEnabled(false);
272 if (ix > m_ui.effectlist->count() - 1) ix = m_ui.effectlist->count() - 1;
273 m_ui.effectlist->setCurrentRow(ix);
274 m_ui.checkAll->setEnabled(true);
276 m_ui.effectlist->blockSignals(false);
277 if (m_ui.effectlist->count() == 0) {
278 m_effectedit->transferParamDesc(QDomElement(), 0, 0, 0);
279 //m_ui.region_url->clear();
280 } else slotItemSelectionChanged(false);
281 slotUpdateCheckAllButton();
284 void EffectStackView::slotItemSelectionChanged(bool update)
286 bool hasItem = m_ui.effectlist->currentItem();
287 int activeRow = m_ui.effectlist->currentRow();
288 bool isChecked = false;
289 if (hasItem && m_ui.effectlist->currentItem()->checkState() == Qt::Checked) isChecked = true;
290 if (hasItem && m_ui.effectlist->currentItem()->isSelected()) {
291 QDomElement eff = m_currentEffectList.at(activeRow);
293 // showing track effects
294 m_effectedit->transferParamDesc(eff, 0, 0, -1);
295 } else m_effectedit->transferParamDesc(eff,
297 m_clipref->cropStart().frames(KdenliveSettings::project_fps()),
298 (m_clipref->cropStart() + m_clipref->cropDuration()).frames(KdenliveSettings::project_fps())); //minx max frame
299 //m_ui.region_url->setUrl(KUrl(eff.attribute("region")));
301 if (!m_trackMode && m_clipref && update) m_clipref->setSelectedEffect(activeRow);
302 m_ui.buttonDel->setEnabled(hasItem);
303 m_ui.buttonSave->setEnabled(hasItem);
304 m_ui.buttonReset->setEnabled(hasItem && isChecked);
305 m_ui.buttonUp->setEnabled(activeRow > 0);
306 m_ui.buttonDown->setEnabled((activeRow < m_ui.effectlist->count() - 1) && hasItem);
307 m_ui.frame_layout->setEnabled(isChecked);
310 void EffectStackView::slotItemUp()
312 int activeRow = m_ui.effectlist->currentRow();
313 if (activeRow <= 0) return;
314 if (m_trackMode) emit changeEffectPosition(NULL, m_trackindex, activeRow + 1, activeRow);
315 else emit changeEffectPosition(m_clipref, -1, activeRow + 1, activeRow);
318 void EffectStackView::slotItemDown()
320 int activeRow = m_ui.effectlist->currentRow();
321 if (activeRow >= m_ui.effectlist->count() - 1) return;
322 if (m_trackMode) emit changeEffectPosition(NULL, m_trackindex, activeRow + 1, activeRow + 2);
323 else emit changeEffectPosition(m_clipref, -1, activeRow + 1, activeRow + 2);
326 void EffectStackView::slotItemDel()
328 int activeRow = m_ui.effectlist->currentRow();
329 if (activeRow >= 0) {
330 if (m_trackMode) emit removeEffect(NULL, m_trackindex, m_currentEffectList.at(activeRow).cloneNode().toElement());
331 else emit removeEffect(m_clipref, -1, m_clipref->effectAt(activeRow));
332 slotUpdateCheckAllButton();
336 void EffectStackView::slotResetEffect()
338 int activeRow = m_ui.effectlist->currentRow();
339 if (activeRow < 0) return;
340 QDomElement old = m_currentEffectList.at(activeRow).cloneNode().toElement();
342 QString effectName = m_ui.effectlist->currentItem()->text();
343 foreach(const QString &type, m_effectLists.keys()) {
344 EffectsList *list = m_effectLists[type];
345 if (list->effectNames().contains(effectName)) {
346 dom = list->getEffectByName(effectName).cloneNode().toElement();
351 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
353 EffectsList::setParameter(dom, "in", QString::number(0));
354 EffectsList::setParameter(dom, "out", QString::number(0));
355 m_effectedit->transferParamDesc(dom, 0, 0, 0);//minx max frame
356 emit updateEffect(NULL, m_trackindex, old, dom, activeRow);
358 m_clipref->initEffect(dom);
359 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
360 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
361 emit updateEffect(m_clipref, -1, old, dom, activeRow);
367 void EffectStackView::raiseWindow(QWidget* dock)
369 if ((m_clipref || m_trackMode) && dock)
373 void EffectStackView::clear()
375 m_ui.effectlist->blockSignals(true);
376 m_ui.effectlist->clear();
377 m_ui.buttonDel->setEnabled(false);
378 m_ui.buttonSave->setEnabled(false);
379 m_ui.buttonReset->setEnabled(false);
380 m_ui.buttonUp->setEnabled(false);
381 m_ui.buttonDown->setEnabled(false);
382 m_ui.checkAll->setEnabled(false);
383 m_effectedit->transferParamDesc(QDomElement(), 0, 0, 0);
384 //m_ui.region_url->clear();
385 m_ui.effectlist->blockSignals(false);
389 void EffectStackView::slotSeekTimeline(int pos)
391 if (!m_trackMode && m_clipref)
392 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
395 void EffectStackView::slotUpdateCheckAllButton()
397 bool hasEnabled = false;
398 bool hasDisabled = false;
399 for (int i = 0; i < m_ui.effectlist->count(); ++i) {
400 if (m_ui.effectlist->item(i)->checkState() == Qt::Checked)
406 m_ui.checkAll->blockSignals(true);
407 if (hasEnabled && hasDisabled)
408 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
410 m_ui.checkAll->setCheckState(Qt::Checked);
412 m_ui.checkAll->setCheckState(Qt::Unchecked);
413 m_ui.checkAll->blockSignals(false);
416 void EffectStackView::slotCheckAll(int state)
420 m_ui.checkAll->blockSignals(true);
421 m_ui.checkAll->setCheckState(Qt::Checked);
422 m_ui.checkAll->blockSignals(false);
425 for (int i = 0; i < m_ui.effectlist->count(); ++i)
426 m_ui.effectlist->item(i)->setCheckState((Qt::CheckState)state);
429 /*void EffectStackView::slotRegionChanged()
431 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
434 void EffectStackView::slotCheckMonitorPosition(int renderPos)
436 if (m_trackMode) return;
437 if (renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps())) {
438 if (!m_monitor->getEffectScene()->views().at(0)->isVisible())
439 m_monitor->slotEffectScene(true);
441 m_monitor->slotEffectScene(false);
445 void EffectStackView::slotRenderPos(int pos)
447 if (m_clipref && m_effectedit && !m_trackMode)
448 m_effectedit->slotSyncEffectsPos(pos - m_clipref->startPos().frames(KdenliveSettings::project_fps()));
451 #include "effectstackview.moc"