Commit d38d6c6a authored by Julius Künzel's avatar Julius Künzel
Browse files

Restructure ripple code to make it possible to run more tests

parent eff592e4
......@@ -19,9 +19,9 @@
#include "snapmodel.hpp"
#include "timelinefunctions.hpp"
// TODO
#include "mainwindow.h"
#include "timeline2/view/timelinewidget.h"
#include "timeline2/view/timelinecontroller.h"
//#include "mainwindow.h"
//#include "timeline2/view/timelinewidget.h"
//#include "timeline2/view/timelinecontroller.h"
#include "timeline2/model/timelinefunctions.hpp"
#include "monitor/monitormanager.h"
......@@ -3392,7 +3392,7 @@ bool TimelineModel::requestItemResize(int itemId, int &size, bool right, bool lo
return result;
}
int TimelineModel::requestItemRippleResize(int itemId, int size, bool right, bool logUndo, int snapDistance, bool allowSingleResize) {
int TimelineModel::requestItemRippleResize(const std::shared_ptr<TimelineItemModel> &timeline, int itemId, int size, bool right, bool logUndo, int snapDistance, bool allowSingleResize) {
QWriteLocker locker(&m_lock);
TRACE(itemId, size, right, logUndo, snapDistance, allowSingleResize)
Q_ASSERT(isItem(itemId));
......@@ -3611,7 +3611,7 @@ int TimelineModel::requestItemRippleResize(int itemId, int size, bool right, boo
} else {
finalSize = qMax(0, getItemPosition(id)) + getItemPlaytime(id) - finalPos;
}
result = result && requestItemRippleResize(id, finalSize, right, logUndo, undo, redo);
result = result && requestItemRippleResize(timeline, id, finalSize, right, logUndo, undo, redo);
resizedCount++;
}
if (!result || resizedCount == 0) {
......@@ -3642,7 +3642,7 @@ int TimelineModel::requestItemRippleResize(int itemId, int size, bool right, boo
return res;
}
bool TimelineModel::requestItemRippleResize(int itemId, int size, bool right, bool logUndo, Fun &undo, Fun &redo, bool blockUndo)
bool TimelineModel::requestItemRippleResize(const std::shared_ptr<TimelineItemModel> &timeline, int itemId, int size, bool right, bool logUndo, Fun &undo, Fun &redo, bool blockUndo)
{
Q_UNUSED(blockUndo)
Fun local_undo = []() { return true; };
......@@ -3686,18 +3686,18 @@ bool TimelineModel::requestItemRippleResize(int itemId, int size, bool right, bo
size = m_allClips[itemId]->getMaxDuration() > 0 ? qBound(1, size, m_allClips[itemId]->getMaxDuration()) : qMax(1, size);
int delta = size - m_allClips[itemId]->getPlaytime();
qDebug() << "requestItemRippleResize logUndo: " << logUndo << " size: " << size << " playtime: " << m_allClips[itemId]->getPlaytime() <<" delta: " << delta;
auto spacerOperation = [this, itemId, affectAllTracks, &local_undo, &local_redo, delta, right](int position) {
auto spacerOperation = [this, itemId, affectAllTracks, &local_undo, &local_redo, delta, right, timeline](int position) {
int trackId = getItemTrackId(itemId);
if (right && getTrackById_const(trackId)->isLastClip(getItemPosition(itemId))) {
return true;
}
int cid = TimelineFunctions::requestSpacerStartOperation(pCore->window()->getCurrentTimeline()->model(), affectAllTracks ? -1 : trackId, position, true);
int cid = TimelineFunctions::requestSpacerStartOperation(timeline, affectAllTracks ? -1 : trackId, position, true);
if (cid == -1) {
return false;
}
int endPos = getItemPosition(cid) + delta;
// Start undoable command
TimelineFunctions::requestSpacerEndOperation(pCore->window()->getCurrentTimeline()->model(), cid, getItemPosition(cid), endPos, affectAllTracks ? -1 : trackId, !KdenliveSettings::lockedGuides(), local_undo, local_redo, false);
TimelineFunctions::requestSpacerEndOperation(timeline, cid, getItemPosition(cid), endPos, affectAllTracks ? -1 : trackId, !KdenliveSettings::lockedGuides(), local_undo, local_redo, false);
return true;
};
if (delta > 0) {
......
......@@ -509,9 +509,9 @@ public:
bool requestItemResize(int itemId, int &size, bool right, bool logUndo, Fun &undo, Fun &redo, bool blockUndo = false);
/** @brief @todo TODO */
Q_INVOKABLE int requestItemRippleResize(int itemId, int size, bool right, bool logUndo = true, int snapDistance = -1, bool allowSingleResize = false);
int requestItemRippleResize(const std::shared_ptr<TimelineItemModel> &timeline, int itemId, int size, bool right, bool logUndo = true, int snapDistance = -1, bool allowSingleResize = false);
/** @brief @todo TODO */
bool requestItemRippleResize(int itemId, int size, bool right, bool logUndo, Fun &undo, Fun &redo, bool blockUndo = false);
bool requestItemRippleResize(const std::shared_ptr<TimelineItemModel> &timeline, int itemId, int size, bool right, bool logUndo, Fun &undo, Fun &redo, bool blockUndo = false);
/** @brief Move ("slip") in and out point of a clip by the given offset
This action is undoable
......
......@@ -328,7 +328,7 @@ Item{
var new_duration = 0;
if (root.activeTool === ProjectTool.RippleTool) {
console.log("In: Request for " + newDuration)
new_duration = controller.requestItemRippleResize(clip.clipId, newDuration, false, false, root.snapping, shiftTrim)
new_duration = timeline.requestItemRippleResize(clip.clipId, newDuration, false, false, root.snapping, shiftTrim)
timeline.requestStartTrimmingMode(clip.clipId, false, false);
timeline.ripplePosChanged(new_duration, false);
} else {
......@@ -355,9 +355,9 @@ Item{
if (shiftTrim || (root.groupTrimData == undefined/*TODO > */ || root.activeTool === ProjectTool.RippleTool /* < TODO*/) || controlTrim) {
// We only resize one element
if (root.activeTool === ProjectTool.RippleTool) {
controller.requestItemRippleResize(clip.clipId, clip.originalDuration, false, false, 0, shiftTrim)
timeline.requestItemRippleResize(clip.clipId, clip.originalDuration, false, false, 0, shiftTrim)
} else {
controller.requestItemResize(clip.clipId, clip.originalDuration, false, false, 0, shiftTrim)
timeline.requestItemResize(clip.clipId, clip.originalDuration, false, false, 0, shiftTrim)
}
if (root.activeTool === ProjectTool.SelectTool && controlTrim) {
......@@ -367,7 +367,7 @@ Item{
speedController.originalSpeed = 1
} else {
if (root.activeTool === ProjectTool.RippleTool) {
controller.requestItemRippleResize(clip.clipId, clip.lastValidDuration, false, true, 0, shiftTrim)
timeline.requestItemRippleResize(clip.clipId, clip.lastValidDuration, false, true, 0, shiftTrim)
timeline.requestEndTrimmingMode();
} else {
controller.requestItemResize(clip.clipId, clip.lastValidDuration, false, true, 0, shiftTrim)
......@@ -402,7 +402,7 @@ Item{
var new_duration = 0;
if (root.activeTool === ProjectTool.RippleTool) {
console.log("Out: Request for " + newDuration)
new_duration = controller.requestItemRippleResize(clip.clipId, newDuration, true, false, root.snapping, shiftTrim)
new_duration = timeline.requestItemRippleResize(clip.clipId, newDuration, true, false, root.snapping, shiftTrim)
timeline.requestStartTrimmingMode(clip.clipId, false, true);
timeline.ripplePosChanged(new_duration, true);
} else {
......@@ -426,7 +426,7 @@ Item{
//bubbleHelp.hide()
if (shiftTrim || (root.groupTrimData == undefined/*TODO > */ || root.activeTool === ProjectTool.RippleTool /* < TODO*/) || controlTrim) {
if (root.activeTool === ProjectTool.RippleTool) {
controller.requestItemRippleResize(clip.clipId, clip.originalDuration, true, false, 0, shiftTrim)
timeline.requestItemRippleResize(clip.clipId, clip.originalDuration, true, false, 0, shiftTrim)
} else {
controller.requestItemResize(clip.clipId, clip.originalDuration, true, false, 0, shiftTrim)
}
......@@ -438,7 +438,7 @@ Item{
speedController.originalSpeed = 1
} else {
if (root.activeTool === ProjectTool.RippleTool) {
controller.requestItemRippleResize(clip.clipId, clip.lastValidDuration, true, true, 0, shiftTrim)
timeline.requestItemRippleResize(clip.clipId, clip.lastValidDuration, true, true, 0, shiftTrim)
timeline.requestEndTrimmingMode();
} else {
controller.requestItemResize(clip.clipId, clip.lastValidDuration, true, true, 0, shiftTrim)
......
......@@ -918,7 +918,7 @@ void TimelineController::setInPoint(bool ripple)
}
auto requestResize = [this, ripple](int id, int size){
if (ripple) {
m_model->requestItemRippleResize(id, size, false, true, 0, false);
m_model->requestItemRippleResize(m_model, id, size, false, true, 0, false);
setPosition(m_model->getItemPosition(id));
} else {
m_model->requestItemResize(id, size, false, true, 0, false);
......@@ -998,7 +998,7 @@ void TimelineController::setOutPoint(bool ripple)
}
auto requestResize = [this, ripple](int id, int size){
if (ripple) {
m_model->requestItemRippleResize(id, size, true, true, 0, false);
m_model->requestItemRippleResize(m_model, id, size, true, true, 0, false);
} else {
m_model->requestItemResize(id, size, true, true, 0, false);
}
......@@ -1969,6 +1969,10 @@ void TimelineController::removeSplitOverlay()
m_model->m_overlayTrackCount = m_timelinePreview->addedTracks();
}
int TimelineController::requestItemRippleResize(int itemId, int size, bool right, bool logUndo, int snapDistance, bool allowSingleResize) {
return m_model->requestItemRippleResize(m_model, itemId, size, right, logUndo, snapDistance, allowSingleResize);
}
void TimelineController::updateTrimmingMode() {
if (trimmingActive()) {
requestStartTrimmingMode();
......
......@@ -534,6 +534,9 @@ public:
Q_INVOKABLE void slipPosChanged(int offset);
Q_INVOKABLE void ripplePosChanged(int pos, bool right);
/** @brief @todo TODO */
Q_INVOKABLE int requestItemRippleResize(int itemId, int size, bool right, bool logUndo = true, int snapDistance = -1, bool allowSingleResize = false);
/** @brief Add current timeline zone to preview rendering
*/
void addPreviewRange(bool add);
......
......@@ -1469,18 +1469,18 @@ TEST_CASE("Advanced trimming operations: Ripple", "[TrimmingRipple]")
};
state();
REQUIRE(timeline->requestItemRippleResize(cid1, l1 + 5, true));
REQUIRE(timeline->requestItemRippleResize(timeline, cid1, l1 + 5, true));
state();
REQUIRE(timeline->requestItemRippleResize(cid1, l1 + 5, false));
REQUIRE(timeline->requestItemRippleResize(timeline, cid1, l1 + 5, false));
state();
REQUIRE(timeline->requestItemRippleResize(cid2, l2 + 5, true));
REQUIRE(timeline->requestItemRippleResize(cid1, l2 + 5, false));
REQUIRE(timeline->requestItemRippleResize(timeline, cid2, l2 + 5, true));
REQUIRE(timeline->requestItemRippleResize(timeline, cid1, l2 + 5, false));
state();
REQUIRE(timeline->requestItemRippleResize(cid3, l3 + 5, true));
REQUIRE(timeline->requestItemRippleResize(cid3, l3 + 5, false));
REQUIRE(timeline->requestItemRippleResize(timeline, cid3, l3 + 5, true));
REQUIRE(timeline->requestItemRippleResize(timeline, cid3, l3 + 5, false));
state();
undoStack->undo();
......@@ -1543,7 +1543,7 @@ TEST_CASE("Advanced trimming operations: Ripple", "[TrimmingRipple]")
REQUIRE(timeline->getClipPtr(cid3)->getIn() == 0);
REQUIRE(timeline->getClipPtr(cid3)->getOut() == l3 - 1);
};
qDebug() << "Wauf" << timeline->requestItemRippleResize(cid2, l2 - 5, true);
qDebug() << "Wauf" << timeline->requestItemRippleResize(timeline, cid2, l2 - 5, true);
//REQUIRE( == l2 - 5);
stateA1();
stateB();
......@@ -1561,7 +1561,7 @@ TEST_CASE("Advanced trimming operations: Ripple", "[TrimmingRipple]")
REQUIRE(timeline->getClipPtr(cid3)->getOut() == l3 - 1);
};
REQUIRE(timeline->requestItemRippleResize(cid2, l2 - 8, false));
REQUIRE(timeline->requestItemRippleResize(timeline, cid2, l2 - 8, false));
stateA1();
stateC();
......
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