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