Fix several issues with transitions, including all problems reported in:

http://www.kdenlive.org/mantis/view.php?id=330

Also fix clip resizing not taking into account the disabled "snap" option

svn path=/branches/KDE4/; revision=2676
parent 746401ac
......@@ -72,7 +72,7 @@ void AbstractClipItem::updateRectGeometry() {
void AbstractClipItem::resizeStart(int posx, double speed) {
GenTime durationDiff = GenTime(posx, m_fps) - m_startPos;
if (durationDiff == GenTime()) return;
kDebug() << "-- RESCALE: CROP=" << m_cropStart.frames(25) << " - " << cropStart().frames(25);
//kDebug() << "-- RESCALE DIFF=" << durationDiff.frames(25) << ", CLIP: " << startPos().frames(25) << "-" << endPos().frames(25);
if (type() == AVWIDGET && cropStart() + durationDiff < GenTime()) {
durationDiff = GenTime() - cropStart();
......@@ -86,6 +86,9 @@ void AbstractClipItem::resizeStart(int posx, double speed) {
setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height());
setPos((qreal) m_startPos.frames(m_fps), pos().y());
//kDebug() << "-- NEW CLIP=" << startPos().frames(25) << "-" << endPos().frames(25);
//setRect((double) m_startPos.frames(m_fps) * scale, rect().y(), (double) m_cropDuration.frames(m_fps) * scale, rect().height());
if (durationDiff < GenTime()) {
QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
......
......@@ -655,11 +655,11 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) {
if (transitionClip && transitionClip->endPos() < m_dragItem->endPos()) {
info.endPos = transitionClip->endPos();
} else info.endPos = info.startPos + GenTime(2.5);
if (info.endPos == info.startPos) info.endPos = info.startPos + GenTime(2.5);
slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
} else if (m_operationMode == TRANSITIONEND) {
ItemInfo info;
info.endPos = m_dragItem->endPos();
info.endPos = GenTime(m_dragItem->endPos().frames(m_document->fps()) - 1, m_document->fps());
info.track = m_dragItem->track();
int transitiontrack = getPreviousVideoTrack(info.track);
ClipItem *transitionClip = NULL;
......@@ -667,6 +667,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) {
if (transitionClip && transitionClip->startPos() > m_dragItem->startPos()) {
info.startPos = transitionClip->startPos();
} else info.startPos = info.endPos - GenTime(2.5);
if (info.endPos == info.startPos) info.startPos = info.endPos - GenTime(2.5);
slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
}
......@@ -780,6 +781,7 @@ void CustomTrackView::dragEnterEvent(QDragEnterEvent * event) {
scene()->destroyItemGroup(m_selectionGroup);
m_selectionGroup = NULL;
}
QStringList list = QString(event->mimeData()->data("kdenlive/clip")).split(";");
m_selectionGroup = new AbstractGroupItem(m_document->fps());
QPoint pos = QPoint();
......@@ -792,6 +794,8 @@ void CustomTrackView::dragEnterEvent(QDragEnterEvent * event) {
info.track = (int)(pos.y() / m_tracksHeight);
ClipItem *item = new ClipItem(clip, info, m_document->fps());
m_selectionGroup->addToGroup(item);
//TODO: check if we do not overlap another clip when first dropping in timeline
// if (insertPossible(m_selectionGroup, event->pos()))
scene()->addItem(m_selectionGroup);
event->acceptProposedAction();
} else if (event->mimeData()->hasFormat("kdenlive/producerslist")) {
......@@ -815,11 +819,44 @@ void CustomTrackView::dragEnterEvent(QDragEnterEvent * event) {
pos.setX(pos.x() + clip->duration().frames(m_document->fps()));
m_selectionGroup->addToGroup(item);
}
//TODO: check if we do not overlap another clip when first dropping in timeline
//if (insertPossible(m_selectionGroup, event->pos()))
scene()->addItem(m_selectionGroup);
event->acceptProposedAction();
} else QGraphicsView::dragEnterEvent(event);
}
bool CustomTrackView::insertPossible(AbstractGroupItem *group, const QPoint &pos) const {
QPolygonF path;
QList<QGraphicsItem *> children = group->childItems();
for (int i = 0; i < children.count(); i++) {
if (children.at(i)->type() == AVWIDGET) {
ClipItem *clip = static_cast <ClipItem *>(children.at(i));
ItemInfo info = clip->info();
kDebug() << " / / INSERT : " << pos.x();
QRectF shape = QRectF(clip->startPos().frames(m_document->fps()), clip->track() * m_tracksHeight + 1, clip->duration().frames(m_document->fps()) - 0.02, m_tracksHeight - 1);
kDebug() << " / / INSERT RECT: " << shape;
path = path.united(QPolygonF(shape));
}
}
QList<QGraphicsItem*> collindingItems = scene()->items(path, Qt::IntersectsItemShape);
if (collindingItems.isEmpty()) return true;
else {
for (int i = 0; i < collindingItems.count(); i++) {
QGraphicsItem *collision = collindingItems.at(i);
if (collision->type() == AVWIDGET) {
// Collision
kDebug() << "// COLLISIION DETECTED";
return false;
}
}
return true;
}
}
void CustomTrackView::slotRefreshEffects(ClipItem *clip) {
int track = m_scene->m_tracksList.count() - clip->track();
GenTime pos = clip->startPos();
......@@ -1075,7 +1112,11 @@ void CustomTrackView::addTransition(ItemInfo transitionInfo, int endTrack, QDomE
}
void CustomTrackView::deleteTransition(ItemInfo transitionInfo, int endTrack, QDomElement params) {
Transition *item = getTransitionItemAt((int)transitionInfo.startPos.frames(m_document->fps()) + 1, transitionInfo.track);
Transition *item = getTransitionItemAt((int)transitionInfo.startPos.frames(m_document->fps()), transitionInfo.track);
if (!item) {
emit displayMessage(i18n("Select clip to delete"), ErrorMessage);
return;
}
m_document->renderer()->mltDeleteTransition(item->transitionTag(), endTrack, m_scene->m_tracksList.count() - transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, item->toXML());
delete item;
emit transitionItemSelected(NULL);
......@@ -1089,7 +1130,7 @@ void CustomTrackView::slotTransitionUpdated(Transition *tr, QDomElement old) {
}
void CustomTrackView::updateTransition(int track, GenTime pos, QDomElement oldTransition, QDomElement transition) {
Transition *item = getTransitionItemAt((int)pos.frames(m_document->fps()) + 1, track);
Transition *item = getTransitionItemAt((int)pos.frames(m_document->fps()), track);
if (!item) {
kWarning() << "Unable to find transition at pos :" << pos.frames(m_document->fps()) << ", ON track: " << track;
return;
......@@ -1103,9 +1144,9 @@ void CustomTrackView::dragMoveEvent(QDragMoveEvent * event) {
event->setDropAction(Qt::IgnoreAction);
const int track = (int)(mapToScene(event->pos()).y() / m_tracksHeight);
const int pos = mapToScene(event->pos()).x();
kDebug() << "// DRAG MOVE TO TRACK: " << track;
//kDebug() << "// DRAG MOVE TO TRACK: " << track;
if (m_selectionGroup) {
m_selectionGroup->setPos(pos, event->pos().y()/*track * m_tracksHeight + 1 - (int) m_selectionGroup->pos().y()*/);
m_selectionGroup->setPos(pos, event->pos().y());
event->setDropAction(Qt::MoveAction);
if (event->mimeData()->hasFormat("kdenlive/producerslist") || event->mimeData()->hasFormat("kdenlive/clip")) {
event->acceptProposedAction();
......@@ -1296,7 +1337,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
m_commandStack->push(command);
if (item->baseClip()->isTransparent()) {
// Also move automatic transition
Transition *tr = getTransitionItemAt((int) m_dragItemInfo.startPos.frames(m_document->fps()) + 1, m_dragItemInfo.track);
Transition *tr = getTransitionItemAt((int) m_dragItemInfo.startPos.frames(m_document->fps()), m_dragItemInfo.track);
if (tr && tr->isAutomatic()) {
tr->updateTransitionEndTrack(getPreviousVideoTrack(info.track));
m_document->renderer()->mltMoveTransition(tr->transitionTag(), m_scene->m_tracksList.count() - m_dragItemInfo.track, m_scene->m_tracksList.count() - info.track, tr->transitionEndTrack(), m_dragItemInfo.startPos, m_dragItemInfo.endPos, info.startPos, info.endPos);
......@@ -1485,7 +1526,7 @@ void CustomTrackView::deleteClip(ItemInfo info) {
if (item->baseClip()->isTransparent()) {
// also remove automatic transition
Transition *tr = getTransitionItemAt((int) info.startPos.frames(m_document->fps()) + 1, info.track);
Transition *tr = getTransitionItemAt((int) info.startPos.frames(m_document->fps()), info.track);
if (tr && tr->isAutomatic()) {
m_document->renderer()->mltDeleteTransition(tr->transitionTag(), tr->transitionEndTrack(), m_scene->m_tracksList.count() - info.track, info.startPos, info.endPos, tr->toXML());
scene()->removeItem(tr);
......@@ -1661,7 +1702,7 @@ void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end) {
item->setPos((int) end.startPos.frames(m_document->fps()), (int)(end.track * m_tracksHeight + 1));
if (item->baseClip()->isTransparent()) {
// Also move automatic transition
Transition *tr = getTransitionItemAt((int) start.startPos.frames(m_document->fps()) + 1, start.track);
Transition *tr = getTransitionItemAt((int) start.startPos.frames(m_document->fps()), start.track);
if (tr && tr->isAutomatic()) {
tr->updateTransitionEndTrack(getPreviousVideoTrack(end.track));
m_document->renderer()->mltMoveTransition(tr->transitionTag(), m_scene->m_tracksList.count() - start.track, m_scene->m_tracksList.count() - end.track, tr->transitionEndTrack(), start.startPos, start.endPos, end.startPos, end.endPos);
......@@ -1675,7 +1716,7 @@ void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end) {
}
void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end) {
Transition *item = getTransitionItemAt((int)start.startPos.frames(m_document->fps()) + 1, start.track);
Transition *item = getTransitionItemAt((int)start.startPos.frames(m_document->fps()), start.track);
if (!item) {
emit displayMessage(i18n("Cannot move transition at time: %1s on track %2", start.startPos.seconds(), start.track), ErrorMessage);
kDebug() << "----------------  ERROR, CANNOT find transition to move... ";// << startPos.x() * m_scale * FRAME_SIZE + 1 << ", " << startPos.y() * m_tracksHeight + m_tracksHeight / 2;
......@@ -1766,7 +1807,7 @@ void CustomTrackView::updateClipFade(ClipItem * item, bool updateFadeOut) {
}
double CustomTrackView::getSnapPointForPos(double pos) {
return m_scene->getSnapPointForPos(pos);
return m_scene->getSnapPointForPos(pos, KdenliveSettings::snaptopoints());
}
void CustomTrackView::updateSnapPoints(AbstractClipItem *selected) {
......
......@@ -187,7 +187,6 @@ private:
QPoint m_menuPosition;
bool m_blockRefresh;
AbstractGroupItem *m_selectionGroup;
AbstractGroupItem *m_dropGroup;
/** Get the index of the video track that is just below current track */
int getPreviousVideoTrack(int track);
......@@ -198,6 +197,7 @@ private:
ClipItem *getClipUnderCursor() const;
ClipItem *getMainActiveClip() const;
ClipItem *getActiveClipUnderCursor() const;
bool insertPossible(AbstractGroupItem *group, const QPoint &pos) const;
private slots:
void slotRefreshGuides();
......
......@@ -1489,9 +1489,8 @@ void MainWindow::slotAddTransition(QAction *result) {
QStringList info = result->data().toStringList();
if (info.isEmpty()) return;
QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
//QDomElement effect = transitions.getEffectByName(result->data().toString());
if (m_activeTimeline) {
m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition);
if (m_activeTimeline && !transition.isNull()) {
m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
}
}
......
......@@ -2085,7 +2085,7 @@ void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int n
int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
int new_in = (int)newIn.frames(m_fps);
int new_out = (int)newOut.frames(m_fps);
int new_out = (int)newOut.frames(m_fps) - 1;
while (mlt_type == "transition") {
mlt_transition tr = (mlt_transition) nextservice;
......@@ -2141,7 +2141,7 @@ void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, G
QString mlt_type = mlt_properties_get(properties, "mlt_type");
QString resource = mlt_properties_get(properties, "mlt_service");
int in_pos = (int) in.frames(m_fps);
int out_pos = (int) out.frames(m_fps);
int out_pos = (int) out.frames(m_fps) - 1;
while (mlt_type == "transition") {
mlt_transition tr = (mlt_transition) nextservice;
......@@ -2398,7 +2398,7 @@ void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in,
char *transId = decodedString(tag);
Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
if (out != GenTime())
transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps));
transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
QMap<QString, QString>::Iterator it;
QString key;
if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
......
......@@ -257,7 +257,7 @@ void TrackView::parseDocument(QDomDocument doc) {
kDebug() << "/////// TRANSITION XML: "<< doc.toString();*/
transitionInfo.startPos = GenTime(e.attribute("in").toInt(), m_doc->fps());
transitionInfo.endPos = GenTime(e.attribute("out").toInt(), m_doc->fps());
transitionInfo.endPos = GenTime(e.attribute("out").toInt() + 1, m_doc->fps());
transitionInfo.track = b_track;
//kDebug() << "/////////////// +++++++++++ ADDING TRANSITION ON TRACK: " << b_track << ", TOTAL TRKA: " << m_projectTracks;
Transition *tr = new Transition(transitionInfo, a_track, m_doc->fps(), base, isAutomatic);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment