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