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::slotClipItemUpdate()
98 int inPoint = m_clipref->cropStart().frames(KdenliveSettings::project_fps());
99 int outPoint = m_clipref->cropDuration().frames(KdenliveSettings::project_fps()) - inPoint;
100 CollapsibleEffect *effectToMove = NULL;
101 for (int i = 0; i < m_effects.count(); i++) {
102 m_effects.at(i)->setRange(inPoint, outPoint);
106 void EffectStackView2::slotClipItemSelected(ClipItem* c)
108 if (c && !c->isEnabled()) return;
109 if (c && c == m_clipref) {
112 if (m_clipref) disconnect(m_clipref, SIGNAL(updateRange()), this, SLOT(slotClipItemUpdate()));
115 connect(m_clipref, SIGNAL(updateRange()), this, SLOT(slotClipItemUpdate()));
116 QString cname = m_clipref->clipName();
117 if (cname.length() > 30) {
118 m_ui.checkAll->setToolTip(i18n("Effects for %1", cname));
120 m_ui.checkAll->setText(i18n("Effects for %1", cname) + "...");
122 m_ui.checkAll->setToolTip(QString());
123 m_ui.checkAll->setText(i18n("Effects for %1", cname));
125 m_ui.checkAll->setEnabled(true);
126 QString size = c->baseClip()->getProperty("frame_size");
127 double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
128 m_effectMetaInfo.frameSize = QPoint((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
131 if (m_clipref == NULL) {
132 //TODO: clear list, reset paramdesc and info
133 // If monitor scene is displayed, hide it
134 if (m_monitorSceneWanted) {
135 m_effectMetaInfo.monitor->slotShowEffectScene(false);
137 m_monitorSceneWanted = false;
142 m_effectMetaInfo.trackMode = false;
143 m_currentEffectList = m_clipref->effectList();
147 void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
150 m_effectMetaInfo.trackMode = true;
151 m_currentEffectList = info.effectsList;
154 m_ui.checkAll->setToolTip(QString());
155 m_ui.checkAll->setText(i18n("Effects for track %1", info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
156 m_ui.checkAll->setEnabled(true);
162 void EffectStackView2::setupListView()
165 m_monitorSceneWanted = false;
166 m_draggedEffect = NULL;
167 m_draggedGroup = NULL;
168 disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
171 QWidget *view = m_ui.container->takeWidget();
176 view = new QWidget(m_ui.container);
177 m_ui.container->setWidget(view);
179 QVBoxLayout *vbox1 = new QVBoxLayout(view);
180 vbox1->setContentsMargins(0, 0, 0, 0);
181 vbox1->setSpacing(0);
183 int effectsCount = m_currentEffectList.count();
185 // Make sure we always have one effect selected
186 if (!m_effectMetaInfo.trackMode) {
187 int selectedEffect = m_clipref->selectedEffectIndex();
188 if (selectedEffect < 1 && effectsCount > 0) m_clipref->setSelectedEffect(1);
189 else if (selectedEffect > effectsCount) m_clipref->setSelectedEffect(effectsCount);
192 for (int i = 0; i < effectsCount; i++) {
193 QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
195 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
199 CollapsibleGroup *group = NULL;
200 EffectInfo effectInfo;
201 effectInfo.fromString(d.attribute("kdenlive_info"));
202 if (effectInfo.groupIndex >= 0) {
203 // effect is in a group
204 for (int j = 0; j < vbox1->count(); j++) {
205 CollapsibleGroup *eff = static_cast<CollapsibleGroup *>(vbox1->itemAt(j)->widget());
206 if (eff->isGroup() && eff->groupIndex() == effectInfo.groupIndex) {
213 group = new CollapsibleGroup(effectInfo.groupIndex, i == 0, i == effectsCount - 1, effectInfo, m_ui.container->widget());
215 vbox1->addWidget(group);
216 group->installEventFilter( this );
218 if (effectInfo.groupIndex >= m_groupIndex) m_groupIndex = effectInfo.groupIndex + 1;
222 doc.appendChild(doc.importNode(d, true));
223 kDebug() << "IMPORTED STK: " << doc.toString();*/
226 bool isSelected = false;
227 if (m_effectMetaInfo.trackMode) {
228 info.track = m_trackInfo.type;
229 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
230 info.cropStart = GenTime(0);
231 info.startPos = GenTime(-1);
235 info = m_clipref->info();
238 CollapsibleEffect *currentEffect = new CollapsibleEffect(d, m_currentEffectList.at(i), info, &m_effectMetaInfo, i == effectsCount - 1, view);
239 if (m_effectMetaInfo.trackMode) {
240 isSelected = currentEffect->effectIndex() == 1;
243 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
246 currentEffect->setActive(true);
247 if (currentEffect->needsMonitorEffectScene()) m_monitorSceneWanted = true;
249 m_effects.append(currentEffect);
251 group->addGroupEffect(currentEffect);
253 vbox1->addWidget(currentEffect);
255 connectEffect(currentEffect);
258 if (m_currentEffectList.isEmpty()) {
259 m_ui.labelComment->setHidden(true);
262 // Adjust group effects (up / down buttons)
263 QList<CollapsibleGroup *> allGroups = m_ui.container->widget()->findChildren<CollapsibleGroup *>();
264 for (int i = 0; i < allGroups.count(); i++) {
265 allGroups.at(i)->adjustEffects();
267 connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
270 vbox1->addStretch(10);
271 slotUpdateCheckAllButton();
272 if (!m_monitorSceneWanted) {
273 // monitor scene not wanted
274 m_effectMetaInfo.monitor->slotShowEffectScene(false);
277 // Wait a little bit for the new layout to be ready, then check if we have a scrollbar
278 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
281 void EffectStackView2::connectEffect(CollapsibleEffect *currentEffect)
284 currentEffect->installEventFilter( this );
285 connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
286 connect(currentEffect, SIGNAL(startFilterJob(QString,QString,QString,QString,const QMap <QString, QString>)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,const QMap <QString, QString>)));
287 connect(currentEffect, SIGNAL(deleteEffect(const QDomElement)), this , SLOT(slotDeleteEffect(const QDomElement)));
288 connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
289 connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
290 connect(currentEffect, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
291 connect(currentEffect, SIGNAL(effectStateChanged(bool,int,bool)), this, SLOT(slotUpdateEffectState(bool,int,bool)));
292 connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
293 connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
294 connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
295 connect(currentEffect, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
296 connect(currentEffect, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
297 connect(currentEffect, SIGNAL(createRegion(int,KUrl)), this, SLOT(slotCreateRegion(int,KUrl)));
298 connect(currentEffect, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
299 connect(currentEffect, SIGNAL(importClipKeyframes()), this, SIGNAL(importClipKeyframes()));
302 void EffectStackView2::slotCheckWheelEventFilter()
304 // If the effect stack widget has no scrollbar, we will not filter the
305 // mouse wheel events, so that user can easily adjust effect params
306 bool filterWheelEvent = false;
307 if (m_ui.container->verticalScrollBar() && m_ui.container->verticalScrollBar()->isVisible()) {
308 // widget has scroll bar,
309 filterWheelEvent = true;
311 for (int i = 0; i < m_effects.count(); i++) {
312 m_effects.at(i)->filterWheelEvent = filterWheelEvent;
316 void EffectStackView2::resizeEvent ( QResizeEvent * event )
318 slotCheckWheelEventFilter();
319 QWidget::resizeEvent(event);
322 bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
324 // Check if user clicked in an effect's top bar to start dragging it
325 if (e->type() == QEvent::MouseButtonPress) {
326 m_draggedEffect = qobject_cast<CollapsibleEffect*>(o);
327 if (m_draggedEffect) {
328 QMouseEvent *me = static_cast<QMouseEvent *>(e);
329 if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse())) {
330 m_clickPoint = me->globalPos();
333 m_clickPoint = QPoint();
334 m_draggedEffect = NULL;
339 m_draggedGroup = qobject_cast<CollapsibleGroup*>(o);
340 if (m_draggedGroup) {
341 QMouseEvent *me = static_cast<QMouseEvent *>(e);
342 if (me->button() == Qt::LeftButton && (m_draggedGroup->frame->underMouse() || m_draggedGroup->title()->underMouse()))
343 m_clickPoint = me->globalPos();
345 m_clickPoint = QPoint();
346 m_draggedGroup = NULL;
352 /*if (e->type() == QEvent::MouseMove) {
353 if (qobject_cast<CollapsibleEffect*>(o)) {
354 QMouseEvent *me = static_cast<QMouseEvent *>(e);
355 if (me->buttons() != Qt::LeftButton) {
365 return QWidget::eventFilter(o, e);
368 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
370 if (m_draggedEffect || m_draggedGroup) {
371 if ((event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
377 void EffectStackView2::mouseReleaseEvent(QMouseEvent * event)
379 m_draggedEffect = NULL;
380 m_draggedGroup = NULL;
381 QWidget::mouseReleaseEvent(event);
384 void EffectStackView2::startDrag()
386 // The data to be transferred by the drag and drop operation is contained in a QMimeData object
389 if (m_draggedEffect) {
390 QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
391 if (m_effectMetaInfo.trackMode) {
392 // Keep clip crop start in case we want to paste effect
393 effect.setAttribute("clipstart", 0);
396 // Keep clip crop start in case we want to paste effect
397 effect.setAttribute("clipstart", m_clipref->cropStart().frames(KdenliveSettings::project_fps()));
399 doc.appendChild(doc.importNode(effect, true));
400 pixmap = QPixmap::grabWidget(m_draggedEffect->title);
402 else if (m_draggedGroup) {
403 doc = m_draggedGroup->effectsData();
404 if (m_effectMetaInfo.trackMode) {
405 doc.documentElement().setAttribute("clipstart", 0);
408 doc.documentElement().setAttribute("clipstart", m_clipref->cropStart().frames(KdenliveSettings::project_fps()));
410 pixmap = QPixmap::grabWidget(m_draggedGroup->title());
413 QDrag *drag = new QDrag(this);
414 drag->setPixmap(pixmap);
415 QMimeData *mime = new QMimeData;
417 data.append(doc.toString().toUtf8());
418 mime->setData("kdenlive/effectslist", data);
420 // Assign ownership of the QMimeData object to the QDrag object.
421 drag->setMimeData(mime);
422 // Start the drag and drop operation
423 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
427 void EffectStackView2::slotUpdateEffectState(bool disable, int index, bool needsMonitorEffectScene)
429 if (m_monitorSceneWanted && disable) {
430 m_effectMetaInfo.monitor->slotShowEffectScene(false);
431 m_monitorSceneWanted = false;
433 else if (!disable && !m_monitorSceneWanted && needsMonitorEffectScene) {
434 m_effectMetaInfo.monitor->slotShowEffectScene(true);
435 m_monitorSceneWanted = true;
437 if (m_effectMetaInfo.trackMode)
438 emit changeEffectState(NULL, m_trackindex, QList <int>() << index, disable);
440 emit changeEffectState(m_clipref, -1, QList <int>() <<index, disable);
441 slotUpdateCheckAllButton();
445 void EffectStackView2::raiseWindow(QWidget* dock)
447 if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
452 void EffectStackView2::slotSeekTimeline(int pos)
454 if (m_effectMetaInfo.trackMode) {
455 emit seekTimeline(pos);
456 } else if (m_clipref) {
457 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
462 /*void EffectStackView2::slotRegionChanged()
464 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
467 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
469 if (m_monitorSceneWanted) {
470 if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
471 if (!m_effectMetaInfo.monitor->effectSceneDisplayed()) {
472 m_effectMetaInfo.monitor->slotShowEffectScene(true);
475 m_effectMetaInfo.monitor->slotShowEffectScene(false);
479 m_effectMetaInfo.monitor->slotShowEffectScene(false);
483 int EffectStackView2::isTrackMode(bool *ok) const
485 *ok = m_effectMetaInfo.trackMode;
489 void EffectStackView2::clear()
492 m_monitorSceneWanted = false;
493 QWidget *view = m_ui.container->takeWidget();
497 m_ui.checkAll->setToolTip(QString());
498 m_ui.checkAll->setText(QString());
499 m_ui.checkAll->setEnabled(false);
500 m_ui.labelComment->setText(QString());
504 void EffectStackView2::slotCheckAll(int state)
506 if (state == Qt::PartiallyChecked) {
508 m_ui.checkAll->blockSignals(true);
509 m_ui.checkAll->setCheckState(Qt::Checked);
510 m_ui.checkAll->blockSignals(false);
513 bool disabled = state == Qt::Unchecked;
514 // Disable all effects
516 for (int i = 0; i < m_effects.count(); i++) {
517 m_effects.at(i)->slotDisable(disabled, false);
518 indexes << m_effects.at(i)->effectIndex();
520 // Take care of groups
521 QList<CollapsibleGroup *> allGroups = m_ui.container->widget()->findChildren<CollapsibleGroup *>();
522 for (int i = 0; i < allGroups.count(); i++) {
523 allGroups.at(i)->slotEnable(disabled, false);
526 if (m_effectMetaInfo.trackMode)
527 emit changeEffectState(NULL, m_trackindex, indexes, disabled);
529 emit changeEffectState(m_clipref, -1, indexes, disabled);
532 void EffectStackView2::slotUpdateCheckAllButton()
534 bool hasEnabled = false;
535 bool hasDisabled = false;
537 for (int i = 0; i < m_effects.count(); i++) {
538 if (!m_effects.at(i)->enabledButton->isChecked()) hasEnabled = true;
539 else hasDisabled = true;
542 m_ui.checkAll->blockSignals(true);
543 if (hasEnabled && hasDisabled)
544 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
546 m_ui.checkAll->setCheckState(Qt::Checked);
548 m_ui.checkAll->setCheckState(Qt::Unchecked);
549 m_ui.checkAll->blockSignals(false);
552 void EffectStackView2::deleteCurrentEffect()
554 for (int i = 0; i < m_effects.count(); i++) {
555 if (m_effects.at(i)->isActive()) {
556 slotDeleteEffect(m_effects.at(i)->effect());
562 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
564 m_effectMetaInfo.profile = profile;
565 m_effectMetaInfo.timecode = t;
568 void EffectStackView2::updateTimecodeFormat()
570 for (int i = 0; i< m_effects.count(); i++)
571 m_effects.at(i)->updateTimecodeFormat();
574 CollapsibleEffect *EffectStackView2::getEffectByIndex(int ix)
576 for (int i = 0; i< m_effects.count(); i++) {
577 if (m_effects.at(i)->effectIndex() == ix) {
578 return m_effects.at(i);
584 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
586 if (m_effectMetaInfo.trackMode)
587 emit updateEffect(NULL, m_trackindex, old, e, ix,false);
588 else if (m_clipref) {
589 emit updateEffect(m_clipref, -1, old, e, ix, false);
590 // Make sure the changed effect is currently displayed
591 slotSetCurrentEffect(ix);
593 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
596 void EffectStackView2::slotSetCurrentEffect(int ix)
598 if (m_clipref && ix != m_clipref->selectedEffectIndex()) {
599 m_clipref->setSelectedEffect(ix);
600 for (int i = 0; i < m_effects.count(); i++) {
601 if (m_effects.at(i)->effectIndex() == ix) {
602 if (m_effects.at(i)->isActive()) return;
603 m_effects.at(i)->setActive(true);
604 m_monitorSceneWanted = m_effects.at(i)->needsMonitorEffectScene();
605 slotCheckMonitorPosition(m_effectMetaInfo.monitor->render->seekFramePosition());
606 m_ui.labelComment->setText(i18n(m_effects.at(i)->effect().firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
607 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
609 else m_effects.at(i)->setActive(false);
614 void EffectStackView2::slotDeleteGroup(QDomDocument doc)
616 QDomNodeList effects = doc.elementsByTagName("effect");
617 ClipItem * clip = NULL;
619 if (m_effectMetaInfo.trackMode) {
627 for (int i = 0; i < effects.count(); i++)
628 emit removeEffect(clip, ix, effects.at(i).toElement());
631 void EffectStackView2::slotDeleteEffect(const QDomElement effect)
633 if (m_effectMetaInfo.trackMode)
634 emit removeEffect(NULL, m_trackindex, effect);
636 emit removeEffect(m_clipref, -1, effect);
639 void EffectStackView2::slotAddEffect(QDomElement effect)
641 emit addEffect(m_clipref, effect);
644 void EffectStackView2::slotMoveEffectUp(QList <int> indexes, bool up)
646 if (up && indexes.first() <= 1) return;
647 if (!up && indexes.last() >= m_currentEffectList.count()) return;
650 endPos = indexes.first() - 1;
653 endPos = indexes.last() + 1;
655 if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, indexes, endPos);
656 else emit changeEffectPosition(m_clipref, -1, indexes, endPos);
659 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&consumer, const QString&consumerParams, const QMap <QString, QString> &extraParams)
661 if (!m_clipref) return;
662 emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, consumer, consumerParams, extraParams);
665 void EffectStackView2::slotResetEffect(int ix)
667 QDomElement old = m_currentEffectList.itemFromIndex(ix);
669 QString effectId = old.attribute("id");
670 QMap<QString, EffectsList*> effectLists;
671 effectLists["audio"] = &MainWindow::audioEffects;
672 effectLists["video"] = &MainWindow::videoEffects;
673 effectLists["custom"] = &MainWindow::customEffects;
674 foreach(const QString &type, effectLists.keys()) {
675 EffectsList *list = effectLists[type];
676 dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
677 if (!dom.isNull()) break;
680 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
681 if (m_effectMetaInfo.trackMode) {
682 EffectsList::setParameter(dom, "in", QString::number(0));
683 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
685 info.track = m_trackInfo.type;
686 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
687 info.cropStart = GenTime(0);
688 info.startPos = GenTime(-1);
690 for (int i = 0; i < m_effects.count(); i++) {
691 if (m_effects.at(i)->effectIndex() == ix) {
692 m_effects.at(i)->updateWidget(info, dom, &m_effectMetaInfo);
696 emit updateEffect(NULL, m_trackindex, old, dom, ix,false);
698 m_clipref->initEffect(dom);
699 for (int i = 0; i < m_effects.count(); i++) {
700 if (m_effects.at(i)->effectIndex() == ix) {
701 m_effects.at(i)->updateWidget(m_clipref->info(), dom, &m_effectMetaInfo);
705 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
706 emit updateEffect(m_clipref, -1, old, dom, ix,false);
710 emit showComments(m_ui.buttonShowComments->isChecked());
711 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
714 void EffectStackView2::slotShowComments()
716 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
717 emit showComments(m_ui.buttonShowComments->isChecked());
720 void EffectStackView2::slotCreateRegion(int ix, KUrl url)
722 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
723 QDomElement neweffect = oldeffect.cloneNode().toElement();
724 QDomElement region = MainWindow::videoEffects.getEffectByTag("region", "region").cloneNode().toElement();
725 region.appendChild(region.ownerDocument().importNode(neweffect, true));
726 region.setAttribute("kdenlive_ix", ix);
727 EffectsList::setParameter(region, "resource", url.path());
728 if (m_effectMetaInfo.trackMode)
729 emit updateEffect(NULL, m_trackindex, oldeffect, region, ix,false);
730 else if (m_clipref) {
731 emit updateEffect(m_clipref, -1, oldeffect, region, ix, false);
732 // Make sure the changed effect is currently displayed
733 //slotSetCurrentEffect(ix);
735 // refresh effect stack
737 bool isSelected = false;
738 if (m_effectMetaInfo.trackMode) {
739 info.track = m_trackInfo.type;
740 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
741 info.cropStart = GenTime(0);
742 info.startPos = GenTime(-1);
745 else if (m_clipref) {
746 info = m_clipref->info();
748 CollapsibleEffect *current = getEffectByIndex(ix);
749 m_effects.removeAll(current);
750 current->setEnabled(false);
751 m_currentEffectList.removeAt(ix);
752 m_currentEffectList.insert(region);
753 current->deleteLater();
754 CollapsibleEffect *currentEffect = new CollapsibleEffect(region, m_currentEffectList.itemFromIndex(ix), info, &m_effectMetaInfo, ix == m_currentEffectList.count() - 1, m_ui.container->widget());
755 connectEffect(currentEffect);
757 if (m_effectMetaInfo.trackMode) {
758 isSelected = currentEffect->effectIndex() == 1;
760 else if (m_clipref) {
761 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
763 if (isSelected) currentEffect->setActive(true);
764 m_effects.append(currentEffect);
765 // TODO: region in group?
767 // group->addGroupEffect(currentEffect);
769 QVBoxLayout *vbox = static_cast <QVBoxLayout *> (m_ui.container->widget()->layout());
770 vbox->insertWidget(ix, currentEffect);
774 currentEffect->installEventFilter( this );
776 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
780 void EffectStackView2::slotCreateGroup(int ix)
782 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
783 QDomElement neweffect = oldeffect.cloneNode().toElement();
784 EffectInfo effectinfo;
785 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
786 effectinfo.groupIndex = m_groupIndex;
787 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
790 if (m_effectMetaInfo.trackMode) {
791 info.track = m_trackInfo.type;
792 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
793 info.cropStart = GenTime(0);
794 info.startPos = GenTime(-1);
796 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix, false);
798 emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix, false);
801 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
803 CollapsibleEffect *effectToMove = NULL;
804 for (int i = 0; i < m_effects.count(); i++) {
805 if (m_effects.at(i)->effectIndex() == ix) {
806 effectToMove = m_effects.at(i);
807 groupPos = l->indexOf(effectToMove);
808 l->removeWidget(effectToMove);
813 CollapsibleGroup *group = new CollapsibleGroup(m_groupIndex, ix == 1, ix == m_currentEffectList.count() - 2, effectinfo, m_ui.container->widget());
816 l->insertWidget(groupPos, group);
817 group->installEventFilter( this );
819 group->addGroupEffect(effectToMove);
822 void EffectStackView2::connectGroup(CollapsibleGroup *group)
824 connect(group, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
825 connect(group, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
826 connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
827 connect(group, SIGNAL(groupRenamed(CollapsibleGroup *)), this , SLOT(slotRenameGroup(CollapsibleGroup*)));
828 connect(group, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
829 connect(group, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
830 connect(group, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
833 void EffectStackView2::slotMoveEffect(QList <int> currentIndexes, int newIndex, int groupIndex, QString groupName)
835 if (currentIndexes.count() == 1) {
836 CollapsibleEffect *effectToMove = getEffectByIndex(currentIndexes.at(0));
837 if (effectToMove == NULL) return;
839 QDomElement oldeffect = effectToMove->effect();
840 QDomElement neweffect = oldeffect.cloneNode().toElement();
842 EffectInfo effectinfo;
843 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
844 effectinfo.groupIndex = groupIndex;
845 effectinfo.groupName = groupName;
846 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
848 if (oldeffect.attribute("kdenlive_info") != effectinfo.toString()) {
849 // effect's group info or collapsed state changed
851 if (m_effectMetaInfo.trackMode) {
852 info.track = m_trackInfo.type;
853 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
854 info.cropStart = GenTime(0);
855 info.startPos = GenTime(-1);
857 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->effectIndex(),false);
859 emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex(),false);
864 // Update effect index with new position
865 if (m_effectMetaInfo.trackMode) {
866 emit changeEffectPosition(NULL, m_trackindex, currentIndexes, newIndex);
869 emit changeEffectPosition(m_clipref, -1, currentIndexes, newIndex);
873 void EffectStackView2::slotUnGroup(CollapsibleGroup* group)
875 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
876 int ix = l->indexOf(group);
877 group->removeGroup(ix, l);
878 group->deleteLater();
881 void EffectStackView2::slotRenameGroup(CollapsibleGroup *group)
883 QList <CollapsibleEffect*> effects = group->effects();
884 for (int i = 0; i < effects.count(); i++) {
885 QDomElement origin = effects.at(i)->effect();
886 QDomElement changed = origin.cloneNode().toElement();
887 changed.setAttribute("kdenlive_info", effects.at(i)->infoString());
888 if (m_effectMetaInfo.trackMode) {
889 emit updateEffect(NULL, m_trackindex, origin, changed, effects.at(i)->effectIndex(),false);
891 emit updateEffect(m_clipref, -1, origin, changed, effects.at(i)->effectIndex(),false);
896 void EffectStackView2::dragEnterEvent(QDragEnterEvent *event)
898 if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
899 event->acceptProposedAction();
903 void EffectStackView2::processDroppedEffect(QDomElement e, QDropEvent *event)
905 int ix = e.attribute("kdenlive_ix").toInt();
906 if (e.tagName() == "effectgroup") {
907 // We are dropping a group, all effects in group should be moved
908 QDomNodeList effects = e.elementsByTagName("effect");
909 if (effects.count() == 0) {
914 info.fromString(effects.at(0).toElement().attribute("kdenlive_info"));
915 if (info.groupIndex < 0) {
916 kDebug()<<"// ADDING EFFECT!!!";
917 // Adding a new group effect to the stack
918 event->setDropAction(Qt::CopyAction);
923 // Moving group: delete all effects and re-add them
925 for (int i = 0; i < effects.count(); i++) {
926 QDomElement effect = effects.at(i).cloneNode().toElement();
927 indexes << effect.attribute("kdenlive_ix").toInt();
929 kDebug()<<"// Moving: "<<indexes<<" TO "<<m_currentEffectList.count();
930 slotMoveEffect(indexes, m_currentEffectList.count(), info.groupIndex, info.groupName);
933 // effect dropped from effects list, add it
934 e.setAttribute("kdenlive_ix", m_currentEffectList.count() + 1);
935 event->setDropAction(Qt::CopyAction);
941 // User is moving an effect
942 slotMoveEffect(QList<int> () << ix, m_currentEffectList.count() + 1, -1);
944 event->setDropAction(Qt::MoveAction);
948 void EffectStackView2::dropEvent(QDropEvent *event)
950 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
951 //event->acceptProposedAction();
953 doc.setContent(effects, true);
954 processDroppedEffect(doc.documentElement(), event);
957 void EffectStackView2::setKeyframes(const QString data, int maximum)
959 for (int i = 0; i < m_effects.count(); i++) {
960 if (m_effects.at(i)->isActive()) {
961 m_effects.at(i)->setKeyframes(data, maximum);
968 const QString EffectStackView2::getStyleSheet()
970 KColorScheme scheme(QApplication::palette().currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
971 QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
972 QColor hgh = KColorUtils::mix(QApplication::palette().window().color(), selected_bg, 0.2);
973 QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
974 QColor light_bg = scheme.shade(KColorScheme::LightShade);
975 QColor alt_bg = scheme.background(KColorScheme::NormalBackground).color();
980 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()));
982 // effect in group background
983 stylesheet.append(QString("QFrame#decoframesub {border-top:1px solid palette(light);} QFrame#decoframesub[active=\"true\"] {background: %1;}").arg(hgh.name()));
986 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;} "));
989 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);}"));
991 // group effect title bar
992 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);} "));
994 // draggable effect bar content
995 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()));
997 // draggable effect bar
998 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()));
1000 // spin box for draggable widget
1001 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()));
1003 // group editable labels
1004 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);} "));
1009 #include "effectstackview2.moc"