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);
228 // Adjust group effects (up / down buttons)
229 QList<CollapsibleGroup *> allGroups = m_ui.container->widget()->findChildren<CollapsibleGroup *>();
230 for (int i = 0; i < allGroups.count(); i++) {
231 allGroups.at(i)->adjustEffects();
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()));
242 void EffectStackView2::connectEffect(CollapsibleEffect *currentEffect)
245 currentEffect->installEventFilter( this );
246 connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
247 connect(currentEffect, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,QString,QString)));
248 connect(currentEffect, SIGNAL(deleteEffect(const QDomElement)), this , SLOT(slotDeleteEffect(const QDomElement)));
249 connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
250 connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
251 connect(currentEffect, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
252 connect(currentEffect, SIGNAL(effectStateChanged(bool,int,bool)), this, SLOT(slotUpdateEffectState(bool,int,bool)));
253 connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
254 connect(currentEffect, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
255 connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
256 connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
257 connect(currentEffect, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
258 connect(currentEffect, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
259 connect(currentEffect, SIGNAL(createRegion(int,KUrl)), this, SLOT(slotCreateRegion(int,KUrl)));
260 connect(currentEffect, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
263 void EffectStackView2::slotCheckWheelEventFilter()
265 // If the effect stack widget has no scrollbar, we will not filter the
266 // mouse wheel events, so that user can easily adjust effect params
267 bool filterWheelEvent = false;
268 if (m_ui.container->verticalScrollBar() && m_ui.container->verticalScrollBar()->isVisible()) {
269 // widget has scroll bar,
270 filterWheelEvent = true;
272 for (int i = 0; i < m_effects.count(); i++) {
273 m_effects.at(i)->filterWheelEvent = filterWheelEvent;
277 void EffectStackView2::resizeEvent ( QResizeEvent * event )
279 slotCheckWheelEventFilter();
280 QWidget::resizeEvent(event);
283 bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
285 // Check if user clicked in an effect's top bar to start dragging it
286 if (e->type() == QEvent::MouseButtonPress) {
287 m_draggedEffect = qobject_cast<CollapsibleEffect*>(o);
288 if (m_draggedEffect) {
289 QMouseEvent *me = static_cast<QMouseEvent *>(e);
290 if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse())) {
291 m_clickPoint = me->globalPos();
294 m_clickPoint = QPoint();
295 m_draggedEffect = NULL;
300 m_draggedGroup = qobject_cast<CollapsibleGroup*>(o);
301 if (m_draggedGroup) {
302 QMouseEvent *me = static_cast<QMouseEvent *>(e);
303 if (me->button() == Qt::LeftButton && (m_draggedGroup->frame->underMouse() || m_draggedGroup->title()->underMouse()))
304 m_clickPoint = me->globalPos();
306 m_clickPoint = QPoint();
307 m_draggedGroup = NULL;
313 /*if (e->type() == QEvent::MouseMove) {
314 if (qobject_cast<CollapsibleEffect*>(o)) {
315 QMouseEvent *me = static_cast<QMouseEvent *>(e);
316 if (me->buttons() != Qt::LeftButton) {
326 return QWidget::eventFilter(o, e);
329 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
331 if (m_draggedEffect || m_draggedGroup) {
332 if ((event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
338 void EffectStackView2::mouseReleaseEvent(QMouseEvent * event)
340 m_draggedEffect = NULL;
341 m_draggedGroup = NULL;
342 QWidget::mouseReleaseEvent(event);
345 void EffectStackView2::startDrag()
347 // The data to be transferred by the drag and drop operation is contained in a QMimeData object
350 if (m_draggedEffect) {
351 QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
352 doc.appendChild(doc.importNode(effect, true));
353 pixmap = QPixmap::grabWidget(m_draggedEffect->title);
355 else if (m_draggedGroup) {
356 doc = m_draggedGroup->effectsData();
357 pixmap = QPixmap::grabWidget(m_draggedGroup->title());
360 QDrag *drag = new QDrag(this);
361 drag->setPixmap(pixmap);
362 QMimeData *mime = new QMimeData;
364 data.append(doc.toString().toUtf8());
365 mime->setData("kdenlive/effectslist", data);
367 // Assign ownership of the QMimeData object to the QDrag object.
368 drag->setMimeData(mime);
369 // Start the drag and drop operation
370 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
374 void EffectStackView2::slotUpdateEffectState(bool disable, int index, bool updateMainStatus)
376 if (m_effectMetaInfo.trackMode)
377 emit changeEffectState(NULL, m_trackindex, index, disable);
379 emit changeEffectState(m_clipref, -1, index, disable);
380 if (updateMainStatus) slotUpdateCheckAllButton();
384 void EffectStackView2::raiseWindow(QWidget* dock)
386 if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
391 void EffectStackView2::slotSeekTimeline(int pos)
393 if (m_effectMetaInfo.trackMode) {
394 emit seekTimeline(pos);
395 } else if (m_clipref) {
396 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
401 /*void EffectStackView2::slotRegionChanged()
403 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
406 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
408 if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
409 if (!m_effectMetaInfo.monitor->getEffectEdit()->getScene()->views().at(0)->isVisible())
410 m_effectMetaInfo.monitor->slotEffectScene(true);
412 m_effectMetaInfo.monitor->slotEffectScene(false);
416 int EffectStackView2::isTrackMode(bool *ok) const
418 *ok = m_effectMetaInfo.trackMode;
422 void EffectStackView2::clear()
425 QWidget *view = m_ui.container->takeWidget();
429 m_ui.checkAll->setToolTip(QString());
430 m_ui.checkAll->setText(QString());
431 m_ui.checkAll->setEnabled(false);
432 m_ui.labelComment->setText(QString());
436 void EffectStackView2::slotCheckAll(int state)
438 if (state == Qt::PartiallyChecked) {
440 m_ui.checkAll->blockSignals(true);
441 m_ui.checkAll->setCheckState(Qt::Checked);
442 m_ui.checkAll->blockSignals(false);
445 bool disabled = state == Qt::Unchecked;
446 for (int i = 0; i < m_effects.count(); i++) {
447 if (!m_effects.at(i)->isGroup()) {
448 m_effects.at(i)->slotEnable(disabled, false);
453 void EffectStackView2::slotUpdateCheckAllButton()
455 bool hasEnabled = false;
456 bool hasDisabled = false;
458 for (int i = 0; i < m_effects.count(); i++) {
459 if (!m_effects.at(i)->enabledButton->isChecked()) hasEnabled = true;
460 else hasDisabled = true;
463 m_ui.checkAll->blockSignals(true);
464 if (hasEnabled && hasDisabled)
465 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
467 m_ui.checkAll->setCheckState(Qt::Checked);
469 m_ui.checkAll->setCheckState(Qt::Unchecked);
470 m_ui.checkAll->blockSignals(false);
473 void EffectStackView2::deleteCurrentEffect()
475 for (int i = 0; i < m_effects.count(); i++) {
476 if (m_effects.at(i)->isActive()) {
477 slotDeleteEffect(m_effects.at(i)->effect());
483 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
485 m_effectMetaInfo.profile = profile;
486 m_effectMetaInfo.timecode = t;
489 void EffectStackView2::updateTimecodeFormat()
491 for (int i = 0; i< m_effects.count(); i++)
492 m_effects.at(i)->updateTimecodeFormat();
495 CollapsibleEffect *EffectStackView2::getEffectByIndex(int ix)
497 for (int i = 0; i< m_effects.count(); i++) {
498 if (m_effects.at(i)->effectIndex() == ix) {
499 return m_effects.at(i);
505 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
507 if (m_effectMetaInfo.trackMode)
508 emit updateEffect(NULL, m_trackindex, old, e, ix,false);
509 else if (m_clipref) {
510 emit updateEffect(m_clipref, -1, old, e, ix, false);
511 // Make sure the changed effect is currently displayed
512 slotSetCurrentEffect(ix);
514 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
517 void EffectStackView2::slotSetCurrentEffect(int ix)
519 if (m_clipref && ix != m_clipref->selectedEffectIndex()) {
520 m_clipref->setSelectedEffect(ix);
521 for (int i = 0; i < m_effects.count(); i++) {
522 if (m_effects.at(i)->effectIndex() == ix) {
523 m_effects.at(i)->setActive(true);
524 m_ui.labelComment->setText(i18n(m_effects.at(i)->effect().firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
525 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
527 else m_effects.at(i)->setActive(false);
532 void EffectStackView2::slotDeleteGroup(QDomDocument doc)
534 QDomNodeList effects = doc.elementsByTagName("effect");
535 ClipItem * clip = NULL;
537 if (m_effectMetaInfo.trackMode) {
545 for (int i = 0; i < effects.count(); i++)
546 emit removeEffect(clip, ix, effects.at(i).toElement());
549 void EffectStackView2::slotDeleteEffect(const QDomElement effect)
551 if (m_effectMetaInfo.trackMode)
552 emit removeEffect(NULL, m_trackindex, effect);
554 emit removeEffect(m_clipref, -1, effect);
557 void EffectStackView2::slotAddEffect(QDomElement effect)
559 emit addEffect(m_clipref, effect);
562 void EffectStackView2::slotMoveEffectUp(QList <int> indexes, bool up)
564 if (up && indexes.first() <= 1) return;
565 if (!up && indexes.last() >= m_currentEffectList.count()) return;
568 endPos = indexes.first() - 1;
571 endPos = indexes.last() + 1;
573 if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, indexes, endPos);
574 else emit changeEffectPosition(m_clipref, -1, indexes, endPos);
577 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
579 if (!m_clipref) return;
580 emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, finalFilterName, consumer, consumerParams, properties);
583 void EffectStackView2::slotResetEffect(int ix)
585 QDomElement old = m_currentEffectList.itemFromIndex(ix);
587 QString effectId = old.attribute("id");
588 QMap<QString, EffectsList*> effectLists;
589 effectLists["audio"] = &MainWindow::audioEffects;
590 effectLists["video"] = &MainWindow::videoEffects;
591 effectLists["custom"] = &MainWindow::customEffects;
592 foreach(const QString &type, effectLists.keys()) {
593 EffectsList *list = effectLists[type];
594 dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
595 if (!dom.isNull()) break;
598 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
599 if (m_effectMetaInfo.trackMode) {
600 EffectsList::setParameter(dom, "in", QString::number(0));
601 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
603 info.track = m_trackInfo.type;
604 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
605 info.cropStart = GenTime(0);
606 info.startPos = GenTime(-1);
608 m_effects.at(ix)->updateWidget(info, dom, &m_effectMetaInfo);
609 emit updateEffect(NULL, m_trackindex, old, dom, ix,false);
611 m_clipref->initEffect(dom);
612 for (int i = 0; i < m_effects.count(); i++) {
613 if (m_effects.at(i)->effectIndex() == ix) {
614 m_effects.at(i)->updateWidget(m_clipref->info(), dom, &m_effectMetaInfo);
618 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
619 emit updateEffect(m_clipref, -1, old, dom, ix,false);
623 emit showComments(m_ui.buttonShowComments->isChecked());
624 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
627 void EffectStackView2::slotShowComments()
629 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
630 emit showComments(m_ui.buttonShowComments->isChecked());
633 void EffectStackView2::slotCreateRegion(int ix, KUrl url)
635 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
636 QDomElement neweffect = oldeffect.cloneNode().toElement();
637 QDomElement region = MainWindow::videoEffects.getEffectByTag("region", "region").cloneNode().toElement();
638 region.appendChild(region.ownerDocument().importNode(neweffect, true));
639 region.setAttribute("kdenlive_ix", ix);
640 EffectsList::setParameter(region, "resource", url.path());
641 if (m_effectMetaInfo.trackMode)
642 emit updateEffect(NULL, m_trackindex, oldeffect, region, ix,false);
643 else if (m_clipref) {
644 emit updateEffect(m_clipref, -1, oldeffect, region, ix, false);
645 // Make sure the changed effect is currently displayed
646 //slotSetCurrentEffect(ix);
648 // refresh effect stack
650 bool isSelected = false;
651 if (m_effectMetaInfo.trackMode) {
652 info.track = m_trackInfo.type;
653 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
654 info.cropStart = GenTime(0);
655 info.startPos = GenTime(-1);
659 info = m_clipref->info();
661 CollapsibleEffect *current = getEffectByIndex(ix);
662 m_effects.removeAll(current);
663 current->setEnabled(false);
664 m_currentEffectList.removeAt(ix);
665 m_currentEffectList.insert(region);
666 current->deleteLater();
667 CollapsibleEffect *currentEffect = new CollapsibleEffect(region, m_currentEffectList.itemFromIndex(ix), info, &m_effectMetaInfo, ix == m_currentEffectList.count() - 1, m_ui.container->widget());
668 connectEffect(currentEffect);
670 if (m_effectMetaInfo.trackMode) {
671 isSelected = currentEffect->effectIndex() == 1;
674 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
676 if (isSelected) currentEffect->setActive(true);
677 m_effects.append(currentEffect);
678 // TODO: region in group?
680 // group->addGroupEffect(currentEffect);
682 QVBoxLayout *vbox = static_cast <QVBoxLayout *> (m_ui.container->widget()->layout());
683 vbox->insertWidget(ix, currentEffect);
687 currentEffect->installEventFilter( this );
689 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
693 void EffectStackView2::slotCreateGroup(int ix)
695 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
696 QDomElement neweffect = oldeffect.cloneNode().toElement();
697 EffectInfo effectinfo;
698 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
699 effectinfo.groupIndex = m_groupIndex;
700 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
703 if (m_effectMetaInfo.trackMode) {
704 info.track = m_trackInfo.type;
705 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
706 info.cropStart = GenTime(0);
707 info.startPos = GenTime(-1);
709 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix, false);
711 emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix, false);
714 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
716 CollapsibleEffect *effectToMove = NULL;
717 for (int i = 0; i < m_effects.count(); i++) {
718 if (m_effects.at(i)->effectIndex() == ix) {
719 effectToMove = m_effects.at(i);
720 groupPos = l->indexOf(effectToMove);
721 l->removeWidget(effectToMove);
726 CollapsibleGroup *group = new CollapsibleGroup(m_groupIndex, ix == 1, ix == m_currentEffectList.count() - 2, effectinfo, m_ui.container->widget());
729 l->insertWidget(groupPos, group);
730 group->installEventFilter( this );
731 group->addGroupEffect(effectToMove);
734 void EffectStackView2::connectGroup(CollapsibleGroup *group)
736 connect(group, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
737 connect(group, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
738 connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
739 connect(group, SIGNAL(groupRenamed(CollapsibleGroup *)), this , SLOT(slotRenameGroup(CollapsibleGroup*)));
740 connect(group, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
741 connect(group, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
742 connect(group, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
745 void EffectStackView2::slotMoveEffect(QList <int> currentIndexes, int newIndex, int groupIndex, QString groupName)
747 if (currentIndexes.count() == 1) {
748 CollapsibleEffect *effectToMove = getEffectByIndex(currentIndexes.at(0));
749 if (effectToMove == NULL) return;
751 QDomElement oldeffect = effectToMove->effect();
752 QDomElement neweffect = oldeffect.cloneNode().toElement();
754 EffectInfo effectinfo;
755 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
756 effectinfo.groupIndex = groupIndex;
757 effectinfo.groupName = groupName;
758 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
760 if (oldeffect.attribute("kdenlive_info") != effectinfo.toString()) {
761 // effect's group info or collapsed state changed
763 if (m_effectMetaInfo.trackMode) {
764 info.track = m_trackInfo.type;
765 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
766 info.cropStart = GenTime(0);
767 info.startPos = GenTime(-1);
769 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->effectIndex(),false);
771 emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex(),false);
776 // Update effect index with new position
777 if (m_effectMetaInfo.trackMode) {
778 emit changeEffectPosition(NULL, m_trackindex, currentIndexes, newIndex);
781 emit changeEffectPosition(m_clipref, -1, currentIndexes, newIndex);
785 void EffectStackView2::slotUnGroup(CollapsibleGroup* group)
787 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
788 int ix = l->indexOf(group);
789 group->removeGroup(ix, l);
790 group->deleteLater();
793 void EffectStackView2::slotRenameGroup(CollapsibleGroup *group)
795 QList <CollapsibleEffect*> effects = group->effects();
796 for (int i = 0; i < effects.count(); i++) {
797 QDomElement origin = effects.at(i)->effect();
798 QDomElement changed = origin.cloneNode().toElement();
799 changed.setAttribute("kdenlive_info", effects.at(i)->infoString());
800 if (m_effectMetaInfo.trackMode) {
801 emit updateEffect(NULL, m_trackindex, origin, changed, effects.at(i)->effectIndex(),false);
803 emit updateEffect(m_clipref, -1, origin, changed, effects.at(i)->effectIndex(),false);
808 void EffectStackView2::dragEnterEvent(QDragEnterEvent *event)
810 if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
811 event->acceptProposedAction();
815 void EffectStackView2::processDroppedEffect(QDomElement e, QDropEvent *event)
817 int ix = e.attribute("kdenlive_ix").toInt();
818 if (e.tagName() == "effectgroup") {
819 // We are dropping a group, all effects in group should be moved
820 QDomNodeList effects = e.elementsByTagName("effect");
821 if (effects.count() == 0) {
826 info.fromString(effects.at(0).toElement().attribute("kdenlive_info"));
827 if (info.groupIndex < 0) {
828 kDebug()<<"// ADDING EFFECT!!!";
829 // Adding a new group effect to the stack
830 event->setDropAction(Qt::CopyAction);
835 // Moving group: delete all effects and re-add them
837 for (int i = 0; i < effects.count(); i++) {
838 QDomElement effect = effects.at(i).cloneNode().toElement();
839 indexes << effect.attribute("kdenlive_ix").toInt();
841 kDebug()<<"// Moving: "<<indexes<<" TO "<<m_currentEffectList.count();
842 slotMoveEffect(indexes, m_currentEffectList.count(), info.groupIndex, info.groupName);
845 // effect dropped from effects list, add it
846 e.setAttribute("kdenlive_ix", m_currentEffectList.count() + 1);
847 event->setDropAction(Qt::CopyAction);
853 // User is moving an effect
854 slotMoveEffect(QList<int> () << ix, m_currentEffectList.count() + 1, -1);
856 event->setDropAction(Qt::MoveAction);
860 void EffectStackView2::dropEvent(QDropEvent *event)
862 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
863 //event->acceptProposedAction();
865 doc.setContent(effects, true);
866 processDroppedEffect(doc.documentElement(), event);
869 #include "effectstackview2.moc"