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;
54 setFont(KGlobalSettings::smallestReadableFont());
55 m_ui.checkAll->setToolTip(i18n("Enable/Disable all effects"));
56 m_ui.buttonShowComments->setIcon(KIcon("help-about"));
57 m_ui.buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
62 QPalette p = palette();
63 KColorScheme scheme(p.currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
64 QColor dark_bg = scheme.shade(KColorScheme::DarkShade);
65 QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
66 QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
67 QColor light_bg = scheme.shade(KColorScheme::LightShade);
69 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}\
70 QProgressBar:horizontal#dragOnly {background: %1} QProgressBar:horizontal:hover#dragOnly {background: %3} QProgressBar:horizontal:hover {border: 1px solid %3;border-right: 0px;}\
71 QProgressBar::chunk:horizontal {background: %1;} QProgressBar::chunk:horizontal:hover {background: %3;}\
72 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;}\
73 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;}\
74 QAbstractSpinBox::up-button#dragBox {width:0px;padding:0px;} QAbstractSpinBox[inTimeline=\"true\"]#dragBox { border: 1px solid %2;} QAbstractSpinBox:hover#dragBox {border: 1px solid %3;} ")
75 .arg(dark_bg.name()).arg(selected_bg.name()).arg(hover_bg.name()).arg(light_bg.name()));
76 setStyleSheet(stylesheet);
79 EffectStackView2::~EffectStackView2()
84 void EffectStackView2::slotRenderPos(int pos)
86 if (m_effects.isEmpty()) return;
87 if (!m_effectMetaInfo.trackMode && m_clipref) pos = pos - m_clipref->startPos().frames(KdenliveSettings::project_fps());
89 for (int i = 0; i< m_effects.count(); i++)
90 m_effects.at(i)->slotSyncEffectsPos(pos);
93 void EffectStackView2::setMenu(QMenu *menu)
95 //m_ui.buttonNew->setMenu(menu);
98 void EffectStackView2::slotClipItemSelected(ClipItem* c, int ix)
100 if (c && !c->isEnabled()) return;
101 if (c && c == m_clipref) {
106 QString cname = m_clipref->clipName();
107 if (cname.length() > 30) {
108 m_ui.checkAll->setToolTip(i18n("Effects for %1").arg(cname));
110 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "...");
112 m_ui.checkAll->setToolTip(QString());
113 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
115 ix = c->selectedEffectIndex();
116 QString size = c->baseClip()->getProperty("frame_size");
117 double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
118 m_effectMetaInfo.frameSize = QPoint((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
123 if (m_clipref == NULL) {
124 //TODO: clear list, reset paramdesc and info
126 //m_effectedit->transferParamDesc(QDomElement(), info);
128 QWidget *view = m_ui.container->takeWidget();
132 m_ui.checkAll->setToolTip(QString());
133 m_ui.checkAll->setText(QString());
138 m_effectMetaInfo.trackMode = false;
139 m_currentEffectList = m_clipref->effectList();
143 void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
146 m_effectMetaInfo.trackMode = true;
147 m_currentEffectList = info.effectsList;
150 m_ui.checkAll->setToolTip(QString());
151 m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
157 void EffectStackView2::setupListView(int ix)
162 m_draggedEffect = NULL;
163 disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
166 QWidget *view = m_ui.container->takeWidget();
169 //view->deleteLater();
172 view = new QWidget(m_ui.container);
173 m_ui.container->setWidget(view);
175 QVBoxLayout *vbox1 = new QVBoxLayout(view);
176 vbox1->setContentsMargins(0, 0, 0, 0);
177 vbox1->setSpacing(0);
179 for (int i = 0; i < m_currentEffectList.count(); i++) {
180 QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
182 kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
186 CollapsibleEffect *group = NULL;
187 QString groupName = EffectsList::property(d, "kdenlive_group");
188 if (!groupName.isEmpty()) {
189 kDebug()<<"// CREATING EWFFECT GRP: "<<groupName;
190 group = new CollapsibleEffect(QDomElement(), QDomElement(), ItemInfo(), groupName.toInt(), &m_effectMetaInfo, false, true, m_ui.container->widget());
191 connect(group, SIGNAL(moveEffect(int, CollapsibleEffect*)), this , SLOT(slotMoveEffectToGroup(int, CollapsibleEffect*)));
192 vbox1->addWidget(group);
196 doc.appendChild(doc.importNode(d, true));
197 kDebug() << "IMPORTED STK: " << doc.toString();*/
200 if (m_effectMetaInfo.trackMode) {
201 info.track = m_trackInfo.type;
202 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
203 info.cropStart = GenTime(0);
204 info.startPos = GenTime(-1);
207 else info = m_clipref->info();
209 CollapsibleEffect *currentEffect = new CollapsibleEffect(d, m_currentEffectList.at(i), info, i, &m_effectMetaInfo, i == m_currentEffectList.count() - 1, false, view);
210 m_effects.append(currentEffect);
212 group->addGroupEffect(currentEffect);
214 vbox1->addWidget(currentEffect);
218 currentEffect->installEventFilter( this );
220 connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
221 connect(currentEffect, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,QString,QString)));
222 connect(currentEffect, SIGNAL(deleteEffect(const QDomElement, int)), this , SLOT(slotDeleteEffect(const QDomElement, int)));
223 connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
224 connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
225 connect(currentEffect, SIGNAL(changeEffectPosition(int,bool)), this , SLOT(slotMoveEffect(int , bool)));
226 connect(currentEffect, SIGNAL(effectStateChanged(bool, int)), this, SLOT(slotUpdateEffectState(bool, int)));
227 connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
228 connect(currentEffect, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
229 connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
230 connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
231 connect(currentEffect, SIGNAL(moveEffect(int, CollapsibleEffect*)), this , SLOT(slotMoveEffectToGroup(int, CollapsibleEffect*)));
233 //ui.title->setPixmap(icon.pixmap(QSize(12, 12)));
235 vbox1->addStretch(10);
236 connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
239 bool EffectStackView2::eventFilter( QObject * o, QEvent * e )
241 // Check if user clicked in an effect's top bar to start dragging it
242 if (e->type() == QEvent::MouseButtonPress) {
243 m_draggedEffect = qobject_cast<CollapsibleEffect*>(o);
244 if (m_draggedEffect) {
245 QMouseEvent *me = static_cast<QMouseEvent *>(e);
246 if (me->button() == Qt::LeftButton && (m_draggedEffect->frame->underMouse() || m_draggedEffect->title->underMouse()))
247 m_clickPoint = me->pos();
249 m_clickPoint = QPoint();
250 m_draggedEffect = NULL;
256 if (e->type() == QEvent::MouseMove) {
257 if (qobject_cast<CollapsibleEffect*>(o)) {
258 CollapsibleEffect *effect = qobject_cast<CollapsibleEffect*>(o);
259 QMouseEvent *me = static_cast<QMouseEvent *>(e);
260 if (me->buttons() != Qt::LeftButton) {
270 return QWidget::eventFilter(o, e);
273 void EffectStackView2::mouseMoveEvent(QMouseEvent * event)
275 if (m_draggedEffect && (event->buttons() & Qt::LeftButton) && (m_clickPoint != QPoint()) && ((event->pos() - m_clickPoint).manhattanLength() >= QApplication::startDragDistance()))
279 void EffectStackView2::mouseReleaseEvent(QMouseEvent * event)
281 m_draggedEffect = NULL;
282 QWidget::mouseReleaseEvent(event);
285 void EffectStackView2::startDrag()
287 QDrag *drag = new QDrag(this);
288 // The data to be transferred by the drag and drop operation is contained in a QMimeData object
289 QDomElement effect = m_draggedEffect->effect().cloneNode().toElement();
290 QPixmap pixmap = QPixmap::grabWidget(m_draggedEffect->title);
291 drag->setPixmap(pixmap);
293 doc.appendChild(doc.importNode(effect, true));
294 QMimeData *mime = new QMimeData;
296 data.append(doc.toString().toUtf8());
297 mime->setData("kdenlive/effectslist", data);
299 // Assign ownership of the QMimeData object to the QDrag object.
300 drag->setMimeData(mime);
301 // Start the drag and drop operation
302 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
306 void EffectStackView2::slotUpdateEffectState(bool disable, int index)
308 if (m_effectMetaInfo.trackMode)
309 emit changeEffectState(NULL, m_trackindex, index, disable);
311 emit changeEffectState(m_clipref, -1, index, disable);
315 void EffectStackView2::raiseWindow(QWidget* dock)
317 if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
322 void EffectStackView2::slotSeekTimeline(int pos)
324 if (m_effectMetaInfo.trackMode) {
325 emit seekTimeline(pos);
326 } else if (m_clipref) {
327 emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
332 /*void EffectStackView2::slotRegionChanged()
334 if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
337 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
339 if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
340 if (!m_effectMetaInfo.monitor->getEffectEdit()->getScene()->views().at(0)->isVisible())
341 m_effectMetaInfo.monitor->slotEffectScene(true);
343 m_effectMetaInfo.monitor->slotEffectScene(false);
347 int EffectStackView2::isTrackMode(bool *ok) const
349 *ok = m_effectMetaInfo.trackMode;
353 void EffectStackView2::clear()
357 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
359 m_effectMetaInfo.profile = profile;
360 m_effectMetaInfo.timecode = t;
363 void EffectStackView2::slotItemDel()
368 void EffectStackView2::updateTimecodeFormat()
370 for (int i = 0; i< m_effects.count(); i++)
371 m_effects.at(i)->updateTimecodeFormat();
374 CollapsibleEffect *EffectStackView2::getEffectByIndex(int ix)
376 for (int i = 0; i< m_effects.count(); i++) {
377 if (m_effects.at(i)->effectIndex() == ix) {
378 return m_effects.at(i);
384 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
386 if (m_effectMetaInfo.trackMode)
387 emit updateEffect(NULL, m_trackindex, old, e, ix);
388 else if (m_clipref) {
389 emit updateEffect(m_clipref, -1, old, e, ix);
390 // Make sure the changed effect is currently displayed
391 slotSetCurrentEffect(ix);
395 void EffectStackView2::slotSetCurrentEffect(int ix)
397 if (m_clipref && ix != m_clipref->selectedEffectIndex())
398 m_clipref->setSelectedEffect(ix);
399 for (int i = 0; i < m_effects.count(); i++) {
400 m_effects.at(i)->setActive(i == ix);
404 void EffectStackView2::slotDeleteEffect(const QDomElement effect, int index)
407 if (m_effectMetaInfo.trackMode)
408 emit removeEffect(NULL, m_trackindex, effect);
410 emit removeEffect(m_clipref, -1, effect);
413 void EffectStackView2::slotMoveEffect(int index, bool up)
415 if (up && index <= 0) return;
416 if (!up && index >= m_currentEffectList.count() - 1) return;
420 startPos = index + 1;
424 startPos = index + 1;
427 if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, startPos, endPos);
428 else emit changeEffectPosition(m_clipref, -1, startPos, endPos);
431 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
433 if (!m_clipref) return;
434 emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, finalFilterName, consumer, consumerParams, properties);
437 void EffectStackView2::slotResetEffect(int ix)
439 QDomElement old = m_currentEffectList.at(ix);
441 QString effectId = old.attribute("id");
442 QMap<QString, EffectsList*> effectLists;
443 effectLists["audio"] = &MainWindow::audioEffects;
444 effectLists["video"] = &MainWindow::videoEffects;
445 effectLists["custom"] = &MainWindow::customEffects;
446 foreach(const QString &type, effectLists.keys()) {
447 EffectsList *list = effectLists[type];
448 dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
449 if (!dom.isNull()) break;
452 dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
453 if (m_effectMetaInfo.trackMode) {
454 EffectsList::setParameter(dom, "in", QString::number(0));
455 EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
457 info.track = m_trackInfo.type;
458 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
459 info.cropStart = GenTime(0);
460 info.startPos = GenTime(-1);
462 m_effects.at(ix)->updateWidget(info, ix, dom, &m_effectMetaInfo);
463 emit updateEffect(NULL, m_trackindex, old, dom, ix);
465 m_clipref->initEffect(dom);
466 m_effects.at(ix)->updateWidget(m_clipref->info(), ix, dom, &m_effectMetaInfo);
467 //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
468 emit updateEffect(m_clipref, -1, old, dom, ix);
472 /*emit showComments(m_ui.buttonShowComments->isChecked());
473 m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || !m_ui.labelComment->text().count());*/
477 void EffectStackView2::slotCreateGroup(int ix)
479 QDomElement oldeffect = m_currentEffectList.at(ix);
480 QDomElement neweffect = oldeffect.cloneNode().toElement();
481 QString groupName = QString::number(m_groupIndex);
483 EffectsList::setProperty(neweffect, "kdenlive_group", groupName);
486 if (m_effectMetaInfo.trackMode) {
487 info.track = m_trackInfo.type;
488 info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
489 info.cropStart = GenTime(0);
490 info.startPos = GenTime(-1);
492 emit updateEffect(NULL, m_trackindex, oldeffect, neweffect, ix);
494 emit updateEffect(m_clipref, -1, oldeffect, neweffect, ix);
497 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
498 int groupPos = l->indexOf(m_effects.at(ix));
500 CollapsibleEffect *group = new CollapsibleEffect(QDomElement(), QDomElement(), ItemInfo(), m_groupIndex, &m_effectMetaInfo, false, true, m_ui.container->widget());
501 connect(group, SIGNAL(moveEffect(int, CollapsibleEffect*)), this , SLOT(slotMoveEffectToGroup(int, CollapsibleEffect*)));
502 CollapsibleEffect *w = static_cast<CollapsibleEffect*>(l->takeAt(groupPos)->widget());
503 l->insertWidget(groupPos, group);
504 group->addGroupEffect(w);
507 void EffectStackView2::slotMoveEffectToGroup(int ix, CollapsibleEffect* group)
509 QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
510 CollapsibleEffect *effectToMove = getEffectByIndex(ix);
511 if (effectToMove == NULL) return;
512 l->removeWidget(effectToMove);
513 group->addGroupEffect(effectToMove);
516 #include "effectstackview2.moc"