From 9c3f7d50a621877f073b98edbe96c0dfc79b13cd Mon Sep 17 00:00:00 2001 From: manongjohn Date: Tue, 25 Dec 2018 21:02:02 -0500 Subject: [PATCH] Fix incorrect keyframe cell pasting and redo (#2398) * Fix incorrect keyframe pasting * Fix keyframe redo --- toonz/sources/toonz/cellkeyframeselection.cpp | 4 +++- toonz/sources/toonz/cellselection.cpp | 6 ++++-- toonz/sources/toonz/keyframedata.cpp | 16 +++++++++++++++- toonz/sources/toonz/keyframedata.h | 7 +++++++ toonz/sources/toonz/keyframeselection.cpp | 11 ++++++++--- 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/toonz/sources/toonz/cellkeyframeselection.cpp b/toonz/sources/toonz/cellkeyframeselection.cpp index 5e2b44bd..a10a75ae 100644 --- a/toonz/sources/toonz/cellkeyframeselection.cpp +++ b/toonz/sources/toonz/cellkeyframeselection.cpp @@ -71,7 +71,9 @@ void TCellKeyframeSelection::copyCellsKeyframes() { QClipboard *clipboard = QApplication::clipboard(); TXsheet *xsh = m_xsheetHandle->getXsheet(); TKeyframeData *keyframeData = new TKeyframeData(); - keyframeData->setKeyframes(m_keyframeSelection->getSelection(), xsh); + TKeyframeData::Position startPos(r0, c0); + keyframeData->setKeyframes(m_keyframeSelection->getSelection(), xsh, + startPos); data->setKeyframeData(keyframeData); } // Set the cliboard diff --git a/toonz/sources/toonz/cellselection.cpp b/toonz/sources/toonz/cellselection.cpp index 15b93f71..4fc08e25 100644 --- a/toonz/sources/toonz/cellselection.cpp +++ b/toonz/sources/toonz/cellselection.cpp @@ -1629,9 +1629,11 @@ void TCellSelection::pasteCells() { // (r0,c0) std::set positions; int newC0 = c0; - if (viewer && !viewer->orientation()->isVerticalTimeline()) + if (viewer && !viewer->orientation()->isVerticalTimeline() && !cellData) newC0 = c0 - keyframeData->getColumnSpanCount() + 1; - positions.insert(TKeyframeSelection::Position(r0, newC0)); + TKeyframeSelection::Position offset(keyframeData->getKeyframesOffset()); + positions.insert(TKeyframeSelection::Position(r0 + offset.first, + newC0 + offset.second)); keyframeData->getKeyframes(positions); selection.select(positions); diff --git a/toonz/sources/toonz/keyframedata.cpp b/toonz/sources/toonz/keyframedata.cpp index 73f6bae9..b09f02c3 100644 --- a/toonz/sources/toonz/keyframedata.cpp +++ b/toonz/sources/toonz/keyframedata.cpp @@ -23,7 +23,8 @@ TKeyframeData::TKeyframeData() {} TKeyframeData::TKeyframeData(const TKeyframeData *src) : m_keyData(src->m_keyData) - , m_isPegbarsCycleEnabled(src->m_isPegbarsCycleEnabled) {} + , m_isPegbarsCycleEnabled(src->m_isPegbarsCycleEnabled) + , m_offset(src->m_offset) {} //----------------------------------------------------------------------------- @@ -32,6 +33,12 @@ TKeyframeData::~TKeyframeData() {} //----------------------------------------------------------------------------- // data <- xsheet void TKeyframeData::setKeyframes(std::set positions, TXsheet *xsh) { + Position startPos(-1, -1); + setKeyframes(positions, xsh, startPos); +} + +void TKeyframeData::setKeyframes(std::set positions, TXsheet *xsh, + Position startPos) { if (positions.empty()) return; TStageObjectId cameraId = xsh->getStageObjectTree()->getCurrentCameraId(); @@ -51,6 +58,9 @@ void TKeyframeData::setKeyframes(std::set positions, TXsheet *xsh) { m_columnSpanCount = c1 - c0 + 1; m_rowSpanCount = r1 - r0 + 1; + if (startPos.first >= 0 && startPos.second >= 0) + m_offset = std::make_pair(r0 - startPos.first, c0 - startPos.second); + for (it = positions.begin(); it != positions.end(); ++it) { int row = it->first; int col = it->second; @@ -126,3 +136,7 @@ void TKeyframeData::getKeyframes(std::set &positions) const { TKeyframeSelection::Position(pos.first + r0, pos.second + c0)); } } + +void TKeyframeData::setKeyframesOffset(int row, int col) { + m_offset = std::make_pair(row, col); +} diff --git a/toonz/sources/toonz/keyframedata.h b/toonz/sources/toonz/keyframedata.h index 3f9aada6..eb86df9d 100644 --- a/toonz/sources/toonz/keyframedata.h +++ b/toonz/sources/toonz/keyframedata.h @@ -25,6 +25,8 @@ public: int m_columnSpanCount; int m_rowSpanCount; + Position m_offset = std::make_pair(0, 0); + // Numero di colonna della pegbar associato al booleano isCycleEnabled della // pegbar std::map m_isPegbarsCycleEnabled; @@ -37,6 +39,8 @@ public: // data <- xsh void setKeyframes(std::set positions, TXsheet *xsh); + void setKeyframes(std::set positions, TXsheet *xsh, + Position startPos); // data -> xsh bool getKeyframes(std::set &positions, TXsheet *xsh) const; @@ -52,6 +56,9 @@ public: int getColumnSpanCount() const { return m_columnSpanCount; } int getRowSpanCount() const { return m_rowSpanCount; } + + void setKeyframesOffset(int row, int col); + Position getKeyframesOffset() const { return m_offset; } }; #endif // KEYFRAMEDATA_INCLUDED diff --git a/toonz/sources/toonz/keyframeselection.cpp b/toonz/sources/toonz/keyframeselection.cpp index 526a3261..385c7f57 100644 --- a/toonz/sources/toonz/keyframeselection.cpp +++ b/toonz/sources/toonz/keyframeselection.cpp @@ -144,12 +144,17 @@ public: // data->xsh void setXshFromData(QMimeData *data) const { const TKeyframeData *keyframeData = dynamic_cast(data); - if (keyframeData) - pasteKeyframesWithoutUndo(keyframeData, &m_selection->getSelection()); + if (keyframeData) { + TKeyframeSelection *selection = + new TKeyframeSelection(m_selection->getSelection()); + pasteKeyframesWithoutUndo(keyframeData, &selection->getSelection()); + } } void undo() const override { // Delete merged data - deleteKeyframesWithoutUndo(&m_selection->getSelection()); + TKeyframeSelection *selection = + new TKeyframeSelection(m_selection->getSelection()); + deleteKeyframesWithoutUndo(&selection->getSelection()); if (-(m_r1 - m_r0 + 1) != 0) shiftKeyframesWithoutUndo(m_r0, m_r1, m_c0, m_c1, true); if (m_oldData) setXshFromData(m_oldData);