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