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 if (!m_effectMetaInfo.trackMode && m_clipref) pos = pos - m_clipref->startPos().frames(KdenliveSettings::project_fps());
90 for (int i = 0; i< m_effects.count(); i++)
91 m_effects.at(i)->slotSyncEffectsPos(pos);
94 void EffectStackView2::slotClipItemSelected(ClipItem* c)
96 if (c && !c->isEnabled()) return;
97 if (c && c == m_clipref) {
102 QString cname = m_clipref->clipName();
103 if (cname.length() > 30) {
104 m_ui.checkAll->setToolTip(i18n("Effects for %1").arg(cname));
106 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "...");
108 m_ui.checkAll->setToolTip(QString());
109 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
111 m_ui.checkAll->setEnabled(true);
112 QString size = c->baseClip()->getProperty("frame_size");
113 double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
114 m_effectMetaInfo.frameSize = QPoint((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
117 if (m_clipref == NULL) {
118 //TODO: clear list, reset paramdesc and info
120 //m_effectedit->transferParamDesc(QDomElement(), info);
125 m_effectMetaInfo.trackMode = false;
126 m_currentEffectList = m_clipref->effectList();
130 void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
133 m_effectMetaInfo.trackMode = true;
134 m_currentEffectList = info.effectsList;
137 m_ui.checkAll->setToolTip(QString());
138 m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
144 void EffectStackView2::setupListView()
147 m_draggedEffect = NULL;
148 m_draggedGroup = NULL;
149 disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
152 QWidget *view = m_ui.container->takeWidget();
157 view = new QWidget(m_ui.container);
158 m_ui.container->setWidget(view);
160 QVBoxLayout *vbox1 = new QVBoxLayout(view);
161 vbox1->setContentsMargins(0, 0, 0, 0);
162 vbox1->setSpacing(0);
164 if (m_currentEffectList.isEmpty()) m_ui.labelComment->setHidden(true);
166 for (int i = 0; i < m_currentEffectList.count(); i++) {
167 QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
169 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
173 CollapsibleGroup *group = NULL;
174 EffectInfo effectInfo;
175 effectInfo.fromString(d.attribute("kdenlive_info"));
176 if (effectInfo.groupIndex >= 0) {
177 // effect is in a group
178 for (int j = 0; j < vbox1->count(); j++) {
179 CollapsibleGroup *eff = static_cast<CollapsibleGroup *>(vbox1->itemAt(j)->widget());
180 if (eff->isGroup() && eff->groupIndex() == effectInfo.groupIndex) {
187 group = new CollapsibleGroup(effectInfo.groupIndex, i == 0, i == m_currentEffectList.count() - 1, effectInfo, m_ui.container->widget());
189 vbox1->addWidget(group);
190 group->installEventFilter( this );
192 if (effectInfo.groupIndex >= m_groupIndex) m_groupIndex = effectInfo.groupIndex + 1;
196 doc.appendChild(doc.importNode(d, true));
197 kDebug() << "IMPORTED STK: " << doc.toString();*/
200 bool isSelected = false;
201 if (m_effectMetaInfo.trackMode) {
202 info.track = m_trackInfo.type;
203 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
204 info.cropStart = GenTime(0);
205 info.startPos = GenTime(-1);
209 info = m_clipref->info();
212 CollapsibleEffect *currentEffect = new CollapsibleEffect(d, m_currentEffectList.at(i), info, &m_effectMetaInfo, i == m_currentEffectList.count() - 1, view);
213 if (m_effectMetaInfo.trackMode) {
214 isSelected = currentEffect->effectIndex() == 1;
217 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
219 if (isSelected) currentEffect->setActive(true);
220 m_effects.append(currentEffect);
222 group->addGroupEffect(currentEffect);
224 vbox1->addWidget(currentEffect);
226 connectEffect(currentEffect);
229 // Adjust group effects (up / down buttons)
230 QList<CollapsibleGroup *> allGroups = m_ui.container->widget()->findChildren<CollapsibleGroup *>();
231 for (int i = 0; i < allGroups.count(); i++) {
232 allGroups.at(i)->adjustEffects();
235 vbox1->addStretch(10);
236 slotUpdateCheckAllButton();
237 connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
239 // Wait a little bit for the new layout to be ready, then check if we have a scrollbar
240 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
243 void EffectStackView2::connectEffect(CollapsibleEffect *currentEffect)
246 currentEffect->installEventFilter( this );
247 connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
248 connect(currentEffect, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,QString,QString)));
249 connect(currentEffect, SIGNAL(deleteEffect(const QDomElement)), this , SLOT(slotDeleteEffect(const QDomElement)));
250 connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
251 connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
252 connect(currentEffect, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
253 connect(currentEffect, SIGNAL(effectStateChanged(bool,int,bool)), this, SLOT(slotUpdateEffectState(bool,int,bool)));
254 connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
255 connect(currentEffect, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
256 connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
257 connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
258 connect(currentEffect, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
259 connect(currentEffect, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
260 connect(currentEffect, SIGNAL(createRegion(int,KUrl)), this, SLOT(slotCreateRegion(int,KUrl)));
261 connect(currentEffect, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
264 void EffectStackView2::slotCheckWheelEventFilter()
266 // If the effect stack widget has no scrollbar, we will not filter the
267 // mouse wheel events, so that user can easily adjust effect params
268 bool filterWheelEvent = false;
269 if (m_ui.container->verticalScrollBar() && m_ui.container->verticalScrollBar()->isVisible()) {
270 // widget has scroll bar,
271 filterWheelEvent = true;
273 for (int i = 0; i < m_effects.count(); i++) {
274 m_effects.at(i)->filterWheelEvent = filterWheelEvent;
278 void EffectStackView2::resizeEvent ( QResizeEvent * event )
280 slotCheckWheelEventFilter();
281 QWidget::resizeEvent(event);
284 bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
286 // Check if user clicked in an effect's top bar to start dragging it
287 if (e->type() == QEvent::MouseButtonPress) {
288 m_draggedEffect = qobject_cast<CollapsibleEffect*>(o);
289 if (m_draggedEffect) {
290 QMouseEvent *me = static_cast<QMouseEvent *>(e);
291 if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse())) {
292 m_clickPoint = me->globalPos();
295 m_clickPoint = QPoint();
296 m_draggedEffect = NULL;
301 m_draggedGroup = qobject_cast<CollapsibleGroup*>(o);
302 if (m_draggedGroup) {
303 QMouseEvent *me = static_cast<QMouseEvent *>(e);
304 if (me->button() == Qt::LeftButton && (m_draggedGroup->frame->underMouse() || m_draggedGroup->title()->underMouse()))
305 m_clickPoint = me->globalPos();
307 m_clickPoint = QPoint();
308 m_draggedGroup = NULL;
314 /*if (e->type() == QEvent::MouseMove) {
315 if (qobject_cast<CollapsibleEffect*>(o)) {
316 QMouseEvent *me = static_cast<QMouseEvent *>(e);
317 if (me->buttons() != Qt::LeftButton) {
327 return QWidget::eventFilter(o, e);
330 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
332 if (m_draggedEffect || m_draggedGroup) {
333 if ((event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
339 void EffectStackView2::mouseReleaseEvent(QMouseEvent * event)
341 m_draggedEffect = NULL;
342 m_draggedGroup = NULL;
343 QWidget::mouseReleaseEvent(event);
346 void EffectStackView2::startDrag()
348 // The data to be transferred by the drag and drop operation is contained in a QMimeData object
351 if (m_draggedEffect) {
352 QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
353 doc.appendChild(doc.importNode(effect, true));
354 pixmap = QPixmap::grabWidget(m_draggedEffect->title);
356 else if (m_draggedGroup) {
357 doc = m_draggedGroup->effectsData();
358 pixmap = QPixmap::grabWidget(m_draggedGroup->title());
361 QDrag *drag = new QDrag(this);
362 drag->setPixmap(pixmap);
363 QMimeData *mime = new QMimeData;
365 data.append(doc.toString().toUtf8());
366 mime->setData("kdenlive/effectslist", data);
368 // Assign ownership of the QMimeData object to the QDrag object.
369 drag->setMimeData(mime);
370 // Start the drag and drop operation
371 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
375 void EffectStackView2::slotUpdateEffectState(bool disable, int index, bool updateMainStatus)
377 if (m_effectMetaInfo.trackMode)
378 emit changeEffectState(NULL, m_trackindex, index, disable);
380 emit changeEffectState(m_clipref, -1, index, disable);
381 if (updateMainStatus) slotUpdateCheckAllButton();
385 void EffectStackView2::raiseWindow(QWidget* dock)
387 if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
392 void EffectStackView2::slotSeekTimeline(int pos)
394 if (m_effectMetaInfo.trackMode) {
395 emit seekTimeline(pos);
396 } else if (m_clipref) {
397 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
402 /*void EffectStackView2::slotRegionChanged()
404 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
407 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
409 if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
410 if (!m_effectMetaInfo.monitor->effectSceneDisplayed())
411 //if (!m_effectMetaInfo.monitor->getEffectEdit()->getScene()->views().at(0)->isVisible())
412 m_effectMetaInfo.monitor->slotShowEffectScene(true);
414 m_effectMetaInfo.monitor->slotShowEffectScene(false);
418 int EffectStackView2::isTrackMode(bool *ok) const
420 *ok = m_effectMetaInfo.trackMode;
424 void EffectStackView2::clear()
427 QWidget *view = m_ui.container->takeWidget();
431 m_ui.checkAll->setToolTip(QString());
432 m_ui.checkAll->setText(QString());
433 m_ui.checkAll->setEnabled(false);
434 m_ui.labelComment->setText(QString());
438 void EffectStackView2::slotCheckAll(int state)
440 if (state == Qt::PartiallyChecked) {
442 m_ui.checkAll->blockSignals(true);
443 m_ui.checkAll->setCheckState(Qt::Checked);
444 m_ui.checkAll->blockSignals(false);
447 bool disabled = state == Qt::Unchecked;
448 for (int i = 0; i < m_effects.count(); i++) {
449 if (!m_effects.at(i)->isGroup()) {
450 m_effects.at(i)->slotEnable(disabled, false);
455 void EffectStackView2::slotUpdateCheckAllButton()
457 bool hasEnabled = false;
458 bool hasDisabled = false;
460 for (int i = 0; i < m_effects.count(); i++) {
461 if (!m_effects.at(i)->enabledButton->isChecked()) hasEnabled = true;
462 else hasDisabled = true;
465 m_ui.checkAll->blockSignals(true);
466 if (hasEnabled && hasDisabled)
467 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
469 m_ui.checkAll->setCheckState(Qt::Checked);
471 m_ui.checkAll->setCheckState(Qt::Unchecked);
472 m_ui.checkAll->blockSignals(false);
475 void EffectStackView2::deleteCurrentEffect()
477 for (int i = 0; i < m_effects.count(); i++) {
478 if (m_effects.at(i)->isActive()) {
479 slotDeleteEffect(m_effects.at(i)->effect());
485 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
487 m_effectMetaInfo.profile = profile;
488 m_effectMetaInfo.timecode = t;
491 void EffectStackView2::updateTimecodeFormat()
493 for (int i = 0; i< m_effects.count(); i++)
494 m_effects.at(i)->updateTimecodeFormat();
497 CollapsibleEffect *EffectStackView2::getEffectByIndex(int ix)
499 for (int i = 0; i< m_effects.count(); i++) {
500 if (m_effects.at(i)->effectIndex() == ix) {
501 return m_effects.at(i);
507 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
509 if (m_effectMetaInfo.trackMode)
510 emit updateEffect(NULL, m_trackindex, old, e, ix,false);
511 else if (m_clipref) {
512 emit updateEffect(m_clipref, -1, old, e, ix, false);
513 // Make sure the changed effect is currently displayed
514 slotSetCurrentEffect(ix);
516 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
519 void EffectStackView2::slotSetCurrentEffect(int ix)
521 if (m_clipref && ix != m_clipref->selectedEffectIndex()) {
522 m_clipref->setSelectedEffect(ix);
523 for (int i = 0; i < m_effects.count(); i++) {
524 if (m_effects.at(i)->effectIndex() == ix) {
525 m_effects.at(i)->setActive(true);
526 m_effectMetaInfo.monitor->slotShowEffectScene(m_effects.at(i)->needsMonitorEffectScene());
527 m_ui.labelComment->setText(i18n(m_effects.at(i)->effect().firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
528 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
530 else m_effects.at(i)->setActive(false);
535 void EffectStackView2::slotDeleteGroup(QDomDocument doc)
537 QDomNodeList effects = doc.elementsByTagName("effect");
538 ClipItem * clip = NULL;
540 if (m_effectMetaInfo.trackMode) {
548 for (int i = 0; i < effects.count(); i++)
549 emit removeEffect(clip, ix, effects.at(i).toElement());
552 void EffectStackView2::slotDeleteEffect(const QDomElement effect)
554 if (m_effectMetaInfo.trackMode)
555 emit removeEffect(NULL, m_trackindex, effect);
557 emit removeEffect(m_clipref, -1, effect);
560 void EffectStackView2::slotAddEffect(QDomElement effect)
562 emit addEffect(m_clipref, effect);
565 void EffectStackView2::slotMoveEffectUp(QList <int> indexes, bool up)
567 if (up && indexes.first() <= 1) return;
568 if (!up && indexes.last() >= m_currentEffectList.count()) return;
571 endPos = indexes.first() - 1;
574 endPos = indexes.last() + 1;
576 if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, indexes, endPos);
577 else emit changeEffectPosition(m_clipref, -1, indexes, endPos);
580 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
582 if (!m_clipref) return;
583 emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, finalFilterName, consumer, consumerParams, properties);
586 void EffectStackView2::slotResetEffect(int ix)
588 QDomElement old = m_currentEffectList.itemFromIndex(ix);
590 QString effectId = old.attribute("id");
591 QMap<QString, EffectsList*> effectLists;
592 effectLists["audio"] = &MainWindow::audioEffects;
593 effectLists["video"] = &MainWindow::videoEffects;
594 effectLists["custom"] = &MainWindow::customEffects;
595 foreach(const QString &type, effectLists.keys()) {
596 EffectsList *list = effectLists[type];
597 dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
598 if (!dom.isNull()) break;
601 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
602 if (m_effectMetaInfo.trackMode) {
603 EffectsList::setParameter(dom, "in", QString::number(0));
604 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
606 info.track = m_trackInfo.type;
607 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
608 info.cropStart = GenTime(0);
609 info.startPos = GenTime(-1);
611 m_effects.at(ix)->updateWidget(info, dom, &m_effectMetaInfo);
612 emit updateEffect(NULL, m_trackindex, old, dom, ix,false);
614 m_clipref->initEffect(dom);
615 for (int i = 0; i < m_effects.count(); i++) {
616 if (m_effects.at(i)->effectIndex() == ix) {
617 m_effects.at(i)->updateWidget(m_clipref->info(), dom, &m_effectMetaInfo);
621 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
622 emit updateEffect(m_clipref, -1, old, dom, ix,false);
626 emit showComments(m_ui.buttonShowComments->isChecked());
627 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
630 void EffectStackView2::slotShowComments()
632 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
633 emit showComments(m_ui.buttonShowComments->isChecked());
636 void EffectStackView2::slotCreateRegion(int ix, KUrl url)
638 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
639 QDomElement neweffect = oldeffect.cloneNode().toElement();
640 QDomElement region = MainWindow::videoEffects.getEffectByTag("region", "region").cloneNode().toElement();
641 region.appendChild(region.ownerDocument().importNode(neweffect, true));
642 region.setAttribute("kdenlive_ix", ix);
643 EffectsList::setParameter(region, "resource", url.path());
644 if (m_effectMetaInfo.trackMode)
645 emit updateEffect(NULL, m_trackindex, oldeffect, region, ix,false);
646 else if (m_clipref) {
647 emit updateEffect(m_clipref, -1, oldeffect, region, ix, false);
648 // Make sure the changed effect is currently displayed
649 //slotSetCurrentEffect(ix);
651 // refresh effect stack
653 bool isSelected = false;
654 if (m_effectMetaInfo.trackMode) {
655 info.track = m_trackInfo.type;
656 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
657 info.cropStart = GenTime(0);
658 info.startPos = GenTime(-1);
662 info = m_clipref->info();
664 CollapsibleEffect *current = getEffectByIndex(ix);
665 m_effects.removeAll(current);
666 current->setEnabled(false);
667 m_currentEffectList.removeAt(ix);
668 m_currentEffectList.insert(region);
669 current->deleteLater();
670 CollapsibleEffect *currentEffect = new CollapsibleEffect(region, m_currentEffectList.itemFromIndex(ix), info, &m_effectMetaInfo, ix == m_currentEffectList.count() - 1, m_ui.container->widget());
671 connectEffect(currentEffect);
673 if (m_effectMetaInfo.trackMode) {
674 isSelected = currentEffect->effectIndex() == 1;
677 isSelected = currentEffect->effectIndex() == m_clipref->selectedEffectIndex();
679 if (isSelected) currentEffect->setActive(true);
680 m_effects.append(currentEffect);
681 // TODO: region in group?
683 // group->addGroupEffect(currentEffect);
685 QVBoxLayout *vbox = static_cast <QVBoxLayout *> (m_ui.container->widget()->layout());
686 vbox->insertWidget(ix, currentEffect);
690 currentEffect->installEventFilter( this );
692 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
696 void EffectStackView2::slotCreateGroup(int ix)
698 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
699 QDomElement neweffect = oldeffect.cloneNode().toElement();
700 EffectInfo effectinfo;
701 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
702 effectinfo.groupIndex = m_groupIndex;
703 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
706 if (m_effectMetaInfo.trackMode) {
707 info.track = m_trackInfo.type;
708 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
709 info.cropStart = GenTime(0);
710 info.startPos = GenTime(-1);
712 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix, false);
714 emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix, false);
717 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
719 CollapsibleEffect *effectToMove = NULL;
720 for (int i = 0; i < m_effects.count(); i++) {
721 if (m_effects.at(i)->effectIndex() == ix) {
722 effectToMove = m_effects.at(i);
723 groupPos = l->indexOf(effectToMove);
724 l->removeWidget(effectToMove);
729 CollapsibleGroup *group = new CollapsibleGroup(m_groupIndex, ix == 1, ix == m_currentEffectList.count() - 2, effectinfo, m_ui.container->widget());
732 l->insertWidget(groupPos, group);
733 group->installEventFilter( this );
734 group->addGroupEffect(effectToMove);
737 void EffectStackView2::connectGroup(CollapsibleGroup *group)
739 connect(group, SIGNAL(moveEffect(QList<int>,int,int,QString)), this , SLOT(slotMoveEffect(QList<int>,int,int,QString)));
740 connect(group, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
741 connect(group, SIGNAL(unGroup(CollapsibleGroup*)), this , SLOT(slotUnGroup(CollapsibleGroup*)));
742 connect(group, SIGNAL(groupRenamed(CollapsibleGroup *)), this , SLOT(slotRenameGroup(CollapsibleGroup*)));
743 connect(group, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
744 connect(group, SIGNAL(deleteGroup(QDomDocument)), this , SLOT(slotDeleteGroup(QDomDocument)));
745 connect(group, SIGNAL(changeEffectPosition(QList <int>,bool)), this , SLOT(slotMoveEffectUp(QList <int>,bool)));
748 void EffectStackView2::slotMoveEffect(QList <int> currentIndexes, int newIndex, int groupIndex, QString groupName)
750 if (currentIndexes.count() == 1) {
751 CollapsibleEffect *effectToMove = getEffectByIndex(currentIndexes.at(0));
752 if (effectToMove == NULL) return;
754 QDomElement oldeffect = effectToMove->effect();
755 QDomElement neweffect = oldeffect.cloneNode().toElement();
757 EffectInfo effectinfo;
758 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
759 effectinfo.groupIndex = groupIndex;
760 effectinfo.groupName = groupName;
761 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
763 if (oldeffect.attribute("kdenlive_info") != effectinfo.toString()) {
764 // effect's group info or collapsed state changed
766 if (m_effectMetaInfo.trackMode) {
767 info.track = m_trackInfo.type;
768 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
769 info.cropStart = GenTime(0);
770 info.startPos = GenTime(-1);
772 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->effectIndex(),false);
774 emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex(),false);
779 // Update effect index with new position
780 if (m_effectMetaInfo.trackMode) {
781 emit changeEffectPosition(NULL, m_trackindex, currentIndexes, newIndex);
784 emit changeEffectPosition(m_clipref, -1, currentIndexes, newIndex);
788 void EffectStackView2::slotUnGroup(CollapsibleGroup* group)
790 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
791 int ix = l->indexOf(group);
792 group->removeGroup(ix, l);
793 group->deleteLater();
796 void EffectStackView2::slotRenameGroup(CollapsibleGroup *group)
798 QList <CollapsibleEffect*> effects = group->effects();
799 for (int i = 0; i < effects.count(); i++) {
800 QDomElement origin = effects.at(i)->effect();
801 QDomElement changed = origin.cloneNode().toElement();
802 changed.setAttribute("kdenlive_info", effects.at(i)->infoString());
803 if (m_effectMetaInfo.trackMode) {
804 emit updateEffect(NULL, m_trackindex, origin, changed, effects.at(i)->effectIndex(),false);
806 emit updateEffect(m_clipref, -1, origin, changed, effects.at(i)->effectIndex(),false);
811 void EffectStackView2::dragEnterEvent(QDragEnterEvent *event)
813 if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
814 event->acceptProposedAction();
818 void EffectStackView2::processDroppedEffect(QDomElement e, QDropEvent *event)
820 int ix = e.attribute("kdenlive_ix").toInt();
821 if (e.tagName() == "effectgroup") {
822 // We are dropping a group, all effects in group should be moved
823 QDomNodeList effects = e.elementsByTagName("effect");
824 if (effects.count() == 0) {
829 info.fromString(effects.at(0).toElement().attribute("kdenlive_info"));
830 if (info.groupIndex < 0) {
831 kDebug()<<"// ADDING EFFECT!!!";
832 // Adding a new group effect to the stack
833 event->setDropAction(Qt::CopyAction);
838 // Moving group: delete all effects and re-add them
840 for (int i = 0; i < effects.count(); i++) {
841 QDomElement effect = effects.at(i).cloneNode().toElement();
842 indexes << effect.attribute("kdenlive_ix").toInt();
844 kDebug()<<"// Moving: "<<indexes<<" TO "<<m_currentEffectList.count();
845 slotMoveEffect(indexes, m_currentEffectList.count(), info.groupIndex, info.groupName);
848 // effect dropped from effects list, add it
849 e.setAttribute("kdenlive_ix", m_currentEffectList.count() + 1);
850 event->setDropAction(Qt::CopyAction);
856 // User is moving an effect
857 slotMoveEffect(QList<int> () << ix, m_currentEffectList.count() + 1, -1);
859 event->setDropAction(Qt::MoveAction);
863 void EffectStackView2::dropEvent(QDropEvent *event)
865 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
866 //event->acceptProposedAction();
868 doc.setContent(effects, true);
869 processDroppedEffect(doc.documentElement(), event);
873 const QString EffectStackView2::getStyleSheet()
875 KColorScheme scheme(QApplication::palette().currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
876 QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
877 QColor hgh = KColorUtils::mix(QApplication::palette().window().color(), selected_bg, 0.2);
878 QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
879 QColor light_bg = scheme.shade(KColorScheme::LightShade);
880 QColor alt_bg = scheme.background(KColorScheme::NormalBackground).color();
885 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()));
887 // effect in group background
888 stylesheet.append(QString("QFrame#decoframesub {border-top:1px solid palette(light);} QFrame#decoframesub[active=\"true\"] {background: %1;}").arg(hgh.name()));
891 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;} "));
894 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);}"));
896 // group effect title bar
897 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);} "));
899 // draggable effect bar content
900 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()));
902 // draggable effect bar
903 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()));
905 // spin box for draggable widget
906 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()));
908 // group editable labels
909 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);} "));
914 #include "effectstackview2.moc"