]> git.sesse.net Git - kdenlive/blob - src/effectstack/effectstackview2.cpp
Some ui love for new effect stack
[kdenlive] / src / effectstack / effectstackview2.cpp
1 /***************************************************************************
2                           effecstackview.cpp2  -  description
3                              -------------------
4     begin                : Feb 15 2008
5     copyright            : (C) 2008 by Marco Gittler
6     email                : g.marco@freenet.de
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
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.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18
19 #include "effectstackview2.h"
20 #include "effectslist.h"
21 #include "clipitem.h"
22 #include "mainwindow.h"
23 #include "docclipbase.h"
24 #include "projectlist.h"
25 #include "kthumb.h"
26 #include "monitoreditwidget.h"
27 #include "monitorscene.h"
28 #include "kdenlivesettings.h"
29
30 #include <KDebug>
31 #include <KLocale>
32 #include <KMessageBox>
33 #include <KStandardDirs>
34 #include <KFileDialog>
35 #include <KColorScheme>
36
37 #include <QMenu>
38 #include <QTextStream>
39 #include <QFile>
40 #include <QInputDialog>
41 #include <QScrollBar>
42
43
44 EffectStackView2::EffectStackView2(Monitor *monitor, QWidget *parent) :
45         QWidget(parent),
46         m_clipref(NULL),
47         m_trackindex(-1),
48         m_draggedEffect(NULL),
49         m_groupIndex(0)
50 {
51     m_effectMetaInfo.trackMode = false;
52     m_effectMetaInfo.monitor = monitor;
53     m_effects = QList <CollapsibleEffect*>();
54
55     m_ui.setupUi(this);
56     setFont(KGlobalSettings::smallestReadableFont());
57     m_ui.checkAll->setToolTip(i18n("Enable/Disable all effects"));
58     m_ui.buttonShowComments->setIcon(KIcon("help-about"));
59     m_ui.buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
60     
61     connect(m_ui.checkAll, SIGNAL(stateChanged(int)), this, SLOT(slotCheckAll(int)));
62     connect(m_ui.buttonShowComments, SIGNAL(clicked()), this, SLOT(slotShowComments()));
63     m_ui.labelComment->setHidden(true);
64
65     setEnabled(false);
66
67     
68     setStyleSheet(CollapsibleEffect::getStyleSheet(palette()));
69 }
70
71 EffectStackView2::~EffectStackView2()
72 {
73 }
74
75
76 void EffectStackView2::slotRenderPos(int pos)
77 {
78     if (m_effects.isEmpty()) return;
79     if (!m_effectMetaInfo.trackMode && m_clipref) pos = pos - m_clipref->startPos().frames(KdenliveSettings::project_fps());
80
81     for (int i = 0; i< m_effects.count(); i++)
82         m_effects.at(i)->slotSyncEffectsPos(pos);
83 }
84
85 void EffectStackView2::slotClipItemSelected(ClipItem* c, int ix)
86 {
87     if (c && !c->isEnabled()) return;
88     if (c && c == m_clipref) {
89         
90     } else {
91         m_clipref = c;
92         if (c) {
93             QString cname = m_clipref->clipName();
94             if (cname.length() > 30) {
95                 m_ui.checkAll->setToolTip(i18n("Effects for %1").arg(cname));
96                 cname.truncate(27);
97                 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "...");
98             } else {
99                 m_ui.checkAll->setToolTip(QString());
100                 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
101             }
102             m_ui.checkAll->setEnabled(true);
103             ix = c->selectedEffectIndex();
104             QString size = c->baseClip()->getProperty("frame_size");
105             double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
106             m_effectMetaInfo.frameSize = QPoint((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
107         } else {
108             ix = 0;
109         }
110     }
111     if (m_clipref == NULL) {
112         //TODO: clear list, reset paramdesc and info
113         //ItemInfo info;
114         //m_effectedit->transferParamDesc(QDomElement(), info);
115         clear();
116         return;
117     }
118     setEnabled(true);
119     m_effectMetaInfo.trackMode = false;
120     m_currentEffectList = m_clipref->effectList();
121     setupListView(ix);
122 }
123
124 void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
125 {
126     m_clipref = NULL;
127     m_effectMetaInfo.trackMode = true;
128     m_currentEffectList = info.effectsList;
129     m_trackInfo = info;
130     setEnabled(true);
131     m_ui.checkAll->setToolTip(QString());
132     m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
133     m_trackindex = ix;
134     setupListView(0);
135 }
136
137
138 void EffectStackView2::setupListView(int ix)
139 {
140     blockSignals(true);
141     m_draggedEffect = NULL;
142     disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
143     m_effects.clear();
144     m_groupIndex = 0;
145     QWidget *view = m_ui.container->takeWidget();
146     if (view) {
147         delete view;
148     }
149     blockSignals(false);
150     view = new QWidget(m_ui.container);
151     m_ui.container->setWidget(view);
152
153     QVBoxLayout *vbox1 = new QVBoxLayout(view);
154     vbox1->setContentsMargins(0, 0, 0, 0);
155     vbox1->setSpacing(0);
156     
157     if (m_currentEffectList.isEmpty()) m_ui.labelComment->setHidden(true);
158
159     for (int i = 0; i < m_currentEffectList.count(); i++) {
160         QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
161         if (d.isNull()) {
162             kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
163             continue;
164         }
165         
166         CollapsibleEffect *group = NULL;
167         EffectInfo effectInfo;
168         effectInfo.fromString(d.attribute("kdenlive_info"));
169         if (effectInfo.groupIndex >= 0) {
170             // effect is in a group
171             for (int i = 0; i < vbox1->count(); i++) {
172                 CollapsibleEffect *eff = static_cast<CollapsibleEffect *>(vbox1->itemAt(i)->widget());
173                 if (eff->isGroup() &&  eff->groupIndex() == effectInfo.groupIndex) {
174                     group = eff;
175                     break;
176                 }
177             }
178             
179             if (group == NULL) {
180                 group = new CollapsibleEffect(QDomElement(), QDomElement(), ItemInfo(), effectInfo.groupIndex, &m_effectMetaInfo, false, true, m_ui.container->widget());
181                 if (!effectInfo.groupName.isEmpty()) group->title->setText(effectInfo.groupName);
182                 connect(group, SIGNAL(moveEffect(int,int,CollapsibleEffect*)), this, SLOT(slotMoveEffect(int,int,CollapsibleEffect*)));
183                 connect(group, SIGNAL(unGroup(CollapsibleEffect*)), this , SLOT(slotUnGroup(CollapsibleEffect*)));
184                 vbox1->addWidget(group);
185             }
186             if (effectInfo.groupIndex >= m_groupIndex) m_groupIndex = effectInfo.groupIndex + 1;
187         }
188
189         /*QDomDocument doc;
190         doc.appendChild(doc.importNode(d, true));
191         kDebug() << "IMPORTED STK: " << doc.toString();*/
192         
193         ItemInfo info;
194         if (m_effectMetaInfo.trackMode) { 
195             info.track = m_trackInfo.type;
196             info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
197             info.cropStart = GenTime(0);
198             info.startPos = GenTime(-1);
199             info.track = 0;
200         }
201         else info = m_clipref->info();
202
203         CollapsibleEffect *currentEffect = new CollapsibleEffect(d, m_currentEffectList.at(i), info, i, &m_effectMetaInfo, i == m_currentEffectList.count() - 1, false, view);
204         m_effects.append(currentEffect);
205         if (group) {
206             group->addGroupEffect(currentEffect);
207         } else {
208             vbox1->addWidget(currentEffect);
209         }
210         if (currentEffect->effectIndex() == ix) currentEffect->setActive(true);
211
212         // Check drag & drop
213         currentEffect->installEventFilter( this );
214
215         connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
216         connect(currentEffect, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,QString,QString)));
217         connect(currentEffect, SIGNAL(deleteEffect(const QDomElement)), this , SLOT(slotDeleteEffect(const QDomElement)));
218         connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
219         connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
220         connect(currentEffect, SIGNAL(changeEffectPosition(int,bool)), this , SLOT(slotMoveEffectUp(int , bool)));
221         connect(currentEffect, SIGNAL(effectStateChanged(bool, int)), this, SLOT(slotUpdateEffectState(bool, int)));
222         connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
223         connect(currentEffect, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
224         connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
225         connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
226         connect(currentEffect, SIGNAL(moveEffect(int,int,CollapsibleEffect*)), this , SLOT(slotMoveEffect(int,int,CollapsibleEffect*)));
227         connect(currentEffect, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
228         
229         //ui.title->setPixmap(icon.pixmap(QSize(12, 12)));
230     }
231     vbox1->addStretch(10);
232     slotUpdateCheckAllButton();
233     connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
234     
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()));
237 }
238
239
240 void EffectStackView2::slotCheckWheelEventFilter()
241 {
242     // If the effect stack widget has no scrollbar, we will not filter the
243     // mouse wheel events, so that user can easily adjust effect params
244     bool filterWheelEvent = false;
245     if (m_ui.container->verticalScrollBar() && m_ui.container->verticalScrollBar()->isVisible()) {
246         // widget has scroll bar, 
247         filterWheelEvent = true;
248     }
249     for (int i = 0; i < m_effects.count(); i++) {
250         m_effects.at(i)->filterWheelEvent = filterWheelEvent;
251     }    
252 }
253
254 void EffectStackView2::resizeEvent ( QResizeEvent * event )
255 {
256     slotCheckWheelEventFilter();
257     QWidget::resizeEvent(event);
258 }
259
260 bool EffectStackView2::eventFilter( QObject * o, QEvent * e ) 
261 {
262     // Check if user clicked in an effect's top bar to start dragging it
263     if (e->type() == QEvent::MouseButtonPress)  {
264         m_draggedEffect = qobject_cast<CollapsibleEffect*>(o);
265         if (m_draggedEffect) {
266             QMouseEvent *me = static_cast<QMouseEvent *>(e);
267             if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse()))
268                 m_clickPoint = me->globalPos();
269             else {
270                 m_clickPoint = QPoint();
271                 m_draggedEffect = NULL;
272             }
273             e->accept();
274             return false;
275         }
276     }  
277     if (e->type() == QEvent::MouseMove)  {
278         if (qobject_cast<CollapsibleEffect*>(o)) {
279             QMouseEvent *me = static_cast<QMouseEvent *>(e);
280             if (me->buttons() != Qt::LeftButton) {
281                 e->accept();
282                 return false;
283             }
284             else {
285                 e->ignore();
286                 return true;
287             }
288         }
289     }
290     return QWidget::eventFilter(o, e);
291 }
292
293 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
294 {
295     if (m_draggedEffect && (event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
296         startDrag();
297     }
298 }
299
300 void EffectStackView2::mouseReleaseEvent(QMouseEvent * event)
301 {
302     m_draggedEffect = NULL;
303     QWidget::mouseReleaseEvent(event);
304 }
305
306 void EffectStackView2::startDrag()
307 {
308     QDrag *drag = new QDrag(this);
309     // The data to be transferred by the drag and drop operation is contained in a QMimeData object
310     QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
311     QPixmap pixmap = QPixmap::grabWidget(m_draggedEffect->title);
312     drag->setPixmap(pixmap);
313     QDomDocument doc;
314     doc.appendChild(doc.importNode(effect, true));
315     QMimeData *mime = new QMimeData;
316     QByteArray data;
317     data.append(doc.toString().toUtf8());
318     mime->setData("kdenlive/effectslist", data);
319
320     // Assign ownership of the QMimeData object to the QDrag object.
321     drag->setMimeData(mime);
322     // Start the drag and drop operation
323     drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
324 }
325
326
327 void EffectStackView2::slotUpdateEffectState(bool disable, int index)
328 {
329     if (m_effectMetaInfo.trackMode)
330         emit changeEffectState(NULL, m_trackindex, index, disable);
331     else
332         emit changeEffectState(m_clipref, -1, index, disable);
333     slotUpdateCheckAllButton();
334 }
335
336
337 void EffectStackView2::raiseWindow(QWidget* dock)
338 {
339     if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
340         dock->raise();
341 }
342
343
344 void EffectStackView2::slotSeekTimeline(int pos)
345 {
346     if (m_effectMetaInfo.trackMode) {
347         emit seekTimeline(pos);
348     } else if (m_clipref) {
349         emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
350     }
351 }
352
353
354 /*void EffectStackView2::slotRegionChanged()
355 {
356     if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
357 }*/
358
359 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
360 {
361     if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
362         if (!m_effectMetaInfo.monitor->getEffectEdit()->getScene()->views().at(0)->isVisible())
363             m_effectMetaInfo.monitor->slotEffectScene(true);
364     } else {
365         m_effectMetaInfo.monitor->slotEffectScene(false);
366     }
367 }
368
369 int EffectStackView2::isTrackMode(bool *ok) const
370 {
371     *ok = m_effectMetaInfo.trackMode;
372     return m_trackindex;
373 }
374
375 void EffectStackView2::clear()
376 {
377     m_effects.clear();
378     QWidget *view = m_ui.container->takeWidget();
379     if (view) {
380         delete view;
381     }
382     m_ui.checkAll->setToolTip(QString());
383     m_ui.checkAll->setText(QString());
384     m_ui.checkAll->setEnabled(false);
385     m_ui.labelComment->setText(QString());
386     setEnabled(false);
387 }
388
389 void EffectStackView2::slotCheckAll(int state)
390 {
391     if (state == 1) {
392         state = 2;
393         m_ui.checkAll->blockSignals(true);
394         m_ui.checkAll->setCheckState(Qt::Checked);
395         m_ui.checkAll->blockSignals(false);
396     }
397
398     bool disabled = (state != 2);
399     for (int i = 0; i < m_effects.count(); i++) {
400         if (!m_effects.at(i)->isGroup()) {
401             m_effects.at(i)->slotEnable(!disabled);
402         }
403     }
404 }
405
406 void EffectStackView2::slotUpdateCheckAllButton()
407 {
408     bool hasEnabled = false;
409     bool hasDisabled = false;
410     
411     for (int i = 0; i < m_effects.count(); i++) {
412         if (m_effects.at(i)->enabledBox->isChecked()) hasEnabled = true;
413         else hasDisabled = true; 
414     }
415
416     m_ui.checkAll->blockSignals(true);
417     if (hasEnabled && hasDisabled)
418         m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
419     else if (hasEnabled)
420         m_ui.checkAll->setCheckState(Qt::Checked);
421     else
422         m_ui.checkAll->setCheckState(Qt::Unchecked);
423     m_ui.checkAll->blockSignals(false);
424 }
425
426 void EffectStackView2::deleteCurrentEffect()
427 {
428     for (int i = 0; i < m_effects.count(); i++) {
429         if (m_effects.at(i)->isActive()) {
430             slotDeleteEffect(m_effects.at(i)->effect());
431             break;
432         }
433     }
434 }
435
436 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
437 {
438     m_effectMetaInfo.profile = profile;
439     m_effectMetaInfo.timecode = t;
440 }
441
442 void EffectStackView2::updateTimecodeFormat()
443 {
444     for (int i = 0; i< m_effects.count(); i++)
445         m_effects.at(i)->updateTimecodeFormat();
446 }
447
448 CollapsibleEffect *EffectStackView2::getEffectByIndex(int ix)
449 {
450     for (int i = 0; i< m_effects.count(); i++) {
451         if (m_effects.at(i)->effectIndex() == ix) {
452             return m_effects.at(i);
453         }
454     }
455     return NULL;
456 }
457
458 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
459 {
460     if (m_effectMetaInfo.trackMode)
461         emit updateEffect(NULL, m_trackindex, old, e, ix);
462     else if (m_clipref) {
463         emit updateEffect(m_clipref, -1, old, e, ix);
464         // Make sure the changed effect is currently displayed
465         slotSetCurrentEffect(ix);
466     }
467     QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
468 }
469
470 void EffectStackView2::slotSetCurrentEffect(int ix)
471 {
472     if (m_clipref && ix != m_clipref->selectedEffectIndex())
473         m_clipref->setSelectedEffect(ix);
474     for (int i = 0; i < m_effects.count(); i++) {
475         if (m_effects.at(i)->effectIndex() == ix) {
476             m_effects.at(i)->setActive(true);
477             m_ui.labelComment->setText(i18n(m_effects.at(i)->effect().firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
478              m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
479         }
480         else m_effects.at(i)->setActive(false);
481     }
482 }
483
484 void EffectStackView2::slotDeleteEffect(const QDomElement effect)
485 {
486     if (m_effectMetaInfo.trackMode)
487         emit removeEffect(NULL, m_trackindex, effect);
488     else
489         emit removeEffect(m_clipref, -1, effect);
490 }
491
492 void EffectStackView2::slotAddEffect(QDomElement effect)
493 {
494     emit addEffect(m_clipref, effect);
495 }
496
497 void EffectStackView2::slotMoveEffectUp(int index, bool up)
498 {
499     if (up && index <= 1) return;
500     if (!up && index >= m_currentEffectList.count()) return;
501     int endPos;
502     if (up) {
503         endPos = index - 1;
504     }
505     else {
506         endPos =  index + 1;
507     }
508     if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, index, endPos);
509     else emit changeEffectPosition(m_clipref, -1, index, endPos);
510 }
511
512 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
513 {
514     if (!m_clipref) return;
515     emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, finalFilterName, consumer, consumerParams, properties);
516 }
517
518 void EffectStackView2::slotResetEffect(int ix)
519 {
520     QDomElement old = m_currentEffectList.itemFromIndex(ix);
521     QDomElement dom;
522     QString effectId = old.attribute("id");
523     QMap<QString, EffectsList*> effectLists;
524     effectLists["audio"] = &MainWindow::audioEffects;
525     effectLists["video"] = &MainWindow::videoEffects;
526     effectLists["custom"] = &MainWindow::customEffects;
527     foreach(const QString &type, effectLists.keys()) {
528         EffectsList *list = effectLists[type];
529         dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
530         if (!dom.isNull()) break;
531     }
532     if (!dom.isNull()) {
533         dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
534         if (m_effectMetaInfo.trackMode) {
535             EffectsList::setParameter(dom, "in", QString::number(0));
536             EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
537             ItemInfo info;
538             info.track = m_trackInfo.type;
539             info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
540             info.cropStart = GenTime(0);
541             info.startPos = GenTime(-1);
542             info.track = 0;
543             m_effects.at(ix)->updateWidget(info, ix, dom, &m_effectMetaInfo);
544             emit updateEffect(NULL, m_trackindex, old, dom, ix);
545         } else {
546             m_clipref->initEffect(dom);
547             m_effects.at(ix)->updateWidget(m_clipref->info(), ix, dom, &m_effectMetaInfo);
548             //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
549             emit updateEffect(m_clipref, -1, old, dom, ix);
550         }
551     }
552
553     emit showComments(m_ui.buttonShowComments->isChecked());
554     m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
555 }
556
557 void EffectStackView2::slotShowComments()
558 {
559     m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
560     emit showComments(m_ui.buttonShowComments->isChecked());
561 }
562
563 void EffectStackView2::slotCreateGroup(int ix)
564 {
565     QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
566     QDomElement neweffect = oldeffect.cloneNode().toElement();
567     EffectInfo effectinfo;
568     effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
569     effectinfo.groupIndex = m_groupIndex;
570     neweffect.setAttribute("kdenlive_info", effectinfo.toString());
571
572     ItemInfo info;
573     if (m_effectMetaInfo.trackMode) { 
574         info.track = m_trackInfo.type;
575         info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
576         info.cropStart = GenTime(0);
577         info.startPos = GenTime(-1);
578         info.track = 0;
579         emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix);
580     } else {
581         emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix);
582     }
583     
584     QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
585     int groupPos = 0;
586     CollapsibleEffect *effectToMove = NULL;
587     for (int i = 0; i < m_effects.count(); i++) {
588         if (m_effects.at(i)->effectIndex() == ix) {
589             effectToMove = m_effects.at(i);
590             groupPos = l->indexOf(effectToMove);
591             l->removeWidget(effectToMove);
592             break;
593         }
594     }
595     
596     CollapsibleEffect *group = new CollapsibleEffect(QDomElement(), QDomElement(), ItemInfo(), m_groupIndex, &m_effectMetaInfo, false, true, m_ui.container->widget());
597     m_groupIndex++;
598     connect(group, SIGNAL(moveEffect(int,int,CollapsibleEffect*)), this , SLOT(slotMoveEffect(int,int,CollapsibleEffect*)));
599     connect(group, SIGNAL(unGroup(CollapsibleEffect*)), this , SLOT(slotUnGroup(CollapsibleEffect*)));
600     l->insertWidget(groupPos, group);
601     group->addGroupEffect(effectToMove);
602 }
603
604 void EffectStackView2::slotMoveEffect(int currentIndex, int newIndex, CollapsibleEffect* target)
605 {
606     CollapsibleEffect *effectToMove = getEffectByIndex(currentIndex);
607     if (effectToMove == NULL) return;
608
609     QDomElement oldeffect = effectToMove->effect();
610     QDomElement neweffect = oldeffect.cloneNode().toElement();
611     
612     EffectInfo effectinfo;
613     effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
614     effectinfo.groupIndex = target->groupIndex();
615     neweffect.setAttribute("kdenlive_info", effectinfo.toString());
616
617     ItemInfo info;
618     if (m_effectMetaInfo.trackMode) { 
619         info.track = m_trackInfo.type;
620         info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
621         info.cropStart = GenTime(0);
622         info.startPos = GenTime(-1);
623         info.track = 0;
624         emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->index());
625     } else {
626         emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->index());
627     }
628     
629     //if (currentIndex == newIndex) return;
630     // Update effect index with new position
631     if (m_effectMetaInfo.trackMode) {
632         emit changeEffectPosition(NULL, m_trackindex, currentIndex, newIndex);
633     }
634     else {
635         emit changeEffectPosition(m_clipref, -1, currentIndex, newIndex);
636     }
637 }
638
639 void EffectStackView2::slotUnGroup(CollapsibleEffect* group)
640 {
641     QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
642     int ix = l->indexOf(group);
643     group->removeGroup(ix, l);
644     group->deleteLater();
645 }
646
647 #include "effectstackview2.moc"