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,QString,QString)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,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)));
289 void EffectStackView2::slotCheckWheelEventFilter()
291 // If the effect stack widget has no scrollbar, we will not filter the
292 // mouse wheel events, so that user can easily adjust effect params
293 bool filterWheelEvent = false;
294 if (m_ui.container->verticalScrollBar() && m_ui.container->verticalScrollBar()->isVisible()) {
295 // widget has scroll bar,
296 filterWheelEvent = true;
298 for (int i = 0; i < m_effects.count(); i++) {
299 m_effects.at(i)->filterWheelEvent = filterWheelEvent;
303 void EffectStackView2::resizeEvent ( QResizeEvent * event )
305 slotCheckWheelEventFilter();
306 QWidget::resizeEvent(event);
309 bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
311 // Check if user clicked in an effect's top bar to start dragging it
312 if (e->type() == QEvent::MouseButtonPress) {
313 m_draggedEffect = qobject_cast<CollapsibleEffect*>(o);
314 if (m_draggedEffect) {
315 QMouseEvent *me = static_cast<QMouseEvent *>(e);
316 if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse())) {
317 m_clickPoint = me->globalPos();
320 m_clickPoint = QPoint();
321 m_draggedEffect = NULL;
326 m_draggedGroup = qobject_cast<CollapsibleGroup*>(o);
327 if (m_draggedGroup) {
328 QMouseEvent *me = static_cast<QMouseEvent *>(e);
329 if (me->button() == Qt::LeftButton && (m_draggedGroup->frame->underMouse() || m_draggedGroup->title()->underMouse()))
330 m_clickPoint = me->globalPos();
332 m_clickPoint = QPoint();
333 m_draggedGroup = NULL;
339 /*if (e->type() == QEvent::MouseMove) {
340 if (qobject_cast<CollapsibleEffect*>(o)) {
341 QMouseEvent *me = static_cast<QMouseEvent *>(e);
342 if (me->buttons() != Qt::LeftButton) {
352 return QWidget::eventFilter(o, e);
355 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
357 if (m_draggedEffect || m_draggedGroup) {
358 if ((event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
364 void EffectStackView2::mouseReleaseEvent(QMouseEvent * event)
366 m_draggedEffect = NULL;
367 m_draggedGroup = NULL;
368 QWidget::mouseReleaseEvent(event);
371 void EffectStackView2::startDrag()
373 // The data to be transferred by the drag and drop operation is contained in a QMimeData object
376 if (m_draggedEffect) {
377 QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
378 if (m_effectMetaInfo.trackMode) {
379 // Keep clip crop start in case we want to paste effect
380 effect.setAttribute("clipstart", 0);
383 // Keep clip crop start in case we want to paste effect
384 effect.setAttribute("clipstart", m_clipref->cropStart().frames(KdenliveSettings::project_fps()));
386 doc.appendChild(doc.importNode(effect, true));
387 pixmap = QPixmap::grabWidget(m_draggedEffect->title);
389 else if (m_draggedGroup) {
390 doc = m_draggedGroup->effectsData();
391 pixmap = QPixmap::grabWidget(m_draggedGroup->title());
394 QDrag *drag = new QDrag(this);
395 drag->setPixmap(pixmap);
396 QMimeData *mime = new QMimeData;
398 data.append(doc.toString().toUtf8());
399 mime->setData("kdenlive/effectslist", data);
401 // Assign ownership of the QMimeData object to the QDrag object.
402 drag->setMimeData(mime);
403 // Start the drag and drop operation
404 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
408 void EffectStackView2::slotUpdateEffectState(bool disable, int index, bool needsMonitorEffectScene)
410 if (m_monitorSceneWanted && disable) {
411 m_effectMetaInfo.monitor->slotShowEffectScene(false);
412 m_monitorSceneWanted = false;
414 else if (!disable && !m_monitorSceneWanted && needsMonitorEffectScene) {
415 m_effectMetaInfo.monitor->slotShowEffectScene(true);
416 m_monitorSceneWanted = true;
418 if (m_effectMetaInfo.trackMode)
419 emit changeEffectState(NULL, m_trackindex, QList <int>() << index, disable);
421 emit changeEffectState(m_clipref, -1, QList <int>() <<index, disable);
422 slotUpdateCheckAllButton();
426 void EffectStackView2::raiseWindow(QWidget* dock)
428 if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
433 void EffectStackView2::slotSeekTimeline(int pos)
435 if (m_effectMetaInfo.trackMode) {
436 emit seekTimeline(pos);
437 } else if (m_clipref) {
438 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
443 /*void EffectStackView2::slotRegionChanged()
445 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
448 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
450 if (m_monitorSceneWanted) {
451 if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
452 if (!m_effectMetaInfo.monitor->effectSceneDisplayed()) {
453 m_effectMetaInfo.monitor->slotShowEffectScene(true);
456 m_effectMetaInfo.monitor->slotShowEffectScene(false);
460 m_effectMetaInfo.monitor->slotShowEffectScene(false);
464 int EffectStackView2::isTrackMode(bool *ok) const
466 *ok = m_effectMetaInfo.trackMode;
470 void EffectStackView2::clear()
473 m_monitorSceneWanted = false;
474 QWidget *view = m_ui.container->takeWidget();
478 m_ui.checkAll->setToolTip(QString());
479 m_ui.checkAll->setText(QString());
480 m_ui.checkAll->setEnabled(false);
481 m_ui.labelComment->setText(QString());
485 void EffectStackView2::slotCheckAll(int state)
487 if (state == Qt::PartiallyChecked) {
489 m_ui.checkAll->blockSignals(true);
490 m_ui.checkAll->setCheckState(Qt::Checked);
491 m_ui.checkAll->blockSignals(false);
494 bool disabled = state == Qt::Unchecked;
495 // Disable all effects
497 for (int i = 0; i < m_effects.count(); i++) {
498 m_effects.at(i)->slotEnable(disabled, false);
499 indexes << m_effects.at(i)->effectIndex();
501 // Take care of groups
502 QList<CollapsibleGroup *> allGroups = m_ui.container->widget()->findChildren<CollapsibleGroup *>();
503 for (int i = 0; i < allGroups.count(); i++) {
504 allGroups.at(i)->slotEnable(disabled, false);
507 if (m_effectMetaInfo.trackMode)
508 emit changeEffectState(NULL, m_trackindex, indexes, disabled);
510 emit changeEffectState(m_clipref, -1, indexes, disabled);
513 void EffectStackView2::slotUpdateCheckAllButton()
515 bool hasEnabled = false;
516 bool hasDisabled = false;
518 for (int i = 0; i < m_effects.count(); i++) {
519 if (!m_effects.at(i)->enabledButton->isChecked()) hasEnabled = true;
520 else hasDisabled = true;
523 m_ui.checkAll->blockSignals(true);
524 if (hasEnabled && hasDisabled)
525 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
527 m_ui.checkAll->setCheckState(Qt::Checked);
529 m_ui.checkAll->setCheckState(Qt::Unchecked);
530 m_ui.checkAll->blockSignals(false);
533 void EffectStackView2::deleteCurrentEffect()
535 for (int i = 0; i < m_effects.count(); i++) {
536 if (m_effects.at(i)->isActive()) {
537 slotDeleteEffect(m_effects.at(i)->effect());
543 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
545 m_effectMetaInfo.profile = profile;
546 m_effectMetaInfo.timecode = t;
549 void EffectStackView2::updateTimecodeFormat()
551 for (int i = 0; i< m_effects.count(); i++)
552 m_effects.at(i)->updateTimecodeFormat();
555 CollapsibleEffect *EffectStackView2::getEffectByIndex(int ix)
557 for (int i = 0; i< m_effects.count(); i++) {
558 if (m_effects.at(i)->effectIndex() == ix) {
559 return m_effects.at(i);
565 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
567 if (m_effectMetaInfo.trackMode)
568 emit updateEffect(NULL, m_trackindex, old, e, ix,false);
569 else if (m_clipref) {
570 emit updateEffect(m_clipref, -1, old, e, ix, false);
571 // Make sure the changed effect is currently displayed
572 slotSetCurrentEffect(ix);
574 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
577 void EffectStackView2::slotSetCurrentEffect(int ix)
579 if (m_clipref && ix != m_clipref->selectedEffectIndex()) {
580 m_clipref->setSelectedEffect(ix);
581 for (int i = 0; i < m_effects.count(); i++) {
582 if (m_effects.at(i)->effectIndex() == ix) {
583 if (m_effects.at(i)->isActive()) return;
584 m_effects.at(i)->setActive(true);
585 m_monitorSceneWanted = m_effects.at(i)->needsMonitorEffectScene();
586 slotCheckMonitorPosition(m_effectMetaInfo.monitor->render->seekFramePosition());
587 m_ui.labelComment->setText(i18n(m_effects.at(i)->effect().firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
588 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
590 else m_effects.at(i)->setActive(false);
595 void EffectStackView2::slotDeleteGroup(QDomDocument doc)
597 QDomNodeList effects = doc.elementsByTagName("effect");
598 ClipItem * clip = NULL;
600 if (m_effectMetaInfo.trackMode) {
608 for (int i = 0; i < effects.count(); i++)
609 emit removeEffect(clip, ix, effects.at(i).toElement());
612 void EffectStackView2::slotDeleteEffect(const QDomElement effect)
614 if (m_effectMetaInfo.trackMode)
615 emit removeEffect(NULL, m_trackindex, effect);
617 emit removeEffect(m_clipref, -1, effect);
620 void EffectStackView2::slotAddEffect(QDomElement effect)
622 emit addEffect(m_clipref, effect);
625 void EffectStackView2::slotMoveEffectUp(QList <int> indexes, bool up)
627 if (up && indexes.first() <= 1) return;
628 if (!up && indexes.last() >= m_currentEffectList.count()) return;
631 endPos = indexes.first() - 1;
634 endPos = indexes.last() + 1;
636 if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, indexes, endPos);
637 else emit changeEffectPosition(m_clipref, -1, indexes, endPos);
640 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
642 if (!m_clipref) return;
643 emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, finalFilterName, consumer, consumerParams, properties);
646 void EffectStackView2::slotResetEffect(int ix)
648 QDomElement old = m_currentEffectList.itemFromIndex(ix);
650 QString effectId = old.attribute("id");
651 QMap<QString, EffectsList*> effectLists;
652 effectLists["audio"] = &MainWindow::audioEffects;
653 effectLists["video"] = &MainWindow::videoEffects;
654 effectLists["custom"] = &MainWindow::customEffects;
655 foreach(const QString &type, effectLists.keys()) {
656 EffectsList *list = effectLists[type];
657 dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
658 if (!dom.isNull()) break;
661 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
662 if (m_effectMetaInfo.trackMode) {
663 EffectsList::setParameter(dom, "in", QString::number(0));
664 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
666 info.track = m_trackInfo.type;
667 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
668 info.cropStart = GenTime(0);
669 info.startPos = GenTime(-1);
671 for (int i = 0; i < m_effects.count(); i++) {
672 if (m_effects.at(i)->effectIndex() == ix) {
673 m_effects.at(i)->updateWidget(info, dom, &m_effectMetaInfo);
677 emit updateEffect(NULL, m_trackindex, old, dom, ix,false);
679 m_clipref->initEffect(dom);
680 for (int i = 0; i < m_effects.count(); i++) {
681 if (m_effects.at(i)->effectIndex() == ix) {
682 m_effects.at(i)->updateWidget(m_clipref->info(), dom, &m_effectMetaInfo);
686 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
687 emit updateEffect(m_clipref, -1, old, dom, ix,false);
691 emit showComments(m_ui.buttonShowComments->isChecked());
692 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
695 void EffectStackView2::slotShowComments()
697 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
698 emit showComments(m_ui.buttonShowComments->isChecked());
701 void EffectStackView2::slotCreateRegion(int ix, KUrl url)
703 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
704 QDomElement neweffect = oldeffect.cloneNode().toElement();
705 QDomElement region = MainWindow::videoEffects.getEffectByTag("region", "region").cloneNode().toElement();
706 region.appendChild(region.ownerDocument().importNode(neweffect, true));
707 region.setAttribute("kdenlive_ix", ix);
708 EffectsList::setParameter(region, "resource", url.path());
709 if (m_effectMetaInfo.trackMode)
710 emit updateEffect(NULL, m_trackindex, oldeffect, region, ix,false);
711 else if (m_clipref) {
712 emit updateEffect(m_clipref, -1, oldeffect, region, ix, false);
713 // Make sure the changed effect is currently displayed
714 //slotSetCurrentEffect(ix);
716 // refresh effect stack
718 bool isSelected = false;
719 if (m_effectMetaInfo.trackMode) {
720 info.track = m_trackInfo.type;
721 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
722 info.cropStart = GenTime(0);
723 info.startPos = GenTime(-1);
727 info = m_clipref->info();
729 CollapsibleEffect *current = getEffectByIndex(ix);
730 m_effects.removeAll(current);
731 current->setEnabled(false);
732 m_currentEffectList.removeAt(ix);
733 m_currentEffectList.insert(region);
734 current->deleteLater();
735 CollapsibleEffect *currentEffect = new CollapsibleEffect(region, m_currentEffectList.itemFromIndex(ix), info, &m_effectMetaInfo, ix == m_currentEffectList.count() - 1, m_ui.container->widget());
736 connectEffect(currentEffect);
738 if (m_effectMetaInfo.trackMode) {
739 isSelected = currentEffect->effectIndex() == 1;
742 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
744 if (isSelected) currentEffect->setActive(true);
745 m_effects.append(currentEffect);
746 // TODO: region in group?
748 // group->addGroupEffect(currentEffect);
750 QVBoxLayout *vbox = static_cast <QVBoxLayout *> (m_ui.container->widget()->layout());
751 vbox->insertWidget(ix, currentEffect);
755 currentEffect->installEventFilter( this );
757 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
761 void EffectStackView2::slotCreateGroup(int ix)
763 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
764 QDomElement neweffect = oldeffect.cloneNode().toElement();
765 EffectInfo effectinfo;
766 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
767 effectinfo.groupIndex = m_groupIndex;
768 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
771 if (m_effectMetaInfo.trackMode) {
772 info.track = m_trackInfo.type;
773 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
774 info.cropStart = GenTime(0);
775 info.startPos = GenTime(-1);
777 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix, false);
779 emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix, false);
782 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
784 CollapsibleEffect *effectToMove = NULL;
785 for (int i = 0; i < m_effects.count(); i++) {
786 if (m_effects.at(i)->effectIndex() == ix) {
787 effectToMove = m_effects.at(i);
788 groupPos = l->indexOf(effectToMove);
789 l->removeWidget(effectToMove);
794 CollapsibleGroup *group = new CollapsibleGroup(m_groupIndex, ix == 1, ix == m_currentEffectList.count() - 2, effectinfo, m_ui.container->widget());
797 l->insertWidget(groupPos, group);
798 group->installEventFilter( this );
799 group->addGroupEffect(effectToMove);
802 void EffectStackView2::connectGroup(CollapsibleGroup *group)
804 connect(group, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
805 connect(group, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
806 connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
807 connect(group, SIGNAL(groupRenamed(CollapsibleGroup *)), this , SLOT(slotRenameGroup(CollapsibleGroup*)));
808 connect(group, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
809 connect(group, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
810 connect(group, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
813 void EffectStackView2::slotMoveEffect(QList <int> currentIndexes, int newIndex, int groupIndex, QString groupName)
815 if (currentIndexes.count() == 1) {
816 CollapsibleEffect *effectToMove = getEffectByIndex(currentIndexes.at(0));
817 if (effectToMove == NULL) return;
819 QDomElement oldeffect = effectToMove->effect();
820 QDomElement neweffect = oldeffect.cloneNode().toElement();
822 EffectInfo effectinfo;
823 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
824 effectinfo.groupIndex = groupIndex;
825 effectinfo.groupName = groupName;
826 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
828 if (oldeffect.attribute("kdenlive_info") != effectinfo.toString()) {
829 // effect's group info or collapsed state changed
831 if (m_effectMetaInfo.trackMode) {
832 info.track = m_trackInfo.type;
833 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
834 info.cropStart = GenTime(0);
835 info.startPos = GenTime(-1);
837 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->effectIndex(),false);
839 emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex(),false);
844 // Update effect index with new position
845 if (m_effectMetaInfo.trackMode) {
846 emit changeEffectPosition(NULL, m_trackindex, currentIndexes, newIndex);
849 emit changeEffectPosition(m_clipref, -1, currentIndexes, newIndex);
853 void EffectStackView2::slotUnGroup(CollapsibleGroup* group)
855 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
856 int ix = l->indexOf(group);
857 group->removeGroup(ix, l);
858 group->deleteLater();
861 void EffectStackView2::slotRenameGroup(CollapsibleGroup *group)
863 QList <CollapsibleEffect*> effects = group->effects();
864 for (int i = 0; i < effects.count(); i++) {
865 QDomElement origin = effects.at(i)->effect();
866 QDomElement changed = origin.cloneNode().toElement();
867 changed.setAttribute("kdenlive_info", effects.at(i)->infoString());
868 if (m_effectMetaInfo.trackMode) {
869 emit updateEffect(NULL, m_trackindex, origin, changed, effects.at(i)->effectIndex(),false);
871 emit updateEffect(m_clipref, -1, origin, changed, effects.at(i)->effectIndex(),false);
876 void EffectStackView2::dragEnterEvent(QDragEnterEvent *event)
878 if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
879 event->acceptProposedAction();
883 void EffectStackView2::processDroppedEffect(QDomElement e, QDropEvent *event)
885 int ix = e.attribute("kdenlive_ix").toInt();
886 if (e.tagName() == "effectgroup") {
887 // We are dropping a group, all effects in group should be moved
888 QDomNodeList effects = e.elementsByTagName("effect");
889 if (effects.count() == 0) {
894 info.fromString(effects.at(0).toElement().attribute("kdenlive_info"));
895 if (info.groupIndex < 0) {
896 kDebug()<<"// ADDING EFFECT!!!";
897 // Adding a new group effect to the stack
898 event->setDropAction(Qt::CopyAction);
903 // Moving group: delete all effects and re-add them
905 for (int i = 0; i < effects.count(); i++) {
906 QDomElement effect = effects.at(i).cloneNode().toElement();
907 indexes << effect.attribute("kdenlive_ix").toInt();
909 kDebug()<<"// Moving: "<<indexes<<" TO "<<m_currentEffectList.count();
910 slotMoveEffect(indexes, m_currentEffectList.count(), info.groupIndex, info.groupName);
913 // effect dropped from effects list, add it
914 e.setAttribute("kdenlive_ix", m_currentEffectList.count() + 1);
915 event->setDropAction(Qt::CopyAction);
921 // User is moving an effect
922 slotMoveEffect(QList<int> () << ix, m_currentEffectList.count() + 1, -1);
924 event->setDropAction(Qt::MoveAction);
928 void EffectStackView2::dropEvent(QDropEvent *event)
930 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
931 //event->acceptProposedAction();
933 doc.setContent(effects, true);
934 processDroppedEffect(doc.documentElement(), event);
938 const QString EffectStackView2::getStyleSheet()
940 KColorScheme scheme(QApplication::palette().currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
941 QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
942 QColor hgh = KColorUtils::mix(QApplication::palette().window().color(), selected_bg, 0.2);
943 QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
944 QColor light_bg = scheme.shade(KColorScheme::LightShade);
945 QColor alt_bg = scheme.background(KColorScheme::NormalBackground).color();
950 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()));
952 // effect in group background
953 stylesheet.append(QString("QFrame#decoframesub {border-top:1px solid palette(light);} QFrame#decoframesub[active=\"true\"] {background: %1;}").arg(hgh.name()));
956 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;} "));
959 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);}"));
961 // group effect title bar
962 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);} "));
964 // draggable effect bar content
965 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()));
967 // draggable effect bar
968 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()));
970 // spin box for draggable widget
971 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()));
973 // group editable labels
974 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);} "));
979 #include "effectstackview2.moc"