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