Fix insert/overwrite/lift not working on grouped clips

parent 8d352982
......@@ -2553,12 +2553,12 @@ void MainWindow::slotInsertClipInsert()
void MainWindow::slotExtractZone()
{
getMainTimeline()->controller()->extractZone();
getMainTimeline()->controller()->extractZone(m_clipMonitor->getZoneInfo());
}
void MainWindow::slotLiftZone()
{
getMainTimeline()->controller()->liftZone();
getMainTimeline()->controller()->liftZone(m_clipMonitor->getZoneInfo());
}
void MainWindow::slotPreviewRender()
......
......@@ -54,7 +54,7 @@ bool TimelineFunctions::copyClip(std::shared_ptr<TimelineItemModel> timeline, in
return res;
}
bool TimelineFunctions::requestClipCut(std::shared_ptr<TimelineItemModel> timeline, int clipId, int position, int &newId, Fun &undo, Fun &redo)
bool TimelineFunctions::processClipCut(std::shared_ptr<TimelineItemModel> timeline, int clipId, int position, int &newId, Fun &undo, Fun &redo)
{
int start = timeline->getClipPosition(clipId);
int duration = timeline->getClipPlaytime(clipId);
......@@ -79,6 +79,16 @@ bool TimelineFunctions::requestClipCut(std::shared_ptr<TimelineItemModel> timeli
{
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
bool result = TimelineFunctions::requestClipCut(timeline, clipId, position, undo, redo);
if (result) {
pCore->pushUndo(undo, redo, i18n("Cut clip"));
}
return result;
}
bool TimelineFunctions::requestClipCut(std::shared_ptr<TimelineItemModel> timeline, int clipId, int position, Fun &undo, Fun &redo)
{
const std::unordered_set<int> clips = timeline->getGroupElements(clipId);
int count = 0;
for (int cid : clips) {
......@@ -87,7 +97,7 @@ bool TimelineFunctions::requestClipCut(std::shared_ptr<TimelineItemModel> timeli
if (start < position && (start + duration) > position) {
count++;
int newId;
bool res = requestClipCut(timeline, cid, position, newId, undo, redo);
bool res = processClipCut(timeline, cid, position, newId, undo, redo);
if (!res) {
bool undone = undo();
Q_ASSERT(undone);
......@@ -109,9 +119,6 @@ bool TimelineFunctions::requestClipCut(std::shared_ptr<TimelineItemModel> timeli
return false;
}
}
if (count > 0) {
pCore->pushUndo(undo, redo, i18n("Cut clip"));
}
return count > 0;
}
......@@ -182,10 +189,9 @@ bool TimelineFunctions::insertZone(std::shared_ptr<TimelineItemModel> timeline,
result = TimelineFunctions::liftZone(timeline, trackId, QPoint(insertFrame, insertFrame + (zone.y() - zone.x())), undo, redo);
} else {
int startClipId = timeline->getClipByPosition(trackId, insertFrame);
int startCutId = -1;
if (startClipId > -1) {
// There is a clip, cut it
TimelineFunctions::requestClipCut(timeline, startClipId, insertFrame, startCutId, undo, redo);
TimelineFunctions::requestClipCut(timeline, startClipId, insertFrame, undo, redo);
}
result = TimelineFunctions::insertSpace(timeline, trackId, QPoint(insertFrame, insertFrame + (zone.y() - zone.x())), undo, redo);
}
......@@ -200,19 +206,17 @@ bool TimelineFunctions::liftZone(std::shared_ptr<TimelineItemModel> timeline, in
{
// Check if there is a clip at start point
int startClipId = timeline->getClipByPosition(trackId, zone.x());
int startCutId = -1;
if (startClipId > -1) {
// There is a clip, cut it
if (timeline->getClipPosition(startClipId) < zone.x()) {
TimelineFunctions::requestClipCut(timeline, startClipId, zone.x(), startCutId, undo, redo);
TimelineFunctions::requestClipCut(timeline, startClipId, zone.x(), undo, redo);
}
}
int endCutId = -1;
int endClipId = timeline->getClipByPosition(trackId, zone.y());
if (endClipId > -1) {
// There is a clip, cut it
if (timeline->getClipPosition(endClipId) + timeline->getClipPlaytime(endClipId) > zone.y()) {
TimelineFunctions::requestClipCut(timeline, endClipId, zone.y(), endCutId, undo, redo);
TimelineFunctions::requestClipCut(timeline, endClipId, zone.y(), undo, redo);
}
}
std::unordered_set<int> clips = timeline->getItemsAfterPosition(trackId, zone.x(), zone.y() - 1);
......
......@@ -44,8 +44,10 @@ struct TimelineFunctions
@param position: position (in frames) where to cut
*/
static bool requestClipCut(std::shared_ptr<TimelineItemModel> timeline, int clipId, int position);
/* This is the same function, except that it accumulates undo/redo and do not deal with groups */
static bool requestClipCut(std::shared_ptr<TimelineItemModel> timeline, int clipId, int position, int &newId, Fun &undo, Fun &redo);
/* This is the same function, except that it accumulates undo/redo */
static bool requestClipCut(std::shared_ptr<TimelineItemModel> timeline, int clipId, int position, Fun &undo, Fun &redo);
/* This is the same function, except that it accumulates undo/redo and do not deal with groups. Do not call directly */
static bool processClipCut(std::shared_ptr<TimelineItemModel> timeline, int clipId, int position, int &newId, Fun &undo, Fun &redo);
/* @brief Makes a perfect copy of a given clip, but do not insert it */
static bool copyClip(std::shared_ptr<TimelineItemModel> timeline, int clipId, int &newId, PlaylistState::ClipState state, Fun &undo, Fun &redo);
......
......@@ -1294,7 +1294,7 @@ void TimelineController::switchCompositing(int mode)
pCore->requestMonitorRefresh();
}
void TimelineController::extractZone()
void TimelineController::extractZone(QPoint zone)
{
QVector<int> tracks;
if (audioTarget() >= 0) {
......@@ -1306,7 +1306,12 @@ void TimelineController::extractZone()
if (tracks.isEmpty()) {
tracks << m_activeTrack;
}
TimelineFunctions::extractZone(m_model, tracks, m_zone, false);
if (m_zone == QPoint()) {
// Use current timeline position and clip zone length
zone.setY(timelinePosition() + zone.y() - zone.x());
zone.setX(timelinePosition());
}
TimelineFunctions::extractZone(m_model, tracks, m_zone == QPoint() ? zone : m_zone, false);
}
void TimelineController::extract(int clipId)
......@@ -1318,7 +1323,7 @@ void TimelineController::extract(int clipId)
TimelineFunctions::extractZone(m_model, QVector<int>() << track, zone, false);
}
void TimelineController::liftZone()
void TimelineController::liftZone(QPoint zone)
{
QVector<int> tracks;
if (audioTarget() >= 0) {
......@@ -1330,7 +1335,12 @@ void TimelineController::liftZone()
if (tracks.isEmpty()) {
tracks << m_activeTrack;
}
TimelineFunctions::extractZone(m_model, tracks, m_zone, true);
if (m_zone == QPoint()) {
// Use current timeline position and clip zone length
zone.setY(timelinePosition() + zone.y() - zone.x());
zone.setX(timelinePosition());
}
TimelineFunctions::extractZone(m_model, tracks, m_zone == QPoint() ? zone : m_zone, true);
}
bool TimelineController::insertZone(const QString &binId, QPoint zone, bool overwrite)
......
......@@ -315,9 +315,9 @@ public:
/** @brief Change a clip item's speed in timeline */
Q_INVOKABLE void changeItemSpeed(int clipId, int speed);
/** @brief Delete selected zone and fill gap by moving following clips*/
void extractZone();
void extractZone(QPoint zone);
/** @brief Delete selected zone */
void liftZone();
void liftZone(QPoint zone);
bool insertZone(const QString &binId, QPoint zone, bool overwrite);
void updateClip(int clipId, QVector<int> roles);
void showClipKeyframes(int clipId, bool value);
......
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