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

Commit 593e207c authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle

Fix insert/overwrite modes, as well as drag and drop insert/overwrite. Fixes #119

parent 5080a445
Pipeline #2326 passed with stage
in 21 minutes and 8 seconds
......@@ -295,7 +295,7 @@ bool TimelineFunctions::insertZone(const std::shared_ptr<TimelineItemModel> &tim
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
bool result = true;
int trackId = trackIds.takeFirst();
int trackId = trackIds.first();
if (overwrite) {
// Cut all tracks
auto it = timeline->m_allTracks.cbegin();
......@@ -307,6 +307,7 @@ bool TimelineFunctions::insertZone(const std::shared_ptr<TimelineItemModel> &tim
}
result = result && TimelineFunctions::liftZone(timeline, target_track, QPoint(insertFrame, insertFrame + (zone.y() - zone.x())), undo, redo);
if (!result) {
qDebug()<<"// LIFTING ZONE FAILED\n";
break;
}
++it;
......@@ -338,6 +339,7 @@ bool TimelineFunctions::insertZone(const std::shared_ptr<TimelineItemModel> &tim
}
}
if (!result) {
qDebug()<<"// REQUESTING SPACE FAILED";
undo();
}
return result;
......
......@@ -207,7 +207,6 @@ Fun TrackModel::requestClipInsertion_lambda(int clipId, int position, bool updat
};
}
}
return []() { return false; };
}
......
......@@ -325,6 +325,8 @@ Rectangle {
return id
}
property int fakeFrame: -1
property int fakeTrack: -1
width: root.width - headerWidth
height: root.height - ruler.height
y: ruler.height
......@@ -341,7 +343,14 @@ Rectangle {
//drag.acceptProposedAction()
clipBeingDroppedData = drag.getDataAsString('kdenlive/producerslist')
console.log('dropped data: ', clipBeingDroppedData)
clipBeingDroppedId = insertAndMaybeGroup(timeline.activeTrack, frame, clipBeingDroppedData)
if (controller.normalEdit()) {
clipBeingDroppedId = insertAndMaybeGroup(timeline.activeTrack, frame, clipBeingDroppedData)
} else {
// we want insert/overwrite mode, make a fake insert at end of timeline, then move to position
clipBeingDroppedId = insertAndMaybeGroup(timeline.activeTrack, timeline.fullDuration, clipBeingDroppedData)
fakeFrame = controller.suggestClipMove(clipBeingDroppedId, timeline.activeTrack, frame, timeline.position, Math.floor(root.snapping))
fakeTrack = timeline.activeTrack
}
continuousScrolling(drag.x + scrollView.flickableItem.contentX)
} else {
drag.accepted = false
......@@ -360,12 +369,21 @@ Rectangle {
if (track >= 0 && track < tracksRepeater.count) {
timeline.activeTrack = tracksRepeater.itemAt(track).trackInternalId
var frame = Math.round((drag.x + scrollView.flickableItem.contentX) / timeline.scaleFactor)
frame = controller.suggestSnapPoint(frame, Math.floor(root.snapping))
if (clipBeingDroppedId >= 0){
controller.requestClipMove(clipBeingDroppedId, timeline.activeTrack, frame, true, false, false)
fakeFrame = controller.suggestClipMove(clipBeingDroppedId, timeline.activeTrack, frame, timeline.position, Math.floor(root.snapping))
fakeTrack = timeline.activeTrack
//controller.requestClipMove(clipBeingDroppedId, timeline.activeTrack, frame, true, false, false)
continuousScrolling(drag.x + scrollView.flickableItem.contentX)
} else {
clipBeingDroppedId = insertAndMaybeGroup(timeline.activeTrack, frame, drag.getDataAsString('kdenlive/producerslist'), false, true)
frame = controller.suggestSnapPoint(frame, Math.floor(root.snapping))
if (controller.normalEdit()) {
clipBeingDroppedId = insertAndMaybeGroup(timeline.activeTrack, frame, drag.getDataAsString('kdenlive/producerslist'), false, true)
} else {
// we want insert/overwrite mode, make a fake insert at end of timeline, then move to position
clipBeingDroppedId = insertAndMaybeGroup(timeline.activeTrack, timeline.fullDuration, clipBeingDroppedData)
fakeFrame = controller.suggestClipMove(clipBeingDroppedId, timeline.activeTrack, frame, timeline.position, Math.floor(root.snapping))
fakeTrack = timeline.activeTrack
}
continuousScrolling(drag.x + scrollView.flickableItem.contentX)
}
}
......@@ -375,6 +393,10 @@ Rectangle {
if (clipBeingDroppedId != -1) {
var frame = controller.getClipPosition(clipBeingDroppedId)
var track = controller.getClipTrackId(clipBeingDroppedId)
if (!controller.normalEdit()) {
frame = fakeFrame
track = fakeTrack
}
/* We simulate insertion at the final position so that stored undo has correct value
* NOTE: even if dropping multiple clips, requesting the deletion of the first one is
* enough as internally it will request the group deletion
......@@ -383,10 +405,21 @@ Rectangle {
var binIds = clipBeingDroppedData.split(";")
if (binIds.length == 1) {
timeline.insertClip(track, frame, clipBeingDroppedData, true, true, false)
if (controller.normalEdit()) {
timeline.insertClip(track, frame, clipBeingDroppedData, true, true, false)
} else {
timeline.insertClipZone(clipBeingDroppedData, track, frame)
}
} else {
timeline.insertClips(track, frame, binIds, true, true)
if (controller.normalEdit()) {
timeline.insertClips(track, frame, binIds, true, true)
} else {
// TODO
console.log('multiple clips insert/overwrite not supported yet')
}
}
fakeTrack = -1
fakeFrame = -1
}
clearDropData()
}
......@@ -1129,7 +1162,7 @@ Rectangle {
controller.requestClipMove(dragProxy.draggedItem, tId, dragFrame , true, true, true)
} else {
// Fake move, only process final move
timeline.endFakeMove(dragProxy.draggedItem, dragFrame , true, true, true)
timeline.endFakeMove(dragProxy.draggedItem, dragFrame, true, true, true)
}
}
dragProxy.x = controller.getItemPosition(dragProxy.draggedItem) * timeline.scaleFactor
......
......@@ -1466,6 +1466,55 @@ void TimelineController::extract(int clipId)
TimelineFunctions::extractZone(m_model, QVector<int>() << track, zone, false);
}
bool TimelineController::insertClipZone(const QString &binId, int tid, int position)
{
QStringList binIdData = binId.split(QLatin1Char('/'));
int in = 0;
int out = -1;
if (binIdData.size() >= 3) {
in = binIdData.at(1).toInt();
out = binIdData.at(2).toInt();
}
QString bid = binIdData.first();
// dropType indicates if we want a normal drop (disabled), audio only or video only drop
PlaylistState::ClipState dropType = PlaylistState::Disabled;
if (bid.startsWith(QLatin1Char('A'))) {
dropType = PlaylistState::AudioOnly;
bid = bid.remove(0, 1);
} else if (bid.startsWith(QLatin1Char('V'))) {
dropType = PlaylistState::VideoOnly;
bid = bid.remove(0, 1);
}
int aTrack = -1;
int vTrack = -1;
std::shared_ptr<ProjectClip> clip = pCore->bin()->getBinClip(bid);
if (out <= in) {
out = clip->frameDuration() - 1;
}
if (dropType == PlaylistState::VideoOnly) {
vTrack = tid;
} else if (dropType == PlaylistState::AudioOnly) {
aTrack = tid;
} else {
if (m_model->getTrackById_const(tid)->isAudioTrack()) {
aTrack = tid;
vTrack = clip->hasAudioAndVideo() ? m_model->getMirrorVideoTrackId(aTrack) : -1;
} else {
vTrack = tid;
aTrack = clip->hasAudioAndVideo() ? m_model->getMirrorAudioTrackId(vTrack) : -1;
}
}
QList<int> target_tracks;
if (vTrack > -1) {
target_tracks << vTrack;
}
if (aTrack > -1) {
target_tracks << aTrack;
}
return TimelineFunctions::insertZone(m_model, target_tracks, binId, position, QPoint(in, out), m_model->m_editMode == TimelineMode::OverwriteEdit);
}
int TimelineController::insertZone(const QString &binId, QPoint zone, bool overwrite)
{
std::shared_ptr<ProjectClip> clip = pCore->bin()->getBinClip(binId);
......
......@@ -421,6 +421,7 @@ public:
/** @brief Insert clip monitor into timeline
* @returns the zone end position or -1 on fail
*/
Q_INVOKABLE bool insertClipZone(const QString &binId, int tid, int pos);
int insertZone(const QString &binId, QPoint zone, bool overwrite);
void updateClip(int clipId, const QVector<int> &roles);
void showClipKeyframes(int clipId, bool value);
......
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