Preliminary copy/paste in timeline through context menu

parent 10b07330
......@@ -221,6 +221,13 @@ bool ClipModel::copyEffect(std::shared_ptr<EffectStackModel> stackModel, int row
return true;
}
bool ClipModel::importEffects(std::shared_ptr<EffectStackModel> stackModel)
{
READ_LOCK();
m_effectStack->importEffects(stackModel);
return true;
}
bool ClipModel::removeFade(bool fromStart)
{
READ_LOCK();
......
......@@ -89,6 +89,7 @@ public:
bool addEffect(const QString &effectId);
bool copyEffect(std::shared_ptr<EffectStackModel> stackModel, int rowId);
bool importEffects(std::shared_ptr<EffectStackModel> stackModel);
bool removeFade(bool fromStart);
bool adjustEffectLength(const QString &effectName, int duration);
......
......@@ -459,6 +459,25 @@ bool TimelineModel::requestClipInsertion(const QString &binClipId, int trackId,
return result;
}
bool TimelineModel::requestClipCopy(int clipId, int trackId, int position, int &id)
{
int in = getClipIn(clipId);
int out = in + getClipPlaytime(clipId);
QString clipData = QString("%1#%2#%3").arg(getClipBinId(clipId)).arg(in).arg(out);
QWriteLocker locker(&m_lock);
Fun undo = []() { return true; };
Fun redo = []() { return true; };
bool result = requestClipInsertion(clipData, trackId, position, id, true, true, undo, redo);
if (result) {
std::shared_ptr<EffectStackModel> sourceStack = getClipEffectStack(clipId);
result = m_allClips.at(id)->importEffects(sourceStack);
PUSH_UNDO(undo, redo, i18n("Copy Clip"));
}
return result;
}
bool TimelineModel::requestClipCreation(const QString &binClipId, int &id, Fun &undo, Fun &redo)
{
int clipId = TimelineModel::getNextId();
......@@ -1099,7 +1118,7 @@ bool TimelineModel::copyClipEffect(int clipId, const QString &sourceId)
int itemId = source.at(1).toInt();
int itemRow = source.at(2).toInt();
std::shared_ptr<EffectStackModel> effectStack = pCore->getItemEffectStack(itemType, itemId);
return m_allClips.at(clipId)->copyEffect(effectStack, itemRow);;
return m_allClips.at(clipId)->copyEffect(effectStack, itemRow);
}
bool TimelineModel::adjustEffectLength(int clipId, const QString &effectId, int duration)
......
......@@ -302,6 +302,7 @@ 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);
/* @brief Creates a new clip instance without inserting it.
This action is undoable, returns true on success
......
......@@ -688,7 +688,7 @@ Rectangle {
MenuItem {
visible: true
text: i18n('Copy')
onTriggered: timeline.copyClip(trackIndex, index)
onTriggered: root.copiedClip = clipId
}
MenuSeparator {
visible: true
......
......@@ -113,6 +113,7 @@ Rectangle {
property real timeScale: timeline.scaleFactor
property real snapping: timeline.snap ? 10 / Math.sqrt(timeScale) : -1
property int trackHeight
property int copiedClip: -1
//onCurrentTrackChanged: timeline.selection = []
onTimeScaleChanged: {
......@@ -251,6 +252,15 @@ Rectangle {
id: menu
property int clickedX
property int clickedY
MenuItem {
text: i18n('Paste')
visible: copiedClip != -1
onTriggered: {
var track = Logic.getTrackIdFromPos(menu.clickedY - ruler.height)
var frame = Math.round((menu.clickedX + scrollView.flickableItem.contentX) / timeline.scaleFactor)
timeline.copyClip(copiedClip, track, frame)
}
}
MenuItem {
text: i18n('Insert Space')
onTriggered: {
......@@ -290,11 +300,6 @@ Rectangle {
timeline.editGuide(timeline.position);
}
}
MenuItem {
text: i18n('Add Audio Track')
shortcut: 'Ctrl+U'
onTriggered: timeline.addAudioTrack();
}
AssetMenu {
title: i18n('Insert a composition...')
menuModel: transitionModel
......
......@@ -300,6 +300,25 @@ void TimelineController::deleteSelectedClips()
}
}
int TimelineController::copyClip(int clipId, int tid, int position)
{
int id;
if (tid == -1) {
QVariant returnedValue;
QMetaObject::invokeMethod(m_root, "currentTrackId", Q_RETURN_ARG(QVariant, returnedValue));
tid = returnedValue.toInt();
}
if (position == -1) {
position = m_position;
}
if (m_model->isClip(clipId)) {
if (!m_model->requestClipCopy(clipId, tid, position, id)) {
id = -1;
}
}
return id;
}
void TimelineController::triggerAction(const QString &name)
{
QAction *action = m_actionCollection->action(name);
......
......@@ -109,6 +109,7 @@ public:
@return the id of the inserted clip
*/
Q_INVOKABLE int insertClip(int tid, int position, const QString &xml, bool logUndo, bool refreshView);
Q_INVOKABLE int copyClip(int clipId, int tid, int position);
/* @brief Request inserting a new composition in timeline (dragged from compositions list)
@param tid is the destination track
......
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