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").arg(cname));
108 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "...");
110 m_ui.checkAll->setToolTip(QString());
111 m_ui.checkAll->setText(i18n("Effects for %1").arg(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
122 //m_effectedit->transferParamDesc(QDomElement(), info);
127 m_effectMetaInfo.trackMode = false;
128 m_currentEffectList = m_clipref->effectList();
132 void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
135 m_effectMetaInfo.trackMode = true;
136 m_currentEffectList = info.effectsList;
139 m_ui.checkAll->setToolTip(QString());
140 m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
146 void EffectStackView2::setupListView()
149 m_monitorSceneWanted = false;
150 m_draggedEffect = NULL;
151 m_draggedGroup = NULL;
152 disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
155 QWidget *view = m_ui.container->takeWidget();
160 view = new QWidget(m_ui.container);
161 m_ui.container->setWidget(view);
163 QVBoxLayout *vbox1 = new QVBoxLayout(view);
164 vbox1->setContentsMargins(0, 0, 0, 0);
165 vbox1->setSpacing(0);
167 for (int i = 0; i < m_currentEffectList.count(); i++) {
168 QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
170 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
174 CollapsibleGroup *group = NULL;
175 EffectInfo effectInfo;
176 effectInfo.fromString(d.attribute("kdenlive_info"));
177 if (effectInfo.groupIndex >= 0) {
178 // effect is in a group
179 for (int j = 0; j < vbox1->count(); j++) {
180 CollapsibleGroup *eff = static_cast<CollapsibleGroup *>(vbox1->itemAt(j)->widget());
181 if (eff->isGroup() && eff->groupIndex() == effectInfo.groupIndex) {
188 group = new CollapsibleGroup(effectInfo.groupIndex, i == 0, i == m_currentEffectList.count() - 1, effectInfo, m_ui.container->widget());
190 vbox1->addWidget(group);
191 group->installEventFilter( this );
193 if (effectInfo.groupIndex >= m_groupIndex) m_groupIndex = effectInfo.groupIndex + 1;
197 doc.appendChild(doc.importNode(d, true));
198 kDebug() << "IMPORTED STK: " << doc.toString();*/
201 bool isSelected = false;
202 if (m_effectMetaInfo.trackMode) {
203 info.track = m_trackInfo.type;
204 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
205 info.cropStart = GenTime(0);
206 info.startPos = GenTime(-1);
210 info = m_clipref->info();
213 CollapsibleEffect *currentEffect = new CollapsibleEffect(d, m_currentEffectList.at(i), info, &m_effectMetaInfo, i == m_currentEffectList.count() - 1, view);
214 if (m_effectMetaInfo.trackMode) {
215 isSelected = currentEffect->effectIndex() == 1;
218 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
221 currentEffect->setActive(true);
222 if (currentEffect->needsMonitorEffectScene()) m_monitorSceneWanted = true;
224 m_effects.append(currentEffect);
226 group->addGroupEffect(currentEffect);
228 vbox1->addWidget(currentEffect);
230 connectEffect(currentEffect);
233 if (m_currentEffectList.isEmpty()) {
234 m_ui.labelComment->setHidden(true);
237 // Adjust group effects (up / down buttons)
238 QList<CollapsibleGroup *> allGroups = m_ui.container->widget()->findChildren<CollapsibleGroup *>();
239 for (int i = 0; i < allGroups.count(); i++) {
240 allGroups.at(i)->adjustEffects();
242 connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
245 vbox1->addStretch(10);
246 slotUpdateCheckAllButton();
248 // Wait a little bit for the new layout to be ready, then check if we have a scrollbar
249 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
252 void EffectStackView2::connectEffect(CollapsibleEffect *currentEffect)
255 currentEffect->installEventFilter( this );
256 connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
257 connect(currentEffect, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,QString,QString)));
258 connect(currentEffect, SIGNAL(deleteEffect(const QDomElement)), this , SLOT(slotDeleteEffect(const QDomElement)));
259 connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
260 connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
261 connect(currentEffect, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
262 connect(currentEffect, SIGNAL(effectStateChanged(bool,int,bool)), this, SLOT(slotUpdateEffectState(bool,int,bool)));
263 connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
264 connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
265 connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
266 connect(currentEffect, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
267 connect(currentEffect, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
268 connect(currentEffect, SIGNAL(createRegion(int,KUrl)), this, SLOT(slotCreateRegion(int,KUrl)));
269 connect(currentEffect, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
272 void EffectStackView2::slotCheckWheelEventFilter()
274 // If the effect stack widget has no scrollbar, we will not filter the
275 // mouse wheel events, so that user can easily adjust effect params
276 bool filterWheelEvent = false;
277 if (m_ui.container->verticalScrollBar() && m_ui.container->verticalScrollBar()->isVisible()) {
278 // widget has scroll bar,
279 filterWheelEvent = true;
281 for (int i = 0; i < m_effects.count(); i++) {
282 m_effects.at(i)->filterWheelEvent = filterWheelEvent;
286 void EffectStackView2::resizeEvent ( QResizeEvent * event )
288 slotCheckWheelEventFilter();
289 QWidget::resizeEvent(event);
292 bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
294 // Check if user clicked in an effect's top bar to start dragging it
295 if (e->type() == QEvent::MouseButtonPress) {
296 m_draggedEffect = qobject_cast<CollapsibleEffect*>(o);
297 if (m_draggedEffect) {
298 QMouseEvent *me = static_cast<QMouseEvent *>(e);
299 if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse())) {
300 m_clickPoint = me->globalPos();
303 m_clickPoint = QPoint();
304 m_draggedEffect = NULL;
309 m_draggedGroup = qobject_cast<CollapsibleGroup*>(o);
310 if (m_draggedGroup) {
311 QMouseEvent *me = static_cast<QMouseEvent *>(e);
312 if (me->button() == Qt::LeftButton && (m_draggedGroup->frame->underMouse() || m_draggedGroup->title()->underMouse()))
313 m_clickPoint = me->globalPos();
315 m_clickPoint = QPoint();
316 m_draggedGroup = NULL;
322 /*if (e->type() == QEvent::MouseMove) {
323 if (qobject_cast<CollapsibleEffect*>(o)) {
324 QMouseEvent *me = static_cast<QMouseEvent *>(e);
325 if (me->buttons() != Qt::LeftButton) {
335 return QWidget::eventFilter(o, e);
338 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
340 if (m_draggedEffect || m_draggedGroup) {
341 if ((event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
347 void EffectStackView2::mouseReleaseEvent(QMouseEvent * event)
349 m_draggedEffect = NULL;
350 m_draggedGroup = NULL;
351 QWidget::mouseReleaseEvent(event);
354 void EffectStackView2::startDrag()
356 // The data to be transferred by the drag and drop operation is contained in a QMimeData object
359 if (m_draggedEffect) {
360 QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
361 doc.appendChild(doc.importNode(effect, true));
362 pixmap = QPixmap::grabWidget(m_draggedEffect->title);
364 else if (m_draggedGroup) {
365 doc = m_draggedGroup->effectsData();
366 pixmap = QPixmap::grabWidget(m_draggedGroup->title());
369 QDrag *drag = new QDrag(this);
370 drag->setPixmap(pixmap);
371 QMimeData *mime = new QMimeData;
373 data.append(doc.toString().toUtf8());
374 mime->setData("kdenlive/effectslist", data);
376 // Assign ownership of the QMimeData object to the QDrag object.
377 drag->setMimeData(mime);
378 // Start the drag and drop operation
379 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
383 void EffectStackView2::slotUpdateEffectState(bool disable, int index, bool updateMainStatus)
385 if (m_effectMetaInfo.trackMode)
386 emit changeEffectState(NULL, m_trackindex, index, disable);
388 emit changeEffectState(m_clipref, -1, index, disable);
389 if (updateMainStatus) slotUpdateCheckAllButton();
393 void EffectStackView2::raiseWindow(QWidget* dock)
395 if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
400 void EffectStackView2::slotSeekTimeline(int pos)
402 if (m_effectMetaInfo.trackMode) {
403 emit seekTimeline(pos);
404 } else if (m_clipref) {
405 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
410 /*void EffectStackView2::slotRegionChanged()
412 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
415 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
417 if (m_monitorSceneWanted) {
418 if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
419 if (!m_effectMetaInfo.monitor->effectSceneDisplayed()) {
420 m_effectMetaInfo.monitor->slotShowEffectScene(true);
423 m_effectMetaInfo.monitor->slotShowEffectScene(false);
427 m_effectMetaInfo.monitor->slotShowEffectScene(false);
431 int EffectStackView2::isTrackMode(bool *ok) const
433 *ok = m_effectMetaInfo.trackMode;
437 void EffectStackView2::clear()
440 m_monitorSceneWanted = false;
441 QWidget *view = m_ui.container->takeWidget();
445 m_ui.checkAll->setToolTip(QString());
446 m_ui.checkAll->setText(QString());
447 m_ui.checkAll->setEnabled(false);
448 m_ui.labelComment->setText(QString());
452 void EffectStackView2::slotCheckAll(int state)
454 if (state == Qt::PartiallyChecked) {
456 m_ui.checkAll->blockSignals(true);
457 m_ui.checkAll->setCheckState(Qt::Checked);
458 m_ui.checkAll->blockSignals(false);
461 bool disabled = state == Qt::Unchecked;
462 for (int i = 0; i < m_effects.count(); i++) {
463 if (!m_effects.at(i)->isGroup()) {
464 m_effects.at(i)->slotEnable(disabled, false);
469 void EffectStackView2::slotUpdateCheckAllButton()
471 bool hasEnabled = false;
472 bool hasDisabled = false;
474 for (int i = 0; i < m_effects.count(); i++) {
475 if (!m_effects.at(i)->enabledButton->isChecked()) hasEnabled = true;
476 else hasDisabled = true;
479 m_ui.checkAll->blockSignals(true);
480 if (hasEnabled && hasDisabled)
481 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
483 m_ui.checkAll->setCheckState(Qt::Checked);
485 m_ui.checkAll->setCheckState(Qt::Unchecked);
486 m_ui.checkAll->blockSignals(false);
489 void EffectStackView2::deleteCurrentEffect()
491 for (int i = 0; i < m_effects.count(); i++) {
492 if (m_effects.at(i)->isActive()) {
493 slotDeleteEffect(m_effects.at(i)->effect());
499 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
501 m_effectMetaInfo.profile = profile;
502 m_effectMetaInfo.timecode = t;
505 void EffectStackView2::updateTimecodeFormat()
507 for (int i = 0; i< m_effects.count(); i++)
508 m_effects.at(i)->updateTimecodeFormat();
511 CollapsibleEffect *EffectStackView2::getEffectByIndex(int ix)
513 for (int i = 0; i< m_effects.count(); i++) {
514 if (m_effects.at(i)->effectIndex() == ix) {
515 return m_effects.at(i);
521 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
523 if (m_effectMetaInfo.trackMode)
524 emit updateEffect(NULL, m_trackindex, old, e, ix,false);
525 else if (m_clipref) {
526 emit updateEffect(m_clipref, -1, old, e, ix, false);
527 // Make sure the changed effect is currently displayed
528 slotSetCurrentEffect(ix);
530 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
533 void EffectStackView2::slotSetCurrentEffect(int ix)
535 if (m_clipref && ix != m_clipref->selectedEffectIndex()) {
536 m_clipref->setSelectedEffect(ix);
537 for (int i = 0; i < m_effects.count(); i++) {
538 if (m_effects.at(i)->effectIndex() == ix) {
539 if (m_effects.at(i)->isActive()) return;
540 m_effects.at(i)->setActive(true);
541 m_monitorSceneWanted = m_effects.at(i)->needsMonitorEffectScene();
542 slotCheckMonitorPosition(m_effectMetaInfo.monitor->render->seekFramePosition());
543 m_ui.labelComment->setText(i18n(m_effects.at(i)->effect().firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
544 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
546 else m_effects.at(i)->setActive(false);
551 void EffectStackView2::slotDeleteGroup(QDomDocument doc)
553 QDomNodeList effects = doc.elementsByTagName("effect");
554 ClipItem * clip = NULL;
556 if (m_effectMetaInfo.trackMode) {
564 for (int i = 0; i < effects.count(); i++)
565 emit removeEffect(clip, ix, effects.at(i).toElement());
568 void EffectStackView2::slotDeleteEffect(const QDomElement effect)
570 if (m_effectMetaInfo.trackMode)
571 emit removeEffect(NULL, m_trackindex, effect);
573 emit removeEffect(m_clipref, -1, effect);
576 void EffectStackView2::slotAddEffect(QDomElement effect)
578 emit addEffect(m_clipref, effect);
581 void EffectStackView2::slotMoveEffectUp(QList <int> indexes, bool up)
583 if (up && indexes.first() <= 1) return;
584 if (!up && indexes.last() >= m_currentEffectList.count()) return;
587 endPos = indexes.first() - 1;
590 endPos = indexes.last() + 1;
592 if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, indexes, endPos);
593 else emit changeEffectPosition(m_clipref, -1, indexes, endPos);
596 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
598 if (!m_clipref) return;
599 emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, finalFilterName, consumer, consumerParams, properties);
602 void EffectStackView2::slotResetEffect(int ix)
604 QDomElement old = m_currentEffectList.itemFromIndex(ix);
606 QString effectId = old.attribute("id");
607 QMap<QString, EffectsList*> effectLists;
608 effectLists["audio"] = &MainWindow::audioEffects;
609 effectLists["video"] = &MainWindow::videoEffects;
610 effectLists["custom"] = &MainWindow::customEffects;
611 foreach(const QString &type, effectLists.keys()) {
612 EffectsList *list = effectLists[type];
613 dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
614 if (!dom.isNull()) break;
617 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
618 if (m_effectMetaInfo.trackMode) {
619 EffectsList::setParameter(dom, "in", QString::number(0));
620 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
622 info.track = m_trackInfo.type;
623 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
624 info.cropStart = GenTime(0);
625 info.startPos = GenTime(-1);
627 m_effects.at(ix)->updateWidget(info, dom, &m_effectMetaInfo);
628 emit updateEffect(NULL, m_trackindex, old, dom, ix,false);
630 m_clipref->initEffect(dom);
631 for (int i = 0; i < m_effects.count(); i++) {
632 if (m_effects.at(i)->effectIndex() == ix) {
633 m_effects.at(i)->updateWidget(m_clipref->info(), dom, &m_effectMetaInfo);
637 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
638 emit updateEffect(m_clipref, -1, old, dom, ix,false);
642 emit showComments(m_ui.buttonShowComments->isChecked());
643 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
646 void EffectStackView2::slotShowComments()
648 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
649 emit showComments(m_ui.buttonShowComments->isChecked());
652 void EffectStackView2::slotCreateRegion(int ix, KUrl url)
654 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
655 QDomElement neweffect = oldeffect.cloneNode().toElement();
656 QDomElement region = MainWindow::videoEffects.getEffectByTag("region", "region").cloneNode().toElement();
657 region.appendChild(region.ownerDocument().importNode(neweffect, true));
658 region.setAttribute("kdenlive_ix", ix);
659 EffectsList::setParameter(region, "resource", url.path());
660 if (m_effectMetaInfo.trackMode)
661 emit updateEffect(NULL, m_trackindex, oldeffect, region, ix,false);
662 else if (m_clipref) {
663 emit updateEffect(m_clipref, -1, oldeffect, region, ix, false);
664 // Make sure the changed effect is currently displayed
665 //slotSetCurrentEffect(ix);
667 // refresh effect stack
669 bool isSelected = false;
670 if (m_effectMetaInfo.trackMode) {
671 info.track = m_trackInfo.type;
672 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
673 info.cropStart = GenTime(0);
674 info.startPos = GenTime(-1);
678 info = m_clipref->info();
680 CollapsibleEffect *current = getEffectByIndex(ix);
681 m_effects.removeAll(current);
682 current->setEnabled(false);
683 m_currentEffectList.removeAt(ix);
684 m_currentEffectList.insert(region);
685 current->deleteLater();
686 CollapsibleEffect *currentEffect = new CollapsibleEffect(region, m_currentEffectList.itemFromIndex(ix), info, &m_effectMetaInfo, ix == m_currentEffectList.count() - 1, m_ui.container->widget());
687 connectEffect(currentEffect);
689 if (m_effectMetaInfo.trackMode) {
690 isSelected = currentEffect->effectIndex() == 1;
693 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
695 if (isSelected) currentEffect->setActive(true);
696 m_effects.append(currentEffect);
697 // TODO: region in group?
699 // group->addGroupEffect(currentEffect);
701 QVBoxLayout *vbox = static_cast <QVBoxLayout *> (m_ui.container->widget()->layout());
702 vbox->insertWidget(ix, currentEffect);
706 currentEffect->installEventFilter( this );
708 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
712 void EffectStackView2::slotCreateGroup(int ix)
714 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
715 QDomElement neweffect = oldeffect.cloneNode().toElement();
716 EffectInfo effectinfo;
717 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
718 effectinfo.groupIndex = m_groupIndex;
719 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
722 if (m_effectMetaInfo.trackMode) {
723 info.track = m_trackInfo.type;
724 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
725 info.cropStart = GenTime(0);
726 info.startPos = GenTime(-1);
728 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix, false);
730 emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix, false);
733 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
735 CollapsibleEffect *effectToMove = NULL;
736 for (int i = 0; i < m_effects.count(); i++) {
737 if (m_effects.at(i)->effectIndex() == ix) {
738 effectToMove = m_effects.at(i);
739 groupPos = l->indexOf(effectToMove);
740 l->removeWidget(effectToMove);
745 CollapsibleGroup *group = new CollapsibleGroup(m_groupIndex, ix == 1, ix == m_currentEffectList.count() - 2, effectinfo, m_ui.container->widget());
748 l->insertWidget(groupPos, group);
749 group->installEventFilter( this );
750 group->addGroupEffect(effectToMove);
753 void EffectStackView2::connectGroup(CollapsibleGroup *group)
755 connect(group, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
756 connect(group, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
757 connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
758 connect(group, SIGNAL(groupRenamed(CollapsibleGroup *)), this , SLOT(slotRenameGroup(CollapsibleGroup*)));
759 connect(group, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
760 connect(group, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
761 connect(group, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
764 void EffectStackView2::slotMoveEffect(QList <int> currentIndexes, int newIndex, int groupIndex, QString groupName)
766 if (currentIndexes.count() == 1) {
767 CollapsibleEffect *effectToMove = getEffectByIndex(currentIndexes.at(0));
768 if (effectToMove == NULL) return;
770 QDomElement oldeffect = effectToMove->effect();
771 QDomElement neweffect = oldeffect.cloneNode().toElement();
773 EffectInfo effectinfo;
774 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
775 effectinfo.groupIndex = groupIndex;
776 effectinfo.groupName = groupName;
777 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
779 if (oldeffect.attribute("kdenlive_info") != effectinfo.toString()) {
780 // effect's group info or collapsed state changed
782 if (m_effectMetaInfo.trackMode) {
783 info.track = m_trackInfo.type;
784 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
785 info.cropStart = GenTime(0);
786 info.startPos = GenTime(-1);
788 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->effectIndex(),false);
790 emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex(),false);
795 // Update effect index with new position
796 if (m_effectMetaInfo.trackMode) {
797 emit changeEffectPosition(NULL, m_trackindex, currentIndexes, newIndex);
800 emit changeEffectPosition(m_clipref, -1, currentIndexes, newIndex);
804 void EffectStackView2::slotUnGroup(CollapsibleGroup* group)
806 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
807 int ix = l->indexOf(group);
808 group->removeGroup(ix, l);
809 group->deleteLater();
812 void EffectStackView2::slotRenameGroup(CollapsibleGroup *group)
814 QList <CollapsibleEffect*> effects = group->effects();
815 for (int i = 0; i < effects.count(); i++) {
816 QDomElement origin = effects.at(i)->effect();
817 QDomElement changed = origin.cloneNode().toElement();
818 changed.setAttribute("kdenlive_info", effects.at(i)->infoString());
819 if (m_effectMetaInfo.trackMode) {
820 emit updateEffect(NULL, m_trackindex, origin, changed, effects.at(i)->effectIndex(),false);
822 emit updateEffect(m_clipref, -1, origin, changed, effects.at(i)->effectIndex(),false);
827 void EffectStackView2::dragEnterEvent(QDragEnterEvent *event)
829 if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
830 event->acceptProposedAction();
834 void EffectStackView2::processDroppedEffect(QDomElement e, QDropEvent *event)
836 int ix = e.attribute("kdenlive_ix").toInt();
837 if (e.tagName() == "effectgroup") {
838 // We are dropping a group, all effects in group should be moved
839 QDomNodeList effects = e.elementsByTagName("effect");
840 if (effects.count() == 0) {
845 info.fromString(effects.at(0).toElement().attribute("kdenlive_info"));
846 if (info.groupIndex < 0) {
847 kDebug()<<"// ADDING EFFECT!!!";
848 // Adding a new group effect to the stack
849 event->setDropAction(Qt::CopyAction);
854 // Moving group: delete all effects and re-add them
856 for (int i = 0; i < effects.count(); i++) {
857 QDomElement effect = effects.at(i).cloneNode().toElement();
858 indexes << effect.attribute("kdenlive_ix").toInt();
860 kDebug()<<"// Moving: "<<indexes<<" TO "<<m_currentEffectList.count();
861 slotMoveEffect(indexes, m_currentEffectList.count(), info.groupIndex, info.groupName);
864 // effect dropped from effects list, add it
865 e.setAttribute("kdenlive_ix", m_currentEffectList.count() + 1);
866 event->setDropAction(Qt::CopyAction);
872 // User is moving an effect
873 slotMoveEffect(QList<int> () << ix, m_currentEffectList.count() + 1, -1);
875 event->setDropAction(Qt::MoveAction);
879 void EffectStackView2::dropEvent(QDropEvent *event)
881 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
882 //event->acceptProposedAction();
884 doc.setContent(effects, true);
885 processDroppedEffect(doc.documentElement(), event);
889 const QString EffectStackView2::getStyleSheet()
891 KColorScheme scheme(QApplication::palette().currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
892 QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
893 QColor hgh = KColorUtils::mix(QApplication::palette().window().color(), selected_bg, 0.2);
894 QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
895 QColor light_bg = scheme.shade(KColorScheme::LightShade);
896 QColor alt_bg = scheme.background(KColorScheme::NormalBackground).color();
901 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()));
903 // effect in group background
904 stylesheet.append(QString("QFrame#decoframesub {border-top:1px solid palette(light);} QFrame#decoframesub[active=\"true\"] {background: %1;}").arg(hgh.name()));
907 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;} "));
910 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);}"));
912 // group effect title bar
913 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);} "));
915 // draggable effect bar content
916 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()));
918 // draggable effect bar
919 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()));
921 // spin box for draggable widget
922 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()));
924 // group editable labels
925 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);} "));
930 #include "effectstackview2.moc"