1 /***************************************************************************
2 effecstackview.cpp2 - description
5 copyright : (C) 2008 by Marco Gittler (g.marco@freenet.de)
6 copyright : (C) 2012 by Jean-Baptiste Mardelle (jb@kdenlive.org)
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
19 #include "effectstackview2.h"
20 #include "effectslist.h"
22 #include "mainwindow.h"
23 #include "docclipbase.h"
24 #include "projectlist.h"
26 #include "monitoreditwidget.h"
27 #include "monitorscene.h"
28 #include "kdenlivesettings.h"
29 #include "collapsibleeffect.h"
30 #include "collapsiblegroup.h"
34 #include <KMessageBox>
35 #include <KStandardDirs>
36 #include <KFileDialog>
37 #include <KColorScheme>
38 #include <KColorUtils>
41 #include <QTextStream>
43 #include <QInputDialog>
47 EffectStackView2::EffectStackView2(Monitor *monitor, QWidget *parent) :
51 m_draggedEffect(NULL),
54 m_monitorSceneWanted(false)
56 m_effectMetaInfo.trackMode = false;
57 m_effectMetaInfo.monitor = monitor;
58 m_effects = QList <CollapsibleEffect*>();
62 setFont(KGlobalSettings::smallestReadableFont());
63 m_ui.checkAll->setToolTip(i18n("Enable/Disable all effects"));
64 m_ui.buttonShowComments->setIcon(KIcon("help-about"));
65 m_ui.buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
67 connect(m_ui.checkAll, SIGNAL(stateChanged(int)), this, SLOT(slotCheckAll(int)));
68 connect(m_ui.buttonShowComments, SIGNAL(clicked()), this, SLOT(slotShowComments()));
69 m_ui.labelComment->setHidden(true);
74 setStyleSheet(getStyleSheet());
77 EffectStackView2::~EffectStackView2()
81 void EffectStackView2::updatePalette()
83 setStyleSheet(getStyleSheet());
86 void EffectStackView2::slotRenderPos(int pos)
88 if (m_effects.isEmpty()) return;
89 if (m_monitorSceneWanted) slotCheckMonitorPosition(pos);
90 if (!m_effectMetaInfo.trackMode && m_clipref) pos = pos - m_clipref->startPos().frames(KdenliveSettings::project_fps());
92 for (int i = 0; i< m_effects.count(); i++)
93 m_effects.at(i)->slotSyncEffectsPos(pos);
96 void EffectStackView2::slotClipItemSelected(ClipItem* c)
98 if (c && !c->isEnabled()) return;
99 if (c && c == m_clipref) {
104 QString cname = m_clipref->clipName();
105 if (cname.length() > 30) {
106 m_ui.checkAll->setToolTip(i18n("Effects for %1").arg(cname));
108 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "...");
110 m_ui.checkAll->setToolTip(QString());
111 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
113 m_ui.checkAll->setEnabled(true);
114 QString size = c->baseClip()->getProperty("frame_size");
115 double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
116 m_effectMetaInfo.frameSize = QPoint((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
119 if (m_clipref == NULL) {
120 //TODO: clear list, reset paramdesc and info
122 //m_effectedit->transferParamDesc(QDomElement(), info);
127 m_effectMetaInfo.trackMode = false;
128 m_currentEffectList = m_clipref->effectList();
132 void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
135 m_effectMetaInfo.trackMode = true;
136 m_currentEffectList = info.effectsList;
139 m_ui.checkAll->setToolTip(QString());
140 m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
146 void EffectStackView2::setupListView()
149 m_monitorSceneWanted = false;
150 m_draggedEffect = NULL;
151 m_draggedGroup = NULL;
152 disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
155 QWidget *view = m_ui.container->takeWidget();
160 view = new QWidget(m_ui.container);
161 m_ui.container->setWidget(view);
163 QVBoxLayout *vbox1 = new QVBoxLayout(view);
164 vbox1->setContentsMargins(0, 0, 0, 0);
165 vbox1->setSpacing(0);
167 for (int i = 0; i < m_currentEffectList.count(); i++) {
168 QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
170 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
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 for (int j = 0; j < vbox1->count(); j++) {
180 CollapsibleGroup *eff = static_cast<CollapsibleGroup *>(vbox1->itemAt(j)->widget());
181 if (eff->isGroup() && eff->groupIndex() == effectInfo.groupIndex) {
188 group = new CollapsibleGroup(effectInfo.groupIndex, i == 0, i == m_currentEffectList.count() - 1, effectInfo, m_ui.container->widget());
190 vbox1->addWidget(group);
191 group->installEventFilter( this );
193 if (effectInfo.groupIndex >= m_groupIndex) m_groupIndex = effectInfo.groupIndex + 1;
197 doc.appendChild(doc.importNode(d, true));
198 kDebug() << "IMPORTED STK: " << doc.toString();*/
201 bool isSelected = false;
202 if (m_effectMetaInfo.trackMode) {
203 info.track = m_trackInfo.type;
204 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
205 info.cropStart = GenTime(0);
206 info.startPos = GenTime(-1);
210 info = m_clipref->info();
213 CollapsibleEffect *currentEffect = new CollapsibleEffect(d, m_currentEffectList.at(i), info, &m_effectMetaInfo, i == m_currentEffectList.count() - 1, view);
214 if (m_effectMetaInfo.trackMode) {
215 isSelected = currentEffect->effectIndex() == 1;
218 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
221 currentEffect->setActive(true);
222 if (currentEffect->needsMonitorEffectScene()) m_monitorSceneWanted = true;
224 m_effects.append(currentEffect);
226 group->addGroupEffect(currentEffect);
228 vbox1->addWidget(currentEffect);
230 connectEffect(currentEffect);
233 if (m_currentEffectList.isEmpty()) {
234 m_ui.labelComment->setHidden(true);
237 // Adjust group effects (up / down buttons)
238 QList<CollapsibleGroup *> allGroups = m_ui.container->widget()->findChildren<CollapsibleGroup *>();
239 for (int i = 0; i < allGroups.count(); i++) {
240 allGroups.at(i)->adjustEffects();
242 connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
245 vbox1->addStretch(10);
246 slotUpdateCheckAllButton();
248 // Wait a little bit for the new layout to be ready, then check if we have a scrollbar
249 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
252 void EffectStackView2::connectEffect(CollapsibleEffect *currentEffect)
255 currentEffect->installEventFilter( this );
256 connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
257 connect(currentEffect, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,QString,QString)));
258 connect(currentEffect, SIGNAL(deleteEffect(const QDomElement)), this , SLOT(slotDeleteEffect(const QDomElement)));
259 connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
260 connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
261 connect(currentEffect, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
262 connect(currentEffect, SIGNAL(effectStateChanged(bool,int)), this, SLOT(slotUpdateEffectState(bool,int)));
263 connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
264 connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
265 connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
266 connect(currentEffect, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
267 connect(currentEffect, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
268 connect(currentEffect, SIGNAL(createRegion(int,KUrl)), this, SLOT(slotCreateRegion(int,KUrl)));
269 connect(currentEffect, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
272 void EffectStackView2::slotCheckWheelEventFilter()
274 // If the effect stack widget has no scrollbar, we will not filter the
275 // mouse wheel events, so that user can easily adjust effect params
276 bool filterWheelEvent = false;
277 if (m_ui.container->verticalScrollBar() && m_ui.container->verticalScrollBar()->isVisible()) {
278 // widget has scroll bar,
279 filterWheelEvent = true;
281 for (int i = 0; i < m_effects.count(); i++) {
282 m_effects.at(i)->filterWheelEvent = filterWheelEvent;
286 void EffectStackView2::resizeEvent ( QResizeEvent * event )
288 slotCheckWheelEventFilter();
289 QWidget::resizeEvent(event);
292 bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
294 // Check if user clicked in an effect's top bar to start dragging it
295 if (e->type() == QEvent::MouseButtonPress) {
296 m_draggedEffect = qobject_cast<CollapsibleEffect*>(o);
297 if (m_draggedEffect) {
298 QMouseEvent *me = static_cast<QMouseEvent *>(e);
299 if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse())) {
300 m_clickPoint = me->globalPos();
303 m_clickPoint = QPoint();
304 m_draggedEffect = NULL;
309 m_draggedGroup = qobject_cast<CollapsibleGroup*>(o);
310 if (m_draggedGroup) {
311 QMouseEvent *me = static_cast<QMouseEvent *>(e);
312 if (me->button() == Qt::LeftButton && (m_draggedGroup->frame->underMouse() || m_draggedGroup->title()->underMouse()))
313 m_clickPoint = me->globalPos();
315 m_clickPoint = QPoint();
316 m_draggedGroup = NULL;
322 /*if (e->type() == QEvent::MouseMove) {
323 if (qobject_cast<CollapsibleEffect*>(o)) {
324 QMouseEvent *me = static_cast<QMouseEvent *>(e);
325 if (me->buttons() != Qt::LeftButton) {
335 return QWidget::eventFilter(o, e);
338 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
340 if (m_draggedEffect || m_draggedGroup) {
341 if ((event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
347 void EffectStackView2::mouseReleaseEvent(QMouseEvent * event)
349 m_draggedEffect = NULL;
350 m_draggedGroup = NULL;
351 QWidget::mouseReleaseEvent(event);
354 void EffectStackView2::startDrag()
356 // The data to be transferred by the drag and drop operation is contained in a QMimeData object
359 if (m_draggedEffect) {
360 QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
361 doc.appendChild(doc.importNode(effect, true));
362 pixmap = QPixmap::grabWidget(m_draggedEffect->title);
364 else if (m_draggedGroup) {
365 doc = m_draggedGroup->effectsData();
366 pixmap = QPixmap::grabWidget(m_draggedGroup->title());
369 QDrag *drag = new QDrag(this);
370 drag->setPixmap(pixmap);
371 QMimeData *mime = new QMimeData;
373 data.append(doc.toString().toUtf8());
374 mime->setData("kdenlive/effectslist", data);
376 // Assign ownership of the QMimeData object to the QDrag object.
377 drag->setMimeData(mime);
378 // Start the drag and drop operation
379 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
383 void EffectStackView2::slotUpdateEffectState(bool disable, int index)
385 if (m_effectMetaInfo.trackMode)
386 emit changeEffectState(NULL, m_trackindex, QList <int>() << index, disable);
388 emit changeEffectState(m_clipref, -1, QList <int>() <<index, disable);
389 slotUpdateCheckAllButton();
393 void EffectStackView2::raiseWindow(QWidget* dock)
395 if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
400 void EffectStackView2::slotSeekTimeline(int pos)
402 if (m_effectMetaInfo.trackMode) {
403 emit seekTimeline(pos);
404 } else if (m_clipref) {
405 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
410 /*void EffectStackView2::slotRegionChanged()
412 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
415 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
417 if (m_monitorSceneWanted) {
418 if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
419 if (!m_effectMetaInfo.monitor->effectSceneDisplayed()) {
420 m_effectMetaInfo.monitor->slotShowEffectScene(true);
423 m_effectMetaInfo.monitor->slotShowEffectScene(false);
427 m_effectMetaInfo.monitor->slotShowEffectScene(false);
431 int EffectStackView2::isTrackMode(bool *ok) const
433 *ok = m_effectMetaInfo.trackMode;
437 void EffectStackView2::clear()
440 m_monitorSceneWanted = false;
441 QWidget *view = m_ui.container->takeWidget();
445 m_ui.checkAll->setToolTip(QString());
446 m_ui.checkAll->setText(QString());
447 m_ui.checkAll->setEnabled(false);
448 m_ui.labelComment->setText(QString());
452 void EffectStackView2::slotCheckAll(int state)
454 if (state == Qt::PartiallyChecked) {
456 m_ui.checkAll->blockSignals(true);
457 m_ui.checkAll->setCheckState(Qt::Checked);
458 m_ui.checkAll->blockSignals(false);
461 bool disabled = state == Qt::Unchecked;
462 // Disable all effects
464 for (int i = 0; i < m_effects.count(); i++) {
465 m_effects.at(i)->slotEnable(disabled, false);
466 indexes << m_effects.at(i)->effectIndex();
468 // Take care of groups
469 QList<CollapsibleGroup *> allGroups = m_ui.container->widget()->findChildren<CollapsibleGroup *>();
470 for (int i = 0; i < allGroups.count(); i++) {
471 allGroups.at(i)->slotEnable(disabled, false);
474 if (m_effectMetaInfo.trackMode)
475 emit changeEffectState(NULL, m_trackindex, indexes, disabled);
477 emit changeEffectState(m_clipref, -1, indexes, disabled);
480 void EffectStackView2::slotUpdateCheckAllButton()
482 bool hasEnabled = false;
483 bool hasDisabled = false;
485 for (int i = 0; i < m_effects.count(); i++) {
486 if (!m_effects.at(i)->enabledButton->isChecked()) hasEnabled = true;
487 else hasDisabled = true;
490 m_ui.checkAll->blockSignals(true);
491 if (hasEnabled && hasDisabled)
492 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
494 m_ui.checkAll->setCheckState(Qt::Checked);
496 m_ui.checkAll->setCheckState(Qt::Unchecked);
497 m_ui.checkAll->blockSignals(false);
500 void EffectStackView2::deleteCurrentEffect()
502 for (int i = 0; i < m_effects.count(); i++) {
503 if (m_effects.at(i)->isActive()) {
504 slotDeleteEffect(m_effects.at(i)->effect());
510 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
512 m_effectMetaInfo.profile = profile;
513 m_effectMetaInfo.timecode = t;
516 void EffectStackView2::updateTimecodeFormat()
518 for (int i = 0; i< m_effects.count(); i++)
519 m_effects.at(i)->updateTimecodeFormat();
522 CollapsibleEffect *EffectStackView2::getEffectByIndex(int ix)
524 for (int i = 0; i< m_effects.count(); i++) {
525 if (m_effects.at(i)->effectIndex() == ix) {
526 return m_effects.at(i);
532 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
534 if (m_effectMetaInfo.trackMode)
535 emit updateEffect(NULL, m_trackindex, old, e, ix,false);
536 else if (m_clipref) {
537 emit updateEffect(m_clipref, -1, old, e, ix, false);
538 // Make sure the changed effect is currently displayed
539 slotSetCurrentEffect(ix);
541 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
544 void EffectStackView2::slotSetCurrentEffect(int ix)
546 if (m_clipref && ix != m_clipref->selectedEffectIndex()) {
547 m_clipref->setSelectedEffect(ix);
548 for (int i = 0; i < m_effects.count(); i++) {
549 if (m_effects.at(i)->effectIndex() == ix) {
550 if (m_effects.at(i)->isActive()) return;
551 m_effects.at(i)->setActive(true);
552 m_monitorSceneWanted = m_effects.at(i)->needsMonitorEffectScene();
553 slotCheckMonitorPosition(m_effectMetaInfo.monitor->render->seekFramePosition());
554 m_ui.labelComment->setText(i18n(m_effects.at(i)->effect().firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
555 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
557 else m_effects.at(i)->setActive(false);
562 void EffectStackView2::slotDeleteGroup(QDomDocument doc)
564 QDomNodeList effects = doc.elementsByTagName("effect");
565 ClipItem * clip = NULL;
567 if (m_effectMetaInfo.trackMode) {
575 for (int i = 0; i < effects.count(); i++)
576 emit removeEffect(clip, ix, effects.at(i).toElement());
579 void EffectStackView2::slotDeleteEffect(const QDomElement effect)
581 if (m_effectMetaInfo.trackMode)
582 emit removeEffect(NULL, m_trackindex, effect);
584 emit removeEffect(m_clipref, -1, effect);
587 void EffectStackView2::slotAddEffect(QDomElement effect)
589 emit addEffect(m_clipref, effect);
592 void EffectStackView2::slotMoveEffectUp(QList <int> indexes, bool up)
594 if (up && indexes.first() <= 1) return;
595 if (!up && indexes.last() >= m_currentEffectList.count()) return;
598 endPos = indexes.first() - 1;
601 endPos = indexes.last() + 1;
603 if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, indexes, endPos);
604 else emit changeEffectPosition(m_clipref, -1, indexes, endPos);
607 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
609 if (!m_clipref) return;
610 emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, finalFilterName, consumer, consumerParams, properties);
613 void EffectStackView2::slotResetEffect(int ix)
615 QDomElement old = m_currentEffectList.itemFromIndex(ix);
617 QString effectId = old.attribute("id");
618 QMap<QString, EffectsList*> effectLists;
619 effectLists["audio"] = &MainWindow::audioEffects;
620 effectLists["video"] = &MainWindow::videoEffects;
621 effectLists["custom"] = &MainWindow::customEffects;
622 foreach(const QString &type, effectLists.keys()) {
623 EffectsList *list = effectLists[type];
624 dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
625 if (!dom.isNull()) break;
628 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
629 if (m_effectMetaInfo.trackMode) {
630 EffectsList::setParameter(dom, "in", QString::number(0));
631 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
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);
638 m_effects.at(ix)->updateWidget(info, dom, &m_effectMetaInfo);
639 emit updateEffect(NULL, m_trackindex, old, dom, ix,false);
641 m_clipref->initEffect(dom);
642 for (int i = 0; i < m_effects.count(); i++) {
643 if (m_effects.at(i)->effectIndex() == ix) {
644 m_effects.at(i)->updateWidget(m_clipref->info(), dom, &m_effectMetaInfo);
648 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
649 emit updateEffect(m_clipref, -1, old, dom, ix,false);
653 emit showComments(m_ui.buttonShowComments->isChecked());
654 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
657 void EffectStackView2::slotShowComments()
659 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
660 emit showComments(m_ui.buttonShowComments->isChecked());
663 void EffectStackView2::slotCreateRegion(int ix, KUrl url)
665 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
666 QDomElement neweffect = oldeffect.cloneNode().toElement();
667 QDomElement region = MainWindow::videoEffects.getEffectByTag("region", "region").cloneNode().toElement();
668 region.appendChild(region.ownerDocument().importNode(neweffect, true));
669 region.setAttribute("kdenlive_ix", ix);
670 EffectsList::setParameter(region, "resource", url.path());
671 if (m_effectMetaInfo.trackMode)
672 emit updateEffect(NULL, m_trackindex, oldeffect, region, ix,false);
673 else if (m_clipref) {
674 emit updateEffect(m_clipref, -1, oldeffect, region, ix, false);
675 // Make sure the changed effect is currently displayed
676 //slotSetCurrentEffect(ix);
678 // refresh effect stack
680 bool isSelected = false;
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);
689 info = m_clipref->info();
691 CollapsibleEffect *current = getEffectByIndex(ix);
692 m_effects.removeAll(current);
693 current->setEnabled(false);
694 m_currentEffectList.removeAt(ix);
695 m_currentEffectList.insert(region);
696 current->deleteLater();
697 CollapsibleEffect *currentEffect = new CollapsibleEffect(region, m_currentEffectList.itemFromIndex(ix), info, &m_effectMetaInfo, ix == m_currentEffectList.count() - 1, m_ui.container->widget());
698 connectEffect(currentEffect);
700 if (m_effectMetaInfo.trackMode) {
701 isSelected = currentEffect->effectIndex() == 1;
704 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
706 if (isSelected) currentEffect->setActive(true);
707 m_effects.append(currentEffect);
708 // TODO: region in group?
710 // group->addGroupEffect(currentEffect);
712 QVBoxLayout *vbox = static_cast <QVBoxLayout *> (m_ui.container->widget()->layout());
713 vbox->insertWidget(ix, currentEffect);
717 currentEffect->installEventFilter( this );
719 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
723 void EffectStackView2::slotCreateGroup(int ix)
725 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
726 QDomElement neweffect = oldeffect.cloneNode().toElement();
727 EffectInfo effectinfo;
728 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
729 effectinfo.groupIndex = m_groupIndex;
730 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
733 if (m_effectMetaInfo.trackMode) {
734 info.track = m_trackInfo.type;
735 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
736 info.cropStart = GenTime(0);
737 info.startPos = GenTime(-1);
739 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix, false);
741 emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix, false);
744 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
746 CollapsibleEffect *effectToMove = NULL;
747 for (int i = 0; i < m_effects.count(); i++) {
748 if (m_effects.at(i)->effectIndex() == ix) {
749 effectToMove = m_effects.at(i);
750 groupPos = l->indexOf(effectToMove);
751 l->removeWidget(effectToMove);
756 CollapsibleGroup *group = new CollapsibleGroup(m_groupIndex, ix == 1, ix == m_currentEffectList.count() - 2, effectinfo, m_ui.container->widget());
759 l->insertWidget(groupPos, group);
760 group->installEventFilter( this );
761 group->addGroupEffect(effectToMove);
764 void EffectStackView2::connectGroup(CollapsibleGroup *group)
766 connect(group, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
767 connect(group, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
768 connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
769 connect(group, SIGNAL(groupRenamed(CollapsibleGroup *)), this , SLOT(slotRenameGroup(CollapsibleGroup*)));
770 connect(group, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
771 connect(group, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
772 connect(group, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
775 void EffectStackView2::slotMoveEffect(QList <int> currentIndexes, int newIndex, int groupIndex, QString groupName)
777 if (currentIndexes.count() == 1) {
778 CollapsibleEffect *effectToMove = getEffectByIndex(currentIndexes.at(0));
779 if (effectToMove == NULL) return;
781 QDomElement oldeffect = effectToMove->effect();
782 QDomElement neweffect = oldeffect.cloneNode().toElement();
784 EffectInfo effectinfo;
785 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
786 effectinfo.groupIndex = groupIndex;
787 effectinfo.groupName = groupName;
788 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
790 if (oldeffect.attribute("kdenlive_info") != effectinfo.toString()) {
791 // effect's group info or collapsed state changed
793 if (m_effectMetaInfo.trackMode) {
794 info.track = m_trackInfo.type;
795 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
796 info.cropStart = GenTime(0);
797 info.startPos = GenTime(-1);
799 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->effectIndex(),false);
801 emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex(),false);
806 // Update effect index with new position
807 if (m_effectMetaInfo.trackMode) {
808 emit changeEffectPosition(NULL, m_trackindex, currentIndexes, newIndex);
811 emit changeEffectPosition(m_clipref, -1, currentIndexes, newIndex);
815 void EffectStackView2::slotUnGroup(CollapsibleGroup* group)
817 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
818 int ix = l->indexOf(group);
819 group->removeGroup(ix, l);
820 group->deleteLater();
823 void EffectStackView2::slotRenameGroup(CollapsibleGroup *group)
825 QList <CollapsibleEffect*> effects = group->effects();
826 for (int i = 0; i < effects.count(); i++) {
827 QDomElement origin = effects.at(i)->effect();
828 QDomElement changed = origin.cloneNode().toElement();
829 changed.setAttribute("kdenlive_info", effects.at(i)->infoString());
830 if (m_effectMetaInfo.trackMode) {
831 emit updateEffect(NULL, m_trackindex, origin, changed, effects.at(i)->effectIndex(),false);
833 emit updateEffect(m_clipref, -1, origin, changed, effects.at(i)->effectIndex(),false);
838 void EffectStackView2::dragEnterEvent(QDragEnterEvent *event)
840 if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
841 event->acceptProposedAction();
845 void EffectStackView2::processDroppedEffect(QDomElement e, QDropEvent *event)
847 int ix = e.attribute("kdenlive_ix").toInt();
848 if (e.tagName() == "effectgroup") {
849 // We are dropping a group, all effects in group should be moved
850 QDomNodeList effects = e.elementsByTagName("effect");
851 if (effects.count() == 0) {
856 info.fromString(effects.at(0).toElement().attribute("kdenlive_info"));
857 if (info.groupIndex < 0) {
858 kDebug()<<"// ADDING EFFECT!!!";
859 // Adding a new group effect to the stack
860 event->setDropAction(Qt::CopyAction);
865 // Moving group: delete all effects and re-add them
867 for (int i = 0; i < effects.count(); i++) {
868 QDomElement effect = effects.at(i).cloneNode().toElement();
869 indexes << effect.attribute("kdenlive_ix").toInt();
871 kDebug()<<"// Moving: "<<indexes<<" TO "<<m_currentEffectList.count();
872 slotMoveEffect(indexes, m_currentEffectList.count(), info.groupIndex, info.groupName);
875 // effect dropped from effects list, add it
876 e.setAttribute("kdenlive_ix", m_currentEffectList.count() + 1);
877 event->setDropAction(Qt::CopyAction);
883 // User is moving an effect
884 slotMoveEffect(QList<int> () << ix, m_currentEffectList.count() + 1, -1);
886 event->setDropAction(Qt::MoveAction);
890 void EffectStackView2::dropEvent(QDropEvent *event)
892 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
893 //event->acceptProposedAction();
895 doc.setContent(effects, true);
896 processDroppedEffect(doc.documentElement(), event);
900 const QString EffectStackView2::getStyleSheet()
902 KColorScheme scheme(QApplication::palette().currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
903 QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
904 QColor hgh = KColorUtils::mix(QApplication::palette().window().color(), selected_bg, 0.2);
905 QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
906 QColor light_bg = scheme.shade(KColorScheme::LightShade);
907 QColor alt_bg = scheme.background(KColorScheme::NormalBackground).color();
912 stylesheet.append(QString("QFrame#decoframe {border-top-left-radius:5px;border-top-right-radius:5px;border-bottom:2px solid palette(mid);border-top:1px solid palette(light);} QFrame#decoframe[active=\"true\"] {background: %1;}").arg(hgh.name()));
914 // effect in group background
915 stylesheet.append(QString("QFrame#decoframesub {border-top:1px solid palette(light);} QFrame#decoframesub[active=\"true\"] {background: %1;}").arg(hgh.name()));
918 stylesheet.append(QString("QFrame#decoframegroup {border-top-left-radius:5px;border-top-right-radius:5px;border:2px solid palette(dark);margin:0px;margin-top:2px;} "));
921 stylesheet.append(QString("QFrame#frame {margin-bottom:2px;border-top-left-radius:5px;border-top-right-radius:5px;} QFrame#frame[target=\"true\"] {background: palette(highlight);}"));
923 // group effect title bar
924 stylesheet.append(QString("QFrame#framegroup {border-top-left-radius:2px;border-top-right-radius:2px;background: palette(dark);} QFrame#framegroup[target=\"true\"] {background: palette(highlight);} "));
926 // draggable effect bar content
927 stylesheet.append(QString("QProgressBar::chunk:horizontal {background: palette(button);border-top-left-radius: 4px;border-bottom-left-radius: 4px;} QProgressBar::chunk:horizontal#dragOnly {background: %1;border-top-left-radius: 4px;border-bottom-left-radius: 4px;} QProgressBar::chunk:horizontal:hover {background: %2;}").arg(alt_bg.name()).arg(selected_bg.name()));
929 // draggable effect bar
930 stylesheet.append(QString("QProgressBar:horizontal {border: 1px solid palette(dark);border-top-left-radius: 4px;border-bottom-left-radius: 4px;border-right:0px;background:%3;padding: 0px;text-align:left center} QProgressBar:horizontal:disabled {border: 1px solid palette(button)} QProgressBar:horizontal#dragOnly {background: %3} QProgressBar:horizontal[inTimeline=\"true\"] { border: 1px solid %1;border-right: 0px;background: %2;padding: 0px;text-align:left center } QProgressBar::chunk:horizontal[inTimeline=\"true\"] {background: %1;}").arg(hover_bg.name()).arg(light_bg.name()).arg(alt_bg.name()));
932 // spin box for draggable widget
933 stylesheet.append(QString("QAbstractSpinBox#dragBox {border: 1px solid palette(dark);border-top-right-radius: 4px;border-bottom-right-radius: 4px;padding-right:0px;} QAbstractSpinBox::down-button#dragBox {width:0px;padding:0px;} QAbstractSpinBox:disabled#dragBox {border: 1px solid palette(button);} QAbstractSpinBox::up-button#dragBox {width:0px;padding:0px;} QAbstractSpinBox[inTimeline=\"true\"]#dragBox { border: 1px solid %1;} QAbstractSpinBox:hover#dragBox {border: 1px solid %2;} ").arg(hover_bg.name()).arg(selected_bg.name()));
935 // group editable labels
936 stylesheet.append(QString("MyEditableLabel { background-color: transparent; color: palette(bright-text); border-radius: 2px;border: 1px solid transparent;} MyEditableLabel:hover {border: 1px solid palette(highlight);} "));
941 #include "effectstackview2.moc"