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", cname));
108 m_ui.checkAll->setText(i18n("Effects for %1", cname) + "...");
110 m_ui.checkAll->setToolTip(QString());
111 m_ui.checkAll->setText(i18n("Effects for %1", 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
121 // If monitor scene is displayed, hide it
122 if (m_monitorSceneWanted) {
123 m_effectMetaInfo.monitor->slotShowEffectScene(false);
125 m_monitorSceneWanted = false;
130 m_effectMetaInfo.trackMode = false;
131 m_currentEffectList = m_clipref->effectList();
135 void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
138 m_effectMetaInfo.trackMode = true;
139 m_currentEffectList = info.effectsList;
142 m_ui.checkAll->setToolTip(QString());
143 m_ui.checkAll->setText(i18n("Effects for track %1", info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
144 m_ui.checkAll->setEnabled(true);
150 void EffectStackView2::setupListView()
153 m_monitorSceneWanted = false;
154 m_draggedEffect = NULL;
155 m_draggedGroup = NULL;
156 disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
159 QWidget *view = m_ui.container->takeWidget();
164 view = new QWidget(m_ui.container);
165 m_ui.container->setWidget(view);
167 QVBoxLayout *vbox1 = new QVBoxLayout(view);
168 vbox1->setContentsMargins(0, 0, 0, 0);
169 vbox1->setSpacing(0);
171 int effectsCount = m_currentEffectList.count();
173 // Make sure we always have one effect selected
174 if (!m_effectMetaInfo.trackMode) {
175 int selectedEffect = m_clipref->selectedEffectIndex();
176 if (selectedEffect < 1 && effectsCount > 0) m_clipref->setSelectedEffect(1);
177 else if (selectedEffect > effectsCount) m_clipref->setSelectedEffect(effectsCount);
180 for (int i = 0; i < effectsCount; i++) {
181 QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
183 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
187 CollapsibleGroup *group = NULL;
188 EffectInfo effectInfo;
189 effectInfo.fromString(d.attribute("kdenlive_info"));
190 if (effectInfo.groupIndex >= 0) {
191 // effect is in a group
192 for (int j = 0; j < vbox1->count(); j++) {
193 CollapsibleGroup *eff = static_cast<CollapsibleGroup *>(vbox1->itemAt(j)->widget());
194 if (eff->isGroup() && eff->groupIndex() == effectInfo.groupIndex) {
201 group = new CollapsibleGroup(effectInfo.groupIndex, i == 0, i == effectsCount - 1, effectInfo, m_ui.container->widget());
203 vbox1->addWidget(group);
204 group->installEventFilter( this );
206 if (effectInfo.groupIndex >= m_groupIndex) m_groupIndex = effectInfo.groupIndex + 1;
210 doc.appendChild(doc.importNode(d, true));
211 kDebug() << "IMPORTED STK: " << doc.toString();*/
214 bool isSelected = false;
215 if (m_effectMetaInfo.trackMode) {
216 info.track = m_trackInfo.type;
217 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
218 info.cropStart = GenTime(0);
219 info.startPos = GenTime(-1);
223 info = m_clipref->info();
226 CollapsibleEffect *currentEffect = new CollapsibleEffect(d, m_currentEffectList.at(i), info, &m_effectMetaInfo, i == effectsCount - 1, view);
227 if (m_effectMetaInfo.trackMode) {
228 isSelected = currentEffect->effectIndex() == 1;
231 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
234 currentEffect->setActive(true);
235 if (currentEffect->needsMonitorEffectScene()) m_monitorSceneWanted = true;
237 m_effects.append(currentEffect);
239 group->addGroupEffect(currentEffect);
241 vbox1->addWidget(currentEffect);
243 connectEffect(currentEffect);
246 if (m_currentEffectList.isEmpty()) {
247 m_ui.labelComment->setHidden(true);
250 // Adjust group effects (up / down buttons)
251 QList<CollapsibleGroup *> allGroups = m_ui.container->widget()->findChildren<CollapsibleGroup *>();
252 for (int i = 0; i < allGroups.count(); i++) {
253 allGroups.at(i)->adjustEffects();
255 connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
258 vbox1->addStretch(10);
259 slotUpdateCheckAllButton();
260 if (!m_monitorSceneWanted) {
261 // monitor scene not wanted
262 m_effectMetaInfo.monitor->slotShowEffectScene(false);
265 // Wait a little bit for the new layout to be ready, then check if we have a scrollbar
266 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
269 void EffectStackView2::connectEffect(CollapsibleEffect *currentEffect)
272 currentEffect->installEventFilter( this );
273 connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
274 connect(currentEffect, SIGNAL(startFilterJob(QString,QString,QString,QString,const QMap <QString, QString>)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,const QMap <QString, QString>)));
275 connect(currentEffect, SIGNAL(deleteEffect(const QDomElement)), this , SLOT(slotDeleteEffect(const QDomElement)));
276 connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
277 connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
278 connect(currentEffect, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
279 connect(currentEffect, SIGNAL(effectStateChanged(bool,int,bool)), this, SLOT(slotUpdateEffectState(bool,int,bool)));
280 connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
281 connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
282 connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
283 connect(currentEffect, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
284 connect(currentEffect, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
285 connect(currentEffect, SIGNAL(createRegion(int,KUrl)), this, SLOT(slotCreateRegion(int,KUrl)));
286 connect(currentEffect, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
287 connect(currentEffect, SIGNAL(importClipKeyframes()), this, SIGNAL(importClipKeyframes()));
290 void EffectStackView2::slotCheckWheelEventFilter()
292 // If the effect stack widget has no scrollbar, we will not filter the
293 // mouse wheel events, so that user can easily adjust effect params
294 bool filterWheelEvent = false;
295 if (m_ui.container->verticalScrollBar() && m_ui.container->verticalScrollBar()->isVisible()) {
296 // widget has scroll bar,
297 filterWheelEvent = true;
299 for (int i = 0; i < m_effects.count(); i++) {
300 m_effects.at(i)->filterWheelEvent = filterWheelEvent;
304 void EffectStackView2::resizeEvent ( QResizeEvent * event )
306 slotCheckWheelEventFilter();
307 QWidget::resizeEvent(event);
310 bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
312 // Check if user clicked in an effect's top bar to start dragging it
313 if (e->type() == QEvent::MouseButtonPress) {
314 m_draggedEffect = qobject_cast<CollapsibleEffect*>(o);
315 if (m_draggedEffect) {
316 QMouseEvent *me = static_cast<QMouseEvent *>(e);
317 if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse())) {
318 m_clickPoint = me->globalPos();
321 m_clickPoint = QPoint();
322 m_draggedEffect = NULL;
327 m_draggedGroup = qobject_cast<CollapsibleGroup*>(o);
328 if (m_draggedGroup) {
329 QMouseEvent *me = static_cast<QMouseEvent *>(e);
330 if (me->button() == Qt::LeftButton && (m_draggedGroup->frame->underMouse() || m_draggedGroup->title()->underMouse()))
331 m_clickPoint = me->globalPos();
333 m_clickPoint = QPoint();
334 m_draggedGroup = NULL;
340 /*if (e->type() == QEvent::MouseMove) {
341 if (qobject_cast<CollapsibleEffect*>(o)) {
342 QMouseEvent *me = static_cast<QMouseEvent *>(e);
343 if (me->buttons() != Qt::LeftButton) {
353 return QWidget::eventFilter(o, e);
356 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
358 if (m_draggedEffect || m_draggedGroup) {
359 if ((event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
365 void EffectStackView2::mouseReleaseEvent(QMouseEvent * event)
367 m_draggedEffect = NULL;
368 m_draggedGroup = NULL;
369 QWidget::mouseReleaseEvent(event);
372 void EffectStackView2::startDrag()
374 // The data to be transferred by the drag and drop operation is contained in a QMimeData object
377 if (m_draggedEffect) {
378 QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
379 if (m_effectMetaInfo.trackMode) {
380 // Keep clip crop start in case we want to paste effect
381 effect.setAttribute("clipstart", 0);
384 // Keep clip crop start in case we want to paste effect
385 effect.setAttribute("clipstart", m_clipref->cropStart().frames(KdenliveSettings::project_fps()));
387 doc.appendChild(doc.importNode(effect, true));
388 pixmap = QPixmap::grabWidget(m_draggedEffect->title);
390 else if (m_draggedGroup) {
391 doc = m_draggedGroup->effectsData();
392 if (m_effectMetaInfo.trackMode) {
393 doc.documentElement().setAttribute("clipstart", 0);
396 doc.documentElement().setAttribute("clipstart", m_clipref->cropStart().frames(KdenliveSettings::project_fps()));
398 pixmap = QPixmap::grabWidget(m_draggedGroup->title());
401 QDrag *drag = new QDrag(this);
402 drag->setPixmap(pixmap);
403 QMimeData *mime = new QMimeData;
405 data.append(doc.toString().toUtf8());
406 mime->setData("kdenlive/effectslist", data);
408 // Assign ownership of the QMimeData object to the QDrag object.
409 drag->setMimeData(mime);
410 // Start the drag and drop operation
411 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
415 void EffectStackView2::slotUpdateEffectState(bool disable, int index, bool needsMonitorEffectScene)
417 if (m_monitorSceneWanted && disable) {
418 m_effectMetaInfo.monitor->slotShowEffectScene(false);
419 m_monitorSceneWanted = false;
421 else if (!disable && !m_monitorSceneWanted && needsMonitorEffectScene) {
422 m_effectMetaInfo.monitor->slotShowEffectScene(true);
423 m_monitorSceneWanted = true;
425 if (m_effectMetaInfo.trackMode)
426 emit changeEffectState(NULL, m_trackindex, QList <int>() << index, disable);
428 emit changeEffectState(m_clipref, -1, QList <int>() <<index, disable);
429 slotUpdateCheckAllButton();
433 void EffectStackView2::raiseWindow(QWidget* dock)
435 if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
440 void EffectStackView2::slotSeekTimeline(int pos)
442 if (m_effectMetaInfo.trackMode) {
443 emit seekTimeline(pos);
444 } else if (m_clipref) {
445 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
450 /*void EffectStackView2::slotRegionChanged()
452 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
455 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
457 if (m_monitorSceneWanted) {
458 if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
459 if (!m_effectMetaInfo.monitor->effectSceneDisplayed()) {
460 m_effectMetaInfo.monitor->slotShowEffectScene(true);
463 m_effectMetaInfo.monitor->slotShowEffectScene(false);
467 m_effectMetaInfo.monitor->slotShowEffectScene(false);
471 int EffectStackView2::isTrackMode(bool *ok) const
473 *ok = m_effectMetaInfo.trackMode;
477 void EffectStackView2::clear()
480 m_monitorSceneWanted = false;
481 QWidget *view = m_ui.container->takeWidget();
485 m_ui.checkAll->setToolTip(QString());
486 m_ui.checkAll->setText(QString());
487 m_ui.checkAll->setEnabled(false);
488 m_ui.labelComment->setText(QString());
492 void EffectStackView2::slotCheckAll(int state)
494 if (state == Qt::PartiallyChecked) {
496 m_ui.checkAll->blockSignals(true);
497 m_ui.checkAll->setCheckState(Qt::Checked);
498 m_ui.checkAll->blockSignals(false);
501 bool disabled = state == Qt::Unchecked;
502 // Disable all effects
504 for (int i = 0; i < m_effects.count(); i++) {
505 m_effects.at(i)->slotDisable(disabled, false);
506 indexes << m_effects.at(i)->effectIndex();
508 // Take care of groups
509 QList<CollapsibleGroup *> allGroups = m_ui.container->widget()->findChildren<CollapsibleGroup *>();
510 for (int i = 0; i < allGroups.count(); i++) {
511 allGroups.at(i)->slotEnable(disabled, false);
514 if (m_effectMetaInfo.trackMode)
515 emit changeEffectState(NULL, m_trackindex, indexes, disabled);
517 emit changeEffectState(m_clipref, -1, indexes, disabled);
520 void EffectStackView2::slotUpdateCheckAllButton()
522 bool hasEnabled = false;
523 bool hasDisabled = false;
525 for (int i = 0; i < m_effects.count(); i++) {
526 if (!m_effects.at(i)->enabledButton->isChecked()) hasEnabled = true;
527 else hasDisabled = true;
530 m_ui.checkAll->blockSignals(true);
531 if (hasEnabled && hasDisabled)
532 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
534 m_ui.checkAll->setCheckState(Qt::Checked);
536 m_ui.checkAll->setCheckState(Qt::Unchecked);
537 m_ui.checkAll->blockSignals(false);
540 void EffectStackView2::deleteCurrentEffect()
542 for (int i = 0; i < m_effects.count(); i++) {
543 if (m_effects.at(i)->isActive()) {
544 slotDeleteEffect(m_effects.at(i)->effect());
550 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
552 m_effectMetaInfo.profile = profile;
553 m_effectMetaInfo.timecode = t;
556 void EffectStackView2::updateTimecodeFormat()
558 for (int i = 0; i< m_effects.count(); i++)
559 m_effects.at(i)->updateTimecodeFormat();
562 CollapsibleEffect *EffectStackView2::getEffectByIndex(int ix)
564 for (int i = 0; i< m_effects.count(); i++) {
565 if (m_effects.at(i)->effectIndex() == ix) {
566 return m_effects.at(i);
572 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
574 if (m_effectMetaInfo.trackMode)
575 emit updateEffect(NULL, m_trackindex, old, e, ix,false);
576 else if (m_clipref) {
577 emit updateEffect(m_clipref, -1, old, e, ix, false);
578 // Make sure the changed effect is currently displayed
579 slotSetCurrentEffect(ix);
581 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
584 void EffectStackView2::slotSetCurrentEffect(int ix)
586 if (m_clipref && ix != m_clipref->selectedEffectIndex()) {
587 m_clipref->setSelectedEffect(ix);
588 for (int i = 0; i < m_effects.count(); i++) {
589 if (m_effects.at(i)->effectIndex() == ix) {
590 if (m_effects.at(i)->isActive()) return;
591 m_effects.at(i)->setActive(true);
592 m_monitorSceneWanted = m_effects.at(i)->needsMonitorEffectScene();
593 slotCheckMonitorPosition(m_effectMetaInfo.monitor->render->seekFramePosition());
594 m_ui.labelComment->setText(i18n(m_effects.at(i)->effect().firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
595 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
597 else m_effects.at(i)->setActive(false);
602 void EffectStackView2::slotDeleteGroup(QDomDocument doc)
604 QDomNodeList effects = doc.elementsByTagName("effect");
605 ClipItem * clip = NULL;
607 if (m_effectMetaInfo.trackMode) {
615 for (int i = 0; i < effects.count(); i++)
616 emit removeEffect(clip, ix, effects.at(i).toElement());
619 void EffectStackView2::slotDeleteEffect(const QDomElement effect)
621 if (m_effectMetaInfo.trackMode)
622 emit removeEffect(NULL, m_trackindex, effect);
624 emit removeEffect(m_clipref, -1, effect);
627 void EffectStackView2::slotAddEffect(QDomElement effect)
629 emit addEffect(m_clipref, effect);
632 void EffectStackView2::slotMoveEffectUp(QList <int> indexes, bool up)
634 if (up && indexes.first() <= 1) return;
635 if (!up && indexes.last() >= m_currentEffectList.count()) return;
638 endPos = indexes.first() - 1;
641 endPos = indexes.last() + 1;
643 if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, indexes, endPos);
644 else emit changeEffectPosition(m_clipref, -1, indexes, endPos);
647 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&consumer, const QString&consumerParams, const QMap <QString, QString> &extraParams)
649 if (!m_clipref) return;
650 emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, consumer, consumerParams, extraParams);
653 void EffectStackView2::slotResetEffect(int ix)
655 QDomElement old = m_currentEffectList.itemFromIndex(ix);
657 QString effectId = old.attribute("id");
658 QMap<QString, EffectsList*> effectLists;
659 effectLists["audio"] = &MainWindow::audioEffects;
660 effectLists["video"] = &MainWindow::videoEffects;
661 effectLists["custom"] = &MainWindow::customEffects;
662 foreach(const QString &type, effectLists.keys()) {
663 EffectsList *list = effectLists[type];
664 dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
665 if (!dom.isNull()) break;
668 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
669 if (m_effectMetaInfo.trackMode) {
670 EffectsList::setParameter(dom, "in", QString::number(0));
671 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
673 info.track = m_trackInfo.type;
674 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
675 info.cropStart = GenTime(0);
676 info.startPos = GenTime(-1);
678 for (int i = 0; i < m_effects.count(); i++) {
679 if (m_effects.at(i)->effectIndex() == ix) {
680 m_effects.at(i)->updateWidget(info, dom, &m_effectMetaInfo);
684 emit updateEffect(NULL, m_trackindex, old, dom, ix,false);
686 m_clipref->initEffect(dom);
687 for (int i = 0; i < m_effects.count(); i++) {
688 if (m_effects.at(i)->effectIndex() == ix) {
689 m_effects.at(i)->updateWidget(m_clipref->info(), dom, &m_effectMetaInfo);
693 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
694 emit updateEffect(m_clipref, -1, old, dom, ix,false);
698 emit showComments(m_ui.buttonShowComments->isChecked());
699 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
702 void EffectStackView2::slotShowComments()
704 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
705 emit showComments(m_ui.buttonShowComments->isChecked());
708 void EffectStackView2::slotCreateRegion(int ix, KUrl url)
710 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
711 QDomElement neweffect = oldeffect.cloneNode().toElement();
712 QDomElement region = MainWindow::videoEffects.getEffectByTag("region", "region").cloneNode().toElement();
713 region.appendChild(region.ownerDocument().importNode(neweffect, true));
714 region.setAttribute("kdenlive_ix", ix);
715 EffectsList::setParameter(region, "resource", url.path());
716 if (m_effectMetaInfo.trackMode)
717 emit updateEffect(NULL, m_trackindex, oldeffect, region, ix,false);
718 else if (m_clipref) {
719 emit updateEffect(m_clipref, -1, oldeffect, region, ix, false);
720 // Make sure the changed effect is currently displayed
721 //slotSetCurrentEffect(ix);
723 // refresh effect stack
725 bool isSelected = false;
726 if (m_effectMetaInfo.trackMode) {
727 info.track = m_trackInfo.type;
728 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
729 info.cropStart = GenTime(0);
730 info.startPos = GenTime(-1);
733 else if (m_clipref) {
734 info = m_clipref->info();
736 CollapsibleEffect *current = getEffectByIndex(ix);
737 m_effects.removeAll(current);
738 current->setEnabled(false);
739 m_currentEffectList.removeAt(ix);
740 m_currentEffectList.insert(region);
741 current->deleteLater();
742 CollapsibleEffect *currentEffect = new CollapsibleEffect(region, m_currentEffectList.itemFromIndex(ix), info, &m_effectMetaInfo, ix == m_currentEffectList.count() - 1, m_ui.container->widget());
743 connectEffect(currentEffect);
745 if (m_effectMetaInfo.trackMode) {
746 isSelected = currentEffect->effectIndex() == 1;
748 else if (m_clipref) {
749 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
751 if (isSelected) currentEffect->setActive(true);
752 m_effects.append(currentEffect);
753 // TODO: region in group?
755 // group->addGroupEffect(currentEffect);
757 QVBoxLayout *vbox = static_cast <QVBoxLayout *> (m_ui.container->widget()->layout());
758 vbox->insertWidget(ix, currentEffect);
762 currentEffect->installEventFilter( this );
764 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
768 void EffectStackView2::slotCreateGroup(int ix)
770 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
771 QDomElement neweffect = oldeffect.cloneNode().toElement();
772 EffectInfo effectinfo;
773 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
774 effectinfo.groupIndex = m_groupIndex;
775 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
778 if (m_effectMetaInfo.trackMode) {
779 info.track = m_trackInfo.type;
780 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
781 info.cropStart = GenTime(0);
782 info.startPos = GenTime(-1);
784 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix, false);
786 emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix, false);
789 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
791 CollapsibleEffect *effectToMove = NULL;
792 for (int i = 0; i < m_effects.count(); i++) {
793 if (m_effects.at(i)->effectIndex() == ix) {
794 effectToMove = m_effects.at(i);
795 groupPos = l->indexOf(effectToMove);
796 l->removeWidget(effectToMove);
801 CollapsibleGroup *group = new CollapsibleGroup(m_groupIndex, ix == 1, ix == m_currentEffectList.count() - 2, effectinfo, m_ui.container->widget());
804 l->insertWidget(groupPos, group);
805 group->installEventFilter( this );
807 group->addGroupEffect(effectToMove);
810 void EffectStackView2::connectGroup(CollapsibleGroup *group)
812 connect(group, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
813 connect(group, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
814 connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
815 connect(group, SIGNAL(groupRenamed(CollapsibleGroup *)), this , SLOT(slotRenameGroup(CollapsibleGroup*)));
816 connect(group, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
817 connect(group, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
818 connect(group, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
821 void EffectStackView2::slotMoveEffect(QList <int> currentIndexes, int newIndex, int groupIndex, QString groupName)
823 if (currentIndexes.count() == 1) {
824 CollapsibleEffect *effectToMove = getEffectByIndex(currentIndexes.at(0));
825 if (effectToMove == NULL) return;
827 QDomElement oldeffect = effectToMove->effect();
828 QDomElement neweffect = oldeffect.cloneNode().toElement();
830 EffectInfo effectinfo;
831 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
832 effectinfo.groupIndex = groupIndex;
833 effectinfo.groupName = groupName;
834 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
836 if (oldeffect.attribute("kdenlive_info") != effectinfo.toString()) {
837 // effect's group info or collapsed state changed
839 if (m_effectMetaInfo.trackMode) {
840 info.track = m_trackInfo.type;
841 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
842 info.cropStart = GenTime(0);
843 info.startPos = GenTime(-1);
845 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->effectIndex(),false);
847 emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex(),false);
852 // Update effect index with new position
853 if (m_effectMetaInfo.trackMode) {
854 emit changeEffectPosition(NULL, m_trackindex, currentIndexes, newIndex);
857 emit changeEffectPosition(m_clipref, -1, currentIndexes, newIndex);
861 void EffectStackView2::slotUnGroup(CollapsibleGroup* group)
863 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
864 int ix = l->indexOf(group);
865 group->removeGroup(ix, l);
866 group->deleteLater();
869 void EffectStackView2::slotRenameGroup(CollapsibleGroup *group)
871 QList <CollapsibleEffect*> effects = group->effects();
872 for (int i = 0; i < effects.count(); i++) {
873 QDomElement origin = effects.at(i)->effect();
874 QDomElement changed = origin.cloneNode().toElement();
875 changed.setAttribute("kdenlive_info", effects.at(i)->infoString());
876 if (m_effectMetaInfo.trackMode) {
877 emit updateEffect(NULL, m_trackindex, origin, changed, effects.at(i)->effectIndex(),false);
879 emit updateEffect(m_clipref, -1, origin, changed, effects.at(i)->effectIndex(),false);
884 void EffectStackView2::dragEnterEvent(QDragEnterEvent *event)
886 if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
887 event->acceptProposedAction();
891 void EffectStackView2::processDroppedEffect(QDomElement e, QDropEvent *event)
893 int ix = e.attribute("kdenlive_ix").toInt();
894 if (e.tagName() == "effectgroup") {
895 // We are dropping a group, all effects in group should be moved
896 QDomNodeList effects = e.elementsByTagName("effect");
897 if (effects.count() == 0) {
902 info.fromString(effects.at(0).toElement().attribute("kdenlive_info"));
903 if (info.groupIndex < 0) {
904 kDebug()<<"// ADDING EFFECT!!!";
905 // Adding a new group effect to the stack
906 event->setDropAction(Qt::CopyAction);
911 // Moving group: delete all effects and re-add them
913 for (int i = 0; i < effects.count(); i++) {
914 QDomElement effect = effects.at(i).cloneNode().toElement();
915 indexes << effect.attribute("kdenlive_ix").toInt();
917 kDebug()<<"// Moving: "<<indexes<<" TO "<<m_currentEffectList.count();
918 slotMoveEffect(indexes, m_currentEffectList.count(), info.groupIndex, info.groupName);
921 // effect dropped from effects list, add it
922 e.setAttribute("kdenlive_ix", m_currentEffectList.count() + 1);
923 event->setDropAction(Qt::CopyAction);
929 // User is moving an effect
930 slotMoveEffect(QList<int> () << ix, m_currentEffectList.count() + 1, -1);
932 event->setDropAction(Qt::MoveAction);
936 void EffectStackView2::dropEvent(QDropEvent *event)
938 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
939 //event->acceptProposedAction();
941 doc.setContent(effects, true);
942 processDroppedEffect(doc.documentElement(), event);
946 const QString EffectStackView2::getStyleSheet()
948 KColorScheme scheme(QApplication::palette().currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
949 QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
950 QColor hgh = KColorUtils::mix(QApplication::palette().window().color(), selected_bg, 0.2);
951 QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
952 QColor light_bg = scheme.shade(KColorScheme::LightShade);
953 QColor alt_bg = scheme.background(KColorScheme::NormalBackground).color();
958 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()));
960 // effect in group background
961 stylesheet.append(QString("QFrame#decoframesub {border-top:1px solid palette(light);} QFrame#decoframesub[active=\"true\"] {background: %1;}").arg(hgh.name()));
964 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;} "));
967 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);}"));
969 // group effect title bar
970 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);} "));
972 // draggable effect bar content
973 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()));
975 // draggable effect bar
976 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()));
978 // spin box for draggable widget
979 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()));
981 // group editable labels
982 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);} "));
987 #include "effectstackview2.moc"