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

Various fixes for spacer moving guides

parent 897371d7
Pipeline #62651 passed with stage
in 8 minutes and 25 seconds
......@@ -254,6 +254,38 @@ bool MarkerListModel::moveMarker(int mid, GenTime pos)
return true;
}
void MarkerListModel::moveMarkersWithoutUndo(QVector<int> markersId, int offset, bool updateView)
{
QWriteLocker locker(&m_lock);
if(markersId.length() <= 0) {
return;
}
int firstRow = -1;
int lastRow = -1;
for (int &mid : markersId) {
Q_ASSERT(m_markerList.count(mid) > 0);
GenTime t = m_markerList.at(mid).time() + GenTime(offset, pCore->getCurrentFps());
m_markerList[mid].setTime(t);
if (!updateView) {
continue;
}
if (firstRow == -1) {
firstRow = getRowfromId(mid);
lastRow = firstRow;
} else {
int row = getRowfromId(mid);
if (row > lastRow) {
lastRow = row;
} else if (row < firstRow) {
firstRow = row;
}
}
}
if (updateView) {
emit dataChanged(index(firstRow), index(lastRow), {FrameRole});
}
}
bool MarkerListModel::moveMarkers(QList<CommentedTime> markers, GenTime fromPos, GenTime toPos, Fun &undo, Fun &redo)
{
QWriteLocker locker(&m_lock);
......@@ -455,6 +487,33 @@ QList<CommentedTime> MarkerListModel::getMarkersInRange(int start, int end) cons
return markers;
}
int MarkerListModel::getMarkerPos(int mid) const
{
READ_LOCK();
Q_ASSERT(m_markerList.count(mid) > 0);
return m_markerList.at(mid).time().frames(pCore->getCurrentFps());
}
QVector<int> MarkerListModel::getMarkersIdInRange(int start, int end) const
{
READ_LOCK();
QVector<int> markers;
// Ensure we provide sorted markers list
std::map<CommentedTime,int> sortedList;
for(std::map<int, CommentedTime>::const_iterator it = m_markerList.begin(); it != m_markerList.end(); ++it)
sortedList.insert(std::pair<CommentedTime, int>(it -> second, it -> first));
for (const auto &marker : sortedList) {
int pos = marker.first.time().frames(pCore->getCurrentFps());
if(pos >= start && (end == -1 || pos <= end)) {
markers << marker.second;
}
}
return markers;
}
std::vector<int> MarkerListModel::getSnapPoints() const
{
READ_LOCK();
......
......@@ -98,6 +98,7 @@ public:
*/
bool moveMarkers(QList<CommentedTime> markers, GenTime fromPos, GenTime toPos, Fun &undo, Fun &redo);
bool moveMarker(int mid, GenTime pos);
void moveMarkersWithoutUndo(QVector<int> markersId, int offset, bool updateView = true);
/** @brief This describes the available markers type and their corresponding colors */
static std::array<QColor, 9> markerTypes;
......@@ -113,6 +114,10 @@ public:
* @param end is the position after which markers will not be returned, set to -1 to get all markers after start
*/
QList<CommentedTime> getMarkersInRange(int start, int end) const;
QVector<int> getMarkersIdInRange(int start, int end) const;
/** @brief Returns a marker position in frames given it's id */
int getMarkerPos(int mid) const;
/** @brief Returns all markers positions in model */
std::vector<int> getSnapPoints() const;
......
......@@ -390,6 +390,7 @@ Rectangle {
property int snapping: (timeline.snap && (timeline.scaleFactor < 2 * baseUnit)) ? Math.floor(baseUnit / (timeline.scaleFactor > 3 ? timeline.scaleFactor / 2 : timeline.scaleFactor)) : -1
property var timelineSelection: timeline.selection
property int selectedMix: timeline.selectedMix
property var selectedGuides
property int trackHeight
property int copiedClip: -1
property int zoomOnMouse: -1
......@@ -1164,6 +1165,16 @@ Rectangle {
spacerClickFrame = frame
spacerFrame = spacerGroup > -1 ? controller.getItemPosition(spacerGroup) : frame
finalSpacerFrame = spacerFrame
if (spacerGuides) {
selectedGuides = timeline.spacerSelection(spacerClickFrame)
if (selectedGuides.length > 0) {
var firstGuidePos = timeline.getGuidePosition(selectedGuides[0])
if (spacerGroup > -1 && firstGuidePos < spacerFrame) {
// Don't allow moving guide below 0
spacerMinPos = Math.max(spacerMinPos, spacerFrame - firstGuidePos + 1)
}
}
}
}
} else if (root.activeTool === 0 || mouse.y <= ruler.height) {
if (mouse.y > ruler.height) {
......@@ -1257,12 +1268,19 @@ Rectangle {
} else if (root.activeTool === 2 && spacerGroup > -1) {
// Spacer tool, move group
var track = controller.getItemTrackId(spacerGroup)
var lastPos = controller.getItemPosition(spacerGroup)
var frame = Math.round((mouse.x + scrollView.contentX) / timeline.scaleFactor) + spacerFrame - spacerClickFrame
frame = Math.max(spacerMinPos, frame)
finalSpacerFrame = controller.suggestItemMove(spacerGroup, track, frame, root.consumerPosition, (mouse.modifiers & Qt.ShiftModifier) ? 0 : root.snapping)[0]
if (spacerGuides) {
timeline.spacerMoveGuides(selectedGuides, finalSpacerFrame - lastPos)
}
continuousScrolling(mouse.x + scrollView.contentX, mouse.y + scrollView.contentY)
} else if (spacerGuides) {
finalSpacerFrame = Math.round((mouse.x + scrollView.contentX) / timeline.scaleFactor) + spacerFrame - spacerClickFrame
var frame = Math.round((mouse.x + scrollView.contentX) / timeline.scaleFactor)
frame = Math.max(spacerMinPos, frame)
timeline.spacerMoveGuides(selectedGuides, frame - spacerFrame)
spacerFrame = frame;
}
scim = true
......@@ -1327,15 +1345,19 @@ Rectangle {
if (spacerGroup > -1 && finalSpacerFrame > -1) {
var frame = controller.getItemPosition(spacerGroup)
timeline.requestSpacerEndOperation(spacerGroup, spacerFrame, finalSpacerFrame, spacerTrack, spacerGuides ? spacerClickFrame : -1);
timeline.requestSpacerEndOperation(spacerGroup, spacerFrame, finalSpacerFrame, spacerTrack, selectedGuides, spacerGuides ? spacerClickFrame : -1);
} else if (spacerGuides) {
timeline.moveGuidesInRange(spacerClickFrame, -1, finalSpacerFrame - spacerFrame)
// Move back guides to original pos
timeline.spacerMoveGuides(selectedGuides, spacerClickFrame - spacerFrame)
timeline.moveGuidesInRange(spacerClickFrame, -1, spacerFrame - finalSpacerFrame)
}
if (spacerGroup > -1 && finalSpacerFrame > -1 || spacerGuides) {
spacerClickFrame = -1
spacerFrame = -1
spacerGroup = -1
spacerMinPos = -1
selectedGuides = []
spacerGuides = false
}
......
......@@ -1640,13 +1640,30 @@ int TimelineController::spacerMinPos() const
return TimelineFunctions::spacerMinPos();
}
bool TimelineController::requestSpacerEndOperation(int clipId, int startPosition, int endPosition, int affectedTrack, int guideStart)
void TimelineController::spacerMoveGuides(QVector<int> ids, int offset)
{
pCore->currentDoc()->getGuideModel()->moveMarkersWithoutUndo(ids, offset);
}
QVector<int> TimelineController::spacerSelection(int startFrame)
{
return pCore->currentDoc()->getGuideModel()->getMarkersIdInRange(startFrame, -1);
}
int TimelineController::getGuidePosition(int id)
{
return pCore->currentDoc()->getGuideModel()->getMarkerPos(id);
}
bool TimelineController::requestSpacerEndOperation(int clipId, int startPosition, int endPosition, int affectedTrack, QVector <int> selectedGuides, int guideStart)
{
QMutexLocker lk(&m_metaMutex);
// Start undoable command
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
if(guideStart > -1) {
// Move guides back to original position
pCore->currentDoc()->getGuideModel()->moveMarkersWithoutUndo(selectedGuides, startPosition - endPosition, false);
moveGuidesInRange(guideStart, -1, endPosition - startPosition, undo, redo);
}
bool result = TimelineFunctions::requestSpacerEndOperation(m_model, clipId, startPosition, endPosition, affectedTrack, false, undo, redo);
......
......@@ -399,9 +399,18 @@ public:
/** @brief Returns the minimum available position for a spacer operation
*/
Q_INVOKABLE int spacerMinPos() const;
/** @brief Get a list of guides Id after a given frame
*/
Q_INVOKABLE QVector<int> spacerSelection(int startFrame);
/** @brief Move a list of guides from a given offset
*/
Q_INVOKABLE void spacerMoveGuides(QVector<int> ids, int offset);
/** @brief Get the position of the first marker in the list
*/
Q_INVOKABLE int getGuidePosition(int ids);
/** @brief Request a spacer operation
*/
Q_INVOKABLE bool requestSpacerEndOperation(int clipId, int startPosition, int endPosition, int affectedTrack, int guideStart = -1);
Q_INVOKABLE bool requestSpacerEndOperation(int clipId, int startPosition, int endPosition, int affectedTrack, QVector<int> selectedGuides = QVector<int>(), int guideStart = -1);
/** @brief Request a Fade in effect for clip
*/
Q_INVOKABLE void adjustFade(int cid, const QString &effectId, int duration, int initialDuration);
......
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