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

Restore timeline insert and insert/overwrite features

parent 9057479f
......@@ -2502,27 +2502,22 @@ void MainWindow::slotCutTimelineClip()
void MainWindow::slotInsertClipOverwrite()
{
// TODO refac
/*
if (pCore->projectManager()->currentTimeline()) {
QPoint binZone = m_clipMonitor->getZoneInfo();
pCore->projectManager()->currentTimeline()->projectView()->insertZone(TimelineMode::OverwriteEdit, m_clipMonitor->activeClipId(), binZone);
const QString &binId = m_clipMonitor->activeClipId();
if (binId.isEmpty()) {
// No clip in monitor
return;
}
*/
getMainTimeline()->controller()->insertZone(binId, m_clipMonitor->getZoneInfo(), true);
}
void MainWindow::slotInsertClipInsert()
{
// TODO refac
/*
if (pCore->projectManager()->currentTimeline()) {
QPoint binZone = m_clipMonitor->getZoneInfo();
int pos = pCore->projectManager()->currentTimeline()->projectView()->insertZone(TimelineMode::InsertEdit, m_clipMonitor->activeClipId(), binZone);
if (pos > 0) {
m_projectMonitor->requestSeek(pos);
}
const QString &binId = m_clipMonitor->activeClipId();
if (binId.isEmpty()) {
// No clip in monitor
return;
}
*/
getMainTimeline()->controller()->insertZone(binId, m_clipMonitor->getZoneInfo(), false);
}
void MainWindow::slotExtractZone()
......
......@@ -148,11 +148,45 @@ bool TimelineFunctions::requestSpacerEndOperation(std::shared_ptr<TimelineItemMo
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; };
bool result = TimelineFunctions::liftZone(timeline, trackId, zone, undo, redo);
if (result && !liftOnly) {
result = TimelineFunctions::removeSpace(timeline, trackId, zone, undo, redo);
}
pCore->pushUndo(undo, redo, liftOnly ? i18n("Lift zone") : i18n("Extract zone"));
return result;
}
bool TimelineFunctions::insertZone(std::shared_ptr<TimelineItemModel> timeline, int trackId, 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;
if (overwrite) {
result = TimelineFunctions::liftZone(timeline, trackId, QPoint(insertFrame, insertFrame + (zone.y() - zone.x())), undo, redo);
} else {
int startClipId = timeline->getClipByPosition(trackId, insertFrame);
int startCutId = -1;
if (startClipId > -1) {
// There is a clip, cut it
TimelineFunctions::requestClipCut(timeline, startClipId, insertFrame, startCutId, undo, redo);
}
result = TimelineFunctions::insertSpace(timeline, trackId, QPoint(insertFrame, insertFrame + (zone.y() - zone.x())), undo, redo);
}
int newId = -1;
QString binClipId = QString("%1#%2#%3").arg(binId).arg(zone.x()).arg(zone.y() - 1);
timeline->requestClipInsertion(binClipId, trackId, insertFrame, newId, true, true, undo, redo);
pCore->pushUndo(undo, redo, overwrite ? i18n("Overwrite zone") : i18n("Insert zone"));
return result;
}
bool TimelineFunctions::liftZone(std::shared_ptr<TimelineItemModel> timeline, int trackId, QPoint zone, Fun &undo, Fun &redo)
{
// Check if there is a clip at start point
int startClipId = timeline->getClipByPosition(trackId, zone.x());
int startCutId = -1;
if (startClipId > -1) {
// There is a clip, cut it
......@@ -168,26 +202,51 @@ bool TimelineFunctions::extractZone(std::shared_ptr<TimelineItemModel> timeline,
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);
}
return true;
}
bool TimelineFunctions::removeSpace(std::shared_ptr<TimelineItemModel> timeline, int trackId, QPoint zone, Fun &undo, Fun &redo)
{
std::unordered_set<int> clips = timeline->getItemsAfterPosition(-1, zone.y() - 1, -1, true);
bool result = false;
if (clips.size() > 0) {
int clipId = *clips.begin();
if (clips.size() > 1) {
int res = timeline->requestClipsGroup(clips, undo, redo);
if (res > -1) {
result = timeline->requestGroupMove(clipId, res, 0, zone.x() - zone.y(), true, true, undo, redo);
if (result) {
result = timeline->requestClipUngroup(clipId, undo, redo);
}
}
} else {
// only 1 clip to be moved
int clipStart = timeline->getItemPosition(clipId);
result = timeline->requestClipMove(clipId, timeline->getItemTrackId(clipId), clipStart - (zone.y() - zone.x()), true, true, undo, redo);
}
}
return result;
}
bool TimelineFunctions::insertSpace(std::shared_ptr<TimelineItemModel> timeline, int trackId, QPoint zone, Fun &undo, Fun &redo)
{
std::unordered_set<int> clips = timeline->getItemsAfterPosition(-1, zone.x(), -1, true);
bool result = false;
if (clips.size() > 0) {
int clipId = *clips.begin();
if (clips.size() > 1) {
int res = timeline->requestClipsGroup(clips, undo, redo);
if (res > -1) {
result = timeline->requestGroupMove(clipId, res, 0, zone.y() - zone.x(), true, true, undo, redo);
if (result) {
result = 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);
}
} else {
// only 1 clip to be moved
int clipStart = timeline->getItemPosition(clipId);
result = timeline->requestClipMove(clipId, timeline->getItemTrackId(clipId), clipStart + (zone.y() - zone.x()), true, true, undo, redo);
}
}
pCore->pushUndo(undo, redo, i18n("Extract zone"));
return true;
return result;
}
......@@ -51,6 +51,10 @@ 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);
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);
};
#endif
......@@ -1047,3 +1047,11 @@ void TimelineController::liftZone()
TimelineFunctions::extractZone(m_model, currenTrackId, m_zone, true);
}
bool TimelineController::insertZone(const QString &binId, QPoint zone, bool overwrite)
{
QVariant returnedValue;
QMetaObject::invokeMethod(m_root, "currentTrackId", Q_RETURN_ARG(QVariant, returnedValue));
int currenTrackId = returnedValue.toInt();
return TimelineFunctions::insertZone(m_model, currenTrackId, binId, m_position, zone, overwrite);
}
......@@ -289,6 +289,7 @@ public:
void extractZone();
/** @brief Delete selected zone */
void liftZone();
bool insertZone(const QString &binId, QPoint zone, bool overwrite);
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