X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fcustomtrackview.cpp;h=5481cd81e1d399690eeea9f210bb85ff2d390647;hb=ead7176d2ab818ec3a1275aeca2b2fc0c1ea1276;hp=693be317be421b57b5c0472fa6494d9038f63eae;hpb=4bb67411893ec881bb21da7227a5b17a0c700d55;p=kdenlive diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 693be317..5481cd81 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -19,7 +19,6 @@ #include "customtrackview.h" -#include "customtrackscene.h" #include "docclipbase.h" #include "clipitem.h" #include "definitions.h" @@ -65,6 +64,8 @@ #include #include #include +#include +#include #include #include @@ -75,6 +76,10 @@ #include +#if QT_VERSION >= 0x040600 +#include +#endif + bool sortGuidesList(const Guide *g1 , const Guide *g2) { return (*g1).position() < (*g2).position(); @@ -114,7 +119,8 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscen m_copiedItems(), m_menuPosition(), m_blockRefresh(false), - m_selectionGroup(NULL) + m_selectionGroup(NULL), + m_selectedTrack(0) { if (doc) m_commandStack = doc->commandStack(); else m_commandStack = NULL; @@ -143,7 +149,7 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscen QPen pen1 = QPen(); pen1.setWidth(1); - pen1.setColor(Qt::black); + pen1.setColor(palette().text().color()); m_cursorLine->setPen(pen1); m_cursorLine->setFlag(QGraphicsItem::ItemIgnoresTransformations, true); @@ -167,19 +173,37 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscen CustomTrackView::~CustomTrackView() { qDeleteAll(m_guides); + m_guides.clear(); m_waitingThumbs.clear(); } +//virtual +void CustomTrackView::keyPressEvent(QKeyEvent * event) +{ + if (event->key() == Qt::Key_Up) { + slotTrackUp(); + event->accept(); + } else if (event->key() == Qt::Key_Down) { + slotTrackDown(); + event->accept(); + } else QWidget::keyPressEvent(event); +} + 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); @@ -236,11 +260,12 @@ void CustomTrackView::checkTrackHeight() transitionitem->setPos((qreal) transitionitem->startPos().frames(m_document->fps()), (qreal) transitionitem->track() * m_tracksHeight + m_tracksHeight / 3 * 2); } } - m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_document->tracksCount()); + double newHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22(); + m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight); for (int i = 0; i < m_guides.count(); i++) { QLineF l = m_guides.at(i)->line(); - l.setP2(QPointF(l.x2(), m_tracksHeight * m_document->tracksCount())); + l.setP2(QPointF(l.x2(), newHeight)); m_guides.at(i)->setLine(l); } @@ -319,11 +344,10 @@ void CustomTrackView::slotCheckPositionScrolling() // virtual - void CustomTrackView::mouseMoveEvent(QMouseEvent * event) { int pos = event->x(); - int mappedXPos = (int)(mapToScene(event->pos()).x() + 0.5); + int mappedXPos = qMax((int)(mapToScene(event->pos()).x() + 0.5), 0); double snappedPos = getSnapPointForPos(mappedXPos); emit mousePosition(mappedXPos); @@ -389,28 +413,99 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) return; } else if (m_operationMode == SPACER && move && m_selectionGroup) { // 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) { collision = true; 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++) { @@ -455,7 +550,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) // razor tool over a clip, display current frame in monitor if (false && !m_blockRefresh && item->type() == AVWIDGET) { //TODO: solve crash when showing frame when moving razor over clip - emit showClipFrame(((ClipItem *) item)->baseClip(), mappedXPos - (clip->startPos() - clip->cropStart()).frames(m_document->fps())); + emit showClipFrame(((ClipItem *) item)->baseClip(), QPoint(), mappedXPos - (clip->startPos() - clip->cropStart()).frames(m_document->fps())); } event->accept(); return; @@ -652,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; @@ -740,7 +835,14 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) if (m_dragItem) emit clipItemSelected(NULL); m_dragItem = NULL; } - +#if QT_VERSION >= 0x040600 + // Add shadow to dragged item, currently disabled because of painting artifacts + //TODO: re-enable when fixed + /*QGraphicsDropShadowEffect *eff = new QGraphicsDropShadowEffect(); + eff->setBlurRadius(5); + eff->setOffset(3, 3); + m_dragItem->setGraphicsEffect(eff);*/ +#endif if (m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) { // update transition menu action m_autoTransition->setChecked(static_cast(m_dragItem)->isAutomatic()); @@ -793,10 +895,16 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) if (event->modifiers() == Qt::ControlModifier) { // Ctrl + click, select all items on track after click position int track = (int)(mapToScene(m_clickEvent).y() / m_tracksHeight); + if (m_document->trackInfoAt(m_document->tracksCount() - track - 1).isLocked) { + // Cannot use spacer on locked track + emit displayMessage(i18n("Cannot use spacer in a locked track"), ErrorMessage); + return; + } + QRectF rect(mapToScene(m_clickEvent).x(), track * m_tracksHeight + m_tracksHeight / 2, sceneRect().width() - mapToScene(m_clickEvent).x(), m_tracksHeight / 2 - 2); bool isOk; - selection = checkForGroups(rect, isOk); + selection = checkForGroups(rect, &isOk); if (!isOk) { // groups found on track, do not allow the move emit displayMessage(i18n("Cannot use spacer in a track with a group"), ErrorMessage); @@ -810,18 +918,21 @@ 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)); + if (item->isItemLocked()) continue; offsetList.append(item->startPos()); offsetList.append(item->endPos()); m_selectionGroup->addToGroup(selection.at(i)); - selection.at(i)->setFlags(QGraphicsItem::ItemIsSelectable); - } else if (selection.at(i)->parentItem() == 0 && selection.at(i)->type() == GROUPWIDGET) { + selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false); + } 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++) { AbstractClipItem *item = static_cast(children.at(j)); @@ -829,13 +940,15 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) offsetList.append(item->endPos()); } m_selectionGroup->addToGroup(selection.at(i)); - selection.at(i)->setFlags(QGraphicsItem::ItemIsSelectable); - } else if (selection.at(i)->parentItem()) { + selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false); + } 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()->setFlags(QGraphicsItem::ItemIsSelectable); + selection.at(i)->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false); } } - + m_spacerOffset = m_selectionGroup->sceneBoundingRect().left() - (int)(mapToScene(m_clickEvent).x()); if (!offsetList.isEmpty()) { qSort(offsetList); QList cleandOffsetList; @@ -1039,11 +1152,11 @@ void CustomTrackView::resetSelectionGroup(bool selectItems) for (int i = 0; i < children.count(); i++) { if (children.at(i)->parentItem() == 0 && (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET)) { if (!static_cast (children.at(i))->isItemLocked()) { - children.at(i)->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + children.at(i)->setFlag(QGraphicsItem::ItemIsMovable, true); children.at(i)->setSelected(selectItems); } } else if (children.at(i)->type() == GROUPWIDGET) { - children.at(i)->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + children.at(i)->setFlag(QGraphicsItem::ItemIsMovable, true); children.at(i)->setSelected(selectItems); } } @@ -1102,7 +1215,7 @@ void CustomTrackView::groupSelectedItems(bool force, bool createNewGroup) for (int i = 0; i < selection.count(); i++) { if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET) { newGroup->addToGroup(selection.at(i)); - selection.at(i)->setFlags(QGraphicsItem::ItemIsSelectable); + selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false); } } KdenliveSettings::setSnaptopoints(snap); @@ -1117,7 +1230,7 @@ void CustomTrackView::groupSelectedItems(bool force, bool createNewGroup) for (int i = 0; i < selection.count(); i++) { if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) { m_selectionGroup->addToGroup(selection.at(i)); - selection.at(i)->setFlags(QGraphicsItem::ItemIsSelectable); + selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false); } } KdenliveSettings::setSnaptopoints(snap); @@ -1132,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); @@ -1153,49 +1267,75 @@ 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); + editClipDuration(); + } else { + QList collisionList = items(event->pos()); + if (collisionList.count() == 1 && collisionList.at(0)->type() == GUIDEITEM) { + Guide *editGuide = (Guide *) collisionList.at(0); + if (editGuide) slotEditGuide(editGuide->info()); + } + } +} + +void CustomTrackView::editClipDuration() +{ + AbstractClipItem *item; + if (m_dragItem) { + item = m_dragItem; + } + else { + GenTime pos = GenTime((int)(mapToScene(m_menuPosition).x()), m_document->fps()); + int track = (int)(mapToScene(m_menuPosition).y() / m_tracksHeight); + item = getClipItemAt(pos, track); + } + + if (item && !item->isItemLocked()) { GenTime minimum; GenTime maximum; - if (m_dragItem->type() == TRANSITIONWIDGET) { - getTransitionAvailableSpace(m_dragItem, minimum, maximum); + if (item->type() == TRANSITIONWIDGET) { + getTransitionAvailableSpace(item, minimum, maximum); } else { - getClipAvailableSpace(m_dragItem, minimum, maximum); + getClipAvailableSpace(item, minimum, maximum); } //kDebug()<<"// GOT MOVE POS: "<timecode(), minimum, maximum, this); if (d.exec() == QDialog::Accepted) { - if (m_dragItem->type() == TRANSITIONWIDGET) { + if (item->type() == TRANSITIONWIDGET) { // move & resize transition ItemInfo startInfo; - startInfo.startPos = m_dragItem->startPos(); - startInfo.endPos = m_dragItem->endPos(); - startInfo.track = m_dragItem->track(); + startInfo.startPos = item->startPos(); + startInfo.endPos = item->endPos(); + startInfo.track = item->track(); ItemInfo endInfo; endInfo.startPos = d.startPos(); endInfo.endPos = endInfo.startPos + d.duration(); - endInfo.track = m_dragItem->track(); + endInfo.track = item->track(); MoveTransitionCommand *command = new MoveTransitionCommand(this, startInfo, endInfo, true); m_commandStack->push(command); } else { // move and resize clip QUndoCommand *moveCommand = new QUndoCommand(); moveCommand->setText(i18n("Edit clip")); - ItemInfo clipInfo = m_dragItem->info(); - if (d.duration() < m_dragItem->cropDuration() || d.cropStart() != clipInfo.cropStart) { + ItemInfo clipInfo = item->info(); + if (d.duration() < item->cropDuration() || d.cropStart() != clipInfo.cropStart) { // duration was reduced, so process it first ItemInfo startInfo = clipInfo; clipInfo.endPos = clipInfo.startPos + d.duration(); @@ -1205,10 +1345,10 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) if (d.startPos() != clipInfo.startPos) { ItemInfo startInfo = clipInfo; clipInfo.startPos = d.startPos(); - clipInfo.endPos = m_dragItem->endPos() + (clipInfo.startPos - startInfo.startPos); + clipInfo.endPos = item->endPos() + (clipInfo.startPos - startInfo.startPos); new MoveClipCommand(this, startInfo, clipInfo, true, moveCommand); } - if (d.duration() > m_dragItem->cropDuration()) { + if (d.duration() > item->cropDuration()) { // duration was increased, so process it after move ItemInfo startInfo = clipInfo; clipInfo.endPos = clipInfo.startPos + d.duration(); @@ -1218,16 +1358,9 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) m_commandStack->push(moveCommand); } } - } else { - QList collisionList = items(event->pos()); - if (collisionList.count() == 1 && collisionList.at(0)->type() == GUIDEITEM) { - Guide *editGuide = (Guide *) collisionList.at(0); - if (editGuide) slotEditGuide(editGuide->info()); - } } } - void CustomTrackView::editKeyFrame(const GenTime pos, const int track, const int index, const QString keyframes) { ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), track); @@ -1242,8 +1375,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); @@ -1252,10 +1388,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); + } } } @@ -1264,18 +1416,43 @@ void CustomTrackView::activateMonitor() emit activateDocumentMonitor(); } +void CustomTrackView::insertClipCut(DocClipBase *clip, int in, int out) +{ + resetSelectionGroup(); + ItemInfo info; + info.startPos = GenTime(); + info.cropStart = GenTime(in, m_document->fps()); + info.endPos = GenTime(out - in, m_document->fps()); + info.cropDuration = info.endPos - info.startPos; + info.track = 0; + + // Check if clip can be inserted at that position + ItemInfo pasteInfo = info; + pasteInfo.startPos = GenTime(m_cursorPos, m_document->fps()); + pasteInfo.endPos = pasteInfo.startPos + info.endPos; + pasteInfo.track = selectedTrack(); + if (!canBePastedTo(pasteInfo, AVWIDGET)) { + emit displayMessage(i18n("Cannot insert clip in timeline"), ErrorMessage); + return; + } + + AddTimelineClipCommand *command = new AddTimelineClipCommand(this, clip->toXML(), clip->getId(), pasteInfo, EffectsList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, true, false); + m_commandStack->push(command); +} + 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) { kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << list.at(0); return false; } - const QPointF framePos = mapToScene(pos); + QPointF framePos = mapToScene(pos); ItemInfo info; info.startPos = GenTime(); info.cropStart = GenTime(list.at(1).toInt(), m_document->fps()); @@ -1288,19 +1465,22 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos) pasteInfo.startPos = GenTime((int)(framePos.x() + 0.5), m_document->fps()); pasteInfo.endPos = pasteInfo.startPos + info.endPos; pasteInfo.track = (int)(framePos.y() / m_tracksHeight); + framePos.setX((int)(framePos.x() + 0.5)); + framePos.setY(pasteInfo.track * m_tracksHeight); if (!canBePastedTo(pasteInfo, AVWIDGET)) { return true; } m_selectionGroup = new AbstractGroupItem(m_document->fps()); ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1); m_selectionGroup->addToGroup(item); - item->setFlags(QGraphicsItem::ItemIsSelectable); + item->setFlag(QGraphicsItem::ItemIsMovable, false); QList offsetList; offsetList.append(info.endPos); updateSnapPoints(NULL, offsetList); m_selectionGroup->setPos(framePos); scene()->addItem(m_selectionGroup); + m_selectionGroup->setSelected(true); return true; } else if (data->hasFormat("kdenlive/producerslist")) { m_clipDrag = true; @@ -1310,9 +1490,11 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos) QList offsetList; QList infoList; - const QPointF framePos = mapToScene(pos); + QPointF framePos = mapToScene(pos); GenTime start = GenTime((int)(framePos.x() + 0.5), m_document->fps()); int track = (int)(framePos.y() / m_tracksHeight); + framePos.setX((int)(framePos.x() + 0.5)); + framePos.setY(track * m_tracksHeight); // Check if clips can be inserted at that position for (int i = 0; i < ids.size(); ++i) { @@ -1344,14 +1526,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->setFlags(QGraphicsItem::ItemIsSelectable); + 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_thumbsTimer.start(); return true; @@ -1426,11 +1609,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); @@ -1451,8 +1629,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; } @@ -1484,7 +1662,7 @@ void CustomTrackView::slotAddGroupEffect(QDomElement effect, AbstractGroupItem * if (item->isAudioOnly() || item->clipType() == AUDIO) continue; } - if (item->hasEffect(effect.attribute("tag"), effect.attribute("id")) != -1 && effect.attribute("unique", "0") != "0") { + if (effect.attribute("unique", "0") != "0" && item->hasEffect(effect.attribute("tag"), effect.attribute("id")) != -1) { emit displayMessage(i18n("Effect already present in clip"), ErrorMessage); continue; } @@ -1516,14 +1694,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)); @@ -1556,17 +1744,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(); @@ -1574,12 +1795,16 @@ void CustomTrackView::slotDeleteEffect(ClipItem *clip, QDomElement effect) void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedEffect, int ix, bool triggeredByUser) { + if (insertedEffect.isNull()) { + emit displayMessage(i18n("Problem editing effect"), ErrorMessage); + return; + } ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track); QDomElement effect = insertedEffect.cloneNode().toElement(); 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(); @@ -1604,11 +1829,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); @@ -1655,7 +1876,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();; @@ -1674,16 +1895,17 @@ void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect m_commandStack->push(command); } -void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut) +ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, bool execute) { if (cut) { // cut clip 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; + return NULL; } if (item->parentItem()) { // Item is part of a group, reset group @@ -1691,7 +1913,7 @@ void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut) } kDebug() << "///////// CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25); - m_document->renderer()->mltCutClip(m_document->tracksCount() - info.track, cutTime); + if (execute) m_document->renderer()->mltCutClip(m_document->tracksCount() - info.track, cutTime); int cutPos = (int) cutTime.frames(m_document->fps()); ItemInfo newPos; newPos.startPos = cutTime; @@ -1700,7 +1922,8 @@ void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut) newPos.track = info.track; newPos.cropDuration = newPos.endPos - newPos.startPos; - + bool snap = KdenliveSettings::snaptopoints(); + KdenliveSettings::setSnaptopoints(false); ClipItem *dup = item->clone(newPos); // remove unwanted effects (fade in) from 2nd part of cutted clip int ix = dup->hasEffect(QString(), "fadein"); @@ -1720,20 +1943,23 @@ void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut) item->baseClip()->addReference(); m_document->updateClip(item->baseClip()->getId()); setDocumentModified(); + KdenliveSettings::setSnaptopoints(snap); + return dup; //kDebug() << "///////// CUTTING CLIP RESULT: (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), DUP: (" << dup->startPos().frames(25) << "-" << dup->endPos().frames(25) << ")" << ", CUT: " << cutTime.frames(25); } else { // uncut clip ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track); ClipItem *dup = getClipItemAt((int) cutTime.frames(m_document->fps()), info.track); + if (!item || !dup || item == dup) { emit displayMessage(i18n("Cannot find clip to uncut"), ErrorMessage); m_blockRefresh = false; - return; + return NULL; } if (m_document->renderer()->mltRemoveClip(m_document->tracksCount() - info.track, cutTime) == false) { emit displayMessage(i18n("Error removing clip at %1 on track %2", m_document->timecode().getTimecodeFromFrames(cutTime.frames(m_document->fps())), info.track), ErrorMessage); - return; + return NULL; } /*kDebug() << "// UNCUTTING CLIPS: ITEM 1 (" << item->startPos().frames(25) << "x" << item->endPos().frames(25) << ")"; @@ -1741,6 +1967,8 @@ void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut) kDebug() << "// UNCUTTING CLIPS, INFO (" << info.startPos.frames(25) << "x" << info.endPos.frames(25) << ") , CUT: " << cutTime.frames(25);;*/ //deleteClip(dup->info()); + bool snap = KdenliveSettings::snaptopoints(); + KdenliveSettings::setSnaptopoints(false); if (dup->isSelected()) emit clipItemSelected(NULL); dup->baseClip()->removeReference(); @@ -1756,9 +1984,11 @@ void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut) setDocumentModified(); } else emit displayMessage(i18n("Error when resizing clip"), ErrorMessage); + KdenliveSettings::setSnaptopoints(snap); + return item; } - QTimer::singleShot(3000, this, SLOT(slotEnableRefresh())); + //QTimer::singleShot(3000, this, SLOT(slotEnableRefresh())); } void CustomTrackView::slotEnableRefresh() @@ -1888,7 +2118,13 @@ void CustomTrackView::deleteTransition(ItemInfo transitionInfo, int endTrack, QD } m_document->renderer()->mltDeleteTransition(item->transitionTag(), endTrack, m_document->tracksCount() - transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, item->toXML(), refresh); if (m_dragItem == item) m_dragItem = NULL; + +#if QT_VERSION >= 0x040600 + // animate item deletion + item->closeAnimation(); +#else delete item; +#endif emit transitionItemSelected(NULL); setDocumentModified(); } @@ -1965,6 +2201,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)); @@ -1975,8 +2212,9 @@ void CustomTrackView::dropEvent(QDropEvent * event) updateClipTypeActions(NULL); } - new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, addCommand); + //TODO: take care of edit mode for undo item->baseClip()->addReference(); + //item->setZValue(item->defaultZValue()); m_document->updateClip(item->baseClip()->getId()); ItemInfo info = item->info(); @@ -1985,9 +2223,14 @@ void CustomTrackView::dropEvent(QDropEvent * event) if (isLocked) item->setItemLocked(true); ItemInfo clipInfo = info; clipInfo.track = m_document->tracksCount() - item->track(); - if (m_document->renderer()->mltInsertClip(clipInfo, item->xml(), item->baseClip()->producer(item->track())) == -1) { + 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); + + new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, false, false, addCommand); if (item->baseClip()->isTransparent() && getTransitionItemAtStart(info.startPos, info.track) == NULL) { // add transparency transition @@ -1996,8 +2239,30 @@ 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(); + + /* + // debug info + QRectF rect(0, 1 * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), 2); + QList selection = m_scene->items(rect); + QStringList timelineList; + + kDebug()<<"// ITEMS on TRACK: "<type() == AVWIDGET) { + ClipItem *clip = static_cast (selection.at(i)); + int start = clip->startPos().frames(m_document->fps()); + int end = clip->endPos().frames(m_document->fps()); + timelineList.append(QString::number(start) + "-" + QString::number(end)); + } + } + kDebug() << "// COMPARE:\n" << timelineList << "\n-------------------"; + */ + m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1); if (items.count() > 1) groupSelectedItems(true); event->setDropAction(Qt::MoveAction); @@ -2006,6 +2271,130 @@ void CustomTrackView::dropEvent(QDropEvent * event) setFocus(); } +void CustomTrackView::adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInfo posinfo, QUndoCommand *command) +{ + bool snap = KdenliveSettings::snaptopoints(); + KdenliveSettings::setSnaptopoints(false); + if (mode == OVERWRITEEDIT) { + // if we are in overwrite mode, move clips accordingly + ItemInfo info; + if (item == NULL) info = posinfo; + else info = item->info(); + QRectF rect(info.startPos.frames(m_document->fps()), info.track * m_tracksHeight + m_tracksHeight / 2, (info.endPos - info.startPos).frames(m_document->fps()) - 1, 5); + QList selection = m_scene->items(rect); + if (item) selection.removeAll(item); + for (int i = 0; i < selection.count(); i++) { + if (!selection.at(i)->isEnabled()) continue; + if (selection.at(i)->type() == AVWIDGET) { + ClipItem *clip = static_cast(selection.at(i)); + if (clip->startPos() < info.startPos) { + if (clip->endPos() > info.endPos) { + ItemInfo clipInfo = clip->info(); + ItemInfo dupInfo = clipInfo; + GenTime diff = info.startPos - clipInfo.startPos; + dupInfo.startPos = info.startPos; + dupInfo.cropStart += diff; + dupInfo.cropDuration = clipInfo.endPos - info.startPos; + ItemInfo newdupInfo = dupInfo; + GenTime diff2 = info.endPos - info.startPos; + newdupInfo.startPos = info.endPos; + newdupInfo.cropStart += diff2; + newdupInfo.cropDuration = clipInfo.endPos - info.endPos; + new RazorClipCommand(this, clipInfo, info.startPos, false, command); + new ResizeClipCommand(this, dupInfo, newdupInfo, false, false, command); + ClipItem *dup = cutClip(clipInfo, info.startPos, true, false); + if (dup) dup->resizeStart(info.endPos.frames(m_document->fps())); + } else { + ItemInfo newclipInfo = clip->info(); + newclipInfo.endPos = info.startPos; + new ResizeClipCommand(this, clip->info(), newclipInfo, false, false, command); + clip->resizeEnd(info.startPos.frames(m_document->fps())); + } + } 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; + clip = NULL; + } else { + ItemInfo newclipInfo = clip->info(); + newclipInfo.startPos = info.endPos; + new ResizeClipCommand(this, clip->info(), newclipInfo, false, false, command); + clip->resizeStart(info.endPos.frames(m_document->fps())); + } + } + } + } else if (mode == INSERTEDIT) { + // if we are in push mode, move clips accordingly + ItemInfo info; + if (item == NULL) info = posinfo; + else info = item->info(); + QRectF rect(info.startPos.frames(m_document->fps()), info.track * m_tracksHeight + m_tracksHeight / 2, (info.endPos - info.startPos).frames(m_document->fps()) - 1, 5); + QList selection = m_scene->items(rect); + if (item) selection.removeAll(item); + for (int i = 0; i < selection.count(); i++) { + if (selection.at(i)->type() == AVWIDGET) { + ClipItem *clip = static_cast(selection.at(i)); + if (clip->startPos() < info.startPos) { + if (clip->endPos() > info.startPos) { + ItemInfo clipInfo = clip->info(); + ItemInfo dupInfo = clipInfo; + GenTime diff = info.startPos - clipInfo.startPos; + dupInfo.startPos = info.startPos; + dupInfo.cropStart += diff; + dupInfo.cropDuration = clipInfo.endPos - info.startPos; + new RazorClipCommand(this, clipInfo, info.startPos, false, command); + // Commented out; variable dup unused. --granjow + //ClipItem *dup = cutClip(clipInfo, info.startPos, true, false); + cutClip(clipInfo, info.startPos, true, false); + } + } + // TODO: add insertspacecommand + } + } + } + + KdenliveSettings::setSnaptopoints(snap); +} + + +void CustomTrackView::adjustTimelineTransitions(EDITMODE mode, Transition *item, QUndoCommand *command) +{ + if (mode == OVERWRITEEDIT) { + // if we are in overwrite or push mode, move clips accordingly + bool snap = KdenliveSettings::snaptopoints(); + KdenliveSettings::setSnaptopoints(false); + ItemInfo info = item->info(); + QRectF rect(info.startPos.frames(m_document->fps()), info.track * m_tracksHeight + m_tracksHeight, (info.endPos - info.startPos).frames(m_document->fps()) - 1, 5); + QList selection = m_scene->items(rect); + selection.removeAll(item); + for (int i = 0; i < selection.count(); i++) { + if (!selection.at(i)->isEnabled()) continue; + if (selection.at(i)->type() == TRANSITIONWIDGET) { + Transition *tr = static_cast(selection.at(i)); + if (tr->startPos() < info.startPos) { + ItemInfo firstPos = tr->info(); + ItemInfo newPos = firstPos; + firstPos.endPos = item->startPos(); + newPos.startPos = item->endPos(); + new MoveTransitionCommand(this, tr->info(), firstPos, true, command); + if (tr->endPos() > info.endPos) { + // clone transition + new AddTransitionCommand(this, newPos, tr->transitionEndTrack(), tr->toXML(), false, true, command); + } + } else if (tr->endPos() > info.endPos) { + // just resize + ItemInfo firstPos = tr->info(); + firstPos.startPos = item->endPos(); + new MoveTransitionCommand(this, tr->info(), firstPos, true, command); + } else { + // remove transition + new AddTransitionCommand(this, tr->info(), tr->transitionEndTrack(), tr->toXML(), true, true, command); + } + } + } + KdenliveSettings::setSnaptopoints(snap); + } +} QStringList CustomTrackView::mimeTypes() const { @@ -2041,7 +2430,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); @@ -2058,7 +2447,7 @@ void CustomTrackView::addTrack(TrackInfo type, int ix) for (int i = 0; i < selection.count(); i++) { if ((!selection.at(i)->parentItem()) && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) { m_selectionGroup->addToGroup(selection.at(i)); - selection.at(i)->setFlags(QGraphicsItem::ItemIsSelectable); + selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false); } } // Move graphic items @@ -2077,6 +2466,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; @@ -2099,14 +2490,14 @@ void CustomTrackView::addTrack(TrackInfo type, int ix) resetSelectionGroup(false); } - int maxHeight = m_tracksHeight * m_document->tracksCount(); + int maxHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22(); for (int i = 0; i < m_guides.count(); i++) { QLineF l = m_guides.at(i)->line(); l.setP2(QPointF(l.x2(), maxHeight)); m_guides.at(i)->setLine(l); } m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight); - setSceneRect(0, 0, sceneRect().width(), maxHeight); + setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount()); viewport()->update(); emit tracksChanged(); //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged())); @@ -2130,7 +2521,7 @@ void CustomTrackView::removeTrack(int ix) for (int i = 0; i < selection.count(); i++) { if ((!selection.at(i)->parentItem()) && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) { m_selectionGroup->addToGroup(selection.at(i)); - selection.at(i)->setFlags(QGraphicsItem::ItemIsSelectable); + selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false); } } // Move graphic items @@ -2172,14 +2563,16 @@ void CustomTrackView::removeTrack(int ix) } resetSelectionGroup(false); - int maxHeight = m_tracksHeight * m_document->tracksCount(); + int maxHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22(); for (int i = 0; i < m_guides.count(); i++) { QLineF l = m_guides.at(i)->line(); l.setP2(QPointF(l.x2(), maxHeight)); m_guides.at(i)->setLine(l); } m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight); - setSceneRect(0, 0, sceneRect().width(), maxHeight); + setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount()); + + m_selectedTrack = qMin(m_selectedTrack, m_document->tracksCount() - 1); viewport()->update(); emit tracksChanged(); //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged())); @@ -2242,18 +2635,19 @@ void CustomTrackView::slotSwitchTrackVideo(int ix) setDocumentModified(); } -QList CustomTrackView::checkForGroups(const QRectF &rect, bool &ok) +QList CustomTrackView::checkForGroups(const QRectF &rect, bool *ok) { // Check there is no group going over several tracks there, or that would result in timeline corruption QList selection = scene()->items(rect); + *ok = true; int maxHeight = m_tracksHeight * 1.5; for (int i = 0; i < selection.count(); i++) { // Check that we don't try to move a group with clips on other tracks if (selection.at(i)->type() == GROUPWIDGET && (selection.at(i)->boundingRect().height() >= maxHeight)) { - ok = false; + *ok = false; break; } else if (selection.at(i)->parentItem() && (selection.at(i)->parentItem()->boundingRect().height() >= maxHeight)) { - ok = false; + *ok = false; break; } } @@ -2282,7 +2676,7 @@ void CustomTrackView::slotRemoveSpace() int length = m_document->renderer()->mltGetSpaceLength(pos, m_document->tracksCount() - track, true); //kDebug() << "// GOT LENGT; " << length; if (length <= 0) { - emit displayMessage(i18n("You must be in an empty space to remove space (time: %1, track:%2)", m_document->timecode().getTimecodeFromFrames(mapToScene(m_menuPosition).x()), track), ErrorMessage); + emit displayMessage(i18n("You must be in an empty space to remove space (time: %1, track: %2)", m_document->timecode().getTimecodeFromFrames(mapToScene(m_menuPosition).x()), track), ErrorMessage); return; } @@ -2290,7 +2684,7 @@ void CustomTrackView::slotRemoveSpace() QRectF rect(pos.frames(m_document->fps()), track * m_tracksHeight + m_tracksHeight / 2, sceneRect().width() - pos.frames(m_document->fps()), m_tracksHeight / 2 - 2); bool isOk; - QList items = checkForGroups(rect, isOk); + QList items = checkForGroups(rect, &isOk); if (!isOk) { // groups found on track, do not allow the move emit displayMessage(i18n("Cannot remove space in a track with a group"), ErrorMessage); @@ -2337,7 +2731,7 @@ void CustomTrackView::slotInsertSpace() // Make sure there is no group in the way QRectF rect(pos.frames(m_document->fps()), track * m_tracksHeight + m_tracksHeight / 2, sceneRect().width() - pos.frames(m_document->fps()), m_tracksHeight / 2 - 2); bool isOk; - QList items = checkForGroups(rect, isOk); + QList items = checkForGroups(rect, &isOk); if (!isOk) { // groups found on track, do not allow the move emit displayMessage(i18n("Cannot insert space in a track with a group"), ErrorMessage); @@ -2386,10 +2780,10 @@ void CustomTrackView::insertSpace(QList clipsToMove, QList t if (clip) { if (clip->parentItem()) { m_selectionGroup->addToGroup(clip->parentItem()); - clip->parentItem()->setFlags(QGraphicsItem::ItemIsSelectable); + clip->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false); } else { m_selectionGroup->addToGroup(clip); - clip->setFlags(QGraphicsItem::ItemIsSelectable); + clip->setFlag(QGraphicsItem::ItemIsMovable, false); } if (trackClipStartList.value(m_document->tracksCount() - clipsToMove.at(i).track) == -1 || clipsToMove.at(i).startPos.frames(m_document->fps()) < trackClipStartList.value(m_document->tracksCount() - clipsToMove.at(i).track)) trackClipStartList[m_document->tracksCount() - clipsToMove.at(i).track] = clipsToMove.at(i).startPos.frames(m_document->fps()); @@ -2402,10 +2796,10 @@ void CustomTrackView::insertSpace(QList clipsToMove, QList t if (transition) { if (transition->parentItem()) { m_selectionGroup->addToGroup(transition->parentItem()); - transition->parentItem()->setFlags(QGraphicsItem::ItemIsSelectable); + transition->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false); } else { m_selectionGroup->addToGroup(transition); - transition->setFlags(QGraphicsItem::ItemIsSelectable); + transition->setFlag(QGraphicsItem::ItemIsMovable, false); } if (trackTransitionStartList.value(m_document->tracksCount() - transToMove.at(i).track) == -1 || transToMove.at(i).startPos.frames(m_document->fps()) < trackTransitionStartList.value(m_document->tracksCount() - transToMove.at(i).track)) trackTransitionStartList[m_document->tracksCount() - transToMove.at(i).track] = transToMove.at(i).startPos.frames(m_document->fps()); @@ -2447,7 +2841,7 @@ void CustomTrackView::deleteClip(const QString &clipId) // Clip is in a group, destroy the group new GroupClipsCommand(this, QList() << item->info(), QList(), false, deleteCommand); } - new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), true, true, deleteCommand); + new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, true, true, deleteCommand); } } } @@ -2503,6 +2897,9 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) if (m_moveOpMode == SEEK) m_moveOpMode = NONE; QGraphicsView::mouseReleaseEvent(event); setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate); +#if QT_VERSION >= 0x040600 + if (m_dragItem) m_dragItem->setGraphicsEffect(NULL); +#endif if (m_scrollTimer.isActive()) m_scrollTimer.stop(); if (event->button() == Qt::MidButton) { return; @@ -2593,7 +2990,6 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) if (m_operationMode == MOVE) { setCursor(Qt::OpenHandCursor); - 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)) { @@ -2602,14 +2998,16 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) if (item->isAudioOnly()) prod = item->baseClip()->audioProducer(m_dragItemInfo.track); else if (item->isVideoOnly()) prod = item->baseClip()->videoProducer(); else prod = item->baseClip()->producer(m_dragItemInfo.track); - bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - m_dragItemInfo.track), (int)(m_document->tracksCount() - m_dragItem->track()), (int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(m_dragItem->startPos().frames(m_document->fps())), prod); + bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - m_dragItemInfo.track), (int)(m_document->tracksCount() - m_dragItem->track()), (int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(m_dragItem->startPos().frames(m_document->fps())), prod, m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT); if (success) { + QUndoCommand *moveCommand = new QUndoCommand(); + moveCommand->setText(i18n("Move clip")); + adjustTimelineClips(m_scene->editMode(), item, ItemInfo(), moveCommand); + int tracknumber = m_document->tracksCount() - item->track() - 1; bool isLocked = m_document->trackInfoAt(tracknumber).isLocked; if (isLocked) item->setItemLocked(true); - QUndoCommand *moveCommand = new QUndoCommand(); - moveCommand->setText(i18n("Move clip")); new MoveClipCommand(this, m_dragItemInfo, info, false, moveCommand); // Also move automatic transitions (on lower track) Transition *startTransition = getTransitionItemAtStart(m_dragItemInfo.startPos, m_dragItemInfo.track); @@ -2650,6 +3048,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) // we have to move both transitions, remove the start one so that there is no collision new AddTransitionCommand(this, startTrInfo, startTransition->transitionEndTrack(), startTransition->toXML(), true, true, moveCommand); } + adjustTimelineTransitions(m_scene->editMode(), tr, moveCommand); new MoveTransitionCommand(this, trInfo, newTrInfo, true, moveCommand); if (moveStartTrans) { // re-add transition in correct place @@ -2657,13 +3056,17 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) if (m_dragItemInfo.track != info.track && !startTransition->forcedTrack()) { transTrack = getPreviousVideoTrack(info.track); } + adjustTimelineTransitions(m_scene->editMode(), startTransition, moveCommand); new AddTransitionCommand(this, newStartTrInfo, transTrack, startTransition->toXML(), false, true, moveCommand); } } } } - if (moveStartTrans && !moveEndTrans) new MoveTransitionCommand(this, startTrInfo, newStartTrInfo, true, moveCommand); + if (moveStartTrans && !moveEndTrans) { + adjustTimelineTransitions(m_scene->editMode(), startTransition, moveCommand); + new MoveTransitionCommand(this, startTrInfo, newStartTrInfo, true, moveCommand); + } // Also move automatic transitions (on upper track) Transition *tr = getTransitionItemAtStart(m_dragItemInfo.startPos, m_dragItemInfo.track - 1); @@ -2677,7 +3080,10 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) // transition end should be adjusted to clip on upper track newTrInfo.endPos = newTrInfo.endPos + (newTrInfo.startPos - trInfo.startPos); } - if (newTrInfo.startPos < newTrInfo.endPos) new MoveTransitionCommand(this, trInfo, newTrInfo, true, moveCommand); + if (newTrInfo.startPos < newTrInfo.endPos) { + adjustTimelineTransitions(m_scene->editMode(), tr, moveCommand); + new MoveTransitionCommand(this, trInfo, newTrInfo, true, moveCommand); + } } } if (m_dragItemInfo.track == info.track && (tr == NULL || tr->endPos() < m_dragItemInfo.endPos)) { @@ -2695,11 +3101,15 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) // transition start should be moved newTrInfo.startPos = newTrInfo.startPos + (newTrInfo.endPos - trInfo.endPos); } - if (newTrInfo.startPos < newTrInfo.endPos) new MoveTransitionCommand(this, trInfo, newTrInfo, true, moveCommand); + if (newTrInfo.startPos < newTrInfo.endPos) { + adjustTimelineTransitions(m_scene->editMode(), tr, moveCommand); + new MoveTransitionCommand(this, trInfo, newTrInfo, true, moveCommand); + } } } } m_commandStack->push(moveCommand); + //checkTrackSequence(m_dragItem->track()); } else { // undo last move and emit error message bool snap = KdenliveSettings::snaptopoints(); @@ -2712,16 +3122,17 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) } if (m_dragItem->type() == TRANSITIONWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) { Transition *transition = static_cast (m_dragItem); - int transitionTrack; transition->updateTransitionEndTrack(getPreviousVideoTrack(m_dragItem->track())); if (!m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_document->tracksCount() - m_dragItemInfo.track), (int)(m_document->tracksCount() - m_dragItem->track()), transition->transitionEndTrack(), m_dragItemInfo.startPos, m_dragItemInfo.endPos, info.startPos, info.endPos)) { // Moving transition failed, revert to previous position emit displayMessage(i18n("Cannot move transition"), ErrorMessage); transition->setPos((int) m_dragItemInfo.startPos.frames(m_document->fps()), (m_dragItemInfo.track) * m_tracksHeight + 1); } else { - MoveTransitionCommand *command = new MoveTransitionCommand(this, m_dragItemInfo, info, false); - m_commandStack->push(command); - transition->updateTransitionEndTrack(transitionTrack); + QUndoCommand *moveCommand = new QUndoCommand(); + moveCommand->setText(i18n("Move transition")); + adjustTimelineTransitions(m_scene->editMode(), transition, moveCommand); + new MoveTransitionCommand(this, m_dragItemInfo, info, false, moveCommand); + m_commandStack->push(moveCommand); } } } else { @@ -2736,6 +3147,8 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) GenTime timeOffset = GenTime(m_dragItem->scenePos().x(), m_document->fps()) - m_dragItemInfo.startPos; const int trackOffset = (int)(m_dragItem->scenePos().y() / m_tracksHeight) - m_dragItemInfo.track; //kDebug() << "// MOVED SEVERAL CLIPS" << timeOffset.frames(25); + QUndoCommand *moveGroup = new QUndoCommand(); + moveGroup->setText(i18n("Move group")); if (timeOffset != GenTime() || trackOffset != 0) { // remove items in MLT playlist @@ -2782,10 +3195,11 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) ClipItem *clip = static_cast (item); info.track = m_document->tracksCount() - info.track; Mlt::Producer *prod; + adjustTimelineClips(m_scene->editMode(), clip, ItemInfo(), moveGroup); if (clip->isAudioOnly()) prod = clip->baseClip()->audioProducer(info.track); else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer(); else prod = clip->baseClip()->producer(info.track); - m_document->renderer()->mltInsertClip(info, clip->xml(), prod); + m_document->renderer()->mltInsertClip(info, clip->xml(), prod, m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT); for (int i = 0; i < clip->effectsCount(); i++) { m_document->renderer()->mltAddEffect(info.track, info.startPos, clip->getEffectArgs(clip->effectAt(i)), false); } @@ -2796,12 +3210,13 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) newTrack = getPreviousVideoTrack(info.track); } tr->updateTransitionEndTrack(newTrack); + adjustTimelineTransitions(m_scene->editMode(), tr, moveGroup); m_document->renderer()->mltAddTransition(tr->transitionTag(), newTrack, m_document->tracksCount() - info.track, info.startPos, info.endPos, tr->toXML()); } } - MoveGroupCommand *move = new MoveGroupCommand(this, clipsToMove, transitionsToMove, timeOffset, trackOffset, false); - m_commandStack->push(move); + new MoveGroupCommand(this, clipsToMove, transitionsToMove, timeOffset, trackOffset, false, moveGroup); + m_commandStack->push(moveGroup); //QPointF top = group->sceneBoundingRect().topLeft(); //QPointF oldpos = m_selectionGroup->scenePos(); @@ -2882,14 +3297,20 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) m_commandStack->push(resizeCommand); } else { + bool snap = KdenliveSettings::snaptopoints(); + KdenliveSettings::setSnaptopoints(false); m_dragItem->resizeStart((int) m_dragItemInfo.startPos.frames(m_document->fps())); + KdenliveSettings::setSnaptopoints(snap); emit displayMessage(i18n("Error when resizing clip"), ErrorMessage); } } else if (m_dragItem->type() == TRANSITIONWIDGET) { Transition *transition = static_cast (m_dragItem); if (!m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_document->tracksCount() - m_dragItemInfo.track), (int)(m_document->tracksCount() - m_dragItemInfo.track), transition->transitionEndTrack(), m_dragItemInfo.startPos, m_dragItemInfo.endPos, info.startPos, info.endPos)) { // Cannot resize transition + bool snap = KdenliveSettings::snaptopoints(); + KdenliveSettings::setSnaptopoints(false); transition->resizeStart((int) m_dragItemInfo.startPos.frames(m_document->fps())); + KdenliveSettings::setSnaptopoints(snap); emit displayMessage(i18n("Cannot resize transition"), ErrorMessage); } else { MoveTransitionCommand *command = new MoveTransitionCommand(this, m_dragItemInfo, info, false); @@ -3010,7 +3431,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(); @@ -3033,7 +3454,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(); @@ -3053,7 +3474,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(); @@ -3078,7 +3499,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(); @@ -3092,10 +3513,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()); @@ -3139,9 +3576,21 @@ void CustomTrackView::deleteClip(ItemInfo info, bool refresh) }*/ m_waitingThumbs.removeAll(item); if (m_dragItem == item) m_dragItem = NULL; - scene()->removeItem(item); +#if QT_VERSION >= 0x040600 + // animate item deletion + item->closeAnimation(); + /*if (refresh) item->closeAnimation(); + else { + // no refresh, means we have several operations chained, we need to delete clip immediatly + // so that it does not get in the way of the other + delete item; + item = NULL; + }*/ +#else delete item; item = NULL; +#endif + setDocumentModified(); if (refresh) m_document->renderer()->doRefresh(); } @@ -3191,7 +3640,7 @@ void CustomTrackView::deleteSelectedClips() ClipItem *item = static_cast (itemList.at(i)); if (item->parentItem()) resetGroup = true; //kDebug()<<"// DELETE CLP AT: "<info().startPos.frames(25); - new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), true, true, deleteSelected); + new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, true, true, deleteSelected); emit clipItemSelected(NULL); } else if (itemList.at(i)->type() == TRANSITIONWIDGET) { transitionCount++; @@ -3251,7 +3700,10 @@ void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependant return; } info.track = m_document->tracksCount() - item->track(); - int endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->producer()); + int endPos; + if (item->isVideoOnly()) endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->videoProducer()); + else if (item->isAudioOnly()) endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->audioProducer(item->track())); + else endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->producer()); if (endPos >= 0) { item->setSpeed(speed, strobe); item->updateRectGeometry(); @@ -3323,7 +3775,7 @@ void CustomTrackView::doGroupClips(QList clipInfos, QList m_document->clipManager()->removeGroup(grp); scene()->destroyItemGroup(grp); } - clip->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + clip->setFlag(QGraphicsItem::ItemIsMovable, true); } for (int i = 0; i < transitionInfos.count(); i++) { Transition *tr = getTransitionItemAt(transitionInfos.at(i).startPos, transitionInfos.at(i).track); @@ -3333,7 +3785,7 @@ void CustomTrackView::doGroupClips(QList clipInfos, QList m_document->clipManager()->removeGroup(grp); scene()->destroyItemGroup(grp); } - tr->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + tr->setFlag(QGraphicsItem::ItemIsMovable, true); } setDocumentModified(); return; @@ -3357,7 +3809,7 @@ void CustomTrackView::doGroupClips(QList clipInfos, QList setDocumentModified(); } -void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo info, EffectsList effects, bool refresh) +void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo info, EffectsList effects, bool overwrite, bool push, bool refresh) { DocClipBase *baseclip = m_document->clipManager()->getClipById(clipId); if (baseclip == NULL) { @@ -3381,13 +3833,13 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i if (item->isAudioOnly()) prod = baseclip->audioProducer(info.track); else if (item->isVideoOnly()) prod = baseclip->videoProducer(); else prod = baseclip->producer(info.track); - m_document->renderer()->mltInsertClip(info, xml, prod); + m_document->renderer()->mltInsertClip(info, xml, prod, overwrite, push); for (int i = 0; i < item->effectsCount(); i++) { m_document->renderer()->mltAddEffect(info.track, info.startPos, item->getEffectArgs(item->effectAt(i)), false); } setDocumentModified(); if (refresh) m_document->renderer()->doRefresh(); - m_waitingThumbs.append(item); + if (!baseclip->isPlaceHolder()) m_waitingThumbs.append(item); m_thumbsTimer.start(); } @@ -3417,6 +3869,7 @@ ClipItem *CustomTrackView::getClipItemAtEnd(GenTime pos, int track) QList list = scene()->items(QPointF(framepos - 1, track * m_tracksHeight + m_tracksHeight / 2)); ClipItem *clip = NULL; for (int i = 0; i < list.size(); i++) { + if (!list.at(i)->isEnabled()) continue; if (list.at(i)->type() == AVWIDGET) { ClipItem *test = static_cast (list.at(i)); if (test->endPos() == pos) clip = test; @@ -3431,6 +3884,7 @@ ClipItem *CustomTrackView::getClipItemAtStart(GenTime pos, int track) QList list = scene()->items(QPointF(pos.frames(m_document->fps()), track * m_tracksHeight + m_tracksHeight / 2)); ClipItem *clip = NULL; for (int i = 0; i < list.size(); i++) { + if (!list.at(i)->isEnabled()) continue; if (list.at(i)->type() == AVWIDGET) { ClipItem *test = static_cast (list.at(i)); if (test->startPos() == pos) clip = test; @@ -3446,6 +3900,7 @@ ClipItem *CustomTrackView::getClipItemAt(int pos, int track) QList list = scene()->items(p); ClipItem *clip = NULL; for (int i = 0; i < list.size(); i++) { + if (!list.at(i)->isEnabled()) continue; if (list.at(i)->type() == AVWIDGET) { clip = static_cast (list.at(i)); break; @@ -3465,6 +3920,7 @@ Transition *CustomTrackView::getTransitionItemAt(int pos, int track) QList list = scene()->items(p); Transition *clip = NULL; for (int i = 0; i < list.size(); i++) { + if (!list.at(i)->isEnabled()) continue; if (list.at(i)->type() == TRANSITIONWIDGET) { clip = static_cast (list.at(i)); break; @@ -3485,6 +3941,7 @@ Transition *CustomTrackView::getTransitionItemAtEnd(GenTime pos, int track) QList list = scene()->items(p); Transition *clip = NULL; for (int i = 0; i < list.size(); i++) { + if (!list.at(i)->isEnabled()) continue; if (list.at(i)->type() == TRANSITIONWIDGET) { Transition *test = static_cast (list.at(i)); if (test->endPos() == pos) clip = test; @@ -3500,6 +3957,7 @@ Transition *CustomTrackView::getTransitionItemAtStart(GenTime pos, int track) QList list = scene()->items(p); Transition *clip = NULL; for (int i = 0; i < list.size(); ++i) { + if (!list.at(i)->isEnabled()) continue; if (list.at(i)->type() == TRANSITIONWIDGET) { Transition *test = static_cast (list.at(i)); if (test->startPos() == pos) clip = test; @@ -3579,10 +4037,10 @@ void CustomTrackView::moveGroup(QList startClip, QList sta clip->setItemLocked(false); if (clip->parentItem()) { m_selectionGroup->addToGroup(clip->parentItem()); - clip->parentItem()->setFlags(QGraphicsItem::ItemIsSelectable); + clip->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false); } else { m_selectionGroup->addToGroup(clip); - clip->setFlags(QGraphicsItem::ItemIsSelectable); + clip->setFlag(QGraphicsItem::ItemIsMovable, false); } m_document->renderer()->mltRemoveClip(m_document->tracksCount() - startClip.at(i).track, startClip.at(i).startPos); } else kDebug() << "//MISSING CLIP AT: " << startClip.at(i).startPos.frames(25); @@ -3597,10 +4055,10 @@ void CustomTrackView::moveGroup(QList startClip, QList sta tr->setItemLocked(false); if (tr->parentItem()) { m_selectionGroup->addToGroup(tr->parentItem()); - tr->parentItem()->setFlags(QGraphicsItem::ItemIsSelectable); + tr->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false); } else { m_selectionGroup->addToGroup(tr); - tr->setFlags(QGraphicsItem::ItemIsSelectable); + tr->setFlag(QGraphicsItem::ItemIsMovable, false); } m_document->renderer()->mltDeleteTransition(tr->transitionTag(), tr->transitionEndTrack(), m_document->tracksCount() - startTransition.at(i).track, startTransition.at(i).startPos, startTransition.at(i).endPos, tr->toXML()); } else kDebug() << "//MISSING TRANSITION AT: " << startTransition.at(i).startPos.frames(25); @@ -3648,18 +4106,15 @@ void CustomTrackView::moveGroup(QList startClip, QList sta else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer(); else prod = clip->baseClip()->producer(info.track); m_document->renderer()->mltInsertClip(info, clip->xml(), prod); - kDebug() << "// inserting new clp: " << info.startPos.frames(25); } else if (item->type() == TRANSITIONWIDGET) { Transition *tr = static_cast (item); int newTrack; - kDebug() << "/// TRANSITION CURR TRK: " << newTrack; if (!tr->forcedTrack()) newTrack = getPreviousVideoTrack(info.track); else { newTrack = tr->transitionEndTrack() + trackOffset; if (newTrack < 0 || newTrack > m_document->tracksCount()) newTrack = getPreviousVideoTrack(info.track); } tr->updateTransitionEndTrack(newTrack); - kDebug() << "/// TRANSITION UPDATED TRK: " << newTrack; m_document->renderer()->mltAddTransition(tr->transitionTag(), newTrack, m_document->tracksCount() - info.track, info.startPos, info.endPos, tr->toXML()); } } @@ -3700,7 +4155,7 @@ void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end, b //item->moveTransition(GenTime((int) (endPos.x() - startPos.x()), m_document->fps())); KdenliveSettings::setSnaptopoints(snap); item->updateTransitionEndTrack(getPreviousVideoTrack(end.track)); - m_document->renderer()->mltMoveTransition(item->transitionTag(), m_document->tracksCount() - start.track, m_document->tracksCount() - end.track, item->transitionEndTrack(), start.startPos, start.endPos, end.startPos, end.endPos); + m_document->renderer()->mltMoveTransition(item->transitionTag(), m_document->tracksCount() - start.track, m_document->tracksCount() - item->track(), item->transitionEndTrack(), start.startPos, start.endPos, item->startPos(), item->endPos()); if (m_dragItem && m_dragItem == item) { QPoint p; ClipItem *transitionClip = getClipItemAt(item->startPos(), item->track()); @@ -3854,7 +4309,7 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info) // Freeze effect needs to be adjusted with clip resize int diff = (info.startPos - item->startPos()).frames(m_document->fps()); QDomElement eff = item->getEffectAt(effectPos); - if (!eff.isNull()) { + if (!eff.isNull() && diff != 0) { int freeze_pos = EffectsList::parameter(eff, "frame").toInt() + diff; EffectsList::setParameter(eff, "frame", QString::number(freeze_pos)); if (item->isSelected() && item->selectedEffect().attribute("id") == "freeze") { @@ -4061,7 +4516,7 @@ bool CustomTrackView::addGuide(const GenTime pos, const QString &comment) return false; } } - Guide *g = new Guide(this, pos, comment, m_tracksHeight * m_document->tracksCount()); + Guide *g = new Guide(this, pos, comment, m_tracksHeight * m_document->tracksCount() * matrix().m22()); scene()->addItem(g); m_guides.append(g); qSort(m_guides.begin(), m_guides.end(), sortGuidesList); @@ -4160,8 +4615,8 @@ void CustomTrackView::setTool(PROJECTTOOL tool) void CustomTrackView::setScale(double scaleFactor, double verticalScale) { - QMatrix matrix; - matrix = matrix.scale(scaleFactor, verticalScale); + QMatrix newmatrix; + newmatrix = newmatrix.scale(scaleFactor, verticalScale); m_scene->setScale(scaleFactor, verticalScale); if (m_visualTip) { scene()->removeItem(m_visualTip); @@ -4172,11 +4627,23 @@ void CustomTrackView::setScale(double scaleFactor, double verticalScale) m_visualTip = NULL; } double verticalPos = mapToScene(QPoint(0, viewport()->height() / 2)).y(); - setMatrix(matrix); - m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_document->tracksCount() * verticalScale); + bool adjust = false; + if (verticalScale != matrix().m22()) adjust = true; + setMatrix(newmatrix); + if (adjust) { + double newHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22(); + m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight); + for (int i = 0; i < m_guides.count(); i++) { + QLineF l = m_guides.at(i)->line(); + l.setP2(QPointF(l.x2(), newHeight)); + m_guides.at(i)->setLine(l); + } + setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount()); + } + int diff = sceneRect().width() - m_projectDuration; - if (diff * matrix.m11() < 50) { - if (matrix.m11() < 0.4) setSceneRect(0, 0, (m_projectDuration + 100 / matrix.m11()), sceneRect().height()); + if (diff * newmatrix.m11() < 50) { + if (newmatrix.m11() < 0.4) setSceneRect(0, 0, (m_projectDuration + 100 / newmatrix.m11()), sceneRect().height()); else setSceneRect(0, 0, (m_projectDuration + 300), sceneRect().height()); } centerOn(QPointF(cursorPos(), verticalPos)); @@ -4202,15 +4669,16 @@ void CustomTrackView::drawBackground(QPainter * painter, const QRectF &rect) double min = rect.left(); double max = rect.right(); painter->drawLine(QPointF(min, 0), QPointF(max, 0)); - uint maxTrack = m_document->tracksCount(); + int maxTrack = m_document->tracksCount(); QColor lockedColor = scheme.background(KColorScheme::NegativeBackground).color(); QColor audioColor = palette().alternateBase().color(); QColor base = scheme.background(KColorScheme::NormalBackground).color(); - for (uint i = 0; i < maxTrack; i++) { + for (int i = 0; i < maxTrack; i++) { TrackInfo info = m_document->trackInfoAt(maxTrack - i - 1); - if (info.isLocked || info.type == AUDIOTRACK) { + if (info.isLocked || info.type == AUDIOTRACK || i == m_selectedTrack) { const QRectF track(min, m_tracksHeight * i + 1, max - min, m_tracksHeight - 1); - painter->fillRect(track, info.isLocked ? lockedColor : audioColor); + if (i == m_selectedTrack) painter->fillRect(track, scheme.background(KColorScheme::ActiveBackground).color()); + else painter->fillRect(track, info.isLocked ? lockedColor : audioColor); } painter->drawLine(QPointF(min, m_tracksHeight *(i + 1)), QPointF(max, m_tracksHeight *(i + 1))); } @@ -4310,6 +4778,10 @@ void CustomTrackView::copyClip() bool CustomTrackView::canBePastedTo(ItemInfo info, int type) const { + if (m_scene->editMode() != NORMALEDIT) { + // If we are in overwrite mode, always allow the move + return true; + } QRectF rect((double) info.startPos.frames(m_document->fps()), (double)(info.track * m_tracksHeight + 1), (double)(info.endPos - info.startPos).frames(m_document->fps()), (double)(m_tracksHeight - 1)); QList collisions = scene()->items(rect, Qt::IntersectsItemBoundingRect); for (int i = 0; i < collisions.count(); i++) { @@ -4408,7 +4880,7 @@ void CustomTrackView::pasteClip() info.endPos += offset; info.track += trackOffset; if (canBePastedTo(info, AVWIDGET)) { - new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), info, clip->effectList(), true, false, pasteClips); + new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), info, clip->effectList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, true, false, pasteClips); } else emit displayMessage(i18n("Cannot paste clip to selected place"), ErrorMessage); } else if (m_copiedItems.at(i) && m_copiedItems.at(i)->type() == TRANSITIONWIDGET) { Transition *tr = static_cast (m_copiedItems.at(i)); @@ -4441,18 +4913,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++) { - new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), clip->effectAt(j), true, paste); + 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, ...) + for (int i = 0; i < clips.count(); ++i) { + 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())); @@ -4473,7 +5000,7 @@ AbstractClipItem *CustomTrackView::getMainActiveClip() const } else { AbstractClipItem *item = NULL; for (int i = 0; i < clips.count(); ++i) { - if (clips.count() == 1 || clips.at(i)->type() == AVWIDGET) { + if (clips.at(i)->type() == AVWIDGET) { item = static_cast < AbstractClipItem *>(clips.at(i)); if (clips.count() > 1 && item->startPos().frames(m_document->fps()) <= m_cursorPos && item->endPos().frames(m_document->fps()) >= m_cursorPos) break; } @@ -4574,6 +5101,7 @@ void CustomTrackView::setOutPoint() void CustomTrackView::slotUpdateAllThumbs() { + if (!isEnabled()) return; QList itemList = items(); //if (itemList.isEmpty()) return; ClipItem *item; @@ -4587,25 +5115,28 @@ 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 { QString startThumb = thumbBase + item->baseClip()->getClipHash() + '_'; QString endThumb = startThumb; - startThumb.append(QString::number(item->cropStart().frames(m_document->fps())) + ".png"); - endThumb.append(QString::number((item->cropStart() + item->cropDuration()).frames(m_document->fps()) - 1) + ".png"); + startThumb.append(QString::number(item->speedIndependantCropStart().frames(m_document->fps())) + ".png"); + 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(); @@ -4630,8 +5161,8 @@ void CustomTrackView::saveThumbnails() } else { QString startThumb = thumbBase + item->baseClip()->getClipHash() + '_'; QString endThumb = startThumb; - startThumb.append(QString::number(item->cropStart().frames(m_document->fps())) + ".png"); - endThumb.append(QString::number((item->cropStart() + item->cropDuration()).frames(m_document->fps()) - 1) + ".png"); + startThumb.append(QString::number(item->speedIndependantCropStart().frames(m_document->fps())) + ".png"); + endThumb.append(QString::number((item->speedIndependantCropStart() + item->speedIndependantCropDuration()).frames(m_document->fps()) - 1) + ".png"); if (!QFile::exists(startThumb)) { QPixmap pix(item->startThumb()); pix.save(startThumb); @@ -4709,8 +5240,9 @@ void CustomTrackView::slotChangeTrack(int ix) d.track_nb->setValue(ix); d.slotUpdateName(ix); d.setWindowTitle(i18n("Change Track Type")); - - if (m_document->trackInfoAt(m_document->tracksCount() - ix - 1).type == VIDEOTRACK) + + TrackInfo oldInfo = m_document->trackInfoAt(m_document->tracksCount() - ix - 1); + if (oldInfo.type == VIDEOTRACK) d.video_track->setChecked(true); else d.audio_track->setChecked(true); @@ -4719,6 +5251,7 @@ void CustomTrackView::slotChangeTrack(int ix) TrackInfo info; info.isLocked = false; info.isMute = false; + info.trackName = oldInfo.trackName; ix = d.track_nb->value(); if (d.video_track->isChecked()) { @@ -4746,7 +5279,7 @@ void CustomTrackView::deleteTimelineTrack(int ix, TrackInfo trackinfo) for (int i = 0; i < selection.count(); i++) { if (selection.at(i)->type() == AVWIDGET) { ClipItem *item = static_cast (selection.at(i)); - new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, true, deleteTrack); + new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, false, true, deleteTrack); m_scene->removeItem(item); delete item; item = NULL; @@ -4965,7 +5498,7 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split) break; } } - clip->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + clip->setFlag(QGraphicsItem::ItemIsMovable, true); m_document->clipManager()->removeGroup(grp); scene()->destroyItemGroup(grp); } @@ -5099,6 +5632,12 @@ void CustomTrackView::updateClipTypeActions(ClipItem *clip) } } +void CustomTrackView::slotGoToMarker(QAction *action) +{ + int pos = action->data().toInt(); + setCursorPos(pos, true); +} + void CustomTrackView::reloadTransitionLumas() { QString lumaNames; @@ -5175,7 +5714,7 @@ void CustomTrackView::updateProjectFps() for (int j = 0; j < children.count(); j++) { if (children.at(j)->type() == AVWIDGET || children.at(j)->type() == TRANSITIONWIDGET) { AbstractClipItem *clip = static_cast (children.at(j)); - clip->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + clip->setFlag(QGraphicsItem::ItemIsMovable, true); clip->updateFps(m_document->fps()); } } @@ -5197,3 +5736,137 @@ void CustomTrackView::updateProjectFps() } viewport()->update(); } + +void CustomTrackView::slotTrackDown() +{ + if (m_selectedTrack > m_document->tracksCount() - 2) m_selectedTrack = 0; + else m_selectedTrack++; + emit updateTrackHeaders(); + QRectF rect(mapToScene(QPoint(10, 0)).x(), m_selectedTrack * m_tracksHeight, 10, m_tracksHeight); + ensureVisible(rect, 0, 0); + viewport()->update(); +} + +void CustomTrackView::slotTrackUp() +{ + if (m_selectedTrack > 0) m_selectedTrack--; + else m_selectedTrack = m_document->tracksCount() - 1; + emit updateTrackHeaders(); + QRectF rect(mapToScene(QPoint(10, 0)).x(), m_selectedTrack * m_tracksHeight, 10, m_tracksHeight); + ensureVisible(rect, 0, 0); + viewport()->update(); +} + +int CustomTrackView::selectedTrack() const +{ + return m_selectedTrack; +} + +void CustomTrackView::slotSelectTrack(int ix) +{ + m_selectedTrack = qMax(0, ix); + m_selectedTrack = qMin(ix, m_document->tracksCount() - 1); + emit updateTrackHeaders(); + QRectF rect(mapToScene(QPoint(10, 0)).x(), m_selectedTrack * m_tracksHeight, 10, m_tracksHeight); + ensureVisible(rect, 0, 0); + viewport()->update(); +} + +void CustomTrackView::selectClip(bool add, bool group) +{ + QRectF rect(m_cursorPos, m_selectedTrack * m_tracksHeight + m_tracksHeight / 2, 1, 1); + QList selection = m_scene->items(rect); + resetSelectionGroup(group); + if (!group) m_scene->clearSelection(); + for (int i = 0; i < selection.count(); i++) { + if (selection.at(i)->type() == AVWIDGET) { + selection.at(i)->setSelected(add); + break; + } + } + if (group) groupSelectedItems(); +} + +void CustomTrackView::selectTransition(bool add, bool group) +{ + QRectF rect(m_cursorPos, m_selectedTrack * m_tracksHeight + m_tracksHeight, 1, 1); + QList selection = m_scene->items(rect); + resetSelectionGroup(group); + if (!group) m_scene->clearSelection(); + for (int i = 0; i < selection.count(); i++) { + if (selection.at(i)->type() == TRANSITIONWIDGET) { + selection.at(i)->setSelected(add); + break; + } + } + if (group) groupSelectedItems(); +} + +QStringList CustomTrackView::extractTransitionsLumas() +{ + QStringList urls; + QList itemList = items(); + Transition *transitionitem; + QDomElement transitionXml; + for (int i = 0; i < itemList.count(); i++) { + if (itemList.at(i)->type() == TRANSITIONWIDGET) { + transitionitem = static_cast (itemList.at(i)); + transitionXml = transitionitem->toXML(); + QString luma = EffectsList::parameter(transitionXml, "luma"); + if (!luma.isEmpty()) urls << luma; + } + } + return urls; +} + +void CustomTrackView::setEditMode(EDITMODE mode) +{ + m_scene->setEditMode(mode); +} + +void CustomTrackView::checkTrackSequence(int track) +{ + QList times = m_document->renderer()->checkTrackSequence(m_document->tracksCount() - track); + //track = m_document->tracksCount() -track; + QRectF rect(0, track * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), 2); + QList selection = m_scene->items(rect); + QList timelineList; + timelineList.append(0); + for (int i = 0; i < selection.count(); i++) { + if (selection.at(i)->type() == AVWIDGET) { + ClipItem *clip = static_cast (selection.at(i)); + int start = clip->startPos().frames(m_document->fps()); + int end = clip->endPos().frames(m_document->fps()); + if (!timelineList.contains(start)) timelineList.append(start); + if (!timelineList.contains(end)) timelineList.append(end); + } + } + qSort(timelineList); + kDebug() << "// COMPARE:\n" << times << "\n" << timelineList << "\n-------------------"; + if (times != timelineList) KMessageBox::sorry(this, i18n("error"), i18n("TRACTOR")); +} + +void CustomTrackView::insertZoneOverwrite(QStringList data, int in) +{ + DocClipBase *clip = m_document->getBaseClip(data.at(0)); + ItemInfo info; + info.startPos = GenTime(in, m_document->fps()); + info.cropStart = GenTime(data.at(1).toInt(), m_document->fps()); + info.endPos = info.startPos + GenTime(data.at(2).toInt(), m_document->fps()) - info.cropStart; + info.cropDuration = info.endPos - info.startPos; + info.track = m_selectedTrack; + QUndoCommand *addCommand = new QUndoCommand(); + addCommand->setText(i18n("Insert clip")); + adjustTimelineClips(OVERWRITEEDIT, NULL, info, addCommand); + 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); +} +