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

Merge branch '2008'

parents 26f6352b 23b87be1
Pipeline #27133 passed with stage
in 9 minutes and 49 seconds
......@@ -1517,7 +1517,7 @@ void MainWindow::setupActions()
editClipMarker->setObjectName(QStringLiteral("edit_marker"));
editClipMarker->setData('P');
QAction *splitAudio = addAction(QStringLiteral("clip_split"), i18n("Split Audio"), this, SLOT(slotSplitAV()),
QAction *splitAudio = addAction(QStringLiteral("clip_split"), i18n("Restore Audio"), this, SLOT(slotSplitAV()),
QIcon::fromTheme(QStringLiteral("document-new")), QKeySequence(), clipActionCategory);
// "S" will be handled specifically to change the action name depending on current selection
splitAudio->setData('S');
......
......@@ -765,11 +765,19 @@ bool TimelineFunctions::requestSplitAudio(const std::shared_ptr<TimelineItemMode
}
int position = timeline->getClipPosition(cid);
int track = timeline->getClipTrackId(cid);
QList<int> possibleTracks = audioTarget >= 0 ? QList<int>() << audioTarget : timeline->getLowerTracksId(track, TrackType::AudioTrack);
QList<int> possibleTracks;
if (audioTarget >= 0) {
possibleTracks = {audioTarget};
} else {
int mirror = timeline->getMirrorAudioTrackId(track);
if (mirror > -1) {
possibleTracks = {mirror};
}
}
if (possibleTracks.isEmpty()) {
// No available audio track for splitting, abort
undo();
pCore->displayMessage(i18n("No available audio track for split operation"), ErrorMessage);
pCore->displayMessage(i18n("No available audio track for restore operation"), ErrorMessage);
return false;
}
int newId;
......@@ -777,7 +785,7 @@ bool TimelineFunctions::requestSplitAudio(const std::shared_ptr<TimelineItemMode
if (!res) {
bool undone = undo();
Q_ASSERT(undone);
pCore->displayMessage(i18n("Audio split failed"), ErrorMessage);
pCore->displayMessage(i18n("Audio restore failed"), ErrorMessage);
return false;
}
bool success = false;
......@@ -790,14 +798,14 @@ bool TimelineFunctions::requestSplitAudio(const std::shared_ptr<TimelineItemMode
if (!success) {
bool undone = undo();
Q_ASSERT(undone);
pCore->displayMessage(i18n("Audio split failed"), ErrorMessage);
pCore->displayMessage(i18n("Audio restore failed"), ErrorMessage);
return false;
}
done = true;
}
if (done) {
timeline->requestSetSelection(clips, undo, redo);
pCore->pushUndo(undo, redo, i18n("Split Audio"));
pCore->pushUndo(undo, redo, i18n("Restore Audio"));
}
return done;
}
......@@ -816,11 +824,20 @@ bool TimelineFunctions::requestSplitVideo(const std::shared_ptr<TimelineItemMode
continue;
}
int position = timeline->getClipPosition(cid);
QList<int> possibleTracks = QList<int>() << videoTarget;
int track = timeline->getClipTrackId(cid);
QList<int> possibleTracks;
if (videoTarget >= 0) {
possibleTracks = {videoTarget};
} else {
int mirror = timeline->getMirrorVideoTrackId(track);
if (mirror > -1) {
possibleTracks = {mirror};
}
}
if (possibleTracks.isEmpty()) {
// No available audio track for splitting, abort
undo();
pCore->displayMessage(i18n("No available video track for split operation"), ErrorMessage);
pCore->displayMessage(i18n("No available video track for restore operation"), ErrorMessage);
return false;
}
int newId;
......@@ -828,7 +845,7 @@ bool TimelineFunctions::requestSplitVideo(const std::shared_ptr<TimelineItemMode
if (!res) {
bool undone = undo();
Q_ASSERT(undone);
pCore->displayMessage(i18n("Video split failed"), ErrorMessage);
pCore->displayMessage(i18n("Video restore failed"), ErrorMessage);
return false;
}
bool success = false;
......@@ -841,13 +858,13 @@ bool TimelineFunctions::requestSplitVideo(const std::shared_ptr<TimelineItemMode
if (!success) {
bool undone = undo();
Q_ASSERT(undone);
pCore->displayMessage(i18n("Video split failed"), ErrorMessage);
pCore->displayMessage(i18n("Video restore failed"), ErrorMessage);
return false;
}
done = true;
}
if (done) {
pCore->pushUndo(undo, redo, i18n("Split Video"));
pCore->pushUndo(undo, redo, i18n("Restore Video"));
}
return done;
}
......
......@@ -1165,13 +1165,14 @@ void TimelineController::setPosition(int position)
void TimelineController::setAudioTarget(QMap<int, int> tracks)
{
if ((!tracks.isEmpty() && !m_model->isTrack(tracks.firstKey())) || m_hasAudioTarget == 0) {
return;
}
// Clear targets before re-adding to trigger qml refresh
m_model->m_audioTarget.clear();
emit audioTargetChanged();
if ((!tracks.isEmpty() && !m_model->isTrack(tracks.firstKey())) || m_hasAudioTarget == 0) {
return;
}
m_model->m_audioTarget = tracks;
emit audioTargetChanged();
}
......@@ -1225,6 +1226,7 @@ int TimelineController::getFirstUnassignedStream() const
void TimelineController::setVideoTarget(int track)
{
if ((track > -1 && !m_model->isTrack(track)) || !m_hasVideoTarget) {
m_model->m_videoTarget = -1;
return;
}
m_model->m_videoTarget = track;
......@@ -2313,7 +2315,9 @@ bool TimelineController::splitAV()
if (clip->clipState() == PlaylistState::AudioOnly) {
return TimelineFunctions::requestSplitVideo(m_model, cid, videoTarget());
} else {
return TimelineFunctions::requestSplitAudio(m_model, cid, m_model->m_audioTarget.firstKey());
QVariantList aTargets = audioTarget();
int targetTrack = aTargets.isEmpty() ? -1 : aTargets.first().toInt();
return TimelineFunctions::requestSplitAudio(m_model, cid, targetTrack);
}
}
pCore->displayMessage(i18n("No clip found to perform AV split operation"), InformationMessage, 500);
......@@ -2322,7 +2326,9 @@ bool TimelineController::splitAV()
void TimelineController::splitAudio(int clipId)
{
TimelineFunctions::requestSplitAudio(m_model, clipId, m_model->m_audioTarget.firstKey());
QVariantList aTargets = audioTarget();
int targetTrack = aTargets.isEmpty() ? -1 : aTargets.first().toInt();
TimelineFunctions::requestSplitAudio(m_model, clipId, targetTrack);
}
void TimelineController::splitVideo(int clipId)
......@@ -2871,7 +2877,25 @@ void TimelineController::updateClipActions()
} else if (actionData == QLatin1Char('X') || actionData == QLatin1Char('S')) {
enableAction = clip && clip->canBeVideo() && clip->canBeAudio();
if (enableAction && actionData == QLatin1Char('S')) {
act->setText(clip->clipState() == PlaylistState::AudioOnly ? i18n("Split video") : i18n("Split audio"));
PlaylistState::ClipState state = clip->clipState();
if (m_model->m_groups->isInGroup(item)) {
// Check if all clips in the group have have same state (audio or video)
int targetRoot = m_model->m_groups->getRootId(item);
if (m_model->isGroup(targetRoot)) {
std::unordered_set<int> sub = m_model->m_groups->getLeaves(targetRoot);
for (int current_id : sub) {
if (current_id == item) {
continue;
}
if (m_model->isClip(current_id) && m_model->getClipPtr(current_id)->clipState() != state) {
// Group with audio and video clips, disable split action
enableAction = false;
break;
}
}
}
}
act->setText(state == PlaylistState::AudioOnly ? i18n("Restore video") : i18n("Restore audio"));
}
} else if (actionData == QLatin1Char('W')) {
enableAction = clip != nullptr;
......
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