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