Commit 09d00866 authored by Stefan Kobza's avatar Stefan Kobza Committed by Jean-Baptiste Mardelle

Cut all clips at timeline position using ctrl+shift+r.

parent e34fa543
......@@ -1547,6 +1547,9 @@ void MainWindow::setupActions()
act = addAction(QStringLiteral("cut_timeline_clip"), i18n("Cut Clip"), this, SLOT(slotCutTimelineClip()), QIcon::fromTheme(QStringLiteral("edit-cut")),
Qt::SHIFT + Qt::Key_R);
act = addAction(QStringLiteral("cut_timeline_all_clips"), i18n("Cut All Clips"), this, SLOT(slotCutTimelineAllClips()), QIcon::fromTheme(QStringLiteral("edit-cut")),
Qt::CTRL + Qt::SHIFT + Qt::Key_R);
act = addAction(QStringLiteral("delete_timeline_clip"), i18n("Delete Selected Item"), this, SLOT(slotDeleteItem()),
QIcon::fromTheme(QStringLiteral("edit-delete")), Qt::Key_Delete);
......@@ -2628,6 +2631,11 @@ void MainWindow::slotCutTimelineClip()
getMainTimeline()->controller()->cutClipUnderCursor();
}
void MainWindow::slotCutTimelineAllClips()
{
getMainTimeline()->controller()->cutAllClipsUnderCursor();
}
void MainWindow::slotInsertClipOverwrite()
{
const QString &binId = m_clipMonitor->activeClipId();
......
......@@ -334,6 +334,7 @@ private slots:
* This can be useful to mark something during playback. */
void slotAddMarkerGuideQuickly();
void slotCutTimelineClip();
void slotCutTimelineAllClips();
void slotInsertClipOverwrite();
void slotInsertClipInsert();
void slotExtractZone();
......
......@@ -233,6 +233,49 @@ bool TimelineFunctions::requestClipCut(const std::shared_ptr<TimelineItemModel>
return count > 0;
}
bool TimelineFunctions::requestClipCutAll(std::shared_ptr<TimelineItemModel> timeline, int position)
{
QVector<std::shared_ptr<TrackModel>> affectedTracks;
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
for (auto track: timeline->m_allTracks) {
if (!track->isLocked()) {
affectedTracks << track;
}
}
if (affectedTracks.isEmpty()) {
pCore->displayMessage(i18n("All tracks are locked"), InformationMessage, 500);
return false;
}
unsigned count = 0;
for (auto track: affectedTracks) {
int clipId = track->getClipByPosition(position);
if (clipId > -1) {
// Found clip at position in track, cut it. Update undo/redo as we go.
if (!TimelineFunctions::requestClipCut(timeline, clipId, position, undo, redo)) {
qWarning() << "Failed to cut clip " << clipId << " at " << position;
pCore->displayMessage(i18n("Failed to cut clip"), ErrorMessage, 500);
// Undo all cuts made, assert successful undo.
bool undone = undo();
Q_ASSERT(undone);
return false;
}
count++;
}
}
if (!count) {
pCore->displayMessage(i18n("No clips to cut"), InformationMessage);
} else {
pCore->pushUndo(undo, redo, i18n("Cut all clips"));
}
return count > 0;
}
int TimelineFunctions::requestSpacerStartOperation(const std::shared_ptr<TimelineItemModel> &timeline, int trackId, int position)
{
std::unordered_set<int> clips = timeline->getItemsInRange(trackId, position, -1);
......
......@@ -51,6 +51,9 @@ struct TimelineFunctions
/* This is the same function, except that it accumulates undo/redo and do not deal with groups. Do not call directly */
static bool processClipCut(const std::shared_ptr<TimelineItemModel> &timeline, int clipId, int position, int &newId, Fun &undo, Fun &redo);
/* Cuts all clips at given position */
static bool requestClipCutAll(std::shared_ptr<TimelineItemModel> timeline, int position);
/* @brief Makes a perfect clone of a given clip, but do not insert it */
static bool cloneClip(const std::shared_ptr<TimelineItemModel> &timeline, int clipId, int &newId, PlaylistState::ClipState state, Fun &undo, Fun &redo);
......
......@@ -1248,6 +1248,16 @@ void TimelineController::cutClipUnderCursor(int position, int track)
}
}
void TimelineController::cutAllClipsUnderCursor(int position)
{
if (position == -1) {
position = pCore->getTimelinePosition();
}
QMutexLocker lk(&m_metaMutex);
TimelineFunctions::requestClipCutAll(m_model, position);
}
int TimelineController::requestSpacerStartOperation(int trackId, int position)
{
QMutexLocker lk(&m_metaMutex);
......
......@@ -340,6 +340,9 @@ public:
/* @brief Cuts the clip on current track at timeline position
*/
Q_INVOKABLE void cutClipUnderCursor(int position = -1, int track = -1);
/* @brief Cuts all clips at timeline position
*/
Q_INVOKABLE void cutAllClipsUnderCursor(int position = -1);
/* @brief Request a spacer operation
*/
Q_INVOKABLE int requestSpacerStartOperation(int trackId, int position);
......
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