Fix clip move

parent 8cf0cd3c
......@@ -66,8 +66,10 @@ std::shared_ptr<TimelineModel> TimelineModel::construct(std::weak_ptr<DocUndoSta
int ix2 = TrackModel::construct(ptr);
int clipId = ClipModel::construct(ptr, prod);
int clipId2 = ClipModel::construct(ptr, prod);
int clipId3 = ClipModel::construct(ptr, prod);
ptr->requestClipMove(clipId, ix, 100, false);
ptr->requestClipMove(clipId2, ix, 50, false);
ptr->requestClipMove(clipId3, ix, 250, false);
ptr->getTrackById(ix)->setProperty("kdenlive:trackheight", "60");
ptr->getTrackById(ix2)->setProperty("kdenlive:trackheight", "140");
}
......@@ -195,14 +197,14 @@ QVariant TimelineModel::data(const QModelIndex &index, int role) const
if (!m_tractor || !index.isValid()) {
return QVariant();
}
qDebug() << "DATA requested "<<index<<roleNames()[role];
const int id = (int)index.internalId();
//qDebug() << "DATA requested "<<index<<roleNames()[role];
if (isClip(id)) {
// Get data for a clip
switch (role) {
//TODO
case ClipIndex:
return m_allClips.at(id)->getId();
return id;
break;
case NameRole:
case ResourceRole:
......@@ -318,15 +320,15 @@ bool TimelineModel::requestClipMove(int cid, int tid, int position, Fun &undo, F
bool ok = true;
int old_tid = m_allClips[cid]->getCurrentTrackId();
if (old_tid != -1) {
// int old_clip_index = getTrackById(old_tid)->getRowfromClip(cid);
int old_clip_index = getTrackById(old_tid)->getRowfromClip(cid);
beginRemoveRows(makeTrackIndexFromID(old_tid), old_clip_index, old_clip_index);
ok = getTrackById(old_tid)->requestClipDeletion(cid, local_undo, local_redo);
if (!ok) {
bool undone = local_undo();
Q_ASSERT(undone);
return false;
}
// beginRemoveRows(makeTrackIndexFromID(old_tid), old_clip_index, old_clip_index);
// endRemoveRows();
endRemoveRows();
}
ok = getTrackById(tid)->requestClipInsertion(m_allClips[cid], position, local_undo, local_redo);
if (!ok) {
......@@ -334,12 +336,13 @@ bool TimelineModel::requestClipMove(int cid, int tid, int position, Fun &undo, F
Q_ASSERT(undone);
return false;
}
// int new_clip_index = getTrackById(tid)->getRowfromClip(cid);
// beginInsertRows(makeTrackIndexFromID(tid), new_clip_index, new_clip_index);
// endInsertRows();
int new_clip_index = getTrackById(tid)->getRowfromClip(cid);
beginInsertRows(makeTrackIndexFromID(tid), new_clip_index, new_clip_index);
endInsertRows();
auto operation = [cid, tid, this]() {
m_allClips[cid]->setCurrentTrackId(tid);
emit dataChanged(makeClipIndexFromID(cid),makeClipIndexFromID(cid), {StartRole});
QModelIndex modelIndex = makeClipIndexFromID(cid);
emit dataChanged(modelIndex, modelIndex, {StartRole});
return true;
};
auto reverse = [cid, old_tid, this]() {
......@@ -351,7 +354,8 @@ bool TimelineModel::requestClipMove(int cid, int tid, int position, Fun &undo, F
local_undo = [local_undo, old_tid, cid, this]() {
bool v = local_undo();
//qDebug()<<"DATA CHANGED SIGNAL";
emit dataChanged(makeClipIndexFromID(cid),makeClipIndexFromID(cid), {StartRole});
QModelIndex modelIndex = makeClipIndexFromID(cid);
emit dataChanged(modelIndex, modelIndex, {StartRole});
//qDebug()<<"Moved back"<<cid<<"to position"<<m_allClips[cid]->getPosition();
return v;
};
......
......@@ -154,6 +154,7 @@ public:
*/
bool requestClipMove(int cid, int tid, int position, bool logUndo = true);
bool allowClipMove(int cid, int tid, int position);
protected:
/* Same function, but accumulates undo and redo, and doesn't check for group*/
bool requestClipMove(int cid, int tid, int position, Fun &undo, Fun &redo);
......
......@@ -316,11 +316,14 @@ bool TrackModel::allowClipMove(int cid, int position, int length)
// Check position is blank or is in cid
int ix = m_playlist.get_clip_index_at(position);
int blankEnd = 0;
int clip_position = m_allClips[cid]->getPosition();
int target_clip = m_playlist.get_clip_index_at(clip_position);
while (blankEnd < position + length && ix < m_playlist.count()) {
if (m_playlist.is_blank(ix) || getRowfromClip(cid) == ix) {
if (m_playlist.is_blank(ix) || target_clip == ix) {
blankEnd = m_playlist.clip_start(++ix) - 1;
} else break;
}
// Return true if we are at playlist end or if there is enough space for the move
return (ix == m_playlist.count() - 1 || blankEnd >= position + length);
return (ix == m_playlist.count() || blankEnd >= position + length);
}
......@@ -41,7 +41,7 @@ Rectangle {
property int fadeOut: 0
property int trackIndex
property int originalTrackIndex: trackIndex
property int originalClipIndex: index
property int originalClipIndex
property int originalX: x
property int draggedX: x
property bool selected: false
......@@ -59,7 +59,7 @@ Rectangle {
signal trimmedOut(var clip)
onModelStartChanged: {
console.log("MODEL START CHANGED !!!!!!", modelStart, clip, x);
console.log("MODEL START CHANGED !!!!!!", modelStart, originalClipIndex, x);
x = modelStart * timeScale;
}
SystemPalette { id: activePalette }
......@@ -253,7 +253,6 @@ Rectangle {
root.stopScrolling = true
originalX = parent.x
originalTrackIndex = trackIndex
originalClipIndex = index
startX = parent.x
clipRoot.forceActiveFocus();
clipRoot.clicked(clipRoot)
......
......@@ -69,6 +69,7 @@ Column{
inPoint: model.in
outPoint: model.out
isBlank: model.blank
originalClipIndex: model.clipIndex
isAudio: false //model.audio
isTransition: false //model.isTransition
audioLevels: false //model.audioLevels
......@@ -91,7 +92,7 @@ Column{
onMoved: {
var fromTrack = clip.originalTrackIndex
var toTrack = clip.trackIndex
var clipIndex = model.clipIndex
var cIndex = clip.originalClipIndex
var frame = Math.round(clip.x / timeScale)
// Remove the placeholder inserted in onDraggedToTrack
......@@ -102,23 +103,23 @@ Column{
// call below to fail. This basically results in rejected operation
// to the user, but at least it prevents the timeline from becoming
// corrupt and out-of-sync with the model.
trackModel.items.resolve(clipIndex, clipIndex + 1)
trackModel.items.resolve(cIndex, cIndex + 1)
else
trackModel.items.remove(clipIndex, 1)
trackModel.items.remove(cIndex, 1)
}
if (!timeline.moveClip(fromTrack, toTrack, clipIndex, frame, false))
if (!timeline.moveClip(fromTrack, toTrack, cIndex, frame, false))
clip.x = clip.originalX
else {
//TODO This hacky, find a better way...
var oldFrame = Math.round(clip.originalX / timeScale)
timeline.moveClip(fromTrack, toTrack, clipIndex, oldFrame, false)
timeline.moveClip(fromTrack, toTrack, clipIndex, frame, true)
timeline.moveClip(fromTrack, toTrack, cIndex, oldFrame, false)
timeline.moveClip(fromTrack, toTrack, cIndex, frame, true)
}
}
onDragged: {
var fromTrack = clip.originalTrackIndex
var toTrack = clip.trackIndex
var clipIndex = model.clipIndex
var cIndex = clip.originalClipIndex
var frame = Math.round(clip.x / timeScale)
/*if (toolbar.scrub) {
root.stopScrolling = false
......@@ -128,9 +129,9 @@ Column{
if (!(mouse.modifiers & Qt.AltModifier) && timeline.snap)
trackRoot.checkSnap(clip)
// Prevent dragging left of multitracks origin.
console.log("dragging clip x: ", clip.x)
console.log("dragging clip x: ", clip.x, " ID: "<<clip.originalClipIndex)
clip.x = Math.max(0, clip.x)
if (!timeline.allowMoveClip(fromTrack, toTrack, clipIndex, frame, false)) {
if (!timeline.allowMoveClip(fromTrack, toTrack, cIndex, frame, false)) {
// Abort move
clip.x = clip.draggedX
}
......
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