X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fcustomtrackview.cpp;h=81b59ac8b115a5809673df188ed1d6ea60fcc7d0;hb=e6e8f38a4631c6d67b63304490e32ce57cf644c7;hp=f6da0f714da933e5917974263d4e19572b394712;hpb=82812d2bbe0841ad5534677c55b7fa84dbd890c0;p=kdenlive diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index f6da0f71..81b59ac8 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -64,6 +64,8 @@ #include #include #include +#include +#include #include #include @@ -72,7 +74,7 @@ #include #include #include -#include + #if QT_VERSION >= 0x040600 #include @@ -171,6 +173,7 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscen CustomTrackView::~CustomTrackView() { qDeleteAll(m_guides); + m_guides.clear(); m_waitingThumbs.clear(); } @@ -191,11 +194,16 @@ void CustomTrackView::setDocumentModified() m_document->setModified(true); } -void CustomTrackView::setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition, QActionGroup *clipTypeGroup) +void CustomTrackView::setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition, QActionGroup *clipTypeGroup, QMenu *markermenu) { m_timelineContextMenu = timeline; m_timelineContextClipMenu = clip; m_clipTypeGroup = clipTypeGroup; + + m_markerMenu = new QMenu(i18n("Go to marker..."), this); + m_markerMenu->setEnabled(false); + markermenu->addMenu(m_markerMenu); + connect(m_markerMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotGoToMarker(QAction *))); QList list = m_timelineContextClipMenu->actions(); for (int i = 0; i < list.count(); i++) { if (list.at(i)->data().toString() == "paste_effects") m_pasteEffectsAction = list.at(i); @@ -407,15 +415,49 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) // spacer tool snappedPos = getSnapPointForPos(mappedXPos + m_spacerOffset); if (snappedPos < 0) snappedPos = 0; + // Make sure there is no collision QList children = m_selectionGroup->childItems(); QPainterPath shape = m_selectionGroup->clipGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0)); QList collidingItems = scene()->items(shape, Qt::IntersectsItemShape); collidingItems.removeAll(m_selectionGroup); for (int i = 0; i < children.count(); i++) { + if (children.at(i)->type() == GROUPWIDGET) { + QList subchildren = children.at(i)->childItems(); + for (int j = 0; j < subchildren.count(); j++) { + collidingItems.removeAll(subchildren.at(j)); + } + } collidingItems.removeAll(children.at(i)); } bool collision = false; + int offset = 0; + for (int i = 0; i < collidingItems.count(); i++) { + if (!collidingItems.at(i)->isEnabled()) continue; + if (collidingItems.at(i)->type() == AVWIDGET && snappedPos < m_selectionGroup->sceneBoundingRect().left()) { + AbstractClipItem *item = static_cast (collidingItems.at(i)); + // Moving backward, determine best pos + QPainterPath clipPath; + clipPath.addRect(item->sceneBoundingRect()); + QPainterPath res = shape.intersected(clipPath); + offset = qMax(offset, (int)(res.boundingRect().width() + 0.5)); + } + } + snappedPos += offset; + // make sure we have no collision + shape = m_selectionGroup->clipGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0)); + collidingItems = scene()->items(shape, Qt::IntersectsItemShape); + collidingItems.removeAll(m_selectionGroup); + for (int i = 0; i < children.count(); i++) { + if (children.at(i)->type() == GROUPWIDGET) { + QList subchildren = children.at(i)->childItems(); + for (int j = 0; j < subchildren.count(); j++) { + collidingItems.removeAll(subchildren.at(j)); + } + } + collidingItems.removeAll(children.at(i)); + } + for (int i = 0; i < collidingItems.count(); i++) { if (!collidingItems.at(i)->isEnabled()) continue; if (collidingItems.at(i)->type() == AVWIDGET) { @@ -423,12 +465,47 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) break; } } + + if (!collision) { // Check transitions shape = m_selectionGroup->transitionGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0)); collidingItems = scene()->items(shape, Qt::IntersectsItemShape); collidingItems.removeAll(m_selectionGroup); for (int i = 0; i < children.count(); i++) { + if (children.at(i)->type() == GROUPWIDGET) { + QList subchildren = children.at(i)->childItems(); + for (int j = 0; j < subchildren.count(); j++) { + collidingItems.removeAll(subchildren.at(j)); + } + } + collidingItems.removeAll(children.at(i)); + } + offset = 0; + + for (int i = 0; i < collidingItems.count(); i++) { + if (collidingItems.at(i)->type() == TRANSITIONWIDGET && snappedPos < m_selectionGroup->sceneBoundingRect().left()) { + AbstractClipItem *item = static_cast (collidingItems.at(i)); + // Moving backward, determine best pos + QPainterPath clipPath; + clipPath.addRect(item->sceneBoundingRect()); + QPainterPath res = shape.intersected(clipPath); + offset = qMax(offset, (int)(res.boundingRect().width() + 0.5)); + } + } + + snappedPos += offset; + // make sure we have no collision + shape = m_selectionGroup->transitionGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0)); + collidingItems = scene()->items(shape, Qt::IntersectsItemShape); + collidingItems.removeAll(m_selectionGroup); + for (int i = 0; i < children.count(); i++) { + if (children.at(i)->type() == GROUPWIDGET) { + QList subchildren = children.at(i)->childItems(); + for (int j = 0; j < subchildren.count(); j++) { + collidingItems.removeAll(subchildren.at(j)); + } + } collidingItems.removeAll(children.at(i)); } for (int i = 0; i < collidingItems.count(); i++) { @@ -670,7 +747,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) // special cases (middle click button or ctrl / shift click if (event->button() == Qt::MidButton) { - m_document->renderer()->switchPlay(); + emit playMonitor(); m_blockRefresh = false; m_operationMode = NONE; return; @@ -841,10 +918,11 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) kDebug() << "SELELCTING ELEMENTS WITHIN =" << event->pos().x() << "/" << 1 << ", " << mapFromScene(sceneRect().width(), 0).x() - event->pos().x() << "/" << sceneRect().height(); } + QList offsetList; // create group to hold selected items m_selectionGroup = new AbstractGroupItem(m_document->fps()); scene()->addItem(m_selectionGroup); - QList offsetList; + for (int i = 0; i < selection.count(); i++) { if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET)) { AbstractClipItem *item = static_cast(selection.at(i)); @@ -853,7 +931,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) offsetList.append(item->endPos()); m_selectionGroup->addToGroup(selection.at(i)); selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false); - } else if (selection.at(i)->parentItem() == 0 && selection.at(i)->type() == GROUPWIDGET) { + } else if (/*selection.at(i)->parentItem() == 0 && */selection.at(i)->type() == GROUPWIDGET) { if (static_cast(selection.at(i))->isItemLocked()) continue; QList children = selection.at(i)->childItems(); for (int j = 0; j < children.count(); j++) { @@ -863,8 +941,9 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) } m_selectionGroup->addToGroup(selection.at(i)); selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false); - } else if (selection.at(i)->parentItem()) { + } else if (selection.at(i)->parentItem() && !selection.contains(selection.at(i)->parentItem())) { if (static_cast(selection.at(i)->parentItem())->isItemLocked()) continue; + //AbstractGroupItem *grp = static_cast(selection.at(i)->parentItem()); m_selectionGroup->addToGroup(selection.at(i)->parentItem()); selection.at(i)->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false); } @@ -987,8 +1066,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) return; } else if (m_operationMode == MOVE) { setCursor(Qt::ClosedHandCursor); - if (m_dragItem) m_dragItem->setZValue(10); - if (m_selectionGroup) m_selectionGroup->setZValue(10); } else if (m_operationMode == TRANSITIONSTART && event->modifiers() != Qt::ControlModifier) { ItemInfo info; info.startPos = m_dragItem->startPos(); @@ -1168,8 +1245,9 @@ void CustomTrackView::groupSelectedItems(bool force, bool createNewGroup) void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) { if (m_dragItem && m_dragItem->hasKeyFrames()) { - if (m_moveOpMode == KEYFRAME) { + /*if (m_moveOpMode == KEYFRAME) { // user double clicked on a keyframe, open edit dialog + //TODO: update for effects with several values per keyframe QDialog d(parentWidget()); Ui::KeyFrameDialog_UI view; view.setupUi(&d); @@ -1189,21 +1267,24 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) emit clipItemSelected(item, item->selectedEffectIndex()); } - } else { + } else*/ { // add keyframe GenTime keyFramePos = GenTime((int)(mapToScene(event->pos()).x()), m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart(); - m_dragItem->addKeyFrame(keyFramePos, mapToScene(event->pos()).toPoint().y()); + int val = m_dragItem->addKeyFrame(keyFramePos, mapToScene(event->pos()).toPoint().y()); ClipItem * item = static_cast (m_dragItem); - QString previous = item->keyframes(item->selectedEffectIndex()); - item->updateKeyframeEffect(); - QString next = item->keyframes(item->selectedEffectIndex()); - EditKeyFrameCommand *command = new EditKeyFrameCommand(this, m_dragItem->track(), m_dragItem->startPos(), item->selectedEffectIndex(), previous, next, false); + //QString previous = item->keyframes(item->selectedEffectIndex()); + QDomElement oldEffect = item->selectedEffect().cloneNode().toElement(); + item->insertKeyframe(item->getEffectAt(item->selectedEffectIndex()), keyFramePos.frames(m_document->fps()), val); + //item->updateKeyframeEffect(); + //QString next = item->keyframes(item->selectedEffectIndex()); + QDomElement newEffect = item->selectedEffect().cloneNode().toElement(); + EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), oldEffect, newEffect, item->selectedEffectIndex(), false); + //EditKeyFrameCommand *command = new EditKeyFrameCommand(this, m_dragItem->track(), m_dragItem->startPos(), item->selectedEffectIndex(), previous, next, false); m_commandStack->push(command); updateEffect(m_document->tracksCount() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex()); emit clipItemSelected(item, item->selectedEffectIndex()); } } else if (m_dragItem && !m_dragItem->isItemLocked()) { - ClipDurationDialog d(m_dragItem, m_document->timecode(), this); GenTime minimum; GenTime maximum; if (m_dragItem->type() == TRANSITIONWIDGET) { @@ -1212,7 +1293,7 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) getClipAvailableSpace(m_dragItem, minimum, maximum); } //kDebug()<<"// GOT MOVE POS: "<timecode(), minimum, maximum, this); if (d.exec() == QDialog::Accepted) { if (m_dragItem->type() == TRANSITIONWIDGET) { // move & resize transition @@ -1278,8 +1359,11 @@ void CustomTrackView::displayContextMenu(QPoint pos, AbstractClipItem *clip, Abs { m_deleteGuide->setEnabled(m_dragGuide != NULL); m_editGuide->setEnabled(m_dragGuide != NULL); - if (clip == NULL) m_timelineContextMenu->popup(pos); - else if (group != NULL) { + m_markerMenu->clear(); + m_markerMenu->setEnabled(false); + if (clip == NULL) { + m_timelineContextMenu->popup(pos); + } else if (group != NULL) { m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1); m_ungroupAction->setEnabled(true); updateClipTypeActions(NULL); @@ -1288,10 +1372,26 @@ void CustomTrackView::displayContextMenu(QPoint pos, AbstractClipItem *clip, Abs m_ungroupAction->setEnabled(false); if (clip->type() == AVWIDGET) { ClipItem *item = static_cast (clip); + //build go to marker menu + if (item->baseClip()) { + QList markers = item->baseClip()->commentedSnapMarkers(); + int offset = item->startPos().frames(m_document->fps()); + if (!markers.isEmpty()) { + for (int i = 0; i < markers.count(); i++) { + int pos = (int) markers.at(i).time().frames(m_document->timecode().fps()); + QString position = m_document->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment(); + QAction *go = m_markerMenu->addAction(position); + go->setData(pos + offset); + } + } + m_markerMenu->setEnabled(!m_markerMenu->isEmpty()); + } updateClipTypeActions(item); m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1); m_timelineContextClipMenu->popup(pos); - } else if (clip->type() == TRANSITIONWIDGET) m_timelineContextTransitionMenu->popup(pos); + } else if (clip->type() == TRANSITIONWIDGET) { + m_timelineContextTransitionMenu->popup(pos); + } } } @@ -1328,7 +1428,8 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos) { if (data->hasFormat("kdenlive/clip")) { m_clipDrag = true; - resetSelectionGroup(); + m_scene->clearSelection(); + resetSelectionGroup(false); QStringList list = QString(data->data("kdenlive/clip")).split(';'); DocClipBase *clip = m_document->getBaseClip(list.at(0)); if (clip == NULL) { @@ -1363,7 +1464,7 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos) updateSnapPoints(NULL, offsetList); m_selectionGroup->setPos(framePos); scene()->addItem(m_selectionGroup); - m_selectionGroup->setZValue(10); + m_selectionGroup->setSelected(true); return true; } else if (data->hasFormat("kdenlive/producerslist")) { m_clipDrag = true; @@ -1409,16 +1510,15 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos) start += info.cropDuration; offsetList.append(start); ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, false); - item->setZValue(10); item->setFlag(QGraphicsItem::ItemIsMovable, false); m_selectionGroup->addToGroup(item); - m_waitingThumbs.append(item); + if (!clip->isPlaceHolder()) m_waitingThumbs.append(item); } updateSnapPoints(NULL, offsetList); m_selectionGroup->setPos(framePos); scene()->addItem(m_selectionGroup); - m_selectionGroup->setZValue(10); + //m_selectionGroup->setZValue(10); m_thumbsTimer.start(); return true; @@ -1493,11 +1593,6 @@ void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect) return; } EffectsParameterList params = clip->addEffect(effect); - if (effect.attribute("disabled") == "1") { - // Effect is disabled, don't add it to MLT playlist - if (clip->isSelected()) emit clipItemSelected(clip); - return; - } if (!m_document->renderer()->mltAddEffect(track, pos, params)) emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage); if (clip->isSelected()) emit clipItemSelected(clip); @@ -1518,8 +1613,8 @@ void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect) return; } } - if (!m_document->renderer()->mltRemoveEffect(track, pos, index, true) && effect.attribute("disabled") != "1") { - kDebug() << "// ERROR REMOV EFFECT: " << index << ", DISABLE: " << effect.attribute("disabled"); + if (!m_document->renderer()->mltRemoveEffect(track, pos, index, true)) { + kDebug() << "// ERROR REMOV EFFECT: " << index << ", DISABLE: " << effect.attribute("disable"); emit displayMessage(i18n("Problem deleting effect"), ErrorMessage); return; } @@ -1583,14 +1678,24 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track) if (!namenode.isNull()) effectName = i18n(namenode.toElement().text().toUtf8().data()); else effectName = i18n("effect"); effectCommand->setText(i18n("Add %1", effectName)); - int count = 0; + if (track == -1) itemList = scene()->selectedItems(); if (itemList.isEmpty()) { ClipItem *clip = getClipItemAt((int) pos.frames(m_document->fps()), track); if (clip) itemList.append(clip); else emit displayMessage(i18n("Select a clip if you want to apply an effect"), ErrorMessage); } - kDebug() << "// REQUESTING EFFECT ON CLIP: " << pos.frames(25) << ", TRK: " << track << "SELECTED ITEMS: " << itemList.count(); + + //expand groups + for (int i = 0; i < itemList.count(); i++) { + if (itemList.at(i)->type() == GROUPWIDGET) { + QList subitems = itemList.at(i)->childItems(); + for (int j = 0; j < subitems.count(); j++) { + if (!itemList.contains(subitems.at(j))) itemList.append(subitems.at(j)); + } + } + } + for (int i = 0; i < itemList.count(); i++) { if (itemList.at(i)->type() == AVWIDGET) { ClipItem *item = static_cast (itemList.at(i)); @@ -1623,17 +1728,50 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track) effect.setAttribute("src", ladpsaFile); } new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), effect, true, effectCommand); - count++; } } - if (count > 0) { + if (effectCommand->childCount() > 0) { m_commandStack->push(effectCommand); setDocumentModified(); } else delete effectCommand; } -void CustomTrackView::slotDeleteEffect(ClipItem *clip, QDomElement effect) +void CustomTrackView::slotDeleteEffect(ClipItem *clip, QDomElement effect, bool affectGroup) { + if (affectGroup && clip->parentItem() && clip->parentItem() == m_selectionGroup) { + //clip is in a group, also remove the effect in other clips of the group + QList items = m_selectionGroup->childItems(); + QUndoCommand *delCommand = new QUndoCommand(); + QString effectName; + QDomNode namenode = effect.elementsByTagName("name").item(0); + if (!namenode.isNull()) effectName = i18n(namenode.toElement().text().toUtf8().data()); + else effectName = i18n("effect"); + delCommand->setText(i18n("Delete %1", effectName)); + + //expand groups + for (int i = 0; i < items.count(); i++) { + if (items.at(i)->type() == GROUPWIDGET) { + QList subitems = items.at(i)->childItems(); + for (int j = 0; j < subitems.count(); j++) { + if (!items.contains(subitems.at(j))) items.append(subitems.at(j)); + } + } + } + + for (int i = 0; i < items.count(); i++) { + if (items.at(i)->type() == AVWIDGET) { + ClipItem *item = static_cast (items.at(i)); + int ix = item->hasEffect(effect.attribute("tag"), effect.attribute("id")); + if (ix != -1) { + QDomElement eff = item->effectAt(ix); + new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), eff, false, delCommand); + } + } + } + if (delCommand->childCount() > 0) m_commandStack->push(delCommand); + else delete delCommand; + return; + } AddEffectCommand *command = new AddEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effect, false); m_commandStack->push(command); setDocumentModified(); @@ -1650,7 +1788,7 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE if (clip) { // Special case: speed effect if (effect.attribute("id") == "speed") { - if (effect.attribute("disabled") == "1") doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), 1.0, clip->speed(), 1, clip->baseClip()->getId()); + if (effect.attribute("disable") == "1") doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), 1.0, clip->speed(), 1, clip->baseClip()->getId()); else { double speed = EffectsList::parameter(effect, "speed").toDouble() / 100.0; int strobe = EffectsList::parameter(effect, "strobe").toInt(); @@ -1675,11 +1813,7 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE clip->initEffect(effect); effectParams = clip->getEffectArgs(effect); } - if (effectParams.paramValue("disabled") == "1") { - if (m_document->renderer()->mltRemoveEffect(track, pos, effectParams.paramValue("kdenlive_ix"), false)) { - kDebug() << "////// DISABLING EFFECT: " << ix << ", CURRENTLA: " << clip->selectedEffectIndex(); - } else emit displayMessage(i18n("Problem deleting effect"), ErrorMessage); - } else if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - clip->track(), clip->startPos(), effectParams)) + if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - clip->track(), clip->startPos(), effectParams)) emit displayMessage(i18n("Problem editing effect"), ErrorMessage); clip->setEffectAt(ix, effect); @@ -1726,7 +1860,7 @@ void CustomTrackView::slotChangeEffectState(ClipItem *clip, int effectPos, bool QDomElement effect = clip->effectAt(effectPos); QDomElement oldEffect = effect.cloneNode().toElement(); - effect.setAttribute("disabled", (int) disable); + effect.setAttribute("disable", (int) disable); EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldEffect, effect, effectPos, true); m_commandStack->push(command); setDocumentModified();; @@ -1752,7 +1886,8 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track); if (!item || cutTime >= item->endPos() || cutTime <= item->startPos()) { emit displayMessage(i18n("Cannot find clip to cut"), ErrorMessage); - kDebug() << "///////// ERROR CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25); + if (item) kDebug() << "///////// ERROR CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25); + else kDebug() << "/// ERROR NO CLIP at: " << info.startPos.frames(m_document->fps()) << ", track: " << info.track; m_blockRefresh = false; return NULL; } @@ -2050,6 +2185,7 @@ void CustomTrackView::dropEvent(QDropEvent * event) bool hasVideoClip = false; QUndoCommand *addCommand = new QUndoCommand(); addCommand->setText(i18n("Add timeline clip")); + QList brokenClips; for (int i = 0; i < items.count(); i++) { ClipItem *item = static_cast (items.at(i)); @@ -2062,7 +2198,7 @@ void CustomTrackView::dropEvent(QDropEvent * event) //TODO: take care of edit mode for undo item->baseClip()->addReference(); - item->setZValue(item->defaultZValue()); + //item->setZValue(item->defaultZValue()); m_document->updateClip(item->baseClip()->getId()); ItemInfo info = item->info(); @@ -2073,6 +2209,8 @@ void CustomTrackView::dropEvent(QDropEvent * event) clipInfo.track = m_document->tracksCount() - item->track(); if (m_document->renderer()->mltInsertClip(clipInfo, item->xml(), item->baseClip()->producer(item->track()), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT) == -1) { emit displayMessage(i18n("Cannot insert clip in timeline"), ErrorMessage); + brokenClips.append(item); + continue; } adjustTimelineClips(m_scene->editMode(), item, ItemInfo(), addCommand); @@ -2085,7 +2223,10 @@ void CustomTrackView::dropEvent(QDropEvent * event) } item->setSelected(true); } - m_commandStack->push(addCommand); + qDeleteAll(brokenClips); + brokenClips.clear(); + if (addCommand->childCount() > 0) m_commandStack->push(addCommand); + else delete addCommand; setDocumentModified(); /* @@ -2153,7 +2294,7 @@ void CustomTrackView::adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInf new ResizeClipCommand(this, clip->info(), newclipInfo, false, false, command); clip->resizeEnd(info.startPos.frames(m_document->fps())); } - } else if (clip->endPos() < info.endPos) { + } else if (clip->endPos() <= info.endPos) { new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), clip->info(), clip->effectList(), false, false, false, true, command); scene()->removeItem(clip); delete clip; @@ -2186,7 +2327,9 @@ void CustomTrackView::adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInf dupInfo.cropStart += diff; dupInfo.cropDuration = clipInfo.endPos - info.startPos; new RazorClipCommand(this, clipInfo, info.startPos, false, command); - ClipItem *dup = cutClip(clipInfo, info.startPos, true, false); + // Commented out; variable dup unused. --granjow + //ClipItem *dup = cutClip(clipInfo, info.startPos, true, false); + cutClip(clipInfo, info.startPos, true, false); } } // TODO: add insertspacecommand @@ -2271,7 +2414,7 @@ int CustomTrackView::duration() const void CustomTrackView::addTrack(TrackInfo type, int ix) { if (ix == -1 || ix == m_document->tracksCount()) { - m_document->insertTrack(ix, type); + m_document->insertTrack(0, type); m_document->renderer()->mltInsertTrack(1, type.type == VIDEOTRACK); } else { m_document->insertTrack(m_document->tracksCount() - ix, type); @@ -2307,6 +2450,8 @@ void CustomTrackView::addTrack(TrackInfo type, int ix) ItemInfo clipinfo = item->info(); if (item->type() == AVWIDGET) { ClipItem *clip = static_cast (item); + // slowmotion clips are not track dependant, so no need to update them + if (clip->speed() != 1.0) continue; // We add a move clip command so that we get the correct producer for new track number if (clip->clipType() == AV || clip->clipType() == AUDIO) { Mlt::Producer *prod; @@ -2829,8 +2974,6 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) if (m_operationMode == MOVE) { setCursor(Qt::OpenHandCursor); - if (m_dragItem) m_dragItem->setZValue(m_dragItem->defaultZValue()); - if (m_selectionGroup) m_selectionGroup->setZValue(1); if (m_dragItem->parentItem() == 0) { // we are moving one clip, easy if (m_dragItem->type() == AVWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) { @@ -3272,7 +3415,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) int start = item->cropStart().frames(m_document->fps()); int end = item->fadeIn(); if (end == 0) { - slotDeleteEffect(item, oldeffect); + slotDeleteEffect(item, oldeffect, false); } else { end += start; QDomElement effect = oldeffect.cloneNode().toElement(); @@ -3295,7 +3438,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) int start = item->cropStart().frames(m_document->fps()); int end = item->fadeIn(); if (end == 0) { - slotDeleteEffect(item, oldeffect); + slotDeleteEffect(item, oldeffect, false); } else { end += start; QDomElement effect = oldeffect.cloneNode().toElement(); @@ -3315,7 +3458,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps()); int start = item->fadeOut(); if (start == 0) { - slotDeleteEffect(item, oldeffect); + slotDeleteEffect(item, oldeffect, false); } else { start = end - start; QDomElement effect = oldeffect.cloneNode().toElement(); @@ -3340,7 +3483,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps()); int start = item->fadeOut(); if (start == 0) { - slotDeleteEffect(item, oldeffect); + slotDeleteEffect(item, oldeffect, false); } else { start = end - start; QDomElement effect = oldeffect.cloneNode().toElement(); @@ -3354,10 +3497,26 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) } else if (m_operationMode == KEYFRAME) { // update the MLT effect ClipItem * item = static_cast (m_dragItem); - QString previous = item->keyframes(item->selectedEffectIndex()); - item->updateKeyframeEffect(); - QString next = item->keyframes(item->selectedEffectIndex()); - EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false); + QDomElement oldEffect = item->selectedEffect().cloneNode().toElement(); + + // check if we want to remove keyframe + double val = mapToScene(event->pos()).toPoint().y(); + QRectF br = item->sceneBoundingRect(); + double maxh = 100.0 / br.height(); + val = (br.bottom() - val) * maxh; + int start = item->cropStart().frames(m_document->fps()); + int end = (item->cropStart() + item->cropDuration()).frames(m_document->fps()) - 1; + if ((val < -50 || val > 150) && item->editedKeyFramePos() != start && item->editedKeyFramePos() != end) { + //delete keyframe + kDebug() << "// DELETE KFR: " << item->editedKeyFramePos(); + item->movedKeyframe(item->getEffectAt(item->selectedEffectIndex()), item->selectedKeyFramePos(), -1, 0); + } else item->movedKeyframe(item->getEffectAt(item->selectedEffectIndex()), item->selectedKeyFramePos(), item->editedKeyFramePos(), item->editedKeyFrameValue()); + QDomElement newEffect = item->selectedEffect().cloneNode().toElement(); + //item->updateKeyframeEffect(); + //QString next = item->keyframes(item->selectedEffectIndex()); + //EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false); + EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), oldEffect, newEffect, item->selectedEffectIndex(), false); + m_commandStack->push(command); updateEffect(m_document->tracksCount() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex()); emit clipItemSelected(item, item->selectedEffectIndex()); @@ -3664,7 +3823,7 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i } setDocumentModified(); if (refresh) m_document->renderer()->doRefresh(); - m_waitingThumbs.append(item); + if (!baseclip->isPlaceHolder()) m_waitingThumbs.append(item); m_thumbsTimer.start(); } @@ -4738,27 +4897,73 @@ void CustomTrackView::pasteClipEffects() paste->setText("Paste effects"); QList clips = scene()->selectedItems(); + + // expand groups + for (int i = 0; i < clips.count(); ++i) { + if (clips.at(i)->type() == GROUPWIDGET) { + QList children = clips.at(i)->childItems(); + for (int j = 0; j < children.count(); j++) { + if (children.at(j)->type() == AVWIDGET && !clips.contains(children.at(j))) { + clips.append(children.at(j)); + } + } + } + } + + for (int i = 0; i < clips.count(); ++i) { if (clips.at(i)->type() == AVWIDGET) { ClipItem *item = static_cast < ClipItem *>(clips.at(i)); for (int j = 0; j < clip->effectsCount(); j++) { QDomElement eff = clip->effectAt(j); if (eff.attribute("unique", "0") == "0" || item->hasEffect(eff.attribute("tag"), eff.attribute("id")) == -1) { + adjustKeyfames(clip->cropStart(), item->cropStart(), item->cropDuration(), eff); new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), eff, true, paste); } } } } - m_commandStack->push(paste); + if (paste->childCount() > 0) m_commandStack->push(paste); + else delete paste; - // adjust effects (fades, ...) + //adjust effects (fades, ...) for (int i = 0; i < clips.count(); ++i) { - ClipItem *item = static_cast < ClipItem *>(clips.at(i)); - updatePositionEffects(item, item->info()); + if (clips.at(i)->type() == AVWIDGET) { + ClipItem *item = static_cast < ClipItem *>(clips.at(i)); + updatePositionEffects(item, item->info()); + } } } +void CustomTrackView::adjustKeyfames(GenTime oldstart, GenTime newstart, GenTime duration, QDomElement xml) +{ + // parse parameters to check if we need to adjust to the new crop start + int diff = (newstart - oldstart).frames(m_document->fps()); + int max = (newstart + duration).frames(m_document->fps()); + QDomNodeList params = xml.elementsByTagName("parameter"); + for (int i = 0; i < params.count(); i++) { + QDomElement e = params.item(i).toElement(); + if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) { + QString def = e.attribute("default"); + // Effect has a keyframe type parameter, we need to adjust the values + QStringList keys = e.attribute("keyframes").split(";", QString::SkipEmptyParts); + QStringList newKeyFrames; + foreach(const QString &str, keys) { + int pos = str.section(':', 0, 0).toInt(); + double val = str.section(':', 1, 1).toDouble(); + pos += diff; + if (pos > max) { + newKeyFrames.append(QString::number(max) + ':' + QString::number(val)); + break; + } else newKeyFrames.append(QString::number(pos) + ':' + QString::number(val)); + } + //kDebug()<<"ORIGIN: "<tracksCount())); @@ -4880,6 +5085,7 @@ void CustomTrackView::setOutPoint() void CustomTrackView::slotUpdateAllThumbs() { + if (!isEnabled()) return; QList itemList = items(); //if (itemList.isEmpty()) return; ClipItem *item; @@ -4893,6 +5099,7 @@ void CustomTrackView::slotUpdateAllThumbs() QString thumb = thumbBase + item->baseClip()->getClipHash() + "_0.png"; if (QFile::exists(thumb)) { QPixmap pix(thumb); + if (pix.isNull()) KIO::NetAccess::del(KUrl(thumb), this); item->slotSetStartThumb(pix); } } else { @@ -4902,16 +5109,18 @@ void CustomTrackView::slotUpdateAllThumbs() endThumb.append(QString::number((item->speedIndependantCropStart() + item->speedIndependantCropDuration()).frames(m_document->fps()) - 1) + ".png"); if (QFile::exists(startThumb)) { QPixmap pix(startThumb); + if (pix.isNull()) KIO::NetAccess::del(KUrl(startThumb), this); item->slotSetStartThumb(pix); } if (QFile::exists(endThumb)) { QPixmap pix(endThumb); + if (pix.isNull()) KIO::NetAccess::del(KUrl(endThumb), this); item->slotSetEndThumb(pix); } } } item->refreshClip(false); - qApp->processEvents(); + //qApp->processEvents(); } } viewport()->update(); @@ -5405,6 +5614,12 @@ void CustomTrackView::updateClipTypeActions(ClipItem *clip) } } +void CustomTrackView::slotGoToMarker(QAction *action) +{ + int pos = action->data().toInt(); + setCursorPos(pos, true); +} + void CustomTrackView::reloadTransitionLumas() { QString lumaNames; @@ -5509,8 +5724,8 @@ void CustomTrackView::slotTrackDown() if (m_selectedTrack > m_document->tracksCount() - 2) m_selectedTrack = 0; else m_selectedTrack++; emit updateTrackHeaders(); - QRectF rect(mapToScene(QPoint()).x(), m_selectedTrack * m_tracksHeight, 10, m_tracksHeight); - ensureVisible(rect); + QRectF rect(mapToScene(QPoint(10, 0)).x(), m_selectedTrack * m_tracksHeight, 10, m_tracksHeight); + ensureVisible(rect, 0, 0); viewport()->update(); } @@ -5519,8 +5734,8 @@ void CustomTrackView::slotTrackUp() if (m_selectedTrack > 0) m_selectedTrack--; else m_selectedTrack = m_document->tracksCount() - 1; emit updateTrackHeaders(); - QRectF rect(mapToScene(QPoint()).x(), m_selectedTrack * m_tracksHeight, 10, m_tracksHeight); - ensureVisible(rect); + QRectF rect(mapToScene(QPoint(10, 0)).x(), m_selectedTrack * m_tracksHeight, 10, m_tracksHeight); + ensureVisible(rect, 0, 0); viewport()->update(); } @@ -5534,8 +5749,8 @@ void CustomTrackView::slotSelectTrack(int ix) m_selectedTrack = qMax(0, ix); m_selectedTrack = qMin(ix, m_document->tracksCount() - 1); emit updateTrackHeaders(); - QRectF rect(mapToScene(QPoint()).x(), m_selectedTrack * m_tracksHeight, 10, m_tracksHeight); - ensureVisible(rect); + QRectF rect(mapToScene(QPoint(10, 0)).x(), m_selectedTrack * m_tracksHeight, 10, m_tracksHeight); + ensureVisible(rect, 0, 0); viewport()->update(); } @@ -5628,3 +5843,12 @@ void CustomTrackView::insertZoneOverwrite(QStringList data, int in) new AddTimelineClipCommand(this, clip->toXML(), clip->getId(), info, EffectsList(), true, false, true, false, addCommand); m_commandStack->push(addCommand); } + +void CustomTrackView::clearSelection() +{ + resetSelectionGroup(); + scene()->clearSelection(); + m_dragItem = NULL; + emit clipItemSelected(NULL); +} +