Undo/redo on clip monitor set in/out point

parent f265f7bb
...@@ -774,14 +774,60 @@ void Monitor::slotLoadClipZone(const QPoint &zone) ...@@ -774,14 +774,60 @@ void Monitor::slotLoadClipZone(const QPoint &zone)
void Monitor::slotSetZoneStart() void Monitor::slotSetZoneStart()
{ {
m_glMonitor->getControllerProxy()->setZoneIn(m_glMonitor->getCurrentPos()); QPoint oldZone = m_glMonitor->getControllerProxy()->zone();
int currentIn = m_glMonitor->getCurrentPos();
int updatedZoneOut = -1;
if (currentIn > oldZone.y()) {
updatedZoneOut = qMin(m_glMonitor->duration(), currentIn + (oldZone.y() - oldZone.x()));
}
Fun undo_zone = [this, oldZone, updatedZoneOut]() {
m_glMonitor->getControllerProxy()->setZoneIn(oldZone.x());
if (updatedZoneOut > -1) {
m_glMonitor->getControllerProxy()->setZoneOut(oldZone.y());
}
checkOverlay(); checkOverlay();
return true;
};
Fun redo_zone = [this, currentIn, updatedZoneOut]() {
if (updatedZoneOut > -1) {
m_glMonitor->getControllerProxy()->setZoneOut(updatedZoneOut);
}
m_glMonitor->getControllerProxy()->setZoneIn(currentIn);
checkOverlay();
return true;
};
redo_zone();
pCore->pushUndo(undo_zone, redo_zone, i18n("Set Zone"));
} }
void Monitor::slotSetZoneEnd() void Monitor::slotSetZoneEnd()
{ {
m_glMonitor->getControllerProxy()->setZoneOut(m_glMonitor->getCurrentPos() + 1); QPoint oldZone = m_glMonitor->getControllerProxy()->zone();
int currentOut = m_glMonitor->getCurrentPos() + 1;
int updatedZoneIn = -1;
if (currentOut < oldZone.x()) {
updatedZoneIn = qMax(0, currentOut - (oldZone.y() - oldZone.x()));
}
Fun undo_zone = [this, oldZone, updatedZoneIn]() {
m_glMonitor->getControllerProxy()->setZoneOut(oldZone.y());
if (updatedZoneIn > -1) {
m_glMonitor->getControllerProxy()->setZoneIn(oldZone.x());
}
checkOverlay(); checkOverlay();
return true;
};
Fun redo_zone = [this, currentOut, updatedZoneIn]() {
if (updatedZoneIn > -1) {
m_glMonitor->getControllerProxy()->setZoneIn(updatedZoneIn);
}
m_glMonitor->getControllerProxy()->setZoneOut(currentOut);
checkOverlay();
return true;
};
redo_zone();
pCore->pushUndo(undo_zone, redo_zone, i18n("Set Zone"));
} }
// virtual // virtual
......
...@@ -140,13 +140,6 @@ void MonitorProxy::setZoneIn(int pos) ...@@ -140,13 +140,6 @@ void MonitorProxy::setZoneIn(int pos)
if (m_zoneIn > 0) { if (m_zoneIn > 0) {
emit removeSnap(m_zoneIn); emit removeSnap(m_zoneIn);
} }
if (pos > m_zoneOut) {
if (m_zoneOut > 0) {
emit removeSnap(m_zoneOut - 1);
}
m_zoneOut = qMin(q->duration(), pos + (m_zoneOut - m_zoneIn));
emit addSnap(m_zoneOut - 1);
}
m_zoneIn = pos; m_zoneIn = pos;
if (pos > 0) { if (pos > 0) {
emit addSnap(pos); emit addSnap(pos);
...@@ -160,13 +153,6 @@ void MonitorProxy::setZoneOut(int pos) ...@@ -160,13 +153,6 @@ void MonitorProxy::setZoneOut(int pos)
if (m_zoneOut > 0) { if (m_zoneOut > 0) {
emit removeSnap(m_zoneOut - 1); emit removeSnap(m_zoneOut - 1);
} }
if (pos < m_zoneIn) {
if (m_zoneIn > 0) {
emit removeSnap(m_zoneIn);
}
m_zoneIn = qMax(0, pos - (m_zoneOut - m_zoneIn));
emit addSnap(m_zoneIn);
}
m_zoneOut = pos; m_zoneOut = pos;
if (pos > 0) { if (pos > 0) {
emit addSnap(m_zoneOut - 1); emit addSnap(m_zoneOut - 1);
......
...@@ -1338,8 +1338,6 @@ void TimelineController::updateZone(const QPoint oldZone, const QPoint newZone, ...@@ -1338,8 +1338,6 @@ void TimelineController::updateZone(const QPoint oldZone, const QPoint newZone,
emit zoneMoved(m_zone); emit zoneMoved(m_zone);
return; return;
} }
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
Fun undo_zone = [this, oldZone]() { Fun undo_zone = [this, oldZone]() {
setZone(oldZone, false); setZone(oldZone, false);
return true; return true;
...@@ -1349,8 +1347,7 @@ void TimelineController::updateZone(const QPoint oldZone, const QPoint newZone, ...@@ -1349,8 +1347,7 @@ void TimelineController::updateZone(const QPoint oldZone, const QPoint newZone,
return true; return true;
}; };
redo_zone(); redo_zone();
UPDATE_UNDO_REDO_NOLOCK(redo_zone, undo_zone, undo, redo); pCore->pushUndo(undo_zone, redo_zone, i18n("Set Zone"));
pCore->pushUndo(undo, redo, i18n("Set Zone"));
} }
void TimelineController::setZoneIn(int inPoint) void TimelineController::setZoneIn(int inPoint)
......
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