From 3cc0a7c26d988eb6448061bf6381f35565fe2a2a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Fri, 10 Jun 2011 22:18:15 +0000 Subject: [PATCH] Do not allow to create overlapping transitions that could corrupt timeline, may be reason for: http://www.kdenlive.org/mantis/view.php?id=1901 svn path=/trunk/kdenlive/; revision=5696 --- src/transition.cpp | 48 +++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/src/transition.cpp b/src/transition.cpp index 759f8b06..811cc8ba 100644 --- a/src/transition.cpp +++ b/src/transition.cpp @@ -231,34 +231,56 @@ QVariant Transition::itemChange(GraphicsItemChange change, const QVariant &value QRectF sceneShape = rect(); sceneShape.translate(newPos); QList items; - if (projectScene()->editMode() == NORMALEDIT) - items = scene()->items(sceneShape, Qt::IntersectsItemShape); + // TODO: manage transitions in OVERWRITE MODE + //if (projectScene()->editMode() == NORMALEDIT) + items = scene()->items(sceneShape, Qt::IntersectsItemShape); items.removeAll(this); + bool forwardMove = newPos.x() > pos().x(); + int offset = 0; if (!items.isEmpty()) { for (int i = 0; i < items.count(); i++) { if (!items.at(i)->isEnabled()) continue; if (items.at(i)->type() == type()) { - // Collision! Don't move. - //kDebug()<<"/// COLLISION WITH ITEM: "<boundingRect()<<", POS: "<pos()<<", ME: "<pos(); - if ((int) otherPos.y() != (int) pos().y()) return pos(); - //kDebug()<<"//// CURRENT Y: "<(items.at(i))->startPos() - m_info.cropDuration).frames(m_fps); - newPos.setX(npos); + if ((int) otherPos.y() != (int) pos().y()) { + return pos(); + } + if (forwardMove) { + offset = qMax(offset, (int)(newPos.x() - (static_cast < AbstractClipItem* >(items.at(i))->startPos() - cropDuration()).frames(m_fps))); } else { - // get pos just after colliding clip - int npos = static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps); - newPos.setX(npos); + offset = qMax(offset, (int)((static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps)) - newPos.x())); + } + + if (offset > 0) { + if (forwardMove) { + sceneShape.translate(QPointF(-offset, 0)); + newPos.setX(newPos.x() - offset); + } else { + sceneShape.translate(QPointF(offset, 0)); + newPos.setX(newPos.x() + offset); + } + QList subitems = scene()->items(sceneShape, Qt::IntersectsItemShape); + subitems.removeAll(this); + for (int j = 0; j < subitems.count(); j++) { + if (!subitems.at(j)->isEnabled()) continue; + if (subitems.at(j)->type() == type()) { + // move was not successful, revert to previous pos + m_info.startPos = GenTime((int) pos().x(), m_fps); + return pos(); + } + } } + m_info.track = newTrack; - //kDebug()<<"// ITEM NEW POS: "<