Fix spacer in overwrite mode, disable spacer in insert mode.

Fixes #677
parent d98c006e
Pipeline #24011 canceled with stage
......@@ -2984,6 +2984,16 @@ void MainWindow::slotChangeEdit(QAction *action)
m_trimLabel->setStyleSheet(QString());
}
getMainTimeline()->controller()->getModel()->setEditMode(mode);
if (mode == TimelineMode::InsertEdit) {
// Disable spacer tool in insert mode
if (m_buttonSpacerTool->isChecked()) {
m_buttonSelectTool->setChecked(true);
slotSetTool(SelectTool);
}
m_buttonSpacerTool->setEnabled(false);
} else {
m_buttonSpacerTool->setEnabled(true);
}
}
void MainWindow::slotSetTool(ProjectTool tool)
......
......@@ -248,7 +248,7 @@ bool TimelineFunctions::requestClipCut(const std::shared_ptr<TimelineItemModel>
}
}
return count > 0;
}
}
bool TimelineFunctions::requestClipCutAll(std::shared_ptr<TimelineItemModel> timeline, int position)
{
......@@ -303,7 +303,7 @@ int TimelineFunctions::requestSpacerStartOperation(const std::shared_ptr<Timelin
return -1;
}
bool TimelineFunctions::requestSpacerEndOperation(const std::shared_ptr<TimelineItemModel> &timeline, int itemId, int startPosition, int endPosition)
bool TimelineFunctions::requestSpacerEndOperation(const std::shared_ptr<TimelineItemModel> &timeline, int itemId, int startPosition, int endPosition, int affectedTrack)
{
// Move group back to original position
int track = timeline->getItemTrackId(itemId);
......@@ -317,12 +317,33 @@ bool TimelineFunctions::requestSpacerEndOperation(const std::shared_ptr<Timeline
// Start undoable command
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
//int res = timeline->requestClipsGroup(clips, undo, redo, GroupType::Selection);
int res = timeline->m_groups->getRootId(itemId);
int mainGroup = timeline->m_groups->getRootId(itemId);
bool final = false;
if (res > -1 || clips.size() == 1) {
bool liftOk = true;
if (timeline->m_editMode == TimelineMode::OverwriteEdit && endPosition < startPosition) {
// Remove zone between end and start pos
if (affectedTrack == -1) {
// touch all tracks
auto it = timeline->m_allTracks.cbegin();
while (it != timeline->m_allTracks.cend()) {
int target_track = (*it)->getId();
if (!timeline->getTrackById_const(target_track)->isLocked()) {
liftOk = liftOk && TimelineFunctions::liftZone(timeline, target_track, QPoint(endPosition, startPosition), undo, redo);
}
++it;
}
} else {
liftOk = TimelineFunctions::liftZone(timeline, affectedTrack, QPoint(endPosition, startPosition), undo, redo);
}
// The lift operation destroys selection group, so regroup now
if (clips.size() > 1) {
final = timeline->requestGroupMove(itemId, res, 0, endPosition - startPosition, true, true, undo, redo);
timeline->requestSetSelection(clips);
mainGroup = timeline->m_groups->getRootId(itemId);
}
}
if (liftOk && (mainGroup > -1 || clips.size() == 1)) {
if (clips.size() > 1) {
final = timeline->requestGroupMove(itemId, mainGroup, 0, endPosition - startPosition, true, true, undo, redo);
} else {
// only 1 clip to be moved
if (isClip) {
......@@ -340,6 +361,8 @@ bool TimelineFunctions::requestSpacerEndOperation(const std::shared_ptr<Timeline
pCore->pushUndo(undo, redo, i18n("Remove space"));
}
return true;
} else {
undo();
}
return false;
}
......@@ -1726,7 +1749,7 @@ bool TimelineFunctions::requestDeleteBlankAt(const std::shared_ptr<TimelineItemM
return false;
}
int start = timeline->getItemPosition(cid);
requestSpacerEndOperation(timeline, cid, start, start - spaceDuration);
requestSpacerEndOperation(timeline, cid, start, start - spaceDuration, affectAllTracks ? -1 : trackId);
return true;
}
......
......@@ -86,7 +86,7 @@ struct TimelineFunctions
static bool requestDeleteBlankAt(const std::shared_ptr<TimelineItemModel> &timeline, int trackId, int position, bool affectAllTracks);
static int requestSpacerStartOperation(const std::shared_ptr<TimelineItemModel> &timeline, int trackId, int position);
static bool requestSpacerEndOperation(const std::shared_ptr<TimelineItemModel> &timeline, int itemId, int startPosition, int endPosition);
static bool requestSpacerEndOperation(const std::shared_ptr<TimelineItemModel> &timeline, int itemId, int startPosition, int endPosition, int affectedTrack);
static bool extractZone(const std::shared_ptr<TimelineItemModel> &timeline, QVector<int> tracks, QPoint zone, bool liftOnly);
static bool liftZone(const std::shared_ptr<TimelineItemModel> &timeline, int trackId, QPoint zone, Fun &undo, Fun &redo);
static bool removeSpace(const std::shared_ptr<TimelineItemModel> &timeline, QPoint zone, Fun &undo, Fun &redo, QVector<int> allowedTracks = QVector<int>(), bool useTargets = true);
......
......@@ -285,7 +285,9 @@ Rectangle {
property int clipBeingMovedId: -1
property int consumerPosition: proxy.position
property int spacerGroup: -1
property int spacerTrack: -1
property int spacerFrame: -1
property int finalSpacerFrame: -1
property int spacerClickFrame: -1
property real timeScale: timeline.scaleFactor
property int snapping: (timeline.snap && (timeline.scaleFactor < 2 * baseUnit)) ? Math.floor(baseUnit / (timeline.scaleFactor > 3 ? timeline.scaleFactor / 2 : timeline.scaleFactor)) : -1
......@@ -834,8 +836,8 @@ Rectangle {
// spacer tool
var y = mouse.y - ruler.height + scrollView.contentY
var frame = (scrollView.contentX + mouse.x) / timeline.scaleFactor
var track = (mouse.modifiers & Qt.ControlModifier) ? tracksRepeater.itemAt(Logic.getTrackIndexFromPos(y)).trackInternalId : -1
spacerGroup = timeline.requestSpacerStartOperation(track, frame)
spacerTrack = (mouse.modifiers & Qt.ControlModifier) ? tracksRepeater.itemAt(Logic.getTrackIndexFromPos(y)).trackInternalId : -1
spacerGroup = timeline.requestSpacerStartOperation(spacerTrack, frame)
if (spacerGroup > -1) {
drag.axis = Drag.XAxis
Drag.active = true
......@@ -919,7 +921,7 @@ Rectangle {
// Move group
var track = controller.getItemTrackId(spacerGroup)
var frame = Math.round((mouse.x + scrollView.contentX) / timeline.scaleFactor) + spacerFrame - spacerClickFrame
frame = controller.suggestItemMove(spacerGroup, track, frame, root.consumerPosition, (mouse.modifiers & Qt.ShiftModifier) ? 0 : root.snapping)[0]
finalSpacerFrame = controller.suggestItemMove(spacerGroup, track, frame, root.consumerPosition, (mouse.modifiers & Qt.ShiftModifier) ? 0 : root.snapping)[0]
continuousScrolling(mouse.x + scrollView.contentX, mouse.y + scrollView.contentY)
}
scim = true
......@@ -962,9 +964,9 @@ Rectangle {
}
return
}
if (spacerGroup > -1) {
if (spacerGroup > -1 && finalSpacerFrame > -1) {
var frame = controller.getItemPosition(spacerGroup)
timeline.requestSpacerEndOperation(spacerGroup, spacerFrame, frame);
timeline.requestSpacerEndOperation(spacerGroup, spacerFrame, finalSpacerFrame, spacerTrack);
spacerClickFrame = -1
spacerFrame = -1
spacerGroup = -1
......
......@@ -1377,10 +1377,10 @@ int TimelineController::requestSpacerStartOperation(int trackId, int position)
return itemId;
}
bool TimelineController::requestSpacerEndOperation(int clipId, int startPosition, int endPosition)
bool TimelineController::requestSpacerEndOperation(int clipId, int startPosition, int endPosition, int affectedTrack)
{
QMutexLocker lk(&m_metaMutex);
bool result = TimelineFunctions::requestSpacerEndOperation(m_model, clipId, startPosition, endPosition);
bool result = TimelineFunctions::requestSpacerEndOperation(m_model, clipId, startPosition, endPosition, affectedTrack);
return result;
}
......@@ -1824,7 +1824,8 @@ void TimelineController::insertSpace(int trackId, int frame)
delete d;
return;
}
int cid = requestSpacerStartOperation(d->affectAllTracks() ? -1 : trackId, frame);
bool affectAllTracks = d->affectAllTracks();
int cid = requestSpacerStartOperation(affectAllTracks ? -1 : trackId, frame);
int spaceDuration = d->selectedDuration().frames(pCore->getCurrentFps());
delete d;
if (cid == -1) {
......@@ -1832,7 +1833,7 @@ void TimelineController::insertSpace(int trackId, int frame)
return;
}
int start = m_model->getItemPosition(cid);
requestSpacerEndOperation(cid, start, start + spaceDuration);
requestSpacerEndOperation(cid, start, start + spaceDuration, affectAllTracks ? -1 : trackId);
}
void TimelineController::removeSpace(int trackId, int frame, bool affectAllTracks)
......
......@@ -354,7 +354,7 @@ public:
Q_INVOKABLE int requestSpacerStartOperation(int trackId, int position);
/* @brief Request a spacer operation
*/
Q_INVOKABLE bool requestSpacerEndOperation(int clipId, int startPosition, int endPosition);
Q_INVOKABLE bool requestSpacerEndOperation(int clipId, int startPosition, int endPosition, int affectedTrack);
/* @brief Request a Fade in effect for clip
*/
Q_INVOKABLE void adjustFade(int cid, const QString &effectId, int duration, int initialDuration);
......
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