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

Fix some mix resize issues allowing to create invalid mixes

parent 956009fc
...@@ -5921,6 +5921,7 @@ bool TimelineModel::resizeStartMix(int cid, int duration, bool singleResize) ...@@ -5921,6 +5921,7 @@ bool TimelineModel::resizeStartMix(int cid, int duration, bool singleResize)
if (mixData.first.firstClipId > -1) { if (mixData.first.firstClipId > -1) {
int clipToResize = mixData.first.firstClipId; int clipToResize = mixData.first.firstClipId;
Q_ASSERT(isClip(clipToResize)); Q_ASSERT(isClip(clipToResize));
duration = qMin(duration, m_allClips.at(cid)->getPlaytime() - 1);
int updatedDuration = m_allClips.at(cid)->getPosition() + duration - m_allClips[clipToResize]->getPosition(); int updatedDuration = m_allClips.at(cid)->getPosition() + duration - m_allClips[clipToResize]->getPosition();
int result = requestItemResize(clipToResize, updatedDuration, true, true, 0, singleResize); int result = requestItemResize(clipToResize, updatedDuration, true, true, 0, singleResize);
return result > -1; return result > -1;
...@@ -5995,7 +5996,16 @@ void TimelineModel::requestResizeMix(int cid, int duration, MixAlignment align, ...@@ -5995,7 +5996,16 @@ void TimelineModel::requestResizeMix(int cid, int duration, MixAlignment align,
// The mix cut position shoud never change through a resize operation // The mix cut position shoud never change through a resize operation
int cutPos = m_allClips.at(clipToResize)->getPosition() + m_allClips.at(clipToResize)->getPlaytime() - m_allClips.at(cid)->getMixCutPosition(); int cutPos = m_allClips.at(clipToResize)->getPosition() + m_allClips.at(clipToResize)->getPlaytime() - m_allClips.at(cid)->getMixCutPosition();
int maxLengthLeft = m_allClips.at(clipToResize)->getMaxDuration(); int maxLengthLeft = m_allClips.at(clipToResize)->getMaxDuration();
// Maximum space for expanding the right clip part
int leftMax = maxLengthLeft > -1 ? (maxLengthLeft - 1 - m_allClips.at(clipToResize)->getOut()) : -1; int leftMax = maxLengthLeft > -1 ? (maxLengthLeft - 1 - m_allClips.at(clipToResize)->getOut()) : -1;
// Maximum space available on the right clip
int availableLeft = m_allClips.at(cid)->getPosition() + m_allClips.at(cid)->getPlaytime() - (m_allClips.at(clipToResize)->getPosition() + m_allClips.at(clipToResize)->getPlaytime());
if (leftMax == -1) {
leftMax = availableLeft;
} else {
leftMax = qMin(leftMax, availableLeft);
}
int maxLengthRight = m_allClips.at(cid)->getMaxDuration(); int maxLengthRight = m_allClips.at(cid)->getMaxDuration();
int rightMax = maxLengthRight > -1 ? (m_allClips.at(cid)->getIn()) : -1; int rightMax = maxLengthRight > -1 ? (m_allClips.at(cid)->getIn()) : -1;
Fun adjust_mix_undo = [this, tid, cid, prevCut = m_allClips.at(cid)->getMixCutPosition(), prevDuration = m_allClips.at(cid)->getMixDuration()]() { Fun adjust_mix_undo = [this, tid, cid, prevCut = m_allClips.at(cid)->getMixCutPosition(), prevDuration = m_allClips.at(cid)->getMixDuration()]() {
...@@ -6171,6 +6181,12 @@ void TimelineModel::requestResizeMix(int cid, int duration, MixAlignment align, ...@@ -6171,6 +6181,12 @@ void TimelineModel::requestResizeMix(int cid, int duration, MixAlignment align,
} }
updatedDurationLeft -= (m_allClips.at(cid)->getMixDuration() - m_allClips.at(cid)->getMixCutPosition()); updatedDurationLeft -= (m_allClips.at(cid)->getMixDuration() - m_allClips.at(cid)->getMixCutPosition());
updatedDurationRight -= m_allClips.at(cid)->getMixCutPosition(); updatedDurationRight -= m_allClips.at(cid)->getMixCutPosition();
if (leftMax > -1) {
updatedDurationLeft = qMin(updatedDurationLeft, m_allClips.at(clipToResize)->getPlaytime() + leftMax);
}
if (rightMax > -1) {
updatedDurationRight = qMin(updatedDurationRight, m_allClips.at(cid)->getPlaytime() + rightMax);
}
if (updatedDurationLeft != 0) { if (updatedDurationLeft != 0) {
requestItemResize(cid, m_allClips.at(cid)->getPlaytime() + updatedDurationLeft, false, true, undo, redo); requestItemResize(cid, m_allClips.at(cid)->getPlaytime() + updatedDurationLeft, false, true, undo, redo);
} }
......
...@@ -396,7 +396,7 @@ Rectangle { ...@@ -396,7 +396,7 @@ Rectangle {
color: "navy" color: "navy"
} }
MouseArea { MouseArea {
// Left resize handle // Right mix resize handle
id: trimInMixArea id: trimInMixArea
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: clipRoot.mixDuration * clipRoot.timeScale anchors.leftMargin: clipRoot.mixDuration * clipRoot.timeScale
...@@ -409,6 +409,7 @@ Rectangle { ...@@ -409,6 +409,7 @@ Rectangle {
drag.target: trimInMixArea drag.target: trimInMixArea
drag.axis: Drag.XAxis drag.axis: Drag.XAxis
drag.smoothed: false drag.smoothed: false
drag.maximumX: clipRoot.width - 1
property bool sizeChanged: false property bool sizeChanged: false
cursorShape: (containsMouse ? Qt.SizeHorCursor : Qt.ClosedHandCursor) cursorShape: (containsMouse ? Qt.SizeHorCursor : Qt.ClosedHandCursor)
onPressed: { onPressed: {
......
Supports Markdown
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