Commit 36472080 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Add basic collision check to speed resize

Related to #224
parent 88f5f07f
Pipeline #5087 passed with stage
in 21 minutes and 13 seconds
......@@ -1809,6 +1809,41 @@ int TimelineModel::requestItemResizeInfo(int itemId, int in, int out, int size,
return size;
}
int TimelineModel::requestItemSpeedChange(int itemId, int size, bool right, int snapDistance)
{
Q_ASSERT(isClip(itemId));
QWriteLocker locker(&m_lock);
TRACE(itemId, size, right, snapDistance);
Q_ASSERT(isItem(itemId));
if (size <= 0) {
TRACE_RES(-1);
return -1;
}
int in = getItemPosition(itemId);
int out = in + getItemPlaytime(itemId);
if (right && size > out - in) {
int targetPos = in + size - 1;
int trackId = getItemTrackId(itemId);
if (!getTrackById_const(trackId)->isBlankAt(targetPos) || !getItemsInRange(trackId, out + 1, targetPos, false).empty()) {
size = getTrackById_const(trackId)->getBlankEnd(out + 1) - in;
}
} else if (!right && size > (out - in)) {
int targetPos = out - size;
int trackId = getItemTrackId(itemId);
if (!getTrackById_const(trackId)->isBlankAt(targetPos) || !getItemsInRange(trackId, targetPos, in - 1, false).empty()) {
size = out - getTrackById_const(trackId)->getBlankStart(in - 1);
}
}
int timelinePos = pCore->getTimelinePosition();
m_snaps->addPoint(timelinePos);
int proposed_size = m_snaps->proposeSize(in, out, getBoundaries(itemId), size, right, snapDistance);
m_snaps->removePoint(timelinePos);
qDebug()<<"==== RESIZE REQUEST: "<<size<<"*, RESULKT: "<<proposed_size;
return proposed_size > 0 ? proposed_size : size;
}
int TimelineModel::requestItemResize(int itemId, int size, bool right, bool logUndo, int snapDistance, bool allowSingleResize)
{
if (logUndo) {
......
......@@ -462,6 +462,8 @@ public:
/* Same function, but accumulates undo and redo and doesn't deal with snapping*/
bool requestItemResize(int itemId, int size, bool right, bool logUndo, Fun &undo, Fun &redo, bool blockUndo = false);
/* Returns a proposed size for clip resize, checking for collisions */
Q_INVOKABLE int requestItemSpeedChange(int itemId, int size, bool right, int snapDistance);
/* Returns a list of {id, position duration} for all elements in the group*/
Q_INVOKABLE const QVariantList getGroupData(int itemId);
Q_INVOKABLE void processGroupResize(QVariantList startPos, QVariantList endPos, bool right);
......
......@@ -271,7 +271,7 @@ Column{
}
onTrimmingIn: {
if (controlTrim) {
newDuration = Math.max(1, newDuration)
newDuration = controller.requestItemSpeedChange(clip.clipId, newDuration, false, root.snapping)
speedController.x = clip.x + clip.width - newDuration * trackRoot.timeScale
speedController.width = newDuration * trackRoot.timeScale
speedController.lastValidDuration = newDuration
......@@ -315,7 +315,7 @@ Column{
onTrimmingOut: {
if (controlTrim) {
speedController.x = clip.x
newDuration = Math.max(1, newDuration)
newDuration = controller.requestItemSpeedChange(clip.clipId, newDuration, true, root.snapping)
speedController.width = newDuration * trackRoot.timeScale
speedController.lastValidDuration = newDuration
speedController.speedText = (100 * clip.originalDuration * clip.speed / speedController.lastValidDuration).toFixed(2) + '%'
......
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