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

Implement composition copy/paste

parent 5ecd4239
......@@ -125,6 +125,12 @@ Mlt::Transition *CompositionModel::service() const
return static_cast<Mlt::Transition *>(m_asset.get());
}
Mlt::Properties *CompositionModel::properties()
{
READ_LOCK();
return new Mlt::Properties(m_asset.get()->get_properties());
}
int CompositionModel::getPlaytime() const
{
READ_LOCK();
......
......@@ -82,6 +82,7 @@ public:
Q_INVOKABLE bool showKeyframes() const;
Q_INVOKABLE void setShowKeyframes(bool show);
const QString &displayName() const;
Mlt::Properties *properties();
protected:
Mlt::Transition *service() const override;
......
......@@ -272,27 +272,36 @@ bool TimelineFunctions::insertSpace(std::shared_ptr<TimelineItemModel> timeline,
return result;
}
bool TimelineFunctions::requestClipCopy(std::shared_ptr<TimelineItemModel> timeline, int clipId, int trackId, int position)
bool TimelineFunctions::requestItemCopy(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);
int deltaTrack = timeline->getTrackPosition(trackId) - timeline->getTrackPosition(timeline->getItemTrackId(clipId));
int deltaPos = position - timeline->getItemPosition(clipId);
std::unordered_set<int> allIds = timeline->getGroupElements(clipId);
std::unordered_map<int, int> mapping; // keys are ids of the source clips, values are ids of the copied clips
bool res = true;
for (int id : allIds) {
int newId = -1;
PlaylistState::ClipState state = timeline->m_allClips[id]->clipState();
bool res = copyClip(timeline, id, newId, state, undo, redo);
res = res && (newId != -1);
int target_position = timeline->getClipPosition(id) + deltaPos;
int target_track_position = timeline->getTrackPosition(timeline->getClipTrackId(id)) + deltaTrack;
if (timeline->isClip(id)) {
PlaylistState::ClipState state = timeline->m_allClips[id]->clipState();
res = copyClip(timeline, id, newId, state, undo, redo);
res = res && (newId != -1);
}
int target_position = timeline->getItemPosition(id) + deltaPos;
int target_track_position = timeline->getTrackPosition(timeline->getItemTrackId(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);
if (timeline->isClip(id)) {
res = res && timeline->requestClipMove(newId, target_track, target_position, true, false, undo, redo);
} else {
const QString &transitionId = timeline->m_allCompositions[id]->getAssetId();
QScopedPointer <Mlt::Properties> transProps(timeline->m_allCompositions[id]->properties());
res = res & timeline->requestCompositionInsertion(transitionId, target_track, -1, target_position, timeline->m_allCompositions[id]->getPlaytime(), transProps.data(), newId, undo, redo);
}
} else {
res = false;
}
......@@ -304,7 +313,7 @@ bool TimelineFunctions::requestClipCopy(std::shared_ptr<TimelineItemModel> timel
mapping[id] = newId;
}
qDebug() << "Sucessful copy, coping groups...";
bool res = timeline->m_groups->copyGroups(mapping, undo, redo);
res = timeline->m_groups->copyGroups(mapping, undo, redo);
if (!res) {
bool undone = undo();
Q_ASSERT(undone);
......
......@@ -58,7 +58,7 @@ struct TimelineFunctions
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);
static bool requestItemCopy(std::shared_ptr<TimelineItemModel> timeline, int clipId, int trackId, int position);
static void showClipKeyframes(std::shared_ptr<TimelineItemModel> timeline, int clipId, bool value);
static void showCompositionKeyframes(std::shared_ptr<TimelineItemModel> timeline, int compoId, bool value);
static bool changeClipState(std::shared_ptr<TimelineItemModel> timeline, int clipId, PlaylistState::ClipState status);
......
......@@ -424,11 +424,7 @@ bool TimelineController::pasteItem(int clipId, int tid, int position)
position = timelinePosition();
}
qDebug() << "PASTING CLIP: " << clipId << ", " << tid << ", " << position;
if (m_model->isClip(clipId)) {
return TimelineFunctions::requestClipCopy(m_model, clipId, tid, position);
} else {
// TODO copy composition
}
return TimelineFunctions::requestItemCopy(m_model, clipId, tid, position);
return false;
}
......
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