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 721df26b authored by Nicolas Carion's avatar Nicolas Carion

[Timeline2] Fix undo/redo for clip dropping

parent d1d6d65f
......@@ -258,7 +258,7 @@ int TimelineModel::suggestClipMove(int cid, int tid, int position)
return position;
}
bool TimelineModel::requestClipInsertion(std::shared_ptr<Mlt::Producer> prod, int trackId, int position, int &id)
bool TimelineModel::requestClipInsertion(std::shared_ptr<Mlt::Producer> prod, int trackId, int position, int &id, bool logUndo)
{
#ifdef LOGGING
m_logFile << "{" <<std::endl<< "std::shared_ptr<Mlt::Producer> producer = std::make_shared<Mlt::Producer>(profile, \"color\", \"red\");" << std::endl;
......@@ -271,7 +271,7 @@ bool TimelineModel::requestClipInsertion(std::shared_ptr<Mlt::Producer> prod, in
Fun undo = [](){return true;};
Fun redo = [](){return true;};
bool result = requestClipInsertion(prod, trackId, position, id, undo, redo);
if (result) {
if (result && logUndo) {
PUSH_UNDO(undo, redo, i18n("Insert Clip"));
}
return result;
......@@ -299,7 +299,7 @@ bool TimelineModel::requestClipInsertion(std::shared_ptr<Mlt::Producer> prod, in
return true;
}
bool TimelineModel::requestClipDeletion(int cid)
bool TimelineModel::requestClipDeletion(int cid, bool logUndo)
{
#ifdef LOGGING
m_logFile << "timeline->requestClipDeletion("<<cid<<"); " <<std::endl;
......@@ -312,7 +312,7 @@ bool TimelineModel::requestClipDeletion(int cid)
Fun undo = [](){return true;};
Fun redo = [](){return true;};
bool res = requestClipDeletion(cid, undo, redo);
if (res) {
if (res && logUndo) {
PUSH_UNDO(undo, redo, i18n("Delete Clip"));
}
return res;
......
......@@ -42,6 +42,7 @@ class ClipModel;
class GroupsModel;
class DocUndoStack;
class SnapModel;
class TimelineItemModel;
/* @brief This class represents a Timeline object, as viewed by the backend.
In general, the Gui associated with it will send modification queries (such as resize or move), and this class authorize them or not depending on the validity of the modifications.
......@@ -96,12 +97,12 @@ public:
/* @brief Returns the id of the track containing clip (-1 if it is not inserted)
@param cid Id of the clip to test
*/
int getClipTrackId(int cid) const;
Q_INVOKABLE int getClipTrackId(int cid) const;
/* @brief Returns the position of clip (-1 if it is not inserted)
@param cid Id of the clip to test
*/
int getClipPosition(int cid) const;
Q_INVOKABLE int getClipPosition(int cid) const;
/* @brief Returns the duration of a clip
@param cid Id of the clip to test
......@@ -150,8 +151,9 @@ public:
@param track Id of the track where to insert
@param Requested position
@param ID return parameter of the id of the inserted clip
@param logUndo if set to false, no undo object is stored
*/
bool requestClipInsertion(std::shared_ptr<Mlt::Producer> prod, int trackId, int position, int &id);
bool requestClipInsertion(std::shared_ptr<Mlt::Producer> prod, int trackId, int position, int &id, bool logUndo = true);
/* Same function, but accumulates undo and redo*/
bool requestClipInsertion(std::shared_ptr<Mlt::Producer> prod, int trackId, int position, int &id, Fun& undo, Fun& redo);
......@@ -160,8 +162,9 @@ public:
Returns true on success. If it fails, nothing is modified.
If the clip is in a group, the call is deferred to requestGroupDeletion
@param cid is the ID of the clip
@param logUndo if set to false, no undo object is stored
*/
bool requestClipDeletion(int cid);
Q_INVOKABLE bool requestClipDeletion(int cid, bool logUndo = true);
/* Same function, but accumulates undo and redo, and doesn't check for group*/
bool requestClipDeletion(int cid, Fun &undo, Fun &redo);
......
......@@ -60,6 +60,9 @@ Rectangle {
property int duration: timeline.duration
property color shotcutBlue: Qt.rgba(23/255, 92/255, 118/255, 1.0)
property int clipBeingDroppedId: -1
property int clipBeingDroppedData
property int droppedPosition: -1
property int droppedTrack: -1
property int clipBeingMovedId: -1
//property alias ripple: toolbar.ripple
......@@ -75,9 +78,11 @@ Rectangle {
if (clipBeingMovedId == -1) {
var track = Logic.getTrackIdFromPos(drag.y)
var frame = Math.round((drag.x + scrollView.flickableItem.contentX) / timeline.scaleFactor)
droppedPosition = frame
if (track >= 0) {
//drag.acceptProposedAction()
clipBeingDroppedId = timeline.insertClip(track, frame, drag.getDataAsString('kdenlive/producerslist'))
clipBeingDroppedData = drag.getDataAsString('kdenlive/producerslist')
clipBeingDroppedId = timeline.insertClip(track, frame, drag.getDataAsString('kdenlive/producerslist'), false)
continuousScrolling(drag.x + scrollView.flickableItem.contentX)
} else {
drag.accepted = false
......@@ -87,9 +92,11 @@ Rectangle {
onExited:{
Logic.dropped()
if (clipBeingDroppedId != -1) {
timeline.deleteClip(clipBeingDroppedId)
controller.requestClipDeletion(clipBeingDroppedId, false)
}
clipBeingDroppedId = -1
droppedPosition = -1
droppedTrack = -1
scrollTimer.running = false
}
onPositionChanged: {
......@@ -107,7 +114,17 @@ Rectangle {
}
}
onDropped: {
if (clipBeingDroppedId != -1) {
var frame = controller.getClipPosition(clipBeingDroppedId)
var track = controller.getClipTrackId(clipBeingDroppedId)
// we simulate insertion at the final position so that stored undo has correct value
controller.requestClipDeletion(clipBeingDroppedId, false)
timeline.insertClip(track, frame, clipBeingDroppedData, true)
}
Logic.dropped()
clipBeingDroppedId = -1
droppedPosition = -1
droppedTrack = -1
scrollTimer.running = false
}
}
......
......@@ -190,11 +190,11 @@ bool TimelineWidget::scrub()
}
int TimelineWidget::insertClip(int tid, int position, QString data_str)
int TimelineWidget::insertClip(int tid, int position, QString data_str, bool logUndo)
{
std::shared_ptr<Mlt::Producer> prod = std::make_shared<Mlt::Producer>(m_binController->getBinProducer(data_str));
int id;
if (!m_model->requestClipInsertion(prod, tid, position, id)) {
if (!m_model->requestClipInsertion(prod, tid, position, id, logUndo)) {
id = -1;
}
return id;
......@@ -211,11 +211,6 @@ void TimelineWidget::deleteSelectedClips()
}
}
void TimelineWidget::deleteClip(int cid)
{
m_model->requestClipDeletion(cid);
}
void TimelineWidget::triggerAction(const QString &name)
{
QAction *action = m_actionCollection->action(name);
......@@ -342,3 +337,4 @@ void TimelineWidget::unGroupSelection(int cid)
{
m_model->requestClipUngroup(cid);
}
......@@ -91,18 +91,14 @@ public:
@param tid is the destination track
@param position is the timeline position
@param xml is the data describing the dropped clip
@param logUndo if set to false, no undo object is stored
@return the id of the inserted clip
*/
Q_INVOKABLE int insertClip(int tid, int position, QString xml);
Q_INVOKABLE int insertClip(int tid, int position, QString xml, bool logUndo);
/* @brief Request deletion of the currently selected clips
*/
Q_INVOKABLE void deleteSelectedClips();
/* @brief Request deletion of the given clip
@param cid id of the clip to delete
*/
Q_INVOKABLE void deleteClip(int cid);
Q_INVOKABLE int requestBestSnapPos(int pos, int duration);
Q_INVOKABLE void triggerAction(const QString &name);
......
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