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),
55 m_effectMetaInfo.trackMode = false;
56 m_effectMetaInfo.monitor = monitor;
57 m_effects = QList <CollapsibleEffect*>();
61 setFont(KGlobalSettings::smallestReadableFont());
62 m_ui.checkAll->setToolTip(i18n("Enable/Disable all effects"));
63 m_ui.buttonShowComments->setIcon(KIcon("help-about"));
64 m_ui.buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
66 connect(m_ui.checkAll, SIGNAL(stateChanged(int)), this, SLOT(slotCheckAll(int)));
67 connect(m_ui.buttonShowComments, SIGNAL(clicked()), this, SLOT(slotShowComments()));
68 m_ui.labelComment->setHidden(true);
73 setStyleSheet(getStyleSheet());
76 EffectStackView2::~EffectStackView2()
80 void EffectStackView2::updatePalette()
82 setStyleSheet(getStyleSheet());
85 void EffectStackView2::slotRenderPos(int pos)
87 if (m_effects.isEmpty()) return;
88 slotCheckMonitorPosition(pos);
89 if (!m_effectMetaInfo.trackMode && m_clipref) pos = pos - m_clipref->startPos().frames(KdenliveSettings::project_fps());
91 for (int i = 0; i< m_effects.count(); i++)
92 m_effects.at(i)->slotSyncEffectsPos(pos);
95 void EffectStackView2::slotClipItemSelected(ClipItem* c)
97 if (c && !c->isEnabled()) return;
98 if (c && c == m_clipref) {
103 QString cname = m_clipref->clipName();
104 if (cname.length() > 30) {
105 m_ui.checkAll->setToolTip(i18n("Effects for %1").arg(cname));
107 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "...");
109 m_ui.checkAll->setToolTip(QString());
110 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
112 m_ui.checkAll->setEnabled(true);
113 QString size = c->baseClip()->getProperty("frame_size");
114 double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
115 m_effectMetaInfo.frameSize = QPoint((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
118 if (m_clipref == NULL) {
119 //TODO: clear list, reset paramdesc and info
121 //m_effectedit->transferParamDesc(QDomElement(), info);
126 m_effectMetaInfo.trackMode = false;
127 m_currentEffectList = m_clipref->effectList();
131 void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
134 m_effectMetaInfo.trackMode = true;
135 m_currentEffectList = info.effectsList;
138 m_ui.checkAll->setToolTip(QString());
139 m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
145 void EffectStackView2::setupListView()
148 m_draggedEffect = NULL;
149 m_draggedGroup = NULL;
150 disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
153 QWidget *view = m_ui.container->takeWidget();
158 view = new QWidget(m_ui.container);
159 m_ui.container->setWidget(view);
161 QVBoxLayout *vbox1 = new QVBoxLayout(view);
162 vbox1->setContentsMargins(0, 0, 0, 0);
163 vbox1->setSpacing(0);
165 for (int i = 0; i < m_currentEffectList.count(); i++) {
166 QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
168 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
172 CollapsibleGroup *group = NULL;
173 EffectInfo effectInfo;
174 effectInfo.fromString(d.attribute("kdenlive_info"));
175 if (effectInfo.groupIndex >= 0) {
176 // effect is in a group
177 for (int j = 0; j < vbox1->count(); j++) {
178 CollapsibleGroup *eff = static_cast<CollapsibleGroup *>(vbox1->itemAt(j)->widget());
179 if (eff->isGroup() && eff->groupIndex() == effectInfo.groupIndex) {
186 group = new CollapsibleGroup(effectInfo.groupIndex, i == 0, i == m_currentEffectList.count() - 1, effectInfo, m_ui.container->widget());
188 vbox1->addWidget(group);
189 group->installEventFilter( this );
191 if (effectInfo.groupIndex >= m_groupIndex) m_groupIndex = effectInfo.groupIndex + 1;
195 doc.appendChild(doc.importNode(d, true));
196 kDebug() << "IMPORTED STK: " << doc.toString();*/
199 bool isSelected = false;
200 if (m_effectMetaInfo.trackMode) {
201 info.track = m_trackInfo.type;
202 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
203 info.cropStart = GenTime(0);
204 info.startPos = GenTime(-1);
208 info = m_clipref->info();
211 CollapsibleEffect *currentEffect = new CollapsibleEffect(d, m_currentEffectList.at(i), info, &m_effectMetaInfo, i == m_currentEffectList.count() - 1, view);
212 if (m_effectMetaInfo.trackMode) {
213 isSelected = currentEffect->effectIndex() == 1;
216 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
218 if (isSelected) currentEffect->setActive(true);
219 m_effects.append(currentEffect);
221 group->addGroupEffect(currentEffect);
223 vbox1->addWidget(currentEffect);
225 connectEffect(currentEffect);
228 if (m_currentEffectList.isEmpty()) {
229 m_ui.labelComment->setHidden(true);
232 // Adjust group effects (up / down buttons)
233 QList<CollapsibleGroup *> allGroups = m_ui.container->widget()->findChildren<CollapsibleGroup *>();
234 for (int i = 0; i < allGroups.count(); i++) {
235 allGroups.at(i)->adjustEffects();
237 connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
240 vbox1->addStretch(10);
241 slotUpdateCheckAllButton();
243 // Wait a little bit for the new layout to be ready, then check if we have a scrollbar
244 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
247 void EffectStackView2::connectEffect(CollapsibleEffect *currentEffect)
250 currentEffect->installEventFilter( this );
251 connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
252 connect(currentEffect, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,QString,QString)));
253 connect(currentEffect, SIGNAL(deleteEffect(const QDomElement)), this , SLOT(slotDeleteEffect(const QDomElement)));
254 connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
255 connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
256 connect(currentEffect, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
257 connect(currentEffect, SIGNAL(effectStateChanged(bool,int,bool)), this, SLOT(slotUpdateEffectState(bool,int,bool)));
258 connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
259 connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
260 connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
261 connect(currentEffect, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
262 connect(currentEffect, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
263 connect(currentEffect, SIGNAL(createRegion(int,KUrl)), this, SLOT(slotCreateRegion(int,KUrl)));
264 connect(currentEffect, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
267 void EffectStackView2::slotCheckWheelEventFilter()
269 // If the effect stack widget has no scrollbar, we will not filter the
270 // mouse wheel events, so that user can easily adjust effect params
271 bool filterWheelEvent = false;
272 if (m_ui.container->verticalScrollBar() && m_ui.container->verticalScrollBar()->isVisible()) {
273 // widget has scroll bar,
274 filterWheelEvent = true;
276 for (int i = 0; i < m_effects.count(); i++) {
277 m_effects.at(i)->filterWheelEvent = filterWheelEvent;
281 void EffectStackView2::resizeEvent ( QResizeEvent * event )
283 slotCheckWheelEventFilter();
284 QWidget::resizeEvent(event);
287 bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
289 // Check if user clicked in an effect's top bar to start dragging it
290 if (e->type() == QEvent::MouseButtonPress) {
291 m_draggedEffect = qobject_cast<CollapsibleEffect*>(o);
292 if (m_draggedEffect) {
293 QMouseEvent *me = static_cast<QMouseEvent *>(e);
294 if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse())) {
295 m_clickPoint = me->globalPos();
298 m_clickPoint = QPoint();
299 m_draggedEffect = NULL;
304 m_draggedGroup = qobject_cast<CollapsibleGroup*>(o);
305 if (m_draggedGroup) {
306 QMouseEvent *me = static_cast<QMouseEvent *>(e);
307 if (me->button() == Qt::LeftButton && (m_draggedGroup->frame->underMouse() || m_draggedGroup->title()->underMouse()))
308 m_clickPoint = me->globalPos();
310 m_clickPoint = QPoint();
311 m_draggedGroup = NULL;
317 /*if (e->type() == QEvent::MouseMove) {
318 if (qobject_cast<CollapsibleEffect*>(o)) {
319 QMouseEvent *me = static_cast<QMouseEvent *>(e);
320 if (me->buttons() != Qt::LeftButton) {
330 return QWidget::eventFilter(o, e);
333 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
335 if (m_draggedEffect || m_draggedGroup) {
336 if ((event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
342 void EffectStackView2::mouseReleaseEvent(QMouseEvent * event)
344 m_draggedEffect = NULL;
345 m_draggedGroup = NULL;
346 QWidget::mouseReleaseEvent(event);
349 void EffectStackView2::startDrag()
351 // The data to be transferred by the drag and drop operation is contained in a QMimeData object
354 if (m_draggedEffect) {
355 QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
356 doc.appendChild(doc.importNode(effect, true));
357 pixmap = QPixmap::grabWidget(m_draggedEffect->title);
359 else if (m_draggedGroup) {
360 doc = m_draggedGroup->effectsData();
361 pixmap = QPixmap::grabWidget(m_draggedGroup->title());
364 QDrag *drag = new QDrag(this);
365 drag->setPixmap(pixmap);
366 QMimeData *mime = new QMimeData;
368 data.append(doc.toString().toUtf8());
369 mime->setData("kdenlive/effectslist", data);
371 // Assign ownership of the QMimeData object to the QDrag object.
372 drag->setMimeData(mime);
373 // Start the drag and drop operation
374 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
378 void EffectStackView2::slotUpdateEffectState(bool disable, int index, bool updateMainStatus)
380 if (m_effectMetaInfo.trackMode)
381 emit changeEffectState(NULL, m_trackindex, index, disable);
383 emit changeEffectState(m_clipref, -1, index, disable);
384 if (updateMainStatus) slotUpdateCheckAllButton();
388 void EffectStackView2::raiseWindow(QWidget* dock)
390 if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
395 void EffectStackView2::slotSeekTimeline(int pos)
397 if (m_effectMetaInfo.trackMode) {
398 emit seekTimeline(pos);
399 } else if (m_clipref) {
400 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
405 /*void EffectStackView2::slotRegionChanged()
407 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
410 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
412 CollapsibleEffect *current = currentEffect();
413 if (current && current->needsMonitorEffectScene()) {
414 if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
415 if (!m_effectMetaInfo.monitor->effectSceneDisplayed()) {
416 m_effectMetaInfo.monitor->slotShowEffectScene(true);
419 m_effectMetaInfo.monitor->slotShowEffectScene(false);
423 m_effectMetaInfo.monitor->slotShowEffectScene(false);
427 int EffectStackView2::isTrackMode(bool *ok) const
429 *ok = m_effectMetaInfo.trackMode;
433 void EffectStackView2::clear()
436 QWidget *view = m_ui.container->takeWidget();
440 m_ui.checkAll->setToolTip(QString());
441 m_ui.checkAll->setText(QString());
442 m_ui.checkAll->setEnabled(false);
443 m_ui.labelComment->setText(QString());
447 void EffectStackView2::slotCheckAll(int state)
449 if (state == Qt::PartiallyChecked) {
451 m_ui.checkAll->blockSignals(true);
452 m_ui.checkAll->setCheckState(Qt::Checked);
453 m_ui.checkAll->blockSignals(false);
456 bool disabled = state == Qt::Unchecked;
457 for (int i = 0; i < m_effects.count(); i++) {
458 if (!m_effects.at(i)->isGroup()) {
459 m_effects.at(i)->slotEnable(disabled, false);
464 void EffectStackView2::slotUpdateCheckAllButton()
466 bool hasEnabled = false;
467 bool hasDisabled = false;
469 for (int i = 0; i < m_effects.count(); i++) {
470 if (!m_effects.at(i)->enabledButton->isChecked()) hasEnabled = true;
471 else hasDisabled = true;
474 m_ui.checkAll->blockSignals(true);
475 if (hasEnabled && hasDisabled)
476 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
478 m_ui.checkAll->setCheckState(Qt::Checked);
480 m_ui.checkAll->setCheckState(Qt::Unchecked);
481 m_ui.checkAll->blockSignals(false);
484 void EffectStackView2::deleteCurrentEffect()
486 for (int i = 0; i < m_effects.count(); i++) {
487 if (m_effects.at(i)->isActive()) {
488 slotDeleteEffect(m_effects.at(i)->effect());
494 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
496 m_effectMetaInfo.profile = profile;
497 m_effectMetaInfo.timecode = t;
500 void EffectStackView2::updateTimecodeFormat()
502 for (int i = 0; i< m_effects.count(); i++)
503 m_effects.at(i)->updateTimecodeFormat();
506 CollapsibleEffect *EffectStackView2::getEffectByIndex(int ix)
508 for (int i = 0; i< m_effects.count(); i++) {
509 if (m_effects.at(i)->effectIndex() == ix) {
510 return m_effects.at(i);
516 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
518 if (m_effectMetaInfo.trackMode)
519 emit updateEffect(NULL, m_trackindex, old, e, ix,false);
520 else if (m_clipref) {
521 emit updateEffect(m_clipref, -1, old, e, ix, false);
522 // Make sure the changed effect is currently displayed
523 slotSetCurrentEffect(ix);
525 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
528 void EffectStackView2::slotSetCurrentEffect(int ix)
530 if (m_clipref && ix != m_clipref->selectedEffectIndex()) {
531 m_clipref->setSelectedEffect(ix);
532 for (int i = 0; i < m_effects.count(); i++) {
533 if (m_effects.at(i)->effectIndex() == ix) {
534 if (m_effects.at(i)->isActive()) return;
535 m_effects.at(i)->setActive(true);
536 slotCheckMonitorPosition(m_effectMetaInfo.monitor->render->seekFramePosition());
537 m_ui.labelComment->setText(i18n(m_effects.at(i)->effect().firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
538 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
540 else m_effects.at(i)->setActive(false);
545 CollapsibleEffect *EffectStackView2::currentEffect() const
547 for (int i = 0; i < m_effects.count(); i++) {
548 if (m_effects.at(i)->isActive()) return m_effects.at(i);
553 void EffectStackView2::slotDeleteGroup(QDomDocument doc)
555 QDomNodeList effects = doc.elementsByTagName("effect");
556 ClipItem * clip = NULL;
558 if (m_effectMetaInfo.trackMode) {
566 for (int i = 0; i < effects.count(); i++)
567 emit removeEffect(clip, ix, effects.at(i).toElement());
570 void EffectStackView2::slotDeleteEffect(const QDomElement effect)
572 if (m_effectMetaInfo.trackMode)
573 emit removeEffect(NULL, m_trackindex, effect);
575 emit removeEffect(m_clipref, -1, effect);
578 void EffectStackView2::slotAddEffect(QDomElement effect)
580 emit addEffect(m_clipref, effect);
583 void EffectStackView2::slotMoveEffectUp(QList <int> indexes, bool up)
585 if (up && indexes.first() <= 1) return;
586 if (!up && indexes.last() >= m_currentEffectList.count()) return;
589 endPos = indexes.first() - 1;
592 endPos = indexes.last() + 1;
594 if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, indexes, endPos);
595 else emit changeEffectPosition(m_clipref, -1, indexes, endPos);
598 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
600 if (!m_clipref) return;
601 emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, finalFilterName, consumer, consumerParams, properties);
604 void EffectStackView2::slotResetEffect(int ix)
606 QDomElement old = m_currentEffectList.itemFromIndex(ix);
608 QString effectId = old.attribute("id");
609 QMap<QString, EffectsList*> effectLists;
610 effectLists["audio"] = &MainWindow::audioEffects;
611 effectLists["video"] = &MainWindow::videoEffects;
612 effectLists["custom"] = &MainWindow::customEffects;
613 foreach(const QString &type, effectLists.keys()) {
614 EffectsList *list = effectLists[type];
615 dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
616 if (!dom.isNull()) break;
619 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
620 if (m_effectMetaInfo.trackMode) {
621 EffectsList::setParameter(dom, "in", QString::number(0));
622 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
624 info.track = m_trackInfo.type;
625 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
626 info.cropStart = GenTime(0);
627 info.startPos = GenTime(-1);
629 m_effects.at(ix)->updateWidget(info, dom, &m_effectMetaInfo);
630 emit updateEffect(NULL, m_trackindex, old, dom, ix,false);
632 m_clipref->initEffect(dom);
633 for (int i = 0; i < m_effects.count(); i++) {
634 if (m_effects.at(i)->effectIndex() == ix) {
635 m_effects.at(i)->updateWidget(m_clipref->info(), dom, &m_effectMetaInfo);
639 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
640 emit updateEffect(m_clipref, -1, old, dom, ix,false);
644 emit showComments(m_ui.buttonShowComments->isChecked());
645 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
648 void EffectStackView2::slotShowComments()
650 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
651 emit showComments(m_ui.buttonShowComments->isChecked());
654 void EffectStackView2::slotCreateRegion(int ix, KUrl url)
656 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
657 QDomElement neweffect = oldeffect.cloneNode().toElement();
658 QDomElement region = MainWindow::videoEffects.getEffectByTag("region", "region").cloneNode().toElement();
659 region.appendChild(region.ownerDocument().importNode(neweffect, true));
660 region.setAttribute("kdenlive_ix", ix);
661 EffectsList::setParameter(region, "resource", url.path());
662 if (m_effectMetaInfo.trackMode)
663 emit updateEffect(NULL, m_trackindex, oldeffect, region, ix,false);
664 else if (m_clipref) {
665 emit updateEffect(m_clipref, -1, oldeffect, region, ix, false);
666 // Make sure the changed effect is currently displayed
667 //slotSetCurrentEffect(ix);
669 // refresh effect stack
671 bool isSelected = false;
672 if (m_effectMetaInfo.trackMode) {
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);
680 info = m_clipref->info();
682 CollapsibleEffect *current = getEffectByIndex(ix);
683 m_effects.removeAll(current);
684 current->setEnabled(false);
685 m_currentEffectList.removeAt(ix);
686 m_currentEffectList.insert(region);
687 current->deleteLater();
688 CollapsibleEffect *currentEffect = new CollapsibleEffect(region, m_currentEffectList.itemFromIndex(ix), info, &m_effectMetaInfo, ix == m_currentEffectList.count() - 1, m_ui.container->widget());
689 connectEffect(currentEffect);
691 if (m_effectMetaInfo.trackMode) {
692 isSelected = currentEffect->effectIndex() == 1;
695 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
697 if (isSelected) currentEffect->setActive(true);
698 m_effects.append(currentEffect);
699 // TODO: region in group?
701 // group->addGroupEffect(currentEffect);
703 QVBoxLayout *vbox = static_cast <QVBoxLayout *> (m_ui.container->widget()->layout());
704 vbox->insertWidget(ix, currentEffect);
708 currentEffect->installEventFilter( this );
710 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
714 void EffectStackView2::slotCreateGroup(int ix)
716 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
717 QDomElement neweffect = oldeffect.cloneNode().toElement();
718 EffectInfo effectinfo;
719 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
720 effectinfo.groupIndex = m_groupIndex;
721 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
724 if (m_effectMetaInfo.trackMode) {
725 info.track = m_trackInfo.type;
726 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
727 info.cropStart = GenTime(0);
728 info.startPos = GenTime(-1);
730 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix, false);
732 emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix, false);
735 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
737 CollapsibleEffect *effectToMove = NULL;
738 for (int i = 0; i < m_effects.count(); i++) {
739 if (m_effects.at(i)->effectIndex() == ix) {
740 effectToMove = m_effects.at(i);
741 groupPos = l->indexOf(effectToMove);
742 l->removeWidget(effectToMove);
747 CollapsibleGroup *group = new CollapsibleGroup(m_groupIndex, ix == 1, ix == m_currentEffectList.count() - 2, effectinfo, m_ui.container->widget());
750 l->insertWidget(groupPos, group);
751 group->installEventFilter( this );
752 group->addGroupEffect(effectToMove);
755 void EffectStackView2::connectGroup(CollapsibleGroup *group)
757 connect(group, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
758 connect(group, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
759 connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
760 connect(group, SIGNAL(groupRenamed(CollapsibleGroup *)), this , SLOT(slotRenameGroup(CollapsibleGroup*)));
761 connect(group, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
762 connect(group, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
763 connect(group, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
766 void EffectStackView2::slotMoveEffect(QList <int> currentIndexes, int newIndex, int groupIndex, QString groupName)
768 if (currentIndexes.count() == 1) {
769 CollapsibleEffect *effectToMove = getEffectByIndex(currentIndexes.at(0));
770 if (effectToMove == NULL) return;
772 QDomElement oldeffect = effectToMove->effect();
773 QDomElement neweffect = oldeffect.cloneNode().toElement();
775 EffectInfo effectinfo;
776 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
777 effectinfo.groupIndex = groupIndex;
778 effectinfo.groupName = groupName;
779 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
781 if (oldeffect.attribute("kdenlive_info") != effectinfo.toString()) {
782 // effect's group info or collapsed state changed
784 if (m_effectMetaInfo.trackMode) {
785 info.track = m_trackInfo.type;
786 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
787 info.cropStart = GenTime(0);
788 info.startPos = GenTime(-1);
790 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->effectIndex(),false);
792 emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex(),false);
797 // Update effect index with new position
798 if (m_effectMetaInfo.trackMode) {
799 emit changeEffectPosition(NULL, m_trackindex, currentIndexes, newIndex);
802 emit changeEffectPosition(m_clipref, -1, currentIndexes, newIndex);
806 void EffectStackView2::slotUnGroup(CollapsibleGroup* group)
808 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
809 int ix = l->indexOf(group);
810 group->removeGroup(ix, l);
811 group->deleteLater();
814 void EffectStackView2::slotRenameGroup(CollapsibleGroup *group)
816 QList <CollapsibleEffect*> effects = group->effects();
817 for (int i = 0; i < effects.count(); i++) {
818 QDomElement origin = effects.at(i)->effect();
819 QDomElement changed = origin.cloneNode().toElement();
820 changed.setAttribute("kdenlive_info", effects.at(i)->infoString());
821 if (m_effectMetaInfo.trackMode) {
822 emit updateEffect(NULL, m_trackindex, origin, changed, effects.at(i)->effectIndex(),false);
824 emit updateEffect(m_clipref, -1, origin, changed, effects.at(i)->effectIndex(),false);
829 void EffectStackView2::dragEnterEvent(QDragEnterEvent *event)
831 if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
832 event->acceptProposedAction();
836 void EffectStackView2::processDroppedEffect(QDomElement e, QDropEvent *event)
838 int ix = e.attribute("kdenlive_ix").toInt();
839 if (e.tagName() == "effectgroup") {
840 // We are dropping a group, all effects in group should be moved
841 QDomNodeList effects = e.elementsByTagName("effect");
842 if (effects.count() == 0) {
847 info.fromString(effects.at(0).toElement().attribute("kdenlive_info"));
848 if (info.groupIndex < 0) {
849 kDebug()<<"// ADDING EFFECT!!!";
850 // Adding a new group effect to the stack
851 event->setDropAction(Qt::CopyAction);
856 // Moving group: delete all effects and re-add them
858 for (int i = 0; i < effects.count(); i++) {
859 QDomElement effect = effects.at(i).cloneNode().toElement();
860 indexes << effect.attribute("kdenlive_ix").toInt();
862 kDebug()<<"// Moving: "<<indexes<<" TO "<<m_currentEffectList.count();
863 slotMoveEffect(indexes, m_currentEffectList.count(), info.groupIndex, info.groupName);
866 // effect dropped from effects list, add it
867 e.setAttribute("kdenlive_ix", m_currentEffectList.count() + 1);
868 event->setDropAction(Qt::CopyAction);
874 // User is moving an effect
875 slotMoveEffect(QList<int> () << ix, m_currentEffectList.count() + 1, -1);
877 event->setDropAction(Qt::MoveAction);
881 void EffectStackView2::dropEvent(QDropEvent *event)
883 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
884 //event->acceptProposedAction();
886 doc.setContent(effects, true);
887 processDroppedEffect(doc.documentElement(), event);
891 const QString EffectStackView2::getStyleSheet()
893 KColorScheme scheme(QApplication::palette().currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
894 QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
895 QColor hgh = KColorUtils::mix(QApplication::palette().window().color(), selected_bg, 0.2);
896 QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
897 QColor light_bg = scheme.shade(KColorScheme::LightShade);
898 QColor alt_bg = scheme.background(KColorScheme::NormalBackground).color();
903 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()));
905 // effect in group background
906 stylesheet.append(QString("QFrame#decoframesub {border-top:1px solid palette(light);} QFrame#decoframesub[active=\"true\"] {background: %1;}").arg(hgh.name()));
909 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;} "));
912 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);}"));
914 // group effect title bar
915 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);} "));
917 // draggable effect bar content
918 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()));
920 // draggable effect bar
921 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()));
923 // spin box for draggable widget
924 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()));
926 // group editable labels
927 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);} "));
932 #include "effectstackview2.moc"