Commit 2544c1e3 authored by Nicolas Carion's avatar Nicolas Carion

move copy functions to TimelineFunctions and simplify logic

parent 09139350
......@@ -21,10 +21,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "timelinefunctions.hpp"
#include "clipmodel.hpp"
#include "groupsmodel.hpp"
#include "core.h"
#include "timelineitemmodel.hpp"
#include "effects/effectstack/model/effectstackmodel.hpp"
#include "groupsmodel.hpp"
#include "timelineitemmodel.hpp"
#include "trackmodel.hpp"
#include <QDebug>
#include <klocalizedstring.h>
......@@ -88,9 +89,7 @@ bool TimelineFunctions::requestClipCut(std::shared_ptr<TimelineItemModel> timeli
if (count > 0 && timeline->m_groups->isInGroup(clipId)) {
// we now split the group hiearchy.
// As a splitting criterion, we compare start point with split position
auto criterion = [timeline, position](int cid) {
return timeline->getClipPosition(cid) < position;
};
auto criterion = [timeline, position](int cid) { return timeline->getClipPosition(cid) < position; };
int root = timeline->m_groups->getRootId(clipId);
bool res = timeline->m_groups->split(root, criterion, undo, redo);
if (!res) {
......@@ -250,3 +249,35 @@ bool TimelineFunctions::insertSpace(std::shared_ptr<TimelineItemModel> timeline,
}
return result;
}
bool TimelineFunctions::requestClipCopy(std::shared_ptr<TimelineItemModel> timeline, int clipId, int trackId, int position)
{
Q_ASSERT(timeline->isClip(clipId) || timeline->isComposition(clipId));
Fun undo = []() { return true; };
Fun redo = []() { return true; };
int deltaTrack = timeline->getTrackPosition(trackId) - timeline->getTrackPosition(timeline->getClipTrackId(clipId));
int deltaPos = position - timeline->getClipPosition(clipId);
std::unordered_set<int> allIds = timeline->getGroupElements(clipId);
for (int id : allIds) {
int newId = -1;
bool res = copyClip(timeline, id, newId, undo, redo);
res = res && (res != -1);
int target_position = timeline->getClipPosition(id) + deltaPos;
int target_track_position = timeline->getTrackPosition(timeline->getClipTrackId(id)) + deltaTrack;
if (target_track_position >= 0 && target_track_position < timeline->getTracksCount()) {
auto it = timeline->m_allTracks.cbegin();
std::advance(it, target_track_position);
int target_track = (*it)->getId();
res = res && timeline->requestClipMove(newId, target_track, target_position, true, false, undo, redo);
} else {
res = false;
}
if (!res) {
bool undone = undo();
Q_ASSERT(undone);
return false;
}
}
return true;
}
......@@ -55,6 +55,8 @@ struct TimelineFunctions {
static bool removeSpace(std::shared_ptr<TimelineItemModel> timeline, int trackId, QPoint zone, Fun &undo, Fun &redo);
static bool insertSpace(std::shared_ptr<TimelineItemModel> timeline, int trackId, QPoint zone, Fun &undo, Fun &redo);
static bool insertZone(std::shared_ptr<TimelineItemModel> timeline, int trackId, const QString &binId, int insertFrame, QPoint zone, bool overwrite);
static bool requestClipCopy(std::shared_ptr<TimelineItemModel> timeline, int clipId, int trackId, int position);
};
#endif
This diff is collapsed.
......@@ -302,9 +302,6 @@ public:
bool requestClipInsertion(const QString &binClipId, int trackId, int position, int &id, bool logUndo = true, bool refreshView = false);
/* Same function, but accumulates undo and redo*/
bool requestClipInsertion(const QString &binClipId, int trackId, int position, int &id, bool logUndo, bool refreshView, Fun &undo, Fun &redo);
bool requestClipCopy(int clipId, int trackId, int position, int &id);
bool processClipCopy(int clipId, int trackId, int position, int &id, Fun &undo, Fun &redo);
bool requestGroupCopy(int clipId, int groupId, int delta_track, int delta_pos, Fun &undo, Fun &redo);
/* @brief Creates a new clip instance without inserting it.
This action is undoable, returns true on success
@param binClipId: Bin id of the clip to insert
......
......@@ -47,11 +47,12 @@ public:
TrackModel() = delete;
~TrackModel();
friend class TimelineModel;
friend class TimelineItemModel;
friend class ClipModel;
friend class CompositionModel;
friend class TimelineController;
friend class TimelineFunctions;
friend class TimelineItemModel;
friend class TimelineModel;
private:
/* This constructor is private, call the static construct instead */
......
......@@ -311,9 +311,8 @@ void TimelineController::copyItem()
m_root->setProperty("copiedClip", clipId);
}
int TimelineController::pasteItem(int clipId, int tid, int position)
bool TimelineController::pasteItem(int clipId, int tid, int position)
{
int id;
//TODO: copy multiple clips / groups
if (clipId == -1) {
clipId = m_root->property("copiedClip").toInt();
......@@ -335,12 +334,10 @@ int TimelineController::pasteItem(int clipId, int tid, int position)
}
qDebug()<< "PASTING CLIP: "<<clipId<<", "<<tid<<", "<<position;
if (m_model->isClip(clipId)) {
if (!m_model->requestClipCopy(clipId, tid, position, id)) {
id = -1;
}
return TimelineFunctions::requestClipCopy(m_model, clipId, tid, position);
}
//TODO copy composition
return id;
return false;
}
void TimelineController::triggerAction(const QString &name)
......
......@@ -110,7 +110,7 @@ public:
*/
Q_INVOKABLE int insertClip(int tid, int position, const QString &xml, bool logUndo, bool refreshView);
Q_INVOKABLE void copyItem();
Q_INVOKABLE int pasteItem(int clipId = -1, int tid = -1, int position = -1);
Q_INVOKABLE bool pasteItem(int clipId = -1, int tid = -1, int position = -1);
/* @brief Request inserting a new composition in timeline (dragged from compositions list)
@param tid is the destination track
@param position is the timeline position
......
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