Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Restore lift & extract operations

parent 3321bfc8
......@@ -2527,22 +2527,12 @@ void MainWindow::slotInsertClipInsert()
void MainWindow::slotExtractZone()
{
// TODO refac
/*
if (pCore->projectManager()->currentTimeline()) {
pCore->projectManager()->currentTimeline()->projectView()->extractZone(QPoint(), true);
}
*/
getMainTimeline()->controller()->extractZone();
}
void MainWindow::slotLiftZone()
{
// TODO refac
/*
if (pCore->projectManager()->currentTimeline()) {
pCore->projectManager()->currentTimeline()->projectView()->extractZone(QPoint(), false);
}
*/
getMainTimeline()->controller()->liftZone();
}
void MainWindow::slotPreviewRender()
......
......@@ -145,3 +145,49 @@ bool TimelineFunctions::requestSpacerEndOperation(std::shared_ptr<TimelineItemMo
}
return false;
}
bool TimelineFunctions::extractZone(std::shared_ptr<TimelineItemModel> timeline, int trackId, QPoint zone, bool liftOnly)
{
// Check if there is a clip at start point
int startClipId = timeline->getClipByPosition(trackId, zone.x());
// Start undoable command
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
int startCutId = -1;
if (startClipId > -1) {
// There is a clip, cut it
TimelineFunctions::requestClipCut(timeline, startClipId, zone.x(), startCutId, undo, redo);
}
int endCutId = -1;
int endClipId = timeline->getClipByPosition(trackId, zone.y());
if (endClipId > -1) {
// There is a clip, cut it
TimelineFunctions::requestClipCut(timeline, endClipId, zone.y(), endCutId, undo, redo);
}
std::unordered_set<int> clips = timeline->getItemsAfterPosition(trackId, zone.x(), zone.y() - 1);
for (const auto &clipId : clips) {
timeline->requestClipDeletion(clipId, undo, redo);
}
if (!liftOnly) {
clips = timeline->getItemsAfterPosition(-1, zone.y() - 1, -1, true);
bool final = false;
if (clips.size() > 0) {
int clipId = *clips.begin();
if (clips.size() > 1) {
int res = timeline->requestClipsGroup(clips, undo, redo);
if (res > -1) {
final = timeline->requestGroupMove(clipId, res, 0, zone.x() - zone.y(), true, true, undo, redo);
if (final) {
final = timeline->requestClipUngroup(clipId, undo, redo);
}
}
} else {
// only 1 clip to be moved
int clipStart = timeline->getItemPosition(clipId);
final = timeline->requestClipMove(clipId, timeline->getItemTrackId(clipId), clipStart - (zone.y() - zone.x()), true, true, undo, redo);
}
}
}
pCore->pushUndo(undo, redo, i18n("Extract zone"));
return true;
}
......@@ -50,6 +50,7 @@ struct TimelineFunctions {
static int requestSpacerStartOperation(std::shared_ptr<TimelineItemModel> timeline, int trackId, int position);
static bool requestSpacerEndOperation(std::shared_ptr<TimelineItemModel> timeline, int clipId, int startPosition, int endPosition);
static bool extractZone(std::shared_ptr<TimelineItemModel> timeline, int trackId, QPoint zone, bool liftOnly);
};
#endif
......@@ -596,7 +596,7 @@ std::unordered_set<int> TimelineModel::getItemsAfterPosition(int trackId, int po
} else {
int target_track_position = getTrackPosition(trackId);
std::advance(it, target_track_position);
std::unordered_set<int> clipTracks = (*it)->getClipsAfterPosition(position);
std::unordered_set<int> clipTracks = (*it)->getClipsAfterPosition(position, end);
allClips.insert(clipTracks.begin(), clipTracks.end());
}
return allClips;
......
......@@ -1030,3 +1030,20 @@ void TimelineController::switchCompositing(int mode)
delete field;
pCore->requestMonitorRefresh();
}
void TimelineController::extractZone()
{
QVariant returnedValue;
QMetaObject::invokeMethod(m_root, "currentTrackId", Q_RETURN_ARG(QVariant, returnedValue));
int currenTrackId = returnedValue.toInt();
TimelineFunctions::extractZone(m_model, currenTrackId, m_zone, false);
}
void TimelineController::liftZone()
{
QVariant returnedValue;
QMetaObject::invokeMethod(m_root, "currentTrackId", Q_RETURN_ARG(QVariant, returnedValue));
int currenTrackId = returnedValue.toInt();
TimelineFunctions::extractZone(m_model, currenTrackId, m_zone, true);
}
......@@ -285,6 +285,10 @@ public:
/** @brief Change a clip item's speed in timeline */
void changeItemSpeed(int clipId, int speed);
/** @brief Delete selected zone and fill gap by moving following clips*/
void extractZone();
/** @brief Delete selected zone */
void liftZone();
public slots:
void selectMultitrack();
......
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