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

Fix corruption on group move. However currently grouped clips are not displayed in the move,

I need to find a way to do the move in qml only
parent 53183a2f
......@@ -359,6 +359,7 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int sn
if (currentPos == position) {
return position;
}
bool after = position > currentPos;
if (snapDistance > 0) {
// For snapping, we must ignore all in/outs of the clips of the group being moved
std::vector<int> ignored_pts;
......@@ -396,12 +397,75 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int sn
qDebug() << "Found blank" << blank_length;
if (blank_length < INT_MAX) {
if (after) {
return currentPos + blank_length;
position = currentPos + blank_length;
} else {
position = currentPos - blank_length;
}
} else {
return false;
}
possible = requestClipMove(clipId, trackId, position, false, false, false);
return possible ? position : currentPos;
}
// find best pos for groups
int groupId = m_groups->getRootId(clipId);
std::unordered_set<int> all_clips = m_groups->getLeaves(groupId);
QMap <int, int> trackPosition;
// First pass, sort clips by track and keep only the first / last depending on move direction
for (int current_clipId : all_clips) {
int clipTrack = getClipTrackId(current_clipId);
if (clipTrack == -1) {
continue;
}
if (trackPosition.contains(clipTrack)) {
int in = getItemPosition(current_clipId);
if (after) {
// keep only last clip position for track
int out = getItemPosition(current_clipId) + getItemPlaytime(current_clipId);
if (trackPosition.value(clipTrack) < out) {
trackPosition.insert(clipTrack, out);
}
} else {
// keep only first clip position for track
int in = getItemPosition(current_clipId);
if (trackPosition.value(clipTrack) > in) {
trackPosition.insert(clipTrack, in);
}
}
}
else {
int in = getItemPosition(current_clipId);
trackPosition.insert(clipTrack, after ? in + getItemPlaytime(current_clipId) : in);
}
}
// Now check space on each track
QMapIterator<int, int> i(trackPosition);
int blank_length = -1;
while (i.hasNext()) {
i.next();
int track_space;
if (!after) {
// Check space before the position
track_space = i.value() - getTrackById(i.key())->getBlankStart(i.value() - 1);
if (blank_length == -1 || blank_length > track_space) {
blank_length = track_space;
}
} else {
// Check after before the position
track_space = getTrackById(i.key())->getBlankEnd(i.value() + 1) - i.value();
if (blank_length == -1 || blank_length > track_space) {
blank_length = track_space;
}
return currentPos - blank_length;
}
}
//TODO: find best pos for groups
if (blank_length != 0) {
int updatedPos = currentPos + (after ? blank_length : -blank_length);
possible = requestClipMove(clipId, trackId, updatedPos, false, false, false);
if (possible) {
return updatedPos;
}
}
return currentPos;
}
......@@ -695,7 +759,7 @@ bool TimelineModel::requestGroupMove(int clipId, int groupId, int delta_track, i
std::advance(it, target_track_position);
int target_track = (*it)->getId();
int target_position = m_allClips[clip]->getPosition() + delta_pos;
ok = requestClipMove(clip, target_track, target_position, updateView || (clip != clipId), finalMove, undo, redo);
ok = requestClipMove(clip, target_track, target_position, updateView, finalMove, undo, redo);
} else {
ok = false;
}
......
......@@ -143,7 +143,6 @@ Fun TrackModel::requestClipInsertion_lambda(int clipId, int position, bool updat
ptr->checkRefresh(new_in, new_out);
}
if (!audioOnly && finalMove) {
qDebug() << "/// INVALIDATE CLIP ON INSERTT!!!!!!";
ptr->invalidateClip(clipId);
}
}
......@@ -240,8 +239,8 @@ Fun TrackModel::requestClipDeletion_lambda(int clipId, bool updateView, bool fin
int old_out = old_in + m_allClips[clipId]->getPlaytime();
return [clip_position, clipId, old_in, old_out, updateView, finalMove, audioOnly, this]() {
auto clip_loc = getClipIndexAt(clip_position);
int old_clip_index = getRowfromClip(clipId);
if (updateView) {
int old_clip_index = getRowfromClip(clipId);
auto ptr = m_parent.lock();
ptr->_beginRemoveRows(ptr->makeTrackIndexFromID(getId()), old_clip_index, old_clip_index);
ptr->_endRemoveRows();
......@@ -709,6 +708,27 @@ bool TrackModel::isBlankAt(int position)
return m_playlists[0].is_blank_at(position) && m_playlists[1].is_blank_at(position);
}
int TrackModel::getBlankStart(int position)
{
READ_LOCK();
int result = 0;
for (int j = 0; j < 2; j++) {
if (m_playlists[j].count() == 0) {
break;
}
if (!m_playlists[j].is_blank_at(position)) {
result = position;
break;
}
int clip_index = m_playlists[j].get_clip_index_at(position);
int start = m_playlists[j].clip_start(clip_index);
if (start > result) {
result = start;
}
}
return result;
}
int TrackModel::getBlankEnd(int position, int track)
{
READ_LOCK();
......@@ -725,6 +745,7 @@ int TrackModel::getBlankEnd(int position, int track)
}
return INT_MAX;
}
int TrackModel::getBlankEnd(int position)
{
READ_LOCK();
......
......@@ -146,6 +146,7 @@ protected:
*/
int getBlankSizeNearClip(int clipId, bool after);
int getBlankSizeNearComposition(int compoId, bool after);
int getBlankStart(int position);
int getBlankSizeAtPos(int frame);
/*@brief Returns the (unique) construction id of the track*/
......
......@@ -356,7 +356,7 @@ Rectangle {
Text {
id: label
text: clipName
font.pixelSize: root.baseUnit
font.pixelSize: root.baseUnit * 1.2
anchors {
top: labelRect.top
left: labelRect.left
......
......@@ -39,9 +39,6 @@ Menu {
text: i18n('Copy')
onTriggered: root.copiedClip = clipId
}
MenuSeparator {
visible: !isComposition
}
MenuItem {
text: i18n('Remove')
onTriggered: timeline.triggerAction('delete_timeline_clip')
......
......@@ -241,7 +241,7 @@ Column{
var toTrack = clip.trackId
var cIndex = clip.clipId
var frame = clip.currentFrame
var origFrame = clip.modelStart //Math.round(clip.originalX / timeScale + 0.5)
var origFrame = clip.modelStart
if (frame > -1) {
controller.requestClipMove(cIndex, clip.originalTrackId, origFrame, false, false, false)
controller.requestClipMove(cIndex, toTrack, frame, true, true, true)
......@@ -263,17 +263,21 @@ Column{
var toTrack = clip.trackId
var cIndex = clip.clipId
clip.x = Math.max(0, clip.x)
var frame = Math.round(clip.x / timeScale)
frame = controller.suggestClipMove(cIndex, toTrack, frame, root.snapping);
if (clip.currentFrame == frame) {
// Abort move
clip.x = clip.draggedX
if (Math.round(clip.currentFrame * timeScale) == clip.x) {
// No move to perform
} else {
clip.x = frame * timeScale
clip.currentFrame = frame
var mapped = trackRoot.mapFromItem(clip, mouse.x, mouse.y)
trackRoot.clipDragged(clip, mapped.x, mapped.y)
clip.draggedX = clip.x
var frame = Math.round(clip.x / timeScale)
frame = controller.suggestClipMove(cIndex, toTrack, frame, root.snapping);
if (clip.currentFrame == frame) {
// Abort move
clip.x = clip.draggedX
} else {
clip.x = frame * timeScale
clip.currentFrame = frame
var mapped = trackRoot.mapFromItem(clip, mouse.x, mouse.y)
trackRoot.clipDragged(clip, mapped.x, mapped.y)
clip.draggedX = clip.x
}
}
}
onTrimmingIn: {
......
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