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