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