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 for (int i = 0; i < m_effects.count(); i++) {
101 m_effects.at(i)->setRange(inPoint, outPoint);
105 void EffectStackView2::slotClipItemSelected(ClipItem* c)
107 if (c && !c->isEnabled()) return;
108 if (c && c == m_clipref) {
111 if (m_clipref) disconnect(m_clipref, SIGNAL(updateRange()), this, SLOT(slotClipItemUpdate()));
114 connect(m_clipref, SIGNAL(updateRange()), this, SLOT(slotClipItemUpdate()));
115 QString cname = m_clipref->clipName();
116 if (cname.length() > 30) {
117 m_ui.checkAll->setToolTip(i18n("Effects for %1", cname));
119 m_ui.checkAll->setText(i18n("Effects for %1", cname) + "...");
121 m_ui.checkAll->setToolTip(QString());
122 m_ui.checkAll->setText(i18n("Effects for %1", cname));
124 m_ui.checkAll->setEnabled(true);
125 QString size = c->baseClip()->getProperty("frame_size");
126 double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
127 m_effectMetaInfo.frameSize = QPoint((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
130 if (m_clipref == NULL) {
131 //TODO: clear list, reset paramdesc and info
132 // If monitor scene is displayed, hide it
133 if (m_monitorSceneWanted) {
134 m_effectMetaInfo.monitor->slotShowEffectScene(false);
136 m_monitorSceneWanted = false;
141 m_effectMetaInfo.trackMode = false;
142 m_currentEffectList = m_clipref->effectList();
146 void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
149 m_effectMetaInfo.trackMode = true;
150 m_currentEffectList = info.effectsList;
153 m_ui.checkAll->setToolTip(QString());
154 m_ui.checkAll->setText(i18n("Effects for track %1", info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
155 m_ui.checkAll->setEnabled(true);
161 void EffectStackView2::setupListView()
164 m_monitorSceneWanted = false;
165 m_draggedEffect = NULL;
166 m_draggedGroup = NULL;
167 disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
170 QWidget *view = m_ui.container->takeWidget();
175 view = new QWidget(m_ui.container);
176 m_ui.container->setWidget(view);
178 QVBoxLayout *vbox1 = new QVBoxLayout(view);
179 vbox1->setContentsMargins(0, 0, 0, 0);
180 vbox1->setSpacing(0);
182 int effectsCount = m_currentEffectList.count();
184 // Make sure we always have one effect selected
185 if (!m_effectMetaInfo.trackMode) {
186 int selectedEffect = m_clipref->selectedEffectIndex();
187 if (selectedEffect < 1 && effectsCount > 0) m_clipref->setSelectedEffect(1);
188 else if (selectedEffect > effectsCount) m_clipref->setSelectedEffect(effectsCount);
191 for (int i = 0; i < effectsCount; i++) {
192 QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
194 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
198 CollapsibleGroup *group = NULL;
199 EffectInfo effectInfo;
200 effectInfo.fromString(d.attribute("kdenlive_info"));
201 if (effectInfo.groupIndex >= 0) {
202 // effect is in a group
203 for (int j = 0; j < vbox1->count(); j++) {
204 CollapsibleGroup *eff = static_cast<CollapsibleGroup *>(vbox1->itemAt(j)->widget());
205 if (eff->isGroup() && eff->groupIndex() == effectInfo.groupIndex) {
212 group = new CollapsibleGroup(effectInfo.groupIndex, i == 0, i == effectsCount - 1, effectInfo, m_ui.container->widget());
214 vbox1->addWidget(group);
215 group->installEventFilter( this );
217 if (effectInfo.groupIndex >= m_groupIndex) m_groupIndex = effectInfo.groupIndex + 1;
221 doc.appendChild(doc.importNode(d, true));
222 kDebug() << "IMPORTED STK: " << doc.toString();*/
225 bool isSelected = false;
226 if (m_effectMetaInfo.trackMode) {
227 info.track = m_trackInfo.type;
228 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
229 info.cropStart = GenTime(0);
230 info.startPos = GenTime(-1);
234 info = m_clipref->info();
237 CollapsibleEffect *currentEffect = new CollapsibleEffect(d, m_currentEffectList.at(i), info, &m_effectMetaInfo, i == effectsCount - 1, view);
238 if (m_effectMetaInfo.trackMode) {
239 isSelected = currentEffect->effectIndex() == 1;
242 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
245 currentEffect->setActive(true);
246 if (currentEffect->needsMonitorEffectScene()) m_monitorSceneWanted = true;
248 m_effects.append(currentEffect);
250 group->addGroupEffect(currentEffect);
252 vbox1->addWidget(currentEffect);
254 connectEffect(currentEffect);
257 if (m_currentEffectList.isEmpty()) {
258 m_ui.labelComment->setHidden(true);
261 // Adjust group effects (up / down buttons)
262 QList<CollapsibleGroup *> allGroups = m_ui.container->widget()->findChildren<CollapsibleGroup *>();
263 for (int i = 0; i < allGroups.count(); i++) {
264 allGroups.at(i)->adjustEffects();
266 connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
269 vbox1->addStretch(10);
270 slotUpdateCheckAllButton();
271 if (!m_monitorSceneWanted) {
272 // monitor scene not wanted
273 m_effectMetaInfo.monitor->slotShowEffectScene(false);
276 // Wait a little bit for the new layout to be ready, then check if we have a scrollbar
277 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
280 void EffectStackView2::connectEffect(CollapsibleEffect *currentEffect)
283 currentEffect->installEventFilter( this );
284 connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
285 connect(currentEffect, SIGNAL(startFilterJob(QString,QString,QString,QString,const QMap <QString, QString>)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,const QMap <QString, QString>)));
286 connect(currentEffect, SIGNAL(deleteEffect(const QDomElement)), this , SLOT(slotDeleteEffect(const QDomElement)));
287 connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
288 connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
289 connect(currentEffect, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
290 connect(currentEffect, SIGNAL(effectStateChanged(bool,int,bool)), this, SLOT(slotUpdateEffectState(bool,int,bool)));
291 connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
292 connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
293 connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
294 connect(currentEffect, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
295 connect(currentEffect, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
296 connect(currentEffect, SIGNAL(createRegion(int,KUrl)), this, SLOT(slotCreateRegion(int,KUrl)));
297 connect(currentEffect, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
298 connect(currentEffect, SIGNAL(importClipKeyframes()), this, SIGNAL(importClipKeyframes()));
301 void EffectStackView2::slotCheckWheelEventFilter()
303 // If the effect stack widget has no scrollbar, we will not filter the
304 // mouse wheel events, so that user can easily adjust effect params
305 bool filterWheelEvent = false;
306 if (m_ui.container->verticalScrollBar() && m_ui.container->verticalScrollBar()->isVisible()) {
307 // widget has scroll bar,
308 filterWheelEvent = true;
310 for (int i = 0; i < m_effects.count(); i++) {
311 m_effects.at(i)->filterWheelEvent = filterWheelEvent;
315 void EffectStackView2::resizeEvent ( QResizeEvent * event )
317 slotCheckWheelEventFilter();
318 QWidget::resizeEvent(event);
321 bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
323 // Check if user clicked in an effect's top bar to start dragging it
324 if (e->type() == QEvent::MouseButtonPress) {
325 m_draggedEffect = qobject_cast<CollapsibleEffect*>(o);
326 if (m_draggedEffect) {
327 QMouseEvent *me = static_cast<QMouseEvent *>(e);
328 if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse())) {
329 m_clickPoint = me->globalPos();
332 m_clickPoint = QPoint();
333 m_draggedEffect = NULL;
338 m_draggedGroup = qobject_cast<CollapsibleGroup*>(o);
339 if (m_draggedGroup) {
340 QMouseEvent *me = static_cast<QMouseEvent *>(e);
341 if (me->button() == Qt::LeftButton && (m_draggedGroup->frame->underMouse() || m_draggedGroup->title()->underMouse()))
342 m_clickPoint = me->globalPos();
344 m_clickPoint = QPoint();
345 m_draggedGroup = NULL;
351 /*if (e->type() == QEvent::MouseMove) {
352 if (qobject_cast<CollapsibleEffect*>(o)) {
353 QMouseEvent *me = static_cast<QMouseEvent *>(e);
354 if (me->buttons() != Qt::LeftButton) {
364 return QWidget::eventFilter(o, e);
367 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
369 if (m_draggedEffect || m_draggedGroup) {
370 if ((event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
376 void EffectStackView2::mouseReleaseEvent(QMouseEvent * event)
378 m_draggedEffect = NULL;
379 m_draggedGroup = NULL;
380 QWidget::mouseReleaseEvent(event);
383 void EffectStackView2::startDrag()
385 // The data to be transferred by the drag and drop operation is contained in a QMimeData object
388 if (m_draggedEffect) {
389 QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
390 if (m_effectMetaInfo.trackMode) {
391 // Keep clip crop start in case we want to paste effect
392 effect.setAttribute("clipstart", 0);
395 // Keep clip crop start in case we want to paste effect
396 effect.setAttribute("clipstart", m_clipref->cropStart().frames(KdenliveSettings::project_fps()));
398 doc.appendChild(doc.importNode(effect, true));
399 pixmap = QPixmap::grabWidget(m_draggedEffect->title);
401 else if (m_draggedGroup) {
402 doc = m_draggedGroup->effectsData();
403 if (m_effectMetaInfo.trackMode) {
404 doc.documentElement().setAttribute("clipstart", 0);
407 doc.documentElement().setAttribute("clipstart", m_clipref->cropStart().frames(KdenliveSettings::project_fps()));
409 pixmap = QPixmap::grabWidget(m_draggedGroup->title());
412 QDrag *drag = new QDrag(this);
413 drag->setPixmap(pixmap);
414 QMimeData *mime = new QMimeData;
416 data.append(doc.toString().toUtf8());
417 mime->setData("kdenlive/effectslist", data);
419 // Assign ownership of the QMimeData object to the QDrag object.
420 drag->setMimeData(mime);
421 // Start the drag and drop operation
422 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
426 void EffectStackView2::slotUpdateEffectState(bool disable, int index, bool needsMonitorEffectScene)
428 if (m_monitorSceneWanted && disable) {
429 m_effectMetaInfo.monitor->slotShowEffectScene(false);
430 m_monitorSceneWanted = false;
432 else if (!disable && !m_monitorSceneWanted && needsMonitorEffectScene) {
433 m_effectMetaInfo.monitor->slotShowEffectScene(true);
434 m_monitorSceneWanted = true;
436 if (m_effectMetaInfo.trackMode)
437 emit changeEffectState(NULL, m_trackindex, QList <int>() << index, disable);
439 emit changeEffectState(m_clipref, -1, QList <int>() <<index, disable);
440 slotUpdateCheckAllButton();
444 void EffectStackView2::raiseWindow(QWidget* dock)
446 if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
451 void EffectStackView2::slotSeekTimeline(int pos)
453 if (m_effectMetaInfo.trackMode) {
454 emit seekTimeline(pos);
455 } else if (m_clipref) {
456 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
461 /*void EffectStackView2::slotRegionChanged()
463 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
466 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
468 if (m_monitorSceneWanted) {
469 if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
470 if (!m_effectMetaInfo.monitor->effectSceneDisplayed()) {
471 m_effectMetaInfo.monitor->slotShowEffectScene(true);
474 m_effectMetaInfo.monitor->slotShowEffectScene(false);
478 m_effectMetaInfo.monitor->slotShowEffectScene(false);
482 int EffectStackView2::isTrackMode(bool *ok) const
484 *ok = m_effectMetaInfo.trackMode;
488 void EffectStackView2::clear()
491 m_monitorSceneWanted = false;
492 QWidget *view = m_ui.container->takeWidget();
496 m_ui.checkAll->setToolTip(QString());
497 m_ui.checkAll->setText(QString());
498 m_ui.checkAll->setEnabled(false);
499 m_ui.labelComment->setText(QString());
503 void EffectStackView2::slotCheckAll(int state)
505 if (state == Qt::PartiallyChecked) {
507 m_ui.checkAll->blockSignals(true);
508 m_ui.checkAll->setCheckState(Qt::Checked);
509 m_ui.checkAll->blockSignals(false);
512 bool disabled = state == Qt::Unchecked;
513 // Disable all effects
515 for (int i = 0; i < m_effects.count(); i++) {
516 m_effects.at(i)->slotDisable(disabled, false);
517 indexes << m_effects.at(i)->effectIndex();
519 // Take care of groups
520 QList<CollapsibleGroup *> allGroups = m_ui.container->widget()->findChildren<CollapsibleGroup *>();
521 for (int i = 0; i < allGroups.count(); i++) {
522 allGroups.at(i)->slotEnable(disabled, false);
525 if (m_effectMetaInfo.trackMode)
526 emit changeEffectState(NULL, m_trackindex, indexes, disabled);
528 emit changeEffectState(m_clipref, -1, indexes, disabled);
531 void EffectStackView2::slotUpdateCheckAllButton()
533 bool hasEnabled = false;
534 bool hasDisabled = false;
536 for (int i = 0; i < m_effects.count(); i++) {
537 if (!m_effects.at(i)->enabledButton->isChecked()) hasEnabled = true;
538 else hasDisabled = true;
541 m_ui.checkAll->blockSignals(true);
542 if (hasEnabled && hasDisabled)
543 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
545 m_ui.checkAll->setCheckState(Qt::Checked);
547 m_ui.checkAll->setCheckState(Qt::Unchecked);
548 m_ui.checkAll->blockSignals(false);
551 void EffectStackView2::deleteCurrentEffect()
553 for (int i = 0; i < m_effects.count(); i++) {
554 if (m_effects.at(i)->isActive()) {
555 slotDeleteEffect(m_effects.at(i)->effect());
561 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
563 m_effectMetaInfo.profile = profile;
564 m_effectMetaInfo.timecode = t;
567 void EffectStackView2::updateTimecodeFormat()
569 for (int i = 0; i< m_effects.count(); i++)
570 m_effects.at(i)->updateTimecodeFormat();
573 CollapsibleEffect *EffectStackView2::getEffectByIndex(int ix)
575 for (int i = 0; i< m_effects.count(); i++) {
576 if (m_effects.at(i)->effectIndex() == ix) {
577 return m_effects.at(i);
583 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
585 if (m_effectMetaInfo.trackMode)
586 emit updateEffect(NULL, m_trackindex, old, e, ix,false);
587 else if (m_clipref) {
588 emit updateEffect(m_clipref, -1, old, e, ix, false);
589 // Make sure the changed effect is currently displayed
590 slotSetCurrentEffect(ix);
592 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
595 void EffectStackView2::slotSetCurrentEffect(int ix)
597 if (m_clipref && ix != m_clipref->selectedEffectIndex()) {
598 m_clipref->setSelectedEffect(ix);
599 for (int i = 0; i < m_effects.count(); i++) {
600 if (m_effects.at(i)->effectIndex() == ix) {
601 if (m_effects.at(i)->isActive()) return;
602 m_effects.at(i)->setActive(true);
603 m_monitorSceneWanted = m_effects.at(i)->needsMonitorEffectScene();
604 slotCheckMonitorPosition(m_effectMetaInfo.monitor->render->seekFramePosition());
605 m_ui.labelComment->setText(i18n(m_effects.at(i)->effect().firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
606 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
608 else m_effects.at(i)->setActive(false);
613 void EffectStackView2::slotDeleteGroup(QDomDocument doc)
615 QDomNodeList effects = doc.elementsByTagName("effect");
616 ClipItem * clip = NULL;
618 if (m_effectMetaInfo.trackMode) {
626 for (int i = 0; i < effects.count(); i++)
627 emit removeEffect(clip, ix, effects.at(i).toElement());
630 void EffectStackView2::slotDeleteEffect(const QDomElement effect)
632 if (m_effectMetaInfo.trackMode)
633 emit removeEffect(NULL, m_trackindex, effect);
635 emit removeEffect(m_clipref, -1, effect);
638 void EffectStackView2::slotAddEffect(QDomElement effect)
640 emit addEffect(m_clipref, effect);
643 void EffectStackView2::slotMoveEffectUp(QList <int> indexes, bool up)
645 if (up && indexes.first() <= 1) return;
646 if (!up && indexes.last() >= m_currentEffectList.count()) return;
649 endPos = indexes.first() - 1;
652 endPos = indexes.last() + 1;
654 if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, indexes, endPos);
655 else emit changeEffectPosition(m_clipref, -1, indexes, endPos);
658 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&consumer, const QString&consumerParams, const QMap <QString, QString> &extraParams)
660 if (!m_clipref) return;
661 emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, consumer, consumerParams, extraParams);
664 void EffectStackView2::slotResetEffect(int ix)
666 QDomElement old = m_currentEffectList.itemFromIndex(ix);
668 QString effectId = old.attribute("id");
669 QMap<QString, EffectsList*> effectLists;
670 effectLists["audio"] = &MainWindow::audioEffects;
671 effectLists["video"] = &MainWindow::videoEffects;
672 effectLists["custom"] = &MainWindow::customEffects;
673 foreach(const QString &type, effectLists.keys()) {
674 EffectsList *list = effectLists[type];
675 dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
676 if (!dom.isNull()) break;
679 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
680 if (m_effectMetaInfo.trackMode) {
681 EffectsList::setParameter(dom, "in", QString::number(0));
682 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
684 info.track = m_trackInfo.type;
685 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
686 info.cropStart = GenTime(0);
687 info.startPos = GenTime(-1);
689 for (int i = 0; i < m_effects.count(); i++) {
690 if (m_effects.at(i)->effectIndex() == ix) {
691 m_effects.at(i)->updateWidget(info, dom, &m_effectMetaInfo);
695 emit updateEffect(NULL, m_trackindex, old, dom, ix,false);
697 m_clipref->initEffect(dom);
698 for (int i = 0; i < m_effects.count(); i++) {
699 if (m_effects.at(i)->effectIndex() == ix) {
700 m_effects.at(i)->updateWidget(m_clipref->info(), dom, &m_effectMetaInfo);
704 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
705 emit updateEffect(m_clipref, -1, old, dom, ix,false);
709 emit showComments(m_ui.buttonShowComments->isChecked());
710 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
713 void EffectStackView2::slotShowComments()
715 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
716 emit showComments(m_ui.buttonShowComments->isChecked());
719 void EffectStackView2::slotCreateRegion(int ix, KUrl url)
721 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
722 QDomElement neweffect = oldeffect.cloneNode().toElement();
723 QDomElement region = MainWindow::videoEffects.getEffectByTag("region", "region").cloneNode().toElement();
724 region.appendChild(region.ownerDocument().importNode(neweffect, true));
725 region.setAttribute("kdenlive_ix", ix);
726 EffectsList::setParameter(region, "resource", url.path());
727 if (m_effectMetaInfo.trackMode)
728 emit updateEffect(NULL, m_trackindex, oldeffect, region, ix,false);
729 else if (m_clipref) {
730 emit updateEffect(m_clipref, -1, oldeffect, region, ix, false);
731 // Make sure the changed effect is currently displayed
732 //slotSetCurrentEffect(ix);
734 // refresh effect stack
736 bool isSelected = false;
737 if (m_effectMetaInfo.trackMode) {
738 info.track = m_trackInfo.type;
739 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
740 info.cropStart = GenTime(0);
741 info.startPos = GenTime(-1);
744 else if (m_clipref) {
745 info = m_clipref->info();
747 CollapsibleEffect *current = getEffectByIndex(ix);
748 m_effects.removeAll(current);
749 current->setEnabled(false);
750 m_currentEffectList.removeAt(ix);
751 m_currentEffectList.insert(region);
752 current->deleteLater();
753 CollapsibleEffect *currentEffect = new CollapsibleEffect(region, m_currentEffectList.itemFromIndex(ix), info, &m_effectMetaInfo, ix == m_currentEffectList.count() - 1, m_ui.container->widget());
754 connectEffect(currentEffect);
756 if (m_effectMetaInfo.trackMode) {
757 isSelected = currentEffect->effectIndex() == 1;
759 else if (m_clipref) {
760 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
762 if (isSelected) currentEffect->setActive(true);
763 m_effects.append(currentEffect);
764 // TODO: region in group?
766 // group->addGroupEffect(currentEffect);
768 QVBoxLayout *vbox = static_cast <QVBoxLayout *> (m_ui.container->widget()->layout());
769 vbox->insertWidget(ix, currentEffect);
773 currentEffect->installEventFilter( this );
775 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
779 void EffectStackView2::slotCreateGroup(int ix)
781 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
782 QDomElement neweffect = oldeffect.cloneNode().toElement();
783 EffectInfo effectinfo;
784 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
785 effectinfo.groupIndex = m_groupIndex;
786 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
789 if (m_effectMetaInfo.trackMode) {
790 info.track = m_trackInfo.type;
791 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
792 info.cropStart = GenTime(0);
793 info.startPos = GenTime(-1);
795 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix, false);
797 emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix, false);
800 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
802 CollapsibleEffect *effectToMove = NULL;
803 for (int i = 0; i < m_effects.count(); i++) {
804 if (m_effects.at(i)->effectIndex() == ix) {
805 effectToMove = m_effects.at(i);
806 groupPos = l->indexOf(effectToMove);
807 l->removeWidget(effectToMove);
812 CollapsibleGroup *group = new CollapsibleGroup(m_groupIndex, ix == 1, ix == m_currentEffectList.count() - 2, effectinfo, m_ui.container->widget());
815 l->insertWidget(groupPos, group);
816 group->installEventFilter( this );
818 group->addGroupEffect(effectToMove);
821 void EffectStackView2::connectGroup(CollapsibleGroup *group)
823 connect(group, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
824 connect(group, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
825 connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
826 connect(group, SIGNAL(groupRenamed(CollapsibleGroup *)), this , SLOT(slotRenameGroup(CollapsibleGroup*)));
827 connect(group, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
828 connect(group, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
829 connect(group, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
832 void EffectStackView2::slotMoveEffect(QList <int> currentIndexes, int newIndex, int groupIndex, QString groupName)
834 if (currentIndexes.count() == 1) {
835 CollapsibleEffect *effectToMove = getEffectByIndex(currentIndexes.at(0));
836 if (effectToMove == NULL) return;
838 QDomElement oldeffect = effectToMove->effect();
839 QDomElement neweffect = oldeffect.cloneNode().toElement();
841 EffectInfo effectinfo;
842 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
843 effectinfo.groupIndex = groupIndex;
844 effectinfo.groupName = groupName;
845 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
847 if (oldeffect.attribute("kdenlive_info") != effectinfo.toString()) {
848 // effect's group info or collapsed state changed
850 if (m_effectMetaInfo.trackMode) {
851 info.track = m_trackInfo.type;
852 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
853 info.cropStart = GenTime(0);
854 info.startPos = GenTime(-1);
856 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->effectIndex(),false);
858 emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex(),false);
863 // Update effect index with new position
864 if (m_effectMetaInfo.trackMode) {
865 emit changeEffectPosition(NULL, m_trackindex, currentIndexes, newIndex);
868 emit changeEffectPosition(m_clipref, -1, currentIndexes, newIndex);
872 void EffectStackView2::slotUnGroup(CollapsibleGroup* group)
874 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
875 int ix = l->indexOf(group);
876 group->removeGroup(ix, l);
877 group->deleteLater();
880 void EffectStackView2::slotRenameGroup(CollapsibleGroup *group)
882 QList <CollapsibleEffect*> effects = group->effects();
883 for (int i = 0; i < effects.count(); i++) {
884 QDomElement origin = effects.at(i)->effect();
885 QDomElement changed = origin.cloneNode().toElement();
886 changed.setAttribute("kdenlive_info", effects.at(i)->infoString());
887 if (m_effectMetaInfo.trackMode) {
888 emit updateEffect(NULL, m_trackindex, origin, changed, effects.at(i)->effectIndex(),false);
890 emit updateEffect(m_clipref, -1, origin, changed, effects.at(i)->effectIndex(),false);
895 void EffectStackView2::dragEnterEvent(QDragEnterEvent *event)
897 if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
898 event->acceptProposedAction();
902 void EffectStackView2::processDroppedEffect(QDomElement e, QDropEvent *event)
904 int ix = e.attribute("kdenlive_ix").toInt();
905 if (e.tagName() == "effectgroup") {
906 // We are dropping a group, all effects in group should be moved
907 QDomNodeList effects = e.elementsByTagName("effect");
908 if (effects.count() == 0) {
913 info.fromString(effects.at(0).toElement().attribute("kdenlive_info"));
914 if (info.groupIndex < 0) {
915 kDebug()<<"// ADDING EFFECT!!!";
916 // Adding a new group effect to the stack
917 event->setDropAction(Qt::CopyAction);
922 // Moving group: delete all effects and re-add them
924 for (int i = 0; i < effects.count(); i++) {
925 QDomElement effect = effects.at(i).cloneNode().toElement();
926 indexes << effect.attribute("kdenlive_ix").toInt();
928 kDebug()<<"// Moving: "<<indexes<<" TO "<<m_currentEffectList.count();
929 slotMoveEffect(indexes, m_currentEffectList.count(), info.groupIndex, info.groupName);
932 // effect dropped from effects list, add it
933 e.setAttribute("kdenlive_ix", m_currentEffectList.count() + 1);
934 event->setDropAction(Qt::CopyAction);
940 // User is moving an effect
941 slotMoveEffect(QList<int> () << ix, m_currentEffectList.count() + 1, -1);
943 event->setDropAction(Qt::MoveAction);
947 void EffectStackView2::dropEvent(QDropEvent *event)
949 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
950 //event->acceptProposedAction();
952 doc.setContent(effects, true);
953 processDroppedEffect(doc.documentElement(), event);
956 void EffectStackView2::setKeyframes(const QString data, int maximum)
958 for (int i = 0; i < m_effects.count(); i++) {
959 if (m_effects.at(i)->isActive()) {
960 m_effects.at(i)->setKeyframes(data, maximum);
967 const QString EffectStackView2::getStyleSheet()
969 KColorScheme scheme(QApplication::palette().currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
970 QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
971 QColor hgh = KColorUtils::mix(QApplication::palette().window().color(), selected_bg, 0.2);
972 QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
973 QColor light_bg = scheme.shade(KColorScheme::LightShade);
974 QColor alt_bg = scheme.background(KColorScheme::NormalBackground).color();
979 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()));
981 // effect in group background
982 stylesheet.append(QString("QFrame#decoframesub {border-top:1px solid palette(light);} QFrame#decoframesub[active=\"true\"] {background: %1;}").arg(hgh.name()));
985 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;} "));
988 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);}"));
990 // group effect title bar
991 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);} "));
993 // draggable effect bar content
994 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()));
996 // draggable effect bar
997 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()));
999 // spin box for draggable widget
1000 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()));
1002 // group editable labels
1003 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);} "));
1008 #include "effectstackview2.moc"