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>
43 EffectStackView2::EffectStackView2(Monitor *monitor, QWidget *parent) :
47 m_draggedEffect(NULL),
50 m_effectMetaInfo.trackMode = false;
51 m_effectMetaInfo.monitor = monitor;
52 m_effects = QList <CollapsibleEffect*>();
55 setFont(KGlobalSettings::smallestReadableFont());
56 m_ui.checkAll->setToolTip(i18n("Enable/Disable all effects"));
57 m_ui.buttonShowComments->setIcon(KIcon("help-about"));
58 m_ui.buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
63 QPalette p = palette();
64 KColorScheme scheme(p.currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
65 QColor dark_bg = scheme.shade(KColorScheme::DarkShade);
66 QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
67 QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
68 QColor light_bg = scheme.shade(KColorScheme::LightShade);
70 QString stylesheet(QString("QProgressBar:horizontal {border: 1px solid %1;border-radius:0px;border-top-left-radius: 4px;border-bottom-left-radius: 4px;border-right: 0px;background:%4;padding: 0px;text-align:left center}\
71 QProgressBar:horizontal#dragOnly {background: %1} QProgressBar:horizontal:hover#dragOnly {background: %3} QProgressBar:horizontal:hover {border: 1px solid %3;border-right: 0px;}\
72 QProgressBar::chunk:horizontal {background: %1;} QProgressBar::chunk:horizontal:hover {background: %3;}\
73 QProgressBar:horizontal[inTimeline=\"true\"] { border: 1px solid %2;border-right: 0px;background: %4;padding: 0px;text-align:left center } QProgressBar::chunk:horizontal[inTimeline=\"true\"] {background: %2;}\
74 QAbstractSpinBox#dragBox {border: 1px solid %1;border-top-right-radius: 4px;border-bottom-right-radius: 4px;padding-right:0px;} QAbstractSpinBox::down-button#dragBox {width:0px;padding:0px;}\
75 QAbstractSpinBox::up-button#dragBox {width:0px;padding:0px;} QAbstractSpinBox[inTimeline=\"true\"]#dragBox { border: 1px solid %2;} QAbstractSpinBox:hover#dragBox {border: 1px solid %3;} ")
76 .arg(dark_bg.name()).arg(selected_bg.name()).arg(hover_bg.name()).arg(light_bg.name()));
77 setStyleSheet(stylesheet);
80 EffectStackView2::~EffectStackView2()
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::setMenu(QMenu *menu)
96 //m_ui.buttonNew->setMenu(menu);
99 void EffectStackView2::slotClipItemSelected(ClipItem* c, int ix)
101 if (c && !c->isEnabled()) return;
102 if (c && c == m_clipref) {
107 QString cname = m_clipref->clipName();
108 if (cname.length() > 30) {
109 m_ui.checkAll->setToolTip(i18n("Effects for %1").arg(cname));
111 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "...");
113 m_ui.checkAll->setToolTip(QString());
114 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
116 ix = c->selectedEffectIndex();
117 QString size = c->baseClip()->getProperty("frame_size");
118 double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
119 m_effectMetaInfo.frameSize = QPoint((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
124 if (m_clipref == NULL) {
125 //TODO: clear list, reset paramdesc and info
127 //m_effectedit->transferParamDesc(QDomElement(), info);
132 m_effectMetaInfo.trackMode = false;
133 m_currentEffectList = m_clipref->effectList();
137 void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
140 m_effectMetaInfo.trackMode = true;
141 m_currentEffectList = info.effectsList;
144 m_ui.checkAll->setToolTip(QString());
145 m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
151 void EffectStackView2::setupListView(int ix)
156 m_draggedEffect = NULL;
157 disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
160 QWidget *view = m_ui.container->takeWidget();
165 view = new QWidget(m_ui.container);
166 m_ui.container->setWidget(view);
168 QVBoxLayout *vbox1 = new QVBoxLayout(view);
169 vbox1->setContentsMargins(0, 0, 0, 0);
170 vbox1->setSpacing(0);
172 for (int i = 0; i < m_currentEffectList.count(); i++) {
173 QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
175 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
179 CollapsibleEffect *group = NULL;
180 EffectInfo effectInfo;
181 effectInfo.fromString(d.attribute("kdenlive_info"));
182 if (effectInfo.groupIndex >= 0) {
183 for (int j = 0; j < vbox1->count(); j++) {
184 CollapsibleEffect *gp = static_cast<CollapsibleEffect *>(vbox1->itemAt(j)->widget());
185 if (gp->groupIndex() == effectInfo.groupIndex) {
192 group = new CollapsibleEffect(QDomElement(), QDomElement(), ItemInfo(), effectInfo.groupIndex, &m_effectMetaInfo, false, true, m_ui.container->widget());
193 if (!effectInfo.groupName.isEmpty()) group->title->setText(effectInfo.groupName);
194 connect(group, SIGNAL(moveEffect(int,int,CollapsibleEffect*)), this, SLOT(slotMoveEffect(int,int,CollapsibleEffect*)));
195 connect(group, SIGNAL(unGroup(CollapsibleEffect*)), this , SLOT(slotUnGroup(CollapsibleEffect*)));
196 vbox1->addWidget(group);
198 if (effectInfo.groupIndex >= m_groupIndex) m_groupIndex = effectInfo.groupIndex + 1;
202 doc.appendChild(doc.importNode(d, true));
203 kDebug() << "IMPORTED STK: " << doc.toString();*/
206 if (m_effectMetaInfo.trackMode) {
207 info.track = m_trackInfo.type;
208 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
209 info.cropStart = GenTime(0);
210 info.startPos = GenTime(-1);
213 else info = m_clipref->info();
215 CollapsibleEffect *currentEffect = new CollapsibleEffect(d, m_currentEffectList.at(i), info, i, &m_effectMetaInfo, i == m_currentEffectList.count() - 1, false, view);
216 m_effects.append(currentEffect);
218 group->addGroupEffect(currentEffect);
220 vbox1->addWidget(currentEffect);
224 currentEffect->installEventFilter( this );
226 connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
227 connect(currentEffect, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,QString,QString)));
228 connect(currentEffect, SIGNAL(deleteEffect(const QDomElement)), this , SLOT(slotDeleteEffect(const QDomElement)));
229 connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
230 connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
231 connect(currentEffect, SIGNAL(changeEffectPosition(int,bool)), this , SLOT(slotMoveEffectUp(int , bool)));
232 connect(currentEffect, SIGNAL(effectStateChanged(bool, int)), this, SLOT(slotUpdateEffectState(bool, int)));
233 connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
234 connect(currentEffect, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
235 connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
236 connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
237 connect(currentEffect, SIGNAL(moveEffect(int,int,CollapsibleEffect*)), this , SLOT(slotMoveEffect(int,int,CollapsibleEffect*)));
238 connect(currentEffect, SIGNAL(addEffect(QDomElement)), this , SLOT(slotAddEffect(QDomElement)));
240 //ui.title->setPixmap(icon.pixmap(QSize(12, 12)));
242 vbox1->addStretch(10);
243 connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
246 bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
248 // Check if user clicked in an effect's top bar to start dragging it
249 if (e->type() == QEvent::MouseButtonPress) {
250 m_draggedEffect = qobject_cast<CollapsibleEffect*>(o);
251 if (m_draggedEffect) {
252 QMouseEvent *me = static_cast<QMouseEvent *>(e);
253 if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse()))
254 m_clickPoint = me->globalPos();
256 m_clickPoint = QPoint();
257 m_draggedEffect = NULL;
263 if (e->type() == QEvent::MouseMove) {
264 if (qobject_cast<CollapsibleEffect*>(o)) {
265 QMouseEvent *me = static_cast<QMouseEvent *>(e);
266 if (me->buttons() != Qt::LeftButton) {
276 return QWidget::eventFilter(o, e);
279 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
281 if (m_draggedEffect && (event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->globalPos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance())) {
286 void EffectStackView2::mouseReleaseEvent(QMouseEvent * event)
288 m_draggedEffect = NULL;
289 QWidget::mouseReleaseEvent(event);
292 void EffectStackView2::startDrag()
294 QDrag *drag = new QDrag(this);
295 // The data to be transferred by the drag and drop operation is contained in a QMimeData object
296 QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
297 QPixmap pixmap = QPixmap::grabWidget(m_draggedEffect->title);
298 drag->setPixmap(pixmap);
300 doc.appendChild(doc.importNode(effect, true));
301 QMimeData *mime = new QMimeData;
303 data.append(doc.toString().toUtf8());
304 mime->setData("kdenlive/effectslist", data);
306 // Assign ownership of the QMimeData object to the QDrag object.
307 drag->setMimeData(mime);
308 // Start the drag and drop operation
309 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
313 void EffectStackView2::slotUpdateEffectState(bool disable, int index)
315 if (m_effectMetaInfo.trackMode)
316 emit changeEffectState(NULL, m_trackindex, index, disable);
318 emit changeEffectState(m_clipref, -1, index, disable);
322 void EffectStackView2::raiseWindow(QWidget* dock)
324 if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
329 void EffectStackView2::slotSeekTimeline(int pos)
331 if (m_effectMetaInfo.trackMode) {
332 emit seekTimeline(pos);
333 } else if (m_clipref) {
334 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
339 /*void EffectStackView2::slotRegionChanged()
341 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
344 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
346 if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
347 if (!m_effectMetaInfo.monitor->getEffectEdit()->getScene()->views().at(0)->isVisible())
348 m_effectMetaInfo.monitor->slotEffectScene(true);
350 m_effectMetaInfo.monitor->slotEffectScene(false);
354 int EffectStackView2::isTrackMode(bool *ok) const
356 *ok = m_effectMetaInfo.trackMode;
360 void EffectStackView2::clear()
363 QWidget *view = m_ui.container->takeWidget();
367 m_ui.checkAll->setToolTip(QString());
368 m_ui.checkAll->setText(QString());
372 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
374 m_effectMetaInfo.profile = profile;
375 m_effectMetaInfo.timecode = t;
378 void EffectStackView2::slotItemDel()
383 void EffectStackView2::updateTimecodeFormat()
385 for (int i = 0; i< m_effects.count(); i++)
386 m_effects.at(i)->updateTimecodeFormat();
389 CollapsibleEffect *EffectStackView2::getEffectByIndex(int ix)
391 for (int i = 0; i< m_effects.count(); i++) {
392 if (m_effects.at(i)->effectIndex() == ix) {
393 return m_effects.at(i);
399 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
401 if (m_effectMetaInfo.trackMode)
402 emit updateEffect(NULL, m_trackindex, old, e, ix);
403 else if (m_clipref) {
404 emit updateEffect(m_clipref, -1, old, e, ix);
405 // Make sure the changed effect is currently displayed
406 slotSetCurrentEffect(ix);
410 void EffectStackView2::slotSetCurrentEffect(int ix)
412 if (m_clipref && ix != m_clipref->selectedEffectIndex())
413 m_clipref->setSelectedEffect(ix);
414 for (int i = 0; i < m_effects.count(); i++) {
415 m_effects.at(i)->setActive(i == ix);
419 void EffectStackView2::slotDeleteEffect(const QDomElement effect)
421 if (m_effectMetaInfo.trackMode)
422 emit removeEffect(NULL, m_trackindex, effect);
424 emit removeEffect(m_clipref, -1, effect);
427 void EffectStackView2::slotAddEffect(QDomElement effect)
429 emit addEffect(m_clipref, effect);
432 void EffectStackView2::slotMoveEffectUp(int index, bool up)
434 if (up && index <= 1) return;
435 if (!up && index >= m_currentEffectList.count()) return;
443 if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, index, endPos);
444 else emit changeEffectPosition(m_clipref, -1, index, endPos);
447 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
449 if (!m_clipref) return;
450 emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, finalFilterName, consumer, consumerParams, properties);
453 void EffectStackView2::slotResetEffect(int ix)
455 QDomElement old = m_currentEffectList.itemFromIndex(ix);
457 QString effectId = old.attribute("id");
458 QMap<QString, EffectsList*> effectLists;
459 effectLists["audio"] = &MainWindow::audioEffects;
460 effectLists["video"] = &MainWindow::videoEffects;
461 effectLists["custom"] = &MainWindow::customEffects;
462 foreach(const QString &type, effectLists.keys()) {
463 EffectsList *list = effectLists[type];
464 dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
465 if (!dom.isNull()) break;
468 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
469 if (m_effectMetaInfo.trackMode) {
470 EffectsList::setParameter(dom, "in", QString::number(0));
471 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
473 info.track = m_trackInfo.type;
474 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
475 info.cropStart = GenTime(0);
476 info.startPos = GenTime(-1);
478 m_effects.at(ix)->updateWidget(info, ix, dom, &m_effectMetaInfo);
479 emit updateEffect(NULL, m_trackindex, old, dom, ix);
481 m_clipref->initEffect(dom);
482 m_effects.at(ix)->updateWidget(m_clipref->info(), ix, dom, &m_effectMetaInfo);
483 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
484 emit updateEffect(m_clipref, -1, old, dom, ix);
488 /*emit showComments(m_ui.buttonShowComments->isChecked());
489 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || !m_ui.labelComment->text().count());*/
493 void EffectStackView2::slotCreateGroup(int ix)
495 QDomElement oldeffect = m_currentEffectList.itemFromIndex(ix);
496 QDomElement neweffect = oldeffect.cloneNode().toElement();
497 QString groupName = QString::number(m_groupIndex);
498 EffectInfo effectinfo;
499 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
500 effectinfo.groupIndex = m_groupIndex;
501 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
504 if (m_effectMetaInfo.trackMode) {
505 info.track = m_trackInfo.type;
506 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
507 info.cropStart = GenTime(0);
508 info.startPos = GenTime(-1);
510 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix);
512 emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix);
515 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
518 CollapsibleEffect *effectToMove = NULL;
519 for (int j = 0; j < l->count(); j++) {
520 CollapsibleEffect *gp = static_cast<CollapsibleEffect *>(l->itemAt(j)->widget());
521 if (gp->effectIndex() == ix) {
523 groupPos = l->indexOf(gp);
529 CollapsibleEffect *group = new CollapsibleEffect(QDomElement(), QDomElement(), ItemInfo(), m_groupIndex, &m_effectMetaInfo, false, true, m_ui.container->widget());
531 connect(group, SIGNAL(moveEffect(int,int,CollapsibleEffect*)), this , SLOT(slotMoveEffect(int,int,CollapsibleEffect*)));
532 connect(group, SIGNAL(unGroup(CollapsibleEffect*)), this , SLOT(slotUnGroup(CollapsibleEffect*)));
533 l->insertWidget(groupPos, group);
534 group->addGroupEffect(effectToMove);
537 void EffectStackView2::slotMoveEffect(int currentIndex, int newIndex, CollapsibleEffect* target)
539 CollapsibleEffect *effectToMove = getEffectByIndex(currentIndex);
540 if (effectToMove == NULL) return;
542 QDomElement oldeffect = effectToMove->effect();
543 QDomElement neweffect = oldeffect.cloneNode().toElement();
545 EffectInfo effectinfo;
546 effectinfo.fromString(oldeffect.attribute("kdenlive_info"));
547 effectinfo.groupIndex = target->groupIndex();
548 neweffect.setAttribute("kdenlive_info", effectinfo.toString());
551 if (m_effectMetaInfo.trackMode) {
552 info.track = m_trackInfo.type;
553 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
554 info.cropStart = GenTime(0);
555 info.startPos = GenTime(-1);
557 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, effectToMove->index());
559 emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->index());
562 if (currentIndex == newIndex) return;
563 // Update effect index with new position
564 if (m_effectMetaInfo.trackMode) {
565 emit changeEffectPosition(NULL, m_trackindex, currentIndex, newIndex);
568 emit changeEffectPosition(m_clipref, -1, currentIndex, newIndex);
572 void EffectStackView2::slotUnGroup(CollapsibleEffect* group)
574 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
575 int ix = l->indexOf(group);
576 group->removeGroup(ix, l);
577 group->deleteLater();
580 #include "effectstackview2.moc"