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