1 /***************************************************************************
2 effecstackview.cpp2 - description
5 copyright : (C) 2008 by Marco Gittler (g.marco@freenet.de)
6 copyright : (C) 2012 by Jean-Baptiste Mardelle (jb@kdenlive.org)
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),
54 m_effectMetaInfo.trackMode = false;
55 m_effectMetaInfo.monitor = monitor;
56 m_effects = QList <CollapsibleEffect*>();
60 setFont(KGlobalSettings::smallestReadableFont());
61 m_ui.checkAll->setToolTip(i18n("Enable/Disable all effects"));
62 m_ui.buttonShowComments->setIcon(KIcon("help-about"));
63 m_ui.buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
65 connect(m_ui.checkAll, SIGNAL(stateChanged(int)), this, SLOT(slotCheckAll(int)));
66 connect(m_ui.buttonShowComments, SIGNAL(clicked()), this, SLOT(slotShowComments()));
67 m_ui.labelComment->setHidden(true);
72 setStyleSheet(CollapsibleEffect::getStyleSheet());
75 EffectStackView2::~EffectStackView2()
79 void EffectStackView2::updatePalette()
81 setStyleSheet(CollapsibleEffect::getStyleSheet());
84 void EffectStackView2::slotRenderPos(int pos)
86 if (m_effects.isEmpty()) return;
87 if (!m_effectMetaInfo.trackMode && m_clipref) pos = pos - m_clipref->startPos().frames(KdenliveSettings::project_fps());
89 for (int i = 0; i< m_effects.count(); i++)
90 m_effects.at(i)->slotSyncEffectsPos(pos);
93 void EffectStackView2::slotClipItemSelected(ClipItem* c)
95 if (c && !c->isEnabled()) return;
96 if (c && c == m_clipref) {
101 QString cname = m_clipref->clipName();
102 if (cname.length() > 30) {
103 m_ui.checkAll->setToolTip(i18n("Effects for %1").arg(cname));
105 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "...");
107 m_ui.checkAll->setToolTip(QString());
108 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
110 m_ui.checkAll->setEnabled(true);
111 QString size = c->baseClip()->getProperty("frame_size");
112 double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
113 m_effectMetaInfo.frameSize = QPoint((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
116 if (m_clipref == NULL) {
117 //TODO: clear list, reset paramdesc and info
119 //m_effectedit->transferParamDesc(QDomElement(), info);
124 m_effectMetaInfo.trackMode = false;
125 m_currentEffectList = m_clipref->effectList();
129 void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
132 m_effectMetaInfo.trackMode = true;
133 m_currentEffectList = info.effectsList;
136 m_ui.checkAll->setToolTip(QString());
137 m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
143 void EffectStackView2::setupListView()
146 m_draggedEffect = NULL;
147 m_draggedGroup = NULL;
148 disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
151 QWidget *view = m_ui.container->takeWidget();
156 view = new QWidget(m_ui.container);
157 m_ui.container->setWidget(view);
159 QVBoxLayout *vbox1 = new QVBoxLayout(view);
160 vbox1->setContentsMargins(0, 0, 0, 0);
161 vbox1->setSpacing(0);
163 if (m_currentEffectList.isEmpty()) m_ui.labelComment->setHidden(true);
165 for (int i = 0; i < m_currentEffectList.count(); i++) {
166 QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
168 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
172 CollapsibleGroup *group = NULL;
173 EffectInfo effectInfo;
174 effectInfo.fromString(d.attribute("kdenlive_info"));
175 if (effectInfo.groupIndex >= 0) {
176 // effect is in a group
177 for (int j = 0; j < vbox1->count(); j++) {
178 CollapsibleGroup *eff = static_cast<CollapsibleGroup *>(vbox1->itemAt(j)->widget());
179 if (eff->isGroup() && eff->groupIndex() == effectInfo.groupIndex) {
186 group = new CollapsibleGroup(effectInfo.groupIndex, i == 0, i == m_currentEffectList.count() - 1, effectInfo, m_ui.container->widget());
188 vbox1->addWidget(group);
189 group->installEventFilter( this );
191 if (effectInfo.groupIndex >= m_groupIndex) m_groupIndex = effectInfo.groupIndex + 1;
195 doc.appendChild(doc.importNode(d, true));
196 kDebug() << "IMPORTED STK: " << doc.toString();*/
199 bool isSelected = false;
200 if (m_effectMetaInfo.trackMode) {
201 info.track = m_trackInfo.type;
202 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
203 info.cropStart = GenTime(0);
204 info.startPos = GenTime(-1);
208 info = m_clipref->info();
211 CollapsibleEffect *currentEffect = new CollapsibleEffect(d, m_currentEffectList.at(i), info, &m_effectMetaInfo, i == m_currentEffectList.count() - 1, view);
212 if (m_effectMetaInfo.trackMode) {
213 isSelected = currentEffect->effectIndex() == 1;
216 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
218 if (isSelected) currentEffect->setActive(true);
219 m_effects.append(currentEffect);
221 group->addGroupEffect(currentEffect);
223 vbox1->addWidget(currentEffect);
225 connectEffect(currentEffect);
227 vbox1->addStretch(10);
228 slotUpdateCheckAllButton();
229 connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
231 // Wait a little bit for the new layout to be ready, then check if we have a scrollbar
232 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
235 void EffectStackView2::connectEffect(CollapsibleEffect *currentEffect)
238 currentEffect->installEventFilter( this );
239 connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
240 connect(currentEffect, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,QString,QString)));
241 connect(currentEffect, SIGNAL(deleteEffect(const QDomElement)), this , SLOT(slotDeleteEffect(const QDomElement)));
242 connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
243 connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
244 connect(currentEffect, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
245 connect(currentEffect, SIGNAL(effectStateChanged(bool,int,bool)), this, SLOT(slotUpdateEffectState(bool,int,bool)));
246 connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
247 connect(currentEffect, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
248 connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
249 connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
250 connect(currentEffect, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
251 connect(currentEffect, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
252 connect(currentEffect, SIGNAL(createRegion(int,KUrl)), this, SLOT(slotCreateRegion(int,KUrl)));
253 connect(currentEffect, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
256 void EffectStackView2::slotCheckWheelEventFilter()
258 // If the effect stack widget has no scrollbar, we will not filter the
259 // mouse wheel events, so that user can easily adjust effect params
260 bool filterWheelEvent = false;
261 if (m_ui.container->verticalScrollBar() && m_ui.container->verticalScrollBar()->isVisible()) {
262 // widget has scroll bar,
263 filterWheelEvent = true;
265 for (int i = 0; i < m_effects.count(); i++) {
266 m_effects.at(i)->filterWheelEvent = filterWheelEvent;
270 void EffectStackView2::resizeEvent ( QResizeEvent * event )
272 slotCheckWheelEventFilter();
273 QWidget::resizeEvent(event);
276 bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
278 // Check if user clicked in an effect's top bar to start dragging it
279 if (e->type() == QEvent::MouseButtonPress) {
280 m_draggedEffect = qobject_cast<CollapsibleEffect*>(o);
281 if (m_draggedEffect) {
282 QMouseEvent *me = static_cast<QMouseEvent *>(e);
283 if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse())) {
284 m_clickPoint = me->globalPos();
287 m_clickPoint = QPoint();
288 m_draggedEffect = NULL;
293 m_draggedGroup = qobject_cast<CollapsibleGroup*>(o);
294 if (m_draggedGroup) {
295 QMouseEvent *me = static_cast<QMouseEvent *>(e);
296 if (me->button() == Qt::LeftButton && (m_draggedGroup->frame->underMouse() || m_draggedGroup->title()->underMouse()))
297 m_clickPoint = me->globalPos();
299 m_clickPoint = QPoint();
300 m_draggedGroup = NULL;
306 /*if (e->type() == QEvent::MouseMove) {
307 if (qobject_cast<CollapsibleEffect*>(o)) {
308 QMouseEvent *me = static_cast<QMouseEvent *>(e);
309 if (me->buttons() != Qt::LeftButton) {
319 return QWidget::eventFilter(o, e);
322 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
324 if (m_draggedEffect || m_draggedGroup) {
325 if ((event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
331 void EffectStackView2::mouseReleaseEvent(QMouseEvent * event)
333 m_draggedEffect = NULL;
334 m_draggedGroup = NULL;
335 QWidget::mouseReleaseEvent(event);
338 void EffectStackView2::startDrag()
340 // The data to be transferred by the drag and drop operation is contained in a QMimeData object
343 if (m_draggedEffect) {
344 QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
345 doc.appendChild(doc.importNode(effect, true));
346 pixmap = QPixmap::grabWidget(m_draggedEffect->title);
348 else if (m_draggedGroup) {
349 doc = m_draggedGroup->effectsData();
350 pixmap = QPixmap::grabWidget(m_draggedGroup->title());
353 QDrag *drag = new QDrag(this);
354 drag->setPixmap(pixmap);
355 QMimeData *mime = new QMimeData;
357 data.append(doc.toString().toUtf8());
358 mime->setData("kdenlive/effectslist", data);
360 // Assign ownership of the QMimeData object to the QDrag object.
361 drag->setMimeData(mime);
362 // Start the drag and drop operation
363 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
367 void EffectStackView2::slotUpdateEffectState(bool disable, int index, bool updateMainStatus)
369 if (m_effectMetaInfo.trackMode)
370 emit changeEffectState(NULL, m_trackindex, index, disable);
372 emit changeEffectState(m_clipref, -1, index, disable);
373 if (updateMainStatus) slotUpdateCheckAllButton();
377 void EffectStackView2::raiseWindow(QWidget* dock)
379 if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
384 void EffectStackView2::slotSeekTimeline(int pos)
386 if (m_effectMetaInfo.trackMode) {
387 emit seekTimeline(pos);
388 } else if (m_clipref) {
389 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
394 /*void EffectStackView2::slotRegionChanged()
396 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
399 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
401 if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
402 if (!m_effectMetaInfo.monitor->getEffectEdit()->getScene()->views().at(0)->isVisible())
403 m_effectMetaInfo.monitor->slotEffectScene(true);
405 m_effectMetaInfo.monitor->slotEffectScene(false);
409 int EffectStackView2::isTrackMode(bool *ok) const
411 *ok = m_effectMetaInfo.trackMode;
415 void EffectStackView2::clear()
418 QWidget *view = m_ui.container->takeWidget();
422 m_ui.checkAll->setToolTip(QString());
423 m_ui.checkAll->setText(QString());
424 m_ui.checkAll->setEnabled(false);
425 m_ui.labelComment->setText(QString());
429 void EffectStackView2::slotCheckAll(int state)
431 if (state == Qt::PartiallyChecked) {
433 m_ui.checkAll->blockSignals(true);
434 m_ui.checkAll->setCheckState(Qt::Checked);
435 m_ui.checkAll->blockSignals(false);
438 bool disabled = state == Qt::Unchecked;
439 for (int i = 0; i < m_effects.count(); i++) {
440 if (!m_effects.at(i)->isGroup()) {
441 m_effects.at(i)->slotEnable(disabled, false);
446 void EffectStackView2::slotUpdateCheckAllButton()
448 bool hasEnabled = false;
449 bool hasDisabled = false;
451 for (int i = 0; i < m_effects.count(); i++) {
452 if (!m_effects.at(i)->enabledButton->isChecked()) hasEnabled = true;
453 else hasDisabled = true;
456 m_ui.checkAll->blockSignals(true);
457 if (hasEnabled && hasDisabled)
458 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
460 m_ui.checkAll->setCheckState(Qt::Checked);
462 m_ui.checkAll->setCheckState(Qt::Unchecked);
463 m_ui.checkAll->blockSignals(false);
466 void EffectStackView2::deleteCurrentEffect()
468 for (int i = 0; i < m_effects.count(); i++) {
469 if (m_effects.at(i)->isActive()) {
470 slotDeleteEffect(m_effects.at(i)->effect());
476 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
478 m_effectMetaInfo.profile = profile;
479 m_effectMetaInfo.timecode = t;
482 void EffectStackView2::updateTimecodeFormat()
484 for (int i = 0; i< m_effects.count(); i++)
485 m_effects.at(i)->updateTimecodeFormat();
488 CollapsibleEffect *EffectStackView2::getEffectByIndex(int ix)
490 for (int i = 0; i< m_effects.count(); i++) {
491 if (m_effects.at(i)->effectIndex() == ix) {
492 return m_effects.at(i);
498 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
500 if (m_effectMetaInfo.trackMode)
501 emit updateEffect(NULL, m_trackindex, old, e, ix,false);
502 else if (m_clipref) {
503 emit updateEffect(m_clipref, -1, old, e, ix, false);
504 // Make sure the changed effect is currently displayed
505 slotSetCurrentEffect(ix);
507 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
510 void EffectStackView2::slotSetCurrentEffect(int ix)
512 if (m_clipref && ix != m_clipref->selectedEffectIndex()) {
513 m_clipref->setSelectedEffect(ix);
514 for (int i = 0; i < m_effects.count(); i++) {
515 if (m_effects.at(i)->effectIndex() == ix) {
516 m_effects.at(i)->setActive(true);
517 m_ui.labelComment->setText(i18n(m_effects.at(i)->effect().firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
518 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
520 else m_effects.at(i)->setActive(false);
525 void EffectStackView2::slotDeleteGroup(QDomDocument doc)
527 QDomNodeList effects = doc.elementsByTagName("effect");
528 ClipItem * clip = NULL;
530 if (m_effectMetaInfo.trackMode) {
538 for (int i = 0; i < effects.count(); i++)
539 emit removeEffect(clip, ix, effects.at(i).toElement());
542 void EffectStackView2::slotDeleteEffect(const QDomElement effect)
544 if (m_effectMetaInfo.trackMode)
545 emit removeEffect(NULL, m_trackindex, effect);
547 emit removeEffect(m_clipref, -1, effect);
550 void EffectStackView2::slotAddEffect(QDomElement effect)
552 emit addEffect(m_clipref, effect);
555 void EffectStackView2::slotMoveEffectUp(QList <int> indexes, bool up)
557 if (up && indexes.first() <= 1) return;
558 if (!up && indexes.last() >= m_currentEffectList.count()) return;
561 endPos = indexes.first() - 1;
564 endPos = indexes.last() + 1;
566 if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, indexes, endPos);
567 else emit changeEffectPosition(m_clipref, -1, indexes, endPos);
570 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
572 if (!m_clipref) return;
573 emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, finalFilterName, consumer, consumerParams, properties);
576 void EffectStackView2::slotResetEffect(int ix)
578 QDomElement old = m_currentEffectList.itemFromIndex(ix);
580 QString effectId = old.attribute("id");
581 QMap<QString, EffectsList*> effectLists;
582 effectLists["audio"] = &MainWindow::audioEffects;
583 effectLists["video"] = &MainWindow::videoEffects;
584 effectLists["custom"] = &MainWindow::customEffects;
585 foreach(const QString &type, effectLists.keys()) {
586 EffectsList *list = effectLists[type];
587 dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
588 if (!dom.isNull()) break;
591 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
592 if (m_effectMetaInfo.trackMode) {
593 EffectsList::setParameter(dom, "in", QString::number(0));
594 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
596 info.track = m_trackInfo.type;
597 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
598 info.cropStart = GenTime(0);
599 info.startPos = GenTime(-1);
601 m_effects.at(ix)->updateWidget(info, dom, &m_effectMetaInfo);
602 emit updateEffect(NULL, m_trackindex, old, dom, ix,false);
604 m_clipref->initEffect(dom);
605 for (int i = 0; i < m_effects.count(); i++) {
606 if (m_effects.at(i)->effectIndex() == ix) {
607 m_effects.at(i)->updateWidget(m_clipref->info(), dom, &m_effectMetaInfo);
611 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
612 emit updateEffect(m_clipref, -1, old, dom, ix,false);
616 emit showComments(m_ui.buttonShowComments->isChecked());
617 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
620 void EffectStackView2::slotShowComments()
622 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
623 emit showComments(m_ui.buttonShowComments->isChecked());
626 void EffectStackView2::slotCreateRegion(int ix, KUrl url)
628 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
629 QDomElement neweffect = oldeffect.cloneNode().toElement();
630 QDomElement region = MainWindow::videoEffects.getEffectByTag("region", "region").cloneNode().toElement();
631 region.appendChild(region.ownerDocument().importNode(neweffect, true));
632 region.setAttribute("kdenlive_ix", ix);
633 EffectsList::setParameter(region, "resource", url.path());
634 if (m_effectMetaInfo.trackMode)
635 emit updateEffect(NULL, m_trackindex, oldeffect, region, ix,false);
636 else if (m_clipref) {
637 emit updateEffect(m_clipref, -1, oldeffect, region, ix, false);
638 // Make sure the changed effect is currently displayed
639 //slotSetCurrentEffect(ix);
641 // refresh effect stack
643 bool isSelected = false;
644 if (m_effectMetaInfo.trackMode) {
645 info.track = m_trackInfo.type;
646 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
647 info.cropStart = GenTime(0);
648 info.startPos = GenTime(-1);
652 info = m_clipref->info();
654 CollapsibleEffect *current = getEffectByIndex(ix);
655 m_effects.removeAll(current);
656 current->setEnabled(false);
657 m_currentEffectList.removeAt(ix);
658 m_currentEffectList.insert(region);
659 current->deleteLater();
660 CollapsibleEffect *currentEffect = new CollapsibleEffect(region, m_currentEffectList.itemFromIndex(ix), info, &m_effectMetaInfo, ix == m_currentEffectList.count() - 1, m_ui.container->widget());
661 connectEffect(currentEffect);
663 if (m_effectMetaInfo.trackMode) {
664 isSelected = currentEffect->effectIndex() == 1;
667 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
669 if (isSelected) currentEffect->setActive(true);
670 m_effects.append(currentEffect);
671 // TODO: region in group?
673 // group->addGroupEffect(currentEffect);
675 QVBoxLayout *vbox = static_cast <QVBoxLayout *> (m_ui.container->widget()->layout());
676 vbox->insertWidget(ix, currentEffect);
680 currentEffect->installEventFilter( this );
682 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
686 void EffectStackView2::slotCreateGroup(int ix)
688 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
689 QDomElement neweffect = oldeffect.cloneNode().toElement();
690 EffectInfo effectinfo;
691 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
692 effectinfo.groupIndex = m_groupIndex;
693 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
696 if (m_effectMetaInfo.trackMode) {
697 info.track = m_trackInfo.type;
698 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
699 info.cropStart = GenTime(0);
700 info.startPos = GenTime(-1);
702 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix, false);
704 emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix, false);
707 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
709 CollapsibleEffect *effectToMove = NULL;
710 for (int i = 0; i < m_effects.count(); i++) {
711 if (m_effects.at(i)->effectIndex() == ix) {
712 effectToMove = m_effects.at(i);
713 groupPos = l->indexOf(effectToMove);
714 l->removeWidget(effectToMove);
719 CollapsibleGroup *group = new CollapsibleGroup(m_groupIndex, ix == 1, ix == m_currentEffectList.count() - 2, effectinfo, m_ui.container->widget());
722 l->insertWidget(groupPos, group);
723 group->installEventFilter( this );
724 group->addGroupEffect(effectToMove);
727 void EffectStackView2::connectGroup(CollapsibleGroup *group)
729 connect(group, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
730 connect(group, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
731 connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
732 connect(group, SIGNAL(groupRenamed(CollapsibleGroup *)), this , SLOT(slotRenameGroup(CollapsibleGroup*)));
733 connect(group, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
734 connect(group, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
735 connect(group, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
738 void EffectStackView2::slotMoveEffect(QList <int> currentIndexes, int newIndex, int groupIndex, QString groupName)
740 if (currentIndexes.count() == 1) {
741 CollapsibleEffect *effectToMove = getEffectByIndex(currentIndexes.at(0));
742 if (effectToMove == NULL) return;
744 QDomElement oldeffect = effectToMove->effect();
745 QDomElement neweffect = oldeffect.cloneNode().toElement();
747 EffectInfo effectinfo;
748 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
749 effectinfo.groupIndex = groupIndex;
750 effectinfo.groupName = groupName;
751 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
753 if (oldeffect.attribute("kdenlive_info") != effectinfo.toString()) {
754 // effect's group info or collapsed state changed
756 if (m_effectMetaInfo.trackMode) {
757 info.track = m_trackInfo.type;
758 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
759 info.cropStart = GenTime(0);
760 info.startPos = GenTime(-1);
762 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->effectIndex(),false);
764 emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex(),false);
769 // Update effect index with new position
770 if (m_effectMetaInfo.trackMode) {
771 emit changeEffectPosition(NULL, m_trackindex, currentIndexes, newIndex);
774 emit changeEffectPosition(m_clipref, -1, currentIndexes, newIndex);
778 void EffectStackView2::slotUnGroup(CollapsibleGroup* group)
780 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
781 int ix = l->indexOf(group);
782 group->removeGroup(ix, l);
783 group->deleteLater();
786 void EffectStackView2::slotRenameGroup(CollapsibleGroup *group)
788 QList <CollapsibleEffect*> effects = group->effects();
789 for (int i = 0; i < effects.count(); i++) {
790 QDomElement origin = effects.at(i)->effect();
791 QDomElement changed = origin.cloneNode().toElement();
792 changed.setAttribute("kdenlive_info", effects.at(i)->infoString());
793 if (m_effectMetaInfo.trackMode) {
794 emit updateEffect(NULL, m_trackindex, origin, changed, effects.at(i)->effectIndex(),false);
796 emit updateEffect(m_clipref, -1, origin, changed, effects.at(i)->effectIndex(),false);
801 void EffectStackView2::dragEnterEvent(QDragEnterEvent *event)
803 if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
804 event->acceptProposedAction();
808 void EffectStackView2::processDroppedEffect(QDomElement e, QDropEvent *event)
810 int ix = e.attribute("kdenlive_ix").toInt();
811 if (e.tagName() == "effectgroup") {
812 // We are dropping a group, all effects in group should be moved
813 QDomNodeList effects = e.elementsByTagName("effect");
814 if (effects.count() == 0) {
819 info.fromString(effects.at(0).toElement().attribute("kdenlive_info"));
820 if (info.groupIndex < 0) {
821 kDebug()<<"// ADDING EFFECT!!!";
822 // Adding a new group effect to the stack
823 event->setDropAction(Qt::CopyAction);
828 // Moving group: delete all effects and re-add them
830 for (int i = 0; i < effects.count(); i++) {
831 QDomElement effect = effects.at(i).cloneNode().toElement();
832 indexes << effect.attribute("kdenlive_ix").toInt();
834 kDebug()<<"// Moving: "<<indexes<<" TO "<<m_currentEffectList.count();
835 slotMoveEffect(indexes, m_currentEffectList.count(), info.groupIndex, info.groupName);
838 // effect dropped from effects list, add it
839 e.setAttribute("kdenlive_ix", m_currentEffectList.count() + 1);
840 event->setDropAction(Qt::CopyAction);
846 // User is moving an effect
847 slotMoveEffect(QList<int> () << ix, m_currentEffectList.count() + 1, -1);
849 event->setDropAction(Qt::MoveAction);
853 void EffectStackView2::dropEvent(QDropEvent *event)
855 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
856 //event->acceptProposedAction();
858 doc.setContent(effects, true);
859 processDroppedEffect(doc.documentElement(), event);
862 #include "effectstackview2.moc"