1 /***************************************************************************
2 effecstackview.cpp2 - description
5 copyright : (C) 2008 by Marco Gittler
6 email : g.marco@freenet.de
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"
32 #include <KMessageBox>
33 #include <KStandardDirs>
34 #include <KFileDialog>
35 #include <KColorScheme>
38 #include <QTextStream>
40 #include <QInputDialog>
44 EffectStackView2::EffectStackView2(Monitor *monitor, QWidget *parent) :
48 m_draggedEffect(NULL),
51 m_effectMetaInfo.trackMode = false;
52 m_effectMetaInfo.monitor = monitor;
53 m_effects = QList <CollapsibleEffect*>();
56 setFont(KGlobalSettings::smallestReadableFont());
57 m_ui.checkAll->setToolTip(i18n("Enable/Disable all effects"));
58 m_ui.buttonShowComments->setIcon(KIcon("help-about"));
59 m_ui.buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
61 connect(m_ui.checkAll, SIGNAL(stateChanged(int)), this, SLOT(slotCheckAll(int)));
62 connect(m_ui.buttonShowComments, SIGNAL(clicked()), this, SLOT(slotShowComments()));
63 m_ui.labelComment->setHidden(true);
68 setStyleSheet(CollapsibleEffect::getStyleSheet(palette()));
71 EffectStackView2::~EffectStackView2()
76 void EffectStackView2::slotRenderPos(int pos)
78 if (m_effects.isEmpty()) return;
79 if (!m_effectMetaInfo.trackMode && m_clipref) pos = pos - m_clipref->startPos().frames(KdenliveSettings::project_fps());
81 for (int i = 0; i< m_effects.count(); i++)
82 m_effects.at(i)->slotSyncEffectsPos(pos);
85 void EffectStackView2::slotClipItemSelected(ClipItem* c, int ix)
87 if (c && !c->isEnabled()) return;
88 if (c && c == m_clipref) {
93 QString cname = m_clipref->clipName();
94 if (cname.length() > 30) {
95 m_ui.checkAll->setToolTip(i18n("Effects for %1").arg(cname));
97 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "...");
99 m_ui.checkAll->setToolTip(QString());
100 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
102 m_ui.checkAll->setEnabled(true);
103 ix = c->selectedEffectIndex();
104 QString size = c->baseClip()->getProperty("frame_size");
105 double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
106 m_effectMetaInfo.frameSize = QPoint((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
111 if (m_clipref == NULL) {
112 //TODO: clear list, reset paramdesc and info
114 //m_effectedit->transferParamDesc(QDomElement(), info);
119 m_effectMetaInfo.trackMode = false;
120 m_currentEffectList = m_clipref->effectList();
124 void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
127 m_effectMetaInfo.trackMode = true;
128 m_currentEffectList = info.effectsList;
131 m_ui.checkAll->setToolTip(QString());
132 m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
138 void EffectStackView2::setupListView(int ix)
141 m_draggedEffect = NULL;
142 disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
145 QWidget *view = m_ui.container->takeWidget();
150 view = new QWidget(m_ui.container);
151 m_ui.container->setWidget(view);
153 QVBoxLayout *vbox1 = new QVBoxLayout(view);
154 vbox1->setContentsMargins(0, 0, 0, 0);
155 vbox1->setSpacing(0);
157 if (m_currentEffectList.isEmpty()) m_ui.labelComment->setHidden(true);
159 for (int i = 0; i < m_currentEffectList.count(); i++) {
160 QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
162 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
166 CollapsibleEffect *group = NULL;
167 EffectInfo effectInfo;
168 effectInfo.fromString(d.attribute("kdenlive_info"));
169 if (effectInfo.groupIndex >= 0) {
170 // effect is in a group
171 for (int i = 0; i < vbox1->count(); i++) {
172 CollapsibleEffect *eff = static_cast<CollapsibleEffect *>(vbox1->itemAt(i)->widget());
173 if (eff->isGroup() && eff->groupIndex() == effectInfo.groupIndex) {
180 group = new CollapsibleEffect(QDomElement(), QDomElement(), ItemInfo(), effectInfo.groupIndex, &m_effectMetaInfo, false, true, m_ui.container->widget());
181 if (!effectInfo.groupName.isEmpty()) group->title->setText(effectInfo.groupName);
182 connect(group, SIGNAL(moveEffect(int,int,CollapsibleEffect*)), this, SLOT(slotMoveEffect(int,int,CollapsibleEffect*)));
183 connect(group, SIGNAL(unGroup(CollapsibleEffect*)), this , SLOT(slotUnGroup(CollapsibleEffect*)));
184 vbox1->addWidget(group);
186 if (effectInfo.groupIndex >= m_groupIndex) m_groupIndex = effectInfo.groupIndex + 1;
190 doc.appendChild(doc.importNode(d, true));
191 kDebug() << "IMPORTED STK: " << doc.toString();*/
194 if (m_effectMetaInfo.trackMode) {
195 info.track = m_trackInfo.type;
196 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
197 info.cropStart = GenTime(0);
198 info.startPos = GenTime(-1);
201 else info = m_clipref->info();
203 CollapsibleEffect *currentEffect = new CollapsibleEffect(d, m_currentEffectList.at(i), info, i, &m_effectMetaInfo, i == m_currentEffectList.count() - 1, false, view);
204 m_effects.append(currentEffect);
206 group->addGroupEffect(currentEffect);
208 vbox1->addWidget(currentEffect);
210 if (currentEffect->effectIndex() == ix) currentEffect->setActive(true);
213 currentEffect->installEventFilter( this );
215 connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
216 connect(currentEffect, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,QString,QString)));
217 connect(currentEffect, SIGNAL(deleteEffect(const QDomElement)), this , SLOT(slotDeleteEffect(const QDomElement)));
218 connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
219 connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
220 connect(currentEffect, SIGNAL(changeEffectPosition(int,bool)), this , SLOT(slotMoveEffectUp(int , bool)));
221 connect(currentEffect, SIGNAL(effectStateChanged(bool, int)), this, SLOT(slotUpdateEffectState(bool, int)));
222 connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
223 connect(currentEffect, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
224 connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
225 connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
226 connect(currentEffect, SIGNAL(moveEffect(int,int,CollapsibleEffect*)), this , SLOT(slotMoveEffect(int,int,CollapsibleEffect*)));
227 connect(currentEffect, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
229 //ui.title->setPixmap(icon.pixmap(QSize(12, 12)));
231 vbox1->addStretch(10);
232 slotUpdateCheckAllButton();
233 connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
235 // Wait a little bit for the new layout to be ready, then check if we have a scrollbar
236 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
240 void EffectStackView2::slotCheckWheelEventFilter()
242 // If the effect stack widget has no scrollbar, we will not filter the
243 // mouse wheel events, so that user can easily adjust effect params
244 bool filterWheelEvent = false;
245 if (m_ui.container->verticalScrollBar() && m_ui.container->verticalScrollBar()->isVisible()) {
246 // widget has scroll bar,
247 filterWheelEvent = true;
249 for (int i = 0; i < m_effects.count(); i++) {
250 m_effects.at(i)->filterWheelEvent = filterWheelEvent;
254 void EffectStackView2::resizeEvent ( QResizeEvent * event )
256 slotCheckWheelEventFilter();
257 QWidget::resizeEvent(event);
260 bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
262 // Check if user clicked in an effect's top bar to start dragging it
263 if (e->type() == QEvent::MouseButtonPress) {
264 m_draggedEffect = qobject_cast<CollapsibleEffect*>(o);
265 if (m_draggedEffect) {
266 QMouseEvent *me = static_cast<QMouseEvent *>(e);
267 if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse()))
268 m_clickPoint = me->globalPos();
270 m_clickPoint = QPoint();
271 m_draggedEffect = NULL;
277 if (e->type() == QEvent::MouseMove) {
278 if (qobject_cast<CollapsibleEffect*>(o)) {
279 QMouseEvent *me = static_cast<QMouseEvent *>(e);
280 if (me->buttons() != Qt::LeftButton) {
290 return QWidget::eventFilter(o, e);
293 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
295 if (m_draggedEffect && (event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
300 void EffectStackView2::mouseReleaseEvent(QMouseEvent * event)
302 m_draggedEffect = NULL;
303 QWidget::mouseReleaseEvent(event);
306 void EffectStackView2::startDrag()
308 QDrag *drag = new QDrag(this);
309 // The data to be transferred by the drag and drop operation is contained in a QMimeData object
310 QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
311 QPixmap pixmap = QPixmap::grabWidget(m_draggedEffect->title);
312 drag->setPixmap(pixmap);
314 doc.appendChild(doc.importNode(effect, true));
315 QMimeData *mime = new QMimeData;
317 data.append(doc.toString().toUtf8());
318 mime->setData("kdenlive/effectslist", data);
320 // Assign ownership of the QMimeData object to the QDrag object.
321 drag->setMimeData(mime);
322 // Start the drag and drop operation
323 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
327 void EffectStackView2::slotUpdateEffectState(bool disable, int index)
329 if (m_effectMetaInfo.trackMode)
330 emit changeEffectState(NULL, m_trackindex, index, disable);
332 emit changeEffectState(m_clipref, -1, index, disable);
333 slotUpdateCheckAllButton();
337 void EffectStackView2::raiseWindow(QWidget* dock)
339 if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
344 void EffectStackView2::slotSeekTimeline(int pos)
346 if (m_effectMetaInfo.trackMode) {
347 emit seekTimeline(pos);
348 } else if (m_clipref) {
349 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
354 /*void EffectStackView2::slotRegionChanged()
356 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
359 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
361 if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
362 if (!m_effectMetaInfo.monitor->getEffectEdit()->getScene()->views().at(0)->isVisible())
363 m_effectMetaInfo.monitor->slotEffectScene(true);
365 m_effectMetaInfo.monitor->slotEffectScene(false);
369 int EffectStackView2::isTrackMode(bool *ok) const
371 *ok = m_effectMetaInfo.trackMode;
375 void EffectStackView2::clear()
378 QWidget *view = m_ui.container->takeWidget();
382 m_ui.checkAll->setToolTip(QString());
383 m_ui.checkAll->setText(QString());
384 m_ui.checkAll->setEnabled(false);
385 m_ui.labelComment->setText(QString());
389 void EffectStackView2::slotCheckAll(int state)
393 m_ui.checkAll->blockSignals(true);
394 m_ui.checkAll->setCheckState(Qt::Checked);
395 m_ui.checkAll->blockSignals(false);
398 bool disabled = (state != 2);
399 for (int i = 0; i < m_effects.count(); i++) {
400 if (!m_effects.at(i)->isGroup()) {
401 m_effects.at(i)->slotEnable(!disabled);
406 void EffectStackView2::slotUpdateCheckAllButton()
408 bool hasEnabled = false;
409 bool hasDisabled = false;
411 for (int i = 0; i < m_effects.count(); i++) {
412 if (m_effects.at(i)->enabledBox->isChecked()) hasEnabled = true;
413 else hasDisabled = true;
416 m_ui.checkAll->blockSignals(true);
417 if (hasEnabled && hasDisabled)
418 m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
420 m_ui.checkAll->setCheckState(Qt::Checked);
422 m_ui.checkAll->setCheckState(Qt::Unchecked);
423 m_ui.checkAll->blockSignals(false);
426 void EffectStackView2::deleteCurrentEffect()
428 for (int i = 0; i < m_effects.count(); i++) {
429 if (m_effects.at(i)->isActive()) {
430 slotDeleteEffect(m_effects.at(i)->effect());
436 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
438 m_effectMetaInfo.profile = profile;
439 m_effectMetaInfo.timecode = t;
442 void EffectStackView2::updateTimecodeFormat()
444 for (int i = 0; i< m_effects.count(); i++)
445 m_effects.at(i)->updateTimecodeFormat();
448 CollapsibleEffect *EffectStackView2::getEffectByIndex(int ix)
450 for (int i = 0; i< m_effects.count(); i++) {
451 if (m_effects.at(i)->effectIndex() == ix) {
452 return m_effects.at(i);
458 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
460 if (m_effectMetaInfo.trackMode)
461 emit updateEffect(NULL, m_trackindex, old, e, ix);
462 else if (m_clipref) {
463 emit updateEffect(m_clipref, -1, old, e, ix);
464 // Make sure the changed effect is currently displayed
465 slotSetCurrentEffect(ix);
467 QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
470 void EffectStackView2::slotSetCurrentEffect(int ix)
472 if (m_clipref && ix != m_clipref->selectedEffectIndex())
473 m_clipref->setSelectedEffect(ix);
474 for (int i = 0; i < m_effects.count(); i++) {
475 if (m_effects.at(i)->effectIndex() == ix) {
476 m_effects.at(i)->setActive(true);
477 m_ui.labelComment->setText(i18n(m_effects.at(i)->effect().firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
478 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
480 else m_effects.at(i)->setActive(false);
484 void EffectStackView2::slotDeleteEffect(const QDomElement effect)
486 if (m_effectMetaInfo.trackMode)
487 emit removeEffect(NULL, m_trackindex, effect);
489 emit removeEffect(m_clipref, -1, effect);
492 void EffectStackView2::slotAddEffect(QDomElement effect)
494 emit addEffect(m_clipref, effect);
497 void EffectStackView2::slotMoveEffectUp(int index, bool up)
499 if (up && index <= 1) return;
500 if (!up && index >= m_currentEffectList.count()) return;
508 if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, index, endPos);
509 else emit changeEffectPosition(m_clipref, -1, index, endPos);
512 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
514 if (!m_clipref) return;
515 emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, finalFilterName, consumer, consumerParams, properties);
518 void EffectStackView2::slotResetEffect(int ix)
520 QDomElement old = m_currentEffectList.itemFromIndex(ix);
522 QString effectId = old.attribute("id");
523 QMap<QString, EffectsList*> effectLists;
524 effectLists["audio"] = &MainWindow::audioEffects;
525 effectLists["video"] = &MainWindow::videoEffects;
526 effectLists["custom"] = &MainWindow::customEffects;
527 foreach(const QString &type, effectLists.keys()) {
528 EffectsList *list = effectLists[type];
529 dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
530 if (!dom.isNull()) break;
533 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
534 if (m_effectMetaInfo.trackMode) {
535 EffectsList::setParameter(dom, "in", QString::number(0));
536 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
538 info.track = m_trackInfo.type;
539 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
540 info.cropStart = GenTime(0);
541 info.startPos = GenTime(-1);
543 m_effects.at(ix)->updateWidget(info, ix, dom, &m_effectMetaInfo);
544 emit updateEffect(NULL, m_trackindex, old, dom, ix);
546 m_clipref->initEffect(dom);
547 m_effects.at(ix)->updateWidget(m_clipref->info(), ix, dom, &m_effectMetaInfo);
548 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
549 emit updateEffect(m_clipref, -1, old, dom, ix);
553 emit showComments(m_ui.buttonShowComments->isChecked());
554 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
557 void EffectStackView2::slotShowComments()
559 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || m_ui.labelComment->text().isEmpty());
560 emit showComments(m_ui.buttonShowComments->isChecked());
563 void EffectStackView2::slotCreateGroup(int ix)
565 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
566 QDomElement neweffect = oldeffect.cloneNode().toElement();
567 EffectInfo effectinfo;
568 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
569 effectinfo.groupIndex = m_groupIndex;
570 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
573 if (m_effectMetaInfo.trackMode) {
574 info.track = m_trackInfo.type;
575 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
576 info.cropStart = GenTime(0);
577 info.startPos = GenTime(-1);
579 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix);
581 emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix);
584 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
586 CollapsibleEffect *effectToMove = NULL;
587 for (int i = 0; i < m_effects.count(); i++) {
588 if (m_effects.at(i)->effectIndex() == ix) {
589 effectToMove = m_effects.at(i);
590 groupPos = l->indexOf(effectToMove);
591 l->removeWidget(effectToMove);
596 CollapsibleEffect *group = new CollapsibleEffect(QDomElement(), QDomElement(), ItemInfo(), m_groupIndex, &m_effectMetaInfo, false, true, m_ui.container->widget());
598 connect(group, SIGNAL(moveEffect(int,int,CollapsibleEffect*)), this , SLOT(slotMoveEffect(int,int,CollapsibleEffect*)));
599 connect(group, SIGNAL(unGroup(CollapsibleEffect*)), this , SLOT(slotUnGroup(CollapsibleEffect*)));
600 l->insertWidget(groupPos, group);
601 group->addGroupEffect(effectToMove);
604 void EffectStackView2::slotMoveEffect(int currentIndex, int newIndex, CollapsibleEffect* target)
606 CollapsibleEffect *effectToMove = getEffectByIndex(currentIndex);
607 if (effectToMove == NULL) return;
609 QDomElement oldeffect = effectToMove->effect();
610 QDomElement neweffect = oldeffect.cloneNode().toElement();
612 EffectInfo effectinfo;
613 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
614 effectinfo.groupIndex = target->groupIndex();
615 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
618 if (m_effectMetaInfo.trackMode) {
619 info.track = m_trackInfo.type;
620 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
621 info.cropStart = GenTime(0);
622 info.startPos = GenTime(-1);
624 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->index());
626 emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->index());
629 //if (currentIndex == newIndex) return;
630 // Update effect index with new position
631 if (m_effectMetaInfo.trackMode) {
632 emit changeEffectPosition(NULL, m_trackindex, currentIndex, newIndex);
635 emit changeEffectPosition(m_clipref, -1, currentIndex, newIndex);
639 void EffectStackView2::slotUnGroup(CollapsibleEffect* group)
641 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
642 int ix = l->indexOf(group);
643 group->removeGroup(ix, l);
644 group->deleteLater();
647 #include "effectstackview2.moc"