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

Fix insert/overwrite zone target tracks

parent b203b788
......@@ -242,14 +242,18 @@ bool TimelineFunctions::extractZone(std::shared_ptr<TimelineItemModel> timeline,
return result;
}
bool TimelineFunctions::insertZone(std::shared_ptr<TimelineItemModel> timeline, int trackId, const QString &binId, int insertFrame, QPoint zone, bool overwrite)
bool TimelineFunctions::insertZone(std::shared_ptr<TimelineItemModel> timeline, QList<int> trackIds, const QString &binId, int insertFrame, QPoint zone, bool overwrite)
{
// Start undoable command
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
bool result = false;
int trackId = trackIds.takeFirst();
if (overwrite) {
result = TimelineFunctions::liftZone(timeline, trackId, QPoint(insertFrame, insertFrame + (zone.y() - zone.x())), undo, redo);
if (!trackIds.isEmpty()) {
result = result && TimelineFunctions::liftZone(timeline, trackIds.takeFirst(), QPoint(insertFrame, insertFrame + (zone.y() - zone.x())), undo, redo);
}
} else {
// Cut all tracks
auto it = timeline->m_allTracks.cbegin();
......@@ -272,7 +276,9 @@ bool TimelineFunctions::insertZone(std::shared_ptr<TimelineItemModel> timeline,
int newId = -1;
QString binClipId = QString("%1/%2/%3").arg(binId).arg(zone.x()).arg(zone.y() - 1);
result = timeline->requestClipInsertion(binClipId, trackId, insertFrame, newId, true, true, true, undo, redo);
pCore->pushUndo(undo, redo, overwrite ? i18n("Overwrite zone") : i18n("Insert zone"));
if (result) {
pCore->pushUndo(undo, redo, overwrite ? i18n("Overwrite zone") : i18n("Insert zone"));
}
}
if (!result){
undo();
......
......@@ -69,7 +69,7 @@ struct TimelineFunctions
static bool liftZone(std::shared_ptr<TimelineItemModel> timeline, int trackId, QPoint zone, Fun &undo, Fun &redo);
static bool removeSpace(std::shared_ptr<TimelineItemModel> timeline, int trackId, QPoint zone, Fun &undo, Fun &redo);
static bool insertSpace(std::shared_ptr<TimelineItemModel> timeline, int trackId, QPoint zone, Fun &undo, Fun &redo);
static bool insertZone(std::shared_ptr<TimelineItemModel> timeline, int trackId, const QString &binId, int insertFrame, QPoint zone, bool overwrite);
static bool insertZone(std::shared_ptr<TimelineItemModel> timeline, QList<int> trackIds, const QString &binId, int insertFrame, QPoint zone, bool overwrite);
static bool requestItemCopy(std::shared_ptr<TimelineItemModel> timeline, int clipId, int trackId, int position);
static void showClipKeyframes(std::shared_ptr<TimelineItemModel> timeline, int clipId, bool value);
......
......@@ -888,6 +888,9 @@ bool TimelineModel::requestClipInsertion(const QString &binClipId, int trackId,
}
std::shared_ptr<ProjectClip> master = pCore->projectItemModel()->getClipByBinID(bid);
type = master->clipType();
if (useTargets && m_audioTarget == -1 && m_videoTarget == -1) {
useTargets = false;
}
if (dropType == PlaylistState::Disabled && (type == ClipType::AV || type == ClipType::Playlist)) {
if (m_audioTarget >= 0 && m_videoTarget == -1 && useTargets) {
......@@ -897,24 +900,15 @@ bool TimelineModel::requestClipInsertion(const QString &binClipId, int trackId,
bool audioDrop = getTrackById_const(trackId)->isAudioTrack();
res = requestClipCreation(binClipId, id, getTrackById_const(trackId)->trackType(), local_undo, local_redo);
res = res && requestClipMove(id, trackId, position, refreshView, logUndo, local_undo, local_redo);
if (m_videoTarget >= 0 && m_audioTarget == -1) {
// No audio target defined, only extract video
audioDrop = true;
} else if (m_audioTarget >= 0) {
if (getTrackById_const(m_audioTarget)->isLocked()) {
// Audio target locked, only extract video
audioDrop = true;
}
}
if (res && !useTargets) {
int target_track = audioDrop ? m_videoTarget : m_audioTarget;
int target_track = audioDrop ? m_videoTarget : m_audioTarget;
if (res && (!useTargets || target_track > -1)) {
if (!useTargets) {
target_track = audioDrop ? getMirrorVideoTrackId(trackId) : getMirrorAudioTrackId(trackId);
}
// QList<int> possibleTracks = m_audioTarget >= 0 ? QList<int>() << m_audioTarget : getLowerTracksId(trackId, TrackType::AudioTrack);
QList<int> possibleTracks;
qDebug() << "CREATING SPLIT " << target_track << " usetargets" << useTargets;
if (target_track >= 0) {
if (target_track >= 0 && !getTrackById_const(target_track)->isLocked()) {
possibleTracks << target_track;
}
if (possibleTracks.isEmpty()) {
......
......@@ -1453,19 +1453,22 @@ void TimelineController::extract(int clipId)
int TimelineController::insertZone(const QString &binId, QPoint zone, bool overwrite)
{
std::shared_ptr<ProjectClip> clip = pCore->bin()->getBinClip(binId);
int targetTrack = -1;
if (audioTarget() == -1 && videoTarget() == -1) {
int aTrack = -1;
int vTrack = -1;
if (clip->hasAudio()) {
aTrack = audioTarget();
}
if (clip->hasVideo()) {
vTrack = videoTarget();
}
if (aTrack == -1 && vTrack == -1) {
// No target tracks defined, use active track
targetTrack = m_activeTrack;
} else if (clip->clipType() == ClipType::Audio) {
// Audio clip, only allowed on audio track
targetTrack = audioTarget();
} else {
// Video clip
targetTrack = videoTarget();
if (targetTrack == -1 && clip->hasAudio()) {
// No video target defined, switch to audio if available
targetTrack = audioTarget();
if (m_model->getTrackById_const(m_activeTrack)->isAudioTrack()) {
aTrack = m_activeTrack;
vTrack = m_model->getMirrorVideoTrackId(aTrack);
} else {
vTrack = m_activeTrack;
aTrack = m_model->getMirrorAudioTrackId(vTrack);
}
}
int insertPoint;
......@@ -1479,8 +1482,14 @@ int TimelineController::insertZone(const QString &binId, QPoint zone, bool overw
insertPoint = timelinePosition();
sourceZone = zone;
}
return TimelineFunctions::insertZone(m_model, targetTrack, binId, insertPoint, sourceZone, overwrite) ? insertPoint + (sourceZone.y() - sourceZone.x())
: -1;
QList <int> target_tracks;
if (vTrack > -1) {
target_tracks << vTrack;
}
if (aTrack > -1) {
target_tracks << aTrack;
}
return TimelineFunctions::insertZone(m_model, target_tracks, binId, insertPoint, sourceZone, overwrite) ? insertPoint + (sourceZone.y() - sourceZone.x()) : -1;
}
void TimelineController::updateClip(int clipId, QVector<int> roles)
......
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