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.groupName, m_ui.container->widget());
187 connect(group, SIGNAL(moveEffect(int,int,int,QString)), this, SLOT(slotMoveEffect(int,int,int,QString)));
188 connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
189 connect(group, SIGNAL(groupRenamed(CollapsibleGroup *)), this, SLOT(slotRenameGroup(CollapsibleGroup*)));
190 connect(group, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
191 connect(group, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
192 vbox1->addWidget(group);
193 group->installEventFilter( this );
195 if (effectInfo.groupIndex >= m_groupIndex) m_groupIndex = effectInfo.groupIndex + 1;
199 doc.appendChild(doc.importNode(d, true));
200 kDebug() << "IMPORTED STK: " << doc.toString();*/
203 bool isSelected = false;
204 if (m_effectMetaInfo.trackMode) {
205 info.track = m_trackInfo.type;
206 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
207 info.cropStart = GenTime(0);
208 info.startPos = GenTime(-1);
212 info = m_clipref->info();
215 CollapsibleEffect *currentEffect = new CollapsibleEffect(d, m_currentEffectList.at(i), info, &m_effectMetaInfo, i == m_currentEffectList.count() - 1, view);
216 if (m_effectMetaInfo.trackMode) {
217 isSelected = currentEffect->effectIndex() == 1;
220 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
222 if (isSelected) currentEffect->setActive(true);
223 m_effects.append(currentEffect);
225 group->addGroupEffect(currentEffect);
227 vbox1->addWidget(currentEffect);
229 connectEffect(currentEffect);
231 vbox1->addStretch(10);
232 slotUpdateCheckAllButton();
233 connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
235 // Wait a little bit for the new layout to be ready, then check if we have a scrollbar
236 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
239 void EffectStackView2::connectEffect(CollapsibleEffect *currentEffect)
242 currentEffect->installEventFilter( this );
243 connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
244 connect(currentEffect, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,QString,QString)));
245 connect(currentEffect, SIGNAL(deleteEffect(const QDomElement)), this , SLOT(slotDeleteEffect(const QDomElement)));
246 connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
247 connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
248 connect(currentEffect, SIGNAL(changeEffectPosition(int,bool)), this , SLOT(slotMoveEffectUp(int , bool)));
249 connect(currentEffect, SIGNAL(effectStateChanged(bool,int,bool)), this, SLOT(slotUpdateEffectState(bool,int,bool)));
250 connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
251 connect(currentEffect, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
252 connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
253 connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
254 connect(currentEffect, SIGNAL(moveEffect(int,int,int,QString)), this , SLOT(slotMoveEffect(int,int,int,QString)));
255 connect(currentEffect, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
256 connect(currentEffect, SIGNAL(createRegion(int,KUrl)), this, SLOT(slotCreateRegion(int,KUrl)));
259 void EffectStackView2::slotCheckWheelEventFilter()
261 // If the effect stack widget has no scrollbar, we will not filter the
262 // mouse wheel events, so that user can easily adjust effect params
263 bool filterWheelEvent = false;
264 if (m_ui.container->verticalScrollBar() && m_ui.container->verticalScrollBar()->isVisible()) {
265 // widget has scroll bar,
266 filterWheelEvent = true;
268 for (int i = 0; i < m_effects.count(); i++) {
269 m_effects.at(i)->filterWheelEvent = filterWheelEvent;
273 void EffectStackView2::resizeEvent ( QResizeEvent * event )
275 slotCheckWheelEventFilter();
276 QWidget::resizeEvent(event);
279 bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
281 // Check if user clicked in an effect's top bar to start dragging it
282 if (e->type() == QEvent::MouseButtonPress) {
283 m_draggedEffect = qobject_cast<CollapsibleEffect*>(o);
284 if (m_draggedEffect) {
285 QMouseEvent *me = static_cast<QMouseEvent *>(e);
286 if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse())) {
287 m_clickPoint = me->globalPos();
290 m_clickPoint = QPoint();
291 m_draggedEffect = NULL;
296 m_draggedGroup = qobject_cast<CollapsibleGroup*>(o);
297 if (m_draggedGroup) {
298 QMouseEvent *me = static_cast<QMouseEvent *>(e);
299 if (me->button() == Qt::LeftButton && (m_draggedGroup->framegroup->underMouse() || m_draggedGroup->title()->underMouse()))
300 m_clickPoint = me->globalPos();
302 m_clickPoint = QPoint();
303 m_draggedGroup = NULL;
309 /*if (e->type() == QEvent::MouseMove) {
310 if (qobject_cast<CollapsibleEffect*>(o)) {
311 QMouseEvent *me = static_cast<QMouseEvent *>(e);
312 if (me->buttons() != Qt::LeftButton) {
322 return QWidget::eventFilter(o, e);
325 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
327 if (m_draggedEffect || m_draggedGroup) {
328 if ((event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
334 void EffectStackView2::mouseReleaseEvent(QMouseEvent * event)
336 m_draggedEffect = NULL;
337 m_draggedGroup = NULL;
338 QWidget::mouseReleaseEvent(event);
341 void EffectStackView2::startDrag()
343 // The data to be transferred by the drag and drop operation is contained in a QMimeData object
346 if (m_draggedEffect) {
347 QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
348 doc.appendChild(doc.importNode(effect, true));
349 pixmap = QPixmap::grabWidget(m_draggedEffect->title);
351 else if (m_draggedGroup) {
352 doc = m_draggedGroup->effectsData();
353 pixmap = QPixmap::grabWidget(m_draggedGroup->title());
356 QDrag *drag = new QDrag(this);
357 drag->setPixmap(pixmap);
358 QMimeData *mime = new QMimeData;
360 data.append(doc.toString().toUtf8());
361 mime->setData("kdenlive/effectslist", data);
363 // Assign ownership of the QMimeData object to the QDrag object.
364 drag->setMimeData(mime);
365 // Start the drag and drop operation
366 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
370 void EffectStackView2::slotUpdateEffectState(bool disable, int index, bool updateMainStatus)
372 if (m_effectMetaInfo.trackMode)
373 emit changeEffectState(NULL, m_trackindex, index, disable);
375 emit changeEffectState(m_clipref, -1, index, disable);
376 if (updateMainStatus) slotUpdateCheckAllButton();
380 void EffectStackView2::raiseWindow(QWidget* dock)
382 if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
387 void EffectStackView2::slotSeekTimeline(int pos)
389 if (m_effectMetaInfo.trackMode) {
390 emit seekTimeline(pos);
391 } else if (m_clipref) {
392 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
397 /*void EffectStackView2::slotRegionChanged()
399 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
402 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
404 if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
405 if (!m_effectMetaInfo.monitor->getEffectEdit()->getScene()->views().at(0)->isVisible())
406 m_effectMetaInfo.monitor->slotEffectScene(true);
408 m_effectMetaInfo.monitor->slotEffectScene(false);
412 int EffectStackView2::isTrackMode(bool *ok) const
414 *ok = m_effectMetaInfo.trackMode;
418 void EffectStackView2::clear()
421 QWidget *view = m_ui.container->takeWidget();
425 m_ui.checkAll->setToolTip(QString());
426 m_ui.checkAll->setText(QString());
427 m_ui.checkAll->setEnabled(false);
428 m_ui.labelComment->setText(QString());
432 void EffectStackView2::slotCheckAll(int state)
434 if (state == Qt::PartiallyChecked) {
436 m_ui.checkAll->blockSignals(true);
437 m_ui.checkAll->setCheckState(Qt::Checked);
438 m_ui.checkAll->blockSignals(false);
441 bool disabled = state == Qt::Unchecked;
442 for (int i = 0; i < m_effects.count(); i++) {
443 if (!m_effects.at(i)->isGroup()) {
444 m_effects.at(i)->slotEnable(disabled, false);
449 void EffectStackView2::slotUpdateCheckAllButton()
451 bool hasEnabled = false;
452 bool hasDisabled = false;
454 for (int i = 0; i < m_effects.count(); i++) {
455 if (!m_effects.at(i)->enabledButton->isChecked()) hasEnabled = true;
456 else hasDisabled = true;
459 m_ui.checkAll->blockSignals(true);
460 if (hasEnabled && hasDisabled)
461 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
463 m_ui.checkAll->setCheckState(Qt::Checked);
465 m_ui.checkAll->setCheckState(Qt::Unchecked);
466 m_ui.checkAll->blockSignals(false);
469 void EffectStackView2::deleteCurrentEffect()
471 for (int i = 0; i < m_effects.count(); i++) {
472 if (m_effects.at(i)->isActive()) {
473 slotDeleteEffect(m_effects.at(i)->effect());
479 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
481 m_effectMetaInfo.profile = profile;
482 m_effectMetaInfo.timecode = t;
485 void EffectStackView2::updateTimecodeFormat()
487 for (int i = 0; i< m_effects.count(); i++)
488 m_effects.at(i)->updateTimecodeFormat();
491 CollapsibleEffect *EffectStackView2::getEffectByIndex(int ix)
493 for (int i = 0; i< m_effects.count(); i++) {
494 if (m_effects.at(i)->effectIndex() == ix) {
495 return m_effects.at(i);
501 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
503 if (m_effectMetaInfo.trackMode)
504 emit updateEffect(NULL, m_trackindex, old, e, ix,false);
505 else if (m_clipref) {
506 emit updateEffect(m_clipref, -1, old, e, ix, false);
507 // Make sure the changed effect is currently displayed
508 slotSetCurrentEffect(ix);
510 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
513 void EffectStackView2::slotSetCurrentEffect(int ix)
515 if (m_clipref && ix != m_clipref->selectedEffectIndex()) {
516 m_clipref->setSelectedEffect(ix);
517 for (int i = 0; i < m_effects.count(); i++) {
518 if (m_effects.at(i)->effectIndex() == ix) {
519 m_effects.at(i)->setActive(true);
520 m_ui.labelComment->setText(i18n(m_effects.at(i)->effect().firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
521 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
523 else m_effects.at(i)->setActive(false);
528 void EffectStackView2::slotDeleteGroup(QDomDocument doc)
530 QDomNodeList effects = doc.elementsByTagName("effect");
531 ClipItem * clip = NULL;
533 if (m_effectMetaInfo.trackMode) {
541 for (int i = 0; i < effects.count(); i++)
542 emit removeEffect(clip, ix, effects.at(i).toElement());
545 void EffectStackView2::slotDeleteEffect(const QDomElement effect)
547 if (m_effectMetaInfo.trackMode)
548 emit removeEffect(NULL, m_trackindex, effect);
550 emit removeEffect(m_clipref, -1, effect);
553 void EffectStackView2::slotAddEffect(QDomElement effect)
555 emit addEffect(m_clipref, effect);
558 void EffectStackView2::slotMoveEffectUp(int index, bool up)
560 if (up && index <= 1) return;
561 if (!up && index >= m_currentEffectList.count()) return;
569 if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, index, endPos);
570 else emit changeEffectPosition(m_clipref, -1, index, endPos);
573 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
575 if (!m_clipref) return;
576 emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, finalFilterName, consumer, consumerParams, properties);
579 void EffectStackView2::slotResetEffect(int ix)
581 QDomElement old = m_currentEffectList.itemFromIndex(ix);
583 QString effectId = old.attribute("id");
584 QMap<QString, EffectsList*> effectLists;
585 effectLists["audio"] = &MainWindow::audioEffects;
586 effectLists["video"] = &MainWindow::videoEffects;
587 effectLists["custom"] = &MainWindow::customEffects;
588 foreach(const QString &type, effectLists.keys()) {
589 EffectsList *list = effectLists[type];
590 dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
591 if (!dom.isNull()) break;
594 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
595 if (m_effectMetaInfo.trackMode) {
596 EffectsList::setParameter(dom, "in", QString::number(0));
597 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
599 info.track = m_trackInfo.type;
600 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
601 info.cropStart = GenTime(0);
602 info.startPos = GenTime(-1);
604 m_effects.at(ix)->updateWidget(info, dom, &m_effectMetaInfo);
605 emit updateEffect(NULL, m_trackindex, old, dom, ix,false);
607 m_clipref->initEffect(dom);
608 for (int i = 0; i < m_effects.count(); i++) {
609 if (m_effects.at(i)->effectIndex() == ix) {
610 m_effects.at(i)->updateWidget(m_clipref->info(), dom, &m_effectMetaInfo);
614 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
615 emit updateEffect(m_clipref, -1, old, dom, ix,false);
619 emit showComments(m_ui.buttonShowComments->isChecked());
620 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
623 void EffectStackView2::slotShowComments()
625 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
626 emit showComments(m_ui.buttonShowComments->isChecked());
629 void EffectStackView2::slotCreateRegion(int ix, KUrl url)
631 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
632 QDomElement neweffect = oldeffect.cloneNode().toElement();
633 QDomElement region = MainWindow::videoEffects.getEffectByTag("region", "region").cloneNode().toElement();
634 region.appendChild(region.ownerDocument().importNode(neweffect, true));
635 region.setAttribute("kdenlive_ix", ix);
636 EffectsList::setParameter(region, "resource", url.path());
637 if (m_effectMetaInfo.trackMode)
638 emit updateEffect(NULL, m_trackindex, oldeffect, region, ix,false);
639 else if (m_clipref) {
640 emit updateEffect(m_clipref, -1, oldeffect, region, ix, false);
641 // Make sure the changed effect is currently displayed
642 //slotSetCurrentEffect(ix);
644 // refresh effect stack
646 bool isSelected = false;
647 if (m_effectMetaInfo.trackMode) {
648 info.track = m_trackInfo.type;
649 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
650 info.cropStart = GenTime(0);
651 info.startPos = GenTime(-1);
655 info = m_clipref->info();
657 CollapsibleEffect *current = getEffectByIndex(ix);
658 m_effects.removeAll(current);
659 current->setEnabled(false);
660 m_currentEffectList.removeAt(ix);
661 m_currentEffectList.insert(region);
662 current->deleteLater();
663 CollapsibleEffect *currentEffect = new CollapsibleEffect(region, m_currentEffectList.itemFromIndex(ix), info, &m_effectMetaInfo, ix == m_currentEffectList.count() - 1, m_ui.container->widget());
664 connectEffect(currentEffect);
666 if (m_effectMetaInfo.trackMode) {
667 isSelected = currentEffect->effectIndex() == 1;
670 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
672 if (isSelected) currentEffect->setActive(true);
673 m_effects.append(currentEffect);
674 // TODO: region in group?
676 // group->addGroupEffect(currentEffect);
678 QVBoxLayout *vbox = static_cast <QVBoxLayout *> (m_ui.container->widget()->layout());
679 vbox->insertWidget(ix, currentEffect);
683 currentEffect->installEventFilter( this );
685 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
689 void EffectStackView2::slotCreateGroup(int ix)
691 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
692 QDomElement neweffect = oldeffect.cloneNode().toElement();
693 EffectInfo effectinfo;
694 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
695 effectinfo.groupIndex = m_groupIndex;
696 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
699 if (m_effectMetaInfo.trackMode) {
700 info.track = m_trackInfo.type;
701 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
702 info.cropStart = GenTime(0);
703 info.startPos = GenTime(-1);
705 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix, false);
707 emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix, false);
710 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
712 CollapsibleEffect *effectToMove = NULL;
713 for (int i = 0; i < m_effects.count(); i++) {
714 if (m_effects.at(i)->effectIndex() == ix) {
715 effectToMove = m_effects.at(i);
716 groupPos = l->indexOf(effectToMove);
717 l->removeWidget(effectToMove);
722 CollapsibleGroup *group = new CollapsibleGroup(m_groupIndex, ix == 1, ix == m_currentEffectList.count() - 2, QString(), m_ui.container->widget());
724 connect(group, SIGNAL(moveEffect(int,int,int,QString)), this , SLOT(slotMoveEffect(int,int,int,QString)));
725 connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
726 connect(group, SIGNAL(groupRenamed(CollapsibleGroup *)), this , SLOT(slotRenameGroup(CollapsibleGroup*)));
727 connect(group, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
728 connect(group, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
729 l->insertWidget(groupPos, group);
730 group->installEventFilter( this );
731 group->addGroupEffect(effectToMove);
734 void EffectStackView2::slotMoveEffect(int currentIndex, int newIndex, int groupIndex, QString groupName)
736 CollapsibleEffect *effectToMove = getEffectByIndex(currentIndex);
737 if (effectToMove == NULL) return;
739 QDomElement oldeffect = effectToMove->effect();
740 QDomElement neweffect = oldeffect.cloneNode().toElement();
742 EffectInfo effectinfo;
743 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
744 effectinfo.groupIndex = groupIndex;
745 effectinfo.groupName = groupName;
746 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
749 if (m_effectMetaInfo.trackMode) {
750 info.track = m_trackInfo.type;
751 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
752 info.cropStart = GenTime(0);
753 info.startPos = GenTime(-1);
755 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->effectIndex(),false);
757 emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex(),false);
759 //if (currentIndex == newIndex) return;
760 // Update effect index with new position
761 if (m_effectMetaInfo.trackMode) {
762 emit changeEffectPosition(NULL, m_trackindex, currentIndex, newIndex);
765 emit changeEffectPosition(m_clipref, -1, currentIndex, newIndex);
769 void EffectStackView2::slotUnGroup(CollapsibleGroup* group)
771 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
772 int ix = l->indexOf(group);
773 group->removeGroup(ix, l);
774 group->deleteLater();
777 void EffectStackView2::slotRenameGroup(CollapsibleGroup *group)
779 QList <CollapsibleEffect*> effects = group->effects();
780 for (int i = 0; i < effects.count(); i++) {
781 QDomElement origin = effects.at(i)->effect();
782 QDomElement changed = origin.cloneNode().toElement();
783 changed.setAttribute("kdenlive_info", effects.at(i)->infoString());
784 if (m_effectMetaInfo.trackMode) {
785 emit updateEffect(NULL, m_trackindex, origin, changed, effects.at(i)->effectIndex(),false);
787 emit updateEffect(m_clipref, -1, origin, changed, effects.at(i)->effectIndex(),false);
792 void EffectStackView2::dragEnterEvent(QDragEnterEvent *event)
794 if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
795 event->acceptProposedAction();
799 void EffectStackView2::dropEvent(QDropEvent *event)
801 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
802 //event->acceptProposedAction();
804 doc.setContent(effects, true);
805 QDomElement e = doc.documentElement();
806 int ix = e.attribute("kdenlive_ix").toInt();
807 if (e.tagName() == "effectgroup") {
808 // We are dropping a group, all effects in group should be moved
809 QDomNodeList effects = e.elementsByTagName("effect");
810 if (effects.count() == 0) {
815 info.fromString(effects.at(0).toElement().attribute("kdenlive_info"));
816 if (info.groupIndex < 0) {
817 // Adding a new group effect to the stack
818 event->setDropAction(Qt::CopyAction);
823 for (int i = 0; i < effects.count(); i++) {
824 //TODO: not working because wee need to move all effects in one go
825 slotMoveEffect(effects.at(i).toElement().attribute("kdenlive_ix").toInt(), m_currentEffectList.count() + 1 + i, info.groupIndex, info.groupName);
829 // effect dropped from effects list, add it
830 e.setAttribute("kdenlive_ix", m_currentEffectList.count() + 1);
831 event->setDropAction(Qt::CopyAction);
837 // User is moving an effect
838 slotMoveEffect(ix, m_currentEffectList.count() + 1, -1);
840 event->setDropAction(Qt::MoveAction);
844 #include "effectstackview2.moc"