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