]> git.sesse.net Git - kdenlive/blob - src/effectstack/effectstackview2.cpp
91476f0b476b4effe6cc24f55e4c2f8f1d96aa6d
[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(QDomDocument)), this , SLOT(slotDeleteGroup(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,bool)), this, SLOT(slotUpdateEffectState(bool,int,bool)));
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, bool updateMainStatus)
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     if (updateMainStatus) 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 == Qt::PartiallyChecked) {
428         state = Qt::Checked;
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 == Qt::Unchecked;
435     for (int i = 0; i < m_effects.count(); i++) {
436         if (!m_effects.at(i)->isGroup()) {
437             m_effects.at(i)->slotEnable(disabled, false);
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)->enabledButton->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
521 void EffectStackView2::slotDeleteGroup(QDomDocument doc)
522 {
523     QDomNodeList effects = doc.elementsByTagName("effect");
524     ClipItem * clip = NULL;
525     int ix;
526     if (m_effectMetaInfo.trackMode) {
527         ix = m_trackindex;
528     }
529     else {
530         clip = m_clipref;
531         ix = -1;
532     }
533     
534     for (int i = 0; i < effects.count(); i++)
535         emit removeEffect(clip, ix, effects.at(i).toElement());
536 }
537
538 void EffectStackView2::slotDeleteEffect(const QDomElement effect)
539 {
540     if (m_effectMetaInfo.trackMode)
541         emit removeEffect(NULL, m_trackindex, effect);
542     else
543         emit removeEffect(m_clipref, -1, effect);
544 }
545
546 void EffectStackView2::slotAddEffect(QDomElement effect)
547 {
548     emit addEffect(m_clipref, effect);
549 }
550
551 void EffectStackView2::slotMoveEffectUp(int index, bool up)
552 {
553     if (up && index <= 1) return;
554     if (!up && index >= m_currentEffectList.count()) return;
555     int endPos;
556     if (up) {
557         endPos = index - 1;
558     }
559     else {
560         endPos =  index + 1;
561     }
562     if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, index, endPos);
563     else emit changeEffectPosition(m_clipref, -1, index, endPos);
564 }
565
566 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
567 {
568     if (!m_clipref) return;
569     emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, finalFilterName, consumer, consumerParams, properties);
570 }
571
572 void EffectStackView2::slotResetEffect(int ix)
573 {
574     QDomElement old = m_currentEffectList.itemFromIndex(ix);
575     QDomElement dom;
576     QString effectId = old.attribute("id");
577     QMap<QString, EffectsList*> effectLists;
578     effectLists["audio"] = &MainWindow::audioEffects;
579     effectLists["video"] = &MainWindow::videoEffects;
580     effectLists["custom"] = &MainWindow::customEffects;
581     foreach(const QString &type, effectLists.keys()) {
582         EffectsList *list = effectLists[type];
583         dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
584         if (!dom.isNull()) break;
585     }
586     if (!dom.isNull()) {
587         dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
588         if (m_effectMetaInfo.trackMode) {
589             EffectsList::setParameter(dom, "in", QString::number(0));
590             EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
591             ItemInfo info;
592             info.track = m_trackInfo.type;
593             info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
594             info.cropStart = GenTime(0);
595             info.startPos = GenTime(-1);
596             info.track = 0;
597             m_effects.at(ix)->updateWidget(info, dom, &m_effectMetaInfo);
598             emit updateEffect(NULL, m_trackindex, old, dom, ix,false);
599         } else {
600             m_clipref->initEffect(dom);
601             for (int i = 0; i < m_effects.count(); i++) {
602                 if (m_effects.at(i)->effectIndex() == ix) {
603                     m_effects.at(i)->updateWidget(m_clipref->info(), dom, &m_effectMetaInfo);
604                     break;
605                 }
606             }
607             //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
608             emit updateEffect(m_clipref, -1, old, dom, ix,false);
609         }
610     }
611
612     emit showComments(m_ui.buttonShowComments->isChecked());
613     m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
614 }
615
616 void EffectStackView2::slotShowComments()
617 {
618     m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
619     emit showComments(m_ui.buttonShowComments->isChecked());
620 }
621
622 void EffectStackView2::slotCreateGroup(int ix)
623 {
624     QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
625     QDomElement neweffect = oldeffect.cloneNode().toElement();
626     EffectInfo effectinfo;
627     effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
628     effectinfo.groupIndex = m_groupIndex;
629     neweffect.setAttribute("kdenlive_info", effectinfo.toString());
630
631     ItemInfo info;
632     if (m_effectMetaInfo.trackMode) { 
633         info.track = m_trackInfo.type;
634         info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
635         info.cropStart = GenTime(0);
636         info.startPos = GenTime(-1);
637         info.track = 0;
638         emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix, false);
639     } else {
640         emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix, false);
641     }
642     
643     QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
644     int groupPos = 0;
645     CollapsibleEffect *effectToMove = NULL;
646     for (int i = 0; i < m_effects.count(); i++) {
647         if (m_effects.at(i)->effectIndex() == ix) {
648             effectToMove = m_effects.at(i);
649             groupPos = l->indexOf(effectToMove);
650             l->removeWidget(effectToMove);
651             break;
652         }
653     }
654     
655     CollapsibleGroup *group = new CollapsibleGroup(m_groupIndex, ix == 1, ix == m_currentEffectList.count() - 2, QString(), m_ui.container->widget());
656     m_groupIndex++;
657     connect(group, SIGNAL(moveEffect(int,int,int,QString)), this , SLOT(slotMoveEffect(int,int,int,QString)));
658     connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
659     connect(group, SIGNAL(groupRenamed(CollapsibleGroup *)), this , SLOT(slotRenameGroup(CollapsibleGroup*)));
660     connect(group, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
661     connect(group, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
662     l->insertWidget(groupPos, group);
663     group->installEventFilter( this );
664     group->addGroupEffect(effectToMove);
665 }
666
667 void EffectStackView2::slotMoveEffect(int currentIndex, int newIndex, int groupIndex, QString groupName)
668 {
669     CollapsibleEffect *effectToMove = getEffectByIndex(currentIndex);
670     if (effectToMove == NULL) return;
671
672     QDomElement oldeffect = effectToMove->effect();
673     QDomElement neweffect = oldeffect.cloneNode().toElement();
674     
675     EffectInfo effectinfo;
676     effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
677     effectinfo.groupIndex = groupIndex;
678     effectinfo.groupName = groupName;
679     neweffect.setAttribute("kdenlive_info", effectinfo.toString());
680
681     ItemInfo info;
682     if (m_effectMetaInfo.trackMode) { 
683         info.track = m_trackInfo.type;
684         info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
685         info.cropStart = GenTime(0);
686         info.startPos = GenTime(-1);
687         info.track = 0;
688         emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->effectIndex(),false);
689     } else {
690         emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex(),false);
691     }
692     //if (currentIndex == newIndex) return;
693     // Update effect index with new position
694     if (m_effectMetaInfo.trackMode) {
695         emit changeEffectPosition(NULL, m_trackindex, currentIndex, newIndex);
696     }
697     else {
698         emit changeEffectPosition(m_clipref, -1, currentIndex, newIndex);
699     }
700 }
701
702 void EffectStackView2::slotUnGroup(CollapsibleGroup* group)
703 {
704     QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
705     int ix = l->indexOf(group);
706     group->removeGroup(ix, l);
707     group->deleteLater();
708 }
709
710 void EffectStackView2::slotRenameGroup(CollapsibleGroup *group)
711 {
712     QList <CollapsibleEffect*> effects = group->effects();
713     for (int i = 0; i < effects.count(); i++) {
714         QDomElement origin = effects.at(i)->effect();
715         QDomElement changed = origin.cloneNode().toElement();
716         changed.setAttribute("kdenlive_info", effects.at(i)->infoString());
717         if (m_effectMetaInfo.trackMode) { 
718             emit updateEffect(NULL, m_trackindex, origin, changed, effects.at(i)->effectIndex(),false);
719         } else {
720             emit updateEffect(m_clipref, -1, origin, changed, effects.at(i)->effectIndex(),false);
721         }
722     }
723 }
724
725 #include "effectstackview2.moc"