1 /***************************************************************************
2 effecstackview.cpp2 - 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 "effectstackview2.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"
29 #include "collapsibleeffect.h"
30 #include "collapsiblegroup.h"
34 #include <KMessageBox>
35 #include <KStandardDirs>
36 #include <KFileDialog>
37 #include <KColorScheme>
40 #include <QTextStream>
42 #include <QInputDialog>
46 EffectStackView2::EffectStackView2(Monitor *monitor, QWidget *parent) :
50 m_draggedEffect(NULL),
53 m_effectMetaInfo.trackMode = false;
54 m_effectMetaInfo.monitor = monitor;
55 m_effects = QList <CollapsibleEffect*>();
58 setFont(KGlobalSettings::smallestReadableFont());
59 m_ui.checkAll->setToolTip(i18n("Enable/Disable all effects"));
60 m_ui.buttonShowComments->setIcon(KIcon("help-about"));
61 m_ui.buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
63 connect(m_ui.checkAll, SIGNAL(stateChanged(int)), this, SLOT(slotCheckAll(int)));
64 connect(m_ui.buttonShowComments, SIGNAL(clicked()), this, SLOT(slotShowComments()));
65 m_ui.labelComment->setHidden(true);
70 setStyleSheet(CollapsibleEffect::getStyleSheet(palette()));
73 EffectStackView2::~EffectStackView2()
78 void EffectStackView2::slotRenderPos(int pos)
80 if (m_effects.isEmpty()) return;
81 if (!m_effectMetaInfo.trackMode && m_clipref) pos = pos - m_clipref->startPos().frames(KdenliveSettings::project_fps());
83 for (int i = 0; i< m_effects.count(); i++)
84 m_effects.at(i)->slotSyncEffectsPos(pos);
87 void EffectStackView2::slotClipItemSelected(ClipItem* c, int ix)
89 if (c && !c->isEnabled()) return;
90 if (c && c == m_clipref) {
95 QString cname = m_clipref->clipName();
96 if (cname.length() > 30) {
97 m_ui.checkAll->setToolTip(i18n("Effects for %1").arg(cname));
99 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "...");
101 m_ui.checkAll->setToolTip(QString());
102 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
104 m_ui.checkAll->setEnabled(true);
105 ix = c->selectedEffectIndex();
106 QString size = c->baseClip()->getProperty("frame_size");
107 double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
108 m_effectMetaInfo.frameSize = QPoint((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
113 if (m_clipref == NULL) {
114 //TODO: clear list, reset paramdesc and info
116 //m_effectedit->transferParamDesc(QDomElement(), info);
121 m_effectMetaInfo.trackMode = false;
122 m_currentEffectList = m_clipref->effectList();
126 void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
129 m_effectMetaInfo.trackMode = true;
130 m_currentEffectList = info.effectsList;
133 m_ui.checkAll->setToolTip(QString());
134 m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
140 void EffectStackView2::setupListView(int ix)
143 m_draggedEffect = NULL;
144 disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
147 QWidget *view = m_ui.container->takeWidget();
152 view = new QWidget(m_ui.container);
153 m_ui.container->setWidget(view);
155 QVBoxLayout *vbox1 = new QVBoxLayout(view);
156 vbox1->setContentsMargins(0, 0, 0, 0);
157 vbox1->setSpacing(0);
159 if (m_currentEffectList.isEmpty()) m_ui.labelComment->setHidden(true);
161 for (int i = 0; i < m_currentEffectList.count(); i++) {
162 QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
164 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
168 CollapsibleGroup *group = NULL;
169 EffectInfo effectInfo;
170 effectInfo.fromString(d.attribute("kdenlive_info"));
171 if (effectInfo.groupIndex >= 0) {
172 // effect is in a group
174 for (int j = 0; j < vbox1->count(); j++) {
175 CollapsibleGroup *eff = static_cast<CollapsibleGroup *>(vbox1->itemAt(j)->widget());
176 if (eff->isGroup() && eff->groupIndex() == effectInfo.groupIndex) {
183 group = new CollapsibleGroup(effectInfo.groupIndex, i == 0, i == m_currentEffectList.count() - 1, m_ui.container->widget());
184 if (!effectInfo.groupName.isEmpty()) group->title->setText(effectInfo.groupName);
185 connect(group, SIGNAL(moveEffect(int,int,int)), this, SLOT(slotMoveEffect(int,int,int)));
186 connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
187 vbox1->addWidget(group);
189 if (effectInfo.groupIndex >= m_groupIndex) m_groupIndex = effectInfo.groupIndex + 1;
193 doc.appendChild(doc.importNode(d, true));
194 kDebug() << "IMPORTED STK: " << doc.toString();*/
197 if (m_effectMetaInfo.trackMode) {
198 info.track = m_trackInfo.type;
199 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
200 info.cropStart = GenTime(0);
201 info.startPos = GenTime(-1);
204 else info = m_clipref->info();
206 CollapsibleEffect *currentEffect = new CollapsibleEffect(d, m_currentEffectList.at(i), info, &m_effectMetaInfo, i == m_currentEffectList.count() - 1, view);
207 m_effects.append(currentEffect);
209 group->addGroupEffect(currentEffect);
211 vbox1->addWidget(currentEffect);
213 if (currentEffect->effectIndex() == ix) currentEffect->setActive(true);
216 currentEffect->installEventFilter( this );
218 connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
219 connect(currentEffect, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,QString,QString)));
220 connect(currentEffect, SIGNAL(deleteEffect(const QDomElement)), this , SLOT(slotDeleteEffect(const QDomElement)));
221 connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
222 connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
223 connect(currentEffect, SIGNAL(changeEffectPosition(int,bool)), this , SLOT(slotMoveEffectUp(int , bool)));
224 connect(currentEffect, SIGNAL(effectStateChanged(bool, int)), this, SLOT(slotUpdateEffectState(bool, int)));
225 connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
226 connect(currentEffect, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
227 connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
228 connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
229 connect(currentEffect, SIGNAL(moveEffect(int,int,int)), this , SLOT(slotMoveEffect(int,int,int)));
230 connect(currentEffect, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
232 //ui.title->setPixmap(icon.pixmap(QSize(12, 12)));
234 vbox1->addStretch(10);
235 slotUpdateCheckAllButton();
236 connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
238 // Wait a little bit for the new layout to be ready, then check if we have a scrollbar
239 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
243 void EffectStackView2::slotCheckWheelEventFilter()
245 // If the effect stack widget has no scrollbar, we will not filter the
246 // mouse wheel events, so that user can easily adjust effect params
247 bool filterWheelEvent = false;
248 if (m_ui.container->verticalScrollBar() && m_ui.container->verticalScrollBar()->isVisible()) {
249 // widget has scroll bar,
250 filterWheelEvent = true;
252 for (int i = 0; i < m_effects.count(); i++) {
253 m_effects.at(i)->filterWheelEvent = filterWheelEvent;
257 void EffectStackView2::resizeEvent ( QResizeEvent * event )
259 slotCheckWheelEventFilter();
260 QWidget::resizeEvent(event);
263 bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
265 // Check if user clicked in an effect's top bar to start dragging it
266 if (e->type() == QEvent::MouseButtonPress) {
267 m_draggedEffect = qobject_cast<CollapsibleEffect*>(o);
268 if (m_draggedEffect) {
269 QMouseEvent *me = static_cast<QMouseEvent *>(e);
270 if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse()))
271 m_clickPoint = me->globalPos();
273 m_clickPoint = QPoint();
274 m_draggedEffect = NULL;
280 if (e->type() == QEvent::MouseMove) {
281 if (qobject_cast<CollapsibleEffect*>(o)) {
282 QMouseEvent *me = static_cast<QMouseEvent *>(e);
283 if (me->buttons() != Qt::LeftButton) {
293 return QWidget::eventFilter(o, e);
296 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
298 if (m_draggedEffect && (event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
303 void EffectStackView2::mouseReleaseEvent(QMouseEvent * event)
305 m_draggedEffect = NULL;
306 QWidget::mouseReleaseEvent(event);
309 void EffectStackView2::startDrag()
311 QDrag *drag = new QDrag(this);
312 // The data to be transferred by the drag and drop operation is contained in a QMimeData object
313 QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
314 QPixmap pixmap = QPixmap::grabWidget(m_draggedEffect->title);
315 drag->setPixmap(pixmap);
317 doc.appendChild(doc.importNode(effect, true));
318 QMimeData *mime = new QMimeData;
320 data.append(doc.toString().toUtf8());
321 mime->setData("kdenlive/effectslist", data);
323 // Assign ownership of the QMimeData object to the QDrag object.
324 drag->setMimeData(mime);
325 // Start the drag and drop operation
326 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
330 void EffectStackView2::slotUpdateEffectState(bool disable, int index)
332 if (m_effectMetaInfo.trackMode)
333 emit changeEffectState(NULL, m_trackindex, index, disable);
335 emit changeEffectState(m_clipref, -1, index, disable);
336 slotUpdateCheckAllButton();
340 void EffectStackView2::raiseWindow(QWidget* dock)
342 if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
347 void EffectStackView2::slotSeekTimeline(int pos)
349 if (m_effectMetaInfo.trackMode) {
350 emit seekTimeline(pos);
351 } else if (m_clipref) {
352 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
357 /*void EffectStackView2::slotRegionChanged()
359 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
362 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
364 if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
365 if (!m_effectMetaInfo.monitor->getEffectEdit()->getScene()->views().at(0)->isVisible())
366 m_effectMetaInfo.monitor->slotEffectScene(true);
368 m_effectMetaInfo.monitor->slotEffectScene(false);
372 int EffectStackView2::isTrackMode(bool *ok) const
374 *ok = m_effectMetaInfo.trackMode;
378 void EffectStackView2::clear()
381 QWidget *view = m_ui.container->takeWidget();
385 m_ui.checkAll->setToolTip(QString());
386 m_ui.checkAll->setText(QString());
387 m_ui.checkAll->setEnabled(false);
388 m_ui.labelComment->setText(QString());
392 void EffectStackView2::slotCheckAll(int state)
396 m_ui.checkAll->blockSignals(true);
397 m_ui.checkAll->setCheckState(Qt::Checked);
398 m_ui.checkAll->blockSignals(false);
401 bool disabled = (state != 2);
402 for (int i = 0; i < m_effects.count(); i++) {
403 if (!m_effects.at(i)->isGroup()) {
404 m_effects.at(i)->slotEnable(!disabled);
409 void EffectStackView2::slotUpdateCheckAllButton()
411 bool hasEnabled = false;
412 bool hasDisabled = false;
414 for (int i = 0; i < m_effects.count(); i++) {
415 if (m_effects.at(i)->enabledBox->isChecked()) hasEnabled = true;
416 else hasDisabled = true;
419 m_ui.checkAll->blockSignals(true);
420 if (hasEnabled && hasDisabled)
421 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
423 m_ui.checkAll->setCheckState(Qt::Checked);
425 m_ui.checkAll->setCheckState(Qt::Unchecked);
426 m_ui.checkAll->blockSignals(false);
429 void EffectStackView2::deleteCurrentEffect()
431 for (int i = 0; i < m_effects.count(); i++) {
432 if (m_effects.at(i)->isActive()) {
433 slotDeleteEffect(m_effects.at(i)->effect());
439 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
441 m_effectMetaInfo.profile = profile;
442 m_effectMetaInfo.timecode = t;
445 void EffectStackView2::updateTimecodeFormat()
447 for (int i = 0; i< m_effects.count(); i++)
448 m_effects.at(i)->updateTimecodeFormat();
451 CollapsibleEffect *EffectStackView2::getEffectByIndex(int ix)
453 for (int i = 0; i< m_effects.count(); i++) {
454 if (m_effects.at(i)->effectIndex() == ix) {
455 return m_effects.at(i);
461 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
463 if (m_effectMetaInfo.trackMode)
464 emit updateEffect(NULL, m_trackindex, old, e, ix);
465 else if (m_clipref) {
466 emit updateEffect(m_clipref, -1, old, e, ix);
467 // Make sure the changed effect is currently displayed
468 slotSetCurrentEffect(ix);
470 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
473 void EffectStackView2::slotSetCurrentEffect(int ix)
475 if (m_clipref && ix != m_clipref->selectedEffectIndex())
476 m_clipref->setSelectedEffect(ix);
477 for (int i = 0; i < m_effects.count(); i++) {
478 if (m_effects.at(i)->effectIndex() == ix) {
479 m_effects.at(i)->setActive(true);
480 m_ui.labelComment->setText(i18n(m_effects.at(i)->effect().firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
481 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
483 else m_effects.at(i)->setActive(false);
487 void EffectStackView2::slotDeleteEffect(const QDomElement effect)
489 if (m_effectMetaInfo.trackMode)
490 emit removeEffect(NULL, m_trackindex, effect);
492 emit removeEffect(m_clipref, -1, effect);
495 void EffectStackView2::slotAddEffect(QDomElement effect)
497 emit addEffect(m_clipref, effect);
500 void EffectStackView2::slotMoveEffectUp(int index, bool up)
502 if (up && index <= 1) return;
503 if (!up && index >= m_currentEffectList.count()) return;
511 if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, index, endPos);
512 else emit changeEffectPosition(m_clipref, -1, index, endPos);
515 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
517 if (!m_clipref) return;
518 emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, finalFilterName, consumer, consumerParams, properties);
521 void EffectStackView2::slotResetEffect(int ix)
523 QDomElement old = m_currentEffectList.itemFromIndex(ix);
525 QString effectId = old.attribute("id");
526 QMap<QString, EffectsList*> effectLists;
527 effectLists["audio"] = &MainWindow::audioEffects;
528 effectLists["video"] = &MainWindow::videoEffects;
529 effectLists["custom"] = &MainWindow::customEffects;
530 foreach(const QString &type, effectLists.keys()) {
531 EffectsList *list = effectLists[type];
532 dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
533 if (!dom.isNull()) break;
536 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
537 if (m_effectMetaInfo.trackMode) {
538 EffectsList::setParameter(dom, "in", QString::number(0));
539 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
541 info.track = m_trackInfo.type;
542 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
543 info.cropStart = GenTime(0);
544 info.startPos = GenTime(-1);
546 m_effects.at(ix)->updateWidget(info, dom, &m_effectMetaInfo);
547 emit updateEffect(NULL, m_trackindex, old, dom, ix);
549 m_clipref->initEffect(dom);
550 m_effects.at(ix)->updateWidget(m_clipref->info(), dom, &m_effectMetaInfo);
551 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
552 emit updateEffect(m_clipref, -1, old, dom, ix);
556 emit showComments(m_ui.buttonShowComments->isChecked());
557 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
560 void EffectStackView2::slotShowComments()
562 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
563 emit showComments(m_ui.buttonShowComments->isChecked());
566 void EffectStackView2::slotCreateGroup(int ix)
568 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
569 QDomElement neweffect = oldeffect.cloneNode().toElement();
570 EffectInfo effectinfo;
571 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
572 effectinfo.groupIndex = m_groupIndex;
573 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
576 if (m_effectMetaInfo.trackMode) {
577 info.track = m_trackInfo.type;
578 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
579 info.cropStart = GenTime(0);
580 info.startPos = GenTime(-1);
582 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix);
584 emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix);
587 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
589 CollapsibleEffect *effectToMove = NULL;
590 for (int i = 0; i < m_effects.count(); i++) {
591 if (m_effects.at(i)->effectIndex() == ix) {
592 effectToMove = m_effects.at(i);
593 groupPos = l->indexOf(effectToMove);
594 l->removeWidget(effectToMove);
599 CollapsibleGroup *group = new CollapsibleGroup(m_groupIndex, ix == 1, ix == m_currentEffectList.count() - 2, m_ui.container->widget());
601 connect(group, SIGNAL(moveEffect(int,int,int)), this , SLOT(slotMoveEffect(int,int,int)));
602 connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
603 l->insertWidget(groupPos, group);
604 group->addGroupEffect(effectToMove);
607 void EffectStackView2::slotMoveEffect(int currentIndex, int newIndex, int groupIndex)
609 CollapsibleEffect *effectToMove = getEffectByIndex(currentIndex);
610 if (effectToMove == NULL) return;
612 QDomElement oldeffect = effectToMove->effect();
613 QDomElement neweffect = oldeffect.cloneNode().toElement();
615 EffectInfo effectinfo;
616 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
617 effectinfo.groupIndex = groupIndex;
618 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
621 if (m_effectMetaInfo.trackMode) {
622 info.track = m_trackInfo.type;
623 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
624 info.cropStart = GenTime(0);
625 info.startPos = GenTime(-1);
627 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->effectIndex());
629 emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex());
632 //if (currentIndex == newIndex) return;
633 // Update effect index with new position
634 if (m_effectMetaInfo.trackMode) {
635 emit changeEffectPosition(NULL, m_trackindex, currentIndex, newIndex);
638 emit changeEffectPosition(m_clipref, -1, currentIndex, newIndex);
642 void EffectStackView2::slotUnGroup(CollapsibleGroup* group)
644 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
645 int ix = l->indexOf(group);
646 group->removeGroup(ix, l);
647 group->deleteLater();
650 #include "effectstackview2.moc"